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
|
/* This file is part of the KDE projects
Copyright (C) 1998, 1999 Torben Weis <weis@kde.org>
Copyright (C) 2000 - 2005 David Faure <faure@kde.org>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
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; see the file COPYING. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include "konq_iconviewwidget.h"
#include "konq_operations.h"
#include "konq_undo.h"
#include "konq_sound.h"
#include "konq_filetip.h"
#include <tqclipboard.h>
#include <tqlayout.h>
#include <tqtimer.h>
#include <tqpainter.h>
#include <tqtooltip.h>
#include <tqlabel.h>
#include <tqmovie.h>
#include <tqregexp.h>
#include <tqcursor.h>
#include <kapplication.h>
#include <kdebug.h>
#include <kio/previewjob.h>
#include <kfileivi.h>
#include <konq_settings.h>
#include <konq_drag.h>
#include <kglobalsettings.h>
#include <kpropertiesdialog.h>
#include <kipc.h>
#include <kicontheme.h>
#include <kiconeffect.h>
#include <kurldrag.h>
#include <kstandarddirs.h>
#include <kprotocolinfo.h>
#include <ktrader.h>
#include <assert.h>
#include <unistd.h>
#include <klocale.h>
struct KonqIconViewWidgetPrivate
{
KonqIconViewWidgetPrivate() {
pActiveItem = 0;
bSoundPreviews = false;
pSoundItem = 0;
bSoundItemClicked = false;
pSoundPlayer = 0;
pSoundTimer = 0;
pPreviewJob = 0;
bAllowSetWallpaper = false;
doAnimations = true;
m_movie = 0L;
m_movieBlocked = 0;
pFileTip = 0;
pActivateDoubleClick = 0L;
bCaseInsensitive = true;
pPreviewMimeTypes = 0L;
bProgramsURLdrag = false;
}
~KonqIconViewWidgetPrivate() {
delete pSoundPlayer;
delete pSoundTimer;
delete m_movie;
delete pFileTip;
delete pActivateDoubleClick;
delete pPreviewMimeTypes;
//delete pPreviewJob; done by stopImagePreview
}
KFileIVI *pActiveItem;
// Sound preview
KFileIVI *pSoundItem;
KonqSoundPlayer *pSoundPlayer;
TQTimer *pSoundTimer;
bool bSoundPreviews;
bool bSoundItemClicked;
bool bAllowSetWallpaper;
bool bCaseInsensitive;
bool bBoostPreview;
// Animated icons support
bool doAnimations;
TQMovie* m_movie;
int m_movieBlocked;
TQString movieFileName;
KIO::PreviewJob *pPreviewJob;
KonqFileTip* pFileTip;
TQStringList previewSettings;
bool renameItem;
bool firstClick;
bool releaseMouseEvent;
TQPoint mousePos;
int mouseState;
TQTimer *pActivateDoubleClick;
TQStringList* pPreviewMimeTypes;
bool bProgramsURLdrag;
};
KonqIconViewWidget::KonqIconViewWidget( TQWidget * parent, const char * name, WFlags f, bool kdesktop )
: KIconView( parent, name, f ),
m_rootItem( 0L ), m_size( 0 ) /* default is DesktopIcon size */,
m_bDesktop( kdesktop ),
m_bSetGridX( !kdesktop ) /* No line breaking on the desktop */
{
d = new KonqIconViewWidgetPrivate;
connect( this, TQT_SIGNAL( dropped( TQDropEvent *, const TQValueList<TQIconDragItem> & ) ),
this, TQT_SLOT( slotDropped( TQDropEvent*, const TQValueList<TQIconDragItem> & ) ) );
connect( this, TQT_SIGNAL( selectionChanged() ),
this, TQT_SLOT( slotSelectionChanged() ) );
kapp->addKipcEventMask( KIPC::IconChanged );
connect( kapp, TQT_SIGNAL(iconChanged(int)), TQT_SLOT(slotIconChanged(int)) );
connect( this, TQT_SIGNAL(onItem(TQIconViewItem *)), TQT_SLOT(slotOnItem(TQIconViewItem *)) );
connect( this, TQT_SIGNAL(onViewport()), TQT_SLOT(slotOnViewport()) );
connect( this, TQT_SIGNAL(itemRenamed(TQIconViewItem *, const TQString &)), TQT_SLOT(slotItemRenamed(TQIconViewItem *, const TQString &)) );
m_pSettings = KonqFMSettings::settings(); // already needed in setItemTextPos(), calculateGridX()
d->bBoostPreview = boostPreview();
// hardcoded settings
setSelectionMode( TQIconView::Extended );
setItemTextPos( TQIconView::Bottom );
d->releaseMouseEvent = false;
d->pFileTip = new KonqFileTip(this);
d->firstClick = false;
calculateGridX();
setAutoArrange( true );
setSorting( true, sortDirection() );
readAnimatedIconsConfig();
m_bSortDirsFirst = true;
m_bMousePressed = false;
m_LineupMode = LineupBoth;
// emit our signals
slotSelectionChanged();
m_iconPositionGroupPrefix = TQString::fromLatin1( "IconPosition::" );
KonqUndoManager::incRef();
}
KonqIconViewWidget::~KonqIconViewWidget()
{
stopImagePreview();
KonqUndoManager::decRef();
delete d;
}
bool KonqIconViewWidget::maySetWallpaper()
{
return d->bAllowSetWallpaper;
}
void KonqIconViewWidget::setMaySetWallpaper(bool b)
{
d->bAllowSetWallpaper = b;
}
void KonqIconViewWidget::focusOutEvent( TQFocusEvent * ev )
{
// We can't possibly have the mouse pressed and still lose focus.
// Well, we can, but when we regain focus we should assume the mouse is
// not down anymore or the slotOnItem code will break with highlighting!
m_bMousePressed = false;
// This will ensure that tooltips don't pop up and the mouseover icon
// effect will go away if the mouse goes out of the view without
// first moving into an empty portion of the view
// Fixes part of #86968, and #85204
// Matt Newell 2004-09-24
slotOnViewport();
KIconView::focusOutEvent( ev );
}
void KonqIconViewWidget::slotItemRenamed(TQIconViewItem *item, const TQString &name)
{
kdDebug(1203) << "KonqIconViewWidget::slotItemRenamed" << endl;
KFileIVI *viewItem = static_cast<KFileIVI *>(item);
KFileItem *fileItem = viewItem->item();
// The correct behavior is to show the old name until the rename has successfully
// completed. Unfortunately, KIconView forces us to allow the text to be changed
// before we try the rename, so set it back to the pre-rename state.
viewItem->setText( fileItem->text() );
kdDebug(1203)<<" fileItem->text() ;"<<fileItem->text()<<endl;
// Don't do anything if the user renamed to a blank name.
if( !name.isEmpty() )
{
// Actually attempt the rename. If it succeeds, KDirLister will update the name.
KURL oldurl( fileItem->url() );
KURL newurl( oldurl );
newurl.setPath( newurl.directory(false) + KIO::encodeFileName( name ) );
kdDebug(1203)<<" newurl :"<<newurl<<endl;
// We use url()+name so that it also works if the name is a relative path (#51176)
KonqOperations::rename( this, oldurl, newurl );
}
}
void KonqIconViewWidget::slotIconChanged( int group )
{
if (group != KIcon::Desktop)
return;
int size = m_size;
if ( m_size == 0 )
m_size = -1; // little trick to force grid change in setIcons
setIcons( size ); // force re-determining all icons
readAnimatedIconsConfig();
}
void KonqIconViewWidget::readAnimatedIconsConfig()
{
KConfigGroup cfgGroup( KGlobal::config(), "DesktopIcons" );
d->doAnimations = cfgGroup.readBoolEntry( "Animated", true /*default*/ );
}
void KonqIconViewWidget::slotOnItem( TQIconViewItem *_item )
{
KFileIVI* item = static_cast<KFileIVI *>( _item );
// Reset icon of previous item
if( d->pActiveItem != 0L && d->pActiveItem != item )
{
if ( d->m_movie && d->pActiveItem->isAnimated() )
{
d->m_movie->pause(); // we'll see below what we do with it
d->pActiveItem->setAnimated( false );
d->pActiveItem->refreshIcon( true );
}
else {
d->pActiveItem->setActive( false );
}
d->pActiveItem = 0L;
d->pFileTip->setItem( 0L );
}
// Stop sound
if (d->pSoundPlayer != 0 && item != d->pSoundItem)
{
d->pSoundPlayer->stop();
d->pSoundItem = 0;
if (d->pSoundTimer && d->pSoundTimer->isActive())
d->pSoundTimer->stop();
}
if ( !m_bMousePressed )
{
if( item != d->pActiveItem )
{
d->pActiveItem = item;
d->pFileTip->setItem( d->pActiveItem->item(),
item->rect(),
item->pixmap() );
if ( d->doAnimations && d->pActiveItem && d->pActiveItem->hasAnimation() )
{
//kdDebug(1203) << "Playing animation for: " << d->pActiveItem->mouseOverAnimation() << endl;
// Check if cached movie can be used
#if 0 // Qt-mng bug, reusing the movie doesn't work currently.
if ( d->m_movie && d->movieFileName == d->pActiveItem->mouseOverAnimation() )
{
d->pActiveItem->setAnimated( true );
if (d->m_movieBlocked) {
kdDebug(1203) << "onitem, but blocked" << endl;
d->m_movie->pause();
}
else {
kdDebug(1203) << "we go ahead.." << endl;
d->m_movieBlocked++;
TQTimer::singleShot(300, this, TQT_SLOT(slotReenableAnimation()));
d->m_movie->restart();
d->m_movie->unpause();
}
}
else
#endif
{
TQMovie movie = KGlobal::iconLoader()->loadMovie( d->pActiveItem->mouseOverAnimation(), KIcon::Desktop, d->pActiveItem->iconSize() );
if ( !movie.isNull() )
{
delete d->m_movie;
d->m_movie = new TQMovie( movie ); // shallow copy, don't worry
// Fix alpha-channel - currently only if no background pixmap,
// the bg pixmap case requires to uncomment the code at qmovie.cpp:404
const TQPixmap* pm = backgroundPixmap();
bool hasPixmap = pm && !pm->isNull();
if ( !hasPixmap ) {
pm = viewport()->backgroundPixmap();
hasPixmap = pm && !pm->isNull();
}
if (!hasPixmap && backgroundMode() != NoBackground)
d->m_movie->setBackgroundColor( viewport()->backgroundColor() );
d->m_movie->connectUpdate( this, TQT_SLOT( slotMovieUpdate(const TQRect &) ) );
d->m_movie->connectStatus( TQT_TQOBJECT(this), TQT_SLOT( slotMovieStatus(int) ) );
d->movieFileName = d->pActiveItem->mouseOverAnimation();
d->pActiveItem->setAnimated( true );
}
else
{
d->pActiveItem->setAnimated( false );
if (d->m_movie)
d->m_movie->pause();
// No movie available, remember it
d->pActiveItem->setMouseOverAnimation( TQString::null );
}
}
} // animations
// Only do the normal "mouseover" effect if no animation is in use
if (d->pActiveItem && !d->pActiveItem->isAnimated())
{
d->pActiveItem->setActive( true );
}
}
else // No change in current item
{
// No effect. If we want to underline on hover, we should
// force the IVI to repaint here, though!
d->pActiveItem = 0L;
d->pFileTip->setItem( 0L );
}
} // bMousePressed
else
{
// All features disabled during mouse clicking, e.g. rectangular
// selection
d->pActiveItem = 0L;
d->pFileTip->setItem( 0L );
}
// ## shouldn't this be disabled during rectangular selection too ?
if (d->bSoundPreviews && d->pSoundPlayer &&
d->pSoundPlayer->mimeTypes().contains(
item->item()->mimetype())
&& KGlobalSettings::showFilePreview(item->item()->url())
&& topLevelWidget() == kapp->activeWindow())
{
d->pSoundItem = item;
d->bSoundItemClicked = false;
if (!d->pSoundTimer)
{
d->pSoundTimer = new TQTimer(this);
connect(d->pSoundTimer, TQT_SIGNAL(timeout()), TQT_SLOT(slotStartSoundPreview()));
}
if (d->pSoundTimer->isActive())
d->pSoundTimer->stop();
d->pSoundTimer->start(500, true);
}
else
{
if (d->pSoundPlayer)
d->pSoundPlayer->stop();
d->pSoundItem = 0;
if (d->pSoundTimer && d->pSoundTimer->isActive())
d->pSoundTimer->stop();
}
}
void KonqIconViewWidget::slotOnViewport()
{
d->pFileTip->setItem( 0L );
if (d->pSoundPlayer)
d->pSoundPlayer->stop();
d->pSoundItem = 0;
if (d->pSoundTimer && d->pSoundTimer->isActive())
d->pSoundTimer->stop();
if (d->pActiveItem == 0L)
return;
if ( d->doAnimations && d->m_movie && d->pActiveItem->isAnimated() )
{
d->pActiveItem->setAnimated( false );
#if 0
// Aborting before the end of the animation ?
if (d->m_movie->running()) {
d->m_movie->pause();
d->m_movieBlocked++;
kdDebug(1203) << "on viewport, blocking" << endl;
TQTimer::singleShot(300, this, TQT_SLOT(slotReenableAnimation()));
}
#endif
d->pActiveItem->refreshIcon( true );
Q_ASSERT( d->pActiveItem->state() == KIcon::DefaultState );
//delete d->m_movie;
//d->m_movie = 0L;
// TODO a timer to delete the movie after some time if unused?
}
else
{
d->pActiveItem->setActive( false );
}
d->pActiveItem = 0L;
}
void KonqIconViewWidget::slotStartSoundPreview()
{
if (!d->pSoundItem || d->bSoundItemClicked)
return;
d->pSoundPlayer->play(d->pSoundItem->item()->url().url());
}
void KonqIconViewWidget::slotPreview(const KFileItem *item, const TQPixmap &pix)
{
// ### slow. Idea: move KonqKfmIconView's m_itemDict into this class
for (TQIconViewItem *it = firstItem(); it; it = it->nextItem())
{
KFileIVI* current = static_cast<KFileIVI *>(it);
if (current->item() == item)
{
if (item->overlays() & KIcon::HiddenOverlay) {
TQPixmap p(pix);
KIconEffect::semiTransparent(p);
current->setThumbnailPixmap(p);
} else {
current->setThumbnailPixmap(pix);
}
break;
}
}
}
void KonqIconViewWidget::slotPreviewResult()
{
d->pPreviewJob = 0;
emit imagePreviewFinished();
}
void KonqIconViewWidget::slotToolTipPreview(const KFileItem* , const TQPixmap &)
{
// unused - remove for KDE4
}
void KonqIconViewWidget::slotToolTipPreviewResult()
{
// unused - remove for KDE4
}
void KonqIconViewWidget::slotMovieUpdate( const TQRect& rect )
{
//kdDebug(1203) << "KonqIconViewWidget::slotMovieUpdate " << rect.x() << "," << rect.y() << " " << rect.width() << "x" << rect.height() << endl;
Q_ASSERT( d );
Q_ASSERT( d->m_movie );
// seems stopAnimation triggers one last update
if ( d->pActiveItem && d->m_movie && d->pActiveItem->isAnimated() ) {
const TQPixmap &frame = d->m_movie->framePixmap();
// This can happen if the icon was scaled to the desired size, so KIconLoader
// will happily return a movie with different dimensions than the icon
int iconSize=d->pActiveItem->iconSize();
if (iconSize==0) iconSize = KGlobal::iconLoader()->currentSize( KIcon::Desktop );
if ( frame.width() != iconSize || frame.height() != iconSize ) {
d->pActiveItem->setAnimated( false );
d->m_movie->pause();
// No movie available, remember it
d->pActiveItem->setMouseOverAnimation( TQString::null );
d->pActiveItem->setActive( true );
return;
}
d->pActiveItem->setPixmapDirect( frame, false, false /*no redraw*/ );
TQRect pixRect = d->pActiveItem->pixmapRect(false);
repaintContents( pixRect.x() + rect.x(), pixRect.y() + rect.y(), rect.width(), rect.height(), false );
}
}
void KonqIconViewWidget::slotMovieStatus( int status )
{
if ( status < 0 ) {
// Error playing the MNG -> forget about it and do normal iconeffect
if ( d->pActiveItem && d->pActiveItem->isAnimated() ) {
d->pActiveItem->setAnimated( false );
d->pActiveItem->setMouseOverAnimation( TQString::null );
d->pActiveItem->setActive( true );
}
}
}
void KonqIconViewWidget::slotReenableAnimation()
{
if (!--d->m_movieBlocked) {
if ( d->pActiveItem && d->m_movie && d->m_movie->paused()) {
kdDebug(1203) << "reenabled animation" << endl;
d->m_movie->restart();
d->m_movie->unpause();
}
}
}
void KonqIconViewWidget::clear()
{
d->pFileTip->setItem( 0L );
stopImagePreview(); // Just in case
KIconView::clear();
d->pActiveItem = 0L;
}
void KonqIconViewWidget::takeItem( TQIconViewItem *item )
{
if ( d->pActiveItem == static_cast<KFileIVI *>(item) )
{
d->pFileTip->setItem( 0L );
d->pActiveItem = 0L;
}
if ( d->pPreviewJob )
d->pPreviewJob->removeItem( static_cast<KFileIVI *>(item)->item() );
KIconView::takeItem( item );
}
// Currently unused - remove in KDE 4.0
void KonqIconViewWidget::setThumbnailPixmap( KFileIVI * item, const TQPixmap & pixmap )
{
if ( item )
{
if ( d->pActiveItem == item )
{
d->pFileTip->setItem( 0L );
d->pActiveItem = 0L;
}
item->setThumbnailPixmap( pixmap );
if ( m_bSetGridX && item->width() > gridX() )
{
setGridX( item->width() );
if (autoArrange())
arrangeItemsInGrid();
}
}
}
bool KonqIconViewWidget::initConfig( bool bInit )
{
bool fontChanged = false;
// Color settings
TQColor normalTextColor = m_pSettings->normalTextColor();
setItemColor( normalTextColor );
if (m_bDesktop)
{
TQColor itemTextBg = m_pSettings->itemTextBackground();
if ( itemTextBg.isValid() )
setItemTextBackground( itemTextBg );
else
setItemTextBackground( Qt::NoBrush );
}
bool on = m_pSettings->showFileTips() && TQToolTip::isGloballyEnabled();
d->pFileTip->setOptions(on,
m_pSettings->showPreviewsInFileTips(),
m_pSettings->numFileTips());
// if the user wants our own tooltip, don't show the one from Qts ListView
setShowToolTips(!on);
// Font settings
TQFont font( m_pSettings->standardFont() );
if (!m_bDesktop)
font.setUnderline( m_pSettings->underlineLink() );
if ( font != KonqIconViewWidget::font() )
{
setFont( font );
if (!bInit)
{
// TQIconView doesn't do it by default... but if the font is made much
// bigger, we really need to give more space between the icons
fontChanged = true;
}
}
setIconTextHeight( m_pSettings->iconTextHeight() );
if ( (itemTextPos() == TQIconView::Right) && (maxItemWidth() != gridXValue()) )
{
int size = m_size;
m_size = -1; // little trick to force grid change in setIcons
setIcons( size ); // force re-determining all icons
}
else if ( d->bBoostPreview != boostPreview() ) // Update icons if settings for preview icon size have changed
setIcons(m_size);
else if (!bInit)
updateContents();
return fontChanged;
}
bool KonqIconViewWidget::boostPreview() const
{
if ( m_bDesktop ) return false;
KConfigGroup group( KGlobal::config(), "PreviewSettings" );
return group.readBoolEntry( "BoostSize", false );
}
void KonqIconViewWidget::disableSoundPreviews()
{
d->bSoundPreviews = false;
if (d->pSoundPlayer)
d->pSoundPlayer->stop();
d->pSoundItem = 0;
if (d->pSoundTimer && d->pSoundTimer->isActive())
d->pSoundTimer->stop();
}
void KonqIconViewWidget::setIcons( int size, const TQStringList& stopImagePreviewFor )
{
// size has changed?
bool sizeChanged = (m_size != size);
int oldGridX = gridX();
m_size = size;
// boost preview option has changed?
bool boost = boostPreview();
bool previewSizeChanged = ( d->bBoostPreview != boost );
d->bBoostPreview = boost;
if ( sizeChanged || previewSizeChanged )
{
int realSize = size ? size : KGlobal::iconLoader()->currentSize( KIcon::Desktop );
// choose spacing depending on font, but min 5 (due to KFileIVI move limit)
setSpacing( ( m_bDesktop || ( realSize > KIcon::SizeSmall ) ) ?
QMAX( 5, TQFontMetrics(font()).width('n') ) : 0 );
}
if ( sizeChanged || previewSizeChanged || !stopImagePreviewFor.isEmpty() )
{
calculateGridX();
}
bool stopAll = !stopImagePreviewFor.isEmpty() && stopImagePreviewFor.first() == "*";
// Disable repaints that can be triggered by ivi->setIcon(). Since icons are
// resized in-place, if the icon size is increasing it can happens that the right
// or bottom icons exceed the size of the viewport.. here we prevent the repaint
// event that will be triggered in that case.
bool prevUpdatesState = viewport()->isUpdatesEnabled();
viewport()->setUpdatesEnabled( false );
// Do this even if size didn't change, since this is used by refreshMimeTypes...
for ( TQIconViewItem *it = firstItem(); it; it = it->nextItem() ) {
KFileIVI * ivi = static_cast<KFileIVI *>( it );
// Set a normal icon for files that are not thumbnails, and for files
// that are thumbnails but for which it should be stopped
if ( !ivi->isThumbnail() ||
sizeChanged ||
previewSizeChanged ||
stopAll ||
mimeTypeMatch( ivi->item()->mimetype(), stopImagePreviewFor ) )
{
ivi->setIcon( size, ivi->state(), true, false );
}
else
ivi->invalidateThumb( ivi->state(), true );
}
// Restore viewport update to previous state
viewport()->setUpdatesEnabled( prevUpdatesState );
if ( ( sizeChanged || previewSizeChanged || oldGridX != gridX() ||
!stopImagePreviewFor.isEmpty() ) && autoArrange() )
arrangeItemsInGrid( true ); // take new grid into account and repaint
else
viewport()->update(); //Repaint later..
}
bool KonqIconViewWidget::mimeTypeMatch( const TQString& mimeType, const TQStringList& mimeList ) const
{
// Code duplication from KIO::PreviewJob
KMimeType::Ptr mime = KMimeType::mimeType( mimeType );
for (TQStringList::ConstIterator mt = mimeList.begin(); mt != mimeList.end(); ++mt)
{
if ( mime->is( *mt ) )
return true;
// Support for *mt == "image/*"
TQString tmp( mimeType );
if ( (*mt).endsWith("*") && tmp.replace(TQRegExp("/.*"), "/*") == (*mt) )
return true;
if ( (*mt) == "text/plain" )
{
TQVariant textProperty = mime->property( "X-TDE-text" );
if ( textProperty.type() == TQVariant::Bool && textProperty.toBool() )
return true;
}
}
return false;
}
void KonqIconViewWidget::setItemTextPos( ItemTextPos pos )
{
// can't call gridXValue() because this already would need the new itemTextPos()
int sz = m_size ? m_size : KGlobal::iconLoader()->currentSize( KIcon::Desktop );
if ( m_bSetGridX )
if ( pos == TQIconView::Bottom )
setGridX( QMAX( sz + 50, previewIconSize( sz ) + 13 ) );
else
{
setMaxItemWidth( QMAX( sz, previewIconSize( sz ) ) + m_pSettings->iconTextWidth() );
setGridX( -1 );
}
KIconView::setItemTextPos( pos );
}
void KonqIconViewWidget::gridValues( int* x, int* y, int* dx, int* dy,
int* nx, int* ny )
{
int previewSize = previewIconSize( m_size );
int iconSize = m_size ? m_size : KGlobal::iconLoader()->currentSize( KIcon::Desktop );
// Grid size
// as KFileIVI limits to move an icon to x >= 5, y >= 5, we define a grid cell as:
// spacing() must be >= 5 (currently set to 5 in setIcons())
// horizontal: left spacing() + <width>
// vertical : top spacing(), <height>, bottom spacing()
// The doubled space in y-direction gives a better visual separation and makes it clearer
// to which item the text belongs
*dx = spacing() + QMAX( QMAX( iconSize, previewSize ), m_pSettings->iconTextWidth() );
int textHeight = iconTextHeight() * fontMetrics().height();
*dy = spacing() + QMAX( iconSize, previewSize ) + 2 + textHeight + spacing();
// Icon Area
int w, h;
if ( m_IconRect.isValid() ) { // w and h must be != 0, otherwise we would get a div by zero
*x = m_IconRect.left(); w = m_IconRect.width();
*y = m_IconRect.top(); h = m_IconRect.height();
}
else {
*x = 0; w = viewport()->width();
*y = 0; h = viewport()->height();
}
// bug:110775 avoid div by zero (happens e.g. when iconTextHeight or iconTextWidth are very large)
if ( *dx > w )
*dx = w;
if ( *dy > h )
*dy = h;
*nx = w / *dx;
*ny = h / *dy;
// TODO: Check that items->count() <= nx * ny
// Let have exactly nx columns and ny rows
if(*nx && *ny) {
*dx = w / *nx;
*dy = h / *ny;
}
kdDebug(1203) << "x=" << *x << " y=" << *y << " spacing=" << spacing() << " iconSize=" << iconSize
<< " w=" << w << " h=" << h
<< " nx=" << *nx << " ny=" << *ny
<< " dx=" << *dx << " dy=" << *dy << endl;
}
void KonqIconViewWidget::calculateGridX()
{
if ( m_bSetGridX )
if ( itemTextPos() == TQIconView::Bottom )
setGridX( gridXValue() );
else
{
setMaxItemWidth( gridXValue() );
setGridX( -1 );
}
}
int KonqIconViewWidget::gridXValue() const
{
// this method is only used in konqi as filemanager (not desktop)
int sz = m_size ? m_size : KGlobal::iconLoader()->currentSize( KIcon::Desktop );
int newGridX;
if ( itemTextPos() == TQIconView::Bottom )
newGridX = QMAX( sz + 50, previewIconSize( sz ) + 13 );
else
newGridX = QMAX( sz, previewIconSize( sz ) ) + m_pSettings->iconTextWidth();
//kdDebug(1203) << "gridXValue: " << newGridX << " sz=" << sz << endl;
return newGridX;
}
void KonqIconViewWidget::refreshMimeTypes()
{
updatePreviewMimeTypes();
for ( TQIconViewItem *it = firstItem(); it; it = it->nextItem() )
(static_cast<KFileIVI *>( it ))->item()->refreshMimeType();
setIcons( m_size );
}
void KonqIconViewWidget::setURL( const KURL &kurl )
{
stopImagePreview();
m_url = kurl;
d->pFileTip->setPreview( KGlobalSettings::showFilePreview(m_url) );
if ( m_url.isLocalFile() )
m_dotDirectoryPath = m_url.path(1).append( ".directory" );
else
m_dotDirectoryPath = TQString::null;
}
void KonqIconViewWidget::startImagePreview( const TQStringList &, bool force )
{
stopImagePreview(); // just in case
// Check config
if ( !KGlobalSettings::showFilePreview( url() ) ) {
kdDebug(1203) << "Previews disabled for protocol " << url().protocol() << endl;
emit imagePreviewFinished();
return;
}
if ((d->bSoundPreviews = d->previewSettings.contains( "audio/" )) &&
!d->pSoundPlayer)
{
KLibFactory *factory = KLibLoader::self()->factory("konq_sound");
if (factory)
d->pSoundPlayer = static_cast<KonqSoundPlayer *>(
factory->create(TQT_TQOBJECT(this), 0, "KonqSoundPlayer"));
d->bSoundPreviews = (d->pSoundPlayer != 0L);
}
KFileItemList items;
for ( TQIconViewItem *it = firstItem(); it; it = it->nextItem() )
if ( force || !static_cast<KFileIVI *>( it )->hasValidThumbnail() )
items.append( static_cast<KFileIVI *>( it )->item() );
bool onlyAudio = true;
for ( TQStringList::ConstIterator it = d->previewSettings.begin(); it != d->previewSettings.end(); ++it ) {
if ( (*it).startsWith( "audio/" ) )
d->bSoundPreviews = true;
else
onlyAudio = false;
}
if ( items.isEmpty() || onlyAudio ) {
emit imagePreviewFinished();
return; // don't start the preview job if not really necessary
}
int iconSize = m_size ? m_size : KGlobal::iconLoader()->currentSize( KIcon::Desktop );
int size;
d->bBoostPreview = boostPreview();
size = previewIconSize( iconSize );
if ( !d->bBoostPreview )
iconSize /= 2;
d->pPreviewJob = KIO::filePreview( items, size, size, iconSize,
m_pSettings->textPreviewIconTransparency(), true /* scale */,
true /* save */, &(d->previewSettings) );
connect( d->pPreviewJob, TQT_SIGNAL( gotPreview( const KFileItem *, const TQPixmap & ) ),
this, TQT_SLOT( slotPreview( const KFileItem *, const TQPixmap & ) ) );
connect( d->pPreviewJob, TQT_SIGNAL( result( KIO::Job * ) ),
this, TQT_SLOT( slotPreviewResult() ) );
}
void KonqIconViewWidget::stopImagePreview()
{
if (d->pPreviewJob)
{
d->pPreviewJob->kill();
d->pPreviewJob = 0;
// Now that previews are updated in-place, calling
// arrangeItemsInGrid() here is not needed anymore
}
}
bool KonqIconViewWidget::isPreviewRunning() const
{
return d->pPreviewJob;
}
KFileItemList KonqIconViewWidget::selectedFileItems()
{
KFileItemList lstItems;
TQIconViewItem *it = firstItem();
for (; it; it = it->nextItem() )
if ( it->isSelected() ) {
KFileItem *fItem = (static_cast<KFileIVI *>(it))->item();
lstItems.append( fItem );
}
return lstItems;
}
void KonqIconViewWidget::slotDropped( TQDropEvent *ev, const TQValueList<TQIconDragItem> & )
{
// Drop on background
KURL dirURL = url();
if ( m_rootItem ) {
bool dummy;
dirURL = m_rootItem->mostLocalURL(dummy);
}
KonqOperations::doDrop( m_rootItem /* may be 0L */, dirURL, ev, this );
}
void KonqIconViewWidget::slotAboutToCreate(const TQPoint &, const TQValueList<KIO::CopyInfo> &)
{
// Do nothing :-)
}
void KonqIconViewWidget::drawBackground( TQPainter *p, const TQRect &r )
{
drawBackground(p, r, r.topLeft());
}
void KonqIconViewWidget::drawBackground( TQPainter *p, const TQRect &r , const TQPoint &pt)
{
const TQPixmap *pm = backgroundPixmap();
bool hasPixmap = pm && !pm->isNull();
if ( !hasPixmap ) {
pm = viewport()->backgroundPixmap();
hasPixmap = pm && !pm->isNull();
}
TQRect rtgt(r);
rtgt.moveTopLeft(pt);
if (!hasPixmap && backgroundMode() != NoBackground) {
p->fillRect(rtgt, viewport()->backgroundColor());
return;
}
if (hasPixmap) {
int ax = (r.x() + contentsX() + leftMargin()) % pm->width();
int ay = (r.y() + contentsY() + topMargin()) % pm->height();
p->drawTiledPixmap(rtgt, *pm, TQPoint(ax, ay));
}
}
TQDragObject * KonqIconViewWidget::dragObject()
{
if ( !currentItem() )
return 0;
return konqDragObject( viewport() );
}
KonqIconDrag * KonqIconViewWidget::konqDragObject( TQWidget * dragSource )
{
//kdDebug(1203) << "KonqIconViewWidget::konqDragObject" << endl;
KonqIconDrag2 * drag = new KonqIconDrag2( dragSource );
TQIconViewItem *primaryItem = currentItem();
// Append all items to the drag object
for ( TQIconViewItem *it = firstItem(); it; it = it->nextItem() ) {
if ( it->isSelected() ) {
if (!primaryItem)
primaryItem = it;
KFileItem* fileItem = (static_cast<KFileIVI *>(it))->item();
KURL url = fileItem->url();
bool dummy;
KURL mostLocalURL = fileItem->mostLocalURL(dummy);
TQString itemURL = KURLDrag::urlToString(url);
kdDebug(1203) << "itemURL=" << itemURL << endl;
TQIconDragItem id;
id.setData( TQCString(itemURL.latin1()) );
drag->append( id,
TQRect( it->pixmapRect(false).topLeft() - m_mousePos,
it->pixmapRect().size() ),
TQRect( it->textRect(false).topLeft() - m_mousePos,
it->textRect().size() ),
itemURL, mostLocalURL );
}
}
if (primaryItem)
drag->setPixmap( *primaryItem->pixmap(), m_mousePos - primaryItem->pixmapRect(false).topLeft() );
return drag;
}
void KonqIconViewWidget::contentsDragEnterEvent( TQDragEnterEvent *e )
{
if ( e->provides( "text/uri-list" ) )
{
TQByteArray payload = e->encodedData( "text/uri-list" );
if ( !payload.size() )
kdError() << "Empty data !" << endl;
// Cache the URLs, since we need them every time we move over a file
// (see KFileIVI)
bool ok = KURLDrag::decode( e, m_lstDragURLs );
if( !ok )
kdError() << "Couldn't decode urls dragged !" << endl;
}
KURL::List uriList;
if ( KURLDrag::decode(e, uriList) )
{
if ( uriList.first().protocol() == "programs" )
{
e->ignore();
emit dragEntered( false );
d->bProgramsURLdrag = true;
return;
}
}
KIconView::contentsDragEnterEvent( e );
emit dragEntered( true /*accepted*/ );
}
void KonqIconViewWidget::contentsDragMoveEvent( TQDragMoveEvent *e )
{
if ( d->bProgramsURLdrag ) {
emit dragMove( false );
e->ignore();
cancelPendingHeldSignal();
return;
}
TQIconViewItem *item = findItem( e->pos() );
if ( e->source() != viewport() &&
!item && m_rootItem && !m_rootItem->isWritable() ) {
emit dragMove( false );
e->ignore();
cancelPendingHeldSignal();
return;
}
emit dragMove( true );
KIconView::contentsDragMoveEvent( e );
}
void KonqIconViewWidget::contentsDragLeaveEvent( TQDragLeaveEvent *e )
{
d->bProgramsURLdrag = false;
KIconView::contentsDragLeaveEvent(e);
emit dragLeft();
}
void KonqIconViewWidget::setItemColor( const TQColor &c )
{
iColor = c;
}
TQColor KonqIconViewWidget::itemColor() const
{
return iColor;
}
void KonqIconViewWidget::disableIcons( const KURL::List & lst )
{
for ( TQIconViewItem *kit = firstItem(); kit; kit = kit->nextItem() )
{
bool bFound = false;
// Wow. This is ugly. Matching two lists together....
// Some sorting to optimise this would be a good idea ?
for (KURL::List::ConstIterator it = lst.begin(); !bFound && it != lst.end(); ++it)
{
if ( static_cast<KFileIVI *>( kit )->item()->url() == *it )
{
bFound = true;
// maybe remove "it" from lst here ?
}
}
static_cast<KFileIVI *>( kit )->setDisabled( bFound );
}
}
void KonqIconViewWidget::slotSelectionChanged()
{
// This code is very related to ListViewBrowserExtension::updateActions
int canCopy = 0;
int canDel = 0;
int canTrash = 0;
bool bInTrash = false;
int iCount = 0;
for ( TQIconViewItem *it = firstItem(); it; it = it->nextItem() )
{
if ( it->isSelected() )
{
iCount++;
canCopy++;
KFileItem *item = ( static_cast<KFileIVI *>( it ) )->item();
KURL url = item->url();
TQString local_path = item->localPath();
if ( url.directory(false) == KGlobalSettings::trashPath() )
bInTrash = true;
if ( KProtocolInfo::supportsDeleting( url ) )
canDel++;
if ( !local_path.isEmpty() )
canTrash++;
}
}
emit enableAction( "cut", canDel > 0 );
emit enableAction( "copy", canCopy > 0 );
emit enableAction( "trash", canDel > 0 && !bInTrash && canTrash==canDel );
emit enableAction( "del", canDel > 0 );
emit enableAction( "properties", iCount > 0 && KPropertiesDialog::canDisplay( selectedFileItems() ) );
emit enableAction( "editMimeType", ( iCount == 1 ) );
emit enableAction( "rename", ( iCount == 1) && !bInTrash );
}
void KonqIconViewWidget::renameCurrentItem()
{
if ( currentItem() )
currentItem()->rename();
}
void KonqIconViewWidget::renameSelectedItem()
{
kdDebug(1203) << " -- KonqIconViewWidget::renameSelectedItem() -- " << endl;
TQIconViewItem * item = 0L;
TQIconViewItem *it = firstItem();
for (; it; it = it->nextItem() )
if ( it->isSelected() && !item )
{
item = it;
break;
}
if (!item)
{
Q_ASSERT(item);
return;
}
item->rename();
}
void KonqIconViewWidget::cutSelection()
{
kdDebug(1203) << " -- KonqIconViewWidget::cutSelection() -- " << endl;
KonqIconDrag * obj = konqDragObject( /* no parent ! */ );
obj->setMoveSelection( true );
TQApplication::clipboard()->setData( obj );
}
void KonqIconViewWidget::copySelection()
{
kdDebug(1203) << " -- KonqIconViewWidget::copySelection() -- " << endl;
KonqIconDrag * obj = konqDragObject( /* no parent ! */ );
TQApplication::clipboard()->setData( obj );
}
void KonqIconViewWidget::pasteSelection()
{
paste( url() );
}
void KonqIconViewWidget::paste( const KURL &url )
{
KonqOperations::doPaste( this, url );
}
KURL::List KonqIconViewWidget::selectedUrls()
{
return selectedUrls( UserVisibleUrls );
}
KURL::List KonqIconViewWidget::selectedUrls( UrlFlags flags ) const
{
KURL::List lstURLs;
bool dummy;
for ( TQIconViewItem *it = firstItem(); it; it = it->nextItem() )
if ( it->isSelected() ) {
KFileItem* item = (static_cast<KFileIVI *>( it ))->item();
lstURLs.append( flags == MostLocalUrls ? item->mostLocalURL( dummy ) : item->url() );
}
return lstURLs;
}
TQRect KonqIconViewWidget::iconArea() const
{
return m_IconRect;
}
void KonqIconViewWidget::setIconArea(const TQRect &rect)
{
m_IconRect = rect;
}
int KonqIconViewWidget::lineupMode() const
{
return m_LineupMode;
}
void KonqIconViewWidget::setLineupMode(int mode)
{
m_LineupMode = mode;
}
bool KonqIconViewWidget::sortDirectoriesFirst() const
{
return m_bSortDirsFirst;
}
void KonqIconViewWidget::setSortDirectoriesFirst( bool b )
{
m_bSortDirsFirst = b;
}
void KonqIconViewWidget::contentsMouseMoveEvent( TQMouseEvent *e )
{
if ( (d->pSoundPlayer && d->pSoundPlayer->isPlaying()) || (d->pSoundTimer && d->pSoundTimer->isActive()))
{
// The following call is SO expensive (the ::widgetAt call eats up to 80%
// of the mouse move cpucycles!), so it's mandatory to place that function
// under strict checks, such as d->pSoundPlayer->isPlaying()
if ( TQApplication::widgetAt( TQCursor::pos() ) != topLevelWidget() )
{
if (d->pSoundPlayer)
d->pSoundPlayer->stop();
d->pSoundItem = 0;
if (d->pSoundTimer && d->pSoundTimer->isActive())
d->pSoundTimer->stop();
}
}
d->renameItem= false;
KIconView::contentsMouseMoveEvent( e );
}
void KonqIconViewWidget::contentsDropEvent( TQDropEvent * ev )
{
TQIconViewItem *i = findItem( ev->pos() );
if ( ev->source() != viewport() &&
!i && m_rootItem && !m_rootItem->isWritable() ) {
ev->accept( false );
return;
}
// Short-circuit TQIconView if Ctrl is pressed, so that it's possible
// to drop a file into its own parent widget to copy it.
if ( !i && (ev->action() == TQDropEvent::Copy || ev->action() == TQDropEvent::Link)
&& ev->source() && ev->source() == viewport())
{
// First we need to call TQIconView though, to clear the drag shape
bool bMovable = itemsMovable();
setItemsMovable(false); // hack ? call it what you want :-)
KIconView::contentsDropEvent( ev );
setItemsMovable(bMovable);
TQValueList<TQIconDragItem> lst;
slotDropped(ev, lst);
}
else
{
KIconView::contentsDropEvent( ev );
emit dropped(); // What is this for ? (David) KDE4: remove
}
// Don't do this here, it's too early !
// slotSaveIconPositions();
// If we want to save after the new file gets listed, though,
// we could reimplement contentsDropEvent in KDIconView and set m_bNeedSave. Bah.
// This signal is sent last because we need to ensure it is
// taken in account when all the slots triggered by the dropped() signal
// are executed. This way we know that the Drag and Drop is truely finished
emit dragFinished();
}
void KonqIconViewWidget::doubleClickTimeout()
{
d->renameItem= true;
mousePressChangeValue();
if ( d->releaseMouseEvent )
{
TQMouseEvent e( TQEvent::MouseButtonPress,d->mousePos , 1, d->mouseState);
TQIconViewItem* item = findItem( e.pos() );
KURL url;
if ( item )
{
url= ( static_cast<KFileIVI *>( item ) )->item()->url();
bool brenameTrash =false;
if ( url.isLocalFile() && (url.directory(false) == KGlobalSettings::trashPath() || url.path(1).startsWith(KGlobalSettings::trashPath())))
brenameTrash = true;
if ( url.isLocalFile() && !brenameTrash && d->renameItem && m_pSettings->renameIconDirectly() && e.button() == Qt::LeftButton && item->textRect( false ).contains(e.pos()))
{
if( d->pActivateDoubleClick->isActive () )
d->pActivateDoubleClick->stop();
item->rename();
m_bMousePressed = false;
}
}
}
else
{
TQMouseEvent e( TQEvent::MouseMove,d->mousePos , 1, d->mouseState);
KIconView::contentsMousePressEvent( &e );
}
if( d->pActivateDoubleClick->isActive() )
d->pActivateDoubleClick->stop();
d->releaseMouseEvent = false;
d->renameItem= false;
}
void KonqIconViewWidget::wheelEvent(TQWheelEvent* e)
{
// when scrolling with mousewheel, stop possible pending filetip
d->pFileTip->setItem( 0 );
if (e->state() == ControlButton)
{
if (e->delta() >= 0)
{
emit incIconSize();
}
else
{
emit decIconSize();
}
e->accept();
return;
}
KIconView::wheelEvent(e);
}
void KonqIconViewWidget::leaveEvent( TQEvent *e )
{
// when leaving the widget, stop possible pending filetip and icon effect
slotOnViewport();
KIconView::leaveEvent(e);
}
void KonqIconViewWidget::mousePressChangeValue()
{
//kdDebug(1203) << "KonqIconViewWidget::contentsMousePressEvent" << endl;
m_bMousePressed = true;
if (d->pSoundPlayer)
d->pSoundPlayer->stop();
d->bSoundItemClicked = true;
d->firstClick = false;
// Once we click on the item, we don't want a tooltip
// Fixes part of #86968
d->pFileTip->setItem( 0 );
}
void KonqIconViewWidget::contentsMousePressEvent( TQMouseEvent *e )
{
if(d->pActivateDoubleClick && d->pActivateDoubleClick->isActive ())
d->pActivateDoubleClick->stop();
TQIconViewItem* item = findItem( e->pos() );
m_mousePos = e->pos();
KURL url;
if ( item )
{
url = ( static_cast<KFileIVI *>( item ) )->item()->url();
bool brenameTrash =false;
if ( url.isLocalFile() && (url.directory(false) == KGlobalSettings::trashPath() || url.path(1).startsWith(KGlobalSettings::trashPath())))
brenameTrash = true;
if ( !brenameTrash && !KGlobalSettings::singleClick() && m_pSettings->renameIconDirectly() && e->button() == Qt::LeftButton && item->textRect( false ).contains(e->pos())&& !d->firstClick && url.isLocalFile() && (!url.protocol().find("device", 0, false)==0))
{
d->firstClick = true;
d->mousePos = e->pos();
d->mouseState = e->state();
if (!d->pActivateDoubleClick)
{
d->pActivateDoubleClick = new TQTimer(this);
connect(d->pActivateDoubleClick, TQT_SIGNAL(timeout()), this, TQT_SLOT(doubleClickTimeout()));
}
if( d->pActivateDoubleClick->isActive () )
d->pActivateDoubleClick->stop();
else
d->pActivateDoubleClick->start(TQApplication::doubleClickInterval());
d->releaseMouseEvent = false;
return;
}
else
d->renameItem= false;
}
else
d->renameItem= false;
mousePressChangeValue();
if(d->pActivateDoubleClick && d->pActivateDoubleClick->isActive())
d->pActivateDoubleClick->stop();
KIconView::contentsMousePressEvent( e );
}
void KonqIconViewWidget::contentsMouseReleaseEvent( TQMouseEvent *e )
{
KIconView::contentsMouseReleaseEvent( e );
if(d->releaseMouseEvent && d->pActivateDoubleClick && d->pActivateDoubleClick->isActive ())
d->pActivateDoubleClick->stop();
slotSelectionChanged();
d->releaseMouseEvent = true;
m_bMousePressed = false;
}
void KonqIconViewWidget::slotSaveIconPositions()
{
// WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
// This code is currently not used but left in for compatibility reasons.
// It can be removed in KDE 4.0
// Saving of desktop icon positions is now done in KDIconView::saveIconPositions()
// in tdebase/kdesktop/kdiconview.cc
// WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
if ( m_dotDirectoryPath.isEmpty() )
return;
if ( !m_bDesktop )
return; // Currently not available in Konqueror
kdDebug(1214) << "KonqIconViewWidget::slotSaveIconPositions" << endl;
KSimpleConfig dotDirectory( m_dotDirectoryPath );
TQIconViewItem *it = firstItem();
if ( !it )
return; // No more icons. Maybe we're closing and they've been removed already
while ( it )
{
KFileIVI *ivi = static_cast<KFileIVI *>( it );
KFileItem *item = ivi->item();
dotDirectory.setGroup( TQString( m_iconPositionGroupPrefix ).append( item->url().fileName() ) );
kdDebug(1214) << "KonqIconViewWidget::slotSaveIconPositions " << item->url().fileName() << " " << it->x() << " " << it->y() << endl;
dotDirectory.writeEntry( TQString( "X %1" ).arg( width() ), it->x() );
dotDirectory.writeEntry( TQString( "Y %1" ).arg( height() ), it->y() );
dotDirectory.writeEntry( "Exists", true );
it = it->nextItem();
}
TQStringList groups = dotDirectory.groupList();
TQStringList::ConstIterator gIt = groups.begin();
TQStringList::ConstIterator gEnd = groups.end();
for (; gIt != gEnd; ++gIt )
if ( (*gIt).left( m_iconPositionGroupPrefix.length() ) == m_iconPositionGroupPrefix )
{
dotDirectory.setGroup( *gIt );
if ( dotDirectory.hasKey( "Exists" ) )
dotDirectory.deleteEntry( "Exists", false );
else
{
kdDebug(1214) << "KonqIconViewWidget::slotSaveIconPositions deleting group " << *gIt << endl;
dotDirectory.deleteGroup( *gIt );
}
}
dotDirectory.sync();
// WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
// This code is currently not used but left in for compatibility reasons.
// It can be removed in KDE 4.0
// Saving of desktop icon positions is now done in KDIconView::saveIconPositions()
// in tdebase/kdesktop/kdiconview.cc
// WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
}
// Adapted version of TQIconView::insertInGrid, that works relative to
// m_IconRect, instead of the entire viewport.
void KonqIconViewWidget::insertInGrid(TQIconViewItem *item)
{
if (0L == item)
return;
if (!m_IconRect.isValid())
{
KIconView::insertInGrid(item);
return;
}
TQRegion r(m_IconRect);
TQIconViewItem *i = firstItem();
int y = -1;
for (; i; i = i->nextItem() )
{
r = r.subtract(i->rect());
y = QMAX(y, i->y() + i->height());
}
TQMemArray<TQRect> rects = r.rects();
TQMemArray<TQRect>::Iterator it = rects.begin();
bool foundPlace = FALSE;
for (; it != rects.end(); ++it)
{
TQRect rect = *it;
if (rect.width() >= item->width() && rect.height() >= item->height())
{
int sx = 0, sy = 0;
if (rect.width() >= item->width() + spacing())
sx = spacing();
if (rect.height() >= item->height() + spacing())
sy = spacing();
item->move(rect.x() + sx, rect.y() + sy);
foundPlace = true;
break;
}
}
if (!foundPlace)
item->move(m_IconRect.topLeft());
//item->dirty = false;
return;
}
/*
* The algorithm used for lineing up the icons could be called
* "beating flat the icon field". Imagine the icon field to be some height
* field on a regular grid, with the height being the number of icons in
* each grid element. Now imagine slamming on the field with a shovel or
* some other flat surface. The high peaks will be flattened and spread out
* over their adjacent areas. This is basically what the algorithm tries to
* simulate.
*
* First, the icons are binned to a grid of the desired size. If all bins
* are containing at most one icon, we're done, of course. We just have to
* move all icons to the center of each grid element.
* For each bin which has more than one icon in it, we calculate 4
* "friction coefficients", one for each cardinal direction. The friction
* coefficient of a direction is the number of icons adjacent in that
* direction. The idea is that this number is somewhat a measure in which
* direction the icons should flow: icons flow in the direction of lowest
* friction coefficient. We move a maximum of one icon per bin and loop over
* all bins. This procedure is repeated some maximum number of times or until
* no icons are moved anymore.
*
* I don't know if this algorithm is good or bad, I don't even know if it will
* work all the time. It seems a correct thing to do, however, and it seems to
* work particularly well. In any case, the number of runs is limited so there
* can be no races.
*/
void KonqIconViewWidget::lineupIcons()
{
// even if there are no items yet, calculate the maxItemWidth to have the correct
// item rect when we insert new items
// Create a grid of (ny x nx) bins.
int x0, y0, dx, dy, nx, ny;
gridValues( &x0, &y0, &dx, &dy, &nx, &ny );
int itemWidth = dx - spacing();
bool newItemWidth = false;
if ( maxItemWidth() != itemWidth ) {
newItemWidth = true;
setMaxItemWidth( itemWidth );
setFont( font() ); // Force calcRect()
}
if ( !firstItem() ) {
kdDebug(1203) << "No icons at all ?\n";
return;
}
int iconSize = m_size ? m_size : KGlobal::iconLoader()->currentSize( KIcon::Desktop );
typedef TQValueList<TQIconViewItem*> Bin;
Bin*** bins = new Bin**[nx];
int i;
int j;
for ( i = 0; i < nx ; i++ ) {
bins[i] = new Bin*[ny];
for ( j = 0; j < ny; j++ )
bins[i][j] = 0L;
}
// Insert items into grid
int textHeight = iconTextHeight() * fontMetrics().height();
for ( TQIconViewItem* item = firstItem(); item; item = item->nextItem() ) {
int x = item->x() + item->width() / 2 - x0;
int y = item->pixmapRect( false ).bottom() - iconSize / 2
- ( dy - ( iconSize + textHeight ) ) / 2 - y0;
int posX = QMIN( nx-1, QMAX( 0, x / dx ) );
int posY = QMIN( ny-1, QMAX( 0, y / dy ) );
if ( !bins[posX][posY] )
bins[posX][posY] = new Bin;
bins[posX][posY]->prepend( item );
}
// The shuffle code
int n, k;
const int infinity = 10000;
int nmoves = 1;
for ( n = 0; n < 30 && nmoves > 0; n++ ) {
nmoves = 0;
for ( i = 0; i < nx; i++ ) {
for ( j = 0; j < ny; j++ ) {
if ( !bins[i][j] || ( bins[i][j]->count() <= 1 ) )
continue;
// Calculate the 4 "friction coefficients".
int tf = 0, bf = 0, lf = 0, rf = 0;
for ( k = j-1; k >= 0 && bins[i][k] && bins[i][k]->count(); k-- )
tf += bins[i][k]->count();
if ( k == -1 )
tf += infinity;
for ( k = j+1; k < ny && bins[i][k] && bins[i][k]->count(); k++ )
bf += bins[i][k]->count();
if ( k == ny )
bf += infinity;
for ( k = i-1; k >= 0 && bins[k][j] && bins[k][j]->count(); k-- )
lf += bins[k][j]->count();
if ( k == -1 )
lf += infinity;
for ( k = i+1; k < nx && bins[k][j] && bins[k][j]->count(); k++ )
rf += bins[k][j]->count();
if ( k == nx )
rf += infinity;
// If we are stuck between walls, continue
if ( tf >= infinity && bf >= infinity &&
lf >= infinity && rf >= infinity )
continue;
// Is there a preferred lineup direction?
if ( m_LineupMode == LineupHorizontal ) {
tf += infinity;
bf += infinity;
}
else if ( m_LineupMode == LineupVertical ) {
lf += infinity;
rf += infinity;
}
// Move one item in the direction of the least friction
TQIconViewItem* movedItem;
Bin* items = bins[i][j];
int mini = QMIN( QMIN( tf, bf ), QMIN( lf, rf ) );
if ( tf == mini ) {
// move top item in (i,j) to (i,j-1)
Bin::iterator it = items->begin();
movedItem = *it;
for ( ++it; it != items->end(); ++it ) {
if ( (*it)->y() < movedItem->y() )
movedItem = *it;
}
items->remove( movedItem );
if ( !bins[i][j-1] )
bins[i][j-1] = new Bin;
bins[i][j-1]->prepend( movedItem );
}
else if ( bf ==mini ) {
// move bottom item in (i,j) to (i,j+1)
Bin::iterator it = items->begin();
movedItem = *it;
for ( ++it; it != items->end(); ++it ) {
if ( (*it)->y() > movedItem->y() )
movedItem = *it;
}
items->remove( movedItem );
if ( !bins[i][j+1] )
bins[i][j+1] = new Bin;
bins[i][j+1]->prepend( movedItem );
}
else if ( lf == mini )
{
// move left item in (i,j) to (i-1,j)
Bin::iterator it = items->begin();
movedItem = *it;
for ( ++it; it != items->end(); ++it ) {
if ( (*it)->x() < movedItem->x() )
movedItem = *it;
}
items->remove( movedItem );
if ( !bins[i-1][j] )
bins[i-1][j] = new Bin;
bins[i-1][j]->prepend( movedItem );
}
else {
// move right item in (i,j) to (i+1,j)
Bin::iterator it = items->begin();
movedItem = *it;
for ( ++it; it != items->end(); ++it ) {
if ( (*it)->x() > movedItem->x() )
movedItem = *it;
}
items->remove( movedItem );
if ( !bins[i+1][j] )
bins[i+1][j] = new Bin;
bins[i+1][j]->prepend( movedItem );
}
nmoves++;
}
}
}
// Perform the actual moving
TQRegion repaintRegion;
TQValueList<TQIconViewItem*> movedItems;
for ( i = 0; i < nx; i++ ) {
for ( j = 0; j < ny; j++ ) {
Bin* bin = bins[i][j];
if ( !bin )
continue;
if ( !bin->isEmpty() ) {
TQIconViewItem* item = bin->first();
int newX = x0 + i*dx + spacing() +
QMAX(0, ( (dx-spacing()) - item->width() ) / 2); // pixmap can be larger as iconsize
// align all icons vertically to their text
int newY = y0 + j*dy + dy - spacing() - ( item->pixmapRect().bottom() + 2 + textHeight );
if ( item->x() != newX || item->y() != newY ) {
TQRect oldRect = item->rect();
movedItems.prepend( item );
item->move( newX, newY );
if ( item->rect() != oldRect )
repaintRegion = repaintRegion.unite( oldRect );
}
}
delete bin;
bins[i][j] = 0L;
}
}
// repaint
if ( newItemWidth )
updateContents();
else {
// Repaint only repaintRegion...
TQMemArray<TQRect> rects = repaintRegion.rects();
for ( uint l = 0; l < rects.count(); l++ ) {
kdDebug( 1203 ) << "Repainting (" << rects[l].x() << ","
<< rects[l].y() << ")\n";
repaintContents( rects[l], false );
}
// Repaint icons that were moved
while ( !movedItems.isEmpty() ) {
repaintItem( movedItems.first() );
movedItems.remove( movedItems.first() );
}
}
for ( i = 0; i < nx ; i++ ) {
delete [] bins[i];
}
delete [] bins;
}
void KonqIconViewWidget::lineupIcons( TQIconView::Arrangement arrangement )
{
int x0, y0, dx, dy, nxmax, nymax;
gridValues( &x0, &y0, &dx, &dy, &nxmax, &nymax );
int textHeight = iconTextHeight() * fontMetrics().height();
TQRegion repaintRegion;
TQValueList<TQIconViewItem*> movedItems;
int nx = 0, ny = 0;
TQIconViewItem* item;
for ( item = firstItem(); item; item = item->nextItem() ) {
int newX = x0 + nx*dx + spacing() +
QMAX(0, ( (dx-spacing()) - item->width() ) / 2); // icon can be larger as defined
// align all icons vertically to their text
int newY = y0 + ny*dy + dy - spacing() - ( item->pixmapRect().bottom() + 2 + textHeight );
if ( item->x() != newX || item->y() != newY ) {
TQRect oldRect = item->rect();
movedItems.prepend( item );
item->move( newX, newY );
if ( item->rect() != oldRect )
repaintRegion = repaintRegion.unite( oldRect );
}
if ( arrangement == TQIconView::LeftToRight ) {
nx++;
if ( nx >= nxmax ) {
ny++;
nx = 0;
}
}
else {
ny++;
if ( ny >= nymax ) {
nx++;
ny = 0;
}
}
}
// Repaint only repaintRegion...
TQMemArray<TQRect> rects = repaintRegion.rects();
for ( uint l = 0; l < rects.count(); l++ ) {
kdDebug( 1203 ) << "Repainting (" << rects[l].x() << ","
<< rects[l].y() << ")\n";
repaintContents( rects[l], false );
}
// Repaint icons that were moved
while ( !movedItems.isEmpty() ) {
repaintItem( movedItems.first() );
movedItems.remove( movedItems.first() );
}
}
int KonqIconViewWidget::largestPreviewIconSize( int size ) const
{
int iconSize = size ? size : KGlobal::iconLoader()->currentSize( KIcon::Desktop );
if (iconSize < 28)
return 48;
if (iconSize < 40)
return 64;
if (iconSize < 60)
return 96;
if (iconSize < 120)
return 128;
return 192;
}
int KonqIconViewWidget::previewIconSize( int size ) const
{
int iconSize = size ? size : KGlobal::iconLoader()->currentSize( KIcon::Desktop );
if (!d->bBoostPreview)
return iconSize;
return largestPreviewIconSize( iconSize );
}
void KonqIconViewWidget::visualActivate(TQIconViewItem * item)
{
// Rect of the TQIconViewItem.
TQRect irect = item->rect();
// Rect of the QIconViewItem's pixmap area.
TQRect rect = item->pixmapRect();
// Adjust to correct position. If this isn't done, the fact that the
// text may be wider than the pixmap puts us off-centre.
rect.moveBy(irect.x(), irect.y());
// Adjust for scrolling (David)
rect.moveBy( -contentsX(), -contentsY() );
if (KGlobalSettings::showKonqIconActivationEffect() == true) {
KIconEffect::visualActivate(viewport(), rect, item->pixmap());
}
}
void KonqIconViewWidget::backgroundPixmapChange( const TQPixmap & )
{
viewport()->update();
}
void KonqIconViewWidget::setPreviewSettings( const TQStringList& settings )
{
d->previewSettings = settings;
updatePreviewMimeTypes();
int size = m_size;
m_size = -1; // little trick to force grid change in setIcons
setIcons( size ); // force re-determining all icons
}
const TQStringList& KonqIconViewWidget::previewSettings()
{
return d->previewSettings;
}
void KonqIconViewWidget::setNewURL( const TQString& url )
{
KURL u;
if ( url.startsWith( "/" ) )
u.setPath( url );
else
u = url;
setURL( u );
}
void KonqIconViewWidget::setCaseInsensitiveSort( bool b )
{
d->bCaseInsensitive = b;
}
bool KonqIconViewWidget::caseInsensitiveSort() const
{
return d->bCaseInsensitive;
}
bool KonqIconViewWidget::canPreview( KFileItem* item )
{
if ( !KGlobalSettings::showFilePreview( url() ) )
return false;
if ( d->pPreviewMimeTypes == 0L )
updatePreviewMimeTypes();
return mimeTypeMatch( item->mimetype(), *( d->pPreviewMimeTypes ) );
}
void KonqIconViewWidget::updatePreviewMimeTypes()
{
if ( d->pPreviewMimeTypes == 0L )
d->pPreviewMimeTypes = new TQStringList;
else
d->pPreviewMimeTypes->clear();
// Load the list of plugins to determine which mimetypes are supported
KTrader::OfferList plugins = KTrader::self()->query("ThumbCreator");
KTrader::OfferList::ConstIterator it;
for ( it = plugins.begin(); it != plugins.end(); ++it ) {
if ( d->previewSettings.contains((*it)->desktopEntryName()) ) {
TQStringList mimeTypes = (*it)->property("MimeTypes").toStringList();
for (TQStringList::ConstIterator mt = mimeTypes.begin(); mt != mimeTypes.end(); ++mt)
d->pPreviewMimeTypes->append(*mt);
}
}
}
#include "konq_iconviewwidget.moc"
/* vim: set et sw=4 ts=8 softtabstop=4: */
|