crdview.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002                          crdview.cpp  -  description
00003                              -------------------
00004     begin                : Tue Jan 13 2004
00005     copyright            : (C) 2004-2006 by Ben Swerts
00006     email                : bswerts@users.sourceforge.net
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
00015  *                                                                         *
00016  ***************************************************************************/
00017 
00019 
00027 
00028 
00029 
00031 
00032 // Qt header files
00033 #include <qaccel.h>
00034 #include <qaction.h>
00035 #include <qapplication.h>
00036 #include <qcheckbox.h>
00037 #include <qcombobox.h>
00038 #include <qfiledialog.h>
00039 #include <qlabel.h>
00040 #include <qmenubar.h>
00041 #include <qmsgbox.h>
00042 #include <qpopupmenu.h>
00043 #include <qsettings.h>
00044 #include <qstatusbar.h>
00045 #include <qtextedit.h>
00046 #include <qtoolbar.h>
00047 #include <qwhatsthis.h>
00048 
00049 // CrdView header files
00050 #include "atomset.h"
00051 #include "crdfactory.h"
00052 #include "crdview.h"
00053 #include "iconsets.h"
00054 #include "glsimplemoleculeview.h"
00055 #include "moleculepropertieswidget.h"
00056 #include "textviewwidget.h"
00057 #include "version.h"
00058 
00062 
00064 CrdView::CrdView() : QMainWindow(0, 0, Qt::WType_TopLevel | Qt::WDestructiveClose)
00065 {
00066   setCaption(tr("CrdView "));
00067 
00068   // create an AtomSet for use with the GLSimpleMoleculeView
00069   atoms = new AtomSet();
00070 
00071   // create a GLSimpleMoleculeView for displaying the coordinates
00072   glview = new GLSimpleMoleculeView(atoms, this);
00073   setCentralWidget(glview);
00074 
00075   initActions(); // needs a valid glview pointer
00076   initMenuBar();
00077   initToolBar();
00078   readSettings();
00079 }
00080 
00082 CrdView::~CrdView()
00083 {
00084   delete atoms;
00085   saveSettings();
00086 }
00087 
00089 void CrdView::readCoordinates(QString filename)
00090 {
00092 
00093   unsigned short int result = CrdFactory::readFromFile(atoms, filename);
00094   switch(result)
00095   {
00096     case CrdFactory::OK:
00097       glview->updateAtomSet(true);
00098       setCaption(tr("CrdView") + QString(" - ") + filename);
00099       break;
00100     case CrdFactory::UnknownExtension:
00101       QMessageBox::warning(this, tr("Unknown format"), "The file " + filename + " has an unknown extension", QMessageBox::Ok, QMessageBox::NoButton);
00102       break;
00103     case CrdFactory::ErrorOpen:
00104       QMessageBox::warning(this, tr("Error opening file"), "The file " + filename + " could not be opened for reading", QMessageBox::Ok, QMessageBox::NoButton);
00105       break;
00106     case CrdFactory::ErrorRead:
00107       QMessageBox::warning(this, tr("Parse error"), "The contents of the file " + filename + " could not be parsed correctly", QMessageBox::Ok, QMessageBox::NoButton);
00108       break;
00109     case CrdFactory::UnknownFormat:
00110       QMessageBox::warning(this, tr("Unknown format"), "The format (normal/extended) of the file " + filename + " could not be detected correctly", QMessageBox::Ok, QMessageBox::NoButton);
00111       break;
00112   }
00113 
00114 }
00115 
00119 
00121 void CrdView::fileOpen()
00123 {
00124   statusBar()->message(tr("Opening a coordinate file..."));
00125 
00126   readCoordinates();
00127 
00128   statusBar()->message(tr("Loaded coordinates"), 2000);
00129 }
00130 
00132 void CrdView::fileSave()
00134 {
00135   statusBar()->message(tr("Saving coordinates in a new format..."));
00136 
00137   unsigned short int result = CrdFactory::writeToFile(atoms);
00138   switch(result)
00139   {
00140     case CrdFactory::UnknownExtension:
00141       QMessageBox::warning(this, "Unknown format", "The file has an unknown extension", QMessageBox::Ok, QMessageBox::NoButton);
00142       break;
00143     case CrdFactory::ErrorOpen:
00144       QMessageBox::warning(this, "Error opening file", "The file could not be opened for writing", QMessageBox::Ok, QMessageBox::NoButton);
00145       break;
00146     case CrdFactory::ErrorWrite:
00147       QMessageBox::warning(this, "Error writing file", "The file could not be written", QMessageBox::Ok, QMessageBox::NoButton);
00148       break;
00149   }
00150   statusBar()->clear();
00151 }
00152 
00154 void CrdView::fileExport()
00156 {
00157   statusBar()->message(tr("Exporting view..."));
00158 
00159   glview->saveImage();
00160 
00161   statusBar()->clear();
00162 }
00163 
00165 void CrdView::filePreferences()
00168 {
00169   statusBar()->message(tr("Changing Preferences..."));
00170 
00171   MoleculePropertiesWidget* properties = new MoleculePropertiesWidget(this, 0, true);
00172   properties->ComboBoxRenderingType->setCurrentItem(glview->displayStyle(GLSimpleMoleculeView::Molecule));
00173   properties->ComboBoxForces->setCurrentItem(glview->displayStyle(GLSimpleMoleculeView::Forces));
00174   properties->CheckBoxElement->setChecked(glview->isShowingElements());
00175   properties->CheckBoxNumber->setChecked(glview->isShowingNumbers());
00176   properties->LabelCharge->hide();
00177   properties->ComboBoxCharge->hide();
00178 
00179   if(properties->exec() == QDialog::Accepted)
00180   {
00181     glview->setDisplayStyle(GLSimpleMoleculeView::Molecule, properties->ComboBoxRenderingType->currentItem());
00182     glview->setDisplayStyle(GLSimpleMoleculeView::Forces, properties->ComboBoxForces->currentItem());
00183     glview->setLabels(properties->CheckBoxElement->isChecked(), properties->CheckBoxNumber->isChecked(), 0); // 0 = no charge
00184     glview->updateGL();
00185   }
00186   delete properties;
00187   statusBar()->clear();
00188 }
00189 
00191 void CrdView::viewToolBar(bool toggle)
00193 {
00194   statusBar()->message(tr("Toggling toolbar..."), 1000);
00195 
00196   // turn toolbar on or off
00197   if (toggle == false)
00198     ToolBarFile->hide();
00199   else
00200     ToolBarFile->show();
00201 }
00202 
00204 void CrdView::viewStatusBar(bool toggle)
00206 {
00207   statusBar()->message(tr("Toggling statusbar..."), 1000);
00208 
00209   //turn statusbar on or off
00210   if (toggle == false)
00211     statusBar()->hide();
00212   else
00213     statusBar()->show();
00214 }
00215 
00217 void CrdView::helpHelp()
00219 {
00220   statusBar()->message(tr("Showing general help..."));
00221 
00222   TextViewWidget* context = new TextViewWidget(this, 0, true, 0);
00223   context->TextEdit->setText(tr(
00224     "<p>As usual, the help pages are worked on at the last moment, so you will not find a "
00225     "complete help system here. The aim was to make the functionality of the programs as self-evident as possible. "
00226     "There are, however, a few ways to get some limited help.</p>"
00227     "<ul><li>All elements of both <em><b>Brabosphere</b></em> and <em><b>CrdView</b></em> have context sensitive help "
00228     "associated with them. These can be invoked by making the programs enter the appropriate state. "
00229     "This can be done with the corresponding icon: <img source=\"WhatsThisNormal\" size=16>, by using "
00230     "Shift+F1 or clicking the question mark in the title bar of most dialogs. At that point the mouse "
00231     "cursor changes into a question mark. When clicking an element context sensitive help for that "
00232     "element will be shown (if any help is associated with it, of course). This normally only works "
00233     "for elements that can be changed (so not regular text).</li>"
00234     "<li>When hovering over the entries in the programs' menu, 1 line of help will appear in the "
00235     "statusbar. The visibility of this statusbar can be changed using the menu (View->Status Bar)</li></ul>"
00236     "<p>Now for some general information not explainable with context sensitive help:</p>"
00237     "<ul><li>CrdView provides a single 3D window in which coordinates can be read and displayed. "
00238     "Almost all preferences have to be changed in Brabosphere. CrdView just uses the same settings. "
00239     "Only the 'Display Mode' of the coordinates can be changed from the default.</li>"
00240     "<li>CrdView can act as a graphical front-end for OpenBabel. Not only by loading and saving coordinates, "
00241     "but also by command line conversion: <b>crdview [-bnf] &lt;input file&gt; &lt;output file&gt;</b>. "
00242     "The '-bnf' option forces using the normal format for writing a BRABO coordinate file instead of the "
00243     "default extended format. The in- and output files can be any file format recognized by CrdView.</li>"
00244     "<li>If CrdView is started with exactly one command line option, it will be interpreted as the coordinate file "
00245     "to load. This way, the program can be used to display a large number of coordinate file formats with a simple click.</li></ul>"));
00246 
00247   context->TextEdit->setWordWrap(QTextEdit::WidgetWidth);
00248   QWhatsThis::add(context->TextEdit, "Yes, you found out how to use the context sensitive help!");
00249   context->TextEdit->setFont(QApplication::font());
00250   context->setCaption(tr("Contents"));
00251   context->exec();
00252   delete context;
00253 
00254   statusBar()->clear();
00255 }
00256 
00258 void CrdView::helpWhatsThis()
00260 {
00261   statusBar()->message(tr("Entering What's This mode..."), 1000);
00262 
00263   QWhatsThis::enterWhatsThisMode();
00264 }
00265 
00267 void CrdView::helpAbout()
00269 {
00270   statusBar()->message(tr("About the program..."));
00271 
00272   QMessageBox::about(this,tr("About..."),
00273                      tr("CrdView") + "\n" +
00274                      tr("Version") + " " + Version::appVersion + " (" + tr("build") + " " + Version::appBuild + ")\n" +
00275                      tr("Part of") + " " + Version::appName + " " + Version::appVersion + "\n" +
00276                      tr("(c) 2006 by Ben Swerts\n")
00277                     );
00278   statusBar()->clear();
00279 }
00280 
00284 
00285 /*//// showEvent ///////////////////////////////////////////////////////////////
00286 void CrdView::showEvent (QShowEvent*)
00287 {
00289 
00290   static bool ok = false;
00291   if(!ok)
00292   {
00293     glview->resetView(false);
00294     ok = true;
00295   }
00296 }// */
00297 
00301 
00303 void CrdView::initActions()
00304 {
00307 
00310   actionFileOpen = new QAction(IconSets::getIconSet(IconSets::Open), tr("&Open..."), CTRL+Key_O, this);
00311   actionFileOpen->setToolTip(tr("Open an existing coordinate file"));
00312   actionFileOpen->setWhatsThis(actionText(tr("Open File"), tr("Opens an existing coordinate file."),
00313                                tr("Any supported file format can be read, including Brabosphere calculations."),
00314                                IconSets::Open));
00315   connect(actionFileOpen, SIGNAL(activated()), this, SLOT(fileOpen()));
00316 
00317   // File->Save As
00318   actionFileSave = new QAction(IconSets::getIconSet(IconSets::Save), tr("&Save As..."), CTRL+Key_S, this);
00319   actionFileSave->setText(tr("Save the current coordinates"));
00320   actionFileSave->setWhatsThis(actionText(tr("Save File"), tr("Saves the currently shown coordinates."),
00321                                tr("Any supported file format can be chosen as a target."),
00322                                IconSets::Save));
00323   connect(actionFileSave, SIGNAL(activated()), this, SLOT(fileSave()));
00324 
00325   // File->Preferences
00326   actionFilePreferences = new QAction(IconSets::getIconSet(IconSets::Prefs), tr("P&references..."), 0, this);
00327   actionFilePreferences->setText(tr("Change the default viewing preferences"));
00328   actionFilePreferences->setWhatsThis(actionText(tr("Preferences"), tr("Changes the viewing preferences."),
00329                                       tr("The only view settings that can be changed are the ones corresponding to Display "
00330                                          "Mode in Brabosphere. They take effect immediately. Other settings will have to "
00331                                          "be changed in Brabosphere itself."
00332                                          "CrdView will have to be restarted for those settings to take effect."),
00333                                       IconSets::Prefs));
00334   connect(actionFilePreferences, SIGNAL(activated()), this, SLOT(filePreferences()));
00335 
00336   // File->Export
00337   actionFileExport = new QAction(IconSets::getIconSet(IconSets::Image), tr("&Export..."), 0, this);
00338   actionFileExport->setText(tr("Export the current view to an image"));
00339   actionFileExport->setWhatsThis(actionText(tr("Export File"), tr("Exports the current view to an image."),
00340                                  tr("A number of formats can be chosen from. "
00341                                     "The size of the image will be determined by the size of the scene's window."),
00342                                  IconSets::Image));
00343   connect(actionFileExport, SIGNAL(activated()), this, SLOT(fileExport()));
00344 
00345   // File->Quit
00346   actionFileQuit = new QAction(QIconSet(), tr("E&xit"), CTRL+Key_Q, this);
00347   actionFileQuit->setText(tr("Quits the application"));
00348   actionFileQuit->setWhatsThis(actionText(tr("Exit"), tr("Exits CrdView."),
00349                                tr("The application will be closed without asking confirmation.")));
00350   connect(actionFileQuit, SIGNAL(activated()), this, SLOT(close()));
00351 
00352   // View->Toolbar
00353   actionViewToolBar = new QAction(QIconSet(), tr("Tool&bar"), 0, this);
00354   actionViewToolBar->setText(tr("Toggles the visibility of the toolbar"));
00355   actionViewToolBar->setToggleAction(true);
00356   actionViewToolBar->setWhatsThis(actionText(tr("View Toolbar"), tr("Toggles the visibility of the toolbar."),
00357                                   tr("This is the toolbar containing shortcuts to selected entries in "
00358                                      "the File menu.")));
00359   connect(actionViewToolBar, SIGNAL(toggled(bool)), this, SLOT(viewToolBar(bool)));
00360 
00361   // View->Statusbar
00362   actionViewStatusBar = new QAction(QIconSet(), tr("&Statusbar"), 0, this);
00363   actionViewStatusBar->setText(tr("Toggles the visibility of the statusbar"));
00364   actionViewStatusBar->setToggleAction(true);
00365   actionViewStatusBar->setWhatsThis(actionText(tr("View Statusbar"), tr("Toggles the visibility of the statusbar."),
00366                                     tr("This is de toolbar at the bottom of the main window which displays temporary messages.")));
00367   connect(actionViewStatusBar, SIGNAL(toggled(bool)), this, SLOT(viewStatusBar(bool)));
00368 
00369   // Reset->Translation
00370   actionCenterView = new QAction(QIconSet(), tr("&Translation"), 0, this);
00371   actionCenterView->setText(tr("Center the molecule"));
00372   actionCenterView->setWhatsThis(actionText(tr("Reset Translation"), tr("Restores the center of the molecule to the center of the 3D scene."))); 
00373   connect(actionCenterView, SIGNAL(activated()), glview, SLOT(centerView()));
00374 
00375   // Reset->Orientation
00376   actionResetOrientation = new QAction(QIconSet(), tr("&Orientation"), 0, this);
00377   actionResetOrientation->setText(tr("Reset the orientation of the molecule"));
00378   actionResetOrientation->setWhatsThis(actionText(tr("Reset Orientation"), tr("Resets the rotational axes of the molecule."),
00379                                        tr("After the reset, the X-axis will again point to the right, "
00380                                           "the Y-axis to the top and the Z-axis into the screen.")));
00381   connect(actionResetOrientation, SIGNAL(activated()), glview, SLOT(resetOrientation()));
00382 
00383   // Reset->Zoom
00384   actionZoomFit = new QAction(QIconSet(), tr("&Zoom"), 0, this);
00385   actionZoomFit->setText(tr("Zoom such that the molecule fits in the window"));
00386   actionZoomFit->setWhatsThis(actionText(tr("Reset Zoom"), tr("Zooms the scene such that the molecule fits exactly in the window.")));
00387   connect(actionZoomFit, SIGNAL(activated()), glview, SLOT(zoomFit()));
00388 
00389   // Reset->View
00390   actionResetView = new QAction(QIconSet(), tr("&View"), 0, this);
00391   actionResetView->setText(tr("Reset translation, orientation and zoom"));
00392   actionResetView->setWhatsThis(actionText(tr("Reset View"), tr("Resets the translation, orientation and zoom of the molecule.")));
00393   connect(actionResetView, SIGNAL(activated()), glview, SLOT(resetView()));
00394 
00395   // Select->All
00396   actionSelectAll = new QAction(QIconSet(), tr("&All"), Qt::CTRL + Qt::Key_A, this);
00397   actionSelectAll->setText(tr("Select all atoms"));
00398   actionSelectAll->setWhatsThis(actionText(tr("Select All"), tr("Selects all atoms.")));
00399   connect(actionSelectAll, SIGNAL(activated()), glview, SLOT(selectAll()));
00400 
00401   // Select->None
00402   actionSelectNone = new QAction(QIconSet(), tr("&None"), Qt::CTRL + Qt::SHIFT + Qt::Key_A, this);
00403   actionSelectNone->setText(tr("Deselect all atoms"));
00404   actionSelectNone->setWhatsThis(actionText(tr("Select None"), tr("Deselects all atoms.")));
00405   connect(actionSelectNone, SIGNAL(activated()), glview, SLOT(unselectAll()));
00406 
00407   // Help->Contents
00408   actionHelp = new QAction(IconSets::getIconSet(IconSets::Help), tr("Contents..."), Qt::Key_F1, this);
00409   actionHelp->setText(tr("Shows useful info"));
00410   actionHelp->setWhatsThis(actionText(tr("Contents of Help"), tr("Shows a brief explanation of the program and the use of the context-sensitive help system."),
00411                            QString::null, IconSets::Help));
00412   connect(actionHelp, SIGNAL(activated()), this, SLOT(helpHelp()));
00413 
00414   // Help->Context sensitive help
00415   actionWhatsThis = new QAction(IconSets::getIconSet(IconSets::WhatsThis), tr("Context sensitive help..."), Qt::SHIFT + Qt::Key_F1, this);
00416   actionWhatsThis->setText(tr("Shows context sensitive help"));
00417   actionWhatsThis->setWhatsThis(actionText(tr("Context Sensitive Help"), tr("Well, if you are reading this, you already know how this thing works!."),
00418                            QString::null, IconSets::WhatsThis));
00419   connect(actionWhatsThis, SIGNAL(activated()), this, SLOT(helpWhatsThis()));
00420 
00421   // Help->About
00422   actionAbout = new QAction(QIconSet(), tr("&About..."), 0, this);
00423   actionAbout->setText(tr("Shows an About box"));
00424   actionAbout->setWhatsThis(actionText(tr("About"), tr("Gives some info about CrdView.")));
00425   connect(actionAbout, SIGNAL(activated()), this, SLOT(helpAbout()));
00426 }
00427 
00429 void CrdView::initMenuBar()
00430 {
00432 
00433   // fileMenu
00434   QPopupMenu* fileMenu = new QPopupMenu();
00435   actionFileOpen->addTo(fileMenu);
00436   fileMenu->insertSeparator();
00437   actionFileSave->addTo(fileMenu);
00438   actionFileExport->addTo(fileMenu);
00439   fileMenu->insertSeparator();
00440   actionFilePreferences->addTo(fileMenu);
00441   fileMenu->insertSeparator();
00442   actionFileQuit->addTo(fileMenu);
00443 
00444   // viewMenu
00445   QPopupMenu* viewMenu = new QPopupMenu();
00446   viewMenu->setCheckable(true);
00447   actionViewToolBar->addTo(viewMenu);
00448   actionViewStatusBar->addTo(viewMenu);
00449 
00450   // resetMenu
00451   QPopupMenu* resetMenu = new QPopupMenu();
00452   actionCenterView->addTo(resetMenu);
00453   actionResetOrientation->addTo(resetMenu);
00454   actionZoomFit->addTo(resetMenu);
00455   actionResetView->addTo(resetMenu);
00456 
00457   // selectMenu
00458   QPopupMenu* selectMenu = new QPopupMenu();
00459   actionSelectAll->addTo(selectMenu);
00460   actionSelectNone->addTo(selectMenu);
00461 
00462   // menuBar entry helpMenu
00463   QPopupMenu* helpMenu=new QPopupMenu();
00464   actionHelp->addTo(helpMenu);
00465   actionWhatsThis->addTo(helpMenu);
00466   actionAbout->addTo(helpMenu);
00467 
00468   // menuBar
00469   menuBar()->insertItem(tr("&File"), fileMenu);
00470   menuBar()->insertItem(tr("&View"), viewMenu);
00471   menuBar()->insertItem(tr("&Reset"), resetMenu);
00472   menuBar()->insertItem(tr("&Select"), selectMenu);
00473   menuBar()->insertItem(tr("&Help"), helpMenu);
00474 }
00475 
00477 void CrdView::initToolBar()
00478 {
00480 
00481   // ToolBarFile
00482   ToolBarFile = new QToolBar(this);
00483   ToolBarFile->setCaption(tr("Standard"));
00484   actionFileOpen->addTo(ToolBarFile);
00485   actionFileSave->addTo(ToolBarFile);
00486   actionFileExport->addTo(ToolBarFile);
00487   ToolBarFile->addSeparator();
00488   actionFilePreferences->addTo(ToolBarFile);
00489   ToolBarFile->addSeparator();
00490   actionHelp->addTo(ToolBarFile);
00491   actionWhatsThis->addTo(ToolBarFile);
00492 }
00493 
00495 void CrdView::readSettings()
00497 {
00499   glview->makeCurrent();
00500   GLfloat lwrange[] = {0.0, 0.0};
00501   GLfloat lwgran[] = {0.0};
00502   glGetFloatv(GL_LINE_WIDTH_RANGE, lwrange);
00503   glGetFloatv(GL_LINE_WIDTH_GRANULARITY, lwgran);
00504   const int defaultLineWidth = static_cast<int>((lwrange[0] > 1.0f ? lwrange[0] : 1.0f)/lwgran[0]);
00505   qDebug("defaultLineWidth = %d", defaultLineWidth);
00506 
00507   QSettings settings;
00508   settings.setPath(Version::appCompany, Version::appName.lower(), QSettings::User);
00509 
00510 #ifdef Q_OS_WIN32
00511   const QString unixPrefix = "/";
00512 #else
00513   const QString unixPrefix = "/" + Version::appName.lower() + "/";
00514 #endif
00515 
00516   QString prefix = unixPrefix + "preferences/";
00517 
00519   GLBaseParameters glBaseParameters;
00520   GLMoleculeParameters glMoleculeParameters;
00521   glMoleculeParameters.defaultMoleculeStyle = settings.readNumEntry(prefix + "style_molecule", 3); // Ball & Stick
00522   glMoleculeParameters.defaultForcesStyle   = settings.readNumEntry(prefix + "style_forces", 2); // Tubes
00523   glMoleculeParameters.fastRenderLimit      = settings.readNumEntry(prefix + "fast_render_limit", 1000);
00524   glMoleculeParameters.showElements         = settings.readBoolEntry(prefix + "show_elements", false);
00525   glMoleculeParameters.showNumbers          = settings.readBoolEntry(prefix + "show_numbers", true);
00526   const int lineWidth                       = settings.readNumEntry(prefix + "size_lines", defaultLineWidth); 
00527   glMoleculeParameters.sizeLines            = static_cast<GLfloat>(lineWidth)*lwgran[0];
00528   qDebug("read sizeLines = %f",glMoleculeParameters.sizeLines);
00529   glMoleculeParameters.sizeBonds            = settings.readEntry(prefix + "size_bonds", QString::number(AtomSet::vanderWaals(1)/2.0)).toFloat()/2.0;
00530   glMoleculeParameters.sizeForces           = settings.readEntry(prefix + "size_forces", QString::number(AtomSet::vanderWaals(1)/2.0*1.1)).toFloat()/2.0;
00531   glMoleculeParameters.colorLabels          = settings.readNumEntry(prefix + "color_labels", QColor(0, 255, 0).rgb()); // green
00532   glMoleculeParameters.colorICs             = settings.readNumEntry(prefix + "color_internal_coordinates", QColor(0, 255, 255).rgb()); // cyan
00533   glBaseParameters.backgroundColor          = settings.readNumEntry(prefix + "color_background_gl", 0); // black
00534   glMoleculeParameters.colorSelections      = settings.readNumEntry(prefix + "color_selections", QColor(255, 255, 0).rgb()); // yellow
00535   glMoleculeParameters.opacitySelections    = settings.readNumEntry(prefix + "opacity_selections", 50);
00536   glMoleculeParameters.colorForces          = settings.readNumEntry(prefix + "color_forces", QColor(255, 255, 0).rgb()); //yellow
00537   glMoleculeParameters.forcesOneColor       = settings.readBoolEntry(prefix + "color_force_type", false); // atom color
00538   glMoleculeParameters.opacityForces        = settings.readNumEntry(prefix + "opacity_forces", 100);
00539 
00541   //data.styleApplication  = settings.readNumEntry(prefix + "style", 0); // Startup style
00542 
00544   switch(settings.readNumEntry(prefix + "light_position", 2))
00545   {
00546     case 0: glBaseParameters.lightPositionX = -1.0f;
00547             glBaseParameters.lightPositionY =  1.0f;
00548             break;
00549     case 1: glBaseParameters.lightPositionX =  0.0f;
00550             glBaseParameters.lightPositionY =  1.0f;
00551             break;
00552     case 3: glBaseParameters.lightPositionX = -1.0f;
00553             glBaseParameters.lightPositionY =  0.0f;
00554             break;
00555     case 4: glBaseParameters.lightPositionX =  0.0f;
00556             glBaseParameters.lightPositionY =  0.0f;
00557             break;
00558     case 5: glBaseParameters.lightPositionX =  1.0f;
00559             glBaseParameters.lightPositionY =  0.0f;
00560             break;
00561     case 6: glBaseParameters.lightPositionX = -1.0f;
00562             glBaseParameters.lightPositionY = -1.0f;
00563             break;
00564     case 7: glBaseParameters.lightPositionX =  0.0f;
00565             glBaseParameters.lightPositionY = -1.0f;
00566             break;
00567     case 8: glBaseParameters.lightPositionX =  1.0f;
00568             glBaseParameters.lightPositionY = -1.0f;
00569             break;
00570     case 2:
00571     default: glBaseParameters.lightPositionX =  1.0f;
00572              glBaseParameters.lightPositionY =  1.0f;
00573              break;
00574   }
00575   glBaseParameters.lightPositionZ = 1.0f;
00576   glBaseParameters.lightColor               = settings.readNumEntry(prefix + "light_color", QColor(255,255,255).rgb());
00577   glBaseParameters.materialSpecular         = settings.readNumEntry(prefix + "material_specular", 80);
00578   glBaseParameters.materialShininess        = settings.readNumEntry(prefix + "material_shininess", 100);
00579   glBaseParameters.antialias                = settings.readBoolEntry(prefix + "antialias", true);
00580   glBaseParameters.smoothShading            = settings.readBoolEntry(prefix + "smooth_shading", true);
00581   glBaseParameters.depthCue                 = settings.readBoolEntry(prefix + "depth_cue", true);
00582   glMoleculeParameters.quality              = settings.readNumEntry(prefix + "quality", 22); // 31 slices
00583   glBaseParameters.perspectiveProjection    = settings.readBoolEntry(prefix + "perspective_projection", true);
00584 
00586   GLView::setParameters(glBaseParameters);
00587   GLSimpleMoleculeView::setParameters(glMoleculeParameters);
00588 
00590   prefix = unixPrefix + "crdview/";
00591 
00593   int x = settings.readNumEntry(prefix + "geometry/x", -1);
00594   int y = settings.readNumEntry(prefix + "geometry/y", -1);
00595   int width = settings.readNumEntry(prefix + "geometry/width", -1);
00596   int height = settings.readNumEntry(prefix + "geometry/height", -1);
00597 
00598   QRect screenRect = QApplication::desktop()->availableGeometry(QApplication::desktop()->primaryScreen());
00600   if((x == -1) || (y == -1) || (width == -1) || (height == -1))
00601   {
00602     width = screenRect.width()/2;
00603     height = screenRect.height()/2;
00604     x = width/2;
00605     y = height/2;
00606   }
00608   if(x < 0) x = 0;
00609   if(y < 0) y = 0;
00610   if(width > screenRect.width())
00611   {
00612     x = 0;
00613     width = screenRect.width();
00614   }
00615   if(height > screenRect.height())
00616   {
00617     y = 0;
00618     height = screenRect.height();
00619   }
00620   if((x + width) > screenRect.width())
00621     x = (screenRect.width() - width)/2; // centered
00622   if((y + height) > screenRect.height())
00623     y = (screenRect.height() - height)/2; // centered
00625   resize(width, height);
00626   move(x, y);
00627 
00629   QString toolbarsInfo = settings.readEntry(prefix + "toolbars/other", QString::null);
00630   if(!toolbarsInfo.isEmpty())
00631   {
00632     QTextStream stream(&toolbarsInfo, IO_ReadOnly);
00633     stream >> *this;
00634   }
00635   if(settings.readBoolEntry(prefix + "toolbars/statusbar", true))
00636     statusBar()->show();
00637   else
00638     statusBar()->hide();
00639   actionViewToolBar->setOn(ToolBarFile->isVisible());
00640   actionViewStatusBar->setOn(statusBar()->isVisible());
00641 }
00642 
00644 void CrdView::saveSettings()
00646 {
00647   QSettings settings;
00648   settings.setPath(Version::appCompany, Version::appName.lower(), QSettings::User);
00649 
00650 #ifdef Q_OS_WIN32
00651   const QString prefix = "/crdview/";
00652 #else
00653   const QString prefix = "/" + Version::appName.lower() + "/crdview/";
00654 #endif
00655 
00656   settings.writeEntry(prefix + "geometry/x", pos().x());
00657   settings.writeEntry(prefix + "geometry/y", pos().y());
00658   settings.writeEntry(prefix + "geometry/width", width());
00659   settings.writeEntry(prefix + "geometry/height", height());
00660   QString toolbarsInfo;
00661   QTextStream stream(&toolbarsInfo, IO_WriteOnly);
00662   stream << *this;
00663   settings.writeEntry(prefix + "toolbars/other", toolbarsInfo);
00664   settings.writeEntry(prefix + "toolbars/statusbar", statusBar()->isVisible());
00665 }
00666 
00668 QString CrdView::actionText(const QString title, const QString brief, const QString details, const IconSets::IconSetID iconID)
00675 {
00676   QString result = "<big><b>" + title + "</b></big> <hr>"; // keep the space before <hr> until this bug is solved (never for Qt pre 3.3.6)
00677   if(iconID != IconSets::LastIcon)
00678     result += "<img source=\"" + IconSets::factoryName(iconID) + "\" align=\"right\"/>";
00679   result += "<br>" + brief;
00680   if(!details.isEmpty())
00681     result += "<br>" + details;
00682   return result;
00683 }
00684 

Generated on Fri May 19 14:31:54 2006 for Brabosphere by  doxygen 1.4.6-NO