#include <KLineEdit>
// Qt framework headers.
+#include <QWebEngineHistory>
#include <QWebEngineView>
MainView::MainView(QWidget *parent) : QWidget(parent)
mainViewUi.setupUi(this);
// Get handles for the views.
+ backButtonPointer = mainViewUi.backButton;
+ forwardButtonPointer = mainViewUi.forwardButton;
urlLineEditPointer = mainViewUi.urlLineEdit;
webEngineViewPointer = mainViewUi.webEngineView;
- // Get a handle for the webpage.
+ // Get handles for the webpage and history.
QWebEnginePage *webEnginePagePointer = webEngineViewPointer->page();
+ webEngineHistoryPointer = webEnginePagePointer->history();
// Update the webengine view from the URL line edit.
connect(urlLineEditPointer, SIGNAL(returnKeyPressed(const QString)), this, SLOT(loadUrl(const QString)));
// Update the URL line edit form the webengine view.
- connect(webEngineViewPointer, SIGNAL(loadStarted()), this, SLOT(updateUrlLineEdit()));
- connect(webEngineViewPointer, SIGNAL(loadProgress(int)), this, SLOT(updateUrlLineEdit()));
- connect(webEngineViewPointer, SIGNAL(loadFinished(bool)), this, SLOT(updateUrlLineEdit()));
+ connect(webEngineViewPointer, SIGNAL(loadStarted()), this, SLOT(updateInterface()));
+ connect(webEngineViewPointer, SIGNAL(loadProgress(int)), this, SLOT(updateInterface()));
+ connect(webEngineViewPointer, SIGNAL(loadFinished(bool)), this, SLOT(updateInterface()));
+
+ // Setup the forward and back buttons.
+ connect(backButtonPointer, SIGNAL(clicked()), webEngineViewPointer, SLOT(back()));
+ connect(forwardButtonPointer, SIGNAL(clicked()), webEngineViewPointer, SLOT(forward()));
// Listen for hovered link URLs.
connect(webEnginePagePointer, SIGNAL(linkHovered(QString)), this, SLOT(pageLinkHovered(QString)));
emit linkHovered(linkUrl);
}
-void MainView::updateUrlLineEdit()
+void MainView::updateInterface()
{
// Update the URL line edit if it does not have focus.
if (!urlLineEditPointer->hasFocus())
urlLineEditPointer->setUrl(webEngineViewPointer->url().toString());
}
+ backButtonPointer->setEnabled(webEngineHistoryPointer->canGoBack());
+ forwardButtonPointer->setEnabled(webEngineHistoryPointer->canGoForward());
+
// Reapply the zoom factor. This is a bug in QWebEngineView that resets the zoom with every load. Hopefully it will be fixed in Qt6. <https://bugreports.qt.io/browse/QTBUG-51992>
webEngineViewPointer->setZoomFactor(Settings::zoomFactor());
}
// Define the private slots.
void loadUrl(const QString &urlFromUser);
void pageLinkHovered(const QString &linkUrl);
- void updateUrlLineEdit();
+ void updateInterface();
private:
// Define the private variables.
+ QPushButton *backButtonPointer;
+ QPushButton *forwardButtonPointer;
KLineEdit *urlLineEditPointer;
+ QWebEngineHistory *webEngineHistoryPointer;
QWebEngineView *webEngineViewPointer;
};
#endif
</property>
<layout class="QVBoxLayout">
+ <!-- Set the spacing between items to 0. -->
+ <property name="spacing">
+ <number>0</number>
+ </property>
+
<!-- Set the margins to 0. -->
<property name="topMargin">
<number>0</number>
</property>
<item>
- <widget class="KLineEdit" name="urlLineEdit" />
+ <layout class="QHBoxLayout">
+ <!-- Set the spacing between items to 0. -->
+ <property name="spacing">
+ <number>0</number>
+ </property>
+
+ <item>
+ <widget class="QPushButton" name="backButton">
+ <property name="icon">
+ <iconset theme="arrow-left" />
+ </property>
+
+ <property name="iconSize">
+ <size>
+ <width>24</width>
+ <height>24</height>
+ </size>
+ </property>
+
+ <property name="flat">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+
+ <item>
+ <widget class="QPushButton" name="forwardButton">
+ <property name="icon">
+ <iconset theme="arrow-right" />
+ </property>
+
+ <property name="iconSize">
+ <size>
+ <width>24</width>
+ <height>24</height>
+ </size>
+ </property>
+
+ <property name="flat">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+
+ <item>
+ <widget class="KLineEdit" name="urlLineEdit" />
+ </item>
+ </layout>
</item>
<item>