mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-09-30 14:54:13 +02:00
Merge pull request #1092 from ispyisail/fix/search-list-dark-icons
Fix element icons that are dark on a dark theme in search results
This commit is contained in:
@@ -45,7 +45,9 @@
|
||||
#include <limits>
|
||||
|
||||
#include "../qetapp.h"
|
||||
#include "../qetpalette.h"
|
||||
#include "../shortcutmanager.h"
|
||||
#include "elementpreviewdelegate.h"
|
||||
#include "elementslocation.h"
|
||||
|
||||
//The palette is read from disk each time the picker opens. It is meant as
|
||||
@@ -53,6 +55,25 @@
|
||||
//slow and the grid unusable.
|
||||
static const int max_palette_entries = 60;
|
||||
|
||||
/**
|
||||
@brief elementIcon
|
||||
@return the element preview @a icon, adapted to @a widget's palette at
|
||||
@a size. The shortcut bar and its editor mix these with command icons,
|
||||
which already follow the palette through the icon theme, so the
|
||||
element icons are adapted once here rather than by an
|
||||
ElementPreviewDelegate over the whole list. An item dragged from one
|
||||
list to another keeps its adapted icon.
|
||||
*/
|
||||
static QIcon elementIcon(const QIcon &icon, const QSize &size, const QWidget *widget)
|
||||
{
|
||||
if (icon.isNull() || !QET::Palette::isDark(widget->palette())) {
|
||||
return icon;
|
||||
}
|
||||
return QIcon(QET::Palette::forPalette(
|
||||
icon.pixmap(size, widget->devicePixelRatio()),
|
||||
widget->palette()));
|
||||
}
|
||||
|
||||
/**
|
||||
@brief ElementPickerPopup::ElementPickerPopup
|
||||
@param source : the collection widget whose model the search runs against
|
||||
@@ -217,6 +238,8 @@ ElementPickerPopup::ElementPickerPopup(ElementsCollectionWidget *source,
|
||||
m_model = new QStandardItemModel(this);
|
||||
m_view = new QListView(this);
|
||||
m_view->setModel(m_model);
|
||||
//Element previews are black line art; adapt them to a dark palette
|
||||
m_view->setItemDelegate(new ElementPreviewDelegate(m_view));
|
||||
m_view->setIconSize(QSize(40, 40));
|
||||
m_view->setVerticalScrollMode(QAbstractItemView::ScrollPerPixel);
|
||||
m_view->setEditTriggers(QAbstractItemView::NoEditTriggers);
|
||||
@@ -378,7 +401,7 @@ void ElementPickerPopup::setCommands(const QStringList &ids)
|
||||
auto *button = new QToolButton(m_commands);
|
||||
button->setAutoRaise(true);
|
||||
button->setIconSize(QSize(24, 24));
|
||||
button->setIcon(location.icon());
|
||||
button->setIcon(elementIcon(location.icon(), QSize(24, 24), this));
|
||||
button->setToolTip(location.name());
|
||||
button->setFocusPolicy(Qt::NoFocus);
|
||||
connect(button, &QToolButton::clicked, this, [this, location]() {
|
||||
@@ -542,7 +565,7 @@ QListWidgetItem *ElementPickerPopup::barItem(const QString &id, bool icon_only)
|
||||
const ElementsLocation location(id);
|
||||
if (location.exist()) {
|
||||
text = location.name();
|
||||
icon = location.icon();
|
||||
icon = elementIcon(location.icon(), QSize(24, 24), this);
|
||||
}
|
||||
} else if (QAction *action = commandAction(id)) {
|
||||
text = action->text().remove(QLatin1Char('&'));
|
||||
@@ -632,7 +655,8 @@ void ElementPickerPopup::runSymbolSearch()
|
||||
if (ElementsLocation(hit.path).isProject()) {
|
||||
continue;
|
||||
}
|
||||
auto *item = new QListWidgetItem(hit.icon, hit.name);
|
||||
auto *item = new QListWidgetItem(
|
||||
elementIcon(hit.icon, m_edit_symbols->iconSize(), this), hit.name);
|
||||
item->setData(Qt::UserRole, hit.path);
|
||||
item->setToolTip(QStringLiteral("%1\n%2").arg(hit.name, hit.folder));
|
||||
m_edit_symbols->addItem(item);
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
#include "../qetmessagebox.h"
|
||||
#include "../qetproject.h"
|
||||
#include "elementcollectionitem.h"
|
||||
#include "elementpreviewdelegate.h"
|
||||
#include "elementscollectionmodel.h"
|
||||
#include "elementslocation.h"
|
||||
#include "elementstreeview.h"
|
||||
@@ -258,6 +259,8 @@ void ElementsCollectionWidget::setUpWidget()
|
||||
m_search_model = new QStandardItemModel(this);
|
||||
m_search_results = new SearchResultsView(this);
|
||||
m_search_results->setModel(m_search_model);
|
||||
//Same dark-palette icons as the tree the list stands in for
|
||||
m_search_results->setItemDelegate(new ElementPreviewDelegate(m_search_results));
|
||||
m_search_results->setDragDropMode(QAbstractItemView::DragOnly);
|
||||
m_search_results->setIconSize(QSize(50, 50));
|
||||
m_search_results->setUniformItemSizes(false);
|
||||
|
||||
Reference in New Issue
Block a user