From cd30d798d08a1b7f8adf3bb78d41960111fe6f71 Mon Sep 17 00:00:00 2001 From: lupoDharkael Date: Mon, 19 Jun 2017 18:03:22 +0200 Subject: [PATCH] Selectable label in button color edition --- flameshot.pro | 6 ++++-- src/config/clickablelabel.cpp | 14 ++++++++++++++ src/config/clickablelabel.h | 20 ++++++++++++++++++++ src/config/uicoloreditor.cpp | 11 ++++++++--- src/config/uicoloreditor.h | 6 +++--- 5 files changed, 49 insertions(+), 8 deletions(-) create mode 100644 src/config/clickablelabel.cpp create mode 100644 src/config/clickablelabel.h diff --git a/flameshot.pro b/flameshot.pro index 4c9ecded..5868c4e5 100644 --- a/flameshot.pro +++ b/flameshot.pro @@ -46,7 +46,8 @@ SOURCES += src/main.cpp\ src/config/buttonlistview.cpp \ src/config/uicoloreditor.cpp \ src/config/geneneralconf.cpp \ - src/flameshotdbusadapter.cpp + src/flameshotdbusadapter.cpp \ + src/config/clickablelabel.cpp HEADERS += \ src/controller.h \ @@ -61,7 +62,8 @@ HEADERS += \ src/config/buttonlistview.h \ src/config/uicoloreditor.h \ src/config/geneneralconf.h \ - src/flameshotdbusadapter.h + src/flameshotdbusadapter.h \ + src/config/clickablelabel.h RESOURCES += \ graphics.qrc diff --git a/src/config/clickablelabel.cpp b/src/config/clickablelabel.cpp new file mode 100644 index 00000000..0ed8575d --- /dev/null +++ b/src/config/clickablelabel.cpp @@ -0,0 +1,14 @@ +#include "clickablelabel.h" + + +ClickableLabel::ClickableLabel(QWidget *parent) : QLabel(parent) { + +} + +ClickableLabel::ClickableLabel(QString s, QWidget *parent) : QLabel(parent) { + setText(s); +} + +void ClickableLabel::mousePressEvent(QMouseEvent *) { + Q_EMIT clicked(); +} diff --git a/src/config/clickablelabel.h b/src/config/clickablelabel.h new file mode 100644 index 00000000..9505206e --- /dev/null +++ b/src/config/clickablelabel.h @@ -0,0 +1,20 @@ +#ifndef CLICKABLELABEL_H +#define CLICKABLELABEL_H + +#include + +class ClickableLabel : public QLabel +{ + Q_OBJECT +public: + explicit ClickableLabel(QWidget *parent = nullptr); + ClickableLabel(QString s, QWidget *parent = nullptr); + +signals: + void clicked(); + +private: + void mousePressEvent (QMouseEvent *) ; +}; + +#endif // CLICKABLELABEL_H diff --git a/src/config/uicoloreditor.cpp b/src/config/uicoloreditor.cpp index f2b6b72e..8c03e156 100644 --- a/src/config/uicoloreditor.cpp +++ b/src/config/uicoloreditor.cpp @@ -16,12 +16,12 @@ // along with Flameshot. If not, see . #include "uicoloreditor.h" +#include "clickablelabel.h" #include #include #include #include #include -#include UIcolorEditor::UIcolorEditor(QWidget *parent) : QFrame(parent) { setFrameStyle(QFrame::StyledPanel); @@ -90,7 +90,7 @@ void UIcolorEditor::initButtons() { m_buttonMainColor->move(m_buttonMainColor->x() + extraSize/2, m_buttonMainColor->y() + extraSize/2); QHBoxLayout *h1 = new QHBoxLayout(); h1->addWidget(frame); - m_labelMain = new QLabel(tr("Main Color"), this); + m_labelMain = new ClickableLabel(tr("Main Color"), this); h1->addWidget(m_labelMain); vLayout->addLayout(h1); @@ -109,7 +109,7 @@ void UIcolorEditor::initButtons() { QHBoxLayout *h2 = new QHBoxLayout(); h2->addWidget(frame2); - m_labelContrast = new QLabel(tr("Contrast Color"), this); + m_labelContrast = new ClickableLabel(tr("Contrast Color"), this); m_labelContrast->setStyleSheet("QLabel { color : gray; }"); h2->addWidget(m_labelContrast); vLayout->addLayout(h2); @@ -122,6 +122,11 @@ void UIcolorEditor::initButtons() { this, &UIcolorEditor::changeLastButton); connect(m_buttonContrast, &Button::pressedButton, this, &UIcolorEditor::changeLastButton); + // clicking the labels chages the button too + connect(m_labelMain, &ClickableLabel::clicked, + this, [this]{ changeLastButton(m_buttonMainColor); }); + connect(m_labelContrast, &ClickableLabel::clicked, + this, [this]{ changeLastButton(m_buttonContrast); }); } void UIcolorEditor::updateButtonIcon() { diff --git a/src/config/uicoloreditor.h b/src/config/uicoloreditor.h index c1f17275..de522091 100644 --- a/src/config/uicoloreditor.h +++ b/src/config/uicoloreditor.h @@ -25,7 +25,7 @@ class QVBoxLayout; class QHBoxLayout; class Button; -class QLabel; +class ClickableLabel; class UIcolorEditor : public QFrame { Q_OBJECT @@ -41,9 +41,9 @@ private slots: private: QColor m_uiColor, m_contrastColor; Button *m_buttonMainColor; - QLabel *m_labelMain; + ClickableLabel *m_labelMain; Button *m_buttonContrast; - QLabel *m_labelContrast; + ClickableLabel *m_labelContrast; Button *m_lastButtonPressed; color_widgets::ColorWheel *m_colorWheel;