kalzium
kalziumglpart.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #include "kalziumglpart.h"
00015
00016 #include <kparts/genericfactory.h>
00017
00018
00019 #include <avogadro/primitive.h>
00020 #include <avogadro/toolgroup.h>
00021
00022 #include "openbabel2wrapper.h"
00023
00024 KalziumGLWidget::KalziumGLWidget(QWidget *parent) : Avogadro::GLWidget(parent)
00025 {
00026
00027
00028 lc_numeric = QString::fromAscii(setlocale(LC_NUMERIC, 0));
00029 setlocale(LC_NUMERIC, "C");
00030
00031
00032 setContextMenuPolicy( Qt::PreventContextMenu );
00033
00034 Avogadro::ToolGroup* tools = new Avogadro::ToolGroup(this);
00035 tools->load();
00036 const QList<Avogadro::Tool *> toolList = tools->tools();
00037 foreach( Avogadro::Tool *tool, toolList )
00038 {
00039 if (tool->name() == "Navigate")
00040 tools->setActiveTool(tool);
00041 }
00042 setToolGroup(tools);
00043 }
00044
00045 KalziumGLWidget::~KalziumGLWidget()
00046 {
00047
00048 setlocale(LC_NUMERIC, lc_numeric.toAscii());
00049 }
00050
00051 void KalziumGLWidget::setStyle( int style )
00052 {
00053 foreach( Avogadro::Engine *engine, engines() )
00054 {
00055 if( engine->name() != "Label" ) {
00056 engine->setEnabled(false);
00057 }
00058
00059 if( ( style == 0 && engine->name() == "Dynamic Ball and Stick" )
00060 || ( style == 1 && engine->name() == "Stick" )
00061 || ( style == 2 && engine->name() == "Sphere" )
00062 || ( style == 3 && engine->name() == "Wireframe" ) ) {
00063 engine->setEnabled(true);
00064 setRenderingEngine(engine);
00065 }
00066 }
00067 update();
00068 }
00069
00070 typedef KParts::GenericFactory<KalziumGLPart> KalziumGLPartFactory;
00071
00072 K_EXPORT_COMPONENT_FACTORY (libkalziumglpart, KalziumGLPartFactory)
00073
00074 KalziumGLPart::KalziumGLPart(QWidget* parentWidget, QObject* parent, const QStringList& args)
00075 {
00076 Q_UNUSED(parent);
00077 Q_UNUSED(parentWidget);
00078 Q_UNUSED(args);
00079 kDebug() << "KalziumGLPart::KalziumGLPart()";
00080
00081
00082 QGLFormat defFormat = QGLFormat::defaultFormat();
00083 defFormat.setSampleBuffers(true);
00084 QGLFormat::setDefaultFormat(defFormat);
00085
00086 m_widget = new KalziumGLWidget();
00087 m_widget->setObjectName("KalziumGLWidget-KPart");
00088 }
00089
00090 KalziumGLPart::~KalziumGLPart()
00091 {
00092 delete m_widget;
00093 kDebug() << "KalziumGLPart::~KalziumGLPart()";
00094 }
00095
00096 KAboutData *KalziumGLPart::createAboutData()
00097 {
00098 KAboutData* aboutData = new KAboutData( "kalzium", 0, ki18n("KalziumGLPart"),
00099 "1.1.1", ki18n("A cool thing"),
00100 KAboutData::License_GPL,
00101 ki18n("(c) 2006, Carsten Niehaus"), KLocalizedString(), "http://edu.kde.org/kalzium/index.php",
00102 "kalzium@kde.org");
00103 aboutData->addAuthor(ki18n("Carsten Niehaus."),KLocalizedString(), "cniehaus@kde.org");
00104
00105 return aboutData;
00106 }
00107
00108 bool KalziumGLPart::openFile()
00109 {
00110 Avogadro::Molecule* mol = OpenBabel2Wrapper::readMolecule( url().path() );
00111
00112 m_widget->setMolecule( mol );
00113 m_widget->update();
00114 return true;
00115 }
00116
00117 #include "kalziumglpart.moc"