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);
76 static void Register(
const char *uri,
int versionMajor,
int versionMinor,
const char *qmlName)
78 qmlRegisterType<T>(uri, versionMajor, versionMinor, qmlName);
79 qmlRegisterUncreatableMetaObject(Cvb::UI::staticMetaObject, uri, versionMajor, versionMinor,
"LabelScale",
"CVB: cannot object for enumerations");
92 Register<ImageLabelItem>(
"CvbQuick", 1, 0,
"ImageLabel");
116 if (imageX_ == imageX)
144 if (imageY_ == imageY)
188 return static_cast<int>(labelScale_);
216 void OnImageXChanged();
218 void OnImageYChanged();
220 void OnImageViewChanged();
222 void OnLabelScaleChanged();
228 void NotifyImageView();
229 void NotifyLabelScale();
233 void SetupConnections();
235 double imageX_ = 0.0;
236 double imageY_ = 0.0;
255 Q_PROPERTY(
int width READ
Width NOTIFY NotifyRefreshImage)
256 Q_PROPERTY(
int height READ
Height NOTIFY NotifyRefreshImage)
257 Q_PROPERTY(
int planesCount READ
PlanesCount NOTIFY NotifyRefreshImage)
282 UnregisterEventImageDataUpdated();
301 UnregisterEventImageDataUpdated();
305 eventCookieDataUpdated_ =
309 NotifyRefreshImage();
339 return image_->Width();
355 return image_->Height();
371 return image_->PlanesCount();
376 void UnregisterEventImageDataUpdated() noexcept
379 image_->UnregisterEventPixelContentChanged(eventCookieDataUpdated_);
392 void NotifyRefresh();
393 void NotifyRefreshImage();
443 auto result = dispatcher_->TryZoomIn([&]()
469 auto result = dispatcher_->TryZoomOut([&]()
497 auto result = dispatcher_->TryTranslate(
QtToCvb(translation), [&]()
528 return CvbToQt(dispatcher_->MapTargetToSource(
QtToCvb(targetPoint)));
539 return CvbToQt(dispatcher_->MapSourceToImage(
QtToCvb(sourcePoint)));
550 return CvbToQt(dispatcher_->MapTargetToView(
QtToCvb(targetPoint)));
561 return CvbToQt(dispatcher_->MapSourceToTarget(
QtToCvb(sourcePoint)));
572 return CvbToQt(dispatcher_->MapImageToSource(
QtToCvb(imagePoint)));
600 auto image = image_->
Image();
604 dispatcher_->UploadImage(*image,
613#pragma endregion QML Interface
623 dispatcher_ = std::make_unique<Private::ImageViewDispatcher>([&]()
633 connect(
this, &ImageViewItem::NotifyViewRect,
this, &ImageViewItem::OnViewRectChanged);
634 connect(
this, &ImageViewItem::NotifyImageRect,
this, &ImageViewItem::OnImageRectChanged);
635 connect(
this, &ImageViewItem::NotifyZoom,
this, &ImageViewItem::OnZoomIDChanged);
636 connect(
this, &ImageViewItem::NotifyZoom,
this, &ImageViewItem::OnZoomFactorChanged);
637 connect(
this, &ImageViewItem::NotifyViewAnchor,
this, &ImageViewItem::OnViewAnchorChnaged);
653 static void Register(
const char *uri,
int versionMajor,
int versionMinor,
const char *qmlName)
655 qmlRegisterType<T>(uri, versionMajor, versionMinor, qmlName);
656 qmlRegisterUncreatableMetaObject(Cvb::UI::staticMetaObject, uri, versionMajor, versionMinor,
"ZoomID",
"CVB: cannot object for enumerations");
657 qmlRegisterUncreatableMetaObject(Cvb::UI::staticMetaObject, uri, versionMajor, versionMinor,
"UploadMode",
"CVB: cannot object for enumerations");
669 Register<ImageViewItem>(
"CvbQuick", 1, 0,
"ImageView");
672#pragma endregion CTor/DTor/Register
686 return CvbToQt(dispatcher_->ImageRect());
699 return CvbToQt(dispatcher_->ViewRect());
711 return CvbToQt(dispatcher_->TargetRect());
724 return CvbToQt(dispatcher_->SourceRect());
745 return static_cast<int>(dispatcher_->ZoomID());
759 dispatcher_->UpdateZoomID(
static_cast<UI::ZoomID>(
id),
776 return dispatcher_->ZoomFactor();
788 dispatcher_->UpdateZoomFactor(factor,
828 return CvbToQt(dispatcher_->ViewAnchor());
840 dispatcher_->UpdateViewAnchor(
QtToCvb(viewAnchor),
856 return CvbToQt(dispatcher_->ImageAnchor());
868 dispatcher_->UpdateImageAnchor(
QtToCvb(imageAnchor),
889 auto image = image_->
Image();
890 if (!image || !dispatcher_->IsHoverPositionValid())
893 auto hoverPosition = dispatcher_->HoverPosition();
894 Point2D<int> hoverPositionInt(
static_cast<int>(std::floor(hoverPosition.X())),
895 static_cast<int>(std::floor(hoverPosition.Y())));
898 if (hoverPositionInt.
X() == image->Width())
899 hoverPositionInt.
SetX(
static_cast<int>(hoverPosition.X() - 1.0));
900 if (hoverPositionInt.
Y() == image->Height())
901 hoverPositionInt.
SetY(
static_cast<int>(hoverPosition.Y() - 1.0));
916 if (!dispatcher_->IsHoverPositionValid())
919 return CvbToQt(dispatcher_->HoverPosition());
933 return static_cast<int>(dispatcher_->UploadMode());
948 dispatcher_->UpdateUploadMode(
static_cast<UI::UploadMode>(uploadMode),
955#pragma endregion Properties
964 void OnViewRectChanged()
966 UpdateTargetSource();
969 void OnImageRectChanged()
971 UpdateTargetSource();
974 void OnZoomFactorChanged()
976 UpdateTargetSource();
981 void OnZoomIDChanged()
983 UpdateTargetSource();
988 void OnViewAnchorChnaged()
990 auto targetPoint = dispatcher_->MapViewToTarget(dispatcher_->ViewAnchor());
991 targetPoint = dispatcher_->LimitPointToRect(targetPoint, dispatcher_->TargetRect());
993 auto sourcePoint = dispatcher_->MapTargetToSource(targetPoint);
994 auto imagePoint = dispatcher_->MapSourceToImage(sourcePoint);
996 dispatcher_->UpdateImageAnchor(imagePoint,
1006#pragma endregion Slots
1013 void UpdateTargetSource()
1015 dispatcher_->UpdateTargetSource(
1026 QImage ScreenImage() const noexcept
1028 auto data = dispatcher_->Buffer();
1029 auto size = dispatcher_->BufferSize();
1031 return QImage(data,
size.Width(),
size.Height(), QImage::Format_ARGB32_Premultiplied);
1035#pragma endregion Helper
1042 void paint(
QPainter *painter)
override
1046 Private::ImageViewDispatcherGuard guard(*dispatcher_);
1047 if (!dispatcher_->IsBufferValid())
1050 auto screenImage = ScreenImage();
1059 CvbToQt(dispatcher_->SourceRect()));
1063 auto image = image_->
Image();
1075 CvbToQt(dispatcher_->SourceRectAdj()));
1079 void geometryChanged(
const QRectF &newGeometry,
const QRectF &oldGeometry)
override
1081 auto tmpNewGemotry =
QtToCvb(newGeometry);
1082 if (tmpNewGemotry != dispatcher_->ViewRect())
1083 dispatcher_->UpdateViewRect(tmpNewGemotry, [&]() { NotifyViewRect(); });
1097 auto numDegrees =
event->angleDelta().y();
1099 if (numDegrees <= -15)
1101 else if (numDegrees >= 15)
1107 if (
event->buttons() & Qt::LeftButton)
1110 if (!dispatcher_->IsLastMousePositionValid())
1112 dispatcher_->InvalidateLastMousePosition(currentPos);
1117 dispatcher_->InvalidateLastMousePosition(currentPos);
1124 dispatcher_->InvalidateLastMousePosition();
1135 auto hoverPosition = dispatcher_->MapViewToImage(
QtToCvb(
event->posF()));
1136 if (!dispatcher_->ImageRect().Contains(hoverPosition))
1139 dispatcher_->UpdateHoverPosition(hoverPosition,
1149#pragma endregion Reimplemented from Qt
1156 ImageController* image_ =
nullptr;
1160#pragma endregion Members
1166 void NotifyImageRect();
1167 void NotifyViewRect();
1168 void NotifySourceRect();
1169 void NotifyTargetRect();
1175 void NotifyViewAnchor();
1176 void NotifyImageAnchor();
1181 void NotifyUploadMode();
1183#pragma endregion Notify
1187inline ImageLabelItem::ImageLabelItem(
QQuickItem *parent)
1191 connect(
this, &ImageLabelItem::NotifyImageView,
this, &ImageLabelItem::OnImageViewChanged);
1195inline void ImageLabelItem::OnImageXChanged()
1201 auto sourceX = imageX_ - sourceRect.x();
1202 auto targetX = sourceX * view_->
ZoomFactor();
1204 auto viewX = targetX + targetRect.
x();
1209inline void ImageLabelItem::OnImageYChanged()
1215 auto sourceY = imageY_ - sourceRect.y();
1216 auto targetY = sourceY * view_->
ZoomFactor();
1218 auto viewY = targetY + targetRect.
y();
1223inline void ImageLabelItem::OnImageViewChanged()
1228 OnLabelScaleChanged();
1231inline void ImageLabelItem::OnLabelScaleChanged()
1233 if (labelScale_ == UI::LabelScale::Off)
1247inline void ImageLabelItem::SetupConnections()
1252 connect(
this, &ImageLabelItem::NotifyImageX,
this, &ImageLabelItem::OnImageXChanged);
1253 connect(
this, &ImageLabelItem::NotifyImageY,
this, &ImageLabelItem::OnImageYChanged);
1254 connect(
this, &ImageLabelItem::NotifyLabelScale,
this, &ImageLabelItem::OnLabelScaleChanged);
1256 connect(view_, &ImageViewItem::NotifySourceRect,
this, &ImageLabelItem::OnImageXChanged);
1257 connect(view_, &ImageViewItem::NotifySourceRect,
this, &ImageLabelItem::OnImageYChanged);
1258 connect(view_, &ImageViewItem::NotifyTargetRect,
this, &ImageLabelItem::OnImageXChanged);
1259 connect(view_, &ImageViewItem::NotifyTargetRect,
this, &ImageLabelItem::OnImageYChanged);
1260 connect(view_, &ImageViewItem::NotifyZoom,
this, &ImageLabelItem::OnImageXChanged);
1261 connect(view_, &ImageViewItem::NotifyZoom,
this, &ImageLabelItem::OnImageYChanged);
1263 connect(view_, &ImageViewItem::NotifyZoom,
this, &ImageLabelItem::OnLabelScaleChanged);
1268using ImageLabelItem = Quick::ImageLabelItem;
1269using ImageController = Quick::ImageController;
1270using ImageViewItem = Quick::ImageViewItem;
Image rectangle operations on a device.
Definition: decl_image_rect.hpp:18
Cookie used to unregister event handlers.
Definition: global.hpp:566
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:252
int Width() const noexcept
Width of the shared image in pixels.
Definition: image_view_item.hpp:335
int Height() const noexcept
Height of the shared image in pixels.
Definition: image_view_item.hpp:351
void Refresh(const ImagePtr &image, AutoRefresh autoRefresh=AutoRefresh::Off)
Share the image and refresh the view.
Definition: image_view_item.hpp:294
int PlanesCount() const noexcept
Get the number of planes for this image.
Definition: image_view_item.hpp:367
void Refresh()
Refresh the view.
Definition: image_view_item.hpp:317
void ReleaseRefreshShare() noexcept
Releases the shared image.
Definition: image_view_item.hpp:279
ImagePtr Image() const
Get the currently shared image.
Definition: image_view_item.hpp:266
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:130
void SetImageView(ImageViewItem *view)
Set the image view for this label.
Definition: image_view_item.hpp:166
void SetImageY(double imageY)
Set the Y position of this label on the image.
Definition: image_view_item.hpp:142
double ImageX() const noexcept
Get the X position of this label on the image.
Definition: image_view_item.hpp:102
void SetImageX(double imageX)
Set the X position of this label on the image.
Definition: image_view_item.hpp:114
static void Register()
Convenience method to register this type in QML.
Definition: image_view_item.hpp:90
void SetLabelScale(int labelScale)
Set the label scale behaviour (as integer, see Cvb::UI::LabelScale).
Definition: image_view_item.hpp:202
int LabelScale() const noexcept
Get the label scale behaviour (as integer, see Cvb::UI::LabelScale).
Definition: image_view_item.hpp:186
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:76
Image view item for QML.
Definition: image_view_item.hpp:409
Q_INVOKABLE QPointF MapViewToTarget(const QPointF &viewPoint) const
Maps a point from the view rectangle to the target rect.
Definition: image_view_item.hpp:515
Q_INVOKABLE QPointF MapSourceToTarget(const QPointF &sourcePoint) const
Maps a point from the source rectangle to the target rectangle.
Definition: image_view_item.hpp:559
Q_INVOKABLE QPointF MapTargetToSource(const QPointF &targetPoint) const
Maps a point from the target rectangle to the source rect.
Definition: image_view_item.hpp:526
int ZoomID() const
Get the zoom identifier for special zoom steps (as integer, see Cvb::UI::ZoomID).
Definition: image_view_item.hpp:743
void SetZoomID(int id)
Set the zoom identifier for special zoom steps (as integer, see Cvb::UI::ZoomID).
Definition: image_view_item.hpp:757
QRectF SourceRect() const noexcept
Get the rectangle inside the image rectangle that is actually rendered.
Definition: image_view_item.hpp:722
QPointF HoverPosition() const noexcept
Get the point the mouse is hovering over.
Definition: image_view_item.hpp:914
QPointF ViewAnchor() const noexcept
Get the reference point for mouse operations in view coordinates.
Definition: image_view_item.hpp:826
Q_INVOKABLE bool TryTranslate(const QPointF &translation)
Tries to translate the target rectangle to a give point.
Definition: image_view_item.hpp:495
Q_INVOKABLE QPointF MapImageToSource(const QPointF &imagePoint) const
Maps a point from the image rectangle to the source rectangle.
Definition: image_view_item.hpp:570
void SetImage(QObject *image)
Set the image controller for this view item.
Definition: image_view_item.hpp:805
void SetViewAnchor(const QPointF &viewAnchor)
Set the reference point for mouse operations in view coordinates.
Definition: image_view_item.hpp:838
QRectF ViewRect() const noexcept
Get the rectangle this items covers.
Definition: image_view_item.hpp:697
QVector< double > HoverPixel() const
The image pixel value the mouse is currently hovered over.
Definition: image_view_item.hpp:884
Q_INVOKABLE bool TryZoomOut()
Tries to zoom out.
Definition: image_view_item.hpp:467
Q_INVOKABLE QPointF MapTargetToView(const QPointF &targetPoint) const
Maps a point from the target rectangle to the view rectangle.
Definition: image_view_item.hpp:548
void SetImageAnchor(const QPointF &imageAnchor)
Set the reference point for mouse operations in image coordinates.
Definition: image_view_item.hpp:866
QRectF ImageRect() const noexcept
Get the rectangle described by the image buffer associated with the view.
Definition: image_view_item.hpp:684
int UploadMode() const noexcept
Get the current upload mode (as integer, see Cvb::UI::UploadMode).
Definition: image_view_item.hpp:931
Q_INVOKABLE QPointF MapSourceToImage(const QPointF &sourcePoint) const
Maps a point from the source rectangle to the image rect.
Definition: image_view_item.hpp:537
Q_INVOKABLE bool TryZoomIn()
Tries to zoom in.
Definition: image_view_item.hpp:441
static void Register()
Convenience method to register this type in QML.
Definition: image_view_item.hpp:667
QRectF TargetRect() const noexcept
Get the rectangle inside the view rectangle the image is actually rendered to.
Definition: image_view_item.hpp:709
void SetZoomFactor(double factor)
Set the view's zoom factor.
Definition: image_view_item.hpp:786
QPointF ImageAnchor() const noexcept
Get the reference point for mouse operations in image coordinates.
Definition: image_view_item.hpp:854
void Refresh()
Refresh the currently shared image.
Definition: image_view_item.hpp:595
Q_INVOKABLE QPointF MapViewToImage(const QPointF &viewPoint) const
Maps a point from the view rectangle to the image rectangle.
Definition: image_view_item.hpp:581
void SetUploadMode(int uploadMode)
Set the current upload mode (as integer).
Definition: image_view_item.hpp:946
double ZoomFactor() const
Get the view's zoom factor.
Definition: image_view_item.hpp:774
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:653
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:238
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:253
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)