Add help menu list view, add toggle to get to help menu
This commit is contained in:
parent
e773033f3b
commit
6f1498d65c
@ -30,6 +30,11 @@ set(PROJECT_SOURCES
|
|||||||
tree/AbstractTreeModel.h
|
tree/AbstractTreeModel.h
|
||||||
tree/SwayTreeModel.h
|
tree/SwayTreeModel.h
|
||||||
tree/SwayTreeModel.cpp
|
tree/SwayTreeModel.cpp
|
||||||
|
Keys/KeyHandler.h
|
||||||
|
Keys/KeyHandler.cpp
|
||||||
|
Keys/AbstractKeyListener.h
|
||||||
|
Keys/HelpKeyListener.h
|
||||||
|
Keys/CloseHelpKeyListener.h
|
||||||
)
|
)
|
||||||
|
|
||||||
if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
|
if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
|
||||||
|
32
Keys/AbstractKeyListener.h
Normal file
32
Keys/AbstractKeyListener.h
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
//
|
||||||
|
// Created by grimmauld on 07.03.24.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef SWAYMUX_ABSTRACTKEYLISTENER_H
|
||||||
|
#define SWAYMUX_ABSTRACTKEYLISTENER_H
|
||||||
|
|
||||||
|
|
||||||
|
#include <set>
|
||||||
|
#include <Qt>
|
||||||
|
#include <QKeyEvent>
|
||||||
|
|
||||||
|
class AbstractKeyListener {
|
||||||
|
public:
|
||||||
|
virtual void handleKeyEvent(const QKeyEvent *keyEvent) const = 0;
|
||||||
|
|
||||||
|
bool testAndInvoke(const QKeyEvent *keyEvent) const {
|
||||||
|
if (canAcceptKey(keyEvent->key())) {
|
||||||
|
handleKeyEvent(keyEvent);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual std::string getDescription() = 0;
|
||||||
|
|
||||||
|
virtual std::string getKeyText() = 0;
|
||||||
|
|
||||||
|
[[nodiscard]] virtual bool canAcceptKey(int key) const = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif //SWAYMUX_ABSTRACTKEYLISTENER_H
|
38
Keys/CloseHelpKeyListener.h
Normal file
38
Keys/CloseHelpKeyListener.h
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
//
|
||||||
|
// Created by grimmauld on 07.03.24.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef SWAYMUX_CLOSEHELPKEYLISTENER_H
|
||||||
|
#define SWAYMUX_CLOSEHELPKEYLISTENER_H
|
||||||
|
|
||||||
|
#include <QStackedWidget>
|
||||||
|
#include "AbstractKeyListener.h"
|
||||||
|
|
||||||
|
class CloseHelpKeyListener : public AbstractKeyListener {
|
||||||
|
public:
|
||||||
|
explicit CloseHelpKeyListener(QWidget *pWidget) : stackPage(pWidget) {}
|
||||||
|
|
||||||
|
void handleKeyEvent(const QKeyEvent *keyEvent) const override {
|
||||||
|
auto* stackWidget = qobject_cast<QStackedWidget*>(stackPage->parent());
|
||||||
|
if (stackWidget != nullptr) {
|
||||||
|
stackWidget->setCurrentWidget(stackPage);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string getDescription() override {
|
||||||
|
return "Close help menu";
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string getKeyText() override {
|
||||||
|
return "?, ESC, q";
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] bool canAcceptKey(int key) const override {
|
||||||
|
return key == Qt::Key_Question || key == Qt::Key_Q || key == Qt::Key_Escape;
|
||||||
|
}
|
||||||
|
|
||||||
|
QWidget *stackPage{};
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif //SWAYMUX_CLOSEHELPKEYLISTENER_H
|
37
Keys/HelpKeyListener.h
Normal file
37
Keys/HelpKeyListener.h
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
//
|
||||||
|
// Created by grimmauld on 07.03.24.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef SWAYMUX_HELPKEYLISTENER_H
|
||||||
|
#define SWAYMUX_HELPKEYLISTENER_H
|
||||||
|
|
||||||
|
#include "AbstractKeyListener.h"
|
||||||
|
|
||||||
|
class HelpKeyListener : public AbstractKeyListener {
|
||||||
|
public:
|
||||||
|
explicit HelpKeyListener(QWidget *pWidget) : stackPage(pWidget) {}
|
||||||
|
|
||||||
|
void handleKeyEvent(const QKeyEvent *keyEvent) const override {
|
||||||
|
auto* stackWidget = qobject_cast<QStackedWidget*>(stackPage->parent());
|
||||||
|
if (stackWidget != nullptr) {
|
||||||
|
stackWidget->setCurrentWidget(stackPage);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string getDescription() override {
|
||||||
|
return "View this help menu";
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string getKeyText() override {
|
||||||
|
return "?";
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] bool canAcceptKey(int key) const override {
|
||||||
|
return key == Qt::Key_Question;
|
||||||
|
}
|
||||||
|
|
||||||
|
QWidget *stackPage;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif //SWAYMUX_HELPKEYLISTENER_H
|
19
Keys/KeyHandler.cpp
Normal file
19
Keys/KeyHandler.cpp
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
//
|
||||||
|
// Created by grimmauld on 07.03.24.
|
||||||
|
//
|
||||||
|
|
||||||
|
#include <QKeyEvent>
|
||||||
|
#include "KeyHandler.h"
|
||||||
|
|
||||||
|
bool KeyHandler::eventFilter(QObject *obj, QEvent *event) {
|
||||||
|
if (event->type() == QEvent::KeyPress) {
|
||||||
|
auto *key = dynamic_cast<QKeyEvent *>(event);
|
||||||
|
|
||||||
|
return std::any_of(listeners.cbegin(), listeners.cend(),
|
||||||
|
[key](const auto *listener) {
|
||||||
|
return listener->testAndInvoke(key);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
return QObject::eventFilter(obj, event);
|
||||||
|
}
|
||||||
|
}
|
25
Keys/KeyHandler.h
Normal file
25
Keys/KeyHandler.h
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
//
|
||||||
|
// Created by grimmauld on 07.03.24.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef SWAYMUX_KEYHANDLER_H
|
||||||
|
#define SWAYMUX_KEYHANDLER_H
|
||||||
|
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
#include "AbstractKeyListener.h"
|
||||||
|
|
||||||
|
class KeyHandler : public QObject {
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
void addListener(AbstractKeyListener *listener) { listeners.push_back(listener); }
|
||||||
|
|
||||||
|
protected:
|
||||||
|
bool eventFilter(QObject *obj, QEvent *event) override;
|
||||||
|
|
||||||
|
std::vector<AbstractKeyListener *> listeners;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif //SWAYMUX_KEYHANDLER_H
|
@ -1,19 +1,20 @@
|
|||||||
#include "mainwindow.h"
|
#include "mainwindow.h"
|
||||||
#include "./ui_mainwindow.h"
|
#include "./ui_mainwindow.h"
|
||||||
#include "tree/PsTreeModel.h"
|
|
||||||
#include "tree/SwayTreeModel.h"
|
#include "tree/SwayTreeModel.h"
|
||||||
#include <QScreen>
|
#include "Keys/HelpKeyListener.h"
|
||||||
|
#include "Keys/CloseHelpKeyListener.h"
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
|
|
||||||
MainWindow::MainWindow(QWidget *parent)
|
MainWindow::MainWindow(QWidget *parent)
|
||||||
: QMainWindow(parent), ui(new Ui::MainWindow) {
|
: QMainWindow(parent), ui(new Ui::MainWindow) {
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
|
||||||
model = new SwayTreeModel(ui->treeView);
|
model = new SwayTreeModel(ui->treeView);
|
||||||
modelUpdateTimer = new QTimer(this);
|
// modelUpdateTimer = new QTimer(this);
|
||||||
connect(modelUpdateTimer, &QTimer::timeout, this, QOverload<>::of(&MainWindow::update));
|
// connect(modelUpdateTimer, &QTimer::timeout, this, QOverload<>::of(&MainWindow::update));
|
||||||
modelUpdateTimer->start(1000);
|
// modelUpdateTimer->start(1000);
|
||||||
|
|
||||||
ui->statusbar->showMessage(QString::fromStdString("test test 123"));
|
ui->statusbar->showMessage(QString::fromStdString("test test 123"));
|
||||||
ui->treeView->setModel(model);
|
ui->treeView->setModel(model);
|
||||||
@ -24,15 +25,28 @@ MainWindow::MainWindow(QWidget *parent)
|
|||||||
|
|
||||||
for (int c = 0; c < model->columnCount(); ++c)
|
for (int c = 0; c < model->columnCount(); ++c)
|
||||||
ui->treeView->resizeColumnToContents(c);
|
ui->treeView->resizeColumnToContents(c);
|
||||||
|
|
||||||
|
swayTreeKeyHandler = new KeyHandler();
|
||||||
|
swayTreeKeyHandler->addListener(new HelpKeyListener(ui->help_page));
|
||||||
|
|
||||||
|
closeHelpKeyHandler = new KeyHandler();
|
||||||
|
closeHelpKeyHandler->addListener(new CloseHelpKeyListener(ui->tree_page));
|
||||||
|
|
||||||
|
ui->stackedWidget->setCurrentIndex(0);
|
||||||
|
ui->treeView->installEventFilter(swayTreeKeyHandler);
|
||||||
|
ui->listView->installEventFilter(closeHelpKeyHandler);
|
||||||
}
|
}
|
||||||
|
|
||||||
MainWindow::~MainWindow() {
|
MainWindow::~MainWindow() {
|
||||||
delete ui;
|
delete ui;
|
||||||
delete model;
|
delete model;
|
||||||
delete modelUpdateTimer;
|
// delete modelUpdateTimer;
|
||||||
|
delete swayTreeKeyHandler;
|
||||||
|
delete closeHelpKeyHandler;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::update() {
|
void MainWindow::keyPressEvent(QKeyEvent *event) {
|
||||||
std::cout << ui->treeView->currentIndex().parent().row() << "\n";
|
if (event->key() == Qt::Key_W) {
|
||||||
// model->update();
|
qDebug() << "hi";
|
||||||
|
}
|
||||||
}
|
}
|
@ -4,6 +4,7 @@
|
|||||||
#include <QMainWindow>
|
#include <QMainWindow>
|
||||||
#include "tree/PsTreeModel.h"
|
#include "tree/PsTreeModel.h"
|
||||||
#include "tree/SwayTreeModel.h"
|
#include "tree/SwayTreeModel.h"
|
||||||
|
#include "Keys/KeyHandler.h"
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
@ -19,11 +20,13 @@ public:
|
|||||||
explicit MainWindow(QWidget *parent = nullptr);
|
explicit MainWindow(QWidget *parent = nullptr);
|
||||||
~MainWindow() override;
|
~MainWindow() override;
|
||||||
|
|
||||||
void update() ;
|
void keyPressEvent(QKeyEvent *event) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::MainWindow *ui;
|
Ui::MainWindow *ui;
|
||||||
SwayTreeModel* model;
|
SwayTreeModel* model;
|
||||||
QTimer* modelUpdateTimer;
|
// QTimer* modelUpdateTimer{};
|
||||||
|
KeyHandler* swayTreeKeyHandler;
|
||||||
|
KeyHandler* closeHelpKeyHandler;
|
||||||
};
|
};
|
||||||
#endif // MAINWINDOW_H
|
#endif // MAINWINDOW_H
|
||||||
|
@ -21,16 +21,23 @@
|
|||||||
</property>
|
</property>
|
||||||
<widget class="QWidget" name="centralwidget">
|
<widget class="QWidget" name="centralwidget">
|
||||||
<property name="sizePolicy">
|
<property name="sizePolicy">
|
||||||
<sizepolicy hsizetype="Maximum" vsizetype="Maximum">
|
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
|
||||||
<horstretch>0</horstretch>
|
<horstretch>0</horstretch>
|
||||||
<verstretch>0</verstretch>
|
<verstretch>0</verstretch>
|
||||||
</sizepolicy>
|
</sizepolicy>
|
||||||
</property>
|
</property>
|
||||||
<property name="maximumSize">
|
<layout class="QGridLayout" name="gridLayout">
|
||||||
<size>
|
<item row="0" column="0">
|
||||||
<width>16777215</width>
|
<widget class="QStackedWidget" name="stackedWidget">
|
||||||
<height>16777215</height>
|
<property name="currentIndex">
|
||||||
</size>
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<widget class="QWidget" name="tree_page">
|
||||||
|
<property name="sizePolicy">
|
||||||
|
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QGridLayout" name="gridLayout">
|
<layout class="QGridLayout" name="gridLayout">
|
||||||
<item row="0" column="0">
|
<item row="0" column="0">
|
||||||
@ -44,6 +51,29 @@
|
|||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
|
<widget class="QWidget" name="help_page">
|
||||||
|
<property name="sizePolicy">
|
||||||
|
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</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>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
<widget class="QStatusBar" name="statusbar"/>
|
<widget class="QStatusBar" name="statusbar"/>
|
||||||
</widget>
|
</widget>
|
||||||
<resources/>
|
<resources/>
|
||||||
|
@ -86,7 +86,7 @@ struct SwayRecord {
|
|||||||
|
|
||||||
explicit SwayRecord(const json &rep) :
|
explicit SwayRecord(const json &rep) :
|
||||||
id(rep["id"]),
|
id(rep["id"]),
|
||||||
name(rep["name"]),
|
name(rep["name"].is_null() ? "untitled container" : rep["name"]),
|
||||||
type(NodeType::fromString(rep["type"])),
|
type(NodeType::fromString(rep["type"])),
|
||||||
border(rep["border"]),
|
border(rep["border"]),
|
||||||
current_border_width(rep["current_border_width"]),
|
current_border_width(rep["current_border_width"]),
|
||||||
|
Loading…
Reference in New Issue
Block a user