From 5f1f9ec3ba8b20ca3da9e8053fb4f3781a69efd7 Mon Sep 17 00:00:00 2001 From: Dax Date: Fri, 8 Sep 2023 15:45:43 +0200 Subject: [PATCH] feat: Support both Qt5 and Qt6 --- .github/workflows/build.yml | 3 +- CMakeLists.txt | 61 +++++++++------- dialogs/devdialog/tabs/documenttab.cpp | 2 +- hooks/disassemblerhooks.cpp | 2 +- hooks/disassemblerhooks.h | 17 +++++ libs/qhexview | 2 +- models/dev/blocklistmodel.cpp | 2 +- models/functionsmodel.cpp | 4 +- models/gotomodel.cpp | 4 +- models/labelsmodel.cpp | 2 +- models/referencesmodel.cpp | 4 +- models/segmentsmodel.cpp | 4 +- models/stringsmodel.cpp | 4 +- redasmfonts.h | 8 +-- redasmsettings.cpp | 2 +- translations/redasm_en.ts | 62 ++++++++-------- widgets/callgraphview/callgraphitem.cpp | 7 +- widgets/dashboard/analysiswidget.cpp | 6 +- widgets/docks/splitdockwidget.cpp | 2 +- widgets/graphview/graphview.cpp | 71 +++++++++++++++---- widgets/graphview/graphview.h | 4 +- widgets/listing/listingpopup/listingpopup.cpp | 8 ++- widgets/listing/listingview.cpp | 55 +++++++------- 23 files changed, 206 insertions(+), 130 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index ff2f6d30..3e6264d8 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -12,11 +12,12 @@ jobs: steps: - uses: actions/checkout@v2 + - uses: jurplel/install-qt-action@v3.3.0 - name: Install dependencies run: | sudo apt-get update - sudo apt-get install -y build-essential gcc-10 g++-10 qt5-default libqt5x11extras5-dev cmake + sudo apt-get install -y build-essential gcc-10 g++-10 cmake sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-10 100 --slave /usr/bin/g++ g++ /usr/bin/g++-10 --slave /usr/bin/gcov gcov /usr/bin/gcov-10 git submodule update --init --recursive diff --git a/CMakeLists.txt b/CMakeLists.txt index 676114d6..23792b9e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,8 +2,6 @@ cmake_minimum_required(VERSION 3.12) project(REDasm) -set(_QT_VERSION_REQ 5.11) -set(QT_VERSION_REQ "${_QT_VERSION_REQ}") set(CMAKE_AUTOMOC ON) set(CMAKE_AUTOUIC ON) set(CMAKE_AUTORCC ON) @@ -12,12 +10,15 @@ include(${CMAKE_SOURCE_DIR}/LibREDasm/cmake/sanitizers.cmake) string(TIMESTAMP REDASM_BUILD_TIMESTAMP "%Y%m%d") set(REDASM_GIT_VERSION "unknown") -set(REDASM_VERSION_BASE "3.0-BETA6") +set(REDASM_VERSION_BASE "3.0-BETA7") find_package(Git) -find_package(Qt5 ${_QT_VERSION_REQ} REQUIRED COMPONENTS Widgets) -#find_package(Qt5X11Extras ${_QT_VERSION_REQ} REQUIRED) # Needed for KDDockWidgets -find_package(Qt5LinguistTools ${_QT_VERSION_REQ}) +find_package(Qt6 COMPONENTS Widgets) + +if(NOT Qt6_FOUND) + find_package(Qt5 REQUIRED COMPONENTS Widgets) + find_package(Qt5LinguistTools) +endif() include(LibREDasm/cmake/CPM.cmake) @@ -34,14 +35,21 @@ endif() set(REDASM_BUILD_VERSION "${REDASM_BUILD_TIMESTAMP}.${REDASM_GIT_VERSION}") add_definitions(-DREDASM_VERSION="${REDASM_VERSION_BASE} \(${REDASM_BUILD_VERSION}\)") -set(KDDOCKWIDGETS_OPTIONS "KDDockWidgets_STATIC ON" - "KDDockWidgets_EXAMPLES OFF" - "KDDockWidgets_UNITY_BUILD OFF") +if(Qt6_FOUND) + set(KDDOCKWIDGETS_OPTIONS "KDDockWidgets_QT6 ON" + "KDDockWidgets_STATIC ON" + "KDDockWidgets_EXAMPLES OFF" + "KDDockWidgets_UNITY_BUILD OFF") +else() + set(KDDOCKWIDGETS_OPTIONS "KDDockWidgets_STATIC ON" + "KDDockWidgets_EXAMPLES OFF" + "KDDockWidgets_UNITY_BUILD OFF") +endif() CPMAddPackage( - NAME KDDockWidgetes + NAME KDDockWidgets GIT_REPOSITORY https://github.com/KDAB/KDDockWidgets - VERSION 1.4.0 + VERSION 1.7.0 OPTIONS ${KDDOCKWIDGETS_OPTIONS} EXCLUDE_FROM_ALL ON ) @@ -56,7 +64,7 @@ add_subdirectory(submodules/plugins) add_subdirectory(submodules/assemblers) add_subdirectory(submodules/loaders) add_subdirectory(submodules/database) -qt5_wrap_ui(UI_HDRS ${UI_FILES}) +qt_wrap_ui(UI_HDRS ${UI_FILES}) # Widgets file(GLOB_RECURSE WIDGETS_HEADERS CONFIGURE_DEPENDS widgets/*.h ) @@ -90,7 +98,6 @@ file(GLOB_RECURSE UI_SOURCES CONFIGURE_DEPENDS ui/*.cpp) file(GLOB_RECURSE UI_UIS CONFIGURE_DEPENDS ui/*.ui) SET(HEADERS - ${QHEXVIEW_HEADERS} ${REDASM_TEST_HEADERS} ${WIDGETS_HEADERS} ${DIALOGS_HEADERS} @@ -105,7 +112,6 @@ SET(HEADERS redasmfonts.h) SET(SOURCES - ${QHEXVIEW_SOURCES} ${REDASM_TEST_SOURCES} ${WIDGETS_SOURCES} ${DIALOGS_SOURCES} @@ -135,20 +141,21 @@ endif() set(ALL_SOURCES ${SOURCES} ${HEADERS} ${FORMS}) -if(Qt5LinguistTools_FOUND) # Prepare translations +if(QtLinguistTools_FOUND) # Prepare translations message(STATUS "${PROJECT_NAME}: Adding multilanguage support") - qt5_create_translation(QM_FILES ${ALL_SOURCES} translations/redasm_en.ts) + qt_create_translation(QM_FILES ${ALL_SOURCES} translations/redasm_en.ts) configure_file(translations.qrc ${CMAKE_BINARY_DIR} COPYONLY) set(TRANSLATIONS_QRC ${CMAKE_BINARY_DIR}/translations.qrc) else() message(STATUS "${PROJECT_NAME}: Multilanguage support NOT available") endif() -add_executable(${PROJECT_NAME} ${GUI_TYPE} - ${ALL_SOURCES} ${RESOURCES} +add_executable(${PROJECT_NAME} ${GUI_TYPE} ${RESOURCES} ${TRANSLATIONS_QRC} ${QM_FILES} "${CMAKE_SOURCE_DIR}/res/windows/resources.rc") +target_sources(${PROJECT_NAME} PRIVATE ${ALL_SOURCES}) + target_compile_features(${PROJECT_NAME} PUBLIC cxx_std_17) set_target_properties(${PROJECT_NAME} PROPERTIES CXX_EXTENSIONS OFF) @@ -159,11 +166,11 @@ target_include_directories(${PROJECT_NAME} PRIVATE libs) target_link_libraries(${PROJECT_NAME} PRIVATE - Qt5::Core - Qt5::Gui - Qt5::Widgets + Qt::Core + Qt::Gui + Qt::Widgets KDAB::kddockwidgets - qhexview-lib + QHexView LibREDasm) # Include Threads @@ -181,16 +188,16 @@ set(REDASM_DEPLOY_DIR ${CMAKE_BINARY_DIR}/deploy) # Deploy Qt DLLs on Windows # https://stackoverflow.com/a/41199492/1806760 -if(Qt5_FOUND AND WIN32 AND TARGET Qt5::qmake AND NOT TARGET Qt5::windeployqt) - get_target_property(_qt5_qmake_location Qt5::qmake IMPORTED_LOCATION) +if(Qt_FOUND AND WIN32 AND TARGET Qt::qmake AND NOT TARGET Qt::windeployqt) + get_target_property(_qt_qmake_location Qt::qmake IMPORTED_LOCATION) execute_process( - COMMAND "${_qt5_qmake_location}" -query QT_INSTALL_PREFIX + COMMAND "${_qt_qmake_location}" -query QT_INSTALL_PREFIX RESULT_VARIABLE return_code - OUTPUT_VARIABLE qt5_install_prefix + OUTPUT_VARIABLE qt_install_prefix OUTPUT_STRIP_TRAILING_WHITESPACE) - set(_WINDEPLOYQT_EXECUTABLE "${qt5_install_prefix}/bin/windeployqt.exe") + set(_WINDEPLOYQT_EXECUTABLE "${qt_install_prefix}/bin/windeployqt.exe") if(EXISTS ${_WINDEPLOYQT_EXECUTABLE}) set(WINDEPLOYQT_EXECUTABLE ${_WINDEPLOYQT_EXECUTABLE}) diff --git a/dialogs/devdialog/tabs/documenttab.cpp b/dialogs/devdialog/tabs/documenttab.cpp index 2bf020ff..716aff5a 100644 --- a/dialogs/devdialog/tabs/documenttab.cpp +++ b/dialogs/devdialog/tabs/documenttab.cpp @@ -113,7 +113,7 @@ QString DocumentTab::padHexDump(const QString& hexdump) const for(int i = 0; i < hexdump.size(); i += 2) { if(!phexdump.isEmpty()) phexdump += " "; - phexdump += hexdump.midRef(i, 2); + phexdump += hexdump.mid(i, 2); } return phexdump; diff --git a/hooks/disassemblerhooks.cpp b/hooks/disassemblerhooks.cpp index a88e1b51..075dc383 100644 --- a/hooks/disassemblerhooks.cpp +++ b/hooks/disassemblerhooks.cpp @@ -422,7 +422,7 @@ void DisassemblerHooks::showDialog(const QString& title, QWidget* w) { QVBoxLayout* l = new QVBoxLayout(); l->setSpacing(0); - l->setMargin(0); + l->setContentsMargins(0, 0, 0, 0); l->addWidget(w); QDialog* dialog = new QDialog(); diff --git a/hooks/disassemblerhooks.h b/hooks/disassemblerhooks.h index d636e4d6..857db227 100644 --- a/hooks/disassemblerhooks.h +++ b/hooks/disassemblerhooks.h @@ -17,6 +17,7 @@ #include #include #include +#include #include #include "isurface.h" @@ -26,6 +27,22 @@ class OutputWidget; class DisassemblerDocks; class DockWidget; +namespace REDasmCompat { + +template +inline QAction* addAction(QMenu* m, const QString& text, const QObject* object, Slot slot, const QKeySequence& shortcut) { +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + return m->addAction(text, shortcut, object, slot); +#else + return m->addAction(text, object, slot, shortcut); +#endif +} + +template +inline QAction* addAction(QMenu* m, const QString& text, const QObject* object, Slot slot) { return m->addAction(text, object, slot); } + +} + class DisassemblerHooks: public QObject { Q_OBJECT diff --git a/libs/qhexview b/libs/qhexview index ce3ff28c..bc72cd22 160000 --- a/libs/qhexview +++ b/libs/qhexview @@ -1 +1 @@ -Subproject commit ce3ff28cc830e956c2f3f1a45e08bad6d8d4aa59 +Subproject commit bc72cd22267f752f6552b4f6e6c733649e54c4c2 diff --git a/models/dev/blocklistmodel.cpp b/models/dev/blocklistmodel.cpp index 29606866..3cd94d51 100644 --- a/models/dev/blocklistmodel.cpp +++ b/models/dev/blocklistmodel.cpp @@ -56,7 +56,7 @@ QVariant BlockListModel::data(const QModelIndex& index, int role) const if(index.column() == 3) return THEME_VALUE(Theme_Type); if(index.column() == 4) return THEME_VALUE(Theme_Label); } - else if(role == Qt::TextAlignmentRole) return (index.column() < 4) ? Qt::AlignCenter : (Qt::AlignLeft + Qt::AlignVCenter); + else if(role == Qt::TextAlignmentRole) return QVariant{(index.column() < 4) ? Qt::AlignCenter : (Qt::AlignLeft | Qt::AlignVCenter)}; return QVariant(); } diff --git a/models/functionsmodel.cpp b/models/functionsmodel.cpp index 47515423..94605555 100644 --- a/models/functionsmodel.cpp +++ b/models/functionsmodel.cpp @@ -26,8 +26,8 @@ QVariant FunctionsModel::data(const QModelIndex& index, int role) const } else if(role == Qt::TextAlignmentRole) { - if(index.column() == 0) return Qt::AlignRight + Qt::AlignVCenter; - if(index.column() == 1) return Qt::AlignLeft + Qt::AlignVCenter; + if(index.column() == 0) return QVariant{Qt::AlignRight | Qt::AlignVCenter}; + if(index.column() == 1) return QVariant{Qt::AlignLeft | Qt::AlignVCenter}; } else if((role == Qt::ForegroundRole) && (index.column() == 0)) return THEME_VALUE(Theme_Address); diff --git a/models/gotomodel.cpp b/models/gotomodel.cpp index 51b86bd1..73c1624c 100644 --- a/models/gotomodel.cpp +++ b/models/gotomodel.cpp @@ -28,8 +28,8 @@ QVariant GotoModel::data(const QModelIndex &index, int role) const } else if(role == Qt::TextAlignmentRole) { - if(index.column() == 0) return Qt::AlignRight + Qt::AlignVCenter; - if(index.column() == 1) return Qt::AlignLeft + Qt::AlignVCenter; + if(index.column() == 0) return QVariant{Qt::AlignRight | Qt::AlignVCenter}; + if(index.column() == 1) return QVariant{Qt::AlignLeft | Qt::AlignVCenter}; } else if((role == Qt::ForegroundRole) && (index.column() == 0)) return THEME_VALUE(Theme_Address); diff --git a/models/labelsmodel.cpp b/models/labelsmodel.cpp index 5b74a7cc..d369a731 100644 --- a/models/labelsmodel.cpp +++ b/models/labelsmodel.cpp @@ -62,7 +62,7 @@ QVariant LabelsModel::data(const QModelIndex& index, int role) const } } else if(role == Qt::ForegroundRole) return (index.column() == 0) ? THEME_VALUE(Theme_Address) : QVariant(); - else if(role == Qt::TextAlignmentRole) return (index.column() < 3) ? Qt::AlignCenter + Qt::AlignVCenter : Qt::AlignLeft + Qt::AlignVCenter; + else if(role == Qt::TextAlignmentRole) return QVariant{(index.column() < 3) ? (Qt::AlignCenter | Qt::AlignVCenter) : (Qt::AlignLeft | Qt::AlignVCenter)}; return QVariant(); } diff --git a/models/referencesmodel.cpp b/models/referencesmodel.cpp index b18a7083..a145f0c4 100644 --- a/models/referencesmodel.cpp +++ b/models/referencesmodel.cpp @@ -66,8 +66,8 @@ QVariant ReferencesModel::data(const QModelIndex &index, int role) const } else if(role == Qt::TextAlignmentRole) { - if(index.column() == 0) return Qt::AlignRight + Qt::AlignVCenter; - if(index.column() == 3) return Qt::AlignLeft + Qt::AlignVCenter; + if(index.column() == 0) return QVariant{Qt::AlignRight | Qt::AlignVCenter}; + if(index.column() == 3) return QVariant{Qt::AlignLeft | Qt::AlignVCenter}; return Qt::AlignCenter; } else if((role == Qt::ForegroundRole) && (index.column() == 0)) diff --git a/models/segmentsmodel.cpp b/models/segmentsmodel.cpp index 95d0dc7e..80205106 100644 --- a/models/segmentsmodel.cpp +++ b/models/segmentsmodel.cpp @@ -43,8 +43,8 @@ QVariant SegmentsModel::data(const QModelIndex &index, int role) const } else if(role == Qt::TextAlignmentRole) { - if(index.column() == 0) return Qt::AlignRight + Qt::AlignVCenter; - if(index.column() == 7) return Qt::AlignLeft + Qt::AlignVCenter; + if(index.column() == 0) return QVariant{Qt::AlignRight | Qt::AlignVCenter}; + if(index.column() == 7) return QVariant{Qt::AlignLeft | Qt::AlignVCenter}; return Qt::AlignCenter; } diff --git a/models/stringsmodel.cpp b/models/stringsmodel.cpp index 9e7f39ed..77228760 100644 --- a/models/stringsmodel.cpp +++ b/models/stringsmodel.cpp @@ -15,8 +15,8 @@ QVariant StringsModel::data(const QModelIndex& index, int role) const } else if(role == Qt::TextAlignmentRole) { - if(index.column() == 0) return Qt::AlignRight + Qt::AlignVCenter; - if(index.column() == 2) return Qt::AlignLeft + Qt::AlignVCenter; + if(index.column() == 0) return QVariant{Qt::AlignRight | Qt::AlignVCenter}; + if(index.column() == 2) return QVariant{Qt::AlignLeft | Qt::AlignVCenter}; return Qt::AlignCenter; } else if(role == Qt::ForegroundRole) diff --git a/redasmfonts.h b/redasmfonts.h index 107b89aa..ee413bc8 100644 --- a/redasmfonts.h +++ b/redasmfonts.h @@ -42,7 +42,7 @@ class REDasmFonts #define FA_FONT REDasmFonts::instance()->faFont() #define FAB_FONT REDasmFonts::instance()->faBrandsFont() -#define FA_ICON(code) REDasmFonts::instance()->icon(code) -#define FA_ICON_COLOR(code, color) REDasmFonts::instance()->icon(code, color) -#define FAB_ICON(code) REDasmFonts::instance()->brand(code) -#define FAB_ICON_COLOR(code, color) REDasmFonts::instance()->brand(code, color) +#define FA_ICON(code) REDasmFonts::instance()->icon(QChar{code}) +#define FA_ICON_COLOR(code, color) REDasmFonts::instance()->icon(QChar{code}, color) +#define FAB_ICON(code) REDasmFonts::instance()->brand(QChar{code}) +#define FAB_ICON_COLOR(code, color) REDasmFonts::instance()->brand(QChar{code}, color) diff --git a/redasmsettings.cpp b/redasmsettings.cpp index 31c92c39..959597cf 100644 --- a/redasmsettings.cpp +++ b/redasmsettings.cpp @@ -58,7 +58,7 @@ int REDasmSettings::currentFontSize() const int size = qApp->font().pixelSize(); if(size == -1) - size = qApp->fontMetrics().height(); + size = QFontMetrics{qApp->font()}.height(); return this->value("selected_font_size", size).toInt(); } diff --git a/translations/redasm_en.ts b/translations/redasm_en.ts index bd52af47..9a1c79d5 100644 --- a/translations/redasm_en.ts +++ b/translations/redasm_en.ts @@ -586,153 +586,153 @@ - + Create Function @ %1 - + Hex Dump %1 - + Cross Reference %1 - + Rename %1 - + Callgraph - + Follow %1 - + Rename - + Rename @ %1 - + Symbol name: - + Comment @ %1 - + Insert a comment (leave blank to remove): - + Cross References - + Follow - + Hex Dump - + Goto... - + Call Graph - + Switch View - + Show Hex Dump - + Hex Dump Function - + Create Function - + Cannot create function @ %1 - + Back - + Forward - - + + Copy - + No References - + There are no references to %1 - + Copy Hex - + Copy Ascii - + Select All - + Switch to Listing diff --git a/widgets/callgraphview/callgraphitem.cpp b/widgets/callgraphview/callgraphitem.cpp index 86d3984c..a934c024 100644 --- a/widgets/callgraphview/callgraphitem.cpp +++ b/widgets/callgraphview/callgraphitem.cpp @@ -20,8 +20,13 @@ CallGraphItem::CallGraphItem(const RDContextPtr& ctx, RDGraphNode node, const RD else m_label = "???"; - auto fm = qApp->fontMetrics(); + QFontMetrics fm{qApp->font()}; + +#if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0) + m_size = { fm.horizontalAdvance(m_label) + (BLOCK_MARGIN * 2), fm.height() * 2 }; +#else m_size = { fm.width(m_label) + (BLOCK_MARGIN * 2), fm.height() * 2 }; +#endif } void CallGraphItem::render(QPainter* painter, size_t state) diff --git a/widgets/dashboard/analysiswidget.cpp b/widgets/dashboard/analysiswidget.cpp index 4e1c6669..c3d749f7 100644 --- a/widgets/dashboard/analysiswidget.cpp +++ b/widgets/dashboard/analysiswidget.cpp @@ -89,13 +89,13 @@ void AnalysisWidget::updateModel(QStandardItemModel* model, const char* const* n void AnalysisWidget::updateStats(const RDAnalysisStatus* s) { - m_statsmodel->item(0, 1)->setText(QDateTime::fromTime_t(static_cast(s->analysisstart)).toString()); + m_statsmodel->item(0, 1)->setText(QDateTime::fromSecsSinceEpoch(static_cast(s->analysisstart)).toString()); auto *item = m_statsmodel->item(1, 1), *timeitem = m_statsmodel->item(2, 1); if(s->analysisend) { - QDateTime start = QDateTime::fromTime_t(static_cast(s->analysisstart)); - QDateTime end = QDateTime::fromTime_t(static_cast(s->analysisend)); + QDateTime start = QDateTime::fromSecsSinceEpoch(static_cast(s->analysisstart)); + QDateTime end = QDateTime::fromSecsSinceEpoch(static_cast(s->analysisend)); item->setText(end.toString()); timeitem->setText(AnalysisWidget::printableDateDiff(start, end)); diff --git a/widgets/docks/splitdockwidget.cpp b/widgets/docks/splitdockwidget.cpp index 45c69452..6a6de950 100644 --- a/widgets/docks/splitdockwidget.cpp +++ b/widgets/docks/splitdockwidget.cpp @@ -15,7 +15,7 @@ SplitDockWidget::SplitDockWidget(QWidget* w, Options opt, LayoutSaverOptions lsp auto* lcontent = new QVBoxLayout(); lcontent->setSpacing(0); - lcontent->setMargin(0); + lcontent->setContentsMargins(0, 0, 0, 0); lcontent->addWidget(m_tbactions); lcontent->addWidget(w); diff --git a/widgets/graphview/graphview.cpp b/widgets/graphview/graphview.cpp index efbfb761..4c33fcb1 100644 --- a/widgets/graphview/graphview.cpp +++ b/widgets/graphview/graphview.cpp @@ -5,6 +5,7 @@ #include #include #include +#include GraphView::GraphView(QWidget *parent): QAbstractScrollArea(parent) { @@ -74,10 +75,18 @@ void GraphView::focusBlock(const GraphViewItem *item, bool force) void GraphView::mouseDoubleClickEvent(QMouseEvent* e) { - bool updated = this->updateSelectedItem(e); + QPoint itempos; + bool updated = this->updateSelectedItem(e, &itempos); if(m_selecteditem && (e->buttons() == Qt::LeftButton)) - m_selecteditem->mouseDoubleClickEvent(e); + { +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + QMouseEvent iteme{e->type(), itempos, e->globalPosition(), e->button(), e->buttons(), e->modifiers()}; +#else + QMouseEvent iteme{e->type(), itempos, e->globalPos(), e->button(), e->buttons(), e->modifiers()}; +#endif + m_selecteditem->mouseDoubleClickEvent(&iteme); + } if(updated) this->selectedItemChangedEvent(); QAbstractScrollArea::mouseDoubleClickEvent(e); @@ -85,10 +94,18 @@ void GraphView::mouseDoubleClickEvent(QMouseEvent* e) void GraphView::mousePressEvent(QMouseEvent *e) { - bool updated = this->updateSelectedItem(e); + QPoint itempos; + bool updated = this->updateSelectedItem(e, &itempos); if(m_selecteditem) - m_selecteditem->mousePressEvent(e); + { +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + QMouseEvent iteme{e->type(), itempos, e->globalPosition(), e->button(), e->buttons(), e->modifiers()}; +#else + QMouseEvent iteme{e->type(), itempos, e->globalPos(), e->button(), e->buttons(), e->modifiers()}; +#endif + m_selecteditem->mousePressEvent(&iteme); + } else if(e->button() == Qt::LeftButton) { m_scrollmode = true; @@ -120,17 +137,31 @@ void GraphView::mouseMoveEvent(QMouseEvent *e) { if(m_selecteditem) { - GraphViewItem* item = this->itemFromMouseEvent(e); + QPoint itempos; + GraphViewItem* item = this->itemFromMouseEvent(e, &itempos); if(item == m_selecteditem) - m_selecteditem->mouseMoveEvent(e); + { +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + QMouseEvent iteme{e->type(), itempos, e->globalPosition(), e->button(), e->buttons(), e->modifiers()}; +#else + QMouseEvent iteme{e->type(), itempos, e->globalPos(), e->button(), e->buttons(), e->modifiers()}; +#endif + m_selecteditem->mouseMoveEvent(&iteme); + } return; } if(m_scrollmode) { - QPoint delta(m_scrollbase.x() - e->x(), m_scrollbase.y() - e->y()); + +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + QPoint delta{m_scrollbase.x() - e->position().x(), m_scrollbase.y() - e->position().y()}; +#else + QPoint delta{m_scrollbase.x() - e->pos().x(), m_scrollbase.y() - e->pos().y()}; +#endif + m_scrollbase = e->pos(); this->horizontalScrollBar()->setValue(this->horizontalScrollBar()->value() + delta.x()); @@ -152,12 +183,12 @@ void GraphView::wheelEvent(QWheelEvent *event) if(nsteps.y() > 0) { m_scaledirection = 1; - this->zoomIn(event->pos()); + this->zoomIn(event->position()); } else if(nsteps.y() < 0) { m_scaledirection = -1; - this->zoomOut(event->pos()); + this->zoomOut(event->position()); } event->accept(); @@ -310,19 +341,29 @@ void GraphView::updateGraph() this->computed(); } -GraphViewItem *GraphView::itemFromMouseEvent(QMouseEvent *e) const +GraphViewItem *GraphView::itemFromMouseEvent(QMouseEvent* e, QPoint* itempos) const { // Convert coordinates to system used in blocks int xofs = this->horizontalScrollBar()->value(); int yofs = this->verticalScrollBar()->value(); - QPoint pos = { static_cast(std::floor((e->x() + xofs - m_renderoffset.x()) / m_scalefactor)), - static_cast(std::floor((e->y() + yofs - m_renderoffset.y()) / m_scalefactor)) }; + +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + QPoint pos = { + static_cast(std::floor((e->position().x() + xofs - m_renderoffset.x()) / m_scalefactor)), + static_cast(std::floor((e->position().y() + yofs - m_renderoffset.y()) / m_scalefactor)) + }; +#else + QPoint pos = { + static_cast(std::floor((e->pos().x() + xofs - m_renderoffset.x()) / m_scalefactor)), + static_cast(std::floor((e->pos().y() + yofs - m_renderoffset.y()) / m_scalefactor)) + }; +#endif for(GraphViewItem* item : m_items) { if(!item->contains(pos)) continue; - e->setLocalPos(item->mapToItem(pos)); + if(itempos) *itempos = item->mapToItem(pos); return item; } @@ -432,10 +473,10 @@ void GraphView::precomputeLine(const RDGraphEdge& e) m_lines[e] = lines; } -bool GraphView::updateSelectedItem(QMouseEvent *e) +bool GraphView::updateSelectedItem(QMouseEvent* e, QPoint* itempos) { GraphViewItem* olditem = m_selecteditem; - m_selecteditem = this->itemFromMouseEvent(e); + m_selecteditem = this->itemFromMouseEvent(e, itempos); if(olditem) { diff --git a/widgets/graphview/graphview.h b/widgets/graphview/graphview.h index b4604848..a521ed71 100644 --- a/widgets/graphview/graphview.h +++ b/widgets/graphview/graphview.h @@ -48,13 +48,13 @@ class GraphView : public QAbstractScrollArea virtual void computed(); private: - GraphViewItem* itemFromMouseEvent(QMouseEvent *e) const; + GraphViewItem* itemFromMouseEvent(QMouseEvent *e, QPoint* itempos = nullptr) const; void zoomOut(const QPointF& cursorpos); void zoomIn(const QPointF& cursorpos); void adjustSize(int vpw, int vph, const QPointF& cursorpos = QPoint(), bool fit = false); void precomputeArrow(const RDGraphEdge& e); void precomputeLine(const RDGraphEdge& e); - bool updateSelectedItem(QMouseEvent* e); + bool updateSelectedItem(QMouseEvent* e, QPoint* itempos = nullptr); Q_SIGNALS: void selectedItemChanged(); diff --git a/widgets/listing/listingpopup/listingpopup.cpp b/widgets/listing/listingpopup/listingpopup.cpp index 66a2490b..ebc72b41 100644 --- a/widgets/listing/listingpopup/listingpopup.cpp +++ b/widgets/listing/listingpopup/listingpopup.cpp @@ -8,7 +8,7 @@ ListingPopup::ListingPopup(const RDContextPtr& ctx, QWidget *parent): QWidget(pa m_popupview = new ListingPopupView(ctx, this); QVBoxLayout* vboxlayout = new QVBoxLayout(this); - vboxlayout->setMargin(POPUP_MARGIN); + vboxlayout->setContentsMargins(POPUP_MARGIN, POPUP_MARGIN, POPUP_MARGIN, POPUP_MARGIN); vboxlayout->addWidget(m_popupview); this->setLayout(vboxlayout); @@ -37,7 +37,11 @@ void ListingPopup::popup(rd_address address) void ListingPopup::mouseMoveEvent(QMouseEvent* event) { +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + if(m_lastpos != event->globalPosition()) +#else if(m_lastpos != event->globalPos()) +#endif { this->hide(); event->accept(); @@ -48,7 +52,7 @@ void ListingPopup::mouseMoveEvent(QMouseEvent* event) void ListingPopup::wheelEvent(QWheelEvent* event) { - m_lastpos = event->globalPos(); + m_lastpos = event->globalPosition(); QPoint delta = event->angleDelta(); if(delta.y() > 0) m_popupview->lessRows(); diff --git a/widgets/listing/listingview.cpp b/widgets/listing/listingview.cpp index 4ef13ee1..c7919152 100644 --- a/widgets/listing/listingview.cpp +++ b/widgets/listing/listingview.cpp @@ -3,8 +3,8 @@ #include "../../dialogs/gotodialog/gotodialog.h" #include "../../hooks/disassemblerhooks.h" #include "../../redasmsettings.h" -#include -#include +#include +#include #include #include #include @@ -55,8 +55,8 @@ rd_address ListingView::currentAddress() const if(this->currentWidget() == m_hexview) { - return m_hexview->document()->baseAddress() + - m_hexview->document()->cursor()->position().offset(); + return m_hexview->baseAddress() + + m_hexview->offset(); } return RD_NVAL; @@ -106,8 +106,8 @@ void ListingView::switchToHex() m_hexview->setDocument(QHexDocument::fromMemory(reinterpret_cast(segmentview.data), static_cast(segmentview.size), m_hexview)); - m_hexview->document()->setBaseAddress(segment.address); - m_hexview->document()->cursor()->selectOffset(loc.offset - segment.offset, view.size); + m_hexview->setBaseAddress(segment.address); + m_hexview->hexCursor()->select(loc.offset - segment.offset, view.size); this->setCurrentWidget(m_hexview); Q_EMIT historyChanged(); @@ -236,7 +236,7 @@ QMenu* ListingView::createActions(ISurface* surface) QMenu* contextmenu = new QMenu(surface->widget()); std::unordered_map actions; - actions[ListingView::Action_Rename] = contextmenu->addAction(tr("Rename"), this, [&, surface]() { + actions[ListingView::Action_Rename] = REDasmCompat::addAction(contextmenu, tr("Rename"), this, [&, surface]() { rd_address address; if(surface->currentLabel(&address).isEmpty()) return; @@ -253,7 +253,7 @@ QMenu* ListingView::createActions(ISurface* surface) RDDocument_UpdateLabel(doc, address, qUtf8Printable(res)); }, QKeySequence(Qt::Key_N)); - actions[ListingView::Action_Comment] = contextmenu->addAction("Comment", this, [&, surface]() { + actions[ListingView::Action_Comment] = REDasmCompat::addAction(contextmenu, "Comment", this, [&, surface]() { rd_address address = surface->currentAddress(); if(address == RD_NVAL) return; @@ -271,36 +271,36 @@ QMenu* ListingView::createActions(ISurface* surface) contextmenu->addSeparator(); - actions[ListingView::Action_XRefs] = contextmenu->addAction(tr("Cross References"), this, [&, surface]() { + actions[ListingView::Action_XRefs] = REDasmCompat::addAction(contextmenu, tr("Cross References"), this, [&, surface]() { rd_address address; if(surface->currentLabel(&address).size()) this->showReferences(address); }, QKeySequence(Qt::Key_X)); - actions[ListingView::Action_Follow] = contextmenu->addAction(tr("Follow"), this, [surface]() { + actions[ListingView::Action_Follow] = REDasmCompat::addAction(contextmenu, tr("Follow"), this, [surface]() { rd_address address; if(surface->currentLabel(&address).size()) surface->goTo(address); }); - actions[ListingView::Action_ShowHexDump] = contextmenu->addAction(tr("Hex Dump"), this, [&, surface]() { + actions[ListingView::Action_ShowHexDump] = REDasmCompat::addAction(contextmenu, tr("Hex Dump"), this, [&, surface]() { rd_address address; if(!surface->currentLabel(&address).size()) return; surface->goTo(address); this->switchToHex(); }); - actions[ListingView::Action_Goto] = contextmenu->addAction(tr("Goto..."), this, [&]() { this->showGoto(); }, QKeySequence(Qt::Key_G)); + actions[ListingView::Action_Goto] = REDasmCompat::addAction(contextmenu, tr("Goto..."), this, [&]() { this->showGoto(); }, QKeySequence(Qt::Key_G)); - actions[ListingView::Action_CallGraph] = contextmenu->addAction(tr("Call Graph"), this, [&, surface]() { + actions[ListingView::Action_CallGraph] = REDasmCompat::addAction(contextmenu, tr("Call Graph"), this, [&, surface]() { rd_address address = surface->currentAddress(); if(address != RD_NVAL) DisassemblerHooks::instance()->showCallGraph(address); - }, QKeySequence(Qt::CTRL + Qt::Key_G)); + }, QKeySequence(Qt::CTRL | Qt::Key_G)); contextmenu->addSeparator(); - actions[ListingView::Action_SwitchView] = contextmenu->addAction(tr("Switch View"), this, [&]() { this->switchMode(); }); - actions[ListingView::Action_HexDump] = contextmenu->addAction(tr("Show Hex Dump"), this, [&]() { this->switchToHex(); }, QKeySequence(Qt::CTRL + Qt::Key_X)); + actions[ListingView::Action_SwitchView] = REDasmCompat::addAction(contextmenu, tr("Switch View"), this, [&]() { this->switchMode(); }); + actions[ListingView::Action_HexDump] = REDasmCompat::addAction(contextmenu, tr("Show Hex Dump"), this, [&]() { this->switchToHex(); }, QKeySequence(Qt::CTRL | Qt::Key_X)); - actions[ListingView::Action_HexDumpFunction] = contextmenu->addAction(tr("Hex Dump Function"), this, [&, surface]() { + actions[ListingView::Action_HexDumpFunction] = REDasmCompat::addAction(contextmenu, tr("Hex Dump Function"), this, [&, surface]() { rd_address address = surface->currentAddress(); if(address == RD_NVAL) return; @@ -312,7 +312,7 @@ QMenu* ListingView::createActions(ISurface* surface) RD_Log(qUtf8Printable(QString("%1: %2").arg(RDDocument_GetLabel(doc, resaddress), hexdump))); }); - actions[ListingView::Action_CreateFunction] = contextmenu->addAction(tr("Create Function"), this, [&, surface]() { + actions[ListingView::Action_CreateFunction] = REDasmCompat::addAction(contextmenu, tr("Create Function"), this, [&, surface]() { rd_address address; if(surface->currentLabel(&address).isEmpty()) { @@ -324,13 +324,13 @@ QMenu* ListingView::createActions(ISurface* surface) RDDocument* doc = RDContext_GetDocument(surface->context().get()); RDDocument_CreateFunction(doc, address, nullptr); }); - }, QKeySequence(Qt::SHIFT + Qt::Key_C)); + }, QKeySequence(Qt::SHIFT | Qt::Key_C)); contextmenu->addSeparator(); - actions[ListingView::Action_Back] = contextmenu->addAction(tr("Back"), this, [surface]() { surface->goBack(); }, QKeySequence(Qt::CTRL + Qt::Key_Left)); - actions[ListingView::Action_Forward] = contextmenu->addAction(tr("Forward"), this, [surface]() { surface->goForward(); }, QKeySequence(Qt::CTRL + Qt::Key_Right)); + actions[ListingView::Action_Back] = REDasmCompat::addAction(contextmenu, tr("Back"), this, [surface]() { surface->goBack(); }, QKeySequence(Qt::CTRL | Qt::Key_Left)); + actions[ListingView::Action_Forward] = REDasmCompat::addAction(contextmenu, tr("Forward"), this, [surface]() { surface->goForward(); }, QKeySequence(Qt::CTRL | Qt::Key_Right)); contextmenu->addSeparator(); - actions[ListingView::Action_Copy] = contextmenu->addAction(tr("Copy"), this, [surface]() { surface->copy(); }, QKeySequence(QKeySequence::Copy)); + actions[ListingView::Action_Copy] = REDasmCompat::addAction(contextmenu, tr("Copy"), this, [surface]() { surface->copy(); }, QKeySequence(QKeySequence::Copy)); for(auto& [type, action] : actions) { @@ -378,13 +378,14 @@ void ListingView::showReferences(rd_address address) void ListingView::createHexViewMenu() { m_menu = new QMenu(m_hexview); - m_menu->addAction(tr("Copy"), this, [&]() { m_hexview->document()->copy(); }, QKeySequence(Qt::CTRL + Qt::Key_C)); - m_menu->addAction(tr("Copy Hex"), this, [&]() { m_hexview->document()->copy(true); }, QKeySequence(Qt::CTRL + Qt::ALT + Qt::Key_C)); - m_menu->addAction(tr("Copy Ascii"), this, [&]() { m_hexview->document()->copy(); }, QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_C)); - m_menu->addAction(tr("Select All"), this, [&]() { }, QKeySequence(Qt::CTRL + Qt::Key_A)); + + REDasmCompat::addAction(m_menu, tr("Copy"), this, [&]() { m_hexview->copy(); }, QKeySequence(Qt::CTRL | Qt::Key_C)); + REDasmCompat::addAction(m_menu, tr("Copy Hex"), this, [&]() { m_hexview->copy(true); }, QKeySequence(Qt::CTRL | Qt::ALT | Qt::Key_C)); + REDasmCompat::addAction(m_menu, tr("Copy Ascii"), this, [&]() { m_hexview->copy(); }, QKeySequence(Qt::CTRL | Qt::SHIFT | Qt::Key_C)); + REDasmCompat::addAction(m_menu, tr("Select All"), this, [&]() { }, QKeySequence(Qt::CTRL | Qt::Key_A)); m_menu->addSeparator(); - m_menu->addAction(tr("Switch to Listing"), this, [&]() { + REDasmCompat::addAction(m_menu, tr("Switch to Listing"), this, [&]() { this->switchToListing(); }, QKeySequence(Qt::Key_Space));