PageRenderTime 39ms CodeModel.GetById 14ms app.highlight 20ms RepoModel.GetById 1ms app.codeStats 1ms

/vp_plugins/global/commands.h

http://cupsfilter.googlecode.com/
C++ Header | 185 lines | 149 code | 36 blank | 0 comment | 3 complexity | b2e9e0272336ead2e4046dda9a3d1e46 MD5 | raw file
  1#ifndef COMMANDS_H
  2#define COMMANDS_H
  3
  4#include "mytextitem.h"
  5#include "mytypes.h"
  6
  7#include <QUndoCommand>
  8#include <QGraphicsScene>
  9#include <QtGui/QFont>
 10#include <QtGui/QColor>
 11#include <QtGlobal>
 12
 13using namespace VPrn;
 14
 15class CommandTextItemRotate : public QUndoCommand
 16{
 17public:
 18    CommandTextItemRotate( QGraphicsScene* scene,  myTextItem*  TextItem, qreal direct )
 19    {
 20        m_TextItem   = TextItem;
 21        m_scene      = scene;
 22        oldDirect    = m_TextItem->getAngle();
 23        newDirect    = direct;
 24        if ( direct  == 90 ){
 25            setText( QObject::tr("??????? %1 ???????? ??????")
 26                     .arg( m_TextItem->getETag() ) );
 27        }else{
 28            setText( QObject::tr("??????? %1 ???????? ?????")
 29                     .arg( m_TextItem->getETag() ) );
 30        }
 31
 32    }
 33
 34
 35    virtual void undo()    { m_TextItem->setAngle(oldDirect); }
 36    virtual void redo()    { m_TextItem->setAngle(newDirect); }
 37
 38private:
 39    myTextItem*      m_TextItem;
 40    QGraphicsScene*  m_scene;
 41    qreal oldDirect;
 42    qreal newDirect;
 43};
 44
 45
 46class CommandTextItemChangeTag : public QUndoCommand
 47{
 48public:
 49    CommandTextItemChangeTag( QGraphicsScene* scene,  myTextItem*  TextItem, QString &mTag)
 50    {
 51        m_TextItem = TextItem;
 52        m_scene    = scene;
 53        oldTag     = m_TextItem->getETag();
 54        newTag     = mTag;
 55        setText( QObject::tr("??????? %1 ??????? ?? %2")
 56                 .arg(oldTag,newTag) );
 57    }
 58
 59
 60    virtual void undo()    { m_TextItem->setETag(oldTag); }
 61    virtual void redo()    { m_TextItem->setETag(newTag); }
 62
 63private:
 64    myTextItem*      m_TextItem;
 65    QGraphicsScene*  m_scene;
 66    QString oldTag;
 67    QString newTag;
 68};
 69
 70class CommandTextItemChangeColor : public QUndoCommand
 71{
 72public:
 73    CommandTextItemChangeColor( QGraphicsScene* scene,  myTextItem*  TextItem, QColor &clr )
 74    {
 75        m_TextItem = TextItem;
 76        m_scene    = scene;
 77        oldColor    = m_TextItem->defaultTextColor();
 78        newColor    = clr;
 79        setText( QObject::tr("? ???????? %1 ??????? ???? ?? %2")
 80                 .arg(m_TextItem->getETag(),clr.name()) );
 81    }
 82
 83
 84    virtual void undo()    { m_TextItem->setDefaultTextColor(oldColor); }
 85    virtual void redo()    { m_TextItem->setDefaultTextColor(newColor); }
 86
 87private:
 88    myTextItem*      m_TextItem;
 89    QGraphicsScene*  m_scene;
 90    QColor oldColor;
 91    QColor newColor;
 92};
 93
 94class CommandTextItemChangeFont : public QUndoCommand
 95{
 96public:
 97    CommandTextItemChangeFont( QGraphicsScene* scene,  myTextItem*  TextItem, QFont &fnt )
 98    {
 99        m_TextItem = TextItem;
100        m_scene    = scene;
101        oldFont    = m_TextItem->font();
102        newFont    = fnt;
103        setText( QObject::tr("? ???????? %1 ??????? ????? ?? %2")
104                 .arg(m_TextItem->getETag(),fnt.family()) );
105    }
106
107
108    virtual void undo()    { m_TextItem->setFont(oldFont); }
109    virtual void redo()    { m_TextItem->setFont(newFont); }
110
111private:
112    myTextItem*      m_TextItem;
113    QGraphicsScene*  m_scene;
114    QFont oldFont;
115    QFont newFont;
116};
117
118class CommandTextItemAdd : public QUndoCommand
119{
120public:
121    CommandTextItemAdd( QGraphicsScene* scene,  myTextItem*  TextItem )
122    {
123        m_TextItem = TextItem;
124        m_scene    = scene;
125        setText( QObject::tr("??????? %1 ??????").arg(m_TextItem->getETag()) );
126    }
127
128    ~CommandTextItemAdd()
129    {
130
131        if ( !m_scene->items().contains( m_TextItem ) )
132            delete m_TextItem;
133    }
134
135    virtual void undo()    { m_scene->removeItem( m_TextItem ); }
136    virtual void redo()    { m_scene->addItem( m_TextItem ); }
137
138private:
139    myTextItem*      m_TextItem;   // station being added
140    QGraphicsScene*  m_scene;      // scene where station being added
141};
142
143class CommandTextItemDelete : public QUndoCommand
144{
145public:
146    CommandTextItemDelete( QGraphicsScene* scene,  myTextItem*  TextItem )
147    {
148        m_scene   = scene;
149        m_TextItem =  TextItem;
150        setText( QObject::tr("??????? %1 ??????").arg(m_TextItem->getETag()) );
151    }
152
153    virtual void undo()    { m_scene->addItem(  m_TextItem ); }
154
155    virtual void redo()    { m_scene->removeItem(  m_TextItem ); }
156
157private:
158    QGraphicsScene*  m_scene;      // scene where station being deleted
159    myTextItem*      m_TextItem;
160};
161
162class CommandTextItemMove : public QUndoCommand
163{
164public:
165    CommandTextItemMove(  myTextItem*  TextItem, qreal fromX, qreal fromY, qreal toX, qreal toY )
166    {
167        m_TextItem =  TextItem;
168        m_from    = QPointF( fromX, fromY );
169        m_to      = QPointF( toX, toY );
170        setText( QObject::tr("??????? %5 ????????? %1,%2 -> %3,%4")
171                 .arg(fromX).arg(fromY).arg(toX).arg(toY).arg(m_TextItem->getETag()) );
172    }
173
174    virtual void undo()    { m_TextItem->setPos( m_from ); }
175
176    virtual void redo()    { m_TextItem->setPos( m_to ); }
177
178private:
179    myTextItem*      m_TextItem;       // station being moved
180    QPointF    m_from;          // original coords
181    QPointF    m_to;            // new coords
182};
183
184#endif  // COMMANDS
185