Merge branch 'master-flameshotorg' into master_nc_merge_upstream

# Conflicts:
#	.travis.yml
#	appveyor.yml
#	data/graphics.qrc
#	data/img/app/keyboard.svg
#	data/img/material/black/delete.png
#	data/img/material/black/delete.svg
#	data/img/material/black/filepath.svg
#	data/img/material/black/shortcut.svg
#	data/img/material/white/filepath.svg
#	data/img/material/white/shortcut.svg
#	data/translations/Internationalization_hu.ts
#	data/translations/Internationalization_ka.ts
#	external/Qt-Color-Widgets/src/color_wheel.cpp
#	external/singleapplication/singleapplication.cpp
#	flameshot.pro
#	src/cli/commandlineparser.cpp
#	src/config/buttonlistview.cpp
#	src/config/configwindow.cpp
#	src/config/configwindow.h
#	src/config/geneneralconf.cpp
#	src/config/geneneralconf.h
#	src/config/uicoloreditor.cpp
#	src/config/uicoloreditor.h
#	src/core/controller.cpp
#	src/core/globalshortcutfilter.cpp
#	src/main.cpp
#	src/third-party/Qt-Color-Widgets/src/color_utils.cpp
#	src/tools/abstractactiontool.h
#	src/tools/abstractpathtool.h
#	src/tools/arrow/arrowtool.cpp
#	src/tools/arrow/arrowtool.h
#	src/tools/blur/blurtool.cpp
#	src/tools/capturetool.h
#	src/tools/circle/circletool.cpp
#	src/tools/circle/circletool.h
#	src/tools/copy/copytool.cpp
#	src/tools/copy/copytool.h
#	src/tools/exit/exittool.cpp
#	src/tools/exit/exittool.h
#	src/tools/imgur/imguruploader.cpp
#	src/tools/launcher/applaunchertool.cpp
#	src/tools/launcher/applaunchertool.h
#	src/tools/launcher/applauncherwidget.cpp
#	src/tools/launcher/openwithprogram.cpp
#	src/tools/line/linetool.cpp
#	src/tools/line/linetool.h
#	src/tools/marker/markertool.cpp
#	src/tools/marker/markertool.h
#	src/tools/move/movetool.cpp
#	src/tools/pencil/penciltool.cpp
#	src/tools/pencil/penciltool.h
#	src/tools/pin/pintool.cpp
#	src/tools/pin/pintool.h
#	src/tools/pin/pinwidget.cpp
#	src/tools/pixelate/pixelatetool.h
#	src/tools/rectangle/rectangletool.cpp
#	src/tools/rectangle/rectangletool.h
#	src/tools/redo/redotool.cpp
#	src/tools/redo/redotool.h
#	src/tools/save/savetool.cpp
#	src/tools/save/savetool.h
#	src/tools/selection/selectiontool.cpp
#	src/tools/selection/selectiontool.h
#	src/tools/sizeindicator/sizeindicatortool.cpp
#	src/tools/sizeindicator/sizeindicatortool.h
#	src/tools/storage/imgur/imguruploader.h
#	src/tools/storage/imgur/imguruploadertool.cpp
#	src/tools/storage/imgur/imguruploadertool.h
#	src/tools/text/textconfig.cpp
#	src/tools/text/texttool.cpp
#	src/tools/text/texttool.h
#	src/tools/toolfactory.cpp
#	src/tools/toolfactory.h
#	src/tools/undo/undotool.cpp
#	src/tools/undo/undotool.h
#	src/utils/confighandler.cpp
#	src/utils/confighandler.h
#	src/utils/dbusutils.cpp
#	src/utils/screenshotsaver.cpp
#	src/utils/screenshotsaver.h
#	src/widgets/capture/buttonhandler.cpp
#	src/widgets/capture/buttonhandler.h
#	src/widgets/capture/capturebutton.cpp
#	src/widgets/capture/capturebutton.h
#	src/widgets/capture/capturewidget.cpp
#	src/widgets/capture/capturewidget.h
#	src/widgets/capture/colorpicker.cpp
#	src/widgets/capturelauncher.cpp
#	src/widgets/infowindow.cpp
#	src/widgets/infowindow.h
#	src/widgets/panel/sidepanelwidget.cpp
#	src/widgets/panel/utilitypanel.cpp
#	src/widgets/panel/utilitypanel.h
#	translations/Internationalization_ca.ts
#	translations/Internationalization_de_DE.ts
#	translations/Internationalization_es.ts
#	translations/Internationalization_fr.ts
#	translations/Internationalization_ja.ts
#	translations/Internationalization_nl.ts
#	translations/Internationalization_pl.ts
#	translations/Internationalization_pt_br.ts
#	translations/Internationalization_ru.ts
#	translations/Internationalization_sk.ts
#	translations/Internationalization_sr.ts
#	translations/Internationalization_tr.ts
#	translations/Internationalization_uk.ts
#	translations/Internationalization_zh_CN.ts
#	translations/Internationalization_zh_TW.ts
This commit is contained in:
Yuriy Puchkov
2020-09-24 18:52:49 +03:00
351 changed files with 23741 additions and 14935 deletions

View File

@@ -0,0 +1,23 @@
add_subdirectory(panel)
add_subdirectory(capture)
# Required to generate MOC
target_sources(
flameshot
PRIVATE capturelauncher.h
draggablewidgetmaker.h
imagelabel.h
infowindow.h
loadspinner.h
notificationwidget.h
orientablepushbutton.h)
target_sources(
flameshot
PRIVATE capturelauncher.cpp
draggablewidgetmaker.cpp
imagelabel.cpp
infowindow.cpp
loadspinner.cpp
notificationwidget.cpp
orientablepushbutton.cpp)

View File

@@ -0,0 +1,23 @@
# Required to generate MOC
target_sources(
flameshot
PRIVATE buttonhandler.h
capturebutton.h
capturetoolbutton.h
capturewidget.h
colorpicker.h
hovereventfilter.h
selectionwidget.h
notifierbox.h)
target_sources(
flameshot
PRIVATE buttonhandler.cpp
capturebutton.cpp
capturetoolbutton.cpp
capturewidget.cpp
colorpicker.cpp
hovereventfilter.cpp
modificationcommand.cpp
notifierbox.cpp
selectionwidget.cpp)

View File

@@ -24,7 +24,8 @@
// ButtonHandler is a habdler for every active button. It makes easier to
// manipulate the buttons as a unit.
ButtonHandler::ButtonHandler(const QVector<CaptureButton*>& v, QObject* parent)
ButtonHandler::ButtonHandler(const QVector<CaptureToolButton*>& v,
QObject* parent)
: QObject(parent)
{
setButtons(v);
@@ -39,7 +40,7 @@ ButtonHandler::ButtonHandler(QObject* parent)
void ButtonHandler::hide()
{
for (CaptureButton* b : m_vectorButtons)
for (CaptureToolButton* b : m_vectorButtons)
b->hide();
}
@@ -48,14 +49,14 @@ void ButtonHandler::show()
if (m_vectorButtons.isEmpty() || m_vectorButtons.first()->isVisible()) {
return;
}
for (CaptureButton* b : m_vectorButtons)
for (CaptureToolButton* b : m_vectorButtons)
b->animatedShow();
}
bool ButtonHandler::isVisible() const
{
bool ret = true;
for (const CaptureButton* b : m_vectorButtons) {
for (const CaptureToolButton* b : m_vectorButtons) {
if (!b->isVisible()) {
ret = false;
break;
@@ -239,7 +240,7 @@ QVector<QPoint> ButtonHandler::verticalPoints(const QPoint& center,
QRect ButtonHandler::intersectWithAreas(const QRect& rect)
{
QRect res;
for (const QRect& r : m_screenRegions.rects()) {
for (const QRect& r : m_screenRegions) {
QRect temp = rect.intersected(r);
if (temp.height() * temp.width() > res.height() * res.width()) {
res = temp;
@@ -361,12 +362,12 @@ void ButtonHandler::adjustHorizontalCenter(QPoint& center)
}
// setButtons redefines the buttons of the button handler
void ButtonHandler::setButtons(const QVector<CaptureButton*> v)
void ButtonHandler::setButtons(const QVector<CaptureToolButton*> v)
{
if (v.isEmpty())
return;
for (CaptureButton* b : m_vectorButtons)
for (CaptureToolButton* b : m_vectorButtons)
delete (b);
m_vectorButtons = v;
m_buttonBaseSize = GlobalValues::buttonBaseSize();

View File

@@ -17,12 +17,12 @@
#pragma once
#include "capturebutton.h"
#include "capturetoolbutton.h"
#include <QObject>
#include <QRegion>
#include <QVector>
class CaptureButton;
class CaptureToolButton;
class QRect;
class QPoint;
@@ -30,7 +30,8 @@ class ButtonHandler : public QObject
{
Q_OBJECT
public:
ButtonHandler(const QVector<CaptureButton*>&, QObject* parent = nullptr);
ButtonHandler(const QVector<CaptureToolButton*>&,
QObject* parent = nullptr);
explicit ButtonHandler(QObject* parent = nullptr);
void hideSectionUnderMouse(const QPoint& p);
@@ -39,7 +40,7 @@ public:
bool buttonsAreInside() const;
size_t size() const;
void setButtons(const QVector<CaptureButton*>);
void setButtons(const QVector<CaptureToolButton*>);
bool contains(const QPoint& p) const;
void updateScreenRegions(const QVector<QRect>& rects);
void updateScreenRegions(const QRect& rect);
@@ -59,7 +60,7 @@ private:
QRect intersectWithAreas(const QRect& rect);
QVector<CaptureButton*> m_vectorButtons;
QVector<CaptureToolButton*> m_vectorButtons;
QRegion m_screenRegions;

View File

@@ -16,56 +16,35 @@
// along with Flameshot. If not, see <http://www.gnu.org/licenses/>.
#include "capturebutton.h"
#include "src/tools/capturetool.h"
#include "src/tools/toolfactory.h"
#include "src/utils/colorutils.h"
#include "src/utils/confighandler.h"
#include "src/utils/globalvalues.h"
#include "src/widgets/capture/capturewidget.h"
#include <QApplication>
#include <QGraphicsDropShadowEffect>
#include <QIcon>
#include <QMouseEvent>
#include <QPropertyAnimation>
#include <QToolTip>
// Button represents a single button of the capture widget, it can enable
// multiple functionality.
CaptureButton::CaptureButton(const ButtonType t, QWidget* parent)
CaptureButton::CaptureButton(QWidget* parent)
: QPushButton(parent)
, m_buttonType(t)
{
initButton();
if (t == TYPE_SELECTIONINDICATOR) {
QFont f = this->font();
setFont(QFont(f.family(), 7, QFont::Bold));
} else {
updateIcon();
}
setCursor(Qt::ArrowCursor);
init();
}
void CaptureButton::initButton()
CaptureButton::CaptureButton(const QString& text, QWidget* parent)
: QPushButton(text, parent)
{
m_tool = ToolFactory().CreateTool(m_buttonType, this);
init();
}
CaptureButton::CaptureButton(const QIcon& icon,
const QString& text,
QWidget* parent)
: QPushButton(icon, text, parent)
{
init();
}
void CaptureButton::init()
{
setCursor(Qt::ArrowCursor);
setFocusPolicy(Qt::NoFocus);
resize(GlobalValues::buttonBaseSize(), GlobalValues::buttonBaseSize());
setMask(QRegion(QRect(-1,
-1,
GlobalValues::buttonBaseSize() + 2,
GlobalValues::buttonBaseSize() + 2),
QRegion::Ellipse));
setToolTip(m_tool->description());
m_emergeAnimation = new QPropertyAnimation(this, "size", this);
m_emergeAnimation->setEasingCurve(QEasingCurve::InOutQuad);
m_emergeAnimation->setDuration(80);
m_emergeAnimation->setStartValue(QSize(0, 0));
m_emergeAnimation->setEndValue(
QSize(GlobalValues::buttonBaseSize(), GlobalValues::buttonBaseSize()));
auto dsEffect = new QGraphicsDropShadowEffect(this);
dsEffect->setBlurRadius(5);
@@ -75,131 +54,36 @@ void CaptureButton::initButton()
setGraphicsEffect(dsEffect);
}
void CaptureButton::updateIcon()
{
setIcon(icon());
setIconSize(size() * 0.6);
}
QVector<CaptureButton::ButtonType> CaptureButton::getIterableButtonTypes()
{
return iterableButtonTypes;
}
QString CaptureButton::globalStyleSheet()
{
QColor mainColor = ConfigHandler().uiMainColorValue();
QString baseSheet = "CaptureButton { border-radius: %3;"
"background-color: %1; color: %4 }"
"CaptureButton:hover { background-color: %2; }"
"CaptureButton:pressed:!hover { "
"background-color: %1; }";
// define color when mouse is hovering
QColor contrast = ColorUtils::contrastColor(m_mainColor);
// foreground color
QString color = ColorUtils::colorIsDark(mainColor) ? "white" : "black";
return baseSheet.arg(mainColor.name())
.arg(contrast.name())
.arg(GlobalValues::buttonBaseSize() / 2)
.arg(color);
return CaptureButton(nullptr).styleSheet();
}
QString CaptureButton::styleSheet() const
{
QString baseSheet = "CaptureButton { border-radius: %3;"
QString baseSheet = "CaptureButton { border: none;"
"padding: 3px 8px;"
"background-color: %1; color: %4 }"
"CaptureToolButton { border-radius: %3;"
"padding: 0; }"
"CaptureButton:hover { background-color: %2; }"
"CaptureButton:pressed:!hover { "
"background-color: %1; }";
// define color when mouse is hovering
QColor contrast = ColorUtils::contrastColor(m_mainColor);
// foreground color
QString color = ColorUtils::colorIsDark(m_mainColor) ? "white" : "black";
QColor color = ColorUtils::colorIsDark(m_mainColor) ? Qt::white : Qt::black;
return baseSheet.arg(m_mainColor.name())
.arg(contrast.name())
.arg(GlobalValues::buttonBaseSize() / 2)
.arg(color);
}
// get icon returns the icon for the type of button
QIcon CaptureButton::icon() const
{
return m_tool->icon(m_mainColor, true);
}
void CaptureButton::mousePressEvent(QMouseEvent* e)
{
if (e->button() == Qt::LeftButton) {
emit pressedButton(this);
emit pressed();
}
}
void CaptureButton::animatedShow()
{
if (!isVisible()) {
show();
m_emergeAnimation->start();
connect(
m_emergeAnimation, &QPropertyAnimation::finished, this, []() {});
}
}
CaptureTool* CaptureButton::tool() const
{
return m_tool;
.arg(color.name());
}
void CaptureButton::setColor(const QColor& c)
{
m_mainColor = c;
setStyleSheet(styleSheet());
updateIcon();
}
QColor CaptureButton::m_mainColor = ConfigHandler().uiMainColorValue();
static std::map<CaptureButton::ButtonType, int> buttonTypeOrder{
{ CaptureButton::TYPE_PENCIL, 0 },
{ CaptureButton::TYPE_DRAWER, 1 },
{ CaptureButton::TYPE_ARROW, 2 },
{ CaptureButton::TYPE_SELECTION, 3 },
{ CaptureButton::TYPE_RECTANGLE, 4 },
{ CaptureButton::TYPE_CIRCLE, 5 },
{ CaptureButton::TYPE_MARKER, 6 },
{ CaptureButton::TYPE_TEXT, 7 },
{ CaptureButton::TYPE_BLUR, 8 },
{ CaptureButton::TYPE_SELECTIONINDICATOR, 9 },
{ CaptureButton::TYPE_MOVESELECTION, 10 },
{ CaptureButton::TYPE_UNDO, 11 },
{ CaptureButton::TYPE_REDO, 12 },
{ CaptureButton::TYPE_COPY, 13 },
{ CaptureButton::TYPE_SAVE, 14 },
{ CaptureButton::TYPE_EXIT, 15 },
{ CaptureButton::TYPE_IMAGEUPLOADER, 16 },
{ CaptureButton::TYPE_OPEN_APP, 17 },
{ CaptureButton::TYPE_PIN, 18 },
};
int CaptureButton::getPriorityByButton(CaptureButton::ButtonType b)
{
auto it = buttonTypeOrder.find(b);
return it == buttonTypeOrder.cend() ? (int)buttonTypeOrder.size()
: it->second;
}
QVector<CaptureButton::ButtonType> CaptureButton::iterableButtonTypes = {
CaptureButton::TYPE_PENCIL, CaptureButton::TYPE_DRAWER,
CaptureButton::TYPE_ARROW, CaptureButton::TYPE_SELECTION,
CaptureButton::TYPE_RECTANGLE, CaptureButton::TYPE_CIRCLE,
CaptureButton::TYPE_MARKER, CaptureButton::TYPE_TEXT,
CaptureButton::TYPE_BLUR, CaptureButton::TYPE_SELECTIONINDICATOR,
CaptureButton::TYPE_MOVESELECTION, CaptureButton::TYPE_UNDO,
CaptureButton::TYPE_REDO, CaptureButton::TYPE_COPY,
CaptureButton::TYPE_SAVE, CaptureButton::TYPE_EXIT,
CaptureButton::TYPE_IMAGEUPLOADER, CaptureButton::TYPE_OPEN_APP,
CaptureButton::TYPE_PIN,
};

View File

@@ -17,83 +17,28 @@
#pragma once
#include <QMap>
#include <QPushButton>
#include <QVector>
class QWidget;
class QPropertyAnimation;
class CaptureTool;
class CaptureButton : public QPushButton
{
Q_OBJECT
public:
// Don't forget to add the new types to CaptureButton::iterableButtonTypes
// in the .cpp and the order value in the private array buttonTypeOrder
enum ButtonType
{
TYPE_PENCIL = 0,
TYPE_DRAWER = 1,
TYPE_ARROW = 2,
TYPE_SELECTION = 3,
TYPE_RECTANGLE = 4,
TYPE_CIRCLE = 5,
TYPE_MARKER = 6,
TYPE_SELECTIONINDICATOR = 7,
TYPE_MOVESELECTION = 8,
TYPE_UNDO = 9,
TYPE_COPY = 10,
TYPE_SAVE = 11,
TYPE_EXIT = 12,
TYPE_IMAGEUPLOADER = 13,
TYPE_OPEN_APP = 14,
TYPE_BLUR = 15,
TYPE_REDO = 16,
TYPE_PIN = 17,
TYPE_TEXT = 18,
};
#if QT_VERSION < QT_VERSION_CHECK(5, 5, 0)
Q_ENUMS(ButtonType)
#else
Q_ENUM(ButtonType)
#endif
CaptureButton() = delete;
explicit CaptureButton(const ButtonType, QWidget* parent = nullptr);
CaptureButton(QWidget* parent = nullptr);
CaptureButton(const QString& text, QWidget* parent = nullptr);
CaptureButton(const QIcon& icon,
const QString& text,
QWidget* parent = nullptr);
static QString globalStyleSheet();
static QVector<CaptureButton::ButtonType> getIterableButtonTypes();
static int getPriorityByButton(CaptureButton::ButtonType);
QString name() const;
QString description() const;
QIcon icon() const;
QString styleSheet() const;
CaptureTool* tool() const;
void setColor(const QColor& c);
void animatedShow();
protected:
virtual void mousePressEvent(QMouseEvent*);
static QVector<ButtonType> iterableButtonTypes;
CaptureTool* m_tool;
signals:
void pressedButton(CaptureButton*);
private:
CaptureButton(QWidget* parent = nullptr);
ButtonType m_buttonType;
QPropertyAnimation* m_emergeAnimation;
static QColor m_mainColor;
void initButton();
void updateIcon();
void init();
};

View File

@@ -0,0 +1,169 @@
// Copyright(c) 2017-2019 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 "capturetoolbutton.h"
#include "src/tools/capturetool.h"
#include "src/tools/toolfactory.h"
#include "src/utils/colorutils.h"
#include "src/utils/confighandler.h"
#include "src/utils/globalvalues.h"
#include "src/widgets/capture/capturewidget.h"
#include <QApplication>
#include <QIcon>
#include <QMouseEvent>
#include <QPropertyAnimation>
#include <QToolTip>
// Button represents a single button of the capture widget, it can enable
// multiple functionality.
CaptureToolButton::CaptureToolButton(const ButtonType t, QWidget* parent)
: CaptureButton(parent)
, m_buttonType(t)
{
initButton();
if (t == TYPE_SELECTIONINDICATOR) {
QFont f = this->font();
setFont(QFont(f.family(), 7, QFont::Bold));
} else {
updateIcon();
}
}
void CaptureToolButton::initButton()
{
m_tool = ToolFactory().CreateTool(m_buttonType, this);
resize(GlobalValues::buttonBaseSize(), GlobalValues::buttonBaseSize());
setMask(QRegion(QRect(-1,
-1,
GlobalValues::buttonBaseSize() + 2,
GlobalValues::buttonBaseSize() + 2),
QRegion::Ellipse));
setToolTip(m_tool->description());
m_emergeAnimation = new QPropertyAnimation(this, "size", this);
m_emergeAnimation->setEasingCurve(QEasingCurve::InOutQuad);
m_emergeAnimation->setDuration(80);
m_emergeAnimation->setStartValue(QSize(0, 0));
m_emergeAnimation->setEndValue(
QSize(GlobalValues::buttonBaseSize(), GlobalValues::buttonBaseSize()));
}
void CaptureToolButton::updateIcon()
{
setIcon(icon());
setIconSize(size() * 0.6);
}
QVector<CaptureToolButton::ButtonType>
CaptureToolButton::getIterableButtonTypes()
{
return iterableButtonTypes;
}
// get icon returns the icon for the type of button
QIcon CaptureToolButton::icon() const
{
return m_tool->icon(m_mainColor, true);
}
void CaptureToolButton::mousePressEvent(QMouseEvent* e)
{
if (e->button() == Qt::LeftButton) {
emit pressedButton(this);
emit pressed();
}
}
void CaptureToolButton::animatedShow()
{
if (!isVisible()) {
show();
m_emergeAnimation->start();
connect(
m_emergeAnimation, &QPropertyAnimation::finished, this, []() {});
}
}
CaptureTool* CaptureToolButton::tool() const
{
return m_tool;
}
void CaptureToolButton::setColor(const QColor& c)
{
CaptureButton::setColor(c);
updateIcon();
}
QColor CaptureToolButton::m_mainColor = ConfigHandler().uiMainColorValue();
static std::map<CaptureToolButton::ButtonType, int> buttonTypeOrder{
{ CaptureToolButton::TYPE_PENCIL, 0 },
{ CaptureToolButton::TYPE_DRAWER, 1 },
{ CaptureToolButton::TYPE_ARROW, 2 },
{ CaptureToolButton::TYPE_SELECTION, 3 },
{ CaptureToolButton::TYPE_RECTANGLE, 4 },
{ CaptureToolButton::TYPE_CIRCLE, 5 },
{ CaptureToolButton::TYPE_MARKER, 6 },
{ CaptureToolButton::TYPE_TEXT, 7 },
{ CaptureToolButton::TYPE_PIXELATE, 8 },
{ CaptureToolButton::TYPE_CIRCLECOUNT, 9 },
{ CaptureToolButton::TYPE_SELECTIONINDICATOR, 10 },
{ CaptureToolButton::TYPE_MOVESELECTION, 11 },
{ CaptureToolButton::TYPE_UNDO, 12 },
{ CaptureToolButton::TYPE_REDO, 13 },
{ CaptureToolButton::TYPE_COPY, 14 },
{ CaptureToolButton::TYPE_SAVE, 15 },
{ CaptureToolButton::TYPE_EXIT, 16 },
{ CaptureToolButton::TYPE_IMAGEUPLOADER, 17 },
{ CaptureToolButton::TYPE_OPEN_APP, 18 },
{ CaptureToolButton::TYPE_PIN, 19 },
};
int CaptureToolButton::getPriorityByButton(CaptureToolButton::ButtonType b)
{
auto it = buttonTypeOrder.find(b);
return it == buttonTypeOrder.cend() ? (int)buttonTypeOrder.size()
: it->second;
}
QVector<CaptureToolButton::ButtonType>
CaptureToolButton::iterableButtonTypes = {
CaptureToolButton::TYPE_PENCIL,
CaptureToolButton::TYPE_DRAWER,
CaptureToolButton::TYPE_ARROW,
CaptureToolButton::TYPE_SELECTION,
CaptureToolButton::TYPE_RECTANGLE,
CaptureToolButton::TYPE_CIRCLE,
CaptureToolButton::TYPE_MARKER,
CaptureToolButton::TYPE_TEXT,
CaptureToolButton::TYPE_PIXELATE,
CaptureToolButton::TYPE_SELECTIONINDICATOR,
CaptureToolButton::TYPE_MOVESELECTION,
CaptureToolButton::TYPE_UNDO,
CaptureToolButton::TYPE_REDO,
CaptureToolButton::TYPE_COPY,
CaptureToolButton::TYPE_SAVE,
CaptureToolButton::TYPE_EXIT,
CaptureToolButton::TYPE_IMAGEUPLOADER,
CaptureToolButton::TYPE_OPEN_APP,
CaptureToolButton::TYPE_PIN,
CaptureToolButton::TYPE_CIRCLECOUNT,
};

View File

@@ -0,0 +1,93 @@
// Copyright(c) 2017-2019 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 "capturebutton.h"
#include <QMap>
#include <QVector>
class QWidget;
class QPropertyAnimation;
class CaptureTool;
class CaptureToolButton : public CaptureButton
{
Q_OBJECT
public:
// Don't forget to add the new types to CaptureButton::iterableButtonTypes
// in the .cpp and the order value in the private array buttonTypeOrder
enum ButtonType
{
TYPE_PENCIL = 0,
TYPE_DRAWER = 1,
TYPE_ARROW = 2,
TYPE_SELECTION = 3,
TYPE_RECTANGLE = 4,
TYPE_CIRCLE = 5,
TYPE_MARKER = 6,
TYPE_SELECTIONINDICATOR = 7,
TYPE_MOVESELECTION = 8,
TYPE_UNDO = 9,
TYPE_COPY = 10,
TYPE_SAVE = 11,
TYPE_EXIT = 12,
TYPE_IMAGEUPLOADER = 13,
TYPE_OPEN_APP = 14,
TYPE_PIXELATE = 15,
TYPE_REDO = 16,
TYPE_PIN = 17,
TYPE_TEXT = 18,
TYPE_CIRCLECOUNT = 19,
};
Q_ENUM(ButtonType)
explicit CaptureToolButton(const ButtonType, QWidget* parent = nullptr);
static QVector<CaptureToolButton::ButtonType> getIterableButtonTypes();
static int getPriorityByButton(CaptureToolButton::ButtonType);
QString name() const;
QString description() const;
QIcon icon() const;
CaptureTool* tool() const;
void setColor(const QColor& c);
void animatedShow();
protected:
void mousePressEvent(QMouseEvent* e) override;
static QVector<ButtonType> iterableButtonTypes;
CaptureTool* m_tool;
signals:
void pressedButton(CaptureToolButton*);
private:
CaptureToolButton(QWidget* parent = nullptr);
ButtonType m_buttonType;
QPropertyAnimation* m_emergeAnimation;
static QColor m_mainColor;
void initButton();
void updateIcon();
};

View File

@@ -36,6 +36,7 @@
#include "src/widgets/capture/hovereventfilter.h"
#include "src/widgets/capture/modificationcommand.h"
#include "src/widgets/capture/notifierbox.h"
#include "src/widgets/orientablepushbutton.h"
#include "src/widgets/panel/sidepanelwidget.h"
#include <QApplication>
#include <QBuffer>
@@ -47,9 +48,10 @@
#include <QScreen>
#include <QShortcut>
#include <QUndoView>
#include <draggablewidgetmaker.h>
// CaptureWidget is the main component used to capture the screen. It contains
// an are of selection with its respective buttons.
// an area of selection with its respective buttons.
// enableSaveWIndow
CaptureWidget::CaptureWidget(const uint id,
@@ -86,7 +88,7 @@ CaptureWidget::CaptureWidget(const uint id,
setMouseTracking(true);
initContext(savePath, fullScreen);
initShortcuts();
m_context.circleCount = 1;
#ifdef Q_OS_WIN
// Top left of the whole set of screens
QPoint topLeft(0, 0);
@@ -175,13 +177,14 @@ void CaptureWidget::updateButtons()
m_uiColor = m_config.uiMainColorValue();
m_contrastUiColor = m_config.uiContrastColorValue();
QVector<CaptureButton*> vectorButtons;
for (const CaptureButton::ButtonType& t : m_config.getButtons()) {
CaptureButton* b = new CaptureButton(t, this);
if (t == CaptureButton::TYPE_SELECTIONINDICATOR) {
auto buttons = m_config.getButtons();
QVector<CaptureToolButton*> vectorButtons;
for (const CaptureToolButton::ButtonType& t : buttons) {
CaptureToolButton* b = new CaptureToolButton(t, this);
if (t == CaptureToolButton::TYPE_SELECTIONINDICATOR) {
m_sizeIndButton = b;
}
b->setColor(m_uiColor);
makeChild(b);
@@ -317,7 +320,7 @@ void CaptureWidget::paintEvent(QPaintEvent*)
painter.setRenderHint(QPainter::Antialiasing);
painter.setBrush(m_uiColor);
for (auto r : m_selection->handlerAreas()) {
painter.drawRoundRect(r, 100, 100);
painter.drawRoundedRect(r, 100, 100);
}
}
}
@@ -604,7 +607,7 @@ void CaptureWidget::keyReleaseEvent(QKeyEvent* e)
void CaptureWidget::wheelEvent(QWheelEvent* e)
{
m_context.thickness += e->delta() / 120;
m_context.thickness += e->angleDelta().y() / 120;
m_context.thickness = qBound(0, m_context.thickness, 100);
QPoint topLeft =
qApp->desktop()
@@ -624,8 +627,8 @@ void CaptureWidget::resizeEvent(QResizeEvent* e)
QWidget::resizeEvent(e);
m_context.widgetDimensions = rect();
m_context.widgetOffset = mapToGlobal(QPoint(0, 0));
m_panel->setFixedHeight(height());
if (!m_context.fullscreen) {
m_panel->setFixedHeight(height());
m_buttonHandler->updateScreenRegions(rect());
}
}
@@ -649,12 +652,32 @@ void CaptureWidget::initContext(const QString& savePath, bool fullscreen)
void CaptureWidget::initPanel()
{
m_panel = new UtilityPanel(this);
makeChild(m_panel);
QRect panelRect = rect();
if (m_context.fullscreen) {
panelRect = QGuiApplication::primaryScreen()->geometry();
}
ConfigHandler config;
if (config.showSidePanelButtonValue()) {
auto* panelToggleButton =
new OrientablePushButton(tr("Tool Settings"), this);
makeChild(panelToggleButton);
panelToggleButton->setOrientation(
OrientablePushButton::VerticalBottomToTop);
panelToggleButton->move(panelRect.x(),
panelRect.y() + panelRect.height() / 2 -
panelToggleButton->width() / 2);
panelToggleButton->setCursor(Qt::ArrowCursor);
(new DraggableWidgetMaker(this))->makeDraggable(panelToggleButton);
connect(panelToggleButton,
&QPushButton::clicked,
this,
&CaptureWidget::togglePanel);
}
m_panel = new UtilityPanel(this);
makeChild(m_panel);
panelRect.moveTo(mapFromGlobal(panelRect.topLeft()));
panelRect.setWidth(m_colorPicker->width() * 1.5);
m_panel->setGeometry(panelRect);
@@ -694,7 +717,7 @@ void CaptureWidget::initSelection()
m_selection->setGeometry(QRect());
}
void CaptureWidget::setState(CaptureButton* b)
void CaptureWidget::setState(CaptureToolButton* b)
{
if (!b) {
return;
@@ -748,6 +771,15 @@ void CaptureWidget::handleButtonSignal(CaptureTool::Request r)
m_undoStack.setIndex(0);
update();
break;
case CaptureTool::REQ_INCREMENT_CIRCLE_COUNT:
incrementCircleCount();
break;
case CaptureTool::REQ_DECREMENT_CIRCLE_COUNT:
decrementCircleCount();
break;
case CaptureTool::REQ_CLOSE_GUI:
close();
break;
@@ -766,6 +798,9 @@ void CaptureWidget::handleButtonSignal(CaptureTool::Request r)
m_undoStack.undo();
break;
case CaptureTool::REQ_REDO_MODIFICATION:
if (m_undoStack.redoText() == "Circle Counter") {
this->incrementCircleCount();
}
m_undoStack.redo();
break;
case CaptureTool::REQ_REDRAW:
@@ -775,6 +810,7 @@ void CaptureWidget::handleButtonSignal(CaptureTool::Request r)
m_panel->toggle();
break;
case CaptureTool::REQ_SHOW_COLOR_PICKER:
// TODO
break;
case CaptureTool::REQ_MOVE_MODE:
setState(m_activeButton); // Disable the actual button
@@ -830,6 +866,16 @@ void CaptureWidget::setDrawColor(const QColor& c)
}
}
void CaptureWidget::incrementCircleCount()
{
m_context.circleCount++;
}
void CaptureWidget::decrementCircleCount()
{
m_context.circleCount--;
}
void CaptureWidget::setDrawThickness(const int& t)
{
m_context.thickness = qBound(0, t, 100);
@@ -1069,7 +1115,7 @@ void CaptureWidget::saveScreenshot()
if (m_context.savePath.isEmpty()) {
ScreenshotSaver().saveToFilesystemGUI(pixmap());
} else {
ScreenshotSaver().saveToFilesystem(pixmap(), m_context.savePath);
ScreenshotSaver().saveToFilesystem(pixmap(), m_context.savePath, "");
}
close();
}

View File

@@ -26,7 +26,7 @@
#pragma once
#include "buttonhandler.h"
#include "capturebutton.h"
#include "capturetoolbutton.h"
#include "src/tools/capturecontext.h"
#include "src/tools/capturetool.h"
#include "src/utils/confighandler.h"
@@ -92,11 +92,14 @@ private slots:
void upMove();
void downMove();
void setState(CaptureButton* b);
void setState(CaptureToolButton* b);
void processTool(CaptureTool* t);
void handleButtonSignal(CaptureTool::Request r);
void setDrawColor(const QColor& c);
void setDrawThickness(const int& t);
void setDrawColor(const QColor &c);
void setDrawThickness(const int &t);
void incrementCircleCount();
void decrementCircleCount();
protected:
void paintEvent(QPaintEvent*);
@@ -119,6 +122,7 @@ protected:
// Outside selection opacity
int m_opacity;
// utility flags
bool m_mouseIsClicked;
bool m_rightClick;
@@ -145,9 +149,9 @@ private:
private:
QUndoStack m_undoStack;
QPointer<CaptureButton> m_sizeIndButton;
QPointer<CaptureToolButton> m_sizeIndButton;
// Last pressed button
QPointer<CaptureButton> m_activeButton;
QPointer<CaptureToolButton> m_activeButton;
QPointer<CaptureTool> m_activeTool;
QPointer<QWidget> m_toolWidget;

View File

@@ -89,7 +89,7 @@ void ColorPicker::paintEvent(QPaintEvent*)
highlight.moveTo(highlight.x() - 3, highlight.y() - 3);
highlight.setHeight(highlight.height() + 6);
highlight.setWidth(highlight.width() + 6);
painter.drawRoundRect(highlight, 100, 100);
painter.drawRoundedRect(highlight, 100, 100);
painter.setPen(QColor(Qt::black));
}

View File

@@ -18,7 +18,9 @@
#include "capturelauncher.h"
#include "src/core/controller.h"
#include "src/utils/screengrabber.h"
#include "src/utils/screenshotsaver.h"
#include "src/widgets/imagelabel.h"
#include "src/widgets/notificationwidget.h"
#include <QCheckBox>
#include <QComboBox>
@@ -145,6 +147,13 @@ void CaptureLauncher::captureTaken(uint id, QPixmap p)
m_imageLabel->setScreenshot(p);
show();
}
auto mode = static_cast<CaptureRequest::CaptureMode>(
m_captureType->currentData().toInt());
if (mode == CaptureRequest::FULLSCREEN_MODE) {
ScreenshotSaver().saveToFilesystemGUI(p);
}
}
void CaptureLauncher::captureFailed(uint id)

View File

@@ -0,0 +1,79 @@
// Copyright(c) 2017-2019 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 "draggablewidgetmaker.h"
#include <QMouseEvent>
DraggableWidgetMaker::DraggableWidgetMaker(QObject* parent)
: QObject(parent)
{}
void DraggableWidgetMaker::makeDraggable(QWidget* widget)
{
widget->installEventFilter(this);
}
bool DraggableWidgetMaker::eventFilter(QObject* obj, QEvent* event)
{
auto widget = static_cast<QWidget*>(obj);
// based on https://stackoverflow.com/a/12221360/964478
switch (event->type()) {
case QEvent::MouseButtonPress: {
auto mouseEvent = static_cast<QMouseEvent*>(event);
m_isPressing = false;
m_isDragging = false;
if (mouseEvent->button() == Qt::LeftButton) {
m_isPressing = true;
m_mousePressPos = mouseEvent->globalPos();
m_mouseMovePos = m_mousePressPos;
}
} break;
case QEvent::MouseMove: {
auto mouseEvent = static_cast<QMouseEvent*>(event);
if (m_isPressing) {
QPoint widgetPos = widget->mapToGlobal(widget->pos());
QPoint eventPos = mouseEvent->globalPos();
QPoint diff = eventPos - m_mouseMovePos;
QPoint newPos = widgetPos + diff;
widget->move(widget->mapFromGlobal(newPos));
if (!m_isDragging) {
QPoint totalMovedDiff = eventPos - m_mousePressPos;
if (totalMovedDiff.manhattanLength() > 3) {
m_isDragging = true;
}
}
m_mouseMovePos = eventPos;
}
} break;
case QEvent::MouseButtonRelease: {
if (m_isDragging) {
m_isPressing = false;
m_isDragging = false;
event->ignore();
return true;
}
} break;
}
return QObject::eventFilter(obj, event);
}

View File

@@ -0,0 +1,41 @@
// Copyright(c) 2017-2019 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 <QEvent>
#include <QObject>
#include <QPoint>
#include <QWidget>
class DraggableWidgetMaker : public QObject
{
Q_OBJECT
public:
DraggableWidgetMaker(QObject* parent = nullptr);
void makeDraggable(QWidget* widget);
protected:
bool eventFilter(QObject* obj, QEvent* event) override;
private:
bool m_isPressing = false;
bool m_isDragging = false;
QPoint m_mouseMovePos;
QPoint m_mousePressPos;
};

View File

@@ -0,0 +1,83 @@
// Copyright(c) 2017-2019 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/>.
// Based on https://stackoverflow.com/a/53135675/964478
#include "orientablepushbutton.h"
#include <QDebug>
#include <QPainter>
#include <QStyleOptionButton>
#include <QStylePainter>
OrientablePushButton::OrientablePushButton(QWidget* parent)
: CaptureButton(parent)
{}
OrientablePushButton::OrientablePushButton(const QString& text, QWidget* parent)
: CaptureButton(text, parent)
{}
OrientablePushButton::OrientablePushButton(const QIcon& icon,
const QString& text,
QWidget* parent)
: CaptureButton(icon, text, parent)
{}
QSize OrientablePushButton::sizeHint() const
{
QSize sh = QPushButton::sizeHint();
if (m_orientation != OrientablePushButton::Horizontal) {
sh.transpose();
}
return sh;
}
void OrientablePushButton::paintEvent(QPaintEvent* event)
{
Q_UNUSED(event)
QStylePainter painter(this);
QStyleOptionButton option;
initStyleOption(&option);
if (m_orientation == OrientablePushButton::VerticalTopToBottom) {
painter.rotate(90);
painter.translate(0, -1 * width());
option.rect = option.rect.transposed();
}
else if (m_orientation == OrientablePushButton::VerticalBottomToTop) {
painter.rotate(-90);
painter.translate(-1 * height(), 0);
option.rect = option.rect.transposed();
}
painter.drawControl(QStyle::CE_PushButton, option);
}
OrientablePushButton::Orientation OrientablePushButton::orientation() const
{
return m_orientation;
}
void OrientablePushButton::setOrientation(
const OrientablePushButton::Orientation& orientation)
{
m_orientation = orientation;
}

View File

@@ -0,0 +1,52 @@
// Copyright(c) 2017-2019 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/>.
// Based on https://stackoverflow.com/a/53135675/964478
#pragma once
#include "capture/capturebutton.h"
#include <QPushButton>
class OrientablePushButton : public CaptureButton
{
Q_OBJECT
public:
enum Orientation
{
Horizontal,
VerticalTopToBottom,
VerticalBottomToTop
};
OrientablePushButton(QWidget* parent = nullptr);
OrientablePushButton(const QString& text, QWidget* parent = nullptr);
OrientablePushButton(const QIcon& icon,
const QString& text,
QWidget* parent = nullptr);
QSize sizeHint() const;
OrientablePushButton::Orientation orientation() const;
void setOrientation(const OrientablePushButton::Orientation& orientation);
protected:
void paintEvent(QPaintEvent* event);
private:
Orientation m_orientation = Horizontal;
};

View File

@@ -0,0 +1,4 @@
# Required to generate MOC
target_sources(flameshot PRIVATE sidepanelwidget.h utilitypanel.h)
target_sources(flameshot PRIVATE sidepanelwidget.cpp utilitypanel.cpp)

View File

@@ -82,7 +82,7 @@ SidePanelWidget::SidePanelWidget(QPixmap* p, QWidget* parent)
this,
&SidePanelWidget::updateThickness);
QColor background = this->palette().background().color();
QColor background = this->palette().window().color();
bool isDark = ColorUtils::colorIsDark(background);
QString modifier =
isDark ? PathInfo::whiteIconPath() : PathInfo::blackIconPath();

View File

@@ -56,6 +56,8 @@ void UtilityPanel::addToolWidget(QWidget* w)
}
if (w) {
m_toolWidget = w;
m_toolWidget->setSizePolicy(QSizePolicy::Ignored,
QSizePolicy::Preferred);
m_upLayout->addWidget(w);
}
}
@@ -69,7 +71,7 @@ void UtilityPanel::clearToolWidget()
void UtilityPanel::pushWidget(QWidget* w)
{
m_layout->addWidget(w);
m_layout->insertWidget(m_layout->count() - 1, w);
}
void UtilityPanel::show()
@@ -111,10 +113,17 @@ void UtilityPanel::initInternalPanel()
m_layout = new QVBoxLayout();
m_upLayout = new QVBoxLayout();
m_bottomLayout = new QVBoxLayout();
m_layout->addLayout(m_upLayout);
m_layout->addLayout(m_bottomLayout);
widget->setLayout(m_layout);
QColor bgColor = palette().background().color();
QPushButton* closeButton = new QPushButton(this);
closeButton->setText(tr("Close"));
connect(closeButton, &QPushButton::clicked, this, &UtilityPanel::toggle);
m_bottomLayout->addWidget(closeButton);
QColor bgColor = palette().window().color();
bgColor.setAlphaF(0.0);
m_internalPanel->setStyleSheet(
QStringLiteral("QScrollArea {background-color: %1}").arg(bgColor.name()));

View File

@@ -52,6 +52,7 @@ private:
QPointer<QWidget> m_toolWidget;
QScrollArea* m_internalPanel;
QVBoxLayout* m_upLayout;
QVBoxLayout* m_bottomLayout;
QVBoxLayout* m_layout;
QPropertyAnimation* m_showAnimation;
QPropertyAnimation* m_hideAnimation;