summaryrefslogtreecommitdiffstats
path: root/examples/widgets/widgets/shortcuteditor/mainwindow.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'examples/widgets/widgets/shortcuteditor/mainwindow.cpp')
-rw-r--r--examples/widgets/widgets/shortcuteditor/mainwindow.cpp46
1 files changed, 46 insertions, 0 deletions
diff --git a/examples/widgets/widgets/shortcuteditor/mainwindow.cpp b/examples/widgets/widgets/shortcuteditor/mainwindow.cpp
new file mode 100644
index 0000000000..587dbbc5b5
--- /dev/null
+++ b/examples/widgets/widgets/shortcuteditor/mainwindow.cpp
@@ -0,0 +1,46 @@
+// Copyright (C) 2022 Laszlo Papp <lpapp@kde.org>
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+
+#include "mainwindow.h"
+
+#include "actionmanager.h"
+#include "application.h"
+#include "shortcuteditorwidget.h"
+
+#include <QAction>
+#include <QHBoxLayout>
+#include <QPushButton>
+#include <QVBoxLayout>
+
+MainWindow::MainWindow()
+{
+ QPushButton *topPushButton = new QPushButton("Left");
+ QPushButton *bottomPushButton = new QPushButton("Right");
+ for (auto nameShortcut : std::vector<std::vector<const char *>>{{"red", "r", "shift+r"}, {"green", "g", "shift+g"}, {"blue", "b", "shift+b"}}) {
+ Application *application = static_cast<Application *>(QCoreApplication::instance());
+ ActionManager *actionManager = application->actionManager();
+ QAction *action = actionManager->registerAction(nameShortcut[0], nameShortcut[1], "top", "color");
+ topPushButton->addAction(action);
+ connect(action, &QAction::triggered, this, [topPushButton, nameShortcut]() {
+ topPushButton->setText(nameShortcut[0]);
+ });
+
+ action = actionManager->registerAction(nameShortcut[0], nameShortcut[2], "bottom", "color");
+ bottomPushButton->addAction(action);
+ connect(action, &QAction::triggered, this, [bottomPushButton, nameShortcut]() {
+ bottomPushButton->setText(nameShortcut[0]);
+ });
+ }
+
+ QVBoxLayout *vBoxLayout = new QVBoxLayout;
+ vBoxLayout->addWidget(topPushButton);
+ vBoxLayout->addWidget(bottomPushButton);
+
+ QHBoxLayout *hBoxLayout = new QHBoxLayout;
+ hBoxLayout->addWidget(new ShortcutEditorWidget);
+ hBoxLayout->addLayout(vBoxLayout);
+
+ QWidget *centralWidget = new QWidget;
+ centralWidget->setLayout(hBoxLayout);
+ setCentralWidget(centralWidget);
+}