LunaSysMgr
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
pixmapobject.h
Go to the documentation of this file.
1 /* @@@LICENSE
2 *
3 * Copyright (c) 2010-2012 Hewlett-Packard Development Company, L.P.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 * LICENSE@@@ */
18 
19 
20 
21 
22 #ifndef PIXMAPOBJECT_H_
23 #define PIXMAPOBJECT_H_
24 
25 #include <QObject>
26 #include <QPixmap>
27 #include <QUuid>
28 #include <QSize>
29 
30 class QPainter;
31 class QPointF;
32 class PixPager;
33 class PixPagerPage;
34 class PixPagerAtlasPage;
35 class VirtualCamera;
36 
37 /*
38  * Not a true guarded pointer, nor intended to be. There is no way to guarantee with this impl that QPixmap wrapped herein
39  * cannot be destroyed by something external. That isn't the purpose though. PixmapObject is just to tag the QPixmap with an id
40  * and to be used like a QPixmap, including destroying *it* directly. This way, the proper signaling can take place for things
41  * like the PixPager
42  *
43  */
44 class PixmapObject : public QObject
45 {
46  Q_OBJECT
47 // QT5_TODO: Do we need someting to replace this?
48 #if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0))
49  Q_PROPERTY(QString id READ id WRITE setId)
50 #endif
51 
52 public:
53 
54  friend class VirtualCamera;
55  friend class PixmapObjectLoader;
56  PixmapObject();
57  PixmapObject ( int width, int height );
58  PixmapObject ( const QString & fileName, const char * format = 0, Qt::ImageConversionFlags flags = Qt::AutoColor );
59  PixmapObject ( const QString& fileName, const QSize& desiredSize, bool limitOnly = true, const char * format = 0, Qt::ImageConversionFlags flags = Qt::AutoColor );
60 
61  //TODO: IMPLEMENT
62  virtual PixmapObject * clone() { return 0; }
63 
64  virtual ~PixmapObject();
65 
66  virtual bool valid() const;
67 
68  virtual QUuid id() const;
69 
70  virtual void setId(const QUuid& uid);
71  virtual void setId(const QString& quuid_as_string);
72 
73  //for resizable target size pixmaps (like the tiled variety). Ignored in other case
74  // (returns true or false for resized or not)
75  virtual bool resize(const quint32 w,const quint32 h);
76  virtual bool resize(const QSize& size);
77 
78  //TODO: create "rendered___"() versions of some of these...e.g. renderedSize(), renderedWidth()...
79  // it is needed to make subclasses like the tileobject more friendly to use and less ambiguous
80  virtual QSize size() const;
81  virtual int width() const;
82  virtual int height() const;
83  virtual QSizeF sizeF() const;
84  virtual quint64 sizeOf() const;
85  virtual bool isSquare() const;
86 
87  virtual QSize nativeSize() const;
88  virtual int nativeWidth() const;
89  virtual int nativeHeight() const;
90  virtual QSizeF nativeSizeF() const;
91 
92  virtual void fill(const QColor& c);
93  virtual void paint(QPainter * painter);
94  virtual void paint(QPainter * painter,const QPointF& targetOriginInPainterCS);
95  virtual void paint(QPainter * painter,const QRectF& targetRectInPainterCS);
96 
97  /*
98  *
99  * sourceRect:
100  * The rectangle source in either PHYSICAL or VIRTUAL space of this PMO!
101  * This is an important point...this rect will be specified in the space of (0,0)->size()
102  * In the case of the base PixmapObject, this will be 1:1 with the actual pixmap contained. e.g. if the
103  * pixmap stored here is 200x300, then the space will be (0,0)-(200,300)
104  * However, in the case of complex subclasses which define a virtual space - i.e. their painted sizes are larger
105  * then the pixmap size contained and/or they stitch a large picture from many smaller pixmaps - the sourceRect
106  * space will be relative to this virtual picture. IT IS VITAL that size(),sizeF(), width(), and height() return
107  * sane values, for this reason
108  *
109  */
110  virtual void paint(QPainter * painter,const QRect& targetRectInPainterCS,
111  const QRect& sourceRect);
112 
113  virtual QPoint translatePaintTargetPointToPixmapPoint(const QPoint& point,const QRect& sourceRect,const QRect& destRect);
114  //this variant is needed for pixmapobject variants that need to express the return coordinates with more than just a QPoint
115  // (e.g. hugepixmap, which will return x,y,index of
116  virtual QVector<qint32> translatePaintTargetPointToPixmapPointEx(const QPoint& point,const QRect& sourceRect,const QRect& destRect);
117 
118  static quint64 sizeOfPixmap(const QPixmap * p_pixmap);
119  //how much would a pixmap of w x h x whatever_bitdepth_we_use
120  static quint64 sizeOfPixmap(quint32 width,quint32 height);
121 
122  virtual QPixmap* operator->() const
123  { return static_cast<QPixmap*>(const_cast<QPixmap*>(pm)); }
124  virtual QPixmap& operator*() const
125  { return *static_cast<QPixmap*>(const_cast<QPixmap*>(pm)); }
126  virtual operator QPixmap*() const
127  { return static_cast<QPixmap*>(const_cast<QPixmap*>(pm)); }
128  virtual QPixmap* data() const
129  { return static_cast<QPixmap*>(const_cast<QPixmap*>(pm)); }
130 
131  friend class PixPager;
132  friend class PixPagerPage;
133  friend class PixPagerAtlasPage;
134 
135 Q_SIGNALS:
136  void signalObjectDestroyed();
137 
138 protected:
139 
140  //DANGEROUS VARIANT! Assumes ownership of pixmap; must never be a pixmap on the stack!
141  PixmapObject (QPixmap * p_pixmap);
142 
143  //this is to be used only in very specific circumstances; PixmapJUPOCObject and PixmapJUPOCRefObject use this to transfer the Uid key of a map to the actual object
144  PixmapObject(const QUuid& specificUid);
145 
146  QUuid m_uid;
147  QPixmap * pm;
148  bool m_destroyEmitted; //a workaround for destructors in base classes
149  //emitting PixmapObject::signalObjectDestroyed
150 };
151 
152 #endif /* PIXMAPOBJECT_H_ */