COPASI API  4.16.103
CQCopasiApplication.cpp
Go to the documentation of this file.
1 // Copyright (C) 2012 - 2013 by Pedro Mendes, Virginia Tech Intellectual
2 // Properties, Inc., University of Heidelberg, and The University
3 // of Manchester.
4 // All rights reserved.
5 
6 #include <QtGui/QFileOpenEvent>
7 #include <QtCore/QString>
8 
9 #include "CQCopasiApplication.h"
10 #include "copasiui3window.h"
11 #include "listviews.h"
13 
14 #ifdef WIN32
15 
16 #include <QtGui/QWindowsVistaStyle>
17 
18 bool IsWindows8()
19 {
20 
21  OSVERSIONINFOEX osvi = {0};
22  DWORDLONG mask = 0;
23 
24  osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
25  osvi.dwMajorVersion = 6;
26  osvi.dwMinorVersion = 2;
27 
28  VER_SET_CONDITION(mask, VER_MAJORVERSION, VER_GREATER_EQUAL);
29  VER_SET_CONDITION(mask, VER_MINORVERSION, VER_GREATER_EQUAL);
30 
31  return VerifyVersionInfo(&osvi,
32  VER_MAJORVERSION | VER_MINORVERSION,
33  mask
34  );
35 }
36 
37 #endif
38 
39 CQCopasiApplication::CQCopasiApplication(int & argc, char ** argv):
40  QApplication(argc, argv),
41  mpMainWindow(NULL),
42  mFile(),
43  mStarting(true)
44 {
45 #if WIN32
46 
47  if (IsWindows8())
48  setStyle(new QWindowsVistaStyle);
49 
50 #endif
51 
52 // Alter styles using Qt's CSS-like mechanism
53  QString globalStyleSheet =
54  "QLineEdit[readOnly=\"true\"] {\n" // When readOnly
55  " color: gray;\n" // make text gray and
56  " border: false;\n" // remove box border.
57  "}\n"; //can add future items after this (move semicolon down)
58 
59  qApp->setStyleSheet(globalStyleSheet);
60 }
61 
63 {
64 }
65 
66 // virtual
67 bool CQCopasiApplication::event(QEvent * pEvent)
68 {
69  switch (pEvent->type())
70  {
71  case QEvent::FileOpen:
72 
73  if (mStarting)
74  {
75  mFile = static_cast<QFileOpenEvent *>(pEvent)->file();
76  }
77  else
78  {
79  // need to take the new file, otherwise whenever the application
80  // is open we will re-open the first file that was supposed to be
81  // opened.
82  mFile = static_cast<QFileOpenEvent *>(pEvent)->file();
84  }
85 
86  pEvent->accept();
87  return true;
88 
89  break;
90 
91  default:
92  break;
93  }
94 
95  return QApplication::event(pEvent);
96 }
97 
99 {
100  mpMainWindow = pMainWindow;
101 
102  processEvents();
103 
105  mStarting = false;
106 }
107 
108 #ifdef COPASI_DEBUG
109 bool CQCopasiApplication::notify(QObject * pObject, QEvent * pEvent)
110 {
111  bool success = false;
112 
113  try
114  {
115  success = QApplication::notify(pObject, pEvent);
116  }
117 
118  catch (CCopasiException & e)
119  {
120  std::cout << "Unhandled Exception: " << e.getMessage().getText() << std::endl;
121  }
122 
123  catch (...)
124  {
125  std::cout << "Unhandled Exception: Unknown Source" << std::endl;
126  }
127 
128  return success;
129 }
130 #endif
void slotFileOpen(QString file=QString::null)
const std::string & getText() const
const CCopasiMessage & getMessage() const
void openInitialDocument(const QString &file)
void setMainWindow(CopasiUI3Window *pMainWindow)
virtual bool event(QEvent *pEvent)
CQCopasiApplication(int &argc, char **argv)
CopasiUI3Window * mpMainWindow