备份
This commit is contained in:
@@ -33,7 +33,7 @@ public:
|
||||
explicit SonGraphicsView(const QString& nameIn)
|
||||
: name(nameIn),
|
||||
scene(new QGraphicsScene(this)),
|
||||
rectGroup(new QGraphicsItemGroup()),
|
||||
//rectGroup(new QGraphicsItemGroup()),
|
||||
imageWidth(1),
|
||||
imageHeight(1),
|
||||
m_isPan(false),
|
||||
@@ -45,7 +45,7 @@ public:
|
||||
setEnabled(false);
|
||||
setObjectName("SonGraphicsView");
|
||||
|
||||
scene->addItem(rectGroup);
|
||||
//scene->addItem(rectGroup);
|
||||
setScene(scene);
|
||||
|
||||
setStyleSheet(R"(
|
||||
@@ -95,9 +95,9 @@ protected:
|
||||
startPos = mapToScene(event->pos());
|
||||
rightClicked = true;
|
||||
|
||||
rectItem = new QGraphicsRectItem(QRectF(startPos, QSizeF(0, 0)));
|
||||
rectItem->setPen(QPen(Qt::red, 5, Qt::DashLine));
|
||||
rectGroup->addToGroup(rectItem);
|
||||
//rectItem = new QGraphicsRectItem(QRectF(startPos, QSizeF(0, 0)));
|
||||
//rectItem->setPen(QPen(Qt::red, 5, Qt::DashLine));
|
||||
//rectGroup->addToGroup(rectItem);
|
||||
update();
|
||||
}
|
||||
else {
|
||||
@@ -108,12 +108,12 @@ protected:
|
||||
void mouseMoveEvent(QMouseEvent* event) override {
|
||||
currentPos = mapToScene(event->pos());
|
||||
|
||||
if (rightClicked && rectItem) {
|
||||
/* if (rightClicked && rectItem) {
|
||||
QPointF endPos = currentPos;
|
||||
qreal width = endPos.x() - startPos.x();
|
||||
qreal height = endPos.y() - startPos.y();
|
||||
rectItem->setRect(startPos.x(), startPos.y(), width, height);
|
||||
}
|
||||
}*/
|
||||
|
||||
if (m_isPan) {
|
||||
pan(event->pos());
|
||||
@@ -129,20 +129,20 @@ protected:
|
||||
togglePan(false);
|
||||
event->accept();
|
||||
}
|
||||
else if (event->button() == Qt::RightButton) {
|
||||
rightClicked = false;
|
||||
QPointF endPos = mapToScene(event->pos());
|
||||
qreal width = endPos.x() - startPos.x();
|
||||
qreal height = endPos.y() - startPos.y();
|
||||
//else if (event->button() == Qt::RightButton) {
|
||||
// rightClicked = false;
|
||||
// QPointF endPos = mapToScene(event->pos());
|
||||
// qreal width = endPos.x() - startPos.x();
|
||||
// qreal height = endPos.y() - startPos.y();
|
||||
|
||||
deleteAllRect();
|
||||
// deleteAllRect();
|
||||
|
||||
if (width != 0 && height != 0) {
|
||||
double scaleRate = getMax(width == 0 ? 1.0 : rect().width() / width,height == 0 ? 1.0 : rect().height() / height);
|
||||
scale(scaleRate, scaleRate);
|
||||
centerOn(startPos + QPointF(width / 2, height / 2));
|
||||
}
|
||||
}
|
||||
// if (width != 0 && height != 0) {
|
||||
// double scaleRate = getMax(width == 0 ? 1.0 : rect().width() / width,height == 0 ? 1.0 : rect().height() / height);
|
||||
// scale(scaleRate, scaleRate);
|
||||
// centerOn(startPos + QPointF(width / 2, height / 2));
|
||||
// }
|
||||
//}
|
||||
else {
|
||||
event->ignore();
|
||||
}
|
||||
@@ -151,8 +151,8 @@ protected:
|
||||
private:
|
||||
QString name;
|
||||
QGraphicsScene* scene = nullptr;
|
||||
QGraphicsItemGroup* rectGroup = nullptr;
|
||||
QGraphicsRectItem* rectItem = nullptr;
|
||||
//QGraphicsItemGroup* rectGroup = nullptr;
|
||||
//QGraphicsRectItem* rectItem = nullptr;
|
||||
// QLabel* imgLabel = nullptr; // 删除
|
||||
QGraphicsPixmapItem* pixmapItem = nullptr;
|
||||
|
||||
@@ -220,7 +220,7 @@ private:
|
||||
}
|
||||
|
||||
void deleteAllRect() {
|
||||
if (!rectGroup)
|
||||
/*if (!rectGroup)
|
||||
return;
|
||||
|
||||
for (QGraphicsItem* item : rectGroup->childItems()) {
|
||||
@@ -230,7 +230,7 @@ private:
|
||||
scene->removeItem(rect);
|
||||
delete rect;
|
||||
}
|
||||
}
|
||||
}*/
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user