syncthingtray/tray/gui/devbuttonsitemdelegate.cpp
Martchus 7b6121cb05 Use ForkAwesome icons more consistently in tray widget
Mixing ForkAwesome icons too much with the regular icon theme doesn't look
good (depending on the theme) so let's prefer ForkAwesome icons within the
tray widget which already uses ForkAwesome in some places like certain
buttons and models. This makes it also look more in-line with Syncthing's
web UI. For context menus and dialogs let's prefer system icons because
there are hardly any ForkAwesome icons used/required so far and it is maybe
nicer to be in-line with the system here.
2021-10-15 00:23:22 +02:00

64 lines
2.2 KiB
C++

#include "./devbuttonsitemdelegate.h"
#include <syncthingconnector/syncthingconnection.h>
#include <syncthingmodel/syncthingdevicemodel.h>
#include <syncthingmodel/syncthingicons.h>
#include <qtforkawesome/renderer.h>
#include <qtforkawesome/icon.h>
#include <QApplication>
#include <QBrush>
#include <QPainter>
#include <QPalette>
#include <QPixmap>
#include <QStyle>
#include <QStyleOptionViewItem>
#include <QTextOption>
using namespace Data;
namespace QtGui {
inline int centerObj(int avail, int size)
{
return (avail - size) / 2;
}
DevButtonsItemDelegate::DevButtonsItemDelegate(QObject *parent)
: QStyledItemDelegate(parent)
{
}
void DevButtonsItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
// use the customization only on top-level rows
if (index.parent().isValid()) {
QStyledItemDelegate::paint(painter, option, index);
} else {
// init style options to use drawControl(), except for the text
QStyleOptionViewItem opt = option;
initStyleOption(&opt, index);
opt.text.clear();
opt.features = QStyleOptionViewItem::None;
QApplication::style()->drawControl(QStyle::CE_ItemViewItem, &opt, painter);
// draw text
QRectF textRect = option.rect;
textRect.setWidth(textRect.width() - 20);
QTextOption textOption;
textOption.setAlignment(opt.displayAlignment);
painter->setFont(opt.font);
painter->setPen(opt.palette.color(opt.state & QStyle::State_Selected ? QPalette::HighlightedText : QPalette::Text));
painter->drawText(textRect, displayText(index.data(Qt::DisplayRole), option.locale), textOption);
// draw buttons
if (index.data(SyncthingDeviceModel::IsOwnDevice).toBool()) {
return;
}
const int buttonY = option.rect.y() + centerObj(option.rect.height(), 16);
IconManager::instance().forkAwesomeRenderer().render(index.data(SyncthingDeviceModel::DevicePaused).toBool() ? QtForkAwesome::Icon::Play : QtForkAwesome::Icon::Pause, painter, QRect(option.rect.right() - 16, buttonY, 16, 16), QGuiApplication::palette().color(QPalette::Text));
}
}
} // namespace QtGui