summaryrefslogtreecommitdiff
path: root/noncore/apps/opie-reader/QTReaderApp.h
blob: ab1b7ad7308e2590e7969be3bd29fd9484ed2779 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
/**********************************************************************
** Copyright (C) 2000 Trolltech AS.  All rights reserved.
**
** This file is part of Qt Palmtop Environment.
**
** This file may be distributed and/or modified under the terms of the
** GNU General Public License version 2 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.trolltech.com/gpl/ for GPL licensing information.
**
** Contact info@trolltech.com if any conditions of this licensing are
** not clear to you.
**
**********************************************************************/
#ifndef __QTREADERAPP_H
#define __QTREADERAPP_H

//#define _SCROLLPIPE
//#define __ISEARCH

//#define MAX_ENCODING 6
#define MAX_ACTIONS 5

#include <sys/timeb.h>
#include <qmainwindow.h>
#include "CExpander.h"
#include "CEncoding.h"
#include <qlist.h>
//#include <qpe/filemanager.h>
#include <qmap.h>
#include <qlineedit.h>
#include <qstack.h>
#include <qlistbox.h>
#ifdef USEQPE
#include <qpe/qpeapplication.h>
#endif
#include "orkey.h"
//#include "Queue.h"
#include "BGType.h"

class QBoxLayout;
class QWidgetStack;
class QToolButton;
class QPopupMenu;
class QToolBar;
#ifdef USEQPE
class QPEToolBar;
class QPEMenuBar;
#endif
class QScrollBar;
class CBkmkSelector;
class QProgressBar;
class QAction;
class CAnnoEdit;
class QFloatBar;
class CDrawBuffer;
class QTReader;
class QImage;
class Config;
class CButtonPrefs;

#ifdef USEQPE
enum ToolbarPolicy
{
    cesSingle = 0,
    cesMenuTool,
    cesMultiple
};
#else
enum ToolbarPolicy
{
    cesMenuTool = 0,
    cesMultiple
};
#endif

enum regedit_type
{
    cAutoGen,
    cAddBkmk,
    cJump,
    cMonoSpace,
    cSetTarget,
#ifdef _SCROLLPIPE
    cSetPipeTarget,
#endif
    cSetConfigName,
    cMargin,
    cExtraSpace,
    cExtraLead,
    cRepara
};

enum bkmk_action
{
    cOpenFile,
    cGotoBkmk,
    cDelBkmk,
    cRmBkmkFile,
    cLdConfig,
    cRmConfig,
    cExportLinks,
    cLdTheme
};

enum fontselector_action
{
    cChooseFont,
    cChooseEncoding
};

#ifdef __ISEARCH
struct searchrecord
{
  QString s;
  size_t pos;
  searchrecord(const QString& _s, size_t _pos) : s(_s), pos(_pos) {}
};
#endif

class infowin;
class GraphicWin;

class QTReaderApp : public QMainWindow
{
    Q_OBJECT

      QColor getcolour(int c);

      QMap<orKey, int> kmap;
    unsigned long m_savedpos;
    int m_debounce;
    bool m_kmapchanged;
    bground m_bgtype;
    timeb m_lastkeytime;
    QScrollBar* m_scrollbar;
    QScrollBar* scrollbar;
    int m_qtscroll, m_localscroll;
    bool m_hidebars, m_scrollishidden, m_statusishidden;
    QBoxLayout *m_layout;
    QLabel* m_prog;
    bool m_annoIsEditing;
    bool m_propogatefontchange, m_bFloatingDialog;
    bool m_url_clipboard, m_url_localfile, m_url_globalfile;
    CButtonPrefs* m_buttonprefs;
    fontselector_action m_fontAction;
    void doAction(QKeyEvent* e);

	public:
    QTReaderApp( QWidget *parent = 0, const char *name = 0, WFlags f = 0 );
    ~QTReaderApp();

    void hideEvent(QHideEvent*)
	{
#ifdef USEQPE
	if (m_grabkeyboard)
	  {
	    ((QPEApplication*)qApp)->ungrabKeyboard();
	  }
#endif
	    suspend();
	}
#ifdef USEQPE
    void showEvent(QShowEvent*)
      {
	if (m_grabkeyboard)
	  {
	    ((QPEApplication*)qApp)->grabKeyboard();
	  }
      }
#endif
    void suspend();
    void openFile( const QString &, unsigned int loc = 0 );


 protected:
    void setfontHelper(const QString& lcn, int size = 0);
    QAction* m_bkmkAvail, *m_actFullscreen;
    CAnnoEdit* m_annoWin;
    Bkmk* m_anno;
    int m_scrollcolor, m_scrollbarcolor, m_background, m_foreground;
//    void resizeEvent(QResizeEvent* e);
    void closeEvent( QCloseEvent *e );
#if defined(USEQPE) && defined(USENEWFULLSCREEN)
    bool m_usenewfullscreen;
    void resizeEvent(QResizeEvent *);
    void focusInEvent(QFocusEvent*);
#endif
	void readbkmks();
	void do_mono(const QString&);
	void do_jump(const QString&);
	void do_reparastring(const QString&);
	void do_settarget(const QString&);
#ifdef _SCROLLPIPE
//	void do_setpipetarget(const QString&);
#endif
	void do_saveconfig(const QString&, bool);
	bool readconfig(const QString&, const QString&, bool);
	bool PopulateConfig(const char*, bool usedirs = false);
	ActionTypes ActNameToInt(const QString&);
#ifdef USEQPE
	bool m_grabkeyboard;
#endif
    bool m_doAnnotation;
    bool m_doDictionary;
    bool m_doOutput;
    bool m_doClipboard;
    bool m_fullscreen;
    bool m_loadedconfig;
 public:
	void saveprefs();
public slots:
      void setBackgroundBitmap();
  void UpdateStatus();
    void setScrollState(bool _b);
    void handlekey(QKeyEvent* e);
      void forceopen(const QString& filename);
    void setDocument(const QString&);
private slots:
#ifdef _SCRIPT
//    void RunScript();
#endif
  void actionscroll(int v);
    void SaveConfig();
 void LoadTheme();
 void LoadConfig();
 void TidyConfig();
 void ExportLinks();
    void zoomin();
    void zoomout();
    void chooseencoding();
    void setfullscreen(bool sfs);
    void setrotated(bool sfs);
    void setinverted(bool sfs);
    void setgrab(bool sfs);
//    void setcontinuous(bool sfs);
    void setTwoTouch(bool _b);
 void restoreFocus();
 void OnAnnotation(bool _b)
	{
	    m_doAnnotation = _b;
	}
    void OnDictionary(bool _b)
	{
	    m_doDictionary = _b;
	}
    void OnClipboard(bool _b)
	{
	    m_doClipboard = _b;
	}
    void OnWordSelected(const QString&, size_t, size_t, const QString&);
    void OnURLSelected(const QString& href, const size_t tgt);
    void showgraphic(QImage&);
    void addAnno(const QString&, const QString&, size_t, size_t);
    void addAnno(const QString&, const QString&);
    void addanno();
    void showAnnotation();
    void do_setencoding(int i);
	void do_setfont(const QString&);
	//	void buttonActionSelected(QAction*);
	void msgHandler(const QCString&, const QByteArray&);
	void monospace(bool);
	void jump();
	void reparastring();
	void settarget();
#ifdef _SCROLLPIPE
//	void setpipetarget();
//	void setpause(bool);
#endif
//	void setspacing();
	void setfont();
	void clearBkmkList();
	void listBkmkFiles();
	void editMark();
	void autoScroll(bool);
	void addbkmk();
	void savebkmks();
//	void importFiles();
	void showprefs();
	void showtoolbarprefs();
	void showbuttonprefs();
	void infoClose();
	//    void oldFile();
	void showinfo();

//    void indentplus();
//    void indentminus();

    void fileOpen();
    void fileClose();

    void editCopy();
    void editFind();

    void gotoStart();
    void gotoEnd();

    void pageup();
    void pagedn();

    void findNext();
    void findClose();

    void regClose();

#ifdef __ISEARCH
//  void search( const QString& );
#else
    void search();
#endif

    void showEditTools();

//    void stripcr(bool);
//    void setfulljust(bool);
//    void onespace(bool);
//    void repalm(bool);
//    void peanut(bool _b);
//    void remap(bool);
//    void embolden(bool);
//    void autofmt(bool);
//    void textfmt(bool);
//    void striphtml(bool);
//    void dehyphen(bool);
//    void depluck(bool);
//    void dejpluck(bool);
//    void unindent(bool);
//    void repara(bool);
//    void dblspce(bool);
    void pagemode(bool);
    //  void gotobkmk(const QString& bm);
    void gotobkmk(int);
    void cancelbkmk();
    void do_gotomark();
    void do_delmark();
    void do_autogen();
    void do_regaction();
    void OnRedraw();

 private:
    void setscrollcolour();
    void setscrollbarcolour();
    void writeUrl(const QString& file, const QString& href);
    QAction *m_preferences_action, *m_open_action, *m_close_action;
    QAction *m_info_action, *m_touch_action, *m_find_action, *m_start_action;
    QAction *m_end_action, *m_jump_action, *m_pageline_action;
    QAction *m_pageup_action, *m_pagedn_action, *m_back_action;
    QAction *m_home_action, *m_forward_action, *m_zoomin_action;
    QAction *m_zoomout_action, *m_setfont_action, *m_mark_action;
    QAction *m_annotate_action, *m_goto_action, *m_delete_action;
    QAction *m_autogen_action, *m_clear_action, *m_save_action;
    QAction *m_tidy_action, *m_startBlock_action, *m_endBlock_action;
    QAction *m_setenc_action, *m_setmono_action, *m_saveconfig_action;
    QAction *m_loadconfig_action, *m_loadtheme_action, *m_toolbarprefs_action, *m_tidyconfig_action;
    QAction *m_exportlinks_action, *m_rotate_action, *m_buttonprefs_action, *m_inverse_action;
    QAction *m_repara_action;
#ifdef USEQPE
    QAction *m_grab_action;
#endif
    void addtoolbars(Config* config);
    ToolbarPolicy m_tbpol, m_tbpolsave;
    ToolBarDock m_tbposition;
    bool m_tbmove, m_tbmovesave;
    QToolBar* filebar();
    QToolBar* viewbar();
    QToolBar* navbar();
    QToolBar* markbar();
    void hidetoolbars();
    void addfilebar(Config* _config, const QString& key, QAction* a);
    void addviewbar(Config* _config, const QString& key, QAction* a);
    void addnavbar(Config* _config, const QString& key, QAction* a);
    void addmarkbar(Config* _config, const QString& key, QAction* a);
    bool checkbar(Config* _config, const QString& key);
#ifdef _SCRIPT
    void SaveScript(const char* sname);
#endif
/*
    void setstate(unsigned char* _sd, unsigned short _sdlen);
    void getstate(unsigned char*& data, unsigned short& len);
*/
    void fileOpen2();
    void readfilelist();
    void savefilelist();
    void updatefileinfo();
    bool openfrombkmk(Bkmk*);
  QString m_targetapp, m_targetmsg, m_statusstring, m_themename;
    bool listbkmk(CList<Bkmk>*, const QString& _lab = QString::null, bool presel=false);
    QString usefilebrowser();
    void do_regedit();
    void colorChanged( const QColor &c );
    void clear();
    void updateCaption();
    void do_autogen(const QString&);
    void do_addbkmk(const QString&);
    bool findNextBookmark(size_t start);

 private:

    QAction* m_scrollButton;

    QAction* m_buttonAction[MAX_ACTIONS];

    CBkmkSelector* bkmkselector;

    //    ActionTypes m_spaceTarget, m_escapeTarget, m_returnTarget, m_leftTarget, m_rightTarget,
    //m_upTarget, m_downTarget;
    //bool m_leftScroll, m_rightScroll, m_upScroll, m_downScroll;
    bool m_bcloseDisabled, m_disableesckey;
    size_t searchStart;
#ifdef __ISEARCH
    QStack<searchrecord>* searchStack;
    bool dosearch(size_t start, CDrawBuffer& test, const QString& arg);
#else
    bool dosearch(size_t start, CDrawBuffer& test, const QRegExp& arg);
#endif
    QWidgetStack *editorStack;
    QTReader* reader;
    QComboBox* m_fontSelector;
//    QPEToolBar /* *menu,*/ *fileBar;
#if defined(USEQPE)
    QToolBar *menubar;
#endif
    QToolBar *fileBar, *navBar, *viewBar, *markBar;
#if defined(USEQPE)
    QPEMenuBar *mb;
#else
    QMenuBar *mb;
#endif
    QFloatBar *searchBar, *regBar/*, *m_fontBar*/;
    QToolBar /* *searchBar, *regBar,*/ *m_fontBar;
    QLineEdit *searchEdit, *regEdit;
    bool searchVisible;
    bool regVisible;
    bool m_fontVisible, m_twoTouch;
    static unsigned long m_uid;
    long unsigned get_unique_id() { return m_uid++; }
    /*
      void resizeEvent( QResizeEvent * r)
      {
//      qDebug("resize:(%u,%u)", r->oldSize().width(), r->oldSize().height());
//      qDebug("resize:(%u,%u)", r->size().width(), r->size().height());
      //    bgroup->move( width()-bgroup->width(), 0 );
      }
    */
    CList<Bkmk>* pBkmklist;
    CList<Bkmk>* pOpenlist;
    infowin*  m_infoWin;
    GraphicWin* m_graphicwin;
    QProgressBar* pbar;
    bool m_fBkmksChanged;
//    int m_nRegAction;
    regedit_type m_nRegAction;
    bkmk_action m_nBkmkAction;
    QString m_autogenstr;
    bool m_dontSave;
};

//const int cAutoGen = 0;
//const int cAddBkmk = 1;
//const int cDelBkmk = 2;
//const int cGotoBkmk = 3;
//const int cRmBkmkFile = 4;
//const int cJump = 5;
//const int cMonoSpace = 6;
//const int cOverlap = 7;
//const int cSetTarget = 8;
//const int cOpenFile = 9;
//const int cSetPipeTarget = 10;
//const int cSetConfigName = 11;
//const int cMargin = 12;
//const int cExtraSpace = 14;
//const int cExtraLead = 15;
//const int cGfxSize = 16;
//const int cChooseFont = 2;
//const int cChooseEncoding = 1;

#endif