{
m_isLeftButtonPressed = false;
m_movedSinceLeftButtonPressed = false;
+ m_clickedAtom = 0;
m_molecule = 0;
m_detail = 0;
m_displayList = 0;
glCallList( m_displayList );
#endif
- renderSelection();
+ renderHighlighting();
if( renderMode == GL_SELECT )
{
}
}
-void KalziumGLWidget::renderSelection()
+void KalziumGLWidget::renderHighlighting()
{
- if( ! m_selectedAtoms.count() ) return;
-
- Color( 0.2, 0.7, 1.0, 0.7 ).applyAsMaterials();
glEnable( GL_BLEND );
- foreach(OpenBabel::OBAtom* atom, m_selectedAtoms)
+
+ if( m_clickedAtom )
{
- glLoadName( atom->GetIdx() );
- m_sphere.draw( atom->GetVector(),
- 0.18 + m_molStyle.getAtomRadius( atom ) );
+ Color( 0.6, 0.0, 1.0, 0.7 ).applyAsMaterials();
+ glLoadName( m_clickedAtom->GetIdx() );
+ m_sphere.draw( m_clickedAtom->GetVector(),
+ 0.18 + m_molStyle.getAtomRadius( m_clickedAtom ) );
}
+
+ if( m_selectedAtoms.count() )
+ {
+ Color( 0.0, 0.7, 1.0, 0.7 ).applyAsMaterials();
+ glEnable( GL_BLEND );
+ foreach(OpenBabel::OBAtom* atom, m_selectedAtoms)
+ {
+ if( atom != m_clickedAtom )
+ {
+ glLoadName( atom->GetIdx() );
+ m_sphere.draw( atom->GetVector(),
+ 0.18 + m_molStyle.getAtomRadius(
+ atom ) );
+ }
+ }
+ }
+
glDisable( GL_BLEND );
}
m_movedSinceLeftButtonPressed = false;
m_lastDraggingPosition = event->pos ();
m_initialDraggingPosition = event->pos ();
-
+ computeClickedAtom( event->pos () );
+ if( m_clickedAtom )
+ kDebug()<<m_clickedAtom->GetIdx()<<endl;
+ updateGL();
}
}
{
m_isLeftButtonPressed = false;
- if( ! m_movedSinceLeftButtonPressed )
+ if( m_clickedAtom && ! m_movedSinceLeftButtonPressed )
{
- OBAtom *atomUnderMouse =
- getAtomUnderMouse( event->pos() );
- if( atomUnderMouse )
+ if( m_selectedAtoms.contains( m_clickedAtom ) )
{
- if( m_selectedAtoms.contains( atomUnderMouse ) )
- {
- m_selectedAtoms.removeAll(
- atomUnderMouse );
- }
- else m_selectedAtoms.append( atomUnderMouse );
+ m_selectedAtoms.removeAll(
+ m_clickedAtom );
}
+ else m_selectedAtoms.append( m_clickedAtom );
updateGL();
}
+ m_clickedAtom = 0;
}
}
m_molecule = molecule;
m_haveToRecompileDisplayList = true;
m_selectedAtoms.clear();
+ m_clickedAtom = 0;
prepareMoleculeData();
setupObjects();
updateGL();
updateGL();
}
-OpenBabel::OBAtom * KalziumGLWidget::getAtomUnderMouse(
+void KalziumGLWidget::computeClickedAtom(
const QPoint & mousePosition )
{
- if( ! m_molecule ) return 0;
+ m_clickedAtom = 0;
+ if( ! m_molecule ) return;
const GLsizei selectionBufferSize = 1024;
GLuint selectionBuffer[selectionBufferSize];
minZ = 0xffffffff,
*ptrNames,
numberOfNames = 0;
- printf ("hits = %d\n", numberOfHits);
for( i = 0; i < numberOfHits; i++ )
{
names = *ptr;
}
for( j = 0, ptr = ptrNames; j < numberOfNames; j++, ptr++ )
- if( *ptr ) return m_molecule->GetAtom( *ptr );
-
- return 0;
+ if( *ptr )
+ {
+ m_clickedAtom = m_molecule->GetAtom( *ptr );
+ return;
+ }
}
#include "kalziumglwidget.moc"
QPoint m_lastDraggingPosition;
QPoint m_initialDraggingPosition;
+ OpenBabel::OBAtom *m_clickedAtom;
+
/**
* Stores the rotation that is applied to the model.
*/
/**
* The molecule which is displayed
*/
- OpenBabel::OBMol* m_molecule;
+ OpenBabel::OBMol *m_molecule;
/**
* approximate radius of the molecule,
virtual void paintGL();
virtual void renderAtoms();
virtual void renderBonds();
- virtual void renderSelection();
+ virtual void renderHighlighting();
virtual void FPSCounter();
/**
*/
void setMolStyle( int style );
- OpenBabel::OBAtom * getAtomUnderMouse(
- const QPoint & mousePosition );
+ void computeClickedAtom( const QPoint & mousePosition );
};
#endif // KALZIUMGLWIDGET_H