コード例 #1
0
ファイル: tabbar.cpp プロジェクト: VengefulVeggie/Miam-Player
void TabBar::paintRoundedTabs(QStylePainter &p, int dist)
{
	/// TODO: minor highlight bug when mouse goes on another tab without click
	// Draw all tabs before the selected tab
	QList<int> tabs;
	for (int i = 0; i < count(); i++)
		if (currentIndex() != i) tabs.append(i);
	tabs.append(currentIndex());

	for (int idx = 0; idx < count(); idx++) {
		int i = tabs.at(idx);
		QStyleOptionTab o;
		initStyleOption(&o, i);

		// Background color
		if (i != currentIndex()) {
			o.rect.adjust(0, 2, 0, 0);
		} else if (i == count()) {
			o.rect.adjust(2, 2, -4, 0);
		}

		/// Adjust parameters to tighten tabs
		//o.rect.adjust(-dist / 2, 0, dist / 2, 0);

		// Rounded frame tab
		QPainterPath ppLeft, ppRight;
		ppLeft.moveTo(o.rect.x() + dist * 0, o.rect.y() + o.rect.height());
		ppLeft.cubicTo(o.rect.x() + dist * 1, o.rect.y() + o.rect.height(),
					o.rect.x() + dist * 1, o.rect.y() + 1,
					o.rect.x() + dist * 2, o.rect.y() + 1);
		QPainterPath ppLeftCurve(ppLeft);
		// Add another point to be able to fill the path afterwards
		ppLeft.lineTo(o.rect.x() + dist * 2, o.rect.y() + o.rect.height());

		QLine topHozLine(o.rect.x() + dist * 2, o.rect.y(),
						 o.rect.x() + o.rect.width() - dist * 1, o.rect.y());

		ppRight.moveTo(o.rect.x() + o.rect.width() - dist * 1, o.rect.y() + 1);
		ppRight.cubicTo(o.rect.x() + o.rect.width() - dist * 0, o.rect.y() + 1,
					o.rect.x() + o.rect.width() - dist * 0, o.rect.y() + o.rect.height(),
					o.rect.x() + o.rect.width() + dist * 1, o.rect.y() + o.rect.height());
		QPainterPath ppRightCurve(ppRight);
		// Like first curve
		ppRight.lineTo(o.rect.x() + o.rect.width() - dist * 1, o.rect.y() + o.rect.height());

		p.save();
		if (o.state.testFlag(QStyle::State_MouseOver)) {
			p.setPen(o.palette.highlight().color());
		} else {
			p.setPen(o.palette.mid().color());
		}
		QRect midRect(topHozLine.p1(), QPoint(topHozLine.p2().x(), topHozLine.p2().y() + o.rect.height()));
		if (i == currentIndex()) {
			p.fillPath(ppLeft, o.palette.base());
			p.fillRect(midRect, o.palette.base());
			p.fillPath(ppRight, o.palette.base());
		} else if (o.state.testFlag(QStyle::State_MouseOver)) {
			p.fillPath(ppLeft, o.palette.highlight().color().lighter());
			p.fillRect(midRect, o.palette.highlight().color().lighter());
			p.fillPath(ppRight, o.palette.highlight().color().lighter());
		} else {
			p.fillPath(ppLeft, o.palette.window());
			p.fillRect(midRect, o.palette.window());
			p.fillPath(ppRight, o.palette.window());
		}
		p.setRenderHint(QPainter::Antialiasing, true);
		p.drawPath(ppLeftCurve);
		p.drawPath(ppRightCurve);
		p.setRenderHint(QPainter::Antialiasing, false);
		p.drawLine(topHozLine);

		p.restore();

		/// DEBUG
		//p.drawRect(o.rect);

		// Icon
		QRect r = tabRect(i);
		r.setHeight(fontMetrics().ascent());
		r.translate(3 + dist * 1.25, (height() - r.height()) / 2);
		r.setWidth(r.height() / 2);
		p.setRenderHint(QPainter::SmoothPixmapTransform);
		o.icon.paint(&p, r, Qt::AlignLeft | Qt::AlignVCenter);

		// Playlist name
		if (i == currentIndex()) {
			p.setPen(o.palette.windowText().color());
		} else if (o.state.testFlag(QStyle::State_MouseOver)) {
			p.setPen(o.palette.windowText().color());
		} else {
			p.setPen(o.palette.mid().color());
		}
		QRect rText(r.x() + r.width() + 5, this->rect().y(),
					o.rect.width() - (r.width() + 5), this->height() - 2);
		p.drawText(rText, Qt::AlignLeft | Qt::AlignVCenter, o.text);
	}
}
コード例 #2
0
ファイル: SvgHandler.cpp プロジェクト: phalgun/amarok-nepomuk
// Experimental, using a mockup from Nuno Pinheiro (new_slider_nuno)
void SvgHandler::paintCustomSlider( QPainter *p, QStyleOptionSlider *slider, qreal percentage, bool paintMoodbar )
{
    int sliderHeight = slider->rect.height() - 6;
    const bool inverse = ( slider->orientation == Qt::Vertical ) ? slider->upsideDown :
                         ( (slider->direction == Qt::RightToLeft) != slider->upsideDown );
    QRect knob = sliderKnobRect( slider->rect, percentage, inverse );
    QPoint pt = slider->rect.topLeft() + QPoint( 0, 2 );

    //debug() << "rel: " << knobRelPos << ", width: " << width << ", height:" << height << ", %: " << percentage;

    //if we should paint moodbar, paint this as the bottom layer
    bool moodbarPainted = false;
    if ( paintMoodbar )
    {
        Meta::TrackPtr currentTrack = The::engineController()->currentTrack();
        if ( currentTrack )
        {
            if( The::moodbarManager()->hasMoodbar( currentTrack ) )
            {
                QPixmap moodbar = The::moodbarManager()->getMoodbar( currentTrack, slider->rect.width() - sliderHeight, sliderHeight, inverse );
                p->drawPixmap( pt, renderSvg( "moodbar_end_left", sliderHeight / 2, sliderHeight, "moodbar_end_left" ) );

                pt.rx() += sliderHeight / 2;
                p->drawPixmap( pt, moodbar );

                pt.rx() += slider->rect.width() - sliderHeight;
                p->drawPixmap( pt, renderSvg( "moodbar_end_right", sliderHeight / 2, sliderHeight, "moodbar_end_right" ) );

                moodbarPainted = true;
            }
        }
    }

    if( !moodbarPainted )
    {
        // Draw the slider background in 3 parts

        p->drawPixmap( pt, renderSvg( "progress_slider_left", sliderHeight, sliderHeight, "progress_slider_left" ) );

        pt.rx() += sliderHeight;
        QRect midRect(pt, QSize(slider->rect.width() - sliderHeight * 2, sliderHeight) );
        p->drawTiledPixmap( midRect, renderSvg( "progress_slider_mid", 32, sliderHeight, "progress_slider_mid" ) );

        pt = midRect.topRight() + QPoint( 1, 0 );
        p->drawPixmap( pt, renderSvg( "progress_slider_right", sliderHeight, sliderHeight, "progress_slider_right" ) );

        //draw the played background.

        int playedBarHeight = sliderHeight - 6;

        int sizeOfLeftPlayed = qBound( 0, inverse ? slider->rect.right() - knob.right() + 2 :
                                                    knob.x() - 2, playedBarHeight );

        if( sizeOfLeftPlayed > 0 )
        {
            QPoint tl, br;
            if ( inverse )
            {
                tl = knob.topRight() + QPoint( -5, 5 ); // 5px x padding to avoid a "gap" between it and the top and bottom of the round knob.
                br = slider->rect.topRight() + QPoint( -3, 5 + playedBarHeight - 1 );
                QPixmap rightEnd = renderSvg( "progress_slider_played_right", playedBarHeight, playedBarHeight, "progress_slider_played_right" );
                p->drawPixmap( br.x() - rightEnd.width() + 1, tl.y(), rightEnd, qMax(0, rightEnd.width() - (sizeOfLeftPlayed + 3)), 0, sizeOfLeftPlayed + 3, playedBarHeight );
                br.rx() -= playedBarHeight;
            }
            else
            {
                tl = slider->rect.topLeft() + QPoint( 3, 5 );
                br = QPoint( knob.x() + 5, tl.y() + playedBarHeight - 1 );
                QPixmap leftEnd = renderSvg( "progress_slider_played_left", playedBarHeight, playedBarHeight, "progress_slider_played_left" );
                p->drawPixmap( tl.x(), tl.y(), leftEnd, 0, 0, sizeOfLeftPlayed + 3, playedBarHeight );
                tl.rx() += playedBarHeight;
            }
            if ( sizeOfLeftPlayed == playedBarHeight )
                p->drawTiledPixmap( QRect(tl, br), renderSvg( "progress_slider_played_mid", 32, playedBarHeight, "progress_slider_played_mid" ) );

        }
    }

    if ( slider->state & QStyle::State_Enabled )
    {   // Draw the knob (handle)
        const char *string = ( slider->activeSubControls & QStyle::SC_SliderHandle ) ?
                             "slider_knob_200911_active" : "slider_knob_200911";
        p->drawPixmap( knob.topLeft(), renderSvg( string, knob.width(), knob.height(), string ) );
    }
}