LunaSysMgr
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
pixmaphugeobject.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 PIXMAPHUGEOBJECT_H_
23 #define PIXMAPHUGEOBJECT_H_
24 
25 #include "pixmapobject.h"
26 #include <QVector>
27 #include <QList>
28 #include <QRect>
29 #include <QDebug>
30 
31 class VirtualCamera;
32 class DemoGoggles;
34 {
35  Q_OBJECT
36 
37 public:
38 
39  friend class VirtualCamera;
40  friend class DemoGoggles;
42  {
43  public:
45  : pixmapIndex(0)
46  {
47  }
48  FragmentedPaintCoordinate(int index,const QRect& src,const QRect& dst)
49  : pixmapIndex(index)
50  , sourceRect(src)
51  , targetRect(dst)
52  {
53  }
54  //which "tile" in the pixmap list
56  //the coordinates of the rectangle to paint from in the absolute coordinate space
57  QRect sourceRect;
58  //coordinates in the painter cs of the pixmap
59  QRect targetRect;
60 
61  friend QDebug operator<<(QDebug dbg, const FragmentedPaintCoordinate &c);
62  };
63 
65  PixmapHugeObject ( int width, int height );
66  PixmapHugeObject ( const QString & fileName, const char * format = 0, Qt::ImageConversionFlags flags = Qt::AutoColor );
67  PixmapHugeObject ( const QList<QString>& fileNames, const QSize& fileLayout,const char * format = 0, Qt::ImageConversionFlags flags = Qt::AutoColor );
68  //this one copies the QPixmaps in the list, so they can be anything in the caller
69  PixmapHugeObject ( const QList<QPixmap>& pixmaps, const QSize& layout);
70 
71  virtual ~PixmapHugeObject();
72 
73  virtual bool valid() const;
74 
75  virtual QSize size() const;
76  virtual int width() const;
77  virtual int height() const;
78  virtual QSizeF sizeF() const;
79  virtual quint64 sizeOf() const;
80  virtual bool isSquare() const;
81 
82  /*
83  * The paint() functions are OUTPUT functions...they paint the contents of this "huge pixmap" onto whatever painter is passed in
84  *
85  * For INPUT functions (i.e. painting ONTO this huge pixmap), each item that wants to be able to render offscreen to a PixmapHugeObject will
86  * have to implement a paint(PixmapHugeObject * p,...). Ideally, this would be done by making a PixmapHuge class derived from QPixmap, and a PixmapHugeEngine
87  * derived from QPaintEngine, and then wrapping PixmapHugeObject around it just as PixmapObject wraps over QPixmap
88  *
89  * ...however I don't have time to do this at the moment so this is a shortcut approach
90  */
91 
92  virtual void paint(QPainter * painter);
93  virtual void paint(QPainter * painter,const QPointF& targetOriginInPainterCS);
94  virtual void paint(QPainter * painter,const QRectF& targetRectInPainterCS);
95  virtual void paint(QPainter * painter,const QRect& targetRectInPainterCS,
96  const QRect& sourceRect);
97 
98  virtual QPoint translatePaintTargetPointToPixmapPoint(const QPoint& point,const QRect& sourceRect,const QRect& destRect);
99  // vec[0] = point.x in hugespace , [1] = point.y in hugespace , [2] = point.x on local pixmap , [3] = point.y on local pixmap , [4] = index of local pixmap
100  virtual QVector<qint32> translatePaintTargetPointToPixmapPointEx(const QPoint& point,const QRect& sourceRect,const QRect& destRect);
101 
102  //these return a 3-vector: [0] = pixmap index (in m_pixmaps vector), [1],[2] x,y coords in painter CS inside that pixmap
103  QVector<int> hugeSpaceCoordinatesOfPoint(const QPoint& pointInAbsolutePainterCS);
104  QVector<int> hugeSpaceCoordinatesOfPoint(const int x,const int y);
105  QVector<FragmentedPaintCoordinate> paintCoordinates(const QRect& rectInAbsolutePainterCS);
106 
107  virtual QPixmap * pixAt(const quint32 index) const;
108 
109  virtual QPixmap* operator->() const;
110  virtual QPixmap& operator*() const;
111  virtual operator QPixmap*() const;
112  virtual QPixmap* data() const;
113 
114  friend class PixPager;
115  friend class PixPagerPage;
116  friend class PixPagerAtlasPage;
117 
118  static QSize pixmapToArraySize(const QSize& pixmapSize,const QSize& maxSinglePixmapSize);
119  //this variant returns the size of the "edge pixmaps" (on the right and bottom edges) since these
120  // are the "leftover" size of what wouldn't fit into a whole maxSinglePixmapSize
121  static QSize pixmapToArraySize(const QSize& pixmapSize,const QSize& maxSinglePixmapSize,QSize& r_rightAndBottomEdgeSizes);
122 
123  void dbg_save(const QString& baseName);
124 
125  friend QDebug operator<<(QDebug dbg, const PixmapHugeObject& c);
126 protected:
127 
128  //DANGEROUS VARIANT! Assumes ownership of pixmaps; must never be pixmaps on the stack!
129  PixmapHugeObject (const QVector<QPixmap *> pixmaps,const QSize& layout);
130 
131  virtual void allocatePixmaps(const QSize& arraySize,const QSize& normalSize,const QSize& leftoverSize);
132  virtual void copyToPixmaps(const QImage& sourceImage);
133 
134  QSize m_arraySize; //array config..e.g. [3][4] (3 by 4)...QSize.w = columns, QSize.h = rows
135  QVector<QRect> m_pixmapRectCoords; //(precomputed divisions from 0,0->m_hugePixmapSize to make paint() faster)
136  QSize m_hugePixmapSize; //the total size of the pixmap if you stitched together all the pixmaps
137  QVector<QPixmap *> m_pixmaps; //using QVector for the property of having pixmap ptrs adjacent in memory
138  bool m_valid; //(precomputed validity to make valid() faster)
139 
140 };
141 
142 QDebug operator<<(QDebug dbg, const PixmapHugeObject& c);
143 QDebug operator<<(QDebug dbg, const PixmapHugeObject::FragmentedPaintCoordinate &c);
144 
145 #endif /* PIXMAPHUGEOBJECT_H_ */