forked from Boms/photoqt-dev
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mainwindow.cpp
2889 lines (2180 loc) · 90 KB
/
mainwindow.cpp
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
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include "mainwindow.h"
MainWindow::MainWindow(QWidget *parent, bool verbose) : QMainWindow(parent) {
// Make a screenshot of each screen
takeScreenshots();
// Black Background
this->setObjectName("mainwindow");
this->setAttribute(Qt::WA_TranslucentBackground);
this->setStyleSheet("#mainwindow { background-color: rgba(0,0,0,0); }");
this->setMouseTracking(true);
// If the user switched to window mode, then we need to have a minimum window size
this->setMinimumSize(800,600);
// Instance for global variables
globVar = new GlobalVariables;
globVar->verbose = verbose;
// Instance for global settings
globSet = new GlobalSettings;
globSet->verbose = verbose;
globSet->readSettings();
// Connect some globSet signals
connect(globSet, SIGNAL(updateSettingsData(QMap<QString,QVariant>)), this, SLOT(updateSettings(QMap<QString,QVariant>)));
connect(globSet, SIGNAL(updateSettingsToApply(QMap<QString,bool>)), this, SLOT(applySettings(QMap<QString,bool>)));
// Instance for which widgets have been set up
setupWidgets = new SetupWidgets;
// Central Widget
QWidget *central = new QWidget;
central->setObjectName("central");
central->setStyleSheet("#central { border: none; background-color:rgba(0,0,0,0); }");
QVBoxLayout *bglayout = new QVBoxLayout;
bglayout->setMargin(0);
bglabel = new QLabel;
bglabel->setMargin(0);
bglayout->addWidget(bglabel);
central->setLayout(bglayout);
this->setCentralWidget(central);
QVBoxLayout *centralLayout = new QVBoxLayout;
centralLayout->setMargin(0);
bglabel->setLayout(centralLayout);
// The main GraphicViews
viewBig = new GraphicsView(globSet->toSignalOut(),bglabel);
connect(viewBig, SIGNAL(mousePos(int,int)), this, SLOT(mouseMoved(int,int)));
connect(viewBig, SIGNAL(clicked(QPoint)), this, SLOT(gotViewBigClick(QPoint)));
// A mouse action triggered a shortcut
connect(viewBig, SIGNAL(shMouseDo(QString,bool)), this, SLOT(shortcutDO(QString,bool)));
connect(viewBig, SIGNAL(loadContextMenuAction(QString)), this, SLOT(shortcutDO(QString)));
// The main GraphicsView fills the whole widget
centralLayout->addWidget(viewBig);
// Setup the quickinfo labels. We have two sets of labels, for the top and for the bottom. This way we can change the position without having to restart PhotoQt.
viewBigLay = new ViewBigLay(globSet->toSignalOut(),verbose);
viewBig->setLayout(viewBigLay);
viewBigLay->setPosition(globSet->thumbnailposition);
connect(viewBigLay, SIGNAL(clickOnX(QString)), this, SLOT(shortcutDO(QString)));
connect(viewBigLay, SIGNAL(updateSettings(QMap<QString,QVariant>)), globSet, SLOT(settingsUpdated(QMap<QString,QVariant>)));
// rotation indicator
/* viewBigLay->updateInfo("",0,0,false);*/
viewBigLay->updateInfo("",0,0);
// The Item holding the big pixmap item
graphItem = new GraphicsItem;
connect(graphItem, SIGNAL(updateSceneBigRect()), this, SLOT(updateSceneBigRect()));
viewBig->scene()->addItem(graphItem);
// The thumbnail-bar instance
viewThumbs = new Thumbnails(globSet->toSignalOut(), globVar->verbose, viewBig);
connect(viewThumbs, SIGNAL(loadNewImg(QString)), this, SLOT(loadNewImgFromThumbs(QString)));
// The quicksetting window
quickset = new QuickSettings(globSet->toSignalOut(), globVar->verbose, viewBig);
connect(quickset, SIGNAL(updateSettings(QMap<QString,QVariant>)), globSet, SLOT(settingsUpdated(QMap<QString,QVariant>)));
connect(quickset, SIGNAL(emulateShortcut(QString)), this, SLOT(shortcutDO(QString)));
// An ImageReader combining QImageReader and GraphicsMagic (if not disabled)
imageReader = new ImageReader(globVar->verbose);
// The settings widget
set = new Settings(globSet->toSignalOut(),verbose,viewBig);
// Set the shortcut version (needed for saving shortcuts
connect(set, SIGNAL(blockFunc(bool)), this, SLOT(blockFunc(bool)));
connect(set, SIGNAL(updateSettings(QMap<QString,QVariant>)), globSet, SLOT(settingsUpdated(QMap<QString,QVariant>)));
connect(set, SIGNAL(restoreDefault()), this, SLOT(restoreDefaultSettings()));
set->sh->version = globSet->version;
connect(set->sh, SIGNAL(updatedShortcuts()), this, SLOT(setupShortcuts()));
connect(set, SIGNAL(widgetClosed()), this, SLOT(settingsAboutClosed()));
// The exif widget
details = new Details(viewBig,globSet->toSignalOut());
connect(details, SIGNAL(updateSettings(QMap<QString,QVariant>)), globSet, SLOT(settingsUpdated(QMap<QString,QVariant>)));
#ifdef EXIV2
connect(details, SIGNAL(setOrientation(int,bool)), this, SLOT(getOrientationFromExif(int,bool)));
connect(details->rotConf, SIGNAL(blockFunc(bool)), this, SLOT(blockFunc(bool)));
#endif
// These shortcut are needed for the widgets like settings, open, etc., thus they need to be set up always
for(int i = 0; i < globVar->systemSh.size(); ++i) {
QShortcut *sysSh = new QShortcut(QKeySequence(globVar->systemSh.at(i)),this);
systemKeySH.insert(globVar->systemSh.at(i),sysSh);
QList<QVariant> list;
list << false << globVar->systemSh.at(i) << "";
systemKeySHdo.value(globVar->systemSh.at(i),list);
QSignalMapper *mapper = new QSignalMapper;
mapper->setMapping(sysSh,globVar->systemSh.at(i));
connect(sysSh, SIGNAL(activated()), mapper, SLOT(map()));
connect(mapper, SIGNAL(mapped(QString)), this, SLOT(systemShortcutDO(QString)));
}
// Setup the shortcuts
setupShortcuts();
// Setup the tray icon
setupTrayIcon();
// Pass the current settings on to all the subclasses
updateSettings(globSet->toSignalOut());
applySettings(QMap<QString,bool>(),true);
// The global timer ensuring only one instance of Photo runs at a time
globalRunningProgTimer = new QTimer;
globalRunningProgTimer->setInterval(1000);
connect(globalRunningProgTimer, SIGNAL(timeout()), this, SLOT(globalRunningProgTimerTimeout()));
globalRunningProgTimer->start();
// A startup-timer (started from main.cpp)
startUpTimer = new QTimer;
startUpTimer->setInterval(300);
connect(startUpTimer, SIGNAL(timeout()), this, SLOT(startuptimer()));
}
// Adjust the geometries (if applicable)
void MainWindow::adjustGeometries() {
if(globVar->verbose) std::clog << "Adjusting geometries" << std::endl;
// The thumbnail hight for later use
int thbHeight = globSet->thumbnailsize + globSet->thumbnailLiftUp + 30;
int viewH = viewBig->height();
int viewW = viewBig->width();
// If the thumbnail bar is shown at the bottom
if(globSet->thumbnailposition == "Bottom") {
if(globVar->verbose) std::clog << "Thumbnails at the bottom" << std::endl;
// Adjust the thumbnail geometry
viewThumbs->setRect(QRect(0,viewH-thbHeight,viewW,thbHeight));
// Adjust the menu geometry
if(setupWidgets->menu) menu->setRect(QRect(viewW-500,0,350,300));
// And if the thumbnail bar is shown at the top
} else if(globSet->thumbnailposition == "Top") {
if(globVar->verbose) std::clog << "Thumbnails at the top" << std::endl;
// Adjust the thumbnail geometry
viewThumbs->setRect(QRect(0,0,viewBig->width(),thbHeight));
// Adjust the menu geometry
if(setupWidgets->menu) menu->setRect(QRect(viewBig->width()-500,viewBig->height()-300,350,300));
}
// Fullscreen Rect
QRect fullscreen = QRect(0,0,viewW,viewH);
if(globVar->verbose) std::clog << "Adjusting Geometries: " << QString("QRect, topleft: %1:%2, size: %3x%4").arg(fullscreen.left()).arg(fullscreen.top()).arg(fullscreen.width()).arg(fullscreen.height()).toStdString() << std::endl;
// exif and set are always setup (the tabs in set aren't initially)
details->setRect(fullscreen);
set->setRect(fullscreen);
quickset->setRect(fullscreen);
// Update the rects for all set up widgets
if(setupWidgets->filehandling) filehandling->setRect(fullscreen);
if(setupWidgets->about) about->setRect(fullscreen);
if(setupWidgets->slideshow) slideshow->setRect(fullscreen);
if(setupWidgets->startup) startup->setRect(fullscreen);
if(setupWidgets->wallpaper) wallpaper->setRect(fullscreen);
if(setupWidgets->scaleimage) scaleimage->setRect(fullscreen);
if(setupWidgets->slideshowbar) slideshowbar->setWidth(this->width());
if(globSet->thumbnailKeepVisible)
viewThumbs->makeShow();
}
// This is called, whenever the settings have changed, and updates all sub-widgets
// This function is needed together with the updateSettings() function to avoid a crash on startup
void MainWindow::applySettings(QMap<QString, bool> applySet, bool justApplyAllOfThem) {
if(globVar->verbose) std::clog << "Applying settings..." << std::endl;
// If all the settings have to be (re-)applied
if(justApplyAllOfThem) {
if(globVar->verbose) std::clog << "Simply apply all settings" << std::endl;
QMap<QString, bool> newApplySet;
QMapIterator<QString, bool> i(applySet);
while (i.hasNext()) {
i.next();
newApplySet.insert(i.key(),true);
}
applySet = newApplySet;
}
// Adjust/Set the background
if(applySet["background"])
setBackground();
// Update window for window mode/fullscreen
if(applySet["window"]) {
if(globSet->windowmode) {
globSet->windowDecoration
? this->setWindowFlags(Qt::Window)
: this->setWindowFlags(Qt::Window | Qt::FramelessWindowHint);
if(globSet->keepOnTop) this->setWindowFlags(this->windowFlags() | Qt::WindowStaysOnTopHint);
if(globVar->windowMaximised)
this->showMaximized();
else
this->showNormal();
} else {
if(globSet->keepOnTop) this->setWindowFlags(Qt::WindowStaysOnTopHint);
this->showFullScreen();
}
}
// Update the thumbnails
if(applySet["thumb"]) {
// The max thumbnail height is
int thbHeight = globSet->thumbnailsize + globSet->thumbnailLiftUp + 30;
int viewH = viewBig->height();
int viewW = viewBig->width();
// If the thumbnails are supposed to be shown at the bottom
if(globSet->thumbnailposition == "Bottom") {
// Adjust the thumbnail geometry
viewThumbs->setRect(QRect(0,viewH-thbHeight,viewW,thbHeight));
// Adjust the menu geometry
if(setupWidgets->menu) menu->setRect(QRect(viewW-500,0,350,300));
// If the thumbnails are supposed to be shown at the top
} else if(globSet->thumbnailposition == "Top") {
// Adjust the thumbnail geometry
viewThumbs->setRect(QRect(0,0,viewBig->width(),thbHeight));
// Adjust the menu geometry
if(setupWidgets->menu) menu->setRect(QRect(viewBig->width()-500,viewBig->height()-300,350,300));
}
// (Re-)Load dir
if(globVar->currentfile != "")
viewThumbs->loadDir(globVar->currentfile);
// Keep Thumbs visible?
if(globSet->thumbnailKeepVisible && !viewThumbs->isVisible())
viewThumbs->makeShow();
}
if(applySet["menu"]) {
// Adjusting the menu sensitivity
if(setupWidgets->menu) menu->setSensitivity(globSet->menusensitivity*3,globSet->menusensitivity*10);
}
if(applySet["thumb"] || applySet["quickinfo"])
// Update the quickinfo labels
// rotation indicator
/* viewBigLay->updateInfo(globVar->currentfile,viewThumbs->countpos,viewThumbs->counttot,globVar->tosave.value(globVar->currentfile));*/
viewBigLay->updateInfo(globVar->currentfile,viewThumbs->countpos,viewThumbs->counttot);
if(applySet["redrawimg"])
drawImage();
if(applySet["exif"])
details->updateFontsize();
QString qtfiles = globSet->knownFileTypesQt;
QString qtfilesextras = globSet->knownFileTypesQtExtras;
if(qtfiles != "" && qtfilesextras != "") qtfiles += ",";
qtfiles += qtfilesextras;
QString gmfiles = globSet->knownFileTypesGm;
imageReader->gmfiles = gmfiles;
imageReader->qtfiles = qtfiles;
imageReader->extrasfiles = globSet->knownFileTypesExtras;
if(setupWidgets->menu) menu->allItems["hide"]->setEnabled(globSet->trayicon);
// If animation is disabled for MyWIdget, we notify class by file (many, many subclasses make use of it)
QFile file_noani(QDir::homePath() + "/.photoqt/mywidget_noani");
if(file_noani.exists()) {
if(!file_noani.remove())
std::cerr << "applysettings: unable to unset 'No Animation' file!" << std::endl;
}
if(!globSet->myWidgetAnimated) {
if(file_noani.open(QIODevice::WriteOnly))
file_noani.close();
else
std::cerr << "applysettings: unable to set 'No Animation' file!" << std::endl;
}
}
// If a widget (like about or settings) is opened, all other functions are suspended
void MainWindow::blockFunc(bool bl) {
if(globVar->verbose) std::clog << "Blocking Interface:" << bl << std::endl;
globVar->blocked = bl;
}
// The close event
void MainWindow::closeEvent(QCloseEvent *e) {
// If a widget (like settings or about) is open, then this close event only closes this widget (like escape)
if(globVar->blocked) {
if(globVar->verbose) std::clog << "Ignoring closeEvent, sending 'Escape' shortcut" << std::endl;
e->ignore();
systemShortcutDO("Escape");
} else {
// Stop the thumbnail thread
viewThumbs->abortThread();
// Hide to system tray
if(globSet->trayicon && !globVar->skipTrayIcon) {
if(set->isVisible())
set->makeHide();
globVar->restoringFromTrayNoResize = QDateTime::currentDateTime().toTime_t();
this->hide();
if(globVar->verbose) std::clog << "Hiding to System Tray." << std::endl;
e->ignore();
// Quit
} else {
viewBig->scene()->clear();
viewThumbs->clearScene();
// Save current geometry
QSettings settings;
settings.setValue("mainWindowGeometry", saveGeometry());
// Remove 'running' file
QFile(QDir::homePath() + "/.photoqt/running").remove();
e->accept();
std::cout << "Goodbye!" << std::endl;
}
}
}
// Draw the big main image
void MainWindow::drawImage() {
if(globVar->verbose) std::clog << "Drawing Image" << std::endl;
// the alignment of the image is always center. If the thumbnails are kept visible, we simply add a tranparent bar to the bottom of the image (happening just a couple lines below)
viewBig->setAlignment(Qt::AlignCenter);
// No file loaded yet,...
if(globVar->currentfile == "") {
if(globVar->verbose) std::clog << "Ask for filename" << std::endl;
// ..., so open a new file
openFile();
// Load image
} else {
// Display busy cursor
qApp->setOverrideCursor(Qt::WaitCursor);
if(globVar->verbose) std::clog << "Got filename:" << globVar->currentfile.toStdString() << std::endl;
// Tell the filehandling widget the new filename
if(setupWidgets->filehandling) filehandling->currentfile = globVar->currentfile;
// If the current directory info hasn't been loaded yet
if(viewThumbs->counttot == 0) {
viewThumbs->setCurrentfile(globVar->currentfile);
viewThumbs->loadDir(globVar->currentfile);
}
// Get the maximum possible dimensions of the main image
int maxW = viewBig->width()-globSet->borderAroundImg*2;
int subtractThumbnailHeight = 0;
if(globSet->thumbnailKeepVisible)
subtractThumbnailHeight = viewThumbs->height();
int maxH = viewBig->height()-2*globSet->borderAroundImg-subtractThumbnailHeight;
// In the two cases below we need to swap dimensions, otherwise the image doesn't fit
if((globVar->rotation == -270 || globVar->rotation == -90)) {
int t = maxW;
maxW = maxH;
maxH = t;
}
// Get the image
QImage img = imageReader->readImage(globVar->currentfile,globVar->rotation,globVar->zoomed,globSet->fitInWindow,QSize(maxW,maxH),true);
if(!globVar->zoomToActualSize) {
// The imagereader stores two possible scaling factors
if(imageReader->scaleImg1 != -1)
viewBig->scale(imageReader->scaleImg1,imageReader->scaleImg1);
if(imageReader->scaleImg2 != -1)
viewBig->scale(imageReader->scaleImg2,imageReader->scaleImg2);
}
// Get the fileformat and the original size
QString fileformat = imageReader->fileformat;
QSize origSize = imageReader->origSize;
globVar->originalImageSize = origSize;
// If the thumbnails are kept visible we need to add a transparent bar to the main image so that they don't overlap
graphItem->setTransBarHeight((!globVar->zoomed && globSet->thumbnailKeepVisible) ? viewThumbs->height() : 0);
// Is it an animated image?
if(imageReader->animatedImg)
graphItem->setMovie(globVar->currentfile,origSize.width(),origSize.height());
// Otherwise do the normal setPixmap()
else
graphItem->setPixmap(QPixmap::fromImage(img));
int imgWidth = img.width();
int imgHeight = img.height();
if((globVar->rotation == -270 || globVar->rotation == -90)) {
int t = imgWidth;
imgWidth = imgHeight;
imgHeight = t;
}
if(imgWidth < viewBig->width()) {
// Set the right position of the main image
int graphItemX = (viewBig->width()-imgWidth)/2.0;
graphItem->setX(graphItemX);
}
if(imgHeight < viewBig->height()) {
int graphItemY = (viewBig->height()-imgHeight)/2.0;
graphItem->setY(graphItemY);
}
// Update the current position of the image in the directory
viewThumbs->countpos = viewThumbs->getImageFilePathIndexOf(globVar->currentfile);
// Adjust scene rect
viewBig->scene()->setSceneRect(viewBig->scene()->itemsBoundingRect());
// If exif isn't read yet AND we also don't need to get this data while a slideshow is running
// (if we check, then it asking if user wants photo rotated can lead to undefined behaviour)
if(!globVar->exifRead && !globVar->slideshowRunning) {
if(globVar->verbose) std::clog << "Requesting Exif Info" << std::endl;
// Exif info read
globVar->exifRead = true;
// These formats known by Photo are supported by exiv2
QStringList formats;
formats << "jpeg"
<< "jpg"
<< "tif"
<< "tiff"
<< "png"
<< "psd"
<< "jpeg2000"
<< "jp2"
<< "jpc"
<< "j2k"
<< "jpf"
<< "jpx"
<< "jpm"
<< "mj2"
<< "bmp"
<< "bitmap"
<< "gif"
<< "tga";
// If supported, load exiv2 data
if(formats.contains(fileformat))
// Update the exif data widget
details->updateData(globVar->currentfile,origSize);
// Otherwise set exiv2 to "unsupported"
else
// Update the exif data widget
details->updateData(globVar->currentfile,origSize,false);
}
// A new image, check if loaded and manipulated previously (this session)
if(globVar->newlyLoadedImage && !globVar->slideshowRunning) {
globVar->newlyLoadedImage = false;
// If the image was zoomed at a previous time this session, we restore the zoom level
if(globVar->store_zoomlevel.keys().contains(globVar->currentfile)) {
if(globVar->store_zoomlevel[globVar->currentfile] == 0 && globSet->rememberZoom)
zoom(true,"actualsize");
else if(globVar->store_zoomlevel[globVar->currentfile] < 0 && globSet->rememberZoom)
for(int tmp = globVar->store_zoomlevel[globVar->currentfile]; tmp < 0; ++tmp)
zoom(false,"storedvalue");
else if(globVar->store_zoomlevel[globVar->currentfile] > 0 && globSet->rememberZoom)
for(int tmp = globVar->store_zoomlevel[globVar->currentfile]; tmp > 0; --tmp)
zoom(true,"storedvalue");
}
// The rotation/flipping is stored temporarily for each session
// We reset the rotation/flipping after the image has changed
if(globVar->store_rotation.keys().contains(globVar->currentfile) && globVar->store_rotation[globVar->currentfile] != 0 && globVar->store_rotation[globVar->currentfile] != globVar->rotation && globSet->rememberRotation) {
int val = globVar->store_rotation[globVar->currentfile];
QString clock = "anticlock";
if(val < 0) {
clock = "clock";
val *= -1;
}
rotateFlip(true,clock,val);
}
if(globSet->rememberRotation && globVar->store_flipHor.value(globVar->currentfile) && globVar->store_flipHor.value(globVar->currentfile) != globVar->flipHor)
rotateFlip(false,"hor");
if(globVar->store_flipVer[globVar->currentfile] && globVar->store_flipVer[globVar->currentfile] != globVar->flipVer && globSet->rememberRotation)
rotateFlip(false,"ver");
// Scroll to previous position
restoreScrollbarValues();
}
// Restore normal cursor
qApp->restoreOverrideCursor();
if(viewThumbs->getImageFilePathIndexOf(globVar->currentfile) != -1 && !globSet->thumbnailDisable) {
if(viewThumbs->pixmapLoaded(globVar->currentfile))
// We center on the image if it's a newly loaded dir or if respective setting it set
viewThumbs->centerOnCurrent();
// We also have to check here where the cursor is, cause sometimes the app reaches these statements here when auto rotate is active (exif)
if(!globSet->thumbnailKeepVisible && viewThumbs->isVisible() && !viewThumbs->areaShown().contains(mapFromGlobal(QCursor::pos())))
viewThumbs->makeHide();
}
}
}
void MainWindow::firstStartSetup() {
// On first start ever, we need to set the default file for disabled file formats.
QFile file(QDir::homePath() + "/.photoqt/fileformats.disabled");
if(file.exists()) file.remove();
if(!file.open(QIODevice::WriteOnly))
std::cerr << "[setup] ERROR: Unable to create file 'fileformats.disabled'";
else {
if(globVar->verbose) std::clog << "[setup] Create default file for disabled file formats" << std::endl;
QTextStream out(&file);
QString txt = QString("*.eps\n")
+ QString("*.epsf\n")
+ QString("*.epi\n")
+ QString("*.epsi\n")
+ QString("*.ept\n")
+ QString("*.eps2\n")
+ QString("*.eps3\n")
+ QString("*.pdf\n")
+ QString("*.ps\n")
+ QString("*.ps2\n")
+ QString("*.ps3\n")
+ QString("*.hp\n")
+ QString("*.hpgl\n")
+ QString("*.jbig\n")
+ QString("*.jbg\n")
+ QString("*.pwp\n")
+ QString("*.rast\n")
+ QString("*.rla\n")
+ QString("*.rle\n")
+ QString("*.sct\n")
+ QString("*.tim\n")
+ QString("**.xcf\n")
+ QString("**.psb\n")
+ QString("**.psd\n");
out << txt;
file.close();
// And update fileformats
globSet->fileFormats->getFormats();
QMap<QString, QVariant> upd;
upd.insert("KnownFileTypesQt",globSet->fileFormats->formatsQtEnabled.join(","));
upd.insert("KnownFileTypesGm",globSet->fileFormats->formatsGmEnabled.join(","));
upd.insert("KnownFileTypesExtras", globSet->fileFormats->formatsExtrasEnabled.join(", "));
globSet->settingsUpdated(upd);
}
// The main image has context menu with internal and external functions
QFile contextmenu(QDir::homePath() + "/.photoqt/contextmenu");
if(!contextmenu.exists()) {
if(globVar->verbose) std::clog << "Create basic context menu file" << std::endl;
if(contextmenu.open(QIODevice::WriteOnly)) {
if(globVar->verbose) std::clog << "Setup default context menu entries";
QTextStream out(&contextmenu);
// We check for the existence of the following applications
QStringList lst;
QStringList lst_desc;
lst << "gimp %f";
lst_desc << "Edit with Gimp";
lst << "krita %f";
lst_desc << "Edit with Krita";
lst << "kolourpaint %f"; // **
lst_desc << "Edit with KolourPaint";
lst << "gwenview %f";
lst_desc << "Open in GwenView";
lst << "shotwell %f"; // **
lst_desc << "Open in Shotwell";
lst << "gthumb %f"; // **
lst_desc << "Open in gThumb";
lst << "showfoto %f";
lst_desc << "Open in showFoto";
lst << "eog %f"; // **
lst_desc << "Open in Eye of Gnome";
QString def = "";
// We use the 'which' command to check for existence
for(int i = 0; i < lst.length(); ++i) {
QProcess p;
p.setStandardOutputFile(QProcess::nullDevice());
p.start("which " + QString(lst.at(i)).remove("%f").remove("%d").trimmed());
p.waitForFinished();
if(!p.exitCode()) def += "0" + lst.at(i) + "\n" + QObject::tr(lst_desc.at(i).toLatin1()) + "\n\n";
}
// And save contextmenu
out << def;
contextmenu.close();
} else
std::cerr << "ERROR: Couldn't create contextmenu file" << std::endl;
}
}
// When the Exif data dictates an orientation
void MainWindow::getOrientationFromExif(int degree, bool flipHor) {
if(globVar->verbose) std::clog << "Exif Rotate/Flip:" << degree << "-" << flipHor << std::endl;
// If we don't abort in that case, we apply rotation more than once...
if(globVar->store_rotation.keys().contains(globVar->currentfile)) return;
// And rotate
if(degree > 0) {
while(degree > 0) {
globVar->rotation += 90;
viewBig->rotate(-90);
globVar->rotation %= 360;
degree -= 90;
}
drawImage();
}
// Flip Horizontally
if(flipHor) {
viewBig->scale(-1,1);
globVar->flipHor = !globVar->flipHor;
}
// A vertical flip is just a horizontal flip plus 180° turn
}
// The global timer to ensure only one instance of PhotoQt running and to make PhotoQt remotely controllable
void MainWindow::globalRunningProgTimerTimeout() {
// Updates the "running" file with current timestamp
QFile t(QDir::homePath() + "/.photoqt/running");
if(t.open(QIODevice::WriteOnly)) {
QTextStream out(&t);
out << QDateTime::currentMSecsSinceEpoch();
t.close();
} else
std::cerr << "ERROR! Unable to write to file '~/.photoqt/running' - unable to control this instance through command line." << std::endl;
// Checks the "cmd" file for commands to be executed
QFile cmd(QDir::homePath() + "/.photoqt/cmd");
// Switches to identify options set
bool doOpen = false;
bool doShow = false;
bool doHide = false;
bool doToggle = false;
bool doNoThumbs = false;
bool doThumbs = false;
QString doNewFile = "";
// If the file exists
if(cmd.exists() && cmd.open(QIODevice::ReadWrite)) {
if(globVar->verbose) std::clog << "Got passed on commands" << std::endl;
QTextStream in(&cmd);
QStringList lines = in.readAll().split("\n",QString::SkipEmptyParts);
foreach(QString line, lines) {
// Check all the possivle options
if(line == "--open")
doOpen = true;
if(line == "--show")
doShow = true;
if(line == "--hide")
doHide = true;
if(line == "--toggle")
doToggle = true;
if(line == "--no-thumbs")
doNoThumbs = true;
if(line == "--thumbs")
doThumbs = true;
if(line.startsWith("-f-"))
doNewFile = line.remove(0,3).toUtf8();
}
cmd.close();
} else if(cmd.exists())
std::cerr << "ERROR! Can't read '~/.photoqt/cmd'." << std::endl;
else if(!cmd.exists())
return;
// Remove file after command is read in
cmd.remove();
// We can only do stuff if interface is not blocked, except show window
if(globVar->blocked) {
if(globVar->verbose) std::clog << "[globtimer] interface blocked, only 'do show'" << std::endl;
doOpen = false;
doShow = true;
doHide = false;
doToggle = false;
doNoThumbs = false;
doThumbs = false;
doNewFile = "";
}
if(doNewFile != "") {
if(this->isHidden())
doShow = true;
doOpen = false;
}
// Toggle PhotoQt
if(doToggle) {
if(this->isVisible()) {
doHide = true;
doShow = false;
} else if(this->isHidden()) {
doShow = true;
doHide = false;
}
}
// Open a new file
if(doOpen) {
if(globVar->verbose) std::clog << "[globtimer] open new file" << std::endl;
if(this->isHidden()) {
takeScreenshots(); // Refresh screenshots
if(!globSet->windowmode) {
this->showFullScreen();
} else if(globVar->windowMaximised) {
this->showMaximized();
globVar->windowMaximised = true;
} else {
this->showNormal();
globVar->windowMaximised = false;
}
setBackground(); // Refresh background
}
doShow = false;
doHide = false;
openFile();
}
// Show PhotoQt
if(doShow) {
if(globVar->verbose) std::clog << "[globtimer] show interface" << std::endl;
if(this->isHidden()) {
takeScreenshots(); // Refresh screenshots
if(!globSet->windowmode) {
this->showFullScreen();
} else if(globVar->windowMaximised) {
this->showMaximized();
globVar->windowMaximised = true;
} else {
this->showNormal();
globVar->windowMaximised = false;
}
setBackground(); // Refresh background
}
this->activateWindow();
this->raise();
doHide = false;
if(globVar->currentfile == "" && doNewFile == "" && !globVar->blocked)
openFile();
// Need to call with delay to make sure they are actually adjusted correctly!
QTimer::singleShot(500,this,SLOT(adjustGeometries()));
}
// Hide PhotoQt
if(doHide) {
if(globVar->verbose) std::clog << "[globtimer] hide interface" << std::endl;
if(!globSet->trayicon) {
globSet->trayicon = true;
globSet->saveSettings();
}
if(this->isVisible())
this->hide();
}
// Disable thumbnails
if(doNoThumbs && !globSet->thumbnailDisable) {
if(globVar->verbose) std::clog << "[globtimer] disable thumbnails" << std::endl;
QMap<QString,QVariant> upd;
upd.insert("ThumbnailDisable",true);
globSet->settingsUpdated(upd);
doThumbs = false;
}
// Enable thumbnails
if(doThumbs && globSet->thumbnailDisable) {
if(globVar->verbose) std::clog << "[globtimer] enable thumbnails" << std::endl;
QMap<QString,QVariant> upd;
upd.insert("ThumbnailDisable",false);
globSet->settingsUpdated(upd);
}
// Load new file
if(doNewFile != "")
loadNewImgFromOpen(doNewFile);
}
// Go to a specific image
void MainWindow::gotoImageAtPos(int p) {
// Store visible area
globVar->store_visibleArea[globVar->currentfile] = std::pair<int,int>(viewBig->horizontalScrollBar()->value(),viewBig->verticalScrollBar()->value());
// When a new image is loaded we reset any zooing, rotation, flipping
QMap<QString,int> tmp_rotation = globVar->store_rotation;
QMap<QString,bool> tmp_flipHor = globVar->store_flipHor;
QMap<QString,bool> tmp_flipVer = globVar->store_flipVer;
QMap<QString,int> tmp_zoomlevel = globVar->store_zoomlevel;
QMap<QString,std::pair<int,int> > tmp_visibleArea = globVar->store_visibleArea;
zoom(true,((globVar->zoomToActualSize || globVar->zoomed) && globSet->transition != 0) ? "reset" : "resetNoDraw");
rotateFlip(true,"resetNoDraw");
rotateFlip(false, "reset");
globVar->store_rotation = tmp_rotation;
globVar->store_flipHor = tmp_flipHor;
globVar->store_flipVer = tmp_flipVer;
globVar->store_zoomlevel = tmp_zoomlevel;
globVar->store_visibleArea = tmp_visibleArea;
// Reset these parameters
viewBig->absoluteScaleFactor = 0;
globVar->zoomed = false;
globVar->rotation = 0;
globVar->exifRead = false;
// Load image at pos 'p'
globVar->newlyLoadedImage = true;
globVar->zoomedImgAtLeastOnce = false;
globVar->currentfile = viewThumbs->getImageFilePathAt(p);
viewThumbs->countpos = p;
viewThumbs->updateThbViewHoverNormPix(viewThumbs->getCurrentfile(),globVar->currentfile);
viewThumbs->setCurrentfile(globVar->currentfile);
drawImage();
// Update info
viewBigLay->updateInfo(globVar->currentfile,viewThumbs->countpos,viewThumbs->counttot);
}
// A click onto the main graphicsview
void MainWindow::gotViewBigClick(QPoint p) {
if(globVar->verbose) std::clog << "Click received:" << QString("x:y: %1:%2").arg(p.x()).arg(p.y()).toStdString() << std::endl;
QPointF point = viewBig->mapToScene(p);
int x = point.x();
int y = point.y();
int xg = graphItem->pos().x();
int yg = graphItem->pos().y();
int wg = graphItem->pixmap().width();
int hg = graphItem->pixmap().height();
// If click was on grey area outside image and corresponding option is set, then close PhotoQt
if(x < xg || x > xg+wg || y < yg || y > yg+hg || globVar->currentfile.trimmed().length() == 0) {
if(globSet->closeongrey) {
globVar->skipTrayIcon = true;
this->close();
}
}
}
// Enabling the key detection by the shortcuts
void MainWindow::keyReleaseEvent(QKeyEvent *e) {