|
|
|
@ -7,7 +7,7 @@
|
|
|
|
|
#include "notelistview.h"
|
|
|
|
|
#include "editorsettingsoptions.h"
|
|
|
|
|
#include "fontloader.h"
|
|
|
|
|
|
|
|
|
|
//分操作系统设置font
|
|
|
|
|
AllNoteButtonTreeDelegateEditor::AllNoteButtonTreeDelegateEditor(QTreeView *view,
|
|
|
|
|
const QStyleOptionViewItem &option,
|
|
|
|
|
const QModelIndex &index,
|
|
|
|
@ -45,20 +45,27 @@ AllNoteButtonTreeDelegateEditor::AllNoteButtonTreeDelegateEditor(QTreeView *view
|
|
|
|
|
{
|
|
|
|
|
setContentsMargins(0, 0, 0, 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//重写paintEvent函数
|
|
|
|
|
void AllNoteButtonTreeDelegateEditor::paintEvent(QPaintEvent *event)
|
|
|
|
|
{
|
|
|
|
|
QPainter painter(this);
|
|
|
|
|
//定图标位置
|
|
|
|
|
auto iconRect = QRect(rect().x() + 22, 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() - 22 - 40);
|
|
|
|
|
|
|
|
|
|
if (m_view->selectionModel()->isSelected(m_index)) {
|
|
|
|
|
//根据是否被选中绘制不同颜色
|
|
|
|
|
painter.fillRect(rect(), QBrush(m_activeColor));
|
|
|
|
|
painter.setPen(m_titleSelectedColor);
|
|
|
|
|
} else {
|
|
|
|
|
//拖动绘制
|
|
|
|
|
auto listView = dynamic_cast<NoteListView *>(m_listView);
|
|
|
|
|
if (listView->isDragging()) {
|
|
|
|
|
if (m_theme == Theme::Dark) {
|
|
|
|
@ -71,6 +78,7 @@ void AllNoteButtonTreeDelegateEditor::paintEvent(QPaintEvent *event)
|
|
|
|
|
}
|
|
|
|
|
painter.setPen(m_folderIconColor);
|
|
|
|
|
}
|
|
|
|
|
//又开始分操作系统绘制
|
|
|
|
|
#ifdef __APPLE__
|
|
|
|
|
int iconPointSizeOffset = 0;
|
|
|
|
|
#else
|
|
|
|
@ -86,6 +94,7 @@ void AllNoteButtonTreeDelegateEditor::paintEvent(QPaintEvent *event)
|
|
|
|
|
painter.setPen(m_titleColor);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//设置子项
|
|
|
|
|
painter.setFont(m_titleFont);
|
|
|
|
|
painter.drawText(nameRect, Qt::AlignLeft | Qt::AlignVCenter, displayName);
|
|
|
|
|
auto childCountRect = rect();
|
|
|
|
@ -100,9 +109,12 @@ void AllNoteButtonTreeDelegateEditor::paintEvent(QPaintEvent *event)
|
|
|
|
|
painter.setFont(m_numberOfNotesFont);
|
|
|
|
|
painter.drawText(childCountRect, Qt::AlignHCenter | Qt::AlignVCenter,
|
|
|
|
|
QString::number(childCount));
|
|
|
|
|
//调用基类 QWidget 的 paintEvent 函数,以确保小部件的其他默认绘制行为得以执行
|
|
|
|
|
QWidget::paintEvent(event);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//又是用switch来设置枚举类型的值
|
|
|
|
|
//要注意的一点是,没有使用0、1、2等来列举,而是使用key值来列举,有利于增加代码规模和程序员阅读
|
|
|
|
|
void AllNoteButtonTreeDelegateEditor::setTheme(Theme::Value theme)
|
|
|
|
|
{
|
|
|
|
|
m_theme = theme;
|
|
|
|
|