Now you can change the thickness of the drawing tools!

This commit is contained in:
lupoDharkael
2017-08-17 14:47:27 +02:00
parent 321ec1b555
commit b966a10c09
40 changed files with 244 additions and 62 deletions

View File

@@ -83,7 +83,8 @@ SOURCES += src/main.cpp\
src/capture/workers/imgur/loadspinner.cpp \
src/capture/workers/imgur/imagelabel.cpp \
src/capture/workers/imgur/notificationwidget.cpp \
src/core/resourceexporter.cpp
src/core/resourceexporter.cpp \
src/capture/widget/notifierbox.cpp
HEADERS += \
src/capture/widget/buttonhandler.h \
@@ -131,7 +132,8 @@ HEADERS += \
src/capture/workers/imgur/loadspinner.h \
src/capture/workers/imgur/imagelabel.h \
src/capture/workers/imgur/notificationwidget.h \
src/core/resourceexporter.h
src/core/resourceexporter.h \
src/capture/widget/notifierbox.h
RESOURCES += \
graphics.qrc

View File

@@ -28,10 +28,12 @@ CaptureModification::CaptureModification(
const CaptureButton::ButtonType t,
const QPoint &p,
const QColor &c,
const int thickness,
QObject *parent) :
QObject(parent),
m_color(c),
m_type(t)
m_type(t),
m_thickness(thickness)
{
m_tool = ToolFactory().CreateTool(t, this);
m_coords.append(p);
@@ -56,6 +58,10 @@ CaptureTool* CaptureModification::tool() const{
return m_tool;
}
int CaptureModification::thickness() const {
return m_thickness;
}
// addPoint adds a point to the vector of points
void CaptureModification::addPoint(const QPoint p) {
if (m_tool->toolType() == CaptureTool::TYPE_LINE_DRAWER) {

View File

@@ -31,13 +31,15 @@ public:
CaptureModification(QObject *parent = nullptr) = delete;
CaptureModification(
const CaptureButton::ButtonType,
const QPoint &,
const QColor &,
const QPoint &initialPoint,
const QColor &color,
const int thickness,
QObject *parent = nullptr
);
QColor color() const;
QVector<QPoint> points() const;
CaptureTool* tool() const;
int thickness() const;
CaptureButton::ButtonType buttonType() const;
void addPoint(const QPoint);
@@ -46,6 +48,7 @@ protected:
CaptureButton::ButtonType m_type;
QVector<QPoint> m_coords;
CaptureTool *m_tool;
int m_thickness;
};

View File

@@ -102,7 +102,8 @@ void Screenshot::paintInPainter(QPainter &painter,
{
const QVector<QPoint> &points = modification->points();
QColor color = modification->color();
modification->tool()->processImage(painter, points, color);
int thickness = modification->thickness();
modification->tool()->processImage(painter, points, color, thickness);
}

View File

@@ -23,14 +23,13 @@ namespace {
const int ArrowWidth = 10;
const int ArrowHeight = 18;
QPainterPath getArrowHead(QPoint p1, QPoint p2) {
QPainterPath getArrowHead(QPoint p1, QPoint p2, const int thickness) {
QLineF body(p1, p2);
int originalLength = body.length();
body.setLength(ArrowWidth);
body.setLength(ArrowWidth + thickness*2);
// move across the line up to the head
//QPointF =;
QLineF temp(QPoint(0,0), p2-p1);
temp.setLength(originalLength-ArrowHeight);
temp.setLength(originalLength - ArrowHeight - thickness*2);
QPointF bottonTranslation(temp.p2());
// generates the transformation to center of the arrowhead
@@ -50,9 +49,9 @@ QPainterPath getArrowHead(QPoint p1, QPoint p2) {
}
// gets a shorter line to prevent overlap in the point of the arrow
QLine getShorterLine(QPoint p1, QPoint p2) {
QLine getShorterLine(QPoint p1, QPoint p2, const int thickness) {
QLineF l(p1, p2);
l.setLength(l.length()-ArrowHeight);
l.setLength(l.length() - ArrowHeight - thickness*2);
return l.toLine();
}
@@ -89,11 +88,12 @@ CaptureTool::ToolWorkType ArrowTool::toolType() const {
void ArrowTool::processImage(
QPainter &painter,
const QVector<QPoint> &points,
const QColor &color)
const QColor &color,
const int thickness)
{
painter.setPen(QPen(color, 2));
painter.drawLine(getShorterLine(points[0], points[1]));
painter.fillPath(getArrowHead(points[0], points[1]), QBrush(color));
painter.setPen(QPen(color, 2 + thickness));
painter.drawLine(getShorterLine(points[0], points[1], thickness));
painter.fillPath(getArrowHead(points[0], points[1], thickness), QBrush(color));
}
void ArrowTool::onPressed() {

View File

@@ -37,7 +37,8 @@ public:
void processImage(
QPainter &painter,
const QVector<QPoint> &points,
const QColor &color) override;
const QColor &color,
const int thickness) override;
void onPressed() override;

View File

@@ -60,7 +60,8 @@ public:
virtual void processImage(
QPainter &painter,
const QVector<QPoint> &points,
const QColor &color) = 0;
const QColor &color,
const int thickness) = 0;
signals:
void requestAction(Request r);

View File

@@ -49,9 +49,10 @@ CaptureTool::ToolWorkType CircleTool::toolType() const {
void CircleTool::processImage(
QPainter &painter,
const QVector<QPoint> &points,
const QColor &color)
const QColor &color,
const int thickness)
{
painter.setPen(QPen(color, 2));
painter.setPen(QPen(color, 2 + thickness));
painter.drawEllipse(QRect(points[0], points[1]));
}

View File

@@ -37,7 +37,8 @@ public:
void processImage(
QPainter &painter,
const QVector<QPoint> &points,
const QColor &color) override;
const QColor &color,
const int thickness) override;
void onPressed() override;

View File

@@ -49,11 +49,13 @@ CaptureTool::ToolWorkType CopyTool::toolType() const {
void CopyTool::processImage(
QPainter &painter,
const QVector<QPoint> &points,
const QColor &color)
const QColor &color,
const int thickness)
{
Q_UNUSED(painter);
Q_UNUSED(points);
Q_UNUSED(color);
Q_UNUSED(thickness);
}
void CopyTool::onPressed() {

View File

@@ -37,7 +37,8 @@ public:
void processImage(
QPainter &painter,
const QVector<QPoint> &points,
const QColor &color) override;
const QColor &color,
const int thickness) override;
void onPressed() override;

View File

@@ -49,11 +49,13 @@ CaptureTool::ToolWorkType ExitTool::toolType() const {
void ExitTool::processImage(
QPainter &painter,
const QVector<QPoint> &points,
const QColor &color)
const QColor &color,
const int thickness)
{
Q_UNUSED(painter);
Q_UNUSED(points);
Q_UNUSED(color);
Q_UNUSED(thickness);
}
void ExitTool::onPressed() {

View File

@@ -37,7 +37,8 @@ public:
void processImage(
QPainter &painter,
const QVector<QPoint> &points,
const QColor &color) override;
const QColor &color,
const int thickness) override;
void onPressed() override;

View File

@@ -49,11 +49,13 @@ CaptureTool::ToolWorkType ImgurUploaderTool::toolType() const {
void ImgurUploaderTool::processImage(
QPainter &painter,
const QVector<QPoint> &points,
const QColor &color)
const QColor &color,
const int thickness)
{
Q_UNUSED(painter);
Q_UNUSED(points);
Q_UNUSED(color);
Q_UNUSED(thickness);
}
void ImgurUploaderTool::onPressed() {

View File

@@ -37,7 +37,8 @@ public:
void processImage(
QPainter &painter,
const QVector<QPoint> &points,
const QColor &color) override;
const QColor &color,
const int thickness) override;
void onPressed() override;

View File

@@ -51,14 +51,15 @@ CaptureTool::ToolWorkType LineTool::toolType() const {
void LineTool::processImage(
QPainter &painter,
const QVector<QPoint> &points,
const QColor &color)
const QColor &color,
const int thickness)
{
QPoint p0 = points[0];
QPoint p1 = points[1];
if (needsAdjustment(p0, p1)) {
p1.setY(p0.y());
}
painter.setPen(QPen(color, 2));
painter.setPen(QPen(color, 2 + thickness));
painter.drawLine(p0, p1);
}

View File

@@ -37,7 +37,8 @@ public:
void processImage(
QPainter &painter,
const QVector<QPoint> &points,
const QColor &color) override;
const QColor &color,
const int thickness) override;
void onPressed() override;

View File

@@ -51,7 +51,8 @@ CaptureTool::ToolWorkType MarkerTool::toolType() const {
void MarkerTool::processImage(
QPainter &painter,
const QVector<QPoint> &points,
const QColor &color)
const QColor &color,
const int thickness)
{
QPoint p0 = points[0];
QPoint p1 = points[1];
@@ -59,7 +60,7 @@ void MarkerTool::processImage(
p1.setY(p0.y());
}
painter.setOpacity(0.35);
painter.setPen(QPen(color, 14));
painter.setPen(QPen(color, 14 + thickness));
painter.drawLine(p0, p1);
painter.setOpacity(1);
}

View File

@@ -37,7 +37,8 @@ public:
void processImage(
QPainter &painter,
const QVector<QPoint> &points,
const QColor &color) override;
const QColor &color,
const int thickness) override;
void onPressed() override;

View File

@@ -49,11 +49,13 @@ CaptureTool::ToolWorkType MoveTool::toolType() const {
void MoveTool::processImage(
QPainter &painter,
const QVector<QPoint> &points,
const QColor &color)
const QColor &color,
const int thickness)
{
Q_UNUSED(painter);
Q_UNUSED(points);
Q_UNUSED(color);
Q_UNUSED(thickness);
}
void MoveTool::onPressed() {

View File

@@ -37,7 +37,8 @@ public:
void processImage(
QPainter &painter,
const QVector<QPoint> &points,
const QColor &color) override;
const QColor &color,
const int thickness) override;
void onPressed() override;

View File

@@ -49,9 +49,10 @@ CaptureTool::ToolWorkType PencilTool::toolType() const {
void PencilTool::processImage(
QPainter &painter,
const QVector<QPoint> &points,
const QColor &color)
const QColor &color,
const int thickness)
{
painter.setPen(QPen(color, 2));
painter.setPen(QPen(color, 2 + thickness));
painter.drawPolyline(points.data(), points.size());
}

View File

@@ -37,7 +37,8 @@ public:
void processImage(
QPainter &painter,
const QVector<QPoint> &points,
const QColor &color) override;
const QColor &color,
const int thickness) override;
void onPressed() override;

View File

@@ -49,9 +49,10 @@ CaptureTool::ToolWorkType RectangleTool::toolType() const {
void RectangleTool::processImage(
QPainter &painter,
const QVector<QPoint> &points,
const QColor &color)
const QColor &color,
const int thickness)
{
painter.setPen(QPen(color, 2));
painter.setPen(QPen(color, 2 + thickness));
painter.setBrush(QBrush(color));
painter.drawRect(QRect(points[0], points[1]));
painter.setBrush(QBrush());

View File

@@ -37,7 +37,8 @@ public:
void processImage(
QPainter &painter,
const QVector<QPoint> &points,
const QColor &color) override;
const QColor &color,
const int thickness) override;
void onPressed() override;

View File

@@ -49,11 +49,13 @@ CaptureTool::ToolWorkType SaveTool::toolType() const {
void SaveTool::processImage(
QPainter &painter,
const QVector<QPoint> &points,
const QColor &color)
const QColor &color,
const int thickness)
{
Q_UNUSED(painter);
Q_UNUSED(points);
Q_UNUSED(color);
Q_UNUSED(thickness);
}
void SaveTool::onPressed() {

View File

@@ -37,7 +37,8 @@ public:
void processImage(
QPainter &painter,
const QVector<QPoint> &points,
const QColor &color) override;
const QColor &color,
const int thickness) override;
void onPressed() override;

View File

@@ -49,9 +49,10 @@ CaptureTool::ToolWorkType SelectionTool::toolType() const {
void SelectionTool::processImage(
QPainter &painter,
const QVector<QPoint> &points,
const QColor &color)
const QColor &color,
const int thickness)
{
painter.setPen(QPen(color, 2));
painter.setPen(QPen(color, 2 + thickness));
painter.drawRect(QRect(points[0], points[1]));
}

View File

@@ -37,7 +37,8 @@ public:
void processImage(
QPainter &painter,
const QVector<QPoint> &points,
const QColor &color) override;
const QColor &color,
const int thickness) override;
void onPressed() override;

View File

@@ -49,11 +49,13 @@ CaptureTool::ToolWorkType SizeIndicatorTool::toolType() const {
void SizeIndicatorTool::processImage(
QPainter &painter,
const QVector<QPoint> &points,
const QColor &color)
const QColor &color,
const int thickness)
{
Q_UNUSED(painter);
Q_UNUSED(points);
Q_UNUSED(color);
Q_UNUSED(thickness);
}
void SizeIndicatorTool::onPressed() {

View File

@@ -37,7 +37,8 @@ public:
void processImage(
QPainter &painter,
const QVector<QPoint> &points,
const QColor &color) override;
const QColor &color,
const int thickness) override;
void onPressed() override;

View File

@@ -49,11 +49,13 @@ CaptureTool::ToolWorkType UndoTool::toolType() const {
void UndoTool::processImage(
QPainter &painter,
const QVector<QPoint> &points,
const QColor &color)
const QColor &color,
const int thickness)
{
Q_UNUSED(painter);
Q_UNUSED(points);
Q_UNUSED(color);
Q_UNUSED(thickness);
}
void UndoTool::onPressed() {

View File

@@ -37,7 +37,8 @@ public:
void processImage(
QPainter &painter,
const QVector<QPoint> &points,
const QColor &color) override;
const QColor &color,
const int thickness) override;
void onPressed() override;

View File

@@ -25,6 +25,7 @@
#include "src/capture/capturemodification.h"
#include "capturewidget.h"
#include "capturebutton.h"
#include "src/capture/widget/notifierbox.h"
#include "src/capture/widget/colorpicker.h"
#include "src/utils/screengrabber.h"
#include "src/utils/confighandler.h"
@@ -55,7 +56,9 @@ CaptureWidget::CaptureWidget(const QString &forcedSavePath, QWidget *parent) :
m_forcedSavePath(forcedSavePath),
m_state(CaptureButton::TYPE_MOVESELECTION)
{
m_showInitialMsg = ConfigHandler().showHelpValue();
ConfigHandler config;
m_showInitialMsg = config.showHelpValue();
m_thickness = config.drawThicknessValue();
setAttribute(Qt::WA_DeleteOnClose);
// create selection handlers
@@ -92,10 +95,15 @@ CaptureWidget::CaptureWidget(const QString &forcedSavePath, QWidget *parent) :
// init interface color
m_colorPicker = new ColorPicker(this);
m_colorPicker->hide();
m_notifierBox = new NotifierBox(this);
auto geometry = QGuiApplication::primaryScreen()->geometry();
m_notifierBox->move(geometry.left() +20, geometry.left() +20);
m_notifierBox->hide();
}
CaptureWidget::~CaptureWidget() {
ConfigHandler().setdrawThickness(m_thickness);
}
// redefineButtons retrieves the buttons configured to be shown with the
@@ -159,16 +167,11 @@ void CaptureWidget::paintEvent(QPaintEvent *) {
QString helpTxt = tr("Select an area with the mouse, or press Esc to exit."
"\nPress Enter to capture the screen."
"\nPress Right Click to show the color picker.");
"\nPress Right Click to show the color picker."
"\nUse the Mouse Wheel to change the thickness of your tool.");
// We draw the white contrasting background for the text, using the
//same text and options to get the boundingRect that the text will have.
QColor rectColor = m_uiColor;
rectColor.setAlpha(180);
QColor textColor((CaptureButton::iconIsWhiteByColor(rectColor) ?
Qt::white : Qt::black));
painter.setPen(QPen(textColor));
painter.setBrush(QBrush(rectColor, Qt::SolidPattern));
QRectF bRect = painter.boundingRect(helpRect, Qt::AlignCenter, helpTxt);
// These four calls provide padding for the rect
@@ -177,10 +180,15 @@ void CaptureWidget::paintEvent(QPaintEvent *) {
bRect.setX(bRect.x() - 12);
bRect.setY(bRect.y() - 10);
QColor rectColor(m_uiColor);
rectColor.setAlpha(180);
painter.setBrush(QBrush(rectColor, Qt::SolidPattern));
painter.drawRect(bRect);
// Draw the text:
painter.setPen(textColor);
QColor textColor((CaptureButton::iconIsWhiteByColor(rectColor) ?
Qt::white : Qt::black));
painter.setPen(QPen(textColor));
painter.drawText(helpRect, Qt::AlignCenter, helpTxt);
}
@@ -212,6 +220,7 @@ void CaptureWidget::mousePressEvent(QMouseEvent *e) {
if (m_state != CaptureButton::TYPE_MOVESELECTION) {
auto mod = new CaptureModification(m_state, e->pos(),
m_colorPicker->drawColor(),
m_thickness,
this);
m_modifications.append(mod);
return;
@@ -381,6 +390,12 @@ void CaptureWidget::keyPressEvent(QKeyEvent *e) {
}
}
void CaptureWidget::wheelEvent(QWheelEvent *e) {
m_thickness += e->delta() / 120;
m_thickness = qBound(0, m_thickness, 100);
m_notifierBox->showMessage(QString::number(m_thickness));
}
bool CaptureWidget::undo() {
bool itemRemoved = false;
if (!m_modifications.isEmpty()) {

View File

@@ -38,6 +38,7 @@ class QNetworkAccessManager;
class QNetworkReply;
class ColorPicker;
class Screenshot;
class NotifierBox;
class CaptureWidget : public QWidget {
Q_OBJECT
@@ -70,6 +71,7 @@ protected:
void mouseMoveEvent(QMouseEvent *);
void mouseReleaseEvent(QMouseEvent *);
void keyPressEvent(QKeyEvent *);
void wheelEvent(QWheelEvent *);
QRegion handleMask() const;
@@ -91,6 +93,9 @@ protected:
const QString m_forcedSavePath;
int m_thickness;
NotifierBox *m_notifierBox;
// naming convention for handles
// T top, B bottom, R Right, L left
// 2 letters: a corner

View File

@@ -0,0 +1,57 @@
// Copyright 2017 Alejandro Sirgo Rica
//
// 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 "notifierbox.h"
#include "src/utils/confighandler.h"
#include "src/capture/widget/capturebutton.h"
#include <QTimer>
#include <QPainter>
NotifierBox::NotifierBox(QWidget *parent) : QWidget(parent) {
m_timer = new QTimer(this);
m_timer->setSingleShot(true);
m_timer->setInterval(1200);
connect(m_timer, &QTimer::timeout, this, &NotifierBox::hide);
m_bgColor = ConfigHandler().uiMainColorValue();
m_foregroundColor = (CaptureButton::iconIsWhiteByColor(m_bgColor) ?
Qt::white : Qt::black);
m_bgColor.setAlpha(180);
setFixedSize(QSize(46, 46));
}
void NotifierBox::enterEvent(QEvent *) {
hide();
}
void NotifierBox::paintEvent(QPaintEvent *) {
QPainter painter(this);
// draw Elipse
painter.setRenderHint(QPainter::Antialiasing);
painter.setBrush(QBrush(m_bgColor, Qt::SolidPattern));
painter.setPen(QPen(Qt::transparent));
painter.drawEllipse(rect());
// Draw the text:
painter.setPen(QPen(m_foregroundColor));
painter.drawText(rect(), Qt::AlignCenter, m_message);
}
void NotifierBox::showMessage(const QString &msg) {
m_message = msg;
update();
show();
m_timer->start();
}

View File

@@ -0,0 +1,45 @@
// Copyright 2017 Alejandro Sirgo Rica
//
// 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/>.
#ifndef NOTIFIERBOX_H
#define NOTIFIERBOX_H
#include <QWidget>
class QTimer;
class NotifierBox : public QWidget
{
Q_OBJECT
public:
explicit NotifierBox(QWidget *parent = nullptr);
protected:
virtual void enterEvent(QEvent *);
virtual void paintEvent(QPaintEvent *);
public slots:
void showMessage(const QString &msg);
private:
QTimer *m_timer;
QString m_message;
QColor m_bgColor;
QColor m_foregroundColor;
};
#endif // NOTIFIERBOX_H

View File

@@ -45,7 +45,8 @@ QVector<const char *> InfoWindow::m_keys = {
"CTRL + C",
"CTRL + S",
"CTRL + Z",
QT_TR_NOOP("Right Click")
QT_TR_NOOP("Right Click"),
QT_TR_NOOP("Mouse Wheel")
};
QVector<const char *> InfoWindow::m_description = {
@@ -55,7 +56,8 @@ QVector<const char *> InfoWindow::m_description = {
QT_TR_NOOP("Copy to clipboard"),
QT_TR_NOOP("Save selection as a file"),
QT_TR_NOOP("Undo the last modification"),
QT_TR_NOOP("Show color picker")
QT_TR_NOOP("Show color picker"),
QT_TR_NOOP("Change draw tool thickness")
};
void InfoWindow::initInfoTable() {

View File

@@ -99,6 +99,14 @@ void ConfigHandler::setDisabledTrayIcon(const bool disabledTrayIcon) {
m_settings.setValue("disabledTrayIcon", disabledTrayIcon);
}
int ConfigHandler::drawThicknessValue() {
return m_settings.value("drawThickness").toInt();
}
void ConfigHandler::setdrawThickness(const int thickness) {
m_settings.setValue("drawThickness", thickness);
}
bool ConfigHandler::initiatedIsSet() {
return m_settings.value("initiated").toBool();
}

View File

@@ -54,6 +54,9 @@ public:
bool disabledTrayIconValue();
void setDisabledTrayIcon(const bool);
int drawThicknessValue();
void setdrawThickness(const int);
bool initiatedIsSet();
void setInitiated();
void setNotInitiated();