summaryrefslogtreecommitdiffstats
path: root/gui/browserdialog.cpp
blob: 40c50c3fe5f737ab08780cbb7e02ce4c0f4ea807 (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
#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);
    //qDebug("urlChanged");
    ui->btnBack->setEnabled(ui->webView->history()->canGoBack());
    ui->btnForward->setEnabled(ui->webView->history()->canGoForward());
}

// Window Title Magic
void BrowserDialog::refreshWindowTitle()
{
    //qDebug("refreshTitle");
    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)
{
    //qDebug("titleChanged");
    if (m_pageTitleInWindowTitle)
        setWindowTitle(m_windowTitleFormat.arg(title));
}

// Public access Methods
void BrowserDialog::load(const QUrl &url)
{
    //qDebug("load");
    ui->webView->setUrl(url);
}