From f9bde4a2ff3912f24f8454a24c0f33b82010361d Mon Sep 17 00:00:00 2001 From: karliss Date: Mon, 30 Nov 2020 09:42:13 +0200 Subject: [PATCH] Start making adjustment for qt6 compatibility. (#2463) * Introduce cmake option for using Qt6, build doesn't work fully yet. * Recursive mutex, QActionGroup, QComboBox::AdjustToMinimumContentsLength * Cleanup dock locking --- src/CMakeLists.txt | 10 ++++- src/common/RichTextPainter.cpp | 7 +++- src/core/Cutter.cpp | 7 +++- src/core/Cutter.h | 4 ++ src/core/MainWindow.cpp | 60 +++++++--------------------- src/core/MainWindow.h | 8 +--- src/core/MainWindow.ui | 38 ++++++------------ src/dialogs/XrefsDialog.cpp | 2 +- src/menus/DisassemblyContextMenu.cpp | 6 +-- src/widgets/CommentsWidget.cpp | 1 + src/widgets/CutterGraphView.cpp | 2 + src/widgets/FunctionsWidget.cpp | 1 + src/widgets/HexWidget.cpp | 1 + src/widgets/HexdumpWidget.ui | 12 +++--- 14 files changed, 66 insertions(+), 93 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index be12b80b..9c006ce7 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -25,6 +25,7 @@ option(CUTTER_ENABLE_DEPENDENCY_DOWNLOADS "Enable downloading of dependencies. S option(CUTTER_PACKAGE_DEPENDENCIES "During install step include the third party dependencies." OFF) option(CUTTER_PACKAGE_R2GHIDRA "Compile and install r2ghidra during install step." OFF) option(CUTTER_PACKAGE_R2DEC "Compile and install r2dec during install step." OFF) +OPTION(CUTTER_QT6 "Use QT6" OFF) if(NOT CUTTER_ENABLE_PYTHON) set(CUTTER_ENABLE_PYTHON_BINDINGS OFF) @@ -55,7 +56,12 @@ set(CMAKE_INCLUDE_CURRENT_DIR ON) set(CMAKE_AUTOMOC ON) set(CMAKE_AUTOUIC ON) set(CMAKE_AUTORCC ON) -find_package(Qt5 REQUIRED COMPONENTS Core Widgets Gui Svg Network) +if (CUTTER_QT6) + set(QT_PREFIX Qt6) +else() + set(QT_PREFIX Qt5) +endif() +find_package(${QT_PREFIX} REQUIRED COMPONENTS Core Widgets Gui Svg Network) include(CutterInstallDirs) @@ -219,7 +225,7 @@ if(CUTTER_ENABLE_CRASH_REPORTS) endif() endif() -target_link_libraries(Cutter PUBLIC Qt5::Core Qt5::Widgets Qt5::Gui PRIVATE Qt5::Svg Qt5::Network) +target_link_libraries(Cutter PUBLIC ${QT_PREFIX}::Core ${QT_PREFIX}::Widgets ${QT_PREFIX}::Gui PRIVATE ${QT_PREFIX}::Svg ${QT_PREFIX}::Network) target_link_libraries(Cutter PUBLIC ${RADARE2_TARGET}) if(CUTTER_ENABLE_PYTHON) if (WIN32) diff --git a/src/common/RichTextPainter.cpp b/src/common/RichTextPainter.cpp index f41b81be..009285ae 100644 --- a/src/common/RichTextPainter.cpp +++ b/src/common/RichTextPainter.cpp @@ -47,7 +47,12 @@ void RichTextPainter::paintRichText(QPainter *painter, T x, T y, T w, T h, T xin painter->setPen(pen); break; } - painter->drawText(typename Metrics::Rect(x + xinc, y, w - xinc, h), Qt::TextBypassShaping, curRichText.text); + int flags = 0; +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) + flags = Qt::TextBypassShaping; +#endif + + painter->drawText(typename Metrics::Rect(x + xinc, y, w - xinc, h), flags, curRichText.text); if (curRichText.highlight && curRichText.highlightColor.alpha()) { highlightPen.setColor(curRichText.highlightColor); highlightPen.setWidth(curRichText.highlightWidth); diff --git a/src/core/Cutter.cpp b/src/core/Cutter.cpp index 6ade8e80..4ebadfec 100644 --- a/src/core/Cutter.cpp +++ b/src/core/Cutter.cpp @@ -165,8 +165,11 @@ static void cutterREventCallback(REvent *, int type, void *user, void *data) core->handleREvent(type, data); } -CutterCore::CutterCore(QObject *parent) : - QObject(parent), coreMutex(QMutex::Recursive) +CutterCore::CutterCore(QObject *parent): + QObject(parent) +#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0) + , coreMutex(QMutex::Recursive) +#endif { } diff --git a/src/core/Cutter.h b/src/core/Cutter.h index 790a648f..b6a3065e 100644 --- a/src/core/Cutter.h +++ b/src/core/Cutter.h @@ -715,7 +715,11 @@ private: * NEVER use this directly! Always use the CORE_LOCK(); macro and access it like core->... */ RCore *core_ = nullptr; +#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0) QMutex coreMutex; +#else + QRecursiveMutex coreMutex; +#endif int coreLockDepth = 0; void *coreBed = nullptr; diff --git a/src/core/MainWindow.cpp b/src/core/MainWindow.cpp index 1fca03db..5a8d0a8a 100644 --- a/src/core/MainWindow.cpp +++ b/src/core/MainWindow.cpp @@ -74,6 +74,7 @@ #include "widgets/CallGraph.h" // Qt Headers +#include #include #include #include @@ -124,7 +125,6 @@ MainWindow::MainWindow(QWidget *parent) : core(Core()), ui(new Ui::MainWindow) { - panelLock = false; tabsOnTop = false; configuration = Config(); @@ -233,7 +233,7 @@ void MainWindow::initUI() ioModesController.setIOMode(IOModesController::Mode::READ_ONLY); setAvailableIOModeOptions(); }); - + connect(ui->actionSaveLayout, &QAction::triggered, this, &MainWindow::saveNamedLayout); connect(ui->actionManageLayouts, &QAction::triggered, this, &MainWindow::manageLayouts); connect(ui->actionDocumentation, &QAction::triggered, this, &MainWindow::documentationClicked); @@ -256,6 +256,8 @@ void MainWindow::initUI() ui->menuPlugins->setEnabled(false); } + connect(ui->actionUnlock, &QAction::toggled, this, [this](bool unlock){ lockDocks(!unlock); }); + #if QT_VERSION < QT_VERSION_CHECK(5, 7, 0) ui->actionGrouped_dock_dragging->setVisible(false); #endif @@ -745,8 +747,7 @@ void MainWindow::readSettings() QSettings settings; responsive = settings.value("responsive").toBool(); - panelLock = settings.value("panelLock").toBool(); - setPanelLock(); + lockDocks(settings.value("panelLock").toBool()); tabsOnTop = settings.value("tabsOnTop").toBool(); setTabLocation(); bool dockGroupedDragging = settings.value("docksGroupedDragging", false).toBool(); @@ -760,7 +761,7 @@ void MainWindow::saveSettings() { QSettings settings; - settings.setValue("panelLock", panelLock); + settings.setValue("panelLock", !ui->actionUnlock->isChecked()); settings.setValue("tabsOnTop", tabsOnTop); settings.setValue("docksGroupedDragging", ui->actionGrouped_dock_dragging->isChecked()); settings.setValue("geometry", saveGeometry()); @@ -769,24 +770,6 @@ void MainWindow::saveSettings() saveLayouts(settings); } - -void MainWindow::setPanelLock() -{ - if (panelLock) { - for (QDockWidget *dockWidget : findChildren()) { - dockWidget->setFeatures(QDockWidget::NoDockWidgetFeatures); - } - - ui->actionLock->setChecked(false); - } else { - for (QDockWidget *dockWidget : findChildren()) { - dockWidget->setFeatures(QDockWidget::AllDockWidgetFeatures); - } - - ui->actionLock->setChecked(true); - } -} - void MainWindow::setTabLocation() { if (tabsOnTop) { @@ -803,15 +786,20 @@ void MainWindow::refreshAll() core->triggerRefreshAll(); } -void MainWindow::lockUnlock_Docks(bool what) +void MainWindow::lockDocks(bool lock) { - if (what) { + if (ui->actionUnlock->isChecked() == lock) { + ui->actionUnlock->setChecked(!lock); + } + if (lock) { for (QDockWidget *dockWidget : findChildren()) { dockWidget->setFeatures(QDockWidget::NoDockWidgetFeatures); } } else { for (QDockWidget *dockWidget : findChildren()) { - dockWidget->setFeatures(QDockWidget::AllDockWidgetFeatures); + dockWidget->setFeatures(QDockWidget::DockWidgetClosable | + QDockWidget::DockWidgetMovable | + QDockWidget::DockWidgetFloatable); } } @@ -1452,26 +1440,6 @@ void MainWindow::saveLayouts(QSettings &settings) settings.endArray(); } -void MainWindow::on_actionLock_triggered() -{ - panelLock = !panelLock; - setPanelLock(); -} - -void MainWindow::on_actionLockUnlock_triggered() -{ - if (ui->actionLockUnlock->isChecked()) { - for (QDockWidget *dockWidget : findChildren()) { - dockWidget->setFeatures(QDockWidget::NoDockWidgetFeatures); - } - ui->actionLockUnlock->setIcon(QIcon(":/lock")); - } else { - for (QDockWidget *dockWidget : findChildren()) { - dockWidget->setFeatures(QDockWidget::AllDockWidgetFeatures); - } - ui->actionLockUnlock->setIcon(QIcon(":/unlock")); - } -} void MainWindow::on_actionDefault_triggered() { diff --git a/src/core/MainWindow.h b/src/core/MainWindow.h index b894b46c..c7bff79f 100644 --- a/src/core/MainWindow.h +++ b/src/core/MainWindow.h @@ -141,18 +141,13 @@ public slots: void refreshAll(); void seekToFunctionLastInstruction(); void seekToFunctionStart(); - void setPanelLock(); void setTabLocation(); - void on_actionLock_triggered(); - - void on_actionLockUnlock_triggered(); - void on_actionTabs_triggered(); void on_actionAnalyze_triggered(); - void lockUnlock_Docks(bool what); + void lockDocks(bool lock); void on_actionRun_Script_triggered(); @@ -220,7 +215,6 @@ private slots: private: CutterCore *core; - bool panelLock; bool tabsOnTop; ut64 hexdumpTopOffset; ut64 hexdumpBottomOffset; diff --git a/src/core/MainWindow.ui b/src/core/MainWindow.ui index 88afb259..223b3c88 100644 --- a/src/core/MainWindow.ui +++ b/src/core/MainWindow.ui @@ -105,12 +105,17 @@ + + + Layouts + + - + @@ -118,11 +123,6 @@ - - - Layouts - - @@ -137,7 +137,6 @@ Edit - @@ -353,7 +352,7 @@ Redo Seek - + true @@ -366,23 +365,12 @@ Toggle panel locks - - false - - - - - true - - :/unlock:/unlock + :/lock:/unlock:/unlock - - Lock/Unlock - - - Lock/Unlock + + false @@ -758,9 +746,9 @@ - - Add Decompiler - + + Add Decompiler + diff --git a/src/dialogs/XrefsDialog.cpp b/src/dialogs/XrefsDialog.cpp index f0aeb120..df5e566e 100644 --- a/src/dialogs/XrefsDialog.cpp +++ b/src/dialogs/XrefsDialog.cpp @@ -70,7 +70,7 @@ QString XrefsDialog::normalizeAddr(const QString &addr) const QString ret = addr; if (addr.length() < 10) { ret = ret.mid(3).rightJustified(8, QLatin1Char('0')); - ret.prepend(QLatin1Literal("0x")); + ret.prepend(QStringLiteral("0x")); } return ret; } diff --git a/src/menus/DisassemblyContextMenu.cpp b/src/menus/DisassemblyContextMenu.cpp index f5fc4da3..096fdf52 100644 --- a/src/menus/DisassemblyContextMenu.cpp +++ b/src/menus/DisassemblyContextMenu.cpp @@ -591,7 +591,7 @@ QKeySequence DisassemblyContextMenu::getCommentSequence() const QKeySequence DisassemblyContextMenu::getCopyAddressSequence() const { - return {Qt::CTRL + Qt::SHIFT + Qt::Key_C}; + return {Qt::CTRL | Qt::SHIFT | Qt::Key_C}; } QKeySequence DisassemblyContextMenu::getSetToCodeSequence() const @@ -606,7 +606,7 @@ QKeySequence DisassemblyContextMenu::getSetAsStringSequence() const QKeySequence DisassemblyContextMenu::getSetAsStringAdvanced() const { - return {Qt::SHIFT + Qt::Key_A}; + return {Qt::SHIFT | Qt::Key_A}; } QKeySequence DisassemblyContextMenu::getSetToDataSequence() const @@ -631,7 +631,7 @@ QKeySequence DisassemblyContextMenu::getRenameSequence() const QKeySequence DisassemblyContextMenu::getRenameUsedHereSequence() const { - return {Qt::SHIFT + Qt::Key_N}; + return {Qt::SHIFT | Qt::Key_N}; } QKeySequence DisassemblyContextMenu::getRetypeSequence() const diff --git a/src/widgets/CommentsWidget.cpp b/src/widgets/CommentsWidget.cpp index a2e6ec0b..3f7acac2 100644 --- a/src/widgets/CommentsWidget.cpp +++ b/src/widgets/CommentsWidget.cpp @@ -5,6 +5,7 @@ #include #include +#include CommentsModel::CommentsModel(QList *comments, QList *nestedComments, diff --git a/src/widgets/CutterGraphView.cpp b/src/widgets/CutterGraphView.cpp index b885eb18..07dd685b 100644 --- a/src/widgets/CutterGraphView.cpp +++ b/src/widgets/CutterGraphView.cpp @@ -8,6 +8,8 @@ #include #include +#include + static const int KEY_ZOOM_IN = Qt::Key_Plus + Qt::ControlModifier; static const int KEY_ZOOM_OUT = Qt::Key_Minus + Qt::ControlModifier; diff --git a/src/widgets/FunctionsWidget.cpp b/src/widgets/FunctionsWidget.cpp index 3a0ac842..000f60a8 100644 --- a/src/widgets/FunctionsWidget.cpp +++ b/src/widgets/FunctionsWidget.cpp @@ -16,6 +16,7 @@ #include #include #include +#include namespace { diff --git a/src/widgets/HexWidget.cpp b/src/widgets/HexWidget.cpp index 22e8fcfc..5d07b0be 100644 --- a/src/widgets/HexWidget.cpp +++ b/src/widgets/HexWidget.cpp @@ -20,6 +20,7 @@ #include #include #include +#include static constexpr uint64_t MAX_COPY_SIZE = 128 * 1024 * 1024; static constexpr int MAX_LINE_WIDTH_PRESET = 32; diff --git a/src/widgets/HexdumpWidget.ui b/src/widgets/HexdumpWidget.ui index d52550b5..1e55c14f 100644 --- a/src/widgets/HexdumpWidget.ui +++ b/src/widgets/HexdumpWidget.ui @@ -124,7 +124,7 @@ - QComboBox::AdjustToMinimumContentsLength + QComboBox::AdjustToContents @@ -201,7 +201,7 @@ - QComboBox::AdjustToMinimumContentsLength + QComboBox::AdjustToContents false @@ -224,7 +224,7 @@ - QComboBox::AdjustToMinimumContentsLength + QComboBox::AdjustToContents @@ -260,15 +260,15 @@ 13 - - true - QFrame::NoFrame 0 + + true +