2013-02-13 05:05:35 +05:30
|
|
|
#include "browserdialog.h"
|
|
|
|
#include "ui_browserdialog.h"
|
|
|
|
|
|
|
|
#include <QtWebKit/QWebHistory>
|
|
|
|
|
|
|
|
BrowserDialog::BrowserDialog(QWidget *parent) :
|
|
|
|
QDialog(parent),
|
|
|
|
ui(new Ui::BrowserDialog),
|
|
|
|
m_pageTitleInWindowTitle(true),
|
|
|
|
m_windowTitleFormat("%1")
|
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
|
|
|
ui->webView->setPage(new QWebPage());
|
|
|
|
refreshWindowTitle();
|
|
|
|
resize(800, 600);
|
|
|
|
}
|
|
|
|
|
|
|
|
BrowserDialog::~BrowserDialog()
|
|
|
|
{
|
|
|
|
delete ui;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Navigation Buttons
|
|
|
|
void BrowserDialog::on_btnBack_clicked()
|
|
|
|
{
|
|
|
|
ui->webView->back();
|
|
|
|
}
|
|
|
|
|
|
|
|
void BrowserDialog::on_btnForward_clicked()
|
|
|
|
{
|
|
|
|
ui->webView->forward();
|
|
|
|
}
|
|
|
|
|
|
|
|
void BrowserDialog::on_webView_urlChanged(const QUrl &url)
|
|
|
|
{
|
|
|
|
Q_UNUSED(url);
|
2013-02-13 08:33:15 +05:30
|
|
|
//qDebug("urlChanged");
|
2013-02-13 05:05:35 +05:30
|
|
|
ui->btnBack->setEnabled(ui->webView->history()->canGoBack());
|
|
|
|
ui->btnForward->setEnabled(ui->webView->history()->canGoForward());
|
|
|
|
}
|
|
|
|
|
|
|
|
// Window Title Magic
|
|
|
|
void BrowserDialog::refreshWindowTitle()
|
|
|
|
{
|
2013-02-13 08:33:15 +05:30
|
|
|
//qDebug("refreshTitle");
|
2013-02-13 05:05:35 +05:30
|
|
|
if (m_pageTitleInWindowTitle)
|
|
|
|
setWindowTitle(m_windowTitleFormat.arg(ui->webView->title()));
|
|
|
|
else
|
|
|
|
setWindowTitle(m_windowTitleFormat);
|
|
|
|
}
|
|
|
|
|
|
|
|
void BrowserDialog::setPageTitleInWindowTitle(bool enable)
|
|
|
|
{
|
|
|
|
m_pageTitleInWindowTitle = enable;
|
|
|
|
refreshWindowTitle();
|
|
|
|
}
|
|
|
|
|
|
|
|
void BrowserDialog::setWindowTitleFormat(QString format)
|
|
|
|
{
|
|
|
|
m_windowTitleFormat = format;
|
|
|
|
refreshWindowTitle();
|
|
|
|
}
|
|
|
|
|
|
|
|
void BrowserDialog::on_webView_titleChanged(const QString &title)
|
|
|
|
{
|
2013-02-13 08:33:15 +05:30
|
|
|
//qDebug("titleChanged");
|
2013-02-13 05:05:35 +05:30
|
|
|
if (m_pageTitleInWindowTitle)
|
|
|
|
setWindowTitle(m_windowTitleFormat.arg(title));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Public access Methods
|
|
|
|
void BrowserDialog::load(const QUrl &url)
|
|
|
|
{
|
2013-02-13 08:33:15 +05:30
|
|
|
//qDebug("load");
|
2013-02-13 05:05:35 +05:30
|
|
|
ui->webView->setUrl(url);
|
|
|
|
}
|