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
|
|
|
//---------------------------------------------------------
|
|
|
|
// testElementDragTransition
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
bool ScoreView::testElementDragTransition(QMouseEvent* ev)
|
|
|
|
{
|
|
|
|
if (curElement == 0 || !curElement->isMovable() || QApplication::mouseButtons() != Qt::LeftButton)
|
|
|
|
return false;
|
2012-09-13 18:01:34 +02:00
|
|
|
if (curElement->type() == Element::MEASURE) {
|
2012-05-26 14:49:10 +02:00
|
|
|
System* dragSystem = (System*)(curElement->parent());
|
2013-10-22 12:05:31 +02:00
|
|
|
int staffIdx = getStaff(dragSystem, data.startMove);
|
2012-05-26 14:49:10 +02:00
|
|
|
dragStaff = score()->staff(staffIdx);
|
|
|
|
if (staffIdx == 0)
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
QPoint delta = ev->pos() - startMoveI;
|
|
|
|
return delta.manhattanLength() > 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
// startDrag
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
void ScoreView::startDrag()
|
|
|
|
{
|
|
|
|
dragElement = curElement;
|
2013-10-22 12:05:31 +02:00
|
|
|
data.startMove -= dragElement->userOff();
|
2012-05-26 14:49:10 +02:00
|
|
|
_score->startCmd();
|
|
|
|
|
2012-09-13 18:01:34 +02:00
|
|
|
if (dragElement->type() == Element::MEASURE) {
|
2012-05-26 14:49:10 +02:00
|
|
|
staffUserDist = dragStaff->userDist();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
foreach(Element* e, _score->selection().elements())
|
|
|
|
e->setStartDragPosition(e->userOff());
|
|
|
|
}
|
|
|
|
_score->end();
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
// doDragElement
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
void ScoreView::doDragElement(QMouseEvent* ev)
|
|
|
|
{
|
2013-10-22 12:05:31 +02:00
|
|
|
QPointF delta = toLogical(ev->pos()) - data.startMove;
|
2012-05-26 14:49:10 +02:00
|
|
|
|
|
|
|
QPointF pt(delta);
|
|
|
|
if (qApp->keyboardModifiers() == Qt::ShiftModifier)
|
2013-06-04 18:15:02 +02:00
|
|
|
pt.setX(dragElement->userOff().x());
|
2012-05-26 14:49:10 +02:00
|
|
|
else if (qApp->keyboardModifiers() == Qt::ControlModifier)
|
2013-06-04 18:15:02 +02:00
|
|
|
pt.setY(dragElement->userOff().y());
|
2013-10-22 12:05:31 +02:00
|
|
|
|
2012-05-26 14:49:10 +02:00
|
|
|
data.hRaster = mscore->hRaster();
|
|
|
|
data.vRaster = mscore->vRaster();
|
2013-10-22 12:05:31 +02:00
|
|
|
data.delta = pt;
|
|
|
|
data.pos = toLogical(ev->pos());
|
2012-05-26 14:49:10 +02:00
|
|
|
|
2012-09-13 18:01:34 +02:00
|
|
|
if (dragElement->type() == Element::MEASURE) {
|
2012-05-26 14:49:10 +02:00
|
|
|
qreal dist = dragStaff->userDist() + delta.y();
|
|
|
|
int partStaves = dragStaff->part()->nstaves();
|
|
|
|
StyleIdx i = (partStaves > 1) ? ST_akkoladeDistance : ST_staffDistance;
|
|
|
|
qreal _spatium = _score->spatium();
|
|
|
|
qreal styleDist = _score->styleS(i).val() * _spatium;
|
|
|
|
|
|
|
|
if ((dist + styleDist) < _spatium) // limit minimum distance to spatium
|
|
|
|
dist = -styleDist + _spatium;
|
|
|
|
|
|
|
|
dragStaff->setUserDist(dist);
|
2013-10-22 12:05:31 +02:00
|
|
|
data.startMove += delta;
|
2012-05-26 14:49:10 +02:00
|
|
|
_score->doLayoutSystems();
|
2013-07-23 18:49:26 +02:00
|
|
|
_score->layoutSpanner();
|
2012-05-26 14:49:10 +02:00
|
|
|
update();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-10-22 12:05:31 +02:00
|
|
|
for (Element* e : _score->selection().elements()) {
|
|
|
|
QRectF r = e->drag(&data);
|
|
|
|
_score->addRefresh(r);
|
|
|
|
}
|
|
|
|
|
2012-05-26 14:49:10 +02:00
|
|
|
if (_score->playNote()) {
|
|
|
|
Element* e = _score->selection().element();
|
|
|
|
if (e)
|
|
|
|
mscore->play(e);
|
|
|
|
_score->setPlayNote(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
Element* e = _score->getSelectedElement();
|
|
|
|
if (e) {
|
|
|
|
QLineF anchor = e->dragAnchor();
|
|
|
|
if (!anchor.isNull())
|
|
|
|
setDropAnchor(anchor);
|
|
|
|
else
|
|
|
|
setDropTarget(0); // this also resets dropAnchor
|
|
|
|
}
|
|
|
|
_score->update();
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
// endDrag
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
void ScoreView::endDrag()
|
|
|
|
{
|
2012-09-13 18:01:34 +02:00
|
|
|
if (dragElement->type() == Element::MEASURE) {
|
2012-05-26 14:49:10 +02:00
|
|
|
qreal userDist = dragStaff->userDist();
|
|
|
|
dragStaff->setUserDist(staffUserDist);
|
|
|
|
score()->undo(new ChangeStaffUserDist(dragStaff, userDist));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
foreach(Element* e, _score->selection().elements()) {
|
|
|
|
e->endDrag();
|
|
|
|
QPointF npos = e->userOff();
|
|
|
|
e->setUserOff(e->startDragPosition());
|
|
|
|
_score->undoMove(e, npos);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_score->setLayoutAll(true);
|
|
|
|
dragElement = 0;
|
|
|
|
setDropTarget(0); // this also resets dropAnchor
|
|
|
|
_score->endCmd();
|
|
|
|
mscore->endCmd();
|
|
|
|
}
|
2013-05-13 18:49:17 +02:00
|
|
|
}
|
|
|
|
|