/
pmrwindowwindow.cpp
382 lines (267 loc) · 12.4 KB
/
pmrwindowwindow.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
/*******************************************************************************
Copyright (C) The University of Auckland
OpenCOR 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.
OpenCOR 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/>.
*******************************************************************************/
//==============================================================================
// PMR window
//==============================================================================
#include "borderedwidget.h"
#include "corecliutils.h"
#include "coreguiutils.h"
#include "pmrsupportpreferenceswidget.h"
#include "pmrwebservice.h"
#include "pmrwindowwidget.h"
#include "pmrwindowwindow.h"
#include "preferencesinterface.h"
#include "toolbarwidget.h"
//==============================================================================
#include "ui_pmrwindowwindow.h"
//==============================================================================
#include <QLabel>
#include <QLineEdit>
#include <QMainWindow>
#include <QTimer>
//==============================================================================
namespace OpenCOR {
namespace PMRWindow {
//==============================================================================
PmrWindowWindow::PmrWindowWindow(QWidget *pParent) :
Core::OrganisationWidget(pParent),
mGui(new Ui::PmrWindowWindow),
mItemDoubleClicked(false)
{
// Set up the GUI
mGui->setupUi(this);
// Create a tool bar widget with a URL value and refresh button
// Note: the spacers is a little trick to improve the rendering of our tool
// bar widget...
Core::ToolBarWidget *toolBarWidget = new Core::ToolBarWidget();
QWidget *spacer = new QWidget(toolBarWidget);
spacer->setMinimumSize(0, 0);
spacer->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding);
mFilterLabel = new QLabel(toolBarWidget);
mFilterValue = new QLineEdit(toolBarWidget);
QFont font = mFilterLabel->font();
font.setBold(true);
mFilterLabel->setFont(font);
#ifdef Q_OS_MAC
mFilterValue->setAttribute(Qt::WA_MacShowFocusRect, false);
#endif
connect(mFilterValue, SIGNAL(textChanged(const QString &)),
this, SLOT(filterValueChanged(const QString &)));
toolBarWidget->addWidget(spacer);
toolBarWidget->addWidget(mFilterLabel);
toolBarWidget->addWidget(mFilterValue);
toolBarWidget->addAction(mGui->actionReload);
mGui->layout->addWidget(toolBarWidget);
// Make the filter value our focus proxy
setFocusProxy(mFilterValue);
// Create and add a label to highlight the repository we are using
mPmrInstanceLabel = new QLabel(this);
QFont newFont = mPmrInstanceLabel->font();
newFont.setPointSizeF(0.7*newFont.pointSizeF());
mPmrInstanceLabel->setAlignment(Qt::AlignCenter);
mPmrInstanceLabel->setEnabled(false);
mPmrInstanceLabel->setFont(newFont);
mGui->layout->addWidget(mPmrInstanceLabel);
// Create and add our PMR widget
mPmrWindowWidget = new PmrWindowWidget(this);
#if defined(Q_OS_WIN) || defined(Q_OS_LINUX)
mGui->layout->addWidget(new Core::BorderedWidget(mPmrWindowWidget,
true, true, true, true));
#elif defined(Q_OS_MAC)
mGui->layout->addWidget(new Core::BorderedWidget(mPmrWindowWidget,
true, false, false, false));
#else
#error Unsupported platform
#endif
// Keep track of the window's visibility, so that we can request the list of
// exposures, if necessary
connect(this, SIGNAL(visibilityChanged(bool)),
this, SLOT(retrieveExposures(const bool &)));
// Create an instance of our PMR web service
mPmrWebService = new PMRSupport::PmrWebService(this);
// Initialise (update) our PMR URL
update(PreferencesInterface::preference(PMRSupport::PluginName,
PMRSupport::SettingsPreferencesPmrUrl,
PMRSupport::SettingsPreferencesPmrUrlDefault).toString());
// Some connections to process responses from our PMR web service
connect(mPmrWebService, SIGNAL(busy(const bool &)),
this, SLOT(busy(const bool &)));
connect(mPmrWebService, SIGNAL(information(const QString &)),
this, SLOT(showInformation(const QString &)));
connect(mPmrWebService, SIGNAL(warning(const QString &)),
this, SLOT(showWarning(const QString &)));
connect(mPmrWebService, SIGNAL(error(const QString &)),
this, SLOT(showError(const QString &)));
connect(mPmrWebService, SIGNAL(exposures(const PMRSupport::PmrExposures &)),
this, SLOT(initializeWidget(const PMRSupport::PmrExposures &)));
connect(mPmrWebService, SIGNAL(exposureFiles(const QString &, const QStringList &)),
mPmrWindowWidget, SLOT(addAndShowExposureFiles(const QString &, const QStringList &)));
// Some connections to know what our PMR widget wants from us
connect(mPmrWindowWidget, SIGNAL(cloneWorkspaceRequested(const QString &)),
mPmrWebService, SLOT(requestExposureWorkspaceClone(const QString &)));
connect(mPmrWindowWidget, SIGNAL(exposureFilesRequested(const QString &)),
mPmrWebService, SLOT(requestExposureFiles(const QString &)));
connect(mPmrWindowWidget, SIGNAL(openExposureFileRequested(const QString &)),
this, SLOT(openFile(const QString &)));
connect(mPmrWindowWidget, SIGNAL(openExposureFilesRequested(const QStringList &)),
this, SLOT(openFiles(const QStringList &)));
connect(mPmrWindowWidget, SIGNAL(itemDoubleClicked()),
this, SLOT(itemDoubleClicked()));
// Some further initialisations that are done as part of retranslating the
// GUI (so that they can be updated when changing languages)
retranslateUi();
}
//==============================================================================
PmrWindowWindow::~PmrWindowWindow()
{
// Delete the GUI
delete mGui;
}
//==============================================================================
void PmrWindowWindow::retranslateUi()
{
// Retranslate our whole window and our information note message
mGui->retranslateUi(this);
mFilterLabel->setText(tr("Filter:"));
mPmrInstanceLabel->setText(mPmrWebService->siteName());
// Retranslate our PMR widget
mPmrWindowWidget->retranslateUi();
}
//==============================================================================
void PmrWindowWindow::resizeEvent(QResizeEvent *pEvent)
{
// Default handling of the event
Core::OrganisationWidget::resizeEvent(pEvent);
// Resize our busy widget
mPmrWindowWidget->resizeBusyWidget();
}
//==============================================================================
void PmrWindowWindow::update(const QString &pPmrUrl)
{
// Update our PMR web service and then reload ourselves, if needed
if (pPmrUrl.compare(mPmrUrl)) {
if (mPmrWindowWidget->hasExposures())
mPmrWindowWidget->initialize(PMRSupport::PmrExposures(), QString(), QString());
mPmrUrl = pPmrUrl;
mPmrWebService->update(pPmrUrl);
mPmrInstanceLabel->setText(mPmrWebService->siteName());
retrieveExposures(isVisible());
}
}
//==============================================================================
void PmrWindowWindow::filterValueChanged(const QString &pText)
{
// Ask our PMR widget to filter its output using the given regular
// expression
mPmrWindowWidget->filter(pText);
}
//==============================================================================
void PmrWindowWindow::busy(const bool &pBusy)
{
// Show ourselves as busy or not busy anymore
static int counter = 0;
if (!pBusy && !counter)
return;
counter += pBusy?1:-1;
if (pBusy && (counter == 1)) {
mGui->dockWidgetContents->setEnabled(false);
mPmrWindowWidget->showBusyWidget();
} else if (!pBusy && !counter) {
// Re-enable the GUI side and give, within the current window, the focus
// to mFilterValue, but only if the current window already has the
// focus, or to mPmrWindowWidget if it was previously double clicked
mGui->dockWidgetContents->setEnabled(true);
if (mItemDoubleClicked) {
mItemDoubleClicked = false;
mPmrWindowWidget->setFocus();
} else {
Core::setFocusTo(mFilterValue);
}
mPmrWindowWidget->hideBusyWidget();
}
}
//==============================================================================
void PmrWindowWindow::showInformation(const QString &pMessage)
{
// Show the given message as an information message box, but only if we
// already have some exposures
// Note: indeed, the idea is not to break the user's workflow, should some
// information become available when trying to retrieve the list of
// exposures at startup...
if (mPmrWindowWidget->hasExposures())
Core::informationMessageBox(windowTitle(), pMessage);
}
//==============================================================================
void PmrWindowWindow::showWarning(const QString &pMessage)
{
// Show the given message as a warning message box, but only if we already
// have some exposures
// Note: indeed, the idea is not to break the user's workflow, should a
// warning occur when trying to retrieve the list of exposures at
// startup...
if (mPmrWindowWidget->hasExposures())
Core::warningMessageBox(windowTitle(), pMessage);
}
//==============================================================================
void PmrWindowWindow::showError(const QString &pMessage)
{
// Either show the given message as an error message box or tell our PMR
// widget that we have a problem, this based on whether we have already
// retrieved the list of exposures
// Note: indeed, the idea is not to break the user's workflow, should an
// error occur when trying to retrieve the list of exposures at
// startup...
if (mPmrWindowWidget->hasExposures())
Core::criticalMessageBox(windowTitle(), pMessage);
else
mPmrWindowWidget->initialize(PMRSupport::PmrExposures(), QString(), pMessage);
}
//==============================================================================
void PmrWindowWindow::on_actionReload_triggered()
{
// Get the list of exposures from our PMR web service
mPmrWebService->requestExposures();
}
//==============================================================================
void PmrWindowWindow::initializeWidget(const PMRSupport::PmrExposures &pExposures)
{
// Ask our PMR widget to initialise itself
mPmrWindowWidget->initialize(pExposures, mFilterValue->text(), QString());
}
//==============================================================================
void PmrWindowWindow::itemDoubleClicked()
{
// Keep track of the fact that an item got double clicked and that we will
// want it to get the focus back once we are not busy anymore
mItemDoubleClicked = true;
}
//==============================================================================
void PmrWindowWindow::retrieveExposures(const bool &pVisible)
{
// Retrieve the list of exposures, if we are becoming visible and the list
// of exposures has never been requested before (through a single shot, this
// to allow other events, such as the one asking OpenCOR's main window to
// resize itself, to be handled properly)
static bool firstTime = true;
if (pVisible && firstTime) {
firstTime = false;
QTimer::singleShot(0, this, SLOT(on_actionReload_triggered()));
}
}
//==============================================================================
} // namespace PMRWindow
} // namespace OpenCOR
//==============================================================================
// End of file
//==============================================================================