Back to index

texmacs  1.0.7.15
Public Member Functions | Public Attributes
qt_gui_rep Class Reference

#include <qt_gui.hpp>

Collaboration diagram for qt_gui_rep:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 qt_gui_rep (int &argc, char **argv)
virtual ~qt_gui_rep ()
void get_extents (SI &width, SI &height)
void get_max_size (SI &width, SI &height)
void event_loop ()
virtual bool get_selection (string key, tree &t, string &s, string format)
virtual bool set_selection (string key, tree t, string s, string format)
virtual void clear_selection (string key)
void image_gc (string name="*")
void set_mouse_pointer (string name)
void set_mouse_pointer (string curs_name, string mask_name)
void show_wait_indicator (widget w, string message, string arg)
bool check_event (int type)
void update ()
void add_notifier (socket_notifier)
void remove_notifier (socket_notifier)
void enable_notifier (socket_notifier, bool)
void process_keypress (simple_widget_rep *wid, string key, time_t t)
void process_keyboard_focus (simple_widget_rep *wid, bool has_focus, time_t t)
void process_mouse (simple_widget_rep *wid, string kind, SI x, SI y, int mods, time_t t)
void process_resize (simple_widget_rep *wid, SI x, SI y)
void process_command (command _cmd)
void process_command (command _cmd, object _args)
void process_socket_notification (socket_notifier sn)
void process_delayed_commands ()
void process_queued_events (int max=-1)

Public Attributes

bool interrupted
time_t interrupt_time
QTMGuiHelpergui_helper
QTimer * updatetimer
QList< QLabel * > waitDialogs
QWidget * waitWindow
hashmap< string, treeselection_t
hashmap< string, stringselection_s

Detailed Description

Definition at line 38 of file qt_gui.hpp.


Constructor & Destructor Documentation

qt_gui_rep::qt_gui_rep ( int &  argc,
char **  argv 
)

Definition at line 67 of file qt_gui.cpp.

                                            :
  interrupted (false), waitWindow (NULL)
{
  (void) argc; (void) argv;
  // argc= argc2;
  // argv= argv2;

  interrupted   = false;
  time_credit = 100;
  timeout_time= texmacs_time () + time_credit;

  //waitDialog = NULL;
  
  set_output_language (get_locale_language ());
  gui_helper = new QTMGuiHelper (this);
  qApp -> installEventFilter (gui_helper);
  
#ifdef QT_MAC_USE_COCOA
  //HACK: this filter is needed to overcome a bug in Qt/Cocoa
  extern void mac_install_filter(); // defined in src/Plugins/MacOS/mac_app.mm
  mac_install_filter();
#endif
  
  
  
  qApp-> installTranslator(new QTMTranslator(qApp));
  
  updatetimer = new QTimer (gui_helper);
  updatetimer->setSingleShot (true);
  QObject::connect ( updatetimer, SIGNAL(timeout()), 
                     gui_helper, SLOT(doUpdate()));
//  (void) default_font ();
}

Here is the call graph for this function:

qt_gui_rep::~qt_gui_rep ( ) [virtual]

Definition at line 118 of file qt_gui.cpp.

                         {
  delete gui_helper;
  
  while (waitDialogs.count()) {
    waitDialogs.last()->deleteLater();
    waitDialogs.removeLast();
  }    
  if (waitWindow) delete waitWindow;
  
 // delete updatetimer; we do not need this given that gui_helper is the 
 // parent of updatetimer
}

Member Function Documentation

Definition at line 327 of file qt_gui.cpp.

{
  QSocketNotifier *qsn;
  
  // replace any already present notifier

  remove_notifier (sn);

  if (DEBUG_QT) cout << "ADD NOTIFIER " << sn->fd << LF;

  
  // installs both a read and a write notifier 
  // (the texmacs interface does not specify enough its needs)
  
  qsn = new QSocketNotifier(sn->fd, QSocketNotifier::Read, gui_helper);
  read_notifiers (sn) = (pointer) (qsn); 
  QObject::connect( qsn, SIGNAL(activated(int)), 
                    gui_helper, SLOT(doReadSocketNotification(int)) );

  qsn = new QSocketNotifier(sn->fd, QSocketNotifier::Write, gui_helper);
  write_notifiers (sn) = (pointer) (qsn);
  QObject::connect( qsn, SIGNAL(activated(int)), 
                    gui_helper, SLOT(doWriteSocketNotification(int)) );  
}

Here is the call graph for this function:

bool qt_gui_rep::check_event ( int  type)

Definition at line 832 of file qt_gui.cpp.

                                 {
//FIXME: add more types and refine, compare with X11 version.
  
// cout << "."; cout.flush();
//  return false;
  
  // do not interrupt while not in update
  // (for example while painting the icons in the menus)
  if (!updating || disable_check_event) return false;
  
  switch (type) {
    case INTERRUPT_EVENT:
      if (interrupted) return true;
      else {
        time_t now= texmacs_time ();
        if (now - timeout_time < 0) return false;
        timeout_time= now + time_credit;
        interrupted= (N(waiting_events) > 0);
        //if (interrupted) cout << "INTERRUPT " 
        //  << now << "------------------" << LF;
        return interrupted;
      }
    case INTERRUPTED_EVENT:
      return interrupted;
    default:
      return false;
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void qt_gui_rep::clear_selection ( string  key) [virtual]

Definition at line 199 of file qt_gui.cpp.

                                       {
  selection_t->reset (key);
  selection_s->reset (key);
  
  QClipboard *cb= QApplication::clipboard();
  QClipboard::Mode mode= QClipboard::Clipboard;
  bool owns= false;
  if (key == "primary");
  else if (key == "mouse" && cb->supportsSelection())
    mode= QClipboard::Selection;
  else return;

  const QMimeData *md= cb->mimeData (mode);
  if (md) owns= md->hasFormat ("application/x-texmacs");
  if (owns) cb->clear (mode);
}

Here is the caller graph for this function:

void qt_gui_rep::enable_notifier ( socket_notifier  sn,
bool  flag 
)

Definition at line 378 of file qt_gui.cpp.

{
  QSocketNotifier *qsn;
  qsn = (QSocketNotifier *)read_notifiers (sn);
  if (qsn) qsn->setEnabled (flag);
  qsn = (QSocketNotifier *)write_notifiers (sn);
  if (qsn) qsn->setEnabled (flag);
}

Here is the caller graph for this function:

Definition at line 312 of file qt_gui.cpp.

                        {
  QApplication *app = (QApplication*) QApplication::instance();
  update();
  //needs_update();
  app->exec();
}

Here is the call graph for this function:

Here is the caller graph for this function:

void qt_gui_rep::get_extents ( SI width,
SI height 
)

Definition at line 103 of file qt_gui.cpp.

                                              {
  QDesktopWidget* d= QApplication::desktop();
  int w = d->width();  // returns desktop width
  int h = d->height(); // returns desktop height        
  width = ((SI) w) * PIXEL;
  height= ((SI) h) * PIXEL;
}

Here is the caller graph for this function:

void qt_gui_rep::get_max_size ( SI width,
SI height 
)

Definition at line 112 of file qt_gui.cpp.

                                               {
  width = 8000 * PIXEL;
  height= 6000 * PIXEL;
}

Here is the caller graph for this function:

bool qt_gui_rep::get_selection ( string  key,
tree t,
string s,
string  format 
) [virtual]

Definition at line 136 of file qt_gui.cpp.

                                                                        {
  (void) format;
  QClipboard *cb= QApplication::clipboard ();
  QClipboard::Mode mode= QClipboard::Clipboard;
  bool owns= false;
  if (key == "primary" || (key == "mouse" && cb->supportsSelection ())) {
    if (key == "mouse") mode= QClipboard::Selection;
    const QMimeData *md= cb->mimeData (mode);
    if (md) owns= md->hasFormat ("application/x-texmacs-clipboard");  
  }
  else owns= true;
  
  s= "";
  t= "none";
  if (owns) {
    if (!selection_t->contains (key)) return false;
    t= copy (selection_t [key]);
    s= copy (selection_s [key]);
    return true;
  }
  else {
    QString originalText= cb->text (mode);
    QByteArray buf;
    if (format == "verbatim" &&
       get_preference ("verbatim->texmacs:encoding") == "utf-8")
      buf= originalText.toUtf8 ();
    else buf= originalText.toAscii ();
    if (!(buf.isEmpty())) s << string (buf.constData(), buf.size());
    t= tuple ("extern", s);
    return true;
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void qt_gui_rep::image_gc ( string  name = "*")

Definition at line 220 of file qt_gui.cpp.

{ (void) name; }

Definition at line 804 of file qt_gui.cpp.

                                         {
  add_event ( 
             queued_event (QP_COMMAND, close_box< command > (_cmd)));
}

Here is the call graph for this function:

void qt_gui_rep::process_command ( command  _cmd,
object  _args 
)

Definition at line 810 of file qt_gui.cpp.

                                                       {
  typedef pair<command, object > T;
  add_event ( 
             queued_event (QP_COMMAND_ARGS, close_box< T > (T(_cmd,_args))));
}

Here is the call graph for this function:

Definition at line 817 of file qt_gui.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void qt_gui_rep::process_keyboard_focus ( simple_widget_rep wid,
bool  has_focus,
time_t  t 
)

Definition at line 766 of file qt_gui.cpp.

                                                {
  typedef triple<widget, bool, time_t > T;
  add_event( 
    queued_event ( QP_KEYBOARD_FOCUS, close_box<T> (T(wid, has_focus, t)))); 
  //wid -> handle_keyboard_focus (has_focus, t);
  //needs_update ();
}

Here is the call graph for this function:

Definition at line 758 of file qt_gui.cpp.

                                                                          {
  typedef triple<widget, string, time_t > T;
  add_event( queued_event ( QP_KEYPRESS, close_box<T> (T(wid, key, t)))); 
 // wid -> handle_keypress (key, t);
 // needs_update ();
}

Here is the call graph for this function:

void qt_gui_rep::process_mouse ( simple_widget_rep wid,
string  kind,
SI  x,
SI  y,
int  mods,
time_t  t 
)

Definition at line 776 of file qt_gui.cpp.

                                                 {
  typedef quintuple<string, SI, SI, int, time_t > T1;
  typedef pair<widget, T1> T;
  add_event ( 
    queued_event ( QP_MOUSE, close_box<T> ( T (wid, T1 (kind, x, y, mods, t))))); 
//  wid -> handle_mouse (kind, x, y, mods, t);
//  needs_update ();
}

Here is the call graph for this function:

void qt_gui_rep::process_queued_events ( int  max = -1)

Definition at line 707 of file qt_gui.cpp.

                                          {
  // we process a maximum of max events. There are two kind of events: those
  // which need a pass on interpose_handler just after and the others. We count
  // only the first kind of events. In update() we call this function with
  // max=1 so that only one of these "sensible" events is handled. Otherwise
  // updating of internal TeXmacs structure become very slow. This can be 
  // considerer a limitation of the current implementation of interpose_handler
  // Likewise this function is just an hack to get things working properly.
  
  int count = 0;
  //cout << "(" << n << " events)"
  while ((max < 0) || (count<max))  {
    queued_event ev = next_event();
    if (ev.x1 == QP_NULL) break;
    process_event(ev);
    switch (ev.x1) {
        case QP_COMMAND:
        case QP_COMMAND_ARGS:
        case QP_SOCKET_NOTIFICATION:
        case QP_RESIZE:
        case QP_DELAYED_COMMANDS:
          break;
        default:
          count++;
          break;
    }
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void qt_gui_rep::process_resize ( simple_widget_rep wid,
SI  x,
SI  y 
)

Definition at line 787 of file qt_gui.cpp.

                                                                {
  typedef triple<widget, SI, SI > T;
  add_event(  queued_event ( QP_RESIZE, close_box<T> (T(wid, x, y)))); 
//  wid -> handle_notify_resize (x, y);
//  needs_update ();
}

Here is the call graph for this function:

Definition at line 795 of file qt_gui.cpp.

                                                             {
  add_event ( 
    queued_event (QP_SOCKET_NOTIFICATION, close_box< socket_notifier > (sn)));
//  sn -> notify ();
//  enable_notifier (sn, true);
// needs_update ();
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 353 of file qt_gui.cpp.

{  
  QSocketNotifier *qsn;

  if (DEBUG_QT) cout << "REMOVE NOTIFIER" << LF;

  // disable the (r/w) notifiers to prevent them to fire past this point
  // and schedule them for deletion at the end of the current runloop

  qsn = (QSocketNotifier *)read_notifiers [sn];
  if (qsn) {
    qsn->setEnabled (false);
    qsn->deleteLater ();
  }
  read_notifiers->reset (sn);

  qsn = (QSocketNotifier *)write_notifiers (sn);
  if (qsn) {
    qsn->setEnabled (false);
    qsn->deleteLater ();
  }
  write_notifiers->reset (sn);
}

Here is the caller graph for this function:

Definition at line 222 of file qt_gui.cpp.

{ (void) name; }
void qt_gui_rep::set_mouse_pointer ( string  curs_name,
string  mask_name 
)

Definition at line 224 of file qt_gui.cpp.

{ (void) curs_name; (void) mask_name; } ;
bool qt_gui_rep::set_selection ( string  key,
tree  t,
string  s,
string  format 
) [virtual]

Definition at line 170 of file qt_gui.cpp.

                                                                      {
  selection_t (key)= copy (t);
  selection_s (key)= copy (s);
        
  QClipboard *cb= QApplication::clipboard ();
  QClipboard::Mode mode= QClipboard::Clipboard;
  if (key == "primary");
  else if (key == "mouse" && cb->supportsSelection())
    mode= QClipboard::Selection;
  else return true;
  cb->clear (mode);

  char *selection = as_charp (s);
  cb->setText (selection, mode);
  QByteArray ba (selection);
  QMimeData *md= new QMimeData;
  md->setData ("application/x-texmacs-clipboard", ba);
  if (format == "verbatim" &&
      get_preference ("texmacs->verbatim:encoding") == "utf-8")
    md->setText (QString::fromUtf8 (selection));
  else md->setText (selection);
  cb->setMimeData (md, mode); 
  // according to the docs, ownership of mimedata is transferred to clipboard
  // so no memory leak here
  tm_delete_array (selection);
  return true;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void qt_gui_rep::show_wait_indicator ( widget  w,
string  message,
string  arg 
)

Definition at line 232 of file qt_gui.cpp.

                                                                      {
  (void) w; (void) message; (void) arg;
  
  if (DEBUG_QT)  cout << "show_wait_indicator \"" << message << "\"\"" << arg << "\"" << LF;

  qt_window_widget_rep *wid = static_cast<qt_window_widget_rep*> (w.rep);

  // we move the texmacs window during an operation. 
  // We need to disable updates of the window to avoid erasure of the canvas
  // area
  //  wid->wid->setUpdatesEnabled(false);
  
  //FIXME: we must center the wait widget wrt the current active window
  
  if (!waitWindow) {
    waitWindow = new QWidget (wid->wid->window());
    waitWindow->setWindowFlags (Qt::Window | Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint);
    QStackedLayout *layout = new QStackedLayout();
    layout->setSizeConstraint(QLayout::SetFixedSize);
    waitWindow->setLayout(layout);
  }
  
  if (waitDialogs.count()) {
    waitWindow->layout()->removeWidget(waitDialogs.last());
  }
  
  if (N(message)) {
    // push a new wait message in the list
    
    if (arg != "") message= message * " " * arg * "...";
    
    QLabel* lab = new  QLabel();
    lab->setFocusPolicy(Qt::NoFocus);
    lab->setMargin(15);
    lab->setText (to_qstring (tm_var_encode(message)));
    waitDialogs << lab;
  } else {
    // pop the next wait message from the list
    if (waitDialogs.count()) {
      waitDialogs.last()->deleteLater();
      waitDialogs.removeLast();
    }    
  }

  if (waitDialogs.count()) {
    waitWindow->layout()->addWidget(waitDialogs.last());
    waitWindow->updateGeometry();
    {
      QSize sz = waitWindow->geometry().size();
      QRect rect = QRect(QPoint(0,0),sz);
      //HACK: 
      // processEvents is needed to let Qt update windows coordinates in the case
      qApp->processEvents();
      //ENDHACK
      QPoint pt = wid->wid->window()->geometry().center();
      rect.moveCenter(pt);
      waitWindow->move(rect.topLeft());
      
    }
    waitWindow->show();
    qApp->processEvents();
    waitWindow->repaint();
  } else {
    waitWindow->close();
  }
  qApp->processEvents();
  QApplication::flush();
  
  
  //    wid->wid->setUpdatesEnabled(true);

  // next time we do update the dialog will disappear
  needs_update();  
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 863 of file qt_gui.cpp.

                    {
  // this is called by doUpdate, which in turns is fired by a timer activated in 
  // needs_update, and ensuring that interpose_handler is run during a pass in 
  // the eventloop afterwards we reactivate the timer with a pause 
  // (see FIXME below) 

  if (updating) {
    cout << "NESTED UPDATING: This should not happen" << LF;
    needs_update();
    return;
  }

  // cout << "<" << texmacs_time() << " " << N(delayed_queue) << " ";
  
  updatetimer->stop();
  updating = true;
  
  static int count_events = 0;
  static int max_proc_events = 10;

  time_t now = texmacs_time();
  needing_update = false;

  time_credit = 100 / (N(waiting_events)+1);

  
  // 1.
  // check if a wait dialog is active and in the case remove it.
  // if we are here then the long operation is finished.
  
  if (waitDialogs.count()) {
    waitWindow->layout()->removeWidget(waitDialogs.last());
    waitWindow->close();
    while (waitDialogs.count()) {
      waitDialogs.last()->deleteLater();
      waitDialogs.removeLast();
    }
  }
  
  
  // 2.
  // manage delayed commands
  
  if (wait_for_delayed_commands && (lapse <= now)) process_delayed_commands();
  
  // 3.
  // if there are pending events in the private queue process them up to some
  // limit in processed events is reached. 
  // if there are no events or the limit is reached then proceed to a redraw.

  if (N(waiting_events) == 0) {
    // if there are not waiting events call at least once
    // the interpose handler
    if (the_interpose_handler) the_interpose_handler();
  } else while ((N(waiting_events) > 0) && (count_events < max_proc_events)) {
    // cout << "e";
    //cout << "PROCESS QUEUED EVENTS START..."; cout.flush();
    process_queued_events (1);
    //cout << "AND END"  << LF;
    count_events++;
    
    //cout << "TYPESET START..."; cout.flush();
    if (the_interpose_handler) the_interpose_handler();
    //cout << "AND END" << LF;
  }
  
  {
    // redrawing
    // cout << "r";
    count_events = 0;
    
    // repaint invalid regions  
    interrupted = false;
    timeout_time = texmacs_time() + time_credit;
    
    //cout << "REPAINT START..."; cout.flush();
    
    QSetIterator<QTMWidget*> i(QTMWidget::all_widgets);
    while (i.hasNext()) {
      QTMWidget *w = i.next();
      w->repaint_invalid_regions();
    }
    //cout << "AND END" << LF;
  }
  
  
  if (N(waiting_events) > 0) needing_update = true;
  if (interrupted) needing_update = true;
 // if (interrupted)     cout << "*";

  if (nr_windows == 0) {
    qApp->quit();
  }
  
  time_t delay = lapse - texmacs_time();
  if (delay > 1000/6) delay = 1000/6;
  if (delay < 0) delay = 0;
  if (needing_update) delay = 0;
  //cout << delay << ">" <<  LF;
  updatetimer->start (delay);
  
  updating = false;
  

  // FIXME: we need to ensure that the interpose_handler is run at regular 
  //        intervals (1/6th of sec) so that informations on the footbar are 
  //        updated. (this should be better handled by promoting code in 
  //        tm_editor::apply_changes (which is activated only after idle 
  //        periods) at the level of delayed commands in the gui.
  //        The interval cannot be too small to keep CPU usage low in idle state
} 

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 42 of file qt_gui.hpp.

Definition at line 41 of file qt_gui.hpp.

Definition at line 40 of file qt_gui.hpp.

Definition at line 48 of file qt_gui.hpp.

Definition at line 47 of file qt_gui.hpp.

Definition at line 43 of file qt_gui.hpp.

QList<QLabel*> qt_gui_rep::waitDialogs

Definition at line 44 of file qt_gui.hpp.

Definition at line 45 of file qt_gui.hpp.


The documentation for this class was generated from the following files: