actually display keybinds in the menu
This commit is contained in:
parent
6f1498d65c
commit
4ace4c2398
4 changed files with 61 additions and 18 deletions
|
@ -10,7 +10,7 @@ bool KeyHandler::eventFilter(QObject *obj, QEvent *event) {
|
|||
auto *key = dynamic_cast<QKeyEvent *>(event);
|
||||
|
||||
return std::any_of(listeners.cbegin(), listeners.cend(),
|
||||
[key](const auto *listener) {
|
||||
[key](auto* listener) {
|
||||
return listener->testAndInvoke(key);
|
||||
});
|
||||
} else {
|
||||
|
|
|
@ -7,14 +7,55 @@
|
|||
|
||||
|
||||
#include <QObject>
|
||||
#include <QAbstractItemModel>
|
||||
#include <iostream>
|
||||
#include "AbstractKeyListener.h"
|
||||
|
||||
class KeyHandler : public QObject {
|
||||
Q_OBJECT
|
||||
|
||||
class KeyHandler : public QAbstractTableModel {
|
||||
public:
|
||||
explicit KeyHandler(QObject *parent = nullptr) : QAbstractTableModel{parent} {};
|
||||
|
||||
void addListener(AbstractKeyListener *listener) { listeners.push_back(listener); }
|
||||
|
||||
[[nodiscard]] int rowCount(const QModelIndex &parent = {}) const override {
|
||||
return listeners.size();
|
||||
}
|
||||
|
||||
[[nodiscard]] int columnCount(const QModelIndex &parent = {}) const override {
|
||||
return 2;
|
||||
}
|
||||
|
||||
[[nodiscard]] QVariant data(const QModelIndex &index, int role) const override {
|
||||
if (!index.isValid() || role != Qt::DisplayRole)
|
||||
return {};
|
||||
|
||||
auto *l = listeners[index.row()];
|
||||
switch (index.column()) {
|
||||
case 0:
|
||||
return QString::fromStdString(l->getKeyText());
|
||||
case 1:
|
||||
return QString::fromStdString(l->getDescription());
|
||||
default:
|
||||
return QVariant{};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
[[nodiscard]] QVariant headerData(int section, Qt::Orientation orientation,
|
||||
int role) const override {
|
||||
if (orientation != Qt::Horizontal || role != Qt::DisplayRole)
|
||||
return QVariant{};
|
||||
|
||||
switch (section) {
|
||||
case 0:
|
||||
return "Key";
|
||||
case 1:
|
||||
return "Description";
|
||||
default:
|
||||
return QVariant{};
|
||||
}
|
||||
}
|
||||
|
||||
protected:
|
||||
bool eventFilter(QObject *obj, QEvent *event) override;
|
||||
|
||||
|
|
|
@ -29,18 +29,20 @@ MainWindow::MainWindow(QWidget *parent)
|
|||
swayTreeKeyHandler = new KeyHandler();
|
||||
swayTreeKeyHandler->addListener(new HelpKeyListener(ui->help_page));
|
||||
|
||||
closeHelpKeyHandler = new KeyHandler();
|
||||
closeHelpKeyHandler = new KeyHandler(ui->tree_page);
|
||||
closeHelpKeyHandler->addListener(new CloseHelpKeyListener(ui->tree_page));
|
||||
|
||||
ui->stackedWidget->setCurrentIndex(0);
|
||||
ui->stackedWidget->setCurrentWidget(ui->tree_page);
|
||||
ui->treeView->installEventFilter(swayTreeKeyHandler);
|
||||
ui->listView->installEventFilter(closeHelpKeyHandler);
|
||||
|
||||
ui->tableView->setModel(swayTreeKeyHandler);
|
||||
ui->tableView->resizeColumnsToContents();
|
||||
ui->tableView->installEventFilter(closeHelpKeyHandler);
|
||||
}
|
||||
|
||||
MainWindow::~MainWindow() {
|
||||
delete ui;
|
||||
delete model;
|
||||
// delete modelUpdateTimer;
|
||||
delete swayTreeKeyHandler;
|
||||
delete closeHelpKeyHandler;
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@
|
|||
<item row="0" column="0">
|
||||
<widget class="QStackedWidget" name="stackedWidget">
|
||||
<property name="currentIndex">
|
||||
<number>0</number>
|
||||
<number>1</number>
|
||||
</property>
|
||||
<widget class="QWidget" name="tree_page">
|
||||
<property name="sizePolicy">
|
||||
|
@ -59,15 +59,15 @@
|
|||
</sizepolicy>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="0" column="0">
|
||||
<widget class="QListView" name="listView">
|
||||
<property name="font">
|
||||
<font>
|
||||
<pointsize>20</pointsize>
|
||||
</font>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QTableView" name="tableView">
|
||||
<property name="font">
|
||||
<font>
|
||||
<pointsize>20</pointsize>
|
||||
</font>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
|
|
Loading…
Reference in a new issue