GNU Octave  4.4.1
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
Figure.cc
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 2011-2018 Michael Goffioul
4 
5 This file is part of Octave.
6 
7 Octave is free software: you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
11 
12 Octave is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16 
17 You should have received a copy of the GNU General Public License
18 along with Octave; see the file COPYING. If not, see
19 <https://www.gnu.org/licenses/>.
20 
21 */
22 
23 #if defined (HAVE_CONFIG_H)
24 # include "config.h"
25 #endif
26 
27 #include <QAction>
28 #include <QActionEvent>
29 #include <QActionGroup>
30 #include <QApplication>
31 #include <QClipboard>
32 #include <QEvent>
33 #include <QFileDialog>
34 #include <QFileInfo>
35 #include <QFrame>
36 #include <QImage>
37 #include <QMainWindow>
38 #include <QMenu>
39 #include <QMenuBar>
40 #include <QMessageBox>
41 #include <QtDebug>
42 #include <QTimer>
43 #include <QToolBar>
44 
45 #include "Canvas.h"
46 #include "Container.h"
47 #include "Figure.h"
48 #include "FigureWindow.h"
49 #include "MouseModeActionGroup.h"
50 #include "QtHandlesUtils.h"
51 
52 #include "file-ops.h"
53 #include "unwind-prot.h"
54 #include "utils.h"
55 #include "version.h"
56 
57 #include "octave-qt-link.h"
58 
59 #include "builtin-defun-decls.h"
60 
61 namespace QtHandles
62 {
63 
65 
66  static bool
68  {
70 
71  Matrix kids = fp.get_all_children ();
72 
73  for (int i = 0; i < kids.numel (); i++)
74  {
76 
77  if (go && (go.isa ("uicontrol") || go.isa ("uipanel")
78  || go.isa ("uibuttongroup")))
79  return true;
80  }
81 
82  return false;
83  }
84 
85  static bool
87  {
89 
90  Matrix kids = fp.get_all_children ();
91 
92  for (int i = 0; i < kids.numel (); i++)
93  {
95 
96  if (go && go.isa ("uimenu") &&
97  go.get ("visible").string_value () == "on")
98  return true;
99  }
100 
101  return false;
102  }
103 
104  static QRect
106  {
107  QRect r;
108 
109  if (bb.numel () == 4)
110  {
111  r = QRect (octave::math::round (bb(0)), octave::math::round (bb(1)),
112  octave::math::round (bb(2)), octave::math::round (bb(3)));
113  if (! r.isValid ())
114  r = QRect ();
115  }
116 
117  return r;
118  }
119 
120  Figure*
122  {
123  return new Figure (go, new FigureWindow ());
124  }
125 
127  : Object (go, win), m_blockUpdates (false), m_figureToolBar (nullptr),
128  m_menuBar (nullptr), m_innerRect (), m_outerRect (),
129  m_mouseModeGroup (nullptr)
130  {
131  m_container = new Container (win);
132  win->setCentralWidget (m_container);
133 
134  figure::properties& fp = properties<figure> ();
135 
136  // Status bar
137  m_statusBar = win->statusBar ();
138  int boffset = 0;
139 
140  // Toolbar and menubar
142  int toffset = 0;
143 
144  if (fp.toolbar_is ("figure") ||
145  (fp.toolbar_is ("auto") && fp.menubar_is ("figure") &&
146  ! hasUiControlChildren (fp)))
147  {
148  toffset += m_figureToolBar->sizeHint ().height ();
149  boffset += m_statusBar->sizeHint ().height ();
150  }
151  else
152  {
153  m_figureToolBar->hide ();
154  m_statusBar->hide ();
155  }
156 
157  if (fp.menubar_is ("figure") || hasUiMenuChildren (fp))
158  toffset += m_menuBar->sizeHint ().height ();
159  else
160  m_menuBar->hide ();
161 
164 
165  win->setGeometry (m_innerRect.adjusted (0, -toffset, 0, boffset));
166 
167  // Enable mouse tracking unconditionally
169 
170  // When this constructor gets called all properties are already
171  // set, even non default. We force "update" here to get things right.
172 
173  // Figure title
174  update (figure::properties::ID_NUMBERTITLE);
175 
176  // Decide what keyboard events we listen to
178  update (figure::properties::ID_KEYPRESSFCN);
179  update (figure::properties::ID_KEYRELEASEFCN);
180 
181  // modal style
182  update (figure::properties::ID_WINDOWSTYLE);
183 
184  // Visibility
185  update (figure::properties::ID_VISIBLE);
186 
187  connect (this, SIGNAL (asyncUpdate (void)),
188  this, SLOT (updateContainer (void)));
189 
190  win->addReceiver (this);
191  m_container->addReceiver (this);
192  }
193 
195  { }
196 
197  static std::string
199  {
200  switch (mode)
201  {
202  case NoMode:
203  return "none";
204 
205  case RotateMode:
206  return "rotate";
207 
208  case ZoomInMode:
209  return "zoom in";
210 
211  case ZoomOutMode:
212  return "zoom out";
213 
214  case PanMode:
215  return "pan";
216 
217  case TextMode:
218  return "text";
219 
220  case SelectMode:
221  return "select";
222 
223  default:
224  break;
225  }
226 
227  return "none";
228  }
229 
230  static MouseMode
232  {
233  if (mode == "none")
234  return NoMode;
235  else if (mode == "rotate")
236  return RotateMode;
237  else if (mode == "zoom in")
238  return ZoomInMode;
239  else if (mode == "zoom out")
240  return ZoomOutMode;
241  else if (mode == "pan")
242  return PanMode;
243  else if (mode == "text")
244  return TextMode;
245  else if (mode == "select")
246  return SelectMode;
247  else
248  return NoMode;
249  }
250 
251  QString
253  {
255 
256  const figure::properties& fp = properties<figure> ();
257 
258  std::string name = fp.get_filename ();
259 
260  return QString::fromStdString (name);
261  }
262 
263  void
264  Figure::setFileName (const QString& name)
265  {
267 
268  figure::properties& fp = properties<figure> ();
269 
270  fp.set_filename (name.toStdString ());
271  }
272 
273  MouseMode
275  {
277 
278  const figure::properties& fp = properties<figure> ();
279 
280  std::string mode = fp.get___mouse_mode__ ();
281 
282  if (mode == "zoom")
283  {
284  octave_scalar_map zm = fp.get___zoom_mode__ ().scalar_map_value ();
285 
286  std::string direction = zm.getfield ("Direction").string_value ();
287 
288  mode += ' ' + direction;
289  }
290 
291  return mouse_mode_from_string (mode);
292  }
293 
294  void
296  {
297  QMainWindow *win = qWidget<QMainWindow> ();
298 
299  m_figureToolBar = win->addToolBar (tr ("Figure ToolBar"));
300  m_figureToolBar->setMovable (false);
301  m_figureToolBar->setFloatable (false);
302 
304  connect (m_mouseModeGroup, SIGNAL (modeChanged (MouseMode)),
305  SLOT (setMouseMode (MouseMode)));
306  m_figureToolBar->addActions (m_mouseModeGroup->actions ());
307 
308  QAction *toggle_axes = m_figureToolBar->addAction (tr ("Axes"));
309  connect (toggle_axes, SIGNAL (triggered (void)),
310  this, SLOT (toggleAxes (void)));
311 
312  QAction *toggle_grid = m_figureToolBar->addAction (tr ("Grid"));
313  connect (toggle_grid, SIGNAL (triggered (void)),
314  this, SLOT (toggleGrid (void)));
315 
316  QAction *auto_axes = m_figureToolBar->addAction (tr ("Autoscale"));
317  connect (auto_axes, SIGNAL (triggered (void)),
318  this, SLOT (autoAxes (void)));
319 
320  m_menuBar = new MenuBar (win);
321  win->setMenuBar (m_menuBar);
322 
323  QMenu *fileMenu = m_menuBar->addMenu (tr ("&File"));
324  fileMenu->menuAction ()->setObjectName ("builtinMenu");
325  fileMenu->addAction (tr ("&Save"), this, SLOT (fileSaveFigure (bool)));
326  fileMenu->addAction (tr ("Save &As"), this, SLOT (fileSaveFigureAs (void)));
327  fileMenu->addSeparator ();
328  fileMenu->addAction (tr ("&Close Figure"), this,
329  SLOT (fileCloseFigure (void)), Qt::CTRL | Qt::Key_W);
330 
331  QMenu *editMenu = m_menuBar->addMenu (tr ("&Edit"));
332  editMenu->menuAction ()->setObjectName ("builtinMenu");
333  editMenu->addAction (tr ("Cop&y"), this, SLOT (editCopy (bool)),
334  Qt::CTRL | Qt::Key_C);
335  editMenu->addSeparator ();
336  editMenu->addActions (m_mouseModeGroup->actions ());
337 
338  QMenu *helpMenu = m_menuBar->addMenu (tr ("&Help"));
339  helpMenu->menuAction ()->setObjectName ("builtinMenu");
340  helpMenu->addAction (tr ("About Octave"), this,
341  SLOT (helpAboutOctave (void)));
342 
343  m_menuBar->addReceiver (this);
344  }
345 
346  void
348  {
349  if (m_mouseModeGroup)
350  {
351  m_blockUpdates = true;
353  m_blockUpdates = false;
354  }
355  }
356 
357  Container*
359  {
360  return m_container;
361  }
362 
363  void
365  {
366  Canvas *canvas = m_container->canvas (m_handle);
367 
368  if (canvas)
369  {
370  canvas->redraw ();
371  //canvas->setMouseMode (RotateMode);
372  }
373 
374  foreach (QFrame *frame,
375  qWidget<QWidget> ()->findChildren<QFrame*> ())
376  {
377  if (frame->objectName () == "UIPanel"
378  || frame->objectName () == "UIButtonGroup")
379  {
381 
382  if (obj)
383  obj->slotRedraw ();
384  }
385  }
386 
388  }
389 
390  void
391  Figure::print (const QString& file_cmd, const QString& term)
392  {
393  Canvas *canvas = m_container->canvas (m_handle);
394 
395  if (canvas)
396  canvas->print (file_cmd, term);
397  }
398 
401  {
403  Canvas *canvas = m_container->canvas (m_handle);
404 
405  if (canvas)
406  {
409  retval = canvas->getPixels ();
410  }
411 
412  return retval;
413  }
414 
415  void
417  {
418  Canvas *canvas = m_container->canvas (m_handle.value (), false);
419 
420  if (canvas)
421  canvas->blockRedraw (true);
422 
423  m_menuBar->removeReceiver (this);
424  m_container->removeReceiver (this);
425  qWidget<FigureWindow> ()->removeReceiver (this);
426  }
427 
428  void
429  Figure::update (int pId)
430  {
431  if (m_blockUpdates)
432  return;
433 
434  figure::properties& fp = properties<figure> ();
435 
436  if (fp.is___printing__ ())
437  return;
438 
439  QMainWindow *win = qWidget<QMainWindow> ();
440 
441  // If the window doesn't exist, there's nothing we can do.
442  if (! win)
443  return;
444 
445  m_blockUpdates = true;
446 
447  switch (pId)
448  {
449  case figure::properties::ID_POSITION:
450  {
452  int toffset = 0;
453  int boffset = 0;
454 
455  foreach (QToolBar *tb, win->findChildren<QToolBar*> ())
456  if (! tb->isHidden ())
457  toffset += tb->sizeHint ().height ();
458 
459  if (! m_menuBar->isHidden ())
460  toffset += m_menuBar->sizeHint ().height ();
461 
462  if (! m_statusBar->isHidden ())
463  boffset += m_statusBar->sizeHint ().height ();
464 
465  win->setGeometry (m_innerRect.adjusted (0, -toffset, 0, boffset));
466  }
467  break;
468 
469  case figure::properties::ID_NAME:
470  case figure::properties::ID_NUMBERTITLE:
471  win->setWindowTitle (Utils::fromStdString (fp.get_title ()));
472  break;
473 
474  case figure::properties::ID_VISIBLE:
475  if (fp.is_visible ())
476  {
477  QTimer::singleShot (0, win, SLOT (show ()));
478  if (! fp.is___gl_window__ ())
479  {
481  fp.set ("__gl_window__", "on");
482  }
483  }
484  else
485  win->hide ();
486  break;
487 
488  case figure::properties::ID_TOOLBAR:
489  if (fp.toolbar_is ("none"))
490  showFigureToolBar (false);
491  else if (fp.toolbar_is ("figure"))
492  showFigureToolBar (true);
493  else // "auto"
495  fp.menubar_is ("figure"));
496  break;
497 
498  case figure::properties::ID_MENUBAR:
499  showMenuBar (fp.menubar_is ("figure"));
500  if (fp.toolbar_is ("auto"))
501  showFigureToolBar (fp.menubar_is ("figure"));
502  break;
503 
504  case figure::properties::ID_KEYPRESSFCN:
505  if (fp.get_keypressfcn ().isempty ())
507  else
509  break;
510 
511  case figure::properties::ID_KEYRELEASEFCN:
512  if (fp.get_keyreleasefcn ().isempty ())
514  else
516  break;
517 
518  case figure::properties::ID_WINDOWSTYLE:
519  if (fp.windowstyle_is ("modal"))
520  {
521  bool is_visible = win->isVisible ();
522 
523  // if window is already visible, need to hide and reshow it in order to
524  // make it use the modal settings
525  if (is_visible)
526  win->setVisible (false);
527 
528  win->setWindowModality (Qt::ApplicationModal);
529  win->setVisible (is_visible);
530  }
531  else
532  win->setWindowModality (Qt::NonModal);
533 
534  break;
535 
536  default:
537  break;
538  }
539 
540  m_blockUpdates = false;
541  }
542 
543  void
545  {
546  if ((! m_figureToolBar->isHidden ()) != visible)
547  {
548  int dy1 = m_figureToolBar->sizeHint ().height ();
549  int dy2 = m_statusBar->sizeHint ().height ();
550  QRect r = qWidget<QWidget> ()->geometry ();
551 
552  if (! visible)
553  r.adjust (0, dy1, 0, -dy2);
554  else
555  r.adjust (0, -dy1, 0, dy2);
556 
557  m_blockUpdates = true;
558  qWidget<QWidget> ()->setGeometry (r);
559  m_figureToolBar->setVisible (visible);
560  m_statusBar->setVisible (visible);
561  m_blockUpdates = false;
562 
563  updateBoundingBox (false);
564  }
565  }
566 
567  void
568  Figure::showMenuBar (bool visible, int h1)
569  {
570  // Get the height before and after toggling the visibility of builtin menus
571  if (h1 <= 0)
572  h1 = m_menuBar->sizeHint ().height ();
573 
574  foreach (QAction *a, m_menuBar->actions ())
575  if (a->objectName () == "builtinMenu")
576  a->setVisible (visible);
577 
578  int h2 = m_menuBar->sizeHint ().height ();
579 
580  // Keep the menubar visible if it contains custom menus
581  if (! visible)
582  visible = hasUiMenuChildren (properties<figure> ());
583 
584  if ((m_menuBar->isVisible () && ! visible)
585  || (! m_menuBar->isVisible () && visible))
586  {
587  int dy = qMax (h1, h2);
588  QRect r = qWidget<QWidget> ()->geometry ();
589 
590  if (! visible)
591  r.adjust (0, dy, 0, 0);
592  else
593  r.adjust (0, -dy, 0, 0);
594 
595  m_blockUpdates = true;
596  qWidget<QWidget> ()->setGeometry (r);
597  m_menuBar->setVisible (visible);
598  m_blockUpdates = false;
599  }
600  updateBoundingBox (false);
601  }
602 
603  void
605  {
607  graphics_object go = object ();
608 
609  if (go.valid_object ())
610  showMenuBar (Utils::properties<figure> (go).menubar_is ("figure"),
611  height);
612  }
613 
614  void
616  {
617  if (! m_statusBar->isHidden ())
618  m_statusBar->showMessage (QString ("(%1, %2)")
619  .arg (pt(0), 0, 'g', 5)
620  .arg (pt(1), 0, 'g', 5));
621  }
622 
623  QWidget*
625  {
626  return qWidget<QMainWindow> ()->menuBar ();
627  }
628 
630  {
635  };
636 
637  void
639  {
641 
642  UpdateBoundingBoxData *d = reinterpret_cast<UpdateBoundingBoxData *> (data);
643  graphics_object go = gh_manager::get_object (d->m_handle);
644 
645  if (go.valid_object ())
646  {
647  figure::properties& fp = Utils::properties<figure> (go);
648 
649  fp.set_boundingbox (d->m_bbox, d->m_internal, false);
650  }
651 
652  delete d;
653  }
654 
655  void
656  Figure::updateBoundingBox (bool internal, int flags)
657  {
658  QWidget *win = qWidget<QWidget> ();
659  Matrix bb (1, 4);
660 
661  if (internal)
662  {
663  QRect r = m_innerRect;
664 
665  if (flags & UpdateBoundingBoxPosition)
666  r.moveTopLeft (win->mapToGlobal (m_container->pos ()));
667  if (flags & UpdateBoundingBoxSize)
668  r.setSize (m_container->size ());
669 
670  if (r.isValid () && r != m_innerRect)
671  {
672  m_innerRect = r;
673 
674  bb(0) = r.x ();
675  bb(1) = r.y ();
676  bb(2) = r.width ();
677  bb(3) = r.height ();
678  }
679  else
680  return;
681  }
682  else
683  {
684  QRect r = m_outerRect;
685 
686  if (flags & UpdateBoundingBoxPosition)
687  r.moveTopLeft (win->pos ());
688  if (flags & UpdateBoundingBoxSize)
689  r.setSize (win->frameGeometry ().size ());
690 
691  if (r.isValid () && r != m_outerRect)
692  {
693  m_outerRect = r;
694 
695  bb(0) = r.x ();
696  bb(1) = r.y ();
697  bb(2) = r.width ();
698  bb(3) = r.height ();
699  }
700  else
701  return;
702  }
703 
705 
706  d->m_bbox = bb;
707  d->m_internal = internal;
708  d->m_handle = m_handle;
709  d->m_figure = this;
710 
712  }
713 
714  void
716  {
717  figure::properties& fp = properties<figure> ();
718  octave_value fnum = fp.get___myhandle__ ().as_octave_value ();
719 
720  Ffeval (ovl ("close", fnum));
721  }
722 
723  bool
724  Figure::eventNotifyBefore (QObject *obj, QEvent *xevent)
725  {
726  if (! m_blockUpdates)
727  {
728  // Clicking the toolbar or the menubar makes this figure current
729  if (xevent->type () == QEvent::MouseButtonPress)
730  {
731  figure::properties& fp = properties<figure> ();
733  if (fp.get_handlevisibility () == "on")
734  root.set ("currentfigure",
735  fp.get___myhandle__ ().as_octave_value ());
736  }
737 
738  if (obj == m_container)
739  {
740  // Do nothing...
741  }
742  else if (obj == m_menuBar)
743  {
744  switch (xevent->type ())
745  {
746  case QEvent::ActionChanged:
747  m_previousHeight = m_menuBar->sizeHint ().height ();
748  break;
749  case QEvent::ActionRemoved:
750  {
751  QAction *a = dynamic_cast<QActionEvent *> (xevent)->action ();
752 
753  if (! a->isSeparator ()
754  && a->objectName () != "builtinMenu")
755  updateMenuBar ();
756  }
757  break;
758 
759  default:
760  break;
761  }
762  }
763  else
764  {
765  switch (xevent->type ())
766  {
767  case QEvent::Close:
768  xevent->ignore ();
770  return true;
771 
772  default:
773  break;
774  }
775  }
776  }
777 
778  return false;
779  }
780 
781  void
782  Figure::eventNotifyAfter (QObject *watched, QEvent *xevent)
783  {
784  if (! m_blockUpdates)
785  {
786  if (watched == m_container)
787  {
788  switch (xevent->type ())
789  {
790  case QEvent::Resize:
792  break;
793 
794  case QEvent::ChildAdded:
795  if (dynamic_cast<QChildEvent *> (xevent)->child
796  ()->isWidgetType())
797  {
799  update (figure::properties::ID_TOOLBAR);
800 
802  }
803  break;
804 
805  case QEvent::ChildRemoved:
806  if (dynamic_cast<QChildEvent *> (xevent)->child
807  ()->isWidgetType())
808  {
810  update (figure::properties::ID_TOOLBAR);
811  }
812  break;
813 
814  default:
815  break;
816  }
817  }
818  else if (watched == m_menuBar)
819  {
820  switch (xevent->type ())
821  {
822  case QEvent::ActionChanged:
823  // The menubar may have been resized if no action is visible
824  {
825  QAction *a = dynamic_cast<QActionEvent *> (xevent)->action ();
826  if (m_menuBar->sizeHint ().height () != m_previousHeight
827  && a->objectName () != "builtinMenu"
828  && ! a->isSeparator ())
830  }
831  break;
832  case QEvent::ActionAdded:
833  {
834  QAction *a = dynamic_cast<QActionEvent *> (xevent)->action ();
835 
836  if (! a->isSeparator ()
837  && a->objectName () != "builtinMenu"
838  && a->isVisible ())
839  updateMenuBar ();
840  }
841  break;
842 
843  default:
844  break;
845  }
846  }
847  else
848  {
849  switch (xevent->type ())
850  {
851  case QEvent::Move:
854  break;
855 
856  case QEvent::Resize:
858  break;
859 
860  default:
861  break;
862  }
863  }
864  }
865  }
866 
867  void
869  {
872 
873  QMessageBox::about (qWidget<QMainWindow> (), tr ("About Octave"),
875  }
876 
877  void
879  {
880  if (m_blockUpdates)
881  return;
882 
884 
885  figure::properties& fp = properties<figure> ();
886 
887  fp.set___mouse_mode__ (mouse_mode_to_string (mode));
888 
889  Canvas *canvas = m_container->canvas (m_handle);
890 
891  if (canvas)
892  canvas->setCursor (mode);
893  }
894 
895  void
897  {
898  QString file = fileName ();
899 
900  if (file.isEmpty ())
901  {
902  prompt = true;
903 
904  file = "untitled.ofig";
905  }
906 
907  if (prompt || file.isEmpty ())
908  {
909  QFileInfo finfo (file);
910 
911  file = QFileDialog::getSaveFileName (qWidget<FigureWindow> (),
912  tr ("Save Figure As"),
913  finfo.absoluteFilePath (),
914  tr ("Octave Figure File (*.ofig);;Vector Image Formats (*.eps *.epsc *.pdf *.svg *.ps *.tikz);;Bitmap Image Formats (*.gif *.jpg *.png *.tiff)"),
915  nullptr,
916  QFileDialog::DontUseNativeDialog);
917  }
918 
919  if (! file.isEmpty ())
920  {
921  QFileInfo finfo (file);
922 
923  setFileName (finfo.absoluteFilePath ());
924 
926  file.toStdString ());
927  }
928  }
929 
930  void
932  {
933  figure::properties& fp = properties<figure> ();
934  octave_value fnum = fp.get___myhandle__ ().as_octave_value ();
935 
936  size_t flen = file.length ();
937 
938  if (flen > 5 && file.substr (flen-5) == ".ofig")
939  Ffeval (ovl ("hgsave", fnum, file));
940  else
941  Ffeval (ovl ("print", fnum, file));
942  }
943 
944  void
946  {
947  std::string msg;
948 
949  std::string file = octave::sys::tempnam ("", "oct-", msg) + '.' + format;
950 
951  if (file.empty ())
952  {
953  // Report error?
954  return;
955  }
956 
958 
960  }
961 
962  void
964  {
965  fileSaveFigure (true);
966  }
967 
968  void
970  {
971  qWidget<QMainWindow> ()->close ();
972  }
973 
974  void
975  Figure::editCopy (bool /* choose_format */)
976  {
977  QString format = "png";
978 
979 #if 0
980 
981  // FIXME: allow choice of image formats.
982 
983  if (choose_format)
984  {
985  QFileInfo finfo (file);
986 
987  format = QFileDialog::getSaveFileName (qWidget<FigureWindow> (),
988  tr ("Save Figure As"),
989  finfo.absoluteFilePath (), 0, 0,
990  QFileDialog::DontUseNativeDialog);
991  }
992 #endif
993 
995  format.toStdString ());
996  }
997 
998  void
999  Figure::addCustomToolBar (QToolBar *bar, bool visible)
1000  {
1001  QMainWindow *win = qWidget<QMainWindow> ();
1002 
1003  if (! visible)
1004  win->addToolBar (bar);
1005  else
1006  {
1007  QSize sz = bar->sizeHint ();
1008  QRect r = win->geometry ();
1009  //qDebug () << "Figure::addCustomToolBar:" << r;
1010 
1011  r.adjust (0, -sz.height (), 0, 0);
1012 
1013  m_blockUpdates = true;
1014  win->setGeometry (r);
1015  win->addToolBarBreak ();
1016  win->addToolBar (bar);
1017  m_blockUpdates = false;
1018 
1019  //qDebug () << "Figure::addCustomToolBar:" << win->geometry ();
1020  updateBoundingBox (false);
1021  }
1022  }
1023 
1024  void
1025  Figure::showCustomToolBar (QToolBar *bar, bool visible)
1026  {
1027  QMainWindow *win = qWidget<QMainWindow> ();
1028 
1029  if ((! bar->isHidden ()) != visible)
1030  {
1031  QSize sz = bar->sizeHint ();
1032  QRect r = win->geometry ();
1033 
1034  if (visible)
1035  r.adjust (0, -sz.height (), 0, 0);
1036  else
1037  r.adjust (0, sz.height (), 0, 0);
1038 
1039  m_blockUpdates = true;
1040  win->setGeometry (r);
1041  bar->setVisible (visible);
1042  m_blockUpdates = false;
1043 
1044  updateBoundingBox (false);
1045  }
1046  }
1047 
1048  void
1050  {
1051  redraw ();
1052  }
1053 
1054  void
1056  {
1057  Canvas *canvas = m_container->canvas (m_handle);
1058 
1059  if (canvas)
1060  canvas->toggleAxes (m_handle);
1061  }
1062 
1063  void
1065  {
1066  Canvas *canvas = m_container->canvas (m_handle);
1067 
1068  if (canvas)
1069  canvas->toggleGrid (m_handle);
1070  }
1071 
1072  void
1074  {
1075  Canvas *canvas = m_container->canvas (m_handle);
1076 
1077  if (canvas)
1078  canvas->autoAxes (m_handle);
1079  }
1080 
1081  void
1083  {
1084  // Enable mouse tracking on every widgets
1085  m_container->setMouseTracking (true);
1086  m_container->canvas (m_handle)->qWidget ()->setMouseTracking (true);
1087  foreach (QWidget *w, m_container->findChildren<QWidget*> ())
1088  w->setMouseTracking (true);
1089  }
1090 
1091 }
void fileSaveFigure(bool prompt=false)
Definition: Figure.cc:896
virtual QWidget * qWidget(void)=0
void update(int pId)
Definition: Figure.cc:429
QWidget * menu(void)
Definition: Figure.cc:624
QString fileName(void)
Definition: Figure.cc:252
QRect m_outerRect
Definition: Figure.h:145
For example cd octave end example noindent changes the current working directory to file
Definition: dirfns.cc:124
static MouseMode mouse_mode_from_string(const std::string &mode)
Definition: Figure.cc:231
void showFigureToolBar(bool visible)
Definition: Figure.cc:544
void fileCloseFigure(void)
Definition: Figure.cc:969
static void updateBoundingBoxHelper(void *)
Definition: Figure.cc:638
std::string string_value(bool force=false) const
Definition: ov.h:955
virtual void set(const caseless_str &, const octave_value &)
Container * m_container
Definition: Figure.h:139
double value(void) const
Definition: oct-handle.h:74
MouseMode
Definition: Figure.h:39
Return the CPU time used by your Octave session The first output is the total time spent executing your process and is equal to the sum of second and third which are the number of CPU seconds spent executing in user mode and the number of CPU seconds spent executing in system mode
Definition: data.cc:6348
QList< QAction * > actions(void) const
virtual void autoAxes(const graphics_handle &handle)=0
void showCustomToolBar(QToolBar *bar, bool visible)
Definition: Figure.cc:1025
#define CTRL(x)
Definition: kpty.cpp:143
std::string tempnam(const std::string &dir, const std::string &pfx)
Definition: file-ops.cc:638
void close_figure_callback(void)
Definition: Figure.cc:715
void setEventMask(int m)
Definition: Canvas.h:64
void helpAboutOctave(void)
Definition: Figure.cc:868
Matrix get_boundingbox(bool internal=false, const Matrix &parent_pix_size=Matrix()) const
Definition: graphics.cc:3937
void beingDeleted(void)
Definition: Figure.cc:416
QString fromStdString(const std::string &s)
void enableMouseTracking(void)
Definition: Figure.cc:1082
void addEventMask(int m)
Definition: Canvas.h:62
void print(const QString &file_cmd, const QString &term)
Definition: Canvas.h:57
static QRect boundingBoxToRect(const Matrix &bb)
Definition: Figure.cc:105
void redraw(bool sync=false)
Definition: Canvas.cc:53
void editCopy(bool choose_format=false)
Definition: Figure.cc:975
Figure(const graphics_object &go, FigureWindow *win)
Definition: Figure.cc:126
octave_value arg
Definition: pr-output.cc:3244
static bool hasUiControlChildren(const figure::properties &fp)
Definition: Figure.cc:67
F77_RET_T const F77_REAL const F77_REAL F77_REAL &F77_RET_T const F77_DBLE const F77_DBLE F77_DBLE &F77_RET_T const F77_DBLE F77_DBLE &F77_RET_T const F77_REAL F77_REAL &F77_RET_T const F77_DBLE const F77_DBLE F77_DBLE * d
bool isa(const std::string &go_name) const
Definition: graphics.in.h:2786
calling an anonymous function involves an overhead quite comparable to the overhead of an m file function Passing a handle to a built in function is because the interpreter is not involved in the internal loop For a
Definition: cellfun.cc:400
void updateContainer(void)
Definition: Figure.cc:1049
void setMouseMode(MouseMode mode)
Definition: Figure.cc:878
void addCustomToolBar(QToolBar *bar, bool visible)
Definition: Figure.cc:999
void message(const char *name, const char *fmt,...)
Definition: error.cc:435
bool valid_object(void) const
Definition: graphics.in.h:2806
nd deftypefn *std::string name
Definition: sysdep.cc:647
virtual uint8NDArray getPixels(void)
Definition: Canvas.h:77
void asyncUpdate(void)
octave_value get(bool all=false) const
Definition: graphics.in.h:2711
void copy_figure_callback(const std::string &format)
Definition: Figure.cc:945
std::complex< double > w(std::complex< double > z, double relerr=0)
void updateMenuBar(int height=-1)
Definition: Figure.cc:604
void slotRedraw(void)
Definition: Object.cc:114
graphics_handle m_handle
Definition: Object.h:115
static Object * fromQObject(QObject *obj)
Definition: Object.cc:176
void fileSaveFigureAs(void)
Definition: Figure.cc:963
is false
Definition: cellfun.cc:400
octave_value retval
Definition: data.cc:6246
void createFigureToolBarAndMenuBar(void)
Definition: Figure.cc:295
MouseModeActionGroup * m_mouseModeGroup
Definition: Figure.h:146
void removeReceiver(GenericEventNotifyReceiver *r)
void eventNotifyAfter(QObject *watched, QEvent *event)
Definition: Figure.cc:782
Definition: dMatrix.h:36
sz
Definition: data.cc:5264
octave_value getfield(const std::string &key) const
Definition: oct-map.cc:184
LS_TEXT format
Definition: load-save.cc:1616
void updateStatusBar(ColumnVector pt)
Definition: Figure.cc:615
graphics_object object(void) const
Definition: Object.cc:72
MenuBar * m_menuBar
Definition: Figure.h:142
void toggleGrid(void)
Definition: Figure.cc:1064
int m_previousHeight
Definition: Figure.h:147
std::string get_title(void) const
Definition: graphics.cc:4671
uint8NDArray slotGetPixels(void)
Definition: Figure.cc:400
Matrix get_all_children(void) const
Definition: graphics.in.h:2280
QStatusBar * m_statusBar
Definition: Figure.h:143
virtual void toggleAxes(const graphics_handle &handle)=0
virtual void toggleGrid(const graphics_handle &handle)=0
bool eventNotifyBefore(QObject *watched, QEvent *event)
Definition: Figure.cc:724
octave::unwind_protect frame
Definition: graphics.cc:12190
std::string octave_name_version_copyright_copying_warranty_and_bugs(bool html, const std::string &extra_info)
Definition: version.cc:98
Container * innerContainer(void)
Definition: Figure.cc:358
static bool hasUiMenuChildren(const figure::properties &fp)
Definition: Figure.cc:86
void autoAxes(void)
Definition: Figure.cc:1073
OCTAVE_EXPORT octave_value_list isa nd deftypefn *return ovl(args(0).isinteger())
QRect m_innerRect
Definition: Figure.h:144
void toggleAxes(void)
Definition: Figure.cc:1055
bool m_blockUpdates
Definition: Figure.h:140
void setCursor(MouseMode mode)
Definition: Canvas.cc:73
static std::string mouse_mode_to_string(MouseMode mode)
Definition: Figure.cc:198
QToolBar * m_figureToolBar
Definition: Figure.h:141
static void post_function(graphics_event::event_fcn fcn, void *data=nullptr)
Definition: graphics.in.h:6222
void print(const QString &file_cmd, const QString &term)
Definition: Figure.cc:391
void addReceiver(GenericEventNotifyReceiver *r)
static graphics_object get_object(double val)
Definition: graphics.in.h:6098
void set_boundingbox(const Matrix &bb, bool internal=false, bool do_notify_toolkit=true)
Definition: graphics.cc:3954
double round(double x)
Definition: lo-mappers.h:145
MouseMode mouseMode(void)
Definition: Figure.cc:274
static Figure * create(const graphics_object &go)
Definition: Figure.cc:121
for i
Definition: data.cc:5264
void showMenuBar(bool visible, int height=-1)
Definition: Figure.cc:568
Canvas * canvas(const graphics_handle &handle, bool create=true)
Definition: Container.cc:50
void updateFigureToolBarAndMenuBar(void)
Definition: Figure.cc:347
void redraw(void)
Definition: Figure.cc:364
#define DECLARE_GENERICEVENTNOTIFY_SENDER(T, B)
void updateBoundingBox(bool internal=false, int flags=0)
Definition: Figure.cc:656
octave_idx_type numel(void) const
Number of elements in the array.
Definition: Array.h:366
If this string is the system will ring the terminal sometimes it is useful to be able to print the original representation of the string
Definition: utils.cc:888
void save_figure_callback(const std::string &file)
Definition: Figure.cc:931
void setFileName(const QString &name)
Definition: Figure.cc:264
void blockRedraw(bool block=true)
Definition: Canvas.cc:67
void clearEventMask(int m)
Definition: Canvas.h:63
static int process_events(void)
Definition: graphics.in.h:6235