Debian Codegraph @

tests/manual/cocoa/qmaccocoaviewcontainer/main.mm

raw
1 /****************************************************************************
2 **
3 ** Copyright (C) 2016 The Qt Company Ltd.
4 ** Contact: https://www.qt.io/licensing/
5 **
6 ** This file is part of the test suite of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:GPL-EXCEPT$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and The Qt Company. For licensing terms
14 ** and conditions see https://www.qt.io/terms-conditions. For further
15 ** information use the contact form at https://www.qt.io/contact-us.
16 **
17 ** GNU General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU
19 ** General Public License version 3 as published by the Free Software
20 ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
21 ** included in the packaging of this file. Please review the following
22 ** information to ensure the GNU General Public License requirements will
23 ** be met: https://www.gnu.org/licenses/gpl-3.0.html.
24 **
25 ** $QT_END_LICENSE$
26 **
27 ****************************************************************************/
28
29
30 #import "TestMouseMovedNSView.h"
31 #include <QtGui>
32 #include <QtWidgets>
33 #include <QMacCocoaViewContainer>
34
35 class MyWidget : public QWidget
36 {
37 Q_OBJECT
38 public:
39 MyWidget(QMacCocoaViewContainer *c, QWidget *parent = 0) : QWidget(parent), container(c), currentlyVisible(true)
40 {
41 QVBoxLayout *vbox = new QVBoxLayout;
42 QLabel *label = new QLabel("1: Check that the cross hairs move when the mouse is moved over the widget\n"
43 "2: Check that clicking on change visibility causes the NSView to hide/show as appropriate\n"
44 "3: Check that clicking on resize makes the view be 200x200");
45 vbox->addWidget(label);
46 QPushButton *button = new QPushButton("Change visibility");
47 connect(button, SIGNAL(clicked()), this, SLOT(changeVisibility()));
48 vbox->addWidget(button);
49 button = new QPushButton("Change size");
50 connect(button, SIGNAL(clicked()), this, SLOT(changeSize()));
51 vbox->addWidget(button);
52 setLayout(vbox);
53 }
54 public slots:
55 void changeVisibility()
56 {
57 currentlyVisible = !currentlyVisible;
58 if (!currentlyVisible)
59 container->hide();
60 else
61 container->show();
62 bool b = !([(NSView *)container->cocoaView() isHidden]);
63 QMessageBox::information(this, "Is visible", QString("NSView visibility: %1").arg(b));
64 }
65 void changeSize()
66 {
67 NSRect r = NSMakeRect(0, 0, 200, 200);
68 [(NSView *)container->cocoaView() setFrame:r];
69 }
70 private:
71 QMacCocoaViewContainer *container;
72 bool currentlyVisible;
73 };
74
75 #include "main.moc"
76
77 int main(int argc, char **argv)
78 {
79 QApplication a(argc, argv);
80 QPoint pos(100,100);
81 QWidget w;
82 w.move(pos);
83 w.resize(300, 300);
84 w.setWindowTitle("QMacCocoaViewContainer");
85 NSRect r = NSMakeRect(0, 0, 100, 100);
86 NSView *view = [[TestMouseMovedNSView alloc] initWithFrame:r];
87 QMacCocoaViewContainer *nativeChild = new QMacCocoaViewContainer(view, &w);
88 QVBoxLayout *vbox = new QVBoxLayout;
89 vbox->addWidget(nativeChild);
90 w.setLayout(vbox);
91 w.show();
92 MyWidget w2(nativeChild);
93 w2.show();
94 return a.exec();
95 }
96