2017-07-21 18:21:34 +02:00
|
|
|
/******************************************************************************
|
|
|
|
* QSkinny - Copyright (C) 2016 Uwe Rathmann
|
|
|
|
* This file may be used under the terms of the 3-clause BSD License
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
#include <SkinnyFont.h>
|
|
|
|
#include <SkinnyShortcut.h>
|
|
|
|
|
2017-07-28 14:47:11 +02:00
|
|
|
#include <QskInputPanel.h>
|
|
|
|
#include <QskDialog.h>
|
|
|
|
#include <QskFocusIndicator.h>
|
|
|
|
#include <QskLinearBox.h>
|
2017-07-28 16:16:13 +02:00
|
|
|
#include <QskListView.h>
|
2017-07-28 14:47:11 +02:00
|
|
|
|
|
|
|
#include <QskWindow.h>
|
|
|
|
#include <QskSetup.h>
|
2017-07-28 16:16:13 +02:00
|
|
|
#include <QskAspect.h>
|
2017-07-28 14:47:11 +02:00
|
|
|
|
2017-07-21 18:21:34 +02:00
|
|
|
#include <QskObjectCounter.h>
|
|
|
|
|
|
|
|
#include <QGuiApplication>
|
2017-07-28 16:16:13 +02:00
|
|
|
#include <QFontMetricsF>
|
2017-07-21 18:21:34 +02:00
|
|
|
|
2017-10-25 13:40:32 +02:00
|
|
|
#include <private/qquicktextinput_p.h>
|
|
|
|
|
2017-07-28 13:06:59 +02:00
|
|
|
#define STRINGIFY(x) #x
|
|
|
|
#define STRING(x) STRINGIFY(x)
|
|
|
|
|
2017-07-28 14:47:11 +02:00
|
|
|
#define LOCAL_PANEL 1
|
|
|
|
|
|
|
|
class InputBox : public QskLinearBox
|
|
|
|
{
|
|
|
|
public:
|
2017-07-28 16:16:13 +02:00
|
|
|
InputBox( QQuickItem* parentItem = nullptr ):
|
2017-07-28 14:47:11 +02:00
|
|
|
QskLinearBox( Qt::Vertical, parentItem )
|
|
|
|
{
|
|
|
|
setDefaultAlignment( Qt::AlignHCenter | Qt::AlignTop );
|
|
|
|
|
|
|
|
setMargins( 10 );
|
|
|
|
setSpacing( 10 );
|
|
|
|
|
2017-10-25 13:40:32 +02:00
|
|
|
auto* textInput = new QQuickTextInput( this );
|
2017-10-29 14:00:10 +01:00
|
|
|
textInput->setActiveFocusOnTab( true );
|
2017-10-25 13:40:32 +02:00
|
|
|
textInput->setText( "I am a line edit. Press and edit Me." );
|
2017-07-28 14:47:11 +02:00
|
|
|
|
|
|
|
#if LOCAL_PANEL
|
|
|
|
auto* inputPanel = new QskInputPanel( this );
|
|
|
|
|
|
|
|
/*
|
|
|
|
QskInputContext is connected to QskSetup::inputPanelChanged,
|
|
|
|
making it the system input. If no input panel has been assigned
|
|
|
|
QskInputContext would create a window or subwindow on the fly.
|
|
|
|
*/
|
|
|
|
qskSetup->setInputPanel( inputPanel );
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-07-28 16:16:13 +02:00
|
|
|
class LocaleListView : public QskListView
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
LocaleListView( QQuickItem* parentItem = nullptr ):
|
|
|
|
QskListView( parentItem ),
|
|
|
|
m_maxWidth( 0.0 )
|
|
|
|
{
|
|
|
|
append( QLocale::Bulgarian, QStringLiteral( "български език" ) );
|
|
|
|
append( QLocale::Czech, QStringLiteral( "Čeština" ) );
|
|
|
|
append( QLocale::German, QStringLiteral( "Deutsch" ) );
|
|
|
|
append( QLocale::Danish, QStringLiteral( "Dansk" ) );
|
|
|
|
|
|
|
|
append( QLocale( QLocale::English, QLocale::UnitedStates ), QStringLiteral( "English (US)" ) );
|
|
|
|
append( QLocale( QLocale::English, QLocale::UnitedKingdom ), QStringLiteral( "English (UK)" ) );
|
|
|
|
|
|
|
|
append( QLocale::Spanish, QStringLiteral( "Español" ) );
|
|
|
|
append( QLocale::Finnish, QStringLiteral( "Suomi" ) );
|
|
|
|
append( QLocale::French, QStringLiteral( "Français" ) );
|
|
|
|
append( QLocale::Hungarian, QStringLiteral( "Magyar" ) );
|
|
|
|
append( QLocale::Italian, QStringLiteral( "Italiano" ) );
|
|
|
|
append( QLocale::Japanese, QStringLiteral( "日本語" ) );
|
|
|
|
append( QLocale::Latvian, QStringLiteral( "Latviešu" ) );
|
|
|
|
append( QLocale::Lithuanian, QStringLiteral( "Lietuvių") );
|
|
|
|
append( QLocale::Dutch, QStringLiteral( "Nederlands" ) );
|
|
|
|
append( QLocale::Portuguese, QStringLiteral( "Português" ) );
|
|
|
|
append( QLocale::Romanian, QStringLiteral( "Română" ) );
|
|
|
|
append( QLocale::Russian, QStringLiteral( "Русский" ) );
|
|
|
|
append( QLocale::Slovenian, QStringLiteral( "Slovenščina" ) );
|
|
|
|
append( QLocale::Slovak, QStringLiteral( "Slovenčina" ) );
|
|
|
|
append( QLocale::Turkish, QStringLiteral( "Türkçe" ) );
|
|
|
|
append( QLocale::Chinese, QStringLiteral( "中文" ) );
|
|
|
|
|
|
|
|
setSizePolicy( Qt::Horizontal, QskSizePolicy::Fixed );
|
|
|
|
setPreferredWidth( columnWidth( 0 ) + 20 );
|
|
|
|
|
|
|
|
setScrollableSize( QSizeF( columnWidth( 0 ), rowCount() * rowHeight() ) );
|
|
|
|
|
|
|
|
// TODO:
|
|
|
|
// 1) changing the keyboard layouts does not yet work
|
|
|
|
// 2) QskInputPanel does not work properly in the threaded environment
|
|
|
|
#if 1
|
|
|
|
connect( this, &QskListView::selectedRowChanged,
|
|
|
|
this, [ = ] { qskSetup->inputPanel()->setLocale( m_values[selectedRow()].second ); } );
|
|
|
|
#else
|
|
|
|
connect( this, &QskListView::selectedRowChanged,
|
|
|
|
this, [ = ] { QLocale::setDefault( m_values[selectedRow()].second ); } );
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual int rowCount() const override final
|
|
|
|
{
|
|
|
|
return m_values.count();
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual int columnCount() const override final
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual qreal columnWidth( int ) const override
|
|
|
|
{
|
|
|
|
if ( m_maxWidth == 0.0 )
|
|
|
|
{
|
|
|
|
using namespace QskAspect;
|
|
|
|
|
2017-08-23 14:53:29 +02:00
|
|
|
const QFontMetricsF fm( effectiveFont( Text ) );
|
2017-07-28 16:16:13 +02:00
|
|
|
|
2017-10-30 12:06:19 +01:00
|
|
|
for ( const auto& entry : m_values )
|
2017-07-28 16:16:13 +02:00
|
|
|
m_maxWidth = qMax( m_maxWidth, fm.width( entry.first ) );
|
|
|
|
|
2017-08-23 14:53:29 +02:00
|
|
|
const QMarginsF padding = marginsHint( Cell | Padding );
|
|
|
|
m_maxWidth += padding.left() + padding.right();
|
2017-07-28 16:16:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return m_maxWidth;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual qreal rowHeight() const override
|
|
|
|
{
|
|
|
|
using namespace QskAspect;
|
|
|
|
|
2017-08-23 14:53:29 +02:00
|
|
|
const QFontMetricsF fm( effectiveFont( Text ) );
|
|
|
|
const QMarginsF padding = marginsHint( Cell | Padding );
|
|
|
|
|
|
|
|
return fm.height() + padding.top() + padding.bottom();
|
2017-07-28 16:16:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual QVariant valueAt( int row, int ) const override final
|
|
|
|
{
|
|
|
|
return m_values[row].first;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
inline void append( QLocale locale, const QString& name )
|
|
|
|
{
|
|
|
|
m_values += qMakePair( QString( name ), locale );
|
|
|
|
}
|
|
|
|
|
|
|
|
QVector< QPair< QString, QLocale > > m_values;
|
|
|
|
mutable qreal m_maxWidth;
|
|
|
|
};
|
|
|
|
|
2017-07-21 18:21:34 +02:00
|
|
|
int main( int argc, char* argv[] )
|
|
|
|
{
|
|
|
|
#ifdef ITEM_STATISTICS
|
|
|
|
QskObjectCounter counter( true );
|
|
|
|
#endif
|
|
|
|
|
2017-07-28 13:06:59 +02:00
|
|
|
qputenv( "QT_IM_MODULE", "skinny" );
|
|
|
|
qputenv( "QT_PLUGIN_PATH", STRING( PLUGIN_PATH ) );
|
|
|
|
|
2017-07-21 18:21:34 +02:00
|
|
|
QGuiApplication app( argc, argv );
|
|
|
|
|
|
|
|
SkinnyFont::init( &app );
|
2017-09-06 10:20:22 +02:00
|
|
|
SkinnyShortcut::enable( SkinnyShortcut::AllShortcuts );
|
2017-07-21 18:21:34 +02:00
|
|
|
|
2017-07-28 14:47:11 +02:00
|
|
|
#if !LOCAL_PANEL
|
|
|
|
// We don't want to have a top level window.
|
|
|
|
qskDialog->setPolicy( QskDialog::EmbeddedBox );
|
|
|
|
#endif
|
|
|
|
|
2017-07-28 16:16:13 +02:00
|
|
|
auto box = new QskLinearBox( Qt::Horizontal );
|
|
|
|
box->setSpacing( 10 );
|
|
|
|
box->setMargins( 20 );
|
|
|
|
|
|
|
|
(void) new LocaleListView( box );
|
|
|
|
(void) new InputBox( box );
|
|
|
|
|
2017-07-28 14:47:11 +02:00
|
|
|
QskWindow window;
|
2017-07-28 16:16:13 +02:00
|
|
|
window.setColor( "PapayaWhip" );
|
|
|
|
window.addItem( box );
|
2017-07-28 14:47:11 +02:00
|
|
|
window.addItem( new QskFocusIndicator() );
|
|
|
|
|
2017-07-28 16:16:13 +02:00
|
|
|
window.resize( 800, 300 );
|
2017-07-28 14:47:11 +02:00
|
|
|
window.show();
|
2017-07-21 18:21:34 +02:00
|
|
|
|
|
|
|
return app.exec();
|
|
|
|
}
|