26#if defined (HAVE_CONFIG_H)
31#include <QActionEvent>
32#include <QApplication>
46#if defined (HAVE_QSCREEN_DEVICEPIXELRATIO)
65#include "builtin-defun-decls.h"
92 QImage retval (cdata.
rows (), cdata.
columns (), QImage::Format_ARGB32);
94 QColor black (
"Black");
95 QColor white (
"White");
99 if (cdata(ii, jj) == 1.0)
101 else if (cdata(ii, jj) == 2.0)
106 retval.setPixel (jj, ii, tmp.rgba ());
114 const graphics_object& go)
121 :
Object (oct_qobj, interp, go, win), m_blockUpdates (false),
122 m_figureToolBar (nullptr), m_menuBar (nullptr), m_innerRect (),
123 m_outerRect (), m_previousHeight (0), m_resizable (true)
153 if (fp.toolbar_is (
"figure")
154 || (fp.toolbar_is (
"auto") && fp.menubar_is (
"figure")))
164 update (figure::properties::ID_NUMBERTITLE);
168 update (figure::properties::ID_KEYPRESSFCN);
169 update (figure::properties::ID_KEYRELEASEFCN);
172 update (figure::properties::ID_WINDOWSTYLE);
175 update (figure::properties::ID_RESIZE);
178 update (figure::properties::ID_POINTERSHAPECDATA);
181 update (figure::properties::ID_VISIBLE);
206 std::string
name = fp.get_filename ();
220 fp.set_filename (
name.toStdString ());
232 std::string mode = fp.get___mouse_mode__ ();
240 mode +=
' ' + direction;
243 if (mode ==
"rotate")
245 else if (mode ==
"zoom in")
247 else if (mode ==
"zoom out")
249 else if (mode ==
"pan")
251 else if (mode ==
"text")
264 win->setSizePolicy (QSizePolicy::Preferred, QSizePolicy::Preferred);
265 win->setFixedSize (QSize( QWIDGETSIZE_MAX, QWIDGETSIZE_MAX));
269 int state = win->windowState ();
270 if (
state == Qt::WindowFullScreen ||
state == Qt::WindowMaximized)
271 win->setWindowState (Qt::WindowNoState);
273 win->setGeometry (r);
277 win->setSizePolicy (QSizePolicy::Fixed, QSizePolicy::Fixed);
278 win->setFixedSize(win->size ());
296 for (
auto *qobj : qWidget<QWidget> ()->findChildren<QObject *> ())
298 if (qobj->objectName () ==
"UIPanel"
299 || qobj->objectName () ==
"UIButtonGroup"
300 || qobj->objectName () ==
"UIControl"
301 || qobj->objectName () ==
"UITable")
314 QWidget *win = qWidget<QWidget> ();
316 win->activateWindow ();
326 canvas->
print (file_cmd, term);
339 gh_mgr.process_events ();
356 qWidget<FigureWindow> ()->removeReceiver (
this);
367 if (fp.is___printing__ ())
380 case figure::properties::ID_POSITION:
386 for (
auto *tb : win->findChildren<QToolBar *> ())
387 if (! tb->isHidden ())
388 toffset += tb->sizeHint ().height ();
391 toffset +=
m_menuBar->sizeHint ().height ();
400 case figure::properties::ID_NAME:
401 case figure::properties::ID_NUMBERTITLE:
405 case figure::properties::ID_VISIBLE:
406 if (fp.is_visible ())
408 QTimer::singleShot (0, win, &QMainWindow::show);
409 if (! fp.is___gl_window__ ())
414 fp.set (
"__gl_window__",
"on");
421 case figure::properties::ID_RESIZE:
424 win->setSizePolicy (QSizePolicy::Preferred, QSizePolicy::Preferred);
425 win->setFixedSize (QSize( QWIDGETSIZE_MAX, QWIDGETSIZE_MAX));
430 win->setSizePolicy (QSizePolicy::Fixed, QSizePolicy::Fixed);
431 win->setFixedSize(win->size ());
436 case figure::properties::ID_MENUBAR:
437 case figure::properties::ID_TOOLBAR:
438 if (fp.toolbar_is (
"none"))
440 else if (fp.toolbar_is (
"figure"))
446 case figure::properties::ID_KEYPRESSFCN:
447 if (fp.get_keypressfcn ().isempty ())
452 for (
auto *qobj : qWidget<QWidget> ()->findChildren<QObject *> ())
454 if (qobj->objectName () ==
"UIPanel")
460 if (fp.get_keypressfcn ().isempty ())
471 case figure::properties::ID_KEYRELEASEFCN:
472 if (fp.get_keyreleasefcn ().isempty ())
478 for (
auto *qobj : qWidget<QWidget> ()->findChildren<QObject *> ())
480 if (qobj->objectName () ==
"UIPanel")
486 if (fp.get_keypressfcn ().isempty ())
497 case figure::properties::ID_WINDOWSTYLE:
498 if (fp.windowstyle_is (
"modal"))
500 bool is_visible = win->isVisible ();
505 win->setVisible (
false);
507 win->setWindowModality (Qt::ApplicationModal);
508 win->setVisible (is_visible);
511 win->setWindowModality (Qt::NonModal);
515 case figure::properties::ID_POINTERSHAPECDATA:
518 if (fp.get_pointer () !=
"custom")
522 case figure::properties::ID_POINTER:
523 case figure::properties::ID_POINTERSHAPEHOTSPOT:
524 case figure::properties::ID___MOUSE_MODE__:
525 case figure::properties::ID___ZOOM_MODE__:
529 fp.get_pointershapehotspot ()
547 QRect r = qWidget<QWidget> ()->geometry ();
550 r.adjust (0, 0, 0, -dy);
552 r.adjust (0, 0, 0, dy);
569 graphics_object go =
object ();
571 if (go.valid_object () && dh != 0)
573 QRect r = qWidget<QWidget> ()->geometry ();
575 r.adjust (0, dh, 0, 0);
590 .arg (pt(0), 0,
'g', 5)
591 .arg (pt(1), 0,
'g', 5));
604 return qWidget<QMainWindow> ()->menuBar ();
610 QWidget *win = qWidget<QWidget> ();
620 r.moveTopLeft (win->mapToGlobal (
m_container->pos ()));
638 prop =
"outerposition";
642 r.moveTopLeft (win->pos ());
644 r.setSize (win->frameGeometry ().size ());
671 if (xevent->type () == QEvent::MouseButtonPress)
677 graphics_object root = gh_mgr.get_object (0);
679 if (fp.get_handlevisibility () ==
"on")
680 root.set (
"currentfigure",
681 fp.get___myhandle__ ().as_octave_value ());
690 switch (xevent->type ())
692 case QEvent::ActionAdded:
693 case QEvent::ActionChanged:
694 case QEvent::ActionRemoved:
703 switch (xevent->type ())
728 switch (xevent->type ())
734 case QEvent::ChildAdded:
735 if (
dynamic_cast<QChildEvent *
> (xevent)->
child
739 update (figure::properties::ID_TOOLBAR);
745 case QEvent::ChildRemoved:
746 if (
dynamic_cast<QChildEvent *
> (xevent)->
child
750 update (figure::properties::ID_TOOLBAR);
760 switch (xevent->type ())
762 case QEvent::ActionAdded:
763 case QEvent::ActionChanged:
764 case QEvent::ActionRemoved:
767 QAction *a =
dynamic_cast<QActionEvent *
> (xevent)->action ();
768 int currentHeight =
m_menuBar->sizeHint ().height ();
770 && ! a->isSeparator ())
781 switch (xevent->type ())
808 win->addToolBar (bar);
811 QSize sz = bar->sizeHint ();
812 QRect r = win->geometry ();
814 r.adjust (0, -sz.height (), 0, 0);
818 win->addToolBarBreak ();
819 win->addToolBar (bar);
831 if ((! bar->isHidden ()) != visible)
833 QSize sz = bar->sizeHint ();
834 QRect r = win->geometry ();
837 r.adjust (0, -sz.height (), 0, 0);
839 r.adjust (0, sz.height (), 0, 0);
843 bar->setVisible (visible);
859#if defined (HAVE_QSCREEN_DEVICEPIXELRATIO)
860 QWindow *window = qWidget<QMainWindow> ()->windowHandle ();
861 QScreen *screen = window->screen ();
868 fp.set___device_pixel_ratio__ (screen->devicePixelRatio ());
877#if defined (HAVE_QSCREEN_DEVICEPIXELRATIO)
883 double old_dpr = fp.get___device_pixel_ratio__ ();
884 double new_dpr = screen->devicePixelRatio ();
885 if (old_dpr != new_dpr)
887 fp.set___device_pixel_ratio__ (new_dpr);
894 octave_unused_parameter (screen);
905 w->setMouseTracking (
true);
#define DECLARE_GENERICEVENTNOTIFY_SENDER(T, B)
octave_idx_type numel(void) const
Number of elements in the array.
octave_idx_type rows(void) const
octave_idx_type columns(void) const
void blockRedraw(bool block=true)
virtual uint8NDArray getPixels(void)
void print(const QString &file_cmd, const QString &term)
void setCursor(MouseMode mode, std::string fallback, QImage cdata, Matrix hotspot)
void redraw(bool sync=false)
void clearEventMask(int m)
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)
virtual Container * innerContainer(void)=0
virtual void do_connections(const QObject *receiver, const QObject *emitter=nullptr)
void gh_callback_event(const graphics_handle &h, const std::string &name)
octave::interpreter & m_interpreter
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
Base class for Octave interfaces that use Qt.
octave_value getfield(const std::string &key) const
std::string string_value(bool force=false) const
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]
static QRect boundingBoxToRect(const Matrix &bb)
static QImage pointer_to_qimage(const Matrix &cdata)