1
/***************************************************************************
2
* Copyright (C) 2009 by Rafael Fernández López <ereslibre@kde.org> *
4
* This library is free software; you can redistribute it and/or *
5
* modify it under the terms of the GNU Library General Public *
6
* License version 2 as published by the Free Software Foundation. *
8
* This library is distributed in the hope that it will be useful, *
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
11
* Library General Public License for more details. *
13
* You should have received a copy of the GNU General Public License *
14
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
15
**************************************************************************/
17
// this code is taken from SystemSettings/icons/CategoryDrawer.{h,cpp}
18
// Rafael agreet to relicense it under LGPLv2 or LGPLv3, just as we need it,
19
// see: http://lists.kde.org/?l=kwrite-devel&m=133061943317199&w=2
21
#include "conferencebox.h"
24
#include <QApplication>
25
#include <QStyleOption>
26
#include <QModelIndex>
30
ConferenceBox::ConferenceBox()
36
///Draw a conference box
37
void ConferenceBox::drawCategory(const QModelIndex& index ,
39
const QStyleOption& option ,
41
const QPalette* pal) const
45
const QPalette* palette = (pal)?pal:&option.palette ;
46
painter->setRenderHint(QPainter::Antialiasing);
48
const QRect optRect = option.rect;
49
const bool leftToRight = painter->layoutDirection() == Qt::LeftToRight;
51
//BEGIN: decoration gradient
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(palette->window().color());
64
const QColor base(palette->base().color());
66
window.setAlphaF(option.state & QStyle::State_Selected?0.9:0.9);
68
QColor window2(window);
69
window2.setAlphaF(option.state & QStyle::State_Selected?0.4:0.4);
71
QLinearGradient decoGradient1;
73
decoGradient1.setStart(optRect.topLeft());
74
decoGradient1.setFinalStop(optRect.bottomLeft());
76
decoGradient1.setStart(optRect.topRight());
77
decoGradient1.setFinalStop(optRect.bottomRight());
79
decoGradient1.setColorAt(0, window);
80
decoGradient1.setColorAt(1, Qt::transparent);
82
QLinearGradient decoGradient2;
84
decoGradient2.setStart(optRect.topLeft());
85
decoGradient2.setFinalStop(optRect.topRight());
87
decoGradient2.setStart(optRect.topRight());
88
decoGradient2.setFinalStop(optRect.topLeft());
90
decoGradient2.setColorAt(0, window2);
91
decoGradient2.setColorAt(1, Qt::transparent);
93
painter->fillPath(path, decoGradient1);
94
painter->fillRect(optRect, decoGradient2);
96
//END: decoration gradient
99
QRect newOptRect(optRect);
102
newOptRect.translate(1, 1);
104
newOptRect.translate(-1, 1);
107
//BEGIN: inner top left corner
110
painter->setPen(palette->base().color());
113
const QPointF topLeft(newOptRect.topLeft());
114
arc = QRectF(topLeft, QSizeF(4, 4));
115
arc.translate(0.5, 0.5);
116
painter->drawArc(arc, 1440, 1440);
118
QPointF topRight(newOptRect.topRight());
120
arc = QRectF(topRight, QSizeF(4, 4));
121
arc.translate(-0.5, 0.5);
122
painter->drawArc(arc, 0, 1440);
126
//END: inner top left corner
128
//BEGIN: inner left vertical line
131
QPoint verticalGradBottom;
133
start = newOptRect.topLeft();
134
verticalGradBottom = newOptRect.topLeft();
136
start = newOptRect.topRight();
137
verticalGradBottom = newOptRect.topRight();
140
verticalGradBottom.ry() += newOptRect.height() - 3;
141
QLinearGradient gradient(start, verticalGradBottom);
142
gradient.setColorAt(0, palette->base().color());
143
gradient.setColorAt(1, Qt::transparent);
144
painter->fillRect(QRect(start, QSize(1, newOptRect.height() - 3)), gradient);
146
//END: inner left vertical line
148
//BEGIN: top inner horizontal line
151
QPoint horizontalGradTop;
153
start = newOptRect.topLeft();
154
horizontalGradTop = newOptRect.topLeft();
156
horizontalGradTop.rx() += newOptRect.width() - 3;
158
start = newOptRect.topRight();
159
horizontalGradTop = newOptRect.topRight();
161
horizontalGradTop.rx() -= newOptRect.width() - 3;
163
QLinearGradient gradient(start, horizontalGradTop);
164
gradient.setColorAt(0, palette->base().color());
165
gradient.setColorAt(1, Qt::transparent);
168
rectSize = QSize(newOptRect.width() - 30, 1);
170
rectSize = QSize(-newOptRect.width() + 30, 1);
172
painter->fillRect(QRect(start, rectSize), gradient);
174
//END: top inner horizontal line
177
QColor outlineColor = palette->text().color();
178
outlineColor.setAlphaF(0.35);
180
//BEGIN: top left corner
183
painter->setPen(outlineColor);
186
const QPointF topLeft(optRect.topLeft());
187
arc = QRectF(topLeft, QSizeF(4, 4));
188
arc.translate(0.5, 0.5);
189
painter->drawArc(arc, 1440, 1440);
191
QPointF topRight(optRect.topRight());
193
arc = QRectF(topRight, QSizeF(4, 4));
194
arc.translate(-0.5, 0.5);
195
painter->drawArc(arc, 0, 1440);
199
//END: top left corner
201
//BEGIN: top right corner
204
painter->setPen(outlineColor);
207
const QPointF topLeft(optRect.topLeft());
208
arc = QRectF(topLeft, QSizeF(4, 4));
209
arc.translate(0.5, 0.5);
210
painter->drawArc(arc, 1440, 1440);
212
QPointF topRight(optRect.topRight());
214
// topRight.ry() += 1;
215
arc = QRectF(topRight, QSizeF(4, 4));
216
arc.translate(-0.5, 0.5);
217
painter->drawArc(arc, 0, 1440);
221
//END: top right corner
223
//BEGIN: left vertical line
226
QPoint verticalGradBottom;
228
start = optRect.topLeft();
229
verticalGradBottom = optRect.topLeft();
231
start = optRect.topRight();
232
verticalGradBottom = optRect.topRight();
235
verticalGradBottom.ry() += optRect.height() - 3 + 200;
236
painter->fillRect(QRect(start, QSize(1, optRect.height() - 21)), outlineColor);
238
//END: left vertical line
240
//BEGIN: right vertical line
243
QPoint verticalGradBottom;
245
start = optRect.topLeft();
246
verticalGradBottom = optRect.topLeft();
248
start = optRect.topRight();
249
verticalGradBottom = optRect.topRight();
252
verticalGradBottom.ry() += optRect.height() - 3 + 200;
253
painter->fillRect(QRect(start, QSize(1, optRect.height() - 21)), outlineColor);
255
//END: right vertical line
257
//BEGIN: horizontal line
260
QPoint horizontalGradTop;
262
start = optRect.topLeft();
263
horizontalGradTop = optRect.topLeft();
265
horizontalGradTop.rx() += optRect.width() - 3;
267
start = optRect.topRight();
268
horizontalGradTop = optRect.topRight();
270
horizontalGradTop.rx() -= optRect.width() - 3;
272
QLinearGradient gradient(start, horizontalGradTop);
273
gradient.setColorAt(0, outlineColor);
274
gradient.setColorAt(1, outlineColor);
277
rectSize = QSize(optRect.width() - 6, 1);
279
rectSize = QSize(-optRect.width() + 6, 1);
281
painter->fillRect(QRect(start, rectSize), gradient);
283
//END: horizontal line
286
///Draw the bottom border of the box
287
void ConferenceBox::drawBoxBottom(const QModelIndex &index, int sortRole, const QStyleOption &option, QPainter *painter,const QPalette* pal) const {
290
const QPalette* palette = (pal)?pal:&option.palette ;
291
painter->setRenderHint(QPainter::Antialiasing);
292
QColor outlineColor = palette->text().color();
293
outlineColor.setAlphaF(0.35);
294
painter->setPen(outlineColor);
296
//BEGIN: bottom horizontal line
298
QPoint bl = option.rect.bottomLeft();
302
painter->fillRect(QRect(bl, QSize(option.rect.width()+4,1)), outlineColor);
304
//END: bottom horizontal line
306
//BEGIN: bottom right corner
309
QPointF br(option.rect.bottomRight());
312
arc = QRectF(br, QSizeF(4, 4));
313
arc.translate(0.5, 0.5);
314
painter->drawArc(arc, 4320, 1440);
316
//END: bottom right corner
319
///Return the height of the conference box
320
int ConferenceBox::categoryHeight(const QModelIndex &index, const QStyleOption &option,const QPalette* pal) const
325
QFont font(QApplication::font());
327
const QFontMetrics fontMetrics = QFontMetrics(font);
329
return fontMetrics.height() + 2 + 12 /* vertical spacing */;