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
|
//=============================================================================
// MuseScore
// Music Composition & Notation
//
// Copyright (C) 2002-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 "lasso.h"
#include "mscore.h"
#include "mscoreview.h"
#include "score.h"
namespace Ms {
//---------------------------------------------------------
// Lasso
//---------------------------------------------------------
Lasso::Lasso(Score* s)
: Element(s)
{
setVisible(false);
}
//---------------------------------------------------------
// draw
//---------------------------------------------------------
void Lasso::draw(QPainter* painter) const
{
painter->setBrush(QBrush(QColor(0, 0, 50, 50)));
// always 2 pixel width
qreal w = 2.0 / painter->transform().m11();
painter->setPen(QPen(MScore::selectColor[0], w));
painter->drawRect(bbox());
}
//---------------------------------------------------------
// editDrag
//---------------------------------------------------------
void Lasso::editDrag(EditData& ed)
{
Qt::CursorShape cursorShape = ed.view->cursor().shape();
switch (int(ed.curGrip)) {
case 0:
cursorShape = Qt::SizeFDiagCursor;
bbox().setTopLeft(bbox().topLeft() + ed.delta);
break;
case 1:
cursorShape = Qt::SizeBDiagCursor;
bbox().setTopRight(bbox().topRight() + ed.delta);
break;
case 2:
cursorShape = Qt::SizeFDiagCursor;
bbox().setBottomRight(bbox().bottomRight() + ed.delta);
break;
case 3:
cursorShape = Qt::SizeBDiagCursor;
bbox().setBottomLeft(bbox().bottomLeft() + ed.delta);
break;
case 4:
cursorShape = Qt::SizeVerCursor;
bbox().setTop(bbox().top() + ed.delta.y());
break;
case 5:
cursorShape = Qt::SizeHorCursor;
bbox().setRight(bbox().right() + ed.delta.x());
break;
case 6:
cursorShape = Qt::SizeVerCursor;
bbox().setBottom(bbox().bottom() + ed.delta.y());
break;
case 7:
cursorShape = Qt::SizeHorCursor;
bbox().setLeft(bbox().left() + ed.delta.x());
break;
}
ed.view->setCursor(QCursor(cursorShape));
}
//---------------------------------------------------------
// updateGrips
//---------------------------------------------------------
void Lasso::updateGrips(EditData& ed) const
{
ed.grip[0].translate(bbox().topLeft());
ed.grip[1].translate(bbox().topRight());
ed.grip[2].translate(bbox().bottomRight());
ed.grip[3].translate(bbox().bottomLeft());
ed.grip[4].translate(bbox().x() + bbox().width() * .5, bbox().top());
ed.grip[5].translate(bbox().right(), bbox().y() + bbox().height() * .5);
ed.grip[6].translate(bbox().x() + bbox().width()*.5, bbox().bottom());
ed.grip[7].translate(bbox().left(), bbox().y() + bbox().height() * .5);
}
//---------------------------------------------------------
// startEdit
//---------------------------------------------------------
void Lasso::startEdit(EditData& ed)
{
Element::startEdit(ed);
ed.grips = 8;
ed.curGrip = Grip(7);
}
//---------------------------------------------------------
// setProperty
//---------------------------------------------------------
bool Lasso::setProperty(Pid propertyId, const QVariant& v)
{
switch (propertyId) {
case Pid::LASSO_POS:
bbox().moveTo(v.toPointF());
break;
case Pid::LASSO_SIZE:
bbox().setSize(v.toSizeF());
break;
default:
if (!Element::setProperty(propertyId, v))
return false;
break;
}
score()->setUpdateAll();
return true;
}
//---------------------------------------------------------
// getProperty
//---------------------------------------------------------
QVariant Lasso::getProperty(Pid propertyId) const
{
switch (propertyId) {
case Pid::LASSO_POS:
return bbox().topLeft();
case Pid::LASSO_SIZE:
return bbox().size();
default:
break;
}
return Element::getProperty(propertyId);
}
}
|