2016-08-26 16:43:53 +02:00
|
|
|
#include "./devbuttonsitemdelegate.h"
|
|
|
|
|
2021-01-25 19:48:11 +01:00
|
|
|
#include <syncthingconnector/syncthingconnection.h>
|
|
|
|
#include <syncthingmodel/syncthingdevicemodel.h>
|
2021-10-15 00:23:22 +02:00
|
|
|
#include <syncthingmodel/syncthingicons.h>
|
|
|
|
|
|
|
|
#include <qtforkawesome/icon.h>
|
2021-10-15 22:18:54 +02:00
|
|
|
#include <qtforkawesome/renderer.h>
|
2016-08-26 16:43:53 +02:00
|
|
|
|
|
|
|
#include <QApplication>
|
|
|
|
#include <QBrush>
|
2017-05-01 03:34:43 +02:00
|
|
|
#include <QPainter>
|
2016-08-26 16:43:53 +02:00
|
|
|
#include <QPalette>
|
2017-05-01 03:34:43 +02:00
|
|
|
#include <QPixmap>
|
|
|
|
#include <QStyle>
|
|
|
|
#include <QStyleOptionViewItem>
|
|
|
|
#include <QTextOption>
|
2016-08-26 16:43:53 +02:00
|
|
|
|
|
|
|
using namespace Data;
|
|
|
|
|
|
|
|
namespace QtGui {
|
|
|
|
|
|
|
|
inline int centerObj(int avail, int size)
|
|
|
|
{
|
|
|
|
return (avail - size) / 2;
|
|
|
|
}
|
|
|
|
|
2017-05-01 03:34:43 +02:00
|
|
|
DevButtonsItemDelegate::DevButtonsItemDelegate(QObject *parent)
|
|
|
|
: QStyledItemDelegate(parent)
|
|
|
|
{
|
|
|
|
}
|
2016-08-26 16:43:53 +02:00
|
|
|
|
|
|
|
void DevButtonsItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
|
|
|
|
{
|
|
|
|
// use the customization only on top-level rows
|
2017-05-01 03:34:43 +02:00
|
|
|
if (index.parent().isValid()) {
|
2016-08-26 16:43:53 +02:00
|
|
|
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);
|
2016-09-29 20:45:54 +02:00
|
|
|
painter->setPen(opt.palette.color(opt.state & QStyle::State_Selected ? QPalette::HighlightedText : QPalette::Text));
|
2016-08-26 16:43:53 +02:00
|
|
|
painter->drawText(textRect, displayText(index.data(Qt::DisplayRole), option.locale), textOption);
|
|
|
|
|
|
|
|
// draw buttons
|
2021-02-12 20:31:05 +01:00
|
|
|
if (index.data(SyncthingDeviceModel::IsOwnDevice).toBool()) {
|
|
|
|
return;
|
|
|
|
}
|
2016-08-26 16:43:53 +02:00
|
|
|
const int buttonY = option.rect.y() + centerObj(option.rect.height(), 16);
|
2022-10-03 14:40:14 +02:00
|
|
|
QtForkAwesome::Renderer::global().render(
|
2021-10-15 22:18:54 +02:00
|
|
|
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));
|
2016-08-26 16:43:53 +02:00
|
|
|
}
|
|
|
|
}
|
2017-09-17 21:48:15 +02:00
|
|
|
} // namespace QtGui
|