26 #if defined (HAVE_CONFIG_H)
31 #include <QActionEvent>
32 #include <QApplication>
35 #include <QFileDialog>
39 #include <QMainWindow>
42 #include <QMessageBox>
46 #if defined (HAVE_QSCREEN_DEVICEPIXELRATIO)
65 #include "builtin-defun-decls.h"
91 QImage retval (cdata.
rows (), cdata.
columns (), QImage::Format_ARGB32);
93 QColor black (
"Black");
94 QColor white (
"White");
98 if (cdata(ii, jj) == 1.0)
100 else if (cdata(ii, jj) == 2.0)
105 retval.setPixel (jj, ii, tmp.rgba ());
113 const graphics_object& go)
120 :
Object (oct_qobj, interp, go, win), m_blockUpdates (false),
121 m_figureToolBar (nullptr), m_menuBar (nullptr), m_innerRect (),
122 m_outerRect (), m_previousHeight (0), m_resizable (true)
151 if (fp.toolbar_is (
"figure")
152 || (fp.toolbar_is (
"auto") && fp.menubar_is (
"figure")))
162 update (figure::properties::ID_NUMBERTITLE);
166 update (figure::properties::ID_KEYPRESSFCN);
167 update (figure::properties::ID_KEYRELEASEFCN);
170 update (figure::properties::ID_WINDOWSTYLE);
173 update (figure::properties::ID_RESIZE);
176 update (figure::properties::ID_POINTERSHAPECDATA);
179 update (figure::properties::ID_VISIBLE);
200 octave::autolock guard (gh_mgr.graphics_lock ());
204 std::string name = fp.get_filename ();
214 octave::autolock guard (gh_mgr.graphics_lock ());
218 fp.set_filename (name.toStdString ());
226 octave::autolock guard (gh_mgr.graphics_lock ());
230 std::string mode = fp.get___mouse_mode__ ();
238 mode +=
' ' + direction;
241 if (mode ==
"rotate")
243 else if (mode ==
"zoom in")
245 else if (mode ==
"zoom out")
247 else if (mode ==
"pan")
249 else if (mode ==
"text")
262 win->setSizePolicy (QSizePolicy::Preferred, QSizePolicy::Preferred);
263 win->setFixedSize (QSize( QWIDGETSIZE_MAX, QWIDGETSIZE_MAX));
267 int state = win->windowState ();
268 if (
state == Qt::WindowFullScreen ||
state == Qt::WindowMaximized)
269 win->setWindowState (Qt::WindowNoState);
271 win->setGeometry (
r);
275 win->setSizePolicy (QSizePolicy::Fixed, QSizePolicy::Fixed);
276 win->setFixedSize(win->size ());
294 for (
auto *qobj : qWidget<QWidget> ()->findChildren<QObject *> ())
296 if (qobj->objectName () ==
"UIPanel"
297 || qobj->objectName () ==
"UIButtonGroup"
298 || qobj->objectName () ==
"UIControl"
299 || qobj->objectName () ==
"UITable")
312 QWidget *win = qWidget<QWidget> ();
314 win->activateWindow ();
324 canvas->
print (file_cmd, term);
337 gh_mgr.process_events ();
338 octave::autolock guard (gh_mgr.graphics_lock ());
354 qWidget<FigureWindow> ()->removeReceiver (
this);
365 if (fp.is___printing__ ())
378 case figure::properties::ID_POSITION:
384 for (
auto *tb : win->findChildren<QToolBar *> ())
385 if (! tb->isHidden ())
386 toffset += tb->sizeHint ().height ();
389 toffset +=
m_menuBar->sizeHint ().height ();
398 case figure::properties::ID_NAME:
399 case figure::properties::ID_NUMBERTITLE:
403 case figure::properties::ID_VISIBLE:
404 if (fp.is_visible ())
406 QTimer::singleShot (0, win, &QMainWindow::show);
407 if (! fp.is___gl_window__ ())
411 octave::autolock guard (gh_mgr.graphics_lock ());
412 fp.set (
"__gl_window__",
"on");
419 case figure::properties::ID_RESIZE:
422 win->setSizePolicy (QSizePolicy::Preferred, QSizePolicy::Preferred);
423 win->setFixedSize (QSize( QWIDGETSIZE_MAX, QWIDGETSIZE_MAX));
428 win->setSizePolicy (QSizePolicy::Fixed, QSizePolicy::Fixed);
429 win->setFixedSize(win->size ());
434 case figure::properties::ID_MENUBAR:
435 case figure::properties::ID_TOOLBAR:
436 if (fp.toolbar_is (
"none"))
438 else if (fp.toolbar_is (
"figure"))
444 case figure::properties::ID_KEYPRESSFCN:
445 if (fp.get_keypressfcn ().isempty ())
450 for (
auto *qobj : qWidget<QWidget> ()->findChildren<QObject *> ())
452 if (qobj->objectName () ==
"UIPanel")
458 if (fp.get_keypressfcn ().isempty ())
469 case figure::properties::ID_KEYRELEASEFCN:
470 if (fp.get_keyreleasefcn ().isempty ())
476 for (
auto *qobj : qWidget<QWidget> ()->findChildren<QObject *> ())
478 if (qobj->objectName () ==
"UIPanel")
484 if (fp.get_keypressfcn ().isempty ())
495 case figure::properties::ID_WINDOWSTYLE:
496 if (fp.windowstyle_is (
"modal"))
498 bool is_visible = win->isVisible ();
503 win->setVisible (
false);
505 win->setWindowModality (Qt::ApplicationModal);
506 win->setVisible (is_visible);
509 win->setWindowModality (Qt::NonModal);
513 case figure::properties::ID_POINTERSHAPECDATA:
516 if (fp.get_pointer () !=
"custom")
520 case figure::properties::ID_POINTER:
521 case figure::properties::ID_POINTERSHAPEHOTSPOT:
522 case figure::properties::ID___MOUSE_MODE__:
523 case figure::properties::ID___ZOOM_MODE__:
527 fp.get_pointershapehotspot ()
545 QRect
r = qWidget<QWidget> ()->geometry ();
548 r.adjust (0, 0, 0, -dy);
550 r.adjust (0, 0, 0, dy);
566 octave::autolock guard (gh_mgr.graphics_lock ());
567 graphics_object go =
object ();
569 if (go.valid_object () && dh != 0)
571 QRect
r = qWidget<QWidget> ()->geometry ();
573 r.adjust (0, dh, 0, 0);
588 .arg (pt(0), 0,
'g', 5)
589 .arg (pt(1), 0,
'g', 5));
602 return qWidget<QMainWindow> ()->menuBar ();
608 QWidget *win = qWidget<QWidget> ();
636 prop =
"outerposition";
640 r.moveTopLeft (win->pos ());
642 r.setSize (win->frameGeometry ().size ());
669 if (xevent->type () == QEvent::MouseButtonPress)
675 graphics_object root = gh_mgr.get_object (0);
677 if (fp.get_handlevisibility () ==
"on")
678 root.set (
"currentfigure",
679 fp.get___myhandle__ ().as_octave_value ());
688 switch (xevent->type ())
690 case QEvent::ActionAdded:
691 case QEvent::ActionChanged:
692 case QEvent::ActionRemoved:
701 switch (xevent->type ())
726 switch (xevent->type ())
732 case QEvent::ChildAdded:
733 if (
dynamic_cast<QChildEvent *
> (xevent)->
child
736 octave::autolock guard (gh_mgr.graphics_lock ());
737 update (figure::properties::ID_TOOLBAR);
743 case QEvent::ChildRemoved:
744 if (
dynamic_cast<QChildEvent *
> (xevent)->
child
747 octave::autolock guard (gh_mgr.graphics_lock ());
748 update (figure::properties::ID_TOOLBAR);
758 switch (xevent->type ())
760 case QEvent::ActionAdded:
761 case QEvent::ActionChanged:
762 case QEvent::ActionRemoved:
765 QAction *a =
dynamic_cast<QActionEvent *
> (xevent)->action ();
766 int currentHeight =
m_menuBar->sizeHint ().height ();
768 && ! a->isSeparator ())
779 switch (xevent->type ())
806 win->addToolBar (bar);
809 QSize sz = bar->sizeHint ();
810 QRect
r = win->geometry ();
812 r.adjust (0, -sz.height (), 0, 0);
816 win->addToolBarBreak ();
817 win->addToolBar (bar);
829 if ((! bar->isHidden ()) != visible)
831 QSize sz = bar->sizeHint ();
832 QRect
r = win->geometry ();
835 r.adjust (0, -sz.height (), 0, 0);
837 r.adjust (0, sz.height (), 0, 0);
841 bar->setVisible (visible);
857 #if defined (HAVE_QSCREEN_DEVICEPIXELRATIO)
858 QWindow *window = qWidget<QMainWindow> ()->windowHandle ();
859 QScreen *screen = window->screen ();
863 octave::autolock guard (gh_mgr.graphics_lock ());
866 fp.set___device_pixel_ratio__ (screen->devicePixelRatio ());
875 #if defined (HAVE_QSCREEN_DEVICEPIXELRATIO)
878 octave::autolock guard (gh_mgr.graphics_lock ());
881 double old_dpr = fp.get___device_pixel_ratio__ ();
882 double new_dpr = screen->devicePixelRatio ();
883 if (old_dpr != new_dpr)
885 fp.set___device_pixel_ratio__ (new_dpr);
892 octave_unused_parameter (screen);
903 w->setMouseTracking (
true);
#define DECLARE_GENERICEVENTNOTIFY_SENDER(T, B)
OCTARRAY_OVERRIDABLE_FUNC_API octave_idx_type columns(void) const
OCTARRAY_OVERRIDABLE_FUNC_API octave_idx_type rows(void) const
void print(const QString &file_cmd, const QString &term)
void clearEventMask(int m)
virtual uint8NDArray getPixels(void)
void redraw(bool sync=false)
void blockRedraw(bool block=true)
void setCursor(MouseMode mode, std::string fallback, QImage cdata, Matrix hotspot)
virtual QWidget * qWidget(void)=0
void interpreter_event(const octave::fcn_callback &fcn)
Canvas * canvas(const graphics_handle &handle, bool create=true)
void addReceiver(GenericEventNotifyReceiver *r)
void removeReceiver(GenericEventNotifyReceiver *r)
void gh_callback_event(const graphics_handle &h, const std::string &name)
virtual void do_connections(const QObject *receiver, const QObject *emitter=nullptr)
static Object * fromQObject(QObject *obj)
void gh_set_event(const graphics_handle &h, const std::string &name, const octave_value &value)
graphics_object object(void) const
virtual Container * innerContainer(void)=0
octave::interpreter & m_interpreter
octave_value getfield(const std::string &key) const
std::string string_value(bool force=false) const
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
const QString global_menubar_style("QMenuBar {" "margin-top: 0px;" "margin-bottom: 0px;" "padding-top: 0px;" "padding-bottom: 0px;" "}")
std::complex< double > w(std::complex< double > z, double relerr=0)
QString fromStdString(const std::string &s)
T::properties & properties(graphics_object obj)
static uint32_t state[624]