Back to index

texmacs  1.0.7.15
qt_window_widget.cpp
Go to the documentation of this file.
00001 
00002 /******************************************************************************
00003  * MODULE     : qt_window_widget.hpp
00004  * DESCRIPTION: QT window widget.
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_window_widget.hpp"
00013 #include "qt_utilities.hpp"
00014 #include "QTMWindow.hpp"
00015 
00016 #include "message.hpp"
00017 #include "analyze.hpp"
00018 
00019 #include <QWidget>
00020 #include <QVariant>
00021 
00022 qt_window_widget_rep::qt_window_widget_rep (QWidget* _wid, command q):
00023 widget_rep(), wid(_wid), quit(q)
00024 {
00025   wid->setProperty ("texmacs_window_widget",
00026                     QVariant::fromValue ((void*) this));
00027   (void) q;
00028   nr_windows++;
00029 }
00030 
00031 qt_window_widget_rep::~qt_window_widget_rep ()
00032 {
00033   nr_windows--;
00034 }
00035 
00036 void
00037 qt_window_widget_rep::send (slot s, blackbox val) {
00038   if (DEBUG_QT)
00039     cout << "qt_window_widget_rep::send " << slot_name (s) << LF;
00040   
00041   switch (s) {
00042     case SLOT_SIZE:
00043     {
00044       TYPE_CHECK (type_box (val) == type_helper<coord2>::id);
00045       coord2 p= open_box<coord2> (val);
00046       if (wid) {
00047         QSize size= to_qsize (p);
00048         wid->resize (size);
00049       }
00050     }
00051       break;
00052       
00053     case SLOT_POSITION:
00054     {
00055       TYPE_CHECK (type_box (val) == type_helper<coord2>::id);
00056       coord2 p= open_box<coord2> (val);
00057       if (wid) {
00058         QPoint pt = to_qpoint (p);
00059         pt.ry() += 40;
00060           // to avoid window under menu bar on MAC when moving at (0,0)
00061         if (DEBUG_QT) 
00062           cout << "Moving to (" << pt.x() << "," 
00063           << pt.y() << ")" << LF;
00064         wid->move (pt);
00065       }
00066     }
00067       break;
00068       
00069     case SLOT_VISIBILITY:
00070     {
00071       check_type<bool> (val, "SLOT_VISIBILITY");
00072       bool flag = open_box<bool> (val);
00073       if (wid) {
00074         if (flag) {
00075           wid->show();
00076           // wid->activateWindow();
00077           //WEIRD: in Ubuntu uncommenting the above line causes the main window 
00078           //to be opened in the background.
00079           wid->raise();
00080         }
00081         else wid->hide();
00082       }
00083     }
00084       break;
00085       
00086     case SLOT_NAME:
00087     {   
00088       check_type<string> (val, "SLOT_NAME");
00089       string name = open_box<string> (val);
00090       if (wid) wid->setWindowTitle (to_qstring (tm_var_encode(name)));
00091     }
00092       break;
00093       
00094     case SLOT_FULL_SCREEN:
00095     {
00096       check_type<bool> (val, "SLOT_FULL_SCREEN");
00097       QTMWindow *win = qobject_cast<QTMWindow*>(wid);
00098       if (win && win->tm_widget()) {
00099         win->tm_widget()->set_full_screen(open_box<bool> (val));
00100       }
00101         //win->set_full_screen (open_box<bool> (val));
00102     }
00103       break;
00104       
00105     case SLOT_UPDATE:
00106       NOT_IMPLEMENTED ;
00107         //send_update (THIS, val);
00108       break;
00109     case SLOT_REFRESH:
00110         //NOT_IMPLEMENTED ;
00111         //send_refresh (THIS, val);
00112       break;
00113       
00114     default:
00115       FAILED ("cannot handle slot type");
00116   }
00117 }
00118 
00119 blackbox
00120 qt_window_widget_rep::query (slot s, int type_id) {
00121   if (DEBUG_QT)
00122     cout << "qt_window_widget_rep::query " << slot_name(s) << LF;
00123   switch (s) {
00124     case SLOT_IDENTIFIER:
00125       TYPE_CHECK (type_id == type_helper<int>::id);
00126         // we need only to know if the widget is attached to some gui window
00127       return close_box<int> (wid? 1: 0);
00128         // return close_box<int> ((int)wid);
00129     case SLOT_POSITION:
00130     {
00131       typedef pair<SI,SI> coord2;
00132       TYPE_CHECK (type_id == type_helper<coord2>::id);
00133       QPoint pt= wid->pos();
00134       if (DEBUG_QT)
00135         cout << "Position (" << pt.x() << "," << pt.y() << ")\n";
00136       return close_box<coord2> (from_qpoint (pt));
00137     }
00138     case SLOT_SIZE:
00139     {
00140       typedef pair<SI,SI> coord2;
00141       TYPE_CHECK (type_id == type_helper<coord2>::id);
00142       QSize s= wid->size();
00143       return close_box<coord2> (from_qsize (s));
00144     }
00145     default:
00146       FAILED ("cannot handle slot type");
00147       return blackbox ();
00148   }
00149 }
00150 
00151 /******************************************************************************
00152  * Notification of state changes
00153  ******************************************************************************/
00154 
00155 void
00156 qt_window_widget_rep::notify (slot s, blackbox new_val) {
00157   if (DEBUG_QT)
00158     cout << "qt_window_widget_rep::notify " << slot_name(s) << LF;
00159   widget_rep::notify (s, new_val);
00160 }
00161 
00162 widget
00163 qt_window_widget_rep::read (slot s, blackbox index) {
00164   (void) index;
00165   if (DEBUG_QT)
00166     cout << "qt_window_widget_rep::read " << slot_name(s) << LF;
00167   switch (s) {
00168     default:
00169       FAILED ("cannot handle slot type");
00170       return widget();
00171   }
00172 }
00173 
00174 void
00175 qt_window_widget_rep::write (slot s, blackbox index, widget w) {
00176   (void) w; (void) index;
00177   if (DEBUG_QT)
00178     cout << "qt_window_widget_rep::write " << slot_name(s) << LF;
00179   
00180   switch (s) {
00181     default:
00182       FAILED ("cannot handle slot type");
00183   }
00184 }
00185