1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-05 13:47:26 +02:00

* Cleaned up StyleHelper and use it in ContextWidget.

This commit is contained in:
Christian Muehlhaeuser
2011-09-06 05:14:45 +02:00
parent 23ecf1264f
commit 00f2195dd2
4 changed files with 77 additions and 56 deletions

View File

@@ -377,7 +377,6 @@ set( libHeaders
utils/spotifyparser.h utils/spotifyparser.h
utils/rdioparser.h utils/rdioparser.h
utils/shortenedlinkparser.h utils/shortenedlinkparser.h
utils/stylehelper.h
widgets/querylabel.h widgets/querylabel.h
widgets/animatedcounterlabel.h widgets/animatedcounterlabel.h

View File

@@ -92,7 +92,7 @@ ContextWidget::ContextWidget( QWidget* parent )
setFixedHeight( m_minHeight ); setFixedHeight( m_minHeight );
QPalette pal = palette(); QPalette pal = palette();
pal.setBrush( QPalette::Window, QColor( 0x70, 0x70, 0x70 ) ); pal.setBrush( QPalette::Window, StyleHelper::headerLowerColor() );
setPalette( pal ); setPalette( pal );
connect( ui->toggleButton, SIGNAL( clicked() ), SLOT( toggleSize() ) ); connect( ui->toggleButton, SIGNAL( clicked() ), SLOT( toggleSize() ) );

View File

@@ -22,22 +22,30 @@
#include <QPixmapCache> #include <QPixmapCache>
#include <QApplication> #include <QApplication>
QColor StyleHelper::headerUpperColor()
QColor
StyleHelper::headerUpperColor()
{ {
return QColor( 80, 80, 80 ); return QColor( 80, 80, 80 );
} }
QColor StyleHelper::headerLowerColor()
QColor
StyleHelper::headerLowerColor()
{ {
return QColor( 72, 72, 72 ); return QColor( 72, 72, 72 );
} }
QColor StyleHelper::headerHighlightColor()
QColor
StyleHelper::headerHighlightColor()
{ {
return QColor( "#333" ); return QColor( "#333" );
} }
void StyleHelper::horizontalHeader(QPainter *painter, const QRect &r)
void
StyleHelper::horizontalHeader( QPainter* painter, const QRect& r )
{ {
QRect upperHalf( 0, 0, r.width(), r.height() / 2 ); QRect upperHalf( 0, 0, r.width(), r.height() / 2 );
QRect lowerHalf( 0, upperHalf.height(), r.width(), r.height() ); QRect lowerHalf( 0, upperHalf.height(), r.width(), r.height() );
@@ -58,7 +66,9 @@ void StyleHelper::horizontalHeader(QPainter *painter, const QRect &r)
} }
} }
QColor StyleHelper::headerTextColor()
QColor
StyleHelper::headerTextColor()
{ {
return Qt::white; return Qt::white;
} }
@@ -71,40 +81,46 @@ QColor StyleHelper::headerTextColor()
* Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). * Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
* Contact: Nokia Corporation (qt-info@nokia.com) * Contact: Nokia Corporation (qt-info@nokia.com)
*/ */
void StyleHelper::drawArrow(QStyle::PrimitiveElement element, QPainter *p, const QStyleOption *opt) void StyleHelper::drawArrow( QStyle::PrimitiveElement element, QPainter* p, const QStyleOption* opt )
{ {
if ( opt->rect.width() <= 1 || opt->rect.height() <= 1 )
if (opt->rect.width() <= 1 || opt->rect.height() <= 1)
return; return;
QRect r = opt->rect; QRect r = opt->rect;
int size = qMin(r.height(), r.width()); int size = qMin( r.height(), r.width() );
QPixmap pixmap; QPixmap pixmap;
QString pixmapName; QString pixmapName;
pixmapName.sprintf("arrow-%s-%d-%d-%d-%lld",
"$qt_ia", pixmapName.sprintf( "arrow-%s-%d-%d-%d-%lld", "$qt_ia", uint(opt->state), element, size, opt->palette.cacheKey() );
uint(opt->state), element, if ( !QPixmapCache::find( pixmapName, pixmap) )
size, opt->palette.cacheKey()); {
if (!QPixmapCache::find(pixmapName, pixmap)) { int border = size / 5;
int border = size/5; int sqsize = 2 * ( size / 2 );
int sqsize = 2*(size/2);
QImage image(sqsize, sqsize, QImage::Format_ARGB32); QImage image( sqsize, sqsize, QImage::Format_ARGB32 );
image.fill(0); image.fill( 0 );
QPainter imagePainter(&image); QPainter imagePainter( &image );
imagePainter.setRenderHint(QPainter::Antialiasing, true); imagePainter.setRenderHint( QPainter::Antialiasing, true );
QPolygon a; QPolygon a;
switch (element) {
switch ( element )
{
case QStyle::PE_IndicatorArrowUp: case QStyle::PE_IndicatorArrowUp:
a.setPoints(3, border, sqsize/2, sqsize/2, border, sqsize - border, sqsize/2); a.setPoints( 3, border, sqsize / 2, sqsize / 2, border, sqsize - border, sqsize / 2 );
break; break;
case QStyle::PE_IndicatorArrowDown: case QStyle::PE_IndicatorArrowDown:
a.setPoints(3, border, sqsize/2, sqsize/2, sqsize - border, sqsize - border, sqsize/2); a.setPoints( 3, border, sqsize / 2, sqsize / 2, sqsize - border, sqsize - border, sqsize / 2 );
break; break;
case QStyle::PE_IndicatorArrowRight: case QStyle::PE_IndicatorArrowRight:
a.setPoints(3, sqsize - border, sqsize/2, sqsize/2, border, sqsize/2, sqsize - border); a.setPoints( 3, sqsize - border, sqsize / 2, sqsize / 2, border, sqsize / 2, sqsize - border );
break; break;
case QStyle::PE_IndicatorArrowLeft: case QStyle::PE_IndicatorArrowLeft:
a.setPoints(3, border, sqsize/2, sqsize/2, border, sqsize/2, sqsize - border); a.setPoints( 3, border, sqsize / 2, sqsize / 2, border, sqsize / 2, sqsize - border );
break; break;
default: default:
break; break;
} }
@@ -112,40 +128,46 @@ void StyleHelper::drawArrow(QStyle::PrimitiveElement element, QPainter *p, const
int bsx = 0; int bsx = 0;
int bsy = 0; int bsy = 0;
if (opt->state & QStyle::State_Sunken) { if ( opt->state & QStyle::State_Sunken )
bsx = qApp->style()->pixelMetric(QStyle::PM_ButtonShiftHorizontal); {
bsy = qApp->style()->pixelMetric(QStyle::PM_ButtonShiftVertical); bsx = qApp->style()->pixelMetric( QStyle::PM_ButtonShiftHorizontal );
bsy = qApp->style()->pixelMetric( QStyle::PM_ButtonShiftVertical );
} }
QRect bounds = a.boundingRect(); QRect bounds = a.boundingRect();
int sx = sqsize / 2 - bounds.center().x() - 1; int sx = sqsize / 2 - bounds.center().x() - 1;
int sy = sqsize / 2 - bounds.center().y() - 1; int sy = sqsize / 2 - bounds.center().y() - 1;
imagePainter.translate(sx + bsx, sy + bsy); imagePainter.translate( sx + bsx, sy + bsy );
imagePainter.setPen(opt->palette.buttonText().color()); imagePainter.setPen( opt->palette.buttonText().color() );
imagePainter.setBrush(opt->palette.buttonText()); imagePainter.setBrush( opt->palette.buttonText() );
if (!(opt->state & QStyle::State_Enabled)) { if ( !( opt->state & QStyle::State_Enabled ) )
QColor foreGround(150, 150, 150, 150); {
imagePainter.setBrush(opt->palette.mid().color()); QColor foreGround( 150, 150, 150, 150 );
imagePainter.setPen(opt->palette.mid().color()); imagePainter.setBrush( opt->palette.mid().color() );
} else { imagePainter.setPen( opt->palette.mid().color() );
QColor shadow(0, 0, 0, 100); }
imagePainter.translate(0, 1); else
imagePainter.setPen(shadow); {
imagePainter.setBrush(shadow); QColor shadow( 0, 0, 0, 100 );
QColor foreGround(255, 255, 255, 210); imagePainter.translate( 0, 1 );
imagePainter.drawPolygon(a); imagePainter.setPen( shadow );
imagePainter.translate(0, -1); imagePainter.setBrush( shadow );
imagePainter.setPen(foreGround); QColor foreGround( 255, 255, 255, 210 );
imagePainter.setBrush(foreGround); imagePainter.drawPolygon( a );
imagePainter.translate( 0, -1 );
imagePainter.setPen( foreGround );
imagePainter.setBrush( foreGround );
} }
imagePainter.drawPolygon(a); imagePainter.drawPolygon( a );
imagePainter.end(); imagePainter.end();
pixmap = QPixmap::fromImage(image);
QPixmapCache::insert(pixmapName, pixmap); pixmap = QPixmap::fromImage( image );
QPixmapCache::insert( pixmapName, pixmap );
} }
int xOffset = r.x() + (r.width() - size)/2;
int yOffset = r.y() + (r.height() - size)/2; int xOffset = r.x() + ( r.width() - size ) / 2;
p->drawPixmap(xOffset, yOffset, pixmap); int yOffset = r.y() + ( r.height() - size ) / 2;
p->drawPixmap( xOffset, yOffset, pixmap );
} }

View File

@@ -19,7 +19,6 @@
#ifndef STYLEHELPER_H #ifndef STYLEHELPER_H
#define STYLEHELPER_H #define STYLEHELPER_H
#include <QColor> #include <QColor>
#include <QStyle> #include <QStyle>
#include <QStyleOption> #include <QStyleOption>
@@ -55,14 +54,15 @@ public:
/** /**
* Draws a header background on a painter with the specified rectangle * Draws a header background on a painter with the specified rectangle
*/ */
static void horizontalHeader(QPainter *painter, const QRect &rect); static void horizontalHeader( QPainter* painter, const QRect& rect );
/** /**
* Draws a styled arrow that looks good on a Header (from qwindowstyle.cpp) * Draws a styled arrow that looks good on a Header (from qwindowstyle.cpp)
* \copyright { Licensed under the GPL v3+ * \copyright { Licensed under the GPL v3+
* Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). * Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
* Contact: Nokia Corporation (qt-info@nokia.com) } * Contact: Nokia Corporation (qt-info@nokia.com) }
*/ */
static void drawArrow(QStyle::PrimitiveElement, QPainter *painter, const QStyleOption *opt); static void drawArrow( QStyle::PrimitiveElement, QPainter* painter, const QStyleOption* opt );
}; };
#endif // STYLEHELPER_H #endif // STYLEHELPER_H