void UBGraphicsTextItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { QColor color = UBSettings::settings()->isDarkBackground() ? mColorOnDarkBackground : mColorOnLightBackground; setDefaultTextColor(color); // Never draw the rubber band, we draw our custom selection with the DelegateFrame QStyleOptionGraphicsItem styleOption = QStyleOptionGraphicsItem(*option); styleOption.state &= ~QStyle::State_Selected; styleOption.state &= ~QStyle::State_HasFocus; QGraphicsTextItem::paint(painter, &styleOption, widget); if (widget == UBApplication::boardController->controlView()->viewport() && !isSelected() && toPlainText().isEmpty()) { QFontMetrics fm(font()); setTextWidth(fm.width(mTypeTextHereLabel)); painter->setFont(font()); painter->setPen(UBSettings::paletteColor); painter->drawText(boundingRect(), Qt::AlignCenter, mTypeTextHereLabel); setTextInteractionFlags(Qt::NoTextInteraction); } Delegate()->postpaint(painter, option, widget); }
TimeDisplay::TimeDisplay(QGraphicsItem* parent) : QGraphicsTextItem(parent) { setAcceptedMouseButtons(Qt::NoButton); setAcceptHoverEvents(false); mFont = QFont("Arial", 18, QFont::Normal, false); mFont.setStyleHint(QFont::SansSerif); mFont.setPixelSize(24); setFont(mFont); setDefaultTextColor(QColor("#d7d8da")); mShowTenth = true; mSs = mLastSs = ""; mHs = ""; mInterval = 50; mPaused = false; mStopped = true; mGameTime = 0; mTime = 0; mTimer = new GameTimer(this); connect(mTimer, SIGNAL(TimeOutSignal(int)), this, SLOT(DisplayTime(int))); mTimer->Start(); setTextWidth(440); setTransform(QTransform::fromScale(0.5, 0.5), true); //scale(0.5, 0.5); }
int QTextDocument::qt_metacall(QMetaObject::Call _c, int _id, void **_a) { _id = QObject::qt_metacall(_c, _id, _a); if (_id < 0) return _id; if (_c == QMetaObject::InvokeMetaMethod) { if (_id < 14) qt_static_metacall(this, _c, _id, _a); _id -= 14; } #ifndef QT_NO_PROPERTIES else if (_c == QMetaObject::ReadProperty) { void *_v = _a[0]; switch (_id) { case 0: *reinterpret_cast< bool*>(_v) = isUndoRedoEnabled(); break; case 1: *reinterpret_cast< bool*>(_v) = isModified(); break; case 2: *reinterpret_cast< QSizeF*>(_v) = pageSize(); break; case 3: *reinterpret_cast< QFont*>(_v) = defaultFont(); break; case 4: *reinterpret_cast< bool*>(_v) = useDesignMetrics(); break; case 5: *reinterpret_cast< QSizeF*>(_v) = size(); break; case 6: *reinterpret_cast< qreal*>(_v) = textWidth(); break; case 7: *reinterpret_cast< int*>(_v) = blockCount(); break; case 8: *reinterpret_cast< qreal*>(_v) = indentWidth(); break; case 9: *reinterpret_cast< QString*>(_v) = defaultStyleSheet(); break; case 10: *reinterpret_cast< int*>(_v) = maximumBlockCount(); break; case 11: *reinterpret_cast< qreal*>(_v) = documentMargin(); break; } _id -= 12; } else if (_c == QMetaObject::WriteProperty) { void *_v = _a[0]; switch (_id) { case 0: setUndoRedoEnabled(*reinterpret_cast< bool*>(_v)); break; case 1: setModified(*reinterpret_cast< bool*>(_v)); break; case 2: setPageSize(*reinterpret_cast< QSizeF*>(_v)); break; case 3: setDefaultFont(*reinterpret_cast< QFont*>(_v)); break; case 4: setUseDesignMetrics(*reinterpret_cast< bool*>(_v)); break; case 6: setTextWidth(*reinterpret_cast< qreal*>(_v)); break; case 8: setIndentWidth(*reinterpret_cast< qreal*>(_v)); break; case 9: setDefaultStyleSheet(*reinterpret_cast< QString*>(_v)); break; case 10: setMaximumBlockCount(*reinterpret_cast< int*>(_v)); break; case 11: setDocumentMargin(*reinterpret_cast< qreal*>(_v)); break; } _id -= 12; } else if (_c == QMetaObject::ResetProperty) { _id -= 12; } else if (_c == QMetaObject::QueryPropertyDesignable) { _id -= 12; } else if (_c == QMetaObject::QueryPropertyScriptable) { _id -= 12; } else if (_c == QMetaObject::QueryPropertyStored) { _id -= 12; } else if (_c == QMetaObject::QueryPropertyEditable) { _id -= 12; } else if (_c == QMetaObject::QueryPropertyUser) { _id -= 12; } #endif // QT_NO_PROPERTIES return _id; }
void UBGraphicsTextItem::resize(qreal w, qreal h) { setTextWidth(w); setTextHeight(h); if (Delegate()) Delegate()->positionHandles(); }
// Main themable function. Called for any theme change. The sprites needs to // resize and redraw here. void TextSprite::changeTheme() { // Get scaling change double scale = thememanager()->getScale(); Themable::setScale(scale); // Retrieve theme data from configuration KConfigGroup config = thememanager()->config(id()); QPoint offset = thememanager()->getOffset(); // Size double width = config.readEntry("width", 1.0); double height = config.readEntry("height", 0.0); width *= scale; height *= scale; // Position QPointF pos = config.readEntry("pos", QPointF(1.0,1.0)); pos *= scale; setPos(pos.x(), pos.y()); // z-Value double zValue = config.readEntry("zValue", 0.0); setZValue(zValue); // Text font bool bold = config.readEntry("bold", false); QFont font; font.setPixelSize(int(height)); font.setBold(bold); setFont(font); if (width < boundingRect().width()) { setTextWidth(width); } // Retrieve font color QColor fontColor; fontColor = config.readEntry("fontColor", QColor(Qt::white)); setDefaultTextColor(fontColor); // Centering bool center = config.readEntry("center", false); resetTransform(); if (center) { translate(-boundingRect().width()/2.0+offset.x(), 0.0+offset.y()); } else { translate(offset.x(),offset.y()); } update(); }
void UBGraphicsTextItem::contentsChanged() { if (scene()) { scene()->setModified(true); } if (toPlainText().isEmpty()) { setTextWidth(textWidth()); } }
void DatumTextItem::setAsTitle() { background = Colors::base03; foreground = Colors::base06; auto f = font(); f.setBold(true); setFont(f); // Allow this item to grow horizontally forever setTextWidth(-1); // Force a redraw onDatumChanged(); }
GraphicsTextItem::GraphicsTextItem(){ setFlag(QGraphicsItem::ItemIsMovable); setFlag(QGraphicsItem::ItemIsSelectable); setFlag(QGraphicsItem::ItemIsFocusable); setAcceptDrops(true); setAcceptHoverEvents(true); QTextDocument *tdocument = document(); tdocument->setModified(true); QTextOption option = tdocument->defaultTextOption(); option.setAlignment(Qt::AlignHCenter); tdocument->setDefaultTextOption(option); //setTextWidth(tdocument->idealWidth()); setTextWidth(400); }
DatumTextItem::DatumTextItem(Datum* datum, QGraphicsItem* parent) : QGraphicsTextItem(parent), d(datum), txt(document()), background(Colors::base02), foreground(Colors::base04), border(background) { setTextInteractionFlags(Qt::TextEditorInteraction); setTextWidth(150); connect(datum, &Datum::changed, this, &DatumTextItem::onDatumChanged); onDatumChanged(); bbox = boundingRect(); connect(txt, &QTextDocument::contentsChanged, this, &DatumTextItem::onTextChanged); connect(document(), &QTextDocument::undoCommandAdded, this, &DatumTextItem::onUndoCommandAdded); installEventFilter(this); }
void BlockDescription::setAlignCenter(int i) { setTextWidth(static_cast<DiagramBlock *>(parentItem())->getWidth() - 1); blockHeight = this->boundingRect().height(); if (i == 0)this->setHtml("<body style='background-color:#4C6BB2;'><center>" + textDescription + "</center></body>"); if (i == 1)this->setHtml("<body style='background-color:#1FFC52;'><center>" + textDescription + "</center></body>"); if (i == -1)this->setHtml("<body style='background-color:#D0FC1F;'><center>" + textDescription + "</center></body>"); //748DC8 //Setting align /*QTextBlockFormat format; format.setAlignment(Qt::AlignCenter); QTextCursor cursor = this->textCursor(); cursor.select(QTextCursor::Document); cursor.mergeBlockFormat(format); cursor.clearSelection(); this->setTextCursor(cursor);*/ setPos(1, 1); }
void DiagramTextItem::deserialize( QDataStream& out) { qreal textwidth; out >> textwidth; setTextWidth(textwidth); QFont font; out >> font; setFont(font); QColor color; out >> color; setDefaultTextColor(color); QString str; out >> str; setPlainText(str); QPointF point; out >> point; setPos(point); out >> *this; }
int QTextDocument::qt_metacall(QMetaObject::Call _c, int _id, void **_a) { _id = QObject::qt_metacall(_c, _id, _a); if (_id < 0) return _id; if (_c == QMetaObject::InvokeMetaMethod) { switch (_id) { case 0: contentsChange((*reinterpret_cast< int(*)>(_a[1])),(*reinterpret_cast< int(*)>(_a[2])),(*reinterpret_cast< int(*)>(_a[3]))); break; case 1: contentsChanged(); break; case 2: undoAvailable((*reinterpret_cast< bool(*)>(_a[1]))); break; case 3: redoAvailable((*reinterpret_cast< bool(*)>(_a[1]))); break; case 4: undoCommandAdded(); break; case 5: modificationChanged((*reinterpret_cast< bool(*)>(_a[1]))); break; case 6: cursorPositionChanged((*reinterpret_cast< const QTextCursor(*)>(_a[1]))); break; case 7: blockCountChanged((*reinterpret_cast< int(*)>(_a[1]))); break; case 8: documentLayoutChanged(); break; case 9: undo(); break; case 10: redo(); break; case 11: appendUndoItem((*reinterpret_cast< QAbstractUndoItem*(*)>(_a[1]))); break; case 12: setModified((*reinterpret_cast< bool(*)>(_a[1]))); break; case 13: setModified(); break; } _id -= 14; } #ifndef QT_NO_PROPERTIES else if (_c == QMetaObject::ReadProperty) { void *_v = _a[0]; switch (_id) { case 0: *reinterpret_cast< bool*>(_v) = isUndoRedoEnabled(); break; case 1: *reinterpret_cast< bool*>(_v) = isModified(); break; case 2: *reinterpret_cast< QSizeF*>(_v) = pageSize(); break; case 3: *reinterpret_cast< QFont*>(_v) = defaultFont(); break; case 4: *reinterpret_cast< bool*>(_v) = useDesignMetrics(); break; case 5: *reinterpret_cast< QSizeF*>(_v) = size(); break; case 6: *reinterpret_cast< qreal*>(_v) = textWidth(); break; case 7: *reinterpret_cast< int*>(_v) = blockCount(); break; case 8: *reinterpret_cast< qreal*>(_v) = indentWidth(); break; case 9: *reinterpret_cast< QString*>(_v) = defaultStyleSheet(); break; case 10: *reinterpret_cast< int*>(_v) = maximumBlockCount(); break; } _id -= 11; } else if (_c == QMetaObject::WriteProperty) { void *_v = _a[0]; switch (_id) { case 0: setUndoRedoEnabled(*reinterpret_cast< bool*>(_v)); break; case 1: setModified(*reinterpret_cast< bool*>(_v)); break; case 2: setPageSize(*reinterpret_cast< QSizeF*>(_v)); break; case 3: setDefaultFont(*reinterpret_cast< QFont*>(_v)); break; case 4: setUseDesignMetrics(*reinterpret_cast< bool*>(_v)); break; case 6: setTextWidth(*reinterpret_cast< qreal*>(_v)); break; case 8: setIndentWidth(*reinterpret_cast< qreal*>(_v)); break; case 9: setDefaultStyleSheet(*reinterpret_cast< QString*>(_v)); break; case 10: setMaximumBlockCount(*reinterpret_cast< int*>(_v)); break; } _id -= 11; } else if (_c == QMetaObject::ResetProperty) { _id -= 11; } else if (_c == QMetaObject::QueryPropertyDesignable) { _id -= 11; } else if (_c == QMetaObject::QueryPropertyScriptable) { _id -= 11; } else if (_c == QMetaObject::QueryPropertyStored) { _id -= 11; } else if (_c == QMetaObject::QueryPropertyEditable) { _id -= 11; } else if (_c == QMetaObject::QueryPropertyUser) { _id -= 11; } #endif // QT_NO_PROPERTIES return _id; }
void FormText::setCfg( const Cfg::Text & c ) { setPlainText( QString() ); QFont f = font(); QTextCharFormat fmt = textCursor().charFormat(); QTextBlockFormat b = textCursor().blockFormat(); foreach( const Cfg::TextStyle & s, c.text() ) { if( s.style().contains( Cfg::c_normalStyle ) ) { f.setWeight( QFont::Normal ); f.setItalic( false ); f.setUnderline( false ); fmt.setFontWeight( QFont::Normal ); fmt.setFontItalic( false ); fmt.setFontUnderline( false ); } else { if( s.style().contains( Cfg::c_boldStyle ) ) { f.setWeight( QFont::Bold ); fmt.setFontWeight( QFont::Bold ); } else { f.setWeight( QFont::Normal ); fmt.setFontWeight( QFont::Normal ); } if( s.style().contains( Cfg::c_italicStyle ) ) { f.setItalic( true ); fmt.setFontItalic( true ); } else { f.setItalic( false ); fmt.setFontItalic( false ); } if( s.style().contains( Cfg::c_underlineStyle ) ) { f.setUnderline( true ); fmt.setFontUnderline( true ); } else { f.setUnderline( false ); fmt.setFontUnderline( false ); } } Cfg::initBlockFormat( b, s ); f.setPointSize( s.fontSize() ); fmt.setFontPointSize( s.fontSize() ); setFont( f ); QTextCursor cursor = textCursor(); cursor.movePosition( QTextCursor::End ); cursor.setCharFormat( fmt ); cursor.setBlockFormat( b ); cursor.insertText( s.text() ); setTextCursor( cursor ); } document()->clearUndoRedoStacks(); setObjectId( c.objectId() ); setTextWidth( c.textWidth() ); setPos( QPointF( c.pos().x(), c.pos().y() ) ); setLink( c.link() ); QRectF r = boundingRect(); r.moveTo( pos() ); d->m_proxy->setRect( r ); }
void Text::restoreDefaultSize() { setTextWidth(-1); updatePos(); }
void Text::setSize(const QSize &size) { setTextWidth(size.width()); }