mirror of
https://github.com/ckb-next/ckb-next.git
synced 2026-10-17 07:33:59 -04:00
gui: Port to Qt6
This commit is contained in:
@@ -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.")
|
||||
|
||||
+61
-13
@@ -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
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
#include "ckbversionnumber.h"
|
||||
|
||||
#include <QtGlobal>
|
||||
#include <QObject>
|
||||
|
||||
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);
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
#include <cmath>
|
||||
|
||||
#include <QtGlobal>
|
||||
#include <QPainter>
|
||||
#include <QPropertyAnimation>
|
||||
#include <QVector>
|
||||
|
||||
#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<int, QColor> 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));
|
||||
|
||||
@@ -6,7 +6,11 @@
|
||||
#include <QWindow>
|
||||
|
||||
#ifdef USE_XCB_SCREENSAVER
|
||||
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
|
||||
#include <QX11Info>
|
||||
#else
|
||||
#include <QGuiApplication>
|
||||
#endif
|
||||
#include <xcb/xcb.h>
|
||||
#include <xcb/screensaver.h>
|
||||
#include <limits.h>
|
||||
@@ -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<QNativeInterface::QX11Application>()))
|
||||
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);
|
||||
|
||||
+2
-2
@@ -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
|
||||
|
||||
+14
-1
@@ -1,24 +1,37 @@
|
||||
#ifndef KB_H
|
||||
#define KB_H
|
||||
|
||||
#include <QtGlobal>
|
||||
#include <QObject>
|
||||
#include <QFile>
|
||||
#include <QThread>
|
||||
#include <QTimer>
|
||||
|
||||
#include "kbprofile.h"
|
||||
#include <QElapsedTimer>
|
||||
#include <limits>
|
||||
#include "batterysystemtrayicon.h"
|
||||
#include "ckbversionnumber.h"
|
||||
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
||||
#include <QStringView>
|
||||
#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<QStringRef> split = str.leftRef(str.size()-1).split(QChar('\n'));
|
||||
QList<QStringView> split = view.split(QChar('\n'));
|
||||
#else
|
||||
// KeepEmptyParts is the default
|
||||
QVector<QStringRef> 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());
|
||||
|
||||
+1
-1
@@ -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())
|
||||
|
||||
@@ -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;
|
||||
|
||||
+1
-1
@@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -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); }
|
||||
|
||||
@@ -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++){
|
||||
|
||||
@@ -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;
|
||||
|
||||
+13
-4
@@ -12,8 +12,10 @@
|
||||
#include <QWindow>
|
||||
#include <xcb/xcb.h>
|
||||
#include <xcb/xproto.h>
|
||||
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
|
||||
#include <QX11Info>
|
||||
#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<QNativeInterface::QX11Application>()))
|
||||
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<xcb_window_t>(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);
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
#include "macrotablemodel.h"
|
||||
#include "macrotablemodel.h"
|
||||
#include <QRegularExpression>
|
||||
#include <QStringBuilder>
|
||||
#include <QMimeData>
|
||||
#include <QIODevice>
|
||||
|
||||
const QSet<QString> MacroTableModel::validMacroKeys =
|
||||
QSet<QString>{"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<QStringView> split = view.split(QChar('_'));
|
||||
#else
|
||||
QVector<QStringRef> 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) % ":<br>" % str.leftRef(end) \
|
||||
% "<b><span style=\"color: #ff0000;\">" % str.midRef(end, start - end) % "</span></b>" \
|
||||
% str.midRef(start)
|
||||
#else
|
||||
#define MACRO_ERROR(end, start) return QString::number(end) % ":<br>" % strView.first(end) \
|
||||
% "<b><span style=\"color: #ff0000;\">" % strView.sliced(end, start - end) % "</span></b>" \
|
||||
% strView.sliced(start)
|
||||
#endif
|
||||
#define MACRO_ERROR_RET() MACRO_ERROR(previousEnd, currentStart)
|
||||
#define MACRO_ERROR_RET_SUFFIX(end, start, suffix) MACRO_ERROR(end, start) % "<br><br>" % 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<MacroLine> 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)){
|
||||
|
||||
@@ -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<QStringRef> macroData = value.midRef(7).split(QChar(':'));
|
||||
#else
|
||||
QStringView valueView(value);
|
||||
QList<QStringView> 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
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user