2016-08-25 00:45:32 +02:00
|
|
|
#include "./dirbuttonsitemdelegate.h"
|
|
|
|
|
2017-02-23 15:49:58 +01:00
|
|
|
#include "../model/syncthingdirectorymodel.h"
|
|
|
|
|
2016-08-25 00:45:32 +02:00
|
|
|
#include <QApplication>
|
|
|
|
#include <QBrush>
|
2017-05-01 03:34:43 +02:00
|
|
|
#include <QPainter>
|
2016-08-25 00:45:32 +02:00
|
|
|
#include <QPalette>
|
2017-05-01 03:34:43 +02:00
|
|
|
#include <QPixmap>
|
|
|
|
#include <QStyle>
|
|
|
|
#include <QStyleOptionViewItem>
|
|
|
|
#include <QTextOption>
|
2016-08-25 00:45:32 +02:00
|
|
|
|
2017-02-23 15:49:58 +01:00
|
|
|
using namespace Data;
|
|
|
|
|
2016-08-25 00:45:32 +02:00
|
|
|
namespace QtGui {
|
|
|
|
|
|
|
|
inline int centerObj(int avail, int size)
|
|
|
|
{
|
|
|
|
return (avail - size) / 2;
|
|
|
|
}
|
|
|
|
|
2017-05-01 03:34:43 +02:00
|
|
|
DirButtonsItemDelegate::DirButtonsItemDelegate(QObject *parent)
|
|
|
|
: QStyledItemDelegate(parent)
|
|
|
|
, m_refreshIcon(QIcon::fromTheme(QStringLiteral("view-refresh"), QIcon(QStringLiteral(":/icons/hicolor/scalable/actions/view-refresh.svg")))
|
|
|
|
.pixmap(QSize(16, 16)))
|
|
|
|
, m_folderIcon(QIcon::fromTheme(QStringLiteral("folder-open"), QIcon(QStringLiteral(":/icons/hicolor/scalable/places/folder-open.svg")))
|
|
|
|
.pixmap(QSize(16, 16)))
|
|
|
|
, m_pauseIcon(
|
|
|
|
QIcon::fromTheme(QStringLiteral("media-playback-pause"), QIcon(QStringLiteral(":/icons/hicolor/scalable/actions/media-playback-pause.svg")))
|
|
|
|
.pixmap(QSize(16, 16)))
|
|
|
|
, m_resumeIcon(
|
|
|
|
QIcon::fromTheme(QStringLiteral("media-playback-start"), QIcon(QStringLiteral(":/icons/hicolor/scalable/actions/media-playback-start.svg")))
|
|
|
|
.pixmap(QSize(16, 16)))
|
|
|
|
{
|
|
|
|
}
|
2016-08-25 00:45:32 +02:00
|
|
|
|
|
|
|
void DirButtonsItemDelegate::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-25 00:45:32 +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;
|
2017-02-23 15:49:58 +01:00
|
|
|
textRect.setWidth(textRect.width() - 58);
|
2016-08-25 00:45:32 +02:00
|
|
|
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-25 00:45:32 +02:00
|
|
|
painter->drawText(textRect, displayText(index.data(Qt::DisplayRole), option.locale), textOption);
|
|
|
|
|
|
|
|
// draw buttons
|
|
|
|
const int buttonY = option.rect.y() + centerObj(option.rect.height(), 16);
|
2017-07-16 21:08:38 +02:00
|
|
|
const bool dirPaused = index.data(SyncthingDirectoryModel::DirectoryPaused).toBool();
|
|
|
|
if (!dirPaused) {
|
|
|
|
painter->drawPixmap(option.rect.right() - 52, buttonY, 16, 16, m_refreshIcon);
|
|
|
|
}
|
|
|
|
painter->drawPixmap(option.rect.right() - 34, buttonY, 16, 16, dirPaused ? m_resumeIcon : m_pauseIcon);
|
2016-08-25 00:45:32 +02:00
|
|
|
painter->drawPixmap(option.rect.right() - 16, buttonY, 16, 16, m_folderIcon);
|
|
|
|
}
|
|
|
|
}
|
2017-09-17 21:48:15 +02:00
|
|
|
} // namespace QtGui
|