Mercurial > octave
diff libgui/graphics/Figure.cc @ 27099:2cd31365c84a
Implement "pointer" and related figure properties for Qt toolkit (bug #56347)
* genpropdoc.m: Document "pointer", "pointershapecdata" and
"pointershapehotspot" properties.
* libgui/src/icons, libgui/src/module.mk, libgui/src/resource.qrc: Add new
cursor png images extracted from the standard DMZ theme. Also add
circle.png/svg designed to look like DMZ icons.
* Canvas.[h, cc] (Canvas::setCursor): Change signature to include, pointer name,
cdata and hotspot location. Use Qt standard QCursors for "arrow", "ibeam", and
"watch" cursors. Use DMZ theme cursors for others. Build QCursor from Qimage
for "custom" pointers.
* Figure.[h,cc](m_pointer_cdata): New QImage data member.
(pointer_to_qimage): New static function to convert from Matrix to QImage.
(Figure::update): Call Canvas::setCursor whenever "pointer" or
"pointershapehotspot" is updated. Refresh m_pointer_cdata when updating
"pointershapecdata" and eventually call Canvas::setCursor.
* graphics.in.h(figure::properties::pointershapecdata): Use 1 as default
value for all pixels.
author | Pantxo Diribarne <pantxo.diribarne@gmail.com> |
---|---|
date | Sun, 19 May 2019 11:15:10 +0200 |
parents | cb5c1ea2062c |
children | 6bc32e6a1b4f |
line wrap: on
line diff
--- a/libgui/graphics/Figure.cc Tue May 21 10:00:52 2019 +0200 +++ b/libgui/graphics/Figure.cc Sun May 19 11:15:10 2019 +0200 @@ -81,6 +81,29 @@ return r; } + static QImage + pointer_to_qimage (const Matrix& cdata) + { + QImage retval (cdata.rows (), cdata.columns (), QImage::Format_ARGB32); + QColor tmp ("White"); + QColor black ("Black"); + QColor white ("White"); + for (octave_idx_type ii = 0; ii < cdata.rows (); ii++) + for (octave_idx_type jj = 0; jj < cdata.columns (); jj++) + { + if (cdata(ii,jj) == 1.0) + tmp = black; + else if (cdata(ii,jj) == 2.0) + tmp = white; + else + tmp.setAlpha (0); + + retval.setPixelColor(jj, ii, tmp); + } + + return retval; + } + Figure* Figure::create (const graphics_object& go) { @@ -136,6 +159,9 @@ // Handle resizing constraints update (figure::properties::ID_RESIZE); + // Custom pointer data + update (figure::properties::ID_POINTERSHAPECDATA); + // Visibility update (figure::properties::ID_VISIBLE); @@ -426,9 +452,23 @@ break; + case figure::properties::ID_POINTERSHAPECDATA: + m_pointer_cdata = + pointer_to_qimage (fp.get_pointershapecdata ().matrix_value ()); + if (fp.get_pointer () != "custom") + break; + // Avoid warning about potential fallthrough + [[fallthrough]]; + + case figure::properties::ID_POINTER: + case figure::properties::ID_POINTERSHAPEHOTSPOT: case figure::properties::ID___MOUSE_MODE__: case figure::properties::ID___ZOOM_MODE__: - m_container->canvas (m_handle)->setCursor (mouseMode ()); + m_container->canvas (m_handle)->setCursor (mouseMode (), + fp.get_pointer (), + m_pointer_cdata, + fp.get_pointershapehotspot () + .matrix_value()); break; default: