DockWidgetManager.cpp 2.68 KB
Newer Older
1
/*****************************************************************************
2
 * DockWidgetManager.cpp: Object managing the application docked widget
3
 *****************************************************************************
Ludovic Fauvet's avatar
Ludovic Fauvet committed
4
 * Copyright (C) 2008-2010 VideoLAN
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
 *
 * Authors: Clement CHAVANCE <chavance.c@gmail.com>
 *
 * 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.
 *****************************************************************************/
22 23 24
#include <QtDebug>
#include <QApplication>
#include <QMap>
25
#include <QMapIterator>
Ludovic Fauvet's avatar
Ludovic Fauvet committed
26
#include <QDockWidget>
27 28

#include "DockWidgetManager.h"
Ludovic Fauvet's avatar
Ludovic Fauvet committed
29
#include "MainWindow.h"
30

Ludovic Fauvet's avatar
Ludovic Fauvet committed
31 32 33 34 35 36 37 38 39 40 41
DockWidgetManager::DockWidgetManager( QObject *parent )
    : QObject( parent )
{
    QObject::connect( qApp,
                      SIGNAL( aboutToQuit() ),
                      this,
                      SLOT( deleteLater() ) );
}

DockWidgetManager::~DockWidgetManager()
{
42
    qDeleteAll( m_dockWidgets );
Ludovic Fauvet's avatar
Ludovic Fauvet committed
43 44
}

45 46
void
DockWidgetManager::setMainWindow( MainWindow *mainWin )
47
{
48
    m_mainWin = mainWin;
49 50
}

51
QDockWidget*
52 53 54
DockWidgetManager::createDockedWidget( const char *qs_name,
                                    Qt::DockWidgetAreas areas,
                                    QDockWidget::DockWidgetFeature features )
55
{
56
    if ( m_dockWidgets.contains( qs_name ) )
57
        return NULL;
58

59
    QDockWidget*    dock = new QDockWidget( tr( qs_name ), m_mainWin );
60

61
    dock->setObjectName( QString( "docked_" ) + qs_name );
62 63
    dock->setAllowedAreas( areas );
    dock->setFeatures( features );
64
    m_dockWidgets.insert( qs_name, dock );
65
    return dock;
66
}
67

68 69 70 71 72 73 74 75
void
DockWidgetManager::addDockedWidget( QDockWidget *dockWidget, QWidget *containedWidget, Qt::DockWidgetArea startArea )
{
    dockWidget->setWidget( containedWidget );
    m_mainWin->addDockWidget( startArea, dockWidget );
    m_mainWin->registerWidgetInWindowMenu( dockWidget );
}

76 77
void
DockWidgetManager::retranslateUi()
78 79 80 81 82 83 84 85 86
{
    QMapIterator<const char*, QDockWidget*> i( m_dockWidgets );

    while ( i.hasNext() )
    {
        i.next();
        i.value()->setWindowTitle( tr( i.key() ) );
    }
}