diff options
Diffstat (limited to 'lib/addressbar/addressbar.cpp')
-rw-r--r-- | lib/addressbar/addressbar.cpp | 43 |
1 files changed, 16 insertions, 27 deletions
diff --git a/lib/addressbar/addressbar.cpp b/lib/addressbar/addressbar.cpp index 355393e..82c2d2e 100644 --- a/lib/addressbar/addressbar.cpp +++ b/lib/addressbar/addressbar.cpp @@ -7,51 +7,40 @@ */ #include "addressbar.h" -#include "urllineedit.h" -#include <QProgressBar> +#include "ui_addressbar.h" #include <QShortcut> -#include <QVBoxLayout> AddressBar::AddressBar(const QHash<QString, QString> &config, QWidget *parent) : QWidget(parent) + , ui(new Ui::AddressBar) { - setLayout(new QVBoxLayout()); - layout()->setContentsMargins(0, 0, 0, 0); - layout()->setSpacing(0); + ui->setupUi(this); - urlBar = new UrlLineEdit(this); - urlBar->menuAction->setShortcut(QKeySequence(config.value("addressbar.shortcuts.menu"))); - layout()->addWidget(urlBar); + ui->urlBar->menuAction->setShortcut(QKeySequence(config.value("addressbar.shortcuts.menu"))); auto *focusShortcut = new QShortcut(QKeySequence(config.value("addressbar.shortcuts.focus")), parent); - connect(focusShortcut, &QShortcut::activated, urlBar, [=]() { - urlBar->setFocus(); - urlBar->selectAll(); + connect(focusShortcut, &QShortcut::activated, ui->urlBar, [=]() { + ui->urlBar->setFocus(); + ui->urlBar->selectAll(); }); - connect(urlBar, &UrlLineEdit::textEdited, [=](const QString &text) { - std::function<void(QStringList &)> callback = std::bind(&UrlLineEdit::updateCompleter, urlBar, std::placeholders::_1); + connect(ui->urlBar, &UrlLineEdit::textEdited, [=](const QString &text) { + std::function<void(QStringList &)> callback = std::bind(&UrlLineEdit::updateCompleter, ui->urlBar, std::placeholders::_1); emit complete(text, callback); }); - connect(urlBar, &UrlLineEdit::returnPressed, [=]() { - const QUrl url = QUrl::fromUserInput(urlBar->text()); + connect(ui->urlBar, &UrlLineEdit::returnPressed, [=]() { + const QUrl url = QUrl::fromUserInput(ui->urlBar->text()); // check if url contains \w+:// (matches protocol://) or contains a '.' (matches site.domain) // this is because single words are valid URLs for QUrl (searchterm becomes http://searchterm) // check for protocol://site because \. wouldn't match it (localhost is a search term; http://localhost is an address) - if(urlBar->text().contains(QRegularExpression("\\w+://|\\.")) && url.isValid()) { + if(ui->urlBar->text().contains(QRegularExpression("\\w+://|\\.")) && url.isValid()) { emit load(url); } else { - emit search(urlBar->text()); + emit search(ui->urlBar->text()); } }); - - progressBar = new QProgressBar(this); - progressBar->setObjectName("LoadingBar"); - progressBar->setMaximumHeight(5); - progressBar->setTextVisible(false); - layout()->addWidget(progressBar); } AddressBar::~AddressBar() @@ -62,11 +51,11 @@ AddressBar::~AddressBar() void AddressBar::setUrl(const QUrl &url) { if(url.isEmpty()) - urlBar->clear(); + ui->urlBar->clear(); else - urlBar->setUrl(url); + ui->urlBar->setUrl(url); } void AddressBar::setProgress(int value) { - progressBar->setValue(std::min(value, 100)); + ui->loadingBar->setValue(std::min(value, 100)); } |