void CWizNoteStyle::drawCategoryViewItem(const QStyleOptionViewItemV4 *vopt,
                                         QPainter *p, const CWizCategoryBaseView *view) const
{
    if (view->isDragHovered() && view->validateDropDestination(view->dragHoveredPos())) {
        QRect rect = view->visualItemRect(view->itemAt(view->dragHoveredPos()));
        p->setRenderHint(QPainter::Antialiasing, true);
        QPen pen;
        pen.setStyle(Qt::SolidLine);
//        pen.setCapStyle(Qt::RoundCap);
        pen.setColor(QColor("#3498DB"));
        pen.setWidth(1);
        p->setPen(pen);
        p->setBrush(Qt::NoBrush);
        rect.setWidth(rect.width() - 2);
        p->drawRect(rect);
    }

    CWizCategoryViewItemBase* pItem = view->categoryItemFromIndex(vopt->index);

    if (view->isHelperItemByIndex(vopt->index)) {
        if (NULL != dynamic_cast<const CWizCategoryViewSectionItem*>(pItem)) {
            QString str = vopt->text;
            QRect rc(vopt->rect);
            rc.setTop(rc.top() + 12);
            Utils::StyleHelper::drawSingleLineText(p, rc, str, Qt::AlignVCenter, Utils::StyleHelper::treeViewItemCategoryText(), p->font());
        }
        else if (NULL != dynamic_cast<const CWizCategoryViewLinkItem*>(pItem)) {
            QString str = vopt->text;
            QRect rc(vopt->rect);
            rc.setLeft(rc.left() + 16);
            Utils::StyleHelper::drawSingleLineText(p, rc, str, Qt::AlignVCenter, Utils::StyleHelper::treeViewItemLinkText(), m_fontLink);
        }

        return;
    }

    p->save();

    bool bSelected = vopt->state.testFlag(State_Selected);
    int nLeftMargin = 4;
    if (!vopt->icon.isNull()) {
        QRect iconRect = subElementRect(SE_ItemViewItemDecoration, vopt, view);
        iconRect.adjust(nLeftMargin, 0, nLeftMargin, 0);
        Utils::StyleHelper::drawTreeViewItemIcon(p, iconRect, vopt->icon, bSelected && (vopt->state & State_HasFocus));
    }

    QFont f;
    Utils::StyleHelper::fontNormal(f);

    QFont fontCount;
    Utils::StyleHelper::fontExtend(fontCount);

    QRect rcText = subElementRect(SE_ItemViewItemText, vopt, view);
    rcText.adjust(nLeftMargin * 2, 0, nLeftMargin * 2, 0);
    QString strCount = pItem->countString();

    QString strText = vopt->text;
    if (!strText.isEmpty()) {
        QColor colorText = Utils::StyleHelper::treeViewItemText(bSelected && (vopt->state & State_HasFocus));

        p->setPen(colorText);
        int right = Utils::StyleHelper::drawSingleLineText(p, rcText, strText, Qt::AlignVCenter, colorText, f);
        //
        rcText.setLeft(right + 4);
    }

    if (!strCount.isEmpty()) {
        QRect rcCount = rcText;
        rcCount.setTop(rcCount.top() + 1);  //add extra 1 pixel for vcenter / 2
        QColor colorCount = Utils::StyleHelper::treeViewItemTextExtend(bSelected && (vopt->state & State_HasFocus));
        Utils::StyleHelper::drawSingleLineText(p, rcCount, strCount, Qt::AlignVCenter, colorCount, fontCount);
    }

    p->restore();

    // FIXME: this is used for drawing additional badge, please merge it.
    view->categoryItemFromIndex(vopt->index)->draw(p, vopt);
}
void CWizNoteStyle::drawCategoryViewItem(const QStyleOptionViewItemV4 *vopt,
                                         QPainter *p, const CWizCategoryBaseView *view) const
{
    CWizCategoryViewItemBase* pItem = view->categoryItemFromIndex(vopt->index);

    if (view->isHelperItemByIndex(vopt->index)) {
        if (NULL != dynamic_cast<const CWizCategoryViewSectionItem*>(pItem)) {
            QString str = vopt->text;
            QRect rc(vopt->rect);
            rc.setTop(rc.top() + 12);
            Utils::StyleHelper::drawSingleLineText(p, rc, str, Qt::AlignVCenter, Utils::StyleHelper::treeViewItemCategoryText(), p->font());
        }
        else if (NULL != dynamic_cast<const CWizCategoryViewLinkItem*>(pItem)) {
            QString str = vopt->text;
            QRect rc(vopt->rect);
            rc.setLeft(rc.left() + 16);
            Utils::StyleHelper::drawSingleLineText(p, rc, str, Qt::AlignVCenter, Utils::StyleHelper::treeViewItemLinkText(), m_fontLink);
        }

        return;
    }

    p->save();

    bool bSelected = vopt->state.testFlag(State_Selected);

    if (!vopt->icon.isNull()) {
        QRect iconRect = subElementRect(SE_ItemViewItemDecoration, vopt, view);
        Utils::StyleHelper::drawTreeViewItemIcon(p, iconRect, vopt->icon, bSelected);
    }

    QFont f;
    Utils::StyleHelper::fontNormal(f);

    QFont fontCount;
    Utils::StyleHelper::fontExtend(fontCount);

    QRect rcText = subElementRect(SE_ItemViewItemText, vopt, view);
    QString strCount = pItem->countString();

    QString strText = vopt->text;
    if (!strText.isEmpty()) {
        QColor colorText = Utils::StyleHelper::treeViewItemText(bSelected);

        p->setPen(colorText);
        int right = Utils::StyleHelper::drawSingleLineText(p, rcText, strText, Qt::AlignVCenter, colorText, f);
        //
        rcText.setLeft(right + 4);
    }

    if (!strCount.isEmpty()) {
        QRect rcCount = rcText;
        rcCount.setTop(rcCount.top() + 1);  //add extra 1 pixel for vcenter / 2
        QColor colorCount = Utils::StyleHelper::treeViewItemTextExtend(bSelected);
        Utils::StyleHelper::drawSingleLineText(p, rcCount, strCount, Qt::AlignVCenter, colorCount, fontCount);
    }

    p->restore();

    // FIXME: this is used for drawing additional badge, please merge it.
    view->categoryItemFromIndex(vopt->index)->draw(p, vopt);
}