Page Menu
Home
Phabricator (Chris)
Search
Configure Global Search
Log In
Files
F133807
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Authored By
Unknown
Size
3 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/src/FilesListWidget.cpp b/src/FilesListWidget.cpp
index b074373..cd364ec 100644
--- a/src/FilesListWidget.cpp
+++ b/src/FilesListWidget.cpp
@@ -1,82 +1,93 @@
#include "FilesListWidget.h"
#include <QDebug>
#include <QPainter>
#include <QStyledItemDelegate>
#include <map>
namespace {
class ItemDelegate : public QStyledItemDelegate {
private:
struct Badge {
QString text;
QColor color;
QIcon icon;
Badge() = default;
Badge(QString const &text, QColor const &color, QIcon const &icon)
: text(text)
, color(color)
, icon(icon)
{
}
};
std::map<QString, Badge> badge_map;
public:
ItemDelegate(QObject *parent)
: QStyledItemDelegate(parent)
{
badge_map["(chg) "] = Badge("Chg", QColor(240, 240, 140), QIcon(":/image/chg.svg"));
badge_map["(add) "] = Badge("Add", QColor(180, 240, 180), QIcon(":/image/add.svg"));
badge_map["(del) "] = Badge("Del", QColor(255, 200, 200), QIcon(":/image/del.svg"));
badge_map["(ren) "] = Badge("Ren", QColor(200, 210, 255), QIcon(":/image/ren.svg"));
badge_map["(cpy) "] = Badge("Cpy", QColor(200, 210, 255), QIcon(":/image/cpy.svg"));
}
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override
{
QStyleOptionViewItem o = option;
QStyledItemDelegate::initStyleOption(&o, index);
int x = o.rect.x();
int y = o.rect.y();
int h = o.rect.height();
int w = 2 + h + painter->fontMetrics().size(0, " Aaa").width() + 2;
// draw badge
QString header = o.text.mid(0, 6);
+ QColor color;
+ Badge const *badge = nullptr;
auto it = badge_map.find(header);
if (it != badge_map.end()) {
+ badge = &it->second;
+ color = badge->color;
+ } else {
+ color = QColor(160, 160, 160);
+ }
+ {
o.text = o.text.mid(6);
- Badge const *badge = &it->second;
QRect r(x, y, w, h);
QRect r_icon = QRect(x + 2, y + 1, h - 2, h - 2).adjusted(2, 2, -2, -2);
QRect r_badge = r.adjusted(1, 1, -2, -2);
QRect r_text = r.adjusted(r_icon.width(), 0, 0, 0);
painter->setPen(Qt::NoPen);
- painter->setBrush(QBrush(badge->color.darker(130)));
+ painter->setBrush(QBrush(color.darker(130)));
painter->drawRoundedRect(r_badge.translated(1, 1), 3, 3);
- painter->setBrush(QBrush(badge->color));
+ painter->setBrush(QBrush(color));
painter->drawRoundedRect(r_badge, 3, 3);
- if (!badge->icon.isNull()) {
+ if (badge && !badge->icon.isNull()) {
painter->save();
painter->setOpacity(0.5);
badge->icon.paint(painter, r_icon);
painter->restore();
}
painter->setPen(Qt::black);
QTextOption to;
to.setAlignment(Qt::AlignCenter | Qt::AlignVCenter);
- painter->drawText(r_text, badge->text, to);
+ if (badge) {
+ painter->drawText(r_text, badge->text, to);
+ } else {
+ painter->drawText(r_badge, "?", to);
+ }
}
o.rect.adjust(w, 0, 0, 0);
// draw text
option.widget->style()->drawControl(QStyle::CE_ItemViewItem, &o, painter, option.widget);
}
};
}
FilesListWidget::FilesListWidget(QWidget *parent)
: QListWidget(parent)
{
item_delegate = new ItemDelegate(this);
setItemDelegate(item_delegate);
}
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Wed, Jun 17, 9:06 PM (1 w, 5 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
69711
Default Alt Text
(3 KB)
Attached To
Mode
R77 Guitar
Attached
Detach File
Event Timeline