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
@@ -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;