kuznec.cpp 39.7 KB
Newer Older
Denis Khachko's avatar
Denis Khachko committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
//****************************************************************************
//**
//** Copyright (C) 2004-2014 IMPB RAS. All rights reserved.
//**
//** This file is part of the KuMir.
//**
//** This file may be used under the terms of the GNU General Public
//** License version 2.0 as published by the Free Software Foundation
//** and appearing in the file LICENSE.GPL included in the packaging of
//** this file.
//**
//** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
//** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
//**
//****************************************************************************/

//begin 14-02-2008

#include "kuznec.h"
#include "dialog.h"
#include "pult.h"
22
#include "grasshoppermodule.h"
Denis Khachko's avatar
Denis Khachko committed
23

Alexander A. Maly's avatar
Alexander A. Maly committed
24 25
#include <QGraphicsSimpleTextItem>
#include <QCloseEvent>
Alexander A. Maly's avatar
Alexander A. Maly committed
26 27 28 29 30 31 32 33 34
#include <QGraphicsSceneMouseEvent>
#include <QGraphicsSceneWheelEvent>
#include <QMessageBox>
#include <QDesktopServices>
#include <QMenu>
#include <QMenuBar>
#include <QLineEdit>
#include <QFileDialog>
#include <math.h>
Alexander A. Maly's avatar
Alexander A. Maly committed
35 36 37


void DrawView:: scrollContentsBy(int dx, int dy)
Denis Khachko's avatar
Denis Khachko committed
38 39
{
//qDebug() << QString("SCROLL EVENT ") << dx << " " << dy;
Alexander A. Maly's avatar
Alexander A. Maly committed
40
	QGraphicsView::scrollContentsBy(dx,  dy);
Denis Khachko's avatar
Denis Khachko committed
41 42 43
}


Alexander A. Maly's avatar
Alexander A. Maly committed
44 45
DrawView::DrawView(QGraphicsScene *scene, QWidget *window) :
	QGraphicsView(scene, window)
Denis Khachko's avatar
Denis Khachko committed
46 47 48 49
{
}


Alexander A. Maly's avatar
Alexander A. Maly committed
50
KumScene::KumScene(QWidget *parent) : QGraphicsScene(parent)
Denis Khachko's avatar
Denis Khachko committed
51
{
Alexander A. Maly's avatar
Alexander A. Maly committed
52
}
Denis Khachko's avatar
Denis Khachko committed
53 54


Alexander A. Maly's avatar
Alexander A. Maly committed
55
void KumScene::mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent)
Denis Khachko's avatar
Denis Khachko committed
56
{
Alexander A. Maly's avatar
Alexander A. Maly committed
57 58 59 60 61 62
	bool LeftButtonFlag;
	if (mouseEvent->button() == 0x00000001) {
		LeftButtonFlag = true;
	} else {
		LeftButtonFlag = false;
	}
Denis Khachko's avatar
Denis Khachko committed
63

Alexander A. Maly's avatar
Alexander A. Maly committed
64 65 66 67 68 69
	QPointF posScene = mouseEvent->scenePos();
	QPointF pos = mouseEvent->screenPos();
	qreal x = pos.x();
	qreal y = pos.y();
	qreal xScene = posScene.x();
	qreal yScene = posScene.y();
Denis Khachko's avatar
Denis Khachko committed
70

Alexander A. Maly's avatar
Alexander A. Maly committed
71 72
	emit MousePress(x, y, LeftButtonFlag, xScene, yScene);
};
Denis Khachko's avatar
Denis Khachko committed
73

Alexander A. Maly's avatar
Alexander A. Maly committed
74
void KumScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *mouseEvent)
Denis Khachko's avatar
Denis Khachko committed
75
{
Alexander A. Maly's avatar
Alexander A. Maly committed
76
	bool LeftButtonFlag = false;
Denis Khachko's avatar
Denis Khachko committed
77
//qWarning("robot release");
Alexander A. Maly's avatar
Alexander A. Maly committed
78 79 80
	if (mouseEvent->button() == 0x00000001) {
		LeftButtonFlag = true;
	}
Denis Khachko's avatar
Denis Khachko committed
81

Alexander A. Maly's avatar
Alexander A. Maly committed
82 83 84 85
	QPointF pos = mouseEvent->screenPos();
	qreal x = pos.x();
	qreal y = pos.y();
	emit MouseRelease(x, y, LeftButtonFlag);
Denis Khachko's avatar
Denis Khachko committed
86 87
}

Alexander A. Maly's avatar
Alexander A. Maly committed
88
void KumScene::mouseMoveEvent(QGraphicsSceneMouseEvent *mouseEvent)
Denis Khachko's avatar
Denis Khachko committed
89
{
Alexander A. Maly's avatar
Alexander A. Maly committed
90
	bool LeftButtonFlag = false;
Denis Khachko's avatar
Denis Khachko committed
91
//qWarning("robot move");
Alexander A. Maly's avatar
Alexander A. Maly committed
92 93 94 95 96 97 98 99 100
	if (mouseEvent->button() == 0x00000001) {
		LeftButtonFlag = true;
	}

	QPoint pos = mouseEvent->screenPos();
	int x = pos.x();
	int y = pos.y();
	emit MouseMove(x, y, LeftButtonFlag);
	QGraphicsScene::mouseMoveEvent(mouseEvent);
Denis Khachko's avatar
Denis Khachko committed
101 102
}

Alexander A. Maly's avatar
Alexander A. Maly committed
103 104 105
void KumScene::wheelEvent(QGraphicsSceneWheelEvent *wheelEvent)
{
	int Delta = wheelEvent->delta();
Denis Khachko's avatar
Denis Khachko committed
106
//qWarning("wheelEvent %i",Delta);
Alexander A. Maly's avatar
Alexander A. Maly committed
107
	emit MouseWheel(Delta);
Denis Khachko's avatar
Denis Khachko committed
108 109
}

Alexander A. Maly's avatar
Alexander A. Maly committed
110 111 112
//------------------------

KuznSled::KuznSled(int start, int fin)
Denis Khachko's avatar
Denis Khachko committed
113
{
Alexander A. Maly's avatar
Alexander A. Maly committed
114 115 116 117
	St = start;
	Fn = fin;
	Intens = 0;
}
Denis Khachko's avatar
Denis Khachko committed
118

Alexander A. Maly's avatar
Alexander A. Maly committed
119 120 121 122 123 124 125 126 127 128 129
void KuznSled::paint(
	QPainter *painter,
	const QStyleOptionGraphicsItem *option,
	QWidget *widget
) {
	QPen black(QColor(Intens, Intens, Intens));
	qDebug() << "ABS " << abs(Fn - St);
	painter->setPen(black);
	painter->drawArc(St, 0, Fn, 32, 0, 360 * 8);
	//qDebug()<<"SLED PAINT";
}
Denis Khachko's avatar
Denis Khachko committed
130 131 132

//-------------------------------------------------------------------------------

Alexander A. Maly's avatar
Alexander A. Maly committed
133
void KumKuznec::showHideWindow(bool show) //Show - true
Denis Khachko's avatar
Denis Khachko committed
134
{
Alexander A. Maly's avatar
Alexander A. Maly committed
135 136
	MV->showNormal();
}
Denis Khachko's avatar
Denis Khachko committed
137 138 139

void KumKuznec::Close()
{
Alexander A. Maly's avatar
Alexander A. Maly committed
140 141 142
	qDebug() << "KUZNEC CLOSE Close";
	if ((Kpult->getLibMode()) || (autoClose)) {
		close();
Denis Khachko's avatar
Denis Khachko committed
143

Alexander A. Maly's avatar
Alexander A. Maly committed
144 145 146 147 148 149
		return;
	}
	Kpult->close();
}

void KumKuznec::resizeEvent(QResizeEvent *event)
Denis Khachko's avatar
Denis Khachko committed
150
{
Alexander A. Maly's avatar
Alexander A. Maly committed
151 152 153 154 155 156 157 158
	qDebug() << "RESIZE" << event->size();
	qDebug() << "RESIZE old:" << event->oldSize();
	if (event->oldSize() == QSize(-1, -1)) {
		return;
	}
	int Delta = SizeX;
	SizeX = event->size().width();
//SizeY=event->size().height ()-MenuHigth;
Denis Khachko's avatar
Denis Khachko committed
159

Alexander A. Maly's avatar
Alexander A. Maly committed
160 161 162 163 164 165 166 167 168 169 170
	Delta -= SizeX;
	qDebug() << "Delta" << Delta;
	SetWindowSize(10, 10, SizeX, SizeY);
	resize(event->size());
	qDebug() << "SizeX" << SizeX;

}

KumKuznec::KumKuznec(const QDir &mresd)
{
	autoClose = false;
Victor Yacovlev's avatar
Victor Yacovlev committed
171
#if QT_VERSION >= 0x050000
Alexander A. Maly's avatar
Alexander A. Maly committed
172
	curDir = QStandardPaths::standardLocations(QStandardPaths::DocumentsLocation).first();
Victor Yacovlev's avatar
Victor Yacovlev committed
173
#else
Alexander A. Maly's avatar
Alexander A. Maly committed
174
	curDir = QDesktopServices::storageLocation(QDesktopServices::DocumentsLocation);
Victor Yacovlev's avatar
Victor Yacovlev committed
175
#endif
Alexander A. Maly's avatar
Alexander A. Maly committed
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223
	if (!QDir(curDir).exists()) {
		QDir::root().mkpath(curDir);
	}
	curMode = 4;
	moving = false;

	MV = new QMainWindow();
	Kpult = new GrasshopperPult(mresd, this);
	MV->setAttribute(Qt::WA_KeyboardFocusChange, false);
	MV->setGeometry(10, 10, 500, 500);
	QIcon icon(":/grasshopper.png");
	Q_ASSERT(!icon.isNull());
	MV->setWindowIcon(icon);

	MV->setWindowTitle(QString::fromUtf8("Кузнечик - нет файла"));
	QPalette PallGrey;
	MV->setPalette(PallGrey);
	CreateMenu(); // debug09

	scene = new KumScene(MV);
	viewFrame = new QFrame(MV);
	viewFrame->setGeometry(0, MenuHigth + 1, DEFAULT_SIZEX, DEFAULT_SIZEY - MenuHigth);
	view = new DrawView(scene, viewFrame);
	view->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
	view->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);

	connect(scene, SIGNAL(MousePress(qreal, qreal, bool, qreal, qreal)), this, SLOT(MousePress(qreal, qreal, bool, qreal, qreal)));
	connect(scene, SIGNAL(MouseRelease(qreal, qreal, bool)), this, SLOT(MouseRelease(qreal, qreal, bool)));
	connect(scene, SIGNAL(MouseMove(int, int, bool)), this, SLOT(MouseMove(int, int, bool)));
	connect(scene, SIGNAL(MouseWheel(int)), this, SLOT(MouseWheel(int)));
	this->setGeometry(MV->geometry());

	scene->setBackgroundBrush(QBrush(QColor("lightgreen")));
	StepX = 1.;
	StepY = 1.;
	SizeX = DEFAULT_SIZEX;
	SizeY = DEFAULT_SIZEY;
	this->setFixedHeight(SizeY + MenuHigth + 2);
	ButtonSdwig = 100;
	SqwareNetFlag = true;
	NetShowFlag = true;
	TmpNetShowFlag = true;
	LeftMousePressFlag = false;
	lines.clear();

	Createbtn12();
	Createbtn13();
	CreateXYLabel();
Denis Khachko's avatar
Denis Khachko committed
224 225

	WindowZoom = 1;
Alexander A. Maly's avatar
Alexander A. Maly committed
226 227 228
	WindowX0 = -SizeX / 2;
	WindowY0 = -SizeY / 2;

Denis Khachko's avatar
Denis Khachko committed
229 230 231 232 233 234 235
	NLastVec = 0;
	CurColor.Red = 0;
	CurColor.Green = 0;
	CurColor.Blue = 0;
	CurY = 0;
	CurX = 0;
	CurZ = 1;
Alexander A. Maly's avatar
Alexander A. Maly committed
236 237 238
	leftBorder = 0;
	rightBorder = 0;
	borderEnable = false;
Denis Khachko's avatar
Denis Khachko committed
239

Alexander A. Maly's avatar
Alexander A. Maly committed
240
	startPos = 0;
Denis Khachko's avatar
Denis Khachko committed
241 242
	PenPosition = true;
	mPen = NULL;
Alexander A. Maly's avatar
Alexander A. Maly committed
243 244
	SdwigNetX = 0.;
	SdwigNetY = 0.;
Denis Khachko's avatar
Denis Khachko committed
245 246

	CreatePen();
Alexander A. Maly's avatar
Alexander A. Maly committed
247 248 249
	SetColorString(QString::fromUtf8("красный"));
	MinZoom = 0.5;
	MaxZoom = 2;
Denis Khachko's avatar
Denis Khachko committed
250

Alexander A. Maly's avatar
Alexander A. Maly committed
251 252 253 254
	SetWindowSize(10, 10, SizeX, SizeY);
	WindowZoom = BASEZOOM;
	WindowX0 =  - SizeX / (WindowZoom);
	WindowY0 =  - SizeY / (WindowZoom * 2) - 1;
Denis Khachko's avatar
Denis Khachko committed
255

Alexander A. Maly's avatar
Alexander A. Maly committed
256
	connect(scene, SIGNAL(sceneRectChanged(QRectF)), view, SLOT(updateSceneRect(QRectF)));
Denis Khachko's avatar
Denis Khachko committed
257

Alexander A. Maly's avatar
Alexander A. Maly committed
258 259
	view->scale(BASEZOOM, BASEZOOM);
	view->centerOn(0, YCENTER);
Denis Khachko's avatar
Denis Khachko committed
260

Alexander A. Maly's avatar
Alexander A. Maly committed
261
	qDebug() << "Center: " << view->mapToScene(view->viewport()->rect().center()) << " YCENTER=" << YCENTER;
Denis Khachko's avatar
Denis Khachko committed
262

Alexander A. Maly's avatar
Alexander A. Maly committed
263 264
	WindowX0 = visibleRect().x();
	WindowY0 = visibleRect().y();
Denis Khachko's avatar
Denis Khachko committed
265

Alexander A. Maly's avatar
Alexander A. Maly committed
266 267 268 269
	RightMousePressFlag = false;
	Fstep = 3;
	Bstep = 2;
	Finish = 1;
Denis Khachko's avatar
Denis Khachko committed
270

Alexander A. Maly's avatar
Alexander A. Maly committed
271 272
	//Risuem flag:
	static const int points[] = { 0, 2, 2, 2, 1, 1, 2, 0, 0, 0, 0, 4};
Denis Khachko's avatar
Denis Khachko committed
273

Alexander A. Maly's avatar
Alexander A. Maly committed
274 275
	QPolygon polygon;
	polygon.setPoints(6, points);
Denis Khachko's avatar
Denis Khachko committed
276 277
	QPolygonF polygonf = QPolygonF(polygon);

Alexander A. Maly's avatar
Alexander A. Maly committed
278
	mFlag = new QGraphicsPolygonItem();
Denis Khachko's avatar
Denis Khachko committed
279 280
	mFlag->setPolygon(polygonf);
	mFlag->setZValue(100);
Alexander A. Maly's avatar
Alexander A. Maly committed
281 282 283 284 285 286 287
	mFlag->setBrush(QBrush(QColor(150, 100, 100)));
	mFlag->setRotation(180);
	mFlag->setScale(0.5);
	mFlag->moveBy(0, 0);

	mFlagLine = new QGraphicsLineItem(0, 0, 0, -1.5);
	mFlagLine->setPen(QPen(QColor(0, 0, 0)));
Denis Khachko's avatar
Denis Khachko committed
288
	mFlagLine->setZValue(100);
289

Alexander A. Maly's avatar
Alexander A. Maly committed
290
	redrawFlags();
291

Alexander A. Maly's avatar
Alexander A. Maly committed
292 293 294 295
	//Reset();
	mPen->setPos(0, -0.25);
	mPen->setBrush(QBrush(QColor("blue")));
	scene->addItem(new QGraphicsLineItem(0, -ZOOMMULTIP * 2, 0, -ZOOMMULTIP * 2 + 0.0005));
Denis Khachko's avatar
Denis Khachko committed
296

Alexander A. Maly's avatar
Alexander A. Maly committed
297 298 299 300
	fileName = "";
	advancedTask = false;
	MV->hide();
}
Denis Khachko's avatar
Denis Khachko committed
301 302 303


//сдвиг на вектор
Alexander A. Maly's avatar
Alexander A. Maly committed
304
int KumKuznec::GoVector(double DeltaXX, double DeltaYY)
Denis Khachko's avatar
Denis Khachko committed
305 306 307 308 309 310
{
	qreal x1 = CurX;
	qreal y1 = -CurY;

	qreal x2 = CurX + DeltaXX;
	qreal y2 = -(CurY + DeltaYY);
Alexander A. Maly's avatar
Alexander A. Maly committed
311 312 313 314 315 316 317 318 319 320 321 322 323
	PenPosition = false;
	if (PenPosition) {
		mPen->setBrush(QBrush(QColor(CurColor.Red, CurColor.Green, CurColor.Blue)));
		lines.append(scene->addLine(x1, y1, x2, y2));
		lines.last()->setZValue(CurZ);
		lines.last()->setPen(QPen(QColor(CurColor.Red, CurColor.Green, CurColor.Blue)));
		CurZ += 0.01;
		CurX += DeltaXX;
		CurY += DeltaYY;
	} else {
		//QGraphicsLineItem *tmp = new QGraphicsLineItem(x1, y1 , x2, y2 );
		//lines.append(tmp);
		//mPen->setBrush(QBrush(QColor("white")));
Denis Khachko's avatar
Denis Khachko committed
324 325 326
		CurX += DeltaXX;
		CurY += DeltaYY;
	}
Alexander A. Maly's avatar
Alexander A. Maly committed
327
	mPen->setPos(CurX, -CurY);
Denis Khachko's avatar
Denis Khachko committed
328
	redrawFlags();
Alexander A. Maly's avatar
Alexander A. Maly committed
329
	return 0;
Denis Khachko's avatar
Denis Khachko committed
330 331 332 333 334 335 336
}

//опустить перо
void KumKuznec::PenDown()
{
	PenPosition = true;
}
Alexander A. Maly's avatar
Alexander A. Maly committed
337

Denis Khachko's avatar
Denis Khachko committed
338 339 340 341 342
//поднять перо
void KumKuznec::PenUp()
{
	PenPosition = false;
}
Alexander A. Maly's avatar
Alexander A. Maly committed
343

Denis Khachko's avatar
Denis Khachko committed
344
//переход в точку
Alexander A. Maly's avatar
Alexander A. Maly committed
345
int KumKuznec::GoPoint(double xx, double yy)
Denis Khachko's avatar
Denis Khachko committed
346 347 348
{
	double DeltaX = xx - CurX;
	double DeltaY = yy - CurY;
Alexander A. Maly's avatar
Alexander A. Maly committed
349 350 351

	GoVector(DeltaX, DeltaY);

Denis Khachko's avatar
Denis Khachko committed
352 353 354 355 356 357
	return 0;
}

//----------------------------------------------------------------------------
//--------------------------------------------------------------
// сдвиг окна в мировых координатах
Alexander A. Maly's avatar
Alexander A. Maly committed
358
//void KumKuznec::SetWindowPosition(double x0,double y0, double zoom)
Denis Khachko's avatar
Denis Khachko committed
359 360 361 362 363 364 365 366 367
//{
//}
//-----------------------------------------------------------------------

//-------------------------------------------------------------------
//сдвиг окна вправо
void KumKuznec::MoveRight(void)
{

Alexander A. Maly's avatar
Alexander A. Maly committed
368 369
	WindowX0 = WindowX0 - SizeX / WindowZoom / 4;

Denis Khachko's avatar
Denis Khachko committed
370 371 372 373 374 375 376 377
	WindowRedraw();

}
//------------------------------------------------------
//сдвиг окна влево
void KumKuznec::MoveLeft(void)
{

Alexander A. Maly's avatar
Alexander A. Maly committed
378 379
	WindowX0 = WindowX0 + SizeX / WindowZoom / 4;

Denis Khachko's avatar
Denis Khachko committed
380 381 382 383 384 385 386
	WindowRedraw();

}
//-----------------------------------------------------
//сдвиг окна вверх
void KumKuznec::MoveUp(void)
{
Alexander A. Maly's avatar
Alexander A. Maly committed
387 388
	WindowY0 = WindowY0 - SizeY / WindowZoom / 4;

Denis Khachko's avatar
Denis Khachko committed
389 390 391 392 393 394
	WindowRedraw();
}
//-----------------------------------------------------
//сдвиг окна вниз
void KumKuznec::MoveDown(void)
{
Alexander A. Maly's avatar
Alexander A. Maly committed
395 396
	WindowY0 = WindowY0 + SizeY / WindowZoom / 4;

Denis Khachko's avatar
Denis Khachko committed
397 398 399 400 401
	WindowRedraw();
}
//-----------------------------------------------------
void KumKuznec::ZoomUp(void)
{
Alexander A. Maly's avatar
Alexander A. Maly committed
402 403 404 405
	if (WindowZoom > MaxZoom) {
		return;
	}

Denis Khachko's avatar
Denis Khachko committed
406 407 408



Denis Khachko's avatar
Denis Khachko committed
409

Alexander A. Maly's avatar
Alexander A. Maly committed
410
	WindowZoom = WindowZoom * 2;
Denis Khachko's avatar
Denis Khachko committed
411 412 413


	//(WindowZoom>64)WindowY0 -= 1;
Alexander A. Maly's avatar
Alexander A. Maly committed
414
	view->scale(2., 2.);
Denis Khachko's avatar
Denis Khachko committed
415
	//view->centerOn(CenterX,0);
Alexander A. Maly's avatar
Alexander A. Maly committed
416 417 418
	WindowX0 = visibleRect().x();
	WindowY0 = visibleRect().y();
	qDebug() << "Zoom" << WindowZoom << " viewRECT" << view->sceneRect() << "sceneRect" << scene->sceneRect();
Denis Khachko's avatar
Denis Khachko committed
419
	//WindowRedraw();
Alexander A. Maly's avatar
Alexander A. Maly committed
420

Denis Khachko's avatar
Denis Khachko committed
421
	//if(WindowZoom>64){MoveDown();MoveDown();qDebug()<<"MOVE DOWN";};
Alexander A. Maly's avatar
Alexander A. Maly committed
422

Denis Khachko's avatar
Denis Khachko committed
423 424 425 426 427

}
//--------------------------------------------------
void KumKuznec::ZoomDown(void)
{
Alexander A. Maly's avatar
Alexander A. Maly committed
428 429 430
	if (WindowZoom < MinZoom) {
		return;
	}
Denis Khachko's avatar
Denis Khachko committed
431 432


Denis Khachko's avatar
Denis Khachko committed
433

Denis Khachko's avatar
Denis Khachko committed
434
	//if(WindowZoom>64)WindowY0 += 1;
Alexander A. Maly's avatar
Alexander A. Maly committed
435 436
	WindowZoom = WindowZoom / 2;

Denis Khachko's avatar
Denis Khachko committed
437 438

	QPointF center_p = view->mapToScene(view->viewport()->rect().center());
Alexander A. Maly's avatar
Alexander A. Maly committed
439
	view->scale(0.5, 0.5);
Denis Khachko's avatar
Denis Khachko committed
440
	//view->centerOn(CenterX,0);
Alexander A. Maly's avatar
Alexander A. Maly committed
441 442 443

	WindowX0 = visibleRect().x();
	WindowY0 = visibleRect().y();
Denis Khachko's avatar
Denis Khachko committed
444
	//view->centerOn(CenterX,0);
Alexander A. Maly's avatar
Alexander A. Maly committed
445
	qDebug() << "Zoom OUT" << WindowZoom << "SCENE RECT" << view->sceneRect() << "ViewRect" << visibleRect() << "Center" << center_p;
Denis Khachko's avatar
Denis Khachko committed
446 447 448 449
}
//-------------------------------------------------------------------
void KumKuznec::lockControls()
{
Alexander A. Maly's avatar
Alexander A. Maly committed
450 451 452
	/*
	    if  ( btnBox->isEnabled() )
	        btnBox->setEnabled(false);
Denis Khachko's avatar
Denis Khachko committed
453

Alexander A. Maly's avatar
Alexander A. Maly committed
454
	*/
Denis Khachko's avatar
Denis Khachko committed
455 456 457 458
}
//----------------------------------------
void KumKuznec::unlockControls()
{
Alexander A. Maly's avatar
Alexander A. Maly committed
459 460 461 462
	/*
	    if ( !btnBox->isEnabled() )
	        btnBox->setEnabled(true);
	*/
Denis Khachko's avatar
Denis Khachko committed
463 464 465 466 467
}
//----------------------------------------------------------
//сохранение в ps-файл
int KumKuznec::SaveToFile(QString p_FileName)
{
Alexander A. Maly's avatar
Alexander A. Maly committed
468 469 470 471
	QFile l_File(p_FileName);
	char ctmp[200];
	if (!l_File.open(QIODevice::WriteOnly)) {
		return 1;
Denis Khachko's avatar
Denis Khachko committed
472
	}
Alexander A. Maly's avatar
Alexander A. Maly committed
473

Denis Khachko's avatar
Denis Khachko committed
474
	//QString ttt = QString::fromUtf8("Чертежник - Начало");
Alexander A. Maly's avatar
Alexander A. Maly committed
475 476 477

//l_File.write( ttt.toUtf8());
	l_File.write("%!PS-Adobe-1.0 EPSF-1.0\n");
Denis Khachko's avatar
Denis Khachko committed
478
	QString l_String;
Alexander A. Maly's avatar
Alexander A. Maly committed
479
	l_File.write("%%Creator: Cherteznik\n");
Denis Khachko's avatar
Denis Khachko committed
480 481 482
	l_File.write("%%Pages: 1\n");
	l_File.write("%%Orientation: Portrait\n");

Alexander A. Maly's avatar
Alexander A. Maly committed
483

Denis Khachko's avatar
Denis Khachko committed
484 485
	// maximum, minimum

Alexander A. Maly's avatar
Alexander A. Maly committed
486 487 488
	qreal MinX, MaxX, MinY, MaxY, VecX1, VecX2, VecY1, VecY2;

	QLineF TmpLine;
Denis Khachko's avatar
Denis Khachko committed
489 490 491 492 493 494 495
	MinX = 1000000;
	MinY = 1000000;

	MaxX = -1000000;
	MaxY = -1000000;


Alexander A. Maly's avatar
Alexander A. Maly committed
496 497
	for (int i = 0; i < lines.count(); i++) {

Denis Khachko's avatar
Denis Khachko committed
498 499 500 501 502
		TmpLine = lines[i]->line();
		VecX1 = TmpLine.x1();
		VecY1 = -TmpLine.y1();
		VecX2 = TmpLine.x2();
		VecY2 = -TmpLine.y2();
Alexander A. Maly's avatar
Alexander A. Maly committed
503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527
		if (VecX1 < MinX) {
			MinX = VecX1;
		}
		if (VecY1 < MinY) {
			MinY = VecY1;
		}
		if (VecX1 > MaxX) {
			MaxX = VecX1;
		}
		if (VecY1 > MaxY) {
			MaxY = VecY1;
		}

		if (VecX2 < MinX) {
			MinX = VecX2;
		}
		if (VecY2 < MinY) {
			MinY = VecY2;
		}
		if (VecX2 > MaxX) {
			MaxX = VecX2;
		}
		if (VecY2 > MaxY) {
			MaxY = VecY2;
		}
Denis Khachko's avatar
Denis Khachko committed
528 529 530 531

	}
	double Scale;

Alexander A. Maly's avatar
Alexander A. Maly committed
532 533 534 535
	if (MaxX - MinX > MaxY - MinY) {
		Scale = (596 - 10) / (MaxX - MinX);
	} else {
		Scale = (842 - 10) / (MaxY - MinY);
Denis Khachko's avatar
Denis Khachko committed
536
	}
Alexander A. Maly's avatar
Alexander A. Maly committed
537 538
	Scale = Scale * 0.9;

Denis Khachko's avatar
Denis Khachko committed
539
//	QString tmp1 = QString(ctmp)+" scale\n";
Alexander A. Maly's avatar
Alexander A. Maly committed
540 541 542



Denis Khachko's avatar
Denis Khachko committed
543 544
	l_File.write("%%BoundingBox: 0 0 596 842\n");
	l_File.write("%%HiResBoundingBox: 0 0 596 842\n");
Alexander A. Maly's avatar
Alexander A. Maly committed
545 546 547
	l_File.write("%%EndComments\n");
	l_File.write("%%Page: 1 1\n");
	sprintf(ctmp, "%f %f translate\n", -MinX, -MinY);
Denis Khachko's avatar
Denis Khachko committed
548
	l_File.write(ctmp);
Alexander A. Maly's avatar
Alexander A. Maly committed
549
	sprintf(ctmp, "%f %f scale\n", Scale, Scale);
Denis Khachko's avatar
Denis Khachko committed
550 551 552 553 554 555 556 557
	l_File.write(ctmp);
	l_File.write("gsave [1 0 0 1 0 0] concat\n");
	l_File.write("0 0 0 setrgbcolor\n");
	l_File.write("[] 0 setdash\n");
	l_File.write("1 setlinewidth\n");
	l_File.write("0 setlinejoin\n");
	l_File.write("0 setlinecap\n");
	l_File.write("newpath\n");
Alexander A. Maly's avatar
Alexander A. Maly committed
558 559 560 561 562
//QColor TmpColor;
	QPen TmpPen;
	QColor TmpColor;
	for (int i = 0; i < lines.count(); i++) {

Denis Khachko's avatar
Denis Khachko committed
563 564 565
		TmpLine = lines[i]->line();
		TmpPen = lines[i]->pen();
		TmpColor = TmpPen.color();
Alexander A. Maly's avatar
Alexander A. Maly committed
566
		sprintf(ctmp, "%i %i %i setrgbcolor\n", TmpColor.red(),  TmpColor.green(), TmpColor.blue());
Denis Khachko's avatar
Denis Khachko committed
567
		l_File.write(ctmp);
Alexander A. Maly's avatar
Alexander A. Maly committed
568

Denis Khachko's avatar
Denis Khachko committed
569 570 571 572
		VecX1 = TmpLine.x1();
		VecY1 = -TmpLine.y1();
		VecX2 = TmpLine.x2();
		VecY2 = -TmpLine.y2();
Alexander A. Maly's avatar
Alexander A. Maly committed
573 574

		sprintf(ctmp, "%f %f moveto\n", VecX1, VecY1);
Denis Khachko's avatar
Denis Khachko committed
575
		l_File.write(ctmp);
Alexander A. Maly's avatar
Alexander A. Maly committed
576 577 578

		sprintf(ctmp, "%f %f lineto\n", VecX2, VecY2);

Denis Khachko's avatar
Denis Khachko committed
579 580 581 582 583
		l_File.write(ctmp);


	}

Alexander A. Maly's avatar
Alexander A. Maly committed
584
	for (int i = 0; i < kumtexts.count(); i++) {
Alexander A. Maly's avatar
Alexander A. Maly committed
585
		qreal FontSize = kumtexts[i]->Size;
Alexander A. Maly's avatar
Alexander A. Maly committed
586 587
		sprintf(ctmp, "/Curier findfont %f scalefont setfont\n", FontSize);
		l_File.write(ctmp);
Denis Khachko's avatar
Denis Khachko committed
588

Alexander A. Maly's avatar
Alexander A. Maly committed
589 590
		qreal tmpX = kumtexts[i]->x;
		qreal tmpY = kumtexts[i]->y;
Alexander A. Maly's avatar
Alexander A. Maly committed
591 592
		sprintf(ctmp, "%f %f moveto\n", tmpX, tmpY);
		l_File.write(ctmp);
Denis Khachko's avatar
Denis Khachko committed
593 594


Alexander A. Maly's avatar
Alexander A. Maly committed
595 596 597 598 599
		//TmpPen = texts[i]->pen();
		//TColor = TmpPen.color();
		sprintf(ctmp, "%i %i %i setrgbcolor\n", kumtexts[i]->color.Red,  kumtexts[i]->color.Green, kumtexts[i]->color.Blue);
		l_File.write(ctmp);

Alexander A. Maly's avatar
Alexander A. Maly committed
600 601
		QString TmpText = "(" + texts[i]->text() + ") show\n";
		QByteArray ccc = TmpText.toUtf8();
Alexander A. Maly's avatar
Alexander A. Maly committed
602
		l_File.write(ccc);
Denis Khachko's avatar
Denis Khachko committed
603 604 605 606
	}

	l_File.write("stroke\n");
	l_File.write("grestore\n");
Alexander A. Maly's avatar
Alexander A. Maly committed
607
	l_File.write("showpage\n");
Denis Khachko's avatar
Denis Khachko committed
608 609
	l_File.close();
	return 0;
Alexander A. Maly's avatar
Alexander A. Maly committed
610
}
Denis Khachko's avatar
Denis Khachko committed
611 612 613 614


int KumKuznec::LoadFromFile(QString p_FileName)
{
Alexander A. Maly's avatar
Alexander A. Maly committed
615 616 617 618 619 620 621 622
	if ((fileName == "") && (advancedTask)) {
		if (QMessageBox::question(this, "", QString::fromUtf8("Сохранить изменения?"), QMessageBox::Yes, QMessageBox::No, 0) == QMessageBox::Yes) {
			SaveToFileActivated();
		}
	}

	QFileInfo fi(p_FileName);
	QString name = fi.fileName();                // name = "archive.tar.gz"
Denis Khachko's avatar
Denis Khachko committed
623

Alexander A. Maly's avatar
Alexander A. Maly committed
624
	QString Title = QString::fromUtf8("Кузнечик - ") + name;
Denis Khachko's avatar
Denis Khachko committed
625

Alexander A. Maly's avatar
Alexander A. Maly committed
626
	MV->setWindowTitle(Title);
Denis Khachko's avatar
Denis Khachko committed
627

Alexander A. Maly's avatar
Alexander A. Maly committed
628 629
	qreal CurrentScale;
	Q_UNUSED(CurrentScale);
Denis Khachko's avatar
Denis Khachko committed
630 631

	QString tmp = "";
Denis Khachko's avatar
Denis Khachko committed
632

Denis Khachko's avatar
Denis Khachko committed
633 634
	QString l_String;
	QFile l_File(p_FileName);
Alexander A. Maly's avatar
Alexander A. Maly committed
635 636 637 638 639 640 641

	if (!l_File.open(QIODevice::ReadOnly)) {
		QMessageBox::information(MV, "", QString::fromUtf8("Ошибка открытия файла"), 0, 0, 0);
		return 1;
	}

	QByteArray ttt;
Denis Khachko's avatar
Denis Khachko committed
642
	ttt = l_File.readLine();
Alexander A. Maly's avatar
Alexander A. Maly committed
643

Denis Khachko's avatar
Denis Khachko committed
644
	//Читаем размеры прыжков
Alexander A. Maly's avatar
Alexander A. Maly committed
645 646 647 648
	while (ttt[0] == ';') {
		ttt = l_File.readLine();
	}
	qDebug() << ttt;
Denis Khachko's avatar
Denis Khachko committed
649
	l_String = QString::fromUtf8(ttt);
Alexander A. Maly's avatar
Alexander A. Maly committed
650 651 652 653 654 655 656 657 658 659 660 661 662 663 664
	l_String = l_String.simplified();
	QStringList zadanie = l_String.split(" ");
	if (zadanie.count() < 2) {
		return 1;
	}
	Fstep = zadanie[0].toInt();
	Bstep = zadanie[1].toInt();
	Kpult->setStepSizes(Fstep, Bstep);

	ttt = l_File.readLine();
	//Читаем стартовую позицию
	while (ttt[0] == ';') {
		ttt = l_File.readLine();
	}
	qDebug() << ttt;
Denis Khachko's avatar
Denis Khachko committed
665 666
	l_String = QString::fromUtf8(ttt);
	bool ok;
Alexander A. Maly's avatar
Alexander A. Maly committed
667 668 669 670 671 672
	startPos = l_String.toInt(&ok);
	if (!ok) {
		return 2;
	}

	ttt = l_File.readLine();
Denis Khachko's avatar
Denis Khachko committed
673
	//Читаем границы
Alexander A. Maly's avatar
Alexander A. Maly committed
674 675 676 677
	while (ttt[0] == ';') {
		ttt = l_File.readLine();
	}
	qDebug() << ttt;
Denis Khachko's avatar
Denis Khachko committed
678
	l_String = QString::fromUtf8(ttt);
Alexander A. Maly's avatar
Alexander A. Maly committed
679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698
	l_String = l_String.simplified();
	zadanie = l_String.split(" ");
	if (zadanie.count() < 2) {
		return 3;
	}
	leftBorder = zadanie[0].toInt(&ok);
	if (!ok) {
		return 4;
	}
	rightBorder = zadanie[1].toInt(&ok);
	if (!ok) {
		return 4;
	}
	borderEnable = true;
	if (leftBorder < -1000) {
		borderEnable = false;
	}
	if (rightBorder > 1000) {
		borderEnable = false;
	}
Denis Khachko's avatar
Denis Khachko committed
699 700 701
	ttt = l_File.readLine();
	//Читаем флаги
	flags_pos.clear();
Alexander A. Maly's avatar
Alexander A. Maly committed
702 703 704 705 706
	while (ttt[0] == ';') {
		ttt = l_File.readLine();
	}

	qDebug() << ttt;
Denis Khachko's avatar
Denis Khachko committed
707
	l_String = QString::fromUtf8(ttt);
Alexander A. Maly's avatar
Alexander A. Maly committed
708 709 710 711
	l_String = l_String.simplified();
	zadanie = l_String.split(" ", QString::SkipEmptyParts);
	for (int i = 0; i < zadanie.count() - 1; i++) {
		qDebug() << "flag:" << zadanie[i];
Denis Khachko's avatar
Denis Khachko committed
712
		flags_pos.append(zadanie[i].toInt(&ok));
Alexander A. Maly's avatar
Alexander A. Maly committed
713 714 715 716
		if (!ok) {
			return 5;
		}
	}
Denis Khachko's avatar
Denis Khachko committed
717 718 719


	Reset();
Alexander A. Maly's avatar
Alexander A. Maly committed
720 721 722
	fileName = QFileInfo(l_File).fileName();
	MV->setWindowTitle(QString::fromUtf8("Кузнечик - ") + QFileInfo(l_File).fileName());
	createFlags();
Denis Khachko's avatar
Denis Khachko committed
723 724 725
	return 0;

}
Alexander A. Maly's avatar
Alexander A. Maly committed
726

Denis Khachko's avatar
Denis Khachko committed
727 728 729

float KumKuznec::GetMinX(void)
{
Alexander A. Maly's avatar
Alexander A. Maly committed
730 731 732
	qreal MinX = 1000000;
	qreal VecX1, VecX2;
	QLineF TmpLine;
Denis Khachko's avatar
Denis Khachko committed
733

Alexander A. Maly's avatar
Alexander A. Maly committed
734
	for (int i = 0; i < lines.count(); i++) {
Denis Khachko's avatar
Denis Khachko committed
735 736 737 738 739

		TmpLine = lines[i]->line();
		VecX1 = TmpLine.x1();
		VecX2 = TmpLine.x2();

Alexander A. Maly's avatar
Alexander A. Maly committed
740 741 742 743 744 745 746 747
		if (VecX1 < MinX) {
			MinX = VecX1;
		}
		if (VecX2 < MinX) {
			MinX = VecX2;
		}
	}
	return MinX;
Denis Khachko's avatar
Denis Khachko committed
748
}
Alexander A. Maly's avatar
Alexander A. Maly committed
749

Denis Khachko's avatar
Denis Khachko committed
750 751
float KumKuznec::GetMinY(void)
{
Alexander A. Maly's avatar
Alexander A. Maly committed
752 753 754
	qreal MinY = 1000000;
	qreal VecY1, VecY2;
	QLineF TmpLine;
Denis Khachko's avatar
Denis Khachko committed
755

Alexander A. Maly's avatar
Alexander A. Maly committed
756
	for (int i = 0; i < lines.count(); i++) {
Denis Khachko's avatar
Denis Khachko committed
757 758 759 760
		TmpLine = lines[i]->line();
		VecY1 = -TmpLine.y1();
		VecY2 = -TmpLine.y2();

Alexander A. Maly's avatar
Alexander A. Maly committed
761 762 763 764 765 766 767
		if (VecY1 < MinY) {
			MinY = VecY1;
		}
		if (VecY2 < MinY) {
			MinY = VecY2;
		}
	}
Denis Khachko's avatar
Denis Khachko committed
768

Alexander A. Maly's avatar
Alexander A. Maly committed
769
	return MinY;
Denis Khachko's avatar
Denis Khachko committed
770
}
Alexander A. Maly's avatar
Alexander A. Maly committed
771

Denis Khachko's avatar
Denis Khachko committed
772 773
float KumKuznec::GetMaxX(void)
{
Alexander A. Maly's avatar
Alexander A. Maly committed
774 775 776
	qreal MaxX = -1000000;
	qreal VecX1, VecX2;
	QLineF TmpLine;
Denis Khachko's avatar
Denis Khachko committed
777

Alexander A. Maly's avatar
Alexander A. Maly committed
778
	for (int i = 0; i < lines.count(); i++) {
Denis Khachko's avatar
Denis Khachko committed
779 780 781 782
		TmpLine = lines[i]->line();
		VecX1 = TmpLine.x1();
		VecX2 = TmpLine.x2();

Alexander A. Maly's avatar
Alexander A. Maly committed
783 784 785 786 787 788 789 790
		if (VecX1 > MaxX) {
			MaxX = VecX1;
		}
		if (VecX2 > MaxX) {
			MaxX = VecX2;
		}
	}
	return MaxX;
Denis Khachko's avatar
Denis Khachko committed
791
}
Alexander A. Maly's avatar
Alexander A. Maly committed
792

Denis Khachko's avatar
Denis Khachko committed
793 794
float KumKuznec::GetMaxY(void)
{
Alexander A. Maly's avatar
Alexander A. Maly committed
795 796 797
	qreal MaxY = -1000000;
	qreal VecY1, VecY2;
	QLineF TmpLine;
Denis Khachko's avatar
Denis Khachko committed
798

Alexander A. Maly's avatar
Alexander A. Maly committed
799
	for (int i = 0; i < lines.count(); i++) {
Denis Khachko's avatar
Denis Khachko committed
800 801 802 803
		TmpLine = lines[i]->line();
		VecY1 = -TmpLine.y1();
		VecY2 = -TmpLine.y2();

Alexander A. Maly's avatar
Alexander A. Maly committed
804 805 806 807 808 809 810 811
		if (VecY1 > MaxY) {
			MaxY = VecY1;
		}
		if (VecY2 > MaxY) {
			MaxY = VecY2;
		}
	}
	return MaxY;
Denis Khachko's avatar
Denis Khachko committed
812
}
Alexander A. Maly's avatar
Alexander A. Maly committed
813

Denis Khachko's avatar
Denis Khachko committed
814 815 816
//загоняет картинку в окно
void KumKuznec::ToWindow(void)
{
Alexander A. Maly's avatar
Alexander A. Maly committed
817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839
	qreal MinX = GetMinX();
	qreal MaxX = GetMaxX();
	qreal MinY = GetMinY();
	qreal MaxY = GetMaxY();

	for (int i = 0; i < kumtexts.count(); i++) {
		qreal TextX = kumtexts[i]->x;
		qreal TextY = kumtexts[i]->y;
		int len = kumtexts[i]->text.length();
		qreal TextScale = kumtexts[i]->Size;
		if (TextX < MinX) {
			MinX = TextX;
		}
		if (TextY < MinY) {
			MinY = TextY;
		}
		if (TextX + len * TextScale > MaxX) {
			MaxX = TextX + len * TextScale;
		}
		if (TextY + TextScale > MaxY) {
			MaxY = TextY + TextScale;
		}
	}
Denis Khachko's avatar
Denis Khachko committed
840

Alexander A. Maly's avatar
Alexander A. Maly committed
841
	qreal dx = MaxX - MinX, dy = MaxY - MinY;
Denis Khachko's avatar
Denis Khachko committed
842

Alexander A. Maly's avatar
Alexander A. Maly committed
843 844 845
	MinX -= dx * 0.1;
	MaxX += dx * 0.1;
	dx = MaxX - MinX;
Denis Khachko's avatar
Denis Khachko committed
846

Alexander A. Maly's avatar
Alexander A. Maly committed
847 848 849
	MinY -= dy * 0.1;
	MaxY += dy * 0.1;
	dy = MaxY - MinY;
Denis Khachko's avatar
Denis Khachko committed
850

Alexander A. Maly's avatar
Alexander A. Maly committed
851 852 853
	qreal zoom = WindowZoom;
	qreal XSdwig = 0;
	qreal YSdwig = 0;
Denis Khachko's avatar
Denis Khachko committed
854

Alexander A. Maly's avatar
Alexander A. Maly committed
855 856 857
	if ((dx < 0.00001) && (dy < 0.00001)) {
		return;
	}
Denis Khachko's avatar
Denis Khachko committed
858

Alexander A. Maly's avatar
Alexander A. Maly committed
859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874
	if (dx / SizeX > dy / SizeY) {
		zoom = SizeX / dx;
		YSdwig = 0.5 * (SizeY / zoom - dy);
	} else {
		zoom = SizeY / dy;
		XSdwig = 0.5 * (SizeX / zoom - dx);
	}

	qreal Scale = zoom / WindowZoom;

	WindowZoom = zoom;
	WindowX0 = MinX  - XSdwig;
	WindowY0 = -MaxY - YSdwig;
	view->scale(Scale, Scale);

	WindowRedraw();
Denis Khachko's avatar
Denis Khachko committed
875 876
}

Alexander A. Maly's avatar
Alexander A. Maly committed
877 878 879
void KumKuznec::ClearPicture(void)
{
	HideCoord();
Denis Khachko's avatar
Denis Khachko committed
880

Alexander A. Maly's avatar
Alexander A. Maly committed
881
	Dialog *newZdialog = new Dialog(MV);
Denis Khachko's avatar
Denis Khachko committed
882

Alexander A. Maly's avatar
Alexander A. Maly committed
883
	newZdialog->setSizes(Fstep, Bstep);
Denis Khachko's avatar
Denis Khachko committed
884

Alexander A. Maly's avatar
Alexander A. Maly committed
885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906
	newZdialog->setFlags(flags_pos);
	newZdialog->setStart(startPos);
	newZdialog->setLeftBorder(leftBorder);
	newZdialog->setRightBorder(rightBorder);
	newZdialog->setBordersChB(borderEnable);
	qDebug() << "Task:" << advancedTask;
	newZdialog->setTaskNeeded(advancedTask);
	if (!newZdialog->exec()) {
		return;
	}
	qDebug() << "Asize" << newZdialog->ASize();
	Kpult->setStepSizes(newZdialog->ASize(), newZdialog->BSize());
	Fstep = newZdialog->ASize();
	Bstep = newZdialog->BSize();
	startPos = newZdialog->getStart();
	flags_pos = newZdialog->getFlags();

	MV->setWindowTitle(QString::fromUtf8("Кузнечик - без имени"));
	for (int i = 0; i < lines.count(); i++) {
		delete lines[i];
	}
	lines.clear();
Denis Khachko's avatar
Denis Khachko committed
907

Alexander A. Maly's avatar
Alexander A. Maly committed
908 909 910 911
	for (int i = 0; i < texts.count(); i++) {
		delete texts[i];
	}
	texts.clear();
Denis Khachko's avatar
Denis Khachko committed
912

Alexander A. Maly's avatar
Alexander A. Maly committed
913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934
	for (int i = 0; i < kumtexts.count(); i++) {
		delete kumtexts[i];
	}
	kumtexts.clear();
	borderEnable = newZdialog->borders();
	if (borderEnable) {
		leftBorder = newZdialog->getLeftBorder();
		rightBorder = newZdialog->getRightBorder();
	}
	WindowRedraw();
	advancedTask = newZdialog->isTaskNeeded();
	CurX = 0;
	CurY = 0;
	mPen->setPos(startPos * ZOOMMULTIP, 0);
	CurX = ZOOMMULTIP * startPos;
	mPen->setBrush(QBrush(QColor("blue")));
	createFlags();
	ClearSledi();
	ClearZakr();
	ToDubl();
	fileName = "";
	myModule->jumpsChanged();
Denis Khachko's avatar
Denis Khachko committed
935
}
Alexander A. Maly's avatar
Alexander A. Maly committed
936

Denis Khachko's avatar
Denis Khachko committed
937 938
void KumKuznec::CreatePen(void)
{
Alexander A. Maly's avatar
Alexander A. Maly committed
939
	static const int points[] = { 0, 0, -3, -6, 3, -6, 0, 0 };
Denis Khachko's avatar
Denis Khachko committed
940

Alexander A. Maly's avatar
Alexander A. Maly committed
941 942
	QPolygon polygon;
	polygon.setPoints(4, points);
Denis Khachko's avatar
Denis Khachko committed
943 944
	QPolygonF polygonf = QPolygonF(polygon);

Alexander A. Maly's avatar
Alexander A. Maly committed
945
	mPen = new QGraphicsPolygonItem();
Denis Khachko's avatar
Denis Khachko committed
946 947
	mPen->setPolygon(polygonf);
	mPen->setZValue(100);
Alexander A. Maly's avatar
Alexander A. Maly committed
948
	mPen->setBrush(QBrush(QColor(200, 200, 200)));
Denis Khachko's avatar
Denis Khachko committed
949 950

	scene->addItem(mPen);
Alexander A. Maly's avatar
Alexander A. Maly committed
951
	mPen->moveBy(0, -0.25);
Denis Khachko's avatar
Denis Khachko committed
952 953 954 955 956
}

void KumKuznec::SetLineColor(int LRed, int LGreen, int LBlue)
{

Alexander A. Maly's avatar
Alexander A. Maly committed
957 958 959 960
	CurColor.Red = LRed;
	CurColor.Green = LGreen;
	CurColor.Blue = LBlue;
	mPen->setBrush(QBrush(QColor(CurColor.Red, CurColor.Green, CurColor.Blue)));
Denis Khachko's avatar
Denis Khachko committed
961 962 963 964
}

bool KumKuznec::SetColorString(QString Color)
{
Alexander A. Maly's avatar
Alexander A. Maly committed
965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002
	CurColorName = Color;
	if (Color == QString::fromUtf8("черный")) {
		SetLineColor(1, 1, 1);
		return true;
	}
	if (Color == QString::fromUtf8("белый")) {
		SetLineColor(254, 254, 254);
		return true;
	}
	if (Color == QString::fromUtf8("красный")) {
		SetLineColor(254, 0, 0);
		return true;
	}
	if (Color == QString::fromUtf8("желтый")) {
		SetLineColor(254, 254, 0);
		return true;
	}
	if (Color == QString::fromUtf8("оранжевый")) {
		SetLineColor(254, 128, 0);
		return true;
	}
	if (Color == QString::fromUtf8("зеленый")) {
		SetLineColor(0, 254, 0);
		return true;
	}
	if (Color == QString::fromUtf8("голубой")) {
		SetLineColor(137, 175, 245);
		return true;
	}
	if (Color == QString::fromUtf8("синий")) {
		SetLineColor(0, 0, 254);
		return true;
	}
	if (Color == QString::fromUtf8("фиолетовый")) {
		SetLineColor(128, 0, 255);
		return true;
	}
	return false;
Denis Khachko's avatar
Denis Khachko committed
1003 1004 1005 1006 1007 1008 1009 1010 1011
}

void KumKuznec::Createbtn11()
{
	btn11 = new QToolButton(MV);
	btn11->setIcon(QIcon(QString::fromUtf8(":/icons/media-skip-forward.png")));
	btn11->setIconSize(QSize(20, 20));
	btn11->setToolTip(trUtf8("Крупнее"));
	btn11->move(ButtonSdwig, 5);
Alexander A. Maly's avatar
Alexander A. Maly committed
1012
	btn11->resize(BUTTON_SIZE, BUTTON_SIZE);
Denis Khachko's avatar
Denis Khachko committed
1013 1014 1015 1016 1017 1018 1019 1020 1021
	btn11->show();
}

void KumKuznec::Createbtn12()
{
	btn12 = new QToolButton(MV);
	btn12->setIcon(QIcon(QString::fromUtf8(":/icons/document-open.png")));
	btn12->setIconSize(QSize(20, 20));
	btn12->setToolTip(trUtf8("Загрузить"));
Alexander A. Maly's avatar
Alexander A. Maly committed
1022 1023 1024
	btn12->move(100 + BUTTON_SIZE, 5);
	btn12->resize(BUTTON_SIZE, BUTTON_SIZE);
	btn12->hide();
Denis Khachko's avatar
Denis Khachko committed
1025
}
Alexander A. Maly's avatar
Alexander A. Maly committed
1026

Denis Khachko's avatar
Denis Khachko committed
1027 1028 1029 1030 1031 1032
void KumKuznec::Createbtn13()
{
	btn13 = new QToolButton(MV);
	btn13->setIcon(QIcon(QString::fromUtf8(":/icons/media-skip-backward.png")));
	btn13->setIconSize(QSize(20, 20));
	btn13->setToolTip(trUtf8("Мельче"));
Alexander A. Maly's avatar
Alexander A. Maly committed
1033 1034 1035
	btn13->move(ButtonSdwig + BUTTON_SIZE, 5);
	btn13->resize(BUTTON_SIZE, BUTTON_SIZE);
	btn13->hide();
Denis Khachko's avatar
Denis Khachko committed
1036 1037 1038 1039
}

void KumKuznec::ToCenter(void)
{
Alexander A. Maly's avatar
Alexander A. Maly committed
1040 1041 1042 1043
	qDebug() << "WZ" << WindowZoom << " BZ" << BASEZOOM;
	view->scale(BASEZOOM / WindowZoom, BASEZOOM / WindowZoom);
	view->centerOn(0, 0);
	WindowZoom = BASEZOOM;
Denis Khachko's avatar
Denis Khachko committed
1044
}
Alexander A. Maly's avatar
Alexander A. Maly committed
1045

Denis Khachko's avatar
Denis Khachko committed
1046 1047 1048 1049

// пересветка окна
void KumKuznec::WindowRedraw(void)
{
Alexander A. Maly's avatar
Alexander A. Maly committed
1050 1051
	qDebug() << "KumKuznec::WindowRedraw: WindowY0 " << WindowY0;
	DrawNet();
Denis Khachko's avatar
Denis Khachko committed
1052
}
Alexander A. Maly's avatar
Alexander A. Maly committed
1053

Denis Khachko's avatar
Denis Khachko committed
1054 1055 1056
void KumKuznec::DrawNet()
{
	int i;
Alexander A. Maly's avatar
Alexander A. Maly committed
1057 1058 1059 1060 1061 1062
	for (i = 0; i < Netlines.count(); i++) {
		delete Netlines[i];
	}
	for (i = 0; i < NetText.count(); i++) {
		delete NetText[i];
	}
Denis Khachko's avatar
Denis Khachko committed
1063 1064
	Netlines.clear();
	NetText.clear();
Alexander A. Maly's avatar
Alexander A. Maly committed
1065

Denis Khachko's avatar
Denis Khachko committed
1066 1067
// вертикальная сетка

Alexander A. Maly's avatar
Alexander A. Maly committed
1068 1069 1070
	double BegX = -1024 * ZOOMMULTIP;
	double EndX = 1024 * ZOOMMULTIP;
	float Step = ZOOMMULTIP;
Denis Khachko's avatar
Denis Khachko committed
1071

Alexander A. Maly's avatar
Alexander A. Maly committed
1072
	double fx1 = BegX;
Denis Khachko's avatar
Denis Khachko committed
1073

Alexander A. Maly's avatar
Alexander A. Maly committed
1074 1075 1076
	while (fx1 < EndX) {
		fx1  += Step;
		double fx2 = fx1 + ZOOMMULTIP;
Denis Khachko's avatar
Denis Khachko committed
1077

Alexander A. Maly's avatar
Alexander A. Maly committed
1078 1079 1080
		Netlines.append(scene->addLine((fx1 - 0.2 * ZOOMMULTIP), 0.2 * ZOOMMULTIP, fx1 - 0.2 * ZOOMMULTIP, -0.2 * ZOOMMULTIP));
		Netlines.last()->setZValue(0.5);
		Netlines.last()->setPen(QPen(QColor("blue"))); // Левая вертикаль
Denis Khachko's avatar
Denis Khachko committed
1081

Alexander A. Maly's avatar
Alexander A. Maly committed
1082 1083 1084
		Netlines.append(scene->addLine((fx1 + 0.2 * ZOOMMULTIP), 0.2 * ZOOMMULTIP, fx1 + 0.2 * ZOOMMULTIP, -0.2 * ZOOMMULTIP));
		Netlines.last()->setZValue(0.5);
		Netlines.last()->setPen(QPen(QColor("blue")));//Правая вертикаль
Denis Khachko's avatar
Denis Khachko committed
1085

Alexander A. Maly's avatar
Alexander A. Maly committed
1086 1087 1088
		Netlines.append(scene->addLine((fx1 - 0.2 * ZOOMMULTIP), -0.2 * ZOOMMULTIP, fx1 + 0.2 * ZOOMMULTIP, -0.2 * ZOOMMULTIP));
		Netlines.last()->setZValue(0.5);
		Netlines.last()->setPen(QPen(QColor("blue")));//верх
Denis Khachko's avatar
Denis Khachko committed
1089

Alexander A. Maly's avatar
Alexander A. Maly committed
1090 1091 1092
		Netlines.append(scene->addLine((fx1 - 0.2 * ZOOMMULTIP), 0.2 * ZOOMMULTIP, fx1 + 0.2 * ZOOMMULTIP, 0.2 * ZOOMMULTIP));
		Netlines.last()->setZValue(0.5);
		Netlines.last()->setPen(QPen(QColor("blue")));//Низ
Denis Khachko's avatar
Denis Khachko committed
1093

Alexander A. Maly's avatar
Alexander A. Maly committed
1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107
		Netlines.append(scene->addLine((fx1 + 0.2 * ZOOMMULTIP), 0, fx2 - 0.2 * ZOOMMULTIP, 0));
		Netlines.last()->setZValue(0.5);
		Netlines.last()->setPen(QPen(QColor("blue")));//соединялка

		if ((borderEnable) && ((fx1 / ZOOMMULTIP == rightBorder) || (fx1 / ZOOMMULTIP == leftBorder))) {
			qreal zdvig = Step / 2;
			if (