Commit d21b785c authored by Clement CHAVANCE's avatar Clement CHAVANCE

refactored class PreferencePanel and added a preferences window for testing it

class PreferencePanel is now class Panel.
TODO : refactor the SimplePreferences class and test it.
parent 5a0a77af
......@@ -20,8 +20,8 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#include "Preferences.h"
#include "ui_Preferences.h"
#include "LanguagePreferences.h"
#include "ui_LanguagePreferences.h"
QTranslator* Preferences::m_currentLang = NULL;
Preferences* Preferences::m_instance = NULL;
......
......@@ -28,7 +28,7 @@
#include <QApplication>
#include <QSettings>
#include <QtDebug>
#include "ui_Preferences.h"
#include "ui_LanguagePreferences.h"
class Preferences : public QDialog
{
......@@ -43,7 +43,7 @@ protected:
private:
explicit Preferences( QWidget *parent = 0 );
Ui::Preferences m_ui;
Ui::LanguagePreferences m_ui;
static QTranslator* m_currentLang;
static Preferences* m_instance;
......
......@@ -44,6 +44,7 @@ MainWindow::MainWindow( QWidget *parent ) :
DockWidgetManager::instance( this )->setMainWindow( this );
m_initializeDockWidgets();
createStatusBar();
createGlobalPreferences();
// Translation
connect( this, SIGNAL( translateDockWidgetTitle() ),
......@@ -56,6 +57,12 @@ MainWindow::MainWindow( QWidget *parent ) :
this, SLOT( zoomIn() ) );
connect( m_timeline->tracksView(), SIGNAL( zoomOut() ),
this, SLOT( zoomOut() ) );
//Global Preferences
QObject::connect( qApp,
SIGNAL( aboutToQuit() ),
m_globalPreferences,
SLOT( deleteLater() ) );
}
MainWindow::~MainWindow()
......@@ -153,6 +160,21 @@ void MainWindow::m_initializeDockWidgets( void )
m_metaDataManager = MetaDataManager::getInstance();
}
void MainWindow::createGlobalPreferences()
{
m_globalPreferences = new SimplePreferences( );
m_globalPreferences->addWidget("language",
Preferences::instance(),
"images/vlmc.png",
"Language");
//For debugging purpose
m_globalPreferences->addWidget("language",
new QWidget,
"images/vlmc.png",
"Language");
m_globalPreferences->build();
}
//Private slots definition
void MainWindow::on_actionQuit_triggered()
......@@ -162,7 +184,7 @@ void MainWindow::on_actionQuit_triggered()
void MainWindow::on_actionPreferences_triggered()
{
Preferences::instance()->exec();
m_globalPreferences->show();
}
void MainWindow::on_actionAbout_triggered()
......
......@@ -29,10 +29,11 @@
#include "ui_MainWindow.h"
#include "DockWidgetManager.h"
#include "Preferences.h"
#include "LanguagePreferences.h"
#include "MetaDataManager.h"
#include "Timeline.h"
#include "WorkflowFileRenderer.h"
#include "SimplePreferences.h"
class MainWindow : public QMainWindow
......@@ -55,6 +56,7 @@ private:
void m_initializeDockWidgets( void );
void setupLibrary();
void createStatusBar();
void createGlobalPreferences();
Ui::MainWindow m_ui;
......@@ -62,6 +64,7 @@ private:
QSlider* m_zoomSlider;
Timeline* m_timeline;
WorkflowFileRenderer* m_renderer;
SimplePreferences* m_globalPreferences;
private slots:
void on_actionFullscreen_triggered( bool checked );
......
#include <QWidget>
#include <QVBoxLayout>
#include <QButtonGroup>
#include <QLabel>
#include <QIcon>
#include <QString>
#include <QToolButton>
#include <QSizePolicy>
#include <QSize>
//DEBUG
#include <QtDebug>
//~DEBUG
#include "Panel.h"
const int Panel::M_ICON_HEIGHT = 64;
Panel::Panel( QWidget* parent )
: QWidget( parent ),
m_layout( 0 ),
m_buttons( 0 ),
m_firstButton( 0 ),
m_firstButtonNb( 0 )
{
m_layout = new QVBoxLayout( this );
m_buttons = new QButtonGroup( this );
m_buttons->setExclusive( true );
m_layout->setMargin( 0 );
m_layout->setSpacing( 1 );
QObject::connect( m_buttons,
SIGNAL( buttonClicked( int ) ),
this,
SLOT( switchPanel( int ) ) );
setSizePolicy( QSizePolicy::Expanding,
QSizePolicy::Expanding );
setLayout( m_layout );
}
Panel::~Panel()
{
delete m_layout;
delete m_buttons;
}
void Panel::addButton( const QString& label,
const QString& iconPath,
int number)
{
QToolButton* button = new QToolButton( this );
button->setText( label );
button->setIcon( QIcon( iconPath ) );
button->setAutoRaise( true );
button->setCheckable( true );
button->setIconSize( QSize( Panel::M_ICON_HEIGHT,
Panel::M_ICON_HEIGHT) );
button->setToolButtonStyle( Qt::ToolButtonTextUnderIcon );
button->resize( Panel::M_ICON_HEIGHT + 6,
Panel::M_ICON_HEIGHT + 6 );
button->setSizePolicy( QSizePolicy::Expanding,
QSizePolicy::Expanding );
if ( m_firstButton == 0 )
{
button->setChecked( true );
m_firstButton = button;
m_firstButtonNb = number;
}
m_buttons->addButton( button, number );
m_layout->addWidget( button );
}
void Panel::show()
{
if ( !m_firstButton->isChecked() )
{
m_firstButton->setChecked( true );
emit changePanel( m_firstButtonNb );
}
QWidget::show();
}
void Panel::switchPanel( int panel )
{
emit changePanel( panel );
}
#ifndef PANEL_H
#define PANEL_H
#include <QWidget>
#include <QVBoxLayout>
#include <QButtonGroup>
#include <QString>
#include <QToolButton>
class Panel : public QWidget
{
Q_OBJECT
Q_DISABLE_COPY( Panel )
public:
Panel( QWidget* parent = 0 );
~Panel();
void addButton( const QString& label,
const QString& iconPath,
int number);
void show();
private:
QVBoxLayout* m_layout;
QButtonGroup* m_buttons;
QToolButton* m_firstButton;
int m_firstButtonNb;
static const int M_ICON_HEIGHT;
private slots:
void switchPanel( int panel );
signals:
void changePanel( int panel );
};
#endif /* !PANEL_H */
......@@ -22,65 +22,19 @@
#include <QPushButton>
#include <QDialogButtonBox>
#include <QApplication>
#include <QSizePolicy>
#include <QLabel>
#include <QHash>
#include <QIcon>
#include <QLabel>
#include "SimplePreferences.h"
/********************************************************************************
PreferencesPanel
********************************************************************************/
const int PreferencesPanel::ICON_HEIGHT = 64;
PreferencesPanel::PreferencesPanel( QWidget* parent )
: QWidget( parent ),
m_nbPanel(0)
{
m_layout = new QVBoxLayout( this );
m_buttonGroup = new QButtonGroup( this );
QObject::connect( m_buttonGroup, SIGNAL( buttonClicked( int ) ),
this, SLOT( switchPanel( int ) ) );
setLayout( m_layout );
}
PreferencesPanel::~PreferencesPanel()
{
delete m_layout;
delete m_buttonGroup;
}
void PreferencesPanel::addPanel( const QString& icon,
const QString& label,
const QString& name)
{
QPushButton* button = new QPushButton( this );
++m_nbPanel;
//button->setIcon(IconPath + icon);
button->setText( label );
button->resize( ICON_HEIGHT + 6, ICON_HEIGHT + 6 );
m_panels.insert( m_nbPanel, name );
m_buttonGroup->addButton( button, m_nbPanel );
m_layout->addWidget( button );
}
void PreferencesPanel::switchPanel( int panel )
{
if ( !m_panels.contains( panel ) )
return ;
emit panelSwitched( m_panels.value( panel ) );
}
/********************************************************************************
SimplePreferences
********************************************************************************/
SimplePreferences::SimplePreferences()
: m_currentWidget( NULL ),
SimplePreferences::SimplePreferences( QWidget* parent)
: QWidget(parent),
m_currentWidget( NULL ),
m_panel(NULL)
{
m_panel = new PreferencesPanel( this );
......@@ -88,10 +42,10 @@ SimplePreferences::SimplePreferences()
SimplePreferences::~SimplePreferences()
{
QHash<QString, QWidget*>::iterator end = m_widgets.end();
QHash<QString, QWidget*>::iterator it = m_widgets.begin();
for ( ; it != end; ++it )
delete it.value();
//QHash<QString, QWidget*>::iterator end = m_widgets.end();
//QHash<QString, QWidget*>::iterator it = m_widgets.begin();
//for ( ; it != end; ++it )
// delete it.value();
delete m_panel;
delete m_title;
}
......@@ -115,6 +69,8 @@ void SimplePreferences::addWidget( const QString& name,
m_widgets.remove( name );
m_widgets.insert( name, widget );
m_panel->addPanel( icon, label, name );
if (m_currentWidget == 0)
m_currentWidget = widget;
}
void SimplePreferences::build()
......@@ -123,15 +79,17 @@ void SimplePreferences::build()
qFatal( "Can't build the preference panel without an added widget" );
QHBoxLayout* hLayout = new QHBoxLayout( this );
PreferencesPanel* prefPanel = new PreferencesPanel( this );
setLayout( hLayout );
//TODO : change the size of the widgets to make it look cleaner
hLayout->addWidget( prefPanel );
hLayout->addLayout( buildRightHLayout() );
//hLayout->addWidget( prefPanel );
//hLayout->addWidget( m_currentWidget );
hLayout->insertLayout( 1, buildRightHLayout() );
}
QVBoxLayout* SimplePreferences::buildRightHLayout()
{
QVBoxLayout* layout = new QVBoxLayout( this );
QVBoxLayout* layout = new QVBoxLayout;
QFrame* titleLine = new QFrame;
QDialogButtonBox* buttons = new QDialogButtonBox( this );
......@@ -150,7 +108,7 @@ QVBoxLayout* SimplePreferences::buildRightHLayout()
QDialogButtonBox::Apply );
layout->addWidget( m_title );
layout->addWidget( m_title );
layout->addWidget( titleLine );
layout->addWidget( m_currentWidget );
layout->addWidget( buttons );
return ( layout );
......
......@@ -30,40 +30,13 @@
#include <QVBoxLayout>
#include <QButtonGroup>
class PreferencesPanel : public QWidget
{
Q_OBJECT
Q_DISABLE_COPY( PreferencesPanel )
public:
PreferencesPanel( QWidget* parent = 0 );
~PreferencesPanel();
void addPanel( const QString& icon,
const QString& label,
const QString& name );
static const int ICON_HEIGHT;
private:
int m_nbPanel;
QVBoxLayout* m_layout;
QButtonGroup* m_buttonGroup;
QHash<int, QString> m_panels;
private slots:
void switchPanel( int panel );
signals:
void panelSwitched( const QString& panel );
};
class SimplePreferences : public QWidget
{
Q_OBJECT
Q_DISABLE_COPY( SimplePreferences )
public:
SimplePreferences();
SimplePreferences( QWidget* parent = 0 );
~SimplePreferences();
QWidget* getWidget( const QString& name ) const;
void addWidget( const QString& name,
......
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Preferences</class>
<widget class="QDialog" name="Preferences">
<class>LanguagePreferences</class>
<widget class="QDialog" name="LanguagePreferences">
<property name="geometry">
<rect>
<x>0</x>
......
......@@ -23,7 +23,7 @@ SOURCES += src/main.cpp \
src/gui/TracksScene.cpp \
src/gui/ClipPreviewWidget.cpp \
src/gui/TracksRuler.cpp \
src/gui/Preferences.cpp \
src/gui/LanguagePreferences.cpp \
src/gui/ListViewMediaItem.cpp \
src/gui/MediaListWidget.cpp \
src/Clip.cpp \
......@@ -60,7 +60,7 @@ HEADERS += src/gui/MainWindow.h \
src/gui/TracksScene.h \
src/gui/ClipPreviewWidget.h \
src/gui/TracksRuler.h \
src/gui/Preferences.h \
src/gui/LanguagePreferences.h \
src/gui/ListViewMediaItem.h \
src/Clip.h \
src/Image.h \
......@@ -93,7 +93,7 @@ HEADERS += src/gui/MainWindow.h \
src/gui/SimplePreferences.h
FORMS += src/gui/ui/MainWindow.ui \
src/gui/ui/PreviewWidget.ui \
src/gui/ui/Preferences.ui \
src/gui/ui/LanguagePreferences.ui \
src/gui/ui/Timeline.ui \
src/gui/ui/LibraryWidget.ui \
src/gui/ui/About.ui \
......
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