Move implementation to its own file

This commit is contained in:
Chocobo1 2019-07-17 21:57:52 +08:00
parent 1e70c52e7a
commit 07263d2d70
No known key found for this signature in database
GPG key ID: 210D9C873253A68C
18 changed files with 535 additions and 290 deletions

View file

@ -29,74 +29,19 @@
#ifndef PREVIEWLISTDELEGATE_H
#define PREVIEWLISTDELEGATE_H
#include <QApplication>
#include <QItemDelegate>
#include <QModelIndex>
#include <QPainter>
#include <QStyleOptionProgressBar>
#include <QStyleOptionViewItem>
#if defined(Q_OS_WIN) || defined(Q_OS_MACOS)
#include <QProxyStyle>
#endif
#include "base/utils/misc.h"
#include "base/utils/string.h"
#include "previewselectdialog.h"
class PreviewListDelegate : public QItemDelegate
{
Q_OBJECT
Q_DISABLE_COPY(PreviewListDelegate)
public:
PreviewListDelegate(QObject *parent = nullptr)
: QItemDelegate(parent)
{
}
explicit PreviewListDelegate(QObject *parent = nullptr);
~PreviewListDelegate() {}
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
painter->save();
QStyleOptionViewItem opt = QItemDelegate::setOptions(index, option);
switch (index.column()) {
case PreviewSelectDialog::SIZE:
QItemDelegate::drawBackground(painter, opt, index);
QItemDelegate::drawDisplay(painter, opt, option.rect, Utils::Misc::friendlyUnit(index.data().toLongLong()));
break;
case PreviewSelectDialog::PROGRESS: {
QStyleOptionProgressBar newopt;
qreal progress = index.data().toDouble() * 100.;
newopt.rect = opt.rect;
newopt.text = ((progress == 100.0) ? QString("100%") : Utils::String::fromDouble(progress, 1) + '%');
newopt.progress = static_cast<int>(progress);
newopt.maximum = 100;
newopt.minimum = 0;
newopt.state |= QStyle::State_Enabled;
newopt.textVisible = true;
#if !defined(Q_OS_WIN) && !defined(Q_OS_MACOS)
QApplication::style()->drawControl(QStyle::CE_ProgressBar, &newopt, painter);
#else
// XXX: To avoid having the progress text on the right of the bar
QProxyStyle st("fusion");
st.drawControl(QStyle::CE_ProgressBar, &newopt, painter, 0);
#endif
}
break;
default:
QItemDelegate::paint(painter, option, index);
}
painter->restore();
}
QWidget *createEditor(QWidget *, const QStyleOptionViewItem &, const QModelIndex &) const
{
// No editor here
return nullptr;
}
private:
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
QWidget *createEditor(QWidget *, const QStyleOptionViewItem &, const QModelIndex &) const override;
};
#endif // PREVIEWLISTDELEGATE_H