DragMode for scene.

--HG--
branch : develop
This commit is contained in:
dismine 2013-10-14 12:31:56 +03:00
parent 244756cb06
commit 4d6179d3e2
3 changed files with 27 additions and 9 deletions

View File

@ -27,12 +27,12 @@
VMainGraphicsView::VMainGraphicsView(QWidget *parent) :
QGraphicsView(parent), _numScheduledScalings(0){
QGraphicsView::setResizeAnchor(QGraphicsView::AnchorUnderMouse);
setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform);
this->setResizeAnchor(QGraphicsView::AnchorUnderMouse);
this->setTransformationAnchor(QGraphicsView::AnchorUnderMouse);
this->setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform);
}
void VMainGraphicsView::wheelEvent(QWheelEvent *event){
// If you press CTRL this code will execute
int numDegrees = event->delta() / 8;
int numSteps = numDegrees / 15; // see QWheelEvent documentation
_numScheduledScalings += numSteps;
@ -51,7 +51,7 @@ void VMainGraphicsView::wheelEvent(QWheelEvent *event){
void VMainGraphicsView::scalingTime(qreal x){
Q_UNUSED(x);
qreal factor = 1.0 + qreal(_numScheduledScalings) / 300.0;
if (QApplication::keyboardModifiers() == Qt::ControlModifier){
if (QApplication::keyboardModifiers() == Qt::ControlModifier){// If you press CTRL this code will execute
scale(factor, factor);
} else {
if(_numScheduledScalings < 0){
@ -70,3 +70,19 @@ void VMainGraphicsView::animFinished(){
}
sender()->~QObject();
}
void VMainGraphicsView::mousePressEvent(QMouseEvent *mousePress){
if(mousePress->button() & Qt::LeftButton){
switch(QGuiApplication::keyboardModifiers()){
case Qt::ControlModifier:
QGraphicsView::setDragMode(QGraphicsView::ScrollHandDrag);
QGraphicsView::mousePressEvent(mousePress);
break;
}
}
}
void VMainGraphicsView::mouseReleaseEvent(QMouseEvent *event){
QGraphicsView::mouseReleaseEvent ( event );
QGraphicsView::setDragMode( QGraphicsView::RubberBandDrag );
}

View File

@ -29,15 +29,17 @@ class VMainGraphicsView : public QGraphicsView{
public:
explicit VMainGraphicsView(QWidget *parent = 0);
signals:
public slots:
void scalingTime(qreal x);
void animFinished();
protected:
/**
* @brief wheelEvent обробник повороту колеса мишки.
* @param event передається подія.
*/
void wheelEvent ( QWheelEvent * event );
public slots:
void scalingTime(qreal x);
void animFinished();
void mousePressEvent(QMouseEvent *mousePress);
void mouseReleaseEvent(QMouseEvent *event);
private:
qint32 _numScheduledScalings;
};

View File

@ -35,10 +35,10 @@ VTableGraphicsView::VTableGraphicsView(QGraphicsScene* pScene, QWidget *parent)
void VTableGraphicsView::selectionChanged(){
QList<QGraphicsItem *> listSelectedItems = scene()->selectedItems();
if( listSelectedItems.isEmpty() == true ){
qDebug() << "деталь не знайдено";
qDebug() << tr("detail don't find");
emit itemChect(true);
} else {
qDebug() << "деталь знайдено";
qDebug() << tr("detail find");
emit itemChect(false);
}
}