From f7df477b1e8fa4528b6fe4f8b44c403f46e72d85 Mon Sep 17 00:00:00 2001 From: aqua Date: Mon, 22 Aug 2022 10:16:01 +0300 Subject: Add UrlBar and TabBar - move src/tabwindow/tabbar.* to src/tabbar/ --- CMakeLists.txt | 3 +- src/CMakeLists.txt | 2 + src/application.hpp | 1 + src/plugins/rplugininterface.hpp | 2 - src/rekonq.hpp | 2 +- src/rekonqwindow.cpp | 30 +- src/rekonqwindow.ui | 55 ++-- src/tabbar/CMakeLists.txt | 2 + src/tabbar/tabbar.cpp | 599 +++++++++++++++++++++++++++++++++++++ src/tabbar/tabbar.h | 90 ++++++ src/tabwindow/tabbar.cpp | 627 -------------------------------------- src/tabwindow/tabbar.h | 111 ------- src/urlbar/CMakeLists.txt | 2 + src/urlbar/urlbar.cpp | 629 ++++++++++++++++----------------------- src/urlbar/urlbar.h | 214 ++++++------- 15 files changed, 1100 insertions(+), 1269 deletions(-) create mode 100644 src/tabbar/CMakeLists.txt create mode 100644 src/tabbar/tabbar.cpp create mode 100644 src/tabbar/tabbar.h delete mode 100644 src/tabwindow/tabbar.cpp delete mode 100644 src/tabwindow/tabbar.h create mode 100644 src/urlbar/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index 9c769cbf..3509fad4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -92,6 +92,7 @@ configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config-version.h.cmake config-version # ================================================================================== # includes for all targets +include_directories(${CMAKE_CURRENT_BINARY_DIR}) include_directories(include) include_directories(${CMAKE_CURRENT_BINARY_DIR}) @@ -117,7 +118,7 @@ add_executable(rekonq ${rekonq_SRCS} third-party/resources.qrc target_include_directories(rekonq PRIVATE src) target_link_libraries(rekonq spdlog::spdlog Qt6::Widgets SingleApplication::SingleApplication - settings pluginloader + settings pluginloader tabbar urlbar ) add_custom_target(rekonq_check_license python scripts/check_license.py ${rekonq_SRCS} WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 9413217c..d46537e9 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -3,6 +3,8 @@ ADD_SUBDIRECTORY( data ) add_subdirectory(settings) add_subdirectory(plugins) +add_subdirectory(tabbar) +add_subdirectory(urlbar) ### ------- sources -------- diff --git a/src/application.hpp b/src/application.hpp index cc38bda9..95390f16 100644 --- a/src/application.hpp +++ b/src/application.hpp @@ -12,6 +12,7 @@ #pragma once #include "rekonq.hpp" +#include "rekonqwindow.h" #include #include #include diff --git a/src/plugins/rplugininterface.hpp b/src/plugins/rplugininterface.hpp index 0a12e3aa..e45f2422 100644 --- a/src/plugins/rplugininterface.hpp +++ b/src/plugins/rplugininterface.hpp @@ -9,8 +9,6 @@ #pragma once -#include "rsettings.hpp" -#include "rview.hpp" #include #include #include diff --git a/src/rekonq.hpp b/src/rekonq.hpp index dc16401f..4a9bf10d 100644 --- a/src/rekonq.hpp +++ b/src/rekonq.hpp @@ -10,7 +10,7 @@ #pragma once // Configurations -#include "config-version.h" +#include // Defines #include "rekonq_defines.h" diff --git a/src/rekonqwindow.cpp b/src/rekonqwindow.cpp index c2355afb..dff85dfb 100644 --- a/src/rekonqwindow.cpp +++ b/src/rekonqwindow.cpp @@ -19,18 +19,42 @@ RekonqWindow::RekonqWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::RekonqWindow) { ui->setupUi(this); + + connect(ui->tabs, &QTabBar::currentChanged, this, [this](int index) { + auto *view = ui->tabs->view(index); + Q_CHECK_PTR(view); + + ui->views->setCurrentWidget(view); + ui->urlBar->setCurrentView(view); + }); + connect(ui->tabs, &TabBar::removeView, this, [this](RekonqView *view) { ui->views->removeWidget(view); }); + + // connect actions connect(ui->actionSettings, &QAction::triggered, this, [this]() { (new SettingsDialog(Application::instance()->settings(), this))->show(); }); connect(ui->actionTaskManager, &QAction::triggered, this, [this]() { (new TaskManager(this))->show(); }); + + connect(ui->newTab, &QToolButton::clicked, this, + [this]() { Application::instance()->newView(QUrl("http://duckduckgo.com"), this); }); } RekonqWindow::~RekonqWindow() { delete ui; } void RekonqWindow::addView(RekonqView *view) { - const auto tabId = ui->tabWidget->addTab(view, view->title()); - connect(view, &RekonqView::titleChanged, this, - [this, tabId](const QString &title) { ui->tabWidget->setTabText(tabId, title); }); + Q_CHECK_PTR(view); + + ui->views->addWidget(view); + ui->tabs->addTab(view); + connect(view, &RekonqView::urlChanged, ui->urlBar, &UrlBar::setUrl); + connect(view, &RekonqView::titleChanged, [this, view](const QString &title) { + const auto index = ui->views->indexOf(view); + ui->tabs->setTabText(index, view->title()); + }); + + connect(view, &RekonqView::loadStarted, ui->urlBar, &UrlBar::loadStarted); + connect(view, &RekonqView::loadProgress, ui->urlBar, &UrlBar::loadProgress); + connect(view, &RekonqView::loadFinished, ui->urlBar, &UrlBar::loadFinished); } /* diff --git a/src/rekonqwindow.ui b/src/rekonqwindow.ui index ee76a408..1105f300 100644 --- a/src/rekonqwindow.ui +++ b/src/rekonqwindow.ui @@ -11,27 +11,33 @@ - MainWindow + rekonq - - 0 - - - 0 - - - 0 - - - 0 - - - 0 - - + + + + + + + + Add Tab + + + + + + + + + + + + + + @@ -41,7 +47,7 @@ 0 0 800 - 22 + 30 @@ -75,6 +81,19 @@ + + + UrlBar + QLineEdit +
urlbar/urlbar.h
+
+ + TabBar + QWidget +
tabbar/tabbar.h
+ 1 +
+
diff --git a/src/tabbar/CMakeLists.txt b/src/tabbar/CMakeLists.txt new file mode 100644 index 00000000..9333ef0a --- /dev/null +++ b/src/tabbar/CMakeLists.txt @@ -0,0 +1,2 @@ +add_library(tabbar STATIC tabbar.cpp tabbar.h) +target_link_libraries(tabbar PUBLIC Qt6::Widgets) \ No newline at end of file diff --git a/src/tabbar/tabbar.cpp b/src/tabbar/tabbar.cpp new file mode 100644 index 00000000..c8624bda --- /dev/null +++ b/src/tabbar/tabbar.cpp @@ -0,0 +1,599 @@ +/* ============================================================ + * The rekonq project + * ============================================================ + * SPDX-License-Identifier: GPL-2.0-or-later + * Copyright (C) 2008-2012 by Andrea Diamantini + * Copyright (C) 2009-2011 by Lionel Chauvin + * SPDX-License-Identifier: GPL-3.0-only + * Copyright (C) 2022 aqua + * ============================================================ */ + +#include "tabbar.h" + +static inline QByteArray highlightPropertyName(int index) +{ + return QByteArray("hAnim").append(QByteArray::number(index)); +} + + +// ------------------------------------------------------------------------------------ + +TabBar::TabBar(QWidget *parent) : QTabBar(parent) +//, m_tabHighlightEffect(new TabHighlightEffect(this)) +//, m_animationMapper(new QSignalMapper(this)) +{ + setElideMode(Qt::ElideRight); + + setTabsClosable(true); + setMovable(true); + setAcceptDrops(true); + + connect(this, &QTabBar::tabMoved, this, [this](int from, int to) { m_views.move(from, to); }); + + connect(this, &QTabBar::tabCloseRequested, this, [this](int index) { + removeTab(index); + emit removeView(m_views.at(index)); + m_views.removeAt(index); + }); + + /* + // context menu(s) + setContextMenuPolicy(Qt::CustomContextMenu); + + connect(this, SIGNAL(contextMenu(int,QPoint)), this, SLOT(contextMenu(int,QPoint))); + connect(this, SIGNAL(emptyAreaContextMenu(QPoint)), this, SLOT(emptyAreaContextMenu(QPoint))); + + // Highlight effect + connect(m_animationMapper, SIGNAL(mapped(int)), this, SLOT(removeAnimation(int))); + setGraphicsEffect(m_tabHighlightEffect); + m_tabHighlightEffect->setEnabled(true); + */ +} + +int TabBar::addTab(RekonqView *view) +{ + m_views.append(view); + const auto id = QTabBar::addTab(view->title()); + + connect(view, &RekonqView::titleChanged, this, [this, view](const QString &title) { + const int index = m_views.indexOf(view); + setTabText(index, title); + }); + + return id; +} + +// ------------------------------------------------------------------------------------ + +QSize TabBar::tabSizeHint(int index) const +{ + QWidget* p = qobject_cast(parent()); + + int w; + // if tab is pinned... + if (tabData(index).toBool()) + { + w = 36; + } + else + { + // available width is tab widget width minus addTabButton width + int tabWidgetWidth = p->size().width() - 24; + w = c_baseTabWidth; + if (w * count() > tabWidgetWidth) + { + w = tabWidgetWidth / count(); + if (w < c_minTabWidth) + { + w = c_minTabWidth; + } + } + } + + int h = size().height(); + + // this because it may happen sometimes (eg: exiting fullscreen) + // that tabbar height is set to ZERO. And this is NOT good... + if (h == 0) h = 30; + + return {w, h}; +} + +// ------------------------------------------------------------------------------------ +// slots +/* +void TabBar::cloneTab() +{ + KAction *a = qobject_cast(sender()); + if (a) + { + int index = a->data().toInt(); + emit cloneTab(index); + } +} + + +void TabBar::closeTab() +{ + KAction *a = qobject_cast(sender()); + if (a) + { + int index = a->data().toInt(); + emit closeTab(index); + } +} + + +void TabBar::closeOtherTabs() +{ + KAction *a = qobject_cast(sender()); + if (a) + { + int index = a->data().toInt(); + emit closeOtherTabs(index); + } +} + + +void TabBar::reloadTab() +{ + KAction *a = qobject_cast(sender()); + if (a) + { + int index = a->data().toInt(); + emit reloadTab(index); + } +} + + +void TabBar::detachTab() +{ + KAction *a = qobject_cast(sender()); + if (a) + { + int index = a->data().toInt(); + emit detachTab(index); + } +} + + +void TabBar::contextMenu(int tabIndex, const QPoint &pos) +{ + TabWidget *w = qobject_cast(parent()); + + QAction *a; + + KMenu menu; + + a = w->actionByName(QL1S("new_tab")); + menu.addAction(a); + + menu.addSeparator(); // ---------------------------------------------------------------- + + a = new KAction(KIcon("tab-duplicate"), i18n("Clone"), this); + a->setData(tabIndex); + connect(a, SIGNAL(triggered(bool)), this, SLOT(cloneTab())); + menu.addAction(a); + + a = new KAction(KIcon("view-refresh"), i18n("Reload"), this); + connect(a, SIGNAL(triggered(bool)), this, SLOT(reloadTab())); + a->setData(tabIndex); + menu.addAction(a); + + a = new KAction(KIcon("view-refresh"), i18n("Reload All"), this); + connect(a, SIGNAL(triggered(bool)), w, SLOT(reloadAllTabs())); + menu.addAction(a); + + if (count() > 1) + { + a = new KAction(KIcon("tab-detach"), i18n("Detach"), this); + connect(a, SIGNAL(triggered(bool)), this, SLOT(detachTab())); + a->setData(tabIndex); + menu.addAction(a); + } + + if (tabData(tabIndex).toBool()) + { + a = new KAction(i18n("Unpin Tab"), this); + connect(a, SIGNAL(triggered(bool)), this, SLOT(unpinTab())); + a->setData(tabIndex); + menu.addAction(a); + } + else + { + a = new KAction(i18n("Pin Tab"), this); + connect(a, SIGNAL(triggered(bool)), this, SLOT(pinTab())); + a->setData(tabIndex); + menu.addAction(a); + } + menu.addSeparator(); // ---------------------------------------------------------------- + + a = new KAction(KIcon("tab-close"), i18n("&Close"), this); + a->setData(tabIndex); + connect(a, SIGNAL(triggered(bool)), this, SLOT(closeTab())); + menu.addAction(a); + + if (count() > 1) + { + a = new KAction(KIcon("tab-close-other"), i18n("Close &Other Tabs"), this); + connect(a, SIGNAL(triggered(bool)), this, SLOT(closeOtherTabs())); + a->setData(tabIndex); + menu.addAction(a); + } + + menu.addSeparator(); + + + a = w->actionByName(QL1S("open_last_closed_tab")); + menu.addAction(a); + + if (count() > 1) + { + a = w->actionByName(QL1S("bookmark_all_tabs")); + menu.addAction(a); + } + + menu.exec(pos); +} + + +void TabBar::emptyAreaContextMenu(const QPoint &pos) +{ + TabWidget *w = qobject_cast(parent()); + + QAction *a; + + KMenu menu; + + a = w->actionByName(QL1S("new_tab")); + menu.addAction(a); + + a = w->actionByName(QL1S("open_last_closed_tab")); + menu.addAction(a); + + if (count() > 1) + { + a = w->actionByName(QL1S("bookmark_all_tabs")); + menu.addAction(a); + } + + menu.exec(pos); +} + + +void TabBar::setTabHighlighted(int index, bool b) +{ + if (!b) + { + removeAnimation(index); + setTabTextColor(index, KColorScheme(QPalette::Active, +KColorScheme::Window).foreground(KColorScheme::NormalText).color()); return; + } + + const QByteArray propertyName = highlightPropertyName(index); + const QColor highlightColor = KColorScheme(QPalette::Active, +KColorScheme::Window).foreground(KColorScheme::PositiveText).color(); + + if (tabTextColor(index) != highlightColor) + { + m_tabHighlightEffect->setEnabled(true); + m_tabHighlightEffect->setProperty(propertyName, qreal(0.9)); + QPropertyAnimation *anim = new QPropertyAnimation(m_tabHighlightEffect, propertyName); + m_highlightAnimation.insert(propertyName, anim); + + //setup the animation + anim->setStartValue(0.9); + anim->setEndValue(0.0); + anim->setDuration(500); + anim->setLoopCount(2); + anim->start(QAbstractAnimation::DeleteWhenStopped); + + m_animationMapper->setMapping(anim, index); + connect(anim, SIGNAL(finished()), m_animationMapper, SLOT(map())); + + setTabTextColor(index, highlightColor); + } +} + + +QRect TabBar::tabTextRect(int index) +{ + QStyleOptionTabV3 option; + initStyleOption(&option, index); + return style()->subElementRect(QStyle::SE_TabBarTabText, &option, this); +} + + +void TabBar::removeAnimation(int index) +{ + const QByteArray propertyName = highlightPropertyName(index); + m_tabHighlightEffect->setProperty(propertyName, QVariant()); //destroy the property + + QPropertyAnimation *anim = m_highlightAnimation.take(propertyName); + m_animationMapper->removeMappings(anim); + delete anim; + + if (m_highlightAnimation.isEmpty()) + m_tabHighlightEffect->setEnabled(false); +} + + +void TabBar::tabInserted(int index) +{ + // Find the available index to move + int availableIndex = index; + for (int i = index; i < count(); i++) + { + if (tabData(i).toBool()) + { + availableIndex++; + break; + } + } + + if (index < availableIndex) + { + TabWidget *w = qobject_cast(parent()); + w->moveTab(index, availableIndex); + } + + KTabBar::tabInserted(index); +} + + +void TabBar::tabRemoved(int index) +{ + hideTabPreview(); + removeAnimation(index); + + KTabBar::tabRemoved(index); +} + + +void TabBar::mouseMoveEvent(QMouseEvent *event) +{ + KTabBar::mouseMoveEvent(event); + + if (count() == 1) + { + return; + } + + if (ReKonfig::hoveringTabOption() != 0) + return; + + // Find the tab under the mouse + const int tabIndex = tabAt(event->pos()); + + // if found and not the current tab then show tab preview + if (tabIndex != -1 + && tabIndex != currentIndex() + && m_currentTabPreviewIndex != tabIndex + && event->buttons() == Qt::NoButton + ) + { + m_currentTabPreviewIndex = tabIndex; + + // if first time over tab, apply a small delay. If not, show it now! + m_isFirstTimeOnTab + ? QTimer::singleShot(200, this, SLOT(showTabPreview())) + : showTabPreview(); + } + + // if current tab or not found then hide previous tab preview + if (tabIndex == currentIndex() || tabIndex == -1) + { + hideTabPreview(); + } +} + + +void TabBar::leaveEvent(QEvent *event) +{ + hideTabPreview(); + m_isFirstTimeOnTab = true; + + KTabBar::leaveEvent(event); +} + + +void TabBar::mousePressEvent(QMouseEvent *event) +{ + hideTabPreview(); + + // just close tab on middle mouse click + if (event->button() == Qt::MidButton) + return; + + KTabBar::mousePressEvent(event); +} + + +void TabBar::mouseReleaseEvent(QMouseEvent *event) +{ + // count pinned tabs + int pinnedTabs = 0; + for (int i = 0; i < count(); i++) + { + if (tabData(i).toBool()) + pinnedTabs++; + } + + // fix unpinned ones + for (int i = 0; i < pinnedTabs; i++) + { + if (!tabData(i).toBool()) + { + TabWidget *w = qobject_cast(parent()); + w->moveTab(i, pinnedTabs); + w->setCurrentIndex(pinnedTabs); + } + } + + // fix pinned ones + for (int i = pinnedTabs; i < count(); i++) + { + if (tabData(i).toBool()) + { + TabWidget *w = qobject_cast(parent()); + w->moveTab(i, pinnedTabs - 1); + w->setCurrentIndex(pinnedTabs - 1); + } + } + KTabBar::mouseReleaseEvent(event); +} + + +void TabBar::tabLayoutChange() +{ + KTabBar::tabLayoutChange(); + emit tabLayoutChanged(); +} + + +void TabBar::showTabPreview() +{ + if (m_isFirstTimeOnTab) + m_isFirstTimeOnTab = false; + + //delete previous tab preview + delete m_previewPopup.data(); + m_previewPopup.clear(); + + TabWidget *tabW = qobject_cast(parent()); + + WebWindow *indexedTab = tabW->webWindow(m_currentTabPreviewIndex); + WebWindow *currentTab = tabW->webWindow(currentIndex()); + + // check if view && currentView exist before using them :) + if (!currentTab || !indexedTab) + return; + + // no previews during load + if (indexedTab->isLoading()) + return; + + int w = c_baseTabWidth; + int h = w * tabW->size().height() / tabW->size().width(); + + m_previewPopup = new TabPreviewPopup(indexedTab->tabPreview(w, h), indexedTab->url().url() , this); + + int tabBarWidth = tabW->size().width(); + int leftIndex = tabRect(m_currentTabPreviewIndex).x() + (tabRect(m_currentTabPreviewIndex).width() - w) / 2; + + if (leftIndex < 0) + { + leftIndex = 0; + } + else if (leftIndex + w > tabBarWidth) + { + leftIndex = tabBarWidth - w; + } + + QPoint pos(leftIndex, tabRect(m_currentTabPreviewIndex).y() + tabRect(m_currentTabPreviewIndex).height()); + m_previewPopup.data()->show(mapToGlobal(pos)); +} + + +void TabBar::hideTabPreview() +{ + if (!m_previewPopup.isNull()) + { + m_previewPopup.data()->hide(); + } + m_currentTabPreviewIndex = -1; +} + + +void TabBar::pinTab() +{ + KAction *a = qobject_cast(sender()); + if (!a) + return; + + int index = a->data().toInt(); + + // Find the available index to move + int availableIndex = 0; + for (int i = 0; i < count(); i++) + { + if (!tabData(i).toBool()) + { + availableIndex = i; + break; + } + } + + TabWidget *w = qobject_cast(parent()); + w->moveTab(index, availableIndex); + index = availableIndex; + + // set this tab data true to know this has been pinned + setTabData(index, true); + + tabButton(index, QTabBar::RightSide)->hide(); + setTabText(index, QString()); + + // workaround: "fix" the icon (or at least, try to...) + QLabel *label = qobject_cast(tabButton(index, QTabBar::LeftSide)); + if (!label) + label = new QLabel(this); + + label->resize(QSize(16,16)); + + setTabButton(index, QTabBar::LeftSide, 0); + setTabButton(index, QTabBar::LeftSide, label); + + KIcon ic = IconManager::self()->iconForUrl(w->webWindow(index)->url()); + label->setPixmap(ic.pixmap(16, 16)); + + SessionManager::self()->saveSession(); +} + + +void TabBar::unpinTab() +{ + KAction *a = qobject_cast(sender()); + if (!a) + return; + + int index = a->data().toInt(); + + // Find the available index to move + int availableIndex = 0; + for (int i = 1; i < count(); i++) + { + if (!tabData(i).toBool()) + { + availableIndex = i - 1; + break; + } + availableIndex++; + } + + TabWidget *w = qobject_cast(parent()); + w->moveTab(index, availableIndex); + index = availableIndex; + + tabButton(index, QTabBar::RightSide)->show(); + setTabText(index, w->webWindow(index)->title()); + + // set the tab data false to forget this pinned tab + setTabData(index, false); + + // workaround: "fix" the icon (or at least, try to...) + QLabel *label = qobject_cast(tabButton(index, QTabBar::LeftSide)); + if (!label) + label = new QLabel(this); + + label->resize(QSize(16,16)); + + setTabButton(index, QTabBar::LeftSide, 0); + setTabButton(index, QTabBar::LeftSide, label); + + KIcon ic = IconManager::self()->iconForUrl(w->webWindow(index)->url()); + label->setPixmap(ic.pixmap(16, 16)); + + SessionManager::self()->saveSession(); +} +*/ \ No newline at end of file diff --git a/src/tabbar/tabbar.h b/src/tabbar/tabbar.h new file mode 100644 index 00000000..c305d1b5 --- /dev/null +++ b/src/tabbar/tabbar.h @@ -0,0 +1,90 @@ +/* ============================================================ + * The rekonq project + * ============================================================ + * SPDX-License-Identifier: GPL-2.0-or-later + * Copyright (C) 2008-2012 by Andrea Diamantini + * Copyright (C) 2009-2011 by Lionel Chauvin + * SPDX-License-Identifier: GPL-3.0-only + * Copyright (C) 2022 aqua + * ============================================================ + * Description: Tab Bar + * ============================================================ */ + +#pragma once + +#include +#include +#include + +class TabBar : public QTabBar { + Q_OBJECT + +public: + explicit TabBar(QWidget *parent = nullptr); + + int addTab(RekonqView *view); + [[nodiscard]] RekonqView *view(int index) { return m_views.at(index); } + /* + void setTabHighlighted(int index, bool b); + QRect tabTextRect(int index); + */ + +signals: + void removeView(RekonqView *); + +protected: + [[nodiscard]] QSize tabSizeHint(int index) const override; + /* + virtual void mouseMoveEvent(QMouseEvent *event); + virtual void leaveEvent(QEvent *event); + virtual void mousePressEvent(QMouseEvent *event); + virtual void mouseReleaseEvent(QMouseEvent *event); + + virtual void tabInserted(int index); + virtual void tabRemoved(int index); + + virtual void tabLayoutChange(); + + Q_SIGNALS: + void cloneTab(int); + void closeTab(int); + void closeOtherTabs(int); + void reloadTab(int); + void detachTab(int); + void tabLayoutChanged(); + + private Q_SLOTS: + void cloneTab(); + void closeTab(); + void closeOtherTabs(); + void reloadTab(); + void detachTab(); + + void pinTab(); + void unpinTab(); + + void contextMenu(int, const QPoint &); + void emptyAreaContextMenu(const QPoint &); + + void removeAnimation(int index); + + void showTabPreview(); + void hideTabPreview(); + + private: + // highlightAnimation + TabHighlightEffect *m_tabHighlightEffect; + QHash m_highlightAnimation; + QSignalMapper *m_animationMapper; + + // tab preview + QWeakPointer m_previewPopup; + int m_currentTabPreviewIndex; + bool m_isFirstTimeOnTab; + */ + static constexpr int c_baseTabWidth = 250; + static constexpr int c_minTabWidth = 50; + +private: + QList> m_views; +}; diff --git a/src/tabwindow/tabbar.cpp b/src/tabwindow/tabbar.cpp deleted file mode 100644 index 40ced0a6..00000000 --- a/src/tabwindow/tabbar.cpp +++ /dev/null @@ -1,627 +0,0 @@ -/* ============================================================ -* -* This file is a part of the rekonq project -* -* Copyright (C) 2008-2012 by Andrea Diamantini -* Copyright (C) 2009-2011 by Lionel Chauvin -* -* -* 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 . -* -* ============================================================ */ - - -// Self Includes -#include "tabbar.h" -#include "tabbar.moc" - -// Auto Includes -#include "rekonq.h" - -// Local Includes -#include "tabwidget.h" - -#include "tabhighlighteffect.h" -#include "tabpreviewpopup.h" -#include "webwindow.h" - -#include "iconmanager.h" -#include "sessionmanager.h" - -// KDE Includes -#include -#include -#include -#include -#include -#include - -// Qt Includes -#include -#include -#include -#include -#include -#include - - -static inline QByteArray highlightPropertyName(int index) -{ - return QByteArray("hAnim").append(QByteArray::number(index)); -} - - -// ------------------------------------------------------------------------------------ - - -TabBar::TabBar(QWidget *parent) - : KTabBar(parent) - , m_tabHighlightEffect(new TabHighlightEffect(this)) - , m_animationMapper(new QSignalMapper(this)) -{ - setElideMode(Qt::ElideRight); - - setTabsClosable(true); - setMovable(true); - setAcceptDrops(true); - - // avoid ambiguos shortcuts. See BUG:275858 - KAcceleratorManager::setNoAccel(this); - - // context menu(s) - setContextMenuPolicy(Qt::CustomContextMenu); - - connect(this, SIGNAL(contextMenu(int,QPoint)), this, SLOT(contextMenu(int,QPoint))); - connect(this, SIGNAL(emptyAreaContextMenu(QPoint)), this, SLOT(emptyAreaContextMenu(QPoint))); - - // Highlight effect - connect(m_animationMapper, SIGNAL(mapped(int)), this, SLOT(removeAnimation(int))); - setGraphicsEffect(m_tabHighlightEffect); - m_tabHighlightEffect->setEnabled(true); -} - - -QSize TabBar::tabSizeHint(int index) const -{ - QWidget* p = qobject_cast(parent()); - - int w; - // if tab is pinned... - if (tabData(index).toBool()) - { - w = 36; - } - else - { - // available width is tab widget width minus addTabButton width - int tabWidgetWidth = p->size().width() - 24; - w = c_baseTabWidth; - if (w * count() > tabWidgetWidth) - { - w = tabWidgetWidth / count(); - if (w < c_minTabWidth) - { - w = c_minTabWidth; - } - } - } - - int h = size().height(); - - // this because it may happen sometimes (eg: exiting fullscreen) - // that tabbar height is set to ZERO. And this is NOT good... - if (h == 0) - h = 30; - - QSize ts = QSize(w, h); - return ts; -} - - -void TabBar::cloneTab() -{ - KAction *a = qobject_cast(sender()); - if (a) - { - int index = a->data().toInt(); - emit cloneTab(index); - } -} - - -void TabBar::closeTab() -{ - KAction *a = qobject_cast(sender()); - if (a) - { - int index = a->data().toInt(); - emit closeTab(index); - } -} - - -void TabBar::closeOtherTabs() -{ - KAction *a = qobject_cast(sender()); - if (a) - { - int index = a->data().toInt(); - emit closeOtherTabs(index); - } -} - - -void TabBar::reloadTab() -{ - KAction *a = qobject_cast(sender()); - if (a) - { - int index = a->data().toInt(); - emit reloadTab(index); - } -} - - -void TabBar::detachTab() -{ - KAction *a = qobject_cast(sender()); - if (a) - { - int index = a->data().toInt(); - emit detachTab(index); - } -} - - -void TabBar::contextMenu(int tabIndex, const QPoint &pos) -{ - TabWidget *w = qobject_cast(parent()); - - QAction *a; - - KMenu menu; - - a = w->actionByName(QL1S("new_tab")); - menu.addAction(a); - - menu.addSeparator(); // ---------------------------------------------------------------- - - a = new KAction(KIcon("tab-duplicate"), i18n("Clone"), this); - a->setData(tabIndex); - connect(a, SIGNAL(triggered(bool)), this, SLOT(cloneTab())); - menu.addAction(a); - - a = new KAction(KIcon("view-refresh"), i18n("Reload"), this); - connect(a, SIGNAL(triggered(bool)), this, SLOT(reloadTab())); - a->setData(tabIndex); - menu.addAction(a); - - a = new KAction(KIcon("view-refresh"), i18n("Reload All"), this); - connect(a, SIGNAL(triggered(bool)), w, SLOT(reloadAllTabs())); - menu.addAction(a); - - if (count() > 1) - { - a = new KAction(KIcon("tab-detach"), i18n("Detach"), this); - connect(a, SIGNAL(triggered(bool)), this, SLOT(detachTab())); - a->setData(tabIndex); - menu.addAction(a); - } - - if (tabData(tabIndex).toBool()) - { - a = new KAction(i18n("Unpin Tab"), this); - connect(a, SIGNAL(triggered(bool)), this, SLOT(unpinTab())); - a->setData(tabIndex); - menu.addAction(a); - } - else - { - a = new KAction(i18n("Pin Tab"), this); - connect(a, SIGNAL(triggered(bool)), this, SLOT(pinTab())); - a->setData(tabIndex); - menu.addAction(a); - } - menu.addSeparator(); // ---------------------------------------------------------------- - - a = new KAction(KIcon("tab-close"), i18n("&Close"), this); - a->setData(tabIndex); - connect(a, SIGNAL(triggered(bool)), this, SLOT(closeTab())); - menu.addAction(a); - - if (count() > 1) - { - a = new KAction(KIcon("tab-close-other"), i18n("Close &Other Tabs"), this); - connect(a, SIGNAL(triggered(bool)), this, SLOT(closeOtherTabs())); - a->setData(tabIndex); - menu.addAction(a); - } - - menu.addSeparator(); - - - a = w->actionByName(QL1S("open_last_closed_tab")); - menu.addAction(a); - - if (count() > 1) - { - a = w->actionByName(QL1S("bookmark_all_tabs")); - menu.addAction(a); - } - - menu.exec(pos); -} - - -void TabBar::emptyAreaContextMenu(const QPoint &pos) -{ - TabWidget *w = qobject_cast(parent()); - - QAction *a; - - KMenu menu; - - a = w->actionByName(QL1S("new_tab")); - menu.addAction(a); - - a = w->actionByName(QL1S("open_last_closed_tab")); - menu.addAction(a); - - if (count() > 1) - { - a = w->actionByName(QL1S("bookmark_all_tabs")); - menu.addAction(a); - } - - menu.exec(pos); -} - - -void TabBar::setTabHighlighted(int index, bool b) -{ - if (!b) - { - removeAnimation(index); - setTabTextColor(index, KColorScheme(QPalette::Active, KColorScheme::Window).foreground(KColorScheme::NormalText).color()); - return; - } - - const QByteArray propertyName = highlightPropertyName(index); - const QColor highlightColor = KColorScheme(QPalette::Active, KColorScheme::Window).foreground(KColorScheme::PositiveText).color(); - - if (tabTextColor(index) != highlightColor) - { - m_tabHighlightEffect->setEnabled(true); - m_tabHighlightEffect->setProperty(propertyName, qreal(0.9)); - QPropertyAnimation *anim = new QPropertyAnimation(m_tabHighlightEffect, propertyName); - m_highlightAnimation.insert(propertyName, anim); - - //setup the animation - anim->setStartValue(0.9); - anim->setEndValue(0.0); - anim->setDuration(500); - anim->setLoopCount(2); - anim->start(QAbstractAnimation::DeleteWhenStopped); - - m_animationMapper->setMapping(anim, index); - connect(anim, SIGNAL(finished()), m_animationMapper, SLOT(map())); - - setTabTextColor(index, highlightColor); - } -} - - -QRect TabBar::tabTextRect(int index) -{ - QStyleOptionTabV3 option; - initStyleOption(&option, index); - return style()->subElementRect(QStyle::SE_TabBarTabText, &option, this); -} - - -void TabBar::removeAnimation(int index) -{ - const QByteArray propertyName = highlightPropertyName(index); - m_tabHighlightEffect->setProperty(propertyName, QVariant()); //destroy the property - - QPropertyAnimation *anim = m_highlightAnimation.take(propertyName); - m_animationMapper->removeMappings(anim); - delete anim; - - if (m_highlightAnimation.isEmpty()) - m_tabHighlightEffect->setEnabled(false); -} - - -void TabBar::tabInserted(int index) -{ - // Find the available index to move - int availableIndex = index; - for (int i = index; i < count(); i++) - { - if (tabData(i).toBool()) - { - availableIndex++; - break; - } - } - - if (index < availableIndex) - { - TabWidget *w = qobject_cast(parent()); - w->moveTab(index, availableIndex); - } - - KTabBar::tabInserted(index); -} - - -void TabBar::tabRemoved(int index) -{ - hideTabPreview(); - removeAnimation(index); - - KTabBar::tabRemoved(index); -} - - -void TabBar::mouseMoveEvent(QMouseEvent *event) -{ - KTabBar::mouseMoveEvent(event); - - if (count() == 1) - { - return; - } - - if (ReKonfig::hoveringTabOption() != 0) - return; - - // Find the tab under the mouse - const int tabIndex = tabAt(event->pos()); - - // if found and not the current tab then show tab preview - if (tabIndex != -1 - && tabIndex != currentIndex() - && m_currentTabPreviewIndex != tabIndex - && event->buttons() == Qt::NoButton - ) - { - m_currentTabPreviewIndex = tabIndex; - - // if first time over tab, apply a small delay. If not, show it now! - m_isFirstTimeOnTab - ? QTimer::singleShot(200, this, SLOT(showTabPreview())) - : showTabPreview(); - } - - // if current tab or not found then hide previous tab preview - if (tabIndex == currentIndex() || tabIndex == -1) - { - hideTabPreview(); - } -} - - -void TabBar::leaveEvent(QEvent *event) -{ - hideTabPreview(); - m_isFirstTimeOnTab = true; - - KTabBar::leaveEvent(event); -} - - -void TabBar::mousePressEvent(QMouseEvent *event) -{ - hideTabPreview(); - - // just close tab on middle mouse click - if (event->button() == Qt::MidButton) - return; - - KTabBar::mousePressEvent(event); -} - - -void TabBar::mouseReleaseEvent(QMouseEvent *event) -{ - // count pinned tabs - int pinnedTabs = 0; - for (int i = 0; i < count(); i++) - { - if (tabData(i).toBool()) - pinnedTabs++; - } - - // fix unpinned ones - for (int i = 0; i < pinnedTabs; i++) - { - if (!tabData(i).toBool()) - { - TabWidget *w = qobject_cast(parent()); - w->moveTab(i, pinnedTabs); - w->setCurrentIndex(pinnedTabs); - } - } - - // fix pinned ones - for (int i = pinnedTabs; i < count(); i++) - { - if (tabData(i).toBool()) - { - TabWidget *w = qobject_cast(parent()); - w->moveTab(i, pinnedTabs - 1); - w->setCurrentIndex(pinnedTabs - 1); - } - } - KTabBar::mouseReleaseEvent(event); -} - - -void TabBar::tabLayoutChange() -{ - KTabBar::tabLayoutChange(); - emit tabLayoutChanged(); -} - - -void TabBar::showTabPreview() -{ - if (m_isFirstTimeOnTab) - m_isFirstTimeOnTab = false; - - //delete previous tab preview - delete m_previewPopup.data(); - m_previewPopup.clear(); - - TabWidget *tabW = qobject_cast(parent()); - - WebWindow *indexedTab = tabW->webWindow(m_currentTabPreviewIndex); - WebWindow *currentTab = tabW->webWindow(currentIndex()); - - // check if view && currentView exist before using them :) - if (!currentTab || !indexedTab) - return; - - // no previews during load - if (indexedTab->isLoading()) - return; - - int w = c_baseTabWidth; - int h = w * tabW->size().height() / tabW->size().width(); - - m_previewPopup = new TabPreviewPopup(indexedTab->tabPreview(w, h), indexedTab->url().url() , this); - - int tabBarWidth = tabW->size().width(); - int leftIndex = tabRect(m_currentTabPreviewIndex).x() + (tabRect(m_currentTabPreviewIndex).width() - w) / 2; - - if (leftIndex < 0) - { - leftIndex = 0; - } - else if (leftIndex + w > tabBarWidth) - { - leftIndex = tabBarWidth - w; - } - - QPoint pos(leftIndex, tabRect(m_currentTabPreviewIndex).y() + tabRect(m_currentTabPreviewIndex).height()); - m_previewPopup.data()->show(mapToGlobal(pos)); -} - - -void TabBar::hideTabPreview() -{ - if (!m_previewPopup.isNull()) - { - m_previewPopup.data()->hide(); - } - m_currentTabPreviewIndex = -1; -} - - -void TabBar::pinTab() -{ - KAction *a = qobject_cast(sender()); - if (!a) - return; - - int index = a->data().toInt(); - - // Find the available index to move - int availableIndex = 0; - for (int i = 0; i < count(); i++) - { - if (!tabData(i).toBool()) - { - availableIndex = i; - break; - } - } - - TabWidget *w = qobject_cast(parent()); - w->moveTab(index, availableIndex); - index = availableIndex; - - // set this tab data true to know this has been pinned - setTabData(index, true); - - tabButton(index, QTabBar::RightSide)->hide(); - setTabText(index, QString()); - - // workaround: "fix" the icon (or at least, try to...) - QLabel *label = qobject_cast(tabButton(index, QTabBar::LeftSide)); - if (!label) - label = new QLabel(this); - - label->resize(QSize(16,16)); - - setTabButton(index, QTabBar::LeftSide, 0); - setTabButton(index, QTabBar::LeftSide, label); - - KIcon ic = IconManager::self()->iconForUrl(w->webWindow(index)->url()); - label->setPixmap(ic.pixmap(16, 16)); - - SessionManager::self()->saveSession(); -} - - -void TabBar::unpinTab() -{ - KAction *a = qobject_cast(sender()); - if (!a) - return; - - int index = a->data().toInt(); - - // Find the available index to move - int availableIndex = 0; - for (int i = 1; i < count(); i++) - { - if (!tabData(i).toBool()) - { - availableIndex = i - 1; - break; - } - availableIndex++; - } - - TabWidget *w = qobject_cast(parent()); - w->moveTab(index, availableIndex); - index = availableIndex; - - tabButton(index, QTabBar::RightSide)->show(); - setTabText(index, w->webWindow(index)->title()); - - // set the tab data false to forget this pinned tab - setTabData(index, false); - - // workaround: "fix" the icon (or at least, try to...) - QLabel *label = qobject_cast(tabButton(index, QTabBar::LeftSide)); - if (!label) - label = new QLabel(this); - - label->resize(QSize(16,16)); - - setTabButton(index, QTabBar::LeftSide, 0); - setTabButton(index, QTabBar::LeftSide, label); - - KIcon ic = IconManager::self()->iconForUrl(w->webWindow(index)->url()); - label->setPixmap(ic.pixmap(16, 16)); - - SessionManager::self()->saveSession(); -} diff --git a/src/tabwindow/tabbar.h b/src/tabwindow/tabbar.h deleted file mode 100644 index f842c9ff..00000000 --- a/src/tabwindow/tabbar.h +++ /dev/null @@ -1,111 +0,0 @@ -/* ============================================================ -* -* This file is a part of the rekonq project -* -* Copyright (C) 2008-2012 by Andrea Diamantini -* Copyright (C) 2009-2011 by Lionel Chauvin -* -* -* 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 . -* -* ============================================================ */ - - -#ifndef TAB_BAR -#define TAB_BAR - - -// Rekonq Includes -#include "rekonq_defines.h" - -// KDE Includes -#include - -#include - -// Forward Declarations -class TabPreviewPopup; -class TabHighlightEffect; - -class QSignalMapper; - - -class TabBar : public KTabBar -{ - Q_OBJECT - -public: - explicit TabBar(QWidget *parent); - - void setTabHighlighted(int index, bool b); - QRect tabTextRect(int index); - -protected: - virtual QSize tabSizeHint(int index) const; - - virtual void mouseMoveEvent(QMouseEvent *event); - virtual void leaveEvent(QEvent *event); - virtual void mousePressEvent(QMouseEvent *event); - virtual void mouseReleaseEvent(QMouseEvent *event); - - virtual void tabInserted(int index); - virtual void tabRemoved(int index); - - virtual void tabLayoutChange(); - -Q_SIGNALS: - void cloneTab(int); - void closeTab(int); - void closeOtherTabs(int); - void reloadTab(int); - void detachTab(int); - void tabLayoutChanged(); - -private Q_SLOTS: - void cloneTab(); - void closeTab(); - void closeOtherTabs(); - void reloadTab(); - void detachTab(); - - void pinTab(); - void unpinTab(); - - void contextMenu(int, const QPoint &); - void emptyAreaContextMenu(const QPoint &); - - void removeAnimation(int index); - - void showTabPreview(); - void hideTabPreview(); - -private: - // highlightAnimation - TabHighlightEffect *m_tabHighlightEffect; - QHash m_highlightAnimation; - QSignalMapper *m_animationMapper; - - // tab preview - QWeakPointer m_previewPopup; - int m_currentTabPreviewIndex; - bool m_isFirstTimeOnTab; - - static const int c_baseTabWidth = 250; - static const int c_minTabWidth = 50; -}; - -#endif // TAB_BAR 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 -* Copyright (C) 2009 by Domrachev Alexandr -* Copyright (C) 2009 by Paweł Prażak -* Copyright (C) 2009-2011 by Lionel Chauvin -* -* -* 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 . -* -* ============================================================ */ - - -// Self Includes + * The rekonq project + * ============================================================ + * SPDX-License-Identifier: GPL-2.0-or-later + * Copyright (C) 2008-2012 by Andrea Diamantini + * Copyright (C) 2009 by Domrachev Alexandr + * Copyright (C) 2009 by Paweł Prażak + * Copyright (C) 2009-2011 by Lionel Chauvin + * SPDX-License-Identifier: GPL-3.0-only + * Copyright (C) 2022 aqua + * ============================================================ */ + #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 -#include -#include -#include -#include -#include -#include -#include -#include - -// Qt Includes -#include +#include +#include #include +#include #include -#include -#include -#include +#include // 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(parent); + //_tab = qobject_cast(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(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 map; + QMap 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 -* Copyright (C) 2009 by Domrachev Alexandr -* Copyright (C) 2009 by Paweł Prażak -* Copyright (C) 2009-2011 by Lionel Chauvin -* -* -* 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 . -* -* ============================================================ */ - - -#ifndef URLBAR_H -#define URLBAR_H - -// Rekonq Includes -#include "rekonq_defines.h" - -// KDE Includes -#include -#include - -// Qt Includes -#include + * The rekonq project + * ============================================================ + * SPDX-License-Identifier: GPL-2.0-or-later + * Copyright (C) 2008-2012 by Andrea Diamantini + * Copyright (C) 2009 by Domrachev Alexandr + * Copyright (C) 2009 by Paweł Prażak + * Copyright (C) 2009-2011 by Lionel Chauvin + * SPDX-License-Identifier: GPL-3.0-only + * Copyright (C) 2022 aqua + * ============================================================ + * Description: URL Bar + * ============================================================ */ + +#pragma once + +#include "../rekonq.hpp" +#include #include +#include -// 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 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 _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 _box; + RekonqView *m_currentView = nullptr; + + IconButton *_icon; + IconButtonPointerList _rightIconsList; }; - - -#endif -- cgit v1.2.1