1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
---|
4 | ** All rights reserved.
|
---|
5 | ** Contact: Nokia Corporation ([email protected])
|
---|
6 | **
|
---|
7 | ** This file is part of the examples of the Qt Toolkit.
|
---|
8 | **
|
---|
9 | ** $QT_BEGIN_LICENSE:BSD$
|
---|
10 | ** You may use this file under the terms of the BSD license as follows:
|
---|
11 | **
|
---|
12 | ** "Redistribution and use in source and binary forms, with or without
|
---|
13 | ** modification, are permitted provided that the following conditions are
|
---|
14 | ** met:
|
---|
15 | ** * Redistributions of source code must retain the above copyright
|
---|
16 | ** notice, this list of conditions and the following disclaimer.
|
---|
17 | ** * Redistributions in binary form must reproduce the above copyright
|
---|
18 | ** notice, this list of conditions and the following disclaimer in
|
---|
19 | ** the documentation and/or other materials provided with the
|
---|
20 | ** distribution.
|
---|
21 | ** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
|
---|
22 | ** the names of its contributors may be used to endorse or promote
|
---|
23 | ** products derived from this software without specific prior written
|
---|
24 | ** permission.
|
---|
25 | **
|
---|
26 | ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
---|
27 | ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
---|
28 | ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
---|
29 | ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
---|
30 | ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
---|
31 | ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
---|
32 | ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
33 | ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
34 | ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
35 | ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
---|
36 | ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
|
---|
37 | ** $QT_END_LICENSE$
|
---|
38 | **
|
---|
39 | ****************************************************************************/
|
---|
40 |
|
---|
41 | #include <QApplication>
|
---|
42 | #include <QAxFactory>
|
---|
43 | #include <QTabWidget>
|
---|
44 | #include <QTimer>
|
---|
45 |
|
---|
46 | class Application;
|
---|
47 | class DocumentList;
|
---|
48 |
|
---|
49 | //! [0]
|
---|
50 | class Document : public QObject
|
---|
51 | {
|
---|
52 | Q_OBJECT
|
---|
53 |
|
---|
54 | Q_CLASSINFO("ClassID", "{2b5775cd-72c2-43da-bc3b-b0e8d1e1c4f7}")
|
---|
55 | Q_CLASSINFO("InterfaceID", "{2ce1761e-07a3-415c-bd11-0eab2c7283de}")
|
---|
56 |
|
---|
57 | Q_PROPERTY(Application *application READ application)
|
---|
58 | Q_PROPERTY(QString title READ title WRITE setTitle)
|
---|
59 |
|
---|
60 | public:
|
---|
61 | Document(DocumentList *list);
|
---|
62 | ~Document();
|
---|
63 |
|
---|
64 | Application *application() const;
|
---|
65 |
|
---|
66 | QString title() const;
|
---|
67 | void setTitle(const QString &title);
|
---|
68 |
|
---|
69 | private:
|
---|
70 | QWidget *page;
|
---|
71 | };
|
---|
72 | //! [0]
|
---|
73 |
|
---|
74 | //! [1]
|
---|
75 | class DocumentList : public QObject
|
---|
76 | {
|
---|
77 | Q_OBJECT
|
---|
78 |
|
---|
79 | Q_CLASSINFO("ClassID", "{496b761d-924b-4554-a18a-8f3704d2a9a6}")
|
---|
80 | Q_CLASSINFO("InterfaceID", "{6c9e30e8-3ff6-4e6a-9edc-d219d074a148}")
|
---|
81 |
|
---|
82 | Q_PROPERTY(Application* application READ application)
|
---|
83 | Q_PROPERTY(int count READ count)
|
---|
84 |
|
---|
85 | public:
|
---|
86 | DocumentList(Application *application);
|
---|
87 |
|
---|
88 | int count() const;
|
---|
89 | Application *application() const;
|
---|
90 |
|
---|
91 | public slots:
|
---|
92 | Document *addDocument();
|
---|
93 | Document *item(int index) const;
|
---|
94 |
|
---|
95 | private:
|
---|
96 | QList<Document*> list;
|
---|
97 | };
|
---|
98 | //! [1]
|
---|
99 |
|
---|
100 | //! [2]
|
---|
101 | class Application : public QObject
|
---|
102 | {
|
---|
103 | Q_OBJECT
|
---|
104 |
|
---|
105 | Q_CLASSINFO("ClassID", "{b50a71db-c4a7-4551-8d14-49983566afee}")
|
---|
106 | Q_CLASSINFO("InterfaceID", "{4a427759-16ef-4ed8-be79-59ffe5789042}")
|
---|
107 | Q_CLASSINFO("RegisterObject", "yes")
|
---|
108 |
|
---|
109 | Q_PROPERTY(DocumentList* documents READ documents)
|
---|
110 | Q_PROPERTY(QString id READ id)
|
---|
111 | Q_PROPERTY(bool visible READ isVisible WRITE setVisible)
|
---|
112 |
|
---|
113 | public:
|
---|
114 | Application(QObject *parent = 0);
|
---|
115 | DocumentList *documents() const;
|
---|
116 |
|
---|
117 | QString id() const { return objectName(); }
|
---|
118 |
|
---|
119 | void setVisible(bool on);
|
---|
120 | bool isVisible() const;
|
---|
121 |
|
---|
122 | QTabWidget *window() const { return ui; }
|
---|
123 |
|
---|
124 | public slots:
|
---|
125 | void quit();
|
---|
126 |
|
---|
127 | private:
|
---|
128 | DocumentList *docs;
|
---|
129 |
|
---|
130 | QTabWidget *ui;
|
---|
131 | };
|
---|
132 | //! [2]
|
---|
133 |
|
---|
134 | //! [3]
|
---|
135 | Document::Document(DocumentList *list)
|
---|
136 | : QObject(list)
|
---|
137 | {
|
---|
138 | QTabWidget *tabs = list->application()->window();
|
---|
139 | page = new QWidget(tabs);
|
---|
140 | page->setWindowTitle("Unnamed");
|
---|
141 | tabs->addTab(page, page->windowTitle());
|
---|
142 |
|
---|
143 | page->show();
|
---|
144 | }
|
---|
145 |
|
---|
146 | Document::~Document()
|
---|
147 | {
|
---|
148 | delete page;
|
---|
149 | }
|
---|
150 |
|
---|
151 | Application *Document::application() const
|
---|
152 | {
|
---|
153 | return qobject_cast<DocumentList*>(parent())->application();
|
---|
154 | }
|
---|
155 |
|
---|
156 | QString Document::title() const
|
---|
|
---|