1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-03-24 09:49:42 +01:00

Superclass FlexibleHeader into BasicHeader for a customizable InfoBar.

BasicHeader reproduces InfoBar's look and feel and provides a generic
InfoBar-like page header, easily customized by subclassing.
Also, BasicHeader and FlexibleHeader now set up the UI programmatically
rather than using a .ui file.
This commit is contained in:
Teo Mrnjavac 2012-10-22 09:54:52 +02:00
parent 5c7404946e
commit c435a3c7f8
6 changed files with 254 additions and 389 deletions

View File

@ -118,6 +118,7 @@ set( libGuiSources
utils/WebResultHintChecker.cpp
widgets/AnimatedCounterLabel.cpp
widgets/BasicHeader.cpp
widgets/Breadcrumb.cpp
widgets/BreadcrumbButton.cpp
widgets/CheckDirTree.cpp
@ -324,7 +325,6 @@ set( libUI ${libUI}
widgets/infowidgets/AlbumInfoWidget.ui
widgets/infowidgets/TrackInfoWidget.ui
playlist/QueueView.ui
playlist/PlaylistHeader.ui
filemetadata/MetadataEditor.ui
context/ContextWidget.ui
infobar/InfoBar.ui

View File

@ -1,6 +1,7 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
*
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
* Copyright 2012, Teo Mrnjavac <teo@kde.org>
*
* Tomahawk is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -17,13 +18,14 @@
*/
#include "FlexibleHeader.h"
#include "ui_PlaylistHeader.h"
#include <QBoxLayout>
#include <QLabel>
#include <QPixmap>
#include <QCheckBox>
#include <QPaintEvent>
#include <QPainter>
#include <QRadioButton>
#include "playlist/FlexibleView.h"
#include "ViewManager.h"
@ -36,111 +38,81 @@
using namespace Tomahawk;
QPixmap* FlexibleHeader::s_tiledHeader = 0;
FlexibleHeader::FlexibleHeader( FlexibleView* parent )
: QWidget( parent )
: BasicHeader( parent )
, m_parent( parent )
, ui( new Ui::PlaylistHeader )
{
ui->setupUi( this );
TomahawkUtils::unmarginLayout( layout() );
layout()->setContentsMargins( 8, 4, 8, 4 );
QPalette pal = palette();
pal.setColor( QPalette::Foreground, Qt::white );
ui->captionLabel->setPalette( pal );
ui->descLabel->setPalette( pal );
QFont font = ui->captionLabel->font();
font.setPointSize( TomahawkUtils::defaultFontSize() + 4 );
font.setBold( true );
ui->captionLabel->setFont( font );
ui->captionLabel->setElideMode( Qt::ElideRight );
font.setPointSize( TomahawkUtils::defaultFontSize() + 1 );
font.setBold( false );
ui->descLabel->setFont( font );
ui->captionLabel->setMargin( 2 );
ui->descLabel->setMargin( 1 );
ui->radioNormal->setFocusPolicy( Qt::NoFocus );
ui->radioDetailed->setFocusPolicy( Qt::NoFocus );
ui->radioCloud->setFocusPolicy( Qt::NoFocus );
QFile f( RESPATH "stylesheets/topbar-radiobuttons.css" );
f.open( QFile::ReadOnly );
QString css = QString::fromAscii( f.readAll() );
f.close();
ui->modeWidget->setStyleSheet( css );
QHBoxLayout* outerModeLayout = new QHBoxLayout;
m_verticalLayout->addLayout( outerModeLayout );
outerModeLayout->addSpacing( 156 );
outerModeLayout->addStretch();
ui->radioNormal->setChecked( true );
ui->filter->setPlaceholderText( tr( "Filter..." ) );
QWidget* modeWidget = new QWidget( this );
QHBoxLayout* modeLayout = new QHBoxLayout;
modeWidget->setLayout( modeLayout );
modeWidget->setStyleSheet( css );
pal = palette();
pal.setColor( QPalette::Window, QColor( "#454e59" ) );
m_radioNormal = new QRadioButton( modeWidget );
m_radioDetailed = new QRadioButton( modeWidget );
m_radioCloud = new QRadioButton( modeWidget );
//for the CSS:
m_radioNormal->setObjectName( "radioNormal");
m_radioCloud->setObjectName( "radioCloud" );
setPalette( pal );
setAutoFillBackground( true );
m_radioNormal->setFocusPolicy( Qt::NoFocus );
m_radioDetailed->setFocusPolicy( Qt::NoFocus );
m_radioCloud->setFocusPolicy( Qt::NoFocus );
setFixedHeight( 80 );
modeLayout->addWidget( m_radioNormal );
modeLayout->addWidget( m_radioDetailed );
modeLayout->addWidget( m_radioCloud );
if ( !s_tiledHeader )
s_tiledHeader = new QPixmap( TomahawkUtils::createTiledPixmap( 2000, height(), QImage( RESPATH "images/playlist-header-tiled.png" ) ) );
modeWidget->setFixedSize( 87, 30 );
m_radioNormal->setChecked( true );
outerModeLayout->addWidget( modeWidget );
outerModeLayout->addStretch();
m_filterField = new QSearchField( this );
m_filterField->setPlaceholderText( tr( "Filter..." ) );
m_filterField->setFixedWidth( 220 );
m_mainLayout->addWidget( m_filterField );
TomahawkUtils::unmarginLayout( outerModeLayout );
TomahawkUtils::unmarginLayout( modeLayout );
connect( &m_filterTimer, SIGNAL( timeout() ), SLOT( applyFilter() ) );
connect( ui->filter, SIGNAL( textChanged( QString ) ), SLOT( onFilterEdited() ) );
connect( m_filterField, SIGNAL( textChanged( QString ) ), SLOT( onFilterEdited() ) );
NewClosure( ui->radioNormal, SIGNAL( clicked() ), const_cast< FlexibleView* >( parent ), SLOT( setCurrentMode( FlexibleViewMode ) ), FlexibleView::Flat )->setAutoDelete( false );
NewClosure( ui->radioDetailed, SIGNAL( clicked() ), const_cast< FlexibleView* >( parent ), SLOT( setCurrentMode( FlexibleViewMode ) ), FlexibleView::Detailed )->setAutoDelete( false );
NewClosure( ui->radioCloud, SIGNAL( clicked() ), const_cast< FlexibleView* >( parent ), SLOT( setCurrentMode( FlexibleViewMode ) ), FlexibleView::Grid )->setAutoDelete( false );
NewClosure( m_radioNormal, SIGNAL( clicked() ), const_cast< FlexibleView* >( parent ), SLOT( setCurrentMode( FlexibleViewMode ) ), FlexibleView::Flat )->setAutoDelete( false );
NewClosure( m_radioDetailed, SIGNAL( clicked() ), const_cast< FlexibleView* >( parent ), SLOT( setCurrentMode( FlexibleViewMode ) ), FlexibleView::Detailed )->setAutoDelete( false );
NewClosure( m_radioCloud, SIGNAL( clicked() ), const_cast< FlexibleView* >( parent ), SLOT( setCurrentMode( FlexibleViewMode ) ), FlexibleView::Grid )->setAutoDelete( false );
}
FlexibleHeader::~FlexibleHeader()
{
delete s_tiledHeader;
s_tiledHeader = 0;
delete ui;
}
void
FlexibleHeader::setCaption( const QString& s )
{
ui->captionLabel->setText( s );
}
void
FlexibleHeader::setDescription( const QString& s )
{
ui->descLabel->setText( s );
}
void
FlexibleHeader::setPixmap( const QPixmap& p )
{
ui->imageLabel->setPixmap( p.scaledToHeight( ui->imageLabel->height(), Qt::SmoothTransformation ) );
}
void
FlexibleHeader::setFilter( const QString& filter )
{
ui->filter->setText( filter );
m_filterField->setText( filter );
}
void
FlexibleHeader::onFilterEdited()
{
m_filter = ui->filter->text();
m_filter = m_filterField->text();
m_filterTimer.stop();
m_filterTimer.setInterval( 280 );
@ -152,7 +124,7 @@ FlexibleHeader::onFilterEdited()
void
FlexibleHeader::applyFilter()
{
emit filterTextChanged( ui->filter->text() );
emit filterTextChanged( m_filterField->text() );
}
@ -171,21 +143,3 @@ FlexibleHeader::changeEvent( QEvent* e )
}
}
void
FlexibleHeader::paintEvent( QPaintEvent* )
{
if ( !s_tiledHeader || s_tiledHeader->isNull() || width() > s_tiledHeader->width() )
{
delete s_tiledHeader;
s_tiledHeader = new QPixmap( TomahawkUtils::createTiledPixmap( width(), height(), QImage( RESPATH "images/playlist-header-tiled.png" ) ) );
}
if ( !s_tiledHeader || s_tiledHeader->isNull() )
return;
QPainter p( this );
// Truncate bg pixmap and paint into bg
p.drawPixmap( rect(), *s_tiledHeader, rect() );
}

View File

@ -1,6 +1,7 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
*
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
* Copyright 2012, Teo Mrnjavac <teo@kde.org>
*
* Tomahawk is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -19,33 +20,26 @@
#ifndef FLEXIBLEHEADER_H
#define FLEXIBLEHEADER_H
#include <QWidget>
#include <QTimer>
#include "widgets/BasicHeader.h"
#include "DllMacro.h"
#include "Artist.h"
class QPaintEvent;
class FlexibleView;
class QRadioButton;
class QSearchField;
namespace Ui
class DLLEXPORT FlexibleHeader : public BasicHeader
{
class PlaylistHeader;
}
class DLLEXPORT FlexibleHeader : public QWidget
{
Q_OBJECT
Q_OBJECT
public:
FlexibleHeader( FlexibleView* parent );
~FlexibleHeader();
public slots:
void setCaption( const QString& s );
void setDescription( const QString& s );
void setPixmap( const QPixmap& p );
void setFilter( const QString& filter );
signals:
@ -53,7 +47,6 @@ signals:
protected:
void changeEvent( QEvent* e );
void paintEvent( QPaintEvent* e );
private slots:
void onFilterEdited();
@ -61,12 +54,15 @@ private slots:
private:
FlexibleView* m_parent;
Ui::PlaylistHeader* ui;
QString m_filter;
QTimer m_filterTimer;
static QPixmap* s_tiledHeader;
QRadioButton* m_radioCloud;
QRadioButton* m_radioDetailed;
QRadioButton* m_radioNormal;
QSearchField* m_filterField;
};
#endif

View File

@ -1,282 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>PlaylistHeader</class>
<widget class="QWidget" name="PlaylistHeader">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>774</width>
<height>80</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>72</height>
</size>
</property>
<property name="windowTitle">
<string>InfoBar</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<property name="leftMargin">
<number>8</number>
</property>
<item>
<widget class="QLabel" name="imageLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>64</width>
<height>64</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>64</width>
<height>64</height>
</size>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>16</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="spacing">
<number>0</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>2</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="ElidedLabel" name="captionLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Caption</string>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="descLabel">
<property name="text">
<string>Description</string>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>1</height>
</size>
</property>
</spacer>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<property name="spacing">
<number>0</number>
</property>
<property name="margin">
<number>0</number>
</property>
<item>
<spacer name="horizontalSpacer_5">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>156</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QWidget" name="modeWidget" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>87</width>
<height>30</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>87</width>
<height>30</height>
</size>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="spacing">
<number>0</number>
</property>
<property name="margin">
<number>0</number>
</property>
<item>
<widget class="QRadioButton" name="radioNormal">
<property name="text">
<string>RadioButton</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="radioDetailed">
<property name="text">
<string>RadioButton</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="radioCloud">
<property name="text">
<string>RadioButton</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</item>
<item>
<spacer name="horizontalSpacer_4">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>16</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QSearchField" name="filter">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>220</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>220</width>
<height>16777215</height>
</size>
</property>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>ElidedLabel</class>
<extends>QLabel</extends>
<header>widgets/ElidedLabel.h</header>
</customwidget>
<customwidget>
<class>QSearchField</class>
<extends>QLineEdit</extends>
<header>thirdparty/Qocoa/qsearchfield.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>

View File

@ -0,0 +1,140 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
*
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
* Copyright 2012, Teo Mrnjavac <teo@kde.org>
*
* 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 "BasicHeader.h"
#include <QtGui/QLabel>
#include <QtGui/QPixmap>
#include <QtGui/QPaintEvent>
#include <QtGui/QPainter>
#include <QtGui/QBoxLayout>
#include "utils/TomahawkUtilsGui.h"
#include "ElidedLabel.h"
using namespace Tomahawk;
QPixmap* BasicHeader::s_tiledHeader = 0;
BasicHeader::BasicHeader( QWidget* parent )
: QWidget( parent )
{
m_mainLayout = new QHBoxLayout;
setLayout( m_mainLayout );
m_imageLabel = new QLabel( this );
m_imageLabel->setFixedSize( 64, 64 );
m_mainLayout->addWidget( m_imageLabel );
m_mainLayout->addSpacing( 16 );
m_verticalLayout = new QVBoxLayout;
m_mainLayout->addLayout( m_verticalLayout );
m_captionLabel = new ElidedLabel( this );
m_descriptionLabel = new ElidedLabel( this );
m_verticalLayout->addWidget( m_captionLabel );
m_verticalLayout->addWidget( m_descriptionLabel );
m_verticalLayout->addStretch();
m_mainLayout->addSpacing( 16 );
QPalette pal = palette();
pal.setColor( QPalette::Foreground, Qt::white );
m_captionLabel->setPalette( pal );
m_descriptionLabel->setPalette( pal );
QFont font = m_captionLabel->font();
font.setPointSize( TomahawkUtils::defaultFontSize() + 4 );
font.setBold( true );
m_captionLabel->setFont( font );
m_captionLabel->setElideMode( Qt::ElideRight );
m_captionLabel->setAlignment( Qt::AlignTop | Qt::AlignLeft );
font.setPointSize( TomahawkUtils::defaultFontSize() + 1 );
font.setBold( false );
m_descriptionLabel->setFont( font );
m_descriptionLabel->setAlignment( Qt::AlignTop | Qt::AlignLeft );
m_captionLabel->setMargin( 2 );
m_descriptionLabel->setMargin( 1 );
TomahawkUtils::unmarginLayout( layout() );
layout()->setContentsMargins( 8, 4, 8, 4 );
setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed );
setFixedHeight( 80 );
pal = palette();
pal.setColor( QPalette::Window, QColor( "#454e59" ) );
setPalette( pal );
setAutoFillBackground( true );
if ( !s_tiledHeader )
s_tiledHeader = new QPixmap( TomahawkUtils::createTiledPixmap( 2000, height(), QImage( RESPATH "images/playlist-header-tiled.png" ) ) );
}
BasicHeader::~BasicHeader()
{
delete s_tiledHeader;
s_tiledHeader = 0;
}
void
BasicHeader::setCaption( const QString& s )
{
m_captionLabel->setText( s );
}
void
BasicHeader::setDescription( const QString& s )
{
m_descriptionLabel->setText( s );
}
void
BasicHeader::setPixmap( const QPixmap& p )
{
m_imageLabel->setPixmap( p.scaledToHeight( m_imageLabel->height(), Qt::SmoothTransformation ) );
}
void
BasicHeader::paintEvent( QPaintEvent* )
{
if ( !s_tiledHeader || s_tiledHeader->isNull() || width() > s_tiledHeader->width() )
{
delete s_tiledHeader;
s_tiledHeader = new QPixmap( TomahawkUtils::createTiledPixmap( width(), height(), QImage( RESPATH "images/playlist-header-tiled.png" ) ) );
}
if ( !s_tiledHeader || s_tiledHeader->isNull() )
return;
QPainter p( this );
// Truncate bg pixmap and paint into bg
p.drawPixmap( rect(), *s_tiledHeader, rect() );
}

View File

@ -0,0 +1,57 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
*
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
* Copyright 2012, Teo Mrnjavac <teo@kde.org>
*
* 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 BASICHEADER_H
#define BASICHEADER_H
#include <QtGui/QWidget>
#include "DllMacro.h"
class QLabel;
class ElidedLabel;
class QPaintEvent;
class QBoxLayout;
class DLLEXPORT BasicHeader : public QWidget
{
Q_OBJECT
public:
explicit BasicHeader( QWidget* parent = 0 );
virtual ~BasicHeader();
public slots:
virtual void setCaption( const QString& s );
virtual void setDescription( const QString& s );
virtual void setPixmap( const QPixmap& p );
protected:
void paintEvent( QPaintEvent* );
QLabel* m_imageLabel;
ElidedLabel* m_captionLabel;
ElidedLabel* m_descriptionLabel;
QBoxLayout* m_mainLayout;
QBoxLayout* m_verticalLayout;
static QPixmap* s_tiledHeader;
};
#endif // BASICHEADER_H