]>
vaikene.ee Git - evaf/blob - src/plugins/SdiWindow/sdiwindow.cpp
5956276b3add6f79abb0a9c05a0691bd777d7697
2 * @file SdiWindow/sdiwindow.cpp
3 * @brief SdiWindow module's implementation
6 * Copyright (c) 2011 Enar Vaikene
8 * This file is part of the eVaf C++ cross-platform application development framework.
10 * This file can be used under the terms of the GNU General Public License
11 * version 3.0 as published by the Free Software Foundation and appearing in
12 * the file LICENSE included in the packaging of this file. Please review the
13 * the following information to ensure the GNU General Public License version
14 * 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html.
16 * Alternatively, this file may be used in accordance with the Commercial License
17 * Agreement provided with the Software.
20 #include "sdiwindow.h"
23 #include <Common/iLogger>
24 #include <Common/iRegistry>
25 #include <Common/iApp>
26 #include <Common/iProp>
29 #include <QXmlStreamReader>
34 /// iSdiWindow interface instance singleton
35 static iSdiWindow
* mSdiWindow
= 0;
36 } // namespace eVaf::SdiWindow::Internal
37 } // namespace eVaf::SdiWindow
43 //-------------------------------------------------------------------
45 SdiWindow::iSdiWindow
* SdiWindow::iSdiWindow::instance()
47 return SdiWindow::Internal::mSdiWindow
;
51 //-------------------------------------------------------------------
53 SdiWindow::Internal::MainWindow::MainWindow(QWidget
* parent
, Qt::WindowFlags flags
)
54 : QWidget(parent
, flags
)
58 setObjectName(QString("%1-%2").arg(VER_MODULE_NAME_STR
).arg(__FUNCTION__
));
63 // Apply the size specified in a) properties; or b) on the command line (overwrites stored geometry)
66 // Create the default layout
67 mLayout
= new QVBoxLayout
;
72 EVAF_INFO("%s created", qPrintable(objectName()));
75 SdiWindow::Internal::MainWindow::~MainWindow()
82 EVAF_INFO("%s destroyed", qPrintable(objectName()));
85 QString
SdiWindow::Internal::MainWindow::getMainPanelName(QString
const & args
) const
87 QXmlStreamReader
xml(args
);
88 while (!xml
.atEnd()) {
90 if (xml
.isStartElement() && xml
.name() == "attributes") {
91 if (xml
.attributes().hasAttribute("mainPanelName"))
92 return xml
.attributes().value("mainPanelName").toString();
98 bool SdiWindow::Internal::MainWindow::init(QString
const & args
)
100 mMainPanelName
= getMainPanelName(args
);
102 Common::iRegistry::instance()->registerInterface("iSdiWindow", this);
104 setWindowTitle(Common::iApp::instance()->name());
110 EVAF_INFO("%s initialized", qPrintable(objectName()));
115 void SdiWindow::Internal::MainWindow::done()
121 // Delete all the panels
122 for (int i
= mPanels
.size() - 1; i
>= 0; --i
) {
123 disconnect(mPanels
.at(i
), SIGNAL(destroyed(QObject
*)), this, SLOT(panelDestroyed(QObject
*)));
124 delete mPanels
.at(i
);
127 mMinimizedPanels
.clear();
130 mMainPanelName
.clear();
132 EVAF_INFO("%s finalized", qPrintable(objectName()));
135 void SdiWindow::Internal::MainWindow::addPanel(QString
const & name
, Gui::Panel
* panel
)
137 connect(panel
, SIGNAL(destroyed(QObject
*)), this, SLOT(panelDestroyed(QObject
*)));
138 mPanels
.append(panel
);
139 mPanelNames
.insert(name
, panel
);
141 // If this is the predefined main panel, add it to this window
142 if (!mMainPanelName
.isEmpty()) {
143 if (name
== mMainPanelName
) {
145 mLayout
->addWidget(panel
);
149 // If the predefined main panel name is not set, use the first panel
153 mLayout
->addWidget(panel
);
158 Gui::Panel
* SdiWindow::Internal::MainWindow::panel(QString
const & name
) const
160 QHash
<QString
, Gui::Panel
*>::const_iterator it
= mPanelNames
.constFind(name
);
161 if (it
!= mPanelNames
.constEnd())
166 bool SdiWindow::Internal::MainWindow::showPanel(QString
const & name
)
168 Gui::Panel
* p
= panel(name
);
176 void SdiWindow::Internal::MainWindow::saveSettings()
178 static int ver
[4] = {VER_FILE_VERSION
};
179 QSettings
settings(VER_COMPANY_NAME_STR
, Common::iApp::instance()->name());
180 settings
.setValue(QString("%1/version/major").arg(objectName()), ver
[0]);
181 settings
.setValue(QString("%1/version/minor").arg(objectName()), ver
[1]);
182 settings
.setValue(QString("%1/geometry").arg(objectName()), saveGeometry());
185 void SdiWindow::Internal::MainWindow::restoreSettings()
187 static int ver
[4] = {VER_FILE_VERSION
};
188 QSettings
settings(VER_COMPANY_NAME_STR
, Common::iApp::instance()->name());
190 // Ignore saved settings if the version number is not the same
191 // More intelligent checks can be implemented to allow upgrading from previous versions
192 QVariant v
= settings
.value(QString("%1/version/major").arg(objectName()));
193 if (!v
.isValid() || v
.toInt() != ver
[0])
195 v
= settings
.value(QString("%1/version/minor").arg(objectName()));
196 if (!v
.isValid() || v
.toInt() != ver
[1])
199 // Restore the geometry
200 restoreGeometry(settings
.value(QString("%1/geometry").arg(objectName())).toByteArray());
203 void SdiWindow::Internal::MainWindow::setWindowSize()
205 // a) Get window size from properties
206 int w
= Common::iProp::instance()->getValue("windowWidth", 0).toInt();
207 int h
= Common::iProp::instance()->getValue("windowHeight", 0).toInt();
209 // b) Use command line arguments
210 QStringList args
= QApplication::arguments();
211 for (int i
= 1; i
< args
.size(); ++i
) {
212 QStringList arg
= args
.at(i
).simplified().split('=');
213 if (QRegExp("-[-]?w[idth]?").exactMatch(arg
.at(0)) && arg
.size() > 1) {
215 int v
= arg
.at(1).toInt(&ok
);
219 if (QRegExp("-[-]?h[eight]?").exactMatch(arg
.at(0)) && arg
.size() > 1) {
221 int v
= arg
.at(1).toInt(&ok
);
228 if (w
> 0 || h
> 0) {
229 QSize sz
= sizeHint();
238 void SdiWindow::Internal::MainWindow::closeEvent(QCloseEvent
* e
)
240 // Try to close all the managed panels; ignore the event if one of the managed panels refuses to close
241 foreach (Gui::Panel
* p
, mPanels
) {
248 QWidget::closeEvent(e
);
251 void SdiWindow::Internal::MainWindow::changeEvent(QEvent
* e
)
253 if (e
->type() == QEvent::WindowStateChange
) {
254 QWindowStateChangeEvent
* wse
= static_cast<QWindowStateChangeEvent
*>(e
);
256 if (windowState() == Qt::WindowNoState
&& wse
->oldState() == Qt::WindowMinimized
) {
258 // Restore all the managed panels that were previously minimized
259 foreach (Gui::Panel
* p
, mMinimizedPanels
) {
263 mMinimizedPanels
.clear();
266 else if (windowState() == Qt::WindowMinimized
&& wse
->oldState() != Qt::WindowMinimized
) {
268 // Minimize all the managed panels that are not minimized yet
269 mMinimizedPanels
.clear();
270 foreach (Gui::Panel
* p
, mPanels
) {
271 if (p
->windowState() != Qt::WindowMinimized
&& p
->isVisible()) {
272 mMinimizedPanels
.append(p
);
278 QWidget::changeEvent(e
);
281 void SdiWindow::Internal::MainWindow::panelDestroyed(QObject
* obj
)
283 // Remove panels that are deleted
285 QList
<Gui::Panel
*>::iterator it
= mPanels
.begin();
286 while (it
!= mPanels
.end()) {
288 it
= mPanels
.erase(it
);
296 // Do the same with panel names
298 QHash
<QString
, Gui::Panel
*>::iterator it
= mPanelNames
.begin();
299 while (it
!= mPanelNames
.end()) {
300 if (it
.value() == obj
) {
301 it
= mPanelNames
.erase(it
);
309 if (mMainPanel
== obj
) {
315 //-------------------------------------------------------------------
317 SdiWindow::Internal::SdiWindowPlugin::SdiWindowPlugin()
320 setObjectName(VER_MODULE_NAME_STR
);
322 mWindow
= new MainWindow
;
324 EVAF_INFO("%s created", qPrintable(objectName()));
327 SdiWindow::Internal::SdiWindowPlugin::~SdiWindowPlugin()
331 EVAF_INFO("%s destroyed", qPrintable(objectName()));
334 bool SdiWindow::Internal::SdiWindowPlugin::init(const QString
& args
)
336 if (!mWindow
->init(args
))
339 EVAF_INFO("%s initialized", qPrintable(objectName()));
344 void SdiWindow::Internal::SdiWindowPlugin::done()
348 EVAF_INFO("%s finalized", qPrintable(objectName()));