Skip to content
Permalink
Browse files

Add new custom widgets (QgsSlider and QgsDial)

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 373ec56922b62e3f3a103435ea8570801f44181e
Showing with 76 additions and 0 deletions.
  1. +6 −0 src/gui/CMakeLists.txt
  2. +19 −0 src/gui/qgsdial.cpp
  3. +13 −0 src/gui/qgsdial.h
  4. +24 −0 src/gui/qgsslider.cpp
  5. +14 −0 src/gui/qgsslider.h
@@ -86,6 +86,7 @@ qgsdetaileditemdata.cpp
qgsdatumtransformdialog.cpp
qgsdetaileditemdelegate.cpp
qgsdetaileditemwidget.cpp
qgsdial.cpp
qgsdialog.cpp
qgsencodingfiledialog.cpp
qgserrordialog.cpp
@@ -148,6 +149,7 @@ qgsscalecombobox.cpp
qgsscalerangewidget.cpp
qgsscalevisibilitydialog.cpp
qgssearchquerybuilder.cpp
qgsslider.cpp
qgssublayersdialog.cpp
qgssvgannotationitem.cpp
qgstextannotationitem.cpp
@@ -243,6 +245,7 @@ qgsdatadefinedbutton.h
qgsdatumtransformdialog.h
qgsdetaileditemdelegate.h
qgsdetaileditemwidget.h
qgsdial.h
qgsdialog.h
qgsencodingfiledialog.h
qgserrordialog.h
@@ -295,6 +298,7 @@ qgsscalecombobox.h
qgsscalerangewidget.h
qgsscalevisibilitydialog.h
qgssearchquerybuilder.h
qgsslider.h
qgssublayersdialog.h
qgsunitselectionwidget.h
)
@@ -322,6 +326,7 @@ qgscolordialog.h
qgscredentialdialog.h
qgscursors.h
qgsdatadefinedbutton.h
qgsdial.h
qgsencodingfiledialog.h
qgsexpressionbuilderdialog.h
qgsexpressionbuilderwidget.h
@@ -363,6 +368,7 @@ qgsscalecombobox.h
qgsscalerangewidget.h
qgsscalevisibilitydialog.h
qgssearchquerybuilder.h
qgsslider.h
qgssublayersdialog.h
qgsvectorlayertools.h
qgsvertexmarker.h
@@ -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();
}
@@ -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 );
};
@@ -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();
}
@@ -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.
You can’t perform that action at this time.