From c6fa1f0969b687ff618ea51427b855dfd2cdb026 Mon Sep 17 00:00:00 2001 From: Eberhard Graether Date: Tue, 7 Jun 2016 15:10:09 +0200 Subject: [PATCH] ui: Defined colors for fulltext search and fulltext code highlights --- bin/app/data/color_schemes/bad_rainbow.xml | 81 +++++++++------- bin/app/data/color_schemes/bright.xml | 72 ++++++++------- bin/app/data/color_schemes/dark.xml | 92 ++++++++++++------- .../component/controller/SearchController.cpp | 1 + src/lib/data/search/SearchMatch.cpp | 2 + src/lib/data/search/SearchMatch.h | 3 +- src/lib/settings/ColorScheme.cpp | 36 +++++++- src/lib/settings/ColorScheme.h | 8 +- .../qt/element/QtAutocompletionList.cpp | 25 ++++- src/lib_gui/qt/element/QtCodeArea.cpp | 13 ++- src/lib_gui/qt/element/QtSmartSearchBox.cpp | 32 ++++--- 11 files changed, 230 insertions(+), 135 deletions(-) diff --git a/bin/app/data/color_schemes/bad_rainbow.xml b/bin/app/data/color_schemes/bad_rainbow.xml index 7d6f634d..01e3d8c3 100644 --- a/bin/app/data/color_schemes/bad_rainbow.xml +++ b/bin/app/data/color_schemes/bad_rainbow.xml @@ -13,7 +13,7 @@ - #3D3D3D + #FFFFFF #808080 #B1B1B1 @@ -27,17 +27,45 @@ - #B1B1B1 - #CCCCCC + + #B1B1B1 + #3D3D3D + + + #CCCCCC + #3D3D3D + - #86BD40 - #9EC769 + + #86BD40 + #3D3D3D + + + #9EC769 + #3D3D3D + - #7D2724 - #8C2B29 + + #7D2724 + #3D3D3D + + + #8C2B29 + #3D3D3D + + + + #C2AFEF + #3D3D3D + + + #AB96EA + #3D3D3D + + @@ -123,46 +151,23 @@ transparent transparent - - transparent - transparent - - - transparent - transparent - transparent #A0FF0000 + #000000 - transparent #FFFF0000 - - transparent - #FFFF0000 - - + - transparent - #80FFFF00 - #000000 + #C2AFEF + #3D3D3D - - transparent - #FFFFFF00 - #000000 - - - transparent - #FFFFFF00 - #000000 - - + @@ -277,6 +282,12 @@ #20FFFFFF #FFFFFF + + #FFFFFF + + + #FFFFFF + file diff --git a/bin/app/data/color_schemes/bright.xml b/bin/app/data/color_schemes/bright.xml index 08bdd695..0cb12721 100644 --- a/bin/app/data/color_schemes/bright.xml +++ b/bin/app/data/color_schemes/bright.xml @@ -27,17 +27,45 @@ - white - #F5F5F5 + + white + black + + + #F5F5F5 + black + - #8FBC92 - #5EA071 + + #8FBC92 + black + + + #5EA071 + black + - #FCA47E - #F97A4E + + #FCA47E + black + + + #F97A4E + black + + + + #C7C7E2 + black + + + #ABABDD + black + + @@ -121,14 +149,6 @@ transparent transparent - - transparent - transparent - - - transparent - transparent - @@ -137,33 +157,15 @@ #000000 - transparent #FFFF0000 - #000000 - - transparent - #FFFF0000 - #000000 - - + - transparent - #80FFFF00 + #C7C7E2 #000000 - - transparent - #FFFFFF00 - #000000 - - - transparent - #FFFFFF00 - #000000 - - + diff --git a/bin/app/data/color_schemes/dark.xml b/bin/app/data/color_schemes/dark.xml index 8b91f9cb..2502d3c3 100644 --- a/bin/app/data/color_schemes/dark.xml +++ b/bin/app/data/color_schemes/dark.xml @@ -27,17 +27,64 @@ - #2F2F2F - black + + - #406D4D - #4E855E + + - #7D2724 - #8C2B29 + + + + + + + + + + + + #2F2F2F + #F7F7F7 + + + black + #F7F7F7 + + + + + #406D4D + #F7F7F7 + + + #4E855E + #F7F7F7 + + + + + #7D2724 + #F7F7F7 + + + #8C2B29 + #F7F7F7 + + + + + #207EA8 + #F7F7F7 + + + #006D93 + #F7F7F7 + + @@ -123,46 +170,23 @@ transparent transparent - - transparent - transparent - - - transparent - transparent - transparent #A0FF0000 + #000000 - transparent #FFFF0000 - - transparent - #FFFF0000 - - + - transparent - #80FFFF00 - #000000 + #207EA8 + #F7F7F7 - - transparent - #FFFFFF00 - #000000 - - - transparent - #FFFFFF00 - #000000 - - + diff --git a/src/lib/component/controller/SearchController.cpp b/src/lib/component/controller/SearchController.cpp index 9b72e604..d4b22424 100644 --- a/src/lib/component/controller/SearchController.cpp +++ b/src/lib/component/controller/SearchController.cpp @@ -65,6 +65,7 @@ void SearchController::handleMessage(MessageSearchFullText* message) prefix += "@"; } SearchMatch match(prefix + message->searchTerm); + match.searchType = SearchMatch::SEARCH_FULLTEXT; getView()->setMatches(std::vector(1, match)); } diff --git a/src/lib/data/search/SearchMatch.cpp b/src/lib/data/search/SearchMatch.cpp index a644f9b1..ea379afa 100644 --- a/src/lib/data/search/SearchMatch.cpp +++ b/src/lib/data/search/SearchMatch.cpp @@ -29,6 +29,8 @@ std::string SearchMatch::getSearchTypeName(SearchType type) return "command"; case SEARCH_OPERATOR: return "operator"; + case SEARCH_FULLTEXT: + return "fulltext"; } } diff --git a/src/lib/data/search/SearchMatch.h b/src/lib/data/search/SearchMatch.h index ca044f37..dee361ae 100644 --- a/src/lib/data/search/SearchMatch.h +++ b/src/lib/data/search/SearchMatch.h @@ -16,7 +16,8 @@ struct SearchMatch SEARCH_NONE, SEARCH_TOKEN, SEARCH_COMMAND, - SEARCH_OPERATOR + SEARCH_OPERATOR, + SEARCH_FULLTEXT }; enum CommandType diff --git a/src/lib/settings/ColorScheme.cpp b/src/lib/settings/ColorScheme.cpp index fb867756..39b86cf7 100644 --- a/src/lib/settings/ColorScheme.cpp +++ b/src/lib/settings/ColorScheme.cpp @@ -21,6 +21,11 @@ std::string ColorScheme::getColor(const std::string& key) const return getValue(key, ""); } +std::string ColorScheme::getColor(const std::string& key, const std::string& defaultColor) const +{ + return getValue(key, defaultColor); +} + std::string ColorScheme::getNodeTypeColor(Node::NodeType type, const std::string& key, ColorState state) const { return getNodeTypeColor(Node::getTypeString(type), key, state); @@ -85,9 +90,10 @@ std::string ColorScheme::getEdgeTypeColor(const std::string& typeStr, ColorState return color; } -std::string ColorScheme::getSearchTypeColor(const std::string& searchTypeName, const std::string& state) const +std::string ColorScheme::getSearchTypeColor( + const std::string& searchTypeName, const std::string& key, const std::string& state) const { - std::string path = "search/query/" + searchTypeName + "/" + state; + std::string path = "search/query/" + searchTypeName + "/" + state + "/" + key; return getValue(path, "#FFFFFF"); } @@ -96,6 +102,31 @@ std::string ColorScheme::getSyntaxColor(const std::string& key) const return getValue("code/snippet/syntax/" + key, "#FFFFFF"); } +std::string ColorScheme::getCodeSelectionTypeColor(const std::string& typeStr, const std::string& key, ColorState state) const +{ + disableWarnings(); + std::string color = getValue("code/snippet/selection/" + typeStr + "/" + stateToString(state) + "/" + key, ""); + + if (!color.size() && state == ACTIVE) + { + color = getValue("code/snippet/selection/" + typeStr + "/" + stateToString(FOCUS) + "/" + key, ""); + } + + if (!color.size() && state != NORMAL) + { + color = getValue("code/snippet/selection/" + typeStr + "/" + stateToString(NORMAL) + "/" + key, ""); + } + + if (!color.size()) + { + color = "transparent"; + } + + enableWarnings(); + + return color; +} + ColorScheme::ColorScheme() { } @@ -106,6 +137,7 @@ std::string ColorScheme::stateToString(ColorState state) { case NORMAL: return "normal"; case FOCUS: return "focus"; + case ACTIVE: return "active"; } return ""; diff --git a/src/lib/settings/ColorScheme.h b/src/lib/settings/ColorScheme.h index 263b76c4..55298b49 100644 --- a/src/lib/settings/ColorScheme.h +++ b/src/lib/settings/ColorScheme.h @@ -12,13 +12,15 @@ public: enum ColorState { NORMAL, - FOCUS + FOCUS, + ACTIVE }; static std::shared_ptr getInstance(); virtual ~ColorScheme(); std::string getColor(const std::string& key) const; + std::string getColor(const std::string& key, const std::string& defaultColor) const; std::string getNodeTypeColor(Node::NodeType type, const std::string& key, ColorState state) const; std::string getNodeTypeColor(const std::string& typeStr, const std::string& key, ColorState state) const; @@ -26,9 +28,11 @@ public: std::string getEdgeTypeColor(Edge::EdgeType type, ColorState state) const; std::string getEdgeTypeColor(const std::string& typeStr, ColorState state) const; - std::string getSearchTypeColor(const std::string& searchTypeName, const std::string& state = "normal") const; + std::string getSearchTypeColor(const std::string& searchTypeName, const std::string& key, const std::string& state = "normal") const; std::string getSyntaxColor(const std::string& key) const; + std::string getCodeSelectionTypeColor(const std::string& typeStr, const std::string& key, ColorState state) const; + protected: ColorScheme(); ColorScheme(const ColorScheme&) = delete; diff --git a/src/lib_gui/qt/element/QtAutocompletionList.cpp b/src/lib_gui/qt/element/QtAutocompletionList.cpp index b85f024b..497a38d6 100644 --- a/src/lib_gui/qt/element/QtAutocompletionList.cpp +++ b/src/lib_gui/qt/element/QtAutocompletionList.cpp @@ -103,28 +103,40 @@ void QtAutocompletionDelegate::paint(QPainter* painter, const QStyleOptionViewIt QString type = index.sibling(index.row(), index.column() + 1).data().toString(); QColor color("#FFFFFF"); + QColor textColor("#000000"); Node::NodeType nodeType = static_cast(index.sibling(index.row(), index.column() + 3).data().toInt()); if (type.size() && type != "command") { - color = QColor(GraphViewStyle::getNodeColor(Node::getTypeString(nodeType), false).fill.c_str()); + const GraphViewStyle::NodeColor& nodeColor = GraphViewStyle::getNodeColor(Node::getTypeString(nodeType), false); + color = QColor(nodeColor.fill.c_str()); + textColor = QColor(nodeColor.text.c_str()); } else { - color = QColor(scheme->getSearchTypeColor(SearchMatch::getSearchTypeName(SearchMatch::SEARCH_COMMAND)).c_str()); + color = QColor(scheme->getSearchTypeColor(SearchMatch::getSearchTypeName(SearchMatch::SEARCH_COMMAND), "fill").c_str()); + textColor = QColor(scheme->getSearchTypeColor(SearchMatch::getSearchTypeName(SearchMatch::SEARCH_COMMAND), "text").c_str()); } float charWidth = option.fontMetrics.width( "----------------------------------------------------------------------------------------------------" ) / 100.0f; + painter->drawText(option.rect.adjusted(charWidth + 2, -1, 0, 0), Qt::AlignLeft, name); + + QString highlightName(name.size(), ' '); + QList indices = index.sibling(index.row(), index.column() + 2).data().toList(); if (indices.size()) { for (int i = 0; i < indices.size(); i++) { - QRect rect = option.rect.adjusted(charWidth * (indices[i].toInt() + 1) + 1, 2, 0, -1); + int idx = indices[i].toInt(); + + QRect rect = option.rect.adjusted(charWidth * (idx + 1) + 1, 2, 0, -1); rect.setWidth(charWidth + 2); painter->fillRect(rect, color); + + highlightName[idx] = name.at(idx); } } else @@ -134,7 +146,12 @@ void QtAutocompletionDelegate::paint(QPainter* painter, const QStyleOptionViewIt painter->fillRect(rect, color); } - painter->drawText(option.rect.adjusted(charWidth + 2, -1, 0, 0), Qt::AlignLeft, name); + painter->save(); + QPen highlightPen = painter->pen(); + highlightPen.setColor(textColor); + painter->setPen(highlightPen); + painter->drawText(option.rect.adjusted(charWidth + 2, -1, 0, 0), Qt::AlignLeft, highlightName); + painter->restore(); if (type.size()) { diff --git a/src/lib_gui/qt/element/QtCodeArea.cpp b/src/lib_gui/qt/element/QtCodeArea.cpp index 754a3e63..95d9bf01 100644 --- a/src/lib_gui/qt/element/QtCodeArea.cpp +++ b/src/lib_gui/qt/element/QtCodeArea.cpp @@ -907,18 +907,17 @@ const QtCodeArea::AnnotationColor& QtCodeArea::getAnnotationColorForAnnotation(c if (!s_annotationColors.size()) { ColorScheme* scheme = ColorScheme::getInstance().get(); - std::vector types = { "token", "local_symbol", "scope", "error", "fulltextmatch"}; - - std::vector states = { "normal", "focus", "active"}; + std::vector types = { "token", "local_symbol", "scope", "error", "fulltext" }; + std::vector states = { ColorScheme::NORMAL, ColorScheme::FOCUS, ColorScheme::ACTIVE }; for (const std::string& type : types) { - for (const std::string& state : states) + for (const ColorScheme::ColorState& state : states) { AnnotationColor color; - color.border = scheme->getColor("code/snippet/selection/" + type + "/" + state + "/border"); - color.fill = scheme->getColor("code/snippet/selection/" + type + "/" + state + "/fill"); - color.text = scheme->getColor("code/snippet/selection/" + type + "/" + state + "/text"); + color.border = scheme->getCodeSelectionTypeColor(type, "border", state); + color.fill = scheme->getCodeSelectionTypeColor(type, "fill", state); + color.text = scheme->getCodeSelectionTypeColor(type, "text", state); s_annotationColors.push_back(color); } } diff --git a/src/lib_gui/qt/element/QtSmartSearchBox.cpp b/src/lib_gui/qt/element/QtSmartSearchBox.cpp index 5ee27a52..0dc4bd3a 100644 --- a/src/lib_gui/qt/element/QtSmartSearchBox.cpp +++ b/src/lib_gui/qt/element/QtSmartSearchBox.cpp @@ -31,10 +31,21 @@ void QtSearchElement::onChecked(bool) emit wasChecked(this); } +void QtSmartSearchBox::search() +{ + editTextToElement(); + + std::vector matches = utility::toVector(m_matches); + + LOG_INFO_STREAM(<< "Search query: " << SearchMatch::searchMatchesToString(matches) << text().toStdString()); + + MessageSearch(matches).dispatch(); +} + void QtSmartSearchBox::fullTextSearch() { std::string term = text().toStdString().substr(1); - if(term.at(0) == '@') + if (term.at(0) == '@') { term = term.substr(1); LOG_INFO_STREAM(<< "FullTextsearch(case sensitive): " << term); @@ -47,17 +58,6 @@ void QtSmartSearchBox::fullTextSearch() } } -void QtSmartSearchBox::search() -{ - editTextToElement(); - - std::vector matches = utility::toVector(m_matches); - - LOG_INFO_STREAM(<< "Search query: " << SearchMatch::searchMatchesToString(matches) << text().toStdString()); - - MessageSearch(matches).dispatch(); -} - QtSmartSearchBox::QtSmartSearchBox(QWidget* parent) : QLineEdit(parent) , m_allowMultipleElements(false) @@ -165,7 +165,7 @@ void QtSmartSearchBox::keyPressEvent(QKeyEvent* event) fullTextSearch(); return; } - if (!completer()->popup()->isVisible()) + else if (!completer()->popup()->isVisible()) { search(); } @@ -653,8 +653,10 @@ void QtSmartSearchBox::updateElements() std::string typeName = match.getSearchTypeName(); element->setObjectName(QString::fromStdString("search_element_" + typeName)); - color = scheme->getSearchTypeColor(typeName); - hoverColor = scheme->getSearchTypeColor(typeName, "hover"); + color = scheme->getSearchTypeColor(typeName, "fill"); + hoverColor = scheme->getSearchTypeColor(typeName, "fill", "hover"); + textColor = scheme->getSearchTypeColor(typeName, "text"); + textHoverColor = scheme->getSearchTypeColor(typeName, "text", "hover");; } std::stringstream css;