mirror of
https://github.com/rizinorg/cutter.git
synced 2024-12-18 10:56:11 +00:00
Qt6 keyboard and mouse API compatibility
* Some of the API replaced int with QKeyCombination, use typedef in cutter code * Use of + operator depracted, replace with recommended "|" operator * QMouseEvent globalPos and localPos renamed to globalPosition and position, replace with helper function or use of integer position which wasn't renamed.
This commit is contained in:
parent
2799390314
commit
585dc961db
@ -286,4 +286,23 @@ bool filterStringContains(const QString &string, const QSortFilterProxyModel *mo
|
||||
return string.contains(model->filterRegularExpression());
|
||||
#endif
|
||||
}
|
||||
|
||||
QPointF mouseEventPos(QMouseEvent *ev)
|
||||
{
|
||||
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
|
||||
return ev->localPos();
|
||||
#else
|
||||
return ev->position();
|
||||
#endif
|
||||
}
|
||||
|
||||
QPoint mouseEventGlobalPos(QMouseEvent *ev)
|
||||
{
|
||||
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
|
||||
return ev->globalPos();
|
||||
#else
|
||||
return ev->globalPosition().toPoint();
|
||||
#endif
|
||||
}
|
||||
|
||||
} // end namespace
|
||||
|
@ -24,6 +24,7 @@ class QMenu;
|
||||
class QPaintDevice;
|
||||
class QComboBox;
|
||||
class QSortFilterProxyModel;
|
||||
class QMouseEvent;
|
||||
|
||||
#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0)
|
||||
# define CUTTER_QT_SKIP_EMPTY_PARTS QString::SkipEmptyParts
|
||||
@ -88,9 +89,15 @@ CUTTER_EXPORT bool filterStringContains(const QString &string, const QSortFilter
|
||||
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
||||
using ColorFloat = float;
|
||||
using KeyComb = QKeyCombination;
|
||||
#else
|
||||
using ColorFloat = qreal;
|
||||
using KeyComb = int;
|
||||
#endif
|
||||
|
||||
CUTTER_EXPORT QPointF mouseEventPos(QMouseEvent *ev);
|
||||
CUTTER_EXPORT QPoint mouseEventGlobalPos(QMouseEvent *ev);
|
||||
|
||||
} // qhelpers
|
||||
|
||||
#endif // HELPERS_H
|
||||
|
@ -20,7 +20,7 @@ AddressableItemContextMenu::AddressableItemContextMenu(QWidget *parent, MainWind
|
||||
|
||||
connect(actionCopyAddress, &QAction::triggered, this,
|
||||
&AddressableItemContextMenu::onActionCopyAddress);
|
||||
actionCopyAddress->setShortcuts({ Qt::CTRL + Qt::SHIFT + Qt::Key_C });
|
||||
actionCopyAddress->setShortcuts({ Qt::CTRL | Qt::SHIFT | Qt::Key_C });
|
||||
actionCopyAddress->setShortcutContext(Qt::ShortcutContext::WidgetWithChildrenShortcut);
|
||||
|
||||
connect(actionShowXrefs, &QAction::triggered, this,
|
||||
|
@ -275,7 +275,8 @@ void DecompilerContextMenu::setActionCopy() // Set all three copy actions
|
||||
connect(&actionCopyReferenceAddress, &QAction::triggered, this,
|
||||
&DecompilerContextMenu::actionCopyReferenceAddressTriggered);
|
||||
addAction(&actionCopyReferenceAddress);
|
||||
actionCopyReferenceAddress.setShortcut({ Qt::CTRL + Qt::SHIFT + Qt::Key_C });
|
||||
actionCopyReferenceAddress.setShortcut({ Qt::KeyboardModifier::ControlModifier
|
||||
| Qt::KeyboardModifier::ControlModifier | Qt::Key_C });
|
||||
}
|
||||
|
||||
void DecompilerContextMenu::setActionShowInSubmenu()
|
||||
@ -339,14 +340,14 @@ void DecompilerContextMenu::setActionToggleBreakpoint()
|
||||
{
|
||||
connect(&actionToggleBreakpoint, &QAction::triggered, this,
|
||||
&DecompilerContextMenu::actionToggleBreakpointTriggered);
|
||||
actionToggleBreakpoint.setShortcuts({ Qt::Key_F2, Qt::CTRL + Qt::Key_B });
|
||||
actionToggleBreakpoint.setShortcuts({ Qt::Key_F2, Qt::CTRL | Qt::Key_B });
|
||||
}
|
||||
|
||||
void DecompilerContextMenu::setActionAdvancedBreakpoint()
|
||||
{
|
||||
connect(&actionAdvancedBreakpoint, &QAction::triggered, this,
|
||||
&DecompilerContextMenu::actionAdvancedBreakpointTriggered);
|
||||
actionAdvancedBreakpoint.setShortcut({ Qt::CTRL + Qt::Key_F2 });
|
||||
actionAdvancedBreakpoint.setShortcut({ Qt::CTRL | Qt::Key_F2 });
|
||||
}
|
||||
|
||||
void DecompilerContextMenu::setActionContinueUntil()
|
||||
|
@ -135,8 +135,7 @@ DisassemblyContextMenu::DisassemblyContextMenu(QWidget *parent, MainWindow *main
|
||||
addAction(&actionXRefs);
|
||||
|
||||
initAction(&actionXRefsForVariables, tr("X-Refs for local variables"),
|
||||
SLOT(on_actionXRefsForVariables_triggered()),
|
||||
QKeySequence({ Qt::SHIFT + Qt::Key_X }));
|
||||
SLOT(on_actionXRefsForVariables_triggered()), QKeySequence(Qt::SHIFT | Qt::Key_X));
|
||||
addAction(&actionXRefsForVariables);
|
||||
|
||||
initAction(&actionDisplayOptions, tr("Show Options"), SLOT(on_actionDisplayOptions_triggered()),
|
||||
@ -302,7 +301,7 @@ void DisassemblyContextMenu::addBreakpointMenu()
|
||||
SLOT(on_actionAddBreakpoint_triggered()), getAddBPSequence());
|
||||
breakpointMenu->addAction(&actionAddBreakpoint);
|
||||
initAction(&actionAdvancedBreakpoint, tr("Advanced breakpoint"),
|
||||
SLOT(on_actionAdvancedBreakpoint_triggered()), QKeySequence(Qt::CTRL + Qt::Key_F2));
|
||||
SLOT(on_actionAdvancedBreakpoint_triggered()), QKeySequence(Qt::CTRL | Qt::Key_F2));
|
||||
breakpointMenu->addAction(&actionAdvancedBreakpoint);
|
||||
}
|
||||
|
||||
@ -675,7 +674,7 @@ QKeySequence DisassemblyContextMenu::getLinkTypeSequence() const
|
||||
|
||||
QList<QKeySequence> DisassemblyContextMenu::getAddBPSequence() const
|
||||
{
|
||||
return { Qt::Key_F2, Qt::CTRL + Qt::Key_B };
|
||||
return { Qt::Key_F2, Qt::CTRL | Qt::Key_B };
|
||||
}
|
||||
|
||||
QKeySequence DisassemblyContextMenu::getDefineNewFunctionSequence() const
|
||||
@ -685,7 +684,7 @@ QKeySequence DisassemblyContextMenu::getDefineNewFunctionSequence() const
|
||||
|
||||
QKeySequence DisassemblyContextMenu::getEditFunctionSequence() const
|
||||
{
|
||||
return { Qt::SHIFT + Qt::Key_P };
|
||||
return { Qt::SHIFT | Qt::Key_P };
|
||||
}
|
||||
|
||||
QKeySequence DisassemblyContextMenu::getUndefineFunctionSequence() const
|
||||
|
@ -77,7 +77,7 @@ ConsoleWidget::ConsoleWidget(MainWindow *main)
|
||||
addAction(actionClear);
|
||||
|
||||
// Ctrl+l to clear the output
|
||||
actionClear->setShortcut(Qt::CTRL + Qt::Key_L);
|
||||
actionClear->setShortcut(Qt::CTRL | Qt::Key_L);
|
||||
actionClear->setShortcutContext(Qt::WidgetWithChildrenShortcut);
|
||||
actions.append(actionClear);
|
||||
|
||||
|
@ -10,9 +10,11 @@
|
||||
#include <QStandardPaths>
|
||||
#include <QActionGroup>
|
||||
|
||||
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_RESET = Qt::Key_Equal + Qt::ControlModifier;
|
||||
static const qhelpers::KeyComb KEY_ZOOM_IN = Qt::Key_Plus | Qt::ControlModifier;
|
||||
static const qhelpers::KeyComb KEY_ZOOM_IN2 =
|
||||
Qt::Key_Plus | (Qt::ControlModifier | Qt::ShiftModifier);
|
||||
static const qhelpers::KeyComb KEY_ZOOM_OUT = Qt::Key_Minus | Qt::ControlModifier;
|
||||
static const qhelpers::KeyComb KEY_ZOOM_RESET = Qt::Key_Equal | Qt::ControlModifier;
|
||||
|
||||
static const uint64_t BITMPA_EXPORT_WARNING_SIZE = 32 * 1024 * 1024;
|
||||
|
||||
@ -205,9 +207,9 @@ bool CutterGraphView::event(QEvent *event)
|
||||
switch (event->type()) {
|
||||
case QEvent::ShortcutOverride: {
|
||||
QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);
|
||||
int key = keyEvent->key() + keyEvent->modifiers();
|
||||
qhelpers::KeyComb key = Qt::Key(keyEvent->key()) | keyEvent->modifiers();
|
||||
if (key == KEY_ZOOM_OUT || key == KEY_ZOOM_RESET || key == KEY_ZOOM_IN
|
||||
|| (key == (KEY_ZOOM_IN | Qt::ShiftModifier))) {
|
||||
|| key == KEY_ZOOM_IN2) {
|
||||
event->accept();
|
||||
return true;
|
||||
}
|
||||
@ -215,8 +217,8 @@ bool CutterGraphView::event(QEvent *event)
|
||||
}
|
||||
case QEvent::KeyPress: {
|
||||
QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);
|
||||
int key = keyEvent->key() + keyEvent->modifiers();
|
||||
if (key == KEY_ZOOM_IN || (key == (KEY_ZOOM_IN | Qt::ShiftModifier))) {
|
||||
qhelpers::KeyComb key = Qt::Key(keyEvent->key()) | keyEvent->modifiers();
|
||||
if (key == KEY_ZOOM_IN || key == KEY_ZOOM_IN2) {
|
||||
zoomIn();
|
||||
return true;
|
||||
} else if (key == KEY_ZOOM_OUT) {
|
||||
|
@ -68,15 +68,15 @@ DebugActions::DebugActions(QToolBar *toolBar, MainWindow *main) : QObject(main),
|
||||
actionContinueUntilCall = new QAction(continueUCLabel, this);
|
||||
actionContinueUntilSyscall = new QAction(continueUSLabel, this);
|
||||
actionContinueBack = new QAction(continueBackIcon, continueBackLabel, this);
|
||||
actionContinueBack->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_F5));
|
||||
actionContinueBack->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_F5));
|
||||
actionStep = new QAction(stepLabel, this);
|
||||
actionStep->setShortcut(QKeySequence(Qt::Key_F7));
|
||||
actionStepOver = new QAction(stepOverLabel, this);
|
||||
actionStepOver->setShortcut(QKeySequence(Qt::Key_F8));
|
||||
actionStepOut = new QAction(stepOutLabel, this);
|
||||
actionStepOut->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_F8));
|
||||
actionStepOut->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_F8));
|
||||
actionStepBack = new QAction(stepBackIcon, stepBackLabel, this);
|
||||
actionStepBack->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_F7));
|
||||
actionStepBack->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_F7));
|
||||
actionTrace = new QAction(startTraceIcon, startTraceLabel, this);
|
||||
|
||||
QToolButton *startButton = new QToolButton;
|
||||
|
@ -650,8 +650,7 @@ bool DisassemblyWidget::eventFilter(QObject *obj, QEvent *event)
|
||||
&& (obj == mDisasTextEdit || obj == mDisasTextEdit->viewport())) {
|
||||
QMouseEvent *mouseEvent = static_cast<QMouseEvent *>(event);
|
||||
|
||||
const QTextCursor &cursor =
|
||||
mDisasTextEdit->cursorForPosition(QPoint(mouseEvent->x(), mouseEvent->y()));
|
||||
const QTextCursor &cursor = mDisasTextEdit->cursorForPosition(mouseEvent->pos());
|
||||
jumpToOffsetUnderCursor(cursor);
|
||||
|
||||
return true;
|
||||
|
@ -156,8 +156,7 @@ void GraphView::cleanupEdges(GraphLayout::Graph &graph)
|
||||
|
||||
void GraphView::beginMouseDrag(QMouseEvent *event)
|
||||
{
|
||||
scroll_base_x = event->x();
|
||||
scroll_base_y = event->y();
|
||||
scrollBase = event->pos();
|
||||
scroll_mode = true;
|
||||
setCursor(Qt::ClosedHandCursor);
|
||||
viewport()->grabMouse();
|
||||
@ -690,10 +689,8 @@ void GraphView::mousePressEvent(QMouseEvent *event)
|
||||
void GraphView::mouseMoveEvent(QMouseEvent *event)
|
||||
{
|
||||
if (scroll_mode) {
|
||||
addViewOffset(QPoint(scroll_base_x - event->x(), scroll_base_y - event->y())
|
||||
/ current_scale);
|
||||
scroll_base_x = event->x();
|
||||
scroll_base_y = event->y();
|
||||
addViewOffset((scrollBase - event->pos()) / current_scale);
|
||||
scrollBase = event->pos();
|
||||
viewport()->update();
|
||||
}
|
||||
}
|
||||
|
@ -189,9 +189,7 @@ private:
|
||||
|
||||
std::unique_ptr<GraphLayout> graphLayoutSystem;
|
||||
|
||||
// Scrolling data
|
||||
int scroll_base_x = 0;
|
||||
int scroll_base_y = 0;
|
||||
QPoint scrollBase;
|
||||
bool scroll_mode = false;
|
||||
|
||||
bool useGL;
|
||||
|
@ -116,7 +116,7 @@ HexWidget::HexWidget(QWidget *parent)
|
||||
|
||||
actionCopyAddress = new QAction(tr("Copy address"), this);
|
||||
actionCopyAddress->setShortcutContext(Qt::ShortcutContext::WidgetWithChildrenShortcut);
|
||||
actionCopyAddress->setShortcut(Qt::CTRL + Qt::SHIFT + Qt::Key_C);
|
||||
actionCopyAddress->setShortcut(Qt::CTRL | Qt::SHIFT | Qt::Key_C);
|
||||
connect(actionCopyAddress, &QAction::triggered, this, &HexWidget::copyAddress);
|
||||
addAction(actionCopyAddress);
|
||||
|
||||
@ -472,7 +472,7 @@ void HexWidget::mouseMoveEvent(QMouseEvent *event)
|
||||
|
||||
QString metaData = getFlagsAndComment(mouseAddr);
|
||||
if (!metaData.isEmpty() && itemArea.contains(pos)) {
|
||||
QToolTip::showText(event->globalPos(), metaData.replace(",", ", "), this);
|
||||
QToolTip::showText(mapToGlobal(event->pos()), metaData.replace(",", ", "), this);
|
||||
} else {
|
||||
QToolTip::hideText();
|
||||
}
|
||||
|
@ -88,16 +88,13 @@ void OverviewView::paintEvent(QPaintEvent *event)
|
||||
void OverviewView::mousePressEvent(QMouseEvent *event)
|
||||
{
|
||||
mouseActive = true;
|
||||
if (rangeRect.contains(event->pos())) {
|
||||
initialDiff = QPointF(event->localPos().x() - rangeRect.x(),
|
||||
event->localPos().y() - rangeRect.y());
|
||||
auto pos = qhelpers::mouseEventPos(event);
|
||||
if (rangeRect.contains(pos)) {
|
||||
initialDiff = pos - rangeRect.topLeft();
|
||||
} else {
|
||||
qreal w = rangeRect.width();
|
||||
qreal h = rangeRect.height();
|
||||
qreal x = event->localPos().x() - w / 2;
|
||||
qreal y = event->localPos().y() - h / 2;
|
||||
rangeRect = QRectF(x, y, w, h);
|
||||
initialDiff = QPointF(w / 2, h / 2);
|
||||
QPointF size(rangeRect.width(), rangeRect.height());
|
||||
initialDiff = size * 0.5;
|
||||
rangeRect.moveCenter(pos);
|
||||
viewport()->update();
|
||||
emit mouseMoved();
|
||||
}
|
||||
@ -114,9 +111,8 @@ void OverviewView::mouseMoveEvent(QMouseEvent *event)
|
||||
if (!mouseActive) {
|
||||
return;
|
||||
}
|
||||
qreal x = event->localPos().x() - initialDiff.x();
|
||||
qreal y = event->localPos().y() - initialDiff.y();
|
||||
rangeRect = QRectF(x, y, rangeRect.width(), rangeRect.height());
|
||||
QPointF topLeft = qhelpers::mouseEventPos(event) - initialDiff;
|
||||
rangeRect.setTopLeft(topLeft);
|
||||
viewport()->update();
|
||||
emit mouseMoved();
|
||||
}
|
||||
|
@ -240,10 +240,11 @@ void VisualNavbar::on_seekChanged(RVA addr)
|
||||
|
||||
void VisualNavbar::mousePressEvent(QMouseEvent *event)
|
||||
{
|
||||
qreal x = event->localPos().x();
|
||||
qreal x = qhelpers::mouseEventPos(event).x();
|
||||
RVA address = localXToAddress(x);
|
||||
if (address != RVA_INVALID) {
|
||||
QToolTip::showText(event->globalPos(), toolTipForAddress(address), this);
|
||||
auto tooltipPos = qhelpers::mouseEventGlobalPos(event);
|
||||
QToolTip::showText(tooltipPos, toolTipForAddress(address), this, this->rect());
|
||||
if (event->buttons() & Qt::LeftButton) {
|
||||
event->accept();
|
||||
Core()->seek(address);
|
||||
|
@ -1,10 +1,14 @@
|
||||
#ifndef WIDGETSHORTCUTS_H
|
||||
#define WIDGETSHORTCUTS_H
|
||||
|
||||
#include <QKeySequence>
|
||||
#include <QHash>
|
||||
#include <QString>
|
||||
|
||||
static const QHash<QString, QKeySequence> widgetShortcuts = {
|
||||
{ "StringsWidget", Qt::SHIFT + Qt::Key_F12 }, { "GraphWidget", Qt::SHIFT + Qt::Key_G },
|
||||
{ "ImportsWidget", Qt::SHIFT + Qt::Key_I }, { "ExportsWidget", Qt::SHIFT + Qt::Key_E },
|
||||
{ "ConsoleWidget", Qt::CTRL + Qt::Key_QuoteLeft }, { "ConsoleWidgetAlternative", Qt::Key_Colon }
|
||||
{ "StringsWidget", Qt::SHIFT | Qt::Key_F12 }, { "GraphWidget", Qt::SHIFT | Qt::Key_G },
|
||||
{ "ImportsWidget", Qt::SHIFT | Qt::Key_I }, { "ExportsWidget", Qt::SHIFT | Qt::Key_E },
|
||||
{ "ConsoleWidget", Qt::CTRL | Qt::Key_QuoteLeft }, { "ConsoleWidgetAlternative", Qt::Key_Colon }
|
||||
};
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user