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>
28@property (nonatomic, assign) BOOL changingOrientation;
40 if (!(self = [super
init]))
44 static UIImage *gridPattern = nil;
45 static dispatch_once_t onceToken;
46 dispatch_once(&onceToken, ^{
49 UIGraphicsBeginImageContextWithOptions(CGSizeMake(dimension, dimension), YES, 0.0f);
52 CGContextTranslateCTM(
context, -0.5, -0.5);
54 #define gridColorWithBrightness(br) \
55 [UIColor colorWithHue:0.6 saturation:0.0 brightness:br alpha:1.0].CGColor
58 CGContextFillRect(
context, CGRectMake(0, 0, dimension, dimension));
60 CGFloat gridLines[][2] = { { 10, 0.1 }, { 20, 0.2 }, { 100, 0.3 } };
61 for (
size_t l = 0; l <
sizeof(gridLines) /
sizeof(gridLines[0]); ++l) {
63 for (
int c = step;
c <= dimension;
c += step) {
65 CGContextAddLineToPoint(
context,
c, dimension);
67 CGContextAddLineToPoint(
context, dimension,
c);
70 CGFloat brightness = gridLines[l][1];
75 gridPattern = UIGraphicsGetImageFromCurrentImageContext();
76 UIGraphicsEndImageContext();
81 self.backgroundColor = [UIColor colorWithPatternImage:gridPattern];
87- (
void)didAddSubview:(UIView *)subview
95 UIWindow *uiWindow =
screen->uiWindow();
97 if (uiWindow.hidden) {
101 uiWindow.screen =
screen->uiScreen();
102 uiWindow.hidden = NO;
106- (
void)willRemoveSubview:(UIView *)subview
111 UIWindow *uiWindow = self.window;
113 if (uiWindow.screen != [UIScreen mainScreen] && self.subviews.
count == 1) {
117 dispatch_async(dispatch_get_main_queue(), ^{
118 uiWindow.hidden = YES;
119 uiWindow.screen = [UIScreen mainScreen];
124- (
void)layoutSubviews
141 qCDebug(lcQpaWindow) <<
"ignoring layout of subviews while suspended,"
146 for (
int i =
int(self.subviews.
count) - 1;
i >= 0; --
i) {
147 UIView *
view =
static_cast<UIView *
>([
self.subviews objectAtIndex:i]);
151 [
self layoutView: static_cast<QUIView *>(view)];
166 window->handle()->setWindowState(
window->windowStates());
179- (
void)setFrame:(CGRect)newFrame
182 Q_ASSERT(!self.window || self.window.rootViewController.view == self);
187 CGRect transformedWindowBounds = [
self.superview convertRect:self.window.bounds fromView:self.window];
188 [
super setFrame:transformedWindowBounds];
191- (
void)setBounds:(CGRect)newBounds
194 CGRect transformedWindowBounds = [
self convertRect:self.window.bounds fromView:self.window];
195 [
super setBounds:CGRectMake(0, 0, CGRectGetWidth(transformedWindowBounds), CGRectGetHeight(transformedWindowBounds))];
198- (
void)setCenter:(CGPoint)newCenter
201 [
super setCenter:self.window.center];
204- (
void)didMoveToWindow
209 [
self setFrame:self.window.bounds];
217 BOOL m_updatingProperties;
223@synthesize prefersStatusBarHidden;
224@synthesize preferredStatusBarUpdateAnimation;
225@synthesize preferredStatusBarStyle;
230 if (self = [self
init]) {
231 self.platformScreen =
screen;
233 self.changingOrientation = NO;
235 self.lockedOrientation = UIInterfaceOrientationUnknown;
238 self.prefersStatusBarHidden =
infoPlistValue(
@"UIStatusBarHidden",
false);
239 self.preferredStatusBarUpdateAnimation = UIStatusBarAnimationNone;
240 self.preferredStatusBarStyle = UIStatusBarStyle(
infoPlistValue(
@"UIStatusBarStyle", UIStatusBarStyleDefault));
244 [
self updateProperties];
255 qCDebug(lcQpaWindow) <<
"triggering root VC layout when coming out of suspended state";
256 [
self.view setNeedsLayout];
284 NSNotificationCenter *
center = [NSNotificationCenter defaultCenter];
285 [center addObserver:self selector:@selector(willChangeStatusBarFrame:)
286 name:UIApplicationWillChangeStatusBarFrameNotification
287 object:qt_apple_sharedApplication()];
289 [center addObserver:self selector:@selector(didChangeStatusBarOrientation:)
290 name:UIApplicationDidChangeStatusBarOrientationNotification
291 object:qt_apple_sharedApplication()];
297 [[NSNotificationCenter defaultCenter] removeObserver:self name:nil object:nil];
298 [
super viewDidUnload];
303- (BOOL)shouldAutorotate
306 return self.platformScreen &&
self.platformScreen->uiScreen() == [UIScreen mainScreen] && !
self.lockedOrientation;
320 return [
self shouldAutorotate] ? UIInterfaceOrientationMaskAll : 0;
323- (
void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)orientation duration:(NSTimeInterval)duration
325 self.changingOrientation = YES;
327 [
super willRotateToInterfaceOrientation:orientation duration:duration];
330- (
void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)orientation
332 self.changingOrientation = NO;
334 [
super didRotateFromInterfaceOrientation:orientation];
337- (
void)willChangeStatusBarFrame:(NSNotification*)notification
341 if (
self.view.window.screen != [UIScreen mainScreen])
349 if (
self.changingOrientation)
357 static qreal kUIStatusBarAnimationDuration = 0.35;
359 [UIView animateWithDuration:kUIStatusBarAnimationDuration animations:^{
360 [
self.view setNeedsLayout];
361 [
self.view layoutIfNeeded];
365- (
void)didChangeStatusBarOrientation:(NSNotification *)notification
369 if (
self.view.window.screen != [UIScreen mainScreen])
375 if (
self.changingOrientation)
378 [
self.view setNeedsLayout];
381- (
void)viewWillLayoutSubviews
386 if (
self.platformScreen)
387 self.platformScreen->updateProperties();
392- (
void)updateProperties
397 if (!
self.platformScreen || !
self.platformScreen->screen())
402 if (
self.platformScreen->uiScreen() != [UIScreen mainScreen])
409 if (m_updatingProperties)
424 if (!focusWindow->screen() || focusWindow->screen()->
handle() !=
self.platformScreen)
434 UIStatusBarStyle oldStatusBarStyle =
self.preferredStatusBarStyle;
436 self.preferredStatusBarStyle = UIStatusBarStyleDefault;
438 self.preferredStatusBarStyle = UIStatusBarStyleLightContent;
440 if (
self.preferredStatusBarStyle != oldStatusBarStyle)
441 [
self setNeedsStatusBarAppearanceUpdate];
443 bool currentStatusBarVisibility =
self.prefersStatusBarHidden;
446 if (
self.prefersStatusBarHidden != currentStatusBarVisibility) {
447 [
self setNeedsStatusBarAppearanceUpdate];
448 [
self.view setNeedsLayout];
456 static BOOL kAnimateContentOrientationChanges = YES;
464 if (!
self.lockedOrientation) {
469 self.lockedOrientation = uiApplication.statusBarOrientation;
472 [uiApplication setStatusBarOrientation:
473 UIInterfaceOrientation(fromQtScreenOrientation(contentOrientation))
474 animated:kAnimateContentOrientationChanges];
481 if (
self.lockedOrientation) {
485 [uiApplication setStatusBarOrientation:self.lockedOrientation
486 animated:kAnimateContentOrientationChanges];
489 self.lockedOrientation = UIInterfaceOrientationUnknown;
492 [UIViewController attemptRotationToDeviceOrientation];
498- (NSArray*)keyCommands
503 NSMutableArray<UIKeyCommand *> *keyCommands = nil;
505 keyCommands = [[NSMutableArray<UIKeyCommand *> alloc] init];
509 [keyCommands addObject:[UIKeyCommand
510 keyCommandWithInput:QString(keyString[keyString.length() - 1]).toNSString()
511 modifierFlags:QAppleKeyMapper::toUIKitModifiers(seq[0].keyboardModifiers())
512 action:@selector(handleShortcut:)]];
517- (
void)handleShortcut:(UIKeyCommand *)keyCommand
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)
QIOSApplicationState applicationState
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.
bool tryShortcut(QKeyEvent *e)
QList< QKeySequence > keySequences(bool getAll=false) const
\macro QT_RESTRICTED_CAST_FROM_ASCII
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
qsizetype count(QChar c, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
QWindow * topLevelWindow(QWindow::AncestorMode mode=QWindow::IncludeTransients) const
Qt::WindowFlags flags
the window flags of the window
Qt::ScreenOrientation contentOrientation
the orientation of the window's contents
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()
AppleApplication * qt_apple_sharedApplication()
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)
QT_END_NAMESPACE typedef QT_PREPEND_NAMESPACE(quintptr) WId