diff --git a/README.md b/README.md index 62ac0a8f..1da42658 100644 --- a/README.md +++ b/README.md @@ -418,7 +418,7 @@ Also you can open and build/debug the project in a C++ IDE. For example, in Qt C ```shell # Compile-time -apt install g++ cmake build-essential qt5-default qttools5-dev-tools libqt5svg5-dev qttools5-dev +apt install g++ cmake build-essential qtbase5-dev qttools5-dev-tools libqt5svg5-dev qttools5-dev # Run-time apt install libqt5dbus5 libqt5network5 libqt5core5a libqt5widgets5 libqt5gui5 libqt5svg5 diff --git a/snapcraft.yaml b/snapcraft.yaml index 03ad90df..75e2b9e9 100644 --- a/snapcraft.yaml +++ b/snapcraft.yaml @@ -46,9 +46,10 @@ parts: - kde-frameworks-5-qt-5-15-core20 source: https://github.com/flameshot-org/flameshot.git plugin: cmake - # This cannot be enabled until the KF5 toolkit in the snap is updated - #cmake-parameters: - # - -DUSE_WAYLAND_CLIPBOARD=1 + cmake-parameters: + - -DFLAMESHOT_ICON=/snap/flameshot/current/usr/local/share/icons/hicolor/scalable/apps/flameshot.svg + # This cannot be enabled until the KF5 toolkit in the snap is updated + #- -DUSE_WAYLAND_CLIPBOARD=1 source-type: git override-pull: | snapcraftctl pull diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 06bcd396..2dd49c32 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -65,6 +65,10 @@ endif () add_executable(Flameshot::flameshot ALIAS flameshot) +if(FLAMESHOT_ICON) + target_compile_definitions(flameshot PUBLIC FLAMESHOT_ICON="${FLAMESHOT_ICON}") +endif() + if (WIN32) set_property(TARGET flameshot PROPERTY WIN32_EXECUTABLE true) if (MSVC) diff --git a/src/cli/commandlineparser.cpp b/src/cli/commandlineparser.cpp index 298c239b..8c5ef697 100644 --- a/src/cli/commandlineparser.cpp +++ b/src/cli/commandlineparser.cpp @@ -14,7 +14,7 @@ CommandLineParser::CommandLineParser() namespace { AbstractLogger out = - AbstractLogger::info(AbstractLogger::Stderr).enableMessageHeader(false); + AbstractLogger::info(AbstractLogger::Stdout).enableMessageHeader(false); AbstractLogger err = AbstractLogger::error(AbstractLogger::Stderr); auto versionOption = diff --git a/src/config/CMakeLists.txt b/src/config/CMakeLists.txt index 6e0c2507..eb9ae901 100644 --- a/src/config/CMakeLists.txt +++ b/src/config/CMakeLists.txt @@ -1,19 +1,20 @@ target_sources( flameshot PRIVATE buttonlistview.cpp + cacheutils.cpp clickablelabel.cpp - configwindow.cpp - configresolver.cpp + colorpickereditmode.cpp + colorpickereditor.cpp configerrordetails.cpp + configresolver.cpp + configwindow.cpp extendedslider.cpp filenameeditor.cpp generalconf.cpp + setshortcutwidget.cpp + shortcutswidget.cpp strftimechooserwidget.cpp styleoverride.cpp uicoloreditor.cpp - colorpickereditor.cpp visualseditor.cpp - shortcutswidget.cpp - setshortcutwidget.cpp - colorpickereditmode.cpp ) diff --git a/src/config/cacheutils.cpp b/src/config/cacheutils.cpp new file mode 100644 index 00000000..b84ead9c --- /dev/null +++ b/src/config/cacheutils.cpp @@ -0,0 +1,49 @@ +// SPDX-License-Identifier: GPL-3.0-or-later +// SPDX-FileCopyrightText: 2021 Jeremy Borgman + +#include "cacheutils.h" +#include +#include +#include +#include +#include +#include + +QString getCachePath() +{ + auto cachePath = + QStandardPaths::writableLocation(QStandardPaths::CacheLocation); + if (!QDir(cachePath).exists()) { + QDir().mkpath(cachePath); + } + return cachePath; +} + +void setLastRegion(QRect const& newRegion) +{ + auto cachePath = getCachePath() + "/region.txt"; + + QFile file(cachePath); + if (file.open(QIODevice::WriteOnly)) { + QDataStream out(&file); + out << newRegion; + file.close(); + } +} + +QRect getLastRegion() +{ + auto cachePath = getCachePath() + "/region.txt"; + QFile file(cachePath); + + QRect lastRegion; + if (file.open(QIODevice::ReadOnly)) { + QDataStream input(&file); + input >> lastRegion; + file.close(); + } else { + lastRegion = QRect(0, 0, 0, 0); + } + + return lastRegion; +} \ No newline at end of file diff --git a/src/config/cacheutils.h b/src/config/cacheutils.h new file mode 100644 index 00000000..ad82ca4a --- /dev/null +++ b/src/config/cacheutils.h @@ -0,0 +1,14 @@ +// SPDX-License-Identifier: GPL-3.0-or-later +// SPDX-FileCopyrightText: 2021 Jeremy Borgman + +#ifndef FLAMESHOT_CACHEUTILS_H +#define FLAMESHOT_CACHEUTILS_H + +class QString; +class QRect; + +QString getCachePath(); +QRect getLastRegion(); +void setLastRegion(QRect const& newRegion); + +#endif // FLAMESHOT_CACHEUTILS_H \ No newline at end of file diff --git a/src/config/generalconf.cpp b/src/config/generalconf.cpp index 69613689..448f2979 100644 --- a/src/config/generalconf.cpp +++ b/src/config/generalconf.cpp @@ -33,6 +33,7 @@ GeneralConf::GeneralConf(QWidget* parent) initScrollArea(); initShowHelp(); + initSaveLastRegion(); initShowSidePanelButton(); initShowDesktopNotification(); initShowTrayIcon(); @@ -84,6 +85,7 @@ void GeneralConf::_updateComponents(bool allowEmptySavePath) m_allowMultipleGuiInstances->setChecked(config.allowMultipleGuiInstances()); m_showMagnifier->setChecked(config.showMagnifier()); m_squareMagnifier->setChecked(config.squareMagnifier()); + m_saveLastRegion->setChecked(config.saveLastRegion()); #if !defined(Q_OS_WIN) m_autoCloseIdleDaemon->setChecked(config.autoCloseIdleDaemon()); @@ -109,6 +111,11 @@ void GeneralConf::updateComponents() _updateComponents(false); } +void GeneralConf::saveLastRegion(bool checked) +{ + ConfigHandler().setSaveLastRegion(checked); +} + void GeneralConf::showHelpChanged(bool checked) { ConfigHandler().setShowHelp(checked); @@ -235,6 +242,19 @@ void GeneralConf::initShowHelp() m_helpMessage, &QCheckBox::clicked, this, &GeneralConf::showHelpChanged); } +void GeneralConf::initSaveLastRegion() +{ + m_saveLastRegion = new QCheckBox(tr("Use last region"), this); + m_saveLastRegion->setToolTip(tr("Uses the last region as the default " + "selection for the next screenshot")); + m_scrollAreaLayout->addWidget(m_saveLastRegion); + + connect(m_saveLastRegion, + &QCheckBox::clicked, + this, + &GeneralConf::saveLastRegion); +} + void GeneralConf::initShowSidePanelButton() { m_sidePanelButton = new QCheckBox(tr("Show the side panel button"), this); diff --git a/src/config/generalconf.h b/src/config/generalconf.h index a2449881..a1178cf5 100644 --- a/src/config/generalconf.h +++ b/src/config/generalconf.h @@ -25,6 +25,7 @@ public slots: private slots: void showHelpChanged(bool checked); + void saveLastRegion(bool checked); void showSidePanelButtonChanged(bool checked); void showDesktopNotificationChanged(bool checked); void checkForUpdatesChanged(bool checked); @@ -72,6 +73,7 @@ private: void initUseJpgForClipboard(); void initUploadHistoryMax(); void initUploadClientSecret(); + void initSaveLastRegion(); void _updateComponents(bool allowEmptySavePath); @@ -91,6 +93,7 @@ private: QCheckBox* m_copyAndCloseAfterUpload; QCheckBox* m_copyPathAfterSave; QCheckBox* m_antialiasingPinZoom; + QCheckBox* m_saveLastRegion; QCheckBox* m_uploadWithoutConfirmation; QPushButton* m_importButton; QPushButton* m_exportButton; diff --git a/src/core/capturerequest.cpp b/src/core/capturerequest.cpp index eec0ceb0..2c58c5b0 100644 --- a/src/core/capturerequest.cpp +++ b/src/core/capturerequest.cpp @@ -3,16 +3,13 @@ #include "capturerequest.h" #include "confighandler.h" -#include "flameshot.h" #include "imgupload/imguploadermanager.h" #include "pinwidget.h" +#include "src/config/cacheutils.h" #include "src/utils/screenshotsaver.h" -#include "src/widgets/imguploaddialog.h" -#include "systemnotification.h" #include #include #include -#include #include #include @@ -24,7 +21,13 @@ CaptureRequest::CaptureRequest(CaptureRequest::CaptureMode mode, , m_delay(delay) , m_tasks(tasks) , m_data(std::move(data)) -{} +{ + + ConfigHandler config; + if (config.saveLastRegion()) { + setInitialSelection(getLastRegion()); + } +} CaptureRequest::CaptureMode CaptureRequest::captureMode() const { diff --git a/src/core/flameshot.cpp b/src/core/flameshot.cpp index 196e8789..cf112d79 100644 --- a/src/core/flameshot.cpp +++ b/src/core/flameshot.cpp @@ -3,7 +3,6 @@ #include "flameshot.h" #include "flameshotdaemon.h" - #if defined(Q_OS_MACOS) #include "external/QHotkey/QHotkey" #endif @@ -25,7 +24,6 @@ #include #include #include -#include #include #include #include @@ -115,8 +113,6 @@ CaptureWidget* Flameshot::gui(const CaptureRequest& req) } m_captureWindow = new CaptureWidget(req); - // m_captureWindow = new CaptureWidget(req, false); // - // debug #ifdef Q_OS_WIN m_captureWindow->show(); @@ -138,20 +134,16 @@ CaptureWidget* Flameshot::gui(const CaptureRequest& req) void Flameshot::screen(CaptureRequest req, const int screenNumber) { - if (!resolveAnyConfigErrors()) + if (!resolveAnyConfigErrors()) { return; + } bool ok = true; QScreen* screen; if (screenNumber < 0) { QPoint globalCursorPos = QCursor::pos(); -#if QT_VERSION > QT_VERSION_CHECK(5, 10, 0) screen = qApp->screenAt(globalCursorPos); -#else - screen = - qApp->screens()[qApp->desktop()->screenNumber(globalCursorPos)]; -#endif } else if (screenNumber >= qApp->screens().count()) { AbstractLogger() << QObject::tr( "Requested screen exceeds screen count"); @@ -184,8 +176,9 @@ void Flameshot::screen(CaptureRequest req, const int screenNumber) void Flameshot::full(const CaptureRequest& req) { - if (!resolveAnyConfigErrors()) + if (!resolveAnyConfigErrors()) { return; + } bool ok = true; QPixmap p(ScreenGrabber().grabEntireDesktop(ok)); @@ -203,10 +196,11 @@ void Flameshot::full(const CaptureRequest& req) void Flameshot::launcher() { - if (!resolveAnyConfigErrors()) + if (!resolveAnyConfigErrors()) { return; + } - if (!m_launcherWindow) { + if (m_launcherWindow == nullptr) { m_launcherWindow = new CaptureLauncher(); } m_launcherWindow->show(); @@ -218,10 +212,11 @@ void Flameshot::launcher() void Flameshot::config() { - if (!resolveAnyConfigErrors()) + if (!resolveAnyConfigErrors()) { return; + } - if (!m_configWindow) { + if (m_configWindow == nullptr) { m_configWindow = new ConfigWindow(); m_configWindow->show(); #if defined(Q_OS_MACOS) @@ -233,7 +228,7 @@ void Flameshot::config() void Flameshot::info() { - if (!m_infoWindow) { + if (m_infoWindow == nullptr) { m_infoWindow = new InfoWindow(); #if defined(Q_OS_MACOS) m_infoWindow->activateWindow(); @@ -416,6 +411,12 @@ void Flameshot::exportCapture(QPixmap capture, if (!(tasks & CR::UPLOAD)) { emit captureTaken(capture); } + // hacks: close a window to trigger qt's quitOnLastWindowClose + // if not create tmp_window and close, the `flameshot gui` won't exit after + // click copy button + QWidget* tmp = new QWidget(); + tmp->show(); + tmp->close(); } // STATIC ATTRIBUTES diff --git a/src/core/flameshot.h b/src/core/flameshot.h index c738a737..ec8ce98c 100644 --- a/src/core/flameshot.h +++ b/src/core/flameshot.h @@ -34,7 +34,7 @@ public: public slots: CaptureWidget* gui( const CaptureRequest& req = CaptureRequest::GRAPHICAL_MODE); - void screen(CaptureRequest req, const int screenNumber = -1); + void screen(CaptureRequest req, int const screenNumber = -1); void full(const CaptureRequest& req); void launcher(); void config(); diff --git a/src/main.cpp b/src/main.cpp index 1d4ddd1b..62d75b61 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -9,6 +9,7 @@ #include "abstractlogger.h" #include "src/cli/commandlineparser.h" +#include "src/config/cacheutils.h" #include "src/config/styleoverride.h" #include "src/core/capturerequest.h" #include "src/core/flameshot.h" @@ -23,7 +24,6 @@ #include #include #include - #if defined(Q_OS_LINUX) || defined(Q_OS_UNIX) #include "abstractlogger.h" #include "src/core/flameshotdbusadapter.h" @@ -49,12 +49,14 @@ void requestCaptureAndWait(const CaptureRequest& req) { Flameshot* flameshot = Flameshot::instance(); flameshot->requestCapture(req); - QObject::connect(flameshot, &Flameshot::captureTaken, [&](QPixmap) { - // Only useful on MacOS because each instance hosts its own widgets +#if defined(Q_OS_MACOS) + // Only useful on MacOS because each instance hosts its own widgets + QObject::connect(flameshot, &Flameshot::captureTaken, [&](const QPixmap&) { if (!FlameshotDaemon::isThisInstanceHostingWidgets()) { qApp->exit(0); } }); +#endif QObject::connect(flameshot, &Flameshot::captureFailed, []() { AbstractLogger::info() << "Screenshot aborted."; qApp->exit(1); @@ -176,6 +178,11 @@ int main(int argc, char* argv[]) CommandOption delayOption({ "d", "delay" }, QObject::tr("Delay time in milliseconds"), QStringLiteral("milliseconds")); + + CommandOption useLastRegionOption( + "last-region", + QObject::tr("Repeat screenshot with previously selected region")); + CommandOption regionOption("region", QObject::tr("Screenshot region to select"), QStringLiteral("WxH+X+Y or string")); @@ -272,6 +279,7 @@ int main(int argc, char* argv[]) mainColorOption.addChecker(colorChecker, colorErr); delayOption.addChecker(numericChecker, delayErr); regionOption.addChecker(regionChecker, regionErr); + useLastRegionOption.addChecker(booleanChecker, booleanErr); pathOption.addChecker(pathChecker, pathErr); trayOption.addChecker(booleanChecker, booleanErr); autostartOption.addChecker(booleanChecker, booleanErr); @@ -290,6 +298,7 @@ int main(int argc, char* argv[]) clipboardOption, delayOption, regionOption, + useLastRegionOption, rawImageOption, selectionOption, uploadOption, @@ -359,6 +368,7 @@ int main(int argc, char* argv[]) } int delay = parser.value(delayOption).toInt(); QString region = parser.value(regionOption); + bool useLastRegion = parser.isSet(useLastRegionOption); bool clipboard = parser.isSet(clipboardOption); bool raw = parser.isSet(rawImageOption); bool printGeometry = parser.isSet(selectionOption); @@ -367,7 +377,10 @@ int main(int argc, char* argv[]) bool acceptOnSelect = parser.isSet(acceptOnSelectOption); CaptureRequest req(CaptureRequest::GRAPHICAL_MODE, delay, path); if (!region.isEmpty()) { - req.setInitialSelection(Region().value(region).toRect()); + auto selectionRegion = Region().value(region).toRect(); + req.setInitialSelection(selectionRegion); + } else if (useLastRegion) { + req.setInitialSelection(getLastRegion()); } if (clipboard) { req.addTask(CaptureRequest::COPY); @@ -394,7 +407,6 @@ int main(int argc, char* argv[]) req.addSaveTask(); } } - requestCaptureAndWait(req); } else if (parser.isSet(fullArgument)) { // FULL // Recreate the application as a QApplication diff --git a/src/tools/circlecount/circlecounttool.cpp b/src/tools/circlecount/circlecounttool.cpp index 7d0458e7..ee238c9a 100644 --- a/src/tools/circlecount/circlecounttool.cpp +++ b/src/tools/circlecount/circlecounttool.cpp @@ -4,6 +4,7 @@ #include "circlecounttool.h" #include "colorutils.h" #include +#include namespace { #define PADDING_VALUE 2 @@ -46,10 +47,20 @@ QRect CircleCountTool::boundingRect() const return {}; } int bubble_size = size() + THICKNESS_OFFSET + PADDING_VALUE; - return { points().first.x() - bubble_size, - points().first.y() - bubble_size, - bubble_size * 2, - bubble_size * 2 }; + + int line_pos_min_x = + std::min(points().first.x() - bubble_size, points().second.x()); + int line_pos_min_y = + std::min(points().first.y() - bubble_size, points().second.y()); + int line_pos_max_x = + std::max(points().first.x() + bubble_size, points().second.x()); + int line_pos_max_y = + std::max(points().first.y() + bubble_size, points().second.y()); + + return { line_pos_min_x, + line_pos_min_y, + line_pos_max_x - line_pos_min_x, + line_pos_max_y - line_pos_min_y }; } QString CircleCountTool::name() const @@ -96,6 +107,30 @@ void CircleCountTool::process(QPainter& painter, const QPixmap& pixmap) ColorUtils::colorIsDark(color()) ? Qt::black : Qt::white; int bubble_size = size() + THICKNESS_OFFSET; + + QLineF line(points().first, points().second); + // if the mouse is outside of the bubble, draw the pointer + if (line.length() > bubble_size) { + painter.setPen(QPen(color(), 0)); + painter.setBrush(color()); + + int middleX = points().first.x(); + int middleY = points().first.y(); + + QLineF normal = line.normalVector(); + normal.setLength(bubble_size); + QPoint p1 = normal.p2().toPoint(); + QPoint p2(middleX - (p1.x() - middleX), middleY - (p1.y() - middleY)); + + QPainterPath path; + path.moveTo(points().first); + path.lineTo(p1); + path.lineTo(points().second); + path.lineTo(p2); + path.lineTo(points().first); + painter.drawPath(path); + } + painter.setPen(contrastColor); painter.setBrush(antiContrastColor); painter.drawEllipse( @@ -131,7 +166,6 @@ void CircleCountTool::process(QPainter& painter, const QPixmap& pixmap) // Draw text painter.setPen(contrastColor); painter.drawText(textRect, Qt::AlignCenter, QString::number(count())); - // restore original font, brush, and pen painter.setFont(orig_font); painter.setBrush(orig_brush); diff --git a/src/tools/text/texttool.cpp b/src/tools/text/texttool.cpp index 415451a8..798688a3 100644 --- a/src/tools/text/texttool.cpp +++ b/src/tools/text/texttool.cpp @@ -114,12 +114,12 @@ QWidget* TextTool::widget() void TextTool::closeEditor() { if (!m_widget.isNull()) { - m_widget->close(); + m_widget->hide(); delete m_widget; m_widget = nullptr; } if (!m_confW.isNull()) { - m_confW->close(); + m_confW->hide(); delete m_confW; m_confW = nullptr; } diff --git a/src/utils/abstractlogger.cpp b/src/utils/abstractlogger.cpp index 083d0fcd..3de73e28 100644 --- a/src/utils/abstractlogger.cpp +++ b/src/utils/abstractlogger.cpp @@ -63,6 +63,12 @@ AbstractLogger& AbstractLogger::sendMessage(QString msg, Channel channel) QTextStream stream(stderr); stream << messageHeader(channel, Stderr) << msg << "\n"; } + + if (m_targets & Stdout) { + QTextStream stream(stdout); + stream << messageHeader(channel, Stdout) << msg << "\n"; + } + return *this; } diff --git a/src/utils/abstractlogger.h b/src/utils/abstractlogger.h index c38c6d5b..05ce8af5 100644 --- a/src/utils/abstractlogger.h +++ b/src/utils/abstractlogger.h @@ -15,6 +15,7 @@ public: Stderr = 0x02, LogFile = 0x08, String = 0x10, + Stdout = 0x20, Default = Notification | LogFile | Stderr, }; diff --git a/src/utils/confighandler.cpp b/src/utils/confighandler.cpp index 2e7a5987..8f53cba9 100644 --- a/src/utils/confighandler.cpp +++ b/src/utils/confighandler.cpp @@ -101,9 +101,10 @@ static QMap> OPTION("savePath" ,ExistingDir ( )), OPTION("savePathFixed" ,Bool ( false )), OPTION("saveAsFileExtension" ,SaveFileExtension ( )), + OPTION("saveLastRegion" ,Bool (false )), OPTION("uploadHistoryMax" ,LowerBoundedInt (0, 25 )), OPTION("undoLimit" ,BoundedInt (0, 999, 100 )), - // Interface tab + // Interface tab OPTION("uiColor" ,Color ( {116, 0, 150} )), OPTION("contrastUiColor" ,Color ( {39, 0, 50} )), OPTION("contrastOpacity" ,BoundedInt ( 0, 255, 190 )), diff --git a/src/utils/confighandler.h b/src/utils/confighandler.h index 3e8322d2..3be5953a 100644 --- a/src/utils/confighandler.h +++ b/src/utils/confighandler.h @@ -119,7 +119,7 @@ public: CONFIG_GETTER_SETTER(squareMagnifier, setSquareMagnifier, bool) CONFIG_GETTER_SETTER(copyOnDoubleClick, setCopyOnDoubleClick, bool) CONFIG_GETTER_SETTER(uploadClientSecret, setUploadClientSecret, QString) - + CONFIG_GETTER_SETTER(saveLastRegion, setSaveLastRegion, bool) // SPECIAL CASES bool startupLaunch(); void setStartupLaunch(const bool); diff --git a/src/utils/screengrabber.cpp b/src/utils/screengrabber.cpp index b2857fd5..d0d1bec8 100644 --- a/src/utils/screengrabber.cpp +++ b/src/utils/screengrabber.cpp @@ -108,6 +108,12 @@ QPixmap ScreenGrabber::grabEntireDesktop(bool& ok) } default: ok = false; + AbstractLogger::error() + << tr("Unable to detect desktop environment (GNOME? KDE? " + "Sway? ...)"); + AbstractLogger::error() + << tr("Hint: try setting the XDG_CURRENT_DESKTOP environment " + "variable."); break; } if (!ok) { diff --git a/src/utils/systemnotification.cpp b/src/utils/systemnotification.cpp index 16c19efa..f593464a 100644 --- a/src/utils/systemnotification.cpp +++ b/src/utils/systemnotification.cpp @@ -12,6 +12,13 @@ #include "src/core/flameshotdaemon.h" #endif +// work-around for snap, which cannot install icons into +// the system folder, so instead the absolute path to the +// icon (saved somwhere in /snap/flameshot/...) is passed +#ifndef FLAMESHOT_ICON +#define FLAMESHOT_ICON "flameshot" +#endif + SystemNotification::SystemNotification(QObject* parent) : QObject(parent) , m_interface(nullptr) @@ -61,9 +68,10 @@ void SystemNotification::sendMessage(const QString& text, hintsMap[QStringLiteral("x-kde-urls")] = QStringList({ fullPath.toString() }); } + args << (qAppName()) // appname << static_cast(0) // id - << "flameshot" // icon + << FLAMESHOT_ICON // icon << title // summary << text // body << QStringList() // actions diff --git a/src/widgets/capture/capturewidget.cpp b/src/widgets/capture/capturewidget.cpp index 8dfbe03e..1f2bc24a 100644 --- a/src/widgets/capture/capturewidget.cpp +++ b/src/widgets/capture/capturewidget.cpp @@ -12,6 +12,7 @@ #include "capturewidget.h" #include "abstractlogger.h" #include "copytool.h" +#include "src/config/cacheutils.h" #include "src/core/flameshot.h" #include "src/core/qguiappcurrentscreen.h" #include "src/tools/toolfactory.h" @@ -259,6 +260,8 @@ CaptureWidget::~CaptureWidget() } #endif if (m_captureDone) { + auto lastRegion = m_selection->geometry(); + setLastRegion(lastRegion); QRect geometry(m_context.selection); geometry.setTopLeft(geometry.topLeft() + m_context.widgetOffset); Flameshot::instance()->exportCapture( @@ -436,7 +439,7 @@ void CaptureWidget::deleteToolWidgetOrClose() m_panel->hide(); } else if (m_toolWidget) { // delete toolWidget if exists - m_toolWidget->close(); + m_toolWidget->hide(); delete m_toolWidget; m_toolWidget = nullptr; } else if (m_colorPicker && m_colorPicker->isVisible()) { @@ -463,7 +466,7 @@ void CaptureWidget::releaseActiveTool() m_activeTool = nullptr; } if (m_toolWidget) { - m_toolWidget->close(); + m_toolWidget->hide(); delete m_toolWidget; m_toolWidget = nullptr; } @@ -559,19 +562,11 @@ bool CaptureWidget::startDrawObjectTool(const QPoint& pos) m_context.mousePos = pos; m_activeTool->drawStart(m_context); // TODO this is the wrong place to do this + if (m_activeTool->type() == CaptureTool::TYPE_CIRCLECOUNT) { - // While it is based on AbstractTwoPointTool it has the only one - // point and shouldn't wait for second point and move event - m_activeTool->drawEnd(m_context.mousePos); - m_activeTool->setCount(m_context.circleCount++); - - m_captureToolObjectsBackup = m_captureToolObjects; - m_captureToolObjects.append(m_activeTool); - pushObjectsStateToUndoStack(); - releaseActiveTool(); - m_mouseIsClicked = false; } + return true; } return false; @@ -1185,7 +1180,7 @@ void CaptureWidget::handleToolSignal(CaptureTool::Request r) break; } if (m_toolWidget) { - m_toolWidget->close(); + m_toolWidget->hide(); delete m_toolWidget; m_toolWidget = nullptr; } @@ -1700,7 +1695,7 @@ void CaptureWidget::redo() QRect CaptureWidget::extendedSelection() const { - if (!m_selection->isVisible()) { + if (m_selection == nullptr) { return {}; } QRect r = m_selection->geometry(); diff --git a/src/widgets/capture/selectionwidget.cpp b/src/widgets/capture/selectionwidget.cpp index 51cfc102..13919d6f 100644 --- a/src/widgets/capture/selectionwidget.cpp +++ b/src/widgets/capture/selectionwidget.cpp @@ -203,14 +203,17 @@ void SelectionWidget::parentMouseMoveEvent(QMouseEvent* e) mouseSide = getMouseSide(e->pos()); } + QPoint pos; + if (!isVisible() || !mouseSide) { show(); - m_dragStartPos = e->pos(); m_activeSide = TOPLEFT_SIDE; - setGeometry({ e->pos(), e->pos() }); + pos = m_dragStartPos; + setGeometry({ pos, pos }); + } else { + pos = e->pos(); } - QPoint pos = e->pos(); auto geom = geometry(); bool symmetryMod = qApp->keyboardModifiers() & Qt::ShiftModifier; @@ -280,7 +283,7 @@ void SelectionWidget::parentMouseMoveEvent(QMouseEvent* e) setGeometry(geom.normalized()); m_activeSide = getProperSide(m_activeSide, geom); } - m_dragStartPos = pos; + m_dragStartPos = e->pos(); } void SelectionWidget::paintEvent(QPaintEvent*) diff --git a/src/widgets/capturelauncher.cpp b/src/widgets/capturelauncher.cpp index 121bdfb8..39a6d7c0 100644 --- a/src/widgets/capturelauncher.cpp +++ b/src/widgets/capturelauncher.cpp @@ -3,15 +3,14 @@ #include "capturelauncher.h" #include "./ui_capturelauncher.h" +#include "src/config/cacheutils.h" #include "src/core/flameshot.h" #include "src/utils/globalvalues.h" #include "src/utils/screengrabber.h" #include "src/utils/screenshotsaver.h" #include "src/widgets/imagelabel.h" -#include -#include #include -#include + // https://github.com/KDE/spectacle/blob/941c1a517be82bed25d1254ebd735c29b0d2951c/src/Gui/KSWidget.cpp // https://github.com/KDE/spectacle/blob/941c1a517be82bed25d1254ebd735c29b0d2951c/src/Gui/KSMainWindow.cpp @@ -80,51 +79,18 @@ CaptureLauncher::CaptureLauncher(QDialog* parent) } }); - auto last_region = getLastRegion(); - ui->screenshotX->setText(QString::number(last_region.x())); - ui->screenshotY->setText(QString::number(last_region.y())); - ui->screenshotWidth->setText(QString::number(last_region.width())); - ui->screenshotHeight->setText(QString::number(last_region.height())); + auto lastRegion = getLastRegion(); + ui->screenshotX->setText(QString::number(lastRegion.x())); + ui->screenshotY->setText(QString::number(lastRegion.y())); + ui->screenshotWidth->setText(QString::number(lastRegion.width())); + ui->screenshotHeight->setText(QString::number(lastRegion.height())); show(); } -void CaptureLauncher::setLastRegion() -{ - auto cachePath = getCachePath() + "/region.txt"; - - QFile file(cachePath); - if (file.open(QIODevice::WriteOnly)) { - auto newRegion = QRect(ui->screenshotX->text().toInt(), - ui->screenshotY->text().toInt(), - ui->screenshotWidth->text().toInt(), - ui->screenshotHeight->text().toInt()); - QDataStream out(&file); - out << newRegion; - file.close(); - } -} - -QRect CaptureLauncher::getLastRegion() -{ - auto cachePath = getCachePath() + "/region.txt"; - QFile file(cachePath); - - QRect lastRegion; - if (file.open(QIODevice::ReadOnly)) { - QDataStream in(&file); - in >> lastRegion; - file.close(); - } else { - lastRegion = QRect(0, 0, 0, 0); - } - - return lastRegion; -} // HACK: // https://github.com/KDE/spectacle/blob/fa1e780b8bf3df3ac36c410b9ece4ace041f401b/src/Gui/KSMainWindow.cpp#L70 void CaptureLauncher::startCapture() { - setLastRegion(); ui->launchButton->setEnabled(false); hide(); @@ -205,13 +171,3 @@ CaptureLauncher::~CaptureLauncher() { delete ui; } - -QString getCachePath() -{ - auto cachePath = - QStandardPaths::writableLocation(QStandardPaths::CacheLocation); - if (!QDir(cachePath).exists()) { - QDir().mkpath(cachePath); - } - return cachePath; -} diff --git a/src/widgets/capturelauncher.h b/src/widgets/capturelauncher.h index ce273483..0e0baf03 100644 --- a/src/widgets/capturelauncher.h +++ b/src/widgets/capturelauncher.h @@ -23,13 +23,9 @@ private: Ui::CaptureLauncher* ui; void connectCaptureSlots() const; void disconnectCaptureSlots() const; - void setLastRegion(); - QRect getLastRegion(); private slots: void startCapture(); void onCaptureTaken(QPixmap const& p); void onCaptureFailed(); }; - -QString getCachePath(); \ No newline at end of file diff --git a/src/widgets/trayicon.cpp b/src/widgets/trayicon.cpp index 9d1137a7..3221118f 100644 --- a/src/widgets/trayicon.cpp +++ b/src/widgets/trayicon.cpp @@ -95,7 +95,7 @@ void TrayIcon::initMenu() { m_menu = new QMenu(); - QAction* captureAction = new QAction(tr("&Take Screenshot"), this); + auto* captureAction = new QAction(tr("&Take Screenshot"), this); connect(captureAction, &QAction::triggered, this, [this]() { #if defined(Q_OS_MACOS) auto currentMacOsVersion = QOperatingSystemVersion::current(); @@ -113,17 +113,17 @@ void TrayIcon::initMenu() }); #endif }); - QAction* launcherAction = new QAction(tr("&Open Launcher"), this); + auto* launcherAction = new QAction(tr("&Open Launcher"), this); connect(launcherAction, &QAction::triggered, Flameshot::instance(), &Flameshot::launcher); - QAction* configAction = new QAction(tr("&Configuration"), this); + auto* configAction = new QAction(tr("&Configuration"), this); connect(configAction, &QAction::triggered, Flameshot::instance(), &Flameshot::config); - QAction* infoAction = new QAction(tr("&About"), this); + auto* infoAction = new QAction(tr("&About"), this); connect( infoAction, &QAction::triggered, Flameshot::instance(), &Flameshot::info);