]>
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>
31 /// iSdiWindow interface instance singleton
32 static iSdiWindow
* mSdiWindow
= 0;
33 } // namespace eVaf::SdiWindow::Internal
34 } // namespace eVaf::SdiWindow
40 //-------------------------------------------------------------------
42 using namespace eVaf::SdiWindow
;
44 iSdiWindow
* iSdiWindow::instance()
46 return Internal::mSdiWindow
;
50 //-------------------------------------------------------------------
52 using namespace eVaf::SdiWindow::Internal
;
54 MainWindow::MainWindow(QWidget
* parent
, Qt::WindowFlags flags
)
55 : QWidget(parent
, flags
)
57 setObjectName(QString("%1-%2").arg(VER_MODULE_NAME_STR
).arg(__FUNCTION__
));
62 // Apply the size specified in a) properties; or b) on the command line
65 EVAF_INFO("%s created", qPrintable(objectName()));
68 MainWindow::~MainWindow()
73 EVAF_INFO("%s destroyed", qPrintable(objectName()));
76 bool MainWindow::init()
80 EVAF_INFO("%s initialized", qPrintable(objectName()));
85 void MainWindow::done()
89 EVAF_INFO("%s finalized", qPrintable(objectName()));
92 void MainWindow::saveSettings()
94 static int ver
[4] = {VER_FILE_VERSION
};
95 QSettings
settings(VER_COMPANY_NAME_STR
, VER_PRODUCT_NAME_STR
);
96 settings
.setValue(QString("%1/version/major").arg(objectName()), ver
[0]);
97 settings
.setValue(QString("%1/version/minor").arg(objectName()), ver
[1]);
98 settings
.setValue(QString("%1/geometry").arg(objectName()), saveGeometry());
101 void MainWindow::restoreSettings()
103 static int ver
[4] = {VER_FILE_VERSION
};
104 QSettings
settings(VER_COMPANY_NAME_STR
, VER_PRODUCT_NAME_STR
);
106 // Ignore saved settings if the version number is not the same
107 // More intelligent checks can be implemented to allow upgrading from previous versions
108 QVariant v
= settings
.value(QString("%1/version/major").arg(objectName()));
109 if (!v
.isValid() || v
.toInt() != ver
[0])
111 v
= settings
.value(QString("%1/version/minor").arg(objectName()));
112 if (!v
.isValid() || v
.toInt() != ver
[1])
115 // Restore the geometry
116 restoreGeometry(settings
.value(QString("%1/geometry").arg(objectName())).toByteArray());
119 void MainWindow::setWindowSize()
121 // a) Get window size from properties
125 // b) Use command line arguments
126 QStringList args
= QApplication::arguments();
127 for (int i
= 1; i
< args
.size(); ++i
) {
128 QStringList arg
= args
.at(i
).simplified().split('=');
129 if (QRegExp("-[-]?w[idth]?").exactMatch(arg
.at(0)) && arg
.size() > 1) {
131 int v
= arg
.at(1).toInt(&ok
);
135 if (QRegExp("-[-]?h[eight]?").exactMatch(arg
.at(0)) && arg
.size() > 1) {
137 int v
= arg
.at(1).toInt(&ok
);
144 if (w
> 0 || h
> 0) {
145 QSize sz
= sizeHint();
155 //-------------------------------------------------------------------
157 SdiWindowImpl::SdiWindowImpl()
161 setObjectName(QString("%1.iSdiWindow").arg(VER_MODULE_NAME_STR
));
165 wWindow
= new MainWindow
;
167 Common::iRegistry::instance()->registerInterface("iSdiWindow", this);
169 EVAF_INFO("%s created", qPrintable(objectName()));
172 SdiWindowImpl::~SdiWindowImpl()
178 EVAF_INFO("%s destroyed", qPrintable(objectName()));
181 bool SdiWindowImpl::init(const QString
& args
)
185 if (!wWindow
->init())
190 EVAF_INFO("%s initialized", qPrintable(objectName()));
195 void SdiWindowImpl::done()
201 EVAF_INFO("%s finalized", qPrintable(objectName()));
205 //-------------------------------------------------------------------
207 SdiWindowPlugin::SdiWindowPlugin()
210 setObjectName(VER_MODULE_NAME_STR
);
212 mWindow
= new SdiWindowImpl
;
214 EVAF_INFO("%s created", qPrintable(objectName()));
217 SdiWindowPlugin::~SdiWindowPlugin()
221 EVAF_INFO("%s destroyed", qPrintable(objectName()));
224 bool SdiWindowPlugin::init(const QString
& args
)
226 if (!mWindow
->init(args
))
229 EVAF_INFO("%s initialized", qPrintable(objectName()));
234 void SdiWindowPlugin::done()
238 EVAF_INFO("%s finalized", qPrintable(objectName()));