Commit ff832749 authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen

Handle docked widget directly from MainWindow

This is way simpler.
Also, this paves the way for a better translation handling from within
the mainwindow
parent 9988f26d
......@@ -109,7 +109,6 @@ ELSE(NOT WITH_GUI)
Gui/About.cpp
Gui/AudioSpectrumDrawer.cpp
Gui/ClipProperty.cpp
Gui/DockWidgetManager.cpp
Gui/IntroDialog.cpp
Gui/LanguageHelper.cpp
Gui/MainWindow.cpp
......
/*****************************************************************************
* DockWidgetManager.cpp: Object managing the application docked widget
*****************************************************************************
* Copyright (C) 2008-2014 VideoLAN
*
* 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.
*****************************************************************************/
#include <QApplication>
#include <QMap>
#include <QMapIterator>
#include <QDockWidget>
#include "DockWidgetManager.h"
#include "MainWindow.h"
DockWidgetManager::DockWidgetManager( QObject *parent )
: QObject( parent )
{
QObject::connect( qApp,
SIGNAL( aboutToQuit() ),
this,
SLOT( deleteLater() ) );
}
DockWidgetManager::~DockWidgetManager()
{
qDeleteAll( m_dockWidgets );
}
void
DockWidgetManager::setMainWindow( MainWindow *mainWin )
{
m_mainWin = mainWin;
}
QDockWidget*
DockWidgetManager::createDockedWidget( const char *qs_name,
Qt::DockWidgetAreas areas,
QDockWidget::DockWidgetFeature features )
{
if ( m_dockWidgets.contains( qs_name ) )
return NULL;
QDockWidget* dock = new QDockWidget( tr( qs_name ), m_mainWin );
dock->setObjectName( QString( "docked_" ) + qs_name );
dock->setAllowedAreas( areas );
dock->setFeatures( features );
m_dockWidgets.insert( qs_name, dock );
return dock;
}
void
DockWidgetManager::addDockedWidget( QDockWidget *dockWidget, QWidget *containedWidget, Qt::DockWidgetArea startArea )
{
dockWidget->setWidget( containedWidget );
m_mainWin->addDockWidget( startArea, dockWidget );
m_mainWin->registerWidgetInWindowMenu( dockWidget );
}
void
DockWidgetManager::retranslateUi()
{
QMapIterator<const char*, QDockWidget*> i( m_dockWidgets );
while ( i.hasNext() )
{
i.next();
i.value()->setWindowTitle( tr( i.key() ) );
}
}
/*****************************************************************************
* DockWidgetManager.h: Object managing the application docked widget
*****************************************************************************
* Copyright (C) 2008-2014 VideoLAN
*
* 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.
*****************************************************************************/
#ifndef DOCKWIDGETMANAGER_H
#define DOCKWIDGETMANAGER_H
#include "Tools/QSingleton.hpp"
#include <QObject>
#include <QWidget>
#include <QDockWidget>
#include <QString>
#include <QMap>
class MainWindow;
class DockWidgetManager : public QObject, public QSingleton<DockWidgetManager>
{
Q_OBJECT
Q_DISABLE_COPY( DockWidgetManager );
public:
void setMainWindow( MainWindow *mainWin );
QDockWidget* createDockedWidget( const char *qs_name,
Qt::DockWidgetAreas areas,
QDockWidget::DockWidgetFeature features );
void addDockedWidget( QDockWidget *dockWidget, QWidget *containedWidget,
Qt::DockWidgetArea startArea );
void retranslateUi();
private:
explicit DockWidgetManager( QObject *parent = 0 );
virtual ~DockWidgetManager();
MainWindow *m_mainWin;
QMap<const char*, QDockWidget*> m_dockWidgets;
friend class QSingleton<DockWidgetManager>;
};
#endif
......@@ -54,7 +54,6 @@
#include "settings/SettingsDialog.h"
/* Widgets */
#include "DockWidgetManager.h"
#include "effectsengine/EffectsListView.h"
#include "import/ImportController.h"
#include "library/MediaLibrary.h"
......@@ -89,7 +88,6 @@ MainWindow::MainWindow( Backend::IBackend* backend, QWidget *parent )
Core::getInstance()->settings()->load();
// GUI
DockWidgetManager::getInstance( this )->setMainWindow( this );
createGlobalPreferences();
initializeDockWidgets();
initToolbar();
......@@ -127,6 +125,7 @@ MainWindow::MainWindow( Backend::IBackend* backend, QWidget *parent )
restoreGeometry( VLMC_GET_BYTEARRAY( "private/MainWindowGeometry" ) );
// Restore the layout
restoreState( VLMC_GET_BYTEARRAY( "private/MainWindowState" ) );
retranslateUi();
}
MainWindow::~MainWindow()
......@@ -147,14 +146,27 @@ MainWindow::showWizard()
m_wizard->show();
}
void
MainWindow::retranslateUi()
{
m_dockedUndoView->setWindowTitle( tr( "History" ) );
m_dockedEffectsList->setWindowTitle( tr( "Effects List" ) );
m_dockedLibrary->setWindowTitle( "Media Library" );
m_dockedClipPreview->setWindowTitle( "Clip Preview" );
m_dockedProjectPreview->setWindowTitle( "Project Preview" );
}
void
MainWindow::changeEvent( QEvent *e )
{
switch ( e->type() )
{
case QEvent::LanguageChange:
// Translate m_ui as a separate step to avoid calling it twice upon first
// creation. We call retranslateUi() from MainWindow's constructor, but we also initialize
// m_ui, which calls m_ui.retranslateUi()
m_ui.retranslateUi( this );
DockWidgetManager::getInstance()->retranslateUi();
retranslateUi();
break;
default:
break;
......@@ -397,7 +409,7 @@ MainWindow::createStatusBar()
void
MainWindow::initializeDockWidgets()
{
m_timeline = new Timeline( this );
m_timeline = new Timeline;
m_timeline->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
m_timeline->show();
setCentralWidget( m_timeline );
......@@ -414,66 +426,45 @@ MainWindow::initializeDockWidgets()
void
MainWindow::setupUndoRedoWidget()
{
QDockWidget *dockedWidget = DockWidgetManager::getInstance()->createDockedWidget(
QT_TRANSLATE_NOOP( "DockWidgetManager", "History" ),
Qt::AllDockWidgetAreas,
QDockWidget::AllDockWidgetFeatures );
m_undoView = new QUndoView( dockedWidget );
DockWidgetManager::getInstance()->addDockedWidget( dockedWidget, m_undoView, Qt::TopDockWidgetArea );
m_undoView = new QUndoView;
m_dockedUndoView = dockWidget( m_undoView, Qt::TopDockWidgetArea );
}
void
MainWindow::setupEffectsList()
{
QDockWidget *dockedWidget = DockWidgetManager::getInstance()->createDockedWidget(
QT_TRANSLATE_NOOP( "DockWidgetManager", "Effects List" ),
Qt::AllDockWidgetAreas,
QDockWidget::AllDockWidgetFeatures );
m_effectsList = new EffectsListView( dockedWidget );
m_effectsList = new EffectsListView;
m_effectsList->setType( Effect::Filter );
Core::getInstance()->effectsEngine()->loadEffects();
DockWidgetManager::getInstance()->addDockedWidget( dockedWidget, m_effectsList, Qt::TopDockWidgetArea );
m_dockedEffectsList = dockWidget( m_effectsList, Qt::TopDockWidgetArea );
}
void
MainWindow::setupLibrary()
{
QDockWidget *dockedLibrary = DockWidgetManager::getInstance()->createDockedWidget(
QT_TRANSLATE_NOOP( "DockWidgetManager", "Media Library" ),
Qt::AllDockWidgetAreas,
QDockWidget::AllDockWidgetFeatures );
m_mediaLibrary = new MediaLibrary( dockedLibrary );
DockWidgetManager::getInstance()->addDockedWidget( dockedLibrary, m_mediaLibrary, Qt::TopDockWidgetArea );
m_mediaLibrary = new MediaLibrary;
m_dockedLibrary = dockWidget( m_mediaLibrary, Qt::TopDockWidgetArea );
}
void
MainWindow::setupClipPreview()
{
QDockWidget *dockedWidget = DockWidgetManager::getInstance()->createDockedWidget(
QT_TRANSLATE_NOOP( "DockWidgetManager", "Clip Preview" ),
Qt::AllDockWidgetAreas,
QDockWidget::AllDockWidgetFeatures );
m_clipPreview = new PreviewWidget( dockedWidget );
m_clipPreview = new PreviewWidget;
m_clipPreview->setRenderer( new ClipRenderer );
KeyboardShortcutHelper* clipShortcut = new KeyboardShortcutHelper( "keyboard/mediapreview", this );
connect( clipShortcut, SIGNAL( activated() ), m_clipPreview, SLOT( on_pushButtonPlay_clicked() ) );
DockWidgetManager::getInstance()->addDockedWidget( dockedWidget, m_clipPreview, Qt::TopDockWidgetArea );
m_dockedClipPreview = dockWidget( m_clipPreview, Qt::TopDockWidgetArea );
}
void
MainWindow::setupProjectPreview()
{
QDockWidget *dockedWidget = DockWidgetManager::getInstance()->createDockedWidget(
QT_TRANSLATE_NOOP( "DockWidgetManager", "Project Preview" ),
Qt::AllDockWidgetAreas,
QDockWidget::AllDockWidgetFeatures );
m_projectPreview = new PreviewWidget( dockedWidget );
m_projectPreview = new PreviewWidget;
m_projectPreview->setClipEdition( false );
KeyboardShortcutHelper* renderShortcut = new KeyboardShortcutHelper( "keyboard/renderpreview", this );
connect( renderShortcut, SIGNAL( activated() ), m_projectPreview, SLOT( on_pushButtonPlay_clicked() ) );
DockWidgetManager::getInstance()->addDockedWidget( dockedWidget, m_projectPreview, Qt::TopDockWidgetArea );
m_dockedProjectPreview = dockWidget( m_projectPreview, Qt::TopDockWidgetArea );
}
void
......@@ -629,6 +620,19 @@ MainWindow::renderVideoSettings( bool shareOnInternet )
return renderVideo( outputFileName, width, height, fps, vbitrate, abitrate );
}
QDockWidget*
MainWindow::dockWidget( QWidget* widget, Qt::DockWidgetArea startArea )
{
QDockWidget* dock = new QDockWidget( this );
dock->setAllowedAreas( Qt::AllDockWidgetAreas );
widget->setParent( dock );
dock->setWidget( widget );
addDockWidget( startArea, dock );
registerWidgetInWindowMenu( dock );
return dock;
}
void
MainWindow::on_actionRender_triggered()
{
......
......@@ -88,6 +88,7 @@ private:
void setupProjectPreview();
void setupEffectsList();
void setupUndoRedoWidget();
void retranslateUi();
#ifdef WITH_CRASHBUTTON
void setupCrashTester();
#endif
......@@ -124,6 +125,8 @@ private:
*/
bool renderVideoSettings( bool exportType );
QDockWidget* dockWidget( QWidget* widget, Qt::DockWidgetArea startArea );
Ui::MainWindow m_ui;
QSlider* m_zoomSlider;
Timeline* m_timeline;
......@@ -139,6 +142,11 @@ private:
MediaLibrary *m_mediaLibrary;
EffectsListView* m_effectsList;
QUndoView* m_undoView;
QDockWidget* m_dockedUndoView;
QDockWidget* m_dockedEffectsList;
QDockWidget* m_dockedLibrary;
QDockWidget* m_dockedClipPreview;
QDockWidget* m_dockedProjectPreview;
private slots:
void on_actionFullscreen_triggered( bool checked );
......
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