From 7f22ea956826b6952247f57973ccf94de9c5589c Mon Sep 17 00:00:00 2001 From: Mavroudis Chatzilazaridis Date: Sat, 27 Apr 2024 19:16:51 +0300 Subject: [PATCH] gui: Port to Qt6 --- CMakeLists.txt | 6 +++ src/gui/CMakeLists.txt | 74 ++++++++++++++++++++++++++------ src/gui/ckbversionnumber.cpp | 8 ++++ src/gui/gradientdialogwidget.cpp | 28 ++++++++++-- src/gui/idletimer.cpp | 13 ++++++ src/gui/kb.cpp | 4 +- src/gui/kb.h | 15 ++++++- src/gui/kbanim.cpp | 2 +- src/gui/kbfirmware.cpp | 2 +- src/gui/kblight.cpp | 2 +- src/gui/kbmode.h | 2 +- src/gui/kbprofile.cpp | 2 +- src/gui/kbprofiledialog.cpp | 2 +- src/gui/keyaction.cpp | 17 ++++++-- src/gui/keywidget.cpp | 8 ++++ src/gui/keywidgetdebugger.cpp | 4 +- src/gui/keywidgetdebugger.h | 2 +- src/gui/macrotablemodel.cpp | 27 +++++++++--- src/gui/rebindwidget.cpp | 9 +++- src/sinfo/CMakeLists.txt | 2 +- 20 files changed, 188 insertions(+), 41 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index df491298..b77cb2eb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -153,6 +153,12 @@ option(SAFE_INSTALL "Execute pre-install tasks to ensure correct installation. Intended to be used with direct installations without package manager." OFF) option(SAFE_UNINSTALL "Execute pre-uninstall tasks to ensure correct removal. Intended to be used with direct removals without package manager." OFF) +option(PREFER_QT6 "Build with Qt 6 if available." OFF) + +set(QT_LIST Qt5) +if (PREFER_QT6) + list(INSERT QT_LIST 0 Qt6) +endif () if (NOT WITH_GUI) message(WARNING "Building without GUI. Proceed only if you know what you are doing.") diff --git a/src/gui/CMakeLists.txt b/src/gui/CMakeLists.txt index 6f847f2f..4d8359dd 100644 --- a/src/gui/CMakeLists.txt +++ b/src/gui/CMakeLists.txt @@ -70,8 +70,11 @@ endif () if (MACOS OR LINUX) set(THREADS_PREFER_PTHREAD_FLAG ON) find_package(Threads REQUIRED) - find_package(QT NAMES Qt5 REQUIRED COMPONENTS Core Widgets Network Gui) + find_package(QT NAMES ${QT_LIST} REQUIRED COMPONENTS Core Widgets Network Gui) find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core Widgets Network Gui) + if(QT_VERSION VERSION_GREATER_EQUAL 6) + find_package(Qt6 REQUIRED COMPONENTS OpenGLWidgets) + endif() find_package(ZLIB REQUIRED) find_package(QuaZip REQUIRED) endif () @@ -283,7 +286,7 @@ elseif (LINUX) pkg_check_modules(XCB_EWMH xcb-ewmh) pkg_check_modules(XCB_SCREENSAVER xcb-screensaver) - if(XCB_SCREENSAVER_FOUND AND Qt5X11Extras_FOUND) + if(XCB_SCREENSAVER_FOUND AND (Qt5X11Extras_FOUND OR QT_VERSION_MAJOR VERSION_EQUAL 6)) target_compile_definitions( ckb-next PRIVATE @@ -291,7 +294,7 @@ elseif (LINUX) else() message(FATAL_ERROR "XCB-Screensaver or Qt5 X11Extras was not found. Either install them or pass -DUSE_XCB=0 to disable idle detection.") endif() - if(XCB_FOUND AND Qt5X11Extras_FOUND) + if(XCB_FOUND AND (Qt5X11Extras_FOUND OR QT_VERSION_MAJOR VERSION_EQUAL 6)) target_compile_definitions( ckb-next PRIVATE @@ -343,12 +346,18 @@ elseif (LINUX) PRIVATE USE_DBUS_MENU) - cmake_language(EVAL CODE - "qt${QT_VERSION_MAJOR}_add_dbus_adaptor(statusNotifierAutogen \"kstatusnotifier/org.kde.StatusNotifierItem.xml\" - \"kstatusnotifier/kstatusnotifieritemdbus_p.h\" KStatusNotifierItemDBus) - qt${QT_VERSION_MAJOR}_add_dbus_interface(statusNotifierAutogen \"kstatusnotifier/org.kde.StatusNotifierWatcher.xml\" statusnotifierwatcher_interface) - qt${QT_VERSION_MAJOR}_add_dbus_interface(statusNotifierAutogen \"kstatusnotifier/org.freedesktop.Notifications.xml\" notifications_interface)" - ) + if(QT_VERSION VERSION_GREATER_EQUAL "5.15") + qt_add_dbus_adaptor(statusNotifierAutogen "kstatusnotifier/org.kde.StatusNotifierItem.xml" + "kstatusnotifier/kstatusnotifieritemdbus_p.h" KStatusNotifierItemDBus) + qt_add_dbus_interface(statusNotifierAutogen "kstatusnotifier/org.kde.StatusNotifierWatcher.xml" statusnotifierwatcher_interface) + qt_add_dbus_interface(statusNotifierAutogen "kstatusnotifier/org.freedesktop.Notifications.xml" notifications_interface) + else() + qt5_add_dbus_adaptor(statusNotifierAutogen "kstatusnotifier/org.kde.StatusNotifierItem.xml" + "kstatusnotifier/kstatusnotifieritemdbus_p.h" KStatusNotifierItemDBus) + qt5_add_dbus_interface(statusNotifierAutogen "kstatusnotifier/org.kde.StatusNotifierWatcher.xml" statusnotifierwatcher_interface) + qt5_add_dbus_interface(statusNotifierAutogen "kstatusnotifier/org.freedesktop.Notifications.xml" notifications_interface) + endif() + #set_property(SOURCE ${statusNotifierAutogen} PROPERTY SKIP_AUTOGEN ON) target_sources( ckb-next @@ -362,6 +371,32 @@ elseif (LINUX) kstatusnotifier/config-kstatusnotifieritem.h ckbsystemtrayicon.cpp ${statusNotifierAutogen}) + if(QT_VERSION VERSION_GREATER_EQUAL "6") + qt6_add_dbus_adaptor(canonicalDbusMenuAutogen "${CMAKE_CURRENT_SOURCE_DIR}/kstatusnotifier/libdbusmenu-qt/com.canonical.dbusmenu.xml" + "${CMAKE_CURRENT_SOURCE_DIR}/kstatusnotifier/libdbusmenu-qt/dbusmenuexporterdbus_p.h" + DBusMenuExporterDBus) + + #set_property(SOURCE ${canonicalDbusMenuAutogen} PROPERTY SKIP_AUTOGEN ON) + target_sources( + ckb-next + PRIVATE + kstatusnotifier/libdbusmenu-qt/dbusmenu_p.cpp + kstatusnotifier/libdbusmenu-qt/dbusmenuexporter.cpp + kstatusnotifier/libdbusmenu-qt/dbusmenuexporterdbus_p.cpp + kstatusnotifier/libdbusmenu-qt/dbusmenushortcut_p.cpp + kstatusnotifier/libdbusmenu-qt/dbusmenutypes_p.cpp + kstatusnotifier/libdbusmenu-qt/utils.cpp + kstatusnotifier/libdbusmenu-qt/dbusmenu_p.h + kstatusnotifier/libdbusmenu-qt/dbusmenuexporter.h + kstatusnotifier/libdbusmenu-qt/dbusmenuexporterdbus_p.h + kstatusnotifier/libdbusmenu-qt/dbusmenuexporterprivate_p.h + kstatusnotifier/libdbusmenu-qt/dbusmenushortcut_p.h + kstatusnotifier/libdbusmenu-qt/dbusmenutypes_p.h + kstatusnotifier/libdbusmenu-qt/utils_p.h + kstatusnotifier/libdbusmenu-qt/debug_p.h + ${canonicalDbusMenuAutogen} + ) + endif() endif() endif () @@ -543,6 +578,12 @@ if (MACOS OR LINUX) Qt${QT_VERSION_MAJOR}::Widgets Qt${QT_VERSION_MAJOR}::Gui ZLIB::ZLIB) +if (QT_VERSION VERSION_GREATER_EQUAL "6") + target_link_libraries( + ckb-next + PRIVATE + Qt6::OpenGLWidgets) +endif () endif () if(MACOS) @@ -582,10 +623,17 @@ target_link_libraries( "${QuaZip_LIBRARIES}") # Target compile features and options -set_target_properties( - ckb-next - PROPERTIES - CXX_STANDARD 11) +if (QT_VERSION_MAJOR VERSION_LESS "6") + set_target_properties( + ckb-next + PROPERTIES + CXX_STANDARD 11) +else () + set_target_properties( + ckb-next + PROPERTIES + CXX_STANDARD 17) +endif() target_compile_options( ckb-next diff --git a/src/gui/ckbversionnumber.cpp b/src/gui/ckbversionnumber.cpp index 62b8befb..7e61dd3e 100644 --- a/src/gui/ckbversionnumber.cpp +++ b/src/gui/ckbversionnumber.cpp @@ -1,5 +1,8 @@ #include "ckbversionnumber.h" +#include +#include + static inline bool isAsciiDigitString(const QString& str){ for(const QChar& c : str) if(c < '0' || c > '9') @@ -45,7 +48,12 @@ CkbVersionNumber::CkbVersionNumber(const QString& vstr) : ckbTooOld(false) { ver = QVersionNumber(FWBcdToBin(usver[1]), FWBcdToBin(usver[0])); return; } +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) int i; +#else + qsizetype i; +#endif + ver = QVersionNumber::fromString(vstr, &i); if(!ver.isNull()) suffix = vstr.mid(i); diff --git a/src/gui/gradientdialogwidget.cpp b/src/gui/gradientdialogwidget.cpp index 31dbbe0b..43792ec4 100644 --- a/src/gui/gradientdialogwidget.cpp +++ b/src/gui/gradientdialogwidget.cpp @@ -1,6 +1,10 @@ #include + +#include #include #include +#include + #include "gradientdialogwidget.h" GradientDialogWidget::GradientDialogWidget(QWidget *parent) : @@ -220,7 +224,12 @@ void GradientDialogWidget::paintEvent(QPaintEvent*){ } void GradientDialogWidget::mousePressEvent(QMouseEvent* event){ +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + int x = event->position().x(), y = event->position().y(); +#else int x = event->x(), y = event->y(); +#endif + if(y < height() - 24) return; QMapIterator i(_colors); @@ -253,8 +262,13 @@ void GradientDialogWidget::mousePressEvent(QMouseEvent* event){ } void GradientDialogWidget::mouseMoveEvent(QMouseEvent* event){ +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) + QPoint evtpos(event->x(), event->y()); +#else + QPoint evtpos = event->position().toPoint(); +#endif if(!selected.isValid()){ - if(event->y() >= height() - 24) + if(evtpos.y() >= height() - 24) setCursor(QCursor(Qt::PointingHandCursor)); else setCursor(QCursor(Qt::ArrowCursor)); @@ -262,7 +276,7 @@ void GradientDialogWidget::mouseMoveEvent(QMouseEvent* event){ } // Move selected point (if any) setCursor(QCursor(Qt::ClosedHandCursor)); - selectedPos = event->x() + selectedOffset; + selectedPos = evtpos.x() + selectedOffset; // Allow the point to be deleted as long as there is at least 1 other point bool last = (_colors.count() == 0); // Hug the left/right edges @@ -274,7 +288,7 @@ void GradientDialogWidget::mouseMoveEvent(QMouseEvent* event){ selectedPos = right; // Remove point if it's too far above/below the widget int top = -30, bottom = height() + 30; - if(!last && (event->y() < top || event->y() > bottom)) + if(!last && (evtpos.y() < top || evtpos.y() > bottom)) selectedPos = -1; makeStops(); } @@ -289,7 +303,13 @@ void GradientDialogWidget::mouseReleaseEvent(QMouseEvent* event){ selected = QColor(); makeStops(); } - if(event->y() >= height() - 24) + +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) + const int y = event->y(); +#else + const int y = event->position().y(); +#endif + if(y >= height() - 24) setCursor(QCursor(Qt::PointingHandCursor)); else setCursor(QCursor(Qt::ArrowCursor)); diff --git a/src/gui/idletimer.cpp b/src/gui/idletimer.cpp index 4fcbd8c8..99e35c86 100644 --- a/src/gui/idletimer.cpp +++ b/src/gui/idletimer.cpp @@ -6,7 +6,11 @@ #include #ifdef USE_XCB_SCREENSAVER +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) #include +#else +#include +#endif #include #include #include @@ -17,7 +21,16 @@ int IdleTimer::getIdleTime(){ const MainWindow* const mw = MainWindow::mainWindow; if(!mw || !mw->windowHandle()) return 0; +#if QT_VERSION < QT_VERSION_CHECK(6, 0 ,0) xcb_connection_t* conn = QX11Info::connection(); +#else + xcb_connection_t* conn = nullptr; + QNativeInterface::QX11Application* x11Application; + if(!(x11Application = qGuiApp->nativeInterface())) + return 0; + + conn = x11Application->connection(); +#endif xcb_get_geometry_cookie_t geomCookie = xcb_get_geometry(conn, mw->windowHandle()->winId()); xcb_get_geometry_reply_t* geomReply = xcb_get_geometry_reply(conn, geomCookie, nullptr); diff --git a/src/gui/kb.cpp b/src/gui/kb.cpp index bbf000cb..8daef575 100644 --- a/src/gui/kb.cpp +++ b/src/gui/kb.cpp @@ -606,7 +606,7 @@ void Kb::readNotify(const QString& line){ QString modified = components[2]; KbProfile* newProfile = nullptr; foreach(KbProfile* profile, _profiles){ - if(profile->id().guid == guid){ + if(profile->id().guid == QUuid::fromString(guid)){ newProfile = profile; break; } @@ -659,7 +659,7 @@ void Kb::readNotify(const QString& line){ KbMode* hwMode = nullptr; bool isUpdated = false; foreach(KbMode* kbMode, _hwProfile->modes()){ - if(kbMode->id().guid == guid){ + if(kbMode->id().guid == QUuid::fromString(guid)){ hwMode = kbMode; if(kbMode->id().hwModifiedString() != modified){ // Update modification time diff --git a/src/gui/kb.h b/src/gui/kb.h index 3736e4c6..3e563e2f 100644 --- a/src/gui/kb.h +++ b/src/gui/kb.h @@ -1,24 +1,37 @@ #ifndef KB_H #define KB_H +#include #include #include #include #include + #include "kbprofile.h" #include #include #include "batterysystemtrayicon.h" #include "ckbversionnumber.h" +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) +#include +#endif + struct firmware_t { CkbVersionNumber app; CkbVersionNumber bld; CkbVersionNumber radioapp; CkbVersionNumber radiobld; void parse(const QString& str){ +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + QStringView view(str); + view.truncate(view.size() - 1); // KeepEmptyParts is the default - QVector split = str.leftRef(str.size()-1).split(QChar('\n')); + QList split = view.split(QChar('\n')); +#else + // KeepEmptyParts is the default + QVector split = str.leftRef(str.size() - 1).split(QChar('\n')); +#endif // Old < 0.5.0 format (NXP and legacy) if(split.size() == 1){ app = CkbVersionNumber(split.at(0).toString()); diff --git a/src/gui/kbanim.cpp b/src/gui/kbanim.cpp index 11db2166..cc162819 100644 --- a/src/gui/kbanim.cpp +++ b/src/gui/kbanim.cpp @@ -32,7 +32,7 @@ KbAnim::KbAnim(QObject* parent, const KeyMap& map, const QUuid id, CkbSettingsBa if(!modeOk) _mode = Normal; _scriptName = settings.value("ScriptName").toString().trimmed(); - _scriptGuid = settings.value("ScriptGuid").toString(); + _scriptGuid = QUuid::fromString(settings.value("ScriptGuid").toString()); { SGroup subgroup(settings, "Parameters"); foreach(const QString& param, settings.childKeys()) diff --git a/src/gui/kbfirmware.cpp b/src/gui/kbfirmware.cpp index 95018b4c..655ebdc5 100644 --- a/src/gui/kbfirmware.cpp +++ b/src/gui/kbfirmware.cpp @@ -116,7 +116,7 @@ void KbFirmware::processDownload(QNetworkReply* reply){ bool scan = false; foreach(QString line, lines){ // Collapse whitespace - line.replace(QRegExp("\\s+"), " ").remove(QRegExp("^\\s")).remove(QRegExp("\\s$")); + line.replace(QRegularExpression("\\s+"), " ").remove(QRegularExpression("^\\s")).remove(QRegularExpression("\\s$")); // Skip empty or commented-out lines if(line.length() == 0 || line.at(0) == '#') continue; diff --git a/src/gui/kblight.cpp b/src/gui/kblight.cpp index 5649cf66..1709a251 100644 --- a/src/gui/kblight.cpp +++ b/src/gui/kblight.cpp @@ -467,7 +467,7 @@ void KbLight::load(CkbSettingsBase& settings){ { SGroup subGroup(settings, "Animations"); foreach(QString anim, settings.value("List").toStringList()){ - QUuid id = anim; + QUuid id(anim); _animList.append(new KbAnim(this, _map, id, settings)); } } diff --git a/src/gui/kbmode.h b/src/gui/kbmode.h index 31f48a77..e85e3fe3 100644 --- a/src/gui/kbmode.h +++ b/src/gui/kbmode.h @@ -20,7 +20,7 @@ struct UsbId { inline UsbId() : guid(QUuid::createUuid()),modified(0) {} QString guidString() const { return guid.toString().toUpper(); } - void guidString(const QString& newGuid) { guid = newGuid; } + void guidString(const QString& newGuid) { guid = QUuid::fromString(newGuid); } QString modifiedString() const { return QString::number(modified, 16); } void modifiedString(const QString& newModified) { modified = newModified.toUInt(nullptr, 16); } QString hwModifiedString() const { return QString::number(hwModified, 16); } diff --git a/src/gui/kbprofile.cpp b/src/gui/kbprofile.cpp index d19bf1ec..5b2a4af1 100644 --- a/src/gui/kbprofile.cpp +++ b/src/gui/kbprofile.cpp @@ -36,7 +36,7 @@ KbProfile::KbProfile(Kb* parent, const KeyMap& keyMap, CkbSettingsBase& settings _usbId.hwModifiedString(settings.value("HwModified").toString()); else _usbId.hwModified = _usbId.modified; - QUuid current = settings.value("CurrentMode").toString().trimmed(); + QUuid current(settings.value("CurrentMode").toString().trimmed()); // Load modes uint count = settings.value("ModeCount").toUInt(); for(uint i = 0; i < count; i++){ diff --git a/src/gui/kbprofiledialog.cpp b/src/gui/kbprofiledialog.cpp index a5d75784..b6932b06 100644 --- a/src/gui/kbprofiledialog.cpp +++ b/src/gui/kbprofiledialog.cpp @@ -480,7 +480,7 @@ void KbProfileDialog::on_importButton_clicked(){ CkbExternalSettings* sptr = profileptrs.at(i).first; //QString guid = profileptrs.at(i).second; //QUuid current = guid.trimmed(); - QUuid guid = sptr->childGroups().first().trimmed(); + QUuid guid(sptr->childGroups().first().trimmed()); // Messy, shhhh const QString& profname = profilestr.at(i); KbProfile* profilematch = nullptr; diff --git a/src/gui/keyaction.cpp b/src/gui/keyaction.cpp index a1f41be4..5cf44260 100644 --- a/src/gui/keyaction.cpp +++ b/src/gui/keyaction.cpp @@ -12,8 +12,10 @@ #include #include #include +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) #include #endif +#endif KeyAction::Type KeyAction::type() const { if(_value.isEmpty()) @@ -244,7 +246,7 @@ QUuid KeyAction::animInfo(bool &onlyOnce, bool &stopOnRelease) const { QStringList split = param.split("+"); if(split.length() < 2) return QUuid(); - QUuid id = split[0]; + QUuid id(split[0]); int flags = split[1].toInt(); onlyOnce = !!(flags & ANIM_ONCE); stopOnRelease = !!(flags & ANIM_KRSTOP); @@ -484,17 +486,24 @@ QString KeyAction::getDisplayForScreenCursor(){ #ifdef USE_XCB if(QApplication::platformName() != QLatin1String("xcb")) return displaystr; +#if QT_VERSION < QT_VERSION_CHECK(6, 0 ,0) xcb_connection_t* conn = QX11Info::connection(); +#else + xcb_connection_t* conn = nullptr; + QNativeInterface::QX11Application* x11Application; + if((x11Application = qGuiApp->nativeInterface())) + conn = x11Application->connection(); +#endif // First, get the window id const MainWindow* const mw = MainWindow::mainWindow; - if(!mw || !mw->windowHandle()) + if(!mw || !mw->windowHandle() || !conn) return displaystr; xcb_window_t ckb_xcb_id = static_cast(mw->windowHandle()->winId()); // Check if the cursor is in the same screen as the ckb-next window - xcb_query_pointer_reply_t* ptr_reply = xcb_query_pointer_reply(conn, xcb_query_pointer(conn, ckb_xcb_id), NULL); + xcb_query_pointer_reply_t* ptr_reply = xcb_query_pointer_reply(conn, xcb_query_pointer(conn, ckb_xcb_id), nullptr); if(!ptr_reply->same_screen) { // Get the screen ID @@ -510,7 +519,7 @@ QString KeyAction::getDisplayForScreenCursor(){ char* host; int parsed_display; - if(xcb_parse_display(DISPLAY, &host, &parsed_display, NULL)) { + if(xcb_parse_display(DISPLAY, &host, &parsed_display, nullptr)) { displaystr = QString("%1:%2.%3").arg(QString::fromUtf8(host)).arg(parsed_display).arg(screen); free(host); } diff --git a/src/gui/keywidget.cpp b/src/gui/keywidget.cpp index bcf82475..61fee793 100644 --- a/src/gui/keywidget.cpp +++ b/src/gui/keywidget.cpp @@ -697,7 +697,11 @@ void KeyWidget::mousePressEvent(QMouseEvent* event){ event->accept(); mouseDownMode = (event->modifiers() & Qt::AltModifier) ? SUBTRACT : (event->modifiers() & Qt::ShiftModifier) ? ADD : (event->modifiers() & Qt::ControlModifier) ? TOGGLE : SET; // See if the event hit a key +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) mouseDown = event->localPos(); +#else + mouseDown = event->position(); +#endif QPointF mouseDownScaled = mouseDown / drawInfoScale - drawInfoOffset; int i = -1; for(const Key& key : keyMap){ @@ -733,7 +737,11 @@ void KeyWidget::mouseMoveEvent(QMouseEvent* event){ return; // Find selection rectangle +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) const QPointF& mouseCurrent = event->localPos(); +#else + const QPointF& mouseCurrent = event->position(); +#endif QPointF mouseCurrentScaled = mouseCurrent / drawInfoScale - drawInfoOffset; QRectF mouseHighlightRectScaled; diff --git a/src/gui/keywidgetdebugger.cpp b/src/gui/keywidgetdebugger.cpp index 5808342a..00f04c5d 100644 --- a/src/gui/keywidgetdebugger.cpp +++ b/src/gui/keywidgetdebugger.cpp @@ -68,9 +68,9 @@ void KeyWidgetDebugger::on_layoutComboBox_currentIndexChanged(int arg1) updateMap(); } -void KeyWidgetDebugger::on_modelComboBox_currentIndexChanged(const QString& arg1) +void KeyWidgetDebugger::on_modelComboBox_currentIndexChanged(int arg1) { - m = KeyMap::getModel(arg1); + m = KeyMap::getModel(ui->modelComboBox->itemText(arg1)); updateMap(); } diff --git a/src/gui/keywidgetdebugger.h b/src/gui/keywidgetdebugger.h index b4f89b2b..ea3998c5 100644 --- a/src/gui/keywidgetdebugger.h +++ b/src/gui/keywidgetdebugger.h @@ -20,7 +20,7 @@ public: private slots: void on_lightingCheckBox_toggled(bool checked); void on_layoutComboBox_currentIndexChanged(int arg1); - void on_modelComboBox_currentIndexChanged(const QString& arg1); + void on_modelComboBox_currentIndexChanged(int arg1); void on_keyList_currentItemChanged(QListWidgetItem* current, QListWidgetItem* previous); void on_x_valueChanged(int arg1); void on_y_valueChanged(int arg1); diff --git a/src/gui/macrotablemodel.cpp b/src/gui/macrotablemodel.cpp index 953ea341..d8d91644 100644 --- a/src/gui/macrotablemodel.cpp +++ b/src/gui/macrotablemodel.cpp @@ -1,7 +1,8 @@ -#include "macrotablemodel.h" +#include "macrotablemodel.h" #include #include #include +#include const QSet MacroTableModel::validMacroKeys = QSet{"esc", @@ -275,7 +276,12 @@ bool MacroTableModel::setData(const QModelIndex& index, const QVariant& value, i ml.usTime = ml.usTimeMax = MacroLine::MACRO_DELAY_DEFAULT; return true; } +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + QStringView view(valstr); + QList split = view.split(QChar('_')); +#else QVector split = valstr.splitRef(QChar('_')); +#endif const int len = split.length(); if(len != 1 && len != 2) return false; @@ -322,19 +328,25 @@ QString MacroTableModel::toString(bool rawData){ return l; } - +#if QT_VERSION < QT_VERSION_CHECK(6, 0 ,0) #define MACRO_ERROR(end, start) return QString::number(end) % ":
" % str.leftRef(end) \ % "" % str.midRef(end, start - end) % "" \ % str.midRef(start) +#else +#define MACRO_ERROR(end, start) return QString::number(end) % ":
" % strView.first(end) \ + % "" % strView.sliced(end, start - end) % "" \ + % strView.sliced(start) +#endif #define MACRO_ERROR_RET() MACRO_ERROR(previousEnd, currentStart) #define MACRO_ERROR_RET_SUFFIX(end, start, suffix) MACRO_ERROR(end, start) % "

" % suffix QString MacroTableModel::fromString(const QString& input, const bool stopOnError){ // Replace all "whitespace" characters with ' ', and then remove that as well QString str = input.simplified(); str.replace(QChar(' '), QString("")); + QStringView strView(str); QVector newMacroLines; QRegularExpression re("(\\+|-)([a-z0-9_]+)(=(\\d+)(_(\\d+))?)?(,|$)"); - QRegularExpressionMatchIterator i = re.globalMatch(str); + QRegularExpressionMatchIterator i = re.globalMatch(strView.toString()); qint64 prevDelay = MacroLine::MACRO_DELAY_DEFAULT, prevMaxDelay = MacroLine::MACRO_DELAY_DEFAULT; int previousEnd = 0; while (i.hasNext()) { @@ -344,10 +356,15 @@ QString MacroTableModel::fromString(const QString& input, const bool stopOnError if(previousEnd != currentStart && stopOnError){ MACRO_ERROR_RET(); } - QStringRef act = m.capturedRef(1); + QStringView act = m.capturedView(1); QString key = m.captured(2); +#if QT_VERSION < QT_VERSION_CHECK(6, 0 ,0) QStringRef delaystr = m.capturedRef(4); QStringRef maxDelayStr = m.capturedRef(6); +#else + QStringView delaystr = m.capturedView(4); + QStringView maxDelayStr = m.capturedView(6); +#endif qint64 delay = MacroLine::MACRO_DELAY_DEFAULT, maxDelay = MacroLine::MACRO_DELAY_DEFAULT; if(!delaystr.isNull()){ @@ -372,7 +389,7 @@ QString MacroTableModel::fromString(const QString& input, const bool stopOnError } } // Act and key will always be valid strings - const bool down = (act == "+"); + const bool down = (act == QStringLiteral("+")); // Make sure the key actually exists if(!validMacroKeys.contains(key)){ diff --git a/src/gui/rebindwidget.cpp b/src/gui/rebindwidget.cpp index c6548f75..96fef3f6 100644 --- a/src/gui/rebindwidget.cpp +++ b/src/gui/rebindwidget.cpp @@ -347,8 +347,13 @@ void RebindWidget::setSelection(const QStringList& newSelection, bool applyPrevi if (act.isMacro()) { // This string needs to exist for as long as the references below are used QString value = act.value(); +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) // Split the action and discard the "$macro" from the beginning QVector macroData = value.midRef(7).split(QChar(':')); +#else + QStringView valueView(value); + QList macroData = valueView.sliced(7).split(QChar(':')); +#endif const int dataCount = macroData.count(); // Old format doesn't have the last field, which is the raw macro data // It might not exist at all (count == 3) or it might be set to "x" @@ -359,8 +364,8 @@ void RebindWidget::setSelection(const QStringList& newSelection, bool applyPrevi ui->macroName->setText(macroName); // Pick the appropriate string to parse due to legacy formats - QStringRef macroString = macroData[0]; - if(dataCount == 4 && macroData[3] != "x") + QStringView macroString = macroData[0]; + if(dataCount == 4 && macroData[3] != QStringLiteral("x")) macroString = macroData[3]; // Try to parse the string diff --git a/src/sinfo/CMakeLists.txt b/src/sinfo/CMakeLists.txt index dc997bd6..8bd7e05c 100644 --- a/src/sinfo/CMakeLists.txt +++ b/src/sinfo/CMakeLists.txt @@ -1,4 +1,4 @@ -find_package(QT NAMES Qt5 COMPONENTS Widgets REQUIRED) +find_package(QT NAMES ${QT_LIST} COMPONENTS Widgets REQUIRED) find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Widgets REQUIRED) add_executable(ckb-next-sinfo sinfo.cpp)