File indexing completed on 2024-05-12 16:33:44
0001 /* This file is part of the KDE project 0002 * Copyright (C) 2010 Carlos Licea <carlos@kdab.com> 0003 * 0004 * This library is free software; you can redistribute it and/or 0005 * modify it under the terms of the GNU Library General Public 0006 * License as published by the Free Software Foundation; either 0007 * version 2 of the License, or (at your option) any later version. 0008 * 0009 * This library is distributed in the hope that it will be useful, 0010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0012 * Library General Public License for more details. 0013 * 0014 * You should have received a copy of the GNU Library General Public License 0015 * along with this library; see the file COPYING.LIB. If not, write to 0016 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0017 * Boston, MA 02110-1301, USA. 0018 */ 0019 0020 #include "InitialsCommentShape.h" 0021 #include "Globals.h" 0022 0023 #include <QPainter> 0024 0025 InitialsCommentShape::InitialsCommentShape() 0026 : KoShape() 0027 , m_active(true) 0028 { 0029 } 0030 0031 InitialsCommentShape::~InitialsCommentShape() 0032 { 0033 } 0034 0035 void InitialsCommentShape::saveOdf(KoShapeSavingContext& /*context*/) const 0036 { 0037 } 0038 0039 bool InitialsCommentShape::loadOdf(const KoXmlElement& /*element*/, KoShapeLoadingContext& /*context*/) 0040 { 0041 return false; 0042 } 0043 0044 void InitialsCommentShape::paint(QPainter& painter, const KoViewConverter& converter, KoShapePaintingContext &) 0045 { 0046 applyConversion(painter, converter); 0047 0048 QLinearGradient gradient(initialsBoxPoint, QPointF(0, initialsBoxSize.height())); 0049 qreal lighterPos = 0.0; 0050 qreal darkerPos = 0.0; 0051 if(!m_active){ 0052 darkerPos = 1.0; 0053 } 0054 else { 0055 lighterPos = 1.0; 0056 } 0057 gradient.setColorAt(lighterPos, QColor(Qt::yellow)); 0058 gradient.setColorAt(darkerPos, QColor(254, 201, 7)); 0059 const QBrush brush(gradient); 0060 painter.setBrush(brush); 0061 0062 painter.setPen(QPen(Qt::black, 0)); 0063 0064 painter.drawRect(QRectF(initialsBoxPoint, initialsBoxSize)); 0065 0066 painter.drawText(QRectF(initialsBoxPoint, initialsBoxSize), Qt::AlignCenter, m_initials); 0067 } 0068 0069 void InitialsCommentShape::setInitials(const QString &initials) 0070 { 0071 m_initials = initials; 0072 } 0073 0074 QString InitialsCommentShape::initials() 0075 { 0076 return m_initials; 0077 0078 } 0079 0080 bool InitialsCommentShape::isActive() const 0081 { 0082 return m_active; 0083 } 0084 0085 void InitialsCommentShape::setActive(bool activate) 0086 { 0087 m_active = activate; 0088 } 0089 0090 void InitialsCommentShape::toogleActive() 0091 { 0092 setActive(!m_active); 0093 update(); 0094 } 0095