From 9088de81056b9456deb97840ce05786a504f7740 Mon Sep 17 00:00:00 2001 From: Eberhard Graether Date: Fri, 19 May 2017 14:08:56 +0200 Subject: [PATCH] ui: History list polishing * Fixed fulltext searches not included * Show smaller colored indicator in front of list items * Font weight bold on history list item hover --- src/lib/data/search/SearchMatch.cpp | 1 + src/lib_gui/qt/element/QtHistoryList.cpp | 75 +++++++++++++++--------- src/lib_gui/qt/element/QtHistoryList.h | 9 +++ 3 files changed, 58 insertions(+), 27 deletions(-) diff --git a/src/lib/data/search/SearchMatch.cpp b/src/lib/data/search/SearchMatch.cpp index 4f2cdeee..7c0f2004 100644 --- a/src/lib/data/search/SearchMatch.cpp +++ b/src/lib/data/search/SearchMatch.cpp @@ -98,6 +98,7 @@ SearchMatch::SearchMatch() SearchMatch::SearchMatch(const std::string& query) : name(query) + , text(query) , typeName("") , searchType(SEARCH_NONE) , hasChildren(false) diff --git a/src/lib_gui/qt/element/QtHistoryList.cpp b/src/lib_gui/qt/element/QtHistoryList.cpp index 85f6876a..1a2aaae3 100644 --- a/src/lib_gui/qt/element/QtHistoryList.cpp +++ b/src/lib_gui/qt/element/QtHistoryList.cpp @@ -34,45 +34,30 @@ QtHistoryItem::QtHistoryItem(const SearchMatch& match, size_t index, bool isCurr setLayout(layout); + QSize size = getSizeHint(); + + m_indicator = new QWidget(m_name); + m_indicator->setGeometry(5, 2, 12, size.height() - 4); + m_indicator->show(); + ColorScheme* scheme = ColorScheme::getInstance().get(); - std::string searchTextColor = scheme->getColor("search/popup/text"); - - std::string color; - std::string hoverColor; - std::string textColor = searchTextColor; - std::string textHoverColor = searchTextColor; - if (match.searchType == SearchMatch::SEARCH_TOKEN) { - color = GraphViewStyle::getNodeColor(Node::getUnderscoredTypeString(match.nodeType), false).fill; - hoverColor = GraphViewStyle::getNodeColor(Node::getUnderscoredTypeString(match.nodeType), true).fill; - textColor = GraphViewStyle::getNodeColor(Node::getUnderscoredTypeString(match.nodeType), false).text; - textHoverColor = GraphViewStyle::getNodeColor(Node::getUnderscoredTypeString(match.nodeType), true).text; + m_indicatorColor = GraphViewStyle::getNodeColor(Node::getUnderscoredTypeString(match.nodeType), false).fill; + m_indicatorHoverColor = GraphViewStyle::getNodeColor(Node::getUnderscoredTypeString(match.nodeType), true).fill; } else { - std::string typeName = match.getSearchTypeName(); - - color = scheme->getSearchTypeColor(typeName, "fill"); - hoverColor = scheme->getSearchTypeColor(typeName, "fill", "hover"); - textColor = scheme->getSearchTypeColor(typeName, "text"); - textHoverColor = scheme->getSearchTypeColor(typeName, "text", "hover");; + m_indicatorColor = scheme->getSearchTypeColor(match.getSearchTypeName(), "fill"); + m_indicatorHoverColor = scheme->getSearchTypeColor(match.getSearchTypeName(), "fill", "hover"); } std::stringstream css; - css << "QLabel { background-color:" << color << "; color:" << textColor << ";} "; - - if (!isCurrent) - { - css << "QLabel:hover { background-color:" << hoverColor << "; color:" << textHoverColor << ";} "; - } - - m_name->setStyleSheet(css.str().c_str()); + css << "QWidget { background-color:" << m_indicatorColor << ";}"; + m_indicator->setStyleSheet(css.str().c_str()); if (isCurrent) { - QSize size = getSizeHint(); - QtDeviceScaledPixmap pixmap(QString::fromStdString(ResourcePaths::getGuiPath().str() + "history_list/images/arrow.png")); pixmap.scaleToHeight(size.height() / 3); @@ -88,6 +73,42 @@ QSize QtHistoryItem::getSizeHint() const return QSize(m_name->fontMetrics().width(m_name->text()) + 40, m_name->fontMetrics().height() + 8); } +void QtHistoryItem::enterEvent(QEvent *event) +{ + QWidget::enterEvent(event); + + std::stringstream css; + css << "QWidget { background-color:" << m_indicatorHoverColor << ";}"; + m_indicator->setStyleSheet(css.str().c_str()); + + if (m_name->objectName() != "history_item") + { + return; + } + + QFont f(m_name->font()); + f.setBold(true); + m_name->setFont(f); +} + +void QtHistoryItem::leaveEvent(QEvent *event) +{ + QWidget::leaveEvent(event); + + std::stringstream css; + css << "QWidget { background-color:" << m_indicatorColor << ";}"; + m_indicator->setStyleSheet(css.str().c_str()); + + if (m_name->objectName() != "history_item") + { + return; + } + + QFont f(m_name->font()); + f.setBold(false); + m_name->setFont(f); +} + QtHistoryList::QtHistoryList(const std::vector& history, size_t currentIndex) : m_currentIndex(currentIndex) diff --git a/src/lib_gui/qt/element/QtHistoryList.h b/src/lib_gui/qt/element/QtHistoryList.h index abdb7fbe..270d6555 100644 --- a/src/lib_gui/qt/element/QtHistoryList.h +++ b/src/lib_gui/qt/element/QtHistoryList.h @@ -18,8 +18,17 @@ public: size_t index; +protected: + // because changing font-weight within the stylesheet does not work for some reason + void enterEvent(QEvent *event); + void leaveEvent(QEvent *event); + private: QLabel* m_name; + + QWidget* m_indicator; + std::string m_indicatorColor; + std::string m_indicatorHoverColor; };