70 #include <qdrawutil.h>
101 palette_.setColor( QPalette::Dark, QColor(0,0,0));
103 setFrameStyle( QtWheel::Panel | QtWheel::Raised );
106 setContextMenuPolicy ( Qt::CustomContextMenu );
108 connect (
this, SIGNAL (customContextMenuRequested (
const QPoint & ) ),
109 this, SLOT( slotCustomContextMenuRequested (
const QPoint & ) ));
120 if (_e->button()==Qt::LeftButton) {
129 if (_e->button()==Qt::LeftButton)
142 if (_e->buttons()&Qt::LeftButton)
144 float dAngle=turn(_e->pos());
156 double QtWheel::turn(
const QPoint& _pos)
158 QPoint dPos=(_pos-
pos_);
161 int d =
orientation_== Horizontal ? dPos.x() : dPos.y();
179 if (_e->button()==Qt::LeftButton) {
182 sz=width(); x=_e->x();
185 sz=height(); x=_e->y();
226 if (!_e->isAutoRepeat())
279 QFrame::resizeEvent(_e);
285 QFrame::paintEvent(_e);
288 QPainter painter(
this);
289 QRect r=contentsRect();
292 painter.drawPixmap( r.left(), r.top(),
pixmap_ );
300 QRect r=contentsRect();
302 if (r.width()<=0 || r.height()<=0) {
313 pixmap_.fill( palette().background().color() );
316 QRect contents = contentsRect();
317 contents.moveTopLeft(QPoint(0,0));
319 QPen pen(Qt::black, 1);
327 paint.drawRect(contents);
329 paint.drawRect(contents);
332 int x0 = contents.left();
333 int y0 = contents.top();
334 int w0 = contents.width();
335 int h0 = contents.height();
340 QBrush b; b.setColor(QColor(Qt::red)); b.setStyle(Qt::SolidPattern);
342 paint.fillRect(x0+8,y0-1,w,h0+2,b);
345 QBrush b; b.setColor(QColor(Qt::blue));
346 int w=std::min(-4*
gearShift_,w0-8); b.setStyle(Qt::SolidPattern);
347 paint.fillRect(x0+w0-w-8,y0-1,w,h0+2,b);
351 double step = 2 * M_PI / (double)
ticks_;
352 for (
int i = 0; i <
ticks_; i++) {
353 double x = sin(
angle_ + i * step);
354 double y = cos(
angle_ + i * step);
356 qDrawShadeLine( &paint,
357 (
int) (x0+(w0+x*w0)/2.0f), y0,
358 (
int) (x0+(w0+x*w0)/2.0f), y0+h0,
369 paint.drawRect(contents);
371 paint.drawRect(contents);
375 int x0 = contents.left();
376 int y0 = contents.top();
377 int w0 = contents.width();
378 int h0 = contents.height();
383 QBrush b; b.setColor(QColor(Qt::red)); b.setStyle(Qt::SolidPattern);
385 paint.fillRect(x0-1,y0+8,w0+2,h,b);
388 QBrush b; b.setColor(QColor(Qt::blue)); b.setStyle(Qt::SolidPattern);
390 paint.fillRect(x0-1,y0+h0-h-8,w0+2,h,b);
394 double step = 2 * M_PI / (double)
ticks_;
395 for (
int i = 0; i <
ticks_; i++) {
396 double x = sin(
angle_ + i * step);
397 double y = cos(
angle_ + i * step);
399 qDrawShadeLine( &paint,
400 x0, (
int) (y0+(h0+x*h0)/2.0f),
401 x0+w0, (
int) (y0+(h0+x*h0)/2.0f),
412 _rect.setLeft(_rect.left()+_dx);
413 _rect.setRight(_rect.right()-_dx);
414 _rect.setTop(_rect.top()+_dy);
415 _rect.setBottom(_rect.bottom()-_dy);
423 return QSizePolicy(QSizePolicy::Preferred,
424 QSizePolicy::Minimum);
426 return QSizePolicy(QSizePolicy::Minimum,
427 QSizePolicy::Preferred);
435 return QSize(120,20);
437 return QSize(20,120);
444 return fmod(_angle,2*M_PI);
448 return _angle*180.0/M_PI;
453 void QtWheel::slotCustomContextMenuRequested (
const QPoint & pos ) {
455 QMenu* menu =
new QMenu(
this);
456 QAction *hide = menu->addAction(
"Hide wheel");
457 connect( hide, SIGNAL(triggered()) ,
this, SIGNAL(
hideWheel()) );
458 menu->popup( mapToGlobal(pos) );
Namespace providing different geometric functions concerning angles.
double angle_
current angle of the wheel
virtual void mouseReleaseEvent(QMouseEvent *)
reimplemented
QPixmap pixmap_
pixmap of the wheel
int ticks_
number of ticks on the wheel
virtual QSize sizeHint() const
reimplemented
int gearShift_
click-shifted gear by 2^gearShift_
virtual void mouseDoubleClickEvent(QMouseEvent *)
reimplemented
void gearDown()
Like gearUp() but the value of gear() halves.
virtual void keyPressEvent(QKeyEvent *)
reimplemented
virtual void resizeEvent(QResizeEvent *)
reimplemented
virtual void mouseMoveEvent(QMouseEvent *)
reimplemented
double gear_
speed of revolution
virtual ~QtWheel()
Destructor.
void angleChangedBy(double _angle)
int size_
size of wheel in pixels
virtual void keyReleaseEvent(QKeyEvent *)
reimplemented
bool dragging_
currently dragging the slider?
QPalette palette_
color group
Orientation orientation_
orientation of the widget
virtual void paintEvent(QPaintEvent *)
reimplemented
bool marker_
should ticks be marked by colors?
void angleChangedTo(double _angle)
virtual void redrawPixmap()
draw wheel to pixmap (double buffering)
static double deg(double _angle)
maps _angle from radiants to degrees (works also for clip()ped angles)
QtWheel(QWidget *_parent=0, const char *_name=0, Orientation _orientation=Horizontal)
Constructor.
bool tracking_
tracking on?
QPoint pos_
recent mouse position
double lastAngle_
last angle, depends on tracking_
void shrinkRect(QRect &, int, int)
expands a rectangle in x/y direction
virtual QSizePolicy sizePolicy() const
reimplemented
virtual void mousePressEvent(QMouseEvent *)
reimplemented
void hideWheel()
Emitted when the wheel will be hidden by the context menu.
static double clip(double _angle)
Orientation
Orientation of the widget.