File: mainwindow.cpp

package info (click to toggle)
socnetv 0.90-3
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 2,028 kB
  • sloc: cpp: 12,953; makefile: 75
file content (6049 lines) | stat: -rwxr-xr-x 224,983 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191
5192
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
5232
5233
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250
5251
5252
5253
5254
5255
5256
5257
5258
5259
5260
5261
5262
5263
5264
5265
5266
5267
5268
5269
5270
5271
5272
5273
5274
5275
5276
5277
5278
5279
5280
5281
5282
5283
5284
5285
5286
5287
5288
5289
5290
5291
5292
5293
5294
5295
5296
5297
5298
5299
5300
5301
5302
5303
5304
5305
5306
5307
5308
5309
5310
5311
5312
5313
5314
5315
5316
5317
5318
5319
5320
5321
5322
5323
5324
5325
5326
5327
5328
5329
5330
5331
5332
5333
5334
5335
5336
5337
5338
5339
5340
5341
5342
5343
5344
5345
5346
5347
5348
5349
5350
5351
5352
5353
5354
5355
5356
5357
5358
5359
5360
5361
5362
5363
5364
5365
5366
5367
5368
5369
5370
5371
5372
5373
5374
5375
5376
5377
5378
5379
5380
5381
5382
5383
5384
5385
5386
5387
5388
5389
5390
5391
5392
5393
5394
5395
5396
5397
5398
5399
5400
5401
5402
5403
5404
5405
5406
5407
5408
5409
5410
5411
5412
5413
5414
5415
5416
5417
5418
5419
5420
5421
5422
5423
5424
5425
5426
5427
5428
5429
5430
5431
5432
5433
5434
5435
5436
5437
5438
5439
5440
5441
5442
5443
5444
5445
5446
5447
5448
5449
5450
5451
5452
5453
5454
5455
5456
5457
5458
5459
5460
5461
5462
5463
5464
5465
5466
5467
5468
5469
5470
5471
5472
5473
5474
5475
5476
5477
5478
5479
5480
5481
5482
5483
5484
5485
5486
5487
5488
5489
5490
5491
5492
5493
5494
5495
5496
5497
5498
5499
5500
5501
5502
5503
5504
5505
5506
5507
5508
5509
5510
5511
5512
5513
5514
5515
5516
5517
5518
5519
5520
5521
5522
5523
5524
5525
5526
5527
5528
5529
5530
5531
5532
5533
5534
5535
5536
5537
5538
5539
5540
5541
5542
5543
5544
5545
5546
5547
5548
5549
5550
5551
5552
5553
5554
5555
5556
5557
5558
5559
5560
5561
5562
5563
5564
5565
5566
5567
5568
5569
5570
5571
5572
5573
5574
5575
5576
5577
5578
5579
5580
5581
5582
5583
5584
5585
5586
5587
5588
5589
5590
5591
5592
5593
5594
5595
5596
5597
5598
5599
5600
5601
5602
5603
5604
5605
5606
5607
5608
5609
5610
5611
5612
5613
5614
5615
5616
5617
5618
5619
5620
5621
5622
5623
5624
5625
5626
5627
5628
5629
5630
5631
5632
5633
5634
5635
5636
5637
5638
5639
5640
5641
5642
5643
5644
5645
5646
5647
5648
5649
5650
5651
5652
5653
5654
5655
5656
5657
5658
5659
5660
5661
5662
5663
5664
5665
5666
5667
5668
5669
5670
5671
5672
5673
5674
5675
5676
5677
5678
5679
5680
5681
5682
5683
5684
5685
5686
5687
5688
5689
5690
5691
5692
5693
5694
5695
5696
5697
5698
5699
5700
5701
5702
5703
5704
5705
5706
5707
5708
5709
5710
5711
5712
5713
5714
5715
5716
5717
5718
5719
5720
5721
5722
5723
5724
5725
5726
5727
5728
5729
5730
5731
5732
5733
5734
5735
5736
5737
5738
5739
5740
5741
5742
5743
5744
5745
5746
5747
5748
5749
5750
5751
5752
5753
5754
5755
5756
5757
5758
5759
5760
5761
5762
5763
5764
5765
5766
5767
5768
5769
5770
5771
5772
5773
5774
5775
5776
5777
5778
5779
5780
5781
5782
5783
5784
5785
5786
5787
5788
5789
5790
5791
5792
5793
5794
5795
5796
5797
5798
5799
5800
5801
5802
5803
5804
5805
5806
5807
5808
5809
5810
5811
5812
5813
5814
5815
5816
5817
5818
5819
5820
5821
5822
5823
5824
5825
5826
5827
5828
5829
5830
5831
5832
5833
5834
5835
5836
5837
5838
5839
5840
5841
5842
5843
5844
5845
5846
5847
5848
5849
5850
5851
5852
5853
5854
5855
5856
5857
5858
5859
5860
5861
5862
5863
5864
5865
5866
5867
5868
5869
5870
5871
5872
5873
5874
5875
5876
5877
5878
5879
5880
5881
5882
5883
5884
5885
5886
5887
5888
5889
5890
5891
5892
5893
5894
5895
5896
5897
5898
5899
5900
5901
5902
5903
5904
5905
5906
5907
5908
5909
5910
5911
5912
5913
5914
5915
5916
5917
5918
5919
5920
5921
5922
5923
5924
5925
5926
5927
5928
5929
5930
5931
5932
5933
5934
5935
5936
5937
5938
5939
5940
5941
5942
5943
5944
5945
5946
5947
5948
5949
5950
5951
5952
5953
5954
5955
5956
5957
5958
5959
5960
5961
5962
5963
5964
5965
5966
5967
5968
5969
5970
5971
5972
5973
5974
5975
5976
5977
5978
5979
5980
5981
5982
5983
5984
5985
5986
5987
5988
5989
5990
5991
5992
5993
5994
5995
5996
5997
5998
5999
6000
6001
6002
6003
6004
6005
6006
6007
6008
6009
6010
6011
6012
6013
6014
6015
6016
6017
6018
6019
6020
6021
6022
6023
6024
6025
6026
6027
6028
6029
6030
6031
6032
6033
6034
6035
6036
6037
6038
6039
6040
6041
6042
6043
6044
6045
6046
6047
6048
6049
/***************************************************************************
 SocNetV: Social Networks Visualizer 
 version: 0.90
 Written in Qt 4.4

-                           mainwindow.cpp  -  description
                             -------------------
    copyright            : (C) 2005-2010 by Dimitris B. Kalamaras
    email                : dimitris.kalamaras@gmail.com
 ***************************************************************************/

/*******************************************************************************
*     This program is free software: you can redistribute it and/or modify     *
*     it under the terms of the GNU General Public License as published by     *
*     the Free Software Foundation, either version 3 of the License, or        *
*     (at your option) any later version.                                      *
*                                                                              *
*     This program is distributed in the hope that it will be useful,          *
*     but WITHOUT ANY WARRANTY; without even the implied warranty of           *
*     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            *
*     GNU General Public License for more details.                             *
*                                                                              *
*     You should have received a copy of the GNU General Public License        *
*     along with this program.  If not, see <http://www.gnu.org/licenses/>.    *
********************************************************************************/

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <QtGui>
#include <QtDebug>
#include <QSpinBox>

#include <ctime> 

#include "mainwindow.h"
#include "graphicswidget.h"
#include "node.h"
#include "edge.h"
#include "nodenumber.h"
#include "nodelabel.h"
#include "edgeweight.h"
#include "htmlviewer.h"
#include "texteditor.h"
#include "filteredgesbyweightdialog.h"
#include "backgrcircle.h"
#include "vertex.h"




bool printDebug=false;


void myMessageOutput( QtMsgType type, const char *msg )     {
	if (printDebug)	
		switch ( type ) {
			case QtDebugMsg:
				fprintf( stderr, "Debug: %s\n", msg );
				break;
			case QtWarningMsg:
				fprintf( stderr, "Warning: %s\n", msg );
				break;
			case QtFatalMsg:
				fprintf( stderr, "Fatal: %s\n", msg );
				abort();                    // deliberately core dump
			case QtCriticalMsg:
				fprintf( stderr, "Critical: %s\n", msg );
				abort();                    // deliberately core dump
		}
}


/** MainWindow contruction method **/
MainWindow::MainWindow(const QString & m_fileName) {

	qInstallMsgHandler( myMessageOutput );

	setWindowIcon (QIcon(":/images/socnetv.png"));

	/** inits that invoke all other construction parts **/
	initActions();  //register and construct menu Actions 
	initMenuBar();  //construct menu
	initToolBar();  //build the toolbar
	initStatusBar();  //and now add the status bar.
	initToolBox(); //finally, build the toolbox

	colorList = QColor::colorNames();  //and fill a stringList with all X-supported color names

	//set MW minimum size, before creating scene and canvas, so that we may have a clue about their sizes..
	this->setMinimumSize(800,600);

 	initView(); //create the canvas

	//Connect some signals to/from the canvas and the Graph
	connect( graphicsWidget, SIGNAL( selectedNode(Node*) ), 
			this, SLOT( nodeInfoStatusBar(Node*) ) 	);
			
	connect( graphicsWidget, SIGNAL( selectedEdge(Edge*) ), 
			this, SLOT ( linkInfoStatusBar(Edge*) )  );
			
	connect( graphicsWidget, SIGNAL( windowResized(int, int)),
			this, SLOT( windowInfoStatusBar(int,int)) 	);  

	connect( graphicsWidget, SIGNAL( userDoubleClicked(int, QPointF) ), 
			this, SLOT( addNodeWithMouse(int,QPointF) ) ) ;
			
	connect( graphicsWidget, SIGNAL( userMiddleClicked(int, int, float) ), 
			this, SLOT( addLink(int, int, float) ) 	);
			
	connect( graphicsWidget, SIGNAL( openNodeMenu() ), 
			this, SLOT( openNodeContextMenu() ) ) ;

	connect( graphicsWidget, SIGNAL( openEdgeMenu() ), 
			this, SLOT( openLinkContextMenu() ) ) ;

	connect( graphicsWidget, SIGNAL(updateNodeCoords(int, int, int)), 
			this, SLOT( updateNodeCoords(int, int, int) ) );
	
	connect( graphicsWidget, SIGNAL(zoomChanged(int)),
			zoomCombo, SLOT( setCurrentIndex(int)) );

	connect( &activeGraph, SIGNAL( addBackgrCircle(int, int, int) ), 
			graphicsWidget, SLOT(  addBackgrCircle(int, int, int) ) ) ;
			
	connect( &activeGraph, SIGNAL( addBackgrHLine(int) ), 
			graphicsWidget, SLOT(  addBackgrHLine(int) ) ) ;
			
	connect( &activeGraph, SIGNAL( moveNode(int, int, int) ), 
			graphicsWidget, SLOT( moveNode(int, int, int) ) ) ;

				
	connect( &activeGraph, SIGNAL( drawNode( int ,int,  QString, QString, int, QString, QString, int, QPointF, QString, bool, bool, bool) ), 
			graphicsWidget, SLOT( drawNode( int ,int,  QString, QString, int, QString, QString, int, QPointF, QString, bool, bool, bool) ) ) ;
			
	connect( &activeGraph, SIGNAL( eraseEdge(int, int)), 
			graphicsWidget, SLOT( eraseEdge(int, int) ) );
	
	connect( &activeGraph, SIGNAL( graphChanged() ), 
			this, SLOT( graphChanged() ) ) ;
	
	connect( &activeGraph, SIGNAL( signalFileType(int , QString , int , int, bool) ), 
			this, SLOT( fileType(int , QString , int , int, bool) ) 	) ;
	
	connect( &activeGraph, SIGNAL( drawEdge( int, int, float, bool, bool, QString, bool)),
			graphicsWidget, SLOT( drawEdge( int, int,float, bool, bool, QString, bool) )  ) ;

	connect( &activeGraph, SIGNAL( drawEdgeReciprocal(int, int) ), 
			graphicsWidget, SLOT( drawEdgeReciprocal(int, int) ) );
	
	connect( &activeGraph, SIGNAL( statusMessage (QString) ),
					 this, SLOT( statusMessage (QString) ) ) ;

	connect( &activeGraph, SIGNAL( selectedVertex(int) ), 
					this, SLOT( selectedNode(int) ) ) ;

	connect( &activeGraph, SIGNAL( eraseNode(long int) ),
			 graphicsWidget, SLOT(  eraseNode(long int) ) );

	
	//connect some signals/slots with MW widgets
	connect( addNodeBt,SIGNAL(clicked()), this, SLOT( addNode() ) );
	
	connect( addLinkBt,SIGNAL(clicked()), this, SLOT( slotAddLink() ) );
	
	connect( removeNodeBt,SIGNAL(clicked()), this, SLOT( slotRemoveNode() ) );
	
	connect( removeLinkBt,SIGNAL(clicked()), this, SLOT( slotRemoveLink() ) );

 	connect( zoomCombo, SIGNAL(currentIndexChanged(const int &)),
			graphicsWidget, SLOT( changeZoom(const int &))  );
			
	connect( zoomOutAct, SIGNAL(triggered()), graphicsWidget, SLOT( zoomOut() ) );
	connect( zoomInAct, SIGNAL(triggered()), graphicsWidget, SLOT( zoomIn() ) );

	connect( rotateSpinBox, SIGNAL(valueChanged(int)), graphicsWidget, SLOT( rot(int) ) );
	
	connect( &m_filterEdgesByWeightDialog, SIGNAL( userChoices( float, bool) ), 
			&activeGraph, SLOT( filterEdgesByWeight (float, bool) ) );

	connect( &m_WebCrawlerDialog, SIGNAL( userChoices( QString, int, int, bool)  ), 
			this, SLOT(  slotWebCrawl( QString, int, int, bool) ) );

	connect( &m_datasetSelectDialog, SIGNAL( userChoices( QString) ), 
			this, SLOT( slotRecreateDataSet(QString) ) );

	connect( &activeGraph, SIGNAL( setEdgeVisibility ( int, int, bool) ), 
			graphicsWidget, SLOT(  setEdgeVisibility ( int, int, bool) ) );

	connect( &activeGraph, SIGNAL( setVertexVisibility(long int, bool)  ),
			graphicsWidget, SLOT(  setNodeVisibility (long int ,  bool) ) );

	connect( circleClearBackgrCirclesAct, SIGNAL(activated()), 
			graphicsWidget, SLOT(clearBackgrCircles()));

 
	//create an horizontal layout for the toolbox and the canvas. This will be our MW layout.
	QHBoxLayout *layout = new QHBoxLayout;
	layout->addWidget(toolBox); 		//add them
	layout->addWidget(graphicsWidget);	//create a dummy widget, for the above layout
	QWidget *widget = new QWidget;
	widget->setLayout(layout);
	
	setCentralWidget(widget);	//now set this as central widget of MW

	/* 
		initialise default network parameters 
	*/
	initNet();


	/** DEFAULTING HERE DOES NOT CHANGE BOOL VALUE **/
	/** EVERY TIME INITNET IS CALLED **/
	bezier=false; 
	firstTime=true;

	graphicsWidget->setInitNodeColor(initNodeColor);	
	graphicsWidget->setInitNumberDistance(numberDistance);
	graphicsWidget->setInitLabelDistance(labelDistance);
	graphicsWidget->setInitNodeSize(initNodeSize);
	graphicsWidget->setBackgroundBrush(QBrush(initBackgroundColor)); //Qt::gray

	 /**Try to load a GraphML network file on exec time*/
	if (!m_fileName.isEmpty())  
	{
		fileName=m_fileName;
		fileNameNoPath=fileName.split ("/");
		loadNetworkFile(fileName, 0 );
	}

	if (firstTime) {
		createFortuneCookies();	
		createTips();
	}	

	graphicsWidget->setFocus();
	
	statusMessage( tr("Welcome to Social Networks Visualizer, Version ")+VERSION);

}



MainWindow::~MainWindow() {
	delete printer;
	delete scene;
	delete graphicsWidget;
}



/** initializes all QActions of the application */
void MainWindow::initActions(){
	printer = new QPrinter;
	
	/**
	File menu actions
	*/
	fileNew = new QAction(QIcon(":/images/new.png"), tr("&New"),  this);
	fileNew->setShortcut(tr("Ctrl+N"));
	fileNew->setStatusTip(tr("Creates a new network"));
	fileNew->setToolTip(tr("New network (Ctrl+N)"));
	fileNew->setWhatsThis(tr("New\n\nCreates a new network"));
	connect(fileNew, SIGNAL(activated()), this, SLOT(slotCreateNew()));

	fileOpen = new QAction(QIcon(":/images/open.png"), tr("&Open"), this);
	fileOpen->setShortcut(tr("Ctrl+O"));
	fileOpen->setToolTip(tr("Open network (Ctrl+O)"));
	fileOpen->setStatusTip(tr("Open a GraphML-formatted file of an existing network"));
	fileOpen->setWhatsThis(tr("Open\n\nOpens a file of an existing network in GraphML format"));
	connect(fileOpen, SIGNAL(activated()), this, SLOT(slotImportGraphML()));


	importPajek = new QAction( QIcon(":/images/open.png"), tr("&Pajek"), this);
	importPajek->setStatusTip(tr("Import a Pajek-formatted file"));
	importPajek->setWhatsThis(tr("Import  Pajek \n\n Imports a network from a Pajek-formatted file"));
	connect(importPajek, SIGNAL(activated()), this, SLOT(slotImportPajek()));
	

	importSM = new QAction( QIcon(":/images/open.png"), tr("&Adjacency Matrix"), this);
	importSM->setStatusTip(tr("Import an Adjacency matrix file"));
	importSM->setWhatsThis(tr("Import Sociomatrix \n\n  Imports a network from an Adjacency matrix-formatted file"));
	connect(importSM, SIGNAL(activated()), this, SLOT(slotImportSM()));

	importDot = new QAction( QIcon(":/images/open.png"), tr("&Dot"), this);
	importDot->setStatusTip(tr("Import an dot file"));
	importDot->setWhatsThis(tr("Import Sociomatrix \n\n  Imports a network from an dot matrix-formatted file"));
	connect(importDot, SIGNAL(activated()), this, SLOT(slotImportDot()));


	importDL = new QAction( QIcon(":/images/open.png"), tr("&DL..."), this);
	importDL->setStatusTip(tr("Import network to a DL-formatted file"));
	importDL->setWhatsThis(tr("Import DL\n\nImport network to a DL-formatted"));
	connect(importDL, SIGNAL(activated()), this, SLOT(slotImportDL()));


	importList = new QAction( QIcon(":/images/open.png"), tr("&List"), this);
	importList->setStatusTip(tr("Import network from a List-formatted file. "));
	importList->setWhatsThis(tr("Import List\n\nImport a network from a List-formatted file"));
	connect(importList, SIGNAL(activated()), this, SLOT(slotImportEdgeList()));


	importTwoModeSM = new QAction( QIcon(":/images/open.png"), tr("&Two Mode Sociomatrix"), this);
	importTwoModeSM->setStatusTip(tr("Imports a two mode sociomatrix (affiliation network) file"));
	importTwoModeSM->setWhatsThis(tr("Import Sociomatrix \n\n  Imports a two mode network from a sociomatrix file. Two-mode networks are described by affiliation network matrices, where A(i,j) codes the events/organizations each actor is affiliated with."));
	connect(importTwoModeSM, SIGNAL(activated()), this, SLOT(slotImportTwoModeSM()));


  	fileSave = new QAction(QIcon(":/images/save.png"), tr("&Save"),  this);
	fileSave->setShortcut(tr("Ctrl+S"));
	fileSave->setToolTip(tr("Save network (Ctrl+S)"));
	fileSave->setStatusTip(tr("Saves the actual network to the current file"));
	fileSave->setWhatsThis(tr("Save.\n\nSaves the actual network"));
	connect(fileSave, SIGNAL(activated()), this, SLOT(slotFileSave()));

	fileSaveAs = new QAction(QIcon(":/images/save.png"), tr("Save &As..."),  this);
	fileSaveAs->setShortcut(tr("Ctrl+Shift+S"));
	fileSaveAs->setStatusTip(tr("Saves the actual network under a new filename"));
	fileSaveAs->setWhatsThis(tr("Save As\n\nSaves the actual network under a new filename"));
	connect(fileSaveAs, SIGNAL(activated()), this, SLOT(slotFileSaveAs()));

	exportBMP = new QAction(QIcon(":/images/save.png"), tr("&BMP..."), this);
	exportBMP->setStatusTip(tr("Export network to a BMP image"));
	exportBMP->setWhatsThis(tr("Export BMP \n\n Export network to a BMP image"));
	connect(exportBMP, SIGNAL(activated()), this, SLOT(slotExportBMP()));

	exportPNG = new QAction( QIcon(":/images/save.png"), tr("&PNG..."), this);
	exportPNG->setStatusTip(tr("Export network to a PNG image"));
	exportPNG->setWhatsThis(tr("Export PNG \n\n Export network to a PNG image"));
	connect(exportPNG, SIGNAL(activated()), this, SLOT(slotExportPNG()));


	exportPDF = new QAction( QIcon(":/images/save.png"), tr("&PDF..."), this);
	exportPDF->setStatusTip(tr("Export network to a PDF file"));
	exportPDF->setWhatsThis(tr("Export PDF\n\n Export network to a PDF document"));
	connect(exportPDF, SIGNAL(activated()), this, SLOT(slotExportPDF()));

	exportSM = new QAction( QIcon(":/images/save.png"), tr("&Adjacency Matrix"), this);
	exportSM->setStatusTip(tr("Export network to an adjacency matrix file"));
	exportSM->setWhatsThis(tr("Export Sociomatrix \n\n Export network to a adjacency matrix-formatted file"));
	connect(exportSM, SIGNAL(activated()), this, SLOT(slotExportSM()));

	exportPajek = new QAction( QIcon(":/images/save.png"), tr("&Pajek"), this);
	exportPajek->setStatusTip(tr("Export network to a Pajek-formatted file"));
	exportPajek->setWhatsThis(tr("Export Pajek \n\n Export network to a Pajek-formatted file"));
	connect(exportPajek, SIGNAL(activated()), this, SLOT(slotExportPajek()));

	exportList = new QAction( QIcon(":/images/save.png"), tr("&List"), this);
	exportList->setStatusTip(tr("Export network to a List-formatted file. "));
	exportList->setWhatsThis(tr("Export List\n\nExport network to a List-formatted file"));
	connect(exportList, SIGNAL(activated()), this, SLOT(slotExportList()));

	exportDL = new QAction( QIcon(":/images/save.png"), tr("&DL..."), this);
	exportDL->setStatusTip(tr("Export network to a DL-formatted file"));
	exportDL->setWhatsThis(tr("Export DL\n\nExport network to a DL-formatted"));
	connect(exportDL, SIGNAL(activated()), this, SLOT(slotExportDL()));

	exportGW = new QAction( QIcon(":/images/save.png"), tr("&GW..."), this);
	exportGW->setStatusTip(tr("Export network to a GW-formatted file"));
	exportGW->setWhatsThis(tr("Export\n\nExport network to a GW formatted file"));
	connect(exportGW, SIGNAL(activated()), this, SLOT(slotExportGW()));

	fileClose = new QAction( tr("&Close"), this);
	fileClose->setStatusTip(tr("Closes the actual network"));
	fileClose->setWhatsThis(tr("Close \n\nCloses the actual network"));
	connect(fileClose, SIGNAL(activated()), this, SLOT(slotFileClose()));

	printNetwork = new QAction(QIcon(":/images/print.png"), tr("&Print"), this);
	printNetwork->setShortcut(tr("Ctrl+P"));
	printNetwork->setStatusTip(tr("Prints whatever is viewable on the canvas."));
	printNetwork->setWhatsThis(tr("Printing \n\n This function prints whatever is viewable on the canvas. \nTo print the whole network, you might want to zoom-out."));
	connect(printNetwork, SIGNAL(activated()), this, SLOT(slotPrintView()));

	fileQuit = new QAction(QIcon(":/images/exit.png"), tr("E&xit"), this);
	fileQuit->setShortcut(tr("Ctrl+Q"));
	fileQuit->setStatusTip(tr("Quits the application"));
	fileQuit->setWhatsThis(tr("Exit\n\nQuits the application"));
	connect(fileQuit, SIGNAL(activated()), this, SLOT(close()));


	openTextEditorAct = new QAction(QIcon(""), tr("Open Text Editor"),this);
	openTextEditorAct ->setShortcut(tr("Shift+F5"));
	openTextEditorAct->setStatusTip(tr("Opens the SocNetV text editor. You can copy/paste network data, save and then import them..."));
	openTextEditorAct->setWhatsThis(tr("Open Text Editor\n\nOpens the SocNetV text editor where you can copy paste network data, of any supported format, and save to a file. Then you can import that file to SocNetV..."));
	connect(openTextEditorAct, SIGNAL(activated()), this, SLOT(slotOpenTextEditor()));
	
	
	viewNetworkFileAct = new QAction(QIcon(":/images/net2.png"), tr("View Loaded File"),this);
	viewNetworkFileAct ->setShortcut(tr("F5"));
	viewNetworkFileAct->setStatusTip(tr("Displays the loaded network file"));
	viewNetworkFileAct->setWhatsThis(tr("View Loaded File\n\nDisplays the file of the loaded network"));
	connect(viewNetworkFileAct, SIGNAL(activated()), this, SLOT(slotViewNetworkFile()));

	viewSociomatrixAct = new QAction(QIcon(":/images/sm.png"), tr("View Adjacency Matrix"),  this);
	viewSociomatrixAct ->setShortcut(tr("F6"));
	viewSociomatrixAct->setStatusTip(tr("Displays the adjacency matrix of the active network. See manual or online help for more..."));
	viewSociomatrixAct->setWhatsThis(tr("View Adjacency Matrix\n\nDisplays the adjacency matrix of the active network. \n\n The adjacency matrix of a network is a matrix where each element a(i,j) is equal to the weight of the link from node i to node j. If the nodes are not connected, then a(i,j)=0. "));
	connect(viewSociomatrixAct, SIGNAL(activated()), this, SLOT(slotViewAdjacencyMatrix()));


	recreateDataSetAct = new QAction(QIcon(":/images/sm.png"), tr("Create Known Data Sets"),  this);
	recreateDataSetAct ->setShortcut(tr("F7"));
	recreateDataSetAct->setStatusTip(tr("Recreates a variety of known data sets."));
	recreateDataSetAct->setWhatsThis(tr("Known Data Sets\n\nRecreates some of the most widely used data sets in network analysis studies"));
	connect(recreateDataSetAct, SIGNAL(activated()), this, SLOT(slotShowDataSetSelectDialog()));



	createUniformRandomNetworkAct = new QAction(QIcon(":/images/erdos.png"), tr("Erdos-Renyi G(n,p)"),  this);
	createUniformRandomNetworkAct ->setShortcut(tr("Shift+U"));
	createUniformRandomNetworkAct->setStatusTip(tr("Creates a random network where each edge is included with a given probability"));
	createUniformRandomNetworkAct->setWhatsThis(tr("Uniform \n\nCreates a random network of G(n, p) model by connecting nodes randomly. Each edge is included in the graph with equal probability p, independently of the other edges"));
	connect(createUniformRandomNetworkAct, SIGNAL(activated()), this, SLOT(slotCreateRandomNetErdos()));

	createLatticeNetworkAct = new QAction( QIcon(":/images/net1.png"), tr("Ring Lattice"), this);
	createLatticeNetworkAct ->setShortcut(tr("Shift+L"));
	createLatticeNetworkAct->setStatusTip(tr("Creates a ring lattice random network"));
	createLatticeNetworkAct->setWhatsThis(tr("Ring Lattice \n\nA ring lattice or a physicist's lattice is a graph with N nodes each connected to K neighbors, K / 2 on each side."));
	connect(createLatticeNetworkAct, SIGNAL(activated()), this, SLOT(slotCreateRandomNetRingLattice()));

	createSameDegreeRandomNetworkAct = new QAction(QIcon(":/images/net.png"), tr("Same Degree"), this);
	createSameDegreeRandomNetworkAct->setStatusTip(tr("Creates a random network where all nodes have the same degree."));
	createSameDegreeRandomNetworkAct->setWhatsThis(tr("Same Degree \n\nCreates a random network where all nodes have the same degree "));
	connect(createSameDegreeRandomNetworkAct, SIGNAL(activated()), this, SLOT(slotCreateSameDegreeRandomNetwork()));

	createGaussianRandomNetworkAct = new QAction(tr("Gaussian"),	this);
	createGaussianRandomNetworkAct->setStatusTip(tr("Creates a Gaussian distributed random network"));
	createGaussianRandomNetworkAct->setWhatsThis(tr("Gaussian \n\nCreates a random network of Gaussian distribution"));
	connect(createGaussianRandomNetworkAct, SIGNAL(activated()), this, SLOT(slotCreateGaussianRandomNetwork()));

	createSmallWorldRandomNetworkAct = new QAction(QIcon(":/images/sw.png"), tr("Small World"),	this);
	createSmallWorldRandomNetworkAct->setShortcut(tr("Shift+W"));
	createSmallWorldRandomNetworkAct->setStatusTip(tr("Creates a random network with small world properties"));
	createSmallWorldRandomNetworkAct->setWhatsThis(tr("Small World \n\nA Small World, according to the Watts and Strogatz model, is a random network with short average path lengths and high clustering coefficient."));
	connect(createSmallWorldRandomNetworkAct, SIGNAL(activated()), this, SLOT(slotCreateSmallWorldRandomNetwork()));




	webCrawlerAct = new QAction(QIcon(":/images/webcrawler.png"), tr("Web Crawler"),	this);
	webCrawlerAct->setShortcut(tr("Shift+C"));
	webCrawlerAct->setStatusTip(tr("Creates a network from all links found in a given website"));
	webCrawlerAct->setWhatsThis(tr("Web Crawler \n\nA Web crawler is a built-in bot, which starts with a given URL (website or webpage) to visit. As the algorithm crawls this webpage, it identifies all the links in the page and adds them to a list of URLs (called frontier). Then, all the URLs from the frontier are recursively visited. You must provide maximum recursion level (how many URLs from the frontier will be visited) and maximum running time, along with the initial web address..."));
	connect(webCrawlerAct, SIGNAL(activated()), this, SLOT(slotShowWebCrawlerDialog()));

	
	/**
	Edit menu actions
	*/
	findNodeAct = new QAction(QIcon(":/images/find.png"), tr("Find Node"), this);
	findNodeAct->setShortcut(tr("Ctrl+F"));
	findNodeAct->setStatusTip(tr("Finds and highlights a node by number or label. Press Ctrl+F again to undo."));
	findNodeAct->setWhatsThis(tr("Find Node\n\nFinds a node with a given number or label and doubles its size. Ctrl+F again resizes back the node"));
	connect(findNodeAct, SIGNAL(activated()), this, SLOT(slotFindNode()) );
		
	addNodeAct = new QAction(QIcon(":/images/add.png"), tr("Add Node"), this);
	addNodeAct->setShortcut(tr("Ctrl+A"));
	addNodeAct->setStatusTip(tr("Adds a node"));
	addNodeAct->setWhatsThis(tr("Add Node\n\nAdds a node to the network"));
	connect(addNodeAct, SIGNAL(activated()), this, SLOT(addNode()));

	removeNodeAct = new QAction(QIcon(":/images/remove.png"),tr("Remove Node"), this);
	removeNodeAct ->setShortcut(tr("Ctrl+Shift+A"));
	removeNodeAct->setStatusTip(tr("Removes a node"));
	removeNodeAct->setWhatsThis(tr("Remove Node\n\nRemoves a node from the network"));
	connect(removeNodeAct, SIGNAL(activated()), this, SLOT(slotRemoveNode()));

	changeNodeLabelAct = new QAction(QIcon(":/images/letters.png"), tr("Change Label"),	this);
	changeNodeLabelAct->setStatusTip(tr("Changes the Label of a node"));
	changeNodeLabelAct->setWhatsThis(tr("Change Label\n\nChanges the label of a node"));
	connect(changeNodeLabelAct, SIGNAL(activated()), this, SLOT(slotChangeNodeLabel()));

	changeNodeColorAct = new QAction(QIcon(":/images/colorize.png"), tr("Change Color"), this);
	changeNodeColorAct->setStatusTip(tr("Changes the color of a node"));
	changeNodeColorAct->setWhatsThis(tr("Change Color\n\nChanges the Color of a node"));
	connect(changeNodeColorAct, SIGNAL(activated()), this, SLOT(slotChangeNodeColor()));

	changeNodeSizeAct = new QAction(QIcon(":/images/resize.png"),tr("Change Size"), this);
	changeNodeSizeAct->setStatusTip(tr("Changes the actual size of a node"));
	changeNodeSizeAct->setWhatsThis(tr("Change Size\n\nChanges the actual size of a node"));
	connect(changeNodeSizeAct, SIGNAL(activated()), this, SLOT(slotChangeNodeSize()));

	changeNodeValueAct = new QAction(tr("Change Value"), this);
	changeNodeValueAct->setStatusTip(tr("Changes the value of a node"));
	changeNodeValueAct->setWhatsThis(tr("Change Value\n\nChanges the value of a node"));
	connect(changeNodeValueAct, SIGNAL(activated()), this, SLOT(slotChangeNodeValue()));

	changeAllNodesSizeAct = new QAction(QIcon(":/images/resize.png"), tr("Change all Nodes Size"),	this);
	changeAllNodesSizeAct->setStatusTip(tr("This option lets you change the size of all nodes"));
	changeAllNodesSizeAct->setWhatsThis(tr("Nodes Size\n\nThis option lets you change the size of all nodes"));
	connect(changeAllNodesSizeAct, SIGNAL(activated()), this, SLOT(slotChangeAllNodesSize()) );

	changeAllNodesShapeAct = new QAction( tr("Change all Nodes Shape"),	this);
	changeAllNodesShapeAct->setStatusTip(tr("This option lets you change the shape of all nodes"));
	changeAllNodesShapeAct->setWhatsThis(tr("Nodes Shape\n\nThis option lets you change the shape of all nodes"));
	connect(changeAllNodesShapeAct, SIGNAL(activated()), this, SLOT(slotChangeAllNodesShape()) );

	changeNodeBoxAct = new QAction(QIcon(":/images/box.png"), tr("Change Node Shape to Box"),this);
	changeNodeBoxAct->setStatusTip(tr("This option lets you change the shape of a node to a box"));
	changeNodeBoxAct->setWhatsThis(tr("Node as a box\n\nThis option lets you change the shape of a node to a box"));
	connect(changeNodeBoxAct, SIGNAL(activated()), this, SLOT(slotChangeNodeBox()) );

	changeNodeTriangleAct = new QAction( tr("Change Node Shape to Triangle"),	this);
	changeNodeTriangleAct->setStatusTip(tr("This option lets you change the shape of a node to a box"));
	changeNodeTriangleAct->setWhatsThis(tr("Node as a box\n\nThis option lets you change the shape of a node to a box"));
	connect(changeNodeTriangleAct, SIGNAL(activated()), this, SLOT(slotChangeNodeTriangle()) );

	changeNodeCircleAct = new QAction(QIcon(":/images/circle.png"), tr("Change Node Shape to Circle"),	this);
	changeNodeCircleAct->setStatusTip(tr("This option lets you change the shape of a node to a box"));
	changeNodeCircleAct->setWhatsThis(tr("Node as a box\n\nThis option lets you change the shape of a node to a box"));
	connect(changeNodeCircleAct, SIGNAL(activated()), this, SLOT(slotChangeNodeCircle()) );

	changeNodeDiamondAct = new QAction(QIcon(":/images/diamond.png"), tr("Change Node Shape to Diamond"),	this);
	changeNodeDiamondAct->setStatusTip(tr("This option lets you change the shape of a node to a box"));
	changeNodeDiamondAct->setWhatsThis(tr("Node as a box\n\nThis option lets you change the shape of a node to a box"));
	connect(changeNodeDiamondAct, SIGNAL(activated()), this, SLOT(slotChangeNodeDiamond()) );

	changeNodeEllipseAct = new QAction( tr("Change Node Shape to Ellipse"),	this);
	changeNodeEllipseAct->setStatusTip(tr("This option lets you change the shape of a node to a box"));
	changeNodeEllipseAct->setWhatsThis(tr("Node as a box\n\nThis option lets you change the shape of a node to a box"));
	connect(changeNodeEllipseAct, SIGNAL(activated()), this, SLOT(slotChangeNodeEllipse()) );

	changeNumbersSizeAct = new QAction( tr("Change all Numbers Size"),	this);
	changeNumbersSizeAct->setStatusTip(tr("It lets you change the font size of the numbers of all nodes"));
	changeNumbersSizeAct->setWhatsThis(tr("Numbers Size\n\nChanges the size of the numbers of all nodes"));
	connect(changeNumbersSizeAct, SIGNAL(activated()), this, SLOT(slotChangeNumbersSize()) );

	changeLabelsSizeAct = new QAction( tr("Change all Labels Size"), this);
	changeLabelsSizeAct->setStatusTip(tr("You can change the font size of the labels of all nodes"));
	changeLabelsSizeAct->setWhatsThis(tr("Labels Size\n\nChange the fontsize of the labels of all nodes"));
	connect(changeLabelsSizeAct, SIGNAL(activated()), this, SLOT(slotChangeLabelsSize()) );
	
	addLinkAct = new QAction(QIcon(":/images/plines.png"), tr("Add Link"),this);
	addLinkAct->setShortcut(tr("Ctrl+L"));
	addLinkAct->setStatusTip(tr("Adds a Link to a Node"));
	addLinkAct->setWhatsThis(tr("Add Link\n\nAdds a Link to the network"));
	connect(addLinkAct, SIGNAL(activated()), this, SLOT(slotAddLink()));
	
	removeLinkAct = new QAction(QIcon(":/images/disconnect.png"), tr("Remove"), this);
	removeLinkAct ->setShortcut(tr("Ctrl+Shift+L"));
	removeLinkAct->setStatusTip(tr("Removes a Link"));
	removeLinkAct->setWhatsThis(tr("Remove Link\n\nRemoves a Link from the network"));
	connect(removeLinkAct, SIGNAL(activated()), this, SLOT(slotRemoveLink()));
	
	changeLinkLabelAct = new QAction(QIcon(":/images/letters.png"), tr("Change Label"), this);
	changeLinkLabelAct->setStatusTip(tr("Changes the Label of a Link"));
	changeLinkLabelAct->setWhatsThis(tr("Change Label\n\nChanges the label of a Link"));
	connect(changeLinkLabelAct, SIGNAL(activated()), this, SLOT(slotChangeLinkLabel()));
	changeLinkLabelAct->setEnabled(false);

	changeLinkColorAct = new QAction(QIcon(":/images/colorize.png"),tr("Change Color"),	this);
	changeLinkColorAct->setStatusTip(tr("Changes the Color of a Link"));
	changeLinkColorAct->setWhatsThis(tr("Change Color\n\nChanges the Color of a Link"));
	connect(changeLinkColorAct, SIGNAL(activated()), this, SLOT(slotChangeLinkColor()));

	changeLinkWeightAct = new QAction(tr("Change Weight"), this);
	changeLinkWeightAct->setStatusTip(tr("Changes the Weight of a Link"));
	changeLinkWeightAct->setWhatsThis(tr("Change Value\n\nChanges the Weight of a Link"));
	connect(changeLinkWeightAct, SIGNAL(activated()), this, SLOT(slotChangeLinkWeight()));

	filterNodesAct = new QAction(tr("Filter Nodes"), this);
	filterNodesAct -> setEnabled(false);
	filterNodesAct->setStatusTip(tr("Filters Nodes of some value out of the network"));
	filterNodesAct->setWhatsThis(tr("Filter Nodes\n\nFilters Nodes of some value out of the network."));
	connect(filterNodesAct, SIGNAL(activated()), this, SLOT(slotFilterNodes()));

	filterOrphanNodesAct = new QAction(tr("Filter Orphan Nodes"), this);
	filterOrphanNodesAct -> setEnabled(true);
	filterOrphanNodesAct -> setCheckable(true);
	filterOrphanNodesAct -> setChecked(false);
	filterOrphanNodesAct -> setStatusTip(tr("Filters Nodes with no edges"));
	filterOrphanNodesAct -> setWhatsThis(tr("Filter Orphan Nodes\n\n Enables or disables displaying of orphan nodes. Orphan nodes are those with no edges..."));
	connect(filterOrphanNodesAct, SIGNAL(activated()), this, SLOT(slotFilterOrphanNodes()));

	filterEdgesAct = new QAction(tr("Filter Links"), this);
	filterEdgesAct -> setEnabled(true);
	filterEdgesAct -> setStatusTip(tr("Filters Links of some weight out of the network"));
	filterEdgesAct -> setWhatsThis(tr("Filter Links\n\nFilters Link of some specific weight out of the network."));
	connect(filterEdgesAct , SIGNAL(activated()), this, SLOT(slotShowFilterEdgesDialog()));

	changeBackColorAct = new QAction(QIcon(":/images/color.png"), tr("Change Background Color"), this);
	changeBackColorAct->setStatusTip(tr("Click to change the background color"));
	changeBackColorAct->setWhatsThis(tr("Background\n\nChanges background color"));
	connect(changeBackColorAct, SIGNAL(activated()), this, SLOT(slotBackgroundColor()));

	changeAllNodesColorAct = new QAction(QIcon(":/images/nodecolor.png"), tr("Change all Nodes Colors"),	this);
	changeAllNodesColorAct->setStatusTip(tr("Click to choose a new color for all nodes."));
	changeAllNodesColorAct->setWhatsThis(tr("All Nodes\n\nChanges all nodes color at once."));
	connect(changeAllNodesColorAct, SIGNAL(activated()), this, SLOT(slotAllNodesColor()) );

	changeAllNumbersColorAct = new QAction( tr("Change all Numbers Colors"),	this);
	changeAllNumbersColorAct->setStatusTip(tr("Click to change the color of all numbers."));
	changeAllNumbersColorAct->setWhatsThis(tr("Numbers\n\nChanges the color of all numbers."));
	connect(changeAllNumbersColorAct, SIGNAL(activated()), this, SLOT(slotAllNumbersColor()));

	changeAllLabelsColorAct = new QAction( tr("Change all Labels Colors"),	this);
	changeAllLabelsColorAct->setStatusTip(tr("Click to change the color of all node labels."));
	changeAllLabelsColorAct->setWhatsThis(tr("Numbers\n\nChanges the color of all node labels."));
	connect(changeAllLabelsColorAct, SIGNAL(activated()), this, SLOT(slotAllLabelsColor()));

	changeAllLinksColorAct = new QAction( tr("Change all Links Colors"), this);
	changeAllLinksColorAct->setStatusTip(tr("Click to change the color of all links."));
	changeAllLinksColorAct->setWhatsThis(tr("Background\n\nChanges all links color"));
	connect(changeAllLinksColorAct, SIGNAL(activated()), this, SLOT(slotAllLinksColor()));



	transformNodes2LinksAct = new QAction( tr("Transform Nodes to Links"),this);
	transformNodes2LinksAct->setStatusTip(tr("Transforms the network so that nodes become links and vice versa"));
	transformNodes2LinksAct->setWhatsThis(tr("Transform Nodes LinksAct\n\nTransforms network so that nodes become links and vice versa"));
	connect(transformNodes2LinksAct, SIGNAL(activated()), this, SLOT(slotTransformNodes2Links()));

	symmetrizeAct= new QAction(QIcon(":/images/symmetrize.png"), tr("Symmetrize Links"), this);
	symmetrizeAct->setShortcut(tr("Shift+R"));
	symmetrizeAct->setStatusTip(tr("Makes all edges reciprocal (thus, a symmetric graph)."));
	symmetrizeAct->setWhatsThis(tr("Symmetrize Edges\n\nTransforms all arcs to double links (edges). The result is a symmetric network"));
	connect(symmetrizeAct, SIGNAL(activated()), this, SLOT(slotSymmetrize()));	




	/**
	Layout menu actions
	*/
	strongColorationAct = new QAction ( tr("Strong Structural"), this);
	strongColorationAct -> setStatusTip( tr("Nodes are assigned the same color if they have identical in and out neighborhoods") );
	strongColorationAct -> setWhatsThis( tr("Click this to colorize nodes; Nodes are assigned the same color if they have identical in and out neighborhoods"));
	connect(strongColorationAct, SIGNAL(activated() ), this, SLOT(slotColorationStrongStructural()) );
	
	regularColorationAct = new QAction ( tr("Regular"), this);
	regularColorationAct -> setStatusTip( tr("Nodes are assigned the same color if they have neighborhoods of the same set of colors") );
	regularColorationAct -> setWhatsThis( tr("Click this to colorize nodes; Nodes are assigned the same color if they have neighborhoods of the same set of colors"));
	connect(regularColorationAct, SIGNAL(activated() ), this, SLOT(slotColorationRegular()) );
	
	randLayoutAct = new QAction( tr("Random"),this);
	randLayoutAct -> setShortcut(tr("Ctrl+0"));
	randLayoutAct -> setStatusTip(tr("Repositions all nodes in random places"));
	randLayoutAct -> setWhatsThis(tr("Random Layout\n\n Repositions all nodes in random places"));
	connect(randLayoutAct, SIGNAL(activated()), this, SLOT(slotLayoutRandom()));

	randCircleLayoutAct = new QAction(tr("Random Circle"),	this);
	randCircleLayoutAct ->setStatusTip(tr("Repositions the nodes randomly on a circle"));
	randCircleLayoutAct->setWhatsThis(tr("Random Circle Layout\n\n Repositions the nodes randomly on a circle"));
	connect(randCircleLayoutAct, SIGNAL(activated()), this, SLOT(slotLayoutRandomCircle()));

	circleInDegreeLayoutAct = new QAction( tr("In-Degree"),	this);
	circleInDegreeLayoutAct ->setShortcut(tr("Ctrl+Alt+1"));
	circleInDegreeLayoutAct ->setStatusTip(tr("Repositions the nodes on circles of different radius. More In-Degree Central Nodes are positioned towards the centre."));
	circleInDegreeLayoutAct->setWhatsThis(tr("Circle In-Degree Centrality Layout\n\n Repositions the nodes on circles of different radius. More In-Degree Central Nodes are positioned towards the centre."));
	connect(circleInDegreeLayoutAct, SIGNAL(activated()), this, SLOT(slotLayoutRadialCentralityInDegree()));

	
	circleOutDegreeLayoutAct = new QAction( tr("Out-Degree"),	this);
	circleOutDegreeLayoutAct ->setShortcut(tr("Ctrl+Alt+2"));
	circleOutDegreeLayoutAct ->setStatusTip(tr("Repositions the nodes on circles of different radius. More Out-Degree Central Nodes are positioned towards the centre."));
	circleOutDegreeLayoutAct->setWhatsThis(tr("Circle Out-Degree Centrality Layout\n\n Repositions the nodes on circles of different radius. More Out-Degree Central Nodes are positioned towards the centre."));
	connect(circleOutDegreeLayoutAct, SIGNAL(activated()), this, SLOT(slotLayoutRadialCentralityOutDegree()));

	circleClosenessLayoutAct = new QAction( tr("Closeness"),	this);
	circleClosenessLayoutAct ->setShortcut(tr("Ctrl+Alt+3"));
	circleClosenessLayoutAct ->setStatusTip(tr("Repositions the nodes on circles of different radius. More Closeness Central Nodes are positioned towards the centre."));
	circleClosenessLayoutAct->setWhatsThis(tr("Circle Closeness Centrality Layout\n\n Repositions the nodes on circles of different radius. More Closeness Central Nodes are positioned towards the centre."));
	connect(circleClosenessLayoutAct, SIGNAL(activated()), this, SLOT(slotLayoutRadialCentralityCloseness()));

	circleBetweenessLayoutAct = new QAction( tr("Betweeness"), this);
	circleBetweenessLayoutAct ->setShortcut(tr("Ctrl+Alt+4"));
	circleBetweenessLayoutAct ->setStatusTip(tr("Repositions the nodes on circles of different radius. More Betweeness Central Nodes are positioned towards the centre."));
	circleBetweenessLayoutAct->setWhatsThis(tr("Circle Betweeness Centrality Layout\n\n Repositions the nodes on circles of different radius. More Betweeness Central Nodes are positioned towards the centre."));
	connect(circleBetweenessLayoutAct, SIGNAL(activated()), this, SLOT(slotLayoutRadialCentralityBetweeness()));

	circleStressLayoutAct = new QAction( tr("Stress"),	this);
        circleStressLayoutAct ->setShortcut(tr("Ctrl+Alt+5"));
	circleStressLayoutAct ->setStatusTip(tr("Repositions the nodes on circles of different radius. More Stressed Central Nodes are positioned towards the centre."));
	circleStressLayoutAct->setWhatsThis(tr("Circle Stress Centrality Layout\n\n Repositions the nodes on circles of different radius. Nodes having greater Stress Centrality are situated towards the centre."));
	connect(circleStressLayoutAct, SIGNAL(activated()), this, SLOT(slotLayoutRadialCentralityStress() ) );
	
	circleGraphLayoutAct = new QAction( tr("Graph"),	this);
        circleGraphLayoutAct ->setShortcut(tr("Ctrl+Alt+6"));
	circleGraphLayoutAct ->setStatusTip(tr("Repositions the nodes on circles of different radius. More Graph centralized nodes are positioned towards the centre."));
	circleGraphLayoutAct->setWhatsThis(tr("Circle Graph Centrality Layout\n\n Repositions the nodes on circles of different radius. Nodes having greater Graph Centrality are situated towards the centre."));
	connect(circleGraphLayoutAct, SIGNAL(activated()), this, SLOT(slotLayoutRadialCentralityGraph() ) );

	
	circleEccentrLayoutAct = new QAction( tr("Eccentricity"),	this);
        circleEccentrLayoutAct ->setShortcut(tr("Ctrl+Alt+7"));
	circleEccentrLayoutAct  ->setStatusTip(tr("Repositions the nodes on circles of different radius. Nodes of large eccentricity are positioned towards the centre."));
	circleEccentrLayoutAct ->setWhatsThis(tr("Circle Eccentricity Centrality Layout\n\n Repositions the nodes on circles of different radius. Nodes having greater Eccentricity Centrality are situated towards the centre."));
	connect(circleEccentrLayoutAct , SIGNAL(activated()), this, SLOT(slotLayoutRadialCentralityEccentr() ) );

        circlePowerLayoutAct = new QAction( tr("Power"),	this);
        circlePowerLayoutAct ->setShortcut(tr("Ctrl+Alt+8"));
        circlePowerLayoutAct  ->setStatusTip(tr("Repositions the nodes on circles of different radius. More power central nodes are positioned towards the centre."));
        circlePowerLayoutAct ->setWhatsThis(tr("Circle Power Centrality Layout\n\n Repositions the nodes on circles of different radius.  More power central nodes are positioned towards the centre."));
        connect(circlePowerLayoutAct , SIGNAL(activated()), this, SLOT(slotLayoutRadialCentralityPower() ) );


        circleInformationLayoutAct = new QAction( tr("Information"),	this);
        circleInformationLayoutAct ->setEnabled(true);
        circleInformationLayoutAct ->setShortcut(tr("Ctrl+Alt+9"));
        circleInformationLayoutAct ->setStatusTip(tr("Repositions the nodes on circles of different radius. More Information Central Nodes are situated towards the centre."));
        circleInformationLayoutAct->setWhatsThis(tr("Circle Information Centrality Layout\n\n Repositions the nodes on circles of different radius. More Information Central Nodes are positioned towards the centre."));
        connect(circleInformationLayoutAct, SIGNAL(activated()), this, SLOT(slotLayoutRadialCentralityInformation()));


	circleClearBackgrCirclesAct = new QAction(QIcon(":/images/gridlines.png"), tr("Remove Layout GuideLines"), this);
	circleClearBackgrCirclesAct ->setStatusTip(tr("Removes all layout guideLines from the canvas."));
	circleClearBackgrCirclesAct->setWhatsThis(tr("Remove GuideLines\n\n Removes any guidelines (circles or horizontal lines) created for the network layout."));

	
	levelInDegreeLayoutAct = new QAction( tr("In-Degree"),this);
	levelInDegreeLayoutAct ->setShortcut(tr("Ctrl+Shift+1"));
	levelInDegreeLayoutAct ->setStatusTip(tr("Repositions the nodes on layers or levels of different height. More In-Degree Central Nodes are situated on higher layers."));
	levelInDegreeLayoutAct->setWhatsThis(tr("Level In-Degree Centrality Layout\n\n Repositions the nodes on layers of different height. More In-Degree Central Nodes are situated on higher layers."));
	connect(levelInDegreeLayoutAct, SIGNAL(activated()), this, SLOT(slotLayoutLayeredCentralityInDegree()));

	levelOutDegreeLayoutAct  = new QAction( tr("Out-Degree"),this);
	levelOutDegreeLayoutAct  ->setShortcut(tr("Ctrl+Shift+2"));
	levelOutDegreeLayoutAct  ->setStatusTip(tr("Repositions the nodes on levels of different height. More Out-Degree Central Nodes are situated on higher levels."));
	levelOutDegreeLayoutAct ->setWhatsThis(tr("Level Out-Degree Centrality Layout\n\n Repositions the nodes on levels of different height. More Out-Degree Central Nodes are situated on higher levels."));
	connect(levelOutDegreeLayoutAct , SIGNAL(activated()), this, SLOT(slotLayoutLayeredCentralityOutDegree()));

	levelClosenessLayoutAct = new QAction( tr("Closeness"),	this);
	levelClosenessLayoutAct ->setShortcut(tr("Ctrl+Shift+3"));
	levelClosenessLayoutAct ->setStatusTip(tr("Repositions the nodes on levels of different height. More Closeness Central Nodes are situated on higher levels."));
	levelClosenessLayoutAct->setWhatsThis(tr("level Closeness Centrality Layout\n\n Repositions the nodes on levels of different height. More Closeness Central Nodes are situated on higher levels."));
	connect(levelClosenessLayoutAct, SIGNAL(activated()), this, SLOT(slotLayoutLayeredCentralityCloseness()));

	levelBetweenessLayoutAct = new QAction( tr("Betweeness"),	this);
	levelBetweenessLayoutAct ->setShortcut(tr("Ctrl+Shift+4"));
	levelBetweenessLayoutAct ->setStatusTip(tr("Repositions the nodes on levels of different height. More Betweeness Central Nodes are situated on higher levels."));
	levelBetweenessLayoutAct->setWhatsThis(tr("level Betweeness Centrality Layout\n\n Repositions the nodes on levels of different height. More Betweeness Central Nodes are situated on higher levels."));
	connect(levelBetweenessLayoutAct, SIGNAL(activated()), this, SLOT(slotLayoutLayeredCentralityBetweeness()));

        levelInformationLayoutAct = new QAction( tr("Informational"),	this);
        levelInformationLayoutAct ->setShortcut(tr("Ctrl+Shift+9"));
        levelInformationLayoutAct -> setEnabled(false);
        levelInformationLayoutAct ->setStatusTip(tr("Repositions the nodes on levels of different height. More Informational Central Nodes are situated on higher levels."));
        levelInformationLayoutAct->setWhatsThis(tr("Level Informational Centrality Layout\n\n Repositions the nodes on levels of different height. More Informational Central Nodes are situated on higher levels."));
        connect(levelInformationLayoutAct, SIGNAL(activated()), this, SLOT(slotLayoutLayeredCentralityInformation()));

	springLayoutAct= new QAction(tr("Spring Embedder"), this);
	springLayoutAct->setShortcut(tr("Alt+1"));
	springLayoutAct->setStatusTip(tr("All nodes repel each other while the connected ones are attracted as if connected by springs."));
	springLayoutAct->setWhatsThis(tr("Spring Embedder Layout\n\n In this model, nodes are regarded as physical bodies (i.e. electrons) which exert repelling forces to each other, while edges are springs connecting adjacents nodes. Non-adjacent nodes repel each other while connected nodes are The algorithm continues until the system retains an equilibrium state in which all forces cancel each other. "));
	connect(springLayoutAct, SIGNAL(activated()), this, SLOT(slotLayoutSpringEmbedder()));

	FRLayoutAct= new QAction( tr("Fruchterman-Reingold"),	this);
	FRLayoutAct->setShortcut(tr("Alt+2"));
	FRLayoutAct->setEnabled(true);
	FRLayoutAct->setStatusTip(tr("Repelling forces between all nodes, and attracting forces between adjacent nodes."));
	FRLayoutAct->setWhatsThis(tr("Fruchterman-Reingold Layout\n\n Embeds a layout all nodes according to a model in which	repelling forces are used between every pair of nodes, while attracting forces are used only between adjacent nodes. The algorithm continues until the system retains its equilibrium state where all forces cancel each other."));
	connect(FRLayoutAct, SIGNAL(activated()), this, SLOT(slotLayoutFruchterman()));


	zoomInAct = new QAction(QIcon(":/images/zoomin.png"), tr("Zoom &in"),  this);
	zoomInAct->setShortcut(tr("Ctrl++"));
	zoomInAct->setToolTip(tr("Zoom in (Ctrl++)"));
	zoomInAct->setStatusTip(tr("Zooms inside the actual network."));
	zoomInAct->setWhatsThis(tr("Zoom In.\n\nZooms in. What else did you expect?"));


	zoomOutAct = new QAction(QIcon(":/images/zoomout.png"), tr("Zoom &out"),  this);
	zoomOutAct->setShortcut(tr("Ctrl+-"));
	zoomOutAct->setToolTip(tr("Zoom out (Ctrl+-)"));
	zoomOutAct->setStatusTip(tr("Zooms out of the actual network."));
	zoomOutAct->setWhatsThis(tr("Zoom out.\n\nZooms out. What else did you expect?"));

	nodeSizeProportionalOutDegreeAct= new QAction(QIcon(":/images/nodeout.png"),tr("NodeSize = F (OutDegree)"), this);
	nodeSizeProportionalOutDegreeAct->setShortcut(tr("Alt+3"));
	nodeSizeProportionalOutDegreeAct->setStatusTip(tr("Resizes all nodes according to their out edges."));
	nodeSizeProportionalOutDegreeAct->setWhatsThis(tr("NodeSize = F (OutDegree) \n\n Adjusts the size of each node according to their out-edges (OutDegree). The more out-likned a node is, the bigger will appear..."));
	nodeSizeProportionalOutDegreeAct->setCheckable(true);
	nodeSizeProportionalOutDegreeAct->setChecked(false);
	connect(nodeSizeProportionalOutDegreeAct, SIGNAL(triggered(bool)), this, SLOT(slotLayoutNodeSizeProportionalOutEdges(bool)));


	nodeSizeProportionalInDegreeAct= new QAction(QIcon(":/images/nodein.png"),tr("NodeSize = F (InDegree)"), this);
	nodeSizeProportionalInDegreeAct->setShortcut(tr("Alt+4"));
	nodeSizeProportionalInDegreeAct->setStatusTip(tr("Resizes all nodes according to their in edges."));
	nodeSizeProportionalInDegreeAct->setWhatsThis(tr("NodeSize = F (InDegree) \n\n This method adjusts the size of each node according to their in-edges (InDegree). The more in-linked a node is, the bigger will appear..."));
	nodeSizeProportionalInDegreeAct->setCheckable(true);
	nodeSizeProportionalInDegreeAct->setChecked(false);
	connect(nodeSizeProportionalInDegreeAct, SIGNAL(triggered(bool)), this, SLOT(slotLayoutNodeSizeProportionalInEdges(bool)));



	/**
	Statistics menu actions
	*/

	symmetryAct = new QAction(QIcon(":/images/symmetry.png"), tr("Network Symmetry"), this);
	symmetryAct ->setShortcut(tr("Shift+S"));
	symmetryAct->setStatusTip(tr("Tests if the network is symmetric or not"));
	symmetryAct->setWhatsThis(tr("Network Symmetry\n\n A network is symmetric when all edges are reciprocal, or, in mathematical language, when the adjacency matrix is symmetric."));
	connect(symmetryAct, SIGNAL(activated()), this, SLOT(slotCheckSymmetry()));

	invertAdjMatrixAct = new QAction(QIcon(":/images/symmetry.png"), tr("Invert Adjacency Matrix"), this);
	invertAdjMatrixAct ->setShortcut(tr("Shift+I"));
	invertAdjMatrixAct->setStatusTip(tr("Inverts the adjacency matrix"));
	invertAdjMatrixAct->setWhatsThis(tr("Invert  Adjacency Matrix \n\n Inverts the adjacency matrix using linear algebra methods."));
	connect(invertAdjMatrixAct, SIGNAL(activated()), this, SLOT(slotInvertAdjMatrix()));


	graphDistanceAct = new QAction(QIcon(":/images/distance.png"),  tr("Graph Distance"), this);
	graphDistanceAct ->setShortcut(tr("Ctrl+G"));
	graphDistanceAct->setStatusTip(tr("Calculates the length of the shortest path between two nodes..."));
	graphDistanceAct->setWhatsThis(tr("Graph Distance\n\n The graph distance (or geodesic distance) of two nodes is the length (number of edges) of the shortest path between them."));
	connect(graphDistanceAct, SIGNAL(activated()), this, SLOT(slotGraphDistance()));

	distanceMatrixAct = new QAction(QIcon(":/images/dm.png"), tr("Distance &Matrix"),this);
	distanceMatrixAct ->setShortcut(tr("Ctrl+M"));
	distanceMatrixAct->setStatusTip(tr("Displays the matrix of graph distances between all nodes"));
	distanceMatrixAct->setWhatsThis(tr("Distance Matrix\n\n A distance matrix is a NxN matrix, where the (i,j) element is the graph distance from node i to node j."));
	connect(distanceMatrixAct, SIGNAL(activated()), this, SLOT( slotViewDistanceMatrix() ) );
	
	diameterAct = new QAction(QIcon(":/images/diameter.png"), tr("Diameter"),this);
	diameterAct ->setShortcut(tr("Ctrl+D"));
	diameterAct->setStatusTip(tr("Calculates and displays the diameter of the network."));
	diameterAct->setWhatsThis(tr("Diameter\n\n The Diameter of a network is the maximum graph distance (maximum shortest path length) between any two nodes of the network."));
	connect(diameterAct, SIGNAL(activated()), this, SLOT(slotDiameter()));

	averGraphDistanceAct = new QAction(QIcon(":/images/avdistance.png"), tr("Average Graph Distance"),this);
	averGraphDistanceAct ->setShortcut(tr("Ctrl+B"));
	averGraphDistanceAct->setStatusTip(tr("Calculates and displays the average shortest path length."));
	averGraphDistanceAct->setWhatsThis(tr("Average Graph Distance\n\n This the average length of all shortest paths between the connected pair of nodes of the network."));
	connect(averGraphDistanceAct, SIGNAL(activated()), this, SLOT(slotAverageGraphDistance()));


	cliquesAct = new QAction(QIcon(":/images/triangle.png"), tr("Number of Cliques"),this);
	cliquesAct->setShortcut(tr("Ctrl+T"));
	cliquesAct->setStatusTip(tr("Calculates and displays the number of cliques (triangles) of each node v."));
	cliquesAct->setWhatsThis(tr("Triangles\n\n A triangle is a complete subgraph of three nodes of G. This method calculates the number of triangles of each node v is defined as delta(v) = |{{u, w} in E : {v, u} in E and {v, w} in E}|.  \n "));
	connect(cliquesAct, SIGNAL(activated()), this, SLOT(slotNumberOfCliques() )  );


	clusteringCoefAct = new QAction(QIcon(":/images/clique.png"), tr("Clustering Coefficient"),this);
	clusteringCoefAct ->setShortcut(tr("Ctrl+C"));
	clusteringCoefAct->setStatusTip(tr("Calculates and displays the average Clustering Coefficient of the network."));
	clusteringCoefAct->setWhatsThis(tr("Clustering Coefficient\n\n The Clustering Coefficient of a vertex quantifies how close the vertex and its neighbors are to being a clique. \n "));
	connect(clusteringCoefAct, SIGNAL(activated()), this, SLOT(slotClusteringCoefficient() )  );


	triadCensusAct = new QAction(QIcon(":/images/clique.png"), tr("Triad Census"),this);
	triadCensusAct->setShortcut(tr("Ctrl+Shift+T"));
	triadCensusAct->setStatusTip(tr("Conducts a triad census for the active network."));
	triadCensusAct->setWhatsThis(tr("Triad Census\n\n A triad census counts all the different kinds of observed triads within a network and codes them according to their number of mutual, asymmetric and non-existent dyads. \n "));
	connect(triadCensusAct, SIGNAL(activated()), this, SLOT(slotTriadCensus() )  );

	cInDegreeAct = new QAction(tr("InDegree"),	 this);
	cInDegreeAct->setStatusTip(tr("Calculates and displays InDegree Centralities"));
	cInDegreeAct->setShortcut(tr("Ctrl+1"));
	cInDegreeAct->setWhatsThis(tr("InDegree Centrality\n\n For each node k, this the number of arcs ending at k. Most in-degree central node might be considered more prominent among others. "));
	connect(cInDegreeAct, SIGNAL(activated()), this, SLOT(slotCentralityInDegree()));


	cOutDegreeAct = new QAction(tr("OutDegree"),this);
	cOutDegreeAct->setShortcut(tr("Ctrl+2"));
	cOutDegreeAct->setStatusTip(tr("Calculates and displays OutDegree Centralities"));
	cOutDegreeAct->setWhatsThis(tr("OutDegree Centrality\n\n For each node k, this is the number of arcs starting from it. This is oftenly a measure of activity."));
	connect(cOutDegreeAct, SIGNAL(activated()), this, SLOT(slotCentralityOutDegree()));


	cClosenessAct = new QAction(tr("Closeness"), this);
	cClosenessAct->setShortcut(tr("Ctrl+3"));
	cClosenessAct->setStatusTip(tr("Calculates and displays Closeness Centralities"));
	cClosenessAct->setWhatsThis(tr("Closeness Centrality\n\n For each node k, this the invert sum of the shortest distances between k and every other node. It is interpreted as the ability to access information through the \"grapevine\" of network members. Nodes with high closeness are those who can reach many other nodes in few steps.  "));
	connect(cClosenessAct, SIGNAL(activated()), this, SLOT(slotCentralityCloseness()));

	cBetweenessAct = new QAction(tr("Betweeness"), this);
	cBetweenessAct->setShortcut(tr("Ctrl+4"));
	cBetweenessAct->setStatusTip(tr("Calculates and displays Betweeness Centralities"));
	cBetweenessAct->setWhatsThis(tr("Betweeness Centrality\n\n For each node k, this is the ratio of all geodesics between pairs of nodes which run through k. It reflects how often an node lies on the geodesics between the other nodes of the network. It can be interpreted as a measure of control. A node which is lies between many others is assumed to have a higher likelihood of being able to control information flow in the network. \n\n Note that betweeness centrality assumes that all geodesics have equal weight or are equally likely to be chosen for the flow of information between any two nodes. This is reasonable only on \"regular\" networks where all nodes have similar degrees. On networks with significant degree variance you might want to try informational centrality instead."));
	connect(cBetweenessAct, SIGNAL(activated()), this, SLOT(slotCentralityBetweeness()));

	cGraphAct = new QAction(tr("Graph"),this);
	cGraphAct->setShortcut(tr("Ctrl+5"));
	cGraphAct->setStatusTip(tr("Calculates and displays Graph Centralities"));
	cGraphAct->setWhatsThis(tr("Graph Centrality\n\n For each node k, this is the invert of the maximum of all geodesic distances from k to all other nodes in the network. Nodes with high GC have short distances to all other nodes in the graph. "));
	connect(cGraphAct, SIGNAL(activated()), this, SLOT(slotCentralityGraph()));

	cStressAct = new QAction(tr("Stress"), this);
	cStressAct->setShortcut(tr("Ctrl+6"));
	cStressAct->setStatusTip(tr("Calculate and display Stress Centrality"));
	cStressAct->setWhatsThis(tr("Stress Centrality\n\n For each node k, this is the total number of geodesics between all other nodes which run through k. When one node falls on all other geodesics between all the remaining (N-1) nodes, then we have a star graph with maximum Stress Centrality"));
	connect(cStressAct, SIGNAL(activated()), this, SLOT(slotCentralityStress()));


	cEccentAct = new QAction(tr("Eccentricity"), this);
	cEccentAct->setShortcut(tr("Ctrl+7"));
	cEccentAct->setStatusTip(tr("Calculate and display Eccentricity Centrality"));
	cEccentAct->setWhatsThis(tr("Stress Centrality\n\n For each node k, this is the largest geodesic distance (k,t) from every other vertex t. Therefore, EC(u) reflects how far, at most, is each node from every other node."));
	connect(cEccentAct, SIGNAL(activated()), this, SLOT(slotCentralityEccentricity()));


	cPowerAct = new QAction(tr("Power"), this);
	cPowerAct->setShortcut(tr("Ctrl+8"));
	cPowerAct->setStatusTip(tr("Calculate and display Power Centrality (aka Gil-Schmidt Power Centrality index)"));
	cPowerAct->setWhatsThis(tr("Power Centrality\n\n For each node k, this index sums its degree (with weight 1), with the size of the 2nd-order neighbourhood (with weight 2), and in general, with the size of the kth order neighbourhood (with weight k). Thus, for each node in the network the most important other nodes are its immediate neighbours and then in decreasing importance the nodes of the 2nd-order neighbourhood, 3rd-order neighbourhood etc. For each node, the sum obtained is normalised by the total numbers of nodes in the same component minus 1. Power centrality has been devised by Gil-Schmidt. "));
	connect(cPowerAct, SIGNAL(activated()), this, SLOT(slotCentralityPower()));


	cInformationAct = new QAction(tr("Information"),	this);
	cInformationAct->setShortcut(tr("Ctrl+9"));
	cInformationAct->setEnabled(true);
	cInformationAct->setStatusTip(tr("Calculate and display Information Centrality"));
	cInformationAct->setWhatsThis(tr("Information Centrality\n\n Information centrality counts all paths between nodes weighted by strength of tie and distance. This centrality  measure developed by Stephenson and Zelen (1989) focuses on how information might flow through many different paths. \n\n Note: To compute this index, SocNetV drops all isolated nodes."));
	connect(cInformationAct, SIGNAL(activated()), this, SLOT(slotCentralityInformation()));

	
	/**
	Options menu actions
	*/
	displayNodeNumbersAct = new QAction( tr("Display Num&bers"), this );
	displayNodeNumbersAct->setStatusTip(tr("Toggles displaying of node numbers"));
	displayNodeNumbersAct->setWhatsThis(tr("Display Numbers\n\nEnables/disables node numbers"));
	displayNodeNumbersAct->setCheckable (true);
	displayNodeNumbersAct->setChecked(true);
	connect(displayNodeNumbersAct, SIGNAL(toggled(bool)), this, SLOT(slotDisplayNodeNumbers(bool)));
		
	displayNodeLabelsAct= new QAction(tr("Display Labels"),	this );
	displayNodeLabelsAct->setStatusTip(tr("Toggles displaying of node labels"));
	displayNodeLabelsAct->setWhatsThis(tr("Display Labels\n\nEnables/disables node labels"));
 	displayNodeLabelsAct->setCheckable (true);
	displayNodeLabelsAct->setChecked(false);
	connect(displayNodeLabelsAct, SIGNAL(toggled(bool)), this, SLOT(slotDisplayNodeLabels(bool)));


	displayNumbersInsideNodesAct= new QAction(tr("Display Numbers Inside Nodes"),	this );
	displayNumbersInsideNodesAct->setStatusTip(tr("Toggles displaying numbers inside nodes"));
	displayNumbersInsideNodesAct->setWhatsThis(tr("Display Numbers Inside Nodes\n\nTurns on/off displaying nodenumbers inside nodes"));
 	displayNumbersInsideNodesAct->setCheckable (true);
	displayNumbersInsideNodesAct->setChecked(false);
	connect(displayNumbersInsideNodesAct, SIGNAL(toggled(bool)), this, SLOT(slotDisplayNumbersInsideNodes(bool)));


	displayLinksAct = new QAction(tr("Display Links"),	this);
	displayLinksAct->setStatusTip(tr("Toggle to display or not links"));
	displayLinksAct->setWhatsThis(tr("Display Links\n\nClick to enable or disable displaying of links"));
	displayLinksAct->setCheckable(true);
	displayLinksAct->setChecked(true);
	connect(displayLinksAct, SIGNAL(toggled(bool)), this, SLOT(slotDisplayLinks(bool)) );

	displayLinksWeightNumbersAct = new QAction(tr("Display Weight Numbers"),	this);
	displayLinksWeightNumbersAct->setStatusTip(tr("Toggles displaying of numbers of links weights"));
	displayLinksWeightNumbersAct->setWhatsThis(tr("Display Weight Numbers\n\nClick to enable or disable displaying numbers of links weight"));
	displayLinksWeightNumbersAct->setCheckable(true);
	displayLinksWeightNumbersAct->setChecked(false);
	connect(displayLinksWeightNumbersAct, SIGNAL(toggled(bool)), this, SLOT(slotDisplayLinksWeightNumbers(bool)) );

	displayLinksArrowsAct = new QAction( tr("Display Arrows"),this);
	displayLinksArrowsAct->setStatusTip(tr("Toggles displaying of arrows in the end of links"));
	displayLinksArrowsAct->setWhatsThis(tr("Display Arrows\n\nClick to enable or disable displaying of arrows in the end of links"));
	displayLinksArrowsAct->setCheckable(true);
	displayLinksArrowsAct->setChecked(true);
	connect(displayLinksArrowsAct, SIGNAL(toggled(bool)), this, SLOT(slotDisplayLinksArrows(bool)) );

	drawLinksWeightsAct = new QAction( tr("Thickness=Weight"), this);
	drawLinksWeightsAct->setStatusTip(tr("Draws links as thick as their weights (if specified)"));
	drawLinksWeightsAct->setWhatsThis(tr("Draw As Thick As Weights\n\nClick to toggle having all links as thick as their weight (if specified)"));
	drawLinksWeightsAct->setCheckable(true);
	drawLinksWeightsAct->setChecked(false);
	drawLinksWeightsAct->setEnabled(false);
	connect(drawLinksWeightsAct, SIGNAL(toggled(bool)), this, SLOT(slotDrawLinksThickAsWeights()) );

	drawLinksBezier = new QAction( tr("Bezier Curves"),	this);
	drawLinksBezier->setStatusTip(tr("Draws links as Bezier curves"));
	drawLinksBezier->setWhatsThis(tr("Links Bezier\n\nEnables/Disables drawing Links as Bezier curves."));
	drawLinksBezier->setCheckable(true);
	drawLinksBezier->setChecked (false);
	drawLinksBezier->setEnabled(false);
	connect(drawLinksBezier, SIGNAL(toggled(bool)), this, SLOT(slotDrawLinksBezier(bool)) );

	
	/**
	Options > View menu actions
	*/

	antialiasingAct = new QAction(tr("Anti-Aliasing"), this);
	antialiasingAct ->setShortcut(tr("F8"));
	antialiasingAct ->setStatusTip(tr("Enables/disables anti-aliasing"));
	antialiasingAct ->setWhatsThis(tr("Enable or disable Anti-Aliasing\n\n Anti-aliasing is a technique which makes nodes, lines and text, smoother and fancier. But it comes at the cost of speed..."));
	antialiasingAct ->setCheckable(true);
	antialiasingAct ->setChecked (true);
	connect(antialiasingAct , SIGNAL(toggled(bool)), this, SLOT(slotAntialiasing(bool)));


	showProgressBarAct = new QAction(tr("Progress Bars"), this);
	showProgressBarAct ->setShortcut(tr("F10"));
	showProgressBarAct->setStatusTip(tr("Enables/disables Progress Bars"));
	showProgressBarAct->setWhatsThis(tr("Enable or disable Progress Bars\n\nProgress Bars may appear during time-cost operations. Enabling progressBar has a significant cpu cost but lets you know about the progress of a given operation."));
	showProgressBarAct->setCheckable(true);
	showProgressBarAct->setChecked (true);
	connect(showProgressBarAct, SIGNAL(toggled(bool)), this, SLOT(slotShowProgressBar(bool)));

	printDebugAct = new QAction(tr("Debug Messages"),	this);
	printDebugAct ->setShortcut(tr("F9"));
	printDebugAct->setStatusTip(tr("Enables/disables printing debug messages to stdout"));
	printDebugAct->setWhatsThis(tr("Enables or disable Debug Messages\n\nPrinting debug messages to strerr. Enabling has a significant cpu cost but lets you know what SocNetV is actually doing."));
	printDebugAct->setCheckable(true);
	printDebugAct->setChecked (false);
	printDebug=false;
	connect(printDebugAct, SIGNAL(toggled(bool)), this, SLOT(slotPrintDebug(bool)));



	viewToolBar = new QAction(tr("Toolbar"), this);
	viewToolBar->setStatusTip(tr("Enables/disables the toolbar"));
	viewToolBar->setWhatsThis(tr("Enable or disable Toolbar\n\nThe toolbar is the widget right below the menu, and carries useful icons. You can disable it if you like..."));
	viewToolBar->setCheckable(true);
	viewToolBar->setChecked(true);
	connect(viewToolBar, SIGNAL(toggled(bool)), this, SLOT(slotViewToolBar(bool)));

	viewStatusBar = new QAction(tr("Statusbar"),	this);
	viewStatusBar->setStatusTip(tr("Enables/disables the statusbar"));
	viewStatusBar->setWhatsThis(tr("Enable or disable Statusbar\n\nThe statusbar is the widget at the bottom of the window, where messages appear. You might want to disable it..."));
	viewStatusBar->setCheckable(true);
	viewStatusBar->setChecked(true);
	connect(viewStatusBar, SIGNAL(toggled(bool)), this, SLOT(slotViewStatusBar(bool)));
	
	backgroundImageAct = new QAction(tr("Background Image"),	this);
	backgroundImageAct->setStatusTip(tr("Enables/disables displaying a user-defined custom image in the background"));
	backgroundImageAct->setWhatsThis(tr("Enable or disable background image\n\n If you enable it, you will be asked for a image file, which will be displayed in the background instead of plain color.."));
	backgroundImageAct->setCheckable(true);
	backgroundImageAct->setChecked(false);
	connect(backgroundImageAct, SIGNAL(toggled(bool)), this, SLOT(slotBackgroundImage(bool)));
	


	/**
	Help menu actions
	*/
	helpApp = new QAction(QIcon(":/images/help.png"), tr("Manual"),	this);
	helpApp ->setShortcut(tr("F1"));
	helpApp->setStatusTip(tr("Read the manual..."));
	helpApp->setWhatsThis(tr("Manual\n\nDisplays the documentation of SocNetV"));
	connect(helpApp, SIGNAL(activated()), this, SLOT(slotHelp()));

	tipsApp = new QAction(tr("Tip of the Day"), this);
	tipsApp->setStatusTip(tr("Read useful tips"));
	tipsApp->setWhatsThis(tr("Quick Tips\n\nDisplays some useful and quick tips"));
	connect(tipsApp, SIGNAL(activated()), this, SLOT(slotTips()));

	helpAboutApp = new QAction(tr("About SocNetV"), this);
	helpAboutApp->setStatusTip(tr("About SocNetV"));
	helpAboutApp->setWhatsThis(tr("About\n\nBasic information about SocNetV"));
	connect(helpAboutApp, SIGNAL(activated()), this, SLOT(slotHelpAbout()));



	helpAboutQt = new QAction(tr("About Qt"), this);
	helpAboutQt->setStatusTip(tr("About Qt"));
	helpAboutQt->setWhatsThis(tr("About\n\nAbout Qt"));
	connect(helpAboutQt, SIGNAL(activated()), this, SLOT(slotAboutQt() ) );
}



/**
  Creates and populates the MenuBar
*/
void MainWindow::initMenuBar() {


/** menuBar entry networkMenu */
	networkMenu = menuBar()->addMenu(tr("&Network"));
	networkMenu -> addAction(fileNew);
	networkMenu -> addAction(fileOpen);
	importSubMenu = new QMenu(tr("Import ..."));
	importSubMenu -> addAction(importPajek);
	importSubMenu -> addAction(importSM);
	importSubMenu -> addAction(importTwoModeSM);
	importSubMenu -> addAction(importList);
	importSubMenu -> addAction(importDL);
	networkMenu ->addMenu (importSubMenu);

	networkMenu -> addSeparator();
	networkMenu -> addAction (openTextEditorAct);
	networkMenu -> addAction (viewNetworkFileAct);
	networkMenu -> addSeparator();
	networkMenu -> addAction (viewSociomatrixAct);
	networkMenu -> addSeparator();
	
	networkMenu -> addAction (recreateDataSetAct);
	networkMenu -> addSeparator();
	
	randomNetworkMenu = new QMenu(tr("Create Random Network..."));
	networkMenu ->addMenu (randomNetworkMenu);
	randomNetworkMenu -> addAction (createSmallWorldRandomNetworkAct);
	randomNetworkMenu -> addAction (createUniformRandomNetworkAct );
// createGaussianRandomNetworkAct -> addTo(randomNetworkMenu);
	randomNetworkMenu -> addAction (createLatticeNetworkAct);
	randomNetworkMenu -> addAction (createSameDegreeRandomNetworkAct);
	networkMenu->addSeparator();

	networkMenu  -> addAction(webCrawlerAct);
	
	networkMenu  -> addSeparator();
	networkMenu  -> addAction(fileSave);
	networkMenu  -> addAction(fileSaveAs);
	networkMenu  -> addSeparator();
	
	exportSubMenu = networkMenu  -> addMenu(tr("Export..."));

	
	exportSubMenu -> addAction (exportBMP);
	exportSubMenu -> addAction (exportPNG);
	exportSubMenu -> addAction (exportPDF);
	exportSubMenu -> addSeparator();
	exportSubMenu -> addAction (exportSM);
	exportSubMenu -> addAction (exportPajek);
	//   exportList->addTo(exportSubMenu);
	//   exportDL->addTo(exportSubMenu);
	//   exportGW->addTo(exportSubMenu);

	networkMenu  -> addSeparator();
	networkMenu  -> addAction(printNetwork);
	networkMenu  -> addSeparator();
	networkMenu  -> addAction(fileClose);
	networkMenu  -> addAction(fileQuit);



  
 /** menuBar entry editMenu */
	
	editMenu = menuBar()->addMenu(tr("&Edit"));
	editNodeMenu = new QMenu(tr("Node..."));
	editNodeMenu -> setIcon(QIcon(":/images/node.png"));
	editMenu -> addMenu ( editNodeMenu );
	editNodeMenu -> addAction (findNodeAct);
	editNodeMenu -> addAction (addNodeAct);
	editNodeMenu -> addAction (removeNodeAct);

	editNodeMenu -> addSeparator();
	editNodeMenu -> addAction (changeNodeLabelAct);
	editNodeMenu -> addAction (changeNodeColorAct);
	editNodeMenu -> addAction (changeNodeSizeAct);
	editNodeMenu -> addAction (changeNodeValueAct);

	editNodeMenu -> addSeparator();
	editNodeMenu -> addAction (changeAllNodesSizeAct);
	editNodeMenu -> addAction (changeAllNodesShapeAct);
	editNodeMenu -> addAction (changeNumbersSizeAct);
	editNodeMenu -> addAction (changeLabelsSizeAct);
	
	editLinkMenu = new QMenu(tr("Link..."));
	editLinkMenu -> setIcon(QIcon(":/images/line.png"));
	editMenu-> addMenu (editLinkMenu);
	editLinkMenu -> addAction(addLinkAct);
	editLinkMenu -> addAction(removeLinkAct);
	editLinkMenu -> addAction(changeLinkLabelAct);
	editLinkMenu -> addAction(changeLinkColorAct);
	editLinkMenu -> addAction(changeLinkWeightAct);
	
	editMenu ->addSeparator();
	filterMenu = new QMenu ( tr("Filter..."));
	editMenu ->addMenu(filterMenu);
	
	filterMenu -> addAction(filterNodesAct );
	filterMenu -> addAction(filterOrphanNodesAct );
	filterMenu -> addAction(filterEdgesAct );
	
	editMenu ->addSeparator();
//   transformNodes2LinksAct -> addTo (editMenu);
	editMenu -> addAction (symmetrizeAct);

	editNodeMenu -> addSeparator();
	colorOptionsMenu=new QMenu(tr("Colors"));
	colorOptionsMenu -> setIcon(QIcon(":/images/colorize.png"));
	editMenu -> addMenu (colorOptionsMenu);
	colorOptionsMenu -> addAction (changeBackColorAct);
	colorOptionsMenu -> addAction (changeAllNodesColorAct);
	colorOptionsMenu -> addAction (changeAllLinksColorAct);
	colorOptionsMenu -> addAction (changeAllNumbersColorAct);
	colorOptionsMenu -> addAction (changeAllLabelsColorAct);


/** menuBar entry layoutMenu  */
	
	layoutMenu = menuBar()->addMenu(tr("&Layout"));
//   colorationMenu = new QPopupMenu();
//   layoutMenu -> insertItem (tr("Colorization"), colorationMenu);
//   strongColorationAct -> addTo(colorationMenu);
//   regularColorationAct-> addTo(colorationMenu);
//   layoutMenu->insertSeparator();
	randomLayoutMenu = new QMenu(tr("Random..."));
	layoutMenu -> addMenu (randomLayoutMenu );
	randomLayoutMenu ->  addAction(randLayoutAct);
	randomLayoutMenu ->  addAction( randCircleLayoutAct );
	 
	circleLayoutMenu = new QMenu(tr("Radial by centrality..."));
	circleLayoutMenu -> setIcon(QIcon(":/images/circular.png"));
	layoutMenu -> addMenu (circleLayoutMenu);
	circleLayoutMenu -> addAction (circleInDegreeLayoutAct);
	circleLayoutMenu -> addAction (circleOutDegreeLayoutAct);
	circleLayoutMenu -> addAction (circleClosenessLayoutAct);
	circleLayoutMenu -> addAction (circleBetweenessLayoutAct);
	circleLayoutMenu -> addAction (circleStressLayoutAct);
	circleLayoutMenu -> addAction (circleGraphLayoutAct);
        circleLayoutMenu -> addAction (circleEccentrLayoutAct);
        circleLayoutMenu -> addAction (circlePowerLayoutAct);
        circleLayoutMenu -> addAction (circleInformationLayoutAct);

	levelLayoutMenu = new QMenu (tr("Layered by centrality..."));
	levelLayoutMenu -> setIcon(QIcon(":/images/net3.png"));
	layoutMenu -> addMenu (levelLayoutMenu);
	levelLayoutMenu ->addAction ( levelInDegreeLayoutAct     );
	levelLayoutMenu ->addAction ( levelOutDegreeLayoutAct    );
	levelLayoutMenu ->addAction ( levelClosenessLayoutAct    );
	levelLayoutMenu ->addAction ( levelBetweenessLayoutAct   );
        levelLayoutMenu ->addAction ( levelInformationLayoutAct  );

	layoutMenu->addSeparator();
	physicalLayoutMenu = new QMenu (tr("Physical..."));
	layoutMenu -> addMenu (physicalLayoutMenu);
	physicalLayoutMenu -> addAction (springLayoutAct);
	physicalLayoutMenu -> addAction (FRLayoutAct);
	layoutMenu->addSeparator();
	layoutMenu->addAction(nodeSizeProportionalOutDegreeAct);
	layoutMenu->addAction(nodeSizeProportionalInDegreeAct);
	layoutMenu->addSeparator();
	layoutMenu -> addAction (circleClearBackgrCirclesAct);
	


/** menuBar entry: statistics menu */
	statMenu = menuBar()->addMenu(tr("&Statistics"));
	statMenu -> addAction (symmetryAct);
	statMenu -> addAction (invertAdjMatrixAct);
//	statMenu -> addAction (netDensity);

	statMenu -> addSeparator();
	statMenu -> addAction (graphDistanceAct);
	statMenu -> addAction (averGraphDistanceAct);
	
	statMenu -> addAction (distanceMatrixAct);
	statMenu -> addAction (diameterAct);
	statMenu -> addSeparator();
	statMenu -> addAction (cliquesAct);
	statMenu -> addAction (clusteringCoefAct);
	
	statMenu -> addSeparator();
	statMenu -> addAction (triadCensusAct);
	
	statMenu->addSeparator();
	centrlMenu = new QMenu(tr("Centralities..."));
	statMenu->addMenu(centrlMenu); 
	centrlMenu -> addAction (cInDegreeAct);
	centrlMenu -> addAction (cOutDegreeAct);
	centrlMenu -> addAction (cClosenessAct);
	centrlMenu -> addAction (cBetweenessAct);
	centrlMenu -> addAction (cGraphAct);
	centrlMenu -> addAction (cStressAct);
	centrlMenu -> addAction (cEccentAct);
	centrlMenu -> addAction (cPowerAct);
	centrlMenu -> addAction (cInformationAct);


/** menuBar entry optionsMenu  */
	optionsMenu = menuBar()->addMenu(tr("&Options"));
	nodeOptionsMenu=new QMenu(tr("Nodes..."));
	nodeOptionsMenu -> setIcon(QIcon(":/images/nodes.png")); 

	optionsMenu -> addMenu (nodeOptionsMenu);
	nodeOptionsMenu -> addAction (displayNodeNumbersAct);
	nodeOptionsMenu -> addAction (displayNodeLabelsAct);
	nodeOptionsMenu -> addAction (displayNumbersInsideNodesAct);

	linkOptionsMenu=new QMenu(tr("Links..."));
	linkOptionsMenu -> setIcon(QIcon(":/images/line.png"));

	optionsMenu -> addMenu (linkOptionsMenu);
	linkOptionsMenu -> addAction (displayLinksAct);
	linkOptionsMenu -> addAction (displayLinksWeightNumbersAct);
	linkOptionsMenu -> addAction (displayLinksArrowsAct );
	linkOptionsMenu -> addSeparator();
	linkOptionsMenu -> addAction (drawLinksWeightsAct);
	linkOptionsMenu -> addAction (drawLinksBezier);
  
	viewOptionsMenu = new QMenu (tr("&View..."));
	viewOptionsMenu -> setIcon(QIcon(":/images/view.png"));
	optionsMenu -> addMenu (viewOptionsMenu);
	viewOptionsMenu-> addAction (backgroundImageAct);
	viewOptionsMenu-> addAction (antialiasingAct);
	viewOptionsMenu-> addAction (printDebugAct);
	viewOptionsMenu-> addAction (showProgressBarAct);
	viewOptionsMenu-> addAction (viewToolBar);
	viewOptionsMenu-> addAction (viewStatusBar);
 

/**  menuBar entry helpMenu */
	helpMenu = menuBar()->addMenu(tr("&Help"));
	helpMenu -> addAction (helpApp);
	helpMenu -> addAction (tipsApp);
	helpMenu -> addSeparator();
	helpMenu-> addAction (helpAboutApp);
	helpMenu-> addAction (helpAboutQt);


}



/**
	Initializes the toolbar
*/
void MainWindow::initToolBar(){
	toolBar = addToolBar("operations");
	toolBar -> addAction (fileNew);
	toolBar -> addAction (fileOpen);
	toolBar -> addAction (fileSave);
	toolBar -> addAction (printNetwork);
	toolBar -> addSeparator();
	
	toolBar -> addAction(zoomInAct);

	//Create zooming widget
	zoomCombo = new QComboBox;
	QStringList scales;
   	scales << tr("25%") << tr("50%") << tr("75%") << tr("100%") << tr("125%") << tr("150%")<<tr("175%")  ;
   	zoomCombo->addItems(scales);
   	zoomCombo->setCurrentIndex(3);

	toolBar -> addWidget(zoomCombo);
	toolBar -> addAction(zoomOutAct);

	toolBar -> addSeparator();

	QLabel *labelRotateSpinBox= new QLabel;
	labelRotateSpinBox ->setText(tr("Rotation:"));

	
	rotateSpinBox = new QSpinBox;
	rotateSpinBox ->setRange(-360, 360);
	rotateSpinBox->setSingleStep(1);
	rotateSpinBox->setValue(0);

	QGroupBox *rotateGroup = new QGroupBox();
	QHBoxLayout *rotateGroupLayout = new QHBoxLayout(rotateGroup);
	rotateGroupLayout->addWidget(labelRotateSpinBox);
    	rotateGroupLayout->addWidget(rotateSpinBox);

	toolBar -> addWidget(rotateGroup);


	toolBar -> addSeparator();
	toolBar -> addAction ( QWhatsThis::createAction (this));


}







//Creates a dock widget for instant menu access
void MainWindow::initToolBox(){
	toolBox = new QTabWidget;
	toolBox->setSizePolicy(QSizePolicy(QSizePolicy::Maximum, QSizePolicy::Ignored));


	//create widgets for the buttons group/tab
	addNodeBt= new QPushButton(QIcon(":/images/add.png"),tr("&Add Node"));	
	addNodeBt->setFocusPolicy(Qt::NoFocus);	
	addNodeBt->setToolTip(tr("Add a new node to the network (Ctrl+A). \n\n Alternately, you can create a new node \nin a specific position by double-clicking \non that spot of the canvas."));
	removeNodeBt= new QPushButton(QIcon(":/images/remove.png"),tr("&Remove Node"));	
	removeNodeBt->setFocusPolicy(Qt::NoFocus);	
	removeNodeBt->setToolTip(tr("Remove a node from the network (Ctrl+Shift+A). \n\n Alternately, you can remove a node \nby right-clicking on it."));

	addLinkBt= new QPushButton(QIcon(":/images/connect.png"),tr("Add &Link"));	
	addLinkBt->setFocusPolicy(Qt::NoFocus);	
	addLinkBt->setToolTip(tr("Add a new link to the network (Ctrl+L).\n\n Alternately, you can create a new link between two \nnodes by middle-clicking on them consequetively."));

	removeLinkBt= new QPushButton(QIcon(":/images/disconnect.png"),tr("Remove Link"));	
	removeLinkBt->setFocusPolicy(Qt::NoFocus);	
	removeLinkBt->setToolTip(tr("Remove a link from the network  \n\n Alternately, you can remove a link \nby right-clicking on it."));

	//create a layout for these widgets
	QGridLayout *buttonsGrid = new QGridLayout;
	buttonsGrid -> addWidget(addNodeBt, 0,0);
	buttonsGrid -> addWidget(removeNodeBt, 0,1);
	buttonsGrid -> addWidget(addLinkBt,1,0);
	buttonsGrid -> addWidget(removeLinkBt,1,1);
	buttonsGrid -> setRowStretch(2,1);   //fix vertical stretch
	//create a box with a title & a frame. Inside, display the vertical layout of widgets
	QGroupBox *buttonsGroup= new QGroupBox(tr(""));
	buttonsGrid->setSpacing(0);
	buttonsGrid->setMargin(10);
	buttonsGroup->setLayout(buttonsGrid);

 	toolBox->addTab(buttonsGroup, tr("Edit"));


	//create widgets for Properties/Statistics group/tab
	QLabel *labelNodesLCD = new QLabel;
	labelNodesLCD->setText(tr("Total Nodes"));
	QLabel *labelEdgesLCD = new QLabel;
	labelEdgesLCD->setText(tr("Total Links"));
	nodesLCD=new QLCDNumber(7);
	nodesLCD->setSegmentStyle(QLCDNumber::Flat);
	nodesLCD->setToolTip(tr("Counts how many nodes (vertices) exist in the whole network."));
	edgesLCD=new QLCDNumber(7);
	edgesLCD->setSegmentStyle(QLCDNumber::Flat);
	edgesLCD->setToolTip(tr("Counts how many links (in and out) exist in the whole network."));

	QLabel *labelDensityLCD = new QLabel;
	labelDensityLCD->setText(tr("Density"));
	densityLCD=new QLCDNumber(7);
	densityLCD->setSegmentStyle(QLCDNumber::Flat);
	densityLCD->setToolTip(tr("The density of a network is the ratio of existing links to all possible links (n(n-1)) between nodes."));

	//create a grid layout
	QGridLayout *propertiesGrid = new QGridLayout();

	propertiesGrid -> setColumnMinimumWidth(0, 10);
	propertiesGrid -> setColumnMinimumWidth(1, 10);

	propertiesGrid -> addWidget(labelNodesLCD, 0,0);
	propertiesGrid -> addWidget(labelEdgesLCD, 0,1);
	propertiesGrid -> addWidget(nodesLCD,1,0);
	propertiesGrid -> addWidget(edgesLCD,1,1);

	propertiesGrid -> addWidget(labelDensityLCD, 2,0);
	propertiesGrid -> addWidget(densityLCD,2,1);

	QLabel *dummyLabel = new QLabel;
	dummyLabel-> setText (" ");
	QLabel *labelNode = new QLabel;
	labelNode-> setText (tr("Active Node"));

	QLabel *labelSelectedNodeLCD = new QLabel;
	labelSelectedNodeLCD -> setText (tr("Node Number:"));
	labelSelectedNodeLCD -> setToolTip (tr("This is the number of the last selected node."));

	selectedNodeLCD =new QLCDNumber(7);
	selectedNodeLCD ->setSegmentStyle(QLCDNumber::Flat);

	QLabel *labelInLinksLCD = new QLabel;
	labelInLinksLCD -> setText (tr("Node In-Degree:"));
	labelInLinksLCD -> setToolTip (tr("This is the number of edges ending at the node you clicked on."));
	inLinksLCD=new QLCDNumber(7);
	inLinksLCD -> setSegmentStyle(QLCDNumber::Flat);
	inLinksLCD -> setToolTip (tr("This is the number of edges ending at the node you clicked on."));
	QLabel *labelOutLinksLCD = new QLabel;
	labelOutLinksLCD -> setText (tr("Node Out-Degree:"));
	labelOutLinksLCD -> setToolTip (tr("This is the number of edges starting from the node you clicked on."));
	outLinksLCD=new QLCDNumber(7);
	outLinksLCD -> setSegmentStyle(QLCDNumber::Flat);
	outLinksLCD -> setToolTip (tr("This is the number of edges starting from the node you clicked on."));

	QLabel *labelClucofLCD  = new QLabel;
	labelClucofLCD -> setText (tr("Clustering Coef."));
	labelClucofLCD -> setToolTip (tr("The Clustering Coefficient quantifies how close the clicked vertex and its neighbors are to being a clique. \nThe value is the proportion of links between the vertices within the neighbourhood of the clicked vertex,\n divided by the number of links that could possibly exist between them. \n\n WARNING: This value is displayed for each node when you click on it,\n but only if you have computed CluCof from the menu Statistics > Clustering Coefficient "));
	clucofLCD = new QLCDNumber(7);
	clucofLCD -> setSegmentStyle(QLCDNumber::Flat);
	clucofLCD  -> setToolTip (tr("The Clustering Coefficient quantifies how close the clicked vertex and its neighbors are to being a clique. \nThe value is the proportion of links between the vertices within the neighbourhood of the clicked vertex,\n divided by the number of links that could possibly exist between them. \n\n WARNING: This value is displayed for each node when you click on it,\n but only if you have computed CluCof from the menu Statistics > Clustering Coefficient "));
	
	
	propertiesGrid -> addWidget(dummyLabel, 6,0);
	propertiesGrid -> addWidget(labelNode, 7,0);
	propertiesGrid -> addWidget(labelSelectedNodeLCD , 8,0);
	propertiesGrid -> addWidget(selectedNodeLCD ,8,1);
	propertiesGrid -> addWidget(labelInLinksLCD, 9,0);
	propertiesGrid -> addWidget(inLinksLCD, 9,1);
	propertiesGrid -> addWidget(labelOutLinksLCD, 10,0);
	propertiesGrid -> addWidget(outLinksLCD,10,1);
	propertiesGrid -> addWidget(labelClucofLCD, 11,0);
	propertiesGrid -> addWidget(clucofLCD,11,1);
	propertiesGrid -> setRowStretch(12,1);   //fix stretch
	
	//create a box with title
	QGroupBox *networkPropertiesGroup = new QGroupBox(tr(""));
	networkPropertiesGroup -> setLayout (propertiesGrid);


 	toolBox->addTab( networkPropertiesGroup, tr("Statistics"));
	toolBox->setMinimumWidth(buttonsGroup->sizeHint().width());



	// create some more widgets for the final tab: "Layout"
	moveSpringEmbedderBx = new QCheckBox(tr("Spring Embedder") );
	moveSpringEmbedderBx->setToolTip(tr("Embeds a spring-gravitational model on the network, where \neach node is regarded as physical object reppeling all \nother nodes, while springs between connected nodes attact them. \nThe result is \nconstant movement. This is a very SLOW process on networks with N > 100!"));

	moveFruchtermanBx = new QCheckBox(tr("Fruchterman-Reingold") );
	moveFruchtermanBx ->setEnabled(false);
	moveFruchtermanBx->setToolTip(tr("In Fruchterman-Reingold model, the vertices behave as atomic particles or celestial bodies, exerting attractive and repulsive forces to each other. Again, only vertices that are neighbours attract each other but, unlike Spring Embedder, all vertices repel each other. "));

	moveKamandaBx= new QCheckBox(tr("Kamanda-Kwei") );
	moveKamandaBx->setEnabled(false);
	moveKamandaBx->setToolTip(tr("!"));


	nodeSizeProportional2OutDegreeBx = new QCheckBox(tr("NodeSize = F (OutDegree)") );
	nodeSizeProportional2OutDegreeBx ->setEnabled(true);
	nodeSizeProportional2OutDegreeBx->setToolTip(tr("If you enable this, all nodes will be resized so that their size reflect their out-degree (the amount of links from them). To put it simply, more out-linked nodes will be bigger..."));

	nodeSizeProportional2InDegreeBx = new QCheckBox(tr("NodeSize = F (InDegree)") );
	nodeSizeProportional2InDegreeBx ->setEnabled(true);
	nodeSizeProportional2InDegreeBx->setToolTip(tr("If you enable this, all nodes will be resized so that their size reflect their in-degree (the amount of links to them from other nodes). To put it simply, more in-linked nodes will be bigger..."));

	QGridLayout *layoutGroupLayout = new QGridLayout();
	layoutGroupLayout -> addWidget(moveSpringEmbedderBx, 0,0);
	layoutGroupLayout -> addWidget(moveKamandaBx, 1,0);
	layoutGroupLayout -> addWidget(nodeSizeProportional2OutDegreeBx, 2,0);
	layoutGroupLayout -> addWidget(nodeSizeProportional2InDegreeBx, 3,0);

	layoutGroupLayout -> setRowStretch(4,1);   //fix stretch	

	//create a box with title
	QGroupBox *layoutGroup= new QGroupBox(tr(""));
	layoutGroup->setLayout (layoutGroupLayout );
 	toolBox->addTab(layoutGroup, tr("Layout"));


	connect(moveSpringEmbedderBx, SIGNAL(stateChanged(int)),this, SLOT(layoutSpringEmbedder(int)));
	connect(moveFruchtermanBx, SIGNAL(stateChanged(int)),this, SLOT(layoutFruchterman(int)));

	connect(nodeSizeProportional2OutDegreeBx , SIGNAL(clicked(bool)),this, SLOT(slotLayoutNodeSizeProportionalOutEdges(bool)));
	connect(nodeSizeProportional2InDegreeBx , SIGNAL(clicked(bool)),this, SLOT(slotLayoutNodeSizeProportionalInEdges(bool)));

}









//FIXME this is a bug: Graph calls GraphicsWidget which calls this to call Graph!
void MainWindow::updateNodeCoords(int nodeNumber, int x, int y){
//	qDebug("MW: updateNodeCoords() for %i with x %i and y %i", nodeNumber, x, y);
	activeGraph.updateVertCoords(nodeNumber, x, y);
}




/**
	Initializes the status bar
*/
void MainWindow::initStatusBar() {
	statusBarDuration=2000;
	statusMessage( tr("Ready."));
}







/**
	Initializes the scene and its graphicsWidget, the main widget of SocNetV
*/
void MainWindow::initView() {
	qDebug ("MW initView()");
	//create a scene
	scene=new QGraphicsScene();

	//create a view widget for this scene
	graphicsWidget=new GraphicsWidget(scene, this);
	graphicsWidget->setViewportUpdateMode( QGraphicsView::MinimalViewportUpdate );
	//  FullViewportUpdate  // MinimalViewportUpdate //SmartViewportUpdate  //BoundingRectViewportUpdate
	//QGraphicsView can cache pre-rendered content in a QPixmap, which is then drawn onto the viewport. 
	graphicsWidget->setCacheMode(QGraphicsView::CacheNone);  //CacheBackground | CacheNone

 	graphicsWidget->setRenderHint(QPainter::Antialiasing, true);
	graphicsWidget->setRenderHint(QPainter::TextAntialiasing, true);
	graphicsWidget->setRenderHint(QPainter::SmoothPixmapTransform, false);
	//Optimization flags:
	// By enabling the flag below, QGraphicsView will completely disable its implicit clipping
	graphicsWidget->setOptimizationFlag(QGraphicsView::DontClipPainter, false); 
	//if items do restore their state, it's not needed for graphicsWidget to do the same...
	graphicsWidget->setOptimizationFlag(QGraphicsView::DontSavePainterState, false);
	//Disables QGraphicsView's antialiasing auto-adjustment of exposed areas.
	graphicsWidget->setOptimizationFlag(QGraphicsView::DontAdjustForAntialiasing, false);
	//"QGraphicsScene applies an indexing algorithm to the scene, to speed up item discovery functions like items() and itemAt(). Indexing is most efficient for static scenes (i.e., where items don't move around). For dynamic scenes, or scenes with many animated items, the index bookkeeping can outweight the fast lookup speeds." So...
	scene->setItemIndexMethod(QGraphicsScene::BspTreeIndex); //NoIndex (for anime) | BspTreeIndex

 	graphicsWidget->setTransformationAnchor(QGraphicsView::AnchorUnderMouse); 	
 	graphicsWidget->setResizeAnchor(QGraphicsView::AnchorViewCenter);

 	// sets dragging the mouse over the scene while the left mouse button is pressed.
  	graphicsWidget->setDragMode(QGraphicsView::RubberBandDrag);
	graphicsWidget->setFocusPolicy(Qt::StrongFocus);	
	graphicsWidget->setFocus();

	this->resize(900,600);

	//set minimum size of canvas
 	graphicsWidget->setMinimumSize( (qreal)  ( this->width()-toolBox->sizeHint().width() -30) , (qreal) ( this->height()-statusBar()->sizeHint().height() -toolBar->sizeHint().height() -menuBar()->sizeHint().height() -20 ) );
	qDebug ("MW initView(): now window size %i, %i, graphicsWidget size %i, %i, scene %f,%f",this->width(),this->height(), graphicsWidget->width(),graphicsWidget->height(), graphicsWidget->scene()->width(), graphicsWidget->scene()->height());

}




/**
	Resizes the scene when the window is resized.
*/
void MainWindow::resizeEvent( QResizeEvent * ){
	qDebug ("MW resizeEvent():INITIAL window size %i, %i, graphicsWidget size %i, %i, scene %f,%f",this->width(),this->height(), graphicsWidget->width(),graphicsWidget->height(), graphicsWidget->scene()->width(), graphicsWidget->scene()->height());

	//the area of the scene displayed by the CanvasView
	scene->setSceneRect(0, 0, (qreal) ( graphicsWidget->width() ), (qreal) (graphicsWidget->height() ) );
	qDebug ("MW resizeEvent(): now window size %i, %i, graphicsWidget size %i, %i, scene %f,%f",this->width(),this->height(), graphicsWidget->width(),graphicsWidget->height(), graphicsWidget->scene()->width(), graphicsWidget->scene()->height());
}


/**
	Initializes the default network parameters. 
	Also used when erasing a network to start a new one
*/
void MainWindow::initNet(){
	qDebug("MW: initNet() START INITIALISATION");
	QApplication::setOverrideCursor( QCursor(Qt::WaitCursor) );
	
	initNodeSize=4;
	initNodeColor="gold";
	initLinkColor="grey"; //"black";
	initLabelColor="darkblue";
	initLabelSize=8;
	initNumberColor="black";
 	initNumberSize=8; 
	initNodeShape="circle";
	initBackgroundColor="white"; //"gainsboro";

	minDuration=3000; //dialogue duration - obsolete
	maxNodes=5000;		//Max nodes used by createRandomNetwork dialogues
	labelDistance=8;
	numberDistance=5;
	totalLinks=0;
	networkName="";
	
	previous_fileName=fileName;
	fileName="";
	
	pajekFileLoaded=false;
	adjacencyFileLoaded=false;
	fileFormat = -1;
	dotFileLoaded=false;
	fileLoaded=false;

	networkModified=false;
	fileSave->setIcon(QIcon(":/images/saved.png"));
	fileSave->setEnabled(true);

	markedNodeExists=false;	//used by slotFindNode()

	cursorPosGW=QPointF(-1,-1);
	clickedJimNumber=-1;
	linkClicked=false;
	nodeClicked=false;
	
	/** Clear previous network data */
	activeGraph.clear();
	activeGraph.setSocNetV_Version(VERSION);

	activeGraph.setInitVertexShape(initNodeShape);
	activeGraph.setInitVertexSize(initNodeSize);
	activeGraph.setInitVertexColor(initNodeColor);

	activeGraph.setInitVertexNumberSize(initNumberSize);
	activeGraph.setInitVertexNumberColor(initNumberColor);
	
	activeGraph.setInitVertexLabelColor(initLabelColor);
	activeGraph.setInitVertexLabelSize(initLabelSize);

	activeGraph.setInitEdgeColor(initLinkColor);

	activeGraph.setShowLabels(this->showLabels());
	activeGraph.setShowNumbersInsideNodes( this->showNumbersInsideNodes());
	
	
	/** Clear scene **/
	graphicsWidget->clear();
	

	//Clear LCDs
	nodesLCD->display(activeGraph.vertices());
	edgesLCD->display(activeGraph.totalEdges());
	densityLCD->display(activeGraph.density());
	inLinksLCD->display(0);
	outLinksLCD->display(0);
	clucofLCD->display(0);
	selectedNodeLCD->display(0);

	nodeSizeProportional2OutDegreeBx->setChecked(false);
	nodeSizeProportional2InDegreeBx->setChecked(false);
  
	displayLinksWeightNumbersAct->setChecked(false);
	//displayLinksArrowsAct->setChecked(false);		//FIXME: USER PREFS EMITTED TO GRAPH?

        filterOrphanNodesAct->setChecked(false); // re-init orphan nodes menu item
	
	//set window title
	setWindowTitle(tr("Social Network Visualizer ")+VERSION);
	QApplication::restoreOverrideCursor();
	statusMessage( tr("Ready"));
	qDebug("MW: initNet() INITIALISATION END");
}




/*
 * Slot called by Graph::statusMessage to display some message to the user 
 */
void MainWindow::statusMessage(const QString message){
	statusBar()->showMessage( message, statusBarDuration );
}



/**
	Closes the application. 
	Asks to write any unsaved network data.
*/
void MainWindow::closeEvent( QCloseEvent* ce ) {
	if ( !networkModified )       {
		ce->accept();
		return;
	}
	switch( QMessageBox::information( this, "Save file",
				      tr("Do you want to save the changes") +
				      tr(" to the network file?"),
				      tr("Yes"), tr("No"), tr("Cancel"),
				      0, 1 ) )
	{
		case 0:
			slotFileSave();
			ce->accept();
			break;
		case 1:
			ce->accept();
			break;
		case 2:
		default: // just for sanity
			ce->ignore();
			break;
	}
}




/**
	Creates a new network
*/
void MainWindow::slotCreateNew() {
	slotFileClose();  
}




/**
	Prompts the user a directory dialogue to choose a file from.
	Loads the specified file, calling loadNetworkFile()
*/
void MainWindow::slotChooseFile() {
	
	if (firstTime && fileFormat == -1 ) {
		QMessageBox::information( this, "SocNetV",
				tr("Attention: \n")+
				tr("This menu option is suitable only for loading a network file with data in GraphML format, which is the default file format of SocNetV. \n")+
				
				tr("If you want to import other supported network formats (i.e. Pajek, UCINET, dot, etc), ")+
				tr("please use the options in the Import sub menu. \n")+
				tr("\n This warning message will not appear again."),
				"OK", 0 ); 
		firstTime=false;
	}
	if ( fileFormat == -1 ) 
		fileFormat = 1;
	
	bool a_file_was_already_loaded=fileLoaded;
	previous_fileName=fileName;
	QString m_fileName, fileType_string;
	int m_fileFormat=fileFormat;
	
	statusMessage( tr("Choose a network file..."));
	switch (m_fileFormat){
		case 1:	//GraphML
				fileType_string = tr("GraphML (*.graphml *.xml);;All (*)");
				break;
		case 2: //Pajek
				fileType_string = tr("Pajek (*.net *.paj *.pajek);;All (*)");
				break;
		case 3: //Adjacency
				fileType_string = tr("Adjacency (*.txt *.csv *.sm *.adj);;All (*)");
				break;
		case 4: //Dot
				fileType_string = tr("GraphViz (*.dot);;All (*)");
				break;
		case 5:	//GML
				fileType_string = tr("GML (*.gml);;All (*)");
				break;
		case 6: //DL
				fileType_string = tr("DL (*.dl);;All (*)");
				break;
		case 7:	// Weighted List
				fileType_string = tr("List (*.lst *.list);;All (*)");
				break;
		case 8:	// Simple List
				fileType_string = tr("List (*.lst *.list);;All (*)");
				break;
		case 9:	// Two mode sm
                                fileType_string = tr("Two-Mode Sociomatrix (*.txt *.2sm *.aff *.csv  *.sm);;All (*)");
                                break;
		default:	//All
				fileType_string = tr("All (*);;GraphML (*.graphml);;GraphViz (*.dot);;Adjacency (*.txt *.csv *.net *.adj *.sm);;Pajek (*.net *.pajek *.paj);;DL (*.dl *.net)");
				break;

	}
	m_fileName = QFileDialog::getOpenFileName( this, tr("Select one file to open"), "", fileType_string	);

	if (!m_fileName.isEmpty()) {
		qDebug()<<"MW: file selected: " << m_fileName;		
		fileNameNoPath=m_fileName.split ("/" );
		if ( loadNetworkFile ( m_fileName, m_fileFormat  ) )
		{
			fileName=m_fileName;
			previous_fileName=fileName;
			setWindowTitle("SocNetV "+ VERSION +" - "+fileNameNoPath.last());
			QString message=tr("Loaded network: ")+fileNameNoPath.last();
			statusMessage( message );
		}
		else {
			statusMessage( tr("Error loading requested file. Aborted."));
			QMessageBox::critical( this, "SocNetV",
				tr("Error! \n")+
				tr("Sorry, the selected file is not in GraphML format, which is the default file format of SocNetV. \n")+
				tr("If you want to import other network formats (i.e. Pajek, UCINET, dot, etc), ")+
				tr("please use the options in the Import sub menu. \n"),
				"OK", 0 );
		}
	}
	else  {
		statusMessage( tr("Opening aborted"));	
		//if a file was previously opened, get back to it.
		if (a_file_was_already_loaded)	{ 
				fileLoaded=true;  
				fileName=previous_fileName; 
		}
  	}
}





/**
	Saves the network in the same file
*/
void MainWindow::slotFileSave() {
	statusMessage( tr("Saving file..."));

	if (!fileLoaded && !networkModified ) {
		statusMessage(  QString(tr("No network loaded.")) );
		return;
	}
	if ( fileName.isEmpty() ) {
		slotFileSaveAs();
		return;
	}

	int maxWidth=scene->width();
	int maxHeight=scene->height();	
	fileNameNoPath=fileName.split ("/");
	if (pajekFileLoaded) 
	{
		if ( activeGraph.saveGraph(fileName, 1, networkName, maxWidth,maxHeight) )
			networkSaved(1);
		else 
			networkSaved(0); 
	}
	else if (adjacencyFileLoaded)
	{
		if ( activeGraph.saveGraph(fileName, 2, networkName, maxWidth,maxHeight) )
			networkSaved(2);
		else 
			networkSaved(0);
	}
	else if (graphMLFileLoaded || ( !fileLoaded && networkModified) )
	{	//new file or GraphML
		if ( activeGraph.saveGraph(fileName, 4, networkName, maxWidth,maxHeight) )
			networkSaved(4);
		else 
			networkSaved(0);
	}
	else
	{
			switch( QMessageBox::information( this, "GraphML File Format",
						tr("This network will be saved in GraphML format. \n")+
						tr("Is this OK? \n\n") +
						tr("If not, press Cancel, then go to Network > Export menu..."),
						"Yes", "No",0,1 ) 
			)
			{
				case 0:
					if ( activeGraph.saveGraph(fileName, 4, networkName, maxWidth,maxHeight) )
						networkSaved(4);
					else 
						networkSaved(0);
		 			break;
				case 1:
					statusMessage( tr("Save aborted...") );
					break;
			}
	}

}



/**
	Saves the network in a new file
*/
void MainWindow::slotFileSaveAs() {
	statusMessage( tr("Saving network under new filename..."));

	QString fn =  QFileDialog::getSaveFileName(this, 
							tr("Save GraphML Network to File Named..."),
							0, tr("GraphML (*.graphml *.xml);;All (*)") );
 	if (!fn.isEmpty())  {
 		if  ( QFileInfo(fn).suffix().isEmpty() ){
 				QMessageBox::information(this, "Missing Extension ",tr("File extension was missing! \nI am appending a standard .graphml to the given filename."), "OK",0);
 				fn.append(".graphml");
			}
		fileName=fn;
		fileNameNoPath=fileName.split ("/");
		adjacencyFileLoaded=false;
		pajekFileLoaded=false;
		graphMLFileLoaded=false;
		slotFileSave();
	}
	else  {
 		statusMessage( tr("Saving aborted"));
		return;
	}
	statusMessage( tr("Ready."));
}



/*
 *	Called from Graph when we try to save file  
 */
void MainWindow::networkSaved(int saved_ok)
{
	if (saved_ok <= 0) 
	{
		graphChanged();
		statusMessage( tr("Error! Could not save this file... ")+fileNameNoPath.last()+tr(".") );
	}
	else	
	{
		fileSave->setIcon(QIcon(":/images/saved.png"));
		fileSave->setEnabled(false);
		fileLoaded=true; networkModified=false;
		setWindowTitle( fileNameNoPath.last() );
		statusMessage( tr("Network saved under filename: ")+fileNameNoPath.last()+tr(".") );
		switch (saved_ok){
			case 1: 
				adjacencyFileLoaded=false;
				pajekFileLoaded=true;
				graphMLFileLoaded=false;
				break;
			case 2:
				adjacencyFileLoaded=true;
				pajekFileLoaded=false;
				graphMLFileLoaded=false;
				break;
			case 3:
				adjacencyFileLoaded=false;
				pajekFileLoaded=false;
				graphMLFileLoaded=false;
				break;
			case 4:
				adjacencyFileLoaded=false;
				pajekFileLoaded=false;
				graphMLFileLoaded=true;
				break;			
		}
	}		
}

/**
	Closes the network. Saves it if necessary. 
	Used by createNew.
*/
void MainWindow::slotFileClose() {
	statusMessage( tr("Closing file..."));
	if (networkModified) {
		switch ( QMessageBox::information (this, 
					"Closing Network...",
					tr("Network has not been saved. \nDo you want to save before closing it?"), 
					"Yes", "No",0,1))
		{
			case 0: slotFileSave(); break;
			case 1: break;
		}
	}
	statusMessage( tr("Erasing old network data...."));
	initNet();	
	statusMessage( tr("Ready."));
}



/**
	Prints whatever is viewable on the Graphics widget
*/
void MainWindow::slotPrintView() {
	statusMessage( tr("Printing..."));
	QPrintDialog dialog(printer, this);
	if ( dialog.exec() )   {
 		QPainter painter(printer);
 		graphicsWidget->render(&painter);
	};
	statusMessage( tr("Ready."));
}




/**	
	Imports a network from a formatted file
*/
void MainWindow::slotImportGraphML(){
	fileFormat=1;
	this->slotChooseFile();
}



/**	
	Imports a network from a formatted file
*/
void MainWindow::slotImportPajek(){
	fileFormat=2;
	this->slotChooseFile();
}



/**	
	Imports a network from a Adjacency matrix formatted file
*/
void MainWindow::slotImportSM(){
	fileFormat=3;
	this->slotChooseFile();	
}



/**
	Imports a network from a two mode sociomatrix formatted file
*/
void MainWindow::slotImportTwoModeSM(){
	fileFormat=9;
	this->slotChooseFile();
}


/**	
	Imports a network from a Dot formatted file
*/
void MainWindow::slotImportDot(){
	fileFormat=4;
	this->slotChooseFile();
}



/**	
	Imports a network from a GML formatted file
*/
void MainWindow::slotImportGML(){
	fileFormat=5;
	this->slotChooseFile();
}


/**	
	Imports a network from a UCINET formatted file
*/
void MainWindow::slotImportDL(){
	fileFormat=6;
	this->slotChooseFile();
}


/**	
	Imports a network from a List formatted file
*/
void MainWindow::slotImportEdgeList(){
	switch( QMessageBox::question( this, "Type of list format",
					  tr("I can parse two kinds of lists: \n\n")+
					  tr("A. Weighted lists, with each line having exactly 3 columns (source, target, weight), i.e.\n  1 2 5 \n \n")+
					  tr("B. Simple edge lists, with each line having 2 or more columns (source, target1, target2, ... etc)\n\n")+
					  tr("Please select the appropriate type of list format for the file you want to load:"),
					  "Weighted", "Simple",0,1 )
		)
	{
	case 0:
		qDebug() << "***  MW: slotImportEdgeList - Weighted list selected! " ;
		fileFormat  = 7;
		break;
	case 1:
		qDebug() << "***  MW: slotImportEdgeList - Simple list selected! " ;
		fileFormat = 8;
		break;
	}
	this->slotChooseFile();
}




/**
 * 	Main network file loader method 
 * 	Inits everything to default values.
 *  Then calls activeGraph::loadGraph to actually load the network...
 */
bool MainWindow::loadNetworkFile(QString m_fileName, int m_fileFormat ){
	qDebug("MW: loadNetworkFile");
	initNet();
	int two_sm_mode = 0;

	if ( m_fileFormat == 9 ) {
		switch( QMessageBox::information( this, "Two-mode sociomatrix",
						tr("If this file is in two-mode sociomatrix format, \n")+
						tr("please specify which mode to open \n\n") +
						tr("1st mode: rows are nodes \n") +
						tr("2nd mode: columns are nodes"),
						tr("1st Mode"), tr("2nd mode"), 0,1 ) ) {
			case 0:
			two_sm_mode = 1;
			break;
			case 1:
			two_sm_mode = 2;
			break;
		}
	}
	QApplication::setOverrideCursor( QCursor(Qt::WaitCursor) );
	bool loadGraphStatus = activeGraph.loadGraph ( 
			m_fileName,
			displayNodeLabelsAct->isChecked(),
			graphicsWidget->width(),
			graphicsWidget->height(),
			m_fileFormat, two_sm_mode
			);
	QApplication::restoreOverrideCursor();
	return loadGraphStatus;
}


/**
*	Called from Parser/Graph when a network file is loaded.
*	It informs the MW about the type of the network so that it can display the appropiate message.
*/
void MainWindow::fileType (
		int type, QString netName, int aNodes, int totalLinks, bool undirected)
{
	qDebug()<< "MW: fileType() networkName is: " << netName << " type " << type;
	Q_UNUSED (undirected);
	if (netName != "")
		networkName=netName ;
	else
		networkName=(fileName.split ("/")).last();
	fileFormat=type;
	switch( type ) 	{
		case 0:
			pajekFileLoaded=false;
			adjacencyFileLoaded=false;
			graphMLFileLoaded=false;
			fileLoaded=false;
			break;
		case 1:
			pajekFileLoaded=false;
			adjacencyFileLoaded=false;
			dotFileLoaded=false;
			graphMLFileLoaded=true;
			fileLoaded=true;
			networkModified=false;
			statusMessage( QString(tr("GraphML formatted network, named %1, loaded with %2 Nodes and %3 total Links.")).arg( networkName ).arg( aNodes ).arg(totalLinks ) );
			break;

		case 2:
			pajekFileLoaded=true;
			adjacencyFileLoaded=false;
			graphMLFileLoaded=false;
			fileLoaded=true;
			networkModified=false;
			statusMessage( QString(tr("Pajek formatted network, named %1, loaded with %2 Nodes and %3 total Links.")).arg( networkName ).arg( aNodes ).arg(totalLinks ));
			break;

		case 3:
			pajekFileLoaded=false;
			adjacencyFileLoaded=true;
			graphMLFileLoaded=false;
			fileLoaded=true;
			networkModified=false;
			statusMessage( QString(tr("Adjacency formatted network, named %1, loaded with %2 Nodes and %3 total Links.")).arg( networkName ).arg( aNodes ).arg(totalLinks ) );
			break;

		case 4:
			pajekFileLoaded=false;
			adjacencyFileLoaded=false;
			dotFileLoaded=true;
			graphMLFileLoaded=false;
			fileLoaded=true;
			networkModified=false;
			statusMessage( QString(tr("Dot formatted network, named %1, loaded with %2 Nodes and %3 total Links.")).arg( networkName ).arg( aNodes ).arg(totalLinks ) );
			break;

		case 5:
			pajekFileLoaded=false;
			adjacencyFileLoaded=false;
			dotFileLoaded=false;
			graphMLFileLoaded=false;
			fileLoaded=true;
			networkModified=false;
			statusMessage( QString(tr("DL-formatted network, named %1, loaded with %2 Nodes and %3 total Links.")).arg( networkName ).arg( aNodes ).arg(totalLinks ) );
			break;
		case 6:
			pajekFileLoaded=false;
			adjacencyFileLoaded=false;
			dotFileLoaded=false;
			graphMLFileLoaded=false;
			fileLoaded=true;
			networkModified=false;
			statusMessage( QString(tr("GML-formatted network, named %1, loaded with %2 Nodes and %3 total Links.")).arg( networkName ).arg( aNodes ).arg(totalLinks ) );
			break;
		case 7:
			pajekFileLoaded=false;
			adjacencyFileLoaded=false;
			dotFileLoaded=false;
			graphMLFileLoaded=false;
			fileLoaded=true;
			networkModified=false;
			statusMessage( QString(tr("Weighted list-formatted network, named %1, loaded with %2 Nodes and %3 total Links.")).arg( networkName ).arg( aNodes ).arg(totalLinks ) );
			break;
		case 8:
			pajekFileLoaded=false;
			adjacencyFileLoaded=false;
			dotFileLoaded=false;
			graphMLFileLoaded=false;
			fileLoaded=true;
			networkModified=false;
			statusMessage( QString(tr("Simple list-formatted network, named %1, loaded with %2 Nodes and %3 total Links.")).arg( networkName ).arg( aNodes ).arg(totalLinks ) );
			break;
		case 9:
			pajekFileLoaded=false;
			adjacencyFileLoaded=false;
			dotFileLoaded=false;
			graphMLFileLoaded=false;
			fileLoaded=true;
			networkModified=false;
			statusMessage( QString(tr("Two-mode affiliation network, named %1, loaded with %2 Nodes and %3 total Links.")).arg( networkName ).arg( aNodes ).arg(totalLinks ) );
			break;

		default: // just for sanity
			pajekFileLoaded=false;
			adjacencyFileLoaded=false;
			graphMLFileLoaded=false;
			fileLoaded=false;
			QMessageBox::critical(this, "Error","Unrecognized format. \nPlease specify"
			" which is the file-format using Import Menu.","OK",0);
			break;
	}
	graphChanged();
	fileSave->setIcon(QIcon(":/images/saved.png"));
	fileSave->setEnabled(false);
}








/**
	Calls Graph::createVertex method to add a new RANDOM node into the activeGraph.
	Called when "Create Node" button is clicked on the Main Window.
*/
void MainWindow::addNode() {
	qDebug("MW: addNode(). Calling activeGraph::createVertex() for -1 - max width and height %i, %i", graphicsWidget->width()-10,  graphicsWidget->height()-10);
	activeGraph.createVertex(-1, graphicsWidget->width()-10,  graphicsWidget->height()-10);  // minus a  screen edge offset...
	statusMessage( tr("New node (numbered %1) added.").arg(activeGraph.lastVertexNumber())  );
}


/**
	Calls Graph::createVertex method to add a new node into the activeGraph.
	Called on double clicking
*/
void MainWindow::addNodeWithMouse(int num, QPointF p) {
	qDebug("MW: addNodeWithMouse(). Calling activeGraph::createVertex() for a vertice named %i", num);
	activeGraph.createVertex(num, p);
	statusMessage( tr("New node (numbered %1) added.").arg(activeGraph.lastVertexNumber())  );
}





/**
	Exports the network to a PNG image 
	Mediocre Quality but smaller file
*/

bool MainWindow::slotExportPNG(){
	qDebug("slotExportPNG");
	if (!fileLoaded && !networkModified )  {
		QMessageBox::critical(this, "Error",tr("The canvas is empty!\nLoad a network file or create a new network first."), "OK",0);
		statusMessage( tr("Cannot export PNG.") );
		return false;
	}
	QString fn = QFileDialog::getSaveFileName(this,tr("Save"), 0, tr("Image Files (*.png)"));
	if (fn.isEmpty())  {
		statusMessage( tr("Saving aborted") );
		return false;
	}	
	tempFileNameNoPath=fn.split ("/");
	qDebug("slotExportPNG: grabing canvas");
	QPixmap picture;
	picture=QPixmap::grabWidget(graphicsWidget, graphicsWidget->rect());
	qDebug("slotExportPNG: adding logo");
	QPainter p;
	p.begin(&picture);
		p.setFont(QFont ("Helvetica", 10, QFont::Normal, false));
		p.drawText(5,10,"SocNetV: "+tempFileNameNoPath.last());
	p.end();
	qDebug("slotExportPNG: checking filename");
	if (fn.contains("png", Qt::CaseInsensitive) ) {
		picture.toImage().save(fn, "PNG");
		QMessageBox::information(this, "Export to PNG...",tr("Image Saved as: ")+tempFileNameNoPath.last(), "OK",0);
 	}
	else {
		picture.toImage().save(fn+".png", "PNG");
		QMessageBox::information(this, "Export to PNG...",tr("Image Saved as: ")+tempFileNameNoPath.last()+".png" , "OK",0);
	}
	
	statusMessage( tr("Exporting completed") );
	
	return true;   
}



/**
	Exports the network to a BMP image  
	Better Quality but larger file
*/
bool MainWindow::slotExportBMP(){
	qDebug(	"slotExportBMP()");
	if (!fileLoaded && !networkModified )  {
		QMessageBox::critical(this, "Error",tr("Nothing to export! \nLoad a network file or create a new network first."), "OK",0);
		statusMessage( tr("Cannot export BMP.") );
		return false;
	}
	QString format="bmp";
	QString fn = QFileDialog::getSaveFileName(this,tr("Save Image as"), 0,tr("Image Files (*.bmp)"));
	if (fn.isEmpty())  {
		statusMessage( tr("Saving aborted") );
		return false;
	}	
	tempFileNameNoPath=fn.split ("/");

	QPixmap picture;
	qDebug("slotExportBMP: grabing canvas");
	picture=QPixmap::grabWidget(graphicsWidget, graphicsWidget->viewport()->rect());
	QPainter p;
	qDebug("slotExportBMP: adding logo");
	p.begin(&picture);
		p.setFont(QFont ("Helvetica", 10, QFont::Normal, false));
		p.drawText(5,10,"SocNetV: "+tempFileNameNoPath.last());
	p.end();
	qDebug("slotExportBMP: checking file");
	if (fn.contains(format, Qt::CaseInsensitive) ) {
		picture.toImage().save(fn, format.toAscii());
		QMessageBox::information(this, tr("Export to BMP..."),tr("Image Saved as: ")+tempFileNameNoPath.last(), "OK",0);
 	}
	else {
		picture.toImage().save(fn+"."+format, format.toAscii());
		QMessageBox::information(this, tr("Export to BMP..."),tr("Image Saved as: ")+tempFileNameNoPath.last()+"."+format , "OK",0);
	}
	qDebug()<< "Exporting BMP to "<< fn;

	statusMessage( tr("Exporting completed") );
	qDebug("Export finished!");
	return true;   
}






/**
	Exports the network to a PDF Document 
	Best Quality 
*/
bool MainWindow::slotExportPDF(){
	qDebug(	"slotExportPDF()");
	if (!fileLoaded && !networkModified )  {
		QMessageBox::critical(this, "Error",tr("The canvas is empty!\nLoad a network file or create a new network first."), "OK",0);
		statusMessage( tr("Cannot export PDF.")  );
		return false;
	}

	QString m_fileName = QFileDialog::getSaveFileName(this, tr("Export to PDF"), 0, tr("Portable Document Format files (*.pdf)"));
	if (m_fileName.isEmpty())  {
		statusMessage( tr("Saving aborted"));
		return false;
	}	
    else {
		if (QFileInfo(m_fileName).suffix().isEmpty())
			m_fileName.append(".pdf");

		QPrinter printer(QPrinter::HighResolution);
		printer.setOutputFormat(QPrinter::PdfFormat);
		printer.setOutputFileName(m_fileName);
		QPainter painter(&printer);
		graphicsWidget->render(&painter);
	}
	qDebug()<< "Exporting PDF to "<< m_fileName;	
	tempFileNameNoPath=m_fileName.split ("/");
	QMessageBox::information(this, tr("Export to PDF..."),tr("File saved as: ")+tempFileNameNoPath.last() , "OK",0);
	statusMessage(  tr("Exporting completed") );
	return true;
}




/**
	Exports the network to a Pajek-formatted file
	Calls the relevant Graph method.
*/
void MainWindow::slotExportPajek()
{
	qDebug ("MW: slotExportPajek");

	if (!fileLoaded && !networkModified )  {
		QMessageBox::critical(this, "Error",tr("Nothing to export! \nLoad a network file or create a new network first."), "OK",0);
		statusMessage( tr("Cannot export to Pajek.")  );
		return;
	}

	statusMessage( tr("Exporting active network under new filename..."));
	QString fn =  QFileDialog::getSaveFileName(this, 
							tr("Export Network to File Named..."),
							0, tr("Pajek (*.paj *.net *.pajek);;All (*)") );
 	if (!fn.isEmpty())  {
 		if  ( QFileInfo(fn).suffix().isEmpty() ){
 				QMessageBox::information(this, "Missing Extension ",tr("File extension was missing! \nI am appending a standard .paj to the given filename."), "OK",0);
 				fn.append(".paj");
			}
		fileName=fn;
		fileNameNoPath=fileName.split ("/");
	}
	else  {
 		statusMessage( tr("Saving aborted"));
		return;
	}

	int maxWidth=scene->width();
	int maxHeight=scene->height();	

	if ( activeGraph.saveGraph(fileName, 1, networkName, maxWidth,maxHeight ) )  
		networkSaved(1);
	else 
		networkSaved(0); 
}



/**	Exports the network to a adjacency matrix-formatted file
	Calls the relevant Graph method.
*/
void MainWindow::slotExportSM(){
	qDebug("MW: slotExportSM()");
	if (!fileLoaded && !networkModified )  {
		QMessageBox::critical(this, "Error",tr("Nothing to export!\nLoad a network file or create a new network first."), "OK",0);
		statusMessage( tr("Cannot export to Adjacency Matrix.")  );
		return;
	}
	statusMessage( tr("Exporting active network under new filename..."));
	QString fn =  QFileDialog::getSaveFileName(this, 
							tr("Export Network to File Named..."),
							0, tr("Adjacency (*.adj *.sm *.txt *.csv *.net);;All (*)") );
 	if (!fn.isEmpty())  {
 		if  ( QFileInfo(fn).suffix().isEmpty() ){
 				QMessageBox::information(this, "Missing Extension ",tr("File extension was missing! \nI am appending a standard .adj to the given filename."), "OK",0);
 				fn.append(".adj");
			}
		fileName=fn;
		fileNameNoPath=fileName.split ("/");
	}
	else  {
 		statusMessage( tr("Saving aborted"));
		return;
	}

	QMessageBox::information(this, "Warning",tr("Note that exporting to an adjacency matrix does not save floating-point weight values; adjacency matrices consist of integers, only. \n If your network had any floating point weights in some edges, these are being truncated to the nearest integer or 1."), "OK",0);
	int maxWidth=scene->width();
	int maxHeight=scene->height();	

	if ( activeGraph.saveGraph(fileName, 2, networkName,maxWidth,maxHeight ) )  
		networkSaved(1);
	else 
		networkSaved(0); 
}






/**
	Exports the network to a DL-formatted file
	TODO slotExportDL
*/
bool MainWindow::slotExportDL(){
	if (!fileLoaded && !networkModified )  {
		QMessageBox::critical(this, "Error",tr("Nothing to export!\nLoad a network file or create a new network first."), "OK",0);
		statusMessage( tr("Cannot export to DL.")  );
		return false;
	}

	if (fileName.isEmpty()) {
		statusMessage( tr("Saving network under new filename..."));
  		QString fn = QFileDialog::getSaveFileName(this, 0, 0);
 	 	if (!fn.isEmpty())  {
			fileName=fn;
  		}
  		else  {
   		 	statusMessage( tr("Saving aborted"));
			return false;
 		}
	}

return true;

}


/**
	Exports the network to a GW-formatted file
	TODO slotExportGW
*/ 
bool MainWindow::slotExportGW(){
	if (!fileLoaded && !networkModified )  {
		QMessageBox::critical(this, "Error",tr("Nothing to export!\nLoad a network file or create a new network first."), "OK",0);
		statusMessage( tr("Cannot export to GW.")  );
		return false;
	}

	if (fileName.isEmpty()) {
		statusMessage( tr("Saving network under new filename..."));
  		QString fn = QFileDialog::getSaveFileName(this, 0, 0);
 	 	if (!fn.isEmpty())  {
			fileName=fn;
  		}
  		else  {
   		 	statusMessage( tr("Saving aborted"));
			return false;
 		}
	}

return true;
}




/**
	Exports the network to a list-formatted file
	TODO slotExportList
*/
bool MainWindow::slotExportList(){
	if (fileName.isEmpty()) {
		statusMessage( tr("Saving network under new filename..."));
  		QString fn = QFileDialog::getSaveFileName(this, 0, 0);
 	 	if (!fn.isEmpty())  {
			fileName=fn;
  		}
  		else  {
   		 	statusMessage( tr("Saving aborted"));
			return false;
 		}
	}

return true;
}





/**
	Adds a little universal randomness :)
*/
void MainWindow::makeThingsLookRandom()   {
    time_t now;				/* define 'now'. time_t is probably a typedef	*/
    now = time((time_t *)NULL);		/* Get the system time and put it
   					 * into 'now' as 'calender time' the number of seconds since  1/1/1970   	*/

     srand( (unsigned int ) now);
  }




/**
	Displays the file of the loaded network.
	Network _must_ be unchanged since last save/load.
	Otherwise it will ask the user to first save the network, then view its file.
*/
void MainWindow::slotViewNetworkFile(){
	qDebug() << "slotViewNetworkFile() : " << fileName.toAscii();
	if ( fileLoaded && !networkModified ) { //file network unmodified
		QFile f( fileName );
		if ( !f.open( QIODevice::ReadOnly ) ) {
			qDebug ("Error in open!");
			return;
		}
		TextEditor *ed = new TextEditor(fileName);//OPEN A TEXT EDITOR WINDOW
		ed->setWindowTitle(tr("Viewing network file - ") + fileNameNoPath.last() );
		ed->show();
		statusMessage(  tr("Loaded network text file " )+ fileNameNoPath.last()  );
	}
	else if (fileName.isEmpty() && networkModified)     {  //New network + something
		QMessageBox::information (this, "Viewing network file",
		tr("This network has not been saved yet. \nI will open a dialog for you to save it now. \nPlease choose a filename..."), "OK",0);
		slotFileSaveAs();
	}
	else if (fileLoaded && networkModified ) {   //file network + modified
		QMessageBox::information (this, "Viewing network file",
		//FIXME maybe better to save automagically rather than asking?
		tr("The network has been modified. \nI will save it to the original file for you now."), "OK",0);
		networkModified = false;
		slotFileSave();
		slotViewNetworkFile();
	}
	else	{
		QMessageBox::critical(this, "Error",
		tr("Empty network! \nLoad a network file first or create and save a new one..."), "OK",0);
		statusMessage(  tr("Nothing here. Not my fault, though!") );
	}
}




/**
	Opens the embedded text editor
*/
void MainWindow::slotOpenTextEditor(){
	qDebug() << "slotOpenTextEditor() : ";

	TextEditor *ed = new TextEditor(""); 
	ed->setWindowTitle(tr("New Network File"));
	ed->show();
	statusMessage(  tr("Enter your network data here" ) );
}





/**
	Displays the adjacency matrix of the network.
	It uses a different method for writing the matrix to a file.
	While slotExportSM uses << operator of Matrix class (via adjacencyMatrix of Graph class), this is using directly the writeAdjacencyMatrix method of Graph class
*/
void MainWindow::slotViewAdjacencyMatrix(){
	if ( !fileLoaded && !networkModified) {
		QMessageBox::critical (this, "Error",
		tr("Empty network! \nLoad a network file or create something by double-clicking on the canvas!"), "OK",0);

        	statusMessage(  tr("Nothing to show!") );
		return;
	}	
	int aNodes=activeNodes();
	statusBar() ->  showMessage ( QString (tr ("creating adjacency adjacency matrix of %1 nodes")).arg(aNodes) );
	qDebug ("MW: calling Graph::writeAdjacencyMatrix with %i nodes", aNodes);
	char fn[]= "adjacency-matrix.dat";

	activeGraph.writeAdjacencyMatrix(fn, networkName.toLocal8Bit()) ;

	//Open a text editor window for the new file created by graph class
	QString qfn=QString::fromLocal8Bit("adjacency-matrix.dat");
	TextEditor *ed = new TextEditor(fn);
	tempFileNameNoPath=qfn.split( "/");
	ed->setWindowTitle(tr("View Adjacency Matrix - ") + tempFileNameNoPath.last());
	ed->show();

}



/*
 * Calls the m_datasetSelectionDialog to display the datasetselection dialog  
 */
void MainWindow::slotShowDataSetSelectDialog(){
	qDebug()<< "slotShowDataSetSelectDialog()";
	m_datasetSelectDialog.exec();
}


/*
 * Recreates some of the most famous and widely used data sets 
 * in network analysis studies
 */
void MainWindow::slotRecreateDataSet (QString m_fileName) {
	int m_fileFormat=0;
	qDebug()<< "slotRecreateDataSet() fileName: " << m_fileName;

	initNet();
	activeGraph.writeDataSetToFile(m_fileName);

	if (m_fileName.endsWith(".graphml")) {
	    m_fileFormat=1;
	}
	else if (m_fileName.endsWith(".pajek")) {
	   m_fileFormat=2;
	}
	else if (m_fileName.endsWith(".sm") || m_fileName.endsWith(".adj")) {
	   m_fileFormat=3;
	}
	else if (m_fileName.endsWith(".dot")) {
	    m_fileFormat=4;
	}
	else if (m_fileName.endsWith(".gml")) {
	    m_fileFormat=5;
	}
	else if (m_fileName.endsWith(".dl")) {
	    m_fileFormat=6;
	}
	else if (m_fileName.endsWith(".list")) {
	    m_fileFormat=7;
	}
	else if (m_fileName.endsWith(".lst")) {
	    m_fileFormat=8;
	}
	else if (m_fileName.endsWith(".2sm")) {
	    m_fileFormat=9;
	}


	if ( loadNetworkFile(m_fileName, m_fileFormat) ) {
		fileNameNoPath=m_fileName.split ("/" );
		fileName=m_fileName;
		previous_fileName=fileName;
		setWindowTitle("SocNetV "+ VERSION +" - "+fileNameNoPath.last());
		QString message=tr("Network saved as ")+fileNameNoPath.last();
		statusMessage( message );
	}
        else {
            statusMessage( "Could not read new network data file. Aborting.");
        }
}

/**
	Calls activeGraph.createRandomNetErdos () to create a symmetric network
	Link existance is controlled by a user specified possibility.
*/
void MainWindow::slotCreateRandomNetErdos(){
	bool ok;
	statusMessage( "You have selected to create a random symmetric network. ");
	int newNodes=( QInputDialog::getInteger(this, "Create random network", tr("This will create a new random symmetric network of G(n,p) model, \nwhere n is the nodes and p is the edge probability. \nPlease enter the number n of nodes you want:"),1, 1, maxNodes, 1, &ok ) ) ;
	if (!ok) { 
		statusMessage( "You did not enter an integer. Aborting.");
		return;
	}
	double probability= QInputDialog::getDouble(this,"Create random network", "Enter an edge probability % (0-100):", 0, 0, 100, 1, &ok );
	if (!ok) { 
		statusMessage( "You did not enter an integer. Aborting.");
		return;
	}
	statusMessage( "Erasing any existing network. ");

	initNet();  
	makeThingsLookRandom();  
	statusMessage( tr("Creating random network. Please wait... ")  );

	qDebug("MW Erdos network:  Create random network of %i nodes and %f edge probability.",newNodes, probability);

	if (showProgressBarAct->isChecked() && newNodes > 300){
		progressDialog= new QProgressDialog("Creating random network. Please wait (or disable me from Options > View > ProgressBar, next time ;)).", "Cancel", 0, newNodes+newNodes, this);
		progressDialog -> setWindowModality(Qt::WindowModal);
		connect( &activeGraph, SIGNAL( updateProgressDialog(int) ), progressDialog, SLOT(setValue(int) ) ) ;
		progressDialog->setMinimumDuration(0);
	}
	
	QApplication::setOverrideCursor( QCursor(Qt::WaitCursor) );

	activeGraph.createRandomNetErdos (newNodes, probability);
	QApplication::restoreOverrideCursor();

	if (showProgressBarAct->isChecked() && newNodes > 300)
		progressDialog->deleteLater();	

	fileLoaded=false;
	
	graphChanged();
	
	setWindowTitle("Untitled");
	double threshold = log(newNodes)/newNodes;
	//float avGraphDistance=activeGraph.averageGraphDistance();
	//float clucof=activeGraph.clusteringCoefficient();
	if ( (probability/100 ) > threshold )
		QMessageBox::information(this, "New Random Network",
		tr("Random network created. \n")+ 
		tr("\nNodes: ")+ QString::number(activeNodes())+
		tr("\nEdges: ")+  QString::number( activeLinks()/2.0)+
		//tr("\nAverage path length: ") + QString::number(avGraphDistance)+
		//tr("\nClustering coefficient: ")+QString::number(clucof)+	
		tr("\n\nOn the average, edges should be ") + QString::number(probability * newNodes*(newNodes-1)/100) +
		tr("\nThis graph is almost surely connected because: \nprobability > ln(n)/n, that is: \n") + QString::number(probability/100)+ 
		tr(" bigger than ")+ QString::number(threshold) , "OK",0);

	else 
		QMessageBox::information(this, "New Random Network",
		tr("Random network created. \n")+ 
		tr("\nNodes: ")+ QString::number(activeNodes())+
		tr("\nEdges: ")+  QString::number( activeLinks()/2.0)+
		//tr("\nAverage path length: ") + QString::number(avGraphDistance)+
		//tr("\nClustering coefficient: ")+QString::number(clucof)+
 		tr("\n\nOn the average, edges should be ") +QString::number(probability * newNodes*(newNodes-1)/100) +
		tr("\nThis graph is almost surely not connected because: \nprobability < ln(n)/n, that is: \n") +
		QString::number(probability/100)+ " smaller than "+ QString::number(threshold) , "OK",0);

	statusMessage( "Random network created. ");

}













/**
	Creates a pseudo-random network where every node has the same degree 
*/
void MainWindow::slotCreateSameDegreeRandomNetwork(){
	bool ok;
	statusMessage( "You have selected to create a pseudo-random network where each node has the same degree. ");
	int newNodes=( QInputDialog::getInteger(this, "Create same degree network", tr("This will create a same degree network. \nPlease enter the number of nodes you want:"),1, 1, maxNodes, 1, &ok ) ) ;
	if (!ok) { 
		statusMessage( "You did not enter an integer. Aborting.");
		return;
	}
	int degree = QInputDialog::getInteger(this,"Create same degree network...", "Now, select an even number d. \nThis will be the number of links of each node:", 2, 2, newNodes-1, 2, &ok);
	if ( (degree% 2)==1 ) {
		QMessageBox::critical(this, "Error",tr(" Sorry. I cannot create such a network. Links must be even number"), "OK",0);
		return;
	}
	statusMessage( "Erasing any existing network. ");
	initNet();  
	makeThingsLookRandom();  
	statusMessage( "Creating a pseudo-random network where each node has the same degree... ");

	if (showProgressBarAct->isChecked() && newNodes > 300){
		progressDialog= new QProgressDialog("Creating random network. Please wait (or disable me from Options > View > ProgressBar, next time ;)).", "Cancel", 0, (int) (newNodes+newNodes), this);
		progressDialog -> setWindowModality(Qt::WindowModal);
		connect( &activeGraph, SIGNAL( updateProgressDialog(int) ), progressDialog, SLOT(setValue(int) ) ) ;
		progressDialog->setMinimumDuration(0);
	}

	QApplication::setOverrideCursor( QCursor(Qt::WaitCursor) );

	activeGraph.createSameDegreeRandomNetwork (newNodes, degree);

	QApplication::restoreOverrideCursor();

	if (showProgressBarAct->isChecked() && newNodes > 300)
		progressDialog->deleteLater();	

	fileLoaded=false;
	
	graphChanged();
	setWindowTitle("Untitled");
	statusMessage( "Uniform random network created: "+QString::number(activeNodes())+" Nodes, "+QString::number( activeLinks())+" Links");

}


void MainWindow::slotCreateGaussianRandomNetwork(){
	graphChanged();

}



void MainWindow::slotCreateSmallWorldRandomNetwork(){
	bool ok=false;
	statusMessage( "You have selected to create a small world network.");
	int newNodes=( QInputDialog::getInteger(this, "Create small world", 
			tr("This will create a small world network, \n")+
			tr("that is an undirected graph with N nodes and N*d/2 edges,\n")+
			tr("where d is the mean edge degree.\n")+
			tr("Please enter the number N of nodes you want:"),
			1, 1, maxNodes, 1, &ok ) ) ;
	if (!ok) { 
		statusMessage( "You did not enter an integer. Aborting.");
		return;
	}
	int degree = QInputDialog::getInteger(this,"Create small world...",
			 tr("Now, enter an even number d. \n")+
			 tr("This is the mean edge degree each new node will have:"), 
			 2, 2, newNodes-1, 2, &ok);
	if ( (degree% 2)==1 ) {
		QMessageBox::critical(this, "Error",tr(" Sorry. I cannot create such a network. Links must be even number"), "OK",0);
		return;
	}
	double beta = QInputDialog::getDouble(this,"Create small world...",
			 tr("Now, enter a parameter beta. \n")+
			 tr("This is the edge rewiring probability:"), 
			 0.6, 0.00, 1.00, 2, &ok);

	statusMessage( tr("Erasing any existing network. "));
	initNet();  
	makeThingsLookRandom();  
	statusMessage( tr("Creating small world. Please wait..."));
	double x0=scene->width()/2.0;
	double y0=scene->height()/2.0;
	double radius=(graphicsWidget->height()/2.0)-50;          //pixels

	if (showProgressBarAct->isChecked() && newNodes > 300){
		progressDialog= new QProgressDialog(
			tr("Creating random network. Please wait \n (or disable me from Options > View > ProgressBar, next time )."), 
			"Cancel", 0, (int) (newNodes+newNodes), this);
		progressDialog -> setWindowModality(Qt::WindowModal);
		connect( &activeGraph, SIGNAL( updateProgressDialog(int) ), progressDialog, SLOT(setValue(int) ) ) ;
		progressDialog->setMinimumDuration(0);
	}
	QApplication::setOverrideCursor( QCursor(Qt::WaitCursor) );
	activeGraph.createRandomNetSmallWorld(newNodes, degree, beta, x0, y0, radius);
	QApplication::restoreOverrideCursor();

	if (showProgressBarAct->isChecked() && newNodes > 300 )
		progressDialog->deleteLater();	

	fileLoaded=false;

	graphChanged();
	setWindowTitle("Untitled");
	statusMessage( tr("Small world random network created: ")+QString::number(activeNodes())+" nodes, "+QString::number( activeLinks())+" links");
	//float avGraphDistance=activeGraph.averageGraphDistance();
	//float clucof=activeGraph.clusteringCoefficient();
	QMessageBox::information(this, "New Small World",
		tr("Small world network created.\n")+ 
		tr("\nNodes: ")+ QString::number(activeNodes())+
		tr("\nEdges: ")+  QString::number( activeLinks()/2.0)
		//+  tr("\nAverage path length: ") + QString::number(avGraphDistance)
		//+ tr("\nClustering coefficient: ")+QString::number(clucof)	
		 , "OK",0);
		
}





/**
	Creates a lattice network, i.e. a connected network where every node
	has the same degree and is linked with its neighborhood.
*/
void MainWindow::slotCreateRandomNetRingLattice(){
	bool ok;
	statusMessage( "You have selected to create a ring lattice network. ");
	int newNodes=( QInputDialog::getInteger(this, "Create ring lattice", tr("This will create a ring lattice network, where each node has degree d:\n d/2 edges to the right and d/2 to the left.\n Please enter the number of nodes you want:"),1, 1, maxNodes, 1, &ok ) ) ;
	if (!ok) { 
		statusMessage( "You did not enter an integer. Aborting.");
		return;
	}
	int degree = QInputDialog::getInteger(this,"Create ring lattice...", "Now, enter an even number d. \nThis is the total number of links each new node will have:", 2, 2, newNodes-1, 2, &ok);
	if ( (degree% 2)==1 ) {
		QMessageBox::critical(this, "Error",tr(" Sorry. I cannot create such a network. Links must be even number"), "OK",0);
		return;
	}

	statusMessage( "Erasing any existing network. ");
	initNet();  
	makeThingsLookRandom();  
	statusMessage( "Creating ring lattice network. Please wait...");
	double x0=scene->width()/2.0;
	double y0=scene->height()/2.0;
	double radius=(graphicsWidget->height()/2.0)-50;          //pixels

	if (showProgressBarAct->isChecked() && newNodes > 300){
		progressDialog= new QProgressDialog("Creating random network. Please wait (or disable me from Options > View > ProgressBar, next time ;)).", "Cancel", 0, (int) (newNodes+newNodes), this);
		progressDialog -> setWindowModality(Qt::WindowModal);
		connect( &activeGraph, SIGNAL( updateProgressDialog(int) ), progressDialog, SLOT(setValue(int) ) ) ;
		progressDialog->setMinimumDuration(0);
	}
	
	QApplication::setOverrideCursor( QCursor(Qt::WaitCursor) );

	activeGraph.createRandomNetRingLattice(newNodes, degree, x0, y0, radius );

	QApplication::restoreOverrideCursor();

	if (showProgressBarAct->isChecked() && newNodes > 300)
		progressDialog->deleteLater();	

	fileLoaded=false;
	
//	graphChanged();
	
	statusMessage( "Ring lattice random network created: "+QString::number(activeNodes())+" nodes, "+QString::number( activeLinks())+" links");
		
	setWindowTitle("Untitled");
	//float avGraphDistance=activeGraph.averageGraphDistance();
	//float clucof=activeGraph.clusteringCoefficient();
	QMessageBox::information(this, "Ring Lattice",
		tr("Ring lattice network created.\n")+ 
		tr("\nNodes: ")+ QString::number(activeNodes())+
		tr("\nEdges: ")+  QString::number( activeLinks()/2.0) 
		// + tr("\nAverage path length: ") + QString::number(avGraphDistance)
		//+ tr("\nClustering coefficient: ")+QString::number(clucof)	
		 , "OK",0);	
}







/**
*	Shows a dialog from where the user   
*	creates a new network by crawling a given website 
*/ 
void MainWindow::slotShowWebCrawlerDialog() {
	qDebug () << "MW: slotShowWebCrawlerDialog() - sending canvasWidth and Height";
	activeGraph.setCanvasDimensions(graphicsWidget->width(), graphicsWidget->height());

	m_WebCrawlerDialog.exec() ;
}






/**
*	Called from m_WebCrawlerDialog
*   Clears the loaded network (saving if needed)    
*	then passes parameters to webCrawl of ActiveGraph class.  
*/ 
void MainWindow::slotWebCrawl(QString  seed, int maxNodes, int maxRecursion,  bool goOut ) {
	this->slotFileClose();
	activeGraph.webCrawl( seed, maxNodes, maxRecursion,  goOut ) ;
}



/**
	 Calls GW: findNode() to find a node by its number or label. The node is then marked.
*/
void MainWindow::slotFindNode(){
	qDebug ("MW: slotFindNode()");
	if (!fileLoaded && !networkModified  ) {
		QMessageBox::critical( this, tr("Find Node"),
				tr("No nodes present! \nLoad a network file first or create some nodes..."),
				 tr("OK"),0 );
		statusMessage(  QString(tr("Nothing to find!"))  );
		return;
	}

	if ( markedNodeExists ) {				// if a node has been already marked
		graphicsWidget->setMarkedNode(""); 	// call setMarkedNode to just unmark it.
		markedNodeExists=false;
		statusMessage( tr("Node unmarked.") );
		return;								// and return to MW
	}

	bool ok=false;
	QString nodeText = QInputDialog::getText(this, tr("Find Node"), 
					tr("Enter node label or node number:"), 
					QLineEdit::Normal,QString::null, &ok );
	if (!ok) {
		statusMessage( tr("Find node operation cancelled.") );
		return;
	}
	
	else {
		if	( graphicsWidget->setMarkedNode(nodeText) ) {
			markedNodeExists=true;
			statusMessage( tr("Node found and marked. Press Ctrl+F again to unmark...") );
		}
		else {
			QMessageBox::information(this, tr("Find Node"), 
			tr("Sorry. There is no such node in this network. \n Try again."), "OK",0);	
		}
	}
}



/*
 * Called by Graph to update what the selected node is.
 */
void MainWindow::selectedNode (const int vertex){
	clickedJimNumber=vertex;
}



/**
	 Popups a context menu with some options when the user right-clicks on a node
*/
void MainWindow::openNodeContextMenu() {
	clickedJimNumber=clickedJim->nodeNumber();
	qDebug("MW: openNodeContextMenu() for node %i at %i, %i",clickedJimNumber, QCursor::pos().x(), QCursor::pos().y());

	QMenu *nodeContextMenu = new QMenu(QString::number(clickedJimNumber), this);
	Q_CHECK_PTR( nodeContextMenu );  //displays "out of memory" if needed

	nodeContextMenu -> addAction(addLinkAct);
	nodeContextMenu -> addAction(removeNodeAct );
	QMenu *options=new QMenu(tr("Options"), this);
	nodeContextMenu -> addMenu( options );
	options -> addAction( changeNodeLabelAct );
	options -> addAction( changeNodeSizeAct );
	options -> addAction( changeNodeValueAct );
	options -> addAction( changeNodeColorAct );
	options -> addAction( changeNodeBoxAct );
	options -> addAction( changeNodeCircleAct );
	options -> addAction( changeNodeDiamondAct );
	options -> addAction( changeNodeEllipseAct);
	options -> addAction( changeNodeTriangleAct );
	//QCursor::pos() is good only for menus not related with node coordinates
	nodeContextMenu -> exec(QCursor::pos() );
	delete  nodeContextMenu;
	clickedJimNumber=-1;    //undo node selection
}



/**
	 Popups a context menu with some options when the user right-clicks on a link
*/
void MainWindow::openLinkContextMenu() {
	int source=clickedLink->sourceNodeNumber();
	int target=clickedLink->targetNodeNumber();
	qDebug("MW: openLinkContextMenu() for edge %i-%i at %i, %i",source, target, QCursor::pos().x(), QCursor::pos().y());
	QString edgeName=QString::number(source)+QString("-")+QString::number(target);
	//make the menu
	QMenu *linkContextMenu = new QMenu(edgeName, this);
	linkContextMenu -> addAction( removeLinkAct );
	linkContextMenu -> addAction( changeLinkWeightAct );
	linkContextMenu -> addAction( changeLinkColorAct );
	linkContextMenu -> exec(QCursor::pos() );
	delete  linkContextMenu;
}

/**
	 Popups a context menu with some options when the user right-clicks on the scene
*/
void MainWindow::openContextMenu( const QPointF &mPos) {
	cursorPosGW=mPos;
	QMenu *contextMenu = new QMenu("Link Menu",this);
	Q_CHECK_PTR( contextMenu );  //displays "out of memory" if needed
	contextMenu -> addAction( addNodeAct );
	QMenu *options=new QMenu("Options", this);
	contextMenu -> addMenu(options );
	options -> addAction(changeBackColorAct  );
	options -> addAction(changeAllNodesSizeAct );
	options -> addAction(changeAllNodesShapeAct  );
	options -> addAction(changeAllNodesColorAct );
	options -> addAction(changeAllLinksColorAct  );
	options -> addAction (displayNodeNumbersAct);
	options -> addAction (displayNodeLabelsAct);
	//QCursor::pos() is good only for menus not related with node coordinates
	contextMenu -> exec(QCursor::pos() );
	delete  contextMenu;
	cursorPosGW=QPoint(-1,-1);
}







/**
*	A slot activated when something has been changed in the graph.
	Makes the fileSave icon active and refreshes any LCD values. 
	Also called from graphicsWidget.
*/
void MainWindow::graphChanged(){
	qDebug("MW: graphChanged");
	networkModified=true;
	fileSave->setIcon(QIcon(":/images/save.png"));
	fileSave->setEnabled(true);
	
	nodesLCD->display(activeGraph.vertices());
	edgesLCD->display(activeGraph.totalEdges());
	densityLCD->display( activeGraph.density() );
}



/**
*	When the user clicks on a node, displays some information about it on the status bar.
*/
void MainWindow::nodeInfoStatusBar ( Node *jim) {
	qDebug ("MW: NodeInfoStatusBar()");	
	linkClicked=false;
	nodeClicked=true;
	clickedJim=jim;
	clickedJimNumber=clickedJim->nodeNumber();
	int inLinks=activeGraph.edgesTo(clickedJimNumber);
	int outLinks=activeGraph.edgesFrom(clickedJimNumber);
	selectedNodeLCD->display (clickedJimNumber);
	inLinksLCD->display (inLinks);
	outLinksLCD->display (outLinks);
	clucofLCD->display(activeGraph.clusteringCoefficient(clickedJimNumber));
	
	statusMessage(  QString(tr("(%1, %2);  Node %3, with label %4, "
		"has %5 in-Links and %6 out-Links.")).arg( ceil( clickedJim->x() ) )
		.arg( ceil( clickedJim->y() )).arg( clickedJimNumber ).arg( clickedJim->labelText() )
		.arg(inLinks).arg(outLinks) );
	clickedJimNumber=-1;
}



/**
*	When the user clicks on a link, displays some information about it on the status bar.
*/
void MainWindow::linkInfoStatusBar (Edge* link) {
	clickedLink=link;
	linkClicked=true;
	nodeClicked=false;
	statusMessage(  QString(tr("Link between node %1 and node %2, weight %3 and color %4.")).arg( link->sourceNodeNumber() ).arg(link->targetNodeNumber()).arg(link->weight()).arg(link->color() ) );
}







/**
* 	Deletes a node and the attached objects (links, etc).
*	It deletes clickedJim (signal from GraphicsView or set by another function) 
*	or else asks for a nodeNumber to remove. The nodeNumber is doomedJim.
	Called from nodeContextMenu
*/
void MainWindow::slotRemoveNode() {
	qDebug("MW: slotRemoveNode()");
	if (!activeGraph.vertices())  {
		QMessageBox::critical(this, "Error",tr("Nothing to do! \nLoad a network file or add some nodes first."), "OK",0);
		statusMessage( tr("Nothing to remove.")  );
		return;
	}
	int doomedJim=-1, min=-1, max=-1;
	bool ok=false; 

	min = activeGraph.firstVertexNumber();
	max = activeGraph.lastVertexNumber();
	qDebug("MW: min is %i and max is %i", min, max);
	if (min==-1 || max==-1 ) {
		qDebug("ERROR in finding min max nodeNumbers. Abort");
		return;
	}
	else if (clickedJimNumber >= 0 && clickedJimNumber<= max ) { 
		doomedJim=clickedJimNumber ;
	}
	else if (clickedJimNumber == -1 ) {
		doomedJim =  QInputDialog::getInteger(this,"Remove node",tr("Choose a node to remove between ("
			+ QString::number(min).toAscii()+"..."+QString::number(max).toAscii()+"):"),min, 1, max, 1, &ok);
		if (!ok) {
			statusMessage( "Remove node operation cancelled." );
			return;
		}
	}	
	qDebug ("MW: removing vertice with number %i from Graph", doomedJim);
	activeGraph.removeVertex(doomedJim);
	clickedJimNumber=-1;
	graphChanged();
	qDebug("MW: removeNode() completed. Node %i removed completely.",doomedJim);
	statusMessage( tr("Node removed completely. Ready. ") );
}





/**
*	Adds a new link between two nodes specified by the user.
	Called when user clicks on the MW button "Add Link".
*/
void MainWindow::slotAddLink(){
	qDebug ("MW: slotAddLink()");
	if (!fileLoaded && !networkModified )  {
		QMessageBox::critical(this, "Error",tr("Nothing to link to! \nCreate some nodes first."), "OK",0);
		statusMessage( tr("There are no nodes yet...")  );
		return;
	}

	int sourceNode=-1, targetNode=-1, sourceIndex=-1, targetIndex=-1;
	float weight=1; 	//weight of this new edge should be one...
	bool ok=false;
	int min=activeGraph.firstVertexNumber();
	int max=activeGraph.lastVertexNumber();

	if (min==max) return;		//if there is only one node -> no link 

	if (clickedJimNumber == -1) {
		sourceNode=QInputDialog::getInteger(this, "Create new link, Step 1",tr("This will draw a new link between two nodes. \nEnter source node ("+QString::number(min).toAscii()+"..."+QString::number(max).toAscii()+"):"), min, 1, max , 1, &ok ) ;
		if (!ok) {
			statusMessage( "Add link operation cancelled." );
			return;
		}
	}
	else sourceNode=clickedJimNumber;
	
	if ( (sourceIndex =activeGraph.hasVertex(sourceNode)) ==-1 ) {
		statusMessage( tr("Aborting. ")  );
		QMessageBox::critical(this,"Error","No such node.", "OK",0);
		qDebug ("MW: slotAddLink: Cant find sourceNode %i.", sourceNode);
		return;
	}
	
	targetNode=QInputDialog::getInteger(this, "Create new link, Step 2", tr("Source node accepted. \nNow enter target node ("+QString::number(min).toAscii()+"..."+QString::number(max).toAscii()+"):"),min, 1, max , 1, &ok)     ;
	if (!ok) {
		statusMessage( "Add link target operation cancelled." );
		return;
	}
	if ( (targetIndex=activeGraph.hasVertex(targetNode)) ==-1 ) {
		statusMessage( tr("Aborting. ")  );	
		QMessageBox::critical(this,"Error","No such node.", "OK",0);
		qDebug ("MW: slotAddLink: Cant find targetNode %i",targetNode);
		return;
	}
	
	weight=QInputDialog::getDouble(this, "Create new link, Step 3", tr("Source and target nodes accepted. \n Please, enter the weight of new link: "),1.0, -20.0, 20.0, 1, &ok);
	if (!ok) {
		statusMessage( "Add link operation cancelled." );
		return;
	}
	//Check if this link already exists...
	if (activeGraph.hasEdge(sourceNode, targetNode)!=0 ) {
		qDebug("Link exists. Aborting");
		statusMessage( tr("Aborting. ")  );
		QMessageBox::critical(this,"Error","Link already exists.", "OK",0);
		return;
	}

	addLink(sourceNode, targetNode, weight);
	graphChanged();
	statusMessage( tr("Ready. ")  );
}



/** 	
	helper to slotAddLink() above
	Also called from GW::userMiddleClicked() signal when user creates links with middle-clicks
	Calls Graph::createEdge method to add the new edge to the active Graph 
*/
void MainWindow::addLink (int v1, int v2, float weight) {
	qDebug("MW: addLink() - setting user preferences and calling Graph::createEdge(...)");
	bool drawArrows=displayLinksArrowsAct->isChecked();
	int reciprocal=0;
	bool bezier = false;
	activeGraph.createEdge(v1, v2, weight, reciprocal, drawArrows, bezier);
}



/**
*	Erases the clicked link. Otherwise asks the user to specify one link.
*	First deletes arc reference from object nodeVector
*	then deletes arc item from scene
**/
void MainWindow::slotRemoveLink(){ 
	if ( (!fileLoaded && !networkModified) || activeGraph.totalEdges() ==0 )  {
		QMessageBox::critical(this, "Error",tr("No links present! \nLoad a network file or create a new network first."), "OK",0);
		statusMessage( tr("No links to remove - sorry.")  );
		return;
	}

	int min=0, max=0, sourceNode=-1, targetNode=-1;
	bool ok=false;
	min=activeGraph.firstVertexNumber();
	max=activeGraph.lastVertexNumber();

  	if (!linkClicked) {
		sourceNode=QInputDialog::getInteger(this,tr("Remove link"),tr("Source node:  (")+QString::number(min)+"..."+QString::number(max)+"):", min, 1, max , 1, &ok )   ;
		if (!ok) {
			statusMessage( "Remove link operation cancelled." );
			return;
		}

		targetNode=QInputDialog::getInteger(this, tr("Remove link"), tr("Target node:  (")+QString::number(min)+"..."+QString::number(max)+"):",min, 1, max , 1, &ok )   ;
		if (!ok) {
			statusMessage( "Remove link operation cancelled." );
			return;
		}
		if ( activeGraph.hasEdge(sourceNode, targetNode)!=0 ) {
			if (activeGraph.symmetricEdge(sourceNode, targetNode) ) 
				graphicsWidget->unmakeEdgeReciprocal(targetNode, sourceNode);
			graphicsWidget->eraseEdge(sourceNode, targetNode);
			activeGraph.removeEdge(sourceNode, targetNode);
		}
		else {
			QMessageBox::critical(this, "Remove link",tr("There is no such link."), "OK",0);
			statusMessage( tr("There are no nodes yet...")  );
			return;
		}

	}
	else {
		sourceNode = clickedLink->sourceNodeNumber();
		targetNode = clickedLink->targetNodeNumber();
		if (activeGraph.symmetricEdge(sourceNode, targetNode) ) {
			QString s=QString::number(sourceNode);
			QString t=QString::number(targetNode);
			switch (QMessageBox::information( this, tr("Remove link"),
				      tr("This link is reciprocal. \n") +
				      tr("Select what Direction to delete or Both..."),
				      s+" -> "+ t, t+" -> "+s, tr("Both"), 0, 1 ))

				{
					case 0:
						graphicsWidget->removeItem(clickedLink);
						activeGraph.removeEdge(sourceNode, targetNode);
						//make new link
// 						graphicsWidget->unmakeEdgeReciprocal(clickedLink->targetNodeNumber(), clickedLink->sourceNodeNumber());
						//FIXME weight should be the same 
						graphicsWidget->drawEdge(targetNode, sourceNode, 1, false, displayLinksArrowsAct->isChecked(), initLinkColor, false);

						break;
					case 1:
						clickedLink->unmakeReciprocal();  
						//graphicsWidget->removeItem(clickedLink);
						activeGraph.removeEdge(targetNode, sourceNode);
//						graphicsWidget->drawEdge(i, j, false, drawArrowsAct->isChecked(), initLinkColor, false);
						break;
					case 2:
						graphicsWidget->removeItem(clickedLink);
						activeGraph.removeEdge(sourceNode, targetNode);
						activeGraph.removeEdge(targetNode, sourceNode);
				}


		}
		else {
			graphicsWidget->removeItem(clickedLink);
			activeGraph.removeEdge(sourceNode, targetNode);

			}

		
	}
	graphChanged();
	qDebug("MW: View items now: %i ", graphicsWidget->items().size());
	qDebug("MW: Scene items now: %i ", scene->items().size());
}




/**
*	Changes the label of the clicked node
*/
void MainWindow::slotChangeNodeLabel(){
	if (!fileLoaded && !networkModified )  {
		QMessageBox::critical(this, "Error",tr("There are no nodes! \nLoad a network file or create a new network first."), "OK",0);
		statusMessage( tr("No nodes created.")  );
		return;
	}
	if (clickedJimNumber==-1) {
		statusMessage( tr("Please click on a node first... ")  );
		return;
	}
	bool ok;
	QString text = QInputDialog::getText(this, "Change node label", tr("Enter new node label:"), QLineEdit::Normal,
	QString::null, &ok );
	if ( ok && !text.isEmpty() ) {
		qDebug()<<"MW: change label to "<< text.toAscii();
		clickedJim->setLabelText(text);
		activeGraph.setVertexLabel( clickedJimNumber, text);
		if (!showLabels()) 
			displayNodeLabelsAct->setChecked(true);
			statusMessage( tr("Changed label to %1. Ready. ").arg(text)  );
			graphChanged();
	} 
	else {
		statusMessage( tr("No label text. Abort. ")  );
	}
}




/**
*	Changes the colour of the clicked node
*/
void MainWindow::slotChangeNodeColor(){
	if (!fileLoaded && !networkModified )  {
		QMessageBox::critical(this, "Error",tr("There are no nodes! \nLoad a network file or create a new network first."), "OK",0);
		statusMessage( tr("No nodes...")  );
		return;
	}

	bool ok;
	if (clickedJimNumber==-1) {
		int min=activeGraph.firstVertexNumber();
		int max=activeGraph.lastVertexNumber();
		long int node=QInputDialog::getInt(this, "Change node color",tr("Select node:  	("+QString::number(min).toAscii()+"..."+QString::number(max).toAscii()+"):"), min, 1, max , 1, &ok)   ;
		statusMessage( tr("Error. ")  );
		if (!ok) {
			statusMessage( "Change clicked node color operation cancelled." );
			return;
		}

		QString newColor = QInputDialog::getItem(this,"Change node color", "Select a  new color:", colorList, 1, true, &ok);
		if (!ok) {
			statusMessage( "Change clicked node color operation cancelled." );
			return;
		}

		if (graphicsWidget->setNodeColor(node, newColor)) {
			activeGraph.setVertexColor( node, newColor);
			graphChanged();
		}
		else
			statusMessage( tr("There is no such link. ") );
		
	}
	else{
		QString nodeColor = QInputDialog::getItem(this,"Change node color", "Select a  color:", colorList, 1, true, &ok);
    		if ( ok ) {
			clickedJim->setColor(nodeColor);
			activeGraph.setVertexColor (clickedJimNumber, nodeColor);
			graphChanged();
			statusMessage( tr("Ready. ") );
    		} 
		else {
		        // user pressed Cancel
			statusMessage( tr("Change node color aborted. ") );
    		}
	}
}



/**
*	Changes the size of the clicked node.  
*/
void MainWindow::slotChangeNodeSize(){
	if (!fileLoaded && !networkModified )  {
		QMessageBox::critical(this, "Error",tr("There are no nodes! \nLoad a network file or create a new network first."), "OK",0);
		statusMessage( tr("Cannot change nothing.")  );
		return;
	}
	if (clickedJimNumber==-1) { 
		statusMessage( tr("Error. ")  );
		return;
	}
	bool ok=false;
	int newSize = QInputDialog::getInteger(this, "Change node size", tr("Change node size to: (1-100)"),initNodeSize, 1, 100, 1, &ok ) ;
	if (!ok) {
		statusMessage( "Change size operation cancelled." );
		return;
	}
	clickedJim->setSize(newSize);
	activeGraph.setVertexSize(clickedJimNumber,newSize);
	graphChanged();
	statusBar()->showMessage (QString(tr("Ready")), statusBarDuration) ;
	return;
}



/**
*	TODO Change the value of the clicked node.  
*/
void MainWindow::slotChangeNodeValue(){
	if (clickedJimNumber==-1) { 
		statusMessage( tr("Error. ")  );
		return;
	}
//	bool ok=false;
	//int newSize =   QInputDialog::getInteger(this, "Change node value", tr("Change node size to: (1-16)"),1, 1, 16, 1, &ok ) ;
//	clickedJim->setSize(newSize);
	graphChanged();
	statusBar()->showMessage (QString(tr("Ready")), statusBarDuration) ;
	return;
}



/**
*	Changes the shape of the clicked node to box
*/
void MainWindow::slotChangeNodeBox(){
	activeGraph.setVertexShape( clickedJim->nodeNumber(), "box");
	clickedJim->setShape("box");
	graphChanged();
}



/**
*	Changes the shape of the clicked node to triangle
*/
void MainWindow::slotChangeNodeTriangle(){
	activeGraph.setVertexShape( clickedJim->nodeNumber(), "triangle");
	clickedJim->setShape("triangle");
	graphChanged();
}



/**
*	Changes the shape of the clicked node to circle
*/
void MainWindow::slotChangeNodeCircle(){
	activeGraph.setVertexShape( clickedJim->nodeNumber(), "circle");
	clickedJim->setShape("circle");
	graphChanged();
}



/**
*	Changes the shape of the clicked node to diamond
*/
void MainWindow::slotChangeNodeDiamond(){
	activeGraph.setVertexShape( clickedJim->nodeNumber(), "diamond");
	clickedJim->setShape("diamond");
	graphChanged();
}



/**
*	Changes the shape of the clicked node to ellipse
*/
void MainWindow::slotChangeNodeEllipse(){
	activeGraph.setVertexShape( clickedJim->nodeNumber(), "ellipse");
	clickedJim->setShape("ellipse");
	graphChanged();
}

 
//TODO slotChangeLinkLabel
void MainWindow::slotChangeLinkLabel(){
	graphChanged();
}



/**
*	Changes the colour of the clicked link. 
*	If no link is clicked, then it asks the user to specify one.
*/
void MainWindow::slotChangeLinkColor(){
	if (!fileLoaded && !networkModified )  {
		QMessageBox::critical(this, "Error",tr("No links here! \nLoad a network file or create a new network first."), "OK",0);
		statusMessage( tr("No links present...")  );
		return;
	}

	int sourceNode=-1, targetNode=-1;
	bool ok=false;
	QString newColor;
	int min=activeGraph.firstVertexNumber();
	int max=activeGraph.lastVertexNumber();
	
  	if (!linkClicked) {	//no edge clicked. Ask user to define an edge.
		sourceNode=QInputDialog::getInteger(this, "Change link color",tr("Select link source node:  ("+QString::number(min).toAscii()+"..."+QString::number(max).toAscii()+"):"), min, 1, max , 1, &ok)   ;
		if (!ok) {
			statusMessage( "Change link color operation cancelled." );
			return;
		}
		targetNode=QInputDialog::getInteger(this, "Change link color...", tr("Select link target node:  ("+QString::number(min).toAscii()+"..."+QString::number(max).toAscii()+"):"),min, 1, max , 1, &ok  )   ;
		if (!ok) {
			statusMessage( "Change link color operation cancelled." );
			return;
		}

		qDebug("source %i target %i",sourceNode, targetNode);

		newColor = QInputDialog::getItem(this , "Change link color....", "Select a  color:", colorList, 1, false, &ok );
		if ( ok ) {
			if (graphicsWidget->setEdgeColor(sourceNode, targetNode, newColor))
				activeGraph.setEdgeColor( sourceNode, targetNode, newColor);
			else
				statusMessage( tr("There is no such link. ") );
		}
		else	
			statusMessage( tr("Change link color cancelled. ") );

	}
	else {	//edge has been clicked. Just ask the color and call the appropriate methods.
		newColor = QInputDialog::getItem(this, "Change link color....", "Select a new color for the clicked link:", colorList, 1, false, &ok );
		if ( ok ) {
			clickedLink->setColor(newColor);
			activeGraph.setEdgeColor( clickedLink->sourceNodeNumber(), clickedLink->targetNodeNumber(), newColor);
			statusMessage( tr("Ready. ")  );
			
		} 
		else {       // user pressed Cancel
			statusMessage( tr("User abort. ")  );
		}
	}
}




/**
*	Changes the weight of the clicked link. 
*	If no link is clicked, asks the user to specify a link.
*/
void MainWindow::slotChangeLinkWeight(){
	if (!fileLoaded && !networkModified )  {
		QMessageBox::critical(this, "Error",tr("There are no links here! \nLoad a network file or create a new network first."), "OK",0);
		statusMessage( tr("No links present...")  );
		return;
	}

	qDebug("MW: slotChangeLinkWeight()");
	int  sourceNode=-1, targetNode=-1;
	float newWeight=1.0;
	int min=activeGraph.firstVertexNumber();
	int max=activeGraph.lastVertexNumber();

	bool ok=false;
	if (!linkClicked) {	
		sourceNode=QInputDialog::getInteger(this, "Change link weight",tr("Select link source node:  ("+QString::number(min).toAscii()+"..."+QString::number(max).toAscii()+"):"), min, 1, max , 1, &ok)   ;
		if (!ok) {
			statusMessage( "Change link weight operation cancelled." );
			return;
		}

		targetNode=QInputDialog::getInteger(this, "Change link weight...", tr("Select link target node:  ("+QString::number(min).toAscii()+"..."+QString::number(max).toAscii()+"):"),min, 1, max , 1, &ok  )   ;
		if (!ok) {
			statusMessage( "Change link weight operation cancelled." );
			return;
		}

		qDebug("source %i target %i",sourceNode, targetNode);
		
		QList<QGraphicsItem *> list=scene->items();	
		for (QList<QGraphicsItem *>::iterator it=list.begin(); it!= list.end() ; it++)
			if ( (*it)->type()==TypeEdge) {
				Edge *link=(Edge*) (*it);
				qDebug ("MW: searching link...");
				if ( link->sourceNodeNumber()==sourceNode && link->targetNodeNumber()==targetNode ) {
					qDebug("MW: link found");
					newWeight=(float) QInputDialog::getDouble(this, 
						"Change link weight...",tr("New link Weight: "), 1, -100, 100 ,1, &ok ) ;
					if (ok) {
						link->setWeight(newWeight);
						link->update();
						activeGraph.setEdgeWeight(sourceNode, targetNode, newWeight);
						statusMessage(  QString(tr("Ready."))  );
						return;
					}
					else {
						statusMessage(  QString(tr("input error. Abort."))  );
						return;
					}
				}
			}
	}
	else {  //linkClicked
		qDebug() << "MW: slotChangeLinkWeight() - a link has already been clicked";
		sourceNode=clickedLink->sourceNodeNumber();
		targetNode=clickedLink->targetNodeNumber();
		if ( activeGraph.symmetricEdge(sourceNode, targetNode) ) {
			QString s=QString::number(sourceNode);
			QString t=QString::number(targetNode);
			switch (QMessageBox::information( this, tr("Change link weight"),
				      tr("This link is reciprocal. \n") +
				      tr("Select what Direction to change or Both..."),
				      s+" -> "+ t, t+" -> "+s, tr("Both"), 0, 1 ))
				{
					case 0:
						qDebug("MW: slotChangeLinkWeight()  real edge %i -> %i", sourceNode, targetNode);
						newWeight=QInputDialog::getDouble(this, 
						"Change link weight...",tr("New link weight: "), 1.0, -20.0, 20.00 ,1, &ok) ;
						if (ok) {
							clickedLink->setWeight(newWeight);
							clickedLink->update();	
							qDebug()<<"MW: newWeight will be "<< newWeight; 
							activeGraph.setEdgeWeight(sourceNode, targetNode, newWeight);
							statusMessage(  QString(tr("Ready."))  );
							return;
						}
						else {
							statusMessage(  QString(tr("Change link weight cancelled."))  );
							return;
						}
						break;
					case 1:
						qDebug("MW: slotChangeLinkWeight() virtual edge %i -> %i",targetNode , sourceNode);
						newWeight=(float) QInputDialog::getDouble(this, 
						"Change link weight...",tr("New link Weight: "), 1, -100, 100 ,1, &ok ) ;
						if (ok) {
							qDebug()<<"MW: newWeight will be "<< newWeight;
							activeGraph.setEdgeWeight( targetNode, sourceNode, newWeight);
							statusMessage(  QString(tr("Ready."))  );								
							return;
						}
						else {
							statusMessage(  QString(tr("Change link weight cancelled."))  );
							return;
						}
						break;
					case 2:
						qDebug("MW: slotChangeLinkWeight()  both directions %i <-> %i",targetNode , sourceNode);
						newWeight=(float) QInputDialog::getDouble(this, 
						"Change link weight...",tr("New link Weight: "), 1, -100, 100 ,1, &ok ) ;

						if (ok) {
							qDebug()<<"MW: Changing first direction. NewWeight will be "<< newWeight;
							activeGraph.setEdgeWeight(sourceNode, targetNode, newWeight);
							qDebug()<<"MW: Changing opposite direction. NewWeight will be "<< newWeight; 
							activeGraph.setEdgeWeight( targetNode, sourceNode, newWeight);
							statusMessage(  QString(tr("Ready."))  );
			 				return;
						}
						else {
							statusMessage(  QString(tr("Change link weight cancelled."))  );
							return;
						}
						break;
				}
		}
		else {
			qDebug("MW: slotChangeLinkWeight()  real edge %i -> %i", sourceNode, targetNode);
			newWeight=QInputDialog::getDouble(this, 
					"Change link weight...",tr("New link weight: "), 1.0, -20.0, 20.00 ,1, &ok) ;
			if (ok) {
				clickedLink->setWeight(newWeight);
				clickedLink->update();	
				qDebug()<<"MW: newWeight will be "<< newWeight; 
				activeGraph.setEdgeWeight(sourceNode, targetNode, newWeight);
				statusMessage(  QString(tr("Ready."))  );
				return;
			}
			else {
				statusMessage(  QString(tr("Change link weight cancelled."))  );
				return;
			}

		}
		linkClicked=false;
	}
	
}




/**
*	Filters Nodes by their value   
	TODO slotFilterNodes
*	
*/
void MainWindow::slotFilterNodes(){

	if (!fileLoaded && !networkModified  )  {
		QMessageBox::critical(this, "Error",tr("Nothing to filter! \nLoad a network file or create a new network. \nThen ask me to compute something!"), "OK",0);

		statusMessage(  QString(tr("Nothing to filter!"))  );
		return;
	}
}

/**
*	Calls Graph::filterOrphanVertices to filter vertices with no links
*/
void MainWindow::slotFilterOrphanNodes(){
	if (!fileLoaded && !networkModified  )  {
		QMessageBox::critical(this, "Error",tr("Nothing to filter! \nLoad a network file or create a new network. \nThen ask me to compute something!"), "OK",0);
		statusMessage(  QString(tr("Nothing to filter!"))  );
		return;
	}
	qDebug()<< "MW: slotFilterOrphanNodes";
	activeGraph.filterOrphanVertices( ! filterOrphanNodesAct->isChecked() );
}


/**
*	Shows a dialog from where the user may  
*	filter edges according to their weight 
*	All edges weighted more (or less) than the specified weight  will be disabled.
*/ 
void MainWindow::slotShowFilterEdgesDialog() {
	if (!fileLoaded && !networkModified  )   {
		statusMessage(  QString(tr("Load a network file first. \nThen you may ask me to compute something!"))  );
		return;
	}
	m_filterEdgesByWeightDialog.exec() ;
}








/**
*	Transforms all nodes to links
	TODO slotTransformNodes2Links
*/
void MainWindow::slotTransformNodes2Links(){
	graphChanged();

}





/**
*	Converts all edges to double edges, so that the network becomes undirected (symmetric adjacency matrix).
*/
void MainWindow::slotSymmetrize(){
	if (!fileLoaded && !networkModified )  {
		QMessageBox::critical(this, "Error",tr("No links here! \nLoad a network file or create a new network first."), "OK",0);
		statusMessage( tr("No links present...")  );
		return;
	}
	qDebug("MW: slotSymmetrize() calling symmetrize");
	activeGraph.symmetrize();
	QMessageBox::information(this, "Symmetrize",tr("All links are reciprocal. \nYour network is symmetric..."), "OK",0);
	statusBar()->showMessage (QString(tr("Ready")), statusBarDuration) ;
}



/**
	TODO slotColorationStrongStructural
*/
void MainWindow::slotColorationStrongStructural() {
}


/**
	TODO slotColorationRegular
*/
void MainWindow::slotColorationRegular() {
}



/**
*	Calls Graph::LayoutRadialCentrality()
*	to reposition all nodes on a circular layout based on their In-Degree Centralities. 
*	More central nodes are closer to the centre
*/
void MainWindow::slotLayoutRandom(){
	if (!fileLoaded && !networkModified  )  {
		QMessageBox::critical(this, "Error",tr("Sorry, I can't follow! \nLoad a network file or create a new network first. \nThen we can talk about layouts!"), "OK",0);
		statusMessage(  QString(tr("Nothing to layout! Are you dreaming?"))  );
		return;
	}
	double maxWidth=graphicsWidget->width();
	double maxHeight=graphicsWidget->height();
	statusMessage(  QString(tr("Randomizing nodes positions. Please wait...")) );
	graphicsWidget->clearBackgrCircles();
	createProgressBar();
	activeGraph.layoutRandom(maxWidth, maxHeight);
	destroyProgressBar();
	statusMessage( tr("Node positions are now randomized.") );	
}


/** 
	TODO slotLayoutRandomCircle
*/
void MainWindow::slotLayoutRandomCircle(){
}





/**
	slotLayoutSpringEmbedder called from menu
*/
void MainWindow::slotLayoutSpringEmbedder(){
	if (!fileLoaded && !networkModified  )  {
		QMessageBox::critical(this, "Error",tr("There are node nodes yet!\nLoad a network file or create a new network first. \nThen we can talk about layouts!"), "OK",0);
		statusMessage( tr("I am really sorry. You must really load a file first... ")  );
		return;
	}
	if (moveSpringEmbedderBx->checkState() == Qt::Unchecked){
		statusMessage( tr("Embedding a spring-gravitational model on the network.... ")  );
		moveSpringEmbedderBx->setCheckState(Qt::Checked);
		statusMessage( tr("Click on the checkbox \"Spring-Embedder\" to stop movement!") );
	}
	else { 
		moveSpringEmbedderBx->setCheckState(Qt::Unchecked);
		statusMessage( tr("Movement stopped!") );
	}
	
}



/** 
	Called from moveSpringEmbedderBx button. 
	Calls Graph::startNodeMovement to embed a spring Embedder layout...
*/
void MainWindow::layoutSpringEmbedder (int state){
	qDebug("MW: layoutSpringEmbedder ()");
	scene->setItemIndexMethod (QGraphicsScene::NoIndex); //best when moving items
	moveFruchtermanBx->setChecked(false);
	activeGraph.nodeMovement(state, 1, graphicsWidget->width(), graphicsWidget->height());
	scene->setItemIndexMethod (QGraphicsScene::BspTreeIndex); //best when not moving items
}




/**
	slotLayoutFruchterman called from menu
*/
void MainWindow::slotLayoutFruchterman(){
	if (!fileLoaded && !networkModified  )  {
		QMessageBox::critical(this, "Error",tr("There are no nodes yet!\nLoad a network file or create a new network first. \nThen we can talk about layouts!"), "OK",0);
		statusMessage( tr("I am really sorry. You must really load a file first... ")  );
		return;
	}
	if (moveFruchtermanBx->checkState() == Qt::Unchecked){
		statusMessage( tr("Embedding a repelling-attracting forces model on the network.... ")  );
		moveFruchtermanBx->setCheckState(Qt::Checked);
		statusMessage( tr("Click on the checkbox \"Fruchterman-Reingold\" to stop movement!") );
	}
	else { 
		moveFruchtermanBx->setCheckState(Qt::Unchecked);
		statusMessage( tr("Movement stopped!") );
	}
	
}


/** 
	Called from moveSpringEmbedderBx button. 
	Calls Graph::startNodeMovement to embed a repelling-attracting forces layout...
*/
void MainWindow::layoutFruchterman (int state){
	qDebug("MW: layoutFruchterman ()");
	moveSpringEmbedderBx->setChecked(false);
	scene->setItemIndexMethod (QGraphicsScene::NoIndex); //best when moving items
	activeGraph.nodeMovement(state, 2, graphicsWidget->width(), graphicsWidget->height());
	scene->setItemIndexMethod (QGraphicsScene::BspTreeIndex); //best when not moving items
}


/** 
	Resizes all nodes according to the amount of their out-Links from other nodes.
*/
void MainWindow::slotLayoutNodeSizeProportionalOutEdges(bool checked){
	if (!fileLoaded && !networkModified  )  {
		QMessageBox::critical(this, "Error",tr("Wake up! \nLoad a network file or create a new network first. \nThen we can talk about layouts!"), "OK",0);
		statusMessage( tr("I am really sorry. You must really load a file first... ")  );
		return;
	}

	qDebug("MW: slotLayoutNodeSizeProportionalOutEdges()");
	QList<QGraphicsItem *> list=scene->items();
	int edges = 0, size = initNodeSize ;
	
	if (checked != true) {
		QApplication::setOverrideCursor( QCursor(Qt::WaitCursor) );
		for (QList<QGraphicsItem *>::iterator it=list.begin(); it!=list.end(); it++)  {
			if ( (*it) -> type() == TypeNode ){
				Node *jim = (Node*) (*it);
				(*jim).setSize(size);
			}
		}
		
		nodeSizeProportionalOutDegreeAct->setChecked(false);
		nodeSizeProportional2OutDegreeBx->setChecked(false);
		QApplication::restoreOverrideCursor();
		return;
	}
	nodeSizeProportionalOutDegreeAct->setChecked(true);
	nodeSizeProportional2OutDegreeBx->setChecked(true);
	statusMessage( tr("Embedding node size model on the network.... ")  );	
	QApplication::setOverrideCursor( QCursor(Qt::WaitCursor) );
	for (QList<QGraphicsItem *>::iterator it=list.begin(); it!=list.end(); it++) {
		if ( (*it) -> type() == TypeNode ){
			Node *jim = (Node*) (*it);
			edges = activeGraph.edgesFrom(  (*jim).nodeNumber() ) ;
			qDebug() << "Node " << (*jim).nodeNumber() <<  " outDegree:  "<<  edges;
			
			if (edges == 0 ) {
				size = initNodeSize; 
			}
			else if (edges == 1 ) {
				size = initNodeSize + 1; 
			}
			else if (edges > 1 && edges <= 2  ) {
				size = initNodeSize + 2; 	
			}
			else if (edges > 2 && edges <= 3  ) {
				size = initNodeSize + 3; 
			}
			else if (edges > 3 && edges <= 4  ) {
				size = initNodeSize + 4; 
			}
			else if (edges > 4 && edges <= 6  ) {
				size = initNodeSize + 4; 
			}
			else if (edges > 5 && edges <= 7  ) {
				size = initNodeSize+5 ; 
			}
			else if (edges > 7 && edges <= 10  ) {
				size = initNodeSize+6 ; 
			}
			else if (edges > 10 && edges <= 15  ) {
				size = initNodeSize+7 ; 
			}
			else if (edges > 15 && edges <= 25  ) {
				size = initNodeSize+8 ; 
			}
			else  if (edges > 25 ) {
				size = initNodeSize+9; 
			}
			qDebug() << "Changing size of " << (*jim).nodeNumber()  << "  to " <<  size;
			(*jim).setSize(size);
		}

	}
	QApplication::restoreOverrideCursor( );

}







/** 
	Resizes all nodes according to the amount of their in-Links from other nodes.
*/
void MainWindow::slotLayoutNodeSizeProportionalInEdges(bool checked){
	if (!fileLoaded && !networkModified  )  {
		QMessageBox::critical(this, "Error",tr("You must be dreaming! \nLoad a network file or create a new network first. \nThen we can talk about layouts!"), "OK",0);
		statusMessage( tr("I am really sorry. You must really load a file first... ")  );
		return;
	}

	qDebug("MW: slotLayoutNodeSizeProportionalInEdges()");
	QList<QGraphicsItem *> list=scene->items();
	int edges = 0, size = initNodeSize ;
	
	if (checked != true) {
		for (QList<QGraphicsItem *>::iterator it=list.begin(); it!=list.end(); it++)  {
			if ( (*it) -> type() == TypeNode ){
				Node *jim = (Node*) (*it);
				(*jim).setSize(size);
			}
		}
		nodeSizeProportionalInDegreeAct->setChecked(false);
		nodeSizeProportional2InDegreeBx->setChecked(false);
		return;
	}
	nodeSizeProportionalInDegreeAct->setChecked(true);
	nodeSizeProportional2InDegreeBx->setChecked(true);
	statusMessage( tr("Embedding node size model on the network.... ")  );	
	for (QList<QGraphicsItem *>::iterator it=list.begin(); it!=list.end(); it++) {
		if ( (*it) -> type() == TypeNode ){
			Node *jim = (Node*) (*it);
			edges = activeGraph.edgesTo(  (*jim).nodeNumber() ) ;
			qDebug() << "Node " << (*jim).nodeNumber() << " inDegree:  " <<  edges;
			
			if (edges == 0 ) {
				size = initNodeSize; 
			}
			else if (edges == 1 ) {
				size = initNodeSize + 1; 
			}
			else if (edges > 1 && edges <= 2  ) {
				size = initNodeSize + 2; 	
			}
			else if (edges > 2 && edges <= 3  ) {
				size = initNodeSize + 3; 
			}
			else if (edges > 3 && edges <= 4  ) {
				size = initNodeSize + 4; 
			}
			else if (edges > 4 && edges <= 6  ) {
				size = initNodeSize + 4; 
			}
			else if (edges > 5 && edges <= 7  ) {
				size = initNodeSize+5 ; 
			}
			else if (edges > 7 && edges <= 10  ) {
				size = initNodeSize+6 ; 
			}
			else if (edges > 10 && edges <= 15  ) {
				size = initNodeSize+7 ; 
			}
			else if (edges > 15 && edges <= 25  ) {
				size = initNodeSize+8 ; 
			}
			else  if (edges > 25 ) {
				size = initNodeSize+9; 
			}
			qDebug() << "Changing size of " <<  (*jim).nodeNumber() << " to " <<  size;
			(*jim).setSize(size);
		}

	}

}




/**
*	Calls Graph::LayoutRadialCentrality()
*	to reposition all nodes on a circular layout based on their In-Degree Centralities. 
*	More central nodes are closer to the centre
*/
void MainWindow::slotLayoutRadialCentralityInDegree(){
	if (!fileLoaded && !networkModified  )  {
		QMessageBox::critical(this, "Error",tr("Sorry, I can't follow! \nLoad a network file or create a new network first. \nThen we can talk about layouts!"), "OK",0);
		statusMessage(  QString(tr("Nothing to layout! Are you dreaming?"))  );
		return;
	}
	double x0=scene->width()/2.0;
	double y0=scene->height()/2.0;
	double maxRadius=(graphicsWidget->height()/2.0)-50;          //pixels
	
	statusMessage(  QString(tr("Calculating new nodes positions. Please wait...")) );
	graphicsWidget->clearBackgrCircles();
	createProgressBar();
	activeGraph.layoutRadialCentrality(x0, y0, maxRadius,1);
	destroyProgressBar();
	statusMessage( tr("Nodes in inner circles have greater In-Degree Centrality.") );	
}


/**
*	Calls Graph::layoutRadialCentrality()
*	to reposition all nodes on a radial layout according to their out-degree Centralities. 
*	More central nodes are closer to the centre
*/
void MainWindow::slotLayoutRadialCentralityOutDegree(){
	if (!fileLoaded && !networkModified  )  {
		QMessageBox::critical(this, "Error",tr("Load a network file or create a new network first!"), "OK",0);
		statusMessage(  QString(tr("Nothing to layout! Are you dreaming?"))  );
		return;
	}
	double x0=scene->width()/2.0;
	double y0=scene->height()/2.0;
	double maxRadius=(graphicsWidget->height()/2.0)-50;          //pixels
	
	statusMessage(  QString(tr("Calculating new nodes positions. Please wait...")) );
	graphicsWidget->clearBackgrCircles();
	createProgressBar();
        activeGraph.layoutRadialCentrality(x0, y0, maxRadius,2);
	destroyProgressBar();
	statusMessage( tr("Nodes in inner circles have greater Out-Degree Centrality. ") );	
}




/**
*	Calls Graph::layoutRadialCentrality()
*	to reposition all nodes on a circular layout based on their Closeness Centralities. 
*	More central nodes are closer to the centre
*/
void MainWindow::slotLayoutRadialCentralityCloseness(){
	if (!fileLoaded && !networkModified  )  {
		QMessageBox::critical(this, "Error",tr("Sorry, there are no nodes yet!\nLoad a network file or create a new network first. \nThen we can talk about layouts!"), "OK",0);

		statusMessage(  QString(tr("Nothing to layout! Are you dreaming?"))  );
		return;
	}
	double x0=scene->width()/2.0;
	double y0=scene->height()/2.0;
	double maxRadius=(graphicsWidget->height()/2.0)-50;          //pixels
	createProgressBar();
	statusMessage(  QString(tr("Calculating new nodes positions. Please wait...")) );
	graphicsWidget->clearBackgrCircles();
	activeGraph.layoutRadialCentrality(x0, y0, maxRadius,3);
	destroyProgressBar();
	statusMessage( tr("Nodes in inner circles have greater Closeness Centrality. ") );	
}





/**
*	Calls Graph::LayoutRadialCentrality()
*	to reposition all nodes on a circular layout based on their Betweeness Centralities. 
*	More central nodes are closer to the centre
*/
void MainWindow::slotLayoutRadialCentralityBetweeness(){
	if (!fileLoaded && !networkModified  )  {
		QMessageBox::critical(this, "Error",tr("No nodes yet!\nLoad a network file or create a new network first. \nThen we can talk about layouts!"), "OK",0);

		statusMessage(  QString(tr("Nothing to layout! Are you dreaming?"))  );
		return;
	}
	double x0=scene->width()/2.0;
	double y0=scene->height()/2.0;
	double maxRadius=(graphicsWidget->height()/2.0)-50;          //pixels
	
	statusMessage(  QString(tr("Calculating new nodes positions. Please wait...")) );
	graphicsWidget->clearBackgrCircles();
	createProgressBar();
	activeGraph.layoutRadialCentrality(x0, y0, maxRadius,4);
	destroyProgressBar();
	statusMessage( tr("Nodes in inner circles have greater Betweeness Centrality. ") );	
}






/**
*	Calls Graph::LayoutRadialCentrality()
*	to reposition all nodes on a circular layout based on their Stress Centralities. 
*	More central nodes are closer to the centre
*/
void MainWindow::slotLayoutRadialCentralityStress(){
	if (!fileLoaded && !networkModified  )  {
		QMessageBox::critical(this, "Error",tr("Nothing to do!\nLoad a network file or create a new network first. \nThen we can talk about layouts!"), "OK",0);
		statusMessage(  QString(tr("Nothing to layout! Are you dreaming?"))  );
		return;
	}
	double x0=scene->width()/2.0;
	double y0=scene->height()/2.0;
	double maxRadius=(graphicsWidget->height()/2.0)-50;          //pixels

	statusMessage(  QString(tr("Calculating new nodes positions. Please wait...")) );
	graphicsWidget->clearBackgrCircles();
	createProgressBar();
	activeGraph.layoutRadialCentrality(x0, y0, maxRadius,5);
	destroyProgressBar();
	statusMessage( tr("Nodes in inner circles have greater Stress Centrality. ") );	
}




/**
*	Calls Graph::LayoutRadialCentrality()
*	to reposition all nodes on a circular layout based on their Graph Centralities. 
*	More central nodes are closer to the centre
*/
void MainWindow::slotLayoutRadialCentralityGraph(){
	if (!fileLoaded && !networkModified  )  {
		QMessageBox::critical(this, "Error",tr("Nothing to do here!\nLoad a network file or create a new network first. \nThen we can talk about layouts!"), "OK",0);
		statusMessage(  QString(tr("Nothing to layout! Are you dreaming?"))  );
		return;
	}
	double x0=scene->width()/2.0;
	double y0=scene->height()/2.0;
	double maxRadius=(graphicsWidget->height()/2.0)-50;          //pixels
	
	statusMessage(  QString(tr("Calculating new nodes positions. Please wait...")) );
	graphicsWidget->clearBackgrCircles();
	createProgressBar();
	activeGraph.layoutRadialCentrality(x0, y0, maxRadius,6);
	destroyProgressBar();
	statusMessage( tr("Nodes in inner circles have greater Graph Centrality. ") );	

}



/**
*	Calls Graph::layoutRadialCentrality()
*	to reposition all nodes on a circular layout based on their Eccentricities 
*	More central nodes are closer to the centre
*/
void MainWindow::slotLayoutRadialCentralityEccentr(){
	if (!fileLoaded && !networkModified  )  {
		QMessageBox::critical(this, "Error",tr("Nothing to do!\nLoad a network file or create a new network first. \nThen we can talk about layouts!"), "OK",0);
		statusMessage(  QString(tr("Nothing to layout! Are you dreaming?"))  );
		return;
	}
	double x0=scene->width()/2.0;
	double y0=scene->height()/2.0;
	double maxRadius=(graphicsWidget->height()/2.0)-50;          //pixels

	statusMessage(  QString(tr("Calculating new nodes positions. Please wait...")) );
	graphicsWidget->clearBackgrCircles();
	createProgressBar();
	activeGraph.layoutRadialCentrality(x0, y0, maxRadius,7);
	destroyProgressBar();
	statusMessage( tr("Nodes in inner circles have greater Eccentricity Centrality. ") );	
}

/**
*	Calls Graph::LayoutRadialCentrality()
*	to reposition all nodes on a circular layout based on their Power Centralities.
*	More central nodes are closer to the centre
*/
void MainWindow::slotLayoutRadialCentralityPower(){
    if (!fileLoaded && !networkModified  )  {
            QMessageBox::critical(this, "Error",tr("Nothing to do!\nLoad a network file or create a new network first. \nThen we can talk about layouts!"), "OK",0);
            statusMessage(  QString(tr("Nothing to layout! Are you dreaming?"))  );
            return;
    }
    double x0=scene->width()/2.0;
    double y0=scene->height()/2.0;
    double maxRadius=(graphicsWidget->height()/2.0)-50;          //pixels

    statusMessage(  QString(tr("Calculating new nodes positions. Please wait...")) );
    graphicsWidget->clearBackgrCircles();
    createProgressBar();
    activeGraph.layoutRadialCentrality(x0, y0, maxRadius,8);
    destroyProgressBar();
    statusMessage( tr("Nodes in inner circles have greater Power Centrality. ") );
}





/**
*	Calls Graph::LayoutRadialCentrality()
*	to reposition all nodes on a circular layout based on their Informational Centralities. 
*	More central nodes are closer to the centre
*/
void MainWindow::slotLayoutRadialCentralityInformation(){
    if (!fileLoaded && !networkModified  )  {
            QMessageBox::critical(this, "Error",tr("Nothing to do!\nLoad a network file or create a new network first. \nThen we can talk about layouts!"), "OK",0);
            statusMessage(  QString(tr("Nothing to layout! Are you dreaming?"))  );
            return;
    }
    double x0=scene->width()/2.0;
    double y0=scene->height()/2.0;
    double maxRadius=(graphicsWidget->height()/2.0)-50;          //pixels

    statusMessage(  QString(tr("Calculating new nodes positions. Please wait...")) );
    graphicsWidget->clearBackgrCircles();
    createProgressBar();
    activeGraph.layoutRadialCentrality(x0, y0, maxRadius,9);
    destroyProgressBar();
    statusMessage( tr("Nodes in inner circles have greater Information Centrality. ") );
}




/**
*	Calls Graph::layoutLayeredCentrality 
*	to reposition all nodes on different top-down levels according to their 
*	In-Degree Centrality
*	More central nodes are closer to the top of the canvas
*/
void MainWindow::slotLayoutLayeredCentralityInDegree(){
	if (!fileLoaded && !networkModified  )  {
		QMessageBox::critical(this, "Error",tr("Nothing to do!\nLoad a network file or create a new network first. \nThen we can talk about layouts!"), "OK",0);
		statusMessage(  QString(tr("Nothing to layout! Are you dreaming?"))  );
		return;
	}
	double maxWidth=scene->width();
	double maxHeight=scene->height(); //pixels
	
	statusMessage(  QString(tr("Calculating new nodes positions. Please wait...")) );
	graphicsWidget->clearBackgrCircles();
	createProgressBar();
	activeGraph.layoutLayeredCentrality(maxWidth, maxHeight, 1);
	destroyProgressBar();
	statusMessage( tr("Nodes in upper levels have greater In-Degree Centrality. ") );	

}



/**
*	Calls Graph::layoutLayeredCentrality 
*	to reposition all nodes on different top-down levels according to their 
*	Out-Degree Centrality
*	More central nodes are closer to the top of the canvas
*/
void MainWindow::slotLayoutLayeredCentralityOutDegree(){
	if (!fileLoaded && !networkModified  )  {
		QMessageBox::critical(this, "Error",tr("Load a network file or create a new network first. \nThen we can talk about layouts!"), "OK",0);
		statusMessage(  QString(tr("Nothing to layout! Are you dreaming?"))  );
		return;
	}
	double maxWidth=scene->width();
	double maxHeight=scene->height(); //pixels

	statusMessage(  QString(tr("Calculating new nodes positions. Please wait...")) );
	graphicsWidget->clearBackgrCircles();
	createProgressBar();
	activeGraph.layoutLayeredCentrality(maxWidth, maxHeight, 2);
	destroyProgressBar();
	statusMessage( tr("Nodes in upper levels have greater Out-Degree Centrality. ") );	

}


/**
*	Calls Graph::LayoutLayeredCentrality 
*	to reposition all nodes on different top-down levels according to their 
*	Closeness Centrality
*	More central nodes are closer to the top of the canvas

*/
void MainWindow::slotLayoutLayeredCentralityCloseness(){
	if (!fileLoaded && !networkModified  )  {
		QMessageBox::critical(this, "Error",tr("Load a network file or create a new network first. \nThen we can talk about layouts!"), "OK",0);
		statusMessage(  QString(tr("Nothing to layout! Are you dreaming?"))  );
		return;
	}
	double maxWidth=scene->width();
	double maxHeight=scene->height(); //pixels
	
	statusMessage(  QString(tr("Calculating new nodes positions. Please wait..."))  );
	graphicsWidget->clearBackgrCircles();
	createProgressBar();
	activeGraph.layoutLayeredCentrality(maxWidth, maxHeight, 3);
	destroyProgressBar();
	
	statusMessage( tr("Nodes in upper levels have greater Closeness Centrality.") );	
}



/**
*	Calls Graph::LayoutLayeredCentrality 
*	to reposition all nodes on different top-down levels according to their 
*	Betweeness Centrality
*	More central nodes are closer to the top of the canvas
*/
void MainWindow::slotLayoutLayeredCentralityBetweeness(){
	if (!fileLoaded && !networkModified  )  {
		QMessageBox::critical(this, "Error",tr("Nothing to do!\nLoad a network file or create a new network first. \nThen we can talk about layouts!"), "OK",0);
		statusMessage(  QString(tr("Nothing to layout! Are you dreaming?"))  );
		return;
	}
	double maxWidth=scene->width();
	double maxHeight=scene->height(); //pixels
	
	statusMessage(  QString(tr("Calculating new nodes positions. Please wait...")) );
	graphicsWidget->clearBackgrCircles();
	createProgressBar();
	activeGraph.layoutLayeredCentrality(maxWidth, maxHeight, 4);
	destroyProgressBar();	
	statusMessage( tr("Nodes in upper levels have greater Betweeness Centrality. ") );	
}


/**
	TODO slotLayoutLayeredCentralityInformational
*/
void MainWindow::slotLayoutLayeredCentralityInformation(){
}







/**
*	Returns the amount of active links on the scene.
*/
int MainWindow::activeLinks(){
	qDebug ("activeLinks()");
	totalLinks=activeGraph.totalEdges();
	return totalLinks;
}








/**
*	Returns the amount of active nodes on the scene.
*/
int MainWindow::activeNodes(){ 
	return activeGraph.vertices();
}







/**
*	Displays a box informing the user about the symmetry or not of the adjacency matrix
*/

void MainWindow::slotCheckSymmetry(){
	if (!fileLoaded && !networkModified  )   {
		QMessageBox::critical(this, "Error",tr("There are no nodes!\nLoad a network file or create a new network. \nThen ask me to compute something!"), "OK",0);
		statusMessage(  QString(tr("There is no network!"))  );
		return;
	}
	if (activeGraph.isSymmetric())
		QMessageBox::information(this, "Network Symmetry", tr("Adjacency matrix symmetry = YES "),"OK",0);
	else
		QMessageBox::information(this, "Network Symmetry", tr("Adjacency matrix symmetry = NO "),"OK",0);
	
	statusMessage (QString(tr("Ready")) );

}


void MainWindow::slotInvertAdjMatrix(){
    if ( !fileLoaded && !networkModified) {
	    QMessageBox::critical (this, "Error",
	    tr("Empty network! \nLoad a network file or create something by double-clicking on the canvas!"), "OK",0);

	    statusMessage(  tr("Nothing to show!") );
	    return;
    }
    int aNodes=activeNodes();
    statusBar() ->  showMessage ( QString (tr ("inverting adjacency adjacency matrix of %1 nodes")).arg(aNodes) );
    qDebug ("MW: calling Graph::writeInvertAdjacencyMatrix with %i nodes", aNodes);
    char fn[]= "invert-adjacency-matrix.dat";

    activeGraph.writeInvertAdjacencyMatrix(fn, networkName.toLocal8Bit()) ;

    //Open a text editor window for the new file created by graph class
    QString qfn=QString::fromLocal8Bit("invert-adjacency-matrix.dat");
    TextEditor *ed = new TextEditor(fn);
    tempFileNameNoPath=qfn.split( "/");
    ed->setWindowTitle(tr("View Adjacency Matrix - ") + tempFileNameNoPath.last());
    ed->show();

}



/**
*  Displays the graph distance (geodesic distance) between two user-specified nodes
	This is the length of the shortest path between them.
*/
void MainWindow::slotGraphDistance(){
	if (!fileLoaded && !networkModified  )  {
		QMessageBox::critical(this, "Error",tr("There are no nodes!\nLoad a network file or create a new network. \nThen ask me to compute something!"), "OK",0);
		statusMessage(  QString(tr("There are no nodes. Nothing to do..."))  );
		return;
	}
	bool ok=false;
	long int  min=1, max=1, i=-1, j=-1;
	QList<QGraphicsItem *> list=scene->items();
	for (QList<QGraphicsItem *> ::iterator it=list.begin(); it!=list.end(); it++) {
		if ( (*it) -> type() == TypeNode ){
			Node *jim = (Node*) (*it);
			if ( min>jim->nodeNumber() ) min=jim->nodeNumber();
			if ( max<jim->nodeNumber() ) max=jim->nodeNumber();
		}
	}
	i=QInputDialog::getInteger(this, tr("Distance between two nodes"),tr("Select source node:  ("+QString::number(min).toAscii()+"..."+QString::number(max).toAscii()+"):"), min, 1, max , 1, &ok )   ;
	if (!ok) {
		statusMessage( "Distance calculation operation cancelled." );
		return;
	}

	j=QInputDialog::getInteger(this, tr("Distance between two nodes"), tr("Select target node:  ("+QString::number(min).toAscii()+"..."+QString::number(max).toAscii()+"):"),min, 1, max , 1, &ok )   ;
	if (!ok) {
		statusMessage( tr("Distance calculation operation cancelled.") );
		return;
	}

	qDebug() << "source " << i  << " target" <<  j;
		
	if (activeGraph.isSymmetric() && i>j) {
		qSwap(i,j);
	}
	if ( activeGraph.distance(i,j) != 0 )
		QMessageBox::information(this, tr("Distance"), tr("Network distance (")+QString::number(i)+", "+QString::number(j)+") = "+QString::number(activeGraph.distance(i,j))+tr("\nThe nodes are connected."),"OK",0);
	else 
		QMessageBox::information(this, tr("Distance"), tr("Network distance (")+QString::number(i)+", "+QString::number(j)+") = "+QString::number(activeGraph.distance(i,j))+tr("\nThe nodes are not connected."),"OK",0);
}




/**
*  Invokes creation of the matrix of nodes' distances, then displays it.
*/
void MainWindow::slotViewDistanceMatrix(){
	qDebug("MW: slotViewDistanceMatrix()");
	if (!fileLoaded && !networkModified  )  {
		QMessageBox::critical(this, "Error",tr("There are no nodes nor links!\nLoad a network file or create a new network. \nThen ask me to compute something!"), "OK",0);
		statusMessage(  QString(tr("Nothing to do!"))  );
		return;
	}
	statusMessage( tr("Creating distance matrix. Please wait...") );	
	char fn[]= "distance-matrix.dat";
	char fn1[]="sigmas-matrix.dat";
	
	createProgressBar();
	
	activeGraph.writeDistanceMatrix(fn, fn1, networkName.toLocal8Bit());

	destroyProgressBar();
	
	//Open a text editor window for the new file created by graph class
	QString qfn1=QString::fromLocal8Bit(fn1);
	TextEditor *ed = new TextEditor(fn);
	TextEditor *ed1 = new TextEditor(fn1);

	ed1->setWindowTitle(tr("Matrix of sigmas "));
	ed->setWindowTitle(tr("Matrix of distances "));
	ed1->show();	
	ed->show();


	
}




/**  Displays the network diameter (largest geodesic) */
void MainWindow::slotDiameter() {
	if (!fileLoaded && !networkModified  )  {
		QMessageBox::critical(this, "Error",tr("There are no nodes nor links!\nLoad a network file or create a new network. \nThen ask me to compute something!"), "OK",0);

		statusMessage(  QString(tr("Cannot find the diameter of nothing..."))  );
		return;
	}
	
	createProgressBar();	

	int netDiameter=activeGraph.diameter();

	destroyProgressBar();

	if (netDiameter > (activeGraph.vertices()-1) ) 
		QMessageBox::information(this, "Diameter", "Network diameter = "+ QString::number(netDiameter)+"  > (vertices()-1).", "OK",0);
	else 
		QMessageBox::information(this, "Diameter", "Network diameter = " + QString::number(netDiameter), "OK",0);
	statusMessage( tr("Diameter calculated. Ready.") );

}





/**  Displays the  average shortest path length (average graph distance) */
void MainWindow::slotAverageGraphDistance() {
	if (!fileLoaded && !networkModified  )  {
		QMessageBox::critical(this, "Error",tr("There are no nodes nor links!\nLoad a network file or create a new network. \nThen ask me to compute something!"), "OK",0);

		statusMessage(  QString(tr("Cannot find the diameter of nothing..."))  );
		return;
	}
			
	createProgressBar();	

	float averGraphDistance=activeGraph.averageGraphDistance();
	
	destroyProgressBar();

	QMessageBox::information(this, "Average Graph Distance", "The average shortest path length is  = " + QString::number(averGraphDistance), "OK",0);
	statusMessage( tr("Average distance calculated. Ready.") );

}






/**
*	Displays a message	on the status bar when you resize the window.
*/
void MainWindow::windowInfoStatusBar(int w, int h){
	statusMessage(  QString(tr("Window resized to (%1, %2) pixels.")).arg(w).arg(h) );
}






/**
*	Calls Graph:: writeNumberOfCliques() to write the number of cliques (triangles)
*  of each vertex into a file, then displays it.
*/
void MainWindow::slotNumberOfCliques(){
	if (!fileLoaded && !networkModified  )  {
		QMessageBox::critical(this, "Error",tr("Nothing to do! \nLoad a network file or create a new network. \nThen ask me to compute something!"), "OK",0);
		statusMessage(  QString(tr(" No network here. Sorry. Nothing to do."))  );
		return;
	}
	QString fn = "number-of-cliques.dat";
	bool considerWeights=true;
	
	createProgressBar();
	
	activeGraph.writeNumberOfCliques(fn, considerWeights);
	
	destroyProgressBar();

	TextEditor *ed = new TextEditor(fn);        //OPEN A TEXT EDITOR WINDOW
	tempFileNameNoPath=fn.split( "/");
	ed->setWindowTitle("Number of cliques saved as: " + tempFileNameNoPath.last());
	ed->show();
}






/**
*	Writes Clustering Coefficients into a file, then displays it.
*/
void MainWindow::slotClusteringCoefficient (){
	if (!fileLoaded && !networkModified  )  {
		QMessageBox::critical(this, "Error",tr("Nothing to do! \nLoad a network file or create a new network. \nThen ask me to compute something!"), "OK",0);
		statusMessage(  QString(tr(" No network here. Sorry. Nothing to do."))  );
		return;
	}
	QString fn = "clustering-coefficients.dat";
	bool considerWeights=true;
	
	createProgressBar();
	
	activeGraph.writeClusteringCoefficient(fn, considerWeights);
	
	destroyProgressBar();

	TextEditor *ed = new TextEditor(fn);        //OPEN A TEXT EDITOR WINDOW
	tempFileNameNoPath=fn.split( "/");
	ed->setWindowTitle("Clustering Coefficients saved as: " + tempFileNameNoPath.last());
	ed->show();
}




/**
*	Calls Graph to conduct and write a triad census into a file, then displays it.
*/
void MainWindow::slotTriadCensus() {
	
	if (!fileLoaded && !networkModified  )  {
		QMessageBox::critical(this, "Error",tr("Nothing to do! \nLoad a network file or create a new network. \nThen ask me to compute something!"), "OK",0);
		statusMessage(  QString(tr(" No network here. Sorry. Nothing to do."))  );
		return;
	}
	QString fn = "triad-census.dat";
	bool considerWeights=true;

	createProgressBar();
	
	activeGraph.writeTriadCensus(fn, considerWeights);
	
	destroyProgressBar();

	TextEditor *ed = new TextEditor(fn);        //OPEN A TEXT EDITOR WINDOW
	tempFileNameNoPath=fn.split( "/");
	ed->setWindowTitle("Triad Census saved as: " + tempFileNameNoPath.last());
	ed->show();
}


/**
*	Writes Out-Degree Centralities into a file, then displays it.
*/
void MainWindow::slotCentralityOutDegree(){
	if (!fileLoaded && !networkModified  )  {
		QMessageBox::critical(this, "Error",tr("Nothing to do! \nLoad a network file or create a new network. \nThen ask me to compute something!"), "OK",0);
		statusMessage(  QString(tr(" No network here. Sorry. Nothing to do."))  );
		return;
	}
	bool considerWeights=false;
	
	switch( QMessageBox::information( this, "Centrality Out-Degree",
				      tr("Take weights into account (Default: No)?"),
				      tr("Yes"), tr("No"),
				      0, 1 ) )
	{
		case 0:
			considerWeights=true;
			break;
		case 1:
			considerWeights=false;
			break;
		default: // just for sanity
			considerWeights=true;
			return;
		break;
	}

	QString fn = "centrality-out-degree.dat";

	createProgressBar();

	activeGraph.writeCentralityOutDegree(fn, considerWeights);
	
	destroyProgressBar();
	
	statusMessage( QString(tr(" displaying file...")));
	
	TextEditor *ed = new TextEditor(fn);        //OPEN A TEXT EDITOR WINDOW
	tempFileNameNoPath=fn.split( "/");
	ed->setWindowTitle("Out-Degree Centralities saved as: " + tempFileNameNoPath.last());
	ed->show();
}




/**
*	Writes In-Degree Centralities into a file, then displays it.
*/
void MainWindow::slotCentralityInDegree(){
	if (!fileLoaded && !networkModified  )  {
		QMessageBox::critical(this, "Error",tr("Nothing to do!\nLoad a network file or create a new network. \nThen ask me to compute something!"), "OK",0);
		statusMessage(  QString(tr("Nothing to do..."))  );
		return;
	}
	bool considerWeights=false;
	
	switch( QMessageBox::information( this, "Centrality In-Degree",
				      tr("Take weights into account (Default: No)?"),
				      tr("Yes"), tr("No"),
				      0, 1 ) )
	{
		case 0:
			considerWeights=true;
			break;
		case 1:
			considerWeights=false;
			break;
		default: // just for sanity
			considerWeights=true;
			return;
		break;
	}
	QString fn = "centrality-in-degree.dat";
	
	createProgressBar();
	
	activeGraph.writeCentralityInDegree(fn, considerWeights);
	
	destroyProgressBar();

	statusMessage( QString(tr(" displaying file...")));
	
	TextEditor *ed = new TextEditor(fn);        //OPEN A TEXT EDITOR WINDOW
	tempFileNameNoPath=fn.split( "/");
	ed->setWindowTitle("In-Degree Centralities saved as: " + tempFileNameNoPath.last());
	ed->show();
}




/**
*	Writes Closeness Centralities into a file, then displays it.
*/
void MainWindow::slotCentralityCloseness(){
	if (!fileLoaded && !networkModified  )  {
		QMessageBox::critical(this, "Error",tr("There are no nodes!\nLoad a network file or create a new network. \nThen ask me to compute something!"), "OK",0);
		statusMessage(  QString(tr("Nothing to do..."))  );
		return;
	}

	QString fn = "centrality_closeness.dat";
	bool considerWeights=true;

	createProgressBar();
	
	activeGraph.writeCentralityCloseness(fn, considerWeights);
	
	destroyProgressBar();

	statusMessage( QString(tr(" displaying file...")));

	TextEditor *ed = new TextEditor(fn);        //OPEN A TEXT EDITOR WINDOW
	tempFileNameNoPath=fn.split( "/");
	ed->setWindowTitle("Closeness Centralities  saved as: " + tempFileNameNoPath.last());
	ed->show();
}




/**
*	Writes Betweeness Centralities into a file, then displays it.
*/
void MainWindow::slotCentralityBetweeness(){
	if (!fileLoaded && !networkModified  )  {
		QMessageBox::critical(this, "Error",tr("There are no nodes!\nLoad a network file or create a new network. \nThen ask me to compute something!"), "OK",0);

		statusMessage(  QString(tr(" Nothing to do..."))  );
		return;
	}
	QString fn = "centrality_betweeness.dat";
	bool considerWeights=true;
	statusMessage(  QString(tr(" Please wait...")));

	createProgressBar();
	activeGraph.writeCentralityBetweeness(fn, considerWeights);
	destroyProgressBar();
					
	statusMessage( QString(tr(" displaying file...")));

	TextEditor *ed = new TextEditor(fn);        //OPEN A TEXT EDITOR WINDOW
	tempFileNameNoPath=fn.split( "/");
	ed->setWindowTitle("Betweeness Centralities saved as: " + tempFileNameNoPath.last());
	ed->show();
	QApplication::restoreOverrideCursor();
}




/**
*	Writes Informational Centralities into a file, then displays it.	
	TODO slotCentralityInformation
*/
void MainWindow::slotCentralityInformation(){
    if (!fileLoaded && !networkModified  )  {
	    QMessageBox::critical(this, "Error",tr("There are no nodes!\nLoad a network file or create a new network. \nThen ask me to compute something!"), "OK",0);

	    statusMessage(  QString(tr(" Nothing to do..."))  );
	    return;
    }
    QString fn = "centrality_information.dat";
    statusMessage(  QString(tr(" Please wait...")));

    createProgressBar();
    activeGraph.writeCentralityInformation(fn);
    destroyProgressBar();

    statusMessage( QString(tr(" displaying file...")));

    TextEditor *ed = new TextEditor(fn);
    tempFileNameNoPath=fn.split( "/");
    ed->setWindowTitle("Information Centralities saved as: " + tempFileNameNoPath.last());
    ed->show();
    QApplication::restoreOverrideCursor();

}




/**
*	Writes Stress Centralities into a file, then displays it.
*/
void MainWindow::slotCentralityStress(){
	if (!fileLoaded && !networkModified  )  {
		QMessageBox::critical(this, "Error",tr("There are no nodes!\nLoad a network file or create a new network. \nThen ask me to compute something!"), "OK",0);

		statusMessage(  QString(tr(" Nothing to do! Why don't you try creating something first?"))  );
		return;
	}
	QString fn = "centrality_stress.dat";
	
	bool considerWeights=true;
	statusMessage(  QString(tr(" Please wait...")));

	createProgressBar();
	
	activeGraph.writeCentralityStress(fn, considerWeights);	

	destroyProgressBar();
				
	TextEditor *ed = new TextEditor(fn);        //OPEN A TEXT EDITOR WINDOW
	tempFileNameNoPath=fn.split( "/");
	ed->setWindowTitle("Stress Centralities saved as: " + tempFileNameNoPath.last());
	ed->show();
}



/**
*	Writes Graph Centralities into a file, then displays it.
*/
void MainWindow::slotCentralityGraph(){
	if (!fileLoaded && !networkModified  )  {
		QMessageBox::critical(this, "Error",tr("There are no nodes!\nLoad a network file or create a new network. \nThen ask me to compute something!"), "OK",0);

		statusMessage(  QString(tr(" Try creating a network first. \nThen I compute whatever you want..."))  );
		return;
	}
	QString fn = "centrality_graph.dat";
	bool considerWeights=true;
	statusMessage(  QString(tr(" Please wait...")));
	
	createProgressBar();
		
	activeGraph.writeCentralityGraph(fn, considerWeights);	

	destroyProgressBar();
	
	TextEditor *ed = new TextEditor(fn);        //OPEN A TEXT EDITOR WINDOW
	tempFileNameNoPath=fn.split( "/" );
	ed->setWindowTitle("Graph Centralities saved as: " + tempFileNameNoPath.last());
	ed->show();
}



/**
*	Writes Power Centralities into a file, then displays it.
*/
void MainWindow::slotCentralityPower(){
	if (!fileLoaded && !networkModified  )  {
		QMessageBox::critical(this, "Error",tr("There are no nodes!\nLoad a network file or create a new network. \nThen ask me to compute something!"), "OK",0);

		statusMessage(  QString(tr(" Nothing to do! Why don't you try creating something first?"))  );
		return;
	}
	QString fn = "centrality_power.dat";

	bool considerWeights=true;
	statusMessage(  QString(tr(" Please wait...")));

	createProgressBar();

	activeGraph.writeCentralityPower(fn, considerWeights);

	destroyProgressBar();

	TextEditor *ed = new TextEditor(fn);        //OPEN A TEXT EDITOR WINDOW
	tempFileNameNoPath=fn.split( "/");
	ed->setWindowTitle("Stress Centralities saved as: " + tempFileNameNoPath.last());
	ed->show();
}


/**
*	Writes Eccentricity Centralities into a file, then displays it.
*/
void MainWindow::slotCentralityEccentricity(){
	if (!fileLoaded && !networkModified  )  {
		QMessageBox::critical(this, "Error",tr("There are no nodes!\nLoad a network file or create a new network. \nThen ask me to compute something!"), "OK",0);

		statusMessage(  QString(tr(" Nothing to do..."))  );
		return;
	}
	QString fn = "centrality_eccentricity.dat";
	bool considerWeights=true;
	statusMessage(  QString(tr(" Please wait...")));

	createProgressBar();
	activeGraph.writeCentralityEccentricity(fn, considerWeights);	
	destroyProgressBar();

	TextEditor *ed = new TextEditor(fn);        //OPEN A TEXT EDITOR WINDOW
	tempFileNameNoPath=fn.split( "/");
	ed->setWindowTitle(tr("Eccentricity Centralities saved as: ") + tempFileNameNoPath.last());
	ed->show();
	QApplication::restoreOverrideCursor();

}



void MainWindow::createProgressBar(){
		
	if (showProgressBarAct->isChecked() || activeGraph.totalEdges() > 2000){
		progressDialog= new QProgressDialog("Please wait, for distance matrix creation....", "Cancel", 0, activeGraph.vertices(), this);
		progressDialog -> setWindowModality(Qt::WindowModal);
		connect( &activeGraph, SIGNAL( updateProgressDialog(int) ), progressDialog, SLOT(setValue(int) ) ) ;
		progressDialog->setMinimumDuration(0);
	}
	
	QApplication::setOverrideCursor( QCursor(Qt::WaitCursor) );
	
}


void MainWindow::destroyProgressBar(){
		QApplication::restoreOverrideCursor();

	if (showProgressBarAct->isChecked() || activeGraph.totalEdges() > 1000)
		progressDialog->deleteLater();
}




/**
*	Called from Graph::
*/ 
bool MainWindow::showNumbers(){
	return displayNodeNumbersAct->isChecked();
}





/**
*  Turns on/off displaying the numbers of nodes (outside ones)
*/
void MainWindow::slotDisplayNodeNumbers(bool toggle) {
 	if (!fileLoaded && ! networkModified) {
		QMessageBox::critical(this, "Error",tr("There are no nodes! \nLoad a network file or create a new network."), "OK",0);
		statusMessage( tr("Errr...no nodes here. Sorry!") );
		return;
	}
	statusMessage( tr("Toggle Nodes Numbers. Please wait...") );

	if (!toggle) 	{
		graphicsWidget->setAllItemsVisibility(TypeNumber, false);
		statusMessage( tr("Node Numbers are invisible now. Click the same option again to display them.") );
		return;
	}
	else{
		graphicsWidget->setAllItemsVisibility(TypeNumber, true);
		statusMessage( tr("Node Numbers are visible again...") );
	}
}


/**
*	Called by Graph:: and this->initNet()
*/
bool MainWindow::showLabels(){
	return displayNodeLabelsAct->isChecked();
}



/**
*	Called by Graph:: and this->initNet()
*/
bool MainWindow::showNumbersInsideNodes(){
	return displayNumbersInsideNodesAct->isChecked();
}



/**
*  Turns on/off displaying the nodenumbers inside the nodes.
*/
void MainWindow::slotDisplayNumbersInsideNodes(bool toggle){
	statusMessage( tr("Toggle Numbers inside nodes. Please wait...") );

	if ( showNumbers() ) 	{
		// ?
	}
	else{
		displayNodeNumbersAct->setChecked(true);
	}
	
	activeGraph.setShowNumbersInsideNodes(toggle);
	graphicsWidget -> setNumbersInsideNodes(toggle);
	
	if (toggle){

		statusMessage( tr("Numbers inside nodes...") );		
	}
	else {
		
		statusMessage( tr("Numbers outside nodes...") );
	}
}

/**
*  Turns on/off displaying labels
*/
void MainWindow::slotDisplayNodeLabels(bool toggle){
 	if (!fileLoaded && ! networkModified) {
		QMessageBox::critical(this, "Error",tr("There are no nodes! \nLoad a network file or create a new network first. "), "OK",0);
		statusMessage( tr("No nodes found. Sorry...") );
		return;
	}
	statusMessage( tr("Toggle Nodes Labels. Please wait...") );

	if (!toggle) 	{
		graphicsWidget->setAllItemsVisibility(TypeLabel, false);
		statusMessage( tr("Node Labels are invisible now. Click the same option again to display them.") );
		return;
	}
	else{
		graphicsWidget->setAllItemsVisibility(TypeLabel, true);
		statusMessage( tr("Node Labels are visible again...") );
	}
	activeGraph.setShowLabels(toggle);
}




/**
*   Changes the size of all nodes
*/
void MainWindow::slotChangeAllNodesSize() {
	bool ok=false;
	
	int newSize = QInputDialog::getInteger(this, "Change node size", tr("Select new size for all nodes: (1-16)"),initNodeSize, 1, 16, 1, &ok );
	if (!ok) {
		statusMessage( "Change node size operation cancelled." );
		return;
	}

	qDebug ("MW: slotChangeAllNodesSize:");
	changeAllNodesSize(newSize);
	graphChanged();
	statusBar()->showMessage (QString(tr("Ready")), statusBarDuration) ;
	return;
}


/**
*   Changes the size of nodes. 
*/
void MainWindow::changeAllNodesSize(int size) {
	qDebug ("MW: changeAllNodesSize:");
	if (size == 0 ) {
		if (activeNodes() < 200) {
			return;
		}
		else if (activeNodes() >= 200 && activeNodes() < 500){
			size = 4; 
		}
		else if (activeNodes() >= 500 && activeNodes() < 1000) {
			size = 3; 
		}
		else if (activeNodes() >= 1000) {
			size = 2; 
		}
	}
	initNodeSize = size;
	activeGraph.setInitVertexSize(initNodeSize);
	qDebug () << "MW: changeAllNodesSize: changing to " <<  size;
	QList<QGraphicsItem *> list=scene->items();
	for (QList<QGraphicsItem *>::iterator it=list.begin(); it!=list.end(); it++) 
		if ( (*it) -> type() == TypeNode ){
		Node *jim = (Node*) (*it);
		(*jim).setSize(size);
	}
}


/**
*  Changes the shape of all nodes. 
*/
void MainWindow::slotChangeAllNodesShape() {
	bool ok=false;
	QStringList lst;
	lst << "box"<< "circle"<< "diamond"<< "ellipse"<< "triangle";
	QString newShape = QInputDialog::getItem(this, "Node shapes", "Select a shape for all nodes: ", lst, 1, true, &ok);
	if ( ok ) {
	        //user selected an item and pressed OK
		QList<QGraphicsItem *> list=scene->items();
		for (QList<QGraphicsItem *>::iterator it=list.begin(); it!=list.end(); it++)
			if ( (*it) -> type() == TypeNode ){
				Node *jim = (Node*) (*it);
				(*jim).setShape(newShape);
				activeGraph.setVertexShape ((*jim).nodeNumber(), newShape);
			}
		graphChanged();
		activeGraph.setInitVertexShape(newShape);
		statusBar()->showMessage (QString(tr("All shapes have been changed. Ready")), statusBarDuration) ;
	} else {
		//user pressed Cancel
		statusBar()->showMessage (QString(tr("Change node shapes aborted...")), statusBarDuration) ;
	}

}



/**
*  Change size of all nodes' numbers (outside ones)
*/
void MainWindow::slotChangeNumbersSize() {
	bool ok=false;
	int newSize;
	newSize = QInputDialog::getInteger(this, "Change text size", tr("Change all nodenumbers size to: (1-16)"),initNumberSize, 1, 16, 1, &ok );
	if (!ok) {
		statusMessage( tr("Change font size: Aborted.") );
	return;
	}
	
	QList<QGraphicsItem *> list=scene->items();
	for (QList<QGraphicsItem *>::iterator it2=list.begin();it2!=list.end(); it2++)
		
		if ( (*it2)->type()==TypeNumber) {
		NodeNumber * number= (NodeNumber*) (*it2);
		qDebug ("MW: slotChangeNumbersSize Found");
		number->setFont( QFont (number->font().family(), newSize, QFont::Light, false) );
	}
	
	activeGraph.setInitVertexNumberSize(newSize);
	statusMessage( tr("Changed numbers size. Ready.") );
}


/**
*  Changes size of all nodes' labels
*/
void MainWindow::slotChangeLabelsSize() {
	bool ok=false;
	int newSize;
	newSize = QInputDialog::getInteger(this, "Change text size", tr("Change all node labels size to: (1-16)"),initNumberSize, 1, 16, 1, &ok );
	if (!ok) {
		statusMessage( tr("Change font size: Aborted.") );
	return;
	}
	QList<QGraphicsItem *> list=scene->items();
	for (QList<QGraphicsItem *>::iterator it2=list.begin();it2!=list.end(); it2++)
		
		if ( (*it2)->type()==TypeLabel) {
		 	NodeLabel *label= (NodeLabel*) (*it2);
			qDebug ("MW: slotChangeLabelsSize Found");
			label->setFont( QFont (label->font().family(), newSize, QFont::Light, false) );
			activeGraph.setVertexLabelSize ( (label->node())->nodeNumber(), newSize); 
	}
	activeGraph.setInitVertexLabelSize(newSize);
	statusMessage( tr("Changed labels size. Ready.") );
}





/**
	Turns on/off drawing links as thick as their weights.
	TODO 
*/
void MainWindow::slotDrawLinksThickAsWeights() {

}



/**
*  Turns on/off displaying link weight numbers
*/
void MainWindow::slotDisplayLinksWeightNumbers(bool toggle) {
 	if (!fileLoaded && ! networkModified) {
		QMessageBox::critical(this, "Error",tr("There are no links! \nLoad a network file or create a new network first."), "OK",0);
		statusMessage( tr("No nodes or edges found. Sorry...") );
		return;
	}
	statusMessage( tr("Toggle Edges Weights. Please wait...") );

	if (!toggle) 	{
		graphicsWidget->setAllItemsVisibility(TypeEdgeWeight, false);
		statusMessage( tr("Edge weights are invisible now. Click the same option again to display them.") );
		return;
	}
	else{
		graphicsWidget->setAllItemsVisibility(TypeEdgeWeight, true);
		statusMessage( tr("Edge weights are visible again...") );
	}
	activeGraph.setShowLabels(toggle);


// 	pair<int,int> pair1;	
// 	QList<QGraphicsItem *> list=scene->items();
// 	if ( toggle )   {  //draw Edge Weight Numbers
// 		qDebug ("toogle is true. Will show weight numbers");
// 		for (QList<QGraphicsItem *>::iterator it=list.begin(); it!=list.end(); it++)
// 			if ( (*it)->type() ==   Link_Rtti ){
// 				Edge* link= (Edge*) (*it);
// 				qDebug ("found link");
//  				EdgeWeight *linkWeight =new  EdgeWeight (link, QString::number(link->weight()), scene );
// 				qDebug ("will draw weight number %i",link->weight() );
// 				
//                			linkWeight ->setZ (255);
// 				pair1=link->center();
//                 		linkWeight ->move(pair1.first,pair1.second);
//                 		linkWeight-> setColor (link->color());
//                 		linkWeight ->show();
// 				qDebug ("show");
// 			}
// 	}
// 	else { //delete them
// 		qDebug ("toogle is false. Deleting all numbers");
// 		for (QList<QGraphicsItem *>::iterator item=list.begin();item!=list.end(); item++){
// 			if ( (*item)->type() ==   Weight_Rtti ) {
// 				delete *item;
// 			}
// 			else if ( (*item)->type() ==   Link_Rtti ) {
// 				Edge* link= (Edge*) (*item);
// 				link->clearWeightList();
// 				qDebug ("weight List cleared");
// 			}	
// 			
// 		}
// 		return;
// 	}

}



/**
*  Turns on/off displaying links
*/
void MainWindow::slotDisplayLinks(bool toggle){
	if (!fileLoaded && ! networkModified) {
		QMessageBox::critical(this, "Error",tr("There are no nodes nor links! \nLoad a network file or create a new network first!"), "OK",0);

		statusMessage( tr("No links found...") );
		return;
	}
	statusMessage( tr("Toggle Edges Arrows. Please wait...") );

	if (!toggle) 	{
		graphicsWidget->setAllItemsVisibility(TypeEdge, false);
		statusMessage( tr("Links are invisible now. Click again the same menu to display them.") );
		return;
	}
	else{
		graphicsWidget->setAllItemsVisibility(TypeEdge, true);
		statusMessage( tr("Links visible again...") );
	}
	
}



/**
*  Turns on/off the arrows of links
*/
void MainWindow::slotDisplayLinksArrows(bool toggle){
	if (!fileLoaded && ! networkModified) {
		QMessageBox::critical(this, "Error",tr("There are no links! \nLoad a network file or create a new network first!"), "OK",0);

		statusMessage( tr("No links found...") );
		return;
	}
	statusMessage( tr("Toggle Edges Arrows. Please wait...") );

	if (!toggle) 	{
		QList<QGraphicsItem *> list = scene->items();
		for (QList<QGraphicsItem *>::iterator item=list.begin();item!=list.end(); item++) {
			if ( (*item)->type() ==TypeEdge){
				Edge *edge = (Edge*) (*item);
				edge->showArrows(false);
			}
		}
		return;
	}
	else{
		QList<QGraphicsItem *> list = scene->items();
		for (QList<QGraphicsItem *>::iterator item=list.begin();item!=list.end(); item++)
			if ( (*item)->type() ==TypeEdge){
				Edge *edge = (Edge*) (*item);
				edge->showArrows(true);
			}
	}
	statusMessage( tr("Ready."));
}



/**
*  FIXME links Bezier 
*/
void MainWindow::slotDrawLinksBezier(bool toggle){
	if (!fileLoaded && ! networkModified) {
		QMessageBox::critical(this, "Error",tr("There are no links! \nLoad a network file or create a new network!"), "OK",0);

		statusMessage( tr("There are NO links here!") );
		return;
	}
	statusMessage( tr("Toggle links bezier. Please wait...") );
// //	graphicsWidget->setBezier(toggle);
	if (!toggle) 	{
// 		QApplication::setOverrideCursor( QCursor(Qt::WaitCursor) );
// 		QList<QGraphicsItem *> list = scene->items();
// 		for (QList<QGraphicsItem *>::iterator item=list.begin();item!=list.end(); item++) {
// 			if ( (*item)->type() ==TypeEdge ){
// 				Edge *edge = (Edge*) (*item);
// //				edge->toggleBezier(false);
// 				(*item)->hide();(*item)->show();
// 			}
// 
// 		}
// 		QApplication::restoreOverrideCursor();
// 		return;
	}
	else{
// 		QApplication::setOverrideCursor( QCursor(Qt::WaitCursor) );
// 		QList<QGraphicsItem *> list = scene->items();
// 		for (QList<QGraphicsItem *>::iterator item=list.begin();item!=list.end(); item++){
// 			if ( (*item)->type() ==TypeEdge ){
// 				Edge *edge = (Edge*) (*item);
// //				edge->toggleBezier(true);
// 				(*item)->hide();(*item)->show();
// 			}
// 		}
// 		QApplication::restoreOverrideCursor();
	}

}



/**
*  Changes the background color of the scene
*/
void MainWindow::slotBackgroundColor () {
	qDebug("MW: slotBackgroundColor ");
	QColor backgrColor = QColorDialog::getColor( initBackgroundColor, this );
	graphicsWidget ->setBackgroundBrush(QBrush(backgrColor));	
	statusMessage( tr("Ready. ") );
}


/**
*  Changes the color of all nodes
*/
void MainWindow::slotAllNodesColor(){
	bool ok=false;
	initNodeColor = QInputDialog::getItem(this, "Nodes' colors", "Select a new color:", colorList, 1, true, &ok);
    	if ( ok ) {
		QApplication::setOverrideCursor( QCursor(Qt::WaitCursor) );
		qDebug ("MW: Will change color");
		QList<QGraphicsItem *> list= scene->items();
		for (QList<QGraphicsItem *>::iterator it=list.begin(); it!=list.end(); it++)
			if ( (*it)->type() == TypeNode ) 	{
				Node *jim = (Node *) (*it);
				jim->setColor(initNodeColor);
				qDebug ("MW: Changed color");
				activeGraph.setVertexColor (jim->nodeNumber(), initNodeColor);
				graphChanged();
			}
		activeGraph.setInitVertexColor(initNodeColor);
		QApplication::restoreOverrideCursor();
		statusMessage( tr("Ready. ")  );
    	} 
	else {
	        // user pressed Cancel
		statusMessage( tr("Change node color aborted. ")  );
    	}

}



/**
*  Changes the color of all links
*/
void MainWindow::slotAllLinksColor(){
	bool ok=false;
	initLinkColor = QInputDialog::getItem(this, "Links' colors", "Select a new color:", colorList, 1, true, &ok);
    	if ( ok ) {
		QApplication::setOverrideCursor( QCursor(Qt::WaitCursor) );
		qDebug ("MW: Will change color");
		QList<QGraphicsItem *> list= scene->items();
		for (QList<QGraphicsItem *>::iterator it=list.begin(); it!=list.end(); it++)
			if ( (*it)->type() == TypeEdge ) 	{
				Edge *link = (Edge *) (*it);
				link->setColor(initLinkColor );
				qDebug ("MW: Changed color");
				activeGraph.setEdgeColor (link->sourceNodeNumber(), link->targetNodeNumber(), initLinkColor);
				graphChanged();
			}
		activeGraph.setInitEdgeColor(initLinkColor);
		QApplication::restoreOverrideCursor();
		statusMessage( tr("Ready. ")  );

	} 
	else {
		// user pressed Cancel
		statusMessage( tr("Change link color aborted. ")  );
	}
}




/**
*  Changes the color of nodes' numbers
*/
void MainWindow::slotAllNumbersColor(){
	// = QInputDialog::getItem(this, "Links' colors", "Select a new color:", colorList, 1, true, &ok);
	QColor textColor = QColorDialog::getColor( Qt::black, this );
	QApplication::setOverrideCursor( QCursor(Qt::WaitCursor) );
	qDebug ("MW: Will change color");
	QList<QGraphicsItem *> list= scene->items();
	for (QList<QGraphicsItem *>::iterator it=list.begin(); it!=list.end(); it++) {
		if ( (*it)->type() == TypeNumber) 		{
			NodeNumber *jimNumber = (NodeNumber *) (*it);
			jimNumber->update();
			jimNumber->setDefaultTextColor(textColor);
		}
	}
	activeGraph.setInitVertexNumberColor( textColor.name() );
	QApplication::restoreOverrideCursor();
	statusMessage( tr("Numbers' colors changed. Ready. ")  );
}



/**
*  Changes the color of nodes labels
*/
void MainWindow::slotAllLabelsColor(){
	QColor textColor = QColorDialog::getColor( Qt::black, this );
	QApplication::setOverrideCursor( QCursor(Qt::WaitCursor) );
	qDebug ("MW: Will change label color");
	QList<QGraphicsItem *> list= scene->items();
	for (QList<QGraphicsItem *>::iterator it=list.begin(); it!=list.end(); it++)
		if ( (*it)->type() == TypeNode ) 	{
				Node *jim = (Node *) (*it);
				jim->label()->update();
				jim->label()->setDefaultTextColor(textColor);
				qDebug ("MW: Changed color");
				activeGraph.setVertexLabelColor (jim->nodeNumber(), textColor.name());
			}
	activeGraph.setInitVertexLabelColor(textColor.name());
	QApplication::restoreOverrideCursor();
	statusMessage( tr("Label colors changed. Ready. ")  );
}



/**
*  turns antialiasing on or off
*/
void MainWindow::slotAntialiasing(bool toggle) {
	statusMessage( tr("Toggle anti-aliasing. This will take some time if the network is large (>500)...") );
	//Inform graphicsWidget about the change
	QApplication::setOverrideCursor( QCursor(Qt::WaitCursor) );
 	graphicsWidget->setRenderHint(QPainter::Antialiasing, toggle);
	graphicsWidget->setRenderHint(QPainter::TextAntialiasing, toggle);
	graphicsWidget->setRenderHint(QPainter::SmoothPixmapTransform, toggle);
	QApplication::restoreOverrideCursor();
	if (!toggle) 
		statusMessage( tr("Anti-aliasing off.") );
	else  
		statusMessage( tr("Anti-aliasing on.") );
	
}

/**
*  turn progressbar on or off
*/
void MainWindow::slotShowProgressBar(bool toggle) {
	statusMessage( tr("Toggle progressbar..."));
	if (!toggle)  {
		statusMessage( tr("Progress bars off.") );	
	}
	else   {
		statusMessage( tr("Progress bars on.") );	
	}
}



/**
*  Turns debugging messages on or off
*/
void MainWindow::slotPrintDebug(bool toggle){
	if (!toggle)   {
		printDebug=false;
		statusMessage( tr("Debug messages off.") );
	}
	else  {
		printDebug=true;
		statusMessage( tr("Debug messages on.") );
	}
}




/**
*  Turns Toolbar on or off
*/
void MainWindow::slotViewToolBar(bool toggle) {
	statusMessage( tr("Toggle toolbar..."));
	if (toggle== false)   {
		toolBar->hide();
		statusMessage( tr("Toolbar off.") );	
	}
	else  {
		toolBar->show();
		statusMessage( tr("Toolbar on.") );	
	}
}



/**
*  Turns Statusbar on or off
*/
void MainWindow::slotViewStatusBar(bool toggle) {
	statusMessage( tr("Toggle statusbar..."));

	if (toggle == false)   {
		statusBar()->hide();
		statusMessage( tr("Status bar off.") );	
	}
	else   {
		statusBar()->show();	
		statusMessage( tr("Status bar on.") );	
	}

}


/*
 * Enables/disables displaying a user-defined custom image in the background
 */ 
void MainWindow::slotBackgroundImage(bool toggle) {
	statusMessage( tr("Toggle BackgroundImage..."));
	QString m_fileName ; 
	if (toggle == false)   {
		statusMessage( tr("BackgroundImage off.") );	
		graphicsWidget->setBackgroundBrush(QBrush(initBackgroundColor)); 
	}
	else   {
		m_fileName = QFileDialog::getOpenFileName( this, tr("Select one image"), "", 
					tr("All (*);;PNG (*.png);;JPG (*.jpg)")
					);
		graphicsWidget->setBackgroundBrush(QImage(m_fileName));
	 	graphicsWidget->setCacheMode(QGraphicsView::CacheBackground);

		statusMessage( tr("BackgroundImage on.") );	
	}

	
}

/**
*  Displays a random tip
*/
void MainWindow::slotTips() {
	int randomTip=rand()%tipsCounter; //Pick a tip.
	QMessageBox::about( this, tr("Tip Of The Day"), tips[randomTip]);
}



/**
	Creates our tips.
*/
void MainWindow::createTips(){
	tips+=tr("You can add a new node by double-clicking on the scene.");	
	tips+=tr("You can add a new node by clicking on Add button.");
	tips+=tr("You can remove a node by clicking on Remove button.");		
	tips+=tr("You can rotate the network by selecting a new angle on the dock.");	
	tips+=tr("You can add a new link between two nodes, by middle-clicking (or pressing both mouse buttons simultanesously) on the first and then on the second node.");	
	tips+=tr("You can remove a node by right-clicking on it and selecting Remove.");
	tips+=tr("You can change background color (from the menu Edit > Colors).");
	tips+=tr("Nodes can have the colors of your choice. Just right-click on a node and then select > Options > Change Color. You can select every color supported by the X.org pallette.");
	tips+=tr("The tabs on the left dock show information about the network (nodes, edges, density, etc) as well as information about any node you clicked on (inDegrees, outDegrees, clustering).");
	tips+=tr("You can move a node easily by dragging it with your mouse.");
	tips+=tr("SocNetV can save the positions of the nodes in a network, if you save it in Pajek/GraphML format.");
	tips+=tr("You can apply layout algorithms on the network from the menu Layout or by clicking on the Dock > Layout tab checkboxes");
	tips+=tr("You can change the label of node by right-clicking on it, and selecting Options > Change Label.");
	tips+=tr("All basic operations of SocNetV are available from the dock on the left, or by right-clicking on a node or a link.");
	tips+=tr("Node information is displayed on the Status bar, when you left-click on it.");
	tips+=tr("Link information is displayed on the Status bar, when you left-click on it.");

   	tipsCounter = 16;
}




/**
	Loads the HTML Help file and displays it via HTMLViewer.
*/
void MainWindow::slotHelp(){

	QString helpPath; 
	bool manualFound = false;
	QDir d( QCoreApplication::applicationDirPath() );
	qDebug()<< QCoreApplication::applicationDirPath().toAscii();

	if ( d.exists("manual.html") ) { 
  		helpPath=d.filePath("manual.html");
	}
	else {
		if (d.dirName()=="bin") {
			d.cdUp();
		}
		if (d.cd("./manual") ) {
			if ( d.exists("manual.html") ) {
				helpPath=d.filePath("manual.html");
				manualFound = true;	
			}
			else 	{
			      qDebug()<< "help file does not exist here.";
			      manualFound = false;
		        }
		}
		if ( !manualFound && d.cd("/usr/local/share/doc/socnetv/") ) {			//for compile installation
			if (d.exists("manual/")) d.cd("manual/");
			if ( d.exists("manual.html") ) {
				helpPath=d.filePath("manual.html");
				qDebug()<< "path" << helpPath.toAscii();
				manualFound = true;	
			}
			else {
				qDebug()<< "help file does not exist.";
				manualFound = false;
			}
		}
		if (!manualFound && d.cd("/usr/share/doc/socnetv/") ) {     //for Debian Ubuntu
			if (d.exists("manual/")) d.cd("manual/");
				if ( d.exists("manual.html") ) {
					helpPath=d.filePath("manual.html");
					manualFound = true;	
				}
				else {
					qDebug("help file does not exist in /usr/share/doc/socnetv/.");
					manualFound = false;
				}
			}             
			if ( !manualFound && d.cd("/usr/share/doc/packages/socnetv/") ) {  //for opensuse file hierarchy
				if (d.exists("manual/")) 
					d.cd("manual/");
				if ( d.exists("manual.html") ) {
					helpPath=d.filePath("manual.html");
					manualFound = true;	
				}
				else {
					qDebug("help file does not exist.");
				}
			}
			QString fedoraPath = "/usr/share/doc/socnetv-" + VERSION;
			if ( !manualFound && d.cd(fedoraPath) ) {  //for Fedora file hierarchy
				if (d.exists("manual/")) 
					d.cd("manual/");
				if ( d.exists("manual.html") ) {
					helpPath=d.filePath("manual.html");
					manualFound = true;	
				}
				else {
					qDebug("help file does not exist.");
				}
			}

	}
	qDebug () << "help path is: " << helpPath.toAscii();
	HTMLViewer *helpViewer = new HTMLViewer (helpPath, this);
	helpViewer -> setWindowTitle ( "SocNetV "+ VERSION + tr(" Manual"));
	helpViewer->show();

}



/**
	Displays the following message!!
*/
void MainWindow::slotHelpAbout(){
     int randomCookie=rand()%fortuneCookiesCounter;//createFortuneCookies();
QString BUILD="Tue Oct 12 00:58:06 EEST 2010";
     QMessageBox::about( this, "About SocNetV",
	"<b>Soc</b>ial <b>Net</b>work <b>V</b>isualizer (SocNetV)"
	"<p><b>Version</b>: " + VERSION + "</p>"
	"<p><b>Build</b>: "  + BUILD + " </p>"
	
	"<p>(C) 2005-2010 by Dimitris V. Kalamaras"
	"<br> dimitris.kalamaras@gmail.com"

	"<p><b>Fortune cookie: </b><br> \""  + fortuneCookie[randomCookie]  +"\""
	
	"<p><b>License:</b><br>"

	"This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version.</p>"

	"<p>This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.</p>"

	"<p>You should have received a copy of the GNU General Public License along with this program; If not, see http://www.gnu.org/licenses/</p>");
}



/**
	Creates the fortune cookies displayed on the above message.
*/
void MainWindow::createFortuneCookies(){
	fortuneCookie+="sic itur ad astra / sic transit gloria mundi ? <br /> --Unknown";
	fortuneCookie+="losers of yesterday, the winners of tomorrow... <br /> --B.Brecht";
	fortuneCookie+="Patriotism is the virtue of the wicked... <br /> --O. Wilde";
 
	fortuneCookie+="No tengo nunca mas, no tengo siempre. En la arena <br />" 
			"la victoria dejo sus piers perdidos.<br />"
		   	"Soy un pobre hombre dispuesto a amar a sus semejantes.<br />"
		   	"No se quien eres. Te amo. No doy, no vendo espinas. <br /> --Pablo Neruda"  ;
	fortuneCookie+="I will never apologize for the United States of America. I don't care what it has done. I don't care what the facts are. <br> --Vice President George H.W. Bush, after the Iranian airliner flight IR655 (an Airbus A300) was shot down by a U.S. missile cruiser (USS Vincennes), killing all 290 civilian passengers...";
	fortuneCookie+="Man must not check reason by tradition, but contrawise, must check tradition by reason.<br> --Leo Tolstoy";
	fortuneCookie+="Only after the last tree has been cut down, <br>only after the last river has been poisoned,<br> only after the last fish has been caught,<br>only then will you realize that money cannot be eaten. <br> --The Cree People";
	fortuneCookie+="Stat rosa pristina nomine, nomina nuda tenemus <br > --Unknown";
	fortuneCookie+="Jupiter and Saturn, Oberon, Miranda <br />"
					"And Titania, Neptune, Titan. <br />"
					"Stars can frighten. <br /> Syd Barrett";

	fortuneCookiesCounter=9;
//   return fortuneCookie.count();
}




/**
	Displays a short message about the Qt Toolbox.
*/
void MainWindow::slotAboutQt(){
	QMessageBox::aboutQt(this, "About Qt - SocNetV");
}