diff --git a/flameshot.pro b/flameshot.pro index b86bf79e..d62071e8 100644 --- a/flameshot.pro +++ b/flameshot.pro @@ -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 diff --git a/src/capture/capturemodification.cpp b/src/capture/capturemodification.cpp index d0df78e8..2a2ae419 100644 --- a/src/capture/capturemodification.cpp +++ b/src/capture/capturemodification.cpp @@ -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) { diff --git a/src/capture/capturemodification.h b/src/capture/capturemodification.h index 620b563e..c07ab669 100644 --- a/src/capture/capturemodification.h +++ b/src/capture/capturemodification.h @@ -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 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 m_coords; CaptureTool *m_tool; + int m_thickness; }; diff --git a/src/capture/screenshot.cpp b/src/capture/screenshot.cpp index 4d6c7f01..51d8a303 100644 --- a/src/capture/screenshot.cpp +++ b/src/capture/screenshot.cpp @@ -102,7 +102,8 @@ void Screenshot::paintInPainter(QPainter &painter, { const QVector &points = modification->points(); QColor color = modification->color(); - modification->tool()->processImage(painter, points, color); + int thickness = modification->thickness(); + modification->tool()->processImage(painter, points, color, thickness); } diff --git a/src/capture/tools/arrowtool.cpp b/src/capture/tools/arrowtool.cpp index 493da1c7..9566745b 100644 --- a/src/capture/tools/arrowtool.cpp +++ b/src/capture/tools/arrowtool.cpp @@ -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 &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() { diff --git a/src/capture/tools/arrowtool.h b/src/capture/tools/arrowtool.h index 1d440013..81c77aac 100644 --- a/src/capture/tools/arrowtool.h +++ b/src/capture/tools/arrowtool.h @@ -37,7 +37,8 @@ public: void processImage( QPainter &painter, const QVector &points, - const QColor &color) override; + const QColor &color, + const int thickness) override; void onPressed() override; diff --git a/src/capture/tools/capturetool.h b/src/capture/tools/capturetool.h index 6a1b9a4a..199c92b7 100644 --- a/src/capture/tools/capturetool.h +++ b/src/capture/tools/capturetool.h @@ -60,7 +60,8 @@ public: virtual void processImage( QPainter &painter, const QVector &points, - const QColor &color) = 0; + const QColor &color, + const int thickness) = 0; signals: void requestAction(Request r); diff --git a/src/capture/tools/circletool.cpp b/src/capture/tools/circletool.cpp index 9d25eb9e..0ea0b74f 100644 --- a/src/capture/tools/circletool.cpp +++ b/src/capture/tools/circletool.cpp @@ -49,9 +49,10 @@ CaptureTool::ToolWorkType CircleTool::toolType() const { void CircleTool::processImage( QPainter &painter, const QVector &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])); } diff --git a/src/capture/tools/circletool.h b/src/capture/tools/circletool.h index 426cc1af..af20b9e6 100644 --- a/src/capture/tools/circletool.h +++ b/src/capture/tools/circletool.h @@ -37,7 +37,8 @@ public: void processImage( QPainter &painter, const QVector &points, - const QColor &color) override; + const QColor &color, + const int thickness) override; void onPressed() override; diff --git a/src/capture/tools/copytool.cpp b/src/capture/tools/copytool.cpp index 8dd51559..a16871d9 100644 --- a/src/capture/tools/copytool.cpp +++ b/src/capture/tools/copytool.cpp @@ -49,11 +49,13 @@ CaptureTool::ToolWorkType CopyTool::toolType() const { void CopyTool::processImage( QPainter &painter, const QVector &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() { diff --git a/src/capture/tools/copytool.h b/src/capture/tools/copytool.h index 12138f6c..164e1e00 100644 --- a/src/capture/tools/copytool.h +++ b/src/capture/tools/copytool.h @@ -37,7 +37,8 @@ public: void processImage( QPainter &painter, const QVector &points, - const QColor &color) override; + const QColor &color, + const int thickness) override; void onPressed() override; diff --git a/src/capture/tools/exittool.cpp b/src/capture/tools/exittool.cpp index ca1f08d7..49869235 100644 --- a/src/capture/tools/exittool.cpp +++ b/src/capture/tools/exittool.cpp @@ -49,11 +49,13 @@ CaptureTool::ToolWorkType ExitTool::toolType() const { void ExitTool::processImage( QPainter &painter, const QVector &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() { diff --git a/src/capture/tools/exittool.h b/src/capture/tools/exittool.h index 981f327a..f21251b1 100644 --- a/src/capture/tools/exittool.h +++ b/src/capture/tools/exittool.h @@ -37,7 +37,8 @@ public: void processImage( QPainter &painter, const QVector &points, - const QColor &color) override; + const QColor &color, + const int thickness) override; void onPressed() override; diff --git a/src/capture/tools/imguruploadertool.cpp b/src/capture/tools/imguruploadertool.cpp index 09a73c1a..1655d2b2 100644 --- a/src/capture/tools/imguruploadertool.cpp +++ b/src/capture/tools/imguruploadertool.cpp @@ -49,11 +49,13 @@ CaptureTool::ToolWorkType ImgurUploaderTool::toolType() const { void ImgurUploaderTool::processImage( QPainter &painter, const QVector &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() { diff --git a/src/capture/tools/imguruploadertool.h b/src/capture/tools/imguruploadertool.h index 137364a3..a766fb68 100644 --- a/src/capture/tools/imguruploadertool.h +++ b/src/capture/tools/imguruploadertool.h @@ -37,7 +37,8 @@ public: void processImage( QPainter &painter, const QVector &points, - const QColor &color) override; + const QColor &color, + const int thickness) override; void onPressed() override; diff --git a/src/capture/tools/linetool.cpp b/src/capture/tools/linetool.cpp index 2824abc7..24af58d5 100644 --- a/src/capture/tools/linetool.cpp +++ b/src/capture/tools/linetool.cpp @@ -51,14 +51,15 @@ CaptureTool::ToolWorkType LineTool::toolType() const { void LineTool::processImage( QPainter &painter, const QVector &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); } diff --git a/src/capture/tools/linetool.h b/src/capture/tools/linetool.h index 6043d8ed..bc6ec74c 100644 --- a/src/capture/tools/linetool.h +++ b/src/capture/tools/linetool.h @@ -37,7 +37,8 @@ public: void processImage( QPainter &painter, const QVector &points, - const QColor &color) override; + const QColor &color, + const int thickness) override; void onPressed() override; diff --git a/src/capture/tools/markertool.cpp b/src/capture/tools/markertool.cpp index c899d09e..bb9aad05 100644 --- a/src/capture/tools/markertool.cpp +++ b/src/capture/tools/markertool.cpp @@ -51,7 +51,8 @@ CaptureTool::ToolWorkType MarkerTool::toolType() const { void MarkerTool::processImage( QPainter &painter, const QVector &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); } diff --git a/src/capture/tools/markertool.h b/src/capture/tools/markertool.h index e17e4458..2a997d18 100644 --- a/src/capture/tools/markertool.h +++ b/src/capture/tools/markertool.h @@ -37,7 +37,8 @@ public: void processImage( QPainter &painter, const QVector &points, - const QColor &color) override; + const QColor &color, + const int thickness) override; void onPressed() override; diff --git a/src/capture/tools/movetool.cpp b/src/capture/tools/movetool.cpp index 76eef841..db906476 100644 --- a/src/capture/tools/movetool.cpp +++ b/src/capture/tools/movetool.cpp @@ -49,11 +49,13 @@ CaptureTool::ToolWorkType MoveTool::toolType() const { void MoveTool::processImage( QPainter &painter, const QVector &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() { diff --git a/src/capture/tools/movetool.h b/src/capture/tools/movetool.h index e9841911..7502e01c 100644 --- a/src/capture/tools/movetool.h +++ b/src/capture/tools/movetool.h @@ -37,7 +37,8 @@ public: void processImage( QPainter &painter, const QVector &points, - const QColor &color) override; + const QColor &color, + const int thickness) override; void onPressed() override; diff --git a/src/capture/tools/penciltool.cpp b/src/capture/tools/penciltool.cpp index 14c84803..2b8f5f89 100644 --- a/src/capture/tools/penciltool.cpp +++ b/src/capture/tools/penciltool.cpp @@ -49,9 +49,10 @@ CaptureTool::ToolWorkType PencilTool::toolType() const { void PencilTool::processImage( QPainter &painter, const QVector &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()); } diff --git a/src/capture/tools/penciltool.h b/src/capture/tools/penciltool.h index 271d5973..5de5630e 100644 --- a/src/capture/tools/penciltool.h +++ b/src/capture/tools/penciltool.h @@ -37,7 +37,8 @@ public: void processImage( QPainter &painter, const QVector &points, - const QColor &color) override; + const QColor &color, + const int thickness) override; void onPressed() override; diff --git a/src/capture/tools/rectangletool.cpp b/src/capture/tools/rectangletool.cpp index 42d97d36..d12419a6 100644 --- a/src/capture/tools/rectangletool.cpp +++ b/src/capture/tools/rectangletool.cpp @@ -49,9 +49,10 @@ CaptureTool::ToolWorkType RectangleTool::toolType() const { void RectangleTool::processImage( QPainter &painter, const QVector &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()); diff --git a/src/capture/tools/rectangletool.h b/src/capture/tools/rectangletool.h index b569d7cf..2477b2cc 100644 --- a/src/capture/tools/rectangletool.h +++ b/src/capture/tools/rectangletool.h @@ -37,7 +37,8 @@ public: void processImage( QPainter &painter, const QVector &points, - const QColor &color) override; + const QColor &color, + const int thickness) override; void onPressed() override; diff --git a/src/capture/tools/savetool.cpp b/src/capture/tools/savetool.cpp index 79ff5f07..347d615e 100644 --- a/src/capture/tools/savetool.cpp +++ b/src/capture/tools/savetool.cpp @@ -49,11 +49,13 @@ CaptureTool::ToolWorkType SaveTool::toolType() const { void SaveTool::processImage( QPainter &painter, const QVector &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() { diff --git a/src/capture/tools/savetool.h b/src/capture/tools/savetool.h index c6f9f150..f24663ab 100644 --- a/src/capture/tools/savetool.h +++ b/src/capture/tools/savetool.h @@ -37,7 +37,8 @@ public: void processImage( QPainter &painter, const QVector &points, - const QColor &color) override; + const QColor &color, + const int thickness) override; void onPressed() override; diff --git a/src/capture/tools/selectiontool.cpp b/src/capture/tools/selectiontool.cpp index e169beb2..f621f744 100644 --- a/src/capture/tools/selectiontool.cpp +++ b/src/capture/tools/selectiontool.cpp @@ -49,9 +49,10 @@ CaptureTool::ToolWorkType SelectionTool::toolType() const { void SelectionTool::processImage( QPainter &painter, const QVector &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])); } diff --git a/src/capture/tools/selectiontool.h b/src/capture/tools/selectiontool.h index 1a3ab5c2..8a8a5dd5 100644 --- a/src/capture/tools/selectiontool.h +++ b/src/capture/tools/selectiontool.h @@ -37,7 +37,8 @@ public: void processImage( QPainter &painter, const QVector &points, - const QColor &color) override; + const QColor &color, + const int thickness) override; void onPressed() override; diff --git a/src/capture/tools/sizeindicatortool.cpp b/src/capture/tools/sizeindicatortool.cpp index 631fd2ef..354e2630 100644 --- a/src/capture/tools/sizeindicatortool.cpp +++ b/src/capture/tools/sizeindicatortool.cpp @@ -49,11 +49,13 @@ CaptureTool::ToolWorkType SizeIndicatorTool::toolType() const { void SizeIndicatorTool::processImage( QPainter &painter, const QVector &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() { diff --git a/src/capture/tools/sizeindicatortool.h b/src/capture/tools/sizeindicatortool.h index 2f6be085..7be04647 100644 --- a/src/capture/tools/sizeindicatortool.h +++ b/src/capture/tools/sizeindicatortool.h @@ -37,7 +37,8 @@ public: void processImage( QPainter &painter, const QVector &points, - const QColor &color) override; + const QColor &color, + const int thickness) override; void onPressed() override; diff --git a/src/capture/tools/undotool.cpp b/src/capture/tools/undotool.cpp index c19e70df..e3060ce6 100644 --- a/src/capture/tools/undotool.cpp +++ b/src/capture/tools/undotool.cpp @@ -49,11 +49,13 @@ CaptureTool::ToolWorkType UndoTool::toolType() const { void UndoTool::processImage( QPainter &painter, const QVector &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() { diff --git a/src/capture/tools/undotool.h b/src/capture/tools/undotool.h index b531310a..88fcd4a9 100644 --- a/src/capture/tools/undotool.h +++ b/src/capture/tools/undotool.h @@ -37,7 +37,8 @@ public: void processImage( QPainter &painter, const QVector &points, - const QColor &color) override; + const QColor &color, + const int thickness) override; void onPressed() override; diff --git a/src/capture/widget/capturewidget.cpp b/src/capture/widget/capturewidget.cpp index 206e141d..98b69d73 100644 --- a/src/capture/widget/capturewidget.cpp +++ b/src/capture/widget/capturewidget.cpp @@ -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()) { diff --git a/src/capture/widget/capturewidget.h b/src/capture/widget/capturewidget.h index a4842266..00b5ca36 100644 --- a/src/capture/widget/capturewidget.h +++ b/src/capture/widget/capturewidget.h @@ -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 diff --git a/src/capture/widget/notifierbox.cpp b/src/capture/widget/notifierbox.cpp new file mode 100644 index 00000000..5618cb49 --- /dev/null +++ b/src/capture/widget/notifierbox.cpp @@ -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 . + +#include "notifierbox.h" +#include "src/utils/confighandler.h" +#include "src/capture/widget/capturebutton.h" +#include +#include + +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(); +} diff --git a/src/capture/widget/notifierbox.h b/src/capture/widget/notifierbox.h new file mode 100644 index 00000000..cf0372c4 --- /dev/null +++ b/src/capture/widget/notifierbox.h @@ -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 . + +#ifndef NOTIFIERBOX_H +#define NOTIFIERBOX_H + +#include + +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 diff --git a/src/infowindow.cpp b/src/infowindow.cpp index b01af737..3f8eafef 100644 --- a/src/infowindow.cpp +++ b/src/infowindow.cpp @@ -45,7 +45,8 @@ QVector 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 InfoWindow::m_description = { @@ -55,7 +56,8 @@ QVector 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() { diff --git a/src/utils/confighandler.cpp b/src/utils/confighandler.cpp index 8b84f947..f8973101 100644 --- a/src/utils/confighandler.cpp +++ b/src/utils/confighandler.cpp @@ -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(); } diff --git a/src/utils/confighandler.h b/src/utils/confighandler.h index 0fd43cce..f77de5c7 100644 --- a/src/utils/confighandler.h +++ b/src/utils/confighandler.h @@ -54,6 +54,9 @@ public: bool disabledTrayIconValue(); void setDisabledTrayIcon(const bool); + int drawThicknessValue(); + void setdrawThickness(const int); + bool initiatedIsSet(); void setInitiated(); void setNotInitiated();