1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
---|
4 | ** Contact: Qt Software Information ([email protected])
|
---|
5 | **
|
---|
6 | ** This file is part of the demonstration applications of the Qt Toolkit.
|
---|
7 | **
|
---|
8 | ** $QT_BEGIN_LICENSE:LGPL$
|
---|
9 | ** Commercial Usage
|
---|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
11 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
12 | ** Software or, alternatively, in accordance with the terms contained in
|
---|
13 | ** a written agreement between you and Nokia.
|
---|
14 | **
|
---|
15 | ** GNU Lesser General Public License Usage
|
---|
16 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
---|
17 | ** General Public License version 2.1 as published by the Free Software
|
---|
18 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
---|
19 | ** packaging of this file. Please review the following information to
|
---|
20 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
---|
21 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
---|
22 | **
|
---|
23 | ** In addition, as a special exception, Nokia gives you certain
|
---|
24 | ** additional rights. These rights are described in the Nokia Qt LGPL
|
---|
25 | ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
|
---|
26 | ** package.
|
---|
27 | **
|
---|
28 | ** GNU General Public License Usage
|
---|
29 | ** Alternatively, this file may be used under the terms of the GNU
|
---|
30 | ** General Public License version 3.0 as published by the Free Software
|
---|
31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
---|
32 | ** packaging of this file. Please review the following information to
|
---|
33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
---|
34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
---|
35 | **
|
---|
36 | ** If you are unsure which license is appropriate for your use, please
|
---|
37 | ** contact the sales department at [email protected].
|
---|
38 | ** $QT_END_LICENSE$
|
---|
39 | **
|
---|
40 | ****************************************************************************/
|
---|
41 |
|
---|
42 | #include "menucontent.h"
|
---|
43 | #include "colors.h"
|
---|
44 | #include "menumanager.h"
|
---|
45 | #include "demotextitem.h"
|
---|
46 | #include "headingitem.h"
|
---|
47 |
|
---|
48 | MenuContentItem::MenuContentItem(const QDomElement &el, QGraphicsScene *scene, QGraphicsItem *parent)
|
---|
49 | : DemoItem(scene, parent)
|
---|
50 | {
|
---|
51 | this->name = el.attribute("name");
|
---|
52 | this->heading = 0;
|
---|
53 | this->description1 = 0;
|
---|
54 | this->description2 = 0;
|
---|
55 |
|
---|
56 | if (el.tagName() == "demos")
|
---|
57 | this->readmePath = QLibraryInfo::location(QLibraryInfo::DemosPath) + "/README";
|
---|
58 | else
|
---|
59 | this->readmePath = QLibraryInfo::location(QLibraryInfo::ExamplesPath) + "/" + el.attribute("dirname") + "/README";
|
---|
60 |
|
---|
61 | }
|
---|
62 |
|
---|
63 | void MenuContentItem::prepare()
|
---|
64 | {
|
---|
65 | if (!this->prepared){
|
---|
66 | this->prepared= true;
|
---|
67 | this->createContent();
|
---|
68 | }
|
---|
69 | }
|
---|
70 |
|
---|
71 | void MenuContentItem::animationStopped(int id)
|
---|
72 | {
|
---|
73 | if (this->name == Colors::rootMenuName)
|
---|
74 | return; // Optimization hack.
|
---|
75 |
|
---|
76 | if (id == DemoItemAnimation::ANIM_OUT){
|
---|
77 | // Free up some memory:
|
---|
78 | delete this->heading;
|
---|
79 | delete this->description1;
|
---|
80 | delete this->description2;
|
---|
81 | this->heading = 0;
|
---|
82 | this->description1 = 0;
|
---|
83 | this->description2 = 0;
|
---|
84 | this->prepared = false;
|
---|
85 | }
|
---|
86 | }
|
---|
87 |
|
---|
88 | QString MenuContentItem::loadDescription(int startPara, int nrPara)
|
---|
89 | {
|
---|
90 | QString result;
|
---|
91 | QFile readme(this->readmePath);
|
---|
92 | if (!readme.open(QFile::ReadOnly)){
|
---|
93 | if (Colors::verbose)
|
---|
94 | qDebug() << "- MenuContentItem::loadDescription: Could not load:" << this->readmePath;
|
---|
95 | return "";
|
---|
96 | }
|
---|
97 |
|
---|
98 | QTextStream in(&readme);
|
---|
99 | // Skip a certain number of paragraphs:
|
---|
100 | while (startPara)
|
---|
101 | if (in.readLine().isEmpty()) --startPara;
|
---|
102 |
|
---|
103 | // Read in the number of wanted paragraphs:
|
---|
104 | QString line = in.readLine();
|
---|
105 | do {
|
---|
106 | result += line + " ";
|
---|
107 | line = in.readLine();
|
---|
108 | if (line.isEmpty()){
|
---|
109 | --nrPara;
|
---|
110 | line = "<br><br>" + in.readLine();
|
---|
111 | }
|
---|
112 | } while (nrPara && !in.atEnd());
|
---|
113 |
|
---|
114 | return Colors::contentColor + result;
|
---|
115 | }
|
---|
116 |
|
---|
117 | void MenuContentItem::createContent()
|
---|
118 | {
|
---|
119 | // Create the items:
|
---|
120 | this->heading = new HeadingItem(this->name, this->scene(), this);
|
---|
121 | QString para1 = this->loadDescription(0, 1);
|
---|
122 | if (para1.isEmpty())
|
---|
123 | para1 = Colors::contentColor + QLatin1String("Could not load description. Ensure that the documentation for Qt is built.");
|
---|
124 | QColor bgcolor = Colors::sceneBg1.darker(200);
|
---|
125 | bgcolor.setAlpha(100);
|
---|
126 | this->description1 = new DemoTextItem(para1, Colors::contentFont(), Colors::heading, 500, this->scene(), this, DemoTextItem::STATIC_TEXT);
|
---|
127 | this->description2 = new DemoTextItem(this->loadDescription(1, 2), Colors::contentFont(), Colors::heading, 250, this->scene(), this, DemoTextItem::STATIC_TEXT);
|
---|
128 |
|
---|
129 | // Place the items on screen:
|
---|
130 | this->heading->setPos(0, 3);
|
---|
131 | this->description1->setPos(0, this->heading->pos().y() + this->heading->boundingRect().height() + 10);
|
---|
132 | this->description2->setPos(0, this->description1->pos().y() + this->description1->boundingRect().height() + 15);
|
---|
133 | }
|
---|
134 |
|
---|
135 | QRectF MenuContentItem::boundingRect() const
|
---|
136 | {
|
---|
137 | return QRectF(0, 0, 500, 350);
|
---|
138 | }
|
---|
139 |
|
---|
140 |
|
---|