MuseScore/mscore/dragelement.cpp

94 lines
2.7 KiB
C++
Raw Normal View History

2012-05-26 14:49:10 +02:00
//=============================================================================
// MuseScore
// Music Composition & Notation
// $Id:$
//
// Copyright (C) 2011 Werner Schweer
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License version 2
// as published by the Free Software Foundation and appearing in
// the file LICENCE.GPL
//=============================================================================
#include "scoreview.h"
#include "libmscore/score.h"
#include "musescore.h"
#include "libmscore/staff.h"
#include "libmscore/utils.h"
#include "libmscore/undo.h"
#include "libmscore/part.h"
2013-05-13 18:49:17 +02:00
namespace Ms {
2012-05-26 14:49:10 +02:00
//---------------------------------------------------------
// startDrag
//---------------------------------------------------------
void ScoreView::startDrag()
{
2017-05-02 14:17:31 +02:00
editData.grips = 0;
editData.clearData();
2017-05-02 14:17:31 +02:00
editData.startMove -= editData.element->userOff();
2017-03-04 15:01:42 +01:00
2012-05-26 14:49:10 +02:00
_score->startCmd();
2017-05-02 14:17:31 +02:00
for (Element* e : _score->selection().elements())
e->startDrag(editData);
2012-05-26 14:49:10 +02:00
}
//---------------------------------------------------------
// doDragElement
//---------------------------------------------------------
void ScoreView::doDragElement(QMouseEvent* ev)
{
2017-03-31 13:03:15 +02:00
QPointF delta = toLogical(ev->pos()) - editData.startMove;
2012-05-26 14:49:10 +02:00
QPointF pt(delta);
if (qApp->keyboardModifiers() == Qt::ShiftModifier)
2017-05-02 14:17:31 +02:00
pt.setX(editData.element->userOff().x());
2012-05-26 14:49:10 +02:00
else if (qApp->keyboardModifiers() == Qt::ControlModifier)
2017-05-02 14:17:31 +02:00
pt.setY(editData.element->userOff().y());
2013-10-22 12:05:31 +02:00
2017-03-31 13:03:15 +02:00
editData.hRaster = mscore->hRaster();
editData.vRaster = mscore->vRaster();
editData.delta = pt;
editData.pos = toLogical(ev->pos());
2012-05-26 14:49:10 +02:00
2017-05-02 14:17:31 +02:00
for (Element* e : _score->selection().elements())
2017-03-31 13:03:15 +02:00
_score->addRefresh(e->drag(editData));
2012-05-26 14:49:10 +02:00
Element* e = _score->getSelectedElement();
if (e) {
if (_score->playNote()) {
mscore->play(e);
_score->setPlayNote(false);
}
2012-05-26 14:49:10 +02:00
QLineF anchor = e->dragAnchor();
2014-08-06 12:28:58 +02:00
2012-05-26 14:49:10 +02:00
if (!anchor.isNull())
setDropAnchor(anchor);
else
setDropTarget(0); // this also resets dropAnchor
}
2017-05-02 14:17:31 +02:00
updateGrips();
2012-05-26 14:49:10 +02:00
_score->update();
}
//---------------------------------------------------------
// endDrag
//---------------------------------------------------------
void ScoreView::endDrag()
{
2018-01-29 09:26:16 +01:00
for (Element* e : _score->selection().elements()) {
2017-05-02 14:17:31 +02:00
e->endDrag(editData);
2018-01-29 09:26:16 +01:00
e->triggerLayout();
}
2012-05-26 14:49:10 +02:00
setDropTarget(0); // this also resets dropAnchor
_score->endCmd();
}
2013-05-13 18:49:17 +02:00
}