From 344b5734e1f4e9a1b219a44cf6f3b5d3d7d6dabe Mon Sep 17 00:00:00 2001 From: Uwe Rathmann Date: Tue, 21 Jan 2025 15:21:03 +0100 Subject: [PATCH] popup layout code imroved/fixed - makes non-modal and CloseOnPressOutside working --- src/inputpanel/QskInputContext.cpp | 87 ++++++++++++++++-------------- src/inputpanel/QskInputPanel.cpp | 4 +- 2 files changed, 51 insertions(+), 40 deletions(-) diff --git a/src/inputpanel/QskInputContext.cpp b/src/inputpanel/QskInputContext.cpp index ec3aa01b..e859cc0e 100644 --- a/src/inputpanel/QskInputContext.cpp +++ b/src/inputpanel/QskInputContext.cpp @@ -29,15 +29,38 @@ namespace { + class Popup : public QskPopup + { + using Inherited = QskPopup; + + public: + Popup() + { + setPolishOnResize( true ); + setPolishOnParentResize( true ); + } + + protected: + void updateLayout() override + { + const auto m = margins(); + const auto item = findChild(); + + auto r = qskItemGeometry( parentItem() ); + r -= m; + r = qskConstrainedItemRect( item, r ); + r += m; + + setGeometry( r ); + } + }; + class Panel final : public QskInputPanel { public: Panel( QQuickItem* parent = nullptr ) : QskInputPanel( parent ) { - setAutoLayoutChildren( true ); - setLayoutAlignmentHint( Qt::AlignHCenter | Qt::AlignBottom ); - m_box = new QskInputPanelBox( this ); connect( m_box, &QskInputPanelBox::keySelected, @@ -87,7 +110,7 @@ namespace QPointer< QskInputPanel > panel; // popup or window embedding the panel - QPointer< QskPopup > popup; + QPointer< Popup > popup; QPointer< QskWindow > window; }; @@ -252,38 +275,6 @@ class QskInputContext::PrivateData return panel; } - inline QskPopup* createPopup( QskInputPanel* panel ) const - { - auto popup = new QskPopup(); - - popup->setAutoLayoutChildren( true ); - popup->setPlacementPolicy( QskPlacementPolicy() ); - popup->setMargins( 5 ); - popup->setModal( true ); - - panel->setParentItem( popup ); - if ( panel->parent() == nullptr ) - panel->setParent( popup ); - - return popup; - } - - inline QskWindow* createWindow( QskInputPanel* panel ) const - { - auto window = new QskWindow(); - - window->setFlags( window->flags() & Qt::Dialog ); - // window->setModality( Qt::ApplicationModal ); - window->setAutoLayoutChildren( true ); -#if 0 - window->setFlags( Qt::Tool | Qt::WindowDoesNotAcceptFocus ); -#endif - - panel->setParentItem( window->contentItem() ); - - return window; - } - void closeChannel( Channel* channel ) { if ( channel->popup ) @@ -400,12 +391,21 @@ void QskInputContext::showPanel( const QQuickItem* item ) { // The input panel is embedded in a top level window - auto window = m_data->createWindow( panel ); + auto window = new QskWindow(); + + window->setFlags( window->flags() & Qt::Dialog ); + // window->setModality( Qt::ApplicationModal ); + window->setAutoLayoutChildren( true ); +#if 0 + window->setFlags( Qt::Tool | Qt::WindowDoesNotAcceptFocus ); +#endif + + panel->setParentItem( window->contentItem() ); QSize size = window->sizeConstraint(); if ( size.isEmpty() ) { - // no idea, may be something based on the screen size + // no idea, maybe something based on the screen size size = QSize( 800, 240 ); } @@ -420,14 +420,23 @@ void QskInputContext::showPanel( const QQuickItem* item ) { // The input panel is embedded in a popup - auto popup = m_data->createPopup( panel ); + auto popup = new Popup(); + + popup->setAutoLayoutChildren( true ); + popup->setMargins( 5 ); + popup->setModal( true ); popup->setPopupFlag( QskPopup::DeleteOnClose, true ); + popup->setParentItem( item->window()->contentItem() ); popup->setParent( this ); channel->popup = popup; + panel->setParentItem( popup ); + if ( panel->parent() == nullptr ) + panel->setParent( popup ); + popup->open(); } diff --git a/src/inputpanel/QskInputPanel.cpp b/src/inputpanel/QskInputPanel.cpp index 9625873b..d2d83442 100644 --- a/src/inputpanel/QskInputPanel.cpp +++ b/src/inputpanel/QskInputPanel.cpp @@ -357,7 +357,9 @@ QskInputPanel::QskInputPanel( QQuickItem* parent ) , m_data( new PrivateData( this ) ) { setAutoLayoutChildren( true ); - initSizePolicy( QskSizePolicy::Expanding, QskSizePolicy::Constrained ); + setLayoutAlignmentHint( Qt::AlignHCenter | Qt::AlignBottom ); + + initSizePolicy( QskSizePolicy::Ignored, QskSizePolicy::Constrained ); connect( this, &QskInputPanel::keySelected, this, &QskInputPanel::commitKey );