104 QFontMetrics fn (font ());
106 int width = _rect.width ();
111 width -= _rect.height () / 2;
113 width -= BACK_OFFSET * 2;
116 width -= _rect.height () / 2;
118 width -= BACK_OFFSET * 2;
121 if (fn.boundingRect (text_).width () > width)
123 QString nt = text_ +
"...";
124 while (fn.boundingRect (nt).width () > width && nt.length () > 3)
125 nt.remove (nt.length () - 4, 1);
126 QGraphicsSimpleTextItem::setText (nt);
129 QGraphicsSimpleTextItem::setText (text_);
131 QGraphicsSimpleTextItem::setPos (_rect.topLeft ());
132 QGraphicsLayoutItem::setGeometry (_rect);
185void Text::paint (QPainter *_painter,
const QStyleOptionGraphicsItem *_option, QWidget *_widget)
187 qreal h = geometry ().size ().height () / 2.0;
193 path.moveTo (geometry ().size ().width () / 2, 0);
197 path.arcTo (0, 0, h * 2.0, h * 2.0, 90, 180);
202 path.arcTo (-h * 2, 0, h * 2.0, h * 2.0, 90, -180);
207 path.lineTo (geometry ().size ().width () - h, geometry ().size ().height ());
208 path.arcTo (geometry ().size ().width () - (h * 2), 0, h * 2.0, h * 2.0, -90, 180);
212 path.lineTo (geometry ().size ().width () + h, geometry ().size ().height ());
213 path.arcTo (geometry ().size ().width (), 0, h * 2.0, h * 2.0, -90, -180);
215 path.lineTo (geometry ().size ().width () / 2, 0);
217 _painter->setBrush (backgroundBrush_);
218 _painter->setPen (backgroundPen_);
219 _painter->drawPath (path);
225 lG.setFinalStop(0, h * 2);
226 lG.setColorAt(0, Qt::transparent);
227 lG.setColorAt(1, QColor (0, 0, 0, 192));
229 _painter->setBrush (lG);
230 _painter->setPen (Qt::NoPen);
231 _painter->drawPath(path);
234 lG.setFinalStop(0, 0);
235 lG.setColorAt(0, Qt::transparent);
236 lG.setColorAt(1, QColor (255, 255, 255, 192));
239 pen.setColor (Qt::transparent);
241 _painter->setBrush (lG);
242 _painter->setPen (pen);
243 _painter->drawPath(path);
246 _painter->translate (h, BACK_OFFSET);
248 _painter->translate (BACK_OFFSET * 2, BACK_OFFSET);
251 QFontMetrics fn (font ());
253 if (alignment_ == Qt::AlignHCenter)
255 trans = geometry ().size ().width ();
262 trans -= BACK_OFFSET * 2;
266 trans -= BACK_OFFSET * 2;
269 _painter->translate ((trans - fn.boundingRect (QGraphicsSimpleTextItem::text ()).width ()) / 2, 0);
271 else if (alignment_ == Qt::AlignRight)
273 trans = geometry ().size ().width ();
280 trans -= BACK_OFFSET * 2;
284 trans -= BACK_OFFSET * 2;
287 _painter->translate (trans - fn.boundingRect (QGraphicsSimpleTextItem::text ()).width (), 0);
294 QGraphicsSimpleTextItem::paint (_painter, _option, _widget);
344 QFontMetrics fn (font ());
349 QRectF rect = QGraphicsSimpleTextItem::boundingRect ();
351 if (alignment_ == Qt::AlignHCenter)
352 rect.translate ((geometry ().size ().width () - fn.boundingRect (QGraphicsSimpleTextItem::text ()).width ()) / 2, 0);
353 else if (alignment_ == Qt::AlignRight)
354 rect.translate (geometry ().size ().width () - fn.boundingRect (QGraphicsSimpleTextItem::text ()).width (), 0);
359 w = geometry ().size ().width ();
364 w += (fn.height () / 2) + (BACK_OFFSET * 2);
365 x -= (fn.height () / 2) + (BACK_OFFSET * 2);
370 w += (fn.height () / 2) + (BACK_OFFSET * 2);
373 return QRectF (QPointF (x, 0), QSizeF(w, geometry ().size ().height ()));
401 QPainterPath
shape = QGraphicsSimpleTextItem::shape ();
403 QFontMetrics fn (font ());
405 if (alignment_ == Qt::AlignHCenter || alignment_ == Qt::AlignRight)
408 if (alignment_ == Qt::AlignHCenter)
409 trans = QTransform::fromTranslate ((geometry ().size ().width () - fn.boundingRect (QGraphicsSimpleTextItem::text ()).width ()) / 2, 0);
410 else if (alignment_ == Qt::AlignRight)
411 trans = QTransform::fromTranslate (geometry ().size ().width () - fn.boundingRect (QGraphicsSimpleTextItem::text ()).width (), 0);
413 QList<QPolygonF> poly =
shape.toSubpathPolygons (trans);
415 shape = QPainterPath ();
417 foreach (
const QPolygonF &p, poly)
424 qreal h = geometry ().size ().height () / 2.0;
428 path.moveTo (geometry ().size ().width () / 2, 0);
432 path.arcTo (0, 0, h * 2.0, h * 2.0, 90, 180);
437 path.arcTo (-h * 2, 0, h * 2.0, h * 2.0, 90, -180);
442 path.lineTo (geometry ().size ().width () - h, geometry ().size ().height ());
443 path.arcTo (geometry ().size ().width () - (h * 2), 0, h * 2.0, h * 2.0, -90, 180);
447 path.lineTo (geometry ().size ().width () + h, geometry ().size ().height ());
448 path.arcTo (geometry ().size ().width (), 0, h * 2.0, h * 2.0, -90, -180);
450 path.lineTo (geometry ().size ().width () / 2, 0);
virtual QRectF boundingRect() const
Bounding rectangle.
virtual void paint(QPainter *_painter, const QStyleOptionGraphicsItem *_option, QWidget *_widget=0)
Background painting.
Text(QGraphicsItem *_parent=0)
Constructor.
virtual void setBackgroundBrush(QBrush _brush)
Sets the background brush.
void setAlignment(Qt::Alignment _alignment)
Placement of the text in a stretched widget.
void clearBackground()
Disables backgorund painting.
virtual void setGeometry(const QRectF &_rect)
Sets the geometry.
virtual void setBackgroundPen(QPen _pen)
Sets the background pen.
void setHorizontalStretch(bool _stretch)
Should this widget be stretchable in horizontal direction.
void setBackground(bool _leftOut, bool _rightOut)
Enables background painting.
QPainterPath shape() const
Returns the shape for proper repainting/event handling.