forked from nuttyartist/notes
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathallnotebuttontreedelegateeditor.cpp
More file actions
67 lines (64 loc) · 2.59 KB
/
Copy pathallnotebuttontreedelegateeditor.cpp
File metadata and controls
67 lines (64 loc) · 2.59 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include "allnotebuttontreedelegateeditor.h"
#include <QPainter>
#include <QDebug>
#include <QTreeView>
#include "nodetreemodel.h"
#include "nodetreeview.h"
AllNoteButtonTreeDelegateEditor::AllNoteButtonTreeDelegateEditor(QTreeView *view, const QStyleOptionViewItem &option,
const QModelIndex &m_index,
QWidget *parent) :
QWidget(parent),
m_option(option),
m_index(m_index),
#ifdef __APPLE__
m_displayFont(QFont(QStringLiteral("SF Pro Text")).exactMatch() ? QStringLiteral("SF Pro Text") : QStringLiteral("Roboto")),
#elif _WIN32
m_displayFont(QFont(QStringLiteral("Segoe UI")).exactMatch() ? QStringLiteral("Segoe UI") : QStringLiteral("Roboto")),
#else
m_displayFont(QStringLiteral("Roboto")),
#endif
#ifdef __APPLE__
m_titleFont(m_displayFont, 13, 65),
#else
m_titleFont(m_displayFont, 10, 60),
#endif
m_titleColor(26, 26, 26),
m_titleSelectedColor(255, 255, 255),
m_activeColor(68, 138, 201),
m_hoverColor(207, 207, 207),
m_view(view)
{
setContentsMargins(0, 0, 0, 0);
}
void AllNoteButtonTreeDelegateEditor::paintEvent(QPaintEvent *event)
{
QPainter painter(this);
auto iconRect = QRect(rect().x() + 5, rect().y() + (rect().height() - 20) / 2, 18, 20);
auto iconPath = m_index.data(NodeItem::Roles::Icon).toString();
auto displayName = m_index.data(NodeItem::Roles::DisplayText).toString();
QRect nameRect(rect());
nameRect.setLeft(iconRect.x() + iconRect.width() + 5);
nameRect.setWidth(nameRect.width() - 5 - 40);
if (m_view->selectionModel()->isSelected(m_index)) {
painter.fillRect(rect(), QBrush(m_activeColor));
painter.setPen(m_titleSelectedColor);
} else {
painter.fillRect(rect(), QBrush(m_hoverColor));
painter.setPen(m_titleColor);
}
painter.drawImage(iconRect, QImage(iconPath));
painter.setFont(m_titleFont);
painter.drawText(nameRect, Qt::AlignLeft | Qt::AlignVCenter, displayName);
auto childCountRect = rect();
childCountRect.setLeft(nameRect.right() + 5);
childCountRect.setWidth(childCountRect.width() - 5);
auto childCount = m_index.data(NodeItem::Roles::ChildCount).toInt();
if (m_view->selectionModel()->isSelected(m_index)) {
painter.setPen(m_titleSelectedColor);
} else {
painter.setPen(m_titleColor);
}
painter.setFont(m_titleFont);
painter.drawText(childCountRect, Qt::AlignHCenter | Qt::AlignVCenter, QString::number(childCount));
QWidget::paintEvent(event);
}