~ubuntu-branches/ubuntu/precise/fritzing/precise

« back to all changes in this revision

Viewing changes to src/fsvgrenderer.h

  • Committer: Bazaar Package Importer
  • Author(s): Georges Khaznadar
  • Date: 2011-08-26 10:11:05 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20110826101105-w5hmn7zcf93ig5v6
Tags: 0.6.3b-1
* upgrapded to the newer upstream version
* parameters of the function GraphicsUtils::distanceFromLine in 
  src/svg/groundplanegenerator.cpp:767 are now declared as doubles,
  which Closes: #636441
* the new version fixes src/utils/folderutils.cpp, which
  Closes: #636061

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*******************************************************************
2
 
 
3
 
Part of the Fritzing project - http://fritzing.org
4
 
Copyright (c) 2007-2010 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: 4214 $:
22
 
$Author: cohen@irascible.com $:
23
 
$Date: 2010-06-04 19:50:59 +0200 (Fri, 04 Jun 2010) $
24
 
 
25
 
********************************************************************/
26
 
 
27
 
#ifndef FSVGRENDERER_H
28
 
#define FSVGRENDERER_H
29
 
 
30
 
#include <QHash>
31
 
#include <QSvgRenderer>
32
 
#include <QXmlStreamReader>
33
 
#include <QDomDocument>
34
 
#include <QMatrix>
35
 
#include <QStringList>
36
 
 
37
 
#include "viewlayer.h"
38
 
 
39
 
struct ConnectorInfo {
40
 
        qreal radius;
41
 
        qreal strokeWidth;
42
 
        QMatrix matrix;
43
 
        QRectF bounds;
44
 
        QMatrix terminalMatrix;
45
 
        bool gotCircle;
46
 
};
47
 
 
48
 
typedef QHash<ViewLayer::ViewLayerID, class FSvgRenderer *> RendererHash;
49
 
 
50
 
class FSvgRenderer : public QSvgRenderer
51
 
{
52
 
public:
53
 
        FSvgRenderer(QObject * parent = 0);
54
 
        ~FSvgRenderer();
55
 
 
56
 
        bool loadSvg(const QString & filename, const QStringList & connectorIDs, const QStringList & terminalIDs, const QString & setColor, const QString & colorElementID, bool findNonConnectors);
57
 
        bool loadSvg(const QString & filename);
58
 
        bool loadSvg( const QByteArray & contents, const QString & filename, const QStringList & connectorNames, const QStringList & terminalNames, const QString & setColor, const QString & colorElementID, bool findNonConnectors);     // for SvgSplitter loads
59
 
        bool loadSvg( const QByteArray & contents, const QString & filename);                                           // for SvgSplitter loads
60
 
        bool fastLoad(const QByteArray & contents);                                                             
61
 
        const QString & filename();
62
 
        QSizeF defaultSizeF();
63
 
        bool setUpConnector(struct SvgIdLayer * svgIdLayer, bool ignoreTerminalPoint);
64
 
        QList<SvgIdLayer *> setUpNonConnectors();
65
 
 
66
 
public:
67
 
        static void set(const QString & moduleID, ViewLayer::ViewLayerID, FSvgRenderer *);
68
 
        static FSvgRenderer * getByModuleID(const QString & moduleID, ViewLayer::ViewLayerID);
69
 
        static FSvgRenderer * getByFilename(const QString & filename, ViewLayer::ViewLayerID);
70
 
        static QPixmap * getPixmap(const QString & moduleID, ViewLayer::ViewLayerID viewLayerID, QSize size);
71
 
        static void calcPrinterScale();
72
 
        static qreal printerScale();
73
 
        static void cleanup();
74
 
        static QSizeF parseForWidthAndHeight(QXmlStreamReader &);
75
 
        static void removeFromHash(const QString &moduleId, const QString filename);
76
 
 
77
 
protected:
78
 
        void determineDefaultSize(QXmlStreamReader &);
79
 
        bool loadAux (const QByteArray & contents, const QString & filename, const QStringList & connectorNames, const QStringList & terminalNames, const QString & setColor, const QString & colorElementID, bool findNonConnectors);
80
 
        void initConnectorInfo(QDomDocument &, const QStringList & connectorIDs, const QStringList & terminalIDs);
81
 
        ConnectorInfo * initConnectorInfo(QDomElement & connectorElement);
82
 
        bool initConnectorInfoAux(QList<QDomElement> & connectorElements, ConnectorInfo * connectorInfo);
83
 
        void initNonConnectorInfo(QDomDocument & domDocument);
84
 
        void initNonConnectorInfoAux(QDomElement & element);
85
 
        void initTerminalInfoAux(QDomElement & element, const QStringList & connectorIDs, const QStringList & terminalIDs);
86
 
        void initConnectorInfoAux(QDomElement & element, const QStringList & connectorIDs);
87
 
        QPointF calcTerminalPoint(const QString & terminalId, const QRectF & connectorRect, bool ignoreTerminalPoint, const QRectF & viewBox, QMatrix & terminalMatrix, bool useF);
88
 
        ConnectorInfo * getConnectorInfo(const QString & connectorID);
89
 
        void clearConnectorInfoHash(QHash<QString, ConnectorInfo *> & hash);
90
 
 
91
 
protected:
92
 
        QString m_filename;
93
 
        QSizeF m_defaultSizeF;
94
 
        QHash<QString, ConnectorInfo *> m_connectorInfoHash;
95
 
        QHash<QString, ConnectorInfo *> m_nonConnectorInfoHash;
96
 
 
97
 
protected:
98
 
        static qreal m_printerScale;
99
 
        static QHash<QString, RendererHash * > m_filenameRendererHash;
100
 
        static QHash<QString, RendererHash * > m_moduleIDRendererHash;
101
 
        static QSet<RendererHash *> m_deleted;
102
 
 
103
 
public:
104
 
        static QString NonConnectorName;
105
 
 
106
 
};
107
 
 
108
 
 
109
 
#endif
 
1
/*******************************************************************
 
2
 
 
3
Part of the Fritzing project - http://fritzing.org
 
4
Copyright (c) 2007-2011 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: 5309 $:
 
22
$Author: cohen@irascible.com $:
 
23
$Date: 2011-07-30 21:17:22 +0200 (Sat, 30 Jul 2011) $
 
24
 
 
25
********************************************************************/
 
26
 
 
27
#ifndef FSVGRENDERER_H
 
28
#define FSVGRENDERER_H
 
29
 
 
30
#include <QHash>
 
31
#include <QSvgRenderer>
 
32
#include <QXmlStreamReader>
 
33
#include <QDomDocument>
 
34
#include <QMatrix>
 
35
#include <QStringList>
 
36
 
 
37
#include "viewlayer.h"
 
38
 
 
39
struct ConnectorInfo {
 
40
        bool gotCircle;
 
41
        double radius;
 
42
        double strokeWidth;
 
43
        QMatrix matrix;
 
44
        QRectF bounds;
 
45
        QMatrix terminalMatrix;
 
46
        QMatrix legMatrix;
 
47
        QString legColor;
 
48
        QLineF legLine;
 
49
        double legStrokeWidth;
 
50
};
 
51
 
 
52
typedef QHash<ViewLayer::ViewLayerID, class FSvgRenderer *> RendererHash;
 
53
 
 
54
class FSvgRenderer : public QSvgRenderer
 
55
{
 
56
public:
 
57
        FSvgRenderer(QObject * parent = 0);
 
58
        ~FSvgRenderer();
 
59
 
 
60
        QByteArray loadSvg(const QString & filename, const QStringList & connectorIDs, const QStringList & terminalIDs, const QStringList & legIDs, const QString & setColor, const QString & colorElementID, bool findNonConnectors);
 
61
        QByteArray loadSvg(const QString & filename);
 
62
        QByteArray loadSvg( const QByteArray & contents, const QString & filename, const QStringList & connectorIDs, const QStringList & terminalIDs, const QStringList & legIDs, const QString & setColor, const QString & colorElementID, bool findNonConnectors);     // for SvgSplitter loads
 
63
        QByteArray loadSvg( const QByteArray & contents, const QString & filename);                                             // for SvgSplitter loads
 
64
        bool fastLoad(const QByteArray & contents);                                                             
 
65
        const QString & filename();
 
66
        QSizeF defaultSizeF();
 
67
        bool setUpConnector(struct SvgIdLayer * svgIdLayer, bool ignoreTerminalPoint);
 
68
        QList<SvgIdLayer *> setUpNonConnectors();
 
69
 
 
70
public:
 
71
        static void set(const QString & moduleID, ViewLayer::ViewLayerID, FSvgRenderer *);
 
72
        static FSvgRenderer * getByModuleID(const QString & moduleID, ViewLayer::ViewLayerID);
 
73
        static FSvgRenderer * getByFilename(const QString & filename, ViewLayer::ViewLayerID);
 
74
        static QPixmap * getPixmap(const QString & moduleID, ViewLayer::ViewLayerID viewLayerID, QSize size);
 
75
        static void calcPrinterScale();
 
76
        static double printerScale();
 
77
        static void cleanup();
 
78
        static QSizeF parseForWidthAndHeight(QXmlStreamReader &);
 
79
        static void removeFromHash(const QString &moduleId, const QString filename);
 
80
 
 
81
protected:
 
82
        void determineDefaultSize(QXmlStreamReader &);
 
83
        QByteArray loadAux (const QByteArray & contents, const QString & filename, const QStringList & connectorIDs, const QStringList & terminalIDs, const QStringList & legIDs, const QString & setColor, const QString & colorElementID, bool findNonConnectors);
 
84
        bool initConnectorInfo(QDomDocument &, const QStringList & connectorIDs, const QStringList & terminalIDs, const QStringList & legIDs);
 
85
        ConnectorInfo * initConnectorInfo(QDomElement & connectorElement);
 
86
        bool initConnectorInfoAux(QList<QDomElement> & connectorElements, ConnectorInfo * connectorInfo);
 
87
        void initNonConnectorInfo(QDomDocument & domDocument);
 
88
        void initNonConnectorInfoAux(QDomElement & element);
 
89
        void initTerminalInfoAux(QDomElement & element, const QStringList & connectorIDs, const QStringList & terminalIDs);
 
90
        void initLegInfoAux(QDomElement & element, const QStringList & connectorIDs, const QStringList & legIDs, bool & gotOne);
 
91
        void initConnectorInfoAux(QDomElement & element, const QStringList & connectorIDs);
 
92
        QPointF calcTerminalPoint(const QString & terminalId, const QRectF & connectorRect, bool ignoreTerminalPoint, const QRectF & viewBox, QMatrix & terminalMatrix);
 
93
        bool initLegInfoAux(QDomElement & element, ConnectorInfo * connectorInfo);
 
94
        void calcLeg(SvgIdLayer *, const QRectF & viewBox, ConnectorInfo * connectorInfo);
 
95
        ConnectorInfo * getConnectorInfo(const QString & connectorID);
 
96
        void clearConnectorInfoHash(QHash<QString, ConnectorInfo *> & hash);
 
97
 
 
98
protected:
 
99
        QString m_filename;
 
100
        QSizeF m_defaultSizeF;
 
101
        QHash<QString, ConnectorInfo *> m_connectorInfoHash;
 
102
        QHash<QString, ConnectorInfo *> m_nonConnectorInfoHash;
 
103
 
 
104
protected:
 
105
        static double m_printerScale;
 
106
        static QHash<QString, RendererHash * > m_filenameRendererHash;
 
107
        static QHash<QString, RendererHash * > m_moduleIDRendererHash;
 
108
        static QSet<RendererHash *> m_deleted;
 
109
 
 
110
public:
 
111
        static QString NonConnectorName;
 
112
 
 
113
};
 
114
 
 
115
 
 
116
#endif