mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-14 01:54:07 +02:00
* Fixed painting issues with BreadcrumbBar.
This commit is contained in:
@@ -47,6 +47,8 @@ StyleHelper::headerHighlightColor()
|
|||||||
void
|
void
|
||||||
StyleHelper::horizontalHeader( QPainter* painter, const QRect& r )
|
StyleHelper::horizontalHeader( QPainter* painter, const QRect& r )
|
||||||
{
|
{
|
||||||
|
painter->save();
|
||||||
|
|
||||||
QRect upperHalf( 0, 0, r.width(), r.height() / 2 );
|
QRect upperHalf( 0, 0, r.width(), r.height() / 2 );
|
||||||
QRect lowerHalf( 0, upperHalf.height(), r.width(), r.height() );
|
QRect lowerHalf( 0, upperHalf.height(), r.width(), r.height() );
|
||||||
painter->fillRect( upperHalf, StyleHelper::headerUpperColor() );
|
painter->fillRect( upperHalf, StyleHelper::headerUpperColor() );
|
||||||
@@ -64,6 +66,8 @@ StyleHelper::horizontalHeader( QPainter* painter, const QRect& r )
|
|||||||
painter->setPen( lineColor );
|
painter->setPen( lineColor );
|
||||||
painter->drawLine( line );
|
painter->drawLine( line );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
painter->restore();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -33,7 +33,6 @@ using namespace Tomahawk;
|
|||||||
Breadcrumb::Breadcrumb( QWidget* parent, Qt::WindowFlags f )
|
Breadcrumb::Breadcrumb( QWidget* parent, Qt::WindowFlags f )
|
||||||
: QWidget( parent, f )
|
: QWidget( parent, f )
|
||||||
, m_model( 0 )
|
, m_model( 0 )
|
||||||
|
|
||||||
, m_buttonlayout( new QHBoxLayout( this ) )
|
, m_buttonlayout( new QHBoxLayout( this ) )
|
||||||
{
|
{
|
||||||
m_buttonlayout->setSpacing( 0 );
|
m_buttonlayout->setSpacing( 0 );
|
||||||
@@ -48,11 +47,12 @@ Breadcrumb::Breadcrumb( QWidget* parent, Qt::WindowFlags f )
|
|||||||
show();
|
show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Breadcrumb::~Breadcrumb()
|
Breadcrumb::~Breadcrumb()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
Breadcrumb::setModel( QAbstractItemModel* model )
|
Breadcrumb::setModel( QAbstractItemModel* model )
|
||||||
{
|
{
|
||||||
@@ -64,6 +64,7 @@ Breadcrumb::setModel( QAbstractItemModel* model )
|
|||||||
updateButtons( QModelIndex() );
|
updateButtons( QModelIndex() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
Breadcrumb::setRootIcon( const QPixmap& pm )
|
Breadcrumb::setRootIcon( const QPixmap& pm )
|
||||||
{
|
{
|
||||||
@@ -85,6 +86,7 @@ Breadcrumb::paintEvent( QPaintEvent* )
|
|||||||
StyleHelper::horizontalHeader( &p, rect() );
|
StyleHelper::horizontalHeader( &p, rect() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// updateFrom is the item that has changed---all children must be recomputed
|
// updateFrom is the item that has changed---all children must be recomputed
|
||||||
// if invalid, redo the whole breadcrumb
|
// if invalid, redo the whole breadcrumb
|
||||||
void
|
void
|
||||||
@@ -127,7 +129,7 @@ Breadcrumb::updateButtons( const QModelIndex& updateFrom )
|
|||||||
{
|
{
|
||||||
QPropertyAnimation* animation = new QPropertyAnimation( btn, "pos" );
|
QPropertyAnimation* animation = new QPropertyAnimation( btn, "pos" );
|
||||||
animation->setDuration( 300 );
|
animation->setDuration( 300 );
|
||||||
animation->setStartValue( m_buttons.last()->pos());
|
animation->setStartValue( m_buttons.last()->pos() );
|
||||||
animation->setEndValue( btn->pos() );
|
animation->setEndValue( btn->pos() );
|
||||||
animation->start( QAbstractAnimation::DeleteWhenStopped );
|
animation->start( QAbstractAnimation::DeleteWhenStopped );
|
||||||
}
|
}
|
||||||
@@ -162,6 +164,7 @@ Breadcrumb::updateButtons( const QModelIndex& updateFrom )
|
|||||||
emit activateIndex( idx );
|
emit activateIndex( idx );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
Breadcrumb::breadcrumbComboChanged( const QModelIndex& childSelected )
|
Breadcrumb::breadcrumbComboChanged( const QModelIndex& childSelected )
|
||||||
{
|
{
|
||||||
|
@@ -23,6 +23,7 @@
|
|||||||
#include "combobox.h"
|
#include "combobox.h"
|
||||||
#include "utils/stylehelper.h"
|
#include "utils/stylehelper.h"
|
||||||
#include "utils/tomahawkutilsgui.h"
|
#include "utils/tomahawkutilsgui.h"
|
||||||
|
#include "utils/logger.h"
|
||||||
|
|
||||||
#include <QPaintEvent>
|
#include <QPaintEvent>
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
@@ -49,9 +50,12 @@ BreadcrumbButton::BreadcrumbButton( Breadcrumb* parent, QAbstractItemModel* mode
|
|||||||
connect( m_combo, SIGNAL( activated( int ) ), SLOT( comboboxActivated( int ) ) );
|
connect( m_combo, SIGNAL( activated( int ) ), SLOT( comboboxActivated( int ) ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
BreadcrumbButton::paintEvent( QPaintEvent* )
|
BreadcrumbButton::paintEvent( QPaintEvent* )
|
||||||
{
|
{
|
||||||
|
return;
|
||||||
|
|
||||||
QPainter p( this );
|
QPainter p( this );
|
||||||
QStyleOption opt;
|
QStyleOption opt;
|
||||||
opt.initFrom( this );
|
opt.initFrom( this );
|
||||||
@@ -59,23 +63,22 @@ BreadcrumbButton::paintEvent( QPaintEvent* )
|
|||||||
|
|
||||||
StyleHelper::horizontalHeader( &p, r ); // draw the background
|
StyleHelper::horizontalHeader( &p, r ); // draw the background
|
||||||
|
|
||||||
if( !hasChildren() )
|
if ( !hasChildren() )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
bool reverse = opt.direction == Qt::RightToLeft;
|
bool reverse = opt.direction == Qt::RightToLeft;
|
||||||
int menuButtonWidth = 12;
|
int menuButtonWidth = 12;
|
||||||
int rightSpacing = 10;
|
int rightSpacing = 10;
|
||||||
int left = !reverse ? r.right()-rightSpacing - menuButtonWidth : r.left();
|
int left = !reverse ? r.right() - rightSpacing - menuButtonWidth : r.left();
|
||||||
int right = !reverse ? r.right()-rightSpacing : r.left() + menuButtonWidth;
|
int right = !reverse ? r.right() - rightSpacing : r.left() + menuButtonWidth;
|
||||||
int height = r.height();
|
int height = r.height();
|
||||||
QRect arrowRect( ( left + right ) / 2 + ( reverse ? 6 : -6 ), 0, height, height );
|
QRect arrowRect( ( left + right ) / 2 + ( reverse ? 6 : -6 ), 0, height, height );
|
||||||
|
|
||||||
QStyleOption arrowOpt = opt;
|
QStyleOption arrowOpt = opt;
|
||||||
arrowOpt.rect = arrowRect;
|
arrowOpt.rect = arrowRect;
|
||||||
|
|
||||||
QLine l1( left, 0, right, height/2 );
|
QLine l1( left, 0, right, height / 2 );
|
||||||
QLine l2( left, height, right, height/2 );
|
QLine l2( left, height, right, height / 2 );
|
||||||
|
|
||||||
|
|
||||||
p.setRenderHint( QPainter::Antialiasing, true );
|
p.setRenderHint( QPainter::Antialiasing, true );
|
||||||
|
|
||||||
@@ -94,6 +97,7 @@ BreadcrumbButton::paintEvent( QPaintEvent* )
|
|||||||
p.drawLine( l2 );
|
p.drawLine( l2 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QSize
|
QSize
|
||||||
BreadcrumbButton::sizeHint() const
|
BreadcrumbButton::sizeHint() const
|
||||||
{
|
{
|
||||||
@@ -125,7 +129,6 @@ BreadcrumbButton::setParentIndex( const QModelIndex& idx )
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if ( m_combo->count() && list.count() )
|
if ( m_combo->count() && list.count() )
|
||||||
{
|
{
|
||||||
// Check if it's the same, Don't change if it is, as it'll cause flickering
|
// 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();
|
m_combo->adjustSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
BreadcrumbButton::comboboxActivated( int idx )
|
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;
|
return m_model->rowCount( m_model->index( m_combo->currentIndex(), 0, m_parentIndex ) ) > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QModelIndex
|
QModelIndex
|
||||||
BreadcrumbButton::currentIndex() const
|
BreadcrumbButton::currentIndex() const
|
||||||
{
|
{
|
||||||
|
@@ -42,6 +42,7 @@ public:
|
|||||||
// calculated immediately after loading, or what the user has selected if he has made
|
// calculated immediately after loading, or what the user has selected if he has made
|
||||||
// a manua;l selection
|
// a manua;l selection
|
||||||
QModelIndex currentIndex() const;
|
QModelIndex currentIndex() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void paintEvent( QPaintEvent* );
|
virtual void paintEvent( QPaintEvent* );
|
||||||
virtual QSize sizeHint() const;
|
virtual QSize sizeHint() const;
|
||||||
|
@@ -19,6 +19,8 @@
|
|||||||
#include "combobox.h"
|
#include "combobox.h"
|
||||||
|
|
||||||
#include "utils/stylehelper.h"
|
#include "utils/stylehelper.h"
|
||||||
|
#include "utils/tomahawkutilsgui.h"
|
||||||
|
#include "utils/logger.h"
|
||||||
|
|
||||||
#include <QStyle>
|
#include <QStyle>
|
||||||
#include <QTextOption>
|
#include <QTextOption>
|
||||||
@@ -37,6 +39,13 @@ ComboBox::~ComboBox()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QSize
|
||||||
|
ComboBox::sizeHint() const
|
||||||
|
{
|
||||||
|
return QComboBox::sizeHint() + QSize( 8, 0 );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
ComboBox::paintEvent( QPaintEvent* )
|
ComboBox::paintEvent( QPaintEvent* )
|
||||||
{
|
{
|
||||||
@@ -45,24 +54,26 @@ ComboBox::paintEvent( QPaintEvent* )
|
|||||||
QStyleOptionComboBox cb;
|
QStyleOptionComboBox cb;
|
||||||
initStyleOption( &cb );
|
initStyleOption( &cb );
|
||||||
QRect r = cb.rect;
|
QRect r = cb.rect;
|
||||||
|
r.setHeight( TomahawkUtils::headerHeight() );
|
||||||
|
|
||||||
StyleHelper::horizontalHeader( &p, r );
|
StyleHelper::horizontalHeader( &p, r );
|
||||||
|
|
||||||
if ( cb.state & QStyle::State_MouseOver )
|
if ( cb.state & QStyle::State_MouseOver )
|
||||||
{
|
{
|
||||||
|
p.save();
|
||||||
QRect highlightRect( r );
|
QRect highlightRect( r );
|
||||||
QSize shrink( 3, 4 );
|
QSize shrink( 3, 4 );
|
||||||
QSize hS( highlightRect.size() );
|
QSize hS( highlightRect.size() );
|
||||||
hS -= shrink;
|
hS -= shrink;
|
||||||
highlightRect.setSize( hS );
|
highlightRect.setSize( hS );
|
||||||
highlightRect.translate( 0, 2 );
|
highlightRect.translate( 0, 2 );
|
||||||
p.save();
|
|
||||||
p.setRenderHint( QPainter::Antialiasing );
|
p.setRenderHint( QPainter::Antialiasing );
|
||||||
p.setBrush( StyleHelper::headerHighlightColor() );
|
p.setBrush( StyleHelper::headerHighlightColor() );
|
||||||
p.drawRoundedRect( highlightRect, 10.0, 10.0 );
|
p.drawRoundedRect( highlightRect, 10.0, 10.0 );
|
||||||
p.restore();
|
p.restore();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
p.save();
|
||||||
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( Qt::white );
|
||||||
@@ -78,4 +89,5 @@ ComboBox::paintEvent( QPaintEvent* )
|
|||||||
QStyleOption arrowOpt = cb;
|
QStyleOption arrowOpt = cb;
|
||||||
arrowOpt.rect = arrowRect;
|
arrowOpt.rect = arrowRect;
|
||||||
StyleHelper::drawArrow( QStyle::PE_IndicatorArrowDown, &p, &arrowOpt );
|
StyleHelper::drawArrow( QStyle::PE_IndicatorArrowDown, &p, &arrowOpt );
|
||||||
|
p.restore();
|
||||||
}
|
}
|
||||||
|
@@ -36,6 +36,9 @@ public:
|
|||||||
ComboBox( QWidget* parent = 0 );
|
ComboBox( QWidget* parent = 0 );
|
||||||
virtual ~ComboBox();
|
virtual ~ComboBox();
|
||||||
|
|
||||||
|
virtual QSize sizeHint() const;
|
||||||
|
|
||||||
|
protected:
|
||||||
virtual void paintEvent( QPaintEvent* );
|
virtual void paintEvent( QPaintEvent* );
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -24,22 +24,25 @@
|
|||||||
#include <QStylePainter>
|
#include <QStylePainter>
|
||||||
#include <QPaintEvent>
|
#include <QPaintEvent>
|
||||||
|
|
||||||
HeaderBreadCrumb::HeaderBreadCrumb(BreadcrumbButtonFactory *buttonFactory, QWidget *parent) :
|
HeaderBreadCrumb::HeaderBreadCrumb( BreadcrumbButtonFactory* buttonFactory, QWidget* parent )
|
||||||
BreadcrumbBar(buttonFactory, parent)
|
: BreadcrumbBar( buttonFactory, parent )
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
HeaderBreadCrumb::HeaderBreadCrumb(QWidget *parent) :
|
|
||||||
BreadcrumbBar(parent)
|
HeaderBreadCrumb::HeaderBreadCrumb( QWidget* parent )
|
||||||
|
: BreadcrumbBar( parent )
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
HeaderBreadCrumb::~HeaderBreadCrumb()
|
HeaderBreadCrumb::~HeaderBreadCrumb()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void HeaderBreadCrumb::paintEvent(QPaintEvent *event)
|
|
||||||
|
void HeaderBreadCrumb::paintEvent( QPaintEvent* /* event */ )
|
||||||
{
|
{
|
||||||
QStylePainter p(this);
|
QStylePainter p( this );
|
||||||
StyleHelper::horizontalHeader(&p, rect());
|
StyleHelper::horizontalHeader( &p, rect() );
|
||||||
}
|
}
|
||||||
|
@@ -30,13 +30,12 @@ class HeaderBreadCrumb : public BreadcrumbBar
|
|||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
HeaderBreadCrumb(BreadcrumbButtonFactory *buttonFactory, QWidget *parent = 0);
|
HeaderBreadCrumb( BreadcrumbButtonFactory* buttonFactory, QWidget* parent = 0 );
|
||||||
HeaderBreadCrumb(QWidget *parent = 0);
|
HeaderBreadCrumb( QWidget* parent = 0 );
|
||||||
~HeaderBreadCrumb();
|
~HeaderBreadCrumb();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
virtual void paintEvent( QPaintEvent* event );
|
||||||
virtual void paintEvent(QPaintEvent *event);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Reference in New Issue
Block a user