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
|
{
*****************************************************************************
* QtWSComCtrls.pp *
* --------------- *
* *
* *
*****************************************************************************
*****************************************************************************
This file is part of the Lazarus Component Library (LCL)
See the file COPYING.modifiedLGPL.txt, included in this distribution,
for details about the license.
*****************************************************************************
}
unit QtWSComCtrls;
{$mode objfpc}{$H+}
interface
{$I qtdefines.inc}
uses
// Bindings
qt5,
qtwidgets, qtobjects, qtproc,
// RTL
SysUtils, Classes, Types,
// LCL
ComCtrls, Controls, LCLType, Graphics, StdCtrls,
LCLIntf, Forms, ImgList,
// Widgetset
WSProc, WSComCtrls, WSLCLClasses, QtWSControls;
type
{ TQtWSCustomPage }
TQtWSCustomPage = class(TWSCustomPage)
protected
class procedure UpdateTabFontColor(APage: TCustomPage; AFont: TFont);
published
class function CreateHandle(const AWinControl: TWinControl;
const AParams: TCreateParams): TLCLHandle; override;
class procedure DestroyHandle(const AWinControl: TWinControl); override;
class procedure SetFont(const AWinControl: TWinControl; const AFont: TFont); override;
class procedure UpdateProperties(const ACustomPage: TCustomPage); override;
end;
{ TQtWSCustomTabControl }
TQtWSCustomTabControl = class(TWSCustomTabControl)
published
class function CreateHandle(const AWinControl: TWinControl;
const AParams: TCreateParams): TLCLHandle; override;
class function GetDefaultClientRect(const AWinControl: TWinControl;
const {%H-}aLeft, {%H-}aTop, aWidth, aHeight: integer; var aClientRect: TRect
): boolean; override;
class procedure AddPage(const ATabControl: TCustomTabControl;
const AChild: TCustomPage; const AIndex: integer); override;
class procedure MovePage(const ATabControl: TCustomTabControl;
const AChild: TCustomPage; const NewIndex: integer); override;
class procedure RemovePage(const ATabControl: TCustomTabControl;
const AIndex: integer); override;
class function GetNotebookMinTabHeight(const AWinControl: TWinControl
): integer; override;
class function GetNotebookMinTabWidth(const AWinControl: TWinControl
): integer; override;
class function GetCapabilities: TCTabControlCapabilities; override;
class function GetDesignInteractive(const AWinControl: TWinControl; AClientPos: TPoint): Boolean; override;
class function GetTabIndexAtPos(const ATabControl: TCustomTabControl; const AClientPos: TPoint): integer; override;
class function GetTabRect(const ATabControl: TCustomTabControl; const AIndex: Integer): TRect; override;
class procedure SetPageIndex(const ATabControl: TCustomTabControl; const AIndex: integer); override;
class procedure SetTabCaption(const ATabControl: TCustomTabControl; const AChild: TCustomPage; const AText: string); override;
class procedure SetTabPosition(const ATabControl: TCustomTabControl; const ATabPosition: TTabPosition); override;
class procedure SetTabSize(const ATabControl: TCustomTabControl; const ATabWidth, ATabHeight: integer); override;
class procedure ShowTabs(const ATabControl: TCustomTabControl; AShowTabs: boolean); override;
class procedure UpdateProperties(const ATabControl: TCustomTabControl); override;
end;
{ TQtWSStatusBar }
TQtWSStatusBar = class(TWSStatusBar)
protected
class procedure ClearPanels(const Widget: TQtStatusBar);
class procedure RecreatePanels(const AStatusBar: TStatusBar; const Widget: TQtStatusBar);
published
class function CreateHandle(const AWinControl: TWinControl; const AParams: TCreateParams): TLCLHandle; override;
class procedure DestroyHandle(const AWinControl: TWinControl); override;
class procedure PanelUpdate(const AStatusBar: TStatusBar; PanelIndex: integer); override;
class procedure SetPanelText(const AStatusBar: TStatusBar; PanelIndex: integer); override;
class procedure SetSizeGrip(const AStatusBar: TStatusBar; SizeGrip: Boolean); override;
class procedure Update(const AStatusBar: TStatusBar); override;
end;
{ TQtWSTabSheet }
TQtWSTabSheet = class(TWSTabSheet)
published
end;
{ TQtWSPageControl }
TQtWSPageControl = class(TWSPageControl)
published
end;
{ TQtWSCustomListView }
TQtWSCustomListView = class(TWSCustomListView)
protected
class function IsIconView(const AList: TCustomListView): boolean;
class procedure InternalUpdateItems(const AList: TCustomListView);
class procedure GetCurrentImages(const ALV: TCustomListView;
out AImgListRes: TScaledImageListResolution);
published
class function CreateHandle(const AWinControl: TWinControl;
const AParams: TCreateParams): TLCLHandle; override;
class procedure ColumnDelete(const ALV: TCustomListView; const AIndex: Integer); override;
class procedure ColumnInsert(const ALV: TCustomListView; const AIndex: Integer; const AColumn: TListColumn); override;
class function ColumnGetWidth(const ALV: TCustomListView; const AIndex: Integer; const AColumn: TListColumn): Integer; override;
class procedure ColumnSetWidth(const ALV: TCustomListView; const AIndex: Integer; const AColumn: TListColumn; const AWidth: Integer); override;
class procedure ColumnSetVisible(const ALV: TCustomListView; const AIndex: Integer; const AColumn: TListColumn; const AVisible: Boolean); override;
class procedure ColumnSetAlignment(const ALV: TCustomListView; const AIndex: Integer; const AColumn: TListColumn; const AAlignment: TAlignment); override;
class procedure ColumnSetAutoSize(const ALV: TCustomListView; const AIndex: Integer; const AColumn: TListColumn; const AAutoSize: Boolean); override;
class procedure ColumnSetCaption(const ALV: TCustomListView; const AIndex: Integer; const AColumn: TListColumn; const ACaption: String); override;
class procedure ColumnSetImage(const ALV: TCustomListView; const AIndex: Integer; const AColumn: TListColumn; const AImageIndex: Integer); override;
class procedure ColumnSetMinWidth(const ALV: TCustomListView; const AIndex: Integer; const AColumn: TListColumn; const AMinWidth: integer); override;
class procedure ColumnMove(const ALV: TCustomListView; const AOldIndex, ANewIndex: Integer; const AColumn: TListColumn); override;
class procedure ColumnSetSortIndicator(const ALV: TCustomListView; const AIndex: Integer;
const AColumn: TListColumn; const ASortIndicator: TSortIndicator);
override;
{items}
class procedure ItemInsert(const ALV: TCustomListView; const AIndex: Integer; const AItem: TListItem); override;
class procedure ItemDelete(const ALV: TCustomListView; const AIndex: Integer); override;
class procedure ItemExchange(const ALV: TCustomListView; AItem: TListItem; const AIndex1, AIndex2: Integer); override;
class procedure ItemMove(const ALV: TCustomListView; AItem: TListItem; const AFromIndex, AToIndex: Integer); override;
class function ItemGetChecked(const ALV: TCustomListView; const AIndex: Integer; const AItem: TListItem): Boolean; override;
class procedure ItemSetChecked(const ALV: TCustomListView; const AIndex: Integer; const AItem: TListItem; const AChecked: Boolean); override;
class function ItemGetPosition(const ALV: TCustomListView; const AIndex: Integer): TPoint; override;
class function ItemGetState(const ALV: TCustomListView; const AIndex: Integer; const AItem: TListItem; const AState: TListItemState; out AIsSet: Boolean): Boolean; override; // returns True if supported
class procedure ItemSetImage(const ALV: TCustomListView; const AIndex: Integer; const AItem: TListItem; const ASubIndex, AImageIndex: Integer); override;
class procedure ItemSetState(const ALV: TCustomListView; const AIndex: Integer; const AItem: TListItem; const AState: TListItemState; const AIsSet: Boolean); override;
class procedure ItemSetStateImage(const ALV: TCustomListView; const AIndex: Integer; const AItem: TListItem; const ASubIndex, AStateImageIndex: Integer); override;
class procedure ItemSetText(const ALV: TCustomListView; const AIndex: Integer; const AItem: TListItem; const ASubIndex: Integer; const AText: String); override;
class procedure ItemShow(const ALV: TCustomListView; const AIndex: Integer; const AItem: TListItem; const PartialOK: Boolean); override;
class function ItemDisplayRect(const ALV: TCustomListView; const AIndex, ASubItem: Integer; ACode: TDisplayCode): TRect; override;
{parent}
class procedure BeginUpdate(const ALV: TCustomListView); override;
class procedure EndUpdate(const ALV: TCustomListView); override;
class function GetFocused(const ALV: TCustomListView): Integer; override;
class function GetHitTestInfoAt( const ALV: TCustomListView; X, Y: Integer ) : THitTests; override;
class function GetItemAt(const ALV: TCustomListView; x,y: integer): Integer; override;
class function GetSelCount(const ALV: TCustomListView): Integer; override;
class function GetSelection(const ALV: TCustomListView): Integer; override;
class function GetTopItem(const ALV: TCustomListView): Integer; override;
class procedure SetSort(const ALV: TCustomListView; const AType: TSortType; const AColumn: Integer;
const ASortDirection: TSortDirection); override;
class function GetBoundingRect(const ALV: TCustomListView): TRect; override;
class function GetViewOrigin(const ALV: TCustomListView): TPoint; override;
class function GetVisibleRowCount(const ALV: TCustomListView): Integer; override;
class function RestoreItemCheckedAfterSort(const ALV: TCustomListView): Boolean; override;
class procedure SelectAll(const ALV: TCustomListView; const AIsSet: Boolean); override;
class procedure SetAllocBy(const ALV: TCustomListView; const AValue: Integer); override;
class procedure SetIconArrangement(const ALV: TCustomListView; const AValue: TIconArrangement); override;
class procedure SetImageList(const ALV: TCustomListView; const AList: TListViewImageList; const AValue: TCustomImageListResolution); override;
class procedure SetItemsCount(const ALV: TCustomListView; const Avalue: Integer); override;
class procedure SetOwnerData(const ALV: TCustomListView; const AValue: Boolean); override;
class procedure SetProperty(const ALV: TCustomListView; const AProp: TListViewProperty; const AIsSet: Boolean); override;
class procedure SetProperties(const ALV: TCustomListView; const AProps: TListViewProperties); override;
class procedure SetScrollBars(const ALV: TCustomListView; const AValue: TScrollStyle); override;
class procedure SetViewStyle(const ALV: TCustomListView; const Avalue: TViewStyle); override;
(*
// Column
class procedure ColumnSetMaxWidth(const ALV: TCustomListView; const AIndex: Integer; const AColumn: TListColumn; const AMaxWidth: Integer); override;
// Item
class function ItemSetPosition(const ALV: TCustomListView; const AIndex: Integer; const ANewPosition: TPoint): Boolean; virtual;
// LV
class function GetDropTarget(const ALV: TCustomListView): Integer; virtual;
class function GetHoverTime(const ALV: TCustomListView): Integer; virtual;
class function GetViewOrigin(const ALV: TCustomListView): TPoint; virtual;
class procedure SetDefaultItemHeight(const ALV: TCustomListView; const AValue: Integer); virtual;
class procedure SetHotTrackStyles(const ALV: TCustomListView; const AValue: TListHotTrackStyles); virtual;
class procedure SetHoverTime(const ALV: TCustomListView; const AValue: Integer); virtual;
class procedure SetImageList(const ALV: TCustomListView; const AList: TListViewImageList; const AValue: TCustomImageList); virtual;
class procedure SetViewOrigin(const ALV: TCustomListView; const AValue: TPoint); virtual;
*)
end;
{ TQtWSListView }
TQtWSListView = class(TWSListView)
published
end;
{ TQtWSProgressBar }
TQtWSProgressBar = class(TWSProgressBar)
protected
class procedure SetRangeStyle(AProgressBar: TQtProgressBar;
AStyle: TProgressBarStyle; AMin, AMax: Integer; const AIsDesign: Boolean);
published
class function CreateHandle(const AWinControl: TWinControl; const AParams: TCreateParams): TLCLHandle; override;
class procedure ApplyChanges(const AProgressBar: TCustomProgressBar); override;
class procedure SetPosition(const AProgressBar: TCustomProgressBar; const NewPosition: integer); override;
class procedure SetStyle(const AProgressBar: TCustomProgressBar; const NewStyle: TProgressBarStyle); override;
end;
{ TQtWSCustomUpDown }
TQtWSCustomUpDown = class(TWSCustomUpDown)
published
end;
{ TQtWSUpDown }
TQtWSUpDown = class(TWSUpDown)
published
end;
{ TQtWSToolButton }
TQtWSToolButton = class(TWSToolButton)
published
end;
{ TQtWSToolBar }
TQtWSToolBar = class(TWSToolBar)
published
class function CreateHandle(const AWinControl: TWinControl; const AParams: TCreateParams): TLCLHandle; override;
end;
{ TQtWSTrackBar }
TQtWSTrackBar = class(TWSTrackBar)
published
class function CreateHandle(const AWinControl: TWinControl; const AParams: TCreateParams): TLCLHandle; override;
class procedure ApplyChanges(const ATrackBar: TCustomTrackBar); override;
class function GetPosition(const ATrackBar: TCustomTrackBar): integer; override;
class procedure SetPosition(const ATrackBar: TCustomTrackBar; const NewPosition: integer); override;
class procedure SetOrientation(const ATrackBar: TCustomTrackBar; const AOrientation: TTrackBarOrientation); override;
end;
{ TQtWSCustomTreeView }
TQtWSCustomTreeView = class(TWSCustomTreeView)
published
end;
{ TQtWSTreeView }
TQtWSTreeView = class(TWSTreeView)
published
end;
implementation
uses qtint, math;
{$include qtpagecontrol.inc}
const
TickMarkToQtSliderTickPositionMap: array[TTickMark] of QSliderTickPosition =
(
{tmBottomRight} QSliderTicksBelow,
{tmTopLeft } QSliderTicksAbove,
{tmBoth } QSliderTicksBothSides
);
TrackBarOrientationToQtOrientationMap: array[TTrackBarOrientation] of QtOrientation =
(
{trHorizontal} QtHorizontal,
{trVertical } QtVertical
);
AlignmentToQtAlignmentMap: array[TAlignment] of QtAlignment =
(
{taLeftJustify } QtAlignLeft,
{taRightJustify} QtAlignRight,
{taCenter } QtAlignCenter
);
IconArngToQListFlow: array[TIconArrangement] of QListViewFlow =
(
{iaTop} QListViewLeftToRight,
{iaLeft}QListViewTopToBottom
);
{ TQtWSToolBar }
class function TQtWSToolBar.CreateHandle(const AWinControl: TWinControl; const AParams: TCreateParams): TLCLHandle;
var
QtToolBar: TQtCustomControl;
begin
{$note TToolBar implementation under LCL is wrong. TToolBar isn't
TCustomControl but TWinControl.
To avoid theoretical crashes we use TQtCustomControl here, but indeed it
should be TQtWidget - so no viewport.}
QtToolBar := TQtCustomControl.Create(AWinControl, AParams);
QtToolBar.setFrameShape(QFrameNoFrame);
QtToolBar.viewportNeeded;
QtToolBar.setFocusPolicy(QtTabFocus);
QtToolBar.AttachEvents;
Result := TLCLHandle(QtToolBar);
end;
{ TQtWSTrackBar }
class function TQtWSTrackBar.CreateHandle(const AWinControl: TWinControl; const AParams: TCreateParams): TLCLHandle;
var
QtTrackBar: TQtTrackBar;
begin
QtTrackBar := TQtTrackBar.Create(AWinControl, AParams);
QtTrackBar.AttachEvents;
Result := TLCLHandle(QtTrackBar);
end;
function TrackBarReversed(const ATrackBar: TCustomTrackBar;
const AQtTrackBar: TQtTrackBar): Boolean;
begin
Result :=
((ATrackBar.Orientation = trHorizontal) and
(AQtTrackbar.getInvertedAppereance <> ATrackBar.Reversed))
or
((ATrackBar.Orientation = trVertical) and
(AQtTrackbar.getInvertedAppereance <> not ATrackBar.Reversed))
end;
class procedure TQtWSTrackBar.ApplyChanges(const ATrackBar: TCustomTrackBar);
var
QtTrackBar: TQtTrackBar;
begin
if not WSCheckHandleAllocated(ATrackBar, 'ApplyChanges') then
Exit;
QtTrackBar := TQtTrackBar(ATrackBar.Handle);
QtTrackBar.BeginUpdate;
try
QtTrackBar.setRange(ATrackBar.Min, ATrackBar.Max);
if ATrackBar.TickStyle = tsNone then
QtTrackBar.SetTickPosition(QSliderNoTicks)
else
QtTrackBar.SetTickPosition(TickMarkToQtSliderTickPositionMap[ATrackBar.TickMarks]);
if QtTrackBar.getPageStep <> ATrackBar.PageSize then
QtTrackBar.setPageStep(ATrackBar.PageSize);
if QtTrackBar.getSingleStep <> ATrackBar.LineSize then
QtTrackBar.setSingleStep(ATrackBar.LineSize);
if QtTrackBar.getTickInterval <> ATrackBar.Frequency then
QtTrackBar.setTickInterval(ATrackBar.Frequency);
if QtTrackBar.getSliderPosition <> ATrackBar.Position then
QtTrackBar.setSliderPosition(ATrackBar.Position);
if (QtTrackBar.getOrientation <>
TrackBarOrientationToQtOrientationMap[ATrackBar.Orientation])
or TrackBarReversed(ATrackBar, QtTrackBar) then
begin
QtTrackBar.Hide;
QtTrackBar.setOrientation(TrackBarOrientationToQtOrientationMap[ATrackBar.Orientation]);
if ATrackBar.Orientation = trHorizontal then
QtTrackBar.setInvertedAppereance(ATrackBar.Reversed)
else
{make it delphi and msdn compatibile when vertical then 0 = top}
QtTrackBar.setInvertedAppereance(not ATrackBar.Reversed);
QtTrackBar.setInvertedControls(False);
QtTrackBar.Show;
end;
finally
QtTrackBar.EndUpdate;
end;
end;
class function TQtWSTrackBar.GetPosition(const ATrackBar: TCustomTrackBar): integer;
var
QtTrackBar: TQtTrackBar;
begin
Result := 0;
if not WSCheckHandleAllocated(ATrackBar, 'GetPosition') then
Exit;
QtTrackBar := TQtTrackBar(ATrackBar.Handle);
Result := QtTrackBar.getSliderPosition;
end;
class procedure TQtWSTrackBar.SetPosition(const ATrackBar: TCustomTrackBar; const NewPosition: integer);
var
QtTrackBar: TQtTrackBar;
begin
if not WSCheckHandleAllocated(ATrackBar, 'SetPosition') then
Exit;
QtTrackBar := TQtTrackBar(ATrackBar.Handle);
QtTrackBar.BeginUpdate;
try
QtTrackBar.setSliderPosition(NewPosition);
finally
QtTrackBar.EndUpdate;
end;
end;
class procedure TQtWSTrackBar.SetOrientation(const ATrackBar: TCustomTrackBar;
const AOrientation: TTrackBarOrientation);
var
QtTrackBar: TQtTrackBar;
begin
if not WSCheckHandleAllocated(ATrackBar, 'SetOrientation') then
Exit;
QtTrackBar := TQtTrackBar(ATrackBar.Handle);
QtTrackBar.BeginUpdate;
try
if (QtTrackBar.getOrientation <>
TrackBarOrientationToQtOrientationMap[ATrackBar.Orientation])
or TrackBarReversed(ATrackBar, QtTrackBar) then
begin
QtTrackBar.Hide;
QtTrackBar.setOrientation(TrackBarOrientationToQtOrientationMap[ATrackBar.Orientation]);
if ATrackBar.Orientation = trHorizontal then
QtTrackBar.setInvertedAppereance(ATrackBar.Reversed)
else
{make it delphi and msdn compatibile when vertical then 0 = top}
QtTrackBar.setInvertedAppereance(not ATrackBar.Reversed);
QtTrackBar.setInvertedControls(False);
QtTrackBar.Show;
end;
finally
QtTrackBar.EndUpdate;
end;
end;
{ TQtWSProgressBar }
class procedure TQtWSProgressBar.SetRangeStyle(AProgressBar: TQtProgressBar;
AStyle: TProgressBarStyle; AMin, AMax: Integer; const AIsDesign: Boolean);
begin
if AStyle = pbstNormal then
begin
if (AMin = 0) and (AMax = 0) then
AProgressBar.setRange(0, 1)
else
AProgressBar.setRange(AMin, AMax)
end
else
AProgressBar.setRange(0, Integer(AIsDesign));
end;
class function TQtWSProgressBar.CreateHandle(const AWinControl: TWinControl; const AParams: TCreateParams): TLCLHandle;
var
QtProgressBar: TQtProgressBar;
begin
QtProgressBar := TQtProgressBar.Create(AWinControl, AParams);
QtProgressBar.AttachEvents;
Result := TLCLHandle(QtProgressBar);
end;
class procedure TQtWSProgressBar.ApplyChanges(const AProgressBar: TCustomProgressBar);
var
QtProgressBar: TQtProgressBar;
begin
QtProgressBar := TQtProgressBar(AProgressBar.Handle);
// AProgressBar.Smooth is not supported by qt
case AProgressBar.Orientation of
pbVertical:
begin
QtProgressBar.setOrientation(QtVertical);
QtProgressBar.setInvertedAppearance(False);
end;
pbRightToLeft:
begin
QtProgressBar.setOrientation(QtHorizontal);
QtProgressBar.setInvertedAppearance(True);
end;
pbTopDown:
begin
QtProgressBar.setOrientation(QtVertical);
QtProgressBar.setInvertedAppearance(True);
end;
else { pbHorizontal is default }
begin
QtProgressBar.setOrientation(QtHorizontal);
QtProgressBar.setInvertedAppearance(False);
end;
end;
QtProgressBar.setTextVisible(AProgressBar.BarShowText);
// The position, minumum and maximum values
SetRangeStyle(QtProgressBar, AProgressBar.Style,
AProgressBar.Min, AProgressBar.Max,
csDesigning in AProgressBar.ComponentState);
QtProgressBar.BeginUpdate;
QtProgressBar.setValue(AProgressBar.Position);
QtProgressBar.EndUpdate;
end;
class procedure TQtWSProgressBar.SetPosition(const AProgressBar: TCustomProgressBar; const NewPosition: integer);
begin
TQtProgressBar(AProgressBar.Handle).BeginUpdate;
TQtProgressBar(AProgressBar.Handle).setValue(NewPosition);
TQtProgressBar(AProgressBar.Handle).EndUpdate;
end;
class procedure TQtWSProgressBar.SetStyle(
const AProgressBar: TCustomProgressBar; const NewStyle: TProgressBarStyle);
var
QProgressBar: TQtProgressBar;
begin
if not WSCheckHandleAllocated(AProgressBar, 'SetStyle') then
Exit;
QProgressBar := TQtProgressBar(AProgressBar.Handle);
QProgressBar.reset;
SetRangeStyle(QProgressBar, NewStyle, AProgressBar.Min, AProgressBar.Max,
csDesigning in AProgressBar.ComponentState);
if NewStyle = pbstNormal then
QProgressBar.setValue(AProgressBar.Position);
end;
{ TQtWSStatusBar }
class procedure TQtWSStatusBar.ClearPanels(const Widget: TQtStatusBar);
var
i: integer;
begin
if length(Widget.Panels) > 0 then
begin
Widget.setUpdatesEnabled(False);
for i := High(Widget.Panels) downto 0 do
begin
Widget.removeWidget(Widget.Panels[i].Widget);
Widget.Panels[i].DetachEvents;
QLabel_destroy(QLabelH(Widget.Panels[i].Widget));
Widget.Panels[i].Widget := nil;
Widget.Panels[i].Free;
end;
Widget.setUpdatesEnabled(True);
SetLength(Widget.Panels, 0);
end;
end;
class procedure TQtWSStatusBar.RecreatePanels(const AStatusBar: TStatusBar;
const Widget: TQtStatusBar);
var
Str: WideString;
i: Integer;
begin
// issues #18683 and #28307
QStatusBar_clearMessage(QStatusBarH(Widget.Widget));
ClearPanels(Widget);
if AStatusBar.SimplePanel then
begin
Str := AStatusBar{%H-}.SimpleText;
Widget.showMessage(@Str);
end else
if AStatusBar.Panels.Count > 0 then
begin
Widget.setUpdatesEnabled(False);
SetLength(Widget.Panels, AStatusBar.Panels.Count);
for i := 0 to AStatusBar.Panels.Count - 1 do
begin
Str := AStatusBar{%H-}.Panels[i].Text;
Widget.Panels[i] := TQtStatusBarPanel.CreateFrom(AStatusBar,
QLabel_create(@Str, Widget.Widget));
Widget.Panels[i].HasPaint := AStatusBar.Panels[i].Style = psOwnerDraw;
Widget.Panels[i].ID := AStatusBar.Panels[i].ID;
QLabel_setText(QLabelH(Widget.Panels[i].Widget), @Str);
QLabel_setAlignment(QLabelH(Widget.Panels[i].Widget),
AlignmentToQtAlignmentMap[AStatusBar.Panels[i].Alignment]);
QWidget_setMinimumWidth(Widget.Panels[i].Widget, Max(0, AStatusBar.Panels[i].Width));
QWidget_setVisible(Widget.Panels[i].Widget,
AStatusBar.Panels[i].Width > 0);
Widget.Panels[i].AttachEvents;
Widget.addWidget(Widget.Panels[i].Widget, ord(i = AStatusBar.Panels.Count - 1));
end;
Widget.setUpdatesEnabled(True);
end;
end;
class function TQtWSStatusBar.CreateHandle(const AWinControl: TWinControl; const AParams: TCreateParams): TLCLHandle;
var
QtStatusBar: TQtStatusBar;
begin
QtStatusBar := TQtStatusBar.Create(AWinControl, AParams);
QtStatusBar.setSizeGripEnabled(TStatusBar(AWinControl).SizeGrip and
TStatusBar(AWinControl).SizeGripEnabled);
RecreatePanels(TStatusBar(AWinControl), QtStatusBar);
QtStatusBar.AttachEvents;
// Return handle
Result := TLCLHandle(QtStatusBar);
end;
class procedure TQtWSStatusBar.DestroyHandle(const AWinControl: TWinControl);
var
QtStatusBar: TQtStatusBar;
begin
QtStatusBar := TQtStatusBar(AWinControl.Handle);
ClearPanels(QtStatusBar);
QtStatusBar.Release;
end;
class procedure TQtWSStatusBar.PanelUpdate(const AStatusBar: TStatusBar; PanelIndex: integer);
var
QtStatusBar: TQtStatusBar;
Str: Widestring;
begin
QtStatusBar := TQtStatusBar(AStatusBar.Handle);
if AStatusBar.SimplePanel then
begin
ClearPanels(QtStatusBar);
Str := AStatusBar{%H-}.SimpleText;
QtStatusBar.showMessage(@Str);
end else
if AStatusBar.Panels.Count > 0 then
begin
QStatusBar_clearMessage(QStatusBarH(QtStatusBar.Widget));
if (PanelIndex >= Low(QtStatusBar.Panels)) and
(PanelIndex <= High(QtStatusBar.Panels)) then
begin
Str := AStatusBar{%H-}.Panels[PanelIndex].Text;
QLabel_setText(QLabelH(QtStatusBar.Panels[PanelIndex].Widget), @Str);
QLabel_setAlignment(QLabelH(QtStatusBar.Panels[PanelIndex].Widget),
AlignmentToQtAlignmentMap[AStatusBar.Panels[PanelIndex].Alignment]);
QWidget_setMinimumWidth(QtStatusBar.Panels[PanelIndex].Widget,
Max(0, AStatusBar.Panels[PanelIndex].Width));
QWidget_setVisible(QtStatusBar.Panels[PanelIndex].Widget,
AStatusBar.Panels[PanelIndex].Width > 0);
end;
end;
end;
class procedure TQtWSStatusBar.SetPanelText(const AStatusBar: TStatusBar; PanelIndex: integer);
var
QtStatusBar: TQtStatusBar;
Str: Widestring;
begin
QtStatusBar := TQtStatusBar(AStatusBar.Handle);
if AStatusBar.SimplePanel then
begin
Str := AStatusBar{%H-}.SimpleText;
QtStatusBar.showMessage(@Str);
end else
begin
if (PanelIndex >= Low(QtStatusBar.Panels)) and
(PanelIndex <= High(QtStatusBar.Panels)) then
begin
Str := AStatusBar{%H-}.Panels[PanelIndex].Text;
QLabel_setText(QLabelH(QtStatusBar.Panels[PanelIndex].Widget), @Str);
end;
end;
end;
class procedure TQtWSStatusBar.SetSizeGrip(const AStatusBar: TStatusBar;
SizeGrip: Boolean);
var
QtStatusBar: TQtStatusBar;
begin
if not WSCheckHandleAllocated(AStatusBar, 'SetSizeGrip') then
Exit;
QtStatusBar := TQtStatusBar(AStatusBar.Handle);
QtStatusBar.setSizeGripEnabled(SizeGrip and AStatusBar.SizeGripEnabled);
end;
class procedure TQtWSStatusBar.Update(const AStatusBar: TStatusBar);
var
QtStatusBar: TQtStatusBar;
begin
QtStatusBar := TQtStatusBar(AStatusBar.Handle);
RecreatePanels(AStatusBar, QtStatusBar);
end;
{ TQtWSCustomListView }
type
TCustomListViewHack = class(TCustomListView);
class function TQtWSCustomListView.IsIconView(const AList: TCustomListView): boolean;
begin
Result := TCustomListViewHack(AList).ViewStyle <> vsReport;
end;
{------------------------------------------------------------------------------
Method: TQtWSCustomListView.CreateHandle
Params: None
Returns: Nothing
------------------------------------------------------------------------------}
class function TQtWSCustomListView.CreateHandle(const AWinControl: TWinControl;
const AParams: TCreateParams): TLCLHandle;
var
QtTreeWidget: TQtTreeWidget;
QtListWidget: TQtListWidget;
ALV: TCustomListViewHack;
begin
ALV := TCustomListViewHack(AWinControl);
if IsIconView(TCustomListView(AWinControl)) then
begin
QtListWidget := TQtListWidget.Create(AWinControl, AParams);
QtListWidget.ViewStyle := Ord(TCustomListViewHack(AWinControl).ViewStyle);
if TCustomListViewHack(AWinControl).ViewStyle in [vsIcon, vsSmallIcon] then
begin
// emabarcadero docs says
// vsIcon, vsSmallIcon
// Each item appears as a full-sized icon with a label below it.
// The user can drag the items to any location in the list view window.
QtListWidget.setViewMode(QListViewIconMode);
QtListWidget.setResizeMode(QListViewAdjust);
QtListWidget.setMovement(QListViewFree);
with TCustomListView(AWinControl) do
begin
QtListWidget.setWrapping(IconOptions.AutoArrange);
QtListWidget.setViewFlow(IconArngToQListFlow[IconOptions.Arrangement]);
QtListWidget.setWordWrap(IconOptions.WrapText);
QtListWidget.setUniformItemSizes(IconOptions.WrapText);
end;
if ALV.ViewStyle = vsIcon then
begin
if Assigned(ALV.LargeImages) then
QtListWidget.IconSize := Size(ALV.LargeImages.Width, ALV.LargeImages.Height);
end;
end else
QtListWidget.setViewMode(QListViewListMode);
QtListWidget.Checkable := TCustomListView(AWinControl).Checkboxes;
QtListWidget.OwnerDrawn := ALV.IsCustomDrawn(dtControl, cdPrePaint);
QtListWidget.AttachEvents;
Result := TLCLHandle(QtListWidget);
end else
begin
QtTreeWidget := TQtTreeWidget.Create(AWinControl, AParams);
QtTreeWidget.ViewStyle := Ord(TCustomListViewHack(AWinControl).ViewStyle);
QtTreeWidget.OwnerDrawn := ALV.IsCustomDrawn(dtControl, cdPrePaint) or (ALV.OwnerDraw and
(ALV.ViewStyle = vsReport));
QtTreeWidget.setStretchLastSection(ALV.AutoWidthLastColumn);
QTreeView_setItemsExpandable(QTreeViewH(QtTreeWidget.Widget), False);
QtTreeWidget.setRootIsDecorated(False);
QtTreeWidget.AttachEvents;
Result := TLCLHandle(QtTreeWidget);
end;
end;
{------------------------------------------------------------------------------
Method: TQtWSCustomListView.ColumnDelete
Params: None
Returns: Nothing
------------------------------------------------------------------------------}
class procedure TQtWSCustomListView.ColumnDelete(const ALV: TCustomListView;
const AIndex: Integer);
begin
if not WSCheckHandleAllocated(ALV, 'ColumnDelete') then
Exit;
// TODO: columns in vsIcon mode
if IsIconView(ALV) then
exit;
// we must recreate handle since there's no column removal support
// in our bindings (protected methods in qt).
RecreateWnd(ALV);
end;
{------------------------------------------------------------------------------
Method: TQtWSCustomListView.ColumnInsert
Params: None
Returns: Nothing
------------------------------------------------------------------------------}
class procedure TQtWSCustomListView.ColumnInsert(const ALV: TCustomListView;
const AIndex: Integer; const AColumn: TListColumn);
var
QtTreeWidget: TQtTreeWidget;
TWI: QTreeWidgetItemH;
TWIChild: QTreeWidgetItemH;
Str: WideString;
begin
if not WSCheckHandleAllocated(ALV, 'ColumnInsert') then
Exit;
// TODO: columns in vsIcon mode
if IsIconView(ALV) then
exit;
QtTreeWidget := TQtTreeWidget(ALV.Handle);
if QtTreeWidget.ColCount <> TCustomListViewHack(ALV).Columns.Count then
QtTreeWidget.ColCount := TCustomListViewHack(ALV).Columns.Count;
if (QtTreeWidget.ColCount <= 1) and TCustomListViewHack(ALV).ShowColumnHeaders then
QtTreeWidget.setHeaderVisible(True);
TWI := QtTreeWidget.headerItem;
if QTreeWidgetItem_childCount(TWI) < (AIndex + 1) then
begin
TWIChild := QTreeWidgetItem_create(Ord(QTreeWidgetItemType));
QTreeWidgetItem_setFlags(TWIChild, QtItemIsEnabled);
QTreeWidgetItem_addChild(TWI, TWIChild);
Str := ALV{%H-}.Column[AIndex].Caption;
QTreeWidgetItem_setText(TWI, AIndex, @Str);
end;
if (csDesigning in ALV.ComponentState) then
exit;
QtTreeWidget.Header.Clickable := TCustomListViewHack(ALV).ColumnClick;
end;
{------------------------------------------------------------------------------
Method: TQtWSCustomListView.ColumnGetWidth
Params: None
Returns: Integer
------------------------------------------------------------------------------}
class function TQtWSCustomListView.ColumnGetWidth(const ALV: TCustomListView;
const AIndex: Integer; const AColumn: TListColumn): Integer;
var
QtTreeWidget: TQtTreeWidget;
begin
if not WSCheckHandleAllocated(ALV, 'ColumnGetWidth') then
Exit(-1);
// TODO: columns in vsIcon mode
if IsIconView(ALV) then
exit(0);
if (TQtWidget(ALV.Handle) is TQtListWidget) then
exit(0);
QtTreeWidget := TQtTreeWidget(ALV.Handle);
{Issue #39353.Such scenario happens only when SetStyle() calls RecreateWnd
while designing control.Default width for TListColumn is 50,
unfortunatelly it''s hardcoded in listcolumn.inc.}
if (csDesigning in ALV.ComponentState) and (QtTreeWidget.ColCount <> ALV.ColumnCount) then
exit(50);
Result := QtTreeWidget.ColWidth[AIndex];
end;
{------------------------------------------------------------------------------
Method: TQtWSCustomListView.ColumnMove
Params: None
Returns: Nothing
------------------------------------------------------------------------------}
class procedure TQtWSCustomListView.ColumnMove(const ALV: TCustomListView;
const AOldIndex, ANewIndex: Integer; const AColumn: TListColumn);
var
QtTreeWidget: TQtTreeWidget;
begin
if not WSCheckHandleAllocated(ALV, 'ColumnMove') then
Exit;
if (csDesigning in ALV.ComponentState) then
exit;
// TODO: columns in vsIcon mode
if IsIconView(ALV) then
exit;
QtTreeWidget := TQtTreeWidget(ALV.Handle);
QtTreeWidget.Header.moveSection(AOldIndex, ANewIndex);
end;
class procedure TQtWSCustomListView.ColumnSetSortIndicator(
const ALV: TCustomListView; const AIndex: Integer;
const AColumn: TListColumn; const ASortIndicator: TSortIndicator);
const
QtSortOrder : array [TSortIndicator] of QtSortOrder = (QtAscendingOrder, QtAscendingOrder, QtDescendingOrder);
var
QtTreeWidget: TQtTreeWidget;
begin
if not WSCheckHandleAllocated(ALV, 'ColumnSetSortIndicator') then
Exit;
if IsIconView(ALV) then
exit;
QtTreeWidget := TQtTreeWidget(ALV.Handle);
if Assigned(QtTreeWidget) and
not (csDesigning in ALV.ComponentState) then
begin
if ASortIndicator = siNone then
QtTreeWidget.Header.SetSortIndicatorVisible(false)
else
begin
QtTreeWidget.Header.SetSortIndicatorVisible(true);
QtTreeWidget.Header.SetSortIndicator(AIndex, QtSortOrder[ASortIndicator]);
end;
end;
end;
{------------------------------------------------------------------------------
Method: TQtWSCustomListView.ColumnSetAlignment
Params: None
Returns: Nothing
------------------------------------------------------------------------------}
class procedure TQtWSCustomListView.ColumnSetAlignment(const ALV: TCustomListView;
const AIndex: Integer; const AColumn: TListColumn; const AAlignment: TAlignment);
var
QtTreeWidget: TQtTreeWidget;
TWI: QTreeWidgetItemH;
i: Integer;
begin
if not WSCheckHandleAllocated(ALV, 'ColumnSetAlignment') then
Exit;
// TODO: columns in vsIcon mode
if IsIconView(ALV) then
exit;
QtTreeWidget := TQtTreeWidget(ALV.Handle);
TWI := QtTreeWidget.headerItem;
QTreeWidgetItem_setTextAlignment(TWI, AIndex,
AlignmentToQtAlignmentMap[AAlignment]);
if not (csLoading in ALV.ComponentState) then
for i := 0 to QtTreeWidget.ItemCount - 1 do
begin
TWI := QtTreeWidget.topLevelItem(i);
if TWI <> nil then
QTreeWidgetItem_setTextAlignment(TWI, AIndex,
AlignmentToQtAlignmentMap[AAlignment]);
end;
end;
{------------------------------------------------------------------------------
Method: TQtWSCustomListView.ColumnSetAutoSize
Params: None
Returns: Nothing
------------------------------------------------------------------------------}
class procedure TQtWSCustomListView.ColumnSetAutoSize(const ALV: TCustomListView;
const AIndex: Integer; const AColumn: TListColumn; const AAutoSize: Boolean);
var
QtTreeWidget: TQtTreeWidget;
begin
if not WSCheckHandleAllocated(ALV, 'ColumnSetAutoSize') then
Exit;
if (csDesigning in ALV.ComponentState) then
exit;
// TODO: columns in vsIcon mode
if IsIconView(ALV) then
exit;
QtTreeWidget := TQtTreeWidget(ALV.Handle);
if AAutoSize then
QtTreeWidget.Header.setResizeMode(AIndex, QHeaderViewResizeToContents)
else
QtTreeWidget.Header.setResizeMode(AIndex, QHeaderViewInteractive);
end;
{------------------------------------------------------------------------------
Method: TQtWSCustomListView.ColumnSetCaption
Params: None
Returns: Nothing
------------------------------------------------------------------------------}
class procedure TQtWSCustomListView.ColumnSetCaption(const ALV: TCustomListView;
const AIndex: Integer; const AColumn: TListColumn; const ACaption: String);
var
Str: WideString;
QtTreeWidget: TQtTreeWidget;
TWI: QTreeWidgetItemH;
begin
if not WSCheckHandleAllocated(ALV, 'ColumnSetCaption') then
Exit;
// TODO: columns in vsIcon mode
if IsIconView(ALV) then
exit;
QtTreeWidget := TQtTreeWidget(ALV.Handle);
TWI := QtTreeWidget.headerItem;
if TWI <> NiL then
begin
Str := {%H-}ACaption;
QTreeWidgetItem_setText(TWI, AIndex, @Str);
end;
end;
{------------------------------------------------------------------------------
Method: TQtWSCustomListView.ColumnSetImage
Params: None
Returns: Nothing
------------------------------------------------------------------------------}
class procedure TQtWSCustomListView.ColumnSetImage(const ALV: TCustomListView;
const AIndex: Integer; const AColumn: TListColumn; const AImageIndex: Integer);
var
QtTreeWidget: TQtTreeWidget;
TWI: QTreeWidgetItemH;
Bmp: TBitmap;
ImgListRes: TScaledImageListResolution;
AIcon: QIconH;
begin
if not WSCheckHandleAllocated(ALV, 'ColumnSetImage') then
Exit;
// TODO: columns in vsIcon mode
if IsIconView(ALV) then
exit;
QtTreeWidget := TQtTreeWidget(ALV.Handle);
TWI := QtTreeWidget.headerItem;
if TWI <> NiL then
begin
GetCurrentImages(ALV, ImgListRes);
if ImgListRes.Valid and (ImgListRes.Count > 0) and
((AImageIndex >= 0) and (AImageIndex < ImgListRes.Count)) then
begin
Bmp := TBitmap.Create;
try
ImgListRes.GetBitmap(AImageIndex, Bmp);
AIcon := TQtImage(Bmp.Handle).AsIcon;
QTreeWidgetItem_setIcon(TWI, AIndex, AIcon);
QIcon_destroy(AIcon);
finally
Bmp.Free;
end;
end;
end;
end;
{------------------------------------------------------------------------------
Method: TQtWSCustomListView.ColumnSetMinWidth
Params: None
Returns: Nothing
------------------------------------------------------------------------------}
class procedure TQtWSCustomListView.ColumnSetMinWidth(const ALV: TCustomListView;
const AIndex: Integer; const AColumn: TListColumn; const AMinWidth: integer);
var
QtTreeWidget: TQtTreeWidget;
begin
if not WSCheckHandleAllocated(ALV, 'ColumnSetMinWidth') then
Exit;
// TODO: columns in vsIcon mode
if IsIconView(ALV) then
exit;
QtTreeWidget := TQtTreeWidget(ALV.Handle);
QtTreeWidget.MinColSize[AIndex] := AMinWidth;
end;
{------------------------------------------------------------------------------
Method: TQtWSCustomListView.ColumnSetWidth
Params: None
Returns: Nothing
------------------------------------------------------------------------------}
class procedure TQtWSCustomListView.ColumnSetWidth(const ALV: TCustomListView;
const AIndex: Integer; const AColumn: TListColumn; const AWidth: Integer);
var
QtTreeWidget: TQtTreeWidget;
begin
if not WSCheckHandleAllocated(ALV, 'ColumnSetWidth') then
Exit;
// TODO: columns in vsIcon mode
if IsIconView(ALV) then
exit;
QtTreeWidget := TQtTreeWidget(ALV.Handle);
QtTreeWidget.ColWidth[AIndex] := AWidth;
end;
{------------------------------------------------------------------------------
Method: TQtWSCustomListView.ColumnSetVisible
Params: None
Returns: Nothing
------------------------------------------------------------------------------}
class procedure TQtWSCustomListView.ColumnSetVisible(const ALV: TCustomListView;
const AIndex: Integer; const AColumn: TListColumn; const AVisible: Boolean);
var
QtTreeWidget: TQtTreeWidget;
begin
if not WSCheckHandleAllocated(ALV, 'ColumnSetVisible') then
Exit;
// TODO: columns in vsIcon mode
if IsIconView(ALV) then
exit;
QtTreeWidget := TQtTreeWidget(ALV.Handle);
QtTreeWidget.ColVisible[AIndex] := AVisible;
end;
{------------------------------------------------------------------------------
Method: TQtWSCustomListView.ItemDelete
Params: None
Returns: Nothing
------------------------------------------------------------------------------}
class procedure TQtWSCustomListView.ItemDelete(const ALV: TCustomListView;
const AIndex: Integer);
var
QtTreeWidget: TQtTreeWidget;
begin
if not WSCheckHandleAllocated(ALV, 'ItemDelete') then
Exit;
if IsIconView(ALV) then
TQtListWidget(ALV.Handle).removeItem(AIndex)
else
begin
TQtListWidget(ALV.Handle).BeginUpdate;
try
QtTreeWidget := TQtTreeWidget(ALV.Handle);
QtTreeWidget.DeleteItem(AIndex);
finally
TQtListWidget(ALV.Handle).EndUpdate;
end;
end;
end;
class procedure TQtWSCustomListView.ItemExchange(const ALV: TCustomListView;
AItem: TListItem; const AIndex1, AIndex2: Integer);
var
QtTreeWidget: TQtTreeWidget;
QtListWidget: TQtListWidget;
begin
if not WSCheckHandleAllocated(ALV, 'ItemExchange') then
Exit;
if IsIconView(ALV) then
begin
QtListWidget := TQtListWidget(ALV.Handle);
QtListWidget.BeginUpdate;
QtListWidget.ExchangeItems(AIndex1, AIndex2);
QtListWidget.EndUpdate;
end else
begin
QtTreeWidget := TQtTreeWidget(ALV.Handle);
QtTreeWidget.BeginUpdate;
QtTreeWidget.ExchangeItems(AIndex1, AIndex2);
QtTreeWidget.EndUpdate;
end;
end;
class procedure TQtWSCustomListView.ItemMove(const ALV: TCustomListView;
AItem: TListItem; const AFromIndex, AToIndex: Integer);
var
QtTreeWidget: TQtTreeWidget;
QtListWidget: TQtListWidget;
begin
if not WSCheckHandleAllocated(ALV, 'ItemMove') then
Exit;
if IsIconView(ALV) then
begin
QtListWidget := TQtListWidget(ALV.Handle);
QtListWidget.BeginUpdate;
QtListWidget.MoveItem(AFromIndex, AToIndex);
QtListWidget.EndUpdate;
end else
begin
QtTreeWidget := TQtTreeWidget(ALV.Handle);
QtTreeWidget.BeginUpdate;
QtTreeWidget.MoveItem(AFromIndex, AToIndex);
QtTreeWidget.EndUpdate;
end;
end;
{------------------------------------------------------------------------------
Method: TQtWSCustomListView.ItemGetChecked
Params: None
Returns: Nothing
------------------------------------------------------------------------------}
class function TQtWSCustomListView.ItemGetChecked(const ALV: TCustomListView;
const AIndex: Integer; const AItem: TListItem): Boolean;
var
QtTreeWidget: TQtTreeWidget;
LWI: QListWidgetItemH;
AState: QtCheckState;
begin
if not WSCheckHandleAllocated(ALV, 'ItemGetChecked') then
Exit(False);
Result := ALV.CheckBoxes;
if not Result then
exit;
if IsIconView(ALV) then
begin
AState := QtUnChecked;
LWI := TQtListWidget(ALV.Handle).getItem(AIndex);
if LWI <> nil then
AState := TQtListWidget(ALV.Handle).GetItemLastCheckState(LWI);
Result := AState = QtChecked;
end else
begin
QtTreeWidget := TQtTreeWidget(ALV.Handle);
Result := QtTreeWidget.ItemChecked[AIndex];
end;
end;
{------------------------------------------------------------------------------
Method: TQtWSCustomListView.ItemGetPosition
Params: None
Returns: TPoint
------------------------------------------------------------------------------}
class function TQtWSCustomListView.ItemGetPosition(const ALV: TCustomListView;
const AIndex: Integer): TPoint;
var
QtListWidget: TQtListWidget;
QtTreeWidget: TQtTreeWidget;
TWI: QTreeWidgetItemH;
R: TRect;
begin
if not WSCheckHandleAllocated(ALV, 'ItemGetPosition') then
Exit(Point(-1,-1));
R := Rect(0, 0, 0, 0);
if IsIconView(ALV) then
begin
QtListWidget := TQtListWidget(ALV.Handle);
R := QtListWidget.getVisualItemRect(QtListWidget.getItem(AIndex));
end else
begin
QtTreeWidget := TQtTreeWidget(ALV.Handle);
TWI := QtTreeWidget.topLevelItem(AIndex);
R := QtTreeWidget.visualItemRect(TWI);
end;
Result.X := R.Left;
Result.Y := R.Top;
end;
{------------------------------------------------------------------------------
Method: TQtWSCustomListView.ItemGetState
Params: None
Returns: TPoint
------------------------------------------------------------------------------}
class function TQtWSCustomListView.ItemGetState(const ALV: TCustomListView;
const AIndex: Integer; const AItem: TListItem;
const AState: TListItemState; out AIsSet: Boolean): Boolean;
var
QtListWidget: TQtListWidget;
LWI: QListWidgetItemH;
QtTreeWidget: TQtTreeWidget;
TWI: QTreeWidgetItemH;
i: Integer;
Arr: TPtrIntArray;
begin
if not WSCheckHandleAllocated(ALV, 'ItemGetState') then
Exit(False);
AIsSet := False;
if IsIconView(ALV) then
begin
QtListWidget := TQtListWidget(ALV.Handle);
LWI := QtListWidget.getItem(AIndex);
if LWI <> nil then
case AState of
lisFocused: AIsSet := LWI = QtListWidget.currentItem;
lisSelected: AIsSet := QtListWidget.getItemSelected(LWI);
end;
end else
begin
QtTreeWidget := TQtTreeWidget(ALV.Handle);
TWI := QtTreeWidget.topLevelItem(AIndex);
if TWI <> nil then
begin
case AState of
lisFocused: AIsSet := TWI = QtTreeWidget.currentItem;
lisSelected:
begin
Arr := QtTreeWidget.selectedItems;
for i := 0 to High(Arr) do
begin
TWI := QTreeWidgetItemH(Arr[i]);
if AIndex = QtTreeWidget.getRow(TWI) then
begin
AIsSet := True;
break;
end;
end;
end;
end;
end;
end;
Result := True;
end;
function CreateTransparentIcon(const AWidth, AHeight: integer): QIconH;
var
APixmap: QPixmapH;
AColor: TQColor;
begin
APixmap := QPixmap_create(AWidth, AHeight);
QColor_fromRgb(PQColor(@AColor), 0, 0, 0, 0);
QPixmap_fill(APixmap, PQColor(@AColor));
Result := QIcon_Create(APixmap);
QPixmap_Destroy(APixmap);
end;
class procedure TQtWSCustomListView.ItemSetImage(const ALV: TCustomListView;
const AIndex: Integer; const AItem: TListItem; const ASubIndex,
AImageIndex: Integer);
var
QtListWidget: TQtListWidget;
LWI: QListWidgetItemH;
QtTreeWidget: TQtTreeWidget;
TWI: QTreeWidgetItemH;
Bmp: TBitmap;
ImgListRes: TScaledImageListResolution;
AIcon: QIconH;
begin
if not WSCheckHandleAllocated(ALV, 'ItemSetImage') then
Exit;
if not Assigned(TCustomListViewHack(ALV).LargeImages) and not
Assigned(TCustomListViewHack(ALV).SmallImages) then
exit;
TWI := nil;
LWI := nil;
if IsIconView(ALV) then
begin
if ASubIndex > 0 then
exit;
QtListWidget := TQtListWidget(ALV.Handle);
LWI := QtListWidget.getItem(AIndex);
end else
begin
QtTreeWidget := TQtTreeWidget(ALV.Handle);
TWI := QtTreeWidget.topLevelItem(AIndex);
end;
if (TWI <> nil) or (LWI <> nil) then
begin
GetCurrentImages(ALV, ImgListRes);
if ImgListRes.Valid and
((AImageIndex >= 0) and (AImageIndex < ImgListRes.Count)) then
begin
Bmp := TBitmap.Create;
try
ImgListRes.GetBitmap(AImageIndex, Bmp);
AIcon := TQtImage(Bmp.Handle).AsIcon;
if LWI <> nil then
QListWidgetItem_setIcon(LWI, AIcon)
else
QTreeWidgetItem_setIcon(TWI, ASubIndex, AIcon);
QIcon_destroy(AIcon);
finally
Bmp.Free;
end;
end else
begin
if Assigned(TCustomListViewHack(ALV).StateImages) and (AItem.StateIndex >= 0) then
exit;
if LWI <> nil then
begin
if ImgListRes.Valid then
begin
AIcon := CreateTransparentIcon(ImgListRes.Width, ImgListRes.Height);
QListWidgetItem_setIcon(LWI, AIcon);
QIcon_Destroy(AIcon);
end else
QListWidgetItem_setIcon(LWI, nil);
end else
QTreeWidgetItem_setIcon(TWI, ASubIndex, nil);
end;
end;
end;
{------------------------------------------------------------------------------
Method: TQtWSCustomListView.ItemSetChecked
Params: None
Returns: Nothing
------------------------------------------------------------------------------}
class procedure TQtWSCustomListView.ItemSetChecked(const ALV: TCustomListView;
const AIndex: Integer; const AItem: TListItem; const AChecked: Boolean);
var
QtListWidget: TQtListWidget;
QtTreeWidget: TQtTreeWidget;
B: Boolean;
begin
if not WSCheckHandleAllocated(ALV, 'ItemSetChecked') then
Exit;
if not ALV.CheckBoxes then
exit;
if IsIconView(ALV) then
begin
QtListWidget := TQtListWidget(ALV.Handle);
B := QtListWidget.GetItemLastCheckState(QtListWidget.getItem(AIndex)) = QtChecked;
if B <> AChecked then
QtListWidget.ItemChecked[AIndex] := AChecked;
end else
begin
QtTreeWidget := TQtTreeWidget(ALV.Handle);
if QtTreeWidget.ItemChecked[AIndex] <> AChecked then
QtTreeWidget.ItemChecked[AIndex] := AChecked;
end;
end;
{------------------------------------------------------------------------------
Method: TQtWSCustomListView.ItemSetState
Params: None
Returns: Nothing
------------------------------------------------------------------------------}
class procedure TQtWSCustomListView.ItemSetState(const ALV: TCustomListView;
const AIndex: Integer; const AItem: TListItem;
const AState: TListItemState; const AIsSet: Boolean);
var
QtListWidget: TQtListWidget;
LWI: QListWidgetItemH;
QtTreeWidget: TQtTreeWidget;
TWI: QTreeWidgetItemH;
begin
if not WSCheckHandleAllocated(ALV, 'ItemSetState') then
Exit;
if IsIconView(ALV) then
begin
QtListWidget := TQtListWidget(ALV.Handle);
LWI := QtListWidget.getItem(AIndex);
QtListWidget.BeginUpdate;
case AState of
lisFocused: QtListWidget.setCurrentItem(LWI, AIsSet);
lisSelected:
begin
if AIsSet and not ALV.MultiSelect then
QtListWidget.setCurrentItem(LWI);
QtListWidget.setItemSelected(LWI, AIsSet);
end;
end;
QtListWidget.EndUpdate;
end else
begin
QtTreeWidget := TQtTreeWidget(ALV.Handle);
if QtTreeWidget.InUpdate then
exit; // issue #40255
TWI := QtTreeWidget.topLevelItem(AIndex);
QtTreeWidget.BeginUpdate;
case AState of
lisFocused: QtTreeWidget.setCurrentItem(TWI);
lisSelected:
begin
if ALV.RowSelect and AIsSet and not ALV.MultiSelect then
QtTreeWidget.setCurrentItem(TWI);
QtTreeWidget.setItemSelected(TWI, AIsSet);
end;
end;
QtTreeWidget.EndUpdate;
end;
end;
class procedure TQtWSCustomListView.ItemSetStateImage(
const ALV: TCustomListView; const AIndex: Integer; const AItem: TListItem;
const ASubIndex, AStateImageIndex: Integer);
var
QtListWidget: TQtListWidget;
LWI: QListWidgetItemH;
QtTreeWidget: TQtTreeWidget;
TWI: QTreeWidgetItemH;
Bmp: TBitmap;
ImgListRes: TScaledImageListResolution;
AImgList: TCustomImageList;
AImgListWidth: Integer;
AIcon: QIconH;
begin
if not WSCheckHandleAllocated(ALV, 'ItemSetStateImage') then
Exit;
if not Assigned(TCustomListViewHack(ALV).StateImages) then
exit;
TWI := nil;
LWI := nil;
if IsIconView(ALV) then
begin
if ASubIndex > 0 then
exit;
QtListWidget := TQtListWidget(ALV.Handle);
LWI := QtListWidget.getItem(AIndex);
end else
begin
QtTreeWidget := TQtTreeWidget(ALV.Handle);
TWI := QtTreeWidget.topLevelItem(AIndex);
end;
if (TWI <> nil) or (LWI <> nil) then
begin
AImgList := TCustomListViewHack(ALV).StateImages;
AImgListWidth := TCustomListViewHack(ALV).StateImagesWidth;
ImgListRes := AImgList.ResolutionForControl[AImgListWidth, ALV];
if ImgListRes.Valid and
((AStateImageIndex >= 0) and (AStateImageIndex < ImgListRes.Count)) then
begin
Bmp := TBitmap.Create;
try
ImgListRes.GetBitmap(AStateImageIndex, Bmp);
AIcon := TQtImage(Bmp.Handle).AsIcon;
if LWI <> nil then
QListWidgetItem_setIcon(LWI, AIcon)
else
QTreeWidgetItem_setIcon(TWI, ASubIndex, AIcon);
QIcon_destroy(AIcon);
finally
Bmp.Free;
end;
end else
begin
if LWI <> nil then
QListWidgetItem_setIcon(LWI, nil)
else
QTreeWidgetItem_setIcon(TWI, ASubIndex, nil);
end;
end;
end;
{------------------------------------------------------------------------------
Method: TQtWSCustomListView.ItemInsert
Params: None
Returns: Nothing
------------------------------------------------------------------------------}
class procedure TQtWSCustomListView.ItemInsert(const ALV: TCustomListView;
const AIndex: Integer; const AItem: TListItem);
var
QtListWidget: TQtListWidget;
QtTreeWidget: TQtTreeWidget;
TWI: QTreeWidgetItemH;
Str: WideString;
i: Integer;
AAlignment: QtAlignment;
begin
if not WSCheckHandleAllocated(ALV, 'ItemInsert') then
Exit;
if IsIconView(ALV) then
begin
QtListWidget := TQtListWidget(ALV.Handle);
QtListWidget.Checkable := ALV.Checkboxes;
QtListWidget.insertItem(AIndex, AItem.Caption);
end else
begin
QtTreeWidget := TQtTreeWidget(ALV.Handle);
TWI := QTreeWidgetItem_create(Ord(QTreeWidgetItemType));
if AItem.Caption <> '' then
Str := AItem{%H-}.Caption
else
Str := '';
if ALV.CheckBoxes then
begin
if AItem.Checked then
QTreeWidgetItem_setCheckState(TWI, 0, QtChecked)
else
QTreeWidgetItem_setCheckState(TWI, 0, QtUnchecked);
end;
AAlignment := QtAlignLeft or QtAlignVCenter;
if TCustomListViewHack(ALV).Columns.Count > 0 then
AAlignment := AlignmentToQtAlignmentMap[ALV.Column[0].Alignment] or QtAlignVCenter;
if Str <> '' then
QtTreeWidget.setItemText(TWI, 0, Str, AAlignment);
QtTreeWidget.setItemData(TWI, 0, AItem);
for i := 0 to AItem.SubItems.Count - 1 do
begin
AAlignment := QtAlignLeft or QtAlignVCenter;
if (TCustomListViewHack(ALV).Columns.Count > 0) and (i + 1 < TCustomListViewHack(ALV).Columns.Count) then
AAlignment := AlignmentToQtAlignmentMap[ALV.Column[i + 1].Alignment] or QtAlignVCenter;
if AItem.Subitems.Strings[i] <> '' then
begin
Str := AItem{%H-}.Subitems.Strings[i];
QtTreeWidget.setItemText(TWI, i + 1, Str, AAlignment);
QtTreeWidget.setItemData(TWI, i + 1, AItem);
end;
end;
QtTreeWidget.insertTopLevelItem(AIndex, TWI);
end;
end;
{------------------------------------------------------------------------------
Method: TQtWSCustomListView.ItemSetText
Params: None
Returns: Nothing
------------------------------------------------------------------------------}
class procedure TQtWSCustomListView.ItemSetText(const ALV: TCustomListView;
const AIndex: Integer; const AItem: TListItem; const ASubIndex: Integer;
const AText: String);
var
QtListWidget: TQtListWidget;
QtTreeWidget: TQtTreeWidget;
TWI: QTreeWidgetItemH;
Str: WideString;
AAlignment: QtAlignment;
begin
if not WSCheckHandleAllocated(ALV, 'ItemSetText') then
Exit;
if IsIconView(ALV) then
begin
if ASubIndex >0 Then exit;
QtListWidget := TQtListWidget(ALV.Handle);
if not QtListWidget.Checkable and (TCustomListViewHack(ALV).ViewStyle = vsIcon) then
AAlignment := QtAlignHCenter or QtAlignBottom
else
if (TCustomListViewHack(ALV).Columns.Count > 0) and (ASubIndex < TCustomListViewHack(ALV).Columns.Count) then
AAlignment := AlignmentToQtAlignmentMap[ALV.Column[ASubIndex].Alignment]
else
AAlignment := QtAlignLeft;
QtListWidget.setItemText(AIndex, AText, AAlignment);
end else
begin
QtTreeWidget := TQtTreeWidget(ALV.Handle);
Str := {%H-}AText;
TWI := QtTreeWidget.topLevelItem(AIndex);
if TWI <> NiL then
begin
AAlignment := QtAlignLeft or QtAlignVCenter;
if (TCustomListViewHack(ALV).Columns.Count > 0) and (ASubIndex < TCustomListViewHack(ALV).Columns.Count) then
AAlignment := AlignmentToQtAlignmentMap[ALV.Column[ASubIndex].Alignment] or QtAlignVCenter;
QtTreeWidget.setItemText(TWI, ASubIndex, Str, AAlignment);
end;
end;
end;
{------------------------------------------------------------------------------
Method: TQtWSCustomListView.ItemShow
Params: None
Returns: Nothing
------------------------------------------------------------------------------}
class procedure TQtWSCustomListView.ItemShow(const ALV: TCustomListView;
const AIndex: Integer; const AItem: TListItem; const PartialOK: Boolean);
var
QtListWidget: TQtListWidget;
LWI: QListWidgetItemH;
QtTreeWidget: TQtTreeWidget;
TWI: QTreeWidgetItemH;
begin
if not WSCheckHandleAllocated(ALV, 'ItemShow') then
Exit;
if IsIconView(ALV) then
begin
QtListWidget := TQtListWidget(ALV.Handle);
LWI := QtListWidget.getItem(AIndex);
QtListWidget.setItemVisible(LWI, True);
if not PartialOK then
QtListWidget.scrollToItem(AIndex, QAbstractItemViewEnsureVisible);
end else
begin
QtTreeWidget := TQtTreeWidget(ALV.Handle);
TWI := QtTreeWidget.topLevelItem(AIndex);
QtTreeWidget.setItemVisible(TWI, True);
if not PartialOK then
QtTreeWidget.scrollToItem(TWI, QAbstractItemViewEnsureVisible);
end;
end;
{------------------------------------------------------------------------------
Method: TQtWSCustomListView.ItemDisplayRect
Params: None
Returns: Nothing
------------------------------------------------------------------------------}
class function TQtWSCustomListView.ItemDisplayRect(const ALV: TCustomListView;
const AIndex, ASubItem: Integer; ACode: TDisplayCode): TRect;
var
QtListWidget: TQtListWidget;
LWI: QListWidgetItemH;
QtTreeWidget: TQtTreeWidget;
TWI: QTreeWidgetItemH;
Size: TSize;
AIcon: QIconH;
IconRect, ChkBoxRect: TRect;
i: Integer;
APixelMetric: Integer;
ImgListRes: TScaledImageListResolution;
begin
if not WSCheckHandleAllocated(ALV, 'ItemDisplayRect') then
Exit;
GetCurrentImages(ALV, ImgListRes);
if IsIconView(ALV) then
begin
QtListWidget := TQtListWidget(ALV.Handle);
LWI := QtListWidget.getItem(AIndex);
Result := QtListWidget.getVisualItemRect(LWI);
if TCustomListViewHack(ALV).ViewStyle = vsList then
begin
if ACode in [drBounds, drSelectBounds] then
exit;
APixelMetric := QStyle_pixelMetric(QApplication_style(), QStylePM_FocusFrameHMargin, nil, QtListWidget.Widget);
IconRect := Result;
// always get icon size
AIcon := QIcon_create();
try
QListWidgetItem_icon(LWI, AIcon);
if QIcon_isNull(AIcon) then
IconRect := Rect(Result.Left, Result.Top, Result.Right, Result.Bottom)
else
begin
Size.cx := 0;
Size.cy := 0;
QIcon_actualSize(AIcon, @Size, @Size);
if (Size.cx = 0) or (Size.cy = 0) then
begin
if ImgListRes.Valid then
IconRect.Right := IconRect.Left + ImgListRes.Width;
end else
begin
IconRect.Right := IconRect.Left + Size.cx;
IconRect.Bottom := IconRect.Top + Size.cy;
end;
end;
finally
QIcon_destroy(AIcon);
end;
IconRect.Left += APixelMetric;
IconRect.Right += APixelMetric;
if ACode = drLabel then
begin
inc(Result.Left, APixelMetric + (IconRect.Right - IconRect.Left));
if (IconRect.Right - IconRect.Left > 0) then
Result.Left += APixelMetric;
end else
if ACode in [drIcon] then
Result := IconRect;
end;
end else
begin
QtTreeWidget := TQtTreeWidget(ALV.Handle);
TWI := QtTreeWidget.topLevelItem(AIndex);
if (QTreeWidgetItem_columnCount(TWI) > 1) and (ASubItem >= 0) then
begin
Result := QtTreeWidget.visualItemRect(TWI);
Result.Left := QTreeView_columnViewportPosition(QTreeWidgetH(QtTreeWidget.Widget), ASubItem);
Result.Right := QtTreeWidget.ColWidth[ASubItem] + Result.Left;
end else
begin
Result := QtTreeWidget.visualItemRect(TWI);
end;
if ACode = drBounds then
begin
QWidget_rect(QtTreeWidget.viewportWidget, @IconRect);
for i := ASubItem + 1 to QtTreeWidget.ColCount - 1 do
Result.Right += QtTreeWidget.ColWidth[i];
if Result.Right > IconRect.Right - IconRect.Left then
Result.Right := IconRect.Right - IconRect.Left;
exit;
end else
begin
IconRect := Result;
// always get icon size
AIcon := QIcon_create();
try
QTreeWidgetItem_icon(TWI, AIcon, ASubItem);
if QIcon_isNull(AIcon) then
IconRect := Rect(0, 0, 0, 0)
else
begin
Size.cx := 0;
Size.cy := 0;
QIcon_actualSize(AIcon, @Size, @Size);
if (Size.cx = 0) or (Size.cy = 0) then
begin
if ImgListRes.Valid then
IconRect.Right := IconRect.Left + ImgListRes.Width;
end else
begin
IconRect.Right := IconRect.Left + Size.cx;
IconRect.Bottom := IconRect.Top + Size.cy;
end;
end;
finally
QIcon_destroy(AIcon);
end;
end;
ChkBoxRect := Rect(0, 0, 0, 0);
if QtTreeWidget.Checkable and (ASubItem = 0) then
begin
APixelMetric := QStyle_pixelMetric(QApplication_style(), QStylePM_IndicatorWidth, nil, QtTreeWidget.Widget);
APixelMetric += QStyle_pixelMetric(QApplication_style(), QStylePM_CheckBoxLabelSpacing, nil, QtTreeWidget.Widget);
ChkBoxRect := Rect(0, 0, APixelMetric, APixelMetric);
if (ChkBoxRect.Bottom > Result.Bottom - Result.Top) then
ChkBoxRect.Bottom := Result.Bottom - Result.Top;
end;
APixelMetric := QStyle_pixelMetric(QApplication_style(), QStylePM_FocusFrameHMargin, nil, QtTreeWidget.Widget);
if ACode = drLabel then
begin
inc(Result.Left, APixelMetric + (IconRect.Right - IconRect.Left) + (ChkBoxRect.Right - ChkBoxRect.Left));
if (IconRect.Right - IconRect.Left > 0) then
Result.Left += APixelMetric;
end else
if ACode = drSelectBounds then
begin
Result.Left += APixelMetric + (ChkBoxRect.Right - ChkBoxRect.Left);
Result.Right := Result.Left + (QtTreeWidget.ColWidth[ASubItem] - APixelMetric);
end else
if ACode in [drIcon] then
begin
if IsRectEmpty(IconRect) and ImgListRes.Valid and
(QtTreeWidget.OwnerData or QtTreeWidget.OwnerDrawn) then
begin
IconRect := Rect(0, 0, ImgListRes.Width, ImgListRes.Height);
Types.OffsetRect(IconRect, Result.Left, Result.Top + APixelMetric);
end;
IconRect.Left += APixelMetric + (ChkBoxRect.Right - ChkBoxRect.Left);
IconRect.Right += APixelMetric;
Result := IconRect;
end;
end;
end;
class procedure TQtWSCustomListView.BeginUpdate(const ALV: TCustomListView);
var
QtWidget: TQtWidget;
begin
if not WSCheckHandleAllocated(ALV, 'BeginUpdate') then
Exit;
QtWidget := TQtWidget(ALV.Handle);
if not QtWidget.InUpdate then
QtWidget.setUpdatesEnabled(False);
QtWidget.BeginUpdate;
end;
class procedure TQtWSCustomListView.EndUpdate(const ALV: TCustomListView);
var
QtWidget: TQtWidget;
begin
if not WSCheckHandleAllocated(ALV, 'EndUpdate') then
Exit;
QtWidget := TQtWidget(ALV.Handle);
QtWidget.EndUpdate;
if not QtWidget.InUpdate then
QtWidget.setUpdatesEnabled(True);
end;
{------------------------------------------------------------------------------
Method: TQtWSCustomListView.GetFocused
Params: None
Returns: Nothing
------------------------------------------------------------------------------}
class function TQtWSCustomListView.GetFocused(const ALV: TCustomListView): Integer;
var
QtListWidget: TQtListWidget;
LWI: QListWidgetItemH;
QtTreeWidget: TQtTreeWidget;
TWI: QTreeWidgetItemH;
i: Integer;
begin
if not WSCheckHandleAllocated(ALV, 'GetFocused') then
Exit(-1);
if IsIconView(ALV) then
begin
QtListWidget := TQtListWidget(ALV.Handle);
LWI := QtListWidget.currentItem;
if QtListWidget.getItemSelected(LWI) then
Result := QtListWidget.getRow(LWI)
else
Result := -1;
end else
begin
QtTreeWidget := TQtTreeWidget(ALV.Handle);
TWI := QtTreeWidget.currentItem;
i := QtTreeWidget.getRow(TWI);
if QTreeWidgetItem_isSelected(TWI) then
Result := i
else
Result := -1;
end;
end;
class function TQtWSCustomListView.GetHitTestInfoAt(const ALV: TCustomListView;
X, Y: Integer): THitTests;
var
I, AImgListWidth, Ax: Integer;
QtListWidget: TQtListWidget;
QtTreeWidget: TQtTreeWidget;
LWI: QListWidgetItemH;
TWI: QTreeWidgetItemH;
AImgList: TCustomImageList;
AImgListRes: TScaledImageListResolution;
AListSpacing, AFocusFrame: integer;
begin
Result := [];
if not WSCheckHandleAllocated(ALV, 'GetHitTestInfoAt') then
Exit;
I := GetItemAt(ALV, x, y);
AFocusFrame := 2;
AListSpacing := 4; {default, we are using pixelMetric() for real spacing}
AX := 0;
if I >= 0 then
begin
Include(Result, htOnItem);
if Assigned(TCustomListViewHack(ALV).LargeImages) or Assigned(TCustomListViewHack(ALV).SmallImages) or
Assigned(TCustomListViewHack(ALV).StateImages) then
begin
if IsIconView(ALV) then
begin
QtListWidget := TQtListWidget(ALV.Handle);
LWI := QtListWidget.getItem(I);
AFocusFrame := QStyle_pixelMetric(QApplication_style(), QStylePM_FocusFrameHMargin, nil, QtListWidget.Widget);
AListSpacing := QStyle_pixelMetric(QApplication_style(), QStylePM_CheckBoxLabelSpacing, nil, QtListWidget.Widget);
// AItemRect := QtListWidget.getVisualItemRect(LWI);
end else
begin
QtTreeWidget := TQtTreeWidget(ALV.Handle);
TWI := QtTreeWidget.topLevelItem(I);
AFocusFrame := QStyle_pixelMetric(QApplication_style(), QStylePM_FocusFrameHMargin, nil, QtTreeWidget.Widget);
AListSpacing := QStyle_pixelMetric(QApplication_style(), QStylePM_CheckBoxLabelSpacing, nil, QtTreeWidget.Widget);
// AItemRect := QtTreeWidget.visualItemRect(TWI);
end;
if Assigned(TCustomListViewHack(ALV).StateImages) and (ALV.Items[I].StateIndex >= 0) then
begin
if Assigned(TWI) or Assigned(LWI) then
begin
AImgList := TCustomListViewHack(ALV).StateImages;
AImgListWidth := TCustomListViewHack(ALV).StateImagesWidth;
AImgListRes := AImgList.ResolutionForControl[AImgListWidth, ALV];
if AImgListRes.Valid then
begin
if (x >= AListSpacing) and (x <= AImgListRes.Width + AFocusFrame) then
include(Result, htOnStateIcon);
Ax += AImgListRes.Width + AListSpacing;
end;
end;
end;
if Assigned(TCustomListViewHack(ALV).SmallImages) and (ALV.Items[I].ImageIndex >= 0) then
begin
if Assigned(TWI) or Assigned(LWI) then
begin
AImgList := TCustomListViewHack(ALV).SmallImages;
AImgListWidth := TCustomListViewHack(ALV).SmallImagesWidth;
AImgListRes := AImgList.ResolutionForControl[AImgListWidth, ALV];
if AImgListRes.Valid and (x >= AListSpacing) and (x <= AImgListRes.Width + AFocusFrame) then
begin
include(Result, htOnIcon);
Ax += AImgListRes.Width + AListSpacing;
end;
end;
end else
if Assigned(TCustomListViewHack(ALV).LargeImages) and (ALV.Items[I].ImageIndex >= 0) then
begin
if Assigned(TWI) or Assigned(LWI) then
begin
AImgList := TCustomListViewHack(ALV).LargeImages;
AImgListWidth := TCustomListViewHack(ALV).LargeImagesWidth;
AImgListRes := AImgList.ResolutionForControl[AImgListWidth, ALV];
if AImgListRes.Valid and (x >= AListSpacing) and (x <= AImgListRes.Width + AFocusFrame) then
begin
include(Result, htOnIcon);
Ax += AImgListRes.Width + AListSpacing;
end;
end;
end;
if [htOnIcon, htOnStateIcon] * Result = [] then
begin
if x >= (AX + AFocusFrame) then
include(Result, htOnLabel);
end;
end;
end else
begin
if PtInRect(ALV.ClientRect, Point(x, y)) then
Result := [THitTest.htNowhere];
end;
end;
{------------------------------------------------------------------------------
Method: TQtWSCustomListView.GetItemAt
Params: None
Returns: Nothing
------------------------------------------------------------------------------}
class function TQtWSCustomListView.GetItemAt(const ALV: TCustomListView; x,y: integer): Integer;
var
QtListWidget: TQtListWidget;
LWI: QListWidgetItemH;
QtTreeWidget: TQtTreeWidget;
TWI: QTreeWidgetItemH;
begin
if not WSCheckHandleAllocated(ALV, 'GetItemAt') then
Exit(-1);
if IsIconView(ALV) then
begin
QtListWidget := TQtListWidget(ALV.Handle);
LWI := QtListWidget.itemAt(x, y);
Result := QtListWidget.getRow(LWI);
end else
begin
QtTreeWidget := TQtTreeWidget(ALV.Handle);
TWI := QtTreeWidget.itemAt(x, y);
Result := QtTreeWidget.getRow(TWI);
end;
end;
{------------------------------------------------------------------------------
Method: TQtWSCustomListView.GetSelCount
Params: None
Returns: Nothing
------------------------------------------------------------------------------}
class function TQtWSCustomListView.GetSelCount(const ALV: TCustomListView): Integer;
begin
if not WSCheckHandleAllocated(ALV, 'GetSelCount') then
Exit(-1);
if IsIconView(ALV) then
Result := TQtListWidget(ALV.Handle).getSelCount
else
Result := TQtTreeWidget(ALV.Handle).selCount;
end;
{------------------------------------------------------------------------------
Method: TQtWSCustomListView.GetSelection
Params: None
Returns: Nothing
------------------------------------------------------------------------------}
class function TQtWSCustomListView.GetSelection(const ALV: TCustomListView): Integer;
var
QtListWidget: TQtListWidget;
QtTreeWidget: TQtTreeWidget;
FPInts: TPtrIntArray;
begin
if not WSCheckHandleAllocated(ALV, 'GetSelection') then
Exit(-1);
if IsIconView(ALV) then
begin
QtListWidget := TQtListWidget(ALV.Handle);
FPInts := QtListWidget.selectedItems;
end else
begin
{implement selection event so we can return Alv.Selected.Index}
QtTreeWidget := TQtTreeWidget(ALV.Handle);
FPInts := QtTreeWidget.selectedItems;
end;
if Length(FPInts)>0 then
Result := FPInts[0]
else
Result := -1;
end;
class function TQtWSCustomListView.GetTopItem(const ALV: TCustomListView): Integer;
var
QtItemView: TQtAbstractItemView;
begin
Result := -1;
if not WSCheckHandleAllocated(ALV, 'GetTopItem') then
Exit;
// according to embarcadero docs this should return
// only for vsList and vsReport
if not (TCustomListViewHack(ALV).ViewStyle in [vsList, vsReport]) then
exit;
QtItemView := TQtAbstractItemView(ALV.Handle);
Result := QtItemView.getTopItem;
end;
{------------------------------------------------------------------------------
Method: TQtWSCustomListView.InternalUpdateItems
Params: TCustomListView
Returns: Nothing
Sync TCustomListView with QTreeWidget items.
------------------------------------------------------------------------------}
class procedure TQtWSCustomListView.InternalUpdateItems(
const AList: TCustomListView);
var
QtTreeWidget: TQtTreeWidget;
i, j: Integer;
AItem: TListItem;
WStr: WideString;
Item: QTreeWidgetItemH;
AAlignment: QtAlignment;
Bmp: TBitmap;
ImgListRes: TScaledImageListResolution;
AIcon: QIconH;
begin
QtTreeWidget := TQtTreeWidget(AList.Handle);
GetCurrentImages(AList, ImgListRes);
BeginUpdate(AList);
try
for i := 0 to AList.Items.Count - 1 do
begin
AItem := AList.Items[i];
WStr := AItem{%H-}.Caption;
Item := QtTreeWidget.topLevelItem(i);
QtTreeWidget.setItemText(Item, 0, WStr, AlignmentToQtAlignmentMap[AList.Column[0].Alignment] or QtAlignVCenter);
QtTreeWidget.setItemData(Item, 0, AItem);
if AList.Checkboxes then
begin
if RestoreItemCheckedAfterSort(AList) then
// when true checkboxes are fixed by LCL, so we uncheck each item first
// look at TCustomListView.SortWithParams. issue #38137
QtTreeWidget.ItemChecked[i] := False
else
begin
if AItem.Checked then
QTreeWidgetItem_setCheckState(Item, 0, QtChecked)
else
QTreeWidgetItem_setCheckState(Item, 0, QtUnChecked);
end;
end;
if ImgListRes.Valid and (ImgListRes.Count > 0) and
((AItem.ImageIndex >= 0) and (AItem.ImageIndex < ImgListRes.Count)) then
begin
Bmp := TBitmap.Create;
try
ImgListRes.GetBitmap(AItem.ImageIndex, Bmp);
AIcon := TQtImage(Bmp.Handle).AsIcon;
QTreeWidgetItem_setIcon(Item, 0, AIcon);
QIcon_Destroy(AIcon);
finally
Bmp.Free;
end;
end else
QTreeWidgetItem_setIcon(Item, 0, nil);
// subitems
for j := 0 to AItem.SubItems.Count - 1 do
begin
AAlignment := QtAlignLeft;
if (TCustomListViewHack(AList).Columns.Count > 0) and (j + 1 < TCustomListViewHack(AList).Columns.Count) then
AAlignment := AlignmentToQtAlignmentMap[TCustomListViewHack(AList).Column[j + 1].Alignment];
WStr := AItem{%H-}.Subitems.Strings[j];
QtTreeWidget.setItemText(Item, j + 1, WStr, AAlignment or QtAlignVCenter);
QtTreeWidget.setItemData(Item, j + 1, AItem);
if ImgListRes.Valid and (ImgListRes.Count > 0) and (AItem.SubItemImages[j] >= 0) then
begin
Bmp := TBitmap.Create;
try
ImgListRes.GetBitmap(AItem.SubItemImages[j], Bmp);
AIcon := TQtImage(Bmp.Handle).AsIcon;
QTreeWidgetItem_setIcon(Item, j + 1, AIcon);
QIcon_destroy(AIcon);
finally
Bmp.Free;
end;
end else
QTreeWidgetItem_setIcon(Item, j + 1, nil);
end;
end;
finally
EndUpdate(AList);
end;
end;
class procedure TQtWSCustomListView.GetCurrentImages(
const ALV: TCustomListView; out AImgListRes: TScaledImageListResolution);
var
LV: TCustomListViewHack;
AImgList: TCustomImageList;
AImgListWidth: Integer;
begin
LV := TCustomListViewHack(ALV);
case LV.ViewStyle of
vsIcon:
begin
AImgList := LV.LargeImages;
AImgListWidth := LV.LargeImagesWidth;
end;
vsSmallIcon, vsReport, vsList:
begin
AImgList := LV.SmallImages;
AImgListWidth := LV.SmallImagesWidth;
end;
else
AImgList := nil;
AImgListWidth := 0;
end;
if AImgList = nil then
begin
AImgList := LV.StateImages;
AImgListWidth := LV.StateImagesWidth;
end;
if AImgList<>nil then
AImgListRes := AImgList.ResolutionForControl[AImgListWidth, ALV]
else
AImgListRes := TScaledImageListResolution.Create(nil, 0);
end;
{------------------------------------------------------------------------------
Method: TQtWSCustomListView.SetSort
Params: None
Returns: Nothing
------------------------------------------------------------------------------}
class procedure TQtWSCustomListView.SetSort(const ALV: TCustomListView;
const AType: TSortType; const AColumn: Integer; const ASortDirection: TSortDirection);
var
QtTreeWidget: TQtTreeWidget;
{$IFDEF TEST_QT_SORTING}
StdModel: QStandardItemModelH;
{$ENDIF}
begin
if not WSCheckHandleAllocated(ALV, 'SetSort') then
Exit;
if (csDesigning in ALV.ComponentState) then
exit;
if IsIconView(ALV) then
exit;
QtTreeWidget := TQtTreeWidget(ALV.Handle);
if AType = stNone then
QtTreeWidget.Header.SetSortIndicatorVisible(False)
else
begin
{$IFDEF TEST_QT_SORTING}
// QTreeWidget crashes sometimes on changing sort role (possible qt bug).
// need deeper investigation.
if QtTreeWidget.ItemCount > 0 then
begin
StdModel := QStandardItemModelH(QtTreeWidget.getModel);
if QStandardItemModel_sortRole(StdModel) <> Ord(QtUserRole) then
QStandardItemModel_setSortRole(StdModel, Ord(QtUserRole));
end;
{$ELSE}
with QtTreeWidget do
begin
Header.SetSortIndicatorVisible(True);
if (AColumn >= 0) and (AColumn < ColCount) then
begin
Header.SetSortIndicator(AColumn, QtSortOrder(Ord(ASortDirection)));
if ItemCount > 0 then
InternalUpdateItems(ALV);
end;
end;
{$ENDIF}
end;
end;
{------------------------------------------------------------------------------
Method: TQtWSCustomListView.GetBoundingRect
Params: None
Returns: Nothing
------------------------------------------------------------------------------}
class function TQtWSCustomListView.GetBoundingRect(const ALV: TCustomListView): TRect;
begin
if not WSCheckHandleAllocated(ALV, 'GetBoundingRect') then
Exit(Rect(0,0,0,0));
Result := TQtWidget(ALV.Handle).getFrameGeometry;
end;
class function TQtWSCustomListView.GetViewOrigin(const ALV: TCustomListView): TPoint;
var
QtItemView: TQtAbstractItemView;
begin
Result := Point(0, 0);
if not WSCheckHandleAllocated(ALV, 'GetViewOrigin') then
Exit;
QtItemView := TQtAbstractItemView(ALV.Handle);
Result := QtItemView.getViewOrigin;
end;
class function TQtWSCustomListView.GetVisibleRowCount(const ALV: TCustomListView
): Integer;
begin
Result := 0;
if not WSCheckHandleAllocated(ALV, 'GetVisibleRowCount') then
Exit;
Result := TQtAbstractItemView(ALV.Handle).getVisibleRowCount;
end;
class function TQtWSCustomListView.RestoreItemCheckedAfterSort(
const ALV: TCustomListView): Boolean;
begin
Result := True;
end;
class procedure TQtWSCustomListView.SelectAll(const ALV: TCustomListView;
const AIsSet: Boolean);
begin
if not WSCheckHandleAllocated(ALV, 'SelectAll') then
Exit;
if AIsSet then
QAbstractItemView_selectAll(QAbstractItemViewH(TQtWidget(ALV.Handle).Widget))
else
QAbstractItemView_clearSelection(QAbstractItemViewH(TQtWidget(ALV.Handle).Widget));
end;
class procedure TQtWSCustomListView.SetAllocBy(const ALV: TCustomListView;
const AValue: Integer);
var
QtList: TQtListWidget;
NewValue: integer;
begin
if not WSCheckHandleAllocated(ALV, 'SetAllocBy') then
Exit;
if TCustomListViewHack(ALV).ViewStyle <> vsReport then
begin
NewValue := AValue;
if NewValue < 0 then
NewValue := 0;
QtList := TQtListWidget(ALV.Handle);
if NewValue > 0 then
begin
QtList.setLayoutMode(QListViewBatched);
QtList.BatchSize := NewValue;
end else
QtList.setLayoutMode(QListViewSinglePass);
end;
end;
class procedure TQtWSCustomListView.SetIconArrangement(
const ALV: TCustomListView; const AValue: TIconArrangement);
var
QtList: TQtListWidget;
begin
if not WSCheckHandleAllocated(ALV, 'SetIconArrangement') then
Exit;
if IsIconView(ALV) then
begin
QtList := TQtListWidget(ALV.Handle);
if QtList.ViewStyle <> Ord(vsList) then
QtList.setViewFlow(IconArngToQListFlow[AValue]);
end;
end;
class procedure TQtWSCustomListView.SetImageList(const ALV: TCustomListView;
const AList: TListViewImageList; const AValue: TCustomImageListResolution);
begin
if not WSCheckHandleAllocated(ALV, 'SetImageList') then
Exit;
if not ALV.OwnerData then
RecreateWnd(ALV);
end;
class procedure TQtWSCustomListView.SetItemsCount(const ALV: TCustomListView;
const Avalue: Integer);
var
QtListWidget: TQtListWidget;
QtTreeWidget: TQtTreeWidget;
begin
if not WSCheckHandleAllocated(ALV, 'SetItemsCount') then
Exit;
if IsIconView(ALV) then
begin
QtListWidget := TQtListWidget(ALV.Handle);
QtListWidget.ItemCount := AValue;
end else
begin
QtTreeWidget := TQtTreeWidget(ALV.Handle);
QtTreeWidget.ItemCount := AValue;
end;
end;
class procedure TQtWSCustomListView.SetOwnerData(const ALV: TCustomListView;
const AValue: Boolean);
var
QtItemView: TQtAbstractItemView;
begin
if not WSCheckHandleAllocated(ALV, 'SetOwnerData') then
Exit;
QtItemView := TQtAbstractItemView(ALV.Handle);
QtItemView.OwnerData := AValue;
end;
class procedure TQtWSCustomListView.SetProperty(const ALV: TCustomListView;
const AProp: TListViewProperty; const AIsSet: Boolean);
const
BoolToSelectionMode: array[Boolean] of QAbstractItemViewSelectionMode =
(
QAbstractItemViewSingleSelection,
QAbstractItemViewExtendedSelection
);
BoolToSelectionBehavior: array[Boolean] of QAbstractItemViewSelectionBehavior =
(
QAbstractItemViewSelectItems,
QAbstractItemViewSelectRows
);
BoolToEditTriggers: array[Boolean] of QAbstractItemViewEditTriggers =
(
QAbstractItemViewNoEditTriggers, // QAbstractItemViewSelectedClicked,
QAbstractItemViewNoEditTriggers
);
var
SavedCheckable: Boolean;
QtItemView: TQtAbstractItemView;
begin
if not WSCheckHandleAllocated(ALV, 'SetProperty')
then Exit;
QtItemView := TQtAbstractItemView(ALV.Handle);
case AProp of
lvpAutoArrange:
begin
if IsIconView(ALV) and
(TQtListWidget(ALV.Handle).ViewStyle <> Ord(vsList)) then
TQtListWidget(ALV.Handle).setWrapping(AIsSet);
end;
lvpCheckboxes:
begin
SavedCheckable := QtItemView.Checkable;
QtItemView.Checkable := AIsSet;
if SavedCheckable <> AIsSet then
RecreateWnd(ALV);
end;
lvpMultiSelect:
begin
if (QtItemView.getSelectionMode <> QAbstractItemViewNoSelection) then
QtItemView.setSelectionMode(BoolToSelectionMode[AIsSet]);
end;
lvpShowColumnHeaders:
begin
if not IsIconView(ALV) then
with TQtTreeWidget(ALV.Handle) do
setHeaderVisible(AIsSet and (TCustomListViewHack(ALV).ViewStyle = vsReport)
and (TCustomListViewHack(ALV).Columns.Count > 0) );
end;
lvpOwnerDraw: ; // utilized automatically.
lvpReadOnly: QtItemView.setEditTriggers(BoolToEditTriggers[AIsSet]);
lvpRowSelect:
begin
if not IsIconView(ALV) then
TQtTreeWidget(ALV.Handle).setAllColumnsShowFocus(AIsSet);
QtItemView.setSelectionBehavior(BoolToSelectionBehavior[AIsSet]);
end;
lvpWrapText: QtItemView.setWordWrap(AIsSet);
lvpHideSelection: QtItemView.HideSelection := AIsSet;
end;
end;
class procedure TQtWSCustomListView.SetProperties(const ALV: TCustomListView;
const AProps: TListViewProperties);
var
i: TListViewProperty;
begin
if not WSCheckHandleAllocated(ALV, 'SetProperties')
then Exit;
for i := Low(TListViewProperty) to High(TListViewProperty) do
SetProperty(ALV, i, i in AProps);
end;
class procedure TQtWSCustomListView.SetScrollBars(const ALV: TCustomListView;
const AValue: TScrollStyle);
var
QtItemView: TQtAbstractItemView;
begin
if not WSCheckHandleAllocated(ALV, 'SetScrollBars') then
Exit;
QtItemView := TQtAbstractItemView(ALV.Handle);
{always reset before applying new TScrollStyle}
QtItemView.setScrollStyle(ssNone);
if AValue <> ssNone then
QtItemView.setScrollStyle(AValue);
end;
class procedure TQtWSCustomListView.SetViewStyle(const ALV: TCustomListView;
const Avalue: TViewStyle);
var
QtItemView: TQtAbstractItemView;
QtListWidget: TQtListWidget;
LWI: QListWidgetItemH;
QtTreeWidget: TQtTreeWidget;
ItemViewWidget: QAbstractItemViewH;
Item: QTreeWidgetItemH;
Size: TSize;
x: Integer;
j: Integer;
ImgListRes: TScaledImageListResolution;
begin
if not WSCheckHandleAllocated(ALV, 'SetViewStyle') then
Exit;
QtItemView := TQtAbstractItemView(ALV.Handle);
if (QtItemView.ViewStyle <> Ord(AValue)) then
begin
RecreateWnd(ALV);
exit;
end;
if IsIconView(ALV) then
begin
QtTreeWidget := Nil; // Suppress compiler warning.
QtListWidget := TQtListWidget(ALV.Handle);
ItemViewWidget := QListWidgetH(QtListWidget.Widget);
QtListWidget.OwnerDrawn := False;
end else
begin
QtListWidget := Nil; // Suppress compiler warning.
QtTreeWidget := TQtTreeWidget(ALV.Handle);
ItemViewWidget := QTreeWidgetH(QtTreeWidget.Widget);
with QtTreeWidget do
setHeaderVisible(TCustomListViewHack(ALV).ShowColumnHeaders and (AValue = vsReport)
and (TCustomListViewHack(ALV).Columns.Count > 0) );
end;
GetCurrentImages(ALV, ImgListRes);
if ImgListRes.Valid then
begin
Size.cy := ImgListRes.Height;
Size.cx := ImgListRes.Width;
end else
begin
case AValue of
vsIcon: Size.cx := GetPixelMetric(QStylePM_IconViewIconSize, nil, ItemViewWidget);
vsSmallIcon: Size.cx := GetPixelMetric(QStylePM_ListViewIconSize, nil, ItemViewWidget);
else
Size.cx := 0;
end;
Size.cy := Size.cx;
end;
if AValue in [vsList, vsReport] then
TQtAbstractItemView(ALV.Handle).OwnerDrawn :=
TCustomListViewHack(ALV).IsCustomDrawn(dtControl, cdPrePaint) or
(TCustomListViewHack(ALV).OwnerDraw and
(TCustomListViewHack(ALV).ViewStyle = vsReport));
TQtAbstractItemView(ALV.Handle).IconSize := Size;
if IsIconView(ALV) then
begin
LWI := QtListWidget.getItem(0);
if LWI <> nil then
begin
X := Size.CY;
QListWidgetItem_sizeHint(LWI, @Size);
Size.Cy := X;
QListWidgetItem_setSizeHint(LWI, @Size);
end;
end else
begin
Item := QtTreeWidget.topLevelItem(0);
if Item <> nil then
begin
X := Size.CY;
QTreeWidgetItem_sizeHint(Item, @Size, 0);
Size.Cy := X;
QTreeWidgetItem_setSizeHint(Item, 0, @Size);
for j := 0 to QtTreeWidget.ColCount - 1 do
begin
Item := QtTreeWidget.itemAt(j, 0);
QTreeWidgetItem_setSizeHint(Item, j, @Size);
end;
end;
QtTreeWidget.UniformRowHeights := True;
end;
end;
end.
|