mirror of https://github.com/OpenMW/openmw.git
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
41 lines
1.1 KiB
C++
41 lines
1.1 KiB
C++
#include <QKeyEvent>
|
|
#include <QString>
|
|
|
|
#include <QStylePainter>
|
|
|
|
#include "combobox.hpp"
|
|
|
|
ContentSelectorView::ComboBox::ComboBox(QWidget* parent)
|
|
: QComboBox(parent)
|
|
{
|
|
mValidator
|
|
= new QRegularExpressionValidator(QRegularExpression("^[a-zA-Z0-9_]*$"), this); // Alpha-numeric + underscore
|
|
setValidator(mValidator);
|
|
setEditable(true);
|
|
setCompleter(nullptr);
|
|
setEnabled(true);
|
|
|
|
setInsertPolicy(QComboBox::NoInsert);
|
|
}
|
|
|
|
void ContentSelectorView::ComboBox::paintEvent(QPaintEvent*)
|
|
{
|
|
QStylePainter painter(this);
|
|
painter.setPen(palette().color(QPalette::Text));
|
|
|
|
// draw the combobox frame, focusrect and selected etc.
|
|
QStyleOptionComboBox opt;
|
|
initStyleOption(&opt);
|
|
painter.drawComplexControl(QStyle::CC_ComboBox, opt);
|
|
|
|
// draw the icon and text
|
|
if (!opt.editable && currentIndex() == -1) // <<< we adjust the text displayed when nothing is selected
|
|
opt.currentText = mPlaceholderText;
|
|
painter.drawControl(QStyle::CE_ComboBoxLabel, opt);
|
|
}
|
|
|
|
void ContentSelectorView::ComboBox::setPlaceholderText(const QString& text)
|
|
{
|
|
mPlaceholderText = text;
|
|
}
|