Skip to content

Commit 373ec56

Browse files
ddanielvazm-kuhn
authored andcommitted
Add new custom widgets (QgsSlider and QgsDial)
Modified versions of QSlider and QDial which show the current value Fix #4417
1 parent 2e4275d commit 373ec56

File tree

5 files changed

+76
-0
lines changed

5 files changed

+76
-0
lines changed

src/gui/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ qgsdetaileditemdata.cpp
8686
qgsdatumtransformdialog.cpp
8787
qgsdetaileditemdelegate.cpp
8888
qgsdetaileditemwidget.cpp
89+
qgsdial.cpp
8990
qgsdialog.cpp
9091
qgsencodingfiledialog.cpp
9192
qgserrordialog.cpp
@@ -148,6 +149,7 @@ qgsscalecombobox.cpp
148149
qgsscalerangewidget.cpp
149150
qgsscalevisibilitydialog.cpp
150151
qgssearchquerybuilder.cpp
152+
qgsslider.cpp
151153
qgssublayersdialog.cpp
152154
qgssvgannotationitem.cpp
153155
qgstextannotationitem.cpp
@@ -243,6 +245,7 @@ qgsdatadefinedbutton.h
243245
qgsdatumtransformdialog.h
244246
qgsdetaileditemdelegate.h
245247
qgsdetaileditemwidget.h
248+
qgsdial.h
246249
qgsdialog.h
247250
qgsencodingfiledialog.h
248251
qgserrordialog.h
@@ -295,6 +298,7 @@ qgsscalecombobox.h
295298
qgsscalerangewidget.h
296299
qgsscalevisibilitydialog.h
297300
qgssearchquerybuilder.h
301+
qgsslider.h
298302
qgssublayersdialog.h
299303
qgsunitselectionwidget.h
300304
)
@@ -322,6 +326,7 @@ qgscolordialog.h
322326
qgscredentialdialog.h
323327
qgscursors.h
324328
qgsdatadefinedbutton.h
329+
qgsdial.h
325330
qgsencodingfiledialog.h
326331
qgsexpressionbuilderdialog.h
327332
qgsexpressionbuilderwidget.h
@@ -363,6 +368,7 @@ qgsscalecombobox.h
363368
qgsscalerangewidget.h
364369
qgsscalevisibilitydialog.h
365370
qgssearchquerybuilder.h
371+
qgsslider.h
366372
qgssublayersdialog.h
367373
qgsvectorlayertools.h
368374
qgsvertexmarker.h

src/gui/qgsdial.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#include "qgsdial.h"
2+
3+
#include <QRect>
4+
5+
QgsDial::QgsDial( QWidget *parent ) : QDial( parent )
6+
{
7+
setMinimumSize( QSize(50, 50) );
8+
}
9+
10+
void QgsDial::paintEvent( QPaintEvent *event )
11+
{
12+
QDial::paintEvent( event );
13+
QPainter painter( this );
14+
QRect rect = geometry();
15+
painter.setPen( QPen( palette().color( QPalette::WindowText ) ) );
16+
painter.drawText( QRectF( 0, rect.height() * 0.65, rect.width(), rect.height() ),
17+
Qt::AlignHCenter, QString::number( value() ), 0 );
18+
painter.end();
19+
}

src/gui/qgsdial.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#include <QDial>
2+
#include <QPainter>
3+
#include <QPaintEvent>
4+
#include <QSize>
5+
6+
class QgsDial : public QDial
7+
{
8+
Q_OBJECT
9+
public:
10+
QgsDial( QWidget *parent = 0 );
11+
protected:
12+
virtual void paintEvent( QPaintEvent * event );
13+
};

src/gui/qgsslider.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#include "qgsslider.h"
2+
3+
#include <QRect>
4+
5+
QgsSlider::QgsSlider ( QWidget * parent ) : QSlider ( parent )
6+
{
7+
setMinimumSize( QSize(100, 40) );
8+
}
9+
10+
QgsSlider::QgsSlider( Qt::Orientation orientation, QWidget * parent) : QSlider( orientation, parent )
11+
{
12+
setMinimumSize( QSize(100, 40) );
13+
}
14+
15+
void QgsSlider::paintEvent( QPaintEvent *event )
16+
{
17+
QSlider::paintEvent( event );
18+
QPainter painter( this );
19+
QRect rect = geometry();
20+
painter.setPen( QPen( palette().color( QPalette::WindowText ) ) );
21+
painter.drawText( QRectF( 0, rect.height() * 0.5, rect.width(), rect.height() ),
22+
Qt::AlignHCenter, QString::number( value() ), 0 );
23+
painter.end();
24+
}

src/gui/qgsslider.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#include <QPainter>
2+
#include <QPaintEvent>
3+
#include <QSize>
4+
#include <QSlider>
5+
6+
class QgsSlider : public QSlider
7+
{
8+
Q_OBJECT
9+
public:
10+
QgsSlider( QWidget *parent = 0 );
11+
QgsSlider( Qt::Orientation orientation, QWidget * parent = 0 );
12+
protected:
13+
virtual void paintEvent( QPaintEvent * event );
14+
};

0 commit comments

Comments
 (0)