SciFigs/GraphicObject.h
Go to the documentation of this file.
00001 /***************************************************************************
00002 **
00003 **  This file is part of SciFigs.
00004 **
00005 **  This library is free software; you can redistribute it and/or
00006 **  modify it under the terms of the GNU Lesser General Public
00007 **  License as published by the Free Software Foundation; either
00008 **  version 2.1 of the License, or (at your option) any later version.
00009 **
00010 **  This file is distributed in the hope that it will be useful, but WITHOUT
00011 **  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00012 **  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
00013 **  License for more details.
00014 **
00015 **  You should have received a copy of the GNU Lesser General Public
00016 **  License along with this library; if not, write to the Free Software
00017 **  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00018 **
00019 **  See http://www.geopsy.org for more information.
00020 **
00021 **  Created : 2003-07-31
00022 **  Authors :
00023 **    Marc Wathelet
00024 **    Marc Wathelet (ULg, Liège, Belgium)
00025 **    Marc Wathelet (LGIT, Grenoble, France)
00026 **
00027 ***************************************************************************/
00028 
00029 #ifndef GRAPHICOBJECT_H
00030 #define GRAPHICOBJECT_H
00031 
00032 #include <QtGui>
00033 #include <QGpGuiTools.h>
00034 
00035 #include "SciFigsDLLExport.h"
00036 
00037 namespace SciFigs {
00038 
00039 #define MIN_RESOLUTION 16
00040 #define MAX_RESOLUTION 1200
00041 
00042 class SelectionWidget;
00043 class GraphicSheet;
00044 class OrderTip;
00045 class GraphicObjectIdProperties;
00046 class GraphicObjectGeometryProperties;
00047 class GraphicObjectPrintProperties;
00048 
00049 class SCIFIGS_EXPORT GraphicObject : public QWidget, public PropertyContext, public PropertyItem, public XMLClass
00050 {
00051   Q_OBJECT
00052   // Overload to mark the beginning of properties to save to XML
00053   Q_PROPERTY(QString objectName READ objectName WRITE setObjectName STORED true)
00054   // Kept only to avoid warning on loading old files
00055   Q_PROPERTY(QString name READ dummyPropertyString WRITE setObjectName STORED false)
00056 
00057   Q_PROPERTY(double printX READ printXAnchor WRITE setPrintXAnchor SCRIPTABLE true)
00058   Q_PROPERTY(double printY READ printYAnchor WRITE setPrintYAnchor SCRIPTABLE true)
00059   Q_PROPERTY(QString anchor READ anchorString WRITE setAnchor SCRIPTABLE true)
00060   Q_PROPERTY(double printWidth READ printWidth WRITE setPrintWidth SCRIPTABLE true)
00061   Q_PROPERTY(double printHeight READ printHeight WRITE setPrintHeight SCRIPTABLE true)
00062   Q_PROPERTY(bool constantWidthHeightRatio READ constantWidthHeightRatio WRITE setConstantWidthHeightRatio SCRIPTABLE true)
00063   Q_PROPERTY(int printResolution READ printResolution WRITE setPrintResolution SCRIPTABLE true)
00064   Q_PROPERTY(int transparency READ transparency WRITE setTransparency SCRIPTABLE true)
00065   Q_PROPERTY(bool transparentMask READ transparentMask WRITE setTransparentMask SCRIPTABLE true)
00066   Q_PROPERTY(double printLeftMargin READ printLeftMargin WRITE setPrintLeftMargin SCRIPTABLE true)
00067   Q_PROPERTY(double printRightMargin READ printRightMargin WRITE setPrintRightMargin SCRIPTABLE true)
00068   Q_PROPERTY(double printTopMargin READ printTopMargin WRITE setPrintTopMargin SCRIPTABLE true)
00069   Q_PROPERTY(double printBottomMargin READ printBottomMargin WRITE setPrintBottomMargin SCRIPTABLE true)
00070   DUMMY_PROPERTIES;
00071 public:
00072   GraphicObject(QWidget * parent=0, Qt::WFlags f=0);
00073   ~GraphicObject();
00074 
00075   virtual const QString& xml_tagName() const {return xmlGraphicObjectTag;}
00076   static const QString xmlGraphicObjectTag;
00077 
00078   GraphicObject& operator=(const GraphicObject& o);
00079   virtual void polish();
00080   virtual QSize sizeHint () const {return QSize(250, 250);}
00081 
00082   // True if normal TopLeft corner
00083   enum PositionAnchor {XMask=1, YMask=2, TopLeft=3, TopRight=2, BottomLeft=1, BottomRight=0};
00084 
00085   virtual void setObjectName(QString name);
00086   double printLeft(double refWidth=0.0) const;
00087   double printTop(double refHeight=0.0) const;
00088   double printRight(double refWidth=0.0) const;
00089   double printBottom(double refHeight=0.0) const;
00090   double printXAnchor() const {return _printAnchor.x();}
00091   double printYAnchor() const {return _printAnchor.y();}
00092   PositionAnchor anchor() const {return _anchor;}
00093   QString anchorString() const;
00094   double printWidth() const {return _printWidth;}
00095   double printHeight() const {return _printHeight;}
00096   bool constantWidthHeightRatio() const {return _constantWidthHeightRatio;}
00097   double printLeftMargin() const {return _printLeftMargin;}
00098   double printRightMargin() const {return _printRightMargin;}
00099   double printTopMargin() const {return _printTopMargin;}
00100   double printBottomMargin() const {return _printBottomMargin;}
00101   int printResolution() const {return _printResolution;}
00102   int transparency() const {return _transparency;}
00103   bool transparentMask() const {return _mask;}
00104 
00105   void setPrintXAnchor(double val);
00106   void setPrintYAnchor(double val);
00107   void setPrintAnchor(Point2D pos);
00108   void setAnchor(PositionAnchor pa) {_anchor=pa;}
00109   void setAnchor(QString pa);
00110   void setPrintLeft(double val);
00111   void setPrintTop(double val);
00112   void setPrintRight(double val);
00113   void setPrintBottom(double val);
00114   void setPrintWidth(double val) {_printWidth=val;}
00115   void setPrintHeight(double val) {_printHeight=val;}
00116   void setConstantWidthHeightRatio(bool c) {_constantWidthHeightRatio=c;}
00117   void setPrintLeftMargin(double val) {_printLeftMargin=val;}
00118   void setPrintRightMargin(double val) {_printRightMargin=val;}
00119   void setPrintTopMargin(double val) {_printTopMargin=val;}
00120   void setPrintBottomMargin(double val) {_printBottomMargin=val;}
00121   void setPrintResolution(int val) {_printResolution=val;}
00122   void setTransparency(int val) {_transparency=val;}
00123   void setTransparentMask(bool val);
00124 
00125   bool isRemovable() {return _isRemovable;}
00126   void setRemovable(bool r) {_isRemovable=r;}
00127 
00128   bool isActive() const;
00129   void setActive(Qt::KeyboardModifiers m);
00130   bool isSelected() const;
00131   SelectionWidget * selectionWidget() const {return _selected;}
00132   void setSelected(SelectionWidget * s);
00133   GraphicObject * activeObject(const char * className=0) const;
00134   void print(QPrinter& printer);
00135 
00136   bool setOrderIndex(int index);
00137   GraphicSheet * sheet() {return _sheet;}
00138 
00139   static QBitmap colorMask(const QPixmap& pixmap, uint blankColor);
00140   static int scaleFont(QFont& f, double scale, bool * changed=0);
00141 
00142   void startDragging() {_oldPrintPos=_printAnchor;}
00143   void drag(Point2D delta);
00144 
00145   static const QString pixelImageFilter;
00146   static const QString vectorialImageFilter;
00147   static const QString allImageFilter;
00148 
00149   // Properties dialog box
00150   PropertyProxy * proxy() const;
00151   virtual void addProperties(PropertyProxy * pp);
00152   virtual void removeProperties(PropertyProxy * pp);
00153   virtual void properties(PropertyWidget * w) const;
00154   virtual void setProperty(uint wid, int pid, QVariant val);
00155   void updateGeometryProperties(PropertyProxy * pp);
00156 
00157   void setToolTip(const QString& t);
00158 public slots:
00159   void keyPopupMenu ();
00160   void showProperties();
00161   void copy();
00162   void copyImage(int dpi=0);
00163   void savePage(QString fileName=QString::null);
00164   void print(int dpi=0);
00165   void print(bool outputToFile, QString name, int dpi);
00166   void exportImage(QString fileName=QString::null,
00167                    QString imageFormat=QString::null, int dpi=0);
00168   QPixmap image(int dpi=0);
00169   void copyMakeUp();
00170   void pasteMakeUp();
00171   void saveMakeUp(QString fileName=QString::null);
00172   void restoreMakeUp(QString fileName=QString::null);
00173   void deleteObject();
00174   virtual void deepUpdate() {update();}
00175   virtual void update();
00176   virtual void updateGeometry();
00177 signals:
00178   void sizeChanged();
00179   void positionChanged();
00180   void wantToBeSelected(GraphicObject *, Qt::KeyboardModifiers);
00181   void wantToStartDragging();
00182   void dragged(Point2D delta);
00183 protected:
00184   virtual void xml_writeProperties(XML_WRITEPROPERTIES_ARGS) const {qobject_writeProperties(this, this, s, context);}
00185   virtual XMLMember xml_member(XML_MEMBER_ARGS) {return qobject_member(this, tag, attributes, context);}
00186   virtual bool xml_setProperty(XML_SETPROPERTY_ARGS) {return qobject_setProperty(this, memberID, tag, attributes, content, context);}
00187   virtual void xml_polish(XML_POLISH_ARGS);
00188 
00189   void printSvg(const QString& fileName, int dpi);
00190   virtual void print(QPainter& p, double dotpercm, int x0Sheet, int y0Sheet, bool mask);
00191   virtual void setPrintSize(double dotpercm);
00192   virtual void paintEvent(QPaintEvent * e);
00193   virtual void addActions();
00194   virtual int * scaleFonts(double scale);
00195   virtual void restoreScaleFonts(int *fontSizeStorage);
00196   int scaleWidgetFonts(QWidget * w, double scale);
00197   virtual void paint(QPainter& p, double dotpercm, int w, int h, bool mask);
00198   // Mouse events
00199   virtual void mousePressEvent (QMouseEvent * e);
00200   virtual void mouseReleaseEvent (QMouseEvent * e);
00201   virtual void mouseMoveEvent (QMouseEvent * e);
00202   virtual void mouseDoubleClickEvent (QMouseEvent * e);
00203   virtual void showEvent (QShowEvent * e);
00204   virtual void enterEvent (QEvent * e);
00205   virtual void leaveEvent (QEvent * e);
00206 
00207   void updateMask();
00208 
00209   Point2D _printAnchor;
00210   PositionAnchor _anchor;
00211   double _printWidth, _printHeight;
00212   double _printLeftMargin, _printRightMargin, _printTopMargin, _printBottomMargin;
00213 private:
00214   friend class SelectionWidget;
00215   friend class GraphicSheet;
00216 
00217   SelectionWidget * _selected;
00218   GraphicSheet * _sheet;
00219   OrderTip * _orderTip;
00220   uint _isRemovable:1;
00221   uint _constantWidthHeightRatio:1;
00222   uint _mask:1;
00223   uint _printResolution:13;
00224   uint _transparency:8;
00225 
00226   static uint _category, _tabId, _tabGeomery, _tabPrint;
00227   static bool _draggingOn;
00228   static bool _draggingStarted;
00229   static QPoint _oldMousePos;
00230   Point2D _oldPrintPos;
00231 };
00232 
00233 } // namespace SciFigs
00234 
00235 #endif // GRAPHICOBJECT_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines