mirror of
https://github.com/NohamR/Reclass.git
synced 2026-05-10 19:59:21 +00:00
add Qt5 compatibility wrapper for addAction and linux-qt5 CI job
This commit is contained in:
30
.github/workflows/build.yml
vendored
30
.github/workflows/build.yml
vendored
@@ -173,3 +173,33 @@ jobs:
|
||||
files: Reclass-x86_64.AppImage
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
linux-qt5:
|
||||
runs-on: ubuntu-22.04
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
submodules: recursive
|
||||
|
||||
- name: Install Qt5
|
||||
uses: jurplel/install-qt-action@v4
|
||||
with:
|
||||
version: '5.15.2'
|
||||
cache: true
|
||||
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y ninja-build libgl1-mesa-dev
|
||||
|
||||
- name: Configure
|
||||
run: cmake -B build -G Ninja -DCMAKE_BUILD_TYPE=Release
|
||||
|
||||
- name: Build
|
||||
run: cmake --build build
|
||||
|
||||
- name: Test
|
||||
run: xvfb-run ctest --test-dir build --output-on-failure --exclude-regex "test_editor"
|
||||
env:
|
||||
QT_QPA_PLATFORM: offscreen
|
||||
|
||||
19
src/main.cpp
19
src/main.cpp
@@ -1,4 +1,5 @@
|
||||
#include "mainwindow.h"
|
||||
#include "qt5compat.h"
|
||||
#include "generator.h"
|
||||
#include "mcp/mcp_bridge.h"
|
||||
#include <QApplication>
|
||||
@@ -359,14 +360,14 @@ QIcon MainWindow::makeIcon(const QString& svgPath) {
|
||||
void MainWindow::createMenus() {
|
||||
// File
|
||||
auto* file = m_titleBar->menuBar()->addMenu("&File");
|
||||
file->addAction("&New", QKeySequence::New, this, &MainWindow::newDocument);
|
||||
file->addAction("New &Tab", QKeySequence(Qt::CTRL | Qt::Key_T), this, &MainWindow::newFile);
|
||||
file->addAction(makeIcon(":/vsicons/folder-opened.svg"), "&Open...", QKeySequence::Open, this, &MainWindow::openFile);
|
||||
rcx::compat::addAction(file, "&New", QKeySequence::New, this, &MainWindow::newDocument);
|
||||
rcx::compat::addAction(file, "New &Tab", QKeySequence(Qt::CTRL | Qt::Key_T), this, &MainWindow::newFile);
|
||||
rcx::compat::addAction(file, makeIcon(":/vsicons/folder-opened.svg"), "&Open...", QKeySequence::Open, this, &MainWindow::openFile);
|
||||
file->addSeparator();
|
||||
file->addAction(makeIcon(":/vsicons/save.svg"), "&Save", QKeySequence::Save, this, &MainWindow::saveFile);
|
||||
file->addAction(makeIcon(":/vsicons/save-as.svg"), "Save &As...", QKeySequence::SaveAs, this, &MainWindow::saveFileAs);
|
||||
rcx::compat::addAction(file, makeIcon(":/vsicons/save.svg"), "&Save", QKeySequence::Save, this, &MainWindow::saveFile);
|
||||
rcx::compat::addAction(file, makeIcon(":/vsicons/save-as.svg"), "Save &As...", QKeySequence::SaveAs, this, &MainWindow::saveFileAs);
|
||||
file->addSeparator();
|
||||
file->addAction("&Unload Project", QKeySequence(Qt::CTRL | Qt::Key_W), this, &MainWindow::closeFile);
|
||||
rcx::compat::addAction(file, "&Unload Project", QKeySequence(Qt::CTRL | Qt::Key_W), this, &MainWindow::closeFile);
|
||||
file->addSeparator();
|
||||
file->addAction(makeIcon(":/vsicons/export.svg"), "Export &C++ Header...", this, &MainWindow::exportCpp);
|
||||
file->addSeparator();
|
||||
@@ -374,12 +375,12 @@ void MainWindow::createMenus() {
|
||||
file->addSeparator();
|
||||
file->addAction(makeIcon(":/vsicons/settings-gear.svg"), "&Options...", this, &MainWindow::showOptionsDialog);
|
||||
file->addSeparator();
|
||||
file->addAction(makeIcon(":/vsicons/close.svg"), "E&xit", QKeySequence(Qt::Key_Close), this, &QMainWindow::close);
|
||||
rcx::compat::addAction(file, makeIcon(":/vsicons/close.svg"), "E&xit", QKeySequence(Qt::Key_Close), this, &QMainWindow::close);
|
||||
|
||||
// Edit
|
||||
auto* edit = m_titleBar->menuBar()->addMenu("&Edit");
|
||||
edit->addAction(makeIcon(":/vsicons/arrow-left.svg"), "&Undo", QKeySequence::Undo, this, &MainWindow::undo);
|
||||
edit->addAction(makeIcon(":/vsicons/arrow-right.svg"), "&Redo", QKeySequence::Redo, this, &MainWindow::redo);
|
||||
rcx::compat::addAction(edit, makeIcon(":/vsicons/arrow-left.svg"), "&Undo", QKeySequence::Undo, this, &MainWindow::undo);
|
||||
rcx::compat::addAction(edit, makeIcon(":/vsicons/arrow-right.svg"), "&Redo", QKeySequence::Redo, this, &MainWindow::redo);
|
||||
edit->addSeparator();
|
||||
edit->addAction("&Type Aliases...", this, &MainWindow::showTypeAliasesDialog);
|
||||
|
||||
|
||||
37
src/qt5compat.h
Normal file
37
src/qt5compat.h
Normal file
@@ -0,0 +1,37 @@
|
||||
#pragma once
|
||||
#include <QtGlobal>
|
||||
#include <QMenu>
|
||||
#include <QAction>
|
||||
#include <QKeySequence>
|
||||
#include <QIcon>
|
||||
|
||||
namespace rcx { namespace compat {
|
||||
|
||||
// QMenu::addAction with shortcut — Qt6 puts shortcut before receiver,
|
||||
// Qt5 puts it after. These normalize to the Qt6 argument order.
|
||||
|
||||
template<typename Obj, typename Func>
|
||||
inline QAction* addAction(QMenu* menu, const QString& text,
|
||||
const QKeySequence& shortcut,
|
||||
const Obj* receiver, Func slot)
|
||||
{
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
||||
return menu->addAction(text, shortcut, receiver, slot);
|
||||
#else
|
||||
return menu->addAction(text, receiver, slot, shortcut);
|
||||
#endif
|
||||
}
|
||||
|
||||
template<typename Obj, typename Func>
|
||||
inline QAction* addAction(QMenu* menu, const QIcon& icon, const QString& text,
|
||||
const QKeySequence& shortcut,
|
||||
const Obj* receiver, Func slot)
|
||||
{
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
||||
return menu->addAction(icon, text, shortcut, receiver, slot);
|
||||
#else
|
||||
return menu->addAction(icon, text, receiver, slot, shortcut);
|
||||
#endif
|
||||
}
|
||||
|
||||
}} // namespace rcx::compat
|
||||
Reference in New Issue
Block a user