/**
 * The value of a type combo box has been changed.
 * @param text
 *      The new text.
 */
void CreateSceFile::typeTextChangedSlot(QString text)
{
    (void)text;
    QObject* obj = sender();
    QComboBox* box = static_cast<QComboBox*>(obj);

    setMenuState();
    int row = 0;
    for(int i = 0; i < ui->filesTableWidget->rowCount(); i++)
    {
        if(box == static_cast<QComboBox*>(ui->filesTableWidget->cellWidget(i, COLUMN_TYPE)))
        {
            row = i;
            break;
        }
    }
    QString subDir =  ui->filesTableWidget->item(row,COLUMN_SUBDIR)->text();
    int index = subDir.indexOf("/", 0);
    if(index != -1)
    {
        subDir.remove(0, index);
        subDir = getSubDirectoryFromType(box->currentText()) + subDir;
    }
    else
    {
        subDir = getSubDirectoryFromType(box->currentText());
    }


    ui->filesTableWidget->item(row,COLUMN_SUBDIR)->setText(subDir);
}
/**
 * Remove file button slot function.
 */
void CreateSceFile::removeFileSlot()
{
    int selectedRow = (ui->filesTableWidget->selectedItems().isEmpty())? -1 : ui->filesTableWidget->selectedItems()[0]->row();
    if(selectedRow != -1 )
    {
        ui->filesTableWidget->removeRow(selectedRow);
        setMenuState();
    }
}
/**
 * Remove argument button slot function.
 */
void CreateSceFile::removeArgumentSlot()
{
    QList<QListWidgetItem*> items = ui->argumentsListWidget->selectedItems();
    for(int i = 0; i < items.length(); i++)
    {
        delete items[i];
    }

    setMenuState();
}
/**
 * Add argument button slot function.
 */
void CreateSceFile::addArgumentSlot()
{
    bool okPressed;
    QString arg = QInputDialog::getMultiLineText(this, "enter argument", "", "", &okPressed);
    if(okPressed)
    {
        ui->argumentsListWidget->addItem(arg);
    }

    setMenuState();
}
/**
 * Select file button slot function.
 */
void CreateSceFile::selectFileSlot()
{
    QString file = QFileDialog::QFileDialog::getSaveFileName(this, tr("Select file name"),
                                                             "", tr("Files (*)"));
    if(!file.isEmpty())
    {
        ui->fileLineEdit->setText(file.split(".")[0]);
    }

    setMenuState();
}
/**
 * Add file button slot function.
 */
void CreateSceFile::addFileSlot()
{
    QStringList files = QFileDialog::getOpenFileNames(this, tr("Select files"),
                                                      "", tr("Files (*)"));
    if(!files.isEmpty())
    {
        for(auto el : files)
        {
            QString type = getFileTypeFromFile(el);
            addTableRow(getSubDirectoryFromType(type), type, el);
        }
    }

    setMenuState();
}
Exemple #7
0
void IN_Frame(void)
{
    static int prev_state = -1;
    int state = -1;
    processMotionEvents();
    processTrackballEvents();

    /* We are in game and neither console/ui is active */
    if (cls.state == CA_ACTIVE && Key_GetCatcher() == 0)
        state = 1;
    else
        state = 0;

    if (state != prev_state)
    {
        setMenuState(state);
        prev_state = state;
    }
}
/**
 * Constructor.
 * @param parent
 *      The parent.
 * @param scriptWindowScriptTable
 *      Pointer to the script table in the script window.
 */
CreateSceFile::CreateSceFile(QWidget *parent, QTableWidget *scriptWindowScriptTable) :
    QMainWindow(parent), ui(new Ui::CreateSceFile), m_scriptWindowScriptTable(scriptWindowScriptTable), m_configFileName()
{
    ui->setupUi(this);

    QShortcut* shortcut = new QShortcut(QKeySequence("Ctrl+Shift+X"), this);
    QObject::connect(shortcut, SIGNAL(activated()), this, SLOT(close()));

    connect(ui->selectFile, SIGNAL(clicked()), this, SLOT(selectFileSlot()));
    connect(ui->addFile, SIGNAL(clicked()), this, SLOT(addFileSlot()));
    connect(ui->addFolder, SIGNAL(clicked()), this, SLOT(addFolderSlot()));
    connect(ui->removeFile, SIGNAL(clicked()), this, SLOT(removeFileSlot()));
    connect(ui->addArgument, SIGNAL(clicked()), this, SLOT(addArgumentSlot()));
    connect(ui->removeArgument, SIGNAL(clicked()), this, SLOT(removeArgumentSlot()));
    connect(ui->actionGenerateFileSce, SIGNAL(triggered(bool)), this, SLOT(generateSlot()));
    connect(ui->actionGenerateCompressedFile, SIGNAL(triggered(bool)), this, SLOT(generateCompressedFileSlot()));
    connect(ui->fileLineEdit, SIGNAL(textChanged(QString)), this, SLOT(sceFileTextChangedSlot(QString)));
    connect(ui->filesTableWidget, SIGNAL(cellChanged(int,int)), this, SLOT(filesTableCellChangedSlot()));
    connect(ui->addAllFromScriptTable, SIGNAL(clicked()), this, SLOT(addAllFromScriptWindow()));

    connect(ui->actionLoadConfig, SIGNAL(triggered()), this, SLOT(loadConfigSlot()));
    connect(ui->actionUnloadConfig, SIGNAL(triggered()), this, SLOT(unloadConfigSlot()));
    connect(ui->actionSaveConfig, SIGNAL(triggered()), this, SLOT(saveConfigSlot()));
    connect(ui->actionSaveConfigAs, SIGNAL(triggered()), this, SLOT(saveConfigAsSlot()));
    connect(ui->minScVersionMajor, SIGNAL(valueChanged(int)), this, SLOT(versionSpinboxValueChangedSlot(int)));
    connect(ui->minScVersionMinor, SIGNAL(valueChanged(int)), this, SLOT(versionSpinboxValueChangedSlot(int)));

    connect(ui->fileEntryDown, SIGNAL(clicked()), this, SLOT(fileEntryDownSlot()));
    connect(ui->fileEntryUp, SIGNAL(clicked()), this, SLOT(fileEntryUpSlot()));
    connect(ui->argEntryDown, SIGNAL(clicked()), this, SLOT(argEntryDownSlot()));
    connect(ui->argEntryUp, SIGNAL(clicked()), this, SLOT(argEntryUpSlot()));

    connect(ui->filesTableWidget, SIGNAL(dropEventSignal(int,int,QStringList)), this, SLOT(tableDropEventSlot(int,int,QStringList)));

    ui->progressBar->setValue(0);

    ui->minScVersionMajor->setValue(MainWindow::VERSION.split(".")[0].toUInt());
    ui->minScVersionMinor->setValue(MainWindow::VERSION.split(".")[1].toUInt());

    setMenuState();
    setTitle("");
}
/**
 * The content of the sce file line edit has been changed.
 * @param text
 *      The new text.
 */
void CreateSceFile::sceFileTextChangedSlot(QString text)
{
    (void)text;
    setMenuState();
}
/**
 * Loads the current config file (m_configFileName).
 */
void CreateSceFile::loadConfigFile(void)
{
    if(!m_configFileName.isEmpty())
    {
        setGuiElementsToDefault();
        setTitle(m_configFileName);

        if(!m_configFileName.isEmpty())
        {
            QFile file(m_configFileName);
            QDomDocument doc("SceConfiguration");

            if (file.open(QFile::ReadOnly))
            {
                file.close();

                if (!doc.setContent(&file))
                {
                    if(!file.readAll().isEmpty())
                    {
                        QMessageBox::critical(this, "parse error", "could not parse " + m_configFileName);

                        m_configFileName = "";
                        setTitle(m_configFileName);
                        emit configHasToBeSavedSignal();
                    }
                }
                else
                {

                    QDomElement docElem = doc.documentElement();
                    ui->filesTableWidget->blockSignals(true);

                    QDomNodeList nodeList = docElem.elementsByTagName("ScriptWindowState");
                    QDomNode nodeItem = nodeList.at(0);
                    ui->withScriptWindowCheckBox->setChecked((nodeItem.attributes().namedItem("withScriptWindow").nodeValue() == "1"));
                    ui->notMinimized->setChecked((nodeItem.attributes().namedItem("notMinimized").nodeValue() == "1"));
                    ui->fileLineEdit->setText(MainWindow::convertToAbsolutePath(m_configFileName, nodeItem.attributes().namedItem("sceFileName").nodeValue()));

                    QStringList versionList = nodeItem.attributes().namedItem("minScVersion").nodeValue().split(".");
                    if(versionList.length() == 2)
                    {
                        ui->minScVersionMajor->setValue(versionList[0].toUInt());
                        ui->minScVersionMinor->setValue(versionList[1].toUInt());
                    }

                    nodeList = docElem.elementsByTagName("File");
                    for (int i = 0; i < nodeList.size(); i++)
                    {
                        nodeItem = nodeList.at(i);
                        QString subDirectory = nodeItem.attributes().namedItem("subDirectory").nodeValue();
                        QString type = (nodeItem.attributes().namedItem("type").nodeValue());
                        QString source = MainWindow::convertToAbsolutePath(m_configFileName, nodeItem.attributes().namedItem("source").nodeValue());
                        addTableRow(subDirectory, type, source);
                    }

                    nodeList = docElem.elementsByTagName("ScriptArgument");
                    for (int i = 0; i < nodeList.size(); i++)
                    {
                        nodeItem = nodeList.at(i);
                        QString value = nodeItem.attributes().namedItem("value").nodeValue();
                        ui->argumentsListWidget->addItem(value);
                    }

                    ui->filesTableWidget->blockSignals(false);
                    resizeTableColumnsSlot();

                    QStringList showStrList = m_configFileName.split("/");
                    statusBar()->showMessage(showStrList[showStrList.size() - 1] + " loaded", 5000);
                    setMenuState();
                }
            }
        }
        else
        {
            QMessageBox::critical(this, "could not open file", m_configFileName);

            m_configFileName = "";
            setTitle(m_configFileName);
            emit configHasToBeSavedSignal();
        }
    }
}