Debian Codegraph @

src/ApvlvImageWidget.h

raw
1 /*
2 * This file is part of the apvlv package
3 *
4 * Copyright (C) 2008 Alf.
5 *
6 * Contact: Alf <[email protected]>
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2.0 of
11 * the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public
19 * License along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 *
22 */
23 /* @CPPFILE ApvlvImageWidget.h
24 *
25 * Author: Alf <[email protected]>
26 */
27
28 #ifndef _APVLV_IMAGEWIDGET_H_
29 #define _APVLV_IMAGEWIDGET_H_
30
31 #include <QLabel>
32 #include <QMainWindow>
33 #include <QScrollArea>
34 #include <QVBoxLayout>
35
36 #include "ApvlvFileWidget.h"
37 #include "ApvlvUtil.h"
38 #ifdef APVLV_WITH_OCR
39 #include "ApvlvEditor.h"
40 #include "ApvlvOCR.h"
41 #endif
42
43 namespace apvlv
44 {
45
46 #ifdef APVLV_WITH_OCR
47 class TextContainer : public Editor
48 {
49 Q_OBJECT
50 public:
51 explicit TextContainer (QWidget *parent = nullptr);
52 ~TextContainer () override = default;
53 };
54 #endif
55
56 class ImageWidget;
57 class ImageContainer : public QLabel
58 {
59 Q_OBJECT
60 public:
61 explicit ImageContainer (QWidget *parent = nullptr);
62
63 void mousePressEvent (QMouseEvent *event) override;
64 void mouseMoveEvent (QMouseEvent *event) override;
65 void mouseReleaseEvent (QMouseEvent *event) override;
66
67 virtual bool renderImage (int pn, double zm, int rot);
68 virtual void redraw ();
69
70 void
71 setImageWidget (ImageWidget *image_widget)
72 {
73 mImageWidget = image_widget;
74 }
75
76 private:
77 bool mIsSelected{ false };
78
79 QPointF mPressPosition;
80 QPointF mMovePosition;
81
82 ImageWidget *mImageWidget{ nullptr };
83
84 friend class ImageWidget;
85
86 QImage mImage;
87 QAction mCopyAction;
88 QAction mUnderlineAction;
89 QAction mCommentAction;
90
91 std::pair<ApvlvPoint, ApvlvPoint> selectionRange ();
92 std::vector<Rectangle> selectionArea ();
93 std::string selectionText ();
94
95 private slots:
96 void copy ();
97 void underline ();
98 void comment ();
99 };
100
101 class ApvlvImage : public QScrollArea
102 {
103 Q_OBJECT
104 public:
105 ApvlvImage ();
106
107 ~ApvlvImage () override;
108
109 #ifdef APVLV_WITH_OCR
110 void ocrDisplay (bool replace);
111 std::unique_ptr<char> ocrGetText ();
112 #endif
113
114 private:
115 ImageContainer mImageContainer;
116 #ifdef APVLV_WITH_OCR
117 TextContainer mTextContainer;
118 OCR mOCR;
119 #endif
120
121 friend class ImageWidget;
122 };
123
124 class ImageWidget : public FileWidget
125 {
126 public:
127 ImageWidget ()
128 {
129 mImage.mImageContainer.setImageWidget (this);
130 mHalScrollBar = mImage.horizontalScrollBar ();
131 mValScrollBar = mImage.verticalScrollBar ();
132 }
133
134 [[nodiscard]] QWidget *
135 widget () override
136 {
137 return &mImage;
138 }
139
140 void showPage (int pn, double s) override;
141 void showPage (int pn, const std::string &anchor) override;
142
143 void setSearchResults (const WordListRectangle &wlr) override;
144 void setZoomrate (double zm) override;
145 void setRotate (int rotate) override;
146
147 private:
148 ApvlvImage mImage{};
149 };
150
151 bool imageSelectSearch (QImage *pix, double zm, int select,
152 const WordListRectangle &poses);
153
154 bool imageSelect (QImage *pix, double zm, const std::vector<Rectangle> &poses);
155
156 bool imageUnderline (QImage *pix, double zm,
157 const std::vector<Rectangle> &poses);
158
159 }
160
161 #endif
162
163 /* Local Variables: */
164 /* mode: c++ */
165 /* End: */