CVB++ 14.0
image_view_item.hpp
1#pragma once
2
3#include <atomic>
4
5#pragma warning(push)
6#pragma warning(disable : 4251)
7#pragma warning(disable : 4172)
8#pragma warning(disable : 4127) // const expr
9#pragma warning(disable : 4800)
10
11#include <QQuickPaintedItem>
12#include <QPainter>
13#include <QtGlobal>
14
15
16
17
18#pragma warning(pop)
19
20#include "ui.hpp"
21#include "../image.hpp"
22
23namespace Cvb
24{
25
26CVB_BEGIN_INLINE_NS
27
28namespace UI
29{
30
32namespace Quick
33{
34
35
36class ImageViewItem;
37
39
48 : public QQuickItem
49{
50 Q_OBJECT
51
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);
54
55 Q_PROPERTY(int labelScale MEMBER labelScale_ READ LabelScale WRITE SetLabelScale NOTIFY NotifyLabelScale);
56
57 Q_PROPERTY(ImageViewItem* imageView READ ImageView WRITE SetImageView NOTIFY NotifyImageView)
58
59 public:
60
62
63 ~ImageLabelItem() = default;
64
65
67
77 template<class T>
78 static void Register(const char *uri, int versionMajor, int versionMinor, const char *qmlName)
79 {
80 qmlRegisterType<T>(uri, versionMajor, versionMinor, qmlName);
81 qmlRegisterUncreatableMetaObject(Cvb::UI::staticMetaObject, uri, versionMajor, versionMinor, "LabelScale", "CVB: cannot object for enumerations");
82 }
83
84
86
92 static void Register()
93 {
94 Register<ImageLabelItem>("CvbQuick", 1, 0, "ImageLabel");
95 }
96
98
104 double ImageX() const noexcept
105 {
106 return imageX_;
107 }
108
110
116 void SetImageX(double imageX)
117 {
118 if (imageX_ == imageX)
119 return;
120
121 imageX_ = imageX;
122 NotifyImageX();
123 }
124
126
132 double ImageY() const noexcept
133 {
134 return imageY_;
135 }
136
138
144 void SetImageY(double imageY)
145 {
146 if (imageY_ == imageY)
147 return;
148
149 imageY_ = imageY;
150 NotifyImageY();
151 }
152
153 // needed put not for public use!
155 {
156 return view_;
157 }
158
160
169 {
170 if (view_ == view)
171 return;
172
173 view_ = view;
174 NotifyImageView();
175 }
176
178
188 int LabelScale() const noexcept
189 {
190 return static_cast<int>(labelScale_);
191 }
192
194
204 void SetLabelScale(int labelScale)
205 {
206 if (labelScale_ == static_cast<UI::LabelScale>(labelScale))
207 return;
208
209 labelScale_ = static_cast<UI::LabelScale>(labelScale);
210 NotifyLabelScale();
211 }
212
213
214
215
216 private Q_SLOTS:
217
218 void OnImageXChanged();
219
220 void OnImageYChanged();
221
222 void OnImageViewChanged();
223
224 void OnLabelScaleChanged();
225
226 Q_SIGNALS:
227
228 void NotifyImageX();
229 void NotifyImageY();
230 void NotifyImageView();
231 void NotifyLabelScale();
232
233 private:
234
235 void SetupConnections();
236
237 double imageX_ = 0.0;
238 double imageY_ = 0.0;
239
240 UI::LabelScale labelScale_ = UI::LabelScale::Off;
241
242 ImageViewItem* view_ = nullptr;
243};
244
246
253 : public QObject
254{
255 Q_OBJECT
256
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)
260
261 public:
262
264
269 {
270 std::unique_lock<std::mutex> guard(imageMutex_);
271 return image_;
272 }
273
275
281 void ReleaseRefreshShare() noexcept
282 {
283 std::unique_lock<std::mutex> guard(imageMutex_);
284 UnregisterEventImageDataUpdated();
285 image_.reset();
286 }
287
288
290
296 void Refresh(const ImagePtr & image, AutoRefresh autoRefresh = AutoRefresh::Off)
297 {
298 if (!image)
299 return;
300
301 std::unique_lock<std::mutex> guard(imageMutex_);
302 UnregisterEventImageDataUpdated();
303 image_ = image;
304
305 if (autoRefresh == AutoRefresh::On)
306 eventCookieDataUpdated_ = image_->RegisterEventPixelContentChanged([&](const class Image &, Rect<int>)
307 {
308 Refresh();
309 });
310
311 NotifyRefreshImage();
312 }
313
315
319 void Refresh()
320 {
321 if (!image_)
322 return;
323
324 std::unique_lock<std::mutex> guard(refreshMutex_);
325 NotifyRefresh();
326 }
327
329
337 int Width() const noexcept
338 {
339 if (!image_)
340 return 0;
341 return image_->Width();
342 }
343
345
353 int Height() const noexcept
354 {
355 if (!image_)
356 return 0;
357 return image_->Height();
358 }
359
361
369 int PlanesCount() const noexcept
370 {
371 if (!image_)
372 return 0;
373 return image_->PlanesCount();
374 }
375
376 private:
377
378 void UnregisterEventImageDataUpdated() noexcept
379 {
380 if (image_)
381 image_->UnregisterEventPixelContentChanged(eventCookieDataUpdated_);
382 }
383
384
385 EventCookie eventCookieDataUpdated_;
386
387 ImagePtr image_;
388
389 mutable std::mutex imageMutex_;
390 mutable std::mutex refreshMutex_;
391
392 Q_SIGNALS:
393
394 void NotifyRefresh();
395 void NotifyRefreshImage();
396};
397
398
400
409 : public QQuickPaintedItem
410
411{
412
413#pragma region
414
415 Q_OBJECT
416
417 Q_PROPERTY(QRectF imageRect READ ImageRect NOTIFY NotifyImageRect)
418 Q_PROPERTY(QRectF viewRect READ ViewRect NOTIFY NotifyViewRect)
419 Q_PROPERTY(QRectF sourceRect READ SourceRect NOTIFY NotifySourceRect)
420 Q_PROPERTY(QRectF targetRect READ TargetRect NOTIFY NotifyTargetRect)
421
422 Q_PROPERTY(QObject* image READ Image WRITE SetImage NOTIFY NotifyImage)
423
424 Q_PROPERTY(int zoomID READ ZoomID WRITE SetZoomID NOTIFY NotifyZoom)
425 Q_PROPERTY(double zoomFactor READ ZoomFactor WRITE SetZoomFactor NOTIFY NotifyZoom)
426
427 Q_PROPERTY(QPointF viewAnchor READ ViewAnchor WRITE SetViewAnchor NOTIFY NotifyViewAnchor)
428 Q_PROPERTY(QPointF imageAnchor READ ImageAnchor WRITE SetImageAnchor NOTIFY NotifyImageAnchor)
429
430 Q_PROPERTY(QVector<double> hoverPixel READ HoverPixel NOTIFY NotifyHover)
431 Q_PROPERTY(QPointF hoverPosition READ HoverPosition NOTIFY NotifyHover)
432
433 Q_PROPERTY(int uploadMode READ UploadMode WRITE SetUploadMode NOTIFY NotifyUploadMode)
434
435 public:
436
437
439
443 Q_INVOKABLE bool TryZoomIn()
444 {
445 auto result = dispatcher_->TryZoomIn([&]()
446 {
447 NotifyTargetRect();
448 },
449 [&]
450 {
451 NotifySourceRect();
452 });
453 update();
454 if (result)
455 {
456 NotifyZoom();
457 if (dispatcher_->UploadMode() == UI::UploadMode::Viewport)
458 Refresh();
459 }
460 return result;
461
462 }
463
465
469 Q_INVOKABLE bool TryZoomOut()
470 {
471 auto result = dispatcher_->TryZoomOut([&]()
472 {
473 NotifyTargetRect();
474 },
475 [&]
476 {
477 NotifySourceRect();
478 });
479 update();
480 if (result)
481 {
482 NotifyZoom();
483
484 if (dispatcher_->UploadMode() == UI::UploadMode::Viewport)
485 Refresh();
486 }
487 return result;
488
489 }
490
492
497 Q_INVOKABLE bool TryTranslate(const QPointF &translation)
498 {
499 auto result = dispatcher_->TryTranslate(QtToCvb(translation), [&]()
500 {
501 NotifySourceRect();
502 });
503 if (dispatcher_->UploadMode() == UI::UploadMode::Viewport)
504 Refresh();
505 else
506 update();
507 return result;
508 }
509
510
512
517 Q_INVOKABLE QPointF MapViewToTarget(const QPointF& viewPoint) const
518 {
519 return CvbToQt(dispatcher_->MapViewToTarget(QtToCvb(viewPoint)));
520 }
521
523
528 Q_INVOKABLE QPointF MapTargetToSource(const QPointF& targetPoint) const
529 {
530 return CvbToQt(dispatcher_->MapTargetToSource(QtToCvb(targetPoint)));
531 }
532
534
539 Q_INVOKABLE QPointF MapSourceToImage(const QPointF& sourcePoint) const
540 {
541 return CvbToQt(dispatcher_->MapSourceToImage(QtToCvb(sourcePoint)));
542 }
543
545
550 Q_INVOKABLE QPointF MapTargetToView(const QPointF& targetPoint) const
551 {
552 return CvbToQt(dispatcher_->MapTargetToView(QtToCvb(targetPoint)));
553 }
554
556
561 Q_INVOKABLE QPointF MapSourceToTarget(const QPointF& sourcePoint) const
562 {
563 return CvbToQt(dispatcher_->MapSourceToTarget(QtToCvb(sourcePoint)));
564 }
565
567
572 Q_INVOKABLE QPointF MapImageToSource(const QPointF& imagePoint) const
573 {
574 return CvbToQt(dispatcher_->MapImageToSource(QtToCvb(imagePoint)));
575 }
576
578
583 Q_INVOKABLE QPointF MapViewToImage(const QPointF& viewPoint) const
584 {
585 return CvbToQt(dispatcher_->MapViewToImage(QtToCvb(viewPoint)));
586 }
587
588 public Q_SLOTS:
589
590
592
597 void Refresh()
598 {
599 if (!image_)
600 return;
601
602 auto image = image_->Image();
603 if (!image)
604 return;
605
606 dispatcher_->UploadImage(*image,
607 [&]()
608 {
609 NotifyImageRect();
610 });
611 update();
612 }
613
614
615#pragma endregion QML Interface
616
617
618#pragma region
619
620 public:
621
622 explicit ImageViewItem(QQuickItem *parent = nullptr)
624 {
625 dispatcher_.reset(new Private::ImageViewDispatcher([&]()
626 {
627 NotifyZoom();
628 }));
629
630
631 setClip(true);
632 setAcceptedMouseButtons(Qt::AllButtons);
634 connect(this, &ImageViewItem::NotifyImage, this, &ImageViewItem::Refresh);
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);
640 }
641
642 ~ImageViewItem() = default;
643
645
655 template<class T>
656 static void Register(const char *uri, int versionMajor, int versionMinor, const char *qmlName)
657 {
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");
661 }
662
664
670 static void Register()
671 {
672 Register<ImageViewItem>("CvbQuick", 1, 0, "ImageView");
673 }
674
675#pragma endregion CTor/DTor/Register
676
677#pragma region
678
679
681
687 QRectF ImageRect() const noexcept
688 {
689 return CvbToQt(dispatcher_->ImageRect());
690 }
691
692
694
700 QRectF ViewRect() const noexcept
701 {
702 return CvbToQt(dispatcher_->ViewRect());
703 }
704
706
712 QRectF TargetRect() const noexcept
713 {
714 return CvbToQt(dispatcher_->TargetRect());
715 }
716
717
719
725 QRectF SourceRect() const noexcept
726 {
727 return CvbToQt(dispatcher_->SourceRect());
728 }
729
730 // needed put not for public use!
731 QObject* Image() const
732 {
733 return image_;
734 }
735
736
738
746 int ZoomID() const
747 {
748 return static_cast<int>(dispatcher_->ZoomID());
749 }
750
752
760 void SetZoomID(int id)
761 {
762 dispatcher_->UpdateZoomID(static_cast<UI::ZoomID>(id),
763 [&]()
764 {
765 NotifyZoom();
766 });
767
768 }
769
771
777 double ZoomFactor() const
778 {
779 return dispatcher_->ZoomFactor();
780 }
781
783
789 void SetZoomFactor(double factor)
790 {
791 dispatcher_->UpdateZoomFactor(factor,
792 [&]()
793 {
794 NotifyZoom();
795 });
796 }
797
799
808 void SetImage(QObject* image)
809 {
810 if (!image)
811 return;
812
813
814 image_ = dynamic_cast<ImageController*>(image);
815 if (!image_)
816 return;
817 connect(image_, &ImageController::NotifyRefresh, this, &ImageViewItem::Refresh);
818 connect(image_, &ImageController::NotifyRefreshImage, this, &ImageViewItem::Refresh);
819 NotifyImage();
820 }
821
823
829 QPointF ViewAnchor() const noexcept
830 {
831 return CvbToQt(dispatcher_->ViewAnchor());
832 }
833
835
841 void SetViewAnchor(const QPointF & viewAnchor)
842 {
843 dispatcher_->UpdateViewAnchor(QtToCvb(viewAnchor),
844 [&]()
845 {
846 NotifyViewAnchor();
847 });
848 }
849
851
857 QPointF ImageAnchor() const noexcept
858 {
859 return CvbToQt(dispatcher_->ImageAnchor());
860 }
861
863
869 void SetImageAnchor(const QPointF & imageAnchor)
870 {
871 dispatcher_->UpdateImageAnchor(QtToCvb(imageAnchor),
872 [&]()
873 {
874 NotifyImageAnchor();
875 });
876 }
877
879
888 {
889 if (!image_)
890 return QVector<double>();
891
892 auto image = image_->Image();
893 if (!image || !dispatcher_->IsHoverPositionValid())
894 return QVector<double>();
895
896 auto hoverPosition = dispatcher_->HoverPosition();
897 Point2D<int> hoverPositionInt(static_cast<int>(std::floor(hoverPosition.X())),
898 static_cast<int>(std::floor(hoverPosition.Y())));
899 // here we can get image width/height as max so we filter it
900
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));
905
906 return QVector<double>::fromStdVector(image->GetPixel(hoverPositionInt));
907 }
908
909
911
917 QPointF HoverPosition() const noexcept
918 {
919 if (!dispatcher_->IsHoverPositionValid())
920 return QPointF();
921
922 return CvbToQt(dispatcher_->HoverPosition());
923 }
924
926
934 int UploadMode() const noexcept
935 {
936 return static_cast<int>(dispatcher_->UploadMode());
937
938 }
939
941
949 void SetUploadMode(int uploadMode)
950 {
951 dispatcher_->UpdateUploadMode(static_cast<UI::UploadMode>(uploadMode),
952 [&]()
953 {
954 NotifyUploadMode();
955 });
956 }
957
958#pragma endregion Properties
959
960#pragma region
961
962 private Q_SLOTS:
963
964
965
966
967 void OnViewRectChanged()
968 {
969 UpdateTargetSource();
970 }
971
972 void OnImageRectChanged()
973 {
974 UpdateTargetSource();
975 }
976
977 void OnZoomFactorChanged()
978 {
979 UpdateTargetSource();
980 update();
981 }
982
983
984 void OnZoomIDChanged()
985 {
986 UpdateTargetSource();
987 update();
988 }
989
990
991 void OnViewAnchorChnaged()
992 {
993 auto targetPoint = dispatcher_->MapViewToTarget(dispatcher_->ViewAnchor());
994 targetPoint = dispatcher_->LimitPointToRect(targetPoint, dispatcher_->TargetRect());
995
996 auto sourcePoint = dispatcher_->MapTargetToSource(targetPoint);
997 auto imagePoint = dispatcher_->MapSourceToImage(sourcePoint);
998
999 dispatcher_->UpdateImageAnchor(imagePoint,
1000 [&]()
1001 {
1002 NotifyImageAnchor();
1003 });
1004 }
1005
1006
1007
1008
1009#pragma endregion Slots
1010
1011#pragma region
1012
1013 private:
1014
1015
1016 void UpdateTargetSource()
1017 {
1018 dispatcher_->UpdateTargetSource(
1019 [&]()
1020 {
1021 NotifyTargetRect();
1022 },
1023 [&]()
1024 {
1025 NotifySourceRect();
1026 });
1027 }
1028
1029 QImage ScreenImage() const noexcept
1030 {
1031 auto data = dispatcher_->Buffer();
1032 auto size = dispatcher_->BufferSize();
1033
1034 return QImage(data, size.Width(), size.Height(), QImage::Format_ARGB32_Premultiplied);
1035 }
1036
1037
1038#pragma endregion Helper
1039
1040
1041#pragma region
1042
1043
1044
1045 void paint(QPainter *painter) override
1046 {
1047
1048
1049 Private::ImageViewDispatcherGuard guard(*dispatcher_);
1050 if (!dispatcher_->IsBufferValid())
1051 return;
1052
1053 auto screenImage = ScreenImage();
1054
1055 if (dispatcher_->UploadMode() == UI::UploadMode::Image)
1056 {
1057
1058
1059
1060 painter->drawImage(CvbToQt(dispatcher_->TargetRect()),
1061 screenImage,
1062 CvbToQt(dispatcher_->SourceRect()));
1063 }
1064 else
1065 {
1066 auto image = image_->Image();
1067 if (!image)
1068 return;
1069
1070
1071
1072
1073
1074
1075
1076 painter->drawImage(CvbToQt(dispatcher_->TargetRect()),
1077 screenImage,
1078 CvbToQt(dispatcher_->SourceRectAdj()));
1079 }
1080 }
1081
1082 void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) override
1083 {
1084 auto tmpNewGemotry = QtToCvb(newGeometry);
1085 if (tmpNewGemotry != dispatcher_->ViewRect())
1086 dispatcher_->UpdateViewRect(tmpNewGemotry, [&]() { NotifyViewRect(); });
1087
1088
1089
1090 QQuickPaintedItem::geometryChanged(newGeometry, oldGeometry);
1091
1092 if (dispatcher_->UploadMode() == UI::UploadMode::Viewport
1093 && image_)
1094 Refresh();
1095 }
1096
1097 void wheelEvent(QWheelEvent *event) override
1098 {
1099 SetViewAnchor(mapFromGlobal(event->globalPosF()));
1100 auto numDegrees = event->angleDelta().y();
1101
1102 if (numDegrees <= -15)
1103 TryZoomOut();
1104 else if (numDegrees >= 15)
1105 TryZoomIn();
1106 }
1107
1108 void mouseMoveEvent(QMouseEvent *event) override
1109 {
1110 if (event->buttons() & Qt::LeftButton)
1111 {
1112 auto currentPos = QtToCvb(mapFromGlobal(event->globalPos()));
1113 if (!dispatcher_->IsLastMousePositionValid())
1114 {
1115 dispatcher_->InvalidateLastMousePosition(currentPos);
1116 return;
1117 }
1118
1119 TryTranslate(CvbToQt(currentPos - dispatcher_->LastMousePosition()));
1120 dispatcher_->InvalidateLastMousePosition(currentPos);
1121 }
1122
1123 }
1124
1125 void mouseReleaseEvent(QMouseEvent *) override
1126 {
1127 dispatcher_->InvalidateLastMousePosition();
1128 }
1129
1130 void mousePressEvent(QMouseEvent *) override
1131 {
1132 // do nothing just prevent the default implementation from ignoring the event
1133 }
1134
1135
1136 void hoverMoveEvent(QHoverEvent *event) override
1137 {
1138 auto hoverPosition = dispatcher_->MapViewToImage(QtToCvb(event->posF()));
1139 if (!dispatcher_->ImageRect().Contains(hoverPosition))
1140 return;
1141
1142 dispatcher_->UpdateHoverPosition(hoverPosition,
1143 [&]()
1144 {
1145 NotifyHover();
1146 });
1147 }
1148
1149
1150
1151
1152#pragma endregion Reimplemented from Qt
1153
1154
1155#pragma region
1156
1158
1159 ImageController* image_ = nullptr;
1160
1161
1162
1163#pragma endregion Members
1164
1165#pragma region
1166
1167 Q_SIGNALS:
1168
1169 void NotifyImageRect();
1170 void NotifyViewRect();
1171 void NotifySourceRect();
1172 void NotifyTargetRect();
1173
1174 void NotifyImage();
1175
1176 void NotifyZoom();
1177
1178 void NotifyViewAnchor();
1179 void NotifyImageAnchor();
1180
1181 void NotifyHover();
1182
1183
1184 void NotifyUploadMode();
1185
1186#pragma endregion Notify
1187
1188};
1189
1190inline ImageLabelItem::ImageLabelItem(QQuickItem *parent)
1191 : QQuickItem(parent)
1192{
1193 setTransformOrigin(QQuickItem::TopLeft);
1194 connect(this, &ImageLabelItem::NotifyImageView, this, &ImageLabelItem::OnImageViewChanged);
1195}
1196
1197
1198inline void ImageLabelItem::OnImageXChanged()
1199{
1200 if (!view_)
1201 return;
1202
1203 auto sourceRect = view_->SourceRect();
1204 auto sourceX = imageX_ - sourceRect.x();
1205 auto targetX = sourceX * view_->ZoomFactor();
1206 auto targetRect = view_->TargetRect();
1207 auto viewX = targetX + targetRect.x();
1208
1209 setX(viewX);
1210}
1211
1212inline void ImageLabelItem::OnImageYChanged()
1213{
1214 if (!view_)
1215 return;
1216
1217 auto sourceRect = view_->SourceRect();
1218 auto sourceY = imageY_ - sourceRect.y();
1219 auto targetY = sourceY * view_->ZoomFactor();
1220 auto targetRect = view_->TargetRect();
1221 auto viewY = targetY + targetRect.y();
1222
1223 setY(viewY);
1224}
1225
1226inline void ImageLabelItem::OnImageViewChanged()
1227{
1228 SetupConnections();
1229 OnImageXChanged();
1230 OnImageYChanged();
1231 OnLabelScaleChanged();
1232}
1233
1234inline void ImageLabelItem::OnLabelScaleChanged()
1235{
1236 if (labelScale_ == UI::LabelScale::Off)
1237 {
1238 setScale(1.0);
1239 return;
1240 }
1241
1242 if (!view_)
1243 return;
1244
1245 setScale(view_->ZoomFactor());
1246
1247}
1248
1249
1250inline void ImageLabelItem::SetupConnections()
1251{
1252 if (!view_)
1253 return;
1254
1255 connect(this, &ImageLabelItem::NotifyImageX, this, &ImageLabelItem::OnImageXChanged);
1256 connect(this, &ImageLabelItem::NotifyImageY, this, &ImageLabelItem::OnImageYChanged);
1257 connect(this, &ImageLabelItem::NotifyLabelScale, this, &ImageLabelItem::OnLabelScaleChanged);
1258
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);
1265
1266 connect(view_, &ImageViewItem::NotifyZoom, this, &ImageLabelItem::OnLabelScaleChanged);
1267}
1268
1269}
1270
1271using ImageLabelItem = Quick::ImageLabelItem;
1272using ImageController = Quick::ImageController;
1273using ImageViewItem = Quick::ImageViewItem;
1274
1275
1276
1277}
1278
1279
1280
1281
1282CVB_END_INLINE_NS
1283
1284}
Image rectangle operations on a device.
Definition: decl_image_rect.hpp:18
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)
void setClip(bool)
virtual bool event(QEvent *ev) override
virtual void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry)
QPointF mapFromGlobal(const QPointF &point) const const
void setScale(qreal)
void setAcceptHoverEvents(bool enabled)
void setAcceptedMouseButtons(Qt::MouseButtons buttons)
QSizeF size() const const
void setTransformOrigin(QQuickItem::TransformOrigin)
void update()
void setX(qreal)
void setY(qreal)
qreal x() const const
qreal y() const const
QVector< T > fromStdVector(const std::vector< T > &vector)