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

KIO

  • sources
  • kde-4.14
  • kdelibs
  • kio
  • kio
kfileitemdelegate.cpp
Go to the documentation of this file.
1 /*
2  This file is part of the KDE project
3  Copyright (C) 2009 Shaun Reich <shaun.reich@kdemail.net>
4  Copyright © 2006-2007, 2008 Fredrik Höglund <fredrik@kde.org>
5 
6 
7  This library is free software; you can redistribute it and/or
8  modify it under the terms of the GNU Library General Public
9  License as published by the Free Software Foundation; either
10  version 2 of the License, or (at your option) any later version.
11 
12  This library is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  Library General Public License for more details.
16 
17  You should have received a copy of the GNU Library General Public License
18  along with this library; see the file COPYING.LIB. If not, write to
19  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20  Boston, MA 02110-1301, USA.
21 */
22 
23 #include "kfileitemdelegate.h"
24 #include "imagefilter_p.h"
25 
26 #include <config.h> // for HAVE_XRENDER
27 
28 #include <QApplication>
29 #include <QStyle>
30 #include <QModelIndex>
31 #include <QPainter>
32 #include <QCache>
33 #include <QImage>
34 #include <QPainterPath>
35 #include <QTextLayout>
36 #include <QListView>
37 #include <QPaintEngine>
38 #include <qmath.h>
39 
40 #include <kglobal.h>
41 #include <klocale.h>
42 #include <kicon.h>
43 #include <kiconloader.h>
44 #include <kiconeffect.h>
45 #include <kdirmodel.h>
46 #include <kfileitem.h>
47 #include <kcolorscheme.h>
48 #include <kglobalsettings.h>
49 #include <ktextedit.h>
50 #include <kstringhandler.h>
51 
52 #include "delegateanimationhandler_p.h"
53 
54 #if defined(Q_WS_X11) && defined(HAVE_XRENDER)
55 # include <X11/Xlib.h>
56 # include <X11/extensions/Xrender.h>
57 # include <QX11Info>
58 # undef KeyPress
59 # undef FocusOut
60 #endif
61 
62 
63 struct Margin
64 {
65  int left, right, top, bottom;
66 };
67 
68 
69 class KFileItemDelegate::Private
70 {
71  public:
72  enum MarginType { ItemMargin = 0, TextMargin, IconMargin, NMargins };
73 
74  Private(KFileItemDelegate *parent);
75  ~Private() {}
76 
77  QSize decorationSizeHint(const QStyleOptionViewItemV4 &option, const QModelIndex &index) const;
78  QSize displaySizeHint(const QStyleOptionViewItemV4 &option, const QModelIndex &index) const;
79  QString replaceNewlines(const QString &string) const;
80  inline KFileItem fileItem(const QModelIndex &index) const;
81  QString elidedText(QTextLayout &layout, const QStyleOptionViewItemV4 &option, const QSize &maxSize) const;
82  QSize layoutText(QTextLayout &layout, const QStyleOptionViewItemV4 &option,
83  const QString &text, const QSize &constraints) const;
84  QSize layoutText(QTextLayout &layout, const QString &text, int maxWidth) const;
85  inline void setLayoutOptions(QTextLayout &layout, const QStyleOptionViewItemV4 &options) const;
86  inline bool verticalLayout(const QStyleOptionViewItemV4 &option) const;
87  inline QBrush brush(const QVariant &value, const QStyleOptionViewItemV4 &option) const;
88  QBrush foregroundBrush(const QStyleOptionViewItemV4 &option, const QModelIndex &index) const;
89  inline void setActiveMargins(Qt::Orientation layout);
90  void setVerticalMargin(MarginType type, int left, int right, int top, int bottom);
91  void setHorizontalMargin(MarginType type, int left, int right, int top, int bottom);
92  inline void setVerticalMargin(MarginType type, int hor, int ver);
93  inline void setHorizontalMargin(MarginType type, int hor, int ver);
94  inline QRect addMargin(const QRect &rect, MarginType type) const;
95  inline QRect subtractMargin(const QRect &rect, MarginType type) const;
96  inline QSize addMargin(const QSize &size, MarginType type) const;
97  inline QSize subtractMargin(const QSize &size, MarginType type) const;
98  QString itemSize(const QModelIndex &index, const KFileItem &item) const;
99  QString information(const QStyleOptionViewItemV4 &option, const QModelIndex &index, const KFileItem &item) const;
100  bool isListView(const QStyleOptionViewItemV4 &option) const;
101  QString display(const QModelIndex &index) const;
102  QIcon decoration(const QStyleOptionViewItemV4 &option, const QModelIndex &index) const;
103  QPoint iconPosition(const QStyleOptionViewItemV4 &option) const;
104  QRect labelRectangle(const QStyleOptionViewItemV4 &option) const;
105  void layoutTextItems(const QStyleOptionViewItemV4 &option, const QModelIndex &index,
106  QTextLayout *labelLayout, QTextLayout *infoLayout, QRect *textBoundingRect) const;
107  void drawTextItems(QPainter *painter, const QTextLayout &labelLayout, const QTextLayout &infoLayout,
108  const QRect &textBoundingRect) const;
109  KIO::AnimationState *animationState(const QStyleOptionViewItemV4 &option, const QModelIndex &index,
110  const QAbstractItemView *view) const;
111  void restartAnimation(KIO::AnimationState* state);
112  QPixmap applyHoverEffect(const QPixmap &icon) const;
113  QPixmap transition(const QPixmap &from, const QPixmap &to, qreal amount) const;
114  void initStyleOption(QStyleOptionViewItemV4 *option, const QModelIndex &index) const;
115  void drawFocusRect(QPainter *painter, const QStyleOptionViewItemV4 &option, const QRect &rect) const;
116 
117  void gotNewIcon(const QModelIndex& index);
118 
119  void paintJobTransfers(QPainter* painter, const qreal& jobAnimationAngle, const QPoint& iconPos, const QStyleOptionViewItemV4& opt);
120 
121  public:
122  KFileItemDelegate::InformationList informationList;
123  QColor shadowColor;
124  QPointF shadowOffset;
125  qreal shadowBlur;
126  QSize maximumSize;
127  bool showToolTipWhenElided;
128  QTextOption::WrapMode wrapMode;
129  bool jobTransfersVisible;
130  KIcon downArrowIcon;
131 
132  private:
133  KFileItemDelegate * const q;
134  KIO::DelegateAnimationHandler *animationHandler;
135  Margin verticalMargin[NMargins];
136  Margin horizontalMargin[NMargins];
137  Margin *activeMargins;
138 };
139 
140 
141 KFileItemDelegate::Private::Private(KFileItemDelegate *parent)
142  : shadowColor(Qt::transparent), shadowOffset(1, 1), shadowBlur(2), maximumSize(0, 0),
143  showToolTipWhenElided(true), wrapMode( QTextOption::WrapAtWordBoundaryOrAnywhere ), jobTransfersVisible(false),
144  q(parent), animationHandler(new KIO::DelegateAnimationHandler(parent)), activeMargins(0)
145 {
146 }
147 
148 
149 void KFileItemDelegate::Private::setActiveMargins(Qt::Orientation layout)
150 {
151  activeMargins = (layout == Qt::Horizontal ?
152  horizontalMargin : verticalMargin);
153 }
154 
155 
156 void KFileItemDelegate::Private::setVerticalMargin(MarginType type, int left, int top, int right, int bottom)
157 {
158  verticalMargin[type].left = left;
159  verticalMargin[type].right = right;
160  verticalMargin[type].top = top;
161  verticalMargin[type].bottom = bottom;
162 }
163 
164 
165 void KFileItemDelegate::Private::setHorizontalMargin(MarginType type, int left, int top, int right, int bottom)
166 {
167  horizontalMargin[type].left = left;
168  horizontalMargin[type].right = right;
169  horizontalMargin[type].top = top;
170  horizontalMargin[type].bottom = bottom;
171 }
172 
173 
174 void KFileItemDelegate::Private::setVerticalMargin(MarginType type, int horizontal, int vertical)
175 {
176  setVerticalMargin(type, horizontal, vertical, horizontal, vertical);
177 }
178 
179 
180 void KFileItemDelegate::Private::setHorizontalMargin(MarginType type, int horizontal, int vertical)
181 {
182  setHorizontalMargin(type, horizontal, vertical, horizontal, vertical);
183 }
184 
185 
186 QRect KFileItemDelegate::Private::addMargin(const QRect &rect, MarginType type) const
187 {
188  Q_ASSERT(activeMargins != 0);
189  const Margin &m = activeMargins[type];
190  return rect.adjusted(-m.left, -m.top, m.right, m.bottom);
191 }
192 
193 
194 QRect KFileItemDelegate::Private::subtractMargin(const QRect &rect, MarginType type) const
195 {
196  Q_ASSERT(activeMargins != 0);
197  const Margin &m = activeMargins[type];
198  return rect.adjusted(m.left, m.top, -m.right, -m.bottom);
199 }
200 
201 
202 QSize KFileItemDelegate::Private::addMargin(const QSize &size, MarginType type) const
203 {
204  Q_ASSERT(activeMargins != 0);
205  const Margin &m = activeMargins[type];
206  return QSize(size.width() + m.left + m.right, size.height() + m.top + m.bottom);
207 }
208 
209 
210 QSize KFileItemDelegate::Private::subtractMargin(const QSize &size, MarginType type) const
211 {
212  Q_ASSERT(activeMargins != 0);
213  const Margin &m = activeMargins[type];
214  return QSize(size.width() - m.left - m.right, size.height() - m.top - m.bottom);
215 }
216 
217 
218 // Returns the size of a file, or the number of items in a directory, as a QString
219 QString KFileItemDelegate::Private::itemSize(const QModelIndex &index, const KFileItem &item) const
220 {
221  // Return a formatted string containing the file size, if the item is a file
222  if (item.isFile())
223  return KGlobal::locale()->formatByteSize(item.size());
224 
225  // Return the number of items in the directory
226  const QVariant value = index.data(KDirModel::ChildCountRole);
227  const int count = value.type() == QVariant::Int ? value.toInt() : KDirModel::ChildCountUnknown;
228 
229  if (count == KDirModel::ChildCountUnknown) {
230  // was: i18nc("Items in a folder", "? items");
231  // but this just looks useless in a remote directory listing,
232  // better not show anything.
233  return QString();
234  }
235 
236  return i18ncp("Items in a folder", "1 item", "%1 items", count);
237 }
238 
239 
240 // Returns the additional information string, if one should be shown, or an empty string otherwise
241 QString KFileItemDelegate::Private::information(const QStyleOptionViewItemV4 &option, const QModelIndex &index,
242  const KFileItem &item) const
243 {
244  QString string;
245 
246  if (informationList.isEmpty() || item.isNull() || !isListView(option))
247  return string;
248 
249  foreach (KFileItemDelegate::Information info, informationList)
250  {
251  if (info == KFileItemDelegate::NoInformation)
252  continue;
253 
254  if (!string.isEmpty())
255  string += QChar::LineSeparator;
256 
257  switch (info)
258  {
259  case KFileItemDelegate::Size:
260  string += itemSize(index, item);
261  break;
262 
263  case KFileItemDelegate::Permissions:
264  string += item.permissionsString();
265  break;
266 
267  case KFileItemDelegate::OctalPermissions:
268  string += QString('0') + QString::number(item.permissions(), 8);
269  break;
270 
271  case KFileItemDelegate::Owner:
272  string += item.user();
273  break;
274 
275  case KFileItemDelegate::OwnerAndGroup:
276  string += item.user() + ':' + item.group();
277  break;
278 
279  case KFileItemDelegate::CreationTime:
280  string += item.timeString(KFileItem::CreationTime);
281  break;
282 
283  case KFileItemDelegate::ModificationTime:
284  string += item.timeString(KFileItem::ModificationTime);
285  break;
286 
287  case KFileItemDelegate::AccessTime:
288  string += item.timeString(KFileItem::AccessTime);
289  break;
290 
291  case KFileItemDelegate::MimeType:
292  string += item.isMimeTypeKnown() ? item.mimetype() : i18nc("@info mimetype","Unknown");
293  break;
294 
295  case KFileItemDelegate::FriendlyMimeType:
296  string += item.isMimeTypeKnown() ? item.mimeComment() : i18nc("@info mimetype","Unknown");
297  break;
298 
299  case KFileItemDelegate::LinkDest:
300  string += item.linkDest();
301  break;
302 
303  case KFileItemDelegate::LocalPathOrUrl:
304  if(!item.localPath().isEmpty())
305  string += item.localPath();
306  else
307  string += item.url().pathOrUrl();
308  break;
309 
310  case KFileItemDelegate::Comment:
311  string += item.comment();
312  break;
313 
314  default:
315  break;
316  } // switch (info)
317  } // foreach (info, list)
318 
319  return string;
320 }
321 
322 
323 // Returns the KFileItem for the index
324 KFileItem KFileItemDelegate::Private::fileItem(const QModelIndex &index) const
325 {
326  const QVariant value = index.data(KDirModel::FileItemRole);
327  return qvariant_cast<KFileItem>(value);
328 }
329 
330 
331 // Replaces any newline characters in the provided string, with QChar::LineSeparator
332 QString KFileItemDelegate::Private::replaceNewlines(const QString &text) const
333 {
334  QString string = text;
335  const QChar newline = QLatin1Char('\n');
336 
337  for (int i = 0; i < string.length(); i++)
338  if (string[i] == newline)
339  string[i] = QChar::LineSeparator;
340 
341  return string;
342 }
343 
344 
345 // Lays the text out in a rectangle no larger than constraints, eliding it as necessary
346 QSize KFileItemDelegate::Private::layoutText(QTextLayout &layout, const QStyleOptionViewItemV4 &option,
347  const QString &text, const QSize &constraints) const
348 {
349  const QSize size = layoutText(layout, text, constraints.width());
350 
351  if (size.width() > constraints.width() || size.height() > constraints.height())
352  {
353  const QString elided = elidedText(layout, option, constraints);
354  return layoutText(layout, elided, constraints.width());
355  }
356 
357  return size;
358 }
359 
360 
361 // Lays the text out in a rectangle no wider than maxWidth
362 QSize KFileItemDelegate::Private::layoutText(QTextLayout &layout, const QString &text, int maxWidth) const
363 {
364  QFontMetrics metrics(layout.font());
365  int leading = metrics.leading();
366  int height = 0;
367  qreal widthUsed = 0;
368  QTextLine line;
369 
370  layout.setText(text);
371 
372  layout.beginLayout();
373  while ((line = layout.createLine()).isValid())
374  {
375  line.setLineWidth(maxWidth);
376  height += leading;
377  line.setPosition(QPoint(0, height));
378  height += int(line.height());
379  widthUsed = qMax(widthUsed, line.naturalTextWidth());
380  }
381  layout.endLayout();
382 
383  return QSize(qCeil(widthUsed), height);
384 }
385 
386 
387 // Elides the text in the layout, by iterating over each line in the layout, eliding
388 // or word breaking the line if it's wider than the max width, and finally adding an
389 // ellipses at the end of the last line, if there are more lines than will fit within
390 // the vertical size constraints.
391 QString KFileItemDelegate::Private::elidedText(QTextLayout &layout, const QStyleOptionViewItemV4 &option,
392  const QSize &size) const
393 {
394  const QString text = layout.text();
395  int maxWidth = size.width();
396  int maxHeight = size.height();
397  qreal height = 0;
398  bool wrapText = (option.features & QStyleOptionViewItemV2::WrapText);
399 
400  // If the string contains a single line of text that shouldn't be word wrapped
401  if (!wrapText && text.indexOf(QChar::LineSeparator) == -1)
402  return option.fontMetrics.elidedText(text, option.textElideMode, maxWidth);
403 
404  // Elide each line that has already been laid out in the layout.
405  QString elided;
406  elided.reserve(text.length());
407 
408  for (int i = 0; i < layout.lineCount(); i++)
409  {
410  QTextLine line = layout.lineAt(i);
411  int start = line.textStart();
412  int length = line.textLength();
413 
414  height += option.fontMetrics.leading();
415  if (height + line.height() + option.fontMetrics.lineSpacing() > maxHeight)
416  {
417  // Unfortunately, if the line ends because of a line separator, elidedText() will be too
418  // clever and keep adding lines until it finds one that's too wide.
419  if (line.naturalTextWidth() < maxWidth && text[start + length - 1] == QChar::LineSeparator)
420  elided += text.mid(start, length - 1);
421  else
422  elided += option.fontMetrics.elidedText(text.mid(start), option.textElideMode, maxWidth);
423  break;
424  }
425  else if (line.naturalTextWidth() > maxWidth)
426  {
427  elided += option.fontMetrics.elidedText(text.mid(start, length), option.textElideMode, maxWidth);
428  if (!elided.endsWith(QChar::LineSeparator))
429  elided += QChar::LineSeparator;
430  }
431  else
432  elided += text.mid(start, length);
433 
434  height += line.height();
435  }
436 
437  return elided;
438 }
439 
440 
441 void KFileItemDelegate::Private::setLayoutOptions(QTextLayout &layout, const QStyleOptionViewItemV4 &option) const
442 {
443  QTextOption textoption;
444  textoption.setTextDirection(option.direction);
445  textoption.setAlignment(QStyle::visualAlignment(option.direction, option.displayAlignment));
446  textoption.setWrapMode((option.features & QStyleOptionViewItemV2::WrapText) ? wrapMode : QTextOption::NoWrap);
447 
448  layout.setFont(option.font);
449  layout.setTextOption(textoption);
450 }
451 
452 
453 QSize KFileItemDelegate::Private::displaySizeHint(const QStyleOptionViewItemV4 &option,
454  const QModelIndex &index) const
455 {
456  QString label = option.text;
457  int maxWidth = 0;
458  if (maximumSize.isEmpty()) {
459  maxWidth = verticalLayout(option) && (option.features & QStyleOptionViewItemV2::WrapText)
460  ? option.decorationSize.width() + 10 : 32757;
461  }
462  else {
463  const Margin &itemMargin = activeMargins[ItemMargin];
464  const Margin &textMargin = activeMargins[TextMargin];
465  maxWidth = maximumSize.width() -
466  (itemMargin.left + itemMargin.right) -
467  (textMargin.left + textMargin.right);
468  }
469 
470  KFileItem item = fileItem(index);
471 
472  // To compute the nominal size for the label + info, we'll just append
473  // the information string to the label
474  const QString info = information(option, index, item);
475  if (!info.isEmpty())
476  label += QString(QChar::LineSeparator) + info;
477 
478  QTextLayout layout;
479  setLayoutOptions(layout, option);
480 
481  QSize size = layoutText(layout, label, maxWidth);
482  if (!info.isEmpty())
483  {
484  // As soon as additional information is shown, it might be necessary that
485  // the label and/or the additional information must get elided. To prevent
486  // an expensive eliding in the scope of displaySizeHint, the maximum
487  // width is reserved instead.
488  size.setWidth(maxWidth);
489  }
490 
491  return addMargin(size, TextMargin);
492 }
493 
494 
495 QSize KFileItemDelegate::Private::decorationSizeHint(const QStyleOptionViewItemV4 &option,
496  const QModelIndex &index) const
497 {
498  Q_UNUSED(index)
499 
500  QSize iconSize = option.icon.actualSize(option.decorationSize);
501  if (!verticalLayout(option))
502  iconSize.rwidth() = option.decorationSize.width();
503  else if (iconSize.width() < option.decorationSize.width())
504  iconSize.rwidth() = qMin(iconSize.width() + 10, option.decorationSize.width());
505  if (iconSize.height() < option.decorationSize.height())
506  iconSize.rheight() = option.decorationSize.height();
507 
508  return addMargin(iconSize, IconMargin);
509 }
510 
511 
512 bool KFileItemDelegate::Private::verticalLayout(const QStyleOptionViewItemV4 &option) const
513 {
514  return (option.decorationPosition == QStyleOptionViewItem::Top ||
515  option.decorationPosition == QStyleOptionViewItem::Bottom);
516 }
517 
518 
519 // Converts a QVariant of type Brush or Color to a QBrush
520 QBrush KFileItemDelegate::Private::brush(const QVariant &value, const QStyleOptionViewItemV4 &option) const
521 {
522  if (value.userType() == qMetaTypeId<KStatefulBrush>())
523  return qvariant_cast<KStatefulBrush>(value).brush(option.palette);
524  switch (value.type())
525  {
526  case QVariant::Color:
527  return QBrush(qvariant_cast<QColor>(value));
528 
529  case QVariant::Brush:
530  return qvariant_cast<QBrush>(value);
531 
532  default:
533  return QBrush(Qt::NoBrush);
534  }
535 }
536 
537 
538 QBrush KFileItemDelegate::Private::foregroundBrush(const QStyleOptionViewItemV4 &option, const QModelIndex &index) const
539 {
540  QPalette::ColorGroup cg = QPalette::Active;
541  if (!(option.state & QStyle::State_Enabled)) {
542  cg = QPalette::Disabled;
543  } else if (!(option.state & QStyle::State_Active)) {
544  cg = QPalette::Inactive;
545  }
546 
547  // Always use the highlight color for selected items
548  if (option.state & QStyle::State_Selected)
549  return option.palette.brush(cg, QPalette::HighlightedText);
550 
551  // If the model provides its own foreground color/brush for this item
552  const QVariant value = index.data(Qt::ForegroundRole);
553  if (value.isValid())
554  return brush(value, option);
555 
556  return option.palette.brush(cg, QPalette::Text);
557 }
558 
559 
560 bool KFileItemDelegate::Private::isListView(const QStyleOptionViewItemV4 &option) const
561 {
562  if (qobject_cast<const QListView*>(option.widget) || verticalLayout(option))
563  return true;
564 
565  return false;
566 }
567 
568 
569 QPixmap KFileItemDelegate::Private::applyHoverEffect(const QPixmap &icon) const
570 {
571  KIconEffect *effect = KIconLoader::global()->iconEffect();
572 
573  // Note that in KIconLoader terminology, active = hover.
574  // ### We're assuming that the icon group is desktop/filemanager, since this
575  // is KFileItemDelegate.
576  if (effect->hasEffect(KIconLoader::Desktop, KIconLoader::ActiveState))
577  return effect->apply(icon, KIconLoader::Desktop, KIconLoader::ActiveState);
578 
579  return icon;
580 }
581 
582 void KFileItemDelegate::Private::gotNewIcon(const QModelIndex& index)
583 {
584  animationHandler->gotNewIcon(index);
585 }
586 
587 void KFileItemDelegate::Private::restartAnimation(KIO::AnimationState* state)
588 {
589  animationHandler->restartAnimation(state);
590 }
591 
592 KIO::AnimationState *KFileItemDelegate::Private::animationState(const QStyleOptionViewItemV4 &option,
593  const QModelIndex &index,
594  const QAbstractItemView *view) const
595 {
596  if (!(KGlobalSettings::graphicEffectsLevel() & KGlobalSettings::SimpleAnimationEffects)) {
597  return NULL;
598  }
599 
600  if (index.column() == KDirModel::Name)
601  return animationHandler->animationState(option, index, view);
602 
603  return NULL;
604 }
605 
606 
607 QPixmap KFileItemDelegate::Private::transition(const QPixmap &from, const QPixmap &to, qreal amount) const
608 {
609  int value = int(0xff * amount);
610 
611  if (value == 0 || to.isNull())
612  return from;
613 
614  if (value == 0xff || from.isNull())
615  return to;
616 
617  QColor color;
618  color.setAlphaF(amount);
619 
620 // FIXME: Somehow this doesn't work on Mac OS..
621 #if defined(Q_OS_MAC)
622  const bool usePixmap = false;
623 #else
624  const bool usePixmap = from.paintEngine()->hasFeature(QPaintEngine::PorterDuff) &&
625  from.paintEngine()->hasFeature(QPaintEngine::BlendModes);
626 #endif
627 
628  // If the native paint engine supports Porter/Duff compositing and CompositionMode_Plus
629  if (usePixmap)
630  {
631  QPixmap under = from;
632  QPixmap over = to;
633 
634  QPainter p;
635  p.begin(&over);
636  p.setCompositionMode(QPainter::CompositionMode_DestinationIn);
637  p.fillRect(over.rect(), color);
638  p.end();
639 
640  p.begin(&under);
641  p.setCompositionMode(QPainter::CompositionMode_DestinationOut);
642  p.fillRect(under.rect(), color);
643  p.setCompositionMode(QPainter::CompositionMode_Plus);
644  p.drawPixmap(0, 0, over);
645  p.end();
646 
647  return under;
648  }
649 #if defined(Q_WS_X11) && defined(HAVE_XRENDER)
650  else if (from.paintEngine()->hasFeature(QPaintEngine::PorterDuff)) // We have Xrender support
651  {
652  // QX11PaintEngine doesn't implement CompositionMode_Plus in Qt 4.3,
653  // which we need to be able to do a transition from one pixmap to
654  // another.
655  //
656  // In order to avoid the overhead of converting the pixmaps to images
657  // and doing the operation entirely in software, this function has a
658  // specialized path for X11 that uses Xrender directly to do the
659  // transition. This operation can be fully accelerated in HW.
660  //
661  // This specialization can be removed when QX11PaintEngine supports
662  // CompositionMode_Plus.
663  QPixmap source(to), destination(from);
664 
665  source.detach();
666  destination.detach();
667 
668  Display *dpy = QX11Info::display();
669 
670  XRenderPictFormat *format = XRenderFindStandardFormat(dpy, PictStandardA8);
671  XRenderPictureAttributes pa;
672  pa.repeat = 1; // RepeatNormal
673 
674  // Create a 1x1 8 bit repeating alpha picture
675  Pixmap pixmap = XCreatePixmap(dpy, destination.handle(), 1, 1, 8);
676  Picture alpha = XRenderCreatePicture(dpy, pixmap, format, CPRepeat, &pa);
677  XFreePixmap(dpy, pixmap);
678 
679  // Fill the alpha picture with the opacity value
680  XRenderColor xcolor;
681  xcolor.alpha = quint16(0xffff * amount);
682  XRenderFillRectangle(dpy, PictOpSrc, alpha, &xcolor, 0, 0, 1, 1);
683 
684  // Reduce the alpha of the destination with 1 - opacity
685  XRenderComposite(dpy, PictOpOutReverse, alpha, None, destination.x11PictureHandle(),
686  0, 0, 0, 0, 0, 0, destination.width(), destination.height());
687 
688  // Add source * opacity to the destination
689  XRenderComposite(dpy, PictOpAdd, source.x11PictureHandle(), alpha,
690  destination.x11PictureHandle(),
691  0, 0, 0, 0, 0, 0, destination.width(), destination.height());
692 
693  XRenderFreePicture(dpy, alpha);
694  return destination;
695  }
696 #endif
697  else
698  {
699  // Fall back to using QRasterPaintEngine to do the transition.
700  QImage under = from.toImage();
701  QImage over = to.toImage();
702 
703  QPainter p;
704  p.begin(&over);
705  p.setCompositionMode(QPainter::CompositionMode_DestinationIn);
706  p.fillRect(over.rect(), color);
707  p.end();
708 
709  p.begin(&under);
710  p.setCompositionMode(QPainter::CompositionMode_DestinationOut);
711  p.fillRect(under.rect(), color);
712  p.setCompositionMode(QPainter::CompositionMode_Plus);
713  p.drawImage(0, 0, over);
714  p.end();
715 
716  return QPixmap::fromImage(under);
717  }
718 }
719 
720 
721 void KFileItemDelegate::Private::layoutTextItems(const QStyleOptionViewItemV4 &option, const QModelIndex &index,
722  QTextLayout *labelLayout, QTextLayout *infoLayout,
723  QRect *textBoundingRect) const
724 {
725  KFileItem item = fileItem(index);
726  const QString info = information(option, index, item);
727  bool showInformation = false;
728 
729  setLayoutOptions(*labelLayout, option);
730 
731  const QRect textArea = labelRectangle(option);
732  QRect textRect = subtractMargin(textArea, Private::TextMargin);
733 
734  // Sizes and constraints for the different text parts
735  QSize maxLabelSize = textRect.size();
736  QSize maxInfoSize = textRect.size();
737  QSize labelSize;
738  QSize infoSize;
739 
740  // If we have additional info text, and there's space for at least two lines of text,
741  // adjust the max label size to make room for at least one line of the info text
742  if (!info.isEmpty() && textRect.height() >= option.fontMetrics.lineSpacing() * 2)
743  {
744  infoLayout->setFont(labelLayout->font());
745  infoLayout->setTextOption(labelLayout->textOption());
746 
747  maxLabelSize.rheight() -= option.fontMetrics.lineSpacing();
748  showInformation = true;
749  }
750 
751  // Lay out the label text, and adjust the max info size based on the label size
752  labelSize = layoutText(*labelLayout, option, option.text, maxLabelSize);
753  maxInfoSize.rheight() -= labelSize.height();
754 
755  // Lay out the info text
756  if (showInformation)
757  infoSize = layoutText(*infoLayout, option, info, maxInfoSize);
758  else
759  infoSize = QSize(0, 0);
760 
761  // Compute the bounding rect of the text
762  const QSize size(qMax(labelSize.width(), infoSize.width()), labelSize.height() + infoSize.height());
763  *textBoundingRect = QStyle::alignedRect(option.direction, option.displayAlignment, size, textRect);
764 
765  // Compute the positions where we should draw the layouts
766  labelLayout->setPosition(QPointF(textRect.x(), textBoundingRect->y()));
767  infoLayout->setPosition(QPointF(textRect.x(), textBoundingRect->y() + labelSize.height()));
768 }
769 
770 
771 void KFileItemDelegate::Private::drawTextItems(QPainter *painter, const QTextLayout &labelLayout,
772  const QTextLayout &infoLayout, const QRect &boundingRect) const
773 {
774  if (shadowColor.alpha() > 0)
775  {
776  QPixmap pixmap(boundingRect.size());
777  pixmap.fill(Qt::transparent);
778 
779  QPainter p(&pixmap);
780  p.translate(-boundingRect.topLeft());
781  p.setPen(painter->pen());
782  labelLayout.draw(&p, QPoint());
783 
784  if (!infoLayout.text().isEmpty())
785  {
786  QColor color = p.pen().color();
787  color.setAlphaF(0.6);
788 
789  p.setPen(color);
790  infoLayout.draw(&p, QPoint());
791  }
792  p.end();
793 
794  int padding = qCeil(shadowBlur);
795  int blurFactor = qRound(shadowBlur);
796 
797  QImage image(boundingRect.size() + QSize(padding * 2, padding * 2), QImage::Format_ARGB32_Premultiplied);
798  image.fill(0);
799  p.begin(&image);
800  p.drawImage(padding, padding, pixmap.toImage());
801  p.end();
802 
803  KIO::ImageFilter::shadowBlur(image, blurFactor, shadowColor);
804 
805  painter->drawImage(boundingRect.topLeft() - QPoint(padding, padding) + shadowOffset.toPoint(), image);
806  painter->drawPixmap(boundingRect.topLeft(), pixmap);
807  return;
808  }
809 
810  labelLayout.draw(painter, QPoint());
811 
812  if (!infoLayout.text().isEmpty())
813  {
814  // TODO - for apps not doing funny things with the color palette,
815  // KColorScheme::InactiveText would be a much more correct choice. We
816  // should provide an API to specify what color to use for information.
817  QColor color = painter->pen().color();
818  color.setAlphaF(0.6);
819 
820  painter->setPen(color);
821  infoLayout.draw(painter, QPoint());
822  }
823 }
824 
825 
826 void KFileItemDelegate::Private::initStyleOption(QStyleOptionViewItemV4 *option,
827  const QModelIndex &index) const
828 {
829  const KFileItem item = fileItem(index);
830  bool updateFontMetrics = false;
831 
832  // Try to get the font from the model
833  QVariant value = index.data(Qt::FontRole);
834  if (value.isValid()) {
835  option->font = qvariant_cast<QFont>(value).resolve(option->font);
836  updateFontMetrics = true;
837  }
838 
839  // Use an italic font for symlinks
840  if (!item.isNull() && item.isLink()) {
841  option->font.setItalic(true);
842  updateFontMetrics = true;
843  }
844 
845  if (updateFontMetrics)
846  option->fontMetrics = QFontMetrics(option->font);
847 
848  // Try to get the alignment for the item from the model
849  value = index.data(Qt::TextAlignmentRole);
850  if (value.isValid())
851  option->displayAlignment = Qt::Alignment(value.toInt());
852 
853  value = index.data(Qt::BackgroundRole);
854  if (value.isValid())
855  option->backgroundBrush = brush(value, *option);
856 
857  option->text = display(index);
858  if (!option->text.isEmpty())
859  option->features |= QStyleOptionViewItemV2::HasDisplay;
860 
861  option->icon = decoration(*option, index);
862  if (!option->icon.isNull())
863  option->features |= QStyleOptionViewItemV2::HasDecoration;
864 
865  // ### Make sure this value is always true for now
866  option->showDecorationSelected = true;
867 }
868 
869 void KFileItemDelegate::Private::paintJobTransfers(QPainter *painter, const qreal &jobAnimationAngle, const QPoint &iconPos, const QStyleOptionViewItemV4& opt)
870 {
871  painter->save();
872  QSize iconSize = opt.icon.actualSize(opt.decorationSize);
873  QPixmap downArrow = downArrowIcon.pixmap(iconSize * 0.30);
874  //corner (less x and y than bottom-right corner) that we will center the painter around
875  QPoint bottomRightCorner = QPoint(iconPos.x() + iconSize.width() * 0.75, iconPos.y() + iconSize.height() * 0.60);
876 
877  QPainter pixmapPainter(&downArrow);
878  //make the icon transparent and such
879  pixmapPainter.setCompositionMode(QPainter::CompositionMode_DestinationIn);
880  pixmapPainter.fillRect(downArrow.rect(), QColor(255, 255, 255, 110));
881 
882 
883  painter->translate(bottomRightCorner);
884 
885  painter->drawPixmap(-downArrow.size().width() * .50, -downArrow.size().height() * .50, downArrow);
886 
887  //animate the circles by rotating the painter around the center point..
888  painter->rotate(jobAnimationAngle);
889  painter->setPen(QColor(20, 20, 20, 80));
890  painter->setBrush(QColor(250, 250, 250, 90));
891 
892  int radius = iconSize.width() * 0.04;
893  int spacing = radius * 4.5;
894 
895  //left
896  painter->drawEllipse(QPoint(-spacing, 0), radius, radius);
897  //right
898  painter->drawEllipse(QPoint(spacing, 0), radius, radius);
899  //up
900  painter->drawEllipse(QPoint(0, -spacing), radius, radius);
901  //down
902  painter->drawEllipse(QPoint(0, spacing), radius, radius);
903  painter->restore();
904 }
905 
906 
907 // ---------------------------------------------------------------------------
908 
909 
910 KFileItemDelegate::KFileItemDelegate(QObject *parent)
911  : QAbstractItemDelegate(parent), d(new Private(this))
912 {
913  int focusHMargin = QApplication::style()->pixelMetric(QStyle::PM_FocusFrameHMargin);
914  int focusVMargin = QApplication::style()->pixelMetric(QStyle::PM_FocusFrameVMargin);
915 
916  // Margins for horizontal mode (list views, tree views, table views)
917  const int textMargin = focusHMargin * 4;
918  if (QApplication::isRightToLeft())
919  d->setHorizontalMargin(Private::TextMargin, textMargin, focusVMargin, focusHMargin, focusVMargin);
920  else
921  d->setHorizontalMargin(Private::TextMargin, focusHMargin, focusVMargin, textMargin, focusVMargin);
922 
923  d->setHorizontalMargin(Private::IconMargin, focusHMargin, focusVMargin);
924  d->setHorizontalMargin(Private::ItemMargin, 0, 0);
925 
926  // Margins for vertical mode (icon views)
927  d->setVerticalMargin(Private::TextMargin, 6, 2);
928  d->setVerticalMargin(Private::IconMargin, focusHMargin, focusVMargin);
929  d->setVerticalMargin(Private::ItemMargin, 0, 0);
930 
931  setShowInformation(NoInformation);
932 }
933 
934 
935 KFileItemDelegate::~KFileItemDelegate()
936 {
937  delete d;
938 }
939 
940 
941 QSize KFileItemDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
942 {
943  // If the model wants to provide its own size hint for the item
944  const QVariant value = index.data(Qt::SizeHintRole);
945  if (value.isValid())
946  return qvariant_cast<QSize>(value);
947 
948  QStyleOptionViewItemV4 opt(option);
949  d->initStyleOption(&opt, index);
950  d->setActiveMargins(d->verticalLayout(opt) ? Qt::Vertical : Qt::Horizontal);
951 
952  const QSize displaySize = d->displaySizeHint(opt, index);
953  const QSize decorationSize = d->decorationSizeHint(opt, index);
954 
955  QSize size;
956 
957  if (d->verticalLayout(opt))
958  {
959  size.rwidth() = qMax(displaySize.width(), decorationSize.width());
960  size.rheight() = decorationSize.height() + displaySize.height() + 1;
961  }
962  else
963  {
964  size.rwidth() = decorationSize.width() + displaySize.width() + 1;
965  size.rheight() = qMax(decorationSize.height(), displaySize.height());
966  }
967 
968  size = d->addMargin(size, Private::ItemMargin);
969  if (!d->maximumSize.isEmpty())
970  {
971  size = size.boundedTo(d->maximumSize);
972  }
973 
974  return size;
975 }
976 
977 
978 QString KFileItemDelegate::Private::display(const QModelIndex &index) const
979 {
980  const QVariant value = index.data(Qt::DisplayRole);
981 
982  switch (value.type())
983  {
984  case QVariant::String:
985  {
986  if (index.column() == KDirModel::Size)
987  return itemSize(index, fileItem(index));
988  else {
989  const QString text = replaceNewlines(value.toString());
990  return KStringHandler::preProcessWrap(text);
991  }
992  }
993 
994  case QVariant::Double:
995  return KGlobal::locale()->formatNumber(value.toDouble());
996 
997  case QVariant::Int:
998  case QVariant::UInt:
999  return KGlobal::locale()->formatLong(value.toInt());
1000 
1001  default:
1002  return QString();
1003  }
1004 }
1005 
1006 
1007 void KFileItemDelegate::setShowInformation(const InformationList &list)
1008 {
1009  d->informationList = list;
1010 }
1011 
1012 
1013 void KFileItemDelegate::setShowInformation(Information value)
1014 {
1015  if (value != NoInformation)
1016  d->informationList = InformationList() << value;
1017  else
1018  d->informationList = InformationList();
1019 }
1020 
1021 
1022 KFileItemDelegate::InformationList KFileItemDelegate::showInformation() const
1023 {
1024  return d->informationList;
1025 }
1026 
1027 
1028 void KFileItemDelegate::setShadowColor(const QColor &color)
1029 {
1030  d->shadowColor = color;
1031 }
1032 
1033 
1034 QColor KFileItemDelegate::shadowColor() const
1035 {
1036  return d->shadowColor;
1037 }
1038 
1039 
1040 void KFileItemDelegate::setShadowOffset(const QPointF &offset)
1041 {
1042  d->shadowOffset = offset;
1043 }
1044 
1045 
1046 QPointF KFileItemDelegate::shadowOffset() const
1047 {
1048  return d->shadowOffset;
1049 }
1050 
1051 
1052 void KFileItemDelegate::setShadowBlur(qreal factor)
1053 {
1054  d->shadowBlur = factor;
1055 }
1056 
1057 
1058 qreal KFileItemDelegate::shadowBlur() const
1059 {
1060  return d->shadowBlur;
1061 }
1062 
1063 
1064 void KFileItemDelegate::setMaximumSize(const QSize &size)
1065 {
1066  d->maximumSize = size;
1067 }
1068 
1069 
1070 QSize KFileItemDelegate::maximumSize() const
1071 {
1072  return d->maximumSize;
1073 }
1074 
1075 
1076 void KFileItemDelegate::setShowToolTipWhenElided(bool showToolTip)
1077 {
1078  d->showToolTipWhenElided = showToolTip;
1079 }
1080 
1081 
1082 bool KFileItemDelegate::showToolTipWhenElided() const
1083 {
1084  return d->showToolTipWhenElided;
1085 }
1086 
1087 
1088 void KFileItemDelegate::setWrapMode(QTextOption::WrapMode wrapMode)
1089 {
1090  d->wrapMode = wrapMode;
1091 }
1092 
1093 
1094 QTextOption::WrapMode KFileItemDelegate::wrapMode() const
1095 {
1096  return d->wrapMode;
1097 }
1098 
1099 QRect KFileItemDelegate::iconRect(const QStyleOptionViewItem &option, const QModelIndex &index) const
1100 {
1101  QStyleOptionViewItemV4 opt(option);
1102  d->initStyleOption(&opt, index);
1103  return QRect(d->iconPosition(opt), opt.icon.actualSize(opt.decorationSize));
1104 }
1105 
1106 
1107 void KFileItemDelegate::setJobTransfersVisible(bool jobTransfersVisible)
1108 {
1109  d->downArrowIcon = KIcon("go-down");
1110  d->jobTransfersVisible = jobTransfersVisible;
1111 }
1112 
1113 
1114 bool KFileItemDelegate::jobTransfersVisible() const
1115 {
1116  return d->jobTransfersVisible;
1117 }
1118 
1119 
1120 QIcon KFileItemDelegate::Private::decoration(const QStyleOptionViewItemV4 &option, const QModelIndex &index) const
1121 {
1122  const QVariant value = index.data(Qt::DecorationRole);
1123  QIcon icon;
1124 
1125  switch (value.type())
1126  {
1127  case QVariant::Icon:
1128  icon = qvariant_cast<QIcon>(value);
1129  break;
1130 
1131  case QVariant::Pixmap:
1132  icon.addPixmap(qvariant_cast<QPixmap>(value));
1133  break;
1134 
1135  case QVariant::Color: {
1136  QPixmap pixmap(option.decorationSize);
1137  pixmap.fill(qvariant_cast<QColor>(value));
1138  icon.addPixmap(pixmap);
1139  break;
1140  }
1141 
1142  default:
1143  break;
1144  }
1145 
1146  return icon;
1147 }
1148 
1149 
1150 QRect KFileItemDelegate::Private::labelRectangle(const QStyleOptionViewItemV4 &option) const
1151 {
1152  if (option.icon.isNull())
1153  return subtractMargin(option.rect, Private::ItemMargin);
1154 
1155  const QSize decoSize = addMargin(option.decorationSize, Private::IconMargin);
1156  const QRect itemRect = subtractMargin(option.rect, Private::ItemMargin);
1157  QRect textArea(QPoint(0, 0), itemRect.size());
1158 
1159  switch (option.decorationPosition)
1160  {
1161  case QStyleOptionViewItem::Top:
1162  textArea.setTop(decoSize.height() + 1);
1163  break;
1164 
1165  case QStyleOptionViewItem::Bottom:
1166  textArea.setBottom(itemRect.height() - decoSize.height() - 1);
1167  break;
1168 
1169  case QStyleOptionViewItem::Left:
1170  textArea.setLeft(decoSize.width() + 1);
1171  break;
1172 
1173  case QStyleOptionViewItem::Right:
1174  textArea.setRight(itemRect.width() - decoSize.width() - 1);
1175  break;
1176  }
1177 
1178  textArea.translate(itemRect.topLeft());
1179  return QStyle::visualRect(option.direction, option.rect, textArea);
1180 }
1181 
1182 
1183 QPoint KFileItemDelegate::Private::iconPosition(const QStyleOptionViewItemV4 &option) const
1184 {
1185  const QRect itemRect = subtractMargin(option.rect, Private::ItemMargin);
1186  Qt::Alignment alignment;
1187 
1188  // Convert decorationPosition to the alignment the decoration will have in option.rect
1189  switch (option.decorationPosition)
1190  {
1191  case QStyleOptionViewItem::Top:
1192  alignment = Qt::AlignHCenter | Qt::AlignTop;
1193  break;
1194 
1195  case QStyleOptionViewItem::Bottom:
1196  alignment = Qt::AlignHCenter | Qt::AlignBottom;
1197  break;
1198 
1199  case QStyleOptionViewItem::Left:
1200  alignment = Qt::AlignVCenter | Qt::AlignLeft;
1201  break;
1202 
1203  case QStyleOptionViewItem::Right:
1204  alignment = Qt::AlignVCenter | Qt::AlignRight;
1205  break;
1206  }
1207 
1208  // Compute the nominal decoration rectangle
1209  const QSize size = addMargin(option.decorationSize, Private::IconMargin);
1210  const QRect rect = QStyle::alignedRect(option.direction, alignment, size, itemRect);
1211 
1212  // Position the icon in the center of the rectangle
1213  QRect iconRect = QRect(QPoint(), option.icon.actualSize(option.decorationSize));
1214  iconRect.moveCenter(rect.center());
1215 
1216  return iconRect.topLeft();
1217 }
1218 
1219 
1220 void KFileItemDelegate::Private::drawFocusRect(QPainter *painter, const QStyleOptionViewItemV4 &option,
1221  const QRect &rect) const
1222 {
1223  if (!(option.state & QStyle::State_HasFocus))
1224  return;
1225 
1226  QStyleOptionFocusRect opt;
1227  opt.direction = option.direction;
1228  opt.fontMetrics = option.fontMetrics;
1229  opt.palette = option.palette;
1230  opt.rect = rect;
1231  opt.state = option.state | QStyle::State_KeyboardFocusChange | QStyle::State_Item;
1232  opt.backgroundColor = option.palette.color(option.state & QStyle::State_Selected ?
1233  QPalette::Highlight : QPalette::Base);
1234 
1235  // Apparently some widget styles expect this hint to not be set
1236  painter->setRenderHint(QPainter::Antialiasing, false);
1237 
1238  QStyle *style = option.widget ? option.widget->style() : QApplication::style();
1239  style->drawPrimitive(QStyle::PE_FrameFocusRect, &opt, painter, option.widget);
1240 
1241  painter->setRenderHint(QPainter::Antialiasing);
1242 }
1243 
1244 
1245 void KFileItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
1246  const QModelIndex &index) const
1247 {
1248  if (!index.isValid())
1249  return;
1250 
1251  QStyleOptionViewItemV4 opt(option);
1252  d->initStyleOption(&opt, index);
1253  d->setActiveMargins(d->verticalLayout(opt) ? Qt::Vertical : Qt::Horizontal);
1254 
1255  if (!(option.state & QStyle::State_Enabled))
1256  {
1257  opt.palette.setCurrentColorGroup(QPalette::Disabled);
1258  }
1259 
1260  // Unset the mouse over bit if we're not drawing the first column
1261  if (index.column() > 0)
1262  opt.state &= ~QStyle::State_MouseOver;
1263  else
1264  opt.viewItemPosition = QStyleOptionViewItemV4::OnlyOne;
1265 
1266  const QAbstractItemView *view = qobject_cast<const QAbstractItemView*>(opt.widget);
1267 
1268 
1269  // Check if the item is being animated
1270  // ========================================================================
1271  KIO::AnimationState *state = d->animationState(opt, index, view);
1272  KIO::CachedRendering *cache = 0;
1273  qreal progress = ((opt.state & QStyle::State_MouseOver) &&
1274  index.column() == KDirModel::Name) ? 1.0 : 0.0;
1275  const QPoint iconPos = d->iconPosition(opt);
1276  QIcon::Mode iconMode = option.state & QStyle::State_Enabled ? QIcon::Normal : QIcon::Disabled;
1277  QIcon::State iconState = option.state & QStyle::State_Open ? QIcon::On : QIcon::Off;
1278  QPixmap icon = opt.icon.pixmap(opt.decorationSize, iconMode, iconState);
1279 
1280  if (state && !state->hasJobAnimation())
1281  {
1282  cache = state->cachedRendering();
1283  progress = state->hoverProgress();
1284  // Clear the mouse over bit temporarily
1285  opt.state &= ~QStyle::State_MouseOver;
1286 
1287 
1288  // If we have a cached rendering, draw the item from the cache
1289  if (cache)
1290  {
1291  if (cache->checkValidity(opt.state) && cache->regular.size() == opt.rect.size())
1292  {
1293  QPixmap pixmap = d->transition(cache->regular, cache->hover, progress);
1294 
1295  if (state->cachedRenderingFadeFrom() && state->fadeProgress() != 1.0)
1296  {
1297  // Apply icon fading animation
1298  KIO::CachedRendering* fadeFromCache = state->cachedRenderingFadeFrom();
1299  const QPixmap fadeFromPixmap = d->transition(fadeFromCache->regular, fadeFromCache->hover, progress);
1300 
1301  pixmap = d->transition(fadeFromPixmap, pixmap, state->fadeProgress());
1302  }
1303  painter->drawPixmap(option.rect.topLeft(), pixmap);
1304  if (d->jobTransfersVisible && index.column() == 0) {
1305  if (index.data(KDirModel::HasJobRole).toBool()) {
1306  d->paintJobTransfers(painter, state->jobAnimationAngle(), iconPos, opt);
1307  }
1308  }
1309  return;
1310  }
1311 
1312  if (!cache->checkValidity(opt.state))
1313  {
1314  if ((KGlobalSettings::graphicEffectsLevel() & KGlobalSettings::SimpleAnimationEffects))
1315  {
1316  // Fade over from the old icon to the new one
1317  // Only start a new fade if the previous one is ready
1318  // Else we may start racing when checkValidity() always returns false
1319  if (state->fadeProgress() == 1)
1320  state->setCachedRenderingFadeFrom(state->takeCachedRendering());
1321  }
1322  d->gotNewIcon(index);
1323  }
1324  // If it wasn't valid, delete it
1325  state->setCachedRendering(0);
1326  }
1327  else
1328  {
1329  // The cache may have been discarded, but the animation handler still needs to know about new icons
1330  d->gotNewIcon(index);
1331  }
1332  }
1333 
1334 
1335  // Compute the metrics, and lay out the text items
1336  // ========================================================================
1337  const QPen pen = QPen(d->foregroundBrush(opt, index), 0);
1338 
1339  //### Apply the selection effect to the icon when the item is selected and
1340  // showDecorationSelected is false.
1341 
1342  QTextLayout labelLayout, infoLayout;
1343  QRect textBoundingRect;
1344 
1345  d->layoutTextItems(opt, index, &labelLayout, &infoLayout, &textBoundingRect);
1346 
1347  QStyle *style = opt.widget ? opt.widget->style() : QApplication::style();
1348 
1349  int focusHMargin = style->pixelMetric(QStyle::PM_FocusFrameHMargin);
1350  int focusVMargin = style->pixelMetric(QStyle::PM_FocusFrameVMargin);
1351  QRect focusRect = textBoundingRect.adjusted(-focusHMargin, -focusVMargin,
1352  +focusHMargin, +focusVMargin);
1353 
1354  // Create a new cached rendering of a hovered and an unhovered item.
1355  // We don't create a new cache for a fully hovered item, since we don't
1356  // know yet if a hover out animation will be run.
1357  // ========================================================================
1358  if (state && (state->hoverProgress() < 1 || state->fadeProgress() < 1))
1359  {
1360  cache = new KIO::CachedRendering(opt.state, option.rect.size(), index);
1361 
1362  QPainter p;
1363  p.begin(&cache->regular);
1364  p.translate(-option.rect.topLeft());
1365  p.setRenderHint(QPainter::Antialiasing);
1366  p.setPen(pen);
1367  style->drawPrimitive(QStyle::PE_PanelItemViewItem, &opt, &p, opt.widget);
1368  p.drawPixmap(iconPos, icon);
1369  d->drawTextItems(&p, labelLayout, infoLayout, textBoundingRect);
1370  d->drawFocusRect(&p, opt, focusRect);
1371  p.end();
1372 
1373  opt.state |= QStyle::State_MouseOver;
1374  icon = d->applyHoverEffect(icon);
1375 
1376  p.begin(&cache->hover);
1377  p.translate(-option.rect.topLeft());
1378  p.setRenderHint(QPainter::Antialiasing);
1379  p.setPen(pen);
1380  style->drawPrimitive(QStyle::PE_PanelItemViewItem, &opt, &p, opt.widget);
1381  p.drawPixmap(iconPos, icon);
1382  d->drawTextItems(&p, labelLayout, infoLayout, textBoundingRect);
1383  d->drawFocusRect(&p, opt, focusRect);
1384  p.end();
1385 
1386  state->setCachedRendering(cache);
1387 
1388  QPixmap pixmap = d->transition(cache->regular, cache->hover, progress);
1389 
1390  if (state->cachedRenderingFadeFrom() && state->fadeProgress() == 0)
1391  {
1392  // Apply icon fading animation
1393  KIO::CachedRendering* fadeFromCache = state->cachedRenderingFadeFrom();
1394  const QPixmap fadeFromPixmap = d->transition(fadeFromCache->regular, fadeFromCache->hover, progress);
1395 
1396  pixmap = d->transition(fadeFromPixmap, pixmap, state->fadeProgress());
1397 
1398  d->restartAnimation(state);
1399  }
1400 
1401  painter->drawPixmap(option.rect.topLeft(), pixmap);
1402  painter->setRenderHint(QPainter::Antialiasing);
1403  if (d->jobTransfersVisible && index.column() == 0) {
1404  if (index.data(KDirModel::HasJobRole).toBool()) {
1405  d->paintJobTransfers(painter, state->jobAnimationAngle(), iconPos, opt);
1406  }
1407  }
1408  return;
1409  }
1410 
1411 
1412  // Render the item directly if we're not using a cached rendering
1413  // ========================================================================
1414  painter->save();
1415  painter->setRenderHint(QPainter::Antialiasing);
1416  painter->setPen(pen);
1417 
1418  if (progress > 0 && !(opt.state & QStyle::State_MouseOver))
1419  {
1420  opt.state |= QStyle::State_MouseOver;
1421  icon = d->applyHoverEffect(icon);
1422  }
1423 
1424  style->drawPrimitive(QStyle::PE_PanelItemViewItem, &opt, painter, opt.widget);
1425  painter->drawPixmap(iconPos, icon);
1426 
1427  d->drawTextItems(painter, labelLayout, infoLayout, textBoundingRect);
1428  d->drawFocusRect(painter, opt, focusRect);
1429 
1430  if (d->jobTransfersVisible && index.column() == 0 && state) {
1431  if (index.data(KDirModel::HasJobRole).toBool()) {
1432  d->paintJobTransfers(painter, state->jobAnimationAngle(), iconPos, opt);
1433  }
1434  }
1435  painter->restore();
1436 }
1437 
1438 
1439 QWidget *KFileItemDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option,
1440  const QModelIndex &index) const
1441 {
1442  QStyleOptionViewItemV4 opt(option);
1443  d->initStyleOption(&opt, index);
1444 
1445  KTextEdit *edit = new KTextEdit(parent);
1446  edit->setAcceptRichText(false);
1447  edit->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
1448  edit->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
1449  edit->setAlignment(opt.displayAlignment);
1450  edit->setEnabled(false); //Disable the text-edit to mark it as un-initialized
1451  return edit;
1452 }
1453 
1454 
1455 bool KFileItemDelegate::editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option,
1456  const QModelIndex &index)
1457 {
1458  Q_UNUSED(event)
1459  Q_UNUSED(model)
1460  Q_UNUSED(option)
1461  Q_UNUSED(index)
1462 
1463  return false;
1464 }
1465 
1466 
1467 void KFileItemDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const
1468 {
1469  KTextEdit *textedit = qobject_cast<KTextEdit*>(editor);
1470  Q_ASSERT(textedit != 0);
1471 
1472  //Do not update existing text that the user may already have edited.
1473  //The models will call setEditorData(..) whenever the icon has changed,
1474  //and this makes the editing work correctly despite that.
1475  if(textedit->isEnabled()) {
1476  return;
1477  }
1478  textedit->setEnabled(true); //Enable the text-edit to mark it as initialized
1479 
1480  const QVariant value = index.data(Qt::EditRole);
1481  const QString text = value.toString();
1482  textedit->insertPlainText(text);
1483  textedit->selectAll();
1484 
1485  const QString extension = KMimeType::extractKnownExtension(text);
1486  if (!extension.isEmpty()) {
1487  // The filename contains an extension. Assure that only the filename
1488  // gets selected.
1489  const int selectionLength = text.length() - extension.length() - 1;
1490  QTextCursor cursor = textedit->textCursor();
1491  cursor.movePosition(QTextCursor::StartOfBlock);
1492  cursor.movePosition(QTextCursor::NextCharacter, QTextCursor::KeepAnchor, selectionLength);
1493  textedit->setTextCursor(cursor);
1494  }
1495 }
1496 
1497 
1498 void KFileItemDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
1499 {
1500  KTextEdit *textedit = qobject_cast<KTextEdit*>(editor);
1501  Q_ASSERT(textedit != 0);
1502 
1503  model->setData(index, textedit->toPlainText(), Qt::EditRole);
1504 }
1505 
1506 
1507 void KFileItemDelegate::updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option,
1508  const QModelIndex &index) const
1509 {
1510  QStyleOptionViewItemV4 opt(option);
1511  d->initStyleOption(&opt, index);
1512  d->setActiveMargins(d->verticalLayout(opt) ? Qt::Vertical : Qt::Horizontal);
1513 
1514  QRect r = d->labelRectangle(opt);
1515 
1516  // Use the full available width for the editor when maximumSize is set
1517  if (!d->maximumSize.isEmpty()) {
1518  if (d->verticalLayout(option)) {
1519  int diff = qMax(r.width(), d->maximumSize.width()) - r.width();
1520  if (diff > 1) {
1521  r.adjust(-(diff / 2), 0, diff / 2, 0);
1522  }
1523  }
1524  else {
1525  int diff = qMax(r.width(), d->maximumSize.width() - opt.decorationSize.width()) - r.width();
1526  if (diff > 0) {
1527  if (opt.decorationPosition == QStyleOptionViewItem::Left) {
1528  r.adjust(0, 0, diff, 0);
1529  }
1530  else {
1531  r.adjust(-diff, 0, 0, 0);
1532  }
1533  }
1534  }
1535  }
1536 
1537  KTextEdit *textedit = qobject_cast<KTextEdit*>(editor);
1538  Q_ASSERT(textedit != 0);
1539  const int frame = textedit->frameWidth();
1540  r.adjust(-frame, -frame, frame, frame);
1541 
1542  editor->setGeometry(r);
1543 }
1544 
1545 
1546 bool KFileItemDelegate::helpEvent(QHelpEvent *event, QAbstractItemView *view, const QStyleOptionViewItem &option,
1547  const QModelIndex &index)
1548 {
1549  Q_UNUSED(event)
1550  Q_UNUSED(view)
1551 
1552  // if the tooltip information the model keeps is different from the display information,
1553  // show it always
1554  const QVariant toolTip = index.data(Qt::ToolTipRole);
1555 
1556  if (!toolTip.isValid()) {
1557  return false;
1558  }
1559 
1560  if (index.data() != toolTip) {
1561  return QAbstractItemDelegate::helpEvent(event, view, option, index);
1562  }
1563 
1564  if (!d->showToolTipWhenElided) {
1565  return false;
1566  }
1567 
1568  // in the case the tooltip information is the same as the display information,
1569  // show it only in the case the display information is elided
1570  QStyleOptionViewItemV4 opt(option);
1571  d->initStyleOption(&opt, index);
1572  d->setActiveMargins(d->verticalLayout(opt) ? Qt::Vertical : Qt::Horizontal);
1573 
1574  QTextLayout labelLayout;
1575  QTextLayout infoLayout;
1576  QRect textBoundingRect;
1577  d->layoutTextItems(opt, index, &labelLayout, &infoLayout, &textBoundingRect);
1578  const QString elidedText = d->elidedText(labelLayout, opt, textBoundingRect.size());
1579 
1580  if (elidedText != d->display(index)) {
1581  return QAbstractItemDelegate::helpEvent(event, view, option, index);
1582  }
1583 
1584  return false;
1585 }
1586 
1587 QRegion KFileItemDelegate::shape(const QStyleOptionViewItem &option, const QModelIndex &index)
1588 {
1589  QStyleOptionViewItemV4 opt(option);
1590  d->initStyleOption(&opt, index);
1591  d->setActiveMargins(d->verticalLayout(opt) ? Qt::Vertical : Qt::Horizontal);
1592 
1593  QTextLayout labelLayout;
1594  QTextLayout infoLayout;
1595  QRect textBoundingRect;
1596  d->layoutTextItems(opt, index, &labelLayout, &infoLayout, &textBoundingRect);
1597 
1598  const QPoint pos = d->iconPosition(opt);
1599  QRect iconRect = QRect(pos, opt.icon.actualSize(opt.decorationSize));
1600 
1601  // Extend the icon rect so it touches the text rect
1602  switch (opt.decorationPosition)
1603  {
1604  case QStyleOptionViewItem::Top:
1605  if (iconRect.width() < textBoundingRect.width())
1606  iconRect.setBottom(textBoundingRect.top());
1607  else
1608  textBoundingRect.setTop(iconRect.bottom());
1609  break;
1610  case QStyleOptionViewItem::Bottom:
1611  if (iconRect.width() < textBoundingRect.width())
1612  iconRect.setTop(textBoundingRect.bottom());
1613  else
1614  textBoundingRect.setBottom(iconRect.top());
1615  break;
1616  case QStyleOptionViewItem::Left:
1617  iconRect.setRight(textBoundingRect.left());
1618  break;
1619  case QStyleOptionViewItem::Right:
1620  iconRect.setLeft(textBoundingRect.right());
1621  break;
1622  }
1623 
1624  QRegion region;
1625  region += iconRect;
1626  region += textBoundingRect;
1627  return region;
1628 }
1629 
1630 bool KFileItemDelegate::eventFilter(QObject *object, QEvent *event)
1631 {
1632  KTextEdit *editor = qobject_cast<KTextEdit*>(object);
1633  if (!editor)
1634  return false;
1635 
1636  switch (event->type())
1637  {
1638  case QEvent::KeyPress:
1639  {
1640  QKeyEvent *keyEvent = static_cast<QKeyEvent*>(event);
1641  switch (keyEvent->key())
1642  {
1643  case Qt::Key_Tab:
1644  case Qt::Key_Backtab:
1645  emit commitData(editor);
1646  emit closeEditor(editor, NoHint);
1647  return true;
1648 
1649  case Qt::Key_Enter:
1650  case Qt::Key_Return: {
1651  const QString text = editor->toPlainText();
1652  if (text.isEmpty() || (text == QLatin1String(".")) || (text == QLatin1String("..")))
1653  return true; // So a newline doesn't get inserted
1654 
1655  emit commitData(editor);
1656  emit closeEditor(editor, SubmitModelCache);
1657  return true;
1658  }
1659 
1660  case Qt::Key_Escape:
1661  emit closeEditor(editor, RevertModelCache);
1662  return true;
1663 
1664  default:
1665  return false;
1666  } // switch (keyEvent->key())
1667  } // case QEvent::KeyPress
1668 
1669  case QEvent::FocusOut:
1670  {
1671  const QWidget *w = QApplication::activePopupWidget();
1672  if (!w || w->parent() != editor)
1673  {
1674  emit commitData(editor);
1675  emit closeEditor(editor, NoHint);
1676  return true;
1677  }
1678  else
1679  return false;
1680  }
1681 
1682  default:
1683  return false;
1684  } // switch (event->type())
1685 }
1686 
1687 
1688 
1689 #include "kfileitemdelegate.moc"
1690 
1691 
1692 // kate: space-indent on; indent-width 4; replace-tabs on;
delegateanimationhandler_p.h
QTextLayout::textOption
QTextOption textOption() const
KFileItemDelegate::shape
QRegion shape(const QStyleOptionViewItem &option, const QModelIndex &index)
Returns the shape of the item as a region.
Definition: kfileitemdelegate.cpp:1587
QModelIndex
QRect::setBottom
void setBottom(int y)
QSize::boundedTo
QSize boundedTo(const QSize &otherSize) const
QString::indexOf
int indexOf(QChar ch, int from, Qt::CaseSensitivity cs) const
QEvent
QPixmap::size
QSize size() const
QWidget
KFileItemDelegate::LinkDest
The destination of a symbolic link.
Definition: kfileitemdelegate.h:174
QApplication::isRightToLeft
bool isRightToLeft()
QRect::size
QSize size() const
QEvent::type
Type type() const
Left
QTextCursor
QSize::width
int width() const
KDirModel::ChildCountUnknown
Definition: kdirmodel.h:132
QTextLayout::setFont
void setFont(const QFont &font)
KFileItemDelegate::updateEditorGeometry
virtual void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const
Reimplemented from QAbstractItemDelegate.
Definition: kfileitemdelegate.cpp:1507
QPainter::end
bool end()
QTextLine::height
qreal height() const
QAbstractItemView
QPainter::fillRect
void fillRect(const QRectF &rectangle, const QBrush &brush)
QPainter::setCompositionMode
void setCompositionMode(CompositionMode mode)
QPainter::setRenderHint
void setRenderHint(RenderHint hint, bool on)
KFileItemDelegate::LocalPathOrUrl
The local path to the file or the URL in case it is not a local file.
Definition: kfileitemdelegate.h:175
QPixmap::fill
void fill(const QColor &color)
QRect::right
int right() const
KIconLoader::global
static KIconLoader * global()
KFileItemDelegate::setMaximumSize
void setMaximumSize(const QSize &size)
Sets the maximum size for KFileItemDelegate::sizeHint().
Definition: kfileitemdelegate.cpp:1064
KIO::AnimationState::hoverProgress
qreal hoverProgress() const
Definition: delegateanimationhandler.cpp:153
KFileItemDelegate::sizeHint
virtual QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
Returns the nominal size for the item referred to by index, given the provided options.
Definition: kfileitemdelegate.cpp:941
kglobalsettings.h
KFileItem::mimetype
QString mimetype() const
Returns the mimetype of the file item.
Definition: kfileitem.cpp:770
KFileItem::user
QString user() const
Returns the owner of the file.
Definition: kfileitem.cpp:681
Right
KFileItemDelegate::showInformation
InformationList showInformation() const
Returns the file item information that should be shown below item labels in list views.
Definition: kfileitemdelegate.cpp:1022
KFileItemDelegate::AccessTime
The date and time the file/folder was last accessed.
Definition: kfileitemdelegate.h:171
KFileItemDelegate::Comment
A simple comment that can be displayed to the user as is.
Definition: kfileitemdelegate.h:176
QChar
KFileItemDelegate::OctalPermissions
The permissions as an octal value, e.g. 0644.
Definition: kfileitemdelegate.h:166
KFileItem::isNull
bool isNull() const
Return true if default-constructed.
Definition: kfileitem.cpp:1714
KFileItemDelegate::setEditorData
virtual void setEditorData(QWidget *editor, const QModelIndex &index) const
Reimplemented from QAbstractItemDelegate.
Definition: kfileitemdelegate.cpp:1467
QX11Info::display
Display * display()
QFont
label
QString label(StandardShortcut id)
QStyle::pixelMetric
virtual int pixelMetric(PixelMetric metric, const QStyleOption *option, const QWidget *widget) const =0
QTextLine::naturalTextWidth
qreal naturalTextWidth() const
KDirModel::FileItemRole
returns the KFileItem for a given index
Definition: kdirmodel.h:137
KFileItemDelegate::setShadowColor
void setShadowColor(const QColor &color)
Sets the color used for drawing the text shadow.
Definition: kfileitemdelegate.cpp:1028
QSize::rwidth
int & rwidth()
KFileItemDelegate::setShadowBlur
void setShadowBlur(qreal radius)
Sets the blur radius for the text shadow.
Definition: kfileitemdelegate.cpp:1052
KFileItemDelegate::editorEvent
virtual bool editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex &index)
Reimplemented from QAbstractItemDelegate.
Definition: kfileitemdelegate.cpp:1455
KFileItemDelegate::Owner
The user name of the file owner, e.g. root.
Definition: kfileitemdelegate.h:167
KLocale::formatLong
QString formatLong(long num) const
QRect::translate
void translate(int dx, int dy)
QPainter::save
void save()
kfileitemdelegate.h
KImageIO::Mode
Mode
Possible image file access modes.
Definition: kimageio.h:53
QPixmap::fromImage
QPixmap fromImage(const QImage &image, QFlags< Qt::ImageConversionFlag > flags)
KDirModel::HasJobRole
returns whether or not there is a job on an item (file/directory)
Definition: kdirmodel.h:139
KFileItemDelegate::InformationList
QList< Information > InformationList
Definition: kfileitemdelegate.h:179
QRect::height
int height() const
QBrush
QRect::x
int x() const
kiconloader.h
KFileItem::comment
QString comment() const
A comment which can contain anything - even rich text.
Definition: kfileitem.cpp:1005
KFileItem::permissions
mode_t permissions() const
Returns the permissions of the file (stat.st_mode containing only permissions).
Definition: kfileitem.cpp:1551
QPoint
QFontMetrics
QPainter::rotate
void rotate(qreal angle)
KFileItemDelegate::paint
virtual void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
Paints the item indicated by index, using painter.
Definition: kfileitemdelegate.cpp:1245
QTextEdit::toPlainText
QString toPlainText() const
KFileItemDelegate::iconRect
QRect iconRect(const QStyleOptionViewItem &option, const QModelIndex &index) const
Returns the rectangle of the icon that is aligned inside the decoration rectangle.
Definition: kfileitemdelegate.cpp:1099
QPaintDevice::paintEngine
virtual QPaintEngine * paintEngine() const =0
Qt::Alignment
typedef Alignment
klocale.h
KFileItemDelegate::OwnerAndGroup
The user and group that owns the file, e.g. root:root.
Definition: kfileitemdelegate.h:168
KIconLoader::Desktop
QTextEdit::selectAll
void selectAll()
QTextLayout::beginLayout
void beginLayout()
QStyle::alignedRect
QRect alignedRect(Qt::LayoutDirection direction, QFlags< Qt::AlignmentFlag > alignment, const QSize &size, const QRect &rectangle)
QPoint::x
int x() const
QPoint::y
int y() const
KDirModel::ChildCountRole
returns the number of items in a directory, or ChildCountUnknown
Definition: kdirmodel.h:138
KIO::AnimationState::jobAnimationAngle
qreal jobAnimationAngle() const
Definition: delegateanimationhandler.cpp:166
KFileItemDelegate::Information
Information
This enum defines the additional information that can be displayed below item labels in icon views...
Definition: kfileitemdelegate.h:162
QTextCursor::movePosition
bool movePosition(MoveOperation operation, MoveMode mode, int n)
i18nc
QString i18nc(const char *ctxt, const char *text)
KFileItemDelegate::showToolTipWhenElided
bool showToolTipWhenElided() const
Returns whether a tooltip should be shown if the display role is elided containing the full display r...
KIO::CachedRendering::regular
QPixmap regular
Definition: delegateanimationhandler_p.h:49
KIO::AnimationState
Definition: delegateanimationhandler_p.h:60
QWidget::setGeometry
void setGeometry(int x, int y, int w, int h)
QSize::rheight
int & rheight()
KFileItemDelegate::setJobTransfersVisible
void setJobTransfersVisible(bool jobTransfersVisible)
Enable/Disable the displaying of an animated overlay that is shown for any destination urls (in the v...
Definition: kfileitemdelegate.cpp:1107
QPointF
KFileItemDelegate::setModelData
virtual void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
Reimplemented from QAbstractItemDelegate.
Definition: kfileitemdelegate.cpp:1498
QTextLine::setLineWidth
void setLineWidth(qreal width)
QObject::event
virtual bool event(QEvent *e)
KIO::AnimationState::setCachedRendering
void setCachedRendering(CachedRendering *rendering)
Definition: delegateanimationhandler_p.h:76
KIO::CachedRendering::hover
QPixmap hover
Definition: delegateanimationhandler_p.h:50
KFileItemDelegate::jobTransfersVisible
bool jobTransfersVisible() const
Returns whether or not the displaying of job transfers is enabled.
KIO::AnimationState::hasJobAnimation
bool hasJobAnimation() const
Definition: delegateanimationhandler.cpp:171
QTextOption::setWrapMode
void setWrapMode(WrapMode mode)
QPen::color
QColor color() const
QRect
QModelIndex::isValid
bool isValid() const
KStatefulBrush
kglobal.h
QWidget::setEnabled
void setEnabled(bool)
QString::number
QString number(int n, int base)
KFileItemDelegate::helpEvent
bool helpEvent(QHelpEvent *event, QAbstractItemView *view, const QStyleOptionViewItem &option, const QModelIndex &index)
Reimplemented from QAbstractItemDelegate.
Definition: kfileitemdelegate.cpp:1546
QTextLine::setPosition
void setPosition(const QPointF &pos)
QVariant::toInt
int toInt(bool *ok) const
QImage::fill
void fill(uint pixelValue)
KFileItemDelegate::setWrapMode
void setWrapMode(QTextOption::WrapMode wrapMode)
When the contents text needs to be wrapped, wrapMode strategy will be followed.
Definition: kfileitemdelegate.cpp:1088
KStringHandler::preProcessWrap
QString preProcessWrap(const QString &text)
QRect::top
int top() const
KFileItem::ModificationTime
Definition: kfileitem.h:58
KIconLoader::ActiveState
QStyleOptionViewItem
QObject
QStyle
i18ncp
QString i18ncp(const char *ctxt, const char *sing, const char *plur, const A1 &a1)
QPainter::setPen
void setPen(const QColor &color)
QTextLayout::createLine
QTextLine createLine()
QPainter::drawEllipse
void drawEllipse(const QRectF &rectangle)
QRect::setTop
void setTop(int y)
QRect::left
int left() const
QAbstractScrollArea::setHorizontalScrollBarPolicy
void setHorizontalScrollBarPolicy(Qt::ScrollBarPolicy)
QPainter::drawPixmap
void drawPixmap(const QRectF &target, const QPixmap &pixmap, const QRectF &source)
QSize::setWidth
void setWidth(int width)
QPainter
KFileItem::localPath
QString localPath() const
Returns the local path if isLocalFile() == true or the KIO item has a UDS_LOCAL_PATH atom...
Definition: kfileitem.cpp:602
KFileItem::linkDest
QString linkDest() const
Returns the link destination if isLink() == true.
Definition: kfileitem.cpp:568
QString::isEmpty
bool isEmpty() const
QImage::rect
QRect rect() const
QTextLayout
KFileItemDelegate::setShadowOffset
void setShadowOffset(const QPointF &offset)
Sets the horizontal and vertical offset for the text shadow.
Definition: kfileitemdelegate.cpp:1040
KUrl::pathOrUrl
QString pathOrUrl() const
KIcon
KFileItemDelegate::NoInformation
No additional information will be shown for items.
Definition: kfileitemdelegate.h:163
KLocale::formatByteSize
QString formatByteSize(double size) const
KFileItemDelegate::createEditor
virtual QWidget * createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
Reimplemented from QAbstractItemDelegate.
Definition: kfileitemdelegate.cpp:1439
KFileItem::mimeComment
QString mimeComment() const
Returns the user-readable string representing the type of this file, like "OpenDocument Text File"...
Definition: kfileitem.cpp:823
QPainter::setBrush
void setBrush(const QBrush &brush)
QString::endsWith
bool endsWith(const QString &s, Qt::CaseSensitivity cs) const
QRect::center
QPoint center() const
QAbstractItemDelegate::elidedText
QString elidedText(const QFontMetrics &fontMetrics, int width, Qt::TextElideMode mode, const QString &text)
QAbstractItemDelegate::closeEditor
void closeEditor(QWidget *editor, QAbstractItemDelegate::EndEditHint hint)
QIcon::addPixmap
void addPixmap(const QPixmap &pixmap, Mode mode, State state)
KIO::AnimationState::cachedRenderingFadeFrom
CachedRendering * cachedRenderingFadeFrom() const
Definition: delegateanimationhandler_p.h:82
KFileItemDelegate::wrapMode
QTextOption::WrapMode wrapMode() const
Returns the wrapping strategy followed to show text when it needs wrapping.
Definition: kfileitemdelegate.cpp:1094
KFileItemDelegate::eventFilter
virtual bool eventFilter(QObject *object, QEvent *event)
Reimplemented from QAbstractItemDelegate.
Definition: kfileitemdelegate.cpp:1630
KFileItem::isFile
bool isFile() const
Returns true if this item represents a file (and not a a directory)
Definition: kfileitem.cpp:1154
QString
KFileItem::group
QString group() const
Returns the group of the file.
Definition: kfileitem.cpp:712
QList
QColor
QTextLine::textStart
int textStart() const
KFileItem::size
KIO::filesize_t size() const
Returns the size of the file, if known.
Definition: kfileitem.cpp:610
QTextEdit::setTextCursor
void setTextCursor(const QTextCursor &cursor)
KFileItem::permissionsString
QString permissionsString() const
Returns the access permissions for the file as a string.
Definition: kfileitem.cpp:1403
QTextOption
KIO::AnimationState::fadeProgress
qreal fadeProgress() const
Definition: delegateanimationhandler.cpp:161
KFileItemDelegate::information
InformationList information
This property holds which additional information (if any) should be shown below items in icon views...
Definition: kfileitemdelegate.h:79
KIconLoader::iconEffect
KIconEffect * iconEffect() const
QVariant::userType
int userType() const
QPixmap
QRect::adjusted
QRect adjusted(int dx1, int dy1, int dx2, int dy2) const
KDirModel::Name
Definition: kdirmodel.h:120
QStyleOptionFocusRect
KFileItemDelegate::FriendlyMimeType
The descriptive name for the mime type, e.g. HTML Document.
Definition: kfileitemdelegate.h:173
QKeyEvent::key
int key() const
KFileItem::isLink
bool isLink() const
Returns true if this item represents a link in the UNIX sense of a link.
Definition: kfileitem.cpp:1567
QPixmap::isNull
bool isNull() const
QSize
QLatin1Char
imagefilter_p.h
QImage
kstringhandler.h
QFontMetrics::leading
int leading() const
QAbstractItemDelegate::helpEvent
bool helpEvent(QHelpEvent *event, QAbstractItemView *view, const QStyleOptionViewItem &option, const QModelIndex &index)
Top
KGlobal::locale
KLocale * locale()
QPainter::restore
void restore()
KFileItemDelegate::CreationTime
The date and time the file/folder was created.
Definition: kfileitemdelegate.h:169
QKeyEvent
QRect::setRight
void setRight(int x)
kdirmodel.h
QRect::width
int width() const
QPainter::drawImage
void drawImage(const QRectF &target, const QImage &image, const QRectF &source, QFlags< Qt::ImageConversionFlag > flags)
KFileItemDelegate::shadowOffset
QPointF shadowOffset() const
Returns the offset used for the text shadow.
QString::mid
QString mid(int position, int n) const
QFrame::frameWidth
frameWidth
QTextLine
KIO::DelegateAnimationHandler
Definition: delegateanimationhandler_p.h:106
QModelIndex::data
QVariant data(int role) const
QTextLine::textLength
int textLength() const
KFileItemDelegate::MimeType
The mime type for the item, e.g. text/html.
Definition: kfileitemdelegate.h:172
QApplication::style
QStyle * style()
QLatin1String
QTextLayout::lineAt
QTextLine lineAt(int i) const
QTextLayout::font
QFont font() const
KFileItemDelegate::maximumSize
QSize maximumSize() const
Returns the maximum size for KFileItemDelegate::sizeHint().
QTextLayout::text
QString text() const
ktextedit.h
QApplication::activePopupWidget
QWidget * activePopupWidget()
KFileItemDelegate::ModificationTime
The date and time the file/folder was last modified.
Definition: kfileitemdelegate.h:170
QStyle::visualRect
QRect visualRect(Qt::LayoutDirection direction, const QRect &boundingRectangle, const QRect &logicalRectangle)
QTextOption::setTextDirection
void setTextDirection(Qt::LayoutDirection direction)
KIconEffect::hasEffect
bool hasEffect(int group, int state) const
KFileItem::CreationTime
Definition: kfileitem.h:60
KIO::CachedRendering::checkValidity
bool checkValidity(QStyle::State current) const
Definition: delegateanimationhandler_p.h:46
QSize::height
int height() const
KFileItemDelegate
KFileItemDelegate is intended to be used to provide a KDE file system view, when using one of the sta...
Definition: kfileitemdelegate.h:67
QRect::adjust
void adjust(int dx1, int dy1, int dx2, int dy2)
QRect::bottom
int bottom() const
QRect::topLeft
QPoint topLeft() const
QModelIndex::column
int column() const
QString::length
int length() const
QString::reserve
void reserve(int size)
QVariant::toBool
bool toBool() const
QPainter::translate
void translate(const QPointF &offset)
KIO::AnimationState::cachedRendering
CachedRendering * cachedRendering() const
Definition: delegateanimationhandler_p.h:74
KIO::AnimationState::setCachedRenderingFadeFrom
void setCachedRenderingFadeFrom(CachedRendering *rendering)
Definition: delegateanimationhandler_p.h:84
QStyle::drawPrimitive
virtual void drawPrimitive(PrimitiveElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget) const =0
QTextLayout::setTextOption
void setTextOption(const QTextOption &option)
KFileItem::timeString
QString timeString(FileTimes which=ModificationTime) const
Requests the modification, access or creation time as a string, depending on which.
Definition: kfileitem.cpp:1415
QAbstractItemModel
QAbstractItemModel::setData
virtual bool setData(const QModelIndex &index, const QVariant &value, int role)
QTextLayout::draw
void draw(QPainter *p, const QPointF &pos, const QVector< FormatRange > &selections, const QRectF &clip) const
QPen
KFileItemDelegate::setShowToolTipWhenElided
void setShowToolTipWhenElided(bool showToolTip)
Sets whether a tooltip should be shown if the display role is elided containing the full display role...
Definition: kfileitemdelegate.cpp:1076
QColor::setAlphaF
void setAlphaF(qreal alpha)
QVariant::isValid
bool isValid() const
KFileItemDelegate::KFileItemDelegate
KFileItemDelegate(QObject *parent=0)
Constructs a new KFileItemDelegate.
Definition: kfileitemdelegate.cpp:910
KFileItemDelegate::Size
The file size for files, and the number of items for folders.
Definition: kfileitemdelegate.h:164
QVariant::toDouble
double toDouble(bool *ok) const
QPaintEngine::hasFeature
bool hasFeature(QFlags< QPaintEngine::PaintEngineFeature > feature) const
KFileItemDelegate::Permissions
A UNIX permissions string, e.g. -rwxr-xr-x.
Definition: kfileitemdelegate.h:165
QAbstractItemDelegate::commitData
void commitData(QWidget *editor)
KIconEffect::apply
QImage apply(const QImage &src, int group, int state) const
QStyle::visualAlignment
Qt::Alignment visualAlignment(Qt::LayoutDirection direction, QFlags< Qt::AlignmentFlag > alignment)
QStyleOptionViewItemV4
QPixmap::toImage
QImage toImage() const
KGlobalSettings::graphicEffectsLevel
static GraphicEffects graphicEffectsLevel()
KFileItem::isMimeTypeKnown
bool isMimeTypeKnown() const
Definition: kfileitem.cpp:804
KFileItemDelegate::shadowColor
QColor shadowColor() const
Returns the color used for the text shadow.
QRect::moveCenter
void moveCenter(const QPoint &position)
KLocale::formatNumber
QString formatNumber(double num, int precision=-1) const
KFileItemDelegate::setShowInformation
void setShowInformation(const InformationList &list)
Sets the list of information lines that are shown below the icon label in list views.
Definition: kfileitemdelegate.cpp:1007
KFileItemDelegate::shadowBlur
qreal shadowBlur() const
Returns the blur radius for the text shadow.
QTextLayout::setText
void setText(const QString &string)
QTextLayout::setPosition
void setPosition(const QPointF &p)
QVariant::type
Type type() const
kicon.h
KIO::ImageFilter::shadowBlur
static void shadowBlur(QImage &image, float radius, const QColor &color)
Definition: imagefilter.cpp:253
KFileItemDelegate::~KFileItemDelegate
virtual ~KFileItemDelegate()
Destroys the item delegate.
Definition: kfileitemdelegate.cpp:935
QObject::parent
QObject * parent() const
QHelpEvent
KIconEffect
QPainter::begin
bool begin(QPaintDevice *device)
KIO::CachedRendering
Definition: delegateanimationhandler_p.h:40
QTextOption::setAlignment
void setAlignment(QFlags< Qt::AlignmentFlag > alignment)
QPainter::pen
const QPen & pen() const
QPixmap::rect
QRect rect() const
QVariant::toString
QString toString() const
QAbstractScrollArea::setVerticalScrollBarPolicy
void setVerticalScrollBarPolicy(Qt::ScrollBarPolicy)
KDirModel::Size
Definition: kdirmodel.h:121
QRect::setLeft
void setLeft(int x)
QTextEdit::setAlignment
void setAlignment(QFlags< Qt::AlignmentFlag > a)
QTextEdit::insertPlainText
void insertPlainText(const QString &text)
kcolorscheme.h
KGlobalSettings::SimpleAnimationEffects
kfileitem.h
QTextEdit::setAcceptRichText
void setAcceptRichText(bool accept)
KFileItem::url
KUrl url() const
Returns the url of the file.
Definition: kfileitem.cpp:1543
QTextEdit::textCursor
QTextCursor textCursor() const
QTextLayout::endLayout
void endLayout()
QRegion
KFileItem
A KFileItem is a generic class to handle a file, local or remote.
Definition: kfileitem.h:45
QIcon
KIO::AnimationState::takeCachedRendering
CachedRendering * takeCachedRendering()
Definition: delegateanimationhandler_p.h:80
KTextEdit
kiconeffect.h
KFileItem::AccessTime
Definition: kfileitem.h:59
KRecentDirs::list
QStringList list(const QString &fileClass)
Returns a list of directories associated with this file-class.
Definition: krecentdirs.cpp:60
QVariant
QTextLayout::lineCount
int lineCount() const
QAbstractItemDelegate
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:24:53 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KIO

Skip menu "KIO"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • 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
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • 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