📄 launcher.cpp
字号:
}QString Launcher::readExampleDescription(const QDomNode &parentNode) const{ QString description; QDomNode node = parentNode.firstChild(); while (!node.isNull()) { QString beginTag; QString endTag; if (node.isText()) description += node.nodeValue(); else if (node.hasChildNodes()) { if (node.nodeName() == "b") { beginTag = "<b>"; endTag = "</b>"; } else if (node.nodeName() == "a") { beginTag = "<font color=\"blue\">"; endTag = "</font>"; } else if (node.nodeName() == "i") { beginTag = "<i>"; endTag = "</i>"; } else if (node.nodeName() == "tt") { beginTag = "<tt>"; endTag = "</tt>"; } description += beginTag + readExampleDescription(node) + endTag; } node = node.nextSibling(); } return description;}void Launcher::launchExample(const QString &uniqueName){ if (runningExamples.contains(uniqueName)) return; QProcess *process = new QProcess(this); connect(process, SIGNAL(finished(int)), this, SLOT(enableLaunching()));#ifdef Q_OS_WIN //make sure it finds the dlls on windows QString curpath = QString::fromLocal8Bit(qgetenv("PATH").constData()); QString newpath = QString("PATH=%1;%2").arg( QLibraryInfo::location(QLibraryInfo::BinariesPath), curpath); process->setEnvironment(QStringList(newpath));#endif runningExamples.append(uniqueName); runningProcesses[process] = uniqueName; if (exampleOptions[uniqueName]["changedirectory"] == "true") process->setWorkingDirectory(exampleDetails[uniqueName]["absolute path"]); process->start(exampleDetails[uniqueName]["path"]); if (process->state() == QProcess::Starting) slideshowTimer->stop();}void Launcher::enableLaunching(){ QProcess *process = static_cast<QProcess*>(sender()); QString example = runningProcesses.take(process); process->deleteLater(); runningExamples.removeAll(example); if (example == currentExample) { for (int i = 0; i < display->shapesCount(); ++i) { DisplayShape *shape = display->shape(i); if (shape->metaData("launch").toString() == example) { shape->setMetaData("fade", 15); display->enableUpdates(); } } slideshowTimer->start(); }}void Launcher::executeAction(const QString &action){ if (action == "parent") showParentPage(); else if (action == "exit") { if (runningExamples.size() == 0) { connect(display, SIGNAL(displayEmpty()), this, SLOT(close())); display->reset(); } else close(); }}void Launcher::closeEvent(QCloseEvent *event){ if (runningExamples.size() > 0) { if (QMessageBox::warning(this, tr("Examples Running"), tr("There are examples running. Do you really want to exit?"), QMessageBox::Yes, QMessageBox::No) == QMessageBox::No) event->ignore(); return; } foreach (QProcess *example, runningProcesses.keys()) { example->terminate(); example->waitForFinished(1000); } qDeleteAll(runningProcesses.keys()); resizeTimer->stop(); slideshowTimer->stop();}void Launcher::showParentPage(){ slideshowTimer->stop(); disconnect(slideshowTimer, SIGNAL(timeout()), this, 0); if (!currentExample.isEmpty()) { currentExample = ""; redisplayWindow(); } else if (!currentCategory.isEmpty()) { currentCategory = ""; redisplayWindow(); }}void Launcher::newPage(){ slideshowTimer->stop(); disconnect(slideshowTimer, SIGNAL(timeout()), this, 0); disconnect(display, SIGNAL(displayEmpty()), this, 0);}DisplayShape *Launcher::addTitle(const QString &title, qreal verticalMargin){ QPointF titlePosition = QPointF(0.0, 2*verticalMargin); DisplayShape *newTitle = new TitleShape(title, titleFont, QPen(Qt::white), titlePosition, QSizeF(0.5 * width(), 2*verticalMargin), Qt::AlignHCenter | Qt::AlignTop); newTitle->setPosition(QPointF(-newTitle->rect().width(), titlePosition.y())); newTitle->setTarget(QPointF(0.25*width(), titlePosition.y())); newTitle->setMetaData("fade", 15); display->appendShape(newTitle); return newTitle;}DisplayShape *Launcher::addTitleBackground(DisplayShape *titleShape){ QPainterPath backgroundPath; backgroundPath.addRect(0, -titleShape->rect().height()*0.3, width(), titleShape->rect().height()*1.6); DisplayShape *titleBackground = new PanelShape(backgroundPath, QBrush(QColor("#a6ce39")), QBrush(QColor("#a6ce39")), Qt::NoPen, QPointF(width(), titleShape->position().y()), backgroundPath.boundingRect().size()); titleBackground->setTarget(QPointF(0.0, titleShape->position().y())); display->insertShape(0, titleBackground); return titleBackground;}void Launcher::addVersionAndCopyright(const QRectF &rect){ DisplayShape *versionCaption = new TitleShape( QString("Qt %1").arg(QT_VERSION_STR), font(), QPen(QColor(0,0,0,0)), QPointF(rect.center().x(), rect.top()), QSizeF(0.5*rect.width(), rect.height()), Qt::AlignRight | Qt::AlignVCenter); versionCaption->setMetaData("fade", 15); display->appendShape(versionCaption); DisplayShape *copyrightCaption = new TitleShape( QString("Copyright \xa9 2005-2006 Trolltech ASA"), font(), QPen(QColor(0,0,0,0)), rect.topLeft(), QSizeF(0.5*rect.width(), rect.height()), Qt::AlignLeft | Qt::AlignVCenter); copyrightCaption->setMetaData("fade", 15); display->appendShape(copyrightCaption);}void Launcher::fadeShapes(){ for (int i = 0; i < display->shapesCount(); ++i) { DisplayShape *shape = display->shape(i); shape->setMetaData("fade", -15); shape->setMetaData("fade minimum", 0); }}void Launcher::showCategories(){ newPage(); fadeShapes(); currentCategory = ""; currentExample = ""; qreal horizontalMargin = 0.025*width(); qreal verticalMargin = 0.025*height(); DisplayShape *title = new TitleShape(tr("Qt Examples and Demos"), titleFont, QPen(QColor("#a6ce39")), QPointF(), QSizeF(0.5*width(), 4*verticalMargin)); title->setPosition(QPointF(width()/2 - title->rect().width()/2, -title->rect().height())); title->setTarget(QPointF(title->position().x(), verticalMargin)); display->appendShape(title); qreal topMargin = 6*verticalMargin; qreal bottomMargin = height() - 3.2*verticalMargin; qreal space = bottomMargin - topMargin; qreal step = qMin(title->rect().height() / fontRatio, space/qreal(maximumLabels)); qreal textHeight = fontRatio * step; QPointF startPosition = QPointF(0.0, topMargin); QSizeF maxSize(10.8*horizontalMargin, textHeight); qreal maxWidth = 0.0; QList<DisplayShape*> newShapes; foreach (QString category, categories) { DisplayShape *caption = new TitleShape(category, font(), QPen(), startPosition, maxSize); caption->setPosition(QPointF(-caption->rect().width(), caption->position().y())); caption->setTarget(QPointF(2*horizontalMargin, caption->position().y())); newShapes.append(caption); startPosition += QPointF(0.0, step); maxWidth = qMax(maxWidth, caption->rect().width()); } DisplayShape *exitButton = new TitleShape(tr("Exit"), font(), QPen(Qt::white), startPosition, maxSize); exitButton->setTarget(QPointF(2*horizontalMargin, exitButton->position().y())); newShapes.append(exitButton); startPosition = QPointF(width(), topMargin); qreal extra = (step - textHeight)/4; QPainterPath backgroundPath; backgroundPath.addRect(-2*extra, -extra, maxWidth + 4*extra, textHeight + 2*extra); foreach (QString category, categories) { DisplayShape *background = new PanelShape(backgroundPath, QBrush(categoryColors[category]), QBrush(QColor("#e0e0ff")), Qt::NoPen, startPosition, QSizeF(maxWidth + 4*extra, textHeight + 2*extra)); background->setMetaData("category", category); background->setInteractive(true); background->setTarget(QPointF(2*horizontalMargin, background->position().y())); display->insertShape(0, background); startPosition += QPointF(0.0, step); } QPainterPath exitPath; exitPath.moveTo(-2*extra, -extra); exitPath.lineTo(-8*extra, textHeight/2); exitPath.lineTo(-extra, textHeight + extra); exitPath.lineTo(maxWidth + 2*extra, textHeight + extra); exitPath.lineTo(maxWidth + 2*extra, -extra); exitPath.closeSubpath(); DisplayShape *exitBackground = new PanelShape(exitPath, QBrush(QColor("#a6ce39")), QBrush(QColor("#c7f745")), Qt::NoPen, startPosition, QSizeF(maxWidth + 10*extra, textHeight + 2*extra)); exitBackground->setMetaData("action", "exit"); exitBackground->setInteractive(true); exitBackground->setTarget(QPointF(2*horizontalMargin, exitBackground->position().y())); display->insertShape(0, exitBackground); foreach (DisplayShape *caption, newShapes) { QPointF position = caption->target(); QSizeF size = caption->rect().size(); caption->setPosition(QPointF(-maxWidth, position.y())); display->appendShape(caption); } qreal leftMargin = 3*horizontalMargin + maxWidth; qreal rightMargin = width() - 3*horizontalMargin; DocumentShape *description = new DocumentShape(categoryDescriptions["[main]"], documentFont, QPointF(leftMargin, topMargin), QSizeF(rightMargin - leftMargin, space), 0); description->setMetaData("fade", 10); display->appendShape(description); qreal imageHeight = title->rect().height() + verticalMargin; qreal qtLength = qMin(imageHeight, title->rect().left()-3*horizontalMargin); QSizeF qtMaxSize = QSizeF(qtLength, qtLength); DisplayShape *qtShape = new ImageShape(qtLogo, QPointF(2*horizontalMargin-extra, -imageHeight), qtMaxSize, 0, Qt::AlignLeft | Qt::AlignVCenter); qtShape->setMetaData("fade", 15); qtShape->setTarget(QPointF(qtShape->rect().x(), verticalMargin)); display->insertShape(0, qtShape); QSizeF trolltechMaxSize = QSizeF( width()-3*horizontalMargin-title->rect().right(), imageHeight); DisplayShape *trolltechShape = new ImageShape(trolltechLogo, QPointF(width()-2*horizontalMargin-trolltechMaxSize.width()+extra, -imageHeight), trolltechMaxSize, 0, Qt::AlignRight | Qt::AlignVCenter); trolltechShape->setMetaData("fade", 15); trolltechShape->setTarget(QPointF(trolltechShape->rect().x(), verticalMargin)); display->insertShape(0, trolltechShape); addVersionAndCopyright(QRectF(2*horizontalMargin, height() - verticalMargin - textHeight, width()-4*horizontalMargin, textHeight));}void Launcher::showExamples(const QString &category){ newPage(); fadeShapes(); currentCategory = category; currentExample = ""; qreal horizontalMargin = 0.025*width(); qreal verticalMargin = 0.025*height(); DisplayShape *newTitle = addTitle(category, verticalMargin); addTitleBackground(newTitle); qreal topMargin = 6*verticalMargin; qreal bottomMargin = height() - 3.2*verticalMargin;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -