mirror of
https://github.com/KLayout/klayout.git
synced 2026-09-01 10:27:53 +02:00
Refactoring (GSI base class for EditorOptionsPage), preparations for 'focus_page' feature
This commit is contained in:
@@ -34,13 +34,13 @@ namespace lay
|
||||
// EditorOptionsPage implementation
|
||||
|
||||
EditorOptionsPage::EditorOptionsPage (lay::LayoutViewBase *view, lay::Dispatcher *dispatcher)
|
||||
: QWidget (0), mp_owner (0), m_active (true), mp_plugin_declaration (0), mp_dispatcher (dispatcher), mp_view (view)
|
||||
: QWidget (0), mp_owner (0), m_active (true), m_focus_page (false), mp_plugin_declaration (0), mp_dispatcher (dispatcher), mp_view (view)
|
||||
{
|
||||
attach_events ();
|
||||
}
|
||||
|
||||
EditorOptionsPage::EditorOptionsPage ()
|
||||
: QWidget (0), mp_owner (0), m_active (true), mp_plugin_declaration (0), mp_dispatcher (0), mp_view (0)
|
||||
: QWidget (0), mp_owner (0), m_active (true), m_focus_page (false), mp_plugin_declaration (0), mp_dispatcher (0), mp_view (0)
|
||||
{
|
||||
// .. nothing here -> call init to set view and dispatcher
|
||||
}
|
||||
@@ -58,6 +58,14 @@ EditorOptionsPage::~EditorOptionsPage ()
|
||||
set_owner (0);
|
||||
}
|
||||
|
||||
void
|
||||
EditorOptionsPage::make_current ()
|
||||
{
|
||||
if (mp_owner && m_active) {
|
||||
mp_owner->make_page_current (this);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
EditorOptionsPage::attach_events ()
|
||||
{
|
||||
|
||||
@@ -60,10 +60,14 @@ public:
|
||||
virtual void setup (lay::Dispatcher * /*root*/) { }
|
||||
virtual void commit_recent (lay::Dispatcher * /*root*/) { }
|
||||
|
||||
bool is_focus_page () const { return m_focus_page; }
|
||||
void set_focus_page (bool f) { m_focus_page = f; }
|
||||
bool active () const { return m_active; }
|
||||
void activate (bool active);
|
||||
void set_owner (EditorOptionsPages *owner);
|
||||
|
||||
void make_current ();
|
||||
|
||||
const lay::PluginDeclaration *plugin_declaration () const { return mp_plugin_declaration; }
|
||||
void set_plugin_declaration (const lay::PluginDeclaration *pd) { mp_plugin_declaration = pd; }
|
||||
|
||||
@@ -92,6 +96,7 @@ protected:
|
||||
private:
|
||||
EditorOptionsPages *mp_owner;
|
||||
bool m_active;
|
||||
bool m_focus_page;
|
||||
const lay::PluginDeclaration *mp_plugin_declaration;
|
||||
lay::Dispatcher *mp_dispatcher;
|
||||
lay::LayoutViewBase *mp_view;
|
||||
|
||||
@@ -120,7 +120,18 @@ EditorOptionsPages::unregister_page (lay::EditorOptionsPage *page)
|
||||
update (0);
|
||||
}
|
||||
|
||||
void
|
||||
void
|
||||
EditorOptionsPages::make_page_current (lay::EditorOptionsPage *page)
|
||||
{
|
||||
for (int i = 0; i < mp_pages->count (); ++i) {
|
||||
if (mp_pages->widget (i) == page) {
|
||||
mp_pages->setCurrentIndex (i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
EditorOptionsPages::activate_page (lay::EditorOptionsPage *page)
|
||||
{
|
||||
try {
|
||||
|
||||
@@ -60,6 +60,7 @@ public:
|
||||
void activate_page (lay::EditorOptionsPage *page);
|
||||
void activate (const lay::Plugin *plugin);
|
||||
void focusInEvent (QFocusEvent *event);
|
||||
void make_page_current (lay::EditorOptionsPage *page);
|
||||
|
||||
const std::vector <lay::EditorOptionsPage *> &pages () const
|
||||
{
|
||||
|
||||
@@ -21,6 +21,8 @@
|
||||
*/
|
||||
|
||||
#include "layEditorServiceBase.h"
|
||||
#include "layEditorOptionsPage.h"
|
||||
#include "layEditorOptionsPages.h"
|
||||
#include "layViewport.h"
|
||||
#include "layLayoutViewBase.h"
|
||||
#include "laybasicConfig.h"
|
||||
@@ -212,7 +214,8 @@ EditorServiceBase::EditorServiceBase (LayoutViewBase *view)
|
||||
lay::Plugin (view),
|
||||
mp_view (view),
|
||||
m_cursor_enabled (true),
|
||||
m_has_tracking_position (false)
|
||||
m_has_tracking_position (false),
|
||||
m_active (false)
|
||||
{
|
||||
// .. nothing yet ..
|
||||
}
|
||||
@@ -328,6 +331,51 @@ void
|
||||
EditorServiceBase::deactivated ()
|
||||
{
|
||||
clear_mouse_cursors ();
|
||||
m_active = false;
|
||||
}
|
||||
|
||||
void
|
||||
EditorServiceBase::activated ()
|
||||
{
|
||||
m_active = true;
|
||||
}
|
||||
|
||||
#if defined(HAVE_QT)
|
||||
std::vector<lay::EditorOptionsPage *>
|
||||
EditorServiceBase::editor_options_pages ()
|
||||
{
|
||||
lay::EditorOptionsPages *eo_pages = mp_view->editor_options_pages ();
|
||||
if (!eo_pages) {
|
||||
return std::vector<lay::EditorOptionsPage *> ();
|
||||
} else {
|
||||
std::vector<lay::EditorOptionsPage *> pages;
|
||||
for (auto p = eo_pages->pages ().begin (); p != eo_pages->pages ().end (); ++p) {
|
||||
if ((*p)->plugin_declaration () == plugin_declaration ()) {
|
||||
pages.push_back (*p);
|
||||
}
|
||||
}
|
||||
return pages;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
bool
|
||||
EditorServiceBase::key_event (unsigned int key, unsigned int buttons)
|
||||
{
|
||||
#if defined(HAVE_QT)
|
||||
if (is_active () && key == Qt::Key_Tab && buttons == 0) {
|
||||
auto pages = editor_options_pages ();
|
||||
for (auto p = pages.begin (); p != pages.end (); ++p) {
|
||||
if ((*p)->is_focus_page ()) {
|
||||
(*p)->make_current ();
|
||||
(*p)->setFocus (Qt::TabFocusReason);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
@@ -74,6 +74,14 @@ public:
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Gets a value indicating whether the plugin is active
|
||||
*/
|
||||
bool is_active () const
|
||||
{
|
||||
return m_active;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Adds a mouse cursor to the given point
|
||||
*/
|
||||
@@ -170,18 +178,12 @@ public:
|
||||
/**
|
||||
* @brief Called when the plugin is activated
|
||||
*/
|
||||
virtual void activated ()
|
||||
{
|
||||
// .. this implementation does nothing ..
|
||||
}
|
||||
virtual void activated ();
|
||||
|
||||
/**
|
||||
* @brief Key event handler
|
||||
*/
|
||||
virtual bool key_event (unsigned int /*key*/, unsigned int /*buttons*/)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
virtual bool key_event (unsigned int /*key*/, unsigned int /*buttons*/);
|
||||
|
||||
/**
|
||||
* @brief Mouse press event handler
|
||||
@@ -263,6 +265,13 @@ public:
|
||||
// The default implementation does nothing
|
||||
}
|
||||
|
||||
#if defined(HAVE_QT)
|
||||
/**
|
||||
* @brief Gets the editor options pages associated with this plugin
|
||||
*/
|
||||
std::vector<lay::EditorOptionsPage *> editor_options_pages ();
|
||||
#endif
|
||||
|
||||
private:
|
||||
// The marker representing the mouse cursor
|
||||
lay::LayoutViewBase *mp_view;
|
||||
@@ -271,6 +280,7 @@ private:
|
||||
bool m_cursor_enabled;
|
||||
bool m_has_tracking_position;
|
||||
db::DPoint m_tracking_position;
|
||||
bool m_active;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user