6#pragma warning(disable : 4251)
7#pragma warning(disable : 4172)
8#pragma warning(disable : 4127)
9#pragma warning(disable : 4800)
11#include <QQuickPaintedItem>
21#include "../image.hpp"
52 Q_PROPERTY(
double imageX MEMBER imageX_ READ
ImageX WRITE
SetImageX NOTIFY NotifyImageX);
53 Q_PROPERTY(
double imageY MEMBER imageY_ READ
ImageY WRITE
SetImageY NOTIFY NotifyImageY);
78 static void Register(
const char *uri,
int versionMajor,
int versionMinor,
const char *qmlName)
80 qmlRegisterType<T>(uri, versionMajor, versionMinor, qmlName);
81 qmlRegisterUncreatableMetaObject(Cvb::UI::staticMetaObject, uri, versionMajor, versionMinor,
"LabelScale",
"CVB: cannot object for enumerations");
94 Register<ImageLabelItem>(
"CvbQuick", 1, 0,
"ImageLabel");
118 if (imageX_ == imageX)
146 if (imageY_ == imageY)
190 return static_cast<int>(labelScale_);
218 void OnImageXChanged();
220 void OnImageYChanged();
222 void OnImageViewChanged();
224 void OnLabelScaleChanged();
230 void NotifyImageView();
231 void NotifyLabelScale();
235 void SetupConnections();
237 double imageX_ = 0.0;
238 double imageY_ = 0.0;
257 Q_PROPERTY(
int width READ
Width NOTIFY NotifyRefreshImage)
258 Q_PROPERTY(
int height READ
Height NOTIFY NotifyRefreshImage)
259 Q_PROPERTY(
int planesCount READ
PlanesCount NOTIFY NotifyRefreshImage)
284 UnregisterEventImageDataUpdated();
302 UnregisterEventImageDataUpdated();
306 eventCookieDataUpdated_ = image_->RegisterEventPixelContentChanged([&](
const class Image &,
Rect<int>)
311 NotifyRefreshImage();
341 return image_->Width();
357 return image_->Height();
373 return image_->PlanesCount();
378 void UnregisterEventImageDataUpdated() noexcept
381 image_->UnregisterEventPixelContentChanged(eventCookieDataUpdated_);
394 void NotifyRefresh();
395 void NotifyRefreshImage();
445 auto result = dispatcher_->TryZoomIn([&]()
471 auto result = dispatcher_->TryZoomOut([&]()
499 auto result = dispatcher_->TryTranslate(
QtToCvb(translation), [&]()
530 return CvbToQt(dispatcher_->MapTargetToSource(
QtToCvb(targetPoint)));
541 return CvbToQt(dispatcher_->MapSourceToImage(
QtToCvb(sourcePoint)));
552 return CvbToQt(dispatcher_->MapTargetToView(
QtToCvb(targetPoint)));
563 return CvbToQt(dispatcher_->MapSourceToTarget(
QtToCvb(sourcePoint)));
574 return CvbToQt(dispatcher_->MapImageToSource(
QtToCvb(imagePoint)));
602 auto image = image_->
Image();
606 dispatcher_->UploadImage(*image,
615#pragma endregion QML Interface
625 dispatcher_.reset(
new Private::ImageViewDispatcher([&]()
635 connect(
this, &ImageViewItem::NotifyViewRect,
this, &ImageViewItem::OnViewRectChanged);
636 connect(
this, &ImageViewItem::NotifyImageRect,
this, &ImageViewItem::OnImageRectChanged);
637 connect(
this, &ImageViewItem::NotifyZoom,
this, &ImageViewItem::OnZoomIDChanged);
638 connect(
this, &ImageViewItem::NotifyZoom,
this, &ImageViewItem::OnZoomFactorChanged);
639 connect(
this, &ImageViewItem::NotifyViewAnchor,
this, &ImageViewItem::OnViewAnchorChnaged);
642 ~ImageViewItem() =
default;
656 static void Register(
const char *uri,
int versionMajor,
int versionMinor,
const char *qmlName)
658 qmlRegisterType<T>(uri, versionMajor, versionMinor, qmlName);
659 qmlRegisterUncreatableMetaObject(Cvb::UI::staticMetaObject, uri, versionMajor, versionMinor,
"ZoomID",
"CVB: cannot object for enumerations");
660 qmlRegisterUncreatableMetaObject(Cvb::UI::staticMetaObject, uri, versionMajor, versionMinor,
"UploadMode",
"CVB: cannot object for enumerations");
672 Register<ImageViewItem>(
"CvbQuick", 1, 0,
"ImageView");
675#pragma endregion CTor/DTor/Register
689 return CvbToQt(dispatcher_->ImageRect());
702 return CvbToQt(dispatcher_->ViewRect());
714 return CvbToQt(dispatcher_->TargetRect());
727 return CvbToQt(dispatcher_->SourceRect());
748 return static_cast<int>(dispatcher_->ZoomID());
762 dispatcher_->UpdateZoomID(
static_cast<UI::ZoomID>(
id),
779 return dispatcher_->ZoomFactor();
791 dispatcher_->UpdateZoomFactor(factor,
831 return CvbToQt(dispatcher_->ViewAnchor());
843 dispatcher_->UpdateViewAnchor(
QtToCvb(viewAnchor),
859 return CvbToQt(dispatcher_->ImageAnchor());
871 dispatcher_->UpdateImageAnchor(
QtToCvb(imageAnchor),
892 auto image = image_->
Image();
893 if (!image || !dispatcher_->IsHoverPositionValid())
896 auto hoverPosition = dispatcher_->HoverPosition();
897 Point2D<int> hoverPositionInt(
static_cast<int>(std::floor(hoverPosition.X())),
898 static_cast<int>(std::floor(hoverPosition.Y())));
901 if (hoverPositionInt.
X() == image->Width())
902 hoverPositionInt.
SetX(
static_cast<int>(hoverPosition.X() - 1.0));
903 if (hoverPositionInt.
Y() == image->Height())
904 hoverPositionInt.
SetY(
static_cast<int>(hoverPosition.Y() - 1.0));
919 if (!dispatcher_->IsHoverPositionValid())
922 return CvbToQt(dispatcher_->HoverPosition());
936 return static_cast<int>(dispatcher_->UploadMode());
951 dispatcher_->UpdateUploadMode(
static_cast<UI::UploadMode>(uploadMode),
958#pragma endregion Properties
967 void OnViewRectChanged()
969 UpdateTargetSource();
972 void OnImageRectChanged()
974 UpdateTargetSource();
977 void OnZoomFactorChanged()
979 UpdateTargetSource();
984 void OnZoomIDChanged()
986 UpdateTargetSource();
991 void OnViewAnchorChnaged()
993 auto targetPoint = dispatcher_->MapViewToTarget(dispatcher_->ViewAnchor());
994 targetPoint = dispatcher_->LimitPointToRect(targetPoint, dispatcher_->TargetRect());
996 auto sourcePoint = dispatcher_->MapTargetToSource(targetPoint);
997 auto imagePoint = dispatcher_->MapSourceToImage(sourcePoint);
999 dispatcher_->UpdateImageAnchor(imagePoint,
1002 NotifyImageAnchor();
1009#pragma endregion Slots
1016 void UpdateTargetSource()
1018 dispatcher_->UpdateTargetSource(
1029 QImage ScreenImage() const noexcept
1031 auto data = dispatcher_->Buffer();
1032 auto size = dispatcher_->BufferSize();
1034 return QImage(data,
size.Width(),
size.Height(), QImage::Format_ARGB32_Premultiplied);
1038#pragma endregion Helper
1045 void paint(
QPainter *painter)
override
1049 Private::ImageViewDispatcherGuard guard(*dispatcher_);
1050 if (!dispatcher_->IsBufferValid())
1053 auto screenImage = ScreenImage();
1062 CvbToQt(dispatcher_->SourceRect()));
1066 auto image = image_->
Image();
1078 CvbToQt(dispatcher_->SourceRectAdj()));
1082 void geometryChanged(
const QRectF &newGeometry,
const QRectF &oldGeometry)
override
1084 auto tmpNewGemotry =
QtToCvb(newGeometry);
1085 if (tmpNewGemotry != dispatcher_->ViewRect())
1086 dispatcher_->UpdateViewRect(tmpNewGemotry, [&]() { NotifyViewRect(); });
1100 auto numDegrees =
event->angleDelta().y();
1102 if (numDegrees <= -15)
1104 else if (numDegrees >= 15)
1110 if (
event->buttons() & Qt::LeftButton)
1113 if (!dispatcher_->IsLastMousePositionValid())
1115 dispatcher_->InvalidateLastMousePosition(currentPos);
1120 dispatcher_->InvalidateLastMousePosition(currentPos);
1127 dispatcher_->InvalidateLastMousePosition();
1138 auto hoverPosition = dispatcher_->MapViewToImage(
QtToCvb(
event->posF()));
1139 if (!dispatcher_->ImageRect().Contains(hoverPosition))
1142 dispatcher_->UpdateHoverPosition(hoverPosition,
1152#pragma endregion Reimplemented from Qt
1159 ImageController* image_ =
nullptr;
1163#pragma endregion Members
1169 void NotifyImageRect();
1170 void NotifyViewRect();
1171 void NotifySourceRect();
1172 void NotifyTargetRect();
1178 void NotifyViewAnchor();
1179 void NotifyImageAnchor();
1184 void NotifyUploadMode();
1186#pragma endregion Notify
1190inline ImageLabelItem::ImageLabelItem(
QQuickItem *parent)
1194 connect(
this, &ImageLabelItem::NotifyImageView,
this, &ImageLabelItem::OnImageViewChanged);
1198inline void ImageLabelItem::OnImageXChanged()
1204 auto sourceX = imageX_ - sourceRect.x();
1205 auto targetX = sourceX * view_->
ZoomFactor();
1207 auto viewX = targetX + targetRect.
x();
1212inline void ImageLabelItem::OnImageYChanged()
1218 auto sourceY = imageY_ - sourceRect.y();
1219 auto targetY = sourceY * view_->
ZoomFactor();
1221 auto viewY = targetY + targetRect.
y();
1226inline void ImageLabelItem::OnImageViewChanged()
1231 OnLabelScaleChanged();
1234inline void ImageLabelItem::OnLabelScaleChanged()
1236 if (labelScale_ == UI::LabelScale::Off)
1250inline void ImageLabelItem::SetupConnections()
1255 connect(
this, &ImageLabelItem::NotifyImageX,
this, &ImageLabelItem::OnImageXChanged);
1256 connect(
this, &ImageLabelItem::NotifyImageY,
this, &ImageLabelItem::OnImageYChanged);
1257 connect(
this, &ImageLabelItem::NotifyLabelScale,
this, &ImageLabelItem::OnLabelScaleChanged);
1259 connect(view_, &ImageViewItem::NotifySourceRect,
this, &ImageLabelItem::OnImageXChanged);
1260 connect(view_, &ImageViewItem::NotifySourceRect,
this, &ImageLabelItem::OnImageYChanged);
1261 connect(view_, &ImageViewItem::NotifyTargetRect,
this, &ImageLabelItem::OnImageXChanged);
1262 connect(view_, &ImageViewItem::NotifyTargetRect,
this, &ImageLabelItem::OnImageYChanged);
1263 connect(view_, &ImageViewItem::NotifyZoom,
this, &ImageLabelItem::OnImageXChanged);
1264 connect(view_, &ImageViewItem::NotifyZoom,
this, &ImageLabelItem::OnImageYChanged);
1266 connect(view_, &ImageViewItem::NotifyZoom,
this, &ImageLabelItem::OnLabelScaleChanged);
1271using ImageLabelItem = Quick::ImageLabelItem;
1272using ImageController = Quick::ImageController;
1273using ImageViewItem = Quick::ImageViewItem;
Image rectangle operations on a device.
Definition: decl_image_rect.hpp:18
Cookie used to unregister event handlers.
Definition: global.hpp:535
The Common Vision Blox image.
Definition: decl_image.hpp:45
T X() const noexcept
Gets the x-component of the point.
Definition: point_2d.hpp:86
T Y() const noexcept
Gets the y-component of the point.
Definition: point_2d.hpp:106
void SetX(T x) noexcept
Sets the x-component of the point.
Definition: point_2d.hpp:96
void SetY(T y)
Sets the y-component of the point.
Definition: point_2d.hpp:116
View to display an image.
Definition: decl_image_view.hpp:75
Controller object for the QML image view item.
Definition: image_view_item.hpp:254
int Width() const noexcept
Width of the shared image in pixels.
Definition: image_view_item.hpp:337
int Height() const noexcept
Height of the shared image in pixels.
Definition: image_view_item.hpp:353
void Refresh(const ImagePtr &image, AutoRefresh autoRefresh=AutoRefresh::Off)
Share the image and refresh the view.
Definition: image_view_item.hpp:296
int PlanesCount() const noexcept
Get the number of planes for this image.
Definition: image_view_item.hpp:369
void Refresh()
Refresh the view.
Definition: image_view_item.hpp:319
void ReleaseRefreshShare() noexcept
Releases the shared image.
Definition: image_view_item.hpp:281
ImagePtr Image() const
Get the currently shared image.
Definition: image_view_item.hpp:268
Image label item for QML.
Definition: image_view_item.hpp:49
double ImageY() const noexcept
Get the Y position of this label on the image.
Definition: image_view_item.hpp:132
void SetImageView(ImageViewItem *view)
Set the image view for this label.
Definition: image_view_item.hpp:168
void SetImageY(double imageY)
Set the Y position of this label on the image.
Definition: image_view_item.hpp:144
double ImageX() const noexcept
Get the X position of this label on the image.
Definition: image_view_item.hpp:104
void SetImageX(double imageX)
Set the X position of this label on the image.
Definition: image_view_item.hpp:116
static void Register()
Convenience method to register this type in QML.
Definition: image_view_item.hpp:92
void SetLabelScale(int labelScale)
Set the label scale behaviour (as integer, see Cvb::UI::LabelScale).
Definition: image_view_item.hpp:204
int LabelScale() const noexcept
Get the label scale behaviour (as integer, see Cvb::UI::LabelScale).
Definition: image_view_item.hpp:188
static void Register(const char *uri, int versionMajor, int versionMinor, const char *qmlName)
Convenience method to register this type or a derived type in QML.
Definition: image_view_item.hpp:78
Image view item for QML.
Definition: image_view_item.hpp:411
Q_INVOKABLE QPointF MapViewToTarget(const QPointF &viewPoint) const
Maps a point from the view rectangle to the target rect.
Definition: image_view_item.hpp:517
Q_INVOKABLE QPointF MapSourceToTarget(const QPointF &sourcePoint) const
Maps a point from the source rectangle to the target rectangle.
Definition: image_view_item.hpp:561
Q_INVOKABLE QPointF MapTargetToSource(const QPointF &targetPoint) const
Maps a point from the target rectangle to the source rect.
Definition: image_view_item.hpp:528
int ZoomID() const
Get the zoom identifier for special zoom steps (as integer, see Cvb::UI::ZoomID).
Definition: image_view_item.hpp:746
void SetZoomID(int id)
Set the zoom identifier for special zoom steps (as integer, see Cvb::UI::ZoomID).
Definition: image_view_item.hpp:760
QRectF SourceRect() const noexcept
Get the rectangle inside the image rectangle that is actually rendered.
Definition: image_view_item.hpp:725
QPointF HoverPosition() const noexcept
Get the point the mouse is hovering over.
Definition: image_view_item.hpp:917
QPointF ViewAnchor() const noexcept
Get the reference point for mouse operations in view coordinates.
Definition: image_view_item.hpp:829
Q_INVOKABLE bool TryTranslate(const QPointF &translation)
Tries to translate the target rectangle to a give point.
Definition: image_view_item.hpp:497
Q_INVOKABLE QPointF MapImageToSource(const QPointF &imagePoint) const
Maps a point from the image rectangle to the source rectangle.
Definition: image_view_item.hpp:572
void SetImage(QObject *image)
Set the image controller for this view item.
Definition: image_view_item.hpp:808
void SetViewAnchor(const QPointF &viewAnchor)
Set the reference point for mouse operations in view coordinates.
Definition: image_view_item.hpp:841
QRectF ViewRect() const noexcept
Get the rectangle this items covers.
Definition: image_view_item.hpp:700
QVector< double > HoverPixel() const
The image pixel value the mouse is currently hovered over.
Definition: image_view_item.hpp:887
Q_INVOKABLE bool TryZoomOut()
Tries to zoom out.
Definition: image_view_item.hpp:469
Q_INVOKABLE QPointF MapTargetToView(const QPointF &targetPoint) const
Maps a point from the target rectangle to the view rectangle.
Definition: image_view_item.hpp:550
void SetImageAnchor(const QPointF &imageAnchor)
Set the reference point for mouse operations in image coordinates.
Definition: image_view_item.hpp:869
QRectF ImageRect() const noexcept
Get the rectangle described by the image buffer associated with the view.
Definition: image_view_item.hpp:687
int UploadMode() const noexcept
Get the current upload mode (as integer, see Cvb::UI::UploadMode).
Definition: image_view_item.hpp:934
Q_INVOKABLE QPointF MapSourceToImage(const QPointF &sourcePoint) const
Maps a point from the source rectangle to the image rect.
Definition: image_view_item.hpp:539
Q_INVOKABLE bool TryZoomIn()
Tries to zoom in.
Definition: image_view_item.hpp:443
static void Register()
Convenience method to register this type in QML.
Definition: image_view_item.hpp:670
QRectF TargetRect() const noexcept
Get the rectangle inside the view rectangle the image is actually rendered to.
Definition: image_view_item.hpp:712
void SetZoomFactor(double factor)
Set the view's zoom factor.
Definition: image_view_item.hpp:789
QPointF ImageAnchor() const noexcept
Get the reference point for mouse operations in image coordinates.
Definition: image_view_item.hpp:857
void Refresh()
Refresh the currently shared image.
Definition: image_view_item.hpp:597
Q_INVOKABLE QPointF MapViewToImage(const QPointF &viewPoint) const
Maps a point from the view rectangle to the image rectangle.
Definition: image_view_item.hpp:583
void SetUploadMode(int uploadMode)
Set the current upload mode (as integer).
Definition: image_view_item.hpp:949
double ZoomFactor() const
Get the view's zoom factor.
Definition: image_view_item.hpp:777
static void Register(const char *uri, int versionMajor, int versionMinor, const char *qmlName)
Convenience method to register this type or a derived type in QML.
Definition: image_view_item.hpp:656
ZoomID
Identifier for a zoom factor.
Definition: detail_ui.hpp:64
Cvb::String QtToCvb(const QString text) noexcept
Convenience converter for strings.
Definition: ui.hpp:239
AutoRefresh
Allows to automatically refresh, if image content changes.
Definition: detail_ui.hpp:118
LabelScale
Switch defining if image view labels are sensitive to zoom operations.
Definition: detail_ui.hpp:134
UploadMode
Defines the upload behavior.
Definition: detail_ui.hpp:38
QString CvbToQt(const Cvb::String &text) noexcept
Convenience converter for strings.
Definition: ui.hpp:254
Root namespace for the Image Manager interface.
Definition: c_barcode.h:24
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
void drawImage(const QRectF &target, const QImage &image, const QRectF &source, Qt::ImageConversionFlags flags)
virtual bool event(QEvent *ev) override
virtual void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry)
QPointF mapFromGlobal(const QPointF &point) const const
void setAcceptHoverEvents(bool enabled)
QSizeF size() const const
QVector< T > fromStdVector(const std::vector< T > &vector)