]>
vaikene.ee Git - evaf/blob - src/plugins/SdiWindow/sdiwindow.cpp
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>
32 /// iSdiWindow interface instance singleton
33 static iSdiWindow
* mSdiWindow
= 0;
34 } // namespace eVaf::SdiWindow::Internal
35 } // namespace eVaf::SdiWindow
41 //-------------------------------------------------------------------
43 using namespace eVaf::SdiWindow
;
45 iSdiWindow
* iSdiWindow::instance()
47 return Internal::mSdiWindow
;
51 //-------------------------------------------------------------------
53 using namespace eVaf::SdiWindow::Internal
;
55 MainWindow::MainWindow(QWidget
* parent
, Qt::WindowFlags flags
)
56 : 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
66 EVAF_INFO("%s created", qPrintable(objectName()));
69 MainWindow::~MainWindow()
74 EVAF_INFO("%s destroyed", qPrintable(objectName()));
77 bool MainWindow::init()
79 setWindowTitle(Common::iApp::instance()->name());
83 EVAF_INFO("%s initialized", qPrintable(objectName()));
88 void MainWindow::done()
92 EVAF_INFO("%s finalized", qPrintable(objectName()));
95 void MainWindow::saveSettings()
97 static int ver
[4] = {VER_FILE_VERSION
};
98 QSettings
settings(VER_COMPANY_NAME_STR
, Common::iApp::instance()->name());
99 settings
.setValue(QString("%1/version/major").arg(objectName()), ver
[0]);
100 settings
.setValue(QString("%1/version/minor").arg(objectName()), ver
[1]);
101 settings
.setValue(QString("%1/geometry").arg(objectName()), saveGeometry());
104 void MainWindow::restoreSettings()
106 static int ver
[4] = {VER_FILE_VERSION
};
107 QSettings
settings(VER_COMPANY_NAME_STR
, Common::iApp::instance()->name());
109 // Ignore saved settings if the version number is not the same
110 // More intelligent checks can be implemented to allow upgrading from previous versions
111 QVariant v
= settings
.value(QString("%1/version/major").arg(objectName()));
112 if (!v
.isValid() || v
.toInt() != ver
[0])
114 v
= settings
.value(QString("%1/version/minor").arg(objectName()));
115 if (!v
.isValid() || v
.toInt() != ver
[1])
118 // Restore the geometry
119 restoreGeometry(settings
.value(QString("%1/geometry").arg(objectName())).toByteArray());
122 void MainWindow::setWindowSize()
124 // a) Get window size from properties
128 // b) Use command line arguments
129 QStringList args
= QApplication::arguments();
130 for (int i
= 1; i
< args
.size(); ++i
) {
131 QStringList arg
= args
.at(i
).simplified().split('=');
132 if (QRegExp("-[-]?w[idth]?").exactMatch(arg
.at(0)) && arg
.size() > 1) {
134 int v
= arg
.at(1).toInt(&ok
);
138 if (QRegExp("-[-]?h[eight]?").exactMatch(arg
.at(0)) && arg
.size() > 1) {
140 int v
= arg
.at(1).toInt(&ok
);
147 if (w
> 0 || h
> 0) {
148 QSize sz
= sizeHint();
158 //-------------------------------------------------------------------
160 SdiWindowImpl::SdiWindowImpl()
164 setObjectName(QString("%1.iSdiWindow").arg(VER_MODULE_NAME_STR
));
168 wWindow
= new MainWindow
;
170 Common::iRegistry::instance()->registerInterface("iSdiWindow", this);
172 EVAF_INFO("%s created", qPrintable(objectName()));
175 SdiWindowImpl::~SdiWindowImpl()
181 EVAF_INFO("%s destroyed", qPrintable(objectName()));
184 bool SdiWindowImpl::init(const QString
& args
)
188 if (!wWindow
->init())
193 EVAF_INFO("%s initialized", qPrintable(objectName()));
198 void SdiWindowImpl::done()
204 EVAF_INFO("%s finalized", qPrintable(objectName()));
208 //-------------------------------------------------------------------
210 SdiWindowPlugin::SdiWindowPlugin()
213 setObjectName(VER_MODULE_NAME_STR
);
215 mWindow
= new SdiWindowImpl
;
217 EVAF_INFO("%s created", qPrintable(objectName()));
220 SdiWindowPlugin::~SdiWindowPlugin()
224 EVAF_INFO("%s destroyed", qPrintable(objectName()));
227 bool SdiWindowPlugin::init(const QString
& args
)
229 if (!mWindow
->init(args
))
232 EVAF_INFO("%s initialized", qPrintable(objectName()));
237 void SdiWindowPlugin::done()
241 EVAF_INFO("%s finalized", qPrintable(objectName()));