drawmodule.h 7.11 KB
Newer Older
Victor Yacovlev's avatar
Victor Yacovlev committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
/*
This file is generated, but you can safely change it
until you run "gen_actor_source.py" with "--project" flag.

Generated file is just a skeleton for module contents.
You should change it corresponding to functionality.
*/

#ifndef DRAWMODULE_H
#define DRAWMODULE_H

// Base class include
#include "drawmodulebase.h"

// Kumir includes
#include "extensionsystem/kplugin.h"
Denis Khachko's avatar
Denis Khachko committed
17

Victor Yacovlev's avatar
Victor Yacovlev committed
18 19

// Qt includes
Denis Khachko's avatar
Denis Khachko committed
20 21 22
#if QT_VERSION >= 0x050000
#include <QtWidgets>
#else
Victor Yacovlev's avatar
Victor Yacovlev committed
23
#include <QtGui>
Denis Khachko's avatar
Denis Khachko committed
24 25 26
#endif
#include <QtCore>

Denis Khachko's avatar
Denis Khachko committed
27
class DrawNavigator;
Victor Yacovlev's avatar
Victor Yacovlev committed
28
namespace ActorDraw {
Denis Khachko's avatar
Denis Khachko committed
29
    
30

Denis Khachko's avatar
Denis Khachko committed
31
    class DrawModule;
Denis Khachko's avatar
Denis Khachko committed
32
    
33

Denis Khachko's avatar
Denis Khachko committed
34
    
Denis Khachko's avatar
Denis Khachko committed
35 36 37 38
    class DrawView
    : public QGraphicsView
    {
    public:
Denis Khachko's avatar
Denis Khachko committed
39 40
        DrawView( QWidget * parent = 0 ){c_scale=1;pressed=false;press_pos=QPoint();firstResize=true;
            net=true;smallNetLabel=new QLabel(this);smallNetLabel->hide(); smallNetLabel->setText(trUtf8("Слишком мелкая сетка"));};
Denis Khachko's avatar
Denis Khachko committed
41
        void setDraw(DrawModule* draw){DRAW=draw;};
Denis Khachko's avatar
Denis Khachko committed
42 43 44
        double zoom()const
        {return c_scale;};
        void setZoom(double zoom);
45
        void setNet();//RESIZE NET
Denis Khachko's avatar
Denis Khachko committed
46 47 48 49 50
        bool isNet() const
        {
            return net;
            
        }
Denis Khachko's avatar
Denis Khachko committed
51 52
        void forceRedraw()
        {
Denis Khachko's avatar
Denis Khachko committed
53 54
            horizontalScrollBar()->setValue(horizontalScrollBar()->value() +1);
            horizontalScrollBar()->setValue(horizontalScrollBar()->value()-1);
Denis Khachko's avatar
Denis Khachko committed
55
            
Denis Khachko's avatar
Denis Khachko committed
56 57
           // verticalScrollBar()->setValue(horizontalScrollBar()->value() +1);
          //  verticalScrollBar()->setValue(horizontalScrollBar()->value()-1);
Denis Khachko's avatar
Denis Khachko committed
58
           
Denis Khachko's avatar
Denis Khachko committed
59
        }
Denis Khachko's avatar
Denis Khachko committed
60

Denis Khachko's avatar
Denis Khachko committed
61
    protected:
Denis Khachko's avatar
Denis Khachko committed
62
       // void scrollContentsBy ( int dx, int dy );
Denis Khachko's avatar
Denis Khachko committed
63
        void resizeEvent ( QResizeEvent * event );
Denis Khachko's avatar
Denis Khachko committed
64 65 66 67
        void wheelEvent ( QWheelEvent * event );
        void mousePressEvent ( QMouseEvent * event );
        void mouseReleaseEvent ( QMouseEvent * event );
        void mouseMoveEvent ( QMouseEvent * event ); 
Denis Khachko's avatar
Denis Khachko committed
68
    private:
Denis Khachko's avatar
Turtle  
Denis Khachko committed
69
       DrawModule* DRAW;
Denis Khachko's avatar
Denis Khachko committed
70 71
        double c_scale;
        bool pressed;
Denis Khachko's avatar
Denis Khachko committed
72
        bool net;
Denis Khachko's avatar
Denis Khachko committed
73
        QPoint press_pos;
Denis Khachko's avatar
Denis Khachko committed
74
        bool firstResize;
Denis Khachko's avatar
Denis Khachko committed
75 76
        double lastStep;
        QLabel* smallNetLabel;
77
 
Denis Khachko's avatar
Denis Khachko committed
78 79 80 81 82 83
    };    
    class DrawScene
    : public QGraphicsScene
    {
    public:
        DrawScene ( QObject * parent = 0 ){};
84
        void drawNet(double startx,double endx,double starty,double endy,QColor color,const double step,const double stepY,bool net,qreal nw,qreal aw);
Denis Khachko's avatar
Denis Khachko committed
85
        void setDraw(DrawModule* draw){DRAW=draw;};
86
        void addDrawLine(QLineF lineF,QColor color,qreal width)
Denis Khachko's avatar
Denis Khachko committed
87
        {
Denis Khachko's avatar
Denis Khachko committed
88
            if(lineF.length()==0)return;
Denis Khachko's avatar
Denis Khachko committed
89
            QGraphicsLineItem* line=addLine(lineF);
90 91 92 93
            QPen mp=QPen(QColor(color));
            mp.setWidthF(width);
            mp.setCosmetic(true);
            line->setPen(mp);
Denis Khachko's avatar
Denis Khachko committed
94
            line->setZValue(90);
Denis Khachko's avatar
Denis Khachko committed
95
            lines.append(line); 
96
            
Denis Khachko's avatar
Denis Khachko committed
97
            
Denis Khachko's avatar
Denis Khachko committed
98 99 100 101 102
        }
        void reset()
        {
            for(int i=0;i<lines.count();i++)
                removeItem(lines.at(i));
103
            lines.clear();
Denis Khachko's avatar
Denis Khachko committed
104 105 106 107
            for(int i=0;i<texts.count();i++)
                removeItem(texts.at(i));
            texts.clear();
            
Denis Khachko's avatar
Denis Khachko committed
108
        }
Denis Khachko's avatar
Denis Khachko committed
109
        void DestroyNet();
110
        void drawOnlyAxis(double startx ,double endx,double starty,double endy,qreal aw);
Denis Khachko's avatar
Denis Khachko committed
111
        bool isLineAt(const QPointF &pos,qreal radius);
Denis Khachko's avatar
Denis Khachko committed
112
        qreal drawText(const QString &Text, qreal widthChar,QPointF from,QColor color);//Returns offset of pen.
Denis Khachko's avatar
Denis Khachko committed
113
        QRectF getRect();
Denis Khachko's avatar
Denis Khachko committed
114 115
        int saveToFile(const QString& p_FileName);
        int loadFromFile(const QString& p_FileName);
Denis Khachko's avatar
Denis Khachko committed
116
    protected:
Denis Khachko's avatar
Denis Khachko committed
117
       // void resizeEvent ( QResizeEvent * event );
Denis Khachko's avatar
Denis Khachko committed
118
    private:
Denis Khachko's avatar
Denis Khachko committed
119
        bool isUserLine(QGraphicsItem*);//Return true if item is user item;
Denis Khachko's avatar
Denis Khachko committed
120 121
        QList<QGraphicsLineItem*> lines;
        QList<QGraphicsLineItem*> Netlines;
Denis Khachko's avatar
Denis Khachko committed
122
        QList<QGraphicsLineItem*> linesDubl;//Базовый чертеж
Denis Khachko's avatar
Denis Khachko committed
123
        QList<QGraphicsSimpleTextItem*> texts;
Denis Khachko's avatar
Denis Khachko committed
124
        DrawModule* DRAW;
125
        
Denis Khachko's avatar
Denis Khachko committed
126
        
Denis Khachko's avatar
Denis Khachko committed
127
       
Denis Khachko's avatar
Denis Khachko committed
128 129
    
    }; 
Victor Yacovlev's avatar
Victor Yacovlev committed
130 131 132 133 134 135
class DrawModule
    : public DrawModuleBase
{
    Q_OBJECT
public /* methods */:
    DrawModule(ExtensionSystem::KPlugin * parent);
Victor Yacovlev's avatar
Victor Yacovlev committed
136
    inline void terminateEvaluation() {}
137
    static QList<ExtensionSystem::CommandLineParameter> acceptableCommandLineParameters();
Victor Yacovlev's avatar
Victor Yacovlev committed
138 139
    QWidget* mainWidget() const;
    QWidget* pultWidget() const;
Denis Khachko's avatar
Denis Khachko committed
140
    void handleGuiReady();
141 142
    // static DrawModule * self;
   // static ExtensionSystem::SettingsPtr MySettings();
Denis Khachko's avatar
Denis Khachko committed
143 144 145 146
    bool isAutoNet() const
    {
        return autoNet;
    }
Denis Khachko's avatar
Denis Khachko committed
147 148 149 150
    void setAutoNet(bool state)
    {
        autoNet=state;
    }
Denis Khachko's avatar
Denis Khachko committed
151 152 153 154 155 156 157 158 159
    double NetStepX() const
    {
        return netStepX;
    }
    void setNetStepX(double step)
    {
        netStepX=step;
    }
    double NetStepY() const
Denis Khachko's avatar
Denis Khachko committed
160
    {
Denis Khachko's avatar
Denis Khachko committed
161
        return netStepY;
Denis Khachko's avatar
Denis Khachko committed
162
    }
Denis Khachko's avatar
Denis Khachko committed
163
    void setNetStepY(double step)
Denis Khachko's avatar
Denis Khachko committed
164
    {
Denis Khachko's avatar
Denis Khachko committed
165
        netStepY=step;
Denis Khachko's avatar
Denis Khachko committed
166 167 168 169 170
    }
    double zoom()
    {
        return CurView->zoom();
    }
Denis Khachko's avatar
Denis Khachko committed
171 172 173 174 175 176 177 178
    
    QGraphicsPolygonItem* Pen()
    {
        return mPen;
    }
    void scalePen(double factor)
    {
        mutex.lock();
Denis Khachko's avatar
Denis Khachko committed
179 180
        mPen->setScale(factor);
        qDebug()<<"PenScale"<<factor<<"mPen->scale"<<mPen->scale();
Denis Khachko's avatar
Denis Khachko committed
181 182
        mutex.unlock();
    }
Denis Khachko's avatar
Denis Khachko committed
183 184 185 186
    DrawView * getCurView()
    {
        return CurView;
    }
Denis Khachko's avatar
Denis Khachko committed
187 188 189 190 191
    static ExtensionSystem::SettingsPtr DrawSettings();
    QColor axisColor()
    {
        return QColor(DrawSettings()->value("AxisColor","blue").toString());
    }
Denis Khachko's avatar
Denis Khachko committed
192 193 194 195 196 197 198 199 200 201 202
    void redrawPicture()
    {
     
            CurView->setViewportUpdateMode (QGraphicsView::FullViewportUpdate);
            CurView->forceRedraw();
            CurScene->update(CurScene->sceneRect());
            CurView->repaint();
            CurView->viewport()->update();
            CurView->setViewportUpdateMode (QGraphicsView::NoViewportUpdate);
       
    }
203
    QString initialize(const QStringList &configurationParameters, const ExtensionSystem::CommandLine &runtimeParameters);
Victor Yacovlev's avatar
Victor Yacovlev committed
204 205
public slots:
    void changeGlobalState(ExtensionSystem::GlobalState old, ExtensionSystem::GlobalState current);
206
    void loadActorData(QIODevice * source);
207
    void reloadSettings(ExtensionSystem::SettingsPtr settings, const QStringList & keys);
Victor Yacovlev's avatar
Victor Yacovlev committed
208 209 210 211 212 213 214 215
    void reset();
    void setAnimationEnabled(bool enabled);
    void runSetupPen();
    void runReleasePen();
    void runSetPenColor(const Color& color);
    void runMoveTo(const qreal x, const qreal y);
    void runMoveBy(const qreal dX, const qreal dY);
    void runAddCaption(const qreal width, const QString& text);
Denis Khachko's avatar
Denis Khachko committed
216
    bool runIsLineAtCircle(const qreal x, const qreal y, const qreal radius);
Denis Khachko's avatar
Denis Khachko committed
217
    void zoomFullDraw();
Denis Khachko's avatar
Denis Khachko committed
218
    
Denis Khachko's avatar
Denis Khachko committed
219
    
Denis Khachko's avatar
Denis Khachko committed
220
    void drawNet();
Denis Khachko's avatar
Denis Khachko committed
221 222
    void autoNetChange(bool value);
    void netStepChange(double value);
223 224 225
    void zoomIn();
    void zoomOut();
    void zoomNorm();
Denis Khachko's avatar
Denis Khachko committed
226 227
    
    void showNavigator(bool state);
Denis Khachko's avatar
Denis Khachko committed
228 229
    void openFile();
    void saveFile();
Denis Khachko's avatar
Denis Khachko committed
230
    void redraw();
Victor Yacovlev's avatar
Victor Yacovlev committed
231 232 233


    /* ========= CLASS PRIVATE ========= */
Denis Khachko's avatar
Denis Khachko committed
234
private:
235
    void createGui();
Denis Khachko's avatar
Denis Khachko committed
236
    void CreatePen(void);
237
    
Denis Khachko's avatar
Denis Khachko committed
238 239
    DrawScene* CurScene;
    DrawView* CurView;
Denis Khachko's avatar
Denis Khachko committed
240
    QGraphicsPolygonItem* mPen;
Denis Khachko's avatar
Denis Khachko committed
241
    double netStepX,netStepY;
Denis Khachko's avatar
Denis Khachko committed
242
    QColor netColor;
Denis Khachko's avatar
Denis Khachko committed
243
    bool autoNet;
Denis Khachko's avatar
Denis Khachko committed
244 245
    bool penIsDrawing;
    Color penColor;
246
    QMutex mutex;
Denis Khachko's avatar
Denis Khachko committed
247
    DrawNavigator* navigator;
Denis Khachko's avatar
Denis Khachko committed
248
    QToolButton *showToolsBut;
Denis Khachko's avatar
Denis Khachko committed
249
    QDir curDir;
Denis Khachko's avatar
Denis Khachko committed
250 251
    bool animate;
    QTimer *redrawTimer;
Victor Yacovlev's avatar
Victor Yacovlev committed
252 253 254 255 256 257 258 259


};
        

} // namespace ActorDraw

#endif // DRAWMODULE_H