From 9c7a9f4c6cba99c1a416df992c4275648b89f2f6 Mon Sep 17 00:00:00 2001 From: Matthias Koefferlein Date: Wed, 2 Sep 2020 23:38:31 +0200 Subject: [PATCH] Some refactoring for reducing size of layMainWindow.cc a little. --- src/lay/lay/HelpDialog.ui | 63 +++ src/lay/lay/lay.pro | 15 +- src/lay/lay/layControlWidgetStack.cc | 141 +++++++ src/lay/lay/layControlWidgetStack.h | 77 ++++ src/lay/lay/layHelpAboutDialog.cc | 140 +++++++ src/lay/lay/layHelpAboutDialog.h | 55 +++ src/lay/lay/layHelpDialog.cc | 46 +-- src/lay/lay/layHelpDialog.h | 7 +- src/lay/lay/layMainWindow.cc | 508 ++----------------------- src/lay/lay/layMainWindow.h | 46 +-- src/lay/lay/layProgressDialog.cc | 75 ++++ src/lay/lay/layProgressDialog.h | 61 +++ src/lay/lay/layTextProgressDelegate.cc | 73 ++++ src/lay/lay/layTextProgressDelegate.h | 55 +++ src/lay/lay/layViewWidgetStack.cc | 103 +++++ src/lay/lay/layViewWidgetStack.h | 64 ++++ 16 files changed, 991 insertions(+), 538 deletions(-) create mode 100644 src/lay/lay/HelpDialog.ui create mode 100644 src/lay/lay/layControlWidgetStack.cc create mode 100644 src/lay/lay/layControlWidgetStack.h create mode 100644 src/lay/lay/layHelpAboutDialog.cc create mode 100644 src/lay/lay/layHelpAboutDialog.h create mode 100644 src/lay/lay/layProgressDialog.cc create mode 100644 src/lay/lay/layProgressDialog.h create mode 100644 src/lay/lay/layTextProgressDelegate.cc create mode 100644 src/lay/lay/layTextProgressDelegate.h create mode 100644 src/lay/lay/layViewWidgetStack.cc create mode 100644 src/lay/lay/layViewWidgetStack.h diff --git a/src/lay/lay/HelpDialog.ui b/src/lay/lay/HelpDialog.ui new file mode 100644 index 000000000..f176091db --- /dev/null +++ b/src/lay/lay/HelpDialog.ui @@ -0,0 +1,63 @@ + + + HelpDialog + + + + 0 + 0 + 900 + 500 + + + + Assistant + + + + + + + 0 + 1 + + + + + + + + QDialogButtonBox::Close + + + + + + + + lay::BrowserPanel + QWidget +
layBrowserPanel.h
+ 1 +
+
+ + + + button_frame + rejected() + HelpDialog + accept() + + + 436 + 487 + + + 309 + 498 + + + + +
diff --git a/src/lay/lay/lay.pro b/src/lay/lay/lay.pro index cfb7e9c75..9724ba932 100644 --- a/src/lay/lay/lay.pro +++ b/src/lay/lay/lay.pro @@ -9,9 +9,11 @@ DEFINES += MAKE_LAY_LIBRARY HEADERS = \ layApplication.h \ layClipDialog.h \ + layControlWidgetStack.h \ layCrashMessage.h \ layFillDialog.h \ layGSIHelpProvider.h \ + layHelpAboutDialog.h \ layHelpDialog.h \ layHelpProvider.h \ layHelpSource.h \ @@ -25,6 +27,7 @@ HEADERS = \ layMainWindow.h \ layNavigator.h \ layProgress.h \ + layProgressDialog.h \ layProgressWidget.h \ layResourceHelpProvider.h \ layRuntimeErrorForm.h \ @@ -35,6 +38,7 @@ HEADERS = \ laySettingsForm.h \ layTechSetupDialog.h \ layTextProgress.h \ + layTextProgressDelegate.h \ layVersion.h \ layCommon.h \ layConfig.h \ @@ -57,7 +61,8 @@ HEADERS = \ layMacroEditorSetupPage.h \ layPasswordDialog.h \ layForceLink.h \ - layInit.h + layInit.h \ + layViewWidgetStack.h FORMS = \ ClipDialog.ui \ @@ -66,6 +71,7 @@ FORMS = \ DeleteModeDialog.ui \ FillDialog.ui \ HelpAboutDialog.ui \ + HelpDialog.ui \ LogViewerDialog.ui \ MacroEditorDialog.ui \ MacroPropertiesDialog.ui \ @@ -112,9 +118,11 @@ SOURCES = \ gsiDeclLayMainWindow.cc \ layApplication.cc \ layClipDialog.cc \ + layControlWidgetStack.cc \ layCrashMessage.cc \ layFillDialog.cc \ layGSIHelpProvider.cc \ + layHelpAboutDialog.cc \ layHelpDialog.cc \ layHelpProvider.cc \ layHelpSource.cc \ @@ -128,6 +136,7 @@ SOURCES = \ layMainWindow.cc \ layNavigator.cc \ layProgress.cc \ + layProgressDialog.cc \ layProgressWidget.cc \ layResourceHelpProvider.cc \ layRuntimeErrorForm.cc \ @@ -139,6 +148,7 @@ SOURCES = \ laySettingsForm.cc \ layTechSetupDialog.cc \ layTextProgress.cc \ + layTextProgressDelegate.cc \ layVersion.cc \ layMacroController.cc \ layTechnologyController.cc \ @@ -159,7 +169,8 @@ SOURCES = \ layMacroEditorSetupPage.cc \ layPasswordDialog.cc \ layForceLink.cc \ - layInit.cc + layInit.cc \ + layViewWidgetStack.cc RESOURCES = layBuildInMacros.qrc \ layHelpResources.qrc \ diff --git a/src/lay/lay/layControlWidgetStack.cc b/src/lay/lay/layControlWidgetStack.cc new file mode 100644 index 000000000..a4806323e --- /dev/null +++ b/src/lay/lay/layControlWidgetStack.cc @@ -0,0 +1,141 @@ + +/* + + KLayout Layout Viewer + Copyright (C) 2006-2020 Matthias Koefferlein + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +*/ + +#include "layControlWidgetStack.h" + +#include + +namespace lay +{ + +ControlWidgetStack::ControlWidgetStack(QWidget *parent, const char *name) + : QFrame (parent), mp_current_widget (0) +{ + setObjectName (QString::fromUtf8 (name)); + + // Background ist a simple label without a text currently + mp_bglabel = new QLabel (this); + mp_bglabel->setAutoFillBackground (true); + mp_bglabel->setAlignment (Qt::AlignVCenter | Qt::AlignHCenter); + mp_bglabel->show (); +} + +void ControlWidgetStack::focusInEvent(QFocusEvent *) +{ + for (size_t i = 0; i < m_widgets.size (); ++i) { + if (m_widgets [i]->isVisible ()) { + m_widgets [i]->setFocus (); + break; + } + } +} + +void ControlWidgetStack::add_widget(QWidget *w) +{ + m_widgets.push_back (w); + w->setParent (this); + resize_children (); + raise_widget (m_widgets.size () - 1); + + int mw = 0; + for (size_t i = 0; i < m_widgets.size (); ++i) { + mw = std::max (m_widgets [i]->sizeHint ().width (), mw); + mw = std::max (m_widgets [i]->minimumWidth (), mw); + } + + if (mw > minimumWidth ()) { + setMinimumWidth (mw); + resize (minimumWidth (), height ()); + } +} + +QSize ControlWidgetStack::sizeHint() const +{ + int w = 0; + for (size_t i = 0; i < m_widgets.size (); ++i) { + w = std::max (m_widgets [i]->sizeHint ().width (), w); + } + return QSize (w, 0); +} + +void ControlWidgetStack::remove_widget(size_t index) +{ + if (index < m_widgets.size ()) { + if (mp_current_widget == m_widgets [index]) { + mp_current_widget = 0; + } + m_widgets.erase (m_widgets.begin () + index); + } + if (m_widgets.size () == 0) { + mp_bglabel->show (); + } +} + +void ControlWidgetStack::raise_widget(size_t index) +{ + mp_current_widget = 0; + bool any_visible = false; + for (size_t i = 0; i < m_widgets.size (); ++i) { + if (m_widgets [i]) { + if (i == index) { + m_widgets [i]->show (); + mp_current_widget = m_widgets [i]; + any_visible = true; + } else { + m_widgets [i]->hide (); + } + } + } + + if (! any_visible) { + mp_bglabel->show (); + } else { + mp_bglabel->hide (); + } +} + +QWidget *ControlWidgetStack::widget(size_t index) +{ + if (index < m_widgets.size ()) { + return m_widgets [index]; + } else { + return 0; + } +} + +QWidget *ControlWidgetStack::background_widget() +{ + return mp_bglabel; +} + +void ControlWidgetStack::resize_children() +{ + // set the geometry of all children + for (std::vector ::iterator child = m_widgets.begin (); child != m_widgets.end (); ++child) { + if (*child) { + (*child)->setGeometry (0, 0, width (), height ()); + } + } + mp_bglabel->setGeometry (0, 0, width (), height ()); +} + +} diff --git a/src/lay/lay/layControlWidgetStack.h b/src/lay/lay/layControlWidgetStack.h new file mode 100644 index 000000000..29b436a68 --- /dev/null +++ b/src/lay/lay/layControlWidgetStack.h @@ -0,0 +1,77 @@ + +/* + + KLayout Layout Viewer + Copyright (C) 2006-2020 Matthias Koefferlein + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +*/ + + +#ifndef HDR_layControlWidgetStack +#define HDR_layControlWidgetStack + +#include "layCommon.h" + +#include + +class QLabel; + +namespace lay +{ + +class ControlWidgetStack + : public QFrame +{ +public: + ControlWidgetStack (QWidget *parent = 0, const char *name = 0); + + void focusInEvent (QFocusEvent *); + + QSize sizeHint () const; + + void add_widget (QWidget *w); + void remove_widget (size_t index); + void raise_widget (size_t index); + QWidget *widget (size_t index); + QWidget *background_widget (); + + QWidget *currentWidget () const + { + return mp_current_widget; + } + + size_t count () const + { + return m_widgets.size (); + } + +protected: + virtual void resizeEvent (QResizeEvent *) + { + resize_children (); + } + + void resize_children (); + + std::vector m_widgets; + QWidget *mp_current_widget; + QLabel *mp_bglabel; +}; + +} + +#endif diff --git a/src/lay/lay/layHelpAboutDialog.cc b/src/lay/lay/layHelpAboutDialog.cc new file mode 100644 index 000000000..6430d43a1 --- /dev/null +++ b/src/lay/lay/layHelpAboutDialog.cc @@ -0,0 +1,140 @@ + +/* + + KLayout Layout Viewer + Copyright (C) 2006-2020 Matthias Koefferlein + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +*/ + +#include "layHelpAboutDialog.h" +#include "layApplication.h" +#include "layVersion.h" +#include "layHelpSource.h" // because of escape_xml +#include "layInit.h" +#include "dbInit.h" +#include "gsiInterpreter.h" + +#include "ui_HelpAboutDialog.h" + +#include + +namespace lay +{ + +// ------------------------------------------------------------ +// Implementation of the "help about" dialog + +HelpAboutDialog::HelpAboutDialog (QWidget *parent) + : QDialog (parent) +{ + mp_ui = new Ui::HelpAboutDialog (); + mp_ui->setupUi (this); + + std::vector build_options; + if (lay::ApplicationBase::instance ()->ruby_interpreter ().available ()) { + build_options.push_back (tl::to_string (tr ("Ruby interpreter ")) + lay::ApplicationBase::instance ()->ruby_interpreter ().version ()); + } + if (lay::ApplicationBase::instance ()->python_interpreter ().available ()) { + build_options.push_back (tl::to_string (tr ("Python interpreter ")) + lay::ApplicationBase::instance ()->python_interpreter ().version ()); + } +#if defined(HAVE_QTBINDINGS) + build_options.push_back (tl::to_string (tr ("Qt bindings for scripts"))); +#endif +#if defined(HAVE_64BIT_COORD) + build_options.push_back (tl::to_string (tr ("Wide coordinates (64 bit)"))); +#endif + + std::string s; + + s = ""; + + s += "

"; + s += escape_xml (std::string (lay::Version::name ()) + " " + lay::Version::version ()); + s += "

"; + + std::vector about_paras = tl::split (lay::Version::about_text (), "\n\n"); + for (std::vector::const_iterator p = about_paras.begin (); p != about_paras.end (); ++p) { + s += std::string ("

") + escape_xml (*p) + "

"; + } + + if (! build_options.empty ()) { + s += "

"; + s += "

"; + s += escape_xml (tl::to_string (QObject::tr ("Build options:"))); + s += "

    "; + for (std::vector::const_iterator bo = build_options.begin (); bo != build_options.end (); ++bo) { + s += "
  • "; + s += escape_xml (*bo); + s += "
  • "; + } + s += "
"; + } + + if (! lay::plugins ().empty () || ! db::plugins ().empty ()) { + + s += "

"; + s += "

"; + s += escape_xml (tl::to_string (QObject::tr ("Binary extensions:"))); + s += "

    "; + + for (std::list::const_iterator pd = lay::plugins ().begin (); pd != lay::plugins ().end (); ++pd) { + s += "
  • "; + if (! pd->description.empty ()) { + s += escape_xml (pd->description); + } else { + s += escape_xml (pd->path); + } + if (! pd->version.empty ()) { + s += " (" + escape_xml (pd->version) + ")"; + } + s += "
  • "; + } + + for (std::list::const_iterator pd = db::plugins ().begin (); pd != db::plugins ().end (); ++pd) { + s += "
  • "; + if (! pd->description.empty ()) { + s += escape_xml (pd->description); + } else { + s += escape_xml (pd->path); + } + if (! pd->version.empty ()) { + s += " (" + escape_xml (pd->version) + ")"; + } + s += "
  • "; + } + + s += "
"; + + } + + s += ""; + + std::string t = tl::to_string (QObject::tr ("About ")) + lay::Version::name (); + + setWindowTitle (tl::to_qstring (t)); + + mp_ui->main->setWordWrap (true); + mp_ui->main->setText (tl::to_qstring (s)); +} + +HelpAboutDialog::~HelpAboutDialog () +{ + delete mp_ui; + mp_ui = 0; +} + +} diff --git a/src/lay/lay/layHelpAboutDialog.h b/src/lay/lay/layHelpAboutDialog.h new file mode 100644 index 000000000..fc98fe98e --- /dev/null +++ b/src/lay/lay/layHelpAboutDialog.h @@ -0,0 +1,55 @@ + +/* + + KLayout Layout Viewer + Copyright (C) 2006-2020 Matthias Koefferlein + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +*/ + + +#ifndef HDR_layHelpAboutDialog +#define HDR_layHelpAboutDialog + +#include "layCommon.h" + +#include + +namespace Ui { + class HelpAboutDialog; +} + +namespace lay +{ + +/** + * @brief A dialog for showing the "help about" dialog + */ +class LAY_PUBLIC HelpAboutDialog + : public QDialog +{ +public: + HelpAboutDialog (QWidget *parent); + ~HelpAboutDialog (); + +private: + Ui::HelpAboutDialog *mp_ui; +}; + +} + +#endif + diff --git a/src/lay/lay/layHelpDialog.cc b/src/lay/lay/layHelpDialog.cc index 36fd04864..8e337ee02 100644 --- a/src/lay/lay/layHelpDialog.cc +++ b/src/lay/lay/layHelpDialog.cc @@ -25,6 +25,7 @@ #include "layHelpSource.h" #include "layBrowserPanel.h" #include "tlStaticObjects.h" +#include "ui_HelpDialog.h" #include "tlString.h" @@ -42,35 +43,16 @@ HelpDialog::HelpDialog (QWidget *parent, bool modal) : QDialog (modal ? parent : 0 /*show as separate window*/, modal ? Qt::WindowFlags (0) : Qt::Window /*enabled minimize button*/), m_initialized (false) { + mp_ui = new Ui::HelpDialog (); + mp_ui->setupUi (this); + setModal (modal); - QVBoxLayout *help_layout = new QVBoxLayout (this); - setLayout (help_layout); - setWindowTitle (QObject::tr ("Assistant")); - mp_browser_panel = new lay::BrowserPanel (this); - help_layout->addWidget (mp_browser_panel); - - QSizePolicy sp = mp_browser_panel->sizePolicy (); - sp.setVerticalStretch (1); - mp_browser_panel->setSizePolicy (sp); - - if (modal) { - QFrame *button_frame = new QFrame (this); - help_layout->addWidget (button_frame); - QHBoxLayout *button_layout = new QHBoxLayout (button_frame); - button_layout->setMargin (0); - QPushButton *close_button = new QPushButton (button_frame); - button_layout->addStretch (1); - button_layout->addWidget (close_button); - close_button->setText (QObject::tr ("Close")); - close_button->setDefault (false); - close_button->setAutoDefault (false); - connect (close_button, SIGNAL (clicked ()), this, SLOT (accept ())); - } + mp_ui->button_frame->setVisible (modal); m_def_title = windowTitle (); - connect (mp_browser_panel, SIGNAL (title_changed (const QString &)), this, SLOT (title_changed (const QString &))); - connect (mp_browser_panel, SIGNAL (url_changed (const QString &)), this, SLOT (title_changed (const QString &))); + connect (mp_ui->browser_panel, SIGNAL (title_changed (const QString &)), this, SLOT (title_changed (const QString &))); + connect (mp_ui->browser_panel, SIGNAL (url_changed (const QString &)), this, SLOT (title_changed (const QString &))); } HelpDialog::~HelpDialog () @@ -82,14 +64,14 @@ void HelpDialog::title_changed (const QString &) { QString wt; - QString title = tl::to_qstring (mp_browser_panel->title ()); + QString title = tl::to_qstring (mp_ui->browser_panel->title ()); if (title.isNull () || title.size () == 0) { wt = m_def_title; } else { wt = m_def_title + QString::fromUtf8 (" - ") + title; } - QString url = tl::to_qstring (mp_browser_panel->url ()); + QString url = tl::to_qstring (mp_ui->browser_panel->url ()); if (! url.isNull () && url.size () > 0) { wt += QString::fromUtf8 (" [") + url + QString::fromUtf8 ("]"); } @@ -100,13 +82,13 @@ void HelpDialog::title_changed (const QString &) void HelpDialog::load (const std::string &url) { initialize (); - mp_browser_panel->load (url); + mp_ui->browser_panel->load (url); } void HelpDialog::search (const std::string &topic) { initialize (); - mp_browser_panel->search (topic); + mp_ui->browser_panel->search (topic); } void HelpDialog::showEvent (QShowEvent *) @@ -121,13 +103,13 @@ void HelpDialog::initialize () { if (! m_initialized) { m_initialized = true; - mp_browser_panel->set_search_url ("int:/search.xml", "string"); + mp_ui->browser_panel->set_search_url ("int:/search.xml", "string"); if (! mp_help_source) { mp_help_source = new lay::HelpSource (); tl::StaticObjects::reg (&mp_help_source); } - mp_browser_panel->set_source (mp_help_source); - mp_browser_panel->set_home ("int:/index.xml"); + mp_ui->browser_panel->set_source (mp_help_source); + mp_ui->browser_panel->set_home ("int:/index.xml"); } } diff --git a/src/lay/lay/layHelpDialog.h b/src/lay/lay/layHelpDialog.h index e24c09d2e..361aed565 100644 --- a/src/lay/lay/layHelpDialog.h +++ b/src/lay/lay/layHelpDialog.h @@ -31,6 +31,11 @@ #include #include +namespace Ui +{ + class HelpDialog; +} + namespace lay { @@ -58,7 +63,7 @@ protected slots: void title_changed (const QString &t); private: - lay::BrowserPanel *mp_browser_panel; + Ui::HelpDialog *mp_ui; QRect m_geometry; static lay::HelpSource *mp_help_source; QString m_def_title; diff --git a/src/lay/lay/layMainWindow.cc b/src/lay/lay/layMainWindow.cc index 70156fe2c..87215e52c 100644 --- a/src/lay/lay/layMainWindow.cc +++ b/src/lay/lay/layMainWindow.cc @@ -69,9 +69,9 @@ #include "layConfig.h" #include "layMainWindow.h" #include "layHelpDialog.h" -#include "layHelpSource.h" // because of escape_xml #include "layNavigator.h" #include "layProgress.h" +#include "layProgressDialog.h" #include "layProgressWidget.h" #include "layStream.h" #include "layLayerControlPanel.h" // because of LabelWithBackground @@ -89,10 +89,12 @@ #include "laySaltController.h" #include "layTipDialog.h" #include "layMacroController.h" +#include "layHelpAboutDialog.h" +#include "layControlWidgetStack.h" +#include "layViewWidgetStack.h" #include "layInit.h" #include "antObject.h" #include "antService.h" -#include "ui_HelpAboutDialog.h" #include "gsi.h" #include "gsiInterpreter.h" #include "gtf.h" @@ -104,334 +106,6 @@ const int max_dirty_files = 15; // ------------------------------------------------------------- -class ProgressDialog - : public QDialog, - public tl::Object -{ -public: - ProgressDialog (QWidget *parent, lay::ProgressReporter *pr) - : QDialog (parent), mp_pr (pr) - { - QVBoxLayout *vbl = new QVBoxLayout (this); - vbl->setMargin (0); - vbl->setSpacing (0); - - mp_progress_widget = new ProgressWidget (pr, this, true); - mp_progress_widget->setObjectName (QString::fromUtf8 ("progress")); - vbl->addWidget (mp_progress_widget); - - setWindowTitle (QObject::tr ("Progress")); - setWindowModality (Qt::WindowModal); - } - - void closeEvent (QCloseEvent * /*event*/) - { - if (mp_pr) { - // NOTE: We don't kill on close for now. This creates a too easy way to scrap results. - // mp_pr->signal_break (); - // TODO: there should be a warning saying some jobs are pending. - } - } - - void set_progress (tl::Progress *progress) - { - mp_progress_widget->set_progress (progress); - } - - void add_widget (QWidget *widget) - { - mp_progress_widget->add_widget (widget); - } - - void remove_widget () - { - mp_progress_widget->remove_widget (); - } - - QWidget *get_widget () const - { - return mp_progress_widget->get_widget (); - } - -private: - lay::ProgressWidget *mp_progress_widget; - lay::ProgressReporter *mp_pr; -}; - -// ------------------------------------------------------------- - -class ControlWidgetStack - : public QFrame -{ -public: - ControlWidgetStack (QWidget *parent = 0, const char *name = 0) - : QFrame (parent), mp_current_widget (0) - { - setObjectName (QString::fromUtf8 (name)); - - // Background ist a simple label without a text currently - mp_bglabel = new QLabel (this); - mp_bglabel->setAutoFillBackground (true); - mp_bglabel->setAlignment (Qt::AlignVCenter | Qt::AlignHCenter); - mp_bglabel->show (); - } - - void focusInEvent (QFocusEvent *) - { - for (size_t i = 0; i < m_widgets.size (); ++i) { - if (m_widgets [i]->isVisible ()) { - m_widgets [i]->setFocus (); - break; - } - } - } - - void addWidget (QWidget *w) - { - m_widgets.push_back (w); - w->setParent (this); - resize_children (); - raiseWidget (m_widgets.size () - 1); - - int mw = 0; - for (size_t i = 0; i < m_widgets.size (); ++i) { - mw = std::max (m_widgets [i]->sizeHint ().width (), mw); - mw = std::max (m_widgets [i]->minimumWidth (), mw); - } - - if (mw > minimumWidth ()) { - setMinimumWidth (mw); - resize (minimumWidth (), height ()); - } - } - - QSize sizeHint () const - { - int w = 0; - for (size_t i = 0; i < m_widgets.size (); ++i) { - w = std::max (m_widgets [i]->sizeHint ().width (), w); - } - return QSize (w, 0); - } - - void removeWidget (size_t index) - { - if (index < m_widgets.size ()) { - if (mp_current_widget == m_widgets [index]) { - mp_current_widget = 0; - } - m_widgets.erase (m_widgets.begin () + index); - } - if (m_widgets.size () == 0) { - mp_bglabel->show (); - } - } - - QWidget *currentWidget () const - { - return mp_current_widget; - } - - void raiseWidget (size_t index) - { - mp_current_widget = 0; - bool any_visible = false; - for (size_t i = 0; i < m_widgets.size (); ++i) { - if (m_widgets [i]) { - if (i == index) { - m_widgets [i]->show (); - mp_current_widget = m_widgets [i]; - any_visible = true; - } else { - m_widgets [i]->hide (); - } - } - } - - if (! any_visible) { - mp_bglabel->show (); - } else { - mp_bglabel->hide (); - } - } - - QWidget *widget (size_t index) - { - if (index < m_widgets.size ()) { - return m_widgets [index]; - } else { - return 0; - } - } - - QWidget *background_widget () - { - return mp_bglabel; - } - - size_t count () const - { - return m_widgets.size (); - } - -protected: - virtual void resizeEvent (QResizeEvent *) - { - resize_children (); - } - - void resize_children () - { - // set the geometry of all children - for (std::vector ::iterator child = m_widgets.begin (); child != m_widgets.end (); ++child) { - if (*child) { - (*child)->setGeometry (0, 0, width (), height ()); - } - } - mp_bglabel->setGeometry (0, 0, width (), height ()); - } - - std::vector m_widgets; - QWidget *mp_current_widget; - QLabel *mp_bglabel; -}; - -// ------------------------------------------------------------- - -class ViewWidgetStack - : public QWidget -{ -public: - ViewWidgetStack (QWidget *parent = 0, const char *name = 0) - : QWidget (parent) - { - setObjectName (QString::fromUtf8 (name)); - - mp_bglabel = new QLabel (this); - mp_bglabel->setAutoFillBackground (true); - mp_bglabel->setText (QObject::tr ("

Use File/Open to open a layout

")); - mp_bglabel->setAlignment (Qt::AlignVCenter | Qt::AlignHCenter); - mp_bglabel->show (); - } - - void addWidget (LayoutView *w) - { - m_widgets.push_back (w); - w->setParent (this); - resize_children (); - raiseWidget (m_widgets.size () - 1); - - updateGeometry (); - } - - void removeWidget (size_t index) - { - if (index < m_widgets.size ()) { - m_widgets.erase (m_widgets.begin () + index); - } - if (m_widgets.size () == 0) { - mp_bglabel->show (); - } - } - - void raiseWidget (size_t index) - { - if (index < m_widgets.size ()) { - mp_bglabel->hide (); - m_widgets [index]->show (); - } else { - mp_bglabel->show (); - } - - size_t i = 0; - for (std::vector ::iterator child = m_widgets.begin (); child != m_widgets.end (); ++child, ++i) { - if (i != index) { - (*child)->hide (); - } - } - } - - LayoutView *widget (size_t index) - { - if (index < m_widgets.size ()) { - return m_widgets [index]; - } else { - return 0; - } - } - - QWidget *background_widget () - { - return mp_bglabel; - } - -protected: - virtual void resizeEvent (QResizeEvent *) - { - resize_children (); - } - - void resize_children () - { - // set the geometry of all children - for (std::vector ::iterator child = m_widgets.begin (); child != m_widgets.end (); ++child) { - (*child)->setGeometry (0, 0, width (), height ()); - } - mp_bglabel->setGeometry (0, 0, width (), height ()); - } - - std::vector m_widgets; - QLabel *mp_bglabel; -}; - -// ------------------------------------------------------------- - -TextProgressDelegate::TextProgressDelegate (MainWindow *mw, int verbosity) - : lay::TextProgress (verbosity), mp_mw (mw) -{ - // .. nothing yet .. -} - -void TextProgressDelegate::update_progress (tl::Progress *progress) -{ - if (!mp_mw->update_progress (progress)) { - lay::TextProgress::update_progress (progress); - } -} - -void TextProgressDelegate::show_progress_bar (bool show) -{ - if (!mp_mw->show_progress_bar (show)) { - lay::TextProgress::show_progress_bar (show); - } -} - -bool TextProgressDelegate::progress_wants_widget () const -{ - return mp_mw != 0 && mp_mw->progress_wants_widget (); -} - -void TextProgressDelegate::progress_add_widget (QWidget *widget) -{ - if (mp_mw) { - mp_mw->progress_add_widget (widget); - } -} - -QWidget *TextProgressDelegate::progress_get_widget () const -{ - return mp_mw ? mp_mw->progress_get_widget () : 0; -} - -void TextProgressDelegate::progress_remove_widget () -{ - if (mp_mw) { - mp_mw->progress_remove_widget (); - } -} - -// ------------------------------------------------------------- - static MainWindow *mw_instance = 0; MainWindow * @@ -1004,12 +678,12 @@ MainWindow::close_all () lay::LayoutView *view = mp_views.back (); mp_views.pop_back (); - mp_lp_stack->removeWidget (mp_views.size ()); - mp_hp_stack->removeWidget (mp_views.size ()); - mp_libs_stack->removeWidget (mp_views.size ()); - mp_eo_stack->removeWidget (mp_views.size ()); - mp_bm_stack->removeWidget (mp_views.size ()); - mp_view_stack->removeWidget (mp_views.size ()); + mp_lp_stack->remove_widget (mp_views.size ()); + mp_hp_stack->remove_widget (mp_views.size ()); + mp_libs_stack->remove_widget (mp_views.size ()); + mp_eo_stack->remove_widget (mp_views.size ()); + mp_bm_stack->remove_widget (mp_views.size ()); + mp_view_stack->remove_widget (mp_views.size ()); delete view; @@ -2698,12 +2372,12 @@ MainWindow::select_view (int index) current_view ()->zoom_box (box); } - mp_view_stack->raiseWidget (index); - mp_hp_stack->raiseWidget (index); - mp_lp_stack->raiseWidget (index); - mp_libs_stack->raiseWidget (index); - mp_eo_stack->raiseWidget (index); - mp_bm_stack->raiseWidget (index); + mp_view_stack->raise_widget (index); + mp_hp_stack->raise_widget (index); + mp_lp_stack->raise_widget (index); + mp_libs_stack->raise_widget (index); + mp_eo_stack->raise_widget (index); + mp_bm_stack->raise_widget (index); mp_setup_form->setup (); } @@ -2890,12 +2564,12 @@ MainWindow::clone_current_view () mp_layer_toolbox->set_view (current_view ()); - mp_view_stack->addWidget (view); - mp_lp_stack->addWidget (view->layer_control_frame ()); - mp_hp_stack->addWidget (view->hierarchy_control_frame ()); - mp_libs_stack->addWidget (view->libraries_frame ()); - mp_eo_stack->addWidget (view->editor_options_frame ()); - mp_bm_stack->addWidget (view->bookmarks_frame ()); + mp_view_stack->add_widget (view); + mp_lp_stack->add_widget (view->layer_control_frame ()); + mp_hp_stack->add_widget (view->hierarchy_control_frame ()); + mp_libs_stack->add_widget (view->libraries_frame ()); + mp_eo_stack->add_widget (view->editor_options_frame ()); + mp_bm_stack->add_widget (view->bookmarks_frame ()); bool f = m_disable_tab_selected; m_disable_tab_selected = true; @@ -3141,12 +2815,12 @@ MainWindow::close_view (int index) } mp_tab_bar->removeTab (index); - mp_view_stack->removeWidget (index); - mp_lp_stack->removeWidget (index); - mp_hp_stack->removeWidget (index); - mp_libs_stack->removeWidget (index); - mp_eo_stack->removeWidget (index); - mp_bm_stack->removeWidget (index); + mp_view_stack->remove_widget (index); + mp_lp_stack->remove_widget (index); + mp_hp_stack->remove_widget (index); + mp_libs_stack->remove_widget (index); + mp_eo_stack->remove_widget (index); + mp_bm_stack->remove_widget (index); view_closed_event (int (index)); @@ -3684,12 +3358,12 @@ MainWindow::create_view () mp_layer_toolbox->set_view (current_view ()); - mp_view_stack->addWidget (mp_views.back ()); - mp_lp_stack->addWidget (mp_views.back ()->layer_control_frame ()); - mp_hp_stack->addWidget (mp_views.back ()->hierarchy_control_frame ()); - mp_libs_stack->addWidget (mp_views.back ()->libraries_frame ()); - mp_eo_stack->addWidget (mp_views.back ()->editor_options_frame ()); - mp_bm_stack->addWidget (mp_views.back ()->bookmarks_frame ()); + mp_view_stack->add_widget (mp_views.back ()); + mp_lp_stack->add_widget (mp_views.back ()->layer_control_frame ()); + mp_hp_stack->add_widget (mp_views.back ()->hierarchy_control_frame ()); + mp_libs_stack->add_widget (mp_views.back ()->libraries_frame ()); + mp_eo_stack->add_widget (mp_views.back ()->editor_options_frame ()); + mp_bm_stack->add_widget (mp_views.back ()->bookmarks_frame ()); bool f = m_disable_tab_selected; m_disable_tab_selected = true; @@ -3748,12 +3422,12 @@ MainWindow::create_or_load_layout (const std::string *filename, const db::LoadLa mp_layer_toolbox->set_view (current_view ()); - mp_view_stack->addWidget (mp_views.back ()); - mp_lp_stack->addWidget (mp_views.back ()->layer_control_frame ()); - mp_hp_stack->addWidget (mp_views.back ()->hierarchy_control_frame ()); - mp_libs_stack->addWidget (mp_views.back ()->libraries_frame ()); - mp_eo_stack->addWidget (mp_views.back ()->editor_options_frame ()); - mp_bm_stack->addWidget (mp_views.back ()->bookmarks_frame ()); + mp_view_stack->add_widget (mp_views.back ()); + mp_lp_stack->add_widget (mp_views.back ()->layer_control_frame ()); + mp_hp_stack->add_widget (mp_views.back ()->hierarchy_control_frame ()); + mp_libs_stack->add_widget (mp_views.back ()->libraries_frame ()); + mp_eo_stack->add_widget (mp_views.back ()->editor_options_frame ()); + mp_bm_stack->add_widget (mp_views.back ()->bookmarks_frame ()); bool f = m_disable_tab_selected; m_disable_tab_selected = true; @@ -4475,108 +4149,6 @@ MainWindow::plugin_removed (lay::PluginDeclaration *cls) } } -// ------------------------------------------------------------ -// Implementation of the "help about" dialog - -HelpAboutDialog::HelpAboutDialog (QWidget *parent) - : QDialog (parent) -{ - mp_ui = new Ui::HelpAboutDialog (); - mp_ui->setupUi (this); - - std::vector build_options; - if (lay::ApplicationBase::instance ()->ruby_interpreter ().available ()) { - build_options.push_back (tl::to_string (tr ("Ruby interpreter ")) + lay::ApplicationBase::instance ()->ruby_interpreter ().version ()); - } - if (lay::ApplicationBase::instance ()->python_interpreter ().available ()) { - build_options.push_back (tl::to_string (tr ("Python interpreter ")) + lay::ApplicationBase::instance ()->python_interpreter ().version ()); - } -#if defined(HAVE_QTBINDINGS) - build_options.push_back (tl::to_string (tr ("Qt bindings for scripts"))); -#endif -#if defined(HAVE_64BIT_COORD) - build_options.push_back (tl::to_string (tr ("Wide coordinates (64 bit)"))); -#endif - - std::string s; - - s = ""; - - s += "

"; - s += escape_xml (std::string (lay::Version::name ()) + " " + lay::Version::version ()); - s += "

"; - - std::vector about_paras = tl::split (lay::Version::about_text (), "\n\n"); - for (std::vector::const_iterator p = about_paras.begin (); p != about_paras.end (); ++p) { - s += std::string ("

") + escape_xml (*p) + "

"; - } - - if (! build_options.empty ()) { - s += "

"; - s += "

"; - s += escape_xml (tl::to_string (QObject::tr ("Build options:"))); - s += "

    "; - for (std::vector::const_iterator bo = build_options.begin (); bo != build_options.end (); ++bo) { - s += "
  • "; - s += escape_xml (*bo); - s += "
  • "; - } - s += "
"; - } - - if (! lay::plugins ().empty () || ! db::plugins ().empty ()) { - - s += "

"; - s += "

"; - s += escape_xml (tl::to_string (QObject::tr ("Binary extensions:"))); - s += "

    "; - - for (std::list::const_iterator pd = lay::plugins ().begin (); pd != lay::plugins ().end (); ++pd) { - s += "
  • "; - if (! pd->description.empty ()) { - s += escape_xml (pd->description); - } else { - s += escape_xml (pd->path); - } - if (! pd->version.empty ()) { - s += " (" + escape_xml (pd->version) + ")"; - } - s += "
  • "; - } - - for (std::list::const_iterator pd = db::plugins ().begin (); pd != db::plugins ().end (); ++pd) { - s += "
  • "; - if (! pd->description.empty ()) { - s += escape_xml (pd->description); - } else { - s += escape_xml (pd->path); - } - if (! pd->version.empty ()) { - s += " (" + escape_xml (pd->version) + ")"; - } - s += "
  • "; - } - - s += "
"; - - } - - s += ""; - - std::string t = tl::to_string (QObject::tr ("About ")) + lay::Version::name (); - - setWindowTitle (tl::to_qstring (t)); - - mp_ui->main->setWordWrap (true); - mp_ui->main->setText (tl::to_qstring (s)); -} - -HelpAboutDialog::~HelpAboutDialog () -{ - delete mp_ui; - mp_ui = 0; -} - // ------------------------------------------------------------ // Declaration of the "plugin" for the menu entries diff --git a/src/lay/lay/layMainWindow.h b/src/lay/lay/layMainWindow.h index 5ef8ccddf..b8c8b9b97 100644 --- a/src/lay/lay/layMainWindow.h +++ b/src/lay/lay/layMainWindow.h @@ -20,8 +20,6 @@ */ - - #ifndef HDR_layMainWindow #define HDR_layMainWindow @@ -46,6 +44,7 @@ #include "layProgress.h" #include "layTextProgress.h" #include "layTechnology.h" +#include "layTextProgressDelegate.h" #include "tlException.h" #include "tlDeferredExecution.h" #include "tlObjectCollection.h" @@ -61,10 +60,6 @@ class QStackedWidget; class QDockWidget; class QAction; -namespace Ui { - class HelpAboutDialog; -} - namespace lay { class SettingsForm; @@ -84,38 +79,19 @@ class Navigator; class LayerToolbox; class MainWindow; class HelpDialog; +class HelpAboutDialog; +class ControlWidgetStack; +class ViewWidgetStack; +class ProgressWidget; /** - * @brief A dialog for showing the "help about" dialog + * @brief A big main window class + * + * The main window is the core UI feature of the application. + * The main window is view container, basic controller, configuration root + * and holder of many resources. + * The main window is a singleton. */ -class LAY_PUBLIC HelpAboutDialog - : public QDialog -{ -public: - HelpAboutDialog (QWidget *parent); - ~HelpAboutDialog (); - -private: - Ui::HelpAboutDialog *mp_ui; -}; - -class TextProgressDelegate - : public lay::TextProgress -{ -public: - TextProgressDelegate (MainWindow *mw, int verbosity); - - virtual void update_progress (tl::Progress *progress); - virtual void show_progress_bar (bool show); - virtual bool progress_wants_widget () const; - virtual void progress_add_widget (QWidget *widget); - virtual QWidget *progress_get_widget () const; - virtual void progress_remove_widget (); - -private: - MainWindow *mp_mw; -}; - class LAY_PUBLIC MainWindow : public QMainWindow, public lay::Dispatcher diff --git a/src/lay/lay/layProgressDialog.cc b/src/lay/lay/layProgressDialog.cc new file mode 100644 index 000000000..5d74fed4f --- /dev/null +++ b/src/lay/lay/layProgressDialog.cc @@ -0,0 +1,75 @@ + +/* + + KLayout Layout Viewer + Copyright (C) 2006-2020 Matthias Koefferlein + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +*/ + +#include "layProgressDialog.h" +#include "layProgressWidget.h" + +#include + +namespace lay +{ + +ProgressDialog::ProgressDialog (QWidget *parent, ProgressReporter *pr) + : QDialog (parent), mp_pr (pr) +{ + QVBoxLayout *vbl = new QVBoxLayout (this); + vbl->setMargin (0); + vbl->setSpacing (0); + + mp_progress_widget = new ProgressWidget (pr, this, true); + mp_progress_widget->setObjectName (QString::fromUtf8 ("progress")); + vbl->addWidget (mp_progress_widget); + + setWindowTitle (QObject::tr ("Progress")); + setWindowModality (Qt::WindowModal); +} + +void ProgressDialog::closeEvent (QCloseEvent *) +{ + if (mp_pr) { + // NOTE: We don't kill on close for now. This creates a too easy way to scrap results. + // mp_pr->signal_break (); + // TODO: there should be a warning saying some jobs are pending. + } +} + +void ProgressDialog::set_progress (tl::Progress *progress) +{ + mp_progress_widget->set_progress (progress); +} + +void ProgressDialog::add_widget (QWidget *widget) +{ + mp_progress_widget->add_widget (widget); +} + +void ProgressDialog::remove_widget () +{ + mp_progress_widget->remove_widget (); +} + +QWidget *ProgressDialog::get_widget () const +{ + return mp_progress_widget->get_widget (); +} + +} diff --git a/src/lay/lay/layProgressDialog.h b/src/lay/lay/layProgressDialog.h new file mode 100644 index 000000000..f1036fd2d --- /dev/null +++ b/src/lay/lay/layProgressDialog.h @@ -0,0 +1,61 @@ + +/* + + KLayout Layout Viewer + Copyright (C) 2006-2020 Matthias Koefferlein + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +*/ + + +#ifndef HDR_layProgressDialog +#define HDR_layProgressDialog + +#include "layCommon.h" + +#include "tlObject.h" +#include "tlProgress.h" + +#include + +namespace lay +{ + +class ProgressReporter; +class ProgressWidget; + +class ProgressDialog + : public QDialog, + public tl::Object +{ +public: + ProgressDialog (QWidget *parent, lay::ProgressReporter *pr); + + void closeEvent (QCloseEvent * /*event*/); + + void set_progress (tl::Progress *progress); + void add_widget (QWidget *widget); + void remove_widget (); + QWidget *get_widget () const; + +private: + lay::ProgressWidget *mp_progress_widget; + lay::ProgressReporter *mp_pr; +}; + +} + +#endif diff --git a/src/lay/lay/layTextProgressDelegate.cc b/src/lay/lay/layTextProgressDelegate.cc new file mode 100644 index 000000000..d0dd0db2f --- /dev/null +++ b/src/lay/lay/layTextProgressDelegate.cc @@ -0,0 +1,73 @@ + +/* + + KLayout Layout Viewer + Copyright (C) 2006-2020 Matthias Koefferlein + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +*/ + +#include "layTextProgressDelegate.h" +#include "layMainWindow.h" + +namespace lay +{ + +TextProgressDelegate::TextProgressDelegate (MainWindow *mw, int verbosity) + : lay::TextProgress (verbosity), mp_mw (mw) +{ + // .. nothing yet .. +} + +void TextProgressDelegate::update_progress (tl::Progress *progress) +{ + if (!mp_mw->update_progress (progress)) { + lay::TextProgress::update_progress (progress); + } +} + +void TextProgressDelegate::show_progress_bar (bool show) +{ + if (!mp_mw->show_progress_bar (show)) { + lay::TextProgress::show_progress_bar (show); + } +} + +bool TextProgressDelegate::progress_wants_widget () const +{ + return mp_mw != 0 && mp_mw->progress_wants_widget (); +} + +void TextProgressDelegate::progress_add_widget (QWidget *widget) +{ + if (mp_mw) { + mp_mw->progress_add_widget (widget); + } +} + +QWidget *TextProgressDelegate::progress_get_widget () const +{ + return mp_mw ? mp_mw->progress_get_widget () : 0; +} + +void TextProgressDelegate::progress_remove_widget () +{ + if (mp_mw) { + mp_mw->progress_remove_widget (); + } +} + +} diff --git a/src/lay/lay/layTextProgressDelegate.h b/src/lay/lay/layTextProgressDelegate.h new file mode 100644 index 000000000..d45128861 --- /dev/null +++ b/src/lay/lay/layTextProgressDelegate.h @@ -0,0 +1,55 @@ + +/* + + KLayout Layout Viewer + Copyright (C) 2006-2020 Matthias Koefferlein + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +*/ + + +#ifndef HDR_layTextProgressDelegate +#define HDR_layTextProgressDelegate + +#include "layCommon.h" + +#include "layTextProgress.h" + +namespace lay +{ + +class MainWindow; + +class TextProgressDelegate + : public lay::TextProgress +{ +public: + TextProgressDelegate (MainWindow *mw, int verbosity); + + virtual void update_progress (tl::Progress *progress); + virtual void show_progress_bar (bool show); + virtual bool progress_wants_widget () const; + virtual void progress_add_widget (QWidget *widget); + virtual QWidget *progress_get_widget () const; + virtual void progress_remove_widget (); + +private: + MainWindow *mp_mw; +}; + +} + +#endif diff --git a/src/lay/lay/layViewWidgetStack.cc b/src/lay/lay/layViewWidgetStack.cc new file mode 100644 index 000000000..7d7b51f81 --- /dev/null +++ b/src/lay/lay/layViewWidgetStack.cc @@ -0,0 +1,103 @@ + +/* + + KLayout Layout Viewer + Copyright (C) 2006-2020 Matthias Koefferlein + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +*/ + +#include "layViewWidgetStack.h" +#include "layLayoutView.h" + +#include + +namespace lay +{ + +ViewWidgetStack::ViewWidgetStack (QWidget *parent, const char *name) + : QWidget (parent) +{ + setObjectName (QString::fromUtf8 (name)); + + mp_bglabel = new QLabel (this); + mp_bglabel->setAutoFillBackground (true); + mp_bglabel->setText (QObject::tr ("

Use File/Open to open a layout

")); + mp_bglabel->setAlignment (Qt::AlignVCenter | Qt::AlignHCenter); + mp_bglabel->show (); +} + +void ViewWidgetStack::add_widget (LayoutView *w) +{ + m_widgets.push_back (w); + w->setParent (this); + resize_children (); + raise_widget (m_widgets.size () - 1); + + updateGeometry (); +} + +void ViewWidgetStack::remove_widget (size_t index) +{ + if (index < m_widgets.size ()) { + m_widgets.erase (m_widgets.begin () + index); + } + if (m_widgets.size () == 0) { + mp_bglabel->show (); + } +} + +void ViewWidgetStack::raise_widget (size_t index) +{ + if (index < m_widgets.size ()) { + mp_bglabel->hide (); + m_widgets [index]->show (); + } else { + mp_bglabel->show (); + } + + size_t i = 0; + for (std::vector ::iterator child = m_widgets.begin (); child != m_widgets.end (); ++child, ++i) { + if (i != index) { + (*child)->hide (); + } + } +} + +LayoutView *ViewWidgetStack::widget (size_t index) +{ + if (index < m_widgets.size ()) { + return m_widgets [index]; + } else { + return 0; + } +} + +QWidget *ViewWidgetStack::background_widget () +{ + return mp_bglabel; +} + +void ViewWidgetStack::resize_children () +{ + // set the geometry of all children + for (std::vector ::iterator child = m_widgets.begin (); child != m_widgets.end (); ++child) { + (*child)->setGeometry (0, 0, width (), height ()); + } + mp_bglabel->setGeometry (0, 0, width (), height ()); +} + +} diff --git a/src/lay/lay/layViewWidgetStack.h b/src/lay/lay/layViewWidgetStack.h new file mode 100644 index 000000000..c4e7b1c1e --- /dev/null +++ b/src/lay/lay/layViewWidgetStack.h @@ -0,0 +1,64 @@ + +/* + + KLayout Layout Viewer + Copyright (C) 2006-2020 Matthias Koefferlein + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +*/ + + +#ifndef HDR_layViewWidgetStack +#define HDR_layViewWidgetStack + +#include "layCommon.h" + +#include + +class QLabel; + +namespace lay +{ + +class LayoutView; + +class ViewWidgetStack + : public QWidget +{ +public: + ViewWidgetStack (QWidget *parent = 0, const char *name = 0); + + void add_widget (LayoutView *w); + void remove_widget (size_t index); + void raise_widget (size_t index); + LayoutView *widget (size_t index); + QWidget *background_widget (); + +protected: + virtual void resizeEvent (QResizeEvent *) + { + resize_children (); + } + + void resize_children (); + + std::vector m_widgets; + QLabel *mp_bglabel; +}; + +} + +#endif