void SwitchButton::drawSlider(QPainter *painter) { painter->save(); painter->setPen(Qt::NoPen); if (!checked) { painter->setBrush(sliderColorOff); } else { painter->setBrush(sliderColorOn); } if (buttonStyle == ButtonStyle_Rect) { int sliderWidth = width() / 2 - space * 2; int sliderHeight = height() - space * 2; QRect sliderRect(startX + space, space, sliderWidth , sliderHeight); painter->drawRoundedRect(sliderRect, rectRadius, rectRadius); } else if (buttonStyle == ButtonStyle_CircleIn) { QRect rect(0, 0, width(), height()); int sliderWidth = qMin(rect.width(), rect.height()) - space * 2; QRect sliderRect(startX + space, space, sliderWidth, sliderWidth); painter->drawEllipse(sliderRect); } else if (buttonStyle == ButtonStyle_CircleOut) { int sliderWidth = this->height(); QRect sliderRect(startX, 0, sliderWidth, sliderWidth); painter->drawEllipse(sliderRect); } painter->restore(); }
void ScrollbarThemeGtk::paintThumb(GraphicsContext* context, ScrollbarThemeClient* scrollbar, const IntRect& rect) { GtkWidget* widget = getWidgetForScrollbar(scrollbar); gboolean activateSlider; gtk_widget_style_get(widget, "activate-slider", &activateSlider, NULL); GtkStateType stateType = GTK_STATE_NORMAL; GtkShadowType shadowType = GTK_SHADOW_OUT; if (activateSlider && scrollbar->pressedPart() == ThumbPart) { stateType = GTK_STATE_ACTIVE; shadowType = GTK_SHADOW_IN; } else if (scrollbar->pressedPart() == ThumbPart || scrollbar->hoveredPart() == ThumbPart) stateType = GTK_STATE_PRELIGHT; // The adjustment controls the rendering of the scrollbar thumb. If it's not set // properly the theme may not draw the thumb borders properly. GtkAdjustment* adjustment = gtk_range_get_adjustment(GTK_RANGE(widget)); gtk_adjustment_set_value(adjustment, scrollbar->currentPos()); gtk_adjustment_set_lower(adjustment, 0); gtk_adjustment_set_upper(adjustment, scrollbar->maximum()); GtkOrientation orientation = GTK_ORIENTATION_HORIZONTAL; if (scrollbar->orientation() == VerticalScrollbar) { gtk_adjustment_set_page_size(adjustment, rect.height()); orientation = GTK_ORIENTATION_VERTICAL; } else gtk_adjustment_set_page_size(adjustment, rect.width()); WidgetRenderingContext widgetContext(context, rect); IntRect sliderRect(IntPoint(), rect.size()); widgetContext.gtkPaintSlider(sliderRect, widget, stateType, shadowType, "slider", orientation); }
/*!\reimp */ void QSlider::paintEvent( QPaintEvent * ) { QPainter p( this ); const QRect & sliderR = sliderRect(); const QColorGroup & g = colorGroup(); int mid = thickness()/2; if ( ticks & Above ) mid += style().sliderLength() / 8; if ( ticks & Below ) mid -= style().sliderLength() / 8; if ( orient == Horizontal ) { style().drawSliderGroove(&p, 0, tickOffset, width(), thickness(), g, mid, Horizontal ); // p.fillRect( 0, 0, width(), tickOffset, g.background() ); // p.fillRect( 0, tickOffset + thickness(), // width(), height()/*###*/, g.background() ); erase( 0, 0, width(), tickOffset ); erase( 0, tickOffset + thickness(), width(), height() ); } else { style().drawSliderGroove( &p, tickOffset, 0, thickness(), height(), g, mid, Vertical ); // p.fillRect( 0, 0, tickOffset, height(), g.background() ); // p.fillRect( tickOffset + thickness(), 0, // width()/*###*/, height(), g.background() ); erase( 0, 0, tickOffset, height() ); erase( tickOffset + thickness(), 0, width()/*###*/, height() ); } int interval = tickInt; if ( interval <= 0 ) { interval = lineStep(); if ( positionFromValue( interval ) - positionFromValue( 0 ) < 3 ) interval = pageStep(); } if ( ticks & Above ) drawTicks( &p, g, 0, tickOffset - 2, interval ); if ( ticks & Below ) { int avail = (orient == Horizontal) ? height() : width(); avail -= tickOffset + thickness(); drawTicks( &p, g, tickOffset + thickness() + 1, avail - 2, interval ); } if ( hasFocus() ) { QRect r; if ( orient == Horizontal ) r.setRect( 0, tickOffset-1, width(), thickness()+2 ); else r.setRect( tickOffset-1, 0, thickness()+2, height() ); r = r.intersect( rect() ); if (style() == MotifStyle) style().drawFocusRect(&p, QRect(r.x()+1, r.y()+1, r.width()-2, r.height()-2), g); else style().drawFocusRect(&p, r, g); } paintSlider( &p, g, sliderR ); }
void Amarok::Slider::mousePressEvent(QMouseEvent* e) { QStyleOptionSlider option; initStyleOption(&option); QRect sliderRect(style()->subControlRect(QStyle::CC_Slider, &option, QStyle::SC_SliderHandle, this)); m_sliding = true; m_prevValue = QSlider::value(); if (!sliderRect.contains(e->pos())) mouseMoveEvent(e); }
void QvisOpacitySlider::reallyMoveSlider(int newPos) { QRect oldR = sliderRect(); sliderPos = newPos; QRect newR = sliderRect(); // Since sliderRect isn't virtual, I know that oldR and newR // are the same size. if(oldR.left() < newR.left()) oldR.setRight(qMin(oldR.right(), newR.left())); else oldR.setLeft(qMax(oldR.left(), newR.right())); // If we're moving the slider, we have to update the text. int pmw = imageWidth(); QRegion newTextR(pmw, 0, width() - pmw, height()); update(QRegion(oldR) + QRegion(newR) + newTextR); }
void QSlider::reallyMoveSlider( int newPos ) { QRect oldR = sliderRect(); sliderPos = newPos; QRect newR = sliderRect(); //since sliderRect isn't virtual, I know that oldR and newR // are the same size. if ( orient == Horizontal ) { if ( oldR.left() < newR.left() ) oldR.setRight( QMIN ( oldR.right(), newR.left())); else //oldR.right() >= newR.right() oldR.setLeft( QMAX ( oldR.left(), newR.right())); } else { if ( oldR.top() < newR.top() ) oldR.setBottom( QMIN ( oldR.bottom(), newR.top())); else //oldR.bottom() >= newR.bottom() oldR.setTop( QMAX ( oldR.top(), newR.bottom())); } repaint( oldR ); repaint( newR, FALSE ); if ( autoMask() ) updateMask(); }
void QvisOpacitySlider::paintEvent(QPaintEvent *) { QPainter p(this); int mid = thickness()/2 + sliderLength() / 8; // Draw the gradient pixmap. if(gradientImage == 0) createGradientImage(); p.drawImage(0, tickOffset, *gradientImage); // Draw the groove on which the slider slides. drawSliderGroove(&p, 0, tickOffset, imageWidth(), thickness(), mid); // Figure out the interval between the tick marks. int interval = tickInt; if(interval <= 0) { interval = singleStep(); if(positionFromValue(interval) - positionFromValue(0) < 3) interval = pageStep(); } // Draw the tick marks. p.fillRect(0, 0, imageWidth(), tickOffset, palette().brush(QPalette::Background)); p.fillRect(0, tickOffset + thickness(), imageWidth(), height(), palette().brush(QPalette::Background)); drawTicks(&p, palette(), 0, tickOffset - 2, interval); // Draw the slider paintSlider(&p, palette(), sliderRect()); // Draw the value text. paintValueText(&p, palette(), imageWidth(), height()); // If this widget has focus, draw the focus rectangle. if(hasFocus()) { QStyleOptionFocusRect so; so.initFrom(this); style()->drawPrimitive(QStyle::PE_FrameFocusRect, &so, &p); } }
void QvisOpacitySlider::mousePressEvent(QMouseEvent *e) { resetState(); sliderStartVal = sliderVal; QRect r = sliderRect(); if(e->button() == Qt::RightButton) { return; } else if(r.contains(e->pos())) { state = Dragging; clickOffset = (int)(e->pos().x() - sliderPos); // emit sliderPressed(); } else if(e->button() == Qt::MidButton) { int pos = e->pos().x(); moveSlider(pos - sliderLength() / 2); state = Dragging; clickOffset = sliderLength() / 2; } else if(e->pos().x() < r.left()) { state = TimingDown; subtractPage(); if(!timer) timer = new QTimer(this); connect( timer, SIGNAL(timeout()), SLOT(repeatTimeout())); timer->setSingleShot(true); timer->start(thresholdTime); } else if(e->pos().x() > r.right()) { state = TimingUp; addPage(); if(!timer) timer = new QTimer(this); connect(timer, SIGNAL(timeout()), SLOT(repeatTimeout())); timer->setSingleShot(true); timer->start(thresholdTime); } }
/*! Reimplementation of QWidget::updateMask(). Draws the mask of the slider when transparency is required. \sa QWidget::setAutoMask() */ void QSlider::updateMask() { QBitmap bm( size() ); bm.fill( color0 ); { QPainter p( &bm, this ); QRect sliderR = sliderRect(); QColorGroup g(color1, color1, color1, color1, color1, color1, color1, color1, color0); int mid = tickOffset + thickness()/2; if ( ticks & Above ) mid += style().sliderLength() / 8; if ( ticks & Below ) mid -= style().sliderLength() / 8; if ( orient == Horizontal ) { style().drawSliderGrooveMask(&p, 0, tickOffset, width(), thickness(), mid, Horizontal ); } else { style().drawSliderGrooveMask( &p, tickOffset, 0, thickness(), height(), mid, Vertical ); } style().drawSliderMask( &p, sliderR.x(), sliderR.y(), sliderR.width(), sliderR.height(), orient, ticks & Above, ticks & Below ); int interval = tickInt; if ( interval <= 0 ) { interval = lineStep(); if ( positionFromValue( interval ) - positionFromValue( 0 ) < 3 ) interval = pageStep(); } if ( ticks & Above ) drawTicks( &p, g, 0, tickOffset - 2, interval ); if ( ticks & Below ) { int avail = (orient == Horizontal) ? height() : width(); avail -= tickOffset + thickness(); drawTicks( &p, g, tickOffset + thickness() + 1, avail - 2, interval ); } } setMask( bm ); }
void Amarok::Slider::slideEvent(QMouseEvent* e) { QStyleOptionSlider option; initStyleOption(&option); QRect sliderRect(style()->subControlRect(QStyle::CC_Slider, &option, QStyle::SC_SliderHandle, this)); QSlider::setValue( orientation() == Qt::Horizontal ? ((QApplication::layoutDirection() == Qt::RightToLeft) ? QStyle::sliderValueFromPosition( minimum(), maximum(), width() - (e->pos().x() - sliderRect.width() / 2), width() + sliderRect.width(), true) : QStyle::sliderValueFromPosition( minimum(), maximum(), e->pos().x() - sliderRect.width() / 2, width() - sliderRect.width())) : QStyle::sliderValueFromPosition( minimum(), maximum(), e->pos().y() - sliderRect.height() / 2, height() - sliderRect.height())); }
/*!\reimp */ void QSlider::mousePressEvent( QMouseEvent *e ) { resetState(); sliderStartVal = sliderVal; QRect r = sliderRect(); if ( e->button() == RightButton ) { return; } else if ( r.contains( e->pos() ) ) { state = Dragging; clickOffset = (QCOORD)( goodPart( e->pos() ) - sliderPos ); emit sliderPressed(); } else if ( e->button() == MidButton || (funnyWindowsStyle && style() == WindowsStyle) ) { int pos = goodPart( e->pos() ); moveSlider( pos - slideLength() / 2 ); state = Dragging; clickOffset = slideLength() / 2; } else if ( orient == Horizontal && e->pos().x() < r.left() //### goodPart || orient == Vertical && e->pos().y() < r.top() ) { state = TimingDown; subtractPage(); if ( !timer ) timer = new QTimer( this ); connect( timer, SIGNAL(timeout()), SLOT(repeatTimeout()) ); timer->start( thresholdTime, TRUE ); } else if ( orient == Horizontal && e->pos().x() > r.right() //### goodPart || orient == Vertical && e->pos().y() > r.bottom() ) { state = TimingUp; addPage(); if ( !timer ) timer = new QTimer( this ); connect( timer, SIGNAL(timeout()), SLOT(repeatTimeout()) ); timer->start( thresholdTime, TRUE ); } }