diff options
author | Aqua-sama <aqua@iserlohn-fortress.net> | 2018-01-03 16:39:32 +0100 |
---|---|---|
committer | Aqua-sama <aqua@iserlohn-fortress.net> | 2018-01-03 16:39:32 +0100 |
commit | 85d9f14aa8bac16ab341662c770b64a15c21628b (patch) | |
tree | 422db18e798646cd4bc98abf342f25c09c0bdf1d /src/lib/navigation | |
parent | Download items' width should no longer exceed the list width (diff) | |
download | smolbote-85d9f14aa8bac16ab341662c770b64a15c21628b.tar.xz |
Changed from qbs to cmake
Diffstat (limited to 'src/lib/navigation')
-rw-r--r-- | src/lib/navigation/navigation.qbs | 26 | ||||
-rw-r--r-- | src/lib/navigation/navigationbutton.cpp | 141 | ||||
-rw-r--r-- | src/lib/navigation/navigationbutton.h | 49 | ||||
-rw-r--r-- | src/lib/navigation/urlcompleter.cpp | 26 | ||||
-rw-r--r-- | src/lib/navigation/urlcompleter.h | 25 | ||||
-rw-r--r-- | src/lib/navigation/urllineedit.cpp | 136 | ||||
-rw-r--r-- | src/lib/navigation/urllineedit.h | 59 |
7 files changed, 0 insertions, 462 deletions
diff --git a/src/lib/navigation/navigation.qbs b/src/lib/navigation/navigation.qbs deleted file mode 100644 index 7719fbc..0000000 --- a/src/lib/navigation/navigation.qbs +++ /dev/null @@ -1,26 +0,0 @@ -import qbs 1.0 - -Project { - name: "navigation" - - StaticLibrary { - id: navigation - name: "navigation" - - cpp.includePaths: ['../..'] - - Depends { - name: "Qt" - submodules: ["core", "widgets", "webengine", "webenginewidgets"] - } - - files: [ - "navigationbutton.cpp", - "navigationbutton.h", - "urlcompleter.cpp", - "urlcompleter.h", - "urllineedit.cpp", - "urllineedit.h", - ] - } -} diff --git a/src/lib/navigation/navigationbutton.cpp b/src/lib/navigation/navigationbutton.cpp deleted file mode 100644 index 13daebc..0000000 --- a/src/lib/navigation/navigationbutton.cpp +++ /dev/null @@ -1,141 +0,0 @@ -/* - * This file is part of smolbote. It's copyrighted by the contributors recorded - * in the version control history of the file, available from its original - * location: git://neueland.iserlohn-fortress.net/smolbote.git - * - * SPDX-License-Identifier: GPL-3.0 - */ - -#include "navigationbutton.h" - -#include <QStyle> -#include <QWebEngineHistory> -#include <QMenu> - -NavigationButton::NavigationButton(Type type, QWidget *parent) : - QToolButton(parent) -{ - m_type = type; - menu = new QMenu(this); - - switch (type) { - 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); - -} - - -void NavigationButton::setView(WebView *view) -{ - disconnect(loadStartedConnection); - disconnect(loadFinishedConnection); - - m_view = view; - 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::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: - if(m_view->history()->canGoBack()) { - setEnabled(true); - } else { - setEnabled(false); - } - break; - case ForwardButton: - if(m_view->history()->canGoForward()) { - setEnabled(true); - } else { - setEnabled(false); - } - break; - case ReloadButton: - break; - case StopButton: - m_type = ReloadButton; - setIcon(style()->standardIcon(QStyle::SP_BrowserReload)); - break; - } -} - -void NavigationButton::doAction() -{ - switch (m_type) { - case BackButton: - m_view->history()->back(); - break; - case ForwardButton: - m_view->history()->forward(); - break; - case ReloadButton: - m_view->reload(); - break; - case StopButton: - m_view->stop(); - break; - } -} - -void NavigationButton::prepareMenu() -{ - menu->clear(); - - QList<QWebEngineHistoryItem> items; - switch (m_type) { - case BackButton: - items = m_view->history()->backItems(10); - break; - case ForwardButton: - items = m_view->history()->forwardItems(10); - break; - default: - break; - } - - for(QWebEngineHistoryItem i : items) { - QAction *a = menu->addAction(i.title()); - connect(a, &QAction::triggered, [i, this]() { - m_view->history()->goToItem(i); - }); - } -} diff --git a/src/lib/navigation/navigationbutton.h b/src/lib/navigation/navigationbutton.h deleted file mode 100644 index ec39efa..0000000 --- a/src/lib/navigation/navigationbutton.h +++ /dev/null @@ -1,49 +0,0 @@ -/* - * This file is part of smolbote. It's copyrighted by the contributors recorded - * in the version control history of the file, available from its original - * location: git://neueland.iserlohn-fortress.net/smolbote.git - * - * SPDX-License-Identifier: GPL-3.0 - */ - -#ifndef NAVIGATIONBUTTON_H -#define NAVIGATIONBUTTON_H - -#include <QToolButton> -#include <webengine/webview.h> - -class QMenu; - -class NavigationButton : public QToolButton -{ - Q_OBJECT -public: - - enum Type { - BackButton, - ForwardButton, - ReloadButton, - StopButton - }; - - explicit NavigationButton(Type type, QWidget *parent = nullptr); - - void setView(WebView *view); - -signals: - -private slots: - void updateOnLoadStarted(); - void updateOnLoadFinished(); - void doAction(); - void prepareMenu(); - -private: - Type m_type; - QMenu *menu; - WebView *m_view; - - QMetaObject::Connection loadStartedConnection, loadFinishedConnection; -}; - -#endif // NAVIGATIONBUTTON_H diff --git a/src/lib/navigation/urlcompleter.cpp b/src/lib/navigation/urlcompleter.cpp deleted file mode 100644 index bbde297..0000000 --- a/src/lib/navigation/urlcompleter.cpp +++ /dev/null @@ -1,26 +0,0 @@ -/* - * This file is part of smolbote. It's copyrighted by the contributors recorded - * in the version control history of the file, available from its original - * location: git://neueland.iserlohn-fortress.net/smolbote.git - * - * SPDX-License-Identifier: GPL-3.0 - */ - -#include "urlcompleter.h" - -UrlCompleter::UrlCompleter(QAbstractItemModel *model, QObject *parent) : - QCompleter(model, parent) -{ - setCompletionMode(QCompleter::PopupCompletion); - setFilterMode(Qt::MatchContains); -} - -QStringList UrlCompleter::splitPath(const QString &path) const -{ - return path.split('.'); -} - -QString UrlCompleter::pathFromIndex(const QModelIndex &index) const -{ - return model()->data(index, completionRole()).toString(); -} diff --git a/src/lib/navigation/urlcompleter.h b/src/lib/navigation/urlcompleter.h deleted file mode 100644 index f2c52ff..0000000 --- a/src/lib/navigation/urlcompleter.h +++ /dev/null @@ -1,25 +0,0 @@ -/* - * This file is part of smolbote. It's copyrighted by the contributors recorded - * in the version control history of the file, available from its original - * location: git://neueland.iserlohn-fortress.net/smolbote.git - * - * SPDX-License-Identifier: GPL-3.0 - */ - -#ifndef URLCOMPLETER_H -#define URLCOMPLETER_H - -#include <QCompleter> - -class UrlCompleter : public QCompleter -{ - Q_OBJECT -public: - explicit UrlCompleter(QAbstractItemModel *model, QObject *parent = nullptr); - -protected: - QStringList splitPath(const QString &path) const override; - QString pathFromIndex(const QModelIndex &index) const override; -}; - -#endif // URLCOMPLETER_H diff --git a/src/lib/navigation/urllineedit.cpp b/src/lib/navigation/urllineedit.cpp deleted file mode 100644 index 4dc6b39..0000000 --- a/src/lib/navigation/urllineedit.cpp +++ /dev/null @@ -1,136 +0,0 @@ -/* - * This file is part of smolbote. It's copyrighted by the contributors recorded - * in the version control history of the file, available from its original - * location: git://neueland.iserlohn-fortress.net/smolbote.git - * - * SPDX-License-Identifier: GPL-3.0 - */ - -#include "urllineedit.h" -#include <QUrl> -#include <QTimer> -#include <QMenu> -#include <QAction> -#include <QStyle> - -#include <QWidgetAction> - -// ssl menu -#include <QLabel> - -#include "lib/bookmarks/bookmarkswidget.h" - -#include <QCompleter> - -UrlLineEdit::UrlLineEdit(QWidget *parent) : - QLineEdit(parent) -{ - setPlaceholderText(tr("Enter address")); - - // ssl menu - m_sslMenu = new QMenu(this); - m_sslLabel = new QLabel(m_sslMenu); - QWidgetAction *sslErrorAction = new QWidgetAction(m_sslMenu); - sslErrorAction->setDefaultWidget(m_sslLabel); - m_sslMenu->addAction(sslErrorAction); - - m_sslAction = addAction(style()->standardIcon(QStyle::SP_DriveNetIcon), QLineEdit::LeadingPosition); - m_sslAction->setToolTip(tr("TODO: Display SSL Status popup here")); - m_sslAction->setMenu(m_sslMenu); - - connect(m_sslAction, &QAction::triggered, this, [this]() { - m_sslMenu->exec(this->mapToGlobal(QPoint(0, height()))); - }); - - 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; - - // connect signals - connect(this, &QLineEdit::returnPressed, [this]() { - if(this->text().startsWith('#')) { - emit searchTermEntered(this->text().mid(1)); - } else { - emit addressEntered(QUrl::fromUserInput(this->text())); - } - this->clearFocus(); - }); - -} - -QAction *UrlLineEdit::sslAction() -{ - Q_CHECK_PTR(m_sslAction); - return m_sslAction; -} - -QAction *UrlLineEdit::pageAction() -{ - Q_CHECK_PTR(m_pageAction); - return m_pageAction; -} - -void UrlLineEdit::setCompleterModel(QAbstractItemModel *model) -{ - Q_CHECK_PTR(model); - m_completer = new UrlCompleter(model, this); - m_completer->setCompletionColumn(1); - this->setCompleter(m_completer); -} - -void UrlLineEdit::setUrl(const QUrl &url) -{ - QString urlText = url.toString(); - QString domain = url.host(); - - m_hostFormat.start = urlText.indexOf(domain); - m_hostFormat.length = domain.length(); - - clear(); - clearTextFormat(); - setTextFormat(m_hostFormat); - setText(urlText); -} - -void UrlLineEdit::showSslError(const QString &message) -{ - m_sslLabel->setText(message); - m_sslAction->trigger(); -} - -void UrlLineEdit::focusInEvent(QFocusEvent *event) -{ - clearTextFormat(); - - QLineEdit::focusInEvent(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())); -} - -// formatting taken from: https://forum.qt.io/topic/60962/setting-qlineedit-text-bold -void UrlLineEdit::setTextFormat(const QTextLayout::FormatRange &format) -{ - QList<QInputMethodEvent::Attribute> attributes; - attributes.append(QInputMethodEvent::Attribute(QInputMethodEvent::TextFormat, format.start, format.length, format.format)); - QInputMethodEvent ev(QString(), attributes); - event(&ev); - -} - -void UrlLineEdit::clearTextFormat() -{ - setTextFormat(QTextLayout::FormatRange()); -} diff --git a/src/lib/navigation/urllineedit.h b/src/lib/navigation/urllineedit.h deleted file mode 100644 index 46366a7..0000000 --- a/src/lib/navigation/urllineedit.h +++ /dev/null @@ -1,59 +0,0 @@ -/* - * This file is part of smolbote. It's copyrighted by the contributors recorded - * in the version control history of the file, available from its original - * location: git://neueland.iserlohn-fortress.net/smolbote.git - * - * SPDX-License-Identifier: GPL-3.0 - */ - -#ifndef URLLINEEDIT_H -#define URLLINEEDIT_H - -#include <QLineEdit> -#include <QTextLayout> -#include <QAction> - -#include "urlcompleter.h" - -class QAbstractItemModel; -class QMenu; -class QLabel; -class UrlLineEdit : public QLineEdit -{ - Q_OBJECT -public: - explicit UrlLineEdit(QWidget *parent = nullptr); - - QAction *sslAction(); - QAction *pageAction(); - - void setCompleterModel(QAbstractItemModel *model); - -signals: - void addressEntered(const QUrl &url); - void searchTermEntered(const QString &term); - -public slots: - void setUrl(const QUrl &url); - void showSslError(const QString &message); - -protected: - void focusInEvent(QFocusEvent *event); - -private: - void setTextFormat(const QTextLayout::FormatRange &format); - void clearTextFormat(); - - QTextLayout::FormatRange m_hostFormat; - - QAction *m_sslAction = nullptr; - QAction *m_pageAction = nullptr; - - // ssl menu - QMenu *m_sslMenu; - QLabel *m_sslLabel; - - UrlCompleter *m_completer; -}; - -#endif // URLLINEEDIT_H |