Commit 702a970e authored by Jakob Leben's avatar Jakob Leben

Qt: locationBar: buttons adjustment

now also the text is not elided if not necessary
parent 6e160dae
...@@ -483,8 +483,9 @@ void LocationBar::setIndex( const QModelIndex &index ) ...@@ -483,8 +483,9 @@ void LocationBar::setIndex( const QModelIndex &index )
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);
QToolButton *btn = new LocationButton( text, bold ); QAbstractButton *btn = new LocationButton( text, bold, i.isValid() );
box->insertWidget( 0, btn ); if( bold ) btn->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Preferred );
box->insertWidget( 0, btn, bold ? 1 : 0 );
buttons.append( btn ); buttons.append( btn );
mapper->setMapping( btn, item->id() ); mapper->setMapping( btn, item->id() );
...@@ -504,37 +505,41 @@ void LocationBar::invoke( int i_id ) ...@@ -504,37 +505,41 @@ void LocationBar::invoke( int i_id )
emit invoked ( index ); emit invoked ( index );
} }
LocationButton::LocationButton( const QString &text, bool bold ) LocationButton::LocationButton( const QString &text, bool bold, bool arrow )
: b_arrow( arrow )
{ {
QFont font; QFont font;
font.setBold( bold ); font.setBold( bold );
setFont( font ); setFont( font );
metrics = new QFontMetrics( font ); setText( text );
setText( metrics->elidedText( text, Qt::ElideRight, 150 ) );
} }
void LocationButton::paintEvent ( QPaintEvent * event ) void LocationButton::paintEvent ( QPaintEvent * event )
{ {
QStyleOptionButton option; QStyleOptionButton option;
option.initFrom( this ); option.initFrom( this );
option.rect = rect(); //option.rect = rect();
option.text = text(); //option.features = QStyleOptionButton::Flat;
option.features = QStyleOptionButton::Flat;
option.state |= QStyle::State_Enabled; option.state |= QStyle::State_Enabled;
option.state |= isChecked() ? QStyle::State_On : QStyle::State_Off; //option.state |= isChecked() ? QStyle::State_On : QStyle::State_Off;
if( isDown() ) option.state |= QStyle::State_Sunken; //if( isDown() ) option.state |= QStyle::State_Sunken;
QPainter p( this ); QPainter p( this );
style()->drawControl( QStyle::CE_PushButtonBevel, &option, &p ); if( underMouse() )
option.rect.setLeft( 18 ); style()->drawControl( QStyle::CE_PushButtonBevel, &option, &p );
if( b_arrow ) option.rect.setLeft( 18 );
else option.rect.setLeft( 6 );
p.drawText( option.rect, Qt::AlignVCenter, p.drawText( option.rect, Qt::AlignVCenter,
metrics->elidedText( text(), Qt::ElideRight, option.rect.width() - 5 ) ); fontMetrics().elidedText( text(), Qt::ElideRight, option.rect.width() - 3 ) );
option.rect = QRect( 0, 0, 18, height() ); if( b_arrow )
style()->drawPrimitive( QStyle::PE_IndicatorArrowRight, &option, &p ); {
option.rect = QRect( 0, 0, 18, height() );
style()->drawPrimitive( QStyle::PE_IndicatorArrowRight, &option, &p );
}
} }
QSize LocationButton::sizeHint() const QSize LocationButton::sizeHint() const
{ {
QSize s( metrics->boundingRect( text() ).size() ); QSize s( fontMetrics().boundingRect( text() ).size() );
s += QSize( 25, 10 ); s += QSize( b_arrow ? 24 : 12, 15 );
return s; return s;
} }
...@@ -127,14 +127,15 @@ private: ...@@ -127,14 +127,15 @@ private:
QList<QWidget*> buttons; QList<QWidget*> buttons;
}; };
class LocationButton : public QToolButton class LocationButton : public QPushButton
{ {
public: public:
LocationButton( const QString &, bool bold ); LocationButton( const QString &, bool bold, bool arrow );
private: private:
void paintEvent ( QPaintEvent * event ); void paintEvent ( QPaintEvent * event );
QSize sizeHint() const; QSize sizeHint() const;
QFontMetrics *metrics; QFontMetrics *metrics;
bool b_arrow;
}; };
#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