ImageCanvas.h
Go to the documentation of this file.00001 /**<!--------------------------------------------------------------------> 00002 @class ImageCanvas 00003 @author Travis Fischer (fisch0920@gmail.com) 00004 @author Matthew Jacobs (jacobs.mh@gmail.com) 00005 @date Fall 2008 00006 00007 @brief 00008 Provides a Qt canvas for displaying 2D raster data 00009 <!-------------------------------------------------------------------->**/ 00010 00011 #ifndef IMAGE_CANVAS_H_ 00012 #define IMAGE_CANVAS_H_ 00013 00014 #include <renderers/outputs/NaiveRenderOutput.h> 00015 #include <common/image/RgbaImage.h> 00016 #include "Canvas.h" 00017 #include <QWidget> 00018 00019 class PointSample; 00020 class QMouseEvent; 00021 class QPaintEvent; 00022 class QImage; 00023 class QTimerEvent; 00024 class MainSyscallProxy; 00025 00026 class ImageCanvas : public QWidget, 00027 public Canvas, 00028 public NaiveRenderOutput 00029 { 00030 Q_OBJECT 00031 00032 public: 00033 ///@name Constructors 00034 //@{----------------------------------------------------------------- 00035 00036 ImageCanvas(Gui *gui, unsigned width = DEFAULT_WIDTH, 00037 unsigned height = DEFAULT_HEIGHT); 00038 ImageCanvas(Gui *gui, const QImage &background); 00039 00040 virtual ~ImageCanvas(); 00041 00042 00043 //@}----------------------------------------------------------------- 00044 ///@name Saving/Loading 00045 //@{----------------------------------------------------------------- 00046 00047 /** 00048 * Attempts to saver this canvas' image to the specified file 00049 * @returns whether or not the save was successful 00050 */ 00051 bool save(const char *fileName); 00052 00053 /** 00054 * Attempts to load this canvas' image from the specified file 00055 * @returns whether or not the load was successful 00056 */ 00057 bool load(const char *fileName); 00058 00059 00060 //@}----------------------------------------------------------------- 00061 ///@name Pixel data accessors/mutators 00062 //@{----------------------------------------------------------------- 00063 00064 /** 00065 * Sets an individual pixel's data on this canvas 00066 */ 00067 void setPixel(unsigned x, unsigned y, const Rgba32 &val); 00068 00069 /** 00070 * @returns an individual pixel's data 00071 */ 00072 Rgba32 getPixel(unsigned x, unsigned y) const; 00073 00074 /** 00075 * Sets all of the pixel data on this canvas 00076 */ 00077 void setData(const Rgba32 *data); 00078 00079 /** 00080 * Sets all of the pixel data and resizes this canvas, all without 00081 * allocating any temporary memory inbetween 00082 */ 00083 void setData(const Rgba32 *data, unsigned newWidth, unsigned newHeight); 00084 00085 /** 00086 * @returns the underlying image data 00087 */ 00088 inline Rgba32 *getData() { 00089 ASSERT(m_image); 00090 00091 return m_image->getData(); 00092 } 00093 00094 00095 //@}----------------------------------------------------------------- 00096 ///@name Canvas dimensions 00097 //@{----------------------------------------------------------------- 00098 00099 void setWidth(unsigned width); 00100 void setHeight(unsigned height); 00101 void setSize(unsigned width, unsigned height); 00102 00103 00104 //@}----------------------------------------------------------------- 00105 00106 virtual bool supportsOpenGL() const; 00107 00108 virtual QWidget *getQWidget() { 00109 return this; 00110 } 00111 00112 00113 public: 00114 // for synchronous gui updates during concurrent rendering 00115 friend class MainSyscallProxy; 00116 00117 public slots: 00118 ///@name Main usage interface 00119 //@{----------------------------------------------------------------- 00120 00121 /// Attempts to render the entire canvas 00122 void render(); 00123 00124 /// Attempts to render the specified rectangular subregion on the canvas 00125 void render(unsigned x0, unsigned y0, 00126 unsigned width, unsigned height); 00127 00128 /// Updates the entire canvas (same as update) 00129 virtual void redraw(); 00130 00131 /// Updates the entire canvas 00132 virtual void update(); 00133 00134 /// Updates the specified rectangular subregion on the canvas 00135 virtual void update(int x, int y, int width, int height); 00136 00137 00138 //@}----------------------------------------------------------------- 00139 00140 protected: 00141 ///@name Overridden from QWidget 00142 //@{----------------------------------------------------------------- 00143 00144 virtual void mousePressEvent(QMouseEvent *); 00145 virtual void mouseReleaseEvent(QMouseEvent *); 00146 virtual void mouseMoveEvent(QMouseEvent *); 00147 00148 virtual void keyPressEvent(QKeyEvent *event); 00149 virtual void keyReleaseEvent(QKeyEvent *event); 00150 00151 virtual QSize sizeHint() const; 00152 virtual QSize minimumSize() const; 00153 virtual QSize maximumSize() const; 00154 00155 virtual void paintEvent(QPaintEvent *e); 00156 00157 00158 //@}----------------------------------------------------------------- 00159 ///@name Overridden from RenderOutput 00160 //@{----------------------------------------------------------------- 00161 00162 virtual void _addSample(const PointSample &sample); 00163 00164 00165 //@}----------------------------------------------------------------- 00166 00167 protected: 00168 QImage *m_qimage; 00169 RgbaImage *m_image; 00170 MainSyscallProxy *m_mainProxy; 00171 unsigned *m_renderCount; 00172 00173 private: 00174 void _init(); 00175 void _setupQWidget(); 00176 void _resizeImage(bool modifyImage = true); 00177 00178 void _repaintPrivate(unsigned x, unsigned y, unsigned w, unsigned h); 00179 }; 00180 00181 #endif // IMAGE_CANVAS_H_ 00182
Generated on 28 Feb 2009 for Milton by
1.5.6