diff options
author | aavit <qt-info@nokia.com> | 2010-11-19 12:30:09 (GMT) |
---|---|---|
committer | aavit <qt-info@nokia.com> | 2010-11-19 12:30:09 (GMT) |
commit | 8034cab2cce55b43dcc1100d0b22f8c85eb733c2 (patch) | |
tree | 5a1637fa48ce23e12c6a51490f6a481fd1ca1a5a /src/gui/styles | |
parent | e614223831f2b3cc9051ae88586370a7d5b63db2 (diff) | |
parent | 1d152964adec62d03ce2f4a45ca40ddbd05819ae (diff) | |
download | Qt-8034cab2cce55b43dcc1100d0b22f8c85eb733c2.zip Qt-8034cab2cce55b43dcc1100d0b22f8c85eb733c2.tar.gz Qt-8034cab2cce55b43dcc1100d0b22f8c85eb733c2.tar.bz2 |
Merge branch 'master' of scm.dev.nokia.troll.no:qt/oslo-staging-2
Diffstat (limited to 'src/gui/styles')
-rw-r--r-- | src/gui/styles/qs60style.cpp | 107 | ||||
-rw-r--r-- | src/gui/styles/qs60style_p.h | 7 | ||||
-rw-r--r-- | src/gui/styles/qs60style_s60.cpp | 75 |
3 files changed, 130 insertions, 59 deletions
diff --git a/src/gui/styles/qs60style.cpp b/src/gui/styles/qs60style.cpp index 6fb3689..087907f 100644 --- a/src/gui/styles/qs60style.cpp +++ b/src/gui/styles/qs60style.cpp @@ -405,13 +405,14 @@ void QS60StylePrivate::clearCaches(CacheClearReason reason) QPixmapCache::clear(); break; case CC_ThemeChange: - m_colorCache.clear(); QPixmapCache::clear(); +#ifdef Q_WS_S60 + deleteStoredSettings(); +#endif deleteBackground(); break; case CC_UndefinedChange: default: - m_colorCache.clear(); m_mappedFontsCache.clear(); QPixmapCache::clear(); deleteBackground(); @@ -419,64 +420,53 @@ void QS60StylePrivate::clearCaches(CacheClearReason reason) } } -// Since S60Style has 'button' and 'tooltip' as a graphic, we don't have any native color which to use -// for QPalette::Button and QPalette::ToolTipBase. Therefore S60Style needs to guesstimate -// palette colors by calculating average rgb values for button pixels. -// Returns Qt::black if there is an issue with the graphics (image is NULL, or no bits() found). -QColor QS60StylePrivate::colorFromFrameGraphics(SkinFrameElements frame) const +QColor QS60StylePrivate::calculatedColor(SkinFrameElements frame) const { - const bool cachedColorExists = m_colorCache.contains(frame); - if (!cachedColorExists) { - const int frameCornerWidth = pixelMetric(PM_FrameCornerWidth); - const int frameCornerHeight = pixelMetric(PM_FrameCornerHeight); - Q_ASSERT(2 * frameCornerWidth < 32); - Q_ASSERT(2 * frameCornerHeight < 32); - - const QImage frameImage = QS60StylePrivate::frame(frame, QSize(32, 32)).toImage(); - Q_ASSERT(frameImage.bytesPerLine() > 0); - if (frameImage.isNull()) - return Qt::black; - - const QRgb *pixelRgb = (const QRgb*)frameImage.bits(); - const int pixels = frameImage.byteCount()/sizeof(QRgb); - - int estimatedRed = 0; - int estimatedGreen = 0; - int estimatedBlue = 0; - - int skips = 0; - int estimations = 0; - - const int topBorderLastPixel = frameCornerHeight*frameImage.width() - 1; - const int bottomBorderFirstPixel = frameImage.width() * frameImage.height() - frameCornerHeight*frameImage.width() - 1; - const int rightBorderFirstPixel = frameImage.width() - frameCornerWidth; - const int leftBorderLastPixel = frameCornerWidth; - - while ((skips + estimations) < pixels) { - if ((skips + estimations) > topBorderLastPixel && - (skips + estimations) < bottomBorderFirstPixel) { - for (int rowIndex = 0; rowIndex < frameImage.width(); rowIndex++) { - if (rowIndex > leftBorderLastPixel && - rowIndex < rightBorderFirstPixel) { - estimatedRed += qRed(*pixelRgb); - estimatedGreen += qGreen(*pixelRgb); - estimatedBlue += qBlue(*pixelRgb); - } - pixelRgb++; - estimations++; + const int frameCornerWidth = pixelMetric(PM_FrameCornerWidth); + const int frameCornerHeight = pixelMetric(PM_FrameCornerHeight); + Q_ASSERT(2 * frameCornerWidth < 32); + Q_ASSERT(2 * frameCornerHeight < 32); + + const QImage frameImage = QS60StylePrivate::frame(frame, QSize(32, 32)).toImage(); + Q_ASSERT(frameImage.bytesPerLine() > 0); + if (frameImage.isNull()) + return Qt::black; + + const QRgb *pixelRgb = (const QRgb*)frameImage.constBits(); + const int pixels = frameImage.byteCount() / sizeof(QRgb); + + int estimatedRed = 0; + int estimatedGreen = 0; + int estimatedBlue = 0; + + int skips = 0; + int estimations = 0; + + const int topBorderLastPixel = frameCornerHeight * frameImage.width() - 1; + const int bottomBorderFirstPixel = frameImage.width() * frameImage.height() - topBorderLastPixel; + const int rightBorderFirstPixel = frameImage.width() - frameCornerWidth; + const int leftBorderLastPixel = frameCornerWidth; + + while ((skips + estimations) < pixels) { + if ((skips + estimations) > topBorderLastPixel && + (skips + estimations) < bottomBorderFirstPixel) { + for (int rowIndex = 0; rowIndex < frameImage.width(); rowIndex++) { + if (rowIndex > leftBorderLastPixel && + rowIndex < rightBorderFirstPixel) { + estimatedRed += qRed(*pixelRgb); + estimatedGreen += qGreen(*pixelRgb); + estimatedBlue += qBlue(*pixelRgb); } - } else { pixelRgb++; - skips++; + estimations++; } + } else { + pixelRgb++; + skips++; } - QColor frameColor(estimatedRed/estimations, estimatedGreen/estimations, estimatedBlue/estimations); - m_colorCache.insert(frame, frameColor); - return !estimations ? Qt::black : frameColor; - } else { - return m_colorCache.value(frame); } - + QColor frameColor(estimatedRed/estimations, estimatedGreen/estimations, estimatedBlue/estimations); + return !estimations ? Qt::black : frameColor; } void QS60StylePrivate::setThemePalette(QApplication *app) const @@ -731,11 +721,14 @@ void QS60StylePrivate::setThemePalette(QPalette *palette) const palette->setBrush(QPalette::Window, backgroundTexture()); // set as transparent so that styled full screen theme background is visible palette->setBrush(QPalette::Base, Qt::transparent); - // set button and tooltipbase based on pixel colors + // set button color based on pixel colors +#ifndef Q_WS_S60 + //For emulated style, just calculate the color every time + const QColor buttonColor = calculatedColor(SF_ButtonNormal); +#else const QColor buttonColor = colorFromFrameGraphics(SF_ButtonNormal); +#endif palette->setColor(QPalette::Button, buttonColor); - const QColor toolTipColor = colorFromFrameGraphics(SF_ToolTip); - palette->setColor(QPalette::ToolTipBase, toolTipColor); palette->setColor(QPalette::Light, palette->color(QPalette::Button).lighter()); palette->setColor(QPalette::Dark, palette->color(QPalette::Button).darker()); palette->setColor(QPalette::Midlight, palette->color(QPalette::Button).lighter(125)); diff --git a/src/gui/styles/qs60style_p.h b/src/gui/styles/qs60style_p.h index b46f75e..db4285d 100644 --- a/src/gui/styles/qs60style_p.h +++ b/src/gui/styles/qs60style_p.h @@ -523,8 +523,12 @@ public: static bool isSingleClickUi(); static bool isWidgetPressed(const QWidget *widget); - // calculates average color based on button skin graphics (minus borders). +#ifdef Q_WS_S60 + static void deleteStoredSettings(); + // calculates average color based on theme graphics (minus borders). QColor colorFromFrameGraphics(SkinFrameElements frame) const; +#endif + QColor calculatedColor(SkinFrameElements frame) const; //set theme palette for application void setThemePalette(QApplication *application) const; @@ -542,7 +546,6 @@ public: static const int m_numberOfLayouts; mutable QHash<QPair<QS60StyleEnums::FontCategories , int>, QFont> m_mappedFontsCache; - mutable QHash<SkinFrameElements, QColor> m_colorCache; // Has one entry per SkinFrameElements static const struct frameElementCenter { diff --git a/src/gui/styles/qs60style_s60.cpp b/src/gui/styles/qs60style_s60.cpp index a1ea308..7b75d40 100644 --- a/src/gui/styles/qs60style_s60.cpp +++ b/src/gui/styles/qs60style_s60.cpp @@ -48,6 +48,7 @@ #include "private/qpixmap_s60_p.h" #include "private/qcore_symbian_p.h" #include "qapplication.h" +#include "qsettings.h" #include "qpluginloader.h" #include "qlibraryinfo.h" @@ -69,6 +70,8 @@ #include <gulicon.h> #include <AknBitmapAnimation.h> +#include <centralrepository.h> + #if !defined(QT_NO_STYLE_S60) || defined(QT_PLUGIN) QT_BEGIN_NAMESPACE @@ -81,6 +84,8 @@ enum TDrawType { ENoDraw }; +const TUid personalisationUID = { 0x101F876F }; + enum TSupportRelease { ES60_None = 0x0000, //indicates that the commonstyle should draw the graphics ES60_3_1 = 0x0001, @@ -689,6 +694,76 @@ bool QS60StylePrivate::isSingleClickUi() return (QSysInfo::s60Version() > QSysInfo::SV_S60_5_0); } +void QS60StylePrivate::deleteStoredSettings() +{ + QSettings settings(QSettings::UserScope, QLatin1String("Trolltech")); + settings.beginGroup(QLatin1String("QS60Style")); + settings.remove(""); + settings.endGroup(); +} + +// Since S60Style has 'button' as a graphic, we don't have any native color which to use +// for QPalette::Button. Therefore S60Style needs to guesstimate palette color by calculating +// average rgb values for button pixels. +// Returns Qt::black if there is an issue with the graphics (image is NULL, or no constBits() found). +QColor QS60StylePrivate::colorFromFrameGraphics(SkinFrameElements frame) const +{ +#ifndef QT_NO_SETTINGS + TInt themeID = 0; + //First we need to fetch active theme ID. We need to store the themeID at the same time + //as color, so that we can later check if the stored color is still from the same theme. + //Native side stores active theme UID/Timestamp into central repository. + int error = 0; + QT_TRAP_THROWING( + CRepository *themeRepository = CRepository::NewLC(personalisationUID); + if (themeRepository) { + static const TInt KThemePkgIDDesSize = 23; //size of the stored theme package ID + TBuf<32> value; //themeID is currently max of 8 + 1 + 8 characters, but lets have some extra space + const TUint32 key = 0x00000002; //active theme key in the repository + error = themeRepository->Get(key, value); + if (error == KErrNone) { + TLex lex(value); + TPtrC numberToken(lex.NextToken()); + if (numberToken.Length()) + error = TLex(numberToken).Val(themeID); + else + error = KErrArgument; + } + } + CleanupStack::PopAndDestroy(themeRepository); + ); + + QSettings settings(QSettings::UserScope, QLatin1String("Trolltech")); + settings.beginGroup(QLatin1String("QS60Style")); + if (themeID != 0) { + QVariant buttonColor = settings.value(QLatin1String("ButtonColor")); + if (!buttonColor.isNull()) { + //there is a stored color value, lets see if the theme ID matches + if (error == KErrNone) { + QVariant themeUID = settings.value(QLatin1String("ThemeUID")); + if (!themeUID.isNull() && themeUID.toInt() == themeID) { + QColor storedColor(buttonColor.value<QColor>()); + if (storedColor.isValid()) + return storedColor; + } + } + settings.remove(""); //if color was invalid, or theme has been changed, just delete all stored settings + } + } +#endif + + QColor color = calculatedColor(frame); + +#ifndef QT_NO_SETTINGS + settings.setValue(QLatin1String("ThemeUID"), QVariant(themeID)); + if (frame == SF_ButtonNormal) //other colors are not currently calculated from graphics + settings.setValue(QLatin1String("ButtonColor"), QVariant(color)); + settings.endGroup(); +#endif + + return color; +} + QPoint qt_s60_fill_background_offset(const QWidget *targetWidget) { CCoeControl *control = targetWidget->effectiveWinId(); |