From fcd11edde50d65f272cfc1ebf211697d778af77e Mon Sep 17 00:00:00 2001 From: aqua Date: Tue, 23 Aug 2022 10:28:54 +0300 Subject: Add RekonqView_fake class --- src/CMakeLists.txt | 3 ++ src/application.cpp | 17 ++++++ src/rekonqwindow.cpp | 3 +- src/test/rview_fake.cpp | 56 ++++++++++++++++++++ src/test/rview_fake.h | 24 +++++++++ src/test/rview_fake.ui | 135 ++++++++++++++++++++++++++++++++++++++++++++++++ src/urlbar/urlbar.cpp | 43 +++++---------- src/urlbar/urlbar.h | 4 ++ 8 files changed, 254 insertions(+), 31 deletions(-) create mode 100644 src/test/rview_fake.cpp create mode 100644 src/test/rview_fake.h create mode 100644 src/test/rview_fake.ui (limited to 'src') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index d46537e9..75905f36 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -19,6 +19,9 @@ set(rekonq_SRCS plugins/rplugininterface.hpp #---------------------------------------- ) +if(${CMAKE_BUILD_TYPE} STREQUAL "Debug") + list(APPEND rekonq_SRCS test/rview_fake.cpp test/rview_fake.h test/rview_fake.ui) +endif() list(TRANSFORM rekonq_SRCS PREPEND src/) set(rekonq_SRCS ${rekonq_SRCS} PARENT_SCOPE) diff --git a/src/application.cpp b/src/application.cpp index aba1fc69..88466d73 100644 --- a/src/application.cpp +++ b/src/application.cpp @@ -20,6 +20,10 @@ #include #include +#ifdef QT_DEBUG +#include "test/rview_fake.h" +#endif + // --------------------------------------------------------------------------------------------------------------- // Ctor and Dtor @@ -383,6 +387,19 @@ RekonqWindow *Application::newWindow() RekonqView *Application::newView(const QUrl &url, RekonqWindow *window) { +#ifdef QT_DEBUG + if (url.isEmpty()) { + auto *view = new RekonqView_fake(window); + if (window == nullptr) { + m_views.append(view); + view->show(); + } + else + window->addView(view); + return view; + } +#endif + RekonqPluginInterface *interface = nullptr; for (const auto &plugin : m_plugins) if (plugin->hasScheme(url.scheme())) { diff --git a/src/rekonqwindow.cpp b/src/rekonqwindow.cpp index dff85dfb..34a8f5b5 100644 --- a/src/rekonqwindow.cpp +++ b/src/rekonqwindow.cpp @@ -34,8 +34,7 @@ RekonqWindow::RekonqWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::Re [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); }); + connect(ui->newTab, &QToolButton::clicked, this, [this]() { Application::instance()->newView(QUrl(), this); }); } RekonqWindow::~RekonqWindow() { delete ui; } diff --git a/src/test/rview_fake.cpp b/src/test/rview_fake.cpp new file mode 100644 index 00000000..bb7e91d6 --- /dev/null +++ b/src/test/rview_fake.cpp @@ -0,0 +1,56 @@ +#include "rview_fake.h" +#include "ui_rview_fake.h" +#include +#include + +RekonqView_fake::RekonqView_fake(QWidget *parent) : RekonqView(QUrl(), parent), ui(new Ui::RekonqView_fake) +{ + ui->setupUi(this); + + connect(ui->progress, &QSlider::valueChanged, this, [this](int value) { + switch (value) { + case 1: + emit loadStarted(); + spdlog::debug("RekonqView_fake loadStarted"); + break; + case 0: + case 100: + emit loadFinished(); + spdlog::debug("RekonqView_fake loadFinished"); + break; + default: + emit loadProgress(value); + break; + } + }); + connect(ui->setTitle, &QToolButton::clicked, this, [this]() { emit titleChanged(ui->title->text()); }); + connect(ui->setUrl, &QToolButton::clicked, this, [this]() { emit urlChanged(QUrl(ui->url->text())); }); +} +RekonqView_fake::~RekonqView_fake() { delete ui; } + +void RekonqView_fake::load(const QUrl &url) +{ + ui->url->setText(url.toString()); + spdlog::debug("{} url={}", std::source_location::current().function_name(), qUtf8Printable(url.toString())); +} +int RekonqView_fake::progress() const +{ + spdlog::debug("{} -> {}", std::source_location::current().function_name(), ui->progress->value()); + return ui->progress->value(); +} + +QIcon RekonqView_fake::icon() const +{ + spdlog::debug("{} -> empty QIcon", std::source_location::current().function_name()); + return {}; +} +QString RekonqView_fake::title() const +{ + spdlog::debug("{} -> {}", std::source_location::current().function_name(), qUtf8Printable(ui->title->text())); + return ui->title->text(); +} +QUrl RekonqView_fake::url() const +{ + spdlog::debug("{} -> {}", std::source_location::current().function_name(), qUtf8Printable(ui->url->text())); + return {ui->url->text()}; +} diff --git a/src/test/rview_fake.h b/src/test/rview_fake.h new file mode 100644 index 00000000..64a8351d --- /dev/null +++ b/src/test/rview_fake.h @@ -0,0 +1,24 @@ +#pragma once + +#include + +namespace Ui { +class RekonqView_fake; +} +class RekonqView_fake final : public RekonqView { + Q_OBJECT + +public: + explicit RekonqView_fake(QWidget *parent = nullptr); + ~RekonqView_fake() override; + + void load(const QUrl &url) override; + int progress() const override; + + QIcon icon() const override; + QString title() const override; + QUrl url() const override; + +private: + Ui::RekonqView_fake *ui; +}; diff --git a/src/test/rview_fake.ui b/src/test/rview_fake.ui new file mode 100644 index 00000000..a97ac61e --- /dev/null +++ b/src/test/rview_fake.ui @@ -0,0 +1,135 @@ + + + RekonqView_fake + + + + 0 + 0 + 400 + 300 + + + + + + + + + + + RekonqView_fake + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + Progress + + + + 0 + + + 0 + + + 0 + + + + + 100 + + + Qt::Horizontal + + + + + + + + + + + + Title + + + + + + + URL + + + + + + + + + RekonqView_fake + + + + + + + ... + + + + + + + + + + + rekonq__debug + + + + + + + ... + + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + diff --git a/src/urlbar/urlbar.cpp b/src/urlbar/urlbar.cpp index 67d77aa4..d9059833 100644 --- a/src/urlbar/urlbar.cpp +++ b/src/urlbar/urlbar.cpp @@ -47,10 +47,8 @@ QString guessUrlWithCustomFirstLevel(const QString &str1, const QString &str2) // ----------------------------------------------------------------------------------------------------------- UrlBar::UrlBar(QWidget *parent) - : QLineEdit(parent) - //, _box(new CompletionWidget(this)) - , - _icon(new IconButton(this)) + : QLineEdit(parent), _icon(new IconButton(this)), backgroundColor{qApp->palette().color(QPalette::Base)}, + highlightColor{qApp->palette().color(QPalette::Highlight)} { // set initial icon @@ -134,7 +132,8 @@ void UrlBar::loadRequestedUrl(const QUrl &url, rekonq::OpenType type) void UrlBar::loadStarted() { if (sender() != m_currentView) return; - //_icon->setIcon(QIcon("text-html")); + m_currentView_progress = 1; + _icon->setIcon(QIcon::fromTheme("text-html")); // clearRightIcons(); repaint(); @@ -143,12 +142,14 @@ void UrlBar::loadStarted() void UrlBar::loadProgress(int progress) { if (sender() != m_currentView) return; + m_currentView_progress = progress; repaint(); } void UrlBar::loadFinished() { if (sender() != m_currentView) return; + m_currentView_progress = 100; // refreshFavicon(); // updateRightIcons(); @@ -162,44 +163,28 @@ void UrlBar::paintEvent(QPaintEvent *event) { if (!m_currentView) return QLineEdit::paintEvent(event); - const auto backgroundColor = qApp->palette().color(QPalette::Base); - const auto foregroundColor = qApp->palette().color(QPalette::Text); - - /*if (_tab->page()->settings()->testAttribute(QWebSettings::PrivateBrowsingEnabled)) - { - backgroundColor = QColor(220, 220, 220); // light gray - foregroundColor = Qt::black; - } - else*/ - // set background color of UrlBar QPalette p = palette(); - const int progress = m_currentView->progress(); - if (progress == 0 || progress == 100) { - p.setBrush(QPalette::Base, backgroundColor); - p.setBrush(QPalette::Text, foregroundColor); - } + if (m_currentView_progress == 0 || m_currentView_progress == 100) p.setBrush(QPalette::Base, backgroundColor); else { - QColor highlight = qApp->palette().color(QPalette::Highlight); - - int r = (highlight.red() + 2 * backgroundColor.red()) / 3; - int g = (highlight.green() + 2 * backgroundColor.green()) / 3; - int b = (highlight.blue() + 2 * backgroundColor.blue()) / 3; + int r = (highlightColor.red() + 2 * backgroundColor.red()) / 3; + int g = (highlightColor.green() + 2 * backgroundColor.green()) / 3; + int b = (highlightColor.blue() + 2 * backgroundColor.blue()) / 3; QColor loadingColor(r, g, b); 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; + r = (2 * highlightColor.red() + backgroundColor.red()) / 3; + g = (2 * highlightColor.green() + backgroundColor.green()) / 3; + b = (2 * highlightColor.blue() + backgroundColor.blue()) / 3; loadingColor = QColor(r, g, b); } QLinearGradient gradient(0, 0, width(), 0); gradient.setColorAt(0, backgroundColor); - gradient.setColorAt(((double)progress) / 100 - .000001, loadingColor); + gradient.setColorAt(((double)m_currentView_progress) / 100, loadingColor); gradient.setColorAt(1, loadingColor); p.setBrush(QPalette::Base, gradient); } diff --git a/src/urlbar/urlbar.h b/src/urlbar/urlbar.h index 80aabedf..cdfcc14f 100644 --- a/src/urlbar/urlbar.h +++ b/src/urlbar/urlbar.h @@ -111,7 +111,11 @@ private: // QWeakPointer _box; RekonqView *m_currentView = nullptr; + int m_currentView_progress = 0; IconButton *_icon; IconButtonPointerList _rightIconsList; + + const QColor backgroundColor; + const QColor highlightColor; }; -- cgit v1.2.1