CuteLogger
Fast and simple logging solution for Qt based applications
videozoomwidget.h
1 /*
2  * Copyright (c) 2019 Meltytech, LLC
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #ifndef VIDEOZOOMWIDGET_H
19 #define VIDEOZOOMWIDGET_H
20 
21 #include "sharedframe.h"
22 
23 #include <QWidget>
24 #include <QMutex>
25 
26 class VideoZoomWidget : public QWidget
27 {
28  Q_OBJECT
29 
30 public:
31  struct PixelValues {
32  uint8_t y;
33  uint8_t u;
34  uint8_t v;
35  uint8_t r;
36  uint8_t g;
37  uint8_t b;
38  };
39 
40  explicit VideoZoomWidget();
41 
42  // May be called from a worker thread.
43  void putFrame(SharedFrame frame);
44 
45  QPoint getSelectedPixel();
46  void setSelectedPixel(QPoint pixel);
47  QRect getPixelRect();
48  int getZoom();
49  PixelValues getPixelValues(const QPoint& pixel);
50  void setOffset(QPoint offset);
51 
52 signals:
53  void pixelSelected(const QPoint&);
54  void zoomChanged(int zoom);
55 
56 public slots:
57  void lock(bool locked);
58 
59 private:
60  virtual QSize sizeHint() const Q_DECL_OVERRIDE;
61 
62  void paintEvent(QPaintEvent*) Q_DECL_OVERRIDE;
63  void mouseMoveEvent(QMouseEvent *event)Q_DECL_OVERRIDE;
64  void mousePressEvent(QMouseEvent *event)Q_DECL_OVERRIDE;
65  void wheelEvent(QWheelEvent *event)Q_DECL_OVERRIDE;
66 
67  QPoint pixelToPos(const QPoint& pixel);
68  QPoint posToPixel(const QPoint& pos);
69  PixelValues pixelToValues(const QPoint& pixel);
70 
71  bool m_locked;
72  bool m_selectionInProgress;
73  int m_zoom;
74  QPoint m_imageOffset;
75  QPoint m_mouseGrabPixel;
76  QPoint m_selectedPixel;
77 
78  // Variables accessed from multiple threads (mutex protected)
79  QMutex m_mutex;
80  SharedFrame m_frame;
81 };
82 
83 #endif // VIDEOZOOMWIDGET_H
SharedFrame
The SharedFrame provides thread safe access to Mlt::Frame data.
Definition: sharedframe.h:48