Newer
Older
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
return 360.0 - angle * 180.0 / M_PI;
}
/*!
Find the value for a given position
\param pos Position
\return Value
*/
double QwtDial::getValue(const QPoint &pos)
{
if ( d_data->maxScaleArc == d_data->minScaleArc || maxValue() == minValue() )
return minValue();
double dir = line2Radians(rect().center(), pos) - d_data->origin;
if ( dir < 0.0 )
dir += 360.0;
if ( mode() == RotateScale )
dir = 360.0 - dir;
// The position might be in the area that is outside the scale arc.
// We need the range of the scale if it was a complete circle.
const double completeCircle = 360.0 / (d_data->maxScaleArc - d_data->minScaleArc)
* (maxValue() - minValue());
double posValue = minValue() + completeCircle * dir / 360.0;
if ( scrollMode() == ScrMouse ) {
if ( d_data->previousDir >= 0.0 ) { // valid direction
// We have to find out whether the mouse is moving
// clock or counter clockwise
bool clockWise = false;
const double angle = dir - d_data->previousDir;
if ( (angle >= 0.0 && angle <= 180.0) || angle < -180.0 )
clockWise = true;
if ( clockWise ) {
if ( dir < d_data->previousDir && mouseOffset() > 0.0 ) {
// We passed 360 -> 0
setMouseOffset(mouseOffset() - completeCircle);
}
if ( wrapping() ) {
if ( posValue - mouseOffset() > maxValue() ) {
// We passed maxValue and the value will be set
// to minValue. We have to adjust the mouseOffset.
setMouseOffset(posValue - minValue());
}
// We fix the value at maxValue by adjusting
// the mouse offset.
setMouseOffset(posValue - maxValue());
}
}
} else {
if ( dir > d_data->previousDir && mouseOffset() < 0.0 ) {
// We passed 0 -> 360
setMouseOffset(mouseOffset() + completeCircle);
if ( wrapping() ) {
if ( posValue - mouseOffset() < minValue() ) {
// We passed minValue and the value will be set
// to maxValue. We have to adjust the mouseOffset.
setMouseOffset(posValue - maxValue());
}
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
// We fix the value at minValue by adjusting
// the mouse offset.
setMouseOffset(posValue - minValue());
}
}
}
}
d_data->previousDir = dir;
}
return posValue;
}
/*!
\sa QwtAbstractSlider::getScrollMode
*/
void QwtDial::getScrollMode(const QPoint &p, int &scrollMode, int &direction)
{
direction = 0;
scrollMode = ScrNone;
const QRegion region(contentsRect(), QRegion::Ellipse);
if ( region.contains(p) && p != rect().center() ) {
scrollMode = ScrMouse;
d_data->previousDir = -1.0;
}
}
Handles key events
- Key_Down, KeyLeft\n
Decrement by 1
- Key_Prior\n
Decrement by pageSize()
- Key_Home\n
Set the value to minValue()
- Key_Up, KeyRight\n
Increment by 1
- Key_Next\n
Increment by pageSize()
- Key_End\n
Set the value to maxValue()
\sa isReadOnly()
*/
void QwtDial::keyPressEvent(QKeyEvent *e)
{
e->ignore();
return;
}
if ( !isValid() )
return;
double previous = prevValue();
switch ( e->key() ) {
case Qt::Key_Down:
case Qt::Key_Left:
QwtDoubleRange::incValue(-1);
break;
QwtDoubleRange::incValue(-pageSize());
break;
case Qt::Key_Home:
setValue(minValue());
break;
case Qt::Key_Up:
case Qt::Key_Right:
QwtDoubleRange::incValue(1);
break;
QwtDoubleRange::incValue(pageSize());
break;
case Qt::Key_End:
setValue(maxValue());
break;
default:
;
e->ignore();
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
}
if (value() != previous)
emit sliderMoved(value());
}
/*!
\brief Update the mask of the dial
In case of "hasVisibleBackground() == false", the backgound is
transparent by a mask.
\sa showBackground(), hasVisibleBackground()
*/
void QwtDial::updateMask()
{
if ( d_data->visibleBackground )
clearMask();
else
setMask(QRegion(boundingRect(), QRegion::Ellipse));
}