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/loadspinner.cpp \
src/capture/workers/imgur/imagelabel.cpp \ src/capture/workers/imgur/imagelabel.cpp \
src/capture/workers/imgur/notificationwidget.cpp \ src/capture/workers/imgur/notificationwidget.cpp \
src/core/resourceexporter.cpp src/core/resourceexporter.cpp \
src/capture/widget/notifierbox.cpp
HEADERS += \ HEADERS += \
src/capture/widget/buttonhandler.h \ src/capture/widget/buttonhandler.h \
@@ -131,7 +132,8 @@ HEADERS += \
src/capture/workers/imgur/loadspinner.h \ src/capture/workers/imgur/loadspinner.h \
src/capture/workers/imgur/imagelabel.h \ src/capture/workers/imgur/imagelabel.h \
src/capture/workers/imgur/notificationwidget.h \ src/capture/workers/imgur/notificationwidget.h \
src/core/resourceexporter.h src/core/resourceexporter.h \
src/capture/widget/notifierbox.h
RESOURCES += \ RESOURCES += \
graphics.qrc graphics.qrc

View File

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

View File

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

View File

@@ -102,7 +102,8 @@ void Screenshot::paintInPainter(QPainter &painter,
{ {
const QVector<QPoint> &points = modification->points(); const QVector<QPoint> &points = modification->points();
QColor color = modification->color(); 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 ArrowWidth = 10;
const int ArrowHeight = 18; const int ArrowHeight = 18;
QPainterPath getArrowHead(QPoint p1, QPoint p2) { QPainterPath getArrowHead(QPoint p1, QPoint p2, const int thickness) {
QLineF body(p1, p2); QLineF body(p1, p2);
int originalLength = body.length(); int originalLength = body.length();
body.setLength(ArrowWidth); body.setLength(ArrowWidth + thickness*2);
// move across the line up to the head // move across the line up to the head
//QPointF =;
QLineF temp(QPoint(0,0), p2-p1); QLineF temp(QPoint(0,0), p2-p1);
temp.setLength(originalLength-ArrowHeight); temp.setLength(originalLength - ArrowHeight - thickness*2);
QPointF bottonTranslation(temp.p2()); QPointF bottonTranslation(temp.p2());
// generates the transformation to center of the arrowhead // 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 // 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); QLineF l(p1, p2);
l.setLength(l.length()-ArrowHeight); l.setLength(l.length() - ArrowHeight - thickness*2);
return l.toLine(); return l.toLine();
} }
@@ -89,11 +88,12 @@ CaptureTool::ToolWorkType ArrowTool::toolType() const {
void ArrowTool::processImage( void ArrowTool::processImage(
QPainter &painter, QPainter &painter,
const QVector<QPoint> &points, 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.drawLine(getShorterLine(points[0], points[1])); painter.drawLine(getShorterLine(points[0], points[1], thickness));
painter.fillPath(getArrowHead(points[0], points[1]), QBrush(color)); painter.fillPath(getArrowHead(points[0], points[1], thickness), QBrush(color));
} }
void ArrowTool::onPressed() { void ArrowTool::onPressed() {

View File

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

View File

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

View File

@@ -49,9 +49,10 @@ CaptureTool::ToolWorkType CircleTool::toolType() const {
void CircleTool::processImage( void CircleTool::processImage(
QPainter &painter, QPainter &painter,
const QVector<QPoint> &points, 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])); painter.drawEllipse(QRect(points[0], points[1]));
} }

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -49,9 +49,10 @@ CaptureTool::ToolWorkType PencilTool::toolType() const {
void PencilTool::processImage( void PencilTool::processImage(
QPainter &painter, QPainter &painter,
const QVector<QPoint> &points, 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()); painter.drawPolyline(points.data(), points.size());
} }

View File

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

View File

@@ -49,9 +49,10 @@ CaptureTool::ToolWorkType RectangleTool::toolType() const {
void RectangleTool::processImage( void RectangleTool::processImage(
QPainter &painter, QPainter &painter,
const QVector<QPoint> &points, 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.setBrush(QBrush(color));
painter.drawRect(QRect(points[0], points[1])); painter.drawRect(QRect(points[0], points[1]));
painter.setBrush(QBrush()); painter.setBrush(QBrush());

View File

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

View File

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

View File

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

View File

@@ -49,9 +49,10 @@ CaptureTool::ToolWorkType SelectionTool::toolType() const {
void SelectionTool::processImage( void SelectionTool::processImage(
QPainter &painter, QPainter &painter,
const QVector<QPoint> &points, 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])); painter.drawRect(QRect(points[0], points[1]));
} }

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -25,6 +25,7 @@
#include "src/capture/capturemodification.h" #include "src/capture/capturemodification.h"
#include "capturewidget.h" #include "capturewidget.h"
#include "capturebutton.h" #include "capturebutton.h"
#include "src/capture/widget/notifierbox.h"
#include "src/capture/widget/colorpicker.h" #include "src/capture/widget/colorpicker.h"
#include "src/utils/screengrabber.h" #include "src/utils/screengrabber.h"
#include "src/utils/confighandler.h" #include "src/utils/confighandler.h"
@@ -55,7 +56,9 @@ CaptureWidget::CaptureWidget(const QString &forcedSavePath, QWidget *parent) :
m_forcedSavePath(forcedSavePath), m_forcedSavePath(forcedSavePath),
m_state(CaptureButton::TYPE_MOVESELECTION) m_state(CaptureButton::TYPE_MOVESELECTION)
{ {
m_showInitialMsg = ConfigHandler().showHelpValue(); ConfigHandler config;
m_showInitialMsg = config.showHelpValue();
m_thickness = config.drawThicknessValue();
setAttribute(Qt::WA_DeleteOnClose); setAttribute(Qt::WA_DeleteOnClose);
// create selection handlers // create selection handlers
@@ -92,10 +95,15 @@ CaptureWidget::CaptureWidget(const QString &forcedSavePath, QWidget *parent) :
// init interface color // init interface color
m_colorPicker = new ColorPicker(this); m_colorPicker = new ColorPicker(this);
m_colorPicker->hide(); 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() { CaptureWidget::~CaptureWidget() {
ConfigHandler().setdrawThickness(m_thickness);
} }
// redefineButtons retrieves the buttons configured to be shown with the // 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." QString helpTxt = tr("Select an area with the mouse, or press Esc to exit."
"\nPress Enter to capture the screen." "\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 // We draw the white contrasting background for the text, using the
//same text and options to get the boundingRect that the text will have. //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); QRectF bRect = painter.boundingRect(helpRect, Qt::AlignCenter, helpTxt);
// These four calls provide padding for the rect // These four calls provide padding for the rect
@@ -177,10 +180,15 @@ void CaptureWidget::paintEvent(QPaintEvent *) {
bRect.setX(bRect.x() - 12); bRect.setX(bRect.x() - 12);
bRect.setY(bRect.y() - 10); bRect.setY(bRect.y() - 10);
QColor rectColor(m_uiColor);
rectColor.setAlpha(180);
painter.setBrush(QBrush(rectColor, Qt::SolidPattern));
painter.drawRect(bRect); painter.drawRect(bRect);
// Draw the text: // 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); painter.drawText(helpRect, Qt::AlignCenter, helpTxt);
} }
@@ -212,6 +220,7 @@ void CaptureWidget::mousePressEvent(QMouseEvent *e) {
if (m_state != CaptureButton::TYPE_MOVESELECTION) { if (m_state != CaptureButton::TYPE_MOVESELECTION) {
auto mod = new CaptureModification(m_state, e->pos(), auto mod = new CaptureModification(m_state, e->pos(),
m_colorPicker->drawColor(), m_colorPicker->drawColor(),
m_thickness,
this); this);
m_modifications.append(mod); m_modifications.append(mod);
return; 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 CaptureWidget::undo() {
bool itemRemoved = false; bool itemRemoved = false;
if (!m_modifications.isEmpty()) { if (!m_modifications.isEmpty()) {

View File

@@ -38,6 +38,7 @@ class QNetworkAccessManager;
class QNetworkReply; class QNetworkReply;
class ColorPicker; class ColorPicker;
class Screenshot; class Screenshot;
class NotifierBox;
class CaptureWidget : public QWidget { class CaptureWidget : public QWidget {
Q_OBJECT Q_OBJECT
@@ -70,6 +71,7 @@ protected:
void mouseMoveEvent(QMouseEvent *); void mouseMoveEvent(QMouseEvent *);
void mouseReleaseEvent(QMouseEvent *); void mouseReleaseEvent(QMouseEvent *);
void keyPressEvent(QKeyEvent *); void keyPressEvent(QKeyEvent *);
void wheelEvent(QWheelEvent *);
QRegion handleMask() const; QRegion handleMask() const;
@@ -91,6 +93,9 @@ protected:
const QString m_forcedSavePath; const QString m_forcedSavePath;
int m_thickness;
NotifierBox *m_notifierBox;
// naming convention for handles // naming convention for handles
// T top, B bottom, R Right, L left // T top, B bottom, R Right, L left
// 2 letters: a corner // 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 + C",
"CTRL + S", "CTRL + S",
"CTRL + Z", "CTRL + Z",
QT_TR_NOOP("Right Click") QT_TR_NOOP("Right Click"),
QT_TR_NOOP("Mouse Wheel")
}; };
QVector<const char *> InfoWindow::m_description = { 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("Copy to clipboard"),
QT_TR_NOOP("Save selection as a file"), QT_TR_NOOP("Save selection as a file"),
QT_TR_NOOP("Undo the last modification"), 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() { void InfoWindow::initInfoTable() {

View File

@@ -99,6 +99,14 @@ void ConfigHandler::setDisabledTrayIcon(const bool disabledTrayIcon) {
m_settings.setValue("disabledTrayIcon", 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() { bool ConfigHandler::initiatedIsSet() {
return m_settings.value("initiated").toBool(); return m_settings.value("initiated").toBool();
} }

View File

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