1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-03-23 09:19:41 +01:00

Bring back the right-arrow that segments the breadcrumbs

This commit is contained in:
Casey Link 2012-04-11 18:43:32 -05:00
parent 6c4e6725b4
commit 90d3661c52
4 changed files with 56 additions and 42 deletions

View File

@ -21,6 +21,7 @@
#include "BreadcrumbButton.h"
#include "utils/stylehelper.h"
#include "utils/logger.h"
#include "utils/tomahawkutilsgui.h"
#include <QStylePainter>
#include <QPushButton>
@ -35,8 +36,7 @@ Breadcrumb::Breadcrumb( QWidget* parent, Qt::WindowFlags f )
, m_model( 0 )
, m_buttonlayout( new QHBoxLayout( this ) )
{
m_buttonlayout->setSpacing( 0 );
m_buttonlayout->setMargin( 0 );
TomahawkUtils::unmarginLayout( m_buttonlayout );
m_buttonlayout->setAlignment( Qt::AlignLeft );
setAutoFillBackground( true );

View File

@ -31,21 +31,67 @@
using namespace Tomahawk;
class BreadcrumbArrow : public QWidget
{
public:
BreadcrumbArrow(QWidget* parent) : QWidget(parent) {}
protected:
virtual void paintEvent( QPaintEvent* ) {
QPainter p( this );
QStyleOption opt;
opt.initFrom( this );
QRect r = rect();
const bool reverse = opt.direction == Qt::RightToLeft;
const int menuButtonWidth = 12;
const int rightSpacing = 10;
const int right = !reverse ? r.right() - rightSpacing : r.left() + menuButtonWidth;
const int height = r.height();
QLine l1( 1, 0, right, height / 2 );
QLine l2( 1, height, right, height / 2 );
p.setRenderHint( QPainter::Antialiasing, true );
// Draw the shadow
QColor shadow( 0, 0, 0, 100 );
p.translate( 0, 1 );
p.setPen( shadow );
p.drawLine( l1 );
p.drawLine( l2 );
// Draw the main arrow
QColor foreGround( "#747474" );
p.translate( 0, -1 );
p.setPen( foreGround );
p.drawLine( l1 );
p.drawLine( l2 );
}
virtual QSize sizeHint() const {
return QSize( 20, TomahawkUtils::headerHeight() );
}
};
BreadcrumbButton::BreadcrumbButton( Breadcrumb* parent, QAbstractItemModel* model )
: QWidget( parent )
, m_breadcrumb( parent )
, m_model( model )
, m_combo( new ComboBox( this ) )
, m_arrow( new BreadcrumbArrow( this ) )
{
setLayout( new QHBoxLayout );
layout()->setContentsMargins( 0, 0, 0, 0 );
layout()->setSpacing( 0 );
TomahawkUtils::unmarginLayout( layout() );
layout()->addWidget( m_combo );
layout()->addWidget( m_arrow );
setFixedHeight( TomahawkUtils::headerHeight() );
m_combo->setSizeAdjustPolicy( QComboBox::AdjustToContents );
setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Expanding );
setSizePolicy( QSizePolicy::Maximum, QSizePolicy::Expanding );
connect( m_combo, SIGNAL( activated( int ) ), SLOT( comboboxActivated( int ) ) );
}
@ -55,44 +101,9 @@ void
BreadcrumbButton::paintEvent( QPaintEvent* )
{
QPainter p( this );
QStyleOption opt;
opt.initFrom( this );
QRect r = rect();
StyleHelper::horizontalHeader( &p, r ); // draw the background
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 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 );
p.setRenderHint( QPainter::Antialiasing, true );
// Draw the shadow
QColor shadow( 0, 0, 0, 100 );
p.translate( 0, -1 );
p.setPen( shadow );
p.drawLine( l1 );
p.drawLine( l2 );
// Draw the main arrow
QColor foreGround( "#747474" );
p.translate( 0, 1 );
p.setPen( foreGround );
p.drawLine( l1 );
p.drawLine( l2 );
StyleHelper::horizontalHeader( &p, rect() ); // draw the background
m_arrow->setVisible( hasChildren() );
}

View File

@ -23,6 +23,7 @@
#include <QModelIndex>
class ComboBox;
class BreadcrumbArrow;
class QPaintEvent;
namespace Tomahawk {
@ -63,6 +64,7 @@ private:
QPersistentModelIndex m_parentIndex;
QPersistentModelIndex m_curIndex;
ComboBox* m_combo;
BreadcrumbArrow* m_arrow;
};
}

View File

@ -64,6 +64,7 @@ NewReleasesWidget::NewReleasesWidget( QWidget* parent )
ui->albumsView->setAttribute( Qt::WA_MacShowFocusRect, 0 );
TomahawkUtils::unmarginLayout( layout() );
TomahawkUtils::unmarginLayout( ui->verticalLayout_2 );
TomahawkUtils::unmarginLayout( ui->breadCrumbLeft->layout() );
m_crumbModelLeft = new QStandardItemModel( this );