23 #include <QFontMetrics>    24 #include <QStyleOptionViewItem>    25 #include <QModelIndex>    27 #include <QLinearGradient>    58       paintAsWidget( thepPainter, theOption, myData );
    62       paintManually( thepPainter, theOption, myData );
    85       return QSize( 50, height( theOption, myData ) );
    91     return QSize( 50, 50 ); 
    95 void QgsDetailedItemDelegate::paintManually( 
QPainter *thepPainter,
   106   mpCheckBox->
render( &myCbxPixmap ); 
   113   QFontMetrics myDetailMetrics( detailFont( theOption ) );
   121   if ( theOption.state & QStyle::State_Selected )
   123     drawHighlight( theOption, thepPainter, height( theOption, theData ) );
   124     thepPainter->
setPen( theOption.palette.highlightedText().color() );
   128     thepPainter->
setPen( theOption.palette.text().color() );
   138                              theOption.rect.y() + mpCheckBox->
height(),
   145   bool myIconFlag = 
false;
   147   if ( !myDecoPixmap.
isNull() )
   150     int iconWidth = 32, iconHeight = 32;
   152     if ( myDecoPixmap.
width() <= iconWidth && myDecoPixmap.
height() <= iconHeight )
   155       int offsetX = 0, offsetY = 0;
   156       if ( myDecoPixmap.
width() < iconWidth )
   157         offsetX = ( iconWidth - myDecoPixmap.
width() ) / 2;
   158       if ( myDecoPixmap.
height() < iconHeight )
   159         offsetY = ( iconHeight - myDecoPixmap.
height() ) / 2;
   161       thepPainter->
drawPixmap( myTextStartX + offsetX,
   162                                myTextStartY + offsetY,
   168       thepPainter->
drawPixmap( myTextStartX, myTextStartY, iconWidth, iconHeight, myDecoPixmap );
   176   myTextStartY += myHeight / 2;
   177   thepPainter->
setFont( titleFont( theOption ) );
   178   thepPainter->
drawText( myTextStartX,
   184   thepPainter->
setFont( detailFont( theOption ) ); 
   194     wordWrap( theData.
detail(), myDetailMetrics, theOption.rect.width() - myTextStartX );
   195   QStringListIterator myLineWrapIterator( myList );
   196   while ( myLineWrapIterator.hasNext() )
   198     QString myLine = myLineWrapIterator.next();
   199     thepPainter->
drawText( myTextStartX,
   208   thepPainter->
setFont( categoryFont( theOption ) ); 
   209   thepPainter->
drawText( myTextStartX,
   241 void QgsDetailedItemDelegate::paintAsWidget( 
QPainter *thepPainter,
   248   mpWidget->
resize( theOption.rect.width(), mpWidget->
height() );
   252   if ( theOption.state & QStyle::State_Selected )
   254     drawHighlight( theOption, thepPainter, height( theOption, theData ) );
   264     int theHeight )
 const   266   QColor myColor1 = theOption.palette.highlight().color();
   267   QColor myColor2 = myColor1;
   268   myColor2 = myColor2.
lighter( 110 ); 
   270                               QPointF( 0, theOption.rect.y() + theHeight ) );
   283   QFontMetrics myDetailMetrics( detailFont( theOption ) );
   284   QFontMetrics myCategoryMetrics( categoryFont( theOption ) );
   296   myList = wordWrap( theData.
category(),
   307   QFont myFont = theOption.font;
   313   QFont myFont = theOption.font;
   320   QFont myTitleFont = detailFont( theOption );
   333   if ( 50 >= theWidth )
   340   QString myStringToPreviousSpace = 
"";
   341   int myPreviousSpacePos = 0;
   342   for ( 
int i = 0; i < theString.
count(); ++i )
   344     QChar myChar = theString.
at( i );
   345     if ( myChar == 
QChar( 
' ' ) )
   347       myStringToPreviousSpace = myCumulativeLine;
   348       myPreviousSpacePos = i;
   350     myCumulativeLine += myChar;
   351     if ( theMetrics.
width( myCumulativeLine ) >= theWidth )
   356       myList << myStringToPreviousSpace.
trimmed();
   357       i = myPreviousSpacePos;
   358       myStringToPreviousSpace = 
"";
   359       myCumulativeLine = 
"";
   365     myList << myCumulativeLine.
trimmed();
   379   return mVerticalSpacing;
   385   mVerticalSpacing = theValue;
   391   return mHorizontalSpacing;
   397   mHorizontalSpacing = theValue;
 bool canConvert(Type t) const
void setPointSize(int pointSize)
void fillRect(const QRectF &rectangle, const QBrush &brush)
QgsDetailedItemDelegate(QObject *parent=nullptr)
This class is the data only representation of a QgsDetailedItemWidget, designed to be used in custom ...
bool isRenderedAsWidget() const
void setColorAt(qreal position, const QColor &color)
virtual QSize sizeHint() const
~QgsDetailedItemDelegate()
void setHorizontalSpacing(int theValue)
void paint(QPainter *thePainter, const QStyleOptionViewItem &theOption, const QModelIndex &theIndex) const override
Reimplement for parent class. 
void setVerticalSpacing(int theValue)
int verticalSpacing() const
void setBold(bool enable)
void setFont(const QFont &font)
int count(const T &value) const
void setPen(const QColor &color)
void drawPixmap(const QRectF &target, const QPixmap &pixmap, const QRectF &source)
void drawText(const QPointF &position, const QString &text)
QSize sizeHint(const QStyleOptionViewItem &theOption, const QModelIndex &theIndex) const override
Reimplement for parent class. 
int width(const QString &text, int len) const
QColor lighter(int factor) const
QVariant data(int role) const
const QChar at(int position) const
int horizontalSpacing() const