]>
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 delete mItemsAdded
.takeAt(0);
100 EVAF_INFO("%s finalized", qPrintable(objectName()));
103 void MainWindow::addWidget(QWidget
* widget
)
105 mLayout
->addWidget(widget
);
106 mItemsAdded
.append(widget
);
109 void MainWindow::addLayout(QLayout
* layout
)
111 mLayout
->addLayout(layout
);
112 mItemsAdded
.append(layout
);
115 void MainWindow::saveSettings()
117 static int ver
[4] = {VER_FILE_VERSION
};
118 QSettings
settings(VER_COMPANY_NAME_STR
, Common::iApp::instance()->name());
119 settings
.setValue(QString("%1/version/major").arg(objectName()), ver
[0]);
120 settings
.setValue(QString("%1/version/minor").arg(objectName()), ver
[1]);
121 settings
.setValue(QString("%1/geometry").arg(objectName()), saveGeometry());
124 void MainWindow::restoreSettings()
126 static int ver
[4] = {VER_FILE_VERSION
};
127 QSettings
settings(VER_COMPANY_NAME_STR
, Common::iApp::instance()->name());
129 // Ignore saved settings if the version number is not the same
130 // More intelligent checks can be implemented to allow upgrading from previous versions
131 QVariant v
= settings
.value(QString("%1/version/major").arg(objectName()));
132 if (!v
.isValid() || v
.toInt() != ver
[0])
134 v
= settings
.value(QString("%1/version/minor").arg(objectName()));
135 if (!v
.isValid() || v
.toInt() != ver
[1])
138 // Restore the geometry
139 restoreGeometry(settings
.value(QString("%1/geometry").arg(objectName())).toByteArray());
142 void MainWindow::setWindowSize()
144 // a) Get window size from properties
148 // b) Use command line arguments
149 QStringList args
= QApplication::arguments();
150 for (int i
= 1; i
< args
.size(); ++i
) {
151 QStringList arg
= args
.at(i
).simplified().split('=');
152 if (QRegExp("-[-]?w[idth]?").exactMatch(arg
.at(0)) && arg
.size() > 1) {
154 int v
= arg
.at(1).toInt(&ok
);
158 if (QRegExp("-[-]?h[eight]?").exactMatch(arg
.at(0)) && arg
.size() > 1) {
160 int v
= arg
.at(1).toInt(&ok
);
167 if (w
> 0 || h
> 0) {
168 QSize sz
= sizeHint();
178 //-------------------------------------------------------------------
180 SdiWindowImpl::SdiWindowImpl()
184 setObjectName(QString("%1.iSdiWindow").arg(VER_MODULE_NAME_STR
));
188 wWindow
= new MainWindow
;
190 Common::iRegistry::instance()->registerInterface("iSdiWindow", this);
192 EVAF_INFO("%s created", qPrintable(objectName()));
195 SdiWindowImpl::~SdiWindowImpl()
201 EVAF_INFO("%s destroyed", qPrintable(objectName()));
204 bool SdiWindowImpl::init(const QString
& args
)
208 if (!wWindow
->init())
213 EVAF_INFO("%s initialized", qPrintable(objectName()));
218 void SdiWindowImpl::done()
224 EVAF_INFO("%s finalized", qPrintable(objectName()));
228 //-------------------------------------------------------------------
230 SdiWindowPlugin::SdiWindowPlugin()
233 setObjectName(VER_MODULE_NAME_STR
);
235 mWindow
= new SdiWindowImpl
;
237 EVAF_INFO("%s created", qPrintable(objectName()));
240 SdiWindowPlugin::~SdiWindowPlugin()
244 EVAF_INFO("%s destroyed", qPrintable(objectName()));
247 bool SdiWindowPlugin::init(const QString
& args
)
249 if (!mWindow
->init(args
))
252 EVAF_INFO("%s initialized", qPrintable(objectName()));
257 void SdiWindowPlugin::done()
261 EVAF_INFO("%s finalized", qPrintable(objectName()));