Implement url adress widget

This commit is contained in:
Fredrik Johansson
2019-01-27 22:38:38 +01:00
committed by wmayer
parent 954c198360
commit f827ab776e
7 changed files with 1586 additions and 6 deletions

View File

@@ -131,7 +131,9 @@ Gui::ToolBarItem* StartGui::Workbench::setupToolBars() const
// web navigation toolbar
Gui::ToolBarItem* navigation = new Gui::ToolBarItem(root);
navigation->setCommand("Navigation");
*navigation << "Web_OpenWebsite"
*navigation << "Web_BrowserSetURL"
<< "Separator"
<< "Web_OpenWebsite"
<< "Start_StartPage"
<< "Separator"
<< "Web_BrowserBack"

View File

@@ -48,6 +48,7 @@
# include <QSignalMapper>
# include <QPointer>
# include <QDir>
# include <QLineEdit>
#endif
@@ -65,6 +66,7 @@
# include <QWebFrame>
# include <QWebView>
# include <QWebSettings>
# include <QNetworkAccessManager>
# define QWEBVIEW QWebView
# define QWEBPAGE QWebPage
#endif
@@ -130,6 +132,42 @@ private:
};
#endif
// ---------------------------------------------------------------------------------------------
UrlWidget::UrlWidget(BrowserView *view) :
QLineEdit(view), m_view(view)
{
setText(QLatin1String("https://"));
hide();
}
UrlWidget::~UrlWidget()
{
}
void UrlWidget::keyPressEvent(QKeyEvent *keyEvt)
{
switch (keyEvt->key()) {
case Qt::Key_Escape:
hide();
break;
case Qt::Key_Return:
case Qt::Key_Enter:
m_view->load(text().toLatin1());
hide();
break;
default:
QLineEdit::keyPressEvent(keyEvt);
}
}
void UrlWidget::display()
{
setFixedWidth(m_view->size().width());
show();
setFocus(Qt::ActiveWindowFocusReason);
}
// ---------------------------------------------------------------------------------------------
class BrowserViewPy : public Py::PythonExtension<BrowserViewPy>
{
public:
@@ -344,6 +382,8 @@ BrowserView::BrowserView(QWidget* parent)
setCentralWidget(view);
view->setAttribute(Qt::WA_OpaquePaintEvent, true);
urlWgt = new UrlWidget(this);
#ifdef QTWEBKIT
textSizeMultiplier = 1.0;
@@ -548,8 +588,7 @@ void BrowserView::onViewSource(const QUrl &url)
QPlainTextEdit *editorWidget = new QPlainTextEdit {};
App::TextDocument *txtDoc = new App::TextDocument;
TextDocumentEditorView *textDocView = new TextDocumentEditorView {
txtDoc,
editorWidget, getMainWindow()
txtDoc, editorWidget, getMainWindow()
};
editorWidget->setReadOnly(true);
editorWidget->setPlainText(pageSource);
@@ -568,6 +607,8 @@ void BrowserView::load(const QUrl & url)
if (isLoading)
stop();
urlWgt->setText(url.toString());
view->load(url);
view->setUrl(url);
if (url.scheme().size() < 2) {
@@ -674,6 +715,9 @@ bool BrowserView::onMsg(const char* pMsg,const char** )
qreal factor = view->zoomFactor();
view->setZoomFactor(factor - 0.2);
return true;
} else if (strcmp(pMsg,"SetURL")==0){
urlWgt->display();
return true;
}
return false;
@@ -693,6 +737,7 @@ bool BrowserView::onHasMsg(const char* pMsg) const
if (strcmp(pMsg,"Stop")==0) return isLoading;
if (strcmp(pMsg,"ZoomIn")==0) return true;
if (strcmp(pMsg,"ZoomOut")==0) return true;
if (strcmp(pMsg,"SetURL")==0) return true;
return false;
}

View File

@@ -27,6 +27,7 @@
#include <Gui/MDIView.h>
#include <Gui/Window.h>
#include <QLineEdit>
#if QT_VERSION >= 0x050700 && defined(QTWEBENGINE)
#include <QWebEngineView>
@@ -42,6 +43,7 @@ class QNetworkRequest;
class QNetworkReply;
namespace WebGui {
class UrlWidget;
#ifdef QTWEBENGINE
class WebGuiExport WebView : public QWebEngineView
@@ -123,6 +125,7 @@ protected Q_SLOTS:
private:
WebView* view;
bool isLoading;
UrlWidget *urlWgt;
#ifdef QTWEBENGINE
WebEngineUrlRequestInterceptor *interceptLinks;
#else
@@ -130,6 +133,19 @@ private:
#endif
};
// the URL ardressbar lineedit
class UrlWidget : public QLineEdit
{
Q_OBJECT
BrowserView *m_view;
public:
explicit UrlWidget(BrowserView *view);
~UrlWidget();
void display();
protected:
void keyPressEvent(QKeyEvent *keyEvt);
};
} // namespace WebGui
#endif // WEBGUI_BROWSERVIEW_H

View File

@@ -237,6 +237,36 @@ bool CmdWebBrowserZoomOut::isActive(void)
return getGuiApplication()->sendHasMsgToActiveView("ZoomOut");
}
//===========================================================================
// CmdWebBrowserSetUrl
//===========================================================================
DEF_STD_CMD_A(CmdWebBrowserSetURL);
CmdWebBrowserSetURL::CmdWebBrowserSetURL()
: Command("Web_BrowserSetURL")
{
sAppModule = "Web";
sGroup = QT_TR_NOOP("Web");
sMenuText = QT_TR_NOOP("Set URL");
sToolTipText = QT_TR_NOOP("Set URL");
sWhatsThis = "Web_BrowserSetURL";
sStatusTip = sToolTipText;
sPixmap = "actions/web-set-url";
}
void CmdWebBrowserSetURL::activated(int iMsg)
{
Q_UNUSED(iMsg);
doCommand(Command::Gui,"Gui.SendMsgToActiveView('SetURL')");
}
bool CmdWebBrowserSetURL::isActive(void)
{
return getGuiApplication()->sendHasMsgToActiveView("SetURL");
}
void CreateWebCommands(void)
{
@@ -249,4 +279,5 @@ void CreateWebCommands(void)
rcCmdMgr.addCommand(new CmdWebBrowserStop());
rcCmdMgr.addCommand(new CmdWebBrowserZoomIn());
rcCmdMgr.addCommand(new CmdWebBrowserZoomOut());
rcCmdMgr.addCommand(new CmdWebBrowserSetURL());
}

View File

@@ -1,5 +1,5 @@
<!DOCTYPE RCC><RCC version="1.0">
<qresource>
<RCC>
<qresource prefix="/">
<file>icons/actions/web-browser.svg</file>
<file>icons/actions/web-home.svg</file>
<file>icons/actions/web-next.svg</file>
@@ -9,6 +9,7 @@
<file>icons/actions/web-zoom-in.svg</file>
<file>icons/actions/web-zoom-out.svg</file>
<file>icons/actions/web-sketchfab.svg</file>
<file>icons/actions/web-set-url.svg</file>
<file>icons/WebWorkbench.svg</file>
<file>translations/Web_de.qm</file>
<file>translations/Web_af.qm</file>

File diff suppressed because it is too large Load Diff

After

Width:  |  Height:  |  Size: 66 KiB

View File

@@ -325,7 +325,9 @@ Gui::ToolBarItem* Workbench::setupToolBars() const
// web navigation toolbar
Gui::ToolBarItem* navigation = new Gui::ToolBarItem(root);
navigation->setCommand("Navigation");
*navigation << "Web_OpenWebsite"
*navigation << "Web_BrowserSetURL"
<< "Separator"
<< "Web_OpenWebsite"
<< "Separator"
<< "Web_BrowserBack"
<< "Web_BrowserNext"