inputpanel example "unqmlified"

This commit is contained in:
Uwe Rathmann 2017-07-28 14:47:11 +02:00
parent f3ebc74f44
commit 9ed7306d75
6 changed files with 60 additions and 61 deletions

View File

@ -52,7 +52,10 @@ LineEdit::LineEdit( QQuickItem* parent ):
setActiveFocusOnTab( true );
#if 1
setSkinlet( new LineEditSkinlet() );
auto skinlet = new LineEditSkinlet();
skinlet->setOwnedBySkinnable( true );
setSkinlet( skinlet );
#endif
}

View File

@ -16,16 +16,16 @@ LineEditSkinlet::~LineEditSkinlet() = default;
QRectF LineEditSkinlet::subControlRect(
const QskSkinnable* skinnable, QskAspect::Subcontrol subControl ) const
{
{
const auto lineEdit = static_cast< const LineEdit* >( skinnable );
if ( subControl == LineEdit::Panel )
{
return panelRect( lineEdit );
}
return Inherited::subControlRect( skinnable, subControl );
}
}
QRectF LineEditSkinlet::panelRect( const LineEdit* lineEdit ) const
{

View File

@ -4,9 +4,6 @@ TARGET = inputpanel
DEFINES += PLUGIN_PATH=$$clean_path( $$QSK_OUT_ROOT/plugins )
RESOURCES += \
inputpanel.qrc
HEADERS += \
LineEditSkinlet.h \
LineEdit.h

View File

@ -1,42 +0,0 @@
import QtQuick 2.5
import Skinny 1.0
import LineEdit 1.0
Main
{
id: main
inputPanel: embeddedInputPanel
Window
{
id: window
visible: true
color: "Gainsboro"
width: 800
height: 400
LinearBox
{
orientation: Qt.Vertical
defaultAlignment: Qt.AlignHCenter | Qt.AlignTop
margins: 10
spacing: 10
LineEdit
{
sizePolicy: [ SizePolicy.Maximum ]
text: "I am a line edit. Edit me."
}
InputPanel
{
id: embeddedInputPanel
//visible: Qt.inputMethod.visible
}
}
}
}

View File

@ -1,5 +0,0 @@
<RCC>
<qresource prefix="/qml">
<file>inputpanel.qml</file>
</qresource>
</RCC>

View File

@ -8,15 +8,54 @@
#include <SkinnyFont.h>
#include <SkinnyShortcut.h>
#include <QskModule.h>
#include <QskInputPanel.h>
#include <QskDialog.h>
#include <QskFocusIndicator.h>
#include <QskLinearBox.h>
#include <QskWindow.h>
#include <QskSetup.h>
#include <QskObjectCounter.h>
#include <QQmlApplicationEngine>
#include <QGuiApplication>
#define STRINGIFY(x) #x
#define STRING(x) STRINGIFY(x)
#define LOCAL_PANEL 1
class InputBox : public QskLinearBox
{
public:
InputBox( QQuickItem* parentItem = nullptr ) :
QskLinearBox( Qt::Vertical, parentItem )
{
setBackgroundColor( "PapayaWhip" );
setDefaultAlignment( Qt::AlignHCenter | Qt::AlignTop );
setMargins( 10 );
setSpacing( 10 );
auto* lineEdit = new LineEdit( this );
lineEdit->setSizePolicy( QskSizePolicy::Fixed, QskSizePolicy::Fixed );
lineEdit->setBackgroundColor( Qt::white );
lineEdit->setText( "I am a line edit. Press and edit Me." );
#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
}
};
int main( int argc, char* argv[] )
{
#ifdef ITEM_STATISTICS
@ -26,16 +65,23 @@ int main( int argc, char* argv[] )
qputenv( "QT_IM_MODULE", "skinny" );
qputenv( "QT_PLUGIN_PATH", STRING( PLUGIN_PATH ) );
QskModule::registerTypes();
qmlRegisterType< LineEdit >( "LineEdit", 1, 0, "LineEdit" );
QGuiApplication app( argc, argv );
SkinnyFont::init( &app );
SkinnyShortcut::enable( SkinnyShortcut::Quit |
SkinnyShortcut::DebugShortcuts );
QQmlApplicationEngine engine( QUrl( QStringLiteral( "qrc:/qml/inputpanel.qml" ) ) );
#if !LOCAL_PANEL
// We don't want to have a top level window.
qskDialog->setPolicy( QskDialog::EmbeddedBox );
#endif
QskWindow window;
window.addItem( new InputBox() );
window.addItem( new QskFocusIndicator() );
window.resize( 800, 400 );
window.show();
return app.exec();
}