From e43e45cd761c744454d0388638c7135636280246 Mon Sep 17 00:00:00 2001 From: Casey Link Date: Fri, 26 Aug 2011 18:43:35 -0500 Subject: [PATCH] Introduce StyleHelper, HeaderWidget and ComboBox These are customized widgets for tomahawk that make headers pretty. --- src/libtomahawk/CMakeLists.txt | 6 ++ src/libtomahawk/utils/stylehelper.cpp | 63 +++++++++++++++++++ src/libtomahawk/utils/stylehelper.h | 44 +++++++++++++ src/libtomahawk/widgets/HeaderLabel.cpp | 24 +------ src/libtomahawk/widgets/HeaderWidget.cpp | 42 +++++++++++++ src/libtomahawk/widgets/HeaderWidget.h | 45 +++++++++++++ src/libtomahawk/widgets/combobox.cpp | 80 ++++++++++++++++++++++++ src/libtomahawk/widgets/combobox.h | 44 +++++++++++++ 8 files changed, 327 insertions(+), 21 deletions(-) create mode 100644 src/libtomahawk/utils/stylehelper.cpp create mode 100644 src/libtomahawk/utils/stylehelper.h create mode 100644 src/libtomahawk/widgets/HeaderWidget.cpp create mode 100644 src/libtomahawk/widgets/HeaderWidget.h create mode 100644 src/libtomahawk/widgets/combobox.cpp create mode 100644 src/libtomahawk/widgets/combobox.h diff --git a/src/libtomahawk/CMakeLists.txt b/src/libtomahawk/CMakeLists.txt index 869e03226..bce5067d7 100644 --- a/src/libtomahawk/CMakeLists.txt +++ b/src/libtomahawk/CMakeLists.txt @@ -174,6 +174,7 @@ set( libSources utils/spotifyparser.cpp utils/rdioparser.cpp utils/shortenedlinkparser.cpp + utils/stylehelper.cpp widgets/newplaylistwidget.cpp widgets/searchwidget.cpp @@ -184,6 +185,8 @@ set( libSources widgets/whatshotwidget.cpp widgets/overlaywidget.cpp widgets/HeaderLabel.cpp + widgets/HeaderWidget.cpp + widgets/combobox.cpp widgets/SocialPlaylistWidget.cpp widgets/infowidgets/sourceinfowidget.cpp widgets/infowidgets/ArtistInfoWidget.cpp @@ -355,6 +358,7 @@ set( libHeaders utils/spotifyparser.h utils/rdioparser.h utils/shortenedlinkparser.h + utils/stylehelper.h widgets/newplaylistwidget.h widgets/searchwidget.h @@ -365,6 +369,8 @@ set( libHeaders widgets/welcomeplaylistmodel.h widgets/overlaywidget.h widgets/HeaderLabel.h + widgets/HeaderWidget.h + widgets/combobox.h widgets/SocialPlaylistWidget.h widgets/infowidgets/sourceinfowidget.h widgets/infowidgets/ArtistInfoWidget.h diff --git a/src/libtomahawk/utils/stylehelper.cpp b/src/libtomahawk/utils/stylehelper.cpp new file mode 100644 index 000000000..2681facc7 --- /dev/null +++ b/src/libtomahawk/utils/stylehelper.cpp @@ -0,0 +1,63 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2011, Casey Link + * + * Tomahawk is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Tomahawk is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Tomahawk. If not, see . + */ + +#include "stylehelper.h" + +#include + + +QColor StyleHelper::headerUpperColor() +{ + return QColor( 80, 80, 80 ); +} + +QColor StyleHelper::headerLowerColor() +{ + return QColor( 72, 72, 72 ); +} + +QColor StyleHelper::headerHighlightColor() +{ + return QColor( "#333" ); +} + +void StyleHelper::horizontalHeader(QPainter *painter, const QRect &r) +{ + QRect upperHalf( 0, 0, r.width(), r.height() / 2 ); + QRect lowerHalf( 0, upperHalf.height(), r.width(), r.height() ); + painter->fillRect( upperHalf, StyleHelper::headerUpperColor() ); + painter->fillRect( lowerHalf, StyleHelper::headerLowerColor() ); + + { + QColor lineColor( 100, 100, 100 ); + QLine line( 0, 0, r.width(), 0 ); + painter->setPen( lineColor ); + painter->drawLine( line ); + } + { + QColor lineColor( 30, 30, 30 ); + QLine line( 0, r.height() - 1, r.width(), r.height() - 1 ); + painter->setPen( lineColor ); + painter->drawLine( line ); + } +} + +QColor StyleHelper::headerTextColor() +{ + return Qt::white; +} diff --git a/src/libtomahawk/utils/stylehelper.h b/src/libtomahawk/utils/stylehelper.h new file mode 100644 index 000000000..7881f5974 --- /dev/null +++ b/src/libtomahawk/utils/stylehelper.h @@ -0,0 +1,44 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2011, Casey Link + * + * Tomahawk is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Tomahawk is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Tomahawk. If not, see . + */ + +#ifndef STYLEHELPER_H +#define STYLEHELPER_H + + +#include +#include + +class QPalette; +class QPainter; + +class StyleHelper +{ +public: + + static QColor headerUpperColor(); + static QColor headerLowerColor(); + static QColor headerTextColor(); + static QColor headerHighlightColor(); + + static void horizontalHeader(QPainter *painter, const QRect &rect); +private: + static QColor m_baseColor; + static QColor m_requestedBaseColor; +}; + +#endif // STYLEHELPER_H diff --git a/src/libtomahawk/widgets/HeaderLabel.cpp b/src/libtomahawk/widgets/HeaderLabel.cpp index 055f2001f..6b86b04e5 100644 --- a/src/libtomahawk/widgets/HeaderLabel.cpp +++ b/src/libtomahawk/widgets/HeaderLabel.cpp @@ -21,6 +21,7 @@ #include #include "utils/logger.h" +#include "utils/stylehelper.h" #define FONT_SIZE 16 @@ -55,29 +56,10 @@ HeaderLabel::paintEvent( QPaintEvent* /* event */ ) { QPainter p( this ); QRect r = contentsRect(); - -// p.setRenderHint( QPainter::Antialiasing ); - - QRect upperHalf( 0, 0, r.width(), r.height() / 2 ); - QRect lowerHalf( 0, upperHalf.height(), r.width(), r.height() ); - p.fillRect( upperHalf, QColor( 80, 80, 80 ) ); - p.fillRect( lowerHalf, QColor( 72, 72, 72 ) ); - - { - QColor lineColor( 100, 100, 100 ); - QLine line( 0, 0, r.width(), 0 ); - p.setPen( lineColor ); - p.drawLine( line ); - } - { - QColor lineColor( 30, 30, 30 ); - QLine line( 0, r.height() - 1, r.width(), r.height() - 1 ); - p.setPen( lineColor ); - p.drawLine( line ); - } + StyleHelper::horizontalHeader(&p, r); QTextOption to( Qt::AlignVCenter ); r.adjust( 8, 0, -8, 0 ); - p.setPen( Qt::white ); + p.setPen( StyleHelper::headerTextColor() ); p.drawText( r, text(), to ); } diff --git a/src/libtomahawk/widgets/HeaderWidget.cpp b/src/libtomahawk/widgets/HeaderWidget.cpp new file mode 100644 index 000000000..94dd03ca4 --- /dev/null +++ b/src/libtomahawk/widgets/HeaderWidget.cpp @@ -0,0 +1,42 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2011, Casey Link + * + * Tomahawk is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Tomahawk is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Tomahawk. If not, see . + */ + +#include "HeaderWidget.h" + + +#include "utils/stylehelper.h" + +#include +#include +#include + +HeaderWidget::HeaderWidget(QWidget *parent) : QWidget(parent) +{ +} + +HeaderWidget::~HeaderWidget() +{ +} + +void HeaderWidget::paintEvent(QPaintEvent *e) +{ + QStylePainter p(this); + QRect r = e->rect(); + + StyleHelper::horizontalHeader(&p, r); +} diff --git a/src/libtomahawk/widgets/HeaderWidget.h b/src/libtomahawk/widgets/HeaderWidget.h new file mode 100644 index 000000000..bdaef5060 --- /dev/null +++ b/src/libtomahawk/widgets/HeaderWidget.h @@ -0,0 +1,45 @@ + +/* === This file is part of Tomahawk Player - === + * + * Copyright 2011, Casey Link + * + * Tomahawk is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Tomahawk is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Tomahawk. If not, see . + */ + +#ifndef HEADERWIDGET_H +#define HEADERWIDGET_H + +#include +#include + +#include "dllmacro.h" + +class DLLEXPORT HeaderWidget : public QWidget +{ +Q_OBJECT + +public: + HeaderWidget(QWidget *parent = 0); + virtual ~HeaderWidget(); + + virtual void paintEvent(QPaintEvent *); + + +private: + + +}; + + +#endif diff --git a/src/libtomahawk/widgets/combobox.cpp b/src/libtomahawk/widgets/combobox.cpp new file mode 100644 index 000000000..29be3bac2 --- /dev/null +++ b/src/libtomahawk/widgets/combobox.cpp @@ -0,0 +1,80 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2011, Casey Link + * + * Tomahawk is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Tomahawk is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Tomahawk. If not, see . + */ + +#include "combobox.h" + + +#include "utils/stylehelper.h" + +#include +#include +#include +#include + +ComboBox::ComboBox(QWidget *parent) : QComboBox(parent) +{ +} + +ComboBox::~ComboBox() +{ +} + +void ComboBox::paintEvent(QPaintEvent *) +{ + QStylePainter p(this); + p.setPen(palette().color(QPalette::Text)); + QStyleOptionComboBox cb; + initStyleOption(&cb); + QRect r = cb.rect; + + + StyleHelper::horizontalHeader(&p, r); + + if( cb.state & QStyle::State_MouseOver ) { + QRect highlightRect(r); + QSize shrink(3,4); + QSize hS(highlightRect.size()); + hS -= shrink; + highlightRect.setSize(hS); + highlightRect.translate(0,2); + p.save(); + p.setRenderHint(QPainter::Antialiasing); + p.setBrush( StyleHelper::headerHighlightColor() ); + p.drawRoundedRect(highlightRect, 10.0, 10.0); + p.restore(); + } + + QTextOption to( Qt::AlignVCenter ); + r.adjust( 8, 0, -8, 0 ); + p.setPen( Qt::white ); + p.setBrush( StyleHelper::headerTextColor() ); + p.drawText( r, cb.currentText, to ); + + + bool reverse = cb.direction == Qt::RightToLeft; + int menuButtonWidth = 12; + int left = !reverse ? r.right() - menuButtonWidth : r.left(); + int right = !reverse ? r.right() : r.left() + menuButtonWidth; + QRect arrowRect((left + right) / 2 + (reverse ? 6 : -6), r.center().y() - 3, 9, 9); + + QStyleOption arrowOpt = cb; + arrowOpt.rect = arrowRect; + //p.drawPrimitive(QStyle::PE_IndicatorArrowDown, arrowOpt); + //Utils::StyleHelper::drawArrow(QStyle::PE_IndicatorArrowDown, &p, &arrowOpt); + +} diff --git a/src/libtomahawk/widgets/combobox.h b/src/libtomahawk/widgets/combobox.h new file mode 100644 index 000000000..df701ab95 --- /dev/null +++ b/src/libtomahawk/widgets/combobox.h @@ -0,0 +1,44 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2011, Casey Link + * + * Tomahawk is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Tomahawk is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Tomahawk. If not, see . + */ + +#ifndef COMBOBOX_H +#define COMBOBOX_H + +#include +#include + +#include "dllmacro.h" + +class DLLEXPORT ComboBox : public QComboBox +{ +Q_OBJECT + +public: + ComboBox(QWidget *parent = 0); + virtual ~ComboBox(); + + virtual void paintEvent(QPaintEvent *); + + +private: + + +}; + + +#endif