67 lines
1.7 KiB
C++
67 lines
1.7 KiB
C++
//
|
|
// Created by grimmauld on 07.03.24.
|
|
//
|
|
|
|
#ifndef SWAYMUX_KEYHANDLER_H
|
|
#define SWAYMUX_KEYHANDLER_H
|
|
|
|
|
|
#include <QObject>
|
|
#include <QAbstractItemModel>
|
|
#include <iostream>
|
|
#include "AbstractKeyListener.h"
|
|
|
|
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;
|
|
|
|
std::vector<AbstractKeyListener *> listeners;
|
|
};
|
|
|
|
|
|
#endif //SWAYMUX_KEYHANDLER_H
|