]>
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
)
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()
109 // Delete all the items added to the main window
110 while (mItemsAdded
.count() > 0) {
111 QWeakPointer
<QObject
> item
= mItemsAdded
.takeAt(0);
116 EVAF_INFO("%s finalized", qPrintable(objectName()));
119 void MainWindow::addWidget(QWidget
* widget
)
121 mLayout
->addWidget(widget
);
122 mItemsAdded
.append(widget
);
125 void MainWindow::addLayout(QLayout
* layout
)
127 mLayout
->addLayout(layout
);
128 mItemsAdded
.append(layout
);
131 void MainWindow::saveSettings()
133 static int ver
[4] = {VER_FILE_VERSION
};
134 QSettings
settings(VER_COMPANY_NAME_STR
, Common::iApp::instance()->name());
135 settings
.setValue(QString("%1/version/major").arg(objectName()), ver
[0]);
136 settings
.setValue(QString("%1/version/minor").arg(objectName()), ver
[1]);
137 settings
.setValue(QString("%1/geometry").arg(objectName()), saveGeometry());
140 void MainWindow::restoreSettings()
142 static int ver
[4] = {VER_FILE_VERSION
};
143 QSettings
settings(VER_COMPANY_NAME_STR
, Common::iApp::instance()->name());
145 // Ignore saved settings if the version number is not the same
146 // More intelligent checks can be implemented to allow upgrading from previous versions
147 QVariant v
= settings
.value(QString("%1/version/major").arg(objectName()));
148 if (!v
.isValid() || v
.toInt() != ver
[0])
150 v
= settings
.value(QString("%1/version/minor").arg(objectName()));
151 if (!v
.isValid() || v
.toInt() != ver
[1])
154 // Restore the geometry
155 restoreGeometry(settings
.value(QString("%1/geometry").arg(objectName())).toByteArray());
158 void MainWindow::setWindowSize()
160 // a) Get window size from properties
164 // b) Use command line arguments
165 QStringList args
= QApplication::arguments();
166 for (int i
= 1; i
< args
.size(); ++i
) {
167 QStringList arg
= args
.at(i
).simplified().split('=');
168 if (QRegExp("-[-]?w[idth]?").exactMatch(arg
.at(0)) && arg
.size() > 1) {
170 int v
= arg
.at(1).toInt(&ok
);
174 if (QRegExp("-[-]?h[eight]?").exactMatch(arg
.at(0)) && arg
.size() > 1) {
176 int v
= arg
.at(1).toInt(&ok
);
183 if (w
> 0 || h
> 0) {
184 QSize sz
= sizeHint();
194 //-------------------------------------------------------------------
196 SdiWindowPlugin::SdiWindowPlugin()
199 setObjectName(VER_MODULE_NAME_STR
);
201 mWindow
= new MainWindow
;
203 EVAF_INFO("%s created", qPrintable(objectName()));
206 SdiWindowPlugin::~SdiWindowPlugin()
210 EVAF_INFO("%s destroyed", qPrintable(objectName()));
213 bool SdiWindowPlugin::init(const QString
& args
)
215 if (!mWindow
->init(args
))
218 EVAF_INFO("%s initialized", qPrintable(objectName()));
223 void SdiWindowPlugin::done()
227 EVAF_INFO("%s finalized", qPrintable(objectName()));