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 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996
|
//=============================================================================
// 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
//=============================================================================
/**
\file
Implementation of Element, ElementList, StaffLines.
*/
#include "element.h"
#include "accidental.h"
#include "ambitus.h"
#include "arpeggio.h"
#include "articulation.h"
#include "bagpembell.h"
#include "barline.h"
#include "bend.h"
#include "box.h"
#include "bracket.h"
#include "breath.h"
#include "chord.h"
#include "chordline.h"
#include "chordrest.h"
#include "clef.h"
#include "dynamic.h"
#include "figuredbass.h"
#include "fingering.h"
#include "fret.h"
#include "glissando.h"
#include "hairpin.h"
#include "harmony.h"
#include "icon.h"
#include "image.h"
#include "iname.h"
#include "instrchange.h"
#include "jump.h"
#include "keysig.h"
#include "layoutbreak.h"
#include "lyrics.h"
#include "marker.h"
#include "measure.h"
#include "mscore.h"
#include "notedot.h"
#include "note.h"
#include "noteline.h"
#include "ossia.h"
#include "ottava.h"
#include "page.h"
#include "pedal.h"
#include "rehearsalmark.h"
#include "repeat.h"
#include "rest.h"
#include "score.h"
#include "segment.h"
#include "slur.h"
#include "spacer.h"
#include "staff.h"
#include "staffstate.h"
#include "stafftext.h"
#include "stafftype.h"
#include "stem.h"
#include "style.h"
#include "symbol.h"
#include "sym.h"
#include "system.h"
#include "tempotext.h"
#include "textframe.h"
#include "text.h"
#include "textline.h"
#include "timesig.h"
#include "tremolobar.h"
#include "tremolo.h"
#include "trill.h"
#include "undo.h"
#include "utils.h"
#include "volta.h"
#include "xml.h"
namespace Ms {
// extern bool showInvisible;
//
// list has to be synchronized with Element::Type enum
//
static const ElementName elementNames[] = {
ElementName("invalid", QT_TRANSLATE_NOOP("elementName", "invalid")),
ElementName("Symbol", QT_TRANSLATE_NOOP("elementName", "Symbol")),
ElementName("Text", QT_TRANSLATE_NOOP("elementName", "Text")),
ElementName("InstrumentName", QT_TRANSLATE_NOOP("elementName", "Instrument Name")),
ElementName("SlurSegment", QT_TRANSLATE_NOOP("elementName", "Slur Segment")),
ElementName("StaffLines", QT_TRANSLATE_NOOP("elementName", "Staff Lines")),
ElementName("BarLine", QT_TRANSLATE_NOOP("elementName", "Barline")),
ElementName("StemSlash", QT_TRANSLATE_NOOP("elementName", "Stem Slash")),
ElementName("Line", QT_TRANSLATE_NOOP("elementName", "Line")),
ElementName("Arpeggio", QT_TRANSLATE_NOOP("elementName", "Arpeggio")),
ElementName("Accidental", QT_TRANSLATE_NOOP("elementName", "Accidental")),
ElementName("Stem", QT_TRANSLATE_NOOP("elementName", "Stem")),
ElementName("Note", QT_TRANSLATE_NOOP("elementName", "Note")),
ElementName("Clef", QT_TRANSLATE_NOOP("elementName", "Clef")),
ElementName("KeySig", QT_TRANSLATE_NOOP("elementName", "Key Signature")),
ElementName("Ambitus", QT_TRANSLATE_NOOP("elementName", "Ambitus")),
ElementName("TimeSig", QT_TRANSLATE_NOOP("elementName", "Time Signature")),
ElementName("Rest", QT_TRANSLATE_NOOP("elementName", "Rest")),
ElementName("Breath", QT_TRANSLATE_NOOP("elementName", "Breath")),
ElementName("RepeatMeasure", QT_TRANSLATE_NOOP("elementName", "Repeat Measure")),
ElementName("Image", QT_TRANSLATE_NOOP("elementName", "Image")),
ElementName("Tie", QT_TRANSLATE_NOOP("elementName", "Tie")),
ElementName("Articulation", QT_TRANSLATE_NOOP("elementName", "Articulation")),
ElementName("ChordLine", QT_TRANSLATE_NOOP("elementName", "Chord Line")),
ElementName("Dynamic", QT_TRANSLATE_NOOP("elementName", "Dynamic")),
ElementName("Beam", QT_TRANSLATE_NOOP("elementName", "Beam")),
ElementName("Hook", QT_TRANSLATE_NOOP("elementName", "Hook")),
ElementName("Lyrics", QT_TRANSLATE_NOOP("elementName", "Lyrics")),
ElementName("FiguredBass", QT_TRANSLATE_NOOP("elementName", "Figured Bass")),
ElementName("Marker", QT_TRANSLATE_NOOP("elementName", "Marker")),
ElementName("Jump", QT_TRANSLATE_NOOP("elementName", "Jump")),
ElementName("Fingering", QT_TRANSLATE_NOOP("elementName", "Fingering")),
ElementName("Tuplet", QT_TRANSLATE_NOOP("elementName", "Tuplet")),
ElementName("Tempo", QT_TRANSLATE_NOOP("elementName", "Tempo")),
ElementName("StaffText", QT_TRANSLATE_NOOP("elementName", "Staff Text")),
ElementName("RehearsalMark", QT_TRANSLATE_NOOP("elementName", "Rehearsal Mark")),
ElementName("InstrumentChange", QT_TRANSLATE_NOOP("elementName", "Instrument Change")),
ElementName("Harmony", QT_TRANSLATE_NOOP("elementName", "Chord Symbol")),
ElementName("FretDiagram", QT_TRANSLATE_NOOP("elementName", "Fretboard Diagram")),
ElementName("Bend", QT_TRANSLATE_NOOP("elementName", "Bend")),
ElementName("TremoloBar", QT_TRANSLATE_NOOP("elementName", "Tremolo Bar")),
ElementName("Volta", QT_TRANSLATE_NOOP("elementName", "Volta")),
ElementName("HairpinSegment", QT_TRANSLATE_NOOP("elementName", "Hairpin Segment")),
ElementName("OttavaSegment", QT_TRANSLATE_NOOP("elementName", "Ottava Segment")),
ElementName("TrillSegment", QT_TRANSLATE_NOOP("elementName", "Trill Segment")),
ElementName("TextLineSegment", QT_TRANSLATE_NOOP("elementName", "Text Line Segment")),
ElementName("VoltaSegment", QT_TRANSLATE_NOOP("elementName", "Volta Segment")),
ElementName("PedalSegment", QT_TRANSLATE_NOOP("elementName", "Pedal Segment")),
ElementName("LyricsLineSegment", QT_TRANSLATE_NOOP("elementName", "Melisma Line Segment")),
ElementName("GlissandoSegment", QT_TRANSLATE_NOOP("elementName", "Glissando Segment")),
ElementName("LayoutBreak", QT_TRANSLATE_NOOP("elementName", "Layout Break")),
ElementName("Spacer", QT_TRANSLATE_NOOP("elementName", "Spacer")),
ElementName("StaffState", QT_TRANSLATE_NOOP("elementName", "Staff State")),
ElementName("LedgerLine", QT_TRANSLATE_NOOP("elementName", "Ledger Line")),
ElementName("NoteHead", QT_TRANSLATE_NOOP("elementName", "Note Head")),
ElementName("NoteDot", QT_TRANSLATE_NOOP("elementName", "Note Dot")),
ElementName("Tremolo", QT_TRANSLATE_NOOP("elementName", "Tremolo")),
ElementName("Measure", QT_TRANSLATE_NOOP("elementName", "Measure")),
ElementName("Selection", QT_TRANSLATE_NOOP("elementName", "Selection")),
ElementName("Lasso", QT_TRANSLATE_NOOP("elementName", "Lasso")),
ElementName("ShadowNote", QT_TRANSLATE_NOOP("elementName", "Shadow Note")),
ElementName("TabDurationSymbol", QT_TRANSLATE_NOOP("elementName", "Tab Duration Symbol")),
ElementName("FSymbol", QT_TRANSLATE_NOOP("elementName", "Font Symbol")),
ElementName("Page", QT_TRANSLATE_NOOP("elementName", "Page")),
ElementName("HairPin", QT_TRANSLATE_NOOP("elementName", "Hairpin")),
ElementName("Ottava", QT_TRANSLATE_NOOP("elementName", "Ottava")),
ElementName("Pedal", QT_TRANSLATE_NOOP("elementName", "Pedal")),
ElementName("Trill", QT_TRANSLATE_NOOP("elementName", "Trill")),
ElementName("TextLine", QT_TRANSLATE_NOOP("elementName", "Text Line")),
ElementName("NoteLine", QT_TRANSLATE_NOOP("elementName", "Note Line")),
ElementName("LyricsLine", QT_TRANSLATE_NOOP("elementName", "Melisma Line")),
ElementName("Glissando", QT_TRANSLATE_NOOP("elementName", "Glissando")),
ElementName("Bracket", QT_TRANSLATE_NOOP("elementName", "Bracket")),
ElementName("Segment", QT_TRANSLATE_NOOP("elementName", "Segment")),
ElementName("System", QT_TRANSLATE_NOOP("elementName", "System")),
ElementName("Compound", QT_TRANSLATE_NOOP("elementName", "Compound")),
ElementName("Chord", QT_TRANSLATE_NOOP("elementName", "Chord")),
ElementName("Slur", QT_TRANSLATE_NOOP("elementName", "Slur")),
ElementName("Element", QT_TRANSLATE_NOOP("elementName", "Element")),
ElementName("ElementList", QT_TRANSLATE_NOOP("elementName", "Element List")),
ElementName("StaffList", QT_TRANSLATE_NOOP("elementName", "Staff List")),
ElementName("MeasureList", QT_TRANSLATE_NOOP("elementName", "Measure List")),
ElementName("HBox", QT_TRANSLATE_NOOP("elementName", "Horizontal Frame")),
ElementName("VBox", QT_TRANSLATE_NOOP("elementName", "Vertical Frame")),
ElementName("TBox", QT_TRANSLATE_NOOP("elementName", "Text Frame")),
ElementName("FBox", QT_TRANSLATE_NOOP("elementName", "Fretboard Diagram Frame")),
ElementName("Icon", QT_TRANSLATE_NOOP("elementName", "Icon")),
ElementName("Ossia", QT_TRANSLATE_NOOP("elementName", "Ossia")),
ElementName("BagpipeEmbellishment", QT_TRANSLATE_NOOP("elementName", "Bagpipe Embellishment"))
};
//---------------------------------------------------------
// DropData
//---------------------------------------------------------
DropData::DropData()
{
view = 0;
element = 0;
duration = Fraction(1,4);
modifiers = 0;
}
//---------------------------------------------------------
// spatiumChanged
//---------------------------------------------------------
void Element::spatiumChanged(qreal oldValue, qreal newValue)
{
_userOff *= (newValue / oldValue);
_readPos *= (newValue / oldValue);
}
//---------------------------------------------------------
// localSpatiumChanged
// the scale of a staff changed
//---------------------------------------------------------
void Element::localSpatiumChanged(qreal oldValue, qreal newValue)
{
_userOff *= (newValue / oldValue);
}
//---------------------------------------------------------
// spatium
//---------------------------------------------------------
qreal Element::spatium() const
{
Staff* s = staff();
return s ? s->spatium() : _score->spatium();
}
//---------------------------------------------------------
// magS
//---------------------------------------------------------
qreal Element::magS() const
{
return mag() * (_score->spatium() / SPATIUM20);
}
//---------------------------------------------------------
// name
//---------------------------------------------------------
const char* Element::name() const
{
return name(type());
}
//---------------------------------------------------------
// name
//---------------------------------------------------------
QString Element::subtypeName() const
{
return "";
}
//---------------------------------------------------------
// userName
//---------------------------------------------------------
QString Element::userName() const
{
return qApp->translate("elementName", elementNames[int(type())].userName);
}
//---------------------------------------------------------
// ~Element
//---------------------------------------------------------
Element::~Element()
{
if (_links) {
_links->removeOne(this);
if (_links->isEmpty()) {
//DEBUG:
score()->links().remove(_links->lid());
//
delete _links;
}
}
}
//---------------------------------------------------------
// Element
//---------------------------------------------------------
Element::Element(Score* s) :
QObject(0), ScoreElement(s)
{
_selected = false;
_generated = false;
_visible = true;
_placement = Placement::BELOW;
_flags = ElementFlag::SELECTABLE;
_track = -1;
_color = MScore::defaultColor;
_mag = 1.0;
_tag = 1;
itemDiscovered = false;
}
Element::Element(const Element& e)
: QObject(0), ScoreElement(e)
{
_parent = e._parent;
_selected = e._selected;
_generated = e._generated;
_visible = e._visible;
_placement = e._placement;
_flags = e._flags;
_track = e._track;
_color = e._color;
_mag = e._mag;
_pos = e._pos;
_userOff = e._userOff;
_readPos = e._readPos;
_bbox = e._bbox;
_tag = e._tag;
itemDiscovered = false;
}
//---------------------------------------------------------
// linkedClone
//---------------------------------------------------------
Element* Element::linkedClone()
{
Element* e = clone();
score()->undo(new Link(e, this));
return e;
}
//---------------------------------------------------------
// adjustReadPos
//---------------------------------------------------------
void Element::adjustReadPos()
{
if (!_readPos.isNull()) {
_userOff = _readPos - _pos;
_readPos = QPointF();
}
}
//---------------------------------------------------------
// scanElements
//---------------------------------------------------------
void Element::scanElements(void* data, void (*func)(void*, Element*), bool all)
{
if (all || _visible || score()->showInvisible())
func(data, this);
}
//---------------------------------------------------------
// reset
//---------------------------------------------------------
void Element::reset()
{
if (!_userOff.isNull())
score()->undoChangeProperty(this, P_ID::USER_OFF, QPointF());
}
//---------------------------------------------------------
// change
//---------------------------------------------------------
void Element::change(Element* o, Element* n)
{
remove(o);
add(n);
}
//---------------------------------------------------------
// staff
//---------------------------------------------------------
Staff* Element::staff() const
{
if (_track == -1 || score()->staves().isEmpty())
return 0;
return score()->staff(staffIdx());
}
//---------------------------------------------------------
// part
//---------------------------------------------------------
Part* Element::part() const
{
Staff* s = staff();
return s ? s->part() : 0;
}
//---------------------------------------------------------
// curColor
//---------------------------------------------------------
QColor Element::curColor() const
{
return curColor(this);
}
//---------------------------------------------------------
// curColor
//---------------------------------------------------------
QColor Element::curColor(const Element* proxy) const
{
// the default element color is always interpreted as black in
// printing
if (score() && score()->printing())
return (proxy->color() == MScore::defaultColor) ? Qt::black : proxy->color();
if (flag(ElementFlag::DROP_TARGET))
return MScore::dropColor;
bool marked = false;
if (type() == Element::Type::NOTE) {
const Note* note = static_cast<const Note*>(this);
marked = note->mark();
}
if (proxy->selected() || marked ) {
if (track() == -1)
return MScore::selectColor[0];
else
return MScore::selectColor[voice()];
}
if (!proxy->visible())
return Qt::gray;
return proxy->color();
}
//---------------------------------------------------------
// drag
/// Return update Rect relative to canvas.
//---------------------------------------------------------
QRectF Element::drag(EditData* data)
{
QRectF r(canvasBoundingRect());
qreal x = data->delta.x();
qreal y = data->delta.y();
qreal _spatium = spatium();
if (data->hRaster) {
qreal hRaster = _spatium / MScore::hRaster();
int n = lrint(x / hRaster);
x = hRaster * n;
}
if (data->vRaster) {
qreal vRaster = _spatium / MScore::vRaster();
int n = lrint(y / vRaster);
y = vRaster * n;
}
setUserOff(QPointF(x, y));
setGenerated(false);
if (type() == Type::TEXT) { // TODO: check for other types
//
// restrict move to page boundaries
//
QRectF r(canvasBoundingRect());
Page* p = 0;
Element* e = this;
while (e) {
if (e->type() == Element::Type::PAGE) {
p = static_cast<Page*>(e);
break;
}
e = e->parent();
}
if (p) {
bool move = false;
QRectF pr(p->canvasBoundingRect());
if (r.right() > pr.right()) {
x -= r.right() - pr.right();
move = true;
}
else if (r.left() < pr.left()) {
x += pr.left() - r.left();
move = true;
}
if (r.bottom() > pr.bottom()) {
y -= r.bottom() - pr.bottom();
move = true;
}
else if (r.top() < pr.top()) {
y += pr.top() - r.top();
move = true;
}
if (move)
setUserOff(QPointF(x, y));
}
}
return canvasBoundingRect() | r;
}
//---------------------------------------------------------
// pagePos
// return position in canvas coordinates
//---------------------------------------------------------
QPointF Element::pagePos() const
{
QPointF p(pos());
if (parent() == 0)
return p;
if (_flags & ElementFlag::ON_STAFF) {
System* system = nullptr;
if (parent()->type() == Element::Type::SEGMENT)
system = static_cast<Segment*>(parent())->measure()->system();
else if (parent()->type() == Element::Type::MEASURE) // used in measure number
system = static_cast<Measure*>(parent())->system();
else if (parent()->type() == Element::Type::SYSTEM)
system = static_cast<System*>(parent());
else
{Q_ASSERT(false);}
if (system) {
int si = staffIdx();
if (type() == Element::Type::CHORD || type() == Element::Type::REST)
si += static_cast<const ChordRest*>(this)->staffMove();
p.ry() += system->staffYpage(si); // system->staff(si)->y() + system->y();
}
p.rx() = pageX();
}
else {
if (parent()->parent())
p += parent()->pagePos();
}
return p;
}
//---------------------------------------------------------
// canvasPos
//---------------------------------------------------------
QPointF Element::canvasPos() const
{
QPointF p(pos());
if (parent() == 0)
return p;
if (_flags & ElementFlag::ON_STAFF) {
System* system = nullptr;
if (parent()->type() == Element::Type::SEGMENT)
system = static_cast<Segment*>(parent())->system();
else if (parent()->type() == Element::Type::MEASURE) // used in measure number
system = static_cast<Measure*>(parent())->system();
else if (parent()->type() == Element::Type::SYSTEM)
system = static_cast<System*>(parent());
else
{Q_ASSERT(false);}
if (system) {
int si = staffIdx();
if (type() == Element::Type::CHORD || type() == Element::Type::REST)
si += static_cast<const ChordRest*>(this)->staffMove();
p.ry() += system->staffYpage(si); // system->staff(si)->y() + system->y();
Page* page = system->page();
if (page)
p.ry() += page->y();
}
p.rx() = canvasX();
}
else {
p += parent()->canvasPos();
}
return p;
}
//---------------------------------------------------------
// pageX
//---------------------------------------------------------
qreal Element::pageX() const
{
qreal xp = x();
for (Element* e = parent(); e && e->parent(); e = e->parent())
xp += e->x();
return xp;
}
//---------------------------------------------------------
// canvasX
//---------------------------------------------------------
qreal Element::canvasX() const
{
qreal xp = x();
for (Element* e = parent(); e; e = e->parent())
xp += e->x();
return xp;
}
//---------------------------------------------------------
// contains
//---------------------------------------------------------
/**
Return true if \a p is inside the shape of the object.
Note: \a p is in page coordinates
*/
bool Element::contains(const QPointF& p) const
{
return shape().contains(p - pagePos());
}
//---------------------------------------------------------
// shape
//---------------------------------------------------------
/**
Returns the shape of this element as a QPainterPath in local
coordinates. The shape is used for collision detection and
hit tests (contains())
The default implementation calls bbox() to return a simple rectangular
shape, but subclasses can reimplement this function to return a more
accurate shape for non-rectangular elements.
*/
QPainterPath Element::shape() const
{
QPainterPath pp;
pp.addRect(bbox());
return pp;
}
//---------------------------------------------------------
// intersects
//---------------------------------------------------------
/**
Return true if \a rr intersects bounding box of object.
Note: \a rr is in page coordinates
*/
bool Element::intersects(const QRectF& rr) const
{
return shape().intersects(rr.translated(-pagePos()));
}
//---------------------------------------------------------
// writeProperties
//---------------------------------------------------------
void Element::writeProperties(Xml& xml) const
{
//copy paste should not keep links
if (_links && (_links->size() > 1) && !xml.clipboardmode)
xml.tag("lid", _links->lid());
if (!userOff().isNull()) {
if (type() == Element::Type::VOLTA_SEGMENT
|| type() == Element::Type::GLISSANDO_SEGMENT || isChordRest()
|| (xml.clipboardmode && isSLineSegment()))
xml.tag("offset", userOff() / spatium());
else
xml.tag("pos", pos() / score()->spatium());
}
if (((track() != xml.curTrack) || (type() == Element::Type::SLUR)) && (track() != -1)) {
int t;
t = track() + xml.trackDiff;
xml.tag("track", t);
}
if (_tag != 0x1) {
for (int i = 1; i < MAX_TAGS; i++) {
if (_tag == ((unsigned)1 << i)) {
xml.tag("tag", score()->layerTags()[i]);
break;
}
}
}
writeProperty(xml, P_ID::COLOR);
writeProperty(xml, P_ID::VISIBLE);
writeProperty(xml, P_ID::PLACEMENT);
}
//---------------------------------------------------------
// readProperties
//---------------------------------------------------------
bool Element::readProperties(XmlReader& e)
{
const QStringRef& tag(e.name());
if (tag == "track")
setTrack(e.readInt() + e.trackOffset());
else if (tag == "color")
setColor(e.readColor());
else if (tag == "visible")
setVisible(e.readInt());
else if (tag == "selected") // obsolete
e.readInt();
else if (tag == "userOff")
_userOff = e.readPoint();
else if (tag == "lid") {
int id = e.readInt();
_links = score()->links().value(id);
if (!_links) {
if (score()->parentScore()) // DEBUG
qDebug("---link %d not found (%d)", id, score()->links().size());
_links = new LinkedElements(score(), id);
score()->links().insert(id, _links);
}
#ifndef NDEBUG
else {
foreach(ScoreElement* eee, *_links) {
Element* ee = static_cast<Element*>(eee);
if (ee->type() != type()) {
qFatal("link %s(%d) type mismatch %s linked to %s",
ee->name(), id, ee->name(), name());
}
}
}
#endif
Q_ASSERT(!_links->contains(this));
_links->append(this);
}
else if (tag == "tick") {
int val = e.readInt();
// certain elements should not be allowed to reset tick
// these include any elements that occur within context of a Chord in a 1.X score
if (val >= 0) {
// if tick is valid, we should honor it
// but there are certain cases where we cannot
// - in 1.X scores, copy & paste of gliss resulted in invalid tick value on the new copy (#21211)
// the tick is not needed for glissandi anyhow, so we can ignore it
// - another bug allowed text items attached to notes or chords to also have invalid tick values (#25616)
// the text might be of any type, but we are now converting any text elements within notes into FINGERING
// - another bug allowed copy & paste of symbols attached to notes to produce invalid tick values (#56146)
// we can't ignore tick for all symbols, because it is needed for correct positioning of symbols attached to measures
// and it also can be relied upon by subsequent elements (http://musescore.org/en/node/25572)
// so honor tick only for elements attached to measures
// symbols attached to notes or other elements don't need the tick anyhow
if (score()->mscVersion() <= 114 && type() == Element::Type::SYMBOL) {
if (!parent() || parent()->type() != Element::Type::MEASURE)
val = -1;
}
if (score()->mscVersion() > 114 || (type() != Element::Type::GLISSANDO && type() != Element::Type::FINGERING && val >= 0))
e.initTick(score()->fileDivision(val));
}
}
else if (tag == "offset") {
setUserOff(e.readPoint() * spatium());
}
else if (tag == "pos") {
QPointF pt = e.readPoint();
if (score()->mscVersion() > 114)
_readPos = pt * score()->spatium();
}
else if (tag == "voice")
setTrack((_track/VOICES)*VOICES + e.readInt());
else if (tag == "tag") {
QString val(e.readElementText());
for (int i = 1; i < MAX_TAGS; i++) {
if (score()->layerTags()[i] == val) {
_tag = 1 << i;
break;
}
}
}
else if (tag == "placement")
_placement = Placement(Ms::getProperty(P_ID::PLACEMENT, e).toInt());
else
return false;
return true;
}
//---------------------------------------------------------
// write
//---------------------------------------------------------
void Element::write(Xml& xml) const
{
xml.stag(name());
writeProperties(xml);
xml.etag();
}
//---------------------------------------------------------
// read
//---------------------------------------------------------
void Element::read(XmlReader& e)
{
while (e.readNextStartElement()) {
if (!readProperties(e))
e.unknown();
}
}
//---------------------------------------------------------
// startEdit
//---------------------------------------------------------
void Element::startEdit(MuseScoreView*, const QPointF&)
{
undoPushProperty(P_ID::USER_OFF);
}
//---------------------------------------------------------
// remove
/// Remove \a el from the list. Return true on success.
//---------------------------------------------------------
bool ElementList::remove(Element* el)
{
auto i = find(begin(), end(), el);
if (i == end())
return false;
erase(i);
return true;
}
//---------------------------------------------------------
// replace
//---------------------------------------------------------
void ElementList::replace(Element* o, Element* n)
{
auto i = find(begin(), end(), o);
if (i == end()) {
qDebug("ElementList::replace: element not found");
return;
}
*i = n;
}
//---------------------------------------------------------
// write
//---------------------------------------------------------
void ElementList::write(Xml& xml) const
{
for (const Element* e : *this)
e->write(xml);
}
//---------------------------------------------------------
// StaffLines
//---------------------------------------------------------
StaffLines::StaffLines(Score* s)
: Element(s)
{
setWidth(1.0); // dummy
lines = 5;
setSelectable(false);
}
//---------------------------------------------------------
// pagePos
//---------------------------------------------------------
QPointF StaffLines::pagePos() const
{
System* system = measure()->system();
return QPointF(measure()->x() + system->x(),
system->staff(staffIdx())->y() + system->y());
}
//---------------------------------------------------------
// canvasPos
//---------------------------------------------------------
QPointF StaffLines::canvasPos() const
{
QPointF p(pagePos());
Element* e = parent();
while (e) {
if (e->type() == Element::Type::PAGE) {
p += e->pos();
break;
}
e = e->parent();
}
return p;
}
//---------------------------------------------------------
// layout
//---------------------------------------------------------
void StaffLines::layout()
{
StaffType* st = staff() ? staff()->staffType() : 0;
qreal _spatium = spatium();
if (st) {
dist = st->lineDistance().val() * _spatium;
lines = st->lines();
}
else {
dist = _spatium;
lines = 5;
}
// qDebug("StaffLines::layout:: dist %f st %p", dist, st);
setColor(staff() ? staff()->color() : MScore::defaultColor);
lw = score()->styleS(StyleIdx::staffLineWidth).val() * _spatium;
bbox().setRect(0.0, -lw*.5, width(), lines * dist + lw);
}
//---------------------------------------------------------
// draw
//---------------------------------------------------------
void StaffLines::draw(QPainter* painter) const
{
QPointF _pos(0.0, 0.0);
qreal x1 = _pos.x();
qreal x2 = x1 + width();
QVector<QLineF> ll(lines);
qreal y = _pos.y();
for (int i = 0; i < lines; ++i) {
ll[i].setLine(x1, y, x2, y);
y += dist;
}
if (MScore::debugMode) {
painter->setPen(QPen(Qt::lightGray, lw, Qt::SolidLine, Qt::FlatCap));
y = _pos.y() - 3 * dist;
painter->drawLine(QLineF(x1, y, x2, y));
y = _pos.y() - 2 * dist;
painter->drawLine(QLineF(x1, y, x2, y));
y = _pos.y() - dist;
painter->drawLine(QLineF(x1, y, x2, y));
y = _pos.y() + lines * dist;
painter->drawLine(QLineF(x1, y, x2, y));
y = _pos.y() + (lines+1) * dist;
painter->drawLine(QLineF(x1, y, x2, y));
y = _pos.y() + (lines+2) * dist;
painter->drawLine(QLineF(x1, y, x2, y));
y = _pos.y() + (lines+3) * dist;
painter->drawLine(QLineF(x1, y, x2, y));
y = _pos.y() + (lines+4) * dist;
painter->drawLine(QLineF(x1, y, x2, y));
}
painter->setPen(QPen(curColor(), lw, Qt::SolidLine, Qt::FlatCap));
painter->drawLines(ll);
}
//---------------------------------------------------------
// y1
//---------------------------------------------------------
qreal StaffLines::y1() const
{
System* system = measure()->system();
if (system == 0 || staffIdx() >= system->staves()->size())
return 0.0;
return system->staff(staffIdx())->y() + ipos().y();
}
//---------------------------------------------------------
// Line
//---------------------------------------------------------
Line::Line(Score* s, bool v)
: Element(s)
{
vertical = v;
_z = int(Element::Type::LINE) * 100;
}
//---------------------------------------------------------
// dump
//---------------------------------------------------------
void Line::dump() const
{
qDebug(" width:%g height:%g vert:%d", point(_width), point(_len), vertical);
}
//---------------------------------------------------------
// setLen
//---------------------------------------------------------
void Line::setLen(Spatium l)
{
_len = l;
}
//---------------------------------------------------------
// setLineWidth
//---------------------------------------------------------
void Line::setLineWidth(Spatium w)
{
_width = w;
}
//---------------------------------------------------------
// layout
//---------------------------------------------------------
void Line::layout()
{
qreal sp = spatium();
qreal w = _width.val() * sp;
qreal l = _len.val() * sp;
qreal w2 = w * .5;
if (vertical)
bbox().setRect(-w2, -w2, w, l + w);
else
bbox().setRect(-w2, -w2, l + w, w);
}
//---------------------------------------------------------
// draw
//---------------------------------------------------------
void Line::draw(QPainter* painter) const
{
qreal sp = spatium();
painter->setPen(QPen(curColor(), _width.val() * sp));
qreal l = _len.val() * sp;
if (vertical)
painter->drawLine(QLineF(0.0, 0.0, 0.0, l));
else
painter->drawLine(QLineF(0.0, 0.0, l, 0.0));
}
//---------------------------------------------------------
// writeProperties
//---------------------------------------------------------
void Line::writeProperties(Xml& xml) const
{
xml.tag("lineWidth", _width.val());
xml.tag("lineLen", _len.val());
if (!vertical)
xml.tag("vertical", vertical);
}
//---------------------------------------------------------
// readProperties
//---------------------------------------------------------
bool Line::readProperties(XmlReader& e)
{
const QStringRef& tag(e.name());
if (tag == "lineWidth")
_width = Spatium(e.readDouble());
else if (tag == "lineLen")
_len = Spatium(e.readDouble());
else if (tag == "vertical")
vertical = e.readInt();
else
return false;
return true;
}
//---------------------------------------------------------
// Compound
//---------------------------------------------------------
Compound::Compound(Score* s)
: Element(s)
{
}
Compound::Compound(const Compound& c)
: Element(c)
{
elements.clear();
foreach(Element* e, c.elements)
elements.append(e->clone());
}
//---------------------------------------------------------
// draw
//---------------------------------------------------------
void Compound::draw(QPainter* painter) const
{
foreach(Element* e, elements) {
QPointF pt(e->pos());
painter->translate(pt);
e->draw(painter);
painter->translate(-pt);
}
}
//---------------------------------------------------------
// addElement
//---------------------------------------------------------
/**
offset \a x and \a y are in Point units
*/
void Compound::addElement(Element* e, qreal x, qreal y)
{
e->setPos(x, y);
e->setParent(this);
elements.push_back(e);
}
//---------------------------------------------------------
// layout
//---------------------------------------------------------
void Compound::layout()
{
setbbox(QRectF());
for (auto i = elements.begin(); i != elements.end(); ++i) {
Element* e = *i;
e->layout();
addbbox(e->bbox().translated(e->pos()));
}
}
//---------------------------------------------------------
// setSelected
//---------------------------------------------------------
void Compound::setSelected(bool f)
{
Element::setSelected(f);
for (auto i = elements.begin(); i != elements.end(); ++i)
(*i)->setSelected(f);
}
//---------------------------------------------------------
// setVisible
//---------------------------------------------------------
void Compound::setVisible(bool f)
{
Element::setVisible(f);
for (auto i = elements.begin(); i != elements.end(); ++i)
(*i)->setVisible(f);
}
//---------------------------------------------------------
// clear
//---------------------------------------------------------
void Compound::clear()
{
foreach(Element* e, elements) {
if (e->selected())
score()->deselect(e);
delete e;
}
elements.clear();
}
//---------------------------------------------------------
// dump
//---------------------------------------------------------
void Element::dump() const
{
qDebug("---Element: %s, pos(%4.2f,%4.2f)"
"\n bbox(%g,%g,%g,%g)"
"\n abox(%g,%g,%g,%g)"
"\n parent: %p",
name(), ipos().x(), ipos().y(),
_bbox.x(), _bbox.y(), _bbox.width(), _bbox.height(),
abbox().x(), abbox().y(), abbox().width(), abbox().height(),
parent());
}
//---------------------------------------------------------
// mimeData
//---------------------------------------------------------
QByteArray Element::mimeData(const QPointF& dragOffset) const
{
QBuffer buffer;
buffer.open(QIODevice::WriteOnly);
Xml xml(&buffer);
xml.clipboardmode = true;
xml.stag("Element");
if (type() == Element::Type::NOTE)
xml.fTag("duration", static_cast<const Note*>(this)->chord()->duration());
if (!dragOffset.isNull())
xml.tag("dragOffset", dragOffset);
write(xml);
xml.etag();
buffer.close();
return buffer.buffer();
}
//---------------------------------------------------------
// readType
// return new position of QDomElement in e
//---------------------------------------------------------
Element::Type Element::readType(XmlReader& e, QPointF* dragOffset,
Fraction* duration)
{
while (e.readNextStartElement()) {
if (e.name() == "Element")
while (e.readNextStartElement()) {
const QStringRef& tag = e.name();
if (tag == "dragOffset")
*dragOffset = e.readPoint();
else if (tag == "duration")
*duration = e.readFraction();
else {
Element::Type type = name2type(tag);
if (type == Element::Type::INVALID)
break;
return type;
}
}
else
e.unknown();
}
return Element::Type::INVALID;
}
//---------------------------------------------------------
// editDrag
//---------------------------------------------------------
void Element::editDrag(const EditData& ed)
{
score()->addRefresh(canvasBoundingRect());
setUserOff(userOff() + ed.delta);
score()->addRefresh(canvasBoundingRect());
}
//---------------------------------------------------------
// edit
// return true if event is accepted
//---------------------------------------------------------
bool Element::edit(MuseScoreView*, Grip, int key, Qt::KeyboardModifiers, const QString&)
{
if (key == Qt::Key_Home) {
setUserOff(QPoint());
return true;
}
return false;
}
//---------------------------------------------------------
// add
//---------------------------------------------------------
void Element::add(Element* e)
{
qDebug("Element: cannot add %s to %s", e->name(), name());
}
//---------------------------------------------------------
// remove
//---------------------------------------------------------
void Element::remove(Element* e)
{
qFatal("Element: cannot remove %s from %s", e->name(), name());
}
//---------------------------------------------------------
// create
// Element factory
//---------------------------------------------------------
Element* Element::create(Element::Type type, Score* score)
{
switch(type) {
case Element::Type::VOLTA: return new Volta(score);
case Element::Type::OTTAVA: return new Ottava(score);
case Element::Type::TEXTLINE: return new TextLine(score);
case Element::Type::NOTELINE: return new NoteLine(score);
case Element::Type::LYRICSLINE: return new LyricsLine(score);
case Element::Type::TRILL: return new Trill(score);
case Element::Type::PEDAL: return new Pedal(score);
case Element::Type::HAIRPIN: return new Hairpin(score);
case Element::Type::CLEF: return new Clef(score);
case Element::Type::KEYSIG: return new KeySig(score);
case Element::Type::TIMESIG: return new TimeSig(score);
case Element::Type::BAR_LINE: return new BarLine(score);
case Element::Type::ARPEGGIO: return new Arpeggio(score);
case Element::Type::BREATH: return new Breath(score);
case Element::Type::GLISSANDO: return new Glissando(score);
case Element::Type::BRACKET: return new Bracket(score);
case Element::Type::ARTICULATION: return new Articulation(score);
case Element::Type::CHORDLINE: return new ChordLine(score);
case Element::Type::ACCIDENTAL: return new Accidental(score);
case Element::Type::DYNAMIC: return new Dynamic(score);
case Element::Type::TEXT: return new Text(score);
case Element::Type::INSTRUMENT_NAME: return new InstrumentName(score);
case Element::Type::STAFF_TEXT: return new StaffText(score);
case Element::Type::REHEARSAL_MARK: return new RehearsalMark(score);
case Element::Type::INSTRUMENT_CHANGE: return new InstrumentChange(score);
case Element::Type::NOTEHEAD: return new NoteHead(score);
case Element::Type::NOTEDOT: return new NoteDot(score);
case Element::Type::TREMOLO: return new Tremolo(score);
case Element::Type::LAYOUT_BREAK: return new LayoutBreak(score);
case Element::Type::MARKER: return new Marker(score);
case Element::Type::JUMP: return new Jump(score);
case Element::Type::REPEAT_MEASURE: return new RepeatMeasure(score);
case Element::Type::ICON: return new Icon(score);
case Element::Type::NOTE: return new Note(score);
case Element::Type::SYMBOL: return new Symbol(score);
case Element::Type::FSYMBOL: return new FSymbol(score);
case Element::Type::CHORD: return new Chord(score);
case Element::Type::REST: return new Rest(score);
case Element::Type::SPACER: return new Spacer(score);
case Element::Type::STAFF_STATE: return new StaffState(score);
case Element::Type::TEMPO_TEXT: return new TempoText(score);
case Element::Type::HARMONY: return new Harmony(score);
case Element::Type::FRET_DIAGRAM: return new FretDiagram(score);
case Element::Type::BEND: return new Bend(score);
case Element::Type::TREMOLOBAR: return new TremoloBar(score);
case Element::Type::LYRICS: return new Lyrics(score);
case Element::Type::FIGURED_BASS: return new FiguredBass(score);
case Element::Type::STEM: return new Stem(score);
case Element::Type::SLUR: return new Slur(score);
case Element::Type::FINGERING: return new Fingering(score);
case Element::Type::HBOX: return new HBox(score);
case Element::Type::VBOX: return new VBox(score);
case Element::Type::TBOX: return new TBox(score);
case Element::Type::FBOX: return new FBox(score);
case Element::Type::MEASURE: return new Measure(score);
case Element::Type::TAB_DURATION_SYMBOL: return new TabDurationSymbol(score);
case Element::Type::OSSIA: return new Ossia(score);
case Element::Type::IMAGE: return new Image(score);
case Element::Type::BAGPIPE_EMBELLISHMENT: return new BagpipeEmbellishment(score);
case Element::Type::AMBITUS: return new Ambitus(score);
case Element::Type::TEXTLINE_SEGMENT: // return new TextLineSegment(score);
case Element::Type::GLISSANDO_SEGMENT:
case Element::Type::SLUR_SEGMENT:
case Element::Type::STEM_SLASH:
case Element::Type::LINE:
case Element::Type::TIE:
case Element::Type::PAGE:
case Element::Type::BEAM:
case Element::Type::HOOK:
case Element::Type::TUPLET:
case Element::Type::HAIRPIN_SEGMENT:
case Element::Type::OTTAVA_SEGMENT:
case Element::Type::TRILL_SEGMENT:
case Element::Type::VOLTA_SEGMENT:
case Element::Type::PEDAL_SEGMENT:
case Element::Type::LYRICSLINE_SEGMENT:
case Element::Type::LEDGER_LINE:
case Element::Type::STAFF_LINES:
case Element::Type::SELECTION:
case Element::Type::LASSO:
case Element::Type::SHADOW_NOTE:
case Element::Type::SEGMENT:
case Element::Type::SYSTEM:
case Element::Type::COMPOUND:
case Element::Type::ELEMENT:
case Element::Type::ELEMENT_LIST:
case Element::Type::STAFF_LIST:
case Element::Type::MEASURE_LIST:
case Element::Type::MAXTYPE:
case Element::Type::INVALID: break;
}
qDebug("cannot create type %d <%s>", int(type), Element::name(type));
return 0;
}
//---------------------------------------------------------
// name
//---------------------------------------------------------
const char* Element::name(Element::Type type)
{
return elementNames[int(type)].name;
}
//---------------------------------------------------------
// name2type
//---------------------------------------------------------
Element::Type Element::name2type(const QStringRef& s)
{
for (int i = 0; i < int(Element::Type::MAXTYPE); ++i) {
if (s == elementNames[i].name)
return Element::Type(i);
}
qDebug("name2type: invalid type <%s>", s.toUtf8().data());
return Element::Type::INVALID;
}
//---------------------------------------------------------
// name2Element
//---------------------------------------------------------
Element* Element::name2Element(const QStringRef& s, Score* sc)
{
Element::Type type = Element::name2type(s);
if (type == Element::Type::INVALID)
return 0;
return Element::create(type, sc);
}
//---------------------------------------------------------
// elementLessThan
//---------------------------------------------------------
bool elementLessThan(const Element* const e1, const Element* const e2)
{
return e1->z() <= e2->z();
}
//---------------------------------------------------------
// getGrip
//---------------------------------------------------------
QPointF Element::getGrip(Grip) const
{
qreal _spatium = score()->spatium();
return QPointF(userOff().x() / _spatium, userOff().y() / _spatium);
}
//---------------------------------------------------------
// setGrip
//---------------------------------------------------------
void Element::setGrip(Grip, const QPointF& pt)
{
qreal _spatium = score()->spatium();
setUserOff(QPointF(pt.x() * _spatium, pt.y() * _spatium));
}
//---------------------------------------------------------
// collectElements
//---------------------------------------------------------
void collectElements(void* data, Element* e)
{
QList<Element*>* el = static_cast<QList<Element*>*>(data);
el->append(e);
}
//---------------------------------------------------------
// undoSetPlacement
//---------------------------------------------------------
void Element::undoSetPlacement(Placement v)
{
score()->undoChangeProperty(this, P_ID::PLACEMENT, int(v));
}
//---------------------------------------------------------
// getProperty
//---------------------------------------------------------
QVariant Element::getProperty(P_ID propertyId) const
{
switch (propertyId) {
case P_ID::TRACK: return track();
case P_ID::GENERATED: return _generated;
case P_ID::COLOR: return color();
case P_ID::VISIBLE: return _visible;
case P_ID::SELECTED: return _selected;
case P_ID::USER_OFF: return _userOff;
case P_ID::PLACEMENT: return int(_placement);
default:
return QVariant();
}
}
//---------------------------------------------------------
// setProperty
//---------------------------------------------------------
bool Element::setProperty(P_ID propertyId, const QVariant& v)
{
switch (propertyId) {
case P_ID::TRACK:
setTrack(v.toInt());
break;
case P_ID::GENERATED:
_generated = v.toBool();
break;
case P_ID::COLOR:
setColor(v.value<QColor>());
break;
case P_ID::VISIBLE:
setVisible(v.toBool());
break;
case P_ID::SELECTED:
setSelected(v.toBool());
break;
case P_ID::USER_OFF:
score()->addRefresh(canvasBoundingRect());
_userOff = v.toPointF();
break;
case P_ID::PLACEMENT:
_placement = Placement(v.toInt());
break;
default:
qFatal("Element::setProperty: unknown <%s>(%hhd), data <%s>",
propertyName(propertyId), propertyId, qPrintable(v.toString()));
return false;
}
setGenerated(false);
score()->addRefresh(canvasBoundingRect());
return true;
}
//---------------------------------------------------------
// propertyDefault
//---------------------------------------------------------
QVariant Element::propertyDefault(P_ID id) const
{
switch(id) {
case P_ID::GENERATED:
return false;
case P_ID::VISIBLE:
return true;
case P_ID::COLOR:
return MScore::defaultColor;
case P_ID::PLACEMENT:
return int(Placement::BELOW);
case P_ID::SELECTED:
return false;
case P_ID::USER_OFF:
return QPointF();
default: // not all properties have a default
break;
}
return QVariant();
}
//---------------------------------------------------------
// isSLine
//---------------------------------------------------------
bool Element::isSLine() const
{
return type() == Element::Type::HAIRPIN || type() == Element::Type::OTTAVA || type() == Element::Type::PEDAL
|| type() == Element::Type::TRILL || type() == Element::Type::VOLTA || type() == Element::Type::TEXTLINE || type() == Element::Type::NOTELINE || type() == Element::Type::GLISSANDO;
}
//---------------------------------------------------------
// isSLine
//---------------------------------------------------------
bool Element::isSLineSegment() const
{
return type() == Element::Type::HAIRPIN_SEGMENT || type() == Element::Type::OTTAVA_SEGMENT || type() == Element::Type::PEDAL_SEGMENT || type() == Element::Type::TRILL_SEGMENT || type() == Element::Type::VOLTA_SEGMENT || type() == Element::Type::TEXTLINE_SEGMENT || type() == Element::Type::GLISSANDO_SEGMENT;
}
//---------------------------------------------------------
// isText
//---------------------------------------------------------
bool Element::isText() const
{
return type() == Element::Type::TEXT
|| type() == Element::Type::LYRICS
|| type() == Element::Type::DYNAMIC
|| type() == Element::Type::FINGERING
|| type() == Element::Type::HARMONY
|| type() == Element::Type::MARKER
|| type() == Element::Type::JUMP
|| type() == Element::Type::STAFF_TEXT
|| type() == Element::Type::REHEARSAL_MARK
|| type() == Element::Type::INSTRUMENT_CHANGE
|| type() == Element::Type::FIGURED_BASS
|| type() == Element::Type::TEMPO_TEXT
|| type() == Element::Type::INSTRUMENT_NAME
;
}
//---------------------------------------------------------
// isPrintable
//---------------------------------------------------------
bool Element::isPrintable() const
{
switch (type()) {
case Element::Type::PAGE:
case Element::Type::SYSTEM:
case Element::Type::MEASURE:
case Element::Type::SEGMENT:
case Element::Type::VBOX:
case Element::Type::HBOX:
case Element::Type::TBOX:
case Element::Type::FBOX:
case Element::Type::SPACER:
case Element::Type::SHADOW_NOTE:
case Element::Type::LASSO:
case Element::Type::ELEMENT_LIST:
case Element::Type::STAFF_LIST:
case Element::Type::MEASURE_LIST:
case Element::Type::SELECTION:
return false;
default:
return true;
}
}
//---------------------------------------------------------
// findMeasure
//---------------------------------------------------------
Element* Element::findMeasure()
{
if (type() == Element::Type::MEASURE)
return this;
else if (_parent)
return _parent->findMeasure();
else
return 0;
}
//---------------------------------------------------------
// undoSetColor
//---------------------------------------------------------
void Element::undoSetColor(const QColor& c)
{
score()->undoChangeProperty(this, P_ID::COLOR, c);
}
//---------------------------------------------------------
// undoSetVisible
//---------------------------------------------------------
void Element::undoSetVisible(bool v)
{
score()->undoChangeProperty(this, P_ID::VISIBLE, v);
}
//---------------------------------------------------------
// bbox() function for scripts
//
// use spatium units rather than raster units
//---------------------------------------------------------
QRectF Element::scriptBbox() const
{
qreal _sp = spatium();
QRectF _bbox = bbox();
return QRectF(_bbox.x() / _sp, _bbox.y() / _sp, _bbox.width() / _sp, _bbox.height() / _sp);
}
//---------------------------------------------------------
// positioning functions for scripts
//
// use spatium units rather than raster units
// are undoable
// route pos changes to usefOff
//---------------------------------------------------------
QPointF Element::scriptPagePos() const
{
return pagePos() / spatium();
}
QPointF Element::scriptPos() const
{
return (_pos + _userOff) / spatium();
}
void Element::scriptSetPos(const QPointF& p)
{
score()->undoChangeProperty(this, P_ID::USER_OFF, p*spatium() - ipos());
}
QPointF Element::scriptUserOff() const
{
return _userOff / spatium();
}
void Element::scriptSetUserOff(const QPointF& o)
{
score()->undoChangeProperty(this, P_ID::USER_OFF, o * spatium());
}
//void Element::draw(SymId id, QPainter* p) const { score()->scoreFont()->draw(id, p, magS()); }
//---------------------------------------------------------
// drawSymbol
//---------------------------------------------------------
void Element::drawSymbol(SymId id, QPainter* p, const QPointF& o) const
{
score()->scoreFont()->draw(id, p, magS(), o);
}
void Element::drawSymbol(SymId id, QPainter* p, const QPointF& o, int n) const
{
score()->scoreFont()->draw(id, p, magS(), o, n);
}
void Element::drawSymbols(const QList<SymId>& s, QPainter* p, const QPointF& o) const
{
score()->scoreFont()->draw(s, p, magS(), o);
}
//---------------------------------------------------------
// symHeight
//---------------------------------------------------------
qreal Element::symHeight(SymId id) const
{
return score()->scoreFont()->height(id, magS());
}
//---------------------------------------------------------
// symWidth
//---------------------------------------------------------
qreal Element::symWidth(SymId id) const
{
return score()->scoreFont()->width(id, magS());
}
qreal Element::symWidth(const QList<SymId>& s) const
{
return score()->scoreFont()->width(s, magS());
}
//---------------------------------------------------------
// symAdvance
//---------------------------------------------------------
qreal Element::symAdvance(SymId id) const
{
return score()->scoreFont()->advance(id, magS());
}
//---------------------------------------------------------
// symBbox
//---------------------------------------------------------
QRectF Element::symBbox(SymId id) const
{
return score()->scoreFont()->bbox(id, magS());
}
QRectF Element::symBbox(const QList<SymId>& s) const
{
return score()->scoreFont()->bbox(s, magS());
}
//---------------------------------------------------------
// symStemDownNW
//---------------------------------------------------------
QPointF Element::symStemDownNW(SymId id) const
{
return score()->scoreFont()->stemDownNW(id, magS());
}
//---------------------------------------------------------
// symStemUpSE
//---------------------------------------------------------
QPointF Element::symStemUpSE(SymId id) const
{
return score()->scoreFont()->stemUpSE(id, magS());
}
//---------------------------------------------------------
// symCutOutNE / symCutOutNW / symCutOutSE / symCutOutNW
//---------------------------------------------------------
QPointF Element::symCutOutNE(SymId id) const
{
return score()->scoreFont()->cutOutNE(id, magS());
}
QPointF Element::symCutOutNW(SymId id) const
{
return score()->scoreFont()->cutOutNW(id, magS());
}
QPointF Element::symCutOutSE(SymId id) const
{
return score()->scoreFont()->cutOutSE(id, magS());
}
QPointF Element::symCutOutSW(SymId id) const
{
return score()->scoreFont()->cutOutSW(id, magS());
}
//---------------------------------------------------------
// symIsValid
//---------------------------------------------------------
bool Element::symIsValid(SymId id) const
{
return score()->scoreFont()->isValid(id);
}
//---------------------------------------------------------
// toTimeSigString
//---------------------------------------------------------
QList<SymId> Element::toTimeSigString(const QString& s) const
{
QList<SymId> d;
for (int i = 0; i < s.size(); ++i) {
switch (s[i].unicode()) {
case 43: d += SymId::timeSigPlusSmall; break; // '+'
case 48: d += SymId::timeSig0; break; // '0'
case 49: d += SymId::timeSig1; break; // '1'
case 50: d += SymId::timeSig2; break; // '2'
case 51: d += SymId::timeSig3; break; // '3'
case 52: d += SymId::timeSig4; break; // '4'
case 53: d += SymId::timeSig5; break; // '5'
case 54: d += SymId::timeSig6; break; // '6'
case 55: d += SymId::timeSig7; break; // '7'
case 56: d += SymId::timeSig8; break; // '8'
case 57: d += SymId::timeSig9; break; // '9'
case 67: d += SymId::timeSigCommon; break; // 'C'
case 40: d += SymId::timeSigParensLeftSmall; break; // '('
case 41: d += SymId::timeSigParensRightSmall; break; // ')'
case 162: d += SymId::timeSigCutCommon; break; // '¢'
case 59664: d += SymId::mensuralProlation1; break;
case 79: // 'O'
case 59665: d += SymId::mensuralProlation2; break;
case 216: // 'Ø'
case 59666: d += SymId::mensuralProlation3; break;
case 59667: d += SymId::mensuralProlation4; break;
case 59668: d += SymId::mensuralProlation5; break;
case 59670: d += SymId::mensuralProlation7; break;
case 59671: d += SymId::mensuralProlation8; break;
case 59673: d += SymId::mensuralProlation10; break;
case 59674: d += SymId::mensuralProlation11; break;
default: break; // d += s[i]; break;
}
}
return d;
}
//---------------------------------------------------------
// concertPitch
//---------------------------------------------------------
bool Element::concertPitch() const
{
return score()->styleB(StyleIdx::concertPitch);
}
//------------------------------------------------------------------------------------------
// nextElement
// This function is used in for the next-element command to navigate between main elements
// of segments. (Note, Rest, Clef, Time Signature, Key Signature, Barline, Ambitus, Breath, etc.)
// The default implementation is to look for the first such element. After it is found each
// element knows how to find the next one and overrides this method
//------------------------------------------------------------------------------------------
Element* Element::nextElement()
{
Element* p = this;
while (p) {
switch (p->type()) {
case Element::Type::NOTE:
if(static_cast<Note*>(p)->chord()->isGrace())
break;
return p;
case Element::Type::REST:
return p;
case Element::Type::CHORD: {
Chord* c = static_cast<Chord*>(p);
if (!c->isGrace())
return c->notes().back();
}
break;
case Element::Type::SEGMENT: {
Segment* s = static_cast<Segment*>(p);
return s->firstElement(staffIdx());
}
case Element::Type::MEASURE: {
Measure* m = static_cast<Measure*>(p);
return m->nextElementStaff(staffIdx());
}
case Element::Type::SYSTEM: {
System* sys = static_cast<System*>(p);
return sys->nextElement();
}
default:
break;
}
p = p->parent();
}
return score()->firstElement();
}
//------------------------------------------------------------------------------------------
// prevElement
// This function is used in for the prev-element command to navigate between main elements
// of segments. (Note, Rest, Clef, Time Signature, Key Signature, Barline, Ambitus, Breath, etc.)
// The default implementation is to look for the first such element. After it is found each
// element knows how to find the previous one and overrides this method
//------------------------------------------------------------------------------------------
Element* Element::prevElement()
{
Element* p = this;
while (p) {
switch (p->type()) {
case Element::Type::NOTE:
if(static_cast<Note*>(p)->chord()->isGrace())
break;
return p;
case Element::Type::REST:
return p;
case Element::Type::CHORD: {
Chord* c = static_cast<Chord*>(p);
if (!c->isGrace())
return c->notes().first();
}
break;
case Element::Type::SEGMENT: {
Segment* s = static_cast<Segment*>(p);
return s->lastElement(staffIdx());
}
case Element::Type::MEASURE: {
Measure* m = static_cast<Measure*>(p);
return m->prevElementStaff(staffIdx());
}
case Element::Type::SYSTEM: {
System* sys = static_cast<System*>(p);
return sys->prevElement();
}
default:
break;
}
p = p->parent();
}
return score()->firstElement();
}
//---------------------------------------------------------
// accessibleInfo
//---------------------------------------------------------
QString Element::accessibleInfo()
{
return userName();
}
//---------------------------------------------------------
// nextGrip
//---------------------------------------------------------
bool Element::nextGrip(Grip* grip) const
{
int i = int(*grip) + 1;
if (i >= grips()) {
*grip = Grip(0);
return false;
}
*grip = Grip(i);
return true;
}
//---------------------------------------------------------
// prevGrip
//---------------------------------------------------------
bool Element::prevGrip(Grip* grip) const
{
int i = int(*grip) - 1;
if (i < 0) {
*grip = Grip(grips() - 1);
return false;
}
*grip = Grip(i);
return true;
}
//---------------------------------------------------------
// isUserModified
// Check if this element was modified by user and
// therefore must be saved.
//---------------------------------------------------------
bool Element::isUserModified() const
{
return !visible() || !userOff().isNull() || (color() != MScore::defaultColor);
}
}
|