30 #include "../../core/pattern/mvc/ItemController.h" 
   31 #include "../core/Scene.h" 
   32 #include "../../core/pattern/mvc/Observable.h" 
   33 #include "../../../color/RGBAColor.h" 
   34 #include "../../../qt/widgets/Utils.h" 
   35 #include "../../../geometry/Envelope.h" 
   36 #include "../../../common/STLUtils.h" 
   37 #include "../../core/pattern/singleton/Context.h" 
   38 #include "../../item/TextModel.h" 
   39 #include "../../core/property/Properties.h" 
   40 #include "../core/pattern/command/ChangePropertyCommand.h" 
   46 #include <QTextDocument> 
   47 #include <QStyleOptionGraphicsItem> 
   48 #include <QTextCursor> 
   49 #include <QAbstractTextDocumentLayout> 
   50 #include <QGraphicsSceneMouseEvent> 
   52 #include <QStyleOptionGraphicsItem> 
   55 #include <QGraphicsView> 
   59   ParentItem<QGraphicsTextItem>(controller, o, true),
 
   63   m_nameClass = std::string(this->metaObject()->className());
 
   66   setAcceptHoverEvents(
false);
 
   83   QFont ft(
"Arial", 12);
 
   84   document()->setDefaultFont(ft);
 
   86   std::string name = m_model->getName();
 
   90     if(model->
getText().compare(
"") == 0)
 
   95     QTextCursor cursor(document());
 
   97     cursor.insertText(name.c_str());
 
   99     std::string txt = model->
getText();
 
  100     document()->setPlainText(txt.c_str());
 
  121   std::string txt = model->
getText();
 
  122   document()->setPlainText(txt.c_str());
 
  138   drawBackground( painter );
 
  140   QGraphicsTextItem::paint(painter, option, widget);
 
  145   if (option->state & QStyle::State_Selected)
 
  147     drawSelection(painter);
 
  164   QFont ft = document()->defaultFont();
 
  167   ft.setPointSize(pts);
 
  168   document()->setDefaultFont(ft);
 
  170   double w = document()->size().width();
 
  171   double h = document()->size().height();
 
  173   QImage img(w, h, QImage::Format_ARGB32_Premultiplied);
 
  174   img.fill(m_backgroundColor);
 
  178   ptr.setRenderHint(QPainter::Antialiasing, 
true);
 
  180   document()->drawContents(&ptr);
 
  198   getDocumentSizeMM(w, h);
 
  200   QPointF pp = scenePos();
 
  203   double y1 = pp.y() - h;
 
  210   model->
setText(document()->toPlainText().toStdString());
 
  215   QPointF posF = scenePos();
 
  220   getDocumentSizeMM(w, h);  
 
  221   qreal valuex = posF.x();
 
  222   qreal valuey = posF.y() - h;
 
  225   coordinate.
x = valuex;
 
  226   coordinate.
y = valuey;
 
  235   QImage img = createImage();
 
  246   if(change == QGraphicsItem::ItemPositionChange && !m_move)
 
  249     QPointF newPos = value.toPointF();
 
  252     getDocumentSizeMM(w, h);
 
  254     newPos.setX(newPos.x() - transform().dx());
 
  255     newPos.setY(newPos.y() - transform().dy() + h);
 
  258   else if(change == QGraphicsItem::ItemPositionHasChanged)
 
  263   else if(change == QGraphicsItem::ItemSelectedHasChanged)
 
  265     if(m_editable && isSelected() == 
false)
 
  271   return QGraphicsTextItem::itemChange(change, value);
 
  276   if(m_editable == 
true)
 
  277     QGraphicsTextItem::keyPressEvent(event);
 
  282   if(event->button() == Qt::LeftButton)
 
  284     m_editable = !m_editable;
 
  288       setTextInteractionFlags(Qt::TextEditable);
 
  289       setCursor(Qt::IBeamCursor);
 
  290       QTextCursor cursor(textCursor());
 
  291       cursor.clearSelection();
 
  292       setTextCursor(cursor);
 
  297       setCursor(Qt::ArrowCursor);
 
  305   if(m_editable == 
false)
 
  307     QGraphicsItem::mouseMoveEvent(event);
 
  310   QGraphicsTextItem::mouseMoveEvent(event);
 
  315   if(m_editable == 
false)
 
  317     QGraphicsItem::mousePressEvent(event);
 
  320   QGraphicsTextItem::mousePressEvent(event);
 
  325   if(m_editable == 
false)
 
  327     QGraphicsItem::mouseReleaseEvent(event);
 
  330   QGraphicsTextItem::mouseReleaseEvent(event);
 
  340   QImage img = createImage();
 
  347   m_editable = editable;
 
  357     if(model->
getText().compare(document()->toPlainText().toStdString()) != 0)
 
  379   QTextCursor cursor(textCursor());
 
  380   cursor.clearSelection();
 
  381   setTextInteractionFlags(Qt::NoTextInteraction);
 
  400   m_backgroundColor.setRed(clrBack.
getRed());
 
  401   m_backgroundColor.setGreen(clrBack.
getGreen());
 
  402   m_backgroundColor.setBlue(clrBack.
getBlue());
 
  403   m_backgroundColor.setAlpha(clrBack.
getAlpha());
 
  416   document()->setDefaultFont(qft);
 
  421   return QGraphicsTextItem::boundingRect();
 
Abstract class to represent an observable. "Model" part of MVC component. 
 
virtual void updateObserver(ContextItem context)
Reimplemented from ItemObserver. 
 
Class responsible for maintaining the drawing context of a MVC component. It is always used by the "M...
 
virtual void setText(std::string txt)
 
virtual void setEditable(bool editable)
 
virtual te::gm::Coord2D getPosition()
Reimplemented from ItemObserver. 
 
bool isBold()
Returns true if font use bold, false otherwise. 
 
virtual void mousePressEvent(QGraphicsSceneMouseEvent *event)
Reimplemented from QGraphicsTextItem. 
 
bool isStrikeout()
Returns true if font use strikeout, false otherwise. 
 
int getRed() const 
It returns the red component color value (a value from 0 to 255). 
 
virtual QRectF boundingRect() const 
Reimplemented from QGraphicsItem. 
 
int getPointSize()
Returns point size of the font. 
 
int getBlue() const 
It returns the blue component color value (a value from 0 to 255). 
 
virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event)
Reimplemented from QGraphicsTextItem. 
 
int getGreen() const 
It returns the green component color value (a value from 0 to 255). 
 
virtual std::string getText()
 
The Properties class represents a persistent set of properties. The Properties can be saved to a file...
 
An utility struct for representing 2D coordinates. 
 
Abstract class to represent a controller. "Controller" part of MVC component. All classes representin...
 
Class that represents a "Model" part of Text MVC component. Its coordinate system is the same of scen...
 
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget=0)
Reimplemented from QGraphicsTextItem. 
 
TextItem(ItemController *controller, Observable *o)
Constructor. 
 
An Envelope defines a 2D rectangular region. 
 
virtual QImage createImage()
 
virtual void refreshDocument()
 
void setFamily(std::string family)
Returns font family name. 
 
int getAlpha() const 
It returns the alpha component color value (a value from 0 to 255). 
 
virtual void keyPressEvent(QKeyEvent *event)
Reimplemented from QGraphicsTextItem. 
 
bool isItalic()
Returns true if font use italic, false otherwise. 
 
std::string m_nameClass
Class name. 
 
virtual ~TextItem()
Destructor. 
 
bool isUnderline()
Returns true if font use underline, false otherwise. 
 
virtual te::color::RGBAColor ** getRGBAColorImage(int &w, int &h)
Reimplemented from ItemObserver. 
 
Class representing the scene. This scene is child of QGraphicsScene, part of Graphics View Framework...
 
virtual te::color::RGBAColor getBackgroundColor()
Returns the background color of the MVC component. 
 
virtual void updateTextConfig()
 
virtual bool isEditable()
 
virtual void getDocumentSizeMM(double &w, double &h)
 
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
Reimplemented from QGraphicsTextItem. 
 
A helper class for 32-bit RGBA (Red-Green-Blue-Alpha channel) color. 
 
virtual void addUndoStack(QUndoCommand *command)
Method that insert command Undo/Redo of type AddCommand in the Undo/Redo stack. 
 
std::string getFamily()
Sets font family name. 
 
virtual void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)
Reimplemented from QGraphicsTextItem. 
 
Class that represents text. This object is of type QGraphicsTextItem. He is directly editable via use...
 
virtual te::layout::Properties * getProperties() const 
Reimplemented from Observable. 
 
Undo/Redo for changes in component properties. 
 
virtual void setBox(te::gm::Envelope box)
Change the bounding rectangle. 
 
Abstract class that represents a graphic item. Its coordinate system is the same of scene (millimeter...
 
virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value)
Reimplemented from QGraphicsTextItem. 
 
bool isKerning()
Returns true if font use kerning, false otherwise.