diff options
author | Sami Merilä <sami.merila@nokia.com> | 2009-05-07 06:58:23 (GMT) |
---|---|---|
committer | Sami Merilä <sami.merila@nokia.com> | 2009-05-07 06:58:23 (GMT) |
commit | fb989778234e84473e5dce7b12df42bb037b43e8 (patch) | |
tree | 75bfd107edc2574042cf2d2d350a42effcab6b86 /src/gui/styles/qs60style.cpp | |
parent | 1b0916db13a52d99dad93322aae0c5c6ba4c2d18 (diff) | |
download | Qt-fb989778234e84473e5dce7b12df42bb037b43e8.zip Qt-fb989778234e84473e5dce7b12df42bb037b43e8.tar.gz Qt-fb989778234e84473e5dce7b12df42bb037b43e8.tar.bz2 |
S60Style: Improved polish. Now fonts are polished instead of set in drawing code. Also, backgroundTexture is set in its own method, so there is no need to reset whole application palette when layout changes. Finally, some widget specific polishing corrections.
Diffstat (limited to 'src/gui/styles/qs60style.cpp')
-rw-r--r-- | src/gui/styles/qs60style.cpp | 83 |
1 files changed, 49 insertions, 34 deletions
diff --git a/src/gui/styles/qs60style.cpp b/src/gui/styles/qs60style.cpp index ae639d7..581ada0 100644 --- a/src/gui/styles/qs60style.cpp +++ b/src/gui/styles/qs60style.cpp @@ -24,6 +24,7 @@ #include "qmenubar.h" #include "qtablewidget.h" #include "qtoolbar.h" +#include "qgroupbox.h" #include "qtoolbutton.h" #include "private/qtoolbarextension_p.h" #include "private/qcombobox_p.h" @@ -481,6 +482,9 @@ int QS60StylePrivate::focusRectPenWidth() void QS60StylePrivate::setThemePalette(QApplication *app) const { + if (!app) + return; + QPalette widgetPalette = QPalette(Qt::white); // basic colors @@ -518,6 +522,15 @@ void QS60StylePrivate::setThemePalette(QApplication *app) const app->setPalette(widgetPalette); } +void QS60StylePrivate::setBackgroundTexture(QApplication *app) const +{ + if (!app) + return; + QPalette applicationPalette = app->palette(); + applicationPalette.setBrush(QPalette::Window, QS60StylePrivate::backgroundTexture()); + app->setPalette(applicationPalette); +} + void QS60Style::polish(QApplication *application) { Q_D(const QS60Style); @@ -530,6 +543,9 @@ void QS60Style::polish(QWidget *widget) Q_D(const QS60Style); QCommonStyle::polish(widget); + if (!widget) + return; + if (QS60StylePrivate::isSkinnableDialog(widget)) { widget->setAttribute(Qt::WA_StyledBackground); } else if (false @@ -548,33 +564,56 @@ void QS60Style::polish(QWidget *widget) QPalette widgetPalette = widget->palette(); - // widget specific colors - if (QSlider *slider = qobject_cast<QSlider *>(widget)){ + // widget specific colors and fonts + if (qobject_cast<QSlider *>(widget)){ widgetPalette.setColor(QPalette::All, QPalette::WindowText, QS60StylePrivate::s60Color(QS60StyleEnums::CL_QsnLineColors, 8, 0)); QApplication::setPalette(widgetPalette, "QSlider"); - } else if (QPushButton *button = qobject_cast<QPushButton *>(widget)){ + } else if (qobject_cast<QPushButton *>(widget)){ + const QFont suggestedFont = d->s60Font( + QS60StyleEnums::FC_Primary, widget->font().pointSizeF()); + widget->setFont(suggestedFont); widgetPalette.setColor(QPalette::Active, QPalette::ButtonText, QS60StylePrivate::s60Color(QS60StyleEnums::CL_QsnTextColors, 6, 0)); widgetPalette.setColor(QPalette::Inactive, QPalette::ButtonText, QS60StylePrivate::s60Color(QS60StyleEnums::CL_QsnTextColors, 6, 0)); QApplication::setPalette(widgetPalette, "QPushButton"); - } else if (QHeaderView *table = qobject_cast<QHeaderView *>(widget)){ + } else if (qobject_cast<QToolButton *>(widget)){ + const QFont suggestedFont = d->s60Font( + QS60StyleEnums::FC_Primary, widget->font().pointSizeF()); + widget->setFont(suggestedFont); + widgetPalette.setColor(QPalette::Active, QPalette::ButtonText, + QS60StylePrivate::s60Color(QS60StyleEnums::CL_QsnTextColors, 6, 0)); + widgetPalette.setColor(QPalette::Inactive, QPalette::ButtonText, + QS60StylePrivate::s60Color(QS60StyleEnums::CL_QsnTextColors, 6, 0)); + QApplication::setPalette(widgetPalette, "QToolButton"); + } else if (qobject_cast<QHeaderView *>(widget)){ + const QFont suggestedFont = d->s60Font( + QS60StyleEnums::FC_Secondary, widget->font().pointSizeF()); + widget->setFont(suggestedFont); widgetPalette.setColor(QPalette::Active, QPalette::ButtonText, QS60StylePrivate::s60Color(QS60StyleEnums::CL_QsnTextColors, 23, 0)); + QHeaderView* header = qobject_cast<QHeaderView *>(widget); + widgetPalette.setColor(QPalette::Button, Qt::transparent ); + if ( header->viewport() ) + header->viewport()->setPalette(widgetPalette); QApplication::setPalette(widgetPalette, "QHeaderView"); - } else if (QMenuBar *menuBar = qobject_cast<QMenuBar *>(widget)){ + } else if (qobject_cast<QMenuBar *>(widget)){ widgetPalette.setColor(QPalette::All, QPalette::ButtonText, QS60StylePrivate::s60Color(QS60StyleEnums::CL_QsnTextColors, 8, 0)); QApplication::setPalette(widgetPalette, "QMenuBar"); - } else if (QTabBar *tabBar = qobject_cast<QTabBar *>(widget)){ + } else if (qobject_cast<QTabBar *>(widget)){ widgetPalette.setColor(QPalette::Active, QPalette::WindowText, QS60StylePrivate::s60Color(QS60StyleEnums::CL_QsnTextColors, 4, 0)); QApplication::setPalette(widgetPalette, "QTabBar"); - } else if (QTableView *table = qobject_cast<QTableView *>(widget)){ + } else if (qobject_cast<QTableView *>(widget)){ widgetPalette.setColor(QPalette::All, QPalette::Text, QS60StylePrivate::s60Color(QS60StyleEnums::CL_QsnTextColors, 22, 0)); QApplication::setPalette(widgetPalette, "QTableView"); + } else if (qobject_cast<QGroupBox *>(widget)){ + const QFont suggestedFont = d->s60Font( + QS60StyleEnums::FC_Title, widget->font().pointSizeF()); + widget->setFont(suggestedFont); } } @@ -956,11 +995,6 @@ void QS60Style::drawComplexControl(ComplexControl control, const QStyleOptionCom QStyleOptionSpinBox copy = *spinBox; PrimitiveElement pe; - /*if (spinBox->frame && (spinBox->subControls & SC_SpinBoxFrame)) { - QRect r = subControlRect(CC_SpinBox, spinBox, SC_SpinBoxFrame, widget); - qDrawWinPanel(painter, r, spinBox->palette, true); - }*/ - if (spinBox->subControls & SC_SpinBoxUp) { copy.subControls = SC_SpinBoxUp; QPalette pal2 = spinBox->palette; @@ -1036,10 +1070,6 @@ void QS60Style::drawComplexControl(ComplexControl control, const QStyleOptionCom const QColor textColor = groupBox->textColor; painter->save(); - const QFont suggestedFont = d->s60Font( - QS60StyleEnums::FC_Title, painter->font().pointSizeF()); - painter->setFont(suggestedFont); - if (textColor.isValid()) painter->setPen(textColor); int alignment = int(groupBox->textAlignment); @@ -1106,16 +1136,7 @@ void QS60Style::drawControl(ControlElement element, const QStyleOption *option, case CE_PushButtonLabel: if (const QStyleOptionButton *button = qstyleoption_cast<const QStyleOptionButton *>(option)) { QStyleOptionButton optionButton = *button; - int margins = 2*QS60StylePrivate::pixelMetric(QStyle::PM_ButtonMargin); - // make sure that margins do not take too much space from button - if (margins > optionButton.rect.height()/3) // TODO: (?) Remove this when s60Fonts are set by polish(QWidget*) - margins = optionButton.rect.height()/3; - const QFont suggestedFont = d->s60Font( - QS60StyleEnums::FC_Primary, painter->font().pointSizeF()); - painter->save(); - painter->setFont(suggestedFont); QCommonStyle::drawControl(element, &optionButton, painter, widget); - painter->restore(); } break; case CE_CheckBoxLabel: @@ -1141,13 +1162,7 @@ void QS60Style::drawControl(ControlElement element, const QStyleOption *option, case CE_HeaderLabel: if (const QStyleOptionHeader *headerLabel = qstyleoption_cast<const QStyleOptionHeader *>(option)) { QStyleOptionHeader optionHeaderLabel = *headerLabel; - // Adjust font according S60 Look-and-Feel - const QFont suggestedFont = d->s60Font( - QS60StyleEnums::FC_Secondary, painter->font().pointSizeF()); - painter->save(); - painter->setFont(suggestedFont); QCommonStyle::drawControl(element, &optionHeaderLabel, painter, widget); - painter->restore(); } break; #ifndef QT_NO_COMBOBOX @@ -1232,7 +1247,7 @@ void QS60Style::drawControl(ControlElement element, const QStyleOption *option, const QModelIndex indexLast = table->model()->index( table->model()->rowCount()-1,table->model()->columnCount()-1); if (table->viewport()) - voptAdj2.rect = QRect( table->visualRect(indexFirst).topLeft(), + voptAdj2.rect = QRect( table->visualRect(indexFirst).topLeft(), table->visualRect(indexLast).bottomRight()).intersect(table->viewport()->rect()); drawPrimitive(PE_PanelItemViewItem, &voptAdj2, painter, widget); } @@ -1475,7 +1490,7 @@ void QS60Style::drawControl(ControlElement element, const QStyleOption *option, if (optionProgressBar->minimum == optionProgressBar->maximum && optionProgressBar->minimum == 0) { // busy indicator - QS60StylePrivate::drawSkinPart(QS60StyleEnums::SP_QgnGrafBarWait, painter, progressRect,flags); + QS60StylePrivate::drawSkinPart(QS60StyleEnums::SP_QgnGrafBarWait, painter, progressRect,flags); } else { const qreal progressFactor = (optionProgressBar->minimum == optionProgressBar->maximum) ? 1.0 : (qreal)optionProgressBar->progress / optionProgressBar->maximum; @@ -1488,7 +1503,7 @@ void QS60Style::drawControl(ControlElement element, const QStyleOption *option, progressRect.adjust(0, 1, 0, -1); progressRect.setTop(progressRect.bottom() - int(progressRect.height() * progressFactor)); } - + const QS60StylePrivate::SkinElements skinElement = optionProgressBar->orientation == Qt::Horizontal ? QS60StylePrivate::SE_ProgressBarIndicatorHorizontal : QS60StylePrivate::SE_ProgressBarIndicatorVertical; QS60StylePrivate::drawSkinElement(skinElement, painter, progressRect, flags); |