CVB++ 15.0
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 return QVector<double>::fromStdVector(image->GetPixel(hoverPositionInt));
864 }
865
867
873 QPointF HoverPosition() const noexcept
874 {
875 if (!dispatcher_->IsHoverPositionValid())
876 return QPointF();
877
878 return CvbToQt(dispatcher_->HoverPosition());
879 }
880
882
890 int UploadMode() const noexcept
891 {
892 return static_cast<int>(dispatcher_->UploadMode());
893 }
894
896
904 void SetUploadMode(int uploadMode)
905 {
906 dispatcher_->UpdateUploadMode(static_cast<UI::UploadMode>(uploadMode), [&]() { NotifyUploadMode(); });
907 }
908
909#pragma endregion Properties
910
911#pragma region
912
913 private Q_SLOTS:
914
915 void OnViewRectChanged()
916 {
917 UpdateTargetSource();
918 }
919
920 void OnImageRectChanged()
921 {
922 UpdateTargetSource();
923 }
924
925 void OnZoomFactorChanged()
926 {
927 UpdateTargetSource();
928 update();
929 }
930
931 void OnZoomIDChanged()
932 {
933 UpdateTargetSource();
934 update();
935 }
936
937 void OnViewAnchorChnaged()
938 {
939 auto targetPoint = dispatcher_->MapViewToTarget(dispatcher_->ViewAnchor());
940 targetPoint = dispatcher_->LimitPointToRect(targetPoint, dispatcher_->TargetRect());
941
942 auto sourcePoint = dispatcher_->MapTargetToSource(targetPoint);
943 auto imagePoint = dispatcher_->MapSourceToImage(sourcePoint);
944
945 dispatcher_->UpdateImageAnchor(imagePoint, [&]() { NotifyImageAnchor(); });
946 }
947
948#pragma endregion Slots
949
950#pragma region
951
952 private:
953 void UpdateTargetSource()
954 {
955 dispatcher_->UpdateTargetSource([&]() { NotifyTargetRect(); }, [&]() { NotifySourceRect(); });
956 }
957
958 QImage ScreenImage() const noexcept
959 {
960 auto data = dispatcher_->Buffer();
961 auto size = dispatcher_->BufferSize();
962
963 return QImage(data, size.Width(), size.Height(), QImage::Format_ARGB32_Premultiplied);
964 }
965
966#pragma endregion Helper
967
968#pragma region
969
970 void paint(QPainter *painter) override
971 {
972
973 Private::ImageViewDispatcherGuard guard(*dispatcher_);
974 if (!dispatcher_->IsBufferValid())
975 return;
976
977 auto screenImage = ScreenImage();
978
979 if (dispatcher_->UploadMode() == UI::UploadMode::Image)
980 {
981
982 painter->drawImage(CvbToQt(dispatcher_->TargetRect()), screenImage, CvbToQt(dispatcher_->SourceRect()));
983 }
984 else
985 {
986 auto image = image_->Image();
987 if (!image)
988 return;
989
990 painter->drawImage(CvbToQt(dispatcher_->TargetRect()), screenImage, CvbToQt(dispatcher_->SourceRectAdj()));
991 }
992 }
993
994 void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) override
995 {
996 auto tmpNewGemotry = QtToCvb(newGeometry);
997 if (tmpNewGemotry != dispatcher_->ViewRect())
998 dispatcher_->UpdateViewRect(tmpNewGemotry, [&]() { NotifyViewRect(); });
999
1000 QQuickPaintedItem::geometryChanged(newGeometry, oldGeometry);
1001
1002 if (dispatcher_->UploadMode() == UI::UploadMode::Viewport && image_)
1003 Refresh();
1004 }
1005
1006 void wheelEvent(QWheelEvent *event) override
1007 {
1008 SetViewAnchor(event->posF()); // globalPosF is buggy, will only work after resize
1009 auto numDegrees = event->angleDelta().y();
1010
1011 if (numDegrees <= -15)
1012 TryZoomOut();
1013 else if (numDegrees >= 15)
1014 TryZoomIn();
1015 }
1016
1017 void mouseMoveEvent(QMouseEvent *event) override
1018 {
1019 if (event->buttons() & Qt::LeftButton)
1020 {
1021 auto currentPos = QtToCvb(event->pos()); // globalPos is buggy, will only work after resize
1022 if (!dispatcher_->IsLastMousePositionValid())
1023 {
1024 dispatcher_->InvalidateLastMousePosition(currentPos);
1025 return;
1026 }
1027
1028 TryTranslate(CvbToQt(currentPos - dispatcher_->LastMousePosition()));
1029 dispatcher_->InvalidateLastMousePosition(currentPos);
1030 }
1031 }
1032
1033 void mouseReleaseEvent(QMouseEvent *) override
1034 {
1035 dispatcher_->InvalidateLastMousePosition();
1036 }
1037
1038 void mousePressEvent(QMouseEvent *) override
1039 {
1040 // do nothing just prevent the default implementation from ignoring the event
1041 }
1042
1043 void hoverMoveEvent(QHoverEvent *event) override
1044 {
1045 auto hoverPosition = dispatcher_->MapViewToImage(QtToCvb(event->posF()));
1046 if (!dispatcher_->ImageRect().Contains(hoverPosition))
1047 return;
1048
1049 dispatcher_->UpdateHoverPosition(hoverPosition, [&]() { NotifyHover(); });
1050 }
1051
1052#pragma endregion Reimplemented from Qt
1053
1054#pragma region
1055
1056 std::unique_ptr<UI::Private::ImageViewDispatcher> dispatcher_;
1057
1058 ImageController *image_ = nullptr;
1059
1060#pragma endregion Members
1061
1062#pragma region
1063
1064 Q_SIGNALS:
1065
1066 void NotifyImageRect();
1067 void NotifyViewRect();
1068 void NotifySourceRect();
1069 void NotifyTargetRect();
1070
1071 void NotifyImage();
1072
1073 void NotifyZoom();
1074
1075 void NotifyViewAnchor();
1076 void NotifyImageAnchor();
1077
1078 void NotifyHover();
1079
1080 void NotifyUploadMode();
1081
1082#pragma endregion Notify
1083 };
1084
1085 inline ImageLabelItem::ImageLabelItem(QQuickItem *parent)
1086 : QQuickItem(parent)
1087 {
1088 setTransformOrigin(QQuickItem::TopLeft);
1089 connect(this, &ImageLabelItem::NotifyImageView, this, &ImageLabelItem::OnImageViewChanged);
1090 }
1091
1092 inline void ImageLabelItem::OnImageXChanged()
1093 {
1094 if (!view_)
1095 return;
1096
1097 auto sourceRect = view_->SourceRect();
1098 auto sourceX = imageX_ - sourceRect.x();
1099 auto targetX = sourceX * view_->ZoomFactor();
1100 auto targetRect = view_->TargetRect();
1101 auto viewX = targetX + targetRect.x();
1102
1103 setX(viewX);
1104 }
1105
1106 inline void ImageLabelItem::OnImageYChanged()
1107 {
1108 if (!view_)
1109 return;
1110
1111 auto sourceRect = view_->SourceRect();
1112 auto sourceY = imageY_ - sourceRect.y();
1113 auto targetY = sourceY * view_->ZoomFactor();
1114 auto targetRect = view_->TargetRect();
1115 auto viewY = targetY + targetRect.y();
1116
1117 setY(viewY);
1118 }
1119
1120 inline void ImageLabelItem::OnImageViewChanged()
1121 {
1122 SetupConnections();
1123 OnImageXChanged();
1124 OnImageYChanged();
1125 OnLabelScaleChanged();
1126 }
1127
1128 inline void ImageLabelItem::OnLabelScaleChanged()
1129 {
1130 if (labelScale_ == UI::LabelScale::Off)
1131 {
1132 setScale(1.0);
1133 return;
1134 }
1135
1136 if (!view_)
1137 return;
1138
1139 setScale(view_->ZoomFactor());
1140 }
1141
1142 inline void ImageLabelItem::SetupConnections()
1143 {
1144 if (!view_)
1145 return;
1146
1147 connect(this, &ImageLabelItem::NotifyImageX, this, &ImageLabelItem::OnImageXChanged);
1148 connect(this, &ImageLabelItem::NotifyImageY, this, &ImageLabelItem::OnImageYChanged);
1149 connect(this, &ImageLabelItem::NotifyLabelScale, this, &ImageLabelItem::OnLabelScaleChanged);
1150
1151 connect(view_, &ImageViewItem::NotifySourceRect, this, &ImageLabelItem::OnImageXChanged);
1152 connect(view_, &ImageViewItem::NotifySourceRect, this, &ImageLabelItem::OnImageYChanged);
1153 connect(view_, &ImageViewItem::NotifyTargetRect, this, &ImageLabelItem::OnImageXChanged);
1154 connect(view_, &ImageViewItem::NotifyTargetRect, this, &ImageLabelItem::OnImageYChanged);
1155 connect(view_, &ImageViewItem::NotifyZoom, this, &ImageLabelItem::OnImageXChanged);
1156 connect(view_, &ImageViewItem::NotifyZoom, this, &ImageLabelItem::OnImageYChanged);
1157
1158 connect(view_, &ImageViewItem::NotifyZoom, this, &ImageLabelItem::OnLabelScaleChanged);
1159 }
1160
1161 } // namespace Quick
1162
1163 using ImageLabelItem = Quick::ImageLabelItem;
1164 using ImageController = Quick::ImageController;
1165 using ImageViewItem = Quick::ImageViewItem;
1166
1167 } // namespace UI
1168
1169 CVB_END_INLINE_NS
1170
1171} // 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:873
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:890
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:904
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