Commit c5b155b6 authored by Jakob Leben's avatar Jakob Leben

Qt: neat and crispy location bar, new location buttons

parent 4fe7b124
...@@ -45,6 +45,7 @@ ...@@ -45,6 +45,7 @@
#include <QWheelEvent> #include <QWheelEvent>
#include <QToolButton> #include <QToolButton>
#include <QFontMetrics> #include <QFontMetrics>
#include <QPainter>
#include <assert.h> #include <assert.h>
...@@ -456,33 +457,33 @@ LocationBar::LocationBar( PLModel *m ) ...@@ -456,33 +457,33 @@ LocationBar::LocationBar( PLModel *m )
model = m; model = m;
mapper = new QSignalMapper( this ); mapper = new QSignalMapper( this );
CONNECT( mapper, mapped( int ), this, invoke( int ) ); CONNECT( mapper, mapped( int ), this, invoke( int ) );
box = new QHBoxLayout;
box->setSpacing( 0 );
setLayout( box );
} }
void LocationBar::setIndex( const QModelIndex &index ) void LocationBar::setIndex( const QModelIndex &index )
{ {
clear(); qDeleteAll( buttons );
QAction *prev = NULL; buttons.clear();
QModelIndex i = index; QModelIndex i = index;
QFont font; bool bold = true;
QFontMetrics metrics( font );
font.setBold( true );
while( true ) while( true )
{ {
PLItem *item = model->getItem( i ); PLItem *item = model->getItem( i );
QToolButton *btn = new QToolButton;
char *fb_name = input_item_GetTitleFbName( item->inputItem() ); char *fb_name = input_item_GetTitleFbName( item->inputItem() );
QString text = qfu(fb_name); QString text = qfu(fb_name);
free(fb_name); free(fb_name);
text = QString("> ") + metrics.elidedText( text, Qt::ElideRight, 150 ); QToolButton *btn = new LocationButton( text, bold );
btn->setText( text ); box->insertWidget( 0, btn );
btn->setFont( font ); buttons.append( btn );
prev = insertWidget( prev, btn );
mapper->setMapping( btn, item->id() ); mapper->setMapping( btn, item->id() );
CONNECT( btn, clicked( ), mapper, map( ) ); CONNECT( btn, clicked( ), mapper, map( ) );
font = QFont(); bold = false;
if( i.isValid() ) i = i.parent(); if( i.isValid() ) i = i.parent();
else break; else break;
...@@ -495,3 +496,38 @@ void LocationBar::invoke( int i_id ) ...@@ -495,3 +496,38 @@ void LocationBar::invoke( int i_id )
setIndex( index ); setIndex( index );
emit invoked ( index ); emit invoked ( index );
} }
LocationButton::LocationButton( const QString &text, bool bold )
{
QFont font;
font.setBold( bold );
setFont( font );
metrics = new QFontMetrics( font );
setText( metrics->elidedText( text, Qt::ElideRight, 150 ) );
}
void LocationButton::paintEvent ( QPaintEvent * event )
{
QStyleOptionButton option;
option.initFrom( this );
option.rect = rect();
option.text = text();
option.features = QStyleOptionButton::Flat;
option.state |= QStyle::State_Enabled;
option.state |= isChecked() ? QStyle::State_On : QStyle::State_Off;
if( isDown() ) option.state |= QStyle::State_Sunken;
QPainter p( this );
style()->drawControl( QStyle::CE_PushButtonBevel, &option, &p );
option.rect.setLeft( 18 );
p.drawText( option.rect, Qt::AlignVCenter,
metrics->elidedText( text(), Qt::ElideRight, option.rect.width() - 5 ) );
option.rect = QRect( 0, 0, 18, height() );
style()->drawPrimitive( QStyle::PE_IndicatorArrowRight, &option, &p );
}
QSize LocationButton::sizeHint() const
{
QSize s( metrics->boundingRect( text() ).size() );
s += QSize( 25, 10 );
return s;
}
...@@ -110,7 +110,7 @@ private slots: ...@@ -110,7 +110,7 @@ private slots:
void browseInto( input_item_t * ); void browseInto( input_item_t * );
}; };
class LocationBar : public QToolBar class LocationBar : public QWidget
{ {
Q_OBJECT; Q_OBJECT;
public: public:
...@@ -123,6 +123,18 @@ private slots: ...@@ -123,6 +123,18 @@ private slots:
private: private:
PLModel *model; PLModel *model;
QSignalMapper *mapper; QSignalMapper *mapper;
QHBoxLayout *box;
QList<QWidget*> buttons;
};
class LocationButton : public QToolButton
{
public:
LocationButton( const QString &, bool bold );
private:
void paintEvent ( QPaintEvent * event );
QSize sizeHint() const;
QFontMetrics *metrics;
}; };
#endif #endif
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment