diff --git a/colors.ui b/colors.ui --- a/colors.ui +++ b/colors.ui @@ -1,69 +1,70 @@ - + + Colors - - + + 0 0 - 240 - 344 + 389 + 444 - + - - + + Display Colors - + - - - - + + + + &Foreground: - + false - + kcfg_ForeColor - - - + + + - + 0 0 0 - - - + + + &Background: - + false - + kcfg_BackColor - - - + + + - + 189 255 @@ -76,10 +77,10 @@ - + Qt::Horizontal - + 40 20 @@ -91,141 +92,203 @@ - - + + Button Colors - + - - - - + + + + + Background + + + false + + + + + + + Foreground + + + false + + + + + + &Functions: - + false - + kcfg_FunctionButtonsColor - - - + + + + + + + + + + - - - + + + St&atistic functions: - + false - + kcfg_StatButtonsColor - - - + + + + + + + + + + - - - + + + He&xadecimals: - + false - + kcfg_HexButtonsColor - - - + + + + + + + + + + - - - + + + &Numbers: - + false - + kcfg_NumberButtonsColor - - - + + + + + + + + + + - - - + + + &Memory: - + false - + kcfg_MemoryButtonsColor - - - + + + - - - + + + + + + + + + + O&perations: - + false - + kcfg_OperationButtonsColor - - - + + + + + + + + + + - + Qt::Horizontal - + 31 20 @@ -238,13 +301,13 @@ - + Qt::Vertical - + QSizePolicy::Expanding - + 151 70 @@ -254,7 +317,7 @@ - + KColorButton QPushButton @@ -265,11 +328,17 @@ kcfg_ForeColor kcfg_BackColor kcfg_FunctionButtonsColor + kcfg_FunctionFontsColor kcfg_StatButtonsColor + kcfg_StatFontsColor kcfg_HexButtonsColor + kcfg_HexFontsColor kcfg_NumberButtonsColor + kcfg_NumberFontsColor kcfg_MemoryButtonsColor + kcfg_MemoryFontsColor kcfg_OperationButtonsColor + kcfg_OperationFontsColor diff --git a/kcalc.cpp b/kcalc.cpp --- a/kcalc.cpp +++ b/kcalc.cpp @@ -2072,50 +2072,49 @@ //------------------------------------------------------------------------------ void KCalculator::setColors() { - calc_display->changeSettings(); - - KColorScheme schemeButtons(QPalette::Active, KColorScheme::Button); - const QColor defaultColor = schemeButtons.background().color(); - - if (KCalcSettings::numberButtonsColor() == defaultColor - && KCalcSettings::functionButtonsColor() == defaultColor - && KCalcSettings::statButtonsColor() == defaultColor - && KCalcSettings::hexButtonsColor() == defaultColor - && KCalcSettings::memoryButtonsColor() == defaultColor - && KCalcSettings::operationButtonsColor() == defaultColor) { - return; - } + calc_display->changeSettings(); const QString sheet = QStringLiteral("QPushButton { background-color: %1 }"); - const QColor numPal(KCalcSettings::numberButtonsColor()); + const QColor numFontColor(KCalcSettings::numberFontsColor()); for (int i = 0; i < 10; ++i) { - (num_button_group_->button(i))->setStyleSheet(sheet.arg(numPal.name())); + (num_button_group_->button(i))->setStyleSheet(sheet.arg(numPal.name())); + qobject_cast((num_button_group_->button(i)))->setTextColor(numFontColor); } const QColor funcPal(KCalcSettings::functionButtonsColor()); + const QColor funcFontColor(KCalcSettings::functionFontsColor()); foreach(QAbstractButton *btn, function_button_list_) { btn->setStyleSheet(sheet.arg(funcPal.name())); + qobject_cast(btn)->setTextColor(funcFontColor); } const QColor statPal(KCalcSettings::statButtonsColor()); + const QColor statFontColor(KCalcSettings::statFontsColor()); foreach(QAbstractButton *btn, stat_buttons_) { - btn->setStyleSheet(sheet.arg(statPal.name())); + btn->setStyleSheet(sheet.arg(statPal.name())); + qobject_cast(btn)->setTextColor(statFontColor); } const QColor hexPal(KCalcSettings::hexButtonsColor()); + const QColor hexFontColor(KCalcSettings::hexFontsColor()); for (int i = 10; i < 16; ++i) { (num_button_group_->button(i))->setStyleSheet(sheet.arg(hexPal.name())); + qobject_cast((num_button_group_->button(i)))->setTextColor(hexFontColor); } const QColor memPal(KCalcSettings::memoryButtonsColor()); + const QColor memFontColor(KCalcSettings::memoryFontsColor()); foreach(QAbstractButton *btn, mem_button_list_) { btn->setStyleSheet(sheet.arg(memPal.name())); + qobject_cast(btn)->setTextColor(memFontColor); } const QColor opPal(KCalcSettings::operationButtonsColor()); + const QColor opFontColor(KCalcSettings::operationFontsColor()); foreach(QAbstractButton *btn, operation_button_list_) { btn->setStyleSheet(sheet.arg(opPal.name())); + qobject_cast(btn)->setTextColor(opFontColor); } } diff --git a/kcalc.kcfg b/kcalc.kcfg --- a/kcalc.kcfg +++ b/kcalc.kcfg @@ -45,6 +45,32 @@ defaultButtonColor + + + KColorScheme schemeFonts(QPalette::Active, KColorScheme::Button); + QColor defaultFontColor = schemeFonts.foreground().color(); + defaultFontColor + + + + defaultFontColor + + + + defaultFontColor + + + + defaultFontColor + + + + defaultFontColor + + + + defaultFontColor + diff --git a/kcalc_button.h b/kcalc_button.h --- a/kcalc_button.h +++ b/kcalc_button.h @@ -67,8 +67,11 @@ const QString &tooltip); QSize sizeHint() const override; + QColor textColor() const; + void setTextColor(const QColor &color); void setFont(const QFont &fnt); + void setEnabled(const bool &enabled); // reimp void setText(const QString &text); // reimp void setToolTip(const QString &tip); // reimp @@ -87,6 +90,7 @@ ButtonModeFlags mode_flags_; QMap mode_; QSize size_; + QColor text_color_; }; #endif diff --git a/kcalc_button.cpp b/kcalc_button.cpp --- a/kcalc_button.cpp +++ b/kcalc_button.cpp @@ -28,7 +28,6 @@ #include - //------------------------------------------------------------------------------ // Name: KCalcButton // Desc: constructor @@ -136,6 +135,14 @@ update(); } +QColor KCalcButton::textColor() const { + QColor col = text_color_; + if (!isEnabled()) { + col.setAlphaF(0.7); +} + return col; +} + //------------------------------------------------------------------------------ // Name: paintEvent // Desc: draws the button @@ -153,15 +160,15 @@ style()->drawControl(QStyle::CE_PushButtonBevel, &option, &p, this); // draw label... - p.save(); + p.save(); // rant: Qt4 needs QSimpleRichText, dammit! - QTextDocument doc; + QTextDocument doc; QAbstractTextDocumentLayout::PaintContext context; doc.setHtml(QLatin1String("
") + text() + QLatin1String("
")); doc.setDefaultFont(font()); context.palette = palette(); - context.palette.setColor(QPalette::Text, context.palette.buttonText().color()); + context.palette.setColor(QPalette::Text, textColor()); p.translate((width() / 2 - doc.size().width() / 2) + x_offset, (height() / 2 - doc.size().height() / 2) + y_offset); doc.documentLayout()->draw(&p, context); @@ -220,6 +227,10 @@ calcSizeHint(); } +void KCalcButton::setTextColor(const QColor &color) { + text_color_ = color; +} + //------------------------------------------------------------------------------ // Name: setText // Desc: @@ -236,6 +247,14 @@ calcSizeHint(); } +void KCalcButton::setEnabled(const bool& enabled) { + QPushButton::setEnabled(enabled); + + if (!enabled) { + text_color_.setAlphaF(0.6); + } +} + //------------------------------------------------------------------------------ // Name: setToolTip // Desc: