Add color tools inside the capture editor

This commit is contained in:
lupoDharkael
2018-05-16 23:02:30 +02:00
parent 4b8d9ba6b2
commit 6adcfef413
15 changed files with 313 additions and 6 deletions

View File

@@ -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 \

View File

@@ -49,5 +49,7 @@
<file>img/buttonIconsWhite/pin.png</file>
<file>img/buttonIconsBlack/text.png</file>
<file>img/buttonIconsWhite/text.png</file>
<file>img/configBlack/colorize.png</file>
<file>img/configWhite/colorize.png</file>
</qresource>
</RCC>

Binary file not shown.

After

Width:  |  Height:  |  Size: 332 B

4
img/configBlack/colorize.svg Executable file
View File

@@ -0,0 +1,4 @@
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24">
<path d="M0 0h24v24H0z" fill="none"/>
<path d="M20.71 5.63l-2.34-2.34c-.39-.39-1.02-.39-1.41 0l-3.12 3.12-1.93-1.91-1.41 1.41 1.42 1.42L3 16.25V21h4.75l8.92-8.92 1.42 1.42 1.41-1.41-1.92-1.92 3.12-3.12c.4-.4.4-1.03.01-1.42zM6.92 19L5 17.08l8.06-8.06 1.92 1.92L6.92 19z"/>
</svg>

After

Width:  |  Height:  |  Size: 371 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 329 B

58
img/configWhite/colorize.svg Executable file
View File

@@ -0,0 +1,58 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="24"
height="24"
viewBox="0 0 24 24"
version="1.1"
id="svg6"
sodipodi:docname="colorize.svg"
inkscape:version="0.92.3 (2405546, 2018-03-11)">
<metadata
id="metadata12">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
</cc:Work>
</rdf:RDF>
</metadata>
<defs
id="defs10" />
<sodipodi:namedview
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1"
objecttolerance="10"
gridtolerance="10"
guidetolerance="10"
inkscape:pageopacity="0"
inkscape:pageshadow="2"
inkscape:window-width="640"
inkscape:window-height="480"
id="namedview8"
showgrid="false"
inkscape:zoom="9.8333333"
inkscape:cx="12"
inkscape:cy="12"
inkscape:window-x="36"
inkscape:window-y="0"
inkscape:window-maximized="0"
inkscape:current-layer="svg6" />
<path
d="M0 0h24v24H0z"
fill="none"
id="path2" />
<path
d="M20.71 5.63l-2.34-2.34c-.39-.39-1.02-.39-1.41 0l-3.12 3.12-1.93-1.91-1.41 1.41 1.42 1.42L3 16.25V21h4.75l8.92-8.92 1.42 1.42 1.41-1.41-1.92-1.92 3.12-3.12c.4-.4.4-1.03.01-1.42zM6.92 19L5 17.08l8.06-8.06 1.92 1.92L6.92 19z"
id="path4"
style="fill:#ffffff" />
</svg>

After

Width:  |  Height:  |  Size: 1.7 KiB

View File

@@ -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();

View File

@@ -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();

View File

@@ -25,6 +25,10 @@ const QString whiteIconPath();
const QString blackIconPath();
const QString whiteConfigIconPath();
const QString blackConfigIconPath();
QStringList translationsPaths();
} // namespace

View File

@@ -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));
}

View File

@@ -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 <QWidget>
#include <QUndoStack>

View File

@@ -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 <http://www.gnu.org/licenses/>.
#include "colorpickerwidget.h"
#include "src/utils/pathinfo.h"
#include "src/utils/colorutils.h"
#include <QVBoxLayout>
#include <QFormLayout>
#include <QPushButton>
#include <QLabel>
#include <QKeyEvent>
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<QMouseEvent *>(event));
case QEvent::MouseButtonPress:
return m_pw->handleMouseButtonPressed(
static_cast<QMouseEvent *>(event));
case QEvent::KeyPress:
return m_pw->handleKeyPress(static_cast<QKeyEvent *>(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;
}

View File

@@ -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 <http://www.gnu.org/licenses/>.
#pragma once
#include <QWidget>
#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;
};