Warning, file /office/calligra/libs/widgets/KoMarkerItemDelegate.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /* This file is part of the KDE project
0002  * Copyright (C) 2011 Thorsten Zachmann <zachmann@kde.org>
0003  * Copyright (C) 2011 Jean-Nicolas Artaud <jeannicolasartaud@gmail.com>
0004  *
0005  * This library is free software; you can redistribute it and/or
0006  * modify it under the terms of the GNU Library General Public
0007  * License as published by the Free Software Foundation; either
0008  * version 2 of the License, or (at your option) any later version.
0009  *
0010  * This library is distributed in the hope that it will be useful,
0011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0013  * Library General Public License for more details.
0014  *
0015  * You should have received a copy of the GNU Library General Public License
0016  * along with this library; see the file COPYING.LIB.  If not, write to
0017  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0018  * Boston, MA 02110-1301, USA.
0019  */
0020 
0021 #include "KoMarkerItemDelegate.h"
0022 
0023 #include <KoPathShape.h>
0024 #include <KoMarker.h>
0025 
0026 #include <QPainter>
0027 #include <QPainterPath>
0028 #include <QPen>
0029 
0030 KoMarkerItemDelegate::KoMarkerItemDelegate(KoMarkerData::MarkerPosition position, QObject *parent)
0031 : QAbstractItemDelegate(parent)
0032 , m_position(position)
0033 {
0034 }
0035 
0036 void KoMarkerItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
0037 {
0038     painter->save();
0039 
0040     if (option.state & QStyle::State_Selected)
0041         painter->fillRect(option.rect, option.palette.highlight());
0042 
0043     bool antialiasing = painter->testRenderHint(QPainter::Antialiasing);
0044     if (!antialiasing) {
0045         painter->setRenderHint(QPainter::Antialiasing, true);
0046     }
0047 
0048     KoPathShape pathShape;
0049     pathShape.moveTo(QPointF(option.rect.left(), option.rect.center().y()));
0050     pathShape.lineTo(QPointF(option.rect.right(), option.rect.center().y()));
0051     KoMarker *marker = index.data(Qt::DecorationRole).value<KoMarker*>();
0052     if (marker != nullptr) {
0053         pathShape.setMarker(marker, m_position);
0054     }
0055 
0056     // paint marker
0057     QPen pen(option.palette.text(), 2);
0058     QPainterPath path = pathShape.pathStroke(pen);
0059     painter->fillPath(path, pen.brush());
0060 
0061     if (!antialiasing) {
0062         painter->setRenderHint(QPainter::Antialiasing, false);
0063     }
0064 
0065     painter->restore();
0066 }
0067 
0068 QSize KoMarkerItemDelegate::sizeHint(const QStyleOptionViewItem & option, const QModelIndex &index) const
0069 {
0070     Q_UNUSED(option)
0071     Q_UNUSED(index)
0072     return QSize(80,30);
0073 }