mirror of
https://github.com/fergalmoran/flameshot.git
synced 2025-12-22 09:51:06 +00:00
NC/Number of fixes, details in commits (#1620)
* fix - General Configuration widget has big spaces between last few options (cherry picked from commit 48b9135a8d654a388fd4d0a266e9097456d00ab7) * Set limit for Latest Uploads Max Size to 50 (cherry picked from commit ef1d83529c5e33ec3819820f3231e5c503aebf61) * Completely reworked undo/redo stack with fixes (object that was created after deleted one disappears when undo last object creating and deleting the first one and try to undo deletion) (cherry picked from commit 8d8c0b0d4a5ba8ecd7dc1c367c220642975c95d1) * - Save font on new text object creation - Remove unused variable context.circleCount (cherry picked from commit 26f7bf620849c68062838d503f8731feea8d4987) * Code refactoring - remove unused m_context.widgetDimensions (cherry picked from commit 76abc09ce07a71ae42f1826a5a1e1e35902960d5) * Make font size other tools thickness independent (cherry picked from commit 5633799fb07acaa50cae5373953e40fa85f700bc) * fix - Font parameters doesn't disappear in panel on click text item in it (cherry picked from commit 8322cbb1acae75c77d4c24b74bc366ba93497d46) * fix - Save thickness if no tool selected (cherry picked from commit 862f2f4806a0c8d1309daae6a3371f6bd2fc5e5c) * fix - Line thickness has not required padding after saving configuration, code refactoring remove number of unused '#define PADDING_VALUE' (cherry picked from commit 294c89ad4fc9d1230942f8b7aa0a13deff7ab1eb) Co-authored-by: Yuriy Puchkov <yuriy.puchkov@namecheap.com>
This commit is contained in:
@@ -38,6 +38,8 @@ GeneralConf::GeneralConf(QWidget* parent)
|
||||
initUploadHistoryMaxSize();
|
||||
initUndoLimit();
|
||||
|
||||
m_layout->addStretch();
|
||||
|
||||
// this has to be at the end
|
||||
initConfigButtons();
|
||||
updateComponents();
|
||||
@@ -267,7 +269,6 @@ void GeneralConf::initHistoryConfirmationToDelete()
|
||||
void GeneralConf::initConfigButtons()
|
||||
{
|
||||
QHBoxLayout* buttonLayout = new QHBoxLayout();
|
||||
m_layout->addStretch();
|
||||
QGroupBox* box = new QGroupBox(tr("Configuration File"));
|
||||
box->setFlat(true);
|
||||
box->setLayout(buttonLayout);
|
||||
@@ -364,7 +365,6 @@ void GeneralConf::initSaveAfterCopy()
|
||||
QGroupBox* box = new QGroupBox(tr("Save Path"));
|
||||
box->setFlat(true);
|
||||
m_layout->addWidget(box);
|
||||
m_layout->addStretch();
|
||||
|
||||
QVBoxLayout* vboxLayout = new QVBoxLayout();
|
||||
box->setLayout(vboxLayout);
|
||||
@@ -378,9 +378,6 @@ void GeneralConf::initSaveAfterCopy()
|
||||
}
|
||||
m_savePath = new QLineEdit(path, this);
|
||||
m_savePath->setDisabled(true);
|
||||
// #if QT_DEPRECATED_SINCE(5, 13)
|
||||
// QT_DEPRECATED_X("Use QPalette::windowText() instead")
|
||||
// inline const QBrush &foreground() const { return windowText(); }
|
||||
QString foreground = this->palette().windowText().color().name();
|
||||
m_savePath->setStyleSheet(QStringLiteral("color: %1").arg(foreground));
|
||||
pathLayout->addWidget(m_savePath);
|
||||
@@ -414,7 +411,6 @@ void GeneralConf::initUploadHistoryMaxSize()
|
||||
QGroupBox* box = new QGroupBox(tr("Latest Uploads Max Size"));
|
||||
box->setFlat(true);
|
||||
m_layout->addWidget(box);
|
||||
m_layout->addStretch();
|
||||
|
||||
QVBoxLayout* vboxLayout = new QVBoxLayout();
|
||||
box->setLayout(vboxLayout);
|
||||
@@ -422,7 +418,7 @@ void GeneralConf::initUploadHistoryMaxSize()
|
||||
int max = ConfigHandler().uploadHistoryMaxSizeValue();
|
||||
|
||||
m_uploadHistoryMaxSize = new QSpinBox(this);
|
||||
m_uploadHistoryMaxSize->setMaximum(1000);
|
||||
m_uploadHistoryMaxSize->setMaximum(50);
|
||||
m_uploadHistoryMaxSize->setValue(max);
|
||||
QString foreground = this->palette().windowText().color().name();
|
||||
m_uploadHistoryMaxSize->setStyleSheet(
|
||||
@@ -445,7 +441,6 @@ 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);
|
||||
|
||||
@@ -6,8 +6,6 @@
|
||||
#include <QScreen>
|
||||
#include <cmath>
|
||||
|
||||
#define PADDING_VALUE_DEFAULT 2
|
||||
|
||||
namespace {
|
||||
|
||||
const double ADJ_UNIT = std::atan(1.0);
|
||||
@@ -97,8 +95,7 @@ void AbstractTwoPointTool::thicknessChanged(int th)
|
||||
void AbstractTwoPointTool::paintMousePreview(QPainter& painter,
|
||||
const CaptureContext& context)
|
||||
{
|
||||
painter.setPen(
|
||||
QPen(context.color, context.thickness + PADDING_VALUE_DEFAULT));
|
||||
painter.setPen(QPen(context.color, context.thickness));
|
||||
painter.drawLine(context.mousePos, context.mousePos);
|
||||
}
|
||||
|
||||
@@ -107,7 +104,7 @@ void AbstractTwoPointTool::drawStart(const CaptureContext& context)
|
||||
colorChanged(context.color);
|
||||
m_points.first = context.mousePos;
|
||||
m_points.second = context.mousePos;
|
||||
thicknessChanged(context.thickness + PADDING_VALUE_DEFAULT);
|
||||
thicknessChanged(context.thickness);
|
||||
}
|
||||
|
||||
QPoint AbstractTwoPointTool::adjustedVector(QPoint v) const
|
||||
|
||||
@@ -5,9 +5,6 @@
|
||||
#include <cmath>
|
||||
|
||||
namespace {
|
||||
|
||||
#define PADDING_VALUE 2
|
||||
|
||||
const int ArrowWidth = 10;
|
||||
const int ArrowHeight = 18;
|
||||
|
||||
|
||||
@@ -16,19 +16,16 @@ struct CaptureContext
|
||||
QPixmap origScreenshot;
|
||||
// Selection area
|
||||
QRect selection;
|
||||
// Widget dimensions
|
||||
QRect widgetDimensions;
|
||||
// Selected tool color
|
||||
QColor color;
|
||||
// Path where the content has to be saved
|
||||
QString savePath;
|
||||
// Ofset of the capture widget based on the system's screen (top-left)
|
||||
// Offset of the capture widget based on the system's screen (top-left)
|
||||
QPoint widgetOffset;
|
||||
// Mouse position inside the widget
|
||||
QPoint mousePos;
|
||||
// Value of the desired thickness
|
||||
int thickness;
|
||||
int circleCount;
|
||||
// Mode of the capture widget
|
||||
bool fullscreen;
|
||||
|
||||
|
||||
@@ -4,10 +4,6 @@
|
||||
#include "circletool.h"
|
||||
#include <QPainter>
|
||||
|
||||
namespace {
|
||||
#define PADDING_VALUE 2
|
||||
}
|
||||
|
||||
CircleTool::CircleTool(QObject* parent)
|
||||
: AbstractTwoPointTool(parent)
|
||||
{
|
||||
|
||||
@@ -139,7 +139,6 @@ void CircleCountTool::paintMousePreview(QPainter& painter,
|
||||
void CircleCountTool::drawStart(const CaptureContext& context)
|
||||
{
|
||||
AbstractTwoPointTool::drawStart(context);
|
||||
setCount(context.circleCount);
|
||||
}
|
||||
|
||||
void CircleCountTool::pressed(const CaptureContext& context)
|
||||
|
||||
@@ -4,12 +4,6 @@
|
||||
#include "linetool.h"
|
||||
#include <QPainter>
|
||||
|
||||
namespace {
|
||||
|
||||
#define PADDING_VALUE 2
|
||||
|
||||
}
|
||||
|
||||
LineTool::LineTool(QObject* parent)
|
||||
: AbstractTwoPointTool(parent)
|
||||
{
|
||||
|
||||
@@ -4,8 +4,6 @@
|
||||
#include "penciltool.h"
|
||||
#include <QPainter>
|
||||
|
||||
#define PADDING_VALUE 2
|
||||
|
||||
PencilTool::PencilTool(QObject* parent)
|
||||
: AbstractPathTool(parent)
|
||||
{}
|
||||
@@ -54,7 +52,7 @@ void PencilTool::paintMousePreview(QPainter& painter,
|
||||
void PencilTool::drawStart(const CaptureContext& context)
|
||||
{
|
||||
m_color = context.color;
|
||||
thicknessChanged(context.thickness + PADDING_VALUE);
|
||||
thicknessChanged(context.thickness);
|
||||
m_points.append(context.mousePos);
|
||||
m_pathArea.setTopLeft(context.mousePos);
|
||||
m_pathArea.setBottomRight(context.mousePos);
|
||||
|
||||
@@ -6,10 +6,6 @@
|
||||
#include <QPainterPath>
|
||||
#include <cmath>
|
||||
|
||||
namespace {
|
||||
#define PADDING_VALUE 2
|
||||
}
|
||||
|
||||
RectangleTool::RectangleTool(QObject* parent)
|
||||
: AbstractTwoPointTool(parent)
|
||||
{
|
||||
|
||||
@@ -4,10 +4,6 @@
|
||||
#include "selectiontool.h"
|
||||
#include <QPainter>
|
||||
|
||||
namespace {
|
||||
#define PADDING_VALUE 2
|
||||
}
|
||||
|
||||
SelectionTool::SelectionTool(QObject* parent)
|
||||
: AbstractTwoPointTool(parent)
|
||||
{
|
||||
|
||||
@@ -3,12 +3,12 @@
|
||||
|
||||
#include "textconfig.h"
|
||||
#include "src/utils/colorutils.h"
|
||||
#include "src/utils/confighandler.h"
|
||||
#include "src/utils/pathinfo.h"
|
||||
#include <QComboBox>
|
||||
#include <QFontDatabase>
|
||||
#include <QHBoxLayout>
|
||||
#include <QPushButton>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
TextConfig::TextConfig(QWidget* parent)
|
||||
: QWidget(parent)
|
||||
@@ -28,8 +28,7 @@ TextConfig::TextConfig(QWidget* parent)
|
||||
this,
|
||||
&TextConfig::fontFamilyChanged);
|
||||
m_fontsCB->addItems(fontDB.families());
|
||||
// TODO save family in config
|
||||
setFontFamily(font().family());
|
||||
setFontFamily(ConfigHandler().fontFamily());
|
||||
|
||||
QString iconPrefix = ColorUtils::colorIsDark(palette().windowText().color())
|
||||
? PathInfo::blackIconPath()
|
||||
@@ -82,7 +81,8 @@ TextConfig::TextConfig(QWidget* parent)
|
||||
|
||||
void TextConfig::setFontFamily(const QString& fontFamily)
|
||||
{
|
||||
m_fontsCB->setCurrentIndex(m_fontsCB->findText(fontFamily));
|
||||
m_fontsCB->setCurrentIndex(
|
||||
m_fontsCB->findText(fontFamily.isEmpty() ? font().family() : fontFamily));
|
||||
}
|
||||
|
||||
void TextConfig::setUnderline(const bool u)
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
// SPDX-FileCopyrightText: 2017-2019 Alejandro Sirgo Rica & Contributors
|
||||
|
||||
#include "texttool.h"
|
||||
#include "src/utils/confighandler.h"
|
||||
#include "textconfig.h"
|
||||
#include "textwidget.h"
|
||||
|
||||
@@ -11,7 +12,12 @@
|
||||
TextTool::TextTool(QObject* parent)
|
||||
: CaptureTool(parent)
|
||||
, m_size(1)
|
||||
{}
|
||||
{
|
||||
QString fontFamily = ConfigHandler().fontFamily();
|
||||
if (!fontFamily.isEmpty()) {
|
||||
m_font.setFamily(ConfigHandler().fontFamily());
|
||||
}
|
||||
}
|
||||
|
||||
TextTool::~TextTool()
|
||||
{
|
||||
@@ -253,6 +259,9 @@ void TextTool::updateText(const QString& s)
|
||||
void TextTool::updateFamily(const QString& s)
|
||||
{
|
||||
m_font.setFamily(s);
|
||||
if (m_textOld.isEmpty()) {
|
||||
ConfigHandler().setFontFamily(m_font.family());
|
||||
}
|
||||
if (m_widget) {
|
||||
m_widget->setFont(m_font);
|
||||
}
|
||||
|
||||
@@ -186,6 +186,20 @@ void ConfigHandler::setDrawColor(const QColor& c)
|
||||
m_settings.setValue(QStringLiteral("drawColor"), c.name());
|
||||
}
|
||||
|
||||
void ConfigHandler::setFontFamily(const QString& fontFamily)
|
||||
{
|
||||
m_settings.setValue(QStringLiteral("fontFamily"), fontFamily);
|
||||
}
|
||||
|
||||
const QString& ConfigHandler::fontFamily()
|
||||
{
|
||||
m_strRes.clear();
|
||||
if (m_settings.contains(QStringLiteral("fontFamily"))) {
|
||||
m_strRes = m_settings.value(QStringLiteral("fontFamily")).toString();
|
||||
}
|
||||
return m_strRes;
|
||||
}
|
||||
|
||||
bool ConfigHandler::showHelpValue()
|
||||
{
|
||||
bool res = true;
|
||||
@@ -289,7 +303,7 @@ void ConfigHandler::setDisabledTrayIcon(const bool disabledTrayIcon)
|
||||
|
||||
int ConfigHandler::drawThicknessValue()
|
||||
{
|
||||
int res = 0;
|
||||
int res = 3;
|
||||
if (m_settings.contains(QStringLiteral("drawThickness"))) {
|
||||
res = m_settings.value(QStringLiteral("drawThickness")).toInt();
|
||||
}
|
||||
@@ -301,6 +315,20 @@ void ConfigHandler::setDrawThickness(const int thickness)
|
||||
m_settings.setValue(QStringLiteral("drawThickness"), thickness);
|
||||
}
|
||||
|
||||
int ConfigHandler::drawFontSizeValue()
|
||||
{
|
||||
int res = 8;
|
||||
if (m_settings.contains(QStringLiteral("drawFontSize"))) {
|
||||
res = m_settings.value(QStringLiteral("drawFontSize")).toInt();
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
void ConfigHandler::setDrawFontSize(const int fontSize)
|
||||
{
|
||||
m_settings.setValue(QStringLiteral("drawFontSize"), fontSize);
|
||||
}
|
||||
|
||||
bool ConfigHandler::keepOpenAppLauncherValue()
|
||||
{
|
||||
return m_settings.value(QStringLiteral("keepOpenAppLauncher")).toBool();
|
||||
|
||||
@@ -34,6 +34,9 @@ public:
|
||||
QColor drawColorValue();
|
||||
void setDrawColor(const QColor&);
|
||||
|
||||
void setFontFamily(const QString&);
|
||||
const QString& fontFamily();
|
||||
|
||||
bool showHelpValue();
|
||||
void setShowHelp(const bool);
|
||||
|
||||
@@ -53,6 +56,9 @@ public:
|
||||
int drawThicknessValue();
|
||||
void setDrawThickness(const int);
|
||||
|
||||
int drawFontSizeValue();
|
||||
void setDrawFontSize(const int);
|
||||
|
||||
bool keepOpenAppLauncherValue();
|
||||
void setKeepOpenAppLauncher(const bool);
|
||||
|
||||
|
||||
@@ -7,10 +7,16 @@
|
||||
#define SEARCH_RADIUS_FAR 5
|
||||
#define SEARCH_RADIUS_TEXT_HANDICAP 3
|
||||
|
||||
CaptureToolObjects::CaptureToolObjects(QObject* parent)
|
||||
: QObject(parent)
|
||||
{}
|
||||
|
||||
void CaptureToolObjects::append(const QPointer<CaptureTool>& captureTool)
|
||||
{
|
||||
m_captureToolObjects.append(captureTool);
|
||||
m_imageCache.clear();
|
||||
if (!captureTool.isNull()) {
|
||||
m_captureToolObjects.append(captureTool->copy(captureTool->parent()));
|
||||
m_imageCache.clear();
|
||||
}
|
||||
}
|
||||
|
||||
QPointer<CaptureTool> CaptureToolObjects::at(int index)
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
class CaptureToolObjects : public QObject
|
||||
{
|
||||
public:
|
||||
explicit CaptureToolObjects(QObject* parent = nullptr) { Q_UNUSED(parent) };
|
||||
explicit CaptureToolObjects(QObject* parent = nullptr);
|
||||
QList<QPointer<CaptureTool>> captureToolObjects();
|
||||
void append(const QPointer<CaptureTool>& captureTool);
|
||||
void removeAt(int index);
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
#include "src/widgets/capture/notifierbox.h"
|
||||
#include "src/widgets/orientablepushbutton.h"
|
||||
#include "src/widgets/panel/sidepanelwidget.h"
|
||||
#include "src/widgets/panel/utilitypanel.h"
|
||||
#include "src/widgets/updatenotificationwidget.h"
|
||||
#include <QApplication>
|
||||
#include <QDateTime>
|
||||
@@ -62,14 +63,13 @@ CaptureWidget::CaptureWidget(uint id,
|
||||
, m_lastMouseWheel(0)
|
||||
, m_updateNotificationWidget(nullptr)
|
||||
, m_activeToolIsMoved(false)
|
||||
, m_lastPressedUndo(false)
|
||||
, m_lastPressedRedo(false)
|
||||
, m_panel(nullptr)
|
||||
, m_sidePanel(nullptr)
|
||||
, m_selection(nullptr)
|
||||
, m_existingObjectIsChanged(false)
|
||||
, m_startMove(false)
|
||||
{
|
||||
m_undoStack.setUndoLimit(ConfigHandler().undoLimit() + 1);
|
||||
m_undoStack.setUndoLimit(ConfigHandler().undoLimit());
|
||||
|
||||
// Base config of the widget
|
||||
m_eventFilter = new HoverEventFilter(this);
|
||||
@@ -87,7 +87,6 @@ CaptureWidget::CaptureWidget(uint id,
|
||||
setMouseTracking(true);
|
||||
initContext(savePath, fullScreen);
|
||||
initShortcuts();
|
||||
m_context.circleCount = 1;
|
||||
#if (defined(Q_OS_WIN) || defined(Q_OS_MACOS))
|
||||
// Top left of the whole set of screens
|
||||
QPoint topLeft(0, 0);
|
||||
@@ -197,7 +196,6 @@ CaptureWidget::~CaptureWidget()
|
||||
} else {
|
||||
emit captureFailed(m_id);
|
||||
}
|
||||
m_config.setDrawThickness(m_context.thickness);
|
||||
}
|
||||
|
||||
// redefineButtons retrieves the buttons configured to be shown with the
|
||||
@@ -333,6 +331,7 @@ void CaptureWidget::releaseActiveTool()
|
||||
void CaptureWidget::uncheckActiveTool()
|
||||
{
|
||||
// uncheck active tool
|
||||
m_panel->setToolWidget(nullptr);
|
||||
m_activeButton->setColor(m_uiColor);
|
||||
m_activeButton = nullptr;
|
||||
releaseActiveTool();
|
||||
@@ -369,10 +368,15 @@ void CaptureWidget::paintEvent(QPaintEvent* paintEvent)
|
||||
|
||||
void CaptureWidget::showColorPicker(const QPoint& pos)
|
||||
{
|
||||
// Reset object selection if mouse pos is not in selection area
|
||||
// Try to select new object if current pos out of active object
|
||||
auto toolItem = activeToolObject();
|
||||
if (toolItem && !toolItem->selectionRect().contains(pos)) {
|
||||
m_panel->setActiveLayer(-1);
|
||||
if (!toolItem || toolItem && !toolItem->selectionRect().contains(pos)) {
|
||||
selectToolItemAtPos(pos);
|
||||
}
|
||||
|
||||
// save current state for undo/redo stack
|
||||
if (m_panel->activeLayerIndex() >= 0) {
|
||||
m_captureToolObjectsBackup = m_captureToolObjects;
|
||||
}
|
||||
|
||||
// Call color picker
|
||||
@@ -409,9 +413,13 @@ bool CaptureWidget::startDrawObjectTool(const QPoint& pos)
|
||||
// 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_captureToolObjectsBackup = m_captureToolObjects;
|
||||
m_captureToolObjects.append(m_activeTool);
|
||||
pushObjectsStateToUndoStack();
|
||||
releaseActiveTool();
|
||||
drawToolsData();
|
||||
|
||||
m_mouseIsClicked = false;
|
||||
}
|
||||
return true;
|
||||
@@ -421,12 +429,9 @@ bool CaptureWidget::startDrawObjectTool(const QPoint& pos)
|
||||
|
||||
void CaptureWidget::pushObjectsStateToUndoStack()
|
||||
{
|
||||
m_existingObjectIsChanged = false;
|
||||
// push zero state to be able to do a complete undo
|
||||
if (m_undoStack.count() == 0 || m_undoStack.index() == 0) {
|
||||
m_undoStack.push(new ModificationCommand(this, m_captureToolObjects));
|
||||
}
|
||||
m_undoStack.push(new ModificationCommand(this, m_captureToolObjects));
|
||||
m_undoStack.push(new ModificationCommand(
|
||||
this, m_captureToolObjects, m_captureToolObjectsBackup));
|
||||
m_captureToolObjectsBackup.clear();
|
||||
}
|
||||
|
||||
int CaptureWidget::selectToolItemAtPos(const QPoint& pos)
|
||||
@@ -472,6 +477,7 @@ void CaptureWidget::mousePressEvent(QMouseEvent* e)
|
||||
return;
|
||||
}
|
||||
showColorPicker(m_mousePressedPos);
|
||||
return;
|
||||
} else if (e->button() == Qt::LeftButton) {
|
||||
m_showInitialMsg = false;
|
||||
m_mouseIsClicked = true;
|
||||
@@ -522,6 +528,7 @@ void CaptureWidget::mouseDoubleClickEvent(QMouseEvent* event)
|
||||
if (m_activeTool && m_activeTool->nameID() == ToolType::TEXT) {
|
||||
m_mouseIsClicked = false;
|
||||
m_context.mousePos = *m_activeTool->pos();
|
||||
m_captureToolObjectsBackup = m_captureToolObjects;
|
||||
m_activeTool->setEditMode(true);
|
||||
drawToolsData(true, false);
|
||||
m_mouseIsClicked = false;
|
||||
@@ -560,8 +567,12 @@ void CaptureWidget::mouseMoveEvent(QMouseEvent* e)
|
||||
m_activeToolOffsetToMouseOnStart =
|
||||
e->pos() - *activeTool->pos();
|
||||
}
|
||||
activeTool->move(e->pos() - m_activeToolOffsetToMouseOnStart);
|
||||
if (!m_activeToolIsMoved) {
|
||||
// save state before movement for undo stack
|
||||
m_captureToolObjectsBackup = m_captureToolObjects;
|
||||
}
|
||||
m_activeToolIsMoved = true;
|
||||
activeTool->move(e->pos() - m_activeToolOffsetToMouseOnStart);
|
||||
drawToolsData(false);
|
||||
}
|
||||
} else if (m_mouseIsClicked &&
|
||||
@@ -673,12 +684,14 @@ void CaptureWidget::mouseReleaseEvent(QMouseEvent* e)
|
||||
{
|
||||
if (e->button() == Qt::LeftButton && m_colorPicker->isVisible()) {
|
||||
// Color picker
|
||||
if (m_colorPicker->isVisible() && m_panel->activeLayerIndex() >= 0 &&
|
||||
m_context.color.isValid()) {
|
||||
pushObjectsStateToUndoStack();
|
||||
}
|
||||
m_colorPicker->hide();
|
||||
if (!m_context.color.isValid()) {
|
||||
m_context.color = ConfigHandler().drawColorValue();
|
||||
m_panel->show();
|
||||
} else if (m_panel->activeLayerIndex() >= 0) {
|
||||
pushObjectsStateToUndoStack();
|
||||
}
|
||||
} else if (m_mouseIsClicked) {
|
||||
if (m_activeTool) {
|
||||
@@ -691,13 +704,12 @@ void CaptureWidget::mouseReleaseEvent(QMouseEvent* e)
|
||||
}
|
||||
} else {
|
||||
if (m_activeToolIsMoved) {
|
||||
m_activeToolIsMoved = false;
|
||||
pushObjectsStateToUndoStack();
|
||||
}
|
||||
|
||||
// Try to select existing tool if it was in the selection area but
|
||||
// need to select another one
|
||||
if (e->pos() == m_mousePressedPos && !m_activeToolIsMoved &&
|
||||
m_activeButton.isNull()) {
|
||||
} else if (e->pos() == m_mousePressedPos &&
|
||||
m_activeButton.isNull()) {
|
||||
// Try to select existing tool if it was in the selection area
|
||||
// but need to select another one
|
||||
m_panel->setActiveLayer(
|
||||
m_captureToolObjects.find(e->pos(), size()));
|
||||
}
|
||||
@@ -832,7 +844,10 @@ void CaptureWidget::wheelEvent(QWheelEvent* e)
|
||||
auto toolItem = activeToolObject();
|
||||
if (toolItem) {
|
||||
toolItem->thicknessChanged(m_context.thickness);
|
||||
m_existingObjectIsChanged = true;
|
||||
if (!m_existingObjectIsChanged) {
|
||||
m_captureToolObjectsBackup = m_captureToolObjects;
|
||||
m_existingObjectIsChanged = true;
|
||||
}
|
||||
}
|
||||
emit thicknessChanged(m_context.thickness);
|
||||
}
|
||||
@@ -840,7 +855,6 @@ void CaptureWidget::wheelEvent(QWheelEvent* e)
|
||||
void CaptureWidget::resizeEvent(QResizeEvent* e)
|
||||
{
|
||||
QWidget::resizeEvent(e);
|
||||
m_context.widgetDimensions = rect();
|
||||
m_context.widgetOffset = mapToGlobal(QPoint(0, 0));
|
||||
if (!m_context.fullscreen) {
|
||||
m_panel->setFixedHeight(height());
|
||||
@@ -856,7 +870,6 @@ void CaptureWidget::moveEvent(QMoveEvent* e)
|
||||
|
||||
void CaptureWidget::initContext(const QString& savePath, bool fullscreen)
|
||||
{
|
||||
m_context.widgetDimensions = rect();
|
||||
m_context.color = m_config.drawColorValue();
|
||||
m_context.savePath = savePath;
|
||||
m_context.widgetOffset = mapToGlobal(QPoint(0, 0));
|
||||
@@ -927,28 +940,30 @@ void CaptureWidget::initPanel()
|
||||
this,
|
||||
&CaptureWidget::updateActiveLayer);
|
||||
|
||||
SidePanelWidget* sidePanel = new SidePanelWidget(&m_context.screenshot);
|
||||
connect(sidePanel,
|
||||
m_sidePanel = new SidePanelWidget(&m_context.screenshot);
|
||||
connect(m_sidePanel,
|
||||
&SidePanelWidget::colorChanged,
|
||||
this,
|
||||
&CaptureWidget::setDrawColor);
|
||||
connect(sidePanel,
|
||||
connect(m_sidePanel,
|
||||
&SidePanelWidget::thicknessChanged,
|
||||
this,
|
||||
&CaptureWidget::setDrawThickness);
|
||||
connect(this,
|
||||
&CaptureWidget::colorChanged,
|
||||
sidePanel,
|
||||
m_sidePanel,
|
||||
&SidePanelWidget::updateColor);
|
||||
connect(this,
|
||||
&CaptureWidget::thicknessChanged,
|
||||
sidePanel,
|
||||
m_sidePanel,
|
||||
&SidePanelWidget::updateThickness);
|
||||
connect(
|
||||
sidePanel, &SidePanelWidget::togglePanel, m_panel, &UtilityPanel::toggle);
|
||||
sidePanel->colorChanged(m_context.color);
|
||||
sidePanel->thicknessChanged(m_context.thickness);
|
||||
m_panel->pushWidget(sidePanel);
|
||||
connect(m_sidePanel,
|
||||
&SidePanelWidget::togglePanel,
|
||||
m_panel,
|
||||
&UtilityPanel::toggle);
|
||||
m_sidePanel->colorChanged(m_context.color);
|
||||
m_sidePanel->thicknessChanged(m_context.thickness);
|
||||
m_panel->pushWidget(m_sidePanel);
|
||||
|
||||
// Fill undo/redo/history list widget
|
||||
m_panel->fillCaptureTools(m_captureToolObjects.captureToolObjects());
|
||||
@@ -1034,11 +1049,24 @@ void CaptureWidget::setState(CaptureToolButton* b)
|
||||
m_activeButton->setColor(m_uiColor);
|
||||
m_activeButton = nullptr;
|
||||
}
|
||||
loadDrawThickness();
|
||||
updateCursor();
|
||||
update(); // clear mouse preview
|
||||
}
|
||||
}
|
||||
|
||||
void CaptureWidget::loadDrawThickness()
|
||||
{
|
||||
if ((m_activeButton && m_activeButton->tool() &&
|
||||
m_activeButton->tool()->nameID() == ToolType::TEXT) ||
|
||||
(m_activeTool && m_activeTool->nameID() == ToolType::TEXT)) {
|
||||
m_context.thickness = m_config.drawFontSizeValue();
|
||||
} else {
|
||||
m_context.thickness = m_config.drawThicknessValue();
|
||||
}
|
||||
m_sidePanel->thicknessChanged(m_context.thickness);
|
||||
}
|
||||
|
||||
void CaptureWidget::processTool(CaptureTool* t)
|
||||
{
|
||||
auto backup = m_activeTool;
|
||||
@@ -1172,6 +1200,7 @@ void CaptureWidget::updateActiveLayer(const int& layer)
|
||||
commitCurrentTool();
|
||||
}
|
||||
if (m_existingObjectIsChanged) {
|
||||
m_existingObjectIsChanged = false;
|
||||
pushObjectsStateToUndoStack();
|
||||
}
|
||||
drawToolsData(false, true);
|
||||
@@ -1183,6 +1212,7 @@ void CaptureWidget::removeToolObject(int index)
|
||||
if (index >= 0 && index < m_captureToolObjects.size()) {
|
||||
const ToolType currentToolType =
|
||||
m_captureToolObjects.at(index)->nameID();
|
||||
m_captureToolObjectsBackup = m_captureToolObjects;
|
||||
m_captureToolObjects.removeAt(index);
|
||||
if (currentToolType == ToolType::CIRCLECOUNT) {
|
||||
// Do circle count reindex
|
||||
@@ -1197,7 +1227,6 @@ void CaptureWidget::removeToolObject(int index)
|
||||
}
|
||||
circleCount++;
|
||||
}
|
||||
m_context.circleCount = circleCount;
|
||||
}
|
||||
pushObjectsStateToUndoStack();
|
||||
drawToolsData();
|
||||
@@ -1207,7 +1236,15 @@ void CaptureWidget::removeToolObject(int index)
|
||||
void CaptureWidget::setDrawThickness(const int& t)
|
||||
{
|
||||
m_context.thickness = qBound(1, t, 100);
|
||||
ConfigHandler().setDrawThickness(m_context.thickness);
|
||||
// save draw thickness for text and other tool separately
|
||||
if (m_activeButton) {
|
||||
if (m_activeButton->tool() &&
|
||||
m_activeButton->tool()->nameID() == ToolType::TEXT) {
|
||||
m_config.setDrawFontSize(m_context.thickness);
|
||||
} else {
|
||||
m_config.setDrawThickness(m_context.thickness);
|
||||
}
|
||||
}
|
||||
|
||||
auto toolItem = activeToolObject();
|
||||
if (toolItem) {
|
||||
@@ -1419,11 +1456,6 @@ void CaptureWidget::updateCursor()
|
||||
void CaptureWidget::pushToolToStack()
|
||||
{
|
||||
// append current tool to the new state
|
||||
bool isChanged = true;
|
||||
if (m_activeTool && m_activeTool->editMode()) {
|
||||
m_activeTool->setEditMode(false);
|
||||
isChanged = m_activeTool->isChanged();
|
||||
}
|
||||
if (m_activeTool && m_activeButton) {
|
||||
disconnect(this,
|
||||
&CaptureWidget::colorChanged,
|
||||
@@ -1437,12 +1469,24 @@ void CaptureWidget::pushToolToStack()
|
||||
disconnect(m_panel->toolWidget(), nullptr, m_activeTool, nullptr);
|
||||
}
|
||||
|
||||
m_captureToolObjects.append(m_activeTool);
|
||||
releaseActiveTool();
|
||||
}
|
||||
// disable signal connect for updating layer because it may call this
|
||||
// function again on text objects
|
||||
disconnect(m_panel,
|
||||
&UtilityPanel::layerChanged,
|
||||
this,
|
||||
&CaptureWidget::updateActiveLayer);
|
||||
|
||||
if (isChanged) {
|
||||
m_captureToolObjectsBackup = m_captureToolObjects;
|
||||
m_captureToolObjects.append(m_activeTool);
|
||||
pushObjectsStateToUndoStack();
|
||||
releaseActiveTool();
|
||||
drawToolsData();
|
||||
|
||||
// restore signal connection for updating layer
|
||||
connect(m_panel,
|
||||
&UtilityPanel::layerChanged,
|
||||
this,
|
||||
&CaptureWidget::updateActiveLayer);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1451,12 +1495,10 @@ void CaptureWidget::drawToolsData(bool updateLayersPanel, bool drawSelection)
|
||||
QPixmap pixmapItem = m_context.origScreenshot.copy();
|
||||
QPainter painter(&pixmapItem);
|
||||
painter.setRenderHint(QPainter::Antialiasing);
|
||||
int index = 0;
|
||||
m_context.circleCount = 1;
|
||||
int circleCount = 1;
|
||||
for (auto toolItem : m_captureToolObjects.captureToolObjects()) {
|
||||
if (toolItem->nameID() == ToolType::CIRCLECOUNT) {
|
||||
toolItem->setCount(m_context.circleCount);
|
||||
m_context.circleCount++;
|
||||
toolItem->setCount(circleCount++);
|
||||
}
|
||||
toolItem->process(painter, pixmapItem);
|
||||
}
|
||||
@@ -1564,33 +1606,14 @@ void CaptureWidget::setCaptureToolObjects(
|
||||
|
||||
void CaptureWidget::undo()
|
||||
{
|
||||
// FIXME - m_lastPressedUndo and m_lastPressedRedo is a brutal hack, cannot
|
||||
// understand why first undo/redo has no effect so need to do it twice if it
|
||||
// is the firs operation
|
||||
if (!m_lastPressedUndo) {
|
||||
m_undoStack.undo();
|
||||
}
|
||||
m_lastPressedUndo = true;
|
||||
m_lastPressedRedo = false;
|
||||
m_undoStack.undo();
|
||||
if (m_undoStack.index() == 0 && m_captureToolObjects.size() > 0) {
|
||||
m_lastPressedUndo = false;
|
||||
m_captureToolObjects.clear();
|
||||
drawToolsData();
|
||||
}
|
||||
drawToolsData();
|
||||
}
|
||||
|
||||
void CaptureWidget::redo()
|
||||
{
|
||||
// FIXME - m_lastPressedUndo and m_lastPressedRedo is a brutal hack, cannot
|
||||
// understand why first undo/redo has no effect so need to do it twice if it
|
||||
// is the firs operation
|
||||
if (!m_lastPressedRedo) {
|
||||
m_undoStack.redo();
|
||||
}
|
||||
m_lastPressedUndo = false;
|
||||
m_lastPressedRedo = true;
|
||||
m_undoStack.redo();
|
||||
drawToolsData();
|
||||
}
|
||||
|
||||
QRect CaptureWidget::extendedSelection() const
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
#include "src/tools/capturetool.h"
|
||||
#include "src/utils/confighandler.h"
|
||||
#include "src/widgets/capture/selectionwidget.h"
|
||||
#include "src/widgets/panel/utilitypanel.h"
|
||||
#include <QPointer>
|
||||
#include <QUndoStack>
|
||||
#include <QWidget>
|
||||
@@ -32,6 +31,8 @@ class ColorPicker;
|
||||
class NotifierBox;
|
||||
class HoverEventFilter;
|
||||
class UpdateNotificationWidget;
|
||||
class UtilityPanel;
|
||||
class SidePanelWidget;
|
||||
|
||||
class CaptureWidget : public QWidget
|
||||
{
|
||||
@@ -107,6 +108,7 @@ protected:
|
||||
void moveEvent(QMoveEvent* moveEvent) override;
|
||||
|
||||
private:
|
||||
void loadDrawThickness();
|
||||
void pushObjectsStateToUndoStack();
|
||||
void releaseActiveTool();
|
||||
void uncheckActiveTool();
|
||||
@@ -169,6 +171,7 @@ private:
|
||||
|
||||
ButtonHandler* m_buttonHandler;
|
||||
UtilityPanel* m_panel;
|
||||
SidePanelWidget* m_sidePanel;
|
||||
ColorPicker* m_colorPicker;
|
||||
ConfigHandler m_config;
|
||||
NotifierBox* m_notifierBox;
|
||||
@@ -180,6 +183,7 @@ private:
|
||||
uint m_id;
|
||||
|
||||
CaptureToolObjects m_captureToolObjects;
|
||||
CaptureToolObjects m_captureToolObjectsBackup;
|
||||
|
||||
QPoint m_mousePressedPos;
|
||||
QPoint m_activeToolOffsetToMouseOnStart;
|
||||
@@ -191,8 +195,4 @@ private:
|
||||
// For start moving after more than X offset
|
||||
QPoint m_startMovePos;
|
||||
bool m_startMove;
|
||||
|
||||
// TODO - should be remove after fixing undo()/redo() functions
|
||||
bool m_lastPressedUndo;
|
||||
bool m_lastPressedRedo;
|
||||
};
|
||||
|
||||
@@ -6,15 +6,17 @@
|
||||
|
||||
ModificationCommand::ModificationCommand(
|
||||
CaptureWidget* captureWidget,
|
||||
const CaptureToolObjects& captureToolObjects)
|
||||
const CaptureToolObjects& captureToolObjects,
|
||||
const CaptureToolObjects& captureToolObjectsBackup)
|
||||
: m_captureWidget(captureWidget)
|
||||
{
|
||||
m_captureToolObjects = captureToolObjects;
|
||||
m_captureToolObjectsBackup = captureToolObjectsBackup;
|
||||
}
|
||||
|
||||
void ModificationCommand::undo()
|
||||
{
|
||||
m_captureWidget->setCaptureToolObjects(m_captureToolObjects);
|
||||
m_captureWidget->setCaptureToolObjects(m_captureToolObjectsBackup);
|
||||
}
|
||||
|
||||
void ModificationCommand::redo()
|
||||
|
||||
@@ -13,13 +13,15 @@ class ModificationCommand : public QUndoCommand
|
||||
{
|
||||
public:
|
||||
ModificationCommand(CaptureWidget* captureWidget,
|
||||
const CaptureToolObjects& captureToolObjects);
|
||||
const CaptureToolObjects& captureToolObjects,
|
||||
const CaptureToolObjects& captureToolObjectsBackup);
|
||||
|
||||
virtual void undo() override;
|
||||
virtual void redo() override;
|
||||
|
||||
private:
|
||||
CaptureToolObjects m_captureToolObjects;
|
||||
CaptureToolObjects m_captureToolObjectsBackup;
|
||||
CaptureWidget* m_captureWidget;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user