diff --git a/src/colorpicker/colorpickerscene.cpp b/src/colorpicker/colorpickerscene.cpp index 5b4cd5a..9920b88 100644 --- a/src/colorpicker/colorpickerscene.cpp +++ b/src/colorpicker/colorpickerscene.cpp @@ -43,7 +43,7 @@ ColorPickerScene::ColorPickerScene(QPixmap pixmap, QWidget *parentWidget) activateWindow(); setGeometry(pixmap.rect()); - QPoint p = screenshotutil::smallestScreenCoordinate() + QPoint p = utils::smallestScreenCoordinate() + QPoint(settings::settings().value("cropx", 0).toInt(), settings::settings().value("cropy", 0).toInt()); move(p.x(), p.y()); } diff --git a/src/colorpicker/colorpickerscene.hpp b/src/colorpicker/colorpickerscene.hpp index 755e8bb..8c39f4e 100644 --- a/src/colorpicker/colorpickerscene.hpp +++ b/src/colorpicker/colorpickerscene.hpp @@ -8,7 +8,7 @@ #include #include #include -#include +#include class ColorPickerScene : public QGraphicsScene, public ScreenOverlayView { Q_DECLARE_TR_FUNCTIONS(ColorPickerScene) @@ -18,7 +18,7 @@ public: void keyPressEvent(QKeyEvent *event) override; void mouseReleaseEvent(QGraphicsSceneMouseEvent *) override; static void showPicker() { - new ColorPickerScene(screenshotutil::fullscreen()); + new ColorPickerScene(utils::fullscreen()); } private: diff --git a/src/cropeditor/cropeditor.cpp b/src/cropeditor/cropeditor.cpp index 81ab8a6..bc47d0a 100644 --- a/src/cropeditor/cropeditor.cpp +++ b/src/cropeditor/cropeditor.cpp @@ -7,8 +7,8 @@ #include #include #include -#include #include +#include CropEditor::CropEditor(QPixmap image, QObject *parent) : QObject(parent) { scene = new CropScene(parent, image); @@ -24,7 +24,7 @@ CropEditor::CropEditor(QPixmap image, QObject *parent) : QObject(parent) { scene->setSceneRect(image.rect()); view->resize(image.width(), image.height()); view->setMinimumSize(image.size()); - QPoint p = screenshotutil::smallestScreenCoordinate() + QPoint p = utils::smallestScreenCoordinate() + QPoint(settings::settings().value("cropx", 0).toInt(), settings::settings().value("cropy", 0).toInt()); view->move(p.x(), p.y()); view->setWindowTitle(tr("KShare Crop Editor")); diff --git a/src/cropeditor/cropscene.cpp b/src/cropeditor/cropscene.cpp index f8de916..8710058 100644 --- a/src/cropeditor/cropscene.cpp +++ b/src/cropeditor/cropscene.cpp @@ -1,3 +1,4 @@ +// vim: set sw=4 tw=4 : #include "cropscene.hpp" #include "selectionrectangle.hpp" #include @@ -228,8 +229,8 @@ void CropScene::setVisible(bool visible) { view->setVisible(visible); if (visible) { if (QApplication::screens().size() == 1) view->showFullScreen(); - QPoint p = screenshotutil::smallestScreenCoordinate() + QPoint(settings::settings().value("cropx", 0).toInt(), - settings::settings().value("cropy", 0).toInt()); + QPoint p = utils::smallestScreenCoordinate() + QPoint(settings::settings().value("cropx", 0).toInt(), + settings::settings().value("cropy", 0).toInt()); view->move(p.x(), p.y()); view->setWindowTitle(tr("KShare Crop Editor")); view->activateWindow(); @@ -389,16 +390,6 @@ void CropScene::keyReleaseEvent(QKeyEvent *event) { if (!(event->modifiers() & Qt::ControlModifier)) QGraphicsScene::keyReleaseEvent(event); } -QPixmap extend(QPixmap img, QColor hl) { - QPixmap newImg(img.width() + 42, img.height() + 42); - QColor filler(255 - hl.red(), 255 - hl.green(), 255 - hl.blue()); - newImg.fill(filler); - QPainter ptr(&newImg); - ptr.drawPixmap(21, 21, img); - ptr.end(); - return newImg; -} - void CropScene::updateMag() { QString rectStr("(-1, -1, 0, 0)"); if (rect) { @@ -414,7 +405,9 @@ void CropScene::updateMag() { QPointF magnifierPos = cursorPos + QPointF(5, 5); magnifier->setPos(magnifierPos); - magnifier->setPixmap(extend(_pixmap, highlight()).copy(magnifierTopLeft.x() + 22, magnifierTopLeft.y() + 22, pixCnt, pixCnt).scaled(110, 110)); + magnifier->setPixmap(utils::extend(_pixmap, pixCnt, utils::invertColor(highlight())) + .copy(magnifierTopLeft.x() + pixCnt, magnifierTopLeft.y() + pixCnt, pixCnt, pixCnt) + .scaled(110, 110)); QPointF bottomRight = magnifierHintBox->sceneBoundingRect().bottomRight(); if (magnifier->sceneBoundingRect().bottom() > bottomRight.y()) bottomRight.setY(magnifier->sceneBoundingRect().bottom()); diff --git a/src/cropeditor/cropscene.hpp b/src/cropeditor/cropscene.hpp index 9387557..7755f25 100644 --- a/src/cropeditor/cropscene.hpp +++ b/src/cropeditor/cropscene.hpp @@ -11,7 +11,7 @@ #include #include #include -#include +#include class CropScene; #include @@ -107,19 +107,19 @@ private: QList gridRectsY; QGraphicsPolygonItem *cursorItem = nullptr; QGraphicsPixmapItem *hint - = new QGraphicsPixmapItem(screenshotutil::renderText(tr( // - "Press F1 to toggle this hint\n" - "\tHold Shift to slow the cursor down\n" - "\tCtrl+Drag a thing to move it around\n" - "\tAlt+Click a drawing to remove it\n" - "\tPress Return/Enter to finish\n" - "\tPress ESC to cancel\n" - "\tUse the menu bar to draw\n" - "\tNOTE: You must select 'Crop' before closing the editor\n" - "\tIf you do not it will not close."), - 5, - QColor(0, 0, 0, 125), - Qt::white)); + = new QGraphicsPixmapItem(utils::renderText(tr( // + "Press F1 to toggle this hint\n" + "\tHold Shift to slow the cursor down\n" + "\tCtrl+Drag a thing to move it around\n" + "\tAlt+Click a drawing to remove it\n" + "\tPress Return/Enter to finish\n" + "\tPress ESC to cancel\n" + "\tUse the menu bar to draw\n" + "\tNOTE: You must select 'Crop' before closing the editor\n" + "\tIf you do not it will not close."), + 5, + QColor(0, 0, 0, 125), + Qt::white)); }; #endif // CROPSCENE_HPP diff --git a/src/cropeditor/drawing/bluritem.cpp b/src/cropeditor/drawing/bluritem.cpp index 753a02e..65f966a 100644 --- a/src/cropeditor/drawing/bluritem.cpp +++ b/src/cropeditor/drawing/bluritem.cpp @@ -19,7 +19,6 @@ void BlurItem::mouseDragEvent(QGraphicsSceneMouseEvent *, CropScene *scene) { rect = scene->addRect(QRect(scene->cursorPosition().toPoint(), QSize(1, 1)), QPen(scene->highlight()), Qt::NoBrush); pixmap = scene->addPixmap(scene->pixmap().copy(rect->rect().toRect())); pixmap->setPos(scene->cursorPosition()); - pixmap->setZValue(rect->zValue() - 0.1); pixmap->setGraphicsEffect(effect); } else { QPointF p = scene->cursorPosition(); diff --git a/src/hotkeyinputdialog.cpp b/src/hotkeyinputdialog.cpp index 8d9d493..770c756 100644 --- a/src/hotkeyinputdialog.cpp +++ b/src/hotkeyinputdialog.cpp @@ -35,6 +35,8 @@ void HotkeyInputDialog::keyPressEvent(QKeyEvent *e) { void HotkeyInputDialog::on_recordButton_clicked() { recording = !recording; ui->recordButton->setText(recording ? tr("Stop recording") : tr("Record")); - if (recording) grabKeyboard(); - else releaseKeyboard(); + if (recording) + grabKeyboard(); + else + releaseKeyboard(); } diff --git a/src/main.cpp b/src/main.cpp index 1538572..57636ad 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,5 +1,4 @@ #include "mainwindow.hpp" -#include "screenshotutil.hpp" #include "ui_mainwindow.h" #include #include diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index d937375..90e014f 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -1,9 +1,9 @@ #include "mainwindow.hpp" #include "aboutbox.hpp" #include "screenshotter.hpp" -#include "screenshotutil.hpp" #include "settingsdialog.hpp" #include "ui_mainwindow.h" +#include "utils.hpp" #include #include #include diff --git a/src/recording/recordingcontroller.cpp b/src/recording/recordingcontroller.cpp index 3f55fbc..56df9b9 100644 --- a/src/recording/recordingcontroller.cpp +++ b/src/recording/recordingcontroller.cpp @@ -5,10 +5,10 @@ #include #include #include -#include #include #include #include +#include #include RecordingController::RecordingController() : timer(this) { @@ -102,8 +102,8 @@ void RecordingController::timeout() { time++; int localTime = time * timer.interval() - 3000; if (localTime > 0) { - QPixmap pp = screenshotutil::fullscreenArea(settings::settings().value("captureCursor", true).toBool(), - area.x(), area.y(), area.width(), area.height()); + QPixmap pp = utils::fullscreenArea(settings::settings().value("captureCursor", true).toBool(), area.x(), + area.y(), area.width(), area.height()); WorkerContext *context = new WorkerContext; context->consumer = _context->consumer; context->targetFormat = _context->format; diff --git a/src/screenshotter.cpp b/src/screenshotter.cpp index 18e5655..3f7a6d4 100644 --- a/src/screenshotter.cpp +++ b/src/screenshotter.cpp @@ -1,20 +1,20 @@ #include "screenshotter.hpp" #include "cropeditor/cropeditor.hpp" #include "mainwindow.hpp" -#include "screenshotutil.hpp" #include "uploaders/uploadersingleton.hpp" +#include "utils.hpp" #include #include #include #include void screenshotter::area() { - CropEditor *editor = new CropEditor(screenshotutil::fullscreen(settings::settings().value("captureCursor", true).toBool())); + CropEditor *editor = new CropEditor(utils::fullscreen(settings::settings().value("captureCursor", true).toBool())); QObject::connect(editor, &CropEditor::cropped, [&](QPixmap pixmap) { UploaderSingleton::inst().upload(pixmap); }); } void screenshotter::fullscreen() { - UploaderSingleton::inst().upload(screenshotutil::fullscreen(settings::settings().value("captureCursor", true).toBool())); + UploaderSingleton::inst().upload(utils::fullscreen(settings::settings().value("captureCursor", true).toBool())); } void screenshotter::areaDelayed() { @@ -31,6 +31,6 @@ void screenshotter::activeDelayed() { void screenshotter::active() { #ifdef PLATFORM_CAPABILITY_ACTIVEWINDOW - UploaderSingleton::inst().upload(screenshotutil::window(PlatformBackend::inst().getActiveWID())); + UploaderSingleton::inst().upload(utils::window(PlatformBackend::inst().getActiveWID())); #endif } diff --git a/src/src.pro b/src/src.pro index 3158b5f..f009d9e 100644 --- a/src/src.pro +++ b/src/src.pro @@ -30,7 +30,7 @@ SOURCES += main.cpp\ cropeditor/cropscene.cpp \ uploaders/uploadersingleton.cpp \ screenshotter.cpp \ - screenshotutil.cpp \ + utils.cpp \ uploaders/default/imguruploader.cpp \ io/ioutils.cpp \ settings.cpp \ @@ -77,7 +77,7 @@ HEADERS += mainwindow.hpp \ uploaders/uploader.hpp \ uploaders/uploadersingleton.hpp \ screenshotter.hpp \ - screenshotutil.hpp \ + utils.hpp \ uploaders/default/imguruploader.hpp \ io/ioutils.hpp \ settings.hpp \ diff --git a/src/uploaders/default/imguruploader.cpp b/src/uploaders/default/imguruploader.cpp index fa6457b..f629976 100644 --- a/src/uploaders/default/imguruploader.cpp +++ b/src/uploaders/default/imguruploader.cpp @@ -8,8 +8,8 @@ #include #include #include -#include #include +#include struct SegfaultWorkaround { // I'm a scrub for doing this SegfaultWorkaround(QByteArray a, ImgurUploader *u, QString m) : byteArray(), dis(u), mime(m) { @@ -49,7 +49,7 @@ private: QByteArray byteArray; ImgurUploader *dis; QString mime; -}; +}; // I feel terrible for making this. I am sorry, reader void ImgurUploader::doUpload(QByteArray byteArray, QString format) { if (byteArray.size() > 1e+7) { @@ -88,7 +88,7 @@ void ImgurUploader::handleSend(QString auth, QString mime, QByteArray byteArray) return; } if (!result.isEmpty()) { - screenshotutil::toClipboard(result); + utils::toClipboard(result); notifications::notify(tr("KShare imgur Uploader"), tr("Uploaded to imgur!")); } else { notifications::notify(tr("KShare imgur Uploader "), diff --git a/src/screenshotutil.cpp b/src/utils.cpp similarity index 79% rename from src/screenshotutil.cpp rename to src/utils.cpp index ffe2044..c3f392a 100644 --- a/src/screenshotutil.cpp +++ b/src/utils.cpp @@ -1,4 +1,4 @@ -#include "screenshotutil.hpp" +#include "utils.hpp" #include #include @@ -8,7 +8,21 @@ #include #include -QPixmap screenshotutil::fullscreen(bool cursor) { + +QColor utils::invertColor(QColor color) { + return QColor(255 - color.red(), 255 - color.green(), 255 - color.blue()); +} + +QPixmap utils::extend(QPixmap img, int extraSize, QColor hl) { + QPixmap newImg(img.width() + extraSize * 2, img.height() + extraSize * 2); + newImg.fill(hl); + QPainter ptr(&newImg); + ptr.drawPixmap(extraSize, extraSize, img); + ptr.end(); + return newImg; +} + +QPixmap utils::fullscreen(bool cursor) { QPixmap image; QPainter painter; QPoint smallestCoordinate = smallestScreenCoordinate(); @@ -54,19 +68,19 @@ QPixmap screenshotutil::fullscreen(bool cursor) { return image; } -QPixmap screenshotutil::window(WId wid, QScreen *w) { +QPixmap utils::window(WId wid, QScreen *w) { return w->grabWindow(wid); } -void screenshotutil::toClipboard(QString value) { +void utils::toClipboard(QString value) { QApplication::clipboard()->setText(value); } -QPixmap screenshotutil::fullscreenArea(bool cursor, qreal x, qreal y, qreal w, qreal h) { +QPixmap utils::fullscreenArea(bool cursor, qreal x, qreal y, qreal w, qreal h) { return fullscreen(cursor).copy(x, y, w, h); } -QPoint screenshotutil::smallestScreenCoordinate() { +QPoint utils::smallestScreenCoordinate() { QPoint smallestCoordinate; for (QScreen *screen : QApplication::screens()) { smallestCoordinate.rx() = qMin(smallestCoordinate.x(), screen->geometry().left()); @@ -75,7 +89,7 @@ QPoint screenshotutil::smallestScreenCoordinate() { return smallestCoordinate; } -QPixmap screenshotutil::renderText(QString toRender, int padding, QColor background, QColor pen, QFont font) { +QPixmap utils::renderText(QString toRender, int padding, QColor background, QColor pen, QFont font) { QFontMetrics metric(font); QStringList lines = toRender.replace("\r", "").split('\n'); QSize resultingSize(0, padding * 2); diff --git a/src/screenshotutil.hpp b/src/utils.hpp similarity index 69% rename from src/screenshotutil.hpp rename to src/utils.hpp index 717e3f5..9458734 100644 --- a/src/screenshotutil.hpp +++ b/src/utils.hpp @@ -1,10 +1,13 @@ -#ifndef SCREENSHOTUTIL_HPP -#define SCREENSHOTUTIL_HPP +#ifndef UTILS_HPP +#define UTILS_HPP #include +#include #include -namespace screenshotutil { +namespace utils { + QColor invertColor(QColor color); + QPixmap extend(QPixmap pixmap, int extraSize = 25, QColor hl = Qt::transparent); QPixmap fullscreen(bool cursor = true); QPixmap fullscreenArea(bool cursor = true, qreal x = 0, qreal y = 0, qreal w = -1, qreal h = -1); QPixmap window(WId wid, QScreen *w = QApplication::primaryScreen()); @@ -14,4 +17,4 @@ namespace screenshotutil { renderText(QString toRender, int padding = 5, QColor background = Qt::transparent, QColor pen = Qt::white, QFont font = QFont()); } -#endif // SCREENSHOTUTIL_HPP +#endif // UTILS_HPP