mirror of https://github.com/debauchee/barrier.git
Enable use of keyboard to modify screens
This commit is contained in:
parent
d4382b9b80
commit
4ee6a54d41
|
@ -0,0 +1 @@
|
|||
Made it possible to use keyboard instead of mouse to modify screen layout.
|
|
@ -71,7 +71,7 @@ Qt::ItemFlags ScreenSetupModel::flags(const QModelIndex& index) const
|
|||
if (!screen(index).isNull())
|
||||
return Qt::ItemIsEnabled | Qt::ItemIsDragEnabled | Qt::ItemIsSelectable | Qt::ItemIsDropEnabled;
|
||||
|
||||
return Qt::ItemIsDropEnabled;
|
||||
return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsDropEnabled;
|
||||
}
|
||||
|
||||
Qt::DropActions ScreenSetupModel::supportedDropActions() const
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -44,6 +44,7 @@ class ScreenSetupView : public QTableView
|
|||
|
||||
protected:
|
||||
void mouseDoubleClickEvent(QMouseEvent*) override;
|
||||
void keyPressEvent(QKeyEvent*) override;
|
||||
void setTableSize();
|
||||
void resizeEvent(QResizeEvent*) override;
|
||||
void dragEnterEvent(QDragEnterEvent* event) override;
|
||||
|
@ -51,6 +52,9 @@ class ScreenSetupView : public QTableView
|
|||
void startDrag(Qt::DropActions supportedActions) override;
|
||||
QStyleOptionViewItem viewOptions() const override;
|
||||
void scrollTo(const QModelIndex&, ScrollHint) override {}
|
||||
private:
|
||||
void enter(const QModelIndex&);
|
||||
void remove(const QModelIndex&);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue