diff libgui/graphics/Canvas.cc @ 20080:908b68a98ba6

initial implementation of text annotations with Qt plotting * Canvas.h, Canvas.cc (Canvas::annotation_callback): New function. (Canvas::canvasMousePressEvent): Handle TextMode case. * MouseModeActionGroup.cc (MouseModeActionGroup::MouseModeActionGroup): Don't disable text annotation button.
author John W. Eaton <jwe@octave.org>
date Thu, 16 Apr 2015 08:47:20 -0400
parents 055ad6fbc910
children c6c5cb9c4743
line wrap: on
line diff
--- a/libgui/graphics/Canvas.cc	Thu Apr 16 00:13:26 2015 -0400
+++ b/libgui/graphics/Canvas.cc	Thu Apr 16 08:47:20 2015 -0400
@@ -27,6 +27,7 @@
 #include <QApplication>
 #include <QBitmap>
 #include <QCursor>
+#include <QInputDialog>
 #include <QList>
 #include <QMouseEvent>
 #include <QWheelEvent>
@@ -39,6 +40,9 @@
 #include "QtHandlesUtils.h"
 
 #include "gl2ps-renderer.h"
+#include "octave-qt-link.h"
+
+#include "builtin-defun-decls.h"
 
 namespace QtHandles
 {
@@ -147,6 +151,14 @@
 }
 
 void
+Canvas::annotation_callback (const octave_value_list& args)
+{
+  Ffeval (ovl ("annotation").append (args));
+
+  redraw ();
+}
+  
+void
 Canvas::canvasToggleAxes (const graphics_handle& handle)
 {
   gh_manager::auto_lock lock;
@@ -556,7 +568,39 @@
           break;
 
         case TextMode:
-          // Handle text insertion here.
+          {
+            QWidget *w = qWidget ();
+
+            if (! w)
+              break;
+
+            bool ok;
+
+            // FIXME: this dialog should allow multiple line text entry
+            // and also provide options for setting text properties of
+            // the text annotation.
+
+            QString text = QInputDialog::getText (w, "Annotation", "",
+                                                  QLineEdit::Normal, "", &ok);
+
+            if (! ok || text.isEmpty ())
+              break;
+
+            Matrix bb = axesObj.get_properties ().get_boundingbox (false);
+
+            QPoint pos = event->pos ();
+
+            Matrix position (1, 4);
+
+            position(0) = pos.x () / bb(2);
+            position(1) = 1.0 - (pos.y () / bb(3));
+            position(2) = pos.x () / bb(2);
+            position(3) = 1.0 - (pos.y () / bb(3));
+
+            octave_link::post_event (this, &Canvas::annotation_callback,
+                                     ovl ("textbox", position,
+                                          "string", text.toStdString ()));
+          }
           break;
 
         case PanMode: