Vidalia 0.3.1
StatusEventItemDelegate.h
Go to the documentation of this file.
1/*
2** This file is part of Vidalia, and is subject to the license terms in the
3** LICENSE file, found in the top level directory of this distribution. If you
4** did not receive the LICENSE file with this file, you may obtain it from the
5** Vidalia source package distributed by the Vidalia Project at
6** http://www.torproject.org/projects/vidalia.html. No part of Vidalia,
7** including this file, may be copied, modified, propagated, or distributed
8** except according to the terms described in the LICENSE file.
9*/
10
11/*
12** \file StatusEventItemDelegate.h
13** \brief Handles custom painting of items in a StatusEventWidget
14*/
15
16#ifndef _STATUSEVENTITEMDELEGATE_H
17#define _STATUSEVENTITEMDELEGATE_H
18
19#include <QItemDelegate>
20#include <QPixmap>
21
22class QStringList;
23
24class StatusEventItemDelegate : public QItemDelegate
25{
26 Q_OBJECT
27
28public:
29 /** Default constructor.
30 */
31 StatusEventItemDelegate(QObject *parent = 0);
32
33 /** Paints a status event item for <b>index</b> using the given paint
34 * device <b>painter</b> and current style <b>option</b>s.
35 */
36 virtual void paint(QPainter *painter,
37 const QStyleOptionViewItem &option,
38 const QModelIndex &index) const;
39
40 /** Returns a QSize representing the desired dimensions needed to paint
41 * a status event item for <b>index</b> using the specified style
42 * <b>option</b>s.
43 */
44 virtual QSize sizeHint(const QStyleOptionViewItem &option,
45 const QModelIndex &index) const;
46
47protected:
48 /** Splits <b>text</b> at <b>maxLineWidth</b> pixels computed using the
49 * font dimensions given by <b>fontMetrics</b> and returns a QStringList
50 * containing at most <b>maxLines</b> of text. If the number of wrapped
51 * lines is greater than or equal to <b>maxLines</b>, the last line of
52 * text will be elided. If <b>maxLines</b> is less than or equal to 0, no
53 * eliding will be done. If <b>textHeight</b> is not NULL, it will be set
54 * to the height (in pixels) required to display the returned wrapped
55 * lines.
56 */
57 static QStringList layoutText(const QString &text,
58 const QFont &fontMetrics,
59 int maxLineWidth,
60 int maxLines = -1,
61 int *textHeight = 0);
62
63private:
64 /** Small icon image drawn in the upper-right (or upper-left in RTL
65 * layouts) for status events that have associated help URLs. */
66 QPixmap _helpIcon;
67};
68
69#endif
70
virtual void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
static QStringList layoutText(const QString &text, const QFont &fontMetrics, int maxLineWidth, int maxLines=-1, int *textHeight=0)
virtual QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
StatusEventItemDelegate(QObject *parent=0)