⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 launcher.cpp

📁 QT 开发环境里面一个很重要的文件
💻 CPP
📖 第 1 页 / 共 3 页
字号:
    qreal space = bottomMargin - topMargin;    qreal step = qMin(newTitle->rect().height() / fontRatio,                      space/qreal(maximumLabels));    qreal textHeight = fontRatio * step;    QPointF startPosition = QPointF(2*horizontalMargin, height() + topMargin);    QPointF finishPosition = QPointF(2*horizontalMargin, topMargin);    QSizeF maxSize(32*horizontalMargin, textHeight);    qreal maxWidth = 0.0;    foreach (QString example, examples[currentCategory]) {        DisplayShape *caption = new TitleShape(example, font(), QPen(),            startPosition, maxSize);        caption->setTarget(finishPosition);        display->appendShape(caption);        startPosition += QPointF(0.0, step);        finishPosition += QPointF(0.0, step);        maxWidth = qMax(maxWidth, caption->rect().width());    }    DisplayShape *menuButton = new TitleShape(tr("Main Menu"), font(),        QPen(Qt::white), startPosition, maxSize);    menuButton->setTarget(finishPosition);    display->appendShape(menuButton);    maxWidth = qMax(maxWidth, menuButton->rect().width());    startPosition = QPointF(width(), topMargin);    qreal extra = (step - textHeight)/4;    foreach (QString example, examples[currentCategory]) {        QString uniqueName = currentCategory+"-"+example;        QPainterPath path;        path.addRect(-2*extra, -extra, maxWidth + 4*extra, textHeight + 2*extra);        DisplayShape *background = new PanelShape(path,            QBrush(QColor(exampleOptions[uniqueName]["color"])),            QBrush(QColor("#e0e0ff")),            Qt::NoPen, startPosition,            QSizeF(maxWidth + 4*extra, textHeight + 2*extra));        background->setMetaData("example", uniqueName);        background->setInteractive(true);        background->setTarget(QPointF(2*horizontalMargin,                                      background->position().y()));        display->insertShape(0, background);        startPosition += QPointF(0.0, step);    }    QPainterPath backPath;    backPath.moveTo(-2*extra, -extra);    backPath.lineTo(-8*extra, textHeight/2);    backPath.lineTo(-extra, textHeight + extra);    backPath.lineTo(maxWidth + 2*extra, textHeight + extra);    backPath.lineTo(maxWidth + 2*extra, -extra);    backPath.closeSubpath();    DisplayShape *buttonBackground = new PanelShape(backPath,        QBrush(QColor("#a6ce39")), QBrush(QColor("#c7f745")), Qt::NoPen,        startPosition, QSizeF(maxWidth + 10*extra, textHeight + 2*extra));    buttonBackground->setMetaData("action", "parent");    buttonBackground->setInteractive(true);    buttonBackground->setTarget(QPointF(2*horizontalMargin,                                        buttonBackground->position().y()));    display->insertShape(0, buttonBackground);    qreal leftMargin = 3*horizontalMargin + maxWidth;    qreal rightMargin = width() - 3*horizontalMargin;    DocumentShape *description = new DocumentShape(        categoryDescriptions[currentCategory], documentFont,        QPointF(leftMargin, topMargin), QSizeF(rightMargin - leftMargin, space),        0);    description->setMetaData("fade", 10);    display->appendShape(description);    addVersionAndCopyright(QRectF(2*horizontalMargin,                           height() - verticalMargin - textHeight,                           width()-4*horizontalMargin, textHeight));}void Launcher::showExampleDocumentation(const QString &uniqueName){    disconnect(display, SIGNAL(displayEmpty()), this, 0);    currentExample = uniqueName;    assistant->showPage(exampleDetails[uniqueName]["document path"]);}void Launcher::showExampleSummary(const QString &uniqueName){    newPage();    fadeShapes();    currentExample = uniqueName;    qreal horizontalMargin = 0.025*width();    qreal verticalMargin = 0.025*height();    DisplayShape *newTitle = addTitle(exampleDetails[currentExample]["name"],                                      verticalMargin);    DisplayShape *titleBackground = addTitleBackground(newTitle);    qreal topMargin = 2*verticalMargin + titleBackground->rect().bottom();    qreal bottomMargin = height() - 8*verticalMargin;    qreal space = bottomMargin - topMargin;    qreal step = qMin(newTitle->rect().height() / fontRatio,                      (bottomMargin + qreal(4.8)*verticalMargin - topMargin)                      /qreal(maximumLabels));    qreal textHeight = fontRatio * step;    qreal leftMargin = 3*horizontalMargin;    qreal rightMargin = width() - 3*horizontalMargin;    if (exampleDetails[currentExample].contains("description")) {        DocumentShape *description = new DocumentShape(            exampleDetails[currentExample]["description"], documentFont,            QPointF(leftMargin, topMargin),            QSizeF(rightMargin-leftMargin, space), 0);        description->setMetaData("fade", 10);        description->setPosition(QPointF(description->position().x(),            0.8*height() - description->rect().height()));        display->appendShape(description);        space = description->position().y() - topMargin - 2*verticalMargin;    }    if (imagePaths.contains(currentExample)) {        QImage image(imagePaths[currentExample][0]);        QSizeF imageMaxSize = QSizeF(width() - 8*horizontalMargin, space);        currentFrame = new ImageShape(image,            QPointF(width() - imageMaxSize.width()/2, topMargin),            imageMaxSize);        currentFrame->setMetaData("fade", 15);        currentFrame->setTarget(QPointF(width()/2 - imageMaxSize.width()/2,                                        topMargin));        display->appendShape(currentFrame);        if (imagePaths[currentExample].size() > 1) {            connect(slideshowTimer, SIGNAL(timeout()),                    this, SLOT(updateExampleSummary()));            slideshowFrame = 0;            slideshowTimer->start();        }    }    QSizeF maxSize(0.3 * width(), 2*verticalMargin);    leftMargin = 0.0;    rightMargin = 0.0;    if (true) {        DisplayShape *backButton = new TitleShape(currentCategory, font(),            QPen(Qt::white), QPointF(0.1*width(), height()), maxSize,            Qt::AlignLeft | Qt::AlignTop);        backButton->setTarget(QPointF(backButton->position().x(),                                      height() - 5.2*verticalMargin));        display->appendShape(backButton);        qreal maxWidth = backButton->rect().width();        qreal textHeight = backButton->rect().height();        qreal extra = (3*verticalMargin - textHeight)/4;        QPainterPath path;        path.moveTo(-extra, -extra);        path.lineTo(-4*extra, textHeight/2);        path.lineTo(-extra, textHeight + extra);        path.lineTo(maxWidth + 2*extra, textHeight + extra);        path.lineTo(maxWidth + 2*extra, -extra);        path.closeSubpath();        DisplayShape *buttonBackground = new PanelShape(path,            QBrush(QColor("#a6ce39")), QBrush(QColor("#c7f745")), Qt::NoPen,            backButton->position(),            QSizeF(maxWidth + 6*extra, textHeight + 2*extra));        buttonBackground->setMetaData("category", currentCategory);        buttonBackground->setInteractive(true);        buttonBackground->setTarget(backButton->target());        display->insertShape(0, buttonBackground);        leftMargin = buttonBackground->rect().right();    }    if (exampleDetails[currentExample].contains("absolute path")) {        DisplayShape *launchCaption = new TitleShape(tr("Launch"),            font(), QPen(Qt::white), QPointF(0.0, 0.0), maxSize,            Qt::AlignLeft | Qt::AlignTop);        launchCaption->setPosition(QPointF(            0.9*width() - launchCaption->rect().width(), height()));        launchCaption->setTarget(QPointF(launchCaption->position().x(),                                         height() - 5.2*verticalMargin));        display->appendShape(launchCaption);        qreal maxWidth = launchCaption->rect().width();        qreal textHeight = launchCaption->rect().height();        qreal extra = (3*verticalMargin - textHeight)/4;        QPainterPath path;        path.addRect(-2*extra, -extra, maxWidth + 4*extra, textHeight + 2*extra);        QColor backgroundColor = QColor("#a63e39");        QColor highlightedColor = QColor("#f95e56");        DisplayShape *background = new PanelShape(path,            QBrush(backgroundColor), QBrush(highlightedColor), Qt::NoPen,            launchCaption->position(),            QSizeF(maxWidth + 4*extra, textHeight + 2*extra));        background->setMetaData("fade minimum", 120);        background->setMetaData("launch", currentExample);        background->setInteractive(true);        background->setTarget(launchCaption->target());        if (runningExamples.contains(currentExample)) {            background->setMetaData("highlight", true);            background->setMetaData("highlight scale", 0.99);            background->animate();            background->setMetaData("fade", -135);            slideshowTimer->stop();        }        display->insertShape(0, background);        rightMargin = background->rect().left();    }    if (exampleDetails[currentExample].contains("document path")) {        DisplayShape *documentCaption = new TitleShape(tr("Show Documentation"),            font(), QPen(Qt::white), QPointF(0.0, 0.0), maxSize,            Qt::AlignLeft | Qt::AlignTop);        if (rightMargin == 0.0) {            documentCaption->setPosition(QPointF(                0.9*width() - documentCaption->rect().width(), height()));        } else {            documentCaption->setPosition(QPointF(                leftMargin/2 + rightMargin/2 - documentCaption->rect().width()/2,                height()));        }        documentCaption->setTarget(QPointF(documentCaption->position().x(),                                           height() - 5.2*verticalMargin));        display->appendShape(documentCaption);        qreal maxWidth = documentCaption->rect().width();        qreal textHeight = documentCaption->rect().height();        qreal extra = (3*verticalMargin - textHeight)/4;        QPainterPath path;        path.addRect(-2*extra, -extra, maxWidth + 4*extra, textHeight + 2*extra);        DisplayShape *background = new PanelShape(path,            QBrush(QColor("#9c9cff")), QBrush(QColor("#cfcfff")), Qt::NoPen,            documentCaption->position(),            QSizeF(maxWidth + 4*extra, textHeight + 2*extra));        background->setMetaData("fade minimum", 120);        background->setMetaData("documentation", currentExample);        background->setInteractive(true);        background->setTarget(documentCaption->target());        display->insertShape(0, background);    }    addVersionAndCopyright(QRectF(2*horizontalMargin,                           height() - verticalMargin - textHeight,                           width()-4*horizontalMargin, textHeight));}void Launcher::updateExampleSummary(){    if (imagePaths.contains(currentExample)) {        currentFrame->setMetaData("fade", -15);        currentFrame->setTarget(currentFrame->position() - QPointF(0.5*width(),                                0));        slideshowFrame = (slideshowFrame+1) % imagePaths[currentExample].size();        QImage image(imagePaths[currentExample][slideshowFrame]);        QSizeF imageSize = currentFrame->size();        QPointF imagePosition = QPointF(width() - imageSize.width()/2,                                        currentFrame->position().y());        currentFrame = new ImageShape(image, imagePosition, imageSize);        currentFrame->setMetaData("fade", 15);        currentFrame->setTarget(QPointF(width()/2 - imageSize.width()/2,                                        imagePosition.y()));        display->appendShape(currentFrame);    }}void Launcher::toggleFullScreen(){    if (inFullScreenResize)        return;    inFullScreenResize = true;    connect(display, SIGNAL(displayEmpty()), this, SLOT(resizeWindow()),            Qt::QueuedConnection);    display->reset();}void Launcher::resizeWindow(){    disconnect(display, SIGNAL(displayEmpty()), this, 0);    if (isFullScreen())        showNormal();    else        showFullScreen();}void Launcher::resizeEvent(QResizeEvent *event){    Q_UNUSED(event);    documentFont = font();    documentFont.setPointSizeF(qMin(documentFont.pointSizeF()*width()/640.0,                                    documentFont.pointSizeF()*height()/480.0));    if (inFullScreenResize)        inFullScreenResize = false;    if (currentCategory != "[starting]")        resizeTimer->start(500);}void Launcher::redisplayWindow(){    if (!currentExample.isEmpty())        showExampleSummary(currentExample);    else if (!currentCategory.isEmpty())        showExamples(currentCategory);    else        showCategories();}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -