7 #include <QtCore/QAbstractEventDispatcher>
8 #include <QtGui/QAction>
9 #include <QtGui/QActionGroup>
10 #include <QtGui/QCloseEvent>
11 #include <QtGui/QColor>
12 #include <QtGui/QColorDialog>
13 #include <QtGui/QComboBox>
14 #include <QtCore/QFileInfo>
15 #include <QtGui/QHBoxLayout>
16 #include <QtGui/QIcon>
17 #include <QtGui/QImage>
18 #include <QtGui/QLabel>
19 #include <QtGui/QPixmap>
20 #include <QtGui/QMenuBar>
21 #include <QtGui/QStackedWidget>
22 #include <QtGui/QStatusBar>
23 #include <QtGui/QToolBar>
24 #include <QtGui/QVBoxLayout>
26 #include <QtCore/QTimer>
69 #include "../UI/icons/photo.xpm"
71 #include "revert_curve.xpm"
72 #include "film_strip.xpm"
74 #include "load_data.xpm"
75 #include <QtGui/QDockWidget>
76 #include "layout_start.xpm"
77 #include "layout_stop.xpm"
79 const char*
const CQNewMainWindow::ZOOM_FACTOR_STRINGS[] = {
"1%",
"2%",
"3%",
"4%",
"5%",
"10%",
"20%",
"25%",
"30%",
"40%",
"50%",
"75%",
"100%",
"150%",
"200%",
"300%",
"400%",
"500%",
"1000%"};
80 const double CQNewMainWindow::ZOOM_FACTORS[] = {0.01, 0.02, 0.03, 0.04, 0.05, 0.1, 0.2, 0.25, 0.3, 0.4, 0.5, 0.75, 1.0, 1.5, 2.0, 3.0, 4.0, 5.0, 10.0};
104 mpLayoutViewer(NULL),
105 mpAnimationWindow(NULL),
106 mpDataModel(pDatamodel),
107 mpCurrentLayout(NULL),
108 mpCurrentRenderInformation(NULL),
109 mDocumentChanged(false),
111 mGraphIcon(QPixmap(graph_xpm)),
112 mAnimationIcon(QPixmap(film_strip_xpm))
113 , mpFogColorPixmap(new QPixmap(32, 32))
114 , mpHighlightColorPixmap(new QPixmap(32, 32))
115 , mpHighlightModeAction(NULL)
116 , mpChangeColorAction(NULL)
117 , mpStopLayoutAction(NULL)
118 , mpRandomizeLayout(NULL)
119 , mpCalculateDimensions(NULL)
120 , mpLayoutThread(NULL)
149 setUnifiedTitleAndToolBarOnMac(
true);
157 this->
mpFogColorPixmap->fill(QColor((
int)(c[0] * 255.0), (
int)(c[1] * 255.0), (
int)(c[2] * 255.0), (
int)(c[3] * 255.0)));
159 this->
mpHighlightColorPixmap->fill(QColor((
int)(c[0] * 255.0), (
int)(c[1] * 255.0), (
int)(c[2] * 255.0), (
int)(c[3] * 255.0)));
164 connect(
mpLayoutThread, SIGNAL(layoutStateChanged(QSharedPointer<CLayoutState>)),
169 addDockWidget(Qt::LeftDockWidgetArea, pParameterWindow);
171 mpViewMenu->addAction(pParameterWindow->toggleViewAction());
187 mpRevertCurveAct =
new QAction(QPixmap(revert_curve_xpm), tr(
"Revert curve"),
this);
188 mpRevertCurveAct->setStatusTip(tr(
"Reverts the currently selected curve."));
192 mpScreenshotAct =
new QAction(QPixmap(photo), tr(
"Export bitmap..."),
this);
200 mpCloseAct->setStatusTip(tr(
"Close Diagram"));
201 connect(
mpCloseAct, SIGNAL(triggered()),
this, SLOT(close()));
203 mpLoadDataAct =
new QAction(QPixmap(load_data_xpm), tr(
"Update Trajectory Data"),
this);
220 mpMimaNodeSizes->setToolTip(
"Change Min/Max for node sizes within animation");
225 mpSFontSize->setToolTip(
"Change the font size of the node labels in the graph view");
283 pAction->setCheckable(
true);
285 pAction->setCheckable(
true);
287 pAction->setCheckable(
true);
289 pAction->setCheckable(
true);
291 pAction->setCheckable(
true);
293 pAction->setCheckable(
true);
295 pAction->setCheckable(
true);
297 pAction->setCheckable(
true);
299 pAction->setCheckable(
true);
301 pAction->setCheckable(
true);
303 pAction->setCheckable(
true);
304 pAction->setChecked(
true);
306 pAction->setCheckable(
true);
308 pAction->setCheckable(
true);
310 pAction->setCheckable(
true);
312 pAction->setCheckable(
true);
314 pAction->setCheckable(
true);
316 pAction->setCheckable(
true);
323 this->
mpHighlightModeAction->setToolTip(tr(
"Toggle whether selected elements are highlighted or unselected items toned down."));
329 this->
mpChangeColorAction->setToolTip(tr(
"When higlighted, sets the highlight color, or the toned down one otherwise."));
331 this->
mpElementaryModesMenu->setToolTip(tr(
"Displays a list of elementary modes when they have been calculated and lets you select one or more that are emphasized in the layout displayed."));
338 QMenu* pM = this->
mpOptionsMenu->addMenu(tr(
"Shape of Label"));
344 menuBar()->addSeparator();
363 QFrame* pFrame1 =
new QFrame;
364 QHBoxLayout* pLayout =
new QHBoxLayout;
365 pLayout->setSpacing(3);
366 QLabel* pLabel =
new QLabel(tr(
"Layout:"));
367 pLayout->addWidget(pLabel);
369 this->
mpLayoutDropdown->setSizeAdjustPolicy(QComboBox::AdjustToContentsOnFirstShow);
370 pFrame1->setLayout(pLayout);
373 QFrame* pFrame2 =
new QFrame;
374 pLayout =
new QHBoxLayout;
375 pLayout->setSpacing(3);
376 pFrame2->setLayout(pLayout);
380 this->
mpRenderDropdown->setSizeAdjustPolicy(QComboBox::AdjustToContentsOnFirstShow);
383 QFrame* pFrame3 =
new QFrame;
384 pLayout =
new QHBoxLayout;
385 pLayout->setSpacing(3);
386 pFrame3->setLayout(pLayout);
387 pLabel =
new QLabel(tr(
"Zoom Factor:"));
388 pLayout->addWidget(pLabel);
393 int defaultIndex = -1;
395 for (i = 0; i < iMax; ++i)
397 this->
mpZoomDropdown->addItem(QString(CQNewMainWindow::ZOOM_FACTOR_STRINGS[i]));
399 if (std::string(CQNewMainWindow::ZOOM_FACTOR_STRINGS[i]) == std::string(
"100%"))
405 this->
mpZoomDropdown->setSizeAdjustPolicy(QComboBox::AdjustToContentsOnFirstShow);
408 assert(defaultIndex != -1);
421 statusBar()->showMessage(tr(
"Ready"));
452 int defaultIndex = -1;
454 for (i = 0; i < iMax; ++i)
456 if (std::string(CQNewMainWindow::ZOOM_FACTOR_STRINGS[i]) == std::string(
"100%"))
463 assert(defaultIndex != -1);
500 QList<QAction*>::iterator it = actions.begin(), endit = actions.end();
504 if ((*it)->isChecked())
506 (*it)->setChecked(
false);
517 QString s = QString(
"%1").arg(zoom * 100);
560 size_t Index = (size_t) index;
565 if (Index >= numLocalRenderInfo)
568 if (Index >= numFileRenderInfo)
622 for (i = num; i > 0; --i)
625 std::string text = pTmpRenderInfo->
getKey();
627 if (!pTmpRenderInfo->
getName().empty())
629 text = pTmpRenderInfo->
getName();
647 for (i = 0; i < iMax; ++i)
661 for (i = 0; i < iMax; ++i)
728 for (i = 0; i < iMax; ++i)
731 std::string text = pTmpRenderInfo->
getKey();
733 if (!pTmpRenderInfo->
getName().empty())
735 text = pTmpRenderInfo->
getName();
755 for (i = 0; i < iMax; ++i)
758 std::string text = pTmpRenderInfo->
getKey();
760 if (!pTmpRenderInfo->
getName().empty())
762 text = pTmpRenderInfo->
getName();
868 if (pPainter == NULL)
871 #ifndef USE_SCREENSHOT_OPTIONS
875 if (!fileName.isEmpty())
880 double layoutX = pPainter->
minX();
881 double layoutY = pPainter->
minY();
882 double layoutWidth = pPainter->
maxX() - layoutX;
883 double layoutHeight = pPainter->
maxY() - layoutY;
890 x, y, width, height, pPainter->width() , pPainter->height(), -1,
this);
892 if (pDialog->exec() == QDialog::Accepted)
898 if (!fileName.isEmpty())
912 if (pPainter == NULL)
915 double layoutX = pPainter->
minX();
916 double layoutY = pPainter->
minY();
917 double layoutWidth = pPainter->
maxX() - layoutX;
918 double layoutHeight = pPainter->
maxY() - layoutY;
920 export_bitmap(filename, layoutX, layoutY, layoutWidth, layoutHeight, layoutWidth * scale, layoutHeight * scale,
false);
927 void CQNewMainWindow::export_bitmap(
const QString& filename,
double x,
double y,
double width,
double height,
unsigned int imageWidth,
unsigned int imageHeight,
bool drawSelection)
930 double size = imageWidth * imageHeight * 4;
939 tr(
"Sorry, refusing to create images that are larger than 500MB."));
945 QFileInfo info(filename);
953 tr(
"Path exists, but it is not a file."));
958 if (!info.isWritable())
962 tr(
"Can't write to file."));
971 if (pPainter == NULL)
974 GLubyte* pImageData = pPainter->
export_bitmap(x, y, width, height, imageWidth, imageHeight, drawSelection);
976 if (pImageData == NULL)
980 QImage* pImage =
new QImage(pImageData, imageWidth, imageHeight, 4 * imageWidth, QImage::Format_ARGB32);
981 bool result = pImage->save(filename,
"PNG");
986 tr(
"An error occured while saving the file.\nThe file might be invalid."));
999 const CLayout* pTmpLayout = NULL;
1002 for (i = 0; i < iMax; ++i)
1005 std::string text = pTmpLayout->
getKey();
1039 switch (this->
mMode)
1107 this->
mpPlayMenu->menuAction()->setVisible(
true);
1114 this->
mpPlayMenu->menuAction()->setVisible(
false);
1121 this->statusBar()->showMessage(message, timeout);
1129 bool fluxModesChanged =
false;
1134 assert(pTaskList != NULL);
1136 if (pTaskList != NULL)
1145 if (pProblem != NULL && !pProblem->
getFluxModes().empty())
1147 const std::vector< CFluxMode >& fluxModes = pProblem->
getFluxModes();
1148 size_t iMax = fluxModes.size();
1152 fluxModesChanged =
true;
1158 while (i < iMax && fluxModesChanged ==
false)
1162 fluxModesChanged =
true;
1169 if (fluxModesChanged)
1174 if (fluxModes.empty())
1186 pFluxMode = &(fluxModes[i]);
1190 pAction->setCheckable(
true);
1211 if (pPainter == NULL)
return;
1219 if (pAction->isChecked())
1227 assert(pTaskList != NULL);
1229 if (pTaskList != NULL)
1240 while (it != endit && pProblem != NULL)
1246 if (pProblem != NULL)
1248 pReaction = pProblem->getReorderedReactions()[it->first];
1249 assert(pReaction != NULL);
1262 QList<QAction*>::const_iterator ait = actions.begin(), aendit = actions.end();
1272 while (ait != aendit)
1274 if ((*ait)->isChecked())
1276 i = actions.indexOf(*ait);
1288 assert(pReaction != NULL);
1319 if (pReaction != NULL && selectionMask != 0 && this->
mpCurrentLayout != NULL)
1332 if ((*it)->getModelObject() == pReaction)
1347 while (it2 != endit2)
1350 switch ((*it2)->getRole())
1357 key = (*it2)->getMetabGlyphKey();
1362 s.insert(static_cast<const CLMetabGlyph*>(pObject));
1373 key = (*it2)->getMetabGlyphKey();
1378 s.insert(static_cast<const CLMetabGlyph*>(pObject));
1389 key = (*it2)->getMetabGlyphKey();
1394 s.insert(static_cast<const CLMetabGlyph*>(pObject));
1405 key = (*it2)->getMetabGlyphKey();
1410 s.insert(static_cast<const CLMetabGlyph*>(pObject));
1421 key = (*it2)->getMetabGlyphKey();
1426 s.insert(static_cast<const CLMetabGlyph*>(pObject));
1437 key = (*it2)->getMetabGlyphKey();
1442 s.insert(static_cast<const CLMetabGlyph*>(pObject));
1453 key = (*it2)->getMetabGlyphKey();
1458 s.insert(static_cast<const CLMetabGlyph*>(pObject));
1469 key = (*it2)->getMetabGlyphKey();
1474 s.insert(static_cast<const CLMetabGlyph*>(pObject));
1508 if ((*it)->getModelObject() == pMetab)
1555 QDialog* pDialog =
new QDialog;
1556 pDialog->setLayout(
new QVBoxLayout(pDialog));
1557 pDialog->layout()->addWidget(
new QLabel(
"Set the fog density:", pDialog));
1558 QDoubleSpinBox* pSpinBox =
new QDoubleSpinBox(pDialog);
1559 pSpinBox->setRange(0.0, 1.0);
1560 pSpinBox->setSingleStep(0.01);
1561 pSpinBox->setValue(c);
1562 pDialog->layout()->addWidget(pSpinBox);
1563 QDialogButtonBox* pBBox =
new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, pDialog);
1564 pDialog->layout()->addWidget(pBBox);
1566 connect(pBBox, SIGNAL(accepted()), pDialog, SLOT(accept()));
1567 connect(pBBox, SIGNAL(rejected()), pDialog, SLOT(reject()));
1569 if (pDialog->exec() == QDialog::Accepted)
1571 c = pSpinBox->value();
1592 const GLfloat* c = NULL;
1604 QColorDialog* pDialog =
new QColorDialog(QColor((
int)(c[0] * 255.0), (
int)(c[1] * 255.0), (
int)(c[2] * 255.0), (
int)(c[3] * 255.0)),
this);
1606 if (pDialog->exec() == QDialog::Accepted)
1610 QColor color = pDialog->selectedColor();
1611 GLfloat newColor[4] = {
static_cast<GLfloat
>(color.red()) / 255.0f, static_cast<GLfloat>(color.green()) / 255.0f, static_cast<GLfloat>(color.blue()) / 255.0f, static_cast<GLfloat>(color.alpha()) / 255.0f};
1640 #ifdef INCLUDE_UNUSED_CODE
1646 CLMetabGlyph* CQNewMainWindow::createMetabGlyph(
const std::string& modelobjectkey,
double width,
double height)
1657 CLCompartmentGlyph* CQNewMainWindow::createCompartmentGlyph(
const std::string& modelobjectkey,
double x,
double y,
double width,
double height)
1669 CLReactionGlyph* CQNewMainWindow::createReactionGlyph(
const std::string& modelobjectkey,
double x,
double y,
double length)
1682 CLTextGlyph* CQNewMainWindow::createTextGlyph(
const std::string& modelobjectkey,
const std::string& objectkey,
double width,
double height)
1705 #endif //INCLUDE_UNUSED_CODE
1778 QRectF
getBounds(
const std::vector<CCopasiSpringLayout::UpdateAction>& updates)
1780 QRectF result(1000, 1000, -1000, -1000);
1781 std::vector<CCopasiSpringLayout::UpdateAction>::const_iterator it, itEnd = updates.end();
1783 for (it = updates.begin(); it != itEnd; ++it)
1785 switch (it->mAction)
1790 result.setLeft(qMin(result.left(), current->
getX()));
1791 result.setTop(qMin(result.top(), current->
getY()));
1792 result.setRight(qMax(result.right(), current->
getX() + current->
getWidth()));
1793 result.setBottom(qMax(result.bottom(), current->
getY() + current->
getHeight()));
1800 result.setLeft(qMin(result.left(), current->
getX()));
1801 result.setTop(qMin(result.top(), current->
getY()));
1802 result.setRight(qMax(result.right(), current->
getX() + current->
getWidth()));
1803 result.setBottom(qMax(result.bottom(), current->
getY() + current->
getHeight()));
1810 result.setLeft(qMin(result.left(), current->
getX()));
1811 result.setTop(qMin(result.top(), current->
getY()));
1812 result.setRight(qMax(result.right(), current->
getX() + current->
getWidth()));
1813 result.setBottom(qMax(result.bottom(), current->
getY() + current->
getHeight()));
1857 this->QMainWindow::closeEvent(event);
void export_bitmap(const QString &filename, double scale=4.0)
QAction * mpChangeColorAction
void setStatusMessage(const QString &message, int timeout)
double getCurrentHeight() const
void createSpringLayout(CLayout *layout, int numIntervals=1000, int updateWait=100)
QPixmap * mpFogColorPixmap
CQPlayerControlWidget * getControlWidget()
static void tagLayout(CLayout *layout)
double getCurrentPositionY() const
QAction * mpRevertCurveAct
void removeFromMainWindow(CopasiUI3Window *window=NULL)
void slotLayoutChanged(int index)
const GLfloat * getHighlightColor() const
bool isSetDrawSelectionDecoration() const
std::set< std::string > mHighlightedMetabolites
void fogDensitySlot(bool)
QComboBox * mpRenderDropdown
void elementaryModeTriggeredSlot(QAction *pAction)
CQGLLayoutPainter * getPainter()
CQNewMainWindow(CCopasiDataModel *pDatamodel)
void update(const CCopasiDataModel *pDataModel, CLayout *pLayout, const CLRenderInformationBase *pRenderInfo, const QString &baseDir)
CCopasiProblem * getProblem()
void slotRunSpringLayout()
std::string getFluxModeDescription(const CFluxMode &fluxMode) const
GLfloat getFogDensity() const
const std::string & getObjectName() const
QAction * mpStopLayoutAction
void slotLayoutStateChanged(QSharedPointer< CLayoutState > state)
QAction * mpRectangularShape
const CCopasiVector< CLLocalRenderInformation > & getListOfLocalRenderInformationObjects() const
CLayout * mpCurrentLayout
virtual size_t size() const
CQLayoutThread * mpLayoutThread
const std::set< const CLGraphicalObject * > & getHighlightedObjects() const
void setZoomFactor(double zoom)
CCopasiObject * get(const std::string &key)
QAction * mpScreenshotAct
virtual const std::string & getKey() const
void setMode(DISPLAY_MODE mode=GRAPH_MODE)
const C_FLOAT64 & getX() const
void selectMetabolite(const CMetab *pMetab, std::set< const CLGraphicalObject * > &s)
void setDimensions(const CLDimensions &d)
void setZoomFactor(QString s)
std::vector< const CFluxMode * > mFluxModes
void slotRunRandomizeLayout()
void setHighlightColor(const GLfloat c[4])
void selectReaction(const CReaction *pReaction, unsigned int selectionMask, std::set< const CLGraphicalObject * > &s)
void calculateAndAssignBounds(CLayout *pLayout)
double getCurrentPositionX() const
void setAnimationToolbar()
CCopasiVector< CLGlobalRenderInformation > * DEFAULT_STYLES
const CLLocalRenderInformation * getRenderInformation(size_t index) const
unsigned int getImageWidth() const
QActionGroup * mpZoomActionGroup
QAction * mpLoopItemAction
const CCopasiVector< CLCompartmentGlyph > & getListOfCompartmentGlyphs() const
void setFogDensity(GLfloat dens)
QComboBox * mpZoomDropdown
double getCurrentWidth() const
CCopasiDataModel * mpDataModel
CLRenderInformationBase * mpCurrentRenderInformation
virtual void closeEvent(QCloseEvent *event)
CLGlobalRenderInformation * getDefaultStyle(size_t index)
void setModelObjectKey(const std::string &k)
virtual ~CQNewMainWindow()
void change_style(bool defaultStyle=false)
const std::string & getReferenceDirectory() const
CCopasiVector< CLGlobalRenderInformation > * loadDefaultStyles()
QPixmap * mpHighlightColorPixmap
QAction * mpCircularShape
const std::vector< CFluxMode > & getFluxModes() const
QToolBar * mpSelectionToolBar
QRectF getBounds(const std::vector< CCopasiSpringLayout::UpdateAction > &updates)
QComboBox * mpLayoutDropdown
size_t getNumDefaultStyles()
void slotSingleCurveSelected(bool selected)
CQLayoutMainWindow * mpAnimationWindow
virtual const std::string & getKey() const
std::set< REACTION_SELECTION_ITEM > mHighlightedReactions
void changeColorSlot(bool)
unsigned int mSelectionMask
virtual QMenu * getWindowMenu() const
static const QIcon & icon(const IconID &id)
CCopasiVectorN< CCopasiTask > * getTaskList()
void slotZoomChanged(int index)
void slotLayoutFinished()
const CCopasiVector< CLMetabGlyph > & getListOfMetaboliteGlyphs() const
const_iterator begin() const
void createSpringLayout(int numIterations, int updateInterval)
unsigned int getImageHeight() const
void addCurveSegment(const CLLineSegment &ls)
void setGraphicalObjectKey(const std::string &k)
void setFogColor(const GLfloat c[4])
void addGlobalRenderInfoItemsToList()
GLubyte * export_bitmap(double x, double y, double width, double height, unsigned int imageWidth, unsigned int imageHeight, bool drawSelection)
CListOfLayouts * getListOfLayouts()
virtual const std::string & getKey() const
void updateRenderInformationList()
void setPosition(const CLPoint &p)
QAction * mpHighlightModeAction
void setLayout(CLayout *pLayout)
const C_FLOAT64 & getWidth() const
void toggleHighlightSlot(bool checked)
void randomizeLayout(CLayout *layout)
void slotCalculateDimensions()
const C_FLOAT64 & getY() const
const GLfloat * getFogColor() const
void addDefaultRenderInfoItemsToList()
static CKeyFactory * getKeyFactory()
QMenu * mpElementaryModesMenu
static StandardButton critical(QWidget *parent, const QString &title, const QString &text, StandardButtons buttons=Ok, StandardButton defaultButton=NoButton)
CLGlobalRenderInformation * getRenderInformation(size_t index)
QAction * mpRandomizeLayout
QDockWidget * getParameterWindow()
QAction * mpFogDensityAction
std::map< size_t, C_FLOAT64 >::const_iterator const_iterator
QAction * mpCalculateDimensions
void change_style(const CLRenderInformationBase *pRenderInfo, bool defaultStyle=false)
CCopasiVectorNS< CReaction > & getReactions()
void setHighlightFlag(bool flag)
void slotZoomMenuItemActivated(QAction *)
QAction * mpMimaNodeSizes
CQGLLayoutViewer * mpLayoutViewer
void checkForElementaryModesSlot()
QStackedWidget * mpWidgetStack
static const double ZOOM_FACTORS[]
const C_FLOAT64 & getHeight() const
const CLCurve & getCurve() const
void slotRenderInfoChanged(int index)
const CCopasiVector< CLReactionGlyph > & getListOfReactionGlyphs() const
static const char *const ZOOM_FACTOR_STRINGS[]
QAction * mpSwitchModeAct
const_iterator end() const
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)
const CCopasiVector< CLGlobalRenderInformation > & getListOfGlobalRenderInformationObjects() const