BALL  1.4.79
 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 
53 
54 using namespace std;
55 //#define BALL_VIEW_DEBUG
56 
57 namespace BALL
58 {
59  using namespace std;
60  using namespace BALL::VIEW;
61 
62  Mainframe::Mainframe(QWidget* parent, const char* name)
63  : MainControl(parent, name, ".BALLView"),
64  scene_(0)
65  {
66  #ifdef BALL_VIEW_DEBUG
67  Log.error() << "new Mainframe " << this << std::endl;
68  #endif
69 
70  // ---------------------
71  // setup main window
72  // ---------------------
73  setWindowTitle(tr("BALLView"));
74  setWindowIcon(QPixmap(bucky_64x64_xpm));
75  // make sure submenus are the first
82  #ifdef BALL_PYTHON_SUPPORT
85  #endif
88 
89  // ---------------------
90  // Logstream setup -----
91  // ---------------------
92 // Log.remove(std::cout);
93 // Log.remove(std::cerr);
94  setLoggingFilename("BALLView.log");
95 
96  // Display Menu
97  String description = "Shortcut|Display|Toggle_Fullscreen";
98  fullscreen_action_ = insertMenuEntry(MainControl::DISPLAY, (String)tr("Toggle Fullscreen"), this,
99  SLOT(toggleFullScreen()), description, QKeySequence("Alt+X"),
101 
102  if (fullscreen_action_)
103  fullscreen_action_->setIcon(IconLoader::instance().getIcon("actions/view-fullscreen"));
104 
107 
108  new MolecularFileDialog (this, "MolecularFileDialog");
109  new DownloadPDBFile (this, "DownloadPDBFile", false);
110  new DownloadElectronDensity(this, "DownloadElectronDensity", false);
111  new PubChemDialog (this, "PubChemDialog");
112  new UndoManagerDialog (this, "UndoManagerDialog");
113 
114  addDockWidget(Qt::LeftDockWidgetArea, new MolecularControl(this, ((String)tr("Structures")).c_str()));
115  addDockWidget(Qt::LeftDockWidgetArea, new GeometricControl(this, ((String)tr("Representations")).c_str()));
116  addDockWidget(Qt::TopDockWidgetArea, new DatasetControl(this, ((String)tr("Datasets")).c_str()));
117  DatasetControl* dc = DatasetControl::getInstance(0);
122 
123 // NOTE: raytraceable grids have been deferred until 1.4/2.0
124 // dc->registerController(new RaytraceableGridController());
125 
126  DatasetControl::getInstance(0)->hide();
127 
128  // For Demo, Tutorial, and RayTracing
129  new DemoTutorialDialog(this, ((String)tr("BALLViewDemo")).c_str());
130 
131  Path path;
132 
133  addDockWidget(Qt::BottomDockWidgetArea, new HelpViewer(this, "BALLView Docu"));
134  new LabelDialog( this, ((String)tr("LabelDialog")).c_str());
135  new MolecularStructure( this, ((String)tr("MolecularStructure")).c_str());
136  addDockWidget(Qt::BottomDockWidgetArea, new LogView( this, ((String)tr("Logs")).c_str()));
137  addDockWidget(Qt::BottomDockWidgetArea, new FileObserver( this, ((String)tr("FileObserver")).c_str()));
138 
141  scene_ = new Scene(this, ((String)tr("3D View")).c_str());
142  setCentralWidget(scene_);
143  setAcceptDrops(true);
144 
145  new DisplayProperties(this, ((String)tr("DisplayProperties")).c_str());
146 
147  // setup the VIEW server
148  #ifdef BALL_HAS_ASIO
149  ServerWidget* server = new ServerWidget(this);
150  // registering object generator
151  MoleculeObjectCreator* object_creator = new MoleculeObjectCreator;
152  server->registerObjectCreator(*object_creator);
153  #endif
154 
155  #ifdef BALL_PYTHON_SUPPORT
156  new TestFramework(this, ((String)"Test Framework").c_str());
157  addDockWidget(Qt::BottomDockWidgetArea, new PyWidget(this, ((String)tr("Python Interpreter")).c_str()));
158  #endif
159 
160  // ---------------------
161  // Menus ---------------
162  // ---------------------
163 
164  description = "Shortcut|File|Open|Project";
165  insertMenuEntry(MainControl::FILE_OPEN, ((String)tr("Project")).c_str(), this,
166  SLOT(loadBALLViewProjectFile()), description, QKeySequence(),
168 
169  description = "Shortcut|File|Save_Project";
170  save_project_action_ = insertMenuEntry(MainControl::FILE, ((String)tr("Save Project")).c_str(), this,
171  SLOT(saveBALLViewProjectFile()), description, QKeySequence(),
173 
174  // Help-Menu -------------------------------------------------------------------
175  QAction* action = 0;
176 
177  description = "Shortcut|Help|About";
178  action = insertMenuEntry(MainControl::HELP, (String)tr("About"), this, SLOT(about()), description);
179  if (action)
180  setMenuHint(action, (String)tr("Show informations on this version of BALLView"));
181 
182  description = "Shortcut|Help|How_to_cite";
183  action = insertMenuEntry(MainControl::HELP, (String)tr("How to cite"), this, SLOT(howToCite()), description,
184  QKeySequence(), UIOperationMode::MODE_ADVANCED);
185  if (action)
186  setMenuHint(action, (String)tr("Show infos on how to cite BALL and BALLView"));
187 
188  // TODO: why is this done here and not, e.g., in mainControl()???
189  description = "Shortcut|MolecularMechanics|Abort_Calculation";
191  SLOT(stopSimulation()), description, QKeySequence("Alt+C"),
194  {
195  stop_simulation_action_->setEnabled(false);
196  setMenuHint(stop_simulation_action_, (String)tr("Abort a running simulation"));
198 
199  stop_simulation_action_->setIcon(IconLoader::instance().getIcon("actions/process-stop"));
200  }
201 
202 
203  description = "Shortcut|Edit|Invert_Selection";
204  complement_selection_action_ = insertMenuEntry(MainControl::EDIT, (String)tr("Invert Selection"), this,
205  SLOT(complementSelection()), description, QKeySequence(),
207 
208  description = "Shortcut|Edit|Clear_Selection";
209  clear_selection_action_ = insertMenuEntry(MainControl::EDIT, (String)tr("Clear Selection"), this,
210  SLOT(clearSelection()), description, QKeySequence(),
212 
213 
214  qApp->installEventFilter(this);
215 
216  setStatusbarText((String)tr("Ready."));
217  }
218 
220  {
221  }
222 
223 
224  bool Mainframe::eventFilter(QObject* sender, QEvent* event)
225  {
226  if (event->type() != QEvent::KeyPress) return false;
227 
228  QKeyEvent* e = dynamic_cast<QKeyEvent*>(event);
229 
230  if (e->key() == Qt::Key_Escape &&
231  HelpViewer::getInstance("BALLView Docu")->isWhatsThisEnabled())
232  {
233  HelpViewer::getInstance("BALLView Docu")->exitWhatsThisMode();
234  }
235 
236  QPoint point = QCursor::pos();
237  QWidget* widget = qApp->widgetAt(point);
238  if (widget == scene_ &&
239  qApp->focusWidget() != scene_)
240  {
241  scene_->keyPressEvent(e);
242  return true;
243  }
244 
245  if (e->key() == Qt::Key_Delete &&
246  RTTI::isKindOf<QTreeWidget>(*sender))
247  {
248  deleteClicked();
249  return true;
250  }
251 
252  if (e->key() == Qt::Key_Enter)
253  {
254  if (composite_manager_.getNumberOfComposites() == 0) return false;
255 
256  if (getMolecularControlSelection().size() == 0)
257  {
259  }
260 
261  MolecularStructure::getInstance(0)->centerCamera();
262  return true;
263  }
264 
265  // check all menu entries if Alt or CTRL is pressed to enable shortcuts
266  if (e->key() == Qt::Key_Alt ||
267  e->key() == Qt::Key_Control)
268  {
269  checkMenus();
270  return false;
271  }
272 
273  #ifdef BALL_PYTHON_SUPPORT
274  PyWidget::getInstance(0)->reactTo(*e);
275  e->accept();
276  #endif
277 
278  return false;
279  }
280 
281 
283  {
284  if (composites_locked_ || getRepresentationManager().updateRunning()) return;
285 
286  clearData();
287 
288  DisplayProperties* dp = DisplayProperties::getInstance(0);
293  dp->setTransparency(0);
295  }
296 
297 
299  {
300  HelpViewer::getInstance("BALLView Docu")->showHelp("tips.html", (String)tr("cite"));
301  }
302 
304  {
305  // prevent multiple inserting of menu entries, by calls of showFullScreen(), ...
306  if (preferences_action_ != 0)
307  {
309  return;
310  }
311 
312  QToolBar* tb = NULL;
314  {
315  tb = new QToolBar("Main Toolbar", this);
316  tb->setObjectName("Main Toolbar");
317  tb->setIconSize(QSize(22,22));
318  addToolBar(Qt::TopToolBarArea, tb);
319  }
320 
322 
324 
325  if (menu)
326  {
327  menu->addSeparator();
328  menu->addAction(tb->toggleViewAction());
329  }
330 
331  // NOTE: this *has* to be run... a null pointer is unproblematic
333  {
334  MolecularFileDialog::getInstance(0)->addToolBarEntries(tb);
335  DownloadPDBFile::getInstance(0)->addToolBarEntries(tb);
336  DownloadElectronDensity::getInstance(0)->addToolBarEntries(tb);
337  PubChemDialog::getInstance(0)->addToolBarEntries(tb);
338  UndoManagerDialog::getInstance(0)->addToolBarEntries(tb);
339  tb->addAction(fullscreen_action_);
340 
341  Path path;
342 
343  IconLoader& loader = IconLoader::instance();
344  qload_action_ = new QAction(loader.getIcon("actions/quickopen-file"), tr("quickload"), this);
345  qload_action_->setObjectName("quickload");
346  connect(qload_action_, SIGNAL(triggered()), this, SLOT(quickLoadConfirm()));
347  HelpViewer::getInstance("BALLView Docu")->registerForHelpSystem(qload_action_, "tips.html#quickload");
348  tb->addAction(qload_action_);
349 
350  qsave_action_ = new QAction(loader.getIcon("actions/quicksave"), tr("quicksave"), this);
351  qsave_action_->setObjectName("quicksave");
352  connect(qsave_action_, SIGNAL(triggered()), this, SLOT(quickSave()));
353  HelpViewer::getInstance("BALLView Docu")->registerForHelpSystem(qsave_action_, "tips.html#quickload");
354  tb->addAction(qsave_action_);
355 
356  tb->addSeparator();
357  DisplayProperties::getInstance(0)->addToolBarEntries(tb);
358  MolecularStructure::getInstance(0)->addToolBarEntries(tb);
359  }
360 
363  {
364 
365  tb->addAction(stop_simulation_action_);
366  tb->addAction(preferences_action_);
367  HelpViewer::getInstance("BALLView Docu")->addToolBarEntries(tb);
368  }
369  // we have changed the child widgets stored in the maincontrol (e.g. toolbars), so we have
370  // to restore the window state again!
371  restoreWindows();
372  }
373 
375  {
376  // Display about dialog
377  QDialog w;
378  Ui_AboutDialog about;
379  about.setupUi(&w);
380  QString version = QString(tr("QT ")) + qVersion();
381 #ifdef BALL_QT_HAS_THREADS
382  version += "(mt)";
383 #endif
384  about.qt_version_label->setText(version);
385  QFont font = about.BALLView_version_label->font();
386  about.BALLView_version_label->setText(QString("BALLView ") + BALL_RELEASE_STRING);
387  font.setPixelSize(18);
388  about.BALLView_version_label->setFont(font);
389  about.BALL_version_label->setText(__DATE__);
390 
391  // find the BALLView log
392  Path p;
393  String logo_path = p.find("graphics/logo.png");
394 
395  if (logo_path != "")
396  about.BALLView_logo_label->setPixmap(QPixmap(logo_path.c_str()));
397 
398  w.exec();
399  }
400 
402  {
403  if(evt->type() == QEvent::WindowStateChange) {
404  if (isFullScreen())
405  {
406  if (fullscreen_action_ != 0)
407  {
408  fullscreen_action_->setIcon(IconLoader::instance().getIcon("actions/view-restore"));
409  }
410  }
411  else
412  {
413  if (fullscreen_action_ != 0)
414  {
415  fullscreen_action_->setIcon(IconLoader::instance().getIcon("actions/view-fullscreen"));
416  }
417  }
418  }
419  }
420 
422  {
424 
425  boost::shared_ptr<InputDevPluginHandler> input_dev_handler(new InputDevPluginHandler());
426  man.registerHandler(input_dev_handler);
427 
429  man.registerHandler(new PluginDialog(getPreferences(), this));
430  }
431 }
CompositeManager composite_manager_
Definition: mainControl.h:910
RepresentationManager & getRepresentationManager()
Definition: mainControl.h:255
QAction * preferences_action_
Definition: mainControl.h:956
void insertPopupMenuSeparator(int ID, UIOperationMode::OperationMode mode=UIOperationMode::MODE_ALL)
Preferences * getPreferences()
void setupPluginHandlers_()
Definition: mainframe.C:421
bool eventFilter(QObject *, QEvent *e)
Catch key events.
Definition: mainframe.C:224
void stopSimulation()
Stop a currently running calculation.
void setSurfaceDrawingPrecision(float value)
std::list< Composite * > & getMolecularControlSelection()
Get the selection (highlighted items) of the MolecularControl (not the selection with checkboxes) ...
void howToCite()
Definition: mainframe.C:298
QAction * fullscreen_action_
Definition: mainControl.h:951
QAction * clear_selection_action_
Definition: mainControl.h:953
void setDrawingPrecision(int value)
virtual void deleteClicked()
void registerObjectCreator(const ObjectCreator &s)
static PluginManager & instance()
QAction * stop_simulation_action_
Definition: mainControl.h:950
BALL_EXPORT LogStream Log
void setMenuHint(QAction *id, const String &hint)
Set a hint for a menu entry.
void setStatusbarText(const String &text, bool important=false, bool beep=false)
static bool stereoBufferSupportTest()
const QIcon & getIcon(const String &name)
void setLoggingFilename(const String &string)
QAction * insertMenuEntry(Position parent_id, const String &name, const QObject *receiver=0, const char *slot=0, const String &description="", QKeySequence accel=QKeySequence(), UIOperationMode::OperationMode minimal_mode=UIOperationMode::MODE_ALL)
QAction * complement_selection_action_
Definition: mainControl.h:952
Macros e.g. for Testing.
Definition: mainControl.h:203
const char * c_str() const BALL_NOEXCEPT
Scene * scene_
Definition: mainframe.h:59
defines the property for the model: Stick
static UIOperationMode & instance()
virtual void restoreWindows()
Restore the positions the main window and of all DockWindow's from the INIFile assigned to this insta...
String find(const String &name)
virtual bool registerController(DatasetController *con)
virtual ~Mainframe()
Definition: mainframe.C:219
LogStream & error(int n=0)
virtual void addToolBarEntries(QToolBar *tb)
virtual void keyPressEvent(QKeyEvent *e)
Catch key events.
File menu sub menu open.
Definition: mainControl.h:142
void reset()
remove all loaded Molecules and Representations, reset Coloring options
Definition: mainframe.C:282
virtual bool event(QEvent *e)
Interface to QT events, e.g. to communicate with other threads.
virtual void checkMenus()
Userdefined menus.
Definition: mainControl.h:200
static IconLoader & instance()
void selectColoringMethod(int index)
void quickSave()
Create a BALLView project file with the name quick.bvp in the users home dir.
void registerHandler(PluginHandler *h)
std::list< Composite * > control_selection_
Definition: mainControl.h:902
virtual QMenu * initPopupMenu(int ID, UIOperationMode::OperationMode mode=UIOperationMode::MODE_ALL)
const char * bucky_64x64_xpm[]
Definition: icons.C:9
QAction * save_project_action_
Definition: mainControl.h:955
void setTransparency(int value)
void changeEvent(QEvent *evt)
Definition: mainframe.C:401
Python submenu in Tools.
Definition: mainControl.h:194