1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-14 01:54:07 +02:00

Introduce StyleHelper, HeaderWidget and ComboBox

These are customized widgets for tomahawk that make headers pretty.
This commit is contained in:
Casey Link
2011-08-26 18:43:35 -05:00
parent 415d2e8ec7
commit e43e45cd76
8 changed files with 327 additions and 21 deletions

View File

@@ -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

View File

@@ -0,0 +1,63 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
*
* Copyright 2011, Casey Link <unnamedrambler@gmail.com>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#include "stylehelper.h"
#include <QPainter>
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;
}

View File

@@ -0,0 +1,44 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
*
* Copyright 2011, Casey Link <unnamedrambler@gmail.com>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#ifndef STYLEHELPER_H
#define STYLEHELPER_H
#include <QColor>
#include <QStyle>
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

View File

@@ -21,6 +21,7 @@
#include <QPainter>
#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 );
}

View File

@@ -0,0 +1,42 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
*
* Copyright 2011, Casey Link <unnamedrambler@gmail.com>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#include "HeaderWidget.h"
#include "utils/stylehelper.h"
#include <QStyle>
#include <QStylePainter>
#include <QStyleOption>
HeaderWidget::HeaderWidget(QWidget *parent) : QWidget(parent)
{
}
HeaderWidget::~HeaderWidget()
{
}
void HeaderWidget::paintEvent(QPaintEvent *e)
{
QStylePainter p(this);
QRect r = e->rect();
StyleHelper::horizontalHeader(&p, r);
}

View File

@@ -0,0 +1,45 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
*
* Copyright 2011, Casey Link <unnamedrambler@gmail.com>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#ifndef HEADERWIDGET_H
#define HEADERWIDGET_H
#include <QWidget>
#include <QPaintEvent>
#include "dllmacro.h"
class DLLEXPORT HeaderWidget : public QWidget
{
Q_OBJECT
public:
HeaderWidget(QWidget *parent = 0);
virtual ~HeaderWidget();
virtual void paintEvent(QPaintEvent *);
private:
};
#endif

View File

@@ -0,0 +1,80 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
*
* Copyright 2011, Casey Link <unnamedrambler@gmail.com>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#include "combobox.h"
#include "utils/stylehelper.h"
#include <QStyle>
#include <QTextOption>
#include <QStylePainter>
#include <QStyleOptionComboBox>
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);
}

View File

@@ -0,0 +1,44 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
*
* Copyright 2011, Casey Link <unnamedrambler@gmail.com>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#ifndef COMBOBOX_H
#define COMBOBOX_H
#include <QComboBox>
#include <QPaintEvent>
#include "dllmacro.h"
class DLLEXPORT ComboBox : public QComboBox
{
Q_OBJECT
public:
ComboBox(QWidget *parent = 0);
virtual ~ComboBox();
virtual void paintEvent(QPaintEvent *);
private:
};
#endif