summaryrefslogtreecommitdiffstats
path: root/src/bookwidget.h
blob: 381cb47c3f427e3b7ac181761f21efe824840812 (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
/***************************************************************************
*   Copyright (C) 2005 by Alexander Nemish  *
*                                                                         *
*   This program is free software; you can redistribute it and/or modify  *
*   it under the terms of the GNU General Public License as published by  *
*   the Free Software Foundation; either version 2 of the License, or     *
*   (at your option) any later version.                                   *
*                                                                         *
*   This program is distributed in the hope that it will be useful,       *
*   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
*   GNU General Public License for more details.                          *
*                                                                         *
*   You should have received a copy of the GNU General Public License     *
*   along with this program; if not, write to the                         *
*   Free Software Foundation, Inc.,                                       *
*   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
***************************************************************************/
#ifndef BOOKWIDGET_H
#define BOOKWIDGET_H

#include <tqwidget.h>
#include <tqevent.h>
#include <tqpixmap.h>
#include <tqthread.h>
#include <tqtimer.h>
#include <tqfile.h>
#include <kurl.h>
#include <algorithm>
#include "renderer.h"
#include "bookmark.h"

class TQStringList;
class TQRect;
class KProgressDialog;


/**
 */
class BookWidget : public TQWidget
{
	Q_OBJECT
  TQ_OBJECT
public:
	
	
	BookWidget(TQWidget *parent = 0, const char *name = 0);
	~BookWidget();

	virtual void openURL(const KURL & url);
	virtual TQString currentURL();
	void paintEvent (TQPaintEvent *);
	void setFont( const TQFont & );
	void setParaOffset(int offset);
	void setCurrentPage(int number);
	int  currentPage() const { return m_currentPage; };
	int  pageCount() const { return m_renderer->pageCount(); }
	void nextPage();
	void prevPage();
	void firstPage();
	void lastPage();
	TQSize minimumSizeHint () const;
	void setupPageSize();
	void setEncoding(int);
	void setEncoding(const TQString & a_encoding);
	void setEncodings(const TQStringList & a_encodings);
	TQString encoding() const { return m_encodings[m_encoding]; }
	//const TextThread * thread() const {return m_thread;}
	void addBookmark(const TQString& name);
	void saveBookmarks();
	void loadBookmarks();
	void setBookmarks(const Bookmarks& bms);
	const Bookmarks & bookmarks() const { return m_bookmarks; }
signals:
	/**
	 * Use this signal to change the content of the statusbar
	 */
	void signalChangeStatusbar(const TQString& text);

	/**
	 * Use this signal to change the content of the caption
	 */
	void signalChangeCaption(const TQString& text);

	void loaded(int);
	void loadingFinished();
protected:
	const TQRect rectLeftPage() const;
	const TQRect rectRightPage() const;
	void mousePressEvent(TQMouseEvent *);
	void keyPressEvent (TQKeyEvent * e);
	void resizeEvent (TQResizeEvent * e);
	void wheelEvent (TQWheelEvent * e);
	void clearAll();
	void drawContent(TQPainter& paint);
	void drawPageNumbers(TQPainter& paint);
	void drawBookmark(TQPainter& paint, Bookmark const& bm);
	bool modified() const { return m_modified; };

private slots:
	void loadLine();
	void cancelLoading();
	void renderingFinished();
	
private:
	KURL	m_url;
	bool m_modified;
	TQPixmap m_cachePixmap;
	int m_currentPage;
	int m_left_margin;
	int m_right_margin;
	int m_top_margin;
	int m_bottom_margin;
	int m_middle_margin;
	TQFile m_file;
	TQTimer m_timer;
	TQStringList m_encodings;
	int m_encoding;
	std::auto_ptr<Renderer> m_renderer;
	std::auto_ptr<TQTextStream> m_stream;
	std::auto_ptr<TQStringList> m_textLines;
	std::auto_ptr<KProgressDialog> m_progressDlg;
	Bookmarks m_bookmarks;
};

#endif