aboutsummaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorAqua-sama <aqua@iserlohn-fortress.net>2017-12-14 11:51:51 +0100
committerAqua-sama <aqua@iserlohn-fortress.net>2017-12-14 11:51:51 +0100
commit783621c89c6c4c9aeae1bcf907c4395b96c5babd (patch)
treebd4f2addc5f8ee9f65fb9d5949b2aa9b82695fa2 /src/lib
parentFixed crash on startup due to missing browser.filterPath (diff)
downloadsmolbote-783621c89c6c4c9aeae1bcf907c4395b96c5babd.tar.xz
Cleaned up UrlLineEdit
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/navigation/addressbar.cpp50
-rw-r--r--src/lib/navigation/addressbar.h45
-rw-r--r--src/lib/navigation/navigation.qbs2
-rw-r--r--src/lib/navigation/urllineedit.cpp81
-rw-r--r--src/lib/navigation/urllineedit.h18
5 files changed, 44 insertions, 152 deletions
diff --git a/src/lib/navigation/addressbar.cpp b/src/lib/navigation/addressbar.cpp
deleted file mode 100644
index 909c89a..0000000
--- a/src/lib/navigation/addressbar.cpp
+++ /dev/null
@@ -1,50 +0,0 @@
-/*******************************************************************************
- **
- ** smolbote: yet another qute browser
- ** Copyright (C) 2017 Xian Nox
- **
- ** This program is free software: you can redistribute it and/or modify
- ** it under the terms of the GNU General Public License as published by
- ** the Free Software Foundation, either version 3 of the License, or
- ** (at your option) any later version.
- **
- ** This program is distributed in the hope that it will be useful,
- ** but WITHOUT ANY WARRANTY; without even the implied warranty of
- ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- ** GNU General Public License for more details.
- **
- ** You should have received a copy of the GNU General Public License
- ** along with this program. If not, see <http://www.gnu.org/licenses/>.
- **
- ******************************************************************************/
-
-#include "addressbar.h"
-#include <QHBoxLayout>
-
-AddressBar::AddressBar(QWidget *parent) : QWidget(parent)
-{
- QHBoxLayout *_layout = new QHBoxLayout(this);
- _layout->setMargin(0);
- _layout->setSpacing(0);
- setLayout(_layout);
-
- m_urlLineEdit = new UrlLineEdit(this);
- setFocusProxy(m_urlLineEdit);
- _layout->addWidget(m_urlLineEdit);
-
- connect(m_urlLineEdit, &UrlLineEdit::returnPressed, [&]() {
- if(m_urlLineEdit->text().startsWith('#')) {
- QString term = m_urlLineEdit->text().mid(1);
- term.replace(' ', '+');
- emit searchTermEntered(term);
- } else {
- emit addressEntered(QUrl::fromUserInput(m_urlLineEdit->text()));
- }
- });
-}
-
-void AddressBar::setWebView(const WebView *view)
-{
- connect(view, &WebView::urlChanged, m_urlLineEdit, &UrlLineEdit::setUrl);
- m_urlLineEdit->setUrl(view->url());
-}
diff --git a/src/lib/navigation/addressbar.h b/src/lib/navigation/addressbar.h
deleted file mode 100644
index 8b037e1..0000000
--- a/src/lib/navigation/addressbar.h
+++ /dev/null
@@ -1,45 +0,0 @@
-/*******************************************************************************
- **
- ** smolbote: yet another qute browser
- ** Copyright (C) 2017 Xian Nox
- **
- ** This program is free software: you can redistribute it and/or modify
- ** it under the terms of the GNU General Public License as published by
- ** the Free Software Foundation, either version 3 of the License, or
- ** (at your option) any later version.
- **
- ** This program is distributed in the hope that it will be useful,
- ** but WITHOUT ANY WARRANTY; without even the implied warranty of
- ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- ** GNU General Public License for more details.
- **
- ** You should have received a copy of the GNU General Public License
- ** along with this program. If not, see <http://www.gnu.org/licenses/>.
- **
- ******************************************************************************/
-
-#ifndef ADDRESSBAR_H
-#define ADDRESSBAR_H
-
-#include <QWidget>
-#include "urllineedit.h"
-#include <webengine/webview.h>
-
-class AddressBar : public QWidget
-{
- Q_OBJECT
-public:
- explicit AddressBar(QWidget *parent = nullptr);
-
-signals:
- void addressEntered(const QUrl &url);
- void searchTermEntered(const QString &term);
-
-public slots:
- void setWebView(const WebView *view);
-
-private:
- UrlLineEdit *m_urlLineEdit;
-};
-
-#endif // ADDRESSBAR_H
diff --git a/src/lib/navigation/navigation.qbs b/src/lib/navigation/navigation.qbs
index ebe2713..d070b7f 100644
--- a/src/lib/navigation/navigation.qbs
+++ b/src/lib/navigation/navigation.qbs
@@ -16,8 +16,6 @@ Project {
}
files: [
- "addressbar.cpp",
- "addressbar.h",
"navigationbutton.cpp",
"navigationbutton.h",
"urllineedit.cpp",
diff --git a/src/lib/navigation/urllineedit.cpp b/src/lib/navigation/urllineedit.cpp
index 5e47223..4244866 100644
--- a/src/lib/navigation/urllineedit.cpp
+++ b/src/lib/navigation/urllineedit.cpp
@@ -21,7 +21,7 @@
#include "urllineedit.h"
#include <QUrl>
#include <QTimer>
-
+#include <QMenu>
#include <QAction>
#include <QStyle>
@@ -31,24 +31,27 @@ UrlLineEdit::UrlLineEdit(QWidget *parent) :
QLineEdit(parent)
{
setPlaceholderText(tr("Enter address"));
- setContextMenuPolicy(Qt::NoContextMenu);
+ // test action
+ m_sslAction = addAction(style()->standardIcon(QStyle::SP_ComputerIcon), QLineEdit::LeadingPosition);
+ m_sslAction->setToolTip(tr("TODO: Display SSL Status popup here"));
+
+ QAction *completerAction = addAction(style()->standardIcon(QStyle::SP_TitleBarMinButton), QLineEdit::TrailingPosition);
+
+ m_pageAction = addAction(style()->standardIcon(QStyle::SP_FileIcon), QLineEdit::TrailingPosition);
+ m_pageAction->setShortcut(QKeySequence("F10"));
+ m_pageAction->setToolTip(tr("Page Actions"));
+ connect(m_pageAction, &QAction::triggered, m_pageAction, [&]() {
+ //this->deselect();
+ if(m_pageAction->menu() != nullptr) {
+ m_pageAction->menu()->exec(this->mapToGlobal(QPoint(width(), height())));
+ }
+ });
QTextCharFormat hostnameFormat;
hostnameFormat.setFontWeight(QFont::Bold);
m_hostFormat.format = hostnameFormat;
- m_contextMenu = new QMenu(this);
- m_contextMenu->addAction("Copy URL", this, SLOT(copyUrl()));
- m_contextMenu->addAction("Paste URL", this, SLOT(pasteUrl()));
- m_contextMenu->addAction("Paste URL and go", this, SLOT(pasteUrlAndGo()));
- m_contextMenu->addSeparator();
- m_contextMenu->addAction("Bookmark this page", this, SLOT(bookmarkUrl()))->setEnabled(false);
-
- QAction *contextAction = addAction(style()->standardIcon(QStyle::SP_TitleBarMinButton), ActionPosition::TrailingPosition);
- contextAction->setShortcut(QKeySequence::fromString("F3"));
- connect(contextAction, SIGNAL(triggered()), this, SLOT(showMenu()));
-
m_menu = new QMenu(this);
m_menu->setWindowFlags(Qt::FramelessWindowHint | Qt::Tool);
@@ -70,14 +73,32 @@ UrlLineEdit::UrlLineEdit(QWidget *parent) :
QAction *closeAction = m_menu->addAction("Close");
connect(closeAction, SIGNAL(triggered()), m_menu, SLOT(hide()));
+ connect(completerAction, &QAction::triggered, this, [this]() {
+ this->showCompleter(this->text());
+ });
+
// connect signals
connect(this, SIGNAL(textEdited(QString)), this, SLOT(showCompleter(QString)));
connect(this, &QLineEdit::returnPressed, [this]() {
+ emit addressEntered(QUrl::fromUserInput(this->text()));
m_menu->hide();
+ this->clearFocus();
});
}
+QAction *UrlLineEdit::sslAction()
+{
+ Q_ASSERT(m_sslAction != nullptr);
+ return m_sslAction;
+}
+
+QAction *UrlLineEdit::pageAction()
+{
+ Q_ASSERT(m_pageAction != nullptr);
+ return m_pageAction;
+}
+
void UrlLineEdit::setUrl(const QUrl &url)
{
QString urlText = url.toString();
@@ -101,7 +122,7 @@ void UrlLineEdit::focusInEvent(QFocusEvent *event)
// select the contents when receiving focus
// http://stackoverflow.com/a/35725950/1054406
// mousePressEvent triggers right after focusInEvent so text selected in focusInEvent unselects by mousePressEvent
- QTimer::singleShot(0, this, SLOT(selectAll()));
+ //QTimer::singleShot(0, this, SLOT(selectAll()));
}
void UrlLineEdit::resizeEvent(QResizeEvent *event)
@@ -159,35 +180,3 @@ void UrlLineEdit::showCompleter(const QString &text)
//listWidget->setCurrentRow(0, QItemSelectionModel::SelectCurrent);
m_menu->exec();
}
-
-// Menu
-
-void UrlLineEdit::showMenu()
-{
- m_contextMenu->exec(mapToGlobal(QPoint(width() - m_contextMenu->width(), height())));
-}
-
-void UrlLineEdit::copyUrl()
-{
- selectAll();
- copy();
- deselect();
-}
-
-void UrlLineEdit::pasteUrl()
-{
- clear();
- paste();
-}
-
-void UrlLineEdit::pasteUrlAndGo()
-{
- clear();
- paste();
- emit returnPressed();
-}
-
-void UrlLineEdit::bookmarkUrl()
-{
- qDebug("TODO: bookmarkUrl()");
-}
diff --git a/src/lib/navigation/urllineedit.h b/src/lib/navigation/urllineedit.h
index 8432f14..fb334ec 100644
--- a/src/lib/navigation/urllineedit.h
+++ b/src/lib/navigation/urllineedit.h
@@ -23,15 +23,18 @@
#include <QLineEdit>
#include <QTextLayout>
-#include <QMenu>
-
#include <QListWidget>
+#include <QAction>
+class QMenu;
class UrlLineEdit : public QLineEdit
{
Q_OBJECT
public:
- explicit UrlLineEdit(QWidget *parent = 0);
+ explicit UrlLineEdit(QWidget *parent = nullptr);
+
+ QAction *sslAction();
+ QAction *pageAction();
signals:
void addressEntered(const QUrl &url);
@@ -47,18 +50,15 @@ protected:
private slots:
void showCompleter(const QString &text);
- void showMenu();
- void copyUrl();
- void pasteUrl();
- void pasteUrlAndGo();
- void bookmarkUrl();
private:
void setTextFormat(const QTextLayout::FormatRange &format);
void clearTextFormat();
QTextLayout::FormatRange m_hostFormat;
- QMenu *m_contextMenu;
+
+ QAction *m_sslAction = nullptr;
+ QAction *m_pageAction = nullptr;
QMenu *m_menu;
QListWidget *listWidget;