26 #include <QAbstractItemView>
27 #include <QApplication>
28 #include <QFocusEvent>
40 elementName(elementName),
41 propertyName(propertyName)
43 layout =
new QHBoxLayout;
45 layout->setSpacing(0);
48 QSettings settings(QString(file.c_str()), QSettings::NativeFormat);
49 valueList = settings.value(elementName +
"/" + propertyName).toStringList();
55 combo->setEditable(
true);
56 combo->setAutoCompletion(
true);
57 combo->setAutoCompletionCaseSensitivity(Qt::CaseInsensitive);
58 combo->addItems(valueList);
60 readOnlyLineEdit =
new QLineEdit();
61 readOnlyLineEdit->setReadOnly(
true);
62 readOnlyLineEdit->setVisible(
false);
64 checkbox =
new QCheckBox(
nullptr);
65 checkbox->setToolTip(
"If checked, this property will be written into the config file");
66 checkbox->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred));
68 setFocusPolicy(Qt::StrongFocus);
69 setAttribute(Qt::WA_InputMethodEnabled);
76 connect(checkbox, SIGNAL(stateChanged(
int)),
this, SLOT(slotEnabledChanged(
int)));
79 layout->addWidget(checkbox);
80 layout->addWidget(combo);
81 layout->addWidget(readOnlyLineEdit);
83 this->setLayout(layout);
90 fixComboboxValues =
true;
102 auto changed =
enabled != checkbox->isChecked();
112 checkbox->setDisabled(readOnly);
114 combo->setVisible(not readOnly);
115 readOnlyLineEdit->setVisible(readOnly);
121 auto changed =
value != combo->currentText();
122 bool enabledState = checkbox->isChecked();
124 combo->setCurrentText(
value);
125 readOnlyLineEdit->setText(
value);
127 if (checkbox->isChecked() != enabledState)
139 valueList.push_front(combo->currentText());
140 valueList.removeDuplicates();
141 if (!fixComboboxValues)
145 combo->addItems(valueList);
150 QSettings settings(QString(file.c_str()), QSettings::NativeFormat);
151 settings.setValue(elementName +
"/" + propertyName, QVariant(valueList));
155 void OptionalEdit::slotEnabledChanged(
int value)
162 QWidget::focusInEvent(e);
167 QWidget::focusOutEvent(e);
185 if (event->reason() != Qt::FocusReason::PopupFocusReason)
193 QComboBox::focusOutEvent(event);