Просмотр исходного кода

NC/Optimisations and bug fixes for objects editing (#1600)

* Optimise undo/redo for thickness, do not save every change on mouse wheel, save just the result

(cherry picked from commit c0bd74790e086dcde1c242a31e27f992a04c07e2)

* fix - In some cases undo/redo stack has excess steps (root cause is in the start move object event on a small not noticeable mouse move)

(cherry picked from commit 912f39f38083e368979f34ef14821979c34482bb)

* fix - It is impossible to remove an object using the "Undo the latest modification" button on second attempt (full undo, draw something, full undo again)

(cherry picked from commit a7f77a130a497ac6fdecd59eb43c889dcc6cbe1a)

* fix - Picked font family in the text editing tool is applied to the autoincrement tool

(cherry picked from commit 11c5eb29b1078bd6aba91fe7a74c2682767ad47c)

* Add git hash to version in the about dialog

(cherry picked from commit b4dbf52b3217b51614100bd307046772a37dc484)

* Add configuration option to limit undo steps

(cherry picked from commit f13cbecabb172060b196a535348f145457ad2f0f)

* Object delete operation is not registered on the undo stack

(cherry picked from commit 5c966cb5d3702a4d735dd542ad03a80899250b4a)

* fix - Unable to draw an object from second attempt after ColorPicker was called

(cherry picked from commit 49a119886fec253376703e8aa2386e16bc23cbcf)

* fix - App freezes and then crashes when changing object line thickness via Active thickness slider in the tool settings

(cherry picked from commit 26fd64f1c333f70c67282630362cbc5fc8427a39)

* fix - set min and max values for thickness slider to 1-100

(cherry picked from commit 6d8661666e4e199a3c29f991d52bef73ec36129c)

* fix - Crash on Move Tool button with an active Text editor

(cherry picked from commit 461f95da3afda56c0e9693e768e86b18d056eecc)

* fix - Text is not modified when picking it as object in the list

(cherry picked from commit 366bb0928b430d442dc67299353f7dc5ceb743b4)

* fix - Text modification cannot be undone
fix - Object that was created after the text object disappears after undo editing text

(cherry picked from commit 79b2fb92aca65b177cffb386db141d30551a2b1c)

* fix - Text is not saved if picking any object in the objects list without clicking at the empty space

(cherry picked from commit 4679a744a3d2498fe27379f89d48b347a34ae0dc)

* Last available undo step reset everything to the beginning

(cherry picked from commit 4af7423d00cfaa9feabc905400aa3ac30fc4a3ea)

* Missed changes (cherry-pick) for switching ColorPicker behaviour (right mouse click and hold to right mouse click and left click)

Co-authored-by: Yuriy Puchkov <yuriy.puchkov@namecheap.com>
Yurii Puchkov 3 лет назад
Родитель
Сommit
df5760c15a

+ 1 - 1
CMakeLists.txt

@@ -9,7 +9,7 @@ set(GIT_API_URL "https://api.github.com/repos/flameshot-org/flameshot/releases/l
 # set(GIT_API_URL "https://api.github.com/repos/namecheap/flameshot/releases/latest")
 
 # TODO - fix it for all linux distros
-# find_package (Git)
+#find_package (Git)
 #if (GIT_FOUND)
 #  message("git found: ${GIT_EXECUTABLE} in version     ${GIT_VERSION_STRING}")
 #

+ 11 - 0
src/CMakeLists.txt

@@ -197,6 +197,17 @@ if (WIN32)
     endif ()
 endif ()
 
+find_package (Git)
+if (GIT_FOUND)
+    message("git found: ${GIT_EXECUTABLE} in version     ${GIT_VERSION_STRING}")
+    execute_process(COMMAND ${GIT_EXECUTABLE} rev-parse --short HEAD OUTPUT_VARIABLE FLAMESHOT_GIT_HASH)
+    string(REGEX REPLACE "\r*\n$" "" FLAMESHOT_GIT_HASH "${FLAMESHOT_GIT_HASH}")
+    target_compile_definitions(flameshot PRIVATE FLAMESHOT_GIT_HASH="${FLAMESHOT_GIT_HASH}")
+    message("FLAMESHOT_GIT_HASH: ${FLAMESHOT_GIT_HASH}")
+else()
+    target_compile_definitions(flameshot PRIVATE FLAMESHOT_GIT_HASH="-")
+    message("git command is not found")
+endif ()
 target_compile_definitions(flameshot PRIVATE APP_PREFIX="${CMAKE_INSTALL_PREFIX}")
 target_compile_definitions(flameshot PRIVATE APP_VERSION="v${PROJECT_VERSION}")
 target_compile_definitions(flameshot PRIVATE IMGUR_CLIENT_ID="313baf0c7b4d3ff")

+ 33 - 1
src/config/generalconf.cpp

@@ -19,6 +19,7 @@
 GeneralConf::GeneralConf(QWidget* parent)
   : QWidget(parent)
   , m_historyConfirmationToDelete(nullptr)
+  , m_undoLimit(nullptr)
 {
     m_layout = new QVBoxLayout(this);
     m_layout->setAlignment(Qt::AlignTop);
@@ -35,6 +36,7 @@ GeneralConf::GeneralConf(QWidget* parent)
     initUseJpgForClipboard();
     initSaveAfterCopy();
     initUploadHistoryMaxSize();
+    initUndoLimit();
 
     // this has to be at the end
     initConfigButtons();
@@ -54,6 +56,7 @@ void GeneralConf::updateComponents()
     m_copyPathAfterSave->setChecked(config.copyPathAfterSaveEnabled());
     m_useJpgForClipboard->setChecked(config.useJpgForClipboard());
     m_uploadHistoryMaxSize->setValue(config.uploadHistoryMaxSizeValue());
+    m_undoLimit->setValue(config.undoLimit());
 
     if (!config.savePath().isEmpty()) {
         m_savePath->setText(config.savePath());
@@ -182,6 +185,7 @@ void GeneralConf::setActualFormData()
     m_historyConfirmationToDelete->setChecked(
       config.historyConfirmationToDelete());
     m_uploadHistoryMaxSize->setValue(config.uploadHistoryMaxSizeValue());
+    m_undoLimit->setValue(config.undoLimit());
     m_useJpgForClipboard->setChecked(config.useJpgForClipboard());
 }
 
@@ -428,7 +432,6 @@ void GeneralConf::initUploadHistoryMaxSize()
             SIGNAL(valueChanged(int)),
             this,
             SLOT(uploadHistoryMaxSizeChanged(int)));
-
     vboxLayout->addWidget(m_uploadHistoryMaxSize);
 }
 
@@ -437,6 +440,35 @@ void GeneralConf::uploadHistoryMaxSizeChanged(int max)
     ConfigHandler().setUploadHistoryMaxSize(max);
 }
 
+void GeneralConf::initUndoLimit()
+{
+    QGroupBox* box = new QGroupBox(tr("Undo limit"));
+    box->setFlat(true);
+    m_layout->addWidget(box);
+    m_layout->addStretch();
+
+    QVBoxLayout* vboxLayout = new QVBoxLayout();
+    box->setLayout(vboxLayout);
+
+    int limit = ConfigHandler().undoLimit();
+
+    m_undoLimit = new QSpinBox(this);
+    m_undoLimit->setMinimum(1);
+    m_undoLimit->setMaximum(999);
+    m_undoLimit->setValue(limit);
+    QString foreground = this->palette().windowText().color().name();
+    m_undoLimit->setStyleSheet(QStringLiteral("color: %1").arg(foreground));
+
+    connect(m_undoLimit, SIGNAL(valueChanged(int)), this, SLOT(undoLimit(int)));
+
+    vboxLayout->addWidget(m_undoLimit);
+}
+
+void GeneralConf::undoLimit(int limit)
+{
+    ConfigHandler().setUndoLimit(limit);
+}
+
 void GeneralConf::initUseJpgForClipboard()
 {
     m_useJpgForClipboard =

+ 3 - 0
src/config/generalconf.h

@@ -30,6 +30,7 @@ private slots:
     void autostartChanged(bool checked);
     void historyConfirmationToDelete(bool checked);
     void uploadHistoryMaxSizeChanged(int max);
+    void undoLimit(int limit);
     void saveAfterCopyChanged(bool checked);
     void changeSavePath();
     void importConfiguration();
@@ -47,6 +48,7 @@ private:
     void initShowTrayIcon();
     void initHistoryConfirmationToDelete();
     void initUploadHistoryMaxSize();
+    void initUndoLimit();
     void initConfigButtons();
     void initCheckForUpdates();
     void initAutostart();
@@ -79,4 +81,5 @@ private:
     QCheckBox* m_historyConfirmationToDelete;
     QCheckBox* m_useJpgForClipboard;
     QSpinBox* m_uploadHistoryMaxSize;
+    QSpinBox* m_undoLimit;
 };

+ 0 - 2
src/core/qguiappcurrentscreen.cpp

@@ -1,7 +1,5 @@
 // SPDX-License-Identifier: GPL-3.0-or-later
 // SPDX-FileCopyrightText: 2021 Yuriy Puchkov <yuriy.puchkov@namecheap.com>
-//
-// Created by yuriypuchkov on 09.02.2021.
 
 #include "qguiappcurrentscreen.h"
 #include <QCursor>

+ 0 - 2
src/core/qguiappcurrentscreen.h

@@ -1,7 +1,5 @@
 // SPDX-License-Identifier: GPL-3.0-or-later
 // SPDX-FileCopyrightText: 2021 Yuriy Puchkov <yuriy.puchkov@namecheap.com>
-//
-// Created by yuriypuchkov on 09.02.2021.
 
 #ifndef FLAMESHOT_QGUIAPPCURRENTSCREEN_H
 #define FLAMESHOT_QGUIAPPCURRENTSCREEN_H

+ 0 - 7
src/imgur.pri

@@ -1,7 +0,0 @@
-# Use default Imgur client_id if user did not pass
-# this variable to qmake
-isEmpty(IMGUR_CLIENT_ID) {
-    IMGUR_CLIENT_ID = "313baf0c7b4d3ff"
-}
-
-DEFINES += IMGUR_CLIENT_ID=\\\"$${IMGUR_CLIENT_ID}\\\"

+ 3 - 3
src/tools/capturetool.h

@@ -72,9 +72,6 @@ public:
         REQ_CAPTURE_DONE_OK,
         // Instance this->widget()'s widget inside the editor under the mouse.
         REQ_ADD_CHILD_WIDGET,
-        // Instance this->widget()'s widget as a window which closes after
-        // closing the editor.
-        REQ_ADD_CHILD_WINDOW,
         // Instance this->widget()'s widget which handles its own lifetime.
         REQ_ADD_EXTERNAL_WIDGETS,
         // increase tool size for all tools
@@ -129,6 +126,9 @@ public:
     virtual void setEditMode(bool b) { m_editMode = b; };
     virtual bool editMode() { return m_editMode; };
 
+    // return true if object was change after editMode
+    virtual bool isChanged() { return true; };
+
     // Counter for all object types (currently is used for the CircleCounter
     // only)
     virtual void setCount(int count) { m_count = count; };

+ 17 - 0
src/tools/text/texttool.cpp

@@ -174,6 +174,8 @@ void TextTool::process(QPainter& painter, const QPixmap& pixmap)
         return;
     }
     const int val = 5;
+    QFont orig_font = painter.font();
+    QPen orig_pen = painter.pen();
     QFontMetrics fm(m_font);
     QSize size(fm.boundingRect(QRect(), 0, m_text).size());
     size.setWidth(size.width() + val * 2);
@@ -185,6 +187,8 @@ void TextTool::process(QPainter& painter, const QPixmap& pixmap)
     if (!editMode()) {
         painter.drawText(m_textArea + QMargins(-val, -val, val, val), m_text);
     }
+    painter.setFont(orig_font);
+    painter.setPen(orig_pen);
 }
 
 void TextTool::drawObjectSelection(QPainter& painter)
@@ -296,3 +300,16 @@ const QPoint* TextTool::pos()
     m_currentPos = m_textArea.topLeft();
     return &m_currentPos;
 }
+
+void TextTool::setEditMode(bool b)
+{
+    if (b) {
+        m_textOld = m_text;
+    }
+    CaptureTool::setEditMode(b);
+}
+
+bool TextTool::isChanged()
+{
+    return QString::compare(m_text, m_textOld, Qt::CaseInsensitive) != 0;
+}

+ 4 - 0
src/tools/text/texttool.h

@@ -38,6 +38,9 @@ public:
     const QPoint* pos() override;
     void drawObjectSelection(QPainter& painter) override;
 
+    void setEditMode(bool b) override;
+    bool isChanged() override;
+
 protected:
     void copyParams(const TextTool* from, TextTool* to);
     ToolType nameID() const override;
@@ -64,6 +67,7 @@ private:
 
     QFont m_font;
     QString m_text;
+    QString m_textOld;
     int m_size;
     QColor m_color;
     QRect m_textArea;

Некоторые файлы не были показаны из-за большого количества измененных файлов