From 96f3ce65c1494f7215299defd11cef0a631f7090 Mon Sep 17 00:00:00 2001 From: Matthias Koefferlein Date: Thu, 26 May 2022 00:07:22 +0200 Subject: [PATCH] First steps towards LayoutView for headless mode, optional arguments for Layout#load_layout and MainWindow#load_layout --- src/img/img/imgNavigator.cc | 11 +- src/lay/lay/gsiDeclLayMainWindow.cc | 16 +- src/lay/lay/layMainWindow.cc | 24 +- src/lay/lay/layNavigator.cc | 21 +- src/lay/lay/layViewWidgetStack.cc | 10 +- .../laybasic/gsiDeclLayLayoutViewBase.cc | 16 +- src/laybasic/laybasic/layLayoutCanvas.cc | 6 +- src/laybasic/laybasic/layLayoutCanvas.h | 4 - src/laybasic/laybasic/layLayoutViewBase.cc | 35 +- src/laybasic/laybasic/layLayoutViewBase.h | 15 +- src/laybasic/laybasic/layViewObject.cc | 29 +- src/laybasic/laybasic/layViewObject.h | 4 - src/layview/layview/layLayoutView_qt.cc | 408 ++++++++++++------ src/layview/layview/layLayoutView_qt.h | 230 ++++++---- 14 files changed, 478 insertions(+), 351 deletions(-) diff --git a/src/img/img/imgNavigator.cc b/src/img/img/imgNavigator.cc index 634b8bd1e..d01f189a9 100644 --- a/src/img/img/imgNavigator.cc +++ b/src/img/img/imgNavigator.cc @@ -52,13 +52,14 @@ img::Object * Navigator::setup (lay::Dispatcher *root, img::Object *img) { mp_view = new lay::LayoutView (0, false, root, this, "img_navigator_view", lay::LayoutView::LV_Naked + lay::LayoutView::LV_NoZoom + lay::LayoutView::LV_NoServices + lay::LayoutView::LV_NoGrid); - mp_view->setSizePolicy (QSizePolicy::Expanding, QSizePolicy::Expanding); - mp_view->setMinimumWidth (100); - mp_view->setMinimumHeight (100); + tl_assert (mp_view->widget ()); + mp_view->widget ()->setSizePolicy (QSizePolicy::Expanding, QSizePolicy::Expanding); + mp_view->widget ()->setMinimumWidth (100); + mp_view->widget ()->setMinimumHeight (100); QVBoxLayout *layout = new QVBoxLayout (this); - layout->addWidget (mp_view); - layout->setStretchFactor (mp_view, 1); + layout->addWidget (mp_view->widget ()); + layout->setStretchFactor (mp_view->widget (), 1); layout->setContentsMargins (0, 0, 0, 0); layout->setSpacing (0); setLayout (layout); diff --git a/src/lay/lay/gsiDeclLayMainWindow.cc b/src/lay/lay/gsiDeclLayMainWindow.cc index 17fa2f064..6443f694b 100644 --- a/src/lay/lay/gsiDeclLayMainWindow.cc +++ b/src/lay/lay/gsiDeclLayMainWindow.cc @@ -547,7 +547,7 @@ Class decl_MainWindow (QT_EXTERNAL_BASE (QMainWindow) "lay", "M "This version was introduced in version 0.22.\n" "Starting with version 0.25, this method returns a cellview object that can be modified to configure the cellview.\n" ) + - gsi::method ("load_layout", (lay::CellViewRef (lay::MainWindow::*) (const std::string &, int)) &lay::MainWindow::load_layout, gsi::arg ("filename"), gsi::arg ("mode"), + gsi::method ("load_layout", (lay::CellViewRef (lay::MainWindow::*) (const std::string &, int)) &lay::MainWindow::load_layout, gsi::arg ("filename"), gsi::arg ("mode", 1), "@brief Loads a new layout\n" "\n" "@param filename The name of the file to load\n" @@ -561,9 +561,9 @@ Class decl_MainWindow (QT_EXTERNAL_BASE (QMainWindow) "lay", "M "This version will use the initial technology and the default reader options. " "Others versions are provided which allow specification of technology and reader options explicitly.\n" "\n" - "Starting with version 0.25, this method returns a cellview object that can be modified to configure the cellview.\n" + "Starting with version 0.25, this method returns a cellview object that can be modified to configure the cellview. The 'mode' argument has been made optional in version 0.28.\n" ) + - gsi::method ("load_layout", (lay::CellViewRef (lay::MainWindow::*) (const std::string &, const std::string &, int)) &lay::MainWindow::load_layout, gsi::arg ("filename"), gsi::arg ("tech"), gsi::arg ("mode"), + gsi::method ("load_layout", (lay::CellViewRef (lay::MainWindow::*) (const std::string &, const std::string &, int)) &lay::MainWindow::load_layout, gsi::arg ("filename"), gsi::arg ("tech"), gsi::arg ("mode", 1), "@brief Loads a new layout and associate it with the given technology\n" "\n" "@param filename The name of the file to load\n" @@ -575,12 +575,12 @@ Class decl_MainWindow (QT_EXTERNAL_BASE (QMainWindow) "lay", "M "into a new view (mode 1) or adding the layout to the current view (mode 2).\n" "In mode 1, the new view is made the current one.\n" "\n" - "If the technology name is not a valid technology name, the default technology will be used.\n" + "If the technology name is not a valid technology name, the default technology will be used. The 'mode' argument has been made optional in version 0.28.\n" "\n" "This version was introduced in version 0.22.\n" "Starting with version 0.25, this method returns a cellview object that can be modified to configure the cellview.\n" ) + - gsi::method ("load_layout", (lay::CellViewRef (lay::MainWindow::*) (const std::string &, const db::LoadLayoutOptions &, int)) &lay::MainWindow::load_layout, gsi::arg ("filename"), gsi::arg ("options"), gsi::arg ("mode"), + gsi::method ("load_layout", (lay::CellViewRef (lay::MainWindow::*) (const std::string &, const db::LoadLayoutOptions &, int)) &lay::MainWindow::load_layout, gsi::arg ("filename"), gsi::arg ("options"), gsi::arg ("mode", 1), "@brief Loads a new layout with the given options\n" "\n" "@param filename The name of the file to load\n" @@ -593,9 +593,9 @@ Class decl_MainWindow (QT_EXTERNAL_BASE (QMainWindow) "lay", "M "In mode 1, the new view is made the current one.\n" "\n" "This version was introduced in version 0.22.\n" - "Starting with version 0.25, this method returns a cellview object that can be modified to configure the cellview.\n" + "Starting with version 0.25, this method returns a cellview object that can be modified to configure the cellview. The 'mode' argument has been made optional in version 0.28.\n" ) + - gsi::method ("load_layout", (lay::CellViewRef (lay::MainWindow::*) (const std::string &, const db::LoadLayoutOptions &, const std::string &, int)) &lay::MainWindow::load_layout, gsi::arg ("filename"), gsi::arg ("options"), gsi::arg ("tech"), gsi::arg ("mode"), + gsi::method ("load_layout", (lay::CellViewRef (lay::MainWindow::*) (const std::string &, const db::LoadLayoutOptions &, const std::string &, int)) &lay::MainWindow::load_layout, gsi::arg ("filename"), gsi::arg ("options"), gsi::arg ("tech"), gsi::arg ("mode", 1), "@brief Loads a new layout with the given options and associate it with the given technology\n" "\n" "@param filename The name of the file to load\n" @@ -611,7 +611,7 @@ Class decl_MainWindow (QT_EXTERNAL_BASE (QMainWindow) "lay", "M "If the technology name is not a valid technology name, the default technology will be used.\n" "\n" "This version was introduced in version 0.22.\n" - "Starting with version 0.25, this method returns a cellview object that can be modified to configure the cellview.\n" + "Starting with version 0.25, this method returns a cellview object that can be modified to configure the cellview. The 'mode' argument has been made optional in version 0.28.\n" ) + gsi::method ("clone_current_view", &lay::MainWindow::clone_current_view, "@brief Clones the current view and make it current\n" diff --git a/src/lay/lay/layMainWindow.cc b/src/lay/lay/layMainWindow.cc index b7bdabddf..a7e412abc 100644 --- a/src/lay/lay/layMainWindow.cc +++ b/src/lay/lay/layMainWindow.cc @@ -3368,21 +3368,23 @@ MainWindow::create_layout (const std::string &technology, int mode) void MainWindow::add_view (lay::LayoutView *view) { - connect (view, SIGNAL (title_changed ()), this, SLOT (view_title_changed ())); - connect (view, SIGNAL (dirty_changed ()), this, SLOT (view_title_changed ())); - connect (view, SIGNAL (edits_enabled_changed ()), this, SLOT (edits_enabled_changed ())); - connect (view, SIGNAL (menu_needs_update ()), this, SLOT (menu_needs_update ())); - connect (view, SIGNAL (show_message (const std::string &, int)), this, SLOT (message (const std::string &, int))); - connect (view, SIGNAL (current_pos_changed (double, double, bool)), this, SLOT (current_pos (double, double, bool))); - connect (view, SIGNAL (clear_current_pos ()), this, SLOT (clear_current_pos ())); - connect (view, SIGNAL (mode_change (int)), this, SLOT (select_mode (int))); + tl_assert (view->widget ()); + + connect (view->widget (), SIGNAL (title_changed ()), this, SLOT (view_title_changed ())); + connect (view->widget (), SIGNAL (dirty_changed ()), this, SLOT (view_title_changed ())); + connect (view->widget (), SIGNAL (edits_enabled_changed ()), this, SLOT (edits_enabled_changed ())); + connect (view->widget (), SIGNAL (menu_needs_update ()), this, SLOT (menu_needs_update ())); + connect (view->widget (), SIGNAL (show_message (const std::string &, int)), this, SLOT (message (const std::string &, int))); + connect (view->widget (), SIGNAL (current_pos_changed (double, double, bool)), this, SLOT (current_pos (double, double, bool))); + connect (view->widget (), SIGNAL (clear_current_pos ()), this, SLOT (clear_current_pos ())); + connect (view->widget (), SIGNAL (mode_change (int)), this, SLOT (select_mode (int))); mp_views.push_back (view); // we must resize the widget here to set the geometry properly. // This is required to make zoom_fit work. - view->setGeometry (0, 0, mp_view_stack->width (), mp_view_stack->height ()); - view->show (); + view->widget ()->setGeometry (0, 0, mp_view_stack->width (), mp_view_stack->height ()); + view->widget ()->show (); } int @@ -3563,7 +3565,7 @@ MainWindow::view_title_changed () update_tab_title (i); } - if (sender () == current_view ()) { + if (current_view () && sender () == current_view ()->widget ()) { update_window_title (); } } diff --git a/src/lay/lay/layNavigator.cc b/src/lay/lay/layNavigator.cc index 77b19d25a..6977e9702 100644 --- a/src/lay/lay/layNavigator.cc +++ b/src/lay/lay/layNavigator.cc @@ -76,7 +76,11 @@ public: // replace by "real" background color if required if (! c.is_valid ()) { - c = lay::Color (mp_view->palette ().color (QPalette::Normal, QPalette::Base).rgb ()); + if (mp_view->widget ()) { + c = lay::Color (mp_view->widget ()->palette ().color (QPalette::Normal, QPalette::Base).rgb ()); + } else { + c = lay::Color (0xffffff); // white + } } lay::Color contrast; @@ -626,8 +630,8 @@ Navigator::view_closed (int index) void Navigator::resizeEvent (QResizeEvent *) { - if (mp_view) { - mp_view->setGeometry (mp_placeholder_label->geometry ()); + if (mp_view && mp_view->widget ()) { + mp_view->widget ()->setGeometry (mp_placeholder_label->geometry ()); } } @@ -652,11 +656,12 @@ Navigator::attach_view (LayoutView *view) if (mp_source_view) { mp_view = new LayoutView (0, false, mp_source_view, this, "navigator", LayoutView::LV_Naked + LayoutView::LV_NoZoom + LayoutView::LV_NoServices + LayoutView::LV_NoGrid); - mp_view->setSizePolicy (QSizePolicy::Expanding, QSizePolicy::Expanding); - mp_view->setMinimumWidth (100); - mp_view->setMinimumHeight (100); - mp_view->setGeometry (mp_placeholder_label->geometry ()); - mp_view->show (); + tl_assert (mp_view->widget ()); + mp_view->widget ()->setSizePolicy (QSizePolicy::Expanding, QSizePolicy::Expanding); + mp_view->widget ()->setMinimumWidth (100); + mp_view->widget ()->setMinimumHeight (100); + mp_view->widget ()->setGeometry (mp_placeholder_label->geometry ()); + mp_view->widget ()->show (); mp_service = new NavigatorService (mp_view); mp_view->view_object_widget ()->activate (mp_service); diff --git a/src/lay/lay/layViewWidgetStack.cc b/src/lay/lay/layViewWidgetStack.cc index 430acef9f..d99f3c098 100644 --- a/src/lay/lay/layViewWidgetStack.cc +++ b/src/lay/lay/layViewWidgetStack.cc @@ -42,8 +42,10 @@ ViewWidgetStack::ViewWidgetStack (QWidget *parent, const char *name) void ViewWidgetStack::add_widget (LayoutView *w) { + tl_assert (w->widget ()); + m_widgets.push_back (w); - w->setParent (this); + w->widget ()->setParent (this); resize_children (); raise_widget (m_widgets.size () - 1); @@ -64,7 +66,7 @@ void ViewWidgetStack::raise_widget (size_t index) { if (index < m_widgets.size ()) { mp_bglabel->hide (); - m_widgets [index]->show (); + m_widgets [index]->widget ()->show (); } else { mp_bglabel->show (); } @@ -72,7 +74,7 @@ void ViewWidgetStack::raise_widget (size_t index) size_t i = 0; for (std::vector ::iterator child = m_widgets.begin (); child != m_widgets.end (); ++child, ++i) { if (i != index) { - (*child)->hide (); + (*child)->widget ()->hide (); } } } @@ -95,7 +97,7 @@ 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 ()); + (*child)->widget ()->setGeometry (0, 0, width (), height ()); } mp_bglabel->setGeometry (0, 0, width (), height ()); } diff --git a/src/laybasic/laybasic/gsiDeclLayLayoutViewBase.cc b/src/laybasic/laybasic/gsiDeclLayLayoutViewBase.cc index b13ae2f36..b6ec122f3 100644 --- a/src/laybasic/laybasic/gsiDeclLayLayoutViewBase.cc +++ b/src/laybasic/laybasic/gsiDeclLayLayoutViewBase.cc @@ -771,7 +771,7 @@ LAYBASIC_PUBLIC Class decl_LayoutViewBase (QT_EXTERNAL_BASE "If a layout is shared between multiple cellviews (which may happen due to a clone of the layout view\n" "for example), all cellviews are renamed.\n" ) + - gsi::method ("load_layout", static_cast (&lay::LayoutViewBase::load_layout), gsi::arg ("filename"), gsi::arg ("options"), gsi::arg ("technology"), gsi::arg ("add_cellview"), + gsi::method ("load_layout", static_cast (&lay::LayoutViewBase::load_layout), gsi::arg ("filename"), gsi::arg ("options"), gsi::arg ("technology"), gsi::arg ("add_cellview", true), "@brief Loads a (new) file into the layout view with the given technology\n" "\n" "Loads the file given by the \"filename\" parameter and associates it with the given technology.\n" @@ -781,9 +781,9 @@ LAYBASIC_PUBLIC Class decl_LayoutViewBase (QT_EXTERNAL_BASE "\n" "@return The index of the cellview loaded.\n" "\n" - "This version has been introduced in version 0.22.\n" + "This version has been introduced in version 0.22. The 'add_cellview' argument has been made optional in version 0.28.\n" ) + - gsi::method ("load_layout", static_cast (&lay::LayoutViewBase::load_layout), gsi::arg ("filename"), gsi::arg ("options"), gsi::arg ("add_cellview"), + gsi::method ("load_layout", static_cast (&lay::LayoutViewBase::load_layout), gsi::arg ("filename"), gsi::arg ("options"), gsi::arg ("add_cellview", true), "@brief Loads a (new) file into the layout view\n" "\n" "Loads the file given by the \"filename\" parameter.\n" @@ -793,9 +793,9 @@ LAYBASIC_PUBLIC Class decl_LayoutViewBase (QT_EXTERNAL_BASE "\n" "@return The index of the cellview loaded.\n" "\n" - "This method has been introduced in version 0.18.\n" + "This method has been introduced in version 0.18. The 'add_cellview' argument has been made optional in version 0.28.\n" ) + - gsi::method ("load_layout", static_cast (&lay::LayoutViewBase::load_layout), gsi::arg ("filename"), gsi::arg ("technology"), gsi::arg ("add_cellview"), + gsi::method ("load_layout", static_cast (&lay::LayoutViewBase::load_layout), gsi::arg ("filename"), gsi::arg ("technology"), gsi::arg ("add_cellview", true), "@brief Loads a (new) file into the layout view with the given technology\n" "\n" "Loads the file given by the \"filename\" parameter and associates it with the given technology.\n" @@ -804,16 +804,16 @@ LAYBASIC_PUBLIC Class decl_LayoutViewBase (QT_EXTERNAL_BASE "\n" "@return The index of the cellview loaded.\n" "\n" - "This version has been introduced in version 0.22.\n" + "This version has been introduced in version 0.22. The 'add_cellview' argument has been made optional in version 0.28.\n" ) + - gsi::method ("load_layout", static_cast (&lay::LayoutViewBase::load_layout), gsi::arg ("filename"), gsi::arg ("add_cellview"), + gsi::method ("load_layout", static_cast (&lay::LayoutViewBase::load_layout), gsi::arg ("filename"), gsi::arg ("add_cellview", true), "@brief Loads a (new) file into the layout view\n" "\n" "Loads the file given by the \"filename\" parameter.\n" "The add_cellview param controls whether to create a new cellview (true)\n" "or clear all cellviews before (false).\n" "\n" - "@return The index of the cellview loaded.\n" + "@return The index of the cellview loaded. The 'add_cellview' argument has been made optional in version 0.28.\n" ) + gsi::method ("active_cellview", static_cast (&lay::LayoutViewBase::active_cellview_ref), "@brief Gets the active cellview (shown in hierarchy browser)\n" diff --git a/src/laybasic/laybasic/layLayoutCanvas.cc b/src/laybasic/laybasic/layLayoutCanvas.cc index 22bddfc51..df8448c3f 100644 --- a/src/laybasic/laybasic/layLayoutCanvas.cc +++ b/src/laybasic/laybasic/layLayoutCanvas.cc @@ -274,13 +274,8 @@ invert (unsigned char *data, unsigned int width, unsigned int height) } } -#if defined(HAVE_QT) -LayoutCanvas::LayoutCanvas (QWidget *parent, lay::LayoutViewBase *view, const char *name) - : lay::ViewObjectWidget (parent, name), -#else LayoutCanvas::LayoutCanvas (lay::LayoutViewBase *view) : lay::ViewObjectWidget (), -#endif mp_view (view), mp_image (0), mp_image_bg (0), mp_image_fg (0), @@ -300,6 +295,7 @@ LayoutCanvas::LayoutCanvas (lay::LayoutViewBase *view) #if QT_VERSION > 0x050000 m_dpr = devicePixelRatio (); #endif + setObjectName (QString::fromUtf8 ("canvas")); #endif // The gamma value used for subsampling: something between 1.8 and 2.2. diff --git a/src/laybasic/laybasic/layLayoutCanvas.h b/src/laybasic/laybasic/layLayoutCanvas.h index c66ac1fcd..2024692e1 100644 --- a/src/laybasic/laybasic/layLayoutCanvas.h +++ b/src/laybasic/laybasic/layLayoutCanvas.h @@ -144,11 +144,7 @@ Q_OBJECT #endif public: -#if defined(HAVE_QT) - LayoutCanvas (QWidget *parent, lay::LayoutViewBase *view, const char *name = "canvas"); -#else LayoutCanvas (lay::LayoutViewBase *view); -#endif ~LayoutCanvas (); void set_colors (lay::Color background, lay::Color foreground, lay::Color active); diff --git a/src/laybasic/laybasic/layLayoutViewBase.cc b/src/laybasic/laybasic/layLayoutViewBase.cc index f6f1da238..f91536907 100644 --- a/src/laybasic/laybasic/layLayoutViewBase.cc +++ b/src/laybasic/laybasic/layLayoutViewBase.cc @@ -235,11 +235,8 @@ struct OpDeleteLayerProps const double animation_interval = 0.5; -LayoutViewBase::LayoutViewBase (db::Manager *manager, bool editable, lay::Plugin *plugin_parent, unsigned int options) : -#if defined(HAVE_QT) - QFrame (0), -#endif - lay::Dispatcher (plugin_parent, false /*not standalone*/), +LayoutViewBase::LayoutViewBase (db::Manager *manager, bool editable, lay::Plugin *plugin_parent, unsigned int options) + : lay::Dispatcher (plugin_parent, false /*not standalone*/), mp_ui (0), m_editable (editable), m_options (options), @@ -251,15 +248,8 @@ LayoutViewBase::LayoutViewBase (db::Manager *manager, bool editable, lay::Plugin init (manager); } -#if defined(HAVE_QT) -LayoutViewBase::LayoutViewBase (QWidget *parent, lay::LayoutView *ui, db::Manager *manager, bool editable, lay::Plugin *plugin_parent, unsigned int options) : -#else -LayoutViewBase::LayoutViewBase (lay::LayoutView *ui, db::Manager *manager, bool editable, lay::Plugin *plugin_parent, unsigned int options) : -#endif -#if defined(HAVE_QT) - QFrame (parent), -#endif - lay::Dispatcher (plugin_parent, false /*not standalone*/), +LayoutViewBase::LayoutViewBase (lay::LayoutView *ui, db::Manager *manager, bool editable, lay::Plugin *plugin_parent, unsigned int options) + : lay::Dispatcher (plugin_parent, false /*not standalone*/), mp_ui (ui), m_editable (editable), m_options (options), @@ -271,15 +261,8 @@ LayoutViewBase::LayoutViewBase (lay::LayoutView *ui, db::Manager *manager, bool init (manager); } -#if defined(HAVE_QT) -LayoutViewBase::LayoutViewBase (QWidget *parent, lay::LayoutView *ui, lay::LayoutViewBase *source, db::Manager *manager, bool editable, lay::Plugin *plugin_parent, unsigned int options) : -#else -LayoutViewBase::LayoutViewBase (lay::LayoutView *ui, lay::LayoutViewBase *source, db::Manager *manager, bool editable, lay::Plugin *plugin_parent, unsigned int options) : -#endif -#if defined(HAVE_QT) - QFrame (parent), -#endif - lay::Dispatcher (plugin_parent, false /*not standalone*/), +LayoutViewBase::LayoutViewBase (lay::LayoutView *ui, lay::LayoutViewBase *source, db::Manager *manager, bool editable, lay::Plugin *plugin_parent, unsigned int options) + : lay::Dispatcher (plugin_parent, false /*not standalone*/), mp_ui (ui), m_editable (editable), m_options (options), @@ -405,11 +388,7 @@ LayoutViewBase::init (db::Manager *mgr) m_layer_properties_lists.back ()->attach_view (this, (unsigned int) (m_layer_properties_lists.size () - 1)); m_current_layer_list = 0; -#if defined(HAVE_QT) - mp_canvas = new lay::LayoutCanvas (widget (), this); -#else mp_canvas = new lay::LayoutCanvas (this); -#endif // occupy services and editables: // these services get deleted by the canvas destructor automatically: @@ -3375,7 +3354,7 @@ LayoutViewBase::box () const QWidget * LayoutViewBase::widget () { - return this; + return 0; } #endif diff --git a/src/laybasic/laybasic/layLayoutViewBase.h b/src/laybasic/laybasic/layLayoutViewBase.h index f15239fe9..0e1fa29a7 100644 --- a/src/laybasic/laybasic/layLayoutViewBase.h +++ b/src/laybasic/laybasic/layLayoutViewBase.h @@ -155,9 +155,6 @@ struct LAYBASIC_PUBLIC LayerDisplayProperties * It manages the layer display list, bookmark list etc. */ class LAYBASIC_PUBLIC LayoutViewBase : -#if defined(HAVE_QT) - public QFrame, -#endif public lay::Editables, public lay::Dispatcher { @@ -195,20 +192,12 @@ public: /** * @brief Constructor */ -#if defined(HAVE_QT) - LayoutViewBase (QWidget *parent, lay::LayoutView *ui, db::Manager *mgr, bool editable, lay::Plugin *plugin_parent, unsigned int options = (unsigned int) LV_Normal); -#else LayoutViewBase (lay::LayoutView *ui, db::Manager *mgr, bool editable, lay::Plugin *plugin_parent, unsigned int options = (unsigned int) LV_Normal); -#endif /** * @brief Constructor (clone from another view) */ -#if defined(HAVE_QT) - LayoutViewBase (QWidget *widget, lay::LayoutView *ui, lay::LayoutViewBase *source, db::Manager *mgr, bool editable, lay::Plugin *plugin_parent, unsigned int options = (unsigned int) LV_Normal); -#else LayoutViewBase (lay::LayoutView *ui, lay::LayoutViewBase *source, db::Manager *mgr, bool editable, lay::Plugin *plugin_parent, unsigned int options = (unsigned int) LV_Normal); -#endif /** * @brief Destructor @@ -1648,7 +1637,7 @@ public: void absolute_coordinates (bool f); /** - * @brief Get the view object widget + * @brief Get the view object widget (the canvas where the layout is drawn and view objects are placed) * * This method intentionally delivers the ViewObjectWidget, not the * LayoutCanvas to emphasize that the LayoutCanvas object shall not @@ -2638,7 +2627,7 @@ public: /** * @brief Gets the QWidget interface */ - QWidget *widget (); + virtual QWidget *widget (); #endif /** diff --git a/src/laybasic/laybasic/layViewObject.cc b/src/laybasic/laybasic/layViewObject.cc index bd4694ab5..9577f9fcb 100644 --- a/src/laybasic/laybasic/layViewObject.cc +++ b/src/laybasic/laybasic/layViewObject.cc @@ -209,9 +209,10 @@ ViewService::set_cursor (lay::Cursor::cursor_shape cursor) // --------------------------------------------------------------- // ViewObjectWidget implementation +ViewObjectWidget::ViewObjectWidget () #if defined(HAVE_QT) -ViewObjectWidget::ViewObjectWidget (QWidget *parent, const char *name) - : QWidget (parent), + : QWidget (), +#endif m_view_objects_dismissed (false), m_needs_update_static (false), m_needs_update_bg (false), @@ -226,31 +227,13 @@ ViewObjectWidget::ViewObjectWidget (QWidget *parent, const char *name) m_widget_height (0), m_image_updated (false) { - setMouseTracking (true); - setObjectName (QString::fromUtf8 (name)); +#if defined(HAVE_QT) + setMouseTracking (true); setAcceptDrops (true); +#endif m_objects.changed ().add (this, &ViewObjectWidget::objects_changed); } -#else -ViewObjectWidget::ViewObjectWidget () - : m_view_objects_dismissed (false), - m_needs_update_static (false), - m_needs_update_bg (false), - mp_active_service (0), - m_mouse_pressed_state (false), - m_mouse_buttons (0), - m_in_mouse_move (false), - m_mouse_inside (false), - m_cursor (lay::Cursor::none), - m_default_cursor (lay::Cursor::none), - m_widget_width (500), - m_widget_height (500), - m_image_updated (false) -{ - m_objects.changed ().add (this, &ViewObjectWidget::objects_changed); -} -#endif ViewObjectWidget::~ViewObjectWidget () { diff --git a/src/laybasic/laybasic/layViewObject.h b/src/laybasic/laybasic/layViewObject.h index 1df6d04b0..e6997d139 100644 --- a/src/laybasic/laybasic/layViewObject.h +++ b/src/laybasic/laybasic/layViewObject.h @@ -583,11 +583,7 @@ public: /** * @brief ctor */ -#if defined(HAVE_QT) - ViewObjectWidget (QWidget *view, const char *name); -#else ViewObjectWidget (); -#endif /** * @brief dtor diff --git a/src/layview/layview/layLayoutView_qt.cc b/src/layview/layview/layLayoutView_qt.cc index e8805b1b3..b9607b786 100644 --- a/src/layview/layview/layLayoutView_qt.cc +++ b/src/layview/layview/layLayoutView_qt.cc @@ -38,6 +38,7 @@ #include #include #include +#include #include "tlInternational.h" #include "tlExpression.h" @@ -84,10 +85,107 @@ #include "gtf.h" #include +#include namespace lay { +// ------------------------------------------------------------- +// LayoutViewFrame implementation + +LayoutViewFrame::LayoutViewFrame (QWidget *parent, lay::LayoutView *view) + : QFrame (parent), mp_view (view) +{ + // .. nothing yet .. +} + +QSize +LayoutViewFrame::sizeHint () const +{ + return mp_view->size_hint (); +} + +bool +LayoutViewFrame::eventFilter(QObject *obj, QEvent *event) +{ + bool taken = false; + bool res = mp_view->event_filter (obj, event, taken); + if (taken) { + return res; + } else { + return QFrame::eventFilter (obj, event); + } +} + +void LayoutViewFrame::showEvent (QShowEvent *) +{ + mp_view->show_event (); +} + +void LayoutViewFrame::hideEvent (QHideEvent *) +{ + mp_view->hide_event (); +} + +// ------------------------------------------------------------- +// LayoutViewConnector implementation + +LayoutViewSignalConnector::LayoutViewSignalConnector (QObject *parent, lay::LayoutView *view) + : QObject (parent), mp_view (view) +{ + // .. nothing yet .. +} + +void LayoutViewSignalConnector::active_cellview_changed (int index) +{ + mp_view->active_cellview_changed (index); +} + +void LayoutViewSignalConnector::active_library_changed (int index) +{ + mp_view->active_cellview_changed (index); +} + +void LayoutViewSignalConnector::side_panel_destroyed () +{ + mp_view->side_panel_destroyed (sender ()); +} + +void LayoutViewSignalConnector::select_cell_dispatch (const lay::LayoutViewBase::cell_path_type &path, int cellview_index) +{ + mp_view->select_cell_dispatch (path, cellview_index); +} + +void LayoutViewSignalConnector::current_layer_changed_slot (const lay::LayerPropertiesConstIterator &iter) +{ + mp_view->current_layer_changed_slot (iter); +} + +void LayoutViewSignalConnector::timer () +{ + mp_view->timer (); +} + +void LayoutViewSignalConnector::layer_tab_changed () +{ + mp_view->layer_tab_changed (); +} + +void LayoutViewSignalConnector::layer_order_changed () +{ + mp_view->layer_order_changed (); +} + +void LayoutViewSignalConnector::min_hier_changed (int i) +{ + mp_view->min_hier_changed (i); +} + +void LayoutViewSignalConnector::max_hier_changed (int i) +{ + mp_view->max_hier_changed (i); +} + // ------------------------------------------------------------- const int timer_interval = 10; @@ -95,35 +193,37 @@ const int timer_interval = 10; static LayoutView *ms_current = 0; LayoutView::LayoutView (db::Manager *manager, bool editable, lay::Plugin *plugin_parent, QWidget *parent, const char *name, unsigned int options) - : LayoutViewBase (parent, this, manager, editable, plugin_parent, options), + : LayoutViewBase (this, manager, editable, plugin_parent, options), + mp_widget (0), dm_setup_editor_option_pages (this, &LayoutView::do_setup_editor_options_pages) { // ensures the deferred method scheduler is present tl::DeferredMethodScheduler::instance (); - setObjectName (QString::fromUtf8(name)); - init_ui (); + init_ui (parent, name); } LayoutView::LayoutView (lay::LayoutView *source, db::Manager *manager, bool editable, lay::Plugin *plugin_parent, QWidget *parent, const char *name, unsigned int options) - : LayoutViewBase (parent, this, source, manager, editable, plugin_parent, options), + : LayoutViewBase (this, source, manager, editable, plugin_parent, options), + mp_widget (0), dm_setup_editor_option_pages (this, &LayoutView::do_setup_editor_options_pages) { // ensures the deferred method scheduler is present tl::DeferredMethodScheduler::instance (); - setObjectName (QString::fromUtf8 (name)); - init_ui (); + init_ui (parent, name); bookmarks (source->bookmarks ()); set_active_cellview_index (source->active_cellview_index ()); } bool -LayoutView::eventFilter(QObject *obj, QEvent *event) +LayoutView::event_filter (QObject *obj, QEvent *event, bool &taken) { if (obj == mp_min_hier_spbx || obj == mp_max_hier_spbx) { + taken = true; + // Makes the min/max spin boxes accept only numeric and some control keys .. QKeyEvent *keyEvent = dynamic_cast(event); if (keyEvent && @@ -133,13 +233,11 @@ LayoutView::eventFilter(QObject *obj, QEvent *event) keyEvent->key () != Qt::Key_Backspace && (keyEvent->key () < Qt::Key_0 || keyEvent->key () > Qt::Key_9)) { return true; - } else { - return false; } - } else { - return QFrame::eventFilter (obj, event); } + + return false; } void @@ -163,13 +261,21 @@ LayoutView::init_menu () } void -LayoutView::init_ui () +LayoutView::init_ui (QWidget *parent, const char *name) { +#if QT_VERSION < 0x50000 + bool has_gui = (QApplication::type () != Qt::Tty); +#else + bool has_gui = (qGuiApp != 0); +#endif + m_activated = true; m_always_show_source = false; m_always_show_ld = true; m_always_show_layout_index = false; + mp_widget = 0; + mp_connector = 0; mp_timer = 0; mp_left_frame = 0; mp_control_panel = 0; @@ -184,125 +290,126 @@ LayoutView::init_ui () mp_min_hier_spbx = 0; mp_max_hier_spbx = 0; - QVBoxLayout *vbl = new QVBoxLayout (this); - vbl->setContentsMargins (0, 0, 0, 0); - vbl->setSpacing (0); - vbl->addWidget (view_object_widget ()); + if (has_gui) { - if ((options () & LV_NoHierarchyPanel) == 0 && (options () & LV_Naked) == 0) { + mp_widget = new LayoutViewFrame (parent, this); + mp_widget->setObjectName (QString::fromUtf8 (name)); + view_object_widget ()->setParent (mp_widget); - QFrame *hierarchy_frame = new QFrame (0); - hierarchy_frame->setObjectName (QString::fromUtf8 ("left")); - mp_hierarchy_frame = hierarchy_frame; - QVBoxLayout *left_frame_ly = new QVBoxLayout (hierarchy_frame); - left_frame_ly->setContentsMargins (0, 0, 0, 0); - left_frame_ly->setSpacing (0); + mp_connector = new LayoutViewSignalConnector (mp_widget, this); - mp_hierarchy_panel = new lay::HierarchyControlPanel (this, hierarchy_frame, "hcp"); - left_frame_ly->addWidget (mp_hierarchy_panel, 1 /*stretch*/); + QVBoxLayout *vbl = new QVBoxLayout (mp_widget); + vbl->setContentsMargins (0, 0, 0, 0); + vbl->setSpacing (0); + vbl->addWidget (view_object_widget ()); - connect (mp_hierarchy_panel, SIGNAL (cell_selected (cell_path_type, int)), this, SLOT (select_cell_dispatch (cell_path_type, int))); - connect (mp_hierarchy_panel, SIGNAL (active_cellview_changed (int)), this, SLOT (active_cellview_changed (int))); - connect (mp_hierarchy_frame, SIGNAL (destroyed ()), this, SLOT (side_panel_destroyed ())); + if ((options () & LV_NoHierarchyPanel) == 0 && (options () & LV_Naked) == 0) { - QFrame *levels_frame = new QFrame (hierarchy_frame); - levels_frame->setObjectName (QString::fromUtf8 ("lvl_frame")); - left_frame_ly->addWidget (levels_frame); - QHBoxLayout *levels_frame_ly = new QHBoxLayout (levels_frame); - levels_frame_ly->setContentsMargins (1, 1, 1, 1); - QLabel *level_l1 = new QLabel (tl::to_qstring (" " + tl::to_string (QObject::tr ("Levels"))), levels_frame); - levels_frame_ly->addWidget (level_l1); - mp_min_hier_spbx = new QSpinBox (levels_frame); - mp_min_hier_spbx->setObjectName (QString::fromUtf8 ("min_lvl")); - levels_frame_ly->addWidget (mp_min_hier_spbx); - QLabel *level_l2 = new QLabel (QString::fromUtf8 (".."), levels_frame); - levels_frame_ly->addWidget (level_l2); - mp_max_hier_spbx = new QSpinBox (levels_frame); - mp_max_hier_spbx->setObjectName (QString::fromUtf8 ("max_lvl")); - levels_frame_ly->addWidget (mp_max_hier_spbx); + QFrame *hierarchy_frame = new QFrame (0); + hierarchy_frame->setObjectName (QString::fromUtf8 ("left")); + mp_hierarchy_frame = hierarchy_frame; + QVBoxLayout *left_frame_ly = new QVBoxLayout (hierarchy_frame); + left_frame_ly->setContentsMargins (0, 0, 0, 0); + left_frame_ly->setSpacing (0); - mp_min_hier_spbx->installEventFilter (this); - mp_max_hier_spbx->installEventFilter (this); + mp_hierarchy_panel = new lay::HierarchyControlPanel (this, hierarchy_frame, "hcp"); + left_frame_ly->addWidget (mp_hierarchy_panel, 1 /*stretch*/); - mp_min_hier_spbx->setMaximum (0); - mp_min_hier_spbx->setMinimum (-1000); - mp_min_hier_spbx->setValue (0); - mp_max_hier_spbx->setMaximum (999); - mp_max_hier_spbx->setValue (0); - mp_max_hier_spbx->setMinimum (-1000); + QObject::connect (mp_hierarchy_panel, SIGNAL (cell_selected (cell_path_type, int)), mp_connector, SLOT (select_cell_dispatch (cell_path_type, int))); + QObject::connect (mp_hierarchy_panel, SIGNAL (active_cellview_changed (int)), mp_connector, SLOT (active_cellview_changed (int))); + QObject::connect (mp_hierarchy_frame, SIGNAL (destroyed ()), mp_connector, SLOT (side_panel_destroyed ())); - connect (mp_min_hier_spbx, SIGNAL (valueChanged (int)), this, SLOT (min_hier_changed (int))); - connect (mp_max_hier_spbx, SIGNAL (valueChanged (int)), this, SLOT (max_hier_changed (int))); + QFrame *levels_frame = new QFrame (hierarchy_frame); + levels_frame->setObjectName (QString::fromUtf8 ("lvl_frame")); + left_frame_ly->addWidget (levels_frame); + QHBoxLayout *levels_frame_ly = new QHBoxLayout (levels_frame); + levels_frame_ly->setContentsMargins (1, 1, 1, 1); + QLabel *level_l1 = new QLabel (tl::to_qstring (" " + tl::to_string (QObject::tr ("Levels"))), levels_frame); + levels_frame_ly->addWidget (level_l1); + mp_min_hier_spbx = new QSpinBox (levels_frame); + mp_min_hier_spbx->setObjectName (QString::fromUtf8 ("min_lvl")); + levels_frame_ly->addWidget (mp_min_hier_spbx); + QLabel *level_l2 = new QLabel (QString::fromUtf8 (".."), levels_frame); + levels_frame_ly->addWidget (level_l2); + mp_max_hier_spbx = new QSpinBox (levels_frame); + mp_max_hier_spbx->setObjectName (QString::fromUtf8 ("max_lvl")); + levels_frame_ly->addWidget (mp_max_hier_spbx); - } + mp_min_hier_spbx->installEventFilter (mp_widget); + mp_max_hier_spbx->installEventFilter (mp_widget); - if ((options () & LV_NoBookmarksView) == 0 && (options () & LV_Naked) == 0) { + mp_min_hier_spbx->setMaximum (0); + mp_min_hier_spbx->setMinimum (-1000); + mp_min_hier_spbx->setValue (0); + mp_max_hier_spbx->setMaximum (999); + mp_max_hier_spbx->setValue (0); + mp_max_hier_spbx->setMinimum (-1000); - QFrame *bookmarks_frame = new QFrame (0); - bookmarks_frame->setObjectName (QString::fromUtf8 ("bookmarks_frame")); - mp_bookmarks_frame = bookmarks_frame; - QVBoxLayout *left_frame_ly = new QVBoxLayout (bookmarks_frame); - left_frame_ly->setContentsMargins (0, 0, 0, 0); - left_frame_ly->setSpacing (0); + QObject::connect (mp_min_hier_spbx, SIGNAL (valueChanged (int)), mp_connector, SLOT (min_hier_changed (int))); + QObject::connect (mp_max_hier_spbx, SIGNAL (valueChanged (int)), mp_connector, SLOT (max_hier_changed (int))); - mp_bookmarks_view = new lay::BookmarksView (this, bookmarks_frame, "bookmarks"); - left_frame_ly->addWidget (mp_bookmarks_view, 1 /*stretch*/); + } - connect (mp_bookmarks_frame, SIGNAL (destroyed ()), this, SLOT (side_panel_destroyed ())); + if ((options () & LV_NoBookmarksView) == 0 && (options () & LV_Naked) == 0) { - } + QFrame *bookmarks_frame = new QFrame (0); + bookmarks_frame->setObjectName (QString::fromUtf8 ("bookmarks_frame")); + mp_bookmarks_frame = bookmarks_frame; + QVBoxLayout *left_frame_ly = new QVBoxLayout (bookmarks_frame); + left_frame_ly->setContentsMargins (0, 0, 0, 0); + left_frame_ly->setSpacing (0); - if ((options () & LV_NoLibrariesView) == 0 && (options () & LV_Naked) == 0) { + mp_bookmarks_view = new lay::BookmarksView (this, bookmarks_frame, "bookmarks"); + left_frame_ly->addWidget (mp_bookmarks_view, 1 /*stretch*/); - mp_libraries_frame = new QFrame (0); - mp_libraries_frame->setObjectName (QString::fromUtf8 ("libs_frame")); - QVBoxLayout *left_frame_ly = new QVBoxLayout (mp_libraries_frame); - left_frame_ly->setContentsMargins (0, 0, 0, 0); - left_frame_ly->setSpacing (0); + QObject::connect (mp_bookmarks_frame, SIGNAL (destroyed ()), mp_connector, SLOT (side_panel_destroyed ())); - mp_libraries_view = new lay::LibrariesView (this, mp_libraries_frame, "libs"); - left_frame_ly->addWidget (mp_libraries_view, 1 /*stretch*/); + } - connect (mp_libraries_view, SIGNAL (active_library_changed (int)), this, SLOT (active_library_changed (int))); - connect (mp_libraries_frame, SIGNAL (destroyed ()), this, SLOT (side_panel_destroyed ())); + if ((options () & LV_NoLibrariesView) == 0 && (options () & LV_Naked) == 0) { - } + mp_libraries_frame = new QFrame (0); + mp_libraries_frame->setObjectName (QString::fromUtf8 ("libs_frame")); + QVBoxLayout *left_frame_ly = new QVBoxLayout (mp_libraries_frame); + left_frame_ly->setContentsMargins (0, 0, 0, 0); + left_frame_ly->setSpacing (0); - if ((options () & LV_NoEditorOptionsPanel) == 0 && (options () & LV_Naked) == 0) { + mp_libraries_view = new lay::LibrariesView (this, mp_libraries_frame, "libs"); + left_frame_ly->addWidget (mp_libraries_view, 1 /*stretch*/); - mp_editor_options_frame = new lay::EditorOptionsFrame (0); - mp_editor_options_frame->populate (this); + QObject::connect (mp_libraries_view, SIGNAL (active_library_changed (int)), mp_connector, SLOT (active_library_changed (int))); + QObject::connect (mp_libraries_frame, SIGNAL (destroyed ()), mp_connector, SLOT (side_panel_destroyed ())); - connect (mp_editor_options_frame, SIGNAL (destroyed ()), this, SLOT (side_panel_destroyed ())); + } - } + if ((options () & LV_NoEditorOptionsPanel) == 0 && (options () & LV_Naked) == 0) { - if ((options () & LV_NoLayers) == 0 && (options () & LV_Naked) == 0) { + mp_editor_options_frame = new lay::EditorOptionsFrame (0); + mp_editor_options_frame->populate (this); - mp_control_panel = new lay::LayerControlPanel (this, manager (), 0, "lcp"); - mp_control_frame = mp_control_panel; + QObject::connect (mp_editor_options_frame, SIGNAL (destroyed ()), mp_connector, SLOT (side_panel_destroyed ())); - connect (mp_control_frame, SIGNAL (destroyed ()), this, SLOT (side_panel_destroyed ())); - connect (mp_control_panel, SIGNAL (tab_changed ()), this, SLOT (layer_tab_changed ())); - connect (mp_control_panel, SIGNAL (order_changed ()), this, SLOT (layer_order_changed ())); - connect (mp_control_panel, SIGNAL (current_layer_changed (const lay::LayerPropertiesConstIterator &)), this, SLOT (current_layer_changed_slot (const lay::LayerPropertiesConstIterator &))); - /* - connect (mp_control_panel, SIGNAL (marked_changed ()), this, SLOT (prop_changed ())); - connect (mp_control_panel, SIGNAL (width_changed ()), this, SLOT (prop_changed ())); - connect (mp_control_panel, SIGNAL (animation_changed ()), this, SLOT (prop_changed ())); - connect (mp_control_panel, SIGNAL (visibility_changed ()), this, SLOT (visibility_changed ())); - connect (mp_control_panel, SIGNAL (transparency_changed ()), this, SLOT (prop_changed ())); - connect (mp_control_panel, SIGNAL (stipple_changed ()), this, SLOT (prop_changed ())); - connect (mp_control_panel, SIGNAL (color_changed ()), this, SLOT (prop_changed ())); - */ + } + + if ((options () & LV_NoLayers) == 0 && (options () & LV_Naked) == 0) { + + mp_control_panel = new lay::LayerControlPanel (this, manager (), 0, "lcp"); + mp_control_frame = mp_control_panel; + + QObject::connect (mp_control_frame, SIGNAL (destroyed ()), mp_connector, SLOT (side_panel_destroyed ())); + QObject::connect (mp_control_panel, SIGNAL (tab_changed ()), mp_connector, SLOT (layer_tab_changed ())); + QObject::connect (mp_control_panel, SIGNAL (order_changed ()), mp_connector, SLOT (layer_order_changed ())); + QObject::connect (mp_control_panel, SIGNAL (current_layer_changed (const lay::LayerPropertiesConstIterator &)), mp_connector, SLOT (current_layer_changed_slot (const lay::LayerPropertiesConstIterator &))); + + } + + mp_timer = new QTimer (mp_widget); + QObject::connect (mp_timer, SIGNAL (timeout ()), mp_connector, SLOT (timer ())); + mp_timer->start (timer_interval); } config_setup (); - - mp_timer = new QTimer (this); - connect (mp_timer, SIGNAL (timeout ()), this, SLOT (timer ())); - mp_timer->start (timer_interval); } LayoutView::~LayoutView () @@ -369,35 +476,25 @@ void LayoutView::do_setup_editor_options_pages () } } -void LayoutView::side_panel_destroyed () +void LayoutView::side_panel_destroyed (QObject *sender) { - if (sender () == mp_control_frame) { + if (sender == mp_control_frame) { mp_control_frame = 0; mp_control_panel = 0; - } else if (sender () == mp_hierarchy_frame) { + } else if (sender == mp_hierarchy_frame) { mp_hierarchy_frame = 0; mp_hierarchy_panel = 0; - } else if (sender () == mp_libraries_frame) { + } else if (sender == mp_libraries_frame) { mp_libraries_frame = 0; mp_libraries_view = 0; - } else if (sender () == mp_editor_options_frame) { + } else if (sender == mp_editor_options_frame) { mp_editor_options_frame = 0; - } else if (sender () == mp_bookmarks_frame) { + } else if (sender == mp_bookmarks_frame) { mp_bookmarks_frame = 0; mp_bookmarks_view = 0; } } -void LayoutView::hideEvent (QHideEvent *) -{ - hide_event (); -} - -void LayoutView::showEvent (QShowEvent *) -{ - show_event (); -} - void LayoutView::set_current () { set_current (this); @@ -613,6 +710,8 @@ LayoutView::set_current_layer (const lay::LayerPropertiesConstIterator &l) { if (mp_control_panel) { mp_control_panel->set_current_layer (l); + } else { + return LayoutViewBase::set_current_layer (l); } } @@ -622,7 +721,7 @@ LayoutView::current_layer () const if (mp_control_panel) { return mp_control_panel->current_layer (); } else { - return lay::LayerPropertiesConstIterator (); + return LayoutViewBase::current_layer (); } } @@ -632,7 +731,7 @@ LayoutView::selected_layers () const if (mp_control_panel) { return mp_control_panel->selected_layers (); } else { - return std::vector (); + return LayoutViewBase::selected_layers (); } } @@ -641,6 +740,8 @@ LayoutView::set_selected_layers (const std::vectorset_selection (sel); + } else { + LayoutViewBase::set_selected_layers (sel); } } @@ -649,6 +750,8 @@ LayoutView::begin_layer_updates () { if (mp_control_panel) { mp_control_panel->begin_updates (); + } else { + LayoutViewBase::begin_layer_updates (); } } @@ -657,6 +760,8 @@ LayoutView::end_layer_updates () { if (mp_control_panel) { mp_control_panel->end_updates (); + } else { + LayoutViewBase::end_layer_updates (); } } @@ -668,23 +773,27 @@ LayoutView::layer_model_updated () if (mp_control_panel) { return mp_control_panel->model_updated (); } else { - return false; + return LayoutViewBase::layer_model_updated (); } } void LayoutView::bookmark_current_view () { + if (! mp_widget) { + return; + } + QString proposed_name = tl::to_qstring (bookmarks ().propose_new_bookmark_name ()); while (true) { bool ok = false; - QString text = QInputDialog::getText (this, QObject::tr ("Enter Bookmark Name"), QObject::tr ("Bookmark name"), + QString text = QInputDialog::getText (mp_widget, QObject::tr ("Enter Bookmark Name"), QObject::tr ("Bookmark name"), QLineEdit::Normal, proposed_name, &ok); if (! ok) { break; } else if (text.isEmpty ()) { - QMessageBox::critical (this, QObject::tr ("Error"), QObject::tr ("Enter a name for the bookmark")); + QMessageBox::critical (mp_widget, QObject::tr ("Error"), QObject::tr ("Enter a name for the bookmark")); } else { bookmark_view (tl::to_string (text)); break; @@ -695,12 +804,16 @@ LayoutView::bookmark_current_view () void LayoutView::manage_bookmarks () { + if (! mp_widget) { + return; + } + std::set selected_bm; if (mp_bookmarks_frame->isVisible ()) { selected_bm = mp_bookmarks_view->selected_bookmarks (); } - BookmarkManagementForm dialog (this, "bookmark_form", bookmarks (), selected_bm); + BookmarkManagementForm dialog (mp_widget, "bookmark_form", bookmarks (), selected_bm); if (dialog.exec ()) { bookmarks (dialog.bookmarks ()); } @@ -710,7 +823,9 @@ void LayoutView::bookmarks_changed () { mp_bookmarks_view->refresh (); - emit menu_needs_update (); + if (mp_widget) { + mp_widget->emit_menu_needs_update (); + } } void @@ -742,7 +857,11 @@ LayoutView::max_hier_changed (int i) lay::Color LayoutView::default_background_color () { - return lay::Color (palette ().color (QPalette::Normal, QPalette::Base).rgb ()); + if (! mp_widget) { + return LayoutViewBase::default_background_color (); + } else { + return lay::Color (mp_widget->palette ().color (QPalette::Normal, QPalette::Base).rgb ()); + } } void @@ -931,7 +1050,10 @@ LayoutView::deactivate () } } - emit clear_current_pos (); + if (mp_widget) { + mp_widget->emit_clear_current_pos (); + } + free_resources (); mp_timer->stop (); m_activated = false; @@ -964,6 +1086,10 @@ LayoutView::update_content_for_cv (int cellview_index) void LayoutView::current_pos (double x, double y) { + if (! mp_widget) { + return; + } + if (m_activated) { if (dbu_coordinates ()) { double dx = 0.0, dy = 0.0; @@ -972,9 +1098,9 @@ LayoutView::current_pos (double x, double y) dx = x / dbu; dy = y / dbu; } - emit current_pos_changed (dx, dy, true); + mp_widget->emit_current_pos_changed (dx, dy, true); } else { - emit current_pos_changed (x, y, false); + mp_widget->emit_current_pos_changed (x, y, false); } } } @@ -982,25 +1108,33 @@ LayoutView::current_pos (double x, double y) void LayoutView::emit_edits_enabled_changed () { - emit edits_enabled_changed (); + if (mp_widget) { + mp_widget->emit_edits_enabled_changed (); + } } void LayoutView::emit_title_changed () { - emit title_changed (); + if (mp_widget) { + mp_widget->emit_title_changed (); + } } void LayoutView::emit_dirty_changed () { - emit dirty_changed (); + if (mp_widget) { + mp_widget->emit_dirty_changed (); + } } void LayoutView::emit_layer_order_changed () { - emit layer_order_changed (); + if (mp_widget) { + mp_widget->emit_layer_order_changed (); + } } void @@ -1016,7 +1150,9 @@ LayoutView::signal_selection_changed () void LayoutView::message (const std::string &s, int timeout) { - emit show_message (s, timeout * 1000); + if (mp_widget) { + mp_widget->emit_show_message (s, timeout * 1000); + } } void @@ -1050,7 +1186,9 @@ LayoutView::switch_mode (int m) { if (mode () != m) { mode (m); - emit mode_change (m); + if (mp_widget) { + mp_widget->emit_mode_change (m); + } } } @@ -1073,7 +1211,7 @@ LayoutView::open_rdb_browser (int rdb_index, int cv_index) } QSize -LayoutView::sizeHint () const +LayoutView::size_hint () const { if ((options () & LV_Naked) != 0) { return QSize (200, 200); diff --git a/src/layview/layview/layLayoutView_qt.h b/src/layview/layview/layLayoutView_qt.h index fe65fde62..ae44e076b 100644 --- a/src/layview/layview/layLayoutView_qt.h +++ b/src/layview/layview/layLayoutView_qt.h @@ -86,6 +86,118 @@ class ColorButton; class ConfigureAction; class EditorOptionsPages; +/** + * @brief A custom QFrame that acts as the central widget for the LayoutView + */ +class LayoutViewFrame + : public QFrame +{ +Q_OBJECT + +public: + LayoutViewFrame (QWidget *parent, lay::LayoutView *view); + + virtual QSize sizeHint () const; + virtual bool eventFilter(QObject *obj, QEvent *event); + virtual void showEvent (QShowEvent *); + virtual void hideEvent (QHideEvent *); + + void emit_title_changed () { emit title_changed (); } + void emit_dirty_changed () { emit dirty_changed (); } + void emit_show_message (const std::string &s, int ms) { emit show_message (s, ms); } + void emit_current_pos_changed (double x, double y, bool dbu_units) { emit current_pos_changed (x, y, dbu_units); } + void emit_clear_current_pos () { emit clear_current_pos (); } + void emit_edits_enabled_changed () { emit edits_enabled_changed (); } + void emit_mode_change (int m) { emit mode_change (m); } + void emit_current_layer_changed (const lay::LayerPropertiesConstIterator &l) { emit current_layer_changed (l); } + void emit_menu_needs_update () { emit menu_needs_update (); } + void emit_layer_order_changed () { emit layer_order_changed (); } + +signals: + /** + * @brief This signal is emitted when the title changes + */ + void title_changed (); + + /** + * @brief This signal is emitted when the "dirty" flag changes + */ + void dirty_changed (); + + /** + * @brief This signal is emitted when the view wants to show a message for the given time (of infinitely for ms == 0) + */ + void show_message (const std::string &s, int ms); + + /** + * @brief This signal is emitted when the view wants to indicate a mouse position change + */ + void current_pos_changed (double x, double y, bool dbu_units); + + /** + * @brief This signal is emitted when the view wants to clear the mouse position + */ + void clear_current_pos (); + + /** + * @brief This signal is sent when the "edits_enabled" state has changed + */ + void edits_enabled_changed (); + + /** + * @brief This signal is sent when the view wants to update the menu + */ + void menu_needs_update (); + + /** + * @brief The view initiated a mode change + */ + void mode_change (int m); + + /** + * @brief The current layer changed + */ + void current_layer_changed (const lay::LayerPropertiesConstIterator &l); + + /** + * @brief The layer order has changed + */ + void layer_order_changed (); + +private: + LayoutView *mp_view; +}; + +/** + * @brief An object connecting child widget signals with methods from LayoutView + */ +class LayoutViewSignalConnector + : public QObject +{ +Q_OBJECT + +public: + LayoutViewSignalConnector (QObject *parent, lay::LayoutView *view); + + typedef lay::LayoutViewBase::cell_path_type cell_path_type; + +private slots: + void active_cellview_changed (int index); + void active_library_changed (int index); + void side_panel_destroyed (); + void current_layer_changed_slot (const lay::LayerPropertiesConstIterator &iter); + void layer_tab_changed (); + void layer_order_changed (); + void select_cell_dispatch (const cell_path_type &path, int cellview_index); + void min_hier_changed (int i); + void max_hier_changed (int i); + + void timer (); + +private: + LayoutView *mp_view; +}; + /** * @brief The layout view object * @@ -96,8 +208,6 @@ class EditorOptionsPages; class LAYVIEW_PUBLIC LayoutView : public LayoutViewBase { -Q_OBJECT - public: /** * @brief Constructor @@ -409,9 +519,14 @@ public: virtual void cut (); /** - * @brief Deliver a size hint (reimplementation of QWidget) + * @brief Gets the widget object + * + * This pointer may be 0 if the layout view is created in a headless environment. */ - virtual QSize sizeHint () const; + virtual QWidget *widget () + { + return mp_widget; + } /** * @brief An event signalling that the view is going to close @@ -428,7 +543,6 @@ public: */ tl::Event hide_event; -public slots: /** * @brief Store the current state on the "previous states" stack */ @@ -509,25 +623,6 @@ public slots: LayoutViewBase::ensure_selection_visible (); } - /** - * @brief Select a cell by index for a certain cell view - * - * This will be forwarded to select_cell or select_cell_fit depending - * on the m_fit_new_cell flag. - */ - void select_cell_dispatch (const cell_path_type &path, int cellview_index) - { - LayoutViewBase::select_cell_dispatch (path, cellview_index); - } - - /** - * @brief Called when the current layer changed - */ - void current_layer_changed_slot (const lay::LayerPropertiesConstIterator &iter) - { - LayoutViewBase::current_layer_changed_slot (iter); - } - // zoom slots void zoom_fit () { @@ -610,76 +705,15 @@ public slots: LayoutViewBase::redraw_cell_boxes (); } - void layer_tab_changed (); - void layer_order_changed (); - - void timer () - { - LayoutViewBase::timer (); - } - - void min_hier_changed (int i); - void max_hier_changed (int i); - void deactivate_all_browsers (); -private slots: - void active_cellview_changed (int index) - { - LayoutViewBase::active_cellview_changed (index); - } - - void active_library_changed (int index); - void side_panel_destroyed (); - -signals: - /** - * @brief This signal is emitted when the title changes - */ - void title_changed (); - - /** - * @brief This signal is emitted when the "dirty" flag changes - */ - void dirty_changed (); - - /** - * @brief This signal is emitted when the view wants to show a message for the given time (of infinitely for ms == 0) - */ - void show_message (const std::string &s, int ms); - - /** - * @brief This signal is emitted when the view wants to indicate a mouse position change - */ - void current_pos_changed (double x, double y, bool dbu_units); - - /** - * @brief This signal is emitted when the view wants to clear the mouse position - */ - void clear_current_pos (); - - /** - * @brief This signal is sent when the "edits_enabled" state has changed - */ - void edits_enabled_changed (); - - /** - * @brief This signal is sent when the view wants to update the menu - */ - void menu_needs_update (); - - /** - * @brief The view initiated a mode change - */ - void mode_change (int m); - - /** - * @brief The current layer changed - */ - void current_layer_changed (const lay::LayerPropertiesConstIterator &l); - private: + friend class LayoutViewSignalConnector; + friend class LayoutViewFrame; + QTimer *mp_timer; + LayoutViewFrame *mp_widget; + LayoutViewSignalConnector *mp_connector; bool m_activated; QFrame *mp_left_frame; lay::LayerControlPanel *mp_control_panel; @@ -696,7 +730,17 @@ private: tl::DeferredMethod dm_setup_editor_option_pages; - void init_ui (); + void active_library_changed (int index); + void side_panel_destroyed (QObject *sender); + void layer_tab_changed (); + void layer_order_changed (); + void min_hier_changed (int i); + void max_hier_changed (int i); + + bool event_filter (QObject *obj, QEvent *ev, bool &taken); + QSize size_hint () const; + + void init_ui (QWidget *parent, const char *name); void init_menu (); void do_setup_editor_options_pages (); @@ -704,10 +748,6 @@ protected: void activate (); void deactivate (); - virtual bool eventFilter(QObject *obj, QEvent *ev); - virtual void showEvent (QShowEvent *); - virtual void hideEvent (QHideEvent *); - virtual bool configure (const std::string &name, const std::string &value); virtual void config_finalize ();