aboutsummaryrefslogtreecommitdiffstats
path: root/src/gui/src/ScreenSetupView.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui/src/ScreenSetupView.cpp')
-rw-r--r--src/gui/src/ScreenSetupView.cpp83
1 files changed, 74 insertions, 9 deletions
diff --git a/src/gui/src/ScreenSetupView.cpp b/src/gui/src/ScreenSetupView.cpp
index 46e7099..5459f23 100644
--- a/src/gui/src/ScreenSetupView.cpp
+++ b/src/gui/src/ScreenSetupView.cpp
@@ -2,11 +2,11 @@
* barrier -- mouse and keyboard sharing utility
* Copyright (C) 2012-2016 Symless Ltd.
* Copyright (C) 2008 Volker Lanz (vl@fidra.de)
- *
+ *
* This package is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* found in the file LICENSE that should have accompanied this file.
- *
+ *
* This package is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
@@ -30,6 +30,7 @@ ScreenSetupView::ScreenSetupView(QWidget* parent) :
setDropIndicatorShown(true);
setDragDropMode(DragDrop);
setSelectionMode(SingleSelection);
+ setTabKeyNavigation(false);
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
@@ -65,18 +66,83 @@ void ScreenSetupView::resizeEvent(QResizeEvent* event)
event->ignore();
}
+void ScreenSetupView::enter(const QModelIndex& index)
+{
+ if (!index.isValid())
+ return;
+ Screen& screen = model()->screen(index);
+ if (screen.isNull())
+ screen = Screen(tr("Unnamed"));
+ ScreenSettingsDialog dlg(this, &screen);
+ dlg.exec();
+}
+
+void ScreenSetupView::remove(const QModelIndex& index)
+{
+ if (!index.isValid())
+ return;
+ Screen& screen = model()->screen(index);
+ if (!screen.isNull()) {
+ screen = Screen();
+ emit dataChanged(index, index);
+ }
+}
+
+void ScreenSetupView::keyPressEvent(QKeyEvent* event)
+{
+ if (event->key() == Qt::Key_Return || event->key() == Qt::Key_Delete)
+ {
+ QModelIndexList indexes = selectedIndexes();
+ if (indexes.count() == 1 && indexes[0].isValid())
+ {
+ if (event->key() == Qt::Key_Return)
+ enter(indexes[0]);
+ else if (event->key() == Qt::Key_Delete)
+ remove(indexes[0]);
+ }
+ // Do not let base handle the event, at least not for return key because it
+ // results in next esc/return key in the opened Screen Settings dialog not
+ // only closing that but also the parent Server Configuration dialog.
+ }
+ else if ((event->modifiers() & Qt::ControlModifier)
+ && (event->key() == Qt::Key_Left || event->key() == Qt::Key_Right
+ || event->key() == Qt::Key_Up || event->key() == Qt::Key_Down))
+ {
+ QModelIndexList indexes = selectedIndexes();
+ if (indexes.count() == 1 && indexes[0].isValid())
+ {
+ const QModelIndex& fromIndex = indexes[0];
+ QModelIndex toIndex;
+
+ if (event->key() == Qt::Key_Left)
+ toIndex = fromIndex.sibling(fromIndex.row(), fromIndex.column() - 1);
+ else if (event->key() == Qt::Key_Right)
+ toIndex = fromIndex.sibling(fromIndex.row(), fromIndex.column() + 1);
+ else if (event->key() == Qt::Key_Up)
+ toIndex = fromIndex.sibling(fromIndex.row() - 1, fromIndex.column());
+ else if (event->key() == Qt::Key_Down)
+ toIndex = fromIndex.sibling(fromIndex.row() + 1, fromIndex.column());
+
+ if (toIndex.isValid() && fromIndex != toIndex)
+ std::swap(model()->screen(fromIndex), model()->screen(toIndex));
+ }
+ // In this case let base also handle the event, because it will proceed moving
+ // the selection to target, update the view according to model changes etc.
+ QTableView::keyPressEvent(event);
+ }
+ else
+ {
+ QTableView::keyPressEvent(event);
+ }
+}
+
void ScreenSetupView::mouseDoubleClickEvent(QMouseEvent* event)
{
if (event->buttons() & Qt::LeftButton)
{
int col = columnAt(event->pos().x());
int row = rowAt(event->pos().y());
-
- if (!model()->screen(col, row).isNull())
- {
- ScreenSettingsDialog dlg(this, &model()->screen(col, row));
- dlg.exec();
- }
+ enter(model()->createIndex(row, col));
}
else
event->ignore();
@@ -159,4 +225,3 @@ QStyleOptionViewItem ScreenSetupView::viewOptions() const
option.textElideMode = Qt::ElideMiddle;
return option;
}
-