diff options
Diffstat (limited to 'tests/manual')
-rw-r--r-- | tests/manual/cocoa/qmaccocoaviewcontainer/TestMouseMovedNSView.h | 7 | ||||
-rw-r--r-- | tests/manual/cocoa/qmaccocoaviewcontainer/TestMouseMovedNSView.m | 25 | ||||
-rw-r--r-- | tests/manual/cocoa/qmaccocoaviewcontainer/main.mm | 2 | ||||
-rw-r--r-- | tests/manual/cocoa/qt_on_cocoa/main.mm | 32 | ||||
-rw-r--r-- | tests/manual/highdpi/main.cpp | 82 |
5 files changed, 112 insertions, 36 deletions
diff --git a/tests/manual/cocoa/qmaccocoaviewcontainer/TestMouseMovedNSView.h b/tests/manual/cocoa/qmaccocoaviewcontainer/TestMouseMovedNSView.h index be716aa582..4a145a729f 100644 --- a/tests/manual/cocoa/qmaccocoaviewcontainer/TestMouseMovedNSView.h +++ b/tests/manual/cocoa/qmaccocoaviewcontainer/TestMouseMovedNSView.h @@ -28,10 +28,5 @@ #import <AppKit/AppKit.h> -@interface TestMouseMovedNSView : NSView { - NSPoint mouseMovedPoint_; - BOOL wasAcceptingMouseEvents_; - NSTrackingRectTag trackingRect_; - NSTrackingArea* trackingArea_; -} +@interface TestMouseMovedNSView : NSView @end diff --git a/tests/manual/cocoa/qmaccocoaviewcontainer/TestMouseMovedNSView.m b/tests/manual/cocoa/qmaccocoaviewcontainer/TestMouseMovedNSView.m index 65b42dbb2f..20a3fcc513 100644 --- a/tests/manual/cocoa/qmaccocoaviewcontainer/TestMouseMovedNSView.m +++ b/tests/manual/cocoa/qmaccocoaviewcontainer/TestMouseMovedNSView.m @@ -28,9 +28,14 @@ #import "TestMouseMovedNSView.h" -@implementation TestMouseMovedNSView +@implementation TestMouseMovedNSView { + NSPoint mouseMovedPoint_; + BOOL wasAcceptingMouseEvents_; + NSTrackingRectTag trackingRect_; + NSTrackingArea* trackingArea_; +} -- (id)initWithFrame:(NSRect)frame +- (instancetype)initWithFrame:(NSRect)frame { self = [super initWithFrame:frame]; if (self) @@ -40,13 +45,13 @@ - (void)viewDidMoveToWindow { - trackingArea_ = [[NSTrackingArea alloc] initWithRect:[self bounds] options: (NSTrackingMouseEnteredAndExited | NSTrackingActiveAlways) owner:self userInfo:nil]; + trackingArea_ = [[NSTrackingArea alloc] initWithRect:self.bounds options:(NSTrackingMouseEnteredAndExited | NSTrackingActiveAlways) owner:self userInfo:nil]; [self addTrackingArea:trackingArea_]; } - (void)viewWillMoveToWindow:(NSWindow *)newWindow { - if ([self window] && trackingArea_) + if (self.window && trackingArea_) [self removeTrackingArea:trackingArea_]; } @@ -54,7 +59,7 @@ { [super updateTrackingAreas]; [self removeTrackingArea: trackingArea_]; - trackingArea_ = [[NSTrackingArea alloc] initWithRect:[self bounds] options: (NSTrackingMouseEnteredAndExited | NSTrackingActiveAlways) owner:self userInfo:nil]; + trackingArea_ = [[NSTrackingArea alloc] initWithRect:self.bounds options:(NSTrackingMouseEnteredAndExited | NSTrackingActiveAlways) owner:self userInfo:nil]; [self addTrackingArea:trackingArea_]; } @@ -64,20 +69,20 @@ - (void)mouseEntered:(NSEvent *)theEvent { wasAcceptingMouseEvents_ = [[self window] acceptsMouseMovedEvents]; - [[self window] setAcceptsMouseMovedEvents:YES]; - [[self window] makeFirstResponder:self]; + [self.window setAcceptsMouseMovedEvents:YES]; + [self.window makeFirstResponder:self]; } - (void)mouseExited:(NSEvent *)theEvent { - [[self window] setAcceptsMouseMovedEvents:wasAcceptingMouseEvents_]; + [self.window setAcceptsMouseMovedEvents:wasAcceptingMouseEvents_]; [self setNeedsDisplay:YES]; [self displayIfNeeded]; } -(void)mouseMoved:(NSEvent *)pTheEvent { - mouseMovedPoint_ = [self convertPoint:[pTheEvent locationInWindow] fromView:nil]; + mouseMovedPoint_ = [self convertPoint:pTheEvent.locationInWindow fromView:nil]; [self setNeedsDisplay:YES]; [self displayIfNeeded]; } @@ -88,7 +93,7 @@ NSRectFill(dirtyRect); NSGraphicsContext *nsGraphicsContext = [NSGraphicsContext currentContext]; - CGContextRef cgContextRef = (CGContextRef) [nsGraphicsContext graphicsPort]; + CGContextRef cgContextRef = nsGraphicsContext.CGContext; CGContextSetRGBStrokeColor(cgContextRef, 0, 0, 0, .5); CGContextSetLineWidth(cgContextRef, 1.0); diff --git a/tests/manual/cocoa/qmaccocoaviewcontainer/main.mm b/tests/manual/cocoa/qmaccocoaviewcontainer/main.mm index 9cf06391ca..8b05b64a1e 100644 --- a/tests/manual/cocoa/qmaccocoaviewcontainer/main.mm +++ b/tests/manual/cocoa/qmaccocoaviewcontainer/main.mm @@ -83,7 +83,7 @@ int main(int argc, char **argv) w.resize(300, 300); w.setWindowTitle("QMacCocoaViewContainer"); NSRect r = NSMakeRect(0, 0, 100, 100); - NSView *view = [[TestMouseMovedNSView alloc] initWithFrame: r]; + NSView *view = [[TestMouseMovedNSView alloc] initWithFrame:r]; QMacCocoaViewContainer *nativeChild = new QMacCocoaViewContainer(view, &w); QVBoxLayout *vbox = new QVBoxLayout; vbox->addWidget(nativeChild); diff --git a/tests/manual/cocoa/qt_on_cocoa/main.mm b/tests/manual/cocoa/qt_on_cocoa/main.mm index 805ef0d7c2..e6218e48ac 100644 --- a/tests/manual/cocoa/qt_on_cocoa/main.mm +++ b/tests/manual/cocoa/qt_on_cocoa/main.mm @@ -50,31 +50,30 @@ } @end -@interface AppDelegate : NSObject <NSApplicationDelegate> { +@interface AppDelegate : NSObject <NSApplicationDelegate> +@end + +@implementation AppDelegate { QGuiApplication *m_app; QWindow *m_window; } -- (AppDelegate *) initWithArgc:(int)argc argv:(const char **)argv; -- (void) applicationWillFinishLaunching: (NSNotification *)notification; -- (void)applicationWillTerminate:(NSNotification *)notification; -@end - -@implementation AppDelegate -- (AppDelegate *) initWithArgc:(int)argc argv:(const char **)argv +- (instancetype)initWithArgc:(int)argc argv:(const char **)argv { - m_app = new QGuiApplication(argc, const_cast<char **>(argv)); + if ((self = [self init])) { + m_app = new QGuiApplication(argc, const_cast<char **>(argv)); + } return self; } -- (void) applicationWillFinishLaunching: (NSNotification *)notification +- (void)applicationWillFinishLaunching:(NSNotification *)notification { Q_UNUSED(notification); // Create the NSWindow NSRect frame = NSMakeRect(500, 500, 500, 500); - NSWindow* window = [[NSWindow alloc] initWithContentRect:frame - styleMask:NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask | NSResizableWindowMask + NSWindow *window = [[NSWindow alloc] initWithContentRect:frame + styleMask:NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask | NSResizableWindowMask backing:NSBackingStoreBuffered defer:NO]; @@ -100,7 +99,7 @@ childWindow->setGeometry(50, 50, 100, 100); NSTextField *textField = [[NSTextField alloc] initWithFrame:NSMakeRect(10, 10, 80, 25)]; - [(NSView*)childWindow->winId() addSubview:textField]; + [reinterpret_cast<NSView *>(childWindow->winId()) addSubview:textField]; [contentView addSubview:reinterpret_cast<NSView *>(m_window->winId())]; @@ -125,10 +124,7 @@ int main(int argc, const char *argv[]) { // Create NSApplicaiton with delgate - NSApplication *app =[NSApplication sharedApplication]; + NSApplication *app = [NSApplication sharedApplication]; app.delegate = [[AppDelegate alloc] initWithArgc:argc argv:argv]; - return NSApplicationMain (argc, argv); + return NSApplicationMain(argc, argv); } - - - diff --git a/tests/manual/highdpi/main.cpp b/tests/manual/highdpi/main.cpp index bd6af75b16..50ad164597 100644 --- a/tests/manual/highdpi/main.cpp +++ b/tests/manual/highdpi/main.cpp @@ -45,6 +45,8 @@ #include <QPainter> #include <QWindow> #include <QScreen> +#include <QGraphicsView> +#include <QGraphicsTextItem> #include <QFile> #include <QMouseEvent> #include <QTemporaryDir> @@ -334,6 +336,59 @@ void PixmapPainter::paintEvent(QPaintEvent *) x+=dx * 2; p.drawImage(QRect(x, y, pixmapPointSize * 2, pixmapPointSize * 2), imageLarge); } +class TiledPixmapPainter : public QWidget +{ +public: + QPixmap pixmap1X; + QPixmap pixmap2X; + QPixmap pixmapLarge; + + TiledPixmapPainter(); + void paintEvent(QPaintEvent *event); +}; + +TiledPixmapPainter::TiledPixmapPainter() +{ + pixmap1X = QPixmap(":/qticon32.png"); + pixmap2X = QPixmap(":/qticon32@2x.png"); + pixmapLarge = QPixmap(":/qticon64.png"); +} + +void TiledPixmapPainter::paintEvent(QPaintEvent *event) +{ + QPainter p(this); + + int xoff = 10; + int yoff = 10; + int tiles = 4; + int pixmapEdge = 32; + int tileAreaEdge = pixmapEdge * tiles; + + // Expected behavior for both 1x and 2x dislays: + // 1x pixmap : 4 x 4 tiles + // large pixmap: 2 x 2 tiles + // 2x pixmap : 4 x 4 tiles + // + // On a 2x display the 2x pimxap tiles + // will be drawn in high resolution. + p.drawTiledPixmap(QRect(xoff, yoff, tileAreaEdge, tileAreaEdge), pixmap1X); + yoff += tiles * pixmapEdge + 10; + p.drawTiledPixmap(QRect(xoff, yoff, tileAreaEdge, tileAreaEdge), pixmapLarge); + yoff += tiles * pixmapEdge + 10; + p.drawTiledPixmap(QRect(xoff, yoff, tileAreaEdge, tileAreaEdge), pixmap2X); + + // Again, with an offset. The offset is in + // device-independent pixels. + QPoint offset(40, 40); // larger than the pixmap edge size to exercise that code path + yoff = 10; + xoff = 20 + tiles * pixmapEdge ; + p.drawTiledPixmap(QRect(xoff, yoff, tileAreaEdge, tileAreaEdge), pixmap1X, offset); + yoff += tiles * pixmapEdge + 10; + p.drawTiledPixmap(QRect(xoff, yoff, tileAreaEdge, tileAreaEdge), pixmapLarge, offset); + yoff += tiles * pixmapEdge + 10; + p.drawTiledPixmap(QRect(xoff, yoff, tileAreaEdge, tileAreaEdge), pixmap2X, offset); +} + class Labels : public QWidget { public: @@ -1098,6 +1153,30 @@ void PhysicalSizeTest::paintEvent(QPaintEvent *) } +class GraphicsViewCaching : public QGraphicsView +{ +public: + GraphicsViewCaching() { + QGraphicsScene *scene = new QGraphicsScene(0, 0, 400, 400); + + QGraphicsTextItem *item = 0; + + item = scene->addText("NoCache"); + item->setCacheMode(QGraphicsItem::NoCache); + item->setPos(10, 10); + + item = scene->addText("ItemCoordinateCache"); + item->setCacheMode(QGraphicsItem::ItemCoordinateCache); + item->setPos(10, 30); + + item = scene->addText("DeviceCoordinateCache"); + item->setCacheMode(QGraphicsItem::DeviceCoordinateCache); + item->setPos(10, 50); + + setScene(scene); + } +}; + int main(int argc, char **argv) { QApplication app(argc, argv); @@ -1119,6 +1198,7 @@ int main(int argc, char **argv) DemoContainerList demoList; demoList << new DemoContainer<PixmapPainter>("pixmap", "Test pixmap painter"); + demoList << new DemoContainer<TiledPixmapPainter>("tiledpixmap", "Test tiled pixmap painter"); demoList << new DemoContainer<Labels>("label", "Test Labels"); demoList << new DemoContainer<MainWindow>("mainwindow", "Test QMainWindow"); demoList << new DemoContainer<StandardIcons>("standard-icons", "Test standard icons"); @@ -1132,7 +1212,7 @@ int main(int argc, char **argv) demoList << new DemoContainer<CursorTester>("cursorpos", "Test cursor and window positioning"); demoList << new DemoContainer<ScreenDisplayer>("screens", "Test screen and window positioning"); demoList << new DemoContainer<PhysicalSizeTest>("physicalsize", "Test manual highdpi support using physicalDotsPerInch"); - + demoList << new DemoContainer<GraphicsViewCaching>("graphicsview", "Test QGraphicsView caching"); foreach (DemoContainerBase *demo, demoList) parser.addOption(demo->option()); |