CVB++ 15.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
61 explicit ImageLabelItem(QQuickItem *parent = nullptr);
62
63
65
75 template<class T>
76 static void Register(const char *uri, int versionMajor, int versionMinor, const char *qmlName)
77 {
78 qmlRegisterType<T>(uri, versionMajor, versionMinor, qmlName);
79 qmlRegisterUncreatableMetaObject(Cvb::UI::staticMetaObject, uri, versionMajor, versionMinor, "LabelScale", "CVB: cannot object for enumerations");
80 }
81
82
84
90 static void Register()
91 {
92 Register<ImageLabelItem>("CvbQuick", 1, 0, "ImageLabel");
93 }
94
96
102 double ImageX() const noexcept
103 {
104 return imageX_;
105 }
106
108
114 void SetImageX(double imageX)
115 {
116 if (imageX_ == imageX)
117 return;
118
119 imageX_ = imageX;
120 NotifyImageX();
121 }
122
124
130 double ImageY() const noexcept
131 {
132 return imageY_;
133 }
134
136
142 void SetImageY(double imageY)
143 {
144 if (imageY_ == imageY)
145 return;
146
147 imageY_ = imageY;
148 NotifyImageY();
149 }
150
151 // needed put not for public use!
153 {
154 return view_;
155 }
156
158
167 {
168 if (view_ == view)
169 return;
170
171 view_ = view;
172 NotifyImageView();
173 }
174
176
186 int LabelScale() const noexcept
187 {
188 return static_cast<int>(labelScale_);
189 }
190
192
202 void SetLabelScale(int labelScale)
203 {
204 if (labelScale_ == static_cast<UI::LabelScale>(labelScale))
205 return;
206
207 labelScale_ = static_cast<UI::LabelScale>(labelScale);
208 NotifyLabelScale();
209 }
210
211
212
213
214 private Q_SLOTS:
215
216 void OnImageXChanged();
217
218 void OnImageYChanged();
219
220 void OnImageViewChanged();
221
222 void OnLabelScaleChanged();
223
224 Q_SIGNALS:
225
226 void NotifyImageX();
227 void NotifyImageY();
228 void NotifyImageView();
229 void NotifyLabelScale();
230
231 private:
232
233 void SetupConnections();
234
235 double imageX_ = 0.0;
236 double imageY_ = 0.0;
237
238 UI::LabelScale labelScale_ = UI::LabelScale::Off;
239
240 ImageViewItem* view_ = nullptr;
241};
242
244
251 : public QObject
252{
253 Q_OBJECT
254
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)
258
259 public:
260
262
267 {
268 std::unique_lock<std::mutex> guard(imageMutex_);
269 return image_;
270 }
271
273
279 void ReleaseRefreshShare() noexcept
280 {
281 std::unique_lock<std::mutex> guard(imageMutex_);
282 UnregisterEventImageDataUpdated();
283 image_.reset();
284 }
285
286
288
294 void Refresh(const ImagePtr & image, AutoRefresh autoRefresh = AutoRefresh::Off)
295 {
296 if (!image)
297 return;
298
299 {
300 std::unique_lock<std::mutex> guard(imageMutex_);
301 UnregisterEventImageDataUpdated();
302 image_ = image;
303
304 if (autoRefresh == AutoRefresh::On)
305 eventCookieDataUpdated_ =
306 image_->RegisterEventPixelContentChanged([&](const class Image &, Rect<int>) { Refresh(); });
307 }
308
309 NotifyRefreshImage();
310 }
311
313
317 void Refresh()
318 {
319 if (!image_)
320 return;
321
322 std::unique_lock<std::mutex> guard(refreshMutex_);
323 NotifyRefresh();
324 }
325
327
335 int Width() const noexcept
336 {
337 if (!image_)
338 return 0;
339 return image_->Width();
340 }
341
343
351 int Height() const noexcept
352 {
353 if (!image_)
354 return 0;
355 return image_->Height();
356 }
357
359
367 int PlanesCount() const noexcept
368 {
369 if (!image_)
370 return 0;
371 return image_->PlanesCount();
372 }
373
374 private:
375
376 void UnregisterEventImageDataUpdated() noexcept
377 {
378 if (image_)
379 image_->UnregisterEventPixelContentChanged(eventCookieDataUpdated_);
380 }
381
382
383 EventCookie eventCookieDataUpdated_;
384
385 ImagePtr image_;
386
387 mutable std::mutex imageMutex_;
388 mutable std::mutex refreshMutex_;
389
390 Q_SIGNALS:
391
392 void NotifyRefresh();
393 void NotifyRefreshImage();
394};
395
396
398
407 : public QQuickPaintedItem
408
409{
410
411#pragma region
412
413 Q_OBJECT
414
415 Q_PROPERTY(QRectF imageRect READ ImageRect NOTIFY NotifyImageRect)
416 Q_PROPERTY(QRectF viewRect READ ViewRect NOTIFY NotifyViewRect)
417 Q_PROPERTY(QRectF sourceRect READ SourceRect NOTIFY NotifySourceRect)
418 Q_PROPERTY(QRectF targetRect READ TargetRect NOTIFY NotifyTargetRect)
419
420 Q_PROPERTY(QObject* image READ Image WRITE SetImage NOTIFY NotifyImage)
421
422 Q_PROPERTY(int zoomID READ ZoomID WRITE SetZoomID NOTIFY NotifyZoom)
423 Q_PROPERTY(double zoomFactor READ ZoomFactor WRITE SetZoomFactor NOTIFY NotifyZoom)
424
425 Q_PROPERTY(QPointF viewAnchor READ ViewAnchor WRITE SetViewAnchor NOTIFY NotifyViewAnchor)
426 Q_PROPERTY(QPointF imageAnchor READ ImageAnchor WRITE SetImageAnchor NOTIFY NotifyImageAnchor)
427
428 Q_PROPERTY(QVector<double> hoverPixel READ HoverPixel NOTIFY NotifyHover)
429 Q_PROPERTY(QPointF hoverPosition READ HoverPosition NOTIFY NotifyHover)
430
431 Q_PROPERTY(int uploadMode READ UploadMode WRITE SetUploadMode NOTIFY NotifyUploadMode)
432
433 public:
434
435
437
441 Q_INVOKABLE bool TryZoomIn()
442 {
443 auto result = dispatcher_->TryZoomIn([&]()
444 {
445 NotifyTargetRect();
446 },
447 [&]
448 {
449 NotifySourceRect();
450 });
451 update();
452 if (result)
453 {
454 NotifyZoom();
455 if (dispatcher_->UploadMode() == UI::UploadMode::Viewport)
456 Refresh();
457 }
458 return result;
459
460 }
461
463
467 Q_INVOKABLE bool TryZoomOut()
468 {
469 auto result = dispatcher_->TryZoomOut([&]()
470 {
471 NotifyTargetRect();
472 },
473 [&]
474 {
475 NotifySourceRect();
476 });
477 update();
478 if (result)
479 {
480 NotifyZoom();
481
482 if (dispatcher_->UploadMode() == UI::UploadMode::Viewport)
483 Refresh();
484 }
485 return result;
486
487 }
488
490
495 Q_INVOKABLE bool TryTranslate(const QPointF &translation)
496 {
497 auto result = dispatcher_->TryTranslate(QtToCvb(translation), [&]()
498 {
499 NotifySourceRect();
500 });
501 if (dispatcher_->UploadMode() == UI::UploadMode::Viewport)
502 Refresh();
503 else
504 update();
505 return result;
506 }
507
508
510
515 Q_INVOKABLE QPointF MapViewToTarget(const QPointF& viewPoint) const
516 {
517 return CvbToQt(dispatcher_->MapViewToTarget(QtToCvb(viewPoint)));
518 }
519
521
526 Q_INVOKABLE QPointF MapTargetToSource(const QPointF& targetPoint) const
527 {
528 return CvbToQt(dispatcher_->MapTargetToSource(QtToCvb(targetPoint)));
529 }
530
532
537 Q_INVOKABLE QPointF MapSourceToImage(const QPointF& sourcePoint) const
538 {
539 return CvbToQt(dispatcher_->MapSourceToImage(QtToCvb(sourcePoint)));
540 }
541
543
548 Q_INVOKABLE QPointF MapTargetToView(const QPointF& targetPoint) const
549 {
550 return CvbToQt(dispatcher_->MapTargetToView(QtToCvb(targetPoint)));
551 }
552
554
559 Q_INVOKABLE QPointF MapSourceToTarget(const QPointF& sourcePoint) const
560 {
561 return CvbToQt(dispatcher_->MapSourceToTarget(QtToCvb(sourcePoint)));
562 }
563
565
570 Q_INVOKABLE QPointF MapImageToSource(const QPointF& imagePoint) const
571 {
572 return CvbToQt(dispatcher_->MapImageToSource(QtToCvb(imagePoint)));
573 }
574
576
581 Q_INVOKABLE QPointF MapViewToImage(const QPointF& viewPoint) const
582 {
583 return CvbToQt(dispatcher_->MapViewToImage(QtToCvb(viewPoint)));
584 }
585
586 public Q_SLOTS:
587
588
590
595 void Refresh()
596 {
597 if (!image_)
598 return;
599
600 auto image = image_->Image();
601 if (!image)
602 return;
603
604 dispatcher_->UploadImage(*image,
605 [&]()
606 {
607 NotifyImageRect();
608 });
609 update();
610 }
611
612
613#pragma endregion QML Interface
614
615
616#pragma region
617
618 public:
619
620 explicit ImageViewItem(QQuickItem *parent = nullptr)
622 {
623 dispatcher_ = std::make_unique<Private::ImageViewDispatcher>([&]()
624 {
625 NotifyZoom();
626 });
627
628
629 setClip(true);
630 setAcceptedMouseButtons(Qt::AllButtons);
632 connect(this, &ImageViewItem::NotifyImage, this, &ImageViewItem::Refresh);
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);
638 }
639
640
642
652 template<class T>
653 static void Register(const char *uri, int versionMajor, int versionMinor, const char *qmlName)
654 {
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");
658 }
659
661
667 static void Register()
668 {
669 Register<ImageViewItem>("CvbQuick", 1, 0, "ImageView");
670 }
671
672#pragma endregion CTor/DTor/Register
673
674#pragma region
675
676
678
684 QRectF ImageRect() const noexcept
685 {
686 return CvbToQt(dispatcher_->ImageRect());
687 }
688
689
691
697 QRectF ViewRect() const noexcept
698 {
699 return CvbToQt(dispatcher_->ViewRect());
700 }
701
703
709 QRectF TargetRect() const noexcept
710 {
711 return CvbToQt(dispatcher_->TargetRect());
712 }
713
714
716
722 QRectF SourceRect() const noexcept
723 {
724 return CvbToQt(dispatcher_->SourceRect());
725 }
726
727 // needed put not for public use!
728 QObject* Image() const
729 {
730 return image_;
731 }
732
733
735
743 int ZoomID() const
744 {
745 return static_cast<int>(dispatcher_->ZoomID());
746 }
747
749
757 void SetZoomID(int id)
758 {
759 dispatcher_->UpdateZoomID(static_cast<UI::ZoomID>(id),
760 [&]()
761 {
762 NotifyZoom();
763 });
764
765 }
766
768
774 double ZoomFactor() const
775 {
776 return dispatcher_->ZoomFactor();
777 }
778
780
786 void SetZoomFactor(double factor)
787 {
788 dispatcher_->UpdateZoomFactor(factor,
789 [&]()
790 {
791 NotifyZoom();
792 });
793 }
794
796
805 void SetImage(QObject* image)
806 {
807 if (!image)
808 return;
809
810
811 image_ = dynamic_cast<ImageController*>(image);
812 if (!image_)
813 return;
814 connect(image_, &ImageController::NotifyRefresh, this, &ImageViewItem::Refresh);
815 connect(image_, &ImageController::NotifyRefreshImage, this, &ImageViewItem::Refresh);
816 NotifyImage();
817 }
818
820
826 QPointF ViewAnchor() const noexcept
827 {
828 return CvbToQt(dispatcher_->ViewAnchor());
829 }
830
832
838 void SetViewAnchor(const QPointF & viewAnchor)
839 {
840 dispatcher_->UpdateViewAnchor(QtToCvb(viewAnchor),
841 [&]()
842 {
843 NotifyViewAnchor();
844 });
845 }
846
848
854 QPointF ImageAnchor() const noexcept
855 {
856 return CvbToQt(dispatcher_->ImageAnchor());
857 }
858
860
866 void SetImageAnchor(const QPointF & imageAnchor)
867 {
868 dispatcher_->UpdateImageAnchor(QtToCvb(imageAnchor),
869 [&]()
870 {
871 NotifyImageAnchor();
872 });
873 }
874
876
885 {
886 if (!image_)
887 return QVector<double>();
888
889 auto image = image_->Image();
890 if (!image || !dispatcher_->IsHoverPositionValid())
891 return QVector<double>();
892
893 auto hoverPosition = dispatcher_->HoverPosition();
894 Point2D<int> hoverPositionInt(static_cast<int>(std::floor(hoverPosition.X())),
895 static_cast<int>(std::floor(hoverPosition.Y())));
896 // here we can get image width/height as max so we filter it
897
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));
902
903 return QVector<double>::fromStdVector(image->GetPixel(hoverPositionInt));
904 }
905
906
908
914 QPointF HoverPosition() const noexcept
915 {
916 if (!dispatcher_->IsHoverPositionValid())
917 return QPointF();
918
919 return CvbToQt(dispatcher_->HoverPosition());
920 }
921
923
931 int UploadMode() const noexcept
932 {
933 return static_cast<int>(dispatcher_->UploadMode());
934
935 }
936
938
946 void SetUploadMode(int uploadMode)
947 {
948 dispatcher_->UpdateUploadMode(static_cast<UI::UploadMode>(uploadMode),
949 [&]()
950 {
951 NotifyUploadMode();
952 });
953 }
954
955#pragma endregion Properties
956
957#pragma region
958
959 private Q_SLOTS:
960
961
962
963
964 void OnViewRectChanged()
965 {
966 UpdateTargetSource();
967 }
968
969 void OnImageRectChanged()
970 {
971 UpdateTargetSource();
972 }
973
974 void OnZoomFactorChanged()
975 {
976 UpdateTargetSource();
977 update();
978 }
979
980
981 void OnZoomIDChanged()
982 {
983 UpdateTargetSource();
984 update();
985 }
986
987
988 void OnViewAnchorChnaged()
989 {
990 auto targetPoint = dispatcher_->MapViewToTarget(dispatcher_->ViewAnchor());
991 targetPoint = dispatcher_->LimitPointToRect(targetPoint, dispatcher_->TargetRect());
992
993 auto sourcePoint = dispatcher_->MapTargetToSource(targetPoint);
994 auto imagePoint = dispatcher_->MapSourceToImage(sourcePoint);
995
996 dispatcher_->UpdateImageAnchor(imagePoint,
997 [&]()
998 {
999 NotifyImageAnchor();
1000 });
1001 }
1002
1003
1004
1005
1006#pragma endregion Slots
1007
1008#pragma region
1009
1010 private:
1011
1012
1013 void UpdateTargetSource()
1014 {
1015 dispatcher_->UpdateTargetSource(
1016 [&]()
1017 {
1018 NotifyTargetRect();
1019 },
1020 [&]()
1021 {
1022 NotifySourceRect();
1023 });
1024 }
1025
1026 QImage ScreenImage() const noexcept
1027 {
1028 auto data = dispatcher_->Buffer();
1029 auto size = dispatcher_->BufferSize();
1030
1031 return QImage(data, size.Width(), size.Height(), QImage::Format_ARGB32_Premultiplied);
1032 }
1033
1034
1035#pragma endregion Helper
1036
1037
1038#pragma region
1039
1040
1041
1042 void paint(QPainter *painter) override
1043 {
1044
1045
1046 Private::ImageViewDispatcherGuard guard(*dispatcher_);
1047 if (!dispatcher_->IsBufferValid())
1048 return;
1049
1050 auto screenImage = ScreenImage();
1051
1052 if (dispatcher_->UploadMode() == UI::UploadMode::Image)
1053 {
1054
1055
1056
1057 painter->drawImage(CvbToQt(dispatcher_->TargetRect()),
1058 screenImage,
1059 CvbToQt(dispatcher_->SourceRect()));
1060 }
1061 else
1062 {
1063 auto image = image_->Image();
1064 if (!image)
1065 return;
1066
1067
1068
1069
1070
1071
1072
1073 painter->drawImage(CvbToQt(dispatcher_->TargetRect()),
1074 screenImage,
1075 CvbToQt(dispatcher_->SourceRectAdj()));
1076 }
1077 }
1078
1079 void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) override
1080 {
1081 auto tmpNewGemotry = QtToCvb(newGeometry);
1082 if (tmpNewGemotry != dispatcher_->ViewRect())
1083 dispatcher_->UpdateViewRect(tmpNewGemotry, [&]() { NotifyViewRect(); });
1084
1085
1086
1087 QQuickPaintedItem::geometryChanged(newGeometry, oldGeometry);
1088
1089 if (dispatcher_->UploadMode() == UI::UploadMode::Viewport
1090 && image_)
1091 Refresh();
1092 }
1093
1094 void wheelEvent(QWheelEvent *event) override
1095 {
1096 SetViewAnchor(mapFromGlobal(event->globalPosF()));
1097 auto numDegrees = event->angleDelta().y();
1098
1099 if (numDegrees <= -15)
1100 TryZoomOut();
1101 else if (numDegrees >= 15)
1102 TryZoomIn();
1103 }
1104
1105 void mouseMoveEvent(QMouseEvent *event) override
1106 {
1107 if (event->buttons() & Qt::LeftButton)
1108 {
1109 auto currentPos = QtToCvb(mapFromGlobal(event->globalPos()));
1110 if (!dispatcher_->IsLastMousePositionValid())
1111 {
1112 dispatcher_->InvalidateLastMousePosition(currentPos);
1113 return;
1114 }
1115
1116 TryTranslate(CvbToQt(currentPos - dispatcher_->LastMousePosition()));
1117 dispatcher_->InvalidateLastMousePosition(currentPos);
1118 }
1119
1120 }
1121
1122 void mouseReleaseEvent(QMouseEvent *) override
1123 {
1124 dispatcher_->InvalidateLastMousePosition();
1125 }
1126
1127 void mousePressEvent(QMouseEvent *) override
1128 {
1129 // do nothing just prevent the default implementation from ignoring the event
1130 }
1131
1132
1133 void hoverMoveEvent(QHoverEvent *event) override
1134 {
1135 auto hoverPosition = dispatcher_->MapViewToImage(QtToCvb(event->posF()));
1136 if (!dispatcher_->ImageRect().Contains(hoverPosition))
1137 return;
1138
1139 dispatcher_->UpdateHoverPosition(hoverPosition,
1140 [&]()
1141 {
1142 NotifyHover();
1143 });
1144 }
1145
1146
1147
1148
1149#pragma endregion Reimplemented from Qt
1150
1151
1152#pragma region
1153
1155
1156 ImageController* image_ = nullptr;
1157
1158
1159
1160#pragma endregion Members
1161
1162#pragma region
1163
1164 Q_SIGNALS:
1165
1166 void NotifyImageRect();
1167 void NotifyViewRect();
1168 void NotifySourceRect();
1169 void NotifyTargetRect();
1170
1171 void NotifyImage();
1172
1173 void NotifyZoom();
1174
1175 void NotifyViewAnchor();
1176 void NotifyImageAnchor();
1177
1178 void NotifyHover();
1179
1180
1181 void NotifyUploadMode();
1182
1183#pragma endregion Notify
1184
1185};
1186
1187inline ImageLabelItem::ImageLabelItem(QQuickItem *parent)
1188 : QQuickItem(parent)
1189{
1190 setTransformOrigin(QQuickItem::TopLeft);
1191 connect(this, &ImageLabelItem::NotifyImageView, this, &ImageLabelItem::OnImageViewChanged);
1192}
1193
1194
1195inline void ImageLabelItem::OnImageXChanged()
1196{
1197 if (!view_)
1198 return;
1199
1200 auto sourceRect = view_->SourceRect();
1201 auto sourceX = imageX_ - sourceRect.x();
1202 auto targetX = sourceX * view_->ZoomFactor();
1203 auto targetRect = view_->TargetRect();
1204 auto viewX = targetX + targetRect.x();
1205
1206 setX(viewX);
1207}
1208
1209inline void ImageLabelItem::OnImageYChanged()
1210{
1211 if (!view_)
1212 return;
1213
1214 auto sourceRect = view_->SourceRect();
1215 auto sourceY = imageY_ - sourceRect.y();
1216 auto targetY = sourceY * view_->ZoomFactor();
1217 auto targetRect = view_->TargetRect();
1218 auto viewY = targetY + targetRect.y();
1219
1220 setY(viewY);
1221}
1222
1223inline void ImageLabelItem::OnImageViewChanged()
1224{
1225 SetupConnections();
1226 OnImageXChanged();
1227 OnImageYChanged();
1228 OnLabelScaleChanged();
1229}
1230
1231inline void ImageLabelItem::OnLabelScaleChanged()
1232{
1233 if (labelScale_ == UI::LabelScale::Off)
1234 {
1235 setScale(1.0);
1236 return;
1237 }
1238
1239 if (!view_)
1240 return;
1241
1242 setScale(view_->ZoomFactor());
1243
1244}
1245
1246
1247inline void ImageLabelItem::SetupConnections()
1248{
1249 if (!view_)
1250 return;
1251
1252 connect(this, &ImageLabelItem::NotifyImageX, this, &ImageLabelItem::OnImageXChanged);
1253 connect(this, &ImageLabelItem::NotifyImageY, this, &ImageLabelItem::OnImageYChanged);
1254 connect(this, &ImageLabelItem::NotifyLabelScale, this, &ImageLabelItem::OnLabelScaleChanged);
1255
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);
1262
1263 connect(view_, &ImageViewItem::NotifyZoom, this, &ImageLabelItem::OnLabelScaleChanged);
1264}
1265
1266}
1267
1268using ImageLabelItem = Quick::ImageLabelItem;
1269using ImageController = Quick::ImageController;
1270using ImageViewItem = Quick::ImageViewItem;
1271
1272
1273
1274}
1275
1276
1277
1278
1279CVB_END_INLINE_NS
1280
1281}
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: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)
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)