Qt 4.8
Public Functions | Public Variables | List of all members
QCommonStylePrivate Class Reference

#include <qcommonstyle_p.h>

Inheritance diagram for QCommonStylePrivate:
QStylePrivate QObjectPrivate QObjectData QMotifStylePrivate QProxyStylePrivate QWindowsStylePrivate QCleanlooksStylePrivate QPlastiqueStylePrivate QStyleSheetStylePrivate QWindowsCEStylePrivate QWindowsMobileStylePrivate QWindowsXPStylePrivate QGtkStylePrivate QWindowsVistaStylePrivate

Public Functions

bool isViewItemCached (const QStyleOptionViewItemV4 &option) const
 
 QCommonStylePrivate ()
 
void tabLayout (const QStyleOptionTabV3 *opt, const QWidget *widget, QRect *textRect, QRect *pixmapRect) const
 
void viewItemDrawText (QPainter *p, const QStyleOptionViewItemV4 *option, const QRect &rect) const
 
void viewItemLayout (const QStyleOptionViewItemV4 *opt, QRect *checkRect, QRect *pixmapRect, QRect *textRect, bool sizehint) const
 Set sizehint to false to layout the elements inside opt->rect. More...
 
QSize viewItemSize (const QStyleOptionViewItemV4 *option, int role) const
 
 ~QCommonStylePrivate ()
 
- Public Functions inherited from QStylePrivate
 QStylePrivate ()
 
- Public Functions inherited from QObjectPrivate
void _q_reregisterTimers (void *pointer)
 
void addConnection (int signal, Connection *c)
 
void cleanConnectionLists ()
 
void connectNotify (const char *signal)
 
void deleteChildren ()
 
void disconnectNotify (const char *signal)
 
bool isSender (const QObject *receiver, const char *signal) const
 
bool isSignalConnected (uint signalIdx) const
 Returns true if the signal with index signal_index from object sender is connected. More...
 
void moveToThread_helper ()
 
 QObjectPrivate (int version=QObjectPrivateVersion)
 
QObjectList receiverList (const char *signal) const
 
QObjectList senderList () const
 
void setParent_helper (QObject *)
 
void setThreadData_helper (QThreadData *currentData, QThreadData *targetData)
 
int signalIndex (const char *signalName) const
 Returns the signal index used in the internal connectionLists vector. More...
 
virtual ~QObjectPrivate ()
 
- Public Functions inherited from QObjectData
virtual ~QObjectData ()=0
 

Public Variables

QStyleOptionViewItemV4cachedOption
 
QRect checkRect
 
QRect decorationRect
 
QRect displayRect
 
QIcon tabBarcloseButtonIcon
 
- Public Variables inherited from QStylePrivate
int layoutSpacingIndex
 
QStyleproxyStyle
 
- Public Variables inherited from QObjectPrivate
union {
   QObject *   currentChildBeingDeleted
 
   QAbstractDeclarativeData *   declarativeData
 
}; 
 
quint32 connectedSignals [2]
 
QObjectConnectionListVectorconnectionLists
 
SendercurrentSender
 
QList< QPointer< QObject > > eventFilters
 
ExtraDataextraData
 
QString objectName
 
Connectionsenders
 
QAtomicPointer< QtSharedPointer::ExternalRefCountData > sharedRefcount
 
QThreadDatathreadData
 
void * unused
 
- Public Variables inherited from QObjectData
uint blockSig: 1
 
QObjectList children
 
uint hasGuards: 1
 
uint inEventHandler: 1
 
uint inThreadChangeEvent: 1
 
uint isWidget: 1
 
QMetaObjectmetaObject
 
uint ownObjectName: 1
 
QObjectparent
 
uint pendTimer: 1
 
int postedEvents
 
QObjectq_ptr
 
uint receiveChildEvents: 1
 
uint sendChildEvents: 1
 
uint unused: 22
 
uint wasDeleted: 1
 

Additional Inherited Members

- Public Types inherited from QObjectPrivate
typedef void(* StaticMetaCallFunction) (QObject *, QMetaObject::Call, int, void **)
 
- Static Public Functions inherited from QObjectPrivate
static void clearGuards (QObject *)
 
static QObjectPrivateget (QObject *o)
 
static void resetCurrentSender (QObject *receiver, Sender *currentSender, Sender *previousSender)
 
static SendersetCurrentSender (QObject *receiver, Sender *sender)
 
static void signalSignature (const QMetaMethod &signal, QVarLengthArray< char > *result)
 

Detailed Description

Definition at line 66 of file qcommonstyle_p.h.

Constructors and Destructors

◆ QCommonStylePrivate()

QCommonStylePrivate::QCommonStylePrivate ( )
inline

Definition at line 70 of file qcommonstyle_p.h.

72  : cachedOption(0)
73 #endif
74  { }
QStyleOptionViewItemV4 * cachedOption

◆ ~QCommonStylePrivate()

QCommonStylePrivate::~QCommonStylePrivate ( )
inline

Definition at line 77 of file qcommonstyle_p.h.

78  {
79  delete cachedOption;
80  }
QStyleOptionViewItemV4 * cachedOption

Functions

◆ isViewItemCached()

bool QCommonStylePrivate::isViewItemCached ( const QStyleOptionViewItemV4 option) const
inline

Definition at line 88 of file qcommonstyle_p.h.

88  {
89  return cachedOption && (option.rect == cachedOption->rect
90  && option.direction == cachedOption->direction
91  && option.state == cachedOption->state
96  && option.font == cachedOption->font
97  && option.features == cachedOption->features
98  && option.widget == cachedOption->widget
99  && option.index == cachedOption->index
100  && option.icon.isNull() == cachedOption->icon.isNull()
101  && option.text == cachedOption->text
103  }
QFont font
the font used for the item
Definition: qstyleoption.h:552
Qt::Alignment decorationAlignment
the alignment of the decoration for the item
Definition: qstyleoption.h:548
QIcon icon
The icon (if any) to be drawn in the view item.
Definition: qstyleoption.h:617
QStyle::State state
the style flags that are used when drawing the control
Definition: qstyleoption.h:88
Position decorationPosition
the position of the decoration for the item
Definition: qstyleoption.h:550
ViewItemFeatures features
a bitwise OR of the features that describe this view item
Definition: qstyleoption.h:577
bool isNull() const
Returns true if the icon is empty; otherwise returns false.
Definition: qicon.cpp:769
ViewItemPosition viewItemPosition
Gives the position of this view item relative to other items.
Definition: qstyleoption.h:619
const QWidget * widget
Definition: qstyleoption.h:596
QModelIndex index
The model index that is to be drawn.
Definition: qstyleoption.h:615
Qt::Alignment displayAlignment
the alignment of the display value for the item
Definition: qstyleoption.h:547
QSize decorationSize
the size of the decoration for the item
Definition: qstyleoption.h:551
Qt::LayoutDirection direction
the text layout direction that should be used when drawing text in the control
Definition: qstyleoption.h:89
QStyleOptionViewItemV4 * cachedOption
QRect rect
the area that should be used for various calculations and painting
Definition: qstyleoption.h:90
QString text
The text (if any) to be drawn in the view item.
Definition: qstyleoption.h:618

◆ tabLayout()

void QCommonStylePrivate::tabLayout ( const QStyleOptionTabV3 opt,
const QWidget widget,
QRect textRect,
QRect iconRect 
) const
Warning
This function is not part of the public interface. Compute the textRect and the pixmapRect from the opt rect

Uses the same computation than in QTabBar::tabSizeHint

Definition at line 1138 of file qcommonstyle.cpp.

1139 {
1140  Q_ASSERT(textRect);
1141  Q_ASSERT(iconRect);
1142  QRect tr = opt->rect;
1143  bool verticalTabs = opt->shape == QTabBar::RoundedEast
1144  || opt->shape == QTabBar::RoundedWest
1145  || opt->shape == QTabBar::TriangularEast
1146  || opt->shape == QTabBar::TriangularWest;
1147  if (verticalTabs)
1148  tr.setRect(0, 0, tr.height(), tr.width()); //0, 0 as we will have a translate transform
1149 
1150  int verticalShift = proxyStyle->pixelMetric(QStyle::PM_TabBarTabShiftVertical, opt, widget);
1151  int horizontalShift = proxyStyle->pixelMetric(QStyle::PM_TabBarTabShiftHorizontal, opt, widget);
1152  int hpadding = proxyStyle->pixelMetric(QStyle::PM_TabBarTabHSpace, opt, widget) / 2;
1153  int vpadding = proxyStyle->pixelMetric(QStyle::PM_TabBarTabVSpace, opt, widget) / 2;
1155  verticalShift = -verticalShift;
1156  tr.adjust(hpadding, verticalShift - vpadding, horizontalShift - hpadding, vpadding);
1157  bool selected = opt->state & QStyle::State_Selected;
1158  if (selected) {
1159  tr.setTop(tr.top() - verticalShift);
1160  tr.setRight(tr.right() - horizontalShift);
1161  }
1162 
1163  // left widget
1164  if (!opt->leftButtonSize.isEmpty()) {
1165  tr.setLeft(tr.left() + 4 +
1166  (verticalTabs ? opt->leftButtonSize.height() : opt->leftButtonSize.width()));
1167  }
1168  // right widget
1169  if (!opt->rightButtonSize.isEmpty()) {
1170  tr.setRight(tr.right() - 4 -
1171  (verticalTabs ? opt->rightButtonSize.height() : opt->rightButtonSize.width()));
1172  }
1173 
1174  // icon
1175  if (!opt->icon.isNull()) {
1176  QSize iconSize = opt->iconSize;
1177  if (!iconSize.isValid()) {
1178  int iconExtent = proxyStyle->pixelMetric(QStyle::PM_SmallIconSize);
1179  iconSize = QSize(iconExtent, iconExtent);
1180  }
1181  QSize tabIconSize = opt->icon.actualSize(iconSize,
1184 
1185  *iconRect = QRect(tr.left(), tr.center().y() - tabIconSize.height() / 2,
1186  tabIconSize.width(), tabIconSize .height());
1187  if (!verticalTabs)
1188  *iconRect = proxyStyle->visualRect(opt->direction, opt->rect, *iconRect);
1189  tr.setLeft(tr.left() + tabIconSize.width() + 4);
1190  }
1191 
1192  if (!verticalTabs)
1193  tr = proxyStyle->visualRect(opt->direction, opt->rect, tr);
1194 
1195  *textRect = tr;
1196 }
QStyle::State state
the style flags that are used when drawing the control
Definition: qstyleoption.h:88
virtual int pixelMetric(PixelMetric metric, const QStyleOption *option=0, const QWidget *widget=0) const =0
Returns the value of the given pixel metric.
static bool verticalTabs(QTabBar::Shape shape)
int left() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:240
int width() const
Returns the width of the rectangle.
Definition: qrect.h:303
int height() const
Returns the height of the rectangle.
Definition: qrect.h:306
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
QTabBar::Shape shape
the tab shape used to draw the tab; by default QTabBar::RoundedNorth
Definition: qstyleoption.h:316
int width() const
Returns the width.
Definition: qsize.h:126
void setTop(int pos)
Sets the top edge of the rectangle to the given y coordinate.
Definition: qrect.h:261
bool isNull() const
Returns true if the icon is empty; otherwise returns false.
Definition: qicon.cpp:769
void adjust(int x1, int y1, int x2, int y2)
Adds dx1, dy1, dx2 and dy2 respectively to the existing coordinates of the rectangle.
Definition: qrect.h:434
void setRight(int pos)
Sets the right edge of the rectangle to the given x coordinate.
Definition: qrect.h:264
QStyle * proxyStyle
Definition: qstyle_p.h:72
QSize rightButtonSize
the size for the right widget on the tab.
Definition: qstyleoption.h:353
QPoint center() const
Returns the center point of the rectangle.
Definition: qrect.h:300
int top() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:243
static QRect visualRect(Qt::LayoutDirection direction, const QRect &boundingRect, const QRect &logicalRect)
Returns the given logicalRectangle converted to screen coordinates based on the specified direction...
Definition: qstyle.cpp:2087
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
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
void setRect(int x, int y, int w, int h)
Sets the coordinates of the rectangle&#39;s top-left corner to ({x}, {y}), and its size to the given widt...
Definition: qrect.h:400
QSize iconSize
the size for the icons
Definition: qstyleoption.h:337
int height() const
Returns the height.
Definition: qsize.h:129
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
bool isValid() const
Returns true if both the width and height is equal to or greater than 0; otherwise returns false...
Definition: qsize.h:123
int y() const
Returns the y coordinate of this point.
Definition: qpoint.h:131
QIcon icon
the icon for the tab
Definition: qstyleoption.h:318
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
bool isEmpty() const
Returns true if either of the width and height is less than or equal to 0; otherwise returns false...
Definition: qsize.h:120
QSize leftButtonSize
the size for the left widget on the tab.
Definition: qstyleoption.h:352
QRect rect
the area that should be used for various calculations and painting
Definition: qstyleoption.h:90

◆ viewItemDrawText()

void QCommonStylePrivate::viewItemDrawText ( QPainter p,
const QStyleOptionViewItemV4 option,
const QRect rect 
) const

Definition at line 924 of file qcommonstyle.cpp.

Referenced by ~QCommonStylePrivate().

925 {
926  const QWidget *widget = option->widget;
927  const int textMargin = proxyStyle->pixelMetric(QStyle::PM_FocusFrameHMargin, 0, widget) + 1;
928 
929  QRect textRect = rect.adjusted(textMargin, 0, -textMargin, 0); // remove width padding
930  const bool wrapText = option->features & QStyleOptionViewItemV2::WrapText;
931  QTextOption textOption;
933  textOption.setTextDirection(option->direction);
934  textOption.setAlignment(QStyle::visualAlignment(option->direction, option->displayAlignment));
935  QTextLayout textLayout;
936  textLayout.setTextOption(textOption);
937  textLayout.setFont(option->font);
938  textLayout.setText(option->text);
939 
940  viewItemTextLayout(textLayout, textRect.width());
941 
942  QString elidedText;
943  qreal height = 0;
944  qreal width = 0;
945  int elidedIndex = -1;
946  const int lineCount = textLayout.lineCount();
947  for (int j = 0; j < lineCount; ++j) {
948  const QTextLine line = textLayout.lineAt(j);
949  if (j + 1 <= lineCount - 1) {
950  const QTextLine nextLine = textLayout.lineAt(j + 1);
951  if ((nextLine.y() + nextLine.height()) > textRect.height()) {
952  int start = line.textStart();
953  int length = line.textLength() + nextLine.textLength();
954  const QStackTextEngine engine(textLayout.text().mid(start, length), option->font);
955  elidedText = engine.elidedText(option->textElideMode, textRect.width());
956  height += line.height();
957  width = textRect.width();
958  elidedIndex = j;
959  break;
960  }
961  }
962  if (line.naturalTextWidth() > textRect.width()) {
963  int start = line.textStart();
964  int length = line.textLength();
965  const QStackTextEngine engine(textLayout.text().mid(start, length), option->font);
966  elidedText = engine.elidedText(option->textElideMode, textRect.width());
967  height += line.height();
968  width = textRect.width();
969  elidedIndex = j;
970  break;
971  }
972  width = qMax<qreal>(width, line.width());
973  height += line.height();
974  }
975 
976  const QRect layoutRect = QStyle::alignedRect(option->direction, option->displayAlignment,
977  QSize(int(width), int(height)), textRect);
978  const QPointF position = layoutRect.topLeft();
979  for (int i = 0; i < lineCount; ++i) {
980  const QTextLine line = textLayout.lineAt(i);
981  if (i == elidedIndex) {
982  qreal x = position.x() + line.x();
983  qreal y = position.y() + line.y() + line.ascent();
984  p->save();
985  p->setFont(option->font);
986  p->drawText(QPointF(x, y), elidedText);
987  p->restore();
988  break;
989  }
990  line.draw(p, position);
991  }
992 }
static QRect alignedRect(Qt::LayoutDirection direction, Qt::Alignment alignment, const QSize &size, const QRect &rectangle)
Returns a new rectangle of the specified size that is aligned to the given rectangle according to the...
Definition: qstyle.cpp:2120
void setText(const QString &string)
Sets the layout&#39;s text to the given string.
QRect adjusted(int x1, int y1, int x2, int y2) const
Returns a new rectangle with dx1, dy1, dx2 and dy2 added respectively to the existing coordinates of ...
Definition: qrect.h:431
QFont font
the font used for the item
Definition: qstyleoption.h:552
double qreal
Definition: qglobal.h:1193
QString elidedText(Qt::TextElideMode mode, const QFixed &width, int flags=0) const
qreal y() const
Returns the line&#39;s y position.
QPointer< QWidget > widget
virtual int pixelMetric(PixelMetric metric, const QStyleOption *option=0, const QWidget *widget=0) const =0
Returns the value of the given pixel metric.
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
void setFont(const QFont &f)
Sets the layout&#39;s font to the given font.
The QTextLine class represents a line of text inside a QTextLayout.
Definition: qtextlayout.h:197
static qreal position(QGraphicsObject *item, QDeclarativeAnchorLine::AnchorLine anchorLine)
void restore()
Restores the current painter state (pops a saved state off the stack).
Definition: qpainter.cpp:1620
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
int textLength() const
Returns the length of the text in the line.
int width() const
Returns the width of the rectangle.
Definition: qrect.h:303
Qt::TextElideMode textElideMode
where ellipsis should be added for text that is too long to fit into an item
Definition: qstyleoption.h:549
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
qreal ascent() const
Returns the line&#39;s ascent.
void save()
Saves the current painter state (pushes the state onto a stack).
Definition: qpainter.cpp:1590
qreal x() const
Returns the x-coordinate of this point.
Definition: qpoint.h:282
void setAlignment(Qt::Alignment alignment)
Sets the option&#39;s text alignment to the specified alignment.
Definition: qtextoption.h:148
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
QString text() const
Returns the layout&#39;s text.
ViewItemFeatures features
a bitwise OR of the features that describe this view item
Definition: qstyleoption.h:577
qreal x() const
Returns the line&#39;s x position.
void setTextDirection(Qt::LayoutDirection aDirection)
Sets the direction of the text layout defined by the option to the given direction.
Definition: qtextoption.h:99
QStyle * proxyStyle
Definition: qstyle_p.h:72
QTextLine lineAt(int i) const
Returns the {i}-th line of text in this text layout.
static QSizeF viewItemTextLayout(QTextLayout &textLayout, int lineWidth)
QString mid(int position, int n=-1) const Q_REQUIRED_RESULT
Returns a string that contains n characters of this string, starting at the specified position index...
Definition: qstring.cpp:3706
The QTextLayout class is used to lay out and render text.
Definition: qtextlayout.h:105
static Qt::Alignment visualAlignment(Qt::LayoutDirection direction, Qt::Alignment alignment)
Transforms an alignment of Qt::AlignLeft or Qt::AlignRight without Qt::AlignAbsolute into Qt::AlignLe...
Definition: qstyle.cpp:2149
const QWidget * widget
Definition: qstyleoption.h:596
qreal naturalTextWidth() const
Returns the width of the line that is occupied by text.
void setTextOption(const QTextOption &option)
Sets the text option structure that controls the layout process to the given option.
Qt::Alignment displayAlignment
the alignment of the display value for the item
Definition: qstyleoption.h:547
qreal width() const
Returns the line&#39;s width as specified by the layout() function.
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
The QTextOption class provides a description of general rich text properties.
Definition: qtextoption.h:59
qreal y() const
Returns the y-coordinate of this point.
Definition: qpoint.h:287
void setWrapMode(WrapMode wrap)
Sets the option&#39;s text wrap mode to the given mode.
Definition: qtextoption.h:109
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
void draw(QPainter *p, const QPointF &point, const QTextLayout::FormatRange *selection=0) const
Draws a line on the given painter at the specified position.
qreal height() const
Returns the line&#39;s height.
int textStart() const
Returns the start of the line from the beginning of the string passed to the QTextLayout.
int lineCount() const
Returns the number of lines in this text layout.
QString text
The text (if any) to be drawn in the view item.
Definition: qstyleoption.h:618
QPoint topLeft() const
Returns the position of the rectangle&#39;s top-left corner.
Definition: qrect.h:288

◆ viewItemLayout()

void QCommonStylePrivate::viewItemLayout ( const QStyleOptionViewItemV4 opt,
QRect checkRect,
QRect pixmapRect,
QRect textRect,
bool  sizehint 
) const

Set sizehint to false to layout the elements inside opt->rect.

Warning
This function is not part of the public interface. compute the position for the different component of an item (pixmap, text, checkbox)

Set sizehint to true to ignore opt->rect and return rectangles in infinite space

Code duplicated in QItemDelegate::doLayout

Definition at line 1005 of file qcommonstyle.cpp.

Referenced by ~QCommonStylePrivate().

1007 {
1008  Q_ASSERT(checkRect && pixmapRect && textRect);
1009  *pixmapRect = QRect(QPoint(0, 0), viewItemSize(opt, Qt::DecorationRole));
1010  *textRect = QRect(QPoint(0, 0), viewItemSize(opt, Qt::DisplayRole));
1011  *checkRect = QRect(QPoint(0, 0), viewItemSize(opt, Qt::CheckStateRole));
1012 
1013  const QWidget *widget = opt->widget;
1014  const bool hasCheck = checkRect->isValid();
1015  const bool hasPixmap = pixmapRect->isValid();
1016  const bool hasText = textRect->isValid();
1017  const int textMargin = hasText ? proxyStyle->pixelMetric(QStyle::PM_FocusFrameHMargin, opt, widget) + 1 : 0;
1018  const int pixmapMargin = hasPixmap ? proxyStyle->pixelMetric(QStyle::PM_FocusFrameHMargin, opt, widget) + 1 : 0;
1019  const int checkMargin = hasCheck ? proxyStyle->pixelMetric(QStyle::PM_FocusFrameHMargin, opt, widget) + 1 : 0;
1020  int x = opt->rect.left();
1021  int y = opt->rect.top();
1022  int w, h;
1023 
1024  if (textRect->height() == 0 && (!hasPixmap || !sizehint)) {
1025  //if there is no text, we still want to have a decent height for the item sizeHint and the editor size
1026  textRect->setHeight(opt->fontMetrics.height());
1027  }
1028 
1029  QSize pm(0, 0);
1030  if (hasPixmap) {
1031  pm = pixmapRect->size();
1032  pm.rwidth() += 2 * pixmapMargin;
1033  }
1034  if (sizehint) {
1035  h = qMax(checkRect->height(), qMax(textRect->height(), pm.height()));
1038  w = textRect->width() + pm.width();
1039  } else {
1040  w = qMax(textRect->width(), pm.width());
1041  }
1042  } else {
1043  w = opt->rect.width();
1044  h = opt->rect.height();
1045  }
1046 
1047  int cw = 0;
1048  QRect check;
1049  if (hasCheck) {
1050  cw = checkRect->width() + 2 * checkMargin;
1051  if (sizehint) w += cw;
1052  if (opt->direction == Qt::RightToLeft) {
1053  check.setRect(x + w - cw, y, cw, h);
1054  } else {
1055  check.setRect(x, y, cw, h);
1056  }
1057  }
1058 
1059  QRect display;
1060  QRect decoration;
1061  switch (opt->decorationPosition) {
1063  if (hasPixmap)
1064  pm.setHeight(pm.height() + pixmapMargin); // add space
1065  h = sizehint ? textRect->height() : h - pm.height();
1066 
1067  if (opt->direction == Qt::RightToLeft) {
1068  decoration.setRect(x, y, w - cw, pm.height());
1069  display.setRect(x, y + pm.height(), w - cw, h);
1070  } else {
1071  decoration.setRect(x + cw, y, w - cw, pm.height());
1072  display.setRect(x + cw, y + pm.height(), w - cw, h);
1073  }
1074  break; }
1076  if (hasText)
1077  textRect->setHeight(textRect->height() + textMargin); // add space
1078  h = sizehint ? textRect->height() + pm.height() : h;
1079 
1080  if (opt->direction == Qt::RightToLeft) {
1081  display.setRect(x, y, w - cw, textRect->height());
1082  decoration.setRect(x, y + textRect->height(), w - cw, h - textRect->height());
1083  } else {
1084  display.setRect(x + cw, y, w - cw, textRect->height());
1085  decoration.setRect(x + cw, y + textRect->height(), w - cw, h - textRect->height());
1086  }
1087  break; }
1089  if (opt->direction == Qt::LeftToRight) {
1090  decoration.setRect(x + cw, y, pm.width(), h);
1091  display.setRect(decoration.right() + 1, y, w - pm.width() - cw, h);
1092  } else {
1093  display.setRect(x, y, w - pm.width() - cw, h);
1094  decoration.setRect(display.right() + 1, y, pm.width(), h);
1095  }
1096  break; }
1098  if (opt->direction == Qt::LeftToRight) {
1099  display.setRect(x + cw, y, w - pm.width() - cw, h);
1100  decoration.setRect(display.right() + 1, y, pm.width(), h);
1101  } else {
1102  decoration.setRect(x, y, pm.width(), h);
1103  display.setRect(decoration.right() + 1, y, w - pm.width() - cw, h);
1104  }
1105  break; }
1106  default:
1107  qWarning("doLayout: decoration position is invalid");
1108  decoration = *pixmapRect;
1109  break;
1110  }
1111 
1112  if (!sizehint) { // we only need to do the internal layout if we are going to paint
1113  *checkRect = QStyle::alignedRect(opt->direction, Qt::AlignCenter,
1114  checkRect->size(), check);
1115  *pixmapRect = QStyle::alignedRect(opt->direction, opt->decorationAlignment,
1116  pixmapRect->size(), decoration);
1117  // the text takes up all available space, unless the decoration is not shown as selected
1118  if (opt->showDecorationSelected)
1119  *textRect = display;
1120  else
1121  *textRect = QStyle::alignedRect(opt->direction, opt->displayAlignment,
1122  textRect->size().boundedTo(display.size()), display);
1123  } else {
1124  *checkRect = check;
1125  *pixmapRect = decoration;
1126  *textRect = display;
1127  }
1128 }
static QRect alignedRect(Qt::LayoutDirection direction, Qt::Alignment alignment, const QSize &size, const QRect &rectangle)
Returns a new rectangle of the specified size that is aligned to the given rectangle according to the...
Definition: qstyle.cpp:2120
void setHeight(int h)
Sets the height of the rectangle to the given height.
Definition: qrect.h:445
Qt::Alignment decorationAlignment
the alignment of the decoration for the item
Definition: qstyleoption.h:548
QPointer< QWidget > widget
virtual int pixelMetric(PixelMetric metric, const QStyleOption *option=0, const QWidget *widget=0) const =0
Returns the value of the given pixel metric.
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
Position decorationPosition
the position of the decoration for the item
Definition: qstyleoption.h:550
int left() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:240
int width() const
Returns the width of the rectangle.
Definition: qrect.h:303
int height() const
Returns the height of the rectangle.
Definition: qrect.h:306
QFontMetrics fontMetrics
the font metrics that should be used when drawing text in the control
Definition: qstyleoption.h:91
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
QSize boundedTo(const QSize &) const
Returns a size holding the minimum width and height of this size and the given otherSize.
Definition: qsize.h:192
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
Q_GUI_EXPORT EGLDisplay display()
Definition: qegl.cpp:589
QSize size() const
Returns the size of the rectangle.
Definition: qrect.h:309
Q_CORE_EXPORT void qWarning(const char *,...)
bool showDecorationSelected
whether the decoration should be highlighted on selected items
Definition: qstyleoption.h:553
QStyle * proxyStyle
Definition: qstyle_p.h:72
int top() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:243
int right() const
Returns the x-coordinate of the rectangle&#39;s right edge.
Definition: qrect.h:246
const QWidget * widget
Definition: qstyleoption.h:596
QSize viewItemSize(const QStyleOptionViewItemV4 *option, int role) const
void setRect(int x, int y, int w, int h)
Sets the coordinates of the rectangle&#39;s top-left corner to ({x}, {y}), and its size to the given widt...
Definition: qrect.h:400
Qt::Alignment displayAlignment
the alignment of the display value for the item
Definition: qstyleoption.h:547
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
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
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
int height() const
Returns the height of the font.
bool isValid() const
Returns true if the rectangle is valid, otherwise returns false.
Definition: qrect.h:237
QRect rect
the area that should be used for various calculations and painting
Definition: qstyleoption.h:90
int & rwidth()
Returns a reference to the width.
Definition: qsize.h:141

◆ viewItemSize()

QSize QCommonStylePrivate::viewItemSize ( const QStyleOptionViewItemV4 option,
int  role 
) const

Definition at line 841 of file qcommonstyle.cpp.

Referenced by ~QCommonStylePrivate().

842 {
843  const QWidget *widget = option->widget;
844  switch (role) {
845  case Qt::CheckStateRole:
847  return QSize(proxyStyle->pixelMetric(QStyle::PM_IndicatorWidth, option, widget),
849  break;
850  case Qt::DisplayRole:
852  QTextOption textOption;
854  QTextLayout textLayout;
855  textLayout.setTextOption(textOption);
856  textLayout.setFont(option->font);
857  textLayout.setText(option->text);
858  const bool wrapText = option->features & QStyleOptionViewItemV2::WrapText;
859  const int textMargin = proxyStyle->pixelMetric(QStyle::PM_FocusFrameHMargin, option, widget) + 1;
860  QRect bounds = option->rect;
861  switch (option->decorationPosition) {
864  bounds.setWidth(wrapText && bounds.isValid() ? bounds.width() - 2 * textMargin : QFIXED_MAX);
865  break;
868  if (wrapText)
869  bounds.setWidth(bounds.isValid() ? bounds.width() - 2 * textMargin : option->decorationSize.width());
870  else
871  bounds.setWidth(QFIXED_MAX);
872  break;
873  default:
874  break;
875  }
876 
877  qreal height = 0, widthUsed = 0;
878  textLayout.beginLayout();
879  while (true) {
880  QTextLine line = textLayout.createLine();
881  if (!line.isValid())
882  break;
883  line.setLineWidth(bounds.width());
884  line.setPosition(QPointF(0, height));
885  height += line.height();
886  widthUsed = qMax(widthUsed, line.naturalTextWidth());
887  }
888  textLayout.endLayout();
889  const QSize size(qCeil(widthUsed), qCeil(height));
890  return QSize(size.width() + 2 * textMargin, size.height());
891  }
892  break;
893  case Qt::DecorationRole:
895  return option->decorationSize;
896  }
897  break;
898  default:
899  break;
900  }
901 
902  return QSize(0, 0);
903 }
void setText(const QString &string)
Sets the layout&#39;s text to the given string.
QFont font
the font used for the item
Definition: qstyleoption.h:552
double qreal
Definition: qglobal.h:1193
void setPosition(const QPointF &pos)
Moves the line to position pos.
#define QFIXED_MAX
Definition: qfixed_p.h:158
QPointer< QWidget > widget
int qCeil(qreal v)
Definition: qmath.h:63
virtual int pixelMetric(PixelMetric metric, const QStyleOption *option=0, const QWidget *widget=0) const =0
Returns the value of the given pixel metric.
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
void setFont(const QFont &f)
Sets the layout&#39;s font to the given font.
The QTextLine class represents a line of text inside a QTextLayout.
Definition: qtextlayout.h:197
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
Position decorationPosition
the position of the decoration for the item
Definition: qstyleoption.h:550
int width() const
Returns the width of the rectangle.
Definition: qrect.h:303
void setLineWidth(qreal width)
Lays out the line with the given width.
bool isValid() const
Returns true if this text line is valid; otherwise returns false.
Definition: qtextlayout.h:201
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
int width() const
Returns the width.
Definition: qsize.h:126
ViewItemFeatures features
a bitwise OR of the features that describe this view item
Definition: qstyleoption.h:577
QStyle * proxyStyle
Definition: qstyle_p.h:72
The QTextLayout class is used to lay out and render text.
Definition: qtextlayout.h:105
const QWidget * widget
Definition: qstyleoption.h:596
QTextLine createLine()
Returns a new text line to be laid out if there is text to be inserted into the layout; otherwise ret...
qreal naturalTextWidth() const
Returns the width of the line that is occupied by text.
void setTextOption(const QTextOption &option)
Sets the text option structure that controls the layout process to the given option.
QSize decorationSize
the size of the decoration for the item
Definition: qstyleoption.h:551
void setWidth(int w)
Sets the width of the rectangle to the given width.
Definition: qrect.h:442
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
The QTextOption class provides a description of general rich text properties.
Definition: qtextoption.h:59
void setWrapMode(WrapMode wrap)
Sets the option&#39;s text wrap mode to the given mode.
Definition: qtextoption.h:109
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
void endLayout()
Ends the layout process.
bool isValid() const
Returns true if the rectangle is valid, otherwise returns false.
Definition: qrect.h:237
QRect rect
the area that should be used for various calculations and painting
Definition: qstyleoption.h:90
qreal height() const
Returns the line&#39;s height.
void beginLayout()
Begins the layout process.
QString text
The text (if any) to be drawn in the view item.
Definition: qstyleoption.h:618

Properties

◆ cachedOption

QStyleOptionViewItemV4* QCommonStylePrivate::cachedOption
mutable

Definition at line 87 of file qcommonstyle_p.h.

Referenced by ~QCommonStylePrivate().

◆ checkRect

QRect QCommonStylePrivate::checkRect
mutable

Definition at line 86 of file qcommonstyle_p.h.

Referenced by ~QCommonStylePrivate().

◆ decorationRect

QRect QCommonStylePrivate::decorationRect
mutable

Definition at line 86 of file qcommonstyle_p.h.

◆ displayRect

QRect QCommonStylePrivate::displayRect
mutable

Definition at line 86 of file qcommonstyle_p.h.

◆ tabBarcloseButtonIcon

QIcon QCommonStylePrivate::tabBarcloseButtonIcon
mutable

Definition at line 105 of file qcommonstyle_p.h.


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