Init
This commit is contained in:
129
graphicsviewmod.cpp
Normal file
129
graphicsviewmod.cpp
Normal file
@@ -0,0 +1,129 @@
|
||||
#include "graphicsviewmod.h"
|
||||
|
||||
|
||||
GraphicsViewMod::GraphicsViewMod(QWidget *parent):QGraphicsView(parent)
|
||||
{
|
||||
setViewportUpdateMode(QGraphicsView::FullViewportUpdate);
|
||||
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||
scMeter = 1;
|
||||
ugR = ugL = numT = 0;
|
||||
|
||||
}
|
||||
|
||||
|
||||
void GraphicsViewMod::drawBackground(QPainter *painter, const QRectF &rect)
|
||||
{
|
||||
|
||||
painter->save();
|
||||
painter->setBrush(QBrush(Qt::black));
|
||||
painter->drawRect(rect);
|
||||
painter->restore();
|
||||
|
||||
painter->setBackground(QBrush(Qt::black));
|
||||
painter->setBackground(QBrush(Qt::SolidPattern));
|
||||
|
||||
QPen p = painter->pen();
|
||||
painter->setPen(QColor(Qt::lightGray));
|
||||
|
||||
|
||||
qreal d = 30;
|
||||
qreal rad = height()/2 - d;
|
||||
QPointF cent=QPointF(width()/2, height()/2);
|
||||
QRect cr = QRect(cent.x()-rad, cent.y()-rad, rad*2, rad*2);
|
||||
|
||||
|
||||
|
||||
painter->drawEllipse(mapToScene(QPolygon(cr)).boundingRect());
|
||||
|
||||
qreal lx1, lx2, ly1, ly2;
|
||||
qreal phi;
|
||||
qreal lin = 2;
|
||||
QPolygonF poly;
|
||||
QString str;
|
||||
QFont f = painter->font();
|
||||
|
||||
cr.setSize(QSize(1,1));
|
||||
qreal fs = mapToScene(cr).boundingRect().height();
|
||||
|
||||
f.setPointSizeF(fs*10);
|
||||
painter->setFont(f);
|
||||
|
||||
|
||||
for (int i=0; i<60; i++)
|
||||
{
|
||||
phi = 2*M_PI/60*i;
|
||||
|
||||
lx1=(rad-lin)*sin(phi)+cent.x();
|
||||
ly1=-(rad-lin)*cos(phi)+cent.y();
|
||||
|
||||
lx2 = lx1+2*lin*sin(phi);
|
||||
ly2 = ly1-2*lin*cos(phi);
|
||||
|
||||
poly.clear();
|
||||
poly << mapToScene(QPoint(lx1, ly1)) << mapToScene(QPoint(lx2, ly2));
|
||||
painter->drawPolygon(poly);
|
||||
|
||||
lx2 = lx1+6*lin*sin(phi)-4;
|
||||
ly2 = ly1-6*lin*cos(phi)+4;
|
||||
|
||||
|
||||
str = QString::number(i);
|
||||
|
||||
|
||||
painter->drawText(mapToScene(QPoint(lx2, ly2)), str);
|
||||
|
||||
}
|
||||
|
||||
|
||||
int du, mdu;
|
||||
str.clear();
|
||||
if (ugL<0){ str.append("-");}
|
||||
|
||||
du = abs(ugL)/100; mdu = abs(ugL)%100;
|
||||
if (du<10) str.append("0");
|
||||
str.append(QString::number(du));
|
||||
str.append("-");
|
||||
if (mdu<10) str.append("0");
|
||||
str.append(QString::number(mdu));
|
||||
|
||||
painter->drawText(mapToScene(QPoint(width()-45, 22)), str);
|
||||
|
||||
str.clear();
|
||||
if (ugR<0) { str.append("-");}
|
||||
|
||||
du = abs(ugR)/100; mdu = abs(ugR)%100;
|
||||
if (du<10) str.append("0");
|
||||
str.append(QString::number(du));
|
||||
str.append("-");
|
||||
if (mdu<10) str.append("0");
|
||||
str.append(QString::number(mdu));
|
||||
|
||||
painter->drawText(mapToScene(QPoint(width()-45, 33)), str);
|
||||
|
||||
if (numT<0) numT = 0;
|
||||
str.setNum(numT);
|
||||
painter->drawText(mapToScene(QPoint(width()-45, 44)), str);
|
||||
|
||||
// str.setNum(scMeter);
|
||||
// painter->drawText(mapToScene(QPoint(cent.x()+40,cent.y()+40)), str);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void GraphicsViewMod::wheelEvent(QWheelEvent *e)
|
||||
{
|
||||
int num = e->delta()/120;
|
||||
if (num!=0)
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
e->accept();
|
||||
centerOn(0,0);
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user