From b97a43008ca07272ca246e6eeff6c9eb27044314 Mon Sep 17 00:00:00 2001 From: Uwe Rathmann Date: Wed, 30 May 2018 11:47:46 +0200 Subject: [PATCH] layout code moved from QskInputPanel to QskBox --- src/controls/QskBox.cpp | 71 +++++++++++++++++++++++++++++ src/controls/QskBox.h | 3 ++ src/inputpanel/QskInputPanel.cpp | 32 ------------- src/inputpanel/QskInputPanel.h | 3 -- src/inputpanel/QskVirtualKeyboard.h | 4 +- 5 files changed, 76 insertions(+), 37 deletions(-) diff --git a/src/controls/QskBox.cpp b/src/controls/QskBox.cpp index 0af35c43..5f0015b7 100644 --- a/src/controls/QskBox.cpp +++ b/src/controls/QskBox.cpp @@ -43,4 +43,75 @@ QSizeF QskBox::contentsSizeHint() const 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" diff --git a/src/controls/QskBox.h b/src/controls/QskBox.h index 4ac31754..7fae8f62 100644 --- a/src/controls/QskBox.h +++ b/src/controls/QskBox.h @@ -22,6 +22,9 @@ public: virtual QRectF layoutRect() const override; virtual QSizeF contentsSizeHint() const override; + + virtual qreal heightForWidth( qreal width ) const override; + virtual qreal widthForHeight( qreal height ) const override; }; #endif diff --git a/src/inputpanel/QskInputPanel.cpp b/src/inputpanel/QskInputPanel.cpp index 12d19a11..7246f073 100644 --- a/src/inputpanel/QskInputPanel.cpp +++ b/src/inputpanel/QskInputPanel.cpp @@ -637,36 +637,4 @@ void QskInputPanel::keyReleaseEvent( QKeyEvent* 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" diff --git a/src/inputpanel/QskInputPanel.h b/src/inputpanel/QskInputPanel.h index 0054bfad..f675aa21 100644 --- a/src/inputpanel/QskInputPanel.h +++ b/src/inputpanel/QskInputPanel.h @@ -41,9 +41,6 @@ public: bool hasInputProxy() const; QString inputPrompt() const; - virtual qreal heightForWidth( qreal width ) const override; - virtual qreal widthForHeight( qreal height ) const override; - virtual QskAspect::Subcontrol effectiveSubcontrol( QskAspect::Subcontrol ) const override; diff --git a/src/inputpanel/QskVirtualKeyboard.h b/src/inputpanel/QskVirtualKeyboard.h index 373c189b..c26dc054 100644 --- a/src/inputpanel/QskVirtualKeyboard.h +++ b/src/inputpanel/QskVirtualKeyboard.h @@ -37,6 +37,7 @@ public: virtual qreal heightForWidth( qreal width ) const override; virtual qreal widthForHeight( qreal height ) const override; + virtual QSizeF contentsSizeHint() const override; virtual QskAspect::Subcontrol effectiveSubcontrol( @@ -49,10 +50,9 @@ Q_SIGNALS: protected: virtual void updateLayout() override; -private Q_SLOTS: +private: void buttonPressed(); -private: class PrivateData; std::unique_ptr< PrivateData > m_data; };