add base: browser window, hints, history, cookies, adblock
This commit is contained in:
@@ -0,0 +1,68 @@
|
||||
#include "statusbar.h"
|
||||
|
||||
#include <QHBoxLayout>
|
||||
#include <QLabel>
|
||||
#include <QStyle>
|
||||
#include <QTimer>
|
||||
|
||||
StatusBar::StatusBar(QWidget *parent)
|
||||
: QWidget(parent)
|
||||
, m_mode(new QLabel(this))
|
||||
, m_url(new QLabel(this))
|
||||
, m_progress(new QLabel(this))
|
||||
{
|
||||
setObjectName(QStringLiteral("statusBar"));
|
||||
|
||||
m_mode->setObjectName(QStringLiteral("statusMode"));
|
||||
m_url->setObjectName(QStringLiteral("statusUrl"));
|
||||
m_progress->setObjectName(QStringLiteral("statusProgress"));
|
||||
|
||||
m_url->setTextInteractionFlags(Qt::NoTextInteraction);
|
||||
|
||||
auto *layout = new QHBoxLayout(this);
|
||||
layout->setContentsMargins(4, 1, 4, 1);
|
||||
layout->setSpacing(8);
|
||||
layout->addWidget(m_mode);
|
||||
layout->addWidget(m_url, 1);
|
||||
layout->addWidget(m_progress);
|
||||
}
|
||||
|
||||
void StatusBar::setMode(const QString &mode)
|
||||
{
|
||||
m_mode->setText(mode.isEmpty() ? QString()
|
||||
: QStringLiteral("-- %1 --").arg(mode.toUpper()));
|
||||
m_mode->setVisible(!mode.isEmpty());
|
||||
}
|
||||
|
||||
void StatusBar::setUrl(const QString &url)
|
||||
{
|
||||
m_urlText = url;
|
||||
m_url->setText(url);
|
||||
}
|
||||
|
||||
void StatusBar::setProgress(int percent)
|
||||
{
|
||||
const bool loading = percent > 0 && percent < 100;
|
||||
m_progress->setText(loading ? QStringLiteral("[%1%]").arg(percent) : QString());
|
||||
m_progress->setVisible(loading);
|
||||
}
|
||||
|
||||
void StatusBar::showMessage(const QString &message, bool isError)
|
||||
{
|
||||
m_url->setProperty("error", isError);
|
||||
m_url->setText(message);
|
||||
|
||||
// Re-polish so the stylesheet picks up the changed property.
|
||||
m_url->style()->unpolish(m_url);
|
||||
m_url->style()->polish(m_url);
|
||||
|
||||
QTimer::singleShot(4000, this, &StatusBar::clearMessage);
|
||||
}
|
||||
|
||||
void StatusBar::clearMessage()
|
||||
{
|
||||
m_url->setProperty("error", false);
|
||||
m_url->style()->unpolish(m_url);
|
||||
m_url->style()->polish(m_url);
|
||||
m_url->setText(m_urlText);
|
||||
}
|
||||
Reference in New Issue
Block a user