A Compass Widget. More...
#include <qwt_compass.h>
Classes | |
class | PrivateData |
Public Member Functions | |
QwtCompass (QWidget *parent=NULL) | |
Constructor. | |
QwtCompass (QWidget *parent, const char *name) | |
Constructor. | |
virtual | ~QwtCompass () |
Destructor. | |
void | setRose (QwtCompassRose *rose) |
const QwtCompassRose * | rose () const |
QwtCompassRose * | rose () |
const QMap< double, QString > & | labelMap () const |
QMap< double, QString > & | labelMap () |
void | setLabelMap (const QMap< double, QString > &map) |
Set a map, mapping values to labels. | |
Protected Member Functions | |
virtual QwtText | scaleLabel (double value) const |
virtual void | drawRose (QPainter *, const QPoint ¢er, int radius, double north, QPalette::ColorGroup) const |
virtual void | drawScaleContents (QPainter *, const QPoint ¢er, int radius) const |
virtual void | keyPressEvent (QKeyEvent *) |
A Compass Widget.
QwtCompass is a widget to display and enter directions. It consists of a scale, an optional needle and rose.
Definition at line 48 of file qwt_compass.h.
QwtCompass::QwtCompass | ( | QWidget * | parent = NULL ) |
[explicit] |
Constructor.
parent | Parent widget |
Create a compass widget with a scale, no needle and no rose. The default origin is 270.0 with no valid value. It accepts mouse and keyboard inputs and has no step size. The default mode is QwtDial::RotateNeedle.
Definition at line 50 of file qwt_compass.cpp.
: QwtDial(parent) { initCompass(); }
QwtCompass::QwtCompass | ( | QWidget * | parent, |
const char * | name | ||
) | [explicit] |
Constructor.
parent | Parent widget |
name | Object name |
Create a compass widget with a scale, no needle and no rose. The default origin is 270.0 with no valid value. It accepts mouse and keyboard inputs and has no step size. The default mode is QwtDial::RotateNeedle.
Definition at line 68 of file qwt_compass.cpp.
: QwtDial(parent, name) { initCompass(); }
QwtCompass::~QwtCompass | ( | ) | [virtual] |
void QwtCompass::drawRose | ( | QPainter * | painter, |
const QPoint & | center, | ||
int | radius, | ||
double | north, | ||
QPalette::ColorGroup | cg | ||
) | const [protected, virtual] |
Draw the compass rose
painter | Painter |
center | Center of the compass |
radius | of the circle, where to paint the rose |
north | Direction pointing north, in degrees counter clockwise |
cg | Color group |
Definition at line 149 of file qwt_compass.cpp.
References QwtCompassRose::draw(), and QwtCompass::PrivateData::rose.
Referenced by drawScaleContents().
void QwtCompass::drawScaleContents | ( | QPainter * | painter, |
const QPoint & | center, | ||
int | radius | ||
) | const [protected, virtual] |
Draw the contents of the scale
painter | Painter |
center | Center of the content circle |
radius | Radius of the content circle |
Reimplemented from QwtDial.
Definition at line 120 of file qwt_compass.cpp.
References drawRose(), QwtAbstractSlider::isValid(), QwtDial::mode(), QwtDial::origin(), QwtDial::RotateScale, and QwtDoubleRange::value().
{ QPalette::ColorGroup cg; if ( isEnabled() ) cg = hasFocus() ? QPalette::Active : QPalette::Inactive; else cg = QPalette::Disabled; double north = origin(); if ( isValid() ) { if ( mode() == RotateScale ) north -= value(); } const int margin = 4; drawRose(painter, center, radius - margin, 360.0 - north, cg); }
void QwtCompass::keyPressEvent | ( | QKeyEvent * | kev ) | [protected, virtual] |
Handles key events
Beside the keys described in QwtDial::keyPressEvent numbers from 1-9 (without 5) set the direction according to their position on the num pad.
Reimplemented from QwtDial.
Definition at line 202 of file qwt_compass.cpp.
References QwtAbstractSlider::isReadOnly(), mitk::Key_1, mitk::Key_2, mitk::Key_3, mitk::Key_4, mitk::Key_5, mitk::Key_6, mitk::Key_7, mitk::Key_8, mitk::Key_9, QwtDial::mode(), QwtDial::origin(), QwtDial::RotateNeedle, QwtAbstractSlider::setValue(), and QwtDoubleRange::value().
{ if (isReadOnly()) return; #if 0 if ( kev->key() == Key_5 ) { invalidate(); // signal ??? return; } #endif double newValue = value(); if ( kev->key() >= Qt::Key_1 && kev->key() <= Qt::Key_9 ) { if ( mode() != RotateNeedle || kev->key() == Qt::Key_5 ) return; switch (kev->key()) { case Qt::Key_6: newValue = 180.0 * 0.0; break; case Qt::Key_3: newValue = 180.0 * 0.25; break; case Qt::Key_2: newValue = 180.0 * 0.5; break; case Qt::Key_1: newValue = 180.0 * 0.75; break; case Qt::Key_4: newValue = 180.0 * 1.0; break; case Qt::Key_7: newValue = 180.0 * 1.25; break; case Qt::Key_8: newValue = 180.0 * 1.5; break; case Qt::Key_9: newValue = 180.0 * 1.75; break; } newValue -= origin(); setValue(newValue); } else { QwtDial::keyPressEvent(kev); } }
QMap< double, QString > & QwtCompass::labelMap | ( | ) |
Definition at line 271 of file qwt_compass.cpp.
References QwtCompass::PrivateData::labelMap.
{ return d_data->labelMap; }
const QMap< double, QString > & QwtCompass::labelMap | ( | ) | const |
Definition at line 262 of file qwt_compass.cpp.
References QwtCompass::PrivateData::labelMap.
{ return d_data->labelMap; }
const QwtCompassRose * QwtCompass::rose | ( | ) | const |
Definition at line 179 of file qwt_compass.cpp.
References QwtCompass::PrivateData::rose.
Referenced by setRose().
{ return d_data->rose; }
QwtCompassRose * QwtCompass::rose | ( | ) |
Definition at line 188 of file qwt_compass.cpp.
References QwtCompass::PrivateData::rose.
{ return d_data->rose; }
QwtText QwtCompass::scaleLabel | ( | double | value ) | const [protected, virtual] |
Map a value to a corresponding label
value | Value that will be mapped |
label() looks in a map for a corresponding label for value or return an null text.
Reimplemented from QwtDial.
Definition at line 303 of file qwt_compass.cpp.
References QwtCompass::PrivateData::labelMap.
void QwtCompass::setLabelMap | ( | const QMap< double, QString > & | map ) |
Set a map, mapping values to labels.
map | value to label map |
The values of the major ticks are found by looking into this map. The default map consists of the labels N, NE, E, SE, S, SW, W, NW.
Definition at line 288 of file qwt_compass.cpp.
References QwtCompass::PrivateData::labelMap.
{ d_data->labelMap = map; }
void QwtCompass::setRose | ( | QwtCompassRose * | rose ) |
Set a rose for the compass
rose | Compass rose |
Definition at line 163 of file qwt_compass.cpp.
References rose(), and QwtCompass::PrivateData::rose.