forked from qt-creator/qt-creator
Force custom colors within usable range
We previously allowed fully white and yellow colors as the base color for our interface. This does not work with our icons or other interface elements. Instead I now constrain the selectable colors within a certain range of saturation and brightness. This still leaves the user in control but will prevent the common case where the user selects an overly saturated color from the color picker and ends up with an unusable or extremely ugly panel.
This commit is contained in:
@@ -95,6 +95,7 @@ QColor StyleHelper::panelTextColor(bool lightColored)
|
|||||||
}
|
}
|
||||||
|
|
||||||
QColor StyleHelper::m_baseColor(0x666666);
|
QColor StyleHelper::m_baseColor(0x666666);
|
||||||
|
QColor StyleHelper::m_requestedBaseColor(0x666666);
|
||||||
|
|
||||||
QColor StyleHelper::baseColor(bool lightColored)
|
QColor StyleHelper::baseColor(bool lightColored)
|
||||||
{
|
{
|
||||||
@@ -136,8 +137,18 @@ QColor StyleHelper::borderColor(bool lightColored)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void StyleHelper::setBaseColor(const QColor &color)
|
// We try to ensure that the actual color used are within
|
||||||
|
// reasonalbe bounds while generating the actual baseColor
|
||||||
|
// from the users request.
|
||||||
|
void StyleHelper::setBaseColor(const QColor &newcolor)
|
||||||
{
|
{
|
||||||
|
m_requestedBaseColor = newcolor;
|
||||||
|
|
||||||
|
QColor color;
|
||||||
|
color.setHsv(newcolor.hue(),
|
||||||
|
newcolor.saturation() * 0.7,
|
||||||
|
64 + newcolor.value() / 3);
|
||||||
|
|
||||||
if (color.isValid() && color != m_baseColor) {
|
if (color.isValid() && color != m_baseColor) {
|
||||||
m_baseColor = color;
|
m_baseColor = color;
|
||||||
foreach (QWidget *w, QApplication::topLevelWidgets())
|
foreach (QWidget *w, QApplication::topLevelWidgets())
|
||||||
|
|||||||
@@ -53,6 +53,7 @@ public:
|
|||||||
static QPalette sidebarFontPalette(const QPalette &original);
|
static QPalette sidebarFontPalette(const QPalette &original);
|
||||||
|
|
||||||
// This is our color table, all colors derive from baseColor
|
// This is our color table, all colors derive from baseColor
|
||||||
|
static QColor requestedBaseColor() { return m_requestedBaseColor; }
|
||||||
static QColor baseColor(bool lightColored = false);
|
static QColor baseColor(bool lightColored = false);
|
||||||
static QColor panelTextColor(bool lightColored = false);
|
static QColor panelTextColor(bool lightColored = false);
|
||||||
static QColor highlightColor(bool lightColored = false);
|
static QColor highlightColor(bool lightColored = false);
|
||||||
@@ -83,6 +84,7 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
static QColor m_baseColor;
|
static QColor m_baseColor;
|
||||||
|
static QColor m_requestedBaseColor;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Utils
|
} // namespace Utils
|
||||||
|
|||||||
@@ -356,7 +356,7 @@ public:
|
|||||||
void mousePressEvent(QMouseEvent *ev)
|
void mousePressEvent(QMouseEvent *ev)
|
||||||
{
|
{
|
||||||
if (ev->modifiers() & Qt::ShiftModifier)
|
if (ev->modifiers() & Qt::ShiftModifier)
|
||||||
Utils::StyleHelper::setBaseColor(QColorDialog::getColor(Utils::StyleHelper::baseColor(), m_parent));
|
Utils::StyleHelper::setBaseColor(QColorDialog::getColor(Utils::StyleHelper::requestedBaseColor(), m_parent));
|
||||||
}
|
}
|
||||||
private:
|
private:
|
||||||
QWidget *m_parent;
|
QWidget *m_parent;
|
||||||
|
|||||||
@@ -120,7 +120,7 @@ QWidget *GeneralSettings::createPage(QWidget *parent)
|
|||||||
QSettings* settings = Core::ICore::instance()->settings();
|
QSettings* settings = Core::ICore::instance()->settings();
|
||||||
Q_UNUSED(settings)
|
Q_UNUSED(settings)
|
||||||
fillLanguageBox();
|
fillLanguageBox();
|
||||||
m_page->colorButton->setColor(StyleHelper::baseColor());
|
m_page->colorButton->setColor(StyleHelper::requestedBaseColor());
|
||||||
m_page->externalEditorEdit->setText(EditorManager::instance()->externalEditor());
|
m_page->externalEditorEdit->setText(EditorManager::instance()->externalEditor());
|
||||||
m_page->reloadBehavior->setCurrentIndex(EditorManager::instance()->reloadBehavior());
|
m_page->reloadBehavior->setCurrentIndex(EditorManager::instance()->reloadBehavior());
|
||||||
#ifdef Q_OS_UNIX
|
#ifdef Q_OS_UNIX
|
||||||
|
|||||||
@@ -1131,7 +1131,7 @@ void MainWindow::writeSettings()
|
|||||||
m_settings->beginGroup(QLatin1String(settingsGroup));
|
m_settings->beginGroup(QLatin1String(settingsGroup));
|
||||||
|
|
||||||
if (!(m_overrideColor.isValid() && Utils::StyleHelper::baseColor() == m_overrideColor))
|
if (!(m_overrideColor.isValid() && Utils::StyleHelper::baseColor() == m_overrideColor))
|
||||||
m_settings->setValue(QLatin1String(colorKey), Utils::StyleHelper::baseColor());
|
m_settings->setValue(QLatin1String(colorKey), Utils::StyleHelper::requestedBaseColor());
|
||||||
|
|
||||||
if (windowState() & (Qt::WindowMaximized | Qt::WindowFullScreen)) {
|
if (windowState() & (Qt::WindowMaximized | Qt::WindowFullScreen)) {
|
||||||
m_settings->setValue(QLatin1String(maxKey), (bool) (windowState() & Qt::WindowMaximized));
|
m_settings->setValue(QLatin1String(maxKey), (bool) (windowState() & Qt::WindowMaximized));
|
||||||
|
|||||||
Reference in New Issue
Block a user