Isis 3 Programmer Reference
WarningWidget.cpp
1 #include "WarningWidget.h"
2 #include "IString.h"
3 #include "FileName.h"
4 
5 #include <QIcon>
6 #include <QPixmap>
7 #include <QGridLayout>
8 #include <QPushButton>
9 #include <QFont>
10 
11 namespace Isis {
20  WarningWidget::WarningWidget(QStatusBar *pParent): QObject(pParent) {
21  mSBar = pParent;
22 
23  QString sToolIconDir = FileName("$base/icons").expanded();
24  QString qsIconFile(sToolIconDir);
25 
26  // default Action - No warning
27  mNoWarning = new QPushButton(mSBar);
28  mNoWarning->setFixedSize(22, 22) ;
29  mNoWarning->setFlat(true);
30  mNoWarning->setIconSize(QSize(15, 15));
31  mNoWarning->setIcon(QPixmap(qsIconFile + "/qview_NoWarning.png"));
32  mNoWarning->setToolTip("No Warning");
33  mNoWarning->setVisible(true);
34  // Add Nowarning object to the layout of the active tool bar of the Tool
35  mSBar->insertPermanentWidget(0, mNoWarning);
36 
37  mSBar->showMessage("Ready");
38  mMsgStr = QString("Ready");
39 
40  // Warning is not set
41  mbWarningFlag = false;
42 
43  // Dialog box displayed when the Warning Icon is clicked
44  mDialog = new QDialog(mSBar);
45  mDialog->setWindowTitle("Warning");
46  mDialog->setSizeGripEnabled(true);
47  mWindow = new QWidget(mDialog);
48  mWindow->installEventFilter(this);//receive events directed to this object
49 
50  mTextEdit = new QTextEdit(mDialog);
51  mTextEdit->setReadOnly(true);
52  QFont font("Helvetica", 11);
53  mTextEdit->setFont(font);
54 
55  // OK button for the dialog window
56  QPushButton *okButton = new QPushButton("Ok", mDialog);
57  okButton->setShortcut(Qt::Key_Enter);
58  connect(okButton, SIGNAL(clicked()), this, SLOT(resetWarning())); //when clicked close dialog and display Nowarning icon
59 
60  QGridLayout *layout = new QGridLayout();
61  layout->addWidget(mTextEdit, 0, 0, 1, 3);
62  layout->addWidget(okButton, 1, 1, 1, 1);
63  mDialog->setLayout(layout);
64 
65  // Warning object
66  mWarning = new QPushButton(mSBar);
67  mWarning->setFixedSize(22, 22) ;
68  mWarning->setFlat(false);
69  mWarning->setIconSize(QSize(15, 15));
70  mWarning->setIcon(QPixmap(qsIconFile + "/qview_Warning.png"));
71  mWarning->setToolTip("Warning");
72  mWarning->setVisible(false);
73  mSBar->insertPermanentWidget(0, mWarning);
74 
75  connect(mWarning, SIGNAL(clicked()), mDialog, SLOT(show())); // display the dialog window when this button is clicked
76  mDialog->resize(800, 250);
77  mTextEdit->setBaseSize(750, 200) ;
78  }
79 
88 
89  }
90 
99  void WarningWidget::setWarningText(std::string pStr) {
100  int findChar1 = pStr.find('[', 0);
101  std::string redStr = pStr.substr(0, findChar1 + 1);
102  redStr += "<font color=#ff0000>";
103  int findChar2 = pStr.find(']', 0);
104  redStr += pStr.substr(findChar1 + 1, findChar2 - findChar1 - 1);
105  redStr += "</font>";
106  redStr += pStr.substr(findChar2, pStr.length() - findChar2);
107  mSBar->showMessage(QString(redStr.c_str()));
108  mTextEdit->setText(QString(redStr.c_str()));
109  }
110 
119  if(mbWarningFlag == true) {
120  mWarning->setVisible(false);
121  mNoWarning->setVisible(true);
122  mDialog->setVisible(false);
123  mbWarningFlag = false;
124  mSBar->showMessage("Ready");
125  mMsgStr = "Ready";
126  }
127  }
128 
135  if(mbWarningFlag == true && mMsgStr.length()) {
136  if(mSBar->currentMessage() != mMsgStr)
137  mSBar->showMessage(mMsgStr);
138  }
139  }
149  void WarningWidget::viewWarningWidgetIcon(std:: string &pStr, const std::string &pExStr) {
150  mbWarningFlag = true;
151  mWarning->setVisible(true);
152  mNoWarning->setVisible(false);
153  std::string sStr = "**PROGRAMMER ERROR** " + pStr;
154  mMsgStr = sStr.c_str();
155  setWarningText(sStr + "<br>" + pExStr);
156  }
157 }
void resetWarning(void)
When the dialog "OK" button is clicked or when the mouse is released on some other area or tool the W...
File name manipulation and expansion.
Definition: FileName.h:116
void viewWarningWidgetIcon(std::string &pStr, const std::string &pExStr)
View Warning icon when there is an exception.
void checkMessage(void)
Verify that the right message is displayed in the status bar.
WarningWidget(QStatusBar *pParent)
Warning widget constructor, initializes and creates the Nowarning, Warning objects and objects associ...
void setWarningText(std::string pStr)
Set the message for the status bar and the dialog window.
~WarningWidget()
Destructor for the Warning widget.
QString expanded() const
Returns a QString of the full file name including the file path, excluding the attributes.
Definition: FileName.cpp:212
Namespace for ISIS/Bullet specific routines.
Definition: Apollo.h:31