CVB++ 15.1
Loading...
Searching...
No Matches
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#pragma warning(pop)
16
17#include "ui.hpp"
18#include "../image.hpp"
19
20namespace Cvb
21{
22
23 CVB_BEGIN_INLINE_NS
24
25 namespace UI
26 {
27
29 namespace Quick
30 {
31
32 class ImageViewItem;
33
35
43 class ImageLabelItem : public QQuickItem
44 {
45 Q_OBJECT
46
47 Q_PROPERTY(double imageX MEMBER imageX_ READ ImageX WRITE SetImageX NOTIFY NotifyImageX);
48 Q_PROPERTY(double imageY MEMBER imageY_ READ ImageY WRITE SetImageY NOTIFY NotifyImageY);
49
50 Q_PROPERTY(int labelScale MEMBER labelScale_ READ LabelScale WRITE SetLabelScale NOTIFY NotifyLabelScale);
51
52 Q_PROPERTY(ImageViewItem *imageView READ ImageView WRITE SetImageView NOTIFY NotifyImageView)
53
54 public:
55 explicit ImageLabelItem(QQuickItem *parent = nullptr);
56
58
68 template <class T>
69 static void Register(const char *uri, int versionMajor, int versionMinor, const char *qmlName)
70 {
71 qmlRegisterType<T>(uri, versionMajor, versionMinor, qmlName);
72 qmlRegisterUncreatableMetaObject(Cvb::UI::staticMetaObject, uri, versionMajor, versionMinor, "LabelScale",
73 "CVB: cannot object for enumerations");
74 }
75
77
83 static void Register()
84 {
85 Register<ImageLabelItem>("CvbQuick", 1, 0, "ImageLabel");
86 }
87
89
95 double ImageX() const noexcept
96 {
97 return imageX_;
98 }
99
101
107 void SetImageX(double imageX)
108 {
109 if (imageX_ == imageX)
110 return;
111
112 imageX_ = imageX;
113 NotifyImageX();
114 }
115
117
123 double ImageY() const noexcept
124 {
125 return imageY_;
126 }
127
129
135 void SetImageY(double imageY)
136 {
137 if (imageY_ == imageY)
138 return;
139
140 imageY_ = imageY;
141 NotifyImageY();
142 }
143
144 // needed put not for public use!
146 {
147 return view_;
148 }
149
151
160 {
161 if (view_ == view)
162 return;
163
164 view_ = view;
165 NotifyImageView();
166 }
167
169
179 int LabelScale() const noexcept
180 {
181 return static_cast<int>(labelScale_);
182 }
183
185
195 void SetLabelScale(int labelScale)
196 {
197 if (labelScale_ == static_cast<UI::LabelScale>(labelScale))
198 return;
199
200 labelScale_ = static_cast<UI::LabelScale>(labelScale);
201 NotifyLabelScale();
202 }
203
204 private Q_SLOTS:
205
206 void OnImageXChanged();
207
208 void OnImageYChanged();
209
210 void OnImageViewChanged();
211
212 void OnLabelScaleChanged();
213
214 Q_SIGNALS:
215
216 void NotifyImageX();
217 void NotifyImageY();
218 void NotifyImageView();
219 void NotifyLabelScale();
220
221 private:
222 void SetupConnections();
223
224 double imageX_ = 0.0;
225 double imageY_ = 0.0;
226
227 UI::LabelScale labelScale_ = UI::LabelScale::Off;
228
229 ImageViewItem *view_ = nullptr;
230 };
231
233
239 class ImageController : public QObject
240 {
241 Q_OBJECT
242
243 Q_PROPERTY(int width READ Width NOTIFY NotifyRefreshImage)
244 Q_PROPERTY(int height READ Height NOTIFY NotifyRefreshImage)
245 Q_PROPERTY(int planesCount READ PlanesCount NOTIFY NotifyRefreshImage)
246
247 public:
249
254 {
255 std::unique_lock<std::mutex> guard(imageMutex_);
256 return image_;
257 }
258
260
266 void ReleaseRefreshShare() noexcept
267 {
268 std::unique_lock<std::mutex> guard(imageMutex_);
269 UnregisterEventImageDataUpdated();
270 image_.reset();
271 }
272
274
280 void Refresh(const ImagePtr &image, AutoRefresh autoRefresh = AutoRefresh::Off)
281 {
282 if (!image)
283 return;
284
285 {
286 std::unique_lock<std::mutex> guard(imageMutex_);
287 UnregisterEventImageDataUpdated();
288 image_ = image;
289
290 if (autoRefresh == AutoRefresh::On)
291 eventCookieDataUpdated_ =
292 image_->RegisterEventPixelContentChanged([&](const class Image &, Rect<int>) { Refresh(); });
293 }
294
295 NotifyRefreshImage();
296 }
297
299
303 void Refresh()
304 {
305 if (!image_)
306 return;
307
308 std::unique_lock<std::mutex> guard(refreshMutex_);
309 NotifyRefresh();
310 }
311
313
321 int Width() const noexcept
322 {
323 if (!image_)
324 return 0;
325 return image_->Width();
326 }
327
329
337 int Height() const noexcept
338 {
339 if (!image_)
340 return 0;
341 return image_->Height();
342 }
343
345
353 int PlanesCount() const noexcept
354 {
355 if (!image_)
356 return 0;
357 return image_->PlanesCount();
358 }
359
360 private:
361 void UnregisterEventImageDataUpdated() noexcept
362 {
363 if (image_)
364 image_->UnregisterEventPixelContentChanged(eventCookieDataUpdated_);
365 }
366
367 EventCookie eventCookieDataUpdated_;
368
369 ImagePtr image_;
370
371 mutable std::mutex imageMutex_;
372 mutable std::mutex refreshMutex_;
373
374 Q_SIGNALS:
375
376 void NotifyRefresh();
377 void NotifyRefreshImage();
378 };
379
381
389 class ImageViewItem : public QQuickPaintedItem
390
391 {
392
393#pragma region
394
395 Q_OBJECT
396
397 Q_PROPERTY(QRectF imageRect READ ImageRect NOTIFY NotifyImageRect)
398 Q_PROPERTY(QRectF viewRect READ ViewRect NOTIFY NotifyViewRect)
399 Q_PROPERTY(QRectF sourceRect READ SourceRect NOTIFY NotifySourceRect)
400 Q_PROPERTY(QRectF targetRect READ TargetRect NOTIFY NotifyTargetRect)
401
402 Q_PROPERTY(QObject *image READ Image WRITE SetImage NOTIFY NotifyImage)
403
404 Q_PROPERTY(int zoomID READ ZoomID WRITE SetZoomID NOTIFY NotifyZoom)
405 Q_PROPERTY(double zoomFactor READ ZoomFactor WRITE SetZoomFactor NOTIFY NotifyZoom)
406
407 Q_PROPERTY(QPointF viewAnchor READ ViewAnchor WRITE SetViewAnchor NOTIFY NotifyViewAnchor)
408 Q_PROPERTY(QPointF imageAnchor READ ImageAnchor WRITE SetImageAnchor NOTIFY NotifyImageAnchor)
409
410 Q_PROPERTY(QVector<double> hoverPixel READ HoverPixel NOTIFY NotifyHover)
411 Q_PROPERTY(QPointF hoverPosition READ HoverPosition NOTIFY NotifyHover)
412
413 Q_PROPERTY(int uploadMode READ UploadMode WRITE SetUploadMode NOTIFY NotifyUploadMode)
414
415 public:
417
421 Q_INVOKABLE bool TryZoomIn()
422 {
423 auto result = dispatcher_->TryZoomIn([&]() { NotifyTargetRect(); }, [&] { NotifySourceRect(); });
424 update();
425 if (result)
426 {
427 NotifyZoom();
428 if (dispatcher_->UploadMode() == UI::UploadMode::Viewport)
429 Refresh();
430 }
431 return result;
432 }
433
435
439 Q_INVOKABLE bool TryZoomOut()
440 {
441 auto result = dispatcher_->TryZoomOut([&]() { NotifyTargetRect(); }, [&] { NotifySourceRect(); });
442 update();
443 if (result)
444 {
445 NotifyZoom();
446
447 if (dispatcher_->UploadMode() == UI::UploadMode::Viewport)
448 Refresh();
449 }
450 return result;
451 }
452
454
459 Q_INVOKABLE bool TryTranslate(const QPointF &translation)
460 {
461 auto result = dispatcher_->TryTranslate(QtToCvb(translation), [&]() { NotifySourceRect(); });
462 if (dispatcher_->UploadMode() == UI::UploadMode::Viewport)
463 Refresh();
464 else
465 update();
466 return result;
467 }
468
470
475 Q_INVOKABLE QPointF MapViewToTarget(const QPointF &viewPoint) const
476 {
477 return CvbToQt(dispatcher_->MapViewToTarget(QtToCvb(viewPoint)));
478 }
479
481
486 Q_INVOKABLE QPointF MapTargetToSource(const QPointF &targetPoint) const
487 {
488 return CvbToQt(dispatcher_->MapTargetToSource(QtToCvb(targetPoint)));
489 }
490
492
497 Q_INVOKABLE QPointF MapSourceToImage(const QPointF &sourcePoint) const
498 {
499 return CvbToQt(dispatcher_->MapSourceToImage(QtToCvb(sourcePoint)));
500 }
501
503
508 Q_INVOKABLE QPointF MapTargetToView(const QPointF &targetPoint) const
509 {
510 return CvbToQt(dispatcher_->MapTargetToView(QtToCvb(targetPoint)));
511 }
512
514
519 Q_INVOKABLE QPointF MapSourceToTarget(const QPointF &sourcePoint) const
520 {
521 return CvbToQt(dispatcher_->MapSourceToTarget(QtToCvb(sourcePoint)));
522 }
523
525
530 Q_INVOKABLE QPointF MapImageToSource(const QPointF &imagePoint) const
531 {
532 return CvbToQt(dispatcher_->MapImageToSource(QtToCvb(imagePoint)));
533 }
534
536
541 Q_INVOKABLE QPointF MapViewToImage(const QPointF &viewPoint) const
542 {
543 return CvbToQt(dispatcher_->MapViewToImage(QtToCvb(viewPoint)));
544 }
545
547
552 Q_INVOKABLE QPointF MapImageToView(const QPointF &imagePoint) const
553 {
554 return CvbToQt(dispatcher_->MapImageToView(QtToCvb(imagePoint)));
555 }
556
558
563 Q_INVOKABLE QPointF MapTargetToImage(const QPointF &targetPoint) const
564 {
565 return CvbToQt(dispatcher_->MapTargetToImage(QtToCvb(targetPoint)));
566 }
567
569
574 Q_INVOKABLE QPointF MapImageToTarget(const QPointF &imagePoint) const
575 {
576 return CvbToQt(dispatcher_->MapImageToTarget(QtToCvb(imagePoint)));
577 }
578
579 public Q_SLOTS:
580
582
587 void Refresh()
588 {
589 if (!image_)
590 return;
591
592 auto image = image_->Image();
593 if (!image)
594 return;
595
596 dispatcher_->UploadImage(*image, [&]() { NotifyImageRect(); });
597 update();
598 }
599
600#pragma endregion QML Interface
601
602#pragma region
603
604 public:
605 explicit ImageViewItem(QQuickItem *parent = nullptr)
606 : QQuickPaintedItem(parent)
607 {
608 dispatcher_ = std::make_unique<Private::ImageViewDispatcher>([&]() { NotifyZoom(); });
609
610 setClip(true);
611 setAcceptedMouseButtons(Qt::AllButtons);
612 setAcceptHoverEvents(true);
613 connect(this, &ImageViewItem::NotifyImage, this, &ImageViewItem::Refresh);
614 connect(this, &ImageViewItem::NotifyViewRect, this, &ImageViewItem::OnViewRectChanged);
615 connect(this, &ImageViewItem::NotifyImageRect, this, &ImageViewItem::OnImageRectChanged);
616 connect(this, &ImageViewItem::NotifyZoom, this, &ImageViewItem::OnZoomIDChanged);
617 connect(this, &ImageViewItem::NotifyZoom, this, &ImageViewItem::OnZoomFactorChanged);
618 connect(this, &ImageViewItem::NotifyViewAnchor, this, &ImageViewItem::OnViewAnchorChnaged);
619 }
620
622
632 template <class T>
633 static void Register(const char *uri, int versionMajor, int versionMinor, const char *qmlName)
634 {
635 qmlRegisterType<T>(uri, versionMajor, versionMinor, qmlName);
636 qmlRegisterUncreatableMetaObject(Cvb::UI::staticMetaObject, uri, versionMajor, versionMinor, "ZoomID",
637 "CVB: cannot object for enumerations");
638 qmlRegisterUncreatableMetaObject(Cvb::UI::staticMetaObject, uri, versionMajor, versionMinor, "UploadMode",
639 "CVB: cannot object for enumerations");
640 }
641
643
649 static void Register()
650 {
651 Register<ImageViewItem>("CvbQuick", 1, 0, "ImageView");
652 }
653
654#pragma endregion CTor / DTor / Register
655
656#pragma region
657
659
665 QRectF ImageRect() const noexcept
666 {
667 return CvbToQt(dispatcher_->ImageRect());
668 }
669
671
677 QRectF ViewRect() const noexcept
678 {
679 return CvbToQt(dispatcher_->ViewRect());
680 }
681
683
689 QRectF TargetRect() const noexcept
690 {
691 return CvbToQt(dispatcher_->TargetRect());
692 }
693
695
701 QRectF SourceRect() const noexcept
702 {
703 return CvbToQt(dispatcher_->SourceRect());
704 }
705
706 // needed put not for public use!
707 QObject *Image() const
708 {
709 return image_;
710 }
711
713
721 int ZoomID() const
722 {
723 return static_cast<int>(dispatcher_->ZoomID());
724 }
725
727
735 void SetZoomID(int id)
736 {
737 dispatcher_->UpdateZoomID(static_cast<UI::ZoomID>(id), [&]() { NotifyZoom(); });
738 }
739
741
747 double ZoomFactor() const
748 {
749 return dispatcher_->ZoomFactor();
750 }
751
753
759 void SetZoomFactor(double factor)
760 {
761 dispatcher_->UpdateZoomFactor(factor, [&]() { NotifyZoom(); });
762 }
763
765
774 void SetImage(QObject *image)
775 {
776 if (!image)
777 return;
778
779 image_ = dynamic_cast<ImageController *>(image);
780 if (!image_)
781 return;
782 connect(image_, &ImageController::NotifyRefresh, this, &ImageViewItem::Refresh);
783 connect(image_, &ImageController::NotifyRefreshImage, this, &ImageViewItem::Refresh);
784 NotifyImage();
785 }
786
788
794 QPointF ViewAnchor() const noexcept
795 {
796 return CvbToQt(dispatcher_->ViewAnchor());
797 }
798
800
806 void SetViewAnchor(const QPointF &viewAnchor)
807 {
808 dispatcher_->UpdateViewAnchor(QtToCvb(viewAnchor), [&]() { NotifyViewAnchor(); });
809 }
810
812
818 QPointF ImageAnchor() const noexcept
819 {
820 return CvbToQt(dispatcher_->ImageAnchor());
821 }
822
824
830 void SetImageAnchor(const QPointF &imageAnchor)
831 {
832 dispatcher_->UpdateImageAnchor(QtToCvb(imageAnchor), [&]() { NotifyImageAnchor(); });
833 }
834
836
844 QVector<double> HoverPixel() const
845 {
846 if (!image_)
847 return QVector<double>();
848
849 auto image = image_->Image();
850 if (!image || !dispatcher_->IsHoverPositionValid())
851 return QVector<double>();
852
853 auto hoverPosition = dispatcher_->HoverPosition();
854 Point2D<int> hoverPositionInt(static_cast<int>(std::floor(hoverPosition.X())),
855 static_cast<int>(std::floor(hoverPosition.Y())));
856 // here we can get image width/height as max so we filter it
857
858 if (hoverPositionInt.X() == image->Width())
859 hoverPositionInt.SetX(static_cast<int>(hoverPosition.X() - 1.0));
860 if (hoverPositionInt.Y() == image->Height())
861 hoverPositionInt.SetY(static_cast<int>(hoverPosition.Y() - 1.0));
862
863 const auto pixel = image->GetPixel(hoverPositionInt);
864 return QVector<double>(pixel.begin(), pixel.end());
865 }
866
868
874 QPointF HoverPosition() const noexcept
875 {
876 if (!dispatcher_->IsHoverPositionValid())
877 return QPointF();
878
879 return CvbToQt(dispatcher_->HoverPosition());
880 }
881
883
891 int UploadMode() const noexcept
892 {
893 return static_cast<int>(dispatcher_->UploadMode());
894 }
895
897
905 void SetUploadMode(int uploadMode)
906 {
907 dispatcher_->UpdateUploadMode(static_cast<UI::UploadMode>(uploadMode), [&]() { NotifyUploadMode(); });
908 }
909
910#pragma endregion Properties
911
912#pragma region
913
914 private Q_SLOTS:
915
916 void OnViewRectChanged()
917 {
918 UpdateTargetSource();
919 }
920
921 void OnImageRectChanged()
922 {
923 UpdateTargetSource();
924 }
925
926 void OnZoomFactorChanged()
927 {
928 UpdateTargetSource();
929 update();
930 }
931
932 void OnZoomIDChanged()
933 {
934 UpdateTargetSource();
935 update();
936 }
937
938 void OnViewAnchorChnaged()
939 {
940 auto targetPoint = dispatcher_->MapViewToTarget(dispatcher_->ViewAnchor());
941 targetPoint = dispatcher_->LimitPointToRect(targetPoint, dispatcher_->TargetRect());
942
943 auto sourcePoint = dispatcher_->MapTargetToSource(targetPoint);
944 auto imagePoint = dispatcher_->MapSourceToImage(sourcePoint);
945
946 dispatcher_->UpdateImageAnchor(imagePoint, [&]() { NotifyImageAnchor(); });
947 }
948
949#pragma endregion Slots
950
951#pragma region
952
953 private:
954 void UpdateTargetSource()
955 {
956 dispatcher_->UpdateTargetSource([&]() { NotifyTargetRect(); }, [&]() { NotifySourceRect(); });
957 }
958
959 QImage ScreenImage() const noexcept
960 {
961 auto data = dispatcher_->Buffer();
962 auto size = dispatcher_->BufferSize();
963
964 return QImage(data, size.Width(), size.Height(), QImage::Format_ARGB32_Premultiplied);
965 }
966
967#pragma endregion Helper
968
969#pragma region
970
971 void paint(QPainter *painter) override
972 {
973
974 Private::ImageViewDispatcherGuard guard(*dispatcher_);
975 if (!dispatcher_->IsBufferValid())
976 return;
977
978 auto screenImage = ScreenImage();
979
980 if (dispatcher_->UploadMode() == UI::UploadMode::Image)
981 {
982
983 painter->drawImage(CvbToQt(dispatcher_->TargetRect()), screenImage, CvbToQt(dispatcher_->SourceRect()));
984 }
985 else
986 {
987 auto image = image_->Image();
988 if (!image)
989 return;
990
991 painter->drawImage(CvbToQt(dispatcher_->TargetRect()), screenImage, CvbToQt(dispatcher_->SourceRectAdj()));
992 }
993 }
994
995#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
996#define geometryChangeFuncName geometryChange
997#else
998#define geometryChangeFuncName geometryChanged
999#endif
1000
1001 void geometryChangeFuncName(const QRectF &newGeometry, const QRectF &oldGeometry) override
1002 {
1003 auto tmpNewGemotry = QtToCvb(newGeometry);
1004 if (tmpNewGemotry != dispatcher_->ViewRect())
1005 dispatcher_->UpdateViewRect(tmpNewGemotry, [&]() { NotifyViewRect(); });
1006
1007 QQuickPaintedItem::geometryChangeFuncName(newGeometry, oldGeometry);
1008
1009 if (dispatcher_->UploadMode() == UI::UploadMode::Viewport && image_)
1010 Refresh();
1011 }
1012
1013 void wheelEvent(QWheelEvent *event) override
1014 {
1015#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
1016 const QPointF pos = event->position();
1017#else
1018 const QPointF pos = event->pos();
1019#endif
1020 SetViewAnchor(pos); // globalPosition is buggy, will only work after resize
1021 auto numDegrees = event->angleDelta().y();
1022
1023 if (numDegrees <= -15)
1024 TryZoomOut();
1025 else if (numDegrees >= 15)
1026 TryZoomIn();
1027 }
1028
1029 void mouseMoveEvent(QMouseEvent *event) override
1030 {
1031 if (event->buttons() & Qt::LeftButton)
1032 {
1033#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
1034 const QPointF pos = event->position();
1035#else
1036 const QPointF pos = event->pos();
1037#endif
1038 auto currentPos = QtToCvb(pos); // globalPos is buggy, will only work after resize
1039 if (!dispatcher_->IsLastMousePositionValid())
1040 {
1041 dispatcher_->InvalidateLastMousePosition(currentPos);
1042 return;
1043 }
1044
1045 TryTranslate(CvbToQt(currentPos - dispatcher_->LastMousePosition()));
1046 dispatcher_->InvalidateLastMousePosition(currentPos);
1047 }
1048 }
1049
1050 void mouseReleaseEvent(QMouseEvent *) override
1051 {
1052 dispatcher_->InvalidateLastMousePosition();
1053 }
1054
1055 void mousePressEvent(QMouseEvent *) override
1056 {
1057 // do nothing just prevent the default implementation from ignoring the event
1058 }
1059
1060 void hoverMoveEvent(QHoverEvent *event) override
1061 {
1062 auto hoverPosition = dispatcher_->MapViewToImage(QtToCvb(event->position()));
1063 if (!dispatcher_->ImageRect().Contains(hoverPosition))
1064 return;
1065
1066 dispatcher_->UpdateHoverPosition(hoverPosition, [&]() { NotifyHover(); });
1067 }
1068
1069#pragma endregion Reimplemented from Qt
1070
1071#pragma region
1072
1073 std::unique_ptr<UI::Private::ImageViewDispatcher> dispatcher_;
1074
1075 ImageController *image_ = nullptr;
1076
1077#pragma endregion Members
1078
1079#pragma region
1080
1081 Q_SIGNALS:
1082
1083 void NotifyImageRect();
1084 void NotifyViewRect();
1085 void NotifySourceRect();
1086 void NotifyTargetRect();
1087
1088 void NotifyImage();
1089
1090 void NotifyZoom();
1091
1092 void NotifyViewAnchor();
1093 void NotifyImageAnchor();
1094
1095 void NotifyHover();
1096
1097 void NotifyUploadMode();
1098
1099#pragma endregion Notify
1100 };
1101
1102 inline ImageLabelItem::ImageLabelItem(QQuickItem *parent)
1103 : QQuickItem(parent)
1104 {
1105 setTransformOrigin(QQuickItem::TopLeft);
1106 connect(this, &ImageLabelItem::NotifyImageView, this, &ImageLabelItem::OnImageViewChanged);
1107 }
1108
1109 inline void ImageLabelItem::OnImageXChanged()
1110 {
1111 if (!view_)
1112 return;
1113
1114 auto sourceRect = view_->SourceRect();
1115 auto sourceX = imageX_ - sourceRect.x();
1116 auto targetX = sourceX * view_->ZoomFactor();
1117 auto targetRect = view_->TargetRect();
1118 auto viewX = targetX + targetRect.x();
1119
1120 setX(viewX);
1121 }
1122
1123 inline void ImageLabelItem::OnImageYChanged()
1124 {
1125 if (!view_)
1126 return;
1127
1128 auto sourceRect = view_->SourceRect();
1129 auto sourceY = imageY_ - sourceRect.y();
1130 auto targetY = sourceY * view_->ZoomFactor();
1131 auto targetRect = view_->TargetRect();
1132 auto viewY = targetY + targetRect.y();
1133
1134 setY(viewY);
1135 }
1136
1137 inline void ImageLabelItem::OnImageViewChanged()
1138 {
1139 SetupConnections();
1140 OnImageXChanged();
1141 OnImageYChanged();
1142 OnLabelScaleChanged();
1143 }
1144
1145 inline void ImageLabelItem::OnLabelScaleChanged()
1146 {
1147 if (labelScale_ == UI::LabelScale::Off)
1148 {
1149 setScale(1.0);
1150 return;
1151 }
1152
1153 if (!view_)
1154 return;
1155
1156 setScale(view_->ZoomFactor());
1157 }
1158
1159 inline void ImageLabelItem::SetupConnections()
1160 {
1161 if (!view_)
1162 return;
1163
1164 connect(this, &ImageLabelItem::NotifyImageX, this, &ImageLabelItem::OnImageXChanged);
1165 connect(this, &ImageLabelItem::NotifyImageY, this, &ImageLabelItem::OnImageYChanged);
1166 connect(this, &ImageLabelItem::NotifyLabelScale, this, &ImageLabelItem::OnLabelScaleChanged);
1167
1168 connect(view_, &ImageViewItem::NotifySourceRect, this, &ImageLabelItem::OnImageXChanged);
1169 connect(view_, &ImageViewItem::NotifySourceRect, this, &ImageLabelItem::OnImageYChanged);
1170 connect(view_, &ImageViewItem::NotifyTargetRect, this, &ImageLabelItem::OnImageXChanged);
1171 connect(view_, &ImageViewItem::NotifyTargetRect, this, &ImageLabelItem::OnImageYChanged);
1172 connect(view_, &ImageViewItem::NotifyZoom, this, &ImageLabelItem::OnImageXChanged);
1173 connect(view_, &ImageViewItem::NotifyZoom, this, &ImageLabelItem::OnImageYChanged);
1174
1175 connect(view_, &ImageViewItem::NotifyZoom, this, &ImageLabelItem::OnLabelScaleChanged);
1176 }
1177
1178 } // namespace Quick
1179
1180 using ImageLabelItem = Quick::ImageLabelItem;
1181 using ImageController = Quick::ImageController;
1182 using ImageViewItem = Quick::ImageViewItem;
1183
1184 } // namespace UI
1185
1186 CVB_END_INLINE_NS
1187
1188} // namespace Cvb
Multi-purpose 2D vector class.
Definition point_2d.hpp:20
T X() const noexcept
Gets the x-component of the point.
Definition point_2d.hpp:84
T Y() const noexcept
Gets the y-component of the point.
Definition point_2d.hpp:104
void SetX(T x) noexcept
Sets the x-component of the point.
Definition point_2d.hpp:94
void SetY(T y)
Sets the y-component of the point.
Definition point_2d.hpp:114
Rectangle object.
Definition rect.hpp:24
View to display an image.
Definition decl_image_view.hpp:69
Controller object for the QML image view item.
Definition image_view_item.hpp:240
int Width() const noexcept
Width of the shared image in pixels.
Definition image_view_item.hpp:321
int Height() const noexcept
Height of the shared image in pixels.
Definition image_view_item.hpp:337
void Refresh(const ImagePtr &image, AutoRefresh autoRefresh=AutoRefresh::Off)
Share the image and refresh the view.
Definition image_view_item.hpp:280
int PlanesCount() const noexcept
Get the number of planes for this image.
Definition image_view_item.hpp:353
void Refresh()
Refresh the view.
Definition image_view_item.hpp:303
void ReleaseRefreshShare() noexcept
Releases the shared image.
Definition image_view_item.hpp:266
ImagePtr Image() const
Get the currently shared image.
Definition image_view_item.hpp:253
Image label item for QML.
Definition image_view_item.hpp:44
double ImageY() const noexcept
Get the Y position of this label on the image.
Definition image_view_item.hpp:123
void SetImageView(ImageViewItem *view)
Set the image view for this label.
Definition image_view_item.hpp:159
void SetImageY(double imageY)
Set the Y position of this label on the image.
Definition image_view_item.hpp:135
double ImageX() const noexcept
Get the X position of this label on the image.
Definition image_view_item.hpp:95
void SetImageX(double imageX)
Set the X position of this label on the image.
Definition image_view_item.hpp:107
static void Register()
Convenience method to register this type in QML.
Definition image_view_item.hpp:83
void SetLabelScale(int labelScale)
Set the label scale behaviour (as integer, see Cvb::UI::LabelScale).
Definition image_view_item.hpp:195
int LabelScale() const noexcept
Get the label scale behaviour (as integer, see Cvb::UI::LabelScale).
Definition image_view_item.hpp:179
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:69
Image view item for QML.
Definition image_view_item.hpp:391
Q_INVOKABLE QPointF MapViewToTarget(const QPointF &viewPoint) const
Maps a point from the view rectangle to the target rect.
Definition image_view_item.hpp:475
Q_INVOKABLE QPointF MapSourceToTarget(const QPointF &sourcePoint) const
Maps a point from the source rectangle to the target rectangle.
Definition image_view_item.hpp:519
Q_INVOKABLE QPointF MapTargetToSource(const QPointF &targetPoint) const
Maps a point from the target rectangle to the source rect.
Definition image_view_item.hpp:486
Q_INVOKABLE QPointF MapImageToTarget(const QPointF &imagePoint) const
Maps a point from the image rectangle to the target rectangle.
Definition image_view_item.hpp:574
int ZoomID() const
Get the zoom identifier for special zoom steps (as integer, see Cvb::UI::ZoomID).
Definition image_view_item.hpp:721
void SetZoomID(int id)
Set the zoom identifier for special zoom steps (as integer, see Cvb::UI::ZoomID).
Definition image_view_item.hpp:735
QRectF SourceRect() const noexcept
Get the rectangle inside the image rectangle that is actually rendered.
Definition image_view_item.hpp:701
QPointF HoverPosition() const noexcept
Get the point the mouse is hovering over.
Definition image_view_item.hpp:874
QPointF ViewAnchor() const noexcept
Get the reference point for mouse operations in view coordinates.
Definition image_view_item.hpp:794
Q_INVOKABLE bool TryTranslate(const QPointF &translation)
Tries to translate the target rectangle to a give point.
Definition image_view_item.hpp:459
Q_INVOKABLE QPointF MapImageToSource(const QPointF &imagePoint) const
Maps a point from the image rectangle to the source rectangle.
Definition image_view_item.hpp:530
void SetImage(QObject *image)
Set the image controller for this view item.
Definition image_view_item.hpp:774
void SetViewAnchor(const QPointF &viewAnchor)
Set the reference point for mouse operations in view coordinates.
Definition image_view_item.hpp:806
QRectF ViewRect() const noexcept
Get the rectangle this items covers.
Definition image_view_item.hpp:677
QVector< double > HoverPixel() const
The image pixel value the mouse is currently hovered over.
Definition image_view_item.hpp:844
Q_INVOKABLE bool TryZoomOut()
Tries to zoom out.
Definition image_view_item.hpp:439
Q_INVOKABLE QPointF MapTargetToView(const QPointF &targetPoint) const
Maps a point from the target rectangle to the view rectangle.
Definition image_view_item.hpp:508
void SetImageAnchor(const QPointF &imageAnchor)
Set the reference point for mouse operations in image coordinates.
Definition image_view_item.hpp:830
QRectF ImageRect() const noexcept
Get the rectangle described by the image buffer associated with the view.
Definition image_view_item.hpp:665
int UploadMode() const noexcept
Get the current upload mode (as integer, see Cvb::UI::UploadMode).
Definition image_view_item.hpp:891
Q_INVOKABLE QPointF MapSourceToImage(const QPointF &sourcePoint) const
Maps a point from the source rectangle to the image rect.
Definition image_view_item.hpp:497
Q_INVOKABLE bool TryZoomIn()
Tries to zoom in.
Definition image_view_item.hpp:421
static void Register()
Convenience method to register this type in QML.
Definition image_view_item.hpp:649
QRectF TargetRect() const noexcept
Get the rectangle inside the view rectangle the image is actually rendered to.
Definition image_view_item.hpp:689
void SetZoomFactor(double factor)
Set the view's zoom factor.
Definition image_view_item.hpp:759
QPointF ImageAnchor() const noexcept
Get the reference point for mouse operations in image coordinates.
Definition image_view_item.hpp:818
void Refresh()
Refresh the currently shared image.
Definition image_view_item.hpp:587
Q_INVOKABLE QPointF MapViewToImage(const QPointF &viewPoint) const
Maps a point from the view rectangle to the image rectangle.
Definition image_view_item.hpp:541
Q_INVOKABLE QPointF MapImageToView(const QPointF &imagePoint) const
Maps a point from the image rectangle to the view rectangle.
Definition image_view_item.hpp:552
void SetUploadMode(int uploadMode)
Set the current upload mode (as integer).
Definition image_view_item.hpp:905
Q_INVOKABLE QPointF MapTargetToImage(const QPointF &targetPoint) const
Maps a point from the target rectangle to the image rectangle.
Definition image_view_item.hpp:563
double ZoomFactor() const
Get the view's zoom factor.
Definition image_view_item.hpp:747
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:633
T floor(T... args)
Namespace for QML related classes.
Definition image_view_item.hpp:30
Namespace for user interface components.
Definition decl_image_scene.hpp:39
ZoomID
Identifier for a zoom factor.
Definition detail_ui.hpp:61
Cvb::String QtToCvb(const QString text) noexcept
Convenience converter for strings.
Definition ui.hpp:242
AutoRefresh
Allows to automatically refresh, if image content changes.
Definition detail_ui.hpp:114
@ On
Definition detail_ui.hpp:121
@ Off
Definition detail_ui.hpp:125
LabelScale
Switch defining if image view labels are sensitive to zoom operations.
Definition detail_ui.hpp:130
UploadMode
Defines the upload behavior.
Definition detail_ui.hpp:37
@ Viewport
Definition detail_ui.hpp:53
@ Image
Definition detail_ui.hpp:45
QString CvbToQt(const Cvb::String &text) noexcept
Convenience converter for strings.
Definition ui.hpp:257
Root namespace for the Image Manager interface.
Definition version.hpp:11
std::shared_ptr< Image > ImagePtr
Convenience shared pointer for Image.
Definition global.hpp:86