@@ -30,6 +30,7 @@ ScreenSetupView::ScreenSetupView(QWidget* parent) :
3030 setDropIndicatorShown (true );
3131 setDragDropMode (DragDrop);
3232 setSelectionMode (SingleSelection);
33+ setTabKeyNavigation (false );
3334
3435 setHorizontalScrollBarPolicy (Qt::ScrollBarAlwaysOff);
3536 setVerticalScrollBarPolicy (Qt::ScrollBarAlwaysOff);
@@ -65,18 +66,83 @@ void ScreenSetupView::resizeEvent(QResizeEvent* event)
6566 event->ignore ();
6667}
6768
69+ void ScreenSetupView::enter (const QModelIndex& index)
70+ {
71+ if (!index.isValid ())
72+ return ;
73+ Screen& screen = model ()->screen (index);
74+ if (screen.isNull ())
75+ screen = Screen (tr (" Unnamed" ));
76+ ScreenSettingsDialog dlg (this , &screen);
77+ dlg.exec ();
78+ }
79+
80+ void ScreenSetupView::remove (const QModelIndex& index)
81+ {
82+ if (!index.isValid ())
83+ return ;
84+ Screen& screen = model ()->screen (index);
85+ if (!screen.isNull ()) {
86+ screen = Screen ();
87+ emit dataChanged (index, index);
88+ }
89+ }
90+
91+ void ScreenSetupView::keyPressEvent (QKeyEvent* event)
92+ {
93+ if (event->key () == Qt::Key_Return || event->key () == Qt::Key_Delete)
94+ {
95+ QModelIndexList indexes = selectedIndexes ();
96+ if (indexes.count () == 1 && indexes[0 ].isValid ())
97+ {
98+ if (event->key () == Qt::Key_Return)
99+ enter (indexes[0 ]);
100+ else if (event->key () == Qt::Key_Delete)
101+ remove (indexes[0 ]);
102+ }
103+ // Do not let base handle the event, at least not for return key because it
104+ // results in next esc/return key in the opened Screen Settings dialog not
105+ // only closing that but also the parent Server Configuration dialog.
106+ }
107+ else if ((event->modifiers () & Qt::ControlModifier)
108+ && (event->key () == Qt::Key_Left || event->key () == Qt::Key_Right
109+ || event->key () == Qt::Key_Up || event->key () == Qt::Key_Down))
110+ {
111+ QModelIndexList indexes = selectedIndexes ();
112+ if (indexes.count () == 1 && indexes[0 ].isValid ())
113+ {
114+ const QModelIndex& fromIndex = indexes[0 ];
115+ QModelIndex toIndex;
116+
117+ if (event->key () == Qt::Key_Left)
118+ toIndex = fromIndex.sibling (fromIndex.row (), fromIndex.column () - 1 );
119+ else if (event->key () == Qt::Key_Right)
120+ toIndex = fromIndex.sibling (fromIndex.row (), fromIndex.column () + 1 );
121+ else if (event->key () == Qt::Key_Up)
122+ toIndex = fromIndex.sibling (fromIndex.row () - 1 , fromIndex.column ());
123+ else if (event->key () == Qt::Key_Down)
124+ toIndex = fromIndex.sibling (fromIndex.row () + 1 , fromIndex.column ());
125+
126+ if (toIndex.isValid () && fromIndex != toIndex)
127+ std::swap (model ()->screen (fromIndex), model ()->screen (toIndex));
128+ }
129+ // In this case let base also handle the event, because it will proceed moving
130+ // the selection to target, update the view according to model changes etc.
131+ QTableView::keyPressEvent (event);
132+ }
133+ else
134+ {
135+ QTableView::keyPressEvent (event);
136+ }
137+ }
138+
68139void ScreenSetupView::mouseDoubleClickEvent (QMouseEvent* event)
69140{
70141 if (event->buttons () & Qt::LeftButton)
71142 {
72143 int col = columnAt (event->pos ().x ());
73144 int row = rowAt (event->pos ().y ());
74-
75- if (!model ()->screen (col, row).isNull ())
76- {
77- ScreenSettingsDialog dlg (this , &model ()->screen (col, row));
78- dlg.exec ();
79- }
145+ enter (model ()->createIndex (row, col));
80146 }
81147 else
82148 event->ignore ();
0 commit comments