Panel.cpp 2.96 KB
Newer Older
1 2 3
/*****************************************************************************
 * Panel.cpp: a simple panel with buttons
 *****************************************************************************
Ludovic Fauvet's avatar
Ludovic Fauvet committed
4
 * Copyright (C) 2008-2010 VideoLAN
5 6
 *
 * Authors: Clement CHAVANCE <kinder@vlmc.org>
7
 *          Ludovic Fauvet <etix@l0cal.com>
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
 *
 * 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.
 *****************************************************************************/
23

24
#include "Panel.h"
25
#include "Settings.h"
26

27 28 29 30 31 32 33 34 35 36 37
#include <QWidget>
#include <QVBoxLayout>
#include <QButtonGroup>
#include <QIcon>
#include <QString>
#include <QToolButton>
#include <QSizePolicy>
#include <QSize>

const int   Panel::M_ICON_HEIGHT = 64;

Ludovic Fauvet's avatar
Ludovic Fauvet committed
38
Panel::Panel( QWidget* parent ) : QWidget( parent )
39 40 41 42 43 44 45
{
    m_layout = new QVBoxLayout( this );
    m_buttons = new QButtonGroup( this );

    m_buttons->setExclusive( true );
    m_layout->setMargin( 0 );
    m_layout->setSpacing( 1 );
46
    m_layout->insertSpacerItem( 1, new QSpacerItem( 1, 1, QSizePolicy::Minimum, QSizePolicy::Expanding ) );
47

48
    connect( m_buttons, SIGNAL( buttonPressed(int) ),
Ludovic Fauvet's avatar
Ludovic Fauvet committed
49
             this, SIGNAL( changePanel(int) ) );
50

51
    setSizePolicy( QSizePolicy::Expanding,
52
                   QSizePolicy::Expanding );
53 54
}

55 56
void
Panel::addButton( const char* name,
57
                          const QIcon& icon,
58
                          int index )
59 60 61
{
    QToolButton*    button = new QToolButton( this );

62 63
    m_buttonsNames[button] = name;
    button->setText( tr( name ) );
64
    button->setIcon( icon );
65 66 67 68 69 70
    button->setAutoRaise( true );
    button->setCheckable( true );
    button->setIconSize( QSize( Panel::M_ICON_HEIGHT,
                                Panel::M_ICON_HEIGHT) );
    button->setToolButtonStyle( Qt::ToolButtonTextUnderIcon  );
    button->setSizePolicy( QSizePolicy::Expanding,
71 72
                           QSizePolicy::Minimum );

73
    if ( m_buttons->buttons().isEmpty() )
74
        button->setChecked( true );
75

76
    m_buttons->addButton( button, index );
77
    m_layout->insertWidget( m_layout->count() - 1, button );
78 79
}

80 81 82 83 84 85 86 87 88 89 90 91
void
Panel::retranslate()
{
    QMap<QToolButton*, const char*>::iterator       it = m_buttonsNames.begin();
    QMap<QToolButton*, const char*>::iterator       ite = m_buttonsNames.end();

    while ( it != ite )
    {
        it.key()->setText( Settings::tr( it.value() ) );
        ++it;
    }
}