Debian Codegraph @

src/stylehelper.cpp

raw symbols SCIP
1 /**************************************************************************
2 **
3 ** This file is part of Qt Creator
4 **
5 ** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
6 **
7 ** Contact: Nokia Corporation ([email protected])
8 **
9 ** Commercial Usage
10 **
11 ** Licensees holding valid Qt Commercial licenses may use this file in
12 ** accordance with the Qt Commercial License Agreement provided with the
13 ** Software or, alternatively, in accordance with the terms contained in
14 ** a written agreement between you and Nokia.
15 **
16 ** GNU Lesser General Public License Usage
17 **
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** If you are unsure which license is appropriate for your use, please
26 ** contact the sales department at http://qt.nokia.com/contact.
27 **
28 **************************************************************************/
29
30 #include "stylehelper.h"cxx . . $ `<file>/src/stylehelper.h`/
31
32 #include <QApplication>
33 #include <QStyleOption>
34 #include <QWidget>
35 #include <QtCore/QObject>
36 #include <QtCore/QRect>
37 #include <QtGui/QPainter>
38 #include <QtGui/QPalette>
39 #include <QtGui/QPixmapCache>
40
41 // Clamps float color values within (0, 255)
42 static int clampcxx . . $ clamp(1bb0578f3efdc255).(float x)
43 {
44 const int val = x > 255 ? 255 : static_cast<int>(x);
45 return val < 0 ? 0 : val;
46 }
47
48 namespace Utilscxx . . $ Utils/ {
49
50 qrealcxx . . $ qreal# StyleHelpercxx . . $ Utils/StyleHelper#::sidebarFontSizecxx . . $ Utils/StyleHelper#sidebarFontSize(31fa7155c10fdd13).()
51 {
52 #if defined(Q_WS_MAC)
53 return 10;
54 #else
55 return 7.5;
56 #endif
57 }
58
59 QColorcxx . . $ QColor# StyleHelpercxx . . $ Utils/StyleHelper#::panelTextColorcxx . . $ Utils/StyleHelper#panelTextColor(9d1fd1d8b71bb60d).(bool lightColored)
60 {
61 if (!lightColored)
62 return Qtcxx . . $ QColor#QColor(408ec4d5924bfb00).::whitecxx . . $ Qt/white.;
63 else
64 return Qtcxx . . $ QColor#QColor(408ec4d5924bfb00).::blackcxx . . $ Qt/black.;
65 }
66
67 // Invalid by default, setBaseColor needs to be called at least once
68 QColorcxx . . $ QColor# StyleHelpercxx . . $ Utils/StyleHelper#::m_baseColorcxx . . $ Utils/StyleHelper#m_baseColor.;
69 QColorcxx . . $ QColor# StyleHelpercxx . . $ Utils/StyleHelper#::m_requestedBaseColorcxx . . $ Utils/StyleHelper#m_requestedBaseColor.;
70
71 QColorcxx . . $ QColor# StyleHelpercxx . . $ Utils/StyleHelper#::baseColorcxx . . $ Utils/StyleHelper#baseColor(9d1fd1d8b71bb60d).(bool lightColored)
72 {
73 if (!lightColored)
74 return m_baseColorcxx . . $ QColor#QColor(c396aab421781ee8).;
75 else
76 return m_baseColorcxx . . $ Utils/StyleHelper#m_baseColor..lightercxx . . $ QColor#lighter(a312dab4e0811e0).(230);
77 }
78
79 QColorcxx . . $ QColor# StyleHelpercxx . . $ Utils/StyleHelper#::highlightColorcxx . . $ Utils/StyleHelper#highlightColor(9d1fd1d8b71bb60d).(bool lightColored)
80 {
81 QColorcxx . . $ QColor# result = baseColorcxx . . $ Utils/StyleHelper#baseColor(9d1fd1d8b71bb60d).(lightColored);
82 if (!lightColored)
83 result.setHsvcxx . . $ QColor#setHsv(748afa4755bc9595).(result.huecxx . . $ QColor#hue(ea6fe5115c70a13f).(),
84 clampcxx . . $ clamp(1bb0578f3efdc255).(result.saturationcxx . . $ QColor#saturation(ea6fe5115c70a13f).()),
85 clampcxx . . $ clamp(1bb0578f3efdc255).(result.valuecxx . . $ QColor#value(ea6fe5115c70a13f).() * 1.16));
86 else
87 result.setHsvcxx . . $ QColor#setHsv(748afa4755bc9595).(result.huecxx . . $ QColor#hue(ea6fe5115c70a13f).(),
88 clampcxx . . $ clamp(1bb0578f3efdc255).(result.saturationcxx . . $ QColor#saturation(ea6fe5115c70a13f).()),
89 clampcxx . . $ clamp(1bb0578f3efdc255).(result.valuecxx . . $ QColor#value(ea6fe5115c70a13f).() * 1.06));
90 return resultcxx . . $ QColor#QColor(8255ad9db0ee6797).;
91 }
92
93 QColorcxx . . $ QColor# StyleHelpercxx . . $ Utils/StyleHelper#::shadowColorcxx . . $ Utils/StyleHelper#shadowColor(9d1fd1d8b71bb60d).(bool lightColored)
94 {
95 QColorcxx . . $ QColor# result = baseColorcxx . . $ Utils/StyleHelper#baseColor(9d1fd1d8b71bb60d).(lightColored);
96 result.setHsvcxx . . $ QColor#setHsv(748afa4755bc9595).(result.huecxx . . $ QColor#hue(ea6fe5115c70a13f).(),
97 clampcxx . . $ clamp(1bb0578f3efdc255).(result.saturationcxx . . $ QColor#saturation(ea6fe5115c70a13f).() * 1.1),
98 clampcxx . . $ clamp(1bb0578f3efdc255).(result.valuecxx . . $ QColor#value(ea6fe5115c70a13f).() * 0.70));
99 return resultcxx . . $ QColor#QColor(8255ad9db0ee6797).;
100 }
101
102 QColorcxx . . $ QColor# StyleHelpercxx . . $ Utils/StyleHelper#::borderColorcxx . . $ Utils/StyleHelper#borderColor(9d1fd1d8b71bb60d).(bool lightColored)
103 {
104 QColorcxx . . $ QColor# result = baseColorcxx . . $ Utils/StyleHelper#baseColor(9d1fd1d8b71bb60d).(lightColored);
105 result.setHsvcxx . . $ QColor#setHsv(748afa4755bc9595).(result.huecxx . . $ QColor#hue(ea6fe5115c70a13f).(),
106 result.saturationcxx . . $ QColor#saturation(ea6fe5115c70a13f).(),
107 result.valuecxx . . $ QColor#value(ea6fe5115c70a13f).() / 2);
108 return resultcxx . . $ QColor#QColor(8255ad9db0ee6797).;
109 }
110
111 // We try to ensure that the actual color used are within
112 // reasonalbe bounds while generating the actual baseColor
113 // from the users request.
114 void StyleHelpercxx . . $ Utils/StyleHelper#::setBaseColorcxx . . $ Utils/StyleHelper#setBaseColor(129a55e114526ad3).(const QColorcxx . . $ QColor#& newcolor)
115 {
116 m_requestedBaseColorcxx . . $ Utils/StyleHelper#m_requestedBaseColor. =cxx . . $ QColor#`operator=`(a3db1be773b26671). newcolor;
117
118 QColorcxx . . $ QColor# colorcxx . . $ QColor#QColor(ced63f7c635d850d).;
119 color.setHsvcxx . . $ QColor#setHsv(748afa4755bc9595).(newcolor.huecxx . . $ QColor#hue(ea6fe5115c70a13f).(),
120 newcolor.saturationcxx . . $ QColor#saturation(ea6fe5115c70a13f).() * 0.7,
121 64 + newcolor.valuecxx . . $ QColor#value(ea6fe5115c70a13f).() / 3);
122
123 if (color.isValidcxx . . $ QColor#isValid(3482b152b9333168).() && color !=cxx . . $ QColor#`operator!=`(8df5130dab4f572b). m_baseColorcxx . . $ Utils/StyleHelper#m_baseColor.) {
124 m_baseColorcxx . . $ Utils/StyleHelper#m_baseColor. =cxx . . $ QColor#`operator=`(a3db1be773b26671). color;
125 foreachcxx . . $ `<external>/15045578679651060896/qglobal.h:1145:13`! (QWidget* w, QApplication::topLevelWidgets())
126 w->updatecxx . . $ QWidget#update(49f6e7a06ebc5aa8).();
127 }
128 }
129
130 static void verticalGradientHelpercxx . . $ Utils/verticalGradientHelper(a205dbb5f371807).(QPaintercxx . . $ QPainter#* p, const QRectcxx . . $ QRect#& spanRect, const QRectcxx . . $ QRect#& rect, bool lightColored)
131 {
132 QColorcxx . . $ QColor# highlight = StyleHelpercxx . . $ Utils/StyleHelper#::highlightColorcxx . . $ Utils/StyleHelper#highlightColor(9d1fd1d8b71bb60d).(lightColored);
133 QColorcxx . . $ QColor# shadow = StyleHelpercxx . . $ Utils/StyleHelper#::shadowColorcxx . . $ Utils/StyleHelper#shadowColor(9d1fd1d8b71bb60d).(lightColored);
134 QLinearGradientcxx . . $ QLinearGradient# gradcxx . . $ QLinearGradient#QLinearGradient(3628e2b324c1bb0).(spanRectcxx . . $ QPointF#QPointF(4f9e9534be445c03)..topRightcxx . . $ QRect#topRight(d9aead42ba53cd9b).(), spanRectcxx . . $ QPointF#QPointF(4f9e9534be445c03)..topLeftcxx . . $ QRect#topLeft(d9aead42ba53cd9b).());
135 grad.setColorAtcxx . . $ QGradient#setColorAt(e8a5895791b6fa8c).(0, highlight.lightercxx . . $ QColor#lighter(a312dab4e0811e0).(117));
136 grad.setColorAtcxx . . $ QGradient#setColorAt(e8a5895791b6fa8c).(1, shadow.darkercxx . . $ QColor#darker(a312dab4e0811e0).(109));
137 p->fillRectcxx . . $ QPainter#fillRect(a493e38a50e0b286).(rect, gradcxx . . $ QBrush#QBrush(cbd511d3bf8d464c).);
138
139 QColorcxx . . $ QColor# lightcxx . . $ QColor#QColor(2261ffe5112eab06).(255, 255, 255, 80);
140 p->setPencxx . . $ QPainter#setPen(129a55e114526ad3).(light);
141 p->drawLinecxx . . $ QPainter#drawLine(1c04991299834bae).(rect.topRightcxx . . $ QRect#topRight(d9aead42ba53cd9b).() -cxx . . $ operator-(e1fd31f94663a124). QPointcxx . . $ QPoint#QPoint(3e454b8ccf442868).(1, 0), rect.bottomRightcxx . . $ QRect#bottomRight(d9aead42ba53cd9b).() -cxx . . $ operator-(e1fd31f94663a124). QPointcxx . . $ QPoint#QPoint(3e454b8ccf442868).(1, 0));
142 QColorcxx . . $ QColor# darkcxx . . $ QColor#QColor(2261ffe5112eab06).(0, 0, 0, 90);
143 p->setPencxx . . $ QPainter#setPen(129a55e114526ad3).(dark);
144 p->drawLinecxx . . $ QPainter#drawLine(1c04991299834bae).(rect.topLeftcxx . . $ QRect#topLeft(d9aead42ba53cd9b).(), rect.bottomLeftcxx . . $ QRect#bottomLeft(d9aead42ba53cd9b).());
145 }
146
147 void StyleHelpercxx . . $ Utils/StyleHelper#::verticalGradientcxx . . $ Utils/StyleHelper#verticalGradient(a205dbb5f371807).(QPaintercxx . . $ QPainter#* painter, const QRectcxx . . $ QRect#& spanRect, const QRectcxx . . $ QRect#& clipRect, bool lightColored)
148 {
149 if (StyleHelpercxx . . $ Utils/StyleHelper#::usePixmapCachecxx . . $ Utils/StyleHelper#usePixmapCache(c9857a73d68e59ba).()) {
150 QStringcxx . . $ QString# keycxx . . $ QString#QString(ced63f7c635d850d).;
151 QColorcxx . . $ QColor# keyColor = baseColorcxx . . $ Utils/StyleHelper#baseColor(9d1fd1d8b71bb60d).(lightColored);
152 key.sprintfcxx . . $ QString#sprintf(88e04698cdda8d9).("mh_vertical %d %d %d %d %d",
153 spanRect.widthcxx . . $ QRect#width(ea6fe5115c70a13f).(), spanRect.heightcxx . . $ QRect#height(ea6fe5115c70a13f).(), clipRect.widthcxx . . $ QRect#width(ea6fe5115c70a13f).(),
154 clipRect.heightcxx . . $ QRect#height(ea6fe5115c70a13f).(), keyColor.rgbcxx . . $ QColor#rgb(d22c8608b6eae7b5).());
155 ;
156
157 QPixmapcxx . . $ QPixmap# pixmapcxx . . $ QPixmap#QPixmap(49f6e7a06ebc5aa8).;
158 if (!QPixmapCachecxx . . $ QPixmapCache#::findcxx . . $ QPixmapCache#find(7ac16cc81568da16).(key, pixmap)) {
159 pixmap =cxx . . $ QPixmap#`operator=`(4972951fe8d596b5). QPixmapcxx . . $ QPixmap#QPixmap(1c5f201b4c2f0aba).(clipRect.sizecxx . . $ QRect#size(31eef80d4686a819).());
160 QPaintercxx . . $ QPainter# pcxx . . $ QPainter#QPainter(dd2eedc069b0ab5f).(&pixmap);
161 QRectcxx . . $ QRect# rectcxx . . $ QRect#QRect(2261ffe5112eab06).(0, 0, clipRect.widthcxx . . $ QRect#width(ea6fe5115c70a13f).(), clipRect.heightcxx . . $ QRect#height(ea6fe5115c70a13f).());
162 verticalGradientHelpercxx . . $ Utils/verticalGradientHelper(a205dbb5f371807).(&p, spanRect, rect, lightColored);
163 p.endcxx . . $ QPainter#end(c9857a73d68e59ba).();
164 QPixmapCachecxx . . $ QPixmapCache#::insertcxx . . $ QPixmapCache#insert(ea4708518c20dff9).(key, pixmap);
165 }
166
167 painter->drawPixmapcxx . . $ QPainter#drawPixmap(ec91560cc62f4651).(clipRect.topLeftcxx . . $ QRect#topLeft(d9aead42ba53cd9b).(), pixmap);
168 } else {
169 verticalGradientHelpercxx . . $ Utils/verticalGradientHelper(a205dbb5f371807).(painter, spanRect, clipRect, lightColored);
170 }
171 }
172
173 // Draws a cached pixmap with shadow
174 void StyleHelpercxx . . $ Utils/StyleHelper#::drawIconWithShadowcxx . . $ Utils/StyleHelper#drawIconWithShadow(4cbb369097595e05).(const QIconcxx . . $ QIcon#& icon, const QRectcxx . . $ QRect#& rect,
175 QPaintercxx . . $ QPainter#* p, QIconcxx . . $ QIcon#::Modecxx . . $ QIcon#Mode# iconMode, int radius, const QColorcxx . . $ QColor#& color, const QPointcxx . . $ QPoint#& offset)
176 {
177 QPixmapcxx . . $ QPixmap# cachecxx . . $ QPixmap#QPixmap(49f6e7a06ebc5aa8).;
178 QStringcxx . . $ QString# pixmapName = QStringcxx . . $ QString#QString(85c52e162fed56f9).("icon %0 %1 %2").argcxx . . $ QString#arg(bc2efffa9f9cbddb).(icon.cacheKeycxx . . $ QIcon#cacheKey(98833e9ab7de59a4).()).argcxx . . $ QString#arg(64ab2ed17cc11715).(iconMode).argcxx . . $ QString#arg(64ab2ed17cc11715).(rect.heightcxx . . $ QRect#height(ea6fe5115c70a13f).());
179
180 if (!QPixmapCachecxx . . $ QPixmapCache#::findcxx . . $ QPixmapCache#find(7ac16cc81568da16).(pixmapName, cache)) {
181 QPixmapcxx . . $ QPixmap# px = icon.pixmapcxx . . $ QIcon#pixmap(bdedaf553c804fc0).(rect.sizecxx . . $ QRect#size(31eef80d4686a819).());
182 cache =cxx . . $ QPixmap#`operator=`(4972951fe8d596b5). QPixmapcxx . . $ QPixmap#QPixmap(1c5f201b4c2f0aba).(px.sizecxx . . $ QPixmap#size(4b3b776e5ee2b367).() +cxx . . $ operator+(21af30ee558738d3). QSizecxx . . $ QSize#QSize(c0d38f4800714fae).(radius * 2, radius * 2));
183 cache.fillcxx . . $ QPixmap#fill(129a55e114526ad3).(Qtcxx . . $ QColor#QColor(408ec4d5924bfb00).::transparentcxx . . $ Qt/transparent.);
184
185 QPaintercxx . . $ QPainter# cachePaintercxx . . $ QPainter#QPainter(dd2eedc069b0ab5f).(&cache);
186 if (iconMode == QIconcxx . . $ QIcon#::Disabledcxx . . $ QIcon#Disabled.) {
187 QImagecxx . . $ QImage# im = px.toImagecxx . . $ QPixmap#toImage(b37cda5778b78373).().convertToFormatcxx . . $ QImage#convertToFormat(17f068fded86ac61).(QImagecxx . . $ QImage#::Format_ARGB32cxx . . $ QImage#Format_ARGB32.);
188 for (int y = 0; y < im.heightcxx . . $ QImage#height(455f465bc33b4cdf).(); ++y) {
189 QRgbcxx . . $ QRgb#* scanLine = (QRgbcxx . . $ QRgb#*)im.scanLinecxx . . $ QImage#scanLine(f18dc31a6ecbac56).(y);
190 for (int x = 0; x < im.widthcxx . . $ QImage#width(455f465bc33b4cdf).(); ++x) {
191 QRgbcxx . . $ QRgb# pixel = *scanLine;
192 char intensity = qGraycxx . . $ qGray(4c679297bf94b9eb).(pixel);
193 *scanLine = qRgbacxx . . $ qRgba(7a6d2d8711beacc4).(intensity, intensity, intensity, qAlphacxx . . $ qAlpha(4c679297bf94b9eb).(pixel));
194 ++scanLine;
195 }
196 }
197 px =cxx . . $ QPixmap#`operator=`(4972951fe8d596b5). QPixmapcxx . . $ QPixmap#::fromImagecxx . . $ QPixmap#fromImage(e89e6101063912f).(im);
198 }
199
200 // Draw shadow
201 QImagecxx . . $ QImage# tmpcxx . . $ QImage#QImage(fe815e29ae3e37c9).(px.sizecxx . . $ QPixmap#size(4b3b776e5ee2b367).() +cxx . . $ operator+(21af30ee558738d3). QSizecxx . . $ QSize#QSize(c0d38f4800714fae).(radius * 2, radius * 2 + 1), QImagecxx . . $ QImage#::Format_ARGB32_Premultipliedcxx . . $ QImage#Format_ARGB32_Premultiplied.);
202 tmp.fillcxx . . $ QImage#fill(cd98eb3c6d110ca7).(Qtcxx . . $ Qt/::transparentcxx . . $ Qt/transparent.);
203
204 QPaintercxx . . $ QPainter# tmpPaintercxx . . $ QPainter#QPainter(dd2eedc069b0ab5f).(&tmp);
205 tmpPainter.setCompositionModecxx . . $ QPainter#setCompositionMode(233e5f91a307c5b).(QPaintercxx . . $ QPainter#::CompositionMode_Sourcecxx . . $ QPainter#CompositionMode_Source.);
206 tmpPainter.drawPixmapcxx . . $ QPainter#drawPixmap(ec91560cc62f4651).(QPointcxx . . $ QPoint#QPoint(3e454b8ccf442868).(radius, radius), px);
207 tmpPainter.endcxx . . $ QPainter#end(c9857a73d68e59ba).();
208
209 // blur the alpha channel
210 QImagecxx . . $ QImage# blurredcxx . . $ QImage#QImage(fe815e29ae3e37c9).(tmp.sizecxx . . $ QImage#size(4b3b776e5ee2b367).(), QImagecxx . . $ QImage#::Format_ARGB32_Premultipliedcxx . . $ QImage#Format_ARGB32_Premultiplied.);
211 blurred.fillcxx . . $ QImage#fill(cd98eb3c6d110ca7).(Qtcxx . . $ Qt/::transparentcxx . . $ Qt/transparent.);
212 QPaintercxx . . $ QPainter# blurPaintercxx . . $ QPainter#QPainter(dd2eedc069b0ab5f).(&blurred);
213 qt_blurImagecxx . . $ qt_blurImage(55ec08f7b5f5408f).(&blurPainter, tmp, radius, false, true);
214 blurPainter.endcxx . . $ QPainter#end(c9857a73d68e59ba).();
215
216 tmp =cxx . . $ QImage#`operator=`(acb38987752f17f1). blurred;
217
218 // blacken the image...
219 tmpPainter.begincxx . . $ QPainter#begin(3d42010d693361d5).(&tmp);
220 tmpPainter.setCompositionModecxx . . $ QPainter#setCompositionMode(233e5f91a307c5b).(QPaintercxx . . $ QPainter#::CompositionMode_SourceIncxx . . $ QPainter#CompositionMode_SourceIn.);
221 tmpPainter.fillRectcxx . . $ QPainter#fillRect(b5c43933f089f858).(tmp.rectcxx . . $ QImage#rect(d857385bac04cbf7).(), color);
222 tmpPainter.endcxx . . $ QPainter#end(c9857a73d68e59ba).();
223
224 tmpPainter.begincxx . . $ QPainter#begin(3d42010d693361d5).(&tmp);
225 tmpPainter.setCompositionModecxx . . $ QPainter#setCompositionMode(233e5f91a307c5b).(QPaintercxx . . $ QPainter#::CompositionMode_SourceIncxx . . $ QPainter#CompositionMode_SourceIn.);
226 tmpPainter.fillRectcxx . . $ QPainter#fillRect(b5c43933f089f858).(tmp.rectcxx . . $ QImage#rect(d857385bac04cbf7).(), color);
227 tmpPainter.endcxx . . $ QPainter#end(c9857a73d68e59ba).();
228
229 // draw the blurred drop shadow...
230 cachePainter.drawImagecxx . . $ QPainter#drawImage(2eae8db60707222a).(QRectcxx . . $ QRect#QRect(2261ffe5112eab06).(0, 0, cache.rectcxx . . $ QPixmap#rect(d857385bac04cbf7).().widthcxx . . $ QRect#width(ea6fe5115c70a13f).(), cache.rectcxx . . $ QPixmap#rect(d857385bac04cbf7).().heightcxx . . $ QRect#height(ea6fe5115c70a13f).()), tmp);
231
232 // Draw the actual pixmap...
233 cachePainter.drawPixmapcxx . . $ QPainter#drawPixmap(ec91560cc62f4651).(QPointcxx . . $ QPoint#QPoint(3e454b8ccf442868).(radius, radius) +cxx . . $ operator+(e1fd31f94663a124). offset, px);
234 QPixmapCachecxx . . $ QPixmapCache#::insertcxx . . $ QPixmapCache#insert(ea4708518c20dff9).(pixmapName, cache);
235 }
236
237 QRectcxx . . $ QRect# targetRect = cache.rectcxx . . $ QPixmap#rect(d857385bac04cbf7).();
238 targetRect.moveCentercxx . . $ QRect#moveCenter(4c7e4a2350b03b37).(rect.centercxx . . $ QRect#center(d9aead42ba53cd9b).());
239 p->drawPixmapcxx . . $ QPainter#drawPixmap(ec91560cc62f4651).(targetRect.topLeftcxx . . $ QRect#topLeft(d9aead42ba53cd9b).() -cxx . . $ operator-(e1fd31f94663a124). offset, cache);
240 }
241
242 } // namespace Utils