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 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905
|
//=============================================================================
// MuseScore
// Linux Music Score Editor
// $Id: scoreview.cpp 3446 2010-09-10 20:18:16Z wschweer $
//
// Copyright (C) 2002-2011 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.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
//=============================================================================
#include "scoreview.h"
#include "musescore.h"
#include "libmscore/score.h"
#include "libmscore/lasso.h"
#include "icons.h"
#include "libmscore/page.h"
#include "preferences.h"
#include "libmscore/image.h"
#include "libmscore/mscore.h"
#include "svggenerator.h"
#include "inspector/inspector.h"
namespace Ms {
//---------------------------------------------------------
// FotoScoreViewDragTransition
//---------------------------------------------------------
class FotoScoreViewDragTransition : public QMouseEventTransition
{
ScoreView* canvas;
protected:
virtual bool eventTest(QEvent* event) {
if (!QMouseEventTransition::eventTest(event))
return false;
QStateMachine::WrappedEvent* we = static_cast<QStateMachine::WrappedEvent*>(event);
QMouseEvent* me = static_cast<QMouseEvent*>(we->event());
if (me->modifiers() & Qt::ShiftModifier)
return false;
return canvas->fotoScoreViewDragTest(me);
}
public:
FotoScoreViewDragTransition(ScoreView* c, QState* target)
: QMouseEventTransition(c, QEvent::MouseButtonPress, Qt::LeftButton), canvas(c) {
setTargetState(target);
}
};
//---------------------------------------------------------
// FotoScoreViewDragRectTransition
//---------------------------------------------------------
class FotoScoreViewDragRectTransition : public QMouseEventTransition
{
ScoreView* canvas;
protected:
virtual bool eventTest(QEvent* event) {
if (!QMouseEventTransition::eventTest(event))
return false;
QStateMachine::WrappedEvent* we = static_cast<QStateMachine::WrappedEvent*>(event);
QMouseEvent* me = static_cast<QMouseEvent*>(we->event());
if (me->modifiers() & Qt::ShiftModifier)
return false;
return canvas->fotoScoreViewDragRectTest(me);
}
public:
FotoScoreViewDragRectTransition(ScoreView* c, QState* target)
: QMouseEventTransition(c, QEvent::MouseButtonPress, Qt::LeftButton), canvas(c) {
setTargetState(target);
}
};
//---------------------------------------------------------
// FotoFrameTransition
//---------------------------------------------------------
class FotoFrameTransition : public QMouseEventTransition
{
ScoreView* canvas;
protected:
virtual bool eventTest(QEvent* event) {
if (!QMouseEventTransition::eventTest(event))
return false;
QStateMachine::WrappedEvent* we = static_cast<QStateMachine::WrappedEvent*>(event);
QMouseEvent* me = static_cast<QMouseEvent*>(we->event());
return !canvas->fotoRectHit(me->pos());
}
public:
FotoFrameTransition(ScoreView* c, QState* target)
: QMouseEventTransition(c, QEvent::MouseButtonPress, Qt::LeftButton), canvas(c) {
setTargetState(target);
setModifierMask(Qt::ShiftModifier);
}
};
//---------------------------------------------------------
// FotoEditElementDragTransition
//---------------------------------------------------------
class FotoEditElementDragTransition : public QMouseEventTransition
{
ScoreView* canvas;
protected:
virtual bool eventTest(QEvent* event) {
if (!QMouseEventTransition::eventTest(event))
return false;
QStateMachine::WrappedEvent* we = static_cast<QStateMachine::WrappedEvent*>(event);
QMouseEvent* me = static_cast<QMouseEvent*>(we->event());
return canvas->fotoEditElementDragTransition(me);
}
public:
FotoEditElementDragTransition(ScoreView* c, QState* target)
: QMouseEventTransition(c, QEvent::MouseButtonPress, Qt::LeftButton), canvas(c) {
setTargetState(target);
}
};
//---------------------------------------------------------
// FotoDragEditTransition
//---------------------------------------------------------
class FotoDragEditTransition : public QEventTransition
{
ScoreView* canvas;
protected:
virtual void onTransition(QEvent* e) {
QStateMachine::WrappedEvent* we = static_cast<QStateMachine::WrappedEvent*>(e);
QMouseEvent* me = static_cast<QMouseEvent*>(we->event());
canvas->doFotoDragEdit(me);
}
public:
FotoDragEditTransition(ScoreView* c)
: QEventTransition(c, QEvent::MouseMove), canvas(c) {}
};
//---------------------------------------------------------
// FotoDragTransition
//---------------------------------------------------------
class FotoDragTransition : public QEventTransition
{
ScoreView* canvas;
protected:
virtual void onTransition(QEvent* e) {
QStateMachine::WrappedEvent* we = static_cast<QStateMachine::WrappedEvent*>(e);
QMouseEvent* me = static_cast<QMouseEvent*>(we->event());
canvas->doDragFoto(me);
}
public:
FotoDragTransition(ScoreView* c)
: QEventTransition(c, QEvent::MouseMove), canvas(c) {}
};
//---------------------------------------------------------
// FotoDragRectTransition
//---------------------------------------------------------
class FotoDragRectTransition : public QEventTransition
{
ScoreView* canvas;
protected:
virtual void onTransition(QEvent* e) {
QStateMachine::WrappedEvent* we = static_cast<QStateMachine::WrappedEvent*>(e);
QMouseEvent* me = static_cast<QMouseEvent*>(we->event());
canvas->doDragFotoRect(me);
}
public:
FotoDragRectTransition(ScoreView* c)
: QEventTransition(c, QEvent::MouseMove), canvas(c) {}
};
//---------------------------------------------------------
// FotoContextTransition
//---------------------------------------------------------
class FotoContextTransition : public QEventTransition
{
ScoreView* canvas;
protected:
virtual bool eventTest(QEvent* e) {
if (!QEventTransition::eventTest(e))
return false;
QStateMachine::WrappedEvent* we = static_cast<QStateMachine::WrappedEvent*>(e);
QContextMenuEvent* me = static_cast<QContextMenuEvent*>(we->event());
return canvas->fotoRectHit(me->pos());
}
virtual void onTransition(QEvent* e) {
QContextMenuEvent* me = static_cast<QContextMenuEvent*>(static_cast<QStateMachine::WrappedEvent*>(e)->event());
canvas->fotoContextPopup(me);
}
public:
FotoContextTransition(ScoreView* c)
: QEventTransition(c, QEvent::ContextMenu), canvas(c) {}
};
//---------------------------------------------------------
// FotoDragDropTransition
//---------------------------------------------------------
class FotoDragDropTransition : public QMouseEventTransition
{
ScoreView* canvas;
protected:
virtual bool eventTest(QEvent* event) {
if (!QMouseEventTransition::eventTest(event))
return false;
QStateMachine::WrappedEvent* we = static_cast<QStateMachine::WrappedEvent*>(event);
QMouseEvent* me = static_cast<QMouseEvent*>(we->event());
return canvas->fotoRectHit(me->pos());
}
virtual void onTransition(QEvent* e) {
QStateMachine::WrappedEvent* we = static_cast<QStateMachine::WrappedEvent*>(e);
QMouseEvent* me = static_cast<QMouseEvent*>(we->event());
canvas->fotoDragDrop(me);
}
public:
FotoDragDropTransition(ScoreView* c)
: QMouseEventTransition(c, QEvent::MouseButtonPress, Qt::LeftButton), canvas(c)
{
setModifierMask(Qt::KeyboardModifiers(Qt::ShiftModifier | Qt::ControlModifier));
}
};
//---------------------------------------------------------
// setupFotoMode
//---------------------------------------------------------
void ScoreView::setupFotoMode()
{
QState* s = states[FOTOMODE];
s->assignProperty(this, "cursor", QCursor(Qt::ArrowCursor));
s->addTransition(new CommandTransition("escape", states[NORMAL])); // ->normal
s->addTransition(new CommandTransition("fotomode", states[NORMAL])); // ->normal
s->addTransition(new ScoreViewDragTransition(this, states[DRAG])); // ->stateDrag
CommandTransition* ct = new CommandTransition("copy", 0); // copy
connect(ct, SIGNAL(triggered()), SLOT(fotoModeCopy()));
s->addTransition(ct);
QState* f1 = new QState(s);
f1->setObjectName("foto-normal");
connect(f1, SIGNAL(entered()), SLOT(enterState()));
connect(f1, SIGNAL(exited()), SLOT(exitState()));
//
// in the f2 state the canvas is dragged
//
QState* f2 = new QState(s);
f2->setObjectName("foto-drag");
connect(f2, SIGNAL(entered()), SLOT(enterState()));
connect(f2, SIGNAL(exited()), SLOT(exitState()));
//
// state f3 draws the foto rectangle
//
QState* f3 = new QState(s);
f3->setObjectName("foto-frame");
connect(f3, SIGNAL(entered()), SLOT(enterState()));
connect(f3, SIGNAL(exited()), SLOT(exitState()));
//
// f4 drags the foto rectangle grips
//
QState* f4 = new QState(s);
f4->setObjectName("foto-drag-edit");
connect(f4, SIGNAL(entered()), SLOT(enterState()));
connect(f4, SIGNAL(exited()), SLOT(exitState()));
//
// f5 drags the foto rectangle itself
//
QState* f5 = new QState(s);
f5->setObjectName("foto-drag-rect");
connect(f5, SIGNAL(entered()), SLOT(enterState()));
connect(f5, SIGNAL(exited()), SLOT(exitState()));
f1->assignProperty(this, "cursor", QCursor(Qt::ArrowCursor));
f1->addTransition(new FotoScoreViewDragTransition(this, f2)); // ->stateDrag
f1->addTransition(new FotoFrameTransition(this, f3)); // ->stateLasso
f1->addTransition(new FotoEditElementDragTransition(this, f4)); // ->editDrag
f1->addTransition(new FotoScoreViewDragRectTransition(this, f5)); // ->foto-drag-rect
f1->addTransition(new FotoContextTransition(this)); // context menu
f1->addTransition(new FotoDragDropTransition(this));
// drag canvas in foto state
f2->assignProperty(this, "cursor", QCursor(Qt::SizeAllCursor));
QEventTransition* cl = new QEventTransition(this, QEvent::MouseButtonRelease);
cl->setTargetState(f1);
f2->addTransition(cl);
f2->addTransition(new DragTransition(this));
// drag foto frame
f3->assignProperty(this, "cursor", QCursor(Qt::ArrowCursor));
cl = new QEventTransition(this, QEvent::MouseButtonRelease);
cl->setTargetState(f1);
f3->addTransition(cl);
f3->addTransition(new class FotoDragTransition(this));
connect(f3, SIGNAL(entered()), SLOT(startFotoDrag()));
connect(f3, SIGNAL(exited()), SLOT(endFotoDrag()));
// foto drag edit state
f4->assignProperty(this, "cursor", QCursor(Qt::ArrowCursor));
cl = new QEventTransition(this, QEvent::MouseButtonRelease);
cl->setTargetState(f1);
f4->addTransition(cl);
f4->addTransition(new FotoDragEditTransition(this));
connect(f4, SIGNAL(exited()), SLOT(endFotoDragEdit()));
f5->assignProperty(this, "cursor", QCursor(Qt::SizeAllCursor));
cl = new QEventTransition(this, QEvent::MouseButtonRelease);
cl->setTargetState(f1);
f5->addTransition(cl);
f5->addTransition(new class FotoDragRectTransition(this));
s->setInitialState(f1);
s->addTransition(new ScoreViewDragTransition(this, f2));
connect(s, SIGNAL(entered()), SLOT(startFotomode()));
connect(s, SIGNAL(exited()), SLOT(stopFotomode()));
}
//---------------------------------------------------------
// startFotomode
//---------------------------------------------------------
void ScoreView::startFotomode()
{
editObject = _foto;
_foto->startEdit(this, QPointF());
qreal w = 8.0 / _matrix.m11();
qreal h = 8.0 / _matrix.m22();
QRectF r(-w*.5, -h*.5, w, h);
// try to find existing rect within current view
QRectF view = toLogical(QRect(0.0, 0.0, width(), height()));
if (_foto->rect().isEmpty() || !view.intersects(_foto->rect())) {
// rect not found - construct new rect with default size & relative position
qreal w = view.width();
qreal h = view.height();
QRectF rect(w * .3, h * .3, w * .4, h * .4);
// convert to absolute position
_foto->setRect(rect.translated(view.topLeft()));
}
grip.resize(8);
for (QRectF& p : grip)
p = r;
curGrip = Grip::START;
updateGrips();
_score->addRefresh(_foto->abbox());
_score->end();
mscore->changeState(STATE_FOTO);
}
//---------------------------------------------------------
// stopFotomode
//---------------------------------------------------------
void ScoreView::stopFotomode()
{
QAction* a = getAction("fotomode");
a->setChecked(false);
editObject = 0;
grips = 0;
_foto->endEdit();
update();
}
//---------------------------------------------------------
// startFotoDrag
//---------------------------------------------------------
void ScoreView::startFotoDrag()
{
_score->addRefresh(_foto->abbox());
_score->end();
grips = 0;
}
//---------------------------------------------------------
// doDragFoto
// drag canvas in foto mode
//---------------------------------------------------------
void ScoreView::doDragFoto(QMouseEvent* ev)
{
QPointF p = toLogical(ev->pos());
QRectF r;
r.setCoords(data.startMove.x(), data.startMove.y(), p.x(), p.y());
_foto->setRect(r.normalized());
QRectF rr(_foto->rect());
r = _matrix.mapRect(rr);
//QSize sz(r.size().toSize());
//mscore->statusBar()->showMessage(QString("%1 x %2").arg(sz.width()).arg(sz.height()), 3000);
update();
//mscore->showMessage("drag", 2000);
}
//---------------------------------------------------------
// endFotoDrag
//---------------------------------------------------------
void ScoreView::endFotoDrag()
{
qreal w = 8.0 / _matrix.m11();
qreal h = 8.0 / _matrix.m22();
QRectF r(-w*.5, -h*.5, w, h);
for (int i = 0; i < 8; ++i)
grip[i] = r;
editObject = _foto;
updateGrips();
_score->setUpdateAll();
_score->end();
}
//---------------------------------------------------------
// doFotoDragEdit
//---------------------------------------------------------
void ScoreView::doFotoDragEdit(QMouseEvent* ev)
{
QPointF p = toLogical(ev->pos());
QPointF delta = p - data.startMove;
_score->setLayoutAll(false);
score()->addRefresh(_foto->abbox());
EditData ed;
ed.curGrip = curGrip;
ed.delta = delta;
ed.view = this;
_foto->editDrag(ed);
updateGrips();
data.startMove = p;
_score->end();
if (mscore->inspector())
mscore->inspector()->setElement(_foto);
}
//---------------------------------------------------------
// endFotoDragEdit
//---------------------------------------------------------
void ScoreView::endFotoDragEdit()
{
}
//---------------------------------------------------------
// fotoEditElementDragTransition
//---------------------------------------------------------
bool ScoreView::fotoEditElementDragTransition(QMouseEvent* ev)
{
data.startMove = imatrix.map(QPointF(ev->pos()));
int i;
for (i = 0; i < grips; ++i) {
if (grip[i].contains(data.startMove)) {
curGrip = Grip(i);
switch (int(curGrip)) {
case 0:
case 2:
setCursor(Qt::SizeFDiagCursor);
break;
case 1:
case 3:
setCursor(Qt::SizeBDiagCursor);
break;
case 4:
case 6:
setCursor(Qt::SizeVerCursor);
break;
case 5:
case 7:
setCursor(Qt::SizeHorCursor);
break;
}
updateGrips();
score()->end();
break;
}
}
return i != grips;
}
//---------------------------------------------------------
// fotoScoreViewDragTest
//---------------------------------------------------------
bool ScoreView::fotoScoreViewDragTest(QMouseEvent* me)
{
QPointF p(imatrix.map(QPointF(me->pos())));
if (_foto->rect().contains(p))
return false;
for (int i = 0; i < grips; ++i) {
if (grip[i].contains(p))
return false;
}
data.startMove = p;
return true;
}
//---------------------------------------------------------
// fotoScoreViewDragRectTest
//---------------------------------------------------------
bool ScoreView::fotoScoreViewDragRectTest(QMouseEvent* me)
{
QPointF p(toLogical(me->pos()));
if (!_foto->rect().contains(p))
return false;
for (int i = 0; i < grips; ++i) {
if (grip[i].contains(p))
return false;
}
data.startMove = p;
return true;
}
//---------------------------------------------------------
// doDragFotoRect
//---------------------------------------------------------
void ScoreView::doDragFotoRect(QMouseEvent* ev)
{
QPointF p(toLogical(ev->pos()));
QPointF delta = p - data.startMove;
_score->setLayoutAll(false);
score()->addRefresh(_foto->abbox());
_foto->setRect(_foto->rect().translated(delta));
score()->addRefresh(_foto->abbox());
data.startMove = p;
updateGrips();
_score->end();
if (mscore->inspector())
mscore->inspector()->setElement(_foto);
}
//---------------------------------------------------------
// MenuEntry
//---------------------------------------------------------
struct MenuEntry {
const char* text;
const char* label;
};
static const MenuEntry resizeEntry[4] {
{ QT_TRANSLATE_NOOP("fotomode", "Resize to A"), "resizeA" },
{ QT_TRANSLATE_NOOP("fotomode", "Resize to B"), "resizeB" },
{ QT_TRANSLATE_NOOP("fotomode", "Resize to C"), "resizeC" },
{ QT_TRANSLATE_NOOP("fotomode", "Resize to D"), "resizeD" }
};
static const MenuEntry setSizeEntry[4] {
{ QT_TRANSLATE_NOOP("fotomode", "Set size A"), "setA" },
{ QT_TRANSLATE_NOOP("fotomode", "Set size B"), "setB" },
{ QT_TRANSLATE_NOOP("fotomode", "Set size C"), "setC" },
{ QT_TRANSLATE_NOOP("fotomode", "Set size D"), "setD" }
};
//---------------------------------------------------------
// fotoContextPopup
//---------------------------------------------------------
void ScoreView::fotoContextPopup(QContextMenuEvent* ev)
{
QPoint pos(ev->globalPos());
QMenu* popup = new QMenu(this);
popup->setSeparatorsCollapsible(false);
QAction* a = popup->addSeparator();
a->setText(tr("Image Capture"));
a = getAction("copy");
popup->addAction(a);
popup->addSeparator();
a = popup->addAction(tr("Resolution (%1 DPI)...").arg(preferences.pngResolution));
a->setData("set-res");
QAction* bgAction = popup->addAction(tr("Transparent background"));
bgAction->setCheckable(true);
bgAction->setChecked(preferences.pngTransparent);
bgAction->setData("set-bg");
popup->addSeparator();
a = new QAction(tr("Auto-resize to page"), this);
a->setData("resizePage");
popup->addAction(a);
for (int i = 0; i < 4; ++i) {
a = new QAction(qApp->translate("fotomode", resizeEntry[i].text), this);
a->setData(resizeEntry[i].label);
popup->addAction(a);
}
QMenu* setSize = new QMenu(tr("Set Standard Size..."));
for (int i = 0; i < 4; ++i) {
a = new QAction(qApp->translate("fotomode", setSizeEntry[i].text), this);
a->setData(setSizeEntry[i].label);
setSize->addAction(a);
}
popup->addMenu(setSize);
popup->addSeparator();
a = new QAction(tr("Save As (Print Mode)..."), this);
a->setData("print");
popup->addAction(a);
a = new QAction(tr("Save As (Screenshot Mode)..."), this);
a->setData("screenshot");
popup->addAction(a);
a = popup->exec(pos);
if (a == 0)
return;
QString cmd(a->data().toString());
if (cmd == "print")
saveFotoAs(true, _foto->rect().normalized());
else if (cmd == "screenshot")
saveFotoAs(false, _foto->rect().normalized());
else if (cmd == "copy")
;
else if (cmd == "set-res") {
bool ok;
double resolution = QInputDialog::getDouble(this,
tr("Set Output Resolution"),
tr("Set output resolution for PNG"),
preferences.pngResolution,
16.0, 2400.0, 1,
&ok
);
if (ok) {
preferences.pngResolution = resolution;
preferences.dirty = true;
}
}
else if (cmd == "resizePage") {
QRectF r = _foto->rect();
Page* page = point2page(r.center());
if (page) {
r = page->tbbox().translated(page->canvasPos());
_foto->setRect(r);
updateGrips();
}
}
else if (cmd.startsWith("resize")) {
QString size = QSettings().value(QString("fotoSize%1").arg(cmd[6]), "50x40").toString();
qreal w = size.split("x")[0].toDouble();
qreal h = size.split("x")[1].toDouble();
_foto->setSize(w * DPMM, h * DPMM);
updateGrips();
}
else if (cmd.startsWith("set")) {
qreal w = _foto->rect().width() / DPMM;
qreal h = _foto->rect().height() / DPMM;
QString val(QString("%1x%2").arg(w).arg(h));
QSettings().setValue(QString("fotoSize%1").arg(cmd[3]), val);
}
if (bgAction->isChecked() != preferences.pngTransparent) {
preferences.pngTransparent = bgAction->isChecked();
preferences.dirty = true;
}
}
//---------------------------------------------------------
// fotoModeCopy
//---------------------------------------------------------
void ScoreView::fotoModeCopy()
{
#if defined(Q_OS_WIN)
// See https://bugreports.qt.io/browse/QTBUG-11463
// while transparent copy/paste works fine inside musescore,
// it does not paste into other programs in Windows though
bool transparent = false;
#else
bool transparent = preferences.pngTransparent;
#endif
double convDpi = preferences.pngResolution;
double mag = convDpi / DPI;
QRectF r(_foto->rect().normalized());
int w = lrint(r.width() * mag);
int h = lrint(r.height() * mag);
QImage::Format f;
f = QImage::Format_ARGB32_Premultiplied;
QImage printer(w, h, f);
printer.setDotsPerMeterX(lrint(DPMM * 1000.0));
printer.setDotsPerMeterY(lrint(DPMM * 1000.0));
printer.fill(transparent ? 0 : 0xffffffff);
QPainter p(&printer);
paintRect(true, p, r, mag);
#if defined(Q_OS_WIN)
// workaround for apparent Qt 5.4 bug; corrupt clipboard when using setImage()
QPixmap px;
px.convertFromImage(printer);
QApplication::clipboard()->setPixmap(px);
#else
QApplication::clipboard()->setImage(printer);
#endif
}
//---------------------------------------------------------
// fotoRectHit
//---------------------------------------------------------
bool ScoreView::fotoRectHit(const QPoint& pos)
{
QPointF p = toLogical(pos);
for (int i = 0; i < grips; ++i) {
if (grip[i].contains(p))
return false;
}
data.startMove = p;
return _foto->rect().contains(p);
}
//---------------------------------------------------------
// saveFotoAs
// return true on success
//---------------------------------------------------------
bool ScoreView::saveFotoAs(bool printMode, const QRectF& r)
{
QStringList fl;
fl.append(tr("PNG Bitmap Graphic") + " (*.png)");
fl.append(tr("PDF File") + " (*.pdf)");
fl.append(tr("Scalable Vector Graphics") + " (*.svg)");
QString selectedFilter;
QString filter = fl.join(";;");
QString fn = mscore->getFotoFilename(filter, &selectedFilter);
if (fn.isEmpty())
return false;
QFileInfo fi(fn);
mscore->lastSaveDirectory = fi.absolutePath();
QString ext;
if (selectedFilter.isEmpty()) {
ext = fi.suffix();
}
else {
int idx = fl.indexOf(selectedFilter);
if (idx != -1) {
static const char* extensions[] = {
"png", "pdf", "svg"
};
ext = extensions[idx];
}
}
if (ext.isEmpty()) {
QMessageBox::critical(mscore, tr("Save As"), tr("Cannot determine file type"));
return false;
}
ext = ext.toLower();
if (fi.suffix().toLower() != ext)
fn += "." + ext;
bool transparent = preferences.pngTransparent;
double convDpi = preferences.pngResolution;
double mag = convDpi / DPI;
if (ext == "svg") mag = 1; // SVG is not scaled, it's scalable.
int w = lrint(r.width() * mag);
int h = lrint(r.height() * mag);
if (ext == "pdf") {
QPrinter printer(QPrinter::HighResolution);
printer.setOutputFormat(QPrinter::PdfFormat);
mag = printer.logicalDpiX() / DPI;
printer.setPaperSize(QSizeF(r.width() * mag, r.height() * mag) , QPrinter::DevicePixel);
printer.setCreator("MuseScore Version: " VERSION);
printer.setFullPage(true);
printer.setColorMode(QPrinter::Color);
printer.setDocName(fn);
printer.setOutputFileName(fn);
QPainter p(&printer);
MScore::pdfPrinting = true;
paintRect(printMode, p, r, mag);
MScore::pdfPrinting = false;
}
else if (ext == "svg") {
// note that clipping is not implemented
// (as of 4.8)
SvgGenerator printer;
printer.setFileName(fn);
printer.setTitle(_score->title());
printer.setSize(QSize(w, h));
printer.setViewBox(QRect(0, 0, w, h));
QPainter p(&printer);
MScore::pdfPrinting = true;
paintRect(printMode, p, r, mag);
MScore::pdfPrinting = false;
}
else if (ext == "png") {
QImage::Format f = QImage::Format_ARGB32_Premultiplied;
QImage printer(w, h, f);
printer.setDotsPerMeterX(lrint((convDpi * 1000) / INCH));
printer.setDotsPerMeterY(lrint((convDpi * 1000) / INCH));
printer.fill(transparent ? 0 : 0xffffffff);
QPainter p(&printer);
paintRect(printMode, p, r, mag);
printer.save(fn, "png");
}
else
qDebug("unknown extension <%s>", qPrintable(ext));
return true;
}
//---------------------------------------------------------
// paintRect
//---------------------------------------------------------
void ScoreView::paintRect(bool printMode, QPainter& p, const QRectF& r, double mag)
{
p.scale(mag, mag);
p.translate(-r.topLeft());
p.setRenderHint(QPainter::Antialiasing, true);
p.setRenderHint(QPainter::TextAntialiasing, true);
score()->setPrinting(printMode);
foreach (Page* page, _score->pages()) {
// QRectF pr(page->abbox());
QRectF pr(page->canvasBoundingRect());
if (pr.right() < r.left())
continue;
if (pr.left() > r.right())
break;
p.translate(page->pos());
QList<Element*> ell = page->items(r.translated(-page->pos()));
qStableSort(ell.begin(), ell.end(), elementLessThan);
drawElements(p, ell);
p.translate(-page->pos());
}
score()->setPrinting(false);
p.end();
}
//---------------------------------------------------------
// fotoDragDrop
//---------------------------------------------------------
void ScoreView::fotoDragDrop(QMouseEvent*)
{
bool printMode = true;
QRectF r(_foto->rect());
QTemporaryFile tf(QDir::tempPath() + QString("/imgXXXXXX.svg"));
tf.setAutoRemove(false);
tf.open();
tf.close();
qDebug("Temp File <%s>", qPrintable(tf.fileName()));
// QString fn = "/home/ws/mops.eps";
QString fn = tf.fileName();
int w = lrint(r.width());
int h = lrint(r.height());
SvgGenerator printer;
printer.setFileName(fn);
printer.setTitle(_score->title());
printer.setSize(QSize(w, h));
printer.setViewBox(QRect(0, 0, w, h));
QPainter p(&printer);
MScore::pdfPrinting = true;
paintRect(printMode, p, r, 1);
MScore::pdfPrinting = false;
QDrag* drag = new QDrag(this);
QMimeData* mimeData = new QMimeData;
QUrl url = QUrl::fromLocalFile(fn);
QList<QUrl> ul;
ul.append(url);
mimeData->setUrls(ul);
drag->setMimeData(mimeData);
drag->start(Qt::CopyAction);
}
}
|