26 #if defined (HAVE_CONFIG_H)
30 #include <QApplication>
33 #include <QInputDialog>
35 #include <QMouseEvent>
36 #include <QWheelEvent>
49 #include "builtin-defun-decls.h"
84 return QCursor (icon.pixmap (22, 22), hot_x, hot_y);
89 QImage cdata,
Matrix hotspot)
92 QCursor cursor = Qt::ArrowCursor;
99 cursor = Qt::ArrowCursor;
101 if (fallback ==
"arrow")
102 cursor = Qt::ArrowCursor;
103 else if (fallback ==
"botl")
104 cursor =
make_cursor (
"bottom_left_corner", 5, 16);
105 else if (fallback ==
"botr")
106 cursor =
make_cursor (
"bottom_right_corner", 16, 16);
107 else if (fallback ==
"bottom")
109 else if (fallback ==
"circle")
111 else if (fallback ==
"cross" || fallback ==
"crosshair")
113 else if (fallback ==
"custom")
115 if (hotspot(0) > cdata.width () || hotspot(0) < 1.0
116 || hotspot(1) > cdata.height () || hotspot(1) < 1.0)
117 hotspot =
Matrix (1, 2, 1);
119 cursor = QCursor (QPixmap::fromImage (cdata),
120 static_cast<int> (hotspot(1) - 1),
121 static_cast<int> (hotspot(0) - 1));
123 else if (fallback ==
"fleur")
125 else if (fallback ==
"hand")
127 else if (fallback ==
"ibeam")
128 cursor = Qt::IBeamCursor;
129 else if (fallback ==
"left")
131 else if (fallback ==
"right")
133 else if (fallback ==
"top")
135 else if (fallback ==
"topl")
137 else if (fallback ==
"topr")
139 else if (fallback ==
"watch")
140 cursor = Qt::BusyCursor;
144 cursor = Qt::ArrowCursor;
156 cursor = Qt::IBeamCursor;
168 cursor = Qt::ArrowCursor;
171 w->setCursor (cursor);
194 for (
int i = 0; i < num_children; i++)
198 if (childObj.
isa (
"axes"))
211 cp(0,0) = p1(0); cp(0,1) = p1(1); cp(0,2) = p1(2);
212 cp(1,0) = p2(0); cp(1,1) = p2(1); cp(1,2) = p2(2);
234 for (
int i = 0; i < num_children; i++)
238 if (childObj.
isa (
"axes"))
243 QPoint p =
w->mapFromGlobal (QCursor::pos ());
253 cp(0,0) = p1(0); cp(0,1) = p1(1); cp(0,2) = p1(2);
254 cp(1,0) = p2(0); cp(1,1) = p2(1); cp(1,2) = p2(2);
270 ap.set_xlimmode (
"auto");
271 ap.set_ylimmode (
"auto");
272 ap.set_zlimmode (
"auto");
296 = Utils::properties<figure> (figObj).get___pan_mode__ ();
308 = Utils::properties<figure> (figObj).get___pan_mode__ ();
320 = Utils::properties<figure> (figObj).get___zoom_mode__ ();
332 = Utils::properties<figure> (figObj).get___zoom_mode__ ();
342 bool axes_only, std::vector<std::string> omit)
350 for (
int i = 0; i < num_children; i++)
354 if (childObj.
isa (
"axes"))
356 auto p = omit.begin ();
357 bool omitfound =
false;
358 while (p != omit.end () && ! omitfound)
364 axesList.append (childObj);
366 else if (childObj.
isa (
"uicontrol") || childObj.
isa (
"uipanel")
367 || childObj.
isa (
"uibuttongroup") || childObj.
isa (
"uitable"))
370 QRectF
r (bb(0), bb(1), bb(2), bb(3));
372 r.adjust (-5, -5, 5, 5);
374 #if defined (HAVE_QMOUSEEVENT_LOCALPOS)
375 bool rect_contains_pos =
r.contains (event->localPos ());
377 bool rect_contains_pos =
r.contains (event->posF ());
379 if (rect_contains_pos)
381 currentObj = childObj;
389 QPoint pt =
event->pos ();
392 it != axesList.end (); ++it)
401 if (xlim(0) < p0(0) && xlim(1) > p0(0)
402 && ylim(0) < p0(1) && ylim(1) > p0(1))
409 else if (! currentObj)
412 it != axesList.end (); ++it)
423 else if (it->get_properties ().is_hittest ())
425 Matrix bb = it->get_properties ().get_boundingbox (
true);
426 QRectF
r (bb(0), bb(1), bb(2), bb(3));
430 r.adjust (-20, -20, 20, 20);
432 #if defined (HAVE_QMOUSEEVENT_LOCALPOS)
433 bool rect_contains_pos =
r.contains (event->localPos ());
435 bool rect_contains_pos =
r.contains (event->posF ());
437 if (rect_contains_pos)
441 if (axesObj && currentObj)
487 std::string mode =
pan_mode (figObj);
516 && ! figObj.
get (
"windowbuttonmotionfcn").
isempty ())
520 "windowbuttonmotionfcn");
532 std::vector<std::string> omit = {
"legend",
"colorbar",
"scribeoverlay"};
561 switch (event->button ())
571 case Qt::RightButton:
591 bool isdblclick = (
event->type () == QEvent::MouseButtonDblClick);
601 Utils::properties<root_figure> (root)
638 Utils::properties<figure> (figObj)
648 switch (newMouseMode)
653 auto& fprop = Utils::properties<figure> (figObj);
657 fprop.set_currentobject (currentObj.
get_handle ()
660 fprop.set_currentobject (
Matrix ());
670 "windowbuttondownfcn",
675 if (currentObj && ! currentObj.
get (
"buttondownfcn").
isempty ())
678 else if (figObj && ! figObj.
get (
"buttondownfcn").
isempty ())
683 if (currentObj && event->button () == Qt::RightButton)
686 event->globalPos ());
692 if (event->modifiers () == Qt::NoModifier)
694 switch (event->buttons ())
712 bool redraw_figure =
true;
716 if (event->button () == Qt::LeftButton)
724 redraw_figure =
false;
727 else if (event->modifiers () == Qt::NoModifier)
729 switch (event->buttons ())
738 case Qt::RightButton:
752 Utils::properties<axes> (axesObj);
759 redraw_figure =
false;
763 else if (event->modifiers () == Qt::ShiftModifier)
765 switch (event->buttons ())
778 redraw_figure =
false;
840 ap.
zoom (zm, xl, yl);
882 if (anno_dlg.exec () == QDialog::Accepted)
892 interp.
feval (
"annotation", props);
925 for (
int i = 0; i < num_children; i++)
929 if (childObj.
isa (
"axes"))
931 #if defined (HAVE_QWHEELEVENT_POSITION)
932 QPoint pos =
event->position().toPoint ();
934 QPoint pos =
event->pos ();
957 Utils::properties<figure> (figObj)
962 #if defined (HAVE_QWHEELEVENT_ANGLEDELTA)
963 if (event->angleDelta().y () > 0)
965 if (event->delta () > 0)
981 bool redrawFigure =
true;
983 switch (newMouseMode)
991 double wheel_zoom_speed = ap.get_mousewheelzoom ();
995 ? 1 / (1.0 - wheel_zoom_speed)
996 : 1.0 - wheel_zoom_speed);
1000 ap.
zoom (mode, factor);
1008 #if defined (HAVE_QWHEELEVENT_ANGLEDELTA)
1009 double factor = (
event->angleDelta().y () > 0 ? 0.1 : -0.1);
1011 double factor = (
event->delta () > 0 ? 0.1 : -0.1);
1014 if (event->modifiers () == Qt::NoModifier
1015 && mode !=
"horizontal")
1016 ap.
pan (
"vertical", factor);
1017 else if (event->modifiers () == Qt::ShiftModifier
1018 && mode !=
"vertical")
1019 ap.
pan (
"horizontal", factor);
1024 redrawFigure =
false;
1032 if (! figObj.
get (
"windowscrollwheelfcn").
isempty ())
1061 eventData.
getfield (
"Character"),
false);
1099 const std::string& )
1102 return new GLCanvas (oct_qobj, interp, handle, parent);
charNDArray max(char d, const charNDArray &m)
charNDArray min(char d, const charNDArray &m)
octave_idx_type numel(void) const
Number of elements in the array.
static Canvas * create(octave::base_qobject &oct_qobj, octave::interpreter &interp, const graphics_handle &handle, QWidget *parent, const std::string &name)
void canvasMousePressEvent(QMouseEvent *event)
virtual QWidget * qWidget(void)=0
virtual void draw(const graphics_handle &handle)=0
void setCursor(MouseMode mode, std::string fallback, QImage cdata, Matrix hotspot)
bool canvasKeyReleaseEvent(QKeyEvent *event)
void canvasMouseReleaseEvent(QMouseEvent *event)
bool canvasKeyPressEvent(QKeyEvent *event)
void updateCurrentPoint(const graphics_object &fig, const graphics_object &obj, QMouseEvent *event)
void canvasMouseDoubleClickEvent(QMouseEvent *event)
void canvasPaintEvent(void)
void gh_set_event(const graphics_handle &h, const std::string &name, const octave_value &value)
graphics_handle m_mouseAxes
virtual void drawZoomBox(const QPoint &p1, const QPoint &p2)=0
void redraw(bool sync=false)
octave::interpreter & m_interpreter
virtual graphics_object selectFromAxes(const graphics_object &ax, const QPoint &pt)=0
void gh_callback_event(const graphics_handle &h, const std::string &name)
void canvasMouseMoveEvent(QMouseEvent *event)
QCursor make_cursor(const QString &name, int hot_x=-1, int hot_y=-1)
void blockRedraw(bool block=true)
void select_object(graphics_object obj, QMouseEvent *event, graphics_object ¤tObj, graphics_object &axesObj, bool axes_only=false, std::vector< std::string > omit=std::vector< std::string >())
void canvasWheelEvent(QWheelEvent *event)
octave::base_qobject & m_octave_qobj
void interpreter_event(const octave::fcn_callback &fcn)
static void executeAt(octave::interpreter &interp, const base_properties &props, const QPoint &pt)
octave_value_list get_properties() const
void zoom(const std::string &mode, double factor, bool push_to_zoom_stack=true)
void rotate3d(double x0, double x1, double y0, double y1, bool push_to_zoom_stack=true)
graphics_xform get_transform(void) const
void pan(const std::string &mode, double factor, bool push_to_zoom_stack=true)
ColumnVector pixel2coord(double px, double py) const
void zoom_about_point(const std::string &mode, double x, double y, double factor, bool push_to_zoom_stack=true)
void clear_zoom_stack(bool do_unzoom=true)
Matrix get_transform_zlim(void) const
void translate_view(const std::string &mode, double x0, double x1, double y0, double y1, bool push_to_zoom_stack=true)
Matrix get_children(void) const
virtual octave_value get_ylim(void) const
virtual octave_value get_xlim(void) const
Matrix get_all_children(void) const
virtual Matrix get_boundingbox(bool=false, const Matrix &=Matrix()) const
graphics_object get_object(double val) const
octave::mutex graphics_lock(void)
octave_value get(bool all=false) const
graphics_object get_ancestor(const std::string &type) const
bool isa(const std::string &go_name) const
base_properties & get_properties(void)
graphics_handle get_handle(void) const
graphics_handle get_parent(void) const
bool valid_object(void) const
Base class for Octave interfaces that use Qt.
resource_manager & get_resource_manager(void)
octave_value_list feval(const char *name, const octave_value_list &args=octave_value_list(), int nargout=0)
Evaluate an Octave function (built-in or interpreted) and return the list of result values.
gh_manager & get_gh_manager(void)
QIcon icon(const QString &icon_name, bool fallback=true)
octave_value as_octave_value(void) const
const octave_value & contents(const_iterator p) const
octave_value getfield(const std::string &key) const
octave_value_list & prepend(const octave_value &val)
std::string string_value(bool force=false) const
octave_scalar_map scalar_map_value(void) const
Matrix matrix_value(bool frc_str_conv=false) const
octave_handle graphics_handle
std::complex< double > w(std::complex< double > z, double relerr=0)
std::string figureSelectionType(QMouseEvent *event, bool isDoubleClick)
octave_scalar_map makeScrollEventStruct(QWheelEvent *event)
octave_scalar_map makeKeyEventStruct(QKeyEvent *event)
Matrix figureCurrentPoint(const graphics_object &fig, QMouseEvent *event)
static double button_number(QMouseEvent *event)
static std::string pan_mode(const graphics_object figObj)
static bool pan_enabled(const graphics_object figObj)
static std::string zoom_mode(const graphics_object figObj)
static bool zoom_enabled(const graphics_object figObj)
static void autoscale_axes(gh_manager &gh_mgr, axes::properties &ap)
octave_value::octave_value(const Array< char > &chm, char type) return retval
octave_value_list ovl(const OV_Args &... args)
Construct an octave_value_list with less typing.