Exemplo n.º 1
0
void MultiValuesLineEdit::setMultiValue(QSet<QString> value)
{
    if (value.count() == 0)
    {
        mMultiState = MultiValuesEmpty;
        QLineEdit::setText("");
        setPlaceholder(this, "");
        mCompleterModel->setStringList(QStringList());
    }

    else if (value.count() == 1)
    {
        mMultiState = MultiValuesEmpty;
        QLineEdit::setText(*(value.constBegin()));
        setPlaceholder(this, "");
        mCompleterModel->setStringList(value.toList());
    }

    else
    {
        mMultiState = MultiValuesMulti;
        QLineEdit::setText("");
        setPlaceholder(this, tr("Multiple values"));
        mCompleterModel->setStringList(value.toList());
    }
}
Exemplo n.º 2
0
void MultiValuesComboBox::setMultiValue(QSet<QString> value)
{
    QSet<QString> v = value;
    v.remove("");

    if (v.count() == 0)
    {
        mMultiState = MultiValuesEmpty;
        setCurrentIndex(-1);
        setPlaceholder(lineEdit(), "");
    }

    else if (v.count() == 1)
    {
        int n = this->findData(*(v.begin()));
        setCurrentIndex(n);
        if (n >-1)
            mMultiState = MultiValuesSingle;
        else
            mMultiState = MultiValuesEmpty;

        setPlaceholder(lineEdit(), "");
    }

    else
    {
        mMultiState = MultiValuesMulti;
        setCurrentIndex(-1);
        setPlaceholder(lineEdit(), tr("Multiple values"));
    }
}
void
PlaceholderLineEdit::focusOutEvent(QFocusEvent *e)
{
    if (QLineEdit::text() == "")
        setPlaceholder();
    QLineEdit::focusOutEvent(e);
    emit lostFocus();
}
Exemplo n.º 4
0
FlatTextarea::FlatTextarea(QWidget *parent, const style::flatTextarea &st, const QString &pholder, const QString &v) : QTextEdit(parent),
    _minHeight(-1), _maxHeight(-1), _maxLength(-1), _ctrlEnterSubmit(true),
    _oldtext(v), _phVisible(!v.length()),
    a_phLeft(_phVisible ? 0 : st.phShift), a_phAlpha(_phVisible ? 1 : 0), a_phColor(st.phColor->c),
    _st(st), _undoAvailable(false), _redoAvailable(false), _inDrop(false), _inHeightCheck(false), _fakeMargin(0),
    _touchPress(false), _touchRightButton(false), _touchMove(false), _correcting(false) {
    setAcceptRichText(false);
    resize(_st.width, _st.font->height);

    setFont(_st.font->f);
    setAlignment(_st.align);

    setPlaceholder(pholder);

    QPalette p(palette());
    p.setColor(QPalette::Text, _st.textColor->c);
    setPalette(p);

    setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);

    setFrameStyle(QFrame::NoFrame | QFrame::Plain);
    viewport()->setAutoFillBackground(false);

    setContentsMargins(0, 0, 0, 0);

    switch (cScale()) {
    case dbisOneAndQuarter:
        _fakeMargin = 1;
        break;
    case dbisOneAndHalf:
        _fakeMargin = 2;
        break;
    case dbisTwo:
        _fakeMargin = 4;
        break;
    }
    setStyleSheet(qsl("QTextEdit { margin: %1px; }").arg(_fakeMargin));

    viewport()->setAttribute(Qt::WA_AcceptTouchEvents);
    _touchTimer.setSingleShot(true);
    connect(&_touchTimer, SIGNAL(timeout()), this, SLOT(onTouchTimer()));

    connect(document(), SIGNAL(contentsChange(int, int, int)), this, SLOT(onDocumentContentsChange(int, int, int)));
    connect(document(), SIGNAL(contentsChanged()), this, SLOT(onDocumentContentsChanged()));
    connect(this, SIGNAL(undoAvailable(bool)), this, SLOT(onUndoAvailable(bool)));
    connect(this, SIGNAL(redoAvailable(bool)), this, SLOT(onRedoAvailable(bool)));
    if (App::wnd()) connect(this, SIGNAL(selectionChanged()), App::wnd(), SLOT(updateGlobalMenu()));

    if (!v.isEmpty()) {
        setPlainText(v);
    }
}
Exemplo n.º 5
0
void PhoneInput::onChooseCode(const QString &code) {
    pattern = phoneNumberParse(code);
    if (!pattern.isEmpty() && pattern.at(0) == code.size()) {
        pattern.pop_front();
    } else {
        pattern.clear();
    }
    if (pattern.isEmpty()) {
        setPlaceholder(lang(lng_phone_ph));
    } else {
        QString ph;
        ph.reserve(20);
        for (int i = 0, l = pattern.size(); i < l; ++i) {
            ph.append(' ');
            ph.append(QString(QChar(0x2212)).repeated(pattern.at(i)));
        }
        setPlaceholder(ph);
    }
    correctValue(0, text());
    setPlaceholderFast(!pattern.isEmpty());
    updatePlaceholder();
}
Exemplo n.º 6
0
void MultiValuesSpinBox::setMultiValue(QSet<int> value)
{
    if (value.count() == 0)
    {
        mMultiState = MultiValuesEmpty;
        QSpinBox::setValue(minimum());
        setPlaceholder(lineEdit(), "");
    }

    else if (value.count() == 1)
    {
        mMultiState = MultiValuesSingle;
        QSpinBox::setValue(*(value.constBegin()));
        setPlaceholder(lineEdit(), "");
    }

    else
    {
        mMultiState = MultiValuesMulti;
        QSpinBox::setValue(minimum());
        setPlaceholder(lineEdit(), tr("Multiple values"));
    }
}
// Qt 4.7 has placeholder text,
// but we need to handle it for lower versions ourselves
PlaceholderLineEdit::PlaceholderLineEdit(QWidget *parent) :
        QLineEdit(parent)

{
    setPlaceholder();
}