File indexing completed on 2024-05-05 04:35:18

0001 /* This file is part of the TikZKit project.
0002  *
0003  * Copyright (C) 2013 Dominik Haumann <dhaumann@kde.org>
0004  *
0005  * This library is free software; you can redistribute it and/or modify
0006  * it under the terms of the GNU Library General Public License as published
0007  * by the Free Software Foundation, either version 2 of the License, or
0008  * (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
0013  * GNU 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, see
0017  * <http://www.gnu.org/licenses/>.
0018  */
0019 
0020 #include "NodeText.h"
0021 #include "NodeText_p.h"
0022 #include "NodeItem.h"
0023 
0024 #include <QPainter>
0025 #include <QPixmap>
0026 #include <QStyleOptionGraphicsItem>
0027 
0028 #include <QDebug>
0029 
0030 namespace tikz {
0031 namespace ui {
0032 
0033 NodeText::NodeText(NodeItem* node)
0034     : QGraphicsItem(node)
0035     , d(new NodeTextPrivate(node, this))
0036 {
0037     setFlag(QGraphicsItem::ItemIsMovable, false);
0038     setFlag(QGraphicsItem::ItemIsSelectable, false);
0039 
0040     QObject::connect(node->node(), SIGNAL(textChanged(QString)), &d->texGenerator, SLOT(generateImage(QString)));
0041 }
0042 
0043 NodeText::~NodeText()
0044 {
0045     delete d;
0046 }
0047 
0048 QRectF NodeText::boundingRect() const
0049 {
0050     return textRect().adjusted(-0.1, -0.1, 0.1, 0.1);
0051 }
0052 
0053 void NodeText::paint(QPainter *painter, const QStyleOptionGraphicsItem * option, QWidget * widget)
0054 {
0055     Q_UNUSED(option)
0056     Q_UNUSED(widget)
0057 
0058     painter->save();
0059     painter->scale(1.0, -1.0);
0060 //     painter->drawRect(textRect());
0061     d->svgRenderer.render(painter, textRect());
0062 
0063     painter->restore();
0064 }
0065 
0066 QRectF NodeText::textRect() const
0067 {
0068     if (d->svgRenderer.isValid()) {
0069         QRectF rect = d->svgRenderer.viewBoxF();
0070         rect.setSize(QSizeF(rect.width(), rect.height()));
0071         rect.moveCenter(QPointF(0.0, 0.0));
0072         return rect;
0073     } else {
0074         return QRectF(0.0, 0.0, 0.0, 0.0);
0075     }
0076 }
0077 
0078 }
0079 }
0080 
0081 // kate: indent-width 4; replace-tabs on;