summaryrefslogtreecommitdiffstats
path: root/src/bookwidget.h
blob: 8089b3d7921ad8b9d0f3ec855d04d6302c2308c8 (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
/***************************************************************************
*   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 <qwidget.h>
#include <qevent.h>
#include <qpixmap.h>
#include <qthread.h>
#include <qtimer.h>
#include <qfile.h>
#include <kurl.h>
#include <algorithm>
#include "renderer.h"
#include "bookmark.h"

class QStringList;
class QRect;
class KProgressDialog;


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

	virtual void openURL(const KURL & url);
	virtual QString currentURL();
	void paintEvent (QPaintEvent *);
	void setFont( const QFont & );
	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();
	QSize minimumSizeHint () const;
	void setupPageSize();
	void setEncoding(int);
	void setEncoding(const QString & a_encoding);
	void setEncodings(const QStringList & a_encodings);
	QString encoding() const { return m_encodings[m_encoding]; }
	//const TextThread * thread() const {return m_thread;}
	void addBookmark(const QString& 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 QString& text);

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

	void loaded(int);
	void loadingFinished();
protected:
	const QRect rectLeftPage() const;
	const QRect rectRightPage() const;
	void mousePressEvent(QMouseEvent *);
	void keyPressEvent (QKeyEvent * e);
	void resizeEvent (QResizeEvent * e);
	void wheelEvent (QWheelEvent * e);
	void clearAll();
	void drawContent(QPainter& paint);
	void drawPageNumbers(QPainter& paint);
	void drawBookmark(QPainter& 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;
	QPixmap 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;
	QFile m_file;
	QTimer m_timer;
	QStringList m_encodings;
	int m_encoding;
	std::auto_ptr<Renderer> m_renderer;
	std::auto_ptr<QTextStream> m_stream;
	std::auto_ptr<QStringList> m_textLines;
	std::auto_ptr<KProgressDialog> m_progressDlg;
	Bookmarks m_bookmarks;
};

#endif