~ubuntu-branches/ubuntu/trusty/sflphone/trusty

« back to all changes in this revision

Viewing changes to kde/src/widgets/conferencebox.cpp

  • Committer: Package Import Robot
  • Author(s): Mark Purcell
  • Date: 2014-01-28 18:23:36 UTC
  • mfrom: (4.3.4 sid)
  • Revision ID: package-import@ubuntu.com-20140128182336-jrsv0k9u6cawc068
Tags: 1.3.0-1
* New upstream release 
  - Fixes "New Upstream Release" (Closes: #735846)
  - Fixes "Ringtone does not stop" (Closes: #727164)
  - Fixes "[sflphone-kde] crash on startup" (Closes: #718178)
  - Fixes "sflphone GUI crashes when call is hung up" (Closes: #736583)
* Build-Depends: ensure GnuTLS 2.6
  - libucommon-dev (>= 6.0.7-1.1), libccrtp-dev (>= 2.0.6-3)
  - Fixes "FTBFS Build-Depends libgnutls{26,28}-dev" (Closes: #722040)
* Fix "boost 1.49 is going away" unversioned Build-Depends: (Closes: #736746)
* Add Build-Depends: libsndfile-dev, nepomuk-core-dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/***************************************************************************
2
 
 *   Copyright (C) 2009 by Rafael Fernández López <ereslibre@kde.org>      *
3
 
 *                                                                         *
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.         *
7
 
 *                                                                         *
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.                        *
12
 
 *                                                                         *
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
 
 **************************************************************************/
16
 
 
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
20
 
 
21
 
#include "conferencebox.h"
22
 
 
23
 
#include <QPainter>
24
 
#include <QApplication>
25
 
#include <QStyleOption>
26
 
#include <QModelIndex>
27
 
#include <QDebug>
28
 
 
29
 
///Constructor
30
 
ConferenceBox::ConferenceBox()
31
 
{
32
 
   setLeftMargin ( 7 );
33
 
   setRightMargin( 7 );
34
 
}
35
 
 
36
 
///Draw a conference box
37
 
void ConferenceBox::drawCategory(const QModelIndex&  index   ,
38
 
                                 int                 sortRole,
39
 
                                 const QStyleOption& option  ,
40
 
                                 QPainter*           painter ,
41
 
                                 const QPalette* pal) const
42
 
{
43
 
   Q_UNUSED( sortRole )
44
 
   Q_UNUSED( index    )
45
 
   const QPalette* palette   = (pal)?pal:&option.palette  ;
46
 
   painter->setRenderHint(QPainter::Antialiasing);
47
 
 
48
 
   const QRect optRect = option.rect;
49
 
   const bool leftToRight = painter->layoutDirection() == Qt::LeftToRight;
50
 
 
51
 
   //BEGIN: decoration gradient
52
 
   {
53
 
      QPainterPath path(optRect.bottomLeft());
54
 
 
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());
62
 
 
63
 
      QColor window(palette->window().color());
64
 
      const QColor base(palette->base().color());
65
 
 
66
 
      window.setAlphaF(option.state & QStyle::State_Selected?0.9:0.9);
67
 
 
68
 
      QColor window2(window);
69
 
      window2.setAlphaF(option.state & QStyle::State_Selected?0.4:0.4);
70
 
 
71
 
      QLinearGradient decoGradient1;
72
 
      if (leftToRight) {
73
 
         decoGradient1.setStart(optRect.topLeft());
74
 
         decoGradient1.setFinalStop(optRect.bottomLeft());
75
 
      } else {
76
 
         decoGradient1.setStart(optRect.topRight());
77
 
         decoGradient1.setFinalStop(optRect.bottomRight());
78
 
      }
79
 
      decoGradient1.setColorAt(0, window);
80
 
      decoGradient1.setColorAt(1, Qt::transparent);
81
 
 
82
 
      QLinearGradient decoGradient2;
83
 
      if (leftToRight) {
84
 
         decoGradient2.setStart(optRect.topLeft());
85
 
         decoGradient2.setFinalStop(optRect.topRight());
86
 
      } else {
87
 
         decoGradient2.setStart(optRect.topRight());
88
 
         decoGradient2.setFinalStop(optRect.topLeft());
89
 
      }
90
 
      decoGradient2.setColorAt(0, window2);
91
 
      decoGradient2.setColorAt(1, Qt::transparent);
92
 
 
93
 
      painter->fillPath(path, decoGradient1);
94
 
      painter->fillRect(optRect, decoGradient2);
95
 
   }
96
 
   //END: decoration gradient
97
 
 
98
 
   {
99
 
      QRect newOptRect(optRect);
100
 
 
101
 
      if (leftToRight) {
102
 
         newOptRect.translate(1, 1);
103
 
      } else {
104
 
         newOptRect.translate(-1, 1);
105
 
      }
106
 
 
107
 
      //BEGIN: inner top left corner
108
 
      {
109
 
         painter->save();
110
 
         painter->setPen(palette->base().color());
111
 
         QRectF arc;
112
 
         if (leftToRight) {
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);
117
 
         } else {
118
 
               QPointF topRight(newOptRect.topRight());
119
 
               topRight.rx() -= 4;
120
 
               arc = QRectF(topRight, QSizeF(4, 4));
121
 
               arc.translate(-0.5, 0.5);
122
 
               painter->drawArc(arc, 0, 1440);
123
 
         }
124
 
         painter->restore();
125
 
      }
126
 
      //END: inner top left corner
127
 
 
128
 
      //BEGIN: inner left vertical line
129
 
      {
130
 
         QPoint start;
131
 
         QPoint verticalGradBottom;
132
 
         if (leftToRight) {
133
 
               start = newOptRect.topLeft();
134
 
               verticalGradBottom = newOptRect.topLeft();
135
 
         } else {
136
 
               start = newOptRect.topRight();
137
 
               verticalGradBottom = newOptRect.topRight();
138
 
         }
139
 
         start.ry() += 3;
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);
145
 
      }
146
 
      //END: inner left vertical line
147
 
 
148
 
      //BEGIN: top inner horizontal line
149
 
      {
150
 
         QPoint start;
151
 
         QPoint horizontalGradTop;
152
 
         if (leftToRight) {
153
 
               start = newOptRect.topLeft();
154
 
               horizontalGradTop = newOptRect.topLeft();
155
 
               start.rx() += 3;
156
 
               horizontalGradTop.rx() += newOptRect.width() - 3;
157
 
         } else {
158
 
               start = newOptRect.topRight();
159
 
               horizontalGradTop = newOptRect.topRight();
160
 
               start.rx() -= 3;
161
 
               horizontalGradTop.rx() -= newOptRect.width() - 3;
162
 
         }
163
 
         QLinearGradient gradient(start, horizontalGradTop);
164
 
         gradient.setColorAt(0, palette->base().color());
165
 
         gradient.setColorAt(1, Qt::transparent);
166
 
         QSize rectSize;
167
 
         if (leftToRight) {
168
 
               rectSize = QSize(newOptRect.width() - 30, 1);
169
 
         } else {
170
 
               rectSize = QSize(-newOptRect.width() + 30, 1);
171
 
         }
172
 
         painter->fillRect(QRect(start, rectSize), gradient);
173
 
      }
174
 
      //END: top inner horizontal line
175
 
   }
176
 
 
177
 
   QColor outlineColor = palette->text().color();
178
 
   outlineColor.setAlphaF(0.35);
179
 
 
180
 
   //BEGIN: top left corner
181
 
   {
182
 
      painter->save();
183
 
      painter->setPen(outlineColor);
184
 
      QRectF arc;
185
 
      if (leftToRight) {
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);
190
 
      } else {
191
 
         QPointF topRight(optRect.topRight());
192
 
         topRight.rx() -= 4;
193
 
         arc = QRectF(topRight, QSizeF(4, 4));
194
 
         arc.translate(-0.5, 0.5);
195
 
         painter->drawArc(arc, 0, 1440);
196
 
      }
197
 
      painter->restore();
198
 
   }
199
 
   //END: top left corner
200
 
 
201
 
   //BEGIN: top right corner
202
 
   {
203
 
      painter->save();
204
 
      painter->setPen(outlineColor);
205
 
      QRectF arc;
206
 
      if (!leftToRight) {
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);
211
 
      } else {
212
 
         QPointF topRight(optRect.topRight());
213
 
         topRight.rx() -= 3;
214
 
//          topRight.ry() += 1;
215
 
         arc = QRectF(topRight, QSizeF(4, 4));
216
 
         arc.translate(-0.5, 0.5);
217
 
         painter->drawArc(arc, 0, 1440);
218
 
      }
219
 
      painter->restore();
220
 
   }
221
 
   //END: top right corner
222
 
 
223
 
   //BEGIN: left vertical line
224
 
   {
225
 
      QPoint start;
226
 
      QPoint verticalGradBottom;
227
 
      if (leftToRight) {
228
 
         start = optRect.topLeft();
229
 
         verticalGradBottom = optRect.topLeft();
230
 
      } else {
231
 
         start = optRect.topRight();
232
 
         verticalGradBottom = optRect.topRight();
233
 
      }
234
 
      start.ry() += 3;
235
 
      verticalGradBottom.ry() += optRect.height() - 3 + 200;
236
 
      painter->fillRect(QRect(start, QSize(1, optRect.height() - 21)), outlineColor);
237
 
   }
238
 
   //END: left vertical line
239
 
 
240
 
   //BEGIN: right vertical line
241
 
   {
242
 
      QPoint start;
243
 
      QPoint verticalGradBottom;
244
 
      if (!leftToRight) {
245
 
         start = optRect.topLeft();
246
 
         verticalGradBottom = optRect.topLeft();
247
 
      } else {
248
 
         start = optRect.topRight();
249
 
         verticalGradBottom = optRect.topRight();
250
 
      }
251
 
      start.ry() += 3;
252
 
      verticalGradBottom.ry() += optRect.height() - 3 + 200;
253
 
      painter->fillRect(QRect(start, QSize(1, optRect.height() - 21)), outlineColor);
254
 
   }
255
 
   //END: right vertical line
256
 
 
257
 
   //BEGIN: horizontal line
258
 
   {
259
 
      QPoint start;
260
 
      QPoint horizontalGradTop;
261
 
      if (leftToRight) {
262
 
         start = optRect.topLeft();
263
 
         horizontalGradTop = optRect.topLeft();
264
 
         start.rx() += 3;
265
 
         horizontalGradTop.rx() += optRect.width() - 3;
266
 
      } else {
267
 
         start = optRect.topRight();
268
 
         horizontalGradTop = optRect.topRight();
269
 
         start.rx() -= 3;
270
 
         horizontalGradTop.rx() -= optRect.width() - 3;
271
 
      }
272
 
      QLinearGradient gradient(start, horizontalGradTop);
273
 
      gradient.setColorAt(0, outlineColor);
274
 
      gradient.setColorAt(1, outlineColor);
275
 
      QSize rectSize;
276
 
      if (leftToRight) {
277
 
         rectSize = QSize(optRect.width() - 6, 1);
278
 
      } else {
279
 
         rectSize = QSize(-optRect.width() + 6, 1);
280
 
      }
281
 
      painter->fillRect(QRect(start, rectSize), gradient);
282
 
   }
283
 
   //END: horizontal line
284
 
} //drawCategory
285
 
 
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 {
288
 
   Q_UNUSED(index)
289
 
   Q_UNUSED(sortRole)
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);
295
 
 
296
 
   //BEGIN: bottom horizontal line
297
 
   {
298
 
   QPoint bl = option.rect.bottomLeft();
299
 
   bl.setY(bl.y());
300
 
   bl.setX(0);
301
 
 
302
 
   painter->fillRect(QRect(bl, QSize(option.rect.width()+4,1)), outlineColor);
303
 
   }
304
 
   //END: bottom horizontal line
305
 
 
306
 
   //BEGIN: bottom right corner
307
 
   {
308
 
      QRectF arc;
309
 
      QPointF br(option.rect.bottomRight());
310
 
      br.setY(br.y()-4);
311
 
      br.setX(br.x()-12);
312
 
      arc = QRectF(br, QSizeF(4, 4));
313
 
      arc.translate(0.5, 0.5);
314
 
      painter->drawArc(arc, 4320, 1440);
315
 
   }
316
 
   //END: bottom right corner
317
 
} //drawBoxBottom
318
 
 
319
 
///Return the height of the conference box
320
 
int ConferenceBox::categoryHeight(const QModelIndex &index, const QStyleOption &option,const QPalette* pal) const
321
 
{
322
 
   Q_UNUSED( index  );
323
 
   Q_UNUSED( option );
324
 
   Q_UNUSED( pal    );
325
 
   QFont font(QApplication::font());
326
 
   font.setBold(true);
327
 
   const QFontMetrics fontMetrics = QFontMetrics(font);
328
 
 
329
 
   return fontMetrics.height() + 2 + 12 /* vertical spacing */;
330
 
}
331