Mercurial > hg > octave-nkf
changeset 20290: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 | 27c0285828f8 |
children | 8bfadb26afcd |
files | libgui/graphics/Canvas.cc libgui/graphics/Canvas.h libgui/graphics/MouseModeActionGroup.cc |
diffstat | 3 files changed, 49 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/libgui/graphics/Canvas.cc +++ b/libgui/graphics/Canvas.cc @@ -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:
--- a/libgui/graphics/Canvas.h +++ b/libgui/graphics/Canvas.h @@ -34,6 +34,8 @@ class QWheelEvent; class QWidget; +class octave_value_list; + namespace QtHandles { @@ -99,6 +101,8 @@ void updateCurrentPoint (const graphics_object& fig, const graphics_object& obj, QMouseEvent *event); + void annotation_callback (const octave_value_list& args); + private: graphics_handle m_handle; bool m_redrawBlocked;