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);
|
auto *key = dynamic_cast<QKeyEvent *>(event);
|
||||||
|
|
||||||
return std::any_of(listeners.cbegin(), listeners.cend(),
|
return std::any_of(listeners.cbegin(), listeners.cend(),
|
||||||
[key](const auto *listener) {
|
[key](auto* listener) {
|
||||||
return listener->testAndInvoke(key);
|
return listener->testAndInvoke(key);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -7,14 +7,55 @@
|
||||||
|
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
|
#include <QAbstractItemModel>
|
||||||
|
#include <iostream>
|
||||||
#include "AbstractKeyListener.h"
|
#include "AbstractKeyListener.h"
|
||||||
|
|
||||||
class KeyHandler : public QObject {
|
class KeyHandler : public QAbstractTableModel {
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
explicit KeyHandler(QObject *parent = nullptr) : QAbstractTableModel{parent} {};
|
||||||
|
|
||||||
void addListener(AbstractKeyListener *listener) { listeners.push_back(listener); }
|
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:
|
protected:
|
||||||
bool eventFilter(QObject *obj, QEvent *event) override;
|
bool eventFilter(QObject *obj, QEvent *event) override;
|
||||||
|
|
||||||
|
|
|
@ -29,18 +29,20 @@ MainWindow::MainWindow(QWidget *parent)
|
||||||
swayTreeKeyHandler = new KeyHandler();
|
swayTreeKeyHandler = new KeyHandler();
|
||||||
swayTreeKeyHandler->addListener(new HelpKeyListener(ui->help_page));
|
swayTreeKeyHandler->addListener(new HelpKeyListener(ui->help_page));
|
||||||
|
|
||||||
closeHelpKeyHandler = new KeyHandler();
|
closeHelpKeyHandler = new KeyHandler(ui->tree_page);
|
||||||
closeHelpKeyHandler->addListener(new CloseHelpKeyListener(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->treeView->installEventFilter(swayTreeKeyHandler);
|
||||||
ui->listView->installEventFilter(closeHelpKeyHandler);
|
|
||||||
|
ui->tableView->setModel(swayTreeKeyHandler);
|
||||||
|
ui->tableView->resizeColumnsToContents();
|
||||||
|
ui->tableView->installEventFilter(closeHelpKeyHandler);
|
||||||
}
|
}
|
||||||
|
|
||||||
MainWindow::~MainWindow() {
|
MainWindow::~MainWindow() {
|
||||||
delete ui;
|
delete ui;
|
||||||
delete model;
|
delete model;
|
||||||
// delete modelUpdateTimer;
|
|
||||||
delete swayTreeKeyHandler;
|
delete swayTreeKeyHandler;
|
||||||
delete closeHelpKeyHandler;
|
delete closeHelpKeyHandler;
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,7 +30,7 @@
|
||||||
<item row="0" column="0">
|
<item row="0" column="0">
|
||||||
<widget class="QStackedWidget" name="stackedWidget">
|
<widget class="QStackedWidget" name="stackedWidget">
|
||||||
<property name="currentIndex">
|
<property name="currentIndex">
|
||||||
<number>0</number>
|
<number>1</number>
|
||||||
</property>
|
</property>
|
||||||
<widget class="QWidget" name="tree_page">
|
<widget class="QWidget" name="tree_page">
|
||||||
<property name="sizePolicy">
|
<property name="sizePolicy">
|
||||||
|
@ -60,7 +60,7 @@
|
||||||
</property>
|
</property>
|
||||||
<layout class="QGridLayout" name="gridLayout">
|
<layout class="QGridLayout" name="gridLayout">
|
||||||
<item row="0" column="0">
|
<item row="0" column="0">
|
||||||
<widget class="QListView" name="listView">
|
<widget class="QTableView" name="tableView">
|
||||||
<property name="font">
|
<property name="font">
|
||||||
<font>
|
<font>
|
||||||
<pointsize>20</pointsize>
|
<pointsize>20</pointsize>
|
||||||
|
|
Loading…
Reference in a new issue