Création d'un compte pour un collaborateur extérieur au laboratoire depuis l'intranet ICube : https://intranet.icube.unistra.fr/fr/labs/member/profile

Commit 85a424a6 authored by Frédéric Larue's avatar Frédéric Larue
Browse files

Modification of the renderText() function of GLViewer class in order to...

Modification of the renderText() function of GLViewer class in order to account for text alignment and new line characters.
parent c5bac540
......@@ -1020,18 +1020,16 @@ void GLViewer::paintGL()
QString label = m_BelowCursor->displayable->label();
QFont f( font().family(), 10, QFont::Bold );
QFontMetrics fm( f );
textY -= 0.5*fm.height();
textX -= 0.5*fm.width( label );
Qt::Alignment align = static_cast<Qt::Alignment>( Qt::AlignHCenter | Qt::AlignCenter );
glColor3ub( 220, 220, 220 );
renderText( textX-1, textY-1, label, f );
renderText( textX-1, textY+1, label, f );
renderText( textX+1, textY-1, label, f );
renderText( textX+1, textY+1, label, f );
renderText( textX-1, textY-1, label, f, align );
renderText( textX-1, textY+1, label, f, align );
renderText( textX+1, textY-1, label, f, align );
renderText( textX+1, textY+1, label, f, align );
glColor3ub( 64, 64, 64 );
renderText( textX, textY, label, f );
renderText( textX, textY, label, f, align );
}
// Display the selection tool, if selection mode is enabled.
......@@ -1155,15 +1153,15 @@ void GLViewer::displayLabel( DisplayableInterface *d )
if( imgName.length() > 0 )
{
int textX = bottomLeft.x() + 4;
int textY = bottomLeft.y() - fm.descent() - 2;
int textY = bottomLeft.y() - 2;
glColor3ub( 220, 220, 220 );
renderText( textX-1, textY-1, imgName, f );
renderText( textX-1, textY+1, imgName, f );
renderText( textX+1, textY-1, imgName, f );
renderText( textX+1, textY+1, imgName, f );
renderText( textX-1, textY-1, imgName, f, Qt::AlignTop );
renderText( textX-1, textY+1, imgName, f, Qt::AlignTop );
renderText( textX+1, textY-1, imgName, f, Qt::AlignTop );
renderText( textX+1, textY+1, imgName, f, Qt::AlignTop );
glColor3ub( 64, 64, 64 );
renderText( textX, textY, imgName, f );
renderText( textX, textY, imgName, f, Qt::AlignTop );
}
}
}
......@@ -1415,8 +1413,23 @@ void GLViewer::renderCoords( double x, double y, double z, double *screenX, doub
}
void GLViewer::renderText( double x, double y, const QString &text, const QFont &font )
void GLViewer::renderText( double x, double y, const QString &text, const QFont &font, Qt::Alignment align )
{
QFontMetrics fm( font );
// Extract lines from the input strings.
QStringList textLines;
int beg = 0, end;
while( (end = text.indexOf('\n',beg)) >= 0 )
{
textLines.push_back( text.mid(beg,end-beg) );
beg = end + 1;
}
textLines.push_back( (beg==0)? text : text.mid(beg) );
// Save OpenGL states.
GLint buffer;
......@@ -1441,11 +1454,25 @@ void GLViewer::renderText( double x, double y, const QString &text, const QFont
// Paint text.
if( align & Qt::AlignTop )
y -= (textLines.size()-1) * fm.height() + fm.descent();
else if( align & Qt::AlignCenter )
y -= ((textLines.size()-2) * fm.height())/2/* + fm.descent()*/;
QPainter painter;
painter.begin( this );
painter.setPen( fontColor );
painter.setFont( font );
painter.drawText( x, y, text );
for( auto &l : textLines )
{
if( align & Qt::AlignRight )
painter.drawText( x - fm.width(l), y, l );
else if( align & Qt::AlignHCenter )
painter.drawText( x - fm.width(l)/2, y, l );
else
painter.drawText( x, y, l );
y += fm.height();
}
painter.end();
// Restore OpenGL states.
......@@ -1458,11 +1485,11 @@ void GLViewer::renderText( double x, double y, const QString &text, const QFont
}
void GLViewer::renderText( double x, double y, double z, const QString &text, const QFont &font )
void GLViewer::renderText( double x, double y, double z, const QString &text, const QFont &font, Qt::Alignment align )
{
double screenX, screenY;
renderCoords( x, y, z, &screenX, &screenY );
renderText( screenX, screenY, text, font );
renderText( screenX, screenY, text, font, align );
}
......
......@@ -311,8 +311,8 @@ public:
void processSelection( GenericUIData *m, BaseSelectionProcessor &proc );
void renderCoords( double x, double y, double z, double *screenX, double *screenY );
void renderText( double x, double y, const QString &text, const QFont &font = QFont() );
void renderText( double x, double y, double z, const QString &text, const QFont &font = QFont() );
void renderText( double x, double y, const QString &text, const QFont &font = QFont(), Qt::Alignment align = Qt::AlignLeft );
void renderText( double x, double y, double z, const QString &text, const QFont &font = QFont(), Qt::Alignment align = Qt::AlignLeft );
bool imageOfCurrentDisplay( const GenericUIData *m, QImage &renderResult );
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment