26 #include <QApplication>
27 #include <QStyleOption>
37 const QStyleOption &option,
38 QPainter *painter)
const
42 painter->setRenderHint(QPainter::Antialiasing);
44 const QRect optRect = option.rect;
45 QFont font(QApplication::font());
47 const QFontMetrics fontMetrics = QFontMetrics(font);
49 const bool leftToRight = painter->layoutDirection() == Qt::LeftToRight;
53 QPainterPath path(optRect.bottomLeft());
55 path.lineTo(
QPoint(optRect.topLeft().x(), optRect.topLeft().y() - 3));
56 const QPointF topLeft(optRect.topLeft());
57 QRectF arc(topLeft, QSizeF(4, 4));
58 path.arcTo(arc, 180, -90);
59 path.lineTo(optRect.topRight());
60 path.lineTo(optRect.bottomRight());
61 path.lineTo(optRect.bottomLeft());
63 QColor window(option.palette.window().color());
64 const QColor base(option.palette.base().color());
66 window.setAlphaF(0.4);
68 QLinearGradient decoGradient1;
70 decoGradient1.setStart(optRect.topLeft());
71 decoGradient1.setFinalStop(optRect.bottomLeft());
73 decoGradient1.setStart(optRect.topRight());
74 decoGradient1.setFinalStop(optRect.bottomRight());
76 decoGradient1.setColorAt(0, window);
77 decoGradient1.setColorAt(1, Qt::transparent);
79 QLinearGradient decoGradient2;
81 decoGradient2.setStart(optRect.topLeft());
82 decoGradient2.setFinalStop(optRect.topRight());
84 decoGradient2.setStart(optRect.topRight());
85 decoGradient2.setFinalStop(optRect.topLeft());
87 decoGradient2.setColorAt(0, Qt::transparent);
88 decoGradient2.setColorAt(1, base);
90 painter->fillPath(path, decoGradient1);
91 painter->fillPath(path, decoGradient2);
96 QRect newOptRect(optRect);
99 newOptRect.translate(1, 1);
101 newOptRect.translate(-1, 1);
107 painter->setPen(option.palette.base().color());
110 const QPointF topLeft(newOptRect.topLeft());
111 arc = QRectF(topLeft, QSizeF(4, 4));
112 arc.translate(0.5, 0.5);
113 painter->drawArc(arc, 1440, 1440);
115 QPointF topRight(newOptRect.topRight());
117 arc = QRectF(topRight, QSizeF(4, 4));
118 arc.translate(-0.5, 0.5);
119 painter->drawArc(arc, 0, 1440);
128 QPoint verticalGradBottom;
130 start = newOptRect.topLeft();
131 verticalGradBottom = newOptRect.topLeft();
133 start = newOptRect.topRight();
134 verticalGradBottom = newOptRect.topRight();
137 verticalGradBottom.ry() += newOptRect.height() - 3;
138 QLinearGradient gradient(start, verticalGradBottom);
139 gradient.setColorAt(0, option.palette.base().color());
140 gradient.setColorAt(1, Qt::transparent);
141 painter->fillRect(
QRect(start,
QSize(1, newOptRect.height() - 3)), gradient);
150 start = newOptRect.topLeft();
151 horizontalGradTop = newOptRect.topLeft();
153 horizontalGradTop.rx() += newOptRect.width() - 3;
155 start = newOptRect.topRight();
156 horizontalGradTop = newOptRect.topRight();
158 horizontalGradTop.rx() -= newOptRect.width() - 3;
160 QLinearGradient gradient(start, horizontalGradTop);
161 gradient.setColorAt(0, option.palette.base().color());
162 gradient.setColorAt(1, Qt::transparent);
165 rectSize =
QSize(newOptRect.width() - 3, 1);
167 rectSize =
QSize(-newOptRect.width() + 3, 1);
169 painter->fillRect(
QRect(start, rectSize), gradient);
174 QColor outlineColor = option.palette.text().color();
175 outlineColor.setAlphaF(0.35);
180 painter->setPen(outlineColor);
183 const QPointF topLeft(optRect.topLeft());
184 arc = QRectF(topLeft, QSizeF(4, 4));
185 arc.translate(0.5, 0.5);
186 painter->drawArc(arc, 1440, 1440);
188 QPointF topRight(optRect.topRight());
190 arc = QRectF(topRight, QSizeF(4, 4));
191 arc.translate(-0.5, 0.5);
192 painter->drawArc(arc, 0, 1440);
201 QPoint verticalGradBottom;
203 start = optRect.topLeft();
204 verticalGradBottom = optRect.topLeft();
206 start = optRect.topRight();
207 verticalGradBottom = optRect.topRight();
210 verticalGradBottom.ry() += optRect.height() - 3;
211 QLinearGradient gradient(start, verticalGradBottom);
212 gradient.setColorAt(0, outlineColor);
213 gradient.setColorAt(1, option.palette.base().color());
214 painter->fillRect(
QRect(start,
QSize(1, optRect.height() - 3)), gradient);
223 start = optRect.topLeft();
224 horizontalGradTop = optRect.topLeft();
226 horizontalGradTop.rx() += optRect.width() - 3;
228 start = optRect.topRight();
229 horizontalGradTop = optRect.topRight();
231 horizontalGradTop.rx() -= optRect.width() - 3;
233 QLinearGradient gradient(start, horizontalGradTop);
234 gradient.setColorAt(0, outlineColor);
235 gradient.setColorAt(1, option.palette.base().color());
238 rectSize =
QSize(optRect.width() - 3, 1);
240 rectSize =
QSize(-optRect.width() + 3, 1);
242 painter->fillRect(
QRect(start, rectSize), gradient);
248 const QString category = index.model()->data(index, Qt::DisplayRole).toString();
249 QRect textRect =
QRect(option.rect.topLeft(),
QSize(option.rect.width() - 2 - 3 - 3, height));
250 textRect.setTop(textRect.top() + 2 + 3 );
251 textRect.setLeft(textRect.left() + 2 + 3 + 3 );
253 painter->setFont(font);
254 QColor penColor(option.palette.text().color());
255 penColor.setAlphaF(0.6);
256 painter->setPen(penColor);
257 painter->drawText(textRect, Qt::AlignLeft | Qt::AlignTop, category);
268 QFont font(QApplication::font());
270 const QFontMetrics fontMetrics = QFontMetrics(font);
272 return fontMetrics.height() + 2 + 12 ;
virtual int categoryHeight(const QModelIndex &index, const QStyleOption &option) const
void setLeftMargin(int leftMargin)
virtual void drawCategory(const QModelIndex &index, int sortRole, const QStyleOption &option, QPainter *painter) const
void setRightMargin(int rightMargin)