aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/lib/navigation/navigationbutton.cpp53
-rw-r--r--src/lib/navigation/navigationbutton.h13
-rw-r--r--src/mainwindow.cpp7
-rw-r--r--src/mainwindow.h2
4 files changed, 60 insertions, 15 deletions
diff --git a/src/lib/navigation/navigationbutton.cpp b/src/lib/navigation/navigationbutton.cpp
index 7065535..6e31028 100644
--- a/src/lib/navigation/navigationbutton.cpp
+++ b/src/lib/navigation/navigationbutton.cpp
@@ -34,28 +34,57 @@ NavigationButton::NavigationButton(Type type, QWidget *parent) :
case BackButton:
setIcon(style()->standardIcon(QStyle::SP_ArrowBack));
setMenu(menu);
+ connect(menu, &QMenu::aboutToShow, this, &NavigationButton::prepareMenu);
break;
case ForwardButton:
setIcon(style()->standardIcon(QStyle::SP_ArrowForward));
setMenu(menu);
+ connect(menu, &QMenu::aboutToShow, this, &NavigationButton::prepareMenu);
+ break;
+ case ReloadButton:
+ setIcon(style()->standardIcon(QStyle::SP_BrowserReload));
+ break;
+ case StopButton:
+ setIcon(style()->standardIcon(QStyle::SP_BrowserStop));
break;
}
connect(this, &NavigationButton::clicked, this, &NavigationButton::doAction);
- connect(menu, &QMenu::aboutToShow, this, &NavigationButton::prepareMenu);
+
}
-void NavigationButton::setView(const WebView *view)
+void NavigationButton::setView(WebView *view)
{
+ disconnect(loadStartedConnection);
disconnect(loadFinishedConnection);
m_view = view;
- updateEnableState();
- loadFinishedConnection = connect(view, &WebView::loadFinished, this, &NavigationButton::updateEnableState);
+ if(m_type == BackButton || m_type == ForwardButton) {
+ updateOnLoadFinished();
+ }
+
+ loadStartedConnection = connect(view, &WebView::loadStarted, this, &NavigationButton::updateOnLoadStarted);
+ loadFinishedConnection = connect(view, &WebView::loadFinished, this, &NavigationButton::updateOnLoadFinished);
}
-void NavigationButton::updateEnableState()
+void NavigationButton::updateOnLoadStarted()
+{
+ switch (m_type) {
+ case BackButton:
+ break;
+ case ForwardButton:
+ break;
+ case ReloadButton:
+ m_type = StopButton;
+ setIcon(style()->standardIcon(QStyle::SP_BrowserStop));
+ break;
+ case StopButton:
+ break;
+ }
+}
+
+void NavigationButton::updateOnLoadFinished()
{
switch (m_type) {
case BackButton:
@@ -72,6 +101,12 @@ void NavigationButton::updateEnableState()
setEnabled(false);
}
break;
+ case ReloadButton:
+ break;
+ case StopButton:
+ m_type = ReloadButton;
+ setIcon(style()->standardIcon(QStyle::SP_BrowserReload));
+ break;
}
}
@@ -84,6 +119,12 @@ void NavigationButton::doAction()
case ForwardButton:
m_view->history()->forward();
break;
+ case ReloadButton:
+ m_view->reload();
+ break;
+ case StopButton:
+ m_view->stop();
+ break;
}
}
@@ -99,6 +140,8 @@ void NavigationButton::prepareMenu()
case ForwardButton:
items = m_view->history()->forwardItems(10);
break;
+ default:
+ break;
}
for(QWebEngineHistoryItem i : items) {
diff --git a/src/lib/navigation/navigationbutton.h b/src/lib/navigation/navigationbutton.h
index 44e3ceb..678d48d 100644
--- a/src/lib/navigation/navigationbutton.h
+++ b/src/lib/navigation/navigationbutton.h
@@ -33,26 +33,29 @@ public:
enum Type {
BackButton,
- ForwardButton
+ ForwardButton,
+ ReloadButton,
+ StopButton
};
explicit NavigationButton(Type type, QWidget *parent = nullptr);
- void setView(const WebView *view);
+ void setView(WebView *view);
signals:
private slots:
- void updateEnableState();
+ void updateOnLoadStarted();
+ void updateOnLoadFinished();
void doAction();
void prepareMenu();
private:
Type m_type;
QMenu *menu;
- const WebView *m_view;
+ WebView *m_view;
- QMetaObject::Connection loadFinishedConnection;
+ QMetaObject::Connection loadStartedConnection, loadFinishedConnection;
};
#endif // NAVIGATIONBUTTON_H
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp
index 68afa40..75f1da3 100644
--- a/src/mainwindow.cpp
+++ b/src/mainwindow.cpp
@@ -80,10 +80,8 @@ MainWindow::MainWindow(QUrl defaultUrl, QWidget *parent) :
forwardButton = new NavigationButton(NavigationButton::ForwardButton, this);
- QToolButton *reloadButton = new QToolButton(this);
- reloadButton->setIcon(style()->standardIcon(QStyle::SP_BrowserReload));
- connect(reloadButton, SIGNAL(clicked()), tabBar->signalMapper(), SLOT(map()));
- tabBar->signalMapper()->setMapping(reloadButton, WebViewTabBar::Reload);
+ reloadButton = new NavigationButton(NavigationButton::ReloadButton, this);
+
QToolButton *homepageButton = new QToolButton(this);
homepageButton->setIcon(style()->standardIcon(QStyle::SP_DirHomeIcon));
connect(homepageButton, SIGNAL(clicked()), tabBar->signalMapper(), SLOT(map()));
@@ -241,6 +239,7 @@ void MainWindow::handleTabChanged(WebView *view)
// connect signals
backButton->setView(view);
forwardButton->setView(view);
+ reloadButton->setView(view);
m_addressBar->setWebView(view);
connect(view, SIGNAL(titleChanged(QString)), this, SLOT(handleTitleUpdated(QString)));
connect(view, SIGNAL(linkHovered(QString)), ui->statusBar, SLOT(showMessage(QString)));
diff --git a/src/mainwindow.h b/src/mainwindow.h
index 50483d2..7f8e251 100644
--- a/src/mainwindow.h
+++ b/src/mainwindow.h
@@ -74,7 +74,7 @@ private:
WebView *m_currentView;
// navigation
- NavigationButton *backButton, *forwardButton;
+ NavigationButton *backButton, *forwardButton, *reloadButton;
AddressBar *m_addressBar;
LoadingBar *m_progressBar;
};