Skip to content

Commit

Permalink
Fix KDMacTouchBar for Qt 6.5
Browse files Browse the repository at this point in the history
  • Loading branch information
cschleifenbaum committed Apr 13, 2023
1 parent 6eac66a commit 2621c3b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
4 changes: 4 additions & 0 deletions examples/mactouchbar/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@

#include <QtGui/QCloseEvent>

#if QT_VERSION >= 0x060000
#include <QtGui/QAction>
#else
#include <QtWidgets/QAction>
#endif
#include <QtWidgets/QMessageBox>
#include <QtWidgets/QLabel>

Expand Down
23 changes: 14 additions & 9 deletions src/kdmactouchbar.mm
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@

#import <AppKit/AppKit.h>

#if QT_VERSION < 0x060000
#define associatedObjects associatedWidgets
#endif

QT_BEGIN_NAMESPACE

static NSImage *create_nsimage(const QIcon &icon)
Expand Down Expand Up @@ -75,7 +79,7 @@ static QString identifierForAction(QObject *action)

static QString removeMnemonics(const QString &original)
{
QString returnText(original.size(), 0);
QString returnText(original.size(), u'\0');
int finalDest = 0;
int currPos = 0;
int l = original.length();
Expand Down Expand Up @@ -121,7 +125,7 @@ static QString removeMnemonics(const QString &original)
void sendDataChanged()
{
QActionEvent e(QEvent::ActionChanged, this);
for (auto w : associatedWidgets())
for (auto w : associatedObjects())
QApplication::sendEvent(w, &e);
}
};
Expand Down Expand Up @@ -164,7 +168,7 @@ void checkStandardButtonAndTexts()
void sendDataChanged()
{
QActionEvent e(QEvent::ActionChanged, this);
for (auto w : associatedWidgets())
for (auto w : associatedObjects())
QApplication::sendEvent(w, &e);
}

Expand Down Expand Up @@ -209,6 +213,7 @@ - (id)initWithQObject:(QObject *)aQObject
setAttribute(Qt::WA_QuitOnClose, false);
ensurePolished();
setVisible(true);
widget->setVisible(true);
QPixmap pm(1, 1);
render(&pm, QPoint(), QRegion(),
widget->autoFillBackground()
Expand Down Expand Up @@ -291,24 +296,24 @@ - (void)touchesBeganWithEvent:(NSEvent *)event
touchTarget = widget->childAt(point);
if (touchTarget == nullptr)
touchTarget = widget;
QMouseEvent e(QEvent::MouseButtonPress, touchTarget->mapFrom(widget, point), Qt::LeftButton,
Qt::LeftButton, Qt::NoModifier);
QMouseEvent e(QEvent::MouseButtonPress, touchTarget->mapFrom(widget, point), point,
Qt::LeftButton, Qt::LeftButton, Qt::NoModifier);
qApp->sendEvent(touchTarget, &e);
}
- (void)touchesMovedWithEvent:(NSEvent *)event
{
NSTouch *touch = [[event touchesMatchingPhase:NSTouchPhaseMoved inView:self] anyObject];
const QPoint point = QPointF::fromCGPoint([touch locationInView:self]).toPoint();
QMouseEvent e(QEvent::MouseButtonPress, touchTarget->mapFrom(widget, point), Qt::LeftButton,
Qt::LeftButton, Qt::NoModifier);
QMouseEvent e(QEvent::MouseButtonPress, touchTarget->mapFrom(widget, point), point,
Qt::LeftButton, Qt::LeftButton, Qt::NoModifier);
qApp->sendEvent(touchTarget, &e);
}
- (void)touchesEndedWithEvent:(NSEvent *)event
{
NSTouch *touch = [[event touchesMatchingPhase:NSTouchPhaseEnded inView:self] anyObject];
const QPoint point = QPointF::fromCGPoint([touch locationInView:self]).toPoint();
QMouseEvent e(QEvent::MouseButtonRelease, touchTarget->mapFrom(widget, point), Qt::LeftButton,
Qt::LeftButton, Qt::NoModifier);
QMouseEvent e(QEvent::MouseButtonRelease, touchTarget->mapFrom(widget, point), point,
Qt::LeftButton, Qt::LeftButton, Qt::NoModifier);
qApp->sendEvent(touchTarget, &e);
}

Expand Down

0 comments on commit 2621c3b

Please sign in to comment.