diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 202fa69..eb78c54 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,90 +1,90 @@ # common - configure file and version definitions configure_file(Config.h.in ${CMAKE_CURRENT_BINARY_DIR}/Config.h) # target set( KSG_SRCS_DEFAULT Main.cpp KSCore.cpp PlatformBackends/ImageGrabber.cpp PlatformBackends/DummyImageGrabber.cpp Gui/KSMainWindow.cpp Gui/KSWidget.cpp Gui/KSImageWidget.cpp Gui/KSSaveConfigDialog.cpp Gui/KSSendToMenu.cpp Editor/KSImageEditor.cpp - Editor/KSCropRubberBand.cpp + Editor/KSCropArea.cpp ) qt5_add_resources(KSG_SRCS_RESOURCES Editor/QmlResources/QmlResources.qrc) if(XCB_FOUND) set( KSG_SRCS_X11 PlatformBackends/X11ImageGrabber.cpp ) endif() if(KF5Kipi_FOUND) set( KSG_SRCS_KIPI KipiInterface/KSGKipiInterface.cpp KipiInterface/KSGKipiInfoShared.cpp KipiInterface/KSGKipiImageCollectionShared.cpp KipiInterface/KSGKipiImageCollectionSelector.cpp ) endif() set( KSG_SRCS_ALL ${KSG_SRCS_DEFAULT} ${KSG_SRCS_KIPI} ${KSG_SRCS_X11} ${KSG_SRCS_RESOURCES} ) add_executable( kscreengenie ${KSG_SRCS_ALL} ) # link libraries target_link_libraries( kscreengenie Qt5::DBus Qt5::PrintSupport Qt5::Quick KF5::CoreAddons KF5::Declarative KF5::Notifications KF5::ConfigGui KF5::I18n KF5::KIOWidgets KF5::WindowSystem KF5::XmlGui KF5::WidgetsAddons ) if(XCB_FOUND) target_link_libraries( kscreengenie XCB::XFIXES XCB::IMAGE XCB::CURSOR XCB::UTIL Qt5::X11Extras KF5::Screen ) endif() if(KF5Kipi_FOUND) target_link_libraries ( kscreengenie KF5::Kipi ) endif() install(TARGETS kscreengenie ${INSTALL_TARGETS_DEFAULT_ARGS}) diff --git a/src/Editor/KSCropRubberBand.cpp b/src/Editor/KSCropArea.cpp similarity index 83% rename from src/Editor/KSCropRubberBand.cpp rename to src/Editor/KSCropArea.cpp index c2900f4..780ffaa 100644 --- a/src/Editor/KSCropRubberBand.cpp +++ b/src/Editor/KSCropArea.cpp @@ -1,357 +1,368 @@ /* * Copyright (C) 2007 Luca Gugelmann * Copyright (C) 2015 Boudhayan Gupta * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU Library General Public License version 2 as * published by the Free Software Foundation * * 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 Library 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 "KSCropRubberBand.h" +#include "KSCropArea.h" -KSCropRubberBand::KSCropRubberBand(QQuickItem *parent) : +KSCropArea::KSCropArea(QQuickItem *parent) : QQuickPaintedItem(parent), + mNoPaint(false), mCropRect(0, 0, 0, 0), mMouseOverHandle(nullptr) { mTLHandle = mTRHandle = mBLHandle = mBRHandle = QRect(0, 0, 15, 15); mLHandle = mRHandle = QRect(0, 0, 10, 20); mTHandle = mBHandle = QRect(0, 0, 20, 10); mHandles = { &mTLHandle, &mTRHandle, &mBLHandle, &mBRHandle, &mLHandle, &mTHandle, &mRHandle, &mBHandle }; setAcceptedMouseButtons(Qt::AllButtons); setAcceptHoverEvents(true); setAntialiasing(true); } -void KSCropRubberBand::paint(QPainter *painter) +void KSCropArea::paint(QPainter *painter) { updateHandles(); - painter->save(); - QRegion drawRegion(boundingRect().toRect()); - // first draw the overlay + if (!mNoPaint) { + painter->save(); + QRegion drawRegion(boundingRect().toRect()); - painter->setClipRegion(drawRegion - mCropRect); - painter->setBrush(QBrush(QColor(0, 0, 0, 127))); - painter->setRenderHint(QPainter::Antialiasing); - painter->drawRect(boundingRect()); + // first draw the overlay - // then draw the border + painter->setClipRegion(drawRegion - mCropRect); + painter->setBrush(QBrush(QColor(0, 0, 0, 127))); + painter->setRenderHint(QPainter::Antialiasing); + painter->drawRect(boundingRect()); - QRegion borderRegion(mCropRect); - borderRegion -= mCropRect.adjusted(1, 1, -1, -1); - painter->setClipRegion(borderRegion); - painter->setBrush(QBrush(QColor(0, 0, 0))); - painter->drawRect(mCropRect); + // then draw the border - // draw the handles + QRegion borderRegion(mCropRect); + borderRegion -= mCropRect.adjusted(1, 1, -1, -1); + painter->setClipRegion(borderRegion); + painter->setBrush(QBrush(QColor(0, 0, 0))); + painter->drawRect(mCropRect); - if ((mCropRect.height() > 20) && (mCropRect.width() > 20)) { - drawHandles(painter, QColor(0, 0, 0)); - } + // draw the handles - // done + if ((mCropRect.height() > 20) && (mCropRect.width() > 20)) { + drawHandles(painter, QColor(0, 0, 0)); + } - painter->restore(); + // done + + painter->restore(); + } } // property accessors -int KSCropRubberBand::cropX() const { return mCropRect.x(); } -int KSCropRubberBand::cropY() const { return mCropRect.y(); } -int KSCropRubberBand::cropWidth() const { return mCropRect.width(); } -int KSCropRubberBand::cropHeight() const { return mCropRect.height(); } +bool KSCropArea::noPaint() const { return mNoPaint; } +int KSCropArea::cropX() const { return mCropRect.x(); } +int KSCropArea::cropY() const { return mCropRect.y(); } +int KSCropArea::cropWidth() const { return mCropRect.width(); } +int KSCropArea::cropHeight() const { return mCropRect.height(); } // property mutators -void KSCropRubberBand::setCropX(const int &x) +void KSCropArea::setNoPaint(const bool &noPaint) +{ + mNoPaint = noPaint; + update(); +} + +void KSCropArea::setCropX(const int &x) { mCropRect.setX(x); update(); } -void KSCropRubberBand::setCropY(const int &y) +void KSCropArea::setCropY(const int &y) { mCropRect.setY(y); update(); } -void KSCropRubberBand::setCropWidth(const int &width) +void KSCropArea::setCropWidth(const int &width) { mCropRect.setWidth(width); update(); } -void KSCropRubberBand::setCropHeight(const int &height) +void KSCropArea::setCropHeight(const int &height) { mCropRect.setHeight(height); update(); } // mouse event handlers -void KSCropRubberBand::mousePressEvent(QMouseEvent *event) +void KSCropArea::mousePressEvent(QMouseEvent *event) { if (!mCropRect.contains(event->pos())) { mCropRect = QRect(event->pos(), event->pos()); mMouseOverHandle = &mBRHandle; } else if (mMouseOverHandle == nullptr) { mMoveDelta = event->pos() - mCropRect.topLeft(); setCursor(Qt::ClosedHandCursor); } update(); } -void KSCropRubberBand::mouseMoveEvent(QMouseEvent *event) +void KSCropArea::mouseMoveEvent(QMouseEvent *event) { if (mMouseOverHandle == nullptr) { // moving the whole selection QRect r = boundingRect().toRect(); r.setBottomRight(r.bottomRight() - QPoint(mCropRect.width(), mCropRect.height()) + QPoint(1, 1)); if (!(r.isNull() || r.isEmpty()) && r.isValid()) { const QPoint newTopLeft = limitPointToRect(event->pos() - mMoveDelta, r); if (newTopLeft == mCropRect.topLeft()) { mMoveDelta = event->pos() - mCropRect.topLeft(); } else { mCropRect.moveTo(newTopLeft); } } } else { // dragging a handle QRect r = mCropRect; if (mMouseOverHandle == &mTLHandle) { if (event->pos().x() <= r.right() && event->pos().y() <= r.bottom()) { r.setTopLeft(event->pos()); } else if (event->pos().x() <= r.right() && event->pos().y() > r.bottom()) { r.setLeft(event->pos().x()); r.setTop(r.bottom()); r.setBottom(event->pos().y()); mMouseOverHandle = &mBLHandle; } else if (event->pos().x() > r.right() && event->pos().y() <= r.bottom()) { r.setTop(event->pos().y()); r.setLeft(r.right()); r.setRight(event->pos().x()); mMouseOverHandle = &mTRHandle; } else { r.setTopLeft(r.bottomRight()); r.setBottomRight(event->pos()); mMouseOverHandle = &mBRHandle; } r = r.normalized(); } else if (mMouseOverHandle == &mTRHandle) { if (event->pos().x() >= r.left() && event->pos().y() <= r.bottom()) { r.setTopRight(event->pos()); } else if (event->pos().x() >= r.left() && event->pos().y() > r.bottom()) { r.setRight(event->pos().x()); r.setTop(r.bottom()); r.setBottom(event->pos().y()); mMouseOverHandle = &mBRHandle; } else if (event->pos().x() < r.left() && event->pos().y() <= r.bottom()) { r.setTop(event->pos().y()); r.setRight(r.left()); r.setLeft(event->pos().x()); mMouseOverHandle = &mTLHandle; } else { r.setTopRight(r.bottomLeft()); r.setBottomLeft(event->pos()); mMouseOverHandle = &mBLHandle; } r = r.normalized(); } else if (mMouseOverHandle == &mBLHandle) { if (event->pos().x() <= r.right() && event->pos().y() >= r.top()) { r.setBottomLeft(event->pos()); } else if (event->pos().x() <= r.left() && event->pos().y() < r.top()) { r.setLeft(event->pos().x()); r.setBottom(r.top()); r.setTop(event->pos().y()); mMouseOverHandle = &mTLHandle; } else if (event->pos().x() > r.left() && event->pos().y() >= r.top()) { r.setBottom(event->pos().y()); r.setLeft(r.right()); r.setRight(event->pos().x()); mMouseOverHandle = &mBRHandle; } else { r.setBottomLeft(r.topRight()); r.setTopRight(event->pos()); mMouseOverHandle = &mTRHandle; } r = r.normalized(); } else if (mMouseOverHandle == &mBRHandle) { if (event->pos().x() >= r.left() && event->pos().y() >= r.top()) { r.setBottomRight(event->pos()); } else if (event->pos().x() >= r.left() && event->pos().y() < r.top()) { r.setRight(event->pos().x()); r.setBottom(r.top()); r.setTop(event->pos().y()); mMouseOverHandle = &mTRHandle; } else if (event->pos().x() < r.left() && event->pos().y() >= r.top()) { r.setBottom(event->pos().y()); r.setRight(r.left()); r.setLeft(event->pos().x()); mMouseOverHandle = &mBLHandle; } else { r.setBottomRight(r.topLeft()); r.setTopLeft(event->pos()); mMouseOverHandle = &mTLHandle; } r = r.normalized(); } else if (mMouseOverHandle == &mTHandle) { if (event->pos().y() <= r.bottom()) { r.setTop(event->pos().y()); } else { r.setTop(r.bottom()); r.setBottom(event->pos().y()); mMouseOverHandle = &mBHandle; } r = r.normalized(); } else if (mMouseOverHandle == &mRHandle) { if (event->pos().x() >= r.left()) { r.setRight(event->pos().x()); } else { r.setRight(r.left()); r.setLeft(event->pos().x()); mMouseOverHandle = &mLHandle; } r = r.normalized(); } else if (mMouseOverHandle == &mLHandle) { if (event->pos().x() <= r.right()) { r.setLeft(event->pos().x()); } else { r.setLeft(r.right()); r.setRight(event->pos().x()); mMouseOverHandle = &mRHandle; } r = r.normalized(); } else if (mMouseOverHandle == &mBHandle) { if (event->pos().y() >= r.top()) { r.setBottom(event->pos().y()); } else { r.setBottom(r.top()); r.setTop(event->pos().y()); mMouseOverHandle = &mTHandle; } r = r.normalized(); } mCropRect = r.normalized(); setResizeCursors(); } update(); emitCropRectChangedSignals(); } -void KSCropRubberBand::mouseReleaseEvent(QMouseEvent *event) +void KSCropArea::mouseReleaseEvent(QMouseEvent *event) { if (mMouseOverHandle == nullptr && mCropRect.contains(event->pos())) { setCursor(Qt::OpenHandCursor); } update(); emitCropRectChangedSignals(); } -void KSCropRubberBand::hoverMoveEvent(QHoverEvent *event) +void KSCropArea::hoverMoveEvent(QHoverEvent *event) { for (auto r: mHandles) { if (r->contains(event->pos())) { mMouseOverHandle = r; setResizeCursors(); return; } } mMouseOverHandle = nullptr; if (mCropRect.contains(event->pos())) { setCursor(Qt::OpenHandCursor); } else { setCursor(Qt::CrossCursor); } } // utility functions -void KSCropRubberBand::setResizeCursors() +void KSCropArea::setResizeCursors() { if (mMouseOverHandle == &mTLHandle || mMouseOverHandle == &mBRHandle) { setCursor(Qt::SizeFDiagCursor); } else if (mMouseOverHandle == &mTRHandle || mMouseOverHandle == &mBLHandle) { setCursor(Qt::SizeBDiagCursor); } else if (mMouseOverHandle == &mLHandle || mMouseOverHandle == &mRHandle) { setCursor(Qt::SizeHorCursor); } else if (mMouseOverHandle == &mTHandle || mMouseOverHandle == &mBHandle) { setCursor(Qt::SizeVerCursor); } } -inline void KSCropRubberBand::drawTriangle(QPainter *painter, const QColor &color, const QPoint &a, const QPoint &b, const QPoint &c) +inline void KSCropArea::drawTriangle(QPainter *painter, const QColor &color, const QPoint &a, const QPoint &b, const QPoint &c) { painter->save(); painter->setClipping(false); QPainterPath path; path.moveTo(a); path.lineTo(b); path.lineTo(c); path.lineTo(a); painter->setPen(Qt::NoPen); painter->fillPath(path, QBrush(color)); painter->setClipping(true); painter->restore(); } -void KSCropRubberBand::updateHandles() +void KSCropArea::updateHandles() { QRect r = mCropRect; mTLHandle.moveTopLeft(r.topLeft()); mTRHandle.moveTopRight(r.topRight()); mBLHandle.moveBottomLeft(r.bottomLeft()); mBRHandle.moveBottomRight(r.bottomRight()); mLHandle.moveTopLeft(QPoint(r.x(), r.y() + (r.height() / 2) - (mLHandle.height() / 2))); mTHandle.moveTopLeft(QPoint(r.x() + (r.width() / 2) - (mTHandle.width() / 2), r.y())); mRHandle.moveTopRight(QPoint(r.right(), r.y() + (r.height() / 2) - (mRHandle.height() / 2))); mBHandle.moveBottomLeft(QPoint(r.x() + (r.width() / 2) - (mBHandle.width() / 2), r.bottom())); } -void KSCropRubberBand::drawHandles(QPainter *painter, const QColor &color) +void KSCropArea::drawHandles(QPainter *painter, const QColor &color) { drawTriangle(painter, color, mTLHandle.topLeft(), mTLHandle.topRight(), mTLHandle.bottomLeft()); drawTriangle(painter, color, mTRHandle.topRight(), mTRHandle.topLeft(), mTRHandle.bottomRight()); drawTriangle(painter, color, mBLHandle.topLeft(), mBLHandle.bottomLeft(), mBLHandle.bottomRight()); drawTriangle(painter, color, mBRHandle.topRight(), mBRHandle.bottomRight(), mBRHandle.bottomLeft()); drawTriangle(painter, color, mTHandle.topLeft(), mTHandle.topRight(), (mTHandle.bottomLeft() + mTHandle.bottomRight()) / 2); drawTriangle(painter, color, mBHandle.bottomLeft(), mBHandle.bottomRight(), (mBHandle.topLeft() + mBHandle.topRight()) / 2); drawTriangle(painter, color, mLHandle.topLeft(), mLHandle.bottomLeft(), (mLHandle.topRight() + mLHandle.bottomRight()) / 2); drawTriangle(painter, color, mRHandle.topRight(), mRHandle.bottomRight(), (mRHandle.topLeft() + mRHandle.bottomLeft()) / 2); } -QPoint KSCropRubberBand::limitPointToRect(const QPoint &p, const QRect &r) const +QPoint KSCropArea::limitPointToRect(const QPoint &p, const QRect &r) const { QPoint q; q.setX(p.x() < r.x() ? r.x() : p.x() < r.right() ? p.x() : r.right()); q.setY(p.y() < r.y() ? r.y() : p.y() < r.bottom() ? p.y() : r.bottom()); return q; } -void KSCropRubberBand::emitCropRectChangedSignals() +void KSCropArea::emitCropRectChangedSignals() { emit cropXChanged(mCropRect.x()); emit cropYChanged(mCropRect.y()); emit cropWidthChanged(mCropRect.width()); emit cropHeightChanged(mCropRect.height()); } diff --git a/src/Editor/KSCropRubberBand.h b/src/Editor/KSCropArea.h similarity index 75% rename from src/Editor/KSCropRubberBand.h rename to src/Editor/KSCropArea.h index 72d7025..e862384 100644 --- a/src/Editor/KSCropRubberBand.h +++ b/src/Editor/KSCropArea.h @@ -1,85 +1,90 @@ /* * Copyright (C) 2007 Luca Gugelmann * Copyright (C) 2015 Boudhayan Gupta * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU Library General Public License version 2 as * published by the Free Software Foundation * * 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 Library 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 KSCROPRUBBERBAND_H -#define KSCROPRUBBERBAND_H +#ifndef KSCROPAREA_H +#define KSCROPAREA_H #include #include #include #include #include -class KSCropRubberBand : public QQuickPaintedItem +class KSCropArea : public QQuickPaintedItem { Q_OBJECT - Q_PROPERTY(int cropX READ cropX WRITE setCropX NOTIFY cropXChanged) - Q_PROPERTY(int cropY READ cropY WRITE setCropY NOTIFY cropYChanged) - Q_PROPERTY(int cropWidth READ cropWidth WRITE setCropWidth NOTIFY cropWidthChanged) - Q_PROPERTY(int cropHeight READ cropHeight WRITE setCropHeight NOTIFY cropHeightChanged) + Q_PROPERTY(bool noPaint READ noPaint WRITE setNoPaint NOTIFY noPaintChanged) + Q_PROPERTY(int cropX READ cropX WRITE setCropX NOTIFY cropXChanged) + Q_PROPERTY(int cropY READ cropY WRITE setCropY NOTIFY cropYChanged) + Q_PROPERTY(int cropWidth READ cropWidth WRITE setCropWidth NOTIFY cropWidthChanged) + Q_PROPERTY(int cropHeight READ cropHeight WRITE setCropHeight NOTIFY cropHeightChanged) public: - explicit KSCropRubberBand(QQuickItem *parent = 0); + explicit KSCropArea(QQuickItem *parent = 0); void paint(QPainter *painter) Q_DECL_OVERRIDE; + bool noPaint() const; int cropX() const; int cropY() const; int cropWidth() const; int cropHeight() const; public slots: + void setNoPaint(const bool &noPaint); void setCropX(const int &x); void setCropY(const int &y); void setCropWidth(const int &width); void setCropHeight(const int &height); signals: + void noPaintChanged(const bool noPaint); void cropXChanged(const int x); void cropYChanged(const int y); void cropWidthChanged(const int width); void cropHeightChanged(const int height); protected: void mousePressEvent(QMouseEvent *event) Q_DECL_OVERRIDE; void mouseMoveEvent(QMouseEvent *event) Q_DECL_OVERRIDE; void mouseReleaseEvent(QMouseEvent *event) Q_DECL_OVERRIDE; void hoverMoveEvent(QHoverEvent *event) Q_DECL_OVERRIDE; private: QPoint limitPointToRect(const QPoint &p, const QRect &r) const; void setResizeCursors(); void updateHandles(); void drawTriangle(QPainter *painter, const QColor &color, const QPoint &a, const QPoint &b, const QPoint &c); void drawHandles(QPainter *painter, const QColor &color); void emitCropRectChangedSignals(); + bool mNoPaint; QRect mCropRect; QPoint mMoveDelta; QRect mTLHandle, mTRHandle, mBLHandle, mBRHandle; QRect mLHandle, mTHandle, mRHandle, mBHandle; QList mHandles; QRect *mMouseOverHandle; }; -#endif // KSCROPRUBBERBAND_H +#endif // KSCROPAREA_H diff --git a/src/Editor/KSImageEditor.cpp b/src/Editor/KSImageEditor.cpp index 894a358..34d5659 100644 --- a/src/Editor/KSImageEditor.cpp +++ b/src/Editor/KSImageEditor.cpp @@ -1,125 +1,125 @@ /* * Copyright (C) 2015 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 "KSImageEditor.h" // the image provider first KSImageProvider::KSImageProvider(const QPixmap &pixmap) : QQuickImageProvider(QQuickImageProvider::Pixmap), mPixmap(pixmap) {} QPixmap KSImageProvider::requestPixmap(const QString &id, QSize *size, const QSize &requestedSize) { Q_UNUSED(id); if (size) { *size = mPixmap.size(); } if (requestedSize.isEmpty()) { return mPixmap; } return mPixmap.scaled(requestedSize, Qt::KeepAspectRatio, Qt::SmoothTransformation); } QPixmap KSImageProvider::pixmap() const { return mPixmap; } // now the editor KSImageEditor::KSImageEditor(const QPixmap &pixmap, QObject *parent) : QObject(parent), mQuickView(new QQuickView), mImageProvider(new KSImageProvider(pixmap)) { QMetaObject::invokeMethod(this, "init", Qt::QueuedConnection); } KSImageEditor::~KSImageEditor() { if (mQuickView->visibility() != QQuickView::Hidden) { mQuickView->hide(); } if (mQuickView) { delete mQuickView; } } void KSImageEditor::init() { // set up the KDeclarative bindings for the QQuickView KDeclarative::KDeclarative decl; decl.setDeclarativeEngine(mQuickView->engine()); decl.setupBindings(); // add in the screenshot imageprovider mQuickView->engine()->addImageProvider("screenshot", mImageProvider); - qmlRegisterType("KSComponents", 2, 0, "KSCropRubberBand"); + qmlRegisterType("KSComponents", 2, 0, "KSCropArea"); // set up the window mQuickView->setResizeMode(QQuickView::SizeViewToRootObject); mQuickView->setFlags(Qt::WindowStaysOnTopHint | Qt::FramelessWindowHint | Qt::Tool); mQuickView->setClearBeforeRendering(true); mQuickView->setSource(QUrl("qrc:///RegionGrabber.qml")); // connect connect(mQuickView->engine(), &QQmlEngine::quit, this, &KSImageEditor::grabCanceled); connect(mQuickView, &QQuickView::statusChanged, this, &KSImageEditor::waitForViewReady); } void KSImageEditor::waitForViewReady(QQuickView::Status status) { switch(status) { case QQuickView::Ready: { QQuickItem *rootItem = mQuickView->rootObject(); connect(rootItem, SIGNAL(editCanceled()), this, SIGNAL(grabCanceled())); connect(rootItem, SIGNAL(editAccepted(int,int,int,int)), this, SLOT(selectConfirmedHandler(int,int,int,int))); mQuickView->showFullScreen(); return; } case QQuickView::Error: emit grabCanceled(); return; case QQuickView::Null: case QQuickView::Loading: return; } } void KSImageEditor::selectConfirmedHandler(int x, int y, int width, int height) { QPixmap pixmap = QPixmap::fromImage(mQuickView->grabWindow()); mQuickView->hide(); QRect region(x, y, width, height); emit grabAccepted(pixmap.copy(region), region); } diff --git a/src/Editor/KSImageEditor.h b/src/Editor/KSImageEditor.h index a6e5d64..7a65fe6 100644 --- a/src/Editor/KSImageEditor.h +++ b/src/Editor/KSImageEditor.h @@ -1,80 +1,80 @@ /* * Copyright (C) 2015 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 KSIMAGEEDITOR_H #define KSIMAGEEDITOR_H #include #include #include #include #include #include #include #include #include #include #include #include -#include "KSCropRubberBand.h" +#include "KSCropArea.h" class KSImageProvider : public QQuickImageProvider { public: explicit KSImageProvider(const QPixmap &Pixmap); QPixmap requestPixmap(const QString &id, QSize *size, const QSize &requestedSize); QPixmap pixmap() const; private: QPixmap mPixmap; }; class KSImageEditor : public QObject { Q_OBJECT public: explicit KSImageEditor(const QPixmap &pixmap, QObject *parent = 0); ~KSImageEditor(); signals: void grabAccepted(const QPixmap &pixmap, const QRect ®ion); void grabCanceled(); private slots: void init(); void waitForViewReady(QQuickView::Status status); void selectConfirmedHandler(int x, int y, int width, int height); private: QQuickView *mQuickView; KSImageProvider *mImageProvider; }; #endif // KSIMAGEEDITOR_H diff --git a/src/Editor/QmlResources/RegionGrabber.qml b/src/Editor/QmlResources/RegionGrabber.qml index 9f1267e..878c563 100644 --- a/src/Editor/QmlResources/RegionGrabber.qml +++ b/src/Editor/QmlResources/RegionGrabber.qml @@ -1,76 +1,88 @@ /* * Copyright (C) 2015 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. */ import QtQuick 2.4 import KSComponents 2.0 Image { id: rootItem; signal editCanceled; signal editAccepted(int x, int y, int width, int height); property var toolOptionsToolbar: null; property var currentGraphicElement: null; function prepareEditAccepted() { if (workArea.tool !== null) { workArea.tool.visible = false; workArea.tool.destroy(); } - editActionsToolbar.visible = false; - editAccepted(x, y, width, height); + cropArea.noPaint = true; + + editAccepted(cropArea.cropX, cropArea.cropY, cropArea.cropWidth, cropArea.cropHeight); } focus: true; Keys.onEscapePressed: editCanceled(); source: "image://screenshot/image"; - Item { - id: workArea; + KSCropArea { + id: cropArea; anchors.fill: parent; - property var tool: null; + Item { + id: workArea; + anchors.fill: parent; + z: -1; + + property var tool: null; + } + } + + Item { + id: toolBarArea; + anchors.fill: parent; } Component { id: rectangleTool; KSRectangleTool {} } KSEditActionsToolBar { id: editActionsToolbar; anchors.bottom: parent.bottom; anchors.right: parent.right; anchors.margins: 10; onDone: prepareEditAccepted(); onCancel: editCanceled(); onToolSelected: { if (workArea.tool !== null) { workArea.tool.destroy(); } if (toolName == "rectangle") { - workArea.tool = rectangleTool.createObject(workArea, {"parentItem" : workArea}); + workArea.tool = rectangleTool.createObject(toolBarArea, {"parentItem" : workArea}); } } } }