Back to index

texmacs  1.0.7.15
QTMMenuHelper.cpp
Go to the documentation of this file.
00001 
00002 /******************************************************************************
00003 * MODULE     : QTMMenuHelper.hpp
00004 * DESCRIPTION: QT Texmacs menu helper 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 "QTMMenuHelper.hpp"
00013 
00014 #include "qt_gui.hpp"
00015 #include "qt_utilities.hpp"
00016 #include "Scheme/object.hpp"
00017 
00018 
00020 
00021 
00023 void 
00024 QTMCommand::apply()  {
00025   if (!is_nil(cmd)) { the_gui->process_command(cmd); }
00026 }
00027 
00028 
00029 
00030 
00032 
00033 void
00034 rerootActions (QWidget* dest, QWidget* src) {
00035   QList<QAction *> list = dest->actions();
00036   while (!list.isEmpty()) {
00037     QAction* a= list.takeFirst();
00038     dest->removeAction (a);
00039     //    delete a;
00040     a->deleteLater();
00041   }
00042   list = src->actions();
00043   while (!list.isEmpty()) {
00044     QAction* a= list.takeFirst();
00045     dest->addAction (a);
00046     a->setParent (dest);
00047   }
00048 }
00049 
00050 
00051 void
00052 QTMLazyMenu::force () {
00053   if (DEBUG_QT)  
00054     cout << "Force lazy menu" << LF;
00055   widget w= pm ();
00056   QMenu *menu2 = concrete(w)->get_qmenu();
00057   rerootActions (this, menu2);
00058 }
00059 
00060 
00062 
00063 
00064 QTMInputTextWidgetHelper::~QTMInputTextWidgetHelper() {
00065   //cout << "deleting" << LF;
00066   // remove refernce to helper in the texmacs widget
00067   wid()->helper = NULL;
00068   // if needed the texmacs widget is automatically deleted
00069 }
00070 
00071 
00072 void
00073 QTMInputTextWidgetHelper::commit () {
00074   QLineEdit *le = qobject_cast <QLineEdit*> (sender());
00075   if (le) {
00076     //    le -> setFrame(false);
00077     wid()->ok = true;
00078     done = false;
00079     wid () -> text = from_qstring (le -> text());
00080   }
00081 }
00082 
00083 void
00084 QTMInputTextWidgetHelper::leave () {
00085   // this is executed after commit
00086   // and when losing focus
00087   QLineEdit *le = qobject_cast <QLineEdit*> (sender());  
00088   if (le) {
00089     // reset the text according to the texmacs widget
00090     le -> setText (to_qstring (wid () -> text));
00091     //ok = false;
00092     QTimer::singleShot (0, this, SLOT (doit ()));
00093   }
00094 }
00095 
00096 void
00097 QTMInputTextWidgetHelper::remove (QObject *obj) {
00098   views.removeAll (qobject_cast<QLineEdit*> (obj));
00099   if (views.count () == 0) {
00100     // no more view, free the helper 
00101     deleteLater();
00102   }
00103 }
00104 
00105 void
00106 QTMInputTextWidgetHelper::add(QLineEdit *obj) {
00107   if (!views.contains (obj)) {
00108     QObject::connect (obj, SIGNAL(destroyed (QObject*)), this, SLOT(remove (QObject*)));
00109     views << obj;
00110   }
00111 }
00112 
00113 
00114 
00115 void
00116 QTMInputTextWidgetHelper::doit () {
00117   if (done) return;
00118   done = true;
00119 #if 0
00120   if (wid()->ok) 
00121     cout << "Committing: " << wid () -> text << LF;
00122   else 
00123     cout << "Leaving with text: " << wid () -> text << LF;
00124 #endif
00125 #if 0
00126   wid () -> cmd (wid()->ok ? list_object (object (wid() -> text)) : 
00127                  list_object (object (false)));
00128 #else
00129   the_gui -> process_command(wid()->cmd, wid()->ok ? list_object (object (wid() -> text)) : 
00130                              list_object (object (false)));
00131 #endif
00132 }
00133 
00134 
00136 
00137 
00138 QTMTabWidget::QTMTabWidget(QWidget *p) : QTabWidget(p) {
00139   QObject::connect(this, SIGNAL(currentChanged(int)), this, SLOT(resizeOthers(int)));
00140 }
00141 
00142 void
00143 QTMTabWidget::resizeOthers(int index) {
00144   for(int i = 0; i < count(); ++i) {
00145     if (i != index)
00146       widget(i)->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
00147       else
00148         widget(i)->setSizePolicy(QSizePolicy::MinimumExpanding, 
00149                                  QSizePolicy::MinimumExpanding);
00150         }
00151 
00152   if (layout())
00153     layout()->activate();
00154   window()->resize(minimumSizeHint());
00155 }