popup layout code imroved/fixed - makes non-modal and CloseOnPressOutside working

This commit is contained in:
Uwe Rathmann 2025-01-21 15:21:03 +01:00
parent 925016bbc0
commit 344b5734e1
2 changed files with 51 additions and 40 deletions

View File

@ -29,15 +29,38 @@
namespace 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<const QskInputPanel*>();
auto r = qskItemGeometry( parentItem() );
r -= m;
r = qskConstrainedItemRect( item, r );
r += m;
setGeometry( r );
}
};
class Panel final : public QskInputPanel class Panel final : public QskInputPanel
{ {
public: public:
Panel( QQuickItem* parent = nullptr ) Panel( QQuickItem* parent = nullptr )
: QskInputPanel( parent ) : QskInputPanel( parent )
{ {
setAutoLayoutChildren( true );
setLayoutAlignmentHint( Qt::AlignHCenter | Qt::AlignBottom );
m_box = new QskInputPanelBox( this ); m_box = new QskInputPanelBox( this );
connect( m_box, &QskInputPanelBox::keySelected, connect( m_box, &QskInputPanelBox::keySelected,
@ -87,7 +110,7 @@ namespace
QPointer< QskInputPanel > panel; QPointer< QskInputPanel > panel;
// popup or window embedding the panel // popup or window embedding the panel
QPointer< QskPopup > popup; QPointer< Popup > popup;
QPointer< QskWindow > window; QPointer< QskWindow > window;
}; };
@ -252,38 +275,6 @@ class QskInputContext::PrivateData
return panel; 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 ) void closeChannel( Channel* channel )
{ {
if ( channel->popup ) if ( channel->popup )
@ -400,12 +391,21 @@ void QskInputContext::showPanel( const QQuickItem* item )
{ {
// The input panel is embedded in a top level window // 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(); QSize size = window->sizeConstraint();
if ( size.isEmpty() ) 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 ); size = QSize( 800, 240 );
} }
@ -420,14 +420,23 @@ void QskInputContext::showPanel( const QQuickItem* item )
{ {
// The input panel is embedded in a popup // 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->setPopupFlag( QskPopup::DeleteOnClose, true );
popup->setParentItem( item->window()->contentItem() ); popup->setParentItem( item->window()->contentItem() );
popup->setParent( this ); popup->setParent( this );
channel->popup = popup; channel->popup = popup;
panel->setParentItem( popup );
if ( panel->parent() == nullptr )
panel->setParent( popup );
popup->open(); popup->open();
} }

View File

@ -357,7 +357,9 @@ QskInputPanel::QskInputPanel( QQuickItem* parent )
, m_data( new PrivateData( this ) ) , m_data( new PrivateData( this ) )
{ {
setAutoLayoutChildren( true ); setAutoLayoutChildren( true );
initSizePolicy( QskSizePolicy::Expanding, QskSizePolicy::Constrained ); setLayoutAlignmentHint( Qt::AlignHCenter | Qt::AlignBottom );
initSizePolicy( QskSizePolicy::Ignored, QskSizePolicy::Constrained );
connect( this, &QskInputPanel::keySelected, connect( this, &QskInputPanel::keySelected,
this, &QskInputPanel::commitKey ); this, &QskInputPanel::commitKey );