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
|
/***************************************************************************
frmprintwizard.cpp - description
-------------------
begin : Mon Sep 30 2002
copyright : (C) 2002 by Todd Shoemaker
: (C) 2007 Angelo Naselli
email : todd@theshoemakers.net
***************************************************************************/
/***************************************************************************
* *
* 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. *
* *
***************************************************************************/
// C Ansi includes.
extern "C"
{
#include <unistd.h>
}
// Include files for TQt
#include <tqlabel.h>
#include <tqpushbutton.h>
#include <tqcheckbox.h>
#include <tqspinbox.h>
#include <tqpainter.h>
#include <tqbuttongroup.h>
#include <tqradiobutton.h>
#include <tqdir.h>
#include <tqslider.h>
// Include files for KDE
#include <kprogress.h>
#include <kprocess.h>
#include <ksimpleconfig.h>
#include <tdelistbox.h>
#include <kprinter.h>
#include <tdelocale.h>
#include <klineedit.h>
#include <kdebug.h>
#include <tdemessagebox.h>
#include <kcombobox.h>
#include <kprogress.h>
#include <kurllabel.h>
#include <tdefiledialog.h>
#include <kpushbutton.h>
#include <tdeapplication.h>
#include <tdeaboutdata.h>
#include <khelpmenu.h>
#include <kiconloader.h>
#include <tdepopupmenu.h>
#include <tdeversion.h>
#include <tdefontcombo.h>
#include <kcolorcombo.h>
// Local includes
#include "kpaboutdata.h"
#include "pluginsversion.h"
#include "utils.h"
#include "cropframe.h"
#include "frmprintwizard.h"
#include "frmprintwizard.moc"
namespace KIPIPrintWizardPlugin
{
inline int buttonGroupSelectedId(const TQButtonGroup* group)
{
return group->selectedId();
}
FrmPrintWizard::FrmPrintWizard(TQWidget *parent, const char *name )
: FrmPrintWizardBase(parent, name)
{
// enable help buttons
for(int i = 0; i < pageCount(); ++i)
setHelpEnabled(page(i), true);
// ---------------------------------------------------------------
// About data and help button.
m_about = new KIPIPlugins::KPAboutData(I18N_NOOP("Print Wizard"),
0,
TDEAboutData::License_GPL,
I18N_NOOP("A KIPI plugin to print images"),
"(c) 2003-2004, Todd Shoemaker\n(c) 2007-2008, Angelo Naselli");
m_about->addAuthor("Todd Shoemaker", I18N_NOOP("Author"),
"todd@theshoemakers.net");
m_about->addAuthor("Angelo Naselli", I18N_NOOP("Developer and maintainer"),
"anaselli@linux.it");
m_about->addAuthor("Valerio Fuoglio", I18N_NOOP("Contributor"),
"valerio.fuoglio@gmail.com");
// setting-up icons on buttons
BtnBrowseOutputPath->setText("");
BtnBrowseOutputPath->setIconSet( SmallIconSet( "fileopen" ) );
BtnPrintOrderDown->setText("");
BtnPrintOrderDown->setIconSet( SmallIconSet( "down" ) );
BtnPrintOrderUp->setText("");
BtnPrintOrderUp->setIconSet( SmallIconSet( "up" ) );
BtnPreviewPageUp->setText("");
BtnPreviewPageUp->setIconSet( SmallIconSet( "go-next" ) );
BtnPreviewPageDown->setText("");
BtnPreviewPageDown->setIconSet( SmallIconSet( "go-previous" ) );
BtnCropPrev->setText("");
BtnCropPrev->setIconSet( SmallIconSet( "go-previous" ) );
BtnCropNext->setText("");
BtnCropNext->setIconSet( SmallIconSet( "go-next" ) );
BtnCropRotate->setText("");
BtnCropRotate->setIconSet( SmallIconSet( "rotate" ) );
// wizard buttons
TQPushButton *pBtn = backButton ();
pBtn->setText("");
pBtn->setIconSet( SmallIconSet( "go-previous" ) );
pBtn = nextButton ();
pBtn->setText("");
pBtn->setIconSet( SmallIconSet( "go-next" ) );
m_helpButton = helpButton();
KHelpMenu* helpMenu = new KHelpMenu(this, m_about, false);
helpMenu->menu()->removeItemAt(0);
helpMenu->menu()->insertItem(i18n("Plugin Handbook"), this, TQT_SLOT(slotHelp()), 0, -1, 0);
m_helpButton->setPopup( helpMenu->menu() );
// NOTE does it work????
setModal(false);
// ---------------------------------------------------------------
// turn off back button for first and last page
setBackEnabled(page(0), false);
m_currentPreviewPage = 0;
//TODO fix next two steps
m_pageSize = Unknown; // select a different page to force a refresh in initPhotoSizes.
initPhotoSizes(A4); // default to A4 for now.
EditOutputPath->setText(TQDir::homeDirPath());
connect(this, TQT_SIGNAL(selected(const TQString &)),
this, TQT_SLOT(FrmPrintWizardBaseSelected(const TQString &)));
connect(GrpOutputSettings, TQT_SIGNAL(clicked(int)),
this, TQT_SLOT(GrpOutputSettings_clicked(int)));
connect(m_captions, TQT_SIGNAL(activated(int)),
this, TQT_SLOT(CaptionChanged(int)));
connect(EditOutputPath, TQT_SIGNAL(textChanged(const TQString &)),
this, TQT_SLOT(EditOutputPath_textChanged(const TQString &)));
connect(BtnBrowseOutputPath, TQT_SIGNAL(clicked(void)),
this, TQT_SLOT(BtnBrowseOutputPath_clicked(void)));
CmbPaperSize->setCurrentItem(0);
connect(CmbPaperSize, TQT_SIGNAL(activated(int)),
this, TQT_SLOT(CmbPaperSize_activated(int)));
connect(BtnPrintOrderDown, TQT_SIGNAL(clicked(void)),
this, TQT_SLOT(BtnPrintOrderDown_clicked(void)));
connect(BtnPrintOrderUp, TQT_SIGNAL(clicked(void)),
this, TQT_SLOT(BtnPrintOrderUp_clicked(void)));
connect(BtnPreviewPageUp, TQT_SIGNAL(clicked(void)),
this, TQT_SLOT(BtnPreviewPageUp_clicked(void)));
connect(BtnPreviewPageDown, TQT_SIGNAL(clicked(void)),
this, TQT_SLOT(BtnPreviewPageDown_clicked(void)));
connect(BtnCropPrev, TQT_SIGNAL(clicked()),
this, TQT_SLOT(BtnCropPrev_clicked()));
connect(BtnCropNext, TQT_SIGNAL(clicked()),
this, TQT_SLOT(BtnCropNext_clicked()));
connect(BtnCropRotate, TQT_SIGNAL(clicked()),
this, TQT_SLOT(BtnCropRotate_clicked()));
loadSettings();
m_Proc = new TDEProcess;
*m_Proc << "kjobviewer" << "--all";
}
FrmPrintWizard::~FrmPrintWizard()
{
for(unsigned int i=0; i < m_photos.count(); i++)
if (m_photos.at(i))
delete m_photos.at(i);
m_photos.clear();
for(unsigned int i=0; i < m_photoSizes.count(); i++)
if (m_photoSizes.at(i))
delete m_photoSizes.at(i);
m_photoSizes.clear();
delete m_about;
}
void FrmPrintWizard::slotHelp()
{
TDEApplication::kApplication()->invokeHelp("printwizard","kipi-plugins");
}
void FrmPrintWizard::print( KURL::List fileList, TQString tempPath)
{
for(unsigned int i=0; i < m_photos.count(); i++)
if (m_photos.at(i))
delete m_photos.at(i);
m_photos.clear();
ListPrintOrder->clear();
for(unsigned int i=0; i < fileList.count(); i++)
{
TPhoto *photo = new TPhoto(150);
photo->filename = fileList[i];
m_photos.append(photo);
// load the print order listbox
ListPrintOrder->insertItem(photo->filename.filename());
}
ListPrintOrder->setCurrentItem(0);
m_tempPath = tempPath;
LblPhotoCount->setText(TQString::number(m_photos.count()));
BtnCropPrev->setEnabled(false);
if (m_photos.count() == 1)
BtnCropNext->setEnabled(false);
}
void FrmPrintWizard::BtnCropRotate_clicked()
{
// by definition, the cropRegion should be set by now,
// which means that after our rotation it will become invalid,
// so we will initialize it to -2 in an awful hack (this
// tells the cropFrame to reset the crop region, but don't
// automagically rotate the image to fit.
TPhoto *photo = m_photos.current();
photo->cropRegion = TQRect(-2, -2, -2, -2);
photo->rotation = (photo->rotation + 90) % 360;
updateCropFrame(photo, m_photos.at());
}
void FrmPrintWizard::setBtnCropEnabled()
{
if (m_photos.at() == 0)
BtnCropPrev->setEnabled(false);
else
BtnCropPrev->setEnabled(true);
if (m_photos.at() == (int)m_photos.count() - 1)
BtnCropNext->setEnabled(false);
else
BtnCropNext->setEnabled(true);
}
void FrmPrintWizard::BtnCropNext_clicked()
{
TPhoto *photo = 0;
photo = m_photos.next();
setBtnCropEnabled();
if (photo == 0)
{
m_photos.last();
return;
}
updateCropFrame(photo, m_photos.at());
}
void FrmPrintWizard::updateCropFrame(TPhoto *photo, int photoIndex)
{
TPhotoSize *s = m_photoSizes.at(ListPhotoSizes->currentItem());
cropFrame->init(photo, getLayout(photoIndex)->width(), getLayout(photoIndex)->height(), s->autoRotate);
LblCropPhoto->setText(i18n("Photo %1 of %2").arg( TQString::number(m_photos.at() + 1) ).arg( TQString::number(m_photos.count()) ));
}
void FrmPrintWizard::BtnCropPrev_clicked()
{
TPhoto *photo = 0;
photo = m_photos.prev();
setBtnCropEnabled();
if (photo == 0)
{
m_photos.first();
return;
}
updateCropFrame(photo, m_photos.at());
}
void FrmPrintWizard::FrmPrintWizardBaseSelected(const TQString &)
{
TQString pageName = this->currentPage()->name();
if (pageName == "pgPrinter")
{
// use this method to enable/disable the next button
GrpOutputSettings_clicked(GrpOutputSettings->id(GrpOutputSettings->selected()));
}
else
if (pageName == "pgLayout")
{
// create our photo sizes list
initPhotoSizes(m_pageSize);
previewPhotos();
}
else
if (pageName == "pgCrop")
{
TPhoto *photo = m_photos.first();
setBtnCropEnabled();
updateCropFrame(photo, m_photos.at());
} else
if (pageName == "pgFinished")
{
this->finishButton()->setEnabled(true);
// set the default crop regions if not already set
TPhotoSize *s = m_photoSizes.at(ListPhotoSizes->currentItem());
int i = 0;
for (TPhoto *photo = m_photos.first(); photo != 0; photo = m_photos.next())
{
if (photo->cropRegion == TQRect(-1, -1, -1, -1))
cropFrame->init(photo, getLayout(i)->width(), getLayout(i)->height(), s->autoRotate);
i++;
}
if (RdoOutputPrinter->isChecked())
{
KPrinter printer(false);
switch(m_pageSize)
{
case Letter : printer.setPageSize(KPrinter::Letter);
break;
case A4 : printer.setPageSize(KPrinter::A4);
break;
case A6 : printer.setPageSize(KPrinter::A6);
break;
default:
break;
}
if (m_fullbleed->isChecked())
{
printer.setFullPage(true);
printer.setMargins (0, 0, 0, 0);
}
#if KDE_IS_VERSION(3,2,0)
printer.setUsePrinterResolution(true);
#endif
if (printer.setup())
printPhotos(m_photos, s->layouts, printer);
}
else
if (RdoOutputFile->isChecked())
{
// now output the items
TQString path = EditOutputPath->text();
if (path.right(1) != "/")
path = path + "/";
path = path + "kipi_printwizard_";
printPhotosToFile(m_photos, path, s);
} else
if (RdoOutputGimp->isChecked())
{
// now output the items
TQString path = m_tempPath;
if (!checkTempPath(this, path))
return;
path = path + "kipi_tmp_";
if (m_gimpFiles.count() > 0)
removeGimpFiles();
m_gimpFiles = printPhotosToFile(m_photos, path, s);
TQStringList args;
args << "gimp-remote";
for(TQStringList::Iterator it = m_gimpFiles.begin(); it != m_gimpFiles.end(); ++it)
args << (*it);
if (!launchExternalApp(args))
{
KMessageBox::sorry(this, i18n("There was an error launching the Gimp. Please make sure it is properly installed."), i18n("KIPI")); return;
}
}
}
}
double getMaxDPI(TQPtrList<TPhoto> photos, TQPtrList<TQRect> layouts, unsigned int current)
{
Q_ASSERT(layouts.count() > 1);
TQRect *layout = layouts.at(1);
double maxDPI = 0.0;
for(; current < photos.count(); current++)
{
TPhoto *photo = photos.at(current);
double dpi = ((double)photo->cropRegion.width() + (double)photo->cropRegion.height()) /
(((double)layout->width() / 1000.0) + ((double)layout->height() / 1000.0));
if (dpi > maxDPI)
maxDPI = dpi;
// iterate to the next position
layout = layouts.next();
if (layout == 0)
{
break;
}
}
return maxDPI;
}
TQRect * FrmPrintWizard::getLayout(int photoIndex)
{
TPhotoSize *s = m_photoSizes.at(ListPhotoSizes->currentItem());
// how many photos would actually be printed, including copies?
int photoCount = (photoIndex + 1);
// how many pages? Recall that the first layout item is the paper size
int photosPerPage = s->layouts.count() - 1;
int remainder = photoCount % photosPerPage;
int retVal = remainder;
if (remainder == 0)
retVal = photosPerPage;
return s->layouts.at(retVal);
}
int FrmPrintWizard::getPageCount()
{
// get the selected layout
TPhotoSize *s = m_photoSizes.at(ListPhotoSizes->currentItem());
int photoCount = m_photos.count();
// how many pages? Recall that the first layout item is the paper size
int photosPerPage = s->layouts.count() - 1;
int remainder = photoCount % photosPerPage;
int emptySlots = 0;
if (remainder > 0)
emptySlots = photosPerPage - remainder;
int pageCount = photoCount / photosPerPage;
if (emptySlots > 0)
pageCount++;
return pageCount;
}
const float FONT_HEIGHT_RATIO = 0.8;
void FrmPrintWizard::printCaption(TQPainter &p, TPhoto*photo, int captionW, int captionH, TQString caption)
{
// PENDING anaselli TPhoto*photo will be needed to add a per photo caption management
TQStringList captionByLines;
uint captionIndex = 0;
while (captionIndex < caption.length())
{
TQString newLine;
bool breakLine = false; // End Of Line found
uint currIndex; // Caption TQString current index
// Check minimal lines dimension
//TODO fix length, maybe useless
uint captionLineLocalLength = 40;
for ( currIndex = captionIndex; currIndex < caption.length() && !breakLine; currIndex++ )
if( caption[currIndex] == TQChar('\n') || caption[currIndex].isSpace() )
breakLine = true;
if (captionLineLocalLength <= (currIndex - captionIndex))
captionLineLocalLength = (currIndex - captionIndex);
breakLine = false;
for ( currIndex = captionIndex;
currIndex <= captionIndex + captionLineLocalLength &&
currIndex < caption.length() && !breakLine;
currIndex++ )
{
breakLine = (caption[currIndex] == TQChar('\n')) ? true : false;
if (breakLine)
newLine.append( ' ' );
else
newLine.append( caption[currIndex] );
}
captionIndex = currIndex; // The line is ended
if ( captionIndex != caption.length() )
while ( !newLine.endsWith(" ") )
{
newLine.truncate(newLine.length() - 1);
captionIndex--;
}
captionByLines.prepend(newLine.stripWhiteSpace());
}
TQFont font(m_font_name->currentFont());
font.setStyleHint(TQFont::SansSerif);
font.setPixelSize( (int)(captionH * FONT_HEIGHT_RATIO) );
font.setWeight(TQFont::Normal);
TQFontMetrics fm( font );
int pixelsHigh = fm.height();
p.setFont(font);
p.setPen(m_font_color->color());
kdDebug( 51000 ) << "Number of lines " << (int)captionByLines.count() << endl;
// Now draw the caption
// TODO allow printing captions per photo and on top, bottom and vertically
for ( int lineNumber = 0; lineNumber < (int)captionByLines.count(); lineNumber++ )
{
if (lineNumber > 0)
p.translate(0, -(int)(pixelsHigh));
TQRect r(0, 0, captionW, captionH);
p.drawText(r, TQt::AlignLeft, captionByLines[lineNumber], -1, &r);
}
}
TQString FrmPrintWizard::captionFormatter(TPhoto *photo, const TQString& format)
{
TQString str=format;
TQFileInfo fi(photo->filename.path());
TQString resolution;
TQSize imageSize = photo->exiv2Iface()->getImageDimensions();
if (imageSize.isValid()) {
resolution = TQString( "%1x%2" ).arg( imageSize.width()).arg( imageSize.height());
}
str.replace("\\n", "\n");
// %f filename
// %c comment
// %d date-time
// %t exposure time
// %i iso
// %r resolution
// %a aperture
// %l focal length
str.replace("%f", fi.fileName());
str.replace("%c", photo->exiv2Iface()->getExifComment());
str.replace("%d", TDEGlobal::locale()->formatDateTime(photo->exiv2Iface()->getImageDateTime(),
false, false));
str.replace("%t", photo->exiv2Iface()->getExifTagString("Exif.Photo.ExposureTime"));
str.replace("%i", photo->exiv2Iface()->getExifTagString("Exif.Photo.ISOSpeedRatings"));
str.replace("%r", resolution);
str.replace("%a", photo->exiv2Iface()->getExifTagString("Exif.Photo.FNumber"));
str.replace("%l", photo->exiv2Iface()->getExifTagString("Exif.Photo.FocalLength"));
return str;
}
bool FrmPrintWizard::paintOnePage(TQPainter &p, TQPtrList<TPhoto> photos, TQPtrList<TQRect> layouts,
int captionType, unsigned int ¤t, bool useThumbnails)
{
Q_ASSERT(layouts.count() > 1);
if (photos.count() == 0) return true; // no photos => last photo
TQRect *srcPage = layouts.at(0);
TQRect *layout = layouts.at(1);
// scale the page size to best fit the painter
// size the rectangle based on the minimum image dimension
int destW = p.window().width();
int destH = p.window().height();
int srcW = srcPage->width();
int srcH = srcPage->height();
if (destW < destH)
{
destH = NINT((double)destW * ((double)srcH / (double)srcW));
if (destH > p.window().height())
{
destH = p.window().height();
destW = NINT((double)destH * ((double)srcW / (double)srcH));
}
}
else
{
destW = NINT((double)destH * ((double)srcW / (double)srcH));
if (destW > p.window().width())
{
destW = p.window().width();
destH = NINT((double)destW * ((double)srcH / (double)srcW));
}
}
double xRatio = (double)destW / (double)srcPage->width();
double yRatio = (double)destH / (double)srcPage->height();
int left = (p.window().width() - destW) / 2;
int top = (p.window().height() - destH) / 2;
// FIXME: may not want to erase the background page
p.eraseRect(left, top,
NINT((double)srcPage->width() * xRatio),
NINT((double)srcPage->height() * yRatio));
for(; current < photos.count(); current++)
{
TPhoto *photo = photos.at(current);
// crop
TQImage img;
if (useThumbnails)
img = photo->thumbnail().convertToImage();
else
img = photo->loadPhoto();
// next, do we rotate?
if (photo->rotation != 0)
{
// rotate
TQWMatrix matrix;
matrix.rotate(photo->rotation);
img = img.xForm(matrix);
}
if (useThumbnails)
{
// scale the crop region to thumbnail coords
double xRatio = 0.0;
double yRatio = 0.0;
if (photo->thumbnail().width() != 0)
xRatio = (double)photo->thumbnail().width() / (double) photo->width();
if (photo->thumbnail().height() != 0)
yRatio = (double)photo->thumbnail().height() / (double) photo->height();
int x1 = NINT((double)photo->cropRegion.left() * xRatio);
int y1 = NINT((double)photo->cropRegion.top() * yRatio);
int w = NINT((double)photo->cropRegion.width() * xRatio);
int h = NINT((double)photo->cropRegion.height() * yRatio);
img = img.copy(TQRect(x1, y1, w, h));
}
else
img = img.copy(photo->cropRegion);
int x1 = NINT((double)layout->left() * xRatio);
int y1 = NINT((double)layout->top() * yRatio);
int w = NINT((double)layout->width() * xRatio);
int h = NINT((double)layout->height() * yRatio);
p.drawImage( TQRect(x1 + left, y1 + top, w, h), img );
if (captionType > 0)
{
p.save();
TQString caption;
TQString format;
switch (captionType)
{
case FileNames:
format = "%f";
break;
case ExifDateTime:
format = "%d";
break;
case Comment:
format = "%c";
break;
case Free:
format = m_FreeCaptionFormat->text();
break;
default:
kdWarning( 51000 ) << "UNKNOWN caption type " << captionType << endl;
break;
}
caption = captionFormatter(photo, format);
kdDebug( 51000 ) << "Caption " << caption << endl;
// draw the text at (0,0), but we will translate and rotate the world
// before drawing so the text will be in the correct location
// next, do we rotate?
int captionW = w-2;
double ratio = m_font_size->value() * 0.01;
int captionH = (int)(TQMIN(w, h) * ratio);
int exifOrientation = photo->exiv2Iface()->getImageOrientation();
int orientatation = photo->rotation;
//ORIENTATION_ROT_90_HFLIP .. ORIENTATION_ROT_270
if (exifOrientation == KExiv2Iface::KExiv2::ORIENTATION_ROT_90_HFLIP ||
exifOrientation == KExiv2Iface::KExiv2::ORIENTATION_ROT_90 ||
exifOrientation == KExiv2Iface::KExiv2::ORIENTATION_ROT_90_VFLIP ||
exifOrientation == KExiv2Iface::KExiv2::ORIENTATION_ROT_270)
orientatation = (photo->rotation + 270) % 360; // -90 degrees
if(orientatation == 90 || orientatation == 270)
{
captionW = h;
}
p.rotate(orientatation);
kdDebug( 51000 ) << "rotation " << photo->rotation << " orientation " << orientatation << endl;
int tx = left;
int ty = top;
switch(orientatation) {
case 0 : {
tx += x1 + 1;
ty += y1 + (h - captionH - 1);
break;
}
case 90 : {
tx = top + y1 + 1;
ty = -left - x1 - captionH - 1;
break;
}
case 180 : {
tx = -left - x1 - w + 1;
ty = -top -y1 - (captionH + 1);
break;
}
case 270 : {
tx = -top - y1 - h + 1;
ty = left + x1 + (w - captionH)- 1;
break;
}
}
p.translate(tx, ty);
printCaption(p, photo, captionW, captionH, caption);
p.restore();
} // caption
// iterate to the next position
layout = layouts.next();
if (layout == 0)
{
current++;
break;
}
}
// did we print the last photo?
return (current < photos.count());
}
// Like above, but outputs to an initialized TQImage. UseThumbnails is
// not an option.
// We have to use TQImage for saving to a file, otherwise we would have
// to use a TQPixmap, which will have the same bit depth as the display.
// So someone with an 8-bit display would not be able to save 24-bit
// images!
bool FrmPrintWizard::paintOnePage(TQImage &p, TQPtrList<TPhoto> photos, TQPtrList<TQRect> layouts,
int captionType, unsigned int ¤t)
{
Q_ASSERT(layouts.count() > 1);
TQRect *srcPage = layouts.at(0);
TQRect *layout = layouts.at(1);
// scale the page size to best fit the painter
// size the rectangle based on the minimum image dimension
int destW = p.width();
int destH = p.height();
int srcW = srcPage->width();
int srcH = srcPage->height();
if (destW < destH)
{
destH = NINT((double)destW * ((double)srcH / (double)srcW));
if (destH > p.height())
{
destH = p.height();
destW = NINT((double)destH * ((double)srcW / (double)srcH));
}
}
else
{
destW = NINT((double)destH * ((double)srcW / (double)srcH));
if (destW > p.width())
{
destW = p.width();
destH = NINT((double)destW * ((double)srcH / (double)srcW));
}
}
double xRatio = (double)destW / (double)srcPage->width();
double yRatio = (double)destH / (double)srcPage->height();
int left = (p.width() - destW) / 2;
int top = (p.height() - destH) / 2;
p.fill(0xffffff);
for(; current < photos.count(); current++)
{
TPhoto *photo = photos.at(current);
// crop
TQImage img;
img = photo->loadPhoto();
// next, do we rotate?
if (photo->rotation != 0)
{
// rotate
TQWMatrix matrix;
matrix.rotate(photo->rotation);
img = img.xForm(matrix);
}
img = img.copy(photo->cropRegion);
int x1 = NINT((double)layout->left() * xRatio);
int y1 = NINT((double)layout->top() * yRatio);
int w = NINT((double)layout->width() * xRatio);
int h = NINT((double)layout->height() * yRatio);
// We can use scaleFree because the crop frame should have the proper dimensions.
img = img.smoothScale(w, h, TQ_ScaleFree);
// don't have drawimage, so we copy the pixels over manually
for(int srcY = 0; srcY < img.height(); srcY++)
for(int srcX = 0; srcX < img.width(); srcX++)
{
p.setPixel(x1 + left + srcX, y1 + top + srcY, img.pixel(srcX, srcY));
}
if (captionType != NoCaptions)
{
// Now draw the caption
TQString caption;
TQString format;
switch (captionType)
{
case FileNames:
format = "%f";
break;
case ExifDateTime:
format = "%d";
break;
case Comment:
format = "%c";
break;
case Free:
format = m_FreeCaptionFormat->text();
break;
default:
kdWarning( 51000 ) << "UNKNOWN caption type " << captionType << endl;
break;
}
caption = captionFormatter(photo, format);
kdDebug( 51000 ) << "Caption " << caption << endl;
int captionW = w-2;
double ratio = m_font_size->value() * 0.01;
int captionH = (int)(TQMIN(w, h) * ratio);
int exifOrientation = photo->exiv2Iface()->getImageOrientation();
int orientatation = photo->rotation;
//ORIENTATION_ROT_90_HFLIP .. ORIENTATION_ROT_270
if (exifOrientation == KExiv2Iface::KExiv2::ORIENTATION_ROT_90_HFLIP ||
exifOrientation == KExiv2Iface::KExiv2::ORIENTATION_ROT_90 ||
exifOrientation == KExiv2Iface::KExiv2::ORIENTATION_ROT_90_VFLIP ||
exifOrientation == KExiv2Iface::KExiv2::ORIENTATION_ROT_270)
orientatation = (photo->rotation + 270) % 360; // -90 degrees
if (orientatation == 90 || orientatation == 270)
{
captionW = h;
}
TQPixmap pixmap(w-2, img.height()-2);
//TODO black is not ok if font is black...
pixmap.fill(TQt::black);
TQPainter painter;
painter.begin(&pixmap);
painter.rotate(orientatation);
kdDebug( 51000 ) << "rotation " << photo->rotation << " orientation " << orientatation << endl;
int tx = left;
int ty = top;
switch(orientatation) {
case 0 : {
tx += x1 + 1;
ty += y1 + (h - captionH - 1);
break;
}
case 90 : {
tx = top + y1 + 1;
ty = -left - x1 - captionH - 1;
break;
}
case 180 : {
tx = -left - x1 - w + 1;
ty = -top -y1 - (captionH + 1);
break;
}
case 270 : {
tx = -top - y1 - h + 1;
ty = left + x1 + (w - captionH)- 1;
break;
}
}
painter.translate(tx, ty);
printCaption(painter, photo, captionW, captionH, caption);
painter.end();
// now put it on picture
TQImage fontImage = pixmap.convertToImage();
TQRgb black = TQColor(0, 0, 0).rgb();
for(int srcY = 0; srcY < fontImage.height(); srcY++)
for(int srcX = 0; srcX < fontImage.width(); srcX++)
{
if (fontImage.pixel(srcX, srcY) != black)
p.setPixel(srcX, srcY, fontImage.pixel(srcX, srcY));
}
} // caption
// iterate to the next position
layout = layouts.next();
if (layout == 0)
{
current++;
break;
}
}
// did we print the last photo?
return (current < photos.count());
}
// update the pages to be printed and preview first/last pages
void FrmPrintWizard::previewPhotos()
{
// get the selected layout
TPhotoSize *s = m_photoSizes.at(ListPhotoSizes->currentItem());
int photoCount = m_photos.count();
// how many pages? Recall that the first layout item is the paper size
int photosPerPage = s->layouts.count() - 1;
int remainder = photoCount % photosPerPage;
int emptySlots = 0;
if (remainder > 0)
emptySlots = photosPerPage - remainder;
int pageCount = photoCount / photosPerPage;
if (emptySlots > 0)
pageCount++;
LblPhotoCount->setText(TQString::number(photoCount));
LblSheetsPrinted->setText(TQString::number(pageCount));
LblEmptySlots->setText(TQString::number(emptySlots));
// photo previews
// preview the first page.
// find the first page of photos
int count = 0;
int page = 0;
unsigned int current = 0;
for (TPhoto *photo = m_photos.first(); photo != 0; photo = m_photos.next())
{
if (page == m_currentPreviewPage) {
photo->cropRegion.setRect(-1, -1, -1, -1);
photo->rotation = 0;
int w = s->layouts.at(count+1)->width();
int h = s->layouts.at(count+1)->height();
cropFrame->init(photo, w, h, s->autoRotate, false);
}
count++;
if (count >= photosPerPage)
{
if (page == m_currentPreviewPage)
break;
page++;
current += photosPerPage;
count = 0;
}
}
// send this photo list to the painter
TQPixmap img(BmpFirstPagePreview->width(), BmpFirstPagePreview->height());
TQPainter p;
p.begin(&img);
p.fillRect(0, 0, img.width(), img.height(), this->paletteBackgroundColor());
paintOnePage(p, m_photos, s->layouts, m_captions->currentItem(), current, true);
p.end();
BmpFirstPagePreview->setPixmap(img);
LblPreview->setText(i18n("Page ") + TQString::number(m_currentPreviewPage + 1) + i18n(" of ") + TQString::number(getPageCount()));
LblPreview->setText(i18n("Page %1 of %2").arg(m_currentPreviewPage + 1).arg(getPageCount()));
manageBtnPreviewPage();
manageBtnPrintOrder();
}
void FrmPrintWizard::ListPhotoSizes_highlighted ( int )
{
m_currentPreviewPage = 0;
for (TPhoto *photo = m_photos.first(); photo != 0; photo = m_photos.next())
{
photo->cropRegion.setRect(-1, -1, -1, -1);
photo->rotation = 0;
}
previewPhotos();
}
void FrmPrintWizard::ListPhotoSizes_selected( TQListBoxItem * )
{
previewPhotos();
}
void FrmPrintWizard::manageBtnPreviewPage()
{
BtnPreviewPageDown->setEnabled(true);
BtnPreviewPageUp->setEnabled(true);
if (m_currentPreviewPage == 0)
{
BtnPreviewPageDown->setEnabled(false);
}
if ((m_currentPreviewPage + 1) == getPageCount())
{
BtnPreviewPageUp->setEnabled(false);
}
}
void FrmPrintWizard::manageBtnPrintOrder()
{
if (ListPrintOrder->currentItem() == -1)
return;
BtnPrintOrderDown->setEnabled(true);
BtnPrintOrderUp->setEnabled(true);
if (ListPrintOrder->currentItem() == 0)
{
BtnPrintOrderUp->setEnabled(false);
}
if (uint(ListPrintOrder->currentItem() + 1) == ListPrintOrder->count())
{
BtnPrintOrderDown->setEnabled(false);
}
}
void FrmPrintWizard::ListPhotoOrder_highlighted ( int index )
{
EditCopies->blockSignals(true);
EditCopies->setValue ( m_photos.at(index)->copies );
EditCopies->blockSignals(false);
manageBtnPrintOrder();
}
void FrmPrintWizard::ListPrintOrder_selected( TQListBoxItem * )
{
int currentIndex = ListPrintOrder->currentItem();
EditCopies->blockSignals(true);
EditCopies->setValue ( m_photos.at(currentIndex)->copies );
EditCopies->blockSignals(false);
manageBtnPrintOrder();
}
void FrmPrintWizard::EditCopies_valueChanged( int copies )
{
if (copies < 1)
return;
int currentIndex = ListPrintOrder->currentItem();
TQString item = ListPrintOrder->selectedItem()->text();
TPhoto *pCurPhoto = m_photos.at(currentIndex);
KURL fileName = pCurPhoto->filename;
if ( pCurPhoto->copies >= copies )
{
// removing copies
if (pCurPhoto->copies == 1 || pCurPhoto->copies == copies)
return;
ListPrintOrder->blockSignals(true);
ListPrintOrder->setSelected (currentIndex, false);
for (int removing = pCurPhoto->copies - copies; removing >0 ;removing--)
{
for (unsigned int index = 0; index < ListPrintOrder->count(); index++)
{
if (ListPrintOrder->text(index) == item)
{
TPhoto *pPhoto = m_photos.at(index);
m_photos.remove(index);
delete (pPhoto);
ListPrintOrder->removeItem(index);
break;
}
}
}
ListPrintOrder->blockSignals(false);
currentIndex = -1;
}
else
{
// adding copies
for (int adding = copies - pCurPhoto->copies; adding >0 ;adding--)
{
TPhoto *pPhoto = new TPhoto(150);
pPhoto->filename = pCurPhoto->filename;
m_photos.insert(currentIndex, pPhoto);
ListPrintOrder->insertItem(pPhoto->filename.filename(), currentIndex);
}
}
LblPhotoCount->setText(TQString::number(m_photos.count()));
int index = 0;
for (TPhoto *pPhoto = m_photos.first(); pPhoto != 0; pPhoto = m_photos.next(), index++)
{
if (pPhoto->filename == fileName)
{
pPhoto->copies = copies;
if (currentIndex == -1)
currentIndex = index;
}
}
ListPrintOrder->blockSignals(true);
ListPrintOrder->setCurrentItem(currentIndex);
ListPrintOrder->setSelected( currentIndex, true );
ListPrintOrder->blockSignals(false);
previewPhotos();
}
void FrmPrintWizard::removeGimpFiles()
{
for(TQStringList::Iterator it = m_gimpFiles.begin(); it != m_gimpFiles.end(); ++it)
{
if (TQFile::exists(*it))
{
if (TQFile::remove(*it) == false)
{
KMessageBox::sorry(this, i18n("Could not remove the Gimp's temporary files."));
break;
}
}
}
}
// this is called when Finish is clicked.
void FrmPrintWizard::accept()
{
saveSettings();
// if we output to Gimp, we need to remove the temp files
if (m_gimpFiles.count() > 0)
removeGimpFiles();
TQDialog::accept();
}
// this is called when Cancel is clicked.
void FrmPrintWizard::reject()
{
m_cancelPrinting = true;
if (m_gimpFiles.count() > 0)
removeGimpFiles();
TQDialog::reject();
}
void FrmPrintWizard::printPhotos(TQPtrList<TPhoto> photos, TQPtrList<TQRect> layouts, KPrinter &printer)
{
m_cancelPrinting = false;
LblPrintProgress->setText("");
PrgPrintProgress->setProgress(0);
PrgPrintProgress->setTotalSteps(photos.count());
this->finishButton()->setEnabled(false);
TDEApplication::kApplication()->processEvents();
TQPainter p;
p.begin(&printer);
unsigned int current = 0;
bool printing = true;
while(printing)
{
printing = paintOnePage(p, photos, layouts, m_captions->currentItem(), current);
if (printing)
printer.newPage();
PrgPrintProgress->setProgress(current);
TDEApplication::kApplication()->processEvents();
if (m_cancelPrinting)
{
printer.abort();
return;
}
}
p.end();
this->finishButton()->setEnabled(true);
if (m_kjobviewer->isChecked())
if ( !m_Proc->start() )
kdDebug( 51000 ) << "Error running kjobviewr\n";
LblPrintProgress->setText(i18n("Complete. Click Finish to exit the Print Wizard."));
}
TQStringList FrmPrintWizard::printPhotosToFile(TQPtrList<TPhoto> photos, TQString &baseFilename, TPhotoSize* layouts)
{
Q_ASSERT(layouts->layouts.count() > 1);
m_cancelPrinting = false;
LblPrintProgress->setText("");
PrgPrintProgress->setProgress(0);
PrgPrintProgress->setTotalSteps(photos.count());
this->finishButton()->setEnabled(false);
TDEApplication::kApplication()->processEvents();
unsigned int current = 0;
int pageCount = 1;
bool printing = true;
TQStringList files;
TQRect *srcPage = layouts->layouts.at(0);
while (printing)
{
// make a pixmap to save to file. Make it just big enough to show the
// highest-dpi image on the page without losing data.
double dpi = layouts->dpi;
if (dpi == 0.0)
dpi = getMaxDPI(photos, layouts->layouts, current) * 1.1;
int w = NINT(srcPage->width() / 1000.0 * dpi);
int h = NINT(srcPage->height() / 1000.0 * dpi);
TQImage *img = new TQImage(w, h, 32);
if (!img)
break;
// save this page out to file
TQString filename = baseFilename + TQString::number(pageCount) + ".jpeg";
bool saveFile = true;
if (TQFile::exists(filename))
{
int result = KMessageBox::warningYesNoCancel( this,
i18n("The following file will be overwritten. Do you want to overwrite this file?") +
"\n\n" + filename);
if (result == KMessageBox::No)
saveFile = false;
else if (result == KMessageBox::Cancel)
{
delete img;
break;
}
}
// paint this page, even if we aren't saving it to keep the page
// count accurate.
printing = paintOnePage(*img, photos, layouts->layouts, m_captions->currentItem(), current);
if (saveFile)
{
files.append(filename);
img->save(filename, "JPEG");
}
delete img;
pageCount++;
PrgPrintProgress->setProgress(current);
TDEApplication::kApplication()->processEvents();
if (m_cancelPrinting)
break;
}
this->finishButton()->setEnabled(true);
// did we cancel?
if (printing)
LblPrintProgress->setText(i18n("Printing Canceled."));
else
{
if (m_kjobviewer->isChecked())
if ( !m_Proc->start() )
kdDebug( 51000 ) << "Error launching kjobviewr\n";
LblPrintProgress->setText(i18n("Complete. Click Finish to exit the Print Wizard."));
}
return files;
}
void FrmPrintWizard::loadSettings()
{
KSimpleConfig config("kipirc");
config.setGroup("PrintWizard");
//internal PageSize
PageSize pageSize = (PageSize)config.readNumEntry("PageSize", (int)A4); //Default A4
initPhotoSizes(pageSize);
CmbPaperSize->setCurrentItem(int(pageSize));
//Use Margins
m_fullbleed->setChecked(config.readBoolEntry("NoMargins", false));
// captions
int captions = config.readNumEntry("ImageCaptions", 0);
m_captions->setCurrentItem(captions);
// caption color
TQColor defColor(TQt::yellow);
TQColor color = config.readColorEntry("CaptionColor", &defColor);
m_font_color->setColor(color);
// caption font
TQFont defFont("Sans Serif");
TQFont font = config.readFontEntry ( "CaptionFont", &defFont);
m_font_name->setCurrentFont(font.family());
// caption size
int fontSize = config.readNumEntry("CaptionSize", 4);
m_font_size->setValue(fontSize);
// free caption
TQString captionTxt = config.readEntry("FreeCaption");
m_FreeCaptionFormat->setText(captionTxt);
//enable right caption stuff
CaptionChanged(captions);
// set the last output path
TQString outputPath = config.readPathEntry("OutputPath", EditOutputPath->text());
EditOutputPath->setText(outputPath);
// set the proper radio button
int id = config.readNumEntry("PrintOutput", GrpOutputSettings->id(RdoOutputPrinter));
GrpOutputSettings->setButton(id);
// photo size
TQString photoSize = config.readEntry("PhotoSize");
TQListBoxItem *item = ListPhotoSizes->findItem(photoSize);
if (item)
ListPhotoSizes->setCurrentItem(item);
else
ListPhotoSizes->setCurrentItem(0);
// kjobviewer
m_kjobviewer->setChecked(config.readBoolEntry("KjobViewer", true));
}
// save the current wizard settings
void FrmPrintWizard::saveSettings()
{
KSimpleConfig config("kipirc");
config.setGroup("PrintWizard");
config.writeEntry("PageSize", (int)m_pageSize);
config.writeEntry("NoMargins", m_fullbleed->isChecked());
// output
int output = 0;
if (RdoOutputPrinter->isChecked())
output = GrpOutputSettings->id(RdoOutputPrinter);
else
if (RdoOutputFile->isChecked())
output = GrpOutputSettings->id(RdoOutputFile);
else
if (RdoOutputGimp->isChecked())
output = GrpOutputSettings->id(RdoOutputGimp);
config.writeEntry("PrintOutput", output);
// image captions
config.writeEntry("ImageCaptions", m_captions->currentItem());
// caption color
config.writeEntry("CaptionColor", m_font_color->color());
// caption font
config.writeEntry ("CaptionFont", TQFont(m_font_name->currentFont()));
// caption size
config.writeEntry("CaptionSize", m_font_size->value());
// free caption
config.writeEntry("FreeCaption", m_FreeCaptionFormat->text());
// output path
config.writePathEntry("OutputPath", EditOutputPath->text());
// photo size
config.writeEntry("PhotoSize", ListPhotoSizes->currentText());
// kjobviewer
config.writeEntry("KjobViewer", m_kjobviewer->isChecked());
}
void FrmPrintWizard::GrpOutputSettings_clicked(int id)
{
this->nextButton()->setEnabled(false);
// disable next buttons when appropriate
if (id == GrpOutputSettings->id(RdoOutputPrinter))
this->nextButton()->setEnabled(true);
else
if (id == GrpOutputSettings->id(RdoOutputFile))
{
if (!EditOutputPath->text().isEmpty())
{
TQFileInfo fileInfo(EditOutputPath->text());
if (fileInfo.exists() && fileInfo.isDir())
this->nextButton()->setEnabled(true);
}
}
else
if (id == GrpOutputSettings->id(RdoOutputGimp))
{
this->nextButton()->setEnabled(true);
}
}
void FrmPrintWizard::BtnBrowseOutputPath_clicked( void )
{
TQString newPath = KFileDialog::getExistingDirectory(EditOutputPath->text(), this, "Select Output Folder");
if (newPath.isEmpty())
return;
// assume this directory exists
EditOutputPath->setText(newPath);
GrpOutputSettings_clicked(GrpOutputSettings->id(GrpOutputSettings->selected()));
}
void FrmPrintWizard::CaptionChanged(int captionUsed)
{
switch (captionUsed)
{
case NoCaptions:
// disable m_font_frame and mFreeOutputFormat
m_font_frame->setEnabled(false);
m_FreeCaptionFormat->setEnabled(false);
m_free_label->setEnabled(false);
break;
case Free:
m_font_frame->setEnabled(true);
m_FreeCaptionFormat->setEnabled(true);
m_free_label->setEnabled(true);
break;
case FileNames:
case ExifDateTime:
case Comment:
default:
// disable mFreeOutputFormat
m_font_frame->setEnabled(true);
m_FreeCaptionFormat->setEnabled(false);
m_free_label->setEnabled(false);
break;
}
}
void FrmPrintWizard::EditOutputPath_textChanged(const TQString &)
{
GrpOutputSettings_clicked(GrpOutputSettings->id(GrpOutputSettings->selected()));
}
void FrmPrintWizard::CmbPaperSize_activated( int index )
{
PageSize pageSize = (PageSize)index;
initPhotoSizes(pageSize);
if (pageSize > A6)
{
KMessageBox::information (this,
i18n("Don't forget to set up the correct page size according to your printer settings"),
i18n("Page size settings"), "pageSizeInfo");
}
}
void FrmPrintWizard::BtnPrintOrderUp_clicked() {
if (ListPrintOrder->currentItem() == 0)
return;
int currentIndex = ListPrintOrder->currentItem();
TQString item1 = ListPrintOrder->selectedItem()->text();
TQString item2 = ListPrintOrder->item(currentIndex - 1)->text();
// swap these items
ListPrintOrder->changeItem(item2, currentIndex);
ListPrintOrder->changeItem(item1, currentIndex - 1);
// the list box items are swapped, now swap the items in the photo list
TPhoto *photo1 = m_photos.at(currentIndex);
TPhoto *photo2 = m_photos.at(currentIndex - 1);
m_photos.remove(currentIndex - 1);
m_photos.remove(currentIndex - 1);
m_photos.insert(currentIndex - 1, photo2);
m_photos.insert(currentIndex - 1, photo1);
previewPhotos();
}
void FrmPrintWizard::BtnPrintOrderDown_clicked() {
if (ListPrintOrder->currentItem() == (signed int)ListPrintOrder->count() - 1)
return;
int currentIndex = ListPrintOrder->currentItem();
TQString item1 = ListPrintOrder->selectedItem()->text();
TQString item2 = ListPrintOrder->item(currentIndex + 1)->text();
// swap these items
ListPrintOrder->changeItem(item2, currentIndex);
ListPrintOrder->changeItem(item1, currentIndex + 1);
// the list box items are swapped, now swap the items in the photo list
TPhoto *photo1 = m_photos.at(currentIndex);
TPhoto *photo2 = m_photos.at(currentIndex + 1);
m_photos.remove(currentIndex);
m_photos.remove(currentIndex);
m_photos.insert(currentIndex, photo1);
m_photos.insert(currentIndex, photo2);
previewPhotos();
}
void FrmPrintWizard::BtnPreviewPageDown_clicked() {
if (m_currentPreviewPage == 0)
return;
m_currentPreviewPage--;
previewPhotos();
}
void FrmPrintWizard::BtnPreviewPageUp_clicked() {
if (m_currentPreviewPage == getPageCount() - 1)
return;
m_currentPreviewPage++;
previewPhotos();
}
// create a MxN grid of photos, fitting on the page
TPhotoSize * createPhotoGrid(int pageWidth, int pageHeight, TQString label, int rows, int columns) {
int MARGIN = (int)((pageWidth + pageHeight) / 2 * 0.04 + 0.5);
int GAP = MARGIN / 4;
int photoWidth = (pageWidth - (MARGIN * 2) - ((columns-1) * GAP)) / columns;
int photoHeight = (pageHeight - (MARGIN * 2) - ((rows-1) * GAP)) / rows;
TPhotoSize *p = new TPhotoSize;
p->label = label;
p->dpi = 100;
p->autoRotate = false;
p->layouts.append(new TQRect(0, 0, pageWidth, pageHeight));
int row = 0;
for(int y=MARGIN; row < rows && y < pageHeight - MARGIN; y += photoHeight + GAP) {
int col = 0;
for(int x=MARGIN; col < columns && x < pageWidth - MARGIN; x += photoWidth + GAP) {
p->layouts.append(new TQRect(x, y, photoWidth, photoHeight));
col++;
}
row++;
}
return p;
}
void FrmPrintWizard::initPhotoSizes(PageSize pageSize)
{
// don't refresh anything if we haven't changed page sizes.
if (pageSize == m_pageSize)
return;
m_pageSize = pageSize;
// cleanng m_pageSize memory before invoking clear()
for(unsigned int i=0; i < m_photoSizes.count(); i++)
if (m_photoSizes.at(i))
delete m_photoSizes.at(i);
m_photoSizes.clear();
switch (pageSize)
{
// ====================== LETTER SIZE =====================
case Letter:
{
TPhotoSize *p;
// ========== 5 x 3.5
p = new TPhotoSize;
p->label = i18n("3.5 x 5\"");
p->dpi = 0;
p->autoRotate = true;
// page size
p->layouts.append(new TQRect(0, 0, 8500, 11000));
// photo layouts
p->layouts.append(new TQRect( 700, 500, 3500, 5000));
p->layouts.append(new TQRect(4300, 500, 3500, 5000));
p->layouts.append(new TQRect( 700, 5600, 3500, 5000));
p->layouts.append(new TQRect(4300, 5600, 3500, 5000));
// add to the list
m_photoSizes.append(p);
// ========== 4 x 6
p = new TPhotoSize;
p->label = i18n("4 x 6\"");
p->dpi = 0;
p->autoRotate = true;
// page size
p->layouts.append(new TQRect(0, 0, 8500, 11000));
// photo layouts
p->layouts.append(new TQRect( 225, 500, 4000, 6000));
p->layouts.append(new TQRect(4275, 500, 4000, 6000));
p->layouts.append(new TQRect(1250, 6600, 6000, 4000));
// add to the list
m_photoSizes.append(p);
// ========== 4 x 6 Album
p = new TPhotoSize;
p->label = i18n("4 x 6\" Album");
p->dpi = 0;
p->autoRotate = true;
// page size
p->layouts.append(new TQRect(0, 0, 8500, 11000));
// photo layouts
p->layouts.append(new TQRect( 1250, 1000, 6000, 4000));
p->layouts.append(new TQRect( 1250, 6000, 6000, 4000));
// add to the list
m_photoSizes.append(p);
// ========== 5 x 7
p = new TPhotoSize;
p->label = i18n("5 x 7\"");
p->dpi = 0;
p->autoRotate = true;
// page size
p->layouts.append(new TQRect(0, 0, 8500, 11000));
// photo layouts
p->layouts.append(new TQRect( 750, 500, 7000, 5000));
p->layouts.append(new TQRect( 750, 5750, 7000, 5000));
// add to the list
m_photoSizes.append(p);
// ========== 8 x 10
p = new TPhotoSize;
p->label = i18n("8 x 10\"");
p->dpi = 0;
p->autoRotate = true;
// page size
p->layouts.append(new TQRect(0, 0, 8500, 11000));
// photo layouts
p->layouts.append(new TQRect(250, 500, 8000, 10000));
// add to the list
m_photoSizes.append(p);
// thumbnails
m_photoSizes.append(createPhotoGrid(8500, 11000, i18n("Thumbnails"), 5, 4));
// small thumbnails
m_photoSizes.append(createPhotoGrid(8500, 11000, i18n("Small Thumbnails"), 6, 5));
// album collage 1
p = new TPhotoSize;
p->label = i18n("Album Collage 1 (9 photos)");
p->dpi = 0;
p->autoRotate = false;
// page size
p->layouts.append(new TQRect(0, 0, 8500, 11000));
// photo layouts
// photo 1 is in the center, 3x4.5
p->layouts.append(new TQRect(2750, 3250, 3000, 4500));
// the remaining 1.5x2 photos begin with upper left and circle around
// top row
p->layouts.append(new TQRect(750, 750, 1500, 2000));
p->layouts.append(new TQRect(3500, 750, 1500, 2000));
p->layouts.append(new TQRect(6250, 750, 1500, 2000));
p->layouts.append(new TQRect(6250, 4500, 1500, 2000));
p->layouts.append(new TQRect(6250, 8250, 1500, 2000));
p->layouts.append(new TQRect(3500, 8250, 1500, 2000));
p->layouts.append(new TQRect(750, 8250, 1500, 2000));
p->layouts.append(new TQRect(750, 4500, 1500, 2000));
m_photoSizes.append(p);
// album collage 2
p = new TPhotoSize;
p->label = i18n("Album Collage 2 (6 photos)");
p->dpi = 0;
p->autoRotate = false;
// page size
p->layouts.append(new TQRect(0, 0, 8500, 11000));
// photo layouts
p->layouts.append(new TQRect(1000, 1000, 3000, 3000));
p->layouts.append(new TQRect(5000, 1000, 2500, 1250));
p->layouts.append(new TQRect(5000, 2750, 2500, 1250));
p->layouts.append(new TQRect(1000, 5000, 1500, 2000));
p->layouts.append(new TQRect(2750, 5000, 4750, 2000));
p->layouts.append(new TQRect(1000, 8000, 6500, 2000));
m_photoSizes.append(p);
} // letter
break;
// ====================== A4 SIZE =====================
case A4:
{
// A4 is 21 x 29.7cm
TPhotoSize *p;
// ========== 20x25cm
p = new TPhotoSize;
p->dpi = 0;
p->autoRotate = true;
p->label = i18n("21 x 29.7cm");
// page size
p->layouts.append(new TQRect(0, 0, 2100, 2970));
// photo layouts
p->layouts.append(new TQRect( 0, 0, 2100, 2970));
// add to the list
m_photoSizes.append(p);
// ========== 6x9 cm - 8 photos
p = new TPhotoSize;
p->dpi = 0;
p->autoRotate = true;
p->label = i18n("6 x 9cm (8 photos)");
// page size
p->layouts.append(new TQRect(0, 0, 2100, 2970));
// photo layouts
p->layouts.append(new TQRect( 100, 100, 900, 600));
p->layouts.append(new TQRect(1100, 100, 900, 600));
p->layouts.append(new TQRect( 100, 800, 900, 600));
p->layouts.append(new TQRect(1100, 800, 900, 600));
p->layouts.append(new TQRect( 100, 1500, 900, 600));
p->layouts.append(new TQRect(1100, 1500, 900, 600));
p->layouts.append(new TQRect( 100, 2200, 900, 600));
p->layouts.append(new TQRect(1100, 2200, 900, 600));
// add to the list
m_photoSizes.append(p);
// ========== 9x13
p = new TPhotoSize;
p->dpi = 0;
p->autoRotate = true;
p->label = i18n("9 x 13cm");
// page size
p->layouts.append(new TQRect(0, 0, 2100, 2970));
// photo layouts
p->layouts.append(new TQRect( 100, 100, 900, 1300));
p->layouts.append(new TQRect(1100, 100, 900, 1300));
p->layouts.append(new TQRect( 100, 1500, 900, 1300));
p->layouts.append(new TQRect(1100, 1500, 900, 1300));
// add to the list
m_photoSizes.append(p);
// ========== 10x13.33cm
p = new TPhotoSize;
p->dpi = 0;
p->autoRotate = true;
p->label = i18n("10 x 13.33cm");
// page size
p->layouts.append(new TQRect(0, 0, 2100, 2970));
// photo layouts
p->layouts.append(new TQRect( 50, 100, 1000, 1333));
p->layouts.append(new TQRect(1060, 100, 1000, 1333));
p->layouts.append(new TQRect( 50, 1500, 1000, 1333));
p->layouts.append(new TQRect(1060, 1500, 1000, 1333));
// add to the list
m_photoSizes.append(p);
// ========== 10x15cm
p = new TPhotoSize;
p->dpi = 0;
p->autoRotate = true;
p->label = i18n("10 x 15cm");
// page size
p->layouts.append(new TQRect(0, 0, 2100, 2970));
// photo layouts
p->layouts.append(new TQRect( 50, 150, 1000, 1500));
p->layouts.append(new TQRect(1060, 150, 1000, 1500));
p->layouts.append(new TQRect( 300, 1750, 1500, 1000));
// add to the list
m_photoSizes.append(p);
// ========== 10x15cm album
p = new TPhotoSize;
p->dpi = 0;
p->autoRotate = true;
p->label = i18n("10 x 15cm Album");
// page size
p->layouts.append(new TQRect(0, 0, 2100, 2970));
// photo layouts
p->layouts.append(new TQRect( 300, 350, 1500, 1000));
p->layouts.append(new TQRect( 300, 1620, 1500, 1000));
// add to the list
m_photoSizes.append(p);
// ========== 11.5x15cm album
p = new TPhotoSize;
p->dpi = 0;
p->autoRotate = true;
p->label = i18n("11.5 x 15cm Album");
// page size
p->layouts.append(new TQRect(0, 0, 2100, 2970));
// photo layouts
p->layouts.append(new TQRect( 300, 250, 1500, 1100));
p->layouts.append(new TQRect( 300, 1570, 1500, 1100));
// add to the list
m_photoSizes.append(p);
// ========== 13x18cm
p = new TPhotoSize;
p->dpi = 0;
p->autoRotate = true;
p->label = i18n("13 x 18cm");
// page size
p->layouts.append(new TQRect(0, 0, 2100, 2970));
// photo layouts
p->layouts.append(new TQRect( 150, 150, 1800, 1300));
p->layouts.append(new TQRect( 150, 1520, 1800, 1300));
// add to the list
m_photoSizes.append(p);
// ========== 20x25cm
p = new TPhotoSize;
p->dpi = 0;
p->autoRotate = true;
p->label = i18n("20 x 25cm");
// page size
p->layouts.append(new TQRect(0, 0, 2100, 2970));
// photo layouts
p->layouts.append(new TQRect( 50, 230, 2000, 2500));
// add to the list
m_photoSizes.append(p);
// thumbnails
m_photoSizes.append(createPhotoGrid(2100, 2970, i18n("Thumbnails"), 5, 4));
// small thumbnails
m_photoSizes.append(createPhotoGrid(2100, 2970, i18n("Small Thumbnails"), 6, 5));
} // A4
break;
// ====================== A6 SIZE =====================
case A6:
{
// A6 is 10.5 x 14.8 cm
TPhotoSize *p;
// ========== 9x13
p = new TPhotoSize;
p->dpi = 0;
p->autoRotate = true;
p->label = i18n("9 x 13cm");
// page size
p->layouts.append(new TQRect(0, 0, 1050, 1480));
// photo layouts
p->layouts.append(new TQRect( 50, 100, 900, 1300));
// add to the list
m_photoSizes.append(p);
// ========== 10x15cm
p = new TPhotoSize;
p->dpi = 0;
p->autoRotate = true;
p->label = i18n("10.5 x 14.8cm");
// page size
p->layouts.append(new TQRect(0, 0, 1050, 1480));
// photo layouts
p->layouts.append(new TQRect(0, 0, 1050, 1480));
// add to the list
m_photoSizes.append(p);
// thumbnails
m_photoSizes.append(createPhotoGrid(1050, 1480, i18n("Thumbnails"), 5, 4));
// small thumbnails
m_photoSizes.append(createPhotoGrid(1050, 1480, i18n("Small Thumbnails"), 6, 5));
} // A6
break;
// ====================== 10x15cm SIZE =====================
case P10X15:
{
// 10x15cm photo paper is 4x6" so the right size is 10.16 x 15.24 cm
TPhotoSize *p;
// ========== 10x15cm
p = new TPhotoSize;
p->dpi = 0;
p->autoRotate = true;
p->label = i18n("10 x 15cm");
// page size
p->layouts.append(new TQRect(0, 0, 1016, 1524));
// photo layouts
p->layouts.append(new TQRect(0, 0, 1016, 1524));
// add to the list
m_photoSizes.append(p);
// ========== 9x13
p = new TPhotoSize;
p->dpi = 0;
p->autoRotate = true;
p->label = i18n("9 x 13cm");
// page size
p->layouts.append(new TQRect(0, 0, 1016, 1524));
// photo layouts
p->layouts.append(new TQRect( 50, 100, 900, 1300));
// add to the list
m_photoSizes.append(p);
// thumbnails
m_photoSizes.append(createPhotoGrid(1016, 1524, i18n("Thumbnails"), 5, 4));
// small thumbnails
m_photoSizes.append(createPhotoGrid(1016, 1524, i18n("Small Thumbnails"), 6, 5));
} // 10x15 cm
break;
// ====================== 13x18cm SIZE =====================
case P13X18:
{
// 10x18cm photo paper is 5x7" so the right conversion
// is 12.7 x 17.78 cm
TPhotoSize *p;
// ========== 10x15cm
p = new TPhotoSize;
p->dpi = 0;
p->autoRotate = true;
p->label = i18n("13 x 18cm");
// page size
p->layouts.append(new TQRect(0, 0, 1270, 1778));
// photo layouts
p->layouts.append(new TQRect(0, 0, 1270, 1778));
// add to the list
m_photoSizes.append(p);
// ========== 10x15cm
p = new TPhotoSize;
p->dpi = 0;
p->autoRotate = true;
p->label = i18n("10 x 15cm");
// page size
p->layouts.append(new TQRect(0, 0, 1270, 1778));
// photo layouts
p->layouts.append(new TQRect(0, 0, 1016, 1524));
// add to the list
m_photoSizes.append(p);
// ========== 9x13
p = new TPhotoSize;
p->dpi = 0;
p->autoRotate = true;
p->label = i18n("9 x 13cm");
// page size
p->layouts.append(new TQRect(0, 0, 1270, 1778));
// photo layouts
p->layouts.append(new TQRect( 50, 100, 900, 1300));
// add to the list
m_photoSizes.append(p);
// thumbnails
m_photoSizes.append(createPhotoGrid(1270, 1778, i18n("Thumbnails"), 5, 4));
// small thumbnails
m_photoSizes.append(createPhotoGrid(1270, 1778, i18n("Small Thumbnails"), 6, 5));
} // 13x18 cm
break;
default:
{
kdDebug( 51000 ) << "Initializing Unsupported page layouts\n";
// We don't support this page size yet. Just create a default page.
TPhotoSize *p;
p = new TPhotoSize;
p->dpi = 0;
p->autoRotate = false;
p->label = i18n("Unsupported Paper Size");
// page size
p->layouts.append(new TQRect(0, 0, 8500, 11000));
p->layouts.append(new TQRect(0, 0, 8500, 11000));
// add to the list
m_photoSizes.append(p);
}
break;
};
// load the photo sizes into the listbox
ListPhotoSizes->clear();
for (TPhotoSize *s = m_photoSizes.first(); s != 0; s = m_photoSizes.next())
ListPhotoSizes->insertItem(s->label);
ListPhotoSizes->setCurrentItem(0);
}
} // NameSpace KIPIPrintWizardPlugin
|