WIP, e.g. avoiding sticky selection when aborting 'move' by chosing a different mode

This commit is contained in:
Matthias Koefferlein 2026-01-12 17:05:38 +01:00
parent c738cf7255
commit 0b9a0c3af1
8 changed files with 76 additions and 26 deletions

View File

@ -31,6 +31,14 @@
namespace lay
{
// ------------------------------------------------------------------
// EditorOptionsPageCollection implementation
EditorOptionsPageCollection::EditorOptionsPageCollection ()
{
// .. nothing yet ..
}
// ------------------------------------------------------------------
// EditorOptionsPage implementation
@ -115,6 +123,11 @@ EditorOptionsPage::activate (bool active)
if (mp_owner) {
mp_owner->activate_page (this);
}
if (m_active) {
activated ();
} else {
deactivated ();
}
}
}
@ -191,6 +204,12 @@ EditorOptionsPageWidget::set_focus ()
QWidget::focusNextPrevChild (true);
}
void
EditorOptionsPageWidget::set_visible (bool visible)
{
setVisible (visible);
}
#endif
}

View File

@ -53,6 +53,7 @@ class EditorOptionsPageWidget;
class LAYBASIC_PUBLIC EditorOptionsPageCollection
{
public:
EditorOptionsPageCollection ();
virtual ~EditorOptionsPageCollection () { }
virtual void unregister_page (EditorOptionsPage *page) = 0;
@ -64,6 +65,7 @@ public:
virtual bool exec_modal (EditorOptionsPage *page) = 0;
virtual std::vector<lay::EditorOptionsPage *> editor_options_pages (const lay::PluginDeclaration *plugin) = 0;
virtual std::vector<lay::EditorOptionsPage *> editor_options_pages () = 0;
virtual lay::EditorOptionsPage *page_with_name (const std::string &name) = 0;
};
/**
@ -79,11 +81,13 @@ public:
virtual std::string title () const = 0;
virtual int order () const = 0;
virtual const char *name () const { return 0; }
virtual void apply (lay::Dispatcher * /*root*/) { }
virtual void setup (lay::Dispatcher * /*root*/) { }
virtual void commit_recent (lay::Dispatcher * /*root*/) { }
virtual void config_recent_for_layer (lay::Dispatcher * /*root*/, const db::LayerProperties & /*lp*/, int /*cv_index*/) { }
virtual void set_focus () { }
virtual void set_visible (bool /*visible*/) { }
virtual EditorOptionsPageWidget *widget () { return 0; }
bool is_focus_page () const { return m_focus_page; }
@ -123,6 +127,8 @@ public:
protected:
virtual void active_cellview_changed () { }
virtual void technology_changed (const std::string & /*tech*/) { }
virtual void activated () { }
virtual void deactivated () { }
private:
EditorOptionsPageCollection *mp_owner;
@ -153,6 +159,7 @@ public:
virtual ~EditorOptionsPageWidget ();
virtual void set_focus ();
virtual void set_visible (bool visible);
virtual EditorOptionsPageWidget *widget () { return this; }
protected slots:

View File

@ -360,17 +360,6 @@ public:
// the base implementation does nothing
}
/**
* @brief Shows or hides a toolbox widget with the given name
*
* Initially toolbox widgets are invisible. They are made visible
* by using this method.
*/
virtual void show_toolbox_widget (const std::string & /*name*/, bool /*visible*/)
{
// the base implementation does nothing
}
/**
* @brief Adds an editor options page as a toolbox widget
*/

View File

@ -37,6 +37,8 @@
namespace lay
{
const char *move_editor_options_name = "move-editor-options";
// -------------------------------------------------------------
// MoveService implementation
@ -62,7 +64,11 @@ MoveService::deactivated ()
EditorServiceBase::deactivated ();
m_shift = db::DPoint ();
mp_editables->clear_transient_selection ();
drag_cancel ();
if (m_dragging) {
// we don't just call drag_cancel() - this way avoids pending selections with the wrong coordinates
mp_view->edit_cancel ();
}
}
bool
@ -127,6 +133,15 @@ MoveService::key_event (unsigned int key, unsigned int buttons)
}
}
void
MoveService::show_toolbox (bool visible)
{
lay::EditorOptionsPage *op = mp_view->editor_options_pages () ? mp_view->editor_options_pages ()->page_with_name (move_editor_options_name) : 0;
if (op) {
op->set_visible (visible);
}
}
int
MoveService::focus_page_open ()
{
@ -320,6 +335,8 @@ MoveService::handle_click (const db::DPoint &p, unsigned int buttons, bool drag_
m_dragging = true;
m_dragging_transient = drag_transient;
show_toolbox (true);
ui ()->grab_mouse (this, false);
m_shift = db::DPoint ();
@ -332,7 +349,9 @@ MoveService::handle_click (const db::DPoint &p, unsigned int buttons, bool drag_
m_dragging = false;
show_toolbox (false);
ui ()->ungrab_mouse (this);
mp_editables->end_move (p, ac_from_buttons (buttons), mp_transaction.release ());
if (m_dragging_transient) {
@ -350,6 +369,7 @@ MoveService::drag_cancel ()
{
m_shift = db::DPoint ();
if (m_dragging) {
show_toolbox (false);
ui ()->ungrab_mouse (this);
m_dragging = false;
}
@ -394,8 +414,7 @@ public:
mp_layout->addWidget (mp_y_le);
mp_layout->addStretch (1);
// @@@
hide ();
set_toolbox_widget (true);
}
@ -404,11 +423,21 @@ public:
return "Move Options";
}
virtual const char *name () const
{
return move_editor_options_name;
}
virtual int order () const
{
return 0;
}
virtual void deactivated ()
{
hide ();
}
private:
QHBoxLayout *mp_layout;
QLineEdit *mp_x_le, *mp_y_le;
@ -436,6 +465,7 @@ public:
virtual void get_editor_options_pages (std::vector<lay::EditorOptionsPage *> &pages, lay::LayoutViewBase *view, lay::Dispatcher *dispatcher) const
{
pages.push_back (new MoveToolboxPage (view, dispatcher));
pages.back ()->set_plugin_declaration (this);
}
#endif
};

View File

@ -57,6 +57,7 @@ private:
virtual void drag_cancel ();
virtual void deactivated ();
int focus_page_open ();
void show_toolbox (bool visible);
bool handle_click (const db::DPoint &p, unsigned int buttons, bool drag_transient, db::Transaction *transaction);

View File

@ -49,12 +49,12 @@ EditorOptionsFrame::~EditorOptionsFrame ()
void
EditorOptionsFrame::populate (LayoutViewBase *view)
{
std::vector<lay::EditorOptionsPage *> prop_dialog_pages;
std::vector<lay::EditorOptionsPage *> editor_options_pages;
for (tl::Registrar<lay::PluginDeclaration>::iterator cls = tl::Registrar<lay::PluginDeclaration>::begin (); cls != tl::Registrar<lay::PluginDeclaration>::end (); ++cls) {
cls->get_editor_options_pages (prop_dialog_pages, view, view->dispatcher ());
cls->get_editor_options_pages (editor_options_pages, view, view->dispatcher ());
}
for (std::vector<lay::EditorOptionsPage *>::const_iterator op = prop_dialog_pages.begin (); op != prop_dialog_pages.end (); ++op) {
for (std::vector<lay::EditorOptionsPage *>::const_iterator op = editor_options_pages.begin (); op != editor_options_pages.end (); ++op) {
(*op)->activate (false);
}
@ -62,7 +62,7 @@ EditorOptionsFrame::populate (LayoutViewBase *view)
delete mp_pages;
}
mp_pages = new lay::EditorOptionsPages (this, view, prop_dialog_pages);
mp_pages = new lay::EditorOptionsPages (this, view, editor_options_pages);
layout ()->addWidget (mp_pages);
setFocusProxy (mp_pages);
}

View File

@ -94,12 +94,6 @@ EditorOptionsPages::focusInEvent (QFocusEvent * /*event*/)
}
}
const tl::weak_collection <lay::EditorOptionsPage> &
EditorOptionsPages::pages () const
{
return m_pages;
}
std::vector<lay::EditorOptionsPage *>
EditorOptionsPages::editor_options_pages (const lay::PluginDeclaration *plugin_declaration)
{
@ -185,6 +179,17 @@ EditorOptionsPages::unregister_page (lay::EditorOptionsPage *page)
update (0);
}
lay::EditorOptionsPage *
EditorOptionsPages::page_with_name (const std::string &name)
{
for (auto p = m_pages.begin (); p != m_pages.end (); ++p) {
if (p->name () && name == p->name ()) {
return p.operator-> ();
}
}
return 0;
}
void
EditorOptionsPages::make_page_current (lay::EditorOptionsPage *page)
{

View File

@ -68,8 +68,7 @@ public:
virtual std::vector<lay::EditorOptionsPage *> editor_options_pages (const lay::PluginDeclaration *plugin_declaration);
virtual std::vector<lay::EditorOptionsPage *> editor_options_pages ();
virtual void activate (const lay::Plugin *plugin);
const tl::weak_collection <lay::EditorOptionsPage> &pages () const;
virtual lay::EditorOptionsPage *page_with_name (const std::string &name);
void do_apply (bool modal);