aboutsummaryrefslogtreecommitdiff
path: root/src/lib/navigation
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/navigation')
-rw-r--r--src/lib/navigation/navigationbutton.cpp53
-rw-r--r--src/lib/navigation/navigationbutton.h13
2 files changed, 56 insertions, 10 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