Пример #1
0
QVariant ProjectDirModel::data(const QModelIndex &index, int role) const {
  if (!index.isValid()) return QVariant();
  DvDirModelNode *node = getNode(index);
  if (role == Qt::DisplayRole || role == Qt::EditRole)
    return QString::fromStdWString(node->getName());
  else if (role == Qt::DecorationRole) {
    return QVariant();
  } else if (role == Qt::ForegroundRole) {
    if (!node || !node->isRenameEnabled())
      return QBrush(Qt::blue);
    else
      return QVariant();
  } else
    return QVariant();
}
void ExportSceneTreeViewDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
	QRect rect = option.rect;
	DvDirModelNode *node = DvDirModel::instance()->getNode(index);
	if (!node)
		return;

	DvDirModelProjectNode *pnode = dynamic_cast<DvDirModelProjectNode *>(node);
	DvDirModelFileFolderNode *fnode = dynamic_cast<DvDirModelFileFolderNode *>(node);

	if (node == m_treeView->getCurrentNode())
		painter->fillRect(rect, option.palette.highlight());

	QPixmap px = node->getPixmap(m_treeView->isExpanded(index));
	if (!px.isNull()) {
		int x = rect.left();
		int y = rect.top() + (rect.height() - px.height()) / 2;
		painter->drawPixmap(QPoint(x, y), px);
	}
	rect.adjust(pnode ? 26 : 20, 0, 0, 0);
	QVariant d = index.data();
	QString name = QString::fromStdWString(node->getName());
	if (node == m_treeView->getCurrentNode() && option.state & QStyle::State_Active)
		painter->setPen(Qt::white);
	else if (fnode && fnode->isProjectFolder())
		painter->setPen(Qt::blue);
	else
		painter->setPen(Qt::black);
	QRect nameBox;
	painter->drawText(rect, Qt::AlignVCenter | Qt::AlignLeft, name, &nameBox);

	if (pnode) {
		painter->setPen(Qt::black);
		if (pnode->isCurrent())
			painter->setBrush(Qt::red);
		else
			painter->setBrush(Qt::NoBrush);
		int d = 4;
		int y = (rect.height() - d) / 2;
		painter->drawEllipse(rect.x() - d - 4, rect.y() + y, d, d);
	}
	painter->setPen(Qt::magenta);
	painter->setBrush(Qt::NoBrush);
}