2013-04-29 15:31:22 +02:00
|
|
|
//=============================================================================
|
|
|
|
// MuseScore
|
|
|
|
// Music Composition & Notation
|
|
|
|
//
|
|
|
|
// Copyright (C) 2013 Werner Schweer and others
|
|
|
|
//
|
|
|
|
// 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 LICENSE.GPL
|
|
|
|
//=============================================================================
|
|
|
|
|
|
|
|
#include "exampleview.h"
|
2020-12-05 16:59:48 +01:00
|
|
|
|
|
|
|
#include <cmath>
|
|
|
|
#include <QMimeData>
|
|
|
|
|
2013-04-29 15:31:22 +02:00
|
|
|
#include "libmscore/score.h"
|
|
|
|
#include "libmscore/element.h"
|
|
|
|
#include "libmscore/page.h"
|
2017-02-19 03:03:57 +01:00
|
|
|
#include "libmscore/system.h"
|
2013-04-29 15:31:22 +02:00
|
|
|
#include "libmscore/icon.h"
|
|
|
|
#include "libmscore/chord.h"
|
2014-04-09 16:09:21 +02:00
|
|
|
#include "libmscore/xml.h"
|
2013-04-29 15:31:22 +02:00
|
|
|
|
2020-12-03 10:31:16 +01:00
|
|
|
#include "commonscenetypes.h"
|
2020-07-09 11:24:44 +02:00
|
|
|
|
2013-05-13 18:49:17 +02:00
|
|
|
namespace Ms {
|
2013-04-29 15:31:22 +02:00
|
|
|
//---------------------------------------------------------
|
|
|
|
// ExampleView
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
2020-05-29 18:47:27 +02:00
|
|
|
ExampleView::ExampleView(QWidget* parent)
|
|
|
|
: QFrame(parent)
|
2013-04-29 15:31:22 +02:00
|
|
|
{
|
2013-05-02 16:40:42 +02:00
|
|
|
_score = 0;
|
2013-04-29 15:31:22 +02:00
|
|
|
setAcceptDrops(true);
|
|
|
|
setFocusPolicy(Qt::StrongFocus);
|
2017-02-19 03:03:57 +01:00
|
|
|
resetMatrix();
|
2016-11-25 13:20:17 +01:00
|
|
|
_fgPixmap = nullptr;
|
2020-07-22 20:22:31 +02:00
|
|
|
_fgColor = Qt::white;
|
2020-08-31 14:16:44 +02:00
|
|
|
|
|
|
|
if (notationConfiguration()->foregroundUseColor()) {
|
|
|
|
_fgColor = notationConfiguration()->foregroundColor();
|
2016-11-25 13:20:17 +01:00
|
|
|
} else {
|
2020-08-31 14:16:44 +02:00
|
|
|
_fgPixmap = new QPixmap(notationConfiguration()->foregroundWallpaper().toQString());
|
2016-11-25 13:20:17 +01:00
|
|
|
if (_fgPixmap == 0 || _fgPixmap->isNull()) {
|
2020-08-31 14:16:44 +02:00
|
|
|
qDebug("no valid pixmap %s", qPrintable(notationConfiguration()->foregroundWallpaper().toQString()));
|
2016-11-25 13:20:17 +01:00
|
|
|
}
|
2020-05-26 15:54:26 +02:00
|
|
|
}
|
2015-11-12 14:59:19 +01:00
|
|
|
// setup drag canvas state
|
|
|
|
sm = new QStateMachine(this);
|
|
|
|
QState* stateActive = new QState;
|
2020-05-26 15:54:26 +02:00
|
|
|
|
2015-11-12 14:59:19 +01:00
|
|
|
QState* s1 = new QState(stateActive);
|
|
|
|
s1->setObjectName("example-normal");
|
|
|
|
s1->assignProperty(this, "cursor", QCursor(Qt::ArrowCursor));
|
2020-05-26 15:54:26 +02:00
|
|
|
|
2015-11-12 14:59:19 +01:00
|
|
|
QState* s = new QState(stateActive);
|
|
|
|
s->setObjectName("example-drag");
|
|
|
|
s->assignProperty(this, "cursor", QCursor(Qt::SizeAllCursor));
|
|
|
|
QEventTransition* cl = new QEventTransition(this, QEvent::MouseButtonRelease);
|
|
|
|
cl->setTargetState(s1);
|
|
|
|
s->addTransition(cl);
|
|
|
|
s1->addTransition(new DragTransitionExampleView(this));
|
2020-05-26 15:54:26 +02:00
|
|
|
|
2015-11-12 14:59:19 +01:00
|
|
|
sm->addState(stateActive);
|
|
|
|
stateActive->setInitialState(s1);
|
|
|
|
sm->setInitialState(stateActive);
|
2020-05-26 15:54:26 +02:00
|
|
|
|
2015-11-12 14:59:19 +01:00
|
|
|
sm->start();
|
2020-11-05 16:08:23 +01:00
|
|
|
|
|
|
|
m_defaultScaling = 0.9 * uiConfiguration()->physicalDotsPerInch() / DPI; // 90% of nominal
|
2016-11-25 13:20:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
// ~ExampleView
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
ExampleView::~ExampleView()
|
|
|
|
{
|
|
|
|
if (_fgPixmap) {
|
|
|
|
delete _fgPixmap;
|
2020-05-26 15:54:26 +02:00
|
|
|
}
|
2013-04-29 15:31:22 +02:00
|
|
|
}
|
|
|
|
|
2017-02-19 03:03:57 +01:00
|
|
|
//---------------------------------------------------------
|
|
|
|
// resetMatrix
|
|
|
|
// used to reset scrolling in case time signature num or denom changed
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
void ExampleView::resetMatrix()
|
|
|
|
{
|
2020-11-05 16:08:23 +01:00
|
|
|
double mag = m_defaultScaling;
|
2017-02-19 03:03:57 +01:00
|
|
|
qreal _spatium = SPATIUM20 * mag;
|
|
|
|
// example would normally be 10sp from top of page; this leaves 3sp margin above
|
2019-08-13 17:56:07 +02:00
|
|
|
_matrix = QTransform(mag, 0.0, 0.0, mag, _spatium, -_spatium * 7.0);
|
2017-02-19 03:03:57 +01:00
|
|
|
imatrix = _matrix.inverted();
|
|
|
|
}
|
|
|
|
|
2013-04-29 15:31:22 +02:00
|
|
|
void ExampleView::layoutChanged()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void ExampleView::dataChanged(const QRectF&)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void ExampleView::updateAll()
|
|
|
|
{
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
2020-08-04 10:29:03 +02:00
|
|
|
void ExampleView::adjustCanvasPosition(const Element* /*el*/, bool /*playBack*/, int)
|
2013-04-29 15:31:22 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
// setScore
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
void ExampleView::setScore(Score* s)
|
|
|
|
{
|
2013-05-02 11:01:38 +02:00
|
|
|
delete _score;
|
2013-04-29 15:31:22 +02:00
|
|
|
_score = s;
|
|
|
|
_score->addViewer(this);
|
2014-05-30 10:15:36 +02:00
|
|
|
_score->setLayoutMode(LayoutMode::LINE);
|
2020-05-26 15:54:26 +02:00
|
|
|
|
2018-11-08 15:45:14 +01:00
|
|
|
ScoreLoad sl;
|
2013-04-29 15:31:22 +02:00
|
|
|
_score->doLayout();
|
2013-05-02 11:01:38 +02:00
|
|
|
update();
|
2013-04-29 15:31:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void ExampleView::removeScore()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void ExampleView::changeEditElement(Element*)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
QCursor ExampleView::cursor() const
|
|
|
|
{
|
|
|
|
return QCursor();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ExampleView::setCursor(const QCursor&)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void ExampleView::setDropRectangle(const QRectF&)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-01-15 22:05:05 +01:00
|
|
|
void ExampleView::cmdAddSlur(Note* /*firstNote*/, Note* /*lastNote*/)
|
2013-04-29 15:31:22 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
Element* ExampleView::elementNear(QPointF)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-11-25 13:20:17 +01:00
|
|
|
void ExampleView::drawBackground(QPainter* p, const QRectF& r) const
|
2013-04-29 15:31:22 +02:00
|
|
|
{
|
2016-11-25 13:20:17 +01:00
|
|
|
if (_fgPixmap == 0 || _fgPixmap->isNull()) {
|
|
|
|
p->fillRect(r, _fgColor);
|
|
|
|
} else {
|
|
|
|
p->drawTiledPixmap(r, *_fgPixmap, r.topLeft()
|
|
|
|
- QPoint(lrint(_matrix.dx()), lrint(_matrix.dy())));
|
|
|
|
}
|
2013-04-29 15:31:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
// drawElements
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
void ExampleView::drawElements(QPainter& painter, const QList<Element*>& el)
|
|
|
|
{
|
2016-09-27 15:37:35 +02:00
|
|
|
for (Element* e : el) {
|
2013-04-29 15:31:22 +02:00
|
|
|
e->itemDiscovered = 0;
|
|
|
|
QPointF pos(e->pagePos());
|
|
|
|
painter.translate(pos);
|
|
|
|
e->draw(&painter);
|
|
|
|
painter.translate(-pos);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
// paintEvent
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
void ExampleView::paintEvent(QPaintEvent* ev)
|
|
|
|
{
|
|
|
|
if (_score) {
|
|
|
|
QPainter p(this);
|
2020-08-31 14:16:44 +02:00
|
|
|
p.setRenderHint(QPainter::Antialiasing, true);
|
2013-04-29 15:31:22 +02:00
|
|
|
p.setRenderHint(QPainter::TextAntialiasing, true);
|
2016-11-25 13:20:17 +01:00
|
|
|
const QRect r(ev->rect());
|
2020-05-26 15:54:26 +02:00
|
|
|
|
2016-11-25 13:20:17 +01:00
|
|
|
drawBackground(&p, r);
|
2020-05-26 15:54:26 +02:00
|
|
|
|
2013-04-29 15:31:22 +02:00
|
|
|
p.setTransform(_matrix);
|
|
|
|
QRectF fr = imatrix.mapRect(QRectF(r));
|
2020-05-26 15:54:26 +02:00
|
|
|
|
2013-04-29 15:31:22 +02:00
|
|
|
QRegion r1(r);
|
|
|
|
Page* page = _score->pages().front();
|
|
|
|
QList<Element*> ell = page->items(fr);
|
Fix Deprecation warnings with Qt 5.15 (and 5.14)
* fix 383 warnings C4996 (deprecated) with one single line change
* fix 5 'empty' warnings about invalid slots, not sure the remaining
slots serve any purpose though
* disable warnings C4127 and C4996 for thirdparty/google_analytics
* fix 30 warnings C4996 using the suggested alternatives available since
at least Qt 5.9, so won't break building against that
* change as requested in code review plus some more fixes using the same
idea
* fixing yet more warnings
* disable deprecation warnings in qoogle_analytics for MinGW too
although I believe maxOS and Linux may use those too. Easy to extend to
those, if need be.
* Fix qml runtime warnings exactly following the advice given by that
warning, but without really know what I'm doing here or whether that is
still backwards compatible to Qt 5.9.
* Use replacements as suggested, if available and no `endl` neded with
`qDebug()`
* fix 24 more
* 2 more
* 7 more (one only seen in DEBUG mode)
* Fix the `endl` warnings
* maybe more changes this way?
* Add all warnings C5999 or bigger to the ignore list for telemetry
with Qt 5.15 Beta 1 as avoiding only C26439, C26444,C 26452, C26495,
C26498, C26812 isn't possible
* fix 2 deprecation warning new with Qt 5.15 beta 1
* fix 4 new warnings and also Qt 5.12 builds, disable some dead code
* fix deprecation warnings new with Qt 5.15's MSVC 2019 integration and
revert some (`QNetworkReply::networkError()`) that Qt 5.15 beta 2
reverted too
* fix warning reg. obsolete operator < for QVariants
* revert changes needed prior to beta 3 And clarifying some earlier
changes
* mark ToDos
* fix warning reg QString()::null
* fix a 'regression' from a revert of an earlier change
2020-06-03 12:59:19 +02:00
|
|
|
std::stable_sort(ell.begin(), ell.end(), elementLessThan);
|
2013-04-29 15:31:22 +02:00
|
|
|
drawElements(p, ell);
|
|
|
|
}
|
|
|
|
QFrame::paintEvent(ev);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
// dragEnterEvent
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
void ExampleView::dragEnterEvent(QDragEnterEvent* event)
|
|
|
|
{
|
2018-08-17 15:06:15 +02:00
|
|
|
const QMimeData* d = event->mimeData();
|
2020-08-27 13:20:03 +02:00
|
|
|
if (d->hasFormat(mu::MIME_SYMBOL_FORMAT)) {
|
2013-04-29 15:31:22 +02:00
|
|
|
event->acceptProposedAction();
|
|
|
|
|
2020-08-27 13:20:03 +02:00
|
|
|
QByteArray a = d->data(mu::MIME_SYMBOL_FORMAT);
|
2013-04-29 15:31:22 +02:00
|
|
|
|
|
|
|
// qDebug("ExampleView::dragEnterEvent Symbol: <%s>", a.data());
|
|
|
|
|
2018-02-21 13:30:07 +01:00
|
|
|
XmlReader e(a);
|
2013-04-29 15:31:22 +02:00
|
|
|
QPointF dragOffset;
|
|
|
|
Fraction duration; // dummy
|
2017-01-18 14:16:33 +01:00
|
|
|
ElementType type = Element::readType(e, &dragOffset, &duration);
|
2020-05-26 15:54:26 +02:00
|
|
|
|
2013-04-29 15:31:22 +02:00
|
|
|
dragElement = Element::create(type, _score);
|
|
|
|
if (dragElement) {
|
|
|
|
dragElement->setParent(0);
|
|
|
|
dragElement->read(e);
|
|
|
|
dragElement->layout();
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
// dragLeaveEvent
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
void ExampleView::dragLeaveEvent(QDragLeaveEvent*)
|
|
|
|
{
|
|
|
|
if (dragElement) {
|
|
|
|
delete dragElement;
|
|
|
|
dragElement = 0;
|
|
|
|
}
|
|
|
|
setDropTarget(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
// moveElement
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
static void moveElement(void* data, Element* e)
|
|
|
|
{
|
|
|
|
QPointF* pos = (QPointF*)data;
|
|
|
|
e->score()->addRefresh(e->canvasBoundingRect());
|
|
|
|
e->setPos(*pos);
|
|
|
|
e->score()->addRefresh(e->canvasBoundingRect());
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
// dragMoveEvent
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
void ExampleView::dragMoveEvent(QDragMoveEvent* event)
|
|
|
|
{
|
|
|
|
event->acceptProposedAction();
|
2020-05-26 15:54:26 +02:00
|
|
|
|
2017-01-18 14:16:33 +01:00
|
|
|
if (!dragElement || dragElement->type() != ElementType::ICON) {
|
2013-04-29 15:31:22 +02:00
|
|
|
return;
|
2020-05-26 15:54:26 +02:00
|
|
|
}
|
|
|
|
|
2013-04-29 15:31:22 +02:00
|
|
|
QPointF pos(imatrix.map(QPointF(event->pos())));
|
|
|
|
QList<Element*> el = elementsAt(pos);
|
|
|
|
bool found = false;
|
|
|
|
foreach (const Element* e, el) {
|
2017-01-18 14:16:33 +01:00
|
|
|
if (e->type() == ElementType::NOTE) {
|
2013-04-29 15:31:22 +02:00
|
|
|
setDropTarget(const_cast<Element*>(e));
|
|
|
|
found = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!found) {
|
|
|
|
setDropTarget(0);
|
2020-05-26 15:54:26 +02:00
|
|
|
}
|
2013-04-29 15:31:22 +02:00
|
|
|
dragElement->scanElements(&pos, moveElement, false);
|
2016-04-18 18:11:51 +02:00
|
|
|
_score->update();
|
2013-04-29 15:31:22 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
// setDropTarget
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
void ExampleView::setDropTarget(const Element* el)
|
|
|
|
{
|
|
|
|
if (dropTarget != el) {
|
|
|
|
if (dropTarget) {
|
|
|
|
dropTarget->setDropTarget(false);
|
|
|
|
dropTarget = 0;
|
|
|
|
}
|
|
|
|
dropTarget = el;
|
|
|
|
if (dropTarget) {
|
|
|
|
dropTarget->setDropTarget(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!dropAnchor.isNull()) {
|
|
|
|
QRectF r;
|
|
|
|
r.setTopLeft(dropAnchor.p1());
|
|
|
|
r.setBottomRight(dropAnchor.p2());
|
|
|
|
dropAnchor = QLineF();
|
|
|
|
}
|
|
|
|
if (dropRectangle.isValid()) {
|
|
|
|
dropRectangle = QRectF();
|
|
|
|
}
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
// dropEvent
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
void ExampleView::dropEvent(QDropEvent* event)
|
|
|
|
{
|
|
|
|
QPointF pos(imatrix.map(QPointF(event->pos())));
|
2020-05-26 15:54:26 +02:00
|
|
|
|
2013-04-29 15:31:22 +02:00
|
|
|
if (!dragElement) {
|
|
|
|
return;
|
2020-05-26 15:54:26 +02:00
|
|
|
}
|
2017-01-18 14:16:33 +01:00
|
|
|
if (dragElement->type() != ElementType::ICON) {
|
2013-04-29 15:31:22 +02:00
|
|
|
delete dragElement;
|
|
|
|
dragElement = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
foreach (Element* e, elementsAt(pos)) {
|
2017-01-18 14:16:33 +01:00
|
|
|
if (e->type() == ElementType::NOTE) {
|
2013-04-29 15:31:22 +02:00
|
|
|
Icon* icon = static_cast<Icon*>(dragElement);
|
|
|
|
Chord* chord = static_cast<Note*>(e)->chord();
|
2017-02-18 14:52:10 +01:00
|
|
|
emit beamPropertyDropped(chord, icon);
|
2013-04-29 15:31:22 +02:00
|
|
|
switch (icon->iconType()) {
|
2014-05-30 10:14:57 +02:00
|
|
|
case IconType::SBEAM:
|
2014-06-26 07:45:09 +02:00
|
|
|
chord->setBeamMode(Beam::Mode::BEGIN);
|
2013-04-29 15:31:22 +02:00
|
|
|
break;
|
2014-05-30 10:14:57 +02:00
|
|
|
case IconType::MBEAM:
|
2014-06-26 07:45:09 +02:00
|
|
|
chord->setBeamMode(Beam::Mode::AUTO);
|
2013-04-29 15:31:22 +02:00
|
|
|
break;
|
2014-05-30 10:14:57 +02:00
|
|
|
case IconType::BEAM32:
|
2014-06-26 07:45:09 +02:00
|
|
|
chord->setBeamMode(Beam::Mode::BEGIN32);
|
2013-04-29 15:31:22 +02:00
|
|
|
break;
|
2014-05-30 10:14:57 +02:00
|
|
|
case IconType::BEAM64:
|
2014-06-26 07:45:09 +02:00
|
|
|
chord->setBeamMode(Beam::Mode::BEGIN64);
|
2013-04-29 15:31:22 +02:00
|
|
|
break;
|
2014-05-30 10:14:57 +02:00
|
|
|
default:
|
2013-04-29 15:31:22 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
score()->doLayout();
|
2020-05-26 15:54:26 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2013-04-29 15:31:22 +02:00
|
|
|
event->acceptProposedAction();
|
|
|
|
delete dragElement;
|
|
|
|
dragElement = 0;
|
|
|
|
setDropTarget(0);
|
|
|
|
}
|
2013-05-03 10:11:50 +02:00
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
// mousePressEvent
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
void ExampleView::mousePressEvent(QMouseEvent* event)
|
|
|
|
{
|
2015-11-12 14:59:19 +01:00
|
|
|
startMove = imatrix.map(QPointF(event->pos()));
|
2013-05-03 10:11:50 +02:00
|
|
|
QPointF pos(imatrix.map(QPointF(event->pos())));
|
2020-05-26 15:54:26 +02:00
|
|
|
|
2013-05-03 10:11:50 +02:00
|
|
|
foreach (Element* e, elementsAt(pos)) {
|
2017-01-18 14:16:33 +01:00
|
|
|
if (e->type() == ElementType::NOTE) {
|
2013-05-03 10:11:50 +02:00
|
|
|
emit noteClicked(static_cast<Note*>(e));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-07 18:28:57 +01:00
|
|
|
//---------------------------------------------------------
|
|
|
|
// sizeHint
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
QSize ExampleView::sizeHint() const
|
|
|
|
{
|
2020-11-05 16:08:23 +01:00
|
|
|
qreal mag = m_defaultScaling;
|
2015-12-03 07:26:52 +01:00
|
|
|
qreal _spatium = SPATIUM20 * mag;
|
|
|
|
// staff is 4sp tall with 3sp margin above; this leaves 3sp margin below
|
2016-11-25 13:20:17 +01:00
|
|
|
qreal height = 10.0 * _spatium;
|
|
|
|
if (score() && score()->pages().size() > 0) {
|
|
|
|
height = score()->pages()[0]->tbbox().height() * mag + (6 * _spatium);
|
2020-05-26 15:54:26 +02:00
|
|
|
}
|
2016-11-25 13:20:17 +01:00
|
|
|
return QSize(1000 * mag, height);
|
2015-01-07 18:28:57 +01:00
|
|
|
}
|
|
|
|
|
2015-11-12 14:59:19 +01:00
|
|
|
//---------------------------------------------------------
|
|
|
|
// dragExampleView
|
2017-02-19 03:03:57 +01:00
|
|
|
// constrained scrolling ensuring that this ExampleView won't be moved past the borders of its QFrame
|
2015-11-12 14:59:19 +01:00
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
void ExampleView::dragExampleView(QMouseEvent* ev)
|
|
|
|
{
|
|
|
|
QPoint d = ev->pos() - _matrix.map(startMove).toPoint();
|
|
|
|
int dx = d.x();
|
|
|
|
if (dx == 0) {
|
|
|
|
return;
|
2020-05-26 15:54:26 +02:00
|
|
|
}
|
|
|
|
|
2017-02-24 12:04:22 +01:00
|
|
|
constraintCanvas(&dx);
|
2020-05-26 15:54:26 +02:00
|
|
|
|
2017-02-24 12:04:22 +01:00
|
|
|
// Perform the actual scrolling
|
|
|
|
_matrix.setMatrix(_matrix.m11(), _matrix.m12(), _matrix.m13(), _matrix.m21(),
|
|
|
|
_matrix.m22(), _matrix.m23(), _matrix.dx() + dx, _matrix.dy(), _matrix.m33());
|
|
|
|
imatrix = _matrix.inverted();
|
|
|
|
scroll(dx, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DragTransitionExampleView::onTransition(QEvent* e)
|
|
|
|
{
|
|
|
|
QStateMachine::WrappedEvent* we = static_cast<QStateMachine::WrappedEvent*>(e);
|
|
|
|
QMouseEvent* me = static_cast<QMouseEvent*>(we->event());
|
|
|
|
canvas->dragExampleView(me);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
// wheelEvent
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
void ExampleView::wheelEvent(QWheelEvent* event)
|
|
|
|
{
|
|
|
|
QPoint pixelsScrolled = event->pixelDelta();
|
|
|
|
QPoint stepsScrolled = event->angleDelta();
|
|
|
|
int dx = 0, dy = 0;
|
|
|
|
if (!pixelsScrolled.isNull()) {
|
|
|
|
dx = pixelsScrolled.x();
|
|
|
|
dy = pixelsScrolled.y();
|
|
|
|
} else if (!stepsScrolled.isNull()) {
|
|
|
|
dx = static_cast<qreal>(stepsScrolled.x()) * qMax(2, width() / 10) / 120;
|
|
|
|
dy = static_cast<qreal>(stepsScrolled.y()) * qMax(2, height() / 10) / 120;
|
|
|
|
}
|
2020-05-26 15:54:26 +02:00
|
|
|
|
2017-02-24 12:04:22 +01:00
|
|
|
if (dx == 0) {
|
|
|
|
if (dy == 0) {
|
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
dx = dy;
|
2020-05-26 15:54:26 +02:00
|
|
|
}
|
2017-02-24 12:04:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
constraintCanvas(&dx);
|
|
|
|
|
|
|
|
_matrix.setMatrix(_matrix.m11(), _matrix.m12(), _matrix.m13(), _matrix.m21(),
|
|
|
|
_matrix.m22(), _matrix.m23(), _matrix.dx() + dx, _matrix.dy(), _matrix.m33());
|
|
|
|
imatrix = _matrix.inverted();
|
|
|
|
scroll(dx, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// constraintCanvas
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
void ExampleView::constraintCanvas(int* dxx)
|
|
|
|
{
|
|
|
|
int dx = *dxx;
|
2020-05-26 15:54:26 +02:00
|
|
|
|
2017-02-19 03:03:57 +01:00
|
|
|
Q_ASSERT(_score->pages().front()->system(0)); // should exist if doLayout ran
|
2020-05-26 15:54:26 +02:00
|
|
|
|
fix various typos
* Found via `codespell -q 3 -S ./share/locale,./thirdparty -L ba,cann,clas,dur,foto,iff,nd,ois,ot,pres,possibile,snaped,strack,tage,te,uint,thru,valu`
* Some revisions made per feedback given during review.
* Follow-up typos for review
* Add revisions per feedback
2019-12-17 21:06:10 +01:00
|
|
|
// form rectangle bounding the system with a spatium margin and translate relative to view space
|
2017-02-19 03:03:57 +01:00
|
|
|
qreal xstart = _score->pages().front()->system(0)->bbox().left() - SPATIUM20;
|
|
|
|
qreal xend = _score->pages().front()->system(0)->bbox().right() + 2.0 * SPATIUM20;
|
|
|
|
QRectF systemScaledViewRect(xstart * _matrix.m11(), 0, xend * _matrix.m11(), 0);
|
|
|
|
systemScaledViewRect.translate(_matrix.dx(), 0);
|
2020-05-26 15:54:26 +02:00
|
|
|
|
2017-02-19 03:03:57 +01:00
|
|
|
qreal frameWidth = static_cast<QFrame*>(this)->frameRect().width();
|
2020-05-26 15:54:26 +02:00
|
|
|
|
2017-02-19 03:03:57 +01:00
|
|
|
// constrain the dx of scrolling so that this ExampleView won't be moved past the borders of its QFrame
|
|
|
|
if (dx > 0) {
|
|
|
|
// when moving right, ensure the left edge of systemScaledViewRect won't be right of frame's left edge
|
|
|
|
if (systemScaledViewRect.left() + dx > 0) {
|
|
|
|
dx = -systemScaledViewRect.left();
|
2015-11-12 14:59:19 +01:00
|
|
|
}
|
2017-02-19 03:03:57 +01:00
|
|
|
} else {
|
|
|
|
// never move left if entire system already fits entirely within the frame
|
|
|
|
if (systemScaledViewRect.width() < frameWidth) {
|
|
|
|
dx = 0;
|
2020-05-26 15:54:26 +02:00
|
|
|
}
|
2017-02-19 03:03:57 +01:00
|
|
|
// when moving left, ensure the right edge of systemScaledViewRect won't be left of frame's right edge
|
|
|
|
else if (systemScaledViewRect.right() + dx < frameWidth) {
|
|
|
|
dx = frameWidth - systemScaledViewRect.right();
|
2020-05-26 15:54:26 +02:00
|
|
|
}
|
2017-02-19 03:03:57 +01:00
|
|
|
}
|
2020-05-26 15:54:26 +02:00
|
|
|
|
2017-02-24 12:04:22 +01:00
|
|
|
*dxx = dx;
|
2015-11-12 14:59:19 +01:00
|
|
|
}
|
2013-05-13 18:49:17 +02:00
|
|
|
}
|