1 /****************************************************************************
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 ** This file is part of the demonstration applications of the Qt Toolkit.
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
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.
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.
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
40 ****************************************************************************/
42 #include "menucontent.h"
44 #include "menumanager.h"
45 #include "demotextitem.h"
46 #include "headingitem.h"
48 MenuContentItem::MenuContentItem(const QDomElement
&el
, QGraphicsScene
*scene
, QGraphicsItem
*parent
)
49 : DemoItem(scene
, parent
)
51 this->name
= el
.attribute("name");
53 this->description1
= 0;
54 this->description2
= 0;
56 if (el
.tagName() == "demos")
57 this->readmePath
= QLibraryInfo::location(QLibraryInfo::DemosPath
) + "/README";
59 this->readmePath
= QLibraryInfo::location(QLibraryInfo::ExamplesPath
) + "/" + el
.attribute("dirname") + "/README";
63 void MenuContentItem::prepare()
67 this->createContent();
71 void MenuContentItem::animationStopped(int id
)
73 if (this->name
== Colors::rootMenuName
)
74 return; // Optimization hack.
76 if (id
== DemoItemAnimation::ANIM_OUT
){
77 // Free up some memory:
79 delete this->description1
;
80 delete this->description2
;
82 this->description1
= 0;
83 this->description2
= 0;
84 this->prepared
= false;
88 QString
MenuContentItem::loadDescription(int startPara
, int nrPara
)
91 QFile
readme(this->readmePath
);
92 if (!readme
.open(QFile::ReadOnly
)){
94 qDebug() << "- MenuContentItem::loadDescription: Could not load:" << this->readmePath
;
98 QTextStream
in(&readme
);
99 // Skip a certain number of paragraphs:
101 if (in
.readLine().isEmpty()) --startPara
;
103 // Read in the number of wanted paragraphs:
104 QString line
= in
.readLine();
106 result
+= line
+ " ";
107 line
= in
.readLine();
110 line
= "<br><br>" + in
.readLine();
112 } while (nrPara
&& !in
.atEnd());
114 return Colors::contentColor
+ result
;
117 void MenuContentItem::createContent()
120 this->heading
= new HeadingItem(this->name
, this->scene(), this);
121 QString para1
= this->loadDescription(0, 1);
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
);
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);
135 QRectF
MenuContentItem::boundingRect() const
137 return QRectF(0, 0, 500, 350);