src/gui/widgets/qcommandlinkbutton.cpp
changeset 33 3e2da88830cd
parent 30 5dc02b23752f
child 37 758a864f9613
equal deleted inserted replaced
30:5dc02b23752f 33:3e2da88830cd
   116     QColor mergedColors(const QColor &a, const QColor &b, int value) const;
   116     QColor mergedColors(const QColor &a, const QColor &b, int value) const;
   117 
   117 
   118     int topMargin() const { return 10; }
   118     int topMargin() const { return 10; }
   119     int leftMargin() const { return 7; }
   119     int leftMargin() const { return 7; }
   120     int rightMargin() const { return 4; }
   120     int rightMargin() const { return 4; }
   121     int bottomMargin() const { return 4; }
   121     int bottomMargin() const { return 10; }
   122 
   122 
   123     QString description;
   123     QString description;
   124     QColor currentColor;
   124     QColor currentColor;
   125 };
   125 };
   126 
   126 
   172 }
   172 }
   173 
   173 
   174 QRect QCommandLinkButtonPrivate::titleRect() const
   174 QRect QCommandLinkButtonPrivate::titleRect() const
   175 {
   175 {
   176     Q_Q(const QCommandLinkButton);
   176     Q_Q(const QCommandLinkButton);
   177     return q->rect().adjusted(textOffset(), topMargin(),
   177     QRect r = q->rect().adjusted(textOffset(), topMargin(), -rightMargin(), 0);
   178                               -rightMargin(), 0);
   178     if (description.isEmpty())
       
   179     {
       
   180         QFontMetrics fm(titleFont());
       
   181         r.setTop(r.top() + qMax(0, (q->icon().actualSize(q->iconSize()).height()
       
   182                  - fm.height()) / 2));
       
   183     }
       
   184 
       
   185     return r;
   179 }
   186 }
   180 
   187 
   181 QRect QCommandLinkButtonPrivate::descriptionRect() const
   188 QRect QCommandLinkButtonPrivate::descriptionRect() const
   182 {
   189 {
   183     Q_Q(const QCommandLinkButton);
   190     Q_Q(const QCommandLinkButton);
   252 QSize QCommandLinkButton::minimumSizeHint() const
   259 QSize QCommandLinkButton::minimumSizeHint() const
   253 {
   260 {
   254     Q_D(const QCommandLinkButton);
   261     Q_D(const QCommandLinkButton);
   255     QSize size = sizeHint();
   262     QSize size = sizeHint();
   256     int minimumHeight = qMax(d->descriptionOffset() + d->bottomMargin(),
   263     int minimumHeight = qMax(d->descriptionOffset() + d->bottomMargin(),
   257                              iconSize().height() + d->topMargin());
   264                              icon().actualSize(iconSize()).height() + d->topMargin());
   258     size.setHeight(minimumHeight);
   265     size.setHeight(minimumHeight);
   259     return size;
   266     return size;
   260 }
   267 }
   261 
   268 
   262 /*!
   269 /*!
   326 {
   333 {
   327     Q_D(const QCommandLinkButton);
   334     Q_D(const QCommandLinkButton);
   328     int heightWithoutDescription = d->descriptionOffset() + d->bottomMargin();
   335     int heightWithoutDescription = d->descriptionOffset() + d->bottomMargin();
   329     // find the width available for the description area
   336     // find the width available for the description area
   330     return qMax(heightWithoutDescription + d->descriptionHeight(width),
   337     return qMax(heightWithoutDescription + d->descriptionHeight(width),
   331                 iconSize().height() + d->topMargin() + d->bottomMargin());
   338                 icon().actualSize(iconSize()).height() + d->topMargin() +
       
   339                 d->bottomMargin());
   332 }
   340 }
   333 
   341 
   334 /*! \reimp */
   342 /*! \reimp */
   335 void QCommandLinkButton::paintEvent(QPaintEvent *)
   343 void QCommandLinkButton::paintEvent(QPaintEvent *)
   336 {
   344 {