Commit 236827ec authored by Denis Khachko's avatar Denis Khachko

Actor Draw - msleep

parent 5468f2a8
......@@ -19,6 +19,7 @@
},
{
"name": {"ascii": "move to", "ru_RU": "сместиться в точку"},
"async": false,
"arguments": [
{"baseType": "double", "name": "x"},
{"baseType": "double", "name": "y"}
......@@ -26,6 +27,7 @@
},
{
"name": {"ascii": "move by", "ru_RU": "сместиться на вектор"},
"async": false,
"arguments": [
{"baseType": "double", "name": "dX"},
{"baseType": "double", "name": "dY"}
......
......@@ -169,6 +169,20 @@ namespace ActorDraw {
texts.last()->setZValue(90);
return widthChar;
};
void DrawScene::addDrawLine(QLineF lineF,QColor color,qreal width)
{
if(lineF.length()==0)return;
QGraphicsLineItem* line=addLine(lineF);
QPen mp=QPen(QColor(color));
mp.setWidthF(width);
mp.setCosmetic(true);
line->setPen(mp);
line->setZValue(90);
lines.append(line);
}
void DrawScene::DestroyNet()
{
// qDebug()<<Netlines.count();
......@@ -272,7 +286,22 @@ namespace ActorDraw {
}
}
int DrawScene::loadFromFile(const QString& p_FileName)
bool DrawScene::event(QEvent * event)
{
// qDebug()<<"ET"<<event->type();
dr_mutex->lock();
QGraphicsScene::event(event);
dr_mutex->unlock();
}
bool DrawScene::eventFilter(QObject *object, QEvent *event)
{
return true;
}
int DrawScene::loadFromFile(const QString& p_FileName)
{
QFileInfo fi(p_FileName);
QString name = fi.fileName();
......@@ -595,7 +624,18 @@ int DrawScene::saveToFile(const QString& p_FileName)
return 0;
};
};
void DrawView::paintEvent(QPaintEvent *event)
{
if(!dr_mutex->tryLock())
{
return;
}else
{
QGraphicsView::paintEvent(event);
dr_mutex->unlock();
}
}
void DrawView::resizeEvent ( QResizeEvent * event )
{
if(firstResize)
......@@ -812,11 +852,11 @@ void DrawModule::createGui()
navigator->move(20,showToolsBut->pos().y()+showToolsBut->height());
navigator->hide();
CurScene->setDraw(this);
CurScene->setDraw(this,&mutex);
CurView->setScene(CurScene);
penColor.r = penColor.g = penColor.b = 0;
penColor.a = 255;
CurView->setDraw(this);
CurView->setDraw(this,&mutex);
CurView->centerOn(5,-5);
CurView->setViewportUpdateMode (QGraphicsView::NoViewportUpdate);//For better perfomance; Manual Update;
drawNet();
......@@ -1058,7 +1098,7 @@ void DrawModule::showNavigator(bool state)
// if(animate)redrawPicture();
mutex.unlock();
msleep(10);
// msleep(10);
}
/* public slot */ void DrawModule::runMoveBy(const qreal dX, const qreal dY)
......@@ -1076,7 +1116,8 @@ void DrawModule::showNavigator(bool state)
//if(animate)redrawPicture();
mutex.unlock();
msleep(10);
msleep(1);
}
/* public slot */ void DrawModule::runAddCaption(const qreal width, const QString& text)
......@@ -1223,7 +1264,7 @@ void DrawModule::drawNet()
navigator->updateSelf(NetStepX(),NetStepY());
CurView->update();
CurView->forceRedraw();
redrawPicture();
redraw();
};
void DrawModule::CreatePen(void)
{
......@@ -1276,6 +1317,7 @@ void DrawModule::redraw()
mutex.lock();
redrawPicture();
msleep(5);
// qApp->processEvents();
mutex.unlock();
}
......
......@@ -38,7 +38,7 @@ namespace ActorDraw {
public:
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("Слишком мелкая сетка"));};
void setDraw(DrawModule* draw){DRAW=draw;};
void setDraw(DrawModule* draw,QMutex* mutex){DRAW=draw;dr_mutex=mutex;};
double zoom()const
{return c_scale;};
void setZoom(double zoom);
......@@ -64,7 +64,9 @@ namespace ActorDraw {
void wheelEvent ( QWheelEvent * event );
void mousePressEvent ( QMouseEvent * event );
void mouseReleaseEvent ( QMouseEvent * event );
void mouseMoveEvent ( QMouseEvent * event );
void mouseMoveEvent ( QMouseEvent * event );
void paintEvent(QPaintEvent *event);
private:
DrawModule* DRAW;
double c_scale;
......@@ -73,6 +75,7 @@ namespace ActorDraw {
QPoint press_pos;
bool firstResize;
double lastStep;
QMutex* dr_mutex;
QLabel* smallNetLabel;
};
......@@ -80,22 +83,10 @@ namespace ActorDraw {
: public QGraphicsScene
{
public:
DrawScene ( QObject * parent = 0 ){};
DrawScene ( QObject * parent = 0 ){installEventFilter(this);};
void drawNet(double startx,double endx,double starty,double endy,QColor color,const double step,const double stepY,bool net,qreal nw,qreal aw);
void setDraw(DrawModule* draw){DRAW=draw;};
void addDrawLine(QLineF lineF,QColor color,qreal width)
{
if(lineF.length()==0)return;
QGraphicsLineItem* line=addLine(lineF);
QPen mp=QPen(QColor(color));
mp.setWidthF(width);
mp.setCosmetic(true);
line->setPen(mp);
line->setZValue(90);
lines.append(line);
}
void setDraw(DrawModule* draw,QMutex* mutex){DRAW=draw;dr_mutex=mutex;};
void addDrawLine(QLineF lineF,QColor color,qreal width);
void reset()
{
for(int i=0;i<lines.count();i++)
......@@ -115,6 +106,8 @@ namespace ActorDraw {
int loadFromFile(const QString& p_FileName);
protected:
// void resizeEvent ( QResizeEvent * event );
bool eventFilter(QObject *object, QEvent *event);
bool event(QEvent * event);
private:
bool isUserLine(QGraphicsItem*);//Return true if item is user item;
QList<QGraphicsLineItem*> lines;
......@@ -122,6 +115,7 @@ namespace ActorDraw {
QList<QGraphicsLineItem*> linesDubl;//Базовый чертеж
QList<QGraphicsSimpleTextItem*> texts;
DrawModule* DRAW;
QMutex* dr_mutex;
......@@ -201,6 +195,7 @@ public /* methods */:
}
QString initialize(const QStringList &configurationParameters, const ExtensionSystem::CommandLine &runtimeParameters);
QMutex mutex;
public slots:
void changeGlobalState(ExtensionSystem::GlobalState old, ExtensionSystem::GlobalState current);
void loadActorData(QIODevice * source);
......@@ -244,7 +239,7 @@ private:
bool penIsDrawing;
bool firstShow;
Color penColor;
QMutex mutex;
DrawNavigator* navigator;
QToolButton *showToolsBut;
QDir curDir;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment