Skip to content

Commit 4f6468e

Browse files
committed
qml: allow to customize blockclockdial's pen width
1 parent 021829c commit 4f6468e

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

src/qml/components/blockclockdial.cpp

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,12 @@
1010
#include <QConicalGradient>
1111
#include <QPen>
1212
#include <QtMath>
13+
#include <QtGlobal>
1314

1415
BlockClockDial::BlockClockDial(QQuickItem *parent)
1516
: QQuickPaintedItem(parent)
1617
, m_time_ratio_list{0.0}
18+
, m_pen_width{4}
1719
, m_background_color{QColor("#2D2D2D")}
1820
, m_confirmation_colors{QList<QColor>{}}
1921
, m_time_tick_color{QColor("#000000")}
@@ -132,6 +134,12 @@ void BlockClockDial::setPaused(bool paused)
132134
}
133135
}
134136

137+
void BlockClockDial::setPenWidth(qreal width)
138+
{
139+
m_pen_width = width;
140+
update();
141+
}
142+
135143
void BlockClockDial::setBackgroundColor(QColor color)
136144
{
137145
m_background_color = color;
@@ -183,7 +191,7 @@ void BlockClockDial::paintBlocks(QPainter * painter)
183191
}
184192

185193
QPen pen(m_confirmation_colors[5]);
186-
pen.setWidth(4);
194+
pen.setWidthF(m_pen_width);
187195
pen.setCapStyle(Qt::FlatCap);
188196
const QRectF bounds = getBoundsForPen(pen);
189197
painter->setPen(pen);
@@ -196,7 +204,7 @@ void BlockClockDial::paintBlocks(QPainter * painter)
196204
for (int i = 1; i < numberOfBlocks; i++) {
197205
if (numberOfBlocks - i <= 6) {
198206
QPen pen(m_confirmation_colors[numberOfBlocks - i - 1]);
199-
pen.setWidth(4);
207+
pen.setWidthF(m_pen_width);
200208
pen.setCapStyle(Qt::FlatCap);
201209
painter->setPen(pen);
202210
}
@@ -227,7 +235,7 @@ void BlockClockDial::paintBlocks(QPainter * painter)
227235
void BlockClockDial::paintProgress(QPainter * painter)
228236
{
229237
QPen pen(m_confirmation_colors[5]);
230-
pen.setWidthF(4);
238+
pen.setWidthF(m_pen_width);
231239
pen.setCapStyle(Qt::RoundCap);
232240
const QRectF bounds = getBoundsForPen(pen);
233241
painter->setPen(pen);
@@ -250,7 +258,7 @@ void BlockClockDial::paintProgress(QPainter * painter)
250258
void BlockClockDial::paintConnectingAnimation(QPainter * painter)
251259
{
252260
QPen pen;
253-
pen.setWidthF(4);
261+
pen.setWidthF(m_pen_width);
254262
setupConnectingGradient(pen);
255263
pen.setBrush(QBrush(m_connecting_gradient));
256264
pen.setCapStyle(Qt::RoundCap);
@@ -267,7 +275,7 @@ void BlockClockDial::paintConnectingAnimation(QPainter * painter)
267275
void BlockClockDial::paintBackground(QPainter * painter)
268276
{
269277
QPen pen(m_background_color);
270-
pen.setWidthF(4);
278+
pen.setWidthF(m_pen_width);
271279
const QRectF bounds = getBoundsForPen(pen);
272280
painter->setPen(pen);
273281

@@ -283,12 +291,12 @@ double BlockClockDial::degreesPerPixel()
283291
void BlockClockDial::paintTimeTicks(QPainter * painter)
284292
{
285293
QPen pen(m_time_tick_color);
286-
pen.setWidthF(4);
294+
pen.setWidthF(m_pen_width);
287295
// Calculate bound based on width of default pen
288296
const QRectF bounds = getBoundsForPen(pen);
289297

290298
QPen time_tick_pen = QPen(m_time_tick_color);
291-
time_tick_pen.setWidth(2);
299+
time_tick_pen.setWidthF(m_pen_width / 2);
292300
time_tick_pen.setCapStyle(Qt::RoundCap);
293301
painter->setPen(time_tick_pen);
294302
for (double angle = 0; angle < 360; angle += 30) {

src/qml/components/blockclockdial.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <QConicalGradient>
1010
#include <QPainter>
1111
#include <QTimer>
12+
#include <QtGlobal>
1213

1314
class BlockClockDial : public QQuickPaintedItem
1415
{
@@ -18,6 +19,7 @@ class BlockClockDial : public QQuickPaintedItem
1819
Q_PROPERTY(bool connected READ connected WRITE setConnected)
1920
Q_PROPERTY(bool synced READ synced WRITE setSynced)
2021
Q_PROPERTY(bool paused READ paused WRITE setPaused)
22+
Q_PROPERTY(qreal penWidth READ penWidth WRITE setPenWidth)
2123
Q_PROPERTY(QColor backgroundColor READ backgroundColor WRITE setBackgroundColor)
2224
Q_PROPERTY(QList<QColor> confirmationColors READ confirmationColors WRITE setConfirmationColors )
2325
Q_PROPERTY(QColor timeTickColor READ timeTickColor WRITE setTimeTickColor)
@@ -31,6 +33,7 @@ class BlockClockDial : public QQuickPaintedItem
3133
bool connected() const { return m_is_connected; };
3234
bool synced() const { return m_is_synced; };
3335
bool paused() const { return m_is_paused; };
36+
qreal penWidth() const { return m_pen_width; };
3437
QColor backgroundColor() const { return m_background_color; };
3538
QList<QColor> confirmationColors() const { return m_confirmation_colors; };
3639
QColor timeTickColor() const { return m_time_tick_color; };
@@ -41,6 +44,7 @@ public Q_SLOTS:
4144
void setConnected(bool connected);
4245
void setSynced(bool synced);
4346
void setPaused(bool paused);
47+
void setPenWidth(qreal width);
4448
void setBackgroundColor(QColor color);
4549
void setConfirmationColors(QList<QColor> colorList);
4650
void setTimeTickColor(QColor color);
@@ -63,6 +67,7 @@ public Q_SLOTS:
6367
bool m_is_connected;
6468
bool m_is_synced;
6569
bool m_is_paused;
70+
qreal m_pen_width;
6671
QColor m_background_color;
6772
QConicalGradient m_connecting_gradient;
6873
qreal m_connecting_start_angle = 90;

0 commit comments

Comments
 (0)