inputpanel example with 2 windows

This commit is contained in:
Uwe Rathmann 2018-06-08 12:54:00 +02:00
parent 87f4d718c5
commit 84f196dcc4

View File

@ -148,6 +148,8 @@ public:
class LocaleListView : public QskListView class LocaleListView : public QskListView
{ {
Q_OBJECT
public: public:
LocaleListView( QQuickItem* parentItem = nullptr ): LocaleListView( QQuickItem* parentItem = nullptr ):
QskListView( parentItem ), QskListView( parentItem ),
@ -180,6 +182,9 @@ public:
setPreferredWidth( columnWidth( 0 ) + 20 ); setPreferredWidth( columnWidth( 0 ) + 20 );
setScrollableSize( QSizeF( columnWidth( 0 ), rowCount() * rowHeight() ) ); setScrollableSize( QSizeF( columnWidth( 0 ), rowCount() * rowHeight() ) );
connect( this, &QskListView::selectedRowChanged,
[ this ]( int row ) { Q_EMIT selected( localeAt( row ) ); } );
} }
virtual int rowCount() const override final virtual int rowCount() const override final
@ -233,6 +238,9 @@ public:
return QLocale(); return QLocale();
} }
Q_SIGNALS:
void selected( const QLocale& );
private: private:
inline void append( const QLocale& locale ) inline void append( const QLocale& locale )
{ {
@ -243,6 +251,37 @@ private:
mutable qreal m_maxWidth; mutable qreal m_maxWidth;
}; };
class Window : public QskWindow
{
public:
Window()
{
populate();
}
void populate()
{
auto box = new QskLinearBox( Qt::Horizontal );
box->setSpacing( 10 );
box->setMargins( 20 );
auto listView = new LocaleListView( box );
auto inputBox = new InputBox( box );
/*
Disable Qt::ClickFocus, so that the input panel stays open
when selecting a different locale
*/
listView->setFocusPolicy( Qt::TabFocus );
connect( listView, &LocaleListView::selected,
inputBox, &InputBox::setLocale );
addItem( box );
addItem( new QskFocusIndicator() );
}
};
int main( int argc, char* argv[] ) int main( int argc, char* argv[] )
{ {
#ifdef ITEM_STATISTICS #ifdef ITEM_STATISTICS
@ -265,32 +304,23 @@ int main( int argc, char* argv[] )
#endif #endif
#if 0 #if 0
QskInputContext::setInputManager( ... ); QskInputContext::setInputEngine( ... );
#endif #endif
auto box = new QskLinearBox( Qt::Horizontal ); Window window;
box->setSpacing( 10 );
box->setMargins( 20 );
auto listView = new LocaleListView( box );
auto inputBox = new InputBox( box );
/*
Disable Qt::ClickFocus, so that the input panel stays open
when selecting a different locale
*/
listView->setFocusPolicy( Qt::TabFocus );
QObject::connect( listView, &QskListView::selectedRowChanged,
inputBox, [ = ]( int row ) { inputBox->setLocale( listView->localeAt( row ) ); } );
QskWindow window;
window.setColor( "PapayaWhip" ); window.setColor( "PapayaWhip" );
window.addItem( box );
window.addItem( new QskFocusIndicator() );
window.resize( 600, 600 ); window.resize( 600, 600 );
window.show(); window.show();
#if 0
Window window2;
window2.setColor( "Pink" );
window2.setX( window.x() + 100 );
window2.resize( 600, 600 );
window2.show();
#endif
return app.exec(); return app.exec();
} }
#include "main.moc"