Skip to content

Commit

Permalink
Add custom step size support for CPULoadWidget
Browse files Browse the repository at this point in the history
  • Loading branch information
he29-net committed Sep 1, 2023
1 parent aa222a5 commit fe134b1
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions data/themes/classic/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ lmms--gui--Oscilloscope {
lmms--gui--CPULoadWidget {
border: none;
background: url(resources:cpuload_bg.png);
qproperty-stepSize: 4;
}

/* scrollbar: trough */
Expand Down
1 change: 1 addition & 0 deletions data/themes/default/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ lmms--gui--Oscilloscope {
lmms--gui--CPULoadWidget {
border: none;
background: url(resources:cpuload_bg.png);
qproperty-stepSize: 1;
}

/* scrollbar: trough */
Expand Down
4 changes: 4 additions & 0 deletions include/CPULoadWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ namespace lmms::gui
class CPULoadWidget : public QWidget
{
Q_OBJECT
Q_PROPERTY(int stepSize MEMBER m_stepSize)
public:
CPULoadWidget( QWidget * _parent );
~CPULoadWidget() override = default;
Expand All @@ -64,6 +65,9 @@ protected slots:

QTimer m_updateTimer;

int m_stepSize;
int stepSize() const { return m_stepSize > 0 ? m_stepSize : 1; }

} ;


Expand Down
4 changes: 3 additions & 1 deletion src/gui/widgets/CPULoadWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ void CPULoadWidget::paintEvent( QPaintEvent * )
QPainter p( &m_temp );
p.drawPixmap( 0, 0, m_background );

int w = m_leds.width() * m_currentLoad / 100;
// Normally the CPU load indicator moves smoothly, with 1 pixel resolution. However, some themes may want to
// draw discrete elements (like LEDs), so the stepSize property can be used to specify a larger step size.
int w = (m_leds.width() * m_currentLoad / (stepSize() * 100)) * stepSize();
if( w > 0 )
{
p.drawPixmap( 23, 3, m_leds, 0, 0, w,
Expand Down

0 comments on commit fe134b1

Please sign in to comment.