Skip to content

Commit

Permalink
Selectable label in button color edition
Browse files Browse the repository at this point in the history
  • Loading branch information
lupoDharkael committed Jun 19, 2017
1 parent 2c55517 commit cd30d79
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 8 deletions.
6 changes: 4 additions & 2 deletions flameshot.pro
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand All @@ -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
Expand Down
14 changes: 14 additions & 0 deletions src/config/clickablelabel.cpp
Original file line number Diff line number Diff line change
@@ -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();
}
20 changes: 20 additions & 0 deletions src/config/clickablelabel.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#ifndef CLICKABLELABEL_H
#define CLICKABLELABEL_H

#include <QLabel>

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
11 changes: 8 additions & 3 deletions src/config/uicoloreditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@
// along with Flameshot. If not, see <http://www.gnu.org/licenses/>.

#include "uicoloreditor.h"
#include "clickablelabel.h"
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QSettings>
#include <QComboBox>
#include <QMap>
#include <QLabel>

UIcolorEditor::UIcolorEditor(QWidget *parent) : QFrame(parent) {
setFrameStyle(QFrame::StyledPanel);
Expand Down Expand Up @@ -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);

Expand All @@ -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);
Expand All @@ -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() {
Expand Down
6 changes: 3 additions & 3 deletions src/config/uicoloreditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
class QVBoxLayout;
class QHBoxLayout;
class Button;
class QLabel;
class ClickableLabel;

class UIcolorEditor : public QFrame {
Q_OBJECT
Expand All @@ -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;

Expand Down

0 comments on commit cd30d79

Please sign in to comment.