[vlmc-devel] commit: Preferences: Reworked UI. (Hugo Beauzee-Luyssen )
git at videolan.org
git at videolan.org
Thu Mar 18 14:34:01 CET 2010
vlmc | branch: master | Hugo Beauzee-Luyssen <beauze.h at gmail.com> | Thu Mar 18 14:32:58 2010 +0100| [a1b6fe8f01610feb6f3b25fcdc134576cfe1ae92] | committer: Hugo Beauzee-Luyssen
Preferences: Reworked UI.
Fields are now extending along with the window, many useless
layout/widget has been removed.
> http://git.videolan.org/gitweb.cgi/vlmc.git/?a=commit;h=a1b6fe8f01610feb6f3b25fcdc134576cfe1ae92
---
src/Gui/settings/KeyboardShortcutInput.cpp | 1 +
src/Gui/settings/PreferenceWidget.cpp | 11 ++-
src/Gui/settings/PreferenceWidget.h | 4 +-
src/Gui/settings/Settings.cpp | 84 ++++++++-------------------
src/Gui/settings/Settings.h | 15 ++---
5 files changed, 40 insertions(+), 75 deletions(-)
diff --git a/src/Gui/settings/KeyboardShortcutInput.cpp b/src/Gui/settings/KeyboardShortcutInput.cpp
index e6bb7c4..5569a4b 100644
--- a/src/Gui/settings/KeyboardShortcutInput.cpp
+++ b/src/Gui/settings/KeyboardShortcutInput.cpp
@@ -42,6 +42,7 @@ KeyboardShortcutInput::KeyboardShortcutInput( const QString& name,
QKeySequence ks( initialValue );
for ( int i = 0; i < 4; ++i )
m_shortcuts[i] = ks[i];
+ setMaximumWidth( 300 );
}
void KeyboardShortcutInput::mousePressEvent( QMouseEvent* )
diff --git a/src/Gui/settings/PreferenceWidget.cpp b/src/Gui/settings/PreferenceWidget.cpp
index 7e026dc..70e443c 100644
--- a/src/Gui/settings/PreferenceWidget.cpp
+++ b/src/Gui/settings/PreferenceWidget.cpp
@@ -40,12 +40,14 @@
PreferenceWidget::PreferenceWidget( const QString &categorie, SettingsManager::Type type,
QWidget *parent ) :
- QWidget( parent ),
+ QScrollArea( parent ),
m_categorie( categorie )
{
+ QWidget *container = new QWidget( this );
SettingsManager::SettingHash settings =
SettingsManager::getInstance()->group( categorie, type );
- QFormLayout *layout = new QFormLayout( this );
+ QFormLayout *layout = new QFormLayout( container );
+ layout->setFieldGrowthPolicy( QFormLayout::AllNonFixedFieldsGrow );
foreach ( SettingValue* s, settings.values() )
{
ISettingsCategorieWidget *widget = widgetFactory( s );
@@ -55,9 +57,10 @@ PreferenceWidget::PreferenceWidget( const QString &categorie, SettingsManager::T
layout->addRow( label, widget->widget() );
m_settings.push_back( widget );
}
- setLayout( layout );
+ setWidget( container );
+ setWidgetResizable( true );
+ setFrameStyle( QFrame::NoFrame );
m_categorie[0] = m_categorie[0].toUpper();
-
}
ISettingsCategorieWidget*
diff --git a/src/Gui/settings/PreferenceWidget.h b/src/Gui/settings/PreferenceWidget.h
index 99657b7..255c3af 100644
--- a/src/Gui/settings/PreferenceWidget.h
+++ b/src/Gui/settings/PreferenceWidget.h
@@ -25,14 +25,14 @@
#ifndef PREFERENCEWIDGET_H
#define PREFERENCEWIDGET_H
-#include <QWidget>
+#include <QScrollArea>
#include <QString>
#include "SettingsManager.h"
class ISettingsCategorieWidget;
class SettingValue;
-class PreferenceWidget : public QWidget
+class PreferenceWidget : public QScrollArea
{
Q_OBJECT
public:
diff --git a/src/Gui/settings/Settings.cpp b/src/Gui/settings/Settings.cpp
index 74f4878..c78af64 100644
--- a/src/Gui/settings/Settings.cpp
+++ b/src/Gui/settings/Settings.cpp
@@ -27,20 +27,19 @@
#include "SettingsManager.h"
#include "Panel.h"
+#include <QApplication>
#include <QDialogButtonBox>
#include <QAbstractButton>
#include <QIcon>
#include <QLabel>
#include <QScrollArea>
#include <QHBoxLayout>
+#include <QStackedLayout>
#include <QtDebug>
-
-
Settings::Settings( SettingsManager::Type type, QWidget* parent, Qt::WindowFlags f ) :
QDialog( parent, f ),
- m_currentWidget( NULL ),
m_type( type )
{
setMinimumHeight( 400 );
@@ -54,81 +53,54 @@ Settings::Settings( SettingsManager::Type type, QWidget* parent, Qt::WindowFlags
connect( m_buttons, SIGNAL( clicked( QAbstractButton* ) ),
this, SLOT( buttonClicked( QAbstractButton* ) ) );
-
// Create the layout
- setLayout( buildLayout() );
+ buildLayout();
connect( m_panel, SIGNAL( changePanel( int ) ),
this, SLOT( switchWidget( int ) ) );
}
-Settings::~Settings()
-{
-}
-
void Settings::addCategorie( const QString& name,
SettingsManager::Type type,
const QIcon& icon,
const QString& label )
{
PreferenceWidget *pWidget = new PreferenceWidget( name, type, this );
- // We don't want the widget to be visible
- pWidget->hide();
-
- // Add the widget to the list
- m_pWidgets.append( pWidget );
+ m_stackedLayout->addWidget( pWidget );
// Create a button linked to the widget using its index
- m_panel->addButton( label, icon, m_pWidgets.indexOf( pWidget ) );
-
- // If this is the first widget, show it by default.
- if ( m_pWidgets.count() == 1 )
- switchWidget( 0 );
+ m_panel->addButton( label, icon, m_stackedLayout->count() - 1 );
}
-void Settings::show()
-{
- emit loadSettings();
- switchWidget( 0 );
- QWidget::show();
-}
-
-QHBoxLayout* Settings::buildLayout()
+void
+Settings::buildLayout()
{
// Create the left panel
m_panel = new Panel( this );
m_panel->setMaximumWidth( 130 );
// Create the master layout
- QHBoxLayout* hLayout = new QHBoxLayout( this );
- hLayout->addWidget( m_panel );
+ QGridLayout* mLayout = new QGridLayout( this );
+ mLayout->addWidget( m_panel, 0, 0, 2, 1 );
- // Right Sub-layout
- QVBoxLayout* vLayout = new QVBoxLayout;
m_title = new QLabel( this );
- m_configPanel = new QScrollArea( this );
- m_configPanel->setFrameShape( QFrame::NoFrame );
+ m_stackedLayout = new QStackedLayout;
// Set the font and text of the panel title
- QFont labelFont = font();
- labelFont.setPointSize( labelFont.pointSize() + 6 );
- labelFont.setFamily( "Verdana" );
- m_title->setFont( labelFont );
- m_title->setText( "Empty" );
-
- vLayout->addWidget( m_title );
- vLayout->addWidget( m_configPanel );
- vLayout->addWidget( m_buttons );
-
- hLayout->insertLayout( -1, vLayout );
-
- return hLayout;
+ QFont titleFont = QApplication::font();
+ titleFont.setPointSize( titleFont.pointSize() + 6 );
+ titleFont.setFamily( "Verdana" );
+ m_title->setFont( titleFont );
+
+ mLayout->addWidget( m_title, 0, 1, 1, 2 );
+ mLayout->addLayout( m_stackedLayout, 1, 2, 1, 2 );
+ mLayout->addWidget( m_buttons, 2, 2 );
}
void Settings::buttonClicked( QAbstractButton* button )
{
bool save = false;
- bool hide = false ;
+ bool hide = false;
switch ( m_buttons->standardButton( button ) )
{
@@ -148,8 +120,8 @@ void Settings::buttonClicked( QAbstractButton* button )
if ( save == true )
{
// Ask each widget to save their state
- for ( int i = 0; i < m_pWidgets.count(); ++i )
- m_pWidgets.at( i )->save();
+ for ( int i = 0; i < m_stackedLayout->count(); ++i )
+ qobject_cast<PreferenceWidget*>( m_stackedLayout->widget( i ) )->save();
//If we're handling vlmc preferences, save the value in the QSettings
if ( m_type == SettingsManager::Vlmc )
SettingsManager::getInstance()->save();
@@ -160,17 +132,11 @@ void Settings::buttonClicked( QAbstractButton* button )
void Settings::switchWidget( int index )
{
- PreferenceWidget* pWidget = m_pWidgets.at( index );
+ PreferenceWidget* pWidget =
+ qobject_cast<PreferenceWidget*>( m_stackedLayout->widget( index ) );
- // This should never happen
- if ( !pWidget )
- return;
+ Q_ASSERT( pWidget != NULL );
m_title->setText( pWidget->categorie() );
- // If there is already a widget into the QScrollArea take it
- // to avoid its deletion.
- if ( m_configPanel->widget() )
- m_configPanel->takeWidget();
-
- m_configPanel->setWidget( pWidget );
+ m_stackedLayout->setCurrentIndex( index );
}
diff --git a/src/Gui/settings/Settings.h b/src/Gui/settings/Settings.h
index f825dcb..98ee786 100644
--- a/src/Gui/settings/Settings.h
+++ b/src/Gui/settings/Settings.h
@@ -28,13 +28,13 @@
#include <QDialog>
#include <QString>
-#include <QList>
+class QAbstractButton;
class QDialogButtonBox;
+class QGridLayout;
class QLabel;
-class QHBoxLayout;
-class QAbstractButton;
class QScrollArea;
+class QStackedLayout;
class Panel;
class PreferenceWidget;
@@ -46,24 +46,19 @@ class Settings : public QDialog
public:
Settings( SettingsManager::Type type, QWidget* parent = 0, Qt::WindowFlags f = 0 );
- virtual ~Settings();
void addCategorie( const QString& name,
SettingsManager::Type type,
const QIcon& icon,
const QString& label );
- void show();
-
private:
- inline QHBoxLayout* buildLayout();
+ void buildLayout();
private:
QDialogButtonBox* m_buttons;
- QList<PreferenceWidget*> m_pWidgets;
- PreferenceWidget* m_currentWidget;
Panel* m_panel;
QLabel* m_title;
- QScrollArea* m_configPanel;
+ QStackedLayout *m_stackedLayout;
SettingsManager::Type m_type;
public slots:
More information about the Vlmc-devel
mailing list