diff --git a/src/ant/ant/antPlugin.cc b/src/ant/ant/antPlugin.cc index 22a3fcaa4..c81176af9 100644 --- a/src/ant/ant/antPlugin.cc +++ b/src/ant/ant/antPlugin.cc @@ -24,10 +24,10 @@ #include "layPlugin.h" #include "layConverters.h" #include "layDispatcher.h" +#include "layAbstractMenu.h" #include "tlColor.h" #if defined(HAVE_QT) # include "layConfigurationDialog.h" -# include "layAbstractMenu.h" #endif #include "antConfig.h" #if defined(HAVE_QT) @@ -214,15 +214,12 @@ PluginDeclaration::initialized (lay::Dispatcher *root) void PluginDeclaration::uninitialize (lay::Dispatcher *) { -#if defined(HAVE_QT) m_actions.clear (); -#endif } void PluginDeclaration::update_current_template () { -#if defined(HAVE_QT) lay::Dispatcher *mp = lay::Dispatcher::instance (); if (! mp || ! mp->has_ui ()) { return; @@ -248,13 +245,11 @@ PluginDeclaration::update_current_template () } } -#endif } void PluginDeclaration::update_menu () { -#if defined(HAVE_QT) lay::Dispatcher *mp = lay::Dispatcher::instance (); if (! mp || ! mp->has_ui ()) { return; @@ -294,7 +289,6 @@ PluginDeclaration::update_menu () } } } -#endif } void diff --git a/src/ant/ant/antPlugin.h b/src/ant/ant/antPlugin.h index 0b8b4ac05..37e90870e 100644 --- a/src/ant/ant/antPlugin.h +++ b/src/ant/ant/antPlugin.h @@ -64,9 +64,7 @@ private: std::vector m_templates; int m_current_template; -#if defined(HAVE_QT) tl::weak_collection m_actions; -#endif bool m_current_template_updated; bool m_templates_updated; }; diff --git a/src/lay/lay/layMainWindow.cc b/src/lay/lay/layMainWindow.cc index c9abd8ddc..388b0d533 100644 --- a/src/lay/lay/layMainWindow.cc +++ b/src/lay/lay/layMainWindow.cc @@ -180,6 +180,7 @@ MainWindow::MainWindow (QApplication *app, const char *name, bool undo_enabled) m_manager (undo_enabled) { m_dispatcher.set_menu_parent_widget (this); + m_dispatcher.make_menu (); // ensures the deferred method scheduler is present tl::DeferredMethodScheduler::instance (); diff --git a/src/laybasic/laybasic/gsiDeclLayLayoutViewBase.cc b/src/laybasic/laybasic/gsiDeclLayLayoutViewBase.cc index 1827f509f..fbbbb4ed9 100644 --- a/src/laybasic/laybasic/gsiDeclLayLayoutViewBase.cc +++ b/src/laybasic/laybasic/gsiDeclLayLayoutViewBase.cc @@ -461,6 +461,11 @@ static LayerPropertiesConstIteratorWrapper each_layer2 (lay::LayoutViewBase *vie return LayerPropertiesConstIteratorWrapper (view->begin_layers (list_index)); } +static lay::AbstractMenu *menu (lay::LayoutViewBase *view) +{ + return view->menu (); +} + #if defined(HAVE_QT) LAYBASIC_PUBLIC Class decl_LayoutViewBase (QT_EXTERNAL_BASE (QWidget) "lay", "LayoutViewBase", #else @@ -976,6 +981,14 @@ LAYBASIC_PUBLIC Class decl_LayoutViewBase (QT_EXTERNAL_BASE "\n" "This method has been introduced in version 0.28." ) + + gsi::method_ext ("menu", &menu, + "@brief Gets the \\AbstractMenu associated with this view.\n" + "\n" + "In normal UI application mode this is the main window's view. For a detached view or in non-UI " + "applications this is the view's private menu.\n" + "\n" + "This method has been introduced in version 0.28." + ) + gsi::method ("call_menu", &lay::LayoutViewBase::menu_activated, gsi::arg ("symbol"), "@brief Calls the menu item with the provided symbol.\n" "To obtain all symbols, use \\menu_symbols.\n" diff --git a/src/layui/layui/gsiDeclLayMenu.cc b/src/laybasic/laybasic/gsiDeclLayMenu.cc similarity index 99% rename from src/layui/layui/gsiDeclLayMenu.cc rename to src/laybasic/laybasic/gsiDeclLayMenu.cc index 9bf185495..559ddf8e7 100644 --- a/src/layui/layui/gsiDeclLayMenu.cc +++ b/src/laybasic/laybasic/gsiDeclLayMenu.cc @@ -20,8 +20,6 @@ */ -#if defined(HAVE_QT) - #include "gsiDecl.h" #include "gsiSignals.h" #include "layAbstractMenu.h" @@ -411,5 +409,3 @@ Class decl_Action (decl_ActionBase, "lay", "Action", ); } - -#endif diff --git a/src/laybasic/laybasic/layAbstractMenu.cc b/src/laybasic/laybasic/layAbstractMenu.cc index e7b587f9a..beb6b2045 100644 --- a/src/laybasic/laybasic/layAbstractMenu.cc +++ b/src/laybasic/laybasic/layAbstractMenu.cc @@ -20,8 +20,6 @@ */ -#if defined(HAVE_QT) - #include "layAbstractMenu.h" #include "layDispatcher.h" #include "layPlugin.h" @@ -30,17 +28,19 @@ #include "gtf.h" #include "gsi.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#if defined(HAVE_QT) +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +#endif #include @@ -245,12 +245,14 @@ AbstractMenuItem::set_action (Action *a, bool copy_properties) a->keep (); +#if defined(HAVE_QT) if (copy_properties && mp_action->qaction () && a->qaction ()) { a->qaction ()->setIcon (mp_action->qaction ()->icon ()); a->qaction ()->setToolTip (mp_action->qaction ()->toolTip ()); a->qaction ()->setShortcut (mp_action->qaction ()->shortcut ()); a->qaction ()->setIconText (mp_action->qaction ()->iconText ()); } +#endif bool enabled = mp_action.get () ? mp_action->is_enabled () : true; bool visible = mp_action.get () ? mp_action->is_visible () : true; @@ -261,9 +263,11 @@ AbstractMenuItem::set_action (Action *a, bool copy_properties) mp_action->set_dispatcher (mp_dispatcher); mp_action->set_object_name (m_basename); +#if defined(HAVE_QT) if (mp_action->menu ()) { mp_action->menu ()->setObjectName (tl::to_qstring (m_basename)); } +#endif } void @@ -289,30 +293,8 @@ AbstractMenuItem::set_remove_on_empty () static std::set *sp_actionHandles = 0; -static void -configure_action_from_title (Action *ah, const std::string &s) -{ - std::string title; - std::string shortcut; - std::string res; - std::string tool_tip; - - parse_menu_title (s, title, shortcut, res, tool_tip); - - ah->qaction ()->setText (tl::to_qstring (title)); - - if (! tool_tip.empty ()) { - ah->qaction ()->setToolTip (tl::to_qstring (tool_tip)); - } - - if (! res.empty ()) { - ah->qaction ()->setIcon (QIcon (tl::to_qstring (res))); - } - - if (! shortcut.empty ()) { - ah->set_default_shortcut (shortcut); - } -} +#if defined(HAVE_QT) +namespace { /** * @brief A specialization that provides a way to catch ambiguous key shortcuts @@ -370,6 +352,8 @@ private: size_t m_id; }; +} + static size_t id_from_action (QAction *action) { @@ -377,9 +361,13 @@ id_from_action (QAction *action) return ao ? ao->id () : 0; } -Action::Action () - : mp_menu (0), +#endif + +Action::Action () : +#if defined(HAVE_QT) + mp_menu (0), mp_action (new ActionObject (0)), +#endif mp_dispatcher (0), m_owned (true), m_visible (true), @@ -391,11 +379,14 @@ Action::Action () } sp_actionHandles->insert (this); +#if defined(HAVE_QT) // catch the destroyed signal to tell if the QAction object is deleted. connect (mp_action, SIGNAL (destroyed (QObject *)), this, SLOT (destroyed (QObject *))); connect (mp_action, SIGNAL (triggered ()), this, SLOT (qaction_triggered ())); +#endif } +#if defined(HAVE_QT) Action::Action (QAction *action, bool owned) : mp_menu (0), mp_action (action), @@ -433,10 +424,13 @@ Action::Action (QMenu *menu, bool owned) connect (mp_menu, SIGNAL (destroyed (QObject *)), this, SLOT (destroyed (QObject *))); connect (mp_action, SIGNAL (triggered ()), this, SLOT (qaction_triggered ())); } +#endif -Action::Action (const std::string &title) - : mp_menu (0), +Action::Action (const std::string &title) : +#if defined(HAVE_QT) + mp_menu (0), mp_action (new QAction (0)), +#endif mp_dispatcher (0), m_owned (true), m_visible (true), @@ -448,11 +442,20 @@ Action::Action (const std::string &title) } sp_actionHandles->insert (this); - configure_action_from_title (this, title); +#if !defined(HAVE_QT) + m_checked = false; + m_checkable = false; + m_enabled = true; + m_separator = false; +#endif + configure_from_title (title); + +#if defined(HAVE_QT) // catch the destroyed signal to tell if the QAction object is deleted. connect (mp_action, SIGNAL (destroyed (QObject *)), this, SLOT (destroyed (QObject *))); connect (mp_action, SIGNAL (triggered ()), this, SLOT (qaction_triggered ())); +#endif } Action::~Action () @@ -465,6 +468,7 @@ Action::~Action () } } +#if defined(HAVE_QT) if (mp_menu) { if (m_owned) { delete mp_menu; @@ -479,19 +483,55 @@ Action::~Action () } mp_action = 0; } +#endif } void Action::set_dispatcher (Dispatcher *dispatcher) { if (mp_dispatcher != dispatcher) { +#if defined(HAVE_QT) if (mp_action && m_owned) { mp_action->setParent (dispatcher ? dispatcher->menu_parent_widget () : 0); } +#endif mp_dispatcher = dispatcher; } } +void +Action::configure_from_title (const std::string &s) +{ + std::string title; + std::string shortcut; + std::string res; + std::string tool_tip; + + parse_menu_title (s, title, shortcut, res, tool_tip); + +#if defined(HAVE_QT) + qaction ()->setText (tl::to_qstring (title)); + + if (! tool_tip.empty ()) { + qaction ()->setToolTip (tl::to_qstring (tool_tip)); + } + + if (! res.empty ()) { + qaction ()->setIcon (QIcon (tl::to_qstring (res))); + } + + if (! shortcut.empty ()) { + set_default_shortcut (shortcut); + } +#else + m_title = title; + m_default_shortcut = shortcut; + m_tooltip = tool_tip; + m_icon = res; +#endif +} + +#if defined(HAVE_QT) void Action::qaction_triggered () { @@ -499,13 +539,18 @@ Action::qaction_triggered () triggered (); END_PROTECTED } +#endif void Action::trigger () { +#if defined(HAVE_QT) if (qaction ()) { qaction ()->trigger (); } +#else + triggered (); +#endif } void @@ -514,6 +559,7 @@ Action::triggered () // .. no action yet, the reimplementation must provide some .. } +#if defined(HAVE_QT) QAction * Action::qaction () const { @@ -538,16 +584,19 @@ Action::destroyed (QObject *obj) } m_owned = false; } +#endif void Action::set_visible (bool v) { if (m_visible != v) { m_visible = v; +#if defined(HAVE_QT) if (mp_action) { mp_action->setVisible (is_effective_visible ()); mp_action->setShortcut (get_key_sequence ()); } +#endif } } @@ -556,10 +605,12 @@ Action::set_hidden (bool h) { if (m_hidden != h) { m_hidden = h; +#if defined(HAVE_QT) if (mp_action) { mp_action->setVisible (is_effective_visible ()); mp_action->setShortcut (get_key_sequence ()); } +#endif } } @@ -586,10 +637,12 @@ Action::set_default_shortcut (const std::string &sc) { if (m_default_shortcut != sc) { m_default_shortcut = sc; +#if defined(HAVE_QT) m_default_key_sequence = QKeySequence (tl::to_qstring (sc)); if (mp_action) { mp_action->setShortcut (get_key_sequence ()); } +#endif } } @@ -599,25 +652,36 @@ Action::set_shortcut (const std::string &sc) if (m_shortcut != sc) { m_shortcut = sc; m_no_key_sequence = (sc == Action::no_shortcut ()); +#if defined(HAVE_QT) m_key_sequence = m_no_key_sequence ? QKeySequence () : QKeySequence (tl::to_qstring (m_shortcut)); if (mp_action) { mp_action->setShortcut (get_key_sequence ()); } +#endif } } std::string Action::get_default_shortcut () const { +#if defined(HAVE_QT) return tl::to_string (m_default_key_sequence.toString ()); +#else + return m_default_shortcut; +#endif } std::string Action::get_shortcut () const { +#if defined(HAVE_QT) return m_no_key_sequence ? Action::no_shortcut () : tl::to_string (m_key_sequence.toString ()); +#else + return m_no_key_sequence ? Action::no_shortcut () : m_shortcut; +#endif } +#if defined(HAVE_QT) QKeySequence Action::get_key_sequence () const { @@ -647,6 +711,7 @@ Action::get_key_sequence_for (const std::string &sc) const return QKeySequence::fromString (tl::to_qstring (sc)); } } +#endif const std::string & Action::no_shortcut () @@ -658,100 +723,168 @@ Action::no_shortcut () void Action::set_title (const std::string &t) { +#if defined(HAVE_QT) if (qaction ()) { qaction ()->setText (tl::to_qstring (t)); } +#else + m_title = t; +#endif } std::string Action::get_title () const { +#if defined(HAVE_QT) if (qaction ()) { return tl::to_string (qaction ()->text ()); } else { return std::string (); } +#else + return m_title; +#endif } std::string Action::get_effective_shortcut () const { +#if defined(HAVE_QT) return tl::to_string (get_key_sequence ().toString ()); +#else + if (m_hidden || m_no_key_sequence) { + // A hidden menu item does not have a key sequence too. + return std::string (); + } else if (m_shortcut.empty ()) { + return m_default_shortcut; + } else { + return m_shortcut; + } +#endif } std::string Action::get_effective_shortcut_for (const std::string &sc) const { +#if defined(HAVE_QT) return tl::to_string (get_key_sequence_for (sc).toString ()); +#else + if (m_hidden) { + // A hidden menu item does not have a key sequence too. + return std::string (); + } else if (sc.empty ()) { + return m_default_shortcut; + } else if (sc == Action::no_shortcut ()) { + return std::string (); + } else { + return sc; + } +#endif } void Action::add_to_exclusive_group (lay::AbstractMenu *menu, const std::string &group_name) { +// NOTE: this feature does not work without Qt +#if defined(HAVE_QT) if (qaction ()) { menu->make_exclusive_group (group_name)->addAction (qaction ()); } +#endif } bool Action::is_checkable () const { +#if defined(HAVE_QT) return qaction () && qaction ()->isCheckable (); +#else + return m_checkable; +#endif } bool Action::is_checked () const { +#if defined(HAVE_QT) return qaction () && qaction ()->isChecked (); +#else + return m_checked; +#endif } bool Action::is_enabled () const { +#if defined(HAVE_QT) return qaction () && qaction ()->isEnabled (); +#else + return m_enabled; +#endif } bool Action::is_separator () const { +#if defined(HAVE_QT) return qaction () && qaction ()->isSeparator (); +#else + return m_separator; +#endif } void Action::set_enabled (bool b) { +#if defined(HAVE_QT) if (qaction ()) { qaction ()->setEnabled (b); } +#else + m_enabled = b; +#endif } void Action::set_checked (bool c) { +#if defined(HAVE_QT) if (qaction ()) { qaction ()->setChecked (c); } +#else + m_checked = c; +#endif } void Action::set_checkable (bool c) { +#if defined(HAVE_QT) if (qaction ()) { qaction ()->setCheckable (c); } +#else + m_checkable = c; +#endif } void Action::set_separator (bool s) { +#if defined(HAVE_QT) if (qaction ()) { qaction ()->setSeparator (s); } +#else + m_separator = s; +#endif } void Action::set_icon (const std::string &filename) { +#if defined(HAVE_QT) if (qaction ()) { if (filename.empty ()) { qaction ()->setIcon (QIcon ()); @@ -759,21 +892,29 @@ Action::set_icon (const std::string &filename) qaction ()->setIcon (QIcon (tl::to_qstring (filename))); } } +#else + m_icon = filename; +#endif } std::string Action::get_tool_tip () const { +#if defined(HAVE_QT) if (qaction ()) { return tl::to_string (qaction ()->toolTip ()); } else { return std::string (); } +#else + return m_tooltip; +#endif } void Action::set_tool_tip (const std::string &text) { +#if defined(HAVE_QT) if (qaction ()) { if (text.empty ()) { qaction ()->setToolTip (QString ()); @@ -781,21 +922,29 @@ Action::set_tool_tip (const std::string &text) qaction ()->setToolTip (tl::to_qstring (text)); } } +#else + m_tooltip = text; +#endif } std::string Action::get_icon_text () const { +#if defined(HAVE_QT) if (qaction ()) { return tl::to_string (qaction ()->iconText ()); } else { return std::string (); } +#else + return m_icontext; +#endif } void Action::set_icon_text (const std::string &icon_text) { +#if defined(HAVE_QT) if (qaction ()) { if (icon_text.empty ()) { qaction ()->setIconText (QString ()); @@ -803,14 +952,19 @@ Action::set_icon_text (const std::string &icon_text) qaction ()->setIconText (tl::to_qstring (icon_text)); } } +#else + m_icontext = icon_text; +#endif } void Action::set_object_name (const std::string &name) { +#if defined(HAVE_QT) if (qaction ()) { qaction ()->setObjectName (tl::to_qstring (name)); } +#endif } // --------------------------------------------------------------- @@ -895,6 +1049,7 @@ AbstractMenu::~AbstractMenu () // .. nothing yet .. } +#if defined(HAVE_QT) QActionGroup * AbstractMenu::make_exclusive_group (const std::string &name) { @@ -1195,6 +1350,7 @@ AbstractMenu::menu (const std::string &path) return 0; } } +#endif bool AbstractMenu::is_valid (const std::string &path) const @@ -1645,7 +1801,9 @@ void AbstractMenu::emit_changed () { m_config_actions_valid = false; +#if defined(HAVE_QT) emit changed (); +#endif } std::vector AbstractMenu::configure_actions (const std::string &name) @@ -1703,5 +1861,3 @@ AbstractMenu::get_shortcuts (const std::string &root, std::map -#include -#include -#include -#include +#if defined(HAVE_QT) +# include +# include +# include +# include +# include +#endif #include #include @@ -43,10 +43,12 @@ #include "tlObject.h" #include "laybasicCommon.h" +#if defined(HAVE_QT) class QFrame; class QMenuBar; class QToolBar; class QMenu; +#endif namespace lay { @@ -85,12 +87,16 @@ LAYBASIC_PUBLIC std::string pack_menu_items_hidden (const std::vectormenu (); } +#endif void set_has_submenu (); @@ -575,11 +606,15 @@ private: * QMenu's created so far (except the detached menus), clear the QMenuBar, recreate the QMenu objects (note, that the * addresses will change this way!) and refill the QToolBar and QMenuBar. */ -class LAYBASIC_PUBLIC AbstractMenu - : public QObject, +class LAYBASIC_PUBLIC AbstractMenu : +#if defined(HAVE_QT) + public QObject, +#endif public gsi::ObjectBase { +#if defined(HAVE_QT) Q_OBJECT +#endif public: /** @@ -592,6 +627,7 @@ public: */ ~AbstractMenu (); +#if defined(HAVE_QT) /** * @brief Rebuild the QMenu's and refill the QMenuBar object */ @@ -616,6 +652,29 @@ public: */ QMenu *menu (const std::string &path); + /** + * @brief Get the detached menu + * + * This will return a QMenu pointer to a detached menu that is created + * with a "@.." top level entry. In any case, a valid QMenu object is returned + * which never changes, even if the menu hierarchy is rebuilt. The QMenu returned + * may be empty. + * + * @param name The name of the detached menu, without the "@" + * @return a valid QMenu object + */ + QMenu *detached_menu (const std::string &name); + + /** + * @brief Creates a new exclusive action group + * + * If a group with that name already exists, this method does nothing. + * + * @return The QActionGroup object of that group + */ + QActionGroup *make_exclusive_group (const std::string &name); +#endif + /** * @brief Get the Action object for a given item * @@ -752,28 +811,6 @@ public: */ std::vector configure_actions (const std::string &name); - /** - * @brief Get the detached menu - * - * This will return a QMenu pointer to a detached menu that is created - * with a "@.." top level entry. In any case, a valid QMenu object is returned - * which never changes, even if the menu hierarchy is rebuilt. The QMenu returned - * may be empty. - * - * @param name The name of the detached menu, without the "@" - * @return a valid QMenu object - */ - QMenu *detached_menu (const std::string &name); - - /** - * @brief Creates a new exclusive action group - * - * If a group with that name already exists, this method does nothing. - * - * @return The QActionGroup object of that group - */ - QActionGroup *make_exclusive_group (const std::string &name); - /** * @brief Gets the keyboard shortcuts * @param with_defaults Returns the default shortcuts if true. Otherwise returns the effective shortcut. @@ -794,11 +831,13 @@ public: return m_root; } +#if defined(HAVE_QT) signals: /** * @brief this signal is emitted whenever something changes on the menu */ void changed (); +#endif private: friend class Action; @@ -806,8 +845,10 @@ private: std::vector::iterator> > find_item (tl::Extractor &extr); const AbstractMenuItem *find_item_exact (const std::string &path) const; AbstractMenuItem *find_item_exact (const std::string &path); +#if defined(HAVE_QT) void build (QMenu *menu, std::list &items); void build (QToolBar *tbar, std::list &items); +#endif void collect_group (std::vector &grp, const std::string &name, const AbstractMenuItem &item) const; void collect_configure_actions (std::vector &ca, AbstractMenuItem &item); void emit_changed (); @@ -815,8 +856,10 @@ private: Dispatcher *mp_dispatcher; AbstractMenuItem m_root; +#if defined(HAVE_QT) tl::stable_vector m_helper_menu_items; std::map m_action_groups; +#endif std::map > m_config_action_by_name; bool m_config_actions_valid; }; @@ -824,5 +867,3 @@ private: } #endif - -#endif // defined(HAVE_QT) diff --git a/src/laybasic/laybasic/layDispatcher.cc b/src/laybasic/laybasic/layDispatcher.cc index 740393388..9ae342912 100644 --- a/src/laybasic/laybasic/layDispatcher.cc +++ b/src/laybasic/laybasic/layDispatcher.cc @@ -22,6 +22,7 @@ #include "layDispatcher.h" +#include "layAbstractMenu.h" #include "tlXMLParser.h" #include "tlXMLWriter.h" @@ -69,25 +70,23 @@ Dispatcher::~Dispatcher () void Dispatcher::set_menu_parent_widget (QWidget *menu_parent_widget) { mp_menu_parent_widget = menu_parent_widget; - if (mp_menu_parent_widget) { - mp_menu.reset (new lay::AbstractMenu (this)); - } else { - mp_menu.reset (0); - } } #endif +void Dispatcher::make_menu () +{ + mp_menu.reset (new lay::AbstractMenu (this)); +} + bool Dispatcher::configure (const std::string &name, const std::string &value) { -#if defined(HAVE_QT) if (mp_menu) { std::vector ca = mp_menu->configure_actions (name); for (std::vector::const_iterator a = ca.begin (); a != ca.end (); ++a) { (*a)->configure (value); } } -#endif if (mp_delegate) { return mp_delegate->configure (name, value); diff --git a/src/laybasic/laybasic/layDispatcher.h b/src/laybasic/laybasic/layDispatcher.h index 05acda580..70b86d0c7 100644 --- a/src/laybasic/laybasic/layDispatcher.h +++ b/src/laybasic/laybasic/layDispatcher.h @@ -222,6 +222,20 @@ public: */ bool has_ui () { return menu_parent_widget () != 0; } +#else + /** + * @brief Returns true, if the dispatcher supplies a user interface + */ + bool has_ui () { return false; } +#endif + + /** + * @brief Creates the menu object + * + * This method will only have an effect on the root dispatcher. + */ + void make_menu (); + /** * @brief Gets the AbstractMenu object * @@ -231,14 +245,6 @@ public: { return (dispatcher () == this) ? mp_menu.get () : dispatcher ()->menu (); } -#else - - /** - * @brief Returns true, if the dispatcher supplies a user interface - */ - bool has_ui () { return false; } - -#endif protected: // capture the configuration events so we can change the value of the configuration actions @@ -249,8 +255,8 @@ private: Dispatcher (const Dispatcher &); Dispatcher &operator= (const Dispatcher &); -#if defined(HAVE_QT) std::unique_ptr mp_menu; +#if defined(HAVE_QT) QWidget *mp_menu_parent_widget; #endif DispatcherDelegate *mp_delegate; diff --git a/src/laybasic/laybasic/layLayoutViewBase.cc b/src/laybasic/laybasic/layLayoutViewBase.cc index 9d26f4cce..5e4230c88 100644 --- a/src/laybasic/laybasic/layLayoutViewBase.cc +++ b/src/laybasic/laybasic/layLayoutViewBase.cc @@ -408,6 +408,43 @@ LayoutViewBase::init (db::Manager *mgr) create_plugins (); } +void +LayoutViewBase::finish () +{ + // if we're the root dispatcher initialize the menu and build the context menus. No other menus are built so far. + if (dispatcher () == this) { +#if defined(HAVE_QT) + set_menu_parent_widget (widget ()); + init_menu (); + menu ()->build (0, 0); +#else + init_menu (); +#endif + } +} + +void +LayoutViewBase::init_menu () +{ + make_menu (); + + // make the plugins create their menu items + for (tl::Registrar::iterator cls = tl::Registrar::begin (); cls != tl::Registrar::end (); ++cls) { + // TODO: get rid of the const_cast hack + const_cast (&*cls)->init_menu (dispatcher ()); + } + + // if not in editable mode, hide all entries from "edit_mode" group and show all from the "view_mode" group and vice versa + std::vector edit_mode_grp = menu ()->group ("edit_mode"); + for (std::vector::const_iterator g = edit_mode_grp.begin (); g != edit_mode_grp.end (); ++g) { + menu ()->action (*g)->set_visible (is_editable ()); + } + std::vector view_mode_grp = menu ()->group ("view_mode"); + for (std::vector::const_iterator g = view_mode_grp.begin (); g != view_mode_grp.end (); ++g) { + menu ()->action (*g)->set_visible (! is_editable ()); + } +} + void LayoutViewBase::shutdown () { diff --git a/src/laybasic/laybasic/layLayoutViewBase.h b/src/laybasic/laybasic/layLayoutViewBase.h index 149000372..99456135a 100644 --- a/src/laybasic/laybasic/layLayoutViewBase.h +++ b/src/laybasic/laybasic/layLayoutViewBase.h @@ -2861,6 +2861,8 @@ protected: void free_resources (); void shutdown (); + void finish (); + void init_menu (); virtual tl::Color default_background_color (); virtual void do_set_background_color (tl::Color color, tl::Color contrast); diff --git a/src/laybasic/laybasic/layPlugin.cc b/src/laybasic/laybasic/layPlugin.cc index 819d2c131..3a28117d5 100644 --- a/src/laybasic/laybasic/layPlugin.cc +++ b/src/laybasic/laybasic/layPlugin.cc @@ -96,8 +96,6 @@ PluginDeclaration::menu_symbols () return symbols; } -#if defined(HAVE_QT) - namespace { class GenericMenuAction @@ -173,7 +171,9 @@ PluginDeclaration::init_menu (lay::Dispatcher *dispatcher) } mp_editable_mode_action.reset (new Action (title)); +#if defined(HAVE_QT) gtf::action_connect (mp_editable_mode_action->qaction (), SIGNAL (triggered ()), this, SLOT (toggle_editable_enabled ())); +#endif mp_editable_mode_action->set_checkable (true); mp_editable_mode_action->set_checked (m_editable_enabled); @@ -281,18 +281,14 @@ PluginDeclaration::remove_menu_items (Dispatcher *dispatcher) m_menu_actions.clear (); } -#endif - void PluginDeclaration::set_editable_enabled (bool f) { if (f != m_editable_enabled) { m_editable_enabled = f; -#if defined(HAVE_QT) if (mp_editable_mode_action.get ()) { mp_editable_mode_action->set_checked (f); } -#endif editable_enabled_changed_event (); } } @@ -443,17 +439,6 @@ Plugin::dispatcher () return dynamic_cast (p); } -Dispatcher * -Plugin::dispatcher_maybe_null () -{ - Plugin *p = this; - while (p->mp_parent) { - p = p->mp_parent; - } - - return dynamic_cast (p); -} - void Plugin::do_config_setup (Plugin *target) { diff --git a/src/laybasic/laybasic/layPlugin.h b/src/laybasic/laybasic/layPlugin.h index 84244ce2c..f6bd14a15 100644 --- a/src/laybasic/laybasic/layPlugin.h +++ b/src/laybasic/laybasic/layPlugin.h @@ -30,9 +30,7 @@ #include "tlClassRegistry.h" #include "tlDeferredExecution.h" #include "gsiObject.h" -#if defined(HAVE_QT) -# include "layAbstractMenu.h" -#endif +#include "layAbstractMenu.h" #include #include @@ -393,7 +391,6 @@ public: */ static std::vector menu_symbols (); -#if defined(HAVE_QT) /** * @brief Creates the menu resources for this plugin * @@ -407,7 +404,6 @@ public: * @brief Removes the menu resources associated with this plugin */ void remove_menu_items (lay::Dispatcher *dispatcher); -#endif /** * @brief Enables this editable part of the plugin @@ -462,11 +458,9 @@ private slots: private: int m_id; -#if defined(HAVE_QT) tl::weak_ptr mp_editable_mode_action; tl::weak_ptr mp_mouse_mode_action; tl::weak_collection m_menu_actions; -#endif bool m_editable_enabled; }; @@ -687,13 +681,6 @@ public: */ Dispatcher *dispatcher (); - /** - * @brief Gets the dispatcher (the top level end of the plugin chain) - * This version may return null, if the plugin is instantiated without a - * root. - */ - Dispatcher *dispatcher_maybe_null (); - /** * @brief Menu command handler * diff --git a/src/laybasic/laybasic/laybasic.pro b/src/laybasic/laybasic/laybasic.pro index 915729a04..fdd56f679 100644 --- a/src/laybasic/laybasic/laybasic.pro +++ b/src/laybasic/laybasic/laybasic.pro @@ -16,7 +16,6 @@ DEFINES += MAKE_LAYBASIC_LIBRARY layPluginConfigPage.cc \ layPropertiesDialog.cc \ layProperties.cc \ - layAbstractMenu.cc \ layDragDropData.cc \ layCursor.cc \ @@ -25,7 +24,6 @@ DEFINES += MAKE_LAYBASIC_LIBRARY layPluginConfigPage.h \ layPropertiesDialog.h \ layProperties.h \ - layAbstractMenu.h \ layDragDropData.h \ layCursor.h \ @@ -35,9 +33,11 @@ SOURCES += \ gsiDeclLayLayers.cc \ gsiDeclLayLayoutViewBase.cc \ gsiDeclLayMarker.cc \ + gsiDeclLayMenu.cc \ gsiDeclLayPlugin.cc \ gsiDeclLayTlAdded.cc \ gsiDeclLayRdbAdded.cc \ + layAbstractMenu.cc \ layLayoutViewConfig.cc \ laybasicForceLink.cc \ layAnnotationShapes.cc \ @@ -90,6 +90,7 @@ SOURCES += \ HEADERS += \ laybasicConfig.h \ laybasicForceLink.h \ + layAbstractMenu.h \ layAnnotationShapes.h \ layBitmap.h \ layBitmapRenderer.h \ diff --git a/src/laybasic/unit_tests/layAbstractMenuTests.cc b/src/laybasic/unit_tests/layAbstractMenuTests.cc index 3f6c67ada..f1e7b165f 100644 --- a/src/laybasic/unit_tests/layAbstractMenuTests.cc +++ b/src/laybasic/unit_tests/layAbstractMenuTests.cc @@ -20,8 +20,6 @@ */ -#if defined(HAVE_QT) - #include "layAbstractMenu.h" #include "tlUnitTest.h" @@ -185,5 +183,3 @@ TEST(3_ActionReferences) // the action is deleted because it's owned by the menu EXPECT_EQ (action.get () == 0, true); } - -#endif diff --git a/src/layui/layui/layui.pro b/src/layui/layui/layui.pro index 086291e28..cd2eec833 100644 --- a/src/layui/layui/layui.pro +++ b/src/layui/layui/layui.pro @@ -80,7 +80,6 @@ RESOURCES = \ SOURCES = \ gsiDeclLayDialogs.cc \ - gsiDeclLayMenu.cc \ gsiDeclLayNetlistBrowserDialog.cc \ gsiDeclLayStream.cc \ layuiForceLink.cc \ diff --git a/src/layview/layview/layLayoutView_noqt.cc b/src/layview/layview/layLayoutView_noqt.cc index 9b80e44ee..524fcae39 100644 --- a/src/layview/layview/layLayoutView_noqt.cc +++ b/src/layview/layview/layLayoutView_noqt.cc @@ -31,12 +31,14 @@ LayoutView::LayoutView (db::Manager *mgr, bool editable, lay::Plugin *plugin_par : LayoutViewBase (this, mgr, editable, plugin_parent, options) { config_setup (); + finish (); } LayoutView::LayoutView (lay::LayoutView *source, db::Manager *mgr, bool editable, lay::Plugin *plugin_parent, unsigned int options) : LayoutViewBase (this, source, mgr, editable, plugin_parent, options) { config_setup (); + finish (); } // NOTE: this methods needs to be called "frequently" diff --git a/src/layview/layview/layLayoutView_qt.cc b/src/layview/layview/layLayoutView_qt.cc index 3fe5653e7..739e9508d 100644 --- a/src/layview/layview/layLayoutView_qt.cc +++ b/src/layview/layview/layLayoutView_qt.cc @@ -241,26 +241,6 @@ LayoutView::event_filter (QObject *obj, QEvent *event, bool &taken) return false; } -void -LayoutView::init_menu () -{ - // make the plugins create their menu items - for (tl::Registrar::iterator cls = tl::Registrar::begin (); cls != tl::Registrar::end (); ++cls) { - // TODO: get rid of the const_cast hack - const_cast (&*cls)->init_menu (dispatcher ()); - } - - // if not in editable mode, hide all entries from "edit_mode" group and show all from the "view_mode" group and vice versa - std::vector edit_mode_grp = menu ()->group ("edit_mode"); - for (std::vector::const_iterator g = edit_mode_grp.begin (); g != edit_mode_grp.end (); ++g) { - menu ()->action (*g)->set_visible (is_editable ()); - } - std::vector view_mode_grp = menu ()->group ("view_mode"); - for (std::vector::const_iterator g = view_mode_grp.begin (); g != view_mode_grp.end (); ++g) { - menu ()->action (*g)->set_visible (! is_editable ()); - } -} - void LayoutView::init_ui (QWidget *parent, const char *name) { @@ -406,6 +386,7 @@ LayoutView::init_ui (QWidget *parent, const char *name) } config_setup (); + finish (); } LayoutView::~LayoutView () diff --git a/src/layview/layview/layLayoutView_qt.h b/src/layview/layview/layLayoutView_qt.h index ec045860a..5c59dec57 100644 --- a/src/layview/layview/layLayoutView_qt.h +++ b/src/layview/layview/layLayoutView_qt.h @@ -741,7 +741,6 @@ private: QSize size_hint () const; void init_ui (QWidget *parent, const char *name); - void init_menu (); void do_setup_editor_options_pages (); protected: