void ConfigMultiRotorWidget::setupUI(SystemSettings::AirframeTypeOptions frameType)
{
    Q_ASSERT(m_aircraft);
    Q_ASSERT(uiowner);
    Q_ASSERT(quad);

    int i;

    // set aircraftType to Multirotor, disable triyaw channel
    setComboCurrentIndex(m_aircraft->aircraftType, m_aircraft->aircraftType->findText("Multirotor"));
    m_aircraft->triYawChannelBox->setEnabled(false);

    // disable all motor channel boxes
    for (i=1; i <=8; i++) {
        // do it manually so we can turn off any error decorations
        QComboBox *combobox = uiowner->findChild<QComboBox*>("multiMotorChannelBox" + QString::number(i));
        if (combobox) {
            combobox->setEnabled(false);
            combobox->setItemData(0, 0, Qt::DecorationRole);
        }
    }


    switch(frameType) {
    case SystemSettings::AIRFRAMETYPE_TRI:
        setComboCurrentIndex( m_aircraft->multirotorFrameType, m_aircraft->multirotorFrameType->findData(SystemSettings::AIRFRAMETYPE_TRI));

        //Enable all necessary motor channel boxes...
        enableComboBoxes(uiowner, CHANNELBOXNAME, 3, true);

        m_aircraft->mrRollMixLevel->setValue(100);
        m_aircraft->mrPitchMixLevel->setValue(100);
        setYawMixLevel(50);

        m_aircraft->triYawChannelBox->setEnabled(true);
        break;
    case SystemSettings::AIRFRAMETYPE_QUADX:
        setComboCurrentIndex( m_aircraft->multirotorFrameType, m_aircraft->multirotorFrameType->findData(SystemSettings::AIRFRAMETYPE_QUADX));

        //Enable all necessary motor channel boxes...
        enableComboBoxes(uiowner, CHANNELBOXNAME, 4, true);

        // init mixer levels
        m_aircraft->mrRollMixLevel->setValue(50);
        m_aircraft->mrPitchMixLevel->setValue(50);
        setYawMixLevel(50);
        break;
    case SystemSettings::AIRFRAMETYPE_QUADP:
        setComboCurrentIndex( m_aircraft->multirotorFrameType, m_aircraft->multirotorFrameType->findData(SystemSettings::AIRFRAMETYPE_QUADP));

        //Enable all necessary motor channel boxes...
        enableComboBoxes(uiowner, CHANNELBOXNAME, 4, true);

        m_aircraft->mrRollMixLevel->setValue(100);
        m_aircraft->mrPitchMixLevel->setValue(100);
        setYawMixLevel(50);
        break;
    case SystemSettings::AIRFRAMETYPE_HEXA:
        setComboCurrentIndex( m_aircraft->multirotorFrameType, m_aircraft->multirotorFrameType->findData(SystemSettings::AIRFRAMETYPE_HEXA));

        //Enable all necessary motor channel boxes...
        enableComboBoxes(uiowner, CHANNELBOXNAME, 6, true);

        m_aircraft->mrRollMixLevel->setValue(50);
        m_aircraft->mrPitchMixLevel->setValue(33);
        setYawMixLevel(33);
        break;
    case SystemSettings::AIRFRAMETYPE_HEXAX:
        setComboCurrentIndex( m_aircraft->multirotorFrameType, m_aircraft->multirotorFrameType->findData(SystemSettings::AIRFRAMETYPE_HEXAX));

        //Enable all necessary motor channel boxes...
        enableComboBoxes(uiowner, CHANNELBOXNAME, 6, true);

        m_aircraft->mrRollMixLevel->setValue(33);
        m_aircraft->mrPitchMixLevel->setValue(50);
        setYawMixLevel(33);
        break;
    case SystemSettings::AIRFRAMETYPE_HEXACOAX:
        setComboCurrentIndex( m_aircraft->multirotorFrameType, m_aircraft->multirotorFrameType->findData(SystemSettings::AIRFRAMETYPE_HEXACOAX));

        //Enable all necessary motor channel boxes...
        enableComboBoxes(uiowner, CHANNELBOXNAME, 6, true);

        m_aircraft->mrRollMixLevel->setValue(100);
        m_aircraft->mrPitchMixLevel->setValue(50);
        setYawMixLevel(66);
        break;
    case SystemSettings::AIRFRAMETYPE_OCTO:
        setComboCurrentIndex( m_aircraft->multirotorFrameType, m_aircraft->multirotorFrameType->findData(SystemSettings::AIRFRAMETYPE_OCTO));

        //Enable all necessary motor channel boxes
        enableComboBoxes(uiowner, CHANNELBOXNAME, 8, true);

        m_aircraft->mrRollMixLevel->setValue(33);
        m_aircraft->mrPitchMixLevel->setValue(33);
        setYawMixLevel(25);
        break;
    case SystemSettings::AIRFRAMETYPE_OCTOV:
        setComboCurrentIndex( m_aircraft->multirotorFrameType, m_aircraft->multirotorFrameType->findData(SystemSettings::AIRFRAMETYPE_OCTOV));
        //Enable all necessary motor channel boxes
        enableComboBoxes(uiowner, CHANNELBOXNAME, 8, true);

        m_aircraft->mrRollMixLevel->setValue(25);
        m_aircraft->mrPitchMixLevel->setValue(25);
        setYawMixLevel(25);
        break;
    case SystemSettings::AIRFRAMETYPE_OCTOCOAXP:
        setComboCurrentIndex( m_aircraft->multirotorFrameType, m_aircraft->multirotorFrameType->findData(SystemSettings::AIRFRAMETYPE_OCTOCOAXP));

        //Enable all necessary motor channel boxes
        enableComboBoxes(uiowner, CHANNELBOXNAME, 8, true);

        m_aircraft->mrRollMixLevel->setValue(100);
        m_aircraft->mrPitchMixLevel->setValue(100);
        setYawMixLevel(50);
        break;
    case SystemSettings::AIRFRAMETYPE_OCTOCOAXX:
        setComboCurrentIndex( m_aircraft->multirotorFrameType, m_aircraft->multirotorFrameType->findData(SystemSettings::AIRFRAMETYPE_OCTOCOAXX));

        //Enable all necessary motor channel boxes
        enableComboBoxes(uiowner, CHANNELBOXNAME, 8, true);

        m_aircraft->mrRollMixLevel->setValue(50);
        m_aircraft->mrPitchMixLevel->setValue(50);
        setYawMixLevel(50);
        break;
    default:
        Q_ASSERT(0);
        break;
    }

    //Draw the appropriate airframe
    drawAirframe(frameType);
}
Example #2
0
void TransPanel::onClickBtnSerialPortOpen()
{
	QComboBox* spCombox = ui.comboBox_serialport ; 
	int currentIdx = spCombox->currentIndex() ; 
	int portNum =spCombox->itemData(currentIdx).toInt();
	LOG("选择串口:%d\r\n" ,portNum );

	if(serialPort_==NULL)
	{
		serialPort_ = new SerialPort(portNum ,DEFAULT_SERIALPORT_BAUD);
		if(serialPort_ == NULL)
			return ;

		serialPort_->set_recv_data_callback(boost::bind(&TransPanel::recvSerialPortDataCB ,this,_1));//数据回调
		serialPort_->set_recv_error_callback(boost::bind(&TransPanel::recvSerialPortErrorCB ,this,_1)); //错误回调

	
		bool openSuccess = serialPort_->open() ;  //打开串口
		if(!openSuccess)
		{
			std::string error_msg = serialPort_->get_last_error_message() ;
			char errorMessage[512] ; 
			sprintf_s(errorMessage,512 , "COM%d 打开失败,错误原因:%s" ,portNum , error_msg.c_str()  );
			LOG(errorMessage);
			SERROR(errorMessage);

			ui.pushButton_com_open->setText("打开串口");
			delete serialPort_ ;
			serialPort_ =NULL ; 

		}
		else
		{
			char message[512] ; 
			sprintf_s(message , 512 ,"COM%d 打开成功!" , portNum);
			LOG(message);
			SINFO(message);

			ui.pushButton_com_open->setText("关闭串口");
			spCombox->setEnabled(false);
		}
	}
	else
	{
	
		serialPort_->close() ;
		delete serialPort_ ;
		serialPort_ = NULL ; 

		char message[512] ; 
		sprintf_s(message , 512 ,"COM%d 已经关闭!" , portNum);
		LOG(message);
		SINFO(message);

		ui.pushButton_com_open->setText("打开串口");
		spCombox->setEnabled(true);
	}

}
Example #3
0
bool Pad::collectExtraInfo(QWidget * parent, const QString & family, const QString & prop, const QString & value, bool swappingEnabled, QString & returnProp, QString & returnValue, QWidget * & returnWidget) 
{
	if (prop.compare("shape", Qt::CaseInsensitive) == 0) {
		returnWidget = setUpDimEntry(false, false, false, returnWidget);
        returnWidget->setEnabled(swappingEnabled);
		returnProp = tr("shape");
		return true;
	}

    if (!copperBlocker()) {
	    if (prop.compare("connect to", Qt::CaseInsensitive) == 0) {
		    QComboBox * comboBox = new QComboBox();
		    comboBox->setObjectName("infoViewComboBox");
		    comboBox->setEditable(false);
		    comboBox->setEnabled(swappingEnabled);
		    comboBox->addItem(tr("center"), "center");
		    comboBox->addItem(tr("north"), "north");
		    comboBox->addItem(tr("east"), "east");
		    comboBox->addItem(tr("south"), "south");
		    comboBox->addItem(tr("west"), "west");
		    QString connectAt = m_modelPart->localProp("connect").toString();
		    for (int i = 0; i < comboBox->count(); i++) {
			    if (comboBox->itemData(i).toString().compare(connectAt) == 0) {
				    comboBox->setCurrentIndex(i);
				    break;
			    }
		    }

		    connect(comboBox, SIGNAL(currentIndexChanged(const QString &)), this, SLOT(terminalPointEntry(const QString &)));

		    returnWidget = comboBox;
		    returnProp = tr("connect to");
		    return true;
	    }
    }
Example #4
0
bool Ruler::collectExtraInfo(QWidget * parent, const QString & family, const QString & prop, const QString & value, bool swappingEnabled, QString & returnProp, QString & returnValue, QWidget * & returnWidget)
{
	bool result = PaletteItem::collectExtraInfo(parent, family, prop, value, swappingEnabled, returnProp, returnValue, returnWidget);

	if (prop.compare("width", Qt::CaseInsensitive) == 0) {
		returnProp = tr("width");

		int units = m_modelPart->localProp("width").toString().contains("cm") ? IndexCm : IndexIn;
		QLineEdit * e1 = new QLineEdit();
		QDoubleValidator * validator = new QDoubleValidator(e1);
		validator->setRange(1.0, 20 * ((units == IndexCm) ? 2.54 : 1), 2);
		validator->setNotation(QDoubleValidator::StandardNotation);
		e1->setValidator(validator);
		e1->setEnabled(swappingEnabled);
		QString temp = m_modelPart->localProp("width").toString();
		temp.chop(2);
		e1->setText(temp);
		e1->setObjectName("infoViewLineEdit");	
        e1->setMaximumWidth(80);

		m_widthEditor = e1;
		m_widthValidator = validator;

		QComboBox * comboBox = new QComboBox(parent);
		comboBox->setEditable(false);
		comboBox->setEnabled(swappingEnabled);
		comboBox->addItem("cm");
		comboBox->addItem("in");
		comboBox->setCurrentIndex(units);
		m_unitsEditor = comboBox;
		comboBox->setObjectName("infoViewComboBox");	
        comboBox->setMinimumWidth(60);


		QHBoxLayout * hboxLayout = new QHBoxLayout();
		hboxLayout->setAlignment(Qt::AlignLeft);
		hboxLayout->setContentsMargins(0, 0, 0, 0);
		hboxLayout->setSpacing(0);
		hboxLayout->setMargin(0);


		hboxLayout->addWidget(e1);
		hboxLayout->addWidget(comboBox);

		QFrame * frame = new QFrame();
		frame->setLayout(hboxLayout);
		frame->setObjectName("infoViewPartFrame");

		connect(e1, SIGNAL(editingFinished()), this, SLOT(widthEntry()));
		connect(comboBox, SIGNAL(currentIndexChanged(const QString &)), this, SLOT(unitsEntry(const QString &)));

        returnValue = temp + QString::number(units);
		returnWidget = frame;

		return true;
	}
Example #5
0
SetFontDlg::SetFontDlg(int logicalIndex,QWidget* parent):m_LogicalIndex(logicalIndex),QDialog(parent)
{	
//	this->setFixedSize(300,400);

	QCheckBox* bold = new QCheckBox("Bold",this);
	QCheckBox* italic = new QCheckBox("Italic",this);	
	QLabel*	   fontSizeLabel = new QLabel("Font Size:",this);
	QSpinBox*  fontSize = new QSpinBox(this);
	QLabel*	   fontColorLabel = new QLabel("Font Color:",this);
	QComboBox* fontColor = new QComboBox(this);

	QHBoxLayout* layout1 = new QHBoxLayout;
	QHBoxLayout* layout2 = new QHBoxLayout;
	QHBoxLayout* layout3 = new QHBoxLayout;
	QGridLayout* layout = new QGridLayout;	  
	layout1->addWidget(bold);
	layout1->addWidget(italic);
	layout2->addWidget(fontSizeLabel);
	layout2->addWidget(fontSize);
	layout3->addWidget(fontColorLabel);
	layout3->addWidget(fontColor);
	layout->addLayout(layout1,0,0,Qt::AlignHCenter);
	layout->addLayout(layout2,1,0,Qt::AlignHCenter);
	layout->addLayout(layout3,2,0,Qt::AlignHCenter);
	this->setLayout(layout);
	this->setWindowTitle("Set Font");

	fontSize->setValue(12);
	fontSize->setMinimum(12);
	fontSize->setMaximum(18); 
	fontColor->addItem("Black");
	fontColor->addItem("Red");
	fontColor->addItem("Green");
	fontColor->addItem("Blue");
	fontColor->addItem("Gray");	
	fontColor->setCurrentIndex(0);
	if(logicalIndex==2 || logicalIndex==3 || logicalIndex==4)
		fontColor->setEnabled(false);

	connect(bold,SIGNAL(stateChanged(int)),this,SLOT(SetBold(int)));
	connect(italic,SIGNAL(stateChanged(int)),this,SLOT(SetItalic(int)));
	connect(fontSize,SIGNAL(valueChanged(int)),this,SLOT(SetFontSize(int)));
	connect(fontColor,SIGNAL(currentIndexChanged(int)),this,SLOT(SetFontColor(int)));

	connect(this,SIGNAL(SetBoldSignal(int,bool)),parent->parent(),SLOT(SetBold(int,bool)));
	connect(this,SIGNAL(SetItalicSignal(int,bool)),parent->parent(),SLOT(SetItalic(int,bool)));
	connect(this,SIGNAL(SetFontSizeSignal(int,int)),parent->parent(),SLOT(SetFontSize(int,int)));
	connect(this,SIGNAL(SetFontColorSignal(int,const QColor&)),parent->parent(),SLOT(SetFontColor(int,const QColor&)));
	QWidget* createWidgets(BasePropertyWidget* parent)
	{
		m_comboBox = new QComboBox(parent);
		m_comboBox->setEnabled(!parent->readOnly());
		auto enumMeta = parent->property()->getMeta<meta::Enum>();
		if (enumMeta)
		{
			for (const auto& v : enumMeta->values)
				m_enumValues.push_back(QString::fromStdString(v));
		}
		m_comboBox->addItems(m_enumValues);

		void(QComboBox::*currentIndexChanged)(int) = &QComboBox::currentIndexChanged; // Get the right overload
		QObject::connect(m_comboBox, currentIndexChanged, parent, &BasePropertyWidget::setWidgetDirty);
		return m_comboBox;
	}
Example #7
0
// This function controls whether or not the settings are read-only.
void SySettingsModule::setEditableItems(bool itemStatus)
{   
    QComboBox * combobox;
    for (int i = 0; i < editableComboItems.size(); i++)
    {
        combobox = editableComboItems.value(i);
        combobox->setEnabled(itemStatus);
    }

    QCheckBox * checkbox;
    for (int i = 0; i < editableCheckBoxItems.size(); i++)
    {
        checkbox = editableCheckBoxItems.value(i);
        checkbox->setEnabled(itemStatus);
    }
}
Example #8
0
// Create new combo widget
QtWidgetObject* AtenTreeGuiDialog::addCombo(TreeGuiWidget* widget, QString label)
{
	QtWidgetObject* qtwo = widgetObjects_.add();
	QComboBox* combo = new QComboBox(this);
	qtwo->set(widget, combo, label);
	// Add items to combo and set current index
	for (int n=0; n<widget->comboItems().count(); ++n) combo->addItem(widget->comboItems().at(n));
	combo->setCurrentIndex(widget->valueI() - 1);
	combo->setEnabled(widget->enabled());
	combo->setVisible(widget->visible());
	combo->setMinimumHeight(WIDGETHEIGHT);
	combo->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
	// Connect signal to master slot
	QObject::connect(combo, SIGNAL(currentIndexChanged(int)), this, SLOT(comboWidget_currentIndexChanged(int)));
	return qtwo;
}
QWidget* ChannelRoutingDelegate::createEditor ( QWidget *pParent,
	const QStyleOptionViewItem & option, const QModelIndex& index ) const
{
	if (!index.isValid())
		return NULL;

	if (index.column() != 0)
		return NULL;

	ChannelRoutingItem item = index.model()->data(index, Qt::DisplayRole).value<ChannelRoutingItem>();

	QComboBox* pComboBox = new QComboBox(pParent);
	pComboBox->addItems(item.options);
	pComboBox->setCurrentIndex(item.selection);
	pComboBox->setEnabled(true);
	pComboBox->setGeometry(option.rect);
	return pComboBox;
}
Example #10
0
void Board::setupLoadImage(QWidget * parent, const QString & family, const QString & prop, const QString & value, bool swappingEnabled, QString & returnProp, QString & returnValue, QWidget * & returnWidget) 
{
    Q_UNUSED(returnValue);
    Q_UNUSED(value);
    Q_UNUSED(prop);
    Q_UNUSED(family);
    Q_UNUSED(parent);

	returnProp = tr("image file");

	QFrame * frame = new QFrame();
	frame->setObjectName("infoViewPartFrame");
	QVBoxLayout * vboxLayout = new QVBoxLayout();
	vboxLayout->setContentsMargins(0, 0, 0, 0);
	vboxLayout->setSpacing(0);
	vboxLayout->setMargin(0);

	QComboBox * comboBox = new QComboBox();
	comboBox->setObjectName("infoViewComboBox");
	comboBox->setEditable(false);
	comboBox->setEnabled(swappingEnabled);
	m_fileNameComboBox = comboBox;

	setFileNameItems();

	connect(comboBox, SIGNAL(currentIndexChanged(const QString &)), this, SLOT(fileNameEntry(const QString &)));

	QPushButton * button = new QPushButton (tr("load image file"));
	button->setObjectName("infoViewButton");
	connect(button, SIGNAL(pressed()), this, SLOT(prepLoadImage()));
	button->setEnabled(swappingEnabled);

	vboxLayout->addWidget(comboBox);
	vboxLayout->addWidget(button);

	frame->setLayout(vboxLayout);
	returnWidget = frame;

	returnProp = "";
}
void WidgetCtrlParameters::update(QMap<QString,ModPlusCtrls *> ctrlsMap)
{
    QStringList models = ctrlsMap.keys();

    // delete old widgets
    for(int i=0;i<_widgetsCreated.size();i++)
        delete _widgetsCreated.at(i);

    _widgetsCreated.clear();

    // clear layout
    delete _layout;
    _layout = new QGridLayout(this);
    this->setLayout(_layout);



    // empty maps
    _ctrls.clear();
    _comboBoxs.clear();
    _parametersPbs.clear();
    _compilePbs.clear();

    QString curmodel;
    ModPlusCtrls *curCtrls;
    int iRow;
    for(int i=0;i<models.size();i++)
    {
        curmodel = models.at(i);
        curCtrls = ctrlsMap.value(curmodel);

        // insert in _ctrls
        _ctrls.insert(curmodel,curCtrls);

        // add model combobox
        QComboBox *newCb = new QComboBox(this);
        //Ctrl box
        ModPlusCtrl::Type curCtrlType;
        ModPlusCtrl *curCtrl;

        for(int i=0;i< curCtrls->keys().size();i++)
        {
            curCtrlType = curCtrls->keys().at(i);
            curCtrl = curCtrls->value(curCtrlType);

            newCb->addItem(curCtrl->name(),curCtrlType);

            if(curCtrlType == curCtrls->currentCtrlType())
            {
                newCb->setCurrentIndex(i);
            }
        }

        newCb->setEnabled(!_isResult);
        _comboBoxs.insert(curmodel,newCb);
        iRow = _layout->rowCount()+1;
        QLabel *newLabel = new QLabel(curmodel,this);
        _layout->addWidget(newLabel,iRow,0);
        _layout->addWidget(newCb,iRow,1);

        // add push buttons
        QPushButton* newParamPb = new QPushButton("Parameters ...",this);
        _layout->addWidget(newParamPb,iRow,2);
        _parametersPbs.insert(curmodel,newParamPb);

        QPushButton* newCompilePb = new QPushButton("Compile",this);
        _layout->addWidget(newCompilePb,iRow,3);
        _compilePbs.insert(curmodel,newCompilePb);

        connect(newCb, SIGNAL(currentIndexChanged(int)),this, SLOT(changedCtrl()));
        connect(newParamPb, SIGNAL(clicked()),this,SLOT(openCtrlParameters()));
        connect(newCompilePb, SIGNAL(clicked()),this,SLOT(compile()));

        // horizontal spacer
        //        QSpacerItem* spacer = new QSpacerItem(10,10,QSizePolicy::Expanding,QSizePolicy::Ignored);
        //        _layout->addItem(spacer,iRow,4);
        _layout->setColumnStretch(4,10);
        _widgetsCreated.push_back(newLabel);
        _widgetsCreated.push_back(newCb);
        _widgetsCreated.push_back(newParamPb);
        _widgetsCreated.push_back(newCompilePb);
        //_widgetsCreated.push_back(spacer);
    }
}
void WidgetIOProperties::createIOProperties()
{
    ui->mainLayout->setColumnMinimumWidth(0, 150);
    ui->optionLayout->setColumnMinimumWidth(0, 150);

    QString lang = Utils::GetLocale();
    QString rsc = QString(":/doc/%1/io_doc.json").arg(lang);

    QFile f(rsc);
    if (!f.open(QIODevice::ReadOnly | QIODevice::Text))
    {
        QMessageBox::warning(this, tr("Error"), tr("Failed to load IO documentation from %1").arg(rsc));
        return;
    }
    QJsonParseError jerr;
    QJsonDocument jdoc = QJsonDocument::fromJson(f.readAll(), &jerr);
    if (jerr.error != QJsonParseError::NoError ||
        !jdoc.isObject())
    {
        QMessageBox::warning(this, tr("Error"), tr("Failed to parse JSON IO documentation from %1").arg(rsc));
        return;
    }

    QString iotype = QString::fromUtf8(params["type"].c_str());
    QJsonObject jobj = jdoc.object();
    for (auto it = jobj.begin();it != jobj.end();it++)
        jobj.insert(it.key().toLower(), it.value());

    QJsonObject jobjAlias;
    if (!jobj.contains(iotype))
    {
        //Search in aliases
        bool aliasfound = false;
        for (auto it = jobj.constBegin();it != jobj.constEnd();it++)
        {
            QJsonObject o = it.value().toObject();
            QJsonArray jalias = o["alias"].toArray();
            for (int i = 0;i < jalias.size();i++)
            {
                if (jalias.at(i).toString() == iotype)
                {
                    aliasfound = true;
                    jobjAlias = o;
                }
            }
        }

        if (!aliasfound)
        {
            QMessageBox::warning(this, tr("Error"), tr("IO type %1 is not found in %2").arg(iotype).arg(rsc));
            return;
        }
    }

    QJsonObject jioobj;
    if (jobjAlias.isEmpty())
        jioobj = jobj[iotype].toObject();
    else
        jioobj = jobjAlias;
    ui->labelTitle->setText(iotype);
    ui->labelDesc->setText(jioobj["description"].toString());

    int rowMain = 0, rowOption = 0;

    QJsonArray jparams = jioobj["parameters"].toArray();
    for (int i = 0;i < jparams.size();i++)
    {
        QJsonObject jparam = jparams[i].toObject();

        QGridLayout *layout = jparam["mandatory"].toString() == "true"?ui->mainLayout:ui->optionLayout;
        int row = jparam["mandatory"].toBool()?rowMain:rowOption;

        QLabel *title = new QLabel(jparam["name"].toString());
        layout->addWidget(title, row, 0);

        QPushButton *revert = new QPushButton();
        revert->setIcon(QIcon(":/img/document-revert.png"));
        revert->setToolTip(tr("Revert modification"));
        layout->addWidget(revert, row, 1);
        hider.hide(revert);

        QString pvalue;
        string prop = jparam["name"].toString().toUtf8().constData();
        if (params.Exists(prop))
            pvalue = QString::fromUtf8(params[prop].c_str());
        else
            pvalue = jparam["default"].toString();

        if (jparam["type"].toString() == "string")
        {
            QLineEdit *w = new QLineEdit();
            w->setEnabled(jparam["readonly"].toString() != "true" && editable);
            w->setText(pvalue);
            layout->addWidget(w, row, 2);

            UiObject uiObject;
            uiObject.type = UiObjectType::LineEdit;
            uiObject.lineEdit = w;
            uiObjectMap[prop] = uiObject;

            connect(w, &QLineEdit::textChanged, [=]()
            {
                updateChangedParam(prop, w->text(), pvalue, title, revert);
            });

            connect(revert, &QPushButton::clicked, [=]()
            {
                w->setText(pvalue);
            });
        }
        else if (jparam["type"].toString() == "bool")
        {
            QCheckBox *w = new QCheckBox();
            w->setEnabled(jparam["readonly"].toString() != "true" && editable);
            w->setChecked(pvalue == "true");
            layout->addWidget(w, row, 2);

            UiObject uiObject;
            uiObject.type = UiObjectType::CheckBox;
            uiObject.checkBox = w;
            uiObjectMap[prop] = uiObject;

            connect(w, &QCheckBox::stateChanged, [=]()
            {
                updateChangedParam(prop, w->isChecked()?"true":"false", pvalue, title, revert);
            });

            connect(revert, &QPushButton::clicked, [=]()
            {
                w->setChecked(pvalue == "true");
            });
        }
        else if (jparam["type"].toString() == "int")
        {
            QSpinBox *w = new QSpinBox();
            w->setEnabled(jparam["readonly"].toString() != "true" && editable);
            if (!jparam["min"].toString().isEmpty())
                w->setMinimum(jparam["min"].toString().toInt());
            else
                w->setMinimum(-999999999);
            if (!jparam["max"].toString().isEmpty())
                w->setMaximum(jparam["max"].toString().toInt());
            else
                w->setMaximum(999999999);
            w->setValue(pvalue.toInt());
            layout->addWidget(w, row, 2);

            UiObject uiObject;
            uiObject.type = UiObjectType::SpinBox;
            uiObject.spinBox = w;
            uiObjectMap[prop] = uiObject;

            connect(w, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), [=]()
            {
                updateChangedParam(prop, QString("%1").arg(w->value()), pvalue.isEmpty()?"0":pvalue, title, revert);
            });

            connect(revert, &QPushButton::clicked, [=]()
            {
                w->setValue(pvalue.toInt());
            });
        }
        else if (jparam["type"].toString() == "float")
        {
            QDoubleSpinBox *w = new QDoubleSpinBox();
            w->setEnabled(jparam["readonly"].toString() != "true" && editable);
            if (!jparam["min"].toString().isEmpty())
                w->setMinimum(jparam["min"].toString().toDouble());
            else
                w->setMinimum(-999999999.0);
            if (!jparam["max"].toString().isEmpty())
                w->setMaximum(jparam["max"].toString().toDouble());
            else
                w->setMaximum(999999999.0);
            w->setValue(pvalue.toDouble());
            layout->addWidget(w, row, 2);
            w->setDecimals(3);

            UiObject uiObject;
            uiObject.type = UiObjectType::DoubleSpinBox;
            uiObject.doubleSpinBox = w;
            uiObjectMap[prop] = uiObject;

            connect(w, static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged), [=]()
            {
                updateChangedParam(prop, QString("%1").arg(w->value()), pvalue.isEmpty()?"0":pvalue, title, revert);
            });

            connect(revert, &QPushButton::clicked, [=]()
            {
                w->setValue(pvalue.toDouble());
            });
        }
        else if (jparam["type"].toString() == "list")
        {
            QComboBox *w = new QComboBox();
            int defIndex = 0;
            w->setEnabled(jparam["readonly"].toString() != "true" && editable);

            //fill combobox with values, if no value, set editable to true
            QJsonObject jvalues = jparam["list_value"].toObject();
            if (jvalues.empty())
                w->setEditable(true);
            else
            {
                w->setEditable(false);
                for (auto it = jvalues.begin();it != jvalues.end();it++)
                {
                    w->addItem(it.value().toString(), it.key());
                    if (it.key() == pvalue)
                    {
                        defIndex = w->count() - 1;
                        w->setCurrentIndex(defIndex);
                    }
                }
            }

            layout->addWidget(w, row, 2);

            UiObject uiObject;
            uiObject.type = UiObjectType::ComboBox;
            uiObject.comboBox = w;
            uiObjectMap[prop] = uiObject;

            if (w->isEditable())
            {
                connect(w, &QComboBox::currentTextChanged, [=]()
                {
                    updateChangedParam(prop, w->currentText(), pvalue, title, revert);
                });
            }
            else
            {
                connect(w, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), [=]()
                {
                    updateChangedParam(prop, w->currentData().toString(), pvalue, title, revert);
                });
            }

            connect(revert, &QPushButton::clicked, [=]()
            {
                if (w->isEditable())
                    w->setEditText(pvalue);
                else
                    w->setCurrentIndex(defIndex);
            });
        }

        QPushButton *help = new QPushButton();
        help->setIcon(QIcon(":/img/icon_unkown.png"));
        help->setFlat(true);
        layout->addWidget(help, row, 3);

        if((i==0)&&(entryHelper != nullptr))
        {
            QPushButton *entryHelperButton = new QPushButton();
            entryHelperButton->setIcon(QIcon(":/img/icon_entry_helper.png"));
            entryHelperButton->setFlat(true);
            layout->addWidget(entryHelperButton, row, 4);
            connect(entryHelperButton, &QPushButton::clicked,  [=]()
            {
                if (entryHelper->exec() == QDialog::Accepted)
                    setValues(entryHelper->getParams());
            });
        }

        //avoid copy the QJsonObject in the lambda
        QString helpInfo = jparam["description"].toString();

        connect(help, &QPushButton::clicked, [=]()
        {
            if (balloonTip)
                delete balloonTip;

            balloonTip = new BalloonTip(QPixmap(":/img/icon_unkown.png"), title->text(), helpInfo, 800, help);
            balloonTip->setArrowPosition(BalloonTip::TopLeft);
            balloonTip->move(QCursor::pos());
            balloonTip->show();
        });

        if (jparam["mandatory"].toBool())
            rowMain++;
        else
            rowOption++;
    }
}
Example #13
0
CreateGameDialog::CreateGameDialog(QWidget *parent) : QDialog(parent)
{
	setWindowTitle(tr("Create game"));
	setWindowIcon(QIcon(":/res/hn_logo.png"));
	setMinimumWidth(300);
	
	QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel,
					  Qt::Horizontal, this);
	
	connect(buttonBox, SIGNAL(accepted()), this, SLOT(actionOk()));
	connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
	
	
	QGroupBox *groupGeneral = new QGroupBox(tr("General"), this);
	
	QLabel *labelName = new QLabel(tr("Game name"), this);
	editName = new QLineEdit(QString::fromStdString(config.get("player_name")) + "'s game", this);
	
	// FIXME:
	QLabel *labelGametype = new QLabel(tr("Game type"), this);
	QComboBox *comboGametype = new QComboBox(this);
	comboGametype->addItem("THNL");
	comboGametype->setEnabled(false);
	
	// FIXME:
	QLabel *labelGamemode = new QLabel(tr("Game mode"), this);
	QComboBox *comboGamemode = new QComboBox(this);
	comboGamemode->addItem("Sit'n'Go");
	comboGamemode->setEnabled(false);
	
	QGridLayout *layoutGeneral = new QGridLayout;
	layoutGeneral->addWidget(labelName, 0, 0);
	layoutGeneral->addWidget(editName, 0, 1);
	layoutGeneral->addWidget(labelGametype, 1, 0);
	layoutGeneral->addWidget(comboGametype, 1, 1);
	layoutGeneral->addWidget(labelGamemode, 2, 0);
	layoutGeneral->addWidget(comboGamemode, 2, 1);
	groupGeneral->setLayout(layoutGeneral);
	
	QGroupBox *groupPlayers = new QGroupBox(tr("Players"), this);
	
	QLabel *labelPlayers = new QLabel(tr("Max. players"), this);
	spinPlayers = new QSpinBox(this);
	spinPlayers->setMinimum(2);
	spinPlayers->setMaximum(10);
	spinPlayers->setSingleStep(1);
	spinPlayers->setValue(5);
	
	QLabel *labelTimeout = new QLabel(tr("Timeout"), this);
	spinTimeout = new QSpinBox(this);
	spinTimeout->setMinimum(5);
	spinTimeout->setMaximum(3*60);
	spinTimeout->setSingleStep(10);
	spinTimeout->setValue(30);
	
	QLabel *labelStake = new QLabel(tr("Initial stake"), this);
	spinStake = new QSpinBox(this);
	spinStake->setMinimum(500);
	spinStake->setMaximum(1000000);
	spinStake->setSingleStep(100);
	spinStake->setValue(1500);
	
	QGridLayout *layoutPlayers = new QGridLayout;
	layoutPlayers->addWidget(labelPlayers, 0, 0);
	layoutPlayers->addWidget(spinPlayers, 0, 1);
	layoutPlayers->addWidget(labelTimeout, 1, 0);
	layoutPlayers->addWidget(spinTimeout, 1, 1);
	layoutPlayers->addWidget(labelStake, 2, 0);
	layoutPlayers->addWidget(spinStake, 2, 1);
	groupPlayers->setLayout(layoutPlayers);
	
	
	QGroupBox *groupBlinds = new QGroupBox(tr("Blinds"), this);
	
	QLabel *labelBlindsStart = new QLabel(tr("Starting blinds"), this);
	spinBlindsStart = new QSpinBox(this);
	spinBlindsStart->setMinimum(5);
	spinBlindsStart->setMaximum(200);
	spinBlindsStart->setSingleStep(10);
	spinBlindsStart->setValue(20);
	
	QLabel *labelBlindsFactor = new QLabel(tr("Raise factor"), this);
	spinBlindsFactor = new QDoubleSpinBox(this);
	spinBlindsFactor->setDecimals(2);
	spinBlindsFactor->setMinimum(1.3);
	spinBlindsFactor->setMaximum(3.5);
	spinBlindsFactor->setSingleStep(0.1);
	spinBlindsFactor->setValue(2.0);
	
	QLabel *labelBlindsTime = new QLabel(tr("Raise time"), this);
	spinBlindsTime = new QSpinBox(this);
	spinBlindsTime->setMinimum(60);
	spinBlindsTime->setMaximum(10*60);
	spinBlindsTime->setSingleStep(60);
	spinBlindsTime->setValue(5*60);
	
	QGridLayout *layoutBlinds = new QGridLayout;
	layoutBlinds->addWidget(labelBlindsStart, 0, 0);
	layoutBlinds->addWidget(spinBlindsStart, 0, 1);
	layoutBlinds->addWidget(labelBlindsFactor, 1, 0);
	layoutBlinds->addWidget(spinBlindsFactor, 1, 1);
	layoutBlinds->addWidget(labelBlindsTime, 2, 0);
	layoutBlinds->addWidget(spinBlindsTime, 2, 1);
	groupBlinds->setLayout(layoutBlinds);
	
	
	QGroupBox *groupPrivate = new QGroupBox(tr("Private game"), this);
	
	QLabel *labelPrivate = new QLabel(tr("Password protected"), this);
	QCheckBox *checkPrivate = new QCheckBox(this);
	connect(checkPrivate, SIGNAL(stateChanged(int)), this, SLOT(slotCheckStatePrivate(int)));
	
	QLabel *labelPassword = new QLabel(tr("Password"), this);
	editPassword = new QLineEdit(this);
	editPassword->setEnabled(false);
	editPassword->setEchoMode(config.getBool("ui_echo_password") ? QLineEdit::Normal : QLineEdit::Password);
	
	
	QGridLayout *layoutPrivate = new QGridLayout;
	layoutPrivate->addWidget(labelPrivate, 0, 0);
	layoutPrivate->addWidget(checkPrivate, 0, 1);
	layoutPrivate->addWidget(labelPassword, 1, 0);
	layoutPrivate->addWidget(editPassword, 1, 1);
	groupPrivate->setLayout(layoutPrivate);
	
	
	QGridLayout *mainLayout = new QGridLayout;
	mainLayout->addWidget(groupGeneral, 0, 0);
	mainLayout->addWidget(groupPlayers, 0, 1);
	mainLayout->addWidget(groupBlinds, 1, 1);
	mainLayout->addWidget(groupPrivate, 1, 0);
	mainLayout->addWidget(buttonBox, 2, 0, 1, 2);
	setLayout(mainLayout);
}