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

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