Back to index

texmacs  1.0.7.15
Public Member Functions | Public Attributes | Protected Attributes | Friends
qt_chooser_widget_rep Class Reference

A file/directory chooser dialog, using native dialogs where available. More...

#include <qt_chooser_widget.hpp>

Inheritance diagram for qt_chooser_widget_rep:
Inheritance graph
[legend]
Collaboration diagram for qt_chooser_widget_rep:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 qt_chooser_widget_rep (command, string, bool)
 ~qt_chooser_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 ()
 A file chooser dialog with image preview for platforms other than Mac/Win FIXME: this is incomplete.
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
 Scheme closure to execute when the file is chosen.
command quit
 Execute when the dialog closes.
string type
bool save
string win_title
string directory
 Set this property sending SLOT_DIRECTORY to this widget.
coord2 position
coord2 size
string file
 Set this property sending SLOT_FILE to this widget.
list< widget_connectionin
list< widget_connectionout

Friends

class widget

Detailed Description

A file/directory chooser dialog, using native dialogs where available.

See widget.cpp for an explanation of send(), query(), read(), etc.

Definition at line 22 of file qt_chooser_widget.hpp.


Constructor & Destructor Documentation

qt_chooser_widget_rep::qt_chooser_widget_rep ( command  _cmd,
string  _type,
bool  _save 
)
Parameters:
_cmdScheme closure to execute after the dialog is closed.
_typeWhat kind of dialog to show. Can be one of "image", "directory", or any of the supported file formats: "texmacs", "tmml", "postscript", etc. See perform_dialog()

Definition at line 28 of file qt_chooser_widget.cpp.

 : qt_widget_rep (), cmd (_cmd), type (_type), save (_save), 
   position (coord2 (0, 0)), size (coord2 (100, 100)), file ("")
{
  if (DEBUG_QT)
    cout << "qt_chooser_widget_rep::qt_chooser_widget_rep type=\""
    << type << "\" save=\"" << save << "\"" << LF;
}

Definition at line 37 of file qt_chooser_widget.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_chooser_widget_rep::notify ( slot  s,
blackbox  new_val 
) [virtual]

Reimplemented from widget_rep.

Definition at line 127 of file qt_chooser_widget.cpp.

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

A file chooser dialog with image preview for platforms other than Mac/Win FIXME: this is incomplete.

Definition at line 269 of file qt_chooser_widget.cpp.

                                       {
    // int result;
  
  QTMFileDialog *dialog;
  QTMImageDialog *imgdialog= 0; // to avoid a dynamic_cast
  
  if (type  == "image")
    dialog= imgdialog= new QTMImageDialog (NULL, to_qstring (win_title), to_qstring(directory * "/" * file));
  else
    dialog= new QTMFileDialog (NULL, to_qstring (win_title), to_qstring(directory * "/" * file));
  
#if (defined(Q_WS_MAC) && (QT_VERSION >= 0x040500))
  dialog->setOptions(QFileDialog::DontUseNativeDialog);
#endif
  
  QPoint pos = to_qpoint(position);
    //cout << "Size :" << size.x1 << "," << size.x2 << LF;
  if (DEBUG_QT) {
    cout << "Position :" << pos.x() << "," << pos.y() << LF;
    cout << "Dir: " << directory * "/" * file << LF;
  }
  
  dialog->updateGeometry();
  QSize sz = dialog->sizeHint();
  QRect r; r.setSize(sz);
  r.moveCenter(pos);
  dialog->setGeometry(r);
  
  dialog->setViewMode (QFileDialog::Detail);
  if (type == "directory") {
    dialog->setFileMode(QFileDialog::Directory);
  } else if (type == "image") {
    dialog->setFileMode(QFileDialog::ExistingFile);
  } else {
    dialog->setFileMode(QFileDialog::AnyFile);
  }
  
#if (QT_VERSION >= 0x040400)
  if (type == "directory") {  
  } else if (type == "texmacs") {
    dialog->setNameFilter ("TeXmacs file (*.tm *.ts *.tp)");
    dialog->setDefaultSuffix ("tm");
  } else if (type == "image") {
    dialog->setNameFilter ("Image file (*.gif *.jpg *.jpeg *.pdf *.png *.pnm *.ps *.eps *.ppm *.svg *.tif *.tiff *.fig *.xpm)");
  } else if (type == "bibtex") {
    dialog->setNameFilter ("BibTeX file (*.bib)");
    dialog->setDefaultSuffix ("bib");
  } else if (type == "html") {
    dialog->setNameFilter ("Html file (*.htm *.html *.xhtml)");
    dialog->setDefaultSuffix ("html");
  } else if (type == "latex") {
    dialog->setNameFilter ("LaTeX file (*.tex *.ltx *.sty *.cls)");
    dialog->setDefaultSuffix ("tex");
  } else if (type == "stm") {
    dialog->setNameFilter ("Scheme file (*.stm *.scm)");
    dialog->setDefaultSuffix ("stm");
  } else if (type == "verbatim") {
    dialog->setNameFilter ("Verbatim file (*.txt)");
    dialog->setDefaultSuffix ("txt");
  } else if (type == "tmml") {
    dialog->setNameFilter ("XML file (*.tmml)");
    dialog->setDefaultSuffix ("tmml");  
  } else if (type == "pdf") {
    dialog->setNameFilter ("Pdf file (*.pdf)");
    dialog->setDefaultSuffix ("pdf");
  } else if (type == "postscript") {
    dialog->setNameFilter ("PostScript file (*.ps *.eps)");
    dialog->setDefaultSuffix ("ps");  
  }
#endif
  
  dialog->setLabelText(QFileDialog::Accept, "Ok");
  
  QStringList fileNames;
  if (dialog->exec ()) {
    fileNames = dialog->selectedFiles();
    if (fileNames.count() > 0) {
      file = from_qstring (fileNames[0]);
      url u = url_system (scm_unquote (file));
      QByteArray arr= to_qstring (as_string (u)).toLocal8Bit ();
      const char* cstr= arr.constData ();
      string localname = string ((char*) cstr);
      if (type == "image")
        file = "(list (url-system " *
        scm_quote (as_string (u)) *
        ") " * imgdialog->getParamsAsString () * ")";
      else
        file = "(url-system " * scm_quote (localname) * ")";
    }
  } else {
    file = "#f";
  }
  
  delete dialog;
  
  cmd ();
  if (!is_nil(quit)) quit ();
}

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 169 of file qt_chooser_widget.cpp.

{
  // Identify ourselves as already being a top-level window, even though
  // the dialog won't be displayed until later.
  //view->setProperty ("texmacs_window_widget",
  //                 QVariant::fromValue ((void*) this));
  win_title = s;
  quit = q;       // (NOT USED)
  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_chooser_widget_rep::query ( slot  s,
int  type_id 
) [virtual]

Reimplemented from widget_rep.

Definition at line 99 of file qt_chooser_widget.cpp.

                                                 {
  if (DEBUG_QT)
    cout << "qt_chooser_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:
    {
      TYPE_CHECK (type_id == type_helper<string>::id);
      if (DEBUG_QT) cout << "String: " << file << LF;
      return close_box<string> (file);
    }
    default:
      return qt_widget_rep::query (s, type_id);
  }
}

Here is the call graph for this function:

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

Reimplemented from widget_rep.

Definition at line 137 of file qt_chooser_widget.cpp.

                                                   {
  if (DEBUG_QT)
    cout << "qt_chooser_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 this;
    case SLOT_FILE:
      check_type_void (index, "SLOT_FILE");
      return this;
    case SLOT_DIRECTORY:
      check_type_void (index, "SLOT_DIRECTORY");
      return this;
    default:
      return qt_widget_rep::read(s,index);
  }
}

Here is the call graph for this function:

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

Reimplemented from widget_rep.

Definition at line 41 of file qt_chooser_widget.cpp.

                                                 {
  if (DEBUG_QT)
    cout << "qt_chooser_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;              
    case SLOT_STRING_INPUT:
        // send_string (THIS, "input", val);
      TYPE_CHECK (type_box (val) == type_helper<string>::id);
      if (DEBUG_QT) cout << "string input: " << open_box<string> (val) << LF;
      NOT_IMPLEMENTED
      break;
    case SLOT_INPUT_TYPE:
      TYPE_CHECK (type_box (val) == type_helper<string>::id);
      type = open_box<string> (val);
      break;
#if 0
    case SLOT_INPUT_PROPOSAL:
        //send_string (THIS, "default", val);
      NOT_IMPLEMENTED
      break;
#endif
    case SLOT_FILE:
        //send_string (THIS, "file", val);
      TYPE_CHECK (type_box (val) == type_helper<string>::id);
      if (DEBUG_QT) cout << "file: " << open_box<string> (val) << LF;
      file = open_box<string> (val);
      break;
    case SLOT_DIRECTORY:
      TYPE_CHECK (type_box (val) == type_helper<string>::id);
      directory = open_box<string> (val);
      directory = as_string (url_pwd () * url_system (directory));
      break;
      
    default:
      qt_widget_rep::send (s, val);
  }
}

Here is the call graph for this function:

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

Reimplemented from widget_rep.

Definition at line 159 of file qt_chooser_widget.cpp.

                                                              {
  if (DEBUG_QT)
    cout << "[qt_chooser_widget] ";
  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

Scheme closure to execute when the file is chosen.

Definition at line 24 of file qt_chooser_widget.hpp.

Set this property sending SLOT_DIRECTORY to this widget.

Definition at line 29 of file qt_chooser_widget.hpp.

Set this property sending SLOT_FILE to this widget.

Definition at line 32 of file qt_chooser_widget.hpp.

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 30 of file qt_chooser_widget.hpp.

Execute when the dialog closes.

(NOT USED)

Definition at line 25 of file qt_chooser_widget.hpp.

int abstract_struct::ref_count [inherited]

Definition at line 142 of file basic.hpp.

bool qt_chooser_widget_rep::save [protected]

Definition at line 27 of file qt_chooser_widget.hpp.

Definition at line 31 of file qt_chooser_widget.hpp.

Definition at line 26 of file qt_chooser_widget.hpp.

Definition at line 28 of file qt_chooser_widget.hpp.


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