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 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632
|
// -*- c-basic-offset: 4 -*-
/*
Rosegarden-4
A sequencer and musical notation editor.
This program is Copyright 2000-2005
Guillaume Laurent <glaurent@telegraph-road.org>,
Chris Cannam <cannam@all-day-breakfast.com>,
Richard Bown <bownie@bownie.com>
The moral right of the authors to claim authorship of this work
has been asserted.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version. See the file
COPYING included with this distribution for more information.
*/
#include <qstring.h>
#include <qregexp.h>
#include <qpaintdevicemetrics.h>
#include <qpixmap.h>
#include <qtimer.h>
#include <algorithm>
#include <kmessagebox.h>
#include <kstatusbar.h>
#include <klocale.h>
#include <kconfig.h>
#include <kstddirs.h>
#include <kglobal.h>
#include <kaction.h>
#include <kstdaction.h>
#include <kglobal.h>
#include <kapp.h>
#include <kprinter.h>
#include "NotationTypes.h"
#include "Quantizer.h"
#include "Selection.h"
#include "BaseProperties.h"
#include "Profiler.h"
#include "notationview.h"
#include "constants.h"
#include "colours.h"
#include "notationstrings.h"
#include "notepixmapfactory.h"
#include "notefont.h"
#include "notestyle.h"
#include "notationtool.h"
#include "notationstrings.h"
#include "barbuttons.h"
#include "loopruler.h"
#include "rosedebug.h"
#include "editcommands.h"
#include "notationcommands.h"
#include "segmentcommands.h"
#include "widgets.h"
#include "chordnameruler.h"
#include "temporuler.h"
#include "rawnoteruler.h"
#include "studiocontrol.h"
#include "notationhlayout.h"
#include "notationvlayout.h"
#include "ktmpstatusmsg.h"
#include "scrollbox.h"
#include "rosegardenguiview.h"
#include "trackeditor.h"
#include "trackbuttons.h"
//#include "tempoview.h"
//!!! TESTING:
#include "qcanvassimplesprite.h"
#include <qpixmap.h>
#include <qfont.h>
#include <qfontmetrics.h>
#include <qpainter.h>
using Rosegarden::Event;
using Rosegarden::Note;
using Rosegarden::Segment;
using Rosegarden::EventSelection;
using Rosegarden::Quantizer;
using Rosegarden::timeT;
using Rosegarden::Mark;
using namespace Rosegarden::Marks;
class NoteActionData
{
public:
NoteActionData();
NoteActionData(const QString& _title,
QString _actionName,
QString _pixmapName,
int _keycode,
bool _rest,
Note::Type _noteType,
int _dots);
QString title;
QString actionName;
QString pixmapName;
int keycode;
bool rest;
Note::Type noteType;
int dots;
};
NoteActionData::NoteActionData()
: title(0),
actionName(0),
pixmapName(0),
keycode(0),
rest(false),
noteType(0),
dots(0)
{
}
NoteActionData::NoteActionData(const QString& _title,
QString _actionName,
QString _pixmapName,
int _keycode,
bool _rest,
Note::Type _noteType,
int _dots)
: title(_title),
actionName(_actionName),
pixmapName(_pixmapName),
keycode(_keycode),
rest(_rest),
noteType(_noteType),
dots(_dots)
{
}
class NoteChangeActionData
{
public:
NoteChangeActionData();
NoteChangeActionData(const QString &_title,
QString _actionName,
QString _pixmapName,
int _keycode,
bool _notationOnly,
Note::Type _noteType);
QString title;
QString actionName;
QString pixmapName;
int keycode;
bool notationOnly;
Note::Type noteType;
};
NoteChangeActionData::NoteChangeActionData()
: title(0),
actionName(0),
pixmapName(0),
keycode(0),
notationOnly(false),
noteType(0)
{
}
NoteChangeActionData::NoteChangeActionData(const QString& _title,
QString _actionName,
QString _pixmapName,
int _keycode,
bool _notationOnly,
Note::Type _noteType)
: title(_title),
actionName(_actionName),
pixmapName(_pixmapName),
keycode(_keycode),
notationOnly(_notationOnly),
noteType(_noteType)
{
}
class MarkActionData
{
public:
MarkActionData() :
title(0),
actionName(0),
keycode(0) { }
MarkActionData(const QString &_title,
QString _actionName,
int _keycode,
Mark _mark) :
title(_title),
actionName(_actionName),
keycode(_keycode),
mark(_mark) { }
QString title;
QString actionName;
int keycode;
Mark mark;
};
//////////////////////////////////////////////////////////////////////
NotationView::NotationView(RosegardenGUIDoc *doc,
std::vector<Segment *> segments,
QWidget *parent,
bool showProgressive) :
EditView(doc, segments, 1, parent, "notationview"),
m_properties(getViewLocalPropertyPrefix()),
m_selectionCounter(0),
m_insertModeLabel(0),
m_annotationsLabel(0),
m_progressBar(0),
m_currentNotePixmap(0),
m_hoveredOverNoteName(0),
m_hoveredOverAbsoluteTime(0),
m_currentStaff(-1),
m_lastFinishingStaff(-1),
m_title(0),
m_subtitle(0),
m_composer(0),
m_copyright(0),
m_insertionTime(0),
m_deferredCursorMove(NoCursorMoveNeeded),
m_lastNoteAction("crotchet"),
m_fontName(NoteFontFactory::getDefaultFontName()),
m_fontSize(NoteFontFactory::getDefaultSize(m_fontName)),
m_pageMode(LinedStaff::LinearMode),
m_leftGutter(20),
m_notePixmapFactory(new NotePixmapFactory(m_fontName, m_fontSize)),
m_hlayout(new NotationHLayout(&doc->getComposition(), m_notePixmapFactory,
m_properties, this)),
m_vlayout(new NotationVLayout(&doc->getComposition(), m_notePixmapFactory,
m_properties, this)),
m_chordNameRuler(0),
m_tempoRuler(0),
m_rawNoteRuler(0),
m_annotationsVisible(false),
m_selectDefaultNote(0),
m_fontCombo(0),
m_fontSizeCombo(0),
m_spacingCombo(0),
m_fontSizeActionMenu(0),
m_pannerDialog(new ScrollBoxDialog(this, ScrollBox::FixHeight)),
m_renderTimer(0),
m_playTracking(true),
m_progressDisplayer(PROGRESS_NONE),
m_inhibitRefresh(true),
m_ok(false),
m_printMode(false),
m_printSize(8) // set in positionStaffs
{
initActionDataMaps(); // does something only the 1st time it's called
m_toolBox = new NotationToolBox(this);
assert(segments.size() > 0);
NOTATION_DEBUG << "NotationView ctor" << endl;
// Initialise the display-related defaults that will be needed
// by both the actions and the layout toolbar
m_config->setGroup(NotationView::ConfigGroup);
m_fontName = qstrtostr(m_config->readEntry
("notefont",
strtoqstr(NoteFontFactory::getDefaultFontName())));
try {
(void)NoteFontFactory::getFont
(m_fontName,
NoteFontFactory::getDefaultSize(m_fontName));
} catch (Rosegarden::Exception e) {
m_fontName = NoteFontFactory::getDefaultFontName();
}
m_fontSize = m_config->readUnsignedNumEntry
((segments.size() > 1 ? "multistaffnotesize" : "singlestaffnotesize"),
NoteFontFactory::getDefaultSize(m_fontName));
int defaultSpacing = m_config->readNumEntry("spacing", 100);
m_hlayout->setSpacing(defaultSpacing);
int defaultProportion = m_config->readNumEntry("proportion", 60);
m_hlayout->setProportion(defaultProportion);
delete m_notePixmapFactory;
m_notePixmapFactory = new NotePixmapFactory(m_fontName, m_fontSize);
m_hlayout->setNotePixmapFactory(m_notePixmapFactory);
m_vlayout->setNotePixmapFactory(m_notePixmapFactory);
setupActions();
// setupAddControlRulerMenu(); - too early for notation, moved to end of ctor.
initLayoutToolbar();
initStatusBar();
setBackgroundMode(PaletteBase);
QCanvas *tCanvas = new QCanvas(this);
tCanvas->resize(width() * 2, height() * 2);
setCanvasView(new NotationCanvasView(*this, tCanvas, getCentralWidget()));
updateViewCaption();
setTopBarButtons(new BarButtons(getDocument(),
m_hlayout, m_leftGutter, 25,
false, getCentralWidget()));
m_topBarButtons->getLoopRuler()->setBackgroundColor
(Rosegarden::GUIPalette::getColour(Rosegarden::GUIPalette::InsertCursorRuler));
m_chordNameRuler = new ChordNameRuler
(m_hlayout, doc, segments, m_leftGutter, 20, getCentralWidget());
addRuler(m_chordNameRuler);
if (showProgressive) m_chordNameRuler->show();
m_tempoRuler = new TempoRuler
(m_hlayout, doc, m_leftGutter, 20, false, getCentralWidget());
addRuler(m_tempoRuler);
m_tempoRuler->hide();
// make tempo ruler double click editable
connect(m_tempoRuler,
SIGNAL(doubleClicked(Rosegarden::timeT)),
SLOT(slotEditTempos(Rosegarden::timeT)));
m_rawNoteRuler = new RawNoteRuler
(m_hlayout, segments[0], m_leftGutter, 20, getCentralWidget());
addRuler(m_rawNoteRuler);
m_rawNoteRuler->show();
// All toolbars should be created before this is called
setAutoSaveSettings("NotationView", true);
// All rulers must have been created before this is called,
// or the program will crash
readOptions();
setBottomBarButtons(new BarButtons(getDocument(), m_hlayout, m_leftGutter, 25,
true, getBottomWidget()));
for (unsigned int i = 0; i < segments.size(); ++i) {
m_staffs.push_back(new NotationStaff
(canvas(), segments[i], 0, // snap
i, this,
m_fontName, m_fontSize));
}
//
// layout
//
RosegardenProgressDialog* progressDlg = 0;
if (showProgressive) {
show();
RosegardenProgressDialog::processEvents();
NOTATION_DEBUG << "NotationView : setting up progress dialog" << endl;
progressDlg = new RosegardenProgressDialog(i18n("Starting..."),
100, this);
progressDlg->setAutoClose(false);
progressDlg->setAutoReset(true);
progressDlg->setMinimumDuration(1000);
setupProgress(progressDlg);
m_progressDisplayer = PROGRESS_DIALOG;
}
m_chordNameRuler->setStudio(&getDocument()->getStudio());
m_currentStaff = 0;
m_staffs[0]->setCurrent(true);
m_config->setGroup(NotationView::ConfigGroup);
int layoutMode = m_config->readNumEntry("layoutmode", 0);
try {
LinedStaff::PageMode mode = LinedStaff::LinearMode;
if (layoutMode == 1) mode = LinedStaff::ContinuousPageMode;
else if (layoutMode == 2) mode = LinedStaff::MultiPageMode;
setPageMode(mode);
for (unsigned int i = 0; i < m_staffs.size(); ++i) {
m_staffs[i]->getSegment().getRefreshStatus
(m_segmentsRefreshStatusIds[i]).setNeedsRefresh(false);
}
m_ok = true;
} catch (ProgressReporter::Cancelled c) {
// when cancelled, m_ok is false -- checked by calling method
NOTATION_DEBUG << "NotationView ctor : layout Cancelled" << endl;
}
NOTATION_DEBUG << "NotationView ctor : m_ok = " << m_ok << endl;
delete progressDlg;
// at this point we can return if operation was cancelled
if (!isOK()) { setOutOfCtor(); return; }
// otherwise, carry on
setupDefaultProgress();
//
// Connect signals
//
QObject::connect
(getCanvasView(), SIGNAL(renderRequired(double, double)),
this, SLOT(slotCheckRendered(double, double)));
QObject::connect
(m_topBarButtons->getLoopRuler(),
SIGNAL(setPointerPosition(Rosegarden::timeT)),
this, SLOT(slotSetInsertCursorPosition(Rosegarden::timeT)));
m_bottomBarButtons->connectRulerToDocPointer(doc);
QObject::connect
(getCanvasView(), SIGNAL(itemPressed(int, int, QMouseEvent*, NotationElement*)),
this, SLOT (slotItemPressed(int, int, QMouseEvent*, NotationElement*)));
QObject::connect
(getCanvasView(), SIGNAL(activeItemPressed(QMouseEvent*, QCanvasItem*)),
this, SLOT (slotActiveItemPressed(QMouseEvent*, QCanvasItem*)));
QObject::connect
(getCanvasView(), SIGNAL(nonNotationItemPressed(QMouseEvent*, QCanvasItem*)),
this, SLOT (slotNonNotationItemPressed(QMouseEvent*, QCanvasItem*)));
QObject::connect
(getCanvasView(), SIGNAL(textItemPressed(QMouseEvent*, QCanvasItem*)),
this, SLOT (slotTextItemPressed(QMouseEvent*, QCanvasItem*)));
QObject::connect
(getCanvasView(), SIGNAL(mouseMoved(QMouseEvent*)),
this, SLOT (slotMouseMoved(QMouseEvent*)));
QObject::connect
(getCanvasView(), SIGNAL(mouseReleased(QMouseEvent*)),
this, SLOT (slotMouseReleased(QMouseEvent*)));
QObject::connect
(getCanvasView(), SIGNAL(hoveredOverNoteChanged(const QString&)),
this, SLOT (slotHoveredOverNoteChanged(const QString&)));
QObject::connect
(getCanvasView(), SIGNAL(hoveredOverAbsoluteTimeChanged(unsigned int)),
this, SLOT (slotHoveredOverAbsoluteTimeChanged(unsigned int)));
QObject::connect
(m_pannerDialog->scrollbox(), SIGNAL(valueChanged(const QPoint &)),
getCanvasView(), SLOT(slotSetScrollPos(const QPoint &)));
QObject::connect
(getCanvasView()->horizontalScrollBar(), SIGNAL(valueChanged(int)),
m_pannerDialog->scrollbox(), SLOT(setViewX(int)));
QObject::connect
(getCanvasView()->verticalScrollBar(), SIGNAL(valueChanged(int)),
m_pannerDialog->scrollbox(), SLOT(setViewY(int)));
QObject::connect
(doc, SIGNAL(pointerPositionChanged(Rosegarden::timeT)),
this, SLOT(slotSetPointerPosition(Rosegarden::timeT)));
stateChanged("have_selection", KXMLGUIClient::StateReverse);
stateChanged("have_notes_in_selection", KXMLGUIClient::StateReverse);
stateChanged("have_rests_in_selection", KXMLGUIClient::StateReverse);
stateChanged("have_multiple_staffs",
(m_staffs.size() > 1 ? KXMLGUIClient::StateNoReverse :
KXMLGUIClient::StateReverse));
stateChanged("rest_insert_tool_current", KXMLGUIClient::StateReverse);
slotTestClipboard();
if (getSegmentsOnlyRests()) {
m_selectDefaultNote->activate();
stateChanged("note_insert_tool_current",
KXMLGUIClient::StateNoReverse);
} else {
actionCollection()->action("select")->activate();
stateChanged("note_insert_tool_current",
KXMLGUIClient::StateReverse);
}
slotSetInsertCursorPosition(0);
slotSetPointerPosition(doc->getComposition().getPosition());
setCurrentSelection(0, false, true);
slotUpdateInsertModeStatus();
m_chordNameRuler->repaint();
m_rawNoteRuler->repaint();
m_inhibitRefresh = false;
// slotCheckRendered(0, getCanvasView()->visibleWidth());
// getCanvasView()->repaintContents();
updateView();
QObject::connect
(this, SIGNAL(renderComplete()),
getCanvasView(), SLOT(slotRenderComplete()));
if (parent) {
const TrackButtons * trackLabels =
((RosegardenGUIView*)parent)->getTrackEditor()->getTrackButtons();
QObject::connect
(trackLabels, SIGNAL(nameChanged()),
this, SLOT(slotUpdateStaffName()));
}
setConfigDialogPageIndex(2);
setOutOfCtor();
// Property and Control Rulers
//
if (getCurrentSegment()->getViewFeatures()) slotShowVelocityControlRuler();
setupControllerTabs();
setupAddControlRulerMenu();
setRewFFwdToAutoRepeat();
slotCompositionStateUpdate();
NOTATION_DEBUG << "NotationView ctor exiting" << endl;
}
//
// Notation Print mode
//
NotationView::NotationView(RosegardenGUIDoc *doc,
std::vector<Segment *> segments,
QWidget *parent,
NotationView *referenceView)
: EditView(doc, segments, 1, 0, "printview"),
m_properties(getViewLocalPropertyPrefix()),
m_selectionCounter(0),
m_currentNotePixmap(0),
m_hoveredOverNoteName(0),
m_hoveredOverAbsoluteTime(0),
m_lastFinishingStaff(-1),
m_title(0),
m_subtitle(0),
m_composer(0),
m_copyright(0),
m_insertionTime(0),
m_deferredCursorMove(NoCursorMoveNeeded),
m_lastNoteAction("crotchet"),
m_fontName(NoteFontFactory::getDefaultFontName()),
m_fontSize(NoteFontFactory::getDefaultSize(m_fontName)),
m_pageMode(LinedStaff::LinearMode),
m_leftGutter(0),
m_notePixmapFactory(new NotePixmapFactory(m_fontName, m_fontSize)),
m_hlayout(new NotationHLayout(&doc->getComposition(), m_notePixmapFactory,
m_properties, this)),
m_vlayout(new NotationVLayout(&doc->getComposition(), m_notePixmapFactory,
m_properties, this)),
m_chordNameRuler(0),
m_tempoRuler(0),
m_rawNoteRuler(0),
m_annotationsVisible(false),
m_selectDefaultNote(0),
m_fontCombo(0),
m_fontSizeCombo(0),
m_spacingCombo(0),
m_fontSizeActionMenu(0),
m_pannerDialog(0),
m_renderTimer(0),
m_playTracking(false),
m_progressDisplayer(PROGRESS_NONE),
m_inhibitRefresh(true),
m_ok(false),
m_printMode(true),
m_printSize(8) // set in positionStaffs
{
assert(segments.size() > 0);
NOTATION_DEBUG << "NotationView print ctor" << endl;
// Initialise the display-related defaults that will be needed
// by both the actions and the layout toolbar
m_config->setGroup(NotationView::ConfigGroup);
if (referenceView) {
m_fontName = referenceView->m_fontName;
} else {
m_fontName = qstrtostr(m_config->readEntry
("notefont",
strtoqstr(NoteFontFactory::getDefaultFontName())));
}
// Force largest font size
std::vector<int> sizes = NoteFontFactory::getAllSizes(m_fontName);
m_fontSize = sizes[sizes.size()-1];
if (referenceView) {
m_hlayout->setSpacing(referenceView->m_hlayout->getSpacing());
m_hlayout->setProportion(referenceView->m_hlayout->getProportion());
} else {
int defaultSpacing = m_config->readNumEntry("spacing", 100);
m_hlayout->setSpacing(defaultSpacing);
int defaultProportion = m_config->readNumEntry("proportion", 60);
m_hlayout->setProportion(defaultProportion);
}
delete m_notePixmapFactory;
m_notePixmapFactory = new NotePixmapFactory(m_fontName, m_fontSize);
m_hlayout->setNotePixmapFactory(m_notePixmapFactory);
m_vlayout->setNotePixmapFactory(m_notePixmapFactory);
setBackgroundMode(PaletteBase);
m_config->setGroup(NotationView::ConfigGroup);
QCanvas *tCanvas = new QCanvas(this);
tCanvas->resize(width() * 2, height() * 2);//!!!
setCanvasView(new NotationCanvasView(*this, tCanvas, getCentralWidget()));
canvas()->retune(128); // tune for larger canvas
for (unsigned int i = 0; i < segments.size(); ++i) {
m_staffs.push_back(new NotationStaff(canvas(), segments[i], 0, // snap
i, this,
m_fontName, m_fontSize));
}
m_currentStaff = 0;
m_staffs[0]->setCurrent(true);
RosegardenProgressDialog* progressDlg = 0;
if (parent) {
RosegardenProgressDialog::processEvents();
NOTATION_DEBUG << "NotationView : setting up progress dialog" << endl;
progressDlg = new RosegardenProgressDialog(i18n("Preparing to print..."),
100, parent);
progressDlg->setAutoClose(false);
progressDlg->setAutoReset(true);
progressDlg->setMinimumDuration(1000);
setupProgress(progressDlg);
m_progressDisplayer = PROGRESS_DIALOG;
}
try {
setPageMode(LinedStaff::MultiPageMode); // also positions and renders the staffs!
for (unsigned int i = 0; i < m_staffs.size(); ++i) {
m_staffs[i]->getSegment().getRefreshStatus
(m_segmentsRefreshStatusIds[i]).setNeedsRefresh(false);
}
m_ok = true;
} catch (ProgressReporter::Cancelled c) {
// when cancelled, m_ok is false -- checked by calling method
NOTATION_DEBUG << "NotationView ctor : layout Cancelled" << endl;
}
NOTATION_DEBUG << "NotationView ctor : m_ok = " << m_ok << endl;
delete progressDlg;
if (!isOK()) {
setOutOfCtor();
return; // In case more code is added there later
}
setOutOfCtor(); // keep this as last call in the ctor
}
NotationView::~NotationView()
{
NOTATION_DEBUG << "-> ~NotationView()" << endl;
if (!m_printMode && m_ok) slotSaveOptions();
delete m_chordNameRuler;
delete m_renderTimer;
for (unsigned int i = 0; i < m_staffs.size(); ++i) {
for (Segment::iterator j = m_staffs[i]->getSegment().begin();
j != m_staffs[i]->getSegment().end(); ++j) {
removeViewLocalProperties(*j);
}
delete m_staffs[i]; // this will erase all "notes" canvas items
}
PixmapArrayGC::deleteAll();
Rosegarden::Profiles::getInstance()->dump();
NOTATION_DEBUG << "<- ~NotationView()" << endl;
}
void
NotationView::removeViewLocalProperties(Rosegarden::Event *e)
{
Event::PropertyNames names(e->getPropertyNames());
std::string prefix(getViewLocalPropertyPrefix());
for (Event::PropertyNames::iterator i = names.begin();
i != names.end(); ++i) {
if (i->getName().substr(0, prefix.size()) == prefix) {
e->unset(*i);
}
}
}
const NotationProperties &
NotationView::getProperties() const
{
return m_properties;
}
void NotationView::positionStaffs()
{
NOTATION_DEBUG << "NotationView::positionStaffs" << endl;
m_config->setGroup(NotationView::ConfigGroup);
m_printSize = m_config->readUnsignedNumEntry("printingnotesize", 5);
int minTrack = 0, maxTrack = 0;
bool haveMinTrack = false;
typedef std::map<int, int> TrackIntMap;
TrackIntMap trackHeights;
TrackIntMap trackCoords;
int pageWidth, pageHeight, leftMargin, topMargin;
pageWidth = getPageWidth();
pageHeight = getPageHeight();
leftMargin = 0, topMargin = 0;
getPageMargins(leftMargin, topMargin);
int accumulatedHeight;
int rowsPerPage = 1;
int legerLines = 8;
if (m_pageMode != LinedStaff::LinearMode) legerLines = 7;
int rowGapPercent = (m_staffs.size() > 1 ? 40 : 10);
int aimFor = -1;
bool done = false;
int titleHeight = 0;
if (m_title) delete m_title;
if (m_subtitle) delete m_subtitle;
if (m_composer) delete m_composer;
if (m_copyright) delete m_copyright;
m_title = m_subtitle = m_composer = m_copyright = 0;
if (m_pageMode == LinedStaff::MultiPageMode) {
const Rosegarden::Configuration &metadata =
getDocument()->getComposition().getMetadata();
QFont defaultFont(NotePixmapFactory::defaultSerifFontFamily);
m_config->setGroup(NotationView::ConfigGroup);
QFont font = m_config->readFontEntry("textfont", &defaultFont);
font.setPixelSize(m_fontSize * 5);
QFontMetrics metrics(font);
if (metadata.has(Rosegarden::CompositionMetadataKeys::Title)) {
QString title(strtoqstr(metadata.get<Rosegarden::String>
(Rosegarden::CompositionMetadataKeys::Title)));
m_title = new QCanvasText(title, font, canvas());
m_title->setX(m_leftGutter + pageWidth/2 - metrics.width(title)/2);
m_title->setY(20 + topMargin/4 + metrics.ascent());
m_title->show();
titleHeight += metrics.height() * 3/2 + topMargin/4;
}
font.setPixelSize(m_fontSize * 3);
metrics = QFontMetrics(font);
if (metadata.has(Rosegarden::CompositionMetadataKeys::Subtitle)) {
QString subtitle(strtoqstr(metadata.get<Rosegarden::String>
(Rosegarden::CompositionMetadataKeys::Subtitle)));
m_subtitle = new QCanvasText(subtitle, font, canvas());
m_subtitle->setX(m_leftGutter + pageWidth/2 - metrics.width(subtitle)/2);
m_subtitle->setY(20 + titleHeight + metrics.ascent());
m_subtitle->show();
titleHeight += metrics.height() * 3/2;
}
if (metadata.has(Rosegarden::CompositionMetadataKeys::Composer)) {
QString composer(strtoqstr(metadata.get<Rosegarden::String>
(Rosegarden::CompositionMetadataKeys::Composer)));
m_composer = new QCanvasText(composer, font, canvas());
m_composer->setX(m_leftGutter + pageWidth - metrics.width(composer) - leftMargin);
m_composer->setY(20 + titleHeight + metrics.ascent());
m_composer->show();
titleHeight += metrics.height() * 3/2;
}
font.setPixelSize(m_fontSize * 2);
metrics = QFontMetrics(font);
if (metadata.has(Rosegarden::CompositionMetadataKeys::Copyright)) {
QString copyright(strtoqstr(metadata.get<Rosegarden::String>
(Rosegarden::CompositionMetadataKeys::Copyright)));
m_copyright = new QCanvasText(copyright, font, canvas());
m_copyright->setX(m_leftGutter + leftMargin);
m_copyright->setY(20 + pageHeight - topMargin - metrics.descent());
m_copyright->show();
}
}
while (1) {
accumulatedHeight = 0;
int maxTrackHeight = 0;
trackHeights.clear();
for (unsigned int i = 0; i < m_staffs.size(); ++i) {
m_staffs[i]->setLegerLineCount(legerLines);
int height = m_staffs[i]->getHeightOfRow();
Rosegarden::TrackId trackId = m_staffs[i]->getSegment().getTrack();
Rosegarden::Track *track =
m_staffs[i]->getSegment().getComposition()->
getTrackById(trackId);
if (!track) continue; // This Should Not Happen, My Friend
int trackPosition = track->getPosition();
TrackIntMap::iterator hi = trackHeights.find(trackPosition);
if (hi == trackHeights.end()) {
trackHeights.insert(TrackIntMap::value_type
(trackPosition, height));
} else if (height > hi->second) {
hi->second = height;
}
if (height > maxTrackHeight) maxTrackHeight = height;
if (trackPosition < minTrack || !haveMinTrack) {
minTrack = trackPosition;
haveMinTrack = true;
}
if (trackPosition > maxTrack) {
maxTrack = trackPosition;
}
}
for (int i = minTrack; i <= maxTrack; ++i) {
TrackIntMap::iterator hi = trackHeights.find(i);
if (hi != trackHeights.end()) {
trackCoords[i] = accumulatedHeight;
accumulatedHeight += hi->second;
}
}
accumulatedHeight += maxTrackHeight * rowGapPercent / 100;
if (done) break;
if (m_pageMode != LinedStaff::MultiPageMode) {
rowsPerPage = 0;
done = true;
break;
} else {
// Check how well all this stuff actually fits on the
// page. If things don't fit as well as we'd like, modify
// at most one parameter so as to save some space, then
// loop around again and see if it worked. This iterative
// approach is inefficient but the time spent here is
// neglible in context, and it's a simple way to code it.
int staffPageHeight = pageHeight - topMargin * 2 - titleHeight;
rowsPerPage = staffPageHeight / accumulatedHeight;
if (rowsPerPage < 1) {
if (legerLines > 5) --legerLines;
else if (rowGapPercent > 20) rowGapPercent -= 10;
else if (legerLines > 4) --legerLines;
else if (rowGapPercent > 0) rowGapPercent -= 10;
else if (legerLines > 3) --legerLines;
else if (m_printSize > 3) --m_printSize;
else { // just accept that we'll have to overflow
rowsPerPage = 1;
done = true;
}
} else {
if (aimFor == rowsPerPage) {
titleHeight +=
(staffPageHeight - (rowsPerPage * accumulatedHeight)) / 2;
done = true;
} else {
if (aimFor == -1) aimFor = rowsPerPage + 1;
// we can perhaps accommodate another row, with care
if (legerLines > 5) --legerLines;
else if (rowGapPercent > 20) rowGapPercent -= 10;
else if (legerLines > 3) --legerLines;
else if (rowGapPercent > 0) rowGapPercent -= 10;
else { // no, we can't
rowGapPercent = 0;
legerLines = 8;
done = true;
}
}
}
}
}
m_hlayout->setPageWidth(pageWidth - leftMargin * 2);
int topGutter = 0;
if (m_pageMode == LinedStaff::MultiPageMode) {
topGutter = 20;
} else if (m_pageMode == LinedStaff::ContinuousPageMode) {
// fewer leger lines above staff than in linear mode --
// compensate for this on the top staff
topGutter = m_notePixmapFactory->getLineSpacing() * 2;
}
for (unsigned int i = 0; i < m_staffs.size(); ++i) {
Rosegarden::TrackId trackId = m_staffs[i]->getSegment().getTrack();
Rosegarden::Track *track =
m_staffs[i]->getSegment().getComposition()->
getTrackById(trackId);
if (!track) continue; // Once Again, My Friend, You Should Never See Me Here
int trackPosition = track->getPosition();
m_staffs[i]->setTitleHeight(titleHeight);
m_staffs[i]->setRowSpacing(accumulatedHeight);
if (trackPosition < maxTrack) {
m_staffs[i]->setConnectingLineLength(trackHeights[trackPosition]);
}
if (trackPosition == minTrack &&
m_pageMode != LinedStaff::LinearMode) {
m_staffs[i]->setBarNumbersEvery(5);
} else {
m_staffs[i]->setBarNumbersEvery(0);
}
m_staffs[i]->setX(m_leftGutter);
m_staffs[i]->setY(topGutter + trackCoords[trackPosition] + topMargin);
m_staffs[i]->setPageWidth(pageWidth - leftMargin * 2);
m_staffs[i]->setRowsPerPage(rowsPerPage);
m_staffs[i]->setPageMode(m_pageMode);
m_staffs[i]->setMargin(leftMargin);
NOTATION_DEBUG << "NotationView::positionStaffs: set staff's page width to "
<< (pageWidth - leftMargin * 2) << endl;
}
}
void NotationView::positionPages()
{
if (m_printMode) return;
QPixmap background;
QPixmap deskBackground;
bool haveBackground = false;
m_config->setGroup(Rosegarden::GeneralOptionsConfigGroup);
if (m_config->readBoolEntry("backgroundtextures", false)) {
QString pixmapDir =
KGlobal::dirs()->findResource("appdata", "pixmaps/");
if (background.load(QString("%1/misc/bg-paper-white.xpm").
arg(pixmapDir))) {
haveBackground = true;
}
// we're happy to ignore errors from this one:
deskBackground.load(QString("%1/misc/bg-desktop.xpm").arg(pixmapDir));
}
int pageWidth = getPageWidth();
int pageHeight = getPageHeight();
int leftMargin = 0, topMargin = 0;
getPageMargins(leftMargin, topMargin);
int maxPageCount = 1;
for (unsigned int i = 0; i < m_staffs.size(); ++i) {
int pageCount = m_staffs[i]->getPageCount();
if (pageCount > maxPageCount) maxPageCount = pageCount;
}
for (unsigned int i = 0; i < m_pages.size(); ++i) {
delete m_pages[i];
delete m_pageNumbers[i];
}
m_pages.clear();
m_pageNumbers.clear();
if (m_pageMode != LinedStaff::MultiPageMode) {
if (haveBackground) {
canvas()->setBackgroundPixmap(background);
getCanvasView()->setBackgroundMode(Qt::FixedPixmap);
getCanvasView()->setPaletteBackgroundPixmap(background);
getCanvasView()->setErasePixmap(background);
}
} else {
if (haveBackground) {
canvas()->setBackgroundPixmap(deskBackground);
getCanvasView()->setBackgroundMode(Qt::FixedPixmap);
getCanvasView()->setPaletteBackgroundPixmap(background);
getCanvasView()->setErasePixmap(background);
}
QFont pageNumberFont;
pageNumberFont.setPixelSize(m_fontSize * 2);
QFontMetrics pageNumberMetrics(pageNumberFont);
for (int page = 0; page < maxPageCount; ++page) {
int x = m_leftGutter + pageWidth * page + leftMargin/4;
int y = 20;
int w = pageWidth - leftMargin/2;
int h = pageHeight;
QString str = QString("%1").arg(page + 1);
QCanvasText *text = new QCanvasText(str, pageNumberFont, canvas());
text->setX(m_leftGutter + pageWidth * page + pageWidth - pageNumberMetrics.width(str) - leftMargin);
text->setY(y + h - pageNumberMetrics.descent() - topMargin);
text->setZ(-999);
text->show();
m_pageNumbers.push_back(text);
QCanvasRectangle *rect = new QCanvasRectangle(x, y, w, h, canvas());
if (haveBackground) rect->setBrush(QBrush(Qt::white, background));
rect->setPen(Qt::black);
rect->setZ(-1000);
rect->show();
m_pages.push_back(rect);
}
updateThumbnails(false);
}
m_config->setGroup(NotationView::ConfigGroup);
}
void NotationView::slotUpdateStaffName()
{
NotationStaff *staff = getStaff(m_currentStaff);
staff->drawStaffName();
}
void NotationView::slotSaveOptions()
{
m_config->setGroup(NotationView::ConfigGroup);
m_config->writeEntry("Show Chord Name Ruler", getToggleAction("show_chords_ruler")->isChecked());
m_config->writeEntry("Show Raw Note Ruler", getToggleAction("show_raw_note_ruler")->isChecked());
m_config->writeEntry("Show Tempo Ruler", getToggleAction("show_tempo_ruler")->isChecked());
m_config->writeEntry("Show Annotations", m_annotationsVisible);
m_config->sync();
}
void NotationView::setOneToolbar(const char *actionName,
const char *toolbarName)
{
KToggleAction *action = getToggleAction(actionName);
if (!action) {
std::cerr << "WARNING: No such action as " << actionName << std::endl;
return;
}
QWidget *toolbar = toolBar(toolbarName);
if (!toolbar) {
std::cerr << "WARNING: No such toolbar as " << toolbarName << std::endl;
return;
}
action->setChecked(!toolbar->isHidden());
}
void NotationView::readOptions()
{
EditView::readOptions();
setOneToolbar("show_tools_toolbar", "Tools Toolbar");
setOneToolbar("show_notes_toolbar", "Notes Toolbar");
setOneToolbar("show_rests_toolbar", "Rests Toolbar");
setOneToolbar("show_clefs_toolbar", "Clefs Toolbar");
setOneToolbar("show_group_toolbar", "Group Toolbar");
setOneToolbar("show_marks_toolbar", "Marks Toolbar");
setOneToolbar("show_layout_toolbar", "Layout Toolbar");
setOneToolbar("show_transport_toolbar", "Transport Toolbar");
setOneToolbar("show_accidentals_toolbar", "Accidentals Toolbar");
setOneToolbar("show_meta_toolbar", "Meta Toolbar");
m_config->setGroup(NotationView::ConfigGroup);
bool opt;
opt = m_config->readBoolEntry("Show Chord Name Ruler", false);
getToggleAction("show_chords_ruler")->setChecked(opt);
slotToggleChordsRuler();
opt = m_config->readBoolEntry("Show Raw Note Ruler", true);
getToggleAction("show_raw_note_ruler")->setChecked(opt);
slotToggleRawNoteRuler();
opt = m_config->readBoolEntry("Show Tempo Ruler", false);
getToggleAction("show_tempo_ruler")->setChecked(opt);
slotToggleTempoRuler();
opt = m_config->readBoolEntry("Show Annotations", true);
m_annotationsVisible = opt;
getToggleAction("show_annotations")->setChecked(opt);
slotUpdateAnnotationsStatus();
// slotToggleAnnotations();
}
void NotationView::setupActions()
{
KStdAction::print(this, SLOT(slotFilePrint()), actionCollection());
KStdAction::printPreview(this, SLOT(slotFilePrintPreview()),
actionCollection());
EditViewBase::setupActions("notation.rc");
EditView::setupActions();
KRadioAction* noteAction = 0;
// View menu stuff
KActionMenu *fontActionMenu =
new KActionMenu(i18n("Note &Font"), this, "note_font_actionmenu");
std::set<std::string> fs(NoteFontFactory::getFontNames());
std::vector<std::string> f(fs.begin(), fs.end());
std::sort(f.begin(), f.end());
for (std::vector<std::string>::iterator i = f.begin(); i != f.end(); ++i) {
QString fontQName(strtoqstr(*i));
KToggleAction *fontAction =
new KToggleAction
(fontQName, 0, this, SLOT(slotChangeFontFromAction()),
actionCollection(), "note_font_" + fontQName);
fontAction->setChecked(*i == m_fontName);
fontActionMenu->insert(fontAction);
}
actionCollection()->insert(fontActionMenu);
m_fontSizeActionMenu =
new KActionMenu(i18n("Si&ze"), this, "note_font_size_actionmenu");
setupFontSizeMenu();
actionCollection()->insert(m_fontSizeActionMenu);
KActionMenu *spacingActionMenu =
new KActionMenu(i18n("S&pacing"), this, "stretch_actionmenu");
int defaultSpacing = m_hlayout->getSpacing();
std::vector<int> spacings = NotationHLayout::getAvailableSpacings();
for (std::vector<int>::iterator i = spacings.begin();
i != spacings.end(); ++i) {
KToggleAction *spacingAction =
new KToggleAction
(QString("%1%").arg(*i), 0, this,
SLOT(slotChangeSpacingFromAction()),
actionCollection(), QString("spacing_%1").arg(*i));
spacingAction->setExclusiveGroup("spacing");
spacingAction->setChecked(*i == defaultSpacing);
spacingActionMenu->insert(spacingAction);
}
actionCollection()->insert(spacingActionMenu);
KActionMenu *proportionActionMenu =
new KActionMenu(i18n("Du&ration Factor"), this, "proportion_actionmenu");
int defaultProportion = m_hlayout->getProportion();
std::vector<int> proportions = NotationHLayout::getAvailableProportions();
for (std::vector<int>::iterator i = proportions.begin();
i != proportions.end(); ++i) {
QString name = QString("%1%").arg(*i);
if (*i == 0) name = i18n("None");
KToggleAction *proportionAction =
new KToggleAction
(name, 0, this,
SLOT(slotChangeProportionFromAction()),
actionCollection(), QString("proportion_%1").arg(*i));
proportionAction->setExclusiveGroup("proportion");
proportionAction->setChecked(*i == defaultProportion);
proportionActionMenu->insert(proportionAction);
}
actionCollection()->insert(proportionActionMenu);
KActionMenu *styleActionMenu =
new KActionMenu(i18n("Note &Style"), this, "note_style_actionmenu");
std::vector<NoteStyleName> styles
(NoteStyleFactory::getAvailableStyleNames());
for (std::vector<NoteStyleName>::iterator i = styles.begin();
i != styles.end(); ++i) {
QString styleQName(strtoqstr(*i));
KAction *styleAction =
new KAction
(styleQName, 0, this, SLOT(slotSetStyleFromAction()),
actionCollection(), "style_" + styleQName);
styleActionMenu->insert(styleAction);
}
actionCollection()->insert(styleActionMenu);
KActionMenu *ornamentActionMenu =
new KActionMenu(i18n("Use Ornament"), this, "ornament_actionmenu");
new KAction
(i18n("Insert Rest"), Key_P, this, SLOT(slotInsertRest()),
actionCollection(), QString("insert_rest"));
new KAction
(i18n("Switch from Note to Rest"), Key_T, this,
SLOT(slotSwitchFromNoteToRest()),
actionCollection(), QString("switch_from_note_to_rest"));
new KAction
(i18n("Switch from Rest to Note"), Key_Y, this,
SLOT(slotSwitchFromRestToNote()),
actionCollection(), QString("switch_from_rest_to_note"));
// setup Notes menu & toolbar
QIconSet icon;
for (NoteActionDataMap::Iterator actionDataIter = m_noteActionDataMap->begin();
actionDataIter != m_noteActionDataMap->end();
++actionDataIter) {
NoteActionData noteActionData = *actionDataIter;
icon = QIconSet
(NotePixmapFactory::toQPixmap(NotePixmapFactory::makeToolbarPixmap
(noteActionData.pixmapName)));
noteAction = new KRadioAction(noteActionData.title,
icon,
noteActionData.keycode,
this,
SLOT(slotNoteAction()),
actionCollection(),
noteActionData.actionName);
noteAction->setExclusiveGroup("notes");
if (noteActionData.noteType == Note::Crotchet &&
noteActionData.dots == 0 && !noteActionData.rest) {
m_selectDefaultNote = noteAction;
}
}
// Note duration change actions
for (NoteChangeActionDataMap::Iterator actionDataIter = m_noteChangeActionDataMap->begin();
actionDataIter != m_noteChangeActionDataMap->end();
++actionDataIter) {
NoteChangeActionData data = *actionDataIter;
icon = QIconSet
(NotePixmapFactory::toQPixmap(NotePixmapFactory::makeToolbarPixmap
(data.pixmapName)));
KAction *action = new KAction(data.title,
icon,
data.keycode,
this,
SLOT(slotNoteChangeAction()),
actionCollection(),
data.actionName);
}
//
// Accidentals
//
static QString actionsAccidental[][4] =
{
{ i18n("No accidental"), "1slotNoAccidental()", "no_accidental", "accidental-none" },
{ i18n("Follow previous accidental"), "1slotFollowAccidental()", "follow_accidental", "accidental-follow" },
{ i18n("Sharp"), "1slotSharp()", "sharp_accidental", "accidental-sharp" },
{ i18n("Flat"), "1slotFlat()", "flat_accidental", "accidental-flat" },
{ i18n("Natural"), "1slotNatural()", "natural_accidental", "accidental-natural" },
{ i18n("Double sharp"), "1slotDoubleSharp()", "double_sharp_accidental", "accidental-doublesharp" },
{ i18n("Double flat"), "1slotDoubleFlat()", "double_flat_accidental", "accidental-doubleflat" }
};
for (unsigned int i = 0;
i < sizeof(actionsAccidental)/sizeof(actionsAccidental[0]); ++i) {
icon = QIconSet(NotePixmapFactory::toQPixmap(NotePixmapFactory::makeToolbarPixmap
(actionsAccidental[i][3])));
noteAction = new KRadioAction(actionsAccidental[i][0], icon, 0, this,
actionsAccidental[i][1],
actionCollection(), actionsAccidental[i][2]);
noteAction->setExclusiveGroup("accidentals");
}
//
// Clefs
//
// Treble
icon = QIconSet(NotePixmapFactory::toQPixmap(NotePixmapFactory::makeToolbarPixmap("clef-treble")));
noteAction = new KRadioAction(i18n("&Treble Clef"), icon, 0, this,
SLOT(slotTrebleClef()),
actionCollection(), "treble_clef");
noteAction->setExclusiveGroup("notes");
// Tenor
icon = QIconSet(NotePixmapFactory::toQPixmap(NotePixmapFactory::makeToolbarPixmap("clef-tenor")));
noteAction = new KRadioAction(i18n("Te&nor Clef"), icon, 0, this,
SLOT(slotTenorClef()),
actionCollection(), "tenor_clef");
noteAction->setExclusiveGroup("notes");
// Alto
icon = QIconSet(NotePixmapFactory::toQPixmap(NotePixmapFactory::makeToolbarPixmap("clef-alto")));
noteAction = new KRadioAction(i18n("&Alto Clef"), icon, 0, this,
SLOT(slotAltoClef()),
actionCollection(), "alto_clef");
noteAction->setExclusiveGroup("notes");
// Bass
icon = QIconSet(NotePixmapFactory::toQPixmap(NotePixmapFactory::makeToolbarPixmap("clef-bass")));
noteAction = new KRadioAction(i18n("&Bass Clef"), icon, 0, this,
SLOT(slotBassClef()),
actionCollection(), "bass_clef");
noteAction->setExclusiveGroup("notes");
icon = QIconSet(NotePixmapFactory::toQPixmap(NotePixmapFactory::makeToolbarPixmap("text")));
noteAction = new KRadioAction(i18n("&Text"), icon, Key_F8, this,
SLOT(slotText()),
actionCollection(), "text");
noteAction->setExclusiveGroup("notes");
//
// Edition tools (eraser, selector...)
//
noteAction = new KRadioAction(i18n("&Erase"), "eraser", Key_F4,
this, SLOT(slotEraseSelected()),
actionCollection(), "erase");
noteAction->setExclusiveGroup("notes");
icon = QIconSet(NotePixmapFactory::toQPixmap(NotePixmapFactory::makeToolbarPixmap("select")));
noteAction = new KRadioAction(i18n("&Select"), icon, Key_F2,
this, SLOT(slotSelectSelected()),
actionCollection(), "select");
noteAction->setExclusiveGroup("notes");
icon = QIconSet(NotePixmapFactory::toQPixmap(NotePixmapFactory::makeToolbarPixmap("step_by_step")));
new KToggleAction(i18n("Ste&p Recording"), icon, 0, this,
SLOT(slotToggleStepByStep()), actionCollection(),
"toggle_step_by_step");
// Edit menu
new KAction(i18n("Select from Sta&rt"), 0, this,
SLOT(slotEditSelectFromStart()), actionCollection(),
"select_from_start");
new KAction(i18n("Select to &End"), 0, this,
SLOT(slotEditSelectToEnd()), actionCollection(),
"select_to_end");
new KAction(i18n("Select Whole St&aff"), Key_A + CTRL, this,
SLOT(slotEditSelectWholeStaff()), actionCollection(),
"select_whole_staff");
new KAction(i18n("C&ut and Close"), CTRL + SHIFT + Key_X, this,
SLOT(slotEditCutAndClose()), actionCollection(),
"cut_and_close");
new KAction(i18n("Pa&ste..."), CTRL + SHIFT + Key_V, this,
SLOT(slotEditGeneralPaste()), actionCollection(),
"general_paste");
new KAction(i18n("De&lete"), Key_Delete, this,
SLOT(slotEditDelete()), actionCollection(),
"delete");
//
// Settings menu
//
int layoutMode = m_config->readNumEntry("layoutmode", 0);
QString pixmapDir = KGlobal::dirs()->findResource("appdata", "pixmaps/");
QCanvasPixmap pixmap(pixmapDir + "/toolbar/linear-layout.xpm");
icon = QIconSet(pixmap);
KRadioAction *linearModeAction = new KRadioAction
(i18n("&Linear Layout"), icon, 0, this, SLOT(slotLinearMode()),
actionCollection(), "linear_mode");
linearModeAction->setExclusiveGroup("layoutMode");
if (layoutMode == 0) linearModeAction->setChecked(true);
pixmap.load(pixmapDir + "/toolbar/continuous-page-mode.xpm");
icon = QIconSet(pixmap);
KRadioAction *continuousPageModeAction = new KRadioAction
(i18n("&Continuous Page Layout"), icon, 0, this, SLOT(slotContinuousPageMode()),
actionCollection(), "continuous_page_mode");
continuousPageModeAction->setExclusiveGroup("layoutMode");
if (layoutMode == 1) continuousPageModeAction->setChecked(true);
pixmap.load(pixmapDir + "/toolbar/multi-page-mode.xpm");
icon = QIconSet(pixmap);
KRadioAction *multiPageModeAction = new KRadioAction
(i18n("&Multiple Page Layout"), icon, 0, this, SLOT(slotMultiPageMode()),
actionCollection(), "multi_page_mode");
multiPageModeAction->setExclusiveGroup("layoutMode");
if (layoutMode == 2) multiPageModeAction->setChecked(true);
new KToggleAction(i18n("Show Ch&ord Name Ruler"), 0, this,
SLOT(slotToggleChordsRuler()),
actionCollection(), "show_chords_ruler");
new KToggleAction(i18n("Show Ra&w Note Ruler"), 0, this,
SLOT(slotToggleRawNoteRuler()),
actionCollection(), "show_raw_note_ruler");
new KToggleAction(i18n("Show &Tempo Ruler"), 0, this,
SLOT(slotToggleTempoRuler()),
actionCollection(), "show_tempo_ruler");
new KToggleAction(i18n("Show &Annotations"), 0, this,
SLOT(slotToggleAnnotations()),
actionCollection(), "show_annotations");
new KAction(i18n("Open L&yric Editor"), 0, this, SLOT(slotEditLyrics()),
actionCollection(), "lyric_editor");
//
// Group menu
//
icon = QIconSet
(NotePixmapFactory::toQPixmap(NotePixmapFactory::makeToolbarPixmap
("group-beam")));
new KAction(NotesMenuBeamCommand::getGlobalName(), icon, Key_B + CTRL, this,
SLOT(slotGroupBeam()), actionCollection(), "beam");
new KAction(NotesMenuAutoBeamCommand::getGlobalName(), 0, this,
SLOT(slotGroupAutoBeam()), actionCollection(), "auto_beam");
icon = QIconSet
(NotePixmapFactory::toQPixmap(NotePixmapFactory::makeToolbarPixmap
("group-unbeam")));
new KAction(NotesMenuBreakCommand::getGlobalName(), icon, Key_U + CTRL, this,
SLOT(slotGroupBreak()), actionCollection(), "break_group");
icon = QIconSet
(NotePixmapFactory::toQPixmap(NotePixmapFactory::makeToolbarPixmap
("group-simple-tuplet")));
new KAction(AdjustMenuTupletCommand::getGlobalName(true), icon, Key_R + CTRL, this,
SLOT(slotGroupSimpleTuplet()), actionCollection(), "simple_tuplet");
icon = QIconSet
(NotePixmapFactory::toQPixmap(NotePixmapFactory::makeToolbarPixmap
("group-tuplet")));
new KAction(AdjustMenuTupletCommand::getGlobalName(false), icon, Key_T + CTRL, this,
SLOT(slotGroupGeneralTuplet()), actionCollection(), "tuplet");
new KAction(AdjustMenuUnTupletCommand::getGlobalName(), 0, this,
SLOT(slotGroupUnTuplet()), actionCollection(), "break_tuplets");
icon = QIconSet(NotePixmapFactory::toQPixmap(NotePixmapFactory::makeToolbarPixmap("triplet")));
(new KToggleAction(i18n("Trip&let Insert Mode"), icon, Key_G,
this, SLOT(slotUpdateInsertModeStatus()),
actionCollection(), "triplet_mode"))->
setChecked(false);
icon = QIconSet(NotePixmapFactory::toQPixmap(NotePixmapFactory::makeToolbarPixmap("chord")));
(new KToggleAction(i18n("C&hord Insert Mode"), icon, Key_H,
this, SLOT(slotUpdateInsertModeStatus()),
actionCollection(), "chord_mode"))->
setChecked(false);
icon = QIconSet
(NotePixmapFactory::toQPixmap(NotePixmapFactory::makeToolbarPixmap
("group-grace")));
new KAction(AdjustMenuGraceCommand::getGlobalName(), icon, 0, this,
SLOT(slotGroupGrace()), actionCollection(), "grace");
new KAction(AdjustMenuUnGraceCommand::getGlobalName(), 0, this,
SLOT(slotGroupUnGrace()), actionCollection(), "ungrace");
icon = QIconSet
(NotePixmapFactory::toQPixmap(NotePixmapFactory::makeToolbarPixmap
("group-slur")));
new KAction(NotesMenuAddIndicationCommand::getGlobalName
(Rosegarden::Indication::Slur), icon, Key_ParenRight, this,
SLOT(slotGroupSlur()), actionCollection(), "slur");
new KAction(NotesMenuAddIndicationCommand::getGlobalName
(Rosegarden::Indication::PhrasingSlur), 0, Key_ParenRight + CTRL, this,
SLOT(slotGroupPhrasingSlur()), actionCollection(), "phrasing_slur");
icon = QIconSet
(NotePixmapFactory::toQPixmap(NotePixmapFactory::makeToolbarPixmap
("group-glissando")));
new KAction(NotesMenuAddIndicationCommand::getGlobalName
(Rosegarden::Indication::Glissando), icon, 0, this,
SLOT(slotGroupGlissando()), actionCollection(), "glissando");
icon = QIconSet
(NotePixmapFactory::toQPixmap(NotePixmapFactory::makeToolbarPixmap
("group-crescendo")));
new KAction(NotesMenuAddIndicationCommand::getGlobalName
(Rosegarden::Indication::Crescendo), icon, Key_Less, this,
SLOT(slotGroupCrescendo()), actionCollection(), "crescendo");
icon = QIconSet
(NotePixmapFactory::toQPixmap(NotePixmapFactory::makeToolbarPixmap
("group-decrescendo")));
new KAction(NotesMenuAddIndicationCommand::getGlobalName
(Rosegarden::Indication::Decrescendo), icon, Key_Greater, this,
SLOT(slotGroupDecrescendo()), actionCollection(), "decrescendo");
new KAction(NotesMenuAddIndicationCommand::getGlobalName
(Rosegarden::Indication::QuindicesimaUp), 0, 0, this,
SLOT(slotGroupOctave2Up()), actionCollection(), "octave_2up");
icon = QIconSet
(NotePixmapFactory::toQPixmap(NotePixmapFactory::makeToolbarPixmap
("group-ottava")));
new KAction(NotesMenuAddIndicationCommand::getGlobalName
(Rosegarden::Indication::OttavaUp), icon, 0, this,
SLOT(slotGroupOctaveUp()), actionCollection(), "octave_up");
new KAction(NotesMenuAddIndicationCommand::getGlobalName
(Rosegarden::Indication::OttavaDown), 0, 0, this,
SLOT(slotGroupOctaveDown()), actionCollection(), "octave_down");
new KAction(NotesMenuAddIndicationCommand::getGlobalName
(Rosegarden::Indication::QuindicesimaDown), 0, 0, this,
SLOT(slotGroupOctave2Down()), actionCollection(), "octave_2down");
icon = QIconSet
(NotePixmapFactory::toQPixmap(NotePixmapFactory::makeToolbarPixmap
("group-chord")));
new KAction(AdjustMenuMakeChordCommand::getGlobalName(), icon, 0, this,
SLOT(slotGroupMakeChord()), actionCollection(), "make_chord");
// setup Transforms menu
new KAction(AdjustMenuNormalizeRestsCommand::getGlobalName(), Key_N + CTRL, this,
SLOT(slotTransformsNormalizeRests()), actionCollection(),
"normalize_rests");
new KAction(AdjustMenuCollapseRestsCommand::getGlobalName(), 0, this,
SLOT(slotTransformsCollapseRests()), actionCollection(),
"collapse_rests_aggressively");
new KAction(AdjustMenuCollapseNotesCommand::getGlobalName(), Key_Equal + CTRL, this,
SLOT(slotTransformsCollapseNotes()), actionCollection(),
"collapse_notes");
icon = QIconSet
(NotePixmapFactory::toQPixmap(NotePixmapFactory::makeToolbarPixmap
("transforms-tie")));
new KAction(NotesMenuTieNotesCommand::getGlobalName(), icon, Key_AsciiTilde, this,
SLOT(slotTransformsTieNotes()), actionCollection(),
"tie_notes");
new KAction(AdjustMenuUntieNotesCommand::getGlobalName(), 0, this,
SLOT(slotTransformsUntieNotes()), actionCollection(),
"untie_notes");
new KAction(AdjustMenuMakeNotesViableCommand::getGlobalName(), 0, this,
SLOT(slotTransformsMakeNotesViable()), actionCollection(),
"make_notes_viable");
icon = QIconSet
(NotePixmapFactory::toQPixmap(NotePixmapFactory::makeToolbarPixmap
("transforms-decounterpoint")));
new KAction(AdjustMenuDeCounterpointCommand::getGlobalName(), icon, 0, this,
SLOT(slotTransformsDeCounterpoint()), actionCollection(),
"de_counterpoint");
new KAction(AdjustMenuChangeStemsCommand::getGlobalName(true),
0, Key_PageUp + CTRL, this,
SLOT(slotTransformsStemsUp()), actionCollection(),
"stems_up");
new KAction(AdjustMenuChangeStemsCommand::getGlobalName(false),
0, Key_PageDown + CTRL, this,
SLOT(slotTransformsStemsDown()), actionCollection(),
"stems_down");
new KAction(AdjustMenuRestoreStemsCommand::getGlobalName(), 0, this,
SLOT(slotTransformsRestoreStems()), actionCollection(),
"restore_stems");
new KAction(AdjustMenuChangeSlurPositionCommand::getGlobalName(true),
0, this,
SLOT(slotTransformsSlursAbove()), actionCollection(),
"slurs_above");
new KAction(AdjustMenuChangeSlurPositionCommand::getGlobalName(false),
0, this,
SLOT(slotTransformsSlursBelow()), actionCollection(),
"slurs_below");
new KAction(AdjustMenuRestoreSlursCommand::getGlobalName(), 0, this,
SLOT(slotTransformsRestoreSlurs()), actionCollection(),
"restore_slurs");
new KAction(RespellCommand::getGlobalName
(RespellCommand::Set, Rosegarden::Accidentals::DoubleFlat),
0, this,
SLOT(slotRespellDoubleFlat()), actionCollection(),
"respell_doubleflat");
new KAction(RespellCommand::getGlobalName
(RespellCommand::Set, Rosegarden::Accidentals::Flat),
0, this,
SLOT(slotRespellFlat()), actionCollection(),
"respell_flat");
new KAction(RespellCommand::getGlobalName
(RespellCommand::Set, Rosegarden::Accidentals::Natural),
0, this,
SLOT(slotRespellNatural()), actionCollection(),
"respell_natural");
new KAction(RespellCommand::getGlobalName
(RespellCommand::Set, Rosegarden::Accidentals::Sharp),
0, this,
SLOT(slotRespellSharp()), actionCollection(),
"respell_sharp");
new KAction(RespellCommand::getGlobalName
(RespellCommand::Set, Rosegarden::Accidentals::DoubleSharp),
0, this,
SLOT(slotRespellDoubleSharp()), actionCollection(),
"respell_doublesharp");
new KAction(RespellCommand::getGlobalName
(RespellCommand::Up, Rosegarden::Accidentals::NoAccidental),
Key_Up + CTRL + SHIFT, this,
SLOT(slotRespellUp()), actionCollection(),
"respell_up");
new KAction(RespellCommand::getGlobalName
(RespellCommand::Down, Rosegarden::Accidentals::NoAccidental),
Key_Down + CTRL + SHIFT, this,
SLOT(slotRespellDown()), actionCollection(),
"respell_down");
new KAction(RespellCommand::getGlobalName
(RespellCommand::Restore, Rosegarden::Accidentals::NoAccidental),
0, this,
SLOT(slotRespellRestore()), actionCollection(),
"respell_restore");
new KAction(MakeAccidentalsCautionaryCommand::getGlobalName(true),
0, this,
SLOT(slotShowCautionary()), actionCollection(),
"show_cautionary");
new KAction(MakeAccidentalsCautionaryCommand::getGlobalName(false),
0, this,
SLOT(slotCancelCautionary()), actionCollection(),
"cancel_cautionary");
icon = QIconSet
(NotePixmapFactory::toQPixmap(NotePixmapFactory::makeToolbarPixmap
("quantize")));
new KAction(EventQuantizeCommand::getGlobalName(), icon, Key_Equal, this,
SLOT(slotTransformsQuantize()), actionCollection(),
"quantize");
new KAction(AdjustMenuFixNotationQuantizeCommand::getGlobalName(), 0,
this, SLOT(slotTransformsFixQuantization()), actionCollection(),
"fix_quantization");
new KAction(AdjustMenuRemoveNotationQuantizeCommand::getGlobalName(), 0,
this, SLOT(slotTransformsRemoveQuantization()), actionCollection(),
"remove_quantization");
new KAction(AdjustMenuInterpretCommand::getGlobalName(), 0,
this, SLOT(slotTransformsInterpret()), actionCollection(),
"interpret");
new KAction(i18n("&Dump selected events to stderr"), 0, this,
SLOT(slotDebugDump()), actionCollection(), "debug_dump");
for (MarkActionDataMap::Iterator i = m_markActionDataMap->begin();
i != m_markActionDataMap->end(); ++i) {
const MarkActionData &markActionData = *i;
icon = QIconSet(NotePixmapFactory::toQPixmap
(NotePixmapFactory::makeMarkMenuPixmap(markActionData.mark)));
new KAction(markActionData.title,
icon,
markActionData.keycode,
this,
SLOT(slotAddMark()),
actionCollection(),
markActionData.actionName);
}
icon = QIconSet
(NotePixmapFactory::toQPixmap(NotePixmapFactory::makeToolbarPixmap
("text-mark")));
new KAction(NotesMenuAddTextMarkCommand::getGlobalName(), icon, 0, this,
SLOT(slotMarksAddTextMark()), actionCollection(),
"add_text_mark");
new KAction(NotesMenuAddFingeringMarkCommand::getGlobalName("0"), 0, Key_0 + ALT, this,
SLOT(slotMarksAddFingeringMarkFromAction()), actionCollection(),
"add_fingering_0");
new KAction(NotesMenuAddFingeringMarkCommand::getGlobalName("1"), 0, Key_1 + ALT, this,
SLOT(slotMarksAddFingeringMarkFromAction()), actionCollection(),
"add_fingering_1");
new KAction(NotesMenuAddFingeringMarkCommand::getGlobalName("2"), 0, Key_2 + ALT, this,
SLOT(slotMarksAddFingeringMarkFromAction()), actionCollection(),
"add_fingering_2");
new KAction(NotesMenuAddFingeringMarkCommand::getGlobalName("3"), 0, Key_3 + ALT, this,
SLOT(slotMarksAddFingeringMarkFromAction()), actionCollection(),
"add_fingering_3");
new KAction(NotesMenuAddFingeringMarkCommand::getGlobalName("4"), 0, Key_4 + ALT, this,
SLOT(slotMarksAddFingeringMarkFromAction()), actionCollection(),
"add_fingering_4");
new KAction(NotesMenuAddFingeringMarkCommand::getGlobalName("5"), 0, Key_5 + ALT, this,
SLOT(slotMarksAddFingeringMarkFromAction()), actionCollection(),
"add_fingering_5");
new KAction(NotesMenuAddFingeringMarkCommand::getGlobalName("+"), 0, Key_9 + ALT, this,
SLOT(slotMarksAddFingeringMarkFromAction()), actionCollection(),
"add_fingering_plus");
new KAction(NotesMenuAddFingeringMarkCommand::getGlobalName(), 0, 0, this,
SLOT(slotMarksAddFingeringMark()), actionCollection(),
"add_fingering_mark");
new KAction(NotesMenuRemoveMarksCommand::getGlobalName(), 0, this,
SLOT(slotMarksRemoveMarks()), actionCollection(),
"remove_marks");
new KAction(NotesMenuRemoveFingeringMarksCommand::getGlobalName(), 0, this,
SLOT(slotMarksRemoveFingeringMarks()), actionCollection(),
"remove_fingering_marks");
new KAction(i18n("Ma&ke Ornament..."), 0, this,
SLOT(slotMakeOrnament()), actionCollection(),
"make_ornament");
new KAction(i18n("Trigger &Ornament..."), 0, this,
SLOT(slotUseOrnament()), actionCollection(),
"use_ornament");
new KAction(i18n("Remove Ornament..."), 0, this,
SLOT(slotRemoveOrnament()), actionCollection(),
"remove_ornament");
static QString slashTitles[] = {
i18n("&None"), "&1", "&2", "&3", "&4", "&5"
};
for (int i = 0; i <= 5; ++i) {
new KAction(slashTitles[i], 0, this,
SLOT(slotAddSlashes()), actionCollection(),
QString("slashes_%1").arg(i));
}
new KAction(ClefInsertionCommand::getGlobalName(), 0, this,
SLOT(slotEditAddClef()), actionCollection(),
"add_clef");
new KAction(KeyInsertionCommand::getGlobalName(), 0, this,
SLOT(slotEditAddKeySignature()), actionCollection(),
"add_key_signature");
new KAction(SustainInsertionCommand::getGlobalName(true), 0, this,
SLOT(slotEditAddSustainDown()), actionCollection(),
"add_sustain_down");
new KAction(SustainInsertionCommand::getGlobalName(false), 0, this,
SLOT(slotEditAddSustainUp()), actionCollection(),
"add_sustain_up");
// setup Settings menu
static QString actionsToolbars[][4] =
{
{ i18n("Show T&ools Toolbar"), "1slotToggleToolsToolBar()", "show_tools_toolbar", "palette-tools" },
{ i18n("Show &Notes Toolbar"), "1slotToggleNotesToolBar()", "show_notes_toolbar", "palette-notes" },
{ i18n("Show &Rests Toolbar"), "1slotToggleRestsToolBar()", "show_rests_toolbar", "palette-rests" },
{ i18n("Show &Accidentals Toolbar"), "1slotToggleAccidentalsToolBar()", "show_accidentals_toolbar", "palette-accidentals" },
{ i18n("Show Cle&fs Toolbar"), "1slotToggleClefsToolBar()", "show_clefs_toolbar",
"palette-clefs" },
{ i18n("Show &Marks Toolbar"), "1slotToggleMarksToolBar()", "show_marks_toolbar",
"palette-marks" },
{ i18n("Show &Group Toolbar"), "1slotToggleGroupToolBar()", "show_group_toolbar",
"palette-group" },
{ i18n("Show &Layout Toolbar"), "1slotToggleLayoutToolBar()", "show_layout_toolbar",
"palette-font" },
{ i18n("Show Trans&port Toolbar"), "1slotToggleTransportToolBar()", "show_transport_toolbar",
"palette-transport" },
{ i18n("Show M&eta Toolbar"), "1slotToggleMetaToolBar()", "show_meta_toolbar",
"palette-meta" }
};
for (unsigned int i = 0;
i < sizeof(actionsToolbars)/sizeof(actionsToolbars[0]); ++i) {
icon = QIconSet(NotePixmapFactory::toQPixmap(NotePixmapFactory::makeToolbarPixmap(actionsToolbars[i][3])));
new KToggleAction(actionsToolbars[i][0], icon, 0,
this, actionsToolbars[i][1],
actionCollection(), actionsToolbars[i][2]);
}
new KAction(i18n("Cursor &Back"), 0, Key_Left, this,
SLOT(slotStepBackward()), actionCollection(),
"cursor_back");
new KAction(i18n("Cursor &Forward"), 0, Key_Right, this,
SLOT(slotStepForward()), actionCollection(),
"cursor_forward");
new KAction(i18n("Cursor Ba&ck Bar"), 0, Key_Left + CTRL, this,
SLOT(slotJumpBackward()), actionCollection(),
"cursor_back_bar");
new KAction(i18n("Cursor For&ward Bar"), 0, Key_Right + CTRL, this,
SLOT(slotJumpForward()), actionCollection(),
"cursor_forward_bar");
new KAction(i18n("Cursor Back and Se&lect"), SHIFT + Key_Left, this,
SLOT(slotExtendSelectionBackward()), actionCollection(),
"extend_selection_backward");
new KAction(i18n("Cursor Forward and &Select"), SHIFT + Key_Right, this,
SLOT(slotExtendSelectionForward()), actionCollection(),
"extend_selection_forward");
new KAction(i18n("Cursor Back Bar and Select"), SHIFT + CTRL + Key_Left, this,
SLOT(slotExtendSelectionBackwardBar()), actionCollection(),
"extend_selection_backward_bar");
new KAction(i18n("Cursor Forward Bar and Select"), SHIFT + CTRL + Key_Right, this,
SLOT(slotExtendSelectionForwardBar()), actionCollection(),
"extend_selection_forward_bar");
/*!!! not here yet
new KAction(i18n("Move Selection Left"), Key_Minus, this,
SLOT(slotMoveSelectionLeft()), actionCollection(),
"move_selection_left");
*/
new KAction(i18n("Cursor to St&art"), 0,
/* #1025717: conflicting meanings for ctrl+a - dupe with Select All
Key_A + CTRL, */ this,
SLOT(slotJumpToStart()), actionCollection(),
"cursor_start");
new KAction(i18n("Cursor to &End"), 0, Key_E + CTRL, this,
SLOT(slotJumpToEnd()), actionCollection(),
"cursor_end");
new KAction(i18n("Cursor &Up Staff"), 0, Key_Up + SHIFT, this,
SLOT(slotCurrentStaffUp()), actionCollection(),
"cursor_up_staff");
new KAction(i18n("Cursor &Down Staff"), 0, Key_Down + SHIFT, this,
SLOT(slotCurrentStaffDown()), actionCollection(),
"cursor_down_staff");
icon = QIconSet(NotePixmapFactory::toQPixmap(NotePixmapFactory::makeToolbarPixmap
("transport-cursor-to-pointer")));
new KAction(i18n("Cursor to &Playback Pointer"), icon, 0, this,
SLOT(slotJumpCursorToPlayback()), actionCollection(),
"cursor_to_playback_pointer");
icon = QIconSet(NotePixmapFactory::toQPixmap(NotePixmapFactory::makeToolbarPixmap
("transport-play")));
new KAction(i18n("&Play"), icon, Key_Enter, this,
SIGNAL(play()), actionCollection(), "play");
icon = QIconSet(NotePixmapFactory::toQPixmap(NotePixmapFactory::makeToolbarPixmap
("transport-stop")));
new KAction(i18n("&Stop"), icon, Key_Insert, this,
SIGNAL(stop()), actionCollection(), "stop");
icon = QIconSet(NotePixmapFactory::toQPixmap(NotePixmapFactory::makeToolbarPixmap
("transport-rewind")));
new KAction(i18n("Re&wind"), icon, Key_End, this,
SIGNAL(rewindPlayback()), actionCollection(),
"playback_pointer_back_bar");
icon = QIconSet(NotePixmapFactory::toQPixmap(NotePixmapFactory::makeToolbarPixmap
("transport-ffwd")));
new KAction(i18n("&Fast Forward"), icon, Key_PageDown, this,
SIGNAL(fastForwardPlayback()), actionCollection(),
"playback_pointer_forward_bar");
icon = QIconSet(NotePixmapFactory::toQPixmap(NotePixmapFactory::makeToolbarPixmap
("transport-rewind-end")));
new KAction(i18n("Rewind to &Beginning"), icon, 0, this,
SIGNAL(rewindPlaybackToBeginning()), actionCollection(),
"playback_pointer_start");
icon = QIconSet(NotePixmapFactory::toQPixmap(NotePixmapFactory::makeToolbarPixmap
("transport-ffwd-end")));
new KAction(i18n("Fast Forward to &End"), icon, 0, this,
SIGNAL(fastForwardPlaybackToEnd()), actionCollection(),
"playback_pointer_end");
icon = QIconSet(NotePixmapFactory::toQPixmap(NotePixmapFactory::makeToolbarPixmap
("transport-pointer-to-cursor")));
new KAction(i18n("Playback Pointer to &Cursor"), icon, 0, this,
SLOT(slotJumpPlaybackToCursor()), actionCollection(),
"playback_pointer_to_cursor");
icon = QIconSet(NotePixmapFactory::toQPixmap(NotePixmapFactory::makeToolbarPixmap
("transport-solo")));
new KToggleAction(i18n("&Solo"), icon, 0, this,
SLOT(slotToggleSolo()), actionCollection(),
"toggle_solo");
icon = QIconSet(NotePixmapFactory::toQPixmap(NotePixmapFactory::makeToolbarPixmap
("transport-tracking")));
(new KToggleAction(i18n("Scro&ll to Follow Playback"), icon, Key_Pause, this,
SLOT(slotToggleTracking()), actionCollection(),
"toggle_tracking"))->setChecked(m_playTracking);
new KAction(i18n("Set Loop to Selection"), Key_Semicolon + CTRL, this,
SLOT(slotPreviewSelection()), actionCollection(),
"preview_selection");
new KAction(i18n("Clear L&oop"), Key_Colon + CTRL, this,
SLOT(slotClearLoop()), actionCollection(),
"clear_loop");
new KAction(i18n("Clear Selection"), Key_Escape, this,
SLOT(slotClearSelection()), actionCollection(),
"clear_selection");
// QString pixmapDir =
// KGlobal::dirs()->findResource("appdata", "pixmaps/");
// icon = QIconSet(QCanvasPixmap(pixmapDir + "/toolbar/eventfilter.xpm"));
new KAction(i18n("&Filter Selection"), "filter", Key_F + CTRL, this,
SLOT(slotFilterSelection()), actionCollection(),
"filter_selection");
new KAction(i18n("Push &Left"), 0, this,
SLOT(slotFinePositionLeft()), actionCollection(),
"fine_position_left");
new KAction(i18n("Push &Right"), 0, this,
SLOT(slotFinePositionRight()), actionCollection(),
"fine_position_right");
new KAction(i18n("Push &Up"), 0, this,
SLOT(slotFinePositionUp()), actionCollection(),
"fine_position_up");
new KAction(i18n("Push &Down"), 0, this,
SLOT(slotFinePositionDown()), actionCollection(),
"fine_position_down");
new KAction(i18n("Restore &Computed Positions"), 0, this,
SLOT(slotFinePositionRestore()), actionCollection(),
"fine_position_restore");
new KAction(i18n("Make &Invisible"), 0, this,
SLOT(slotMakeInvisible()), actionCollection(),
"make_invisible");
new KAction(i18n("Make &Visible"), 0, this,
SLOT(slotMakeVisible()), actionCollection(),
"make_visible");
new KAction(i18n("Toggle Dot"), Key_Period, this,
SLOT(slotToggleDot()), actionCollection(),
"toggle_dot");
new KAction(i18n("Add Dot"), Key_Period + CTRL, this,
SLOT(slotAddDot()), actionCollection(),
"add_dot");
new KAction(i18n("Add Dot"), Key_Period + CTRL + ALT, this,
SLOT(slotAddDotNotationOnly()), actionCollection(),
"add_notation_dot");
createGUI(getRCFileName(), false);
}
bool
NotationView::isInChordMode()
{
return ((KToggleAction *)actionCollection()->action("chord_mode"))->
isChecked();
}
bool
NotationView::isInTripletMode()
{
return ((KToggleAction *)actionCollection()->action("triplet_mode"))->
isChecked();
}
void
NotationView::setupFontSizeMenu(std::string oldFontName)
{
if (oldFontName != "") {
std::vector<int> sizes = NoteFontFactory::getScreenSizes(oldFontName);
for (unsigned int i = 0; i < sizes.size(); ++i) {
KAction *action =
actionCollection()->action
(QString("note_font_size_%1").arg(sizes[i]));
m_fontSizeActionMenu->remove(action);
// Don't delete -- that could cause a crash when this
// function is called from the action itself. Instead
// we reuse and reinsert existing actions below.
}
}
std::vector<int> sizes = NoteFontFactory::getScreenSizes(m_fontName);
for (unsigned int i = 0; i < sizes.size(); ++i) {
QString actionName = QString("note_font_size_%1").arg(sizes[i]);
KToggleAction *sizeAction = dynamic_cast<KToggleAction *>
(actionCollection()->action(actionName));
if (!sizeAction) {
sizeAction =
new KToggleAction
(sizes[i] == 1 ? i18n("%1 pixel").arg(sizes[i]) :
i18n("%1 pixels").arg(sizes[i]),
0, this,
SLOT(slotChangeFontSizeFromAction()),
actionCollection(), actionName);
}
sizeAction->setChecked(sizes[i] == m_fontSize);
m_fontSizeActionMenu->insert(sizeAction);
}
}
NotationStaff *
NotationView::getStaff(const Segment &segment)
{
for (unsigned int i = 0; i < m_staffs.size(); ++i) {
if (&(m_staffs[i]->getSegment()) == &segment) return m_staffs[i];
}
return 0;
}
void NotationView::initLayoutToolbar()
{
KToolBar *layoutToolbar = toolBar("Layout Toolbar");
if (!layoutToolbar) {
std::cerr
<< "NotationView::initLayoutToolbar() : layout toolbar not found"
<< std::endl;
return;
}
new QLabel(i18n(" Font: "), layoutToolbar, "font label");
//
// font combo
//
m_fontCombo = new KComboBox(layoutToolbar);
m_fontCombo->setEditable(false);
std::set<std::string> fs(NoteFontFactory::getFontNames());
std::vector<std::string> f(fs.begin(), fs.end());
std::sort(f.begin(), f.end());
bool foundFont = false;
for (std::vector<std::string>::iterator i = f.begin(); i != f.end(); ++i) {
QString fontQName(strtoqstr(*i));
m_fontCombo->insertItem(fontQName);
if (fontQName.lower() == strtoqstr(m_fontName).lower()) {
m_fontCombo->setCurrentItem(m_fontCombo->count() - 1);
foundFont = true;
}
}
if (!foundFont) {
KMessageBox::sorry
(this, i18n("Unknown font \"%1\", using default").arg
(strtoqstr(m_fontName)));
m_fontName = NoteFontFactory::getDefaultFontName();
}
connect(m_fontCombo, SIGNAL(activated(const QString &)),
this, SLOT(slotChangeFont(const QString &)));
new QLabel(i18n(" Size: "), layoutToolbar, "size label");
QString value;
//
// font size combo
//
std::vector<int> sizes = NoteFontFactory::getScreenSizes(m_fontName);
m_fontSizeCombo = new KComboBox(layoutToolbar, "font size combo");
for (std::vector<int>::iterator i = sizes.begin(); i != sizes.end(); ++i) {
value.setNum(*i);
m_fontSizeCombo->insertItem(value);
}
// set combo's current value to default
value.setNum(m_fontSize);
m_fontSizeCombo->setCurrentText(value);
connect(m_fontSizeCombo, SIGNAL(activated(const QString&)),
this, SLOT(slotChangeFontSizeFromStringValue(const QString&)));
new QLabel(i18n(" Spacing: "), layoutToolbar, "spacing label");
//
// spacing combo
//
int defaultSpacing = m_hlayout->getSpacing();
std::vector<int> spacings = NotationHLayout::getAvailableSpacings();
m_spacingCombo = new KComboBox(layoutToolbar, "spacing combo");
for (std::vector<int>::iterator i = spacings.begin(); i != spacings.end(); ++i) {
value.setNum(*i);
value += "%";
m_spacingCombo->insertItem(value);
}
// set combo's current value to default
value.setNum(defaultSpacing); value += "%";
m_spacingCombo->setCurrentText(value);
connect(m_spacingCombo, SIGNAL(activated(const QString&)),
this, SLOT(slotChangeSpacingFromStringValue(const QString&)));
}
void NotationView::initStatusBar()
{
KStatusBar* sb = statusBar();
m_hoveredOverNoteName = new QLabel(sb);
m_hoveredOverNoteName->setMinimumWidth(32);
m_hoveredOverAbsoluteTime = new QLabel(sb);
m_hoveredOverAbsoluteTime->setMinimumWidth(160);
sb->addWidget(m_hoveredOverAbsoluteTime);
sb->addWidget(m_hoveredOverNoteName);
QHBox *hbox = new QHBox(sb);
m_currentNotePixmap = new QLabel(hbox);
m_currentNotePixmap->setMinimumWidth(20);
m_insertModeLabel = new QLabel(hbox);
m_annotationsLabel = new QLabel(hbox);
sb->addWidget(hbox);
sb->insertItem(KTmpStatusMsg::getDefaultMsg(),
KTmpStatusMsg::getDefaultId(), 1);
sb->setItemAlignment(KTmpStatusMsg::getDefaultId(),
AlignLeft | AlignVCenter);
m_selectionCounter = new QLabel(sb);
sb->addWidget(m_selectionCounter);
m_progressBar = new RosegardenProgressBar(100, true, sb);
m_progressBar->setMinimumWidth(100);
sb->addWidget(m_progressBar);
}
QSize NotationView::getViewSize()
{
return canvas()->size();
}
void NotationView::setViewSize(QSize s)
{
canvas()->resize(s.width(), s.height());
}
void
NotationView::setPageMode(LinedStaff::PageMode pageMode)
{
m_pageMode = pageMode;
if (pageMode != LinedStaff::LinearMode) {
if (m_topBarButtons) m_topBarButtons->hide();
if (m_bottomBarButtons) m_bottomBarButtons->hide();
if (m_chordNameRuler) m_chordNameRuler->hide();
if (m_rawNoteRuler) m_rawNoteRuler->hide();
if (m_tempoRuler) m_tempoRuler->hide();
} else {
if (m_topBarButtons) m_topBarButtons->show();
if (m_bottomBarButtons) m_bottomBarButtons->show();
if (m_chordNameRuler && getToggleAction("show_chords_ruler")->isChecked())
m_chordNameRuler->show();
if (m_rawNoteRuler && getToggleAction("show_raw_note_ruler")->isChecked())
m_rawNoteRuler->show();
if (m_tempoRuler && getToggleAction("show_tempo_ruler")->isChecked())
m_tempoRuler->show();
}
stateChanged("linear_mode",
(pageMode == LinedStaff::LinearMode ? KXMLGUIClient::StateNoReverse :
KXMLGUIClient::StateReverse));
int pageWidth = getPageWidth();
int topMargin = 0, leftMargin = 0;
getPageMargins(leftMargin, topMargin);
m_hlayout->setPageMode(pageMode != LinedStaff::LinearMode);
m_hlayout->setPageWidth(pageWidth - leftMargin * 2);
NOTATION_DEBUG << "NotationView::setPageMode: set layout's page width to "
<< (pageWidth - leftMargin * 2) << endl;
positionStaffs();
bool layoutApplied = applyLayout();
if (!layoutApplied) KMessageBox::sorry(0, "Couldn't apply layout");
else {
for (unsigned int i = 0; i < m_staffs.size(); ++i) {
m_staffs[i]->markChanged();
}
}
positionPages();
if (!m_printMode) {
updateView();
slotSetInsertCursorPosition(getInsertionTime(), false, false);
slotSetPointerPosition(getDocument()->getComposition().getPosition(), false);
}
Rosegarden::Profiles::getInstance()->dump();
}
int
NotationView::getPageWidth()
{
if (m_pageMode != LinedStaff::MultiPageMode) {
if (isInPrintMode() && getCanvasView() && getCanvasView()->canvas())
return getCanvasView()->canvas()->width();
if (getCanvasView()) {
return
getCanvasView()->width() -
getCanvasView()->verticalScrollBar()->width() -
m_leftGutter - 10;
}
return width() - 50;
} else {
//!!! For the moment we use A4 for this calculation
double printSizeMm = 25.4 * ((double)m_printSize / 72.0);
double mmPerPixel = printSizeMm / (double)m_notePixmapFactory->getSize();
return (int)(210.0 / mmPerPixel);
}
}
int
NotationView::getPageHeight()
{
if (m_pageMode != LinedStaff::MultiPageMode) {
if (isInPrintMode() && getCanvasView() && getCanvasView()->canvas())
return getCanvasView()->canvas()->height();
if (getCanvasView()) {
return getCanvasView()->height();
}
return (height() > 200 ? height() - 100 : height());
} else {
//!!! For the moment we use A4 for this calculation
double printSizeMm = 25.4 * ((double)m_printSize / 72.0);
double mmPerPixel = printSizeMm / (double)m_notePixmapFactory->getSize();
return (int)(297.0 / mmPerPixel);
}
}
void
NotationView::getPageMargins(int &left, int &top)
{
if (m_pageMode != LinedStaff::MultiPageMode) {
left = 0;
top = 0;
} else {
//!!! For the moment we use A4 for this calculation
double printSizeMm = 25.4 * ((double)m_printSize / 72.0);
double mmPerPixel = printSizeMm / (double)m_notePixmapFactory->getSize();
left = (int)(20.0 / mmPerPixel);
top = (int)(15.0 / mmPerPixel);
}
}
/// Scrolls the view such that the given time is centered
void
NotationView::scrollToTime(timeT t) {
double notationViewLayoutCoord = m_hlayout->getXForTime(t);
// Doesn't appear to matter which staff we use
//!!! actually it probably does matter, if they don't have the same extents
double notationViewCanvasCoord =
getStaff(0)->getCanvasCoordsForLayoutCoords
(notationViewLayoutCoord, 0).first;
// HK: I could have sworn I saw a hard-coded scroll happen somewhere
// (i.e. a default extra scroll to make up for the staff not beginning on
// the left edge) but now I can't find it.
getCanvasView()->slotScrollHorizSmallSteps
(int(notationViewCanvasCoord));// + DEFAULT_STAFF_OFFSET);
}
Rosegarden::RulerScale*
NotationView::getHLayout()
{
return m_hlayout;
}
void
NotationView::paintEvent(QPaintEvent *e)
{
m_inPaintEvent = true;
// This is duplicated here from EditViewBase, because (a) we need
// to know about the segment being removed before we try to check
// the staff names etc., and (b) it's not safe to call close()
// from EditViewBase::paintEvent if we're then going to try to do
// some more work afterwards in this function
if (isCompositionModified()) {
// Check if one of the segments we display has been removed
// from the composition.
//
// For the moment we'll have to close the view if any of the
// segments we handle has been deleted.
for (unsigned int i = 0; i < m_segments.size(); ++i) {
if (!m_segments[i]->getComposition()) {
// oops, I think we've been deleted
close();
return;
}
}
}
int topMargin = 0, leftMargin = 0;
getPageMargins(leftMargin, topMargin);
if (m_pageMode == LinedStaff::ContinuousPageMode) {
// relayout if the window width changes significantly in continuous page mode
int diff = int(getPageWidth() - leftMargin*2 - m_hlayout->getPageWidth());
if (diff < -10 || diff > 10) {
setPageMode(m_pageMode);
refreshSegment(0, 0, 0);
}
} else if (m_pageMode == LinedStaff::LinearMode) {
// resize canvas again if the window height has changed significantly
if (getCanvasView() && getCanvasView()->canvas()) {
int diff = int(getPageHeight() - getCanvasView()->canvas()->height());
if (diff > 10) {
readjustCanvasSize();
}
}
}
// check for staff name changes
for (unsigned int i = 0; i < m_staffs.size(); ++i) {
if (!m_staffs[i]->isStaffNameUpToDate()) {
refreshSegment(0);
break;
}
}
m_inPaintEvent = false;
EditView::paintEvent(e);
m_inPaintEvent = false;
// now deal with any backlog of insertable notes that appeared
// during paint (because it's not safe to modify a segment from
// within a sub-event-loop in a processEvents call from a paint)
if (!m_pendingInsertableNotes.empty()) {
std::vector<std::pair<int, int> > notes = m_pendingInsertableNotes;
m_pendingInsertableNotes.clear();
for (unsigned int i = 0; i < notes.size(); ++i) {
slotInsertableNoteEventReceived(notes[i].first, notes[i].second, true);
}
}
slotSetOperationNameAndStatus(i18n(" Ready."));
}
bool NotationView::applyLayout(int staffNo, timeT startTime, timeT endTime)
{
slotSetOperationNameAndStatus(i18n("Laying out score..."));
RosegardenProgressDialog::processEvents();
m_hlayout->setStaffCount(m_staffs.size());
Rosegarden::Profiler profiler("NotationView::applyLayout");
unsigned int i;
for (i = 0; i < m_staffs.size(); ++i) {
if (staffNo >= 0 && (int)i != staffNo) continue;
slotSetOperationNameAndStatus(i18n("Laying out staff %1...").arg(i + 1));
RosegardenProgressDialog::processEvents();
m_hlayout->resetStaff(*m_staffs[i], startTime, endTime);
m_vlayout->resetStaff(*m_staffs[i], startTime, endTime);
m_hlayout->scanStaff(*m_staffs[i], startTime, endTime);
m_vlayout->scanStaff(*m_staffs[i], startTime, endTime);
}
slotSetOperationNameAndStatus(i18n("Reconciling staffs..."));
RosegardenProgressDialog::processEvents();
m_hlayout->finishLayout(startTime, endTime);
m_vlayout->finishLayout(startTime, endTime);
// find the last finishing staff for future use
timeT lastFinishingStaffEndTime = 0;
bool haveEndTime = false;
m_lastFinishingStaff = -1;
timeT firstStartingStaffStartTime = 0;
bool haveStartTime = false;
int firstStartingStaff = -1;
for (i = 0; i < m_staffs.size(); ++i) {
timeT thisStartTime = m_staffs[i]->getSegment().getStartTime();
if (thisStartTime < firstStartingStaffStartTime || !haveStartTime) {
firstStartingStaffStartTime = thisStartTime;
haveStartTime = true;
firstStartingStaff = i;
}
timeT thisEndTime = m_staffs[i]->getSegment().getEndTime();
if (thisEndTime > lastFinishingStaffEndTime || !haveEndTime) {
lastFinishingStaffEndTime = thisEndTime;
haveEndTime = true;
m_lastFinishingStaff = i;
}
}
readjustCanvasSize();
if (m_topBarButtons) {
m_topBarButtons->update();
}
if (m_bottomBarButtons) {
m_bottomBarButtons->update();
}
if (m_rawNoteRuler && m_rawNoteRuler->isVisible()) {
m_rawNoteRuler->update();
}
return true;
}
void NotationView::setCurrentSelectedNote(const char *pixmapName,
bool rest, Note::Type n, int dots)
{
NoteInserter* inserter = 0;
if (rest)
inserter = dynamic_cast<NoteInserter*>(m_toolBox->getTool(RestInserter::ToolName));
else
inserter = dynamic_cast<NoteInserter*>(m_toolBox->getTool(NoteInserter::ToolName));
inserter->slotSetNote(n);
inserter->slotSetDots(dots);
setTool(inserter);
m_currentNotePixmap->setPixmap
(NotePixmapFactory::toQPixmap(NotePixmapFactory::makeToolbarPixmap(pixmapName)));
emit changeCurrentNote(rest, n);
}
void NotationView::setCurrentSelectedNote(NoteActionData noteAction)
{
setCurrentSelectedNote(noteAction.pixmapName,
noteAction.rest,
noteAction.noteType,
noteAction.dots);
}
void NotationView::setCurrentSelection(EventSelection* s, bool preview,
bool redrawNow)
{
//!!! rather too much here shared with matrixview -- could much of
// this be in editview?
if (m_currentEventSelection == s) return;
NOTATION_DEBUG << "XXX " << endl;
EventSelection *oldSelection = m_currentEventSelection;
m_currentEventSelection = s;
// positionElements is overkill here, but we hope it's not too
// much overkill (if that's not a contradiction)
timeT startA, endA, startB, endB;
if (oldSelection) {
startA = oldSelection->getStartTime();
endA = oldSelection->getEndTime();
startB = s ? s->getStartTime() : startA;
endB = s ? s->getEndTime() : endA;
} else {
// we know they can't both be null -- first thing we tested above
startA = startB = s->getStartTime();
endA = endB = s->getEndTime();
}
// refreshSegment takes start==end to mean refresh everything
if (startA == endA) ++endA;
if (startB == endB) ++endB;
bool updateRequired = true;
// play previews if appropriate -- also permits an optimisation
// for the case where the selection is unchanged (quite likely
// when sweeping)
if (s && preview) {
bool foundNewEvent = false;
for (EventSelection::eventcontainer::iterator i =
s->getSegmentEvents().begin();
i != s->getSegmentEvents().end(); ++i) {
if (oldSelection && oldSelection->getSegment() == s->getSegment()
&& oldSelection->contains(*i)) continue;
foundNewEvent = true;
long pitch;
if (!(*i)->get<Rosegarden::Int>(Rosegarden::BaseProperties::PITCH,
pitch)) continue;
long velocity = -1;
(void)(*i)->get<Rosegarden::Int>(Rosegarden::BaseProperties::VELOCITY,
velocity);
if (!((*i)->has(Rosegarden::BaseProperties::TIED_BACKWARD)&&
(*i)->get<Rosegarden::Bool>
(Rosegarden::BaseProperties::TIED_BACKWARD)))
playNote(s->getSegment(), pitch, velocity);
}
if (!foundNewEvent) {
if (oldSelection &&
oldSelection->getSegment() == s->getSegment() &&
oldSelection->getSegmentEvents().size() ==
s->getSegmentEvents().size()) updateRequired = false;
}
}
if (updateRequired) {
if (!s || !oldSelection ||
(endA >= startB && endB >= startA &&
oldSelection->getSegment() == s->getSegment())) {
// the regions overlap: use their union and just do one refresh
Segment &segment(s ? s->getSegment() :
oldSelection->getSegment());
if (redrawNow) {
// recolour the events now
getStaff(segment)->positionElements(std::min(startA, startB),
std::max(endA, endB));
} else {
// mark refresh status and then request a repaint
segment.getRefreshStatus
(m_segmentsRefreshStatusIds
[getStaff(segment)->getId()]).
push(std::min(startA, startB), std::max(endA, endB));
}
} else {
// do two refreshes, one for each -- here we know neither is null
if (redrawNow) {
// recolour the events now
getStaff(oldSelection->getSegment())->positionElements(startA,
endA);
getStaff(s->getSegment())->positionElements(startB, endB);
} else {
// mark refresh status and then request a repaint
oldSelection->getSegment().getRefreshStatus
(m_segmentsRefreshStatusIds
[getStaff(oldSelection->getSegment())->getId()]).
push(startA, endA);
s->getSegment().getRefreshStatus
(m_segmentsRefreshStatusIds
[getStaff(s->getSegment())->getId()]).
push(startB, endB);
}
}
if (s) {
// make the staff containing the selection current
int staffId = getStaff(s->getSegment())->getId();
if (staffId != m_currentStaff) slotSetCurrentStaff(staffId);
}
}
delete oldSelection;
statusBar()->changeItem(KTmpStatusMsg::getDefaultMsg(),
KTmpStatusMsg::getDefaultId());
if (s) {
int eventsSelected = s->getSegmentEvents().size();
m_selectionCounter->setText
(i18n(" 1 event selected ",
" %n events selected ", eventsSelected));
} else {
m_selectionCounter->setText(i18n(" No selection "));
}
m_selectionCounter->update();
setMenuStates();
if (redrawNow) updateView();
else update();
NOTATION_DEBUG << "XXX " << endl;
}
void NotationView::setSingleSelectedEvent(int staffNo, Event *event,
bool preview, bool redrawNow)
{
setSingleSelectedEvent(getStaff(staffNo)->getSegment(), event,
preview, redrawNow);
}
void NotationView::setSingleSelectedEvent(Segment &segment, Event *event,
bool preview, bool redrawNow)
{
EventSelection *selection = new EventSelection(segment);
selection->addEvent(event);
setCurrentSelection(selection, preview, redrawNow);
}
bool NotationView::canPreviewAnotherNote()
{
static time_t lastCutOff = 0;
static int sinceLastCutOff = 0;
time_t now = time(0);
++sinceLastCutOff;
if ((now - lastCutOff) > 0) {
sinceLastCutOff = 0;
lastCutOff = now;
NOTATION_DEBUG << "NotationView::canPreviewAnotherNote: reset" << endl;
} else {
if (sinceLastCutOff >= 20) {
// don't permit more than 20 notes per second or so, to
// avoid gungeing up the sound drivers
NOTATION_DEBUG << "Rejecting preview (too busy)" << endl;
return false;
}
NOTATION_DEBUG << "NotationView::canPreviewAnotherNote: ok" << endl;
}
return true;
}
void NotationView::playNote(Rosegarden::Segment &s, int pitch, int velocity)
{
Rosegarden::Composition &comp = getDocument()->getComposition();
Rosegarden::Studio &studio = getDocument()->getStudio();
Rosegarden::Track *track = comp.getTrackById(s.getTrack());
Rosegarden::Instrument *ins =
studio.getInstrumentById(track->getInstrument());
// check for null instrument
//
if (ins == 0) return;
if (!canPreviewAnotherNote()) return;
if (velocity < 0) velocity = Rosegarden::MidiMaxValue;
Rosegarden::MappedEvent mE(ins->getId(),
Rosegarden::MappedEvent::MidiNoteOneShot,
pitch + s.getTranspose(),
velocity,
Rosegarden::RealTime::zeroTime,
Rosegarden::RealTime(0, 250000000),
Rosegarden::RealTime::zeroTime);
Rosegarden::StudioControl::sendMappedEvent(mE);
}
void NotationView::showPreviewNote(int staffNo, double layoutX,
int pitch, int height,
const Rosegarden::Note ¬e,
int velocity)
{
m_staffs[staffNo]->showPreviewNote(layoutX, height, note);
playNote(m_staffs[staffNo]->getSegment(), pitch, velocity);
}
void NotationView::clearPreviewNote()
{
for (unsigned int i = 0; i < m_staffs.size(); ++i) {
m_staffs[i]->clearPreviewNote();
}
}
void NotationView::setNotePixmapFactory(NotePixmapFactory* f)
{
delete m_notePixmapFactory;
m_notePixmapFactory = f;
if (m_hlayout) m_hlayout->setNotePixmapFactory(m_notePixmapFactory);
if (m_vlayout) m_vlayout->setNotePixmapFactory(m_notePixmapFactory);
}
NotationCanvasView* NotationView::getCanvasView()
{
return dynamic_cast<NotationCanvasView *>(m_canvasView);
}
Rosegarden::Segment *
NotationView::getCurrentSegment()
{
NotationStaff *staff = getStaff(m_currentStaff);
return (staff ? &staff->getSegment() : 0);
}
Rosegarden::Staff *
NotationView::getCurrentStaff()
{
return getStaff(m_currentStaff);
}
timeT
NotationView::getInsertionTime()
{
return m_insertionTime;
}
timeT
NotationView::getInsertionTime(Rosegarden::Clef &clef,
Rosegarden::Key &key)
{
// This fuss is solely to recover the clef and key: we already
// set m_insertionTime to the right value when we first placed
// the insert cursor. We could get clef and key directly from
// the segment but the staff has a more efficient lookup
NotationStaff *staff = m_staffs[m_currentStaff];
double layoutX = staff->getLayoutXOfInsertCursor();
if (layoutX < 0) layoutX = 0;
Rosegarden::Event *clefEvt = 0, *keyEvt = 0;
(void)staff->getElementUnderLayoutX(layoutX, clefEvt, keyEvt);
if (clefEvt) clef = Rosegarden::Clef(*clefEvt);
else clef = Rosegarden::Clef();
if (keyEvt) key = Rosegarden::Key(*keyEvt);
else key = Rosegarden::Key();
return m_insertionTime;
}
LinedStaff*
NotationView::getStaffForCanvasCoords(int x, int y) const
{
for (unsigned int i = 0; i < m_staffs.size(); ++i) {
NotationStaff *s = m_staffs[i];
// NOTATION_DEBUG << "NotationView::getStaffForCanvasCoords(" << x << "," << y << "): looking at staff " << i << endl;
if (s->containsCanvasCoords(x, y)) {
NotationStaff::LinedStaffCoords coords =
s->getLayoutCoordsForCanvasCoords(x, y);
// NOTATION_DEBUG << "NotationView::getStaffForCanvasCoords(" << x << "," << y << "): layout coords are (" << coords.first << "," << coords.second << ")" << endl;
int barNo = m_hlayout->getBarForX(coords.first);
// NOTATION_DEBUG << "NotationView::getStaffForCanvasCoords(" << x << "," << y << "): bar number " << barNo << endl;
// 931067: < instead of <= in conditional:
if (barNo >= m_hlayout->getFirstVisibleBarOnStaff(*s) &&
barNo < m_hlayout->getLastVisibleBarOnStaff(*s)) {
// NOTATION_DEBUG << "NotationView::getStaffForCanvasCoords(" << x << "," << y << "): it's within range for staff " << i << m_hlayout->getFirstVisibleBarOnStaff(*s) << "->" << m_hlayout->getLastVisibleBarOnStaff(*s) << ", returning true" << endl;
return m_staffs[i];
}
// NOTATION_DEBUG << "NotationView::getStaffForCanvasCoords(" << x << "," << y << "): out of range for this staff " << i << " (" << m_hlayout->getFirstVisibleBarOnStaff(*s) << "->" << m_hlayout->getLastVisibleBarOnStaff(*s) << ")" << endl;
}
}
return 0;
}
void NotationView::updateView()
{
slotCheckRendered
(getCanvasView()->contentsX(),
getCanvasView()->contentsX() + getCanvasView()->visibleWidth());
canvas()->update();
}
void NotationView::print(bool previewOnly)
{
if (m_staffs.size() == 0) {
KMessageBox::error(0, "Nothing to print");
return;
}
Rosegarden::Profiler profiler("NotationView::print");
// We need to be in multi-page mode at this point
int pageWidth = getPageWidth();
int pageHeight = getPageHeight();
int leftMargin = 0, topMargin = 0;
getPageMargins(leftMargin, topMargin);
int maxPageCount = 1;
for (unsigned int i = 0; i < m_staffs.size(); ++i) {
int pageCount = m_staffs[i]->getPageCount();
NOTATION_DEBUG << "NotationView::print(): staff " << i << " reports " << pageCount << " pages " << endl;
if (pageCount > maxPageCount) maxPageCount = pageCount;
}
KPrinter printer(true, QPrinter::HighResolution);
printer.setPageSelection(KPrinter::ApplicationSide);
printer.setMinMax(1, maxPageCount + 1);
if (previewOnly) printer.setPreviewOnly(true);
else if (!printer.setup((QWidget *)parent())) return;
QPaintDeviceMetrics pdm(&printer);
QPainter printpainter(&printer);
// Ideally we should aim to retain the aspect ratio and to move the
// staffs so as to be centred after scaling. But because we haven't
// got around to the latter, let's lose the former too and just
// expand to fit.
// Retain aspect ratio when scaling
// double ratioX = (double)pdm.width() / (double)(pageWidth - leftMargin*2),
// ratioY = (double)pdm.height() / (double)(pageHeight - topMargin*2);
// double ratio = std::min(ratioX, ratioY);
// printpainter.scale(ratio, ratio);
printpainter.scale((double)pdm.width() / (double)(pageWidth - leftMargin*2),
(double)pdm.height() / (double)(pageHeight - topMargin*2));
printpainter.translate(-leftMargin, -topMargin);
QValueList<int> pages = printer.pageList();
for (QValueList<int>::Iterator pli = pages.begin();
pli != pages.end(); ) { // incremented just below
int page = *pli - 1;
++pli;
if (page < 0 || page >= maxPageCount) continue;
NOTATION_DEBUG << "Printing page " << page << endl;
QRect pageRect(m_leftGutter + leftMargin + pageWidth * page,
topMargin,
pageWidth - leftMargin,
pageHeight - topMargin);
for (size_t i = 0; i < m_staffs.size(); ++i) {
NotationStaff *staff = m_staffs[i];
LinedStaff::LinedStaffCoords cc0 = staff->getLayoutCoordsForCanvasCoords
(pageRect.x(), pageRect.y());
LinedStaff::LinedStaffCoords cc1 = staff->getLayoutCoordsForCanvasCoords
(pageRect.x() + pageRect.width(), pageRect.y() + pageRect.height());
timeT t0 = m_hlayout->getTimeForX(cc0.first);
timeT t1 = m_hlayout->getTimeForX(cc1.first);
m_staffs[i]->setPrintPainter(&printpainter);
m_staffs[i]->checkRendered(t0, t1);
}
// Supplying doublebuffer==true to this method appears to
// slow down printing considerably but without it we get
// all sorts of horrible artifacts (possibly related to
// mishandling of pixmap masks?) in qt-3.0. Let's permit
// it as a "hidden" option.
m_config->setGroup(NotationView::ConfigGroup);
NOTATION_DEBUG << "NotationView::print: calling QCanvas::drawArea" << endl;
{
Rosegarden::Profiler profiler("NotationView::print(QCanvas::drawArea)");
if (m_config->readBoolEntry("forcedoublebufferprinting", false)) {
getCanvasView()->canvas()->drawArea(pageRect, &printpainter, true);
} else {
#if QT_VERSION >= 0x030100
getCanvasView()->canvas()->drawArea(pageRect, &printpainter, false);
#else
getCanvasView()->canvas()->drawArea(pageRect, &printpainter, true);
#endif
}
}
NOTATION_DEBUG << "NotationView::print: QCanvas::drawArea done" << endl;
for (size_t i = 0; i < m_staffs.size(); ++i) {
NotationStaff *staff = m_staffs[i];
LinedStaff::LinedStaffCoords cc0 = staff->getLayoutCoordsForCanvasCoords
(pageRect.x(), pageRect.y());
LinedStaff::LinedStaffCoords cc1 = staff->getLayoutCoordsForCanvasCoords
(pageRect.x() + pageRect.width(), pageRect.y() + pageRect.height());
timeT t0 = m_hlayout->getTimeForX(cc0.first);
timeT t1 = m_hlayout->getTimeForX(cc1.first);
m_staffs[i]->renderPrintable(t0, t1);
}
printpainter.translate(-pageWidth, 0);
if (pli != pages.end() && *pli - 1 < maxPageCount) printer.newPage();
for (size_t i = 0; i < m_staffs.size(); ++i) {
m_staffs[i]->markChanged(); // recover any memory used for this page
PixmapArrayGC::deleteAll();
}
}
for (size_t i = 0; i < m_staffs.size(); ++i) {
for (Segment::iterator j = m_staffs[i]->getSegment().begin();
j != m_staffs[i]->getSegment().end(); ++j) {
removeViewLocalProperties(*j);
}
delete m_staffs[i];
}
m_staffs.clear();
printpainter.end();
Rosegarden::Profiles::getInstance()->dump();
}
void
NotationView::updateThumbnails(bool complete)
{
if (m_pageMode != LinedStaff::MultiPageMode) return;
int pageWidth = getPageWidth();
int pageHeight = getPageHeight();
int leftMargin = 0, topMargin = 0;
getPageMargins(leftMargin, topMargin);
int maxPageCount = 1;
for (unsigned int i = 0; i < m_staffs.size(); ++i) {
int pageCount = m_staffs[i]->getPageCount();
if (pageCount > maxPageCount) maxPageCount = pageCount;
}
int thumbScale = 20;
QPixmap thumbnail(canvas()->width() / thumbScale,
canvas()->height() / thumbScale);
thumbnail.fill(Qt::white);
QPainter thumbPainter(&thumbnail);
if (complete) {
thumbPainter.scale(1.0 / double(thumbScale), 1.0 / double(thumbScale));
thumbPainter.setPen(Qt::black);
thumbPainter.setBrush(Qt::white);
/*
QCanvas *canvas = getCanvasView()->canvas();
canvas->drawArea(QRect(0, 0, canvas->width(), canvas->height()),
&thumbPainter, false);
*/
// hide small texts, as we get a crash in Xft when trying to
// render them at this scale
if (m_title) m_title->hide();
if (m_subtitle) m_subtitle->hide();
if (m_composer) m_composer->hide();
if (m_copyright) m_copyright->hide();
for (size_t page = 0; page < maxPageCount; ++page) {
bool havePageNumber = ((m_pageNumbers.size() > page) &&
(m_pageNumbers[page] != 0));
if (havePageNumber) m_pageNumbers[page]->hide();
QRect pageRect(m_leftGutter + leftMargin * 2 + pageWidth * page,
topMargin * 2,
pageWidth - leftMargin*3,
pageHeight - topMargin*3);
QCanvas *canvas = getCanvasView()->canvas();
canvas->drawArea(pageRect, &thumbPainter, false);
if (havePageNumber) m_pageNumbers[page]->show();
}
if (m_title) m_title->show();
if (m_subtitle) m_subtitle->show();
if (m_composer) m_composer->show();
if (m_copyright) m_copyright->show();
} else {
thumbPainter.setPen(Qt::black);
for (int page = 0; page < maxPageCount; ++page) {
int x = m_leftGutter + pageWidth * page + leftMargin/4;
int y = 20;
int w = pageWidth - leftMargin/2;
int h = pageHeight;
QString str = QString("%1").arg(page + 1);
thumbPainter.drawRect(x / thumbScale, y / thumbScale,
w / thumbScale, h / thumbScale);
int tx = (x + w/2) / thumbScale, ty = (y + h/2) / thumbScale;
tx -= thumbPainter.fontMetrics().width(str)/2;
thumbPainter.drawText(tx, ty, str);
}
}
thumbPainter.end();
if (m_pannerDialog) m_pannerDialog->scrollbox()->setThumbnail(thumbnail);
}
void NotationView::refreshSegment(Segment *segment,
timeT startTime, timeT endTime)
{
NOTATION_DEBUG << "*** " << endl;
if (m_inhibitRefresh) return;
NOTATION_DEBUG << "NotationView::refreshSegment(" << segment << "," << startTime << "," << endTime << ")" << endl;
Rosegarden::Profiler foo("NotationView::refreshSegment");
emit usedSelection();
if (segment) {
NotationStaff *staff = getStaff(*segment);
if (staff) applyLayout(staff->getId(), startTime, endTime);
} else {
applyLayout(-1, startTime, endTime);
}
for (unsigned int i = 0; i < m_staffs.size(); ++i) {
Segment *ssegment = &m_staffs[i]->getSegment();
bool thisStaff = (ssegment == segment || segment == 0);
m_staffs[i]->markChanged(startTime, endTime, !thisStaff);
}
PixmapArrayGC::deleteAll();
statusBar()->changeItem(KTmpStatusMsg::getDefaultMsg(),
KTmpStatusMsg::getDefaultId());
Event::dumpStats(std::cerr);
if (m_deferredCursorMove == NoCursorMoveNeeded) {
slotSetInsertCursorPosition(getInsertionTime(), false, false);
} else {
doDeferredCursorMove();
}
slotSetPointerPosition(getDocument()->getComposition().getPosition(), false);
if (m_currentEventSelection &&
m_currentEventSelection->getSegmentEvents().size() == 0) {
delete m_currentEventSelection;
m_currentEventSelection = 0;
//!!!??? was that the right thing to do?
}
setMenuStates();
slotSetOperationNameAndStatus(i18n(" Ready."));
NOTATION_DEBUG << "*** " << endl;
}
void NotationView::setMenuStates()
{
// 1. set selection-related states
// Clear states first, then enter only those ones that apply
// (so as to avoid ever clearing one after entering another, in
// case the two overlap at all)
stateChanged("have_selection", KXMLGUIClient::StateReverse);
stateChanged("have_notes_in_selection", KXMLGUIClient::StateReverse);
stateChanged("have_rests_in_selection", KXMLGUIClient::StateReverse);
if (m_currentEventSelection) {
NOTATION_DEBUG << "NotationView::setMenuStates: Have selection; it's " << m_currentEventSelection << " covering range from " << m_currentEventSelection->getStartTime() << " to " << m_currentEventSelection->getEndTime() << " (" << m_currentEventSelection->getSegmentEvents().size() << " events)" << endl;
stateChanged("have_selection", KXMLGUIClient::StateNoReverse);
if (m_currentEventSelection->contains
(Rosegarden::Note::EventType)) {
stateChanged("have_notes_in_selection",
KXMLGUIClient::StateNoReverse);
}
if (m_currentEventSelection->contains
(Rosegarden::Note::EventRestType)) {
stateChanged("have_rests_in_selection",
KXMLGUIClient::StateNoReverse);
}
}
// 2. set inserter-related states
if (dynamic_cast<NoteInserter *>(m_tool)) {
NOTATION_DEBUG << "Have note inserter " << endl;
stateChanged("note_insert_tool_current", StateNoReverse);
stateChanged("rest_insert_tool_current", StateReverse);
} else if (dynamic_cast<RestInserter *>(m_tool)) {
NOTATION_DEBUG << "Have rest inserter " << endl;
stateChanged("note_insert_tool_current", StateReverse);
stateChanged("rest_insert_tool_current", StateNoReverse);
} else {
NOTATION_DEBUG << "Have neither inserter " << endl;
stateChanged("note_insert_tool_current", StateReverse);
stateChanged("rest_insert_tool_current", StateReverse);
}
}
#define UPDATE_PROGRESS(n) \
progressCount += (n); \
if (progressTotal > 0) { \
emit setProgress(progressCount * 100 / progressTotal); \
RosegardenProgressDialog::processEvents(); \
}
void NotationView::readjustCanvasSize()
{
Rosegarden::Profiler profiler("NotationView::readjustCanvasSize");
double maxWidth = 0.0;
int maxHeight = 0;
slotSetOperationNameAndStatus(i18n("Sizing and allocating canvas..."));
RosegardenProgressDialog::processEvents();
int progressTotal = m_staffs.size() + 2;
int progressCount = 0;
for (unsigned int i = 0; i < m_staffs.size(); ++i) {
NotationStaff &staff = *m_staffs[i];
staff.sizeStaff(*m_hlayout);
UPDATE_PROGRESS(1);
if (staff.getTotalWidth() + staff.getX() > maxWidth) {
maxWidth = staff.getTotalWidth() + staff.getX() + 1;
}
if (staff.getTotalHeight() + staff.getY() > maxHeight) {
maxHeight = staff.getTotalHeight() + staff.getY() + 1;
}
}
int topMargin = 0, leftMargin = 0;
getPageMargins(leftMargin, topMargin);
int pageWidth = getPageWidth();
int pageHeight = getPageHeight();
NOTATION_DEBUG << "NotationView::readjustCanvasSize: maxHeight is "
<< maxHeight << ", page height is " << pageHeight << endl
<< " - maxWidth is " << maxWidth << ", page width is " << pageWidth << endl;
if (m_pageMode == LinedStaff::LinearMode) {
maxWidth = ((maxWidth / pageWidth) + 1) * pageWidth;
if (maxHeight < pageHeight) maxHeight = pageHeight;
} else {
if (maxWidth < pageWidth) maxWidth = pageWidth;
if (maxHeight < pageHeight + topMargin*2)
maxHeight = pageHeight + topMargin*2;
}
// now get the EditView to do the biz
readjustViewSize(QSize(int(maxWidth), maxHeight), true);
UPDATE_PROGRESS(2);
if (m_pannerDialog) {
if (m_pageMode != LinedStaff::MultiPageMode) {
m_pannerDialog->hide();
} else {
m_pannerDialog->show();
m_pannerDialog->setPageSize
(QSize(canvas()->width(),
canvas()->height()));
m_pannerDialog->scrollbox()->setViewSize
(QSize(getCanvasView()->width(),
getCanvasView()->height()));
}
}
}
// Slots: These are here because they use the note action data map
// or mark action data map
void NotationView::slotNoteAction()
{
const QObject* sigSender = sender();
NoteActionDataMap::Iterator noteAct =
m_noteActionDataMap->find(sigSender->name());
if (noteAct != m_noteActionDataMap->end()) {
m_lastNoteAction = sigSender->name();
setCurrentSelectedNote(*noteAct);
setMenuStates();
} else {
std::cerr << "NotationView::slotNoteAction() : couldn't find NoteActionData named '"
<< sigSender->name() << "'\n";
}
}
// Reactivate the last note that was activated
void NotationView::slotLastNoteAction()
{
KAction *action = actionCollection()->action(m_lastNoteAction);
if (!action) action = actionCollection()->action("crotchet");
if (action) {
action->activate();
} else {
std::cerr << "NotationView::slotNoteAction() : couldn't find action named '"
<< m_lastNoteAction << "' or 'crotchet'\n";
}
}
void NotationView::slotAddMark()
{
const QObject *s = sender();
if (!m_currentEventSelection) return;
MarkActionDataMap::Iterator i = m_markActionDataMap->find(s->name());
if (i != m_markActionDataMap->end()) {
addCommandToHistory(new NotesMenuAddMarkCommand
((*i).mark, *m_currentEventSelection));
}
}
void NotationView::slotNoteChangeAction()
{
const QObject* sigSender = sender();
NoteChangeActionDataMap::Iterator noteAct =
m_noteChangeActionDataMap->find(sigSender->name());
if (noteAct != m_noteChangeActionDataMap->end()) {
slotSetNoteDurations((*noteAct).noteType, (*noteAct).notationOnly);
} else {
std::cerr << "NotationView::slotNoteChangeAction() : couldn't find NoteChangeAction named '"
<< sigSender->name() << "'\n";
}
}
void NotationView::initActionDataMaps()
{
static bool called = false;
static int keys[] =
{ Key_0, Key_3, Key_6, Key_8, Key_4, Key_2, Key_1, Key_5 };
if (called) return;
called = true;
m_noteActionDataMap = new NoteActionDataMap;
for (int rest = 0; rest < 2; ++rest) {
for (int dots = 0; dots < 2; ++dots) {
for (int type = Note::Longest; type >= Note::Shortest; --type) {
if (dots && (type == Note::Longest)) continue;
QString refName
(NotationStrings::getReferenceName(Note(type, dots), rest == 1));
QString shortName(refName);
shortName.replace(QRegExp("-"), "_");
QString titleName
(NotationStrings::getNoteName(Note(type, dots)));
titleName = titleName.left(1).upper() +
titleName.right(titleName.length()-1);
if (rest) {
titleName.replace(QRegExp(i18n("note")), i18n("rest"));
}
int keycode = keys[type - Note::Shortest];
if (dots) // keycode += CTRL; -- used below for note change action
keycode = 0;
if (rest) // keycode += SHIFT; -- can't do shift+numbers
keycode = 0;
m_noteActionDataMap->insert
(shortName, NoteActionData
(titleName, shortName, refName, keycode,
rest > 0, type, dots));
}
}
}
m_noteChangeActionDataMap = new NoteChangeActionDataMap;
for (int notationOnly = 0; notationOnly <= 1; ++notationOnly) {
for (int type = Note::Longest; type >= Note::Shortest; --type) {
QString refName
(NotationStrings::getReferenceName(Note(type, 0), false));
QString shortName(QString("change_%1%2")
.arg(notationOnly ? "notation_" : "").arg(refName));
shortName.replace(QRegExp("-"), "_");
QString titleName
(NotationStrings::getNoteName(Note(type, 0)));
titleName = titleName.left(1).upper() +
titleName.right(titleName.length()-1);
int keycode = keys[type - Note::Shortest];
keycode += CTRL;
if (notationOnly) keycode += ALT;
m_noteChangeActionDataMap->insert
(shortName, NoteChangeActionData
(titleName, shortName, refName, keycode,
notationOnly ? true : false, type));
}
}
m_markActionDataMap = new MarkActionDataMap;
std::vector<Mark> marks = Rosegarden::Marks::getStandardMarks();
for (unsigned int i = 0; i < marks.size(); ++i) {
Mark mark = marks[i];
QString markName(strtoqstr(mark));
QString actionName = QString("add_%1").arg(markName);
m_markActionDataMap->insert
(actionName, MarkActionData
(NotesMenuAddMarkCommand::getGlobalName(mark),
actionName, 0, mark));
}
}
void NotationView::setupProgress(KProgress* bar)
{
if (bar) {
NOTATION_DEBUG << "NotationView::setupProgress(bar)\n";
connect(m_hlayout, SIGNAL(setProgress(int)),
bar, SLOT(setValue(int)));
connect(m_hlayout, SIGNAL(incrementProgress(int)),
bar, SLOT(advance(int)));
connect(this, SIGNAL(setProgress(int)),
bar, SLOT(setValue(int)));
connect(this, SIGNAL(incrementProgress(int)),
bar, SLOT(advance(int)));
for (unsigned int i = 0; i < m_staffs.size(); ++i) {
connect(m_staffs[i], SIGNAL(setProgress(int)),
bar, SLOT(setValue(int)));
connect(m_staffs[i], SIGNAL(incrementProgress(int)),
bar, SLOT(advance(int)));
}
}
}
void NotationView::setupProgress(RosegardenProgressDialog* dialog)
{
NOTATION_DEBUG << "NotationView::setupProgress(dialog)" << endl;
disconnectProgress();
if (dialog) {
setupProgress(dialog->progressBar());
connect(dialog, SIGNAL(cancelClicked()),
m_hlayout, SLOT(slotCancel()));
for (unsigned int i = 0; i < m_staffs.size(); ++i) {
connect(m_staffs[i], SIGNAL(setOperationName(QString)),
this, SLOT(slotSetOperationNameAndStatus(QString)));
connect(dialog, SIGNAL(cancelClicked()),
m_staffs[i], SLOT(slotCancel()));
}
connect(this, SIGNAL(setOperationName(QString)),
dialog, SLOT(slotSetOperationName(QString)));
m_progressDisplayer = PROGRESS_DIALOG;
}
}
void NotationView::slotSetOperationNameAndStatus(QString name)
{
emit setOperationName(name);
statusBar()->changeItem(QString(" %1").arg(name),
KTmpStatusMsg::getDefaultId());
}
void NotationView::disconnectProgress()
{
NOTATION_DEBUG << "NotationView::disconnectProgress()" << endl;
m_hlayout->disconnect();
disconnect(SIGNAL(setProgress(int)));
disconnect(SIGNAL(incrementProgress(int)));
disconnect(SIGNAL(setOperationName(QString)));
for (unsigned int i = 0; i < m_staffs.size(); ++i) {
m_staffs[i]->disconnect();
}
}
void NotationView::setupDefaultProgress()
{
if (m_progressDisplayer != PROGRESS_BAR) {
NOTATION_DEBUG << "NotationView::setupDefaultProgress()" << endl;
disconnectProgress();
setupProgress(m_progressBar);
m_progressDisplayer = PROGRESS_BAR;
}
}
void NotationView::updateViewCaption()
{
if (m_segments.size() == 1) {
Rosegarden::TrackId trackId = m_segments[0]->getTrack();
Rosegarden::Track *track =
m_segments[0]->getComposition()->getTrackById(trackId);
int trackPosition = -1;
if (track) trackPosition = track->getPosition();
setCaption(i18n("%1 - Segment Track #%2 - Notation")
.arg(getDocument()->getTitle())
.arg(trackPosition + 1));
} else if (m_segments.size() == getDocument()->getComposition().getNbSegments()) {
setCaption(i18n("%1 - All Segments - Notation")
.arg(getDocument()->getTitle()));
} else {
setCaption(i18n("%1 - %2 Segments - Notation")
.arg(getDocument()->getTitle())
.arg(m_segments.size()));
}
}
NotationView::NoteActionDataMap* NotationView::m_noteActionDataMap = 0;
NotationView::NoteChangeActionDataMap* NotationView::m_noteChangeActionDataMap = 0;
NotationView::MarkActionDataMap* NotationView::m_markActionDataMap = 0;
const char* const NotationView::ConfigGroup = "Notation Options";
|