Skip to content

Commit

Permalink
Add new custom widgets (QgsSlider and QgsDial)
Browse files Browse the repository at this point in the history
Modified versions of QSlider and QDial which show the current value

Fix #4417
  • Loading branch information
ddanielvaz authored and m-kuhn committed May 22, 2014
1 parent 2e4275d commit 373ec56
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/gui/CMakeLists.txt
Expand Up @@ -86,6 +86,7 @@ qgsdetaileditemdata.cpp
qgsdatumtransformdialog.cpp
qgsdetaileditemdelegate.cpp
qgsdetaileditemwidget.cpp
qgsdial.cpp
qgsdialog.cpp
qgsencodingfiledialog.cpp
qgserrordialog.cpp
Expand Down Expand Up @@ -148,6 +149,7 @@ qgsscalecombobox.cpp
qgsscalerangewidget.cpp
qgsscalevisibilitydialog.cpp
qgssearchquerybuilder.cpp
qgsslider.cpp
qgssublayersdialog.cpp
qgssvgannotationitem.cpp
qgstextannotationitem.cpp
Expand Down Expand Up @@ -243,6 +245,7 @@ qgsdatadefinedbutton.h
qgsdatumtransformdialog.h
qgsdetaileditemdelegate.h
qgsdetaileditemwidget.h
qgsdial.h
qgsdialog.h
qgsencodingfiledialog.h
qgserrordialog.h
Expand Down Expand Up @@ -295,6 +298,7 @@ qgsscalecombobox.h
qgsscalerangewidget.h
qgsscalevisibilitydialog.h
qgssearchquerybuilder.h
qgsslider.h
qgssublayersdialog.h
qgsunitselectionwidget.h
)
Expand Down Expand Up @@ -322,6 +326,7 @@ qgscolordialog.h
qgscredentialdialog.h
qgscursors.h
qgsdatadefinedbutton.h
qgsdial.h
qgsencodingfiledialog.h
qgsexpressionbuilderdialog.h
qgsexpressionbuilderwidget.h
Expand Down Expand Up @@ -363,6 +368,7 @@ qgsscalecombobox.h
qgsscalerangewidget.h
qgsscalevisibilitydialog.h
qgssearchquerybuilder.h
qgsslider.h
qgssublayersdialog.h
qgsvectorlayertools.h
qgsvertexmarker.h
Expand Down
19 changes: 19 additions & 0 deletions src/gui/qgsdial.cpp
@@ -0,0 +1,19 @@
#include "qgsdial.h"

#include <QRect>

QgsDial::QgsDial( QWidget *parent ) : QDial( parent )
{
setMinimumSize( QSize(50, 50) );
}

void QgsDial::paintEvent( QPaintEvent *event )
{
QDial::paintEvent( event );
QPainter painter( this );
QRect rect = geometry();
painter.setPen( QPen( palette().color( QPalette::WindowText ) ) );
painter.drawText( QRectF( 0, rect.height() * 0.65, rect.width(), rect.height() ),
Qt::AlignHCenter, QString::number( value() ), 0 );
painter.end();
}
13 changes: 13 additions & 0 deletions src/gui/qgsdial.h
@@ -0,0 +1,13 @@
#include <QDial>
#include <QPainter>
#include <QPaintEvent>
#include <QSize>

class QgsDial : public QDial
{
Q_OBJECT
public:
QgsDial( QWidget *parent = 0 );
protected:
virtual void paintEvent( QPaintEvent * event );
};
24 changes: 24 additions & 0 deletions src/gui/qgsslider.cpp
@@ -0,0 +1,24 @@
#include "qgsslider.h"

#include <QRect>

QgsSlider::QgsSlider ( QWidget * parent ) : QSlider ( parent )
{
setMinimumSize( QSize(100, 40) );
}

QgsSlider::QgsSlider( Qt::Orientation orientation, QWidget * parent) : QSlider( orientation, parent )
{
setMinimumSize( QSize(100, 40) );
}

void QgsSlider::paintEvent( QPaintEvent *event )
{
QSlider::paintEvent( event );
QPainter painter( this );
QRect rect = geometry();
painter.setPen( QPen( palette().color( QPalette::WindowText ) ) );
painter.drawText( QRectF( 0, rect.height() * 0.5, rect.width(), rect.height() ),
Qt::AlignHCenter, QString::number( value() ), 0 );
painter.end();
}
14 changes: 14 additions & 0 deletions src/gui/qgsslider.h
@@ -0,0 +1,14 @@
#include <QPainter>
#include <QPaintEvent>
#include <QSize>
#include <QSlider>

class QgsSlider : public QSlider
{
Q_OBJECT
public:
QgsSlider( QWidget *parent = 0 );
QgsSlider( Qt::Orientation orientation, QWidget * parent = 0 );
protected:
virtual void paintEvent( QPaintEvent * event );
};

0 comments on commit 373ec56

Please sign in to comment.