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: 6984 $: 22 $Author: irascibl@gmail.com $: 23 $Date: 2013-04-22 23:44:56 +0200 (Mo, 22. Apr 2013) $ 24 25 ********************************************************************/ 26 27 #ifndef RESIZABLEBOARD_H 28 #define RESIZABLEBOARD_H 29 30 #include <QRectF> 31 #include <QPainterPath> 32 #include <QPixmap> 33 #include <QVariant> 34 #include <QLineEdit> 35 #include <QCursor> 36 #include <QLabel> 37 #include <QCheckBox> 38 #include <QComboBox> 39 #include <QPushButton> 40 41 #include "paletteitem.h" 42 43 class Board : public PaletteItem 44 { 45 Q_OBJECT 46 47 public: 48 // after calling this constructor if you want to render the loaded svg (either from model or from file), MUST call <renderImage> 49 Board(ModelPart *, ViewLayer::ViewID, const ViewGeometry & viewGeometry, long id, QMenu * itemMenu, bool doLabel); 50 ~Board(); 51 52 QStringList collectValues(const QString & family, const QString & prop, QString & value); 53 void paintHover(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); 54 bool rotation45Allowed(); 55 bool stickyEnabled(); 56 PluralType isPlural(); 57 bool canFindConnectorsUnder(); 58 bool collectExtraInfo(QWidget * parent, const QString & family, const QString & prop, const QString & value, bool swappingEnabled, QString & returnProp, QString & returnValue, QWidget * & returnWidget, bool & hide); 59 60 protected: 61 void setupLoadImage(QWidget * parent, const QString & family, const QString & prop, const QString & value, bool swappingEnabled, QString & returnProp, QString & returnValue, QWidget * & returnWidget); 62 void setFileNameItems(); 63 virtual QStringList & getImageNames(); 64 virtual QStringList & getNewImageNames(); 65 virtual bool checkImage(const QString & filename); 66 void unableToLoad(const QString & fileName, const QString & reason); 67 bool canLoad(const QString & fileName, const QString & reason); 68 virtual void prepLoadImageAux(const QString & fileName, bool addName); 69 ViewLayer::ViewID useViewIDForPixmap(ViewLayer::ViewID, bool swappingEnabled); 70 71 protected: 72 static void moreCheckImage(const QString & filename); 73 static QString setBoardOutline(const QString & svg); 74 75 public: 76 static QString OneLayerTranslated; 77 static QString TwoLayersTranslated; 78 79 public: 80 static bool isBoard(ItemBase *); 81 static bool isBoard(ModelPart *); 82 static QString convertToXmlName(const QString &); 83 static QString convertFromXmlName(const QString &); 84 85 protected slots: 86 void prepLoadImage(); 87 void fileNameEntry(const QString & filename); 88 89 protected: 90 QPointer<QComboBox> m_fileNameComboBox; 91 bool m_svgOnly; 92 93 protected: 94 static QStringList BoardImageNames; 95 static QStringList NewBoardImageNames; 96 }; 97 98 class ResizableBoard : public Board 99 { 100 Q_OBJECT 101 102 public: 103 // after calling this constructor if you want to render the loaded svg (either from model or from file), MUST call <renderImage> 104 ResizableBoard(ModelPart *, ViewLayer::ViewID, const ViewGeometry & viewGeometry, long id, QMenu * itemMenu, bool doLabel); 105 ~ResizableBoard(); 106 107 virtual bool resizeMM(double w, double h, const LayerHash & viewLayers); 108 void resizePixels(double w, double h, const LayerHash & viewLayers); 109 void loadLayerKin(const LayerHash & viewLayers, ViewLayer::ViewLayerPlacement); 110 virtual void setInitialSize(); 111 QString retrieveSvg(ViewLayer::ViewLayerID, QHash<QString, QString> & svgHash, bool blackOnly, double dpi, double & factor); 112 bool collectExtraInfo(QWidget * parent, const QString & family, const QString & prop, const QString & value, bool swappingEnabled, QString & returnProp, QString & returnValue, QWidget * & returnWidget, bool & hide); 113 void saveParams(); 114 void getParams(QPointF &, QSizeF &); 115 bool hasCustomSVG(); 116 QSizeF getSizeMM(); 117 void addedToScene(bool temporary); 118 bool hasPartNumberProperty(); 119 void paintSelected(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); 120 bool inResize(); 121 void figureHover(); 122 123 public slots: 124 virtual void widthEntry(); 125 virtual void heightEntry(); 126 void keepAspectRatio(bool checkState); 127 void revertSize(bool); 128 virtual void paperSizeChanged(int); 129 130 protected: 131 enum Corner { 132 NO_CORNER = 0, 133 TOP_LEFT , 134 TOP_RIGHT, 135 BOTTOM_LEFT, 136 BOTTOM_RIGHT 137 }; 138 139 protected: 140 void mousePressEvent(QGraphicsSceneMouseEvent * event ); 141 void mouseMoveEvent(QGraphicsSceneMouseEvent * event ); 142 void mouseReleaseEvent(QGraphicsSceneMouseEvent * event ); 143 void hoverEnterEvent(QGraphicsSceneHoverEvent * event ); 144 void hoverLeaveEvent(QGraphicsSceneHoverEvent * event ); 145 void hoverMoveEvent(QGraphicsSceneHoverEvent * event ); 146 QString makeBoardSvg(double mmW, double mmH, double milsW, double milsH); 147 QString makeSilkscreenSvg(ViewLayer::ViewLayerID, double mmW, double mmH, double milsW, double milsH); 148 QString makeSvg(double mmW, double mmH, const QString & layerTemplate); 149 QStringList collectValues(const QString & family, const QString & prop, QString & value); 150 virtual void loadTemplates(); 151 virtual double minWidth(); 152 virtual double minHeight(); 153 virtual ViewLayer::ViewID theViewID(); 154 virtual QString makeLayerSvg(ViewLayer::ViewLayerID viewLayerID, double mmW, double mmH, double milsW, double milsH); 155 virtual QString makeFirstLayerSvg(double mmW, double mmH, double milsW, double milsH); 156 virtual QString makeNextLayerSvg(ViewLayer::ViewLayerID, double mmW, double mmH, double milsW, double milsH); 157 virtual void resizeMMAux(double w, double h); 158 virtual ResizableBoard::Corner findCorner(QPointF p, Qt::KeyboardModifiers); 159 void setKinCursor(QCursor &); 160 void setKinCursor(Qt::CursorShape); 161 QFrame * setUpDimEntry(bool includeAspectRatio, bool includeRevert, bool includePaperSizes, QWidget * & returnWidget); 162 void fixWH(); 163 void setWidthAndHeight(double w, double h); 164 QString getShapeForRenderer(const QString & svg, ViewLayer::ViewLayerID viewLayerID); 165 void initPaperSizes(); 166 void updatePaperSizes(double width, double height); 167 168 protected: 169 static const double CornerHandleSize; 170 171 Corner m_corner; 172 QSizeF m_boardSize; 173 QPointF m_boardPos; 174 QPointer<QLineEdit> m_widthEditor; 175 QPointer<QLineEdit> m_heightEditor; 176 bool m_keepAspectRatio; 177 QSizeF m_aspectRatio; 178 double m_currentScale; 179 QPointer<QCheckBox> m_aspectRatioCheck; 180 QPointer<QLabel> m_aspectRatioLabel; 181 QPointer<QPushButton> m_revertButton; 182 QPointer<QComboBox> m_paperSizeComboBox; 183 184 QPointF m_resizeMousePos; 185 QSizeF m_resizeStartSize; 186 QPointF m_resizeStartPos; 187 QPointF m_resizeStartTopLeft; 188 QPointF m_resizeStartBottomRight; 189 QPointF m_resizeStartTopRight; 190 QPointF m_resizeStartBottomLeft; 191 int m_decimalsAfter; 192 193 }; 194 195 #endif 196