Esempio n. 1
0
void NativeTabItem::SetInfo(const PartInfo& info)
{
  QTabBar* widget = parent->GetTabFolder();

  int index = parent->IndexOf(this);
  if (widget->tabText(index) != info.name)
  {
    widget->setTabText(index, info.name);
  }

  if (widget->tabToolTip(index) != info.toolTip)
  {
    widget->setTabToolTip(index, info.toolTip);
  }

  if (widget->tabIcon(index).cacheKey() != info.image.cacheKey())
  {
    widget->setTabIcon(index, info.image);
  }
}
Qtilities::CoreGui::WidgetLoggerEngineFrontend::WidgetLoggerEngineFrontend(WidgetLoggerEngine::MessageDisplaysFlag message_displays_flag,
                                                                           Qt::ToolBarArea toolbar_area,
                                                                           QWidget *parent) : QMainWindow(parent)
{
    d = new WidgetLoggerEngineFrontendPrivateData;
    d->message_displays_flag = message_displays_flag;

    // When only one message display is present we don't create it as a tab widget.
    if (message_displays_flag == WidgetLoggerEngine::AllMessagesPlainTextEdit ||
            message_displays_flag == WidgetLoggerEngine::IssuesPlainTextEdit ||
            message_displays_flag == WidgetLoggerEngine::WarningsPlainTextEdit ||
            message_displays_flag == WidgetLoggerEngine::ErrorsPlainTextEdit) {

        MessagesPlainTextEditTab* new_tab = new MessagesPlainTextEditTab(0,toolbar_area);
        d->message_displays[message_displays_flag] = new_tab;
        setCentralWidget(new_tab);
    } else {
        int info_index = -1;
        int issues_index = -1;
        int warning_index = -1;
        int error_index = -1;

        // Create needed tabs:
        if (d->message_displays_flag & WidgetLoggerEngine::AllMessagesPlainTextEdit) {
            MessagesPlainTextEditTab* new_tab = new MessagesPlainTextEditTab(0,toolbar_area);
            d->message_displays[WidgetLoggerEngine::AllMessagesPlainTextEdit] = new_tab;
            QDockWidget* new_dock = new QDockWidget("Messages");

            // We don't want users to be able to close the individual log
            // dock widgets since there is no way to get them back then
            // until the application is restarted.
            QDockWidget::DockWidgetFeatures features = new_dock->features();
            features &= ~QDockWidget::DockWidgetClosable;
            new_dock->setFeatures(features);

            d->message_display_docks[WidgetLoggerEngine::AllMessagesPlainTextEdit] = new_dock;
            connect(new_dock,SIGNAL(visibilityChanged(bool)),SLOT(handle_dockVisibilityChanged(bool)));
            new_dock->setWidget(new_tab);
            addDockWidget(Qt::BottomDockWidgetArea,new_dock);

            info_index = 0;
        }

        if (d->message_displays_flag & WidgetLoggerEngine::IssuesPlainTextEdit) {
            MessagesPlainTextEditTab* new_tab = new MessagesPlainTextEditTab(0,toolbar_area);
            d->message_displays[WidgetLoggerEngine::IssuesPlainTextEdit] = new_tab;
            QDockWidget* new_dock = new QDockWidget("Issues");

            // We don't want users to be able to close the individual log
            // dock widgets since there is no way to get them back then
            // until the application is restarted.
            QDockWidget::DockWidgetFeatures features = new_dock->features();
            features &= ~QDockWidget::DockWidgetClosable;
            new_dock->setFeatures(features);

            d->message_display_docks[WidgetLoggerEngine::IssuesPlainTextEdit] = new_dock;
            connect(new_dock,SIGNAL(visibilityChanged(bool)),SLOT(handle_dockVisibilityChanged(bool)));
            new_dock->setWidget(new_tab);
            addDockWidget(Qt::BottomDockWidgetArea,new_dock);

            if (d->message_displays_flag & WidgetLoggerEngine::AllMessagesPlainTextEdit)
                issues_index = 1;
            else
                issues_index = 0;
        }

        if (d->message_displays_flag & WidgetLoggerEngine::WarningsPlainTextEdit) {
            MessagesPlainTextEditTab* new_tab = new MessagesPlainTextEditTab(0,toolbar_area);
            d->message_displays[WidgetLoggerEngine::WarningsPlainTextEdit] = new_tab;
            QDockWidget* new_dock = new QDockWidget("Warnings");

            // We don't want users to be able to close the individual log
            // dock widgets since there is no way to get them back then
            // until the application is restarted.
            QDockWidget::DockWidgetFeatures features = new_dock->features();
            features &= ~QDockWidget::DockWidgetClosable;
            new_dock->setFeatures(features);

            d->message_display_docks[WidgetLoggerEngine::WarningsPlainTextEdit] = new_dock;
            connect(new_dock,SIGNAL(visibilityChanged(bool)),SLOT(handle_dockVisibilityChanged(bool)));
            new_dock->setWidget(new_tab);
            addDockWidget(Qt::BottomDockWidgetArea,new_dock);

            if (d->message_displays_flag & WidgetLoggerEngine::AllMessagesPlainTextEdit && d->message_displays_flag & WidgetLoggerEngine::IssuesPlainTextEdit)
                warning_index = 2;
            else if (d->message_displays_flag & WidgetLoggerEngine::AllMessagesPlainTextEdit)
                warning_index = 1;
            else
                warning_index = 0;
        }

        if (d->message_displays_flag & WidgetLoggerEngine::ErrorsPlainTextEdit) {
            MessagesPlainTextEditTab* new_tab = new MessagesPlainTextEditTab(0,toolbar_area);
            d->message_displays[WidgetLoggerEngine::ErrorsPlainTextEdit] = new_tab;
            QDockWidget* new_dock = new QDockWidget("Errors");

            // We don't want users to be able to close the individual log
            // dock widgets since there is no way to get them back then
            // until the application is restarted.
            QDockWidget::DockWidgetFeatures features = new_dock->features();
            features &= ~QDockWidget::DockWidgetClosable;
            new_dock->setFeatures(features);

            d->message_display_docks[WidgetLoggerEngine::ErrorsPlainTextEdit] = new_dock;
            connect(new_dock,SIGNAL(visibilityChanged(bool)),SLOT(handle_dockVisibilityChanged(bool)));
            new_dock->setWidget(new_tab);
            addDockWidget(Qt::BottomDockWidgetArea,new_dock);

            if (d->message_displays_flag & WidgetLoggerEngine::AllMessagesPlainTextEdit && d->message_displays_flag & WidgetLoggerEngine::IssuesPlainTextEdit && d->message_displays_flag & WidgetLoggerEngine::WarningsPlainTextEdit)
                error_index = 3;
            else if (d->message_displays_flag & WidgetLoggerEngine::AllMessagesPlainTextEdit && d->message_displays_flag & WidgetLoggerEngine::WarningsPlainTextEdit)
                error_index = 2;
            else if (d->message_displays_flag & WidgetLoggerEngine::AllMessagesPlainTextEdit && d->message_displays_flag & WidgetLoggerEngine::IssuesPlainTextEdit)
                error_index = 2;
            else if (d->message_displays_flag & WidgetLoggerEngine::AllMessagesPlainTextEdit)
                error_index = 1;
            else if (d->message_displays_flag & WidgetLoggerEngine::WarningsPlainTextEdit)
                error_index = 1;
            else if (d->message_displays_flag & WidgetLoggerEngine::IssuesPlainTextEdit)
                error_index = 1;
            else
                error_index = 0;
        }

        for (int i = 1; i < d->message_display_docks.count(); ++i)
            tabifyDockWidget(d->message_display_docks.values().at(i-1),d->message_display_docks.values().at(i));

        QList<QTabBar *> tabList = findChildren<QTabBar *>();
        if (!tabList.isEmpty()) {
            QTabBar *tabBar = tabList.at(0);
            tabBar->setCurrentIndex(0);
            tabBar->setShape(QTabBar::RoundedSouth);

            if (info_index != -1)
                tabBar->setTabIcon(info_index,QIcon(qti_icon_INFO_12x12));
            if (issues_index != -1)
                tabBar->setTabIcon(issues_index,QIcon(qti_icon_WARNING_12x12));
            if (warning_index != -1)
                tabBar->setTabIcon(warning_index,QIcon(qti_icon_WARNING_12x12));
            if (error_index != -1)
                tabBar->setTabIcon(error_index,QIcon(qti_icon_ERROR_12x12));
        }
    }
}
Esempio n. 3
0
void MainWindow::startSWG() {
    QStringList arguments;

    QSettings settings;
    QString folder = settings.value("swg_folder").toString();
    bool multiple = settings.value("multiple_instances").toBool();
    ConfigParser* parser = new ConfigParser();
    GameProcess* process = new GameProcess(parser, NULL);

    parser->connect(parser, SIGNAL(errorSignal(QString)), process, SLOT(outputDebugString(QString)));

    try {
        if (parser->loadFile(folder, "swgemu.cfg") != 0) {
            QMessageBox::warning(this, "Warning", "There was an issue parsing the swg config files! To restore them run full scan!");
        }
    } catch (...) {
        QMessageBox::warning(this, "Warning", "There was an issue parsing the swg config files! To restore them run full scan!");
    }

    QVector<ConfigValue> loginServerAddresses = parser->getConfigValues("ClientGame", "loginServerAddress0");
    QVector<ConfigValue> loginServerPorts = parser->getConfigValues("ClientGame", "loginServerPort0");

    if (loginServerAddresses.size() > 1) {
        QString warningString;
        QTextStream stream(&warningString);

        stream << "You have several login server addresses defined in the following swg config files: ";

        for (int i = 0; i < loginServerAddresses.size(); ++i) {
            const ConfigValue val = loginServerAddresses.at(i);

            stream << val.fileName << " ";
        }

        stream << " client will use the value: " << parser->getStringConfigValue("ClientGame", "loginServerAddress0");

        QMessageBox::warning(this, "Warning", warningString);
    }

    if (loginServerPorts.size() > 1) {
        QString warningString;
        QTextStream stream(&warningString);

        stream << "You have several login server ports defined in the following swg config files: ";

        for (int i = 0; i < loginServerPorts.size(); ++i) {
            const ConfigValue val = loginServerPorts.at(i);

            stream << val.fileName << " ";
        }

        stream << " client will use the value: " << parser->getStringConfigValue("ClientGame", "loginServerPort0");

        QMessageBox::warning(this, "Warning", warningString);
    }

    LoginServer* server = loginServers->getServer(ui->comboBox_login->currentText());

    QString loginAddress = parser->getStringConfigValue("ClientGame", "loginServerAddress0", "loginServerAddress0");
    QString port = parser->getStringConfigValue("ClientGame", "loginServerAddress0", "loginServerPort0");

    if (loginAddress != server->getHost() || port != QString::number(server->getPort())) {
#ifdef Q_OS_WIN32
        QFile loginFile(folder + "\\swgemu_login.cfg");
#else
        QFile loginFile(folder + "/swgemu_login.cfg");
#endif

        if (loginFile.open(QIODevice::WriteOnly | QIODevice::Text)) {
            QTextStream stream(&loginFile);
            stream << "[ClientGame]" << endl;
            stream << "loginServerAddress0=" << server->getHost() << endl;
            stream << "loginServerPort0=" << server->getPort();

            loginFile.close();
        } else {
            QMessageBox::warning(this, "Error", "Could not write swgemu_login.cfg!");
        }
    }
/*
    arguments.append("--");
    arguments.append("-s");
    arguments.append("ClientGame");
    arguments.append("cameraFarPlane=4096");
*/
/*
    arguments.append("--");
    arguments.append("-s");
    arguments.append("SharedFoundation");
    arguments.append("minFrameRate=60");
*/
  //  QFile executable()
/*
    arguments.append("--");
    arguments.append("-s");
    arguments.append("ClientTerrain");
    arguments.append("dynamicNearFloraDistance=128");

    arguments.append("--");
    arguments.append("-s");
    arguments.append("ClientTerrain");
    arguments.append("staticNonCollidableFloraDistance=2048");

    arguments.append("--");
    arguments.append("-s");
    arguments.append("ClientProceduralTerrainAppearance_LevelOfDetail");
    arguments.append("forceHighThreshold=40");

    arguments.append("--");
    arguments.append("-s");
    arguments.append("ClientProceduralTerrainAppearance_LevelOfDetail");
    arguments.append("threshold=40");

    arguments.append("--");
    arguments.append("-s");
    arguments.append("ClientProceduralTerrainAppearance_LevelOfDetail");
    arguments.append("heightBiasMax=4096");
*/
    //ClientProceduralTerrainAppearance_LevelOfDetail.heightBiasMax



    //ClientGame.cameraFarPlane

    /*ClientProceduralTerrainAppearance_LevelOfDetail.threshold*/


    /*ClientProceduralTerrainAppearance_LevelOfDetail.forceHighThreshold*/


    arguments.append("--");
    arguments.append("-s");
    arguments.append("ClientGame");

    if (server != NULL)
        arguments.append("loginServerAddress0=" + server->getHost());
    else
        arguments.append("loginServerAddress0=" + LoginServers::defaultLoginAddress);

    if (server == NULL)
        arguments.append("loginServerPort0=" + QString::number(LoginServers::defaultLoginPort));
    else
        arguments.append("loginServerPort0=" + QString::number(server->getPort()));

    arguments.append("-s");
    arguments.append("Station");
    arguments.append("gameFeatures=34929");

    if (multiple) {
        if (parser->hasConfigValue("SwgClient", "allowMultipleInstances")) {
            bool val = parser->getBooleanConfigValue("SwgClient", "allowMultipleInstances");

            if (!val) {
                QMessageBox::warning(this, "Warning", "You selected the multiple instances option but you have set it to false in the swg config files!");
            }
        }

        arguments.append("-s");
        arguments.append("SwgClient");
        arguments.append("allowMultipleInstances=true");
    }

    qDebug() << "start swg with arguments " << arguments;

    connect(process, SIGNAL(processFinished(GameProcess*,int)), this, SLOT(gameProcessFinished(GameProcess*,int)));

    ui->tabWidget->addTab(process, "Process " + QString::number(++gameProcessesCount));
    gameProcesses.append(process);
    QTabBar* bar = ui->tabWidget->tabBar();
    int tabIndex = ui->tabWidget->indexOf(process);
    bar->setTabTextColor(tabIndex, Qt::green);
    bar->setTabIcon(tabIndex, QIcon(":/img/tab.svg"));

    //process->show();
    bool startResult = process->start(folder, gameExecutable, arguments);

    if (startResult) {
        //showMinimized();
        if (settings.value("minimize_after_start", false).toBool()) {
            systemTrayIcon->show();

            QTimer::singleShot(0, this, SLOT(hide()));
        }
    }
}
Esempio n. 4
0
int main(int argc, char *argv[])
{
    QApplication app(argc, argv);
    auto *proxyStyle = new TabBarProxyStyle;
    app.setStyle(proxyStyle);

    QWidget widget;
    QStackedWidget stackedWidget;
    QTabBar tabBar;
    tabBar.setDocumentMode(true);
    tabBar.setTabsClosable(true);
    tabBar.setMovable(true);
    tabBar.setExpanding(false);

    // top
    tabBar.setShape(QTabBar::RoundedNorth);
    // bottom
//    tabBar.setShape(QTabBar::RoundedSouth);
    // left
//    tabBar.setShape(QTabBar::RoundedWest);
    // right
//    tabBar.setShape(QTabBar::RoundedEast);

    const auto shortLabel = QStringLiteral("Tab %1");
    const auto longLabel = QStringLiteral("An Extremely Long Tab Label %1");

    QMap<int, QWidget*> tabs;
    for (int i = 0; i < TabCount; i++) {
        QString tabNumberString = QString::number(i);
        QLabel *label = new QLabel(QStringLiteral("Tab %1 content").arg(tabNumberString));
        tabs[i] = label;
        label->setAlignment(Qt::AlignCenter);
        stackedWidget.addWidget(label);
        tabBar.addTab(shortLabel.arg(tabNumberString));
    }

    QObject::connect(&tabBar, &QTabBar::tabMoved, [&tabs](int from, int to) {
        QWidget *thisWidget = tabs[from];
        QWidget *thatWidget = tabs[to];
        tabs[from] = thatWidget;
        tabs[to] = thisWidget;
    });

    QObject::connect(&tabBar, &QTabBar::currentChanged, [&stackedWidget, &tabs](int index) {
        if (index >= 0)
            stackedWidget.setCurrentWidget(tabs[index]);
    });

    QObject::connect(&tabBar, &QTabBar::tabCloseRequested, [&stackedWidget, &tabBar, &tabs](int index) {
        QWidget *widget = tabs[index];
        tabBar.removeTab(index);
        for (int i = index + 1; i < TabCount; i++)
            tabs[i-1] = tabs[i];
        int currentIndex = tabBar.currentIndex();
        if (currentIndex >= 0)
            stackedWidget.setCurrentWidget(tabs[currentIndex]);
        delete widget;
    });

    QLayout *layout;
    switch (tabBar.shape()) {
    case QTabBar::RoundedEast:
    case QTabBar::TriangularEast:
        tabBar.setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Expanding);
        layout = new QHBoxLayout(&widget);
        layout->addWidget(&stackedWidget);
        layout->addWidget(&tabBar);
        break;
    case QTabBar::RoundedWest:
    case QTabBar::TriangularWest:
        tabBar.setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Expanding);
        layout = new QHBoxLayout(&widget);
        layout->addWidget(&tabBar);
        layout->addWidget(&stackedWidget);
        break;
    case QTabBar::RoundedNorth:
    case QTabBar::TriangularNorth:
        tabBar.setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum);
        layout = new QVBoxLayout(&widget);
        layout->addWidget(&tabBar);
        layout->addWidget(&stackedWidget);
        break;
    case QTabBar::RoundedSouth:
    case QTabBar::TriangularSouth:
        tabBar.setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum);
        layout = new QVBoxLayout(&widget);
        layout->addWidget(&stackedWidget);
        layout->addWidget(&tabBar);
        break;
    }

    TabBarForm form;
    layout->addWidget(&form);
    layout->setAlignment(&form, Qt::AlignHCenter);

    form.ui->documentModeButton->setChecked(tabBar.documentMode());
    QObject::connect(form.ui->documentModeButton, &QCheckBox::toggled, [&] {
        tabBar.setDocumentMode(form.ui->documentModeButton->isChecked());
        // QMacStyle (and maybe other styles) requires a re-polish to get the right font
        QApplication::sendEvent(&tabBar, new QEvent(QEvent::ThemeChange));
    });

    form.ui->movableTabsButton->setChecked(tabBar.isMovable());
    QObject::connect(form.ui->movableTabsButton, &QCheckBox::toggled, [&] {
        tabBar.setMovable(form.ui->movableTabsButton->isChecked());
        tabBar.update();
    });

    form.ui->closableTabsButton->setChecked(tabBar.tabsClosable());
    QObject::connect(form.ui->closableTabsButton, &QCheckBox::toggled, [&] {
        tabBar.setTabsClosable(form.ui->closableTabsButton->isChecked());
        tabBar.update();
    });

    form.ui->expandingTabsButton->setChecked(tabBar.expanding());
    QObject::connect(form.ui->expandingTabsButton, &QCheckBox::toggled, [&] {
        tabBar.setExpanding(form.ui->expandingTabsButton->isChecked());
        tabBar.update();
    });

    form.ui->displayIconButton->setChecked(!tabBar.tabIcon(0).isNull());
    QObject::connect(form.ui->displayIconButton, &QCheckBox::toggled, [&] {
        const auto icon = form.ui->displayIconButton->isChecked() ?
                          tabBar.style()->standardIcon(QStyle::SP_ComputerIcon) : QIcon();
        for (int i = 0; i < tabBar.count(); i++)
            tabBar.setTabIcon(i, icon);
    });

    form.ui->longLabelButton->setChecked(false);
    QObject::connect(form.ui->longLabelButton, &QCheckBox::toggled, [&] {
        const auto &label = form.ui->longLabelButton->isChecked() ? longLabel : shortLabel;
        for (int i = 0; i < tabBar.count(); i++)
            tabBar.setTabText(i, label.arg(i));
    });

    QObject::connect(form.ui->shapeComboBox, QOverload<int>::of(&QComboBox::currentIndexChanged), [&](int index) {
        Q_UNUSED(index);
        // TODO
    });

    if (proxyStyle->alignment == Qt::AlignLeft)
        form.ui->leftAlignedButton->setChecked(true);
    else if (proxyStyle->alignment == Qt::AlignRight)
        form.ui->rightAlignedButton->setChecked(true);
    else
        form.ui->centeredButton->setChecked(true);
    QObject::connect(form.ui->textAlignmentGroup, QOverload<QAbstractButton *>::of(&QButtonGroup::buttonClicked), [&](QAbstractButton *b) {
        proxyStyle->alignment = b == form.ui->leftAlignedButton ? Qt::AlignLeft :
                                b == form.ui->rightAlignedButton ? Qt::AlignRight : Qt::AlignCenter;
        QApplication::sendEvent(&tabBar, new QEvent(QEvent::StyleChange));
    });

    layout->setMargin(12);
    widget.show();

    return app.exec();
}