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) : VMainGraphicsView::VMainGraphicsView(QWidget *parent) :
QGraphicsView(parent), _numScheduledScalings(0){ QGraphicsView(parent), _numScheduledScalings(0){
QGraphicsView::setResizeAnchor(QGraphicsView::AnchorUnderMouse); this->setResizeAnchor(QGraphicsView::AnchorUnderMouse);
setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform); this->setTransformationAnchor(QGraphicsView::AnchorUnderMouse);
this->setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform);
} }
void VMainGraphicsView::wheelEvent(QWheelEvent *event){ void VMainGraphicsView::wheelEvent(QWheelEvent *event){
// If you press CTRL this code will execute
int numDegrees = event->delta() / 8; int numDegrees = event->delta() / 8;
int numSteps = numDegrees / 15; // see QWheelEvent documentation int numSteps = numDegrees / 15; // see QWheelEvent documentation
_numScheduledScalings += numSteps; _numScheduledScalings += numSteps;
@ -51,7 +51,7 @@ void VMainGraphicsView::wheelEvent(QWheelEvent *event){
void VMainGraphicsView::scalingTime(qreal x){ void VMainGraphicsView::scalingTime(qreal x){
Q_UNUSED(x); Q_UNUSED(x);
qreal factor = 1.0 + qreal(_numScheduledScalings) / 300.0; 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); scale(factor, factor);
} else { } else {
if(_numScheduledScalings < 0){ if(_numScheduledScalings < 0){
@ -70,3 +70,19 @@ void VMainGraphicsView::animFinished(){
} }
sender()->~QObject(); 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: public:
explicit VMainGraphicsView(QWidget *parent = 0); explicit VMainGraphicsView(QWidget *parent = 0);
signals: signals:
public slots:
void scalingTime(qreal x);
void animFinished();
protected: protected:
/** /**
* @brief wheelEvent обробник повороту колеса мишки. * @brief wheelEvent обробник повороту колеса мишки.
* @param event передається подія. * @param event передається подія.
*/ */
void wheelEvent ( QWheelEvent * event ); void wheelEvent ( QWheelEvent * event );
public slots: void mousePressEvent(QMouseEvent *mousePress);
void scalingTime(qreal x); void mouseReleaseEvent(QMouseEvent *event);
void animFinished();
private: private:
qint32 _numScheduledScalings; qint32 _numScheduledScalings;
}; };

View File

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