Newer
Older
/* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
* Qwt Widget Library
* Copyright (C) 1997 Josef Wilgen
* Copyright (C) 2002 Uwe Rathmann
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the Qwt License, Version 1.0
*****************************************************************************/
#include "qwt_wheel.h"
#include "qwt_math.h"
#include "qwt_painter.h"
#include <qevent.h>
#include <qdrawutil.h>
#include <qpainter.h>
#include <qstyle.h>
#include <qstyleoption.h>
#include <qapplication.h>
#include <qdatetime.h>
#if QT_VERSION < 0x040601
#define qFabs(x) ::fabs(x)
#define qFastSin(x) ::sin(x)
#define qExp(x) ::exp(x)
#endif
PrivateData():
orientation( Qt::Horizontal ),
viewAngle( 175.0 ),
totalAngle( 360.0 ),
tickCount( 10 ),
wheelBorderWidth( 2 ),
borderWidth( 2 ),
wheelWidth( 20 ),
isScrolling( false ),
mouseOffset( 0.0 ),
tracking( true ),
pendingValueChanged( false ),
updateInterval( 50 ),
mass( 0.0 ),
timerId( 0 ),
speed( 0.0 ),
mouseValue( 0.0 ),
flyingValue( 0.0 ),
minimum( 0.0 ),
maximum( 100.0 ),
singleStep( 1.0 ),
pageStepCount( 1 ),
stepAlignment( true ),
value( 0.0 ),
inverted( false ),
wrapping( false )
{
bool isScrolling;
double mouseOffset;
bool tracking;
bool pendingValueChanged; // when not tracking
int updateInterval;
double mass;
// for the flying wheel effect
int timerId;
QTime time;
double speed;
double mouseValue;
double flyingValue;
double minimum;
double maximum;
double singleStep;
int pageStepCount;
bool stepAlignment;
double value;
bool inverted;
bool wrapping;
d_data = new PrivateData;
setFocusPolicy( Qt::StrongFocus );
setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Fixed );
setAttribute( Qt::WA_WState_OwnSizePolicy, false );
/*!
\brief En/Disable tracking
If tracking is enabled (the default), the wheel emits the valueChanged()
signal while the wheel is moving. If tracking is disabled, the wheel
emits the valueChanged() signal only when the wheel movement is terminated.
The wheelMoved() signal is emitted regardless id tracking is enabled or not.
\param enable On/Off
\sa isTracking()
*/
void QwtWheel::setTracking( bool enable )
/*!
\return True, when tracking is enabled
\sa setTracking(), valueChanged(), wheelMoved()
*/
bool QwtWheel::isTracking() const
{
return d_data->tracking;
}
/*!
\brief Specify the update interval when the wheel is flying
\param interval Interval in milliseconds
\sa updateInterval(), setMass(), setTracking()
*/
void QwtWheel::setUpdateInterval( int interval )
{
d_data->updateInterval = qMax( interval, 50 );
/*!
\return Update interval when the wheel is flying
\sa setUpdateInterval(), mass(), isTracking()
*/
int QwtWheel::updateInterval() const
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
return d_data->updateInterval;
}
/*!
\brief Mouse press event handler
Start movement of the wheel.
\param event Mouse event
*/
void QwtWheel::mousePressEvent( QMouseEvent *event )
{
stopFlying();
d_data->isScrolling = wheelRect().contains( event->pos() );
if ( d_data->isScrolling )
{
d_data->time.start();
d_data->speed = 0.0;
d_data->mouseValue = valueAt( event->pos() );
d_data->mouseOffset = d_data->mouseValue - d_data->value;
d_data->pendingValueChanged = false;
Q_EMIT wheelPressed();
}
/*!
\brief Mouse Move Event handler
Turn the wheel according to the mouse position
\param event Mouse event
*/
void QwtWheel::mouseMoveEvent( QMouseEvent *event )
double mouseValue = valueAt( event->pos() );
if ( d_data->mass > 0.0 )
Loading
Loading full blame...