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
|
/****************************************************************************
**
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the QtGui module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the either Technology Preview License Agreement or the
** Beta Release License Agreement.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain
** additional rights. These rights are described in the Nokia Qt LGPL
** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
** package.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met: http://www.gnu.org/copyleft/gpl.html.
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at http://www.qtsoftware.com/contact.
** $QT_END_LICENSE$
**
****************************************************************************/
#include "qlineedit.h"
#include "qlineedit_p.h"
#ifndef QT_NO_LINEEDIT
#include "qaction.h"
#include "qapplication.h"
#include "qclipboard.h"
#include "qdrag.h"
#include "qdrawutil.h"
#include "qevent.h"
#include "qfontmetrics.h"
#include "qmenu.h"
#include "qpainter.h"
#include "qpixmap.h"
#include "qpointer.h"
#include "qstringlist.h"
#include "qstyle.h"
#include "qstyleoption.h"
#include "qtimer.h"
#include "qvalidator.h"
#include "qvariant.h"
#include "qvector.h"
#include "qwhatsthis.h"
#include "qdebug.h"
#include "qtextedit.h"
#include <private/qtextedit_p.h>
#ifndef QT_NO_ACCESSIBILITY
#include "qaccessible.h"
#endif
#ifndef QT_NO_IM
#include "qinputcontext.h"
#include "qlist.h"
#endif
#include "qabstractitemview.h"
#include "private/qstylesheetstyle_p.h"
#ifndef QT_NO_SHORTCUT
#include "private/qapplication_p.h"
#include "private/qshortcutmap_p.h"
#include "qkeysequence.h"
#define ACCEL_KEY(k) (!qApp->d_func()->shortcutMap.hasShortcutForKeySequence(k) ? QLatin1Char('\t') + QString(QKeySequence(k)) : QString())
#else
#define ACCEL_KEY(k) QString()
#endif
#include <limits.h>
#define verticalMargin 1
#define horizontalMargin 2
QT_BEGIN_NAMESPACE
#ifdef Q_WS_MAC
extern void qt_mac_secure_keyboard(bool); //qapplication_mac.cpp
#endif
static inline bool shouldEnableInputMethod(QLineEdit *lineedit)
{
return !lineedit->isReadOnly();
}
/*!
Initialize \a option with the values from this QLineEdit. This method
is useful for subclasses when they need a QStyleOptionFrame or QStyleOptionFrameV2, but don't want
to fill in all the information themselves. This function will check the version
of the QStyleOptionFrame and fill in the additional values for a
QStyleOptionFrameV2.
\sa QStyleOption::initFrom()
*/
void QLineEdit::initStyleOption(QStyleOptionFrame *option) const
{
if (!option)
return;
Q_D(const QLineEdit);
option->initFrom(this);
option->rect = contentsRect();
option->lineWidth = d->frame ? style()->pixelMetric(QStyle::PM_DefaultFrameWidth, option, this)
: 0;
option->midLineWidth = 0;
option->state |= QStyle::State_Sunken;
if (d->readOnly)
option->state |= QStyle::State_ReadOnly;
#ifdef QT_KEYPAD_NAVIGATION
if (hasEditFocus())
option->state |= QStyle::State_HasEditFocus;
#endif
if (QStyleOptionFrameV2 *optionV2 = qstyleoption_cast<QStyleOptionFrameV2 *>(option))
optionV2->features = QStyleOptionFrameV2::None;
}
/*!
\class QLineEdit
\brief The QLineEdit widget is a one-line text editor.
\ingroup basicwidgets
\mainclass
A line edit allows the user to enter and edit a single line of
plain text with a useful collection of editing functions,
including undo and redo, cut and paste, and drag and drop.
By changing the echoMode() of a line edit, it can also be used as
a "write-only" field, for inputs such as passwords.
The length of the text can be constrained to maxLength(). The text
can be arbitrarily constrained using a validator() or an
inputMask(), or both.
A related class is QTextEdit which allows multi-line, rich text
editing.
You can change the text with setText() or insert(). The text is
retrieved with text(); the displayed text (which may be different,
see \l{EchoMode}) is retrieved with displayText(). Text can be
selected with setSelection() or selectAll(), and the selection can
be cut(), copy()ied and paste()d. The text can be aligned with
setAlignment().
When the text changes the textChanged() signal is emitted; when
the text changes other than by calling setText() the textEdited()
signal is emitted; when the cursor is moved the
cursorPositionChanged() signal is emitted; and when the Return or
Enter key is pressed the returnPressed() signal is emitted.
When editing is finished, either because the line edit lost focus
or Return/Enter is pressed the editingFinished() signal is
emitted.
Note that if there is a validator set on the line edit, the
returnPressed()/editingFinished() signals will only be emitted if
the validator returns QValidator::Acceptable.
By default, QLineEdits have a frame as specified by the Windows
and Motif style guides; you can turn it off by calling
setFrame(false).
The default key bindings are described below. The line edit also
provides a context menu (usually invoked by a right mouse click)
that presents some of these editing options.
\target desc
\table
\header \i Keypress \i Action
\row \i Left Arrow \i Moves the cursor one character to the left.
\row \i Shift+Left Arrow \i Moves and selects text one character to the left.
\row \i Right Arrow \i Moves the cursor one character to the right.
\row \i Shift+Right Arrow \i Moves and selects text one character to the right.
\row \i Home \i Moves the cursor to the beginning of the line.
\row \i End \i Moves the cursor to the end of the line.
\row \i Backspace \i Deletes the character to the left of the cursor.
\row \i Ctrl+Backspace \i Deletes the word to the left of the cursor.
\row \i Delete \i Deletes the character to the right of the cursor.
\row \i Ctrl+Delete \i Deletes the word to the right of the cursor.
\row \i Ctrl+A \i Select all.
\row \i Ctrl+C \i Copies the selected text to the clipboard.
\row \i Ctrl+Insert \i Copies the selected text to the clipboard.
\row \i Ctrl+K \i Deletes to the end of the line.
\row \i Ctrl+V \i Pastes the clipboard text into line edit.
\row \i Shift+Insert \i Pastes the clipboard text into line edit.
\row \i Ctrl+X \i Deletes the selected text and copies it to the clipboard.
\row \i Shift+Delete \i Deletes the selected text and copies it to the clipboard.
\row \i Ctrl+Z \i Undoes the last operation.
\row \i Ctrl+Y \i Redoes the last undone operation.
\endtable
Any other key sequence that represents a valid character, will
cause the character to be inserted into the line edit.
\table 100%
\row \o \inlineimage macintosh-lineedit.png Screenshot of a Macintosh style line edit
\o A line edit shown in the \l{Macintosh Style Widget Gallery}{Macintosh widget style}.
\row \o \inlineimage windows-lineedit.png Screenshot of a Windows XP style line edit
\o A line edit shown in the \l{Windows XP Style Widget Gallery}{Windows XP widget style}.
\row \o \inlineimage plastique-lineedit.png Screenshot of a Plastique style line edit
\o A line edit shown in the \l{Plastique Style Widget Gallery}{Plastique widget style}.
\endtable
\sa QTextEdit, QLabel, QComboBox, {fowler}{GUI Design Handbook: Field, Entry}, {Line Edits Example}
*/
/*!
\fn void QLineEdit::textChanged(const QString &text)
This signal is emitted whenever the text changes. The \a text
argument is the new text.
Unlike textEdited(), this signal is also emitted when the text is
changed programmatically, for example, by calling setText().
*/
/*!
\fn void QLineEdit::textEdited(const QString &text)
This signal is emitted whenever the text is edited. The \a text
argument is the next text.
Unlike textChanged(), this signal is not emitted when the text is
changed programmatically, for example, by calling setText().
*/
/*!
\fn void QLineEdit::cursorPositionChanged(int old, int new)
This signal is emitted whenever the cursor moves. The previous
position is given by \a old, and the new position by \a new.
\sa setCursorPosition(), cursorPosition()
*/
/*!
\fn void QLineEdit::selectionChanged()
This signal is emitted whenever the selection changes.
\sa hasSelectedText(), selectedText()
*/
/*!
Constructs a line edit with no text.
The maximum text length is set to 32767 characters.
The \a parent argument is sent to the QWidget constructor.
\sa setText(), setMaxLength()
*/
QLineEdit::QLineEdit(QWidget* parent)
: QWidget(*new QLineEditPrivate, parent,0)
{
Q_D(QLineEdit);
d->init(QString());
}
/*!
Constructs a line edit containing the text \a contents.
The cursor position is set to the end of the line and the maximum
text length to 32767 characters.
The \a parent and argument is sent to the QWidget
constructor.
\sa text(), setMaxLength()
*/
QLineEdit::QLineEdit(const QString& contents, QWidget* parent)
: QWidget(*new QLineEditPrivate, parent, 0)
{
Q_D(QLineEdit);
d->init(contents);
}
#ifdef QT3_SUPPORT
/*!
Constructs a line edit with no text.
The maximum text length is set to 32767 characters.
The \a parent and \a name arguments are sent to the QWidget constructor.
\sa setText(), setMaxLength()
*/
QLineEdit::QLineEdit(QWidget* parent, const char* name)
: QWidget(*new QLineEditPrivate, parent,0)
{
Q_D(QLineEdit);
setObjectName(QString::fromAscii(name));
d->init(QString());
}
/*!
Constructs a line edit containing the text \a contents.
The cursor position is set to the end of the line and the maximum
text length to 32767 characters.
The \a parent and \a name arguments are sent to the QWidget
constructor.
\sa text(), setMaxLength()
*/
QLineEdit::QLineEdit(const QString& contents, QWidget* parent, const char* name)
: QWidget(*new QLineEditPrivate, parent, 0)
{
Q_D(QLineEdit);
setObjectName(QString::fromAscii(name));
d->init(contents);
}
/*!
Constructs a line edit with an input \a inputMask and the text \a
contents.
The cursor position is set to the end of the line and the maximum
text length is set to the length of the mask (the number of mask
characters and separators).
The \a parent and \a name arguments are sent to the QWidget
constructor.
\sa setMask() text()
*/
QLineEdit::QLineEdit(const QString& contents, const QString &inputMask, QWidget* parent, const char* name)
: QWidget(*new QLineEditPrivate, parent, 0)
{
Q_D(QLineEdit);
setObjectName(QString::fromAscii(name));
d->parseInputMask(inputMask);
if (d->maskData) {
QString ms = d->maskString(0, contents);
d->init(ms + d->clearString(ms.length(), d->maxLength - ms.length()));
d->cursor = d->nextMaskBlank(ms.length());
} else {
d->init(contents);
}
}
#endif
/*!
Destroys the line edit.
*/
QLineEdit::~QLineEdit()
{
}
/*!
\property QLineEdit::text
\brief the line edit's text
Setting this property clears the selection, clears the undo/redo
history, moves the cursor to the end of the line and resets the
\l modified property to false. The text is not validated when
inserted with setText().
The text is truncated to maxLength() length.
By default, this property contains an empty string.
\sa insert(), clear()
*/
QString QLineEdit::text() const
{
Q_D(const QLineEdit);
QString res = d->text;
if (d->maskData)
res = d->stripString(d->text);
return (res.isNull() ? QString::fromLatin1("") : res);
}
void QLineEdit::setText(const QString& text)
{
Q_D(QLineEdit);
d->setText(text, -1, false);
#ifdef QT_KEYPAD_NAVIGATION
d->origText = d->text;
#endif
}
/*!
\property QLineEdit::displayText
\brief the displayed text
If \l echoMode is \l Normal this returns the same as text(); if
\l EchoMode is \l Password or \l PasswordEchoOnEdit it returns a string of asterisks
text().length() characters long, e.g. "******"; if \l EchoMode is
\l NoEcho returns an empty string, "".
By default, this property contains an empty string.
\sa setEchoMode() text() EchoMode
*/
QString QLineEdit::displayText() const
{
Q_D(const QLineEdit);
if (d->echoMode == NoEcho)
return QString::fromLatin1("");
QString res = d->text;
if (d->echoMode == Password || (d->echoMode == PasswordEchoOnEdit
&& !d->passwordEchoEditing)) {
QStyleOptionFrameV2 opt;
initStyleOption(&opt);
res.fill(style()->styleHint(QStyle::SH_LineEdit_PasswordCharacter, &opt, this));
}
return (res.isNull() ? QString::fromLatin1("") : res);
}
/*!
\property QLineEdit::maxLength
\brief the maximum permitted length of the text
If the text is too long, it is truncated at the limit.
If truncation occurs any selected text will be unselected, the
cursor position is set to 0 and the first part of the string is
shown.
If the line edit has an input mask, the mask defines the maximum
string length.
By default, this property contains a value of 32767.
\sa inputMask
*/
int QLineEdit::maxLength() const
{
Q_D(const QLineEdit);
return d->maxLength;
}
void QLineEdit::setMaxLength(int maxLength)
{
Q_D(QLineEdit);
if (d->maskData)
return;
d->maxLength = maxLength;
setText(d->text);
}
/*!
\property QLineEdit::frame
\brief whether the line edit draws itself with a frame
If enabled (the default) the line edit draws itself inside a
frame, otherwise the line edit draws itself without any frame.
*/
bool QLineEdit::hasFrame() const
{
Q_D(const QLineEdit);
return d->frame;
}
void QLineEdit::setFrame(bool enable)
{
Q_D(QLineEdit);
d->frame = enable;
update();
updateGeometry();
}
/*!
\enum QLineEdit::EchoMode
This enum type describes how a line edit should display its
contents.
\value Normal Display characters as they are entered. This is the
default.
\value NoEcho Do not display anything. This may be appropriate
for passwords where even the length of the
password should be kept secret.
\value Password Display asterisks instead of the characters
actually entered.
\value PasswordEchoOnEdit Display characters as they are entered
while editing otherwise display asterisks.
\sa setEchoMode() echoMode()
*/
/*!
\property QLineEdit::echoMode
\brief the line edit's echo mode
The echo mode determines how the text entered in the line edit is
displayed (or echoed) to the user.
The most common setting is \l Normal, in which the text entered by the
user is displayed verbatim, but QLineEdit also supports modes that allow
the entered text to be suppressed or obscured: these include \l NoEcho,
\l Password and \l PasswordEchoOnEdit.
The widget's display and the ability to copy or drag the text is
affected by this setting.
By default, this property is set to \l Normal.
\sa EchoMode displayText()
*/
QLineEdit::EchoMode QLineEdit::echoMode() const
{
Q_D(const QLineEdit);
return (EchoMode) d->echoMode;
}
void QLineEdit::setEchoMode(EchoMode mode)
{
Q_D(QLineEdit);
if (mode == (EchoMode)d->echoMode)
return;
Qt::InputMethodHints imHints = inputMethodHints();
if (mode == Password) {
imHints |= Qt::ImhHiddenText;
} else {
imHints &= ~Qt::ImhHiddenText;
}
setInputMethodHints(imHints);
d->echoMode = mode;
d->passwordEchoEditing = false;
d->updateTextLayout();
update();
#ifdef Q_WS_MAC
if (hasFocus())
qt_mac_secure_keyboard(d->echoMode == Password || d->echoMode == NoEcho);
#endif
}
#ifndef QT_NO_VALIDATOR
/*!
Returns a pointer to the current input validator, or 0 if no
validator has been set.
\sa setValidator()
*/
const QValidator * QLineEdit::validator() const
{
Q_D(const QLineEdit);
return d->validator;
}
/*!
Sets this line edit to only accept input that the validator, \a v,
will accept. This allows you to place any arbitrary constraints on
the text which may be entered.
If \a v == 0, setValidator() removes the current input validator.
The initial setting is to have no input validator (i.e. any input
is accepted up to maxLength()).
\sa validator() QIntValidator QDoubleValidator QRegExpValidator
*/
void QLineEdit::setValidator(const QValidator *v)
{
Q_D(QLineEdit);
d->validator = const_cast<QValidator*>(v);
}
#endif // QT_NO_VALIDATOR
#ifndef QT_NO_COMPLETER
/*!
\since 4.2
Sets this line edit to provide auto completions from the completer, \a c.
The completion mode is set using QCompleter::setCompletionMode().
To use a QCompleter with a QValidator or QLineEdit::inputMask, you need to
ensure that the model provided to QCompleter contains valid entries. You can
use the QSortFilterProxyModel to ensure that the QCompleter's model contains
only valid entries.
If \a c == 0, setCompleter() removes the current completer, effectively
disabling auto completion.
\sa QCompleter
*/
void QLineEdit::setCompleter(QCompleter *c)
{
Q_D(QLineEdit);
if (c == d->completer)
return;
if (d->completer) {
disconnect(d->completer, 0, this, 0);
d->completer->setWidget(0);
if (d->completer->parent() == this)
delete d->completer;
}
d->completer = c;
if (!c)
return;
if (c->widget() == 0)
c->setWidget(this);
if (hasFocus()) {
QObject::connect(d->completer, SIGNAL(activated(QString)),
this, SLOT(setText(QString)));
QObject::connect(d->completer, SIGNAL(highlighted(QString)),
this, SLOT(_q_completionHighlighted(QString)));
}
}
/*!
\since 4.2
Returns the current QCompleter that provides completions.
*/
QCompleter *QLineEdit::completer() const
{
Q_D(const QLineEdit);
return d->completer;
}
// looks for an enabled item iterating forward(dir=1)/backward(dir=-1) from the
// current row based. dir=0 indicates a new completion prefix was set.
bool QLineEditPrivate::advanceToEnabledItem(int dir)
{
int start = completer->currentRow();
if (start == -1)
return false;
int i = start + dir;
if (dir == 0) dir = 1;
do {
if (!completer->setCurrentRow(i)) {
if (!completer->wrapAround())
break;
i = i > 0 ? 0 : completer->completionCount() - 1;
} else {
QModelIndex currentIndex = completer->currentIndex();
if (completer->completionModel()->flags(currentIndex) & Qt::ItemIsEnabled)
return true;
i += dir;
}
} while (i != start);
completer->setCurrentRow(start); // restore
return false;
}
void QLineEditPrivate::complete(int key)
{
if (!completer || readOnly || echoMode != QLineEdit::Normal)
return;
if (completer->completionMode() == QCompleter::InlineCompletion) {
if (key == Qt::Key_Backspace)
return;
int n = 0;
if (key == Qt::Key_Up || key == Qt::Key_Down) {
if (selend != 0 && selend != text.length())
return;
QString prefix = hasSelectedText() ? text.left(selstart) : text;
if (text.compare(completer->currentCompletion(), completer->caseSensitivity()) != 0
|| prefix.compare(completer->completionPrefix(), completer->caseSensitivity()) != 0) {
completer->setCompletionPrefix(prefix);
} else {
n = (key == Qt::Key_Up) ? -1 : +1;
}
} else {
completer->setCompletionPrefix(text);
}
if (!advanceToEnabledItem(n))
return;
} else {
#ifndef QT_KEYPAD_NAVIGATION
if (text.isEmpty()) {
completer->popup()->hide();
return;
}
#endif
completer->setCompletionPrefix(text);
}
completer->complete();
}
void QLineEditPrivate::_q_completionHighlighted(QString newText)
{
Q_Q(QLineEdit);
if (completer->completionMode() != QCompleter::InlineCompletion)
q->setText(newText);
else {
int c = cursor;
q->setText(text.left(c) + newText.mid(c));
q->setSelection(text.length(), c - newText.length());
}
}
#endif // QT_NO_COMPLETER
/*!
Returns a recommended size for the widget.
The width returned, in pixels, is usually enough for about 15 to
20 characters.
*/
QSize QLineEdit::sizeHint() const
{
Q_D(const QLineEdit);
ensurePolished();
QFontMetrics fm(font());
int h = qMax(fm.lineSpacing(), 14) + 2*verticalMargin
+ d->topTextMargin + d->bottomTextMargin
+ d->topmargin + d->bottommargin;
int w = fm.width(QLatin1Char('x')) * 17 + 2*horizontalMargin
+ d->leftTextMargin + d->rightTextMargin
+ d->leftmargin + d->rightmargin; // "some"
QStyleOptionFrameV2 opt;
initStyleOption(&opt);
return (style()->sizeFromContents(QStyle::CT_LineEdit, &opt, QSize(w, h).
expandedTo(QApplication::globalStrut()), this));
}
/*!
Returns a minimum size for the line edit.
The width returned is enough for at least one character.
*/
QSize QLineEdit::minimumSizeHint() const
{
Q_D(const QLineEdit);
ensurePolished();
QFontMetrics fm = fontMetrics();
int h = fm.height() + qMax(2*verticalMargin, fm.leading())
+ d->topmargin + d->bottommargin;
int w = fm.maxWidth() + d->leftmargin + d->rightmargin;
QStyleOptionFrameV2 opt;
initStyleOption(&opt);
return (style()->sizeFromContents(QStyle::CT_LineEdit, &opt, QSize(w, h).
expandedTo(QApplication::globalStrut()), this));
}
/*!
\property QLineEdit::cursorPosition
\brief the current cursor position for this line edit
Setting the cursor position causes a repaint when appropriate.
By default, this property contains a value of 0.
*/
int QLineEdit::cursorPosition() const
{
Q_D(const QLineEdit);
return d->cursor;
}
void QLineEdit::setCursorPosition(int pos)
{
Q_D(QLineEdit);
if (pos < 0)
pos = 0;
if (pos <= d->text.length())
d->moveCursor(pos);
}
/*!
Returns the cursor position under the point \a pos.
*/
// ### What should this do if the point is outside of contentsRect? Currently returns 0.
int QLineEdit::cursorPositionAt(const QPoint &pos)
{
Q_D(QLineEdit);
return d->xToPos(pos.x());
}
#ifdef QT3_SUPPORT
/*! \obsolete
Use setText(), setCursorPosition() and setSelection() instead.
*/
bool QLineEdit::validateAndSet(const QString &newText, int newPos,
int newMarkAnchor, int newMarkDrag)
{
Q_D(QLineEdit);
int priorState = d->undoState;
d->selstart = 0;
d->selend = d->text.length();
d->removeSelectedText();
d->insert(newText);
d->finishChange(priorState);
if (d->undoState > priorState) {
d->cursor = newPos;
d->selstart = qMin(newMarkAnchor, newMarkDrag);
d->selend = qMax(newMarkAnchor, newMarkDrag);
update();
d->emitCursorPositionChanged();
return true;
}
return false;
}
#endif //QT3_SUPPORT
/*!
\property QLineEdit::alignment
\brief the alignment of the line edit
Both horizontal and vertical alignment is allowed here, Qt::AlignJustify
will map to Qt::AlignLeft.
By default, this property contains a combination of Qt::AlignLeft and Qt::AlignVCenter.
\sa Qt::Alignment
*/
Qt::Alignment QLineEdit::alignment() const
{
Q_D(const QLineEdit);
return QFlag(d->alignment);
}
void QLineEdit::setAlignment(Qt::Alignment alignment)
{
Q_D(QLineEdit);
d->alignment = alignment;
update();
}
/*!
Moves the cursor forward \a steps characters. If \a mark is true
each character moved over is added to the selection; if \a mark is
false the selection is cleared.
\sa cursorBackward()
*/
void QLineEdit::cursorForward(bool mark, int steps)
{
Q_D(QLineEdit);
int cursor = d->cursor;
if (steps > 0) {
while(steps--)
cursor = d->textLayout.nextCursorPosition(cursor);
} else if (steps < 0) {
while (steps++)
cursor = d->textLayout.previousCursorPosition(cursor);
}
d->moveCursor(cursor, mark);
}
/*!
Moves the cursor back \a steps characters. If \a mark is true each
character moved over is added to the selection; if \a mark is
false the selection is cleared.
\sa cursorForward()
*/
void QLineEdit::cursorBackward(bool mark, int steps)
{
cursorForward(mark, -steps);
}
/*!
Moves the cursor one word forward. If \a mark is true, the word is
also selected.
\sa cursorWordBackward()
*/
void QLineEdit::cursorWordForward(bool mark)
{
Q_D(QLineEdit);
d->moveCursor(d->textLayout.nextCursorPosition(d->cursor, QTextLayout::SkipWords), mark);
}
/*!
Moves the cursor one word backward. If \a mark is true, the word
is also selected.
\sa cursorWordForward()
*/
void QLineEdit::cursorWordBackward(bool mark)
{
Q_D(QLineEdit);
d->moveCursor(d->textLayout.previousCursorPosition(d->cursor, QTextLayout::SkipWords), mark);
}
/*!
If no text is selected, deletes the character to the left of the
text cursor and moves the cursor one position to the left. If any
text is selected, the cursor is moved to the beginning of the
selected text and the selected text is deleted.
\sa del()
*/
void QLineEdit::backspace()
{
Q_D(QLineEdit);
int priorState = d->undoState;
if (d->hasSelectedText()) {
d->removeSelectedText();
} else if (d->cursor) {
--d->cursor;
if (d->maskData)
d->cursor = d->prevMaskBlank(d->cursor);
QChar uc = d->text.at(d->cursor);
if (d->cursor > 0 && uc.unicode() >= 0xdc00 && uc.unicode() < 0xe000) {
// second half of a surrogate, check if we have the first half as well,
// if yes delete both at once
uc = d->text.at(d->cursor - 1);
if (uc.unicode() >= 0xd800 && uc.unicode() < 0xdc00) {
d->del(true);
--d->cursor;
}
}
d->del(true);
}
d->finishChange(priorState);
}
/*!
If no text is selected, deletes the character to the right of the
text cursor. If any text is selected, the cursor is moved to the
beginning of the selected text and the selected text is deleted.
\sa backspace()
*/
void QLineEdit::del()
{
Q_D(QLineEdit);
int priorState = d->undoState;
if (d->hasSelectedText()) {
d->removeSelectedText();
} else {
int n = d->textLayout.nextCursorPosition(d->cursor) - d->cursor;
while (n--)
d->del();
}
d->finishChange(priorState);
}
/*!
Moves the text cursor to the beginning of the line unless it is
already there. If \a mark is true, text is selected towards the
first position; otherwise, any selected text is unselected if the
cursor is moved.
\sa end()
*/
void QLineEdit::home(bool mark)
{
Q_D(QLineEdit);
d->moveCursor(0, mark);
}
/*!
Moves the text cursor to the end of the line unless it is already
there. If \a mark is true, text is selected towards the last
position; otherwise, any selected text is unselected if the cursor
is moved.
\sa home()
*/
void QLineEdit::end(bool mark)
{
Q_D(QLineEdit);
d->moveCursor(d->text.length(), mark);
}
/*!
\property QLineEdit::modified
\brief whether the line edit's contents has been modified by the user
The modified flag is never read by QLineEdit; it has a default value
of false and is changed to true whenever the user changes the line
edit's contents.
This is useful for things that need to provide a default value but
do not start out knowing what the default should be (perhaps it
depends on other fields on the form). Start the line edit without
the best default, and when the default is known, if modified()
returns false (the user hasn't entered any text), insert the
default value.
Calling setText() resets the modified flag to false.
*/
bool QLineEdit::isModified() const
{
Q_D(const QLineEdit);
return d->modifiedState != d->undoState;
}
void QLineEdit::setModified(bool modified)
{
Q_D(QLineEdit);
if (modified)
d->modifiedState = -1;
else
d->modifiedState = d->undoState;
}
/*!\fn QLineEdit::clearModified()
Use setModified(false) instead.
\sa isModified()
*/
/*!
\property QLineEdit::hasSelectedText
\brief whether there is any text selected
hasSelectedText() returns true if some or all of the text has been
selected by the user; otherwise returns false.
By default, this property is false.
\sa selectedText()
*/
bool QLineEdit::hasSelectedText() const
{
Q_D(const QLineEdit);
return d->hasSelectedText();
}
/*!
\property QLineEdit::selectedText
\brief the selected text
If there is no selected text this property's value is
an empty string.
By default, this property contains an empty string.
\sa hasSelectedText()
*/
QString QLineEdit::selectedText() const
{
Q_D(const QLineEdit);
if (d->hasSelectedText())
return d->text.mid(d->selstart, d->selend - d->selstart);
return QString();
}
/*!
selectionStart() returns the index of the first selected character in the
line edit or -1 if no text is selected.
\sa selectedText()
*/
int QLineEdit::selectionStart() const
{
Q_D(const QLineEdit);
return d->hasSelectedText() ? d->selstart : -1;
}
#ifdef QT3_SUPPORT
/*!
\fn void QLineEdit::lostFocus()
This signal is emitted when the line edit has lost focus.
Use editingFinished() instead
\sa editingFinished(), returnPressed()
*/
/*!
Use isModified() instead.
*/
bool QLineEdit::edited() const { return isModified(); }
/*!
Use setModified() or setText().
*/
void QLineEdit::setEdited(bool on) { setModified(on); }
/*!
There exists no equivalent functionality in Qt 4.
*/
int QLineEdit::characterAt(int xpos, QChar *chr) const
{
Q_D(const QLineEdit);
int pos = d->xToPos(xpos + contentsRect().x() - d->hscroll + horizontalMargin);
if (chr && pos < (int) d->text.length())
*chr = d->text.at(pos);
return pos;
}
/*!
Use selectedText() and selectionStart() instead.
*/
bool QLineEdit::getSelection(int *start, int *end)
{
Q_D(QLineEdit);
if (d->hasSelectedText() && start && end) {
*start = d->selstart;
*end = d->selend;
return true;
}
return false;
}
#endif
/*!
Selects text from position \a start and for \a length characters.
Negative lengths are allowed.
\sa deselect() selectAll() selectedText()
*/
void QLineEdit::setSelection(int start, int length)
{
Q_D(QLineEdit);
if (start < 0 || start > (int)d->text.length()) {
qWarning("QLineEdit::setSelection: Invalid start position (%d)", start);
return;
} else {
if (length > 0) {
d->selstart = start;
d->selend = qMin(start + length, (int)d->text.length());
d->cursor = d->selend;
} else {
d->selstart = qMax(start + length, 0);
d->selend = start;
d->cursor = d->selstart;
}
}
if (d->hasSelectedText()){
QStyleOptionFrameV2 opt;
initStyleOption(&opt);
if (!style()->styleHint(QStyle::SH_BlinkCursorWhenTextSelected, &opt, this))
d->setCursorVisible(false);
}
update();
d->emitCursorPositionChanged();
}
/*!
\property QLineEdit::undoAvailable
\brief whether undo is available
Undo becomes available once the user has modified the text in the line edit.
By default, this property is false.
*/
bool QLineEdit::isUndoAvailable() const
{
Q_D(const QLineEdit);
return d->isUndoAvailable();
}
/*!
\property QLineEdit::redoAvailable
\brief whether redo is available
Redo becomes available once the user has performed one or more undo operations
on text in the line edit.
By default, this property is false.
*/
bool QLineEdit::isRedoAvailable() const
{
Q_D(const QLineEdit);
return d->isRedoAvailable();
}
/*!
\property QLineEdit::dragEnabled
\brief whether the lineedit starts a drag if the user presses and
moves the mouse on some selected text
Dragging is disabled by default.
*/
bool QLineEdit::dragEnabled() const
{
Q_D(const QLineEdit);
return d->dragEnabled;
}
void QLineEdit::setDragEnabled(bool b)
{
Q_D(QLineEdit);
d->dragEnabled = b;
}
/*!
\property QLineEdit::acceptableInput
\brief whether the input satisfies the inputMask and the
validator.
By default, this property is true.
\sa setInputMask(), setValidator()
*/
bool QLineEdit::hasAcceptableInput() const
{
Q_D(const QLineEdit);
return d->hasAcceptableInput(d->text);
}
/*!
Sets the margins around the text inside the frame to have the
sizes \a left, \a top, \a right, and \a bottom.
\since 4.5
See also getTextMargins().
*/
void QLineEdit::setTextMargins(int left, int top, int right, int bottom)
{
Q_D(QLineEdit);
d->leftTextMargin = left;
d->topTextMargin = top;
d->rightTextMargin = right;
d->bottomTextMargin = bottom;
updateGeometry();
update();
}
/*!
Returns the widget's text margins for \a left, \a top, \a right, and \a bottom.
\since 4.5
\sa setTextMargins()
*/
void QLineEdit::getTextMargins(int *left, int *top, int *right, int *bottom) const
{
Q_D(const QLineEdit);
if (left)
*left = d->leftTextMargin;
if (top)
*top = d->topTextMargin;
if (right)
*right = d->rightTextMargin;
if (bottom)
*bottom = d->bottomTextMargin;
}
/*!
\property QLineEdit::inputMask
\brief The validation input mask
If no mask is set, inputMask() returns an empty string.
Sets the QLineEdit's validation mask. Validators can be used
instead of, or in conjunction with masks; see setValidator().
Unset the mask and return to normal QLineEdit operation by passing
an empty string ("") or just calling setInputMask() with no
arguments.
The table below shows the characters that can be used in an input mask.
A space character, the default character for a blank, is needed for cases
where a character is \e{permitted but not required}.
\table
\header \i Character \i Meaning
\row \i \c A \i ASCII alphabetic character required. A-Z, a-z.
\row \i \c a \i ASCII alphabetic character permitted but not required.
\row \i \c N \i ASCII alphanumeric character required. A-Z, a-z, 0-9.
\row \i \c n \i ASCII alphanumeric character permitted but not required.
\row \i \c X \i Any character required.
\row \i \c x \i Any character permitted but not required.
\row \i \c 9 \i ASCII digit required. 0-9.
\row \i \c 0 \i ASCII digit permitted but not required.
\row \i \c D \i ASCII digit required. 1-9.
\row \i \c d \i ASCII digit permitted but not required (1-9).
\row \i \c # \i ASCII digit or plus/minus sign permitted but not required.
\row \i \c H \i Hexadecimal character required. A-F, a-f, 0-9.
\row \i \c h \i Hexadecimal character permitted but not required.
\row \i \c B \i Binary character required. 0-1.
\row \i \c b \i Binary character permitted but not required.
\row \i \c > \i All following alphabetic characters are uppercased.
\row \i \c < \i All following alphabetic characters are lowercased.
\row \i \c ! \i Switch off case conversion.
\row \i \tt{\\} \i Use \tt{\\} to escape the special
characters listed above to use them as
separators.
\endtable
The mask consists of a string of mask characters and separators,
optionally followed by a semicolon and the character used for
blanks. The blank characters are always removed from the text
after editing.
Examples:
\table
\header \i Mask \i Notes
\row \i \c 000.000.000.000;_ \i IP address; blanks are \c{_}.
\row \i \c HH:HH:HH:HH:HH:HH;_ \i MAC address
\row \i \c 0000-00-00 \i ISO Date; blanks are \c space
\row \i \c >AAAAA-AAAAA-AAAAA-AAAAA-AAAAA;# \i License number;
blanks are \c - and all (alphabetic) characters are converted to
uppercase.
\endtable
To get range control (e.g., for an IP address) use masks together
with \link setValidator() validators\endlink.
\sa maxLength
*/
QString QLineEdit::inputMask() const
{
Q_D(const QLineEdit);
return (d->maskData ? d->inputMask + QLatin1Char(';') + d->blank : QString());
}
void QLineEdit::setInputMask(const QString &inputMask)
{
Q_D(QLineEdit);
d->parseInputMask(inputMask);
if (d->maskData)
d->moveCursor(d->nextMaskBlank(0));
}
/*!
Selects all the text (i.e. highlights it) and moves the cursor to
the end. This is useful when a default value has been inserted
because if the user types before clicking on the widget, the
selected text will be deleted.
\sa setSelection() deselect()
*/
void QLineEdit::selectAll()
{
Q_D(QLineEdit);
d->selstart = d->selend = d->cursor = 0;
d->moveCursor(d->text.length(), true);
}
/*!
Deselects any selected text.
\sa setSelection() selectAll()
*/
void QLineEdit::deselect()
{
Q_D(QLineEdit);
d->deselect();
d->finishChange();
}
/*!
Deletes any selected text, inserts \a newText, and validates the
result. If it is valid, it sets it as the new contents of the line
edit.
\sa setText(), clear()
*/
void QLineEdit::insert(const QString &newText)
{
// q->resetInputContext(); //#### FIX ME IN QT
Q_D(QLineEdit);
int priorState = d->undoState;
d->removeSelectedText();
d->insert(newText);
d->finishChange(priorState);
}
/*!
Clears the contents of the line edit.
\sa setText(), insert()
*/
void QLineEdit::clear()
{
Q_D(QLineEdit);
int priorState = d->undoState;
resetInputContext();
d->selstart = 0;
d->selend = d->text.length();
d->removeSelectedText();
d->separate();
d->finishChange(priorState, /*update*/false, /*edited*/false);
}
/*!
Undoes the last operation if undo is \link
QLineEdit::undoAvailable available\endlink. Deselects any current
selection, and updates the selection start to the current cursor
position.
*/
void QLineEdit::undo()
{
Q_D(QLineEdit);
resetInputContext();
d->undo();
d->finishChange(-1, true);
}
/*!
Redoes the last operation if redo is \link
QLineEdit::redoAvailable available\endlink.
*/
void QLineEdit::redo()
{
Q_D(QLineEdit);
resetInputContext();
d->redo();
d->finishChange();
}
/*!
\property QLineEdit::readOnly
\brief whether the line edit is read only.
In read-only mode, the user can still copy the text to the
clipboard, or drag and drop the text (if echoMode() is \l Normal),
but cannot edit it.
QLineEdit does not show a cursor in read-only mode.
By default, this property is false.
\sa setEnabled()
*/
bool QLineEdit::isReadOnly() const
{
Q_D(const QLineEdit);
return d->readOnly;
}
void QLineEdit::setReadOnly(bool enable)
{
Q_D(QLineEdit);
if (d->readOnly != enable) {
d->readOnly = enable;
setAttribute(Qt::WA_MacShowFocusRect, !d->readOnly);
setAttribute(Qt::WA_InputMethodEnabled, shouldEnableInputMethod(this));
#ifndef QT_NO_CURSOR
setCursor(enable ? Qt::ArrowCursor : Qt::IBeamCursor);
#endif
update();
}
}
#ifndef QT_NO_CLIPBOARD
/*!
Copies the selected text to the clipboard and deletes it, if there
is any, and if echoMode() is \l Normal.
If the current validator disallows deleting the selected text,
cut() will copy without deleting.
\sa copy() paste() setValidator()
*/
void QLineEdit::cut()
{
if (hasSelectedText()) {
copy();
del();
}
}
/*!
Copies the selected text to the clipboard, if there is any, and if
echoMode() is \l Normal.
\sa cut() paste()
*/
void QLineEdit::copy() const
{
Q_D(const QLineEdit);
d->copy();
}
/*!
Inserts the clipboard's text at the cursor position, deleting any
selected text, providing the line edit is not \link
QLineEdit::readOnly read-only\endlink.
If the end result would not be acceptable to the current
\link setValidator() validator\endlink, nothing happens.
\sa copy() cut()
*/
void QLineEdit::paste()
{
Q_D(QLineEdit);
if (echoMode() == PasswordEchoOnEdit && !d->passwordEchoEditing) {
// Clear the edit and reset to normal echo mode when pasting; the echo
// mode switches back when the edit loses focus. ### changes a public
// property, resets current content
d->updatePasswordEchoEditing(true);
clear();
}
insert(QApplication::clipboard()->text(QClipboard::Clipboard));
}
void QLineEditPrivate::copy(bool clipboard) const
{
Q_Q(const QLineEdit);
QString t = q->selectedText();
if (!t.isEmpty() && echoMode == QLineEdit::Normal) {
QApplication::clipboard()->setText(t, clipboard ? QClipboard::Clipboard : QClipboard::Selection);
}
}
#endif // !QT_NO_CLIPBOARD
/*! \reimp
*/
bool QLineEdit::event(QEvent * e)
{
Q_D(QLineEdit);
#ifndef QT_NO_SHORTCUT
if (e->type() == QEvent::ShortcutOverride && !d->readOnly) {
QKeyEvent* ke = (QKeyEvent*) e;
if (ke == QKeySequence::Copy
|| ke == QKeySequence::Paste
|| ke == QKeySequence::Cut
|| ke == QKeySequence::Redo
|| ke == QKeySequence::Undo
|| ke == QKeySequence::MoveToNextWord
|| ke == QKeySequence::MoveToPreviousWord
|| ke == QKeySequence::MoveToStartOfDocument
|| ke == QKeySequence::MoveToEndOfDocument
|| ke == QKeySequence::SelectNextWord
|| ke == QKeySequence::SelectPreviousWord
|| ke == QKeySequence::SelectStartOfLine
|| ke == QKeySequence::SelectEndOfLine
|| ke == QKeySequence::SelectStartOfBlock
|| ke == QKeySequence::SelectEndOfBlock
|| ke == QKeySequence::SelectStartOfDocument
|| ke == QKeySequence::SelectAll
|| ke == QKeySequence::SelectEndOfDocument) {
ke->accept();
} else if (ke->modifiers() == Qt::NoModifier || ke->modifiers() == Qt::ShiftModifier
|| ke->modifiers() == Qt::KeypadModifier) {
if (ke->key() < Qt::Key_Escape) {
ke->accept();
} else {
switch (ke->key()) {
case Qt::Key_Delete:
case Qt::Key_Home:
case Qt::Key_End:
case Qt::Key_Backspace:
case Qt::Key_Left:
case Qt::Key_Right:
ke->accept();
default:
break;
}
}
}
} else
#endif
if (e->type() == QEvent::Timer) {
// should be timerEvent, is here for binary compatibility
int timerId = ((QTimerEvent*)e)->timerId();
if (timerId == d->cursorTimer) {
QStyleOptionFrameV2 opt;
initStyleOption(&opt);
if(!hasSelectedText()
|| style()->styleHint(QStyle::SH_BlinkCursorWhenTextSelected, &opt, this))
d->setCursorVisible(!d->cursorVisible);
#ifndef QT_NO_DRAGANDDROP
} else if (timerId == d->dndTimer.timerId()) {
d->drag();
#endif
}
else if (timerId == d->tripleClickTimer.timerId())
d->tripleClickTimer.stop();
#ifdef QT_KEYPAD_NAVIGATION
else if (timerId == d->deleteAllTimer.timerId()) {
d->deleteAllTimer.stop();
clear();
}
#endif
} else if (e->type() == QEvent::ContextMenu) {
#ifndef QT_NO_IM
if (d->composeMode())
return true;
#endif
d->separate();
} else if (e->type() == QEvent::WindowActivate) {
QTimer::singleShot(0, this, SLOT(_q_handleWindowActivate()));
}
#ifdef QT_KEYPAD_NAVIGATION
if (QApplication::keypadNavigationEnabled()) {
if ((e->type() == QEvent::KeyPress) || (e->type() == QEvent::KeyRelease)) {
QKeyEvent *ke = (QKeyEvent *)e;
if (ke->key() == Qt::Key_Back) {
if (ke->isAutoRepeat()) {
// Swallow it. We don't want back keys running amok.
ke->accept();
return true;
}
if ((e->type() == QEvent::KeyRelease)
&& !isReadOnly()
&& d->deleteAllTimer.isActive()) {
d->deleteAllTimer.stop();
backspace();
ke->accept();
return true;
}
}
} else if (e->type() == QEvent::EnterEditFocus) {
end(false);
if (!d->cursorTimer) {
int cft = QApplication::cursorFlashTime();
d->cursorTimer = cft ? startTimer(cft/2) : -1;
}
} else if (e->type() == QEvent::LeaveEditFocus) {
d->setCursorVisible(false);
if (d->cursorTimer > 0)
killTimer(d->cursorTimer);
d->cursorTimer = 0;
if (!d->emitingEditingFinished) {
if (hasAcceptableInput() || d->fixup()) {
d->emitingEditingFinished = true;
emit editingFinished();
d->emitingEditingFinished = false;
}
}
}
}
#endif
return QWidget::event(e);
}
/*! \reimp
*/
void QLineEdit::mousePressEvent(QMouseEvent* e)
{
Q_D(QLineEdit);
if (d->sendMouseEventToInputContext(e))
return;
if (e->button() == Qt::RightButton)
return;
#ifdef QT_KEYPAD_NAVIGATION
if (QApplication::keypadNavigationEnabled() && !hasEditFocus()) {
setEditFocus(true);
// Get the completion list to pop up.
if (d->completer)
d->completer->complete();
}
#endif
if (d->tripleClickTimer.isActive() && (e->pos() - d->tripleClick).manhattanLength() <
QApplication::startDragDistance()) {
selectAll();
return;
}
bool mark = e->modifiers() & Qt::ShiftModifier;
int cursor = d->xToPos(e->pos().x());
#ifndef QT_NO_DRAGANDDROP
if (!mark && d->dragEnabled && d->echoMode == Normal &&
e->button() == Qt::LeftButton && d->inSelection(e->pos().x())) {
d->cursor = cursor;
update();
d->dndPos = e->pos();
if (!d->dndTimer.isActive())
d->dndTimer.start(QApplication::startDragTime(), this);
d->emitCursorPositionChanged();
} else
#endif
{
d->moveCursor(cursor, mark);
}
}
/*! \reimp
*/
void QLineEdit::mouseMoveEvent(QMouseEvent * e)
{
Q_D(QLineEdit);
if (d->sendMouseEventToInputContext(e))
return;
if (e->buttons() & Qt::LeftButton) {
#ifndef QT_NO_DRAGANDDROP
if (d->dndTimer.isActive()) {
if ((d->dndPos - e->pos()).manhattanLength() > QApplication::startDragDistance())
d->drag();
} else
#endif
{
d->moveCursor(d->xToPos(e->pos().x()), true);
}
}
}
/*! \reimp
*/
void QLineEdit::mouseReleaseEvent(QMouseEvent* e)
{
Q_D(QLineEdit);
if (d->sendMouseEventToInputContext(e))
return;
#ifndef QT_NO_DRAGANDDROP
if (e->button() == Qt::LeftButton) {
if (d->dndTimer.isActive()) {
d->dndTimer.stop();
deselect();
return;
}
}
#endif
#ifndef QT_NO_CLIPBOARD
if (QApplication::clipboard()->supportsSelection()) {
if (e->button() == Qt::LeftButton) {
d->copy(false);
} else if (!d->readOnly && e->button() == Qt::MidButton) {
d->deselect();
insert(QApplication::clipboard()->text(QClipboard::Selection));
}
}
#endif
if (e->button() == Qt::LeftButton && qApp->autoSipEnabled()
&& (!d->clickCausedFocus || qApp->autoSipOnMouseFocus())) {
QEvent event(QEvent::RequestSoftwareInputPanel);
QApplication::sendEvent(this, &event);
}
d->clickCausedFocus = 0;
}
/*! \reimp
*/
void QLineEdit::mouseDoubleClickEvent(QMouseEvent* e)
{
Q_D(QLineEdit);
if (d->sendMouseEventToInputContext(e))
return;
if (e->button() == Qt::LeftButton) {
deselect();
d->cursor = d->xToPos(e->pos().x());
d->cursor = d->textLayout.previousCursorPosition(d->cursor, QTextLayout::SkipWords);
// ## text layout should support end of words.
int end = d->textLayout.nextCursorPosition(d->cursor, QTextLayout::SkipWords);
while (end > d->cursor && d->text[end-1].isSpace())
--end;
d->moveCursor(end, true);
d->tripleClickTimer.start(QApplication::doubleClickInterval(), this);
d->tripleClick = e->pos();
}
}
/*!
\fn void QLineEdit::returnPressed()
This signal is emitted when the Return or Enter key is pressed.
Note that if there is a validator() or inputMask() set on the line
edit, the returnPressed() signal will only be emitted if the input
follows the inputMask() and the validator() returns
QValidator::Acceptable.
*/
/*!
\fn void QLineEdit::editingFinished()
This signal is emitted when the Return or Enter key is pressed or
the line edit loses focus. Note that if there is a validator() or
inputMask() set on the line edit and enter/return is pressed, the
editingFinished() signal will only be emitted if the input follows
the inputMask() and the validator() returns QValidator::Acceptable.
*/
/*!
Converts the given key press \a event into a line edit action.
If Return or Enter is pressed and the current text is valid (or
can be \link QValidator::fixup() made valid\endlink by the
validator), the signal returnPressed() is emitted.
The default key bindings are listed in the class's detailed
description.
*/
void QLineEdit::keyPressEvent(QKeyEvent *event)
{
Q_D(QLineEdit);
bool inlineCompletionAccepted = false;
#ifndef QT_NO_COMPLETER
if (d->completer) {
QCompleter::CompletionMode completionMode = d->completer->completionMode();
if ((completionMode == QCompleter::PopupCompletion
|| completionMode == QCompleter::UnfilteredPopupCompletion)
&&d->completer->popup()
&& d->completer->popup()->isVisible()) {
// The following keys are forwarded by the completer to the widget
// Ignoring the events lets the completer provide suitable default behavior
switch (event->key()) {
case Qt::Key_Escape:
event->ignore();
return;
case Qt::Key_Enter:
case Qt::Key_Return:
case Qt::Key_F4:
#ifdef QT_KEYPAD_NAVIGATION
case Qt::Key_Select:
if (!QApplication::keypadNavigationEnabled())
break;
#endif
d->completer->popup()->hide(); // just hide. will end up propagating to parent
default:
break; // normal key processing
}
} else if (completionMode == QCompleter::InlineCompletion) {
switch (event->key()) {
case Qt::Key_Enter:
case Qt::Key_Return:
case Qt::Key_F4:
#ifdef QT_KEYPAD_NAVIGATION
case Qt::Key_Select:
if (!QApplication::keypadNavigationEnabled())
break;
#endif
if (!d->completer->currentCompletion().isEmpty() && d->selend > d->selstart
&& d->selend == d->text.length()) {
setText(d->completer->currentCompletion());
inlineCompletionAccepted = true;
}
default:
break; // normal key processing
}
}
}
#endif // QT_NO_COMPLETER
#ifdef QT_KEYPAD_NAVIGATION
bool select = false;
switch (event->key()) {
case Qt::Key_Select:
if (QApplication::keypadNavigationEnabled()) {
if (hasEditFocus()) {
setEditFocus(false);
if (d->completer && d->completer->popup()->isVisible())
d->completer->popup()->hide();
select = true;
}
}
break;
case Qt::Key_Back:
case Qt::Key_No:
if (!QApplication::keypadNavigationEnabled() || !hasEditFocus()) {
event->ignore();
return;
}
break;
default:
if (QApplication::keypadNavigationEnabled()) {
if (!hasEditFocus() && !(event->modifiers() & Qt::ControlModifier)) {
if (!event->text().isEmpty() && event->text().at(0).isPrint()
&& !isReadOnly())
{
setEditFocus(true);
clear();
} else {
event->ignore();
return;
}
}
}
}
if (QApplication::keypadNavigationEnabled() && !select && !hasEditFocus()) {
setEditFocus(true);
if (event->key() == Qt::Key_Select)
return; // Just start. No action.
}
#endif
if (echoMode() == PasswordEchoOnEdit
&& !d->passwordEchoEditing
&& !isReadOnly()
&& !event->text().isEmpty()
#ifdef QT_KEYPAD_NAVIGATION
&& event->key() != Qt::Key_Select
&& event->key() != Qt::Key_Up
&& event->key() != Qt::Key_Down
&& event->key() != Qt::Key_Back
#endif
&& !(event->modifiers() & Qt::ControlModifier)) {
// Clear the edit and reset to normal echo mode while editing; the
// echo mode switches back when the edit loses focus. ### changes a
// public property, resets current content. dubious code; you can
// navigate with keys up, down, back, and select(?), but if you press
// "left" or "right" it clears?
d->updatePasswordEchoEditing(true);
clear();
}
d->setCursorVisible(true);
if (event->key() == Qt::Key_Enter || event->key() == Qt::Key_Return) {
if (hasAcceptableInput() || d->fixup()) {
emit returnPressed();
d->emitingEditingFinished = true;
emit editingFinished();
d->emitingEditingFinished = false;
}
if (inlineCompletionAccepted)
event->accept();
else
event->ignore();
return;
}
bool unknown = false;
if (false) {
}
#ifndef QT_NO_SHORTCUT
else if (event == QKeySequence::Undo) {
if (!d->readOnly)
undo();
}
else if (event == QKeySequence::Redo) {
if (!d->readOnly)
redo();
}
else if (event == QKeySequence::SelectAll) {
selectAll();
}
#ifndef QT_NO_CLIPBOARD
else if (event == QKeySequence::Copy) {
copy();
}
else if (event == QKeySequence::Paste) {
if (!d->readOnly)
paste();
}
else if (event == QKeySequence::Cut) {
if (!d->readOnly) {
cut();
}
}
else if (event == QKeySequence::DeleteEndOfLine) {
if (!d->readOnly) {
setSelection(d->cursor, d->text.size());
copy();
del();
}
}
#endif //QT_NO_CLIPBOARD
else if (event == QKeySequence::MoveToStartOfLine) {
home(0);
}
else if (event == QKeySequence::MoveToEndOfLine) {
end(0);
}
else if (event == QKeySequence::SelectStartOfLine) {
home(1);
}
else if (event == QKeySequence::SelectEndOfLine) {
end(1);
}
else if (event == QKeySequence::MoveToNextChar) {
#if !defined(Q_WS_WIN) || defined(QT_NO_COMPLETER)
if (d->hasSelectedText()) {
#else
if (d->hasSelectedText() && d->completer
&& d->completer->completionMode() == QCompleter::InlineCompletion) {
#endif
d->moveCursor(d->selend, false);
} else {
cursorForward(0, layoutDirection() == Qt::LeftToRight ? 1 : -1);
}
}
else if (event == QKeySequence::SelectNextChar) {
cursorForward(1, layoutDirection() == Qt::LeftToRight ? 1 : -1);
}
else if (event == QKeySequence::MoveToPreviousChar) {
#if !defined(Q_WS_WIN) || defined(QT_NO_COMPLETER)
if (d->hasSelectedText()) {
#else
if (d->hasSelectedText() && d->completer
&& d->completer->completionMode() == QCompleter::InlineCompletion) {
#endif
d->moveCursor(d->selstart, false);
} else {
cursorBackward(0, layoutDirection() == Qt::LeftToRight ? 1 : -1);
}
}
else if (event == QKeySequence::SelectPreviousChar) {
cursorBackward(1, layoutDirection() == Qt::LeftToRight ? 1 : -1);
}
else if (event == QKeySequence::MoveToNextWord) {
if (echoMode() == Normal)
layoutDirection() == Qt::LeftToRight ? cursorWordForward(0) : cursorWordBackward(0);
else
layoutDirection() == Qt::LeftToRight ? end(0) : home(0);
}
else if (event == QKeySequence::MoveToPreviousWord) {
if (echoMode() == Normal)
layoutDirection() == Qt::LeftToRight ? cursorWordBackward(0) : cursorWordForward(0);
else if (!d->readOnly) {
layoutDirection() == Qt::LeftToRight ? home(0) : end(0);
}
}
else if (event == QKeySequence::SelectNextWord) {
if (echoMode() == Normal)
layoutDirection() == Qt::LeftToRight ? cursorWordForward(1) : cursorWordBackward(1);
else
layoutDirection() == Qt::LeftToRight ? end(1) : home(1);
}
else if (event == QKeySequence::SelectPreviousWord) {
if (echoMode() == Normal)
layoutDirection() == Qt::LeftToRight ? cursorWordBackward(1) : cursorWordForward(1);
else
layoutDirection() == Qt::LeftToRight ? home(1) : end(1);
}
else if (event == QKeySequence::Delete) {
if (!d->readOnly)
del();
}
else if (event == QKeySequence::DeleteEndOfWord) {
if (!d->readOnly) {
cursorWordForward(true);
del();
}
}
else if (event == QKeySequence::DeleteStartOfWord) {
if (!d->readOnly) {
cursorWordBackward(true);
del();
}
}
#endif // QT_NO_SHORTCUT
else {
#ifdef Q_WS_MAC
if (event->key() == Qt::Key_Up || event->key() == Qt::Key_Down) {
Qt::KeyboardModifiers myModifiers = (event->modifiers() & ~Qt::KeypadModifier);
if (myModifiers & Qt::ShiftModifier) {
if (myModifiers == (Qt::ControlModifier|Qt::ShiftModifier)
|| myModifiers == (Qt::AltModifier|Qt::ShiftModifier)
|| myModifiers == Qt::ShiftModifier) {
event->key() == Qt::Key_Up ? home(1) : end(1);
}
} else {
if ((myModifiers == Qt::ControlModifier
|| myModifiers == Qt::AltModifier
|| myModifiers == Qt::NoModifier)) {
event->key() == Qt::Key_Up ? home(0) : end(0);
}
}
}
#endif
if (event->modifiers() & Qt::ControlModifier) {
switch (event->key()) {
case Qt::Key_Backspace:
if (!d->readOnly) {
cursorWordBackward(true);
del();
}
break;
#ifndef QT_NO_COMPLETER
case Qt::Key_Up:
case Qt::Key_Down:
d->complete(event->key());
break;
#endif
#if defined(Q_WS_X11)
case Qt::Key_E:
end(0);
break;
case Qt::Key_U:
if (!d->readOnly) {
setSelection(0, d->text.size());
#ifndef QT_NO_CLIPBOARD
copy();
#endif
del();
}
break;
#endif
default:
unknown = true;
}
} else { // ### check for *no* modifier
switch (event->key()) {
case Qt::Key_Backspace:
if (!d->readOnly) {
backspace();
#ifndef QT_NO_COMPLETER
d->complete(Qt::Key_Backspace);
#endif
}
break;
#ifdef QT_KEYPAD_NAVIGATION
case Qt::Key_Back:
if (QApplication::keypadNavigationEnabled() && !event->isAutoRepeat()
&& !isReadOnly()) {
if (text().length() == 0) {
setText(d->origText);
if (d->passwordEchoEditing)
d->updatePasswordEchoEditing(false);
setEditFocus(false);
} else if (!d->deleteAllTimer.isActive()) {
d->deleteAllTimer.start(750, this);
}
} else {
unknown = true;
}
break;
#endif
default:
unknown = true;
}
}
}
if (event->key() == Qt::Key_Direction_L || event->key() == Qt::Key_Direction_R) {
setLayoutDirection((event->key() == Qt::Key_Direction_L) ? Qt::LeftToRight : Qt::RightToLeft);
d->updateTextLayout();
update();
unknown = false;
}
if (unknown && !d->readOnly) {
QString t = event->text();
if (!t.isEmpty() && t.at(0).isPrint() &&
((event->modifiers() & (Qt::ControlModifier | Qt::AltModifier | Qt::MetaModifier)) == Qt::NoModifier)) {
insert(t);
#ifndef QT_NO_COMPLETER
d->complete(event->key());
#endif
event->accept();
return;
}
}
if (unknown)
event->ignore();
else
event->accept();
}
/*!
\since 4.4
Returns a rectangle that includes the lineedit cursor.
*/
QRect QLineEdit::cursorRect() const
{
Q_D(const QLineEdit);
return d->cursorRect();
}
/*!
This function is not intended as polymorphic usage. Just a shared code
fragment that calls QInputContext::mouseHandler for this
class.
*/
bool QLineEditPrivate::sendMouseEventToInputContext( QMouseEvent *e )
{
#if !defined QT_NO_IM
Q_Q(QLineEdit);
if ( composeMode() ) {
int tmp_cursor = xToPos(e->pos().x());
int mousePos = tmp_cursor - cursor;
if ( mousePos < 0 || mousePos > textLayout.preeditAreaText().length() ) {
mousePos = -1;
// don't send move events outside the preedit area
if ( e->type() == QEvent::MouseMove )
return true;
}
QInputContext *qic = q->inputContext();
if ( qic )
// may be causing reset() in some input methods
qic->mouseHandler(mousePos, e);
if (!textLayout.preeditAreaText().isEmpty())
return true;
}
#else
Q_UNUSED(e);
#endif
return false;
}
/*! \reimp
*/
void QLineEdit::inputMethodEvent(QInputMethodEvent *e)
{
Q_D(QLineEdit);
if (d->readOnly) {
e->ignore();
return;
}
if (echoMode() == PasswordEchoOnEdit && !d->passwordEchoEditing) {
// Clear the edit and reset to normal echo mode while entering input
// method data; the echo mode switches back when the edit loses focus.
// ### changes a public property, resets current content.
d->updatePasswordEchoEditing(true);
clear();
}
#ifdef QT_KEYPAD_NAVIGATION
// Focus in if currently in navigation focus on the widget
// Only focus in on preedits, to allow input methods to
// commit text as they focus out without interfering with focus
if (QApplication::keypadNavigationEnabled()
&& hasFocus() && !hasEditFocus()
&& !e->preeditString().isEmpty()) {
setEditFocus(true);
selectAll(); // so text is replaced rather than appended to
}
#endif
int priorState = 0;
bool isGettingInput = !e->commitString().isEmpty() || !e->preeditString().isEmpty()
|| e->replacementLength() > 0;
bool cursorPositionChanged = false;
if (isGettingInput) {
// If any text is being input, remove selected text.
priorState = d->undoState;
d->removeSelectedText();
}
int c = d->cursor; // cursor position after insertion of commit string
if (e->replacementStart() <= 0)
c += e->commitString().length() + qMin(-e->replacementStart(), e->replacementLength());
d->cursor += e->replacementStart();
// insert commit string
if (e->replacementLength()) {
d->selstart = d->cursor;
d->selend = d->selstart + e->replacementLength();
d->removeSelectedText();
}
if (!e->commitString().isEmpty()) {
d->insert(e->commitString());
cursorPositionChanged = true;
}
d->cursor = qMin(c, d->text.length());
for (int i = 0; i < e->attributes().size(); ++i) {
const QInputMethodEvent::Attribute &a = e->attributes().at(i);
if (a.type == QInputMethodEvent::Selection) {
d->cursor = qBound(0, a.start + a.length, d->text.length());
if (a.length) {
d->selstart = qMax(0, qMin(a.start, d->text.length()));
d->selend = d->cursor;
if (d->selend < d->selstart) {
qSwap(d->selstart, d->selend);
}
} else {
d->selstart = d->selend = 0;
}
cursorPositionChanged = true;
}
}
d->textLayout.setPreeditArea(d->cursor, e->preeditString());
d->preeditCursor = e->preeditString().length();
d->hideCursor = false;
QList<QTextLayout::FormatRange> formats;
for (int i = 0; i < e->attributes().size(); ++i) {
const QInputMethodEvent::Attribute &a = e->attributes().at(i);
if (a.type == QInputMethodEvent::Cursor) {
d->preeditCursor = a.start;
d->hideCursor = !a.length;
} else if (a.type == QInputMethodEvent::TextFormat) {
QTextCharFormat f = qvariant_cast<QTextFormat>(a.value).toCharFormat();
if (f.isValid()) {
QTextLayout::FormatRange o;
o.start = a.start + d->cursor;
o.length = a.length;
o.format = f;
formats.append(o);
}
}
}
d->textLayout.setAdditionalFormats(formats);
d->updateTextLayout();
update();
if (cursorPositionChanged)
d->emitCursorPositionChanged();
if (isGettingInput)
d->finishChange(priorState);
#ifndef QT_NO_COMPLETER
if (!e->commitString().isEmpty())
d->complete(Qt::Key_unknown);
#endif
}
/*!\reimp
*/
QVariant QLineEdit::inputMethodQuery(Qt::InputMethodQuery property) const
{
Q_D(const QLineEdit);
switch(property) {
case Qt::ImMicroFocus:
return d->cursorRect();
case Qt::ImFont:
return font();
case Qt::ImCursorPosition:
return QVariant(d->cursor);
case Qt::ImSurroundingText:
return QVariant(d->text);
case Qt::ImCurrentSelection:
return QVariant(selectedText());
case Qt::ImMaximumTextLength:
return QVariant(maxLength());
case Qt::ImAnchorPosition:
if (d->selstart == d->selend)
return QVariant(d->cursor);
else if (d->selstart == d->cursor)
return QVariant(d->selend);
else
return QVariant(d->selstart);
default:
return QVariant();
}
}
/*!\reimp
*/
void QLineEdit::focusInEvent(QFocusEvent *e)
{
Q_D(QLineEdit);
if (e->reason() == Qt::TabFocusReason ||
e->reason() == Qt::BacktabFocusReason ||
e->reason() == Qt::ShortcutFocusReason) {
if (d->maskData)
d->moveCursor(d->nextMaskBlank(0));
else if (!d->hasSelectedText())
selectAll();
} else if (e->reason() == Qt::MouseFocusReason) {
d->clickCausedFocus = 1;
}
#ifdef QT_KEYPAD_NAVIGATION
if (!QApplication::keypadNavigationEnabled() || (hasEditFocus() && e->reason() == Qt::PopupFocusReason))
#endif
if (!d->cursorTimer) {
int cft = QApplication::cursorFlashTime();
d->cursorTimer = cft ? startTimer(cft/2) : -1;
}
QStyleOptionFrameV2 opt;
initStyleOption(&opt);
if((!hasSelectedText() && d->textLayout.preeditAreaText().isEmpty())
|| style()->styleHint(QStyle::SH_BlinkCursorWhenTextSelected, &opt, this))
d->setCursorVisible(true);
#ifdef Q_WS_MAC
if (d->echoMode == Password || d->echoMode == NoEcho)
qt_mac_secure_keyboard(true);
#endif
#ifdef QT_KEYPAD_NAVIGATION
d->origText = d->text;
#endif
#ifndef QT_NO_COMPLETER
if (d->completer) {
d->completer->setWidget(this);
QObject::connect(d->completer, SIGNAL(activated(QString)),
this, SLOT(setText(QString)));
QObject::connect(d->completer, SIGNAL(highlighted(QString)),
this, SLOT(_q_completionHighlighted(QString)));
}
#endif
update();
}
/*!\reimp
*/
void QLineEdit::focusOutEvent(QFocusEvent *e)
{
Q_D(QLineEdit);
if (d->passwordEchoEditing) {
// Reset the echomode back to PasswordEchoOnEdit when the widget loses
// focus.
d->updatePasswordEchoEditing(false);
}
Qt::FocusReason reason = e->reason();
if (reason != Qt::ActiveWindowFocusReason &&
reason != Qt::PopupFocusReason)
deselect();
d->setCursorVisible(false);
if (d->cursorTimer > 0)
killTimer(d->cursorTimer);
d->cursorTimer = 0;
#ifdef QT_KEYPAD_NAVIGATION
// editingFinished() is already emitted on LeaveEditFocus
if (!QApplication::keypadNavigationEnabled())
#endif
if (reason != Qt::PopupFocusReason
|| !(QApplication::activePopupWidget() && QApplication::activePopupWidget()->parentWidget() == this)) {
if (!d->emitingEditingFinished) {
if (hasAcceptableInput() || d->fixup()) {
d->emitingEditingFinished = true;
emit editingFinished();
d->emitingEditingFinished = false;
}
}
#ifdef QT3_SUPPORT
emit lostFocus();
#endif
}
#ifdef Q_WS_MAC
if (d->echoMode == Password || d->echoMode == NoEcho)
qt_mac_secure_keyboard(false);
#endif
#ifdef QT_KEYPAD_NAVIGATION
d->origText = QString();
#endif
#ifndef QT_NO_COMPLETER
if (d->completer) {
QObject::disconnect(d->completer, 0, this, 0);
}
#endif
update();
}
/*!\reimp
*/
void QLineEdit::paintEvent(QPaintEvent *)
{
Q_D(QLineEdit);
QPainter p(this);
QRect r = rect();
QPalette pal = palette();
QStyleOptionFrameV2 panel;
initStyleOption(&panel);
style()->drawPrimitive(QStyle::PE_PanelLineEdit, &panel, &p, this);
r = style()->subElementRect(QStyle::SE_LineEditContents, &panel, this);
r.setX(r.x() + d->leftTextMargin);
r.setY(r.y() + d->topTextMargin);
r.setRight(r.right() - d->rightTextMargin);
r.setBottom(r.bottom() - d->bottomTextMargin);
p.setClipRect(r);
QFontMetrics fm = fontMetrics();
Qt::Alignment va = QStyle::visualAlignment(layoutDirection(), QFlag(d->alignment));
switch (va & Qt::AlignVertical_Mask) {
case Qt::AlignBottom:
d->vscroll = r.y() + r.height() - fm.height() - verticalMargin;
break;
case Qt::AlignTop:
d->vscroll = r.y() + verticalMargin;
break;
default:
//center
d->vscroll = r.y() + (r.height() - fm.height() + 1) / 2;
break;
}
QRect lineRect(r.x() + horizontalMargin, d->vscroll, r.width() - 2*horizontalMargin, fm.height());
QTextLine line = d->textLayout.lineAt(0);
int cursor = d->cursor;
if (d->preeditCursor != -1)
cursor += d->preeditCursor;
// locate cursor position
int cix = qRound(line.cursorToX(cursor));
// horizontal scrolling. d->hscroll is the left indent from the beginning
// of the text line to the left edge of lineRect. we update this value
// depending on the delta from the last paint event; in effect this means
// the below code handles all scrolling based on the textline (widthUsed,
// minLB, minRB), the line edit rect (lineRect) and the cursor position
// (cix).
int minLB = qMax(0, -fm.minLeftBearing());
int minRB = qMax(0, -fm.minRightBearing());
int widthUsed = qRound(line.naturalTextWidth()) + 1 + minRB;
if ((minLB + widthUsed) <= lineRect.width()) {
// text fits in lineRect; use hscroll for alignment
switch (va & ~(Qt::AlignAbsolute|Qt::AlignVertical_Mask)) {
case Qt::AlignRight:
d->hscroll = widthUsed - lineRect.width() + 1;
break;
case Qt::AlignHCenter:
d->hscroll = (widthUsed - lineRect.width()) / 2;
break;
default:
// Left
d->hscroll = 0;
break;
}
d->hscroll -= minLB;
} else if (cix - d->hscroll >= lineRect.width()) {
// text doesn't fit, cursor is to the right of lineRect (scroll right)
d->hscroll = cix - lineRect.width() + 1;
} else if (cix - d->hscroll < 0 && d->hscroll < widthUsed) {
// text doesn't fit, cursor is to the left of lineRect (scroll left)
d->hscroll = cix;
} else if (widthUsed - d->hscroll < lineRect.width()) {
// text doesn't fit, text document is to the left of lineRect; align
// right
d->hscroll = widthUsed - lineRect.width() + 1;
}
// the y offset is there to keep the baseline constant in case we have script changes in the text.
QPoint topLeft = lineRect.topLeft() - QPoint(d->hscroll, d->ascent - fm.ascent());
// draw text, selections and cursors
#ifndef QT_NO_STYLE_STYLESHEET
if (QStyleSheetStyle* cssStyle = qobject_cast<QStyleSheetStyle*>(style())) {
cssStyle->styleSheetPalette(this, &panel, &pal);
}
#endif
p.setPen(pal.text().color());
QVector<QTextLayout::FormatRange> selections;
#ifdef QT_KEYPAD_NAVIGATION
if (!QApplication::keypadNavigationEnabled() || hasEditFocus())
#endif
if (d->selstart < d->selend || (d->cursorVisible && d->maskData && !d->readOnly)) {
QTextLayout::FormatRange o;
if (d->selstart < d->selend) {
o.start = d->selstart;
o.length = d->selend - d->selstart;
o.format.setBackground(pal.brush(QPalette::Highlight));
o.format.setForeground(pal.brush(QPalette::HighlightedText));
} else {
// mask selection
o.start = d->cursor;
o.length = 1;
o.format.setBackground(pal.brush(QPalette::Text));
o.format.setForeground(pal.brush(QPalette::Window));
}
selections.append(o);
}
// Asian users see an IM selection text as cursor on candidate
// selection phase of input method, so the ordinary cursor should be
// invisible if we have a preedit string.
d->textLayout.draw(&p, topLeft, selections, r);
if (d->cursorVisible && !d->readOnly && !d->hideCursor)
d->textLayout.drawCursor(&p, topLeft, cursor, style()->pixelMetric(QStyle::PM_TextCursorWidth));
}
#ifndef QT_NO_DRAGANDDROP
/*!\reimp
*/
void QLineEdit::dragMoveEvent(QDragMoveEvent *e)
{
Q_D(QLineEdit);
if (!d->readOnly && e->mimeData()->hasFormat(QLatin1String("text/plain"))) {
e->acceptProposedAction();
d->cursor = d->xToPos(e->pos().x());
d->cursorVisible = true;
update();
d->emitCursorPositionChanged();
}
}
/*!\reimp */
void QLineEdit::dragEnterEvent(QDragEnterEvent * e)
{
QLineEdit::dragMoveEvent(e);
}
/*!\reimp */
void QLineEdit::dragLeaveEvent(QDragLeaveEvent *)
{
Q_D(QLineEdit);
if (d->cursorVisible) {
d->cursorVisible = false;
update();
}
}
/*!\reimp */
void QLineEdit::dropEvent(QDropEvent* e)
{
Q_D(QLineEdit);
QString str = e->mimeData()->text();
if (!str.isNull() && !d->readOnly) {
if (e->source() == this && e->dropAction() == Qt::CopyAction)
deselect();
d->cursor =d->xToPos(e->pos().x());
int selStart = d->cursor;
int oldSelStart = d->selstart;
int oldSelEnd = d->selend;
d->cursorVisible = false;
e->acceptProposedAction();
insert(str);
if (e->source() == this) {
if (e->dropAction() == Qt::MoveAction) {
if (selStart > oldSelStart && selStart <= oldSelEnd)
setSelection(oldSelStart, str.length());
else if (selStart > oldSelEnd)
setSelection(selStart - str.length(), str.length());
else
setSelection(selStart, str.length());
} else {
setSelection(selStart, str.length());
}
}
} else {
e->ignore();
update();
}
}
void QLineEditPrivate::drag()
{
Q_Q(QLineEdit);
dndTimer.stop();
QMimeData *data = new QMimeData;
data->setText(q->selectedText());
QDrag *drag = new QDrag(q);
drag->setMimeData(data);
Qt::DropAction action = drag->start();
if (action == Qt::MoveAction && !readOnly && drag->target() != q) {
int priorState = undoState;
removeSelectedText();
finishChange(priorState);
}
}
#endif // QT_NO_DRAGANDDROP
#ifndef QT_NO_CONTEXTMENU
/*!
Shows the standard context menu created with
createStandardContextMenu().
If you do not want the line edit to have a context menu, you can set
its \l contextMenuPolicy to Qt::NoContextMenu. If you want to
customize the context menu, reimplement this function. If you want
to extend the standard context menu, reimplement this function, call
createStandardContextMenu() and extend the menu returned.
\snippet doc/src/snippets/code/src_gui_widgets_qlineedit.cpp 0
The \a event parameter is used to obtain the position where
the mouse cursor was when the event was generated.
\sa setContextMenuPolicy()
*/
void QLineEdit::contextMenuEvent(QContextMenuEvent *event)
{
QPointer<QMenu> menu = createStandardContextMenu();
menu->exec(event->globalPos());
delete menu;
}
#if defined(Q_WS_WIN)
extern bool qt_use_rtl_extensions;
#endif
/*! This function creates the standard context menu which is shown
when the user clicks on the line edit with the right mouse
button. It is called from the default contextMenuEvent() handler.
The popup menu's ownership is transferred to the caller.
*/
QMenu *QLineEdit::createStandardContextMenu()
{
Q_D(QLineEdit);
QMenu *popup = new QMenu(this);
popup->setObjectName(QLatin1String("qt_edit_menu"));
QAction *action = popup->addAction(QLineEdit::tr("&Undo") + ACCEL_KEY(QKeySequence::Undo));
action->setEnabled(d->isUndoAvailable());
connect(action, SIGNAL(triggered()), SLOT(undo()));
action = popup->addAction(QLineEdit::tr("&Redo") + ACCEL_KEY(QKeySequence::Redo));
action->setEnabled(d->isRedoAvailable());
connect(action, SIGNAL(triggered()), SLOT(redo()));
popup->addSeparator();
#ifndef QT_NO_CLIPBOARD
action = popup->addAction(QLineEdit::tr("Cu&t") + ACCEL_KEY(QKeySequence::Cut));
action->setEnabled(!d->readOnly && d->hasSelectedText() && d->echoMode == QLineEdit::Normal);
connect(action, SIGNAL(triggered()), SLOT(cut()));
action = popup->addAction(QLineEdit::tr("&Copy") + ACCEL_KEY(QKeySequence::Copy));
action->setEnabled(d->hasSelectedText() && d->echoMode == QLineEdit::Normal);
connect(action, SIGNAL(triggered()), SLOT(copy()));
action = popup->addAction(QLineEdit::tr("&Paste") + ACCEL_KEY(QKeySequence::Paste));
action->setEnabled(!d->readOnly && !QApplication::clipboard()->text().isEmpty());
connect(action, SIGNAL(triggered()), SLOT(paste()));
#endif
action = popup->addAction(QLineEdit::tr("Delete"));
action->setEnabled(!d->readOnly && !d->text.isEmpty() && d->hasSelectedText());
connect(action, SIGNAL(triggered()), SLOT(_q_deleteSelected()));
popup->addSeparator();
action = popup->addAction(QLineEdit::tr("Select All") + ACCEL_KEY(QKeySequence::SelectAll));
action->setEnabled(!d->text.isEmpty() && !d->allSelected());
d->selectAllAction = action;
connect(action, SIGNAL(triggered()), SLOT(selectAll()));
#if !defined(QT_NO_IM)
QInputContext *qic = inputContext();
if (qic) {
QList<QAction *> imActions = qic->actions();
for (int i = 0; i < imActions.size(); ++i)
popup->addAction(imActions.at(i));
}
#endif
#if defined(Q_WS_WIN)
if (!d->readOnly && qt_use_rtl_extensions) {
#else
if (!d->readOnly) {
#endif
popup->addSeparator();
QUnicodeControlCharacterMenu *ctrlCharacterMenu = new QUnicodeControlCharacterMenu(this, popup);
popup->addMenu(ctrlCharacterMenu);
}
return popup;
}
#endif // QT_NO_CONTEXTMENU
/*! \reimp */
void QLineEdit::changeEvent(QEvent *ev)
{
Q_D(QLineEdit);
if(ev->type() == QEvent::ActivationChange) {
if (!palette().isEqual(QPalette::Active, QPalette::Inactive))
update();
} else if (ev->type() == QEvent::FontChange
|| ev->type() == QEvent::StyleChange
|| ev->type() == QEvent::LayoutDirectionChange) {
d->updateTextLayout();
}
QWidget::changeEvent(ev);
}
void QLineEditPrivate::_q_handleWindowActivate()
{
Q_Q(QLineEdit);
if (!q->hasFocus() && q->hasSelectedText())
q->deselect();
}
void QLineEditPrivate::_q_deleteSelected()
{
Q_Q(QLineEdit);
if (!hasSelectedText())
return;
int priorState = undoState;
q->resetInputContext();
removeSelectedText();
separate();
finishChange(priorState);
}
void QLineEditPrivate::init(const QString& txt)
{
Q_Q(QLineEdit);
#ifndef QT_NO_CURSOR
q->setCursor(Qt::IBeamCursor);
#endif
q->setFocusPolicy(Qt::StrongFocus);
q->setAttribute(Qt::WA_InputMethodEnabled);
// Specifies that this widget can use more, but is able to survive on
// less, horizontal space; and is fixed vertically.
q->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed, QSizePolicy::LineEdit));
q->setBackgroundRole(QPalette::Base);
q->setAttribute(Qt::WA_KeyCompression);
q->setMouseTracking(true);
q->setAcceptDrops(true);
text = txt;
updateTextLayout();
cursor = text.length();
q->setAttribute(Qt::WA_MacShowFocusRect);
}
void QLineEditPrivate::updatePasswordEchoEditing(bool editing)
{
Q_Q(QLineEdit);
passwordEchoEditing = editing;
q->setAttribute(Qt::WA_InputMethodEnabled, shouldEnableInputMethod(q));
updateTextLayout();
q->update();
}
void QLineEditPrivate::updateTextLayout()
{
// replace certain non-printable characters with spaces (to avoid
// drawing boxes when using fonts that don't have glyphs for such
// characters)
Q_Q(QLineEdit);
QString str = q->displayText();
QChar* uc = str.data();
for (int i = 0; i < (int)str.length(); ++i) {
if ((uc[i] < 0x20 && uc[i] != 0x09)
|| uc[i] == QChar::LineSeparator
|| uc[i] == QChar::ParagraphSeparator
|| uc[i] == QChar::ObjectReplacementCharacter)
uc[i] = QChar(0x0020);
}
textLayout.setFont(q->font());
textLayout.setText(str);
QTextOption option;
option.setTextDirection(q->layoutDirection());
option.setFlags(QTextOption::IncludeTrailingSpaces);
textLayout.setTextOption(option);
textLayout.beginLayout();
QTextLine l = textLayout.createLine();
textLayout.endLayout();
ascent = qRound(l.ascent());
}
int QLineEditPrivate::xToPos(int x, QTextLine::CursorPosition betweenOrOn) const
{
QRect cr = adjustedContentsRect();
x-= cr.x() - hscroll + horizontalMargin;
QTextLine l = textLayout.lineAt(0);
return l.xToCursor(x, betweenOrOn);
}
QRect QLineEditPrivate::cursorRect() const
{
Q_Q(const QLineEdit);
QRect cr = adjustedContentsRect();
int cix = cr.x() - hscroll + horizontalMargin;
QTextLine l = textLayout.lineAt(0);
int c = cursor;
if (preeditCursor != -1)
c += preeditCursor;
cix += qRound(l.cursorToX(c));
int ch = qMin(cr.height(), q->fontMetrics().height() + 1);
int w = q->style()->pixelMetric(QStyle::PM_TextCursorWidth);
return QRect(cix-5, vscroll, w + 9, ch);
}
QRect QLineEditPrivate::adjustedContentsRect() const
{
Q_Q(const QLineEdit);
QStyleOptionFrameV2 opt;
q->initStyleOption(&opt);
QRect r = q->style()->subElementRect(QStyle::SE_LineEditContents, &opt, q);
r.setX(r.x() + leftTextMargin);
r.setY(r.y() + topTextMargin);
r.setRight(r.right() - rightTextMargin);
r.setBottom(r.bottom() - bottomTextMargin);
return r;
}
bool QLineEditPrivate::fixup() // this function assumes that validate currently returns != Acceptable
{
#ifndef QT_NO_VALIDATOR
if (validator) {
QString textCopy = text;
int cursorCopy = cursor;
validator->fixup(textCopy);
if (validator->validate(textCopy, cursorCopy) == QValidator::Acceptable) {
if (textCopy != text || cursorCopy != cursor)
setText(textCopy, cursorCopy);
return true;
}
}
#endif
return false;
}
void QLineEditPrivate::moveCursor(int pos, bool mark)
{
Q_Q(QLineEdit);
if (pos != cursor) {
separate();
if (maskData)
pos = pos > cursor ? nextMaskBlank(pos) : prevMaskBlank(pos);
}
bool fullUpdate = mark || hasSelectedText();
if (mark) {
int anchor;
if (selend > selstart && cursor == selstart)
anchor = selend;
else if (selend > selstart && cursor == selend)
anchor = selstart;
else
anchor = cursor;
selstart = qMin(anchor, pos);
selend = qMax(anchor, pos);
updateTextLayout();
} else {
deselect();
}
if (fullUpdate) {
cursor = pos;
q->update();
} else {
setCursorVisible(false);
cursor = pos;
setCursorVisible(true);
if (!adjustedContentsRect().contains(cursorRect()))
q->update();
}
QStyleOptionFrameV2 opt;
q->initStyleOption(&opt);
if (mark && !q->style()->styleHint(QStyle::SH_BlinkCursorWhenTextSelected, &opt, q))
setCursorVisible(false);
if (mark || selDirty) {
selDirty = false;
emit q->selectionChanged();
}
q->updateMicroFocus();
emitCursorPositionChanged();
}
void QLineEditPrivate::finishChange(int validateFromState, bool update, bool edited)
{
Q_Q(QLineEdit);
bool lineDirty = selDirty;
if (textDirty) {
// do validation
bool wasValidInput = validInput;
validInput = true;
#ifndef QT_NO_VALIDATOR
if (validator) {
validInput = false;
QString textCopy = text;
int cursorCopy = cursor;
validInput = (validator->validate(textCopy, cursorCopy) != QValidator::Invalid);
if (validInput) {
if (text != textCopy) {
setText(textCopy, cursorCopy);
return;
}
cursor = cursorCopy;
}
}
#endif
if (validateFromState >= 0 && wasValidInput && !validInput) {
undo(validateFromState);
history.resize(undoState);
if (modifiedState > undoState)
modifiedState = -1;
validInput = true;
textDirty = false;
}
updateTextLayout();
lineDirty |= textDirty;
if (textDirty) {
textDirty = false;
QString actualText = maskData ? stripString(text) : text;
if (edited)
emit q->textEdited(actualText);
q->updateMicroFocus();
#ifndef QT_NO_COMPLETER
if (edited && completer && completer->completionMode() != QCompleter::InlineCompletion)
complete(-1); // update the popup on cut/paste/del
#endif
emit q->textChanged(actualText);
}
#ifndef QT_NO_ACCESSIBILITY
QAccessible::updateAccessibility(q, 0, QAccessible::ValueChanged);
#endif
}
if (selDirty) {
selDirty = false;
emit q->selectionChanged();
}
if (lineDirty || update)
q->update();
emitCursorPositionChanged();
}
void QLineEditPrivate::emitCursorPositionChanged()
{
Q_Q(QLineEdit);
if (cursor != lastCursorPos) {
const int oldLast = lastCursorPos;
lastCursorPos = cursor;
emit q->cursorPositionChanged(oldLast, cursor);
}
}
void QLineEditPrivate::setText(const QString& txt, int pos, bool edited)
{
Q_Q(QLineEdit);
q->resetInputContext();
deselect();
QString oldText = text;
if (maskData) {
text = maskString(0, txt, true);
text += clearString(text.length(), maxLength - text.length());
} else {
text = txt.isEmpty() ? txt : txt.left(maxLength);
}
history.clear();
modifiedState = undoState = 0;
cursor = (pos < 0 || pos > text.length()) ? text.length() : pos;
textDirty = (oldText != text);
finishChange(-1, true, edited);
}
void QLineEditPrivate::setCursorVisible(bool visible)
{
Q_Q(QLineEdit);
if ((bool)cursorVisible == visible)
return;
if (cursorTimer)
cursorVisible = visible;
QRect r = cursorRect();
if (maskData)
q->update();
else
q->update(r);
}
void QLineEditPrivate::addCommand(const Command& cmd)
{
if (separator && undoState && history[undoState-1].type != Separator) {
history.resize(undoState + 2);
history[undoState++] = Command(Separator, cursor, 0, selstart, selend);
} else {
history.resize(undoState + 1);
}
separator = false;
history[undoState++] = cmd;
}
void QLineEditPrivate::insert(const QString& s)
{
if (hasSelectedText())
addCommand(Command(SetSelection, cursor, 0, selstart, selend));
if (maskData) {
QString ms = maskString(cursor, s);
for (int i = 0; i < (int) ms.length(); ++i) {
addCommand (Command(DeleteSelection, cursor+i, text.at(cursor+i), -1, -1));
addCommand(Command(Insert, cursor+i, ms.at(i), -1, -1));
}
text.replace(cursor, ms.length(), ms);
cursor += ms.length();
cursor = nextMaskBlank(cursor);
textDirty = true;
} else {
int remaining = maxLength - text.length();
if (remaining != 0) {
text.insert(cursor, s.left(remaining));
for (int i = 0; i < (int) s.left(remaining).length(); ++i)
addCommand(Command(Insert, cursor++, s.at(i), -1, -1));
textDirty = true;
}
}
}
void QLineEditPrivate::del(bool wasBackspace)
{
if (cursor < (int) text.length()) {
if (hasSelectedText())
addCommand(Command(SetSelection, cursor, 0, selstart, selend));
addCommand (Command((CommandType)((maskData?2:0)+(wasBackspace?Remove:Delete)), cursor, text.at(cursor), -1, -1));
if (maskData) {
text.replace(cursor, 1, clearString(cursor, 1));
addCommand(Command(Insert, cursor, text.at(cursor), -1, -1));
} else {
text.remove(cursor, 1);
}
textDirty = true;
}
}
void QLineEditPrivate::removeSelectedText()
{
if (selstart < selend && selend <= (int) text.length()) {
separate();
int i ;
addCommand(Command(SetSelection, cursor, 0, selstart, selend));
if (selstart <= cursor && cursor < selend) {
// cursor is within the selection. Split up the commands
// to be able to restore the correct cursor position
for (i = cursor; i >= selstart; --i)
addCommand (Command(DeleteSelection, i, text.at(i), -1, 1));
for (i = selend - 1; i > cursor; --i)
addCommand (Command(DeleteSelection, i - cursor + selstart - 1, text.at(i), -1, -1));
} else {
for (i = selend-1; i >= selstart; --i)
addCommand (Command(RemoveSelection, i, text.at(i), -1, -1));
}
if (maskData) {
text.replace(selstart, selend - selstart, clearString(selstart, selend - selstart));
for (int i = 0; i < selend - selstart; ++i)
addCommand(Command(Insert, selstart + i, text.at(selstart + i), -1, -1));
} else {
text.remove(selstart, selend - selstart);
}
if (cursor > selstart)
cursor -= qMin(cursor, selend) - selstart;
deselect();
textDirty = true;
// adjust hscroll to avoid gap
const int minRB = qMax(0, -q_func()->fontMetrics().minRightBearing());
updateTextLayout();
const QTextLine line = textLayout.lineAt(0);
const int widthUsed = qRound(line.naturalTextWidth()) + 1 + minRB;
hscroll = qMin(hscroll, widthUsed);
}
}
void QLineEditPrivate::parseInputMask(const QString &maskFields)
{
int delimiter = maskFields.indexOf(QLatin1Char(';'));
if (maskFields.isEmpty() || delimiter == 0) {
if (maskData) {
delete [] maskData;
maskData = 0;
maxLength = 32767;
setText(QString());
}
return;
}
if (delimiter == -1) {
blank = QLatin1Char(' ');
inputMask = maskFields;
} else {
inputMask = maskFields.left(delimiter);
blank = (delimiter + 1 < maskFields.length()) ? maskFields[delimiter + 1] : QLatin1Char(' ');
}
// calculate maxLength / maskData length
maxLength = 0;
QChar c = 0;
for (int i=0; i<inputMask.length(); i++) {
c = inputMask.at(i);
if (i > 0 && inputMask.at(i-1) == QLatin1Char('\\')) {
maxLength++;
continue;
}
if (c != QLatin1Char('\\') && c != QLatin1Char('!') &&
c != QLatin1Char('<') && c != QLatin1Char('>') &&
c != QLatin1Char('{') && c != QLatin1Char('}') &&
c != QLatin1Char('[') && c != QLatin1Char(']'))
maxLength++;
}
delete [] maskData;
maskData = new MaskInputData[maxLength];
MaskInputData::Casemode m = MaskInputData::NoCaseMode;
c = 0;
bool s;
bool escape = false;
int index = 0;
for (int i = 0; i < inputMask.length(); i++) {
c = inputMask.at(i);
if (escape) {
s = true;
maskData[index].maskChar = c;
maskData[index].separator = s;
maskData[index].caseMode = m;
index++;
escape = false;
} else if (c == QLatin1Char('<')) {
m = MaskInputData::Lower;
} else if (c == QLatin1Char('>')) {
m = MaskInputData::Upper;
} else if (c == QLatin1Char('!')) {
m = MaskInputData::NoCaseMode;
} else if (c != QLatin1Char('{') && c != QLatin1Char('}') && c != QLatin1Char('[') && c != QLatin1Char(']')) {
switch (c.unicode()) {
case 'A':
case 'a':
case 'N':
case 'n':
case 'X':
case 'x':
case '9':
case '0':
case 'D':
case 'd':
case '#':
case 'H':
case 'h':
case 'B':
case 'b':
s = false;
break;
case '\\':
escape = true;
default:
s = true;
break;
}
if (!escape) {
maskData[index].maskChar = c;
maskData[index].separator = s;
maskData[index].caseMode = m;
index++;
}
}
}
setText(text);
}
/* checks if the key is valid compared to the inputMask */
bool QLineEditPrivate::isValidInput(QChar key, QChar mask) const
{
switch (mask.unicode()) {
case 'A':
if (key.isLetter())
return true;
break;
case 'a':
if (key.isLetter() || key == blank)
return true;
break;
case 'N':
if (key.isLetterOrNumber())
return true;
break;
case 'n':
if (key.isLetterOrNumber() || key == blank)
return true;
break;
case 'X':
if (key.isPrint())
return true;
break;
case 'x':
if (key.isPrint() || key == blank)
return true;
break;
case '9':
if (key.isNumber())
return true;
break;
case '0':
if (key.isNumber() || key == blank)
return true;
break;
case 'D':
if (key.isNumber() && key.digitValue() > 0)
return true;
break;
case 'd':
if ((key.isNumber() && key.digitValue() > 0) || key == blank)
return true;
break;
case '#':
if (key.isNumber() || key == QLatin1Char('+') || key == QLatin1Char('-') || key == blank)
return true;
break;
case 'B':
if (key == QLatin1Char('0') || key == QLatin1Char('1'))
return true;
break;
case 'b':
if (key == QLatin1Char('0') || key == QLatin1Char('1') || key == blank)
return true;
break;
case 'H':
if (key.isNumber() || (key >= QLatin1Char('a') && key <= QLatin1Char('f')) || (key >= QLatin1Char('A') && key <= QLatin1Char('F')))
return true;
break;
case 'h':
if (key.isNumber() || (key >= QLatin1Char('a') && key <= QLatin1Char('f')) || (key >= QLatin1Char('A') && key <= QLatin1Char('F')) || key == blank)
return true;
break;
default:
break;
}
return false;
}
bool QLineEditPrivate::hasAcceptableInput(const QString &str) const
{
#ifndef QT_NO_VALIDATOR
QString textCopy = str;
int cursorCopy = cursor;
if (validator && validator->validate(textCopy, cursorCopy)
!= QValidator::Acceptable)
return false;
#endif
if (!maskData)
return true;
if (str.length() != maxLength)
return false;
for (int i=0; i < maxLength; ++i) {
if (maskData[i].separator) {
if (str.at(i) != maskData[i].maskChar)
return false;
} else {
if (!isValidInput(str.at(i), maskData[i].maskChar))
return false;
}
}
return true;
}
/*
Applies the inputMask on \a str starting from position \a pos in the mask. \a clear
specifies from where characters should be gotten when a separator is met in \a str - true means
that blanks will be used, false that previous input is used.
Calling this when no inputMask is set is undefined.
*/
QString QLineEditPrivate::maskString(uint pos, const QString &str, bool clear) const
{
if (pos >= (uint)maxLength)
return QString::fromLatin1("");
QString fill;
fill = clear ? clearString(0, maxLength) : text;
int strIndex = 0;
QString s = QString::fromLatin1("");
int i = pos;
while (i < maxLength) {
if (strIndex < str.length()) {
if (maskData[i].separator) {
s += maskData[i].maskChar;
if (str[(int)strIndex] == maskData[i].maskChar)
strIndex++;
++i;
} else {
if (isValidInput(str[(int)strIndex], maskData[i].maskChar)) {
switch (maskData[i].caseMode) {
case MaskInputData::Upper:
s += str[(int)strIndex].toUpper();
break;
case MaskInputData::Lower:
s += str[(int)strIndex].toLower();
break;
default:
s += str[(int)strIndex];
}
++i;
} else {
// search for separator first
int n = findInMask(i, true, true, str[(int)strIndex]);
if (n != -1) {
if (str.length() != 1 || i == 0 || (i > 0 && (!maskData[i-1].separator || maskData[i-1].maskChar != str[(int)strIndex]))) {
s += fill.mid(i, n-i+1);
i = n + 1; // update i to find + 1
}
} else {
// search for valid blank if not
n = findInMask(i, true, false, str[(int)strIndex]);
if (n != -1) {
s += fill.mid(i, n-i);
switch (maskData[n].caseMode) {
case MaskInputData::Upper:
s += str[(int)strIndex].toUpper();
break;
case MaskInputData::Lower:
s += str[(int)strIndex].toLower();
break;
default:
s += str[(int)strIndex];
}
i = n + 1; // updates i to find + 1
}
}
}
strIndex++;
}
} else
break;
}
return s;
}
/*
Returns a "cleared" string with only separators and blank chars.
Calling this when no inputMask is set is undefined.
*/
QString QLineEditPrivate::clearString(uint pos, uint len) const
{
if (pos >= (uint)maxLength)
return QString();
QString s;
int end = qMin((uint)maxLength, pos + len);
for (int i=pos; i<end; i++)
if (maskData[i].separator)
s += maskData[i].maskChar;
else
s += blank;
return s;
}
/*
Strips blank parts of the input in a QLineEdit when an inputMask is set,
separators are still included. Typically "127.0__.0__.1__" becomes "127.0.0.1".
*/
QString QLineEditPrivate::stripString(const QString &str) const
{
if (!maskData)
return str;
QString s;
int end = qMin(maxLength, (int)str.length());
for (int i=0; i < end; i++)
if (maskData[i].separator)
s += maskData[i].maskChar;
else
if (str[i] != blank)
s += str[i];
return s;
}
/* searches forward/backward in maskData for either a separator or a blank */
int QLineEditPrivate::findInMask(int pos, bool forward, bool findSeparator, QChar searchChar) const
{
if (pos >= maxLength || pos < 0)
return -1;
int end = forward ? maxLength : -1;
int step = forward ? 1 : -1;
int i = pos;
while (i != end) {
if (findSeparator) {
if (maskData[i].separator && maskData[i].maskChar == searchChar)
return i;
} else {
if (!maskData[i].separator) {
if (searchChar.isNull())
return i;
else if (isValidInput(searchChar, maskData[i].maskChar))
return i;
}
}
i += step;
}
return -1;
}
void QLineEditPrivate::undo(int until)
{
if (!isUndoAvailable())
return;
deselect();
while (undoState && undoState > until) {
Command& cmd = history[--undoState];
switch (cmd.type) {
case Insert:
text.remove(cmd.pos, 1);
cursor = cmd.pos;
break;
case SetSelection:
selstart = cmd.selStart;
selend = cmd.selEnd;
cursor = cmd.pos;
break;
case Remove:
case RemoveSelection:
text.insert(cmd.pos, cmd.uc);
cursor = cmd.pos + 1;
break;
case Delete:
case DeleteSelection:
text.insert(cmd.pos, cmd.uc);
cursor = cmd.pos;
break;
case Separator:
continue;
}
if (until < 0 && undoState) {
Command& next = history[undoState-1];
if (next.type != cmd.type && next.type < RemoveSelection
&& (cmd.type < RemoveSelection || next.type == Separator))
break;
}
}
textDirty = true;
emitCursorPositionChanged();
}
void QLineEditPrivate::redo() {
if (!isRedoAvailable())
return;
deselect();
while (undoState < (int)history.size()) {
Command& cmd = history[undoState++];
switch (cmd.type) {
case Insert:
text.insert(cmd.pos, cmd.uc);
cursor = cmd.pos + 1;
break;
case SetSelection:
selstart = cmd.selStart;
selend = cmd.selEnd;
cursor = cmd.pos;
break;
case Remove:
case Delete:
case RemoveSelection:
case DeleteSelection:
text.remove(cmd.pos, 1);
selstart = cmd.selStart;
selend = cmd.selEnd;
cursor = cmd.pos;
break;
case Separator:
selstart = cmd.selStart;
selend = cmd.selEnd;
cursor = cmd.pos;
break;
}
if (undoState < (int)history.size()) {
Command& next = history[undoState];
if (next.type != cmd.type && cmd.type < RemoveSelection && next.type != Separator
&& (next.type < RemoveSelection || cmd.type == Separator))
break;
}
}
textDirty = true;
emitCursorPositionChanged();
}
/*!
\fn void QLineEdit::repaintArea(int a, int b)
Use update() instead.
*/
/*!
\fn void QLineEdit::cursorLeft(bool mark, int steps)
Use cursorForward() with a negative number of steps instead. For
example, cursorForward(mark, -steps).
*/
/*!
\fn void QLineEdit::cursorRight(bool mark, int steps)
Use cursorForward() instead.
*/
/*!
\fn bool QLineEdit::frame() const
Use hasFrame() instead.
*/
/*!
\fn void QLineEdit::clearValidator()
Use setValidator(0) instead.
*/
/*!
\fn bool QLineEdit::hasMarkedText() const
Use hasSelectedText() instead.
*/
/*!
\fn QString QLineEdit::markedText() const
Use selectedText() instead.
*/
/*!
\fn void QLineEdit::setFrameRect(QRect)
\internal
*/
/*!
\fn QRect QLineEdit::frameRect() const
\internal
*/
/*!
\enum QLineEdit::DummyFrame
\internal
\value Box
\value Sunken
\value Plain
\value Raised
\value MShadow
\value NoFrame
\value Panel
\value StyledPanel
\value HLine
\value VLine
\value GroupBoxPanel
\value WinPanel
\value ToolBarPanel
\value MenuBarPanel
\value PopupPanel
\value LineEditPanel
\value TabWidgetPanel
\value MShape
*/
/*!
\fn void QLineEdit::setFrameShadow(DummyFrame)
\internal
*/
/*!
\fn DummyFrame QLineEdit::frameShadow() const
\internal
*/
/*!
\fn void QLineEdit::setFrameShape(DummyFrame)
\internal
*/
/*!
\fn DummyFrame QLineEdit::frameShape() const
\internal
*/
/*!
\fn void QLineEdit::setFrameStyle(int)
\internal
*/
/*!
\fn int QLineEdit::frameStyle() const
\internal
*/
/*!
\fn int QLineEdit::frameWidth() const
\internal
*/
/*!
\fn void QLineEdit::setLineWidth(int)
\internal
*/
/*!
\fn int QLineEdit::lineWidth() const
\internal
*/
/*!
\fn void QLineEdit::setMargin(int margin)
Sets the width of the margin around the contents of the widget to \a margin.
Use QWidget::setContentsMargins() instead.
\sa margin(), QWidget::setContentsMargins()
*/
/*!
\fn int QLineEdit::margin() const
Returns the width of the margin around the contents of the widget.
Use QWidget::getContentsMargins() instead.
\sa setMargin(), QWidget::getContentsMargins()
*/
/*!
\fn void QLineEdit::setMidLineWidth(int)
\internal
*/
/*!
\fn int QLineEdit::midLineWidth() const
\internal
*/
QT_END_NAMESPACE
#include "moc_qlineedit.cpp"
#endif // QT_NO_LINEEDIT
|