Back to index

texmacs  1.0.7.15
Public Member Functions | Public Attributes | Protected Attributes | Friends
qt_input_widget_rep Class Reference
Inheritance diagram for qt_input_widget_rep:
Inheritance graph
[legend]
Collaboration diagram for qt_input_widget_rep:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 qt_input_widget_rep (command, array< string >)
 ~qt_input_widget_rep ()
virtual void send (slot s, blackbox val)
virtual blackbox query (slot s, int type_id)
virtual widget read (slot s, blackbox index)
virtual void write (slot s, blackbox index, widget w)
virtual void notify (slot s, blackbox new_val)
virtual widget plain_window_widget (string s, command q)
 Returns the widget as window.
void perform_dialog ()
virtual widget make_popup_widget ()
virtual widget popup_window_widget (string s)
virtual QAction * as_qaction ()
virtual QWidget * as_qwidget ()
 Returns the actual QWidget wrapped by this qt_widget_rep.
virtual QMenu * get_qmenu ()
 This method must not give ownership of the menu to the caller, thus allowing menu caching at the TeXmacs level.
virtual QWidget * get_canvas ()
 Get a texmacs canvas (if available).
virtual QLayoutItem * as_qlayoutitem ()
 Returns a QLayoutItem...
virtual tm_ostreamprint (tm_ostream &out)
virtual void connect (slot s, widget w2, slot s2)
virtual void deconnect (slot s, widget w2, slot s2)

Public Attributes

int ref_count

Protected Attributes

command cmd
array< qt_field_widgetfields
coord2 size
coord2 position
string win_title
int style
list< widget_connectionin
list< widget_connectionout

Friends

class widget

Detailed Description

Definition at line 35 of file qt_dialogues.cpp.


Constructor & Destructor Documentation

Definition at line 122 of file qt_dialogues.cpp.

                                        :
    qt_widget_rep (), cmd (_cmd),
    fields (N (_prompts)),
    size (coord2 (100, 100)), position (coord2 (0, 0)),
    win_title (""), style (0)
{
  for (int i=0; i < N(_prompts); i++) {
    fields[i] = tm_new<qt_field_widget_rep> (this);
    fields[i]->prompt = _prompts[i];
  }
}

Here is the call graph for this function:

Definition at line 134 of file qt_dialogues.cpp.

{}

Member Function Documentation

QAction * qt_widget_rep::as_qaction ( ) [virtual, inherited]

Reimplemented in qt_glue_widget_rep, qt_ui_element_rep, simple_widget_rep, qt_menu_rep, and qt_input_text_widget_rep.

Definition at line 106 of file qt_menu.cpp.

                                   {
  QAction *a = new QTMAction (NULL); 
  //  a->setSeparator(true);
  a->setEnabled(false);
  return a;
};
virtual QLayoutItem* qt_widget_rep::as_qlayoutitem ( ) [inline, virtual, inherited]

Returns a QLayoutItem...

Reimplemented in qt_ui_element_rep, and qt_input_text_widget_rep.

Definition at line 84 of file qt_widget.hpp.

{ return NULL; }
virtual QWidget* qt_widget_rep::as_qwidget ( ) [inline, virtual, inherited]

Returns the actual QWidget wrapped by this qt_widget_rep.

This is used to connect to signals, to change properties of the QWidget, etc.

Reimplemented in qt_glue_widget_rep, qt_ui_element_rep, qt_view_widget_rep, and qt_input_text_widget_rep.

Definition at line 66 of file qt_widget.hpp.

{ return NULL; }
void widget_rep::connect ( slot  s,
widget  w2,
slot  s2 
) [virtual, inherited]

Definition at line 150 of file widget.cpp.

                                               {
  widget_connection con (this, s, w2.rep, s2);
  insert (out, con);
  insert (w2->in, con);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void widget_rep::deconnect ( slot  s,
widget  w2,
slot  s2 
) [virtual, inherited]

Definition at line 157 of file widget.cpp.

                                                 {
  widget_connection con (this, s, w2.rep, s2);
  remove (out, con);
  remove (w2->in, con);
}
virtual QWidget* qt_widget_rep::get_canvas ( ) [inline, virtual, inherited]

Get a texmacs canvas (if available).

Reimplemented in simple_widget_rep.

Definition at line 80 of file qt_widget.hpp.

{ return NULL; }
virtual QMenu* qt_widget_rep::get_qmenu ( ) [inline, virtual, inherited]

This method must not give ownership of the menu to the caller, thus allowing menu caching at the TeXmacs level.

Called only by code which attaches root menus in the GUI elements.

Reimplemented in qt_ui_element_rep, and qt_menu_rep.

Definition at line 74 of file qt_widget.hpp.

{ return NULL; }
widget qt_widget_rep::make_popup_widget ( ) [virtual, inherited]

Reimplemented in qt_ui_element_rep, and qt_menu_rep.

Definition at line 34 of file qt_widget.cpp.

                                  {
  return this;
}
void qt_input_widget_rep::notify ( slot  s,
blackbox  new_val 
) [virtual]

Reimplemented from widget_rep.

Definition at line 193 of file qt_dialogues.cpp.

                                                     {
  if (DEBUG_QT)
    cout << "[qt_input_widget_rep] ";
  switch (s) {
  default: ;
  }
  qt_widget_rep::notify (s, new_val);
}

Definition at line 237 of file qt_dialogues.cpp.

                                    {
  if ((N(fields)==1) && (fields[0]->type == "question")) {
   // then use Qt messagebox for smoother, more standard UI
    QWidget * mainwindow = QApplication::activeWindow ();
    // main texmacs window. There are probably better ways...
    // Presently not checking if the windows has the focus;
    // In case it has not, it should be brought into focus
    // before calling the dialog
    QMessageBox * msgBox=new QMessageBox(mainwindow);
    //sets parent widget, so that appears at proper location   
    msgBox->setText(to_qstring (qt_translate (fields[0]->prompt)));
    msgBox->setStandardButtons(QMessageBox::Cancel);
    int choices = N(fields[0]->proposals);
    QVector<QPushButton*> buttonlist (choices);
    //allowing for any number of choices
    for(int i=0; i<choices; i++) {
      string blabel= "&" * upcase_first (fields[0]->proposals[i]);
      //capitalize the first character?
      buttonlist[i] = msgBox->addButton (to_qstring (qt_translate (blabel)), QMessageBox::ActionRole);
    }
    msgBox->setDefaultButton (buttonlist[0]); //default is first choice
    msgBox->setWindowTitle (to_qstring (qt_translate ("Question")));
    msgBox->setIcon (QMessageBox::Question);

    msgBox->exec();
    bool buttonclicked=false;
    for(int i=0; i<choices; i++) {
      if (msgBox->clickedButton() == buttonlist[i]) {
        fields[0] -> input = scm_quote (fields[0]->proposals[i]);
        buttonclicked=true;
        break;
      }
    }
    if (!buttonclicked) {fields[0] -> input = "#f";} //cancelled
  }

  else {  //usual dialogue layout
    QDialog d (0, Qt::Sheet);
    QVBoxLayout* vl = new QVBoxLayout(&d);

    QVector<QComboBox*> cbs (N (fields));

    for(int i=0; i<N(fields); i++) {
      QHBoxLayout *hl = new QHBoxLayout();

      QLabel *lab = new QLabel (to_qstring (tm_var_encode( (fields[i]->prompt))),&d);
      cbs[i] = new QComboBox(&d);
      cbs[i] -> setSizeAdjustPolicy (QComboBox::AdjustToMinimumContentsLength);
      cbs[i] -> setEditText (to_qstring(fields[i]->input));
      int minlen = 0;
      for(int j=0; j < N(fields[i]->proposals); j++) {
        QString str = to_qstring (fields[i]->proposals[j]);
        cbs[i] -> addItem (str);
        int c = str.count();
        if (c > minlen) minlen = c;
      }
      cbs[i] -> setMinimumContentsLength (minlen>50 ? 50 : (minlen < 2 ? 10 : minlen));
      cbs[i] -> setEditable (true);
      // apparently the following flag prevents Qt from substituting
      // an history item for an input when they differ only from
      // the point of view of case (upper/lower)
      // eg. if the history contains aAAAAa and you type AAAAAA then
      // the combo box will retain the string aAAAAa    
      cbs[i]->setDuplicatesEnabled(true); 
      cbs[i]->completer()->setCaseSensitivity(Qt::CaseSensitive);
      lab -> setBuddy (cbs[i]);
      hl -> addWidget (lab);
      hl -> addWidget (cbs[i]);
      vl -> addLayout (hl);
      
      if (ends (fields[i]->type, "file") || fields[i]->type == "directory") {
        // autocompletion
        //QCompleter *completer = new QCompleter(cbs[i]);
        QCompleter *completer = cbs[i]->completer();
        QDirModel *dirModel = new QDirModel();
        completer->setModel(dirModel);
        //cbs[i]->setCompleter(completer);
      }
    }
    
    {
      QDialogButtonBox* buttonBox =
        new QDialogButtonBox (QDialogButtonBox::Ok | QDialogButtonBox::Cancel,
                              Qt::Horizontal, &d);
      QObject::connect (buttonBox, SIGNAL (accepted()), &d, SLOT (accept()));
      QObject::connect (buttonBox, SIGNAL (rejected()), &d, SLOT (reject()));
      vl -> addWidget (buttonBox);
    }
    //  d.setLayout (vl);
    d.setWindowTitle(to_qstring(win_title));
    QPoint pos = to_qpoint(position);
    //cout << "Size :" << size.x1 << "," << size.x2 << LF;
    //cout << "Position :" << pos.x() << "," << pos.y() << LF;
    
    d.updateGeometry();
    QSize sz = d.sizeHint();
    QRect r; r.setSize(sz);
    r.moveCenter(pos);
    d.setGeometry(r);
    
    int result = d.exec ();
    if (result == QDialog::Accepted) {
      for(int i=0; i<N(fields); i++) {
        QString item = cbs[i]->currentText();
        fields[i] -> input = scm_quote (from_qstring (item));
      }
    } else {
      for(int i=0; i<N(fields); i++) {
        fields[i] -> input = "#f";
      }
    }
  }

  cmd ();
}

Here is the call graph for this function:

Here is the caller graph for this function:

Returns the widget as window.

Each TeXmacs widget can at some point be asked to present itself into a window. The scheme-originating function window_create() expects this method in every widget. Widgets which are windows must declare themselves to be via the QProperty "texmacs_window_widget". This will be checked when processing messages from scheme asking to actually display the window. See qt_view_widget_rep::read() and qt_window_widget_rep::qt_window_widget_rep().

Parameters:
s(Often?) a title for the window.
q
Returns:
A pointer to this widget.

Reimplemented from qt_widget_rep.

Definition at line 229 of file qt_dialogues.cpp.

{
  win_title = s;
  (void) q;  // FIXME? ignore ok?
  return this;
}
widget qt_widget_rep::popup_window_widget ( string  s) [virtual, inherited]

Reimplemented in qt_ui_element_rep, and qt_menu_rep.

Definition at line 39 of file qt_widget.cpp.

                                            {
  (void) s;
  return widget ();
}
tm_ostream & widget_rep::print ( tm_ostream out) [virtual, inherited]

Reimplemented in wk_widget_rep.

Definition at line 207 of file widget.cpp.

                                  {
  return out << "widget";
}
blackbox qt_input_widget_rep::query ( slot  s,
int  type_id 
) [virtual]

Reimplemented from widget_rep.

Definition at line 169 of file qt_dialogues.cpp.

                                               {
  if (DEBUG_QT)
    cout << "qt_input_widget_rep::query " << slot_name(s) << LF;
  switch (s) {
  case SLOT_POSITION:
    {
      typedef pair<SI,SI> coord2;
      TYPE_CHECK (type_id == type_helper<coord2>::id);
      return close_box<coord2> (position);
    }
  case SLOT_SIZE:
    {
      typedef pair<SI,SI> coord2;
      TYPE_CHECK (type_id == type_helper<coord2>::id);
      return close_box<coord2> (size);
    }
  case SLOT_STRING_INPUT:
    return fields[0]->query (s, type_id);
  default:
    return qt_widget_rep::query (s, type_id);
  }
}

Here is the call graph for this function:

widget qt_input_widget_rep::read ( slot  s,
blackbox  index 
) [virtual]

Reimplemented from widget_rep.

Definition at line 203 of file qt_dialogues.cpp.

                                                 {
  if (DEBUG_QT)
    cout << "qt_input_widget_rep::read " << slot_name(s) << LF;
  switch (s) {
  case SLOT_WINDOW:
    check_type_void (index, "SLOT_WINDOW");
    return this;
  case SLOT_FORM_FIELD:
    check_type<int> (index, "SLOT_FORM_FIELD");
    return (widget_rep*) (fields [open_box<int> (index)].rep);
  default:
    return qt_widget_rep::read (s, index);
  }
}

Here is the call graph for this function:

void qt_input_widget_rep::send ( slot  s,
blackbox  val 
) [virtual]

Reimplemented from widget_rep.

Definition at line 137 of file qt_dialogues.cpp.

                                               {
  if (DEBUG_QT)
    cout << "qt_input_widget_rep::send " << slot_name(s) << LF;

  switch (s) {
  case SLOT_VISIBILITY:
    {   
      check_type<bool> (val, "SLOT_VISIBILITY");
      bool flag = open_box<bool> (val);
      (void) flag;
      NOT_IMPLEMENTED
    }   
    break;
  case SLOT_SIZE:
    TYPE_CHECK (type_box (val) == type_helper<coord2>::id);
    size = open_box<coord2> (val);
    break;
  case SLOT_POSITION:
    TYPE_CHECK (type_box (val) == type_helper<coord2>::id);
    position = open_box<coord2> (val);
    break;
  case SLOT_KEYBOARD_FOCUS:
    TYPE_CHECK (type_box (val) == type_helper<bool>::id);
    perform_dialog ();
    break;
  default:
    qt_widget_rep::send (s, val);
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void qt_input_widget_rep::write ( slot  s,
blackbox  index,
widget  w 
) [virtual]

Reimplemented from widget_rep.

Definition at line 219 of file qt_dialogues.cpp.

                                                            {
  if (DEBUG_QT)
    cout << "[qt_input_widget_rep] ";
  switch (s) {
  default:
    qt_widget_rep::write (s, index, w);
  }
}

Friends And Related Function Documentation

friend class widget [friend, inherited]

Definition at line 59 of file widget.hpp.


Member Data Documentation

Definition at line 37 of file qt_dialogues.cpp.

Definition at line 38 of file qt_dialogues.cpp.

list<widget_connection> widget_rep::in [protected, inherited]

Definition at line 36 of file widget.hpp.

list<widget_connection> widget_rep::out [protected, inherited]

Definition at line 37 of file widget.hpp.

Definition at line 39 of file qt_dialogues.cpp.

int abstract_struct::ref_count [inherited]

Definition at line 142 of file basic.hpp.

Definition at line 39 of file qt_dialogues.cpp.

int qt_input_widget_rep::style [protected]

Definition at line 41 of file qt_dialogues.cpp.

Definition at line 40 of file qt_dialogues.cpp.


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