7#include <QtCore/qscopedvaluerollback.h>
8#include <QtCore/private/qcore_mac_p.h>
9#include <QtGui/private/qapplekeymapper_p.h>
11#include <QtGui/QGuiApplication>
12#include <QtGui/QWindow>
13#include <QtGui/QScreen>
15#include <QtGui/private/qwindow_p.h>
16#include <QtGui/private/qguiapplication_p.h>
24#include <QtCore/qpointer.h>
29@property (nonatomic, assign) UIWindow *
window;
31@property (nonatomic, assign) BOOL changingOrientation;
43 if (!(self = [super
init]))
47 static UIImage *gridPattern = nil;
48 static dispatch_once_t onceToken;
49 dispatch_once(&onceToken, ^{
52 UIGraphicsBeginImageContextWithOptions(CGSizeMake(dimension, dimension), YES, 0.0f);
55 CGContextTranslateCTM(
context, -0.5, -0.5);
57 #define gridColorWithBrightness(br) \
58 [UIColor colorWithHue:0.6 saturation:0.0 brightness:br alpha:1.0].CGColor
61 CGContextFillRect(
context, CGRectMake(0, 0, dimension, dimension));
63 CGFloat gridLines[][2] = { { 10, 0.1 }, { 20, 0.2 }, { 100, 0.3 } };
64 for (
size_t l = 0; l <
sizeof(gridLines) /
sizeof(gridLines[0]); ++l) {
66 for (
int c = step;
c <= dimension;
c += step) {
68 CGContextAddLineToPoint(
context,
c, dimension);
70 CGContextAddLineToPoint(
context, dimension,
c);
73 CGFloat brightness = gridLines[l][1];
78 gridPattern = UIGraphicsGetImageFromCurrentImageContext();
79 UIGraphicsEndImageContext();
84 self.backgroundColor = [UIColor colorWithPatternImage:gridPattern];
90- (
void)didAddSubview:(UIView *)subview
97 UIWindow *uiWindow = self.qtViewController.window;
99 if (uiWindow.hidden) {
104 uiWindow.hidden = NO;
108#if !defined(Q_OS_VISIONOS)
109- (
void)willRemoveSubview:(UIView *)subview
113 UIWindow *uiWindow = self.window;
119 if (uiWindow.screen != [UIScreen mainScreen] && self.subviews.
count == 1) {
123 dispatch_async(dispatch_get_main_queue(), ^{
124 uiWindow.hidden = YES;
130- (
void)layoutSubviews
147 qCDebug(lcQpaWindow) <<
"ignoring layout of subviews while suspended,"
152 for (
int i =
int(self.subviews.
count) - 1;
i >= 0; --
i) {
153 UIView *
view =
static_cast<UIView *
>([
self.subviews objectAtIndex:i]);
157 [
self layoutView: static_cast<QUIView *>(view)];
172 window->handle()->setWindowState(
window->windowStates());
185- (
void)setFrame:(CGRect)newFrame
188 Q_ASSERT(!self.window || self.window.rootViewController.view == self);
193 CGRect transformedWindowBounds = [
self.superview convertRect:self.window.bounds fromView:self.window];
194 [
super setFrame:transformedWindowBounds];
197- (
void)setBounds:(CGRect)newBounds
200 CGRect transformedWindowBounds = [
self convertRect:self.window.bounds fromView:self.window];
201 [
super setBounds:CGRectMake(0, 0, CGRectGetWidth(transformedWindowBounds), CGRectGetHeight(transformedWindowBounds))];
204- (
void)setCenter:(CGPoint)newCenter
207 [
super setCenter:self.window.center];
210- (
void)didMoveToWindow
215 [
self setFrame:self.window.bounds];
223 BOOL m_updatingProperties;
229@synthesize prefersStatusBarHidden;
230@synthesize preferredStatusBarUpdateAnimation;
231@synthesize preferredStatusBarStyle;
234- (instancetype)initWithWindow:(UIWindow*)window andScreen:(QT_PREPEND_NAMESPACE(
QIOSScreen) *)screen
236 if (self = [self
init]) {
238 self.platformScreen =
screen;
240 self.changingOrientation = NO;
243 self.prefersStatusBarHidden =
infoPlistValue(
@"UIStatusBarHidden",
false);
244 self.preferredStatusBarUpdateAnimation = UIStatusBarAnimationNone;
245 self.preferredStatusBarStyle = UIStatusBarStyle(
infoPlistValue(
@"UIStatusBarStyle", UIStatusBarStyleDefault));
249 [
self updateProperties];
260 qCDebug(lcQpaWindow) <<
"triggering root VC layout when coming out of suspended state";
261 [
self.view setNeedsLayout];
288#if !defined(Q_OS_TVOS) && !defined(Q_OS_VISIONOS)
289 NSNotificationCenter *
center = [NSNotificationCenter defaultCenter];
290 [center addObserver:self selector:@selector(willChangeStatusBarFrame:)
291 name:UIApplicationWillChangeStatusBarFrameNotification
292 object:qt_apple_sharedApplication()];
294 [center addObserver:self selector:@selector(didChangeStatusBarOrientation:)
295 name:UIApplicationDidChangeStatusBarOrientationNotification
296 object:qt_apple_sharedApplication()];
302 if (
window->screen()->handle() !=
self.platformScreen)
304 if (
auto *platformWindow =
window->handle())
305 platformWindow->setParent(
nullptr);
311 [[NSNotificationCenter defaultCenter] removeObserver:self name:nil object:nil];
312 [
super viewDidUnload];
317- (
void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)orientation duration:(NSTimeInterval)duration
319 self.changingOrientation = YES;
321 [
super willRotateToInterfaceOrientation:orientation duration:duration];
324- (
void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)orientation
326 self.changingOrientation = NO;
328 [
super didRotateFromInterfaceOrientation:orientation];
331#if !defined(Q_OS_VISIONOS)
332- (
void)willChangeStatusBarFrame:(NSNotification*)notification
336 if (
self.view.window.screen != [UIScreen mainScreen])
344 if (
self.changingOrientation)
352 static qreal kUIStatusBarAnimationDuration = 0.35;
354 [UIView animateWithDuration:kUIStatusBarAnimationDuration animations:^{
355 [
self.view setNeedsLayout];
356 [
self.view layoutIfNeeded];
360- (
void)didChangeStatusBarOrientation:(NSNotification *)notification
364 if (
self.view.window.screen != [UIScreen mainScreen])
370 if (
self.changingOrientation)
373 [
self.view setNeedsLayout];
377- (
void)viewWillLayoutSubviews
382 if (
self.platformScreen)
383 self.platformScreen->updateProperties();
388- (
void)updateProperties
393 if (!
self.platformScreen || !
self.platformScreen->screen())
396#if !defined(Q_OS_VISIONOS)
399 if (
self.platformScreen->uiScreen() != [UIScreen mainScreen])
407 if (m_updatingProperties)
410 QScopedValueRollback<BOOL> updateRollback(m_updatingProperties, YES);
422 if (!focusWindow->screen() || focusWindow->screen()->
handle() !=
self.platformScreen)
428#if !defined(Q_OS_TVOS) && !defined(Q_OS_VISIONOS)
432 UIStatusBarStyle oldStatusBarStyle =
self.preferredStatusBarStyle;
434 self.preferredStatusBarStyle = UIStatusBarStyleDefault;
436 self.preferredStatusBarStyle = UIStatusBarStyleLightContent;
438 if (
self.preferredStatusBarStyle != oldStatusBarStyle)
439 [
self setNeedsStatusBarAppearanceUpdate];
441 bool currentStatusBarVisibility =
self.prefersStatusBarHidden;
444 if (
self.prefersStatusBarHidden != currentStatusBarVisibility) {
445 [
self setNeedsStatusBarAppearanceUpdate];
446 [
self.view setNeedsLayout];
451- (NSArray*)keyCommands
456 NSMutableArray<UIKeyCommand *> *keyCommands = nil;
458 keyCommands = [[NSMutableArray<UIKeyCommand *> alloc] init];
459 const QList<QKeySequence>
keys = shortcutMap.keySequences();
462 [keyCommands addObject:[UIKeyCommand
463 keyCommandWithInput:QString(keyString[keyString.length() - 1]).toNSString()
464 modifierFlags:QAppleKeyMapper::toUIKitModifiers(seq[0].keyboardModifiers())
465 action:@selector(handleShortcut:)]];
470- (
void)handleShortcut:(UIKeyCommand *)keyCommand
477 shortcutMap.tryShortcut(&keyEvent);
QPointer< QT_PREPEND_NAMESPACE(QIOSScreen)> platformScreen
static Qt::KeyboardModifiers fromUIKitModifiers(ulong uikitModifiers)
static QCoreApplication * instance() noexcept
Returns a pointer to the application's QCoreApplication (or QGuiApplication/QApplication) instance.
static QGuiApplicationPrivate * instance()
static Qt::ApplicationState applicationState()
static QWindow * focusWindow()
Returns the QWindow that receives events tied to focus, such as key events.
void focusWindowChanged(QWindow *focusWindow)
This signal is emitted when the focused window changes.
void applicationStateDidChange(Qt::ApplicationState oldState, Qt::ApplicationState newState)
static QIOSIntegration * instance()
The QKeyEvent class describes a key event.
The QKeySequence class encapsulates a key sequence as used by shortcuts.
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
static bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *member)
\threadsafe
Qt::ScreenOrientation primaryOrientation
the primary screen orientation
QPlatformScreen * handle() const
Get the platform screen handle.
\macro QT_RESTRICTED_CAST_FROM_ASCII
bool isEmpty() const noexcept
Returns true if the string has no characters; otherwise returns false.
qsizetype count(QChar c, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Qt::WindowFlags flags
the window flags of the window
void newState(QList< State > &states, const char *token, const char *lexem, bool pre)
QTextStream & center(QTextStream &stream)
Calls QTextStream::setFieldAlignment(QTextStream::AlignCenter) on stream and returns stream.
@ MaximizeUsingFullscreenGeometryHint
bool qt_apple_isApplicationExtension()
DBusConnection const char DBusError DBusBusType DBusError return DBusConnection DBusHandleMessageFunction void DBusFreeFunction return DBusConnection return DBusConnection return const char DBusError return DBusConnection DBusMessage dbus_uint32_t return DBusConnection dbus_bool_t DBusConnection DBusAddWatchFunction DBusRemoveWatchFunction DBusWatchToggledFunction void DBusFreeFunction return DBusConnection DBusDispatchStatusFunction void DBusFreeFunction DBusTimeout return DBusTimeout return DBusWatch return DBusWatch unsigned int return DBusError const DBusError return const DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessageIter int const void return DBusMessageIter DBusMessageIter return DBusMessageIter void DBusMessageIter void int return DBusMessage DBusMessageIter return DBusMessageIter return DBusMessageIter DBusMessageIter const char const char const char const char return DBusMessage return DBusMessage const char return DBusMessage dbus_bool_t return DBusMessage dbus_uint32_t return DBusMessage void
int infoPlistValue(NSString *key, int defaultValue)
#define gridColorWithBrightness(br)
QMetaObject::Connection m_appStateChangedConnection
QMetaObject::Connection m_focusWindowChangeConnection
#define qCDebug(category,...)
GLenum GLenum GLenum input
struct CGContext * CGContextRef
static QString keyString(int sym, QChar::Category category)
Q_CORE_EXPORT int qEnvironmentVariableIntValue(const char *varName, bool *ok=nullptr) noexcept
static QT_BEGIN_NAMESPACE void init(QTextBoundaryFinder::BoundaryType type, QStringView str, QCharAttributes *attributes)
Q_GUI_EXPORT QWindowPrivate * qt_window_private(QWindow *window)