Skip to content

Commit

Permalink
Add cancel information in grab color button
Browse files Browse the repository at this point in the history
  • Loading branch information
lupoDharkael committed May 23, 2018
1 parent 6ab7321 commit cf7066a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/widgets/panel/colorpickerwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ ColorPickerWidget::ColorPickerWidget(QPixmap *p, QWidget *parent) :
QString modifier = isDark ? PathInfo::whiteConfigIconPath() :
PathInfo::blackConfigIconPath();
QIcon grabIcon(modifier + "colorize.png");
m_colorGrabButton = new QPushButton(grabIcon, tr("Grab Color"));
m_colorGrabButton = new QPushButton(grabIcon, "");
updateGrabButton(false);
connect(m_colorGrabButton, &QPushButton::pressed,
this, &ColorPickerWidget::colorGrabberActivated);
m_layout->addWidget(m_colorGrabButton);
Expand Down Expand Up @@ -105,6 +106,7 @@ void ColorPickerWidget::colorGrabberActivated() {
m_eventFilter = new QColorPickingEventFilter(this, this);
}
installEventFilter(m_eventFilter);
updateGrabButton(true);
}

void ColorPickerWidget::releaseColorGrab() {
Expand All @@ -113,6 +115,7 @@ void ColorPickerWidget::releaseColorGrab() {
releaseMouse();
releaseKeyboard();
setFocus();
updateGrabButton(false);
}

QColor ColorPickerWidget::grabPixmapColor(const QPoint &p) {
Expand Down Expand Up @@ -155,3 +158,11 @@ bool ColorPickerWidget::handleMouseMove(QMouseEvent *e) {
updateColorNoWheel(grabPixmapColor(e->globalPos()));
return true;
}

void ColorPickerWidget::updateGrabButton(const bool activated) {
if (activated) {
m_colorGrabButton->setText(tr("Press ESC to cancel"));
} else {
m_colorGrabButton->setText(tr("Grab Color"));
}
}
2 changes: 2 additions & 0 deletions src/widgets/panel/colorpickerwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ private slots:
bool handleMouseButtonPressed(QMouseEvent *e);
bool handleMouseMove(QMouseEvent *e);

void updateGrabButton(const bool activated);

QVBoxLayout *m_layout;
QPushButton *m_colorGrabButton;
color_widgets::ColorWheel *m_colorWheel;
Expand Down

0 comments on commit cf7066a

Please sign in to comment.