Commit 1d1df19c authored by Waqar Ahmed's avatar Waqar Ahmed Committed by Christoph Cullmann
Browse files

search: Fix expand triangle color with light themes

If you are using a non-breeze theme such as fusion and the only color
scheme available to you is "light" and you like using dark editor theme,
then while searching the expand triangle is almost invisible in search
results. This change fixes that.
parent f2e0dd85
Pipeline #139841 passed with stage
in 4 minutes and 52 seconds
......@@ -40,5 +40,6 @@ target_sources(
plugin_search.cpp
search_open_files.cpp
Results.cpp
ResultsTreeView.cpp
)
/*
SPDX-FileCopyrightText: 2011-21 Kåre Särs <kare.sars@iki.fi>
SPDX-FileCopyrightText: 2022 Waqar Ahmed <waqar.17a@gmail.com>
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#include "Results.h"
#include "MatchProxyModel.h"
......@@ -30,22 +36,12 @@ Results::Results(QWidget *parent)
if (!e) {
return;
}
const auto theme = e->theme();
auto bg = QColor::fromRgba(theme.editorColor(KSyntaxHighlighting::Theme::BackgroundColor));
auto hl = QColor::fromRgba(theme.editorColor(KSyntaxHighlighting::Theme::TextSelection));
auto search = QColor::fromRgba(theme.editorColor(KSyntaxHighlighting::Theme::SearchHighlight));
auto replace = QColor::fromRgba(theme.editorColor(KSyntaxHighlighting::Theme::ReplaceHighlight));
auto fg = QColor::fromRgba(theme.textColor(KSyntaxHighlighting::Theme::Normal));
auto pal = treeView->palette();
pal.setColor(QPalette::Base, bg);
pal.setColor(QPalette::Highlight, hl);
pal.setColor(QPalette::Text, fg);
matchModel.setMatchColors(fg.name(QColor::HexArgb), search.name(QColor::HexArgb), replace.name(QColor::HexArgb));
treeView->setPalette(pal);
Q_EMIT colorsChanged();
};
auto e = KTextEditor::Editor::instance();
......
/*
SPDX-FileCopyrightText: 2011-21 Kåre Särs <kare.sars@iki.fi>
SPDX-FileCopyrightText: 2022 Waqar Ahmed <waqar.17a@gmail.com>
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#ifndef KATE_SEARCH_RESULTS_H
#define KATE_SEARCH_RESULTS_H
......@@ -36,9 +42,6 @@ public:
QModelIndex lastMatch() const;
KTextEditor::Range matchRange(const QModelIndex &matchIndex) const;
bool replaceSingleMatch(KTextEditor::Document *doc, const QModelIndex &matchIndex, const QRegularExpression &regExp, const QString &replaceString);
Q_SIGNALS:
void colorsChanged();
};
#endif
/*
SPDX-FileCopyrightText: 2011-21 Kåre Särs <kare.sars@iki.fi>
SPDX-FileCopyrightText: 2022 Waqar Ahmed <waqar.17a@gmail.com>
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#include "ResultsTreeView.h"
#include <KSyntaxHighlighting/Theme>
#include <KTextEditor/Editor>
ResultsTreeView::ResultsTreeView(QWidget *parent)
: QTreeView(parent)
{
auto updateColors = [this](KTextEditor::Editor *e) {
if (!e) {
return;
}
const auto theme = e->theme();
auto base = QColor::fromRgba(theme.editorColor(KSyntaxHighlighting::Theme::BackgroundColor));
auto highlight = QColor::fromRgba(theme.editorColor(KSyntaxHighlighting::Theme::TextSelection));
m_fg = QColor::fromRgba(theme.textColor(KSyntaxHighlighting::Theme::Normal));
auto pal = palette();
pal.setColor(QPalette::Base, base);
pal.setColor(QPalette::Text, m_fg);
pal.setColor(QPalette::Highlight, highlight);
setPalette(pal);
};
auto *e = KTextEditor::Editor::instance();
connect(e, &KTextEditor::Editor::configChanged, this, updateColors);
updateColors(e);
}
QStyleOptionViewItem ResultsTreeView::viewOptions() const
{
auto options = QTreeView::viewOptions();
// We set this here so that the "expand triangle" in the treeview
// is always colored in a visible color. This is important for
// styles like fusion, where it can be dark on dark
options.palette.setColor(QPalette::WindowText, m_fg);
return options;
}
/*
SPDX-FileCopyrightText: 2011-21 Kåre Särs <kare.sars@iki.fi>
SPDX-FileCopyrightText: 2022 Waqar Ahmed <waqar.17a@gmail.com>
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#ifndef KATE_SEARCH_RESULTS_TREE_VIEW_H
#define KATE_SEARCH_RESULTS_TREE_VIEW_H
#include <QTreeView>
class ResultsTreeView : public QTreeView
{
Q_OBJECT
public:
ResultsTreeView(QWidget *parent);
QStyleOptionViewItem viewOptions() const override;
private:
QColor m_fg;
};
#endif
......@@ -554,6 +554,10 @@ KatePluginSearchView::KatePluginSearchView(KTextEditor::Plugin *plugin, KTextEdi
m_toolView->installEventFilter(this);
m_mainWindow->guiFactory()->addClient(this);
auto e = KTextEditor::Editor::instance();
connect(e, &KTextEditor::Editor::configChanged, this, &KatePluginSearchView::updateViewColors);
updateViewColors();
}
KatePluginSearchView::~KatePluginSearchView()
......@@ -905,28 +909,21 @@ void KatePluginSearchView::stopClicked()
*/
void KatePluginSearchView::updateViewColors()
{
auto *view = m_mainWindow->activeView();
KTextEditor::ConfigInterface *ciface = qobject_cast<KTextEditor::ConfigInterface *>(view);
if (ciface && view) {
// save for later reuse when the search tree starts getting populated
QColor search = ciface->configValue(QStringLiteral("search-highlight-color")).value<QColor>();
if (!search.isValid()) {
search = Qt::yellow;
}
m_replaceHighlightColor = ciface->configValue(QStringLiteral("replace-highlight-color")).value<QColor>();
if (!m_replaceHighlightColor.isValid()) {
m_replaceHighlightColor = Qt::green;
}
QColor fg = view->defaultStyleAttribute(KTextEditor::dsNormal)->foreground().color();
auto *e = KTextEditor::Editor::instance();
const auto theme = e->theme();
if (!m_resultAttr) {
m_resultAttr = new KTextEditor::Attribute();
}
// reset colors at the start of search
m_resultAttr->clear();
m_resultAttr->setBackground(search);
m_resultAttr->setForeground(fg);
auto search = QColor::fromRgba(theme.editorColor(KSyntaxHighlighting::Theme::SearchHighlight));
auto replace = QColor::fromRgba(theme.editorColor(KSyntaxHighlighting::Theme::ReplaceHighlight));
auto fg = QColor::fromRgba(theme.textColor(KSyntaxHighlighting::Theme::Normal));
if (!m_resultAttr) {
m_resultAttr = new KTextEditor::Attribute();
}
m_resultAttr->clear();
m_resultAttr->setBackground(search);
m_resultAttr->setForeground(fg);
m_replaceHighlightColor = replace;
}
// static QElapsedTimer s_timer;
......@@ -1003,8 +1000,6 @@ void KatePluginSearchView::startSearch()
Q_EMIT searchBusy(true);
updateViewColors();
m_curResults->searchStr = currentSearchText;
m_curResults->regExp = reg;
m_curResults->useRegExp = m_ui.useRegExp->isChecked();
......@@ -1163,7 +1158,6 @@ void KatePluginSearchView::startSearchWhileTyping()
// Now we should have a true typed text change
m_isSearchAsYouType = true;
updateViewColors();
clearMarksAndRanges();
QString pattern = (m_ui.useRegExp->isChecked() ? currentSearchText : QRegularExpression::escape(currentSearchText));
......@@ -1989,10 +1983,6 @@ void KatePluginSearchView::addTab()
{
Results *res = new Results();
connect(res, &Results::colorsChanged, this, [this]() {
updateViewColors();
});
res->treeView->setContextMenuPolicy(Qt::CustomContextMenu);
res->treeView->setRootIsDecorated(false);
connect(res->treeView, &QTreeView::doubleClicked, this, &KatePluginSearchView::itemSelected, Qt::UniqueConnection);
......
......@@ -24,7 +24,7 @@
<number>0</number>
</property>
<item>
<widget class="QTreeView" name="treeView">
<widget class="ResultsTreeView" name="treeView">
<property name="uniformRowHeights">
<bool>true</bool>
</property>
......@@ -38,6 +38,13 @@
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>ResultsTreeView</class>
<extends>QTreeView</extends>
<header>ResultsTreeView.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment