1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-01-20 02:23:53 +00:00
openmw/components/contentselector/view/combobox.cpp

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

41 lines
1.1 KiB
C++
Raw Normal View History

#include <QKeyEvent>
#include <QString>
2022-06-16 19:29:55 +00:00
#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);
2020-11-13 07:39:47 +00:00
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;
}