]>
vaikene.ee Git - evaf/blob - src/plugins/SdiWindow/sdiwindow.cpp
aa264de0362658deacd5b22e587cd5f6d56abee5
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
)
59 setObjectName(QString("%1-%2").arg(VER_MODULE_NAME_STR
).arg(__FUNCTION__
));
64 // Apply the size specified in a) properties; or b) on the command line
67 // Create the default layout
68 mLayout
= new QVBoxLayout
;
73 EVAF_INFO("%s created", qPrintable(objectName()));
76 MainWindow::~MainWindow()
83 EVAF_INFO("%s destroyed", qPrintable(objectName()));
86 bool MainWindow::init(QString
const & args
)
90 Common::iRegistry::instance()->registerInterface("iSdiWindow", this);
92 setWindowTitle(Common::iApp::instance()->name());
98 EVAF_INFO("%s initialized", qPrintable(objectName()));
103 void MainWindow::done()
111 delete mWindow
.data();
113 EVAF_INFO("%s finalized", qPrintable(objectName()));
116 void MainWindow::addWindow(Gui::Window
* window
)
118 // Delete the existing window
120 delete mWindow
.data();
121 mLayout
->addWidget(window
);
125 void MainWindow::saveSettings()
127 static int ver
[4] = {VER_FILE_VERSION
};
128 QSettings
settings(VER_COMPANY_NAME_STR
, Common::iApp::instance()->name());
129 settings
.setValue(QString("%1/version/major").arg(objectName()), ver
[0]);
130 settings
.setValue(QString("%1/version/minor").arg(objectName()), ver
[1]);
131 settings
.setValue(QString("%1/geometry").arg(objectName()), saveGeometry());
134 void MainWindow::restoreSettings()
136 static int ver
[4] = {VER_FILE_VERSION
};
137 QSettings
settings(VER_COMPANY_NAME_STR
, Common::iApp::instance()->name());
139 // Ignore saved settings if the version number is not the same
140 // More intelligent checks can be implemented to allow upgrading from previous versions
141 QVariant v
= settings
.value(QString("%1/version/major").arg(objectName()));
142 if (!v
.isValid() || v
.toInt() != ver
[0])
144 v
= settings
.value(QString("%1/version/minor").arg(objectName()));
145 if (!v
.isValid() || v
.toInt() != ver
[1])
148 // Restore the geometry
149 restoreGeometry(settings
.value(QString("%1/geometry").arg(objectName())).toByteArray());
152 void MainWindow::setWindowSize()
154 // a) Get window size from properties
158 // b) Use command line arguments
159 QStringList args
= QApplication::arguments();
160 for (int i
= 1; i
< args
.size(); ++i
) {
161 QStringList arg
= args
.at(i
).simplified().split('=');
162 if (QRegExp("-[-]?w[idth]?").exactMatch(arg
.at(0)) && arg
.size() > 1) {
164 int v
= arg
.at(1).toInt(&ok
);
168 if (QRegExp("-[-]?h[eight]?").exactMatch(arg
.at(0)) && arg
.size() > 1) {
170 int v
= arg
.at(1).toInt(&ok
);
177 if (w
> 0 || h
> 0) {
178 QSize sz
= sizeHint();
188 //-------------------------------------------------------------------
190 SdiWindowPlugin::SdiWindowPlugin()
193 setObjectName(VER_MODULE_NAME_STR
);
195 mWindow
= new MainWindow
;
197 EVAF_INFO("%s created", qPrintable(objectName()));
200 SdiWindowPlugin::~SdiWindowPlugin()
204 EVAF_INFO("%s destroyed", qPrintable(objectName()));
207 bool SdiWindowPlugin::init(const QString
& args
)
209 if (!mWindow
->init(args
))
212 EVAF_INFO("%s initialized", qPrintable(objectName()));
217 void SdiWindowPlugin::done()
221 EVAF_INFO("%s finalized", qPrintable(objectName()));