Windows doesn't #define STD{IN,OUT,ERR}_FILENO
[qt-netbsd.git] / demos / qtdemo / menucontent.cpp
blobe605e8a5aeefcf27b77afe1982355d3f4722328a
1 /****************************************************************************
2 **
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
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.
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.
38 ** $QT_END_LICENSE$
40 ****************************************************************************/
42 #include "menucontent.h"
43 #include "colors.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");
52 this->heading = 0;
53 this->description1 = 0;
54 this->description2 = 0;
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";
63 void MenuContentItem::prepare()
65 if (!this->prepared){
66 this->prepared= true;
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:
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;
88 QString MenuContentItem::loadDescription(int startPara, int nrPara)
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 "";
98 QTextStream in(&readme);
99 // Skip a certain number of paragraphs:
100 while (startPara)
101 if (in.readLine().isEmpty()) --startPara;
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();
112 } while (nrPara && !in.atEnd());
114 return Colors::contentColor + result;
117 void MenuContentItem::createContent()
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);
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);