keyboard: Preselect the current keyboard layout variant.
This commit is contained in:
parent
3d9116b80e
commit
9b75999706
@ -84,6 +84,7 @@ KeyboardPage::init()
|
|||||||
{
|
{
|
||||||
//### Detect current keyboard layout and variant
|
//### Detect current keyboard layout and variant
|
||||||
QString currentLayout;
|
QString currentLayout;
|
||||||
|
QString currentVariant;
|
||||||
QProcess process;
|
QProcess process;
|
||||||
process.start( "setxkbmap", QStringList() << "-print" );
|
process.start( "setxkbmap", QStringList() << "-print" );
|
||||||
|
|
||||||
@ -109,9 +110,17 @@ KeyboardPage::init()
|
|||||||
currentLayout = split.at( 1 );
|
currentLayout = split.at( 1 );
|
||||||
|
|
||||||
if ( currentLayout.contains( "(" ) )
|
if ( currentLayout.contains( "(" ) )
|
||||||
currentLayout = currentLayout
|
{
|
||||||
.mid( 0, currentLayout.indexOf( "(" ) )
|
int parenthesisIndex = currentLayout.indexOf( "(" );
|
||||||
|
currentVariant = currentLayout.mid( parenthesisIndex + 1 )
|
||||||
.trimmed();
|
.trimmed();
|
||||||
|
currentVariant.chop( 1 );
|
||||||
|
currentLayout = currentLayout
|
||||||
|
.mid( 0, parenthesisIndex )
|
||||||
|
.trimmed();
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -167,13 +176,19 @@ KeyboardPage::init()
|
|||||||
|
|
||||||
ui->listLayout->sortItems();
|
ui->listLayout->sortItems();
|
||||||
|
|
||||||
|
// Set current layout and variant
|
||||||
|
if ( currentLayoutItem )
|
||||||
|
{
|
||||||
|
ui->listLayout->setCurrentItem( currentLayoutItem );
|
||||||
|
updateVariants( currentLayoutItem, currentVariant );
|
||||||
|
}
|
||||||
|
|
||||||
// Unblock signals
|
// Unblock signals
|
||||||
ui->listLayout->blockSignals( false );
|
ui->listLayout->blockSignals( false );
|
||||||
|
|
||||||
// Set current layout
|
// Default to the first available layout if none was set
|
||||||
if ( currentLayoutItem )
|
// Do this after unblocking signals so we get the default variant handling.
|
||||||
ui->listLayout->setCurrentItem( currentLayoutItem );
|
if ( !currentLayoutItem && ui->listLayout->count() > 0 )
|
||||||
else if ( ui->listLayout->count() > 0 )
|
|
||||||
ui->listLayout->setCurrentRow( 0 );
|
ui->listLayout->setCurrentRow( 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -233,16 +248,12 @@ KeyboardPage::finalize()
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
KeyboardPage::onListLayoutCurrentItemChanged( QListWidgetItem* current, QListWidgetItem* previous )
|
KeyboardPage::updateVariants( LayoutItem* currentItem, QString currentVariant )
|
||||||
{
|
{
|
||||||
LayoutItem *item = dynamic_cast< LayoutItem* >( current );
|
|
||||||
if ( !item )
|
|
||||||
return;
|
|
||||||
|
|
||||||
// Block signals
|
// Block signals
|
||||||
ui->listVariant->blockSignals( true );
|
ui->listVariant->blockSignals( true );
|
||||||
|
|
||||||
QMap< QString, QString > variants = item->info.variants;
|
QMap< QString, QString > variants = currentItem->info.variants;
|
||||||
QMapIterator< QString, QString > li( variants );
|
QMapIterator< QString, QString > li( variants );
|
||||||
LayoutItem* defaultItem = nullptr;
|
LayoutItem* defaultItem = nullptr;
|
||||||
|
|
||||||
@ -252,12 +263,14 @@ KeyboardPage::onListLayoutCurrentItemChanged( QListWidgetItem* current, QListWid
|
|||||||
{
|
{
|
||||||
li.next();
|
li.next();
|
||||||
|
|
||||||
item = new LayoutItem();
|
LayoutItem* item = new LayoutItem();
|
||||||
item->setText( li.key() );
|
item->setText( li.key() );
|
||||||
item->data = li.value();
|
item->data = li.value();
|
||||||
ui->listVariant->addItem( item );
|
ui->listVariant->addItem( item );
|
||||||
|
|
||||||
if ( li.value() == "" )
|
// currentVariant defaults to QString(). It is only non-empty during the
|
||||||
|
// initial setup.
|
||||||
|
if ( li.value() == currentVariant )
|
||||||
defaultItem = item;
|
defaultItem = item;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -270,6 +283,17 @@ KeyboardPage::onListLayoutCurrentItemChanged( QListWidgetItem* current, QListWid
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
KeyboardPage::onListLayoutCurrentItemChanged( QListWidgetItem* current, QListWidgetItem* previous )
|
||||||
|
{
|
||||||
|
LayoutItem* item = dynamic_cast< LayoutItem* >( current );
|
||||||
|
if ( !item )
|
||||||
|
return;
|
||||||
|
|
||||||
|
updateVariants( item );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
KeyboardPage::onListVariantCurrentItemChanged( QListWidgetItem* current, QListWidgetItem* previous )
|
KeyboardPage::onListVariantCurrentItemChanged( QListWidgetItem* current, QListWidgetItem* previous )
|
||||||
{
|
{
|
||||||
|
@ -68,6 +68,8 @@ private:
|
|||||||
KeyboardGlobal::KeyboardInfo info;
|
KeyboardGlobal::KeyboardInfo info;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void updateVariants( LayoutItem* currentItem, QString currentVariant = QString() );
|
||||||
|
|
||||||
Ui::Page_Keyboard *ui;
|
Ui::Page_Keyboard *ui;
|
||||||
KeyBoardPreview* m_keyboardPreview;
|
KeyBoardPreview* m_keyboardPreview;
|
||||||
int m_defaultIndex;
|
int m_defaultIndex;
|
||||||
|
Loading…
Reference in New Issue
Block a user