standardpanel.cpp 18.2 KB
Newer Older
1 2 3
/*****************************************************************************
 * standardpanel.cpp : The "standard" playlist panel : just a treeview
 ****************************************************************************
4
 * Copyright (C) 2000-2009 VideoLAN
5
 * $Id$
6 7
 *
 * Authors: Clément Stenac <zorglub@videolan.org>
8
 *          JB Kempf <jb@videolan.org>
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
 *****************************************************************************/
24

25 26 27
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
28

29
#include "dialogs_provider.hpp"
30

31
#include "components/playlist/playlist_model.hpp"
32
#include "components/playlist/standardpanel.hpp"
33
#include "components/playlist/icon_view.hpp"
Clément Stenac's avatar
Clément Stenac committed
34
#include "util/customwidgets.hpp"
35
#include "menus.hpp"
Clément Stenac's avatar
Clément Stenac committed
36

37 38
#include <vlc_intf_strings.h>

Clément Stenac's avatar
Clément Stenac committed
39
#include <QPushButton>
40
#include <QHeaderView>
Clément Stenac's avatar
Clément Stenac committed
41 42
#include <QKeyEvent>
#include <QModelIndexList>
Clément Stenac's avatar
Clément Stenac committed
43
#include <QLabel>
44
#include <QMenu>
45
#include <QSignalMapper>
46
#include <QWheelEvent>
47 48
#include <QToolButton>
#include <QFontMetrics>
49
#include <QPainter>
50
#include <QStackedLayout>
51

Clément Stenac's avatar
Clément Stenac committed
52
#include <assert.h>
Clément Stenac's avatar
Clément Stenac committed
53

Rafaël Carré's avatar
Rafaël Carré committed
54 55
#include "sorting.h"

Jakob Leben's avatar
Jakob Leben committed
56 57 58 59
static const QString viewNames[] = { qtr( "Detailed View" ),
                                     qtr( "Icon View" ),
                                     qtr( "List View" ) };

60
StandardPLPanel::StandardPLPanel( PlaylistWidget *_parent,
61
                                  intf_thread_t *_p_intf,
Clément Stenac's avatar
Clément Stenac committed
62
                                  playlist_t *p_playlist,
Clément Stenac's avatar
Clément Stenac committed
63
                                  playlist_item_t *p_root ):
64
                                  QWidget( _parent ), p_intf( _p_intf )
65
{
66
    layout = new QGridLayout( this );
67
    layout->setSpacing( 0 ); layout->setMargin( 0 );
68
    setMinimumWidth( 300 );
69

70
    iconView = NULL;
71
    treeView = NULL;
Jakob Leben's avatar
Jakob Leben committed
72
    listView = NULL;
73 74
    viewStack = new QStackedLayout();
    layout->addLayout( viewStack, 1, 0, 1, -1 );
75

76
    model = new PLModel( p_playlist, p_intf, p_root, this );
77
    currentRootId = -1;
78 79
    currentRootIndexId = -1;
    lastActivatedId = -1;
Clément Stenac's avatar
Clément Stenac committed
80

81
    locationBar = new LocationBar( model );
Jakob Leben's avatar
Jakob Leben committed
82
    locationBar->setSizePolicy( QSizePolicy::Ignored, QSizePolicy::Preferred );
83
    layout->addWidget( locationBar, 0, 0 );
Jakob Leben's avatar
Jakob Leben committed
84
    layout->setColumnStretch( 0, 5 );
85 86
    CONNECT( locationBar, invoked( const QModelIndex & ),
             this, browseInto( const QModelIndex & ) );
87

88 89 90
    searchEdit = new SearchLineEdit( this );
    searchEdit->setMaximumWidth( 250 );
    searchEdit->setMinimumWidth( 80 );
Jakob Leben's avatar
Jakob Leben committed
91
    layout->addWidget( searchEdit, 0, 2 );
92
    CONNECT( searchEdit, textChanged( const QString& ),
93
             this, search( const QString& ) );
Jakob Leben's avatar
Jakob Leben committed
94
    layout->setColumnStretch( 2, 3 );
95

96
    /* Button to switch views */
97
    QToolButton *viewButton = new QToolButton( this );
98
    viewButton->setIcon( style()->standardIcon( QStyle::SP_FileDialogDetailedView ) );
99
    viewButton->setToolTip( qtr("Change playlistview"));
Jakob Leben's avatar
Jakob Leben committed
100
    layout->addWidget( viewButton, 0, 1 );
101 102

    /* View selection menu */
103
    viewSelectionMapper = new QSignalMapper( this );
104 105 106 107
    CONNECT( viewSelectionMapper, mapped( int ), this, showView( int ) );

    QActionGroup *actionGroup = new QActionGroup( this );

Jakob Leben's avatar
Jakob Leben committed
108 109 110 111 112 113 114
    for( int i = 0; i < VIEW_COUNT; i++ )
    {
        viewActions[i] = actionGroup->addAction( viewNames[i] );
        viewActions[i]->setCheckable( true );
        viewSelectionMapper->setMapping( viewActions[i], i );
        CONNECT( viewActions[i], triggered(), viewSelectionMapper, map() );
    }
115

116
    BUTTONACT( viewButton, cycleViews() );
117 118 119 120
    QMenu *viewMenu = new QMenu( this );
    viewMenu->addActions( actionGroup->actions() );

    viewButton->setMenu( viewMenu );
121 122 123 124 125 126 127

    /* Saved Settings */
    getSettings()->beginGroup("Playlist");

    int i_viewMode = getSettings()->value( "view-mode", TREE_VIEW ).toInt();

    getSettings()->endGroup();
128

Jakob Leben's avatar
Jakob Leben committed
129 130
    showView( i_viewMode );

131 132
    DCONNECT( THEMIM, leafBecameParent( input_item_t *),
              this, browseInto( input_item_t * ) );
133 134 135

    CONNECT( model, currentChanged( const QModelIndex& ),
             this, handleExpansion( const QModelIndex& ) );
136
    CONNECT( model, rootChanged(), this, handleRootChange() );
137 138
}

139 140 141
StandardPLPanel::~StandardPLPanel()
{
    getSettings()->beginGroup("Playlist");
142 143
    if( treeView )
        getSettings()->setValue( "headerStateV2", treeView->header()->saveState() );
Jakob Leben's avatar
Jakob Leben committed
144 145 146 147 148 149
    if( currentView == treeView )
        getSettings()->setValue( "view-mode", TREE_VIEW );
    else if( currentView == listView )
        getSettings()->setValue( "view-mode", LIST_VIEW );
    else if( currentView == iconView )
        getSettings()->setValue( "view-mode", ICON_VIEW );
150 151 152
    getSettings()->endGroup();
}

153
/* Unused anymore, but might be useful, like in right-click menu */
154 155
void StandardPLPanel::gotoPlayingItem()
{
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
156
    currentView->scrollTo( model->currentIndex() );
157 158
}

159
void StandardPLPanel::handleExpansion( const QModelIndex& index )
Clément Stenac's avatar
Qt4:  
Clément Stenac committed
160
{
Ilkka Ollakka's avatar
Ilkka Ollakka committed
161
    assert( currentView );
162
    browseInto( index.parent() );
163
    currentView->scrollTo( index );
Clément Stenac's avatar
Qt4:  
Clément Stenac committed
164 165
}

166 167
void StandardPLPanel::handleRootChange()
{
168
    browseInto();
169 170
}

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
171 172 173 174
void StandardPLPanel::popupPlView( const QPoint &point )
{
    QModelIndex index = currentView->indexAt( point );
    QPoint globalPoint = currentView->viewport()->mapToGlobal( point );
175 176 177 178
    QItemSelectionModel *selection = currentView->selectionModel();
    QModelIndexList list = selection->selectedIndexes();

    if( !model->popup( index, globalPoint, list ) )
Erwan Tulou's avatar
Erwan Tulou committed
179
        QVLCMenu::PopupMenu( p_intf, true );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
180 181
}

182
void StandardPLPanel::popupSelectColumn( QPoint pos )
183
{
184
    QMenu menu;
185
    assert( treeView );
186

187 188
    /* We do not offer the option to hide index 0 column, or
    * QTreeView will behave weird */
189
    int i, j;
190
    for( i = 1 << 1, j = 1; i < COLUMN_END; i <<= 1, j++ )
191
    {
192 193 194
        QAction* option = menu.addAction(
            qfu( psz_column_title( i ) ) );
        option->setCheckable( true );
195
        option->setChecked( !treeView->isColumnHidden( j ) );
196 197
        selectColumnsSigMapper->setMapping( option, j );
        CONNECT( option, triggered(), selectColumnsSigMapper, map() );
198
    }
199
    menu.exec( QCursor::pos() );
200 201
}

202
void StandardPLPanel::toggleColumnShown( int i )
203
{
204
    treeView->setColumnHidden( i, !treeView->isColumnHidden( i ) );
205
}
206

207
/* Search in the playlist */
208
void StandardPLPanel::search( const QString& searchText )
Clément Stenac's avatar
Clément Stenac committed
209
{
210 211 212 213
    bool flat = currentView == iconView || currentView == listView;
    model->search( searchText,
                   flat ? currentView->rootIndex() : QModelIndex(),
                   !flat );
Clément Stenac's avatar
Clément Stenac committed
214 215
}

216 217
/* Set the root of the new Playlist */
/* This activated by the selector selection */
218 219
void StandardPLPanel::setRoot( playlist_item_t *p_item )
{
Clément Stenac's avatar
Clément Stenac committed
220
    model->rebuild( p_item );
221 222
}

223 224 225 226
void StandardPLPanel::browseInto( const QModelIndex &index )
{
    if( currentView == iconView || currentView == listView )
    {
Ilkka Ollakka's avatar
Ilkka Ollakka committed
227
        currentRootIndexId = model->itemId( index );
228 229 230 231 232 233 234 235 236 237 238 239 240 241
        currentView->setRootIndex( index );
    }

    locationBar->setIndex( index );
    searchEdit->clear();
}

void StandardPLPanel::browseInto( )
{
    browseInto( currentRootIndexId != -1 && currentView != treeView ?
                model->index( currentRootIndexId, 0 ) :
                QModelIndex() );
}

242
void StandardPLPanel::wheelEvent( QWheelEvent *e )
Clément Stenac's avatar
Clément Stenac committed
243
{
244 245 246 247 248 249 250
    // Accept this event in order to prevent unwanted volume up/down changes
    e->accept();
}

bool StandardPLPanel::eventFilter ( QObject * watched, QEvent * event )
{
    if (event->type() == QEvent::KeyPress)
Clément Stenac's avatar
Clément Stenac committed
251
    {
252 253
        QKeyEvent *keyEvent = static_cast<QKeyEvent*>(event);
        if( keyEvent->key() == Qt::Key_Delete ||
254
            keyEvent->key() == Qt::Key_Backspace )
255 256 257 258
        {
            deleteSelection();
            return true;
        }
Clément Stenac's avatar
Clément Stenac committed
259
    }
260
    return false;
Clément Stenac's avatar
Clément Stenac committed
261 262 263 264
}

void StandardPLPanel::deleteSelection()
{
265
    QItemSelectionModel *selection = currentView->selectionModel();
Clément Stenac's avatar
Clément Stenac committed
266 267 268 269
    QModelIndexList list = selection->selectedIndexes();
    model->doDelete( list );
}

270 271 272 273 274 275
void StandardPLPanel::createIconView()
{
    iconView = new PlIconView( model, this );
    iconView->setContextMenuPolicy( Qt::CustomContextMenu );
    CONNECT( iconView, customContextMenuRequested( const QPoint & ),
             this, popupPlView( const QPoint & ) );
276 277
    CONNECT( iconView, activated( const QModelIndex & ),
             this, activate( const QModelIndex & ) );
278
    iconView->installEventFilter( this );
279
    viewStack->addWidget( iconView );
280 281
}

Jakob Leben's avatar
Jakob Leben committed
282 283 284 285 286 287 288 289
void StandardPLPanel::createListView()
{
    listView = new PlListView( model, this );
    listView->setContextMenuPolicy( Qt::CustomContextMenu );
    CONNECT( listView, customContextMenuRequested( const QPoint & ),
             this, popupPlView( const QPoint & ) );
    CONNECT( listView, activated( const QModelIndex & ),
             this, activate( const QModelIndex & ) );
290
    listView->installEventFilter( this );
291
    viewStack->addWidget( listView );
Jakob Leben's avatar
Jakob Leben committed
292 293 294
}


295 296 297
void StandardPLPanel::createTreeView()
{
    /* Create and configure the QTreeView */
298
    treeView = new PlTreeView;
299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316

    treeView->setIconSize( QSize( 20, 20 ) );
    treeView->setAlternatingRowColors( true );
    treeView->setAnimated( true );
    treeView->setUniformRowHeights( true );
    treeView->setSortingEnabled( true );
    treeView->header()->setSortIndicator( -1 , Qt::AscendingOrder );
    treeView->header()->setSortIndicatorShown( true );
    treeView->header()->setClickable( true );
    treeView->header()->setContextMenuPolicy( Qt::CustomContextMenu );

    treeView->setSelectionBehavior( QAbstractItemView::SelectRows );
    treeView->setSelectionMode( QAbstractItemView::ExtendedSelection );
    treeView->setDragEnabled( true );
    treeView->setAcceptDrops( true );
    treeView->setDropIndicatorShown( true );
    treeView->setContextMenuPolicy( Qt::CustomContextMenu );

317 318 319
    /* setModel after setSortingEnabled(true), or the model will sort immediately! */
    treeView->setModel( model );

Jakob Leben's avatar
Jakob Leben committed
320 321
    getSettings()->beginGroup("Playlist");

322 323 324 325 326 327 328 329 330
    if( getSettings()->contains( "headerStateV2" ) )
    {
        treeView->header()->restoreState(
                getSettings()->value( "headerStateV2" ).toByteArray() );
    }
    else
    {
        for( int m = 1, c = 0; m != COLUMN_END; m <<= 1, c++ )
        {
331
            treeView->setColumnHidden( c, !( m & COLUMN_DEFAULT ) );
332 333 334 335 336
            if( m == COLUMN_TITLE ) treeView->header()->resizeSection( c, 200 );
            else if( m == COLUMN_DURATION ) treeView->header()->resizeSection( c, 80 );
        }
    }

Jakob Leben's avatar
Jakob Leben committed
337 338
    getSettings()->endGroup();

339 340
    /* Connections for the TreeView */
    CONNECT( treeView, activated( const QModelIndex& ),
341
             this, activate( const QModelIndex& ) );
342 343 344 345
    CONNECT( treeView->header(), customContextMenuRequested( const QPoint & ),
             this, popupSelectColumn( QPoint ) );
    CONNECT( treeView, customContextMenuRequested( const QPoint & ),
             this, popupPlView( const QPoint & ) );
346
    treeView->installEventFilter( this );
347 348 349 350 351 352 353

    /* SignalMapper for columns */
    selectColumnsSigMapper = new QSignalMapper( this );
    CONNECT( selectColumnsSigMapper, mapped( int ),
             this, toggleColumnShown( int ) );

    /* Finish the layout */
354
    viewStack->addWidget( treeView );
355 356
}

357
void StandardPLPanel::showView( int i_view )
358
{
359 360 361 362 363 364 365 366 367 368
    switch( i_view )
    {
    case TREE_VIEW:
    {
        if( treeView == NULL )
            createTreeView();
        currentView = treeView;
        break;
    }
    case ICON_VIEW:
369
    {
370
        if( iconView == NULL )
371
            createIconView();
372
        currentView = iconView;
Jakob Leben's avatar
Jakob Leben committed
373 374 375 376 377 378 379
        break;
    }
    case LIST_VIEW:
    {
        if( listView == NULL )
            createListView();
        currentView = listView;
380
        break;
381
    }
382
    default: return;
383
    }
384

385 386
    viewStack->setCurrentWidget( currentView );
    viewActions[i_view]->setChecked( true );
387
    browseInto();
388
    gotoPlayingItem();
389
}
390

391 392 393 394 395
void StandardPLPanel::cycleViews()
{
    if( currentView == iconView )
        showView( TREE_VIEW );
    else if( currentView == treeView )
Jakob Leben's avatar
Jakob Leben committed
396 397
        showView( LIST_VIEW );
    else if( currentView == listView )
398 399 400 401 402
        showView( ICON_VIEW );
    else
        assert( 0 );
}

403 404
void StandardPLPanel::activate( const QModelIndex &index )
{
405
    if( !index.data( PLModel::IsLeafNodeRole ).toBool() )
406
    {
407 408
        if( currentView != treeView )
            browseInto( index );
409 410 411
    }
    else
    {
412 413 414
        playlist_Lock( THEPL );
        playlist_item_t *p_item = playlist_ItemGetById( THEPL, model->itemId( index ) );
        p_item->i_flags |= PLAYLIST_SUBITEM_STOP_FLAG;
415
        lastActivatedId = p_item->p_input->i_id;
416
        playlist_Unlock( THEPL );
417 418 419
        model->activateItem( index );
    }
}
420

421
void StandardPLPanel::browseInto( input_item_t *p_input )
422
{
Jakob Leben's avatar
Jakob Leben committed
423

424
    if( p_input->i_id != lastActivatedId ) return;
425 426 427

    playlist_Lock( THEPL );

428
    playlist_item_t *p_item = playlist_ItemGetByInput( THEPL, p_input );
429 430 431 432 433
    if( !p_item )
    {
        playlist_Unlock( THEPL );
        return;
    }
434

435
    QModelIndex index = model->index( p_item->i_id, 0 );
436 437 438

    playlist_Unlock( THEPL );

439
    if( currentView == treeView )
440
        treeView->setExpanded( index, true );
441 442
    else
        browseInto( index );
443

444
    lastActivatedId = -1;
445

446

447
}
448 449 450

LocationBar::LocationBar( PLModel *m )
{
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
451 452 453
    model = m;
    mapper = new QSignalMapper( this );
    CONNECT( mapper, mapped( int ), this, invoke( int ) );
454

455 456 457
    btnMore = new LocationButton( "...", false, true, this );
    menuMore = new QMenu( this );
    btnMore->setMenu( menuMore );
458 459 460 461
}

void LocationBar::setIndex( const QModelIndex &index )
{
462 463
    qDeleteAll( buttons );
    buttons.clear();
464 465 466
    qDeleteAll( actions );
    actions.clear();

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
467
    QModelIndex i = index;
468 469
    bool first = true;

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
470 471 472 473 474 475 476
    while( true )
    {
        PLItem *item = model->getItem( i );

        char *fb_name = input_item_GetTitleFbName( item->inputItem() );
        QString text = qfu(fb_name);
        free(fb_name);
477 478

        QAbstractButton *btn = new LocationButton( text, first, !first, this );
479
        btn->setSizePolicy( QSizePolicy::Maximum, QSizePolicy::Fixed );
480
        buttons.append( btn );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
481

482 483 484
        QAction *action = new QAction( text, this );
        actions.append( action );
        CONNECT( btn, clicked(), action, trigger() );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
485

486 487 488 489
        mapper->setMapping( action, item->id() );
        CONNECT( action, triggered(), mapper, map() );

        first = false;
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
490 491 492 493

        if( i.isValid() ) i = i.parent();
        else break;
    }
494 495 496 497 498 499 500 501 502

    QString prefix;
    for( int a = actions.count() - 1; a >= 0 ; a-- )
    {
        actions[a]->setText( prefix + actions[a]->text() );
        prefix += QString("  ");
    }

    if( isVisible() ) layOut( size() );
503 504
}

505 506 507 508 509
void LocationBar::setRootIndex()
{
    setIndex( QModelIndex() );
}

510 511
void LocationBar::invoke( int i_id )
{
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
512 513
    QModelIndex index = model->index( i_id, 0 );
    emit invoked ( index );
514
}
515

516 517 518
void LocationBar::layOut( const QSize& size )
{
    menuMore->clear();
519
    widths.clear();
520 521 522 523 524 525

    int count = buttons.count();
    int totalWidth = 0;
    for( int i = 0; i < count; i++ )
    {
        int w = buttons[i]->sizeHint().width();
526 527
        widths.append( w );
        totalWidth += w;
528 529 530 531 532
        if( totalWidth > size.width() ) break;
    }

    int x = 0;
    int shown = widths.count();
533 534

    if( totalWidth > size.width() && count > 1 )
535 536 537 538 539 540 541 542 543 544 545 546 547
    {
        QSize sz = btnMore->sizeHint();
        btnMore->setGeometry( 0, 0, sz.width(), size.height() );
        btnMore->show();
        x = sz.width();
        totalWidth += x;
    }
    else
    {
        btnMore->hide();
    }
    for( int i = count - 1; i >= 0; i-- )
    {
548
        if( totalWidth <= size.width() || i == 0)
549
        {
550 551 552
            buttons[i]->setGeometry( x, 0, qMin( size.width() - x, widths[i] ), size.height() );
            buttons[i]->show();
            x += widths[i];
553 554 555 556
            totalWidth -= widths[i];
        }
        else
        {
557 558 559
            menuMore->addAction( actions[i] );
            buttons[i]->hide();
            if( i < shown ) totalWidth -= widths[i];
560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576
        }
    }
}

void LocationBar::resizeEvent ( QResizeEvent * event )
{
    layOut( event->size() );
}

QSize LocationBar::sizeHint() const
{
    return btnMore->sizeHint();
}

LocationButton::LocationButton( const QString &text, bool bold,
                                bool arrow, QWidget * parent )
  : b_arrow( arrow ), QPushButton( parent )
577 578 579 580
{
    QFont font;
    font.setBold( bold );
    setFont( font );
581
    setText( text );
582 583
}

Jakob Leben's avatar
Jakob Leben committed
584 585
#define PADDING 4

586 587 588 589 590 591
void LocationButton::paintEvent ( QPaintEvent * event )
{
    QStyleOptionButton option;
    option.initFrom( this );
    option.state |= QStyle::State_Enabled;
    QPainter p( this );
Jakob Leben's avatar
Jakob Leben committed
592

593
    if( underMouse() )
594 595 596 597 598 599 600 601 602 603
    {
        p.save();
        p.setRenderHint( QPainter::Antialiasing, true );
        QColor c = palette().color( QPalette::Highlight );
        p.setPen( c );
        p.setBrush( c.lighter( 150 ) );
        p.setOpacity( 0.2 );
        p.drawRoundedRect( option.rect.adjusted( 0, 2, 0, -2 ), 5, 5 );
        p.restore();
    }
Jakob Leben's avatar
Jakob Leben committed
604

605
    QRect r = option.rect.adjusted( PADDING, 0, -PADDING - (b_arrow ? 10 : 0), 0 );
Jakob Leben's avatar
Jakob Leben committed
606 607 608 609

    QString str( text() );
    /* This check is absurd, but either it is not done properly inside elidedText(),
       or boundingRect() is wrong */
610 611 612
    if( r.width() < fontMetrics().boundingRect( text() ).width() )
        str = fontMetrics().elidedText( text(), Qt::ElideRight, r.width() );
    p.drawText( r, Qt::AlignVCenter | Qt::AlignLeft, str );
Jakob Leben's avatar
Jakob Leben committed
613

614 615
    if( b_arrow )
    {
616 617
        option.rect.setWidth( 10 );
        option.rect.moveRight( rect().right() );
618 619
        style()->drawPrimitive( QStyle::PE_IndicatorArrowRight, &option, &p );
    }
620 621 622 623
}

QSize LocationButton::sizeHint() const
{
624
    QSize s( fontMetrics().boundingRect( text() ).size() );
Jakob Leben's avatar
Jakob Leben committed
625 626
    /* Add two pixels to width: font metrics are buggy, if you pass text through elidation
       with exactly the width of its bounding rect, sometimes it still elides */
627 628
    s.setWidth( s.width() + ( 2 * PADDING ) + ( b_arrow ? 10 : 0 ) + 2 );
    s.setHeight( s.height() + 2 * PADDING );
629 630
    return s;
}
Jakob Leben's avatar
Jakob Leben committed
631 632

#undef PADDING