-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsessionwindow.cpp
More file actions
169 lines (140 loc) · 4.81 KB
/
sessionwindow.cpp
File metadata and controls
169 lines (140 loc) · 4.81 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
#include <QFileInfo>
#include <QShortcut>
#include <QMovie>
#include <QDebug>
#include <QScrollBar>
#include <QSizePolicy>
#include <QDesktopWidget>
#include "sessionwindow.h"
#include "mainwindow.h"
#include "ui_sessionwindow.h"
SessionWindow::SessionWindow(Session *s, QWidget *parent) :
QMainWindow(parent),
ui(new Ui::SessionWindow)
{
session = s;
// Load the files for the session again, in case any new ones have been added
session->LoadFiles();
ui->setupUi(this);
lblImage = new QLabel;
lblImage->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum);
ui->imageScrollArea->setWidget(lblImage);
QObject::connect(ui->btnNext, SIGNAL(clicked()), this, SLOT(ButtonNextPushed()));
QObject::connect(ui->btnPrevious, SIGNAL(clicked()), this, SLOT(ButtonPreviousPushed()));
QObject::connect(ui->btnFirst, SIGNAL(clicked()), this, SLOT(ButtonFirstPushed()));
QObject::connect(ui->btnLast, SIGNAL(clicked()), this, SLOT(ButtonLastPushed()));
setWindowTitle("QImageViewer | " + session->GetName());
}
SessionWindow::~SessionWindow()
{
delete ui;
}
void SessionWindow::closeEvent(QCloseEvent *event)
{
MainWindow::Get()->RemoveActiveSessionWindow(this);
}
void SessionWindow::keyPressEvent(QKeyEvent *event)
{
if (event->key() == Qt::Key_Left)
{
ButtonPreviousPushed();
}
else if (event->key() == Qt::Key_Right)
{
ButtonNextPushed();
}
}
Session * SessionWindow::GetSession()
{
return session;
}
void SessionWindow::ButtonNextPushed()
{
session->NextFile();
ShowCurrentImage();
}
void SessionWindow::ButtonPreviousPushed()
{
session->PreviousFile();
ShowCurrentImage();
}
void SessionWindow::ButtonFirstPushed()
{
session->FirstFile();
ShowCurrentImage();
}
void SessionWindow::ButtonLastPushed()
{
session->LastFile();
ShowCurrentImage();
}
void SessionWindow::showEvent(QShowEvent *event)
{
QWidget::showEvent(event);
ShowCurrentImage();
}
void SessionWindow::ShowCurrentImage()
{
QString filename = session->GetCurrentFileName();
// Display the current filename in a label
QFileInfo info(filename);
ui->lblFilename->setText(info.fileName());
// Remember the previous movie
QMovie *oldMovie = lblImage->movie();
// Setup the movie for the current image
QMovie *newMovie = new QMovie(filename);
if (!newMovie->isValid())
{
lblImage->setText("File format not supported");
return;
}
lblImage->setMovie(newMovie);
newMovie->start();
// Delete the previous movie
if (oldMovie != NULL)
{
delete oldMovie;
}
// Set the hover text for the current image
lblImage->setToolTip(QString("<FONT COLOR=black>") + session->GetCurrentHoverText() + QString("</FONT>"));
// Pack the window
lblImage->adjustSize();
// Must resize scroll area by hand, add a small offset so scrollbars hide
ui->imageScrollArea->setFixedHeight(lblImage->height() + 2);
ui->imageScrollArea->setFixedWidth(lblImage->width() + 2);
ui->centralwidget->adjustSize();
this->adjustSize();
// If we're too big then shrink the scroll area
int availableHeight = QApplication::desktop()->availableGeometry().height();
int availableWidth = QApplication::desktop()->availableGeometry().width();
int windowHeight = this->frameSize().height();
int windowWidth = this->frameSize().width();
if (windowHeight > availableHeight)
{
int offset = windowHeight - availableHeight;
ui->imageScrollArea->setFixedHeight(ui->imageScrollArea->height() - offset);
// Expand the width because of the new scrollbar
int roomToGrowWidth = availableWidth - windowWidth;
int amountToExpandWidth = std::min(roomToGrowWidth, ui->imageScrollArea->verticalScrollBar()->width());
amountToExpandWidth = std::max(amountToExpandWidth, 0);
ui->imageScrollArea->setFixedWidth(ui->imageScrollArea->width() + amountToExpandWidth);
// Pack the rest of the ui
ui->centralwidget->adjustSize();
this->adjustSize();
}
windowHeight = this->frameSize().height();
windowWidth = this->frameSize().width();
if (windowWidth > availableWidth)
{
int offset = windowWidth - availableWidth;
ui->imageScrollArea->setFixedWidth(ui->imageScrollArea->width() - offset);
// Expand the height because of the new scrollbar
int roomToGrowHeight = availableHeight - windowHeight;
int amountToExpandHeight = std::min(roomToGrowHeight, ui->imageScrollArea->horizontalScrollBar()->height());
amountToExpandHeight = std::max(amountToExpandHeight, 0);
ui->imageScrollArea->setFixedHeight(ui->imageScrollArea->height() + amountToExpandHeight);
// Pack the rest of the ui
ui->centralwidget->adjustSize();
this->adjustSize();
}
}