BALL 1.5.0
Loading...
Searching...
No Matches
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"
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
43using namespace std;
44//#define BALL_VIEW_DEBUG
45
46namespace 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
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";
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 {
221 return true;
222 }
223
224 if (e->key() == Qt::Key_Delete &&
226 {
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
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
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!
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);
403 }
404}
const char * bucky_64x64_xpm[]
Definition icons.C:9
STL namespace.
BALL_EXPORT LogStream Log
bool isKindOf(const U *u)
Definition rtti.h:192
@ MODEL_STICK
defines the property for the model: Stick
LogStream & error(int n=0)
virtual void registerThis()
const char * c_str() const BALL_NOEXCEPT
static PluginManager & instance()
void registerHandler(PluginHandler *h)
static void finalize()
static void initialize()
String find(const String &name)
void setTransparency(int value)
void setSurfaceDrawingPrecision(float value)
void setDrawingPrecision(int value)
void selectColoringMethod(int index)
static IconLoader & instance()
const QIcon & getIcon(const String &name)
QAction * stop_simulation_action_
void stopSimulation()
Stop a currently running calculation.
void setStatusbarText(const String &text, bool important=false, bool beep=false)
void quickSave()
Create a BALLView project file with the name quick.bvp in the users home dir.
QAction * clear_selection_action_
QAction * complement_selection_action_
virtual void restoreWindows()
Restore the positions the main window and of all DockWindow's from the INIFile assigned to this insta...
virtual QMenu * initPopupMenu(int ID, UIOperationMode::OperationMode mode=UIOperationMode::MODE_ALL)
std::list< Composite * > & getMolecularControlSelection()
Get the selection (highlighted items) of the MolecularControl (not the selection with checkboxes)
virtual bool event(QEvent *e)
Interface to QT events, e.g. to communicate with other threads.
void insertPopupMenuSeparator(int ID, UIOperationMode::OperationMode mode=UIOperationMode::MODE_ALL)
void setMenuHint(QAction *id, const String &hint)
Set a hint for a menu entry.
RepresentationManager & getRepresentationManager()
std::list< Composite * > control_selection_
virtual void deleteClicked()
Preferences * getPreferences()
@ FILE_OPEN
File menu sub menu open.
@ DISPLAY
Display menu.
@ USER
Userdefined menus.
@ TOOLS_PYTHON
Python submenu in Tools.
@ MOLECULARMECHANICS
Simulations menu.
@ MACRO
Macros e.g. for Testing.
@ WINDOWS
Windows menu.
@ DISPLAY_VIEWPOINT
Display Viewpoint submenu.
virtual void checkMenus()
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)
void setLoggingFilename(const String &string)
CompositeManager composite_manager_
static UIOperationMode & instance()
virtual bool registerController(DatasetController *con)
virtual void keyPressEvent(QKeyEvent *e)
Catch key events.
virtual void addToolBarEntries(QToolBar *tb)
static bool stereoBufferSupportTest()
QAction * qload_action_
Definition mainframe.h:60
void setupPluginHandlers_()
Definition mainframe.C:393
bool eventFilter(QObject *, QEvent *e)
Catch key events.
Definition mainframe.C:209
virtual ~Mainframe()
Definition mainframe.C:201
Scene * scene_
Definition mainframe.h:58
void changeEvent(QEvent *evt)
Definition mainframe.C:373
Mainframe(QWidget *parent=0, const char *name=0)
Definition mainframe.C:51
QAction * save_project_action_
Definition mainframe.h:59
void checkMenus()
Definition mainframe.C:272
void reset()
remove all loaded Molecules and Representations, reset Coloring options
Definition mainframe.C:256
QAction * qsave_action_
Definition mainframe.h:60