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 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 4288 4289 4290 4291 4292 4293 4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305 4306 4307 4308 4309 4310 4311 4312 4313 4314 4315 4316 4317 4318 4319 4320 4321 4322 4323 4324 4325 4326 4327 4328 4329 4330 4331 4332 4333 4334 4335 4336 4337 4338 4339 4340 4341 4342 4343 4344 4345 4346 4347 4348 4349 4350 4351 4352 4353 4354 4355 4356 4357 4358 4359 4360 4361 4362 4363 4364 4365 4366 4367 4368 4369 4370 4371 4372 4373 4374 4375 4376 4377 4378 4379 4380 4381 4382 4383 4384 4385 4386 4387 4388 4389 4390 4391 4392 4393 4394 4395 4396 4397 4398 4399 4400 4401 4402 4403 4404 4405 4406 4407 4408 4409 4410 4411 4412 4413 4414 4415 4416 4417 4418 4419 4420 4421 4422 4423 4424 4425 4426 4427 4428 4429 4430 4431 4432 4433 4434 4435 4436 4437 4438 4439 4440 4441 4442 4443 4444 4445 4446 4447 4448 4449 4450 4451 4452 4453 4454 4455 4456 4457 4458 4459 4460 4461 4462 4463 4464 4465 4466 4467 4468 4469 4470 4471 4472 4473 4474 4475 4476 4477 4478 4479 4480 4481 4482 4483 4484 4485 4486 4487 4488 4489 4490 4491 4492 4493 4494 4495 4496 4497 4498 4499 4500 4501 4502 4503 4504 4505 4506 4507 4508 4509 4510 4511 4512 4513 4514 4515 4516 4517 4518 4519 4520 4521 4522 4523 4524 4525 4526 4527 4528 4529 4530 4531 4532 4533 4534 4535 4536 4537 4538 4539 4540 4541 4542 4543 4544 4545 4546 4547 4548 4549 4550 4551 4552 4553 4554 4555 4556 4557 4558 4559 4560 4561 4562 4563 4564 4565 4566 4567 4568 4569 4570 4571 4572 4573 4574 4575 4576 4577 4578 4579 4580 4581 4582 4583 4584 4585 4586 4587 4588 4589 4590 4591 4592 4593 4594 4595 4596 4597 4598 4599 4600 4601 4602 4603 4604 4605 4606 4607 4608 4609 4610 4611 4612 4613 4614 4615 4616 4617 4618 4619 4620 4621 4622 4623 4624 4625 4626 4627 4628 4629 4630 4631 4632 4633 4634 4635 4636 4637 4638 4639 4640 4641 4642 4643 4644 4645 4646 4647 4648 4649 4650 4651 4652 4653 4654 4655 4656 4657 4658 4659 4660 4661 4662 4663 4664 4665 4666 4667 4668 4669 4670 4671 4672 4673 4674 4675 4676 4677 4678 4679 4680 4681 4682 4683 4684 4685 4686 4687 4688 4689 4690 4691 4692 4693 4694 4695 4696 4697 4698 4699 4700 4701 4702 4703 4704 4705 4706 4707 4708 4709 4710 4711 4712 4713 4714 4715 4716 4717 4718 4719 4720 4721 4722 4723 4724 4725 4726 4727 4728 4729 4730 4731 4732 4733 4734 4735 4736 4737 4738 4739 4740 4741 4742 4743 4744 4745 4746 4747 4748 4749 4750 4751 4752 4753 4754 4755 4756 4757 4758 4759 4760 4761 4762 4763 4764 4765 4766 4767 4768 4769 4770 4771 4772 4773 4774 4775 4776 4777 4778 4779 4780 4781 4782 4783 4784 4785 4786 4787 4788 4789 4790 4791 4792 4793 4794 4795 4796 4797 4798 4799 4800 4801 4802 4803 4804 4805 4806 4807 4808 4809 4810 4811 4812 4813 4814 4815 4816 4817 4818 4819 4820 4821 4822 4823 4824 4825 4826 4827 4828 4829 4830 4831 4832 4833 4834 4835 4836 4837 4838 4839 4840 4841 4842 4843 4844 4845 4846 4847 4848 4849 4850 4851 4852 4853 4854 4855 4856 4857 4858 4859 4860 4861 4862 4863 4864 4865 4866 4867 4868 4869 4870 4871 4872 4873 4874 4875 4876 4877 4878 4879 4880 4881 4882 4883 4884 4885 4886 4887 4888 4889 4890 4891 4892 4893 4894 4895 4896 4897 4898 4899 4900 4901 4902 4903 4904 4905 4906 4907 4908 4909 4910 4911 4912 4913 4914 4915 4916 4917 4918 4919 4920 4921 4922 4923 4924 4925 4926 4927 4928 4929 4930 4931 4932 4933 4934 4935 4936 4937 4938 4939 4940 4941 4942 4943 4944 4945 4946 4947 4948 4949 4950 4951 4952 4953 4954 4955 4956 4957 4958 4959 4960 4961 4962 4963 4964 4965 4966 4967 4968 4969 4970 4971 4972 4973 4974 4975 4976 4977 4978 4979 4980 4981 4982 4983 4984 4985 4986 4987 4988 4989 4990 4991 4992 4993 4994 4995 4996 4997 4998 4999 5000 5001 5002 5003 5004 5005 5006 5007 5008 5009 5010 5011 5012 5013 5014 5015 5016 5017 5018 5019 5020 5021 5022 5023 5024 5025 5026 5027 5028 5029 5030 5031 5032 5033 5034 5035 5036 5037 5038 5039 5040 5041 5042 5043 5044 5045 5046 5047 5048 5049 5050 5051 5052 5053 5054 5055 5056 5057 5058 5059 5060 5061 5062 5063 5064 5065 5066 5067 5068 5069 5070 5071 5072 5073 5074 5075 5076 5077 5078 5079 5080 5081 5082 5083 5084 5085 5086 5087 5088 5089 5090 5091 5092 5093 5094 5095 5096 5097 5098 5099 5100 5101 5102 5103 5104 5105 5106 5107 5108 5109 5110 5111 5112 5113 5114 5115 5116 5117 5118 5119 5120 5121 5122 5123 5124 5125 5126 5127 5128 5129 5130 5131 5132 5133 5134 5135 5136 5137 5138 5139 5140 5141 5142 5143 5144 5145 5146 5147 5148 5149 5150 5151 5152 5153 5154 5155 5156 5157 5158 5159 5160 5161 5162 5163 5164 5165 5166 5167 5168 5169 5170 5171 5172 5173 5174 5175 5176 5177 5178 5179 5180 5181 5182 5183 5184 5185 5186 5187 5188 5189 5190 5191 5192 5193 5194 5195 5196 5197 5198 5199 5200 5201 5202 5203 5204 5205 5206 5207 5208 5209 5210 5211 5212 5213 5214 5215 5216 5217 5218 5219 5220 5221 5222 5223 5224 5225 5226 5227 5228 5229 5230 5231 5232 5233 5234 5235 5236 5237 5238 5239 5240 5241 5242 5243 5244 5245 5246 5247 5248 5249 5250 5251 5252 5253 5254 5255 5256 5257 5258 5259 5260 5261 5262 5263 5264 5265 5266 5267 5268 5269 5270 5271 5272 5273 5274 5275 5276 5277 5278 5279 5280 5281 5282 5283 5284 5285 5286 5287 5288 5289 5290 5291 5292 5293 5294 5295 5296 5297 5298 5299 5300 5301 5302 5303 5304 5305 5306 5307 5308 5309 5310 5311 5312 5313 5314 5315 5316 5317 5318 5319 5320 5321 5322 5323 5324 5325 5326 5327 5328 5329 5330 5331 5332 5333 5334 5335 5336 5337 5338 5339 5340 5341 5342 5343 5344 5345 5346 5347 5348 5349 5350 5351 5352 5353 5354 5355 5356 5357 5358 5359 5360 5361 5362 5363 5364 5365 5366 5367 5368 5369 5370 5371 5372 5373 5374 5375 5376 5377 5378 5379 5380 5381 5382 5383 5384 5385 5386 5387 5388 5389 5390 5391 5392 5393 5394 5395 5396 5397 5398 5399 5400 5401 5402 5403 5404 5405 5406 5407 5408 5409 5410 5411 5412 5413 5414 5415 5416 5417 5418 5419 5420 5421 5422 5423 5424 5425 5426 5427 5428 5429 5430 5431 5432 5433 5434 5435 5436 5437 5438 5439 5440 5441 5442 5443 5444 5445 5446 5447 5448 5449 5450 5451 5452 5453 5454 5455 5456 5457 5458 5459 5460 5461 5462 5463 5464 5465 5466 5467 5468 5469 5470 5471 5472 5473 5474 5475 5476 5477 5478 5479 5480 5481 5482 5483 5484 5485 5486 5487 5488 5489 5490 5491 5492 5493 5494 5495 5496 5497 5498 5499 5500 5501 5502 5503 5504 5505 5506 5507 5508 5509 5510 5511 5512 5513 5514 5515 5516 5517 5518 5519 5520 5521 5522 5523 5524 5525 5526 5527 5528 5529 5530 5531 5532 5533 5534 5535 5536 5537 5538 5539 5540 5541 5542 5543 5544 5545 5546 5547 5548 5549 5550 5551 5552 5553 5554 5555 5556 5557 5558 5559 5560 5561 5562 5563 5564 5565 5566 5567 5568 5569 5570 5571 5572 5573 5574 5575 5576 5577 5578 5579 5580 5581 5582 5583 5584 5585 5586 5587 5588 5589 5590 5591 5592 5593 5594 5595 5596 5597 5598 5599 5600 5601 5602 5603 5604 5605 5606 5607 5608 5609 5610 5611 5612 5613 5614 5615 5616 5617 5618 5619 5620 5621 5622 5623 5624 5625 5626 5627 5628 5629 5630 5631 5632 5633 5634 5635 5636 5637 5638 5639 5640 5641 5642 5643 5644 5645 5646 5647 5648 5649 5650 5651 5652 5653 5654 5655 5656 5657 5658 5659 5660 5661 5662 5663 5664 5665 5666 5667 5668 5669 5670 5671 5672 5673 5674 5675 5676 5677 5678 5679 5680 5681 5682 5683 5684 5685 5686 5687 5688 5689 5690 5691 5692 5693 5694 5695 5696 5697 5698 5699 5700 5701 5702 5703 5704 5705 5706 5707 5708 5709 5710 5711 5712 5713 5714 5715 5716 5717 5718 5719 5720 5721 5722 5723 5724 5725 5726 5727 5728 5729 5730 5731 5732 5733 5734 5735 5736 5737 5738 5739 5740 5741 5742 5743 5744 5745 5746 5747 5748 5749 5750 5751 5752 5753 5754 5755 5756 5757 5758 5759 5760 5761 5762 5763 5764 5765 5766 5767 5768 5769 5770 5771 5772 5773 5774 5775 5776 5777 5778 5779 5780 5781 5782 5783 5784 5785 5786 5787 5788 5789 5790 5791 5792 5793 5794 5795 5796 5797 5798 5799 5800 5801 5802 5803 5804 5805 5806 5807 5808 5809 5810 5811 5812 5813 5814 5815 5816 5817 5818 5819 5820 5821 5822 5823 5824 5825 5826 5827 5828 5829 5830 5831 5832 5833 5834 5835 5836 5837 5838 5839 5840 5841 5842 5843 5844 5845 5846 5847 5848 5849 5850 5851 5852 5853 5854 5855 5856 5857 5858 5859 5860 5861 5862 5863 5864 5865 5866 5867 5868 5869 5870 5871 5872 5873 5874 5875 5876 5877 5878 5879 5880 5881 5882 5883 5884 5885 5886 5887 5888 5889 5890 5891 5892 5893 5894 5895 5896 5897 5898 5899 5900 5901 5902 5903 5904 5905 5906 5907 5908 5909 5910 5911 5912 5913 5914 5915 5916 5917 5918 5919 5920 5921 5922 5923 5924 5925 5926 5927 5928 5929 5930 5931 5932 5933 5934 5935 5936 5937 5938 5939 5940 5941 5942 5943 5944 5945 5946 5947 5948 5949 5950 5951 5952 5953 5954 5955 5956 5957 5958 5959 5960 5961 5962 5963 5964 5965 5966 5967 5968 5969 5970 5971 5972 5973 5974 5975 5976 5977 5978 5979 5980 5981 5982 5983 5984 5985 5986 5987 5988 5989 5990 5991 5992 5993 5994 5995 5996 5997 5998 5999 6000 6001 6002 6003 6004 6005 6006 6007 6008 6009 6010 6011 6012 6013 6014 6015 6016 6017 6018 6019 6020 6021 6022 6023 6024 6025 6026 6027 6028 6029 6030 6031 6032 6033 6034 6035 6036 6037 6038 6039 6040 6041 6042 6043 6044 6045 6046 6047 6048 6049 6050 6051 6052 6053 6054 6055 6056 6057 6058 6059 6060 6061 6062 6063 6064 6065 6066 6067 6068 6069 6070 6071 6072 6073 6074 6075 6076 6077 6078 6079 6080 6081 6082 6083 6084 6085 6086 6087 6088 6089 6090 6091 6092 6093 6094 6095 6096 6097 6098 6099 6100 6101 6102 6103 6104 6105 6106 6107 6108 6109 6110 6111 6112 6113 6114 6115 6116 6117 6118 6119 6120 6121 6122 6123 6124 6125 6126 6127 6128 6129 6130 6131 6132 6133 6134 6135 6136 6137 6138 6139 6140 6141 6142 6143 6144 6145 6146 6147 6148 6149 6150 6151 6152 6153 6154 6155 6156 6157 6158 6159 6160 6161 6162 6163 6164 6165 6166 6167 6168 6169 6170 6171 6172 6173 6174 6175 6176 6177 6178 6179 6180 6181 6182 6183 6184 6185 6186 6187 6188 6189 6190 6191 6192 6193 6194 6195 6196 6197 6198 6199 6200 6201 6202 6203 6204 6205 6206 6207 6208 6209 6210 6211 6212 6213 6214 6215 6216 6217 6218 6219 6220 6221 6222 6223 6224 6225 6226 6227 6228 6229 6230 6231 6232 6233 6234 6235 6236 6237 6238 6239 6240 6241 6242 6243 6244 6245 6246 6247 6248 6249 6250 6251 6252 6253 6254 6255 6256 6257 6258 6259 6260 6261 6262 6263 6264 6265 6266 6267 6268 6269 6270 6271 6272 6273 6274 6275 6276 6277 6278 6279 6280 6281 6282 6283 6284 6285 6286 6287 6288 6289 6290 6291 6292 6293 6294 6295 6296 6297 6298 6299 6300 6301 6302 6303 6304 6305 6306 6307 6308 6309 6310 6311 6312 6313 6314 6315 6316 6317 6318 6319 6320 6321 6322 6323 6324 6325 6326 6327 6328 6329 6330 6331 6332 6333 6334 6335 6336 6337 6338 6339 6340 6341 6342 6343 6344 6345 6346 6347 6348 6349 6350 6351 6352 6353 6354 6355 6356 6357 6358 6359 6360 6361 6362 6363 6364 6365 6366 6367 6368 6369 6370 6371 6372 6373 6374 6375 6376 6377 6378 6379 6380 6381 6382 6383 6384 6385 6386 6387 6388 6389 6390 6391 6392 6393 6394 6395 6396 6397 6398 6399 6400 6401 6402 6403 6404 6405 6406 6407 6408 6409 6410 6411 6412 6413 6414 6415 6416 6417 6418 6419 6420 6421 6422 6423 6424 6425 6426 6427 6428 6429 6430 6431 6432 6433 6434 6435 6436 6437 6438 6439 6440 6441 6442 6443 6444 6445 6446 6447 6448 6449 6450 6451 6452 6453 6454 6455 6456 6457 6458 6459 6460 6461 6462 6463 6464 6465 6466 6467 6468 6469 6470 6471 6472 6473 6474 6475 6476 6477 6478 6479 6480 6481 6482 6483 6484 6485 6486 6487 6488 6489 6490 6491 6492 6493 6494 6495 6496 6497 6498 6499 6500 6501 6502 6503 6504 6505 6506 6507 6508 6509 6510 6511 6512 6513 6514 6515 6516 6517 6518 6519 6520 6521 6522 6523 6524 6525 6526 6527 6528 6529 6530 6531 6532 6533 6534 6535 6536 6537 6538 6539 6540 6541 6542 6543 6544 6545 6546 6547 6548 6549 6550 6551 6552 6553 6554 6555 6556 6557 6558 6559 6560 6561 6562 6563 6564 6565 6566 6567 6568 6569 6570 6571 6572 6573 6574 6575 6576 6577 6578 6579 6580 6581 6582 6583 6584 6585 6586 6587 6588 6589 6590 6591 6592 6593 6594 6595 6596 6597 6598 6599 6600 6601 6602 6603 6604 6605 6606 6607 6608 6609 6610 6611 6612 6613 6614 6615 6616 6617 6618 6619 6620 6621 6622 6623 6624 6625 6626 6627 6628 6629 6630 6631 6632 6633 6634 6635 6636 6637 6638 6639 6640 6641 6642 6643 6644 6645 6646 6647 6648 6649 6650 6651 6652 6653 6654 6655 6656 6657 6658 6659 6660 6661 6662 6663 6664 6665 6666 6667 6668 6669 6670 6671 6672 6673 6674 6675 6676 6677 6678 6679 6680 6681 6682 6683 6684 6685 6686 6687 6688 6689 6690 6691 6692 6693 6694 6695 6696 6697 6698 6699 6700 6701 6702 6703 6704 6705 6706 6707 6708 6709 6710 6711 6712 6713 6714 6715 6716 6717 6718 6719 6720 6721 6722 6723 6724 6725 6726 6727 6728 6729 6730 6731 6732 6733 6734 6735 6736 6737 6738 6739 6740 6741 6742 6743 6744 6745 6746 6747 6748 6749 6750 6751 6752 6753 6754 6755 6756 6757 6758 6759 6760 6761 6762 6763 6764 6765 6766 6767 6768 6769 6770 6771 6772 6773 6774 6775 6776 6777 6778 6779 6780 6781 6782 6783 6784 6785 6786 6787 6788 6789 6790 6791 6792 6793 6794 6795 6796 6797 6798 6799 6800 6801 6802 6803 6804 6805 6806 6807 6808 6809 6810 6811 6812 6813 6814 6815 6816 6817 6818 6819 6820 6821 6822 6823 6824 6825 6826 6827 6828 6829 6830 6831 6832 6833 6834 6835 6836 6837 6838 6839 6840 6841 6842 6843 6844 6845 6846 6847 6848 6849 6850 6851 6852 6853 6854 6855 6856 6857 6858 6859 6860 6861 6862 6863 6864 6865 6866 6867 6868 6869 6870 6871 6872 6873 6874 6875 6876 6877 6878 6879 6880 6881 6882 6883 6884 6885 6886 6887 6888 6889 6890 6891 6892 6893 6894 6895 6896 6897 6898 6899 6900 6901 6902 6903 6904 6905 6906 6907 6908 6909 6910 6911 6912 6913 6914 6915 6916 6917 6918 6919 6920 6921 6922 6923 6924 6925 6926 6927 6928 6929 6930 6931 6932 6933 6934 6935 6936 6937 6938 6939 6940 6941 6942 6943 6944 6945 6946 6947 6948 6949 6950 6951 6952 6953 6954 6955 6956 6957 6958 6959 6960 6961 6962 6963 6964 6965 6966 6967 6968 6969 6970 6971 6972 6973 6974 6975 6976 6977 6978 6979 6980 6981 6982 6983 6984 6985 6986 6987 6988 6989 6990 6991 6992 6993 6994 6995 6996 6997 6998 6999 7000 7001 7002 7003 7004 7005 7006 7007 7008 7009 7010 7011 7012 7013 7014 7015 7016 7017 7018 7019 7020 7021 7022 7023 7024 7025 7026 7027 7028 7029 7030 7031 7032 7033 7034 7035 7036 7037 7038 7039 7040 7041 7042 7043 7044 7045 7046 7047 7048 7049 7050 7051 7052 7053 7054 7055 7056 7057 7058 7059 7060 7061 7062 7063 7064 7065 7066 7067 7068 7069 7070 7071 7072 7073 7074 7075 7076 7077 7078 7079 7080 7081 7082 7083 7084 7085 7086 7087 7088 7089 7090 7091 7092 7093 7094 7095 7096 7097 7098 7099 7100 7101 7102 7103 7104 7105 7106 7107 7108 7109 7110 7111 7112 7113 7114 7115 7116 7117 7118 7119 7120 7121 7122 7123 7124 7125 7126 7127 7128 7129 7130 7131 7132 7133 7134 7135 7136 7137 7138 7139 7140 7141 7142 7143 7144 7145 7146 7147 7148 7149 7150 7151 7152 7153 7154 7155 7156 7157 7158 7159 7160 7161 7162 7163 7164 7165 7166 7167 7168 7169 7170 7171 7172 7173 7174 7175 7176 7177 7178 7179 7180 7181 7182 7183 7184 7185 7186 7187 7188 7189 7190 7191 7192 7193 7194 7195 7196 7197 7198 7199 7200 7201 7202 7203 7204 7205 7206 7207 7208 7209 7210 7211 7212 7213 7214 7215 7216 7217 7218 7219 7220 7221 7222 7223 7224 7225 7226 7227 7228 7229 7230 7231 7232 7233 7234 7235 7236 7237 7238 7239 7240 7241 7242 7243 7244 7245 7246 7247 7248 7249 7250 7251 7252 7253 7254 7255 7256 7257 7258 7259 7260 7261 7262 7263 7264 7265 7266 7267 7268 7269 7270 7271 7272 7273 7274 7275 7276 7277 7278 7279 7280 7281 7282 7283 7284 7285 7286 7287 7288 7289 7290 7291 7292 7293 7294 7295 7296 7297 7298 7299 7300 7301 7302 7303 7304 7305 7306 7307 7308 7309 7310 7311 7312 7313 7314 7315 7316 7317 7318 7319 7320 7321 7322 7323 7324 7325 7326 7327 7328 7329 7330 7331 7332 7333 7334 7335 7336 7337 7338 7339 7340 7341 7342 7343 7344 7345 7346 7347 7348 7349 7350 7351 7352 7353 7354 7355 7356 7357 7358 7359 7360 7361 7362 7363 7364 7365 7366 7367 7368 7369 7370 7371 7372 7373 7374 7375 7376 7377 7378 7379 7380 7381 7382 7383 7384 7385 7386 7387 7388 7389 7390 7391 7392 7393 7394 7395 7396 7397 7398 7399 7400 7401 7402 7403 7404 7405 7406 7407 7408 7409 7410 7411 7412 7413 7414 7415 7416 7417 7418 7419 7420 7421 7422 7423 7424 7425 7426 7427 7428 7429 7430 7431 7432 7433 7434 7435 7436 7437 7438 7439 7440 7441 7442 7443 7444 7445 7446 7447 7448 7449 7450 7451 7452 7453 7454 7455 7456 7457 7458 7459 7460 7461 7462 7463 7464 7465 7466 7467 7468 7469 7470 7471 7472 7473 7474 7475 7476 7477 7478 7479 7480 7481 7482 7483 7484 7485 7486 7487 7488 7489 7490 7491 7492 7493 7494 7495 7496 7497 7498 7499 7500 7501 7502 7503 7504 7505 7506 7507 7508 7509 7510 7511 7512 7513 7514 7515 7516 7517 7518 7519 7520 7521 7522 7523 7524 7525 7526 7527 7528 7529 7530 7531 7532 7533 7534 7535 7536 7537 7538 7539 7540 7541 7542 7543 7544 7545 7546 7547 7548 7549 7550 7551 7552 7553 7554 7555 7556 7557 7558 7559 7560 7561 7562 7563 7564 7565 7566 7567 7568 7569 7570 7571 7572 7573 7574 7575 7576 7577 7578 7579 7580 7581 7582 7583 7584 7585 7586 7587 7588 7589 7590 7591 7592 7593 7594 7595 7596 7597 7598 7599 7600 7601 7602 7603 7604 7605 7606 7607 7608 7609 7610 7611 7612 7613 7614 7615 7616 7617 7618 7619 7620 7621 7622 7623 7624 7625 7626 7627 7628 7629 7630 7631 7632 7633 7634 7635 7636 7637 7638 7639 7640 7641 7642 7643 7644 7645 7646 7647 7648 7649 7650 7651 7652 7653 7654 7655 7656 7657 7658 7659 7660 7661 7662 7663 7664 7665 7666 7667 7668 7669 7670 7671 7672 7673 7674 7675 7676 7677 7678 7679 7680 7681 7682 7683 7684 7685 7686 7687 7688 7689 7690 7691 7692 7693 7694 7695 7696 7697 7698 7699 7700 7701 7702 7703 7704 7705 7706 7707 7708 7709 7710 7711 7712 7713 7714 7715 7716 7717 7718 7719 7720 7721 7722 7723 7724 7725 7726 7727 7728 7729 7730 7731 7732 7733 7734 7735 7736 7737 7738 7739 7740 7741 7742 7743 7744 7745 7746 7747 7748 7749 7750 7751 7752 7753 7754 7755 7756 7757 7758 7759 7760 7761 7762 7763 7764 7765 7766 7767 7768 7769 7770 7771 7772 7773 7774 7775 7776 7777 7778 7779 7780 7781 7782 7783 7784 7785 7786 7787 7788 7789 7790 7791 7792 7793 7794 7795 7796 7797 7798 7799 7800 7801 7802 7803 7804 7805 7806 7807 7808 7809 7810 7811 7812 7813 7814 7815 7816 7817 7818 7819 7820 7821 7822 7823 7824 7825 7826 7827 7828 7829 7830 7831 7832 7833 7834 7835 7836 7837 7838 7839 7840 7841 7842 7843 7844 7845 7846 7847 7848 7849 7850 7851 7852 7853 7854 7855 7856 7857 7858 7859 7860 7861 7862 7863 7864 7865 7866 7867 7868 7869 7870 7871 7872 7873 7874 7875 7876 7877 7878 7879 7880 7881 7882 7883 7884 7885 7886 7887 7888 7889 7890 7891 7892 7893 7894 7895 7896 7897 7898 7899 7900 7901 7902 7903 7904 7905 7906 7907 7908 7909 7910 7911 7912 7913 7914 7915 7916 7917 7918 7919 7920 7921 7922 7923 7924 7925 7926 7927 7928 7929 7930 7931 7932 7933 7934 7935 7936 7937 7938 7939 7940 7941 7942 7943 7944 7945 7946 7947 7948 7949 7950 7951 7952 7953 7954 7955 7956 7957 7958 7959 7960 7961 7962 7963 7964 7965 7966 7967 7968 7969 7970 7971 7972 7973 7974 7975 7976 7977 7978 7979 7980 7981 7982 7983 7984 7985 7986 7987 7988 7989 7990 7991 7992 7993 7994 7995 7996 7997 7998 7999 8000 8001 8002 8003 8004 8005 8006 8007 8008 8009 8010 8011 8012 8013 8014 8015 8016 8017 8018 8019 8020 8021 8022 8023 8024 8025 8026 8027 8028 8029 8030 8031 8032 8033 8034 8035 8036 8037 8038 8039 8040 8041 8042 8043 8044 8045 8046 8047 8048 8049 8050 8051 8052 8053 8054 8055 8056 8057 8058 8059 8060 8061 8062 8063 8064 8065 8066 8067 8068 8069 8070 8071 8072 8073 8074 8075 8076 8077 8078 8079 8080 8081 8082 8083 8084 8085 8086 8087 8088 8089 8090 8091 8092 8093 8094 8095 8096 8097 8098 8099 8100 8101 8102 8103 8104 8105 8106 8107 8108 8109 8110 8111 8112 8113 8114 8115 8116 8117 8118 8119 8120 8121 8122 8123 8124 8125 8126 8127 8128 8129 8130 8131 8132 8133 8134 8135 8136 8137 8138 8139 8140 8141 8142 8143 8144 8145 8146 8147 8148 8149 8150 8151 8152 8153 8154 8155 8156 8157 8158 8159 8160 8161 8162 8163 8164 8165 8166 8167 8168 8169 8170 8171 8172 8173 8174 8175 8176 8177 8178 8179 8180 8181 8182 8183 8184 8185 8186 8187 8188 8189 8190 8191 8192 8193 8194 8195 8196 8197 8198 8199 8200 8201 8202 8203 8204 8205 8206 8207 8208 8209 8210 8211 8212 8213 8214 8215 8216 8217 8218 8219 8220 8221 8222 8223 8224 8225 8226 8227 8228 8229 8230 8231 8232 8233 8234 8235 8236 8237 8238 8239 8240 8241 8242 8243 8244 8245 8246 8247 8248 8249 8250 8251 8252 8253 8254 8255 8256 8257 8258 8259 8260 8261 8262 8263 8264 8265 8266 8267 8268 8269 8270 8271 8272 8273 8274 8275 8276 8277 8278 8279 8280 8281 8282 8283 8284 8285 8286 8287 8288 8289 8290 8291 8292 8293 8294 8295 8296 8297 8298 8299 8300 8301 8302 8303 8304 8305 8306 8307 8308 8309 8310 8311 8312 8313 8314 8315 8316 8317 8318 8319 8320 8321 8322 8323 8324 8325 8326 8327 8328 8329 8330 8331 8332 8333 8334 8335 8336 8337 8338 8339 8340 8341 8342 8343 8344 8345 8346 8347 8348 8349 8350 8351 8352 8353 8354 8355 8356 8357 8358 8359 8360 8361 8362 8363 8364 8365 8366 8367 8368 8369 8370 8371 8372 8373 8374 8375 8376 8377 8378 8379 8380 8381 8382 8383 8384 8385 8386 8387 8388 8389 8390 8391 8392 8393 8394 8395 8396 8397 8398 8399 8400 8401 8402 8403 8404 8405 8406 8407 8408 8409 8410 8411 8412 8413 8414 8415 8416 8417 8418 8419 8420 8421 8422 8423 8424 8425 8426 8427 8428 8429 8430 8431 8432 8433 8434 8435 8436 8437 8438 8439 8440 8441 8442 8443 8444 8445 8446 8447 8448 8449 8450 8451 8452 8453 8454 8455 8456 8457 8458 8459 8460 8461 8462 8463 8464 8465 8466 8467 8468 8469 8470 8471 8472 8473 8474 8475 8476 8477 8478 8479 8480 8481 8482 8483 8484 8485 8486 8487 8488 8489 8490 8491 8492 8493 8494 8495 8496 8497 8498 8499 8500 8501 8502 8503 8504 8505 8506 8507 8508 8509 8510 8511 8512 8513 8514 8515 8516 8517 8518 8519 8520 8521 8522 8523 8524 8525 8526 8527 8528 8529 8530 8531 8532 8533 8534 8535 8536 8537 8538 8539 8540 8541 8542 8543 8544 8545 8546 8547 8548 8549 8550 8551 8552 8553 8554 8555 8556 8557 8558 8559 8560 8561 8562 8563 8564 8565 8566 8567 8568 8569 8570 8571 8572 8573 8574 8575 8576 8577 8578 8579 8580 8581 8582 8583 8584 8585 8586 8587 8588 8589 8590 8591 8592 8593 8594 8595 8596 8597 8598 8599 8600 8601 8602 8603 8604 8605 8606 8607 8608 8609 8610 8611 8612 8613 8614 8615 8616 8617 8618 8619 8620 8621 8622 8623 8624 8625 8626 8627 8628 8629 8630 8631 8632 8633 8634 8635 8636 8637 8638 8639 8640 8641 8642 8643 8644 8645 8646 8647 8648 8649 8650 8651 8652 8653 8654 8655 8656 8657 8658 8659 8660 8661 8662 8663 8664 8665 8666 8667 8668 8669 8670 8671 8672 8673 8674 8675 8676 8677 8678 8679 8680 8681 8682 8683 8684 8685 8686 8687 8688 8689 8690 8691 8692 8693 8694 8695 8696 8697 8698 8699 8700 8701 8702 8703 8704 8705 8706 8707 8708 8709 8710 8711 8712 8713 8714 8715 8716 8717 8718 8719 8720 8721 8722 8723 8724 8725 8726 8727 8728 8729 8730 8731 8732 8733 8734 8735 8736 8737 8738 8739 8740 8741 8742 8743 8744 8745 8746 8747 8748 8749 8750 8751 8752 8753 8754 8755 8756 8757 8758 8759 8760 8761 8762 8763 8764 8765 8766 8767
|
// krazy:excludeall=qclasses
//////////////////////////////////////////////////////////////////////////////
// oxygenstyle.cpp
// Oxygen widget style for KDE 4
// -------------------
//
// Copyright ( C ) 2009-2010 Hugo Pereira Da Costa <hugo.pereira@free.fr>
// Copyright ( C ) 2008 Long Huynh Huu <long.upcase@googlemail.com>
// Copyright ( C ) 2007-2008 Casper Boemann <cbr@boemann.dk>
// Copyright ( C ) 2007 Matthew Woehlke <mw_triad@users.sourceforge.net>
// Copyright ( C ) 2003-2005 Sandro Giessl <sandro@giessl.com>
//
// based on the KDE style "dotNET":
// Copyright ( C ) 2001-2002, Chris Lee <clee@kde.org>
// Carsten Pfeiffer <pfeiffer@kde.org>
// Karol Szwed <gallium@kde.org>
// Drawing routines completely reimplemented from KDE3 +HighColor, which was
// originally based on some stuff from the KDE2 HighColor.
//
// based on drawing routines of the style "Keramik":
// Copyright ( c ) 2002 Malte Starostik <malte@kde.org>
// ( c ) 2002,2003 Maksim Orlovich <mo002j@mail.rochester.edu>
// based on the KDE3 HighColor Style
// Copyright ( C ) 2001-2002 Karol Szwed <gallium@kde.org>
// ( C ) 2001-2002 Fredrik H?glund <fredrik@kde.org>
// Drawing routines adapted from the KDE2 HCStyle,
// Copyright ( C ) 2000 Daniel M. Duley <mosfet@kde.org>
// ( C ) 2000 Dirk Mueller <mueller@kde.org>
// ( C ) 2001 Martijn Klingens <klingens@kde.org>
// Progressbar code based on KStyle,
// Copyright ( C ) 2001-2002 Karol Szwed <gallium@kde.org>
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Library General Public
// License version 2 as published by the Free Software Foundation.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Library General Public License for more details.
//
// You should have received a copy of the GNU Library General Public License
// along with this library; see the file COPYING.LIB. If not, write to
// the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
// Boston, MA 02110-1301, USA.
//////////////////////////////////////////////////////////////////////////////
#include "oxygenstyle.h"
#include "oxygen.h"
#include "oxygenanimations.h"
#include "oxygenblurhelper.h"
#include "oxygenframeshadow.h"
#include "oxygenmdiwindowshadow.h"
#include "oxygenmnemonics.h"
#include "oxygenpropertynames.h"
#include "oxygenshadowhelper.h"
#include "oxygensplitterproxy.h"
#include "oxygenstyleconfigdata.h"
#include "oxygentransitions.h"
#include "oxygenwidgetexplorer.h"
#include "oxygenwindowmanager.h"
#include <QAbstractButton>
#include <QAbstractItemView>
#include <QApplication>
#include <QCheckBox>
#include <QComboBox>
#include <QDBusConnection>
#include <QDial>
#include <QDialogButtonBox>
#include <QDockWidget>
#include <QDoubleSpinBox>
#include <QFormLayout>
#include <QFrame>
#include <QGraphicsView>
#include <QGroupBox>
#include <QItemDelegate>
#include <QLayout>
#include <QLineEdit>
#include <QMainWindow>
#include <QMdiSubWindow>
#include <QPushButton>
#include <QRadioButton>
#include <QScrollBar>
#include <QSpinBox>
#include <QSplitterHandle>
#include <QStyleOption>
#include <QTextEdit>
#include <QToolBar>
#include <QToolBox>
#include <QToolButton>
#include <KColorUtils>
#include <cmath>
namespace OxygenPrivate
{
/*!
tabBar data class needed for
the rendering of tabbars when
one tab is being drawn
*/
class TabBarData: public QObject
{
public:
//* constructor
explicit TabBarData( Oxygen::Style* parent ):
QObject( parent ),
_style( parent )
{}
//* assign target tabBar
void lock( const QWidget* widget )
{ _tabBar = widget; }
//* true if tabbar is locked
bool locks( const QWidget* widget ) const
{ return _tabBar && _tabBar.data() == widget; }
//* set dirty
void setDirty( const bool& value = true )
{ _dirty = value; }
//* release
void release( void )
{ _tabBar.clear(); }
//* draw tabBarBase
virtual void drawTabBarBaseControl( const QStyleOptionTab*, QPainter*, const QWidget* );
private:
//* pointer to parent style object
Oxygen::WeakPointer<const Oxygen::Style> _style;
//* pointer to target tabBar
Oxygen::WeakPointer<const QWidget> _tabBar;
//* if true, will paint on next TabBarTabShapeControl call
bool _dirty = false;
};
//* needed to have spacing added to items in combobox
class ComboBoxItemDelegate: public QItemDelegate
{
public:
//* constructor
ComboBoxItemDelegate( QAbstractItemView* parent ):
QItemDelegate( parent ),
_proxy( parent->itemDelegate() ),
_itemMargin( Oxygen::Metrics::ItemView_ItemMarginWidth )
{}
//* paint
void paint( QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override
{
// call either proxy or parent class
if( _proxy ) _proxy.data()->paint( painter, option, index );
else QItemDelegate::paint( painter, option, index );
}
//* size hint for index
QSize sizeHint( const QStyleOptionViewItem& option, const QModelIndex& index ) const override
{
// get size from either proxy or parent class
QSize size( _proxy ?
_proxy.data()->sizeHint( option, index ):
QItemDelegate::sizeHint( option, index ) );
// adjust and return
if( size.isValid() ) { size.rheight() += _itemMargin*2; }
return size;
}
private:
//* proxy
Oxygen::WeakPointer<QAbstractItemDelegate> _proxy;
//* margin
int _itemMargin;
};
}
namespace Oxygen
{
//* toplevel manager
class TopLevelManager: public QObject
{
public:
//* constructor
TopLevelManager( QObject* parent, const StyleHelper& helper ):
QObject( parent ),
_helper( helper )
{}
//* event filter
bool eventFilter(QObject* object, QEvent* event ) override
{
// cast to QWidget
QWidget *widget = static_cast<QWidget*>( object );
if( event->type() == QEvent::Show && _helper.hasDecoration( widget ) )
{ _helper.setHasBackgroundGradient( widget->winId(), true ); }
return false;
}
private:
//* helper
const StyleHelper& _helper;
};
//______________________________________________________________
Style::Style( void ):
_helper( new StyleHelper( StyleConfigData::self()->sharedConfig() ) )
,_shadowHelper( new ShadowHelper( this, *_helper ) )
,_animations( new Animations( this ) )
,_transitions( new Transitions( this ) )
,_windowManager( new WindowManager( this ) )
,_topLevelManager( new TopLevelManager( this, *_helper ) )
,_frameShadowFactory( new FrameShadowFactory( this ) )
,_mdiWindowShadowFactory( new MdiWindowShadowFactory( this, *_helper ) )
,_mnemonics( new Mnemonics( this ) )
,_blurHelper( new BlurHelper( this, *_helper ) )
,_widgetExplorer( new WidgetExplorer( this ) )
,_tabBarData( new OxygenPrivate::TabBarData( this ) )
,_splitterFactory( new SplitterFactory( this ) )
,SH_ArgbDndWindow( newStyleHint( QStringLiteral( "SH_ArgbDndWindow" ) ) )
,CE_CapacityBar( newControlElement( QStringLiteral( "CE_CapacityBar" ) ) )
{
// use DBus connection to update on oxygen configuration change
QDBusConnection dbus = QDBusConnection::sessionBus();
dbus.connect( QString(),
QStringLiteral( "/OxygenStyle" ),
QStringLiteral( "org.kde.Oxygen.Style" ),
QStringLiteral( "reparseConfiguration" ), this, SLOT(configurationChanged()) );
// call the slot directly; this initial call will set up things that also
// need to be reset when the system palette changes
loadConfiguration();
}
//______________________________________________________________
Style::~Style( void )
{
// _shadowHelper is a child of us, but its destructor uses _helper so we
// delete it manually to ensure it is deleted *before* _helper is
// deleted
delete _shadowHelper;
delete _helper;
}
//______________________________________________________________
void Style::polish( QWidget* widget )
{
if( !widget ) return;
// register widget to animations
_animations->registerWidget( widget );
_transitions->registerWidget( widget );
_windowManager->registerWidget( widget );
_frameShadowFactory->registerWidget( widget, *_helper );
_mdiWindowShadowFactory->registerWidget( widget );
_shadowHelper->registerWidget( widget );
_splitterFactory->registerWidget( widget );
// scroll areas
if( QAbstractScrollArea* scrollArea = qobject_cast<QAbstractScrollArea*>( widget ) )
{ polishScrollArea( scrollArea ); }
// several widgets set autofill background to false, which effectively breaks the background
// gradient rendering. Instead of patching all concerned applications,
// we change the background here
if( widget->inherits( "MessageList::Core::Widget" ) )
{ widget->setAutoFillBackground( false ); }
// adjust layout for K3B themed headers
// FIXME: to be removed when fixed upstream
if( widget->inherits( "K3b::ThemedHeader" ) && widget->layout() )
{
widget->layout()->setContentsMargins( 0, 0, 0, 0 );
_frameShadowFactory->setHasContrast( widget, true );
}
// adjust flags for windows and dialogs
switch( widget->windowFlags() & Qt::WindowType_Mask )
{
case Qt::Window:
case Qt::Dialog:
// set background as styled
widget->setAttribute( Qt::WA_StyledBackground );
widget->installEventFilter( _topLevelManager );
break;
default: break;
}
// enforce translucency for drag and drop window
if( widget->testAttribute( Qt::WA_X11NetWmWindowTypeDND ) && _helper->compositingActive() )
{
widget->setAttribute( Qt::WA_TranslucentBackground );
widget->clearMask();
}
if(
qobject_cast<QAbstractItemView*>( widget )
|| qobject_cast<QAbstractSpinBox*>( widget )
|| qobject_cast<QCheckBox*>( widget )
|| qobject_cast<QComboBox*>( widget )
|| qobject_cast<QDial*>( widget )
|| qobject_cast<QLineEdit*>( widget )
|| qobject_cast<QPushButton*>( widget )
|| qobject_cast<QRadioButton*>( widget )
|| qobject_cast<QScrollBar*>( widget )
|| qobject_cast<QSlider*>( widget )
|| qobject_cast<QSplitterHandle*>( widget )
|| qobject_cast<QTabBar*>( widget )
|| qobject_cast<QTextEdit*>( widget )
|| qobject_cast<QToolButton*>( widget )
|| widget->inherits( "KTextEditor::View" )
)
{ widget->setAttribute( Qt::WA_Hover ); }
// transparent tooltips
if( widget->inherits( "QTipLabel" ) )
{
widget->setAttribute( Qt::WA_TranslucentBackground );
#ifdef Q_WS_WIN
//FramelessWindowHint is needed on windows to make WA_TranslucentBackground work properly
widget->setWindowFlags( widget->windowFlags() | Qt::FramelessWindowHint );
#endif
}
if( QAbstractItemView *itemView = qobject_cast<QAbstractItemView*>( widget ) )
{
// enable hover effects in itemviews' viewport
itemView->viewport()->setAttribute( Qt::WA_Hover );
} else if( QAbstractScrollArea* scrollArea = qobject_cast<QAbstractScrollArea*>( widget ) ) {
// enable hover effect in sunken scrollareas that support focus
if( scrollArea->frameShadow() == QFrame::Sunken && widget->focusPolicy()&Qt::StrongFocus )
{ widget->setAttribute( Qt::WA_Hover ); }
} else if( QGroupBox* groupBox = qobject_cast<QGroupBox*>( widget ) ) {
// checkable group boxes
if( groupBox->isCheckable() )
{ groupBox->setAttribute( Qt::WA_Hover ); }
} else if( qobject_cast<QAbstractButton*>( widget ) && qobject_cast<QDockWidget*>( widget->parent() ) ) {
widget->setAttribute( Qt::WA_Hover );
} else if( qobject_cast<QAbstractButton*>( widget ) && qobject_cast<QToolBox*>( widget->parent() ) ) {
widget->setAttribute( Qt::WA_Hover );
}
if( qobject_cast<QToolButton*>( widget ) )
{
if( qobject_cast<QToolBar*>( widget->parent() ) )
{
// this hack is needed to have correct text color
// rendered in toolbars. This does not really update nicely when changing styles
// but is the best I can do for now since setting the palette color at painting
// time is not doable
QPalette palette( widget->palette() );
palette.setColor( QPalette::Disabled, QPalette::ButtonText, palette.color( QPalette::Disabled, QPalette::WindowText ) );
palette.setColor( QPalette::Active, QPalette::ButtonText, palette.color( QPalette::Active, QPalette::WindowText ) );
palette.setColor( QPalette::Inactive, QPalette::ButtonText, palette.color( QPalette::Inactive, QPalette::WindowText ) );
widget->setPalette( palette );
}
widget->setBackgroundRole( QPalette::NoRole );
if( widget->parentWidget() &&
widget->parentWidget()->parentWidget() &&
widget->parentWidget()->parentWidget()->inherits( "Gwenview::SideBarGroup" ) )
{ widget->setProperty( PropertyNames::toolButtonAlignment, Qt::AlignLeft ); }
} else if( qobject_cast<QMenuBar*>( widget ) ) {
widget->setBackgroundRole( QPalette::NoRole );
} else if( widget->inherits( "KMultiTabBar" ) ) {
// kMultiTabBar margins are set to unity for alignment
// with ( usually sunken ) neighbor frames
widget->setContentsMargins( 1, 1, 1, 1 );
} else if( qobject_cast<QToolBar*>( widget ) ) {
widget->setBackgroundRole( QPalette::NoRole );
addEventFilter( widget );
} else if( qobject_cast<QTabBar*>( widget ) ) {
addEventFilter( widget );
} else if( widget->inherits( "QTipLabel" ) ) {
widget->setBackgroundRole( QPalette::NoRole );
widget->setAttribute( Qt::WA_TranslucentBackground );
#ifdef Q_WS_WIN
//FramelessWindowHint is needed on windows to make WA_TranslucentBackground work properly
widget->setWindowFlags( widget->windowFlags() | Qt::FramelessWindowHint );
#endif
} else if( qobject_cast<QScrollBar*>( widget ) ) {
widget->setAttribute( Qt::WA_OpaquePaintEvent, false );
// when painted in konsole, one needs to paint the window background below
// the scrollarea, otherwise an ugly flat background is used
if( widget->parent() && widget->parent()->inherits( "Konsole::TerminalDisplay" ) )
{ addEventFilter( widget ); }
} else if( qobject_cast<QDockWidget*>( widget ) ) {
widget->setBackgroundRole( QPalette::NoRole );
widget->setContentsMargins( 3,3,3,3 );
addEventFilter( widget );
} else if( qobject_cast<QMdiSubWindow*>( widget ) ) {
widget->setAutoFillBackground( false );
addEventFilter( widget );
} else if( qobject_cast<QToolBox*>( widget ) ) {
widget->setBackgroundRole( QPalette::NoRole );
widget->setAutoFillBackground( false );
widget->setContentsMargins( 5,5,5,5 );
addEventFilter( widget );
} else if( widget->parentWidget() && widget->parentWidget()->parentWidget() && qobject_cast<QToolBox*>( widget->parentWidget()->parentWidget()->parentWidget() ) ) {
widget->setBackgroundRole( QPalette::NoRole );
widget->setAutoFillBackground( false );
widget->parentWidget()->setAutoFillBackground( false );
} else if( qobject_cast<QMenu*>( widget ) ) {
widget->setAttribute( Qt::WA_TranslucentBackground );
#ifdef Q_WS_WIN
//FramelessWindowHint is needed on windows to make WA_TranslucentBackground work properly
widget->setWindowFlags( widget->windowFlags() | Qt::FramelessWindowHint );
#endif
} else if( qobject_cast<QCommandLinkButton*>( widget ) ) {
addEventFilter( widget );
} else if( QComboBox *comboBox = qobject_cast<QComboBox*>( widget ) ) {
if( !hasParent( widget, "QWebView" ) )
{
QAbstractItemView *itemView( comboBox->view() );
if( itemView && itemView->itemDelegate() && itemView->itemDelegate()->inherits( "QComboBoxDelegate" ) )
{ itemView->setItemDelegate( new OxygenPrivate::ComboBoxItemDelegate( itemView ) ); }
}
} else if( widget->inherits( "QComboBoxPrivateContainer" ) ) {
addEventFilter( widget );
widget->setAttribute( Qt::WA_TranslucentBackground );
#ifdef Q_WS_WIN
//FramelessWindowHint is needed on windows to make WA_TranslucentBackground work properly
widget->setWindowFlags( widget->windowFlags() | Qt::FramelessWindowHint );
#endif
} else if( qobject_cast<QFrame*>( widget ) && widget->parent() && widget->parent()->inherits( "KTitleWidget" ) ) {
widget->setAutoFillBackground( false );
widget->setBackgroundRole( QPalette::Window );
}
// base class polishing
KStyle::polish( widget );
}
//_______________________________________________________________
void Style::unpolish( QWidget* widget )
{
// register widget to animations
_animations->unregisterWidget( widget );
_transitions->unregisterWidget( widget );
_windowManager->unregisterWidget( widget );
_frameShadowFactory->unregisterWidget( widget );
_mdiWindowShadowFactory->unregisterWidget( widget );
_shadowHelper->unregisterWidget( widget );
_splitterFactory->unregisterWidget( widget );
_blurHelper->unregisterWidget( widget );
// event filters
switch( widget->windowFlags() & Qt::WindowType_Mask )
{
case Qt::Window:
case Qt::Dialog:
widget->removeEventFilter( this );
widget->setAttribute( Qt::WA_StyledBackground, false );
break;
default:
break;
}
// checkable group boxes
if( QGroupBox* groupBox = qobject_cast<QGroupBox*>( widget ) )
{
if( groupBox->isCheckable() )
{ groupBox->setAttribute( Qt::WA_Hover, false ); }
}
// hover flags
if(
qobject_cast<QAbstractItemView*>( widget )
|| qobject_cast<QAbstractSpinBox*>( widget )
|| qobject_cast<QCheckBox*>( widget )
|| qobject_cast<QComboBox*>( widget )
|| qobject_cast<QDial*>( widget )
|| qobject_cast<QLineEdit*>( widget )
|| qobject_cast<QPushButton*>( widget )
|| qobject_cast<QRadioButton*>( widget )
|| qobject_cast<QScrollBar*>( widget )
|| qobject_cast<QSlider*>( widget )
|| qobject_cast<QSplitterHandle*>( widget )
|| qobject_cast<QTabBar*>( widget )
|| qobject_cast<QTextEdit*>( widget )
|| qobject_cast<QToolButton*>( widget )
)
{ widget->setAttribute( Qt::WA_Hover, false ); }
// checkable group boxes
if( QGroupBox* groupBox = qobject_cast<QGroupBox*>( widget ) )
{
if( groupBox->isCheckable() )
{ groupBox->setAttribute( Qt::WA_Hover, false ); }
}
if( qobject_cast<QMenuBar*>( widget )
|| qobject_cast<QToolBar*>( widget )
|| ( widget && qobject_cast<QToolBar *>( widget->parent() ) )
|| qobject_cast<QToolBox*>( widget ) )
{
widget->setBackgroundRole( QPalette::Button );
widget->removeEventFilter( this );
widget->clearMask();
}
if( qobject_cast<QTabBar*>( widget ) )
{
widget->removeEventFilter( this );
} else if( widget->inherits( "QTipLabel" ) ) {
widget->setAttribute( Qt::WA_PaintOnScreen, false );
widget->setAttribute( Qt::WA_NoSystemBackground, false );
widget->clearMask();
} else if( qobject_cast<QScrollBar*>( widget ) ) {
widget->setAttribute( Qt::WA_OpaquePaintEvent );
} else if( qobject_cast<QDockWidget*>( widget ) ) {
widget->setContentsMargins( 0,0,0,0 );
widget->clearMask();
} else if( qobject_cast<QToolBox*>( widget ) ) {
widget->setBackgroundRole( QPalette::Button );
widget->setContentsMargins( 0,0,0,0 );
widget->removeEventFilter( this );
} else if( qobject_cast<QMenu*>( widget ) ) {
widget->setAttribute( Qt::WA_PaintOnScreen, false );
widget->setAttribute( Qt::WA_NoSystemBackground, false );
widget->clearMask();
} else if( widget->inherits( "QComboBoxPrivateContainer" ) ) widget->removeEventFilter( this );
KStyle::unpolish( widget );
}
//______________________________________________________________
int Style::pixelMetric( PixelMetric metric, const QStyleOption* option, const QWidget* widget ) const
{
// handle special cases
switch( metric )
{
case PM_DefaultFrameWidth:
if( qobject_cast<const QLineEdit*>( widget ) ) return Metrics::LineEdit_FrameWidth;
else if( isQtQuickControl( option, widget ) )
{
const QString &elementType = option->styleObject->property( "elementType" ).toString();
if( elementType == QLatin1String( "edit" ) || elementType == QLatin1String( "spinbox" ) )
{
return Metrics::LineEdit_FrameWidth;
} else if( elementType == QLatin1String( "combobox" ) ) {
return Metrics::ComboBox_FrameWidth;
}
}
// fallback
return Metrics::Frame_FrameWidth;
case PM_ComboBoxFrameWidth:
{
const QStyleOptionComboBox* comboBoxOption( qstyleoption_cast< const QStyleOptionComboBox*>( option ) );
return comboBoxOption && comboBoxOption->editable ? Metrics::LineEdit_FrameWidth : Metrics::ComboBox_FrameWidth;
}
case PM_SpinBoxFrameWidth: return Metrics::SpinBox_FrameWidth;
case PM_ToolBarFrameWidth: return Metrics::ToolBar_FrameWidth;
case PM_ToolTipLabelFrameWidth: return Metrics::ToolTip_FrameWidth;
// layout
case PM_LayoutLeftMargin:
case PM_LayoutTopMargin:
case PM_LayoutRightMargin:
case PM_LayoutBottomMargin:
{
/*
use either Child margin or TopLevel margin,
depending on widget type
*/
if( ( option && ( option->state & QStyle::State_Window ) ) || ( widget && widget->isWindow() ) )
{
return Metrics::Layout_TopLevelMarginWidth;
} else {
return Metrics::Layout_ChildMarginWidth;
}
}
case PM_LayoutHorizontalSpacing: return Metrics::Layout_DefaultSpacing;
case PM_LayoutVerticalSpacing: return Metrics::Layout_DefaultSpacing;
// buttons
case PM_ButtonMargin:
{
/* HACK: needs special case for kcalc buttons, to prevent the application to set too small margins */
if( widget && widget->inherits( "KCalcButton" ) ) return Metrics::Button_MarginWidth + 4;
else return Metrics::Button_MarginWidth;
}
// buttons
case PM_ButtonDefaultIndicator: return 0;
case PM_ButtonShiftHorizontal: return 0;
case PM_ButtonShiftVertical: return 0;
// menubars
case PM_MenuBarPanelWidth: return 0;
case PM_MenuBarHMargin: return 0;
case PM_MenuBarVMargin: return 0;
case PM_MenuBarItemSpacing: return 0;
case PM_MenuDesktopFrameWidth: return 0;
// menu buttons
case PM_MenuButtonIndicator: return Metrics::MenuButton_IndicatorWidth;
// toolbars
case PM_ToolBarHandleExtent: return Metrics::ToolBar_HandleExtent;
case PM_ToolBarSeparatorExtent: return Metrics::ToolBar_SeparatorWidth;
case PM_ToolBarExtensionExtent:
return pixelMetric( PM_SmallIconSize, option, widget ) + 2*Metrics::ToolButton_MarginWidth;
case PM_ToolBarItemMargin: return 0;
case PM_ToolBarItemSpacing: return Metrics::ToolBar_ItemSpacing;
// tabbars
case PM_TabBarTabShiftVertical: return 0;
case PM_TabBarTabShiftHorizontal: return 0;
case PM_TabBarTabOverlap: return Metrics::TabBar_TabOverlap;
case PM_TabBarBaseOverlap: return Metrics::TabBar_BaseOverlap;
case PM_TabBarTabHSpace: return 2*Metrics::TabBar_TabMarginWidth;
case PM_TabBarTabVSpace: return 2*Metrics::TabBar_TabMarginHeight;
case PM_TabCloseIndicatorWidth:
case PM_TabCloseIndicatorHeight:
return pixelMetric( PM_SmallIconSize, option, widget );
// scrollbars
case PM_ScrollBarExtent: return StyleConfigData::scrollBarWidth() + 2;
case PM_ScrollBarSliderMin: return Metrics::ScrollBar_MinSliderHeight;
// title bar
case PM_TitleBarHeight: return 2*Metrics::TitleBar_MarginWidth + pixelMetric( PM_SmallIconSize, option, widget );
// sliders
case PM_SliderThickness: return Metrics::Slider_ControlThickness;
case PM_SliderControlThickness: return Metrics::Slider_ControlThickness;
case PM_SliderLength: return Metrics::Slider_ControlThickness;
// checkboxes and radio buttons
case PM_IndicatorWidth: return Metrics::CheckBox_Size;
case PM_IndicatorHeight: return Metrics::CheckBox_Size;
case PM_ExclusiveIndicatorWidth: return Metrics::CheckBox_Size;
case PM_ExclusiveIndicatorHeight: return Metrics::CheckBox_Size;
// list heaaders
case PM_HeaderMarkSize: return Metrics::Header_ArrowSize;
case PM_HeaderMargin: return Metrics::Header_MarginWidth;
// dock widget
// return 0 here, since frame is handled directly in polish
case PM_DockWidgetFrameWidth: return 0;
case PM_DockWidgetTitleMargin: return Metrics::Frame_FrameWidth;
case PM_DockWidgetTitleBarButtonMargin: return Metrics::ToolButton_MarginWidth;
case PM_SplitterWidth: return Metrics::Splitter_SplitterWidth;
case PM_DockWidgetSeparatorExtent: return Metrics::Splitter_SplitterWidth;
// spacing between widget and scrollbars
case PM_ScrollView_ScrollBarSpacing:
if( const QFrame* frame = qobject_cast<const QFrame*>( widget ) )
{
const bool framed( frame->frameShape() != QFrame::NoFrame );
return framed ? -1:0;
} else return -1;
// fallback
default: return KStyle::pixelMetric( metric, option, widget );
}
}
//______________________________________________________________
int Style::styleHint( StyleHint hint, const QStyleOption* option, const QWidget* widget, QStyleHintReturn* returnData ) const
{
/*
special cases, that cannot be registered in styleHint map,
because of conditional statements
*/
switch( hint )
{
case SH_RubberBand_Mask:
{
if( QStyleHintReturnMask *mask = qstyleoption_cast<QStyleHintReturnMask*>( returnData ) )
{
mask->region = option->rect;
// need to check on widget before removing inner region
// in order to still preserve rubberband in MainWindow and QGraphicsView
// in QMainWindow because it looks better
// in QGraphicsView because the painting fails completely otherwise
if( widget && (
qobject_cast<const QAbstractItemView*>( widget->parent() ) ||
qobject_cast<const QGraphicsView*>( widget->parent() ) ||
qobject_cast<const QMainWindow*>( widget->parent() ) ) )
{ return true; }
// also check if widget's parent is some itemView viewport
if( widget && widget->parent() &&
qobject_cast<const QAbstractItemView*>( widget->parent()->parent() ) &&
static_cast<const QAbstractItemView*>( widget->parent()->parent() )->viewport() == widget->parent() )
{ return true; }
// mask out center
mask->region -= insideMargin( option->rect, 1 );
return true;
}
return false;
}
case SH_ToolTip_Mask:
case SH_Menu_Mask:
{
if( !_helper->hasAlphaChannel( widget ) && ( !widget || widget->isWindow() ) )
{
// mask should be set only if compositing is disabled
if( QStyleHintReturnMask *mask = qstyleoption_cast<QStyleHintReturnMask *>( returnData ) )
{ mask->region = _helper->roundedMask( option->rect ); }
}
return true;
}
// mouse tracking
case SH_ComboBox_ListMouseTracking: return true;
case SH_MenuBar_MouseTracking: return true;
case SH_Menu_MouseTracking: return true;
case SH_Menu_SubMenuPopupDelay: return 150;
case SH_Menu_SloppySubMenus: return true;
case SH_ToolBox_SelectedPageTitleBold: return false;
case SH_Widget_Animate: return StyleConfigData::animationsEnabled();
case SH_Menu_SupportsSections: return true;
case SH_TitleBar_NoBorder: return false;
case SH_GroupBox_TextLabelVerticalAlignment: return Qt::AlignVCenter;
case SH_ScrollBar_MiddleClickAbsolutePosition: return true;
case SH_ScrollView_FrameOnlyAroundContents: return true;
case SH_FormLayoutFormAlignment: return Qt::AlignLeft | Qt::AlignTop;
case SH_FormLayoutLabelAlignment: return Qt::AlignRight;
case SH_FormLayoutFieldGrowthPolicy: return QFormLayout::ExpandingFieldsGrow;
case SH_FormLayoutWrapPolicy: return QFormLayout::DontWrapRows;
case SH_MessageBox_TextInteractionFlags: return Qt::TextSelectableByMouse | Qt::LinksAccessibleByMouse;
case SH_RequestSoftwareInputPanel: return RSIP_OnMouseClick;
case SH_ProgressDialog_CenterCancelButton:
case SH_MessageBox_CenterButtons:
return false;
default: return KStyle::styleHint( hint, option, widget, returnData );
}
}
//______________________________________________________________
QRect Style::subElementRect( SubElement element, const QStyleOption* option, const QWidget* widget ) const
{
switch( element )
{
case SE_PushButtonContents: return pushButtonContentsRect( option, widget );
case SE_CheckBoxContents: return checkBoxContentsRect( option, widget );
case SE_RadioButtonContents: return checkBoxContentsRect( option, widget );
case SE_LineEditContents: return lineEditContentsRect( option, widget );
case SE_ProgressBarGroove: return progressBarGrooveRect( option, widget );
case SE_ProgressBarContents: return progressBarContentsRect( option, widget );
case SE_ProgressBarLabel: return defaultSubElementRect( option, widget );
case SE_HeaderArrow: return headerArrowRect( option, widget );
case SE_HeaderLabel: return headerLabelRect( option, widget );
case SE_TabBarTabLeftButton: return tabBarTabLeftButtonRect( option, widget );
case SE_TabBarTabRightButton: return tabBarTabRightButtonRect( option, widget );
case SE_TabWidgetTabBar: return tabWidgetTabBarRect( option, widget );
case SE_TabWidgetTabContents: return tabWidgetTabContentsRect( option, widget );
case SE_TabWidgetTabPane: return tabWidgetTabPaneRect( option, widget );
case SE_TabWidgetLeftCorner: return tabWidgetCornerRect( SE_TabWidgetLeftCorner, option, widget );
case SE_TabWidgetRightCorner: return tabWidgetCornerRect( SE_TabWidgetRightCorner, option, widget );
case SE_ToolBoxTabContents: return toolBoxTabContentsRect( option, widget );
default: return KStyle::subElementRect( element, option, widget );
}
}
//______________________________________________________________
QRect Style::subControlRect( ComplexControl element, const QStyleOptionComplex* option, SubControl subControl, const QWidget* widget ) const
{
switch( element )
{
case CC_GroupBox: return groupBoxSubControlRect( option, subControl, widget );
case CC_ToolButton: return toolButtonSubControlRect( option, subControl, widget );
case CC_ComboBox: return comboBoxSubControlRect( option, subControl, widget );
case CC_SpinBox: return spinBoxSubControlRect( option, subControl, widget );
case CC_ScrollBar: return scrollBarSubControlRect( option, subControl, widget );
case CC_Slider: return sliderSubControlRect( option, subControl, widget );
// fallback
default: return KStyle::subControlRect( element, option, subControl, widget );
}
}
//______________________________________________________________
QSize Style::sizeFromContents( ContentsType element, const QStyleOption* option, const QSize& size, const QWidget* widget ) const
{
switch( element )
{
case CT_CheckBox: return checkBoxSizeFromContents( option, size, widget );
case CT_RadioButton: return checkBoxSizeFromContents( option, size, widget );
case CT_LineEdit: return lineEditSizeFromContents( option, size, widget );
case CT_ComboBox: return comboBoxSizeFromContents( option, size, widget );
case CT_SpinBox: return spinBoxSizeFromContents( option, size, widget );
case CT_Slider: return sliderSizeFromContents( option, size, widget );
case CT_PushButton: return pushButtonSizeFromContents( option, size, widget );
case CT_ToolButton: return toolButtonSizeFromContents( option, size, widget );
case CT_MenuBar: return defaultSizeFromContents( option, size, widget );
case CT_MenuBarItem: return menuBarItemSizeFromContents( option, size, widget );
case CT_MenuItem: return menuItemSizeFromContents( option, size, widget );
case CT_TabWidget: return tabWidgetSizeFromContents( option, size, widget );
case CT_TabBarTab: return tabBarTabSizeFromContents( option, size, widget );
case CT_HeaderSection: return headerSectionSizeFromContents( option, size, widget );
case CT_ItemViewItem: return itemViewItemSizeFromContents( option, size, widget );
default: return KStyle::sizeFromContents( element, option, size, widget );
}
}
//______________________________________________________________
QStyle::SubControl Style::hitTestComplexControl( ComplexControl control, const QStyleOptionComplex* option, const QPoint& point, const QWidget* widget ) const
{
switch( control )
{
case CC_ScrollBar:
{
QRect grooveRect = subControlRect( CC_ScrollBar, option, SC_ScrollBarGroove, widget );
if( grooveRect.contains( point ) )
{
//Must be either page up/page down, or just click on the slider.
//Grab the slider to compare
QRect sliderRect = subControlRect( CC_ScrollBar, option, SC_ScrollBarSlider, widget );
if( sliderRect.contains( point ) ) return SC_ScrollBarSlider;
else if( preceeds( point, sliderRect, option ) ) return SC_ScrollBarSubPage;
else return SC_ScrollBarAddPage;
}
//This is one of the up/down buttons. First, decide which one it is.
if( preceeds( point, grooveRect, option ) )
{
if( _subLineButtons == DoubleButton )
{
QRect buttonRect = scrollBarInternalSubControlRect( option, SC_ScrollBarSubLine );
return scrollBarHitTest( buttonRect, point, option );
} else return SC_ScrollBarSubLine;
}
if( _addLineButtons == DoubleButton )
{
QRect buttonRect = scrollBarInternalSubControlRect( option, SC_ScrollBarAddLine );
return scrollBarHitTest( buttonRect, point, option );
} else return SC_ScrollBarAddLine;
}
// fallback
default: return KStyle::hitTestComplexControl( control, option, point, widget );
}
}
//______________________________________________________________
void Style::drawPrimitive( PrimitiveElement element, const QStyleOption* option, QPainter* painter, const QWidget* widget ) const
{
StylePrimitive fcn( nullptr );
switch( element )
{
case PE_PanelButtonCommand: fcn = &Style::drawPanelButtonCommandPrimitive; break;
case PE_PanelButtonTool: fcn = &Style::drawPanelButtonToolPrimitive; break;
case PE_PanelScrollAreaCorner: fcn = &Style::drawPanelScrollAreaCornerPrimitive; break;
case PE_PanelMenu: fcn = &Style::drawPanelMenuPrimitive; break;
case PE_PanelTipLabel: fcn = &Style::drawPanelTipLabelPrimitive; break;
case PE_PanelItemViewItem: fcn = &Style::drawPanelItemViewItemPrimitive; break;
case PE_IndicatorCheckBox: fcn = &Style::drawIndicatorCheckBoxPrimitive; break;
case PE_IndicatorRadioButton: fcn = &Style::drawIndicatorRadioButtonPrimitive; break;
case PE_IndicatorButtonDropDown: fcn = &Style::drawIndicatorButtonDropDownPrimitive; break;
case PE_IndicatorTabClose: fcn = &Style::drawIndicatorTabClosePrimitive; break;
case PE_IndicatorTabTear: fcn = &Style::drawIndicatorTabTearPrimitive; break;
case PE_IndicatorArrowUp: fcn = &Style::drawIndicatorArrowUpPrimitive; break;
case PE_IndicatorArrowDown: fcn = &Style::drawIndicatorArrowDownPrimitive; break;
case PE_IndicatorArrowLeft: fcn = &Style::drawIndicatorArrowLeftPrimitive; break;
case PE_IndicatorArrowRight: fcn = &Style::drawIndicatorArrowRightPrimitive; break;
case PE_IndicatorMenuCheckMark: fcn = &Style::drawIndicatorMenuCheckMarkPrimitive; break;
case PE_IndicatorHeaderArrow: fcn = &Style::drawIndicatorHeaderArrowPrimitive; break;
case PE_IndicatorToolBarHandle: fcn = &Style::drawIndicatorToolBarHandlePrimitive; break;
case PE_IndicatorToolBarSeparator: fcn = &Style::drawIndicatorToolBarSeparatorPrimitive; break;
case PE_IndicatorBranch: fcn = &Style::drawIndicatorBranchPrimitive; break;
case PE_IndicatorDockWidgetResizeHandle: fcn = &Style::drawIndicatorDockWidgetResizeHandlePrimitive; break;
case PE_FrameStatusBar: fcn = &Style::emptyPrimitive; break;
case PE_Frame: fcn = &Style::drawFramePrimitive; break;
case PE_FrameLineEdit: fcn = &Style::drawFrameLineEditPrimitive; break;
case PE_FrameMenu: fcn = &Style::drawFrameMenuPrimitive; break;
case PE_FrameGroupBox: fcn = &Style::drawFrameGroupBoxPrimitive; break;
case PE_FrameTabWidget: fcn = &Style::drawFrameTabWidgetPrimitive; break;
case PE_FrameTabBarBase: fcn = &Style::drawFrameTabBarBasePrimitive; break;
case PE_FrameWindow: fcn = &Style::drawFrameWindowPrimitive; break;
case PE_FrameFocusRect: fcn = _frameFocusPrimitive; break;
case PE_Widget: fcn = &Style::drawWidgetPrimitive; break;
// fallback
default: break;
}
painter->save();
// call function if implemented
if( !( fcn && ( this->*fcn )( option, painter, widget ) ) )
{ KStyle::drawPrimitive( element, option, painter, widget ); }
painter->restore();
}
//______________________________________________________________
void Style::drawControl( ControlElement element, const QStyleOption* option, QPainter* painter, const QWidget* widget ) const
{
StyleControl fcn( nullptr );
if( element == CE_CapacityBar )
{
fcn = &Style::drawProgressBarControl;
} else
switch( element ) {
case CE_ComboBoxLabel: break;
case CE_DockWidgetTitle: fcn = &Style::drawDockWidgetTitleControl; break;
case CE_HeaderEmptyArea: fcn = &Style::drawHeaderEmptyAreaControl; break;
case CE_HeaderLabel: break;
case CE_HeaderSection: fcn = &Style::drawHeaderSectionControl; break;
case CE_MenuBarEmptyArea: fcn = &Style::emptyControl; break;
case CE_MenuBarItem: fcn = &Style::drawMenuBarItemControl; break;
case CE_MenuItem: fcn = &Style::drawMenuItemControl; break;
case CE_ProgressBar: fcn = &Style::drawProgressBarControl; break;
case CE_ProgressBarContents: fcn = &Style::drawProgressBarContentsControl; break;
case CE_ProgressBarGroove: fcn = &Style::drawProgressBarGrooveControl; break;
case CE_ProgressBarLabel: fcn = &Style::drawProgressBarLabelControl; break;
case CE_PushButtonBevel: fcn = &Style::drawPanelButtonCommandPrimitive; break;
case CE_PushButtonLabel: fcn = &Style::drawPushButtonLabelControl; break;
case CE_RubberBand: fcn = &Style::drawRubberBandControl; break;
case CE_ScrollBarSlider: fcn = &Style::drawScrollBarSliderControl; break;
case CE_ScrollBarAddLine: fcn = &Style::drawScrollBarAddLineControl; break;
case CE_ScrollBarSubLine: fcn = &Style::drawScrollBarSubLineControl; break;
case CE_ScrollBarAddPage: fcn = &Style::emptyControl; break;
case CE_ScrollBarSubPage: fcn = &Style::emptyControl; break;
case CE_ShapedFrame: fcn = &Style::drawShapedFrameControl; break;
case CE_SizeGrip: fcn = &Style::emptyControl; break;
case CE_Splitter: fcn = &Style::drawSplitterControl; break;
case CE_TabBarTabLabel: fcn = &Style::drawTabBarTabLabelControl; break;
case CE_TabBarTabShape: fcn = &Style::drawTabBarTabShapeControl; break;
case CE_ToolBar: fcn = &Style::drawToolBarControl; break;
case CE_ToolBoxTabLabel: fcn = &Style::drawToolBoxTabLabelControl; break;
case CE_ToolBoxTabShape: fcn = &Style::drawToolBoxTabShapeControl; break;
case CE_ToolButtonLabel: fcn = &Style::drawToolButtonLabelControl; break;
default: break;
}
painter->save();
// call function if implemented
if( !( fcn && ( this->*fcn )( option, painter, widget ) ) )
{ KStyle::drawControl( element, option, painter, widget ); }
painter->restore();
}
//______________________________________________________________
void Style::drawComplexControl( ComplexControl element, const QStyleOptionComplex* option, QPainter* painter, const QWidget* widget ) const
{
StyleComplexControl fcn( nullptr );
switch( element )
{
case CC_GroupBox: break;
case CC_ToolButton: fcn = &Style::drawToolButtonComplexControl; break;
case CC_ComboBox: fcn = &Style::drawComboBoxComplexControl; break;
case CC_SpinBox: fcn = &Style::drawSpinBoxComplexControl; break;
case CC_Slider: fcn = &Style::drawSliderComplexControl; break;
case CC_Dial: fcn = &Style::drawDialComplexControl; break;
case CC_ScrollBar: fcn = &Style::drawScrollBarComplexControl; break;
case CC_TitleBar: fcn = &Style::drawTitleBarComplexControl; break;
// fallback
default: break;
}
painter->save();
// call function if implemented
if( !( fcn && ( this->*fcn )( option, painter, widget ) ) )
{ KStyle::drawComplexControl( element, option, painter, widget ); }
painter->restore();
}
//___________________________________________________________________________________
void Style::drawItemText(
QPainter* painter, const QRect& rect, int flags, const QPalette& palette, bool enabled,
const QString &text, QPalette::ColorRole textRole ) const
{
// hide mnemonics if requested
if( !_mnemonics->enabled() && ( flags&Qt::TextShowMnemonic ) && !( flags&Qt::TextHideMnemonic ) )
{
flags &= ~Qt::TextShowMnemonic;
flags |= Qt::TextHideMnemonic;
}
// make sure vertical alignment is defined
// fallback on Align::VCenter if not
if( !(flags&Qt::AlignVertical_Mask) ) flags |= Qt::AlignVCenter;
if( _animations->widgetEnableStateEngine().enabled() )
{
/*
check if painter engine is registered to widgetEnableStateEngine, and animated
if yes, merge the palettes. Note: a static_cast is safe here, since only the address
of the pointer is used, not the actual content.
*/
const QWidget* widget( static_cast<const QWidget*>( painter->device() ) );
if( _animations->widgetEnableStateEngine().isAnimated( widget, AnimationEnable ) )
{
const QPalette copy( _helper->disabledPalette( palette, _animations->widgetEnableStateEngine().opacity( widget, AnimationEnable ) ) );
return KStyle::drawItemText( painter, rect, flags, copy, enabled, text, textRole );
}
}
// fallback
return KStyle::drawItemText( painter, rect, flags, palette, enabled, text, textRole );
}
//_____________________________________________________________________
bool Style::eventFilter( QObject *object, QEvent *event )
{
if( QTabBar* tabBar = qobject_cast<QTabBar*>( object ) ) { return eventFilterTabBar( tabBar, event ); }
else if( QToolBar* toolBar = qobject_cast<QToolBar*>( object ) ) { return eventFilterToolBar( toolBar, event ); }
else if( QDockWidget* dockWidget = qobject_cast<QDockWidget*>( object ) ) { return eventFilterDockWidget( dockWidget, event ); }
else if( QToolBox* toolBox = qobject_cast<QToolBox*>( object ) ) { return eventFilterToolBox( toolBox, event ); }
else if( QMdiSubWindow* subWindow = qobject_cast<QMdiSubWindow*>( object ) ) { return eventFilterMdiSubWindow( subWindow, event ); }
else if( QScrollBar* scrollBar = qobject_cast<QScrollBar*>( object ) ) { return eventFilterScrollBar( scrollBar, event ); }
else if( QCommandLinkButton* commandLinkButton = qobject_cast<QCommandLinkButton*>( object ) ) { return eventFilterCommandLinkButton( commandLinkButton, event ); }
// cast to QWidget
QWidget *widget = static_cast<QWidget*>( object );
if( widget->inherits( "QComboBoxPrivateContainer" ) ) { return eventFilterComboBoxContainer( widget, event ); }
// fallback
return KStyle::eventFilter( object, event );
}
//_________________________________________________________
bool Style::eventFilterComboBoxContainer( QWidget* widget, QEvent* event )
{
switch( event->type() )
{
case QEvent::Show:
case QEvent::Resize:
{
if( !_helper->hasAlphaChannel( widget ) ) widget->setMask( _helper->roundedMask( widget->size() ) );
else widget->clearMask();
return false;
}
case QEvent::Paint:
{
QPainter painter( widget );
QPaintEvent *paintEvent = static_cast<QPaintEvent*>( event );
painter.setClipRegion( paintEvent->region() );
const QRect rect( widget->rect() );
const QColor color( widget->palette().color( widget->window()->backgroundRole() ) );
const bool hasAlpha( _helper->hasAlphaChannel( widget ) );
if( hasAlpha )
{
_helper->roundCorner( color ).render( rect, &painter );
painter.setCompositionMode( QPainter::CompositionMode_SourceOver );
painter.setClipPath( _helper->roundedPath( insideMargin( rect, 1 ) ), Qt::IntersectClip );
}
// background
_helper->renderMenuBackground( &painter, paintEvent->rect(), widget, widget->palette() );
// frame
if( hasAlpha ) painter.setClipping( false );
_helper->drawFloatFrame( &painter, rect, color, !hasAlpha );
return false;
}
default: return false;
}
}
//____________________________________________________________________________
bool Style::eventFilterDockWidget( QDockWidget* dockWidget, QEvent* event )
{
switch( event->type() )
{
case QEvent::Show:
case QEvent::Resize:
{
// make sure mask is appropriate
if( dockWidget->isFloating() ) dockWidget->setMask( _helper->roundedMask( dockWidget->size() ) );
else dockWidget->clearMask();
return false;
}
case QEvent::Paint:
{
QPainter painter( dockWidget );
QPaintEvent *paintEvent = static_cast<QPaintEvent*>( event );
painter.setClipRegion( paintEvent->region() );
const QColor color( dockWidget->palette().color( QPalette::Window ) );
const QRect rect( dockWidget->rect() );
if( dockWidget->isWindow() )
{
_helper->renderWindowBackground( &painter, rect, dockWidget, color, 0 );
#ifndef Q_WS_WIN
_helper->drawFloatFrame( &painter, rect, color, !_helper->compositingActive() );
#endif
} else {
// need to draw window background for autoFilled dockWidgets for better rendering
if( dockWidget->autoFillBackground() )
{ _helper->renderWindowBackground( &painter, rect, dockWidget, color ); }
// adjust color
QColor top( _helper->backgroundColor( color, dockWidget, rect.topLeft() ) );
QColor bottom( _helper->backgroundColor( color, dockWidget, rect.bottomLeft() ) );
_helper->dockFrame( top, bottom ).render( rect, &painter );
}
return false;
}
default: return false;
}
}
//____________________________________________________________________________
bool Style::eventFilterMdiSubWindow( QMdiSubWindow* subWindow, QEvent* event )
{
if( event->type() == QEvent::Paint )
{
QPainter painter( subWindow );
QRect clip( static_cast<QPaintEvent*>( event )->rect() );
if( subWindow->isMaximized() ) _helper->renderWindowBackground( &painter, clip, subWindow, subWindow->palette() );
else {
painter.setClipRect( clip );
const QRect rect( subWindow->rect() );
_helper->roundCorner( subWindow->palette().color( subWindow->backgroundRole() ) ).render( rect, &painter );
painter.setClipPath( _helper->roundedPath( insideMargin( rect, 1 ) ), Qt::IntersectClip );
_helper->renderWindowBackground( &painter, clip, subWindow, subWindow, subWindow->palette(), 0 );
}
}
// continue with normal painting
return false;
}
//____________________________________________________________________________
bool Style::eventFilterCommandLinkButton( QCommandLinkButton* button, QEvent* event )
{
if( event->type() == QEvent::Paint )
{
// painter
QPainter painter( button );
painter.setClipRegion( static_cast<QPaintEvent*>( event )->region() );
const bool isFlat = false;
// option
QStyleOptionButton option;
option.initFrom( button );
option.features |= QStyleOptionButton::CommandLinkButton;
if( isFlat ) option.features |= QStyleOptionButton::Flat;
option.text = QString();
option.icon = QIcon();
if( button->isChecked() ) option.state|=State_On;
if( button->isDown() ) option.state|=State_Sunken;
// frame
drawControl(QStyle::CE_PushButton, &option, &painter, button );
// offset
const int margin( Metrics::Button_MarginWidth + Metrics::Frame_FrameWidth );
QPoint offset( margin, margin );
// state
const State& state( option.state );
const bool enabled( state & State_Enabled );
// icon
if( !button->icon().isNull() )
{
const QSize pixmapSize( button->icon().actualSize( button->iconSize() ) );
const QRect pixmapRect( QPoint( offset.x(), button->description().isEmpty() ? (button->height() - pixmapSize.height())/2:offset.y() ), pixmapSize );
const QPixmap pixmap( button->icon().pixmap(pixmapSize,
enabled ? QIcon::Normal : QIcon::Disabled,
button->isChecked() ? QIcon::On : QIcon::Off) );
drawItemPixmap( &painter, pixmapRect, Qt::AlignCenter, pixmap );
offset.rx() += pixmapSize.width() + 4;
}
// text rect
QRect textRect( offset, QSize( button->size().width() - offset.x() - margin, button->size().height() - 2*margin ) );
const QPalette::ColorRole textRole = QPalette::ButtonText;
if( !button->text().isEmpty() )
{
QFont font( button->font() );
font.setBold( true );
painter.setFont( font );
if( button->description().isEmpty() )
{
drawItemText( &painter, textRect, Qt::AlignLeft|Qt::AlignVCenter|Qt::TextHideMnemonic, button->palette(), enabled, button->text(), textRole );
} else {
drawItemText( &painter, textRect, Qt::AlignLeft|Qt::AlignTop|Qt::TextHideMnemonic, button->palette(), enabled, button->text(), textRole );
textRect.setTop( textRect.top() + QFontMetrics( font ).height() );
}
painter.setFont( button->font() );
}
if( !button->description().isEmpty() )
{ drawItemText( &painter, textRect, Qt::AlignLeft|Qt::AlignVCenter|Qt::TextWordWrap, button->palette(), enabled, button->description(), textRole ); }
return true;
}
// continue with normal painting
return false;
}
//_________________________________________________________
bool Style::eventFilterScrollBar( QWidget* widget, QEvent* event )
{
if( event->type() == QEvent::Paint )
{
QPainter painter( widget );
painter.setClipRegion( static_cast<QPaintEvent*>( event )->region() );
_helper->renderWindowBackground( &painter, widget->rect(), widget,widget->palette() );
}
return false;
}
//_____________________________________________________________________
bool Style::eventFilterTabBar( QWidget* widget, QEvent* event )
{
if( event->type() == QEvent::Paint && _tabBarData->locks( widget ) )
{
/*
this makes sure that tabBar base is drawn ( and drawn only once )
every time a replaint is triggered by dragging a tab around
*/
_tabBarData->setDirty();
}
return false;
}
//_____________________________________________________________________
bool Style::eventFilterToolBar( QToolBar* toolBar, QEvent* event )
{
switch( event->type() )
{
case QEvent::Show:
case QEvent::Resize:
{
// make sure mask is appropriate
if( toolBar->isFloating() )
{
// TODO: should not be needed
toolBar->setMask( _helper->roundedMask( toolBar->size() ) );
} else toolBar->clearMask();
return false;
}
case QEvent::Paint:
{
QPainter painter( toolBar );
QPaintEvent *paintEvent = static_cast<QPaintEvent*>( event );
painter.setClipRegion( paintEvent->region() );
const QRect rect( toolBar->rect() );
const QColor color( toolBar->palette().window().color() );
// default painting when not qrealing
if( !toolBar->isFloating() )
{
// background has to be rendered explicitly
// when one of the parent has autofillBackground set to true
if( _helper->checkAutoFillBackground( toolBar ) )
{ _helper->renderWindowBackground( &painter, rect, toolBar, color, 0 ); }
return false;
} else {
// background
_helper->renderWindowBackground( &painter, rect, toolBar, color );
if( toolBar->isMovable() )
{
// remaining painting: need to add handle
// this is copied from QToolBar::paintEvent
QStyleOptionToolBar opt;
opt.initFrom( toolBar );
if( toolBar->orientation() == Qt::Horizontal )
{
opt.rect = visualRect( &opt, QRect( rect.topLeft(), QSize( 8, rect.height() ) ) );
opt.state |= QStyle::State_Horizontal;
} else {
opt.rect = visualRect( &opt, QRect( rect.topLeft(), QSize( rect.width(), 8 ) ) );
}
drawPrimitive( PE_IndicatorToolBarHandle, &opt, &painter, toolBar );
}
#ifndef Q_WS_WIN
if( _helper->compositingActive() ) _helper->drawFloatFrame( &painter, insideMargin( rect, -1 ), color, false );
else _helper->drawFloatFrame( &painter, rect, color, true );
#endif
// do not propagate
return true;
}
}
default: return false;
}
}
//____________________________________________________________________________
bool Style::eventFilterToolBox( QToolBox* toolBox, QEvent* event )
{
if( event->type() == QEvent::Paint )
{
if( toolBox->frameShape() != QFrame::NoFrame )
{
const QRect rect( toolBox->rect() );
const StyleOptions styleOptions( NoFill );
QPainter painter( toolBox );
painter.setClipRegion( static_cast<QPaintEvent*>( event )->region() );
renderSlab( &painter, rect, toolBox->palette().color( QPalette::Button ), styleOptions );
}
}
return false;
}
//_____________________________________________________________________
void Style::configurationChanged()
{
// reload
StyleConfigData::self()->load();
_shadowHelper->reparseCacheConfig();
_helper->invalidateCaches();
loadConfiguration();
}
//____________________________________________________________________
QIcon Style::standardIconImplementation(
StandardPixmap standardPixmap,
const QStyleOption *option,
const QWidget *widget ) const
{
// MDI windows buttons
// get button color ( unfortunately option and widget might not be set )
QColor buttonColor;
QColor iconColor;
if( option )
{
buttonColor = option->palette.window().color();
iconColor = option->palette.windowText().color();
} else if( widget ) {
buttonColor = widget->palette().window().color();
iconColor = widget->palette().windowText().color();
} else if( qApp ) {
// might not have a QApplication
buttonColor = QPalette().window().color();
iconColor = QPalette().windowText().color();
} else {
// KCS is always safe
buttonColor = KColorScheme( QPalette::Active, KColorScheme::Window, _helper->config() ).background().color();
iconColor = KColorScheme( QPalette::Active, KColorScheme::Window, _helper->config() ).foreground().color();
}
// contrast
const QColor contrast( _helper->calcLightColor( buttonColor ) );
const int iconSize( pixelMetric( QStyle::PM_SmallIconSize ) );
const QRect rect( 0, 0, iconSize, iconSize );
switch( standardPixmap )
{
case SP_TitleBarNormalButton:
{
QPixmap pixmap( _helper->highDpiPixmap( rect.size() ) );
pixmap.fill( Qt::transparent );
QPainter painter( &pixmap );
renderTitleBarButton( &painter, rect, buttonColor, iconColor, SC_TitleBarNormalButton );
return QIcon( pixmap );
}
case SP_TitleBarShadeButton:
{
QPixmap pixmap( _helper->highDpiPixmap( rect.size() ) );
pixmap.fill( Qt::transparent );
QPainter painter( &pixmap );
renderTitleBarButton( &painter, rect, buttonColor, iconColor, SC_TitleBarShadeButton );
return QIcon( pixmap );
}
case SP_TitleBarUnshadeButton:
{
QPixmap pixmap( _helper->highDpiPixmap( rect.size() ) );
pixmap.fill( Qt::transparent );
QPainter painter( &pixmap );
renderTitleBarButton( &painter, rect, buttonColor, iconColor, SC_TitleBarUnshadeButton );
return QIcon( pixmap );
}
case SP_TitleBarCloseButton:
case SP_DockWidgetCloseButton:
{
QPixmap pixmap( _helper->highDpiPixmap( rect.size() ) );
pixmap.fill( Qt::transparent );
QPainter painter( &pixmap );
renderTitleBarButton( &painter, rect, buttonColor, iconColor, SC_TitleBarCloseButton );
return QIcon( pixmap );
}
case SP_ToolBarHorizontalExtensionButton:
{
QIcon icon;
// default icon sizes
static const QList<int> iconSizes = { 8, 16, 22, 32, 48 };
foreach( const int& iconSize, iconSizes )
{
QPixmap pixmap( iconSize, iconSize );
pixmap.fill( Qt::transparent );
QPainter painter( &pixmap );
painter.setRenderHints( QPainter::Antialiasing );
painter.setWindow( rect );
painter.setBrush( Qt::NoBrush );
painter.translate( QRectF( rect ).center() );
const bool reverseLayout( option && option->direction == Qt::RightToLeft );
QPolygonF arrow = genericArrow( reverseLayout ? ArrowLeft:ArrowRight, ArrowTiny );
const qreal width( 1.1 );
painter.translate( 0, 0.5 );
painter.setBrush( Qt::NoBrush );
painter.setPen( QPen( _helper->calcLightColor( buttonColor ), width, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin ) );
painter.drawPolyline( arrow );
painter.translate( 0,-1 );
painter.setBrush( Qt::NoBrush );
painter.setPen( QPen( iconColor, width, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin ) );
painter.drawPolyline( arrow );
painter.end();
icon.addPixmap( pixmap );
}
return icon;
}
case SP_ToolBarVerticalExtensionButton:
{
QIcon icon;
// default icon sizes
static const QList<int> iconSizes = { 8, 16, 22, 32, 48 };
foreach( const int& iconSize, iconSizes )
{
QPixmap pixmap( iconSize, iconSize );
pixmap.fill( Qt::transparent );
QPainter painter( &pixmap );
painter.setRenderHints( QPainter::Antialiasing );
painter.setWindow( rect );
painter.setBrush( Qt::NoBrush );
painter.translate( QRectF( rect ).center() );
QPolygonF arrow = genericArrow( ArrowDown, ArrowTiny );
const qreal width( 1.1 );
painter.translate( 0, 0.5 );
painter.setBrush( Qt::NoBrush );
painter.setPen( QPen( _helper->calcLightColor( buttonColor ), width, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin ) );
painter.drawPolyline( arrow );
painter.translate( 0,-1 );
painter.setBrush( Qt::NoBrush );
painter.setPen( QPen( iconColor, width, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin ) );
painter.drawPolyline( arrow );
painter.end();
icon.addPixmap( pixmap );
}
return icon;
}
default:
// do not cache parent style icon, since it may change at runtime
return KStyle::standardIcon( standardPixmap, option, widget );
}
}
//_____________________________________________________________________
void Style::loadConfiguration()
{
// set helper configuration
_helper->loadConfig();
// background gradient
_helper->setUseBackgroundGradient( StyleConfigData::useBackgroundGradient() );
// update top level window hints
foreach( QWidget* widget, qApp->topLevelWidgets() )
{
// make sure widget has a valid WId
if( !(widget->testAttribute(Qt::WA_WState_Created) || widget->internalWinId() ) ) continue;
// make sure widget has a decoration
if( !_helper->hasDecoration( widget ) ) continue;
// update flags
_helper->setHasBackgroundGradient( widget->winId(), true );
}
// update caches size
int cacheSize( StyleConfigData::cacheEnabled() ?
StyleConfigData::maxCacheSize():0 );
_helper->setMaxCacheSize( cacheSize );
// always enable blur helper
_blurHelper->setEnabled( true );
// reinitialize engines
_animations->setupEngines();
_transitions->setupEngines();
_windowManager->initialize();
_shadowHelper->loadConfig();
// mnemonics
_mnemonics->setMode( StyleConfigData::mnemonicsMode() );
// widget explorer
_widgetExplorer->setEnabled( StyleConfigData::widgetExplorerEnabled() );
_widgetExplorer->setDrawWidgetRects( StyleConfigData::drawWidgetRects() );
// splitter proxy
_splitterFactory->setEnabled( StyleConfigData::splitterProxyEnabled() );
// scrollbar button dimentions.
/* it has to be reinitialized here because scrollbar width might have changed */
_noButtonHeight = 0;
_singleButtonHeight = qMax( StyleConfigData::scrollBarWidth() * 7 / 10, 14 );
_doubleButtonHeight = 2*_singleButtonHeight;
// scrollbar buttons
switch( StyleConfigData::scrollBarAddLineButtons() )
{
case 0: _addLineButtons = NoButton; break;
case 1: _addLineButtons = SingleButton; break;
default:
case 2: _addLineButtons = DoubleButton; break;
}
switch( StyleConfigData::scrollBarSubLineButtons() )
{
case 0: _subLineButtons = NoButton; break;
case 1: _subLineButtons = SingleButton; break;
default:
case 2: _subLineButtons = DoubleButton; break;
}
// frame focus
if( StyleConfigData::viewDrawFocusIndicator() ) _frameFocusPrimitive = &Style::drawFrameFocusRectPrimitive;
else _frameFocusPrimitive = &Style::emptyPrimitive;
}
//___________________________________________________________________________________________________________________
QRect Style::pushButtonContentsRect( const QStyleOption* option, const QWidget* ) const
{ return insideMargin( option->rect, Metrics::Frame_FrameWidth ); }
//___________________________________________________________________________________________________________________
QRect Style::checkBoxContentsRect( const QStyleOption* option, const QWidget* ) const
{ return visualRect( option, option->rect.adjusted( Metrics::CheckBox_Size + Metrics::CheckBox_ItemSpacing, 0, 0, 0 ) ); }
//___________________________________________________________________________________________________________________
QRect Style::lineEditContentsRect( const QStyleOption* option, const QWidget* widget ) const
{
// cast option and check
const QStyleOptionFrame* frameOption( qstyleoption_cast<const QStyleOptionFrame*>( option ) );
if( !frameOption ) return option->rect;
// check flatness
const bool flat( frameOption->lineWidth == 0 );
if( flat ) return option->rect;
// copy rect and take out margins
QRect rect( option->rect );
// take out margins if there is enough room
const int frameWidth( pixelMetric( PM_DefaultFrameWidth, option, widget ) );
if( rect.height() > option->fontMetrics.height() + 2*frameWidth ) return insideMargin( rect, frameWidth );
else return rect;
}
//____________________________________________________________________
QRect Style::progressBarGrooveRect( const QStyleOption* option, const QWidget* ) const
{
const QRect rect( option->rect );
const auto progressBarOption2( qstyleoption_cast<const QStyleOptionProgressBar*>( option ) );
const bool horizontal( !progressBarOption2 || progressBarOption2->orientation == Qt::Horizontal );
if( horizontal ) return insideMargin( rect, 1, 0 );
else return insideMargin( rect, 0, 1 );
}
//____________________________________________________________________
QRect Style::progressBarContentsRect( const QStyleOption* option, const QWidget* widget ) const
{
// cast option and check
const QStyleOptionProgressBar* progressBarOption( qstyleoption_cast<const QStyleOptionProgressBar*>( option ) );
if( !progressBarOption ) return QRect();
// get orientation
const auto progressBarOption2( qstyleoption_cast<const QStyleOptionProgressBar*>( option ) );
const bool horizontal( !progressBarOption2 || progressBarOption2->orientation == Qt::Horizontal );
// check inverted appearance
const bool inverted( progressBarOption2 ? progressBarOption2->invertedAppearance : false );
// get groove rect
const QRect rect( progressBarGrooveRect( option, widget ) );
// get progress
qreal progress = progressBarOption->progress - progressBarOption->minimum;
const bool busy = ( progressBarOption->minimum == 0 && progressBarOption->maximum == 0 );
if( busy ) progress = _animations->busyIndicatorEngine().value();
if( !( progress || busy ) ) return QRect();
const int steps = qMax( progressBarOption->maximum - progressBarOption->minimum, 1 );
//Calculate width fraction
qreal widthFrac( busy ? qreal(Metrics::ProgressBar_BusyIndicatorSize)/100 : progress/steps );
widthFrac = qMin( (qreal)1, widthFrac );
// And now the pixel width
const int indicatorSize( widthFrac*( horizontal ? rect.width():rect.height() ) );
// do nothing if indicator size is too small
if( indicatorSize < 4 ) return QRect();
QRect indicatorRect;
if( busy )
{
// The space around which we move around...
int remSize = ( ( 1 - widthFrac )*( horizontal ? rect.width():rect.height() ) );
remSize = qMax( remSize, 1 );
int pstep = remSize*2*progress;
if( pstep > remSize )
{ pstep = -( pstep - 2*remSize ); }
if( horizontal ) {
indicatorRect = QRect( inverted ? (rect.right() - pstep - indicatorSize + 1) : (rect.left() + pstep), rect.top(), indicatorSize, rect.height() );
indicatorRect = visualRect( option->direction, rect, indicatorRect );
} else {
indicatorRect = QRect( rect.left(), inverted ? (rect.bottom() - pstep - indicatorSize + 1) : (rect.top() + pstep), rect.width(), indicatorSize );
}
} else {
if( horizontal )
{
indicatorRect = QRect( inverted ? (rect.right() - indicatorSize + 1) : rect.left(), rect.top(), indicatorSize, rect.height() );
indicatorRect = visualRect( option->direction, rect, indicatorRect );
} else {
indicatorRect = QRect( rect.left(), inverted ? rect.top() : (rect.bottom()- indicatorSize + 1), rect.width(), indicatorSize );
}
}
// adjust
return insideMargin( indicatorRect, 1 );
}
//___________________________________________________________________________________________________________________
QRect Style::headerArrowRect( const QStyleOption* option, const QWidget* ) const
{
// cast option and check
const QStyleOptionHeader* headerOption( qstyleoption_cast<const QStyleOptionHeader*>( option ) );
if( !headerOption ) return option->rect;
// check if arrow is necessary
if( headerOption->sortIndicator == QStyleOptionHeader::None ) return QRect();
QRect arrowRect( insideMargin( option->rect, Metrics::Header_MarginWidth ) );
arrowRect.setLeft( arrowRect.right() - Metrics::Header_ArrowSize + 1 );
return visualRect( option, arrowRect );
}
//___________________________________________________________________________________________________________________
QRect Style::headerLabelRect( const QStyleOption* option, const QWidget* ) const
{
// cast option and check
const QStyleOptionHeader* headerOption( qstyleoption_cast<const QStyleOptionHeader*>( option ) );
if( !headerOption ) return option->rect;
// check if arrow is necessary
// QRect labelRect( insideMargin( option->rect, Metrics::Header_MarginWidth ) );
QRect labelRect( insideMargin( option->rect, Metrics::Header_MarginWidth, 0 ) );
if( headerOption->sortIndicator == QStyleOptionHeader::None ) return labelRect;
labelRect.adjust( 0, 0, -Metrics::Header_ArrowSize-Metrics::Header_ItemSpacing, 0 );
return visualRect( option, labelRect );
}
//____________________________________________________________________
QRect Style::tabBarTabLeftButtonRect( const QStyleOption* option, const QWidget* ) const
{
// cast option and check
const auto tabOptionV3( qstyleoption_cast<const QStyleOptionTab*>( option ) );
if( !tabOptionV3 || tabOptionV3->leftButtonSize.isEmpty() ) return QRect();
const QRect rect( option->rect );
const QSize size( tabOptionV3->leftButtonSize );
QRect buttonRect( QPoint(0,0), size );
// vertical positioning
switch( tabOptionV3->shape )
{
case QTabBar::RoundedNorth:
case QTabBar::TriangularNorth:
case QTabBar::RoundedSouth:
case QTabBar::TriangularSouth:
buttonRect.moveLeft( rect.left() + Metrics::TabBar_TabMarginWidth );
buttonRect.moveTop( ( rect.height() - buttonRect.height() )/2 );
buttonRect = visualRect( option, buttonRect );
break;
case QTabBar::RoundedWest:
case QTabBar::TriangularWest:
buttonRect.moveBottom( rect.bottom() - Metrics::TabBar_TabMarginWidth );
buttonRect.moveLeft( ( rect.width() - buttonRect.width() )/2 );
break;
case QTabBar::RoundedEast:
case QTabBar::TriangularEast:
buttonRect.moveTop( rect.top() + Metrics::TabBar_TabMarginWidth );
buttonRect.moveLeft( ( rect.width() - buttonRect.width() )/2 );
break;
default: break;
}
return buttonRect;
}
//____________________________________________________________________
QRect Style::tabBarTabRightButtonRect( const QStyleOption* option, const QWidget* ) const
{
// cast option and check
const auto tabOptionV3( qstyleoption_cast<const QStyleOptionTab*>( option ) );
if( !tabOptionV3 || tabOptionV3->rightButtonSize.isEmpty() ) return QRect();
const QRect rect( option->rect );
const QSize size( tabOptionV3->rightButtonSize );
QRect buttonRect( QPoint(0,0), size );
// vertical positioning
switch( tabOptionV3->shape )
{
case QTabBar::RoundedNorth:
case QTabBar::TriangularNorth:
case QTabBar::RoundedSouth:
case QTabBar::TriangularSouth:
buttonRect.moveRight( rect.right() - Metrics::TabBar_TabMarginWidth );
buttonRect.moveTop( ( rect.height() - buttonRect.height() )/2 );
buttonRect = visualRect( option, buttonRect );
break;
case QTabBar::RoundedWest:
case QTabBar::TriangularWest:
buttonRect.moveTop( rect.top() + Metrics::TabBar_TabMarginWidth );
buttonRect.moveLeft( ( rect.width() - buttonRect.width() )/2 );
break;
case QTabBar::RoundedEast:
case QTabBar::TriangularEast:
buttonRect.moveBottom( rect.bottom() - Metrics::TabBar_TabMarginWidth );
buttonRect.moveLeft( ( rect.width() - buttonRect.width() )/2 );
break;
default: break;
}
return buttonRect;
}
//____________________________________________________________________
QRect Style::tabWidgetTabBarRect( const QStyleOption* option, const QWidget* widget ) const
{
// cast option and check
const QStyleOptionTabWidgetFrame* tabOption = qstyleoption_cast<const QStyleOptionTabWidgetFrame*>( option );
if( !tabOption ) return KStyle::subElementRect( SE_TabWidgetTabBar, option, widget );
// do nothing if tabbar is hidden
const QSize tabBarSize( tabOption->tabBarSize );
QRect rect( option->rect );
QRect tabBarRect( QPoint(0, 0), tabBarSize );
// horizontal positioning
const bool verticalTabs( isVerticalTab( tabOption->shape ) );
if( verticalTabs )
{
tabBarRect.setHeight( qMin( tabBarRect.height(), rect.height() - 2 ) );
tabBarRect.moveTop( rect.top()+1 );
} else {
// account for corner rects
// need to re-run visualRect to remove right-to-left handling, since it is re-added on tabBarRect at the end
const QRect leftButtonRect( visualRect( option, subElementRect( SE_TabWidgetLeftCorner, option, widget ) ) );
const QRect rightButtonRect( visualRect( option, subElementRect( SE_TabWidgetRightCorner, option, widget ) ) );
rect.setLeft( leftButtonRect.width() );
rect.setRight( rightButtonRect.left() - 1 );
tabBarRect.setWidth( qMin( tabBarRect.width(), rect.width() - 2 ) );
tabBarRect.moveLeft( rect.left() + 1 );
tabBarRect = visualRect( option, tabBarRect );
}
// vertical positioning
switch( tabOption->shape )
{
case QTabBar::RoundedNorth:
case QTabBar::TriangularNorth:
tabBarRect.moveTop( rect.top()+1 );
break;
case QTabBar::RoundedSouth:
case QTabBar::TriangularSouth:
tabBarRect.moveBottom( rect.bottom()-1 );
break;
case QTabBar::RoundedWest:
case QTabBar::TriangularWest:
tabBarRect.moveLeft( rect.left()+1 );
break;
case QTabBar::RoundedEast:
case QTabBar::TriangularEast:
tabBarRect.moveRight( rect.right()-1 );
break;
default: break;
}
return tabBarRect;
}
//____________________________________________________________________
QRect Style::tabWidgetTabContentsRect( const QStyleOption* option, const QWidget* widget ) const
{
// cast option and check
const QStyleOptionTabWidgetFrame* tabOption = qstyleoption_cast<const QStyleOptionTabWidgetFrame*>( option );
if( !tabOption ) return option->rect;
// do nothing if tabbar is hidden
if( tabOption->tabBarSize.isEmpty() ) return option->rect;
const QRect rect = tabWidgetTabPaneRect( option, widget );
const bool documentMode( tabOption->lineWidth == 0 );
if( documentMode )
{
// add margin only to the relevant side
switch( tabOption->shape )
{
case QTabBar::RoundedNorth:
case QTabBar::TriangularNorth:
return rect.adjusted( 0, Metrics::TabWidget_MarginWidth, 0, 0 );
case QTabBar::RoundedSouth:
case QTabBar::TriangularSouth:
return rect.adjusted( 0, 0, 0, -Metrics::TabWidget_MarginWidth );
case QTabBar::RoundedWest:
case QTabBar::TriangularWest:
return rect.adjusted( Metrics::TabWidget_MarginWidth, 0, 0, 0 );
case QTabBar::RoundedEast:
case QTabBar::TriangularEast:
return rect.adjusted( 0, 0, -Metrics::TabWidget_MarginWidth, 0 );
default: return rect;
}
} else return insideMargin( rect, Metrics::TabWidget_MarginWidth );
}
//____________________________________________________________________
QRect Style::tabWidgetTabPaneRect( const QStyleOption* option, const QWidget* ) const
{
const QStyleOptionTabWidgetFrame* tabOption = qstyleoption_cast<const QStyleOptionTabWidgetFrame*>( option );
if( !tabOption || tabOption->tabBarSize.isEmpty() ) return option->rect;
const int overlap = Metrics::TabBar_BaseOverlap - 1;
const QSize tabBarSize( tabOption->tabBarSize - QSize( overlap, overlap ) );
QRect rect( option->rect );
switch( tabOption->shape )
{
case QTabBar::RoundedNorth:
case QTabBar::TriangularNorth:
rect.adjust( 0, tabBarSize.height(), 0, 0 );
break;
case QTabBar::RoundedSouth:
case QTabBar::TriangularSouth:
rect.adjust( 0, 0, 0, -tabBarSize.height() );
break;
case QTabBar::RoundedWest:
case QTabBar::TriangularWest:
rect.adjust( tabBarSize.width(), 0, 0, 0 );
break;
case QTabBar::RoundedEast:
case QTabBar::TriangularEast:
rect.adjust( 0, 0, -tabBarSize.width(), 0 );
break;
default: break;
}
return rect;
}
//____________________________________________________________________
QRect Style::tabWidgetCornerRect( SubElement element, const QStyleOption* option, const QWidget* widget ) const
{
// cast option and check
const QStyleOptionTabWidgetFrame *tabOption = qstyleoption_cast<const QStyleOptionTabWidgetFrame *>( option );
if( !tabOption ) return QRect();
// copy rect
const QRect paneRect( subElementRect( SE_TabWidgetTabPane, option, widget ) );
QRect rect;
switch( element )
{
case SE_TabWidgetLeftCorner:
rect = QRect( QPoint(0,0), tabOption->leftCornerWidgetSize );
break;
case SE_TabWidgetRightCorner:
rect = QRect( QPoint(0,0), tabOption->rightCornerWidgetSize );
break;
default: break;
}
if( element == SE_TabWidgetRightCorner ) rect.moveRight( paneRect.right() );
else rect.moveLeft( paneRect.left() );
switch( tabOption->shape )
{
case QTabBar::RoundedNorth:
case QTabBar::TriangularNorth:
rect.moveBottom( paneRect.top() - 1 );
rect.translate( 0, 3 );
break;
case QTabBar::RoundedSouth:
case QTabBar::TriangularSouth:
rect.moveTop( paneRect.bottom() + 1 );
rect.translate( 0, -3 );
break;
default:
return QRect();
}
rect = visualRect( tabOption, rect );
return rect;
}
//____________________________________________________________________
QRect Style::toolBoxTabContentsRect( const QStyleOption* option, const QWidget* widget ) const
{
// cast option and check
const QStyleOptionToolBox* toolBoxOption( qstyleoption_cast<const QStyleOptionToolBox *>( option ) );
if( !toolBoxOption ) return option->rect;
// copy rect
const QRect& rect( option->rect );
int contentsWidth(0);
if( !toolBoxOption->icon.isNull() )
{
const int iconSize( pixelMetric( QStyle::PM_SmallIconSize, option, widget ) );
contentsWidth += iconSize;
if( !toolBoxOption->text.isEmpty() ) contentsWidth += Metrics::ToolBox_TabItemSpacing;
}
if( !toolBoxOption->text.isEmpty() )
{
const int textWidth = toolBoxOption->fontMetrics.size( _mnemonics->textFlags(), toolBoxOption->text ).width();
contentsWidth += textWidth;
}
contentsWidth = qMin( contentsWidth, rect.width() );
contentsWidth = qMax( contentsWidth, int(Metrics::ToolBox_TabMinWidth) );
return centerRect( rect, contentsWidth, rect.height() );
}
//______________________________________________________________
QRect Style::groupBoxSubControlRect( const QStyleOptionComplex* option, SubControl subControl, const QWidget* widget ) const
{
QRect rect = option->rect;
switch( subControl )
{
case SC_GroupBoxFrame: return rect;
case SC_GroupBoxContents:
{
// cast option and check
const QStyleOptionGroupBox *groupBoxOption = qstyleoption_cast<const QStyleOptionGroupBox*>( option );
if( !groupBoxOption ) break;
// take out frame width
rect = insideMargin( rect, Metrics::Frame_FrameWidth );
// get state
const bool checkable( groupBoxOption->subControls & QStyle::SC_GroupBoxCheckBox );
const bool emptyText( groupBoxOption->text.isEmpty() );
// calculate title height
int titleHeight( 0 );
if( !emptyText ) titleHeight = groupBoxOption->fontMetrics.height();
if( checkable ) titleHeight = qMax( titleHeight, int(Metrics::CheckBox_Size) );
// add margin
if( titleHeight > 0 ) titleHeight += 2*Metrics::GroupBox_TitleMarginWidth;
rect.adjust( 0, titleHeight, 0, 0 );
return rect;
}
case SC_GroupBoxCheckBox:
case SC_GroupBoxLabel:
{
// cast option and check
const QStyleOptionGroupBox *groupBoxOption = qstyleoption_cast<const QStyleOptionGroupBox*>( option );
if( !groupBoxOption ) break;
// take out frame width
rect = insideMargin( rect, Metrics::Frame_FrameWidth );
const bool emptyText( groupBoxOption->text.isEmpty() );
const bool checkable( groupBoxOption->subControls & QStyle::SC_GroupBoxCheckBox );
// calculate title height
int titleHeight( 0 );
int titleWidth( 0 );
if( !emptyText )
{
const QFontMetrics fontMetrics = option->fontMetrics;
titleHeight = qMax( titleHeight, fontMetrics.height() );
titleWidth += fontMetrics.size( _mnemonics->textFlags(), groupBoxOption->text ).width();
}
if( checkable )
{
titleHeight = qMax( titleHeight, int(Metrics::CheckBox_Size) );
titleWidth += Metrics::CheckBox_Size;
if( !emptyText ) titleWidth += Metrics::CheckBox_ItemSpacing;
}
// adjust height
QRect titleRect( rect );
titleRect.setHeight( titleHeight );
titleRect.translate( 0, Metrics::GroupBox_TitleMarginWidth );
// center
titleRect = centerRect( titleRect, titleWidth, titleHeight );
if( subControl == SC_GroupBoxCheckBox )
{
// vertical centering
titleRect = centerRect( titleRect, titleWidth, Metrics::CheckBox_Size );
// horizontal positioning
const QRect subRect( titleRect.topLeft(), QSize( Metrics::CheckBox_Size, titleRect.height() ) );
return visualRect( option->direction, titleRect, subRect );
} else {
// vertical centering
QFontMetrics fontMetrics = option->fontMetrics;
titleRect = centerRect( titleRect, titleWidth, fontMetrics.height() );
// horizontal positioning
QRect subRect( titleRect );
if( checkable ) subRect.adjust( Metrics::CheckBox_Size + Metrics::CheckBox_ItemSpacing, 0, 0, 0 );
return visualRect( option->direction, titleRect, subRect );
}
}
default: break;
}
return KStyle::subControlRect( CC_GroupBox, option, subControl, widget );
}
//___________________________________________________________________________________________________________________
QRect Style::toolButtonSubControlRect( const QStyleOptionComplex* option, SubControl subControl, const QWidget* widget ) const
{
// cast option and check
const QStyleOptionToolButton* toolButtonOption = qstyleoption_cast<const QStyleOptionToolButton*>( option );
if( !toolButtonOption ) return KStyle::subControlRect( CC_ToolButton, option, subControl, widget );
const bool hasPopupMenu( toolButtonOption->features & QStyleOptionToolButton::MenuButtonPopup );
const bool hasInlineIndicator(
toolButtonOption->features&QStyleOptionToolButton::HasMenu
&& toolButtonOption->features&QStyleOptionToolButton::PopupDelay
&& !hasPopupMenu );
// store rect
const QRect& rect( option->rect );
const int menuButtonWidth( Metrics::MenuButton_IndicatorWidth );
switch( subControl )
{
case SC_ToolButtonMenu:
{
// check fratures
if( !(hasPopupMenu || hasInlineIndicator ) ) return QRect();
// check features
QRect menuRect( rect );
menuRect.setLeft( rect.right() - menuButtonWidth + 1 );
if( hasInlineIndicator )
{ menuRect.setTop( menuRect.bottom() - menuButtonWidth + 1 ); }
return visualRect( option, menuRect );
}
case SC_ToolButton:
{
if( hasPopupMenu )
{
QRect contentsRect( rect );
contentsRect.setRight( rect.right() - menuButtonWidth );
return visualRect( option, contentsRect );
} else return rect;
}
default: return QRect();
}
}
//___________________________________________________________________________________________________________________
QRect Style::comboBoxSubControlRect( const QStyleOptionComplex* option, SubControl subControl, const QWidget* widget ) const
{
// cast option and check
const QStyleOptionComboBox *comboBoxOption( qstyleoption_cast<const QStyleOptionComboBox*>( option ) );
if( !comboBoxOption ) return KStyle::subControlRect( CC_ComboBox, option, subControl, widget );
const bool editable( comboBoxOption->editable );
const bool flat( editable && !comboBoxOption->frame );
// copy rect
QRect rect( option->rect );
switch( subControl )
{
case SC_ComboBoxFrame: return flat ? rect : QRect();
case SC_ComboBoxListBoxPopup: return rect;
case SC_ComboBoxArrow:
{
// take out frame width
if( !flat ) rect = insideMargin( rect, Metrics::Frame_FrameWidth );
QRect arrowRect(
rect.right() - Metrics::MenuButton_IndicatorWidth + 1,
rect.top(),
Metrics::MenuButton_IndicatorWidth,
rect.height() );
arrowRect = centerRect( arrowRect, Metrics::MenuButton_IndicatorWidth, Metrics::MenuButton_IndicatorWidth );
return visualRect( option, arrowRect );
}
case SC_ComboBoxEditField:
{
QRect labelRect;
const int frameWidth( pixelMetric( PM_ComboBoxFrameWidth, option, widget ) );
labelRect = QRect(
rect.left(), rect.top(),
rect.width() - Metrics::MenuButton_IndicatorWidth,
rect.height() );
// remove margins
if( !flat && rect.height() > option->fontMetrics.height() + 2*frameWidth )
{ labelRect.adjust( frameWidth, frameWidth, 0, -frameWidth ); }
return visualRect( option, labelRect );
}
default: break;
}
return KStyle::subControlRect( CC_ComboBox, option, subControl, widget );
}
//___________________________________________________________________________________________________________________
QRect Style::spinBoxSubControlRect( const QStyleOptionComplex* option, SubControl subControl, const QWidget* widget ) const
{
// cast option and check
const QStyleOptionSpinBox *spinBoxOption( qstyleoption_cast<const QStyleOptionSpinBox*>( option ) );
if( !spinBoxOption ) return KStyle::subControlRect( CC_SpinBox, option, subControl, widget );
const bool flat( !spinBoxOption->frame );
// copy rect
QRect rect( option->rect );
switch( subControl )
{
case SC_SpinBoxFrame: return flat ? QRect():rect;
case SC_SpinBoxUp:
case SC_SpinBoxDown:
{
// take out frame width
if( !flat && rect.height() >= 2*Metrics::Frame_FrameWidth + Metrics::SpinBox_ArrowButtonWidth ) rect = insideMargin( rect, Metrics::Frame_FrameWidth );
QRect arrowRect;
arrowRect = QRect(
rect.right() - Metrics::SpinBox_ArrowButtonWidth + 1,
rect.top(),
Metrics::SpinBox_ArrowButtonWidth,
rect.height() );
const int arrowHeight( qMin( rect.height(), int(Metrics::SpinBox_ArrowButtonWidth) ) );
arrowRect = centerRect( arrowRect, Metrics::SpinBox_ArrowButtonWidth, arrowHeight );
arrowRect.setHeight( arrowHeight/2 );
if( subControl == SC_SpinBoxDown ) arrowRect.translate( 0, arrowHeight/2 );
return visualRect( option, arrowRect );
}
case SC_SpinBoxEditField:
{
QRect labelRect;
labelRect = QRect(
rect.left(), rect.top(),
rect.width() - Metrics::SpinBox_ArrowButtonWidth,
rect.height() );
// remove right side line editor margins
const int frameWidth( pixelMetric( PM_SpinBoxFrameWidth, option, widget ) );
if( !flat && labelRect.height() > option->fontMetrics.height() + 2*frameWidth )
{ labelRect.adjust( frameWidth, frameWidth, 0, -frameWidth ); }
return visualRect( option, labelRect );
}
default: break;
}
return KStyle::subControlRect( CC_SpinBox, option, subControl, widget );
}
//___________________________________________________________________________________________________________________
QRect Style::scrollBarInternalSubControlRect( const QStyleOptionComplex* option, SubControl subControl ) const
{
const QRect& rect = option->rect;
const State& state( option->state );
const bool horizontal( state & State_Horizontal );
switch( subControl )
{
case SC_ScrollBarSubLine:
{
int majorSize( scrollBarButtonHeight( _subLineButtons ) );
if( horizontal ) return visualRect( option, QRect( rect.left(), rect.top(), majorSize, rect.height() ) );
else return visualRect( option, QRect( rect.left(), rect.top(), rect.width(), majorSize ) );
}
case SC_ScrollBarAddLine:
{
int majorSize( scrollBarButtonHeight( _addLineButtons ) );
if( horizontal ) return visualRect( option, QRect( rect.right() - majorSize + 1, rect.top(), majorSize, rect.height() ) );
else return visualRect( option, QRect( rect.left(), rect.bottom() - majorSize + 1, rect.width(), majorSize ) );
}
default: return QRect();
}
}
//___________________________________________________________________________________________________________________
QRect Style::scrollBarSubControlRect( const QStyleOptionComplex* option, SubControl subControl, const QWidget* widget ) const
{
// cast option and check
const QStyleOptionSlider* sliderOption( qstyleoption_cast<const QStyleOptionSlider*>( option ) );
if( !sliderOption ) return KStyle::subControlRect( CC_ScrollBar, option, subControl, widget );
// get relevant state
const State& state( option->state );
const bool horizontal( state & State_Horizontal );
switch( subControl )
{
case SC_ScrollBarSubLine:
case SC_ScrollBarAddLine:
return scrollBarInternalSubControlRect( option, subControl );
case SC_ScrollBarGroove:
{
QRect topRect = visualRect( option, scrollBarInternalSubControlRect( option, SC_ScrollBarSubLine ) );
QRect bottomRect = visualRect( option, scrollBarInternalSubControlRect( option, SC_ScrollBarAddLine ) );
QPoint topLeftCorner;
QPoint botRightCorner;
if( horizontal )
{
topLeftCorner = QPoint( topRect.right() + 1, topRect.top() );
botRightCorner = QPoint( bottomRect.left() - 1, topRect.bottom() );
} else {
topLeftCorner = QPoint( topRect.left(), topRect.bottom() + 1 );
botRightCorner = QPoint( topRect.right(), bottomRect.top() - 1 );
}
// define rect
return visualRect( option, QRect( topLeftCorner, botRightCorner ) );
}
case SC_ScrollBarSlider:
{
// We handle RTL here to unreflect things if need be
QRect groove = visualRect( option, subControlRect( CC_ScrollBar, option, SC_ScrollBarGroove, widget ) );
if( sliderOption->minimum == sliderOption->maximum ) return groove;
//Figure out how much room we have..
int space( horizontal ? groove.width() : groove.height() );
//Calculate the portion of this space that the slider should take up.
int sliderSize = space * qreal( sliderOption->pageStep ) / ( sliderOption->maximum - sliderOption->minimum + sliderOption->pageStep );
sliderSize = qMax( sliderSize, static_cast<int>(Metrics::ScrollBar_MinSliderHeight ) );
sliderSize = qMin( sliderSize, space );
space -= sliderSize;
if( space <= 0 ) return groove;
int pos = qRound( qreal( sliderOption->sliderPosition - sliderOption->minimum )/ ( sliderOption->maximum - sliderOption->minimum )*space );
if( sliderOption->upsideDown ) pos = space - pos;
if( horizontal ) return visualRect( option, QRect( groove.left() + pos, groove.top(), sliderSize, groove.height() ) );
else return visualRect( option, QRect( groove.left(), groove.top() + pos, groove.width(), sliderSize ) );
}
case SC_ScrollBarSubPage:
{
//We do visualRect here to unreflect things if need be
QRect slider = visualRect( option, subControlRect( CC_ScrollBar, option, SC_ScrollBarSlider, widget ) );
QRect groove = visualRect( option, subControlRect( CC_ScrollBar, option, SC_ScrollBarGroove, widget ) );
if( horizontal ) return visualRect( option, QRect( groove.left(), groove.top(), slider.left() - groove.left(), groove.height() ) );
else return visualRect( option, QRect( groove.left(), groove.top(), groove.width(), slider.top() - groove.top() ) );
}
case SC_ScrollBarAddPage:
{
//We do visualRect here to unreflect things if need be
QRect slider = visualRect( option, subControlRect( CC_ScrollBar, option, SC_ScrollBarSlider, widget ) );
QRect groove = visualRect( option, subControlRect( CC_ScrollBar, option, SC_ScrollBarGroove, widget ) );
if( horizontal ) return visualRect( option, QRect( slider.right() + 1, groove.top(), groove.right() - slider.right(), groove.height() ) );
else return visualRect( option, QRect( groove.left(), slider.bottom() + 1, groove.width(), groove.bottom() - slider.bottom() ) );
}
default: return KStyle::subControlRect( CC_ScrollBar, option, subControl, widget );;
}
}
//___________________________________________________________________________________________________________________
QRect Style::sliderSubControlRect( const QStyleOptionComplex* option, SubControl subControl, const QWidget* widget ) const
{
// cast option and check
const QStyleOptionSlider* sliderOption( qstyleoption_cast<const QStyleOptionSlider*>( option ) );
if( !sliderOption ) return KStyle::subControlRect( CC_Slider, option, subControl, widget );
switch( subControl )
{
case SC_SliderGroove:
{
// direction
const bool horizontal( sliderOption->orientation == Qt::Horizontal );
// get base class rect
QRect grooveRect( KStyle::subControlRect( CC_Slider, option, subControl, widget ) );
grooveRect = insideMargin( grooveRect, pixelMetric( PM_DefaultFrameWidth, option, widget ) );
// centering
if( horizontal )
{
grooveRect = centerRect( grooveRect, grooveRect.width(), Metrics::Slider_GrooveThickness );
grooveRect = insideMargin( grooveRect, 3, 0 );
} else {
grooveRect = centerRect( grooveRect, Metrics::Slider_GrooveThickness, grooveRect.height() );
grooveRect = insideMargin( grooveRect, 0, 3 );
}
return grooveRect;
}
case SC_SliderHandle:
{
QRect handleRect( KStyle::subControlRect( CC_Slider, option, subControl, widget ) );
handleRect = centerRect( handleRect, Metrics::Slider_ControlThickness, Metrics::Slider_ControlThickness );
return handleRect;
}
default: return KStyle::subControlRect( CC_Slider, option, subControl, widget );
}
}
//______________________________________________________________
QSize Style::checkBoxSizeFromContents( const QStyleOption*, const QSize& contentsSize, const QWidget* ) const
{
// get contents size
QSize size( contentsSize );
// add focus height
size = expandSize( size, 0, Metrics::CheckBox_FocusMarginWidth );
// make sure there is enough height for indicator
size.setHeight( qMax( size.height(), int(Metrics::CheckBox_Size) ) );
// Add space for the indicator and the icon
size.rwidth() += Metrics::CheckBox_Size + Metrics::CheckBox_ItemSpacing;
// also add extra space, to leave room to the right of the label
size.rwidth() += Metrics::CheckBox_ItemSpacing;
return size;
}
//______________________________________________________________
QSize Style::lineEditSizeFromContents( const QStyleOption* option, const QSize& contentsSize, const QWidget* widget ) const
{
// cast option and check
const QStyleOptionFrame* frameOption( qstyleoption_cast<const QStyleOptionFrame*>( option ) );
if( !frameOption ) return contentsSize;
const bool flat( frameOption->lineWidth == 0 );
const int frameWidth( pixelMetric( PM_DefaultFrameWidth, option, widget ) );
return flat ? contentsSize : expandSize( contentsSize, frameWidth );
}
//______________________________________________________________
QSize Style::comboBoxSizeFromContents( const QStyleOption* option, const QSize& contentsSize, const QWidget* widget ) const
{
// cast option and check
const QStyleOptionComboBox* comboBoxOption( qstyleoption_cast<const QStyleOptionComboBox*>( option ) );
if( !comboBoxOption ) return contentsSize;
// copy size
QSize size( contentsSize );
// add relevant margin
const bool flat( !comboBoxOption->frame );
const int frameWidth( pixelMetric( PM_ComboBoxFrameWidth, option, widget ) );
if( !flat ) size = expandSize( size, frameWidth );
// make sure there is enough height for the button
size.setHeight( qMax( size.height(), int(Metrics::MenuButton_IndicatorWidth) ) );
// add button width and spacing
size.rwidth() += Metrics::MenuButton_IndicatorWidth;
return size;
}
//______________________________________________________________
QSize Style::spinBoxSizeFromContents( const QStyleOption* option, const QSize& contentsSize, const QWidget* widget ) const
{
// cast option and check
const QStyleOptionSpinBox *spinBoxOption( qstyleoption_cast<const QStyleOptionSpinBox*>( option ) );
if( !spinBoxOption ) return contentsSize;
const bool flat( !spinBoxOption->frame );
// copy size
QSize size( contentsSize );
// add editor margins
const int frameWidth( pixelMetric( PM_SpinBoxFrameWidth, option, widget ) );
if( !flat ) size = expandSize( size, frameWidth );
// make sure there is enough height for the button
size.setHeight( qMax( size.height(), int(Metrics::SpinBox_ArrowButtonWidth) ) );
// add button width and spacing
size.rwidth() += Metrics::SpinBox_ArrowButtonWidth;
return size;
}
//______________________________________________________________
QSize Style::sliderSizeFromContents( const QStyleOption* option, const QSize& contentsSize, const QWidget* ) const
{
// cast option and check
const QStyleOptionSlider *sliderOption( qstyleoption_cast<const QStyleOptionSlider*>( option ) );
if( !sliderOption ) return contentsSize;
// store tick position and orientation
const QSlider::TickPosition& tickPosition( sliderOption->tickPosition );
const bool horizontal( sliderOption->orientation == Qt::Horizontal );
const bool disableTicks( !StyleConfigData::sliderDrawTickMarks() );
/*
Qt adds its own tick length directly inside QSlider.
Take it out and replace by ours, if needed
*/
const int tickLength( disableTicks ? 0 : (
Metrics::Slider_TickLength + Metrics::Slider_TickMarginWidth +
(Metrics::Slider_GrooveThickness - Metrics::Slider_ControlThickness)/2 ) );
const int builtInTickLength( 5 );
if( tickPosition == QSlider::NoTicks ) return contentsSize;
QSize size( contentsSize );
if( horizontal )
{
if(tickPosition & QSlider::TicksAbove) size.rheight() += tickLength - builtInTickLength;
if(tickPosition & QSlider::TicksBelow) size.rheight() += tickLength - builtInTickLength;
} else {
if(tickPosition & QSlider::TicksAbove) size.rwidth() += tickLength - builtInTickLength;
if(tickPosition & QSlider::TicksBelow) size.rwidth() += tickLength - builtInTickLength;
}
return size;
}
//______________________________________________________________
QSize Style::pushButtonSizeFromContents( const QStyleOption* option, const QSize& contentsSize, const QWidget* widget ) const
{
// cast option and check
const QStyleOptionButton* buttonOption( qstyleoption_cast<const QStyleOptionButton*>( option ) );
if( !buttonOption ) return contentsSize;
QSize size( contentsSize );
// add space for arrow
if( buttonOption->features & QStyleOptionButton::HasMenu )
{
size.rheight() += 2*Metrics::Button_MarginWidth;
size.setHeight( qMax( size.height(), int( Metrics::MenuButton_IndicatorWidth ) ) );
size.rwidth() += Metrics::Button_MarginWidth;
if( !( buttonOption->icon.isNull() && buttonOption->text.isEmpty() ) )
{ size.rwidth() += Metrics::Button_ItemSpacing; }
} else size = expandSize( size, Metrics::Button_MarginWidth );
// add space for icon
if( !buttonOption->icon.isNull() )
{
QSize iconSize = buttonOption->iconSize;
if( !iconSize.isValid() ) iconSize = QSize( pixelMetric( PM_SmallIconSize, option, widget ), pixelMetric( PM_SmallIconSize, option, widget ) );
size.setHeight( qMax( size.height(), iconSize.height() ) );
if( !buttonOption->text.isEmpty() )
{ size.rwidth() += Metrics::Button_ItemSpacing; }
}
// make sure buttons have a minimum width
if( !buttonOption->text.isEmpty() )
{ size.rwidth() = qMax( size.rwidth(), int( Metrics::Button_MinWidth ) ); }
// finally add margins
return expandSize( size, Metrics::Frame_FrameWidth );
}
//______________________________________________________________
QSize Style::toolButtonSizeFromContents( const QStyleOption* option, const QSize& contentsSize, const QWidget* ) const
{
// cast option and check
const QStyleOptionToolButton* toolButtonOption = qstyleoption_cast<const QStyleOptionToolButton*>( option );
if( !toolButtonOption ) return contentsSize;
// copy size
QSize size = contentsSize;
// get relevant state flags
const State& state( option->state );
const bool autoRaise( state & State_AutoRaise );
const bool hasPopupMenu( toolButtonOption->features & QStyleOptionToolButton::MenuButtonPopup );
const bool hasInlineIndicator(
toolButtonOption->features&QStyleOptionToolButton::HasMenu
&& toolButtonOption->features&QStyleOptionToolButton::PopupDelay
&& !hasPopupMenu );
const int marginWidth( autoRaise ? Metrics::ToolButton_MarginWidth : Metrics::Button_MarginWidth + Metrics::Frame_FrameWidth );
if( hasInlineIndicator ) size.rwidth() += Metrics::ToolButton_InlineIndicatorWidth;
size = expandSize( size, marginWidth );
return size;
}
//______________________________________________________________
QSize Style::menuBarItemSizeFromContents( const QStyleOption*, const QSize& contentsSize, const QWidget* ) const
{ return expandSize( contentsSize, Metrics::MenuBarItem_MarginWidth, Metrics::MenuBarItem_MarginHeight ); }
//______________________________________________________________
QSize Style::menuItemSizeFromContents( const QStyleOption* option, const QSize& contentsSize, const QWidget* widget ) const
{
// cast option and check
const QStyleOptionMenuItem* menuItemOption = qstyleoption_cast<const QStyleOptionMenuItem*>( option );
if( !menuItemOption ) return contentsSize;
// First, we calculate the intrinsic size of the item.
// this must be kept consistent with what's in drawMenuItemControl
QSize size( contentsSize );
switch( menuItemOption->menuItemType )
{
case QStyleOptionMenuItem::Normal:
case QStyleOptionMenuItem::DefaultItem:
case QStyleOptionMenuItem::SubMenu:
{
const int iconWidth( isQtQuickControl( option, widget ) ? qMax( pixelMetric(PM_SmallIconSize, option, widget ), menuItemOption->maxIconWidth ) : menuItemOption->maxIconWidth );
int leftColumnWidth( iconWidth );
// add space with respect to text
leftColumnWidth += Metrics::MenuItem_ItemSpacing;
// add checkbox indicator width
if( menuItemOption->menuHasCheckableItems )
{ leftColumnWidth += Metrics::CheckBox_Size + Metrics::MenuItem_ItemSpacing; }
// add spacing for accelerator
/*
Note:
The width of the accelerator itself is not included here since
Qt will add that on separately after obtaining the
sizeFromContents() for each menu item in the menu to be shown
( see QMenuPrivate::calcActionRects() )
*/
const bool hasAccelerator( menuItemOption->text.indexOf( QLatin1Char( '\t' ) ) >= 0 );
if( hasAccelerator ) size.rwidth() += Metrics::MenuItem_AcceleratorSpace;
// right column
const int rightColumnWidth = Metrics::MenuButton_IndicatorWidth + Metrics::MenuItem_ItemSpacing;
size.rwidth() += leftColumnWidth + rightColumnWidth;
// make sure height is large enough for icon and arrow
size.setHeight( qMax( size.height(), int(Metrics::MenuButton_IndicatorWidth) ) );
size.setHeight( qMax( size.height(), int(Metrics::CheckBox_Size) ) );
size.setHeight( qMax( size.height(), iconWidth ) );
return expandSize( size, Metrics::MenuItem_MarginWidth );
}
case QStyleOptionMenuItem::Separator:
{
if( menuItemOption->text.isEmpty() && menuItemOption->icon.isNull() )
{
return expandSize( QSize(0,1), Metrics::MenuItem_MarginWidth );
} else {
// build toolbutton option
const QStyleOptionToolButton toolButtonOption( separatorMenuItemOption( menuItemOption, widget ) );
// make sure height is large enough for icon and text
const int iconWidth( qMax( pixelMetric(PM_SmallIconSize, option, widget ), menuItemOption->maxIconWidth ) );
const int textHeight( menuItemOption->fontMetrics.height() );
if( !menuItemOption->icon.isNull() ) size.setHeight( qMax( size.height(), iconWidth ) );
if( !menuItemOption->text.isEmpty() )
{
size.setHeight( qMax( size.height(), textHeight ) );
size.setWidth( qMax( size.width(), menuItemOption->fontMetrics.width( menuItemOption->text ) ) );
}
return sizeFromContents( CT_ToolButton, &toolButtonOption, size, widget );
}
}
// for all other cases, return input
default: return contentsSize;
}
}
//______________________________________________________________
QSize Style::tabWidgetSizeFromContents( const QStyleOption*, const QSize& contentsSize, const QWidget* ) const
{ return expandSize( contentsSize, Metrics::TabWidget_MarginWidth ); }
//______________________________________________________________
QSize Style::tabBarTabSizeFromContents( const QStyleOption* option, const QSize& contentsSize, const QWidget* ) const
{
const auto tabOption( qstyleoption_cast<const QStyleOptionTab*>( option ) );
const auto tabOptionV3( qstyleoption_cast<const QStyleOptionTab*>( option ) );
const bool hasText( tabOption && !tabOption->text.isEmpty() );
const bool hasIcon( tabOption && !tabOption->icon.isNull() );
const bool hasLeftButton( tabOptionV3 && !tabOptionV3->leftButtonSize.isEmpty() );
const bool hasRightButton( tabOptionV3 && !tabOptionV3->leftButtonSize.isEmpty() );
// calculate width increment for horizontal tabs
int widthIncrement = 0;
if( hasIcon && !( hasText || hasLeftButton || hasRightButton ) ) widthIncrement -= 4;
if( hasText && hasIcon ) widthIncrement += Metrics::TabBar_TabItemSpacing;
if( hasLeftButton && ( hasText || hasIcon ) ) widthIncrement += Metrics::TabBar_TabItemSpacing;
if( hasRightButton && ( hasText || hasIcon || hasLeftButton ) ) widthIncrement += Metrics::TabBar_TabItemSpacing;
// add margins
QSize size( contentsSize );
// compare to minimum size
const bool verticalTabs( tabOption && isVerticalTab( tabOption ) );
if( verticalTabs )
{
size.rwidth() += 2*Metrics::TabBar_TabOffset;
size.rheight() += widthIncrement;
if( hasIcon && !hasText ) size = size.expandedTo( QSize( Metrics::TabBar_TabMinHeight, 0 ) );
else size = size.expandedTo( QSize( Metrics::TabBar_TabMinHeight, Metrics::TabBar_TabMinWidth ) );
} else {
size.rheight() += 2*Metrics::TabBar_TabOffset;
size.rwidth() += widthIncrement;
if( hasIcon && !hasText ) size = size.expandedTo( QSize( 0, Metrics::TabBar_TabMinHeight ) );
else size = size.expandedTo( QSize( Metrics::TabBar_TabMinWidth, Metrics::TabBar_TabMinHeight ) );
}
return size;
}
//______________________________________________________________
QSize Style::headerSectionSizeFromContents( const QStyleOption* option, const QSize& contentsSize, const QWidget* ) const
{
// cast option and check
const QStyleOptionHeader* headerOption( qstyleoption_cast<const QStyleOptionHeader*>( option ) );
if( !headerOption ) return contentsSize;
// get text size
const bool horizontal( headerOption->orientation == Qt::Horizontal );
const bool hasText( !headerOption->text.isEmpty() );
const bool hasIcon( !headerOption->icon.isNull() );
const QSize textSize( hasText ? headerOption->fontMetrics.size( 0, headerOption->text ) : QSize() );
const QSize iconSize( hasIcon ? QSize( 22,22 ) : QSize() );
// contents width
int contentsWidth( 0 );
if( hasText ) contentsWidth += textSize.width();
if( hasIcon )
{
contentsWidth += iconSize.width();
if( hasText ) contentsWidth += Metrics::Header_ItemSpacing;
}
// contents height
int contentsHeight( headerOption->fontMetrics.height() );
if( hasIcon ) contentsHeight = qMax( contentsHeight, iconSize.height() );
if( horizontal && headerOption->sortIndicator != QStyleOptionHeader::None )
{
// also add space for sort indicator
contentsWidth += Metrics::Header_ArrowSize + Metrics::Header_ItemSpacing;
contentsHeight = qMax( contentsHeight, int(Metrics::Header_ArrowSize) );
}
// update contents size, add margins and return
const QSize size( contentsSize.expandedTo( QSize( contentsWidth, contentsHeight ) ) );
return expandSize( size, Metrics::Header_MarginWidth );
}
//______________________________________________________________
QSize Style::itemViewItemSizeFromContents( const QStyleOption* option, const QSize& contentsSize, const QWidget* widget ) const
{
// call base class
QSize size( KStyle::sizeFromContents( CT_ItemViewItem, option, contentsSize, widget ) );
// add margins
return expandSize( size, Metrics::ItemView_ItemMarginWidth );
}
//___________________________________________________________________________________
bool Style::drawFramePrimitive( const QStyleOption* option, QPainter* painter, const QWidget* widget ) const
{
// copy rect and palette
const QRect& rect( option->rect );
const QPalette& palette( option->palette );
// store state
const State& state( option->state );
const bool enabled( state & State_Enabled );
const bool isInputWidget( ( widget && widget->testAttribute( Qt::WA_Hover ) ) ||
( isQtQuickControl( option, widget ) && option->styleObject->property( "elementType" ).toString() == QStringLiteral( "edit") ) );
const bool mouseOver( enabled && isInputWidget && ( state & State_MouseOver ) );
const bool hasFocus( enabled && isInputWidget && ( state & State_HasFocus ) );
// assume focus takes precedence over hover
_animations->inputWidgetEngine().updateState( widget, AnimationFocus, hasFocus );
_animations->inputWidgetEngine().updateState( widget, AnimationHover, mouseOver && !hasFocus );
if( state & State_Sunken )
{
// retrieve animation mode and opacity
const AnimationMode mode( _animations->inputWidgetEngine().frameAnimationMode( widget ) );
const qreal opacity( _animations->inputWidgetEngine().frameOpacity( widget ) );
if( _frameShadowFactory->isRegistered( widget ) )
{
_frameShadowFactory->updateShadowsGeometry( widget, rect );
_frameShadowFactory->updateState( widget, hasFocus, mouseOver, opacity, mode );
} else {
StyleOptions options;
if( hasFocus ) options |= Focus;
if( mouseOver ) options |= Hover;
_helper->renderHole(
painter, palette.color( QPalette::Window ), rect, options,
opacity, mode, TileSet::Ring );
}
} else if( state & State_Raised ) {
const QRect local( rect );
renderSlab( painter, rect, palette.color( QPalette::Window ), NoFill );
}
return true;
}
//___________________________________________________________________________________
bool Style::drawFrameLineEditPrimitive( const QStyleOption* option, QPainter* painter, const QWidget* widget ) const
{
// copy rect and palette
const QRect& rect( option->rect );
const QPalette& palette( option->palette );
// make sure there is enough room to render frame
if( rect.height() < 2*Metrics::LineEdit_FrameWidth + option->fontMetrics.height() )
{
const QColor background( palette.color( QPalette::Base ) );
painter->setPen( Qt::NoPen );
painter->setBrush( background );
painter->drawRect( rect );
return true;
} else {
// store state
const State& state( option->state );
const bool enabled( state & State_Enabled );
const bool mouseOver( enabled && ( state & State_MouseOver ) );
const bool hasFocus( enabled && ( state & State_HasFocus ) );
// assume focus takes precedence over hover
_animations->inputWidgetEngine().updateState( widget, AnimationFocus, hasFocus );
_animations->inputWidgetEngine().updateState( widget, AnimationHover, mouseOver && !hasFocus );
// retrieve animation mode and opacity
const AnimationMode mode( _animations->inputWidgetEngine().frameAnimationMode( widget ) );
const qreal opacity( _animations->inputWidgetEngine().frameOpacity( widget ) );
// fill
painter->setPen( Qt::NoPen );
painter->setBrush( palette.color( QPalette::Base ) );
_helper->fillHole( *painter, rect );
// render hole
StyleOptions options;
if( hasFocus ) options |= Focus;
if( mouseOver ) options |= Hover;
_helper->renderHole( painter, palette.color( QPalette::Window ), rect, options, opacity, mode, TileSet::Ring );
}
return true;
}
//___________________________________________________________________________________
bool Style::drawFrameFocusRectPrimitive( const QStyleOption* option, QPainter* painter, const QWidget* widget ) const
{
if( !widget ) return true;
// no focus indicator on buttons, since it is rendered elsewhere
if( qobject_cast< const QAbstractButton*>( widget ) )
{ return true; }
const State& state( option->state );
const QRect rect( option->rect.adjusted( 0, 0, 0, 1 ) );
const QPalette& palette( option->palette );
if( rect.width() < 10 ) return true;
const QColor outlineColor( state & State_Selected ? palette.color( QPalette::HighlightedText ):palette.color( QPalette::Highlight ) );
painter->setRenderHint( QPainter::Antialiasing, false );
painter->setPen( outlineColor );
painter->drawLine( rect.bottomLeft(), rect.bottomRight() );
return true;
}
//___________________________________________________________________________________
bool Style::drawFrameMenuPrimitive( const QStyleOption* option, QPainter* painter, const QWidget* widget ) const
{
// only draw frame for ( expanded ) toolbars
// do nothing for other cases
if( qobject_cast<const QToolBar*>( widget ) )
{
_helper->renderWindowBackground( painter, option->rect, widget, option->palette );
_helper->drawFloatFrame( painter, option->rect, option->palette.window().color(), true );
} else if( isQtQuickControl( option, widget ) ) {
// QtQuick Control case
painter->fillRect( option->rect, option->palette.window() );
_helper->drawFloatFrame( painter, option->rect, option->palette.window().color(), true );
}
return true;
}
//______________________________________________________________
bool Style::drawFrameGroupBoxPrimitive( const QStyleOption* option, QPainter* painter, const QWidget* widget ) const
{
// cast option and check
const auto frameOption( qstyleoption_cast<const QStyleOptionFrame*>( option ) );
if( !frameOption ) return true;
// no frame for flat groupboxes
if( frameOption->features & QStyleOptionFrame::Flat ) return true;
// normal frame
const QPalette& palette( option->palette );
const QRect& rect( option->rect );
const QColor base( _helper->backgroundColor( palette.color( QPalette::Window ), widget, rect.center() ) );
painter->save();
painter->setRenderHint( QPainter::Antialiasing );
painter->setPen( Qt::NoPen );
QLinearGradient innerGradient( 0, rect.top()-rect.height()+12, 0, rect.bottom()+rect.height()-19 );
QColor light( _helper->calcLightColor( base ) );
light.setAlphaF( 0.4 ); innerGradient.setColorAt( 0, light );
light.setAlphaF( 0 ); innerGradient.setColorAt( 1, light );
painter->setBrush( innerGradient );
painter->setClipRect( rect.adjusted( 0, 0, 0, -19 ) );
_helper->fillSlab( *painter, rect );
painter->setClipping( false );
_helper->slope( base, 0 ).render( rect, painter );
painter->restore();
return true;
}
//___________________________________________________________________________________
bool Style::drawFrameTabWidgetPrimitive( const QStyleOption* option, QPainter* painter, const QWidget* ) const
{
// cast option and check
const QStyleOptionTabWidgetFrame* tabOption( qstyleoption_cast<const QStyleOptionTabWidgetFrame*>( option ) );
if( !tabOption ) return true;
// copy rect and palette
const QRect& rect( option->rect );
const QPalette& palette( option->palette );
const bool reverseLayout( option->direction == Qt::RightToLeft );
/*
no frame is drawn when tabbar is empty.
this is consistent with the tabWidgetTabContents subelementRect
*/
if( tabOption->tabBarSize.isEmpty() ) return true;
// get tabbar dimensions
const int width( tabOption->tabBarSize.width() );
const int height( tabOption->tabBarSize.height() );
// left corner widget
const int leftWidth( tabOption->leftCornerWidgetSize.width() );
const int rightWidth( tabOption->rightCornerWidgetSize.width() );
// list of slabs to be drawn
SlabRect::List slabs;
QRect baseSlabRect( rect );
// render the three free sides
switch( tabOption->shape )
{
case QTabBar::RoundedNorth:
case QTabBar::TriangularNorth:
{
// main slab
slabs << SlabRect( baseSlabRect, ( TileSet::Ring & ~TileSet::Top ) );
// top
if( reverseLayout )
{
// left side
QRect slabRect( baseSlabRect );
slabRect.setRight( qMax( slabRect.right() - width - leftWidth, slabRect.left() + rightWidth ) );
slabRect.setHeight( 1 );
slabs << SlabRect( slabRect, TileSet::TopLeft ).adjusted( TileSet::DefaultSize );
// right side
if( rightWidth > 0 )
{
QRect slabRect( baseSlabRect );
slabRect.setLeft( slabRect.right() - rightWidth );
slabRect.setHeight( 1 );
slabs << SlabRect( slabRect, TileSet::TopRight ).adjusted( TileSet::DefaultSize );
}
} else {
// left side
if( leftWidth > 0 )
{
QRect slabRect( baseSlabRect );
slabRect.setRight( baseSlabRect.left() + leftWidth );
slabRect.setHeight( 1 );
slabs << SlabRect( slabRect, TileSet::TopLeft ).adjusted( TileSet::DefaultSize );
}
// right side
QRect slabRect( baseSlabRect );
slabRect.setLeft( qMin( slabRect.left() + width + leftWidth + 1, slabRect.right() - rightWidth ) );
slabRect.setHeight( 1 );
slabs << SlabRect( slabRect, TileSet::TopRight ).adjusted( TileSet::DefaultSize );
}
break;
}
case QTabBar::RoundedSouth:
case QTabBar::TriangularSouth:
{
slabs << SlabRect( baseSlabRect, TileSet::Ring & ~TileSet::Bottom );
if( reverseLayout )
{
// left side
QRect slabRect( baseSlabRect );
slabRect.setRight( qMax( slabRect.right() -width - leftWidth, slabRect.left() + rightWidth ) );
slabRect.setTop( slabRect.bottom() );
slabs << SlabRect( slabRect, TileSet::BottomLeft ).adjusted( TileSet::DefaultSize );
// right side
if( rightWidth > 0 )
{
QRect slabRect( baseSlabRect );
slabRect.setLeft( slabRect.right() - rightWidth - TileSet::DefaultSize );
slabRect.setTop( slabRect.bottom() );
slabs << SlabRect( slabRect, TileSet::BottomRight ).adjusted( TileSet::DefaultSize );
}
} else {
// left side
if( leftWidth > 0 )
{
QRect slabRect( baseSlabRect );
slabRect.setRight( baseSlabRect.left() + leftWidth );
slabRect.setTop( slabRect.bottom() );
slabs << SlabRect( slabRect, TileSet::BottomLeft ).adjusted( TileSet::DefaultSize );
}
// right side
QRect slabRect( baseSlabRect );
slabRect.setLeft( qMin( slabRect.left() + width + leftWidth + 1, slabRect.right() - rightWidth ) );
slabRect.setTop( slabRect.bottom() );
slabs << SlabRect( slabRect, TileSet::BottomRight ).adjusted( TileSet::DefaultSize );
}
break;
}
case QTabBar::RoundedWest:
case QTabBar::TriangularWest:
{
slabs << SlabRect( baseSlabRect, TileSet::Ring & ~TileSet::Left );
// bottom side
QRect slabRect( baseSlabRect );
slabRect.setTop( qMin( slabRect.top() + height, slabRect.bottom() ) );
slabRect.setWidth( 1 );
slabs << SlabRect( slabRect, TileSet::BottomLeft ).adjusted( TileSet::DefaultSize );
break;
}
case QTabBar::RoundedEast:
case QTabBar::TriangularEast:
{
slabs << SlabRect( baseSlabRect, TileSet::Ring & ~TileSet::Right );
// bottom side
QRect slabRect( baseSlabRect );
slabRect.setTop( qMin( slabRect.top() + height, slabRect.bottom() ) );
slabRect.setLeft( slabRect.right() );
slabs << SlabRect( slabRect, TileSet::BottomRight ).adjusted( TileSet::DefaultSize );
break;
}
break;
default: break;
}
// render registered slabs
foreach( const SlabRect& slab, slabs )
{ renderSlab( painter, slab, palette.color( QPalette::Window ), NoFill ); }
return true;
}
//___________________________________________________________________________________
bool Style::drawFrameTabBarBasePrimitive( const QStyleOption* option, QPainter* painter, const QWidget* ) const
{
// tabbar frame used either for 'separate' tabbar, or in 'document mode'
// cast option and check
const QStyleOptionTabBarBase* tabOption( qstyleoption_cast<const QStyleOptionTabBarBase*>( option ) );
if( !tabOption ) return true;
if( tabOption->tabBarRect.isValid() )
{
// if tabBar rect is valid, all the frame is handled in tabBarTabShapeControl
// nothing to be done here.
// on the other hand, invalid tabBarRect corresponds to buttons in tabbars ( e.g. corner buttons ),
// and the appropriate piece of frame needs to be drawn
return true;
}
// store palette and rect
const QPalette& palette( option->palette );
const QRect& rect( option->rect );
if( !rect.isValid() ) return true;
QRect frameRect( rect );
SlabRect slab;
switch( tabOption->shape )
{
case QTabBar::RoundedNorth:
case QTabBar::TriangularNorth:
{
frameRect = insideMargin( frameRect, -8, 0 );
frameRect.translate( 0, 4 );
slab = SlabRect( frameRect, TileSet::Top );
break;
}
case QTabBar::RoundedSouth:
case QTabBar::TriangularSouth:
{
frameRect = insideMargin( frameRect, -8, 0 );
frameRect.translate( 0, -4 );
slab = SlabRect( frameRect, TileSet::Bottom );
break;
}
default: return true;
}
// render registered slabs
renderSlab( painter, slab, palette.color( QPalette::Window ), NoFill );
return true;
}
//___________________________________________________________________________________
bool Style::drawFrameWindowPrimitive( const QStyleOption* option, QPainter* painter, const QWidget* ) const
{
// copy rect and palette
const QRect& rect( option->rect );
const QPalette& palette( option->palette );
// render
_helper->drawFloatFrame( painter, rect, palette.window().color(), false );
return true;
}
//___________________________________________________________________________________
bool Style::drawIndicatorArrowPrimitive( ArrowOrientation orientation, const QStyleOption* option, QPainter* painter, const QWidget* widget ) const
{
// store rect and palette
const QRect& rect( option->rect );
const QPalette& palette( option->palette );
// store state
const State& state( option->state );
const bool enabled( state & State_Enabled );
bool mouseOver( enabled && ( state & State_MouseOver ) );
bool hasFocus( enabled && ( state & State_HasFocus ) );
// detect special buttons
const bool inTabBar( widget && qobject_cast<const QTabBar*>( widget->parentWidget() ) );
const bool inToolButton( qstyleoption_cast<const QStyleOptionToolButton *>( option ) );
// color
QColor color;
if( inTabBar ) {
// for tabbar arrows one uses animations to get the arrow color
// get animation state
/* there is no need to update the engine since this was already done when rendering the frame */
const AnimationMode mode( _animations->widgetStateEngine().buttonAnimationMode( widget ) );
const qreal opacity( _animations->widgetStateEngine().buttonOpacity( widget ) );
StyleOptions styleOptions;
if( mouseOver ) styleOptions |= Hover;
if( hasFocus ) styleOptions |= Focus;
color = _helper->arrowColor( palette, styleOptions, opacity, mode );
} else if( mouseOver && !inToolButton ) {
color = _helper->hoverColor( palette );
} else if( inToolButton ) {
const bool flat( state & State_AutoRaise );
// cast option
const QStyleOptionToolButton* toolButtonOption( static_cast<const QStyleOptionToolButton*>( option ) );
const bool hasPopupMenu( toolButtonOption->subControls & SC_ToolButtonMenu );
if( flat && hasPopupMenu )
{
// for menu arrows in flat toolbutton one uses animations to get the arrow color
// handle arrow over animation
const bool arrowHover( mouseOver && ( toolButtonOption->activeSubControls & SC_ToolButtonMenu ) );
_animations->toolButtonEngine().updateState( widget, AnimationHover, arrowHover );
const bool animated( _animations->toolButtonEngine().isAnimated( widget, AnimationHover ) );
const qreal opacity( _animations->toolButtonEngine().opacity( widget, AnimationHover ) );
StyleOptions styleOptions;
if( arrowHover ) styleOptions |= Hover;
color = _helper->arrowColor( palette, styleOptions, opacity, animated ? AnimationHover:AnimationNone );
} else {
color = palette.color( flat ? QPalette::WindowText : QPalette::ButtonText );
}
} else color = palette.color( QPalette::WindowText );
// get arrow polygon
const QPolygonF arrow = genericArrow( orientation, ArrowNormal );
const qreal penThickness = 1.6;
const qreal offset( qMin( penThickness, qreal( 1 ) ) );
painter->translate( QRectF( rect ).center() );
painter->setRenderHint( QPainter::Antialiasing );
painter->translate( 0,offset );
const QColor background = palette.color( QPalette::Window );
painter->setPen( QPen( _helper->calcLightColor( background ), penThickness, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin ) );
painter->drawPolyline( arrow );
painter->translate( 0,-offset );
painter->setPen( QPen( _helper->decoColor( background, color ) , penThickness, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin ) );
painter->drawPolyline( arrow );
return true;
}
//___________________________________________________________________________________
bool Style::drawIndicatorHeaderArrowPrimitive( const QStyleOption* option, QPainter* painter, const QWidget* widget ) const
{
const QStyleOptionHeader *headerOption = qstyleoption_cast<const QStyleOptionHeader *>( option );
const State& state( option->state );
// arrow orientation
ArrowOrientation orientation( ArrowNone );
if( state & State_UpArrow || ( headerOption && headerOption->sortIndicator==QStyleOptionHeader::SortUp ) ) orientation = ArrowUp;
else if( state & State_DownArrow || ( headerOption && headerOption->sortIndicator==QStyleOptionHeader::SortDown ) ) orientation = ArrowDown;
if( orientation == ArrowNone ) return true;
// invert arrows if requested by (hidden) options
if( StyleConfigData::viewInvertSortIndicator() ) orientation = (orientation == ArrowUp) ? ArrowDown:ArrowUp;
// flags, rect and palette
const QRect& rect( option->rect );
const QPalette& palette( option->palette );
const bool enabled( state & State_Enabled );
const bool mouseOver( enabled && ( state & State_MouseOver ) );
_animations->headerViewEngine().updateState( widget, rect.topLeft(), mouseOver );
const bool animated( enabled && _animations->headerViewEngine().isAnimated( widget, rect.topLeft() ) );
// define gradient and polygon for drawing arrow
const QPolygonF arrow = genericArrow( orientation, ArrowNormal );
QColor color = palette.color( QPalette::WindowText );
const QColor background = palette.color( QPalette::Window );
const QColor highlight( _helper->hoverColor( palette ) );
const qreal penThickness = 1.6;
const qreal offset( qMin( penThickness, qreal( 1 ) ) );
if( animated )
{
const qreal opacity( _animations->headerViewEngine().opacity( widget, rect.topLeft() ) );
color = KColorUtils::mix( color, highlight, opacity );
} else if( mouseOver ) color = highlight;
painter->translate( QRectF(rect).center() );
painter->translate( 0, 1 );
painter->setRenderHint( QPainter::Antialiasing );
painter->translate( 0,offset );
painter->setPen( QPen( _helper->calcLightColor( background ), penThickness, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin ) );
painter->drawPolyline( arrow );
painter->translate( 0,-offset );
painter->setPen( QPen( _helper->decoColor( background, color ) , penThickness, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin ) );
painter->drawPolyline( arrow );
return true;
}
//______________________________________________________________
bool Style::drawPanelButtonCommandPrimitive( const QStyleOption* option, QPainter* painter, const QWidget* widget ) const
{
// copy rect and palette
const QRect& rect( option->rect );
const QPalette& palette( option->palette );
// store state
const State& state( option->state );
const bool enabled( state & State_Enabled );
const bool mouseOver( enabled && ( state & State_MouseOver ) );
const bool hasFocus( enabled && ( state & State_HasFocus ) && !( widget && widget->focusProxy() ) );
const bool sunken( state & ( State_On|State_Sunken ) );
StyleOptions styleOptions;
if( sunken ) styleOptions |= Sunken;
if( hasFocus ) styleOptions |= Focus;
if( mouseOver ) styleOptions |= Hover;
// update animation state
_animations->widgetStateEngine().updateState( widget, AnimationHover, mouseOver );
_animations->widgetStateEngine().updateState( widget, AnimationFocus, hasFocus && !mouseOver );
// store animation state
AnimationMode mode( _animations->widgetStateEngine().buttonAnimationMode( widget ) );
const qreal opacity( _animations->widgetStateEngine().buttonOpacity( widget ) );
// decide if widget must be rendered flat.
/*
The decision is made depending on
- whether the "flat" flag is set in the option
- whether the widget is hight enough to render both icons and normal margins
Note: in principle one should also check for the button text height
*/
const QStyleOptionButton* buttonOption( qstyleoption_cast< const QStyleOptionButton* >( option ) );
bool flat = ( buttonOption && (
buttonOption->features.testFlag( QStyleOptionButton::Flat ) ||
( ( !buttonOption->icon.isNull() ) && sizeFromContents( CT_PushButton, option, buttonOption->iconSize, widget ).height() > rect.height() ) ) );
if( flat )
{
if( !sunken )
{
const QColor glow( _helper->buttonGlowColor( palette, styleOptions, opacity, mode ) );
if( glow.isValid() ) _helper->slitFocused( glow ).render( rect, painter );
} else {
_helper->renderHole( painter, palette.color( QPalette::Window ), rect, styleOptions, opacity, mode, TileSet::Ring );
}
} else {
// match color to the window background
QColor buttonColor( _helper->backgroundColor( palette.color( QPalette::Button ), widget, rect.center() ) );
// merge button color with highlight in case of default button
if( enabled && buttonOption && (buttonOption->features&QStyleOptionButton::DefaultButton) )
{
const QColor tintColor( _helper->calcLightColor( buttonColor ) );
buttonColor = KColorUtils::mix( buttonColor, tintColor, 0.5 );
}
// disable animation for sunken buttons
if( sunken ) mode = AnimationNone;
renderButtonSlab( painter, rect, buttonColor, styleOptions, opacity, mode, TileSet::Ring );
}
return true;
}
//______________________________________________________________
bool Style::drawPanelButtonToolPrimitive( const QStyleOption* option, QPainter* painter, const QWidget* widget ) const
{
// copy rect and palette
const QRect& rect( option->rect );
const QPalette& palette( option->palette );
// store state
const State& state( option->state );
const bool enabled( state & State_Enabled );
const bool mouseOver( enabled && ( state & State_MouseOver ) );
const bool hasFocus( enabled && ( state & State_HasFocus ) );
const bool autoRaised( state & State_AutoRaise );
const bool sunken( state & ( State_On|State_Sunken ) );
const bool reverseLayout( option->direction == Qt::RightToLeft );
// toolbar animation
const bool isInToolBar( widget && qobject_cast<const QToolBar*>( widget->parent() ) );
const bool toolBarAnimated( isInToolBar && widget && ( _animations->toolBarEngine().isAnimated( widget->parentWidget() ) || _animations->toolBarEngine().isFollowMouseAnimated( widget->parentWidget() ) ) );
const QRect animatedRect( ( isInToolBar && widget ) ? _animations->toolBarEngine().animatedRect( widget->parentWidget() ):QRect() );
const QRect childRect( ( widget && widget->parentWidget() ) ? rect.translated( widget->mapToParent( QPoint( 0,0 ) ) ):QRect() );
const QRect currentRect( widget ? _animations->toolBarEngine().currentRect( widget->parentWidget() ):QRect() );
const bool current( isInToolBar && widget && widget->parentWidget() && currentRect.intersects( rect.translated( widget->mapToParent( QPoint( 0,0 ) ) ) ) );
const bool toolBarTimerActive( isInToolBar && widget && _animations->toolBarEngine().isTimerActive( widget->parentWidget() ) );
const qreal toolBarOpacity( ( isInToolBar && widget ) ? _animations->toolBarEngine().opacity( widget->parentWidget() ):0 );
// normal animation state
// no need to update, this was already done in drawToolButtonComplexControl
const AnimationMode mode( _animations->widgetStateEngine().buttonAnimationMode( widget ) );
const qreal opacity( _animations->widgetStateEngine().buttonOpacity( widget ) );
// style options
StyleOptions styleOptions;
if( sunken ) styleOptions |= Sunken;
if( hasFocus ) styleOptions |= Focus;
if( mouseOver ) styleOptions |= Hover;
// non autoraised tool buttons get same slab as regular buttons
if( !autoRaised )
{
TileSet::Tiles tiles( TileSet::Ring );
// adjust tiles and rect in case of menubutton
const QToolButton* toolButton = qobject_cast<const QToolButton*>( widget );
const bool hasPopupMenu( toolButton && toolButton->popupMode() == QToolButton::MenuButtonPopup );
if( hasPopupMenu )
{
if( reverseLayout ) tiles &= ~TileSet::Left;
else tiles &= ~TileSet::Right;
}
// match button color to window background
const QColor buttonColor( _helper->backgroundColor( palette.color( QPalette::Button ), widget, rect.center() ) );
// render slab
renderButtonSlab( painter, rect, buttonColor, styleOptions, opacity, mode, tiles );
return true;
}
// normal ( auto-raised ) toolbuttons
if( sunken )
{
// fill hole
qreal holeOpacity = 1;
const qreal bias = 0.75;
if( mode == AnimationHover ) holeOpacity = 1 - bias*opacity;
else if( toolBarAnimated && enabled && animatedRect.isNull() && current ) holeOpacity = 1 - bias*toolBarOpacity;
else if( enabled && (( toolBarTimerActive && current ) || mouseOver ) ) holeOpacity = 1 - bias;
if( holeOpacity > 0 )
{
QColor color( _helper->backgroundColor( _helper->calcMidColor( palette.color( QPalette::Window ) ), widget, rect.center() ) );
color = _helper->alphaColor( color, holeOpacity );
painter->setRenderHint( QPainter::Antialiasing );
painter->setPen( Qt::NoPen );
painter->setBrush( color );
painter->drawRoundedRect( insideMargin( rect, 1 ), 3.5, 3.5 );
}
styleOptions |= HoleContrast;
if( mode != AnimationNone )
{
_helper->renderHole( painter, palette.color( QPalette::Window ), rect, styleOptions, opacity, mode, TileSet::Ring );
} else if( toolBarAnimated ) {
if( enabled && animatedRect.isNull() && current )
{
_helper->renderHole( painter, palette.color( QPalette::Window ), rect, styleOptions, toolBarOpacity, AnimationHover, TileSet::Ring );
} else {
_helper->renderHole( painter, palette.color( QPalette::Window ), rect, HoleContrast );
}
} else if( toolBarTimerActive && current ) {
_helper->renderHole( painter, palette.color( QPalette::Window ), rect, styleOptions | Hover );
} else {
_helper->renderHole( painter, palette.color( QPalette::Window ), rect, styleOptions );
}
} else {
const QColor glow( _helper->buttonGlowColor( palette, styleOptions, opacity, mode ) );
if( mode != AnimationNone ) _helper->slitFocused( glow ).render( rect, painter );
else if( toolBarAnimated ) {
if( enabled && animatedRect.isNull() && current )
{
QColor glow( _helper->alphaColor( _helper->hoverColor( palette ), toolBarOpacity ) );
_helper->slitFocused( glow ).render( rect, painter );
}
} else if( hasFocus || mouseOver ) {
_helper->slitFocused( glow ).render( rect, painter );
} else if( toolBarTimerActive && current ) {
_helper->slitFocused( _helper->hoverColor( palette ) ).render( rect, painter );
}
}
return true;
}
//______________________________________________________________
bool Style::drawTabBarPanelButtonToolPrimitive( const QStyleOption* option, QPainter* painter, const QWidget* widget ) const
{
const QPalette& palette( option->palette );
QRect rect( option->rect );
// adjust rect depending on shape
const QTabBar* tabBar( static_cast<const QTabBar*>( widget->parent() ) );
switch( tabBar->shape() )
{
case QTabBar::RoundedNorth:
case QTabBar::TriangularNorth:
rect.adjust( 0, 0, 0, -6 );
break;
case QTabBar::RoundedSouth:
case QTabBar::TriangularSouth:
rect.adjust( 0, 6, 0, 0 );
break;
case QTabBar::RoundedWest:
case QTabBar::TriangularWest:
rect.adjust( 0, 0, -6, 0 );
break;
case QTabBar::RoundedEast:
case QTabBar::TriangularEast:
rect.adjust( 6, 0, 0, 0 );
break;
default: break;
}
const QPalette local( widget->parentWidget() ? widget->parentWidget()->palette() : palette );
// check whether parent has autofill background flag
const QWidget* parent = _helper->checkAutoFillBackground( widget );
if( parent && !qobject_cast<const QDockWidget*>( parent ) ) painter->fillRect( rect, parent->palette().color( parent->backgroundRole() ) );
else _helper->renderWindowBackground( painter, rect, widget, local );
return true;
}
//___________________________________________________________________________________
bool Style::drawPanelScrollAreaCornerPrimitive( const QStyleOption*, QPainter*, const QWidget* widget ) const
{
// disable painting of PE_PanelScrollAreaCorner
// the default implementation fills the rect with the window background color
// which does not work for windows that have gradients.
// unfortunately, this does not work when scrollbars are children of QWebView,
// in which case, false is returned, in order to fall back to the parent style implementation
return !( widget && widget->inherits( "QWebView" ) );
}
//___________________________________________________________________________________
bool Style::drawPanelMenuPrimitive( const QStyleOption* option, QPainter* painter, const QWidget* widget ) const
{
// do nothing if menu is embedded in another widget
// this corresponds to having a transparent background
if( widget && !widget->isWindow() ) return true;
// cast option and check
const QStyleOptionMenuItem* menuItemOption( qstyleoption_cast<const QStyleOptionMenuItem*>( option ) );
if( !( menuItemOption && widget ) ) return true;
// copy rect and get color
const QRect& rect = menuItemOption->rect;
const QColor color = menuItemOption->palette.color( widget->window()->backgroundRole() );
const bool hasAlpha( _helper->hasAlphaChannel( widget ) );
if( hasAlpha )
{
painter->setCompositionMode( QPainter::CompositionMode_Source );
_helper->roundCorner( color ).render( rect, painter );
painter->setCompositionMode( QPainter::CompositionMode_SourceOver );
painter->setClipPath( _helper->roundedPath( insideMargin( rect, 1 ) ), Qt::IntersectClip );
}
_helper->renderMenuBackground( painter, rect, widget, menuItemOption->palette );
if( hasAlpha ) painter->setClipping( false );
_helper->drawFloatFrame( painter, rect, color, !hasAlpha );
return true;
}
//___________________________________________________________________________________
bool Style::drawPanelTipLabelPrimitive( const QStyleOption* option, QPainter* painter, const QWidget* widget ) const
{
// force registration of widget
if( widget && widget->window() )
{ _shadowHelper->registerWidget( widget->window(), true ); }
const QRect& rect( option->rect );
const QColor color( option->palette.brush( QPalette::ToolTipBase ).color() );
QColor topColor( _helper->backgroundTopColor( color ) );
QColor bottomColor( _helper->backgroundBottomColor( color ) );
// make tooltip semi transparents when possible
// alpha is copied from "kdebase/apps/dolphin/tooltips/filemetadatatooltip.cpp"
const bool hasAlpha( _helper->hasAlphaChannel( widget ) );
if( hasAlpha && StyleConfigData::toolTipTransparent() )
{
if( widget && widget->window() )
{ _blurHelper->registerWidget( widget->window() ); }
topColor.setAlpha( 220 );
bottomColor.setAlpha( 220 );
}
QLinearGradient gradient( 0, rect.top(), 0, rect.bottom() );
gradient.setColorAt( 0, topColor );
gradient.setColorAt( 1, bottomColor );
// contrast pixmap
QLinearGradient gradient2( 0, rect.top(), 0, rect.bottom() );
gradient2.setColorAt( 0.5, _helper->calcLightColor( bottomColor ) );
gradient2.setColorAt( 0.9, bottomColor );
painter->save();
if( hasAlpha )
{
painter->setRenderHint( QPainter::Antialiasing );
QRectF local( rect );
local.adjust( 0.5, 0.5, -0.5, -0.5 );
painter->setPen( Qt::NoPen );
painter->setBrush( gradient );
painter->drawRoundedRect( local, 4, 4 );
painter->setBrush( Qt::NoBrush );
painter->setPen( QPen( gradient2, 1.1, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin ) );
painter->drawRoundedRect( local, 3.5, 3.5 );
} else {
painter->setPen( Qt::NoPen );
painter->setBrush( gradient );
painter->drawRect( rect );
painter->setBrush( Qt::NoBrush );
painter->setPen( QPen( gradient2, 1.1, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin ) );
painter->drawRect( rect );
}
painter->restore();
return true;
}
//___________________________________________________________________________________
bool Style::drawPanelItemViewItemPrimitive( const QStyleOption* option, QPainter* painter, const QWidget* widget ) const
{
// cast option and check
const auto viewItemOption = qstyleoption_cast<const QStyleOptionViewItem*>( option );
if( !viewItemOption ) return false;
// try cast widget
const auto view = qobject_cast<const QAbstractItemView *>( widget );
// store palette and rect
const auto& palette( option->palette );
QRect rect( option->rect );
// store flags
const State& state( option->state );
const bool mouseOver( ( state & State_MouseOver ) && (!view || view->selectionMode() != QAbstractItemView::NoSelection) );
const bool selected( state & State_Selected );
const bool enabled( state & State_Enabled );
const bool active( state & State_Active );
const bool hasCustomBackground( viewItemOption->backgroundBrush.style() != Qt::NoBrush && !selected );
const bool hasSolidBackground( !hasCustomBackground || viewItemOption->backgroundBrush.style() == Qt::SolidPattern );
if( !mouseOver && !selected && !hasCustomBackground && !( viewItemOption->features & QStyleOptionViewItemV2::Alternate ) )
{ return true; }
QPalette::ColorGroup colorGroup;
if( enabled ) colorGroup = active ? QPalette::Normal : QPalette::Inactive;
else colorGroup = QPalette::Disabled;
QColor color;
if( hasCustomBackground && hasSolidBackground ) color = viewItemOption->backgroundBrush.color();
else color = palette.color( colorGroup, QPalette::Highlight );
if( mouseOver && !hasCustomBackground )
{
if( !selected ) color.setAlphaF( 0.2 );
else color = color.lighter( 110 );
}
if( viewItemOption && ( viewItemOption->features & QStyleOptionViewItemV2::Alternate ) )
{ painter->fillRect( option->rect, palette.brush( colorGroup, QPalette::AlternateBase ) ); }
if( !mouseOver && !selected && !hasCustomBackground )
{ return true; }
if( hasCustomBackground && !hasSolidBackground )
{
const QPointF oldBrushOrigin = painter->brushOrigin();
painter->setBrushOrigin( viewItemOption->rect.topLeft() );
painter->setBrush( viewItemOption->backgroundBrush );
painter->setPen( Qt::NoPen );
painter->drawRect( viewItemOption->rect );
painter->setBrushOrigin( oldBrushOrigin );
} else {
// get selection tileset
TileSet tileSet( _helper->selection( color, rect.height(), hasCustomBackground ) );
bool roundedLeft = false;
bool roundedRight = false;
if( viewItemOption )
{
roundedLeft = ( viewItemOption->viewItemPosition == QStyleOptionViewItem::Beginning );
roundedRight = ( viewItemOption->viewItemPosition == QStyleOptionViewItem::End );
if( viewItemOption->viewItemPosition == QStyleOptionViewItem::OnlyOne ||
viewItemOption->viewItemPosition == QStyleOptionViewItem::Invalid ||
( view && view->selectionBehavior() != QAbstractItemView::SelectRows ) )
{
roundedLeft = true;
roundedRight = true;
}
}
const bool reverseLayout( option->direction == Qt::RightToLeft );
// define tiles
TileSet::Tiles tiles( TileSet::Center );
if( !reverseLayout ? roundedLeft : roundedRight ) tiles |= TileSet::Left;
if( !reverseLayout ? roundedRight : roundedLeft ) tiles |= TileSet::Right;
// adjust rect and render
rect = tileSet.adjust( rect, tiles );
if( rect.isValid() ) tileSet.render( rect, painter, tiles );
}
return true;
}
//___________________________________________________________________________________
bool Style::drawIndicatorMenuCheckMarkPrimitive( const QStyleOption *option, QPainter *painter, const QWidget * ) const
{
const QRect& rect( option->rect );
const State& state( option->state );
const QPalette& palette( option->palette );
const bool enabled( state & State_Enabled );
StyleOptions styleOptions( NoFill );
if( !enabled ) styleOptions |= Disabled;
renderCheckBox( painter, rect, palette, styleOptions, CheckOn );
return true;
}
//___________________________________________________________________________________
bool Style::drawIndicatorCheckBoxPrimitive( const QStyleOption* option, QPainter* painter, const QWidget* widget ) const
{
// get rect
const QRect& rect( option->rect );
const State& state( option->state );
const bool enabled( state & State_Enabled );
const bool mouseOver( enabled && ( state & State_MouseOver ) );
const bool hasFocus( enabled && ( state & State_HasFocus ) );
StyleOptions styleOptions;
if( !enabled ) styleOptions |= Disabled;
if( mouseOver ) styleOptions |= Hover;
if( hasFocus ) styleOptions |= Focus;
// get checkbox state
CheckBoxState checkBoxState;
if( state & State_NoChange ) checkBoxState = CheckTriState;
else if( state & State_Sunken ) checkBoxState = CheckSunken;
else if( state & State_On ) checkBoxState = CheckOn;
else checkBoxState = CheckOff;
// match button color to window background
QPalette palette( option->palette );
palette.setColor( QPalette::Button, _helper->backgroundColor( palette.color( QPalette::Button ), widget, rect.center() ) );
// animation state: mouseOver has precedence over focus
_animations->widgetStateEngine().updateState( widget, AnimationHover, mouseOver );
_animations->widgetStateEngine().updateState( widget, AnimationFocus, hasFocus&&!mouseOver );
const AnimationMode mode( _animations->widgetStateEngine().buttonAnimationMode( widget ) );
const qreal opacity( _animations->widgetStateEngine().buttonOpacity( widget ) );
renderCheckBox( painter, rect, palette, styleOptions, checkBoxState, opacity, mode );
return true;
}
//___________________________________________________________________________________
bool Style::drawIndicatorRadioButtonPrimitive( const QStyleOption* option, QPainter* painter, const QWidget* widget ) const
{
// copy rect
const QRect& rect( option->rect );
// store state
const State& state( option->state );
const bool enabled( state & State_Enabled );
const bool mouseOver( enabled && ( state & State_MouseOver ) );
const bool hasFocus( state & State_HasFocus );
StyleOptions styleOptions;
if( !enabled ) styleOptions |= Disabled;
if( mouseOver ) styleOptions |= Hover;
if( hasFocus ) styleOptions |= Focus;
CheckBoxState checkBoxState;
if( state & State_Sunken ) checkBoxState = CheckSunken;
else if( state & State_On ) checkBoxState = CheckOn;
else checkBoxState = CheckOff;
// match button color to window background
QPalette palette( option->palette );
palette.setColor( QPalette::Button, _helper->backgroundColor( palette.color( QPalette::Button ), widget, rect.center() ) );
// animation state: mouseOver has precedence over focus
_animations->widgetStateEngine().updateState( widget, AnimationHover, mouseOver );
_animations->widgetStateEngine().updateState( widget, AnimationFocus, hasFocus&&!mouseOver );
const AnimationMode mode( _animations->widgetStateEngine().buttonAnimationMode( widget ) );
const qreal opacity( _animations->widgetStateEngine().buttonOpacity( widget ) );
renderRadioButton( painter, rect, palette, styleOptions, checkBoxState, opacity, mode );
return true;
}
//___________________________________________________________________________________
bool Style::drawIndicatorButtonDropDownPrimitive( const QStyleOption* option, QPainter* painter, const QWidget* widget ) const
{
// cast option and check
const QStyleOptionToolButton* toolButtonOption( qstyleoption_cast<const QStyleOptionToolButton*>( option ) );
if( !toolButtonOption ) return true;
// copy palette and rect
const QPalette& palette( option->palette );
const QRect& rect( option->rect );
// store state
const State& state( option->state );
const bool autoRaise( state & State_AutoRaise );
// do nothing for autoraise buttons
if( autoRaise || !(toolButtonOption->subControls & SC_ToolButtonMenu) ) return true;
// store state
const bool enabled( state & State_Enabled );
const bool hasFocus( enabled && ( state & State_HasFocus ) );
const bool mouseOver( enabled && ( state & State_MouseOver ) );
const bool sunken( enabled && ( state & State_Sunken ) );
const bool reverseLayout( option->direction == Qt::RightToLeft );
// match button color to window background
const QColor highlight( _helper->hoverColor( palette ) );
const QColor background( _helper->backgroundColor( palette.color( QPalette::Button ), widget, rect.center() ) );
StyleOptions styleOptions;
if( hasFocus ) styleOptions |= Focus;
if( mouseOver ) styleOptions |= Hover;
// update animation state
// mouse over takes precedence over focus
_animations->widgetStateEngine().updateState( widget, AnimationHover, mouseOver );
_animations->widgetStateEngine().updateState( widget, AnimationFocus, hasFocus && !mouseOver );
const AnimationMode mode( _animations->widgetStateEngine().buttonAnimationMode( widget ) );
const qreal opacity( _animations->widgetStateEngine().buttonOpacity( widget ) );
// paint frame
TileSet::Tiles tiles( TileSet::Ring );
if( state & ( State_On|State_Sunken ) ) styleOptions |= Sunken;
if( reverseLayout ) tiles &= ~TileSet::Right;
else tiles &= ~TileSet::Left;
painter->setClipRect( rect, Qt::IntersectClip );
renderButtonSlab( painter, rect, background, styleOptions, opacity, mode, tiles );
// draw separating vertical line
const QColor color( palette.color( QPalette::Button ) );
const QColor light =_helper->alphaColor( _helper->calcLightColor( color ), 0.6 );
QColor dark = _helper->calcDarkColor( color );
dark.setAlpha( 200 );
const int top( rect.top()+ (sunken ? 3:2) );
const int bottom( rect.bottom()-4 );
painter->setPen( QPen( light,1 ) );
if( reverseLayout )
{
painter->drawLine( rect.right()+1, top+1, rect.right()+1, bottom );
painter->drawLine( rect.right()-1, top+2, rect.right()-1, bottom );
painter->setPen( dark );
painter->drawLine( rect.right(), top, rect.right(), bottom );
} else {
painter->drawLine( rect.left()-1, top+1, rect.left()-1, bottom-1 );
painter->drawLine( rect.left()+1, top+1, rect.left()+1, bottom-1 );
painter->setPen( dark );
painter->drawLine( rect.left(), top, rect.left(), bottom );
}
return true;
}
//___________________________________________________________________________________
bool Style::drawIndicatorTabClosePrimitive( const QStyleOption* option, QPainter* painter, const QWidget* ) const
{
if( _tabCloseIcon.isNull() )
{
// load the icon on-demand: in the constructor, KDE is not yet ready to find it!
_tabCloseIcon = QIcon::fromTheme( QStringLiteral( "dialog-close" ) );
if( _tabCloseIcon.isNull() ) return false;
}
const int size( pixelMetric(QStyle::PM_SmallIconSize) );
QIcon::Mode mode;
if( option->state & State_Enabled )
{
if( option->state & State_Raised ) mode = QIcon::Active;
else mode = QIcon::Normal;
} else mode = QIcon::Disabled;
if( !(option->state & State_Raised)
&& !(option->state & State_Sunken)
&& !(option->state & QStyle::State_Selected))
mode = QIcon::Disabled;
QIcon::State state = option->state & State_Sunken ? QIcon::On:QIcon::Off;
QPixmap pixmap( _tabCloseIcon.pixmap(size, mode, state) );
drawItemPixmap( painter, option->rect, Qt::AlignCenter, pixmap );
return true;
}
//___________________________________________________________________________________
bool Style::drawIndicatorTabTearPrimitive( const QStyleOption* option, QPainter* painter, const QWidget* widget ) const
{
const QStyleOptionTab* tabOption( qstyleoption_cast<const QStyleOptionTab*>( option ) );
if( !tabOption ) return true;
const QRect& rect( option->rect );
const QPalette& palette( option->palette );
const bool reverseLayout( option->direction == Qt::RightToLeft );
// in fact with current version of Qt ( 4.6.0 ) the cast fails and document mode is always false
// this will hopefully be fixed in later versions
const auto tabOptionV3( qstyleoption_cast<const QStyleOptionTab*>( option ) );
bool documentMode( tabOptionV3 ? tabOptionV3->documentMode : false );
const QTabWidget *tabWidget = ( widget && widget->parentWidget() ) ? qobject_cast<const QTabWidget *>( widget->parentWidget() ) : nullptr;
documentMode |= ( tabWidget ? tabWidget->documentMode() : true );
QRect gradientRect( rect );
switch( tabOption->shape )
{
case QTabBar::TriangularNorth:
case QTabBar::RoundedNorth:
gradientRect.adjust( 0, 0, 0, -5 );
break;
case QTabBar::TriangularSouth:
case QTabBar::RoundedSouth:
gradientRect.adjust( 0, 5, 0, 0 );
break;
case QTabBar::TriangularWest:
case QTabBar::RoundedWest:
gradientRect.adjust( 0, 0, -5, 0 );
break;
case QTabBar::TriangularEast:
case QTabBar::RoundedEast:
gradientRect.adjust( 5, 0, 0, 0 );
break;
default: return true;
}
// fade tabbar
QPixmap pixmap( gradientRect.size() );
{
pixmap.fill( Qt::transparent );
QPainter painter( &pixmap );
const bool verticalTabs( isVerticalTab( tabOption ) );
int width = 0;
int height = 0;
if( verticalTabs ) height = gradientRect.height();
else width = gradientRect.width();
QLinearGradient grad;
if( reverseLayout && !verticalTabs ) grad = QLinearGradient( 0, 0, width, height );
else grad = QLinearGradient( width, height, 0, 0 );
grad.setColorAt( 0, Qt::transparent );
grad.setColorAt( 0.6, Qt::black );
if( widget )
{ _helper->renderWindowBackground( &painter, pixmap.rect(), widget, palette ); }
painter.setCompositionMode( QPainter::CompositionMode_DestinationAtop );
painter.fillRect( pixmap.rect(), QBrush( grad ) );
painter.end();
}
// draw pixmap
painter->drawPixmap( gradientRect.topLeft() + QPoint( 0,-1 ), pixmap );
return true;
}
//___________________________________________________________________________________
bool Style::drawIndicatorToolBarHandlePrimitive( const QStyleOption* option, QPainter* painter, const QWidget* ) const
{
// do nothing if disabled from options
if( !StyleConfigData::toolBarDrawItemSeparator() )
{ return true; }
// copy rect and palette
const QRect& rect( option->rect );
const QPalette& palette( option->palette );
// store state
const State& state( option->state );
const bool horizontal( state & State_Horizontal );
int counter( 1 );
if( horizontal )
{
const int center( rect.left()+ rect.width()/2 );
for( int j = rect.top()+2; j <= rect.bottom()-3; j+=3, ++counter )
{
if( counter%2 == 0 ) _helper->renderDot( painter, QPoint( center+1, j ), palette.color( QPalette::Window ) );
else _helper->renderDot( painter, QPoint( center-2, j ), palette.color( QPalette::Window ) );
}
} else {
const int center( rect.top()+ rect.height()/2 );
for( int j = rect.left()+2; j <= rect.right()-3; j+=3, ++counter )
{
if( counter%2 == 0 ) _helper->renderDot( painter, QPoint( j, center+1 ), palette.color( QPalette::Window ) );
else _helper->renderDot( painter, QPoint( j, center-2 ), palette.color( QPalette::Window ) );
}
}
return true;
}
//___________________________________________________________________________________
bool Style::drawIndicatorToolBarSeparatorPrimitive( const QStyleOption* option, QPainter* painter, const QWidget* widget ) const
{
/*
do nothing if disabled from options
also need to check if widget is a combobox, because of Qt hack using 'toolbar' separator primitive
for rendering separators in comboboxes
*/
if( !( StyleConfigData::toolBarDrawItemSeparator() || qobject_cast<const QComboBox*>( widget ) ) )
{ return true; }
// store rect and palette
const QRect& rect( option->rect );
const QPalette& palette( option->palette );
// store state
const State& state( option->state );
const bool separatorIsVertical( state & State_Horizontal );
// define color and render
const QColor color( palette.color( QPalette::Window ) );
if( separatorIsVertical ) _helper->drawSeparator( painter, rect, color, Qt::Vertical );
else _helper->drawSeparator( painter, rect, color, Qt::Horizontal );
return true;
}
//___________________________________________________________________________________
bool Style::drawIndicatorBranchPrimitive( const QStyleOption* option, QPainter* painter, const QWidget* ) const
{
// copy rect and palette
const QRect& rect( option->rect );
const QPalette& palette( option->palette );
// state
const State& state( option->state );
const bool reverseLayout( option->direction == Qt::RightToLeft );
//draw expander
int expanderAdjust = 0;
if( state & State_Children )
{
int sizeLimit = qMin( rect.width(), rect.height() );
const bool expanderOpen( state & State_Open );
// make sure size limit is odd
expanderAdjust = sizeLimit/2 + 1;
// flags
const bool enabled( state & State_Enabled );
const bool mouseOver( enabled && ( state & State_MouseOver ) );
// color
const QColor expanderColor( mouseOver ? _helper->hoverColor( palette ):palette.color( QPalette::Text ) );
// get arrow size from option
ArrowSize size = ArrowSmall;
qreal penThickness( 1.2 );
switch( StyleConfigData::viewTriangularExpanderSize() )
{
case StyleConfigData::TE_TINY:
size = ArrowTiny;
break;
default:
case StyleConfigData::TE_SMALL:
size = ArrowSmall;
break;
case StyleConfigData::TE_NORMAL:
penThickness = 1.6;
size = ArrowNormal;
break;
}
// get arrows polygon
QPolygonF arrow;
if( expanderOpen ) arrow = genericArrow( ArrowDown, size );
else arrow = genericArrow( reverseLayout ? ArrowLeft:ArrowRight, size );
// render
painter->save();
painter->translate( QRectF( rect ).center() );
painter->setPen( QPen( expanderColor, penThickness, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin ) );
painter->setRenderHint( QPainter::Antialiasing );
painter->drawPolyline( arrow );
painter->restore();
}
// tree branches
if( !StyleConfigData::viewDrawTreeBranchLines() ) return true;
const QPoint center( rect.center() );
const QColor lineColor( KColorUtils::mix( palette.color( QPalette::Text ), palette.color( QPalette::Window ), 0.8 ) );
painter->setRenderHint( QPainter::Antialiasing, false );
painter->setPen( lineColor );
if( state & ( State_Item | State_Children | State_Sibling ) )
{
const QLine line( QPoint( center.x(), rect.top() ), QPoint( center.x(), center.y() - expanderAdjust ) );
painter->drawLine( line );
}
//The right/left ( depending on dir ) line gets drawn if we have an item
if( state & State_Item )
{
const QLine line = reverseLayout ?
QLine( QPoint( rect.left(), center.y() ), QPoint( center.x() - expanderAdjust, center.y() ) ):
QLine( QPoint( center.x() + expanderAdjust, center.y() ), QPoint( rect.right(), center.y() ) );
painter->drawLine( line );
}
//The bottom if we have a sibling
if( state & State_Sibling )
{
const QLine line( QPoint( center.x(), center.y() + expanderAdjust ), QPoint( center.x(), rect.bottom() ) );
painter->drawLine( line );
}
return true;
}
//___________________________________________________________________________________
bool Style::drawWidgetPrimitive( const QStyleOption* option, QPainter* painter, const QWidget* widget ) const
{
// check widget and attributes
if( !widget || !widget->testAttribute( Qt::WA_StyledBackground ) || widget->testAttribute( Qt::WA_NoSystemBackground ) ) return false;
if( !( ( widget->windowFlags() & Qt::WindowType_Mask ) & ( Qt::Window|Qt::Dialog ) ) ) return false;
if( !widget->isWindow() ) return false;
// normal "window" background
const QPalette& palette( option->palette );
// do not render background if palette brush has a texture (pixmap or image)
const QBrush brush( palette.brush( widget->backgroundRole() ) );
if( !( brush.texture().isNull() && brush.textureImage().isNull() ) )
{ return false; }
_helper->renderWindowBackground( painter, option->rect, widget, palette );
return true;
}
//___________________________________________________________________________________
bool Style::drawPushButtonLabelControl( const QStyleOption* option, QPainter* painter, const QWidget* widget ) const
{
// cast option and check
const QStyleOptionButton* buttonOption( qstyleoption_cast<const QStyleOptionButton*>( option ) );
if( !buttonOption ) return true;
// copy rect and palette
const QRect& rect( option->rect );
const QPalette& palette( option->palette );
// state
const State& state( option->state );
const bool enabled( state & State_Enabled );
const bool sunken( ( state & State_On ) || ( state & State_Sunken ) );
const bool mouseOver( enabled && (option->state & State_MouseOver) );
const bool flat( buttonOption->features & QStyleOptionButton::Flat );
// content
const bool hasIcon( !buttonOption->icon.isNull() );
const bool hasText( !buttonOption->text.isEmpty() );
// contents
QRect contentsRect( rect );
// color role
const QPalette::ColorRole textRole( flat ? QPalette::WindowText:QPalette::ButtonText );
// menu arrow
if( buttonOption->features & QStyleOptionButton::HasMenu )
{
// define rect
QRect arrowRect( contentsRect );
arrowRect.setLeft( contentsRect.right() - Metrics::MenuButton_IndicatorWidth + 1 );
arrowRect = centerRect( arrowRect, Metrics::MenuButton_IndicatorWidth, Metrics::MenuButton_IndicatorWidth );
contentsRect.setRight( arrowRect.left() - Metrics::Button_ItemSpacing - 1 );
contentsRect.adjust( Metrics::Button_MarginWidth, 0, 0, 0 );
arrowRect = visualRect( option, arrowRect );
// arrow
const qreal penThickness = 1.6;
QPolygonF arrow = genericArrow( ArrowDown, ArrowNormal );
const QColor color = palette.color( flat ? QPalette::WindowText:QPalette::ButtonText );
const QColor background = palette.color( flat ? QPalette::Window:QPalette::Button );
painter->save();
painter->translate( QRectF( arrowRect ).center() );
painter->setRenderHint( QPainter::Antialiasing );
const qreal offset( qMin( penThickness, qreal( 1 ) ) );
painter->translate( 0,offset );
painter->setPen( QPen( _helper->calcLightColor( background ), penThickness, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin ) );
painter->drawPolyline( arrow );
painter->translate( 0,-offset );
painter->setPen( QPen( _helper->decoColor( background, color ) , penThickness, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin ) );
painter->drawPolyline( arrow );
painter->restore();
} else contentsRect = insideMargin( contentsRect, Metrics::Button_MarginWidth, 0 );
// icon size
QSize iconSize( buttonOption->iconSize );
if( !iconSize.isValid() )
{
const int metric( pixelMetric( PM_SmallIconSize, option, widget ) );
iconSize = QSize( metric, metric );
}
// text size
const int textFlags( _mnemonics->textFlags() | Qt::AlignCenter );
const QSize textSize( option->fontMetrics.size( textFlags, buttonOption->text ) );
// adjust text and icon rect based on options
QRect iconRect;
QRect textRect;
if( hasText && !hasIcon ) textRect = contentsRect;
else if( hasIcon && !hasText ) iconRect = contentsRect;
else {
const int contentsWidth( iconSize.width() + textSize.width() + Metrics::Button_ItemSpacing );
iconRect = QRect( QPoint( contentsRect.left() + (contentsRect.width() - contentsWidth )/2, contentsRect.top() + (contentsRect.height() - iconSize.height())/2 ), iconSize );
textRect = QRect( QPoint( iconRect.right() + Metrics::ToolButton_ItemSpacing + 1, contentsRect.top() + (contentsRect.height() - textSize.height())/2 ), textSize );
}
// handle right to left
if( iconRect.isValid() ) iconRect = visualRect( option, iconRect );
if( textRect.isValid() ) textRect = visualRect( option, textRect );
// make sure there is enough room for icon
if( iconRect.isValid() ) iconRect = centerRect( iconRect, iconSize );
// render icon
if( hasIcon && iconRect.isValid() ) {
// icon state and mode
const QIcon::State iconState( sunken ? QIcon::On : QIcon::Off );
QIcon::Mode iconMode;
if( !enabled ) iconMode = QIcon::Disabled;
else if( mouseOver && flat ) iconMode = QIcon::Active;
else iconMode = QIcon::Normal;
const QPixmap pixmap = buttonOption->icon.pixmap( iconSize, iconMode, iconState );
drawItemPixmap( painter, iconRect, Qt::AlignCenter, pixmap );
}
// render text
if( hasText && textRect.isValid() )
{ drawItemText( painter, textRect, textFlags, palette, enabled, buttonOption->text, textRole ); }
return true;
}
//___________________________________________________________________________________
bool Style::drawToolButtonLabelControl( const QStyleOption* option, QPainter* painter, const QWidget* widget ) const
{
// cast option and check
const QStyleOptionToolButton* toolButtonOption( qstyleoption_cast<const QStyleOptionToolButton*>(option) );
// copy rect and palette
const QRect& rect = option->rect;
const QPalette& palette = option->palette;
// state
const State& state( option->state );
const bool enabled( state & State_Enabled );
const bool sunken( ( state & State_On ) || ( state & State_Sunken ) );
const bool mouseOver( enabled && (option->state & State_MouseOver) );
const bool flat( state & State_AutoRaise );
const bool hasArrow( toolButtonOption->features & QStyleOptionToolButton::Arrow );
const bool hasIcon( !( hasArrow || toolButtonOption->icon.isNull() ) );
const bool hasText( !toolButtonOption->text.isEmpty() );
// icon size
const QSize iconSize( toolButtonOption->iconSize );
// text size
int textFlags( _mnemonics->textFlags() );
const QSize textSize( option->fontMetrics.size( textFlags, toolButtonOption->text ) );
// adjust text and icon rect based on options
QRect iconRect;
QRect textRect;
if( hasText && ( !(hasArrow||hasIcon) || toolButtonOption->toolButtonStyle == Qt::ToolButtonTextOnly ) )
{
// text only
textRect = rect;
textFlags |= Qt::AlignCenter;
} else if( (hasArrow||hasIcon) && (!hasText || toolButtonOption->toolButtonStyle == Qt::ToolButtonIconOnly ) ) {
// icon only
iconRect = rect;
} else if( toolButtonOption->toolButtonStyle == Qt::ToolButtonTextUnderIcon ) {
const int contentsHeight( iconSize.height() + textSize.height() + Metrics::ToolButton_ItemSpacing );
iconRect = QRect( QPoint( rect.left() + (rect.width() - iconSize.width())/2, rect.top() + (rect.height() - contentsHeight)/2 ), iconSize );
textRect = QRect( QPoint( rect.left() + (rect.width() - textSize.width())/2, iconRect.bottom() + Metrics::ToolButton_ItemSpacing + 1 ), textSize );
textFlags |= Qt::AlignCenter;
} else {
const bool leftAlign( widget && widget->property( PropertyNames::toolButtonAlignment ).toInt() == Qt::AlignLeft );
if( leftAlign ) {
const int marginWidth( Metrics::Button_MarginWidth + Metrics::Frame_FrameWidth + 1 );
iconRect = QRect( QPoint( rect.left() + marginWidth, rect.top() + (rect.height() - iconSize.height())/2 ), iconSize );
}
else {
const int contentsWidth( iconSize.width() + textSize.width() + Metrics::ToolButton_ItemSpacing );
iconRect = QRect( QPoint( rect.left() + (rect.width() - contentsWidth )/2, rect.top() + (rect.height() - iconSize.height())/2 ), iconSize );
}
textRect = QRect( QPoint( iconRect.right() + Metrics::ToolButton_ItemSpacing + 1, rect.top() + (rect.height() - textSize.height())/2 ), textSize );
// handle right to left layouts
iconRect = visualRect( option, iconRect );
textRect = visualRect( option, textRect );
textFlags |= Qt::AlignLeft | Qt::AlignVCenter;
}
// make sure there is enough room for icon
if( iconRect.isValid() ) iconRect = centerRect( iconRect, iconSize );
// render arrow or icon
if( hasArrow && iconRect.isValid() )
{
QStyleOptionToolButton copy( *toolButtonOption );
copy.rect = iconRect;
switch( toolButtonOption->arrowType )
{
case Qt::LeftArrow: drawPrimitive( PE_IndicatorArrowLeft, ©, painter, widget ); break;
case Qt::RightArrow: drawPrimitive( PE_IndicatorArrowRight, ©, painter, widget ); break;
case Qt::UpArrow: drawPrimitive( PE_IndicatorArrowUp, ©, painter, widget ); break;
case Qt::DownArrow: drawPrimitive( PE_IndicatorArrowDown, ©, painter, widget ); break;
default: break;
}
} else if( hasIcon && iconRect.isValid() ) {
// icon state and mode
const QIcon::State iconState( sunken ? QIcon::On : QIcon::Off );
QIcon::Mode iconMode;
if( !enabled ) iconMode = QIcon::Disabled;
else if( mouseOver && flat ) iconMode = QIcon::Active;
else iconMode = QIcon::Normal;
const QPixmap pixmap = toolButtonOption->icon.pixmap( iconSize, iconMode, iconState );
drawItemPixmap( painter, iconRect, Qt::AlignCenter, pixmap );
}
// render text
if( hasText && textRect.isValid() )
{
const QPalette::ColorRole textRole( flat ? QPalette::WindowText: QPalette::ButtonText );
painter->setFont(toolButtonOption->font);
drawItemText( painter, textRect, textFlags, palette, enabled, toolButtonOption->text, textRole );
}
return true;
}
//___________________________________________________________________________________
bool Style::drawMenuBarItemControl( const QStyleOption* option, QPainter* painter, const QWidget* widget ) const
{
// cast option and check
const QStyleOptionMenuItem* menuItemOption = qstyleoption_cast<const QStyleOptionMenuItem*>( option );
if( !menuItemOption ) return true;
// copy rect and palette
const QRect& rect( option->rect );
const QPalette& palette( option->palette );
// store state
const State& state( option->state );
const bool enabled( state & State_Enabled );
const bool selected( enabled && (state & State_Selected) );
const bool sunken( state & State_Sunken );
const bool useStrongFocus = StyleConfigData::menuHighlightMode() == StyleConfigData::MM_STRONG;
if( enabled )
{
const bool active( state & State_Selected );
const bool animated( _animations->menuBarEngine().isAnimated( widget, rect.topLeft() ) );
const qreal opacity( _animations->menuBarEngine().opacity( widget, rect.topLeft() ) );
const QRect currentRect( _animations->menuBarEngine().currentRect( widget, rect.topLeft() ) );
const QRect animatedRect( _animations->menuBarEngine().animatedRect( widget ) );
const bool intersected( animatedRect.intersects( rect ) );
const bool current( currentRect.contains( rect.topLeft() ) );
const bool timerIsActive( _animations->menuBarEngine().isTimerActive( widget ) );
// do nothing in case of empty intersection between animated rect and current
if( ( intersected || !animated || animatedRect.isNull() ) && ( active || animated || timerIsActive ) )
{
QColor color( _helper->calcMidColor( palette.color( QPalette::Window ) ) );
if( StyleConfigData::menuHighlightMode() != StyleConfigData::MM_DARK )
{
if( state & State_Sunken )
{
if( StyleConfigData::menuHighlightMode() == StyleConfigData::MM_STRONG ) color = palette.color( QPalette::Highlight );
else color = KColorUtils::mix( color, KColorUtils::tint( color, palette.color( QPalette::Highlight ), 0.6 ) );
} else {
if( StyleConfigData::menuHighlightMode() == StyleConfigData::MM_STRONG ) color = KColorUtils::tint( color, _helper->hoverColor( palette ) );
else color = KColorUtils::mix( color, KColorUtils::tint( color, _helper->hoverColor( palette ) ) );
}
} else color = _helper->backgroundColor( color, widget, rect.center() );
// drawing
if( animated && intersected )
{
_helper->holeFlat( color, 0 ).render( insideMargin( animatedRect, 1 ), painter, TileSet::Full );
} else if( timerIsActive && current ) {
_helper->holeFlat( color, 0 ).render( insideMargin( rect, 1 ), painter, TileSet::Full );
} else if( animated && current ) {
color.setAlphaF( opacity );
_helper->holeFlat( color, 0 ).render( insideMargin( rect, 1 ), painter, TileSet::Full );
} else if( active ) {
_helper->holeFlat( color, 0 ).render( insideMargin( rect, 1 ), painter, TileSet::Full );
}
}
}
/*
check if item as an icon, in which case only the icon should be rendered
consistently with comment in QMenuBarPrivate::calcActionRects
*/
if( !menuItemOption->icon.isNull() )
{
// icon size is forced to SmallIconSize
const auto iconSize = pixelMetric(QStyle::PM_SmallIconSize, nullptr, widget);
const auto iconRect = centerRect( rect, iconSize, iconSize );
// decide icon mode and state
QIcon::Mode iconMode;
QIcon::State iconState;
if( !enabled )
{
iconMode = QIcon::Disabled;
iconState = QIcon::Off;
} else {
if( useStrongFocus && sunken ) iconMode = QIcon::Selected;
else if( selected ) iconMode = QIcon::Active;
else iconMode = QIcon::Normal;
iconState = sunken ? QIcon::On : QIcon::Off;
}
const auto pixmap = menuItemOption->icon.pixmap( iconSize, iconMode, iconState );
drawItemPixmap( painter, iconRect, Qt::AlignCenter, pixmap );
} else {
// text role
QPalette::ColorRole role( QPalette::WindowText );
if( useStrongFocus && sunken && enabled )
{ role = QPalette::HighlightedText; }
// text flags
const int textFlags( Qt::AlignCenter|_mnemonics->textFlags() );
drawItemText( painter, rect, textFlags, palette, enabled, menuItemOption->text, role );
}
return true;
}
//___________________________________________________________________________________
bool Style::drawMenuItemControl( const QStyleOption* option, QPainter* painter, const QWidget* widget ) const
{
// cast option and check
const QStyleOptionMenuItem* menuItemOption = qstyleoption_cast<const QStyleOptionMenuItem*>( option );
if( !menuItemOption ) return true;
if( menuItemOption->menuItemType == QStyleOptionMenuItem::EmptyArea ) return true;
// copy rect and palette
const QRect& rect( option->rect );
const QPalette& palette( option->palette );
// render background
renderMenuItemBackground( option, painter, widget );
// store state
const State& state( option->state );
const bool enabled( state & State_Enabled );
const bool selected( enabled && (state & State_Selected) );
const bool sunken( enabled && (state & (State_On|State_Sunken) ) );
const bool hasFocus( enabled && ( state & State_HasFocus ) );
const bool mouseOver( enabled && ( state & State_MouseOver ) );
const bool reverseLayout( option->direction == Qt::RightToLeft );
// Active indicator
if( selected )
{
// check if there is a 'sliding' animation in progress, in which case, do nothing
const QRect animatedRect( _animations->menuEngine().animatedRect( widget ) );
if( animatedRect.isNull() )
{
const bool animated( _animations->menuEngine().isAnimated( widget, Current ) );
const QRect currentRect( _animations->menuEngine().currentRect( widget, Current ) );
const bool intersected( currentRect.contains( rect.topLeft() ) );
const QColor color( _helper->menuBackgroundColor( _helper->calcMidColor( palette.color( QPalette::Window ) ), widget, rect.center() ) );
if( animated && intersected ) renderMenuItemRect( option, rect, color, palette, painter, _animations->menuEngine().opacity( widget, Current ) );
else renderMenuItemRect( option, rect, color, palette, painter );
}
}
// get rect available for contents
QRect contentsRect( insideMargin( rect, Metrics::MenuItem_MarginWidth ) );
// deal with separators
if( menuItemOption->menuItemType == QStyleOptionMenuItem::Separator )
{
// normal separator
if( menuItemOption->text.isEmpty() && menuItemOption->icon.isNull() )
{
// in all other cases draw regular separator
const QColor color( _helper->menuBackgroundColor( palette.color( QPalette::Window ), widget, rect.center() ) );
_helper->drawSeparator( painter, rect, color, Qt::Horizontal );
return true;
} else {
// separator can have a title and an icon
// in that case they are rendered as sunken flat toolbuttons
QStyleOptionToolButton toolButtonOption( separatorMenuItemOption( menuItemOption, widget ) );
toolButtonOption.state = State_On|State_Sunken|State_Enabled;
drawComplexControl( CC_ToolButton, &toolButtonOption, painter, widget );
return true;
}
}
// define relevant rectangles
// checkbox
QRect checkBoxRect;
if( menuItemOption->menuHasCheckableItems )
{
checkBoxRect = QRect( contentsRect.left(), contentsRect.top() + (contentsRect.height()-Metrics::CheckBox_Size)/2 - 1, Metrics::CheckBox_Size, Metrics::CheckBox_Size );
contentsRect.setLeft( checkBoxRect.right() + Metrics::MenuItem_ItemSpacing + 1 );
}
// render checkbox indicator
const CheckBoxState checkBoxState( menuItemOption->checked ? CheckOn:CheckOff );
if( menuItemOption->checkType == QStyleOptionMenuItem::NonExclusive )
{
checkBoxRect = visualRect( option, checkBoxRect );
StyleOptions styleOptions;
styleOptions |= Sunken;
if( !enabled ) styleOptions |= Disabled;
if( mouseOver ) styleOptions |= Hover;
if( hasFocus ) styleOptions |= Focus;
QPalette localPalette( palette );
localPalette.setColor( QPalette::Window, _helper->menuBackgroundColor( palette.color( QPalette::Window ), widget, rect.topLeft() ) );
renderCheckBox( painter, checkBoxRect, localPalette, styleOptions, checkBoxState );
} else if( menuItemOption->checkType == QStyleOptionMenuItem::Exclusive ) {
checkBoxRect = visualRect( option, checkBoxRect );
StyleOptions styleOptions;
if( !enabled ) styleOptions |= Disabled;
if( mouseOver ) styleOptions |= Hover;
if( hasFocus ) styleOptions |= Focus;
QPalette localPalette( palette );
localPalette.setColor( QPalette::Window, _helper->menuBackgroundColor( palette.color( QPalette::Window ), widget, rect.topLeft() ) );
renderRadioButton( painter, checkBoxRect, localPalette, styleOptions, checkBoxState );
}
// icon
const int iconWidth( isQtQuickControl( option, widget ) ? qMax( pixelMetric(PM_SmallIconSize, option, widget ), menuItemOption->maxIconWidth ) : menuItemOption->maxIconWidth );
QRect iconRect( contentsRect.left(), contentsRect.top() + (contentsRect.height()-iconWidth)/2, iconWidth, iconWidth );
contentsRect.setLeft( iconRect.right() + Metrics::MenuItem_ItemSpacing + 1 );
if( !menuItemOption->icon.isNull() )
{
const QSize iconSize( pixelMetric( PM_SmallIconSize, option, widget ), pixelMetric( PM_SmallIconSize, option, widget ) );
iconRect = centerRect( iconRect, iconSize );
iconRect = visualRect( option, iconRect );
// icon mode
QIcon::Mode mode;
if( (StyleConfigData::menuHighlightMode() != StyleConfigData::MM_DARK) && selected ) mode = QIcon::Selected;
else if( selected ) mode = QIcon::Active;
else if( enabled ) mode = QIcon::Normal;
else mode = QIcon::Disabled;
// icon state
const QIcon::State iconState( sunken ? QIcon::On:QIcon::Off );
const QPixmap icon = menuItemOption->icon.pixmap( iconRect.size(), mode, iconState );
painter->drawPixmap( iconRect, icon );
}
// text role
const QPalette::ColorRole textRole( ( selected && StyleConfigData::menuHighlightMode() == StyleConfigData::MM_STRONG ) ?
QPalette::HighlightedText:
QPalette::WindowText );
QRect arrowRect( contentsRect.right() - Metrics::MenuButton_IndicatorWidth + 1, contentsRect.top() + (contentsRect.height()-Metrics::MenuButton_IndicatorWidth)/2, Metrics::MenuButton_IndicatorWidth, Metrics::MenuButton_IndicatorWidth );
contentsRect.setRight( arrowRect.left() - Metrics::MenuItem_ItemSpacing - 1 );
// arrow
if( menuItemOption->menuItemType == QStyleOptionMenuItem::SubMenu )
{
const qreal penThickness = 1.6;
const QColor color = palette.color( textRole );
const QColor background = palette.color( QPalette::Window );
// get arrow shape
QPolygonF arrow = genericArrow( option->direction == Qt::LeftToRight ? ArrowRight : ArrowLeft, ArrowNormal );
painter->save();
painter->translate( QRectF( arrowRect ).center() );
painter->setRenderHint( QPainter::Antialiasing );
// white outline
const qreal offset( qMin( penThickness, qreal( 1 ) ) );
painter->translate( 0,offset );
painter->setPen( QPen( _helper->calcLightColor( background ), penThickness, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin ) );
painter->drawPolyline( arrow );
painter->translate( 0,-offset );
painter->setPen( QPen( _helper->decoColor( background, color ) , penThickness, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin ) );
painter->drawPolyline( arrow );
painter->restore();
}
// text
QRect textRect = contentsRect;
if( !menuItemOption->text.isEmpty() )
{
// adjust textRect
QString text = menuItemOption->text;
textRect = centerRect( textRect, textRect.width(), option->fontMetrics.size( _mnemonics->textFlags(), text ).height() );
textRect = visualRect( option, textRect );
// set font
painter->setFont( menuItemOption->font );
// locate accelerator and render
const int tabPosition( text.indexOf( QLatin1Char( '\t' ) ) );
if( tabPosition >= 0 )
{
QString accelerator( text.mid( tabPosition + 1 ) );
text = text.left( tabPosition );
drawItemText( painter, textRect, Qt::AlignRight | Qt::AlignVCenter | _mnemonics->textFlags(), palette, enabled, accelerator, textRole );
}
// render text
const int textFlags( Qt::AlignVCenter | (reverseLayout ? Qt::AlignRight : Qt::AlignLeft ) | _mnemonics->textFlags() );
drawItemText( painter, textRect, textFlags, palette, enabled, text, textRole );
}
return true;
}
//___________________________________________________________________________________
bool Style::drawProgressBarControl( const QStyleOption* option, QPainter* painter, const QWidget* widget ) const
{
const QStyleOptionProgressBar* progressBarOption( qstyleoption_cast<const QStyleOptionProgressBar*>( option ) );
if( !progressBarOption ) return true;
QStyleOptionProgressBar progressBarOption2 = *progressBarOption;
progressBarOption2.rect = subElementRect( SE_ProgressBarGroove, progressBarOption, widget );
drawControl( CE_ProgressBarGroove, &progressBarOption2, painter, widget );
// enable busy animations
const QObject* styleObject( widget ? widget:progressBarOption->styleObject );
if( styleObject && _animations->busyIndicatorEngine().enabled() )
{
// register QML object if defined
if( !widget && progressBarOption->styleObject )
{ _animations->busyIndicatorEngine().registerWidget( progressBarOption->styleObject ); }
_animations->busyIndicatorEngine().setAnimated( styleObject, progressBarOption->maximum == 0 && progressBarOption->minimum == 0 );
}
if( _animations->busyIndicatorEngine().isAnimated( styleObject ) )
{ progressBarOption2.progress = _animations->busyIndicatorEngine().value(); }
// render contents
progressBarOption2.rect = subElementRect( SE_ProgressBarContents, progressBarOption, widget );
drawControl( CE_ProgressBarContents, &progressBarOption2, painter, widget );
// render text
const bool textVisible( progressBarOption->textVisible );
const bool busy( progressBarOption->minimum == 0 && progressBarOption->maximum == 0 );
if( textVisible && !busy )
{
progressBarOption2.rect = subElementRect( SE_ProgressBarLabel, progressBarOption, widget );
drawControl( CE_ProgressBarLabel, &progressBarOption2, painter, widget );
}
return true;
}
//___________________________________________________________________________________
bool Style::drawProgressBarContentsControl( const QStyleOption* option, QPainter* painter, const QWidget* ) const
{
// cast option and check
const QStyleOptionProgressBar* progressBarOption = qstyleoption_cast<const QStyleOptionProgressBar*>( option );
if( !progressBarOption ) return true;
// get orientation
const auto progressBarOption2 = qstyleoption_cast<const QStyleOptionProgressBar*>( option );
const bool horizontal( !progressBarOption2 || progressBarOption2->orientation == Qt::Horizontal );
// copy rect and palette
const QRect& rect( option->rect );
const QPalette& palette( option->palette );
// make sure rect is large enough
if( rect.isValid() )
{
// calculate dimension
int dimension( 20 );
if( progressBarOption2 ) dimension = qMax( 5, horizontal ? rect.height() : rect.width() );
_helper->progressBarIndicator( palette, dimension ).render( rect, painter, TileSet::Full );
}
return true;
}
//___________________________________________________________________________________
bool Style::drawProgressBarGrooveControl( const QStyleOption* option, QPainter* painter, const QWidget* ) const
{
const auto progressBarOption = qstyleoption_cast<const QStyleOptionProgressBar*>( option );
const Qt::Orientation orientation( progressBarOption? progressBarOption->orientation : Qt::Horizontal );
renderScrollBarHole( painter, option->rect, option->palette.color( QPalette::Window ), orientation );
return true;
}
//___________________________________________________________________________________
bool Style::drawProgressBarLabelControl( const QStyleOption* option, QPainter* painter, const QWidget* widget ) const
{
// cast option and check
const QStyleOptionProgressBar* progressBarOption = qstyleoption_cast<const QStyleOptionProgressBar*>( option );
if( !progressBarOption ) return true;
// copy rect and palette
const QRect& rect( option->rect );
const QPalette& palette( option->palette );
// store state
const State& state( option->state );
const bool enabled( state & State_Enabled );
const bool reverseLayout = ( option->direction == Qt::RightToLeft );
// get orientation
const auto progressBarOption2 = qstyleoption_cast<const QStyleOptionProgressBar*>( option );
const bool horizontal = !progressBarOption2 || progressBarOption2->orientation == Qt::Horizontal;
// check inverted appearance
const bool inverted( progressBarOption2 ? progressBarOption2->invertedAppearance : false );
// rotate label for vertical layout
QTransform transform;
if( !horizontal )
{
if( reverseLayout ) transform.rotate( -90 );
else transform.rotate( 90 );
}
painter->setTransform( transform );
const QRect progressRect( transform.inverted().mapRect( subElementRect( SE_ProgressBarContents, progressBarOption, widget ) ) );
QRect textRect( transform.inverted().mapRect( rect ) );
Qt::Alignment hAlign( ( progressBarOption->textAlignment == Qt::AlignLeft ) ? Qt::AlignHCenter : progressBarOption->textAlignment );
/*
Figure out the geometry of the indicator.
This is copied from drawProgressBarContentsControl
*/
if( progressRect.isValid() )
{
// first pass ( normal )
QRect textClipRect( textRect );
if( horizontal )
{
if( (reverseLayout && !inverted) || (inverted && !reverseLayout) ) textClipRect.setRight( progressRect.left() );
else textClipRect.setLeft( progressRect.right() + 1 );
} else if( (reverseLayout && !inverted) || (inverted && !reverseLayout) ) textClipRect.setLeft( progressRect.right() + 1 );
else textClipRect.setRight( progressRect.left() );
painter->setClipRect( textClipRect );
drawItemText( painter, textRect, Qt::AlignVCenter | hAlign, palette, enabled, progressBarOption->text, QPalette::WindowText );
// second pass ( highlighted )
painter->setClipRect( progressRect );
drawItemText( painter, textRect, Qt::AlignVCenter | hAlign, palette, enabled, progressBarOption->text, QPalette::HighlightedText );
} else {
drawItemText( painter, textRect, Qt::AlignVCenter | hAlign, palette, enabled, progressBarOption->text, QPalette::WindowText );
}
return true;
}
//___________________________________________________________________________________
bool Style::drawScrollBarSliderControl( const QStyleOption* option, QPainter* painter, const QWidget* widget ) const
{
// cast option and check
const QStyleOptionSlider *sliderOption = qstyleoption_cast<const QStyleOptionSlider *>( option );
if( !sliderOption ) return true;
// store rect and palette
QRect rect( option->rect );
const QPalette& palette( option->palette );
// store state
const State& state( option->state );
const Qt::Orientation orientation( (state & State_Horizontal) ? Qt::Horizontal : Qt::Vertical );
const bool enabled( state & State_Enabled );
const bool mouseOver( enabled && ( state & State_MouseOver ) );
// update animations
_animations->scrollBarEngine().updateState( widget, enabled && ( sliderOption->activeSubControls & SC_ScrollBarSlider ) );
const bool animated( enabled && _animations->scrollBarEngine().isAnimated( widget, SC_ScrollBarSlider ) );
if( orientation == Qt::Horizontal ) rect = insideMargin( rect, 0, 1 );
else rect = insideMargin( rect, 1, 0 );
// render
if( animated ) renderScrollBarHandle( painter, rect, palette, orientation, mouseOver, _animations->scrollBarEngine().opacity( widget, SC_ScrollBarSlider ) );
else renderScrollBarHandle( painter, rect, palette, orientation, mouseOver );
return true;
}
//___________________________________________________________________________________
bool Style::drawScrollBarAddLineControl( const QStyleOption* option, QPainter* painter, const QWidget* widget ) const
{
// do nothing if no buttons are defined
if( _addLineButtons == NoButton ) return true;
// cast option and check
const QStyleOptionSlider* sliderOption( qstyleoption_cast<const QStyleOptionSlider*>( option ) );
if( !sliderOption ) return true;
const State& state( option->state );
const bool horizontal( state & State_Horizontal );
const bool reverseLayout( option->direction == Qt::RightToLeft );
// colors
const QPalette& palette( option->palette );
const QColor background( palette.color( QPalette::Window ) );
// adjust rect, based on number of buttons to be drawn
const QRect rect( scrollBarInternalSubControlRect( sliderOption, SC_ScrollBarAddLine ) );
QColor color;
QStyleOptionSlider copy( *sliderOption );
if( _addLineButtons == DoubleButton )
{
if( horizontal )
{
//Draw the arrows
const QSize halfSize( rect.width()/2, rect.height() );
const QRect leftSubButton( rect.topLeft(), halfSize );
const QRect rightSubButton( leftSubButton.topRight() + QPoint( 1, 0 ), halfSize );
copy.rect = leftSubButton;
color = scrollBarArrowColor( ©, reverseLayout ? SC_ScrollBarAddLine:SC_ScrollBarSubLine, widget );
renderScrollBarArrow( painter, leftSubButton, color, background, ArrowLeft );
copy.rect = rightSubButton;
color = scrollBarArrowColor( ©, reverseLayout ? SC_ScrollBarSubLine:SC_ScrollBarAddLine, widget );
renderScrollBarArrow( painter, rightSubButton, color, background, ArrowRight );
} else {
const QSize halfSize( rect.width(), rect.height()/2 );
const QRect topSubButton( rect.topLeft(), halfSize );
const QRect botSubButton( topSubButton.bottomLeft() + QPoint( 0, 1 ), halfSize );
copy.rect = topSubButton;
color = scrollBarArrowColor( ©, SC_ScrollBarSubLine, widget );
renderScrollBarArrow( painter, topSubButton, color, background, ArrowUp );
copy.rect = botSubButton;
color = scrollBarArrowColor( ©, SC_ScrollBarAddLine, widget );
renderScrollBarArrow( painter, botSubButton, color, background, ArrowDown );
}
} else if( _addLineButtons == SingleButton ) {
copy.rect = rect;
color = scrollBarArrowColor( ©, SC_ScrollBarAddLine, widget );
if( horizontal ) renderScrollBarArrow( painter, rect, color, background, reverseLayout ? ArrowLeft : ArrowRight );
else renderScrollBarArrow( painter, rect, color, background, ArrowDown );
}
return true;
}
//___________________________________________________________________________________
bool Style::drawScrollBarSubLineControl( const QStyleOption* option, QPainter* painter, const QWidget* widget ) const
{
// do nothing if no buttons are set
if( _subLineButtons == NoButton ) return true;
// cast option and check
const QStyleOptionSlider* sliderOption( qstyleoption_cast<const QStyleOptionSlider*>( option ) );
if( !sliderOption ) return true;
const State& state( option->state );
const bool horizontal( state & State_Horizontal );
const bool reverseLayout( option->direction == Qt::RightToLeft );
// colors
const QPalette& palette( option->palette );
const QColor background( palette.color( QPalette::Window ) );
// adjust rect, based on number of buttons to be drawn
QRect rect( scrollBarInternalSubControlRect( sliderOption, SC_ScrollBarSubLine ) );
QColor color;
QStyleOptionSlider copy( *sliderOption );
if( _subLineButtons == DoubleButton )
{
if( horizontal )
{
//Draw the arrows
const QSize halfSize( rect.width()/2, rect.height() );
const QRect leftSubButton( rect.topLeft(), halfSize );
const QRect rightSubButton( leftSubButton.topRight() + QPoint( 1, 0 ), halfSize );
copy.rect = leftSubButton;
color = scrollBarArrowColor( ©, reverseLayout ? SC_ScrollBarAddLine:SC_ScrollBarSubLine, widget );
renderScrollBarArrow( painter, leftSubButton, color, background, ArrowLeft );
copy.rect = rightSubButton;
color = scrollBarArrowColor( ©, reverseLayout ? SC_ScrollBarSubLine:SC_ScrollBarAddLine, widget );
renderScrollBarArrow( painter, rightSubButton, color, background, ArrowRight );
} else {
const QSize halfSize( rect.width(), rect.height()/2 );
const QRect topSubButton( rect.topLeft(), halfSize );
const QRect botSubButton( topSubButton.bottomLeft() + QPoint( 0, 1 ), halfSize );
copy.rect = topSubButton;
color = scrollBarArrowColor( ©, SC_ScrollBarSubLine, widget );
renderScrollBarArrow( painter, topSubButton, color, background, ArrowUp );
copy.rect = botSubButton;
color = scrollBarArrowColor( ©, SC_ScrollBarAddLine, widget );
renderScrollBarArrow( painter, botSubButton, color, background, ArrowDown );
}
} else if( _subLineButtons == SingleButton ) {
copy.rect = rect;
color = scrollBarArrowColor( ©, SC_ScrollBarSubLine, widget );
if( horizontal ) renderScrollBarArrow( painter, rect, color, background, reverseLayout ? ArrowRight : ArrowLeft );
else renderScrollBarArrow( painter, rect, color, background, ArrowUp );
}
return true;
}
//___________________________________________________________________________________
bool Style::drawShapedFrameControl( const QStyleOption* option, QPainter* painter, const QWidget* widget ) const
{
// cast option and check
const auto frameOption = qstyleoption_cast<const QStyleOptionFrame*>( option );
if( !frameOption ) return false;
switch( frameOption->frameShape )
{
case QFrame::Box:
{
if( option->state & State_Sunken ) return true;
else break;
}
case QFrame::HLine:
{
const QColor color( _helper->backgroundColor( option->palette.color( QPalette::Window ), widget, option->rect.center() ) );
_helper->drawSeparator( painter, option->rect, color, Qt::Horizontal );
return true;
}
case QFrame::VLine:
{
const QColor color( _helper->backgroundColor( option->palette.color( QPalette::Window ), widget, option->rect.center() ) );
_helper->drawSeparator( painter, option->rect, color, Qt::Vertical );
return true;
}
case QFrame::StyledPanel:
{
if( isQtQuickControl( option, widget ) )
{
// ComboBox popup frame
drawFrameMenuPrimitive( option, painter, widget );
return true;
} else break;
}
default: break;
}
return false;
}
//___________________________________________________________________________________
bool Style::drawRubberBandControl( const QStyleOption* option, QPainter* painter, const QWidget* ) const
{
const QPalette& palette( option->palette );
const QRect rect( option->rect );
QColor color = palette.color( QPalette::Highlight );
painter->setPen( KColorUtils::mix( color, palette.color( QPalette::Active, QPalette::WindowText ) ) );
color.setAlpha( 50 );
painter->setBrush( color );
painter->setClipRegion( rect );
painter->drawRect( rect.adjusted( 0, 0, -1, -1 ) );
return true;
}
//___________________________________________________________________________________
bool Style::drawHeaderSectionControl( const QStyleOption* option, QPainter* painter, const QWidget* widget ) const
{
// cast option and check
const QStyleOptionHeader* headerOption( qstyleoption_cast<const QStyleOptionHeader *>( option ) );
if( !headerOption ) return true;
// copy rect and palette
const QRect& rect( option->rect );
const QPalette& palette( option->palette );
// store state
const bool horizontal( headerOption->orientation == Qt::Horizontal );
const bool reverseLayout( option->direction == Qt::RightToLeft );
const bool isFirst( horizontal && ( headerOption->position == QStyleOptionHeader::Beginning ) );
const bool isCorner( widget && widget->inherits( "QTableCornerButton" ) );
// corner header lines
if( isCorner )
{
if( widget ) _helper->renderWindowBackground( painter, rect, widget, palette );
else painter->fillRect( rect, palette.color( QPalette::Window ) );
if( reverseLayout ) renderHeaderLines( rect, palette, painter, TileSet::BottomLeft );
else renderHeaderLines( rect, palette, painter, TileSet::BottomRight );
} else renderHeaderBackground( rect, palette, painter, widget, horizontal, reverseLayout );
// dots
const QColor color( palette.color( QPalette::Window ) );
if( horizontal )
{
if( headerOption->section != 0 || isFirst )
{
const int center( rect.center().y() );
const int pos( reverseLayout ? rect.left()+1 : rect.right()-1 );
_helper->renderDot( painter, QPoint( pos, center-3 ), color );
_helper->renderDot( painter, QPoint( pos, center ), color );
_helper->renderDot( painter, QPoint( pos, center+3 ), color );
}
} else {
const int center( rect.center().x() );
const int pos( rect.bottom()-1 );
_helper->renderDot( painter, QPoint( center-3, pos ), color );
_helper->renderDot( painter, QPoint( center, pos ), color );
_helper->renderDot( painter, QPoint( center+3, pos ), color );
}
return true;
}
//___________________________________________________________________________________
bool Style::drawHeaderEmptyAreaControl( const QStyleOption* option, QPainter* painter, const QWidget* widget ) const
{
// use the same background as in drawHeaderPrimitive
QPalette palette( option->palette );
if( widget && _animations->widgetEnableStateEngine().isAnimated( widget, AnimationEnable ) )
{ palette = _helper->disabledPalette( palette, _animations->widgetEnableStateEngine().opacity( widget, AnimationEnable ) ); }
const bool horizontal( option->state & QStyle::State_Horizontal );
const bool reverseLayout( option->direction == Qt::RightToLeft );
renderHeaderBackground( option->rect, palette, painter, widget, horizontal, reverseLayout );
return true;
}
//___________________________________________________________________________________
bool Style::drawTabBarTabLabelControl( const QStyleOption* option, QPainter* painter, const QWidget* widget ) const
{
// call parent style method
KStyle::drawControl( CE_TabBarTabLabel, option, painter, widget );
// store rect and palette
const QRect& rect( option->rect );
const QPalette& palette( option->palette );
// check focus
const State& state( option->state );
const bool enabled( state & State_Enabled );
const bool selected( state & State_Selected );
const bool hasFocus( enabled && selected && (state & State_HasFocus) );
// update mouse over animation state
_animations->tabBarEngine().updateState( widget, rect.topLeft(), AnimationFocus, hasFocus );
const bool animated( enabled && selected && _animations->tabBarEngine().isAnimated( widget, rect.topLeft(), AnimationFocus ) );
const qreal opacity( _animations->tabBarEngine().opacity( widget, rect.topLeft(), AnimationFocus ) );
if( !( hasFocus || animated ) ) return true;
// code is copied from QCommonStyle, but adds focus
// cast option and check
const QStyleOptionTab *tabOption( qstyleoption_cast<const QStyleOptionTab*>(option) );
if( !tabOption || tabOption->text.isEmpty() ) return true;
// tab option rect
const bool verticalTabs( isVerticalTab( tabOption ) );
const int textFlags( Qt::AlignCenter | _mnemonics->textFlags() );
// text rect
QRect textRect( subElementRect(SE_TabBarTabText, option, widget) );
if( verticalTabs )
{
// properly rotate painter
painter->save();
int newX, newY, newRot;
if( tabOption->shape == QTabBar::RoundedEast || tabOption->shape == QTabBar::TriangularEast)
{
newX = rect.width() + rect.x();
newY = rect.y();
newRot = 90;
} else {
newX = rect.x();
newY = rect.y() + rect.height();
newRot = -90;
}
QTransform transform;
transform.translate( newX, newY );
transform.rotate(newRot);
painter->setTransform( transform, true );
}
// adjust text rect based on font metrics
textRect = option->fontMetrics.boundingRect( textRect, textFlags, tabOption->text );
// focus color
QColor focusColor;
if( animated ) focusColor = _helper->alphaColor( _helper->focusColor( palette ), opacity );
else if( hasFocus ) focusColor = _helper->focusColor( palette );
// render focus line
if( focusColor.isValid() )
{
painter->save();
painter->setRenderHint( QPainter::Antialiasing, false );
painter->setBrush( Qt::NoBrush );
painter->setPen( focusColor );
painter->translate( 0, 2 );
painter->drawLine( textRect.bottomLeft(), textRect.bottomRight() );
painter->restore();
}
if( verticalTabs ) painter->restore();
return true;
}
//___________________________________________________________________________________
bool Style::drawTabBarTabShapeControl( const QStyleOption* option, QPainter* painter, const QWidget* widget ) const
{
// check if tabwidget is selected and redirect
const State& state( option->state );
const bool selected( state & State_Selected );
if( selected ) return drawTabBarTabShapeControl_selected( option, painter, widget );
else return drawTabBarTabShapeControl_unselected( option, painter, widget );
}
//___________________________________________________________________________________
bool Style::drawTabBarTabShapeControl_selected( const QStyleOption* option, QPainter* painter, const QWidget* widget ) const
{
// cast option and check
const QStyleOptionTab* tabOption( qstyleoption_cast<const QStyleOptionTab*>( option ) );
if( !tabOption ) return true;
// copy rect and palette
const QRect& rect( option->rect );
const QPalette& palette( option->palette );
// store state
const State& state( option->state );
const bool enabled( state & State_Enabled );
const bool reverseLayout( option->direction == Qt::RightToLeft );
// tab position and state
const QStyleOptionTab::TabPosition& position = tabOption->position;
bool isFirst( position == QStyleOptionTab::OnlyOneTab || position == QStyleOptionTab::Beginning );
bool isLast( position == QStyleOptionTab::OnlyOneTab || position == QStyleOptionTab::End );
// document mode
const auto tabOptionV3 = qstyleoption_cast<const QStyleOptionTab*>( option );
bool documentMode = tabOptionV3 ? tabOptionV3->documentMode : false;
const QTabWidget *tabWidget = ( widget && widget->parentWidget() ) ? qobject_cast<const QTabWidget *>( widget->parentWidget() ) : nullptr;
documentMode |= ( tabWidget ? tabWidget->documentMode() : true );
// this is needed to complete the base frame when there are widgets in tabbar
const QTabBar* tabBar( qobject_cast<const QTabBar*>( widget ) );
const QRect tabBarRect( tabBar ? tabBar->rect():QRect() );
// check if tab is being dragged
const bool isDragged( painter->device() != tabBar );
// hover and animation state
/* all are disabled when tabBar is locked ( drag in progress ) */
const bool tabBarLocked( _tabBarData->locks( tabBar ) );
const bool mouseOver( enabled && !tabBarLocked && ( state & State_MouseOver ) );
// animation state
_animations->tabBarEngine().updateState( widget, rect.topLeft(), AnimationHover, mouseOver );
// handle base frame painting, for tabbars in which tab is being dragged
_tabBarData->drawTabBarBaseControl( tabOption, painter, widget );
if( tabBar && isDragged ) _tabBarData->lock( tabBar );
else if( _tabBarData->locks( tabBar ) ) _tabBarData->release();
// corner widgets
const bool verticalTabs( isVerticalTab( tabOption ) );
const bool hasLeftCornerWidget( (tabOption->cornerWidgets & QStyleOptionTab::LeftCornerWidget) && !verticalTabs );
// true if widget is aligned to the frame
const bool isFrameAligned( !documentMode && isFirst && !hasLeftCornerWidget && !isDragged );
// swap state based on reverse layout, so that they become layout independent
if( reverseLayout && !verticalTabs ) qSwap( isFirst, isLast );
// part of the tab in which the text is drawn
QRect tabRect( insideMargin( rect, -1 ) );
SlabRect tabSlab( insideMargin( rect, -1 ), TileSet::Ring );
// connection to the frame
SlabRect::List slabs;
switch( tabOption->shape )
{
case QTabBar::RoundedNorth:
case QTabBar::TriangularNorth:
{
tabSlab.tiles &= ~TileSet::Bottom;
tabSlab.rect.adjust( 0, 0, 0, 2 );
if( isDragged ) break;
// left side
if( isFrameAligned && !reverseLayout )
{
QRect frameRect( rect );
frameRect.setLeft( frameRect.left() - 1 );
frameRect.setRight( tabRect.left() );
frameRect.setTop( tabRect.bottom() - 4 );
slabs << SlabRect( frameRect, TileSet::Left ).adjusted( TileSet::DefaultSize );
} else {
QRect frameRect( rect );
frameRect.setRight( tabRect.left() + 3 );
frameRect.setTop( rect.bottom() - TileSet::DefaultSize + 1 );
slabs << SlabRect( frameRect, TileSet::Top ).adjusted( TileSet::DefaultSize );
}
// right side
if( isFrameAligned && reverseLayout )
{
QRect frameRect( rect );
frameRect.setLeft( tabRect.right() );
frameRect.setRight( frameRect.right() + 1 );
frameRect.setTop( tabRect.bottom() - 4 );
slabs << SlabRect( frameRect, TileSet::Right ).adjusted( TileSet::DefaultSize );
} else {
QRect frameRect( rect );
frameRect.setLeft( tabRect.right() - 3 );
frameRect.setTop( rect.bottom() - TileSet::DefaultSize + 1 );
slabs << SlabRect( frameRect, TileSet::Top ).adjusted( TileSet::DefaultSize );
}
// extra base, to extend below inactive tabs and buttons
if( tabBar )
{
QRect frameRect( rect );
frameRect.setTop( rect.bottom() - Metrics::TabBar_BaseOverlap + 1 );
if( rect.left() > tabBarRect.left() )
{
frameRect.setLeft( tabBarRect.left() - Metrics::TabBar_BaseOverlap );
frameRect.setRight( rect.left() + Metrics::TabBar_BaseOverlap - 1 );
if( documentMode || reverseLayout ) slabs << SlabRect( frameRect, TileSet::Top );
else slabs << SlabRect( frameRect, TileSet::TopLeft );
}
if( rect.right() < tabBarRect.right() )
{
frameRect.setLeft( rect.right() - Metrics::TabBar_BaseOverlap + 1 );
frameRect.setRight( tabBarRect.right() + Metrics::TabBar_BaseOverlap );
if( documentMode || !reverseLayout ) slabs << SlabRect( frameRect, TileSet::Top );
else slabs << SlabRect( frameRect, TileSet::TopRight );
}
}
break;
}
case QTabBar::RoundedSouth:
case QTabBar::TriangularSouth:
{
tabSlab.tiles &= ~TileSet::Top;
tabSlab.rect.adjust( 0, -2, 0, 0 );
if( isDragged ) break;
// left side
if( isFrameAligned && !reverseLayout )
{
QRect frameRect( rect );
frameRect.setLeft( frameRect.left() - 1 );
frameRect.setRight( tabRect.left() );
frameRect.setBottom( tabRect.top() + 4 );
slabs << SlabRect( frameRect, TileSet::Left ).adjusted( TileSet::DefaultSize );
} else {
QRect frameRect( rect );
frameRect.setRight( tabRect.left() + 3 );
frameRect.setBottom( rect.top() + TileSet::DefaultSize - 1 );
slabs << SlabRect( frameRect, TileSet::Bottom ).adjusted( TileSet::DefaultSize );
}
// right side
if( isFrameAligned && reverseLayout )
{
QRect frameRect( rect );
frameRect.setLeft( tabRect.right() );
frameRect.setRight( frameRect.right() + 1 );
frameRect.setBottom( tabRect.top() + 4 );
slabs << SlabRect( frameRect, TileSet::Right ).adjusted( TileSet::DefaultSize );
} else {
QRect frameRect( rect );
frameRect.setLeft( tabRect.right() - 3 );
frameRect.setBottom( rect.top() + TileSet::DefaultSize - 1 );
slabs << SlabRect( frameRect, TileSet::Bottom ).adjusted( TileSet::DefaultSize );
}
// extra base, to extend below tabbar buttons
if( tabBar )
{
QRect frameRect( rect );
frameRect.setBottom( rect.top() + Metrics::TabBar_BaseOverlap - 1 );
if( rect.left() > tabBarRect.left() )
{
frameRect.setLeft( tabBarRect.left() - Metrics::TabBar_BaseOverlap );
frameRect.setRight( rect.left() + Metrics::TabBar_BaseOverlap - 1 );
if( documentMode || reverseLayout ) slabs << SlabRect( frameRect, TileSet::Bottom );
else slabs << SlabRect( frameRect, TileSet::BottomLeft );
}
if( rect.right() < tabBarRect.right() )
{
frameRect.setLeft( rect.right() - Metrics::TabBar_BaseOverlap + 1 );
frameRect.setRight( tabBarRect.right() + Metrics::TabBar_BaseOverlap );
if( documentMode || !reverseLayout ) slabs << SlabRect( frameRect, TileSet::Bottom );
else slabs << SlabRect( frameRect, TileSet::BottomRight );
}
}
break;
}
case QTabBar::RoundedWest:
case QTabBar::TriangularWest:
{
tabSlab.tiles &= ~TileSet::Right;
tabSlab.rect.adjust( 0, 0, 2, 0 );
if( isDragged ) break;
// top side
if( isFrameAligned )
{
QRect frameRect( rect );
frameRect.setLeft( tabRect.right() - 4 );
frameRect.setTop( frameRect.top() - 1 );
frameRect.setBottom( tabRect.top() );
slabs << SlabRect( frameRect, TileSet::Top ).adjusted( TileSet::DefaultSize );
} else {
QRect frameRect( rect );
frameRect.setLeft( rect.right() - TileSet::DefaultSize + 1 );
frameRect.setBottom( tabRect.top() + 3 );
slabs << SlabRect( frameRect, TileSet::Left ).adjusted( TileSet::DefaultSize );
}
// bottom side
QRect frameRect( rect );
frameRect.setLeft( rect.right() - TileSet::DefaultSize + 1 );
frameRect.setTop( tabRect.bottom() - 3 );
slabs << SlabRect( frameRect, TileSet::Left ).adjusted( TileSet::DefaultSize );
// extra base, to extend below tabbar buttons
if( tabBar )
{
QRect frameRect( rect );
frameRect.setLeft( rect.right() - Metrics::TabBar_BaseOverlap + 1 );
if( rect.top() > tabBarRect.top() )
{
frameRect.setTop( tabBarRect.top() - Metrics::TabBar_BaseOverlap );
frameRect.setBottom( rect.top() + Metrics::TabBar_BaseOverlap - 1 );
if( documentMode ) slabs << SlabRect( frameRect, TileSet::Left );
else slabs << SlabRect( frameRect, TileSet::TopLeft );
}
if( rect.bottom() < tabBarRect.bottom() )
{
frameRect.setTop( rect.bottom() - Metrics::TabBar_BaseOverlap + 1 );
frameRect.setBottom( tabBarRect.bottom() + Metrics::TabBar_BaseOverlap - 1 );
slabs << SlabRect( frameRect, TileSet::Left );
}
}
break;
}
case QTabBar::RoundedEast:
case QTabBar::TriangularEast:
{
tabSlab.tiles &= ~TileSet::Left;
tabSlab.rect.adjust( -2, 0, 0, 0 );
if( isDragged ) break;
// top side
if( isFrameAligned )
{
QRect frameRect( rect );
frameRect.setRight( tabRect.left() + 4 );
frameRect.setTop( frameRect.top() - 1 );
frameRect.setBottom( tabRect.top() );
slabs << SlabRect( frameRect, TileSet::Top ).adjusted( TileSet::DefaultSize );
} else {
QRect frameRect( rect );
frameRect.setRight( rect.left() + TileSet::DefaultSize - 1 );
frameRect.setBottom( tabRect.top() + 3 );
slabs << SlabRect( frameRect, TileSet::Right ).adjusted( TileSet::DefaultSize );
}
// bottom side
QRect frameRect( rect );
frameRect.setRight( rect.left() + TileSet::DefaultSize - 1 );
frameRect.setTop( tabRect.bottom() - 3 );
slabs << SlabRect( frameRect, TileSet::Right ).adjusted( TileSet::DefaultSize );
// extra base, to extend below tabbar buttons
if( tabBar )
{
QRect frameRect( rect );
frameRect.setRight( rect.left() + Metrics::TabBar_BaseOverlap - 1 );
if( rect.top() > tabBarRect.top() )
{
frameRect.setTop( tabBarRect.top() - Metrics::TabBar_BaseOverlap );
frameRect.setBottom( rect.top() + Metrics::TabBar_BaseOverlap - 1 );
if( documentMode ) slabs << SlabRect( frameRect, TileSet::Right );
else slabs << SlabRect( frameRect, TileSet::TopRight );
}
if( rect.bottom() < tabBarRect.bottom() )
{
frameRect.setTop( rect.bottom() - Metrics::TabBar_BaseOverlap + 1 );
frameRect.setBottom( tabBarRect.bottom() + Metrics::TabBar_BaseOverlap - 1 );
slabs << SlabRect( frameRect, TileSet::Right );
}
}
break;
}
default: break;
}
// store default color
const QColor color( palette.color( QPalette::Window ) );
// render connections to frame
// extra care must be taken care of so that no slab
// extends beyond tabWidget frame, if any
const QRect tabWidgetRect( tabWidget ? tabWidget->rect().translated( -widget->geometry().topLeft() ) : QRect() );
foreach( SlabRect slab, slabs ) // krazy:exclude=foreach
{
adjustSlabRect( slab, tabWidgetRect, documentMode, verticalTabs );
renderSlab( painter, slab, color, NoFill );
}
// adjust clip rect and render tab
if( tabBar )
{
painter->save();
painter->setClipRegion( tabBarClipRegion( tabBar ) );
}
// fill tab
if( isDragged ) fillTabBackground( painter, tabRect, color, widget );
// slab options
renderSlab( painter, tabSlab, color, NoFill );
fillTab( painter, tabRect, color, tabOption->shape );
// restore clip region
if( tabBar ) painter->restore();
return true;
}
//___________________________________________________________________________________
bool Style::drawTabBarTabShapeControl_unselected( const QStyleOption* option, QPainter* painter, const QWidget* widget ) const
{
// cast option and check
const QStyleOptionTab* tabOption( qstyleoption_cast<const QStyleOptionTab*>( option ) );
if( !tabOption ) return true;
// copy rect and palette
const QRect& rect( option->rect );
const QPalette& palette( option->palette );
// store state
const State& state( option->state );
const bool enabled( state & State_Enabled );
const bool reverseLayout( option->direction == Qt::RightToLeft );
// tab position and flags
const QStyleOptionTab::TabPosition& position = tabOption->position;
bool isFirst( position == QStyleOptionTab::OnlyOneTab || position == QStyleOptionTab::Beginning );
bool isLast( position == QStyleOptionTab::OnlyOneTab || position == QStyleOptionTab::End );
bool isLeftOfSelected( tabOption->selectedPosition == QStyleOptionTab::NextIsSelected );
bool isRightOfSelected( tabOption->selectedPosition == QStyleOptionTab::PreviousIsSelected );
// document mode
const auto tabOptV3 = qstyleoption_cast<const QStyleOptionTab*>( option );
bool documentMode = tabOptV3 ? tabOptV3->documentMode : false;
const QTabWidget *tabWidget = ( widget && widget->parentWidget() ) ? qobject_cast<const QTabWidget *>( widget->parentWidget() ) : nullptr;
documentMode |= ( tabWidget ? tabWidget->documentMode() : true );
// this is needed to complete the base frame when there are widgets in tabbar
const QTabBar* tabBar( qobject_cast<const QTabBar*>( widget ) );
const QRect tabBarRect( tabBar ? tabBar->rect():QRect() );
// hover and animation flags
/* all are disabled when tabBar is locked ( drag in progress ) */
const bool tabBarLocked( _tabBarData->locks( tabBar ) );
const bool mouseOver( enabled && !tabBarLocked && ( state & State_MouseOver ) );
// animation state
_animations->tabBarEngine().updateState( widget, rect.topLeft(), AnimationHover, mouseOver );
const bool animated( enabled && !tabBarLocked && _animations->tabBarEngine().isAnimated( widget, rect.topLeft(), AnimationHover ) );
// corner widgets
const bool verticalTabs( isVerticalTab( tabOption ) );
const bool hasLeftCornerWidget( ( tabOption->cornerWidgets & QStyleOptionTab::LeftCornerWidget ) && !verticalTabs );
// true if widget is aligned to the frame
/* need to check for 'isRightOfSelected' because for some reason the isFirst flag is set when active tab is being moved */
const bool isFrameAligned( !documentMode && isFirst && !hasLeftCornerWidget && !isRightOfSelected );
isFirst &= !isRightOfSelected;
isLast &= !isLeftOfSelected;
// swap flags based on reverse layout, so that they become layout independent
if( reverseLayout && !verticalTabs )
{
qSwap( isFirst, isLast );
qSwap( isLeftOfSelected, isRightOfSelected );
}
const qreal radius = 4;
// part of the tab in which the text is drawn
QRect tabRect( rect );
QPainterPath path;
// highlighted slab (if any)
SlabRect highlightSlab;
switch( tabOption->shape )
{
case QTabBar::RoundedNorth:
case QTabBar::TriangularNorth:
{
tabRect.adjust( 0, 3, 1, -4 );
// adjust sides when slab is adjacent to selected slab
if( isLeftOfSelected ) tabRect.adjust( 0, 0, 2, 0 );
else if( isRightOfSelected ) tabRect.adjust( -2, 0, 0, 0 );
if( isFirst )
{
tabRect.adjust( 1, 0, 0, 0 );
if( isFrameAligned ) path.moveTo( tabRect.bottomLeft() + QPoint( 0, 2 ) );
else path.moveTo( tabRect.bottomLeft() );
path.lineTo( tabRect.topLeft() + QPointF( 0, radius ) );
path.quadTo( tabRect.topLeft(), tabRect.topLeft() + QPoint( radius, 0 ) );
path.lineTo( tabRect.topRight() );
path.lineTo( tabRect.bottomRight() );
} else if( isLast ) {
tabRect.adjust( 0, 0, -2, 0 );
path.moveTo( tabRect.bottomLeft() );
path.lineTo( tabRect.topLeft() );
path.lineTo( tabRect.topRight() - QPointF( radius, 0 ) );
path.quadTo( tabRect.topRight(), tabRect.topRight() + QPointF( 0, radius ) );
if( isFrameAligned ) path.lineTo( tabRect.bottomRight() + QPointF( 0, 2 ) );
else path.lineTo( tabRect.bottomRight() );
} else {
path.moveTo( tabRect.bottomLeft() );
path.lineTo( tabRect.topLeft() );
path.lineTo( tabRect.topRight() );
path.lineTo( tabRect.bottomRight() );
}
// highlight
QRect highlightRect( tabRect.left(), tabRect.bottom() - Metrics::TabBar_BaseOverlap + Metrics::TabBar_TabOffset, tabRect.width(), 1 );
if( isFrameAligned && isFirst ) highlightSlab = SlabRect( highlightRect.adjusted( -2, 0, 0, 0 ), TileSet::TopLeft );
else if( isFrameAligned && isLast ) highlightSlab = SlabRect( highlightRect.adjusted( 0, 0, 2, 0 ), TileSet::TopRight );
else highlightSlab = SlabRect( highlightRect, TileSet::Top );
break;
}
case QTabBar::RoundedSouth:
case QTabBar::TriangularSouth:
{
tabRect.adjust( 0, 4, 1, -3 );
// adjust sides when slab is adjacent to selected slab
if( isLeftOfSelected ) tabRect.adjust( 0, 0, 2, 0 );
else if( isRightOfSelected ) tabRect.adjust( -2, 0, 0, 0 );
if( isFirst )
{
tabRect.adjust( 1, 0, 0, 0 );
if( isFrameAligned ) path.moveTo( tabRect.topLeft() - QPoint( 0, 2 ) );
else path.moveTo( tabRect.topLeft() );
path.lineTo( tabRect.bottomLeft() - QPointF( 0, radius ) );
path.quadTo( tabRect.bottomLeft(), tabRect.bottomLeft() + QPoint( radius, 0 ) );
path.lineTo( tabRect.bottomRight() );
path.lineTo( tabRect.topRight() );
} else if( isLast ) {
tabRect.adjust( 0, 0, -2, 0 );
path.moveTo( tabRect.topLeft() );
path.lineTo( tabRect.bottomLeft() );
path.lineTo( tabRect.bottomRight() - QPointF( radius, 0 ) );
path.quadTo( tabRect.bottomRight(), tabRect.bottomRight() - QPointF( 0, radius ) );
if( isFrameAligned ) path.lineTo( tabRect.topRight() - QPointF( 0, 2 ) );
else path.lineTo( tabRect.topRight() );
} else {
path.moveTo( tabRect.topLeft() );
path.lineTo( tabRect.bottomLeft() );
path.lineTo( tabRect.bottomRight() );
path.lineTo( tabRect.topRight() );
}
// highlight
QRect highlightRect( tabRect.left(), tabRect.top() - Metrics::TabBar_BaseOverlap + Metrics::TabBar_TabOffset, tabRect.width(), TileSet::DefaultSize );
if( isFrameAligned && isFirst ) highlightSlab = SlabRect( highlightRect.adjusted( -2, 0, 0, 0 ), TileSet::BottomLeft );
else if( isFrameAligned && isLast ) highlightSlab = SlabRect( highlightRect.adjusted( 0, 0, 2, 0 ), TileSet::BottomRight );
else highlightSlab = SlabRect( highlightRect, TileSet::Bottom );
break;
}
case QTabBar::RoundedWest:
case QTabBar::TriangularWest:
{
tabRect.adjust( 3, 0, -4, 1 );
// adjust sides when slab is adjacent to selected slab
if( isLeftOfSelected ) tabRect.adjust( 0, 0, 0, 2 );
else if( isRightOfSelected ) tabRect.adjust( 0, -2, 0, 0 );
if( isFirst )
{
tabRect.adjust( 0, 1, 0, 0 );
if( isFrameAligned ) path.moveTo( tabRect.topRight() + QPoint( 2, 0 ) );
else path.moveTo( tabRect.topRight() );
path.lineTo( tabRect.topLeft() + QPointF( radius, 0 ) );
path.quadTo( tabRect.topLeft(), tabRect.topLeft() + QPoint( 0, radius ) );
path.lineTo( tabRect.bottomLeft() );
path.lineTo( tabRect.bottomRight() );
} else if( isLast ) {
tabRect.adjust( 0, 0, 0, -1 );
path.moveTo( tabRect.topRight() );
path.lineTo( tabRect.topLeft() );
path.lineTo( tabRect.bottomLeft() - QPointF( 0, radius ) );
path.quadTo( tabRect.bottomLeft(), tabRect.bottomLeft() + QPointF( radius, 0 ) );
path.lineTo( tabRect.bottomRight() );
} else {
path.moveTo( tabRect.topRight() );
path.lineTo( tabRect.topLeft() );
path.lineTo( tabRect.bottomLeft() );
path.lineTo( tabRect.bottomRight() );
}
// highlight
QRect highlightRect( tabRect.right() - Metrics::TabBar_BaseOverlap + Metrics::TabBar_TabOffset, tabRect.top(), 1, tabRect.height() );
if( isFrameAligned && isFirst ) highlightSlab = SlabRect( highlightRect.adjusted( 0, -2, 0, 0 ), TileSet::TopLeft );
else if( isFrameAligned && isLast ) highlightSlab = SlabRect( highlightRect.adjusted( 0, 0, 0, 2 ), TileSet::BottomLeft );
else highlightSlab = SlabRect( highlightRect, TileSet::Left );
break;
}
case QTabBar::RoundedEast:
case QTabBar::TriangularEast:
{
tabRect.adjust( 4, 0, -3, 1 );
// adjust sides when slab is adjacent to selected slab
if( isLeftOfSelected ) tabRect.adjust( 0, 0, 0, 2 );
else if( isRightOfSelected ) tabRect.adjust( 0, -2, 0, 0 );
if( isFirst )
{
tabRect.adjust( 0, 1, 0, 0 );
if( isFrameAligned ) path.moveTo( tabRect.topLeft() - QPoint( 2, 0 ) );
else path.moveTo( tabRect.topLeft() );
path.lineTo( tabRect.topRight() - QPointF( radius, 0 ) );
path.quadTo( tabRect.topRight(), tabRect.topRight() + QPoint( 0, radius ) );
path.lineTo( tabRect.bottomRight() );
path.lineTo( tabRect.bottomLeft() );
} else if( isLast ) {
tabRect.adjust( 0, 0, 0, -1 );
path.moveTo( tabRect.topLeft() );
path.lineTo( tabRect.topRight() );
path.lineTo( tabRect.bottomRight() - QPointF( 0, radius ) );
path.quadTo( tabRect.bottomRight(), tabRect.bottomRight() - QPointF( radius, 0 ) );
path.lineTo( tabRect.bottomLeft() );
} else {
path.moveTo( tabRect.topLeft() );
path.lineTo( tabRect.topRight() );
path.lineTo( tabRect.bottomRight() );
path.lineTo( tabRect.bottomLeft() );
}
// highlight
QRect highlightRect( tabRect.left() - Metrics::TabBar_BaseOverlap + Metrics::TabBar_TabOffset, tabRect.top(), TileSet::DefaultSize, tabRect.height() );
if( isFrameAligned && isFirst ) highlightSlab = SlabRect( highlightRect.adjusted( 0, -2, 0, 0 ), TileSet::TopRight );
else if( isFrameAligned && isLast ) highlightSlab = SlabRect( highlightRect.adjusted( 0, 0, 0, 2 ), TileSet::BottomRight );
else highlightSlab = SlabRect( highlightRect, TileSet::Right );
break;
}
default: break;
}
const QColor color( palette.color( QPalette::Window ) );
// adjust clip rect and render tab
if( tabBar )
{
painter->save();
painter->setClipRegion( tabBarClipRegion( tabBar ) );
}
// fill tab
const QColor backgroundColor = _helper->backgroundColor( color, widget, rect.center() );
const QColor midColor = _helper->alphaColor( _helper->calcDarkColor( backgroundColor ), 0.4 );
const QColor darkColor = _helper->alphaColor( _helper->calcDarkColor( backgroundColor ), 0.6 );
painter->save();
painter->translate( 0.5, 0.5 );
painter->setRenderHints( QPainter::Antialiasing );
painter->setPen( darkColor );
painter->setBrush( midColor );
painter->drawPath( path );
painter->restore();
// restore clip region
if( tabBar ) painter->restore();
// handle base frame painting, for tabbars in which tab is being dragged
_tabBarData->drawTabBarBaseControl( tabOption, painter, widget );
// hovered highlight
if( ( animated || mouseOver ) && highlightSlab.isValid() )
{
highlightSlab.adjust( TileSet::DefaultSize );
const QRect tabWidgetRect( tabWidget ? tabWidget->rect().translated( -widget->geometry().topLeft() ) : QRect() );
adjustSlabRect( highlightSlab, tabWidgetRect, documentMode, verticalTabs );
const qreal opacity( _animations->tabBarEngine().opacity( widget, rect.topLeft(), AnimationHover ) );
const StyleOptions hoverTabOpts( NoFill | Hover );
// pass an invalid color to have only the glow painted
if( animated ) renderSlab( painter, highlightSlab, QColor(), hoverTabOpts, opacity, AnimationHover );
else renderSlab( painter, highlightSlab, QColor(), hoverTabOpts );
}
return true;
}
//___________________________________________________________________________________
bool Style::drawToolBoxTabLabelControl( const QStyleOption* option, QPainter* painter, const QWidget* widget ) const
{
// cast option and check
const QStyleOptionToolBox* toolBoxOption( qstyleoption_cast<const QStyleOptionToolBox *>( option ) );
if( !toolBoxOption ) return true;
// copy palette
const QPalette& palette( option->palette );
const State& state( option->state );
const bool enabled( state & State_Enabled );
// text alignment
const int textFlags( _mnemonics->textFlags() | Qt::AlignCenter );
// contents rect
const QRect rect( subElementRect( SE_ToolBoxTabContents, option, widget ) );
// store icon size
const int iconSize( pixelMetric( QStyle::PM_SmallIconSize, option, widget ) );
// find contents size and rect
QRect contentsRect( rect );
QSize contentsSize;
if( !toolBoxOption->text.isEmpty() )
{
contentsSize = option->fontMetrics.size( _mnemonics->textFlags(), toolBoxOption->text );
if( !toolBoxOption->icon.isNull() ) contentsSize.rwidth() += Metrics::ToolBox_TabItemSpacing;
}
// icon size
if( !toolBoxOption->icon.isNull() )
{
contentsSize.setHeight( qMax( contentsSize.height(), iconSize ) );
contentsSize.rwidth() += iconSize;
}
// adjust contents rect
contentsRect = centerRect( contentsRect, contentsSize );
// render icon
if( !toolBoxOption->icon.isNull() )
{
// icon rect
QRect iconRect;
if( toolBoxOption->text.isEmpty() ) iconRect = centerRect( contentsRect, iconSize, iconSize );
else {
iconRect = contentsRect;
iconRect.setWidth( iconSize );
iconRect = centerRect( iconRect, iconSize, iconSize );
contentsRect.setLeft( iconRect.right() + Metrics::ToolBox_TabItemSpacing + 1 );
}
iconRect = visualRect( option, iconRect );
const QIcon::Mode mode( enabled ? QIcon::Normal : QIcon::Disabled );
const QPixmap pixmap( toolBoxOption->icon.pixmap( iconSize, mode ) );
drawItemPixmap( painter, iconRect, textFlags, pixmap );
}
// render text
if( !toolBoxOption->text.isEmpty() )
{
contentsRect = visualRect( option, contentsRect );
drawItemText( painter, contentsRect, textFlags, palette, enabled, toolBoxOption->text, QPalette::WindowText );
}
return true;
}
//___________________________________________________________________________________
bool Style::drawToolBoxTabShapeControl( const QStyleOption* option, QPainter* painter, const QWidget* widget ) const
{
// copy rect and palette
const QRect& rect( option->rect );
const QPalette& palette( option->palette );
// copy state
const State& state( option->state );
const bool enabled( state & State_Enabled );
const bool selected( state & State_Selected );
const bool mouseOver( enabled && !selected && ( state & State_MouseOver ) );
const bool reverseLayout( option->direction == Qt::RightToLeft );
// cast option and check
const auto v2 = qstyleoption_cast<const QStyleOptionToolBox*>( option );
if( v2 && v2->position == QStyleOptionToolBox::Beginning && selected ) return true;
/*
the proper widget ( the toolbox tab ) is not passed as argument by Qt.
What is passed is the toolbox directly. To implement animations properly,
the painter->device() is used instead
*/
bool animated( false );
qreal opacity( AnimationData::OpacityInvalid );
if( enabled )
{
// try retrieve button from painter device.
if( QPaintDevice* device = painter->device() )
{
_animations->toolBoxEngine().updateState( device, mouseOver );
animated = _animations->toolBoxEngine().isAnimated( device );
opacity = _animations->toolBoxEngine().opacity( device );
}
}
// save colors for shadow
/* important: option returns a wrong color. We use the widget's palette when widget is set */
const QColor color( widget ? widget->palette().color( widget->backgroundRole() ) : palette.color( QPalette::Window ) );
const QColor dark( _helper->calcDarkColor( color ) );
QList<QColor> colors;
colors.append( _helper->calcLightColor( color ) );
if( mouseOver || animated )
{
QColor highlight = _helper->hoverColor( palette );
if( animated )
{
colors.append( KColorUtils::mix( dark, highlight, opacity ) );
colors.append( _helper->alphaColor( highlight, 0.2*opacity ) );
} else {
colors.append( highlight );
colors.append( _helper->alphaColor( highlight, 0.2 ) );
}
} else colors.append( dark );
// create path
const qreal radius( 8 );
const qreal offset( radius * std::tan( M_PI/8 ) );
const QRectF rectf( rect );
QPainterPath path;
if( reverseLayout )
{
path.moveTo( rectf.right()-1, rectf.top() );
path.lineTo( rectf.left() + 50 + radius + offset, rectf.top() );
path.arcTo( QRectF( rectf.left() + 50 + radius + offset - 2*radius, rectf.top(), radius*2, radius*2 ), 90, 45 );
path.lineTo( rectf.left() + 50 - rectf.height() + 3 + offset/std::sqrt(2), rectf.bottom() - 3 - offset/std::sqrt(2) );
path.arcTo( QRectF( rectf.left() + 50 - rectf.height() + 3 + radius - offset - 2*radius, rectf.bottom() - 3 - 2*radius, 2*radius, 2*radius ), 315, -45 );
path.lineTo( rectf.left(), rectf.bottom() - 3 );
} else {
path.moveTo( rectf.left(), rectf.top() );
path.lineTo( rectf.right()- 50 - radius - offset, rectf.top() );
path.arcTo( QRectF( rectf.right() - 50 - radius - offset, rectf.top(), radius*2, radius*2 ), 90, -45 );
path.lineTo( rectf.right() - 50 + rectf.height() - 3 - offset/std::sqrt(2), rectf.bottom() - 3 - offset/std::sqrt(2) );
path.arcTo( QRectF( rectf.right() - 50 + rectf.height() - 3 - radius + offset, rectf.bottom() - 3 - 2*radius, 2*radius, 2*radius ), 225, 45 );
path.lineTo( rectf.right() - 1, rectf.bottom() - 3 );
}
// paint
painter->setRenderHint( QPainter::Antialiasing, true );
painter->translate(0.5, 0.5 );
painter->translate( 0, 2 );
foreach( const QColor& color, colors )
{
painter->setPen( color );
painter->drawPath( path );
painter->translate( 0,-1 );
}
return true;
}
//___________________________________________________________________________________
bool Style::drawDockWidgetTitleControl( const QStyleOption* option, QPainter* painter, const QWidget* widget ) const
{
// cast option and check
const QStyleOptionDockWidget* dockWidgetOption = qstyleoption_cast<const QStyleOptionDockWidget*>( option );
if( !dockWidgetOption ) return true;
// copy palette
const QPalette& palette( option->palette );
// store state
const State& state( option->state );
const bool enabled( state & State_Enabled );
const bool reverseLayout( option->direction == Qt::RightToLeft );
// cast to v2 to check vertical bar
const auto v2 = qstyleoption_cast<const QStyleOptionDockWidget*>( option );
const bool verticalTitleBar( v2 ? v2->verticalTitleBar : false );
const QRect buttonRect( subElementRect( dockWidgetOption->floatable ? SE_DockWidgetFloatButton : SE_DockWidgetCloseButton, option, widget ) );
// get rectangle and adjust to properly accounts for buttons
QRect rect( insideMargin( dockWidgetOption->rect, Metrics::Frame_FrameWidth ) );
if( verticalTitleBar )
{
if( buttonRect.isValid() ) rect.setTop( buttonRect.bottom()+1 );
} else if( reverseLayout ) {
if( buttonRect.isValid() ) rect.setLeft( buttonRect.right()+1 );
rect.adjust( 0, 0, -4, 0 );
} else {
if( buttonRect.isValid() ) rect.setRight( buttonRect.left()-1 );
rect.adjust( 4, 0, 0, 0 );
}
QString title( dockWidgetOption->title );
int titleWidth = dockWidgetOption->fontMetrics.size( _mnemonics->textFlags(), title ).width();
int width = verticalTitleBar ? rect.height() : rect.width();
if( width < titleWidth ) title = dockWidgetOption->fontMetrics.elidedText( title, Qt::ElideRight, width, Qt::TextShowMnemonic );
if( verticalTitleBar )
{
QSize s = rect.size();
s.transpose();
rect.setSize( s );
painter->save();
painter->translate( rect.left(), rect.top() + rect.width() );
painter->rotate( -90 );
painter->translate( - rect.left(), - rect.top() );
drawItemText( painter, rect, Qt::AlignLeft | Qt::AlignVCenter | _mnemonics->textFlags(), palette, enabled, title, QPalette::WindowText );
painter->restore();
} else {
drawItemText( painter, rect, Qt::AlignLeft | Qt::AlignVCenter | _mnemonics->textFlags(), palette, enabled, title, QPalette::WindowText );
}
return true;
}
//___________________________________________________________________________________
bool Style::drawToolBarControl( const QStyleOption* option, QPainter* painter, const QWidget* widget ) const
{
// copy rect and palette
const QRect& rect( option->rect );
const QPalette& palette( option->palette );
// when timeLine is running draw border event if not hovered
const bool toolBarAnimated( _animations->toolBarEngine().isFollowMouseAnimated( widget ) );
const QRect animatedRect( _animations->toolBarEngine().animatedRect( widget ) );
const bool toolBarIntersected( toolBarAnimated && animatedRect.intersects( rect ) );
if( toolBarIntersected )
{ _helper->slitFocused( _helper->focusColor( palette ) ).render( animatedRect, painter ); }
// draw nothing otherwise ( toolbars are transparent )
return true;
}
//______________________________________________________________
bool Style::drawToolButtonComplexControl( const QStyleOptionComplex* option, QPainter* painter, const QWidget* widget ) const
{
// check autoRaise state
const State& state( option->state );
const bool isInToolBar( widget && qobject_cast<QToolBar*>( widget->parent() ) );
// get rect and palette
const QRect& rect( option->rect );
const QStyleOptionToolButton *toolButtonOption( qstyleoption_cast<const QStyleOptionToolButton *>( option ) );
if( !toolButtonOption ) return true;
const bool enabled( state & State_Enabled );
const bool mouseOver( enabled && ( state & State_MouseOver ) );
const bool hasFocus( enabled && ( state & State_HasFocus ) );
const bool sunken( state & ( State_Sunken|State_On ) );
const bool autoRaise( state & State_AutoRaise );
if( isInToolBar )
{
_animations->widgetStateEngine().updateState( widget, AnimationHover, mouseOver );
} else {
// mouseOver has precedence over focus
_animations->widgetStateEngine().updateState( widget, AnimationHover, mouseOver );
_animations->widgetStateEngine().updateState( widget, AnimationFocus, hasFocus&&!mouseOver );
}
// toolbar animation
QWidget* parent( widget ? widget->parentWidget():0 );
const bool toolBarAnimated( isInToolBar && _animations->toolBarEngine().isAnimated( parent ) );
const QRect animatedRect( _animations->toolBarEngine().animatedRect( parent ) );
const QRect currentRect( _animations->toolBarEngine().currentRect( parent ) );
const bool current( isInToolBar && currentRect.intersects( rect.translated( widget->mapToParent( QPoint( 0,0 ) ) ) ) );
const bool toolBarTimerActive( isInToolBar && _animations->toolBarEngine().isTimerActive( widget->parentWidget() ) );
// normal toolbutton animation
const AnimationMode mode( _animations->widgetStateEngine().buttonAnimationMode( widget ) );
// detect buttons in tabbar, for which special rendering is needed
const bool inTabBar( widget && qobject_cast<const QTabBar*>( widget->parentWidget() ) );
// local copy of option
QStyleOptionToolButton copy( *toolButtonOption );
const bool hasPopupMenu( toolButtonOption->features & QStyleOptionToolButton::MenuButtonPopup );
const bool hasInlineIndicator(
toolButtonOption->features&QStyleOptionToolButton::HasMenu
&& toolButtonOption->features&QStyleOptionToolButton::PopupDelay
&& !hasPopupMenu );
const QRect buttonRect( subControlRect( CC_ToolButton, option, SC_ToolButton, widget ) );
const QRect menuRect( subControlRect( CC_ToolButton, option, SC_ToolButtonMenu, widget ) );
// frame
const bool drawFrame(
(enabled && !( mouseOver || hasFocus || sunken ) &&
((mode != AnimationNone) || ( ( ( toolBarAnimated && animatedRect.isNull() )||toolBarTimerActive ) && current )) ) ||
(toolButtonOption->subControls & SC_ToolButton) );
if( drawFrame )
{
copy.rect = buttonRect;
if( inTabBar ) drawTabBarPanelButtonToolPrimitive( ©, painter, widget );
else drawPrimitive( PE_PanelButtonTool, ©, painter, widget);
}
if( hasPopupMenu )
{
copy.rect = menuRect;
if( !autoRaise )
{
drawPrimitive( PE_IndicatorButtonDropDown, ©, painter, widget );
copy.state &= ~(State_MouseOver|State_HasFocus);
}
drawPrimitive( PE_IndicatorArrowDown, ©, painter, widget );
} else if( hasInlineIndicator ) {
copy.rect = menuRect;
copy.state &= ~(State_MouseOver|State_HasFocus);
drawPrimitive( PE_IndicatorArrowDown, ©, painter, widget );
}
// contents
{
// restore state
copy.state = state;
// define contents rect
QRect contentsRect( buttonRect );
// detect dock widget title button
/* for dockwidget title buttons, do not take out margins, so that icon do not get scaled down */
const bool isDockWidgetTitleButton( widget && widget->inherits( "QDockWidgetTitleButton" ) );
if( isDockWidgetTitleButton )
{
// cast to abstract button
// adjust state to have correct icon rendered
const QAbstractButton* button( qobject_cast<const QAbstractButton*>( widget ) );
if( button->isChecked() || button->isDown() ) copy.state |= State_On;
} else if( !inTabBar && hasInlineIndicator ) {
const int marginWidth( autoRaise ? Metrics::ToolButton_MarginWidth : Metrics::Button_MarginWidth + Metrics::Frame_FrameWidth );
contentsRect = insideMargin( contentsRect, marginWidth, 0 );
contentsRect.setRight( contentsRect.right() - Metrics::ToolButton_InlineIndicatorWidth );
contentsRect = visualRect( option, contentsRect );
}
copy.rect = contentsRect;
// render
drawControl( CE_ToolButtonLabel, ©, painter, widget);
}
return true;
}
//______________________________________________________________
bool Style::drawComboBoxComplexControl( const QStyleOptionComplex* option, QPainter* painter, const QWidget* widget ) const
{
// cast option and check
const QStyleOptionComboBox* comboBoxOption( qstyleoption_cast<const QStyleOptionComboBox*>( option ) );
if( !comboBoxOption ) return true;
// rect and palette
const QRect& rect( option->rect );
const QPalette& palette( option->palette );
// state
const State& state( option->state );
const bool enabled( state & State_Enabled );
const bool mouseOver( enabled && ( state & State_MouseOver ) );
const bool hasFocus( enabled && ( state & State_HasFocus ) );
const bool editable( comboBoxOption->editable );
const bool sunken( state & (State_On|State_Sunken) );
bool flat( !comboBoxOption->frame );
// style options
StyleOptions styleOptions;
if( mouseOver ) styleOptions |= Hover;
if( hasFocus ) styleOptions |= Focus;
if( sunken && !editable ) styleOptions |= Sunken;
// frame
if( comboBoxOption->subControls & SC_ComboBoxFrame )
{
if( editable )
{
// editable combobox. Make it look like a LineEdit
// focus takes precedence over hover
_animations->inputWidgetEngine().updateState( widget, AnimationFocus, hasFocus );
_animations->inputWidgetEngine().updateState( widget, AnimationHover, mouseOver && !hasFocus );
// input area
painter->setRenderHint( QPainter::Antialiasing );
flat |= ( rect.height() <= 2*Metrics::Frame_FrameWidth + Metrics::MenuButton_IndicatorWidth );
if( flat )
{
const QColor background( palette.color( QPalette::Base ) );
painter->setPen( Qt::NoPen );
painter->setBrush( background );
painter->drawRect( rect );
} else {
drawPrimitive( PE_FrameLineEdit, option, painter, widget );
}
} else {
// non editable combobox. Make it look like a PushButton
// hover takes precedence over focus
_animations->inputWidgetEngine().updateState( widget, AnimationHover, mouseOver );
_animations->inputWidgetEngine().updateState( widget, AnimationFocus, hasFocus && !mouseOver );
const AnimationMode mode( _animations->inputWidgetEngine().buttonAnimationMode( widget ) );
const qreal opacity( _animations->inputWidgetEngine().buttonOpacity( widget ) );
// blend button color to the background
const QColor buttonColor( _helper->backgroundColor( palette.color( QPalette::Button ), widget, rect.center() ) );
const QRect slabRect( rect );
if( flat )
{
if( !sunken )
{
// hover rect
const QColor glow( _helper->buttonGlowColor( palette, styleOptions, opacity, mode ) );
if( glow.isValid() ) _helper->slitFocused( glow ).render( rect, painter );
} else {
styleOptions |= HoleContrast;
_helper->renderHole( painter, palette.color( QPalette::Window ), rect, styleOptions, opacity, mode );
}
} else {
renderButtonSlab( painter, slabRect, buttonColor, styleOptions, opacity, mode, TileSet::Ring );
}
}
}
if( comboBoxOption->subControls & SC_ComboBoxArrow )
{
const QComboBox* comboBox = qobject_cast<const QComboBox*>( widget );
const bool empty( comboBox && !comboBox->count() );
QColor color;
QColor background;
bool drawContrast( true );
if( comboBoxOption->editable )
{
if( enabled && empty ) color = palette.color( QPalette::Disabled, QPalette::Text );
else {
// check animation state
const bool subControlHover( enabled && mouseOver && comboBoxOption->activeSubControls&SC_ComboBoxArrow );
_animations->comboBoxEngine().updateState( widget, AnimationHover, subControlHover );
const bool animated( enabled && _animations->comboBoxEngine().isAnimated( widget, AnimationHover ) );
const qreal opacity( _animations->comboBoxEngine().opacity( widget, AnimationHover ) );
if( animated )
{
QColor highlight = _helper->hoverColor( palette );
color = KColorUtils::mix( palette.color( QPalette::Text ), highlight, opacity );
} else if( subControlHover ) {
color = _helper->hoverColor( palette );
} else {
color = palette.color( QPalette::Text );
}
}
background = palette.color( QPalette::Window );
if( enabled ) drawContrast = false;
} else {
// foreground color
const QPalette::ColorRole role( flat ? QPalette::WindowText : QPalette::ButtonText );
if( enabled && empty ) color = palette.color( QPalette::Disabled, role );
else color = palette.color( role );
// background color
background = palette.color( flat ? QPalette::Window : QPalette::Button );
}
// draw the arrow
QRect arrowRect = subControlRect( CC_ComboBox, option, SC_ComboBoxArrow, widget );
const QPolygonF arrow( genericArrow( ArrowDown, ArrowNormal ) );
const qreal penThickness = 1.6;
painter->save();
painter->translate( QRectF( arrowRect ).center() );
painter->setRenderHint( QPainter::Antialiasing );
if( drawContrast )
{
const qreal offset( qMin( penThickness, qreal( 1 ) ) );
painter->translate( 0,offset );
painter->setPen( QPen( _helper->calcLightColor( palette.color( QPalette::Window ) ), penThickness, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin ) );
painter->drawPolyline( arrow );
painter->translate( 0,-offset );
}
painter->setPen( QPen( _helper->decoColor( background, color ) , penThickness, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin ) );
painter->drawPolyline( arrow );
painter->restore();
}
return true;
}
//______________________________________________________________
bool Style::drawSpinBoxComplexControl( const QStyleOptionComplex* option, QPainter* painter, const QWidget* widget ) const
{
// cast option and check
const QStyleOptionSpinBox *spinBoxOption = qstyleoption_cast<const QStyleOptionSpinBox *>( option );
if( !spinBoxOption ) return true;
// copy rect and palette
const QRect& rect( option->rect );
const QPalette& palette( option->palette );
if( spinBoxOption->subControls & SC_SpinBoxFrame )
{
// detect flat spinboxes
bool flat( !spinBoxOption->frame );
flat |= ( rect.height() <= 2*Metrics::Frame_FrameWidth + Metrics::MenuButton_IndicatorWidth );
if( flat )
{
const QColor background( palette.color( QPalette::Base ) );
painter->setRenderHint( QPainter::Antialiasing );
painter->setPen( Qt::NoPen );
painter->setBrush( background );
painter->drawRect( rect );
} else {
drawPrimitive( PE_FrameLineEdit, option, painter, widget );
}
}
if( spinBoxOption->subControls & SC_SpinBoxUp ) renderSpinBoxArrow( painter, spinBoxOption, widget, SC_SpinBoxUp );
if( spinBoxOption->subControls & SC_SpinBoxDown ) renderSpinBoxArrow( painter, spinBoxOption, widget, SC_SpinBoxDown );
return true;
}
//______________________________________________________________
bool Style::drawSliderComplexControl( const QStyleOptionComplex* option, QPainter* painter, const QWidget* widget ) const
{
// cast option and check
const QStyleOptionSlider *sliderOption( qstyleoption_cast<const QStyleOptionSlider *>( option ) );
if( !sliderOption ) return true;
// copy rect and palette
const QRect& rect( option->rect );
const QPalette& palette( option->palette );
// copy state
const State& state( option->state );
const bool enabled( state & State_Enabled );
const bool mouseOver( enabled && ( state & State_MouseOver ) );
const bool hasFocus( state & State_HasFocus );
// direction
const bool horizontal( sliderOption->orientation == Qt::Horizontal );
if( sliderOption->subControls & SC_SliderTickmarks )
{
const bool upsideDown( sliderOption->upsideDown );
const int tickPosition( sliderOption->tickPosition );
const int available( pixelMetric( PM_SliderSpaceAvailable, option, widget ) );
int interval = sliderOption->tickInterval;
if( interval < 1 ) interval = sliderOption->pageStep;
if( interval >= 1 )
{
const int fudge( pixelMetric( PM_SliderLength, option, widget ) / 2 );
int current( sliderOption->minimum );
// store tick lines
const QRect grooveRect( subControlRect( CC_Slider, sliderOption, SC_SliderGroove, widget ) );
QList<QLine> tickLines;
if( horizontal )
{
if( tickPosition & QSlider::TicksAbove ) tickLines.append( QLine( rect.left(), grooveRect.top() - Metrics::Slider_TickMarginWidth, rect.left(), grooveRect.top() - Metrics::Slider_TickMarginWidth - Metrics::Slider_TickLength ) );
if( tickPosition & QSlider::TicksBelow ) tickLines.append( QLine( rect.left(), grooveRect.bottom() + Metrics::Slider_TickMarginWidth, rect.left(), grooveRect.bottom() + Metrics::Slider_TickMarginWidth + Metrics::Slider_TickLength ) );
} else {
if( tickPosition & QSlider::TicksAbove ) tickLines.append( QLine( grooveRect.left() - Metrics::Slider_TickMarginWidth, rect.top(), grooveRect.left() - Metrics::Slider_TickMarginWidth - Metrics::Slider_TickLength, rect.top() ) );
if( tickPosition & QSlider::TicksBelow ) tickLines.append( QLine( grooveRect.right() + Metrics::Slider_TickMarginWidth, rect.top(), grooveRect.right() + Metrics::Slider_TickMarginWidth + Metrics::Slider_TickLength, rect.top() ) );
}
// colors
QColor base( _helper->backgroundColor( palette.color( QPalette::Window ), widget, rect.center() ) );
base = _helper->calcDarkColor( base );
painter->setPen( base );
while( current <= sliderOption->maximum )
{
// calculate positions and draw lines
int position( sliderPositionFromValue( sliderOption->minimum, sliderOption->maximum, current, available ) + fudge );
foreach( const QLine& tickLine, tickLines )
{
if( horizontal ) painter->drawLine( tickLine.translated( upsideDown ? (rect.width() - position) : position, 0 ) );
else painter->drawLine( tickLine.translated( 0, upsideDown ? (rect.height() - position):position ) );
}
// go to next position
current += interval;
}
}
}
// groove
if( sliderOption->subControls & SC_SliderGroove )
{
// get rect
QRect grooveRect( subControlRect( CC_Slider, sliderOption, SC_SliderGroove, widget ) );
// render
_helper->scrollHole( palette.color( QPalette::Window ), sliderOption->orientation, true ).render( grooveRect, painter, TileSet::Full );
}
// handle
if( sliderOption->subControls & SC_SliderHandle )
{
// get rect and center
QRect handleRect( subControlRect( CC_Slider, sliderOption, SC_SliderHandle, widget ) );
// handle state
const bool handleActive( sliderOption->activeSubControls & SC_SliderHandle );
const bool sunken( state & (State_On|State_Sunken) );
StyleOptions styleOptions;
if( hasFocus ) styleOptions |= Focus;
if( handleActive && mouseOver ) styleOptions |= Hover;
// animation state
_animations->widgetStateEngine().updateState( widget, AnimationHover, handleActive && mouseOver );
_animations->widgetStateEngine().updateState( widget, AnimationFocus, hasFocus );
const AnimationMode mode( _animations->widgetStateEngine().buttonAnimationMode( widget ) );
const qreal opacity( _animations->widgetStateEngine().buttonOpacity( widget ) );
// define colors
const QColor color( _helper->backgroundColor( palette.color( QPalette::Button ), widget, handleRect.center() ) );
const QColor glow( _helper->buttonGlowColor( palette, styleOptions, opacity, mode ) );
// render
painter->drawPixmap( handleRect.topLeft(), _helper->sliderSlab( color, glow, sunken, 0 ) );
}
return true;
}
//______________________________________________________________
bool Style::drawDialComplexControl( const QStyleOptionComplex* option, QPainter* painter, const QWidget* widget ) const
{
const State& state( option->state );
const bool enabled = state & State_Enabled;
const bool mouseOver( enabled && ( state & State_MouseOver ) );
const bool hasFocus( enabled && ( state & State_HasFocus ) );
const bool sunken( state & ( State_On|State_Sunken ) );
StyleOptions styleOptions;
if( sunken ) styleOptions |= Sunken;
if( hasFocus ) styleOptions |= Focus;
if( mouseOver ) styleOptions |= Hover;
// mouseOver has precedence over focus
_animations->widgetStateEngine().updateState( widget, AnimationHover, mouseOver );
_animations->widgetStateEngine().updateState( widget, AnimationFocus, hasFocus && !mouseOver );
const AnimationMode mode( _animations->widgetStateEngine().buttonAnimationMode( widget ) );
const qreal opacity( _animations->widgetStateEngine().buttonOpacity( widget ) );
const QRect rect( option->rect );
const QPalette &palette( option->palette );
const QColor buttonColor( _helper->backgroundColor( palette.color( QPalette::Button ), widget, rect.center() ) );
renderDialSlab( painter, rect, buttonColor, option, styleOptions, opacity, mode );
return true;
}
//______________________________________________________________
bool Style::drawScrollBarComplexControl( const QStyleOptionComplex* option, QPainter* painter, const QWidget* widget ) const
{
// render full groove directly, rather than using the addPage and subPage control element methods
if( option->subControls & SC_ScrollBarGroove )
{
// retrieve groove rectangle
QRect grooveRect( subControlRect( CC_ScrollBar, option, SC_ScrollBarGroove, widget ) );
const QPalette& palette( option->palette );
const QColor color( palette.color( QPalette::Window ) );
const State& state( option->state );
const bool horizontal( state & State_Horizontal );
if( horizontal ) grooveRect = centerRect( grooveRect, grooveRect.width(), StyleConfigData::scrollBarWidth() );
else grooveRect = centerRect( grooveRect, StyleConfigData::scrollBarWidth(), grooveRect.height() );
// render
renderScrollBarHole( painter, grooveRect, color, Qt::Horizontal );
}
// call base class primitive
KStyle::drawComplexControl( CC_ScrollBar, option, painter, widget );
return true;
}
//______________________________________________________________
bool Style::drawTitleBarComplexControl( const QStyleOptionComplex* option, QPainter* painter, const QWidget* widget ) const
{
const QStyleOptionTitleBar *titleBarOption( qstyleoption_cast<const QStyleOptionTitleBar *>( option ) );
if( !titleBarOption ) return true;
const State& state( option->state );
const bool enabled( state & State_Enabled );
const bool active( enabled && ( titleBarOption->titleBarState & Qt::WindowActive ) );
// draw title text
{
QRect textRect = subControlRect( CC_TitleBar, titleBarOption, SC_TitleBarLabel, widget );
// enable state transition
_animations->widgetEnableStateEngine().updateState( widget, AnimationEnable, active );
// make sure palette has the correct color group
QPalette palette( option->palette );
if( _animations->widgetEnableStateEngine().isAnimated( widget, AnimationEnable ) )
{ palette = _helper->disabledPalette( palette, _animations->widgetEnableStateEngine().opacity( widget, AnimationEnable ) ); }
palette.setCurrentColorGroup( active ? QPalette::Active: QPalette::Disabled );
KStyle::drawItemText( painter, textRect, Qt::AlignCenter, palette, active, titleBarOption->text, QPalette::WindowText );
}
// menu button
if( ( titleBarOption->subControls & SC_TitleBarSysMenu ) && ( titleBarOption->titleBarFlags & Qt::WindowSystemMenuHint ) && !titleBarOption->icon.isNull() )
{
QRect iconRect = subControlRect( CC_TitleBar, titleBarOption, SC_TitleBarSysMenu, widget );
const int iconWidth( pixelMetric( PM_SmallIconSize, option, widget ) );
const QSize iconSize( iconWidth, iconWidth );
iconRect = centerRect( iconRect, iconSize );
const QPixmap pixmap = titleBarOption->icon.pixmap( iconSize, QIcon::Normal, QIcon::On );
painter->drawPixmap( iconRect, pixmap );
}
if( ( titleBarOption->subControls & SC_TitleBarMinButton ) && ( titleBarOption->titleBarFlags & Qt::WindowMinimizeButtonHint ) )
{ renderTitleBarButton( painter, titleBarOption, widget, SC_TitleBarMinButton ); }
if( ( titleBarOption->subControls & SC_TitleBarMaxButton ) && ( titleBarOption->titleBarFlags & Qt::WindowMaximizeButtonHint ) )
{ renderTitleBarButton( painter, titleBarOption, widget, SC_TitleBarMaxButton ); }
if( ( titleBarOption->subControls & SC_TitleBarCloseButton ) )
{ renderTitleBarButton( painter, titleBarOption, widget, SC_TitleBarCloseButton ); }
if( ( titleBarOption->subControls & SC_TitleBarNormalButton ) &&
( ( ( titleBarOption->titleBarFlags & Qt::WindowMinimizeButtonHint ) &&
( titleBarOption->titleBarState & Qt::WindowMinimized ) ) ||
( ( titleBarOption->titleBarFlags & Qt::WindowMaximizeButtonHint ) &&
( titleBarOption->titleBarState & Qt::WindowMaximized ) ) ) )
{ renderTitleBarButton( painter, titleBarOption, widget, SC_TitleBarNormalButton ); }
if( titleBarOption->subControls & SC_TitleBarShadeButton )
{ renderTitleBarButton( painter, titleBarOption, widget, SC_TitleBarShadeButton ); }
if( titleBarOption->subControls & SC_TitleBarUnshadeButton )
{ renderTitleBarButton( painter, titleBarOption, widget, SC_TitleBarUnshadeButton ); }
if( ( titleBarOption->subControls & SC_TitleBarContextHelpButton ) && ( titleBarOption->titleBarFlags & Qt::WindowContextHelpButtonHint ) )
{ renderTitleBarButton( painter, titleBarOption, widget, SC_TitleBarContextHelpButton ); }
return true;
}
//_________________________________________________________________________________
void Style::renderDialSlab( QPainter *painter, const QRect& constRect, const QColor &color, const QStyleOption *option, StyleOptions styleOptions, qreal opacity, AnimationMode mode ) const
{
// cast option and check
const QStyleOptionSlider* sliderOption( qstyleoption_cast<const QStyleOptionSlider*>( option ) );
if( !sliderOption ) return;
// copy palette
const QPalette& palette( option->palette );
// adjust rect to be square, and centered
const int dimension( qMin( constRect.width(), constRect.height() ) );
const QRect rect( centerRect( constRect, dimension, dimension ) );
// calculate glow color
const QColor glow( _helper->buttonGlowColor( palette, styleOptions, opacity, mode ) );
// get main slab
QPixmap pixmap( _helper->dialSlab( color, glow, 0, dimension ) );
{
const QColor light( _helper->calcLightColor( color ) );
const QColor shadow( _helper->calcShadowColor( color ) );
QPainter painter( &pixmap );
painter.setPen( Qt::NoPen );
painter.setRenderHints( QPainter::Antialiasing );
// indicator
const qreal angle( dialAngle( sliderOption, sliderOption->sliderPosition ) );
QPointF center( pixmap.rect().center()/_helper->devicePixelRatio( pixmap ) );
const int sliderWidth( dimension/6 );
const qreal radius( 0.5*( dimension - 2*sliderWidth ) );
center += QPointF( radius*cos( angle ), -radius*sin( angle ) );
QRectF sliderRect( 0, 0, sliderWidth, sliderWidth );
sliderRect.moveCenter( center );
// outline circle
const qreal offset( 0.3 );
painter.setBrush( light );
painter.setPen( Qt::NoPen );
painter.drawEllipse( sliderRect.translated( 0, offset ) );
// mask
painter.setPen( Qt::NoPen );
painter.save();
painter.setCompositionMode( QPainter::CompositionMode_DestinationOut );
painter.setBrush( QBrush( Qt::black ) );
painter.drawEllipse( sliderRect );
painter.restore();
// shadow
painter.translate( sliderRect.topLeft() );
_helper->drawInverseShadow( painter, shadow.darker( 200 ), 0, sliderRect.width(), 0 );
// glow
if( glow.isValid() ) _helper->drawInverseGlow( painter, glow, 0, sliderRect.width(), sliderRect.width() );
painter.end();
}
painter->drawPixmap( rect.topLeft(), pixmap );
return;
}
//____________________________________________________________________________________
void Style::renderButtonSlab( QPainter *painter, QRect rect, const QColor &color, StyleOptions options, qreal opacity,
AnimationMode mode,
TileSet::Tiles tiles ) const
{
// check rect
if( !rect.isValid() ) return;
// edges
// for slabs, hover takes precedence over focus ( other way around for holes )
// but in any case if the button is sunken we don't show focus nor hover
TileSet tileSet;
if( options & Sunken )
{
tileSet = _helper->slabSunken( color );
} else {
QColor glow = _helper->buttonGlowColor( QPalette::Active, options, opacity, mode );
tileSet = _helper->slab( color, glow, 0 );
}
// adjust rect to account for missing tiles
if( tileSet.isValid() ) rect = tileSet.adjust( rect, tiles );
// fill
if( !( options & NoFill ) ) _helper->fillButtonSlab( *painter, rect, color, options&Sunken );
// render slab
if( tileSet.isValid() ) tileSet.render( rect, painter, tiles );
}
//____________________________________________________________________________________
void Style::renderSlab(
QPainter *painter, QRect rect,
const QColor &color,
StyleOptions options, qreal opacity,
AnimationMode mode,
TileSet::Tiles tiles ) const
{
// check rect
if( !rect.isValid() ) return;
// fill
if( !( options & NoFill ) )
{
painter->save();
painter->setRenderHint( QPainter::Antialiasing );
painter->setPen( Qt::NoPen );
if( _helper->calcShadowColor( color ).value() > color.value() && ( options & Sunken ) )
{
QLinearGradient innerGradient( 0, rect.top(), 0, rect.bottom() + rect.height() );
innerGradient.setColorAt( 0, color );
innerGradient.setColorAt( 1, _helper->calcLightColor( color ) );
painter->setBrush( innerGradient );
} else {
QLinearGradient innerGradient( 0, rect.top() - rect.height(), 0, rect.bottom() );
innerGradient.setColorAt( 0, _helper->calcLightColor( color ) );
innerGradient.setColorAt( 1, color );
painter->setBrush( innerGradient );
}
_helper->fillSlab( *painter, rect );
painter->restore();
}
// edges
// for slabs, hover takes precedence over focus ( other way around for holes )
// but in any case if the button is sunken we don't show focus nor hover
TileSet tileSet;
if( ( options & Sunken ) && color.isValid() )
{
tileSet = _helper->slabSunken( color );
} else {
// calculate proper glow color based on current settings and opacity
const QColor glow( _helper->buttonGlowColor( QPalette::Active, options, opacity, mode ) );
if( color.isValid() || glow.isValid() ) tileSet = _helper->slab( color, glow , 0 );
else return;
}
// render tileset
if( tileSet.isValid() ) tileSet.render( rect, painter, tiles );
}
//______________________________________________________________________________________________________________________________
void Style::fillTabBackground( QPainter* painter, const QRect& rect, const QColor &color, const QWidget* widget ) const
{
// filling
const QRect fillRect( insideMargin( rect, Metrics::TabBar_TabOffset ) );
if( widget ) _helper->renderWindowBackground( painter, fillRect, widget, color );
else painter->fillRect( fillRect, color );
}
//______________________________________________________________________________________________________________________________
void Style::fillTab( QPainter* painter, const QRect &rect, const QColor &color, QTabBar::Shape shape ) const
{
const QColor dark( _helper->calcDarkColor( color ) );
const QColor shadow( _helper->calcShadowColor( color ) );
const QColor light( _helper->calcLightColor( color ) );
const QRect fillRect( insideMargin( rect, Metrics::TabBar_TabOffset ) );
QLinearGradient gradient;
switch( shape )
{
case QTabBar::RoundedNorth:
case QTabBar::TriangularNorth:
gradient = QLinearGradient( fillRect.topLeft(), fillRect.bottomLeft() );
break;
case QTabBar::RoundedSouth:
case QTabBar::TriangularSouth:
gradient = QLinearGradient( fillRect.bottomLeft(), fillRect.topLeft() );
break;
case QTabBar::RoundedEast:
case QTabBar::TriangularEast:
gradient = QLinearGradient( fillRect.topRight(), fillRect.topLeft() );
break;
case QTabBar::RoundedWest:
case QTabBar::TriangularWest:
gradient = QLinearGradient( fillRect.topLeft(), fillRect.topRight() );
break;
default: return;
}
gradient.setColorAt( 0, _helper->alphaColor( light, 0.5 ) );
gradient.setColorAt( 0.1, _helper->alphaColor( light, 0.5 ) );
gradient.setColorAt( 0.25, _helper->alphaColor( light, 0.3 ) );
gradient.setColorAt( 0.5, _helper->alphaColor( light, 0.2 ) );
gradient.setColorAt( 0.75, _helper->alphaColor( light, 0.1 ) );
gradient.setColorAt( 0.9, Qt::transparent );
painter->setRenderHints( QPainter::Antialiasing );
painter->setPen( Qt::NoPen );
painter->setBrush( gradient );
painter->drawRoundedRect( fillRect, 2, 2 );
}
//____________________________________________________________________________________________________
void Style::renderSpinBoxArrow( QPainter* painter, const QStyleOptionSpinBox* option, const QWidget* widget, const SubControl& subControl ) const
{
const QPalette& palette( option->palette );
const State& state( option->state );
// enable state
bool enabled( state & State_Enabled );
// check steps enable step
const bool atLimit(
(subControl == SC_SpinBoxUp && !(option->stepEnabled & QAbstractSpinBox::StepUpEnabled )) ||
(subControl == SC_SpinBoxDown && !(option->stepEnabled & QAbstractSpinBox::StepDownEnabled ) ) );
// update enabled state accordingly
enabled &= !atLimit;
// update mouse-over effect
const bool mouseOver( enabled && ( state & State_MouseOver ) );
// check animation state
const bool subControlHover( enabled && mouseOver && ( option->activeSubControls & subControl ) );
_animations->spinBoxEngine().updateState( widget, subControl, subControlHover );
const bool animated( enabled && _animations->spinBoxEngine().isAnimated( widget, subControl ) );
const qreal opacity( _animations->spinBoxEngine().opacity( widget, subControl ) );
QColor color;
if( animated )
{
QColor highlight = _helper->hoverColor( palette );
color = KColorUtils::mix( palette.color( QPalette::Text ), highlight, opacity );
} else if( subControlHover ) {
color = _helper->hoverColor( palette );
} else if( atLimit ) {
color = palette.color( QPalette::Disabled, QPalette::Text );
} else {
color = palette.color( QPalette::Text );
}
const qreal penThickness = 1.6;
const QColor background = palette.color( QPalette::Window );
const QPolygonF arrow( genericArrow( ( subControl == SC_SpinBoxUp ) ? ArrowUp:ArrowDown, ArrowNormal ) );
const QRect arrowRect( subControlRect( CC_SpinBox, option, subControl, widget ) );
painter->save();
painter->translate( QRectF( arrowRect ).center() );
painter->setRenderHint( QPainter::Antialiasing );
painter->setPen( QPen( _helper->decoColor( background, color ) , penThickness, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin ) );
painter->drawPolyline( arrow );
painter->restore();
return;
}
//___________________________________________________________________________________
void Style::renderSplitter( const QStyleOption* option, QPainter* painter, const QWidget* widget, bool horizontal ) const
{
// copy rect and palette
const QRect& rect( option->rect );
const QPalette& palette( option->palette );
// store state
const State& state( option->state );
const bool enabled( state & State_Enabled );
const bool mouseOver( enabled && ( state & ( State_MouseOver|State_Sunken ) ) );
// get orientation
const Qt::Orientation orientation( horizontal ? Qt::Horizontal : Qt::Vertical );
bool animated( false );
qreal opacity( AnimationData::OpacityInvalid );
if( enabled )
{
if( qobject_cast<const QMainWindow*>( widget ) )
{
_animations->dockSeparatorEngine().updateRect( widget, rect, orientation, mouseOver );
animated = _animations->dockSeparatorEngine().isAnimated( widget, rect, orientation );
opacity = animated ? _animations->dockSeparatorEngine().opacity( widget, orientation ) : AnimationData::OpacityInvalid;
} else if( QPaintDevice* device = painter->device() ) {
/*
try update QSplitterHandle using painter device, because Qt passes
QSplitter as the widget to the QStyle primitive.
*/
_animations->splitterEngine().updateState( device, mouseOver );
animated = _animations->splitterEngine().isAnimated( device );
opacity = _animations->splitterEngine().opacity( device );
}
}
// get base color
const QColor color = palette.color( QPalette::Window );
if( horizontal )
{
const int hCenter = rect.center().x();
const int h = rect.height();
if( animated || mouseOver )
{
const QColor highlight = _helper->alphaColor( _helper->calcLightColor( color ),0.5*( animated ? opacity:1 ) );
const qreal fraction( rect.height() > 30 ? 10/rect.height():0.1 );
QLinearGradient gradient( rect.topLeft(), rect.bottomLeft() );
gradient.setColorAt( 0, Qt::transparent );
gradient.setColorAt( fraction, highlight );
gradient.setColorAt( 1-fraction, highlight );
gradient.setColorAt( 1, Qt::transparent );
painter->fillRect( rect, gradient );
}
const int ngroups( qMax( 1,h / 250 ) );
int center( ( h - ( ngroups-1 ) * 250 ) /2 + rect.top() );
for( int k = 0; k < ngroups; k++, center += 250 )
{
_helper->renderDot( painter, QPoint( hCenter, center-3 ), color );
_helper->renderDot( painter, QPoint( hCenter, center ), color );
_helper->renderDot( painter, QPoint( hCenter, center+3 ), color );
}
} else {
const int vCenter( rect.center().y() );
const int w( rect.width() );
if( animated || mouseOver )
{
const QColor highlight( _helper->alphaColor( _helper->calcLightColor( color ),0.5*( animated ? opacity:1 ) ) );
const qreal fraction( rect.width() > 30 ? 10 / rect.width():0.1 );
QLinearGradient gradient( rect.topLeft(), rect.topRight() );
gradient.setColorAt( 0, Qt::transparent );
gradient.setColorAt( fraction, highlight );
gradient.setColorAt( 1 - fraction, highlight );
gradient.setColorAt( 1, Qt::transparent );
painter->fillRect( rect, gradient );
}
const int ngroups( qMax( 1, w / 250 ) );
int center = ( w - ( ngroups-1 ) * 250 ) /2 + rect.left();
for( int k = 0; k < ngroups; k++, center += 250 )
{
_helper->renderDot( painter, QPoint( center-3, vCenter ), color );
_helper->renderDot( painter, QPoint( center, vCenter ), color );
_helper->renderDot( painter, QPoint( center+3, vCenter ), color );
}
}
}
//____________________________________________________________________________________________________
void Style::renderTitleBarButton( QPainter* painter, const QStyleOptionTitleBar* option, const QWidget* widget, const SubControl& subControl ) const
{
// get relevant rect
const QRect rect = subControlRect( CC_TitleBar, option, subControl, widget );
if( !rect.isValid() ) return;
// copy palette
QPalette palette = option->palette;
// store state
const State& state( option->state );
const bool enabled( state & State_Enabled );
const bool active( enabled && ( option->titleBarState & Qt::WindowActive ) );
// enable state transition
_animations->widgetEnableStateEngine().updateState( widget, AnimationEnable, active );
if( _animations->widgetEnableStateEngine().isAnimated( widget, AnimationEnable ) )
{ palette = _helper->disabledPalette( palette, _animations->widgetEnableStateEngine().opacity( widget, AnimationEnable ) ); }
const bool sunken( state & State_Sunken );
const bool mouseOver( ( !sunken ) && widget && rect.translated( widget->mapToGlobal( QPoint( 0,0 ) ) ).contains( QCursor::pos() ) );
_animations->mdiWindowEngine().updateState( widget, subControl, enabled && mouseOver );
const bool animated( enabled && _animations->mdiWindowEngine().isAnimated( widget, subControl ) );
const qreal opacity( _animations->mdiWindowEngine().opacity( widget, subControl ) );
// contrast color
const QColor base =option->palette.color( QPalette::Active, QPalette::Window );
// icon color
QColor color;
if( animated )
{
const QColor base( palette.color( active ? QPalette::Active : QPalette::Disabled, QPalette::WindowText ) );
const QColor glow( subControl == SC_TitleBarCloseButton ?
_helper->negativeTextColor( palette ):
_helper->hoverColor( palette ) );
color = KColorUtils::mix( base, glow, opacity );
} else if( mouseOver ) {
color = ( subControl == SC_TitleBarCloseButton ) ?
_helper->negativeTextColor( palette ):
_helper->hoverColor( palette );
} else {
color = palette.color( active ? QPalette::Active : QPalette::Disabled, QPalette::WindowText );
}
// rendering
renderTitleBarButton( painter, rect, base, color, subControl );
}
//____________________________________________________________________________________________________
void Style::renderTitleBarButton( QPainter* painter, const QRect& rect, const QColor& base, const QColor& color, const SubControl& subControl ) const
{
painter->save();
painter->setRenderHints( QPainter::Antialiasing );
painter->setBrush( Qt::NoBrush );
painter->drawPixmap( rect, _helper->dockWidgetButton( base, true, rect.width() ) );
const qreal width( 1.1 );
// contrast
painter->translate( 0, 0.5 );
painter->setPen( QPen( _helper->calcLightColor( base ), width, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin ) );
renderTitleBarIcon( painter, rect, subControl );
// main icon painting
painter->translate( 0,-1 );
painter->setPen( QPen( color, width, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin ) );
renderTitleBarIcon( painter, rect, subControl );
painter->restore();
}
//____________________________________________________________________________________
void Style::renderTitleBarIcon( QPainter *painter, const QRect& rect, const SubControl& subControl ) const
{
painter->save();
painter->translate( rect.topLeft() );
painter->scale( qreal( rect.width() )/16, qreal( rect.height() )/16 );
switch( subControl )
{
case SC_TitleBarContextHelpButton:
{
painter->drawArc( 6, 4, 3, 3, 135*16, -180*16 );
painter->drawArc( 8, 7, 3, 3, 135*16, 45*16 );
painter->drawPoint( 8, 11 );
break;
}
case SC_TitleBarMinButton:
{
painter->drawPolyline( QPolygon() << QPoint( 5, 7 ) << QPoint( 8, 10 ) << QPoint( 11, 7 ) );
break;
}
case SC_TitleBarNormalButton:
{
painter->drawPolygon( QPolygon() << QPoint( 8, 5 ) << QPoint( 11, 8 ) << QPoint( 8, 11 ) << QPoint( 5, 8 ) );
break;
}
case SC_TitleBarMaxButton:
{
painter->drawPolyline( QPolygon() << QPoint( 5, 9 ) << QPoint( 8, 6 ) << QPoint( 11, 9 ) );
break;
}
case SC_TitleBarCloseButton:
{
painter->drawLine( QPointF( 5.5, 5.5 ), QPointF( 10.5, 10.5 ) );
painter->drawLine( QPointF( 10.5, 5.5 ), QPointF( 5.5, 10.5 ) );
break;
}
case SC_TitleBarShadeButton:
{
painter->drawLine( QPoint( 5, 11 ), QPoint( 11, 11 ) );
painter->drawPolyline( QPolygon() << QPoint( 5, 5 ) << QPoint( 8, 8 ) << QPoint( 11, 5 ) );
break;
}
case SC_TitleBarUnshadeButton:
{
painter->drawPolyline( QPolygon() << QPoint( 5, 8 ) << QPoint( 8, 5 ) << QPoint( 11, 8 ) );
painter->drawLine( QPoint( 5, 11 ), QPoint( 11, 11 ) );
break;
}
default:
break;
}
painter->restore();
}
//__________________________________________________________________________
void Style::renderHeaderBackground( const QRect& rect, const QPalette& palette, QPainter* painter, const QWidget* widget, bool horizontal, bool reverse ) const
{
// use window background for the background
if( widget ) _helper->renderWindowBackground( painter, rect, widget, palette );
else painter->fillRect( rect, palette.color( QPalette::Window ) );
if( horizontal ) renderHeaderLines( rect, palette, painter, TileSet::Bottom );
else if( reverse ) renderHeaderLines( rect, palette, painter, TileSet::Left );
else renderHeaderLines( rect, palette, painter, TileSet::Right );
}
//__________________________________________________________________________
void Style::renderHeaderLines( const QRect& constRect, const QPalette& palette, QPainter* painter, TileSet::Tiles tiles ) const
{
// add horizontal lines
const QColor color( palette.color( QPalette::Window ) );
const QColor dark( _helper->calcDarkColor( color ) );
const QColor light( _helper->calcLightColor( color ) );
painter->save();
QRect rect( constRect );
if( tiles & TileSet::Bottom )
{
painter->setPen( dark );
if( tiles & TileSet::Left ) painter->drawPoint( rect.bottomLeft() );
else if( tiles& TileSet::Right ) painter->drawPoint( rect.bottomRight() );
else painter->drawLine( rect.bottomLeft(), rect.bottomRight() );
rect.adjust( 0, 0, 0, -1 );
painter->setPen( light );
if( tiles & TileSet::Left )
{
painter->drawLine( rect.bottomLeft(), rect.bottomLeft()+QPoint( 1, 0 ) );
painter->drawLine( rect.bottomLeft()+ QPoint( 1, 0 ), rect.bottomLeft()+QPoint( 1, 1 ) );
} else if( tiles & TileSet::Right ) {
painter->drawLine( rect.bottomRight(), rect.bottomRight() - QPoint( 1, 0 ) );
painter->drawLine( rect.bottomRight() - QPoint( 1, 0 ), rect.bottomRight() - QPoint( 1, -1 ) );
} else {
painter->drawLine( rect.bottomLeft(), rect.bottomRight() );
}
} else if( tiles & TileSet::Left ) {
painter->setPen( dark );
painter->drawLine( rect.topLeft(), rect.bottomLeft() );
rect.adjust( 1, 0, 0, 0 );
painter->setPen( light );
painter->drawLine( rect.topLeft(), rect.bottomLeft() );
} else if( tiles & TileSet::Right ) {
painter->setPen( dark );
painter->drawLine( rect.topRight(), rect.bottomRight() );
rect.adjust( 0, 0, -1, 0 );
painter->setPen( light );
painter->drawLine( rect.topRight(), rect.bottomRight() );
}
painter->restore();
return;
}
//__________________________________________________________________________
void Style::renderMenuItemBackground( const QStyleOption* option, QPainter* painter, const QWidget* widget ) const
{
const QRect& rect( option->rect );
const QPalette& palette( option->palette );
const QRect animatedRect( _animations->menuEngine().animatedRect( widget ) );
if( !animatedRect.isNull() )
{
if( animatedRect.intersects( rect ) )
{
const QColor color( _helper->menuBackgroundColor( _helper->calcMidColor( palette.color( QPalette::Window ) ), widget, animatedRect.center() ) );
renderMenuItemRect( option, animatedRect, color, palette, painter );
}
} else if( _animations->menuEngine().isTimerActive( widget ) ) {
const QRect previousRect( _animations->menuEngine().currentRect( widget, Previous ) );
if( previousRect.intersects( rect ) )
{
const QColor color( _helper->menuBackgroundColor( _helper->calcMidColor( palette.color( QPalette::Window ) ), widget, previousRect.center() ) );
renderMenuItemRect( option, previousRect, color, palette, painter );
}
} else if( _animations->menuEngine().isAnimated( widget, Previous ) ) {
QRect previousRect( _animations->menuEngine().currentRect( widget, Previous ) );
if( previousRect.intersects( rect ) )
{
const qreal opacity( _animations->menuEngine().opacity( widget, Previous ) );
const QColor color( _helper->menuBackgroundColor( _helper->calcMidColor( palette.color( QPalette::Window ) ), widget, previousRect.center() ) );
renderMenuItemRect( option, previousRect, color, palette, painter, opacity );
}
}
return;
}
//__________________________________________________________________________
void Style::renderMenuItemRect( const QStyleOption* option, const QRect& rect, const QColor& base, const QPalette& palette, QPainter* painter, qreal opacity ) const
{
if( opacity == 0 ) return;
// get relevant color
// TODO: this is inconsistent with MenuBar color.
// this should change to properly account for 'sunken' state
QColor color( base );
if( StyleConfigData::menuHighlightMode() == StyleConfigData::MM_STRONG )
{
color = palette.color( QPalette::Highlight );
} else if( StyleConfigData::menuHighlightMode() == StyleConfigData::MM_SUBTLE ) {
color = KColorUtils::mix( color, KColorUtils::tint( color, palette.color( QPalette::Highlight ), 0.6 ) );
}
// special painting for items with submenus
const QStyleOptionMenuItem* menuItemOption = qstyleoption_cast<const QStyleOptionMenuItem*>( option );
if( menuItemOption && menuItemOption->menuItemType == QStyleOptionMenuItem::SubMenu )
{
QPixmap pixmap( rect.size() );
{
pixmap.fill( Qt::transparent );
QPainter painter( &pixmap );
const QRect pixmapRect( pixmap.rect() );
painter.setRenderHint( QPainter::Antialiasing );
painter.setPen( Qt::NoPen );
painter.setBrush( color );
_helper->fillHole( painter, pixmapRect );
_helper->holeFlat( color, 0 ).render( pixmapRect.adjusted( 1, 2, -2, -1 ), &painter );
QRect maskRect( visualRect( option->direction, pixmapRect, QRect( pixmapRect.width()-40, 0, 40, pixmapRect.height() ) ) );
QLinearGradient gradient(
visualPos( option->direction, maskRect, QPoint( maskRect.left(), 0 ) ),
visualPos( option->direction, maskRect, QPoint( maskRect.right()-4, 0 ) ) );
gradient.setColorAt( 0, Qt::black );
gradient.setColorAt( 1, Qt::transparent );
painter.setBrush( gradient );
painter.setCompositionMode( QPainter::CompositionMode_DestinationIn );
painter.drawRect( maskRect );
if( opacity >= 0 && opacity < 1 )
{
painter.setCompositionMode( QPainter::CompositionMode_DestinationIn );
painter.fillRect( pixmapRect, _helper->alphaColor( Qt::black, opacity ) );
}
painter.end();
}
painter->drawPixmap( visualRect( option, rect ), pixmap );
} else {
if( opacity >= 0 && opacity < 1 )
{ color.setAlphaF( opacity ); }
_helper->holeFlat( color, 0 ).render( rect.adjusted( 1, 2, -2, -1 ), painter, TileSet::Full );
}
}
//________________________________________________________________________
void Style::renderCheckBox(
QPainter *painter, const QRect &constRect, const QPalette &palette,
StyleOptions options, CheckBoxState state,
qreal opacity,
AnimationMode mode ) const
{
const int size( qMin( constRect.width(), constRect.height() ) );
const QRect rect( centerRect( constRect, size, size ) );
if( !( options & NoFill ) )
{
if( options & Sunken ) _helper->holeFlat( palette.color( QPalette::Window ), 0, false ).render( insideMargin( rect, 1 ), painter, TileSet::Full );
else renderSlab( painter, rect, palette.color( QPalette::Button ), options, opacity, mode, TileSet::Ring );
}
if( state == CheckOff ) return;
// check mark
qreal penThickness( 2 );
const QColor color( palette.color( ( options&Sunken ) ? QPalette::WindowText:QPalette::ButtonText ) );
const QColor background( palette.color( ( options&Sunken ) ? QPalette::Window:QPalette::Button ) );
QPen pen( _helper->decoColor( background, color ), penThickness, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin );
QPen contrastPen( _helper->calcLightColor( background ), penThickness, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin );
if( state == CheckTriState )
{
QVector<qreal> dashes;
dashes << 1 << 2;
penThickness = 1.3;
pen.setWidthF( penThickness );
contrastPen.setWidthF( penThickness );
pen.setDashPattern( dashes );
contrastPen.setDashPattern( dashes );
} else if( state == CheckSunken ) {
pen.setColor( _helper->alphaColor( pen.color(), 0.3 ) );
contrastPen.setColor( _helper->alphaColor( contrastPen.color(), 0.3 ) );
}
painter->save();
painter->translate( QRectF( rect ).center() );
if( !( options&Sunken ) ) painter->translate( 0, -1 );
painter->setRenderHint( QPainter::Antialiasing );
QPolygonF checkMark;
checkMark << QPointF( 5, -2 ) << QPointF( -1, 5 ) << QPointF( -4, 2 );
const qreal offset( qMin( penThickness, qreal( 1 ) ) );
painter->setPen( contrastPen );
painter->translate( 0, offset );
painter->drawPolyline( checkMark );
painter->setPen( pen );
painter->translate( 0, -offset );
painter->drawPolyline( checkMark );
painter->restore();
return;
}
//___________________________________________________________________
void Style::renderRadioButton(
QPainter* painter, const QRect& constRect,
const QPalette& palette,
StyleOptions options,
CheckBoxState state,
qreal opacity,
AnimationMode mode ) const
{
// get pixmap
const QColor color( palette.color( QPalette::Button ) );
const QColor glow( _helper->buttonGlowColor( palette, options, opacity, mode ) );
QPixmap pixmap( _helper->roundSlab( color, glow, 0 ) );
// center rect
const QRect rect( centerRect( constRect, pixmap.size()/_helper->devicePixelRatio( pixmap ) ) );
// render
painter->drawPixmap( rect.topLeft(), pixmap );
// draw the radio mark
if( state != CheckOff )
{
const qreal radius( 2.6 );
const qreal dx( 0.5*rect.width() - radius );
const qreal dy( 0.5*rect.height() - radius );
const QRectF symbolRect( QRectF( rect ).adjusted( dx, dy, -dx, -dy ) );
painter->save();
painter->setRenderHints( QPainter::Antialiasing );
painter->setPen( Qt::NoPen );
const QColor background( palette.color( QPalette::Button ) );
const QColor color( palette.color( QPalette::ButtonText ) );
// contrast
if( state == CheckOn ) painter->setBrush( _helper->calcLightColor( background ) );
else painter->setBrush( _helper->alphaColor( _helper->calcLightColor( background ), 0.3 ) );
painter->translate( 0, radius/2 );
painter->drawEllipse( symbolRect );
// symbol
if( state == CheckOn ) painter->setBrush( _helper->decoColor( background, color ) );
else painter->setBrush( _helper->alphaColor( _helper->decoColor( background, color ), 0.3 ) );
painter->translate( 0, -radius/2 );
painter->drawEllipse( symbolRect );
painter->restore();
}
return;
}
//______________________________________________________________________________
void Style::renderScrollBarHole(
QPainter *painter, const QRect &rect, const QColor &color,
const Qt::Orientation& orientation, const TileSet::Tiles& tiles ) const
{
if( !rect.isValid() ) return;
// one need to make smaller shadow
// notably on the size when rect height is too high
const bool smallShadow( orientation == Qt::Horizontal ? rect.height() < 10 : rect.width() < 10 );
_helper->scrollHole( color, orientation, smallShadow ).render( rect, painter, tiles );
}
//______________________________________________________________________________
void Style::renderScrollBarHandle(
QPainter* painter, const QRect& constRect, const QPalette& palette,
const Qt::Orientation& orientation, const bool& hover, const qreal& opacity ) const
{
if( !constRect.isValid() ) return;
// define rect and check
QRect rect( insideMargin( constRect, 3 ) );
painter->save();
painter->setRenderHints( QPainter::Antialiasing );
const QColor color( palette.color( QPalette::Button ) );
// draw the slider
const qreal radius = 3.5;
// glow / shadow
QColor glow;
const QColor shadow( _helper->alphaColor( _helper->calcShadowColor( color ), 0.4 ) );
const QColor hovered( _helper->hoverColor( palette ) );
if( opacity >= 0 ) glow = KColorUtils::mix( shadow, hovered, opacity );
else if( hover ) glow = hovered;
else glow = shadow;
_helper->scrollHandle( color, glow ).render( constRect, painter, TileSet::Full );
// contents
const QColor mid( _helper->calcMidColor( color ) );
QLinearGradient gradient( rect.topLeft(), rect.bottomLeft() );
gradient.setColorAt(0, color );
gradient.setColorAt(1, mid );
painter->setPen( Qt::NoPen );
painter->setBrush( gradient );
painter->drawRoundedRect( insideMargin( rect, 1 ), radius - 2, radius - 2 );
// bevel pattern
const QColor light( _helper->calcLightColor( color ) );
const bool horizontal( orientation == Qt::Horizontal );
QLinearGradient patternGradient( 0, 0, horizontal ? 30:0, horizontal? 0:30 );
patternGradient.setSpread( QGradient::ReflectSpread );
patternGradient.setColorAt( 0, Qt::transparent );
patternGradient.setColorAt( 1, _helper->alphaColor( light, 0.1 ) );
QRect bevelRect( rect );
if( horizontal ) bevelRect = insideMargin( bevelRect, 0, 3 );
else bevelRect = insideMargin( bevelRect, 3, 0 );
if( bevelRect.isValid() )
{
painter->setBrush( patternGradient );
painter->drawRect( bevelRect );
}
painter->restore();
return;
}
//______________________________________________________________________________
void Style::renderScrollBarArrow(
QPainter* painter, const QRect& rect, const QColor& color, const QColor& background,
ArrowOrientation orientation ) const
{
const qreal penThickness = 1.6;
QPolygonF arrow( genericArrow( orientation, ArrowNormal ) );
const QColor contrast( _helper->calcLightColor( background ) );
const QColor base( _helper->decoColor( background, color ) );
painter->save();
painter->translate( QRectF(rect).center() );
painter->setRenderHint( QPainter::Antialiasing );
const qreal offset( qMin( penThickness, qreal( 1 ) ) );
painter->translate( 0,offset );
painter->setPen( QPen( contrast, penThickness, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin ) );
painter->drawPolyline( arrow );
painter->translate( 0,-offset );
painter->setPen( QPen( base, penThickness, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin ) );
painter->drawPolyline( arrow );
painter->restore();
return;
}
//______________________________________________________________________________
QColor Style::scrollBarArrowColor( const QStyleOptionSlider* option, const SubControl& control, const QWidget* widget ) const
{
// copy rect and palette
const QRect& rect( option->rect );
const QPalette& palette( option->palette );
// color
QColor color( palette.color( QPalette::WindowText ) );
// check enabled state
const bool enabled( option->state & State_Enabled );
if( !enabled ) return color;
if(
( control == SC_ScrollBarSubLine && option->sliderValue == option->minimum ) ||
( control == SC_ScrollBarAddLine && option->sliderValue == option->maximum ) )
{
// manually disable arrow, to indicate that scrollbar is at limit
return palette.color( QPalette::Disabled, QPalette::WindowText );
}
const bool mouseOver( _animations->scrollBarEngine().isHovered( widget, control ) );
const bool animated( _animations->scrollBarEngine().isAnimated( widget, control ) );
const qreal opacity( _animations->scrollBarEngine().opacity( widget, control ) );
// retrieve mouse position from engine
QPoint position( mouseOver ? _animations->scrollBarEngine().position( widget ) : QPoint( -1, -1 ) );
if( mouseOver && rect.contains( position ) )
{
// need to update the arrow controlRect on fly because there is no
// way to get it from the styles directly, outside of repaint events
_animations->scrollBarEngine().setSubControlRect( widget, control, rect );
}
if( rect.intersects( _animations->scrollBarEngine().subControlRect( widget, control ) ) )
{
QColor highlight = _helper->hoverColor( palette );
if( animated )
{
color = KColorUtils::mix( color, highlight, opacity );
} else if( mouseOver ) {
color = highlight;
}
}
return color;
}
//______________________________________________________________________________
qreal Style::dialAngle( const QStyleOptionSlider* sliderOption, int value ) const
{
// calculate angle at which handle needs to be drawn
qreal angle( 0 );
if( sliderOption->maximum == sliderOption->minimum ) angle = M_PI / 2;
else {
qreal fraction( qreal( value - sliderOption->minimum )/qreal( sliderOption->maximum - sliderOption->minimum ) );
if( !sliderOption->upsideDown ) fraction = 1 - fraction;
if( sliderOption->dialWrapping ) angle = 1.5*M_PI - fraction*2*M_PI;
else angle = ( M_PI*8 - fraction*10*M_PI )/6;
}
return angle;
}
//______________________________________________________________
void Style::polishScrollArea( QAbstractScrollArea* scrollArea ) const
{
if( !scrollArea ) return;
// HACK: add exception for KPIM transactionItemView, which is an overlay widget
// and must have filled background. This is a temporary workaround until a more
// robust solution is found.
if( scrollArea->inherits( "KPIM::TransactionItemView" ) )
{
// also need to make the scrollarea background plain ( using autofill background )
// so that optional vertical scrollbar background is not transparent either.
// TODO: possibly add an event filter to use the "normal" window background
// instead of something flat.
scrollArea->setAutoFillBackground( true );
return;
}
// check frame style and background role
if( !(scrollArea->frameShape() == QFrame::NoFrame || scrollArea->backgroundRole() == QPalette::Window ) )
{ return; }
// get viewport and check background role
QWidget* viewport( scrollArea->viewport() );
if( !( viewport && viewport->backgroundRole() == QPalette::Window ) ) return;
// change viewport autoFill background.
// do the same for children if the background role is QPalette::Window
viewport->setAutoFillBackground( false );
QList<QWidget*> children( viewport->findChildren<QWidget*>() );
foreach( QWidget* child, children )
{
if( child->parent() == viewport && child->backgroundRole() == QPalette::Window )
{ child->setAutoFillBackground( false ); }
}
}
//_______________________________________________________________
QRegion Style::tabBarClipRegion( const QTabBar* tabBar ) const
{
// need to mask-out arrow buttons, if visible.
QRegion mask( tabBar->rect() );
foreach( const QObject* child, tabBar->children() )
{
const QToolButton* toolButton( qobject_cast<const QToolButton*>( child ) );
if( toolButton && toolButton->isVisible() ) mask -= toolButton->geometry();
}
return mask;
}
//____________________________________________________________________________________
QPolygonF Style::genericArrow( ArrowOrientation orientation, ArrowSize size ) const
{
QPolygonF arrow;
switch( orientation )
{
case ArrowUp:
{
if( size == ArrowTiny ) arrow << QPointF( -2.25, 1.125 ) << QPointF( 0, -1.125 ) << QPointF( 2.25, 1.125 );
else if( size == ArrowSmall ) arrow << QPointF( -2.5, 1.5 ) << QPointF( 0, -1.5 ) << QPointF( 2.5, 1.5 );
else arrow << QPointF( -3.5, 2 ) << QPointF( 0, -2 ) << QPointF( 3.5, 2 );
break;
}
case ArrowDown:
{
if( size == ArrowTiny ) arrow << QPointF( -2.25, -1.125 ) << QPointF( 0, 1.125 ) << QPointF( 2.25, -1.125 );
else if( size == ArrowSmall ) arrow << QPointF( -2.5, -1.5 ) << QPointF( 0, 1.5 ) << QPointF( 2.5, -1.5 );
else arrow << QPointF( -3.5, -2 ) << QPointF( 0, 2 ) << QPointF( 3.5, -2 );
break;
}
case ArrowLeft:
{
if( size == ArrowTiny ) arrow << QPointF( 1.125, -2.25 ) << QPointF( -1.125, 0 ) << QPointF( 1.125, 2.25 );
else if( size == ArrowSmall ) arrow << QPointF( 1.5, -2.5 ) << QPointF( -1.5, 0 ) << QPointF( 1.5, 2.5 );
else arrow << QPointF( 2, -3.5 ) << QPointF( -2, 0 ) << QPointF( 2, 3.5 );
break;
}
case ArrowRight:
{
if( size == ArrowTiny ) arrow << QPointF( -1.125, -2.25 ) << QPointF( 1.125, 0 ) << QPointF( -1.125, 2.25 );
else if( size == ArrowSmall ) arrow << QPointF( -1.5, -2.5 ) << QPointF( 1.5, 0 ) << QPointF( -1.5, 2.5 );
else arrow << QPointF( -2, -3.5 ) << QPointF( 2, 0 ) << QPointF( -2, 3.5 );
break;
}
default: break;
}
return arrow;
}
//____________________________________________________________________________________
QStyleOptionToolButton Style::separatorMenuItemOption( const QStyleOptionMenuItem* menuItemOption, const QWidget* widget ) const
{
// separator can have a title and an icon
// in that case they are rendered as sunken flat toolbuttons
QStyleOptionToolButton toolButtonOption;
toolButtonOption.initFrom( widget );
toolButtonOption.rect = menuItemOption->rect;
toolButtonOption.features = QStyleOptionToolButton::None;
toolButtonOption.state = State_On|State_Sunken|State_Enabled;
toolButtonOption.subControls = SC_ToolButton;
toolButtonOption.icon = menuItemOption->icon;
const int iconWidth( pixelMetric( PM_SmallIconSize, menuItemOption, widget ) );
toolButtonOption.iconSize = QSize( iconWidth, iconWidth );
toolButtonOption.text = menuItemOption->text;
toolButtonOption.toolButtonStyle = Qt::ToolButtonTextBesideIcon;
return toolButtonOption;
}
//____________________________________________________________________
bool Style::isQtQuickControl( const QStyleOption* option, const QWidget* widget ) const
{
const bool is = (widget == nullptr) && option && option->styleObject && option->styleObject->inherits( "QQuickItem" );
if ( is ) _windowManager->registerQuickItem( static_cast<QQuickItem*>( option->styleObject ) );
return is;
}
//_____________________________________________________________
Style::SlabRect::SlabRect(void):
tiles( TileSet::Ring )
{}
//_____________________________________________________________
Style::SlabRect::SlabRect( const QRect& rect, int tiles ):
rect( rect ),
tiles( TileSet::Tiles(tiles) )
{}
//_____________________________________________________________
bool Style::SlabRect::isValid( void ) const
{ return rect.isValid() && tiles; }
//_____________________________________________________________
void Style::SlabRect::adjust( int tileSize )
{
if( !( tiles & TileSet::Left ) ) rect.adjust( -tileSize, 0, 0, 0 );
if( !( tiles & TileSet::Right ) ) rect.adjust( 0, 0, tileSize, 0 );
if( !( tiles & TileSet::Top ) ) rect.adjust( 0, -tileSize, 0, 0 );
if( !( tiles & TileSet::Bottom ) ) rect.adjust( 0, 0, 0, tileSize );
}
//_____________________________________________________________
Style::SlabRect Style::SlabRect::adjusted( int tileSize ) const
{
SlabRect copy( *this );
copy.adjust( tileSize );
return copy;
}
}
namespace OxygenPrivate
{
//_________________________________________________________________________________________________________
void TabBarData::drawTabBarBaseControl( const QStyleOptionTab* tabOption, QPainter* painter, const QWidget* widget )
{
// check parent
if( !_style ) return;
// make sure widget is locked
if( !locks( widget ) ) return;
// make sure dirty flag is set
if( !_dirty ) return;
// cast to TabBar and check
const QTabBar* tabBar( qobject_cast<const QTabBar*>( widget ) );
if( !tabBar ) return;
// get reverseLayout flag
const bool reverseLayout( tabOption->direction == Qt::RightToLeft );
// get documentMode flag
const auto tabOptionV3 = qstyleoption_cast<const QStyleOptionTab*>( tabOption );
bool documentMode = tabOptionV3 ? tabOptionV3->documentMode : false;
const QTabWidget *tabWidget = ( widget && widget->parentWidget() ) ? qobject_cast<const QTabWidget *>( widget->parentWidget() ) : nullptr;
documentMode |= ( tabWidget ? tabWidget->documentMode() : true );
const QRect tabBarRect( tabBar->rect() );
// define slab
Oxygen::Style::SlabRect slab;
// switch on tab shape
switch( tabOption->shape )
{
case QTabBar::RoundedNorth:
case QTabBar::TriangularNorth:
{
Oxygen::TileSet::Tiles tiles( Oxygen::TileSet::Top );
QRect frameRect;
frameRect.setLeft( tabBarRect.left() - Oxygen::TileSet::DefaultSize );
frameRect.setRight( tabBarRect.right() + Oxygen::TileSet::DefaultSize );
frameRect.setTop( tabBarRect.bottom() - Oxygen::TileSet::DefaultSize + 1 );
frameRect.setHeight( 4 );
if( !( documentMode || reverseLayout ) ) tiles |= Oxygen::TileSet::Left;
if( !documentMode && reverseLayout ) tiles |= Oxygen::TileSet::Right;
slab = Oxygen::Style::SlabRect( frameRect, tiles );
break;
}
case QTabBar::RoundedSouth:
case QTabBar::TriangularSouth:
{
Oxygen::TileSet::Tiles tiles( Oxygen::TileSet::Bottom );
QRect frameRect;
frameRect.setLeft( tabBarRect.left() - Oxygen::TileSet::DefaultSize );
frameRect.setRight( tabBarRect.right() + Oxygen::TileSet::DefaultSize );
frameRect.setBottom( tabBarRect.top() + Oxygen::TileSet::DefaultSize - 1 );
frameRect.setTop( frameRect.bottom() - 4 );
if( !( documentMode || reverseLayout ) ) tiles |= Oxygen::TileSet::Left;
if( !documentMode && reverseLayout ) tiles |= Oxygen::TileSet::Right;
slab = Oxygen::Style::SlabRect( frameRect, tiles );
break;
}
case QTabBar::RoundedWest:
case QTabBar::TriangularWest:
{
Oxygen::TileSet::Tiles tiles( Oxygen::TileSet::Left );
QRect frameRect;
frameRect.setTop( tabBarRect.top() - Oxygen::TileSet::DefaultSize );
frameRect.setBottom( tabBarRect.bottom() + Oxygen::TileSet::DefaultSize );
frameRect.setLeft( tabBarRect.right() - Oxygen::TileSet::DefaultSize + 1 );
frameRect.setWidth( 4 );
if( !( documentMode || reverseLayout ) ) tiles |= Oxygen::TileSet::Top;
if( !documentMode && reverseLayout ) tiles |= Oxygen::TileSet::Bottom;
slab = Oxygen::Style::SlabRect( frameRect, tiles );
break;
}
case QTabBar::RoundedEast:
case QTabBar::TriangularEast:
{
Oxygen::TileSet::Tiles tiles( Oxygen::TileSet::Right );
QRect frameRect;
frameRect.setTop( tabBarRect.top() - Oxygen::TileSet::DefaultSize );
frameRect.setBottom( tabBarRect.bottom() + Oxygen::TileSet::DefaultSize );
frameRect.setRight( tabBarRect.left() + Oxygen::TileSet::DefaultSize - 1 );
frameRect.setLeft( frameRect.right() - 4 );
if( !( documentMode || reverseLayout ) ) tiles |= Oxygen::TileSet::Top;
if( !documentMode && reverseLayout ) tiles |= Oxygen::TileSet::Bottom;
slab = Oxygen::Style::SlabRect( frameRect, tiles );
break;
}
default:
break;
}
const bool verticalTabs( _style.data()->isVerticalTab( tabOption ) );
const QRect tabWidgetRect( tabWidget ? tabWidget->rect().translated( -widget->geometry().topLeft() ) : QRect() );
const QPalette& palette( tabOption->palette );
const QColor color( palette.color( QPalette::Window ) );
_style.data()->adjustSlabRect( slab, tabWidgetRect, documentMode, verticalTabs );
_style.data()->renderSlab( painter, slab, color, Oxygen::NoFill );
setDirty( false );
return;
}
}
|