diff --git a/colors.ui b/colors.ui --- a/colors.ui +++ b/colors.ui @@ -1,69 +1,70 @@ - + + Colors - - + + 0 0 - 240 - 344 + 389 + 704 - + - - + + 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,287 @@ - - + + Button Colors - + - - - - + + + + + &Numbers: + + + false + + + kcfg_NumberButtonsColor + + + + + + &Functions: - + false - + kcfg_FunctionButtonsColor - - - + + + - - - + + + + &Memory: + + + false + + + kcfg_MemoryButtonsColor + + + + + + + + + + + + + St&atistic functions: - + false - + kcfg_StatButtonsColor - - - + + + + + + + + + + - - - + + + He&xadecimals: - + false - + kcfg_HexButtonsColor - - - + + + + O&perations: + + + false + + + kcfg_OperationButtonsColor + + + + + + - - - + + + + + + + + + + + + + Qt::Horizontal + + + + 31 + 20 + + + + + + + + + + + Font Colors + + + + + + + &Numbers: - + false - - kcfg_NumberButtonsColor + + kcfg_NumberFontsColor - - - + + + + &Functions: + + + false + + + kcfg_FunctionFontsColor + + + + + + - - - + + + &Memory: - + false - - kcfg_MemoryButtonsColor + + kcfg_MemoryFontsColor - - - + + + - - - + + + + St&atistic functions: + + + false + + + kcfg_StatFontsColor + + + + + + + + + + + + + + + + + + + + + He&xadecimals: + + + false + + + kcfg_HexFontsColor + + + + + + O&perations: - + false - - kcfg_OperationButtonsColor + + kcfg_OperationFontsColor + + + + + + + - - - + + + - + Qt::Horizontal - + 31 20 @@ -238,13 +385,13 @@ - + Qt::Vertical - + QSizePolicy::Expanding - + 151 70 @@ -254,7 +401,7 @@ - + KColorButton QPushButton diff --git a/kcalc.cpp b/kcalc.cpp --- a/kcalc.cpp +++ b/kcalc.cpp @@ -2072,50 +2072,70 @@ //------------------------------------------------------------------------------ void KCalculator::setColors() { - calc_display->changeSettings(); + 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) { + const QColor defaultButtonsColor = schemeButtons.background().color(); + + KColorScheme schemeFonts(QPalette::Active, KColorScheme::Button); + const QColor defaultFontColor = schemeFonts.foreground().color(); + + if (KCalcSettings::numberButtonsColor() == defaultButtonsColor + && KCalcSettings::functionButtonsColor() == defaultButtonsColor + && KCalcSettings::statButtonsColor() == defaultButtonsColor + && KCalcSettings::hexButtonsColor() == defaultButtonsColor + && KCalcSettings::memoryButtonsColor() == defaultButtonsColor + && KCalcSettings::operationButtonsColor() == defaultButtonsColor + && KCalcSettings::numberFontsColor() == defaultFontColor + && KCalcSettings::functionFontsColor() == defaultFontColor + && KCalcSettings::statFontsColor() == defaultFontColor + && KCalcSettings::hexFontsColor() == defaultFontColor + && KCalcSettings::memoryFontsColor() == defaultFontColor + && KCalcSettings::operationFontsColor() == defaultFontColor) { return; } - + 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())); + dynamic_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())); + dynamic_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())); + dynamic_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())); + dynamic_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())); + dynamic_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())); + dynamic_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,6 +67,8 @@ const QString &tooltip); QSize sizeHint() const override; + QColor textColor(); + void setTextColor(const QColor &color); void setFont(const QFont &fnt); void setText(const QString &text); // reimp @@ -87,6 +89,7 @@ ButtonModeFlags mode_flags_; QMap mode_; QSize size_; + QColor mTextColor; }; #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,10 @@ update(); } +QColor KCalcButton::textColor() { + return mTextColor; +} + //------------------------------------------------------------------------------ // Name: paintEvent // Desc: draws the button @@ -153,15 +156,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.setHtml(QLatin1String("
") + text() + QLatin1String("
")); doc.setDefaultFont(font()); context.palette = palette(); - context.palette.setColor(QPalette::Text, context.palette.buttonText().color()); + context.palette.setColor(QPalette::Text, QColor(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 +223,11 @@ calcSizeHint(); } +void KCalcButton::setTextColor(const QColor &color) { + mTextColor = color; + calcSizeHint(); +} + //------------------------------------------------------------------------------ // Name: setText // Desc: