X-Git-Url: https://vaikene.ee/gitweb/pswgen09.html?a=blobdiff_plain;f=src%2Fplugins%2FSdiWindow%2Fsdiwindow.cpp;h=25a86acab2639b0505ebf10fc35f6b938b5a4ca1;hb=HEAD;hp=d0294d8c83c1e18fddee8cc105170a9020de20eb;hpb=f443e47f50a5d12f592aaae6a4e553e4a125ee1c;p=evaf
diff --git a/src/plugins/SdiWindow/sdiwindow.cpp b/src/plugins/SdiWindow/sdiwindow.cpp
index d0294d8..25a86ac 100644
--- a/src/plugins/SdiWindow/sdiwindow.cpp
+++ b/src/plugins/SdiWindow/sdiwindow.cpp
@@ -3,7 +3,7 @@
* @brief SdiWindow module's implementation
* @author Enar Vaikene
*
- * Copyright (c) 2011 Enar Vaikene
+ * Copyright (c) 2011-2019 Enar Vaikene
*
* This file is part of the eVaf C++ cross-platform application development framework.
*
@@ -23,14 +23,16 @@
#include
#include
#include
+#include
-#include
+#include
+#include
namespace eVaf {
namespace SdiWindow {
namespace Internal {
/// iSdiWindow interface instance singleton
- static iSdiWindow * mSdiWindow = 0;
+ static iSdiWindow * mSdiWindow = nullptr;
} // namespace eVaf::SdiWindow::Internal
} // namespace eVaf::SdiWindow
} // namespace eVaf
@@ -40,82 +42,138 @@ using namespace eVaf;
//-------------------------------------------------------------------
-using namespace eVaf::SdiWindow;
-
-iSdiWindow * iSdiWindow::instance()
+SdiWindow::iSdiWindow * SdiWindow::iSdiWindow::instance()
{
- return Internal::mSdiWindow;
+ return SdiWindow::Internal::mSdiWindow;
}
//-------------------------------------------------------------------
-using namespace eVaf::SdiWindow::Internal;
-
-MainWindow::MainWindow(QWidget * parent, Qt::WindowFlags flags)
+SdiWindow::Internal::MainWindow::MainWindow(QWidget * parent, Qt::WindowFlags flags)
: QWidget(parent, flags)
+ , mReady(false)
+ , mMainPanel(nullptr)
{
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
+ // Apply the size specified in a) properties; or b) on the command line (overwrites stored geometry)
setWindowSize();
// Create the default layout
mLayout = new QVBoxLayout;
setLayout(mLayout);
+ mSdiWindow = this;
+
EVAF_INFO("%s created", qPrintable(objectName()));
}
-MainWindow::~MainWindow()
+SdiWindow::Internal::MainWindow::~MainWindow()
{
+ mSdiWindow = nullptr;
+
// Save geometry
saveSettings();
EVAF_INFO("%s destroyed", qPrintable(objectName()));
}
-bool MainWindow::init()
+QString SdiWindow::Internal::MainWindow::getMainPanelName(QString const & args) const
+{
+ QXmlStreamReader xml(args);
+ while (!xml.atEnd()) {
+ xml.readNext();
+ if (xml.isStartElement() && xml.name() == "attributes") {
+ if (xml.attributes().hasAttribute("mainPanelName"))
+ return xml.attributes().value("mainPanelName").toString();
+ }
+ }
+ return QString();
+}
+
+bool SdiWindow::Internal::MainWindow::init(QString const & args)
{
+ mMainPanelName = getMainPanelName(args);
+
+ Common::iRegistry::instance()->registerInterface("iSdiWindow", this);
+
setWindowTitle(Common::iApp::instance()->name());
show();
+ mReady = true;
+
EVAF_INFO("%s initialized", qPrintable(objectName()));
return true;
}
-void MainWindow::done()
+void SdiWindow::Internal::MainWindow::done()
{
+ mReady = false;
+
close();
- // Delete all the items added to the main window
- while (mItemsAdded.count() > 0) {
- QPointer item = mItemsAdded.takeAt(0);
- if (item)
- delete item.data();
+ // Delete all the panels
+ for (int i = mPanels.size() - 1; i >= 0; --i) {
+ disconnect(mPanels.at(i), SIGNAL(destroyed(QObject *)), this, SLOT(panelDestroyed(QObject *)));
+ delete mPanels.at(i);
}
+ mPanels.clear();
+ mMinimizedPanels.clear();
+ mPanelNames.clear();
+ mMainPanel = nullptr;
+ mMainPanelName.clear();
EVAF_INFO("%s finalized", qPrintable(objectName()));
}
-void MainWindow::addWidget(QWidget * widget)
+void SdiWindow::Internal::MainWindow::addPanel(QString const & name, Gui::Panel * panel)
{
- mLayout->addWidget(widget);
- mItemsAdded.append(widget);
+ connect(panel, SIGNAL(destroyed(QObject *)), this, SLOT(panelDestroyed(QObject*)));
+ mPanels.append(panel);
+ mPanelNames.insert(name, panel);
+
+ // If this is the predefined main panel, add it to this window
+ if (!mMainPanelName.isEmpty()) {
+ if (name == mMainPanelName) {
+ mMainPanel = panel;
+ mLayout->addWidget(panel);
+ }
+ }
+
+ // If the predefined main panel name is not set, use the first panel
+ else {
+ if (!mMainPanel) {
+ mMainPanel = panel;
+ mLayout->addWidget(panel);
+ }
+ }
}
-void MainWindow::addLayout(QLayout * layout)
+Gui::Panel * SdiWindow::Internal::MainWindow::panel(QString const & name) const
{
- mLayout->addLayout(layout);
- mItemsAdded.append(layout);
+ QHash::const_iterator it = mPanelNames.constFind(name);
+ if (it != mPanelNames.constEnd())
+ return it.value();
+ return nullptr;
}
-void MainWindow::saveSettings()
+bool SdiWindow::Internal::MainWindow::showPanel(QString const & name)
+{
+ Gui::Panel * p = panel(name);
+ if (p) {
+ p->show();
+ return true;
+ }
+ return false;
+}
+
+void SdiWindow::Internal::MainWindow::saveSettings()
{
static int ver[4] = {VER_FILE_VERSION};
QSettings settings(VER_COMPANY_NAME_STR, Common::iApp::instance()->name());
@@ -124,7 +182,7 @@ void MainWindow::saveSettings()
settings.setValue(QString("%1/geometry").arg(objectName()), saveGeometry());
}
-void MainWindow::restoreSettings()
+void SdiWindow::Internal::MainWindow::restoreSettings()
{
static int ver[4] = {VER_FILE_VERSION};
QSettings settings(VER_COMPANY_NAME_STR, Common::iApp::instance()->name());
@@ -142,11 +200,11 @@ void MainWindow::restoreSettings()
restoreGeometry(settings.value(QString("%1/geometry").arg(objectName())).toByteArray());
}
-void MainWindow::setWindowSize()
+void SdiWindow::Internal::MainWindow::setWindowSize()
{
// a) Get window size from properties
- int w = 0;
- int h = 0;
+ int w = Common::iProp::instance()->getValue("windowWidth", 0).toInt();
+ int h = Common::iProp::instance()->getValue("windowHeight", 0).toInt();
// b) Use command line arguments
QStringList args = QApplication::arguments();
@@ -177,77 +235,117 @@ void MainWindow::setWindowSize()
}
}
-
-//-------------------------------------------------------------------
-
-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()
+void SdiWindow::Internal::MainWindow::closeEvent(QCloseEvent * e)
{
- delete wWindow;
-
- mSdiWindow = 0;
+ // Try to close all the managed panels; ignore the event if one of the managed panels refuses to close
+ foreach (Gui::Panel * p, mPanels) {
+ if (!p->close()) {
+ e->ignore();
+ return;
+ }
+ }
- EVAF_INFO("%s destroyed", qPrintable(objectName()));
+ QWidget::closeEvent(e);
}
-bool SdiWindowImpl::init(const QString & args)
+void SdiWindow::Internal::MainWindow::changeEvent(QEvent * e)
{
- Q_UNUSED(args);
+ if (e->type() == QEvent::WindowStateChange) {
+ QWindowStateChangeEvent * wse = static_cast(e);
- if (!wWindow->init())
- return false;
+ if (windowState() == Qt::WindowNoState && wse->oldState() == Qt::WindowMinimized) {
- mReady = true;
+ // Restore all the managed panels that were previously minimized
+ foreach (Gui::Panel * p, mMinimizedPanels) {
+ if (p->isVisible())
+ p->showNormal();
+ }
+ mMinimizedPanels.clear();
+ }
- EVAF_INFO("%s initialized", qPrintable(objectName()));
+ else if (windowState() == Qt::WindowMinimized && wse->oldState() != Qt::WindowMinimized) {
- return true;
+ // Minimize all the managed panels that are not minimized yet
+ mMinimizedPanels.clear();
+ foreach (Gui::Panel * p, mPanels) {
+ if (p->windowState() != Qt::WindowMinimized && p->isVisible()) {
+ mMinimizedPanels.append(p);
+ p->showMinimized();
+ }
+ }
+ }
+ }
+ QWidget::changeEvent(e);
}
-void SdiWindowImpl::done()
+void SdiWindow::Internal::MainWindow::panelDestroyed(QObject * obj)
{
- mReady = false;
+ // Remove panels that are deleted
+ {
+ QList::iterator it = mPanels.begin();
+ while (it != mPanels.end()) {
+ if (*it == obj) {
+ it = mPanels.erase(it);
+ }
+ else {
+ ++it;
+ }
+ }
+ }
+ {
+ QVector::iterator it = mMinimizedPanels.begin();
+ while (it != mMinimizedPanels.end())
+ {
+ if (*it == obj)
+ {
+ it = mMinimizedPanels.erase(it);
+ }
+ else
+ {
+ ++it;
+ }
+ }
+ }
- wWindow->done();
+ // Do the same with panel names
+ {
+ QHash::iterator it = mPanelNames.begin();
+ while (it != mPanelNames.end()) {
+ if (it.value() == obj) {
+ it = mPanelNames.erase(it);
+ }
+ else {
+ ++it;
+ }
+ }
+ }
- EVAF_INFO("%s finalized", qPrintable(objectName()));
+ // If it was the main panel, set the main panel to NULL
+ if (mMainPanel == obj) {
+ mMainPanel = nullptr;
+ }
}
//-------------------------------------------------------------------
-SdiWindowPlugin::SdiWindowPlugin()
+SdiWindow::Internal::SdiWindowPlugin::SdiWindowPlugin()
: Plugins::iPlugin()
+ , mWindow(new MainWindow)
{
setObjectName(VER_MODULE_NAME_STR);
- mWindow = new SdiWindowImpl;
-
EVAF_INFO("%s created", qPrintable(objectName()));
}
-SdiWindowPlugin::~SdiWindowPlugin()
+SdiWindow::Internal::SdiWindowPlugin::~SdiWindowPlugin()
{
- delete mWindow;
+ mWindow.reset();
EVAF_INFO("%s destroyed", qPrintable(objectName()));
}
-bool SdiWindowPlugin::init(const QString & args)
+bool SdiWindow::Internal::SdiWindowPlugin::init(const QString & args)
{
if (!mWindow->init(args))
return false;
@@ -257,7 +355,7 @@ bool SdiWindowPlugin::init(const QString & args)
return true;
}
-void SdiWindowPlugin::done()
+void SdiWindow::Internal::SdiWindowPlugin::done()
{
mWindow->done();