Merge feature/platformbackends

This commit is contained in:
ArsenArsen 2017-05-17 13:53:30 +02:00
commit ec6b9c2821
14 changed files with 157 additions and 9 deletions

View File

@ -72,7 +72,26 @@ HEADERS += mainwindow.hpp \
cropeditor/drawing/pathitem.hpp \
cropeditor/drawing/lineitem.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 \
cropeditor/settings/brushpenselection.ui \

View File

@ -56,9 +56,6 @@ int main(int argc, char *argv[]) {
verbose = parser.isSet(v);
MainWindow w;
w.show();
QTimer::singleShot(0, [&] {
if (parser.isSet(h)) w.hide();
});
if (!parser.isSet(h)) w.show();
return a.exec();
}

View File

@ -90,6 +90,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi
ui->quickMode->setChecked(settings::settings().value("quickMode", false).toBool());
ui->hideToTray->setChecked(settings::settings().value("hideOnClose", true).toBool());
ui->captureCursor->setChecked(settings::settings().value("captureCursor", true).toBool());
}
MainWindow::~MainWindow() {
@ -189,3 +190,7 @@ void MainWindow::on_hideToTray_clicked(bool checked) {
void MainWindow::on_actionColor_Picker_triggered() {
ColorPickerScene::showPicker();
}
void MainWindow::on_captureCursor_clicked(bool checked) {
settings::settings().setValue("captureCursor", checked);
}

View File

@ -30,8 +30,8 @@ class MainWindow : public QMainWindow {
void on_settingsButton_clicked();
void on_quickMode_clicked(bool checked);
void on_hideToTray_clicked(bool checked);
void on_actionColor_Picker_triggered();
void on_captureCursor_clicked(bool checked);
public:
explicit MainWindow(QWidget *parent = 0);

14
platformbackend.hpp Normal file
View 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

View 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
}

View 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

View 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());
}

View 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

View 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)));
}

View 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

View File

@ -5,6 +5,7 @@
#include "uploaders/uploadersingleton.hpp"
#include <QDoubleSpinBox>
#include <QTimer>
#include <settings.hpp>
void screenshotter::area() {
CropEditor *editor = new CropEditor(screenshotutil::fullscreen());
@ -15,7 +16,7 @@ void screenshotter::area() {
}
void screenshotter::fullscreen() {
UploaderSingleton::inst().upload(screenshotutil::fullscreen());
UploaderSingleton::inst().upload(screenshotutil::fullscreen(settings::settings().value("captureCursor", true).toBool()));
}
void screenshotter::areaDelayed() {

View File

@ -2,10 +2,22 @@
#include <QApplication>
#include <QClipboard>
#include <QPainter>
#include <QPixmap>
#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);
}

View File

@ -4,7 +4,7 @@
#include <QPixmap>
namespace screenshotutil {
QPixmap *fullscreen();
QPixmap *fullscreen(bool cursor = true);
QPixmap *window(long wid);
void toClipboard(QString value);
}