layout code with transformations

This commit is contained in:
Uwe Rathmann 2018-04-06 18:07:12 +02:00
parent 07d28529be
commit 546044f916
2 changed files with 22 additions and 12 deletions

View File

@ -587,8 +587,8 @@ void QskSquiekSkin::initInputPanelHints()
const ColorPalette& pal = m_data->palette; const ColorPalette& pal = m_data->palette;
// key panel
setMargins( Q::Panel | Padding, 5 ); setMargins( Q::Panel | Padding, 5 );
setMetric( Q::Panel | Spacing, 5 );
setPanel( Q::Panel, Raised ); setPanel( Q::Panel, Raised );
setButton( Q::ButtonPanel, Raised ); setButton( Q::ButtonPanel, Raised );

View File

@ -299,23 +299,33 @@ void QskVirtualKeyboard::updateLayout()
if( r.isEmpty() ) if( r.isEmpty() )
return; return;
QTransform transform; const auto spacing = metric( Panel | QskAspect::Spacing );
transform.translate( r.top(), r.left() ); const auto totalVSpacing = ( RowCount - 1 ) * spacing;
transform.scale( r.width(), r.height() );
const auto keyHeight = 1.0f / RowCount; const auto keyHeight = ( r.height() - totalVSpacing ) / RowCount;
const auto& keyCodes = ( *m_data->currentLayout )[ m_data->mode ]; const auto& keyCodes = ( *m_data->currentLayout )[ m_data->mode ];
qreal yPos = 0; qreal yPos = r.top();
for( int row = 0; row < RowCount; row++ ) for( int row = 0; row < RowCount; row++ )
{ {
const auto& keys = keyCodes.data[ row ]; const auto& keys = keyCodes.data[ row ];
const auto baseKeyWidth = 1.0 / qskRowStretch( keys ); #if 1
// there should be a better way
qreal xPos = 0; auto totalHSpacing = -spacing;
if ( spacing )
{
for ( int col = 0; col < KeyCount; col++ )
{
if ( keys[ col ] != Qt::Key( 0 ) )
totalHSpacing += spacing;
}
}
#endif
const auto baseKeyWidth = ( r.width() - totalHSpacing ) / qskRowStretch( keys );
qreal xPos = r.left();
for ( int col = 0; col < KeyCount; col++ ) for ( int col = 0; col < KeyCount; col++ )
{ {
@ -330,15 +340,15 @@ void QskVirtualKeyboard::updateLayout()
const QRectF rect( xPos, yPos, keyWidth, keyHeight ); const QRectF rect( xPos, yPos, keyWidth, keyHeight );
button->setGeometry( transform.mapRect( rect ) ); button->setGeometry( rect );
button->setAutoRepeat( qskIsAutorepeat( key ) ); button->setAutoRepeat( qskIsAutorepeat( key ) );
button->setText( qskTextForKey( key ) ); button->setText( qskTextForKey( key ) );
xPos += keyWidth; xPos += keyWidth + spacing;
} }
} }
yPos += keyHeight; yPos += keyHeight + spacing;
} }
} }