1
mirror of https://invent.kde.org/network/falkon.git synced 2024-12-20 18:56:34 +01:00

New option to show loading progress in address bar.

- enable it in Preferences -> Tabs -> Address Bar
- patch by Franz Fellner

closes #236
This commit is contained in:
nowrep 2012-08-24 20:53:53 +02:00
parent 2acc6021aa
commit dd84a84bc0
8 changed files with 319 additions and 225 deletions

View File

@ -39,6 +39,7 @@
#include "qzsettings.h" #include "qzsettings.h"
#include <QClipboard> #include <QClipboard>
#include <QTimer>
LocationBar::LocationBar(QupZilla* mainClass) LocationBar::LocationBar(QupZilla* mainClass)
: LineEdit(mainClass) : LineEdit(mainClass)
@ -48,6 +49,8 @@ LocationBar::LocationBar(QupZilla* mainClass)
, m_pasteAndGoAction(0) , m_pasteAndGoAction(0)
, m_clearAction(0) , m_clearAction(0)
, m_holdingAlt(false) , m_holdingAlt(false)
, m_loadProgress(0)
, m_loadFinished(true)
{ {
setObjectName("locationbar"); setObjectName("locationbar");
setDragEnabled(true); setDragEnabled(true);
@ -86,6 +89,14 @@ LocationBar::LocationBar(QupZilla* mainClass)
updatePlaceHolderText(); updatePlaceHolderText();
} }
void LocationBar::setWebView(TabbedWebView* view)
{
m_webView = view;
connect(m_webView, SIGNAL(loadProgress(int)), SLOT(onLoadProgress(int)));
connect(m_webView, SIGNAL(loadFinished(bool)), SLOT(onLoadFinished()));
}
void LocationBar::setText(const QString &text) void LocationBar::setText(const QString &text)
{ {
LineEdit::setText(text); LineEdit::setText(text);
@ -484,3 +495,75 @@ LocationBar::~LocationBar()
{ {
delete m_bookmarkIcon; delete m_bookmarkIcon;
} }
void LocationBar::onLoadProgress(int progress)
{
if (qzSettings->showLoadingProgress) {
m_loadFinished = false;
m_loadProgress = progress;
repaint();
}
}
void LocationBar::onLoadFinished()
{
if (qzSettings->showLoadingProgress) {
m_loadFinished = false;
QTimer::singleShot(700, this, SLOT(hideProgress()));
}
}
void LocationBar::hideProgress()
{
if (qzSettings->showLoadingProgress) {
m_loadFinished = true;
repaint();
}
}
void LocationBar::paintEvent(QPaintEvent* event)
{
if (hasFocus() || !qzSettings->showLoadingProgress || m_loadFinished) {
LineEdit::paintEvent(event);
return;
}
QStyleOptionFrameV3 option;
initStyleOption(&option);
QPainter p(this);
p.setRenderHint(QPainter::Antialiasing, true);
p.setRenderHint(QPainter::TextAntialiasing, true);
style()->drawPrimitive(QStyle::PE_PanelLineEdit, &option, &p, this);
QRect contentsRect = style()->subElementRect(QStyle::SE_LineEditContents, &option, this);
int lm, tm, rm, bm;
getTextMargins(&lm, &tm, &rm, &bm);
contentsRect.adjust(lm, tm, -rm, -bm);
QFontMetrics fm = fontMetrics();
const int x = contentsRect.x() + 3;
const int y = contentsRect.y() + (contentsRect.height() - fm.height() + 1) / 2;
const int width = contentsRect.width() - 6;
const int height = fm.height();
QRect textRect(x, y, width, height);
QColor bg = palette().color(QPalette::Base);
if (!bg.isValid() || bg.alpha() == 0) {
bg = p_QupZilla->palette().color(QPalette::Base);
}
bg = bg.darker(110);
p.setBrush(QBrush(bg));
QPen oldPen = p.pen();
QPen outlinePen(bg.darker(110), 0.8);
p.setPen(outlinePen);
QRect bar = textRect.adjusted(-3, 0, 6 - (textRect.width() * (100.0 - m_loadProgress) / 100), 0);
const int roundness = bar.height() / 4.0;
p.drawRoundedRect(bar, roundness, roundness);
p.setPen(oldPen);
// Qt::Alignment va = QStyle::visualAlignment(QApplication::layoutDirection(), QFlag(alignment()));
p.drawText(textRect, text());
}

View File

@ -45,7 +45,7 @@ public:
explicit LocationBar(QupZilla* mainClass); explicit LocationBar(QupZilla* mainClass);
~LocationBar(); ~LocationBar();
void setWebView(TabbedWebView* view) { m_webView = view; } void setWebView(TabbedWebView* view);
TabbedWebView* webView() { return m_webView; } TabbedWebView* webView() { return m_webView; }
signals: signals:
@ -55,6 +55,9 @@ public slots:
void showUrl(const QUrl &url); void showUrl(const QUrl &url);
void setText(const QString &text); void setText(const QString &text);
protected:
virtual void paintEvent(QPaintEvent* event);
private slots: private slots:
void siteIconChanged(); void siteIconChanged();
void setPrivacy(bool state); void setPrivacy(bool state);
@ -70,6 +73,10 @@ private slots:
void updatePlaceHolderText(); void updatePlaceHolderText();
void showCompletion(const QString &newText); void showCompletion(const QString &newText);
void onLoadProgress(int progress);
void onLoadFinished();
void hideProgress();
private: private:
void contextMenuEvent(QContextMenuEvent* event); void contextMenuEvent(QContextMenuEvent* event);
void focusOutEvent(QFocusEvent* e); void focusOutEvent(QFocusEvent* e);
@ -100,6 +107,8 @@ private:
bool m_rssIconVisible; bool m_rssIconVisible;
bool m_holdingAlt; bool m_holdingAlt;
int m_loadProgress;
bool m_loadFinished;
}; };
#endif // LOCATIONBAR_H #endif // LOCATIONBAR_H

View File

@ -30,6 +30,7 @@ void QzSettings::loadSettings()
selectAllOnDoubleClick = settings.value("SelectAllTextOnDoubleClick", true).toBool(); selectAllOnDoubleClick = settings.value("SelectAllTextOnDoubleClick", true).toBool();
selectAllOnClick = settings.value("SelectAllTextOnClick", false).toBool(); selectAllOnClick = settings.value("SelectAllTextOnClick", false).toBool();
addCountryWithAlt = settings.value("AddCountryDomainWithAltKey", true).toBool(); addCountryWithAlt = settings.value("AddCountryDomainWithAltKey", true).toBool();
showLoadingProgress = settings.value("ShowLoadingProgress", false).toBool();
showLocationSuggestions = settings.value("showSuggestions", 0).toInt(); showLocationSuggestions = settings.value("showSuggestions", 0).toInt();
settings.endGroup(); settings.endGroup();

View File

@ -35,6 +35,7 @@ public:
bool selectAllOnDoubleClick; bool selectAllOnDoubleClick;
bool selectAllOnClick; bool selectAllOnClick;
bool addCountryWithAlt; bool addCountryWithAlt;
bool showLoadingProgress;
int showLocationSuggestions; int showLocationSuggestions;
// SearchEngines // SearchEngines

View File

@ -182,6 +182,7 @@ Preferences::Preferences(QupZilla* mainClass, QWidget* parent)
ui->selectAllOnFocus->setChecked(settings.value("SelectAllTextOnDoubleClick", true).toBool()); ui->selectAllOnFocus->setChecked(settings.value("SelectAllTextOnDoubleClick", true).toBool());
ui->selectAllOnClick->setChecked(settings.value("SelectAllTextOnClick", false).toBool()); ui->selectAllOnClick->setChecked(settings.value("SelectAllTextOnClick", false).toBool());
ui->addCountryWithAlt->setChecked(settings.value("AddCountryDomainWithAltKey", true).toBool()); ui->addCountryWithAlt->setChecked(settings.value("AddCountryDomainWithAltKey", true).toBool());
ui->showLoadingInAddressBar->setChecked(settings.value("ShowLoadingProgress", false).toBool());
settings.endGroup(); settings.endGroup();
//BROWSING //BROWSING
@ -867,6 +868,7 @@ void Preferences::saveSettings()
settings.setValue("SelectAllTextOnDoubleClick", ui->selectAllOnFocus->isChecked()); settings.setValue("SelectAllTextOnDoubleClick", ui->selectAllOnFocus->isChecked());
settings.setValue("SelectAllTextOnClick", ui->selectAllOnClick->isChecked()); settings.setValue("SelectAllTextOnClick", ui->selectAllOnClick->isChecked());
settings.setValue("AddCountryDomainWithAltKey", ui->addCountryWithAlt->isChecked()); settings.setValue("AddCountryDomainWithAltKey", ui->addCountryWithAlt->isChecked());
settings.setValue("ShowLoadingProgress", ui->showLoadingInAddressBar->isChecked());
settings.endGroup(); settings.endGroup();
//Languages //Languages

View File

@ -602,147 +602,18 @@
</layout> </layout>
</widget> </widget>
<widget class="QWidget" name="stackedWidgetPage3"> <widget class="QWidget" name="stackedWidgetPage3">
<layout class="QGridLayout" name="gridLayout"> <layout class="QVBoxLayout" name="verticalLayout_4">
<item row="0" column="0" colspan="2"> <item>
<widget class="QLabel" name="label_13"> <widget class="QTabWidget" name="tabWidget_3">
<property name="text"> <property name="currentIndex">
<string>&lt;b&gt;Tabs behavior&lt;/b&gt;</string> <number>0</number>
</property> </property>
</widget> <widget class="QWidget" name="tab_6">
</item> <attribute name="title">
<item row="1" column="0"> <string>Tabs behavior</string>
<spacer name="horizontalSpacer_9"> </attribute>
<property name="orientation"> <layout class="QVBoxLayout" name="verticalLayout_2">
<enum>Qt::Horizontal</enum> <item>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="1" column="2">
<spacer name="horizontalSpacer_16">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="6" column="1">
<widget class="QCheckBox" name="hideTabsOnTab">
<property name="text">
<string>Hide tabs when there is only one tab</string>
</property>
</widget>
</item>
<item row="9" column="1">
<widget class="QCheckBox" name="activateLastTab">
<property name="text">
<string>Activate last tab when closing active tab</string>
</property>
</widget>
</item>
<item row="10" column="1">
<widget class="QCheckBox" name="openNewTabAfterActive">
<property name="text">
<string>Open new tabs after active tab</string>
</property>
</widget>
</item>
<item row="12" column="1">
<widget class="QCheckBox" name="dontQuitOnTab">
<property name="text">
<string>Don't quit upon closing last tab</string>
</property>
</widget>
</item>
<item row="13" column="1">
<widget class="QCheckBox" name="askWhenClosingMultipleTabs">
<property name="text">
<string>Ask when closing multiple tabs</string>
</property>
</widget>
</item>
<item row="14" column="1">
<widget class="QCheckBox" name="closedInsteadOpened">
<property name="text">
<string>Closed tabs list instead of opened in tab bar</string>
</property>
</widget>
</item>
<item row="15" column="1">
<spacer name="verticalSpacer_7">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item row="16" column="0" colspan="2">
<widget class="QLabel" name="label_25">
<property name="text">
<string>&lt;b&gt;Address Bar behaviour&lt;/b&gt;</string>
</property>
</widget>
</item>
<item row="18" column="1" colspan="2">
<widget class="QCheckBox" name="selectAllOnFocus">
<property name="text">
<string>Select all text by double clicking in address bar</string>
</property>
</widget>
</item>
<item row="19" column="1">
<widget class="QCheckBox" name="selectAllOnClick">
<property name="text">
<string>Select all text by clicking in address bar</string>
</property>
</widget>
</item>
<item row="20" column="1">
<widget class="QCheckBox" name="addCountryWithAlt">
<property name="text">
<string>Add .co.uk domain by pressing ALT key</string>
</property>
</widget>
</item>
<item row="21" column="1">
<spacer name="verticalSpacer_8">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item row="11" column="1">
<widget class="QCheckBox" name="switchToNewTabs">
<property name="text">
<string>Automatically switch to newly opened tab</string>
</property>
</widget>
</item>
<item row="1" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_15"> <layout class="QHBoxLayout" name="horizontalLayout_15">
<item> <item>
<widget class="QCheckBox" name="showTabPreviews"> <widget class="QCheckBox" name="showTabPreviews">
@ -774,9 +645,91 @@
</property> </property>
</widget> </widget>
</item> </item>
<item>
<spacer name="horizontalSpacer_16">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>63</width>
<height>13</height>
</size>
</property>
</spacer>
</item>
</layout> </layout>
</item> </item>
<item row="17" column="1" colspan="2"> <item>
<widget class="QCheckBox" name="hideTabsOnTab">
<property name="text">
<string>Hide tabs when there is only one tab</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="activateLastTab">
<property name="text">
<string>Activate last tab when closing active tab</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="openNewTabAfterActive">
<property name="text">
<string>Open new tabs after active tab</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="switchToNewTabs">
<property name="text">
<string>Automatically switch to newly opened tab</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="dontQuitOnTab">
<property name="text">
<string>Don't quit upon closing last tab</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="askWhenClosingMultipleTabs">
<property name="text">
<string>Ask when closing multiple tabs</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="closedInsteadOpened">
<property name="text">
<string>Closed tabs list instead of opened in tab bar</string>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer_8">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<widget class="QWidget" name="tab_7">
<attribute name="title">
<string>Address Bar behavior</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_16"> <layout class="QHBoxLayout" name="horizontalLayout_16">
<item> <item>
<widget class="QLabel" name="label_59"> <widget class="QLabel" name="label_59">
@ -833,6 +786,51 @@
</item> </item>
</layout> </layout>
</item> </item>
<item>
<widget class="QCheckBox" name="showLoadingInAddressBar">
<property name="text">
<string>Show loading progress in address bar</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="selectAllOnFocus">
<property name="text">
<string>Select all text by double clicking in address bar</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="selectAllOnClick">
<property name="text">
<string>Select all text by clicking in address bar</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="addCountryWithAlt">
<property name="text">
<string>Add .co.uk domain by pressing ALT key</string>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer_7">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</widget>
</item>
</layout> </layout>
</widget> </widget>
<widget class="QWidget" name="stackedWidgetPage4"> <widget class="QWidget" name="stackedWidgetPage4">

View File

@ -49,7 +49,7 @@ TabbedWebView::TabbedWebView(QupZilla* mainClass, WebTab* webTab)
, m_rssChecked(false) , m_rssChecked(false)
{ {
connect(this, SIGNAL(loadStarted()), this, SLOT(slotLoadStarted())); connect(this, SIGNAL(loadStarted()), this, SLOT(slotLoadStarted()));
connect(this, SIGNAL(loadProgress(int)), this, SLOT(slotLoadProgress(int))); connect(this, SIGNAL(loadProgress(int)), this, SLOT(loadProgress(int)));
connect(this, SIGNAL(loadFinished(bool)), this, SLOT(slotLoadFinished())); connect(this, SIGNAL(loadFinished(bool)), this, SLOT(slotLoadFinished()));
connect(this, SIGNAL(urlChanged(QUrl)), this, SLOT(urlChanged(QUrl))); connect(this, SIGNAL(urlChanged(QUrl)), this, SLOT(urlChanged(QUrl)));
@ -128,7 +128,7 @@ void TabbedWebView::urlChanged(const QUrl &url)
} }
} }
void TabbedWebView::slotLoadProgress(int prog) void TabbedWebView::loadProgress(int prog)
{ {
if (prog > 60) { if (prog > 60) {
checkRss(); checkRss();

View File

@ -63,7 +63,7 @@ public slots:
void showIcon(); void showIcon();
void slotLoadStarted(); void slotLoadStarted();
void slotLoadProgress(int prog); void loadProgress(int prog);
void userLoadAction(const QUrl &url); void userLoadAction(const QUrl &url);