Something went wrong. Try again.
OpenMW is an open implementation of the Morrowind engine
Something went wrong. Try again.
C++
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798#include <QApplication>#include <QString>
#include "profilescombobox.hpp"
ProfilesComboBox::ProfilesComboBox(QWidget* parent) : ContentSelectorView::ComboBox(parent){ connect(this, qOverload<int>(&ProfilesComboBox::activated), this, &ProfilesComboBox::slotIndexChangedByUser);
setInsertPolicy(QComboBox::NoInsert);}
void ProfilesComboBox::setEditEnabled(bool editable){ if (isEditable() == editable) return;
if (!editable) { disconnect(lineEdit(), &QLineEdit::editingFinished, this, &ProfilesComboBox::slotEditingFinished); disconnect(lineEdit(), &QLineEdit::textChanged, this, &ProfilesComboBox::slotTextChanged); return setEditable(false); }
// Reset the completer and validator setEditable(true); setValidator(mValidator);
auto* edit = new ComboBoxLineEdit(this);
setLineEdit(edit); setCompleter(nullptr);
connect(lineEdit(), &QLineEdit::editingFinished, this, &ProfilesComboBox::slotEditingFinished);
connect(lineEdit(), &QLineEdit::textChanged, this, &ProfilesComboBox::slotTextChanged);
connect(lineEdit(), &QLineEdit::textChanged, this, &ProfilesComboBox::signalProfileTextChanged);}
void ProfilesComboBox::slotTextChanged(const QString& text){ QPalette palette; palette.setColor(QPalette::Text, Qt::red);
int index = findText(text);
if (text.isEmpty() || (index != -1 && index != currentIndex())) { lineEdit()->setPalette(palette); } else { lineEdit()->setPalette(QApplication::palette()); }}
void ProfilesComboBox::slotEditingFinished(){ QString current = currentText(); QString previous = itemText(currentIndex());
if (currentIndex() == -1) return;
if (current.isEmpty()) return;
if (current == previous) return;
if (findText(current) != -1) return;
setItemText(currentIndex(), current); emit profileRenamed(previous, current);}
void ProfilesComboBox::slotIndexChangedByUser(int index){ if (index == -1) return;
emit signalProfileChanged(mOldProfile, currentText()); mOldProfile = currentText();}
ProfilesComboBox::ComboBoxLineEdit::ComboBoxLineEdit(QWidget* parent) : LineEdit(parent){ int frameWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth);
setObjectName(QString("ComboBoxLineEdit")); setStyleSheet(QString("ComboBoxLineEdit { background-color: transparent; padding-right: %1px; } ") .arg(mClearButton->sizeHint().width() + frameWidth + 1));}