From e267231ecdd4f1614da62f620f82b19e1157b0b8 Mon Sep 17 00:00:00 2001 From: Miikka Heikkinen Date: Wed, 29 Apr 2009 15:06:10 +0300 Subject: Basic optimizations to qdrawhelper for RVCT builds: - Force static inline methods to be actually inline - Force ARM code for strategic methods RevBy: axis --- src/gui/painting/qdrawhelper.cpp | 11 +++++ src/gui/painting/qdrawhelper_p.h | 95 ++++++++++++++++++++++++---------------- 2 files changed, 69 insertions(+), 37 deletions(-) diff --git a/src/gui/painting/qdrawhelper.cpp b/src/gui/painting/qdrawhelper.cpp index c11837a..b8babd7 100644 --- a/src/gui/painting/qdrawhelper.cpp +++ b/src/gui/painting/qdrawhelper.cpp @@ -1499,6 +1499,12 @@ static const uint * QT_FASTCALL fetchConicalGradient(uint *buffer, const Operato +#if defined(Q_CC_RVCT) +// Force ARM code generation for blend methods +# pragma push +# pragma arm +#endif + /* The constant alpha factor describes an alpha factor that gets applied to the result of the composition operation combining it with the destination. @@ -2757,6 +2763,11 @@ static void QT_FASTCALL comp_func_Exclusion(uint *dest, const uint *src, int len comp_func_Exclusion_impl(dest, src, length, QPartialCoverage(const_alpha)); } +#if defined(Q_CC_RVCT) +// Restore pragma state from previous #pragma arm +# pragma pop +#endif + static void QT_FASTCALL rasterop_solid_SourceOrDestination(uint *dest, int length, uint color, diff --git a/src/gui/painting/qdrawhelper_p.h b/src/gui/painting/qdrawhelper_p.h index de97683..ddda7f7 100644 --- a/src/gui/painting/qdrawhelper_p.h +++ b/src/gui/painting/qdrawhelper_p.h @@ -87,7 +87,7 @@ QT_BEGIN_NAMESPACE #if defined(Q_CC_RVCT) // RVCT doesn't like static template functions # define Q_STATIC_TEMPLATE_FUNCTION -# define Q_STATIC_INLINE_FUNCTION inline +# define Q_STATIC_INLINE_FUNCTION static __forceinline #else # define Q_STATIC_TEMPLATE_FUNCTION static # define Q_STATIC_INLINE_FUNCTION static inline @@ -300,19 +300,23 @@ struct QSpanData }; -static inline uint BYTE_MUL_RGB16(uint x, uint a) { +Q_STATIC_INLINE_FUNCTION uint BYTE_MUL_RGB16(uint x, uint a) { a += 1; uint t = (((x & 0x07e0)*a) >> 8) & 0x07e0; t |= (((x & 0xf81f)*(a>>2)) >> 6) & 0xf81f; return t; } -static inline uint BYTE_MUL_RGB16_32(uint x, uint a) { +Q_STATIC_INLINE_FUNCTION uint BYTE_MUL_RGB16_32(uint x, uint a) { uint t = (((x & 0xf81f07e0) >> 5)*a) & 0xf81f07e0; t |= (((x & 0x07e0f81f)*a) >> 5) & 0x07e0f81f; return t; } +#if defined(Q_CC_RVCT) +# pragma push +# pragma arm +#endif Q_STATIC_INLINE_FUNCTION uint BYTE_MUL(uint x, uint a) { uint t = (x & 0xff00ff) * a; t = (t + ((t >> 8) & 0xff00ff) + 0x800080) >> 8; @@ -324,8 +328,11 @@ Q_STATIC_INLINE_FUNCTION uint BYTE_MUL(uint x, uint a) { x |= t; return x; } +#if defined(Q_CC_RVCT) +# pragma pop +#endif -static inline uint PREMUL(uint x) { +Q_STATIC_INLINE_FUNCTION uint PREMUL(uint x) { uint a = x >> 24; uint t = (x & 0xff00ff) * a; t = (t + ((t >> 8) & 0xff00ff) + 0x800080) >> 8; @@ -390,7 +397,7 @@ public: return qt_colorConvert(data, 0); } - static inline quint32p fromRawData(quint32 v) + Q_STATIC_INLINE_FUNCTION quint32p fromRawData(quint32 v) { quint32p p; p.data = v; @@ -421,7 +428,7 @@ class qrgb565; class qargb8565 { public: - static inline bool hasAlpha() { return true; } + Q_STATIC_INLINE_FUNCTION bool hasAlpha() { return true; } inline qargb8565() {} inline qargb8565(quint32 v); @@ -438,8 +445,8 @@ public: data[1] &= 0xdf; return *this; } - static inline quint8 alpha(quint8 a) { return (a + 1) >> 3; } - static inline quint8 ialpha(quint8 a) { return 0x20 - alpha(a); } + Q_STATIC_INLINE_FUNCTION quint8 alpha(quint8 a) { return (a + 1) >> 3; } + Q_STATIC_INLINE_FUNCTION quint8 ialpha(quint8 a) { return 0x20 - alpha(a); } inline qargb8565 byte_mul(quint8 a) const; inline qargb8565 operator+(qargb8565 v) const; @@ -456,7 +463,7 @@ private: class qrgb565 { public: - static inline bool hasAlpha() { return false; } + Q_STATIC_INLINE_FUNCTION bool hasAlpha() { return false; } qrgb565(int v = 0) : data(v) {} @@ -471,8 +478,8 @@ public: inline quint8 alpha() const { return 0xff; } inline qrgb565 truncedAlpha() { return *this; } - static inline quint8 alpha(quint8 a) { return (a + 1) >> 3; } - static inline quint8 ialpha(quint8 a) { return 0x20 - alpha(a); } + Q_STATIC_INLINE_FUNCTION quint8 alpha(quint8 a) { return (a + 1) >> 3; } + Q_STATIC_INLINE_FUNCTION quint8 ialpha(quint8 a) { return 0x20 - alpha(a); } inline qrgb565 byte_mul(quint8 a) const; @@ -647,7 +654,7 @@ class qrgb555; class qargb8555 { public: - static inline bool hasAlpha() { return true; } + Q_STATIC_INLINE_FUNCTION bool hasAlpha() { return true; } qargb8555() {} inline qargb8555(quint32 v); @@ -659,8 +666,8 @@ public: inline quint8 alpha() const { return data[0]; } inline qargb8555 truncedAlpha() { data[0] &= 0xf8; return *this; } - static inline quint8 alpha(quint8 a) { return (a + 1) >> 3; } - static inline quint8 ialpha(quint8 a) { return 0x20 - alpha(a); } + Q_STATIC_INLINE_FUNCTION quint8 alpha(quint8 a) { return (a + 1) >> 3; } + Q_STATIC_INLINE_FUNCTION quint8 ialpha(quint8 a) { return 0x20 - alpha(a); } inline qargb8555 operator+(qargb8555 v) const; inline qargb8555 byte_mul(quint8 a) const; @@ -677,7 +684,7 @@ private: class qrgb555 { public: - static inline bool hasAlpha() { return false; } + Q_STATIC_INLINE_FUNCTION bool hasAlpha() { return false; } inline qrgb555(int v = 0) : data(v) {} @@ -726,8 +733,8 @@ public: inline quint8 alpha() const { return 0xff; } inline qrgb555 truncedAlpha() { return *this; } - static inline quint8 alpha(quint8 a) { return (a + 1) >> 3; } - static inline quint8 ialpha(quint8 a) { return 0x20 - alpha(a); } + Q_STATIC_INLINE_FUNCTION quint8 alpha(quint8 a) { return (a + 1) >> 3; } + Q_STATIC_INLINE_FUNCTION quint8 ialpha(quint8 a) { return 0x20 - alpha(a); } inline bool operator==(const qrgb555 &v) const { return v.data == data; } inline bool operator!=(const qrgb555 &v) const { return v.data != data; } @@ -875,7 +882,7 @@ class qrgb666; class qargb6666 { public: - static inline bool hasAlpha() { return true; } + Q_STATIC_INLINE_FUNCTION bool hasAlpha() { return true; } inline qargb6666() {} inline qargb6666(quint32 v) { *this = qargb6666(quint32p(v)); } @@ -887,8 +894,8 @@ public: inline quint8 alpha() const; inline qargb6666 truncedAlpha() { return *this; } - static inline quint8 alpha(quint8 a) { return (a + 1) >> 2; } - static inline quint8 ialpha(quint8 a) { return (255 - a + 1) >> 2; } + Q_STATIC_INLINE_FUNCTION quint8 alpha(quint8 a) { return (a + 1) >> 2; } + Q_STATIC_INLINE_FUNCTION quint8 ialpha(quint8 a) { return (255 - a + 1) >> 2; } inline qargb6666 byte_mul(quint8 a) const; inline qargb6666 operator+(qargb6666 v) const; @@ -905,7 +912,7 @@ private: class qrgb666 { public: - static inline bool hasAlpha() { return false; } + Q_STATIC_INLINE_FUNCTION bool hasAlpha() { return false; } inline qrgb666() {} inline qrgb666(quint32 v); @@ -915,8 +922,8 @@ public: inline quint8 alpha() const { return 0xff; } inline qrgb666 truncedAlpha() { return *this; } - static inline quint8 alpha(quint8 a) { return (a + 1) >> 2; } - static inline quint8 ialpha(quint8 a) { return (255 - a + 1) >> 2; } + Q_STATIC_INLINE_FUNCTION quint8 alpha(quint8 a) { return (a + 1) >> 2; } + Q_STATIC_INLINE_FUNCTION quint8 ialpha(quint8 a) { return (255 - a + 1) >> 2; } inline qrgb666 operator+(qrgb666 v) const; inline qrgb666 byte_mul(quint8 a) const; @@ -1073,7 +1080,7 @@ quint32 qargb6666::rawValue() const class qrgb888 { public: - static inline bool hasAlpha() { return false; } + Q_STATIC_INLINE_FUNCTION bool hasAlpha() { return false; } inline qrgb888() {} inline qrgb888(quint32 v); @@ -1082,8 +1089,8 @@ public: inline quint8 alpha() const { return 0xff; } inline qrgb888 truncedAlpha() { return *this; } - static inline quint8 alpha(quint8 a) { return a; } - static inline quint8 ialpha(quint8 a) { return 255 - a; } + Q_STATIC_INLINE_FUNCTION quint8 alpha(quint8 a) { return a; } + Q_STATIC_INLINE_FUNCTION quint8 ialpha(quint8 a) { return 255 - a; } inline qrgb888 byte_mul(quint8 a) const; inline qrgb888 operator+(qrgb888 v) const; @@ -1262,7 +1269,7 @@ class qrgb444; class qargb4444 { public: - static inline bool hasAlpha() { return true; } + Q_STATIC_INLINE_FUNCTION bool hasAlpha() { return true; } inline qargb4444() {} inline qargb4444(quint32 v) { *this = qargb4444(quint32p(v)); } @@ -1276,8 +1283,8 @@ public: inline quint8 alpha() const { return ((data & 0xf000) >> 8) | ((data & 0xf000) >> 12); } inline qargb4444 truncedAlpha() { return *this; } - static inline quint8 alpha(quint8 a) { return (a + 1) >> 4; } - static inline quint8 ialpha(quint8 a) { return 0x10 - alpha(a); } + Q_STATIC_INLINE_FUNCTION quint8 alpha(quint8 a) { return (a + 1) >> 4; } + Q_STATIC_INLINE_FUNCTION quint8 ialpha(quint8 a) { return 0x10 - alpha(a); } inline qargb4444 byte_mul(quint8 a) const; inline bool operator==(const qargb4444 &v) const { return data == v.data; } @@ -1293,7 +1300,7 @@ private: class qrgb444 { public: - static inline bool hasAlpha() { return false; } + Q_STATIC_INLINE_FUNCTION bool hasAlpha() { return false; } inline qrgb444() {} inline qrgb444(quint32 v); @@ -1305,8 +1312,8 @@ public: inline qrgb444 operator+(qrgb444 v) const; inline quint8 alpha() const { return 0xff; } inline qrgb444 truncedAlpha() { return *this; } - static inline quint8 alpha(quint8 a) { return (a + 1) >> 4; } - static inline quint8 ialpha(quint8 a) { return 0x10 - alpha(a); } + Q_STATIC_INLINE_FUNCTION quint8 alpha(quint8 a) { return (a + 1) >> 4; } + Q_STATIC_INLINE_FUNCTION quint8 ialpha(quint8 a) { return 0x10 - alpha(a); } inline qrgb444 byte_mul(quint8 a) const; inline bool operator==(const qrgb444 &v) const { return data == v.data; } @@ -1767,7 +1774,14 @@ do { \ } \ } while (0) +#if defined(Q_CC_RVCT) +# pragma push +# pragma arm +#endif Q_STATIC_INLINE_FUNCTION int qt_div_255(int x) { return (x + (x>>8) + 0x80) >> 8; } +#if defined(Q_CC_RVCT) +# pragma pop +#endif inline ushort qConvertRgb32To16(uint c) { @@ -1810,7 +1824,7 @@ inline int qBlue565(quint16 rgb) { } #if 1 -static inline uint INTERPOLATE_PIXEL_256(uint x, uint a, uint y, uint b) { +Q_STATIC_INLINE_FUNCTION uint INTERPOLATE_PIXEL_256(uint x, uint a, uint y, uint b) { uint t = (x & 0xff00ff) * a + (y & 0xff00ff) * b; t >>= 8; t &= 0xff00ff; @@ -1821,7 +1835,11 @@ static inline uint INTERPOLATE_PIXEL_256(uint x, uint a, uint y, uint b) { return x; } -static inline uint INTERPOLATE_PIXEL_255(uint x, uint a, uint y, uint b) { +#if defined(Q_CC_RVCT) +# pragma push +# pragma arm +#endif +Q_STATIC_INLINE_FUNCTION uint INTERPOLATE_PIXEL_255(uint x, uint a, uint y, uint b) { uint t = (x & 0xff00ff) * a + (y & 0xff00ff) * b; t = (t + ((t >> 8) & 0xff00ff) + 0x800080) >> 8; t &= 0xff00ff; @@ -1832,9 +1850,12 @@ static inline uint INTERPOLATE_PIXEL_255(uint x, uint a, uint y, uint b) { x |= t; return x; } +#if defined(Q_CC_RVCT) +# pragma pop +#endif #else // possible implementation for 64 bit -static inline uint INTERPOLATE_PIXEL_256(uint x, uint a, uint y, uint b) { +Q_STATIC_INLINE_FUNCTION uint INTERPOLATE_PIXEL_256(uint x, uint a, uint y, uint b) { ulong t = (((ulong(x)) | ((ulong(x)) << 24)) & 0x00ff00ff00ff00ff) * a; t += (((ulong(y)) | ((ulong(y)) << 24)) & 0x00ff00ff00ff00ff) * b; t >>= 8; @@ -1842,7 +1863,7 @@ static inline uint INTERPOLATE_PIXEL_256(uint x, uint a, uint y, uint b) { return (uint(t)) | (uint(t >> 24)); } -static inline uint INTERPOLATE_PIXEL_255(uint x, uint a, uint y, uint b) { +Q_STATIC_INLINE_FUNCTION uint INTERPOLATE_PIXEL_255(uint x, uint a, uint y, uint b) { ulong t = (((ulong(x)) | ((ulong(x)) << 24)) & 0x00ff00ff00ff00ff) * a; t += (((ulong(y)) | ((ulong(y)) << 24)) & 0x00ff00ff00ff00ff) * b; t = (t + ((t >> 8) & 0xff00ff00ff00ff) + 0x80008000800080); @@ -1857,7 +1878,7 @@ Q_STATIC_INLINE_FUNCTION uint BYTE_MUL(uint x, uint a) { return (uint(t)) | (uint(t >> 24)); } -static inline uint PREMUL(uint x) { +Q_STATIC_INLINE_FUNCTION uint PREMUL(uint x) { uint a = x >> 24; ulong t = (((ulong(x)) | ((ulong(x)) << 24)) & 0x00ff00ff00ff00ff) * a; t = (t + ((t >> 8) & 0xff00ff00ff00ff) + 0x80008000800080); -- cgit v0.12 From 37beda2303649664c71c2cc32292d5b54547032b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sami=20Meril=C3=A4?= Date: Wed, 29 Apr 2009 15:43:28 +0300 Subject: S60Style: Styled QToolBar implementation. --- src/gui/styles/qs60style.cpp | 198 +++++++++++++++++++++++++++------ src/gui/styles/qs60style_p.h | 41 ++++++- src/gui/styles/qs60style_simulated.cpp | 8 +- src/gui/styles/qs60style_symbian.cpp | 52 ++++++++- 4 files changed, 258 insertions(+), 41 deletions(-) diff --git a/src/gui/styles/qs60style.cpp b/src/gui/styles/qs60style.cpp index 58dcb98..5747ceb 100644 --- a/src/gui/styles/qs60style.cpp +++ b/src/gui/styles/qs60style.cpp @@ -23,6 +23,9 @@ #include "qpushbutton.h" #include "qmenubar.h" #include "qtablewidget.h" +#include "qtoolbar.h" +#include "qtoolbutton.h" +#include "private/qtoolbarextension_p.h" #include "private/qcombobox_p.h" #include "private/qwidget_p.h" #include "qscrollbar.h" @@ -50,16 +53,16 @@ static const QByteArray propertyKeyCurrentlayout = "currentlayout"; #if defined(QT_S60STYLE_LAYOUTDATA_SIMULATED) const layoutHeader QS60StylePrivate::m_layoutHeaders[] = { // *** generated layout data *** -{240,320,1,12,true,QLatin1String("QVGA Landscape Mirrored")}, -{240,320,1,12,false,QLatin1String("QVGA Landscape")}, -{320,240,1,12,true,QLatin1String("QVGA Portrait Mirrored")}, -{320,240,1,12,false,QLatin1String("QVGA Portrait")}, -{360,640,1,12,true,QLatin1String("NHD Landscape Mirrored")}, -{360,640,1,12,false,QLatin1String("NHD Landscape")}, -{640,360,1,12,true,QLatin1String("NHD Portrait Mirrored")}, -{640,360,1,12,false,QLatin1String("NHD Portrait")}, -{352,800,1,9,true,QLatin1String("E90 Landscape Mirrored")}, -{352,800,1,9,false,QLatin1String("E90 Landscape")} +{240,320,1,13,true,QLatin1String("QVGA Landscape Mirrored")}, +{240,320,1,13,false,QLatin1String("QVGA Landscape")}, +{320,240,1,13,true,QLatin1String("QVGA Portrait Mirrored")}, +{320,240,1,13,false,QLatin1String("QVGA Portrait")}, +{360,640,1,13,true,QLatin1String("NHD Landscape Mirrored")}, +{360,640,1,13,false,QLatin1String("NHD Landscape")}, +{640,360,1,13,true,QLatin1String("NHD Portrait Mirrored")}, +{640,360,1,13,false,QLatin1String("NHD Portrait")}, +{352,800,1,12,true,QLatin1String("E90 Landscape Mirrored")}, +{352,800,1,12,false,QLatin1String("E90 Landscape")} // *** End of generated data *** }; const int QS60StylePrivate::m_numberOfLayouts = @@ -67,16 +70,17 @@ const int QS60StylePrivate::m_numberOfLayouts = const short QS60StylePrivate::data[][MAX_PIXELMETRICS] = { // *** generated pixel metrics *** -{5,0,-909,0,0,1,0,0,-1,8,15,22,15,15,7,198,-909,-909,-909,19,15,2,0,0,21,-909,21,-909,4,4,1,-909,-909,0,2,0,0,13,23,17,17,21,21,2,115,21,0,-909,-909,-909,-909,0,0,15,4,-909,0,0,-909,-909,-909,-909,-909,-909,37,21,51,27,51,4,4,5,3,15,-909,5,58,12,5,0,7,4,4,9,4,4,-909,1,-909,-909,-909,-909,4,4,3,1}, -{5,0,-909,0,0,1,0,0,-1,8,15,22,15,15,7,198,-909,-909,-909,19,15,2,0,0,21,-909,21,-909,4,4,1,-909,-909,0,2,0,0,13,23,17,17,21,21,2,115,21,0,-909,-909,-909,-909,0,0,15,5,-909,0,0,-909,-909,-909,-909,-909,-909,37,21,51,27,51,4,4,5,3,15,-909,5,58,12,5,0,4,4,7,9,4,4,-909,1,-909,-909,-909,-909,4,4,3,1}, -{5,0,-909,0,0,1,0,0,-1,8,14,22,15,15,7,164,-909,-909,-909,19,15,2,0,0,21,-909,27,-909,4,4,1,-909,-909,0,7,6,0,13,23,17,17,21,21,7,115,21,0,-909,-909,-909,-909,0,0,15,4,-909,0,0,-909,-909,-909,-909,-909,-909,37,21,65,27,65,4,4,5,3,15,-909,5,58,13,5,0,7,4,4,9,4,4,-909,1,-909,-909,-909,-909,4,4,3,1}, -{5,0,-909,0,0,1,0,0,-1,8,14,22,15,15,7,164,-909,-909,-909,19,15,2,0,0,21,-909,27,-909,4,4,1,-909,-909,0,7,6,0,13,23,17,17,21,21,7,115,21,0,-909,-909,-909,-909,0,0,15,5,-909,0,0,-909,-909,-909,-909,-909,-909,37,21,65,27,65,4,4,5,3,15,-909,5,58,13,5,0,4,4,7,9,4,4,-909,1,-909,-909,-909,-909,4,4,3,1}, -{7,0,-909,0,0,2,0,0,-1,20,53,28,19,19,9,258,-909,-909,-909,29,19,26,0,0,32,-909,72,-909,5,5,2,-909,-909,0,7,21,0,17,29,22,22,27,27,7,173,29,0,-909,-909,-909,-909,0,0,25,5,-909,0,0,-909,-909,-909,-909,-909,-909,87,27,77,35,77,5,5,6,3,19,-909,7,74,19,7,0,8,5,5,12,5,5,-909,2,-909,-909,-909,-909,7,7,3,1}, -{7,0,-909,0,0,2,0,0,-1,20,53,28,19,19,9,258,-909,-909,-909,29,19,26,0,0,32,-909,72,-909,5,5,2,-909,-909,0,7,21,0,17,29,22,22,27,27,7,173,29,0,-909,-909,-909,-909,0,0,25,7,-909,0,0,-909,-909,-909,-909,-909,-909,87,27,77,35,77,5,5,6,3,19,-909,7,74,19,7,0,5,5,8,12,5,5,-909,2,-909,-909,-909,-909,7,7,3,1}, -{7,0,-909,0,0,2,0,0,-1,20,52,28,19,19,9,258,-909,-909,-909,29,19,6,0,0,32,-909,60,-909,5,5,2,-909,-909,0,7,32,0,17,29,22,22,27,27,7,173,29,0,-909,-909,-909,-909,0,0,26,5,-909,0,0,-909,-909,-909,-909,-909,-909,87,27,98,35,98,5,5,6,3,19,-909,7,74,22,7,0,8,5,5,12,5,5,-909,2,-909,-909,-909,-909,7,7,3,1}, -{7,0,-909,0,0,2,0,0,-1,20,52,28,19,19,9,258,-909,-909,-909,29,19,6,0,0,32,-909,60,-909,5,5,2,-909,-909,0,7,32,0,17,29,22,22,27,27,7,173,29,0,-909,-909,-909,-909,0,0,26,7,-909,0,0,-909,-909,-909,-909,-909,-909,87,27,98,35,98,5,5,6,3,19,-909,7,74,22,7,0,5,5,8,12,5,5,-909,2,-909,-909,-909,-909,7,7,3,1}, -{7,0,-909,0,0,2,0,0,-1,10,20,27,18,18,9,301,-909,-909,-909,29,18,5,0,0,35,-909,32,-909,5,5,2,-909,-909,0,2,8,0,16,16,21,21,26,26,2,170,26,0,-909,-909,-909,-909,0,0,21,5,-909,0,0,-909,-909,-909,-909,-909,-909,54,26,265,34,265,5,5,6,3,18,-909,7,72,34,7,0,2,2,3,0,1,1,-909,2,-909,-909,-909,-909,7,7,3,1}, -{7,0,-909,0,0,2,0,0,-1,10,20,27,18,18,9,301,-909,-909,-909,29,18,5,0,0,35,-909,32,-909,5,5,2,-909,-909,0,2,8,0,16,16,21,21,26,26,2,170,26,0,-909,-909,-909,-909,0,0,21,6,-909,0,0,-909,-909,-909,-909,-909,-909,54,26,265,34,265,5,5,6,3,18,-909,7,72,34,7,0,3,2,2,0,1,1,-909,2,-909,-909,-909,-909,7,7,3,1} +{5,0,-909,0,0,1,0,0,-1,8,15,22,15,15,7,198,-909,-909,-909,19,15,2,0,0,21,-909,21,-909,4,4,1,-909,-909,0,2,0,0,13,23,17,17,21,21,2,115,21,0,-909,-909,-909,-909,0,0,15,1,-909,0,0,-909,15,-909,-909,-909,-909,32,21,51,27,51,4,4,5,3,15,-909,5,58,12,5,0,7,4,4,9,4,4,-909,1,-909,-909,-909,-909,4,4,3,1}, +{5,0,-909,0,0,1,0,0,-1,8,15,22,15,15,7,198,-909,-909,-909,19,15,2,0,0,21,-909,21,-909,4,4,1,-909,-909,0,2,0,0,13,23,17,17,21,21,2,115,21,0,-909,-909,-909,-909,0,0,15,1,-909,0,0,-909,15,-909,-909,-909,-909,32,21,51,27,51,4,4,5,3,15,-909,5,58,12,5,0,4,4,7,9,4,4,-909,1,-909,-909,-909,-909,4,4,3,1}, +{5,0,-909,0,0,1,0,0,-1,8,14,22,15,15,7,164,-909,-909,-909,19,15,2,0,0,21,-909,27,-909,4,4,1,-909,-909,0,7,6,0,13,23,17,17,21,21,7,115,21,0,-909,-909,-909,-909,0,0,15,1,-909,0,0,-909,15,-909,-909,-909,-909,32,21,65,27,65,4,4,5,3,15,-909,5,58,13,5,0,7,4,4,9,4,4,-909,1,-909,-909,-909,-909,4,4,3,1}, +{5,0,-909,0,0,1,0,0,-1,8,14,22,15,15,7,164,-909,-909,-909,19,15,2,0,0,21,-909,27,-909,4,4,1,-909,-909,0,7,6,0,13,23,17,17,21,21,7,115,21,0,-909,-909,-909,-909,0,0,15,1,-909,0,0,-909,15,-909,-909,-909,-909,32,21,65,27,65,4,4,5,3,15,-909,5,58,13,5,0,4,4,7,9,4,4,-909,1,-909,-909,-909,-909,4,4,3,1}, +{7,0,-909,0,0,2,0,0,-1,20,53,28,19,19,9,258,-909,-909,-909,29,19,26,0,0,32,-909,72,-909,5,5,2,-909,-909,0,7,21,0,17,29,22,22,27,27,7,173,29,0,-909,-909,-909,-909,0,0,25,2,-909,0,0,-909,25,-909,-909,-909,-909,87,27,77,35,77,5,5,6,3,19,-909,7,74,19,7,0,8,5,5,12,5,5,-909,2,-909,-909,-909,-909,7,7,3,1}, +{7,0,-909,0,0,2,0,0,-1,20,53,28,19,19,9,258,-909,-909,-909,29,19,26,0,0,32,-909,72,-909,5,5,2,-909,-909,0,7,21,0,17,29,22,22,27,27,7,173,29,0,-909,-909,-909,-909,0,0,25,2,-909,0,0,-909,25,-909,-909,-909,-909,87,27,77,35,77,5,5,6,3,19,-909,7,74,19,7,0,5,5,8,12,5,5,-909,2,-909,-909,-909,-909,7,7,3,1}, +{7,0,-909,0,0,2,0,0,-1,20,52,28,19,19,9,258,-909,-909,-909,29,19,6,0,0,32,-909,60,-909,5,5,2,-909,-909,0,7,32,0,17,29,22,22,27,27,7,173,29,0,-909,-909,-909,-909,0,0,26,2,-909,0,0,-909,26,-909,-909,-909,-909,87,27,98,35,98,5,5,6,3,19,-909,7,74,22,7,0,8,5,5,12,5,5,-909,2,-909,-909,-909,-909,7,7,3,1}, +{7,0,-909,0,0,2,0,0,-1,20,52,28,19,19,9,258,-909,-909,-909,29,19,6,0,0,32,-909,60,-909,5,5,2,-909,-909,0,7,32,0,17,29,22,22,27,27,7,173,29,0,-909,-909,-909,-909,0,0,26,2,-909,0,0,-909,26,-909,-909,-909,-909,87,27,98,35,98,5,5,6,3,19,-909,7,74,22,7,0,5,5,8,12,5,5,-909,2,-909,-909,-909,-909,7,7,3,1}, +{7,0,-909,0,0,2,0,0,-1,10,20,27,18,18,9,301,-909,-909,-909,29,18,5,0,0,35,-909,32,-909,5,5,2,-909,-909,0,2,8,0,16,28,21,21,26,26,2,170,26,0,-909,-909,-909,-909,0,0,21,5,-909,0,0,-909,-909,-909,-909,-909,-909,54,26,265,34,265,5,5,6,3,18,-909,7,72,19,7,0,8,6,5,11,6,5,-909,2,-909,-909,-909,-909,5,5,3,1}, +{7,0,-909,0,0,2,0,0,-1,10,20,27,18,18,9,301,-909,-909,-909,29,18,5,0,0,35,-909,32,-909,5,5,2,-909,-909,0,2,8,0,16,28,21,21,26,26,2,170,26,0,-909,-909,-909,-909,0,0,21,6,-909,0,0,-909,-909,-909,-909,-909,-909,54,26,265,34,265,5,5,6,3,18,-909,7,72,19,7,0,5,6,8,11,6,5,-909,2,-909,-909,-909,-909,5,5,3,1} + // *** End of generated data *** }; @@ -95,7 +99,10 @@ const struct QS60StylePrivate::frameElementCenter QS60StylePrivate::m_frameEleme {SE_SettingsList, QS60StyleEnums::SP_QsnFrSetOptCenter}, {SE_TableItem, QS60StyleEnums::SP_QsnFrCaleCenter}, {SE_TableHeaderItem, QS60StyleEnums::SP_QsnFrCaleHeadingCenter}, - {SE_ToolTip, QS60StyleEnums::SP_QsnFrPopupPreviewCenter} + {SE_ToolTip, QS60StyleEnums::SP_QsnFrPopupPreviewCenter}, + {SE_ToolBar, QS60StyleEnums::SP_QsnFrPopupSubCenter}, + {SE_ToolBarButton, QS60StyleEnums::SP_QsnFrSctrlButtonCenter}, + {SE_ToolBarButtonPressed, QS60StyleEnums::SP_QsnFrSctrlButtonCenterPressed}, }; static const int frameElementsCount = int(sizeof(QS60StylePrivate::m_frameElementsData)/sizeof(QS60StylePrivate::m_frameElementsData[0])); @@ -302,6 +309,16 @@ void QS60StylePrivate::drawSkinElement(SkinElements element, QPainter *painter, case SE_ToolTip: drawFrame(SF_ToolTip, painter, rect, flags | SF_PointNorth); break; + case SE_ToolBar: + drawFrame(SF_ToolBar, painter, rect, flags | SF_PointNorth); + break; + case SE_ToolBarButton: + drawFrame(SF_ToolBarButton, painter, rect, flags | SF_PointNorth); + break; + case SE_ToolBarButtonPressed: + drawFrame(SF_ToolBarButtonPressed, painter, rect, flags | SF_PointNorth); + break; + default: break; } @@ -831,15 +848,73 @@ void QS60Style::drawComplexControl(ComplexControl control, const QStyleOptionCom if (const QStyleOptionToolButton *toolBtn = qstyleoption_cast(option)) { const State bflags = toolBtn->state; const QRect button(subControlRect(control, toolBtn, SC_ToolButton, widget)); - QStyleOptionToolButton label = *toolBtn; + QStyleOptionToolButton toolButton = *toolBtn; if (sub&SC_ToolButton) { QStyleOption tool(0); tool.palette = toolBtn->palette; + + // Check if toolbutton is in toolbar. + QToolBar *toolBar = 0; + if (widget) + toolBar = qobject_cast(widget->parentWidget()); + if (bflags & (State_Sunken | State_On | State_Raised)) { tool.rect = button; tool.state = bflags; - drawPrimitive(PE_PanelButtonTool, &tool, painter, widget); + + // todo: I'd like to move extension button next to where last button is + // however, the painter seems to want to clip the button rect even if I turn of the clipping. + if (toolBar && (qobject_cast(widget))){ + /*QList actionList = toolBar->actions(); + const int actionCount = actionList.count(); + const int toolbarWidth = toolBar->width(); + const int extButtonWidth = pixelMetric(PM_ToolBarExtensionExtent, option, widget); + const int toolBarButtonWidth = pixelMetric(PM_ToolBarIconSize, option, widget); + const int frame = pixelMetric(PM_ToolBarFrameWidth, option, widget); + const int margin = pixelMetric(PM_ToolBarItemMargin, option, widget); + const int border = frame + margin; + const int spacing = pixelMetric(PM_ToolBarItemSpacing, option, widget); + const int toolBarButtonArea = toolbarWidth - extButtonWidth - spacing - 2*border; + const int numberOfVisibleButtons = toolBarButtonArea / toolBarButtonWidth; + // new extension button place is after border and all the other visible buttons (with spacings) + const int newXForExtensionButton = numberOfVisibleButtons * toolBarButtonWidth + (numberOfVisibleButtons-1)*spacing + border; + painter->save(); + painter->setClipping(false); + tool.rect.translate(-newXForExtensionButton,0); + painter->restore();*/ + } + + if (toolBar){ + /*if (toolBar->orientation() == Qt::Vertical){ + // todo: I'd like to make all vertical buttons the same size, but again the painter + // prefers to use clipping for button rects, even though clipping has been set off. + painter->save(); + painter->setClipping(false); + + const int origWidth = tool.rect.width(); + const int newWidth = toolBar->width()-2*pixelMetric(PM_ToolBarFrameWidth, option, widget); + painter->translate(origWidth-newWidth,0); + tool.rect.translate(origWidth-tool.rect.width(),0); + tool.rect.setWidth(newWidth); + + if (option->state & QStyle::State_Sunken) + QS60StylePrivate::drawSkinElement(QS60StylePrivate::SE_ToolBarButtonPressed, painter, tool.rect, flags); + else + QS60StylePrivate::drawSkinElement(QS60StylePrivate::SE_ToolBarButton, painter, tool.rect, flags); + + }*/ + if (option->state & QStyle::State_Sunken) + QS60StylePrivate::drawSkinElement(QS60StylePrivate::SE_ToolBarButtonPressed, painter, tool.rect, flags); + else + QS60StylePrivate::drawSkinElement(QS60StylePrivate::SE_ToolBarButton, painter, tool.rect, flags); + /* + if (toolBar->orientation() == Qt::Vertical) + painter->restore(); + */ + } else { + drawPrimitive(PE_PanelButtonTool, &tool, painter, widget); + } } } if (toolBtn->state & State_HasFocus) { @@ -867,15 +942,15 @@ void QS60Style::drawComplexControl(ComplexControl control, const QStyleOptionCom break; default: break; } - label.rect = button; - drawPrimitive(pe, &label, painter, widget); + toolButton.rect = button; + drawPrimitive(pe, &toolButton, painter, widget); } if (toolBtn->text.length()>0 || !toolBtn->icon.isNull()) { const int frameWidth = pixelMetric(PM_DefaultFrameWidth, option, widget); - label.rect = button.adjusted(frameWidth, frameWidth, -frameWidth, -frameWidth); - drawControl(CE_ToolButtonLabel, &label, painter, widget); + toolButton.rect = button.adjusted(frameWidth, frameWidth, -frameWidth, -frameWidth); + drawControl(CE_ToolButtonLabel, &toolButton, painter, widget); } } break; @@ -1556,6 +1631,50 @@ void QS60Style::drawControl(ControlElement element, const QStyleOption *option, QCommonStyle::drawControl(element, header, painter, widget); } break; + +#ifndef QT_NO_TOOLBAR + case CE_ToolBar: + if (const QStyleOptionToolBar *toolBar = qstyleoption_cast(option)) { + const QToolBar *tbWidget = qobject_cast(widget); + + if (!tbWidget || (widget && qobject_cast(widget->parentWidget()))) + break; + + // Normally in S60 5.0+ there is no background for toolbar, but in some cases with versatile QToolBar, + // it looks a bit strange. So, lets fillRect with Button. + if (!QS60StylePrivate::isToolBarBackground()) { + QList actions = tbWidget->actions(); + bool justToolButtonsInToolBar = true; + for (int i = 0; i < actions.size(); ++i) { + QWidget *childWidget = tbWidget->widgetForAction(actions.at(i)); + const QToolButton *button = qobject_cast(childWidget); + if (!button){ + justToolButtonsInToolBar = false; + } + } + + // Draw frame background + // for vertical toolbars with text only and + // for toolbars with extension buttons and + // for toolbars with widgets in them. + if (!justToolButtonsInToolBar || + (tbWidget && + (tbWidget->orientation() == Qt::Vertical) && + (tbWidget->toolButtonStyle() == Qt::ToolButtonTextOnly))) { + painter->save(); + if (widget) + painter->setBrush(widget->palette().button()); + painter->setOpacity(0.3); + painter->fillRect(toolBar->rect, painter->brush()); + painter->restore(); + } + } else { + QS60StylePrivate::drawSkinElement(QS60StylePrivate::SE_ToolBar, painter, toolBar->rect, flags); + } + } + break; +#endif //QT_NO_TOOLBAR + case CE_ShapedFrame: case CE_MenuVMargin: case CE_MenuHMargin: @@ -1592,9 +1711,6 @@ void QS60Style::drawControl(ControlElement element, const QStyleOption *option, case CE_ScrollBarFirst: case CE_ScrollBarLast: case CE_FocusFrame: -#ifndef QT_NO_TOOLBAR - case CE_ToolBar: -#endif //QT_NO_TOOLBAR #ifndef QT_NO_TOOLBOX case CE_ToolBoxTab: case CE_ToolBoxTabShape: @@ -1876,6 +1992,14 @@ void QS60Style::drawPrimitive(PrimitiveElement element, const QStyleOption *opti } break; +#ifndef QT_NO_TOOLBAR + case PE_IndicatorToolBarHandle: + // no toolbar handles in S60/AVKON UI + case PE_IndicatorToolBarSeparator: + // no separators in S60/AVKON UI + break; +#endif //QT_NO_TOOLBAR + case PE_PanelMenuBar: case PE_FrameMenu: break; //disable frame in menu @@ -1900,8 +2024,6 @@ void QS60Style::drawPrimitive(PrimitiveElement element, const QStyleOption *opti #endif //QT_NO_PROGRESSBAR #ifndef QT_NO_TOOLBAR case PE_PanelToolBar: - case PE_IndicatorToolBarHandle: - case PE_IndicatorToolBarSeparator: #endif //QT_NO_TOOLBAR #ifndef QT_NO_COLUMNVIEW case PE_IndicatorColumnViewArrow: @@ -2371,7 +2493,7 @@ QVariant QS60Style::styleProperty(const char *name) const } QIcon QS60Style::standardIconImplementation(StandardPixmap standardIcon, - const QStyleOption * option, const QWidget * widget) const + const QStyleOption *option, const QWidget *widget) const { const int iconDimension = QS60StylePrivate::pixelMetric(QStyle::PM_ToolBarIconSize); const QRect iconSize = (!option) ? QRect(0,0,iconDimension,iconDimension) : option->rect; @@ -2437,6 +2559,16 @@ QIcon QS60Style::standardIconImplementation(StandardPixmap standardIcon, case QStyle::SP_TrashIcon: part = QS60StyleEnums::SP_QgnNoteErased; break; + case QStyle::SP_ToolBarHorizontalExtensionButton: + part = QS60StyleEnums::SP_QgnIndiSubMenu; + if (QApplication::layoutDirection() == Qt::RightToLeft) + adjustedFlags |= QS60StylePrivate::SF_PointSouth; + break; + case QStyle::SP_ToolBarVerticalExtensionButton: + adjustedFlags |= QS60StylePrivate::SF_PointEast; + part = QS60StyleEnums::SP_QgnIndiSubMenu; + break; + default: return QCommonStyle::standardIconImplementation(standardIcon, option, widget); } diff --git a/src/gui/styles/qs60style_p.h b/src/gui/styles/qs60style_p.h index c11d89a..8839866 100644 --- a/src/gui/styles/qs60style_p.h +++ b/src/gui/styles/qs60style_p.h @@ -191,7 +191,34 @@ public: SP_QsnFrSetOptSideB, SP_QsnFrSetOptSideL, SP_QsnFrSetOptSideR, - SP_QsnFrSetOptCenter + SP_QsnFrSetOptCenter, + SP_QsnFrPopupSubCornerTl, // Toolbar background + SP_QsnFrPopupSubCornerTr, + SP_QsnFrPopupSubCornerBl, + SP_QsnFrPopupSubCornerBr, + SP_QsnFrPopupSubSideT, + SP_QsnFrPopupSubSideB, + SP_QsnFrPopupSubSideL, + SP_QsnFrPopupSubSideR, + SP_QsnFrPopupSubCenter, + SP_QsnFrSctrlButtonCornerTl, // Toolbar button + SP_QsnFrSctrlButtonCornerTr, + SP_QsnFrSctrlButtonCornerBl, + SP_QsnFrSctrlButtonCornerBr, + SP_QsnFrSctrlButtonSideT, + SP_QsnFrSctrlButtonSideB, + SP_QsnFrSctrlButtonSideL, + SP_QsnFrSctrlButtonSideR, + SP_QsnFrSctrlButtonCenter, + SP_QsnFrSctrlButtonCornerTlPressed, // Toolbar button, pressed + SP_QsnFrSctrlButtonCornerTrPressed, + SP_QsnFrSctrlButtonCornerBlPressed, + SP_QsnFrSctrlButtonCornerBrPressed, + SP_QsnFrSctrlButtonSideTPressed, + SP_QsnFrSctrlButtonSideBPressed, + SP_QsnFrSctrlButtonSideLPressed, + SP_QsnFrSctrlButtonSideRPressed, + SP_QsnFrSctrlButtonCenterPressed }; enum ColorLists { @@ -245,7 +272,10 @@ public: SE_SettingsList, SE_TableItem, SE_TableHeaderItem, - SE_ToolTip //own graphic available on 3.2+ releases + SE_ToolTip, //own graphic available on 3.2+ releases, + SE_ToolBar, + SE_ToolBarButton, + SE_ToolBarButtonPressed }; enum SkinFrameElements { @@ -257,7 +287,10 @@ public: SF_SettingsList, SF_TableItem, SF_TableHeaderItem, - SF_ToolTip + SF_ToolTip, + SF_ToolBar, + SF_ToolBarButton, + SF_ToolBarButtonPressed }; enum SkinElementFlag { @@ -305,6 +338,8 @@ public: static QPixmap backgroundTexture(); static bool isTouchSupported(); + static bool isToolBarBackground(); + // calculates average color based on button skin graphics (minus borders). QColor colorFromFrameGraphics(QS60StylePrivate::SkinFrameElements frame) const; void setThemePalette(QWidget *widget) const; diff --git a/src/gui/styles/qs60style_simulated.cpp b/src/gui/styles/qs60style_simulated.cpp index 68f0b70..17c1ebe 100644 --- a/src/gui/styles/qs60style_simulated.cpp +++ b/src/gui/styles/qs60style_simulated.cpp @@ -131,7 +131,7 @@ QPixmap QS60StylePrivate::frame(SkinFrameElements frame, const QSize &size, // The size of topLeft defines all other sizes const QSize cornerSize(partSize(topLeft)); // if frame is so small that corners would cover it completely, draw only center piece - const bool drawOnlyCenter = + const bool drawOnlyCenter = 2 * cornerSize.width() + 1 >= size.width() || 2 * cornerSize.height() + 1 >= size.height(); const int cornerWidth = cornerSize.width(); @@ -200,6 +200,12 @@ bool QS60StylePrivate::isTouchSupported() #endif } +bool QS60StylePrivate::isToolBarBackground() +{ + return true; +} + + QFont QS60StylePrivate::s60Font_specific(QS60StyleEnums::FontCategories fontCategory, int pointSize) { QFont result; diff --git a/src/gui/styles/qs60style_symbian.cpp b/src/gui/styles/qs60style_symbian.cpp index a1e7800..353926e 100644 --- a/src/gui/styles/qs60style_symbian.cpp +++ b/src/gui/styles/qs60style_symbian.cpp @@ -201,8 +201,8 @@ const partMapEntry QS60StyleModeSpecifics::m_partMap[] = { /* SP_QsnFrPopupSideR */ {KAknsIIDQsnFrPopupSideR, ENoDraw, ES60_AllReleases, -1,-1,-1}, /* SP_QsnFrPopupCenter */ {KAknsIIDQsnFrPopupCenter, ENoDraw, ES60_AllReleases, -1,-1,-1}, - - /* SP_QsnFrPopupPreviewCornerTl */ {KAknsIIDQsnFrPopupCornerTl, ENoDraw, ES60_3_1, -1, EAknsMajorSkin, 0x19c5}, + // ToolTip graphics different in 3.1 vs. 3.2+. + /* SP_QsnFrPopupPreviewCornerTl */ {KAknsIIDQsnFrPopupCornerTl, ENoDraw, ES60_3_1, -1, EAknsMajorSkin, 0x19c5}, /* KAknsIIDQsnFrPopupPreviewCornerTl */ /* SP_QsnFrPopupPreviewCornerTr */ {KAknsIIDQsnFrPopupCornerTr, ENoDraw, ES60_3_1, -1, EAknsMajorSkin, 0x19c6}, /* SP_QsnFrPopupPreviewCornerBl */ {KAknsIIDQsnFrPopupCornerBl, ENoDraw, ES60_3_1, -1, EAknsMajorSkin, 0x19c3}, /* SP_QsnFrPopupPreviewCornerBr */ {KAknsIIDQsnFrPopupCornerBr, ENoDraw, ES60_3_1, -1, EAknsMajorSkin, 0x19c4}, @@ -221,6 +221,39 @@ const partMapEntry QS60StyleModeSpecifics::m_partMap[] = { /* SP_QsnFrSetOptSideL */ {KAknsIIDQsnFrSetOptSideL, ENoDraw, ES60_AllReleases, -1,-1,-1}, /* SP_QsnFrSetOptSideR */ {KAknsIIDQsnFrSetOptSideR, ENoDraw, ES60_AllReleases, -1,-1,-1}, /* SP_QsnFrSetOptCenter */ {KAknsIIDQsnFrSetOptCenter, ENoDraw, ES60_AllReleases, -1,-1,-1}, + + // No toolbar frame for 5.0+ releases. + /* SP_QsnFrPopupSubCornerTl */ {KAknsIIDQsnFrPopupSubCornerTl, ENoDraw, ES60_3_1 | ES60_3_2, -1,-1,-1}, + /* SP_QsnFrPopupSubCornerTr */ {KAknsIIDQsnFrPopupSubCornerTr, ENoDraw, ES60_3_1 | ES60_3_2, -1,-1,-1}, + /* SP_QsnFrPopupSubCornerBl */ {KAknsIIDQsnFrPopupSubCornerBl, ENoDraw, ES60_3_1 | ES60_3_2, -1,-1,-1}, + /* SP_QsnFrPopupSubCornerBr */ {KAknsIIDQsnFrPopupSubCornerBr, ENoDraw, ES60_3_1 | ES60_3_2, -1,-1,-1}, + /* SP_QsnFrPopupSubSideT */ {KAknsIIDQsnFrPopupSubSideT, ENoDraw, ES60_3_1 | ES60_3_2, -1,-1,-1}, + /* SP_QsnFrPopupSubSideB */ {KAknsIIDQsnFrPopupSubSideB, ENoDraw, ES60_3_1 | ES60_3_2, -1,-1,-1}, + /* SP_QsnFrPopupSubSideL */ {KAknsIIDQsnFrPopupSubSideL, ENoDraw, ES60_3_1 | ES60_3_2, -1,-1,-1}, + /* SP_QsnFrPopupSubSideR */ {KAknsIIDQsnFrPopupSubSideR, ENoDraw, ES60_3_1 | ES60_3_2, -1,-1,-1}, + /* SP_QsnFrPopupSubCenter */ {KAknsIIDQsnFrPopupCenterSubmenu, ENoDraw, ES60_3_1 | ES60_3_2, -1,-1,-1}, + + // Toolbar graphics is different in 3.1/3.2 vs. 5.0 + /* SP_QsnFrSctrlButtonCornerTl */ {KAknsIIDQsnFrButtonTbCornerTl, ENoDraw, ES60_3_1 | ES60_3_2, -1,EAknsMajorSkin,0x2301}, /* KAknsIIDQgnFrSctrlButtonCornerTl*/ + /* SP_QsnFrSctrlButtonCornerTr */ {KAknsIIDQsnFrButtonTbCornerTr, ENoDraw, ES60_3_1 | ES60_3_2, -1,EAknsMajorSkin,0x2302}, + /* SP_QsnFrSctrlButtonCornerBl */ {KAknsIIDQsnFrButtonTbCornerBl, ENoDraw, ES60_3_1 | ES60_3_2, -1,EAknsMajorSkin,0x2303}, + /* SP_QsnFrSctrlButtonCornerBr */ {KAknsIIDQsnFrButtonTbCornerBr, ENoDraw, ES60_3_1 | ES60_3_2, -1,EAknsMajorSkin,0x2304}, + /* SP_QsnFrSctrlButtonSideT */ {KAknsIIDQsnFrButtonTbSideT, ENoDraw, ES60_3_1 | ES60_3_2, -1,EAknsMajorSkin,0x2305}, + /* SP_QsnFrSctrlButtonSideB */ {KAknsIIDQsnFrButtonTbSideB, ENoDraw, ES60_3_1 | ES60_3_2, -1,EAknsMajorSkin,0x2306}, + /* SP_QsnFrSctrlButtonSideL */ {KAknsIIDQsnFrButtonTbSideL, ENoDraw, ES60_3_1 | ES60_3_2, -1,EAknsMajorSkin,0x2307}, + /* SP_QsnFrSctrlButtonSideR */ {KAknsIIDQsnFrButtonTbSideR, ENoDraw, ES60_3_1 | ES60_3_2, -1,EAknsMajorSkin,0x2308}, + /* SP_QsnFrSctrlButtonCenter */ {KAknsIIDQsnFrButtonTbCenter, ENoDraw, ES60_3_1 | ES60_3_2, -1,EAknsMajorSkin,0x2309}, /*KAknsIIDQgnFrSctrlButtonCenter*/ + + // No pressed state for toolbar button in 3.1/3.2. + /* SP_QsnFrSctrlButtonCornerTlPressed */ {KAknsIIDQsnFrSctrlButtonCornerTlPressed, ENoDraw, ES60_5_0, -1,EAknsMajorSkin,0x2171}, /*KAknsIIDQsnFrButtonTbCornerTl*/ + /* SP_QsnFrSctrlButtonCornerTrPressed */ {KAknsIIDQsnFrSctrlButtonCornerTrPressed, ENoDraw, ES60_5_0, -1,EAknsMajorSkin,0x2172}, + /* SP_QsnFrSctrlButtonCornerBlPressed */ {KAknsIIDQsnFrSctrlButtonCornerBlPressed, ENoDraw, ES60_5_0, -1,EAknsMajorSkin,0x2173}, + /* SP_QsnFrSctrlButtonCornerBrPressed */ {KAknsIIDQsnFrSctrlButtonCornerBrPressed, ENoDraw, ES60_5_0, -1,EAknsMajorSkin,0x2174}, + /* SP_QsnFrSctrlButtonSideTPressed */ {KAknsIIDQsnFrSctrlButtonSideTPressed, ENoDraw, ES60_5_0, -1,EAknsMajorSkin,0x2175}, + /* SP_QsnFrSctrlButtonSideBPressed */ {KAknsIIDQsnFrSctrlButtonSideBPressed, ENoDraw, ES60_5_0, -1,EAknsMajorSkin,0x2176}, + /* SP_QsnFrSctrlButtonSideLPressed */ {KAknsIIDQsnFrSctrlButtonSideLPressed, ENoDraw, ES60_5_0, -1,EAknsMajorSkin,0x2177}, + /* SP_QsnFrSctrlButtonSideRPressed */ {KAknsIIDQsnFrSctrlButtonSideRPressed, ENoDraw, ES60_5_0, -1,EAknsMajorSkin,0x2178}, + /* SP_QsnFrSctrlButtonCenterPressed */ {KAknsIIDQsnFrSctrlButtonCenterPressed, ENoDraw, ES60_5_0, -1,EAknsMajorSkin,0x2179} }; QPixmap QS60StyleModeSpecifics::skinnedGraphics( @@ -372,6 +405,11 @@ bool QS60StylePrivate::isTouchSupported() return bool(AknLayoutUtils::PenEnabled()); } +bool QS60StylePrivate::isToolBarBackground() +{ + return (QSysInfo::s60Version() == QSysInfo::SV_S60_3_1 || QSysInfo::s60Version() == QSysInfo::SV_S60_3_2); +} + void qt_s60_fill_background(QPainter *painter, const QRegion &rgn, const QPoint &offset) { const QPixmap backgroundTexture(QS60StylePrivate::backgroundTexture()); @@ -573,13 +611,19 @@ void QS60StyleModeSpecifics::frameIdAndCenterId(QS60StylePrivate::SkinFrameEleme switch(frameElement) { case QS60StylePrivate::SF_ToolTip: if (QSysInfo::s60Version()==QSysInfo::SV_S60_5_0 || QSysInfo::s60Version()==QSysInfo::SV_S60_3_2) { - centerId.Set(EAknsMajorSkin, 0x5300); - frameId.Set(EAknsMajorGeneric, 0x19c2); + centerId.Set(EAknsMajorGeneric, 0x19c2); + frameId.Set(EAknsMajorSkin, 0x5300); } else { centerId.Set(KAknsIIDQsnFrPopupCenter); frameId.iMinor = centerId.iMinor - 9; } break; + case QS60StylePrivate::SF_ToolBar: + if (QSysInfo::s60Version()==QSysInfo::SV_S60_3_1 || QSysInfo::s60Version()==QSysInfo::SV_S60_3_2) { + centerId.Set(KAknsIIDQsnFrPopupCenterSubmenu); + frameId.Set(KAknsIIDQsnFrPopupSub); + } + break; default: // center should be correct here frameId.iMinor = centerId.iMinor - 9; -- cgit v0.12 From d333404c72aa6c707cf389899999f2247454b824 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sami=20Meril=C3=A4?= Date: Wed, 29 Apr 2009 15:46:12 +0300 Subject: S60Style: Use title font for GroupBox title. --- src/gui/styles/qs60style.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/gui/styles/qs60style.cpp b/src/gui/styles/qs60style.cpp index 5747ceb..20eaf16 100644 --- a/src/gui/styles/qs60style.cpp +++ b/src/gui/styles/qs60style.cpp @@ -986,6 +986,11 @@ void QS60Style::drawComplexControl(ComplexControl control, const QStyleOptionCom if ((groupBox->subControls & QStyle::SC_GroupBoxLabel) && !groupBox->text.isEmpty()) { 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); -- cgit v0.12 ize_t i; PyObject *warnings_filters; warnings_filters = get_warnings_attr("filters"); if (warnings_filters == NULL) { if (PyErr_Occurred()) return NULL; } else { Py_DECREF(_filters); _filters = warnings_filters; } if (_filters == NULL || !PyList_Check(_filters)) { PyErr_SetString(PyExc_ValueError, MODULE_NAME ".filters must be a list"); return NULL; } /* _filters could change while we are iterating over it. */ for (i = 0; i < PyList_GET_SIZE(_filters); i++) { PyObject *tmp_item, *action, *msg, *cat, *mod, *ln_obj; Py_ssize_t ln; int is_subclass, good_msg, good_mod; tmp_item = *item = PyList_GET_ITEM(_filters, i); if (PyTuple_Size(tmp_item) != 5) { PyErr_Format(PyExc_ValueError, MODULE_NAME ".filters item %zd isn't a 5-tuple", i); return NULL; } /* Python code: action, msg, cat, mod, ln = item */ action = PyTuple_GET_ITEM(tmp_item, 0); msg = PyTuple_GET_ITEM(tmp_item, 1); cat = PyTuple_GET_ITEM(tmp_item, 2); mod = PyTuple_GET_ITEM(tmp_item, 3); ln_obj = PyTuple_GET_ITEM(tmp_item, 4); good_msg = check_matched(msg, text); good_mod = check_matched(mod, module); is_subclass = PyObject_IsSubclass(category, cat); ln = PyLong_AsSsize_t(ln_obj); if (good_msg == -1 || good_mod == -1 || is_subclass == -1 || (ln == -1 && PyErr_Occurred())) return NULL; if (good_msg && is_subclass && good_mod && (ln == 0 || lineno == ln)) return _PyUnicode_AsString(action); } action = get_default_action(); if (action != NULL) { return _PyUnicode_AsString(action); } PyErr_SetString(PyExc_ValueError, MODULE_NAME ".defaultaction not found"); return NULL; } static int already_warned(PyObject *registry, PyObject *key, int should_set) { PyObject *already_warned; if (key == NULL) return -1; already_warned = PyDict_GetItem(registry, key); if (already_warned != NULL) { int rc = PyObject_IsTrue(already_warned); if (rc != 0) return rc; } /* This warning wasn't found in the registry, set it. */ if (should_set) return PyDict_SetItem(registry, key, Py_True); return 0; } /* New reference. */ static PyObject * normalize_module(PyObject *filename) { PyObject *module; const char *mod_str; Py_ssize_t len; int rc = PyObject_IsTrue(filename); if (rc == -1) return NULL; else if (rc == 0) return PyUnicode_FromString("<unknown>"); mod_str = _PyUnicode_AsString(filename); if (mod_str == NULL) return NULL; len = PyUnicode_GetLength(filename); if (len < 0) return NULL; if (len >= 3 && strncmp(mod_str + (len - 3), ".py", 3) == 0) { module = PyUnicode_Substring(filename, 0, len-3); } else { module = filename; Py_INCREF(module); } return module; } static int update_registry(PyObject *registry, PyObject *text, PyObject *category, int add_zero) { PyObject *altkey, *zero = NULL; int rc; if (add_zero) { zero = PyLong_FromLong(0); if (zero == NULL) return -1; altkey = PyTuple_Pack(3, text, category, zero); } else altkey = PyTuple_Pack(2, text, category); rc = already_warned(registry, altkey, 1); Py_XDECREF(zero); Py_XDECREF(altkey); return rc; } static void show_warning(PyObject *filename, int lineno, PyObject *text, PyObject *category, PyObject *sourceline) { PyObject *f_stderr; PyObject *name; char lineno_str[128]; _Py_IDENTIFIER(__name__); PyOS_snprintf(lineno_str, sizeof(lineno_str), ":%d: ", lineno); name = _PyObject_GetAttrId(category, &PyId___name__); if (name == NULL) /* XXX Can an object lack a '__name__' attribute? */ return; f_stderr = PySys_GetObject("stderr"); if (f_stderr == NULL) { fprintf(stderr, "lost sys.stderr\n"); Py_DECREF(name); return; } /* Print "filename:lineno: category: text\n" */ PyFile_WriteObject(filename, f_stderr, Py_PRINT_RAW); PyFile_WriteString(lineno_str, f_stderr); PyFile_WriteObject(name, f_stderr, Py_PRINT_RAW); PyFile_WriteString(": ", f_stderr); PyFile_WriteObject(text, f_stderr, Py_PRINT_RAW); PyFile_WriteString("\n", f_stderr); Py_XDECREF(name); /* Print " source_line\n" */ if (sourceline) { char *source_line_str = _PyUnicode_AsString(sourceline); if (source_line_str == NULL) return; while (*source_line_str == ' ' || *source_line_str == '\t' || *source_line_str == '\014') source_line_str++; PyFile_WriteString(source_line_str, f_stderr); PyFile_WriteString("\n", f_stderr); } else if (_Py_DisplaySourceLine(f_stderr, filename, lineno, 2) < 0) return; PyErr_Clear(); } static PyObject * warn_explicit(PyObject *category, PyObject *message, PyObject *filename, int lineno, PyObject *module, PyObject *registry, PyObject *sourceline) { PyObject *key = NULL, *text = NULL, *result = NULL, *lineno_obj = NULL; PyObject *item = Py_None; const char *action; int rc; if (registry && !PyDict_Check(registry) && (registry != Py_None)) { PyErr_SetString(PyExc_TypeError, "'registry' must be a dict"); return NULL; } /* Normalize module. */ if (module == NULL) { module = normalize_module(filename); if (module == NULL) return NULL; } else Py_INCREF(module); /* Normalize message. */ Py_INCREF(message); /* DECREF'ed in cleanup. */ rc = PyObject_IsInstance(message, PyExc_Warning); if (rc == -1) { goto cleanup; } if (rc == 1) { text = PyObject_Str(message); if (text == NULL) goto cleanup; category = (PyObject*)message->ob_type; } else { text = message; message = PyObject_CallFunction(category, "O", message); if (message == NULL) goto cleanup; } lineno_obj = PyLong_FromLong(lineno); if (lineno_obj == NULL) goto cleanup; /* Create key. */ key = PyTuple_Pack(3, text, category, lineno_obj); if (key == NULL) goto cleanup; if ((registry != NULL) && (registry != Py_None)) { rc = already_warned(registry, key, 0); if (rc == -1) goto cleanup; else if (rc == 1) goto return_none; /* Else this warning hasn't been generated before. */ } action = get_filter(category, text, lineno, module, &item); if (action == NULL) goto cleanup; if (strcmp(action, "error") == 0) { PyErr_SetObject(category, message); goto cleanup; } /* Store in the registry that we've been here, *except* when the action is "always". */ rc = 0; if (strcmp(action, "always") != 0) { if (registry != NULL && registry != Py_None && PyDict_SetItem(registry, key, Py_True) < 0) goto cleanup; else if (strcmp(action, "ignore") == 0) goto return_none; else if (strcmp(action, "once") == 0) { if (registry == NULL || registry == Py_None) { registry = get_once_registry(); if (registry == NULL) goto cleanup; } /* _once_registry[(text, category)] = 1 */ rc = update_registry(registry, text, category, 0); } else if (strcmp(action, "module") == 0) { /* registry[(text, category, 0)] = 1 */ if (registry != NULL && registry != Py_None) rc = update_registry(registry, text, category, 0); } else if (strcmp(action, "default") != 0) { PyObject *to_str = PyObject_Str(item); const char *err_str = "???"; if (to_str != NULL) { err_str = _PyUnicode_AsString(to_str); if (err_str == NULL) goto cleanup; } PyErr_Format(PyExc_RuntimeError, "Unrecognized action (%s) in warnings.filters:\n %s", action, err_str); Py_XDECREF(to_str); goto cleanup; } } if (rc == 1) /* Already warned for this module. */ goto return_none; if (rc == 0) { PyObject *show_fxn = get_warnings_attr("showwarning"); if (show_fxn == NULL) { if (PyErr_Occurred()) goto cleanup; show_warning(filename, lineno, text, category, sourceline); } else { PyObject *res; if (!PyCallable_Check(show_fxn)) { PyErr_SetString(PyExc_TypeError, "warnings.showwarning() must be set to a " "callable"); Py_DECREF(show_fxn); goto cleanup; } res = PyObject_CallFunctionObjArgs(show_fxn, message, category, filename, lineno_obj, NULL); Py_DECREF(show_fxn); Py_XDECREF(res); if (res == NULL) goto cleanup; } } else /* if (rc == -1) */ goto cleanup; return_none: result = Py_None; Py_INCREF(result); cleanup: Py_XDECREF(key); Py_XDECREF(text); Py_XDECREF(lineno_obj); Py_DECREF(module); Py_XDECREF(message); return result; /* Py_None or NULL. */ } /* filename, module, and registry are new refs, globals is borrowed */ /* Returns 0 on error (no new refs), 1 on success */ static int setup_context(Py_ssize_t stack_level, PyObject **filename, int *lineno, PyObject **module, PyObject **registry) { PyObject *globals; /* Setup globals and lineno. */ PyFrameObject *f = PyThreadState_GET()->frame; while (--stack_level > 0 && f != NULL) f = f->f_back; if (f == NULL) { globals = PyThreadState_Get()->interp->sysdict; *lineno = 1; } else { globals = f->f_globals; *lineno = PyFrame_GetLineNumber(f); } *module = NULL; /* Setup registry. */ assert(globals != NULL); assert(PyDict_Check(globals)); *registry = PyDict_GetItemString(globals, "__warningregistry__"); if (*registry == NULL) { int rc; *registry = PyDict_New(); if (*registry == NULL) return 0; rc = PyDict_SetItemString(globals, "__warningregistry__", *registry); if (rc < 0) goto handle_error; } else Py_INCREF(*registry); /* Setup module. */ *module = PyDict_GetItemString(globals, "__name__"); if (*module == NULL) { *module = PyUnicode_FromString("<string>"); if (*module == NULL) goto handle_error; } else Py_INCREF(*module); /* Setup filename. */ *filename = PyDict_GetItemString(globals, "__file__"); if (*filename != NULL && PyUnicode_Check(*filename)) { Py_ssize_t len; int kind; void *data; if (PyUnicode_READY(*filename)) goto handle_error; len = PyUnicode_GetLength(*filename); kind = PyUnicode_KIND(*filename); data = PyUnicode_DATA(*filename); #define ascii_lower(c) ((c <= 127) ? Py_TOLOWER(c) : 0) /* if filename.lower().endswith((".pyc", ".pyo")): */ if (len >= 4 && PyUnicode_READ(kind, data, len-4) == '.' && ascii_lower(PyUnicode_READ(kind, data, len-3)) == 'p' && ascii_lower(PyUnicode_READ(kind, data, len-2)) == 'y' && (ascii_lower(PyUnicode_READ(kind, data, len-1)) == 'c' || ascii_lower(PyUnicode_READ(kind, data, len-1)) == 'o')) { *filename = PyUnicode_Substring(*filename, 0, PyUnicode_GET_LENGTH(*filename)-1); if (*filename == NULL) goto handle_error; } else Py_INCREF(*filename); } else { const char *module_str = _PyUnicode_AsString(*module); *filename = NULL; if (module_str == NULL) goto handle_error; if (strcmp(module_str, "__main__") == 0) { PyObject *argv = PySys_GetObject("argv"); if (argv != NULL && PyList_Size(argv) > 0) { int is_true; *filename = PyList_GetItem(argv, 0); Py_INCREF(*filename); /* If sys.argv[0] is false, then use '__main__'. */ is_true = PyObject_IsTrue(*filename); if (is_true < 0) { Py_DECREF(*filename); goto handle_error; } else if (!is_true) { Py_DECREF(*filename); *filename = PyUnicode_FromString("__main__"); if (*filename == NULL) goto handle_error; } } else { /* embedded interpreters don't have sys.argv, see bug #839151 */ *filename = PyUnicode_FromString("__main__"); if (*filename == NULL) goto handle_error; } } if (*filename == NULL) { *filename = *module; Py_INCREF(*filename); } } return 1; handle_error: /* filename not XDECREF'ed here as there is no way to jump here with a dangling reference. */ Py_XDECREF(*registry); Py_XDECREF(*module); return 0; } static PyObject * get_category(PyObject *message, PyObject *category) { int rc; /* Get category. */ rc = PyObject_IsInstance(message, PyExc_Warning); if (rc == -1) return NULL; if (rc == 1) category = (PyObject*)message->ob_type; else if (category == NULL) category = PyExc_UserWarning; /* Validate category. */ rc = PyObject_IsSubclass(category, PyExc_Warning); if (rc == -1) return NULL; if (rc == 0) { PyErr_SetString(PyExc_ValueError, "category is not a subclass of Warning"); return NULL; } return category; } static PyObject * do_warn(PyObject *message, PyObject *category, Py_ssize_t stack_level) { PyObject *filename, *module, *registry, *res; int lineno; if (!setup_context(stack_level, &filename, &lineno, &module, &registry)) return NULL; res = warn_explicit(category, message, filename, lineno, module, registry, NULL); Py_DECREF(filename); Py_DECREF(registry); Py_DECREF(module); return res; } static PyObject * warnings_warn(PyObject *self, PyObject *args, PyObject *kwds) { static char *kw_list[] = { "message", "category", "stacklevel", 0 }; PyObject *message, *category = NULL; Py_ssize_t stack_level = 1; if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|On:warn", kw_list, &message, &category, &stack_level)) return NULL; category = get_category(message, category); if (category == NULL) return NULL; return do_warn(message, category, stack_level); } static PyObject * warnings_warn_explicit(PyObject *self, PyObject *args, PyObject *kwds) { static char *kwd_list[] = {"message", "category", "filename", "lineno", "module", "registry", "module_globals", 0}; PyObject *message; PyObject *category; PyObject *filename; int lineno; PyObject *module = NULL; PyObject *registry = NULL; PyObject *module_globals = NULL; if (!PyArg_ParseTupleAndKeywords(args, kwds, "OOOi|OOO:warn_explicit", kwd_list, &message, &category, &filename, &lineno, &module, &registry, &module_globals)) return NULL; if (module_globals) { _Py_IDENTIFIER(get_source); _Py_IDENTIFIER(splitlines); PyObject *tmp; PyObject *loader; PyObject *module_name; PyObject *source; PyObject *source_list; PyObject *source_line; PyObject *returned; if ((tmp = _PyUnicode_FromId(&PyId_get_source)) == NULL) return NULL; if ((tmp = _PyUnicode_FromId(&PyId_splitlines)) == NULL) return NULL; /* Check/get the requisite pieces needed for the loader. */ loader = PyDict_GetItemString(module_globals, "__loader__"); module_name = PyDict_GetItemString(module_globals, "__name__"); if (loader == NULL || module_name == NULL) goto standard_call; /* Make sure the loader implements the optional get_source() method. */ if (!_PyObject_HasAttrId(loader, &PyId_get_source)) goto standard_call; /* Call get_source() to get the source code. */ source = PyObject_CallMethodObjArgs(loader, PyId_get_source.object, module_name, NULL); if (!source) return NULL; else if (source == Py_None) { Py_DECREF(Py_None); goto standard_call; } /* Split the source into lines. */ source_list = PyObject_CallMethodObjArgs(source, PyId_splitlines.object, NULL); Py_DECREF(source); if (!source_list) return NULL; /* Get the source line. */ source_line = PyList_GetItem(source_list, lineno-1); if (!source_line) { Py_DECREF(source_list); return NULL; } /* Handle the warning. */ returned = warn_explicit(category, message, filename, lineno, module, registry, source_line); Py_DECREF(source_list); return returned; } standard_call: return warn_explicit(category, message, filename, lineno, module, registry, NULL); } /* Function to issue a warning message; may raise an exception. */ static int warn_unicode(PyObject *category, PyObject *message, Py_ssize_t stack_level) { PyObject *res; if (category == NULL) category = PyExc_RuntimeWarning; res = do_warn(message, category, stack_level); if (res == NULL) return -1; Py_DECREF(res); return 0; } int PyErr_WarnFormat(PyObject *category, Py_ssize_t stack_level, const char *format, ...) { int ret; PyObject *message; va_list vargs; #ifdef HAVE_STDARG_PROTOTYPES va_start(vargs, format); #else va_start(vargs); #endif message = PyUnicode_FromFormatV(format, vargs); if (message != NULL) { ret = warn_unicode(category, message, stack_level); Py_DECREF(message); } else ret = -1; va_end(vargs); return ret; } int PyErr_WarnEx(PyObject *category, const char *text, Py_ssize_t stack_level) { int ret; PyObject *message = PyUnicode_FromString(text); if (message == NULL) return -1; ret = warn_unicode(category, message, stack_level); Py_DECREF(message); return ret; } /* PyErr_Warn is only for backwards compatibility and will be removed. Use PyErr_WarnEx instead. */ #undef PyErr_Warn PyAPI_FUNC(int) PyErr_Warn(PyObject *category, char *text) { return PyErr_WarnEx(category, text, 1); } /* Warning with explicit origin */ int PyErr_WarnExplicit(PyObject *category, const char *text, const char *filename_str, int lineno, const char *module_str, PyObject *registry) { PyObject *res; PyObject *message = PyUnicode_FromString(text); PyObject *filename = PyUnicode_DecodeFSDefault(filename_str); PyObject *module = NULL; int ret = -1; if (message == NULL || filename == NULL) goto exit; if (module_str != NULL) { module = PyUnicode_FromString(module_str); if (module == NULL) goto exit; } if (category == NULL) category = PyExc_RuntimeWarning; res = warn_explicit(category, message, filename, lineno, module, registry, NULL); if (res == NULL) goto exit; Py_DECREF(res); ret = 0; exit: Py_XDECREF(message); Py_XDECREF(module); Py_XDECREF(filename); return ret; } PyDoc_STRVAR(warn_doc, "Issue a warning, or maybe ignore it or raise an exception."); PyDoc_STRVAR(warn_explicit_doc, "Low-level inferface to warnings functionality."); static PyMethodDef warnings_functions[] = { {"warn", (PyCFunction)warnings_warn, METH_VARARGS | METH_KEYWORDS, warn_doc}, {"warn_explicit", (PyCFunction)warnings_warn_explicit, METH_VARARGS | METH_KEYWORDS, warn_explicit_doc}, /* XXX(brett.cannon): add showwarning? */ /* XXX(brett.cannon): Reasonable to add formatwarning? */ {NULL, NULL} /* sentinel */ }; static PyObject * create_filter(PyObject *category, const char *action) { static PyObject *ignore_str = NULL; static PyObject *error_str = NULL; static PyObject *default_str = NULL; static PyObject *always_str = NULL; PyObject *action_obj = NULL; PyObject *lineno, *result; if (!strcmp(action, "ignore")) { if (ignore_str == NULL) { ignore_str = PyUnicode_InternFromString("ignore"); if (ignore_str == NULL) return NULL; } action_obj = ignore_str; } else if (!strcmp(action, "error")) { if (error_str == NULL) { error_str = PyUnicode_InternFromString("error"); if (error_str == NULL) return NULL; } action_obj = error_str; } else if (!strcmp(action, "default")) { if (default_str == NULL) { default_str = PyUnicode_InternFromString("default"); if (default_str == NULL) return NULL; } action_obj = default_str; } else if (!strcmp(action, "always")) { if (always_str == NULL) { always_str = PyUnicode_InternFromString("always"); if (always_str == NULL) return NULL; } action_obj = always_str; } else { Py_FatalError("unknown action"); } /* This assumes the line number is zero for now. */ lineno = PyLong_FromLong(0); if (lineno == NULL) return NULL; result = PyTuple_Pack(5, action_obj, Py_None, category, Py_None, lineno); Py_DECREF(lineno); return result; } static PyObject * init_filters(void) { PyObject *filters = PyList_New(5); unsigned int pos = 0; /* Post-incremented in each use. */ unsigned int x; const char *bytes_action, *resource_action; if (filters == NULL) return NULL; PyList_SET_ITEM(filters, pos++, create_filter(PyExc_DeprecationWarning, "ignore")); PyList_SET_ITEM(filters, pos++, create_filter(PyExc_PendingDeprecationWarning, "ignore")); PyList_SET_ITEM(filters, pos++, create_filter(PyExc_ImportWarning, "ignore")); if (Py_BytesWarningFlag > 1) bytes_action = "error"; else if (Py_BytesWarningFlag) bytes_action = "default"; else bytes_action = "ignore"; PyList_SET_ITEM(filters, pos++, create_filter(PyExc_BytesWarning, bytes_action)); /* resource usage warnings are enabled by default in pydebug mode */ #ifdef Py_DEBUG resource_action = "always"; #else resource_action = "ignore"; #endif PyList_SET_ITEM(filters, pos++, create_filter(PyExc_ResourceWarning, resource_action)); for (x = 0; x < pos; x += 1) { if (PyList_GET_ITEM(filters, x) == NULL) { Py_DECREF(filters); return NULL; } } return filters; } static struct PyModuleDef warningsmodule = { PyModuleDef_HEAD_INIT, MODULE_NAME, warnings__doc__, 0, warnings_functions, NULL, NULL, NULL, NULL }; PyMODINIT_FUNC _PyWarnings_Init(void) { PyObject *m; m = PyModule_Create(&warningsmodule); if (m == NULL) return NULL; if (_filters == NULL) { _filters = init_filters(); if (_filters == NULL) return NULL; } Py_INCREF(_filters); if (PyModule_AddObject(m, "filters", _filters) < 0) return NULL; if (_once_registry == NULL) { _once_registry = PyDict_New(); if (_once_registry == NULL) return NULL; } Py_INCREF(_once_registry); if (PyModule_AddObject(m, "_onceregistry", _once_registry) < 0) return NULL; if (_default_action == NULL) { _default_action = PyUnicode_FromString("default"); if (_default_action == NULL) return NULL; } Py_INCREF(_default_action); if (PyModule_AddObject(m, "_defaultaction", _default_action) < 0) return NULL; return m; }