• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdelibs API Reference
  • KDE Home
  • Contact Us
 

KDEUI

  • sources
  • kde-4.12
  • kdelibs
  • kdeui
  • itemviews
kcategorydrawer.cpp
Go to the documentation of this file.
1 
21 #include "kcategorydrawer.h"
22 
23 #include <QPainter>
24 #include <QStyleOption>
25 #include <QApplication>
26 
27 #include <kiconloader.h>
28 #include <kcategorizedview.h>
29 #include <kcategorizedsortfilterproxymodel.h>
30 
31 #define HORIZONTAL_HINT 3
32 
33 class KCategoryDrawer::Private
34 {
35 public:
36  Private()
37  : leftMargin(0)
38  , rightMargin(0)
39  {
40  }
41 
42  ~Private()
43  {
44  }
45 
46  int leftMargin;
47  int rightMargin;
48 };
49 
50 KCategoryDrawer::KCategoryDrawer()
51  : d(new Private)
52 {
53  setLeftMargin(2);
54  setRightMargin(2);
55 }
56 
57 KCategoryDrawer::~KCategoryDrawer()
58 {
59  delete d;
60 }
61 
62 void KCategoryDrawer::drawCategory(const QModelIndex &index,
63  int /*sortRole*/,
64  const QStyleOption &option,
65  QPainter *painter) const
66 {
67  painter->setRenderHint(QPainter::Antialiasing);
68 
69  const QString category = index.model()->data(index, KCategorizedSortFilterProxyModel::CategoryDisplayRole).toString();
70  const QRect optRect = option.rect;
71  QFont font(QApplication::font());
72  font.setBold(true);
73  const QFontMetrics fontMetrics = QFontMetrics(font);
74 
75  QColor outlineColor = option.palette.text().color();
76  outlineColor.setAlphaF(0.35);
77 
78  //BEGIN: top left corner
79  {
80  painter->save();
81  painter->setPen(outlineColor);
82  const QPointF topLeft(optRect.topLeft());
83  QRectF arc(topLeft, QSizeF(4, 4));
84  arc.translate(0.5, 0.5);
85  painter->drawArc(arc, 1440, 1440);
86  painter->restore();
87  }
88  //END: top left corner
89 
90  //BEGIN: left vertical line
91  {
92  QPoint start(optRect.topLeft());
93  start.ry() += 3;
94  QPoint verticalGradBottom(optRect.topLeft());
95  verticalGradBottom.ry() += fontMetrics.height() + 5;
96  QLinearGradient gradient(start, verticalGradBottom);
97  gradient.setColorAt(0, outlineColor);
98  gradient.setColorAt(1, Qt::transparent);
99  painter->fillRect(QRect(start, QSize(1, fontMetrics.height() + 5)), gradient);
100  }
101  //END: left vertical line
102 
103  //BEGIN: horizontal line
104  {
105  QPoint start(optRect.topLeft());
106  start.rx() += 3;
107  QPoint horizontalGradTop(optRect.topLeft());
108  horizontalGradTop.rx() += optRect.width() - 6;
109  painter->fillRect(QRect(start, QSize(optRect.width() - 6, 1)), outlineColor);
110  }
111  //END: horizontal line
112 
113  //BEGIN: top right corner
114  {
115  painter->save();
116  painter->setPen(outlineColor);
117  QPointF topRight(optRect.topRight());
118  topRight.rx() -= 4;
119  QRectF arc(topRight, QSizeF(4, 4));
120  arc.translate(0.5, 0.5);
121  painter->drawArc(arc, 0, 1440);
122  painter->restore();
123  }
124  //END: top right corner
125 
126  //BEGIN: right vertical line
127  {
128  QPoint start(optRect.topRight());
129  start.ry() += 3;
130  QPoint verticalGradBottom(optRect.topRight());
131  verticalGradBottom.ry() += fontMetrics.height() + 5;
132  QLinearGradient gradient(start, verticalGradBottom);
133  gradient.setColorAt(0, outlineColor);
134  gradient.setColorAt(1, Qt::transparent);
135  painter->fillRect(QRect(start, QSize(1, fontMetrics.height() + 5)), gradient);
136  }
137  //END: right vertical line
138 
139  //BEGIN: text
140  {
141  QRect textRect(option.rect);
142  textRect.setTop(textRect.top() + 7);
143  textRect.setLeft(textRect.left() + 7);
144  textRect.setHeight(fontMetrics.height());
145  textRect.setRight(textRect.right() - 7);
146 
147  painter->save();
148  painter->setFont(font);
149  QColor penColor(option.palette.text().color());
150  penColor.setAlphaF(0.6);
151  painter->setPen(penColor);
152  painter->drawText(textRect, Qt::AlignLeft | Qt::AlignVCenter, category);
153  painter->restore();
154  }
155  //END: text
156 }
157 
158 int KCategoryDrawer::categoryHeight(const QModelIndex &index, const QStyleOption &option) const
159 {
160  Q_UNUSED(index);
161  Q_UNUSED(option)
162 
163  QFont font(QApplication::font());
164  font.setBold(true);
165  QFontMetrics fontMetrics(font);
166 
167  const int height = fontMetrics.height() + 1 /* 1 pixel-width gradient */
168  + 11 /* top and bottom separation */;
169  return height;
170 }
171 
172 int KCategoryDrawer::leftMargin() const
173 {
174  return d->leftMargin;
175 }
176 
177 void KCategoryDrawer::setLeftMargin(int leftMargin)
178 {
179  d->leftMargin = leftMargin;
180 }
181 
182 int KCategoryDrawer::rightMargin() const
183 {
184  return d->rightMargin;
185 }
186 
187 void KCategoryDrawer::setRightMargin(int rightMargin)
188 {
189  d->rightMargin = rightMargin;
190 }
191 
192 KCategoryDrawer &KCategoryDrawer::operator=(const KCategoryDrawer &cd)
193 {
194  d->leftMargin = cd.d->leftMargin;
195  d->rightMargin = cd.d->rightMargin;
196  return *this;
197 }
198 
199 KCategoryDrawerV2::KCategoryDrawerV2(QObject *parent)
200  : QObject(parent)
201  , KCategoryDrawer()
202 {
203 }
204 
205 KCategoryDrawerV2::~KCategoryDrawerV2()
206 {
207 }
208 
209 void KCategoryDrawerV2::mouseButtonPressed(const QModelIndex&, QMouseEvent *event)
210 {
211  event->ignore();
212 }
213 
214 void KCategoryDrawerV2::mouseButtonReleased(const QModelIndex&, QMouseEvent *event)
215 {
216  event->ignore();
217 }
218 
219 void KCategoryDrawerV2::mouseButtonMoved(const QModelIndex&, QMouseEvent *event)
220 {
221  event->ignore();
222 }
223 
224 void KCategoryDrawerV2::mouseButtonDoubleClicked(const QModelIndex&, QMouseEvent *event)
225 {
226  event->ignore();
227 }
228 
229 class KCategoryDrawerV3::Private
230 {
231 public:
232  Private(KCategorizedView *view)
233  : view(view)
234  {
235  }
236 
237  ~Private()
238  {
239  }
240 
241  KCategorizedView *view;
242 };
243 
244 KCategoryDrawerV3::KCategoryDrawerV3(KCategorizedView *view)
245  : KCategoryDrawerV2(view)
246  , d(new Private(view))
247 {
248 }
249 
250 KCategoryDrawerV3::~KCategoryDrawerV3()
251 {
252  delete d;
253 }
254 
255 KCategorizedView *KCategoryDrawerV3::view() const
256 {
257  return d->view;
258 }
259 
260 void KCategoryDrawerV3::mouseButtonPressed(const QModelIndex&, const QRect&, QMouseEvent *event)
261 {
262  event->ignore();
263 }
264 
265 void KCategoryDrawerV3::mouseButtonReleased(const QModelIndex&, const QRect&, QMouseEvent *event)
266 {
267  event->ignore();
268 }
269 
270 void KCategoryDrawerV3::mouseMoved(const QModelIndex&, const QRect&, QMouseEvent *event)
271 {
272  event->ignore();
273 }
274 
275 void KCategoryDrawerV3::mouseButtonDoubleClicked(const QModelIndex&, const QRect&, QMouseEvent *event)
276 {
277  event->ignore();
278 }
279 
280 void KCategoryDrawerV3::mouseLeft(const QModelIndex&, const QRect&)
281 {
282 }
283 
284 #include "kcategorydrawer.moc"
kcategorizedview.h
QColor
kcategorizedsortfilterproxymodel.h
KCategoryDrawerV3::view
KCategorizedView * view() const
Definition: kcategorydrawer.cpp:255
KCategoryDrawerV3::KCategoryDrawerV3
KCategoryDrawerV3(KCategorizedView *view)
Definition: kcategorydrawer.cpp:244
KCategoryDrawer::leftMargin
int leftMargin() const
Definition: kcategorydrawer.cpp:172
KCategoryDrawerV2::KCategoryDrawerV2
KCategoryDrawerV2(QObject *parent=0)
Definition: kcategorydrawer.cpp:199
kiconloader.h
KCategoryDrawerV3::mouseButtonReleased
virtual void mouseButtonReleased(const QModelIndex &index, const QRect &blockRect, QMouseEvent *event)
Method called when the mouse button has been released.
Definition: kcategorydrawer.cpp:265
QString
KCategoryDrawer::~KCategoryDrawer
virtual ~KCategoryDrawer()
Definition: kcategorydrawer.cpp:57
KCategoryDrawer::drawCategory
virtual void drawCategory(const QModelIndex &index, int sortRole, const QStyleOption &option, QPainter *painter) const
This method purpose is to draw a category represented by the given.
Definition: kcategorydrawer.cpp:62
KCategoryDrawerV3::mouseMoved
virtual void mouseMoved(const QModelIndex &index, const QRect &blockRect, QMouseEvent *event)
Method called when the mouse has been moved.
Definition: kcategorydrawer.cpp:270
QObject
KCategoryDrawerV3::mouseLeft
virtual void mouseLeft(const QModelIndex &index, const QRect &blockRect)
Method called when the mouse button has left this block.
Definition: kcategorydrawer.cpp:280
KCategoryDrawer
Definition: kcategorydrawer.h:43
KCategorizedView
Item view for listing items in a categorized fashion optionally.
Definition: kcategorizedview.h:79
KCategoryDrawerV2::mouseButtonDoubleClicked
virtual void mouseButtonDoubleClicked(const QModelIndex &index, QMouseEvent *event)
Definition: kcategorydrawer.cpp:224
KCategoryDrawer::operator=
KCategoryDrawer & operator=(const KCategoryDrawer &cd)
Definition: kcategorydrawer.cpp:192
KCategoryDrawerV2::~KCategoryDrawerV2
virtual ~KCategoryDrawerV2()
Definition: kcategorydrawer.cpp:205
KCategoryDrawer::rightMargin
int rightMargin() const
Definition: kcategorydrawer.cpp:182
KCategoryDrawerV2::mouseButtonMoved
virtual void mouseButtonMoved(const QModelIndex &index, QMouseEvent *event)
Definition: kcategorydrawer.cpp:219
KCategoryDrawer::KCategoryDrawer
KCategoryDrawer()
Definition: kcategorydrawer.cpp:50
KCategoryDrawerV3::mouseButtonDoubleClicked
virtual void mouseButtonDoubleClicked(const QModelIndex &index, const QRect &blockRect, QMouseEvent *event)
Method called when the mouse button has been double clicked.
Definition: kcategorydrawer.cpp:275
KCategoryDrawer::setLeftMargin
void setLeftMargin(int leftMargin)
Definition: kcategorydrawer.cpp:177
kcategorydrawer.h
QFont
KCategoryDrawerV2
Definition: kcategorydrawer.h:113
QPoint
KCategoryDrawerV3::~KCategoryDrawerV3
virtual ~KCategoryDrawerV3()
Definition: kcategorydrawer.cpp:250
QRect
KCategoryDrawer::categoryHeight
virtual int categoryHeight(const QModelIndex &index, const QStyleOption &option) const
Definition: kcategorydrawer.cpp:158
KCategoryDrawerV2::mouseButtonPressed
virtual void mouseButtonPressed(const QModelIndex &index, QMouseEvent *event)
Definition: kcategorydrawer.cpp:209
QSize
KCategoryDrawer::setRightMargin
void setRightMargin(int rightMargin)
Definition: kcategorydrawer.cpp:187
KCategorizedSortFilterProxyModel::CategoryDisplayRole
This role is used for asking the category to a given index.
Definition: kcategorizedsortfilterproxymodel.h:52
KCategoryDrawerV3::mouseButtonPressed
virtual void mouseButtonPressed(const QModelIndex &index, const QRect &blockRect, QMouseEvent *event)
Method called when the mouse button has been pressed.
Definition: kcategorydrawer.cpp:260
KCategoryDrawerV2::mouseButtonReleased
virtual void mouseButtonReleased(const QModelIndex &index, QMouseEvent *event)
Definition: kcategorydrawer.cpp:214
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:49:14 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KDEUI

Skip menu "KDEUI"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Modules
  • Related Pages

kdelibs API Reference

Skip menu "kdelibs API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  • kjsembed
  •   WTF
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Nepomuk-Core
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal