better solution for error on text widget size error

preferencesAboutTextFull
Claudio Valerio 11 years ago
parent 3cb904a71b
commit 90577c3165
  1. 10
      src/domain/UBGraphicsTextItem.cpp
  2. 1
      src/domain/UBGraphicsTextItem.h

@ -48,7 +48,6 @@ UBGraphicsTextItem::UBGraphicsTextItem(QGraphicsItem * parent)
, mLastMousePressTime(QTime::currentTime()) , mLastMousePressTime(QTime::currentTime())
, mTypeTextHereLabel(tr("<Type Text Here>")) , mTypeTextHereLabel(tr("<Type Text Here>"))
{ {
mEmptyTextWidth = QFontMetrics(font()).width(mTypeTextHereLabel);
setDelegate(new UBGraphicsTextItemDelegate(this, 0)); setDelegate(new UBGraphicsTextItemDelegate(this, 0));
// TODO claudio remove this because in contrast with the fact the frame should be created on demand. // TODO claudio remove this because in contrast with the fact the frame should be created on demand.
@ -331,7 +330,7 @@ void UBGraphicsTextItem::contentsChanged()
if (toPlainText().isEmpty()) if (toPlainText().isEmpty())
{ {
resize(textWidth(),textHeight()); resize(QFontMetrics(font()).width(mTypeTextHereLabel),QFontMetrics(font()).height());
} }
} }
@ -344,15 +343,8 @@ UBGraphicsScene* UBGraphicsTextItem::scene()
void UBGraphicsTextItem::resize(qreal w, qreal h) void UBGraphicsTextItem::resize(qreal w, qreal h)
{ {
#ifdef Q_WS_MACX
// Claudio Mac os x >= 10.8.
// on text widget creation sometimes the computed height is completely wrong (more than 10^10)
setTextWidth(w > 10000 ? 250 : w);
setTextHeight(h > 10000 ? 80 : h);
#else
setTextWidth(w); setTextWidth(w);
setTextHeight(h); setTextHeight(h);
#endif
if (Delegate()) if (Delegate())
Delegate()->positionHandles(); Delegate()->positionHandles();
} }

@ -99,7 +99,6 @@ class UBGraphicsTextItem : public QGraphicsTextItem, public UBItem, public UBRes
void setSelected(bool selected); void setSelected(bool selected);
QString mTypeTextHereLabel; QString mTypeTextHereLabel;
int mEmptyTextWidth;
signals: signals:
void textUndoCommandAdded(UBGraphicsTextItem *textItem); void textUndoCommandAdded(UBGraphicsTextItem *textItem);

Loading…
Cancel
Save