ui: bug fixes in search bar

* use DEL key to delete next element
* cursor not jumping to end of word anymore when autocompletions are updated
* holding down arrows for moving to start or end of word won't turn word into element

fortune cookie message = You deserve to have a good time after a hard days work.
This commit is contained in:
Eberhard Graether
2015-05-12 14:46:20 +02:00
parent a41c0e1b85
commit f58b6f50ed
+21 -2
View File
@@ -63,9 +63,14 @@ QtSmartSearchBox::~QtSmartSearchBox()
void QtSmartSearchBox::setAutocompletionList(const std::vector<SearchMatch>& autocompletionList)
{
// Save the cursor position, because after activating the completer the cursor gets set to the end position.
int cursor = cursorPosition();
QtAutocompletionList* completer = dynamic_cast<QtAutocompletionList*>(this->completer());
completer->completeAt(QPoint(textMargins().left() + 3, height() + 3), autocompletionList);
setCursorPosition(cursor);
connect(completer, SIGNAL(matchHighlighted(const SearchMatch&)), this, SLOT(onAutocompletionHighlighted(const SearchMatch&)), Qt::DirectConnection);
connect(completer, SIGNAL(matchActivated(const SearchMatch&)), this, SLOT(onAutocompletionActivated(const SearchMatch&)), Qt::DirectConnection);
@@ -153,6 +158,20 @@ void QtSmartSearchBox::keyPressEvent(QKeyEvent* event)
return;
}
}
else if (event->matches(QKeySequence::Delete))
{
if (hasSelectedElements())
{
deleteSelectedElements();
return;
}
else if (!hasSelectedText() && cursorPosition() == text().size() && m_cursorIndex < m_elements.size())
{
m_elements[m_cursorIndex]->setChecked(true);
deleteSelectedElements();
return;
}
}
else if (event->matches(QKeySequence::MoveToPreviousChar))
{
if (hasSelectedElements())
@@ -169,7 +188,7 @@ void QtSmartSearchBox::keyPressEvent(QKeyEvent* event)
selectAllElementsWith(false);
layoutElements();
}
else if (cursorPosition() == 0 && m_cursorIndex > 0)
else if (cursorPosition() == 0 && m_cursorIndex > 0 && !event->isAutoRepeat())
{
editTextToElement();
moveCursor(-1);
@@ -192,7 +211,7 @@ void QtSmartSearchBox::keyPressEvent(QKeyEvent* event)
selectAllElementsWith(false);
layoutElements();
}
else if (cursorPosition() == text().size())
else if (cursorPosition() == text().size() && !event->isAutoRepeat())
{
if (completer()->popup()->isVisible())
{