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

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