Qt 4.8
Public Functions | Public Variables | List of all members
QFontFamilyDelegate Class Reference
Inheritance diagram for QFontFamilyDelegate:
QAbstractItemDelegate QObject

Public Functions

void paint (QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
 This pure abstract function must be reimplemented if you want to provide custom rendering. More...
 
 QFontFamilyDelegate (QObject *parent)
 
QSize sizeHint (const QStyleOptionViewItem &option, const QModelIndex &index) const
 This pure abstract function must be reimplemented if you want to provide custom rendering. More...
 
- Public Functions inherited from QAbstractItemDelegate
virtual QWidgetcreateEditor (QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
 Returns the editor to be used for editing the data item with the given index. More...
 
virtual bool editorEvent (QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex &index)
 When editing of an item starts, this function is called with the event that triggered the editing, the model, the index of the item, and the option used for rendering the item. More...
 
 QAbstractItemDelegate (QObject *parent=0)
 Creates a new abstract item delegate with the given parent. More...
 
virtual void setEditorData (QWidget *editor, const QModelIndex &index) const
 Sets the contents of the given editor to the data for the item at the given index. More...
 
virtual void setModelData (QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
 Sets the data for the item at the given index in the model to the contents of the given editor. More...
 
virtual void updateEditorGeometry (QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const
 Updates the geometry of the editor for the item with the given index, according to the rectangle specified in the option. More...
 
virtual ~QAbstractItemDelegate ()
 Destroys the abstract item delegate. More...
 
- Public Functions inherited from QObject
bool blockSignals (bool b)
 If block is true, signals emitted by this object are blocked (i.e., emitting a signal will not invoke anything connected to it). More...
 
const QObjectListchildren () const
 Returns a list of child objects. More...
 
bool connect (const QObject *sender, const char *signal, const char *member, Qt::ConnectionType type=Qt::AutoConnection) const
 
bool disconnect (const char *signal=0, const QObject *receiver=0, const char *member=0)
 
bool disconnect (const QObject *receiver, const char *member=0)
 
void dumpObjectInfo ()
 Dumps information about signal connections, etc. More...
 
void dumpObjectTree ()
 Dumps a tree of children to the debug output. More...
 
QList< QByteArraydynamicPropertyNames () const
 Returns the names of all properties that were dynamically added to the object using setProperty(). More...
 
virtual bool event (QEvent *)
 This virtual function receives events to an object and should return true if the event e was recognized and processed. More...
 
virtual bool eventFilter (QObject *, QEvent *)
 Filters events if this object has been installed as an event filter for the watched object. More...
 
template<typename T >
findChild (const QString &aName=QString()) const
 Returns the child of this object that can be cast into type T and that is called name, or 0 if there is no such object. More...
 
template<typename T >
QList< T > findChildren (const QString &aName=QString()) const
 Returns all children of this object with the given name that can be cast to type T, or an empty list if there are no such objects. More...
 
template<typename T >
QList< T > findChildren (const QRegExp &re) const
 
bool inherits (const char *classname) const
 Returns true if this object is an instance of a class that inherits className or a QObject subclass that inherits className; otherwise returns false. More...
 
void installEventFilter (QObject *)
 Installs an event filter filterObj on this object. More...
 
bool isWidgetType () const
 Returns true if the object is a widget; otherwise returns false. More...
 
void killTimer (int id)
 Kills the timer with timer identifier, id. More...
 
virtual const QMetaObjectmetaObject () const
 Returns a pointer to the meta-object of this object. More...
 
void moveToThread (QThread *thread)
 Changes the thread affinity for this object and its children. More...
 
QString objectName () const
 
QObjectparent () const
 Returns a pointer to the parent object. More...
 
QVariant property (const char *name) const
 Returns the value of the object's name property. More...
 
Q_INVOKABLE QObject (QObject *parent=0)
 Constructs an object with parent object parent. More...
 
void removeEventFilter (QObject *)
 Removes an event filter object obj from this object. More...
 
void setObjectName (const QString &name)
 
void setParent (QObject *)
 Makes the object a child of parent. More...
 
bool setProperty (const char *name, const QVariant &value)
 Sets the value of the object's name property to value. More...
 
void setUserData (uint id, QObjectUserData *data)
 
bool signalsBlocked () const
 Returns true if signals are blocked; otherwise returns false. More...
 
int startTimer (int interval)
 Starts a timer and returns a timer identifier, or returns zero if it could not start a timer. More...
 
QThreadthread () const
 Returns the thread in which the object lives. More...
 
QObjectUserDatauserData (uint id) const
 
virtual ~QObject ()
 Destroys the object, deleting all its child objects. More...
 

Public Variables

QIcon bitmap
 
QIcon truetype
 
QFontDatabase::WritingSystem writingSystem
 

Additional Inherited Members

- Public Types inherited from QAbstractItemDelegate
enum  EndEditHint {
  NoHint, EditNextItem, EditPreviousItem, SubmitModelCache,
  RevertModelCache
}
 This enum describes the different hints that the delegate can give to the model and view components to make editing data in a model a comfortable experience for the user. More...
 
- Public Slots inherited from QAbstractItemDelegate
bool helpEvent (QHelpEvent *event, QAbstractItemView *view, const QStyleOptionViewItem &option, const QModelIndex &index)
 Whenever a help event occurs, this function is called with the event view option and the index that corresponds to the item where the event occurs. More...
 
- Public Slots inherited from QObject
void deleteLater ()
 Schedules this object for deletion. More...
 
- Signals inherited from QAbstractItemDelegate
void closeEditor (QWidget *editor, QAbstractItemDelegate::EndEditHint hint=NoHint)
 This signal is emitted when the user has finished editing an item using the specified editor. More...
 
void commitData (QWidget *editor)
 This signal must be emitted when the editor widget has completed editing the data, and wants to write it back into the model. More...
 
void sizeHintChanged (const QModelIndex &)
 This signal must be emitted when the sizeHint() of index changed. More...
 
- Signals inherited from QObject
void destroyed (QObject *=0)
 This signal is emitted immediately before the object obj is destroyed, and can not be blocked. More...
 
- Static Public Functions inherited from QAbstractItemDelegate
static QString elidedText (const QFontMetrics &fontMetrics, int width, Qt::TextElideMode mode, const QString &text)
 Use QFontMetrics::elidedText() instead. More...
 
- Static Public Functions inherited from QObject
static bool connect (const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
 Creates a connection of the given type from the signal in the sender object to the method in the receiver object. More...
 
static bool connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type=Qt::AutoConnection)
 
static bool disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *member)
 Disconnects signal in object sender from method in object receiver. More...
 
static bool disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &member)
 
static uint registerUserData ()
 
static QString tr (const char *sourceText, const char *comment=0, int n=-1)
 
static QString trUtf8 (const char *sourceText, const char *comment=0, int n=-1)
 
- Static Public Variables inherited from QObject
static const QMetaObject staticMetaObject
 This variable stores the meta-object for the class. More...
 
- Protected Functions inherited from QAbstractItemDelegate
 QAbstractItemDelegate (QObjectPrivate &, QObject *parent=0)
 Creates a new abstract item delegate with the given parent. More...
 
- Protected Functions inherited from QObject
virtual void childEvent (QChildEvent *)
 This event handler can be reimplemented in a subclass to receive child events. More...
 
virtual void connectNotify (const char *signal)
 This virtual function is called when something has been connected to signal in this object. More...
 
virtual void customEvent (QEvent *)
 This event handler can be reimplemented in a subclass to receive custom events. More...
 
virtual void disconnectNotify (const char *signal)
 This virtual function is called when something has been disconnected from signal in this object. More...
 
 QObject (QObjectPrivate &dd, QObject *parent=0)
 
int receivers (const char *signal) const
 Returns the number of receivers connected to the signal. More...
 
QObjectsender () const
 Returns a pointer to the object that sent the signal, if called in a slot activated by a signal; otherwise it returns 0. More...
 
int senderSignalIndex () const
 
virtual void timerEvent (QTimerEvent *)
 This event handler can be reimplemented in a subclass to receive timer events for the object. More...
 
- Protected Variables inherited from QObject
QScopedPointer< QObjectDatad_ptr
 
- Static Protected Variables inherited from QObject
static const QMetaObject staticQtMetaObject
 

Detailed Description

Definition at line 101 of file qfontcombobox.cpp.

Constructors and Destructors

◆ QFontFamilyDelegate()

QFontFamilyDelegate::QFontFamilyDelegate ( QObject parent)
explicit

Definition at line 120 of file qfontcombobox.cpp.

121  : QAbstractItemDelegate(parent)
122 {
123  truetype = QIcon(QLatin1String(":/trolltech/styles/commonstyle/images/fonttruetype-16.png"));
124  bitmap = QIcon(QLatin1String(":/trolltech/styles/commonstyle/images/fontbitmap-16.png"));
126 }
QAbstractItemDelegate(QObject *parent=0)
Creates a new abstract item delegate with the given parent.
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
QFontDatabase::WritingSystem writingSystem
The QIcon class provides scalable icons in different modes and states.
Definition: qicon.h:60

Functions

◆ paint()

void QFontFamilyDelegate::paint ( QPainter painter,
const QStyleOptionViewItem option,
const QModelIndex index 
) const
virtual

This pure abstract function must be reimplemented if you want to provide custom rendering.

Use the painter and style option to render the item specified by the item index.

If you reimplement this you must also reimplement sizeHint().

Implements QAbstractItemDelegate.

Definition at line 128 of file qfontcombobox.cpp.

131 {
133  QFont font(option.font);
134  font.setPointSize(QFontInfo(font).pointSize() * 3 / 2);
135  QFont font2 = font;
136  font2.setFamily(text);
137 
138  bool hasLatin;
139  QFontDatabase::WritingSystem system = writingSystemForFont(font2, &hasLatin);
140  if (hasLatin)
141  font = font2;
142 
143  QRect r = option.rect;
144 
145  if (option.state & QStyle::State_Selected) {
146  painter->save();
147  painter->setBrush(option.palette.highlight());
148  painter->setPen(Qt::NoPen);
149  painter->drawRect(option.rect);
150  painter->setPen(QPen(option.palette.highlightedText(), 0));
151  }
152 
153  const QIcon *icon = &bitmap;
154  if (QFontDatabase().isSmoothlyScalable(text)) {
155  icon = &truetype;
156  }
157  QSize actualSize = icon->actualSize(r.size());
158 
159  icon->paint(painter, r, Qt::AlignLeft|Qt::AlignVCenter);
160  if (option.direction == Qt::RightToLeft)
161  r.setRight(r.right() - actualSize.width() - 4);
162  else
163  r.setLeft(r.left() + actualSize.width() + 4);
164 
165  QFont old = painter->font();
166  painter->setFont(font);
167 
168  // If the ascent of the font is larger than the height of the rect,
169  // we will clip the text, so it's better to align the tight bounding rect in this case
170  // This is specifically for fonts where the ascent is very large compared to
171  // the descent, like certain of the Stix family.
172  QFontMetricsF fontMetrics(font);
173  if (fontMetrics.ascent() > r.height()) {
174  QRectF tbr = fontMetrics.tightBoundingRect(text);
175  painter->drawText(r.x(), r.y() + (r.height() + tbr.height()) / 2.0, text);
176  } else {
178  }
179 
181  system = writingSystem;
182 
183  if (system != QFontDatabase::Any) {
184  int w = painter->fontMetrics().width(text + QLatin1String(" "));
185  painter->setFont(font2);
186  QString sample = QFontDatabase().writingSystemSample(system);
187  if (option.direction == Qt::RightToLeft)
188  r.setRight(r.right() - w);
189  else
190  r.setLeft(r.left() + w);
192  }
193  painter->setFont(old);
194 
195  if (option.state & QStyle::State_Selected)
196  painter->restore();
197 
198 }
const QBrush & highlight() const
Returns the highlight brush of the current color group.
Definition: qpalette.h:140
int width(const QString &, int len=-1) const
Returns the width in pixels of the first len characters of text.
QFont font
the font used for the item
Definition: qstyleoption.h:552
QVariant data(int role=Qt::DisplayRole) const
Returns the data for the given role for the item referred to by the index.
QStyle::State state
the style flags that are used when drawing the control
Definition: qstyleoption.h:88
void restore()
Restores the current painter state (pops a saved state off the stack).
Definition: qpainter.cpp:1620
QString toString() const
Returns the variant as a QString if the variant has type() String , Bool , ByteArray ...
Definition: qvariant.cpp:2270
int left() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:240
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
static QFontDatabase::WritingSystem writingSystemForFont(const QFont &font, bool *hasLatin)
int height() const
Returns the height of the rectangle.
Definition: qrect.h:306
The QString class provides a Unicode character string.
Definition: qstring.h:83
The QPen class defines how a QPainter should draw lines and outlines of shapes.
Definition: qpen.h:64
void save()
Saves the current painter state (pushes the state onto a stack).
Definition: qpainter.cpp:1590
void setFamily(const QString &)
Sets the family name of the font.
Definition: qfont.cpp:924
int width() const
Returns the width.
Definition: qsize.h:126
void drawText(const QPointF &p, const QString &s)
Draws the given text with the currently defined text direction, beginning at the given position...
Definition: qpainter.cpp:6231
QFontMetrics fontMetrics() const
Returns the font metrics for the painter if the painter is active.
Definition: qpainter.cpp:2077
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
The QFontDatabase class provides information about the fonts available in the underlying window syste...
Definition: qfontdatabase.h:66
const QFont & font() const
Returns the currently set font used for drawing text.
Definition: qpainter.cpp:4312
qreal height() const
Returns the height of the rectangle.
Definition: qrect.h:710
QSize size() const
Returns the size of the rectangle.
Definition: qrect.h:309
void setRight(int pos)
Sets the right edge of the rectangle to the given x coordinate.
Definition: qrect.h:264
The QFontInfo class provides general information about fonts.
Definition: qfontinfo.h:54
static QString writingSystemSample(WritingSystem writingSystem)
Returns a string with sample characters from writingSystem.
QPalette palette
the palette that should be used when painting the control
Definition: qstyleoption.h:92
QFontDatabase::WritingSystem writingSystem
int right() const
Returns the x-coordinate of the rectangle&#39;s right edge.
Definition: qrect.h:246
void setLeft(int pos)
Sets the left edge of the rectangle to the given x coordinate.
Definition: qrect.h:258
The QFont class specifies a font used for drawing text.
Definition: qfont.h:64
int y() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:255
const QBrush & highlightedText() const
Returns the highlighted text brush of the current color group.
Definition: qpalette.h:141
QSize actualSize(const QSize &size, Mode mode=Normal, State state=Off) const
Returns the actual size of the icon for the requested size, mode, and state.
Definition: qicon.cpp:730
int x() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:252
void setBrush(const QBrush &brush)
Sets the painter&#39;s brush to the given brush.
Definition: qpainter.cpp:4171
void setPen(const QColor &color)
Sets the painter&#39;s pen to have style Qt::SolidLine, width 0 and the specified color.
Definition: qpainter.cpp:4047
Qt::LayoutDirection direction
the text layout direction that should be used when drawing text in the control
Definition: qstyleoption.h:89
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
void drawRect(const QRectF &rect)
Draws the current rectangle with the current pen and brush.
Definition: qpainter.h:650
The QFontMetricsF class provides font metrics information.
Definition: qfontmetrics.h:145
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
void setFont(const QFont &f)
Sets the painter&#39;s font to the given font.
Definition: qpainter.cpp:4288
bool isSmoothlyScalable(const QString &family, const QString &style=QString()) const
Returns true if the font that has family family and style style is smoothly scalable; otherwise retur...
QRect rect
the area that should be used for various calculations and painting
Definition: qstyleoption.h:90
static float pointSize(const QFontDef &fd, int dpi)
Definition: qfont_win.cpp:90
#define text
Definition: qobjectdefs.h:80
void paint(QPainter *painter, const QRect &rect, Qt::Alignment alignment=Qt::AlignCenter, Mode mode=Normal, State state=Off) const
Uses the painter to paint the icon with specified alignment, required mode, and state into the rectan...
Definition: qicon.cpp:744
The QIcon class provides scalable icons in different modes and states.
Definition: qicon.h:60

◆ sizeHint()

QSize QFontFamilyDelegate::sizeHint ( const QStyleOptionViewItem option,
const QModelIndex index 
) const
virtual

This pure abstract function must be reimplemented if you want to provide custom rendering.

The options are specified by option and the model item by index.

If you reimplement this you must also reimplement paint().

Implements QAbstractItemDelegate.

Definition at line 200 of file qfontcombobox.cpp.

202 {
204  QFont font(option.font);
205 // font.setFamily(text);
206  font.setPointSize(QFontInfo(font).pointSize() * 3/2);
207  QFontMetrics fontMetrics(font);
208  return QSize(fontMetrics.width(text), fontMetrics.height());
209 }
QFont font
the font used for the item
Definition: qstyleoption.h:552
The QFontMetrics class provides font metrics information.
Definition: qfontmetrics.h:65
QVariant data(int role=Qt::DisplayRole) const
Returns the data for the given role for the item referred to by the index.
QString toString() const
Returns the variant as a QString if the variant has type() String , Bool , ByteArray ...
Definition: qvariant.cpp:2270
The QString class provides a Unicode character string.
Definition: qstring.h:83
The QFontInfo class provides general information about fonts.
Definition: qfontinfo.h:54
The QFont class specifies a font used for drawing text.
Definition: qfont.h:64
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
static float pointSize(const QFontDef &fd, int dpi)
Definition: qfont_win.cpp:90
#define text
Definition: qobjectdefs.h:80

Properties

◆ bitmap

QIcon QFontFamilyDelegate::bitmap

Definition at line 116 of file qfontcombobox.cpp.

Referenced by paint(), and QFontFamilyDelegate().

◆ truetype

QIcon QFontFamilyDelegate::truetype

Definition at line 115 of file qfontcombobox.cpp.

Referenced by paint(), and QFontFamilyDelegate().

◆ writingSystem

QFontDatabase::WritingSystem QFontFamilyDelegate::writingSystem

The documentation for this class was generated from the following file: