From da49ed556f06f54ed92bbd1be7be3fa15075a240 Mon Sep 17 00:00:00 2001 From: Alfredo Ramos Date: Wed, 10 Oct 2018 16:34:42 -0500 Subject: [PATCH] [WIP] Add line thickness to side panel (#374) * Add thickness slider * Fix enums compatibility * Rename ColorPickerWidget to SidePanelWidget --- flameshot.pro | 4 +- src/widgets/capture/capturebutton.h | 7 ++- src/widgets/capture/capturewidget.cpp | 28 +++++++--- src/widgets/capture/capturewidget.h | 5 +- ...orpickerwidget.cpp => sidepanelwidget.cpp} | 52 +++++++++++++------ ...{colorpickerwidget.h => sidepanelwidget.h} | 10 +++- translations/Internationalization_ca.ts | 8 +-- translations/Internationalization_es.ts | 8 +-- translations/Internationalization_fr.ts | 8 +-- translations/Internationalization_ja.ts | 8 +-- translations/Internationalization_ka.ts | 8 +-- translations/Internationalization_pl.ts | 8 +-- translations/Internationalization_pt_br.ts | 8 +-- translations/Internationalization_ru.ts | 8 +-- translations/Internationalization_tr.ts | 8 +-- translations/Internationalization_zh_CN.ts | 8 +-- translations/Internationalization_zh_TW.ts | 8 +-- 17 files changed, 119 insertions(+), 75 deletions(-) rename src/widgets/panel/{colorpickerwidget.cpp => sidepanelwidget.cpp} (75%) rename src/widgets/panel/{colorpickerwidget.h => sidepanelwidget.h} (85%) diff --git a/flameshot.pro b/flameshot.pro index 72eaaa1c..62e67ffa 100644 --- a/flameshot.pro +++ b/flameshot.pro @@ -140,7 +140,7 @@ SOURCES += src/main.cpp \ src/tools/text/textwidget.cpp \ src/core/capturerequest.cpp \ src/tools/text/textconfig.cpp \ - src/widgets/panel/colorpickerwidget.cpp + src/widgets/panel/sidepanelwidget.cpp HEADERS += src/widgets/capture/buttonhandler.h \ src/widgets/infowindow.h \ @@ -212,7 +212,7 @@ HEADERS += src/widgets/capture/buttonhandler.h \ src/tools/text/textwidget.h \ src/core/capturerequest.h \ src/tools/text/textconfig.h \ - src/widgets/panel/colorpickerwidget.h + src/widgets/panel/sidepanelwidget.h unix:!macx { SOURCES += src/core/flameshotdbusadapter.cpp \ diff --git a/src/widgets/capture/capturebutton.h b/src/widgets/capture/capturebutton.h index a3a23968..8c97fcc3 100644 --- a/src/widgets/capture/capturebutton.h +++ b/src/widgets/capture/capturebutton.h @@ -27,7 +27,6 @@ class CaptureTool; class CaptureButton : public QPushButton { Q_OBJECT - Q_ENUMS(ButtonType) public: // Don't forget to add the new types to CaptureButton::iterableButtonTypes @@ -54,6 +53,12 @@ public: TYPE_TEXT = 18, }; +#if QT_VERSION < QT_VERSION_CHECK(5, 5, 0) + Q_ENUMS(ButtonType) +#else + Q_ENUM(ButtonType) +#endif + CaptureButton() = delete; explicit CaptureButton(const ButtonType, QWidget *parent = nullptr); diff --git a/src/widgets/capture/capturewidget.cpp b/src/widgets/capture/capturewidget.cpp index b988a2cb..9bc4f626 100644 --- a/src/widgets/capture/capturewidget.cpp +++ b/src/widgets/capture/capturewidget.cpp @@ -23,7 +23,7 @@ #include "capturewidget.h" #include "src/widgets/capture/hovereventfilter.h" -#include "src/widgets/panel/colorpickerwidget.h" +#include "src/widgets/panel/sidepanelwidget.h" #include "src/utils/colorutils.h" #include "src/utils/globalvalues.h" #include "src/widgets/capture/notifierbox.h" @@ -541,16 +541,21 @@ void CaptureWidget::initPanel() { panelRect.setWidth(m_colorPicker->width() * 3); m_panel->setGeometry(panelRect); - ColorPickerWidget *colorPicker = - new ColorPickerWidget(&m_context.screenshot); - connect(colorPicker, &ColorPickerWidget::colorChanged, + SidePanelWidget *sidePanel = + new SidePanelWidget(&m_context.screenshot); + connect(sidePanel, &SidePanelWidget::colorChanged, this, &CaptureWidget::setDrawColor); + connect(sidePanel, &SidePanelWidget::thicknessChanged, + this, &CaptureWidget::setDrawThickness); connect(this, &CaptureWidget::colorChanged, - colorPicker, &ColorPickerWidget::updateColor); - connect(colorPicker, &ColorPickerWidget::togglePanel, + sidePanel, &SidePanelWidget::updateColor); + connect(this, &CaptureWidget::thicknessChanged, + sidePanel, &SidePanelWidget::updateThickness); + connect(sidePanel, &SidePanelWidget::togglePanel, m_panel, &UtilityPanel::toggle); - colorPicker->colorChanged(m_context.color); - m_panel->pushWidget(colorPicker); + sidePanel->colorChanged(m_context.color); + sidePanel->thicknessChanged(m_context.thickness); + m_panel->pushWidget(sidePanel); m_panel->pushWidget(new QUndoView(&m_undoStack, this)); } @@ -692,6 +697,13 @@ void CaptureWidget::setDrawColor(const QColor &c) { emit colorChanged(c); } +void CaptureWidget::setDrawThickness(const int &t) +{ + m_context.thickness = qBound(0, t, 100); + ConfigHandler().setdrawThickness(m_context.thickness); + emit thicknessChanged(m_context.thickness); +} + void CaptureWidget::leftResize() { if (m_selection->isVisible() && m_selection->geometry().right() > m_selection->geometry().left()) { m_selection->setGeometry(m_selection->geometry() + QMargins(0, 0, -1, 0)); diff --git a/src/widgets/capture/capturewidget.h b/src/widgets/capture/capturewidget.h index eb638706..2e8c8033 100644 --- a/src/widgets/capture/capturewidget.h +++ b/src/widgets/capture/capturewidget.h @@ -14,10 +14,10 @@ // // You should have received a copy of the GNU General Public License // along with Flameshot. If not, see . - + // Based on Lightscreen areadialog.h, Copyright 2017 Christian Kaiser // released under the GNU GPL2 - + // Based on KDE's KSnapshot regiongrabber.cpp, revision 796531, Copyright 2007 Luca Gugelmann // released under the GNU LGPL @@ -89,6 +89,7 @@ private slots: void processTool(CaptureTool *t); void handleButtonSignal(CaptureTool::Request r); void setDrawColor(const QColor &c); + void setDrawThickness(const int &t); protected: void paintEvent(QPaintEvent *); diff --git a/src/widgets/panel/colorpickerwidget.cpp b/src/widgets/panel/sidepanelwidget.cpp similarity index 75% rename from src/widgets/panel/colorpickerwidget.cpp rename to src/widgets/panel/sidepanelwidget.cpp index 30fe48f4..47cbc88a 100644 --- a/src/widgets/panel/colorpickerwidget.cpp +++ b/src/widgets/panel/sidepanelwidget.cpp @@ -15,7 +15,7 @@ // You should have received a copy of the GNU General Public License // along with Flameshot. If not, see . -#include "colorpickerwidget.h" +#include "sidepanelwidget.h" #include "src/utils/pathinfo.h" #include "src/utils/colorutils.h" #include @@ -23,12 +23,13 @@ #include #include #include +#include class QColorPickingEventFilter : public QObject { public: explicit QColorPickingEventFilter( - ColorPickerWidget *pw, QObject *parent = 0) : + SidePanelWidget *pw, QObject *parent = nullptr) : QObject(parent), m_pw(pw) {} bool eventFilter(QObject *, QEvent *event) override { @@ -48,22 +49,30 @@ public: } private: - ColorPickerWidget *m_pw; + SidePanelWidget *m_pw; }; //////////////////////// -ColorPickerWidget::ColorPickerWidget(QPixmap *p, QWidget *parent) : +SidePanelWidget::SidePanelWidget(QPixmap *p, QWidget *parent) : QWidget(parent), m_pixmap(p), m_eventFilter(nullptr) { m_layout = new QVBoxLayout(this); QFormLayout *colorForm = new QFormLayout(); + m_thicknessSlider = new QSlider(Qt::Horizontal); + m_thicknessSlider->setValue(m_thickness); m_colorLabel = new QLabel(); m_colorLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); + colorForm->addRow(tr("Active thickness:"), m_thicknessSlider); colorForm->addRow(tr("Active color:"), m_colorLabel); m_layout->addLayout(colorForm); + connect(m_thicknessSlider, &QSlider::sliderReleased, + this, &SidePanelWidget::updateCurrentThickness); + connect(this, &SidePanelWidget::thicknessChanged, + this, &SidePanelWidget::updateThickness); + QColor background = this->palette().background().color(); bool isDark = ColorUtils::colorIsDark(background); QString modifier = isDark ? PathInfo::whiteIconPath() : @@ -72,32 +81,43 @@ ColorPickerWidget::ColorPickerWidget(QPixmap *p, QWidget *parent) : m_colorGrabButton = new QPushButton(grabIcon, ""); updateGrabButton(false); connect(m_colorGrabButton, &QPushButton::pressed, - this, &ColorPickerWidget::colorGrabberActivated); + this, &SidePanelWidget::colorGrabberActivated); m_layout->addWidget(m_colorGrabButton); m_colorWheel = new color_widgets::ColorWheel(this); m_colorWheel->setColor(m_color); connect(m_colorWheel, &color_widgets::ColorWheel::mouseReleaseOnColor, this, - &ColorPickerWidget::colorChanged); + &SidePanelWidget::colorChanged); connect(m_colorWheel, &color_widgets::ColorWheel::colorChanged, this, - &ColorPickerWidget::updateColorNoWheel); + &SidePanelWidget::updateColorNoWheel); m_layout->addWidget(m_colorWheel); } -void ColorPickerWidget::updateColor(const QColor &c) { +void SidePanelWidget::updateColor(const QColor &c) { m_color = c; m_colorLabel->setStyleSheet( QString("QLabel { background-color : %1; }").arg(c.name())); m_colorWheel->setColor(m_color); } -void ColorPickerWidget::updateColorNoWheel(const QColor &c) { +void SidePanelWidget::updateThickness(const int &t) +{ + m_thickness = qBound(0, t, 100); + m_thicknessSlider->setValue(m_thickness); +} + +void SidePanelWidget::updateColorNoWheel(const QColor &c) { m_color = c; m_colorLabel->setStyleSheet( QString("QLabel { background-color : %1; }").arg(c.name())); } -void ColorPickerWidget::colorGrabberActivated() { +void SidePanelWidget::updateCurrentThickness() +{ + emit thicknessChanged(m_thicknessSlider->value()); +} + +void SidePanelWidget::colorGrabberActivated() { grabKeyboard(); grabMouse(Qt::CrossCursor); setMouseTracking(true); @@ -109,7 +129,7 @@ void ColorPickerWidget::colorGrabberActivated() { updateGrabButton(true); } -void ColorPickerWidget::releaseColorGrab() { +void SidePanelWidget::releaseColorGrab() { setMouseTracking(false); removeEventFilter(m_eventFilter); releaseMouse(); @@ -118,7 +138,7 @@ void ColorPickerWidget::releaseColorGrab() { updateGrabButton(false); } -QColor ColorPickerWidget::grabPixmapColor(const QPoint &p) { +QColor SidePanelWidget::grabPixmapColor(const QPoint &p) { QColor c; if (m_pixmap) { QPixmap pixel = m_pixmap->copy(QRect(p, p)); @@ -127,7 +147,7 @@ QColor ColorPickerWidget::grabPixmapColor(const QPoint &p) { return c; } -bool ColorPickerWidget::handleKeyPress(QKeyEvent *e) { +bool SidePanelWidget::handleKeyPress(QKeyEvent *e) { if (e->key() == Qt::Key_Space) { emit togglePanel(); } else if (e->key() == Qt::Key_Escape) { @@ -141,7 +161,7 @@ bool ColorPickerWidget::handleKeyPress(QKeyEvent *e) { return true; } -bool ColorPickerWidget::handleMouseButtonPressed(QMouseEvent *e) { +bool SidePanelWidget::handleMouseButtonPressed(QMouseEvent *e) { if (m_colorGrabButton->geometry().contains(e->pos()) || e->button() == Qt::RightButton) { @@ -154,12 +174,12 @@ bool ColorPickerWidget::handleMouseButtonPressed(QMouseEvent *e) { return true; } -bool ColorPickerWidget::handleMouseMove(QMouseEvent *e) { +bool SidePanelWidget::handleMouseMove(QMouseEvent *e) { updateColorNoWheel(grabPixmapColor(e->globalPos())); return true; } -void ColorPickerWidget::updateGrabButton(const bool activated) { +void SidePanelWidget::updateGrabButton(const bool activated) { if (activated) { m_colorGrabButton->setText(tr("Press ESC to cancel")); } else { diff --git a/src/widgets/panel/colorpickerwidget.h b/src/widgets/panel/sidepanelwidget.h similarity index 85% rename from src/widgets/panel/colorpickerwidget.h rename to src/widgets/panel/sidepanelwidget.h index 6cd5544a..34c2d031 100644 --- a/src/widgets/panel/colorpickerwidget.h +++ b/src/widgets/panel/sidepanelwidget.h @@ -24,23 +24,27 @@ class QVBoxLayout; class QPushButton; class QLabel; class QColorPickingEventFilter; +class QSlider; -class ColorPickerWidget : public QWidget { +class SidePanelWidget : public QWidget { Q_OBJECT friend class QColorPickingEventFilter; public: - explicit ColorPickerWidget(QPixmap *p, QWidget *parent = nullptr); + explicit SidePanelWidget(QPixmap *p, QWidget *parent = nullptr); signals: void colorChanged(const QColor &c); + void thicknessChanged(const int &t); void togglePanel(); public slots: void updateColor(const QColor &c); + void updateThickness(const int &t); private slots: void updateColorNoWheel(const QColor &c); + void updateCurrentThickness(); private slots: void colorGrabberActivated(); @@ -62,6 +66,8 @@ private: QPixmap *m_pixmap; QColor m_colorBackup; QColor m_color; + QSlider *m_thicknessSlider; + int m_thickness; QColorPickingEventFilter *m_eventFilter; }; diff --git a/translations/Internationalization_ca.ts b/translations/Internationalization_ca.ts index 81b2738a..0f973179 100644 --- a/translations/Internationalization_ca.ts +++ b/translations/Internationalization_ca.ts @@ -106,19 +106,19 @@ Press Space to open the side panel. - ColorPickerWidget + SidePanelWidget - + Active color: - + Press ESC to cancel - + Grab Color diff --git a/translations/Internationalization_es.ts b/translations/Internationalization_es.ts index 06ddf62e..c28962c0 100644 --- a/translations/Internationalization_es.ts +++ b/translations/Internationalization_es.ts @@ -109,19 +109,19 @@ Presiona Espacion para abrir el panel lateral. - ColorPickerWidget + SidePanelWidget - + Active color: Color activo: - + Press ESC to cancel Presiona Esc para cancelar - + Grab Color Tomar Color diff --git a/translations/Internationalization_fr.ts b/translations/Internationalization_fr.ts index 7edac782..950963d6 100644 --- a/translations/Internationalization_fr.ts +++ b/translations/Internationalization_fr.ts @@ -105,19 +105,19 @@ Press Space to open the side panel. - ColorPickerWidget + SidePanelWidget - + Active color: - + Press ESC to cancel - + Grab Color diff --git a/translations/Internationalization_ja.ts b/translations/Internationalization_ja.ts index 5dda0ec9..68e48198 100644 --- a/translations/Internationalization_ja.ts +++ b/translations/Internationalization_ja.ts @@ -109,19 +109,19 @@ Enter を押すと画面をキャプチャー。 - ColorPickerWidget + SidePanelWidget - + Active color: アクティブな色: - + Press ESC to cancel ESC でキャンセル - + Grab Color 色の取得 diff --git a/translations/Internationalization_ka.ts b/translations/Internationalization_ka.ts index e6f4435f..8a115be5 100644 --- a/translations/Internationalization_ka.ts +++ b/translations/Internationalization_ka.ts @@ -105,19 +105,19 @@ Press Space to open the side panel. - ColorPickerWidget + SidePanelWidget - + Active color: - + Press ESC to cancel - + Grab Color diff --git a/translations/Internationalization_pl.ts b/translations/Internationalization_pl.ts index 56e027d1..852ca0a5 100644 --- a/translations/Internationalization_pl.ts +++ b/translations/Internationalization_pl.ts @@ -108,19 +108,19 @@ Spacja, aby pokazać panel boczny. - ColorPickerWidget + SidePanelWidget - + Active color: Aktywny kolor: - + Press ESC to cancel Wciśnij ESC, aby anulować - + Grab Color Pobierz kolor diff --git a/translations/Internationalization_pt_br.ts b/translations/Internationalization_pt_br.ts index 39afd7dd..1acba130 100644 --- a/translations/Internationalization_pt_br.ts +++ b/translations/Internationalization_pt_br.ts @@ -109,19 +109,19 @@ Pressione espaço abrir o painel lateral. - ColorPickerWidget + SidePanelWidget - + Active color: Cor ativa: - + Press ESC to cancel Presione Esc para cancelar - + Grab Color Usar Cor diff --git a/translations/Internationalization_ru.ts b/translations/Internationalization_ru.ts index 7a21b389..e6a7c9f2 100644 --- a/translations/Internationalization_ru.ts +++ b/translations/Internationalization_ru.ts @@ -105,19 +105,19 @@ Press Space to open the side panel. - ColorPickerWidget + SidePanelWidget - + Active color: - + Press ESC to cancel - + Grab Color diff --git a/translations/Internationalization_tr.ts b/translations/Internationalization_tr.ts index a676c66e..92962343 100644 --- a/translations/Internationalization_tr.ts +++ b/translations/Internationalization_tr.ts @@ -109,19 +109,19 @@ Yan paneli açmak için Boşluk tuşuna basın. - ColorPickerWidget + SidePanelWidget - + Active color: Aktif Renk: - + Press ESC to cancel Çıkmak için ESC'ye tıklayın - + Grab Color diff --git a/translations/Internationalization_zh_CN.ts b/translations/Internationalization_zh_CN.ts index a822dfb1..d9801f57 100644 --- a/translations/Internationalization_zh_CN.ts +++ b/translations/Internationalization_zh_CN.ts @@ -110,19 +110,19 @@ Press Space to open the side panel. - ColorPickerWidget + SidePanelWidget - + Active color: 活动颜色: - + Press ESC to cancel 按下 ESC 键以取消 - + Grab Color 获取颜色 diff --git a/translations/Internationalization_zh_TW.ts b/translations/Internationalization_zh_TW.ts index e7d997e8..916a0a61 100644 --- a/translations/Internationalization_zh_TW.ts +++ b/translations/Internationalization_zh_TW.ts @@ -105,19 +105,19 @@ Press Space to open the side panel. - ColorPickerWidget + SidePanelWidget - + Active color: - + Press ESC to cancel - + Grab Color