libidxgui
|
00001 /*************************************************************************** 00002 * Copyright (C) 2009 by Pierre Sermanet * 00003 * pierre.sermanet@gmail.com * 00004 * All rights reserved. 00005 * 00006 * Redistribution and use in source and binary forms, with or without 00007 * modification, are permitted provided that the following conditions are met: 00008 * * Redistributions of source code must retain the above copyright 00009 * notice, this list of conditions and the following disclaimer. 00010 * * Redistributions in binary form must reproduce the above copyright 00011 * notice, this list of conditions and the following disclaimer in the 00012 * documentation and/or other materials provided with the distribution. 00013 * * Redistribution under a license not approved by the Open Source 00014 * Initiative (http://www.opensource.org) must display the 00015 * following acknowledgement in all advertising material: 00016 * This product includes software developed at the Courant 00017 * Institute of Mathematical Sciences (http://cims.nyu.edu). 00018 * * The names of the authors may not be used to endorse or promote products 00019 * derived from this software without specific prior written permission. 00020 * 00021 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED 00022 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 00023 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00024 * DISCLAIMED. IN NO EVENT SHALL ThE AUTHORS BE LIABLE FOR ANY 00025 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 00026 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00027 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 00028 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00029 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00030 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00031 ***************************************************************************/ 00032 00033 #ifndef WIN2D_H_ 00034 #define WIN2D_H_ 00035 00036 #include <QPixmap> 00037 #include <QWidget> 00038 #include <QtGui> 00039 #include <QResizeEvent> 00040 #include <math.h> 00041 #include <iostream> 00042 00043 #include "defines_idxgui.h" 00044 #include "libidx.h" 00045 #include "defines.h" 00046 #include "win.h" 00047 00048 using namespace std; 00049 00050 namespace ebl { 00051 00053 // win2d 00054 00055 class IDXGUIEXPORT win2d : public QWidget, public win { 00056 Q_OBJECT 00057 00058 public: 00059 win2d(uint wid, const char *wname = NULL, uint height = 1, uint width = 1); 00060 virtual ~win2d(); 00061 00063 // overloaded methods from win 00064 00067 virtual void set_wupdate(bool ud); 00070 virtual void clear(); 00072 virtual void clear_resize(); 00076 virtual void resize_window(uint h, uint w, bool force = false); 00079 virtual void update_window(bool activate = false); 00082 virtual void repaint_pixmap(); 00084 virtual void set_bg_colors(ubyte r, ubyte g, ubyte b); 00085 00087 // additionnal methods 00088 00090 void update_pixmap(idx<ubyte> *img, uint h0, uint w0, bool updatepix =true); 00092 void update_pixmap(idx<ubyte> &img, uint h0, uint w0, bool updatepix =true); 00093 00094 protected: 00096 // event methods 00097 00099 void paintEvent(QPaintEvent *event); 00100 void wheelEvent(QWheelEvent *event); 00101 void mousePressEvent(QMouseEvent *event); 00102 void mouseMoveEvent(QMouseEvent *event); 00103 void mouseReleaseEvent(QMouseEvent *event); 00104 void keyPressEvent(QKeyEvent *event); 00105 void keyReleaseEvent(QKeyEvent *event); 00106 00108 // update methods 00109 00113 void buffer_resize(uint h, uint w, bool force = false); 00115 void buffer_fill(idx<ubyte> *buf); 00117 void update_qimage(uint mode = 0); 00118 void swap(); 00119 00121 // painting/drawing methods 00122 void draw_arrows(QPainter &painter); 00123 void draw_boxes(QPainter &painter); 00124 void draw_crosses(QPainter &painter); 00125 void draw_ellipses(QPainter &painter); 00126 void draw_masks(QPainter &painter); 00127 void draw_images(bool update = false); 00128 00129 // member variables //////////////////////////////////////////////////////// 00130 protected: 00131 using win::buffer; 00132 using win::drawing_mode; 00133 00134 private slots: 00135 void scroll_previous(); 00136 void scroll_next(); 00137 00138 private: 00139 QPixmap *pixmap; 00140 QPoint pixmapOffset; 00141 QPoint lastDragPos; 00142 double pixmapScale; 00143 uint buffer_maxh; 00144 uint buffer_maxw; 00145 QImage *qimage; 00146 idx<ubyte> *channel_buffer; 00147 }; 00148 00149 } // namespace ebl { 00150 00151 #endif /* WIN2D_H_ */