Skip to content

Commit

Permalink
feat: Support both Qt5 and Qt6
Browse files Browse the repository at this point in the history
  • Loading branch information
Dax89 committed Sep 8, 2023
1 parent fc73e1c commit 5f1f9ec
Show file tree
Hide file tree
Showing 23 changed files with 206 additions and 130 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
61 changes: 34 additions & 27 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)

Expand All @@ -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
)
Expand All @@ -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 )
Expand Down Expand Up @@ -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}
Expand All @@ -105,7 +112,6 @@ SET(HEADERS
redasmfonts.h)

SET(SOURCES
${QHEXVIEW_SOURCES}
${REDASM_TEST_SOURCES}
${WIDGETS_SOURCES}
${DIALOGS_SOURCES}
Expand Down Expand Up @@ -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)

Expand All @@ -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
Expand All @@ -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})
Expand Down
2 changes: 1 addition & 1 deletion dialogs/devdialog/tabs/documenttab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion hooks/disassemblerhooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
17 changes: 17 additions & 0 deletions hooks/disassemblerhooks.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <QPushButton>
#include <QLabel>
#include <QFileInfo>
#include <QMenu>
#include <rdapi/rdapi.h>
#include "isurface.h"

Expand All @@ -26,6 +27,22 @@ class OutputWidget;
class DisassemblerDocks;
class DockWidget;

namespace REDasmCompat {

template<typename Slot>
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<typename Slot>
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
Expand Down
2 changes: 1 addition & 1 deletion libs/qhexview
Submodule qhexview updated 55 files
+55 −29 CMakeLists.txt
+33 −24 QHexView.pri
+49 −43 README.md
+343 −0 dialogs/hexfinddialog.cpp
+52 −0 dialogs/hexfinddialog.h
+0 −106 document/buffer/qfilebuffer.cpp
+0 −98 document/buffer/qmemoryrefbuffer.cpp
+0 −26 document/buffer/qmemoryrefbuffer.h
+0 −3 document/commands/hexcommand.cpp
+0 −10 document/commands/insertcommand.cpp
+0 −14 document/commands/insertcommand.h
+0 −15 document/commands/removecommand.cpp
+0 −14 document/commands/removecommand.h
+0 −15 document/commands/replacecommand.cpp
+0 −17 document/commands/replacecommand.h
+0 −135 document/qhexcursor.cpp
+0 −80 document/qhexcursor.h
+0 −213 document/qhexdocument.cpp
+0 −128 document/qhexdocument.h
+0 −160 document/qhexmetadata.cpp
+0 −72 document/qhexmetadata.h
+0 −502 document/qhexrenderer.cpp
+0 −76 document/qhexrenderer.h
+130 −0 model/buffer/qdevicebuffer.cpp
+8 −12 model/buffer/qdevicebuffer.h
+2 −3 model/buffer/qhexbuffer.cpp
+1 −5 model/buffer/qhexbuffer.h
+49 −0 model/buffer/qmappedfilebuffer.cpp
+22 −0 model/buffer/qmappedfilebuffer.h
+3 −2 model/buffer/qmemorybuffer.cpp
+2 −5 model/buffer/qmemorybuffer.h
+28 −0 model/buffer/qmemoryrefbuffer.cpp
+13 −0 model/buffer/qmemoryrefbuffer.h
+3 −0 model/commands/hexcommand.cpp
+5 −5 model/commands/hexcommand.h
+16 −0 model/commands/insertcommand.cpp
+11 −0 model/commands/insertcommand.h
+20 −0 model/commands/removecommand.cpp
+11 −0 model/commands/removecommand.h
+20 −0 model/commands/replacecommand.cpp
+14 −0 model/commands/replacecommand.h
+129 −0 model/qhexcursor.cpp
+69 −0 model/qhexcursor.h
+68 −0 model/qhexdelegate.cpp
+25 −0 model/qhexdelegate.h
+103 −0 model/qhexdocument.cpp
+91 −0 model/qhexdocument.h
+149 −0 model/qhexmetadata.cpp
+64 −0 model/qhexmetadata.h
+55 −0 model/qhexoptions.h
+320 −0 model/qhexutils.cpp
+49 −0 model/qhexutils.h
+1,028 −459 qhexview.cpp
+147 −42 qhexview.h
+ screenshots/QHexView.png
2 changes: 1 addition & 1 deletion models/dev/blocklistmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
4 changes: 2 additions & 2 deletions models/functionsmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions models/gotomodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion models/labelsmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
4 changes: 2 additions & 2 deletions models/referencesmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
4 changes: 2 additions & 2 deletions models/segmentsmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
4 changes: 2 additions & 2 deletions models/stringsmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions redasmfonts.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
2 changes: 1 addition & 1 deletion redasmsettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
Loading

0 comments on commit 5f1f9ec

Please sign in to comment.