-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfilebrowser.cpp
More file actions
45 lines (39 loc) · 1.01 KB
/
filebrowser.cpp
File metadata and controls
45 lines (39 loc) · 1.01 KB
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
#include "filebrowser.h"
FileBrowser::FileBrowser(QTextEdit *parent,QString fileName)
{
m_in = new QFile(fileName);
if (!m_in->open(QIODevice::ReadOnly)) {
QMessageBox::critical(m_qtb, tr("Error"), tr("Could not open file"));
return;
}
m_filename = fileName;
m_qtb = parent;
m_ts = new QTextStream(m_in);
m_qtb->setText(m_ts->read(m_browserReadSize));
m_nextPageTop=m_ts->pos();
}
FileBrowser::~FileBrowser()
{
delete m_ts;
m_in->close();
delete m_in;
}
void FileBrowser::pageDown()
{
m_qtb->setText(m_ts->read(m_browserReadSize));
setFPos();
}
void FileBrowser::setFPos()
{
m_nextPageTop = m_ts->pos();
m_prevPageTop = (m_nextPageTop - (2 * m_browserReadSize) > 0 ) ? m_nextPageTop - ( 2 * m_browserReadSize) : 0 ;
}
void FileBrowser::pageUp()
{
if (m_ts->seek(m_prevPageTop)) {
m_qtb->setText(m_ts->read(m_browserReadSize));
setFPos();
}else {
QMessageBox::critical(m_qtb, tr("Error"), tr("failed to page up "));
}
}