64 #include <qdrawutil.h> 85 orientation_(_orientation),
93 palette_.setColor( QPalette::Dark, QColor(0,0,0));
95 setFrameStyle( QtWheel::Panel | QtWheel::Raised );
98 setContextMenuPolicy ( Qt::CustomContextMenu );
100 connect (
this, SIGNAL (customContextMenuRequested (
const QPoint & ) ),
101 this, SLOT( slotCustomContextMenuRequested (
const QPoint & ) ));
113 if (_e->button()==Qt::LeftButton) {
122 if (_e->button()==Qt::LeftButton)
135 if (_e->buttons()&Qt::LeftButton)
137 float dAngle=turn(_e->pos());
149 double QtWheel::turn(
const QPoint& _pos)
151 QPoint dPos=(_pos-
pos_);
154 int d =
orientation_== Horizontal ? dPos.x() : dPos.y();
172 if (_e->button()==Qt::LeftButton) {
175 sz=width(); x=_e->x();
178 sz=height(); x=_e->y();
219 if (!_e->isAutoRepeat())
272 QFrame::resizeEvent(_e);
278 QFrame::paintEvent(_e);
281 QPainter painter(
this);
282 QRect r=contentsRect();
285 painter.drawPixmap( r.left(), r.top(),
pixmap_ );
293 QRect r=contentsRect();
295 if (r.width()<=0 || r.height()<=0) {
306 pixmap_.fill( palette().background().color() );
309 QRect contents = contentsRect();
310 contents.moveTopLeft(QPoint(0,0));
312 QPen pen(Qt::black, 1);
320 paint.drawRect(contents);
322 paint.drawRect(contents);
325 int x0 = contents.left();
326 int y0 = contents.top();
327 int w0 = contents.width();
328 int h0 = contents.height();
333 QBrush b; b.setColor(QColor(Qt::red)); b.setStyle(Qt::SolidPattern);
335 paint.fillRect(x0+8,y0-1,w,h0+2,b);
338 QBrush b; b.setColor(QColor(Qt::blue));
339 int w=std::min(-4*
gearShift_,w0-8); b.setStyle(Qt::SolidPattern);
340 paint.fillRect(x0+w0-w-8,y0-1,w,h0+2,b);
344 double step = 2 * M_PI / (double)
ticks_;
345 for (
int i = 0; i <
ticks_; i++) {
346 double x = sin(
angle_ + i * step);
347 double y = cos(
angle_ + i * step);
349 qDrawShadeLine( &paint,
350 (
int) (x0+(w0+x*w0)/2.0f), y0,
351 (
int) (x0+(w0+x*w0)/2.0f), y0+h0,
362 paint.drawRect(contents);
364 paint.drawRect(contents);
368 int x0 = contents.left();
369 int y0 = contents.top();
370 int w0 = contents.width();
371 int h0 = contents.height();
376 QBrush b; b.setColor(QColor(Qt::red)); b.setStyle(Qt::SolidPattern);
378 paint.fillRect(x0-1,y0+8,w0+2,h,b);
381 QBrush b; b.setColor(QColor(Qt::blue)); b.setStyle(Qt::SolidPattern);
383 paint.fillRect(x0-1,y0+h0-h-8,w0+2,h,b);
387 double step = 2 * M_PI / (double)
ticks_;
388 for (
int i = 0; i <
ticks_; i++) {
389 double x = sin(
angle_ + i * step);
390 double y = cos(
angle_ + i * step);
392 qDrawShadeLine( &paint,
393 x0, (
int) (y0+(h0+x*h0)/2.0f),
394 x0+w0, (
int) (y0+(h0+x*h0)/2.0f),
405 _rect.setLeft(_rect.left()+_dx);
406 _rect.setRight(_rect.right()-_dx);
407 _rect.setTop(_rect.top()+_dy);
408 _rect.setBottom(_rect.bottom()-_dy);
416 return QSizePolicy(QSizePolicy::Preferred,
417 QSizePolicy::Minimum);
419 return QSizePolicy(QSizePolicy::Minimum,
420 QSizePolicy::Preferred);
428 return QSize(120,20);
430 return QSize(20,120);
437 return fmod(_angle,2*M_PI);
441 return _angle*180.0/M_PI;
446 void QtWheel::slotCustomContextMenuRequested (
const QPoint & pos ) {
448 QMenu* menu =
new QMenu(
this);
449 QAction *hide = menu->addAction(
"Hide wheel");
450 connect( hide, SIGNAL(triggered()) ,
this, SIGNAL(
hideWheel()) );
451 menu->popup( mapToGlobal(pos) );
Namespace providing different geometric functions concerning angles.