Merge pull request 'master' (#65) from master into release
All checks were successful
SHS Gitea/libs/pipeline/head This commit looks good
All checks were successful
SHS Gitea/libs/pipeline/head This commit looks good
Reviewed-on: https://git.shs.tools/SHS/libs/pulls/65
This commit was merged in pull request #65.
This commit is contained in:
2
pip
2
pip
Submodule pip updated: 31f0d88157...9834ac177b
@@ -28,6 +28,9 @@
|
|||||||
</color>
|
</color>
|
||||||
</brush>
|
</brush>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="renderHints">
|
||||||
|
<set>QPainter::SmoothPixmapTransform|QPainter::TextAntialiasing</set>
|
||||||
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
|
|||||||
@@ -483,16 +483,16 @@ int BlockBusItem::neighborSegmentPoint(int point, int * seg) const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void BlockBusItem::testPoint(QPointF pos, int * sel_point, int * sel_segment) {
|
void BlockBusItem::testPoint(QPointF pos, int * sel_point, int * sel_segment, bool for_trace) {
|
||||||
for (int i = 0; i < pol.size(); ++i) {
|
for (int i = 0; i < pol.size(); ++i) {
|
||||||
if ((pol[i] - pos).manhattanLength() <= 10.) { // Point
|
if ((pol[i] - pos).manhattanLength() <= (for_trace ? 5. : 10.)) { // Point
|
||||||
*sel_point = i;
|
*sel_point = i;
|
||||||
*sel_segment = -1;
|
*sel_segment = -1;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (int i = 0; i < segments.size(); ++i) {
|
for (int i = 0; i < segments.size(); ++i) {
|
||||||
if (distPointToLine(pol[segments[i].first], pol[segments[i].second], pos) <= 7.) { // Segment
|
if (distPointToLine(pol[segments[i].first], pol[segments[i].second], pos) <= (for_trace ? 5. : 7.)) { // Segment
|
||||||
*sel_point = -1;
|
*sel_point = -1;
|
||||||
*sel_segment = i;
|
*sel_segment = i;
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ public:
|
|||||||
double endpointImageScale() const {return im_end_scale;}
|
double endpointImageScale() const {return im_end_scale;}
|
||||||
void appendPoint(const QPointF & p);
|
void appendPoint(const QPointF & p);
|
||||||
void appendPoint(qreal x, qreal y);
|
void appendPoint(qreal x, qreal y);
|
||||||
void testPoint(QPointF pos, int * sel_point, int * sel_segment);
|
void testPoint(QPointF pos, int * sel_point, int * sel_segment, bool for_trace = false);
|
||||||
void clear();
|
void clear();
|
||||||
/*void setStart(const QPointF & p) {pol[0] = p; scene()->update();}
|
/*void setStart(const QPointF & p) {pol[0] = p; scene()->update();}
|
||||||
void setStart(qreal x, qreal y) {setStart(QPointF(x, y));}
|
void setStart(qreal x, qreal y) {setStart(QPointF(x, y));}
|
||||||
|
|||||||
@@ -1,8 +1,26 @@
|
|||||||
project(blockeditor)
|
project(blockeditor)
|
||||||
|
import_version(${PROJECT_NAME} QAD)
|
||||||
find_qt(${QtVersions} Core Gui Widgets)
|
find_qt(${QtVersions} Core Gui Widgets)
|
||||||
|
if (Qt5_FOUND)
|
||||||
|
import_version(${PROJECT_NAME}5 ${PROJECT_NAME})
|
||||||
|
import_deploy_properties(${PROJECT_NAME}5 ${PROJECT_NAME})
|
||||||
|
endif()
|
||||||
|
set_deploy_property(${PROJECT_NAME}
|
||||||
|
LABEL ${PROJECT_NAME}
|
||||||
|
FULLNAME "${_QAD_DOMAIN}.${PROJECT_NAME}"
|
||||||
|
COMPANY ${_QAD_COMPANY}
|
||||||
|
INFO "Editor for BlockView Blocks")
|
||||||
|
if(APPLE)
|
||||||
|
#set_deploy_property(${PROJECT_NAME} ICON "icons/blockview.icns")
|
||||||
|
elseif(WIN32)
|
||||||
|
set_deploy_property(${PROJECT_NAME} ICON "icons/blockview.ico")
|
||||||
|
else()
|
||||||
|
set_deploy_property(${PROJECT_NAME} ICON "icons/blockview.png")
|
||||||
|
endif()
|
||||||
|
make_rc(${PROJECT_NAME} out_RC)
|
||||||
qt_sources(SRC)
|
qt_sources(SRC)
|
||||||
qt_wrap(${SRC} CPPS out_CPP QMS out_QM)
|
qt_wrap(${SRC} HDRS out_HDR CPPS out_CPP QMS out_QM)
|
||||||
qt_add_executable(${PROJECT_NAME} WIN32 out_CPP)
|
qt_add_executable(${PROJECT_NAME} WIN32 out_CPP ${out_RC})
|
||||||
qt_target_link_libraries(${PROJECT_NAME} qad_utils qad_widgets qad_blockview)
|
qt_target_link_libraries(${PROJECT_NAME} qad_utils qad_widgets qad_blockview)
|
||||||
message(STATUS "Building ${PROJECT_NAME}")
|
message(STATUS "Building ${PROJECT_NAME}")
|
||||||
if(LIB)
|
if(LIB)
|
||||||
@@ -18,5 +36,7 @@ if(LIB)
|
|||||||
#message(STATUS "Install ${PROJECT_NAME} to system \"${CMAKE_INSTALL_PREFIX}\"")
|
#message(STATUS "Install ${PROJECT_NAME} to system \"${CMAKE_INSTALL_PREFIX}\"")
|
||||||
else()
|
else()
|
||||||
qt_install(TARGETS ${PROJECT_NAME} DESTINATION bin)
|
qt_install(TARGETS ${PROJECT_NAME} DESTINATION bin)
|
||||||
#message(STATUS "Install ${PROJECT_NAME} to local \"bin\"")
|
endif()
|
||||||
|
if (Qt5_FOUND)
|
||||||
|
deploy_target(${PROJECT_NAME}5 VERBOSE DEPLOY_DIR ${CMAKE_CURRENT_BINARY_DIR} DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/../release)
|
||||||
endif()
|
endif()
|
||||||
|
|||||||
BIN
qad/blockview/blockeditor/icons/blockview.png
Normal file
BIN
qad/blockview/blockeditor/icons/blockview.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 4.2 KiB |
@@ -1,43 +0,0 @@
|
|||||||
# if defined(UNDER_CE)
|
|
||||||
# include <winbase.h>
|
|
||||||
# else
|
|
||||||
# include <winver.h>
|
|
||||||
# endif
|
|
||||||
|
|
||||||
1 ICON icons/blockview.ico
|
|
||||||
|
|
||||||
VS_VERSION_INFO VERSIONINFO
|
|
||||||
FILEVERSION 1,0,0,0
|
|
||||||
PRODUCTVERSION 1,0,0,0
|
|
||||||
FILEFLAGSMASK 0x3fL
|
|
||||||
#ifdef _DEBUG
|
|
||||||
FILEFLAGS 0x9L
|
|
||||||
#else
|
|
||||||
FILEFLAGS 0x8L
|
|
||||||
#endif
|
|
||||||
FILEOS 0x40004L
|
|
||||||
FILETYPE 0x2L
|
|
||||||
FILESUBTYPE 0x0L
|
|
||||||
BEGIN
|
|
||||||
BLOCK "StringFileInfo"
|
|
||||||
BEGIN
|
|
||||||
BLOCK "040904b0"
|
|
||||||
BEGIN
|
|
||||||
VALUE "Comments", "\0"
|
|
||||||
VALUE "CompanyName", "BMSTU SM5\0"
|
|
||||||
VALUE "FileDescription", "Block Editor\0"
|
|
||||||
VALUE "FileVersion", "1,0,0,0\0"
|
|
||||||
VALUE "InternalName", "Block Editor\0"
|
|
||||||
VALUE "LegalTrademarks", "\0"
|
|
||||||
VALUE "OriginalFilename", "blockeditor.exe\0"
|
|
||||||
VALUE "PrivateBuild", "1\0"
|
|
||||||
VALUE "ProductName", "Block Editor\0"
|
|
||||||
VALUE "ProductVersion", "1, 0, 0, 0\0"
|
|
||||||
VALUE "SpecialBuild", "\0"
|
|
||||||
END
|
|
||||||
END
|
|
||||||
BLOCK "VarFileInfo"
|
|
||||||
BEGIN
|
|
||||||
VALUE "Translation", 0x409, 1200
|
|
||||||
END
|
|
||||||
END
|
|
||||||
@@ -1264,23 +1264,26 @@ void BlockView::trace(QPointF scene_pos_from, QPointF scene_pos_to, BlockBusItem
|
|||||||
double signx = (p1.x() >= p0.x() ? 1. : -1.), signy = (p1.y() >= p0.y() ? 1. : -1.);
|
double signx = (p1.x() >= p0.x() ? 1. : -1.), signy = (p1.y() >= p0.y() ? 1. : -1.);
|
||||||
int steps(0);
|
int steps(0);
|
||||||
if ((dx + dy) < grid_step) continue;
|
if ((dx + dy) < grid_step) continue;
|
||||||
|
BlockViewWavetrace::CellState cs = BlockViewWavetrace::Blocked;
|
||||||
if (dx >= dy) { // by x
|
if (dx >= dy) { // by x
|
||||||
sx = grid_step;
|
sx = grid_step;
|
||||||
sy = sx * dy / dx;
|
sy = sx * dy / dx;
|
||||||
steps = qRound(dx / grid_step);
|
steps = qRound(dx / grid_step);
|
||||||
|
cs = BlockViewWavetrace::HorizontalBus;
|
||||||
} else {
|
} else {
|
||||||
sy = grid_step;
|
sy = grid_step;
|
||||||
sx = sy * dx / dy;
|
sx = sy * dx / dy;
|
||||||
steps = qRound(dy / grid_step);
|
steps = qRound(dy / grid_step);
|
||||||
|
cs = BlockViewWavetrace::VerticalBus;
|
||||||
}
|
}
|
||||||
sx *= signx;
|
sx *= signx;
|
||||||
sy *= signy;
|
sy *= signy;
|
||||||
//qDebug() << "fill" << p0 << "->" << p1 << "in" << steps << sx << sy;
|
//qDebug() << "fill" << p0 << "->" << p1 << "in" << steps << sx << sy;
|
||||||
for (int j = 0; j < steps; ++j) {
|
for (int j = 0; j <= steps; ++j) {
|
||||||
QPoint tp = quantize(cp, grid_step).toPoint() / grid_step + dp;
|
QPoint tp = quantize(cp, grid_step).toPoint() / grid_step + dp;
|
||||||
if (tp != qpt)
|
if (tp != qpt)
|
||||||
wavetrace.fill(tp, BlockViewWavetrace::Jump);
|
wavetrace.fill(tp, (j > 0 && j < steps) ? cs : BlockViewWavetrace::Blocked);
|
||||||
//qDebug() << " set" << cp;
|
//qDebug() << " set" << cp << ((j > 0 && j < steps) ? cs : BlockViewWavetrace::Blocked);
|
||||||
cp += QPointF(sx, sy);
|
cp += QPointF(sx, sy);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1346,7 +1349,7 @@ void BlockView::matchBus() {
|
|||||||
//qDebug() << "1" << buses.size() << tmp_bus.pol;
|
//qDebug() << "1" << buses.size() << tmp_bus.pol;
|
||||||
for (int i = 0; i < buses.size(); ++i) {
|
for (int i = 0; i < buses.size(); ++i) {
|
||||||
b = buses[i];
|
b = buses[i];
|
||||||
b->testPoint(point, &sp, &ss);
|
b->testPoint(point, &sp, &ss, true);
|
||||||
//qDebug() << i << sp << ss;
|
//qDebug() << i << sp << ss;
|
||||||
if (sp >= 0 || ss >= 0) break;
|
if (sp >= 0 || ss >= 0) break;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
#include "blockviewwavetrace.h"
|
#include "blockviewwavetrace.h"
|
||||||
#include <QTime>
|
|
||||||
|
|
||||||
|
|
||||||
BlockViewWavetrace::BlockViewWavetrace(int width, int height) {
|
BlockViewWavetrace::BlockViewWavetrace(int width, int height) {
|
||||||
@@ -17,14 +16,13 @@ void BlockViewWavetrace::resize(int width, int height) {
|
|||||||
for (int i = 0; i < wid; ++i) {
|
for (int i = 0; i < wid; ++i) {
|
||||||
if (field[i].size() != hei) {
|
if (field[i].size() != hei) {
|
||||||
field[i].resize(hei);
|
field[i].resize(hei);
|
||||||
field[i].fill(-1);
|
field[i].fill(Cell());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void BlockViewWavetrace::fill(short val) {
|
void BlockViewWavetrace::fill(short val) {
|
||||||
QTime tm; tm.restart();
|
|
||||||
for (int i = 0; i < wid; ++i) {
|
for (int i = 0; i < wid; ++i) {
|
||||||
if (i == 0)
|
if (i == 0)
|
||||||
field[i].fill(val);
|
field[i].fill(val);
|
||||||
@@ -37,11 +35,18 @@ void BlockViewWavetrace::fill(short val) {
|
|||||||
void BlockViewWavetrace::fill(const QRect & rect, short val) {
|
void BlockViewWavetrace::fill(const QRect & rect, short val) {
|
||||||
for (int i = rect.left(); i <= rect.right(); ++i)
|
for (int i = rect.left(); i <= rect.right(); ++i)
|
||||||
for (int j = rect.top(); j <= rect.bottom(); ++j)
|
for (int j = rect.top(); j <= rect.bottom(); ++j)
|
||||||
field[i][j] = val;
|
field[i][j].value = field[i][j].direction = val;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void BlockViewWavetrace::fill(int px, int py, short val) {
|
void BlockViewWavetrace::fill(int px, int py, short val) {
|
||||||
field[px][py] = val;
|
short p = field[px][py].value;
|
||||||
|
if ((val == HorizontalBus && p == VerticalBus ) ||
|
||||||
|
(val == VerticalBus && p == HorizontalBus))
|
||||||
|
field[px][py].value = Blocked;
|
||||||
|
else
|
||||||
|
field[px][py].value = val;
|
||||||
|
field[px][py].direction = field[px][py].value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -51,44 +56,33 @@ bool BlockViewWavetrace::trace(const QPoint & start, const QPoint & finish) {
|
|||||||
if (dir_ == NoTrace) return true;
|
if (dir_ == NoTrace) return true;
|
||||||
//qDebug() << "trace" << start << finish;
|
//qDebug() << "trace" << start << finish;
|
||||||
//return true;
|
//return true;
|
||||||
int cx, cy;
|
|
||||||
short cl = 0;
|
short cl = 0;
|
||||||
QRect frect(0, 0, wid - 1, hei - 1);
|
QRect frect(0, 0, wid - 1, hei - 1);
|
||||||
QVector<QPoint> cpnts, npnts;
|
QVector<QPoint> cpnts, npnts;
|
||||||
fill(st, cl);
|
fill(st, cl);
|
||||||
jumps.clear();
|
cpnts.push_back(st);
|
||||||
cpnts.append(st);
|
if (field[fn.x()][fn.y()].value == (short)Blocked)
|
||||||
auto checkAndFill = [this, &npnts, &frect](int x, int y, short c) {
|
return false;
|
||||||
|
auto checkAndFill = [this, &npnts, &frect](int x, int y, short acc_dir, short c) {
|
||||||
if (!frect.contains(x, y)) return;
|
if (!frect.contains(x, y)) return;
|
||||||
short p = field[x][y];
|
short p = field[x][y].value;
|
||||||
if (p == (short)Empty || p == (short)Jump) {
|
if (p == (short)Empty || p == acc_dir) {
|
||||||
npnts.append(QPoint(x, y));
|
npnts.push_back(QPoint(x, y));
|
||||||
fill(x, y, c);
|
field[x][y].value = c;
|
||||||
}
|
|
||||||
if (p == (short)Jump) {
|
|
||||||
jumps.append(QPoint(x, y));
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
if (field[fn.x()][fn.y()] < (short)Empty)
|
|
||||||
return false;
|
|
||||||
while (cpnts.size() > 0) {
|
while (cpnts.size() > 0) {
|
||||||
npnts.clear();
|
npnts.clear();
|
||||||
cl++;
|
cl++;
|
||||||
if (cl >= max_steps) return false;
|
if (cl >= max_steps)
|
||||||
|
return false;
|
||||||
for (int i = 0; i < cpnts.size(); ++i) {
|
for (int i = 0; i < cpnts.size(); ++i) {
|
||||||
if (cpnts[i] == fn) {
|
if (cpnts[i] == fn)
|
||||||
return true;
|
return true;
|
||||||
}
|
checkAndFill(cpnts[i].x() - 1, cpnts[i].y() , (short)VerticalBus , cl);
|
||||||
cx = cpnts[i].x() - 1;
|
checkAndFill(cpnts[i].x() + 1, cpnts[i].y() , (short)VerticalBus , cl);
|
||||||
cy = cpnts[i].y();
|
checkAndFill(cpnts[i].x() , cpnts[i].y() - 1, (short)HorizontalBus, cl);
|
||||||
checkAndFill(cx, cy, cl);
|
checkAndFill(cpnts[i].x() , cpnts[i].y() + 1, (short)HorizontalBus, cl);
|
||||||
cx = cpnts[i].x() + 1;
|
|
||||||
checkAndFill(cx, cy, cl);
|
|
||||||
cx = cpnts[i].x();
|
|
||||||
cy = cpnts[i].y() - 1;
|
|
||||||
checkAndFill(cx, cy, cl);
|
|
||||||
cy = cpnts[i].y() + 1;
|
|
||||||
checkAndFill(cx, cy, cl);
|
|
||||||
}
|
}
|
||||||
cpnts = npnts;
|
cpnts = npnts;
|
||||||
//qDebug() << cl << ": " << cpnts.size();
|
//qDebug() << cl << ": " << cpnts.size();
|
||||||
@@ -106,27 +100,21 @@ void BlockViewWavetrace::gatherPath() {
|
|||||||
}
|
}
|
||||||
int pa = -1, ca = -1;
|
int pa = -1, ca = -1;
|
||||||
bool first = true;
|
bool first = true;
|
||||||
short cl = field[fn.x()][fn.y()];
|
short cl = field[fn.x()][fn.y()].value;
|
||||||
QRect frect(0, 0, wid, hei);
|
QRect frect(0, 0, wid, hei);
|
||||||
QPoint cpnt = fn;
|
QPoint cpnt = fn;
|
||||||
//cout << "start from " << cl << endl;
|
//cout << "start from " << cl << endl;
|
||||||
auto checkAndStep = [this, &cpnt, &first, &frect] (int & dir, short c, int & ca_, int pa_)->bool {
|
auto checkAndStep = [this, &cpnt, &first, &frect] (int dir, short c, int & ca_, int pa_)->bool {
|
||||||
int cx = cpnt.x() + dps[dir].x();
|
int cx = cpnt.x() + dps[dir].x();
|
||||||
int cy = cpnt.y() + dps[dir].y();
|
int cy = cpnt.y() + dps[dir].y();
|
||||||
dir++;
|
|
||||||
if (frect.contains(cx, cy)) {
|
if (frect.contains(cx, cy)) {
|
||||||
if (field[cx][cy] == c) {
|
const Cell & cell(field[cx][cy]);
|
||||||
if (jumps.contains(QPoint(cx, cy))) {
|
if (cell.value == c) {
|
||||||
int jx = cx - 1;
|
if (cell.direction == HorizontalBus || cell.direction == VerticalBus) {
|
||||||
int jy = cy;
|
if (dps[dir].x() == 0 && cell.direction == VerticalBus)
|
||||||
if (jumps.contains(QPoint(jx, jy))) fill(jx, jy, (short)Jump);
|
return false;
|
||||||
jx = cx + 1;
|
if (dps[dir].y() == 0 && cell.direction == HorizontalBus)
|
||||||
if (jumps.contains(QPoint(jx, jy))) fill(jx, jy, (short)Jump);
|
return false;
|
||||||
jx = cx;
|
|
||||||
jy = cy - 1;
|
|
||||||
if (jumps.contains(QPoint(jx, jy))) fill(jx, jy, (short)Jump);
|
|
||||||
jy = cy + 1;
|
|
||||||
if (jumps.contains(QPoint(jx, jy))) fill(jx, jy, (short)Jump);
|
|
||||||
}
|
}
|
||||||
ca_ = QLineF(QPointF(cx, cy), cpnt).angle();
|
ca_ = QLineF(QPointF(cx, cy), cpnt).angle();
|
||||||
if (ca_ != pa_ && !first)
|
if (ca_ != pa_ && !first)
|
||||||
@@ -141,11 +129,12 @@ void BlockViewWavetrace::gatherPath() {
|
|||||||
while (cl > 0) {
|
while (cl > 0) {
|
||||||
cl--;
|
cl--;
|
||||||
pa = ca;
|
pa = ca;
|
||||||
int dir = 0;
|
|
||||||
if (checkAndStep(dir, cl, ca, pa)) continue;
|
if (checkAndStep(0, cl, ca, pa)) continue;
|
||||||
if (checkAndStep(dir, cl, ca, pa)) continue;
|
if (checkAndStep(1, cl, ca, pa)) continue;
|
||||||
if (checkAndStep(dir, cl, ca, pa)) continue;
|
if (checkAndStep(2, cl, ca, pa)) continue;
|
||||||
if (checkAndStep(dir, cl, ca, pa)) continue;
|
if (checkAndStep(3, cl, ca, pa)) continue;
|
||||||
|
|
||||||
}
|
}
|
||||||
path_.push_front(st);
|
path_.push_front(st);
|
||||||
//cout << path_.size() << endl;
|
//cout << path_.size() << endl;
|
||||||
@@ -154,13 +143,13 @@ void BlockViewWavetrace::gatherPath() {
|
|||||||
|
|
||||||
void BlockViewWavetrace::setPreferredDirection(BlockViewWavetrace::Direction dir) {
|
void BlockViewWavetrace::setPreferredDirection(BlockViewWavetrace::Direction dir) {
|
||||||
dir_ = dir;
|
dir_ = dir;
|
||||||
if (dir == Horizontal) {
|
if (dir == BlockViewWavetrace::Horizontal) {
|
||||||
dps[0] = QPoint(0, -1);
|
dps[0] = QPoint(0, -1);
|
||||||
dps[1] = QPoint(0, 1);
|
dps[1] = QPoint(0, 1);
|
||||||
dps[2] = QPoint(-1, 0);
|
dps[2] = QPoint(-1, 0);
|
||||||
dps[3] = QPoint(1, 0);
|
dps[3] = QPoint(1, 0);
|
||||||
}
|
}
|
||||||
if (dir == Vertical) {
|
if (dir == BlockViewWavetrace::Vertical) {
|
||||||
dps[2] = QPoint(0, -1);
|
dps[2] = QPoint(0, -1);
|
||||||
dps[3] = QPoint(0, 1);
|
dps[3] = QPoint(0, 1);
|
||||||
dps[0] = QPoint(-1, 0);
|
dps[0] = QPoint(-1, 0);
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ class QAD_EXPORT BlockViewWavetrace {
|
|||||||
public:
|
public:
|
||||||
BlockViewWavetrace(int width = 1, int height = 1);
|
BlockViewWavetrace(int width = 1, int height = 1);
|
||||||
|
|
||||||
enum CellState {Empty = -1, Blocked = -2, Jump = -3};
|
enum CellState {Empty = -1, Blocked = -2, HorizontalBus = -3, VerticalBus = -4};
|
||||||
enum Direction {NoTrace, Horizontal, Vertical};
|
enum Direction {NoTrace, Horizontal, Vertical};
|
||||||
|
|
||||||
int width() const {return wid;}
|
int width() const {return wid;}
|
||||||
@@ -36,7 +36,7 @@ public:
|
|||||||
void resize(const QSize & sz) {resize(sz.width(), sz.height());}
|
void resize(const QSize & sz) {resize(sz.width(), sz.height());}
|
||||||
void fill(short val = -1);
|
void fill(short val = -1);
|
||||||
void fill(const QRect & rect, short val = -1);
|
void fill(const QRect & rect, short val = -1);
|
||||||
void fill(const QPoint & point, short val = -1) {field[point.x()][point.y()] = val;}
|
void fill(const QPoint & point, short val = -1) {fill(point.x(), point.y(), val);}
|
||||||
void fill(int px, int py, short val);
|
void fill(int px, int py, short val);
|
||||||
void fill(BlockViewWavetrace::CellState val = Empty) {fill((short)val);}
|
void fill(BlockViewWavetrace::CellState val = Empty) {fill((short)val);}
|
||||||
void fill(const QRect & rect, BlockViewWavetrace::CellState val = Empty) {fill(rect, (short)val);}
|
void fill(const QRect & rect, BlockViewWavetrace::CellState val = Empty) {fill(rect, (short)val);}
|
||||||
@@ -52,9 +52,15 @@ public:
|
|||||||
const QVector<QPoint> & path() const;
|
const QVector<QPoint> & path() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
struct Cell {
|
||||||
|
Cell(short v = Empty): value(v), direction(0) {}
|
||||||
|
short value;
|
||||||
|
short direction;
|
||||||
|
};
|
||||||
|
|
||||||
int wid, hei, max_steps;
|
int wid, hei, max_steps;
|
||||||
Direction dir_;
|
Direction dir_;
|
||||||
QVector<QVector<short> > field;
|
QVector<QVector<Cell> > field;
|
||||||
QVector<QPoint> path_;
|
QVector<QPoint> path_;
|
||||||
QVector<QPoint> jumps;
|
QVector<QPoint> jumps;
|
||||||
QPoint dps[4], st, fn;
|
QPoint dps[4], st, fn;
|
||||||
|
|||||||
@@ -14,8 +14,10 @@ ImageView::ImageView(QWidget * parent): QGraphicsView(parent) {
|
|||||||
setDragMode(QGraphicsView::NoDrag);
|
setDragMode(QGraphicsView::NoDrag);
|
||||||
setTransformationAnchor(QGraphicsView::AnchorUnderMouse);
|
setTransformationAnchor(QGraphicsView::AnchorUnderMouse);
|
||||||
setScene(new QGraphicsScene());
|
setScene(new QGraphicsScene());
|
||||||
|
setRenderHint(QPainter::Antialiasing, true);
|
||||||
|
setRenderHint(QPainter::SmoothPixmapTransform, true);
|
||||||
item.setTransformationMode(Qt::SmoothTransformation);
|
item.setTransformationMode(Qt::SmoothTransformation);
|
||||||
item.setFlags(0);
|
item.setFlags(QGraphicsItem::GraphicsItemFlags());
|
||||||
scene()->addItem(&item);
|
scene()->addItem(&item);
|
||||||
viewport()->setAutoFillBackground(false);
|
viewport()->setAutoFillBackground(false);
|
||||||
viewport()->installEventFilter(this);
|
viewport()->installEventFilter(this);
|
||||||
@@ -28,12 +30,12 @@ ImageView::~ImageView() {
|
|||||||
|
|
||||||
|
|
||||||
QPixmap ImageView::pixmap() const {
|
QPixmap ImageView::pixmap() const {
|
||||||
return item.pixmap();
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void ImageView::setPixmap(QPixmap pixmap) {
|
void ImageView::setPixmap(QPixmap pixmap) {
|
||||||
item.setPixmap(pixmap);
|
map = pixmap;
|
||||||
adjustView();
|
adjustView();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -42,12 +44,13 @@ void ImageView::setImage(const QImage & i) {
|
|||||||
im_data.clear();
|
im_data.clear();
|
||||||
if (i.isNull()) {
|
if (i.isNull()) {
|
||||||
item.setPixmap(QPixmap());
|
item.setPixmap(QPixmap());
|
||||||
|
map = QPixmap();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
QBuffer b(&im_data); b.open(QIODevice::ReadWrite);
|
QBuffer b(&im_data); b.open(QIODevice::ReadWrite);
|
||||||
i.save(&b, "png");
|
i.save(&b, "png");
|
||||||
b.close();
|
b.close();
|
||||||
item.setPixmap(QPixmap::fromImage(i));
|
map = QPixmap::fromImage(i);
|
||||||
adjustView();
|
adjustView();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -56,17 +59,18 @@ void ImageView::setImage(const QByteArray & i) {
|
|||||||
im_data = i;
|
im_data = i;
|
||||||
if (i.isEmpty()) {
|
if (i.isEmpty()) {
|
||||||
item.setPixmap(QPixmap());
|
item.setPixmap(QPixmap());
|
||||||
|
map = QPixmap();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
item.setPixmap(QPixmap::fromImage(QImage::fromData(i)));
|
map = QPixmap::fromImage(QImage::fromData(i));
|
||||||
adjustView();
|
adjustView();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void ImageView::clear() {
|
void ImageView::clear() {
|
||||||
im_data.clear();
|
im_data.clear();
|
||||||
item.setPixmap(QPixmap());
|
item.setPixmap(QPixmap());
|
||||||
|
map = QPixmap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -121,10 +125,17 @@ bool ImageView::eventFilter(QObject * o, QEvent * e) {
|
|||||||
|
|
||||||
|
|
||||||
void ImageView::adjustView() {
|
void ImageView::adjustView() {
|
||||||
|
qreal mp = map.width() / map.size().boundedTo(size()).width();
|
||||||
|
if (mp > 1) {
|
||||||
|
item.setPixmap(map.scaled(map.size()/mp, Qt::KeepAspectRatio, Qt::SmoothTransformation));
|
||||||
|
} else {
|
||||||
|
item.setPixmap(map);
|
||||||
|
}
|
||||||
if (!autofit_) return;
|
if (!autofit_) return;
|
||||||
setSceneRect(item.boundingRect());
|
setSceneRect(item.boundingRect());
|
||||||
fitInView(&item, Qt::KeepAspectRatio);
|
fitInView(&item, Qt::KeepAspectRatio);
|
||||||
centerOn(&item);
|
centerOn(&item);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -52,6 +52,7 @@ private:
|
|||||||
QByteArray im_data;
|
QByteArray im_data;
|
||||||
QPoint prev_pos;
|
QPoint prev_pos;
|
||||||
bool autofit_;
|
bool autofit_;
|
||||||
|
QPixmap map;
|
||||||
|
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
|||||||
Reference in New Issue
Block a user