BALL  1.4.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
mainframe.C
Go to the documentation of this file.
1 // -*- Mode: C++; tab-width: 2; -*-
2 // vi: set ts=2:
3 //
4 
5 #include "mainframe.h"
6 #include "icons.h"
7 #include "demoTutorialDialog.h"
8 
28 #ifdef BALL_PYTHON_SUPPORT
31 #endif
32 
33 #include <BALL/SYSTEM/path.h>
34 #include <BALL/KERNEL/forEach.h>
35 #include <BALL/COMMON/version.h>
36 
37 #include <QtGui/QKeyEvent>
38 #include <QtGui/QTreeWidget>
39 
41 #ifdef BALL_HAS_ASIO
43 #endif
44 
45 #include "ui_aboutDialog.h"
46 
48 
49 using namespace std;
50 //#define BALL_VIEW_DEBUG
51 
52 namespace BALL
53 {
54  using namespace std;
55  using namespace BALL::VIEW;
56 
57  Mainframe::Mainframe(QWidget* parent, const char* name)
58  : MainControl(parent, name, ".BALLView"),
59  scene_(0)
60  {
61  #ifdef BALL_VIEW_DEBUG
62  Log.error() << "new Mainframe " << this << std::endl;
63  #endif
64 
65  // ---------------------
66  // setup main window
67  // ---------------------
68  setWindowTitle(tr("BALLView"));
69  setWindowIcon(QPixmap(bucky_64x64_xpm));
70  // make sure submenus are the first
77  #ifdef BALL_PYTHON_SUPPORT
80  #endif
83 
84  // ---------------------
85  // Logstream setup -----
86  // ---------------------
87 // Log.remove(std::cout);
88 // Log.remove(std::cerr);
89  setLoggingFilename("BALLView.log");
90 
91  // Display Menu
92  String description = "Shortcut|Display|Toggle_Fullscreen";
93  fullscreen_action_ = insertMenuEntry(MainControl::DISPLAY, (String)tr("Toggle Fullscreen"), this,
94  SLOT(toggleFullScreen()), description,
95  QKeySequence("Alt+X"));
96 
97  fullscreen_action_->setIcon(IconLoader::instance().getIcon("actions/view-fullscreen"));
98 
101 
102  new MolecularFileDialog(this, ((String)tr("MolecularFileDialog")).c_str());
103  new DownloadPDBFile( this, ((String)tr("DownloadPDBFile")).c_str(), false);
104  new DownloadElectronDensity(this, ((String)tr("DownloadElectronDensity")).c_str(), false);
105  new PubChemDialog( this, ((String)tr("PubChemDialog")).c_str());
106  new PluginDialog( this, ((String)tr("PluginDialog")).c_str());
107  new UndoManagerDialog( this, ((String)tr("UndoManagerDialog")).c_str());
108 
109  addDockWidget(Qt::LeftDockWidgetArea, new MolecularControl(this, ((String)tr("Structures")).c_str()));
110  addDockWidget(Qt::LeftDockWidgetArea, new GeometricControl(this, ((String)tr("Representations")).c_str()));
111  addDockWidget(Qt::TopDockWidgetArea, new DatasetControl(this, ((String)tr("Datasets")).c_str()));
112  DatasetControl* dc = DatasetControl::getInstance(0);
117 
118 // NOTE: raytraceable grids have been deferred until 1.4/2.0
119 // dc->registerController(new RaytraceableGridController());
120 
121  DatasetControl::getInstance(0)->hide();
122 
123  new DemoTutorialDialog(this, ((String)tr("BALLViewDemo")).c_str());
124 
125  Path path;
126 
127  // NOTE: disable the link to the BALL documentation until we can use webkit to correctly
128  // display full HTML including remote links
129  String dirp = path.find("../doc/BALL/");
130 
131  if (dirp != "")
132  {
133  HelpViewer* BALL_docu = new HelpViewer(this, ((String)tr("BALL Docu")).c_str());
134  addDockWidget(Qt::BottomDockWidgetArea, BALL_docu);
135 
136  BALL_docu->setBaseDirectory(dirp);
137  BALL_docu->setWhatsThisEnabled(false);
138  BALL_docu->setProject("BALL");
139  BALL_docu->setDefaultPage("index.html");
140 
141  }
142  else
143  {
144  Log.error() << "Please build the BALL documentation!" << std::endl;
145  }
146 
147  addDockWidget(Qt::BottomDockWidgetArea, new HelpViewer(this, "BALLView Docu"));
148  new LabelDialog( this, ((String)tr("LabelDialog")).c_str());
149  new MolecularStructure( this, ((String)tr("MolecularStructure")).c_str());
150  addDockWidget(Qt::BottomDockWidgetArea, new LogView( this, ((String)tr("Logs")).c_str()));
151  addDockWidget(Qt::BottomDockWidgetArea, new FileObserver( this, ((String)tr("FileObserver")).c_str()));
152 
154  scene_ = new EditableScene(this, ((String)tr("3D View")).c_str());
155  setCentralWidget(scene_);
156  setAcceptDrops(true);
157 
158  new DisplayProperties(this, ((String)tr("DisplayProperties")).c_str());
159 
160  // setup the VIEW server
161  #ifdef BALL_HAS_ASIO
162  ServerWidget* server = new ServerWidget(this);
163  // registering object generator
164  MoleculeObjectCreator* object_creator = new MoleculeObjectCreator;
165  server->registerObjectCreator(*object_creator);
166  #endif
167 
168  #ifdef BALL_PYTHON_SUPPORT
169  new TestFramework(this, ((String)"Test Framework").c_str());
170  addDockWidget(Qt::BottomDockWidgetArea, new PyWidget(this, ((String)tr("Python Interpreter")).c_str()));
171  #endif
172 
173  // ---------------------
174  // Menus ---------------
175  // ---------------------
176 
177  description = "Shortcut|File|Open|Project";
178  insertMenuEntry(MainControl::FILE_OPEN, ((String)tr("Project")).c_str(), this,
179  SLOT(loadBALLViewProjectFile()), description);
180 
181  description = "Shortcut|File|Save_Project";
182  save_project_action_ = insertMenuEntry(MainControl::FILE, ((String)tr("Save Project")).c_str(), this,
183  SLOT(saveBALLViewProjectFile()), description);
184 
185  // Help-Menu -------------------------------------------------------------------
186  QAction* action = 0;
187 
188  description = "Shortcut|Help|About";
189  action = insertMenuEntry(MainControl::HELP, (String)tr("About"), this, SLOT(about()), description);
190  setMenuHint(action, (String)tr("Show informations on this version of BALLView"));
191 
192  description = "Shortcut|Help|How_to_cite";
193  action = insertMenuEntry(MainControl::HELP, (String)tr("How to cite"), this, SLOT(howToCite()), description);
194  setMenuHint(action, (String)tr("Show infos on how to cite BALL and BALLView"));
195 
196  // TODO: why is this done here and not, e.g., in mainControl()???
197  description = "Shortcut|MolecularMechanics|Abort_Calculation";
199  SLOT(stopSimulation()), description,
200  QKeySequence("Alt+C"));
201 
202  stop_simulation_action_->setEnabled(false);
204  setMenuHint(stop_simulation_action_, (String)tr("Abort a running simulation"));
205 
206  stop_simulation_action_->setIcon(IconLoader::instance().getIcon("actions/process-stop"));
207 
208  description = "Shortcut|Edit|Invert_Selection";
209  complement_selection_action_ = insertMenuEntry(MainControl::EDIT, (String)tr("Invert Selection"), this,
210  SLOT(complementSelection()), description);
211 
212  description = "Shortcut|Edit|Clear_Selection";
213  clear_selection_action_ = insertMenuEntry(MainControl::EDIT, (String)tr("Clear Selection"), this,
214  SLOT(clearSelection()), description);
215 
216 
217  qApp->installEventFilter(this);
218 
219  setStatusbarText((String)tr("Ready."));
220  }
221 
223  {
224  }
225 
226 
227  bool Mainframe::eventFilter(QObject* sender, QEvent* event)
228  {
229  if (event->type() != QEvent::KeyPress) return false;
230 
231  QKeyEvent* e = dynamic_cast<QKeyEvent*>(event);
232 
233  if (e->key() == Qt::Key_Escape &&
234  HelpViewer::getInstance("BALLView Docu")->isWhatsThisEnabled())
235  {
236  HelpViewer::getInstance("BALLView Docu")->exitWhatsThisMode();
237  }
238 
239  QPoint point = QCursor::pos();
240  QWidget* widget = qApp->widgetAt(point);
241  if (widget == scene_ &&
242  qApp->focusWidget() != scene_)
243  {
244  scene_->keyPressEvent(e);
245  return true;
246  }
247 
248  if (e->key() == Qt::Key_Delete &&
249  RTTI::isKindOf<QTreeWidget>(*sender))
250  {
251  deleteClicked();
252  return true;
253  }
254 
255  if (e->key() == Qt::Key_Enter)
256  {
257  if (composite_manager_.getNumberOfComposites() == 0) return false;
258 
259  if (getMolecularControlSelection().size() == 0)
260  {
262  }
263 
264  MolecularStructure::getInstance(0)->centerCamera();
265  return true;
266  }
267 
268  // check all menu entries if Alt or CTRL is pressed to enable shortcuts
269  if (e->key() == Qt::Key_Alt ||
270  e->key() == Qt::Key_Control)
271  {
272  checkMenus();
273  return false;
274  }
275 
276  #ifdef BALL_PYTHON_SUPPORT
277  PyWidget::getInstance(0)->reactTo(*e);
278  e->accept();
279  #endif
280 
281  return false;
282  }
283 
284 
286  {
287  if (composites_locked_ || getRepresentationManager().updateRunning()) return;
288 
289  clearData();
290 
291  DisplayProperties* dp = DisplayProperties::getInstance(0);
296  dp->setTransparency(0);
298  }
299 
300 
302  {
303  HelpViewer::getInstance("BALLView Docu")->showHelp("tips.html", (String)tr("cite"));
304  }
305 
307  {
308  // prevent multiple inserting of menu entries, by calls of showFullScreen(), ...
309  if (preferences_action_ != 0)
310  {
312  return;
313  }
314 
315 
316  QToolBar* tb = new QToolBar("Main Toolbar", this);
317  tb->setObjectName("Main Toolbar");
318  tb->setIconSize(QSize(22,22));
319  addToolBar(Qt::TopToolBarArea, tb);
320 
322 
323  initPopupMenu(MainControl::WINDOWS)->addSeparator();
324  initPopupMenu(MainControl::WINDOWS)->addAction(tb->toggleViewAction());
325  MolecularFileDialog::getInstance(0)->addToolBarEntries(tb);
326  DownloadPDBFile::getInstance(0)->addToolBarEntries(tb);
327  DownloadElectronDensity::getInstance(0)->addToolBarEntries(tb);
328  PubChemDialog::getInstance(0)->addToolBarEntries(tb);
329  UndoManagerDialog::getInstance(0)->addToolBarEntries(tb);
330  tb->addAction(fullscreen_action_);
331  Path path;
332 
333  IconLoader& loader = IconLoader::instance();
334  qload_action_ = new QAction(loader.getIcon("actions/quickopen-file"), tr("quickload"), this);
335  qload_action_->setObjectName("quickload");
336  connect(qload_action_, SIGNAL(triggered()), this, SLOT(quickLoadConfirm()));
337  HelpViewer::getInstance("BALLView Docu")->registerForHelpSystem(qload_action_, "tips.html#quickload");
338  tb->addAction(qload_action_);
339 
340  qsave_action_ = new QAction(loader.getIcon("actions/quicksave"), tr("quicksave"), this);
341  qsave_action_->setObjectName("quicksave");
342  connect(qsave_action_, SIGNAL(triggered()), this, SLOT(quickSave()));
343  HelpViewer::getInstance("BALLView Docu")->registerForHelpSystem(qsave_action_, "tips.html#quickload");
344  tb->addAction(qsave_action_);
345 
346  tb->addSeparator();
347  DisplayProperties::getInstance(0)->addToolBarEntries(tb);
348  MolecularStructure::getInstance(0)->addToolBarEntries(tb);
350  tb->addAction(stop_simulation_action_);
351  tb->addAction(preferences_action_);
352  HelpViewer::getInstance("BALLView Docu")->addToolBarEntries(tb);
353 
354  // we have changed the child widgets stored in the maincontrol (e.g. toolbars), so we have
355  // to restore the window state again!
356  restoreWindows();
357  }
358 
360  {
361  // Display about dialog
362  QDialog w;
363  Ui_AboutDialog about;
364  about.setupUi(&w);
365  QString version = QString(tr("QT ")) + qVersion();
366 #ifdef BALL_QT_HAS_THREADS
367  version += "(mt)";
368 #endif
369  about.qt_version_label->setText(version);
370  QFont font = about.BALLView_version_label->font();
371  about.BALLView_version_label->setText(QString("BALLView ") + BALL_RELEASE_STRING);
372  font.setPixelSize(18);
373  about.BALLView_version_label->setFont(font);
374  about.BALL_version_label->setText(__DATE__);
375 
376  // find the BALLView log
377  Path p;
378  String logo_path = p.find("graphics/logo.png");
379 
380  if (logo_path != "")
381  about.BALLView_logo_label->setPixmap(QPixmap(logo_path.c_str()));
382 
383  w.exec();
384  }
385 
387  {
388  if(evt->type() == QEvent::WindowStateChange) {
389  if (isFullScreen())
390  {
391  fullscreen_action_->setIcon(IconLoader::instance().getIcon("actions/view-restore"));
392  } else {
393  fullscreen_action_->setIcon(IconLoader::instance().getIcon("actions/view-fullscreen"));
394  }
395  }
396  }
397 
398 }