Replaced WebView with a custom BrowserWidget
Added browser navigation buttons and url textbox FossilOrigin-Name: 4914092dd81da4678e5aa76e8c8a15bc7cb1e146
This commit is contained in:
73
src/BrowserWidget.cpp
Normal file
73
src/BrowserWidget.cpp
Normal file
@ -0,0 +1,73 @@
|
||||
#include <QLineEdit>
|
||||
#include "BrowserWidget.h"
|
||||
#include "ui_BrowserWidget.h"
|
||||
|
||||
BrowserWidget::BrowserWidget(QWidget *parent) :
|
||||
QWidget(parent),
|
||||
loading(false)
|
||||
{
|
||||
ui = new Ui::BrowserWidget;
|
||||
ui->setupUi(this);
|
||||
ui->toolBar->addWidget(ui->txtUrl);
|
||||
connect(ui->txtUrl, SIGNAL(returnPressed()), this, SLOT(on_txtUrl_returnPressed()) );
|
||||
ui->actionBrowserStop->setVisible(false);
|
||||
}
|
||||
|
||||
BrowserWidget::~BrowserWidget()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void BrowserWidget::load(const QUrl &url)
|
||||
{
|
||||
ui->webView->load(url);
|
||||
}
|
||||
|
||||
void BrowserWidget::on_webView_urlChanged(const QUrl &url)
|
||||
{
|
||||
ui->txtUrl->setText(url.toString());
|
||||
}
|
||||
|
||||
void BrowserWidget::on_webView_loadStarted()
|
||||
{
|
||||
loading=true;
|
||||
ui->actionBrowserRefresh->setVisible(false);
|
||||
ui->actionBrowserStop->setVisible(true);
|
||||
}
|
||||
|
||||
void BrowserWidget::on_webView_loadFinished(bool /*errorOccured*/)
|
||||
{
|
||||
loading=false;
|
||||
ui->actionBrowserRefresh->setVisible(true);
|
||||
ui->actionBrowserStop->setVisible(false);
|
||||
}
|
||||
|
||||
|
||||
void BrowserWidget::on_txtUrl_returnPressed()
|
||||
{
|
||||
QUrl url(ui->txtUrl->text());
|
||||
if(url.scheme().isEmpty())
|
||||
url.setScheme("http");
|
||||
ui->webView->load(url);
|
||||
}
|
||||
|
||||
|
||||
void BrowserWidget::on_actionBrowserBack_triggered()
|
||||
{
|
||||
ui->webView->back();
|
||||
}
|
||||
|
||||
void BrowserWidget::on_actionBrowserForward_triggered()
|
||||
{
|
||||
ui->webView->forward();
|
||||
}
|
||||
|
||||
void BrowserWidget::on_actionBrowserRefresh_triggered()
|
||||
{
|
||||
ui->webView->reload();
|
||||
}
|
||||
|
||||
void BrowserWidget::on_actionBrowserStop_triggered()
|
||||
{
|
||||
ui->webView->stop();
|
||||
}
|
37
src/BrowserWidget.h
Normal file
37
src/BrowserWidget.h
Normal file
@ -0,0 +1,37 @@
|
||||
#ifndef BROWSERWIDGET_H
|
||||
#define BROWSERWIDGET_H
|
||||
|
||||
#include <QWidget>
|
||||
#include <QUrl>
|
||||
|
||||
namespace Ui {
|
||||
class BrowserWidget;
|
||||
}
|
||||
|
||||
class BrowserWidget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit BrowserWidget(QWidget *parent = 0);
|
||||
~BrowserWidget();
|
||||
|
||||
void load(const QUrl &url);
|
||||
|
||||
private slots:
|
||||
void on_webView_urlChanged(const QUrl &url);
|
||||
void on_webView_loadStarted();
|
||||
void on_webView_loadFinished(bool);
|
||||
void on_actionBrowserBack_triggered();
|
||||
void on_actionBrowserForward_triggered();
|
||||
void on_actionBrowserRefresh_triggered();
|
||||
void on_txtUrl_returnPressed();
|
||||
|
||||
void on_actionBrowserStop_triggered();
|
||||
|
||||
private:
|
||||
Ui::BrowserWidget *ui;
|
||||
bool loading;
|
||||
};
|
||||
|
||||
#endif // BROWSERWIDGET_H
|
Reference in New Issue
Block a user