WIP: adding tab key to move tool (calls 'move by' menu), enhancing 'move_to' and 'move_by' dialogs.

This commit is contained in:
Matthias Koefferlein 2025-09-07 23:54:40 +02:00
parent aba1f87b0d
commit 7fd01a64f6
9 changed files with 134 additions and 87 deletions

View File

@ -98,9 +98,7 @@ BEGIN_PROTECTED
// The Return key on a non-modal page commits the values and gives back the focus
// to the view
apply (dispatcher ());
if (view ()->canvas ()->widget ()) {
view ()->canvas ()->widget ()->setFocus (Qt::TabFocusReason);
}
view ()->set_focus ();
event->accept ();
} else {
QWidget::keyPressEvent (event);

View File

@ -691,6 +691,12 @@ LayoutViewBase::message (const std::string & /*s*/, int /*timeout*/)
// .. nothing yet ..
}
void
LayoutViewBase::set_focus ()
{
// .. nothing yet ..
}
bool
LayoutViewBase::is_dirty () const
{

View File

@ -295,6 +295,11 @@ public:
*/
virtual void message (const std::string &s = "", int timeout = 10);
/**
* @brief Sets the keyboard focus to the view
*/
virtual void set_focus ();
/**
* @brief The "dirty" flag indicates that one of the layout has been modified
*

View File

@ -39,6 +39,7 @@ MoveService::MoveService (lay::LayoutViewBase *view)
lay::Plugin (view),
m_dragging (false),
m_dragging_transient (false),
m_active (false),
mp_editables (view),
mp_view (view),
m_global_grid (0.001)
@ -51,10 +52,17 @@ MoveService::~MoveService ()
drag_cancel ();
}
void
void
MoveService::activated ()
{
m_active = true;
}
void
MoveService::deactivated ()
{
m_shift = db::DPoint ();
m_active = false;
mp_view->clear_transient_selection ();
drag_cancel ();
}
@ -87,8 +95,15 @@ MoveService::configure (const std::string &name, const std::string &value)
}
bool
MoveService::key_event (unsigned int key, unsigned int /*buttons*/)
MoveService::key_event (unsigned int key, unsigned int buttons)
{
if (m_active && key == Qt::Key_Tab && buttons == 0) {
if (dispatcher ()) {
dispatcher ()->menu_activated ("cm_sel_move");
}
return true;
}
double dx = 0.0, dy = 0.0;
if (int (key) == lay::KeyDown) {
dy = -1.0;

View File

@ -61,12 +61,14 @@ private:
virtual bool wheel_event (int delta, bool horizontal, const db::DPoint &p, unsigned int buttons, bool prio);
virtual bool key_event (unsigned int key, unsigned int buttons);
virtual void drag_cancel ();
virtual void activated ();
virtual void deactivated ();
bool handle_click (const db::DPoint &p, unsigned int buttons, bool drag_transient, db::Transaction *transaction);
bool m_dragging;
bool m_dragging_transient;
bool m_active;
lay::Editables *mp_editables;
lay::LayoutViewBase *mp_view;
double m_global_grid;

View File

@ -6,7 +6,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>233</width>
<width>240</width>
<height>168</height>
</rect>
</property>
@ -17,7 +17,7 @@
<property name="spacing">
<number>6</number>
</property>
<property name="margin">
<property name="margin" stdset="0">
<number>9</number>
</property>
<item>
@ -26,12 +26,16 @@
<string>Displacement</string>
</property>
<layout class="QGridLayout">
<property name="margin">
<number>9</number>
</property>
<property name="spacing">
<number>6</number>
</property>
<item row="1" column="2">
<widget class="QLabel" name="label_5">
<property name="text">
<string>µm</string>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QLabel" name="label_4">
<property name="sizePolicy">
@ -45,13 +49,6 @@
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QLabel" name="label_5">
<property name="text">
<string>µm</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
@ -69,13 +66,6 @@
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>x </string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="disp_x_le">
<property name="sizePolicy">
@ -86,6 +76,13 @@
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>x </string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
@ -117,26 +114,9 @@
<tabstops>
<tabstop>disp_x_le</tabstop>
<tabstop>disp_y_le</tabstop>
<tabstop>buttonBox</tabstop>
</tabstops>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>MoveOptionsDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
@ -153,5 +133,53 @@
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>MoveOptionsDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>119</x>
<y>146</y>
</hint>
<hint type="destinationlabel">
<x>119</x>
<y>83</y>
</hint>
</hints>
</connection>
<connection>
<sender>disp_x_le</sender>
<signal>returnPressed()</signal>
<receiver>MoveOptionsDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>119</x>
<y>53</y>
</hint>
<hint type="destinationlabel">
<x>119</x>
<y>83</y>
</hint>
</hints>
</connection>
<connection>
<sender>disp_y_le</sender>
<signal>returnPressed()</signal>
<receiver>MoveOptionsDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>119</x>
<y>84</y>
</hint>
<hint type="destinationlabel">
<x>119</x>
<y>83</y>
</hint>
</hints>
</connection>
</connections>
</ui>

View File

@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>396</width>
<height>345</height>
<height>357</height>
</rect>
</property>
<property name="windowTitle">
@ -354,6 +354,13 @@
</layout>
</widget>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
<item>
<widget class="QFrame" name="frame">
<property name="frameShape">
@ -369,44 +376,14 @@
<property name="margin" stdset="0">
<number>0</number>
</property>
<item>
<spacer>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>209</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="pushButton">
<property name="text">
<string>Ok</string>
</property>
<property name="default">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_2">
<property name="text">
<string>Cancel</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<tabstops>
<tabstop>pushButton</tabstop>
<tabstop>pushButton_2</tabstop>
<tabstop>x_le</tabstop>
<tabstop>y_le</tabstop>
<tabstop>lt</tabstop>
<tabstop>ct</tabstop>
<tabstop>rt</tabstop>
@ -422,34 +399,34 @@
</resources>
<connections>
<connection>
<sender>pushButton</sender>
<signal>clicked()</signal>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>MoveToOptionsDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>237</x>
<y>203</y>
<x>197</x>
<y>323</y>
</hint>
<hint type="destinationlabel">
<x>147</x>
<y>81</y>
<x>197</x>
<y>175</y>
</hint>
</hints>
</connection>
<connection>
<sender>pushButton_2</sender>
<signal>clicked()</signal>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>MoveToOptionsDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>325</x>
<y>202</y>
<x>197</x>
<y>323</y>
</hint>
<hint type="destinationlabel">
<x>325</x>
<y>57</y>
<x>197</x>
<y>175</y>
</hint>
</hints>
</connection>

View File

@ -1577,12 +1577,21 @@ LayoutView::message (const std::string &s, int timeout)
}
}
void
LayoutView::set_focus ()
{
if (canvas () && canvas ()->widget ()) {
canvas ()->widget ()->setFocus (Qt::TabFocusReason);
}
}
void
LayoutView::mode (int m)
{
if (mode () != m) {
LayoutViewBase::mode (m);
activate_editor_option_pages ();
set_focus ();
}
}
@ -1599,10 +1608,12 @@ void
LayoutView::switch_mode (int m)
{
if (mode () != m) {
mode (m);
LayoutViewBase::mode (m);
activate_editor_option_pages ();
if (mp_widget) {
mp_widget->emit_mode_change (m);
}
set_focus ();
}
}

View File

@ -183,6 +183,11 @@ public:
*/
void message (const std::string &s = "", int timeout = 10);
/**
* @brief Sets the keyboard focus to the view
*/
virtual void set_focus ();
/**
* @brief Select a certain mode (by index)
*/