mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-16 19:14:06 +02:00
Introduce StyleHelper, HeaderWidget and ComboBox
These are customized widgets for tomahawk that make headers pretty.
This commit is contained in:
@@ -174,6 +174,7 @@ set( libSources
|
|||||||
utils/spotifyparser.cpp
|
utils/spotifyparser.cpp
|
||||||
utils/rdioparser.cpp
|
utils/rdioparser.cpp
|
||||||
utils/shortenedlinkparser.cpp
|
utils/shortenedlinkparser.cpp
|
||||||
|
utils/stylehelper.cpp
|
||||||
|
|
||||||
widgets/newplaylistwidget.cpp
|
widgets/newplaylistwidget.cpp
|
||||||
widgets/searchwidget.cpp
|
widgets/searchwidget.cpp
|
||||||
@@ -184,6 +185,8 @@ set( libSources
|
|||||||
widgets/whatshotwidget.cpp
|
widgets/whatshotwidget.cpp
|
||||||
widgets/overlaywidget.cpp
|
widgets/overlaywidget.cpp
|
||||||
widgets/HeaderLabel.cpp
|
widgets/HeaderLabel.cpp
|
||||||
|
widgets/HeaderWidget.cpp
|
||||||
|
widgets/combobox.cpp
|
||||||
widgets/SocialPlaylistWidget.cpp
|
widgets/SocialPlaylistWidget.cpp
|
||||||
widgets/infowidgets/sourceinfowidget.cpp
|
widgets/infowidgets/sourceinfowidget.cpp
|
||||||
widgets/infowidgets/ArtistInfoWidget.cpp
|
widgets/infowidgets/ArtistInfoWidget.cpp
|
||||||
@@ -355,6 +358,7 @@ set( libHeaders
|
|||||||
utils/spotifyparser.h
|
utils/spotifyparser.h
|
||||||
utils/rdioparser.h
|
utils/rdioparser.h
|
||||||
utils/shortenedlinkparser.h
|
utils/shortenedlinkparser.h
|
||||||
|
utils/stylehelper.h
|
||||||
|
|
||||||
widgets/newplaylistwidget.h
|
widgets/newplaylistwidget.h
|
||||||
widgets/searchwidget.h
|
widgets/searchwidget.h
|
||||||
@@ -365,6 +369,8 @@ set( libHeaders
|
|||||||
widgets/welcomeplaylistmodel.h
|
widgets/welcomeplaylistmodel.h
|
||||||
widgets/overlaywidget.h
|
widgets/overlaywidget.h
|
||||||
widgets/HeaderLabel.h
|
widgets/HeaderLabel.h
|
||||||
|
widgets/HeaderWidget.h
|
||||||
|
widgets/combobox.h
|
||||||
widgets/SocialPlaylistWidget.h
|
widgets/SocialPlaylistWidget.h
|
||||||
widgets/infowidgets/sourceinfowidget.h
|
widgets/infowidgets/sourceinfowidget.h
|
||||||
widgets/infowidgets/ArtistInfoWidget.h
|
widgets/infowidgets/ArtistInfoWidget.h
|
||||||
|
63
src/libtomahawk/utils/stylehelper.cpp
Normal file
63
src/libtomahawk/utils/stylehelper.cpp
Normal 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;
|
||||||
|
}
|
44
src/libtomahawk/utils/stylehelper.h
Normal file
44
src/libtomahawk/utils/stylehelper.h
Normal 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
|
@@ -21,6 +21,7 @@
|
|||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
|
|
||||||
#include "utils/logger.h"
|
#include "utils/logger.h"
|
||||||
|
#include "utils/stylehelper.h"
|
||||||
|
|
||||||
#define FONT_SIZE 16
|
#define FONT_SIZE 16
|
||||||
|
|
||||||
@@ -55,29 +56,10 @@ HeaderLabel::paintEvent( QPaintEvent* /* event */ )
|
|||||||
{
|
{
|
||||||
QPainter p( this );
|
QPainter p( this );
|
||||||
QRect r = contentsRect();
|
QRect r = contentsRect();
|
||||||
|
StyleHelper::horizontalHeader(&p, r);
|
||||||
// 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 );
|
|
||||||
}
|
|
||||||
|
|
||||||
QTextOption to( Qt::AlignVCenter );
|
QTextOption to( Qt::AlignVCenter );
|
||||||
r.adjust( 8, 0, -8, 0 );
|
r.adjust( 8, 0, -8, 0 );
|
||||||
p.setPen( Qt::white );
|
p.setPen( StyleHelper::headerTextColor() );
|
||||||
p.drawText( r, text(), to );
|
p.drawText( r, text(), to );
|
||||||
}
|
}
|
||||||
|
42
src/libtomahawk/widgets/HeaderWidget.cpp
Normal file
42
src/libtomahawk/widgets/HeaderWidget.cpp
Normal 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);
|
||||||
|
}
|
45
src/libtomahawk/widgets/HeaderWidget.h
Normal file
45
src/libtomahawk/widgets/HeaderWidget.h
Normal 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
|
80
src/libtomahawk/widgets/combobox.cpp
Normal file
80
src/libtomahawk/widgets/combobox.cpp
Normal 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);
|
||||||
|
|
||||||
|
}
|
44
src/libtomahawk/widgets/combobox.h
Normal file
44
src/libtomahawk/widgets/combobox.h
Normal 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
|
Reference in New Issue
Block a user