1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-15 10:33:59 +02:00

* Fixed painting issues with BreadcrumbBar.

This commit is contained in:
Christian Muehlhaeuser
2012-01-23 05:52:39 +01:00
parent 39a40ce372
commit 5a719f39bd
8 changed files with 52 additions and 22 deletions

View File

@@ -47,6 +47,8 @@ StyleHelper::headerHighlightColor()
void
StyleHelper::horizontalHeader( QPainter* painter, const QRect& r )
{
painter->save();
QRect upperHalf( 0, 0, r.width(), r.height() / 2 );
QRect lowerHalf( 0, upperHalf.height(), r.width(), r.height() );
painter->fillRect( upperHalf, StyleHelper::headerUpperColor() );
@@ -64,6 +66,8 @@ StyleHelper::horizontalHeader( QPainter* painter, const QRect& r )
painter->setPen( lineColor );
painter->drawLine( line );
}
painter->restore();
}

View File

@@ -33,7 +33,6 @@ using namespace Tomahawk;
Breadcrumb::Breadcrumb( QWidget* parent, Qt::WindowFlags f )
: QWidget( parent, f )
, m_model( 0 )
, m_buttonlayout( new QHBoxLayout( this ) )
{
m_buttonlayout->setSpacing( 0 );
@@ -48,11 +47,12 @@ Breadcrumb::Breadcrumb( QWidget* parent, Qt::WindowFlags f )
show();
}
Breadcrumb::~Breadcrumb()
{
}
void
Breadcrumb::setModel( QAbstractItemModel* model )
{
@@ -64,6 +64,7 @@ Breadcrumb::setModel( QAbstractItemModel* model )
updateButtons( QModelIndex() );
}
void
Breadcrumb::setRootIcon( const QPixmap& pm )
{
@@ -85,6 +86,7 @@ Breadcrumb::paintEvent( QPaintEvent* )
StyleHelper::horizontalHeader( &p, rect() );
}
// updateFrom is the item that has changed---all children must be recomputed
// if invalid, redo the whole breadcrumb
void
@@ -127,7 +129,7 @@ Breadcrumb::updateButtons( const QModelIndex& updateFrom )
{
QPropertyAnimation* animation = new QPropertyAnimation( btn, "pos" );
animation->setDuration( 300 );
animation->setStartValue( m_buttons.last()->pos());
animation->setStartValue( m_buttons.last()->pos() );
animation->setEndValue( btn->pos() );
animation->start( QAbstractAnimation::DeleteWhenStopped );
}
@@ -162,6 +164,7 @@ Breadcrumb::updateButtons( const QModelIndex& updateFrom )
emit activateIndex( idx );
}
void
Breadcrumb::breadcrumbComboChanged( const QModelIndex& childSelected )
{

View File

@@ -23,6 +23,7 @@
#include "combobox.h"
#include "utils/stylehelper.h"
#include "utils/tomahawkutilsgui.h"
#include "utils/logger.h"
#include <QPaintEvent>
#include <QPainter>
@@ -49,9 +50,12 @@ BreadcrumbButton::BreadcrumbButton( Breadcrumb* parent, QAbstractItemModel* mode
connect( m_combo, SIGNAL( activated( int ) ), SLOT( comboboxActivated( int ) ) );
}
void
BreadcrumbButton::paintEvent( QPaintEvent* )
{
return;
QPainter p( this );
QStyleOption opt;
opt.initFrom( this );
@@ -59,23 +63,22 @@ BreadcrumbButton::paintEvent( QPaintEvent* )
StyleHelper::horizontalHeader( &p, r ); // draw the background
if( !hasChildren() )
if ( !hasChildren() )
return;
bool reverse = opt.direction == Qt::RightToLeft;
int menuButtonWidth = 12;
int rightSpacing = 10;
int left = !reverse ? r.right()-rightSpacing - menuButtonWidth : r.left();
int right = !reverse ? r.right()-rightSpacing : r.left() + menuButtonWidth;
int left = !reverse ? r.right() - rightSpacing - menuButtonWidth : r.left();
int right = !reverse ? r.right() - rightSpacing : r.left() + menuButtonWidth;
int height = r.height();
QRect arrowRect( ( left + right ) / 2 + ( reverse ? 6 : -6 ), 0, height, height );
QStyleOption arrowOpt = opt;
arrowOpt.rect = arrowRect;
QLine l1( left, 0, right, height/2 );
QLine l2( left, height, right, height/2 );
QLine l1( left, 0, right, height / 2 );
QLine l2( left, height, right, height / 2 );
p.setRenderHint( QPainter::Antialiasing, true );
@@ -94,6 +97,7 @@ BreadcrumbButton::paintEvent( QPaintEvent* )
p.drawLine( l2 );
}
QSize
BreadcrumbButton::sizeHint() const
{
@@ -125,7 +129,6 @@ BreadcrumbButton::setParentIndex( const QModelIndex& idx )
}
}
if ( m_combo->count() && list.count() )
{
// Check if it's the same, Don't change if it is, as it'll cause flickering
@@ -152,6 +155,7 @@ BreadcrumbButton::setParentIndex( const QModelIndex& idx )
m_combo->adjustSize();
}
void
BreadcrumbButton::comboboxActivated( int idx )
{
@@ -171,6 +175,7 @@ BreadcrumbButton::hasChildren() const
return m_model->rowCount( m_model->index( m_combo->currentIndex(), 0, m_parentIndex ) ) > 0;
}
QModelIndex
BreadcrumbButton::currentIndex() const
{

View File

@@ -42,6 +42,7 @@ public:
// calculated immediately after loading, or what the user has selected if he has made
// a manua;l selection
QModelIndex currentIndex() const;
protected:
virtual void paintEvent( QPaintEvent* );
virtual QSize sizeHint() const;

View File

@@ -19,6 +19,8 @@
#include "combobox.h"
#include "utils/stylehelper.h"
#include "utils/tomahawkutilsgui.h"
#include "utils/logger.h"
#include <QStyle>
#include <QTextOption>
@@ -37,6 +39,13 @@ ComboBox::~ComboBox()
}
QSize
ComboBox::sizeHint() const
{
return QComboBox::sizeHint() + QSize( 8, 0 );
}
void
ComboBox::paintEvent( QPaintEvent* )
{
@@ -45,24 +54,26 @@ ComboBox::paintEvent( QPaintEvent* )
QStyleOptionComboBox cb;
initStyleOption( &cb );
QRect r = cb.rect;
r.setHeight( TomahawkUtils::headerHeight() );
StyleHelper::horizontalHeader( &p, r );
if ( cb.state & QStyle::State_MouseOver )
{
p.save();
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();
}
p.save();
QTextOption to( Qt::AlignVCenter );
r.adjust( 8, 0, -8, 0 );
p.setPen( Qt::white );
@@ -78,4 +89,5 @@ ComboBox::paintEvent( QPaintEvent* )
QStyleOption arrowOpt = cb;
arrowOpt.rect = arrowRect;
StyleHelper::drawArrow( QStyle::PE_IndicatorArrowDown, &p, &arrowOpt );
p.restore();
}

View File

@@ -36,6 +36,9 @@ public:
ComboBox( QWidget* parent = 0 );
virtual ~ComboBox();
virtual QSize sizeHint() const;
protected:
virtual void paintEvent( QPaintEvent* );
};

View File

@@ -24,22 +24,25 @@
#include <QStylePainter>
#include <QPaintEvent>
HeaderBreadCrumb::HeaderBreadCrumb(BreadcrumbButtonFactory *buttonFactory, QWidget *parent) :
BreadcrumbBar(buttonFactory, parent)
HeaderBreadCrumb::HeaderBreadCrumb( BreadcrumbButtonFactory* buttonFactory, QWidget* parent )
: BreadcrumbBar( buttonFactory, parent )
{
}
HeaderBreadCrumb::HeaderBreadCrumb(QWidget *parent) :
BreadcrumbBar(parent)
HeaderBreadCrumb::HeaderBreadCrumb( QWidget* parent )
: BreadcrumbBar( parent )
{
}
HeaderBreadCrumb::~HeaderBreadCrumb()
{
}
void HeaderBreadCrumb::paintEvent(QPaintEvent *event)
void HeaderBreadCrumb::paintEvent( QPaintEvent* /* event */ )
{
QStylePainter p(this);
StyleHelper::horizontalHeader(&p, rect());
QStylePainter p( this );
StyleHelper::horizontalHeader( &p, rect() );
}

View File

@@ -30,13 +30,12 @@ class HeaderBreadCrumb : public BreadcrumbBar
{
Q_OBJECT
public:
HeaderBreadCrumb(BreadcrumbButtonFactory *buttonFactory, QWidget *parent = 0);
HeaderBreadCrumb(QWidget *parent = 0);
HeaderBreadCrumb( BreadcrumbButtonFactory* buttonFactory, QWidget* parent = 0 );
HeaderBreadCrumb( QWidget* parent = 0 );
~HeaderBreadCrumb();
protected:
virtual void paintEvent(QPaintEvent *event);
virtual void paintEvent( QPaintEvent* event );
};
#endif