@@ -31,6 +31,7 @@ MainWindow::MainWindow(QWidget *parent) :
31
31
this ->setAttribute (Qt::WA_TranslucentBackground, true );
32
32
this ->setMinimumSize (710 , 530 );
33
33
this ->setWindowIcon (QIcon (" :/icons/app-icon.svg" ));
34
+ this ->setMouseTracking (true );
34
35
35
36
m_fadeOutAnimation = new QPropertyAnimation (this , " windowOpacity" );
36
37
m_fadeOutAnimation->setDuration (300 );
@@ -72,13 +73,29 @@ MainWindow::MainWindow(QWidget *parent) :
72
73
connect (m_graphicsView, &GraphicsView::requestGallery,
73
74
this , &MainWindow::loadGalleryBySingleLocalFile);
74
75
75
- m_closeButton = new ToolButton (m_graphicsView);
76
+ m_closeButton = new ToolButton (true , m_graphicsView);
76
77
m_closeButton->setIcon (QIcon (" :/icons/window-close" ));
77
78
m_closeButton->setIconSize (QSize (50 , 50 ));
78
79
79
80
connect (m_closeButton, &QAbstractButton::clicked,
80
81
this , &MainWindow::closeWindow);
81
82
83
+ m_prevButton = new ToolButton (false , m_graphicsView);
84
+ m_prevButton->setIcon (QIcon (" :/icons/go-previous" ));
85
+ m_prevButton->setIconSize (QSize (75 , 75 ));
86
+ m_prevButton->setVisible (false );
87
+ m_prevButton->setOpacity (0 , false );
88
+ m_nextButton = new ToolButton (false , m_graphicsView);
89
+ m_nextButton->setIcon (QIcon (" :/icons/go-next" ));
90
+ m_nextButton->setIconSize (QSize (75 , 75 ));
91
+ m_nextButton->setVisible (false );
92
+ m_nextButton->setOpacity (0 , false );
93
+
94
+ connect (m_prevButton, &QAbstractButton::clicked,
95
+ this , &MainWindow::galleryPrev);
96
+ connect (m_nextButton, &QAbstractButton::clicked,
97
+ this , &MainWindow::galleryNext);
98
+
82
99
m_bottomButtonGroup = new BottomButtonGroup (this );
83
100
84
101
connect (m_bottomButtonGroup, &BottomButtonGroup::resetToOriginalBtnClicked,
@@ -109,6 +126,11 @@ MainWindow::MainWindow(QWidget *parent) :
109
126
m_gv->setOpacity (0 , false );
110
127
m_closeButton->setOpacity (0 , false );
111
128
129
+ connect (this , &MainWindow::galleryLoaded, this , [this ]() {
130
+ m_prevButton->setVisible (isGalleryAvailable ());
131
+ m_nextButton->setVisible (isGalleryAvailable ());
132
+ });
133
+
112
134
QShortcut * quitAppShorucut = new QShortcut (QKeySequence (Qt::Key_Space), this );
113
135
connect (quitAppShorucut, &QShortcut::activated,
114
136
std::bind (&MainWindow::quitAppAction, this , false ));
@@ -222,13 +244,13 @@ void MainWindow::loadGalleryBySingleLocalFile(const QString &path)
222
244
}
223
245
}
224
246
225
- // qDebug() << m_files << m_currentFileIndex ;
247
+ emit galleryLoaded () ;
226
248
}
227
249
228
250
void MainWindow::galleryPrev ()
229
251
{
230
252
int count = m_files.count ();
231
- if (m_currentFileIndex < 0 || m_files. isEmpty () || m_currentFileIndex >= m_files. count ()) {
253
+ if (! isGalleryAvailable ()) {
232
254
return ;
233
255
}
234
256
@@ -240,7 +262,7 @@ void MainWindow::galleryPrev()
240
262
void MainWindow::galleryNext ()
241
263
{
242
264
int count = m_files.count ();
243
- if (m_currentFileIndex < 0 || m_files. isEmpty () || m_currentFileIndex >= m_files. count ()) {
265
+ if (! isGalleryAvailable ()) {
244
266
return ;
245
267
}
246
268
@@ -249,6 +271,14 @@ void MainWindow::galleryNext()
249
271
m_graphicsView->showFileFromUrl (m_files.at (m_currentFileIndex), false );
250
272
}
251
273
274
+ bool MainWindow::isGalleryAvailable ()
275
+ {
276
+ if (m_currentFileIndex < 0 || m_files.isEmpty () || m_currentFileIndex >= m_files.count ()) {
277
+ return false ;
278
+ }
279
+ return true ;
280
+ }
281
+
252
282
void MainWindow::showEvent (QShowEvent *event)
253
283
{
254
284
updateWidgetsPosition ();
@@ -262,6 +292,8 @@ void MainWindow::enterEvent(QEvent *event)
262
292
m_gv->setOpacity (1 );
263
293
264
294
m_closeButton->setOpacity (1 );
295
+ m_prevButton->setOpacity (1 );
296
+ m_nextButton->setOpacity (1 );
265
297
266
298
return QMainWindow::enterEvent (event);
267
299
}
@@ -272,6 +304,8 @@ void MainWindow::leaveEvent(QEvent *event)
272
304
m_gv->setOpacity (0 );
273
305
274
306
m_closeButton->setOpacity (0 );
307
+ m_prevButton->setOpacity (0 );
308
+ m_nextButton->setOpacity (0 );
275
309
276
310
return QMainWindow::leaveEvent (event);
277
311
}
@@ -537,6 +571,9 @@ void MainWindow::closeWindow()
537
571
void MainWindow::updateWidgetsPosition ()
538
572
{
539
573
m_closeButton->move (width () - m_closeButton->width (), 0 );
574
+ m_prevButton->move (25 , (height () - m_prevButton->height ()) / 2 );
575
+ m_nextButton->move (width () - m_nextButton->width () - 25 ,
576
+ (height () - m_prevButton->height ()) / 2 );
540
577
m_bottomButtonGroup->move ((width () - m_bottomButtonGroup->width ()) / 2 ,
541
578
height () - m_bottomButtonGroup->height ());
542
579
m_gv->move (width () - m_gv->width (), height () - m_gv->height ());
@@ -546,6 +583,8 @@ void MainWindow::toggleProtectedMode()
546
583
{
547
584
m_protectedMode = !m_protectedMode;
548
585
m_closeButton->setVisible (!m_protectedMode);
586
+ m_prevButton->setVisible (!m_protectedMode);
587
+ m_nextButton->setVisible (!m_protectedMode);
549
588
}
550
589
551
590
void MainWindow::toggleStayOnTop ()
0 commit comments