コード例 #1
0
void MRuleDialog::initDialog()
{
	ui->setupUi(this);

	//Resizing and sorting of widgets
	ui->variableBox->setInsertPolicy(QComboBox::InsertAlphabetically);
	ui->propList->header()->setResizeMode(0, QHeaderView::ResizeToContents);

	//Make sure the button is enabled only when rules have been added
	ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);

	//Hide description labels for now
	ui->actionDescLabel->hide();
	ui->valueDescLabel->hide();

	//Add the actions list and fill the variables list according to the selected action
	QList<ProgramAction> actList=_prog.actions();
	for(int i=0; i<actList.size(); i++)
		ui->actionBox->addItem(actList[i].displayName(), actList[i].name());
	connect(ui->actionBox, SIGNAL(currentIndexChanged(int)), this, SLOT(onActionChanged(int)));
	ui->actionBox->insertItem(0, UndefinedAction);
	ui->actionBox->setCurrentIndex(0);

	//Setup the variables combobox and use the variable changed handler to initialise the editor widget
	connect(ui->variableBox, SIGNAL(currentIndexChanged(QString)), this, SLOT(onVariableChanged(QString)));
	onVariableChanged(QString());

	//Various signals for dialog buttons, mandatory fields, tree widget related buttons
	connect(ui->propAddButton, SIGNAL(clicked()), this, SLOT(onCondAddButtonClicked()));
	connect(ui->propRemoveButton, SIGNAL(clicked()), this, SLOT(onCondRemoveButtonClicked()));
	connect(ui->variableBox, SIGNAL(currentIndexChanged(int)), this, SLOT(onMandatoryFieldsChanged()));
	connect(ui->valueLineEdit, SIGNAL(textChanged(QString)), this, SLOT(onMandatoryFieldsChanged()));
	connect(ui->valueComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(onMandatoryFieldsChanged()));
	connect(ui->valueCheckBox, SIGNAL(clicked()), this, SLOT(onMandatoryFieldsChanged()));
	connect(ui->valueSpinBox, SIGNAL(valueChanged(int)), this, SLOT(onMandatoryFieldsChanged()));
	connect(ui->propList, SIGNAL(itemSelectionChanged()), this, SLOT(onCondListSelectionChanged()));
	onMandatoryFieldsChanged();
	onCondListSelectionChanged();
}
コード例 #2
0
ファイル: chatappearance.cpp プロジェクト: akahan/qutim
void ChatAppearance::makeSettings() {
	m_current_variables.clear();
	if (settingsWidget)
		delete settingsWidget;
	settingsWidget = new QWidget(this);
	QFormLayout *layout = new QFormLayout(settingsWidget);
	layout->setLabelAlignment(Qt::AlignLeft|Qt::AlignVCenter);
	QSizePolicy sizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding);
	settingsWidget->setLayout(layout);
	QString category = "webkitstyle";
	StyleVariants variants = ChatStyleGenerator::listVariants(ThemeManager::path(category, m_current_style_name)
															  .append("/Contents/Resources/Variants"));
	if (!variants.isEmpty()) {
		QLabel *label = new QLabel(tr("Style variant:"), settingsWidget);
		label->setSizePolicy(sizePolicy);
		QComboBox *variantBox = new QComboBox(settingsWidget);
		layout->addRow(label, variantBox);
		StyleVariants::const_iterator it;
		for (it=variants.begin(); it!=variants.end(); it++)
			variantBox->addItem(it.key());
		connect(variantBox, SIGNAL(currentIndexChanged(QString)), SLOT(onVariantChanged(QString)));
		int index = isLoad ? variantBox->findText(m_current_variant) : 0;
		m_current_variant = variantBox->itemText(index);
		variantBox->setCurrentIndex(index);
		onVariantChanged(m_current_variant);
	}
	Config achat(QStringList()
				 << "appearance/adiumChat"
				 << ThemeManager::path(category,m_current_style_name)
				 .append("/Contents/Resources/custom.json"));
	ConfigGroup variables = achat;
	int count = variables.beginArray(m_current_style_name);
	for (int num = 0; num < count; num++) {
		ConfigGroup parameter = variables.arrayElement(num);
		QString type = parameter.value("type", QString());
		QString text = parameter.value("label", QString());
		text = parameter.value(QString("label-").append(QLocale().name()), text);
		CustomChatStyle style;
		style.parameter = parameter.value("parameter", QString());
		style.selector = parameter.value("selector", QString());
		style.value = parameter.value("value", QString());
		if (type == "font") {
			QLabel *label = new QLabel(text % ":", settingsWidget);
			label->setSizePolicy(sizePolicy);
			ChatFont *fontField = new ChatFont(style, settingsWidget);
			layout->addRow(label, fontField);
			connect(fontField, SIGNAL(changeValue()), SLOT(onVariableChanged()));
			if (ChatVariable *widget = qobject_cast<ChatVariable*>(fontField))
				m_current_variables.append(widget);
		} else if (type == "color") {
			QLabel *label = new QLabel(text % ":", settingsWidget);
			label->setSizePolicy(sizePolicy);
			ChatColor *colorField = new ChatColor(style, settingsWidget);
			layout->addRow(label, colorField);
			connect(colorField, SIGNAL(changeValue()), SLOT(onVariableChanged()));
			if (ChatVariable *widget = qobject_cast<ChatVariable*>(colorField))
				m_current_variables.append(widget);
		} else if (type == "numeric") {
			QLabel *label = new QLabel(text % ":", settingsWidget);
			label->setSizePolicy(sizePolicy);
			double min = parameter.value<double>("min", 0);
			double max = parameter.value<double>("max", 0);
			double step = parameter.value<double>("step", 1);
			ChatNumeric *numField = new ChatNumeric(style, min, max, step, settingsWidget);
			layout->addRow(label, numField);
			connect(numField, SIGNAL(changeValue()), SLOT(onVariableChanged()));
			if (ChatVariable *widget = qobject_cast<ChatVariable*>(numField))
				m_current_variables.append(widget);
		} else if (type == "boolean") {
			QString trueValue = parameter.value("true", QString());
			QString falseValue = parameter.value("false", QString());
			ChatBoolean *boolField = new ChatBoolean(style, trueValue, falseValue, settingsWidget);
			boolField->setText(text);
			layout->addRow(boolField);
			connect(boolField, SIGNAL(changeValue()), SLOT(onVariableChanged()));
			if (ChatVariable *widget = qobject_cast<ChatVariable*>(boolField))
				m_current_variables.append(widget);
		}
	}
	onVariableChanged();
	QSpacerItem *space = new QSpacerItem(20, 40, QSizePolicy::Minimum, QSizePolicy::MinimumExpanding);
	layout->addItem(space);
	ui->scrollAreaLayout->addWidget(settingsWidget);
}