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 | |
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/
-rw-r--r-- | CMakeLists.txt | 3 | ||||
-rw-r--r-- | src/CMakeLists.txt | 2 | ||||
-rw-r--r-- | src/application.hpp | 1 | ||||
-rw-r--r-- | src/plugins/rplugininterface.hpp | 2 | ||||
-rw-r--r-- | src/rekonq.hpp | 2 | ||||
-rw-r--r-- | src/rekonqwindow.cpp | 30 | ||||
-rw-r--r-- | src/rekonqwindow.ui | 55 | ||||
-rw-r--r-- | src/tabbar/CMakeLists.txt | 2 | ||||
-rw-r--r-- | src/tabbar/tabbar.cpp (renamed from src/tabwindow/tabbar.cpp) | 140 | ||||
-rw-r--r-- | src/tabbar/tabbar.h | 90 | ||||
-rw-r--r-- | src/tabwindow/tabbar.h | 111 | ||||
-rw-r--r-- | src/urlbar/CMakeLists.txt | 2 | ||||
-rw-r--r-- | src/urlbar/urlbar.cpp | 629 | ||||
-rw-r--r-- | src/urlbar/urlbar.h | 214 |
14 files changed, 557 insertions, 726 deletions
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 <QPointer> #include <QUrl> #include <QWidget> 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 <QtPlugin> #include <rsettings.hpp> #include <rview.hpp> 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 <config-version.h> // 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 @@ </rect> </property> <property name="windowTitle"> - <string>MainWindow</string> + <string>rekonq</string> </property> <widget class="QWidget" name="centralwidget"> <layout class="QVBoxLayout" name="verticalLayout"> - <property name="spacing"> - <number>0</number> - </property> - <property name="leftMargin"> - <number>0</number> - </property> - <property name="topMargin"> - <number>0</number> - </property> - <property name="rightMargin"> - <number>0</number> - </property> - <property name="bottomMargin"> - <number>0</number> - </property> <item> - <widget class="QTabWidget" name="tabWidget"/> + <layout class="QHBoxLayout" name="horizontalLayout_2"> + <item> + <widget class="TabBar" name="tabs" native="true"/> + </item> + <item> + <widget class="QToolButton" name="newTab"> + <property name="text"> + <string>Add Tab</string> + </property> + </widget> + </item> + </layout> + </item> + <item> + <layout class="QHBoxLayout" name="horizontalLayout"> + <item> + <widget class="UrlBar" name="urlBar"/> + </item> + </layout> + </item> + <item> + <widget class="QStackedWidget" name="views"/> </item> </layout> </widget> @@ -41,7 +47,7 @@ <x>0</x> <y>0</y> <width>800</width> - <height>22</height> + <height>30</height> </rect> </property> <widget class="QMenu" name="menurekonq"> @@ -75,6 +81,19 @@ </property> </action> </widget> + <customwidgets> + <customwidget> + <class>UrlBar</class> + <extends>QLineEdit</extends> + <header>urlbar/urlbar.h</header> + </customwidget> + <customwidget> + <class>TabBar</class> + <extends>QWidget</extends> + <header>tabbar/tabbar.h</header> + <container>1</container> + </customwidget> + </customwidgets> <resources/> <connections> <connection> 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/tabwindow/tabbar.cpp b/src/tabbar/tabbar.cpp index 40ced0a6..c8624bda 100644 --- a/src/tabwindow/tabbar.cpp +++ b/src/tabbar/tabbar.cpp @@ -1,63 +1,14 @@ /* ============================================================ -* -* This file is a part of the rekonq project -* -* Copyright (C) 2008-2012 by Andrea Diamantini <adjam7 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 -#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 <KAcceleratorManager> -#include <KAction> -#include <KColorScheme> -#include <KLocalizedString> -#include <KMenu> -#include <KUrl> - -// Qt Includes -#include <QLabel> -#include <QPropertyAnimation> -#include <QSignalMapper> -#include <QStyleOptionFrameV3> -#include <QMouseEvent> -#include <QTimer> + * 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-2011 by Lionel Chauvin <megabigbug@yahoo.fr> + * SPDX-License-Identifier: GPL-3.0-only + * Copyright (C) 2022 aqua <aqua@iserlohn-fortress.net> + * ============================================================ */ +#include "tabbar.h" static inline QByteArray highlightPropertyName(int index) { @@ -67,11 +18,9 @@ static inline QByteArray highlightPropertyName(int index) // ------------------------------------------------------------------------------------ - -TabBar::TabBar(QWidget *parent) - : KTabBar(parent) - , m_tabHighlightEffect(new TabHighlightEffect(this)) - , m_animationMapper(new QSignalMapper(this)) +TabBar::TabBar(QWidget *parent) : QTabBar(parent) +//, m_tabHighlightEffect(new TabHighlightEffect(this)) +//, m_animationMapper(new QSignalMapper(this)) { setElideMode(Qt::ElideRight); @@ -79,21 +28,42 @@ TabBar::TabBar(QWidget *parent) setMovable(true); setAcceptDrops(true); - // avoid ambiguos shortcuts. See BUG:275858 - KAcceleratorManager::setNoAccel(this); + connect(this, &QTabBar::tabMoved, this, [this](int from, int to) { m_views.move(from, to); }); - // context menu(s) - setContextMenuPolicy(Qt::CustomContextMenu); + connect(this, &QTabBar::tabCloseRequested, this, [this](int index) { + removeTab(index); + emit removeView(m_views.at(index)); + m_views.removeAt(index); + }); - connect(this, SIGNAL(contextMenu(int,QPoint)), this, SLOT(contextMenu(int,QPoint))); - connect(this, SIGNAL(emptyAreaContextMenu(QPoint)), this, SLOT(emptyAreaContextMenu(QPoint))); + /* + // context menu(s) + setContextMenuPolicy(Qt::CustomContextMenu); - // Highlight effect - connect(m_animationMapper, SIGNAL(mapped(int)), this, SLOT(removeAnimation(int))); - setGraphicsEffect(m_tabHighlightEffect); - m_tabHighlightEffect->setEnabled(true); + 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 { @@ -124,14 +94,14 @@ QSize TabBar::tabSizeHint(int index) const // 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; + if (h == 0) h = 30; - QSize ts = QSize(w, h); - return ts; + return {w, h}; } - +// ------------------------------------------------------------------------------------ +// slots +/* void TabBar::cloneTab() { KAction *a = qobject_cast<KAction *>(sender()); @@ -296,12 +266,13 @@ void TabBar::setTabHighlighted(int index, bool b) if (!b) { removeAnimation(index); - setTabTextColor(index, KColorScheme(QPalette::Active, KColorScheme::Window).foreground(KColorScheme::NormalText).color()); - return; + 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(); + const QColor highlightColor = KColorScheme(QPalette::Active, +KColorScheme::Window).foreground(KColorScheme::PositiveText).color(); if (tabTextColor(index) != highlightColor) { @@ -390,7 +361,7 @@ void TabBar::mouseMoveEvent(QMouseEvent *event) if (ReKonfig::hoveringTabOption() != 0) return; - + // Find the tab under the mouse const int tabIndex = tabAt(event->pos()); @@ -587,7 +558,7 @@ void TabBar::unpinTab() return; int index = a->data().toInt(); - + // Find the available index to move int availableIndex = 0; for (int i = 1; i < count(); i++) @@ -599,7 +570,7 @@ void TabBar::unpinTab() } availableIndex++; } - + TabWidget *w = qobject_cast<TabWidget *>(parent()); w->moveTab(index, availableIndex); index = availableIndex; @@ -625,3 +596,4 @@ void TabBar::unpinTab() 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 <adjam7 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: Tab Bar + * ============================================================ */ + +#pragma once + +#include <QPointer> +#include <QTabBar> +#include <rview.hpp> + +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<QByteArray, QPropertyAnimation*> m_highlightAnimation; + QSignalMapper *m_animationMapper; + + // tab preview + QWeakPointer<TabPreviewPopup> m_previewPopup; + int m_currentTabPreviewIndex; + bool m_isFirstTimeOnTab; + */ + static constexpr int c_baseTabWidth = 250; + static constexpr int c_minTabWidth = 50; + +private: + QList<QPointer<RekonqView>> m_views; +}; 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 <adjam7 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 TAB_BAR -#define TAB_BAR - - -// Rekonq Includes -#include "rekonq_defines.h" - -// KDE Includes -#include <KTabBar> - -#include <QPropertyAnimation> - -// 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<QByteArray, QPropertyAnimation*> m_highlightAnimation; - QSignalMapper *m_animationMapper; - - // tab preview - QWeakPointer<TabPreviewPopup> 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 <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 |