ui: bug fixes in smart search box

* hide completer when elements are updated
* show correct indices in sub query search
* move query elements forward when the cursor is at the end of the box
This commit is contained in:
Eberhard Graether
2014-11-03 16:16:35 +01:00
parent e972dbe098
commit 38d9ec07a5
3 changed files with 51 additions and 14 deletions
+41 -14
View File
@@ -536,6 +536,7 @@ void QtSmartSearchBox::updateElements()
setStyleSheet(TextAccess::createFromFile("data/gui/search_view/search_element.css")->getText().c_str());
updatePlaceholder();
hideAutoCompletions();
layoutElements();
}
@@ -544,36 +545,58 @@ void QtSmartSearchBox::layoutElements()
{
ensurePolished();
int x = 7;
bool hasSelected = hasSelectedElements();
QString cursorText = text();
cursorText.resize(cursorPosition());
int x = 7;
int editX = x;
int cursorX = fontMetrics().width(cursorText) + x + 5;
std::vector<int> elementX;
for (size_t i = 0; i <= m_elements.size(); i++)
{
if (!hasSelected && i == m_cursorIndex)
{
int left, top, right, bottom;
getTextMargins(&left, &top, &right, &bottom);
setTextMargins(x - 9, top, right, bottom);
editX = x - 9;
cursorX += editX;
x += fontMetrics().width(text());
}
if (i < m_elements.size())
{
QtQueryElement* button = m_elements[i].get();
QSize size = button->minimumSizeHint();
int y = (rect().height() - size.height()) / 2.0;
button->setGeometry(x, y, size.width(), size.height());
x += size.width() + 5;
elementX.push_back(x);
x += button->minimumSizeHint().width() + 5;
}
}
int offsetX = 0;
if (cursorX > width())
{
offsetX = width() - cursorX;
}
for (size_t i = 0; i < elementX.size(); i++)
{
QtQueryElement* button = m_elements[i].get();
QSize size = button->minimumSizeHint();
int y = (rect().height() - size.height()) / 2.0;
button->setGeometry(elementX[i] + offsetX, y, size.width(), size.height());
}
if (hasSelected)
{
setTextMargins(width() + 10, 0, 0, 0);
}
else
{
QMargins margins = textMargins();
setTextMargins(editX + offsetX, margins.top(), margins.right(), margins.bottom());
}
}
bool QtSmartSearchBox::hasSelectedElements() const
{
for (const std::shared_ptr<QtQueryElement> element : m_elements)
@@ -672,11 +695,7 @@ void QtSmartSearchBox::updatePlaceholder()
void QtSmartSearchBox::clearLineEdit()
{
setEditText("");
if (completer())
{
completer()->popup()->hide();
}
hideAutoCompletions();
}
void QtSmartSearchBox::requestAutoCompletions() const
@@ -690,3 +709,11 @@ void QtSmartSearchBox::requestAutoCompletions() const
MessageSearchAutocomplete(query, text().toStdString()).dispatch();
}
void QtSmartSearchBox::hideAutoCompletions()
{
if (completer())
{
completer()->popup()->hide();
}
}
+2
View File
@@ -82,7 +82,9 @@ private:
void updatePlaceholder();
void clearLineEdit();
void requestAutoCompletions() const;
void hideAutoCompletions();
bool m_allowTextChange;
QString m_oldText;
+8
View File
@@ -169,10 +169,18 @@ SearchMatch SearchNode::fuzzyMatchData(const std::string& query, const SearchNod
size_t pos = 0;
size_t size = 0;
const SearchNode* root = parent;
std::deque<const SearchNode*> nodes = getNodesToParent(parent);
if (!nodes.size())
{
nodes.push_back(this);
root = root->getParent();
}
while (root && root->getNameId())
{
size += root->getName().size() + SearchIndex::DELIMITER.size();
root = root->getParent();
}
for (const SearchNode* node : nodes)