Skip to content

Instantly share code, notes, and snippets.

@torarnv
Created October 21, 2024 10:33
Show Gist options
  • Save torarnv/b1803b7d42bb476ae472bd8f537b4d1a to your computer and use it in GitHub Desktop.
Save torarnv/b1803b7d42bb476ae472bd8f537b4d1a to your computer and use it in GitHub Desktop.
Dication WIP
commit 384146e1c4db9808f6ce79b6af3857399a45fe4f
Merge: 8f79864cf62 d3cc207ff45
Author: Tor Arne Vestbø <[email protected]>
Date: Thu Oct 17 11:29:15 2024 +0200
WIP on dev: 8f79864cf62 macOS: Release main thread transaction block as soon as we're done with it
diff --cc examples/widgets/widgets/lineedits/window.cpp
index c8a47a15942,c8a47a15942..fb351a3fcb0
--- a/examples/widgets/widgets/lineedits/window.cpp
+++ b/examples/widgets/widgets/lineedits/window.cpp
@@@ -8,6 -8,6 +8,7 @@@
#include <QGroupBox>
#include <QLabel>
#include <QLineEdit>
++#include <QtGui/qevent.h>
//! [0]
Window::Window(QWidget *parent)
@@@ -136,9 -136,9 +137,19 @@@
setLayout(layout);
setWindowTitle(tr("Line Edits"));
++
++ echoLineEdit->installEventFilter(this);
}
//! [8]
++bool Window::eventFilter(QObject *watched, QEvent *event)
++{
++ if (event->type() == QEvent::KeyPress || (event->type() == QEvent::KeyRelease)) {
++ qDebug() << static_cast<QKeyEvent*>(event);
++ }
++ return false;
++}
++
//! [9]
void Window::echoChanged(int index)
{
diff --cc examples/widgets/widgets/lineedits/window.h
index 13fdcf64fa4,13fdcf64fa4..e9eefad03cf
--- a/examples/widgets/widgets/lineedits/window.h
+++ b/examples/widgets/widgets/lineedits/window.h
@@@ -18,6 -18,6 +18,8 @@@ class Window : public QWidge
public:
Window(QWidget *parent = nullptr);
++ bool eventFilter(QObject *watched, QEvent *event) override;
++
public slots:
void echoChanged(int);
void validatorChanged(int);
diff --cc src/plugins/platforms/cocoa/qcocoainputcontext.mm
index 70461376e22,70461376e22..099028d2d6d
--- a/src/plugins/platforms/cocoa/qcocoainputcontext.mm
+++ b/src/plugins/platforms/cocoa/qcocoainputcontext.mm
@@@ -52,6 -52,6 +52,11 @@@ QCocoaInputContext::QCocoaInputContext(
updateLocale();
});
++ connect(qGuiApp, &QGuiApplication::focusWindowChanged, this, []{
++ qDebug() << "Focus window changed to" << QGuiApplication::focusWindow()
++ << "with focus object" << (QGuiApplication::focusWindow() ? QGuiApplication::focusWindow()->focusObject() : nullptr);
++ });
++
updateLocale();
}
diff --cc src/plugins/platforms/cocoa/qnsview_complextext.mm
index a61265c0676,a61265c0676..cfe66fcc3bb
--- a/src/plugins/platforms/cocoa/qnsview_complextext.mm
+++ b/src/plugins/platforms/cocoa/qnsview_complextext.mm
@@@ -501,6 -501,6 +501,7 @@@
Q_UNUSED(actualRange);
QWindow *window = m_platformWindow ? m_platformWindow->window() : nullptr;
++ qDebug() << __FUNCTION__ << window << self.focusObject;
if (window && queryInputMethod(window->focusObject())) {
if (range.length) // FIXME: Handle the case when range is non-zero
qCWarning(lcQpaKeys) << "Can't satisfy firstRectForCharacterRange for" << range;
@@@ -508,6 -508,6 +509,53 @@@
cursorRect.moveBottomLeft(window->mapToGlobal(cursorRect.bottomLeft()));
return QCocoaScreen::mapToNative(cursorRect);
} else {
++ qDebug() << "NSZeroRect!!!";
++ return NSZeroRect;
++ }
++}
++
++/*
++ Returns the visible rect of the document area in screen coordinates.
++
++ This is used among other things to position the text insertion and
++ dictation indicator.
++*/
++- (NSRect)documentVisibleRect
++{
++ qDebug() << __FUNCTION__;
++ if (queryInputMethod(self.focusObject)) {
++ auto itemClipRect = qApp->inputMethod()->inputItemClipRectangle();
++ auto *window = m_platformWindow->window();
++ auto ret = QCocoaScreen::mapToNative(QRectF(
++ window->mapToGlobal(itemClipRect.topLeft()),
++ itemClipRect.size())
++ );
++ ret = QCocoaScreen::mapToNative(QRectF(100, 100, 0, 0));
++ qDebug() << self.focusObject << window <<
++ itemClipRect << QRectF::fromCGRect(ret);
++ return ret;
++ } else {
++ qDebug() << "NSZeroRect!!!";
++ return NSZeroRect;
++ }
++}
++
++/*
++ Returns the visible rect of the selection in screen coordinates.
++*/
++- (NSRect)unionRectInVisibleSelectedRange
++{
++ qDebug() << __FUNCTION__;
++ if (auto selectionRect = [self selectionRect]; !selectionRect.isEmpty()) {
++ auto *window = m_platformWindow->window();
++ auto globalRect = QRectF(window->mapToGlobal(selectionRect.topLeft()),
++ selectionRect.size());
++ auto ret = QCocoaScreen::mapToNative(globalRect);
++
++ qDebug() << self.focusObject << window << selectionRect << globalRect << QRectF::fromCGRect(ret);
++ return ret;
++ } else {
++ qDebug() << "NSZeroRect!!!";
return NSZeroRect;
}
}
@@@ -611,6 -611,6 +659,32 @@@
return {replaceFrom, replaceLength};
}
++/*
++ Returns the visible rect of the selection in window coordinates.
++*/
++- (QRectF)selectionRect
++{
++ if (queryInputMethod(self.focusObject)) {
++ // We don't have a way of querying the selection rectangle via
++ // the input method protocol (yet), so we use crude heuristics.
++ const auto *inputMethod = qApp->inputMethod();
++ auto cursorRect = inputMethod->cursorRectangle();
++ auto anchorRect = inputMethod->anchorRectangle();
++ auto selectionRect = cursorRect.united(anchorRect);
++ if (cursorRect.top() != anchorRect.top()) {
++ // Multi line selection. Assume the selections extends to
++ // the entire width of the input item. This does not account
++ // for center-aligned text and a bunch of other cases. FIXME
++ auto itemClipRect = inputMethod->inputItemClipRectangle();
++ selectionRect.setLeft(itemClipRect.left());
++ selectionRect.setRight(itemClipRect.right());
++ }
++ return selectionRect;
++ } else {
++ return {};
++ }
++}
++
@end
@implementation QNSView (ServicesMenu)
@@@ -683,25 -683,25 +757,7 @@@
*/
- (NSRect)selectionAnchorRect
{
-- if (queryInputMethod(self.focusObject)) {
-- // We don't have a way of querying the selection rectangle via
-- // the input method protocol (yet), so we use crude heuristics.
-- const auto *inputMethod = qApp->inputMethod();
-- auto cursorRect = inputMethod->cursorRectangle();
-- auto anchorRect = inputMethod->anchorRectangle();
-- auto selectionRect = cursorRect.united(anchorRect);
-- if (cursorRect.top() != anchorRect.top()) {
-- // Multi line selection. Assume the selections extends to
-- // the entire width of the input item. This does not account
-- // for center-aligned text and a bunch of other cases. FIXME
-- auto itemClipRect = inputMethod->inputItemClipRectangle();
-- selectionRect.setLeft(itemClipRect.left());
-- selectionRect.setRight(itemClipRect.right());
-- }
-- return selectionRect.toCGRect();
-- } else {
-- return NSZeroRect;
-- }
++ return [self selectionRect].toCGRect();
}
@end
#endif // macOS 15 SDK
diff --cc src/widgets/kernel/qwidget.cpp
index 85850df11a3,85850df11a3..cb5b0453fe2
--- a/src/widgets/kernel/qwidget.cpp
+++ b/src/widgets/kernel/qwidget.cpp
@@@ -9956,6 -9956,6 +9956,7 @@@ void QWidget::inputMethodEvent(QInputMe
*/
QVariant QWidget::inputMethodQuery(Qt::InputMethodQuery query) const
{
++ qDebug() << "QWidget::inputMethodQuery" << this << query;
switch(query) {
case Qt::ImCursorRectangle:
return QRect(width()/2, 0, 1, height());
diff --cc src/widgets/kernel/qwidgetwindow.cpp
index e489749214f,e489749214f..625716d7ce6
--- a/src/widgets/kernel/qwidgetwindow.cpp
+++ b/src/widgets/kernel/qwidgetwindow.cpp
@@@ -1145,6 -1145,6 +1145,7 @@@ void QWidgetWindow::handleContextMenuEv
QContextMenuEvent widgetEvent(QContextMenuEvent::Keyboard, pos, fw->mapToGlobal(pos),
e->modifiers());
QGuiApplication::forwardEvent(fw, &widgetEvent, e);
++ e->setAccepted(widgetEvent.isAccepted());
}
}
#endif // QT_NO_CONTEXTMENU
diff --cc src/widgets/widgets/qlineedit.cpp
index 0db46bf175e,0db46bf175e..b361d72fadd
--- a/src/widgets/widgets/qlineedit.cpp
+++ b/src/widgets/widgets/qlineedit.cpp
@@@ -1842,6 -1842,6 +1842,7 @@@ QVariant QLineEdit::inputMethodQuery(Qt
*/
QVariant QLineEdit::inputMethodQuery(Qt::InputMethodQuery property, QVariant argument) const
{
++ qDebug() << __FUNCTION__ << property;
Q_D(const QLineEdit);
switch(property) {
case Qt::ImEnabled:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment