ToolInstance::ToolInstance(QString filename, ToolInformation information, mcrl2::gui::qt::PersistentFileDialog* fileDialog, QWidget *parent) : QWidget(parent), m_filename(filename), m_info(information), m_fileDialog(fileDialog) { m_ui.setupUi(this); connect(this, SIGNAL(colorChanged(QColor)), this, SLOT(onColorChanged(QColor))); connect(&m_process, SIGNAL(stateChanged(QProcess::ProcessState)), this, SLOT(onStateChange(QProcess::ProcessState))); connect(&m_process, SIGNAL(readyReadStandardOutput()), this, SLOT(onStandardOutput())); connect(&m_process, SIGNAL(readyReadStandardError()), this, SLOT(onStandardError())); connect(m_ui.btnRun, SIGNAL(clicked()), this, SLOT(onRun())); connect(m_ui.btnAbort, SIGNAL(clicked()), this, SLOT(onAbort())); connect(m_ui.btnSave, SIGNAL(clicked()), this, SLOT(onSave())); connect(m_ui.btnClear, SIGNAL(clicked()), m_ui.edtOutput, SLOT(clear())); QFileInfo fileInfo(filename); m_process.setWorkingDirectory(fileInfo.absoluteDir().absolutePath()); m_ui.lblDirectoryValue->setText(fileInfo.absoluteDir().absolutePath()); m_ui.lblFileValue->setText(fileInfo.fileName()); if (m_info.hasOutput()) { QDir dir = fileInfo.absoluteDir(); QString newfile = fileInfo.baseName().append(".%1").arg(m_info.output); int filenr = 0; while(dir.exists(newfile)) { filenr++; newfile = fileInfo.baseName().append("_%1.%2").arg(filenr).arg(m_info.output); } m_pckFileOut = new FilePicker(m_fileDialog, m_ui.pckFileOut); m_ui.pckFileOut->layout()->addWidget(m_pckFileOut); m_pckFileOut->setText(newfile); } else { m_pckFileOut = NULL; m_ui.lblFileOut->setVisible(false); m_ui.pckFileOut->setVisible(false); } if (m_info.hasSecondInput()) { m_pckFileIn = new FilePicker(m_fileDialog, m_ui.pckFileIn, false); m_ui.pckFileIn->layout()->addWidget(m_pckFileIn); } else { m_pckFileIn = NULL; m_ui.lblFileIn->setVisible(false); m_ui.pckFileIn->setVisible(false); } QFormLayout *formLayout = new QFormLayout(); formLayout->setFieldGrowthPolicy(QFormLayout::ExpandingFieldsGrow); for (int i = 0; i < m_info.options.count(); i++) { ToolOption option = m_info.options.at(i); QWidget *nameOpt = NULL; QCheckBox* cbOpt = NULL; QVBoxLayout *lytOpt = new QVBoxLayout(); if (option.argument.type == EnumArgument) { nameOpt = new QLabel("<b>"+option.nameLong+": </b>"); } else { cbOpt = new QCheckBox(option.nameLong + ": ", this); cbOpt->setChecked(option.standard); QFont font(cbOpt->font()); font.setBold(true); cbOpt->setFont(font); nameOpt = cbOpt; } formLayout->addRow(nameOpt, lytOpt); QLabel *lblOpt = new QLabel(option.description, this); lblOpt->setAlignment(Qt::AlignJustify | Qt::AlignTop); lblOpt->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum); lblOpt->setWordWrap(true); lytOpt->addWidget(lblOpt); if (!option.hasArgument()) { m_optionValues.append(new OptionValue(option, cbOpt)); } else { switch (option.argument.type) { case StringArgument: case LevelArgument: case IntegerArgument: case RealArgument: case BooleanArgument: { QHBoxLayout *lytArg = new QHBoxLayout(); lytArg->setSpacing(6); QWidget *edtArg = NULL; switch (option.argument.type) { case LevelArgument: { QLineEdit *edtLdt = new QLineEdit("verbose", this); m_optionValues.append(new OptionValue(option, cbOpt, edtLdt)); edtArg = edtLdt; } break; case IntegerArgument: { QSpinBox *edtSpb = new QSpinBox(this); edtSpb->setRange(std::numeric_limits<int>::min(), std::numeric_limits<int>::max()); if (option.argument.optional) { QCheckBox *cbOptional = new QCheckBox(this); lytArg->addWidget(cbOptional); m_optionValues.append(new OptionValue(option, cbOpt, edtSpb, cbOptional)); } else { m_optionValues.append(new OptionValue(option, cbOpt, edtSpb)); } edtArg = edtSpb; } break; case RealArgument: { QDoubleSpinBox *edtSpb = new QDoubleSpinBox(this); edtSpb->setRange(std::numeric_limits<double>::min(), std::numeric_limits<double>::max()); if (option.argument.optional) { QCheckBox *cbOptional = new QCheckBox(this); lytArg->addWidget(cbOptional); m_optionValues.append(new OptionValue(option, cbOpt, edtSpb, cbOptional)); } else { m_optionValues.append(new OptionValue(option, cbOpt, edtSpb)); } edtArg = edtSpb; } break; case BooleanArgument: { QCheckBox *edtChb = new QCheckBox("Yes", this); m_optionValues.append(new OptionValue(option, cbOpt, edtChb)); edtArg = edtChb; } break; case StringArgument: default: { QLineEdit *edtLdt = new QLineEdit(this); m_optionValues.append(new OptionValue(option, cbOpt, edtLdt)); edtArg = edtLdt; } break; } edtArg->setMinimumWidth(300); lytArg->addWidget(edtArg); if (!option.argument.optional && option.argument.type != BooleanArgument) { QLabel *lblReq = new QLabel("*", this); lytArg->addWidget(lblReq); } QSpacerItem *spacer = new QSpacerItem(100, 20, QSizePolicy::Expanding); lytArg->addItem(spacer); lytOpt->addLayout(lytArg); } break; case FileArgument: { QHBoxLayout *lytArg = new QHBoxLayout(); lytArg->setSpacing(6); FilePicker *edtArg = new FilePicker(m_fileDialog, this, false); lytArg->addWidget(edtArg); m_optionValues.append(new OptionValue(option, cbOpt, edtArg)); if (!option.argument.optional) { QLabel *lblReq = new QLabel("*", this); lytArg->addWidget(lblReq); } QSpacerItem *spacer = new QSpacerItem(100, 20, QSizePolicy::Expanding); lytArg->addItem(spacer); lytOpt->addLayout(lytArg); } break; case EnumArgument: { QFormLayout *lytValues = new QFormLayout(); lytValues->setSpacing(6); QButtonGroup *grpValues = new QButtonGroup(this); for (int j = 0; j < option.argument.values.count(); j++) { ToolValue val = option.argument.values.at(j); QRadioButton *rbVal = new QRadioButton(val.nameLong, this); rbVal->setChecked(val.standard); grpValues->addButton(rbVal); QLabel *lblVal = new QLabel(val.description, this); lblVal->setWordWrap(true); lytValues->addRow(rbVal, lblVal); } m_optionValues.append(new OptionValue(option, cbOpt, grpValues)); lytOpt->addLayout(lytValues); } break; default: break; } } } m_ui.scrollWidget->setLayout(formLayout); }
void MainWindow::initialize() { createActions(); createTrayIcon(); setIcon(); statusLedLabel = new QLabel; if(statusLedLabel) { statusBar()->addWidget(statusLedLabel); statusLedLabel->setPixmap(QPixmap("://images/led-red.png")); } statusLabel = new QLabel; if(statusLabel) { statusBar()->addWidget(statusLabel); statusLabel->setText(tr("Minecraft Server: Stopped")); } ui->actionStart->setEnabled(true); ui->actionStop->setEnabled(false); ui->actionSettings->setEnabled(true); ui->serverPropertiesTextEdit->setEnabled(true); ui->sendCommandButton->setEnabled(false); ui->actionSaveServerProperties->setEnabled(false); if(trayIcon) { trayIcon->show(); } m_pServerProcess = new QProcess(this); connect( m_pServerProcess, SIGNAL(started()), SLOT(onStart()) ); connect( m_pServerProcess, SIGNAL(finished(int,QProcess::ExitStatus)), SLOT(onFinish(int,QProcess::ExitStatus)) ); connect( m_pServerProcess, SIGNAL(readyReadStandardOutput()), SLOT(onStandardOutput()) ); connect( m_pServerProcess, SIGNAL(readyReadStandardError()), SLOT(onStandardError()) ); m_pFileSystemWatcher = new QFileSystemWatcher(this); connect( m_pFileSystemWatcher, SIGNAL(fileChanged(QString)), SLOT(onWatchedFileChanged(QString)) ); m_pDirSystemWatcher = new QFileSystemWatcher(this); connect( m_pDirSystemWatcher, SIGNAL(directoryChanged(QString)), SLOT(onWatchedDirChanged(QString)) ); m_pSettings = new QSettings(QSettings::IniFormat, QSettings::UserScope, "Qt Minecraft Server", "qtmcserver", this); loadSettings(); if(m_mcServerPath.isEmpty()) { on_actionSettings_triggered(); } loadServerProperties(); if(!m_mcServerPath.isEmpty()) { updateWatchedFileSystemPath("", getMinecraftServerPropertiesPath(m_mcServerPath)); updateWatchedDirSystemPath("", getMinecraftServerWorkingDirectoryPath(m_mcServerPath)); } }