1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-01-23 14:23:53 +00:00
openmw/apps/launcher/utils/profilescombobox.cpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

94 lines
2.5 KiB
C++
Raw Normal View History

#include <QString>
#include <QApplication>
#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);
2020-11-13 07:39:47 +00:00
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)
{
2014-12-23 19:44:25 +00:00
QPalette palette;
palette.setColor(QPalette::Text,Qt::red);
int index = findText(text);
if (text.isEmpty() || (index != -1 && index != currentIndex())) {
2014-12-23 19:44:25 +00:00
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);
2013-08-18 22:11:23 +00:00
setObjectName(QString("ComboBoxLineEdit"));
setStyleSheet(QString("ComboBoxLineEdit { background-color: transparent; padding-right: %1px; } ").arg(mClearButton->sizeHint().width() + frameWidth + 1));
2013-08-18 22:11:23 +00:00
}