Debian Codegraph @

src/ApvlvFrame.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 ApvlvFrame.h
24 *
25 * Author: Alf <[email protected]>
26 */
27
28 #ifndef _APVLV_FRAME_H_
29 #define _APVLV_FRAME_H_
30
31 #include <QAction>
32 #include <QCheckBox>
33 #include <QFileSystemWatcher>
34 #include <QLabel>
35 #include <QSplitter>
36 #include <iostream>
37 #include <map>
38
39 #include "ApvlvCmds.h"
40 #include "ApvlvDirectory.h"
41 #include "ApvlvFile.h"
42 #include "ApvlvFileWidget.h"
43 #include "ApvlvWidget.h"
44
45 namespace apvlv
46 {
47
48 struct ApvlvDocPosition
49 {
50 int pagenum;
51 double scrollrate;
52 };
53
54 using ApvlvDocPositionMap = std::map<char, ApvlvDocPosition>;
55
56 struct ApvlvWord
57 {
58 CharRectangle pos;
59 std::string word;
60 };
61
62 struct ApvlvLine
63 {
64 CharRectangle pos;
65 std::vector<ApvlvWord> mWords;
66 };
67
68 class ApvlvFrame;
69 class ApvlvStatus : public QFrame
70 {
71 Q_OBJECT
72 public:
73 ApvlvStatus ();
74
75 ~ApvlvStatus () override = default;
76
77 void setActive (bool act);
78
79 void showMessages (const std::vector<std::string> &msgs);
80
81 private:
82 QHBoxLayout mLayout;
83 };
84
85 class ApvlvToolStatus : public QToolBar
86 {
87 Q_OBJECT
88 public:
89 explicit ApvlvToolStatus (ApvlvFrame *frame);
90
91 void updateValue (int pn, int totpn, double zm, double sr);
92
93 private:
94 ApvlvFrame *mFrame;
95
96 ApvlvLineEdit mPageValue;
97 QLabel mPageSum;
98 QLabel mScrollRate;
99
100 QComboBox mZoomType;
101 ApvlvLineEdit mZoomValue;
102
103 #ifdef APVLV_WITH_OCR
104 QCheckBox mOcrParse;
105 QAction mOcrCopy;
106 #endif
107
108 private slots:
109 void gotoPage ();
110
111 friend class ApvlvFrame;
112 };
113
114 const int DEFAULT_CONTENT_WIDTH = 300;
115
116 class FileWidget;
117 class ApvlvView;
118 class ApvlvFrame final : public QFrame
119 {
120 Q_OBJECT
121 public:
122 explicit ApvlvFrame (ApvlvView *view);
123
124 ~ApvlvFrame () override;
125
126 bool reload ();
127
128 void inuse (bool use);
129
130 bool inuse ();
131
132 ApvlvFrame *clone ();
133
134 void setDirIndex (const std::string &path);
135
136 bool loadFile (const std::string &file, bool check, bool show_directory);
137
138 bool loadUri (const std::string &uri);
139
140 const char *filename ();
141
142 int pageNumber ();
143
144 void showPage (int pn, double s);
145 void showPage (int pn, const std::string &anchor);
146 void refresh (int pn, double s);
147
148 void setActive (bool act);
149
150 void updateStatus ();
151
152 bool isStatusHidden ();
153
154 void statusShow ();
155
156 void statusHide ();
157
158 bool print (int ct);
159
160 bool totext (const char *name);
161
162 bool rotate (int ct);
163
164 void markposition (char s);
165
166 void setZoomrate (double zm);
167
168 void setZoomString (const char *z);
169
170 void jump (char s);
171
172 void nextPage (int times);
173
174 void previousPage (int times);
175
176 void halfNextPage (int times);
177
178 void halfPreviousPage (int times);
179
180 bool search (const char *str, bool reverse);
181
182 void gotoLink (int ct);
183
184 void returnLink (int ct);
185
186 bool loadLastPosition (const std::string &filename);
187 bool saveLastPosition (const std::string &filename);
188
189 void directoryShowPage (const FileIndex *index, bool force);
190
191 int getSkip ();
192 void setSkip (int ct);
193
194 void toggleDirectory ();
195
196 void toggleDirectory (bool enabled);
197
198 bool toggledControlDirectory (bool is_right);
199
200 bool isShowDirectory ();
201
202 bool isControlledDirectory ();
203
204 void wheelEvent (QWheelEvent *event) override;
205
206 CmdReturn process (int has, int times, uint keyval);
207
208 ApvlvView *mView;
209
210 void
211 focusInEvent (QFocusEvent *event) override
212 {
213 emit focusIn ();
214 }
215
216 static ApvlvFrame *findByWidget (QWidget *widget);
217
218 private:
219 std::unique_ptr<File> mFile;
220
221 FileIndex mDirIndex{};
222
223 bool mInuse;
224
225 std::unique_ptr<QFileSystemWatcher> mWatcher;
226
227 std::string mFilestr;
228
229 uint mProCmd;
230
231 char mSearchCmd{};
232 std::unique_ptr<WordListRectangle> mSearchResults;
233 std::string mSearchStr;
234
235 enum class ZoomMode
236 {
237 NORMAL,
238 FITWIDTH,
239 FITHEIGHT,
240 CUSTOM
241 };
242 ZoomMode mZoomMode;
243 static std::vector<const char *> ZoomLabel;
244
245 bool mZoominit{};
246
247 int mSkip{};
248
249 ApvlvDocPositionMap mPositions;
250
251 // the main menubar
252 QVBoxLayout mVbox;
253
254 // the main panel
255 QSplitter mPaned;
256 int mDirectoryWidth;
257
258 QHBoxLayout mHBoxLayout;
259
260 // directory panel
261 Directory mDirectory;
262
263 QFrame mTextFrame;
264 QVBoxLayout mTextLayout;
265 ApvlvToolStatus mToolStatus;
266 std::unique_ptr<FileWidget> mWidget;
267
268 // status bar
269 ApvlvStatus mStatus;
270
271 // if active
272 bool mActive{};
273
274 void setWidget (DISPLAY_TYPE type);
275 void unsetHighlight ();
276 void setHighlightAndIndex (const WordListRectangle &poses, int sel);
277 bool needSearch (const std::string &str, bool reverse);
278 CmdReturn subProcess (int ct, uint key);
279
280 signals:
281 void indexGenerited (const FileIndex &index);
282 void focusIn ();
283
284 private slots:
285 void previousPage ();
286 void nextPage ();
287 void setZoomMode (int mode);
288 void zoomIn ();
289 void zoomOut ();
290 #ifdef APVLV_WITH_OCR
291 void ocrParse ();
292 void ocrCopy ();
293 #endif
294
295 friend class ApvlvStats;
296 friend class ApvlvToolStatus;
297 };
298 }
299
300 #endif
301
302 /* Local Variables: */
303 /* mode: c++ */
304 /* End: */