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#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
546 public Q_SLOTS:
547
549
554 void Refresh()
555 {
556 if (!image_)
557 return;
558
559 auto image = image_->Image();
560 if (!image)
561 return;
562
563 dispatcher_->UploadImage(*image, [&]() { NotifyImageRect(); });
564 update();
565 }
566
567#pragma endregion QML Interface
568
569#pragma region
570
571 public:
572 explicit ImageViewItem(QQuickItem *parent = nullptr)
573 : QQuickPaintedItem(parent)
574 {
575 dispatcher_ = std::make_unique<Private::ImageViewDispatcher>([&]() { NotifyZoom(); });
576
577 setClip(true);
578 setAcceptedMouseButtons(Qt::AllButtons);
579 setAcceptHoverEvents(true);
580 connect(this, &ImageViewItem::NotifyImage, this, &ImageViewItem::Refresh);
581 connect(this, &ImageViewItem::NotifyViewRect, this, &ImageViewItem::OnViewRectChanged);
582 connect(this, &ImageViewItem::NotifyImageRect, this, &ImageViewItem::OnImageRectChanged);
583 connect(this, &ImageViewItem::NotifyZoom, this, &ImageViewItem::OnZoomIDChanged);
584 connect(this, &ImageViewItem::NotifyZoom, this, &ImageViewItem::OnZoomFactorChanged);
585 connect(this, &ImageViewItem::NotifyViewAnchor, this, &ImageViewItem::OnViewAnchorChnaged);
586 }
587
589
599 template <class T>
600 static void Register(const char *uri, int versionMajor, int versionMinor, const char *qmlName)
601 {
602 qmlRegisterType<T>(uri, versionMajor, versionMinor, qmlName);
603 qmlRegisterUncreatableMetaObject(Cvb::UI::staticMetaObject, uri, versionMajor, versionMinor, "ZoomID",
604 "CVB: cannot object for enumerations");
605 qmlRegisterUncreatableMetaObject(Cvb::UI::staticMetaObject, uri, versionMajor, versionMinor, "UploadMode",
606 "CVB: cannot object for enumerations");
607 }
608
610
616 static void Register()
617 {
618 Register<ImageViewItem>("CvbQuick", 1, 0, "ImageView");
619 }
620
621#pragma endregion CTor / DTor / Register
622
623#pragma region
624
626
632 QRectF ImageRect() const noexcept
633 {
634 return CvbToQt(dispatcher_->ImageRect());
635 }
636
638
644 QRectF ViewRect() const noexcept
645 {
646 return CvbToQt(dispatcher_->ViewRect());
647 }
648
650
656 QRectF TargetRect() const noexcept
657 {
658 return CvbToQt(dispatcher_->TargetRect());
659 }
660
662
668 QRectF SourceRect() const noexcept
669 {
670 return CvbToQt(dispatcher_->SourceRect());
671 }
672
673 // needed put not for public use!
674 QObject *Image() const
675 {
676 return image_;
677 }
678
680
688 int ZoomID() const
689 {
690 return static_cast<int>(dispatcher_->ZoomID());
691 }
692
694
702 void SetZoomID(int id)
703 {
704 dispatcher_->UpdateZoomID(static_cast<UI::ZoomID>(id), [&]() { NotifyZoom(); });
705 }
706
708
714 double ZoomFactor() const
715 {
716 return dispatcher_->ZoomFactor();
717 }
718
720
726 void SetZoomFactor(double factor)
727 {
728 dispatcher_->UpdateZoomFactor(factor, [&]() { NotifyZoom(); });
729 }
730
732
741 void SetImage(QObject *image)
742 {
743 if (!image)
744 return;
745
746 image_ = dynamic_cast<ImageController *>(image);
747 if (!image_)
748 return;
749 connect(image_, &ImageController::NotifyRefresh, this, &ImageViewItem::Refresh);
750 connect(image_, &ImageController::NotifyRefreshImage, this, &ImageViewItem::Refresh);
751 NotifyImage();
752 }
753
755
761 QPointF ViewAnchor() const noexcept
762 {
763 return CvbToQt(dispatcher_->ViewAnchor());
764 }
765
767
773 void SetViewAnchor(const QPointF &viewAnchor)
774 {
775 dispatcher_->UpdateViewAnchor(QtToCvb(viewAnchor), [&]() { NotifyViewAnchor(); });
776 }
777
779
785 QPointF ImageAnchor() const noexcept
786 {
787 return CvbToQt(dispatcher_->ImageAnchor());
788 }
789
791
797 void SetImageAnchor(const QPointF &imageAnchor)
798 {
799 dispatcher_->UpdateImageAnchor(QtToCvb(imageAnchor), [&]() { NotifyImageAnchor(); });
800 }
801
803
811 QVector<double> HoverPixel() const
812 {
813 if (!image_)
814 return QVector<double>();
815
816 auto image = image_->Image();
817 if (!image || !dispatcher_->IsHoverPositionValid())
818 return QVector<double>();
819
820 auto hoverPosition = dispatcher_->HoverPosition();
821 Point2D<int> hoverPositionInt(static_cast<int>(std::floor(hoverPosition.X())),
822 static_cast<int>(std::floor(hoverPosition.Y())));
823 // here we can get image width/height as max so we filter it
824
825 if (hoverPositionInt.X() == image->Width())
826 hoverPositionInt.SetX(static_cast<int>(hoverPosition.X() - 1.0));
827 if (hoverPositionInt.Y() == image->Height())
828 hoverPositionInt.SetY(static_cast<int>(hoverPosition.Y() - 1.0));
829
830 return QVector<double>::fromStdVector(image->GetPixel(hoverPositionInt));
831 }
832
834
840 QPointF HoverPosition() const noexcept
841 {
842 if (!dispatcher_->IsHoverPositionValid())
843 return QPointF();
844
845 return CvbToQt(dispatcher_->HoverPosition());
846 }
847
849
857 int UploadMode() const noexcept
858 {
859 return static_cast<int>(dispatcher_->UploadMode());
860 }
861
863
871 void SetUploadMode(int uploadMode)
872 {
873 dispatcher_->UpdateUploadMode(static_cast<UI::UploadMode>(uploadMode), [&]() { NotifyUploadMode(); });
874 }
875
876#pragma endregion Properties
877
878#pragma region
879
880 private Q_SLOTS:
881
882 void OnViewRectChanged()
883 {
884 UpdateTargetSource();
885 }
886
887 void OnImageRectChanged()
888 {
889 UpdateTargetSource();
890 }
891
892 void OnZoomFactorChanged()
893 {
894 UpdateTargetSource();
895 update();
896 }
897
898 void OnZoomIDChanged()
899 {
900 UpdateTargetSource();
901 update();
902 }
903
904 void OnViewAnchorChnaged()
905 {
906 auto targetPoint = dispatcher_->MapViewToTarget(dispatcher_->ViewAnchor());
907 targetPoint = dispatcher_->LimitPointToRect(targetPoint, dispatcher_->TargetRect());
908
909 auto sourcePoint = dispatcher_->MapTargetToSource(targetPoint);
910 auto imagePoint = dispatcher_->MapSourceToImage(sourcePoint);
911
912 dispatcher_->UpdateImageAnchor(imagePoint, [&]() { NotifyImageAnchor(); });
913 }
914
915#pragma endregion Slots
916
917#pragma region
918
919 private:
920 void UpdateTargetSource()
921 {
922 dispatcher_->UpdateTargetSource([&]() { NotifyTargetRect(); }, [&]() { NotifySourceRect(); });
923 }
924
925 QImage ScreenImage() const noexcept
926 {
927 auto data = dispatcher_->Buffer();
928 auto size = dispatcher_->BufferSize();
929
930 return QImage(data, size.Width(), size.Height(), QImage::Format_ARGB32_Premultiplied);
931 }
932
933#pragma endregion Helper
934
935#pragma region
936
937 void paint(QPainter *painter) override
938 {
939
940 Private::ImageViewDispatcherGuard guard(*dispatcher_);
941 if (!dispatcher_->IsBufferValid())
942 return;
943
944 auto screenImage = ScreenImage();
945
946 if (dispatcher_->UploadMode() == UI::UploadMode::Image)
947 {
948
949 painter->drawImage(CvbToQt(dispatcher_->TargetRect()), screenImage, CvbToQt(dispatcher_->SourceRect()));
950 }
951 else
952 {
953 auto image = image_->Image();
954 if (!image)
955 return;
956
957 painter->drawImage(CvbToQt(dispatcher_->TargetRect()), screenImage, CvbToQt(dispatcher_->SourceRectAdj()));
958 }
959 }
960
961 void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) override
962 {
963 auto tmpNewGemotry = QtToCvb(newGeometry);
964 if (tmpNewGemotry != dispatcher_->ViewRect())
965 dispatcher_->UpdateViewRect(tmpNewGemotry, [&]() { NotifyViewRect(); });
966
967 QQuickPaintedItem::geometryChanged(newGeometry, oldGeometry);
968
969 if (dispatcher_->UploadMode() == UI::UploadMode::Viewport && image_)
970 Refresh();
971 }
972
973 void wheelEvent(QWheelEvent *event) override
974 {
975 SetViewAnchor(mapFromGlobal(event->globalPosF()));
976 auto numDegrees = event->angleDelta().y();
977
978 if (numDegrees <= -15)
979 TryZoomOut();
980 else if (numDegrees >= 15)
981 TryZoomIn();
982 }
983
984 void mouseMoveEvent(QMouseEvent *event) override
985 {
986 if (event->buttons() & Qt::LeftButton)
987 {
988 auto currentPos = QtToCvb(mapFromGlobal(event->globalPos()));
989 if (!dispatcher_->IsLastMousePositionValid())
990 {
991 dispatcher_->InvalidateLastMousePosition(currentPos);
992 return;
993 }
994
995 TryTranslate(CvbToQt(currentPos - dispatcher_->LastMousePosition()));
996 dispatcher_->InvalidateLastMousePosition(currentPos);
997 }
998 }
999
1000 void mouseReleaseEvent(QMouseEvent *) override
1001 {
1002 dispatcher_->InvalidateLastMousePosition();
1003 }
1004
1005 void mousePressEvent(QMouseEvent *) override
1006 {
1007 // do nothing just prevent the default implementation from ignoring the event
1008 }
1009
1010 void hoverMoveEvent(QHoverEvent *event) override
1011 {
1012 auto hoverPosition = dispatcher_->MapViewToImage(QtToCvb(event->posF()));
1013 if (!dispatcher_->ImageRect().Contains(hoverPosition))
1014 return;
1015
1016 dispatcher_->UpdateHoverPosition(hoverPosition, [&]() { NotifyHover(); });
1017 }
1018
1019#pragma endregion Reimplemented from Qt
1020
1021#pragma region
1022
1023 std::unique_ptr<UI::Private::ImageViewDispatcher> dispatcher_;
1024
1025 ImageController *image_ = nullptr;
1026
1027#pragma endregion Members
1028
1029#pragma region
1030
1031 Q_SIGNALS:
1032
1033 void NotifyImageRect();
1034 void NotifyViewRect();
1035 void NotifySourceRect();
1036 void NotifyTargetRect();
1037
1038 void NotifyImage();
1039
1040 void NotifyZoom();
1041
1042 void NotifyViewAnchor();
1043 void NotifyImageAnchor();
1044
1045 void NotifyHover();
1046
1047 void NotifyUploadMode();
1048
1049#pragma endregion Notify
1050 };
1051
1052 inline ImageLabelItem::ImageLabelItem(QQuickItem *parent)
1053 : QQuickItem(parent)
1054 {
1055 setTransformOrigin(QQuickItem::TopLeft);
1056 connect(this, &ImageLabelItem::NotifyImageView, this, &ImageLabelItem::OnImageViewChanged);
1057 }
1058
1059 inline void ImageLabelItem::OnImageXChanged()
1060 {
1061 if (!view_)
1062 return;
1063
1064 auto sourceRect = view_->SourceRect();
1065 auto sourceX = imageX_ - sourceRect.x();
1066 auto targetX = sourceX * view_->ZoomFactor();
1067 auto targetRect = view_->TargetRect();
1068 auto viewX = targetX + targetRect.x();
1069
1070 setX(viewX);
1071 }
1072
1073 inline void ImageLabelItem::OnImageYChanged()
1074 {
1075 if (!view_)
1076 return;
1077
1078 auto sourceRect = view_->SourceRect();
1079 auto sourceY = imageY_ - sourceRect.y();
1080 auto targetY = sourceY * view_->ZoomFactor();
1081 auto targetRect = view_->TargetRect();
1082 auto viewY = targetY + targetRect.y();
1083
1084 setY(viewY);
1085 }
1086
1087 inline void ImageLabelItem::OnImageViewChanged()
1088 {
1089 SetupConnections();
1090 OnImageXChanged();
1091 OnImageYChanged();
1092 OnLabelScaleChanged();
1093 }
1094
1095 inline void ImageLabelItem::OnLabelScaleChanged()
1096 {
1097 if (labelScale_ == UI::LabelScale::Off)
1098 {
1099 setScale(1.0);
1100 return;
1101 }
1102
1103 if (!view_)
1104 return;
1105
1106 setScale(view_->ZoomFactor());
1107 }
1108
1109 inline void ImageLabelItem::SetupConnections()
1110 {
1111 if (!view_)
1112 return;
1113
1114 connect(this, &ImageLabelItem::NotifyImageX, this, &ImageLabelItem::OnImageXChanged);
1115 connect(this, &ImageLabelItem::NotifyImageY, this, &ImageLabelItem::OnImageYChanged);
1116 connect(this, &ImageLabelItem::NotifyLabelScale, this, &ImageLabelItem::OnLabelScaleChanged);
1117
1118 connect(view_, &ImageViewItem::NotifySourceRect, this, &ImageLabelItem::OnImageXChanged);
1119 connect(view_, &ImageViewItem::NotifySourceRect, this, &ImageLabelItem::OnImageYChanged);
1120 connect(view_, &ImageViewItem::NotifyTargetRect, this, &ImageLabelItem::OnImageXChanged);
1121 connect(view_, &ImageViewItem::NotifyTargetRect, this, &ImageLabelItem::OnImageYChanged);
1122 connect(view_, &ImageViewItem::NotifyZoom, this, &ImageLabelItem::OnImageXChanged);
1123 connect(view_, &ImageViewItem::NotifyZoom, this, &ImageLabelItem::OnImageYChanged);
1124
1125 connect(view_, &ImageViewItem::NotifyZoom, this, &ImageLabelItem::OnLabelScaleChanged);
1126 }
1127
1128 } // namespace Quick
1129
1130 using ImageLabelItem = Quick::ImageLabelItem;
1131 using ImageController = Quick::ImageController;
1132 using ImageViewItem = Quick::ImageViewItem;
1133
1134 } // namespace UI
1135
1136 CVB_END_INLINE_NS
1137
1138} // 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
int ZoomID() const
Get the zoom identifier for special zoom steps (as integer, see Cvb::UI::ZoomID).
Definition image_view_item.hpp:688
void SetZoomID(int id)
Set the zoom identifier for special zoom steps (as integer, see Cvb::UI::ZoomID).
Definition image_view_item.hpp:702
QRectF SourceRect() const noexcept
Get the rectangle inside the image rectangle that is actually rendered.
Definition image_view_item.hpp:668
QPointF HoverPosition() const noexcept
Get the point the mouse is hovering over.
Definition image_view_item.hpp:840
QPointF ViewAnchor() const noexcept
Get the reference point for mouse operations in view coordinates.
Definition image_view_item.hpp:761
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:741
void SetViewAnchor(const QPointF &viewAnchor)
Set the reference point for mouse operations in view coordinates.
Definition image_view_item.hpp:773
QRectF ViewRect() const noexcept
Get the rectangle this items covers.
Definition image_view_item.hpp:644
QVector< double > HoverPixel() const
The image pixel value the mouse is currently hovered over.
Definition image_view_item.hpp:811
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:797
QRectF ImageRect() const noexcept
Get the rectangle described by the image buffer associated with the view.
Definition image_view_item.hpp:632
int UploadMode() const noexcept
Get the current upload mode (as integer, see Cvb::UI::UploadMode).
Definition image_view_item.hpp:857
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:616
QRectF TargetRect() const noexcept
Get the rectangle inside the view rectangle the image is actually rendered to.
Definition image_view_item.hpp:656
void SetZoomFactor(double factor)
Set the view's zoom factor.
Definition image_view_item.hpp:726
QPointF ImageAnchor() const noexcept
Get the reference point for mouse operations in image coordinates.
Definition image_view_item.hpp:785
void Refresh()
Refresh the currently shared image.
Definition image_view_item.hpp:554
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
void SetUploadMode(int uploadMode)
Set the current upload mode (as integer).
Definition image_view_item.hpp:871
double ZoomFactor() const
Get the view's zoom factor.
Definition image_view_item.hpp:714
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:600
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 c_bayer_to_rgb.h:17
std::shared_ptr< Image > ImagePtr
Convenience shared pointer for Image.
Definition global.hpp:86