436 lines
9.3 KiB
C++
436 lines
9.3 KiB
C++
#include "graphicsviewmod.h"
|
||
#include "widget.h"
|
||
|
||
GraphicsViewMod::GraphicsViewMod(QWidget *parent):QGraphicsView(parent)
|
||
{
|
||
setViewportUpdateMode(QGraphicsView::FullViewportUpdate);
|
||
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||
|
||
uid = 0;
|
||
drawCoords = false;
|
||
defSize = 10;
|
||
dScale = 5;
|
||
obj=0;
|
||
drawSpecialLine = false;
|
||
setMouseTracking(true);
|
||
}
|
||
|
||
|
||
|
||
void GraphicsViewMod::drawBackground(QPainter *painter, const QRectF &rect)
|
||
{
|
||
|
||
int x1, x2, y1, y2;
|
||
QPointF p1, p2;
|
||
QPointF l1, l2;
|
||
|
||
painter->save();
|
||
painter->setBrush(QBrush(Qt::black));
|
||
painter->drawRect(rect);
|
||
painter->restore();
|
||
|
||
painter->setBackground(QBrush(Qt::black));
|
||
painter->setBackground(QBrush(Qt::SolidPattern));
|
||
|
||
p1 = mapToScene(10, 10);
|
||
p2 = mapToScene(width()-10, height()-10);
|
||
QPointF pt;
|
||
pt = mapToScene(10,20);
|
||
defSize = pt.y()-p1.y();
|
||
|
||
x1= p1.x()/100; y1=p1.y()/100;
|
||
|
||
x2 = p2.x()/100+1; y2=p2.y()/100+1;
|
||
|
||
dScale = x2-x1;
|
||
|
||
if (drawCoords)
|
||
{
|
||
|
||
painter->setPen(QColor(Qt::darkGray));
|
||
|
||
|
||
|
||
|
||
QFont f = painter->font();
|
||
f.setPointSizeF(defSize);
|
||
painter->setFont(f);
|
||
|
||
|
||
for (int i=x1; i<x2; i++)
|
||
{
|
||
l1 = QPointF(i*100, p1.y());
|
||
l2 = QPointF(i*100, p2.y());
|
||
painter->drawLine(l1, l2);
|
||
|
||
if (dScale<30)
|
||
{
|
||
|
||
painter->drawText(l1, QString::number(i));
|
||
painter->drawText(l2, QString::number(i));
|
||
|
||
}
|
||
|
||
}
|
||
for (int i=y1; i<y2; i++)
|
||
{
|
||
l1 = QPointF(p1.x(), i*100);
|
||
l2 = QPointF(p2.x(), i*100);
|
||
painter->drawLine(l1, l2);
|
||
|
||
if (dScale<30)
|
||
{
|
||
|
||
painter->drawText(l1, QString::number(-i));
|
||
painter->drawText(l2, QString::number(-i));
|
||
|
||
}
|
||
|
||
}
|
||
|
||
|
||
}
|
||
|
||
|
||
x1=reper.x()-defSize/2; x2=reper.x()+defSize/2;
|
||
y1=reper.y()-defSize/2; y2=reper.y()+defSize/2;
|
||
painter->setPen(QColor(Qt::red));
|
||
painter->drawLine(x1,y1,x2,y2);
|
||
painter->drawLine(x1,y2,x2,y1);
|
||
|
||
|
||
|
||
|
||
|
||
|
||
}
|
||
|
||
|
||
void GraphicsViewMod::drawForeground(QPainter *painter, const QRectF &rect)
|
||
{
|
||
qreal dim, x, y;
|
||
QRectF target;
|
||
QImage pic;
|
||
QPointF p;
|
||
|
||
QFont f = painter->font();
|
||
f.setPointSizeF(defSize);
|
||
painter->setPen(Qt::lightGray);
|
||
painter->setFont(f);
|
||
|
||
|
||
if (dScale<30) dim = 2*defSize; else dim = 100;
|
||
|
||
|
||
groundObj *gro;
|
||
airObj *tarr;
|
||
|
||
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>*/
|
||
|
||
for (int i=0;i<obj->count(); i++)
|
||
{
|
||
|
||
gro = obj->at(i);
|
||
|
||
if (gro->exist)
|
||
{
|
||
|
||
p = gro->getPos();
|
||
x=p.x(); y=p.y();
|
||
target=QRectF(x, y-dim, dim, dim);
|
||
pic = gro->pic;
|
||
if (gro->boegotov)
|
||
pic.setColor(0, QColor(Qt::cyan).rgb());
|
||
else
|
||
pic.setColor(0, QColor(Qt::red).rgb());
|
||
|
||
painter->drawImage(target, pic);
|
||
|
||
if (i) painter->drawText(target.topRight(), QString::number(i));
|
||
}
|
||
}
|
||
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>*/
|
||
|
||
int cu;
|
||
QPen penCU;
|
||
QPointF ptar;
|
||
|
||
|
||
for (int i=0;i<tar->count(); i++)
|
||
{
|
||
tarr = tar->at(i);
|
||
if (tarr->exist)
|
||
{
|
||
p = tarr->getPos();
|
||
x=p.x(); y=p.y();
|
||
target=QRectF(x, y-dim, dim, dim);
|
||
pic = tarr->pic;
|
||
|
||
// pic.setColor(0, tarr->col.rgb() );
|
||
|
||
|
||
QLineF lf(0,0,tarr->vx,tarr->vy);
|
||
if (lf.angle()<90)
|
||
{
|
||
target.moveTop(y+dim/4*3);
|
||
} else
|
||
{
|
||
target.moveLeft(x+dim/2);
|
||
}
|
||
|
||
|
||
|
||
painter->setPen(QColor(tarr->col));
|
||
painter->drawImage(target, pic);
|
||
|
||
painter->save();
|
||
if (uid==1)
|
||
if (tarr->priznakAction)
|
||
{
|
||
penCU = painter->pen();
|
||
penCU.setColor(tarr->priznakColor);
|
||
penCU.setWidthF(2);
|
||
painter->setPen(penCU);
|
||
|
||
painter->drawRect(target);
|
||
}
|
||
painter->restore();
|
||
|
||
target.moveLeft(target.right());
|
||
target.setWidth(dim/2);
|
||
target.setHeight(dim/2);
|
||
|
||
|
||
pic = tarr->picAlt;
|
||
painter->drawImage(target, pic);
|
||
|
||
|
||
painter->drawText(target.bottomRight(), "8");
|
||
ptar = target.center();
|
||
ptar+=QPointF(0,dim);
|
||
painter->drawText(ptar, QString::number(tarr->numer+1));
|
||
|
||
|
||
for (int j=1; j<7; j++)
|
||
{
|
||
cu = tarr->CU[j];
|
||
if (cu)
|
||
{
|
||
painter->save();
|
||
|
||
penCU = painter->pen();
|
||
if (cu%20==1) penCU.setColor(Qt::green); else penCU.setColor(Qt::red);
|
||
if (cu>20) penCU.setStyle(Qt::DashLine); else penCU.setStyle(Qt::DotLine);
|
||
painter->setPen(penCU);
|
||
|
||
if (obj->at(j)->exist) painter->drawLine(p, obj->at(j)->getPos());
|
||
|
||
painter->restore();
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
}
|
||
|
||
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
||
if (drawSpecialLine)
|
||
{
|
||
painter->setPen(QColor(200, 0, 200));
|
||
painter->drawLine(QPointF(0,0), cursPos);
|
||
}
|
||
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> */
|
||
KO tKO;
|
||
QPointF p2Z;
|
||
QString st;
|
||
|
||
|
||
QDateTime curTime = QDateTime::currentDateTime();
|
||
int ms = curTime.time().second() ;
|
||
|
||
if (ms%2)
|
||
{
|
||
|
||
painter->save();
|
||
f.setPointSizeF(defSize-2);
|
||
painter->setFont(f);
|
||
painter->setPen(Qt::white);
|
||
|
||
|
||
|
||
|
||
int siz = ((Widget*)parent()->parent())->cmdKO.size();
|
||
for (int i=1; i<siz; i++)
|
||
{
|
||
tKO = (((Widget*)parent()->parent())->cmdKO.at(i)) ;
|
||
gro = obj->at(i);
|
||
if (gro->exist)
|
||
{
|
||
if (tKO.ZZ!=99)
|
||
{
|
||
if ((tKO.x==0)&&(tKO.y==0))
|
||
p2Z = gro->getPos();
|
||
else
|
||
p2Z = QPointF(tKO.x, tKO.y);
|
||
|
||
|
||
|
||
st = QString("%1 %2%3").arg(i).arg((tKO.ZZ<10)?"0":"").arg(tKO.ZZ);
|
||
painter->drawText(p2Z, st);
|
||
}
|
||
|
||
}
|
||
|
||
}
|
||
painter->restore();
|
||
|
||
|
||
}
|
||
}
|
||
|
||
void GraphicsViewMod::mouseMoveEvent(QMouseEvent *e)
|
||
{
|
||
QPoint p;
|
||
QPointF pf;
|
||
QWidget *w;
|
||
QString st;
|
||
|
||
if (uid == 1)
|
||
{
|
||
w = ((Widget*)parent()->parent())->openWidget;
|
||
if (w)
|
||
{
|
||
p = e->pos();
|
||
pf = mapToScene(p);
|
||
|
||
|
||
switch (((Widget*)parent()->parent())->openWidgetType)
|
||
{
|
||
case 1:
|
||
|
||
break;
|
||
default:
|
||
// drawSpecialLine = false;
|
||
break;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
drawSpecialLine=false;
|
||
}
|
||
|
||
}
|
||
e->accept();
|
||
}
|
||
|
||
|
||
void GraphicsViewMod::mouseReleaseEvent(QMouseEvent *e)
|
||
{
|
||
|
||
QPoint p;
|
||
QPointF pf;
|
||
int px, py;
|
||
QWidget *w;
|
||
QLineF lf;
|
||
qreal dist;
|
||
QString st;
|
||
|
||
if (uid==1)
|
||
{
|
||
if (e->button() & Qt::RightButton)
|
||
{
|
||
p = e->pos();
|
||
QPointF p1;
|
||
|
||
QPointF pSc = mapToScene(p);
|
||
|
||
airObj *ao;
|
||
for (int i=0; i<tar->count(); i++)
|
||
{
|
||
ao = tar->at(i);
|
||
if (ao->exist)
|
||
{
|
||
p1 =ao->getPos()-pSc;
|
||
if (p1.manhattanLength()<30)
|
||
{
|
||
((Widget*)parent()->parent())->curAirTicketNum=ao->numer;
|
||
QTimer::singleShot(100, ((Widget*)parent()->parent()), SLOT(msAirTicketFree()) );
|
||
break;
|
||
|
||
}
|
||
|
||
}
|
||
}
|
||
|
||
|
||
}
|
||
|
||
|
||
if (e->button() & Qt::LeftButton)
|
||
{
|
||
if (e->modifiers() & Qt::ShiftModifier)
|
||
{
|
||
p=e->pos();
|
||
pf = mapToScene(p);
|
||
lf = QLineF(QPointF(0,0), pf);
|
||
|
||
dist = lf.length()/10;
|
||
px = int (pf.x()*100);
|
||
py = int (pf.y()*100);
|
||
st = QString(" [%1 %2] d=").arg(px).arg(py);
|
||
st.append(QString::number(dist, 'f', 2));
|
||
((Widget*)parent()->parent())->addLogText(st);
|
||
}
|
||
|
||
w = ((Widget*)parent()->parent())->openWidget;
|
||
if (w)
|
||
{
|
||
p = e->pos();
|
||
pf = mapToScene(p);
|
||
|
||
px = -int(pf.y()*100);
|
||
py = int(pf.x()*100);
|
||
|
||
switch (((Widget*)parent()->parent())->openWidgetType)
|
||
{
|
||
case 2: // <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><>
|
||
|
||
((vvod2z*)w)->setCoord(px, py);
|
||
|
||
// ((Widget*)parent()->parent())->addLogText(QString("[%1] [%2]").arg(px).arg(py));
|
||
|
||
break;
|
||
|
||
case 1: // <20><><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD>_<EFBFBD><5F><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
((vvodSectOtvet*)w)->setAngles(pf);
|
||
|
||
default:
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
if (uid==2)
|
||
{
|
||
if (e->button() & Qt::LeftButton)
|
||
{
|
||
p = e->pos();
|
||
pf = mapToScene(p);
|
||
((Widget*)parent()->parent())->setCentr(pf);
|
||
|
||
}
|
||
|
||
}
|
||
e->accept();
|
||
}
|
||
|
||
void GraphicsViewMod::wheelEvent(QWheelEvent *e)
|
||
{
|
||
|
||
|
||
e->ignore();
|
||
|
||
|
||
}
|