]>
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 // Create the default layout
67 mLayout
= new QVBoxLayout
;
70 EVAF_INFO("%s created", qPrintable(objectName()));
73 MainWindow::~MainWindow()
78 EVAF_INFO("%s destroyed", qPrintable(objectName()));
81 bool MainWindow::init()
83 setWindowTitle(Common::iApp::instance()->name());
87 EVAF_INFO("%s initialized", qPrintable(objectName()));
92 void MainWindow::done()
96 // Delete all the items added to the main window
97 while (mItemsAdded
.count() > 0) {
98 QPointer
<QObject
> item
= mItemsAdded
.takeAt(0);
103 EVAF_INFO("%s finalized", qPrintable(objectName()));
106 void MainWindow::addWidget(QWidget
* widget
)
108 mLayout
->addWidget(widget
);
109 mItemsAdded
.append(widget
);
112 void MainWindow::addLayout(QLayout
* layout
)
114 mLayout
->addLayout(layout
);
115 mItemsAdded
.append(layout
);
118 void MainWindow::saveSettings()
120 static int ver
[4] = {VER_FILE_VERSION
};
121 QSettings
settings(VER_COMPANY_NAME_STR
, Common::iApp::instance()->name());
122 settings
.setValue(QString("%1/version/major").arg(objectName()), ver
[0]);
123 settings
.setValue(QString("%1/version/minor").arg(objectName()), ver
[1]);
124 settings
.setValue(QString("%1/geometry").arg(objectName()), saveGeometry());
127 void MainWindow::restoreSettings()
129 static int ver
[4] = {VER_FILE_VERSION
};
130 QSettings
settings(VER_COMPANY_NAME_STR
, Common::iApp::instance()->name());
132 // Ignore saved settings if the version number is not the same
133 // More intelligent checks can be implemented to allow upgrading from previous versions
134 QVariant v
= settings
.value(QString("%1/version/major").arg(objectName()));
135 if (!v
.isValid() || v
.toInt() != ver
[0])
137 v
= settings
.value(QString("%1/version/minor").arg(objectName()));
138 if (!v
.isValid() || v
.toInt() != ver
[1])
141 // Restore the geometry
142 restoreGeometry(settings
.value(QString("%1/geometry").arg(objectName())).toByteArray());
145 void MainWindow::setWindowSize()
147 // a) Get window size from properties
151 // b) Use command line arguments
152 QStringList args
= QApplication::arguments();
153 for (int i
= 1; i
< args
.size(); ++i
) {
154 QStringList arg
= args
.at(i
).simplified().split('=');
155 if (QRegExp("-[-]?w[idth]?").exactMatch(arg
.at(0)) && arg
.size() > 1) {
157 int v
= arg
.at(1).toInt(&ok
);
161 if (QRegExp("-[-]?h[eight]?").exactMatch(arg
.at(0)) && arg
.size() > 1) {
163 int v
= arg
.at(1).toInt(&ok
);
170 if (w
> 0 || h
> 0) {
171 QSize sz
= sizeHint();
181 //-------------------------------------------------------------------
183 SdiWindowImpl::SdiWindowImpl()
187 setObjectName(QString("%1.iSdiWindow").arg(VER_MODULE_NAME_STR
));
191 wWindow
= new MainWindow
;
193 Common::iRegistry::instance()->registerInterface("iSdiWindow", this);
195 EVAF_INFO("%s created", qPrintable(objectName()));
198 SdiWindowImpl::~SdiWindowImpl()
204 EVAF_INFO("%s destroyed", qPrintable(objectName()));
207 bool SdiWindowImpl::init(const QString
& args
)
211 if (!wWindow
->init())
216 EVAF_INFO("%s initialized", qPrintable(objectName()));
221 void SdiWindowImpl::done()
227 EVAF_INFO("%s finalized", qPrintable(objectName()));
231 //-------------------------------------------------------------------
233 SdiWindowPlugin::SdiWindowPlugin()
236 setObjectName(VER_MODULE_NAME_STR
);
238 mWindow
= new SdiWindowImpl
;
240 EVAF_INFO("%s created", qPrintable(objectName()));
243 SdiWindowPlugin::~SdiWindowPlugin()
247 EVAF_INFO("%s destroyed", qPrintable(objectName()));
250 bool SdiWindowPlugin::init(const QString
& args
)
252 if (!mWindow
->init(args
))
255 EVAF_INFO("%s initialized", qPrintable(objectName()));
260 void SdiWindowPlugin::done()
264 EVAF_INFO("%s finalized", qPrintable(objectName()));