diff options
author | aqua <aqua@iserlohn-fortress.net> | 2022-08-22 10:16:01 +0300 |
---|---|---|
committer | aqua <aqua@iserlohn-fortress.net> | 2022-09-05 23:07:41 +0300 |
commit | f7df477b1e8fa4528b6fe4f8b44c403f46e72d85 (patch) | |
tree | 0411b17b662b7668127da151aaabab8c716cac24 /src/urlbar | |
parent | check_license.py: add BSD-3-Clause (diff) | |
download | rekonq-f7df477b1e8fa4528b6fe4f8b44c403f46e72d85.tar.xz |
Add UrlBar and TabBar
- move src/tabwindow/tabbar.* to src/tabbar/
Diffstat (limited to 'src/urlbar')
-rw-r--r-- | src/urlbar/CMakeLists.txt | 2 | ||||
-rw-r--r-- | src/urlbar/urlbar.cpp | 629 | ||||
-rw-r--r-- | src/urlbar/urlbar.h | 214 |
3 files changed, 339 insertions, 506 deletions
diff --git a/src/urlbar/CMakeLists.txt b/src/urlbar/CMakeLists.txt new file mode 100644 index 00000000..6a68ce58 --- /dev/null +++ b/src/urlbar/CMakeLists.txt @@ -0,0 +1,2 @@ +add_library(urlbar STATIC urlbar.cpp urlbar.h) +target_link_libraries(urlbar PUBLIC Qt6::Widgets)
\ No newline at end of file diff --git a/src/urlbar/urlbar.cpp b/src/urlbar/urlbar.cpp index 0022bfaf..67d77aa4 100644 --- a/src/urlbar/urlbar.cpp +++ b/src/urlbar/urlbar.cpp @@ -1,313 +1,230 @@ /* ============================================================ -* -* This file is a part of the rekonq project -* -* Copyright (C) 2008-2012 by Andrea Diamantini <adjam7 at gmail dot com> -* Copyright (C) 2009 by Domrachev Alexandr <alexandr.domrachev@gmail.com> -* Copyright (C) 2009 by Paweł Prażak <pawelprazak at gmail dot com> -* Copyright (C) 2009-2011 by Lionel Chauvin <megabigbug@yahoo.fr> -* -* -* 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 2 of -* the License or (at your option) version 3 or any later version -* accepted by the membership of KDE e.V. (or its successor approved -* by the membership of KDE e.V.), which shall act as a proxy -* defined in Section 14 of version 3 of the license. -* -* 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/>. -* -* ============================================================ */ - - -// Self Includes + * The rekonq project + * ============================================================ + * SPDX-License-Identifier: GPL-2.0-or-later + * Copyright (C) 2008-2012 by Andrea Diamantini <adjam7 at gmail dot com> + * Copyright (C) 2009 by Domrachev Alexandr <alexandr.domrachev@gmail.com> + * Copyright (C) 2009 by Paweł Prażak <pawelprazak at gmail dot com> + * Copyright (C) 2009-2011 by Lionel Chauvin <megabigbug@yahoo.fr> + * SPDX-License-Identifier: GPL-3.0-only + * Copyright (C) 2022 aqua <aqua@iserlohn-fortress.net> + * ============================================================ */ + #include "urlbar.h" -#include "urlbar.moc" - -// Auto Includes -#include "rekonq.h" - -// App Includes -#include "application.h" - -// Local Includes -#include "adblockmanager.h" -#include "bookmarkmanager.h" -#include "iconmanager.h" - -#include "adblockwidget.h" -#include "bookmarkwidget.h" -#include "rsswidget.h" -#include "sslwidget.h" - -#include "completionwidget.h" -#include "urlresolver.h" - -#include "webtab.h" -#include "webpage.h" -#include "searchengine.h" -#include "websnap.h" - -// KDE Includes -#include <KCompletionBox> -#include <KStandardDirs> -#include <KColorScheme> -#include <KMenu> -#include <KIcon> -#include <KIconLoader> -#include <KMessageBox> -#include <KStandardAction> -#include <KAction> - -// Qt Includes -#include <QPainter> +#include <QApplication> +#include <QClipboard> #include <QPaintEvent> +#include <QPainter> #include <QPalette> -#include <QVBoxLayout> -#include <QClipboard> -#include <QTimer> +#include <QStyleOptionFrame> // const values -const int c_iconMargin = 4; - - -IconButton::IconButton(QWidget *parent) - : QToolButton(parent) -{ - setToolButtonStyle(Qt::ToolButtonIconOnly); - setStyleSheet("IconButton { background-color:transparent; border: none; padding: 0px}"); - setCursor(Qt::ArrowCursor); - - setContextMenuPolicy(Qt::PreventContextMenu); -} - +constexpr int c_iconMargin = 4; -void IconButton::mouseReleaseEvent(QMouseEvent* event) +IconButton::IconButton(QWidget *parent) : QToolButton(parent) { - emit clicked(event->globalPos()); + setToolButtonStyle(Qt::ToolButtonIconOnly); + setStyleSheet("IconButton { background-color:transparent; border: none; padding: 0px}"); + setCursor(Qt::ArrowCursor); + setContextMenuPolicy(Qt::PreventContextMenu); } +void IconButton::mouseReleaseEvent(QMouseEvent *event) { emit clicked(event->globalPos()); } // ----------------------------------------------------------------------------------------------------------- - QString guessUrlWithCustomFirstLevel(const QString &str1, const QString &str2) { - QUrl url(QL1S("http://www.") + str1); - QString host = url.host().toLower(); - if (!host.endsWith(str2, Qt::CaseInsensitive)) - { - host += str2; - url.setHost(host); - } - return url.toString(); + QUrl url(QL1S("http://www.") + str1); + QString host = url.host().toLower(); + if (!host.endsWith(str2, Qt::CaseInsensitive)) { + host += str2; + url.setHost(host); + } + return url.toString(); } - // ----------------------------------------------------------------------------------------------------------- - UrlBar::UrlBar(QWidget *parent) - : KLineEdit(parent) - , _box(new CompletionWidget(this)) - , _tab(0) - , _icon(new IconButton(this)) - , _suggestionTimer(new QTimer(this)) + : QLineEdit(parent) + //, _box(new CompletionWidget(this)) + , + _icon(new IconButton(this)) { - setLayoutDirection(Qt::LeftToRight); - // set initial icon - _icon->setIcon(KIcon("arrow-right")); + // set initial icon + //_icon->setIcon(QIcon("arrow-right")); + _icon->setIcon(QIcon::fromTheme("arrow-right")); + _icon->show(); - // initial style - setStyleSheet(QString("UrlBar { padding: 2px 0 2px %1px; height: %1px } ").arg(_icon->sizeHint().width())); + // initial style + setStyleSheet(QString("UrlBar { padding: 2px 0 2px %1px; height: %1px } ").arg(_icon->sizeHint().width() + 4)); - // doesn't show the clear button - setClearButtonShown(false); + // doesn't show the clear button + setClearButtonEnabled(false); - // enable dragging - setDragEnabled(true); + // TODO: enable dragging + // setDragEnabled(true); - // insert decoded URLs - setUrlDropsEnabled(true); + // TODO: insert decoded URLs + // setUrlDropsEnabled(true); - // tooltip - setToolTip(i18n("Type here to search your bookmarks, history and the web...")); + // tooltip + setToolTip(tr("Type here to search your bookmarks, history and the web...")); + setPlaceholderText(tr("Type here to search your bookmarks, history and the web...")); - // accept focus, via tabbing, clicking & wheeling - setFocusPolicy(Qt::WheelFocus); + // accept focus, via tabbing, clicking & wheeling + setFocusPolicy(Qt::WheelFocus); - // disable completion object (we have our own :) ) - setCompletionObject(0); + // TODO: disable completion object (we have our own :) ) + // setCompletionObject(0); - _tab = qobject_cast<WebTab *>(parent); + //_tab = qobject_cast<WebTab *>(parent); - connect(_tab, SIGNAL(loadProgressing()), this, SLOT(update())); + // connect(_tab, SIGNAL(loadProgressing()), this, SLOT(update())); - connect(_tab, SIGNAL(urlChanged(QUrl)), this, SLOT(setQUrl(QUrl))); - connect(_tab, SIGNAL(loadFinished(bool)), this, SLOT(loadFinished())); - connect(_tab, SIGNAL(loadStarted()), this, SLOT(loadStarted())); + // connect(_tab, SIGNAL(urlChanged(QUrl)), this, SLOT(setUrl(QUrl))); + connect(this, &QLineEdit::returnPressed, this, [this]() { loadRequestedUrl(QUrl::fromUserInput(text())); }); - // bookmark icon - connect(BookmarkManager::self(), SIGNAL(bookmarksUpdated()), this, SLOT(updateRightIcons())); + // bookmark icon + // connect(BookmarkManager::self(), SIGNAL(bookmarksUpdated()), this, SLOT(updateRightIcons())); - // suggestions - connect(_box.data(), SIGNAL(chosenUrl(KUrl,Rekonq::OpenType)), this, SLOT(loadRequestedUrl(KUrl,Rekonq::OpenType))); - connect(this, SIGNAL(textEdited(QString)), this, SLOT(detectTypedString(QString))); + // suggestions + // connect(_box.data(), SIGNAL(chosenUrl(QUrl,Rekonq::OpenType)), this, + // SLOT(loadRequestedUrl(QUrl,Rekonq::OpenType))); connect(this, SIGNAL(textEdited(QString)), this, + // SLOT(detectTypedString(QString))); - _suggestionTimer->setSingleShot(true); - connect(_suggestionTimer, SIGNAL(timeout()), this, SLOT(suggest())); + //_suggestionTimer->setSingleShot(true); + // connect(_suggestionTimer, SIGNAL(timeout()), this, SLOT(suggest())); } - -UrlBar::~UrlBar() +void UrlBar::setUrl(const QUrl &url) { - _suggestionTimer->stop(); - _box.clear(); + if (url.scheme() == QL1S("rekonq")) return; - disconnect(); -} + // we don't set empty url + if (url.isEmpty()) return; + clearFocus(); -void UrlBar::setQUrl(const QUrl& url) -{ - if (url.scheme() == QL1S("rekonq")) - return; + // Workaround for KLineEdit bug: incorrectly displaying + // unicode symbols at query parameter + const QByteArray urlTextData = url.toString().toUtf8(); + const QString humanReadableUrl = QString::fromUtf8(QByteArray::fromPercentEncoding(urlTextData).constData()); - // we don't set empty url - if (url.isEmpty()) - return; - - clearFocus(); - - // Workaround for KLineEdit bug: incorrectly displaying - // unicode symbols at query parameter - const QByteArray urlTextData = url.toString().toUtf8(); - const QString humanReadableUrl = QString::fromUtf8( - QByteArray::fromPercentEncoding(urlTextData).constData() - ); - - // End workaround - setText(humanReadableUrl); + // End workaround + setText(humanReadableUrl); - setCursorPosition(0); + setCursorPosition(0); } +// ----------------------------------------------------------------------------------------------------------- +// slots -void UrlBar::loadRequestedUrl(const KUrl& url, Rekonq::OpenType type) +void UrlBar::loadRequestedUrl(const QUrl &url, rekonq::OpenType type) { - clearFocus(); - - // Workaround for KLineEdit bug: incorrectly displaying - // unicode symbols at query parameter - const QByteArray urlTextData = url.prettyUrl().toUtf8(); - const QString humanReadableUrl = QString::fromUtf8( - QByteArray::fromPercentEncoding(urlTextData).constData() - ); - - // End workaround - setText(humanReadableUrl); - - rApp->loadUrl(url, type); + clearFocus(); + setText(url.toString()); + + Q_CHECK_PTR(m_currentView); + m_currentView->load(url); } +void UrlBar::loadStarted() +{ + if (sender() != m_currentView) return; + //_icon->setIcon(QIcon("text-html")); + // clearRightIcons(); + + repaint(); +} -void UrlBar::loadTypedUrl() +void UrlBar::loadProgress(int progress) { - KUrl urlToLoad; - if (!_box.isNull()) - { - urlToLoad = _box.data()->activeSuggestion(); - if (!urlToLoad.isEmpty()) - { - loadRequestedUrl(urlToLoad); - return; - } - } + if (sender() != m_currentView) return; + repaint(); +} - // fallback here - urlToLoad = UrlResolver::urlFromTextTyped(text()); - loadRequestedUrl(urlToLoad); +void UrlBar::loadFinished() +{ + if (sender() != m_currentView) return; + // refreshFavicon(); + // updateRightIcons(); + + repaint(); } +// ----------------------------------------------------------------------------------------------------------- +// events void UrlBar::paintEvent(QPaintEvent *event) { - KColorScheme colorScheme(palette().currentColorGroup()); - QColor backgroundColor; - QColor foregroundColor; + if (!m_currentView) return QLineEdit::paintEvent(event); - if (_tab->page()->settings()->testAttribute(QWebSettings::PrivateBrowsingEnabled)) - { - backgroundColor = QColor(220, 220, 220); // light gray - foregroundColor = Qt::black; - } - else - { - backgroundColor = rApp->palette().color(QPalette::Base); - foregroundColor = rApp->palette().color(QPalette::Text); - } + const auto backgroundColor = qApp->palette().color(QPalette::Base); + const auto foregroundColor = qApp->palette().color(QPalette::Text); - // set background color of UrlBar - QPalette p = palette(); + /*if (_tab->page()->settings()->testAttribute(QWebSettings::PrivateBrowsingEnabled)) + { + backgroundColor = QColor(220, 220, 220); // light gray + foregroundColor = Qt::black; + } + else*/ - int progr = _tab->progress(); - if (progr == 0 || progr == 100) - { - p.setBrush(QPalette::Base, backgroundColor); - p.setBrush(QPalette::Text, foregroundColor); - } - else - { - QColor highlight = rApp->palette().color(QPalette::Highlight); + // set background color of UrlBar + QPalette p = palette(); - int r = (highlight.red() + 2 * backgroundColor.red()) / 3; - int g = (highlight.green() + 2 * backgroundColor.green()) / 3; - int b = (highlight.blue() + 2 * backgroundColor.blue()) / 3; + const int progress = m_currentView->progress(); + if (progress == 0 || progress == 100) { + p.setBrush(QPalette::Base, backgroundColor); + p.setBrush(QPalette::Text, foregroundColor); + } + else { + QColor highlight = qApp->palette().color(QPalette::Highlight); - QColor loadingColor(r, g, b); + int r = (highlight.red() + 2 * backgroundColor.red()) / 3; + int g = (highlight.green() + 2 * backgroundColor.green()) / 3; + int b = (highlight.blue() + 2 * backgroundColor.blue()) / 3; - if (abs(loadingColor.lightness() - backgroundColor.lightness()) < 20) //eg. Gaia color scheme - { - r = (2 * highlight.red() + backgroundColor.red()) / 3; - g = (2 * highlight.green() + backgroundColor.green()) / 3; - b = (2 * highlight.blue() + backgroundColor.blue()) / 3; - loadingColor = QColor(r, g, b); - } + QColor loadingColor(r, g, b); - QLinearGradient gradient(QPoint(0, 0), QPoint(width(), 0)); - gradient.setColorAt(0, loadingColor); - gradient.setColorAt(((double)progr) / 100 - .000001, loadingColor); - gradient.setColorAt(((double)progr) / 100, backgroundColor); - p.setBrush(QPalette::Base, gradient); + if (abs(loadingColor.lightness() - backgroundColor.lightness()) < 20) // eg. Gaia color scheme + { + r = (2 * highlight.red() + backgroundColor.red()) / 3; + g = (2 * highlight.green() + backgroundColor.green()) / 3; + b = (2 * highlight.blue() + backgroundColor.blue()) / 3; + loadingColor = QColor(r, g, b); } - setPalette(p); - // you need this before our code to draw inside the line edit.. - KLineEdit::paintEvent(event); + QLinearGradient gradient(0, 0, width(), 0); + gradient.setColorAt(0, backgroundColor); + gradient.setColorAt(((double)progress) / 100 - .000001, loadingColor); + gradient.setColorAt(1, loadingColor); + p.setBrush(QPalette::Base, gradient); + } + setPalette(p); - if (text().isEmpty() && (progr == 0 || progr == 100)) - { - QStyleOptionFrame option; - initStyleOption(&option); - QRect textRect = style()->subElementRect(QStyle::SE_LineEditContents, &option, this); - QPainter painter(this); - painter.setPen(Qt::gray); - painter.drawText(textRect, - Qt::AlignVCenter | Qt::AlignCenter, - i18n("Type here to search your bookmarks, history and the web...") - ); - } + QLineEdit::paintEvent(event); } +void UrlBar::resizeEvent(QResizeEvent *event) +{ + int ih = _icon->sizeHint().height(); + int iconsCount = _rightIconsList.count(); + int iconHeight = (height() - ih) / 2; + + _icon->move(c_iconMargin, iconHeight); + + for (int i = 0; i < iconsCount; ++i) { + IconButton *bt = _rightIconsList.at(i); + // updateRightIconPosition(bt, i + 1); + } + QLineEdit::resizeEvent(event); +} + +/* void UrlBar::keyReleaseEvent(QKeyEvent *event) { QString trimmedText = text().trimmed(); @@ -315,14 +232,14 @@ void UrlBar::keyReleaseEvent(QKeyEvent *event) if (trimmedText.isEmpty()) { disconnect(_icon); - _icon->setIcon(KIcon("arrow-right")); + _icon->setIcon(QIcon("arrow-right")); return KLineEdit::keyReleaseEvent(event); } - + // this handles the Modifiers + Return key combinations if (event->key() == Qt::Key_Return || event->key() == Qt::Key_Enter) { - KUrl urlToLoad; + QUrl urlToLoad; switch (event->modifiers()) { case Qt::AltModifier: @@ -359,15 +276,8 @@ void UrlBar::keyReleaseEvent(QKeyEvent *event) KLineEdit::keyReleaseEvent(event); } - - -void UrlBar::focusInEvent(QFocusEvent *event) -{ - emit focusIn(); - KLineEdit::focusInEvent(event); -} - - +*/ +/* void UrlBar::dropEvent(QDropEvent *event) { // handles only plain-text with url format @@ -377,7 +287,7 @@ void UrlBar::dropEvent(QDropEvent *event) if (url.isValid()) { - setQUrl(url); + setUrl(url); loadRequestedUrl(text()); return; } @@ -387,35 +297,21 @@ void UrlBar::dropEvent(QDropEvent *event) KLineEdit::dropEvent(event); loadRequestedUrl(text()); } - - -void UrlBar::loadStarted() -{ - _icon->setIcon(KIcon("text-html")); - clearRightIcons(); -} - - -void UrlBar::loadFinished() -{ - refreshFavicon(); - updateRightIcons(); -} - - +*/ +/* void UrlBar::updateRightIcons() { if (_tab->isPageLoading()) return; clearRightIcons(); - + if (_tab->url().scheme() == QL1S("rekonq")) { update(); return; } - + // show bookmark info IconButton *bt = addRightIcon(UrlBar::BK); connect(bt, SIGNAL(clicked(QPoint)), this, SLOT(manageStarred(QPoint))); @@ -446,25 +342,26 @@ void UrlBar::updateRightIcons() // an update call int oneIconWidth = _icon->sizeHint().width(); int rightIconWidth = (oneIconWidth + c_iconMargin) * (_rightIconsList.count()); - setStyleSheet(QString("UrlBar { padding: 2px %2px 2px %1px; height: %1px } ").arg(oneIconWidth).arg(rightIconWidth)); + setStyleSheet(QString("UrlBar { padding: 2px %2px 2px %1px; height: %1px } +").arg(oneIconWidth).arg(rightIconWidth)); } - - +*/ +/* void UrlBar::mouseDoubleClickEvent(QMouseEvent *event) { Q_UNUSED(event); selectAll(); } - - +*/ +/* void UrlBar::contextMenuEvent(QContextMenuEvent* event) { - KMenu menu; + QMenu menu; const bool clipboardFilled = !rApp->clipboard()->text().isEmpty(); // Cut - KAction *a = KStandardAction::cut(this, SLOT(cut()), &menu); + QAction *a = KStandardAction::cut(this, SLOT(cut()), &menu); a->setEnabled(hasSelectedText()); menu.addAction(a); @@ -482,19 +379,19 @@ void UrlBar::contextMenuEvent(QContextMenuEvent* event) const QString clipboardText = rApp->clipboard()->text(); if (isValidURL(clipboardText) || clipboardText.isEmpty()) { - a = new KAction(i18n("Paste && Go"), &menu); + a = new QAction(i18n("Paste && Go"), &menu); connect(a, SIGNAL(triggered(bool)), this, SLOT(pasteAndGo())); } else { - a = new KAction(i18n("Paste && Search"), &menu); + a = new QAction(i18n("Paste && Search"), &menu); connect(a, SIGNAL(triggered(bool)), this, SLOT(pasteAndSearch())); } a->setEnabled(clipboardFilled); menu.addAction(a); // Delete - a = new KAction(KIcon("edit-delete"), i18n("Delete"), &menu); + a = new QAction(QIcon("edit-delete"), i18n("Delete"), &menu); connect(a, SIGNAL(triggered(bool)), this, SLOT(delSlot())); a->setEnabled(hasSelectedText()); menu.addAction(a); @@ -508,8 +405,8 @@ void UrlBar::contextMenuEvent(QContextMenuEvent* event) menu.exec(event->globalPos()); } - - +*/ +/* bool UrlBar::isValidURL(QString url) { bool isValid = false; @@ -529,8 +426,8 @@ bool UrlBar::isValidURL(QString url) return isValid; } - - +*/ +/* IconButton *UrlBar::addRightIcon(UrlBar::icon ic) { IconButton *rightIcon = new IconButton(this); @@ -538,30 +435,30 @@ IconButton *UrlBar::addRightIcon(UrlBar::icon ic) switch (ic) { case UrlBar::KGet: - rightIcon->setIcon(KIcon("download")); + rightIcon->setIcon(QIcon("download")); rightIcon->setToolTip(i18n("List all links with KGet")); break; case UrlBar::RSS: - rightIcon->setIcon(KIcon("application-rss+xml")); + rightIcon->setIcon(QIcon("application-rss+xml")); rightIcon->setToolTip(i18n("List all available RSS feeds")); break; case UrlBar::BK: - if (BookmarkManager::self()->bookmarkForUrl(_tab->url()).isNull() && + if (BookmarkManager::self()->bookmarkForUrl(_tab->url()).isNull() && !ReKonfig::previewUrls().contains(_tab->url().url())) { - rightIcon->setIcon(KIcon("bookmarks").pixmap(32, 32, QIcon::Disabled)); + rightIcon->setIcon(QIcon("bookmarks").pixmap(32, 32, QIcon::Disabled)); } else { - rightIcon->setIcon(KIcon("bookmarks")); + rightIcon->setIcon(QIcon("bookmarks")); } break; case UrlBar::SearchEngine: { - KIcon wsIcon("edit-web-search"); + QIcon wsIcon("edit-web-search"); if (wsIcon.isNull()) { - wsIcon = KIcon("preferences-web-browser-shortcuts"); + wsIcon = QIcon("preferences-web-browser-shortcuts"); } rightIcon->setIcon(wsIcon); rightIcon->setToolTip(i18n("Add search engine")); @@ -572,12 +469,12 @@ IconButton *UrlBar::addRightIcon(UrlBar::icon ic) QStringList hosts = ReKonfig::whiteReferer(); if (!hosts.contains(_tab->url().host())) { - rightIcon->setIcon(KIcon("preferences-web-browser-adblock")); + rightIcon->setIcon(QIcon("preferences-web-browser-adblock")); rightIcon->setToolTip(i18n("AdBlock is enabled on this site")); } else { - rightIcon->setIcon(KIcon("preferences-web-browser-adblock").pixmap(32, 32, QIcon::Disabled)); + rightIcon->setIcon(QIcon("preferences-web-browser-adblock").pixmap(32, 32, QIcon::Disabled)); rightIcon->setToolTip(i18n("AdBlock is not enabled on this site")); } break; @@ -596,38 +493,20 @@ IconButton *UrlBar::addRightIcon(UrlBar::icon ic) return rightIcon; } - - +*/ +/* void UrlBar::clearRightIcons() { qDeleteAll(_rightIconsList); _rightIconsList.clear(); } - - -void UrlBar::resizeEvent(QResizeEvent *event) -{ - int ih = _icon->sizeHint().height(); - int iconsCount = _rightIconsList.count(); - int iconHeight = (height() - ih) / 2; - - _icon->move(c_iconMargin, iconHeight); - - for (int i = 0; i < iconsCount; ++i) - { - IconButton *bt = _rightIconsList.at(i); - updateRightIconPosition(bt, i + 1); - } - - KLineEdit::resizeEvent(event); -} - - +*/ +/* void UrlBar::detectTypedString(const QString &typed) { if (typed.count() == 1) { - _icon->setIcon(KIcon("arrow-right")); + _icon->setIcon(QIcon("arrow-right")); QTimer::singleShot(0, this, SLOT(suggest())); return; } @@ -636,8 +515,8 @@ void UrlBar::detectTypedString(const QString &typed) _suggestionTimer->stop(); _suggestionTimer->start(100); } - - +*/ +/* void UrlBar::suggest() { if (!_box.isNull()) @@ -645,67 +524,67 @@ void UrlBar::suggest() _box.data()->suggestUrls(text().trimmed()); } } - - +*/ +/* void UrlBar::refreshFavicon() { _icon->disconnect(); - + const QString scheme = _tab->url().protocol(); - + if (_tab->page()->settings()->testAttribute(QWebSettings::PrivateBrowsingEnabled)) { - _icon->setIcon(KIcon("view-media-artist")); + _icon->setIcon(QIcon("view-media-artist")); return; } - + if (scheme == QL1S("https")) { if (_tab->page()->hasSslValid()) { - _icon->setIcon(KIcon("security-high")); + _icon->setIcon(QIcon("security-high")); } else { - _icon->setIcon(KIcon("security-low")); + _icon->setIcon(QIcon("security-low")); } - + connect(_icon, SIGNAL(clicked(QPoint)), this, SLOT(showSSLInfo(QPoint)), Qt::UniqueConnection); return; } if (scheme == QL1S("rekonq")) { - _icon->setIcon(KIcon("arrow-right")); + _icon->setIcon(QIcon("arrow-right")); return; } - _icon->setIcon(KIcon("text-html")); + _icon->setIcon(QIcon("text-html")); } - - +*/ +/* void UrlBar::pasteAndGo() { - KUrl urlToLoad = UrlResolver::urlFromTextTyped(rApp->clipboard()->text().trimmed()); + QUrl urlToLoad = UrlResolver::urlFromTextTyped(rApp->clipboard()->text().trimmed()); kDebug() << "Url to load: " << urlToLoad; loadRequestedUrl(urlToLoad); } - - +*/ +/* void UrlBar::pasteAndSearch() { KService::Ptr defaultEngine = SearchEngine::defaultEngine(); if (defaultEngine) - loadRequestedUrl(KUrl(SearchEngine::buildQuery(defaultEngine, QApplication::clipboard()->text().trimmed()))); + loadRequestedUrl(QUrl(SearchEngine::buildQuery(defaultEngine, QApplication::clipboard()->text().trimmed()))); } - - +*/ +/* void UrlBar::delSlot() { del(); } - - +*/ +/* void UrlBar::manageBookmarks() { if (_tab->url().scheme() == QL1S("rekonq")) @@ -719,7 +598,7 @@ void UrlBar::manageBookmarks() } // calculate position - int iconSize = IconSize(KIconLoader::Small) + c_iconMargin; + int iconSize = IconSize(QIconLoader::Small) + c_iconMargin; // Add a generic 10 to move it a bit below and right. // No need to be precise... @@ -732,8 +611,8 @@ void UrlBar::manageBookmarks() BookmarkWidget *widget = new BookmarkWidget(bookmark, window()); widget->showAt(p); } - - +*/ +/* void UrlBar::manageAdBlock(QPoint pos) { IconButton *bt = qobject_cast<IconButton *>(this->sender()); @@ -747,28 +626,28 @@ void UrlBar::manageAdBlock(QPoint pos) connect(widget, SIGNAL(updateIcon()), this, SLOT(updateRightIcons())); widget->showAt(pos); } - - +*/ +/* void UrlBar::updateRightIconPosition(IconButton *icon, int iconsCount) { // NOTE: cannot show a (let's say) 16x16 icon in a 16x16 square. // It needs some margin. It usually is 3, but using 4 (default rekonq icon margin) // seems NOT a big problem and let's us using just one const ;) - int iconSize = IconSize(KIconLoader::Small) + c_iconMargin; + int iconSize = IconSize(QIconLoader::Small) + c_iconMargin; int iconWidth = width() - ((iconSize + c_iconMargin) * iconsCount); int iconHeight = (height() - iconSize) / 2; icon->move(iconWidth, iconHeight); } - - +*/ +/* void UrlBar::showRSSInfo(QPoint pos) { QWebElementCollection col = _tab->page()->mainFrame()->findAllElements("link[type=\"application/rss+xml\"]"); col.append(_tab->page()->mainFrame()->findAllElements("link[type=\"application/atom+xml\"]")); - QMap<KUrl, QString> map; + QMap<QUrl, QString> map; Q_FOREACH(const QWebElement & el, col) { @@ -777,7 +656,7 @@ void UrlBar::showRSSInfo(QPoint pos) urlString = el.attribute("href"); else { - KUrl u = _tab->url(); + QUrl u = _tab->url(); // NOTE // cd() is probably better than setPath() here, // for all those url sites just having a path @@ -789,14 +668,14 @@ void UrlBar::showRSSInfo(QPoint pos) if (title.isEmpty()) title = el.attribute("href"); - map.insert(KUrl(urlString), title); + map.insert(QUrl(urlString), title); } RSSWidget *widget = new RSSWidget(map, window()); widget->showAt(pos); } - - +*/ +/* void UrlBar::showSSLInfo(QPoint pos) { if (_tab->url().scheme() == QL1S("https")) @@ -812,44 +691,44 @@ void UrlBar::showSSLInfo(QPoint pos) ); } } - - +*/ +/* void UrlBar::manageStarred(QPoint pos) { - KMenu menu; - KAction *a; + QMenu menu; + QAction *a; // Bookmarks if (BookmarkManager::self()->bookmarkForUrl(_tab->url()).isNull()) { - a = new KAction(KIcon(KIcon("bookmarks").pixmap(32, 32, QIcon::Disabled)), i18n("Add Bookmark"), &menu); + a = new QAction(QIcon(QIcon("bookmarks").pixmap(32, 32, QIcon::Disabled)), i18n("Add Bookmark"), &menu); connect(a, SIGNAL(triggered(bool)), this, SLOT(manageBookmarks())); } else { - a = new KAction(KIcon("bookmarks"), i18n("Edit Bookmark"), &menu); - connect(a, SIGNAL(triggered(bool)), this, SLOT(manageBookmarks())); + a = new QAction(QIcon("bookmarks"), i18n("Edit Bookmark"), &menu); + connect(a, SIGNAL(triggered(bool)), this, SLOT(manageBookmarks())); } menu.addAction(a); - + // Favorites if (ReKonfig::previewUrls().contains(_tab->url().url())) { - a = new KAction(KIcon("emblem-favorite"), i18n("Remove from Favorites"), &menu); - connect(a, SIGNAL(triggered(bool)), this, SLOT(removeFromFavorites())); + a = new QAction(QIcon("emblem-favorite"), i18n("Remove from Favorites"), &menu); + connect(a, SIGNAL(triggered(bool)), this, SLOT(removeFromFavorites())); } else { - a = new KAction(KIcon(KIcon("emblem-favorite").pixmap(32, 32, QIcon::Disabled)), i18n("Add to Favorites"), &menu); - connect(a, SIGNAL(triggered(bool)), this, SLOT(addToFavorites())); + a = new QAction(QIcon(QIcon("emblem-favorite").pixmap(32, 32, QIcon::Disabled)), i18n("Add to Favorites"), +&menu); connect(a, SIGNAL(triggered(bool)), this, SLOT(addToFavorites())); } menu.addAction(a); - + QPoint p(pos.x() - menu.sizeHint().width() + 15, pos.y() + 15); menu.exec(p); } - - +*/ +/* void UrlBar::addToFavorites() { if (_tab->url().scheme() == QL1S("rekonq")) @@ -870,8 +749,8 @@ void UrlBar::addToFavorites() updateRightIcons(); } - - +*/ +/* void UrlBar::removeFromFavorites() { if (_tab->url().scheme() == QL1S("rekonq")) @@ -886,13 +765,13 @@ void UrlBar::removeFromFavorites() ReKonfig::setPreviewNames(titles); updateRightIcons(); - } + } } - +*/ void UrlBar::clearUrlbar() { - clear(); - clearRightIcons(); - setFocus(); + clear(); + // TODO: clearRightIcons(); + setFocus(); } diff --git a/src/urlbar/urlbar.h b/src/urlbar/urlbar.h index 29531711..80aabedf 100644 --- a/src/urlbar/urlbar.h +++ b/src/urlbar/urlbar.h @@ -1,165 +1,117 @@ /* ============================================================ -* -* This file is a part of the rekonq project -* -* Copyright (C) 2008-2012 by Andrea Diamantini <adjam7 at gmail dot com> -* Copyright (C) 2009 by Domrachev Alexandr <alexandr.domrachev@gmail.com> -* Copyright (C) 2009 by Paweł Prażak <pawelprazak at gmail dot com> -* Copyright (C) 2009-2011 by Lionel Chauvin <megabigbug@yahoo.fr> -* -* -* 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 2 of -* the License or (at your option) version 3 or any later version -* accepted by the membership of KDE e.V. (or its successor approved -* by the membership of KDE e.V.), which shall act as a proxy -* defined in Section 14 of version 3 of the license. -* -* 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 URLBAR_H -#define URLBAR_H - -// Rekonq Includes -#include "rekonq_defines.h" - -// KDE Includes -#include <KUrl> -#include <KLineEdit> - -// Qt Includes -#include <QWeakPointer> + * The rekonq project + * ============================================================ + * SPDX-License-Identifier: GPL-2.0-or-later + * Copyright (C) 2008-2012 by Andrea Diamantini <adjam7 at gmail dot com> + * Copyright (C) 2009 by Domrachev Alexandr <alexandr.domrachev@gmail.com> + * Copyright (C) 2009 by Paweł Prażak <pawelprazak at gmail dot com> + * Copyright (C) 2009-2011 by Lionel Chauvin <megabigbug@yahoo.fr> + * SPDX-License-Identifier: GPL-3.0-only + * Copyright (C) 2022 aqua <aqua@iserlohn-fortress.net> + * ============================================================ + * Description: URL Bar + * ============================================================ */ + +#pragma once + +#include "../rekonq.hpp" +#include <QLineEdit> #include <QToolButton> +#include <rview.hpp> -// Forward Declarations -class QWidget; -class CompletionWidget; -class WebTab; -class QTimer; - - -class IconButton : public QToolButton -{ - Q_OBJECT +class IconButton : public QToolButton { + Q_OBJECT public: - explicit IconButton(QWidget *parent = 0); + explicit IconButton(QWidget *parent = nullptr); -Q_SIGNALS: - void clicked(QPoint); +signals: + void clicked(QPoint); protected: - void mouseReleaseEvent(QMouseEvent *event); + void mouseReleaseEvent(QMouseEvent *event); }; - // Definitions +class QProgressBar; typedef QList<IconButton *> IconButtonPointerList; - -// ------------------------------------------------------------------------------------ - - -class REKONQ_TESTS_EXPORT UrlBar : public KLineEdit -{ - Q_OBJECT +class UrlBar : public QLineEdit { + Q_OBJECT public: + enum Icon { KGet = 0x00000001, RSS = 0x00000010, BK = 0x00001000, SearchEngine = 0x00010000, AdBlock = 0x01000000 }; - enum icon - { - KGet = 0x00000001, - RSS = 0x00000010, - BK = 0x00001000, - SearchEngine = 0x00010000, - AdBlock = 0x01000000 - }; - - explicit UrlBar(QWidget *parent = 0); - ~UrlBar(); + explicit UrlBar(QWidget *parent = nullptr); + ~UrlBar() override = default; -public Q_SLOTS: - void setQUrl(const QUrl &url); +public slots: + void setCurrentView(RekonqView *view) + { + m_currentView = view; + loadProgress(view->progress()); + setUrl(view->url()); + } - /** - * Let us add bookmarks as the major browsers do - * - */ - void manageBookmarks(); + void setUrl(const QUrl &url); - void clearUrlbar(); + /** + * Let us add bookmarks as the major browsers do + * + */ + // void manageBookmarks(); -private Q_SLOTS: - void loadRequestedUrl(const KUrl& url, Rekonq::OpenType = Rekonq::CurrentTab); + void clearUrlbar(); - void loadStarted(); - void loadFinished(); + void loadRequestedUrl(const QUrl &url, rekonq::OpenType = rekonq::CurrentTab); - void clearRightIcons(); - void updateRightIcons(); + void loadStarted(); + void loadProgress(int); + void loadFinished(); - void detectTypedString(const QString &); - void suggest(); + // void clearRightIcons(); + // void updateRightIcons(); - void manageStarred(QPoint); - void manageAdBlock(QPoint); + // void detectTypedString(const QString &); + // void suggest(); - void addToFavorites(); - void removeFromFavorites(); + // void manageStarred(QPoint); + // void manageAdBlock(QPoint); - void refreshFavicon(); + // void addToFavorites(); + // void removeFromFavorites(); - void pasteAndGo(); - void pasteAndSearch(); - void delSlot(); - bool isValidURL(QString url); + // void refreshFavicon(); - /** - * Load typed url - */ - void loadTypedUrl(); + // void pasteAndGo(); + // void pasteAndSearch(); + // void delSlot(); + // bool isValidURL(QString url); - void showRSSInfo(QPoint); - void showSSLInfo(QPoint); + // void showRSSInfo(QPoint); + // void showSSLInfo(QPoint); protected: - void paintEvent(QPaintEvent *event); - void keyReleaseEvent(QKeyEvent *event); - void focusInEvent(QFocusEvent *event); - void dropEvent(QDropEvent *event); - void mouseDoubleClickEvent(QMouseEvent *); - void contextMenuEvent(QContextMenuEvent *event); - void resizeEvent(QResizeEvent *); - -Q_SIGNALS: - void focusIn(); + void paintEvent(QPaintEvent *event); + void resizeEvent(QResizeEvent *); + /* + void keyReleaseEvent(QKeyEvent *event); + void dropEvent(QDropEvent *event); + void mouseDoubleClickEvent(QMouseEvent *); + void contextMenuEvent(QContextMenuEvent *event); + */ private: - /** - * Updates right icon position, given its number in the right icons list - * and considering rekonq window position/dimension - */ - void updateRightIconPosition(IconButton *, int); - IconButton *addRightIcon(UrlBar::icon); - - QWeakPointer<CompletionWidget> _box; - WebTab *_tab; - - IconButton *_icon; - IconButtonPointerList _rightIconsList; - - QTimer *_suggestionTimer; + /** + * Updates right icon position, given its number in the right icons list + * and considering rekonq window position/dimension + */ + // void updateRightIconPosition(IconButton *, int); + // IconButton *addRightIcon(UrlBar::icon); + + // QWeakPointer<CompletionWidget> _box; + RekonqView *m_currentView = nullptr; + + IconButton *_icon; + IconButtonPointerList _rightIconsList; }; - - -#endif |