mirror of
https://invent.kde.org/network/falkon.git
synced 2024-12-20 10:46:35 +01:00
Add options to select color+style for progresss locationbar.
This commit is contained in:
parent
e59241f525
commit
8723382b5c
@ -52,7 +52,7 @@ LocationBar::LocationBar(QupZilla* mainClass)
|
||||
, m_clearAction(0)
|
||||
, m_holdingAlt(false)
|
||||
, m_loadProgress(0)
|
||||
, m_loadFinished(true)
|
||||
, m_progressVisible(false)
|
||||
{
|
||||
setObjectName("locationbar");
|
||||
setDragEnabled(true);
|
||||
@ -87,6 +87,9 @@ LocationBar::LocationBar(QupZilla* mainClass)
|
||||
connect(m_bookmarkIcon, SIGNAL(clicked(QPoint)), this, SLOT(bookmarkIconClicked()));
|
||||
connect(down, SIGNAL(clicked(QPoint)), this, SLOT(showMostVisited()));
|
||||
connect(mApp->searchEnginesManager(), SIGNAL(activeEngineChanged()), this, SLOT(updatePlaceHolderText()));
|
||||
connect(mApp, SIGNAL(message(Qz::AppMessageType, bool)), SLOT(onMessage(Qz::AppMessageType, bool)));
|
||||
|
||||
loadSettings();
|
||||
|
||||
clearIcon();
|
||||
updatePlaceHolderText();
|
||||
@ -96,6 +99,7 @@ void LocationBar::setWebView(TabbedWebView* view)
|
||||
{
|
||||
m_webView = view;
|
||||
|
||||
connect(m_webView, SIGNAL(loadStarted()), SLOT(onLoadStarted()));
|
||||
connect(m_webView, SIGNAL(loadProgress(int)), SLOT(onLoadProgress(int)));
|
||||
connect(m_webView, SIGNAL(loadFinished(bool)), SLOT(onLoadFinished()));
|
||||
}
|
||||
@ -528,34 +532,59 @@ LocationBar::~LocationBar()
|
||||
delete m_bookmarkIcon;
|
||||
}
|
||||
|
||||
void LocationBar::onLoadStarted()
|
||||
{
|
||||
m_progressVisible = true;
|
||||
}
|
||||
|
||||
void LocationBar::onLoadProgress(int progress)
|
||||
{
|
||||
if (qzSettings->showLoadingProgress) {
|
||||
m_loadFinished = false;
|
||||
m_loadProgress = progress;
|
||||
repaint();
|
||||
update();
|
||||
}
|
||||
}
|
||||
|
||||
void LocationBar::onLoadFinished()
|
||||
{
|
||||
if (qzSettings->showLoadingProgress) {
|
||||
m_loadFinished = false;
|
||||
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()
|
||||
{
|
||||
if (qzSettings->showLoadingProgress) {
|
||||
m_loadFinished = true;
|
||||
repaint();
|
||||
m_progressVisible = false;
|
||||
update();
|
||||
}
|
||||
}
|
||||
|
||||
void LocationBar::paintEvent(QPaintEvent* event)
|
||||
{
|
||||
if (hasFocus() || !qzSettings->showLoadingProgress || m_loadFinished) {
|
||||
if (hasFocus()) {
|
||||
LineEdit::paintEvent(event);
|
||||
return;
|
||||
}
|
||||
@ -580,22 +609,54 @@ void LocationBar::paintEvent(QPaintEvent* event)
|
||||
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);
|
||||
if (qzSettings->showLoadingProgress && m_progressVisible) {
|
||||
QColor bg = m_progressColor;
|
||||
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);
|
||||
// Qt::Alignment va = QStyle::visualAlignment(QApplication::layoutDirection(), QFlag(alignment()));
|
||||
p.drawText(textRect, text());
|
||||
QTextOption opt;
|
||||
opt.setWrapMode(QTextOption::NoWrap);
|
||||
p.drawText(textRect, text(), opt);
|
||||
}
|
||||
|
@ -74,11 +74,20 @@ private slots:
|
||||
void updatePlaceHolderText();
|
||||
void showCompletion(const QString &newText);
|
||||
|
||||
void onLoadStarted();
|
||||
void onLoadProgress(int progress);
|
||||
void onLoadFinished();
|
||||
void hideProgress();
|
||||
|
||||
void onMessage(Qz::AppMessageType, bool);
|
||||
|
||||
private:
|
||||
enum ProgressStyle {
|
||||
ProgressFilled,
|
||||
ProgressBottom,
|
||||
ProgressTop
|
||||
};
|
||||
|
||||
void contextMenuEvent(QContextMenuEvent* event);
|
||||
void focusInEvent(QFocusEvent* event);
|
||||
void focusOutEvent(QFocusEvent* event);
|
||||
@ -94,6 +103,8 @@ private:
|
||||
void showGoButton();
|
||||
void hideGoButton();
|
||||
|
||||
void loadSettings();
|
||||
|
||||
LocationCompleter m_completer;
|
||||
|
||||
BookmarkIcon* m_bookmarkIcon;
|
||||
@ -112,7 +123,9 @@ private:
|
||||
bool m_holdingAlt;
|
||||
|
||||
int m_loadProgress;
|
||||
bool m_loadFinished;
|
||||
bool m_progressVisible;
|
||||
ProgressStyle m_progressStyle;
|
||||
QColor m_progressColor;
|
||||
};
|
||||
|
||||
#endif // LOCATIONBAR_H
|
||||
|
@ -49,6 +49,7 @@
|
||||
#include <QFileDialog>
|
||||
#include <QMessageBox>
|
||||
#include <QCloseEvent>
|
||||
#include <QColorDialog>
|
||||
|
||||
Preferences::Preferences(QupZilla* mainClass, QWidget* parent)
|
||||
: QDialog(parent)
|
||||
@ -185,7 +186,17 @@ Preferences::Preferences(QupZilla* mainClass, QWidget* parent)
|
||||
ui->selectAllOnFocus->setChecked(settings.value("SelectAllTextOnDoubleClick", true).toBool());
|
||||
ui->selectAllOnClick->setChecked(settings.value("SelectAllTextOnClick", false).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();
|
||||
|
||||
//BROWSING
|
||||
@ -870,6 +881,9 @@ void Preferences::saveSettings()
|
||||
settings.setValue("SelectAllTextOnClick", ui->selectAllOnClick->isChecked());
|
||||
settings.setValue("AddCountryDomainWithAltKey", ui->addCountryWithAlt->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();
|
||||
|
||||
//Languages
|
||||
@ -936,3 +950,23 @@ Preferences::~Preferences()
|
||||
delete m_pluginsList;
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -83,6 +83,9 @@ private slots:
|
||||
void deleteProfile();
|
||||
void startProfileIndexChanged(QString index);
|
||||
|
||||
void setProgressBarColorIcon(QColor col = QColor());
|
||||
void selectCustomProgressBarColor();
|
||||
|
||||
void setNotificationPreviewVisible(bool state);
|
||||
|
||||
private:
|
||||
|
@ -793,6 +793,80 @@
|
||||
</property>
|
||||
</widget>
|
||||
</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 "Highlight" 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>
|
||||
<widget class="QCheckBox" name="selectAllOnFocus">
|
||||
<property name="text">
|
||||
@ -2383,5 +2457,38 @@
|
||||
<tabstop>showBookmarksToolbar</tabstop>
|
||||
</tabstops>
|
||||
<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>
|
||||
|
Loading…
Reference in New Issue
Block a user