ui: Defined colors for fulltext search and fulltext code highlights

This commit is contained in:
Eberhard Graether
2016-06-07 15:10:09 +02:00
parent b10c55e7f9
commit c6fa1f0969
11 changed files with 230 additions and 135 deletions
+46 -35
View File
@@ -13,7 +13,7 @@
</button>
<field>
<text>#3D3D3D</text>
<text>#FFFFFF</text>
<background>#808080</background>
<highlight>#B1B1B1</highlight>
</field>
@@ -27,17 +27,45 @@
<query>
<none>
<normal>#B1B1B1</normal>
<hover>#CCCCCC</hover>
<normal>
<fill>#B1B1B1</fill>
<text>#3D3D3D</text>
</normal>
<hover>
<fill>#CCCCCC</fill>
<text>#3D3D3D</text>
</hover>
</none>
<command>
<normal>#86BD40</normal>
<hover>#9EC769</hover>
<normal>
<fill>#86BD40</fill>
<text>#3D3D3D</text>
</normal>
<hover>
<fill>#9EC769</fill>
<text>#3D3D3D</text>
</hover>
</command>
<operator>
<normal>#7D2724</normal>
<hover>#8C2B29</hover>
<normal>
<fill>#7D2724</fill>
<text>#3D3D3D</text>
</normal>
<hover>
<fill>#8C2B29</fill>
<text>#3D3D3D</text>
</hover>
</operator>
<fulltext>
<normal>
<fill>#C2AFEF</fill>
<text>#3D3D3D</text>
</normal>
<hover>
<fill>#AB96EA</fill>
<text>#3D3D3D</text>
</hover>
</fulltext>
</query>
</search>
@@ -123,46 +151,23 @@
<border>transparent</border>
<fill>transparent</fill>
</normal>
<focus>
<border>transparent</border>
<fill>transparent</fill>
</focus>
<active>
<border>transparent</border>
<fill>transparent</fill>
</active>
</scope>
<error>
<normal>
<border>transparent</border>
<fill>#A0FF0000</fill>
<text>#000000</text>
</normal>
<focus>
<border>transparent</border>
<fill>#FFFF0000</fill>
</focus>
<active>
<border>transparent</border>
<fill>#FFFF0000</fill>
</active>
</error>
<fulltextmatch>
<fulltext>
<normal>
<border>transparent</border>
<fill>#80FFFF00</fill>
<text>#000000</text>
<fill>#C2AFEF</fill>
<text>#3D3D3D</text>
</normal>
<focus>
<border>transparent</border>
<fill>#FFFFFF00</fill>
<text>#000000</text>
</focus>
<active>
<border>transparent</border>
<fill>#FFFFFF00</fill>
<text>#000000</text>
</active>
</fulltextmatch>
</fulltext>
</selection>
</snippet>
</code>
@@ -277,6 +282,12 @@
<normal>#20FFFFFF</normal>
<focus>#FFFFFF</focus>
</border>
<text>
<normal>#FFFFFF</normal>
</text>
<icon>
<normal>#FFFFFF</normal>
</icon>
</file>
<macro>
<like>file</like>
+37 -35
View File
@@ -27,17 +27,45 @@
<query>
<none>
<normal>white</normal>
<hover>#F5F5F5</hover>
<normal>
<fill>white</fill>
<text>black</text>
</normal>
<hover>
<fill>#F5F5F5</fill>
<text>black</text>
</hover>
</none>
<command>
<normal>#8FBC92</normal>
<hover>#5EA071</hover>
<normal>
<fill>#8FBC92</fill>
<text>black</text>
</normal>
<hover>
<fill>#5EA071</fill>
<text>black</text>
</hover>
</command>
<operator>
<normal>#FCA47E</normal>
<hover>#F97A4E</hover>
<normal>
<fill>#FCA47E</fill>
<text>black</text>
</normal>
<hover>
<fill>#F97A4E</fill>
<text>black</text>
</hover>
</operator>
<fulltext>
<normal>
<fill>#C7C7E2</fill>
<text>black</text>
</normal>
<hover>
<fill>#ABABDD</fill>
<text>black</text>
</hover>
</fulltext>
</query>
</search>
@@ -121,14 +149,6 @@
<border>transparent</border>
<fill>transparent</fill>
</normal>
<focus>
<border>transparent</border>
<fill>transparent</fill>
</focus>
<active>
<border>transparent</border>
<fill>transparent</fill>
</active>
</scope>
<error>
<normal>
@@ -137,33 +157,15 @@
<text>#000000</text>
</normal>
<focus>
<border>transparent</border>
<fill>#FFFF0000</fill>
<text>#000000</text>
</focus>
<active>
<border>transparent</border>
<fill>#FFFF0000</fill>
<text>#000000</text>
</active>
</error>
<fulltextmatch>
<fulltext>
<normal>
<border>transparent</border>
<fill>#80FFFF00</fill>
<fill>#C7C7E2</fill>
<text>#000000</text>
</normal>
<focus>
<border>transparent</border>
<fill>#FFFFFF00</fill>
<text>#000000</text>
</focus>
<active>
<border>transparent</border>
<fill>#FFFFFF00</fill>
<text>#000000</text>
</active>
</fulltextmatch>
</fulltext>
</selection>
</snippet>
</code>
+58 -34
View File
@@ -27,17 +27,64 @@
<query>
<none>
<normal>#2F2F2F</normal>
<hover>black</hover>
<normal></normal>
<hover></hover>
</none>
<command>
<normal>#406D4D</normal>
<hover>#4E855E</hover>
<normal></normal>
<hover></hover>
</command>
<operator>
<normal>#7D2724</normal>
<hover>#8C2B29</hover>
<normal></normal>
<hover></hover>
</operator>
<fulltext>
<normal></normal>
<hover></hover>
</fulltext>
</query>
<query>
<none>
<normal>
<fill>#2F2F2F</fill>
<text>#F7F7F7</text>
</normal>
<hover>
<fill>black</fill>
<text>#F7F7F7</text>
</hover>
</none>
<command>
<normal>
<fill>#406D4D</fill>
<text>#F7F7F7</text>
</normal>
<hover>
<fill>#4E855E</fill>
<text>#F7F7F7</text>
</hover>
</command>
<operator>
<normal>
<fill>#7D2724</fill>
<text>#F7F7F7</text>
</normal>
<hover>
<fill>#8C2B29</fill>
<text>#F7F7F7</text>
</hover>
</operator>
<fulltext>
<normal>
<fill>#207EA8</fill>
<text>#F7F7F7</text>
</normal>
<hover>
<fill>#006D93</fill>
<text>#F7F7F7</text>
</hover>
</fulltext>
</query>
</search>
@@ -123,46 +170,23 @@
<border>transparent</border>
<fill>transparent</fill>
</normal>
<focus>
<border>transparent</border>
<fill>transparent</fill>
</focus>
<active>
<border>transparent</border>
<fill>transparent</fill>
</active>
</scope>
<error>
<normal>
<border>transparent</border>
<fill>#A0FF0000</fill>
<text>#000000</text>
</normal>
<focus>
<border>transparent</border>
<fill>#FFFF0000</fill>
</focus>
<active>
<border>transparent</border>
<fill>#FFFF0000</fill>
</active>
</error>
<fulltextmatch>
<fulltext>
<normal>
<border>transparent</border>
<fill>#80FFFF00</fill>
<text>#000000</text>
<fill>#207EA8</fill>
<text>#F7F7F7</text>
</normal>
<focus>
<border>transparent</border>
<fill>#FFFFFF00</fill>
<text>#000000</text>
</focus>
<active>
<border>transparent</border>
<fill>#FFFFFF00</fill>
<text>#000000</text>
</active>
</fulltextmatch>
</fulltext>
</selection>
</snippet>
</code>
@@ -65,6 +65,7 @@ void SearchController::handleMessage(MessageSearchFullText* message)
prefix += "@";
}
SearchMatch match(prefix + message->searchTerm);
match.searchType = SearchMatch::SEARCH_FULLTEXT;
getView()->setMatches(std::vector<SearchMatch>(1, match));
}
+2
View File
@@ -29,6 +29,8 @@ std::string SearchMatch::getSearchTypeName(SearchType type)
return "command";
case SEARCH_OPERATOR:
return "operator";
case SEARCH_FULLTEXT:
return "fulltext";
}
}
+2 -1
View File
@@ -16,7 +16,8 @@ struct SearchMatch
SEARCH_NONE,
SEARCH_TOKEN,
SEARCH_COMMAND,
SEARCH_OPERATOR
SEARCH_OPERATOR,
SEARCH_FULLTEXT
};
enum CommandType
+34 -2
View File
@@ -21,6 +21,11 @@ std::string ColorScheme::getColor(const std::string& key) const
return getValue<std::string>(key, "");
}
std::string ColorScheme::getColor(const std::string& key, const std::string& defaultColor) const
{
return getValue<std::string>(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<std::string>(path, "#FFFFFF");
}
@@ -96,6 +102,31 @@ std::string ColorScheme::getSyntaxColor(const std::string& key) const
return getValue<std::string>("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<std::string>("code/snippet/selection/" + typeStr + "/" + stateToString(state) + "/" + key, "");
if (!color.size() && state == ACTIVE)
{
color = getValue<std::string>("code/snippet/selection/" + typeStr + "/" + stateToString(FOCUS) + "/" + key, "");
}
if (!color.size() && state != NORMAL)
{
color = getValue<std::string>("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 "";
+6 -2
View File
@@ -12,13 +12,15 @@ public:
enum ColorState
{
NORMAL,
FOCUS
FOCUS,
ACTIVE
};
static std::shared_ptr<ColorScheme> 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;
@@ -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<Node::NodeType>(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<QVariant> 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())
{
+6 -7
View File
@@ -907,18 +907,17 @@ const QtCodeArea::AnnotationColor& QtCodeArea::getAnnotationColorForAnnotation(c
if (!s_annotationColors.size())
{
ColorScheme* scheme = ColorScheme::getInstance().get();
std::vector<std::string> types = { "token", "local_symbol", "scope", "error", "fulltextmatch"};
std::vector<std::string> states = { "normal", "focus", "active"};
std::vector<std::string> types = { "token", "local_symbol", "scope", "error", "fulltext" };
std::vector<ColorScheme::ColorState> 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);
}
}
+17 -15
View File
@@ -31,10 +31,21 @@ void QtSearchElement::onChecked(bool)
emit wasChecked(this);
}
void QtSmartSearchBox::search()
{
editTextToElement();
std::vector<SearchMatch> 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<SearchMatch> 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;