28 #include <QActionEvent>
29 #include <QActionGroup>
30 #include <QApplication>
33 #include <QFileDialog>
37 #include <QMainWindow>
40 #include <QMessageBox>
63 #define ABOUT_TEXT "<b>QtHandles</b> - a Qt-based toolkit for <a href=\"http://www.octave.org\">Octave</a>.<br><br>Copyright (C) 2011-2015 Michael Goffioul"
74 for (
int i = 0; i < kids.
numel (); i++)
78 if (go && (go.
isa (
"uicontrol") || go.
isa (
"uipanel")
79 || go.
isa (
"uibuttongroup")))
93 for (
int i = 0; i < kids.
numel (); i++)
97 if (go && go.
isa (
"uimenu"))
109 if (bb.
numel () == 4)
127 :
Object (go, win), m_blockUpdates (false), m_figureToolBar (0),
128 m_menuBar (0), m_innerRect (), m_outerRect (), m_mouseModeGroup (0)
145 offset +=
m_menuBar->sizeHint ().height () + 1;
153 win->setGeometry (
m_innerRect.adjusted (0, -offset, 0, 0));
174 QTimer::singleShot (0, win, SLOT (show ()));
224 else if (mode ==
"rotate")
226 else if (mode ==
"zoom in")
228 else if (mode ==
"zoom out")
230 else if (mode ==
"pan")
232 else if (mode ==
"text")
234 else if (mode ==
"select")
277 mode +=
" " + direction;
289 m_figureToolBar->setMovable (
false);
290 m_figureToolBar->setFloatable (
false);
297 QAction *toggle_axes = m_figureToolBar->addAction (tr (
"Axes"));
298 connect (toggle_axes, SIGNAL (triggered (
void)),
301 QAction *toggle_grid = m_figureToolBar->addAction (tr (
"Grid"));
302 connect (toggle_grid, SIGNAL (triggered (
void)),
305 QAction *auto_axes = m_figureToolBar->addAction (tr (
"Autoscale"));
306 connect (auto_axes, SIGNAL (triggered (
void)),
312 QMenu* fileMenu =
m_menuBar->addMenu (tr (
"&File"));
313 fileMenu->menuAction ()->setObjectName (
"builtinMenu");
314 fileMenu->addAction (tr (
"&Save"),
this, SLOT (
fileSaveFigure (
bool)));
315 fileMenu->addAction (tr (
"Save &As"),
this, SLOT (
fileSaveFigureAs (
void)));
316 fileMenu->addSeparator ();
317 fileMenu->addAction (tr (
"&Close Figure"),
this,
320 QMenu* editMenu =
m_menuBar->addMenu (tr (
"&Edit"));
321 editMenu->menuAction ()->setObjectName (
"builtinMenu");
322 editMenu->addAction (tr (
"Cop&y"),
this, SLOT (
editCopy (
bool)),
324 editMenu->addSeparator ();
327 QMenu* helpMenu =
m_menuBar->addMenu (tr (
"&Help"));
328 helpMenu->menuAction ()->setObjectName (
"builtinMenu");
329 helpMenu->addAction (tr (
"&About QtHandles"),
this,
331 helpMenu->addAction (tr (
"About &Qt"), qApp, SLOT (aboutQt (
void)));
364 foreach (QFrame* frame,
365 qWidget<QWidget> ()->findChildren<QFrame*> (
"UIPanel"))
382 canvas->
print (file_cmd, term);
395 qWidget<FigureWindow> ()->removeReceiver (
this);
417 foreach (QToolBar* tb, win->findChildren<QToolBar*> ())
418 if (! tb->isHidden ())
419 offset += tb->sizeHint ().height ();
421 offset +=
m_menuBar->sizeHint ().height () + 1;
423 win->setGeometry (
m_innerRect.adjusted (0, -offset, 0, 0));
435 QTimer::singleShot (0, win, SLOT (show ()));
476 { w->setMouseTracking (hasCallback); }
484 m_blockUpdates =
false;
493 QRect r = qWidget<QWidget> ()->geometry ();
496 r.adjust (0, dy, 0, 0);
498 r.adjust (0, -dy, 0, 0);
501 qWidget<QWidget> ()->setGeometry (r);
512 int h1 =
m_menuBar->sizeHint ().height ();
514 foreach (QAction* a,
m_menuBar->actions ())
515 if (a->objectName () ==
"builtinMenu")
516 a->setVisible (visible);
518 int h2 =
m_menuBar->sizeHint ().height ();
523 if ((!
m_menuBar->isHidden ()) != visible)
525 int dy = qMax (h1, h2) + 1;
526 QRect r = qWidget<QWidget> ()->geometry ();
530 r.adjust (0, dy, 0, 0);
532 r.adjust (0, -dy, 0, 0);
536 qWidget<QWidget> ()->setGeometry (r);
551 showMenuBar (Utils::properties<figure> (go).menubar_is (
"figure"));
557 return qWidget<QMainWindow> ()->menuBar ();
589 QWidget* win = qWidget<QWidget> ();
597 r.moveTopLeft (win->mapToGlobal (
m_container->pos ()));
618 r.moveTopLeft (win->pos ());
620 r.setSize (win->frameGeometry ().size ());
656 switch (xevent->type ())
658 case QEvent::ActionRemoved:
660 QAction* a =
dynamic_cast<QActionEvent*
> (xevent)->action ();
662 if (! a->isSeparator ()
663 && a->objectName () !=
"builtinMenu")
674 switch (xevent->type ())
697 switch (xevent->type ())
703 case QEvent::ChildAdded:
704 if (dynamic_cast<QChildEvent*> (xevent)->child
719 switch (xevent->type ())
721 case QEvent::ActionAdded:
723 QAction* a =
dynamic_cast<QActionEvent*
> (xevent)->action ();
725 if (! a->isSeparator ()
726 && a->objectName () !=
"builtinMenu")
737 switch (xevent->type ())
758 QMessageBox::about (qWidget<QMainWindow> (), tr (
"About QtHandles"),
789 file =
"untitled.pdf";
792 if (prompt || file.isEmpty ())
794 QFileInfo finfo (file);
796 file = QFileDialog::getSaveFileName (qWidget<FigureWindow> (),
797 tr (
"Save Figure As"),
798 finfo.absoluteFilePath (), 0, 0,
799 QFileDialog::DontUseNativeDialog);
802 if (! file.isEmpty ())
804 QFileInfo finfo (file);
809 file.toStdString ());
824 std::string file =
octave_tempnam (
"",
"oct-", msg) +
"." + format;
832 std::string device =
"-d" + format;
848 qWidget<QMainWindow> ()->close ();
854 QString format =
"png";
862 QFileInfo finfo (file);
864 format = QFileDialog::getSaveFileName (qWidget<FigureWindow> (),
865 tr (
"Save Figure As"),
866 finfo.absoluteFilePath (), 0, 0,
867 QFileDialog::DontUseNativeDialog);
872 format.toStdString ());
881 win->addToolBar (bar);
884 QSize sz = bar->sizeHint ();
885 QRect r = win->geometry ();
888 r.adjust (0, -sz.height (), 0, 0);
891 win->setGeometry (r);
892 win->addToolBarBreak ();
893 win->addToolBar (bar);
906 if ((! bar->isHidden ()) != visible)
908 QSize sz = bar->sizeHint ();
909 QRect r = win->geometry ();
912 r.adjust (0, -sz.height (), 0, 0);
914 r.adjust (0, sz.height (), 0, 0);
917 win->setGeometry (r);
918 bar->setVisible (visible);
virtual QWidget * qWidget(void)=0
static MouseMode mouse_mode_from_string(const std::string &mode)
static void post_callback(const graphics_handle &h, const std::string &name, const octave_value &data=Matrix())
bool is_visible(void) const
bool isa(const std::string &go_name) const
QList< QAction * > actions(void) const
octave_idx_type numel(void) const
Number of elements in the array.
virtual void autoAxes(const graphics_handle &handle)=0
QString fromStdString(const std::string &s)
void setMode(MouseMode mode)
void print(const QString &file_cmd, const QString &term)
static QRect boundingBoxToRect(const Matrix &bb)
void redraw(bool sync=false)
F77_RET_T const double const double double * d
static bool hasUiControlChildren(const figure::properties &fp)
std::string string_value(bool force=false) const
std::complex< double > w(std::complex< double > z, double relerr=0)
static bool copy_image_to_clipboard(const std::string &file)
static Object * fromQObject(QObject *obj)
static void post_event(T *obj, void(T::*method)(void))
void removeReceiver(GenericEventNotifyReceiver *r)
virtual void toggleAxes(const graphics_handle &handle)=0
virtual void toggleGrid(const graphics_handle &handle)=0
graphics_object object(void) const
bool valid_object(void) const
bool is_empty(void) const
static bool hasUiMenuChildren(const figure::properties &fp)
octave_value_list ovl(const octave_value &a0)
octave_scalar_map scalar_map_value(void) const
void setCursor(MouseMode mode)
static std::string mouse_mode_to_string(MouseMode mode)
Matrix get_all_children(void) const
void addReceiver(GenericEventNotifyReceiver *r)
static graphics_object get_object(double val)
static void post_function(graphics_event::event_fcn fcn, void *data=0)
octave_value getfield(const std::string &key) const
OCTINTERP_API octave_value_list Ffeval(const octave_value_list &=octave_value_list(), int=0)
Canvas * canvas(const graphics_handle &handle, bool create=true)
#define DECLARE_GENERICEVENTNOTIFY_SENDER(T, B)
std::string octave_tempnam(const std::string &dir, const std::string &pfx)
void blockRedraw(bool block=true)
void clearEventMask(int m)