代码拉取完成,页面将自动刷新
同步操作将从 wufangzhao/startalk_pc_v2 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
//
// Created by cc on 18-11-13.
//
#include "TreeItemDelegate.h"
#include "../CustomUi/HeadPhotoLab.h"
#include "../UICom/qimage/qimage.h"
#include "../UICom/StyleDefine.h"
#include "../Platform/AppSetting.h"
#include <QTreeView>
#include <iostream>
#include <QApplication>
#include <QMouseEvent>
#include <QAbstractItemModel>
TreeItemDelegate::TreeItemDelegate(QWidget *parent)
: QStyledItemDelegate(parent), _parentWgt(parent)
{
}
TreeItemDelegate::~TreeItemDelegate()
= default;
void TreeItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
QStyledItemDelegate::paint(painter, option, index);
painter->save();
painter->setRenderHint(QPainter::TextAntialiasing);
painter->fillRect(option.rect, QTalk::StyleDefine::instance().getGroupManagerNormalColor());
///
int rowType = index.data(EM_STAFF_DATATYPE_ROW_TYPE).toInt();
int radius = 15;
if(rowType == EM_ROW_TYPE_SUBTITLE)
radius = 11;
else if(rowType == EM_ROW_TYPE_ITEM)
radius = 10;
QRect rect = option.rect;
QString strText = index.data(EM_STAFF_DATATYPE_TEXT).toString();
QString iconPath = index.data(EM_STAFF_DATATYPE_ICONPATH).toString();
QPixmap icon = QTalk::qimage::loadCirclePixmap(iconPath, radius * QTalk::qimage::dpi());
painter->setRenderHints(QPainter::Antialiasing, true);
painter->setRenderHints(QPainter::SmoothPixmapTransform, true);
painter->drawPixmap(QRect(rect.x(), rect.y() + (rect.height() - radius * 2) / 2, radius * 2, radius * 2), icon);
//
QTalk::setPainterFont(painter, AppSetting::instance().getFontLevel());
painter->setPen(QTalk::StyleDefine::instance().getGroupManagerNormalFontColor());
painter->drawText(QRect(rect.x() + radius * 2 + 2, rect.y(),
rect.width() - radius * 2 - 2 - 40, rect.height()), Qt::AlignVCenter, strText);
QString picPath;
QRect pixRect = QRect(rect.right() - 40, rect.y() + (rect.height() - radius * 2) / 2, 20, 20);;
if(rowType == EM_ROW_TYPE_ITEM)
{
bool isChecked = index.data(EM_DATATYPE_CHECKSTATE).toBool();
picPath = isChecked ? ":/GroupManager/image1/checkbox_checked.png"
: ":/GroupManager/image1/checkbox_unchecked.png";
}
else
{
bool isChecked = index.data(EM_STAFF_DATATYPE_EXTEND).toBool();
picPath = isChecked ? ":/GroupManager/image1/collapse.png"
: ":/GroupManager/image1/extend.png";
}
QPixmap checkIcon = QTalk::qimage::loadCirclePixmap(picPath,
20 * QTalk::qimage::dpi());
painter->drawPixmap(pixRect, checkIcon);
painter->restore();
}
QSize TreeItemDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
{
const QSize& size = QStyledItemDelegate::sizeHint(option, index);
int rowType = index.data(EM_STAFF_DATATYPE_ROW_TYPE).toInt();
if(rowType == EM_ROW_TYPE_TITLE)
return {size.width(), 60};
else
return {size.width(), 40};
}
bool TreeItemDelegate::editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option,
const QModelIndex &index)
{
if(event->type() == QEvent::MouseButtonPress)
{
int rowType = index.data(EM_STAFF_DATATYPE_ROW_TYPE).toInt();
if(EM_ROW_TYPE_ITEM == rowType)
{
bool isChecked = model->data(index, EM_DATATYPE_CHECKSTATE).toBool();
model->setData(index, !isChecked, EM_DATATYPE_CHECKSTATE);
emit itemChanged(index);
}
else
{
bool extend = model->data(index, EM_STAFF_DATATYPE_EXTEND).toBool();
model->setData(index, !extend, EM_STAFF_DATATYPE_EXTEND);
emit itemChanged(index);
}
}
else if(event->type() == QEvent::MouseButtonDblClick)
{
emit sgItemDbClicked(index);
}
return QStyledItemDelegate::editorEvent(event, model, option, index);
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。