COPASI API  4.16.103
Public Slots | Signals | Public Member Functions | Protected Slots | Protected Member Functions | Private Slots | Private Member Functions | Private Attributes | List of all members
CQExpressionMmlStackedWidget Class Reference

#include <CQExpressionMmlStackedWidget.h>

Inheritance diagram for CQExpressionMmlStackedWidget:
Inheritance graph
[legend]
Collaboration diagram for CQExpressionMmlStackedWidget:
Collaboration graph
[legend]

Public Slots

void updateWidget ()
 

Signals

void signalCheckValidity (bool)
 

Public Member Functions

 CQExpressionMmlStackedWidget (QWidget *parent=0)
 
QString getText ()
 
void setReadOnly (const bool &readOnly)
 
 ~CQExpressionMmlStackedWidget ()
 

Protected Slots

void slotGoExpressionWidget ()
 
void slotGoMmlWidget ()
 

Protected Member Functions

void init ()
 

Private Slots

void slotSaveExpression ()
 

Private Member Functions

void saveMML (const QString filename)
 
void savePNG (const QString filename)
 
void saveTeX (const QString filename)
 

Private Attributes

QString MMLStr
 

Detailed Description

Definition at line 18 of file CQExpressionMmlStackedWidget.h.

Constructor & Destructor Documentation

CQExpressionMmlStackedWidget::CQExpressionMmlStackedWidget ( QWidget *  parent = 0)

Definition at line 42 of file CQExpressionMmlStackedWidget.cpp.

References CQIconResource::copasi, CQIconResource::edit, CQIconResource::fileExport, CQIconResource::icon(), init(), and CQIconResource::renderMathML.

43  : QStackedWidget(parent)
44 {
45  setupUi(this);
46 
47  mpBtnExpressionObject->setIcon(CQIconResource::icon(CQIconResource::copasi));
48  mpBtnViewExpression->setIcon(CQIconResource::icon(CQIconResource::renderMathML));
49  mpBtnEditExpression->setIcon(CQIconResource::icon(CQIconResource::edit));
50  mpBtnSaveExpression->setIcon(CQIconResource::icon(CQIconResource::fileExport));
51 
52  mpMmlScrollView->setStyleSheet(QString(mpMmlScrollView->widget()->metaObject()->className()) + "{background-color:" + QColor(Qt::white).name() + ";}");
53 
54 #ifdef WIN32
55  // on windows there ought to be a border around the MML widget
56  // otherwise it is difficult to distinguish the formula from the rest of the
57  // dialog
58  mpMmlScrollView->setFrameShape(QFrame::Panel);
59  mpMmlScrollView->setFrameStyle(QFrame::Panel | QFrame::Plain);
60 #endif
61 
62  init();
63 }
static const QIcon & icon(const IconID &id)
CQExpressionMmlStackedWidget::~CQExpressionMmlStackedWidget ( )

Definition at line 68 of file CQExpressionMmlStackedWidget.cpp.

69 {
70  // no need to delete child widgets, Qt does it all for us
71 }

Member Function Documentation

QString CQExpressionMmlStackedWidget::getText ( )

Definition at line 147 of file CQExpressionMmlStackedWidget.cpp.

148 {
149  return mpExpressionWidget->toPlainText();
150 }
void CQExpressionMmlStackedWidget::init ( )
protected

Definition at line 152 of file CQExpressionMmlStackedWidget.cpp.

Referenced by CQExpressionMmlStackedWidget().

153 {
154 #ifdef DEBUG_UI
155  qDebug() << "L" << __LINE__ << " on CQEMSW mpExpressionWidget->text() = " << mpExpressionWidget->text();
156  qDebug() << "L" << __LINE__ << " on CQEMSW: activeWidget = " << currentIndex();
157 #endif
158 
159 #ifndef HAVE_MML
160  mpBtnViewExpression->hide();
161 #endif // not HAVE_MML
162 }
void CQExpressionMmlStackedWidget::saveMML ( const QString  filename)
private

Definition at line 222 of file CQExpressionMmlStackedWidget.cpp.

References CLocaleString::fromUtf8(), and TO_UTF8.

Referenced by slotSaveExpression().

223 {
224  std::ofstream ofile;
225  ofile.open(CLocaleString::fromUtf8(TO_UTF8(outfilename)).c_str(), std::ios::trunc);
226 
227  ofile << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" << std::endl;
228  ofile << "<!DOCTYPE math PUBLIC \"-//W3C//DTD MathML 2.0//EN\" \"http://www.w3.org/Math/DTD/mathml2/mathml2.dtd\">" << std::endl;
229  ofile << "<math xmlns=\"http://www.w3.org/1998/Math/MathML\">" << std::endl;
230 
231  mpExpressionWidget->writeMathML(ofile);
232 
233  ofile << "</math>" << std::endl;
234 
235  ofile.close();
236 }
#define TO_UTF8(__x)
Definition: qtUtilities.h:74
static CLocaleString fromUtf8(const std::string &utf8)
void CQExpressionMmlStackedWidget::savePNG ( const QString  filename)
private

Definition at line 202 of file CQExpressionMmlStackedWidget.cpp.

References FROM_UTF8.

Referenced by slotSaveExpression().

203 {
204  std::ostringstream mml;
205  mpExpressionWidget->writeMathML(mml);
206  QtMmlDocument doc;
207  doc.setBaseFontPointSize(20);
208  doc.setFontName(QtMmlWidget::NormalFont, qApp->font().family());
209  doc.setContent(FROM_UTF8(mml.str()));
210 
211  const QSize &size = doc.size();
212  QPixmap pixmap(size.width(), size.height());
213  QPainter painter(&pixmap);
214  painter.setRenderHint(QPainter::Antialiasing);
215  painter.setRenderHint(QPainter::SmoothPixmapTransform);
216  painter.setRenderHint(QPainter::HighQualityAntialiasing);
217  painter.fillRect(0, 0, size.width(), size.height(), Qt::white);
218  doc.paint(&painter, QPoint(0, 0));
219  pixmap.save(outfilename, "PNG");
220 }
#define FROM_UTF8(__x)
Definition: qtUtilities.h:73
void CQExpressionMmlStackedWidget::saveTeX ( const QString  filename)
private

Definition at line 238 of file CQExpressionMmlStackedWidget.cpp.

References CMathMLToTeX::convert(), FROM_UTF8, CLocaleString::fromUtf8(), and TO_UTF8.

Referenced by slotSaveExpression().

239 {
240  std::ostringstream mml;
241  mpExpressionWidget->writeMathML(mml);
242 
243  QString latexStr(FROM_UTF8(mml.str()));
244 
245  CMathMLToTeX::convert(latexStr);
246 
247  std::ofstream ofile;
248  ofile.open(CLocaleString::fromUtf8(TO_UTF8(outfilename)).c_str(), std::ios::trunc);
249 
250  ofile << TO_UTF8(latexStr);
251 
252  ofile.close();
253 }
#define FROM_UTF8(__x)
Definition: qtUtilities.h:73
static void convert(QString &text)
convert to TeX
#define TO_UTF8(__x)
Definition: qtUtilities.h:74
static CLocaleString fromUtf8(const std::string &utf8)
void CQExpressionMmlStackedWidget::setReadOnly ( const bool &  readOnly)

Definition at line 139 of file CQExpressionMmlStackedWidget.cpp.

140 {
141  if (readOnly)
142  mpBtnEditExpression->hide();
143  else
144  mpBtnEditExpression->show();
145 }
void CQExpressionMmlStackedWidget::signalCheckValidity ( bool  )
signal
void CQExpressionMmlStackedWidget::slotGoExpressionWidget ( )
protectedslot

Definition at line 73 of file CQExpressionMmlStackedWidget.cpp.

74 {
75 #ifdef DEBUG_UI
76  qDebug() << "- here on CQExpressionMmlStackedWidget::slotGoExpressionWidget() -";
77  qDebug() << "L" << __LINE__ << " on CQEMSW mpExpressionWidget->text() = " << mpExpressionWidget->text();
78 #endif
79 
80  setCurrentWidget(mpExpressionPage);
81 
82 #ifdef DEBUG_UI
83  qDebug() << "L" << __LINE__ << " on CQEMSW mpExpressionWidget->text() = " << mpExpressionWidget->text();
84  qDebug() << "L" << __LINE__ << " on CQEMSW: activeWidget NEW = " << currentIndex();
85 #endif
86 }
void CQExpressionMmlStackedWidget::slotGoMmlWidget ( )
protectedslot

Definition at line 88 of file CQExpressionMmlStackedWidget.cpp.

89 {
90 #ifdef DEBUG_UI
91  qDebug() << "L" << __LINE__ << " on CQEMSW mpExpressionWidget->text() = " << mpExpressionWidget->text();
92 #endif
93 
94  setCurrentWidget(mpMmlPage);
95 
96 #ifdef DEBUG_UI
97  qDebug() << "L" << __LINE__ << " on CQEMSW mpExpressionWidget->text() = " << mpExpressionWidget->text();
98  qDebug() << "L" << __LINE__ << " on CQEMSW: activeWidget NEW = " << currentIndex();
99 #endif
100 }
void CQExpressionMmlStackedWidget::slotSaveExpression ( )
privateslot

Definition at line 164 of file CQExpressionMmlStackedWidget.cpp.

References C_INT32, checkSelection(), CopasiFileDialog::getSaveFileName(), saveMML(), savePNG(), and saveTeX().

165 {
166  QString *filter = new QString;
167  QString outfilename;
168 
169  C_INT32 Answer = QMessageBox::No;
170 
171  while (Answer == QMessageBox::No)
172  {
173  outfilename =
175  "Save File Dialog",
176  "untitled.mml",
177  "MathML (*.mml);;TeX (*.tex);;PNG (*.png)",
178 // "Save Expression to Disk", new QString);
179  "Save Expression to Disk", filter);
180 
181  if (outfilename.isEmpty()) return;
182 
183  // Checks whether the file exists
184  Answer = checkSelection(outfilename);
185 
186  if (Answer == QMessageBox::Cancel)
187  return;
188  }
189 
190 #ifdef DEBUG_UI
191  qDebug() << "\non CQEMSW::slotSaveExpression -> filter = " << *filter << "\n";
192 #endif
193 
194  if (filter->contains(".tex"))
195  saveTeX(outfilename);
196  else if (filter->contains(".png"))
197  savePNG(outfilename);
198  else
199  saveMML(outfilename);
200 }
#define C_INT32
Definition: copasi.h:90
C_INT32 checkSelection(const QString &file)
static QString getSaveFileName(QWidget *parent=0, const char *name=0, const QString &startWith=QString::null, const QString &filter=QString::null, const QString &caption=QString::null, QString *pSelectedFilter=NULL, QFileDialog::Options options=0)
void CQExpressionMmlStackedWidget::updateWidget ( )
slot

Definition at line 102 of file CQExpressionMmlStackedWidget.cpp.

References FROM_UTF8.

103 {
104 #ifdef DEBUG_UI
105  qDebug() << "- here on CQExpressionMmlStackedWidget::updateWidget() -";
106 #endif
107 
108 #ifdef HAVE_MML
109 
110  std::ostringstream mml;
111  std::vector<std::vector<std::string> > params;
112 
113 #ifdef DEBUG_UI
114  qDebug() << "L" << __LINE__ << " on CQEMSW mpExpressionWidget->text() = " << mpExpressionWidget->text();
115  qDebug() << "L" << __LINE__ << " on CQEMSW: activeWidget NEW = " << currentIndex();
116 #endif
117 
118  if (mpExpressionWidget->toPlainText().isEmpty() || !mpExpressionWidget->isValid())
119  setCurrentWidget(mpExpressionPage);
120  else
121  {
122  mpExpressionWidget->writeMathML(mml);
123 
124 #ifdef DEBUG_UI
125  qDebug() << "mml.str() = " << FROM_UTF8(mml.str());
126 #endif
127 
128  setCurrentWidget(mpMmlPage);
129  mpMmlScrollView->updateWidget(mml);
130  }
131 
132 #endif /* HAVE_MML */
133 
134 #ifdef DEBUG_UI
135  qDebug() << "L" << __LINE__ << " on CQEMSW: activeWidget = " << currentIndex();
136 #endif
137 }
#define FROM_UTF8(__x)
Definition: qtUtilities.h:73

Member Data Documentation

QString CQExpressionMmlStackedWidget::MMLStr
private

Definition at line 45 of file CQExpressionMmlStackedWidget.h.


The documentation for this class was generated from the following files: