texmacs-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Texmacs-dev] UI improvements and export selection as graphics


From: Philippe Joyez
Subject: [Texmacs-dev] UI improvements and export selection as graphics
Date: Fri, 15 Jan 2010 15:32:19 -0800 (PST)

Dear all,

I propose here a couple of simple modifications and additions. 

The first ones aim to make the UI more standard, so that new users
immediately feel "at home". 

-For simple Yes/No questions in QtTexmacs, the ComboBox-based dialogue is
replaced by a simple MessageBox.

-Something I already posted a month ago or so : change the behavior of the
selection so that it gets overwritten if you type or paste something. I have
been testing this for a while and have found no side effect yet (though I
have not played with client-server setups).

-finally, a wording change ("buffer" to "document") to avoid programmer's
jargon


The other modifications are to enable seamless export of the selection as
graphics:

-print_snippet and printer are tuned so that they now generate eps files
with appropriate extension and header, so that converters properly recognize
them.

-added the capability to export the selection as graphics, either in a file
or on the clipboard, via Qt. It supports many formats but I mainly focused
on getting good svg.

As a result I can now directly copy-paste perfect svg equations in inkscape
(v >= 0.47) or bitmaps in any application. I'm really happy with that
because previously I had no convenient ways of graphically editing
good-looking equations in linux.

best,
Philippe



$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
$ simple Qt msgBox for Yes/No questions
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
diff -u -r source_copy/src/Plugins/Qt/qt_dialogues.cpp
working_copy/src/Plugins/Qt/qt_dialogues.cpp
--- source_copy/src/Plugins/Qt/qt_dialogues.cpp 2010-01-11
19:53:16.000000000 +0100
+++ working_copy/src/Plugins/Qt/qt_dialogues.cpp        2010-01-11
20:04:00.000000000 +0100
@@ -470,6 +470,33 @@
 
 void
 qt_input_widget_rep::perform_dialog() {
+ if ((N(fields)==1) && (fields[0]->type == "question")) // then use simple
msgbox for smoother, more standard UI
+ {   QWidget * activewindow= QApplication::activeWindow ();
+     QMessageBox * msgBox=new QMessageBox::QMessageBox(activewindow);//sets
parent widget, so that appears at proper location       
+     msgBox->setText(to_qstring(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="&"*(fields[0]->proposals[i]);//capitalize the 
first
character?
+               buttonlist[i] = msgBox->addButton(to_qstring(blabel),
QMessageBox::ActionRole);
+                }
+     msgBox->setDefaultButton(buttonlist[0]); //default is first choice
+     msgBox->setWindowTitle (to_qstring("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);
 
@@ -536,6 +563,7 @@
       fields[i] -> input = "#f";
     }
   }
+ }//\else usual dialogue layout
   cmd ();
 }
 
diff -u -r source_copy/src/Plugins/Qt/qt_dialogues.hpp
working_copy/src/Plugins/Qt/qt_dialogues.hpp
--- source_copy/src/Plugins/Qt/qt_dialogues.hpp 2010-01-11
19:53:16.000000000 +0100
+++ working_copy/src/Plugins/Qt/qt_dialogues.hpp        2010-01-11
20:04:00.000000000 +0100
@@ -13,5 +13,6 @@
 #define QT_DIALOGUES_HPP
 
 #include "qt_widget.hpp"
+#include <QApplication>
 
 #endif // defined QT_DIALOGUES_HPP
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
$ enable overwrite of selection
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
diff -u -r source_copy/src/Edit/Modify/edit_text.cpp
working_copy/src/Edit/Modify/edit_text.cpp
--- source_copy/src/Edit/Modify/edit_text.cpp   2010-01-11 19:53:17.000000000
+0100
+++ working_copy/src/Edit/Modify/edit_text.cpp  2010-01-11 20:04:00.000000000
+0100
@@ -197,6 +197,7 @@
 
 void
 edit_text_rep::insert_tree (tree t, path p_in_t) {
+  selection_cut ("none") ; // delete existing selection to get standard
overwrite behavior
   if (is_atomic (t) && (p_in_t == end (t)) &&
       is_atomic (subtree (et, path_up (tp))))
     insert (tp, t);
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
$ wording change
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
diff -u -r source_copy/TeXmacs/progs/texmacs/texmacs/tm-server.scm
working_copy/TeXmacs/progs/texmacs/texmacs/tm-server.scm
--- source_copy/TeXmacs/progs/texmacs/texmacs/tm-server.scm     2010-01-11
19:53:23.000000000 +0100
+++ working_copy/TeXmacs/progs/texmacs/texmacs/tm-server.scm    2010-01-12
00:03:00.000000000 +0100
@@ -96,7 +96,7 @@
   (dialogue
     (if (or (not (buffer-unsaved?))
            (dialogue-confirm?
-            "The buffer has not been saved. Really close it?" #f))
+            "The document has not been saved. Really close it?" #f))
        (kill-buffer))))
 
 (tm-define (safely-kill-window)
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
$ fix header of eps files
$ (otherwise boundingbox not always taken into account properly) 
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
diff -u -r source_copy/src/Graphics/Renderer/printer.cpp
working_copy/src/Graphics/Renderer/printer.cpp
--- source_copy/src/Graphics/Renderer/printer.cpp       2010-01-11
19:53:15.000000000 +0100
+++ working_copy/src/Graphics/Renderer/printer.cpp      2010-01-12
00:42:31.000000000 +0100
@@ -57,7 +57,9 @@
   load_string ("$TEXMACS_PATH/misc/convert/color.pro", color_pro, true);
   load_string ("$TEXMACS_PATH/misc/convert/texps.pro", texps_pro, true);
   
-  prologue   << "%!PS-Adobe-2.0\n"
+  prologue   << "%!PS-Adobe-2.0";
+  if (suffix (ps_file_name) == "eps") {prologue   << " EPSF-2.0";}
+  prologue   << "\n"
             << "%%Creator: TeXmacs-" TEXMACS_VERSION "\n"
             << "%%Title: " << as_string (tail (ps_file_name)) << "\n"
             << "%%Pages: " << as_string (nr_pages) << "\n"
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
$ implement graphics export of selection,
$ both as file or through clipboard.
$ This makes use of better converters ps2pdf and pdf2svg 
$ (ps2pdf comes with gs, but pdf2svg creates a new dependency)
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
diff -u -r source_copy/src/Edit/Editor/edit_main.cpp
working_copy/src/Edit/Editor/edit_main.cpp
--- source_copy/src/Edit/Editor/edit_main.cpp   2010-01-11 19:53:17.000000000
+0100
+++ working_copy/src/Edit/Editor/edit_main.cpp  2010-01-15 19:23:30.000000000
+0100
@@ -20,6 +20,7@@
 #include "drd_std.hpp"
 #include "message.hpp"
 #include <setjmp.h>
+#include "Plugins/Qt/qt_gui.hpp"
 #ifdef EXPERIMENTAL
 #include "../../Style/Memorizer/clean_copy.hpp"
 #endif
@@ -249,7 +252,7 @@
   if (b->x4 - b->x3 >= 5*PIXEL && b->y4 - b->y3 >= 5*PIXEL) {
     if (ps) make_eps (name, b, dpi);
     else {
-      url temp= url_temp ("eps");
+      url temp= url_temp (".eps"); //some converters are confused if no dot
       make_eps (temp, b, dpi);
       system ("convert", temp, name);
       ::remove (temp);
@@ -260,6 +263,50 @@
   return a;
 }
 
+bool
+edit_main_rep::export_selection_as_graphics (string output) {
+//output must either be a full file path or an extension type
+    bool clipboard=false;
+    url name = url (output);
+    if ((suffix(name)=="")&&(head(name)==".")) //if name contains no
extension & no path, then assume it's only an extension type and send to
clipboard
+             {clipboard =true;
+             name= url_temp ("." * output); //make temporary file with
given extension 
+            }
+    tree t= selection_get ();
+    string mode= get_env_string (MODE);
+    if (mode == "math") // if selection is part of math need to
re-encapsulate it with math to obtain proper typesetting
+       {
+//        t= tree (WITH, copy (MODE), copy (mode), t);
+        t= compound ("equation*", compound ("document", t)); // equation*
generally preferable 
+        }
+   if (suffix(name) == "eps") {print_snippet (name, t);}
+   else 
+      {url temp= url_temp (".eps");
+      print_snippet (temp, t);
+      if (suffix (name) == "pdf" )
+         {system ("ps2pdf -dEPSCrop", temp, name);}
+      else if (suffix (name) == "svg")
+              {url temp2= url_temp (".pdf");
+               system ("ps2pdf -dEPSCrop", temp, temp2);
+              system ("pdf2svg", temp2, name);
+               ::remove (temp2);
+              }
+            else{system ("convert", temp, name);}
+        ::remove (temp);
+      }
+   if (clipboard) { 
+#ifdef QTTEXMACS
+        the_gui->put_graphics_on_clipboard (name);
+        ::remove (name);
+        return true;
+#else 
+        ::remove (name);
+        return false;
+#endif
+        }
+   else {return true;}
+}
+

/******************************************************************************
 * Evaluation of expressions

******************************************************************************/
diff -u -r source_copy/src/Edit/Editor/edit_main.hpp
working_copy/src/Edit/Editor/edit_main.hpp
--- source_copy/src/Edit/Editor/edit_main.hpp   2010-01-11 19:53:17.000000000
+0100
+++ working_copy/src/Edit/Editor/edit_main.hpp  2010-01-15 10:01:58.000000000
+0100
@@ -68,6 +68,7 @@
   void print_buffer (string first="1", string last="1000000");
   void export_ps (url ps_name, string first="1", string last="1000000");
   array<int> print_snippet (url u, tree t);
+  bool export_selection_as_graphics (string output);
 
   void footer_eval (string s);
   tree the_line ();
diff -u -r source_copy/src/Edit/editor.hpp working_copy/src/Edit/editor.hpp
--- source_copy/src/Edit/editor.hpp     2010-01-11 19:53:17.000000000 +0100
+++ working_copy/src/Edit/editor.hpp    2010-01-15 10:01:49.000000000 +0100
@@ -481,6 +481,7 @@
   virtual void export_ps (url ps_name,
                          string first="1", string last="1000000") = 0;
   virtual array<int> print_snippet (url u, tree t) = 0;
+  virtual bool export_selection_as_graphics (string output) = 0;
   virtual void footer_eval (string s) = 0;
   virtual tree the_line () = 0;
   virtual tree the_root () = 0;
diff -u -r source_copy/src/Guile/Glue/build-glue-editor.scm
working_copy/src/Guile/Glue/build-glue-editor.scm
--- source_copy/src/Guile/Glue/build-glue-editor.scm    2010-01-11
19:53:17.000000000 +0100
+++ working_copy/src/Guile/Glue/build-glue-editor.scm   2010-01-15
10:01:38.000000000 +0100
@@ -257,6 +257,7 @@
   (print print_buffer (void))
   (print-pages print_buffer (void string string))
   (print-snippet print_snippet (array_int url content))
+  (export-selection-as-graphics export_selection_as_graphics (bool string))
   (export-postscript export_ps (void url))
   (export-pages-postscript export_ps (void url string string))
   (footer-eval footer_eval (void string))
diff -u -r source_copy/src/Plugins/Qt/qt_gui.cpp
working_copy/src/Plugins/Qt/qt_gui.cpp
--- source_copy/src/Plugins/Qt/qt_gui.cpp       2010-01-11 19:53:16.000000000
+0100
+++ working_copy/src/Plugins/Qt/qt_gui.cpp      2010-01-14 23:56:24.000000000
+0100
@@ -25,6 +25,12 @@
 #include "QTMWidget.hpp"
 #include "qt_renderer.hpp" // for the_qt_renderer
 
+#include "file.hpp" //added for copy_as_graphics
+#include <QMimeData>
+#include <QByteArray>
+#include <QApplication>
+#include <QImage>
+
 #include "tm_link.hpp" // for number_of_servers
 
 #include "Scheme/object.hpp"
@@ -824,6 +830,38 @@
   the_gui->clear_selection (key);
 }
 
+bool
+qt_gui_rep::put_graphics_on_clipboard (url file) {
+   string extension= suffix (file) ;
+   
+  // for bitmaps this works :
+  if ((extension=="bmp")||(extension=="png")||(extension=="jpg") ||
(extension=="jpeg")){ 
+   QImage myqimage=QImage ( as_charp (as_string (file)) );
+   QClipboard *clipboard = QApplication::clipboard();
+   clipboard->setImage(myqimage);
+   }
+  else { //vector formats
+   // Are there applications receiving eps, pdf,... through the clipboard?
+   // I have not experimented with EMF/WMF (windows) or SVM (Ooo)
+   QString mime="image/*"; // generic image format;
+   if(extension=="eps")        mime="application/postscript";
+   if(extension=="pdf")        mime="application/pdf";
+   if(extension=="svg")        mime="image/svg+xml"; //this works with Inskcape
version >= 0.47
+   
+   string filecontent;
+   load_string (as_string (file), filecontent, true);
+
+   QByteArray rawdata= as_charp (filecontent);
+
+   QMimeData *mymimeData = new QMimeData;
+   mymimeData->setData(mime, rawdata);
+
+   QClipboard *clipboard = QApplication::clipboard();
+   clipboard->setMimeData(mymimeData);// default mode=
QClipboard::Clipboard 
+   }
+  return true;
+}
+

/******************************************************************************
 * Miscellaneous

******************************************************************************/
diff -u -r source_copy/src/Plugins/Qt/qt_gui.hpp
working_copy/src/Plugins/Qt/qt_gui.hpp
--- source_copy/src/Plugins/Qt/qt_gui.hpp       2010-01-11 19:53:16.000000000
+0100
+++ working_copy/src/Plugins/Qt/qt_gui.hpp      2010-01-14 23:55:14.000000000
+0100
@@ -59,6 +59,7 @@
   virtual bool get_selection (string key, tree& t, string& s);
   virtual bool set_selection (string key, tree t, string s);
   virtual void clear_selection (string key);
+  bool put_graphics_on_clipboard (url file);
 
   /* miscellaneous */
   void image_gc (string name= "*");

$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$

finally, before compiling :
run src/Guile/Glue/build-glue build-glue-editor.scm glue_editor.cpp

and add a quick menu access to these new functions in your
~/.Texmacs/progs/my-init-texmacs.scm :

;*************************************"
; my menu 
;*************************************

(menu-extend texmacs-extra-menu
  (=> "MyMenu"
    ("export selection as image..."
      (dialogue (let ((myfile "")) 
                                (
                                (set! myfile (dialogue-url "save as... filename 
with extension" "*") )
                                (if (!= myfile "") (export-selection-as-graphics
(url->string myfile))) ; no warning on overwrite!
                                )
                                )
                )    
       )
    )
    (-> "copy selection as image"
      ("bitmap" (export-selection-as-graphics "png"))
      ("vector (svg)" (export-selection-as-graphics "svg"))
      
    )
  )
)

-- 
View this message in context: 
http://old.nabble.com/UI-improvements-and-export-selection-as-graphics-tp27185075p27185075.html
Sent from the Gnu - Texmacs - Dev mailing list archive at Nabble.com.





reply via email to

[Prev in Thread] Current Thread [Next in Thread]