Skip to content

Commit a6144df

Browse files
Fix alignment bug and applied many clang format warnings (flameshot-org#2448)
* Fix alignment bug and applied many clang format warnings * removed nodiscard from slot
1 parent 413a3f9 commit a6144df

File tree

8 files changed

+105
-104
lines changed

8 files changed

+105
-104
lines changed

src/tools/text/textconfig.cpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212

1313
TextConfig::TextConfig(QWidget* parent)
1414
: QWidget(parent)
15-
, m_layout(nullptr)
16-
, m_fontsCB(nullptr)
15+
, m_layout(new QVBoxLayout(this))
16+
, m_fontsCB(new QComboBox())
1717
, m_strikeOutButton(nullptr)
1818
, m_underlineButton(nullptr)
1919
, m_weightButton(nullptr)
@@ -22,10 +22,9 @@ TextConfig::TextConfig(QWidget* parent)
2222
, m_centerAlignButton(nullptr)
2323
, m_rightAlignButton(nullptr)
2424
{
25-
m_layout = new QVBoxLayout(this);
2625

2726
QFontDatabase fontDB;
28-
m_fontsCB = new QComboBox();
27+
2928
connect(m_fontsCB,
3029
&QComboBox::currentTextChanged,
3130
this,
@@ -121,29 +120,30 @@ void TextConfig::setFontFamily(const QString& fontFamily)
121120
m_fontsCB->findText(fontFamily.isEmpty() ? font().family() : fontFamily));
122121
}
123122

124-
void TextConfig::setUnderline(const bool u)
123+
void TextConfig::setUnderline(const bool underline)
125124
{
126-
m_underlineButton->setChecked(u);
125+
m_underlineButton->setChecked(underline);
127126
}
128127

129-
void TextConfig::setStrikeOut(const bool s)
128+
void TextConfig::setStrikeOut(const bool strikeout)
130129
{
131-
m_strikeOutButton->setChecked(s);
130+
m_strikeOutButton->setChecked(strikeout);
132131
}
133132

134-
void TextConfig::setWeight(const int w)
133+
void TextConfig::setWeight(const int weight)
135134
{
136-
m_weightButton->setChecked(static_cast<QFont::Weight>(w) == QFont::Bold);
135+
m_weightButton->setChecked(static_cast<QFont::Weight>(weight) ==
136+
QFont::Bold);
137137
}
138138

139-
void TextConfig::setItalic(const bool i)
139+
void TextConfig::setItalic(const bool italic)
140140
{
141-
m_italicButton->setChecked(i);
141+
m_italicButton->setChecked(italic);
142142
}
143143

144-
void TextConfig::weightButtonPressed(const bool w)
144+
void TextConfig::weightButtonPressed(const bool weight)
145145
{
146-
if (w) {
146+
if (weight) {
147147
emit fontWeightChanged(QFont::Bold);
148148
} else {
149149
emit fontWeightChanged(QFont::Normal);

src/tools/text/textconfig.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ class TextConfig : public QWidget
1616
explicit TextConfig(QWidget* parent = nullptr);
1717

1818
void setFontFamily(const QString& fontFamily);
19-
void setUnderline(const bool u);
20-
void setStrikeOut(const bool s);
21-
void setWeight(const int w);
22-
void setItalic(const bool i);
19+
void setUnderline(bool underline);
20+
void setStrikeOut(bool strikeout);
21+
void setWeight(int weight);
22+
void setItalic(bool italic);
2323
void setTextAlignment(Qt::AlignmentFlag alignment);
2424

2525
signals:
@@ -32,7 +32,7 @@ class TextConfig : public QWidget
3232
public slots:
3333

3434
private slots:
35-
void weightButtonPressed(const bool w);
35+
void weightButtonPressed(bool weight);
3636

3737
private:
3838
QVBoxLayout* m_layout;

src/tools/text/texttool.cpp

Lines changed: 41 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ TextTool::TextTool(QObject* parent)
1717
if (!fontFamily.isEmpty()) {
1818
m_font.setFamily(ConfigHandler().fontFamily());
1919
}
20-
m_alignment = Qt::AlignRight;
20+
m_alignment = Qt::AlignLeft;
2121
}
2222

2323
TextTool::~TextTool()
@@ -161,34 +161,36 @@ QWidget* TextTool::configurationWidget()
161161

162162
CaptureTool* TextTool::copy(QObject* parent)
163163
{
164-
auto* tt = new TextTool(parent);
165-
if (m_confW) {
166-
connect(
167-
m_confW, &TextConfig::fontFamilyChanged, tt, &TextTool::updateFamily);
164+
auto* textTool = new TextTool(parent);
165+
if (m_confW != nullptr) {
166+
connect(m_confW,
167+
&TextConfig::fontFamilyChanged,
168+
textTool,
169+
&TextTool::updateFamily);
168170
connect(m_confW,
169171
&TextConfig::fontItalicChanged,
170-
tt,
172+
textTool,
171173
&TextTool::updateFontItalic);
172174
connect(m_confW,
173175
&TextConfig::fontStrikeOutChanged,
174-
tt,
176+
textTool,
175177
&TextTool::updateFontStrikeOut);
176178
connect(m_confW,
177179
&TextConfig::fontUnderlineChanged,
178-
tt,
180+
textTool,
179181
&TextTool::updateFontUnderline);
180182
connect(m_confW,
181183
&TextConfig::fontWeightChanged,
182-
tt,
184+
textTool,
183185
&TextTool::updateFontWeight);
184186

185187
connect(m_confW,
186188
&TextConfig::alignmentChanged,
187-
tt,
189+
textTool,
188190
&TextTool::updateAlignment);
189191
}
190-
copyParams(this, tt);
191-
return tt;
192+
copyParams(this, textTool);
193+
return textTool;
192194
}
193195

194196
void TextTool::process(QPainter& painter, const QPixmap& pixmap)
@@ -215,7 +217,7 @@ void TextTool::process(QPainter& painter, const QPixmap& pixmap)
215217
painter.setFont(orig_font);
216218
painter.setPen(orig_pen);
217219

218-
if (m_widget) {
220+
if (m_widget != nullptr) {
219221
m_widget->setAlignment(m_alignment);
220222
}
221223
}
@@ -235,14 +237,14 @@ void TextTool::paintMousePreview(QPainter& painter,
235237
Q_UNUSED(context)
236238
}
237239

238-
void TextTool::drawEnd(const QPoint& p)
240+
void TextTool::drawEnd(const QPoint& point)
239241
{
240-
m_textArea.moveTo(p);
242+
m_textArea.moveTo(point);
241243
}
242244

243-
void TextTool::drawMove(const QPoint& p)
245+
void TextTool::drawMove(const QPoint& point)
244246
{
245-
m_widget->move(p);
247+
m_widget->move(point);
246248
}
247249

248250
void TextTool::drawStart(const CaptureContext& context)
@@ -257,67 +259,67 @@ void TextTool::pressed(CaptureContext& context)
257259
Q_UNUSED(context)
258260
}
259261

260-
void TextTool::onColorChanged(const QColor& c)
262+
void TextTool::onColorChanged(const QColor& color)
261263
{
262-
m_color = c;
263-
if (m_widget) {
264-
m_widget->setTextColor(c);
264+
m_color = color;
265+
if (m_widget != nullptr) {
266+
m_widget->setTextColor(color);
265267
}
266268
}
267269

268270
void TextTool::onSizeChanged(int size)
269271
{
270272
m_size = size;
271273
m_font.setPointSize(m_size + BASE_POINT_SIZE);
272-
if (m_widget) {
274+
if (m_widget != nullptr) {
273275
m_widget->setFont(m_font);
274276
}
275277
}
276278

277-
void TextTool::updateText(const QString& s)
279+
void TextTool::updateText(const QString& newText)
278280
{
279-
m_text = s;
281+
m_text = newText;
280282
}
281283

282-
void TextTool::updateFamily(const QString& s)
284+
void TextTool::updateFamily(const QString& text)
283285
{
284-
m_font.setFamily(s);
286+
m_font.setFamily(text);
285287
if (m_textOld.isEmpty()) {
286288
ConfigHandler().setFontFamily(m_font.family());
287289
}
288-
if (m_widget) {
290+
if (m_widget != nullptr) {
289291
m_widget->setFont(m_font);
290292
}
291293
}
292294

293295
void TextTool::updateFontUnderline(const bool underlined)
294296
{
295297
m_font.setUnderline(underlined);
296-
if (m_widget) {
298+
if (m_widget != nullptr) {
297299
m_widget->setFont(m_font);
298300
}
299301
}
300302

301-
void TextTool::updateFontStrikeOut(const bool s)
303+
void TextTool::updateFontStrikeOut(const bool strikeout)
302304
{
303-
m_font.setStrikeOut(s);
304-
if (m_widget) {
305+
m_font.setStrikeOut(strikeout);
306+
if (m_widget != nullptr) {
305307
m_widget->setFont(m_font);
306308
}
307309
}
308310

309-
void TextTool::updateFontWeight(const QFont::Weight w)
311+
void TextTool::updateFontWeight(const QFont::Weight weight)
310312
{
311-
m_font.setWeight(w);
312-
if (m_widget) {
313+
m_font.setWeight(weight);
314+
if (m_widget != nullptr) {
313315
m_widget->setFont(m_font);
314316
}
315317
}
316318

317319
void TextTool::updateFontItalic(const bool italic)
318320
{
319321
m_font.setItalic(italic);
320-
if (m_widget) {
322+
if (m_widget != nullptr) {
321323
m_widget->setFont(m_font);
322324
}
323325
}
@@ -330,7 +332,7 @@ void TextTool::move(const QPoint& pos)
330332
void TextTool::updateAlignment(Qt::AlignmentFlag alignment)
331333
{
332334
m_alignment = alignment;
333-
if (m_widget) {
335+
if (m_widget != nullptr) {
334336
m_widget->setAlignment(m_alignment);
335337
}
336338
}
@@ -341,12 +343,12 @@ const QPoint* TextTool::pos()
341343
return &m_currentPos;
342344
}
343345

344-
void TextTool::setEditMode(bool b)
346+
void TextTool::setEditMode(bool editMode)
345347
{
346-
if (b) {
348+
if (editMode) {
347349
m_textOld = m_text;
348350
}
349-
CaptureTool::setEditMode(b);
351+
CaptureTool::setEditMode(editMode);
350352
}
351353

352354
bool TextTool::isChanged()

src/tools/text/texttool.h

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,18 @@ class TextTool : public CaptureTool
1515
Q_OBJECT
1616
public:
1717
explicit TextTool(QObject* parent = nullptr);
18-
~TextTool();
18+
~TextTool() override;
1919

20-
bool isValid() const override;
21-
bool closeOnButtonPressed() const override;
22-
bool isSelectable() const override;
23-
bool showMousePreview() const override;
24-
QRect boundingRect() const override;
20+
[[nodiscard]] bool isValid() const override;
21+
[[nodiscard]] bool closeOnButtonPressed() const override;
22+
[[nodiscard]] bool isSelectable() const override;
23+
[[nodiscard]] bool showMousePreview() const override;
24+
[[nodiscard]] QRect boundingRect() const override;
2525

26-
QIcon icon(const QColor& background, bool inEditor) const override;
27-
QString name() const override;
28-
QString description() const override;
26+
[[nodiscard]] QIcon icon(const QColor& background,
27+
bool inEditor) const override;
28+
[[nodiscard]] QString name() const override;
29+
[[nodiscard]] QString description() const override;
2930
QString info() override;
3031

3132
QWidget* widget() override;
@@ -39,29 +40,29 @@ class TextTool : public CaptureTool
3940
const QPoint* pos() override;
4041
void drawObjectSelection(QPainter& painter) override;
4142

42-
void setEditMode(bool b) override;
43+
void setEditMode(bool editMode) override;
4344
bool isChanged() override;
4445

4546
protected:
4647
void copyParams(const TextTool* from, TextTool* to);
47-
CaptureTool::Type type() const override;
48+
[[nodiscard]] CaptureTool::Type type() const override;
4849

4950
public slots:
50-
void drawEnd(const QPoint& p) override;
51-
void drawMove(const QPoint& p) override;
51+
void drawEnd(const QPoint& point) override;
52+
void drawMove(const QPoint& point) override;
5253
void drawStart(const CaptureContext& context) override;
5354
void pressed(CaptureContext& context) override;
54-
void onColorChanged(const QColor& c) override;
55+
void onColorChanged(const QColor& color) override;
5556
void onSizeChanged(int size) override;
56-
virtual int size() const override { return m_size; };
57+
int size() const override { return m_size; };
5758

5859
private slots:
59-
void updateText(const QString& s);
60-
void updateFamily(const QString& s);
61-
void updateFontUnderline(const bool underlined);
62-
void updateFontStrikeOut(const bool s);
63-
void updateFontWeight(const QFont::Weight w);
64-
void updateFontItalic(const bool italic);
60+
void updateText(const QString& string);
61+
void updateFamily(const QString& string);
62+
void updateFontUnderline(bool underlined);
63+
void updateFontStrikeOut(bool strikeout);
64+
void updateFontWeight(QFont::Weight weight);
65+
void updateFontItalic(bool italic);
6566
void updateAlignment(Qt::AlignmentFlag alignment);
6667

6768
private:

src/widgets/panel/sidepanelwidget.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
#include "src/utils/pathinfo.h"
99
#include "utilitypanel.h"
1010
#include <QApplication>
11-
#include <QDebug> // TODO remove
12-
#include <QFormLayout>
1311
#include <QKeyEvent>
1412
#include <QLabel>
1513
#include <QLineEdit>
@@ -23,9 +21,10 @@
2321

2422
SidePanelWidget::SidePanelWidget(QPixmap* p, QWidget* parent)
2523
: QWidget(parent)
24+
, m_layout(new QVBoxLayout(this))
2625
, m_pixmap(p)
2726
{
28-
m_layout = new QVBoxLayout(this);
27+
2928
if (parent) {
3029
parent->installEventFilter(this);
3130
}
@@ -109,7 +108,7 @@ void SidePanelWidget::onColorChanged(const QColor& c)
109108
m_colorWheel->setColor(c);
110109
}
111110

112-
void SidePanelWidget::onToolSizeChanged(const int& t)
111+
void SidePanelWidget::onToolSizeChanged(int t)
113112
{
114113
m_toolSize = qBound(0, t, maxToolSize);
115114
m_toolSizeSlider->setValue(m_toolSize);

0 commit comments

Comments
 (0)