diff options
author | Paul Olav Tvete <paul.tvete@theqtcompany.com> | 2015-05-13 12:42:46 +0200 |
---|---|---|
committer | Paul Olav Tvete <paul.tvete@theqtcompany.com> | 2015-05-13 12:42:46 +0200 |
commit | 8524853227c753b5cfa14184a086ec0acff3930a (patch) | |
tree | 808fab49e65286a4b4416a8462bb78fc188dfeac /tests/manual | |
parent | d5a6c1613b52ebc015aa85a46c1387909d435926 (diff) | |
parent | bf06924f3ffd22747c93a720caa501d8478dcbe6 (diff) |
Merge branch 'wip/highdpi' of git://code.qt.io/qt/qtbase into dev-highdpi
Conflicts:
src/plugins/platforms/xcb/qxcbscreen.cpp
src/plugins/platforms/xcb/qxcbwindow.cpp
Diffstat (limited to 'tests/manual')
-rw-r--r-- | tests/manual/cocoa/appicon/README | 3 | ||||
-rw-r--r-- | tests/manual/cocoa/appicon/appicon.pro | 4 | ||||
-rw-r--r-- | tests/manual/cocoa/appicon/main.cpp | 68 | ||||
-rw-r--r-- | tests/manual/cocoa/qt_on_cocoa/main.mm | 168 | ||||
-rw-r--r-- | tests/manual/cocoa/qt_on_cocoa/qt_on_cocoa.pro | 10 | ||||
-rw-r--r-- | tests/manual/cocoa/qt_on_cocoa/rasterwindow.cpp (renamed from tests/manual/cocoa/qt_on_cocoa/window.cpp) | 37 | ||||
-rw-r--r-- | tests/manual/cocoa/qt_on_cocoa/rasterwindow.h (renamed from tests/manual/cocoa/qt_on_cocoa/window.h) | 7 | ||||
-rw-r--r-- | tests/manual/diaglib/textdump.cpp | 29 | ||||
-rw-r--r-- | tests/manual/qscreen/main.cpp | 139 | ||||
-rw-r--r-- | tests/manual/qscreen/propertywatcher.cpp | 81 | ||||
-rw-r--r-- | tests/manual/qscreen/propertywatcher.h | 14 | ||||
-rw-r--r-- | tests/manual/qscreen/qscreen.pro | 1 |
12 files changed, 345 insertions, 216 deletions
diff --git a/tests/manual/cocoa/appicon/README b/tests/manual/cocoa/appicon/README new file mode 100644 index 0000000000..ecef1286ff --- /dev/null +++ b/tests/manual/cocoa/appicon/README @@ -0,0 +1,3 @@ +Test for checking that the dock icon is changed when +QGuiApplication::setWindowIcon() is called. Clicking the +buttong should change the entry in the dock to a red icon. diff --git a/tests/manual/cocoa/appicon/appicon.pro b/tests/manual/cocoa/appicon/appicon.pro new file mode 100644 index 0000000000..87df7b872c --- /dev/null +++ b/tests/manual/cocoa/appicon/appicon.pro @@ -0,0 +1,4 @@ +QT += widgets +TEMPLATE = app +TARGET = appicon +SOURCES += main.cpp diff --git a/tests/manual/cocoa/appicon/main.cpp b/tests/manual/cocoa/appicon/main.cpp new file mode 100644 index 0000000000..9e00e4e64c --- /dev/null +++ b/tests/manual/cocoa/appicon/main.cpp @@ -0,0 +1,68 @@ +/**************************************************************************** + ** + ** Copyright (C) 2015 The Qt Company Ltd. + ** Contact: http://www.qt.io/licensing/ + ** + ** This file is part of the test suite of the Qt Toolkit. + ** + ** $QT_BEGIN_LICENSE:LGPL21$ + ** Commercial License Usage + ** Licensees holding valid commercial Qt licenses may use this file in + ** accordance with the commercial license agreement provided with the + ** Software or, alternatively, in accordance with the terms contained in + ** a written agreement between you and The Qt Company. For licensing terms + ** and conditions see http://www.qt.io/terms-conditions. For further + ** information use the contact form at http://www.qt.io/contact-us. + ** + ** GNU Lesser General Public License Usage + ** Alternatively, this file may be used under the terms of the GNU Lesser + ** General Public License version 2.1 or version 3 as published by the Free + ** Software Foundation and appearing in the file LICENSE.LGPLv21 and + ** LICENSE.LGPLv3 included in the packaging of this file. Please review the + ** following information to ensure the GNU Lesser General Public License + ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and + ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. + ** + ** As a special exception, The Qt Company gives you certain additional + ** rights. These rights are described in The Qt Company LGPL Exception + ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. + ** + ** $QT_END_LICENSE$ + ** + ****************************************************************************/ + +#include <QApplication> +#include <QPushButton> +#include <QVBoxLayout> + +class TopWidget : public QWidget +{ + Q_OBJECT +public: + TopWidget(QWidget *parent = 0) : QWidget(parent) + { + QVBoxLayout *layout = new QVBoxLayout; + QPushButton *button = new QPushButton("Change app icon"); + connect(button, SIGNAL(clicked()), this, SLOT(changeIcon())); + layout->addWidget(button); + setLayout(layout); + } +public slots: + void changeIcon() + { + QPixmap pix(32, 32); + pix.fill(Qt::red); + QIcon i(pix); + qApp->setWindowIcon(i); + } +}; + +#include "main.moc" + +int main(int argc, char **argv) +{ + QApplication a(argc, argv); + TopWidget w; + w.show(); + return a.exec(); +} diff --git a/tests/manual/cocoa/qt_on_cocoa/main.mm b/tests/manual/cocoa/qt_on_cocoa/main.mm index 5dd546479e..23370b0305 100644 --- a/tests/manual/cocoa/qt_on_cocoa/main.mm +++ b/tests/manual/cocoa/qt_on_cocoa/main.mm @@ -31,123 +31,35 @@ ** ****************************************************************************/ -#include <QtGui> -#include <QtDeclarative> +#include "rasterwindow.h" +#include <QtGui> #include <QtWidgets/QtWidgets> -#include <private/qwidgetwindow_p.h> -#include <QtGui/qpa/qplatformnativeinterface.h> - -#include <QtGui/QPixmap> - -#include "window.h" #include <Cocoa/Cocoa.h> - -@interface FilledView : NSView -{ - +@interface AppDelegate : NSObject <NSApplicationDelegate> { + QGuiApplication *m_app; + QWindow *m_window; } +- (AppDelegate *) initWithArgc:(int)argc argv:(const char **)argv; +- (void) applicationWillFinishLaunching: (NSNotification *)notification; +- (void)applicationWillTerminate:(NSNotification *)notification; @end -@implementation FilledView - -- (void)drawRect:(NSRect)dirtyRect { - // set any NSColor for filling, say white: - [[NSColor redColor] setFill]; - NSRectFill(dirtyRect); -} - -@end - -@interface QtMacToolbarDelegate : NSObject <NSToolbarDelegate> +@implementation AppDelegate +- (AppDelegate *) initWithArgc:(int)argc argv:(const char **)argv { -@public - NSToolbar *toolbar; -} - -- (id)init; -- (NSToolbarItem *) toolbar: (NSToolbar *)toolbar itemForItemIdentifier: (NSString *) itemIdent willBeInsertedIntoToolbar:(BOOL) willBeInserted; -- (NSArray *)toolbarDefaultItemIdentifiers:(NSToolbar*)tb; -- (NSArray *)toolbarAllowedItemIdentifiers:(NSToolbar*)toolbar; -- (NSArray *)toolbarSelectableItemIdentifiers:(NSToolbar *)toolbar; -@end - -@implementation QtMacToolbarDelegate - -- (id)init -{ - self = [super init]; - if (self) { - } + m_app = new QGuiApplication(argc, const_cast<char **>(argv)); return self; } -- (void)dealloc -{ - [super dealloc]; -} - -- (NSArray *)toolbarDefaultItemIdentifiers:(NSToolbar*)tb -{ - Q_UNUSED(tb); - NSMutableArray *array = [[[NSMutableArray alloc] init] autorelease]; -// [array addObject : NSToolbarPrintItemIdentifier]; -// [array addObject : NSToolbarShowColorsItemIdentifier]; - [array addObject : @"filledView"]; - return array; -} - -- (NSArray *)toolbarAllowedItemIdentifiers:(NSToolbar*)tb -{ - Q_UNUSED(tb); - NSMutableArray *array = [[[NSMutableArray alloc] init] autorelease]; -// [array addObject : NSToolbarPrintItemIdentifier]; -// [array addObject : NSToolbarShowColorsItemIdentifier]; - [array addObject : @"filledView"]; - return array; -} - -- (NSArray *)toolbarSelectableItemIdentifiers: (NSToolbar *)tb -{ - Q_UNUSED(tb); - NSMutableArray *array = [[[NSMutableArray alloc] init] autorelease]; - return array; -} - -- (IBAction)itemClicked:(id)sender +- (void) applicationWillFinishLaunching: (NSNotification *)notification { + Q_UNUSED(notification); -} - -- (NSToolbarItem *) toolbar: (NSToolbar *)tb itemForItemIdentifier: (NSString *) itemIdentifier willBeInsertedIntoToolbar:(BOOL) willBeInserted -{ - Q_UNUSED(tb); - Q_UNUSED(willBeInserted); - //const QString identifier = toQString(itemIdentifier); - //NSToolbarItem *toolbarItem = [[[NSToolbarItem alloc] initWithItemIdentifier: itemIdentifier] autorelease]; - //return toolbarItem; - - //NSToolbarItem *toolbarItem = [[[NSToolbarItem alloc] initWithItemIdentifier: itemIdentifier] autorelease]; - NSToolbarItem *toolbarItem = [[[NSToolbarItem alloc] initWithItemIdentifier: itemIdentifier] autorelease]; - FilledView *theView = [[FilledView alloc] init]; - [toolbarItem setView : theView]; - [toolbarItem setMinSize : NSMakeSize(400, 40)]; - [toolbarItem setMaxSize : NSMakeSize(4000, 40)]; - return toolbarItem; -} -@end - -@interface WindowAndViewAndQtCreator : NSObject {} -- (void)createWindowAndViewAndQt; -@end - -@implementation WindowAndViewAndQtCreator -- (void)createWindowAndViewAndQt { - - // Create the window + // Create the NSWindow NSRect frame = NSMakeRect(500, 500, 500, 500); NSWindow* window = [[NSWindow alloc] initWithContentRect:frame styleMask:NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask | NSResizableWindowMask @@ -156,49 +68,31 @@ NSString *title = @"This the NSWindow window"; [window setTitle:title]; - [window setBackgroundColor:[NSColor blueColor]]; - // Create a tool bar, set Qt delegate - NSToolbar *toolbar = [[NSToolbar alloc] initWithIdentifier : @"foobartoolbar"]; - QtMacToolbarDelegate *delegate = [[QtMacToolbarDelegate alloc] init]; - [toolbar setDelegate : delegate]; - [window setToolbar : toolbar]; - - // Create the QWindow, don't show it. - Window *qtWindow = new Window(); - qtWindow->create(); - - //QSGView *qtWindow = new QSGView(); - //qtWindow->setSource(QUrl::fromLocalFile("/Users/msorvig/code/qt5/qtdeclarative/examples/declarative/samegame/samegame.qml")); - // qtWindow->setWindowFlags(Qt::WindowType(13)); // 13: NativeEmbeddedWindow - - // Get the nsview from the QWindow, set it as the content view - // on the NSWindow created above. - QPlatformNativeInterface *platformNativeInterface = QGuiApplication::platformNativeInterface(); - NSView *qtView = (NSView *)platformNativeInterface->nativeResourceForWindow("nsview", qtWindow); - [window setContentView:qtView]; + // Create the QWindow, use its NSView as the content view + m_window = new RasterWindow(); + [window setContentView:reinterpret_cast<NSView *>(m_window->winId())]; + + // Show the NSWindow [window makeKeyAndOrderFront:NSApp]; } -@end -int main(int argc, char *argv[]) +- (void)applicationWillTerminate:(NSNotification *)notification { - QGuiApplication app(argc, argv); - - // fake NSApplicationMain() implementation follows: - NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; - [NSApplication sharedApplication]; + Q_UNUSED(notification); + delete m_window; + delete m_app; +} - // schedule call to create the UI. - WindowAndViewAndQtCreator *windowAndViewAndQtCreator= [WindowAndViewAndQtCreator alloc]; - [NSTimer scheduledTimerWithTimeInterval:0 target:windowAndViewAndQtCreator selector:@selector(createWindowAndViewAndQt) userInfo:nil repeats:NO]; +@end - [(NSApplication *)NSApp run]; - [NSApp release]; - [pool release]; - exit(0); - return 0; +int main(int argc, const char *argv[]) +{ + // Create NSApplicaiton with delgate + NSApplication *app =[NSApplication sharedApplication]; + app.delegate = [[AppDelegate alloc] initWithArgc:argc argv:argv]; + return NSApplicationMain (argc, argv); } diff --git a/tests/manual/cocoa/qt_on_cocoa/qt_on_cocoa.pro b/tests/manual/cocoa/qt_on_cocoa/qt_on_cocoa.pro index 3d526909a5..97e4473e15 100644 --- a/tests/manual/cocoa/qt_on_cocoa/qt_on_cocoa.pro +++ b/tests/manual/cocoa/qt_on_cocoa/qt_on_cocoa.pro @@ -1,13 +1,11 @@ TEMPLATE = app OBJECTIVE_SOURCES += main.mm -HEADERS += window.h -SOURCES += window.cpp +HEADERS += rasterwindow.h +SOURCES += rasterwindow.cpp LIBS += -framework Cocoa -QMAKE_INFO_PLIST = Info_mac.plist -OTHER_FILES = Info_mac.plist -QT += gui widgets widgets-private gui-private core-private +QT += gui widgets quick -QT += declarative +QT += quick DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0 diff --git a/tests/manual/cocoa/qt_on_cocoa/window.cpp b/tests/manual/cocoa/qt_on_cocoa/rasterwindow.cpp index 9929a50065..9b8f5e63ce 100644 --- a/tests/manual/cocoa/qt_on_cocoa/window.cpp +++ b/tests/manual/cocoa/qt_on_cocoa/rasterwindow.cpp @@ -31,9 +31,9 @@ ** ****************************************************************************/ -#include "window.h" +#include "rasterwindow.h" -#include <private/qguiapplication_p.h> +//#include <private/qguiapplication_p.h> #include <QBackingStore> #include <QPainter> @@ -48,21 +48,14 @@ QColor colorTable[] = QColor("#c0ef8f") }; -Window::Window(QScreen *screen) - : QWindow(screen) +RasterWindow::RasterWindow(QRasterWindow *parent) + : QRasterWindow(parent) , m_backgroundColorIndex(colorIndexId++) { initialize(); } -Window::Window(QWindow *parent) - : QWindow(parent) - , m_backgroundColorIndex(colorIndexId++) -{ - initialize(); -} - -void Window::initialize() +void RasterWindow::initialize() { if (parent()) setGeometry(QRect(160, 120, 320, 240)); @@ -85,12 +78,12 @@ void Window::initialize() m_renderTimer = 0; } -void Window::mousePressEvent(QMouseEvent *event) +void RasterWindow::mousePressEvent(QMouseEvent *event) { m_lastPos = event->pos(); } -void Window::mouseMoveEvent(QMouseEvent *event) +void RasterWindow::mouseMoveEvent(QMouseEvent *event) { if (m_lastPos != QPoint(-1, -1)) { QPainter p(&m_image); @@ -102,7 +95,7 @@ void Window::mouseMoveEvent(QMouseEvent *event) scheduleRender(); } -void Window::mouseReleaseEvent(QMouseEvent *event) +void RasterWindow::mouseReleaseEvent(QMouseEvent *event) { if (m_lastPos != QPoint(-1, -1)) { QPainter p(&m_image); @@ -114,16 +107,16 @@ void Window::mouseReleaseEvent(QMouseEvent *event) scheduleRender(); } -void Window::exposeEvent(QExposeEvent *) +void RasterWindow::exposeEvent(QExposeEvent *) { scheduleRender(); } -void Window::resizeEvent(QResizeEvent *) +void RasterWindow::resizeEvent(QResizeEvent *) { QImage old = m_image; - //qDebug() << "Window::resizeEvent" << width << height; + //qDebug() << "RasterWindow::resizeEvent" << width << height; int width = qMax(geometry().width(), old.width()); int height = qMax(geometry().height(), old.height()); @@ -139,7 +132,7 @@ void Window::resizeEvent(QResizeEvent *) render(); } -void Window::keyPressEvent(QKeyEvent *event) +void RasterWindow::keyPressEvent(QKeyEvent *event) { switch (event->key()) { case Qt::Key_Backspace: @@ -156,20 +149,20 @@ void Window::keyPressEvent(QKeyEvent *event) scheduleRender(); } -void Window::scheduleRender() +void RasterWindow::scheduleRender() { if (!m_renderTimer) m_renderTimer = startTimer(1); } -void Window::timerEvent(QTimerEvent *) +void RasterWindow::timerEvent(QTimerEvent *) { render(); killTimer(m_renderTimer); m_renderTimer = 0; } -void Window::render() +void RasterWindow::render() { QRect rect(QPoint(), geometry().size()); diff --git a/tests/manual/cocoa/qt_on_cocoa/window.h b/tests/manual/cocoa/qt_on_cocoa/rasterwindow.h index a36180e0f3..1de66b5302 100644 --- a/tests/manual/cocoa/qt_on_cocoa/window.h +++ b/tests/manual/cocoa/qt_on_cocoa/rasterwindow.h @@ -31,14 +31,13 @@ ** ****************************************************************************/ -#include <QWindow> +#include <QRasterWindow> #include <QImage> -class Window : public QWindow +class RasterWindow : public QRasterWindow { public: - Window(QWindow *parent = 0); - Window(QScreen *screen); + RasterWindow(QRasterWindow *parent = 0); protected: void mousePressEvent(QMouseEvent *); diff --git a/tests/manual/diaglib/textdump.cpp b/tests/manual/diaglib/textdump.cpp index 40295f8833..ed4d5021be 100644 --- a/tests/manual/diaglib/textdump.cpp +++ b/tests/manual/diaglib/textdump.cpp @@ -222,6 +222,32 @@ static const EnumLookup scriptEnumLookup[] = {QChar::Script_Sharada, "Script_Sharada"}, {QChar::Script_SoraSompeng, "Script_SoraSompeng"}, {QChar::Script_Takri, "Script_Takri"}, + +#if QT_VERSION >= 0x050500 + {QChar::Script_CaucasianAlbanian, "Script_CaucasianAlbanian"}, + {QChar::Script_BassaVah, "Script_BassaVah"}, + {QChar::Script_Duployan, "Script_Duployan"}, + {QChar::Script_Elbasan, "Script_Elbasan"}, + {QChar::Script_Grantha, "Script_Grantha"}, + {QChar::Script_PahawhHmong, "Script_PahawhHmong"}, + {QChar::Script_Khojki, "Script_Khojki"}, + {QChar::Script_LinearA, "Script_LinearA"}, + {QChar::Script_Mahajani, "Script_Mahajani"}, + {QChar::Script_Manichaean, "Script_Manichaean"}, + {QChar::Script_MendeKikakui, "Script_MendeKikakui"}, + {QChar::Script_Modi, "Script_Modi"}, + {QChar::Script_Mro, "Script_Mro"}, + {QChar::Script_OldNorthArabian, "Script_OldNorthArabian"}, + {QChar::Script_Nabataean, "Script_Nabataean"}, + {QChar::Script_Palmyrene, "Script_Palmyrene"}, + {QChar::Script_PauCinHau, "Script_PauCinHau"}, + {QChar::Script_OldPermic, "Script_OldPermic"}, + {QChar::Script_PsalterPahlavi, "Script_PsalterPahlavi"}, + {QChar::Script_Siddham, "Script_Siddham"}, + {QChar::Script_Khudawadi, "Script_Khudawadi"}, + {QChar::Script_Tirhuta, "Script_Tirhuta"}, + {QChar::Script_WarangCiti, "Script_WarangCiti"}, +#endif // Qt 5.5 }; #endif // Qt 5.1 @@ -335,6 +361,9 @@ static const EnumLookup unicodeVersionEnumLookup[] = {QChar::Unicode_6_1, "Unicode_6_1"}, {QChar::Unicode_6_2, "Unicode_6_2"}, {QChar::Unicode_6_3, "Unicode_6_3"}, +#if QT_VERSION >= 0x050500 + {QChar::Unicode_7_0, "Unicode_7_0"}, +#endif // Qt 5.5 #endif // Qt 5 }; diff --git a/tests/manual/qscreen/main.cpp b/tests/manual/qscreen/main.cpp index 6f672ee422..ef9c2efe19 100644 --- a/tests/manual/qscreen/main.cpp +++ b/tests/manual/qscreen/main.cpp @@ -36,22 +36,117 @@ #include <QScreen> #include <QWindow> #include <QDebug> +#include <QTextStream> #include <QFormLayout> +#include <QMainWindow> +#include <QMenu> +#include <QMenuBar> +#include <QAction> +#include <QStatusBar> #include <QLineEdit> -int i = 0; +class ScreenPropertyWatcher : public PropertyWatcher +{ + Q_OBJECT +public: + ScreenPropertyWatcher(QWidget *wp = Q_NULLPTR) : PropertyWatcher(Q_NULLPTR, QString(), wp) + { + // workaround for the fact that virtualSiblings is not a property, + // thus there is no change notification: + // allow the user to update the field manually + connect(this, &PropertyWatcher::updatedAllFields, this, &ScreenPropertyWatcher::updateSiblings); + } + + QScreen *screenSubject() const { return qobject_cast<QScreen *>(subject()); } + void setScreenSubject(QScreen *s, const QString &annotation = QString()) + { + setSubject(s, annotation); + updateSiblings(); + } -typedef QHash<QScreen*, PropertyWatcher*> ScreensHash; -Q_GLOBAL_STATIC(ScreensHash, props); +public slots: + void updateSiblings(); +}; -void updateSiblings(PropertyWatcher* w) +void ScreenPropertyWatcher::updateSiblings() { - QLineEdit *siblingsField = w->findChild<QLineEdit *>("siblings"); - QScreen* screen = (QScreen*)w->subject(); - QStringList siblingsList; - foreach (QScreen *sibling, screen->virtualSiblings()) - siblingsList << sibling->name(); - siblingsField->setText(siblingsList.join(", ")); + const QScreen *screen = screenSubject(); + if (!screen) + return; + const QString objectName = QLatin1String("siblings"); + QLineEdit *siblingsField = findChild<QLineEdit *>(objectName); + if (!siblingsField) { + siblingsField = new QLineEdit(this); + siblingsField->setObjectName(objectName); + siblingsField->setReadOnly(true); + formLayout()->insertRow(0, QLatin1String("virtualSiblings"), siblingsField); + } + QString text; + foreach (const QScreen *sibling, screen->virtualSiblings()) { + if (!text.isEmpty()) + text += QLatin1String(", "); + text += sibling->name(); + } + siblingsField->setText(text); +} + +class ScreenWatcherMainWindow : public QMainWindow +{ + Q_OBJECT +public: + explicit ScreenWatcherMainWindow(QScreen *screen); + + QScreen *screenSubject() const { return m_watcher->screenSubject(); } + +protected: + bool event(QEvent *event) Q_DECL_OVERRIDE; + +private: + const QString m_annotation; + ScreenPropertyWatcher *m_watcher; +}; + +static int i = 0; + +ScreenWatcherMainWindow::ScreenWatcherMainWindow(QScreen *screen) + : m_annotation(QLatin1Char('#') + QString::number(i++)) + , m_watcher(new ScreenPropertyWatcher(this)) +{ + setAttribute(Qt::WA_DeleteOnClose); + setCentralWidget(m_watcher); + m_watcher->setScreenSubject(screen, m_annotation); + + QMenu *fileMenu = menuBar()->addMenu(QLatin1String("&File")); + QAction *a = fileMenu->addAction(QLatin1String("Close")); + a->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_W)); + connect(a, SIGNAL(triggered()), this, SLOT(close())); + a = fileMenu->addAction(QLatin1String("Quit")); + a->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_Q)); + connect(a, SIGNAL(triggered()), qApp, SLOT(quit())); +} + +static inline QString msgScreenChange(const QWidget *w, const QScreen *oldScreen, const QScreen *newScreen) +{ + QString result; + const QRect geometry = w->geometry(); + const QPoint pos = QCursor::pos(); + QTextStream(&result) << "Screen changed \"" << oldScreen->name() << "\" --> \"" + << newScreen->name() << "\" at " << pos.x() << ',' << pos.y() << " geometry: " + << geometry.width() << 'x' << geometry.height() << forcesign << geometry.x() + << geometry.y() << '.'; + return result; +} + +bool ScreenWatcherMainWindow::event(QEvent *event) +{ + if (event->type() == QEvent::ScreenChangeInternal) { + QScreen *newScreen = windowHandle()->screen(); + const QString message = msgScreenChange(this, m_watcher->screenSubject(), newScreen); + qDebug().noquote() << message; + statusBar()->showMessage(message); + m_watcher->setScreenSubject(newScreen, m_annotation); + } + return QMainWindow::event(event); } void screenAdded(QScreen* screen) @@ -59,12 +154,7 @@ void screenAdded(QScreen* screen) screen->setOrientationUpdateMask((Qt::ScreenOrientations)0x0F); qDebug("\nscreenAdded %s siblings %d first %s", qPrintable(screen->name()), screen->virtualSiblings().count(), (screen->virtualSiblings().isEmpty() ? "none" : qPrintable(screen->virtualSiblings().first()->name()))); - PropertyWatcher *w = new PropertyWatcher(screen, QString::number(i++)); - QLineEdit *siblingsField = new QLineEdit(); - siblingsField->setObjectName("siblings"); - siblingsField->setReadOnly(true); - w->layout()->insertRow(0, "virtualSiblings", siblingsField); - updateSiblings(w); + ScreenWatcherMainWindow *w = new ScreenWatcherMainWindow(screen); // This doesn't work. If the multiple screens are part of // a virtual desktop (i.e. they are virtual siblings), then @@ -85,18 +175,17 @@ void screenAdded(QScreen* screen) geom.setHeight(screen->geometry().height() * 9 / 10); geom.moveCenter(screen->geometry().center()); w->setGeometry(geom); - - props->insert(screen, w); - - // workaround for the fact that virtualSiblings is not a property, - // thus there is no change notification: - // allow the user to update the field manually - QObject::connect(w, &PropertyWatcher::updatedAllFields, &updateSiblings); } void screenRemoved(QScreen* screen) { - delete props->take(screen); + const QWidgetList topLevels = QApplication::topLevelWidgets(); + for (int i = topLevels.size() - 1; i >= 0; --i) { + if (ScreenWatcherMainWindow *sw = qobject_cast<ScreenWatcherMainWindow *>(topLevels.at(i))) { + if (sw->screenSubject() == screen) + sw->close(); + } + } } int main(int argc, char *argv[]) @@ -109,3 +198,5 @@ int main(int argc, char *argv[]) QObject::connect((const QGuiApplication*)QGuiApplication::instance(), &QGuiApplication::screenRemoved, &screenRemoved); return a.exec(); } + +#include "main.moc" diff --git a/tests/manual/qscreen/propertywatcher.cpp b/tests/manual/qscreen/propertywatcher.cpp index 19668a8d26..b745ef5125 100644 --- a/tests/manual/qscreen/propertywatcher.cpp +++ b/tests/manual/qscreen/propertywatcher.cpp @@ -35,35 +35,82 @@ #include <QMetaProperty> #include <QFormLayout> #include <QPushButton> +#include <QLabel> #include "propertyfield.h" PropertyWatcher::PropertyWatcher(QObject *subject, QString annotation, QWidget *parent) - : QWidget(parent), m_subject(subject), m_layout(new QFormLayout) + : QWidget(parent), m_subject(Q_NULLPTR), m_formLayout(new QFormLayout(this)) { - setWindowTitle(QString("Properties of %1 %2 %3") - .arg(subject->metaObject()->className()).arg(subject->objectName()).arg(annotation)); setMinimumSize(450, 300); + m_formLayout->setFieldGrowthPolicy(QFormLayout::ExpandingFieldsGrow); + setSubject(subject, annotation); +} + +class UpdatesEnabledBlocker +{ + Q_DISABLE_COPY(UpdatesEnabledBlocker); +public: + explicit UpdatesEnabledBlocker(QWidget *w) : m_widget(w) + { + m_widget->setUpdatesEnabled(false); + } + ~UpdatesEnabledBlocker() + { + m_widget->setUpdatesEnabled(true); + m_widget->update(); + } + +private: + QWidget *m_widget; +}; + +void PropertyWatcher::setSubject(QObject *s, const QString &annotation) +{ + if (s == m_subject) + return; + + UpdatesEnabledBlocker blocker(this); + + if (m_subject) { + disconnect(m_subject, &QObject::destroyed, this, &PropertyWatcher::subjectDestroyed); + for (int i = m_formLayout->count() - 1; i >= 0; --i) { + QLayoutItem *item = m_formLayout->takeAt(i); + delete item->widget(); + delete item; + } + window()->setWindowTitle(QString()); + window()->setWindowIconText(QString()); + } + + m_subject = s; + if (!m_subject) + return; + const QMetaObject* meta = m_subject->metaObject(); + QString title = QLatin1String("Properties ") + QLatin1String(meta->className()); + if (!m_subject->objectName().isEmpty()) + title += QLatin1Char(' ') + m_subject->objectName(); + if (!annotation.isEmpty()) + title += QLatin1Char(' ') + annotation; + window()->setWindowTitle(title); - for (int i = 0; i < meta->propertyCount(); ++i) { - QMetaProperty prop = meta->property(i); + for (int i = 0, count = meta->propertyCount(); i < count; ++i) { + const QMetaProperty prop = meta->property(i); if (prop.isReadable()) { - PropertyField* field = new PropertyField(m_subject, prop); - m_layout->addRow(prop.name(), field); + QLabel *label = new QLabel(prop.name(), this); + PropertyField *field = new PropertyField(m_subject, prop, this); + m_formLayout->addRow(label, field); if (!qstrcmp(prop.name(), "name")) - setWindowIconText(prop.read(subject).toString()); + window()->setWindowIconText(prop.read(m_subject).toString()); + label->setVisible(true); + field->setVisible(true); } } - QPushButton *updateButton = new QPushButton("update"); - connect(updateButton, &QPushButton::clicked, this, &PropertyWatcher::updateAllFields); - m_layout->addRow("", updateButton); - m_layout->setFieldGrowthPolicy(QFormLayout::ExpandingFieldsGrow); - setLayout(m_layout); - connect(subject, &QObject::destroyed, this, &PropertyWatcher::subjectDestroyed); -} + connect(m_subject, &QObject::destroyed, this, &PropertyWatcher::subjectDestroyed); -PropertyWatcher::~PropertyWatcher() -{ + QPushButton *updateButton = new QPushButton(QLatin1String("Update"), this); + connect(updateButton, &QPushButton::clicked, this, &PropertyWatcher::updateAllFields); + m_formLayout->addRow(QString(), updateButton); } void PropertyWatcher::updateAllFields() diff --git a/tests/manual/qscreen/propertywatcher.h b/tests/manual/qscreen/propertywatcher.h index 7dccfe3672..01e448845a 100644 --- a/tests/manual/qscreen/propertywatcher.h +++ b/tests/manual/qscreen/propertywatcher.h @@ -44,10 +44,12 @@ class PropertyWatcher : public QWidget Q_OBJECT public: - PropertyWatcher(QObject* subject, QString annotation = QString(), QWidget *parent = 0); - ~PropertyWatcher(); - QFormLayout *layout() { return m_layout; } - QObject* subject() { return m_subject; } + explicit PropertyWatcher(QObject* subject = Q_NULLPTR, QString annotation = QString(), QWidget *parent = Q_NULLPTR); + + QFormLayout *formLayout() { return m_formLayout; } + + QObject *subject() const { return m_subject; } + void setSubject(QObject *s, const QString &annotation = QString()); public slots: void updateAllFields(); @@ -56,9 +58,9 @@ public slots: signals: void updatedAllFields(PropertyWatcher* sender); -protected: +private: QObject* m_subject; - QFormLayout * m_layout; + QFormLayout * m_formLayout; }; #endif // PROPERTY_WATCHER_H diff --git a/tests/manual/qscreen/qscreen.pro b/tests/manual/qscreen/qscreen.pro index cec8bbf245..5d587db3f4 100644 --- a/tests/manual/qscreen/qscreen.pro +++ b/tests/manual/qscreen/qscreen.pro @@ -1,4 +1,5 @@ QT += core gui widgets +CONFIG += console TARGET = qscreen TEMPLATE = app |