/* Marcion
Copyright (C) 2009-2013 Milan Konvicka
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.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */
#include "htmlreader.h"
#include "ui_htmlreader.h"
CHtmlReader::CHtmlReader(QWidget *parent) :
QWidget(parent),
MDocumentBase(MDocumentBase::Html),
ui(new Ui::CHtmlReader),
_home()
{
ui->setupUi(this);
}
CHtmlReader::CHtmlReader(QString const & title,
QString const & filename,
CBookTextBrowser::Script script,
QString const & show_text,
QWidget *parent) :
QWidget(parent),
MDocumentBase(MDocumentBase::Html),
ui(new Ui::CHtmlReader),
_home(QUrl::fromLocalFile(filename))
{
ui->setupUi(this);
ui->btNext->setEnabled(false);
ui->btPrev->setEnabled(false);
ui->brContent->init(title,script,false);
ui->brContent->browser()->setOpenLinks(true);
ui->brContent->browser()->setOpenExternalLinks(false);
ui->brContent->allowChangeScript();
goHome();
if(!show_text.isEmpty())
{
ui->brContent->setPanelVisibility(true);
ui->brContent->inputBox().setText(show_text);
}
IC_SIZES
}
CHtmlReader::~CHtmlReader()
{
delete ui;
}
void CHtmlReader::init(QString const & title,QString const & filename,
CBookTextBrowser::Script script,
QString const & show_text,
bool allow_font)
{
_home=QUrl::fromLocalFile(filename);
ui->btNext->setEnabled(false);
ui->btPrev->setEnabled(false);
ui->brContent->init(title,script,allow_font);
ui->brContent->browser()->setOpenLinks(true);
ui->brContent->browser()->setOpenExternalLinks(false);
ui->brContent->allowChangeScript();
goHome();
if(!show_text.isEmpty())
{
ui->brContent->setPanelVisibility(true);
ui->brContent->inputBox().setText(show_text);
}
}
/*void CHtmlReader::changeEvent(QEvent *e)
{
QWidget::changeEvent(e);
switch (e->type()) {
case QEvent::LanguageChange:
ui->retranslateUi(this);
break;
default:
break;
}
}*/
void CHtmlReader::goHome()
{
loadPage(_home);
}
void CHtmlReader::loadPage(QUrl const & u)
{
QUrl u1(u),u2(ui->brContent->browser()->source());
u1.setFragment(QString::null);
u2.setFragment(QString::null);
if(u1!=u2)
{
m_msg()->MsgMsg(tr("opening page ")+u.toString()+" ...");
ui->brContent->browser()->setSource(u);
}
else
ui->brContent->browser()->moveCursor(QTextCursor::Start);
}
void CHtmlReader::on_btHome_clicked()
{
ui->brContent->showPage(CTextBrowserExt::Text);
goHome();
}
void CHtmlReader::on_btPrev_clicked()
{
ui->brContent->showPage(CTextBrowserExt::Text);
ui->brContent->browser()->backward();
//ui->brContent->setOrigText();
}
void CHtmlReader::on_btNext_clicked()
{
ui->brContent->showPage(CTextBrowserExt::Text);
ui->brContent->browser()->forward();
//ui->brContent->setOrigText();
}
void CHtmlReader::on_btShowPanel_clicked()
{
ui->brContent->showPage(CTextBrowserExt::Text);
ui->brContent->setPanelVisibility(true);
}
void CHtmlReader::on_btZoomIn_clicked()
{
ui->brContent->showPage(CTextBrowserExt::Text);
ui->brContent->browser()->zoomIn(1);
}
void CHtmlReader::on_btZoomOut_clicked()
{
ui->brContent->showPage(CTextBrowserExt::Text);
ui->brContent->browser()->zoomOut(1);
}
CTextBrowserExt * CHtmlReader::browser()
{
return ui->brContent;
}
void CHtmlReader::on_btReload_clicked()
{
ui->brContent->showPage(CTextBrowserExt::Text);
ui->brContent->beforeReload();
ui->brContent->browser()->reload();
}
void CHtmlReader::on_brContent_historyFBChanged(int direction,bool available)
{
switch(direction)
{
case CBookTextBrowser::Forward :
ui->btNext->setEnabled(available);
break;
case CBookTextBrowser::Backward :
ui->btPrev->setEnabled(available);
break;
}
}
void CHtmlReader::keyPressEvent(QKeyEvent * event)
{
event->ignore();
ui->brContent->keyPressEvent(event);
if(!event->isAccepted())
QWidget::keyPressEvent(event);
}