8 #include <QApplication>
9 #include <QCoreApplication>
10 #include <QDesktopWidget>
16 #include <QMessageBox>
18 #include <QScrollArea>
58 if (!XOpenDisplay(NULL)) {
59 std::cerr <<
"cannot connect to X server...\n\n"
60 "Do you have an X server running?\n\n"
62 " If you are trying to run this program remotely using ssh, then "
63 "did you enable X11 forwarding?\n\n"
64 "If the possible causes cited above have been ruled out and this "
65 "problem persists, then check your X settings or contact your "
66 "system administrator.\n\n";
79 PvlGroup &uiPref = Preference::Preferences().findGroup(
"UserInterface");
85 setlocale(LC_ALL,
"en_US");
86 QCoreApplication::setApplicationName(
FileName(argv[0]).baseName());
87 QApplication::setQuitOnLastWindowClosed(
true);
94 QString style = uiPref[
"GuiStyle"];
95 QApplication::setStyle(style);
111 for(
int group = 0; group < ui.
NumGroups(); group++) {
112 for(
int param = 0; param < ui.
NumParams(group); param++) {
113 p_parameters.push_back(AddParameter(ui, group, param));
118 for(
int p = 0; p < (int)p_parameters.size(); p++) {
126 p_scrollLayout->addStretch(1);
130 p_progressBar->setMinimum(0);
131 p_progressBar->setMaximum(100);
132 p_progressBar->setValue(0);
133 p_progressBar->setMinimumWidth(200);
135 p_statusText =
new QLabel(
"Ready");
137 statusBar()->setSizeGripEnabled(
true);
138 statusBar()->addWidget(p_progressBar, 0);
139 statusBar()->addWidget(p_statusText, 3);
148 for(
unsigned int i = 0; i < p_parameters.size(); i++) {
149 delete p_parameters[i];
152 p_parameters.clear();
156 void Gui::CreateAreas() {
158 QSplitter *split =
new QSplitter(Qt::Vertical,
this);
161 p_scrollArea =
new QScrollArea();
162 p_scrollWidget =
new QWidget();
163 p_scrollLayout =
new QVBoxLayout;
164 p_scrollWidget->setLayout(p_scrollLayout);
165 p_scrollArea->setWidget(p_scrollWidget);
166 p_scrollArea->setWidgetResizable(
true);
169 int height = QApplication::desktop()->height();
173 p_log->setMinimumHeight(10);
174 p_log->resize(p_log->width(), 250);
176 split->addWidget(p_scrollArea);
177 split->addWidget(p_log);
178 split->setChildrenCollapsible(
false);
179 split->setStretchFactor(0, 3);
180 split->setStretchFactor(1, 0);
181 setCentralWidget(split);
182 resize(720, (
int)(height / 2) + 350);
185 p_processAction = CreateProcessAction();
186 p_stopAction = CreateStopAction();
187 p_exitAction = CreateExitAction();
189 p_previousHistoryAction = CreatePreviousHistoryAction();
190 p_nextHistoryAction = CreateNextHistoryAction();
191 p_resetAction = CreateResetAction();
193 p_saveLogAction = CreateSaveLogAction();
194 p_clearLogAction = CreateClearLogAction();
196 QAction *whatsThisAction = CreateWhatsThisAction();
199 QMenu *fileMenu = menuBar()->addMenu(
"&File");
200 fileMenu->addAction(p_processAction);
201 fileMenu->addAction(p_stopAction);
202 fileMenu->addAction(p_exitAction);
205 QMenu *optionsMenu = menuBar()->addMenu(
"&Options");
206 optionsMenu->addAction(p_resetAction);
207 optionsMenu->addAction(p_previousHistoryAction);
208 optionsMenu->addAction(p_nextHistoryAction);
209 optionsMenu->addAction(p_saveLogAction);
210 optionsMenu->addAction(p_clearLogAction);
213 QToolBar *tb = addToolBar(
"Controls");
214 tb->setIconSize(QSize(22, 22));
215 tb->addAction(p_processAction);
216 tb->addAction(p_stopAction);
217 tb->addAction(p_exitAction);
220 tb->addAction(p_previousHistoryAction);
221 tb->addAction(p_nextHistoryAction);
222 tb->addAction(p_resetAction);
225 tb->addAction(p_saveLogAction);
226 tb->addAction(p_clearLogAction);
229 tb->addAction(whatsThisAction);
232 showControls->setText(
"Controls");
233 showControls->setCheckable(
true);
234 connect(showControls, SIGNAL(toggled(
bool)), tb, SLOT(setVisible(
bool)));
236 tb->installEventFilter(
this);
240 addToolBar(Qt::BottomToolBarArea, tb);
241 tb->setIconSize(QSize(22, 22));
242 tb->setAllowedAreas(Qt::BottomToolBarArea);
243 p_commandLineEdit =
new QLineEdit(tb);
244 p_commandLineEdit->setReadOnly(
true);
245 tb->addWidget(p_commandLineEdit);
247 showCommandLine->setText(
"Command Line");
248 showCommandLine->setCheckable(
true);
249 connect(showCommandLine, SIGNAL(toggled(
bool)), tb, SLOT(setVisible(
bool)));
253 QMenu *viewMenu = menuBar()->addMenu(
"&View");
254 viewMenu->addAction(showControls);
255 viewMenu->addAction(showCommandLine);
256 showControls->setChecked(
true);
257 showCommandLine->setChecked(
true);
260 QMenu *helpMenu = menuBar()->addMenu(
"&Help");
261 helpMenu->addAction(whatsThisAction);
264 aboutProgram->setMenuRole(QAction::AboutRole);
265 aboutProgram->setText(
"About this program");
266 aboutProgram->setShortcut(Qt::CTRL + Qt::Key_H);
267 helpMenu->addAction(aboutProgram);
268 connect(aboutProgram, SIGNAL(triggered(
bool)),
this, SLOT(AboutProgram()));
271 aboutIsis->setMenuRole(QAction::NoRole);
272 aboutIsis->setText(
"About Isis");
273 aboutIsis->setShortcut(Qt::CTRL + Qt::Key_I);
274 helpMenu->addAction(aboutIsis);
275 connect(aboutIsis, SIGNAL(triggered(
bool)),
this, SLOT(AboutIsis()));
280 QAction *Gui::CreateProcessAction() {
282 QString baseDir = FileName(
"$BASE/icons").expanded();
283 processAction->setIcon(QPixmap(baseDir +
"/guiRun.png"));
284 processAction->setText(
"&Run");
285 processAction->setToolTip(
"Run");
286 QString processActionWhatsThisText =
"<p><b>Function: </b> \
287 Runs the application with the current parameters</p> \
288 <p><b>Shortcut: </b> Ctrl+R</p>";
289 processAction->setShortcut(Qt::CTRL + Qt::Key_R);
290 processAction->setWhatsThis(processActionWhatsThisText);
292 connect(processAction, SIGNAL(triggered(
bool)),
this, SLOT(
StartProcess()));
294 return processAction;
308 p_processAction->setEnabled(
false);
316 for(
int p = 0; p < (int)p_parameters.size(); p++) {
320 QString value = param.Value().simplified().trimmed();
321 if(value.length() > 0) {
333 Isis::SessionLog::TheLog(
true);
334 QApplication::setOverrideCursor(Qt::WaitCursor);
336 QApplication::restoreOverrideCursor();
340 for(
int p = 0; p < (int)p_parameters.size(); p++) {
349 QApplication::restoreOverrideCursor();
363 p_processAction->setEnabled(
true);
367 QAction *Gui::CreateExitAction() {
369 QString baseDir =
FileName(
"$BASE/icons").expanded();
370 exitAction->setIcon(QPixmap(baseDir +
"/guiExit.png"));
371 exitAction->setText(
"&Exit");
372 exitAction->setToolTip(
"Exit");
373 QString exitWhatsThisText =
"<p><b>Function: </b> \
374 Closes the program window </p> <p><b>Shortcut: </b> Ctrl+Q</p>";
375 exitAction->setWhatsThis(exitWhatsThisText);
376 exitAction->setShortcut(Qt::CTRL + Qt::Key_Q);
377 connect(exitAction, SIGNAL(triggered()), qApp, SLOT(quit()));
382 QAction *Gui::CreateResetAction() {
384 QString baseDir = FileName(
"$BASE/icons").expanded();
385 resetAction->setIcon(QPixmap(baseDir +
"/guiReset.png"));
386 resetAction->setText(
"&Reset");
387 resetAction->setToolTip(
"Reset parameters");
388 QString resetWhatsThisText =
"<p><b>Function: </b> \
389 Resets the application parameters to their default values</p> \
390 <p><b>Shortcut: </b> F3</p>";
391 resetAction->setWhatsThis(resetWhatsThisText);
392 resetAction->setShortcut(Qt::Key_F3);
393 connect(resetAction, SIGNAL(triggered()),
this, SLOT(
ResetParameters()));
399 QAction *Gui::CreateStopAction() {
401 QString baseDir = FileName(
"$BASE/icons").expanded();
402 stopAction->setIcon(QPixmap(baseDir +
"/guiStop.png"));
403 stopAction->setText(
"&Stop");
404 stopAction->setToolTip(
"Stop");
405 QString stopWhatsThisText =
"<p><b>Function: </b> \
406 Stops the application from running</p> \
407 <p><b>Shortcut: </b> Ctrl+E</p>";
408 stopAction->setShortcut(Qt::CTRL + Qt::Key_E);
409 stopAction->setWhatsThis(stopWhatsThisText);
410 connect(stopAction, SIGNAL(triggered()),
this, SLOT(
StopProcessing()));
416 QAction *Gui::CreateSaveLogAction() {
418 QString baseDir = FileName(
"$BASE/icons").expanded();
419 saveLogAction->setIcon(QPixmap(baseDir +
"/guiSaveLog.png"));
420 saveLogAction->setText(
"&Save Log...");
421 saveLogAction->setToolTip(
"Save log");
422 QString saveWhatsThisText =
"<p><b>Function: </b> Saves the information \
423 currently in the log area to a file <p><b>Shortcut: </b> Ctrl+S</p>";
424 saveLogAction->setWhatsThis(saveWhatsThisText);
425 saveLogAction->setShortcut(Qt::CTRL + Qt::Key_S);
426 connect(saveLogAction, SIGNAL(triggered(
bool)), p_log, SLOT(Save()));
428 return saveLogAction;
432 QAction *Gui::CreateClearLogAction() {
434 QString baseDir = FileName(
"$BASE/icons").expanded();
435 clearlogAction->setIcon(QPixmap(baseDir +
"/guiClearLog.png"));
436 clearlogAction->setText(
"&Clear Log");
437 clearlogAction->setToolTip(
"Clear log");
438 QString clearWhatsThisText =
"<p><b>Function: </b>Clears all information \
439 from the log area at the bottom of the application screen</p> \
440 <p><b>Shortcut: </b> Ctrl+L</p>";
441 clearlogAction->setWhatsThis(clearWhatsThisText);
442 clearlogAction->setShortcut(Qt::CTRL + Qt::Key_L);
443 connect(clearlogAction, SIGNAL(triggered(
bool)), p_log, SLOT(Clear()));
445 return clearlogAction;
449 QAction *Gui::CreatePreviousHistoryAction() {
451 QString baseDir = FileName(
"$BASE/icons").expanded();
452 previousHistoryAction->setIcon(QPixmap(baseDir +
"/guiPrevHistory.png"));
453 previousHistoryAction->setText(
"&Previous");
454 previousHistoryAction->setToolTip(
"Previous parameters");
455 QString previousWhatsThisText =
"<p><b>Function: </b>Fills in parameter \
456 values using the previous history entry</p> \
457 <p><b>Shortcut: </b> F5</p>";
458 previousHistoryAction->setWhatsThis(previousWhatsThisText);
459 previousHistoryAction->setShortcut(Qt::Key_F5);
460 connect(previousHistoryAction, SIGNAL(triggered()),
this, SLOT(
PreviousHistory()));
462 return previousHistoryAction;
466 QAction *Gui::CreateNextHistoryAction() {
468 QString baseDir = FileName(
"$BASE/icons").expanded();
469 nextHistoryAction->setIcon(QPixmap(baseDir +
"/guiNextHistory.png"));
470 nextHistoryAction->setText(
"&Next");
471 nextHistoryAction->setToolTip(
"Next parameters");
472 QString nextWhatsThisText =
"<p><b>Function: </b>Fills in parameter \
473 values using the next history entry</p> \
474 <p><b>Shortcut: </b>F6</p>";
475 nextHistoryAction->setWhatsThis(nextWhatsThisText);
476 nextHistoryAction->setShortcut(Qt::Key_F6);
477 connect(nextHistoryAction, SIGNAL(triggered()),
this, SLOT(
NextHistory()));
479 return nextHistoryAction;
483 QAction *Gui::CreateWhatsThisAction() {
485 QString baseDir = FileName(
"$BASE/icons").expanded();
486 action->setIcon(QPixmap(baseDir +
"/contexthelp.png"));
487 action->setText(
"&What's This");
488 action->setToolTip(
"What's This");
489 QString whatsThisText =
"<p><b>Function: </b> Use this to get longer \
490 descriptions of button functions and parameter information</p> \
491 <p><b>Shortcut: </b> Shift+F1</p>";
492 action->setWhatsThis(whatsThisText);
493 action->setShortcut(Qt::SHIFT + Qt::Key_F1);
494 connect(action, SIGNAL(triggered(
bool)),
this, SLOT(WhatsThis()));
502 QGridLayout *gridLayout = NULL;
503 if(!p_grids.contains(ui.
GroupName(group))) {
505 QGroupBox *groupBox =
new QGroupBox(ui.
GroupName(group));
506 p_scrollLayout->addWidget(groupBox);
507 groupBox->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed);
508 groupBox->setAlignment(Qt::AlignHCenter);
511 gridLayout =
new QGridLayout;
512 gridLayout->setColumnStretch(0, 0);
513 gridLayout->setColumnStretch(1, 0);
514 gridLayout->setColumnMinimumWidth(1, 10);
515 gridLayout->setColumnStretch(2, 10);
516 groupBox->setLayout(gridLayout);
517 p_grids[ui.
GroupName(group)] = gridLayout;
521 gridLayout = p_grids[ui.
GroupName(group)];
524 GuiParameter *p = GuiParameterFactory::Create(gridLayout, ui, group, param);
526 if (p->Type() == GuiParameter::ListWidget || p->Type() == GuiParameter::ComboWidget ||
527 p->Type() == GuiParameter::BooleanWidget) {
531 connect(p, SIGNAL(HelperTrigger(
const QString &)),
538 p_statusText->setText(text);
539 qApp->processEvents();
544 p_progressBar->setValue(percent);
545 qApp->processEvents();
560 QString m = QString(message).replace(
"\n",
"<br>");
563 if(message.contains(
"[") &&
564 message.contains(
"]") &&
565 (message.indexOf(
"[") < message.indexOf(
"]"))) {
568 while(m.indexOf(
"[", indx) != -1) {
569 m.insert(m.indexOf(
"[", indx) + 1,
"<font color=#ff0000>");
570 m.insert(m.indexOf(
"]", indx),
"</font>");
571 indx = m.indexOf(
"]", indx) + 1;
580 int status = QMessageBox::warning(
this,
583 "Ok",
"Abort",
"", 0, 1);
584 p_errorString.clear();
595 if(e->type() == QEvent::Enter) {
596 if(p_processAction->isEnabled()) {
606 if(p_processAction->isEnabled())
return;
609 switch(QMessageBox::information(
this,
611 QString(
"Program suspended, choose to ") +
612 QString(
"continue processing, stop ") +
613 QString(
"processing or exit the program"),
634 qApp->processEvents();
642 for(
int p = 0; p < (int)p_parameters.size(); p++) {
648 for(
int p = 0; p < (int)p_parameters.size(); p++) {
675 if(p_historyEntry < -1) {
677 QApplication::beep();
681 if(p_historyEntry == -1) {
693 if(!progHist.fileExists()) {
695 QApplication::beep();
702 hist.
read(progHist.expanded());
706 QString msg =
"A corrupt parameter history file [" + progHist.expanded() +
707 "] has been detected. Please fix or remove this file";
717 for(
int i = 0; i < hist.
groups(); i++) {
722 if(p_historyEntry == entries) {
723 p_historyEntry = entries - 1;
724 QApplication::beep();
728 int useEntry = entries - p_historyEntry - 1;
735 for (
int k = 0; k < up.
keywords(); k++) {
736 QString key = up[k].
name();
740 if (up[k].size() > 1) {
742 for (
int i = 0; i < up[k].size(); i++) {
743 QString newVal = up[k][i];
744 if (newVal.contains(
",")) {
745 newVal =
'"' + newVal +
'"';
747 if (i == up[k].size() - 1) {
751 val += newVal +
", ";
757 QString newVal = up[k];
764 for(
unsigned int p = 0; p < p_parameters.size(); p++) {
771 p_historyEntry = entries - 1;
772 QApplication::beep();
782 for(
unsigned int p = 0; p < p_parameters.size(); p++) {
788 for(
unsigned int p = 0; p < p_parameters.size(); p++) {
790 std::vector<QString> excludeList = param.
Exclusions();
791 for(
int i = 0; i < (int)excludeList.size(); i++) {
792 for(
unsigned int e = 0; e < p_parameters.size(); e++) {
794 if(exclude.
Name() != excludeList[i])
continue;
795 exclude.
SetEnabled(
false, (param.Type()==GuiParameter::ComboWidget));
804 for(
int p = 0; p < (int)p_parameters.size(); p++) {
808 QString name = param.
Name().toLower();
811 QString value = param.Value();
812 if(param.Type() == GuiParameter::StringWidget) {
813 if(value.contains(
" ")) {
814 cline +=
"\"" + value +
"\"";
820 else if(param.Type() == GuiParameter::FileNameWidget ||
821 param.Type() == GuiParameter::CubeWidget) {
825 value = value.toLower();
830 p_commandLineEdit->setText(cline);
835 for(
unsigned int p = 0; p < p_parameters.size(); p++) {
842 void Gui::WhatsThis() {
843 QWhatsThis::enterWhatsThisMode();
847 void Gui::AboutIsis() {
849 QString command = (QString) uig[
"GuiHelpBrowser"] +
850 " http://isis.astrogeology.usgs.gov >> /dev/null &";
855 void Gui::AboutProgram() {
857 "$ISISROOT/doc/Application/presentation/PrinterFriendly/" +
864 QString command = (QString) uig[
"GuiHelpBrowser"] +
865 (QString)
" file:" + file.expanded() +
" &";
871 p_processAction->setEnabled(
false);
876 for(
int p = 0; p < (int)p_parameters.size(); p++) {
880 QString value = param.Value().simplified().trimmed();
881 if(value.length() > 0) {
890 helper = (void ( *)())ptr;
899 p_processAction->setEnabled(
true);
bool eventFilter(QObject *o, QEvent *e)
Reset the Progress bar when the user moves the mouse onto the toolbar.
int NumParams(const int &) const
Returns the number of parameters in a group.
void NextHistory()
Goto the next history entry.
void FunctionCleanup()
Cleans up after the function by writing the log, saving the history, and either sending the log to th...
PvlGroupIterator findGroup(const QString &name, PvlGroupIterator beg, PvlGroupIterator end)
Find a group with the specified name, within these indexes.
void SetEnabled(bool enabled, bool isParentCombo=false)
Enable or disable the parameter.
static UserInterface & GetUserInterface()
Returns the UserInterface object.
File name manipulation and expansion.
void ProgressText(const QString &text)
Change progress text.
void InvokeHelper(const QString &funct)
Activate helper buttons.
void StopProcessing()
The user pressed the stop button ... see what they want to do.
static void checkX11()
check to see if X is available
bool ProcessEvents()
Let the event loop have some time to see if we need to cancel.
int keywords() const
Returns the number of keywords contained in the PvlContainer.
void Write(const QString &string)
Add more information to the log widget.
Gui(Isis::UserInterface &ui)
Constructor.
void UpdateParameters()
Update Parameters.
void PutAsString(const QString ¶mName, const QString &value)
Allows the insertion of a value for any parameter.
void GuiReportError(IException &e)
Loads the error message into the gui, but does not write it to the session log.
void Update()
Update the value on the GUI with the value in the UI.
void Progress(int percent)
Update the progress bar.
static Gui * p_gui
Singleton.
void UpdateCommandLine()
Update the command line toolbar.
void SaveHistory()
Saves the user parameter information in the history of the program for later use. ...
void ResetParameters()
Reset the parameters fields to the defaults.
static void RunSystemCommand(QString commandLine)
This runs arbitrary system commands.
void PreviousHistory()
Goto the previous history entry.
void Log(const QString &text)
Write text to the gui log.
Contains multiple PvlContainers.
void UpdateHistory()
Changed the parameters based on the history pointer.
QString Name() const
Return the name of the parameter.
virtual bool IsModified()
Return if the parameter value is different from the default value.
void Clear(const QString ¶mName)
Clears the value(s) in the named parameter.
Container for cube-like labels.
int FunctionError(IException &e)
Adds the error to the session log, sends the error to the parent if it has one, loads the error messa...
int Exec(void(*funct)())
Start the Gui and enter the main loop This routine only returns when the program is ready to exit...
int groups() const
Returns the number of groups contained.
PvlGroup & group(const int index)
Return the group at the specified index.
QString ProgramName() const
Returns the Program name.
void StartProcess()
The user pressed the go button.
int NumGroups() const
Returns the number of groups found in the XML.
QString toString() const
Returns a string representation of this exception.
void LoadMessage(const QString &message)
Add more information to the error message.
virtual std::vector< QString > Exclusions()
Return list of current exclusions.
void VerifyAll()
Verify all parameters.
Command Line and Xml loader, validation, and access.
int ShowWarning()
Show an error message and return if the user wants to continue/abort.
bool isNamed(const QString &match) const
Returns whether the given string is equal to the container name or not.
void read(const QString &file)
Loads PVL information from a stream.
void UpdateExclusions()
Grey out parameters that should be excluded for radio buttons and checkboxes.
bool hasKeyword(const QString &name) const
Check to see if a keyword exists.
QString name() const
Returns the container name.
QString GroupName(const int &group) const
Returns the group name of group[index].
void * GetGuiHelper(QString helper)
Reads user preferences from a data file.
bool IsEnabled() const
Is the parameter enabled.
Gui for Isis Applications.