author | Eckhart Koeppen <eckhart.koppen@nokia.com> |
Wed, 21 Apr 2010 20:15:53 +0300 | |
branch | RCL_3 |
changeset 13 | c0432d11811c |
parent 4 | 3b1da2848fc7 |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 4 |
** All rights reserved. |
5 |
** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 |
** |
|
7 |
** This file is part of the demonstration applications of the Qt Toolkit. |
|
8 |
** |
|
9 |
** $QT_BEGIN_LICENSE:LGPL$ |
|
10 |
** No Commercial Usage |
|
11 |
** This file contains pre-release code and may not be distributed. |
|
12 |
** You may use this file in accordance with the terms and conditions |
|
13 |
** contained in the Technology Preview License Agreement accompanying |
|
14 |
** this package. |
|
15 |
** |
|
16 |
** GNU Lesser General Public License Usage |
|
17 |
** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 |
** General Public License version 2.1 as published by the Free Software |
|
19 |
** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 |
** packaging of this file. Please review the following information to |
|
21 |
** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 |
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 |
** |
|
24 |
** In addition, as a special exception, Nokia gives you certain additional |
|
25 |
** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 |
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 |
** |
|
28 |
** If you have questions regarding the use of this file, please contact |
|
29 |
** Nokia at qt-info@nokia.com. |
|
30 |
** |
|
31 |
** |
|
32 |
** |
|
33 |
** |
|
34 |
** |
|
35 |
** |
|
36 |
** |
|
37 |
** |
|
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 |