BALL  1.5.0
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 
24 #ifdef BALL_PYTHON_SUPPORT
27 #endif
28 
29 #include <BALL/SYSTEM/path.h>
30 #include <BALL/KERNEL/forEach.h>
31 
33 
34 #include "ui_aboutDialog.h"
35 
42 
43 using namespace std;
44 //#define BALL_VIEW_DEBUG
45 
46 namespace BALL
47 {
48  using namespace std;
49  using namespace BALL::VIEW;
50 
51  Mainframe::Mainframe(QWidget* parent, const char* name)
52  : MainControl(parent, name, ".BALLView"),
53  scene_(0),
54  save_project_action_(0),
55  qload_action_(0),
56  qsave_action_(0)
57  {
58  // Fixes a major problem with Qt WebEngine 5.5 when being used in a DockWidget
59  qApp->setAttribute(Qt::AA_DontCreateNativeWidgetSiblings);
60 
61  registerThis();
62 
63  #ifdef BALL_VIEW_DEBUG
64  Log.error() << "new Mainframe " << this << std::endl;
65  #endif
66 
67  // ---------------------
68  // setup main window
69  // ---------------------
70  setWindowTitle(tr("BALLView"));
71  setWindowIcon(QPixmap(bucky_64x64_xpm));
72  // make sure submenus are the first
79  #ifdef BALL_PYTHON_SUPPORT
82  #endif
85 
86  // ---------------------
87  // Logstream setup -----
88  // ---------------------
89 // Log.remove(std::cout);
90 // Log.remove(std::cerr);
91  setLoggingFilename("BALLView.log");
92 
93  // Display Menu
94  String description = "Shortcut|Display|Toggle_Fullscreen";
95  fullscreen_action_ = insertMenuEntry(MainControl::DISPLAY, (String)tr("Toggle Fullscreen"), this,
96  SLOT(toggleFullScreen()), description, QKeySequence("Alt+X"),
98 
100  fullscreen_action_->setIcon(IconLoader::instance().getIcon("actions/view-fullscreen"));
101 
104 
105  new MolecularFileDialog (this, "MolecularFileDialog");
106  new DownloadPDBFile (this, "DownloadPDBFile", false);
107  new DownloadElectronDensity(this, "DownloadElectronDensity", false);
108  new PubChemDialog (this, "PubChemDialog");
109  new UndoManagerDialog (this, "UndoManagerDialog");
110 
111  addDockWidget(Qt::LeftDockWidgetArea, new MolecularControl(this, ((String)tr("Structures")).c_str()));
112  addDockWidget(Qt::LeftDockWidgetArea, new GeometricControl(this, ((String)tr("Representations")).c_str()));
113  addDockWidget(Qt::TopDockWidgetArea, new DatasetControl(this, ((String)tr("Datasets")).c_str()));
114  DatasetControl* dc = DatasetControl::getInstance(0);
119 
120 // NOTE: raytraceable grids have been deferred until 1.4/2.0
121 // dc->registerController(new RaytraceableGridController());
122 
123  DatasetControl::getInstance(0)->hide();
124 
125  // For Demo, Tutorial, and RayTracing
126  new DemoTutorialDialog(this, ((String)tr("BALLViewDemo")).c_str());
127 
128  Path path;
129 
130  new LabelDialog( this, ((String)tr("LabelDialog")).c_str());
131  new MolecularStructure( this, ((String)tr("MolecularStructure")).c_str());
132  addDockWidget(Qt::BottomDockWidgetArea, new LogView( this, ((String)tr("Logs")).c_str()));
133  addDockWidget(Qt::BottomDockWidgetArea, new FileObserver( this, ((String)tr("FileObserver")).c_str()));
134 
137  scene_ = new Scene(this, ((String)tr("3D View")).c_str());
138  setCentralWidget(scene_);
139  setAcceptDrops(true);
140 
141  new DisplayProperties(this, ((String)tr("DisplayProperties")).c_str());
142 
143  #ifdef BALL_PYTHON_SUPPORT
145  new TestFramework(this, ((String)"Test Framework").c_str());
146  #endif
147 
148  // ---------------------
149  // Menus ---------------
150  // ---------------------
151 
152  description = "Shortcut|File|Open|Project";
153  insertMenuEntry(MainControl::FILE_OPEN, ((String)tr("Project")).c_str(), this,
154  SLOT(loadBALLViewProjectFile()), description, QKeySequence(),
156 
157  description = "Shortcut|File|Save_Project";
158  save_project_action_ = insertMenuEntry(MainControl::FILE, ((String)tr("Save Project")).c_str(), this,
159  SLOT(saveBALLViewProjectFile()), description, QKeySequence(),
161 
162  // Help-Menu -------------------------------------------------------------------
163  QAction* action = 0;
164 
165  description = "Shortcut|Help|About";
166  action = insertMenuEntry(MainControl::HELP, (String)tr("About"), this, SLOT(about()), description);
167  if (action)
168  setMenuHint(action, (String)tr("Show informations on this version of BALLView"));
169 
170  // TODO: why is this done here and not, e.g., in mainControl()???
171  description = "Shortcut|MolecularMechanics|Abort_Calculation";
173  SLOT(stopSimulation()), description, QKeySequence("Alt+C"),
176  {
177  stop_simulation_action_->setEnabled(false);
178  setMenuHint(stop_simulation_action_, (String)tr("Abort a running simulation"));
180 
181  stop_simulation_action_->setIcon(IconLoader::instance().getIcon("actions/process-stop"));
182  }
183 
184 
185  description = "Shortcut|Edit|Invert_Selection";
186  complement_selection_action_ = insertMenuEntry(MainControl::EDIT, (String)tr("Invert Selection"), this,
187  SLOT(complementSelection()), description, QKeySequence(),
189 
190  description = "Shortcut|Edit|Clear_Selection";
191  clear_selection_action_ = insertMenuEntry(MainControl::EDIT, (String)tr("Clear Selection"), this,
192  SLOT(clearSelection()), description, QKeySequence(),
194 
195 
196  qApp->installEventFilter(this);
197 
198  setStatusbarText((String)tr("Ready."));
199  }
200 
202  {
203  #ifdef BALL_PYTHON_SUPPORT
205  #endif
206  }
207 
208 
209  bool Mainframe::eventFilter(QObject* sender, QEvent* event)
210  {
211  if (event->type() != QEvent::KeyPress) return false;
212 
213  QKeyEvent* e = dynamic_cast<QKeyEvent*>(event);
214 
215  QPoint point = QCursor::pos();
216  QWidget* widget = qApp->widgetAt(point);
217  if (widget == scene_ &&
218  qApp->focusWidget() != scene_)
219  {
220  scene_->keyPressEvent(e);
221  return true;
222  }
223 
224  if (e->key() == Qt::Key_Delete &&
225  RTTI::isKindOf<QTreeWidget>(sender))
226  {
227  deleteClicked();
228  return true;
229  }
230 
231  if (e->key() == Qt::Key_Enter)
232  {
233  if (composite_manager_.getNumberOfComposites() == 0) return false;
234 
235  if (getMolecularControlSelection().size() == 0)
236  {
238  }
239 
240  MolecularStructure::getInstance(0)->centerCamera();
241  return true;
242  }
243 
244  // check all menu entries if Alt or CTRL is pressed to enable shortcuts
245  if (e->key() == Qt::Key_Alt ||
246  e->key() == Qt::Key_Control)
247  {
248  checkMenus();
249  return false;
250  }
251 
252  return false;
253  }
254 
255 
257  {
258  if (composites_locked_ || getRepresentationManager().updateRunning()) return;
259 
260  clearData();
261 
262  DisplayProperties* dp = DisplayProperties::getInstance(0);
267  dp->setTransparency(0);
269  }
270 
271 
273  {
275 
277  qload_action_->setEnabled(!composites_locked_);
278  qsave_action_->setEnabled(!composites_locked_);
279  }
280 
282  {
283  // prevent multiple inserting of menu entries, by calls of showFullScreen(), ...
284  if (preferences_action_ != 0)
285  {
287  return;
288  }
289 
290  QToolBar* tb = NULL;
292  {
293  tb = new QToolBar("Main Toolbar", this);
294  tb->setObjectName("Main Toolbar");
295  tb->setIconSize(QSize(22,22));
296  addToolBar(Qt::TopToolBarArea, tb);
297  }
298 
300 
302 
303  if (menu)
304  {
305  menu->addSeparator();
306  menu->addAction(tb->toggleViewAction());
307  }
308 
309  // NOTE: this *has* to be run... a null pointer is unproblematic
311  {
312  MolecularFileDialog::getInstance(0)->addToolBarEntries(tb);
313  DownloadPDBFile::getInstance(0)->addToolBarEntries(tb);
314  DownloadElectronDensity::getInstance(0)->addToolBarEntries(tb);
315  PubChemDialog::getInstance(0)->addToolBarEntries(tb);
316  UndoManagerDialog::getInstance(0)->addToolBarEntries(tb);
317  tb->addAction(fullscreen_action_);
318 
319  Path path;
320 
321  IconLoader& loader = IconLoader::instance();
322  qload_action_ = new QAction(loader.getIcon("actions/quickopen-file"), tr("quickload"), this);
323  qload_action_->setObjectName("quickload");
324  connect(qload_action_, SIGNAL(triggered()), this, SLOT(quickLoadConfirm()));
325  tb->addAction(qload_action_);
326 
327  qsave_action_ = new QAction(loader.getIcon("actions/quicksave"), tr("quicksave"), this);
328  qsave_action_->setObjectName("quicksave");
329  connect(qsave_action_, SIGNAL(triggered()), this, SLOT(quickSave()));
330  tb->addAction(qsave_action_);
331 
332  tb->addSeparator();
333  DisplayProperties::getInstance(0)->addToolBarEntries(tb);
334  MolecularStructure::getInstance(0)->addToolBarEntries(tb);
335  }
336 
339  {
340 
341  tb->addAction(stop_simulation_action_);
342  tb->addAction(preferences_action_);
343  }
344  // we have changed the child widgets stored in the maincontrol (e.g. toolbars), so we have
345  // to restore the window state again!
346  restoreWindows();
347  }
348 
350  {
351  // Display about dialog
352  QDialog w;
353  Ui_AboutDialog about;
354  about.setupUi(&w);
355  QString version = QString(tr("QT ")) + qVersion() + "(mt)";
356  about.qt_version_label->setText(version);
357  QFont font = about.BALLView_version_label->font();
358  about.BALLView_version_label->setText(QString("BALLView ") + BALL_RELEASE_STRING);
359  font.setPixelSize(18);
360  about.BALLView_version_label->setFont(font);
361  about.BALL_version_label->setText(__DATE__);
362 
363  // find the BALLView log
364  Path p;
365  String logo_path = p.find("graphics/logo.png");
366 
367  if (logo_path != "")
368  about.BALLView_logo_label->setPixmap(QPixmap(logo_path.c_str()));
369 
370  w.exec();
371  }
372 
374  {
375  if(evt->type() == QEvent::WindowStateChange) {
376  if (isFullScreen())
377  {
378  if (fullscreen_action_ != 0)
379  {
380  fullscreen_action_->setIcon(IconLoader::instance().getIcon("actions/view-restore"));
381  }
382  }
383  else
384  {
385  if (fullscreen_action_ != 0)
386  {
387  fullscreen_action_->setIcon(IconLoader::instance().getIcon("actions/view-fullscreen"));
388  }
389  }
390  }
391  }
392 
394  {
396 
397  boost::shared_ptr<PluginHandler> handler(new InputDevPluginHandler());
398  man.registerHandler(handler);
399 
400  handler.reset(new ModularWidgetPluginHandler(this));
401  man.registerHandler(handler);
402  man.registerHandler(new PluginDialog(getPreferences(), this));
403  }
404 }
BALL::VIEW::MainControl::setMenuHint
void setMenuHint(QAction *id, const String &hint)
Set a hint for a menu entry.
BALL::VIEW::COLORING_ELEMENT
@ COLORING_ELEMENT
Definition: VIEW/KERNEL/common.h:245
BALL::VIEW::MainControl::DISPLAY_VIEWPOINT
@ DISPLAY_VIEWPOINT
Display Viewpoint submenu.
Definition: mainControl.h:169
standardDatasets.h
BALL::VIEW::IconLoader::getIcon
const QIcon & getIcon(const String &name)
BALL::VIEW::PubChemDialog
Definition: pubchemDialog.h:41
BALL::VIEW::VectorGridController
Definition: standardDatasets.h:257
BALL::VIEW::MainControl::TOOLS
@ TOOLS
Tools menu.
Definition: mainControl.h:188
BALL::PluginManager::instance
static PluginManager & instance()
BALL::Mainframe::eventFilter
bool eventFilter(QObject *, QEvent *e)
Catch key events.
Definition: mainframe.C:209
BALL::VIEW::DemoTutorialDialog
Definition: demoTutorialDialog.h:32
undoManagerDialog.h
BALL::VIEW::MainControl::quickSave
void quickSave()
Create a BALLView project file with the name quick.bvp in the users home dir.
BALL::VIEW::MainControl::composite_manager_
CompositeManager composite_manager_
Definition: mainControl.h:911
bucky_64x64_xpm
const char * bucky_64x64_xpm[]
Definition: icons.C:9
BALL::VIEW::DisplayProperties::selectMode
void selectMode(int index)
BALL::VIEW::MainControl::stop_simulation_action_
QAction * stop_simulation_action_
Definition: mainControl.h:951
BALL::Embeddable::registerThis
virtual void registerThis()
BALL::VIEW::MainControl::setLoggingFilename
void setLoggingFilename(const String &string)
logView.h
forEach.h
BALL::VIEW::MainControl::loadBALLViewProjectFile
void loadBALLViewProjectFile()
BALL::VIEW::MainControl::stopSimulation
void stopSimulation()
Stop a currently running calculation.
downloadPDBFile.h
BALL::VIEW::MainControl::TOOLS_PYTHON
@ TOOLS_PYTHON
Python submenu in Tools.
Definition: mainControl.h:194
BALL::PyInterpreter::initialize
static void initialize()
BALL::VIEW::LogView
Definition: logView.h:47
BALL::VIEW::InputDevPluginHandler
Definition: inputDevPluginHandler.h:18
BALL::VIEW::DisplayProperties::setDrawingPrecision
void setDrawingPrecision(int value)
BALL::VIEW::MainControl::saveBALLViewProjectFile
void saveBALLViewProjectFile()
BALL::VIEW::DRAWING_PRECISION_HIGH
@ DRAWING_PRECISION_HIGH
Definition: VIEW/KERNEL/common.h:140
BALL::VIEW::Scene::addToolBarEntries
virtual void addToolBarEntries(QToolBar *tb)
BALL::VIEW::MainControl::checkMenus
virtual void checkMenus()
demoTutorialDialog.h
BALL::VIEW::MainControl::insertMenuEntry
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)
BALL::Log
BALL_EXPORT LogStream Log
QObject
BALL::VIEW::DisplayProperties::selectModel
void selectModel(int index)
BALL::LogStream::error
LogStream & error(int n=0)
BALL::VIEW::DRAWING_MODE_SOLID
@ DRAWING_MODE_SOLID
Definition: VIEW/KERNEL/common.h:118
BALL::VIEW::MainControl::EDIT
@ EDIT
Edit menu.
Definition: mainControl.h:157
BALL::VIEW::DatasetControl::registerController
virtual bool registerController(DatasetController *con)
BALL::VIEW::UndoManagerDialog
Definition: undoManagerDialog.h:31
BALL::VIEW::MainControl::initPopupMenu
virtual QMenu * initPopupMenu(int ID, UIOperationMode::OperationMode mode=UIOperationMode::MODE_ALL)
BALL::Mainframe::setupPluginHandlers_
void setupPluginHandlers_()
Definition: mainframe.C:393
BALL::Mainframe::about
void about()
Definition: mainframe.C:349
BALL::VIEW::MainControl::quickLoadConfirm
void quickLoadConfirm()
BALL::VIEW::ModularWidgetPluginHandler
Definition: modularWidgetPluginHandler.h:23
BALL::Mainframe::show
void show()
Definition: mainframe.C:281
BALL::VIEW::MainControl::show
virtual void show()
BALL::VIEW::MainControl::MACRO
@ MACRO
Macros e.g. for Testing.
Definition: mainControl.h:203
BALL::VIEW::MainControl::fullscreen_action_
QAction * fullscreen_action_
Definition: mainControl.h:952
BALL::VIEW::DisplayProperties::selectColoringMethod
void selectColoringMethod(int index)
molecularControl.h
BALL::VIEW::MainControl::complement_selection_action_
QAction * complement_selection_action_
Definition: mainControl.h:953
QEvent
modularWidgetPluginHandler.h
BALL::VIEW::RegularData3DController
Definition: standardDatasets.h:57
BALL::String
Definition: string.h:56
BALL::VIEW::PluginDialog
Definition: pluginDialog.h:73
BALL::VIEW::DownloadPDBFile
Definition: downloadPDBFile.h:34
BALL::VIEW::LabelDialog
Definition: labelDialog.h:38
BALL::VIEW::MainControl::getRepresentationManager
RepresentationManager & getRepresentationManager()
Definition: mainControl.h:256
BALL::VIEW::MainControl::composites_locked_
bool composites_locked_
Definition: mainControl.h:920
BALL::VIEW::MainControl
Definition: mainControl.h:114
BALL::VIEW::MainControl::clearData
void clearData()
BALL::VIEW::Scene
Definition: scene.h:138
BALL::VIEW::MainControl::USER
@ USER
Userdefined menus.
Definition: mainControl.h:200
BALL
Definition: constants.h:12
BALL::VIEW::DisplayProperties::setTransparency
void setTransparency(int value)
BALL::Mainframe::qsave_action_
QAction * qsave_action_
Definition: mainframe.h:60
pluginManager.h
BALL::VIEW::MainControl::FILE
@ FILE
File menu.
Definition: mainControl.h:139
geometricControl.h
testFramework.h
BALL::Path::find
String find(const String &name)
BALL::VIEW::FileObserver
Definition: fileObserver.h:34
BALL::String::c_str
const char * c_str() const BALL_NOEXCEPT
BALL::VIEW::DatasetControl
Definition: datasetControl.h:36
BALL::VIEW::MainControl::restoreWindows
virtual void restoreWindows()
Restore the positions the main window and of all DockWindow's from the INIFile assigned to this insta...
BALL::VIEW::CompositeManager::getNumberOfComposites
Size getNumberOfComposites() const
Definition: compositeManager.h:101
BALL::VIEW::MainControl::FILE_OPEN
@ FILE_OPEN
File menu sub menu open.
Definition: mainControl.h:142
BALL::VIEW::MainControl::clear_selection_action_
QAction * clear_selection_action_
Definition: mainControl.h:954
BALL::VIEW::Scene::keyPressEvent
virtual void keyPressEvent(QKeyEvent *e)
Catch key events.
downloadElectronDensity.h
BALL::VIEW::MainControl::HELP
@ HELP
Definition: mainControl.h:207
BALL::VIEW::MODEL_STICK
@ MODEL_STICK
defines the property for the model: Stick
Definition: VIEW/KERNEL/common.h:171
BALL::VIEW
Definition: constraints.h:34
displayProperties.h
BALL::VIEW::MolecularFileDialog
Definition: molecularFileDialog.h:45
BALL::VIEW::MainControl::clearSelection
void clearSelection()
labelDialog.h
BALL::VIEW::IconLoader::instance
static IconLoader & instance()
BALL::VIEW::CompositeManager::begin
CompositeIterator begin()
Definition: compositeManager.h:110
BALL::VIEW::MolecularStructure
Definition: molecularStructure.h:90
iconLoader.h
BALL::VIEW::MainControl::complementSelection
void complementSelection()
pyInterpreter.h
datasetControl.h
BALL::VIEW::DockResultController
Definition: standardDatasets.h:201
icons.h
BALL::VIEW::MainControl::event
virtual bool event(QEvent *e)
Interface to QT events, e.g. to communicate with other threads.
BALL::Mainframe::save_project_action_
QAction * save_project_action_
Definition: mainframe.h:59
BALL::VIEW::MainControl::BUILD
@ BUILD
Build menu.
Definition: mainControl.h:160
BALL::Mainframe::~Mainframe
virtual ~Mainframe()
Definition: mainframe.C:201
BALL::VIEW::MainControl::toggleFullScreen
void toggleFullScreen()
path.h
BALL::VIEW::MainControl::deleteClicked
virtual void deleteClicked()
BALL::VIEW::Scene::stereoBufferSupportTest
static bool stereoBufferSupportTest()
BALL::VIEW::MainControl::getPreferences
Preferences * getPreferences()
BALL::Mainframe::scene_
Scene * scene_
Definition: mainframe.h:58
BALL::Mainframe::checkMenus
void checkMenus()
Definition: mainframe.C:272
QWidget
BALL::VIEW::MainControl::WINDOWS
@ WINDOWS
Windows menu.
Definition: mainControl.h:197
BALL::Mainframe::qload_action_
QAction * qload_action_
Definition: mainframe.h:60
BALL::VIEW::MainControl::DISPLAY
@ DISPLAY
Display menu.
Definition: mainControl.h:163
BALL::VIEW::TrajectoryController
Definition: standardDatasets.h:146
BALL::VIEW::MainControl::MOLECULARMECHANICS
@ MOLECULARMECHANICS
Simulations menu.
Definition: mainControl.h:182
mainframe.h
pluginDialog.h
BALL::VIEW::GeometricControl
Definition: geometricControl.h:41
molecularFileDialog.h
BALL::VIEW::UIOperationMode::MODE_ADVANCED
@ MODE_ADVANCED
Definition: UIOperationMode.h:32
pubchemDialog.h
BALL::PluginManager::registerHandler
void registerHandler(PluginHandler *h)
BALL::VIEW::DownloadElectronDensity
Definition: downloadElectronDensity.h:35
moleculeObjectCreator.h
inputDevPluginHandler.h
BALL::VIEW::DisplayProperties::setSurfaceDrawingPrecision
void setSurfaceDrawingPrecision(float value)
BALL::VIEW::MolecularControl
Definition: molecularControl.h:49
BALL::VIEW::MainControl::insertPopupMenuSeparator
void insertPopupMenuSeparator(int ID, UIOperationMode::OperationMode mode=UIOperationMode::MODE_ALL)
BALL::VIEW::MainControl::setStatusbarText
void setStatusbarText(const String &text, bool important=false, bool beep=false)
BALL::PyInterpreter::finalize
static void finalize()
BALL::Mainframe::reset
void reset()
remove all loaded Molecules and Representations, reset Coloring options
Definition: mainframe.C:256
BALL::VIEW::MainControl::preferences_action_
QAction * preferences_action_
Definition: mainControl.h:956
QDialog
BALL::VIEW::DisplayProperties
Definition: displayProperties.h:54
BALL::VIEW::MainControl::getMolecularControlSelection
std::list< Composite * > & getMolecularControlSelection()
Get the selection (highlighted items) of the MolecularControl (not the selection with checkboxes)
fileObserver.h
BALL::VIEW::MainControl::control_selection_
std::list< Composite * > control_selection_
Definition: mainControl.h:903
BALL::Path
Definition: path.h:39
BALL::VIEW::IconLoader
Definition: iconLoader.h:28
preferences.h
BALL::Mainframe::changeEvent
void changeEvent(QEvent *evt)
Definition: mainframe.C:373
molecularStructure.h
VIEWPlugin.h
BALL::VIEW::TestFramework
Definition: testFramework.h:58
BALL::VIEW::UIOperationMode::instance
static UIOperationMode & instance()
BALL::PluginManager
Definition: pluginManager.h:38