diff --git a/CMakeLists.txt b/CMakeLists.txt index 53de829..0a049cc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,122 +1,118 @@ # KDE Application Version, managed by release script set(KDE_APPLICATIONS_VERSION_MAJOR "18") set(KDE_APPLICATIONS_VERSION_MINOR "11") set(KDE_APPLICATIONS_VERSION_MICRO "70") set(KDE_APPLICATIONS_VERSION "${KDE_APPLICATIONS_VERSION_MAJOR}.${KDE_APPLICATIONS_VERSION_MINOR}.${KDE_APPLICATIONS_VERSION_MICRO}") set(SPECTACLE_VERSION ${KDE_APPLICATIONS_VERSION}) # minimum requirements cmake_minimum_required (VERSION 3.0 FATAL_ERROR) # Spectacle project project(Spectacle VERSION ${SPECTACLE_VERSION}) set(QT_MIN_VERSION "5.6.0") set(KF5_MIN_VERSION "5.29.0") set(PLASMA_MIN_VERSION "5.4.0") find_package(ECM ${KF5_MIN_VERSION} REQUIRED NO_MODULE) set( CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules ${CMAKE_MODULE_PATH} ${ECM_MODULE_PATH} ${ECM_KDE_MODULE_DIR} ) # set up kf5 include(KDEInstallDirs) include(KDECMakeSettings) include(KDECompilerSettings NO_POLICY_SCOPE) include(ECMInstallIcons) include(ECMSetupVersion) include(FeatureSummary) find_package( Qt5 ${QT_MIN_VERSION} CONFIG REQUIRED Core Concurrent Widgets DBus PrintSupport Quick ) find_package( KF5 ${KF5_MIN_VERSION} REQUIRED CoreAddons WidgetsAddons DBusAddons Notifications Config I18n KIO XmlGui WindowSystem DocTools Declarative NewStuff ) add_definitions(-DQT_NO_URL_CAST_FROM_STRING) add_definitions(-DQT_USE_QSTRINGBUILDER) add_definitions(-DQT_NO_CAST_FROM_ASCII) add_definitions(-DQT_NO_CAST_TO_ASCII) add_definitions(-DQT_NO_NARROWING_CONVERSIONS_IN_CONNECT) # optional components find_package(KF5Kipi) if (KF5Kipi_FOUND) set(KIPI_FOUND 1) endif () find_package(KDEExperimentalPurpose) if (KDEExperimentalPurpose_FOUND) set(PURPOSE_FOUND 1) endif() find_package(XCB COMPONENTS XFIXES IMAGE UTIL CURSOR) set(XCB_COMPONENTS_ERRORS FALSE) if (XCB_FOUND) find_package(Qt5X11Extras ${QT_MIN_VERSION} REQUIRED) endif() set(XCB_COMPONENTS_FOUND TRUE) if(NOT XCB_XFIXES_FOUND) set(XCB_COMPONENTS_ERRORS "${XCB_COMPONENTS_ERRORS} XCB-XFIXES ") set(XCB_COMPONENTS_FOUND FALSE) endif() if(NOT XCB_IMAGE_FOUND) set(XCB_COMPONENTS_ERRORS "${XCB_COMPONENTS_ERRORS} XCB-IMAGE ") set(XCB_COMPONENTS_FOUND FALSE) endif() if(NOT XCB_UTIL_FOUND) set(XCB_COMPONENTS_ERRORS "${XCB_COMPONENTS_ERRORS} XCB-UTIL ") set(XCB_COMPONENTS_FOUND FALSE) endif() if(NOT XCB_CURSOR_FOUND) set(XCB_COMPONENTS_ERRORS "${XCB_COMPONENTS_ERRORS} XCB-CURSOR ") set(XCB_COMPONENTS_FOUND FALSE) endif() # fail build if none of the platform backends can be found if (NOT XCB_FOUND OR NOT XCB_COMPONENTS_FOUND) message(FATAL_ERROR "No suitable backend platform was found. Currenty supported platforms are: XCB Components Required: ${XCB_COMPONENTS_ERRORS}") endif() -if (CMAKE_CXX_COMPILER_ID MATCHES "Clang") - add_definitions("-Wno-mismatched-tags") -endif() - # hand off to subdirectories add_subdirectory(src) add_subdirectory(dbus) add_subdirectory(desktop) add_subdirectory(icons) add_subdirectory(doc) # summaries feature_summary(WHAT ALL INCLUDE_QUIET_PACKAGES FATAL_ON_MISSING_REQUIRED_PACKAGES) diff --git a/src/QuickEditor/QuickEditor.cpp b/src/QuickEditor/QuickEditor.cpp index 91e3d5d..7ba7a53 100644 --- a/src/QuickEditor/QuickEditor.cpp +++ b/src/QuickEditor/QuickEditor.cpp @@ -1,150 +1,151 @@ /* * Copyright (C) 2016 Boudhayan Gupta * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "QuickEditor.h" #include "SpectacleConfig.h" #include #include #include #include #include #include #include #include struct QuickEditor::ImageStore : public QQuickImageProvider { ImageStore(const QPixmap &pixmap) : QQuickImageProvider(QQuickImageProvider::Pixmap), mPixmap(pixmap) {} QPixmap requestPixmap(const QString &id, QSize *size, const QSize &requestedSize) Q_DECL_OVERRIDE { Q_UNUSED(id); if (size) { *size = mPixmap.size(); } if (requestedSize.isEmpty()) { return mPixmap; } return mPixmap.scaled(requestedSize, Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation); } QPixmap mPixmap; }; -struct QuickEditor::QuickEditorPrivate +class QuickEditor::QuickEditorPrivate { +public: KDeclarative::KDeclarative *mDecl; QQuickView *mQuickView; QQmlEngine *mQmlEngine; QRect mGrabRect; QSharedPointer mCurrentGrabResult; }; QuickEditor::QuickEditor(const QPixmap &pixmap, QObject *parent) : QObject(parent), mImageStore(new ImageStore(pixmap)), d_ptr(new QuickEditorPrivate) { Q_D(QuickEditor); d->mQmlEngine = new QQmlEngine(); d->mDecl = new KDeclarative::KDeclarative; d->mDecl->setDeclarativeEngine(d->mQmlEngine); #if KDECLARATIVE_VERSION >= QT_VERSION_CHECK(5, 45, 0) d->mDecl->setupEngine(d->mQmlEngine); d->mDecl->setupContext(); #else d->mDecl->setupBindings(); #endif d->mQmlEngine->addImageProvider(QStringLiteral("snapshot"), mImageStore); d->mQuickView = new QQuickView(d->mQmlEngine, nullptr); d->mQuickView->setClearBeforeRendering(false); d->mQuickView->setSource(QUrl(QStringLiteral("qrc:///QuickEditor/EditorRoot.qml"))); d->mQuickView->setFlags(Qt::BypassWindowManagerHint | Qt::WindowStaysOnTopHint | Qt::FramelessWindowHint | Qt::Tool); d->mQuickView->setGeometry(0, 0, pixmap.width(), pixmap.height()); d->mQuickView->showFullScreen(); // connect up the signals QQuickItem *rootItem = d->mQuickView->rootObject(); connect(rootItem, SIGNAL(acceptImage(int, int, int, int)), this, SLOT(acceptImageHandler(int, int, int, int))); connect(rootItem, SIGNAL(cancelImage()), this, SIGNAL(grabCancelled())); // set up initial config SpectacleConfig *config = SpectacleConfig::instance(); if (config->rememberLastRectangularRegion()) { auto pixelRatio = d->mQuickView->devicePixelRatio(); QRect cropRegion = config->cropRegion(); if (!cropRegion.isEmpty()) { QMetaObject::invokeMethod( rootItem, "setInitialSelection", Q_ARG(QVariant, cropRegion.x() / pixelRatio), Q_ARG(QVariant, cropRegion.y() / pixelRatio), Q_ARG(QVariant, cropRegion.width() / pixelRatio), Q_ARG(QVariant, cropRegion.height() / pixelRatio) ); } } rootItem->setProperty("showMagnifier", config->showMagnifierChecked()); if (config->useLightRegionMaskColour()) { rootItem->setProperty("maskColour", QColor(255, 255, 255, 100)); } } QuickEditor::~QuickEditor() { Q_D(QuickEditor); delete d->mQuickView; delete d->mDecl; delete d->mQmlEngine; delete d_ptr; } void QuickEditor::acceptImageHandler(int x, int y, int width, int height) { Q_D(QuickEditor); if ((x == -1) && (y == -1) && (width == -1) && (height == -1)) { SpectacleConfig::instance()->setCropRegion(QRect()); emit grabCancelled(); return; } auto pixelRatio = d->mQuickView->devicePixelRatio(); d->mGrabRect = QRect(x * pixelRatio, y * pixelRatio, width * pixelRatio, height * pixelRatio); SpectacleConfig::instance()->setCropRegion(d->mGrabRect); d->mQuickView->hide(); emit grabDone(mImageStore->mPixmap.copy(d->mGrabRect), d->mGrabRect); } diff --git a/src/QuickEditor/QuickEditor.h b/src/QuickEditor/QuickEditor.h index 0a57fa7..9544b8e 100644 --- a/src/QuickEditor/QuickEditor.h +++ b/src/QuickEditor/QuickEditor.h @@ -1,53 +1,53 @@ /* * Copyright (C) 2016 Boudhayan Gupta * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef QUICKEDITOR_H #define QUICKEDITOR_H #include class QuickEditor : public QObject { Q_OBJECT public: explicit QuickEditor(const QPixmap &pixmap, QObject *parent = nullptr); virtual ~QuickEditor(); signals: void grabDone(const QPixmap &pixmap, const QRect &cropRegion); void grabCancelled(); private slots: void acceptImageHandler(int x, int y, int width, int height); private: struct ImageStore; ImageStore *mImageStore; - struct QuickEditorPrivate; - Q_DECLARE_PRIVATE(QuickEditor); + class QuickEditorPrivate; + Q_DECLARE_PRIVATE(QuickEditor) QuickEditorPrivate *d_ptr; }; #endif // QUICKEDITOR_H