1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171
|
//=============================================================================
// 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"
namespace Ms {
//---------------------------------------------------------
// testElementDragTransition
//---------------------------------------------------------
bool ScoreView::testElementDragTransition(QMouseEvent* ev)
{
if (curElement == 0 || !curElement->isMovable() || QApplication::mouseButtons() != Qt::LeftButton)
return false;
if (curElement->type() == Element::Type::MEASURE) {
System* dragSystem = (System*)(curElement->parent());
int staffIdx = getStaff(dragSystem, data.startMove);
dragStaff = score()->staff(staffIdx);
if (staffIdx == 0)
return false;
}
QPoint delta = ev->pos() - startMoveI;
return delta.manhattanLength() > 2;
}
//---------------------------------------------------------
// startDrag
//---------------------------------------------------------
void ScoreView::startDrag()
{
dragElement = curElement;
data.startMove -= dragElement->userOff();
_score->startCmd();
if (dragElement->type() == Element::Type::MEASURE) {
staffUserDist = dragStaff->userDist();
}
else {
foreach(Element* e, _score->selection().elements())
e->setStartDragPosition(e->userOff());
}
_score->end();
}
//---------------------------------------------------------
// doDragElement
//---------------------------------------------------------
void ScoreView::doDragElement(QMouseEvent* ev)
{
QPointF delta = toLogical(ev->pos()) - data.startMove;
QPointF pt(delta);
if (qApp->keyboardModifiers() == Qt::ShiftModifier)
pt.setX(dragElement->userOff().x());
else if (qApp->keyboardModifiers() == Qt::ControlModifier)
pt.setY(dragElement->userOff().y());
data.hRaster = mscore->hRaster();
data.vRaster = mscore->vRaster();
data.delta = pt;
data.pos = toLogical(ev->pos());
if (dragElement->type() == Element::Type::MEASURE) {
if (qApp->keyboardModifiers() == Qt::ShiftModifier) {
qreal dist = dragStaff->userDist() + delta.y();
int partStaves = dragStaff->part()->nstaves();
StyleIdx i = (partStaves > 1) ? StyleIdx::akkoladeDistance : StyleIdx::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);
data.startMove += delta;
_score->doLayoutSystems();
_score->layoutSpanner();
update();
loopUpdate(getAction("loop")->isChecked());
}
return;
}
// special case when dragging notes:
// you usually dont want dragging stems & hooks
// which would offset stems
bool dragNotes = false;
for (Element* e : _score->selection().elements()) {
if (e->type() == Element::Type::NOTE) {
dragNotes = true;
break;
}
}
QList<Element*> el;
for (Element* e : _score->selection().elements()) {
if (dragNotes) {
if (e->type() == Element::Type::STEM || e->type() == Element::Type::HOOK)
continue;
}
el.append(e);
}
for (Element* e : el) {
QRectF r = e->drag(&data);
_score->addRefresh(r);
}
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()
{
if (dragElement->type() == Element::Type::MEASURE) {
qreal userDist = dragStaff->userDist();
dragStaff->setUserDist(staffUserDist);
score()->undo(new ChangeStaffUserDist(dragStaff, userDist));
}
else {
foreach(Element* e, _score->selection().elements()) {
e->endDrag();
e->score()->undoPropertyChanged(e, P_ID::USER_OFF, e->startDragPosition());
}
}
_score->setLayoutAll(true);
dragElement = 0;
setDropTarget(0); // this also resets dropAnchor
_score->endCmd();
}
}
|