Esempio n. 1
0
void QGraphicsCompleter::complete(const QRect &rect)
{
    if (p_proxyPopup->scene() == 0)
        p_graphicsItem->scene()->addItem(p_proxyPopup);

    QAbstractItemView *popup = static_cast<QAbstractItemView *>(p_proxyPopup->widget());
    if (popup->model()->rowCount() == 0)
    {
        popup->hide();
        p_graphicsItem->setFocus();
        return;
    }

   showPopup(rect);
}
Esempio n. 2
0
bool BAutoCompletionHelper::eventFilter(QObject *object, QEvent *event)
{
    if (event->type() != QEvent::KeyPress)
        return false;
    QKeyEvent *ke = static_cast<QKeyEvent *>(event);
    if (ke->key() != Qt::Key_Enter && ke->key() != Qt::Key_Return)
        return false;
    QAbstractItemView *popup = qobject_cast<QAbstractItemView *>(object);
    if (!popup || !popup->isVisible())
        return false;
    popup->hide();
    completerActivated(popup->currentIndex());
    ke->ignore();
    return true;
}
Esempio n. 3
0
void TagWidget::keyPressEvent(QKeyEvent *e)
{
	switch (e->key()) {
	case Qt::Key_Return:
	case Qt::Key_Enter:
	case Qt::Key_Tab:
		/*
		 * Fake the QLineEdit behaviour by simply
		 * closing the QAbstractViewitem
		 */
		if (m_completer) {
			QAbstractItemView *popup = m_completer->popup();
			if (popup)
				popup->hide();
		}
	}
	if (e->key() == Qt::Key_Tab) { // let's pretend this is a comma instead
		QKeyEvent fakeEvent(e->type(), Qt::Key_Comma, e->modifiers(), QString(","));
		GroupedLineEdit::keyPressEvent(&fakeEvent);
	} else {
		GroupedLineEdit::keyPressEvent(e);
	}
}
Esempio n. 4
0
void TagWidget::reparse()
{
	highlight();
	QPair<int, int> pos = getCursorTagPosition();
	QString currentText;
	if (pos.first >= 0 && pos.second > 0)
		currentText = text().mid(pos.first, pos.second - pos.first).trimmed();
	else
		currentText = "";
	if (m_completer) {
		m_completer->setCompletionPrefix(currentText);
		if (m_completer->completionCount() == 1) {
			if (m_completer->currentCompletion() == currentText) {
				QAbstractItemView *popup = m_completer->popup();
				if (popup)
					popup->hide();
			} else {
				m_completer->complete();
			}
		} else {
			m_completer->complete();
		}
	}
}