diff --git a/KShare.pro b/KShare.pro index e5e7388..feef83e 100644 --- a/KShare.pro +++ b/KShare.pro @@ -70,7 +70,25 @@ HEADERS += mainwindow.hpp \ cropeditor/settings/blurdialog.hpp \ cropeditor/drawing/pathitem.hpp \ cropeditor/drawing/lineitem.hpp \ - cropeditor/drawing/textitem.hpp + cropeditor/drawing/textitem.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); +} FORMS += mainwindow.ui \ cropeditor/settings/brushpenselection.ui \ diff --git a/main.cpp b/main.cpp index 718d139..caada8c 100644 --- a/main.cpp +++ b/main.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include bool verbose = false; @@ -44,6 +45,7 @@ int main(int argc, char *argv[]) { parser.addOption(v); parser.process(a); verbose = parser.isSet(v); + PlatformBackend::inst().getCursor().save("test.png", "PNG"); MainWindow w; w.show(); diff --git a/platformbackend.hpp b/platformbackend.hpp new file mode 100644 index 0000000..8133ebc --- /dev/null +++ b/platformbackend.hpp @@ -0,0 +1,14 @@ +#ifndef PLATFORMBACKEND_HPP +#define PLATFORMBACKEND_HPP + +#ifdef __APPLE__ +#include +#endif +#ifdef _WIN32 +#include +#endif +#ifdef __unix__ +#include +#endif + +#endif // PLATFORMBACKEND_HPP diff --git a/platformspecifics/mac/macbackend.cpp b/platformspecifics/mac/macbackend.cpp new file mode 100644 index 0000000..af2f4e5 --- /dev/null +++ b/platformspecifics/mac/macbackend.cpp @@ -0,0 +1,6 @@ +#include "macbackend.hpp" + +QPixmap PlatformBackend::getCursor() { +#warning "TODO: Mac backend" + return QPixmap(); +} diff --git a/platformspecifics/mac/macbackend.hpp b/platformspecifics/mac/macbackend.hpp new file mode 100644 index 0000000..324e375 --- /dev/null +++ b/platformspecifics/mac/macbackend.hpp @@ -0,0 +1,15 @@ +#ifndef MACBACKEND_HPP +#define MACBACKEND_HPP + +#include + +class PlatformBackend { + public: + QPixmap getCursor(); + static PlatformBackend &inst() { + static PlatformBackend inst; + return inst; + } +}; + +#endif // MACBACKEND_HPP diff --git a/platformspecifics/u32/u32backend.cpp b/platformspecifics/u32/u32backend.cpp new file mode 100644 index 0000000..b190328 --- /dev/null +++ b/platformspecifics/u32/u32backend.cpp @@ -0,0 +1,21 @@ +#include "u32backend.hpp" + +#include +#include +#include + +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 QtWin::fromHBITMAP(info.hbmColor); + } else + return QPixmap(); + } else + return QPixmap(); + } else + return QPixmap(); +} diff --git a/platformspecifics/u32/u32backend.hpp b/platformspecifics/u32/u32backend.hpp new file mode 100644 index 0000000..4d082d2 --- /dev/null +++ b/platformspecifics/u32/u32backend.hpp @@ -0,0 +1,15 @@ +#ifndef U32BACKEND_HPP +#define U32BACKEND_HPP + +#include + +class PlatformBackend { + public: + QPixmap getCursor(); + static PlatformBackend &inst() { + static PlatformBackend inst; + return inst; + } +}; + +#endif // U32BACKEND_HPP diff --git a/platformspecifics/x11/x11backend.cpp b/platformspecifics/x11/x11backend.cpp new file mode 100644 index 0000000..f347f54 --- /dev/null +++ b/platformspecifics/x11/x11backend.cpp @@ -0,0 +1,22 @@ +#include "x11backend.hpp" + +#include +#include +#include +#include +#include + +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 cursorReply(xcb_xfixes_get_cursor_image_reply(connection, cursorCookie, NULL)); + if (cursorReply.isNull()) { + return QPixmap(); + } + + quint32 *pixels = xcb_xfixes_get_cursor_image_cursor_image(cursorReply.data()); + if (!pixels) { + return QPixmap(); + } + return QPixmap::fromImage(QImage((quint8 *)pixels, cursorReply->width, cursorReply->height, QImage::Format_ARGB32_Premultiplied)); +} diff --git a/platformspecifics/x11/x11backend.hpp b/platformspecifics/x11/x11backend.hpp new file mode 100644 index 0000000..ab4ed57 --- /dev/null +++ b/platformspecifics/x11/x11backend.hpp @@ -0,0 +1,15 @@ +#ifndef X11BACKEND_HPP +#define X11BACKEND_HPP + +#include + +class PlatformBackend { + public: + QPixmap getCursor(); + static PlatformBackend &inst() { + static PlatformBackend inst; + return inst; + } +}; + +#endif // X11BACKEND_HPP