[r45]: trunk / EnlargerDialog.cpp Maximize Restore History

Download this file

EnlargerDialog.cpp    1570 lines (1330 with data), 62.1 kB

   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
/* ----------------------------------------------------------------
SmillaEnlarger - resize, especially magnify bitmaps in high quality
EnlargerDialog.cpp: the Qt Dialog
Copyright (C) 2009 Mischa Lusteck
This program is free software;
you can redistribute it and/or modify it under the terms of the
GNU General Public License as published by the Free Software Foundation;
either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY;
without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, see <http://www.gnu.org/licenses/>.
---------------------------------------------------------------------- */
#include <QFileDialog>
#include <QDesktopServices> // for getting std. picture-directory
#include <QDir>
#include <QSettings>
#include <QtGui>
#include <iostream>
#include "EnlargerDialog.h"
#include "ui_enlargerdialog.h"
#include "previewField.h"
#include "EnlargerThread.h"
#include "ImageEnlargerCode/FractTab.h"
#include "CalcQueue.h"
const int historyClipMax = 100;
using namespace std;
EnlargerDialog::EnlargerDialog(QWidget *parent)
: QMainWindow(parent), ui(new Ui::EnlargerDialog),
calcThread( new EnlargerThread ), previewThread( new EnlargerThread )
{
setUpdatesEnabled( false );
ui->setupUi(this);
MenuBarSetup();
setCentralWidget( ui->centralwidget );
zoomFact = 1.0;
aspectX = aspectY = 1.0;
freeAspectRatio = false;
zoomInt = 100;
zoomUpdateMod = useZoom;
ui->zoomRButton->setChecked( true );
// avoid indirect self-calls of setZoom via diverse value-changes
// recursionBlocker set true at begin of SetZoom, false at end
setZoom_recursionBlocker = false;
// create the calculation queue
theCalcQueue = new CalcQueue();
ui->queueListView->setModel( theCalcQueue->DisplayModel() );
// set up clipping history
historyClipIdx = 0;
historyClipX0 = new float[ historyClipMax + 1 ];
historyClipY0 = new float[ historyClipMax + 1 ];
historyClipX1 = new float[ historyClipMax + 1 ];
historyClipY1 = new float[ historyClipMax + 1 ];
QString picDir = QDesktopServices::storageLocation ( QDesktopServices::PicturesLocation );
srcDir.setPath( picDir );
SetDestDir( picDir );
ui->sourceDirLabel->setText( " < none > ");
ui->destFileEdit->setText( "enlarged.jpg" );
ui->srcCheckBox->setChecked( true );
ui->load2Button->setEnabled( false );
connect( ui->load1Button, SIGNAL(clicked()), this, SLOT(slot_load1()) );
connect( ui->load2Button, SIGNAL(clicked()), this, SLOT(slot_load2()) );
connect( ui->comboBox, SIGNAL(activated ( const QString & )),
this, SLOT(slot_comboChanged( const QString & )) );
connect( ui->srcCheckBox, SIGNAL(stateChanged( int ) ), this, SLOT(slot_checkBoxChanged( int ) ) );
connect( ui->previewButton, SIGNAL(clicked()), this, SLOT(DoPreview()) );
//connect( ui->calcButton, SIGNAL(clicked()), this, SLOT(slot_calc()) );
connect( ui->calcButton, SIGNAL(clicked()), this, SLOT(slot_queueCalc()) );
connect( ui->previewField, SIGNAL(selectionChanged(float,float)),
ui->selectField, SLOT(moveSelection( float, float ) ) );
connect( ui->selectField, SIGNAL(selectionChanged(float,float)),
ui->previewField, SLOT(moveSelection( float, float ) ) );
connect( ui->selectField, SIGNAL(selectionChanged(float,float)),
this, SLOT(stopPreview() ) );
connect( ui->selectField, SIGNAL(clippingChanged( float, float, float, float )),
this, SLOT(slot_setClipping( float, float, float, float ) ) );
connect( ui->clipResetButton, SIGNAL(clicked()), this, SLOT(slot_resetClipping()) );
//--------- ToolTips ---------------------------------
QString tipStr;
tipStr = QString(" All you see here will be enlarged. \n");
tipStr += QString(" With the left mouse-button you can select a new \n");
tipStr += QString(" cropping rectangle or grab the frame of the preview-square ");
SetToolTip( ui->srcGroupBox, ui->selectField, tipStr );
tipStr = QString(" Preview - shows a ( small ) part of the result \n");
tipStr += QString(" in the desired magnification. \n" );
tipStr += QString(" Move it with left mouse-button ");
SetToolTip( ui->previewGroupBox, ui->previewField, tipStr );
SetToolTip( ui->newWidthBox, QString(" explicitly set Width of result " ) );
SetToolTip( ui->newHeightBox, QString(" explicitly set Height of result " ) );
SetToolTip( ui->clipResetButton, QString(" Undo the last cropping " ) );
SetToolTip( ui->zoomSlider, ui->zoomSpinBox, QString(" Set the scale factor ( in percent ) " ) );
SetToolTip( ui->previewButton, QString(" calculate the preview " ) );
SetToolTip( ui->calcButton, QString(" calculate the enlarged image " ) );
SetToolTip( ui->deNoiseSlider, ui->deNoiseSpinBox, QString(" remove some noise/artifacts in the source image " ) );
SetToolTip( ui->preSharpSlider, ui->preSharpSpinBox, QString(" simple sharpening of the source image " ) );
SetToolTip( ui->sharpSlider, ui->sharpSpinBox, QString(" higher values for sharper edges in the result " ) );
SetToolTip( ui->flatSlider, ui->flatSpinBox, QString(" higher values for less gradients, more 'painted' looking results ") );
SetToolTip( ui->ditherSlider, ui->ditherSpinBox, QString(" higher values for more grainy noise in the result ") );
SetToolTip( ui->fractNoiseSlider, ui->fractNoiseSpinBox,QString(" modify result with plasma fractal noise" ) );
SetToolTip( ui->comboBox, QString(" select an image in the source directory " ) );
SetToolTip( ui->destFileEdit, QString(" filename of the enlarged image " ) );
SetToolTip( ui->sourceDirLabel, QString(" Source directory " ) );
SetToolTip( ui->destDirLabel, QString(" Destination directory " ) );
SetToolTip( ui->load1Button, QString(" select new source image " ) );
SetToolTip( ui->load2Button, QString(" change destination directory " ) );
SetToolTip( ui->srcCheckBox, QString(" write result into source directory " ) );
//--------- End of ToolTips ---------------------------------
// calc & preview Threads
connect( theCalcQueue, SIGNAL( tellProgress(int) ), ui->progressBar, SLOT( setValue(int) ) );
connect( theCalcQueue, SIGNAL(tellJobCount(int,int)), this, SLOT(slot_ShowJobCount(int,int)) );
// connect( calcThread, SIGNAL( badAlloc() ), this, SLOT(BadAllocMessage() ) );
connect( calcThread, SIGNAL( imageSaved() ), this, SLOT(slot_imageSaved() ) );
connect( calcThread, SIGNAL( imageNotSaved() ), this, SLOT(slot_imageNotSaved() ) );
connect( previewThread, SIGNAL( tellProgress(int) ), this, SLOT( slot_showPreviewProgress(int) ) );
connect( previewThread, SIGNAL( enlargedImage(QImage) ), this, SLOT(slot_showPreview(QImage)) );
// Sliders & Boxes
const int zoomMin = 1, zoomMax = 3000;
const int sharpMin = 0, sharpMax = 100;
const int flatMin = 0, flatMax = 100;
const int ditherMin = 0, ditherMax = 100;
const int deNoiseMin = 0, deNoiseMax = 100;
const int preSharpMin = 0, preSharpMax = 100;
const int fractNoiseMin=0, fractNoiseMax= 100;
ui->newWidthBox ->setRange( 1, 100000 );
ui->newHeightBox->setRange( 1, 100000 );
ui->zoomSpinBox->setRange( zoomMin, zoomMax );
ui->zoomSlider ->setRange( zoomMin, zoomMax );
ui->zoomSpinBox->setSuffix( "%" );
connect( ui->zoomSlider, SIGNAL(valueChanged(int)), ui->zoomSpinBox, SLOT(setValue(int)) );
connect( ui->zoomSpinBox, SIGNAL(valueChanged(int)), ui->zoomSlider, SLOT(setValue(int)) );
connect( ui->zoomSpinBox, SIGNAL(valueChanged(int)), this, SLOT(SetZoomInt(int)) );
connect( ui->newWidthBox, SIGNAL(valueChanged(int)), this, SLOT(SetNewWidth(int)) );
connect( ui->newHeightBox, SIGNAL(valueChanged(int)), this, SLOT(SetNewHeight(int)) );
connect( ui->zoomRButton, SIGNAL(pressed()), this, SLOT(slot_ZoomRadioButton()) );
connect( ui->widthRButton, SIGNAL(pressed()), this, SLOT(slot_WidthRadioButton()) );
connect( ui->heightRButton, SIGNAL(pressed()), this, SLOT(slot_HeightRadioButton()) );
ui->zoomSpinBox->setValue( 1100 );
ui->sharpSpinBox->setRange( sharpMin, sharpMax );
ui->sharpSlider ->setRange( sharpMin, sharpMax );
connect( ui->sharpSlider, SIGNAL(valueChanged(int)), ui->sharpSpinBox, SLOT(setValue(int)) );
connect( ui->sharpSpinBox, SIGNAL(valueChanged(int)), ui->sharpSlider, SLOT(setValue(int)) );
ui->sharpSlider->setValue( 80 );
ui->flatSpinBox->setRange( flatMin, flatMax );
ui->flatSlider ->setRange( flatMin, flatMax );
connect( ui->flatSlider, SIGNAL(valueChanged(int)), ui->flatSpinBox, SLOT(setValue(int)) );
connect( ui->flatSpinBox, SIGNAL(valueChanged(int)), ui->flatSlider, SLOT(setValue(int)) );
ui->flatSlider->setValue( 20 );
ui->ditherSpinBox->setRange( ditherMin, ditherMax );
ui->ditherSlider ->setRange( ditherMin, ditherMax );
connect( ui->ditherSlider, SIGNAL(valueChanged(int)), ui->ditherSpinBox, SLOT(setValue(int)) );
connect( ui->ditherSpinBox, SIGNAL(valueChanged(int)), ui->ditherSlider, SLOT(setValue(int)) );
ui->ditherSlider->setValue( 20 );
ui->deNoiseSpinBox->setRange( deNoiseMin, deNoiseMax );
ui->deNoiseSlider ->setRange( deNoiseMin, deNoiseMax );
connect( ui->deNoiseSlider, SIGNAL(valueChanged(int)), ui->deNoiseSpinBox, SLOT(setValue(int)) );
connect( ui->deNoiseSpinBox, SIGNAL(valueChanged(int)), ui->deNoiseSlider, SLOT(setValue(int)) );
ui->deNoiseSlider->setValue( 50 );
ui->preSharpSpinBox->setRange( preSharpMin, preSharpMax );
ui->preSharpSlider ->setRange( preSharpMin, preSharpMax );
connect( ui->preSharpSlider, SIGNAL(valueChanged(int)), ui->preSharpSpinBox, SLOT(setValue(int)) );
connect( ui->preSharpSpinBox, SIGNAL(valueChanged(int)), ui->preSharpSlider, SLOT(setValue(int)) );
ui->preSharpSlider->setValue( 0 );
ui->fractNoiseSpinBox->setRange( fractNoiseMin, fractNoiseMax );
ui->fractNoiseSlider ->setRange( fractNoiseMin, fractNoiseMax );
connect( ui->fractNoiseSlider, SIGNAL(valueChanged(int)), ui->fractNoiseSpinBox, SLOT(setValue(int)) );
connect( ui->fractNoiseSpinBox, SIGNAL(valueChanged(int)), ui->fractNoiseSlider, SLOT(setValue(int)) );
ui->fractNoiseSlider->setValue( 0 );
SetSource( QImage(":/smilla.bmp") );
ui->progressBar->setRange( 0, 100 );
ui->progressBar->setValue( 100 );
ui->comboBox->setSizeAdjustPolicy( QComboBox::AdjustToContentsOnFirstShow );
ui->comboBox->setMinimumContentsLength( 30 );
ui->comboBox->clear();
currentSrcName = " < Smilla > ";
currentSrcPath = ":/smilla.bmp";
ui->comboBox->addItem( currentSrcName );
//----- Parameter Edit -----
ui->paramCombo->setEditable( true );
ui->paramCombo->setSizeAdjustPolicy( QComboBox::AdjustToContentsOnFirstShow );
ui->paramCombo->setMinimumContentsLength( 15 );
ui->paramCombo->clear();
ui->paramCombo->setCompleter( 0 );
ui->paramCombo->setInsertPolicy( QComboBox::InsertAtCurrent );
connect( ui->paramAddButton, SIGNAL( clicked() ), this, SLOT(slot_AddParam()) );
connect( ui->paramDelButton, SIGNAL( clicked() ), this, SLOT(slot_DelParam()) );
connect( ui->paramCombo, SIGNAL( activated(int) ), this, SLOT(slot_SetParamSlidersFromCombo(int)) );
connect( ui->paramChangeCheckBox, SIGNAL(stateChanged( int ) ), this, SLOT(slot_ParamCheckBoxChanged( int ) ) );
//----- CalcQueue -----
connect( ui->clearQueueButton, SIGNAL( clicked() ), this, SLOT(slot_QueueClear()) );
connect( ui->removeJobButton, SIGNAL( clicked() ), this, SLOT(slot_QueueRemoveSelected()) );
connect( ui->cleanUpQueueButton,SIGNAL( clicked() ), this, SLOT(slot_QueueRemoveEnded()) );
ResetDialog();
setAcceptDrops(true); // Drag and Drop: accept drops ( of source files )
PrintStatusText(" Welcome to SmillaEnlarger 0.8.5. Drop a file onto the window to open it." );
theSettings = 0; // Pointer to settings, none loaded yet
ReadSettings();
SetZoom( 5.0 );
DoPreview();
IncDestName(); // if dstName exists already: add or inc number at end of name
resize( minimumSize() );
setUpdatesEnabled( true );
}
EnlargerDialog::~EnlargerDialog()
{
delete[] historyClipX0;
delete[] historyClipY0;
delete[] historyClipX1;
delete[] historyClipY1;
delete calcThread;
delete previewThread;
if( theSettings != 0 )
delete theSettings;
delete theCalcQueue;
delete ui;
}
void EnlargerDialog::MenuBarSetup( void ) {
QMenu *fileMenu, *helpMenu;
QAction *aboutA, *quitA, *loadA, *saveA, *pasteA;
QAction *smallA;
QAction *helpStartA, *helpClipA, *helpSliderA, *helpDropA, *helpLoadA, *helpMoreA;
fileMenu = menuBar()->addMenu(tr("File"));
helpMenu = menuBar()->addMenu(tr("Help"));
loadA = fileMenu->addAction(tr("&Open..."));
saveA = fileMenu->addAction(tr("Enlarge && Save"));
pasteA = fileMenu->addAction(tr("Paste"));
smallA = fileMenu->addAction(tr("small mode"));
smallA->setCheckable( true );
smallA->setChecked( false );
quitA = fileMenu->addAction(tr("Quit"));
aboutA = helpMenu->addAction(tr("About"));
helpStartA = helpMenu->addAction(tr("Getting Started"));
helpClipA = helpMenu->addAction(tr("Preview && Cropping"));
helpSliderA = helpMenu->addAction(tr("Zoom && Sliders"));
helpDropA = helpMenu->addAction(tr("Drop && Paste"));
helpLoadA = helpMenu->addAction(tr("Load && Save"));
helpMoreA = helpMenu->addAction(tr("more Help..."));
loadA->setShortcut( QKeySequence::Open );
saveA->setShortcut( QKeySequence::Save );
pasteA->setShortcut( QKeySequence::Paste );
connect( aboutA, SIGNAL(triggered()), this, SLOT( InfoMessage()) );
connect( loadA, SIGNAL(triggered()), this, SLOT( slot_load1()) );
connect( saveA, SIGNAL(triggered()), this, SLOT( slot_calc()) );
connect( pasteA, SIGNAL(triggered()), this, SLOT( slot_paste()) );
connect( smallA, SIGNAL(toggled(bool)), this, SLOT( slot_SmallMode( bool )) );
connect( quitA, SIGNAL(triggered()), this, SLOT( close()) );
connect( helpStartA, SIGNAL(triggered()), this, SLOT( HelpMessageStart()) );
connect( helpClipA, SIGNAL(triggered()), this, SLOT( HelpMessageClip()) );
connect( helpSliderA, SIGNAL(triggered()), this, SLOT( HelpMessageSlider()) );
connect( helpDropA, SIGNAL(triggered()), this, SLOT( HelpMessageDrop()) );
connect( helpLoadA, SIGNAL(triggered()), this, SLOT( HelpMessageLoad()) );
connect( helpMoreA, SIGNAL(triggered()), this, SLOT( HelpMessageMore()) );
}
void EnlargerDialog::slot_load1( void ) {
QString path,body,type;
QString fileName = QFileDialog::getOpenFileName(this,
tr("Open File"), srcDir.absolutePath(),
tr("Image Files (*.bmp *.jpg *.png *.jpeg *.ppm *.tif *.tiff *.gif )") );
if (!fileName.isEmpty()) {
TryOpenSource( fileName );
}
}
void EnlargerDialog::slot_load2( void ) {
QString path,body,type;
QString fileName = QFileDialog::getExistingDirectory(this, tr("Open Directory"), dstDir.absolutePath() );
if (!fileName.isEmpty()) {
SetDestDir( fileName );
}
IncDestName(); // if dstName exists already: add or inc number at end of name
}
void EnlargerDialog::slot_comboChanged( const QString & txt ) {
if( txt == currentSrcName )
return;
if( srcDir.exists( txt ) ) {
currentSrcName = txt;
currentSrcPath = srcDir.absoluteFilePath( txt );
QString path, body, type;
SetSource( QImage( srcDir.absoluteFilePath( txt ) ) );
SplitFileName( txt, path, body, type );
ui->destFileEdit->setText( body+"_e."+type );
IncDestName(); // if dstName exists already: add or inc number at end of name
stopPreview();
}
}
void EnlargerDialog::slot_checkBoxChanged( int state ) {
if( ui->srcCheckBox->isChecked() ) {
ui->load2Button->setEnabled( false );
SetDestDir( srcDir.absolutePath() );
IncDestName(); // if dstName exists already: add or inc number at end of name
}
else {
ui->load2Button->setEnabled( true );
}
}
void EnlargerDialog::stopEnlarge( void ) {
calcThread->StopEnlarge();
PrintStatusText( "Calculation stopped. " );
ResetDialog();
}
void EnlargerDialog::stopPreview( void ) {
previewThread->StopEnlarge();
ui->previewProgressLabel->setText(" " );
}
void EnlargerDialog::DoPreview( void ) {
if( ZoomX() < 1.0 && ZoomY() < 1.0 )
return;
QRect dstRect;
QImage srcImage;
QImage preImage;
EnlargeFormat format;
EnlargeParamInt enlargeParam;
dstRect = ui->previewField->DstRect();
srcImage = ui->previewField->theImage();
format.srcWidth = srcImage.width();
format.srcHeight = srcImage.height();
format.SetScaleFact( ZoomX(), ZoomY() );
format.SetDstClip( dstRect.x(), dstRect.y(), dstRect.x() + dstRect.width(), dstRect.y() + dstRect.height() );
ReadParameters( enlargeParam );
previewThread->Enlarge( srcImage, format, enlargeParam.FloatParam() );
previewThread->setPriority( QThread::NormalPriority );
}
void EnlargerDialog::slot_queueCalc( void ) {
if( dstDir.exists( ui->destFileEdit->text() ) ) {
if( !FileExistsMessage( ui->destFileEdit->text(), dstDir.dirName() ) )
return;
}
SingleCalcJob *newJob;
newJob = new SingleCalcJob();
newJob->srcName = currentSrcName;
newJob->srcPath = currentSrcPath;
if( currentSrcPath.isEmpty() ) { // indicates, that the image itself has to be attached to the job
newJob->AttachImage( ui->previewField->theImage() );
}
newJob->dstName = ui->destFileEdit->text();
newJob->dstPath = dstDir.absoluteFilePath( ui->destFileEdit->text() );
newJob->format.srcWidth = ui->previewField->theImage().width();
newJob->format.srcHeight = ui->previewField->theImage().height();
newJob->format.SetScaleFact( ZoomX(), ZoomY() );
newJob->format.SetSrcClip( baseClipX0, baseClipY0, baseClipX1, baseClipY1 );
ReadParameters( newJob->param );
connect( newJob, SIGNAL(StatusMessage(QString)), this, SLOT(slot_MessageToLog(QString)) );
connect( newJob, SIGNAL(ErrorMessage(QString)), this, SLOT(slot_MessageToLog(QString)) );
connect( newJob, SIGNAL(BadAlloc(QString)), this, SLOT(BadAllocMessage(QString)) );
QString statusText;
statusText = "Calculating '" + ui->destFileEdit->text() + "' . ";
statusText += " Source was '" + ui->comboBox->currentText() + "' . ";
statusText += " Destination directory is '" + ui->destDirLabel->text() + "' . ";
PrintStatusText( statusText );
theCalcQueue->AddJob( newJob );
IncDestName();
ui->queueListView->clearFocus();
ui->queueListView->setFocus();
//ui->queueListView->repaint();
//ui->queueListView->update();
//ui->tabWidgetRight->update();
}
void EnlargerDialog::slot_showPreview( const QImage & result ) {
ui->previewField->setPreview( result );
}
void EnlargerDialog::slot_showPreviewProgress( int val ) {
if( val<100 ) {
ui->previewProgressLabel->setText(" [ " + QString::number( val ) + "% ] " );
}
else {
ui->previewProgressLabel->setText(" " );
}
}
void EnlargerDialog::slot_imageSaved( void ) {
IncDestName(); // image was saved, so maybe new number has to be appended to dstFileName?
PrintStatusText( " Image '" + calcResultName + "' has been saved sucessfully." );
ResetDialog();
}
void EnlargerDialog::slot_imageNotSaved( void ) {
PrintStatusText( " Image '" + calcResultName + "' could not be saved!" );
ResetDialog();
}
void EnlargerDialog::SetZoomInt( int v ) {
if( zoomInt != v ) {
if( ui->zoomSlider->hasFocus() || ui->zoomSpinBox->hasFocus() ) {
ZoomUseZoom();
}
SetZoom( float( v )*0.01 );
stopPreview();
}
}
void EnlargerDialog::SetNewWidth( int v ) {
if( setZoom_recursionBlocker ) // called from within SetZoom -> nothing to do
return;
if( v != newWidth ) {
if( zoomUpdateMod == useWidthAndHeight ){
ChangeAspectRatio( v, newHeight );
}
else {
if( ui->newWidthBox->hasFocus() ) {
ZoomUseWidth();
}
SetZoom( float( v ) / (baseClipX1-baseClipX0) );
}
stopPreview();
}
}
void EnlargerDialog::SetNewHeight( int v ) {
if( setZoom_recursionBlocker ) // called from within SetZoom -> nothing to do
return;
if( v != newHeight ) {
if( zoomUpdateMod == useWidthAndHeight ){
ChangeAspectRatio( newWidth, v );
}
else {
if( ui->newHeightBox->hasFocus() ) {
ZoomUseHeight();
}
SetZoom( float( v ) / (baseClipY1-baseClipY0) );
}
stopPreview();
}
}
void EnlargerDialog::slot_ZoomRadioButton( void ) {
ZoomUseZoom();
ui->zoomRButton->setChecked( false ); // will be toggled after releasing the button
}
void EnlargerDialog::slot_WidthRadioButton( void ) {
if( ui->widthRButton->isChecked() && ui->heightRButton->isChecked()) {
ZoomUseWidth();
}
else if( !ui->widthRButton->isChecked() && !ui->heightRButton->isChecked() ) {
ZoomUseWidth();
}
else if( !ui->widthRButton->isChecked() && ui->heightRButton->isChecked() ) {
ZoomUseWidthAndHeight();
}
ui->widthRButton->setChecked( false ); // will be toggled after releasing the button
}
void EnlargerDialog::slot_HeightRadioButton( void ) {
if( ui->widthRButton->isChecked() && ui->heightRButton->isChecked()) {
ZoomUseHeight();
}
else if( !ui->widthRButton->isChecked() && !ui->heightRButton->isChecked() ) {
ZoomUseHeight();
}
else if( ui->widthRButton->isChecked() && !ui->heightRButton->isChecked() ) {
ZoomUseWidthAndHeight();
}
ui->heightRButton->setChecked( false ); // will be toggled after releasing the button
}
void EnlargerDialog::slot_applyClipping( void ) {
float cx0, cy0, cx1, cy1;
ui->selectField->GetMarkedClipRect( cx0, cy0, cx1, cy1 );
if( cx0 >= cx1 || cy0 >= cy1 )
return;
if( cx0 < 0.0 || cy0 < 0.0 )
return;
if( cy1 > float( srcHeight ) || cx1 > float( srcWidth ) )
return;
ui->selectField ->setClipRect( cx0, cy0, cx1, cy1 );
ui->previewField->setClipRect( cx0, cy0, cx1, cy1 );
baseClipX0 = cx0; baseClipY0 = cy0;
baseClipX1 = cx1; baseClipY1 = cy1;
UpdateZoom(); // format changed -> maybe zoom changed ( if newWidth or newHeight held const. )
//CenterSelectBox();
}
void EnlargerDialog::slot_setClipping( float cx0, float cy0, float cx1, float cy1 ) {
if( cx0 >= cx1 || cy0 >= cy1 )
return;
if( cx0 < 0.0 || cy0 < 0.0 )
return;
if( cy1 > float( srcHeight ) || cx1 > float( srcWidth ) )
return;
ui->selectField ->setClipRect( cx0, cy0, cx1, cy1 );
ui->previewField->setClipRect( cx0, cy0, cx1, cy1 );
baseClipX0 = cx0; baseClipY0 = cy0;
baseClipX1 = cx1; baseClipY1 = cy1;
ClippingHistoryAdd();
UpdateZoom(); // format changed -> maybe zoom changed ( if newWidth or newHeight held const. )
//CenterSelectBox();
}
void EnlargerDialog::slot_resetClipping( void ) {
ClippingHistoryUndo();
ui->selectField ->setClipRect( baseClipX0, baseClipY0, baseClipX1, baseClipY1 );
ui->previewField->setClipRect( baseClipX0, baseClipY0, baseClipX1, baseClipY1 );
UpdateZoom(); // format changed -> maybe zoom changed ( if newWidth or newHeight held const. )
//CenterSelectBox();
}
void EnlargerDialog::slot_paste( void )
{
const QClipboard *clipboard = QApplication::clipboard();
SourceFromMimeData( clipboard->mimeData() );
}
void EnlargerDialog::slot_ShowJobCount( int endedJobs, int totalJobs ) {
int tabIndex;
tabIndex = ui->tabWidgetRight->indexOf( ui->jobTab );
if( tabIndex != -1 ) {
ui->tabWidgetRight->setTabText( tabIndex, "Jobs: ( " + QString::number( endedJobs ) + "/" + QString::number( totalJobs ) + " )" );
}
}
void EnlargerDialog::slot_MessageToLog( const QString & message ) {
ui->logDisplay->append( message );
ui->logDisplay->moveCursor ( QTextCursor::End );
ui->logDisplay->ensureCursorVisible();
}
void EnlargerDialog::slot_SmallMode( bool switchToSmall ) {
// hide();
setUpdatesEnabled( false );
if( switchToSmall ) {
ui->srcGroupBox->hide();
ui->previewGroupBox->hide();
ui->tabWidgetLeft->hide();
ui->tabWidgetRight->setParent( ui->centralwidget );
ui->tabWidgetLeft->removeTab( 0 );
ui->tabWidgetRight->insertTab( 0, ui->enlargeTab, "Enlarge" );
// workaround ?!?: force correct resize ?!?
setUpdatesEnabled( true );
ui->centralwidget->setParent( 0 );
setCentralWidget( ui->centralwidget );
ui->centralwidget->show();
}
else {
ui->tabWidgetRight->removeTab( 0 );
ui->tabWidgetLeft->insertTab( 0, ui->enlargeTab, "Enlarge" );
ui->tabWidgetLeft->show();
ui->tabWidgetRight->show();
ui->srcGroupBox->show();
ui->previewGroupBox->show();
}
resize( minimumSize() );
setUpdatesEnabled( true );
}
void EnlargerDialog::closeEvent(QCloseEvent *event)
{
WriteSettings();
if ( theCalcQueue->UnfinishedJobs() == 0 ) {
theCalcQueue->Clear();
event->accept();
return;
}
if( AbortCalcMessage( theCalcQueue->UnfinishedJobs() ) ) {
theCalcQueue->Clear();
event->accept();
} else {
event->ignore();
}
}
// ---- Drag and Drop ----
void EnlargerDialog::dragEnterEvent(QDragEnterEvent *event)
{
/*
QStringList formatsList;
cout<<" ED DragEnter "<<" \n"<<flush;
formatsList = event->mimeData()->formats();
for (int i = 0; i < formatsList.size(); i++) {
cout << "MimeType ("<<i<<"): "<<formatsList.at(i).toLocal8Bit().constData()<<" \n"<<flush;
}
if (event->mimeData()->hasFormat("text/uri-list")) {
cout<<" text/uri-list "<<" \n"<<flush;
QList<QUrl> uriList;
uriList = event->mimeData()->urls();
for (int i = 0; i < uriList.size(); i++) {
cout << "URI ("<<i<<"): "<<uriList.at(i).toString().toLocal8Bit().constData()<<" \n"<<flush;
cout << " Path: "<<uriList.at(i).path().toLocal8Bit().constData()<<" \n"<<flush;
}
}
cout << "Text: "<<event->mimeData()->text().toLocal8Bit().constData()<<" \n"<<flush;
event->acceptProposedAction();
if( event->mimeData()->hasImage() )
cout << "Has Image!\n"<<flush;
else
cout << "No Image.\n"<<flush;
*/
event->acceptProposedAction();
}
void EnlargerDialog::dropEvent(QDropEvent *event)
{
SourceFromMimeData( event->mimeData() );
event->acceptProposedAction();
}
// ------------------------------------------------------------
// search for smillaenlarger.ini
// in ~/.smillacenlarger/, in current dir, and in MacOS-bundle Contents dir
// create *theSettings,
// read the settings
void EnlargerDialog::ReadSettings( void ) {
QString iniFilePath;
iniFilePath = FindSettingsFile();
cout<<"Settings Path: "<<iniFilePath.toStdString()<<" \n"<<flush;
if( theSettings != 0) { // settings have been read before, delete them
delete theSettings;
}
theSettings = new QSettings( iniFilePath, QSettings::IniFormat );
// clear the array of parameter settings
ui->paramCombo->clear();
paramSetVal.clear();
// fill with data from settings file
int size = theSettings->beginReadArray("parameters/array");
for (int i = 0; i < size; ++i) {
theSettings->setArrayIndex(i);
QString settingName;
EnlargeParamInt p;
settingName = theSettings->value("name").toString();
p.sharp = theSettings->value("sharp", 80 ).toInt();
p.flat = theSettings->value("flat", 80 ).toInt();
p.dither = theSettings->value("dither", 80 ).toInt();
p.deNoise = theSettings->value("deNoise", 80 ).toInt();
p.preSharp = theSettings->value("preSharp", 80 ).toInt();
p.fractNoise = theSettings->value("fractNoise", 80 ).toInt();
ui->paramCombo->addItem( settingName );
paramSetVal.append( p );
}
theSettings->endArray();
currentParamIdx = theSettings->value( "parameters/currentIndex", 0 ).toInt();
if( size == 0 ) {
EnlargeParamInt p;
p.sharp = 80;
p.flat = 10;
p.dither = 20;
p.preSharp = 0;
p.deNoise = 10;
p.fractNoise = 0;
AddParamSet( "default", p );
currentParamIdx = 0;
}
SetParamSliders( paramSetVal.at( currentParamIdx ) );
ui->paramCombo->setCurrentIndex( currentParamIdx );
ui->paramChangeCheckBox->setChecked( false );
slot_ParamCheckBoxChanged( Qt::Unchecked );
}
void EnlargerDialog::WriteSettings( void ) {
EnlargeParamInt p;
if( ui->paramChangeCheckBox->isChecked() ) {
GetParamSliders( p );
ChangeParamSet( currentParamIdx, p );
}
theSettings->beginWriteArray("parameters/array");
for (int i = 0; i < paramSetVal.size(); i++) {
theSettings->setArrayIndex(i);
p = paramSetVal.at( i );
theSettings->setValue( "name" , ui->paramCombo->itemText( i ) );
theSettings->setValue( "sharp" , p.sharp );
theSettings->setValue( "flat" , p.flat );
theSettings->setValue( "dither" , p.dither );
theSettings->setValue( "deNoise" , p.deNoise );
theSettings->setValue( "preSharp" , p.preSharp );
theSettings->setValue( "fractNoise", p.fractNoise );
}
theSettings->endArray();
theSettings->setValue( "parameters/currentIndex", currentParamIdx );
}
QString EnlargerDialog::FindSettingsFile( void ) {
QDir settingsDir;
QString iniFilePath;
settingsDir = QDir::home();
iniFilePath = settingsDir.absoluteFilePath( ".smillaenlarger/smillaenlarger.ini" );
cout<<" Home: "<<iniFilePath.toStdString()<<" \n";
if( QFile::exists( iniFilePath ) ) {
return iniFilePath;
}
settingsDir = QDir::currentPath();
if( settingsDir.dirName() == "MacOS" ) { // maybe we are in a MacOS-app-bundle?
settingsDir.cdUp();
if( settingsDir.dirName() == "Contents" ) { // look in "Contents" of the bundle for smillaenlarger.ini
iniFilePath = settingsDir.absoluteFilePath( "smillaenlarger.ini" );
cout<<" MacOS: "<<iniFilePath.toStdString()<<" \n";
if( QFile::exists( iniFilePath ) ) {
return iniFilePath;
}
}
}
// maybe we are near a MacOS-app-bundle?
iniFilePath = settingsDir.absoluteFilePath( "SmillaEnlarger.app/Contents/smillaenlarger.ini" );
cout<<" MacOS b: "<<iniFilePath.toStdString()<<" \n";
if( QFile::exists( iniFilePath ) ) {
return iniFilePath;
}
// no settings file found elsewhere: use directory of binary
settingsDir = QDir::currentPath();
iniFilePath = settingsDir.absoluteFilePath( "smillaenlarger.ini" );
cout<<" Current: "<<iniFilePath.toStdString()<<" \n";
return iniFilePath;
}
void EnlargerDialog::ZoomUseWidth ( void ) {
zoomUpdateMod = useWidth;
ui->zoomRButton->setChecked( false );
ui->widthRButton->setChecked( true );
ui->heightRButton->setChecked( false );
aspectX = aspectY = 1.0;
UpdateZoom();
}
void EnlargerDialog::ZoomUseHeight( void ) {
zoomUpdateMod = useHeight;
ui->zoomRButton->setChecked( false );
ui->widthRButton->setChecked( false );
ui->heightRButton->setChecked( true );
aspectX = aspectY = 1.0;
UpdateZoom();
}
void EnlargerDialog::ZoomUseWidthAndHeight( void ) {
zoomUpdateMod = useWidthAndHeight;
ui->zoomRButton->setChecked( false );
ui->widthRButton->setChecked( true );
ui->heightRButton->setChecked( true );
}
void EnlargerDialog::ZoomUseZoom ( void ) {
zoomUpdateMod = useZoom;
ui->zoomRButton->setChecked( true );
ui->widthRButton->setChecked( false );
ui->heightRButton->setChecked( false );
aspectX = aspectY = 1.0;
UpdateZoom();
}
void EnlargerDialog::UpdateZoom( void ) {
float newZoom;
if( zoomUpdateMod == useWidthAndHeight ) { // width and height const
ChangeAspectRatio( ui->newWidthBox->value(), ui->newHeightBox->value() );
return;
}
if( zoomUpdateMod == useWidth ) { // newWidth spinbox has focus -> width const
newZoom = float( ui->newWidthBox->value() ) / (baseClipX1-baseClipX0) ;
}
else if( zoomUpdateMod == useHeight ) { // newWidth spinbox has focus -> width const
newZoom = float( ui->newHeightBox->value() ) / (baseClipY1-baseClipY0) ;
}
else {
newZoom = float( ui->zoomSpinBox->value() )*0.01 ;
}
SetZoom( newZoom );
}
void EnlargerDialog::SetZoom( float zoomF ) {
if( !setZoom_recursionBlocker ) {
setZoom_recursionBlocker = true;
zoomFact = zoomF;
newWidth = int( (baseClipX1-baseClipX0)*ZoomX() + 0.5);
newHeight = int( (baseClipY1-baseClipY0)*ZoomY() + 0.5);
zoomInt = int(zoomF*100.0 + 0.5);
ui->previewField->setZoom( ZoomX(), ZoomY() );
ui->selectField->setSelectSize( preWidth/ZoomX(), preHeight/ZoomY() );
ui->newWidthBox->setValue(newWidth);
ui->newHeightBox->setValue(newHeight);
ui->zoomSpinBox->setValue(zoomInt);
setZoom_recursionBlocker = false;
}
}
void EnlargerDialog::ChangeAspectRatio( int dstWidth, int dstHeight ) {
float zx, zy , zoomF;
zx = float( dstWidth ) / (baseClipX1-baseClipX0); // zoom in X
zy = float( dstHeight) / (baseClipY1-baseClipY0); // zoom in Y
zoomF = sqrt( zx*zy ); // zoomFact
aspectX = zx/zoomF;
aspectY = zy/zoomF;
SetZoom( zoomF );
}
void EnlargerDialog::ResetDialog( void ) {
ui->previewButton->setFocus();
}
bool EnlargerDialog::TryOpenSource( QString fileName ) {
QString path,body,type,typeL;
QString symLinkTarget, symLinkPath;
bool isSymLink = false;
// test if symbolic link, if true: use link target ( but use dir of link as dstDir )
symLinkTarget = QFile::symLinkTarget( fileName );
if( !symLinkTarget.isEmpty() ) { // is symLink
isSymLink = true;
SplitFileName( fileName, symLinkPath, body, type ); // get path of symLink
fileName = symLinkTarget; // switch to the target
}
if( !QFile::exists( fileName ) ) {
PrintStatusText( QString("File '") + fileName + QString("' does not exist.") );
return false;
}
// switch to absolute file path
QFileInfo fi( fileName );
fileName = fi.absoluteFilePath();
SplitFileName( fileName, path, body, type );
QStringList typeList;
typeList << "jpg" << "jpeg" << "bmp" << "png" << "tif" << "tiff" << "ppm" << "gif";
if( !typeList.contains( type, Qt::CaseInsensitive ) ) {
PrintStatusText( QString("File '") + fileName + QString("' of unsupported type < ") + type + QString(" > .") );
return false;
}
PrintStatusText( QString("Loading image '") + fileName + QString("' .") );
QImage sIm;
if( !sIm.load( fileName ) ) {
PrintStatusText( QString("Could not open image '") + fileName + QString("' .") );
return false;
}
SetSource( sIm.convertToFormat( QImage::Format_ARGB32 ) );
SetSourceDir( path );
if( ui->srcCheckBox->isChecked() ) {
// if it is a symbolic link:
// don't use path of symLinkTarget but folder containing the link
if( isSymLink ) {
SetDestDir( symLinkPath );
}
else {
SetDestDir( path );
}
}
FillComboBox();
int cIdx = ui->comboBox->findText( body+"."+type );
if( cIdx >= 0 )
ui->comboBox->setCurrentIndex( cIdx );
currentSrcName = body+"."+type;
currentSrcPath = srcDir.absoluteFilePath( currentSrcName );
if( type.toLower() == QString("gif") )
type = QString("png");
QString dstName = body+"_e."+type;
ui->destFileEdit->setText( dstName );
IncDestName(); // if dstName exists already: add or inc number at end of name
stopPreview();
PrintStatusText( QString("Source image '") + fileName + QString("' loaded.") );
return true;
}
// for dropping, clipboard-paste
void EnlargerDialog::SourceFromMimeData( const QMimeData *mimeData ) {
QString statusText;
if( mimeData->hasUrls() ) {
QList<QUrl> uriList;
uriList = mimeData->urls();
for (int i = 0; i < uriList.size(); i++) {
// cout << "URI ("<<i<<"): "<<uriList.at(i).toString().toLocal8Bit().constData()<<" \n"<<flush;
// cout << " Path: "<<uriList.at(i).path().toLocal8Bit().constData()<<" \n"<<flush;
if( TryOpenSource( uriList.at(i).toLocalFile() ) ) {
return;
}
}
}
if ( mimeData->hasImage() ){
QImage image = qvariant_cast<QImage>( mimeData->imageData() );
if ( !image.isNull() ) { // set the image, clear comboBox
SetSource( image );
ui->comboBox->clear();
currentSrcName = " < dropped / pasted > ";
currentSrcPath = ""; // no path -> image itself has to be stored in calcJob
ui->comboBox->addItem( currentSrcName );
QString picDir = QDesktopServices::storageLocation ( QDesktopServices::PicturesLocation );
srcDir.setPath( picDir );
if( ui->srcCheckBox->isChecked() )
SetDestDir( picDir );
ui->sourceDirLabel->setText( " < none > ");
ui->destFileEdit->setText( "dropped.jpg" );
IncDestName();
}
}
}
void EnlargerDialog::SetSource(const QImage & src ) {
srcWidth = src.width();
srcHeight = src.height();
baseClipX0 = 0.0; baseClipY0 = 0.0;
baseClipX1 = float( srcWidth ); baseClipY1 = float( srcHeight );
ClippingHistoryClear();
// UpdateZoom();
ui->selectField->setTheImage( src );
ui->selectField->setClipRect( baseClipX0, baseClipY0, baseClipX1, baseClipY1 );
ui->previewField->setTheImage( src );
ui->previewField->setClipRect( baseClipX0, baseClipY0, baseClipX1, baseClipY1 );
//newWidth = int( float( srcWidth )*zoomFact );
//newHeight = int( float( srcHeight )*zoomFact );
//ui->newWidthBox ->setValue( newWidth );
//ui->newHeightBox->setValue( newHeight );
stopPreview();
UpdateZoom(); // format changed -> maybe zoom changed ( if newWidth or newHeight held const. )
CenterSelectBox();
}
void EnlargerDialog::CenterSelectBox( void ) {
/*
// change pos&zoom of selectBox to put it into middle of selectField
float dx = 0.3*(baseClipX1-baseClipX0), dy = 0.4*(baseClipY1-baseClipY0);
float newZoom,z2;
newZoom = preWidth/dx;
z2 = preHeight/dy;
if( newZoom<z2 )
newZoom=z2;
if( newZoom>30.0 )
newZoom = 30.0;
SetZoom( newZoom );
*/
float nX = baseClipX0 + 0.5*( baseClipX1 - baseClipX0 ) - 0.5*preWidth/ZoomX();
float nY = baseClipY0 + 0.5*( baseClipY1 - baseClipY0 ) - 0.5*preHeight/ZoomY();
ui->selectField->moveSelection( nX, nY );
}
void EnlargerDialog::ReadParameters( EnlargeParamInt & param ) {
param.sharp = ui->sharpSlider->value();
param.flat = ui->flatSlider->value();
param.dither = ui->ditherSlider->value();
param.deNoise = ui->deNoiseSlider->value();
param.preSharp = ui->preSharpSlider->value();
param.fractNoise = ui->fractNoiseSlider->value();
}
void EnlargerDialog::SplitFileName( QString fullName, QString & path, QString & nameBody, QString & nameType ) {
int pointPos, slashPos, h;
pointPos = fullName.lastIndexOf( '.' );
slashPos = fullName.lastIndexOf( '/' );
h = fullName.lastIndexOf( '\\' );
if( h>slashPos )
slashPos = h;
if( pointPos>=0 ) {
nameType = fullName.mid( pointPos + 1 );
fullName.truncate( pointPos );
}
else {
nameType = "";
}
if( slashPos>=0 ) {
nameBody = fullName.mid( slashPos + 1 );
fullName.truncate( slashPos + 1 );
path = fullName;
}
else {
nameBody = fullName;
path = "";
}
}
void EnlargerDialog::FillComboBox( void ) {
QString path,body,type;
QStringList filters;
filters << "*.jpg" << "*.jpeg" << "*.bmp" << "*.png" << "*.tif" << "*.tiff" << "*.gif" << "*.ppm";
srcDir.setNameFilters(filters);
srcDir.setSorting ( QDir::Name );
QStringList entries;
entries = srcDir.entryList();
ui->comboBox->clear();
ui->comboBox->addItems( entries );
}
void EnlargerDialog::SetSourceDir( const QString & srcName ) {
srcDir.setPath( srcName );
ui->sourceDirLabel->setText( srcDir.dirName() );
FillComboBox();
}
void EnlargerDialog::SetDestDir( const QString & dstName ) {
dstDir.setPath( dstName );
ui->destDirLabel->setText( dstDir.dirName() );
}
void EnlargerDialog::ClippingHistoryUndo( void ) {
if( historyClipIdx > 0 ) {
historyClipIdx--;
}
baseClipX0 = historyClipX0[ historyClipIdx ];
baseClipY0 = historyClipY0[ historyClipIdx ];
baseClipX1 = historyClipX1[ historyClipIdx ];
baseClipY1 = historyClipY1[ historyClipIdx ];
}
void EnlargerDialog::ClippingHistoryAdd( void ) {
if( historyClipIdx < historyClipMax ) {
historyClipIdx++;
}
historyClipX0[ historyClipIdx ] = baseClipX0;
historyClipY0[ historyClipIdx ] = baseClipY0;
historyClipX1[ historyClipIdx ] = baseClipX1;
historyClipY1[ historyClipIdx ] = baseClipY1;
}
void EnlargerDialog::ClippingHistoryClear( void ) {
historyClipIdx = 0;
historyClipX0[ 0 ] = 0.0; historyClipY0[ 0 ] = 0.0;
historyClipX1[ 0 ] = float( srcWidth ); historyClipY1[ 0 ] = float( srcHeight );
}
// if the current dst-filename exists, then
// increment a number at end of filename
void EnlargerDialog::IncDestName( void ) {
QString dstName = ui->destFileEdit->text();
QString path, body, type, dstPath;
if( dstName.isEmpty() )
dstName = QString("enlarged.jpg");
SplitFileName( dstName, path, body, type );
QStringList typeList;
typeList << "jpg" << "jpeg" << "bmp" << "png" << "tif" << "tiff" <<"ppm";
if( !typeList.contains( type, Qt::CaseInsensitive ) ) {
type = QString("PNG");
dstName = body+ "." + type;
ui->destFileEdit->setText( dstName );
}
dstPath = dstDir.absoluteFilePath( dstName );
if( !dstDir.exists( dstName ) && !theCalcQueue->IsInQueue( dstPath ) )
return;
int num=0;
QRegExp rx("[0-9]*$"); // search the number before end
int numPos = rx.indexIn(body);
if( numPos == body.size() ) // no number: begin with 0
num=0;
else {
// find the number and increment it, cut body
bool isOk;
num = body.right( body.size() - numPos ).toInt( &isOk, 10 );
if( num<0 )
num=0;
num++;
body = body.left( numPos );
}
// count up until name is found, which does not exist in dir nor queue
while( num < 100 ) {
dstName = body+QString::number(num) + "." + type;
dstPath = dstDir.absoluteFilePath( dstName );
if( !dstDir.exists( dstName ) && !theCalcQueue->IsInQueue( dstPath ) )
break;
num++;
}
ui->destFileEdit->setText( dstName );
}
void EnlargerDialog::PrintStatusText( QString statusText ) {
ui->logDisplay->append( statusText );
ui->logDisplay->moveCursor ( QTextCursor::End );
ui->logDisplay->ensureCursorVisible();
SetToolTip( ui->statusTextLabel, statusText );
statusText.truncate( 180 );
ui->statusTextLabel->setText ( statusText );
}
void EnlargerDialog::InfoMessage( void ) {
QMessageBox msgBox;
QString mainText, infoText;
msgBox.setTextFormat( Qt::RichText );
mainText = "<p><b>SmillaEnlarger version 0.8.5</b></p>";
infoText = "<p>Copyright (C) 2009 Mischa Lusteck</p>";
infoText += "<p>Project site: <a href=\"http://sourceforge.net/projects/imageenlarger/\">";
infoText += "http://sourceforge.net/projects/imageenlarger/</a></p>";
infoText += "<p></p>";
infoText += "<p>This program is free software; </p>";
infoText += "<p> you can redistribute it and/or modify it under the terms of the ";
infoText += " GNU General Public License as published by the Free Software Foundation; ";
infoText += " either version 3 of the License, or (at your option) any later version. ";
infoText += "</p>";
infoText += "<p>This program is distributed in the hope that it will be useful, ";
infoText += " but WITHOUT ANY WARRANTY; ";
infoText += " without even the implied warranty of MERCHANTABILITY ";
infoText += " or FITNESS FOR A PARTICULAR PURPOSE. ";
infoText += " See the GNU General Public License for more details. ";
infoText += "</p>";
infoText += "<p>You should have received a copy of the GNU General Public License ";
infoText += " along with this program; if not, see ";
infoText += " <a href=\"http://www.gnu.org/licenses/\">http://www.gnu.org/licenses/</a>. </p>";
msgBox.setText( mainText );
msgBox.setInformativeText( infoText );
msgBox.exec();
}
void EnlargerDialog::HelpMessageStart( void ) {
QMessageBox msgBox;
msgBox.setTextFormat( Qt::RichText );
msgBox.setText( "<b>Getting Started</b>" );
QString helpText;
helpText = "<p>First you need a source image: ";
helpText += "<ul> <li>Grab an image somewhere and drop it onto the enlarger window, </li>";
helpText += "<li>or paste something from the clipboard,</li> ";
helpText += "<li>or open a file using the File-Menu or the '<b>Open Source...</b>'-button.</li> ";
helpText += "</ul></p>";
helpText += "<p>Now you should see your image in the left view titled '<b>Source</b>' and ";
helpText += " a zoomed part of it in the right view. The right '<b>Preview</b>'-view is only for ";
helpText += " giving you an impression of the zoom and for testing enlarging-parameters. ";
helpText += " By clicking onto the '<b>Preview</b>'-button, you can see what the enlarger ";
helpText += " does with the contents of the preview.</p> ";
helpText += "<p>Change the zoom with the slider under the left view and ";
helpText += " press ' <b>Enlarge & Save</b> ' to create an enlarged version of the ";
helpText += " complete contents of the left view. After the progress bar reached 100% ";
helpText += " the result is automatically saved to the file and location named in ";
helpText += " the '<b>Save To:</b>' - line at the bottom of the enlarger-window.</p> ";
helpText += "<p>Most interface elemets have tool tips ( they pop up when you don't move the mouse some time ).</p> ";
helpText += "<p>By the way: For big zoom rates you might get better results when doing the ";
helpText += " enlargement in multiple steps: </p> ";
helpText += "<p>For example for a 16-times Enlargement you could first enlarge with 400% into ";
helpText += " a temporary file ( best not to use JPEG for this to avoid artifacts ) ";
helpText += " which you then load and enlarge by a further 400% to the desired format.</p> ";
msgBox.setInformativeText( helpText );
msgBox.exec();
}
void EnlargerDialog::HelpMessageClip( void ) {
QMessageBox msgBox;
msgBox.setTextFormat( Qt::RichText );
msgBox.setText( "<b>Preview and Cropping</b>" );
QString helpText;
helpText = "<p>When you move the mouse into the '<b>Preview</b>'-window and hold down the left ";
helpText += " mouse-button, you can drag the contents around. You can also change the preview ";
helpText += " by grabbing the gray frame in the left view ( with left mouse-button down ) - if you ";
helpText += " move it around, the contents in the right view will change accordingly. </p>";
helpText += "<p>By holding down the left mouse-button elsewhere in the left '<b>Source</b>' view, you ";
helpText += " begin selecting a cropping rectangle. Drag the mouse from top-left to bottom-right of ";
helpText += " the part you want to enlarge ( with button down ), after releasing the button the ";
helpText += " 'Source' view will switch to the selected part, pressing ' <b>Enlarge & Save</b> ' will ";
helpText += " now enlarge only this part of the source. If you want to undo your selection, press ";
helpText += " ' <b>Undo Cropping</b> '. </p>";
msgBox.setInformativeText( helpText );
msgBox.exec();
}
void EnlargerDialog::HelpMessageSlider( void ) {
QMessageBox msgBox;
msgBox.setTextFormat( Qt::RichText );
msgBox.setText( "<b>Zoom and Parameter-Sliders</b>" );
QString helpText;
helpText = "<p>The scaling factor can be changed by ";
helpText += "<ul><li> moving the zoom slider</li>";
helpText += "<li> typing a new percentage value into the spin-box alongside the slider</li>";
helpText += "<li> specifying desired width or height of the result in the fields beneath the zoom-slider</li></ul></p>";
helpText += "<p>Additionally there are the sliders directly beneath the 'Preview'-field. ";
helpText += " They allow you to change some enlarging-parameters: ";
helpText += "<ul><li> <b>Sharpness:</b> higher values lead to sharper edges, might look artificial if too sharp</li>";
helpText += "<li> <b>Flatness:</b> higher values produce more 'painted' looking results with less gradients</li> ";
helpText += "<li> <b>PreSharpen:</b> applies simple sharpening to the source before enlarging</li>";
helpText += "<li> <b>Dithering:</b> add a slightly analogue looking grain-structure to the result</li>";
helpText += "<li> <b>DeNoise:</b> remove some noise and artifacts from the source</li>";
helpText += "<li> <b>FractNoise:</b> just a gimmick: get some irregularity into your result; contours and ";
helpText += " colors are modified by plasma fractal noise.</li>";
helpText += "</ul></p>";
msgBox.setInformativeText( helpText );
msgBox.exec();
}
void EnlargerDialog::HelpMessageDrop( void ) {
QMessageBox msgBox;
msgBox.setTextFormat( Qt::RichText );
msgBox.setText( "<b>Drop and Paste</b>" );
QString helpText;
helpText = "<p>SmillaEnlarger supports Drag & Drop: You can drag a file or image from any folder ";
helpText += " or from another program offering Drag&Drop and drop it onto ";
helpText += " the enlarger window. The enlarger then tries to open it as new source. </p>";
helpText += "<p>You also can paste the contents of the clipboard, i.e. use <b>Copy</b> within another ";
helpText += " program on a file or image and then in SmillaEnlarger call <b>Paste</b> from ";
helpText += " the File Menu ( or press <b>Ctrl V</b> / <b>Cmd V</b> ) to load it into the enlarger.</p> ";
helpText += "<p>( This might not work in all cases. SmillaEnlarger tries to cope with things ";
helpText += " you throw at it, but will probably not always succeed. )</p>";
msgBox.setInformativeText( helpText );
msgBox.exec();
}
void EnlargerDialog::HelpMessageLoad( void ) {
QMessageBox msgBox;
msgBox.setTextFormat( Qt::RichText );
msgBox.setText( "<b>Load and Save</b>" );
QString helpText;
helpText = "<p>As described in 'Drop & Paste', you can import images by drag & drop or paste ";
helpText += " them via the clipboard. Or choose '<b>Open...</b>' in the File-Menu or press ";
helpText += " <b>Ctrl-O</b> / <b>Cmd-O</b> or click ' <b>Open Source...</b> ' in the 'Source:'-line near the bottom of ";
helpText += " the program window. After selecting a picture, you will see it in the 'Source' ";
helpText += " view, name of file and containing directory are displayed in the 'Source:' line. ";
helpText += " To quickly switch to another file in the same directory, click onto the box ";
helpText += " containing the filename, you will see that it's a combo-box displaying all pictures ";
helpText += " in the source folder. Supported types for loading are ";
helpText += " <b>JPG</b>, <b>GIF</b>, <b>TIF</b>, <b>BMP</b>, <b>PPM</b> and <b>PNG</b> .</p>";
helpText += "<p> To save an enlarged version of the '<b>Source</b>', ";
helpText += " press '<b>Enlarge & Save</b>'. </p> ";
helpText += " Under the source information yo see the line starting with '<b>Save To:</b>', it tells you ";
helpText += " where the result will be saved. The enlarger automatically chooses the ";
helpText += " source name and type with an appended <b>_e</b> and a number as the result's filename, but ";
helpText += " you can enter something else as long as the ending belongs to one of the supported ";
helpText += " image types. The appended number is increased if you enlarge several parts of the ";
helpText += " same source. By default the enlarged picture is written into the source directory, ";
helpText += " uncheck '<b>Use Source Dir.</b>' and click '<b>Change Dest.Dir.</b>' to choose something different. ";
helpText += " Supported types for saving are <b>JPG</b>, <b>TIF</b>, <b>BMP</b>, <b>PPM</b> and <b>PNG</b> .</p>";
msgBox.setInformativeText( helpText );
msgBox.exec();
}
void EnlargerDialog::HelpMessageMore( void ) {
QMessageBox msgBox;
msgBox.setText("<b>More Help:</b>");
msgBox.setTextFormat( Qt::RichText );
QString helpText;
helpText += "<p>Visit the <a href=\"http://sourceforge.net/projects/imageenlarger/\"> ";
helpText += " Project Page</a> ,</p>";
helpText += "<p>especially the <a href=\"http://sourceforge.net/forum/forum.php?forum_id=974929\">Support Forum</a>.</p>";
helpText += "<p>Most interface elemets have tool tips ( they pop up when you don't move the mouse some time ).</p> ";
msgBox.setInformativeText( helpText );
msgBox.exec();
}
void EnlargerDialog::BadAllocMessage( const QString & dstName ) {
QMessageBox msgBox;
msgBox.setTextFormat( Qt::RichText );
msgBox.setText("<b>Result too big !?</b>");
QString helpText;
helpText = "<p> An error occured:</p>";
helpText += "<p> SmillaEnlarger was not able to allocate enough memory for '" + dstName + "', calculation was aborted.</p>";
msgBox.setInformativeText( helpText );
msgBox.exec();
ResetDialog();
}
bool EnlargerDialog::FileExistsMessage( const QString & fileName, const QString & dirName ) {
QMessageBox msgBox;
msgBox.setText("The file '" + fileName + "' exists. Do you want to replace it? " );
QString helpText;
helpText = "In the directory '" + dirName +"' exists a file with the same name. ";
helpText += " Click 'OK' to replace it. ";
msgBox.setInformativeText( helpText );
msgBox.setStandardButtons( QMessageBox::Ok | QMessageBox::Cancel);
int ret = msgBox.exec();
return ret == QMessageBox::Ok;
}
bool EnlargerDialog::AbortCalcMessage( int unfinishedJobs ) {
QMessageBox msgBox;
QString helpText;
if( unfinishedJobs == 0 )
return true;
if( unfinishedJobs == 1 ) {
msgBox.setText("Do you want to abort the current calculation? " );
helpText = "Currently there is a unfinished job in the calculation queue. ";
helpText += " Click 'Abort' to stop the calculation. ";
}
else {
msgBox.setText("Do you want to abort the current calculations? " );
helpText = "Currently there are " + QString::number( unfinishedJobs ) + " unfinished jobs in the calculation queue. ";
helpText += " Click 'Abort' to stop the calculations. ";
}
msgBox.setInformativeText( helpText );
msgBox.setStandardButtons( QMessageBox::Abort | QMessageBox::Cancel);
int ret = msgBox.exec();
return ret == QMessageBox::Abort;
}
void EnlargerDialog::SetToolTip( QWidget *widget, const QString & tipStr ) {
widget->setToolTip( tipStr );
widget->setWhatsThis( tipStr );
}
void EnlargerDialog::SetToolTip( QWidget *w1, QWidget *w2, const QString & tipStr ) {
w1->setToolTip( tipStr );
w1->setWhatsThis( tipStr );
w2->setToolTip( tipStr );
w2->setWhatsThis( tipStr );
}
//--------- list of Parameter Settings --------
int EnlargerDialog::AddParamSet( const QString & name, const EnlargeParamInt & p ) {
ui->paramCombo->addItem( name );
paramSetVal.append( p );
return paramSetVal.size() - 1;
}
void EnlargerDialog::DelParamSet( int idx ) {
if( idx>=0 && idx<paramSetVal.size() ) {
ui->paramCombo->removeItem( idx );
paramSetVal.removeAt( idx );
}
}
void EnlargerDialog::ChangeParamSet( int idx, const EnlargeParamInt & p ) {
if( idx>=0 && idx<paramSetVal.size() ) {
paramSetVal.replace( idx, p );
}
}
void EnlargerDialog::GetParamSliders( EnlargeParamInt & p ) {
p.sharp = ui->sharpSlider ->value();
p.flat = ui->flatSlider ->value();
p.dither = ui->ditherSlider ->value();
p.deNoise = ui->deNoiseSlider ->value();
p.preSharp = ui->preSharpSlider ->value();
p.fractNoise = ui->fractNoiseSlider->value();
}
void EnlargerDialog::SetParamSliders( const EnlargeParamInt & p ) {
ui->sharpSlider ->setValue( p.sharp );
ui->flatSlider ->setValue( p.flat );
ui->ditherSlider ->setValue( p.dither );
ui->deNoiseSlider ->setValue( p.deNoise );
ui->preSharpSlider ->setValue( p.preSharp );
ui->fractNoiseSlider->setValue( p.fractNoise );
cout<<"SetParamSliders( "<<ui->sharpSlider->value()<<" "<<p.sharp<<" ) \n"<<flush;
}
void EnlargerDialog::slot_AddParam( void ) {
int idx;
EnlargeParamInt p;
GetParamSliders( p );
// if changes allowed: write slider settings before switching to new
if( ui->paramChangeCheckBox->isChecked() ) {
ChangeParamSet( currentParamIdx, p );
}
idx = AddParamSet( "new", p );
ui->paramCombo->setCurrentIndex( idx );
currentParamIdx = idx;
ui->paramChangeCheckBox->setCheckState( Qt::Checked ); // allow editing of new
ui->paramCombo->setFocus(); // for typing of new name: set focus
idx = ui->paramCombo->currentIndex();
cout<<" ( "<<idx<<" "<<paramSetVal.size()<<" "<<ui->paramCombo->count() <<" ) \n"<<flush;
}
void EnlargerDialog::slot_DelParam( void ) {
int idx;
if( ui->paramCombo->count() > 1 ) {
idx = ui->paramCombo->currentIndex();
cout<<" ( "<<idx<<" "<<paramSetVal.size()<<" "<<ui->paramCombo->count() <<" ) \n"<<flush;
DelParamSet( idx );
ui->paramChangeCheckBox->setCheckState( Qt::Unchecked ); // switch -> disable editing
idx = ui->paramCombo->currentIndex();
cout<<" ( "<<idx<<" "<<paramSetVal.size()<<" "<<ui->paramCombo->count() <<" ) \n"<<flush;
}
}
void EnlargerDialog::slot_ParamCheckBoxChanged( int state ) {
EnlargeParamInt p;
GetParamSliders( p );
ChangeParamSet( currentParamIdx, p );
if( ui->paramChangeCheckBox->isChecked() ) {
ui->paramDelButton->setEnabled( true );
ui->paramCombo->setFocusPolicy( Qt::StrongFocus );
ui->sharpSlider ->setEnabled( true ); ui->sharpSpinBox ->setEnabled( true );
ui->flatSlider ->setEnabled( true ); ui->flatSpinBox ->setEnabled( true );
ui->ditherSlider ->setEnabled( true ); ui->ditherSpinBox ->setEnabled( true );
ui->preSharpSlider ->setEnabled( true ); ui->preSharpSpinBox ->setEnabled( true );
ui->deNoiseSlider ->setEnabled( true ); ui->deNoiseSpinBox ->setEnabled( true );
ui->fractNoiseSlider->setEnabled( true ); ui->fractNoiseSpinBox->setEnabled( true );
}
else {
ui->paramDelButton->setEnabled( false );
ui->paramCombo->setFocusPolicy( Qt::NoFocus );
ui->paramCombo->clearFocus();
ui->sharpSlider ->setEnabled( false ); ui->sharpSpinBox ->setEnabled( false );
ui->flatSlider ->setEnabled( false ); ui->flatSpinBox ->setEnabled( false );
ui->ditherSlider ->setEnabled( false ); ui->ditherSpinBox ->setEnabled( false );
ui->preSharpSlider ->setEnabled( false ); ui->preSharpSpinBox ->setEnabled( false );
ui->deNoiseSlider ->setEnabled( false ); ui->deNoiseSpinBox ->setEnabled( false );
ui->fractNoiseSlider->setEnabled( false ); ui->fractNoiseSpinBox->setEnabled( false );
}
}
void EnlargerDialog::slot_SetParamSlidersFromCombo( int idx ) {
//ui->paramCombo->setEditable( !ui->paramCombo->isEditable() );
EnlargeParamInt p;
GetParamSliders( p );
// if changes allowed: write slider settings before switching to new
if( ui->paramChangeCheckBox->isChecked() ) {
ChangeParamSet( currentParamIdx, p );
}
if( idx != currentParamIdx && idx >=0 && idx < paramSetVal.size() ) {
SetParamSliders( paramSetVal.at( idx ) );
currentParamIdx = idx;
ui->paramChangeCheckBox->setCheckState( Qt::Unchecked ); // switch -> disable editing
}
cout<<" ( "<<idx<<" "<<paramSetVal.size()<<" "<<ui->paramCombo->count() <<" ) \n"<<flush;
}
void EnlargerDialog::slot_QueueRemoveSelected( void ) {
QModelIndex jobIdx = ui->queueListView->currentIndex();
if( !jobIdx.isValid() )
return;
if( !ui->queueListView->selectionModel()->isSelected( jobIdx ) )
return;
theCalcQueue->RemoveJob( jobIdx );
ui->queueListView->clearFocus();
ui->queueListView->setFocus();
}
void EnlargerDialog::slot_QueueClear( void ) {
theCalcQueue->Clear();
ui->queueListView->clearFocus();
ui->queueListView->setFocus();
}
void EnlargerDialog::slot_QueueRemoveEnded( void ) {
theCalcQueue->RemoveEnded();
ui->queueListView->clearFocus();
ui->queueListView->setFocus();
}