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
This commit is contained in:
karliss 2020-11-30 09:42:13 +02:00 committed by GitHub
parent ef9b1328f4
commit f9bde4a2ff
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 66 additions and 93 deletions

View File

@ -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_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_R2GHIDRA "Compile and install r2ghidra during install step." OFF)
option(CUTTER_PACKAGE_R2DEC "Compile and install r2dec 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) if(NOT CUTTER_ENABLE_PYTHON)
set(CUTTER_ENABLE_PYTHON_BINDINGS OFF) set(CUTTER_ENABLE_PYTHON_BINDINGS OFF)
@ -55,7 +56,12 @@ set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOMOC ON) set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON) set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTORCC 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) include(CutterInstallDirs)
@ -219,7 +225,7 @@ if(CUTTER_ENABLE_CRASH_REPORTS)
endif() endif()
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}) target_link_libraries(Cutter PUBLIC ${RADARE2_TARGET})
if(CUTTER_ENABLE_PYTHON) if(CUTTER_ENABLE_PYTHON)
if (WIN32) if (WIN32)

View File

@ -47,7 +47,12 @@ void RichTextPainter::paintRichText(QPainter *painter, T x, T y, T w, T h, T xin
painter->setPen(pen); painter->setPen(pen);
break; break;
} }
painter->drawText(typename Metrics<T>::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<T>::Rect(x + xinc, y, w - xinc, h), flags, curRichText.text);
if (curRichText.highlight && curRichText.highlightColor.alpha()) { if (curRichText.highlight && curRichText.highlightColor.alpha()) {
highlightPen.setColor(curRichText.highlightColor); highlightPen.setColor(curRichText.highlightColor);
highlightPen.setWidth(curRichText.highlightWidth); highlightPen.setWidth(curRichText.highlightWidth);

View File

@ -165,8 +165,11 @@ static void cutterREventCallback(REvent *, int type, void *user, void *data)
core->handleREvent(type, data); core->handleREvent(type, data);
} }
CutterCore::CutterCore(QObject *parent) : CutterCore::CutterCore(QObject *parent):
QObject(parent), coreMutex(QMutex::Recursive) QObject(parent)
#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0)
, coreMutex(QMutex::Recursive)
#endif
{ {
} }

View File

@ -715,7 +715,11 @@ private:
* NEVER use this directly! Always use the CORE_LOCK(); macro and access it like core->... * NEVER use this directly! Always use the CORE_LOCK(); macro and access it like core->...
*/ */
RCore *core_ = nullptr; RCore *core_ = nullptr;
#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0)
QMutex coreMutex; QMutex coreMutex;
#else
QRecursiveMutex coreMutex;
#endif
int coreLockDepth = 0; int coreLockDepth = 0;
void *coreBed = nullptr; void *coreBed = nullptr;

View File

@ -74,6 +74,7 @@
#include "widgets/CallGraph.h" #include "widgets/CallGraph.h"
// Qt Headers // Qt Headers
#include <QActionGroup>
#include <QApplication> #include <QApplication>
#include <QComboBox> #include <QComboBox>
#include <QCompleter> #include <QCompleter>
@ -124,7 +125,6 @@ MainWindow::MainWindow(QWidget *parent) :
core(Core()), core(Core()),
ui(new Ui::MainWindow) ui(new Ui::MainWindow)
{ {
panelLock = false;
tabsOnTop = false; tabsOnTop = false;
configuration = Config(); configuration = Config();
@ -256,6 +256,8 @@ void MainWindow::initUI()
ui->menuPlugins->setEnabled(false); ui->menuPlugins->setEnabled(false);
} }
connect(ui->actionUnlock, &QAction::toggled, this, [this](bool unlock){ lockDocks(!unlock); });
#if QT_VERSION < QT_VERSION_CHECK(5, 7, 0) #if QT_VERSION < QT_VERSION_CHECK(5, 7, 0)
ui->actionGrouped_dock_dragging->setVisible(false); ui->actionGrouped_dock_dragging->setVisible(false);
#endif #endif
@ -745,8 +747,7 @@ void MainWindow::readSettings()
QSettings settings; QSettings settings;
responsive = settings.value("responsive").toBool(); responsive = settings.value("responsive").toBool();
panelLock = settings.value("panelLock").toBool(); lockDocks(settings.value("panelLock").toBool());
setPanelLock();
tabsOnTop = settings.value("tabsOnTop").toBool(); tabsOnTop = settings.value("tabsOnTop").toBool();
setTabLocation(); setTabLocation();
bool dockGroupedDragging = settings.value("docksGroupedDragging", false).toBool(); bool dockGroupedDragging = settings.value("docksGroupedDragging", false).toBool();
@ -760,7 +761,7 @@ void MainWindow::saveSettings()
{ {
QSettings settings; QSettings settings;
settings.setValue("panelLock", panelLock); settings.setValue("panelLock", !ui->actionUnlock->isChecked());
settings.setValue("tabsOnTop", tabsOnTop); settings.setValue("tabsOnTop", tabsOnTop);
settings.setValue("docksGroupedDragging", ui->actionGrouped_dock_dragging->isChecked()); settings.setValue("docksGroupedDragging", ui->actionGrouped_dock_dragging->isChecked());
settings.setValue("geometry", saveGeometry()); settings.setValue("geometry", saveGeometry());
@ -769,24 +770,6 @@ void MainWindow::saveSettings()
saveLayouts(settings); saveLayouts(settings);
} }
void MainWindow::setPanelLock()
{
if (panelLock) {
for (QDockWidget *dockWidget : findChildren<QDockWidget *>()) {
dockWidget->setFeatures(QDockWidget::NoDockWidgetFeatures);
}
ui->actionLock->setChecked(false);
} else {
for (QDockWidget *dockWidget : findChildren<QDockWidget *>()) {
dockWidget->setFeatures(QDockWidget::AllDockWidgetFeatures);
}
ui->actionLock->setChecked(true);
}
}
void MainWindow::setTabLocation() void MainWindow::setTabLocation()
{ {
if (tabsOnTop) { if (tabsOnTop) {
@ -803,15 +786,20 @@ void MainWindow::refreshAll()
core->triggerRefreshAll(); 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<QDockWidget *>()) { for (QDockWidget *dockWidget : findChildren<QDockWidget *>()) {
dockWidget->setFeatures(QDockWidget::NoDockWidgetFeatures); dockWidget->setFeatures(QDockWidget::NoDockWidgetFeatures);
} }
} else { } else {
for (QDockWidget *dockWidget : findChildren<QDockWidget *>()) { for (QDockWidget *dockWidget : findChildren<QDockWidget *>()) {
dockWidget->setFeatures(QDockWidget::AllDockWidgetFeatures); dockWidget->setFeatures(QDockWidget::DockWidgetClosable |
QDockWidget::DockWidgetMovable |
QDockWidget::DockWidgetFloatable);
} }
} }
@ -1452,26 +1440,6 @@ void MainWindow::saveLayouts(QSettings &settings)
settings.endArray(); settings.endArray();
} }
void MainWindow::on_actionLock_triggered()
{
panelLock = !panelLock;
setPanelLock();
}
void MainWindow::on_actionLockUnlock_triggered()
{
if (ui->actionLockUnlock->isChecked()) {
for (QDockWidget *dockWidget : findChildren<QDockWidget *>()) {
dockWidget->setFeatures(QDockWidget::NoDockWidgetFeatures);
}
ui->actionLockUnlock->setIcon(QIcon(":/lock"));
} else {
for (QDockWidget *dockWidget : findChildren<QDockWidget *>()) {
dockWidget->setFeatures(QDockWidget::AllDockWidgetFeatures);
}
ui->actionLockUnlock->setIcon(QIcon(":/unlock"));
}
}
void MainWindow::on_actionDefault_triggered() void MainWindow::on_actionDefault_triggered()
{ {

View File

@ -141,18 +141,13 @@ public slots:
void refreshAll(); void refreshAll();
void seekToFunctionLastInstruction(); void seekToFunctionLastInstruction();
void seekToFunctionStart(); void seekToFunctionStart();
void setPanelLock();
void setTabLocation(); void setTabLocation();
void on_actionLock_triggered();
void on_actionLockUnlock_triggered();
void on_actionTabs_triggered(); void on_actionTabs_triggered();
void on_actionAnalyze_triggered(); void on_actionAnalyze_triggered();
void lockUnlock_Docks(bool what); void lockDocks(bool lock);
void on_actionRun_Script_triggered(); void on_actionRun_Script_triggered();
@ -220,7 +215,6 @@ private slots:
private: private:
CutterCore *core; CutterCore *core;
bool panelLock;
bool tabsOnTop; bool tabsOnTop;
ut64 hexdumpTopOffset; ut64 hexdumpTopOffset;
ut64 hexdumpBottomOffset; ut64 hexdumpBottomOffset;

View File

@ -105,12 +105,17 @@
<addaction name="separator"/> <addaction name="separator"/>
<addaction name="actionZoomReset"/> <addaction name="actionZoomReset"/>
</widget> </widget>
<widget class="QMenu" name="menuLayouts">
<property name="title">
<string>Layouts</string>
</property>
</widget>
<addaction name="actionRefresh_contents"/> <addaction name="actionRefresh_contents"/>
<addaction name="separator"/> <addaction name="separator"/>
<addaction name="actionDefault"/> <addaction name="actionDefault"/>
<addaction name="actionReset_settings"/> <addaction name="actionReset_settings"/>
<addaction name="separator"/> <addaction name="separator"/>
<addaction name="actionLock"/> <addaction name="actionUnlock"/>
<addaction name="actionTabs_on_Top"/> <addaction name="actionTabs_on_Top"/>
<addaction name="actionGrouped_dock_dragging"/> <addaction name="actionGrouped_dock_dragging"/>
<addaction name="separator"/> <addaction name="separator"/>
@ -118,11 +123,6 @@
<addaction name="separator"/> <addaction name="separator"/>
<addaction name="actionManageLayouts"/> <addaction name="actionManageLayouts"/>
<addaction name="actionSaveLayout"/> <addaction name="actionSaveLayout"/>
<widget class="QMenu" name="menuLayouts">
<property name="title">
<string>Layouts</string>
</property>
</widget>
<addaction name="menuLayouts"/> <addaction name="menuLayouts"/>
</widget> </widget>
<widget class="QMenu" name="menuHelp"> <widget class="QMenu" name="menuHelp">
@ -137,7 +137,6 @@
<property name="title"> <property name="title">
<string>Edit</string> <string>Edit</string>
</property> </property>
<addaction name="actionSearch"/>
<addaction name="actionBackward"/> <addaction name="actionBackward"/>
<addaction name="actionForward"/> <addaction name="actionForward"/>
<addaction name="separator"/> <addaction name="separator"/>
@ -353,7 +352,7 @@
<string>Redo Seek</string> <string>Redo Seek</string>
</property> </property>
</action> </action>
<action name="actionLock"> <action name="actionUnlock">
<property name="checkable"> <property name="checkable">
<bool>true</bool> <bool>true</bool>
</property> </property>
@ -366,23 +365,12 @@
<property name="toolTip"> <property name="toolTip">
<string>Toggle panel locks</string> <string>Toggle panel locks</string>
</property> </property>
<property name="iconVisibleInMenu">
<bool>false</bool>
</property>
</action>
<action name="actionLockUnlock">
<property name="checkable">
<bool>true</bool>
</property>
<property name="icon"> <property name="icon">
<iconset> <iconset>
<normaloff>:/unlock</normaloff>:/unlock</iconset> <normaloff>:/lock</normaloff><normalon>:/unlock</normalon>:/unlock</iconset>
</property> </property>
<property name="text"> <property name="iconVisibleInMenu">
<string>Lock/Unlock</string> <bool>false</bool>
</property>
<property name="toolTip">
<string>Lock/Unlock</string>
</property> </property>
</action> </action>
<action name="actionTheme"> <action name="actionTheme">

View File

@ -70,7 +70,7 @@ QString XrefsDialog::normalizeAddr(const QString &addr) const
QString ret = addr; QString ret = addr;
if (addr.length() < 10) { if (addr.length() < 10) {
ret = ret.mid(3).rightJustified(8, QLatin1Char('0')); ret = ret.mid(3).rightJustified(8, QLatin1Char('0'));
ret.prepend(QLatin1Literal("0x")); ret.prepend(QStringLiteral("0x"));
} }
return ret; return ret;
} }

View File

@ -591,7 +591,7 @@ QKeySequence DisassemblyContextMenu::getCommentSequence() const
QKeySequence DisassemblyContextMenu::getCopyAddressSequence() 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 QKeySequence DisassemblyContextMenu::getSetToCodeSequence() const
@ -606,7 +606,7 @@ QKeySequence DisassemblyContextMenu::getSetAsStringSequence() const
QKeySequence DisassemblyContextMenu::getSetAsStringAdvanced() const QKeySequence DisassemblyContextMenu::getSetAsStringAdvanced() const
{ {
return {Qt::SHIFT + Qt::Key_A}; return {Qt::SHIFT | Qt::Key_A};
} }
QKeySequence DisassemblyContextMenu::getSetToDataSequence() const QKeySequence DisassemblyContextMenu::getSetToDataSequence() const
@ -631,7 +631,7 @@ QKeySequence DisassemblyContextMenu::getRenameSequence() const
QKeySequence DisassemblyContextMenu::getRenameUsedHereSequence() const QKeySequence DisassemblyContextMenu::getRenameUsedHereSequence() const
{ {
return {Qt::SHIFT + Qt::Key_N}; return {Qt::SHIFT | Qt::Key_N};
} }
QKeySequence DisassemblyContextMenu::getRetypeSequence() const QKeySequence DisassemblyContextMenu::getRetypeSequence() const

View File

@ -5,6 +5,7 @@
#include <QMenu> #include <QMenu>
#include <QShortcut> #include <QShortcut>
#include <QActionGroup>
CommentsModel::CommentsModel(QList<CommentDescription> *comments, CommentsModel::CommentsModel(QList<CommentDescription> *comments,
QList<CommentGroup> *nestedComments, QList<CommentGroup> *nestedComments,

View File

@ -8,6 +8,8 @@
#include <cmath> #include <cmath>
#include <QStandardPaths> #include <QStandardPaths>
#include <QActionGroup>
static const int KEY_ZOOM_IN = Qt::Key_Plus + Qt::ControlModifier; static const int KEY_ZOOM_IN = Qt::Key_Plus + Qt::ControlModifier;
static const int KEY_ZOOM_OUT = Qt::Key_Minus + Qt::ControlModifier; static const int KEY_ZOOM_OUT = Qt::Key_Minus + Qt::ControlModifier;

View File

@ -16,6 +16,7 @@
#include <QJsonArray> #include <QJsonArray>
#include <QJsonObject> #include <QJsonObject>
#include <QInputDialog> #include <QInputDialog>
#include <QActionGroup>
namespace { namespace {

View File

@ -20,6 +20,7 @@
#include <QJsonArray> #include <QJsonArray>
#include <QRegularExpression> #include <QRegularExpression>
#include <QToolTip> #include <QToolTip>
#include <QActionGroup>
static constexpr uint64_t MAX_COPY_SIZE = 128 * 1024 * 1024; static constexpr uint64_t MAX_COPY_SIZE = 128 * 1024 * 1024;
static constexpr int MAX_LINE_WIDTH_PRESET = 32; static constexpr int MAX_LINE_WIDTH_PRESET = 32;

View File

@ -124,7 +124,7 @@
<item> <item>
<widget class="QComboBox" name="parseEndianComboBox"> <widget class="QComboBox" name="parseEndianComboBox">
<property name="sizeAdjustPolicy"> <property name="sizeAdjustPolicy">
<enum>QComboBox::AdjustToMinimumContentsLength</enum> <enum>QComboBox::AdjustToContents</enum>
</property> </property>
<item> <item>
<property name="text"> <property name="text">
@ -201,7 +201,7 @@
</sizepolicy> </sizepolicy>
</property> </property>
<property name="sizeAdjustPolicy"> <property name="sizeAdjustPolicy">
<enum>QComboBox::AdjustToMinimumContentsLength</enum> <enum>QComboBox::AdjustToContents</enum>
</property> </property>
<property name="frame"> <property name="frame">
<bool>false</bool> <bool>false</bool>
@ -224,7 +224,7 @@
<item> <item>
<widget class="QComboBox" name="parseBitsComboBox"> <widget class="QComboBox" name="parseBitsComboBox">
<property name="sizeAdjustPolicy"> <property name="sizeAdjustPolicy">
<enum>QComboBox::AdjustToMinimumContentsLength</enum> <enum>QComboBox::AdjustToContents</enum>
</property> </property>
<item> <item>
<property name="text"> <property name="text">
@ -260,15 +260,15 @@
<pointsize>13</pointsize> <pointsize>13</pointsize>
</font> </font>
</property> </property>
<property name="readOnly">
<bool>true</bool>
</property>
<property name="frameShape"> <property name="frameShape">
<enum>QFrame::NoFrame</enum> <enum>QFrame::NoFrame</enum>
</property> </property>
<property name="lineWidth"> <property name="lineWidth">
<number>0</number> <number>0</number>
</property> </property>
<property name="readOnly">
<bool>true</bool>
</property>
<property name="plainText"> <property name="plainText">
<string/> <string/>
</property> </property>