Back to index

texmacs  1.0.7.15
qt_simple_widget.cpp
Go to the documentation of this file.
00001 
00002 /******************************************************************************
00003  * MODULE     : qt_simple_widget.hpp
00004  * DESCRIPTION: QT simple widget class
00005  * COPYRIGHT  : (C) 2008  Massimiliano Gubinelli
00006  *******************************************************************************
00007  * This software falls under the GNU general public license version 3 or later.
00008  * It comes WITHOUT ANY WARRANTY WHATSOEVER. For details, see the file LICENSE
00009  * in the root directory or <http://www.gnu.org/licenses/gpl-3.0.html>.
00010  ******************************************************************************/
00011 
00012 #include "qt_simple_widget.hpp"
00013 #include "qt_utilities.hpp"
00014 #include "qt_renderer.hpp"
00015 
00016 #include "message.hpp"
00017 
00018 
00019 
00023 simple_widget_rep::simple_widget_rep ():
00024 qt_view_widget_rep (new QTMWidget (this))
00025 {
00026     // view->setProperty ("texmacs_widget", QVariant::fromValue ((void*) this));
00027 }
00028 
00029 
00030 /******************************************************************************
00031  * Empty handlers for redefinition later on
00032  ******************************************************************************/
00033 
00034 void
00035 simple_widget_rep::handle_get_size_hint (SI& w, SI& h) {
00036   gui_root_extents (w, h);
00037 }
00038 
00039 void
00040 simple_widget_rep::handle_notify_resize (SI w, SI h) {
00041   (void) w; (void) h;
00042 }
00043 
00044 void
00045 simple_widget_rep::handle_keypress (string key, time_t t) {
00046   (void) key; (void) t;
00047 }
00048 
00049 void
00050 simple_widget_rep::handle_keyboard_focus (bool has_focus, time_t t) {
00051   (void) has_focus; (void) t;
00052 }
00053 
00054 void
00055 simple_widget_rep::handle_mouse (string kind, SI x, SI y, int mods, time_t t) {
00056   (void) kind; (void) x; (void) y; (void) mods; (void) t;
00057 }
00058 
00059 void
00060 simple_widget_rep::handle_set_shrinking_factor (int sf) {
00061   (void) sf;
00062 }
00063 
00064 void
00065 simple_widget_rep::handle_clear (SI x1, SI y1, SI x2, SI y2) {
00066   (void) x1; (void) y1; (void) x2; (void) y2;
00067 }
00068 
00069 void
00070 simple_widget_rep::handle_repaint (SI x1, SI y1, SI x2, SI y2) {
00071   (void) x1; (void) y1; (void) x2; (void) y2;
00072 }
00073 
00074 void
00075 simple_widget_rep::send (slot s, blackbox val) {
00076   if (DEBUG_QT) cout << "qt_simple_widget_rep::send " << slot_name(s) << LF;
00077   switch (s) {
00078     case SLOT_INVALIDATE:
00079     {
00080       TYPE_CHECK (type_box (val) == type_helper<coord4>::id);
00081       coord4 p= open_box<coord4> (val);
00082       if (DEBUG_QT)
00083         cout << "Invalidating rect " << rectangle(p.x1,p.x2,p.x3,p.x4) << LF;
00084       qt_renderer_rep* ren = (qt_renderer_rep*)get_renderer (this);
00085       if (ren) {
00086         SI x1 = p.x1, y1 = p.x2, x2 = p.x3, y2 = p.x4;    
00087         ren->outer_round (x1, y1, x2, y2);
00088         ren->decode (x1, y1);
00089         ren->decode (x2, y2);
00090         tm_canvas()->invalidate_rect (x1,y2,x2,y1);
00091       }
00092     }
00093       break;
00094     case SLOT_INVALIDATE_ALL:
00095     {
00096       ASSERT (is_nil (val), "type mismatch");
00097       if (DEBUG_QT)
00098         cout << "Invalidating all"<<  LF;
00099       tm_canvas()->invalidate_all ();
00100     }
00101       break;
00102     case SLOT_CURSOR:
00103     {
00104       TYPE_CHECK (type_box (val) == type_helper<coord2>::id);
00105       coord2 p= open_box<coord2> (val);
00106       QPoint pt = to_qpoint(p);
00107       tm_canvas() -> setCursorPos(pt);
00108     }
00109       break;
00110       
00111     default:
00112       if (DEBUG_QT) cout << "[qt_simple_widget_rep] ";
00113       qt_view_widget_rep::send (s, val);
00114         //      FAILED ("unhandled slot type");
00115   }
00116   
00117 }
00118 
00119 
00120 blackbox
00121 simple_widget_rep::query (slot s, int type_id) {
00122   if ((DEBUG_QT) && (s != SLOT_RENDERER))
00123     cout << "qt_simple_widget_rep::query " << slot_name(s) << LF;
00124   switch (s) {
00125     case SLOT_RENDERER:
00126     {
00127       TYPE_CHECK (type_id == type_helper<renderer>::id);
00128       renderer r = get_current_renderer();
00129         //FIXME: sometimes the renderer is queried outside repaint events 
00130         //       (see e.g. edit_interface_rep::idle_time)
00131         //       TeXmacs current policy is that we should return NULL only 
00132         //       if the widget is not attached (in X11 sense)
00133       if (!r) 
00134         r = the_qt_renderer();
00135       
00136 #if 1
00137       QTMWidget *canvas = tm_canvas();
00138       if (r && canvas) {
00139         SI ox = -canvas->backing_pos.x()*PIXEL;
00140         SI oy = canvas->backing_pos.y()*PIXEL;
00141         r->set_origin(ox,oy);
00142       }
00143 #endif 
00144       return close_box<renderer> (r);
00145     }
00146       
00147     default:
00148       return qt_view_widget_rep::query (s, type_id);      
00149   }
00150 }
00151 
00152 void
00153 simple_widget_rep::notify (slot s, blackbox new_val) {
00154   if (DEBUG_QT) cout << "[qt_simple_widget_rep] ";
00155   qt_view_widget_rep::notify (s, new_val);
00156 }
00157 
00158 /******************************************************************************
00159  * Read and write access of subwidgets
00160  ******************************************************************************/
00161 
00162 widget
00163 simple_widget_rep::read (slot s, blackbox index) {
00164   if (DEBUG_QT) cout << "[qt_simple_widget_rep] ";
00165   return qt_view_widget_rep::read (s, index);
00166 }
00167 
00168 void
00169 simple_widget_rep::write (slot s, blackbox index, widget w) {
00170   if (DEBUG_QT) cout << "[qt_simple_widget_rep] ";
00171   qt_view_widget_rep::write (s, index, w);
00172 }