NDEVR
API Documentation
ImageView.h
1/*--------------------------------------------------------------------------------------------
2Copyright (c) 2019, NDEVR LLC
3tyler.parke@ndevr.org
4 __ __ ____ _____ __ __ _______
5 | \ | | | __ \ | ___|\ \ / / | __ \
6 | \ | | | | \ \ | |___ \ \ / / | |__) |
7 | . \| | | |__/ / | |___ \ V / | _ /
8 | |\ |_|_____/__|_____|___\_/____| | \ \
9 |__| \__________________________________| \__\
10
11Subject to the terms of the Enterprise+ Agreement, NDEVR hereby grants
12Licensee a limited, non-exclusive, non-transferable, royalty-free license
13(without the right to sublicense) to use the API solely for the purpose of
14Licensee's internal development efforts to develop applications for which
15the API was provided.
16
17The above copyright notice and this permission notice shall be included in all
18copies or substantial portions of the Software.
19
20THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
21INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
22PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
23FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
24OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25DEALINGS IN THE SOFTWARE.
26
27Library: Widgets
28File: ImageView
29Included in API: True
30Author(s): Tyler Parke
31 *-----------------------------------------------------------------------------------------**/
32#pragma once
33#include "DLLInfo.h"
34#include <NDEVR/QTTools.h>
35#include <QWidget>
36#include <QStyle>
37namespace NDEVR
38{
43 class NDEVR_WIDGETS_API ImageView : public QWidget
44 {
45 Q_OBJECT
46 public:
57
62 ImageView(const StringView& image, QWidget* parent = nullptr);
67 ImageView(QWidget* parent = nullptr);
68 ~ImageView();
74 void setImageID(const StringView& image, bool force_refresh = false);
80 void setIconID(const StringView& image, bool force_refresh = false);
82 void clearImage();
87 void paintEvent(QPaintEvent* event) override;
92 void setImage(const QPixmap& pixmap);
97 void setAlignment(Qt::Alignment alignment);
102 void setSizeHintPixelMetric(QStyle::PixelMetric metric);
107 void setSmoothResize(bool smooth_resize)
108 {
109 m_smooth_transform = smooth_resize;
110 }
111
115 void setImage(const QImage& image);
121 void setIcon(const QIcon& image, QIcon::Mode mode = QIcon::Mode::Normal);
126 void setIconMode(QIcon::Mode mode);
131 void setAllowImageContextMenu(bool allow_context_menu);
136 QSize sizeHint() const override;
141 QSize minimumSizeHint() const override
142 {
143 return QSize(0, 0);
144 }
145
149 void setAutoResize(bool auto_resize)
150 {
151 m_auto_resize = auto_resize;
152 }
153
158 {
159 m_view_mode = mode;
160 }
161
165 void setBlendFactor(fltp04 blend_factor);
170 void setBlendImage(const QPixmap& blend_image);
175 void resizeEvent(QResizeEvent* resize_event) override;
181 {
182 m_icon_scale = scale;
183 }
184
188 void setIgnoreDPR(bool ignore);
193 void setForceAspectRatioH(bool force);
198 void setForceAspectRatioW(bool force);
203 QIcon icon() { return m_icon; };
204 protected slots:
206 void showContextMenuSlot(const QPoint& pos);
207 private:
209 void setupIconListener();
211 QRect alignRect(QSize size, QSize preferred_size) const;
212 private:
213 ViewMode m_view_mode = ViewMode::e_zoom_out;
214 bool m_auto_resize = true;
215 bool m_smooth_transform = true;
216 bool m_force_aspect_ratio_width = false;
217 bool m_force_aspect_ratio_height = false;
218 bool m_ignore_device_pixel_ratio = false;
219 fltp08 m_icon_scale;
220 QMenu* m_menu = nullptr;
221 fltp04 m_blend_factor;
222 QPixmap m_image;
223 QPixmap m_blend_image;
224 QIcon m_icon;
225 String m_image_path;
226 String m_icon_path;
227 QIcon::Mode m_icon_mode;
228 QStyle::PixelMetric m_size_hint_pixel_metric;
229 Qt::Alignment m_alignment;
230 QTResourceListener* m_theme_listener;
231 };
232
233
234}
ViewMode
Enumerates how the image is scaled to fit the widget frame.
Definition ImageView.h:51
@ e_zoom_out
Scale the entire image to fit within the frame.
Definition ImageView.h:54
@ e_zoom_in
Crop the image to fill the frame.
Definition ImageView.h:53
@ e_keep
No size adjustment; display at native resolution.
Definition ImageView.h:52
@ e_stretch
Stretch the image to exactly match the frame dimensions.
Definition ImageView.h:55
void setImage(const QImage &image)
Sets the displayed image from a QImage.
void setBlendFactor(fltp04 blend_factor)
Sets the blend factor between the primary and blend images.
void setSmoothResize(bool smooth_resize)
Sets whether smooth (bilinear) scaling is used when resizing.
Definition ImageView.h:107
QSize minimumSizeHint() const override
Returns the minimum size hint, which is zero to allow full shrinking.
Definition ImageView.h:141
void setIgnoreDPR(bool ignore)
Sets whether to ignore the device pixel ratio when rendering.
void paintEvent(QPaintEvent *event) override
Paints the image within the widget bounds using the current view mode.
void setSizeHintPixelMetric(QStyle::PixelMetric metric)
Sets the size hint based on a QStyle pixel metric.
void clearImage()
Clears the currently displayed image.
void setAutoResize(bool auto_resize)
Sets whether the widget automatically resizes to fit its content.
Definition ImageView.h:149
ImageView(const StringView &image, QWidget *parent=nullptr)
Constructs an ImageView with an initial image.
void setIcon(const QIcon &image, QIcon::Mode mode=QIcon::Mode::Normal)
Sets the displayed icon from a QIcon.
void setAllowImageContextMenu(bool allow_context_menu)
Sets whether a context menu is shown when right-clicking the image.
void setImageScale(fltp08 scale)
Sets a custom scale factor for the displayed icon.
Definition ImageView.h:180
void setAlignment(Qt::Alignment alignment)
Sets the alignment of the image within the widget.
void setForceAspectRatioH(bool force)
Sets whether to force the image height to maintain the aspect ratio.
QIcon icon()
Returns the currently displayed QIcon.
Definition ImageView.h:203
void setIconMode(QIcon::Mode mode)
Sets the icon rendering mode.
void resizeEvent(QResizeEvent *resize_event) override
Handles resize events, updating the cached scaled image.
void setBlendImage(const QPixmap &blend_image)
Sets a secondary image to blend with the primary image.
void setImage(const QPixmap &pixmap)
Sets the displayed image from a QPixmap.
QSize sizeHint() const override
Returns the recommended size for this widget.
void setIconID(const StringView &image, bool force_refresh=false)
Sets the displayed icon by its resource ID.
void setViewMode(ViewMode mode)
Sets the view mode controlling how the image fits the widget.
Definition ImageView.h:157
ImageView(QWidget *parent=nullptr)
Constructs an empty ImageView.
void setImageID(const StringView &image, bool force_refresh=false)
Sets the displayed image by its resource ID.
void setForceAspectRatioW(bool force)
Sets whether to force the image width to maintain the aspect ratio.
void showContextMenuSlot(const QPoint &pos)
Shows a context menu at the given position for image operations.
A ResourceListener which will always be executed on the main UI thread and can be tied to a Qt Object...
Definition QTTools.h:493
The core String View class for the NDEVR API.
Definition StringView.h:58
The core String class for the NDEVR API.
Definition String.h:95
The primary namespace for the NDEVR SDK.
float fltp04
Defines an alias representing a 4 byte floating-point number Bit layout is as follows: -Sign: 1 bit a...
double fltp08
Defines an alias representing an 8 byte floating-point number.