00001 /* 00002 Copyright © 2010 guillaume belz 00003 00004 This file is part of QExtend. 00005 00006 QExtend is free software: you can redistribute it and/or modify 00007 it under the terms of the GNU General Public License as published by 00008 the Free Software Foundation, either version 3 of the License, or 00009 any later version. 00010 00011 QExtend is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 GNU General Public License for more details. 00015 00016 You should have received a copy of the GNU General Public License 00017 along with QExtend. If not, see <http://www.gnu.org/licenses/>. 00018 */ 00019 00020 #include "standardapplication.hpp" 00021 #include <QtCore/QSettings> 00022 #include <QtGui/QMainWindow> 00023 #include <QtGui/QMenuBar> 00024 #include <QtGui/QAction> 00025 #include <QtGui/QToolBar> 00026 #include <QtGui/QStatusBar> 00027 #include <QExtend/Application/ActionManager> 00028 #include <QExtend/Application/PluginManager> 00029 00030 using namespace QExtend; 00031 00032 class MainWindowPrivate : public QMainWindow 00033 { 00034 private: 00035 QSettings *m_settings; 00036 00037 public: 00038 MainWindowPrivate(QSettings *settings) : QMainWindow(), m_settings(settings) {} 00039 00040 void closeEvent(QCloseEvent *event) 00041 { 00042 Q_UNUSED(event) 00043 00044 if(m_settings) 00045 { 00046 m_settings->beginGroup("MainWindow"); 00047 m_settings->setValue("size", size()); 00048 m_settings->setValue("pos", pos()); 00049 m_settings->endGroup(); 00050 } 00051 } 00052 }; 00053 00054 StandardApplication::StandardApplication(int &argc, char **argv) : 00055 QApplication(argc, argv), 00056 m_options(ObjectPool | Settings | MainWindow | StatusBar | Actions | Plugins), 00057 m_objectPool(), 00058 m_settings(NULL), 00059 m_mainWindow(NULL), 00060 m_actionManager(NULL), 00061 m_pluginManager(NULL) 00062 { 00063 } 00064 00065 int StandardApplication::exec() 00066 { 00067 // create settings 00068 if(option(Settings) && !applicationName().isEmpty() && !organizationName().isEmpty()) 00069 { 00070 m_settings = new QSettings(applicationName(), organizationName()); 00071 saveObject(m_settings); 00072 } 00073 00074 // create and show main window 00075 if(option(MainWindow)) 00076 { 00077 if(!m_mainWindow) 00078 m_mainWindow = new MainWindowPrivate(m_settings); 00079 00080 saveObject(m_mainWindow); 00081 00082 if(m_settings) 00083 { 00084 m_settings->beginGroup("MainWindow"); 00085 m_mainWindow->resize(m_settings->value("size", QSize(400, 400)).toSize()); 00086 m_mainWindow->move(m_settings->value("pos", QPoint(200, 200)).toPoint()); 00087 m_settings->endGroup(); 00088 } 00089 00090 if(option(Actions)) 00091 { 00092 if(true) 00093 { 00094 00095 } 00096 } 00097 00098 if(option(StatusBar)) 00099 { 00100 m_mainWindow->statusBar()->showMessage(tr("Ready")); 00101 } 00102 00103 m_mainWindow->show(); 00104 } 00105 return QApplication::exec(); 00106 } 00107 00108 void StandardApplication::saveObject(QObject* object) 00109 { 00110 if(option(ObjectPool)) 00111 { 00112 m_objectPool.append(object); 00113 } 00114 } 00115 00116 bool StandardApplication::option(Option f) 00117 { 00118 return m_options.testFlag(f); 00119 } 00120 00121 const ObjectList& StandardApplication::getObjectPool() const 00122 { 00123 return m_objectPool; 00124 } 00125 00126 ObjectList& StandardApplication::getObjectPool() 00127 { 00128 return m_objectPool; 00129 } 00130 00131 QSettings* StandardApplication::getSettings() const 00132 { 00133 return m_settings; 00134 } 00135 00136 QMainWindow* StandardApplication::getMainWindow() const 00137 { 00138 return m_mainWindow; 00139 } 00140 00141 ActionManager* StandardApplication::getActionManager() const 00142 { 00143 return m_actionManager; 00144 } 00145 00146 PluginManager* StandardApplication::getPluginManager() const 00147 { 00148 return m_pluginManager; 00149 }
Les sources présentées sur cette page sont libres de droits et vous pouvez les utiliser à votre convenance. Par contre, la page de présentation constitue une œuvre intellectuelle protégée par les droits d'auteur. Copyright © 2010 Developpez LLC. Tous droits réservés Developpez LLC. Aucune reproduction, même partielle, ne peut être faite de ce site ni de l'ensemble de son contenu : textes, documents et images sans l'autorisation expresse de Developpez LLC. Sinon vous encourez selon la loi jusqu'à trois ans de prison et jusqu'à 300 000 € de dommages et intérêts.