2013-11-15 13:41:26 +01:00
|
|
|
/************************************************************************
|
2013-09-18 21:16:19 +02:00
|
|
|
**
|
2013-11-15 13:50:05 +01:00
|
|
|
** @file vtablegraphicsview.cpp
|
2013-11-15 13:41:26 +01:00
|
|
|
** @author Roman Telezhinsky <dismine@gmail.com>
|
2013-11-15 13:50:05 +01:00
|
|
|
** @date November 15, 2013
|
2013-09-18 21:16:19 +02:00
|
|
|
**
|
2013-11-15 13:41:26 +01:00
|
|
|
** @brief
|
|
|
|
** @copyright
|
|
|
|
** This source code is part of the Valentine project, a pattern making
|
|
|
|
** program, whose allow create and modeling patterns of clothing.
|
|
|
|
** Copyright (C) 2013 Valentina project
|
|
|
|
** <https://bitbucket.org/dismine/valentina> All Rights Reserved.
|
2013-09-18 21:16:19 +02:00
|
|
|
**
|
2013-11-15 13:41:26 +01:00
|
|
|
** Valentina is free software: you can redistribute it and/or modify
|
2013-09-18 21:16:19 +02:00
|
|
|
** it under the terms of the GNU General Public License as published by
|
|
|
|
** the Free Software Foundation, either version 3 of the License, or
|
|
|
|
** (at your option) any later version.
|
|
|
|
**
|
2013-10-27 13:36:29 +01:00
|
|
|
** Valentina is distributed in the hope that it will be useful,
|
2013-09-18 21:16:19 +02:00
|
|
|
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
** GNU General Public License for more details.
|
|
|
|
**
|
|
|
|
** You should have received a copy of the GNU General Public License
|
|
|
|
** along with Valentina. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
**
|
2013-11-15 13:41:26 +01:00
|
|
|
*************************************************************************/
|
2013-12-19 11:42:00 +01:00
|
|
|
//TODO if this class is still in use: please translate ukrainian text into english
|
2013-09-18 21:16:19 +02:00
|
|
|
|
2013-08-29 12:31:50 +02:00
|
|
|
#include "vtablegraphicsview.h"
|
|
|
|
|
2013-11-21 13:05:26 +01:00
|
|
|
#include <QDebug>
|
|
|
|
#include <QtWidgets>
|
|
|
|
#include <QWheelEvent>
|
|
|
|
|
2013-11-04 21:35:15 +01:00
|
|
|
VTableGraphicsView::VTableGraphicsView(QGraphicsScene* pScene, QWidget *parent)
|
|
|
|
:QGraphicsView(pScene, parent)
|
|
|
|
{
|
2013-08-29 12:31:50 +02:00
|
|
|
QGraphicsView::setResizeAnchor(QGraphicsView::AnchorUnderMouse);
|
|
|
|
connect(pScene, &QGraphicsScene::selectionChanged, this, &VTableGraphicsView::selectionChanged);
|
|
|
|
}
|
|
|
|
|
2013-11-04 21:35:15 +01:00
|
|
|
void VTableGraphicsView::selectionChanged()
|
|
|
|
{
|
2013-08-29 12:31:50 +02:00
|
|
|
QList<QGraphicsItem *> listSelectedItems = scene()->selectedItems();
|
2013-11-04 21:35:15 +01:00
|
|
|
if ( listSelectedItems.isEmpty() == true )
|
|
|
|
{
|
2013-12-19 11:42:00 +01:00
|
|
|
qDebug() << tr("can't find detail");
|
2013-08-29 12:31:50 +02:00
|
|
|
emit itemChect(true);
|
2013-11-04 21:35:15 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-12-19 11:42:00 +01:00
|
|
|
qDebug() << tr("detail found");
|
2013-08-29 12:31:50 +02:00
|
|
|
emit itemChect(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-04 21:35:15 +01:00
|
|
|
void VTableGraphicsView::MirrorItem()
|
|
|
|
{
|
2013-08-29 12:31:50 +02:00
|
|
|
QList<QGraphicsItem *> list = scene()->selectedItems();
|
2013-11-04 21:35:15 +01:00
|
|
|
if (list.size()>0)
|
|
|
|
{
|
|
|
|
for ( qint32 i = 0; i < list.count(); ++i )
|
|
|
|
{
|
2013-11-07 15:40:39 +01:00
|
|
|
QGraphicsItem *item = list.at(i);
|
|
|
|
Q_ASSERT(item != 0);
|
|
|
|
QRectF itemRectOld = item->sceneBoundingRect();
|
2013-08-29 12:31:50 +02:00
|
|
|
//Get the current transform
|
2013-11-07 15:40:39 +01:00
|
|
|
QTransform transform(item->transform());
|
2013-08-29 12:31:50 +02:00
|
|
|
|
|
|
|
qreal m11 = transform.m11(); // Horizontal scaling
|
|
|
|
qreal m12 = transform.m12(); // Vertical shearing
|
|
|
|
qreal m13 = transform.m13(); // Horizontal Projection
|
|
|
|
qreal m21 = transform.m21(); // Horizontal shearing
|
|
|
|
qreal m22 = transform.m22(); // vertical scaling
|
|
|
|
qreal m23 = transform.m23(); // Vertical Projection
|
|
|
|
qreal m31 = transform.m31(); // Horizontal Position (DX)
|
|
|
|
qreal m32 = transform.m32(); // Vertical Position (DY)
|
|
|
|
qreal m33 = transform.m33(); // Addtional Projection Factor
|
|
|
|
|
|
|
|
// Horizontal flip
|
|
|
|
m11 = -m11;
|
|
|
|
|
|
|
|
// Write back to the matrix
|
|
|
|
transform.setMatrix(m11, m12, m13, m21, m22, m23, m31, m32, m33);
|
|
|
|
|
|
|
|
// Set the items transformation
|
2013-11-07 15:40:39 +01:00
|
|
|
item->setTransform(transform);
|
|
|
|
QRectF itemRectNew = item->sceneBoundingRect();
|
2013-08-29 12:31:50 +02:00
|
|
|
qreal dx, dy;
|
|
|
|
dx = itemRectOld.center().x()-itemRectNew.center().x();
|
|
|
|
dy = itemRectOld.center().y()-itemRectNew.center().y();
|
2013-11-07 15:40:39 +01:00
|
|
|
item->moveBy(dx, dy);
|
2013-08-29 12:31:50 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-04 21:35:15 +01:00
|
|
|
void VTableGraphicsView::wheelEvent(QWheelEvent *event)
|
|
|
|
{
|
|
|
|
if (QGuiApplication::keyboardModifiers() == Qt::ControlModifier)
|
|
|
|
{
|
2013-08-29 12:31:50 +02:00
|
|
|
// Если нажата клавиша CTRL этот код выполнится
|
2013-11-04 21:35:15 +01:00
|
|
|
if ((event->delta())>0)
|
|
|
|
{
|
2013-08-29 12:31:50 +02:00
|
|
|
ZoomIn();
|
2013-11-04 21:35:15 +01:00
|
|
|
}
|
|
|
|
else if ((event->delta())<0)
|
|
|
|
{
|
2013-08-29 12:31:50 +02:00
|
|
|
ZoomOut();
|
|
|
|
}
|
2013-11-04 21:35:15 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-08-29 12:31:50 +02:00
|
|
|
verticalScrollBar()->setValue(verticalScrollBar()->value()-event->delta());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-04 21:35:15 +01:00
|
|
|
void VTableGraphicsView::mousePressEvent(QMouseEvent *mousePress)
|
|
|
|
{
|
|
|
|
if (mousePress->button() & Qt::LeftButton)
|
|
|
|
{
|
|
|
|
switch (QGuiApplication::keyboardModifiers())
|
|
|
|
{
|
|
|
|
case Qt::ControlModifier:
|
|
|
|
QGraphicsView::setDragMode(QGraphicsView::ScrollHandDrag);
|
|
|
|
QGraphicsView::mousePressEvent(mousePress);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
QGraphicsView::mousePressEvent(mousePress);
|
|
|
|
break;
|
2013-08-29 12:31:50 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-04 21:35:15 +01:00
|
|
|
void VTableGraphicsView::mouseReleaseEvent(QMouseEvent *event)
|
|
|
|
{
|
2013-08-29 12:31:50 +02:00
|
|
|
QGraphicsView::mouseReleaseEvent ( event );
|
|
|
|
QGraphicsView::setDragMode( QGraphicsView::RubberBandDrag );
|
|
|
|
}
|
|
|
|
|
2013-11-04 21:35:15 +01:00
|
|
|
void VTableGraphicsView::keyPressEvent(QKeyEvent *event)
|
|
|
|
{
|
|
|
|
switch (event->key())
|
|
|
|
{
|
|
|
|
case Qt::Key_Space:
|
|
|
|
rotateIt();
|
|
|
|
break;
|
|
|
|
case Qt::Key_Left:
|
|
|
|
MoveItem(VTableGraphicsView::Left);
|
|
|
|
break;
|
|
|
|
case Qt::Key_Right:
|
|
|
|
MoveItem(VTableGraphicsView::Right);
|
|
|
|
break;
|
|
|
|
case Qt::Key_Up:
|
|
|
|
MoveItem(VTableGraphicsView::Up);
|
|
|
|
break;
|
|
|
|
case Qt::Key_Down:
|
|
|
|
MoveItem(VTableGraphicsView::Down);
|
|
|
|
break;
|
2013-11-12 19:29:03 +01:00
|
|
|
default:
|
|
|
|
break;
|
2013-08-29 12:31:50 +02:00
|
|
|
}
|
|
|
|
QGraphicsView::keyPressEvent ( event );
|
|
|
|
}
|
|
|
|
|
2013-11-04 21:35:15 +01:00
|
|
|
void VTableGraphicsView::rotateIt()
|
|
|
|
{
|
2013-08-29 12:31:50 +02:00
|
|
|
QList<QGraphicsItem *> list = scene()->selectedItems();
|
2013-11-04 21:35:15 +01:00
|
|
|
if (list.size()>0)
|
|
|
|
{
|
|
|
|
for ( qint32 i = 0; i < list.count(); ++i )
|
|
|
|
{
|
2013-11-07 15:40:39 +01:00
|
|
|
QGraphicsItem *item = list.at(i);
|
|
|
|
Q_ASSERT(item != 0);
|
|
|
|
item->setTransformOriginPoint(item->boundingRect().center());
|
|
|
|
item->setRotation(item->rotation() + 180);
|
2013-08-29 12:31:50 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-04 21:35:15 +01:00
|
|
|
void VTableGraphicsView::MoveItem(VTableGraphicsView::typeMove_e move)
|
|
|
|
{
|
2013-08-29 12:31:50 +02:00
|
|
|
qreal dx = 0, dy = 0;
|
2013-11-04 21:35:15 +01:00
|
|
|
switch (move)
|
|
|
|
{
|
|
|
|
case VTableGraphicsView::Left:
|
|
|
|
dx = -3;
|
|
|
|
dy = 0;
|
|
|
|
break;
|
|
|
|
case VTableGraphicsView::Right:
|
|
|
|
dx = 3;
|
|
|
|
dy = 0;
|
|
|
|
break;
|
|
|
|
case VTableGraphicsView::Up:
|
|
|
|
dx = 0;
|
|
|
|
dy = -3;
|
|
|
|
break;
|
|
|
|
case VTableGraphicsView::Down:
|
|
|
|
dx = 0;
|
|
|
|
dy = 3;
|
|
|
|
break;
|
2013-11-12 19:29:03 +01:00
|
|
|
default:
|
|
|
|
break;
|
2013-08-29 12:31:50 +02:00
|
|
|
}
|
|
|
|
QList<QGraphicsItem *> listSelectedItems = scene()->selectedItems();
|
2013-11-04 21:35:15 +01:00
|
|
|
if (listSelectedItems.size()>0)
|
|
|
|
{
|
|
|
|
for ( qint32 i = 0; i < listSelectedItems.count(); ++i )
|
|
|
|
{
|
2013-08-29 12:31:50 +02:00
|
|
|
listSelectedItems.at(i)->moveBy(dx, dy);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|