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

Add options to select color+style for progresss locationbar.

This commit is contained in:
Franz Fellner 2012-09-19 10:08:30 +02:00
parent e59241f525
commit 8723382b5c
5 changed files with 242 additions and 24 deletions

View File

@ -52,7 +52,7 @@ LocationBar::LocationBar(QupZilla* mainClass)
, m_clearAction(0) , m_clearAction(0)
, m_holdingAlt(false) , m_holdingAlt(false)
, m_loadProgress(0) , m_loadProgress(0)
, m_loadFinished(true) , m_progressVisible(false)
{ {
setObjectName("locationbar"); setObjectName("locationbar");
setDragEnabled(true); setDragEnabled(true);
@ -87,6 +87,9 @@ LocationBar::LocationBar(QupZilla* mainClass)
connect(m_bookmarkIcon, SIGNAL(clicked(QPoint)), this, SLOT(bookmarkIconClicked())); connect(m_bookmarkIcon, SIGNAL(clicked(QPoint)), this, SLOT(bookmarkIconClicked()));
connect(down, SIGNAL(clicked(QPoint)), this, SLOT(showMostVisited())); connect(down, SIGNAL(clicked(QPoint)), this, SLOT(showMostVisited()));
connect(mApp->searchEnginesManager(), SIGNAL(activeEngineChanged()), this, SLOT(updatePlaceHolderText())); connect(mApp->searchEnginesManager(), SIGNAL(activeEngineChanged()), this, SLOT(updatePlaceHolderText()));
connect(mApp, SIGNAL(message(Qz::AppMessageType, bool)), SLOT(onMessage(Qz::AppMessageType, bool)));
loadSettings();
clearIcon(); clearIcon();
updatePlaceHolderText(); updatePlaceHolderText();
@ -96,6 +99,7 @@ void LocationBar::setWebView(TabbedWebView* view)
{ {
m_webView = view; m_webView = view;
connect(m_webView, SIGNAL(loadStarted()), SLOT(onLoadStarted()));
connect(m_webView, SIGNAL(loadProgress(int)), SLOT(onLoadProgress(int))); connect(m_webView, SIGNAL(loadProgress(int)), SLOT(onLoadProgress(int)));
connect(m_webView, SIGNAL(loadFinished(bool)), SLOT(onLoadFinished())); connect(m_webView, SIGNAL(loadFinished(bool)), SLOT(onLoadFinished()));
} }
@ -528,34 +532,59 @@ LocationBar::~LocationBar()
delete m_bookmarkIcon; delete m_bookmarkIcon;
} }
void LocationBar::onLoadStarted()
{
m_progressVisible = true;
}
void LocationBar::onLoadProgress(int progress) void LocationBar::onLoadProgress(int progress)
{ {
if (qzSettings->showLoadingProgress) { if (qzSettings->showLoadingProgress) {
m_loadFinished = false;
m_loadProgress = progress; m_loadProgress = progress;
repaint(); update();
} }
} }
void LocationBar::onLoadFinished() void LocationBar::onLoadFinished()
{ {
if (qzSettings->showLoadingProgress) { if (qzSettings->showLoadingProgress) {
m_loadFinished = false;
QTimer::singleShot(700, this, SLOT(hideProgress())); QTimer::singleShot(700, this, SLOT(hideProgress()));
} }
} }
void LocationBar::loadSettings()
{
Settings settings;
settings.beginGroup("AddressBar");
m_progressStyle = static_cast<ProgressStyle>(settings.value("ProgressStyle", 0).toInt());
bool customColor = settings.value("UseCustomProgressColor", false).toBool();
m_progressColor = customColor ? settings.value("CustomProgressColor", palette().color(QPalette::Highlight)).value<QColor>() : QColor();
settings.endGroup();
}
void LocationBar::onMessage(Qz::AppMessageType msg, bool state)
{
Q_UNUSED(state)
if (!qzSettings->showLoadingProgress) {
return;
}
if (msg == Qz::AM_ReloadSettings) {
loadSettings();
}
}
void LocationBar::hideProgress() void LocationBar::hideProgress()
{ {
if (qzSettings->showLoadingProgress) { if (qzSettings->showLoadingProgress) {
m_loadFinished = true; m_progressVisible = false;
repaint(); update();
} }
} }
void LocationBar::paintEvent(QPaintEvent* event) void LocationBar::paintEvent(QPaintEvent* event)
{ {
if (hasFocus() || !qzSettings->showLoadingProgress || m_loadFinished) { if (hasFocus()) {
LineEdit::paintEvent(event); LineEdit::paintEvent(event);
return; return;
} }
@ -580,22 +609,54 @@ void LocationBar::paintEvent(QPaintEvent* event)
const int height = fm.height(); const int height = fm.height();
QRect textRect(x, y, width, 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 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); if (qzSettings->showLoadingProgress && m_progressVisible) {
const int roundness = bar.height() / 4.0; QColor bg = m_progressColor;
p.drawRoundedRect(bar, roundness, roundness); if (!bg.isValid() || bg.alpha() == 0) {
bg = palette().color(QPalette::Base).darker(110);
if (!bg.isValid() || bg.alpha() == 0) {
bg = p_QupZilla->palette().color(QPalette::Base).darker(110);
}
}
p.setBrush(QBrush(bg));
QPen outlinePen(bg.darker(110), 0.8);
p.setPen(outlinePen);
switch (m_progressStyle) {
case ProgressFilled: {
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);
break;
}
case ProgressBottom: {
outlinePen.setWidthF(0.3);
outlinePen.setColor(outlinePen.color().darker(130));
p.setPen(outlinePen);
QRect bar(contentsRect.x(), contentsRect.bottom() - 2,
contentsRect.width()*m_loadProgress / 100.0, 3);
p.drawRoundedRect(bar, 1, 1);
break;
}
case ProgressTop: {
outlinePen.setWidthF(0.3);
outlinePen.setColor(outlinePen.color().darker(130));
p.setPen(outlinePen);
QRect bar(contentsRect.x(), contentsRect.top() + 1,
contentsRect.width()*m_loadProgress / 100.0, 3);
p.drawRoundedRect(bar, 1, 1);
break;
}
default:
break;
}
}
p.setPen(oldPen); p.setPen(oldPen);
// Qt::Alignment va = QStyle::visualAlignment(QApplication::layoutDirection(), QFlag(alignment())); QTextOption opt;
p.drawText(textRect, text()); opt.setWrapMode(QTextOption::NoWrap);
p.drawText(textRect, text(), opt);
} }

View File

@ -74,11 +74,20 @@ private slots:
void updatePlaceHolderText(); void updatePlaceHolderText();
void showCompletion(const QString &newText); void showCompletion(const QString &newText);
void onLoadStarted();
void onLoadProgress(int progress); void onLoadProgress(int progress);
void onLoadFinished(); void onLoadFinished();
void hideProgress(); void hideProgress();
void onMessage(Qz::AppMessageType, bool);
private: private:
enum ProgressStyle {
ProgressFilled,
ProgressBottom,
ProgressTop
};
void contextMenuEvent(QContextMenuEvent* event); void contextMenuEvent(QContextMenuEvent* event);
void focusInEvent(QFocusEvent* event); void focusInEvent(QFocusEvent* event);
void focusOutEvent(QFocusEvent* event); void focusOutEvent(QFocusEvent* event);
@ -94,6 +103,8 @@ private:
void showGoButton(); void showGoButton();
void hideGoButton(); void hideGoButton();
void loadSettings();
LocationCompleter m_completer; LocationCompleter m_completer;
BookmarkIcon* m_bookmarkIcon; BookmarkIcon* m_bookmarkIcon;
@ -112,7 +123,9 @@ private:
bool m_holdingAlt; bool m_holdingAlt;
int m_loadProgress; int m_loadProgress;
bool m_loadFinished; bool m_progressVisible;
ProgressStyle m_progressStyle;
QColor m_progressColor;
}; };
#endif // LOCATIONBAR_H #endif // LOCATIONBAR_H

View File

@ -49,6 +49,7 @@
#include <QFileDialog> #include <QFileDialog>
#include <QMessageBox> #include <QMessageBox>
#include <QCloseEvent> #include <QCloseEvent>
#include <QColorDialog>
Preferences::Preferences(QupZilla* mainClass, QWidget* parent) Preferences::Preferences(QupZilla* mainClass, QWidget* parent)
: QDialog(parent) : QDialog(parent)
@ -185,7 +186,17 @@ 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()); bool showPBinAB = settings.value("ShowLoadingProgress", false).toBool();
ui->showLoadingInAddressBar->setChecked(showPBinAB);
ui->adressProgressSettings->setEnabled(showPBinAB);
ui->progressStyleSelector->setCurrentIndex(settings.value("ProgressStyle", 0).toInt());
bool pbInABuseCC = settings.value("UseCustomProgressColor", false).toBool();
ui->checkBoxCustomProgressColor->setChecked(pbInABuseCC);
ui->progressBarColorSelector->setEnabled(pbInABuseCC);
QColor pbColor = settings.value("CustomProgressColor", p_QupZilla->palette().color(QPalette::Highlight)).value<QColor>();
setProgressBarColorIcon(pbColor);
connect(ui->customColorToolButton, SIGNAL(clicked(bool)), SLOT(selectCustomProgressBarColor()));
connect(ui->setProgressBarColorToHighlightButton, SIGNAL(clicked()), SLOT(setProgressBarColorIcon()));
settings.endGroup(); settings.endGroup();
//BROWSING //BROWSING
@ -870,6 +881,9 @@ void Preferences::saveSettings()
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.setValue("ShowLoadingProgress", ui->showLoadingInAddressBar->isChecked());
settings.setValue("ProgressStyle", ui->progressStyleSelector->currentIndex());
settings.setValue("UseCustomProgressColor", ui->checkBoxCustomProgressColor->isChecked());
settings.setValue("CustomProgressColor", ui->customColorToolButton->property("ProgressColor").value<QColor>());
settings.endGroup(); settings.endGroup();
//Languages //Languages
@ -936,3 +950,23 @@ Preferences::~Preferences()
delete m_pluginsList; delete m_pluginsList;
delete m_notification.data(); delete m_notification.data();
} }
void Preferences::setProgressBarColorIcon(QColor color)
{
const int size = style()->pixelMetric(QStyle::PM_ToolBarIconSize);
QPixmap pm(QSize(size, size));
if (!color.isValid()) {
color = p_QupZilla->palette().color(QPalette::Highlight);
}
pm.fill(color);
ui->customColorToolButton->setIcon(pm);
ui->customColorToolButton->setProperty("ProgressColor", color);
}
void Preferences::selectCustomProgressBarColor()
{
QColor newColor = QColorDialog::getColor(ui->customColorToolButton->property("ProgressColor").value<QColor>(), this, tr("Select Color"));
if (newColor.isValid()) {
setProgressBarColorIcon(newColor);
}
}

View File

@ -83,6 +83,9 @@ private slots:
void deleteProfile(); void deleteProfile();
void startProfileIndexChanged(QString index); void startProfileIndexChanged(QString index);
void setProgressBarColorIcon(QColor col = QColor());
void selectCustomProgressBarColor();
void setNotificationPreviewVisible(bool state); void setNotificationPreviewVisible(bool state);
private: private:

View File

@ -793,6 +793,80 @@
</property> </property>
</widget> </widget>
</item> </item>
<item>
<widget class="QWidget" name="adressProgressSettings" native="true">
<layout class="QHBoxLayout" name="horizontalLayout_18">
<item>
<widget class="QComboBox" name="progressStyleSelector">
<item>
<property name="text">
<string>Fill</string>
</property>
</item>
<item>
<property name="text">
<string>Bottom</string>
</property>
</item>
<item>
<property name="text">
<string>Top</string>
</property>
</item>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBoxCustomProgressColor">
<property name="toolTip">
<string>If unchecked the bar will adapt to the background color.</string>
</property>
<property name="text">
<string>custom color:</string>
</property>
</widget>
</item>
<item>
<widget class="QWidget" name="progressBarColorSelector" native="true">
<layout class="QHBoxLayout" name="horizontalLayout_19">
<item>
<widget class="QToolButton" name="customColorToolButton">
<property name="toolTip">
<string>Select color</string>
</property>
<property name="text">
<string>...</string>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="setProgressBarColorToHighlightButton">
<property name="toolTip">
<string>Many styles use Highlight color for the progressbar.</string>
</property>
<property name="text">
<string>set to &quot;Highlight&quot; color</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_9">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
<item> <item>
<widget class="QCheckBox" name="selectAllOnFocus"> <widget class="QCheckBox" name="selectAllOnFocus">
<property name="text"> <property name="text">
@ -2383,5 +2457,38 @@
<tabstop>showBookmarksToolbar</tabstop> <tabstop>showBookmarksToolbar</tabstop>
</tabstops> </tabstops>
<resources/> <resources/>
<connections/> <connections>
<connection>
<sender>showLoadingInAddressBar</sender>
<signal>toggled(bool)</signal>
<receiver>adressProgressSettings</receiver>
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>513</x>
<y>117</y>
</hint>
<hint type="destinationlabel">
<x>513</x>
<y>154</y>
</hint>
</hints>
</connection>
<connection>
<sender>checkBoxCustomProgressColor</sender>
<signal>toggled(bool)</signal>
<receiver>progressBarColorSelector</receiver>
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>405</x>
<y>152</y>
</hint>
<hint type="destinationlabel">
<x>567</x>
<y>157</y>
</hint>
</hints>
</connection>
</connections>
</ui> </ui>