ui: Fixed search related issues

* select elements when clicking into search bar
* fixed crash and single file mode clearing when fulltext search yields no results
This commit is contained in:
Eberhard Graether
2017-07-20 15:55:31 +02:00
parent 3c72ce7459
commit faae66b304
8 changed files with 65 additions and 14 deletions
+39 -13
View File
@@ -88,6 +88,7 @@ QtSmartSearchBox::QtSmartSearchBox(QWidget* parent)
, m_cursorIndex(0)
, m_shiftKeyDown(false)
, m_mousePressed(false)
, m_ignoreNextMousePress(false)
{
m_highlightRect = new QWidget(this);
m_highlightRect->setGeometry(0, 0, 0, 0);
@@ -150,17 +151,6 @@ void QtSmartSearchBox::setMatches(const std::vector<SearchMatch>& matches)
void QtSmartSearchBox::setFocus()
{
QLineEdit::setFocus(Qt::ShortcutFocusReason);
if (text().size() == 1 && text().startsWith(SearchMatch::FULLTEXT_SEARCH_CHARACTER))
{
setEditText("");
}
else
{
editTextToElement();
selectAllElementsWith(true);
layoutElements();
}
}
void QtSmartSearchBox::findFulltext()
@@ -214,6 +204,32 @@ void QtSmartSearchBox::resizeEvent(QResizeEvent* event)
layoutElements();
}
void QtSmartSearchBox::focusInEvent(QFocusEvent* event)
{
QLineEdit::focusInEvent(event);
if (event->reason() != Qt::MouseFocusReason && event->reason() != Qt::ShortcutFocusReason)
{
return;
}
if (text().size() == 1 && text().startsWith(SearchMatch::FULLTEXT_SEARCH_CHARACTER))
{
setEditText("");
}
else
{
editTextToElement();
selectAllElementsWith(true);
layoutElements();
}
if (event->reason() == Qt::MouseFocusReason)
{
m_ignoreNextMousePress = true;
}
}
void QtSmartSearchBox::keyPressEvent(QKeyEvent* event)
{
m_shiftKeyDown = event->modifiers() & Qt::ShiftModifier;
@@ -436,14 +452,24 @@ void QtSmartSearchBox::mousePressEvent(QMouseEvent* event)
{
QLineEdit::mousePressEvent(event);
m_mousePressed = true;
m_mouseX = event->x();
if (!m_ignoreNextMousePress)
{
m_mousePressed = true;
m_mouseX = event->x();
}
m_ignoreNextMousePress = false;
}
void QtSmartSearchBox::mouseReleaseEvent(QMouseEvent* event)
{
QLineEdit::mouseReleaseEvent(event);
if (!m_mousePressed)
{
return;
}
m_mousePressed = false;
if (abs(event->x() - m_mouseX) > 5)