Switchable color for webbrowser progressbar.

This commit is contained in:
Martin Rotter 2013-07-20 21:11:52 +02:00
parent 93a191058e
commit 7bbdd7a7a2
4 changed files with 114 additions and 10 deletions

View File

@ -1,6 +1,7 @@
#include <QMessageBox>
#include <QProcess>
#include <QNetworkProxy>
#include <QColorDialog>
#include "gui/formsettings.h"
#include "gui/themefactory.h"
@ -42,6 +43,8 @@ FormSettings::FormSettings(QWidget *parent) : QDialog(parent), m_ui(new Ui::Form
this, &FormSettings::onProxyTypeChanged);
connect(m_ui->m_checkShowPassword, &QCheckBox::stateChanged,
this, &FormSettings::displayProxyPassword);
connect(m_ui->m_btnBrowserProgressColor, &QPushButton::clicked,
this, &FormSettings::changeBrowserProgressColor);
// Load all settings.
loadGeneral();
@ -55,6 +58,15 @@ FormSettings::~FormSettings() {
delete m_ui;
}
void FormSettings::changeBrowserProgressColor() {
QColorDialog color_dialog(m_initialSettings.m_webBrowserProgress, this);
color_dialog.setWindowTitle(tr("Select color for web browser progress bar"));
color_dialog.setOption(QColorDialog::ShowAlphaChannel);
color_dialog.exec();
m_initialSettings.m_webBrowserProgress = color_dialog.selectedColor();
}
void FormSettings::displayProxyPassword(int state) {
if (state == Qt::Checked) {
m_ui->m_txtProxyPassword->setEchoMode(QLineEdit::Normal);
@ -243,6 +255,14 @@ void FormSettings::loadInterface() {
m_ui->m_grpTray->setDisabled(true);
}
// Load settings of web browser GUI.
m_initialSettings.m_webBrowserProgress = Settings::getInstance()->value(APP_CFG_GUI,
"browser_progress_color",
QColor(0, 255, 0, 100)).value<QColor>();
m_ui->m_checkBrowserProgressColor->setChecked(Settings::getInstance()->value(APP_CFG_GUI,
"browser_colored_progress_enabled",
true).toBool());
// Load settings of icon theme.
QString current_theme = ThemeFactory::getCurrentIconTheme();
@ -290,6 +310,14 @@ void FormSettings::saveInterface() {
}
}
// Save settings of GUI of web browser.
Settings::getInstance()->setValue(APP_CFG_GUI,
"browser_progress_color",
m_initialSettings.m_webBrowserProgress);
Settings::getInstance()->setValue(APP_CFG_GUI,
"browser_colored_progress_enabled",
m_ui->m_checkBrowserProgressColor->isChecked());
// Save selected icon theme.
ThemeFactory::setCurrentIconTheme(m_ui->m_cmbIconTheme->itemData(m_ui->m_cmbIconTheme->currentIndex()).toString());
}

View File

@ -10,6 +10,11 @@ namespace Ui {
class FormSettings;
}
// Structure holding some initial values.
struct TemporarySettings {
QColor m_webBrowserProgress;
};
class FormSettings : public QDialog {
Q_OBJECT
@ -21,9 +26,9 @@ class FormSettings : public QDialog {
// Saves settings into global configuration.
void saveSettings();
// Load/save GUI settings.
void loadInterface();
void saveInterface();
void changeBrowserProgressColor();
void loadGeneral();
void saveGeneral();
@ -42,6 +47,7 @@ class FormSettings : public QDialog {
private:
Ui::FormSettings *m_ui;
TemporarySettings m_initialSettings;
};
#endif // FORMSETTINGS_H

View File

@ -65,7 +65,7 @@
<item row="0" column="1">
<widget class="QStackedWidget" name="m_stackedSettings">
<property name="currentIndex">
<number>4</number>
<number>2</number>
</property>
<widget class="QWidget" name="m_pageGeneral">
<layout class="QFormLayout" name="formLayout_5">
@ -117,8 +117,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>100</width>
<height>30</height>
<width>506</width>
<height>367</height>
</rect>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_4">
@ -163,7 +163,7 @@
<enum>QTabWidget::North</enum>
</property>
<property name="currentIndex">
<number>0</number>
<number>2</number>
</property>
<widget class="QWidget" name="m_tabIconSkin">
<attribute name="title">
@ -256,10 +256,42 @@
</item>
</layout>
</widget>
<widget class="QWidget" name="m_tabFonts">
<widget class="QWidget" name="m_tabWebBrowser">
<attribute name="title">
<string>Fonts</string>
<string>Web browser</string>
</attribute>
<layout class="QFormLayout" name="formLayout_7">
<item row="1" column="0">
<widget class="QLabel" name="m_lblBrowserProgressColor">
<property name="text">
<string>Color of website loading progress bar</string>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
</property>
<property name="indent">
<number>20</number>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QPushButton" name="m_btnBrowserProgressColor">
<property name="text">
<string>&amp;Change...</string>
</property>
</widget>
</item>
<item row="0" column="0" colspan="2">
<widget class="QCheckBox" name="m_checkBrowserProgressColor">
<property name="text">
<string>Use custom color for web browser progress bar</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="m_tabMisc">
<attribute name="title">
@ -562,5 +594,37 @@
</hint>
</hints>
</connection>
<connection>
<sender>m_checkBrowserProgressColor</sender>
<signal>toggled(bool)</signal>
<receiver>m_btnBrowserProgressColor</receiver>
<slot>setVisible(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>416</x>
<y>48</y>
</hint>
<hint type="destinationlabel">
<x>519</x>
<y>74</y>
</hint>
</hints>
</connection>
<connection>
<sender>m_checkBrowserProgressColor</sender>
<signal>toggled(bool)</signal>
<receiver>m_lblBrowserProgressColor</receiver>
<slot>setVisible(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>416</x>
<y>48</y>
</hint>
<hint type="destinationlabel">
<x>275</x>
<y>73</y>
</hint>
</hints>
</connection>
</connections>
</ui>

View File

@ -3,6 +3,8 @@
#include <QPainter>
#include <QApplication>
#include "core/defs.h"
#include "core/settings.h"
#include "gui/locationlineedit.h"
@ -48,9 +50,13 @@ void LocationLineEdit::mousePressEvent(QMouseEvent *event) {
void LocationLineEdit::paintEvent(QPaintEvent *event) {
// Draw "progress bar" if needed.
if (m_progress > 0) {
if (m_progress > 0 && Settings::getInstance()->value(APP_CFG_GUI,
"browser_colored_progress_enabled",
true).toBool()) {
QPalette current_palette = palette();
QColor loadingColor = QColor(0, 255, 0, 100);
QColor loadingColor = Settings::getInstance()->value(APP_CFG_GUI,
"browser_progress_color",
QColor(0, 255, 0, 100)).value<QColor>();
QLinearGradient gradient(0, 0, width(), 0);
qreal percentage_border = m_progress / 100.0;
@ -63,7 +69,7 @@ void LocationLineEdit::paintEvent(QPaintEvent *event) {
setPalette(current_palette);
}
// No "progress bar" is needed, restore default palette.
// No "progress bar" is needed or enabled, restore default palette.
else {
setPalette(m_defaultPalette);
}