Merge feature/platformbackends
This commit is contained in:
commit
ec6b9c2821
21
KShare.pro
21
KShare.pro
@ -72,7 +72,26 @@ HEADERS += mainwindow.hpp \
|
|||||||
cropeditor/drawing/pathitem.hpp \
|
cropeditor/drawing/pathitem.hpp \
|
||||||
cropeditor/drawing/lineitem.hpp \
|
cropeditor/drawing/lineitem.hpp \
|
||||||
cropeditor/drawing/textitem.hpp \
|
cropeditor/drawing/textitem.hpp \
|
||||||
colorpicker/colorpickerscene.hpp
|
colorpicker/colorpickerscene.hpp \
|
||||||
|
platformbackend.hpp
|
||||||
|
mac {
|
||||||
|
SOURCES += $$PWD/platformspecifics/mac/macbackend.cpp
|
||||||
|
HEADERS += $$PWD/platformspecifics/mac/macbackend.hpp
|
||||||
|
LIBS += -framework Carbon
|
||||||
|
} else:win32 {
|
||||||
|
SOURCES += $$PWD/platformspecifics/u32/u32backend.cpp
|
||||||
|
HEADERS += $$PWD/platformspecifics/u32/u32backend.hpp
|
||||||
|
LIBS += -luser32
|
||||||
|
QT += winextras
|
||||||
|
} else:unix {
|
||||||
|
SOURCES += $$PWD/platformspecifics/x11/x11backend.cpp
|
||||||
|
HEADERS += $$PWD/platformspecifics/x11/x11backend.hpp
|
||||||
|
QT += x11extras
|
||||||
|
LIBS += -lxcb-cursor -lxcb-xfixes
|
||||||
|
} else {
|
||||||
|
error(Unsupported platform);
|
||||||
|
}
|
||||||
|
>>>>>>> feature/platformbackends
|
||||||
|
|
||||||
FORMS += mainwindow.ui \
|
FORMS += mainwindow.ui \
|
||||||
cropeditor/settings/brushpenselection.ui \
|
cropeditor/settings/brushpenselection.ui \
|
||||||
|
5
main.cpp
5
main.cpp
@ -56,9 +56,6 @@ int main(int argc, char *argv[]) {
|
|||||||
verbose = parser.isSet(v);
|
verbose = parser.isSet(v);
|
||||||
|
|
||||||
MainWindow w;
|
MainWindow w;
|
||||||
w.show();
|
if (!parser.isSet(h)) w.show();
|
||||||
QTimer::singleShot(0, [&] {
|
|
||||||
if (parser.isSet(h)) w.hide();
|
|
||||||
});
|
|
||||||
return a.exec();
|
return a.exec();
|
||||||
}
|
}
|
||||||
|
@ -90,6 +90,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi
|
|||||||
|
|
||||||
ui->quickMode->setChecked(settings::settings().value("quickMode", false).toBool());
|
ui->quickMode->setChecked(settings::settings().value("quickMode", false).toBool());
|
||||||
ui->hideToTray->setChecked(settings::settings().value("hideOnClose", true).toBool());
|
ui->hideToTray->setChecked(settings::settings().value("hideOnClose", true).toBool());
|
||||||
|
ui->captureCursor->setChecked(settings::settings().value("captureCursor", true).toBool());
|
||||||
}
|
}
|
||||||
|
|
||||||
MainWindow::~MainWindow() {
|
MainWindow::~MainWindow() {
|
||||||
@ -189,3 +190,7 @@ void MainWindow::on_hideToTray_clicked(bool checked) {
|
|||||||
void MainWindow::on_actionColor_Picker_triggered() {
|
void MainWindow::on_actionColor_Picker_triggered() {
|
||||||
ColorPickerScene::showPicker();
|
ColorPickerScene::showPicker();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWindow::on_captureCursor_clicked(bool checked) {
|
||||||
|
settings::settings().setValue("captureCursor", checked);
|
||||||
|
}
|
||||||
|
@ -30,8 +30,8 @@ class MainWindow : public QMainWindow {
|
|||||||
void on_settingsButton_clicked();
|
void on_settingsButton_clicked();
|
||||||
void on_quickMode_clicked(bool checked);
|
void on_quickMode_clicked(bool checked);
|
||||||
void on_hideToTray_clicked(bool checked);
|
void on_hideToTray_clicked(bool checked);
|
||||||
|
|
||||||
void on_actionColor_Picker_triggered();
|
void on_actionColor_Picker_triggered();
|
||||||
|
void on_captureCursor_clicked(bool checked);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit MainWindow(QWidget *parent = 0);
|
explicit MainWindow(QWidget *parent = 0);
|
||||||
|
14
platformbackend.hpp
Normal file
14
platformbackend.hpp
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
#ifndef PLATFORMBACKEND_HPP
|
||||||
|
#define PLATFORMBACKEND_HPP
|
||||||
|
|
||||||
|
#ifdef __APPLE__
|
||||||
|
#include <platformspecifics/mac/macbackend.hpp>
|
||||||
|
#endif
|
||||||
|
#ifdef _WIN32
|
||||||
|
#include <platformspecifics/u32/u32backend.hpp>
|
||||||
|
#endif
|
||||||
|
#ifdef __unix__
|
||||||
|
#include <platformspecifics/x11/x11backend.hpp>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif // PLATFORMBACKEND_HPP
|
9
platformspecifics/mac/macbackend.cpp
Normal file
9
platformspecifics/mac/macbackend.cpp
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
#include "macbackend.hpp"
|
||||||
|
|
||||||
|
QPixmap PlatformBackend::getCursor() {
|
||||||
|
#warning "TODO: Mac backend"
|
||||||
|
return std::tuple<QPoint, QPixmap>(QPoint(0, 0), QPixmap());
|
||||||
|
// Not Monday: https://developer.apple.com/reference/appkit/nscursor/1527062-image
|
||||||
|
// Some on how to do NSImage -> QPixmap: http://stackoverflow.com/a/2468961/3809164
|
||||||
|
// This is gonna be easier than with Windows
|
||||||
|
}
|
15
platformspecifics/mac/macbackend.hpp
Normal file
15
platformspecifics/mac/macbackend.hpp
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
#ifndef MACBACKEND_HPP
|
||||||
|
#define MACBACKEND_HPP
|
||||||
|
|
||||||
|
#include <QPixmap>
|
||||||
|
|
||||||
|
class PlatformBackend {
|
||||||
|
public:
|
||||||
|
QPixmap getCursor();
|
||||||
|
static PlatformBackend &inst() {
|
||||||
|
static PlatformBackend inst;
|
||||||
|
return inst;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // MACBACKEND_HPP
|
22
platformspecifics/u32/u32backend.cpp
Normal file
22
platformspecifics/u32/u32backend.cpp
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
#include "u32backend.hpp"
|
||||||
|
|
||||||
|
#include <QCursor>
|
||||||
|
#include <QtWin>
|
||||||
|
#include <windows.h>
|
||||||
|
|
||||||
|
std::tuple<QPoint, QPixmap> PlatformBackend::getCursor() {
|
||||||
|
CURSORINFO cursorInfo;
|
||||||
|
cursorInfo.cbSize = sizeof(cursorInfo);
|
||||||
|
if (GetCursorInfo(&cursorInfo)) {
|
||||||
|
if (cursorInfo.flags == CURSOR_SHOWING) {
|
||||||
|
ICONINFO info; // It took me 5 hours to get to here
|
||||||
|
if (GetIconInfo(cursorInfo.hCursor, &info)) {
|
||||||
|
return std::tuple<QPoint, QPixmap>(QPoint(info.xHotspot, info.yHotspot),
|
||||||
|
QtWin::fromHBITMAP(info.hbmColor, QtWin::HBitmapAlpha));
|
||||||
|
} else
|
||||||
|
return std::tuple<QPoint, QPixmap>(QPoint(0, 0), QPixmap());
|
||||||
|
} else
|
||||||
|
return std::tuple<QPoint, QPixmap>(QPoint(0, 0), QPixmap());
|
||||||
|
} else
|
||||||
|
return std::tuple<QPoint, QPixmap>(QPoint(0, 0), QPixmap());
|
||||||
|
}
|
15
platformspecifics/u32/u32backend.hpp
Normal file
15
platformspecifics/u32/u32backend.hpp
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
#ifndef U32BACKEND_HPP
|
||||||
|
#define U32BACKEND_HPP
|
||||||
|
|
||||||
|
#include <QPixmap>
|
||||||
|
|
||||||
|
class PlatformBackend {
|
||||||
|
public:
|
||||||
|
std::tuple<QPoint, QPixmap> getCursor();
|
||||||
|
static PlatformBackend &inst() {
|
||||||
|
static PlatformBackend inst;
|
||||||
|
return inst;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // U32BACKEND_HPP
|
24
platformspecifics/x11/x11backend.cpp
Normal file
24
platformspecifics/x11/x11backend.cpp
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
#include "x11backend.hpp"
|
||||||
|
|
||||||
|
#include <QPixmap>
|
||||||
|
#include <QX11Info>
|
||||||
|
#include <xcb/xcb_cursor.h>
|
||||||
|
#include <xcb/xcb_util.h>
|
||||||
|
#include <xcb/xfixes.h>
|
||||||
|
|
||||||
|
std::tuple<QPoint, QPixmap> PlatformBackend::getCursor() {
|
||||||
|
xcb_connection_t *connection = QX11Info::connection();
|
||||||
|
xcb_xfixes_get_cursor_image_cookie_t cursorCookie = xcb_xfixes_get_cursor_image_unchecked(connection);
|
||||||
|
QScopedPointer<xcb_xfixes_get_cursor_image_reply_t> cursorReply(xcb_xfixes_get_cursor_image_reply(connection, cursorCookie, NULL));
|
||||||
|
if (cursorReply.isNull()) {
|
||||||
|
return std::tuple<QPoint, QPixmap>(QPoint(0, 0), QPixmap());
|
||||||
|
}
|
||||||
|
|
||||||
|
quint32 *pixels = xcb_xfixes_get_cursor_image_cursor_image(cursorReply.data());
|
||||||
|
if (!pixels) {
|
||||||
|
return std::tuple<QPoint, QPixmap>(QPoint(0, 0), QPixmap());
|
||||||
|
}
|
||||||
|
return std::tuple<QPoint, QPixmap>(QPoint(cursorReply->xhot, cursorReply->yhot),
|
||||||
|
QPixmap::fromImage(QImage((quint8 *)pixels, cursorReply->width, cursorReply->height,
|
||||||
|
QImage::Format_ARGB32_Premultiplied)));
|
||||||
|
}
|
15
platformspecifics/x11/x11backend.hpp
Normal file
15
platformspecifics/x11/x11backend.hpp
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
#ifndef X11BACKEND_HPP
|
||||||
|
#define X11BACKEND_HPP
|
||||||
|
|
||||||
|
#include <QPixmap>
|
||||||
|
|
||||||
|
class PlatformBackend {
|
||||||
|
public:
|
||||||
|
std::tuple<QPoint, QPixmap> getCursor();
|
||||||
|
static PlatformBackend &inst() {
|
||||||
|
static PlatformBackend inst;
|
||||||
|
return inst;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // X11BACKEND_HPP
|
@ -5,6 +5,7 @@
|
|||||||
#include "uploaders/uploadersingleton.hpp"
|
#include "uploaders/uploadersingleton.hpp"
|
||||||
#include <QDoubleSpinBox>
|
#include <QDoubleSpinBox>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
|
#include <settings.hpp>
|
||||||
|
|
||||||
void screenshotter::area() {
|
void screenshotter::area() {
|
||||||
CropEditor *editor = new CropEditor(screenshotutil::fullscreen());
|
CropEditor *editor = new CropEditor(screenshotutil::fullscreen());
|
||||||
@ -15,7 +16,7 @@ void screenshotter::area() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void screenshotter::fullscreen() {
|
void screenshotter::fullscreen() {
|
||||||
UploaderSingleton::inst().upload(screenshotutil::fullscreen());
|
UploaderSingleton::inst().upload(screenshotutil::fullscreen(settings::settings().value("captureCursor", true).toBool()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void screenshotter::areaDelayed() {
|
void screenshotter::areaDelayed() {
|
||||||
|
@ -2,10 +2,22 @@
|
|||||||
|
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QClipboard>
|
#include <QClipboard>
|
||||||
|
#include <QPainter>
|
||||||
#include <QPixmap>
|
#include <QPixmap>
|
||||||
#include <QScreen>
|
#include <QScreen>
|
||||||
|
#include <platformbackend.hpp>
|
||||||
|
|
||||||
QPixmap *screenshotutil::fullscreen() {
|
QPixmap *screenshotutil::fullscreen(bool cursor) {
|
||||||
|
if (cursor) {
|
||||||
|
QPixmap *noCursor = window(0);
|
||||||
|
QScopedPointer<QPixmap> p(noCursor);
|
||||||
|
QPixmap *withCursor = new QPixmap(*noCursor);
|
||||||
|
QPainter painter(withCursor);
|
||||||
|
auto cursorData = PlatformBackend::inst().getCursor();
|
||||||
|
painter.drawPixmap(QCursor::pos() - std::get<0>(cursorData), std::get<1>(cursorData));
|
||||||
|
painter.end();
|
||||||
|
return withCursor;
|
||||||
|
}
|
||||||
return window(0);
|
return window(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
#include <QPixmap>
|
#include <QPixmap>
|
||||||
|
|
||||||
namespace screenshotutil {
|
namespace screenshotutil {
|
||||||
QPixmap *fullscreen();
|
QPixmap *fullscreen(bool cursor = true);
|
||||||
QPixmap *window(long wid);
|
QPixmap *window(long wid);
|
||||||
void toClipboard(QString value);
|
void toClipboard(QString value);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user