Debian Codegraph @

src/ApvlvFileWidget.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 ApvlvFileWidget.h
24 *
25 * Author: Alf <[email protected]>
26 */
27
28 #ifndef _APVLV_FILE_WIDGET_H_
29 #define _APVLV_FILE_WIDGET_H_
30
31 #include <QScrollBar>
32 #include <string>
33
34 #include "ApvlvFile.h"
35
36 namespace apvlv
37 {
38
39 const int WORD_WIDTH_DEFAULT = 40;
40 const int LINE_HEIGHT_DEFAULT = 15;
41
42 const double DEFAULT_ZOOMRATE = 1.3f;
43 const int INVALID_PAGENUM = -1;
44
45 class File;
46 class FileWidget : public QObject
47 {
48 Q_OBJECT
49 public:
50 FileWidget () = default;
51
52 ~FileWidget () override = default;
53
54 [[nodiscard]] virtual QWidget *widget () = 0;
55
56 [[nodiscard]] virtual File *
57 file () const
58 {
59 return mFile;
60 }
61
62 virtual void
63 setFile (File *file)
64 {
65 mFile = file;
66 }
67
68 virtual int
69 pageNumber ()
70 {
71 return mPageNumber;
72 }
73
74 virtual std::string
75 anchor ()
76 {
77 return mAnchor;
78 }
79
80 virtual double
81 zoomrate ()
82 {
83 return mZoomrate;
84 }
85
86 virtual void
87 showPage (int pn, double rate)
88 {
89 mPageNumber = pn;
90 mScrollValue = rate;
91 }
92
93 virtual void
94 showPage (int pn, const std::string &anchor)
95 {
96 mPageNumber = pn;
97 mAnchor = anchor;
98 }
99
100 virtual void scroll (int times, int w, int h);
101
102 virtual double scrollRate ();
103
104 virtual void scrollTo (double s, double y);
105
106 virtual void scrollUp (int times);
107
108 virtual void scrollDown (int times);
109
110 virtual void scrollLeft (int times);
111
112 virtual void scrollRight (int times);
113
114 virtual void
115 setZoomrate (double zm)
116 {
117 mZoomrate = zm;
118 }
119
120 virtual void
121 setRotate (int rot)
122 {
123 mRotate = rot;
124 }
125
126 virtual int
127 rotate ()
128 {
129 return mRotate;
130 }
131
132 void
133 setAnchor (const std::string &anchor)
134 {
135 mAnchor = anchor;
136 }
137
138 virtual void
139 setSearchSelect (int select)
140 {
141 mSearchSelect = select;
142 }
143
144 [[nodiscard]] virtual int
145 searchSelect () const
146 {
147 return mSearchSelect;
148 }
149
150 virtual void
151 setSearchStr (const std::string &str)
152 {
153 mSearchStr = str;
154 }
155
156 [[nodiscard]] virtual std::string
157 searchStr () const
158 {
159 return mSearchStr;
160 }
161
162 virtual void
163 setSearchResults (const WordListRectangle &wlr)
164 {
165 mSearchResults = wlr;
166 }
167
168 virtual const WordListRectangle &
169 searchResults ()
170 {
171 return mSearchResults;
172 }
173
174 virtual void
175 setSelects (const std::vector<Rectangle> &rect_list)
176 {
177 mSelects = rect_list;
178 }
179
180 virtual const std::vector<Rectangle> &
181 selects ()
182 {
183 return mSelects;
184 }
185
186 protected:
187 QScrollBar *mValScrollBar{ nullptr };
188 QScrollBar *mHalScrollBar{ nullptr };
189
190 File *mFile{ nullptr };
191
192 int mPageNumber{ INVALID_PAGENUM };
193 double mScrollValue{ 0.0f };
194 std::string mAnchor;
195 double mZoomrate{ DEFAULT_ZOOMRATE };
196 int mRotate{ 0 };
197
198 std::string mSearchStr;
199 WordListRectangle mSearchResults;
200 int mSearchSelect{ 0 };
201
202 std::vector<Rectangle> mSelects;
203 };
204 }
205
206 #endif
207
208 /* Local Variables: */
209 /* mode: c++ */
210 /* End: */