Code refactoring - change code style to the new clang-format rules

This commit is contained in:
Yuriy Puchkov
2020-09-23 15:24:16 +03:00
parent 5a62cd3b13
commit b88a5fbce8
175 changed files with 6200 additions and 5356 deletions

View File

@@ -17,43 +17,45 @@
#include "buttonhandler.h"
#include "src/utils/globalvalues.h"
#include <QPoint>
#include <QGuiApplication>
#include <QPoint>
#include <QScreen>
// 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) :
QObject(parent)
ButtonHandler::ButtonHandler(const QVector<CaptureButton*>& v, QObject* parent)
: QObject(parent)
{
setButtons(v);
init();
}
ButtonHandler::ButtonHandler(QObject *parent) :
QObject(parent)
ButtonHandler::ButtonHandler(QObject* parent)
: QObject(parent)
{
init();
}
void ButtonHandler::hide() {
for (CaptureButton *b: m_vectorButtons)
void ButtonHandler::hide()
{
for (CaptureButton* b : m_vectorButtons)
b->hide();
}
void ButtonHandler::show() {
void ButtonHandler::show()
{
if (m_vectorButtons.isEmpty() || m_vectorButtons.first()->isVisible()) {
return;
}
for (CaptureButton *b: m_vectorButtons)
for (CaptureButton* b : m_vectorButtons)
b->animatedShow();
}
bool ButtonHandler::isVisible() const {
bool ButtonHandler::isVisible() const
{
bool ret = true;
for (const CaptureButton *b: m_vectorButtons) {
for (const CaptureButton* b : m_vectorButtons) {
if (!b->isVisible()) {
ret = false;
break;
@@ -62,11 +64,13 @@ bool ButtonHandler::isVisible() const {
return ret;
}
bool ButtonHandler::buttonsAreInside() const {
bool ButtonHandler::buttonsAreInside() const
{
return m_buttonsAreInside;
}
size_t ButtonHandler::size() const {
size_t ButtonHandler::size() const
{
return m_vectorButtons.size();
}
@@ -74,7 +78,8 @@ size_t ButtonHandler::size() const {
// selection area. Ignores the sides blocked by the end of the screen.
// When the selection is too small it works on a virtual selection with
// the original in the center.
void ButtonHandler::updatePosition(const QRect &selection) {
void ButtonHandler::updatePosition(const QRect& selection)
{
resetRegionTrack();
const int vecLength = m_vectorButtons.size();
if (vecLength == 0) {
@@ -96,11 +101,13 @@ void ButtonHandler::updatePosition(const QRect &selection) {
break; // the while
}
// Number of buttons per row column
int buttonsPerRow = (m_selection.width() + m_separator) / (m_buttonExtendedSize);
int buttonsPerCol = (m_selection.height() + m_separator) / (m_buttonExtendedSize);
int buttonsPerRow =
(m_selection.width() + m_separator) / (m_buttonExtendedSize);
int buttonsPerCol =
(m_selection.height() + m_separator) / (m_buttonExtendedSize);
// Buttons to be placed in the corners
int extraButtons = (vecLength - elemIndicator) -
(buttonsPerRow + buttonsPerCol) * 2;
int extraButtons =
(vecLength - elemIndicator) - (buttonsPerRow + buttonsPerCol) * 2;
int elemsAtCorners = extraButtons > 4 ? 4 : extraButtons;
int maxExtra = 2;
if (m_oneHorizontalBlocked) {
@@ -123,7 +130,8 @@ void ButtonHandler::updatePosition(const QRect &selection) {
adjustHorizontalCenter(center);
}
// ElemIndicator, elemsAtCorners
QVector<QPoint> positions = horizontalPoints(center, addCounter, true);
QVector<QPoint> positions =
horizontalPoints(center, addCounter, true);
moveButtonsToPoints(positions, elemIndicator);
}
// Add buttons at the right side of the seletion
@@ -133,7 +141,8 @@ void ButtonHandler::updatePosition(const QRect &selection) {
QPoint center = QPoint(m_selection.right() + m_separator,
m_selection.center().y());
QVector<QPoint> positions = verticalPoints(center, addCounter, false);
QVector<QPoint> positions =
verticalPoints(center, addCounter, false);
moveButtonsToPoints(positions, elemIndicator);
}
// Add buttons at the top of the seletion
@@ -145,7 +154,8 @@ void ButtonHandler::updatePosition(const QRect &selection) {
if (addCounter == 1 + buttonsPerRow) {
adjustHorizontalCenter(center);
}
QVector<QPoint> positions = horizontalPoints(center, addCounter, false);
QVector<QPoint> positions =
horizontalPoints(center, addCounter, false);
moveButtonsToPoints(positions, elemIndicator);
}
// Add buttons at the left side of the seletion
@@ -155,7 +165,8 @@ void ButtonHandler::updatePosition(const QRect &selection) {
QPoint center = QPoint(m_selection.left() - m_buttonExtendedSize,
m_selection.center().y());
QVector<QPoint> positions = verticalPoints(center, addCounter, true);
QVector<QPoint> positions =
verticalPoints(center, addCounter, true);
moveButtonsToPoints(positions, elemIndicator);
}
// If there are elements for the next cycle, increase the size of the
@@ -170,8 +181,9 @@ void ButtonHandler::updatePosition(const QRect &selection) {
// horizontalPoints is an auxiliary method for the button position computation.
// starts from a known center and keeps adding elements horizontally
// and returns the computed positions.
QVector<QPoint> ButtonHandler::horizontalPoints(
const QPoint &center, const int elements, const bool leftToRight) const
QVector<QPoint> ButtonHandler::horizontalPoints(const QPoint& center,
const int elements,
const bool leftToRight) const
{
QVector<QPoint> res;
// Distance from the center to start adding buttons
@@ -179,16 +191,18 @@ QVector<QPoint> ButtonHandler::horizontalPoints(
if (elements % 2 == 0) {
shift = m_buttonExtendedSize * (elements / 2) - (m_separator / 2);
} else {
shift = m_buttonExtendedSize * ((elements-1) / 2) + m_buttonBaseSize / 2;
shift =
m_buttonExtendedSize * ((elements - 1) / 2) + m_buttonBaseSize / 2;
}
if (!leftToRight) { shift -= m_buttonBaseSize; }
int x = leftToRight ? center.x() - shift :
center.x() + shift;
if (!leftToRight) {
shift -= m_buttonBaseSize;
}
int x = leftToRight ? center.x() - shift : center.x() + shift;
QPoint i(x, center.y());
while (elements > res.length()) {
res.append(i);
leftToRight ? i.setX(i.x() + m_buttonExtendedSize) :
i.setX(i.x() - m_buttonExtendedSize);
leftToRight ? i.setX(i.x() + m_buttonExtendedSize)
: i.setX(i.x() - m_buttonExtendedSize);
}
return res;
}
@@ -196,8 +210,9 @@ QVector<QPoint> ButtonHandler::horizontalPoints(
// verticalPoints is an auxiliary method for the button position computation.
// starts from a known center and keeps adding elements vertically
// and returns the computed positions.
QVector<QPoint> ButtonHandler::verticalPoints(
const QPoint &center, const int elements, const bool upToDown) const
QVector<QPoint> ButtonHandler::verticalPoints(const QPoint& center,
const int elements,
const bool upToDown) const
{
QVector<QPoint> res;
// Distance from the center to start adding buttons
@@ -205,23 +220,26 @@ QVector<QPoint> ButtonHandler::verticalPoints(
if (elements % 2 == 0) {
shift = m_buttonExtendedSize * (elements / 2) - (m_separator / 2);
} else {
shift = m_buttonExtendedSize * ((elements-1) / 2) + m_buttonBaseSize / 2;
shift =
m_buttonExtendedSize * ((elements - 1) / 2) + m_buttonBaseSize / 2;
}
if (!upToDown) { shift -= m_buttonBaseSize; }
int y = upToDown ? center.y() - shift :
center.y() + shift;
if (!upToDown) {
shift -= m_buttonBaseSize;
}
int y = upToDown ? center.y() - shift : center.y() + shift;
QPoint i(center.x(), y);
while (elements > res.length()) {
res.append(i);
upToDown ? i.setY(i.y() + m_buttonExtendedSize) :
i.setY(i.y() - m_buttonExtendedSize);
upToDown ? i.setY(i.y() + m_buttonExtendedSize)
: i.setY(i.y() - m_buttonExtendedSize);
}
return res;
}
QRect ButtonHandler::intersectWithAreas(const QRect &rect) {
QRect ButtonHandler::intersectWithAreas(const QRect& rect)
{
QRect res;
for(const QRect &r : m_screenRegions.rects()) {
for (const QRect& r : m_screenRegions.rects()) {
QRect temp = rect.intersected(r);
if (temp.height() * temp.width() > res.height() * res.width()) {
res = temp;
@@ -230,54 +248,56 @@ QRect ButtonHandler::intersectWithAreas(const QRect &rect) {
return res;
}
void ButtonHandler::init() {
void ButtonHandler::init()
{
m_separator = GlobalValues::buttonBaseSize() / 4;
}
void ButtonHandler::resetRegionTrack() {
void ButtonHandler::resetRegionTrack()
{
m_buttonsAreInside = false;
}
void ButtonHandler::updateBlockedSides() {
void ButtonHandler::updateBlockedSides()
{
const int EXTENSION = m_separator * 2 + m_buttonBaseSize;
// Right
QPoint pointA(m_selection.right() + EXTENSION,
m_selection.bottom());
QPoint pointB(pointA.x(),
m_selection.top());
m_blockedRight = !(m_screenRegions.contains(pointA) &&
m_screenRegions.contains(pointB));
QPoint pointA(m_selection.right() + EXTENSION, m_selection.bottom());
QPoint pointB(pointA.x(), m_selection.top());
m_blockedRight =
!(m_screenRegions.contains(pointA) && m_screenRegions.contains(pointB));
// Left
pointA.setX(m_selection.left() - EXTENSION);
pointB.setX(pointA.x());
m_blockedLeft = !(m_screenRegions.contains(pointA) &&
m_screenRegions.contains(pointB));
m_blockedLeft =
!(m_screenRegions.contains(pointA) && m_screenRegions.contains(pointB));
// Bottom
pointA = QPoint(m_selection.left(),
m_selection.bottom() + EXTENSION);
pointB = QPoint(m_selection.right(),
pointA.y());
m_blockedBotton = !(m_screenRegions.contains(pointA) &&
m_screenRegions.contains(pointB));
pointA = QPoint(m_selection.left(), m_selection.bottom() + EXTENSION);
pointB = QPoint(m_selection.right(), pointA.y());
m_blockedBotton =
!(m_screenRegions.contains(pointA) && m_screenRegions.contains(pointB));
// Top
pointA.setY(m_selection.top() - EXTENSION);
pointB.setY(pointA.y());
m_blockedTop = !(m_screenRegions.contains(pointA) &&
m_screenRegions.contains(pointB));
m_blockedTop =
!(m_screenRegions.contains(pointA) && m_screenRegions.contains(pointB));
// Auxiliary
m_oneHorizontalBlocked = (!m_blockedRight && m_blockedLeft) ||
(m_blockedRight && !m_blockedLeft);
m_oneHorizontalBlocked =
(!m_blockedRight && m_blockedLeft) || (m_blockedRight && !m_blockedLeft);
m_horizontalyBlocked = (m_blockedRight && m_blockedLeft);
m_allSidesBlocked = (m_blockedBotton && m_horizontalyBlocked && m_blockedTop);
m_allSidesBlocked =
(m_blockedBotton && m_horizontalyBlocked && m_blockedTop);
}
void ButtonHandler::expandSelection() {
int &s = m_buttonExtendedSize;
void ButtonHandler::expandSelection()
{
int& s = m_buttonExtendedSize;
m_selection = m_selection + QMargins(s, s, s, s);
m_selection = intersectWithAreas(m_selection);
}
void ButtonHandler::positionButtonsInside(int index) {
void ButtonHandler::positionButtonsInside(int index)
{
// Position the buttons in the botton-center of the main but inside of the
// selection.
QRect mainArea = m_selection;
@@ -286,8 +306,8 @@ void ButtonHandler::positionButtonsInside(int index) {
if (buttonsPerRow == 0) {
return;
}
QPoint center = QPoint(mainArea.center().x(),
mainArea.bottom() - m_buttonExtendedSize);
QPoint center =
QPoint(mainArea.center().x(), mainArea.bottom() - m_buttonExtendedSize);
while (m_vectorButtons.size() > index) {
int addCounter = buttonsPerRow;
@@ -300,56 +320,61 @@ void ButtonHandler::positionButtonsInside(int index) {
m_buttonsAreInside = true;
}
void ButtonHandler::ensureSelectionMinimunSize() {
void ButtonHandler::ensureSelectionMinimunSize()
{
// Detect if a side is smaller than a button in order to prevent collision
// and redimension the base area the the base size of a single button per side
// and redimension the base area the the base size of a single button per
// side
if (m_selection.width() < m_buttonBaseSize) {
if (!m_blockedLeft) {
m_selection.setX(m_selection.x() -
(m_buttonBaseSize-m_selection.width()) / 2);
(m_buttonBaseSize - m_selection.width()) / 2);
}
m_selection.setWidth(m_buttonBaseSize);
}
if (m_selection.height() < m_buttonBaseSize) {
if (!m_blockedTop) {
m_selection.setY(m_selection.y() -
(m_buttonBaseSize-m_selection.height()) / 2);
(m_buttonBaseSize - m_selection.height()) / 2);
}
m_selection.setHeight(m_buttonBaseSize);
}
}
void ButtonHandler::moveButtonsToPoints(
const QVector<QPoint> &points, int &index)
void ButtonHandler::moveButtonsToPoints(const QVector<QPoint>& points,
int& index)
{
for (const QPoint &p: points) {
for (const QPoint& p : points) {
auto button = m_vectorButtons[index];
button->move(p);
++index;
}
}
void ButtonHandler::adjustHorizontalCenter(QPoint &center) {
void ButtonHandler::adjustHorizontalCenter(QPoint& center)
{
if (m_blockedLeft) {
center.setX(center.x() + m_buttonExtendedSize/2);
center.setX(center.x() + m_buttonExtendedSize / 2);
} else if (m_blockedRight) {
center.setX(center.x() - m_buttonExtendedSize/2);
center.setX(center.x() - m_buttonExtendedSize / 2);
}
}
// setButtons redefines the buttons of the button handler
void ButtonHandler::setButtons(const QVector<CaptureButton *> v) {
void ButtonHandler::setButtons(const QVector<CaptureButton*> v)
{
if (v.isEmpty())
return;
for (CaptureButton *b: m_vectorButtons)
delete(b);
for (CaptureButton* b : m_vectorButtons)
delete (b);
m_vectorButtons = v;
m_buttonBaseSize = GlobalValues::buttonBaseSize();
m_buttonExtendedSize = m_buttonBaseSize + m_separator;
}
bool ButtonHandler::contains(const QPoint &p) const {
bool ButtonHandler::contains(const QPoint& p) const
{
QPoint first(m_vectorButtons.first()->pos());
QPoint last(m_vectorButtons.last()->pos());
bool firstIsTopLeft = (first.x() <= last.x() && first.y() <= last.y());
@@ -361,13 +386,15 @@ bool ButtonHandler::contains(const QPoint &p) const {
return r.contains(p);
}
void ButtonHandler::updateScreenRegions(const QVector<QRect> &rects) {
void ButtonHandler::updateScreenRegions(const QVector<QRect>& rects)
{
m_screenRegions = QRegion();
for (const QRect &rect: rects) {
for (const QRect& rect : rects) {
m_screenRegions += rect;
}
}
void ButtonHandler::updateScreenRegions(const QRect &rect) {
void ButtonHandler::updateScreenRegions(const QRect& rect)
{
m_screenRegions = QRegion(rect);
}

View File

@@ -18,43 +18,46 @@
#pragma once
#include "capturebutton.h"
#include <QVector>
#include <QObject>
#include <QRegion>
#include <QVector>
class CaptureButton;
class QRect;
class QPoint;
class ButtonHandler : public QObject {
class ButtonHandler : public QObject
{
Q_OBJECT
public:
ButtonHandler(const QVector<CaptureButton*>&, QObject *parent = nullptr);
explicit ButtonHandler(QObject *parent = nullptr);
ButtonHandler(const QVector<CaptureButton*>&, QObject* parent = nullptr);
explicit ButtonHandler(QObject* parent = nullptr);
void hideSectionUnderMouse(const QPoint &p);
void hideSectionUnderMouse(const QPoint& p);
bool isVisible() const;
bool buttonsAreInside() const;
size_t size() const;
void setButtons(const QVector<CaptureButton*>);
bool contains(const QPoint &p) const;
void updateScreenRegions(const QVector<QRect> &rects);
void updateScreenRegions(const QRect &rect);
bool contains(const QPoint& p) const;
void updateScreenRegions(const QVector<QRect>& rects);
void updateScreenRegions(const QRect& rect);
public slots:
void updatePosition(const QRect &selection);
void updatePosition(const QRect& selection);
void hide();
void show();
private:
QVector<QPoint> horizontalPoints(const QPoint &center, const int elements,
const bool leftToRight) const;
QVector<QPoint> verticalPoints(const QPoint &center, const int elements,
const bool upToDown) const;
QVector<QPoint> horizontalPoints(const QPoint& center,
const int elements,
const bool leftToRight) const;
QVector<QPoint> verticalPoints(const QPoint& center,
const int elements,
const bool upToDown) const;
QRect intersectWithAreas(const QRect &rect);
QRect intersectWithAreas(const QRect& rect);
QVector<CaptureButton*> m_vectorButtons;
@@ -82,6 +85,6 @@ private:
void expandSelection();
void positionButtonsInside(int index);
void ensureSelectionMinimunSize();
void moveButtonsToPoints(const QVector<QPoint> &points, int &index);
void adjustHorizontalCenter(QPoint &center);
void moveButtonsToPoints(const QVector<QPoint>& points, int& index);
void adjustHorizontalCenter(QPoint& center);
};

View File

@@ -16,24 +16,25 @@
// along with Flameshot. If not, see <http://www.gnu.org/licenses/>.
#include "capturebutton.h"
#include "src/widgets/capture/capturewidget.h"
#include "src/utils/confighandler.h"
#include "src/tools/capturetool.h"
#include "src/tools/toolfactory.h"
#include "src/utils/globalvalues.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>
#include <QMouseEvent>
#include <QGraphicsDropShadowEffect>
#include <QApplication>
// Button represents a single button of the capture widget, it can enable
// multiple functionality.
CaptureButton::CaptureButton(const ButtonType t, QWidget *parent) : QPushButton(parent),
m_buttonType(t)
CaptureButton::CaptureButton(const ButtonType t, QWidget* parent)
: QPushButton(parent)
, m_buttonType(t)
{
initButton();
if (t == TYPE_SELECTIONINDICATOR) {
@@ -45,23 +46,26 @@ CaptureButton::CaptureButton(const ButtonType t, QWidget *parent) : QPushButton(
setCursor(Qt::ArrowCursor);
}
void CaptureButton::initButton() {
void CaptureButton::initButton()
{
m_tool = ToolFactory().CreateTool(m_buttonType, this);
setFocusPolicy(Qt::NoFocus);
resize(GlobalValues::buttonBaseSize(), GlobalValues::buttonBaseSize());
setMask(QRegion(QRect(-1,-1, GlobalValues::buttonBaseSize()+2,
GlobalValues::buttonBaseSize()+2),
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 = 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()));
QSize(GlobalValues::buttonBaseSize(), GlobalValues::buttonBaseSize()));
auto dsEffect = new QGraphicsDropShadowEffect(this);
dsEffect->setBlurRadius(5);
@@ -69,19 +73,21 @@ void CaptureButton::initButton() {
dsEffect->setColor(QColor(Qt::black));
setGraphicsEffect(dsEffect);
}
void CaptureButton::updateIcon() {
void CaptureButton::updateIcon()
{
setIcon(icon());
setIconSize(size()*0.6);
setIconSize(size() * 0.6);
}
QVector<CaptureButton::ButtonType> CaptureButton::getIterableButtonTypes() {
QVector<CaptureButton::ButtonType> CaptureButton::getIterableButtonTypes()
{
return iterableButtonTypes;
}
QString CaptureButton::globalStyleSheet() {
QString CaptureButton::globalStyleSheet()
{
QColor mainColor = ConfigHandler().uiMainColorValue();
QString baseSheet = "CaptureButton { border-radius: %3;"
"background-color: %1; color: %4 }"
@@ -94,11 +100,14 @@ QString CaptureButton::globalStyleSheet() {
// foreground color
QString color = ColorUtils::colorIsDark(mainColor) ? "white" : "black";
return baseSheet.arg(mainColor.name()).arg(contrast.name())
.arg(GlobalValues::buttonBaseSize()/2).arg(color);
return baseSheet.arg(mainColor.name())
.arg(contrast.name())
.arg(GlobalValues::buttonBaseSize() / 2)
.arg(color);
}
QString CaptureButton::styleSheet() const {
QString CaptureButton::styleSheet() const
{
QString baseSheet = "CaptureButton { border-radius: %3;"
"background-color: %1; color: %4 }"
"CaptureButton:hover { background-color: %2; }"
@@ -109,36 +118,43 @@ QString CaptureButton::styleSheet() const {
// foreground color
QString color = ColorUtils::colorIsDark(m_mainColor) ? "white" : "black";
return baseSheet.arg(m_mainColor.name()).arg(contrast.name())
.arg(GlobalValues::buttonBaseSize()/2).arg(color);
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 {
QIcon CaptureButton::icon() const
{
return m_tool->icon(m_mainColor, true);
}
void CaptureButton::mousePressEvent(QMouseEvent *e) {
void CaptureButton::mousePressEvent(QMouseEvent* e)
{
if (e->button() == Qt::LeftButton) {
emit pressedButton(this);
emit pressed();
}
}
void CaptureButton::animatedShow() {
if(!isVisible()) {
void CaptureButton::animatedShow()
{
if (!isVisible()) {
show();
m_emergeAnimation->start();
connect(m_emergeAnimation, &QPropertyAnimation::finished, this, [](){
});
connect(
m_emergeAnimation, &QPropertyAnimation::finished, this, []() {});
}
}
CaptureTool *CaptureButton::tool() const {
CaptureTool* CaptureButton::tool() const
{
return m_tool;
}
void CaptureButton::setColor(const QColor &c) {
void CaptureButton::setColor(const QColor& c)
{
m_mainColor = c;
setStyleSheet(styleSheet());
updateIcon();
@@ -146,51 +162,44 @@ void CaptureButton::setColor(const QColor &c) {
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 },
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 },
{ 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) {
int CaptureButton::getPriorityByButton(CaptureButton::ButtonType b)
{
auto it = buttonTypeOrder.find(b);
return it == buttonTypeOrder.cend() ? (int)buttonTypeOrder.size() : it->second;
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_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,21 +17,23 @@
#pragma once
#include <QPushButton>
#include <QMap>
#include <QPushButton>
#include <QVector>
class QWidget;
class QPropertyAnimation;
class CaptureTool;
class CaptureButton : public QPushButton {
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 {
enum ButtonType
{
TYPE_PENCIL = 0,
TYPE_DRAWER = 1,
TYPE_ARROW = 2,
@@ -60,7 +62,7 @@ public:
#endif
CaptureButton() = delete;
explicit CaptureButton(const ButtonType, QWidget *parent = nullptr);
explicit CaptureButton(const ButtonType, QWidget* parent = nullptr);
static QString globalStyleSheet();
static QVector<CaptureButton::ButtonType> getIterableButtonTypes();
@@ -72,23 +74,23 @@ public:
QString styleSheet() const;
CaptureTool* tool() const;
void setColor(const QColor &c);
void setColor(const QColor& c);
void animatedShow();
protected:
virtual void mousePressEvent(QMouseEvent *);
virtual void mousePressEvent(QMouseEvent*);
static QVector<ButtonType> iterableButtonTypes;
CaptureTool *m_tool;
CaptureTool* m_tool;
signals:
void pressedButton(CaptureButton *);
void pressedButton(CaptureButton*);
private:
CaptureButton(QWidget *parent = nullptr);
CaptureButton(QWidget* parent = nullptr);
ButtonType m_buttonType;
QPropertyAnimation *m_emergeAnimation;
QPropertyAnimation* m_emergeAnimation;
static QColor m_mainColor;

View File

@@ -15,24 +15,26 @@
// 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 Lightscreen areadialog.h, Copyright 2017 Christian Kaiser <info@ckaiser.com.ar>
// released under the GNU GPL2 <https://www.gnu.org/licenses/gpl-2.0.txt>
// Based on Lightscreen areadialog.h, Copyright 2017 Christian Kaiser
// <info@ckaiser.com.ar> released under the GNU GPL2
// <https://www.gnu.org/licenses/gpl-2.0.txt>
// Based on KDE's KSnapshot regiongrabber.cpp, revision 796531, Copyright 2007 Luca Gugelmann <lucag@student.ethz.ch>
// released under the GNU LGPL <http://www.gnu.org/licenses/old-licenses/library.txt>
// Based on KDE's KSnapshot regiongrabber.cpp, revision 796531, Copyright 2007
// Luca Gugelmann <lucag@student.ethz.ch> released under the GNU LGPL
// <http://www.gnu.org/licenses/old-licenses/library.txt>
#pragma once
#include "buttonhandler.h"
#include "capturebutton.h"
#include "src/tools/capturecontext.h"
#include "src/tools/capturetool.h"
#include "src/utils/confighandler.h"
#include "src/widgets/capture/selectionwidget.h"
#include "src/widgets/panel/utilitypanel.h"
#include "buttonhandler.h"
#include <QWidget>
#include <QUndoStack>
#include <QPointer>
#include <QUndoStack>
#include <QWidget>
class QPaintEvent;
class QResizeEvent;
@@ -45,18 +47,17 @@ class Screenshot;
class NotifierBox;
class HoverEventFilter;
class CaptureWidget : public QWidget {
class CaptureWidget : public QWidget
{
Q_OBJECT
public:
explicit CaptureWidget(const uint id = 0,
const QString &savePath = QString(),
const QString& savePath = QString(),
bool fullScreen = true,
QWidget *parent = nullptr);
QWidget* parent = nullptr);
~CaptureWidget();
void updateButtons();
QPixmap pixmap();
@@ -66,7 +67,7 @@ public slots:
signals:
void captureTaken(uint id, QPixmap p);
void captureFailed(uint id);
void colorChanged(const QColor &c);
void colorChanged(const QColor& c);
void thicknessChanged(const int thickness);
private slots:
@@ -91,22 +92,22 @@ private slots:
void upMove();
void downMove();
void setState(CaptureButton *b);
void processTool(CaptureTool *t);
void setState(CaptureButton* 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);
protected:
void paintEvent(QPaintEvent *);
void mousePressEvent(QMouseEvent *);
void mouseMoveEvent(QMouseEvent *);
void mouseReleaseEvent(QMouseEvent *);
void keyPressEvent(QKeyEvent *);
void keyReleaseEvent(QKeyEvent *);
void wheelEvent(QWheelEvent *);
void resizeEvent(QResizeEvent *);
void moveEvent(QMoveEvent *);
void paintEvent(QPaintEvent*);
void mousePressEvent(QMouseEvent*);
void mouseMoveEvent(QMouseEvent*);
void mouseReleaseEvent(QMouseEvent*);
void keyPressEvent(QKeyEvent*);
void keyReleaseEvent(QKeyEvent*);
void wheelEvent(QWheelEvent*);
void resizeEvent(QResizeEvent*);
void moveEvent(QMoveEvent*);
// Context information
CaptureContext m_context;
@@ -129,18 +130,18 @@ protected:
bool m_adjustmentButtonPressed;
private:
void initContext(const QString &savePath, bool fullscreen);
void initContext(const QString& savePath, bool fullscreen);
void initPanel();
void initSelection();
void initShortcuts();
void updateSizeIndicator();
void updateCursor();
void pushToolToStack();
void makeChild(QWidget *w);
void makeChild(QWidget* w);
private:
QRect extendedSelection() const;
QRect extendedRect(QRect *r) const;
QRect extendedRect(QRect* r) const;
private:
QUndoStack m_undoStack;
@@ -150,13 +151,13 @@ private:
QPointer<CaptureTool> m_activeTool;
QPointer<QWidget> m_toolWidget;
ButtonHandler *m_buttonHandler;
UtilityPanel *m_panel;
ColorPicker *m_colorPicker;
ButtonHandler* m_buttonHandler;
UtilityPanel* m_panel;
ColorPicker* m_colorPicker;
ConfigHandler m_config;
NotifierBox *m_notifierBox;
HoverEventFilter *m_eventFilter;
SelectionWidget *m_selection;
NotifierBox* m_notifierBox;
HoverEventFilter* m_eventFilter;
SelectionWidget* m_selection;
QPoint m_dragStartPoint;
SelectionWidget::SideType m_mouseOverHandle;

View File

@@ -18,10 +18,12 @@
#include "colorpicker.h"
#include "src/utils/confighandler.h"
#include "src/utils/globalvalues.h"
#include <QPainter>
#include <QMouseEvent>
#include <QPainter>
ColorPicker::ColorPicker(QWidget *parent) : QWidget(parent) {
ColorPicker::ColorPicker(QWidget* parent)
: QWidget(parent)
{
ConfigHandler config;
m_colorList = config.getUserColors();
m_colorAreaSize = GlobalValues::buttonBaseSize() * 0.6;
@@ -39,32 +41,37 @@ ColorPicker::ColorPicker(QWidget *parent) : QWidget(parent) {
double degreeAcum = degree;
// this line is the radius of the circle which will be rotated to add
// the color components.
QLineF baseLine = QLineF(QPoint(radius + extraSize / 2, radius+extraSize / 2),
QPoint(radius * 2, radius));
QLineF baseLine =
QLineF(QPoint(radius + extraSize / 2, radius + extraSize / 2),
QPoint(radius * 2, radius));
for (int i = 0; i < m_colorList.size(); ++i) {
m_colorAreaList.append(QRect(baseLine.x2(), baseLine.y2(),
m_colorAreaSize, m_colorAreaSize));
m_colorAreaList.append(QRect(
baseLine.x2(), baseLine.y2(), m_colorAreaSize, m_colorAreaSize));
baseLine.setAngle(degreeAcum);
degreeAcum += degree;
}
}
QColor ColorPicker::drawColor() {
QColor ColorPicker::drawColor()
{
return m_drawColor;
}
void ColorPicker::show() {
void ColorPicker::show()
{
grabMouse();
QWidget::show();
}
void ColorPicker::hide() {
void ColorPicker::hide()
{
releaseMouse();
QWidget::hide();
}
void ColorPicker::paintEvent(QPaintEvent *) {
void ColorPicker::paintEvent(QPaintEvent*)
{
QPainter painter(this);
painter.setRenderHint(QPainter::Antialiasing);
@@ -91,15 +98,15 @@ void ColorPicker::paintEvent(QPaintEvent *) {
// draw preset color
painter.setBrush(QColor(m_colorList.at(i)));
painter.drawRoundRect(rects.at(i), 100, 100);
}
else {
} else {
// draw rainbow (part) for custom color
QRect lastRect = rects.at(i);
int nStep = 1;
int nSteps = lastRect.height() / nStep;
// 0.02 - start rainbow color, 0.33 - end rainbow color from range: 0.0 - 1.0
// 0.02 - start rainbow color, 0.33 - end rainbow color from range:
// 0.0 - 1.0
float h = 0.02;
for (int radius = nSteps; radius > 0; radius -= nStep*2) {
for (int radius = nSteps; radius > 0; radius -= nStep * 2) {
// calculate color
float fHStep = (0.33 - h) / (nSteps / nStep / 2);
QColor color = QColor::fromHslF(h, 0.95, 0.5);
@@ -120,7 +127,8 @@ void ColorPicker::paintEvent(QPaintEvent *) {
}
}
void ColorPicker::mouseMoveEvent(QMouseEvent *e) {
void ColorPicker::mouseMoveEvent(QMouseEvent* e)
{
for (int i = 0; i < m_colorList.size(); ++i) {
if (m_colorAreaList.at(i).contains(e->pos())) {
m_drawColor = m_colorList.at(i);
@@ -131,9 +139,10 @@ void ColorPicker::mouseMoveEvent(QMouseEvent *e) {
}
}
QVector<QRect> ColorPicker::handleMask() const {
QVector<QRect> ColorPicker::handleMask() const
{
QVector<QRect> areas;
for (const QRect &rect: m_colorAreaList) {
for (const QRect& rect : m_colorAreaList) {
areas.append(rect);
}
return areas;

View File

@@ -19,10 +19,11 @@
#include <QWidget>
class ColorPicker : public QWidget {
class ColorPicker : public QWidget
{
Q_OBJECT
public:
explicit ColorPicker(QWidget *parent = nullptr);
explicit ColorPicker(QWidget* parent = nullptr);
QColor drawColor();
@@ -33,8 +34,8 @@ signals:
void colorSelected(QColor c);
protected:
void paintEvent(QPaintEvent *);
void mouseMoveEvent(QMouseEvent *);
void paintEvent(QPaintEvent*);
void mouseMoveEvent(QMouseEvent*);
QVector<QRect> handleMask() const;

View File

@@ -15,30 +15,33 @@
// 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 Lightscreen areadialog.h, Copyright 2017 Christian Kaiser <info@ckaiser.com.ar>
// released under the GNU GPL2 <https://www.gnu.org/licenses/gpl-2.0.txt>
// Based on Lightscreen areadialog.h, Copyright 2017 Christian Kaiser
// <info@ckaiser.com.ar> released under the GNU GPL2
// <https://www.gnu.org/licenses/gpl-2.0.txt>
// Based on KDE's KSnapshot regiongrabber.cpp, revision 796531, Copyright 2007 Luca Gugelmann <lucag@student.ethz.ch>
// released under the GNU LGPL <http://www.gnu.org/licenses/old-licenses/library.txt>
// Based on KDE's KSnapshot regiongrabber.cpp, revision 796531, Copyright 2007
// Luca Gugelmann <lucag@student.ethz.ch> released under the GNU LGPL
// <http://www.gnu.org/licenses/old-licenses/library.txt>
#include "hovereventfilter.h"
#include <QEvent>
HoverEventFilter::HoverEventFilter(QObject *parent) : QObject(parent) {
HoverEventFilter::HoverEventFilter(QObject* parent)
: QObject(parent)
{}
}
bool HoverEventFilter::eventFilter(QObject *watched, QEvent *event) {
bool HoverEventFilter::eventFilter(QObject* watched, QEvent* event)
{
QEvent::Type t = event->type();
switch (t) {
case QEvent::Enter:
emit hoverIn(watched);
break;
case QEvent::Leave:
emit hoverOut(watched);
break;
default:
break;
case QEvent::Enter:
emit hoverIn(watched);
break;
case QEvent::Leave:
emit hoverOut(watched);
break;
default:
break;
}
return false;
}

View File

@@ -15,11 +15,13 @@
// 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 Lightscreen areadialog.h, Copyright 2017 Christian Kaiser <info@ckaiser.com.ar>
// released under the GNU GPL2 <https://www.gnu.org/licenses/gpl-2.0.txt>
// Based on Lightscreen areadialog.h, Copyright 2017 Christian Kaiser
// <info@ckaiser.com.ar> released under the GNU GPL2
// <https://www.gnu.org/licenses/gpl-2.0.txt>
// Based on KDE's KSnapshot regiongrabber.cpp, revision 796531, Copyright 2007 Luca Gugelmann <lucag@student.ethz.ch>
// released under the GNU LGPL <http://www.gnu.org/licenses/old-licenses/library.txt>
// Based on KDE's KSnapshot regiongrabber.cpp, revision 796531, Copyright 2007
// Luca Gugelmann <lucag@student.ethz.ch> released under the GNU LGPL
// <http://www.gnu.org/licenses/old-licenses/library.txt>
#pragma once
@@ -29,12 +31,12 @@ class HoverEventFilter : public QObject
{
Q_OBJECT
public:
explicit HoverEventFilter(QObject *parent = nullptr);
explicit HoverEventFilter(QObject* parent = nullptr);
signals:
void hoverIn(QObject *);
void hoverOut(QObject *);
void hoverIn(QObject*);
void hoverOut(QObject*);
protected:
bool eventFilter(QObject *watched, QEvent *event);
bool eventFilter(QObject* watched, QEvent* event);
};

View File

@@ -18,17 +18,20 @@
#include "modificationcommand.h"
#include <QPainter>
ModificationCommand::ModificationCommand(QPixmap *p, CaptureTool *t) :
m_pixmap(p), m_tool(t)
ModificationCommand::ModificationCommand(QPixmap* p, CaptureTool* t)
: m_pixmap(p)
, m_tool(t)
{
setText(t->name());
}
void ModificationCommand::undo() {
void ModificationCommand::undo()
{
m_tool->undo(*m_pixmap);
}
void ModificationCommand::redo() {
void ModificationCommand::redo()
{
QPainter p(m_pixmap);
p.setRenderHint(QPainter::Antialiasing);
m_tool->process(p, *m_pixmap, true);

View File

@@ -17,17 +17,18 @@
#pragma once
#include <QUndoCommand>
#include "src/tools/capturetool.h"
#include <QUndoCommand>
class ModificationCommand : public QUndoCommand {
class ModificationCommand : public QUndoCommand
{
public:
ModificationCommand(QPixmap *, CaptureTool *);
ModificationCommand(QPixmap*, CaptureTool*);
virtual void undo() override;
virtual void redo() override;
private:
QPixmap *m_pixmap;
QPixmap* m_pixmap;
QScopedPointer<CaptureTool> m_tool;
};

View File

@@ -16,33 +16,37 @@
// along with Flameshot. If not, see <http://www.gnu.org/licenses/>.
#include "notifierbox.h"
#include "src/utils/confighandler.h"
#include "src/utils/colorutils.h"
#include "src/utils/confighandler.h"
#include "src/utils/globalvalues.h"
#include <QTimer>
#include <QPainter>
#include <QApplication>
#include <QPainter>
#include <QTimer>
NotifierBox::NotifierBox(QWidget *parent) : QWidget(parent) {
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 = (ColorUtils::colorIsDark(m_bgColor) ?
Qt::white : Qt::black);
m_foregroundColor =
(ColorUtils::colorIsDark(m_bgColor) ? Qt::white : Qt::black);
m_bgColor.setAlpha(180);
const int size = (GlobalValues::buttonBaseSize() +
GlobalValues::buttonBaseSize()/2) *
qApp->devicePixelRatio();
const int size =
(GlobalValues::buttonBaseSize() + GlobalValues::buttonBaseSize() / 2) *
qApp->devicePixelRatio();
setFixedSize(QSize(size, size));
}
void NotifierBox::enterEvent(QEvent *) {
void NotifierBox::enterEvent(QEvent*)
{
hide();
}
void NotifierBox::paintEvent(QPaintEvent *) {
void NotifierBox::paintEvent(QPaintEvent*)
{
QPainter painter(this);
// draw Elipse
painter.setRenderHint(QPainter::Antialiasing);
@@ -54,14 +58,16 @@ void NotifierBox::paintEvent(QPaintEvent *) {
painter.drawText(rect(), Qt::AlignCenter, m_message);
}
void NotifierBox::showMessage(const QString &msg) {
void NotifierBox::showMessage(const QString& msg)
{
m_message = msg;
update();
show();
m_timer->start();
}
void NotifierBox::showColor(const QColor &color) {
void NotifierBox::showColor(const QColor& color)
{
Q_UNUSED(color);
m_message = QLatin1String("");
}

View File

@@ -21,21 +21,22 @@
class QTimer;
class NotifierBox : public QWidget {
class NotifierBox : public QWidget
{
Q_OBJECT
public:
explicit NotifierBox(QWidget *parent = nullptr);
explicit NotifierBox(QWidget* parent = nullptr);
protected:
virtual void enterEvent(QEvent *);
virtual void paintEvent(QPaintEvent *);
virtual void enterEvent(QEvent*);
virtual void paintEvent(QPaintEvent*);
public slots:
void showMessage(const QString &msg);
void showColor(const QColor &color);
void showMessage(const QString& msg);
void showColor(const QColor& color);
private:
QTimer *m_timer;
QTimer* m_timer;
QString m_message;
QColor m_bgColor;
QColor m_foregroundColor;

View File

@@ -20,29 +20,34 @@
#include <QPainter>
#include <QPropertyAnimation>
SelectionWidget::SelectionWidget(const QColor &c, QWidget *parent) :
QWidget(parent), m_color(c)
SelectionWidget::SelectionWidget(const QColor& c, QWidget* parent)
: QWidget(parent)
, m_color(c)
{
m_animation = new QPropertyAnimation(this, "geometry", this);
m_animation->setEasingCurve(QEasingCurve::InOutQuad);
m_animation->setDuration(200);
connect(m_animation, &QPropertyAnimation::finished,
this, &SelectionWidget::animationEnded);
connect(m_animation,
&QPropertyAnimation::finished,
this,
&SelectionWidget::animationEnded);
setAttribute(Qt::WA_TransparentForMouseEvents);
int sideVal = GlobalValues::buttonBaseSize() * 0.6;
int handleSide = sideVal / 2;
const QRect areaRect(0, 0, sideVal, sideVal);
const QRect handleRect(0, 0, handleSide, handleSide);
m_TLHandle = m_TRHandle = m_BLHandle = m_BRHandle =
m_LHandle = m_THandle = m_RHandle = m_BHandle= handleRect;
m_TLHandle = m_TRHandle = m_BLHandle = m_BRHandle = m_LHandle = m_THandle =
m_RHandle = m_BHandle = handleRect;
m_TLArea = m_TRArea = m_BLArea = m_BRArea = areaRect;
m_areaOffset = QPoint(-sideVal/2, -sideVal/2);
m_handleOffset = QPoint(-handleSide/2, -handleSide/2);
m_areaOffset = QPoint(-sideVal / 2, -sideVal / 2);
m_handleOffset = QPoint(-handleSide / 2, -handleSide / 2);
}
SelectionWidget::SideType SelectionWidget::getMouseSide(const QPoint &point) const {
SelectionWidget::SideType SelectionWidget::getMouseSide(
const QPoint& point) const
{
if (m_TLArea.contains(point)) {
return TOPLEFT_SIDE;
} else if (m_TRArea.contains(point)) {
@@ -58,20 +63,22 @@ SelectionWidget::SideType SelectionWidget::getMouseSide(const QPoint &point) con
} else if (m_RArea.contains(point)) {
return RIGHT_SIDE;
} else if (m_BArea.contains(point)) {
return BOTTON_SIDE;
return BOTTON_SIDE;
} else {
return NO_SIDE;
}
}
QVector<QRect> SelectionWidget::handlerAreas() {
QVector<QRect> SelectionWidget::handlerAreas()
{
QVector<QRect> areas;
areas << m_TLHandle << m_TRHandle << m_BLHandle << m_BRHandle
<<m_LHandle << m_THandle << m_RHandle << m_BHandle;
areas << m_TLHandle << m_TRHandle << m_BLHandle << m_BRHandle << m_LHandle
<< m_THandle << m_RHandle << m_BHandle;
return areas;
}
void SelectionWidget::setGeometryAnimated(const QRect &r) {
void SelectionWidget::setGeometryAnimated(const QRect& r)
{
if (isVisible()) {
m_animation->setStartValue(geometry());
m_animation->setEndValue(r);
@@ -79,33 +86,40 @@ void SelectionWidget::setGeometryAnimated(const QRect &r) {
}
}
void SelectionWidget::saveGeometry() {
void SelectionWidget::saveGeometry()
{
m_geometryBackup = geometry();
}
QRect SelectionWidget::savedGeometry() {
QRect SelectionWidget::savedGeometry()
{
return m_geometryBackup;
}
void SelectionWidget::paintEvent(QPaintEvent *) {
void SelectionWidget::paintEvent(QPaintEvent*)
{
QPainter p(this);
p.setPen(m_color);
p.drawRect(rect() + QMargins(0, 0, -1, -1));
}
void SelectionWidget::resizeEvent(QResizeEvent *) {
void SelectionWidget::resizeEvent(QResizeEvent*)
{
updateAreas();
}
void SelectionWidget::moveEvent(QMoveEvent *) {
void SelectionWidget::moveEvent(QMoveEvent*)
{
updateAreas();
}
void SelectionWidget::updateColor(const QColor &c) {
void SelectionWidget::updateColor(const QColor& c)
{
m_color = c;
}
void SelectionWidget::updateAreas() {
void SelectionWidget::updateAreas()
{
QRect r = rect();
m_TLArea.moveTo(m_areaOffset + pos());
m_TRArea.moveTo(r.topRight() + m_areaOffset + pos());

View File

@@ -25,7 +25,8 @@ class SelectionWidget : public QWidget
{
Q_OBJECT
public:
enum SideType {
enum SideType
{
TOPLEFT_SIDE,
BOTTONLEFT_SIDE,
TOPRIGHT_SIDE,
@@ -37,30 +38,30 @@ public:
NO_SIDE,
};
explicit SelectionWidget(const QColor &c, QWidget *parent = nullptr);
explicit SelectionWidget(const QColor& c, QWidget* parent = nullptr);
SideType getMouseSide(const QPoint &point) const;
SideType getMouseSide(const QPoint& point) const;
QVector<QRect> handlerAreas();
void setGeometryAnimated(const QRect &r);
void setGeometryAnimated(const QRect& r);
void saveGeometry();
QRect savedGeometry();
protected:
void paintEvent(QPaintEvent *);
void resizeEvent(QResizeEvent *);
void moveEvent(QMoveEvent *);
void paintEvent(QPaintEvent*);
void resizeEvent(QResizeEvent*);
void moveEvent(QMoveEvent*);
signals:
void animationEnded();
public slots:
void updateColor(const QColor &c);
void updateColor(const QColor& c);
private:
void updateAreas();
QPropertyAnimation *m_animation;
QPropertyAnimation* m_animation;
QColor m_color;
QPoint m_areaOffset;

View File

@@ -17,43 +17,49 @@
#include "capturelauncher.h"
#include "src/core/controller.h"
#include "src/utils/screengrabber.h"
#include "src/widgets/imagelabel.h"
#include "src/widgets/notificationwidget.h"
#include "src/utils/screengrabber.h"
#include <QCheckBox>
#include <QPushButton>
#include <QGridLayout>
#include <QVBoxLayout>
#include <QSpinBox>
#include <QLabel>
#include <QComboBox>
#include <QMimeData>
#include <QDrag>
#include <QFormLayout>
#include <QGridLayout>
#include <QLabel>
#include <QMimeData>
#include <QPushButton>
#include <QSpinBox>
#include <QVBoxLayout>
// https://github.com/KDE/spectacle/blob/941c1a517be82bed25d1254ebd735c29b0d2951c/src/Gui/KSWidget.cpp
// https://github.com/KDE/spectacle/blob/941c1a517be82bed25d1254ebd735c29b0d2951c/src/Gui/KSMainWindow.cpp
CaptureLauncher::CaptureLauncher(QWidget *parent) :
QWidget(parent), m_id(0)
CaptureLauncher::CaptureLauncher(QWidget* parent)
: QWidget(parent)
, m_id(0)
{
setAttribute(Qt::WA_DeleteOnClose);
connect(Controller::getInstance(), &Controller::captureTaken,
this, &CaptureLauncher::captureTaken);
connect(Controller::getInstance(), &Controller::captureFailed,
this, &CaptureLauncher::captureFailed);
connect(Controller::getInstance(),
&Controller::captureTaken,
this,
&CaptureLauncher::captureTaken);
connect(Controller::getInstance(),
&Controller::captureFailed,
this,
&CaptureLauncher::captureFailed);
m_imageLabel = new ImageLabel(this);
bool ok;
m_imageLabel->setScreenshot(ScreenGrabber().grabEntireDesktop(ok));
if (!ok) {
}
m_imageLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
connect(m_imageLabel, &ImageLabel::dragInitiated,
this, &CaptureLauncher::startDrag);
connect(m_imageLabel,
&ImageLabel::dragInitiated,
this,
&CaptureLauncher::startDrag);
QGridLayout *layout = new QGridLayout(this);
QGridLayout* layout = new QGridLayout(this);
layout->addWidget(m_imageLabel, 0, 0);
m_CaptureModeLabel = new QLabel(tr("<b>Capture Mode</b>"));
@@ -61,9 +67,12 @@ CaptureLauncher::CaptureLauncher(QWidget *parent) :
m_captureType = new QComboBox();
m_captureType->setMinimumWidth(240);
// TODO remember number
m_captureType->insertItem(1, tr("Rectangular Region"), CaptureRequest::GRAPHICAL_MODE);
m_captureType->insertItem(2, tr("Full Screen (All Monitors)"), CaptureRequest::FULLSCREEN_MODE);
//m_captureType->insertItem(3, tr("Single Screen"), CaptureRequest::SCREEN_MODE);
m_captureType->insertItem(
1, tr("Rectangular Region"), CaptureRequest::GRAPHICAL_MODE);
m_captureType->insertItem(
2, tr("Full Screen (All Monitors)"), CaptureRequest::FULLSCREEN_MODE);
// m_captureType->insertItem(3, tr("Single Screen"),
// CaptureRequest::SCREEN_MODE);
m_delaySpinBox = new QSpinBox();
m_delaySpinBox->setSingleStep(1.0);
@@ -74,19 +83,21 @@ CaptureLauncher::CaptureLauncher(QWidget *parent) :
// with QT 5.7 qOverload<int>(&QSpinBox::valueChanged),
connect(m_delaySpinBox,
static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged),
this, [this](int val)
{
QString sufix = val == 1 ?tr(" second") : tr(" seconds");
this->m_delaySpinBox->setSuffix(sufix);
});
this,
[this](int val) {
QString sufix = val == 1 ? tr(" second") : tr(" seconds");
this->m_delaySpinBox->setSuffix(sufix);
});
m_launchButton = new QPushButton(tr("Take new screenshot"));
m_launchButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
connect(m_launchButton, &QPushButton::pressed,
this, &CaptureLauncher::startCapture);
connect(m_launchButton,
&QPushButton::pressed,
this,
&CaptureLauncher::startCapture);
m_launchButton->setFocus();
QFormLayout *captureModeForm = new QFormLayout;
QFormLayout* captureModeForm = new QFormLayout;
captureModeForm->addRow(tr("Area:"), m_captureType);
captureModeForm->addRow(tr("Delay:"), m_delaySpinBox);
captureModeForm->setContentsMargins(24, 0, 0, 0);
@@ -96,37 +107,39 @@ CaptureLauncher::CaptureLauncher(QWidget *parent) :
m_mainLayout->addWidget(m_CaptureModeLabel);
m_mainLayout->addLayout(captureModeForm);
m_mainLayout->addStretch(10);
m_mainLayout->addWidget(m_launchButton, 1 , Qt::AlignCenter);
m_mainLayout->addWidget(m_launchButton, 1, Qt::AlignCenter);
m_mainLayout->setContentsMargins(10, 0, 0, 10);
layout->addLayout(m_mainLayout, 0 ,1);
layout->addLayout(m_mainLayout, 0, 1);
layout->setColumnMinimumWidth(0, 320);
layout->setColumnMinimumWidth(1, 320);
}
// HACK: https://github.com/KDE/spectacle/blob/fa1e780b8bf3df3ac36c410b9ece4ace041f401b/src/Gui/KSMainWindow.cpp#L70
void CaptureLauncher::startCapture() {
// HACK:
// https://github.com/KDE/spectacle/blob/fa1e780b8bf3df3ac36c410b9ece4ace041f401b/src/Gui/KSMainWindow.cpp#L70
void CaptureLauncher::startCapture()
{
hide();
auto mode = static_cast<CaptureRequest::CaptureMode>(
m_captureType->currentData().toInt());
m_captureType->currentData().toInt());
CaptureRequest req(mode, 600 + m_delaySpinBox->value() * 1000);
m_id = req.id();
Controller::getInstance()->requestCapture(req);
}
void CaptureLauncher::startDrag() {
QDrag *dragHandler = new QDrag(this);
QMimeData *mimeData = new QMimeData;
void CaptureLauncher::startDrag()
{
QDrag* dragHandler = new QDrag(this);
QMimeData* mimeData = new QMimeData;
mimeData->setImageData(m_imageLabel->pixmap());
dragHandler->setMimeData(mimeData);
dragHandler->setPixmap(m_imageLabel->pixmap()
->scaled(256, 256, Qt::KeepAspectRatioByExpanding,
Qt::SmoothTransformation));
dragHandler->setPixmap(m_imageLabel->pixmap()->scaled(
256, 256, Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation));
dragHandler->exec();
}
void CaptureLauncher::captureTaken(uint id, QPixmap p) {
void CaptureLauncher::captureTaken(uint id, QPixmap p)
{
if (id == m_id) {
m_id = 0;
m_imageLabel->setScreenshot(p);
@@ -134,7 +147,8 @@ void CaptureLauncher::captureTaken(uint id, QPixmap p) {
}
}
void CaptureLauncher::captureFailed(uint id) {
void CaptureLauncher::captureFailed(uint id)
{
if (id == m_id) {
m_id = 0;
show();

View File

@@ -31,7 +31,7 @@ class CaptureLauncher : public QWidget
{
Q_OBJECT
public:
explicit CaptureLauncher(QWidget *parent = nullptr);
explicit CaptureLauncher(QWidget* parent = nullptr);
private slots:
void startCapture();
@@ -40,12 +40,11 @@ private slots:
void captureFailed(uint id);
private:
QSpinBox *m_delaySpinBox;
QComboBox *m_captureType;
QVBoxLayout *m_mainLayout;
QPushButton *m_launchButton;
QLabel *m_CaptureModeLabel;
ImageLabel *m_imageLabel;
QSpinBox* m_delaySpinBox;
QComboBox* m_captureType;
QVBoxLayout* m_mainLayout;
QPushButton* m_launchButton;
QLabel* m_CaptureModeLabel;
ImageLabel* m_imageLabel;
uint m_id;
};

View File

@@ -1,7 +1,7 @@
#include "historywidget.h"
#include "src/tools/storage/storagemanager.h"
#include "src/tools/storage/imguploader.h"
#include "src/tools/storage/s3/imgs3uploader.h"
#include "src/tools/storage/storagemanager.h"
#include "src/utils/history.h"
#include "src/widgets/notificationwidget.h"
#include <QApplication>

View File

@@ -20,8 +20,9 @@
#include "imagelabel.h"
ImageLabel::ImageLabel(QWidget *parent):
QLabel(parent), m_pixmap(QPixmap())
ImageLabel::ImageLabel(QWidget* parent)
: QLabel(parent)
, m_pixmap(QPixmap())
{
m_DSEffect = new QGraphicsDropShadowEffect(this);
@@ -35,44 +36,48 @@ ImageLabel::ImageLabel(QWidget *parent):
setMinimumSize(size());
}
void ImageLabel::setScreenshot(const QPixmap &pixmap) {
void ImageLabel::setScreenshot(const QPixmap& pixmap)
{
m_pixmap = pixmap;
const QString tooltip = QStringLiteral("%1x%2 px").arg(m_pixmap.width())
.arg(m_pixmap.height());
const QString tooltip =
QStringLiteral("%1x%2 px").arg(m_pixmap.width()).arg(m_pixmap.height());
setToolTip(tooltip);
setScaledPixmap();
}
void ImageLabel::setScaledPixmap() {
void ImageLabel::setScaledPixmap()
{
const qreal scale = qApp->devicePixelRatio();
QPixmap scaledPixmap = m_pixmap.scaled(size() * scale, Qt::KeepAspectRatio,
Qt::SmoothTransformation);
QPixmap scaledPixmap = m_pixmap.scaled(
size() * scale, Qt::KeepAspectRatio, Qt::SmoothTransformation);
scaledPixmap.setDevicePixelRatio(scale);
setPixmap(scaledPixmap);
}
// drag handlers
void ImageLabel::mousePressEvent(QMouseEvent *event) {
void ImageLabel::mousePressEvent(QMouseEvent* event)
{
if (event->button() == Qt::LeftButton) {
m_dragStartPosition = event->pos();
setCursor(Qt::ClosedHandCursor);
}
}
void ImageLabel::mouseReleaseEvent(QMouseEvent *event) {
void ImageLabel::mouseReleaseEvent(QMouseEvent* event)
{
if (event->button() == Qt::LeftButton) {
setCursor(Qt::OpenHandCursor);
}
}
void ImageLabel::mouseMoveEvent(QMouseEvent *event) {
void ImageLabel::mouseMoveEvent(QMouseEvent* event)
{
if (!(event->buttons() & Qt::LeftButton)) {
return;
}
if ((event->pos() - m_dragStartPosition).manhattanLength() <
QGuiApplication::styleHints()->startDragDistance())
{
QGuiApplication::styleHints()->startDragDistance()) {
return;
}
setCursor(Qt::OpenHandCursor);
@@ -80,7 +85,8 @@ void ImageLabel::mouseMoveEvent(QMouseEvent *event) {
}
// resize handler
void ImageLabel::resizeEvent(QResizeEvent *event) {
void ImageLabel::resizeEvent(QResizeEvent* event)
{
Q_UNUSED(event);
setScaledPixmap();
}

View File

@@ -20,35 +20,36 @@
#pragma once
#include <QGuiApplication>
#include <QStyleHints>
#include <QLabel>
#include <QColor>
#include <QMouseEvent>
#include <QPoint>
#include <QPixmap>
#include <QGraphicsDropShadowEffect>
#include <QGuiApplication>
#include <QLabel>
#include <QMouseEvent>
#include <QPixmap>
#include <QPoint>
#include <QStyleHints>
class ImageLabel : public QLabel {
class ImageLabel : public QLabel
{
Q_OBJECT
public:
explicit ImageLabel(QWidget *parent = nullptr);
void setScreenshot(const QPixmap &pixmap);
explicit ImageLabel(QWidget* parent = nullptr);
void setScreenshot(const QPixmap& pixmap);
signals:
void dragInitiated();
protected:
void mousePressEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
void mouseReleaseEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
void mouseMoveEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
void resizeEvent(QResizeEvent *event) Q_DECL_OVERRIDE;
void mousePressEvent(QMouseEvent* event) Q_DECL_OVERRIDE;
void mouseReleaseEvent(QMouseEvent* event) Q_DECL_OVERRIDE;
void mouseMoveEvent(QMouseEvent* event) Q_DECL_OVERRIDE;
void resizeEvent(QResizeEvent* event) Q_DECL_OVERRIDE;
private:
void setScaledPixmap();
QGraphicsDropShadowEffect *m_DSEffect;
QGraphicsDropShadowEffect* m_DSEffect;
QPixmap m_pixmap;
QPoint m_dragStartPosition;
};

View File

@@ -16,30 +16,32 @@
// along with Flameshot. If not, see <http://www.gnu.org/licenses/>.
#include "infowindow.h"
#include <QIcon>
#include <QVBoxLayout>
#include <QTableWidget>
#include <QHeaderView>
#include <QLabel>
#include <QIcon>
#include <QKeyEvent>
#include <QLabel>
#include <QTableWidget>
#include <QVBoxLayout>
#if (QT_VERSION >= QT_VERSION_CHECK(5, 10, 0))
#include <QCursor>
#include <QGuiApplication>
#include <QRect>
#include <QScreen>
#include <QGuiApplication>
#endif
// InfoWindow show basic information about the usage of Flameshot
InfoWindow::InfoWindow(QWidget *parent) : QWidget(parent) {
InfoWindow::InfoWindow(QWidget* parent)
: QWidget(parent)
{
setAttribute(Qt::WA_DeleteOnClose);
setWindowIcon(QIcon(":img/app/flameshot.svg"));
setWindowTitle(tr("About"));
#if (QT_VERSION >= QT_VERSION_CHECK(5, 10, 0))
QRect position = frameGeometry();
QScreen *screen = QGuiApplication::screenAt(QCursor::pos());
QScreen* screen = QGuiApplication::screenAt(QCursor::pos());
position.moveCenter(screen->availableGeometry().center());
move(position.topLeft());
#endif
@@ -50,34 +52,35 @@ InfoWindow::InfoWindow(QWidget *parent) : QWidget(parent) {
show();
}
void InfoWindow::initLabels() {
QLabel *icon = new QLabel();
void InfoWindow::initLabels()
{
QLabel* icon = new QLabel();
icon->setPixmap(QPixmap(":img/app/flameshot.svg"));
icon->setAlignment(Qt::AlignHCenter);
m_layout->addWidget(icon);
QLabel *licenseTitleLabel = new QLabel(tr("<u><b>License</b></u>"), this);
QLabel* licenseTitleLabel = new QLabel(tr("<u><b>License</b></u>"), this);
licenseTitleLabel->setAlignment(Qt::AlignHCenter);
m_layout->addWidget(licenseTitleLabel);
QLabel *licenseLabel = new QLabel(QStringLiteral("GPLv3+"), this);
QLabel* licenseLabel = new QLabel(QStringLiteral("GPLv3+"), this);
licenseLabel->setAlignment(Qt::AlignHCenter);
m_layout->addWidget(licenseLabel);
m_layout->addStretch();
QLabel *versionTitleLabel = new QLabel(tr("<u><b>Version</b></u>"), this);
QLabel* versionTitleLabel = new QLabel(tr("<u><b>Version</b></u>"), this);
versionTitleLabel->setAlignment(Qt::AlignHCenter);
m_layout->addWidget(versionTitleLabel);
QString versionMsg = "Flameshot " + QStringLiteral(APP_VERSION) + "\nCompiled with Qt "
+ QT_VERSION_STR;
QLabel *versionLabel = new QLabel(versionMsg, this);
QString versionMsg = "Flameshot " + QStringLiteral(APP_VERSION) +
"\nCompiled with Qt " + QT_VERSION_STR;
QLabel* versionLabel = new QLabel(versionMsg, this);
versionLabel->setAlignment(Qt::AlignHCenter);
m_layout->addWidget(versionLabel);
m_layout->addSpacing(30);
}
void InfoWindow::keyPressEvent(QKeyEvent *e) {
void InfoWindow::keyPressEvent(QKeyEvent* e)
{
if (e->key() == Qt::Key_Escape) {
close();
}

View File

@@ -21,15 +21,16 @@
class QVBoxLayout;
class InfoWindow : public QWidget {
class InfoWindow : public QWidget
{
Q_OBJECT
public:
explicit InfoWindow(QWidget *parent = nullptr);
explicit InfoWindow(QWidget* parent = nullptr);
protected:
void keyPressEvent(QKeyEvent *);
void keyPressEvent(QKeyEvent*);
private:
void initLabels();
QVBoxLayout *m_layout;
QVBoxLayout* m_layout;
};

View File

@@ -16,81 +16,92 @@
// along with Flameshot. If not, see <http://www.gnu.org/licenses/>.
#include "loadspinner.h"
#include <QApplication>
#include <QPaintEvent>
#include <QPainter>
#include <QTimer>
#include <QApplication>
#define OFFSET 5
LoadSpinner::LoadSpinner(QWidget *parent) :
QWidget(parent), m_startAngle(0), m_span(0), m_growing(true)
LoadSpinner::LoadSpinner(QWidget* parent)
: QWidget(parent)
, m_startAngle(0)
, m_span(0)
, m_growing(true)
{
setAttribute(Qt::WA_TranslucentBackground);
const int size = QApplication::fontMetrics().height() * 8;
setFixedSize(size, size);
updateFrame();
// init timer
m_timer = new QTimer(this);
m_timer = new QTimer(this);
connect(m_timer, &QTimer::timeout, this, &LoadSpinner::rotate);
m_timer->setInterval(30);
}
void LoadSpinner::setColor(const QColor &c) {
void LoadSpinner::setColor(const QColor& c)
{
m_color = c;
}
void LoadSpinner::setWidth(int w) {
void LoadSpinner::setWidth(int w)
{
setFixedSize(w, w);
updateFrame();
}
void LoadSpinner::setHeight(int h) {
void LoadSpinner::setHeight(int h)
{
setFixedSize(h, h);
updateFrame();
}
void LoadSpinner::start() {
void LoadSpinner::start()
{
m_timer->start();
}
void LoadSpinner::stop() {
void LoadSpinner::stop()
{
m_timer->stop();
}
void LoadSpinner::paintEvent(QPaintEvent *) {
void LoadSpinner::paintEvent(QPaintEvent*)
{
QPainter painter(this);
painter.setRenderHint(QPainter::Antialiasing, true);
auto pen = QPen(m_color);
pen.setWidth(height()/10);
pen.setWidth(height() / 10);
painter.setPen(pen);
painter.setOpacity(0.2);
painter.drawArc(m_frame, 0, 5760);
painter.drawArc(m_frame, 0, 5760);
painter.setOpacity(1.0);
painter.drawArc(m_frame, (m_startAngle * 16), (m_span * 16));
}
void LoadSpinner::rotate() {
void LoadSpinner::rotate()
{
const int advance = 3;
const int grow = 8;
if (m_growing) {
m_startAngle = (m_startAngle + advance) % 360;
m_span += grow;
if(m_span > 260) {
if (m_span > 260) {
m_growing = false;
}
} else {
m_startAngle = (m_startAngle + grow) % 360;
m_span = m_span + advance - grow;
if(m_span < 10) {
if (m_span < 10) {
m_growing = true;
}
}
update();
}
void LoadSpinner::updateFrame() {
m_frame = QRect(OFFSET, OFFSET, width() - OFFSET*2, height() - OFFSET*2);
void LoadSpinner::updateFrame()
{
m_frame =
QRect(OFFSET, OFFSET, width() - OFFSET * 2, height() - OFFSET * 2);
}

View File

@@ -19,31 +19,32 @@
#include <QWidget>
class LoadSpinner : public QWidget {
class LoadSpinner : public QWidget
{
Q_OBJECT
public:
explicit LoadSpinner(QWidget *parent = nullptr);
explicit LoadSpinner(QWidget* parent = nullptr);
void setColor(const QColor &c);
void setColor(const QColor& c);
void setWidth(int w);
void setHeight(int h);
void start();
void stop();
protected:
void paintEvent(QPaintEvent *);
void paintEvent(QPaintEvent*);
private slots:
void rotate();
private:
QColor m_color;
QTimer *m_timer;
QTimer* m_timer;
int m_startAngle = 0;
int m_span =180;
int m_span = 180;
bool m_growing;
QRect m_frame;
QRect m_frame;
void updateFrame();
};

View File

@@ -16,15 +16,16 @@
// along with Flameshot. If not, see <http://www.gnu.org/licenses/>.
#include "notificationwidget.h"
#include <QLabel>
#include <QTimer>
#include <QLabel>
#include <QPropertyAnimation>
#include <QVBoxLayout>
#include <QFrame>
#include <QIcon>
#include <QLabel>
#include <QPropertyAnimation>
#include <QTimer>
#include <QVBoxLayout>
NotificationWidget::NotificationWidget(QWidget *parent) : QWidget(parent) {
NotificationWidget::NotificationWidget(QWidget* parent)
: QWidget(parent)
{
m_timer = new QTimer(this);
m_timer->setSingleShot(true);
m_timer->setInterval(7000);
@@ -40,7 +41,8 @@ NotificationWidget::NotificationWidget(QWidget *parent) : QWidget(parent) {
m_hideAnimation = new QPropertyAnimation(m_content, "geometry", this);
m_hideAnimation->setDuration(300);
connect(m_hideAnimation, &QPropertyAnimation::finished, m_label, &QLabel::hide);
connect(
m_hideAnimation, &QPropertyAnimation::finished, m_label, &QLabel::hide);
auto mainLayout = new QVBoxLayout();
setLayout(mainLayout);
@@ -52,20 +54,23 @@ NotificationWidget::NotificationWidget(QWidget *parent) : QWidget(parent) {
setFixedHeight(40);
}
void NotificationWidget::showMessage(const QString &msg) {
void NotificationWidget::showMessage(const QString& msg)
{
m_label->setText(msg);
m_label->show();
animatedShow();
}
void NotificationWidget::animatedShow() {
void NotificationWidget::animatedShow()
{
m_showAnimation->setStartValue(QRect(0, 0, width(), 0));
m_showAnimation->setEndValue(QRect(0, 0, width(), height()));
m_showAnimation->start();
m_timer->start();
}
void NotificationWidget::animatedHide() {
void NotificationWidget::animatedHide()
{
m_hideAnimation->setStartValue(QRect(0, 0, width(), height()));
m_hideAnimation->setEndValue(QRect(0, 0, width(), 0));
m_hideAnimation->start();

View File

@@ -25,20 +25,21 @@ class QPropertyAnimation;
class QVBoxLayout;
class QFrame;
class NotificationWidget : public QWidget {
class NotificationWidget : public QWidget
{
Q_OBJECT
public:
explicit NotificationWidget(QWidget *parent = nullptr);
explicit NotificationWidget(QWidget* parent = nullptr);
void showMessage(const QString &msg);
void showMessage(const QString& msg);
private:
QLabel *m_label;
QPropertyAnimation *m_showAnimation;
QPropertyAnimation *m_hideAnimation;
QVBoxLayout *m_layout;
QFrame *m_content;
QTimer *m_timer;
QLabel* m_label;
QPropertyAnimation* m_showAnimation;
QPropertyAnimation* m_hideAnimation;
QVBoxLayout* m_layout;
QFrame* m_content;
QTimer* m_timer;
void animatedShow();
void animatedHide();

View File

@@ -16,50 +16,55 @@
// along with Flameshot. If not, see <http://www.gnu.org/licenses/>.
#include "sidepanelwidget.h"
#include "src/utils/pathinfo.h"
#include "src/utils/colorutils.h"
#include <QVBoxLayout>
#include "src/utils/pathinfo.h"
#include <QFormLayout>
#include <QPushButton>
#include <QLabel>
#include <QKeyEvent>
#include <QLabel>
#include <QPushButton>
#include <QSlider>
#include <QVBoxLayout>
class QColorPickingEventFilter : public QObject {
class QColorPickingEventFilter : public QObject
{
public:
explicit QColorPickingEventFilter(SidePanelWidget* pw,
QObject* parent = nullptr)
: QObject(parent)
, m_pw(pw)
{}
explicit QColorPickingEventFilter(
SidePanelWidget *pw, QObject *parent = nullptr) :
QObject(parent), m_pw(pw) {}
bool eventFilter(QObject *, QEvent *event) override {
bool eventFilter(QObject*, QEvent* event) override
{
event->accept();
switch (event->type()) {
case QEvent::MouseMove:
return m_pw->handleMouseMove(static_cast<QMouseEvent *>(event));
case QEvent::MouseButtonPress:
return m_pw->handleMouseButtonPressed(
static_cast<QMouseEvent *>(event));
case QEvent::KeyPress:
return m_pw->handleKeyPress(static_cast<QKeyEvent *>(event));
default:
break;
case QEvent::MouseMove:
return m_pw->handleMouseMove(static_cast<QMouseEvent*>(event));
case QEvent::MouseButtonPress:
return m_pw->handleMouseButtonPressed(
static_cast<QMouseEvent*>(event));
case QEvent::KeyPress:
return m_pw->handleKeyPress(static_cast<QKeyEvent*>(event));
default:
break;
}
return false;
}
private:
SidePanelWidget *m_pw;
SidePanelWidget* m_pw;
};
////////////////////////
SidePanelWidget::SidePanelWidget(QPixmap *p, QWidget *parent) :
QWidget(parent), m_pixmap(p), m_eventFilter(nullptr)
SidePanelWidget::SidePanelWidget(QPixmap* p, QWidget* parent)
: QWidget(parent)
, m_pixmap(p)
, m_eventFilter(nullptr)
{
m_layout = new QVBoxLayout(this);
QFormLayout *colorForm = new QFormLayout();
QFormLayout* colorForm = new QFormLayout();
m_thicknessSlider = new QSlider(Qt::Horizontal);
m_thicknessSlider->setValue(m_thickness);
m_colorLabel = new QLabel();
@@ -68,48 +73,60 @@ SidePanelWidget::SidePanelWidget(QPixmap *p, QWidget *parent) :
colorForm->addRow(tr("Active color:"), m_colorLabel);
m_layout->addLayout(colorForm);
connect(m_thicknessSlider, &QSlider::sliderReleased,
this, &SidePanelWidget::updateCurrentThickness);
connect(this, &SidePanelWidget::thicknessChanged,
this, &SidePanelWidget::updateThickness);
connect(m_thicknessSlider,
&QSlider::sliderReleased,
this,
&SidePanelWidget::updateCurrentThickness);
connect(this,
&SidePanelWidget::thicknessChanged,
this,
&SidePanelWidget::updateThickness);
QColor background = this->palette().background().color();
bool isDark = ColorUtils::colorIsDark(background);
QString modifier = isDark ? PathInfo::whiteIconPath() :
PathInfo::blackIconPath();
QString modifier =
isDark ? PathInfo::whiteIconPath() : PathInfo::blackIconPath();
QIcon grabIcon(modifier + "colorize.svg");
m_colorGrabButton = new QPushButton(grabIcon, QLatin1String(""));
updateGrabButton(false);
connect(m_colorGrabButton, &QPushButton::pressed,
this, &SidePanelWidget::colorGrabberActivated);
connect(m_colorGrabButton,
&QPushButton::pressed,
this,
&SidePanelWidget::colorGrabberActivated);
m_layout->addWidget(m_colorGrabButton);
m_colorWheel = new color_widgets::ColorWheel(this);
m_colorWheel->setColor(m_color);
connect(m_colorWheel, &color_widgets::ColorWheel::mouseReleaseOnColor, this,
connect(m_colorWheel,
&color_widgets::ColorWheel::mouseReleaseOnColor,
this,
&SidePanelWidget::colorChanged);
connect(m_colorWheel, &color_widgets::ColorWheel::colorChanged, this,
connect(m_colorWheel,
&color_widgets::ColorWheel::colorChanged,
this,
&SidePanelWidget::updateColorNoWheel);
m_layout->addWidget(m_colorWheel);
}
void SidePanelWidget::updateColor(const QColor &c) {
void SidePanelWidget::updateColor(const QColor& c)
{
m_color = c;
m_colorLabel->setStyleSheet(
QStringLiteral("QLabel { background-color : %1; }").arg(c.name()));
QStringLiteral("QLabel { background-color : %1; }").arg(c.name()));
m_colorWheel->setColor(m_color);
}
void SidePanelWidget::updateThickness(const int &t)
void SidePanelWidget::updateThickness(const int& t)
{
m_thickness = qBound(0, t, 100);
m_thicknessSlider->setValue(m_thickness);
}
void SidePanelWidget::updateColorNoWheel(const QColor &c) {
void SidePanelWidget::updateColorNoWheel(const QColor& c)
{
m_color = c;
m_colorLabel->setStyleSheet(
QStringLiteral("QLabel { background-color : %1; }").arg(c.name()));
QStringLiteral("QLabel { background-color : %1; }").arg(c.name()));
}
void SidePanelWidget::updateCurrentThickness()
@@ -117,7 +134,8 @@ void SidePanelWidget::updateCurrentThickness()
emit thicknessChanged(m_thicknessSlider->value());
}
void SidePanelWidget::colorGrabberActivated() {
void SidePanelWidget::colorGrabberActivated()
{
grabKeyboard();
grabMouse(Qt::CrossCursor);
setMouseTracking(true);
@@ -129,7 +147,8 @@ void SidePanelWidget::colorGrabberActivated() {
updateGrabButton(true);
}
void SidePanelWidget::releaseColorGrab() {
void SidePanelWidget::releaseColorGrab()
{
setMouseTracking(false);
removeEventFilter(m_eventFilter);
releaseMouse();
@@ -138,16 +157,18 @@ void SidePanelWidget::releaseColorGrab() {
updateGrabButton(false);
}
QColor SidePanelWidget::grabPixmapColor(const QPoint &p) {
QColor SidePanelWidget::grabPixmapColor(const QPoint& p)
{
QColor c;
if (m_pixmap) {
QPixmap pixel = m_pixmap->copy(QRect(p, p));
c = pixel.toImage().pixel(0,0);
c = pixel.toImage().pixel(0, 0);
}
return c;
}
bool SidePanelWidget::handleKeyPress(QKeyEvent *e) {
bool SidePanelWidget::handleKeyPress(QKeyEvent* e)
{
if (e->key() == Qt::Key_Escape) {
releaseColorGrab();
updateColor(m_colorBackup);
@@ -159,10 +180,10 @@ bool SidePanelWidget::handleKeyPress(QKeyEvent *e) {
return true;
}
bool SidePanelWidget::handleMouseButtonPressed(QMouseEvent *e) {
bool SidePanelWidget::handleMouseButtonPressed(QMouseEvent* e)
{
if (m_colorGrabButton->geometry().contains(e->pos()) ||
e->button() == Qt::RightButton)
{
e->button() == Qt::RightButton) {
updateColorNoWheel(m_colorBackup);
} else if (e->button() == Qt::LeftButton) {
updateColor(grabPixmapColor(QCursor::pos()));
@@ -172,12 +193,14 @@ bool SidePanelWidget::handleMouseButtonPressed(QMouseEvent *e) {
return true;
}
bool SidePanelWidget::handleMouseMove(QMouseEvent *e) {
bool SidePanelWidget::handleMouseMove(QMouseEvent* e)
{
updateColorNoWheel(grabPixmapColor(e->globalPos()));
return true;
}
void SidePanelWidget::updateGrabButton(const bool activated) {
void SidePanelWidget::updateGrabButton(const bool activated)
{
if (activated) {
m_colorGrabButton->setText(tr("Press ESC to cancel"));
} else {

View File

@@ -17,8 +17,8 @@
#pragma once
#include <QWidget>
#include "color_wheel.hpp"
#include <QWidget>
class QVBoxLayout;
class QPushButton;
@@ -26,24 +26,26 @@ class QLabel;
class QColorPickingEventFilter;
class QSlider;
class SidePanelWidget : public QWidget {
class SidePanelWidget : public QWidget
{
Q_OBJECT
friend class QColorPickingEventFilter;
public:
explicit SidePanelWidget(QPixmap *p, QWidget *parent = nullptr);
explicit SidePanelWidget(QPixmap* p, QWidget* parent = nullptr);
signals:
void colorChanged(const QColor &c);
void thicknessChanged(const int &t);
void colorChanged(const QColor& c);
void thicknessChanged(const int& t);
void togglePanel();
public slots:
void updateColor(const QColor &c);
void updateThickness(const int &t);
void updateColor(const QColor& c);
void updateThickness(const int& t);
private slots:
void updateColorNoWheel(const QColor &c);
void updateColorNoWheel(const QColor& c);
void updateCurrentThickness();
private slots:
@@ -51,23 +53,22 @@ private slots:
void releaseColorGrab();
private:
QColor grabPixmapColor(const QPoint &p);
QColor grabPixmapColor(const QPoint& p);
bool handleKeyPress(QKeyEvent *e);
bool handleMouseButtonPressed(QMouseEvent *e);
bool handleMouseMove(QMouseEvent *e);
bool handleKeyPress(QKeyEvent* e);
bool handleMouseButtonPressed(QMouseEvent* e);
bool handleMouseMove(QMouseEvent* e);
void updateGrabButton(const bool activated);
QVBoxLayout *m_layout;
QPushButton *m_colorGrabButton;
color_widgets::ColorWheel *m_colorWheel;
QLabel *m_colorLabel;
QPixmap *m_pixmap;
QVBoxLayout* m_layout;
QPushButton* m_colorGrabButton;
color_widgets::ColorWheel* m_colorWheel;
QLabel* m_colorLabel;
QPixmap* m_pixmap;
QColor m_colorBackup;
QColor m_color;
QSlider *m_thicknessSlider;
QSlider* m_thicknessSlider;
int m_thickness;
QColorPickingEventFilter *m_eventFilter;
QColorPickingEventFilter* m_eventFilter;
};

View File

@@ -17,13 +17,15 @@
#include "utilitypanel.h"
#include <QPropertyAnimation>
#include <QVBoxLayout>
#include <QTimer>
#include <QScrollArea>
#include <QWheelEvent>
#include <QPushButton>
#include <QScrollArea>
#include <QTimer>
#include <QVBoxLayout>
#include <QWheelEvent>
UtilityPanel::UtilityPanel(QWidget *parent) : QWidget(parent) {
UtilityPanel::UtilityPanel(QWidget* parent)
: QWidget(parent)
{
initInternalPanel();
setAttribute(Qt::WA_TransparentForMouseEvents);
setCursor(Qt::ArrowCursor);
@@ -36,15 +38,19 @@ UtilityPanel::UtilityPanel(QWidget *parent) : QWidget(parent) {
m_hideAnimation->setEasingCurve(QEasingCurve::InOutQuad);
m_hideAnimation->setDuration(300);
connect(m_hideAnimation, &QPropertyAnimation::finished,
m_internalPanel, &QWidget::hide);
connect(m_hideAnimation,
&QPropertyAnimation::finished,
m_internalPanel,
&QWidget::hide);
}
QWidget *UtilityPanel::toolWidget() const {
QWidget* UtilityPanel::toolWidget() const
{
return m_toolWidget;
}
void UtilityPanel::addToolWidget(QWidget *w) {
void UtilityPanel::addToolWidget(QWidget* w)
{
if (m_toolWidget) {
m_toolWidget->deleteLater();
}
@@ -54,17 +60,20 @@ void UtilityPanel::addToolWidget(QWidget *w) {
}
}
void UtilityPanel::clearToolWidget() {
void UtilityPanel::clearToolWidget()
{
if (m_toolWidget) {
m_toolWidget->deleteLater();
}
}
void UtilityPanel::pushWidget(QWidget *w) {
void UtilityPanel::pushWidget(QWidget* w)
{
m_layout->addWidget(w);
}
void UtilityPanel::show() {
void UtilityPanel::show()
{
setAttribute(Qt::WA_TransparentForMouseEvents, false);
m_showAnimation->setStartValue(QRect(-width(), 0, 0, height()));
m_showAnimation->setEndValue(QRect(0, 0, width(), height()));
@@ -73,7 +82,8 @@ void UtilityPanel::show() {
QWidget::show();
}
void UtilityPanel::hide() {
void UtilityPanel::hide()
{
setAttribute(Qt::WA_TransparentForMouseEvents);
m_hideAnimation->setStartValue(QRect(0, 0, width(), height()));
m_hideAnimation->setEndValue(QRect(-width(), 0, 0, height()));
@@ -82,7 +92,8 @@ void UtilityPanel::hide() {
QWidget::hide();
}
void UtilityPanel::toggle() {
void UtilityPanel::toggle()
{
if (m_internalPanel->isHidden()) {
show();
} else {
@@ -90,10 +101,11 @@ void UtilityPanel::toggle() {
}
}
void UtilityPanel::initInternalPanel() {
void UtilityPanel::initInternalPanel()
{
m_internalPanel = new QScrollArea(this);
m_internalPanel->setAttribute(Qt::WA_NoMousePropagation);
QWidget *widget = new QWidget();
QWidget* widget = new QWidget();
m_internalPanel->setWidget(widget);
m_internalPanel->setWidgetResizable(true);
@@ -104,8 +116,8 @@ void UtilityPanel::initInternalPanel() {
QColor bgColor = palette().background().color();
bgColor.setAlphaF(0.0);
m_internalPanel->setStyleSheet(QStringLiteral("QScrollArea {background-color: %1}")
.arg(bgColor.name()));
m_internalPanel->setStyleSheet(
QStringLiteral("QScrollArea {background-color: %1}").arg(bgColor.name()));
m_internalPanel->hide();
m_hide = new QPushButton();
@@ -114,6 +126,7 @@ void UtilityPanel::initInternalPanel() {
connect(m_hide, SIGNAL(clicked()), this, SLOT(slotHidePanel()));
}
void UtilityPanel::slotHidePanel() {
void UtilityPanel::slotHidePanel()
{
hide();
}

View File

@@ -17,23 +17,24 @@
#pragma once
#include <QWidget>
#include <QPointer>
#include <QWidget>
class QVBoxLayout;
class QPropertyAnimation;
class QScrollArea;
class QPushButton;
class UtilityPanel : public QWidget {
class UtilityPanel : public QWidget
{
Q_OBJECT
public:
explicit UtilityPanel(QWidget *parent = nullptr);
explicit UtilityPanel(QWidget* parent = nullptr);
QWidget* toolWidget() const;
void addToolWidget(QWidget *w);
void addToolWidget(QWidget* w);
void clearToolWidget();
void pushWidget(QWidget *w);
void pushWidget(QWidget* w);
void hide();
void show();
@@ -49,10 +50,10 @@ private:
void initInternalPanel();
QPointer<QWidget> m_toolWidget;
QScrollArea *m_internalPanel;
QVBoxLayout *m_upLayout;
QVBoxLayout *m_layout;
QPropertyAnimation *m_showAnimation;
QPropertyAnimation *m_hideAnimation;
QPushButton *m_hide;
QScrollArea* m_internalPanel;
QVBoxLayout* m_upLayout;
QVBoxLayout* m_layout;
QPropertyAnimation* m_showAnimation;
QPropertyAnimation* m_hideAnimation;
QPushButton* m_hide;
};