Vidalia  0.2.17
StatusEventItemDelegate.h
Go to the documentation of this file.
00001 /*
00002 **  This file is part of Vidalia, and is subject to the license terms in the
00003 **  LICENSE file, found in the top level directory of this distribution. If you
00004 **  did not receive the LICENSE file with this file, you may obtain it from the
00005 **  Vidalia source package distributed by the Vidalia Project at
00006 **  http://www.torproject.org/projects/vidalia.html. No part of Vidalia, 
00007 **  including this file, may be copied, modified, propagated, or distributed 
00008 **  except according to the terms described in the LICENSE file.
00009 */
00010 
00011 /*
00012 ** \file StatusEventItemDelegate.h
00013 ** \brief Handles custom painting of items in a StatusEventWidget
00014 */
00015 
00016 #ifndef _STATUSEVENTITEMDELEGATE_H
00017 #define _STATUSEVENTITEMDELEGATE_H
00018 
00019 #include <QItemDelegate>
00020 #include <QPixmap>
00021 
00022 class QStringList;
00023 
00024 class StatusEventItemDelegate : public QItemDelegate
00025 {
00026   Q_OBJECT
00027 
00028 public:
00029   /** Default constructor.
00030    */
00031   StatusEventItemDelegate(QObject *parent = 0);
00032 
00033   /** Paints a status event item for <b>index</b> using the given paint
00034    * device <b>painter</b> and current style <b>option</b>s.
00035    */
00036   virtual void paint(QPainter *painter,
00037                      const QStyleOptionViewItem &option,
00038                      const QModelIndex &index) const;
00039 
00040   /** Returns a QSize representing the desired dimensions needed to paint
00041    * a status event item for <b>index</b> using the specified style
00042    * <b>option</b>s.
00043    */
00044   virtual QSize sizeHint(const QStyleOptionViewItem &option,
00045                          const QModelIndex &index) const;
00046 
00047 protected:
00048   /** Splits <b>text</b> at <b>maxLineWidth</b> pixels computed using the
00049    * font dimensions given by <b>fontMetrics</b> and returns a QStringList
00050    * containing at most <b>maxLines</b> of text. If the number of wrapped
00051    * lines is greater than or equal to <b>maxLines</b>, the last line of 
00052    * text will be elided. If <b>maxLines</b> is less than or equal to 0, no
00053    * eliding will be done. If <b>textHeight</b> is not NULL, it will be set
00054    * to the height (in pixels) required to display the returned wrapped
00055    * lines.
00056    */
00057   static QStringList layoutText(const QString &text,
00058                                 const QFont &fontMetrics,
00059                                 int maxLineWidth,
00060                                 int maxLines = -1,
00061                                 int *textHeight = 0);
00062 
00063 private:
00064   /** Small icon image drawn in the upper-right (or upper-left in RTL
00065    * layouts) for status events that have associated help URLs. */
00066   QPixmap _helpIcon;
00067 };
00068 
00069 #endif
00070