Debian Codegraph @

src/ApvlvView.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 ApvlvView.h
24 *
25 * Author: Alf <[email protected]>
26 */
27
28 #ifndef _APVLV_VIEW_H_
29 #define _APVLV_VIEW_H_
30
31 #include <QLineEdit>
32 #include <QMainWindow>
33 #include <QMenuBar>
34 #include <QTabWidget>
35 #include <QVBoxLayout>
36 #include <iosfwd>
37 #include <iostream>
38 #include <sstream>
39 #include <string_view>
40
41 #include "ApvlvCmds.h"
42 #include "ApvlvCompletion.h"
43 #include "ApvlvFrame.h"
44 #include "ApvlvSearchDialog.h"
45 #include "ApvlvWindow.h"
46
47 namespace apvlv
48 {
49
50 namespace CommandModeType
51 {
52 const char SEARCH = '/';
53 const char BACKSEARCH = '?';
54 const char COMMANDMODE = ':';
55 const char FIND = 'F';
56 }
57
58 class ApvlvFrame;
59 class ApvlvWindow;
60
61 class ApvlvCommandBar : public QLineEdit
62 {
63 Q_OBJECT
64 public:
65 ApvlvCommandBar () { installEventFilter (this); };
66
67 protected:
68 void keyPressEvent (QKeyEvent *evt) override;
69 bool eventFilter (QObject *obj, QEvent *event) override;
70
71 signals:
72 void keyPressed (QKeyEvent *evt);
73 };
74
75 class ApvlvView final : public QMainWindow
76 {
77 Q_OBJECT
78 public:
79 explicit ApvlvView (ApvlvView *view = nullptr);
80
81 ~ApvlvView () override;
82
83 ApvlvWindow *currentWindow ();
84
85 void delCurrentWindow ();
86
87 bool newTab (const std::string &filename);
88
89 bool newTab (ApvlvFrame *core);
90
91 void promptCommand (char ch);
92
93 void promptCommand (const char *str);
94
95 template <typename... T>
96 void
97 errorMessage (T... args)
98 {
99 std::stringstream msg;
100 msg << "ERROR: ";
101 msg << (... + args);
102 mCommandBar.setText (QString::fromLocal8Bit (msg.str ()));
103 cmdShow (CmdStatusType::CMD_MESSAGE);
104 }
105
106 static char *input (const char *str, int width = 400, int height = 150,
107 const std::string &content = "");
108
109 bool run (const char *str);
110
111 bool loadFile (const std::string &filename);
112
113 bool loadDir (const std::string &path);
114
115 std::optional<ApvlvFrame *> hasLoaded (std::string_view abpath);
116
117 void regLoaded (ApvlvFrame *doc);
118
119 CmdReturn process (int hastimes, int times, uint keyval);
120
121 CmdReturn subProcess (int times, uint keyval);
122
123 void cmdShow (CmdStatusType cmdtype);
124
125 void cmdHide ();
126
127 void cmdAuto (const char *str);
128
129 void setTitle (const std::string &title);
130
131 ApvlvFrame *currentFrame ();
132
133 void appendChild (ApvlvView *view);
134
135 void eraseChild (ApvlvView *view);
136
137 public slots:
138 void loadFileOnPage (const std::string &filename, int pn);
139
140 void open ();
141
142 void openDir ();
143
144 void openRrl ();
145
146 void quit (bool only_tab = true);
147
148 void search ();
149
150 void backSearch ();
151
152 void advancedSearch ();
153
154 void dired ();
155
156 void fullScreen ();
157
158 void nextPage ();
159
160 void previousPage ();
161
162 void toggleDirectory ();
163
164 void toggleToolBar ();
165
166 void toggleStatus ();
167
168 void newTab ();
169
170 void closeTab ();
171
172 void horizontalSplit ();
173
174 void verticalSplit ();
175
176 void unBirth ();
177
178 private:
179 void setupMenuBar (const std::string &guiopt);
180
181 void setupToolBar ();
182
183 bool runCommand (const char *cmd);
184
185 void switchTab (int tabPos);
186
187 // Update the tab's context and update tab label.
188 void windowAdded ();
189
190 void updateTabName ();
191
192 CmdStatusType mCmdType;
193 std::chrono::time_point<std::chrono::steady_clock> mCmdTime;
194
195 uint mProCmd;
196 int mProCmdCnt;
197
198 QFrame mCentral;
199 QVBoxLayout mVBoxLayout;
200
201 QTabWidget mTabContainer;
202 ApvlvCommandBar mCommandBar;
203
204 QMenuBar mMenuBar;
205 QToolBar mToolBar;
206
207 bool mHasFull;
208
209 struct keyNode
210 {
211 ;
212 int Has;
213 int Ct;
214 uint Key;
215 bool End;
216 };
217 bool keyLastEnd;
218 bool processInLast;
219 std::vector<keyNode> keySquence;
220
221 void saveKey (int has, int ct, uint key, bool end);
222
223 void processLastKey ();
224
225 void closeEvent (QCloseEvent *evt) override;
226 void keyPressEvent (QKeyEvent *evt) override;
227
228 ApvlvCmds mCmds;
229
230 SearchDialog mSearchDialog;
231
232 std::vector<std::unique_ptr<ApvlvFrame>> mDocs;
233
234 std::vector<std::string> mCmdHistroy;
235 size_t mCurrHistroy;
236
237 ApvlvView *mParent;
238 std::vector<ApvlvView *> mChildren;
239
240 private slots:
241 void commandbarEdited (const QString &str);
242 void commandbarReturn ();
243 void commandbarKeyPressed (QKeyEvent *gek);
244 void tabSwitched (int ind);
245 };
246
247 }
248
249 #endif
250
251 /* Local Variables: */
252 /* mode: c++ */
253 /* End: */