diff --git a/flameshot.pro b/flameshot.pro
index 87cb3944..49cc2529 100644
--- a/flameshot.pro
+++ b/flameshot.pro
@@ -130,14 +130,15 @@ SOURCES += src/main.cpp \
src/tools/abstracttwopointtool.cpp \
src/tools/abstractactiontool.cpp \
src/utils/globalvalues.cpp \
- src/widgets/capture/utilitypanel.cpp \
+ src/widgets/panel/utilitypanel.cpp \
src/widgets/capture/hovereventfilter.cpp \
src/widgets/capture/selectionwidget.cpp \
src/tools/pin/pinwidget.cpp \
src/tools/text/texttool.cpp \
src/tools/text/textwidget.cpp \
src/core/capturerequest.cpp \
- src/tools/text/textconfig.cpp
+ src/tools/text/textconfig.cpp \
+ src/widgets/panel/colorpickerwidget.cpp
HEADERS += src/widgets/capture/buttonhandler.h \
src/widgets/infowindow.h \
@@ -201,14 +202,15 @@ HEADERS += src/widgets/capture/buttonhandler.h \
src/tools/abstractpathtool.h \
src/tools/abstracttwopointtool.h \
src/tools/abstractactiontool.h \
- src/widgets/capture/utilitypanel.h \
+ src/widgets/panel/utilitypanel.h \
src/widgets/capture/hovereventfilter.h \
src/widgets/capture/selectionwidget.h \
src/tools/pin/pinwidget.h \
src/tools/text/texttool.h \
src/tools/text/textwidget.h \
src/core/capturerequest.h \
- src/tools/text/textconfig.h
+ src/tools/text/textconfig.h \
+ src/widgets/panel/colorpickerwidget.h
unix:!macx {
SOURCES += src/core/flameshotdbusadapter.cpp \
diff --git a/graphics.qrc b/graphics.qrc
index 590d6183..c51a80cf 100644
--- a/graphics.qrc
+++ b/graphics.qrc
@@ -49,5 +49,7 @@
img/buttonIconsWhite/pin.png
img/buttonIconsBlack/text.png
img/buttonIconsWhite/text.png
+ img/configBlack/colorize.png
+ img/configWhite/colorize.png
diff --git a/img/configBlack/colorize.png b/img/configBlack/colorize.png
new file mode 100644
index 00000000..09678878
Binary files /dev/null and b/img/configBlack/colorize.png differ
diff --git a/img/configBlack/colorize.svg b/img/configBlack/colorize.svg
new file mode 100755
index 00000000..b387cdbe
--- /dev/null
+++ b/img/configBlack/colorize.svg
@@ -0,0 +1,4 @@
+
diff --git a/img/configWhite/colorize.png b/img/configWhite/colorize.png
new file mode 100644
index 00000000..a3950f8d
Binary files /dev/null and b/img/configWhite/colorize.png differ
diff --git a/img/configWhite/colorize.svg b/img/configWhite/colorize.svg
new file mode 100755
index 00000000..2c1ef5dc
--- /dev/null
+++ b/img/configWhite/colorize.svg
@@ -0,0 +1,58 @@
+
+
diff --git a/src/config/configwindow.cpp b/src/config/configwindow.cpp
index 1157edbf..524ef077 100644
--- a/src/config/configwindow.cpp
+++ b/src/config/configwindow.cpp
@@ -54,7 +54,8 @@ ConfigWindow::ConfigWindow(QWidget *parent) : QTabWidget(parent) {
QColor background = this->palette().background().color();
bool isDark = ColorUtils::colorIsDark(background);
- QString modifier = isDark ? PathInfo::whiteIconPath() : PathInfo::blackIconPath();
+ QString modifier = isDark ? PathInfo::whiteIconPath() :
+ PathInfo::blackIconPath();
// visuals
m_visuals = new VisualsEditor();
diff --git a/src/utils/pathinfo.cpp b/src/utils/pathinfo.cpp
index bf45a8c9..18340d14 100644
--- a/src/utils/pathinfo.cpp
+++ b/src/utils/pathinfo.cpp
@@ -28,6 +28,15 @@ const QString PathInfo::blackIconPath() {
return ":/img/buttonIconsBlack/";
}
+const QString PathInfo::whiteConfigIconPath() {
+ return ":/img/configWhite/";
+}
+
+const QString PathInfo::blackConfigIconPath() {
+ return ":/img/configBlack/";
+}
+
+
QStringList PathInfo::translationsPaths() {
QString binaryPath = QFileInfo(qApp->applicationDirPath())
.absoluteFilePath();
diff --git a/src/utils/pathinfo.h b/src/utils/pathinfo.h
index 503eaa18..cdf44c76 100644
--- a/src/utils/pathinfo.h
+++ b/src/utils/pathinfo.h
@@ -25,6 +25,10 @@ const QString whiteIconPath();
const QString blackIconPath();
+const QString whiteConfigIconPath();
+
+const QString blackConfigIconPath();
+
QStringList translationsPaths();
} // namespace
diff --git a/src/widgets/capture/capturewidget.cpp b/src/widgets/capture/capturewidget.cpp
index eb762869..48fdda4b 100644
--- a/src/widgets/capture/capturewidget.cpp
+++ b/src/widgets/capture/capturewidget.cpp
@@ -23,6 +23,7 @@
#include "capturewidget.h"
#include "src/widgets/capture/hovereventfilter.h"
+#include "src/widgets/panel/colorpickerwidget.h"
#include "src/utils/colorutils.h"
#include "src/utils/globalvalues.h"
#include "src/widgets/capture/notifierbox.h"
@@ -526,6 +527,13 @@ void CaptureWidget::initPanel() {
panelRect.setWidth(m_colorPicker->width() * 3);
m_panel->setGeometry(panelRect);
+ ColorPickerWidget *colorPicker = new ColorPickerWidget(&m_context.screenshot);
+ connect(colorPicker, &ColorPickerWidget::colorChanged,
+ this, &CaptureWidget::setDrawColor);
+ connect(this, &CaptureWidget::colorChanged,
+ colorPicker, &ColorPickerWidget::updateColor);
+ colorPicker->colorChanged(m_context.color);
+ m_panel->pushWidget(colorPicker);
m_panel->pushWidget(new QUndoView(&m_undoStack, this));
}
diff --git a/src/widgets/capture/capturewidget.h b/src/widgets/capture/capturewidget.h
index fdea1b69..3e558250 100644
--- a/src/widgets/capture/capturewidget.h
+++ b/src/widgets/capture/capturewidget.h
@@ -28,7 +28,7 @@
#include "src/tools/capturetool.h"
#include "src/utils/confighandler.h"
#include "src/widgets/capture/selectionwidget.h"
-#include "src/widgets/capture/utilitypanel.h"
+#include "src/widgets/panel/utilitypanel.h"
#include "buttonhandler.h"
#include
#include
diff --git a/src/widgets/panel/colorpickerwidget.cpp b/src/widgets/panel/colorpickerwidget.cpp
new file mode 100644
index 00000000..eb5f942d
--- /dev/null
+++ b/src/widgets/panel/colorpickerwidget.cpp
@@ -0,0 +1,155 @@
+// Copyright(c) 2017-2018 Alejandro Sirgo Rica & Contributors
+//
+// This file is part of Flameshot.
+//
+// Flameshot is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Flameshot is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Flameshot. If not, see .
+
+#include "colorpickerwidget.h"
+#include "src/utils/pathinfo.h"
+#include "src/utils/colorutils.h"
+#include
+#include
+#include
+#include
+#include
+
+class QColorPickingEventFilter : public QObject {
+public:
+
+ explicit QColorPickingEventFilter(
+ ColorPickerWidget *pw, QObject *parent = 0) :
+ QObject(parent), m_pw(pw) {}
+
+ bool eventFilter(QObject *, QEvent *event) override {
+ event->accept();
+ switch (event->type()) {
+ case QEvent::MouseMove:
+ return m_pw->handleMouseMove(static_cast(event));
+ case QEvent::MouseButtonPress:
+ return m_pw->handleMouseButtonPressed(
+ static_cast(event));
+ case QEvent::KeyPress:
+ return m_pw->handleKeyPress(static_cast(event));
+ default:
+ break;
+ }
+ return false;
+ }
+
+private:
+ ColorPickerWidget *m_pw;
+};
+
+////////////////////////
+
+ColorPickerWidget::ColorPickerWidget(QPixmap *p, QWidget *parent) :
+ QWidget(parent), m_pixmap(p), m_eventFilter(nullptr)
+{
+ m_layout = new QVBoxLayout(this);
+
+ QFormLayout *colorForm = new QFormLayout();
+ m_colorLabel = new QLabel();
+ m_colorLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
+ colorForm->addRow(tr("Active color:"), m_colorLabel);
+ m_layout->addLayout(colorForm);
+
+ QColor background = this->palette().background().color();
+ bool isDark = ColorUtils::colorIsDark(background);
+ QString modifier = isDark ? PathInfo::whiteConfigIconPath() :
+ PathInfo::blackConfigIconPath();
+ QIcon grabIcon(modifier + "colorize.png");
+ m_colorGrabButton = new QPushButton(grabIcon, tr("Grab Color"));
+ connect(m_colorGrabButton, &QPushButton::pressed,
+ this, &ColorPickerWidget::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);
+ connect(m_colorWheel, &color_widgets::ColorWheel::colorChanged, this,
+ &ColorPickerWidget::updateColorNoWheel);
+ m_layout->addWidget(m_colorWheel);
+}
+
+void ColorPickerWidget::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) {
+ m_color = c;
+ m_colorLabel->setStyleSheet(
+ QString("QLabel { background-color : %1; }").arg(c.name()));
+}
+
+void ColorPickerWidget::colorGrabberActivated() {
+ grabKeyboard();
+ grabMouse(Qt::CrossCursor);
+ setMouseTracking(true);
+ m_colorBackup = m_color;
+ if (!m_eventFilter) {
+ m_eventFilter = new QColorPickingEventFilter(this, this);
+ }
+ installEventFilter(m_eventFilter);
+}
+
+void ColorPickerWidget::releaseColorGrab() {
+ setMouseTracking(false);
+ removeEventFilter(m_eventFilter);
+ releaseMouse();
+ releaseKeyboard();
+ setFocus();
+}
+
+QColor ColorPickerWidget::grabPixmapColor(const QPoint &p) {
+ QColor c;
+ if (m_pixmap) {
+ QPixmap pixel = m_pixmap->copy(QRect(p, p));
+ c = pixel.toImage().pixel(0,0);
+ }
+ return c;
+}
+
+bool ColorPickerWidget::handleKeyPress(QKeyEvent *e) {
+ if (e->matches(QKeySequence::Cancel)) {
+ releaseColorGrab();
+ updateColor(m_colorBackup);
+ } else if (e->key() == Qt::Key_Return || e->key() == Qt::Key_Enter) {
+ updateColor(grabPixmapColor(QCursor::pos()));
+ releaseColorGrab();
+ emit colorChanged(m_color);
+ }
+ return true;
+}
+
+bool ColorPickerWidget::handleMouseButtonPressed(QMouseEvent *e) {
+ if (m_colorGrabButton->geometry().contains(e->pos()) ||
+ e->button() == Qt::RightButton)
+ {
+ updateColorNoWheel(m_colorBackup);
+ } else if (e->button() == Qt::LeftButton) {
+ updateColor(grabPixmapColor(QCursor::pos()));
+ }
+ releaseColorGrab();
+ emit colorChanged(m_color);
+ return true;
+}
+
+bool ColorPickerWidget::handleMouseMove(QMouseEvent *e) {
+ updateColorNoWheel(grabPixmapColor(e->globalPos()));
+ return true;
+}
diff --git a/src/widgets/panel/colorpickerwidget.h b/src/widgets/panel/colorpickerwidget.h
new file mode 100644
index 00000000..6351b8e1
--- /dev/null
+++ b/src/widgets/panel/colorpickerwidget.h
@@ -0,0 +1,64 @@
+// Copyright(c) 2017-2018 Alejandro Sirgo Rica & Contributors
+//
+// This file is part of Flameshot.
+//
+// Flameshot is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Flameshot is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Flameshot. If not, see .
+
+#pragma once
+
+#include
+#include "color_wheel.hpp"
+
+class QVBoxLayout;
+class QPushButton;
+class QLabel;
+class QColorPickingEventFilter;
+
+class ColorPickerWidget : public QWidget {
+ Q_OBJECT
+
+ friend class QColorPickingEventFilter;
+public:
+ explicit ColorPickerWidget(QPixmap *p, QWidget *parent = nullptr);
+
+signals:
+ void colorChanged(const QColor &c);
+
+public slots:
+ void updateColor(const QColor &c);
+
+private slots:
+ void updateColorNoWheel(const QColor &c);
+
+private slots:
+ void colorGrabberActivated();
+ void releaseColorGrab();
+
+private:
+ QColor grabPixmapColor(const QPoint &p);
+
+ bool handleKeyPress(QKeyEvent *e);
+ bool handleMouseButtonPressed(QMouseEvent *e);
+ bool handleMouseMove(QMouseEvent *e);
+
+ QVBoxLayout *m_layout;
+ QPushButton *m_colorGrabButton;
+ color_widgets::ColorWheel *m_colorWheel;
+ QLabel *m_colorLabel;
+ QPixmap *m_pixmap;
+ QColor m_colorBackup;
+ QColor m_color;
+ QColorPickingEventFilter *m_eventFilter;
+
+};
diff --git a/src/widgets/capture/utilitypanel.cpp b/src/widgets/panel/utilitypanel.cpp
similarity index 100%
rename from src/widgets/capture/utilitypanel.cpp
rename to src/widgets/panel/utilitypanel.cpp
diff --git a/src/widgets/capture/utilitypanel.h b/src/widgets/panel/utilitypanel.h
similarity index 100%
rename from src/widgets/capture/utilitypanel.h
rename to src/widgets/panel/utilitypanel.h