layout code moved from QskInputPanel to QskBox

This commit is contained in:
Uwe Rathmann 2018-05-30 11:47:46 +02:00
parent 62de379794
commit b97a43008c
5 changed files with 76 additions and 37 deletions

View File

@ -43,4 +43,75 @@ QSizeF QskBox::contentsSizeHint() const
return outerBoxSize( Panel, size ).expandedTo( minSize ); return outerBoxSize( Panel, size ).expandedTo( minSize );
} }
qreal QskBox::heightForWidth( qreal width ) const
{
qreal height = -1;
if ( autoLayoutChildren() )
{
const auto children = childItems();
if ( !children.isEmpty() )
{
const auto margins = this->margins();
width -= margins.left() + margins.right();
const auto padding = innerPadding( Panel, QSizeF( width, width ) );
width -= padding.left() + padding.right();
for ( auto child : children )
{
if ( auto control = qobject_cast< const QskControl* >( child ) )
{
if ( !control->isTransparentForPositioner() )
height = qMax( height, control->heightForWidth( width ) );
}
}
if ( height >= 0 )
{
height += padding.top() + padding.bottom();
height += margins.top() + margins.bottom();
}
}
}
return height;
}
qreal QskBox::widthForHeight( qreal height ) const
{
qreal width = -1;
if ( autoLayoutChildren() )
{
const auto children = childItems();
if ( !children.isEmpty() )
{
const auto margins = this->margins();
height -= margins.top() + margins.bottom();
const auto padding = innerPadding( Panel, QSizeF( height, height ) );
height -= padding.top() + padding.bottom();
for ( auto child : children )
{
if ( auto control = qobject_cast< const QskControl* >( child ) )
{
if ( !control->isTransparentForPositioner() )
width = qMax( width, control->widthForHeight( height ) );
}
}
if ( width >= 0 )
{
width += padding.left() + padding.right();
width += margins.left() + margins.right();
}
}
}
return width;
}
#include "moc_QskBox.cpp" #include "moc_QskBox.cpp"

View File

@ -22,6 +22,9 @@ public:
virtual QRectF layoutRect() const override; virtual QRectF layoutRect() const override;
virtual QSizeF contentsSizeHint() const override; virtual QSizeF contentsSizeHint() const override;
virtual qreal heightForWidth( qreal width ) const override;
virtual qreal widthForHeight( qreal height ) const override;
}; };
#endif #endif

View File

@ -637,36 +637,4 @@ void QskInputPanel::keyReleaseEvent( QKeyEvent* event )
return Inherited::keyReleaseEvent( event ); return Inherited::keyReleaseEvent( event );
} }
qreal QskInputPanel::heightForWidth( qreal width ) const
{
const auto margins = this->margins();
width -= margins.left() + margins.right();
const auto padding = innerPadding( Panel, QSizeF( width, width ) );
width -= padding.left() + padding.right();
qreal height = m_data->layout->heightForWidth( width );
height += padding.top() + padding.bottom();
height += margins.top() + margins.bottom();
return height;
}
qreal QskInputPanel::widthForHeight( qreal height ) const
{
const auto margins = this->margins();
height -= margins.top() + margins.bottom();
const auto padding = innerPadding( Panel, QSizeF( height, height ) );
height -= padding.top() + padding.bottom();
qreal width = m_data->keyboard->widthForHeight( height );
width += padding.left() + padding.right();
width += margins.left() + margins.right();
return width;
}
#include "moc_QskInputPanel.cpp" #include "moc_QskInputPanel.cpp"

View File

@ -41,9 +41,6 @@ public:
bool hasInputProxy() const; bool hasInputProxy() const;
QString inputPrompt() const; QString inputPrompt() const;
virtual qreal heightForWidth( qreal width ) const override;
virtual qreal widthForHeight( qreal height ) const override;
virtual QskAspect::Subcontrol effectiveSubcontrol( virtual QskAspect::Subcontrol effectiveSubcontrol(
QskAspect::Subcontrol ) const override; QskAspect::Subcontrol ) const override;

View File

@ -37,6 +37,7 @@ public:
virtual qreal heightForWidth( qreal width ) const override; virtual qreal heightForWidth( qreal width ) const override;
virtual qreal widthForHeight( qreal height ) const override; virtual qreal widthForHeight( qreal height ) const override;
virtual QSizeF contentsSizeHint() const override; virtual QSizeF contentsSizeHint() const override;
virtual QskAspect::Subcontrol effectiveSubcontrol( virtual QskAspect::Subcontrol effectiveSubcontrol(
@ -49,10 +50,9 @@ Q_SIGNALS:
protected: protected:
virtual void updateLayout() override; virtual void updateLayout() override;
private Q_SLOTS: private:
void buttonPressed(); void buttonPressed();
private:
class PrivateData; class PrivateData;
std::unique_ptr< PrivateData > m_data; std::unique_ptr< PrivateData > m_data;
}; };