1 /*******************************************************************
2
3 Part of the Fritzing project - http://fritzing.org
4 Copyright (c) 2007-2014 Fachhochschule Potsdam - http://fh-potsdam.de
5
6 Fritzing is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
10
11 Fritzing is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with Fritzing. If not, see <http://www.gnu.org/licenses/>.
18
19 ********************************************************************
20
21 $Revision: 6904 $:
22 $Author: irascibl@gmail.com $:
23 $Date: 2013-02-26 16:26:03 +0100 (Di, 26. Feb 2013) $
24
25 ********************************************************************/
26
27 #include "pesvgview.h"
28 #include "pegraphicsitem.h"
29 #include "peutils.h"
30 #include "../utils/textutils.h"
31 #include "../utils/graphicsutils.h"
32 #include "../debugdialog.h"
33
34 #include <QHBoxLayout>
35 #include <QTextStream>
36 #include <QSplitter>
37 #include <QPushButton>
38 #include <QLineEdit>
39 #include <QFile>
40
41 //////////////////////////////////////
42
43
PESvgView(QWidget * parent)44 PESvgView::PESvgView(QWidget * parent) : QFrame(parent)
45 {
46 this->setObjectName("peSVG");
47
48 m_pegi = NULL;
49
50 QVBoxLayout * mainLayout = new QVBoxLayout;
51
52 m_filename = new QLabel();
53 mainLayout->addWidget(m_filename);
54
55 QFrame * boundsFrame = new QFrame;
56 QHBoxLayout * boundsLayout = new QHBoxLayout;
57
58 QLabel * label = new QLabel("x:");
59 boundsLayout->addWidget(label);
60 m_x = new QLabel;
61 boundsLayout->addWidget(m_x);
62 boundsLayout->addSpacing(PEUtils::Spacing);
63
64 label = new QLabel("y:");
65 boundsLayout->addWidget(label);
66 m_y = new QLabel;
67 boundsLayout->addWidget(m_y);
68 boundsLayout->addSpacing(PEUtils::Spacing);
69
70 label = new QLabel(tr("width:"));
71 boundsLayout->addWidget(label);
72 m_width = new QLabel;
73 boundsLayout->addWidget(m_width);
74 boundsLayout->addSpacing(PEUtils::Spacing);
75
76 label = new QLabel(tr("height:"));
77 boundsLayout->addWidget(label);
78 m_height = new QLabel;
79 boundsLayout->addWidget(m_height);
80 boundsLayout->addSpacing(PEUtils::Spacing);
81
82 m_units = new QLabel();
83 boundsLayout->addWidget(m_units);
84
85 boundsLayout->addSpacerItem(new QSpacerItem(1, 1, QSizePolicy::Expanding));
86 boundsFrame->setLayout(boundsLayout);
87 mainLayout->addWidget(boundsFrame);
88
89 m_svgElement = new QLabel;
90 m_svgElement->setWordWrap(false);
91 m_svgElement->setTextFormat(Qt::PlainText);
92 mainLayout->addWidget(m_svgElement);
93
94 mainLayout->addSpacerItem(new QSpacerItem(1, 1, QSizePolicy::Minimum, QSizePolicy::Expanding));
95
96 //this->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
97
98 this->setLayout(mainLayout);
99
100
101 }
102
~PESvgView()103 PESvgView::~PESvgView()
104 {
105 }
106
highlightElement(PEGraphicsItem * pegi)107 void PESvgView::highlightElement(PEGraphicsItem * pegi) {
108 m_pegi = pegi;
109 if (pegi == NULL) {
110 m_svgElement->setText("");
111 m_x->setText("");
112 m_y->setText("");
113 m_width->setText("");
114 m_height->setText("");
115 return;
116 }
117
118 QString string;
119 QTextStream stream(&string);
120 pegi->element().save(stream, 0);
121 string = TextUtils::killXMLNS(string);
122 int ix = string.indexOf("\n");
123 if (ix > 0) {
124 int jx = string.indexOf("\n", ix + 1);
125 if (jx >= 0) {
126 string.truncate(jx - 1);
127 }
128 else {
129 string.truncate(ix + 200);
130 }
131 }
132 else {
133 string.truncate(200);
134 }
135
136 m_svgElement->setText(string);
137 QPointF p = pegi->offset();
138 m_x->setText(PEUtils::convertUnitsStr(p.x()));
139 m_y->setText(PEUtils::convertUnitsStr(p.y()));
140 QRectF r = pegi->rect();
141 m_width->setText(PEUtils::convertUnitsStr(r.width()));
142 m_height->setText(PEUtils::convertUnitsStr(r.height()));
143 m_units->setText(QString("(%1)").arg(PEUtils::Units));
144
145 }
146
setChildrenVisible(bool vis)147 void PESvgView::setChildrenVisible(bool vis)
148 {
149 foreach (QWidget * widget, findChildren<QWidget *>()) {
150 widget->setVisible(vis);
151 }
152 }
153
setFilename(const QString & filename)154 void PESvgView::setFilename(const QString & filename) {
155 m_filename->setText(filename);
156 }
157