From: Enar Väikene Date: Wed, 20 Jul 2011 08:42:52 +0000 (+0300) Subject: Added main window plugin implementing Single Document Interface. X-Git-Url: https://vaikene.ee/gitweb/pswgen06.html?a=commitdiff_plain;h=06f9c5336ba8a2200b68f636520707693eb5ada7;p=evaf Added main window plugin implementing Single Document Interface. --- diff --git a/src/plugins/CMakeLists.txt b/src/plugins/CMakeLists.txt index 1150223..7c1d85c 100644 --- a/src/plugins/CMakeLists.txt +++ b/src/plugins/CMakeLists.txt @@ -1 +1,2 @@ +add_subdirectory(SdiWindow) add_subdirectory(Test) diff --git a/src/plugins/SdiWindow/CMakeLists.txt b/src/plugins/SdiWindow/CMakeLists.txt new file mode 100644 index 0000000..9edf476 --- /dev/null +++ b/src/plugins/SdiWindow/CMakeLists.txt @@ -0,0 +1,40 @@ +# Name of the target +set(TARGET SdiWindow) + +# Qt modules +include(${QT_USE_FILE}) + +# Needed for exporting/importing symbols +add_definitions(-DSDIWINDOW_LIBRARY) + +# Include files +include_directories(${eVaf_INCLUDE}) + +# Required eVaf libraries +set(eVaf_LIBRARIES CommonLib PluginsLib) + +# Source files +set(SRCS + factory.cpp + sdiwindow.cpp +) + +# Header files for the meta-object compiler +set(MOC_HDRS + factory.h + isdiwindow.h + sdiwindow.h +) + +# Version info resource file for Windows builds +if(WIN32) + set(SRCS ${SRCS} version.rc) +endif(WIN32) + +qt4_wrap_cpp(MOC_SRCS ${MOC_HDRS}) + +add_library(${TARGET} SHARED ${SRCS} ${MOC_SRCS}) + +target_link_libraries(${TARGET} ${QT_LIBRARIES} ${eVaf_LIBRARIES}) + +install(TARGETS ${TARGET} DESTINATION bin) diff --git a/src/plugins/SdiWindow/factory.cpp b/src/plugins/SdiWindow/factory.cpp new file mode 100644 index 0000000..5ce4d1a --- /dev/null +++ b/src/plugins/SdiWindow/factory.cpp @@ -0,0 +1,60 @@ +/** + * @file SdiWindow/factory.cpp + * @brief SDI module's factory class + * @author Enar Vaikene + * + * Copyright (c) 2011 Enar Vaikene + * + * This file is part of the eVaf C++ cross-platform application development framework. + * + * This file can be used under the terms of the GNU General Public License + * version 3.0 as published by the Free Software Foundation and appearing in + * the file LICENSE included in the packaging of this file. Please review the + * the following information to ensure the GNU General Public License version + * 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html. + * + * Alternatively, this file may be used in accordance with the Commercial License + * Agreement provided with the Software. + */ + +#include "factory.h" +#include "sdiwindow.h" +#include "version.h" + +#include + +#include + +using namespace eVaf::SdiWindow; + +VER_EXPORT_VERSION_INFO() +Q_EXPORT_PLUGIN2(VER_MODULE_NAME_STR, Factory) + + +//------------------------------------------------------------------- + +Factory::Factory() + : Plugins::iPluginFactory() + , mPlugin(0) +{ + setObjectName(QString("%1-Factory").arg(VER_MODULE_NAME_STR)); + + EVAF_INFO("%s created", qPrintable(objectName())); +} + +Factory::~Factory() +{ + if (mPlugin) + delete mPlugin; + + EVAF_INFO("%s destroyed", qPrintable(objectName())); +} + +QObject * Factory::create(QString const & name) +{ + Q_UNUSED(name); + + if (mPlugin == 0) + mPlugin = new Internal::SdiWindowPlugin; + return mPlugin; +} diff --git a/src/plugins/SdiWindow/factory.h b/src/plugins/SdiWindow/factory.h new file mode 100644 index 0000000..3b7201b --- /dev/null +++ b/src/plugins/SdiWindow/factory.h @@ -0,0 +1,67 @@ +/** + * @file SdiWindow/factory.h + * @brief SDI module's factory class + * @author Enar Vaikene + * + * Copyright (c) 2011 Enar Vaikene + * + * This file is part of the eVaf C++ cross-platform application development framework. + * + * This file can be used under the terms of the GNU General Public License + * version 3.0 as published by the Free Software Foundation and appearing in + * the file LICENSE included in the packaging of this file. Please review the + * the following information to ensure the GNU General Public License version + * 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html. + * + * Alternatively, this file may be used in accordance with the Commercial License + * Agreement provided with the Software. + */ + +#ifndef __SDIWINDOW_FACTORY_H +# define __SDIWINDOW_FACTORY_H + +#include + +namespace eVaf { + +/** + * Module that implements the Single Document Interface. + * + * Use this module as the main window for SDI applications. + */ +namespace SdiWindow { + +/** + * Internal implementation of the module. + */ +namespace Internal { + class SdiWindowPlugin; +} // namespace eVaf::SdiWindow::Internal + + +/** + * Plugin factory class for the module + */ +class Factory : public Plugins::iPluginFactory +{ + Q_OBJECT + +public: + + Factory(); + + virtual ~Factory(); + + virtual QObject * create(QString const & name); + + +private: // Members + + Internal::SdiWindowPlugin * mPlugin; + +}; + +} // namespace eVaf::SdiWindow +} // namespace eVaf + +#endif // factory.h diff --git a/src/plugins/SdiWindow/iSdiWindow b/src/plugins/SdiWindow/iSdiWindow new file mode 100644 index 0000000..c0696d6 --- /dev/null +++ b/src/plugins/SdiWindow/iSdiWindow @@ -0,0 +1 @@ +#include "isdiwindow.h" diff --git a/src/plugins/SdiWindow/isdiwindow.h b/src/plugins/SdiWindow/isdiwindow.h new file mode 100644 index 0000000..a5794db --- /dev/null +++ b/src/plugins/SdiWindow/isdiwindow.h @@ -0,0 +1,73 @@ +/** + * @file SdiWindow/isdiwindow.h + * @brief eVaf SDI window interface + * @author Enar Vaikene + * + * Copyright (c) 2011 Enar Vaikene + * + * This file is part of the eVaf C++ cross-platform application development framework. + * + * This file can be used under the terms of the GNU General Public License + * version 3.0 as published by the Free Software Foundation and appearing in + * the file LICENSE included in the packaging of this file. Please review the + * the following information to ensure the GNU General Public License version + * 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html. + * + * Alternatively, this file may be used in accordance with the Commercial License + * Agreement provided with the Software. + */ + +#ifndef __SDIWINDOW_ISDIWINDOW_H +# define __SDIWINDOW_ISDIWINDOW_H + +#include "libsdiwindow.h" + +#include +#include + +namespace eVaf { +namespace SdiWindow { + +/** + * Main window interface for eVaf applications implementing the Single Document Interface. + * + * The iSdiWindow interface provides access to the SDI main window. The SDI main window is + * an empty window that the application needs to fill with widgets. + */ +class SDIWINDOW_EXPORT iSdiWindow : public QObject +{ + Q_OBJECT + +public: + + /// Interface constructor + iSdiWindow() : QObject() {} + + /// Empty virtual destructor + virtual ~iSdiWindow() {} + + /** + * Returns the iSdiWindow interface instance + * @return The iSdiWindow interface or zero if not available + * + * This function returns the global iSdiWindow interface instance. Using this function + * is not mandatory and modules can use the iRegistry interface instead. Using the iRegistry + * interface has the advantage that modules do not need to link against this library. + */ + static iSdiWindow * instance(); + + /** + * Returns the main window widget + * @return The main window widget + * + * This function provides access to the main window widget. The main window is an empty QWidget and + * needs to be filled with additional widgets in order to provide some functionality. + */ + virtual QWidget * widget() const = 0; + +}; + +} // namespace eVaf::SdiWindow +} // namespace eVaf + +#endif // isdiwindow.h diff --git a/src/plugins/SdiWindow/libsdiwindow.h b/src/plugins/SdiWindow/libsdiwindow.h new file mode 100644 index 0000000..8608fdd --- /dev/null +++ b/src/plugins/SdiWindow/libsdiwindow.h @@ -0,0 +1,30 @@ +/** + * @file SdiWindow/libsdiwindow.h + * @author Enar Vaikene + * + * Copyright (c) 2011 Enar Vaikene + * + * This file is part of the eVaf C++ cross-platform application development framework. + * + * This file can be used under the terms of the GNU General Public License + * version 3.0 as published by the Free Software Foundation and appearing in + * the file LICENSE included in the packaging of this file. Please review the + * the following information to ensure the GNU General Public License version + * 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html. + * + * Alternatively, this file may be used in accordance with the Commercial License + * Agreement provided with the Software. + */ + +#ifndef __SDIWINDOW_LIBSDIWINDOW_H +# define __SDIWINDOW_LIBSDIWINDOW_H + +#include + +#if defined(SDIWINDOW_LIBRARY) +# define SDIWINDOW_EXPORT Q_DECL_EXPORT +#else +# define SDIWINDOW_EXPORT Q_DECL_IMPORT +#endif + +#endif // libsdiwindow.h diff --git a/src/plugins/SdiWindow/sdiwindow.cpp b/src/plugins/SdiWindow/sdiwindow.cpp new file mode 100644 index 0000000..b63ab97 --- /dev/null +++ b/src/plugins/SdiWindow/sdiwindow.cpp @@ -0,0 +1,239 @@ +/** + * @file SdiWindow/sdiwindow.cpp + * @brief SdiWindow module's implementation + * @author Enar Vaikene + * + * Copyright (c) 2011 Enar Vaikene + * + * This file is part of the eVaf C++ cross-platform application development framework. + * + * This file can be used under the terms of the GNU General Public License + * version 3.0 as published by the Free Software Foundation and appearing in + * the file LICENSE included in the packaging of this file. Please review the + * the following information to ensure the GNU General Public License version + * 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html. + * + * Alternatively, this file may be used in accordance with the Commercial License + * Agreement provided with the Software. + */ + +#include "sdiwindow.h" +#include "version.h" + +#include +#include + +#include + +namespace eVaf { +namespace SdiWindow { +namespace Internal { + /// iSdiWindow interface instance singleton + static iSdiWindow * mSdiWindow = 0; +} // namespace eVaf::SdiWindow::Internal +} // namespace eVaf::SdiWindow +} // namespace eVaf + + +using namespace eVaf; + +//------------------------------------------------------------------- + +using namespace eVaf::SdiWindow; + +iSdiWindow * iSdiWindow::instance() +{ + return Internal::mSdiWindow; +} + + +//------------------------------------------------------------------- + +using namespace eVaf::SdiWindow::Internal; + +MainWindow::MainWindow(QWidget * parent, Qt::WindowFlags flags) + : QWidget(parent, flags) +{ + setObjectName(QString("%1-%2").arg(VER_MODULE_NAME_STR).arg(__FUNCTION__)); + + // Restore geometry + restoreSettings(); + + // Apply the size specified in a) properties; or b) on the command line + setWindowSize(); + + EVAF_INFO("%s created", qPrintable(objectName())); +} + +MainWindow::~MainWindow() +{ + // Save geometry + saveSettings(); + + EVAF_INFO("%s destroyed", qPrintable(objectName())); +} + +bool MainWindow::init() +{ + show(); + + EVAF_INFO("%s initialized", qPrintable(objectName())); + + return true; +} + +void MainWindow::done() +{ + close(); + + EVAF_INFO("%s finalized", qPrintable(objectName())); +} + +void MainWindow::saveSettings() +{ + static int ver[4] = {VER_FILE_VERSION}; + QSettings settings(VER_COMPANY_NAME_STR, VER_PRODUCT_NAME_STR); + settings.setValue(QString("%1/version/major").arg(objectName()), ver[0]); + settings.setValue(QString("%1/version/minor").arg(objectName()), ver[1]); + settings.setValue(QString("%1/geometry").arg(objectName()), saveGeometry()); +} + +void MainWindow::restoreSettings() +{ + static int ver[4] = {VER_FILE_VERSION}; + QSettings settings(VER_COMPANY_NAME_STR, VER_PRODUCT_NAME_STR); + + // Ignore saved settings if the version number is not the same + // More intelligent checks can be implemented to allow upgrading from previous versions + QVariant v = settings.value(QString("%1/version/major").arg(objectName())); + if (!v.isValid() || v.toInt() != ver[0]) + return; + v = settings.value(QString("%1/version/minor").arg(objectName())); + if (!v.isValid() || v.toInt() != ver[1]) + return; + + // Restore the geometry + restoreGeometry(settings.value(QString("%1/geometry").arg(objectName())).toByteArray()); +} + +void MainWindow::setWindowSize() +{ + // a) Get window size from properties + int w = 0; + int h = 0; + + // b) Use command line arguments + QStringList args = QApplication::arguments(); + for (int i = 1; i < args.size(); ++i) { + QStringList arg = args.at(i).simplified().split('='); + if (QRegExp("-[-]?w[idth]?").exactMatch(arg.at(0)) && arg.size() > 1) { + bool ok; + int v = arg.at(1).toInt(&ok); + if (ok) + w = v; + } + if (QRegExp("-[-]?h[eight]?").exactMatch(arg.at(0)) && arg.size() > 1) { + bool ok; + int v = arg.at(1).toInt(&ok); + if (ok) + h = v; + } + } + + // Resize the window + if (w > 0 || h > 0) { + QSize sz = sizeHint(); + if (w > 0) + sz.setWidth(w); + if (h > 0) + sz.setHeight(h); + resize(sz); + } +} + + +//------------------------------------------------------------------- + +SdiWindowImpl::SdiWindowImpl() + : iSdiWindow() + , mReady(false) +{ + setObjectName(QString("%1.iSdiWindow").arg(VER_MODULE_NAME_STR)); + + mSdiWindow = this; + + wWindow = new MainWindow; + + Common::iRegistry::instance()->registerInterface("iSdiWindow", this); + + EVAF_INFO("%s created", qPrintable(objectName())); +} + +SdiWindowImpl::~SdiWindowImpl() +{ + delete wWindow; + + mSdiWindow = 0; + + EVAF_INFO("%s destroyed", qPrintable(objectName())); +} + +bool SdiWindowImpl::init(const QString & args) +{ + Q_UNUSED(args); + + if (!wWindow->init()) + return false; + + mReady = true; + + EVAF_INFO("%s initialized", qPrintable(objectName())); + + return true; +} + +void SdiWindowImpl::done() +{ + mReady = false; + + wWindow->done(); + + EVAF_INFO("%s finalized", qPrintable(objectName())); +} + + +//------------------------------------------------------------------- + +SdiWindowPlugin::SdiWindowPlugin() + : Plugins::iPlugin() +{ + setObjectName(VER_MODULE_NAME_STR); + + mWindow = new SdiWindowImpl; + + EVAF_INFO("%s created", qPrintable(objectName())); +} + +SdiWindowPlugin::~SdiWindowPlugin() +{ + delete mWindow; + + EVAF_INFO("%s destroyed", qPrintable(objectName())); +} + +bool SdiWindowPlugin::init(const QString & args) +{ + if (!mWindow->init(args)) + return false; + + EVAF_INFO("%s initialized", qPrintable(objectName())); + + return true; +} + +void SdiWindowPlugin::done() +{ + mWindow->done(); + + EVAF_INFO("%s finalized", qPrintable(objectName())); +} diff --git a/src/plugins/SdiWindow/sdiwindow.h b/src/plugins/SdiWindow/sdiwindow.h new file mode 100644 index 0000000..d886cca --- /dev/null +++ b/src/plugins/SdiWindow/sdiwindow.h @@ -0,0 +1,123 @@ +/** + * @file SdiWindow/sdiwindow.h + * @brief SdiWindow module's implementation + * @author Enar Vaikene + * + * Copyright (c) 2011 Enar Vaikene + * + * This file is part of the eVaf C++ cross-platform application development framework. + * + * This file can be used under the terms of the GNU General Public License + * version 3.0 as published by the Free Software Foundation and appearing in + * the file LICENSE included in the packaging of this file. Please review the + * the following information to ensure the GNU General Public License version + * 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html. + * + * Alternatively, this file may be used in accordance with the Commercial License + * Agreement provided with the Software. + */ + +#ifndef __SDIWINDOW_SDIWINDOW_H +# define __SDIWINDOW_SDIWINDOW_H + +#include "isdiwindow.h" + +#include + +#include +#include +#include + +namespace eVaf { +namespace SdiWindow { +namespace Internal { + +/** + * Main window widget + */ +class MainWindow : public QWidget +{ + Q_OBJECT + +public: + + MainWindow(QWidget * parent = 0, Qt::WindowFlags flags = 0); + + virtual ~MainWindow(); + + bool init(); + + void done(); + + +private: // Methods + + void setWindowSize(); + + void saveSettings(); + + void restoreSettings(); +}; + +/** + * iSdiWindow interface implementation + */ +class SdiWindowImpl : public iSdiWindow +{ + Q_OBJECT + +public: + + SdiWindowImpl(); + + virtual ~SdiWindowImpl(); + + bool init(const QString & args); + + void done(); + + bool isReady() const { return mReady; } + + virtual QWidget * widget() const { return wWindow; } + + +private: // Members + + /// Ready flag + bool mReady; + + /// The main window widget + MainWindow * wWindow; +}; + +/** + * SdiWindow module's implementation + */ +class SdiWindowPlugin : public Plugins::iPlugin +{ + Q_OBJECT + +public: + + SdiWindowPlugin(); + + virtual ~SdiWindowPlugin(); + + virtual bool init(const QString & args); + + virtual void done(); + + virtual bool isReady() const { return mWindow != 0 && mWindow->isReady(); } + + +private: + + /// iSdiWindow interface implementation + SdiWindowImpl * mWindow; +}; + +} // namespace eVaf::SdiWindow::Internal +} // namespace eVaf::SdiWindow +} // namespace eVaf + +#endif // sdiwindow.h diff --git a/src/plugins/SdiWindow/version.h b/src/plugins/SdiWindow/version.h new file mode 100644 index 0000000..7945a0c --- /dev/null +++ b/src/plugins/SdiWindow/version.h @@ -0,0 +1,60 @@ +/** + * @file SdiWindow/version.h + * @brief Version information for eVaf modules + * @author Enar Vaikene + * + * Copyright (c) 2011 Enar Vaikene + * + * This file is part of the eVaf C++ cross-platform application development framework. + * + * This file can be used under the terms of the GNU General Public License + * version 3.0 as published by the Free Software Foundation and appearing in + * the file LICENSE included in the packaging of this file. Please review the + * the following information to ensure the GNU General Public License version + * 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html. + * + * Alternatively, this file may be used in accordance with the Commercial License + * Agreement provided with the Software. + */ + +#ifndef __SDI_WINDOW_VERSION_H +#define __SDI_WINDOW_VERSION_H + +#include + +/** + * Module/library version number in the form major,minor,release,build + */ +#define VER_FILE_VERSION 0,1,1,1 + +/** + * Module/library version number in the string format (shall end with \0) + */ +#define VER_FILE_VERSION_STR "0.1.1.1\0" + +/** + * Module/library name (shall end with \0) + */ +#define VER_MODULE_NAME_STR "SdiWindow\0" + +/** + * Module type (see version_rc.h for all the types) + */ +#define VER_MODULE_TYPE MT_GENERIC + +/** + * Module type in the string format (see version_rc for all the types) + */ +#define VER_MODULE_TYPE_STR MT_GENERIC + +/** + * Original file name for windows (shall end with \0) + */ +#define VER_ORIGINAL_FILE_NAME_STR "SdiWindow.dll\0" + +/** + * Description of the module/library (shall end with \0) + */ +#define VER_FILE_DESCRIPTION_STR "Module that implements Single Document Interface for the eVaf application framework.\0" + +#endif // version.h diff --git a/src/plugins/SdiWindow/version.rc b/src/plugins/SdiWindow/version.rc new file mode 100644 index 0000000..1ca9b4c --- /dev/null +++ b/src/plugins/SdiWindow/version.rc @@ -0,0 +1,54 @@ +/** + * @file plugins/Test/version.rc + * @brief Windows resource file with module/library version information. + * @author Enar Vaikene + * + * Copyright (c) 2011 Enar Vaikene + * + * This file is part of the eVaf C++ cross-platform application development framework. + * + * This file can be used under the terms of the GNU General Public License + * version 3.0 as published by the Free Software Foundation and appearing in + * the file LICENSE included in the packaging of this file. Please review the + * the following information to ensure the GNU General Public License version + * 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html. + * + * Alternatively, this file may be used in accordance with the Commercial License + * Agreement provided with the Software. + */ + +#include "version.h" +#include +#include + + +VS_VERSION_INFO VERSIONINFO + FILEVERSION VER_FILE_VERSION + PRODUCTVERSION VER_PRODUCT_VERSION + FILEFLAGSMASK 0x3fL +#ifdef _DEBUG + FILEFLAGS VS_FF_DEBUG +#else + FILEFLAGS 0x0L +#endif + FILEOS VOS__WINDOWS32 + FILETYPE VFT_DLL + FILESUBTYPE 0x0L + BEGIN + BLOCK "StringFileInfo" + BEGIN + BLOCK "040904B0" + BEGIN + VALUE "CompanyName", VER_COMPANY_NAME_STR + VALUE "FileDescription", VER_FILE_DESCRIPTION_STR + VALUE "FileVersion", VER_FILE_VERSION_STR + VALUE "LegalCopyright", VER_LEGAL_COPYRIGHT_STR + VALUE "OriginalFilename", VER_ORIGINAL_FILE_NAME_STR + VALUE "ProductName", VER_PRODUCT_NAME_STR + VALUE "ProductVersion", VER_PRODUCT_VERSION_STR + VALUE "Build Date", VER_PRODUCT_DATE_STR + VALUE "Module Name", VER_MODULE_NAME_STR + VALUE "Module Type", VER_MODULE_TYPE_STR + END + END + END