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 WIN_H_ 00034 #define WIN_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 "scroll_box0.h" 00046 #include "defines.h" 00047 00048 using namespace std; 00049 00050 namespace ebl { 00051 00052 // TODO: derive all objects from a common drawable_object and hold 00053 // all of them in a same vector, to retain the drawing order. 00054 00056 // string 00057 00058 class text : public string { 00059 public: 00060 float h0, w0; 00061 bool pos_reset; 00062 unsigned char fg_r, fg_g, fg_b, fg_a, bg_r, bg_g, bg_b, bg_a; 00063 text(float h0, float w0, bool pos_reset = false, 00064 unsigned char fg_r = 255, unsigned char fg_g = 255, 00065 unsigned char fg_b = 255, unsigned char fg_a = 255, 00066 unsigned char bg_r = 0, unsigned char bg_g = 0, 00067 unsigned char bg_b = 0, unsigned char bg_a = 127); 00068 ~text() {}; 00069 }; 00070 00072 // arrow 00073 00074 class arrow { 00075 public: 00076 int h1, w1, h2, w2; 00077 bool head1, head2; 00078 arrow(int h1, int w1, int h2, int w2, 00079 bool head1 = true, bool head2 = false); 00080 ~arrow() {}; 00081 }; 00082 00084 // box 00085 00086 class box { 00087 public: 00088 box(float h0, float w0, float h, float w, ubyte r, ubyte g, ubyte b, 00089 ubyte a); 00090 ~box() {}; 00091 float h0, w0, h, w; 00092 ubyte r, g, b, a; 00093 }; 00094 00096 // cross 00097 00098 class cross { 00099 public: 00100 float h0, w0, length; 00101 ubyte r, g, b, a; 00102 cross(float h0, float w0, float length, ubyte r, 00103 ubyte g, ubyte b, ubyte a); 00104 ~cross() {}; 00105 }; 00106 00108 // image 00109 00110 class image { 00111 public: 00112 uint h0, w0; 00113 idx<ubyte> img; 00114 image(idx<ubyte> &img, uint h0, uint w0); 00115 ~image() {}; 00116 }; 00117 00119 // mask 00120 00121 class imask { 00122 public: 00124 imask(idx<ubyte> *img, uint h0, uint w0, 00125 ubyte r, ubyte g, ubyte b, ubyte a); 00126 ~imask() {}; 00127 00128 // members 00129 uint h0, w0; 00130 QPixmap map; 00131 }; 00132 00134 // window 00135 00136 class IDXGUIEXPORT win { 00137 public: 00140 win(QWidget *qwidj, uint wid, const char *wname = NULL, 00141 uint height = 1, uint width = 1); 00143 win(); 00144 virtual ~win(); 00145 00146 virtual void show(); 00147 virtual QWidget* get_widget(); 00148 00150 virtual void save(const string &filename, bool confirm = false); 00153 virtual void save_mat(const string &filename, bool confirm = false); 00155 virtual void set_silent(const std::string *filename); 00158 virtual void freeze_style(bool freeze); 00160 virtual void freeze_window_size(uint h, uint w); 00162 virtual void set_title(const char *title); 00165 virtual void set_wupdate(bool ud); 00169 virtual void resize_window(uint h, uint w, bool force = false); 00172 virtual void update_window(bool activate = false); 00174 virtual bool busy_drawing(); 00175 00177 // Objects adding methods 00178 00180 virtual void add_text(const std::string *s); 00181 virtual void add_arrow(int h1, int w1, int h2, int w2); 00182 virtual void add_flow(idx<float> *flow, int h, int w); 00183 virtual void add_box(float h0, float w0, float h, float w, ubyte r, ubyte g, 00184 ubyte b, ubyte a, string *s); 00185 virtual void add_cross(float h0, float w0, float length, ubyte r, ubyte g, 00186 ubyte b, ubyte a, string *s); 00187 virtual void add_ellipse(float h0, float w0, float h, float w, ubyte r, 00188 ubyte g, ubyte b, ubyte a, string *s); 00189 virtual void add_image(idx<ubyte> &img, uint h0, uint w0); 00190 virtual void add_mask(idx<ubyte> *img, uint h0, uint w0, 00191 ubyte r, ubyte g, ubyte b, ubyte a); 00192 00194 virtual void set_text_origin(float h0, float w0); 00195 00197 // clear methods 00198 00201 virtual void clear(); 00203 virtual void clear_resize(); 00206 virtual void clear_all(bool clear_tmp = false); 00209 void clear_text(bool clear_tmp = false); 00212 void clear_arrows(bool clear_tmp = false); 00215 void clear_boxes(bool clear_tmp = false); 00218 void clear_crosses(bool clear_tmp = false); 00221 void clear_ellipses(bool clear_tmp = false); 00224 void clear_images(bool clear_tmp = false); 00227 void clear_masks(bool clear_tmp = false); 00228 00230 // Style methods 00231 00233 virtual void set_text_colors(ubyte fg_r, ubyte fg_g, ubyte fg_b, ubyte fg_a, 00234 ubyte bg_r, ubyte bg_g, ubyte bg_b, ubyte bg_a, 00235 bool ignore_frozen = false); 00237 virtual void set_bg_colors(ubyte r, ubyte g, ubyte b); 00239 virtual void set_font_size(int sz); 00240 00242 // Events methods 00243 00246 virtual int pop_key_pressed(); 00247 00249 // Scrolling methods 00250 00251 virtual void add_scroll_box(scroll_box0 *sb); 00252 virtual void remove_scroll_box(scroll_box0 *sb); 00253 virtual void replace_scroll_box_with_copy(scroll_box0 *sb); 00254 00256 // Painting methods 00257 00259 virtual void paint(QPainter &painter, double scale = 1.0); 00261 virtual void draw_text(QPainter &painter); 00262 00263 protected: 00265 // event methods 00266 void wheelEvent(QWheelEvent *event); 00267 void mousePressEvent(QMouseEvent *event); 00268 void mouseMoveEvent(QMouseEvent *event); 00269 void mouseReleaseEvent(QMouseEvent *event); 00270 void keyPressEvent(QKeyEvent *event); 00271 void keyReleaseEvent(QKeyEvent *event); 00272 00273 private slots: 00274 void scroll_previous(); 00275 void scroll_next(); 00276 00277 protected: 00278 QWidget *qw; 00279 QPixmap *pixmap; 00280 QPoint pixmapOffset; 00281 QPoint lastDragPos; 00282 double pixmapScale; 00283 double curScale; 00284 float scaleIncr; 00285 idx<ubyte> *buffer; 00286 uint buffer_maxh; 00287 uint buffer_maxw; 00288 QVector<QRgb> colorTable; 00289 QImage *qimage; 00290 vector<text*> texts; 00291 vector<text*> texts_tmp; 00292 text* txt; 00293 vector<arrow*> arrows; 00294 vector<arrow*> arrows_tmp; 00295 vector<box*> boxes; 00296 vector<box*> boxes_tmp; 00297 vector<cross*> crosses; 00298 vector<cross*> crosses_tmp; 00299 vector<box*> ellipses; 00300 vector<box*> ellipses_tmp; 00301 vector<image*> images; 00302 vector<image*> images_tmp; 00303 vector<imask*> masks; 00304 vector<imask*> masks_tmp; 00305 bool silent; 00306 uint id; 00307 string savefname; 00308 float text_h0; 00309 float text_w0; 00310 bool pos_reset; // text position was reset or not 00311 bool wupdate; 00312 QColor text_fg_color; 00313 QColor text_bg_color; 00314 QColor bg_color; 00315 unsigned char fg_r, fg_g, fg_b, fg_a, bg_r, bg_g, bg_b, bg_a; 00316 int wupdate_ndisable;// count how many disables called 00317 bool frozen_style; 00318 bool frozen_size; 00319 idxdim frozen_dims; 00320 list<int> keyspressed; 00321 int font_size; 00322 bool ctrl_on; 00323 bool text_on; 00324 bool images_only; 00325 scroll_box0 *scrollbox; 00326 bool busy; 00327 uint drawing_mode; 00328 }; 00329 00330 } // namespace ebl { 00331 00332 #endif /* WIN_H_ */