Commit a15081d9 authored by Christophe Courtaut's avatar Christophe Courtaut

Preferences code cleanup

parent 6b4f2094
...@@ -79,8 +79,7 @@ void MainWindow::on_actionQuit_triggered() ...@@ -79,8 +79,7 @@ void MainWindow::on_actionQuit_triggered()
void MainWindow::on_actionPreferences_triggered() void MainWindow::on_actionPreferences_triggered()
{ {
Preferences* pref = new Preferences(); Preferences::instance()->exec();
pref->show();
} }
void MainWindow::on_actionAbout_triggered() void MainWindow::on_actionAbout_triggered()
......
...@@ -24,19 +24,16 @@ ...@@ -24,19 +24,16 @@
#include "ui_Preferences.h" #include "ui_Preferences.h"
QTranslator* Preferences::m_currentLang = NULL; QTranslator* Preferences::m_currentLang = NULL;
Preferences* Preferences::m_instance = NULL;
Preferences::Preferences( QWidget *parent ) : QWidget( parent ) Preferences::Preferences( QWidget *parent ) : QDialog( parent )
{ {
m_ui.setupUi( this ); m_ui.setupUi( this );
m_ui.comboBoxLanguage->addItem( tr( "English" ), "" ); m_ui.comboBoxLanguage->addItem( tr( "English" ), "" );
m_ui.comboBoxLanguage->addItem( tr( "French" ), "fr" ); m_ui.comboBoxLanguage->addItem( tr( "French" ), "fr" );
m_ui.comboBoxLanguage->addItem( tr( "Spanish" ), "es" ); m_ui.comboBoxLanguage->addItem( tr( "Spanish" ), "es" );
m_ui.comboBoxLanguage->addItem( tr( "Swedish" ), "sv" ); m_ui.comboBoxLanguage->addItem( tr( "Swedish" ), "sv" );
} connect( qApp, SIGNAL( aboutToQuit() ), this, SLOT( deleteLater() ) );
Preferences::~Preferences()
{
} }
void Preferences::changeEvent( QEvent *e ) void Preferences::changeEvent( QEvent *e )
...@@ -52,6 +49,14 @@ void Preferences::changeEvent( QEvent *e ) ...@@ -52,6 +49,14 @@ void Preferences::changeEvent( QEvent *e )
} }
} }
Preferences* Preferences::instance()
{
if ( m_instance )
return m_instance;
m_instance = new Preferences();
return m_instance;
}
void Preferences::on_pushButtonCancel_clicked() void Preferences::on_pushButtonCancel_clicked()
{ {
close(); close();
......
...@@ -30,22 +30,22 @@ ...@@ -30,22 +30,22 @@
#include <QtDebug> #include <QtDebug>
#include "ui_Preferences.h" #include "ui_Preferences.h"
class Preferences : public QWidget class Preferences : public QDialog
{ {
Q_OBJECT Q_OBJECT
Q_DISABLE_COPY( Preferences ) Q_DISABLE_COPY( Preferences )
public: public:
explicit Preferences( QWidget *parent = 0 ); static Preferences* instance();
virtual ~Preferences();
static void changeLang(QString lang); static void changeLang(QString lang);
protected: protected:
virtual void changeEvent( QEvent *e ); virtual void changeEvent( QEvent *e );
private: private:
explicit Preferences( QWidget *parent = 0 );
Ui::Preferences m_ui; Ui::Preferences m_ui;
static QTranslator* m_currentLang; static QTranslator* m_currentLang;
static Preferences* m_instance;
private slots: private slots:
void on_pushButtonCancel_clicked(); void on_pushButtonCancel_clicked();
......
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0"> <ui version="4.0">
<class>Preferences</class> <class>Preferences</class>
<widget class="QWidget" name="Preferences"> <widget class="QDialog" name="Preferences">
<property name="windowModality">
<enum>Qt::ApplicationModal</enum>
</property>
<property name="geometry"> <property name="geometry">
<rect> <rect>
<x>0</x> <x>0</x>
......
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