File: devbuttonsitemdelegate.cpp

package info (click to toggle)
syncthingtray 1.7.5-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 6,804 kB
  • sloc: cpp: 31,085; xml: 1,694; java: 570; sh: 81; javascript: 53; makefile: 25
file content (49 lines) | stat: -rw-r--r-- 1,677 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include "./devbuttonsitemdelegate.h"

#include "./helper.h"

#include <syncthingconnector/syncthingconnection.h>
#include <syncthingmodel/syncthingdevicemodel.h>
#include <syncthingmodel/syncthingicons.h>

#include <qtforkawesome/icon.h>
#include <qtforkawesome/renderer.h>

#include <QPainter>
#include <QPalette>
#include <QStyle>
#include <QStyleOptionViewItem>

using namespace Data;

namespace QtGui {

DevButtonsItemDelegate::DevButtonsItemDelegate(QObject *parent)
    : QStyledItemDelegate(parent)
{
}

void DevButtonsItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
    auto opt = option;
    initStyleOption(&opt, index);
    opt.viewItemPosition = QStyleOptionViewItem::OnlyOne;

    if (index.parent().isValid()) {
        drawField(this, painter, opt, index, SyncthingDeviceModel::DeviceDetail);
    } else {
        drawIdAndStatus(this, painter, opt, index, SyncthingDeviceModel::DeviceStatusString, SyncthingDeviceModel::DeviceStatusColor,
            listItemIconsSize(0) + listItemSpacing);

        // draw button
        if (index.data(SyncthingDeviceModel::IsThisDevice).toBool()) {
            return;
        }
        const int buttonY = option.rect.y() + centerObj(option.rect.height(), listItemIconSize);
        QtForkAwesome::Renderer::global().render(
            index.data(SyncthingDeviceModel::DevicePaused).toBool() ? QtForkAwesome::Icon::Play : QtForkAwesome::Icon::Pause, painter,
            QRect(option.rect.right() - listItemIconsSize(0), buttonY, listItemIconSize, listItemIconSize),
            QGuiApplication::palette().color(QPalette::Text));
    }
}
} // namespace QtGui