Skip to content

Commit cd30d79

Browse files
committed
Selectable label in button color edition
1 parent 2c55517 commit cd30d79

File tree

5 files changed

+49
-8
lines changed

5 files changed

+49
-8
lines changed

flameshot.pro

+4-2
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ SOURCES += src/main.cpp\
4646
src/config/buttonlistview.cpp \
4747
src/config/uicoloreditor.cpp \
4848
src/config/geneneralconf.cpp \
49-
src/flameshotdbusadapter.cpp
49+
src/flameshotdbusadapter.cpp \
50+
src/config/clickablelabel.cpp
5051

5152
HEADERS += \
5253
src/controller.h \
@@ -61,7 +62,8 @@ HEADERS += \
6162
src/config/buttonlistview.h \
6263
src/config/uicoloreditor.h \
6364
src/config/geneneralconf.h \
64-
src/flameshotdbusadapter.h
65+
src/flameshotdbusadapter.h \
66+
src/config/clickablelabel.h
6567

6668
RESOURCES += \
6769
graphics.qrc

src/config/clickablelabel.cpp

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#include "clickablelabel.h"
2+
3+
4+
ClickableLabel::ClickableLabel(QWidget *parent) : QLabel(parent) {
5+
6+
}
7+
8+
ClickableLabel::ClickableLabel(QString s, QWidget *parent) : QLabel(parent) {
9+
setText(s);
10+
}
11+
12+
void ClickableLabel::mousePressEvent(QMouseEvent *) {
13+
Q_EMIT clicked();
14+
}

src/config/clickablelabel.h

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#ifndef CLICKABLELABEL_H
2+
#define CLICKABLELABEL_H
3+
4+
#include <QLabel>
5+
6+
class ClickableLabel : public QLabel
7+
{
8+
Q_OBJECT
9+
public:
10+
explicit ClickableLabel(QWidget *parent = nullptr);
11+
ClickableLabel(QString s, QWidget *parent = nullptr);
12+
13+
signals:
14+
void clicked();
15+
16+
private:
17+
void mousePressEvent (QMouseEvent *) ;
18+
};
19+
20+
#endif // CLICKABLELABEL_H

src/config/uicoloreditor.cpp

+8-3
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@
1616
// along with Flameshot. If not, see <http://www.gnu.org/licenses/>.
1717

1818
#include "uicoloreditor.h"
19+
#include "clickablelabel.h"
1920
#include <QHBoxLayout>
2021
#include <QVBoxLayout>
2122
#include <QSettings>
2223
#include <QComboBox>
2324
#include <QMap>
24-
#include <QLabel>
2525

2626
UIcolorEditor::UIcolorEditor(QWidget *parent) : QFrame(parent) {
2727
setFrameStyle(QFrame::StyledPanel);
@@ -90,7 +90,7 @@ void UIcolorEditor::initButtons() {
9090
m_buttonMainColor->move(m_buttonMainColor->x() + extraSize/2, m_buttonMainColor->y() + extraSize/2);
9191
QHBoxLayout *h1 = new QHBoxLayout();
9292
h1->addWidget(frame);
93-
m_labelMain = new QLabel(tr("Main Color"), this);
93+
m_labelMain = new ClickableLabel(tr("Main Color"), this);
9494
h1->addWidget(m_labelMain);
9595
vLayout->addLayout(h1);
9696

@@ -109,7 +109,7 @@ void UIcolorEditor::initButtons() {
109109

110110
QHBoxLayout *h2 = new QHBoxLayout();
111111
h2->addWidget(frame2);
112-
m_labelContrast = new QLabel(tr("Contrast Color"), this);
112+
m_labelContrast = new ClickableLabel(tr("Contrast Color"), this);
113113
m_labelContrast->setStyleSheet("QLabel { color : gray; }");
114114
h2->addWidget(m_labelContrast);
115115
vLayout->addLayout(h2);
@@ -122,6 +122,11 @@ void UIcolorEditor::initButtons() {
122122
this, &UIcolorEditor::changeLastButton);
123123
connect(m_buttonContrast, &Button::pressedButton,
124124
this, &UIcolorEditor::changeLastButton);
125+
// clicking the labels chages the button too
126+
connect(m_labelMain, &ClickableLabel::clicked,
127+
this, [this]{ changeLastButton(m_buttonMainColor); });
128+
connect(m_labelContrast, &ClickableLabel::clicked,
129+
this, [this]{ changeLastButton(m_buttonContrast); });
125130
}
126131

127132
void UIcolorEditor::updateButtonIcon() {

src/config/uicoloreditor.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
class QVBoxLayout;
2626
class QHBoxLayout;
2727
class Button;
28-
class QLabel;
28+
class ClickableLabel;
2929

3030
class UIcolorEditor : public QFrame {
3131
Q_OBJECT
@@ -41,9 +41,9 @@ private slots:
4141
private:
4242
QColor m_uiColor, m_contrastColor;
4343
Button *m_buttonMainColor;
44-
QLabel *m_labelMain;
44+
ClickableLabel *m_labelMain;
4545
Button *m_buttonContrast;
46-
QLabel *m_labelContrast;
46+
ClickableLabel *m_labelContrast;
4747
Button *m_lastButtonPressed;
4848
color_widgets::ColorWheel *m_colorWheel;
4949

0 commit comments

Comments
 (0)