Changeset View
Changeset View
Standalone View
Standalone View
kcms/keyboard/kcm_keyboard_widget.cpp
Show All 28 Lines | |||||
29 | #include <QWidget> | 29 | #include <QWidget> | ||
30 | #include <QCheckBox> | 30 | #include <QCheckBox> | ||
31 | #include <QPixmap> | 31 | #include <QPixmap> | ||
32 | #include <QVBoxLayout> | 32 | #include <QVBoxLayout> | ||
33 | #include <QX11Info> | 33 | #include <QX11Info> | ||
34 | #include <QDebug> | 34 | #include <QDebug> | ||
35 | 35 | | |||
36 | #include "keyboard_config.h" | 36 | #include "keyboard_config.h" | ||
37 | #ifdef NEW_GEOMETRY | | |||
38 | #include "preview/keyboardpainter.h" | | |||
39 | #endif | | |||
40 | #include "xkb_rules.h" | 37 | #include "xkb_rules.h" | ||
41 | #include "flags.h" | 38 | #include "flags.h" | ||
42 | #include "x11_helper.h" | 39 | #include "x11_helper.h" | ||
43 | #include "kcm_view_models.h" | 40 | #include "kcm_view_models.h" | ||
44 | #include "kcm_add_layout_dialog.h" | 41 | #include "kcm_add_layout_dialog.h" | ||
45 | #include "bindings.h" | 42 | #include "bindings.h" | ||
43 | #include "tastenbrett.h" | ||||
46 | 44 | | |||
47 | #include "kcmmisc.h" | 45 | #include "kcmmisc.h" | ||
48 | #include "ui_kcm_add_layout_dialog.h" | 46 | #include "ui_kcm_add_layout_dialog.h" | ||
49 | 47 | | |||
50 | 48 | | |||
51 | static const QString GROUP_SWITCH_GROUP_NAME(QStringLiteral("grp")); | 49 | static const QString GROUP_SWITCH_GROUP_NAME(QStringLiteral("grp")); | ||
52 | static const QString LV3_SWITCH_GROUP_NAME(QStringLiteral("lv3")); | 50 | static const QString LV3_SWITCH_GROUP_NAME(QStringLiteral("lv3")); | ||
53 | //static const QString RESET_XKB_OPTIONS("-option"); | 51 | //static const QString RESET_XKB_OPTIONS("-option"); | ||
▲ Show 20 Lines • Show All 172 Lines • ▼ Show 20 Line(s) | 223 | { | |||
226 | if( keyboardConfig->layouts.count() >= X11Helper::ARTIFICIAL_GROUP_LIMIT_COUNT ) { // artificial limit now | 224 | if( keyboardConfig->layouts.count() >= X11Helper::ARTIFICIAL_GROUP_LIMIT_COUNT ) { // artificial limit now | ||
227 | QMessageBox msgBox; | 225 | QMessageBox msgBox; | ||
228 | msgBox.setText(i18np("Only up to %1 keyboard layout is supported", "Only up to %1 keyboard layouts are supported", X11Helper::ARTIFICIAL_GROUP_LIMIT_COUNT)); | 226 | msgBox.setText(i18np("Only up to %1 keyboard layout is supported", "Only up to %1 keyboard layouts are supported", X11Helper::ARTIFICIAL_GROUP_LIMIT_COUNT)); | ||
229 | // more information https://bugs.freedesktop.org/show_bug.cgi?id=19501 | 227 | // more information https://bugs.freedesktop.org/show_bug.cgi?id=19501 | ||
230 | msgBox.exec(); | 228 | msgBox.exec(); | ||
231 | return; | 229 | return; | ||
232 | } | 230 | } | ||
233 | 231 | | |||
234 | AddLayoutDialog dialog(rules, keyboardConfig->isFlagShown() ? flags : nullptr, keyboardConfig->keyboardModel, keyboardConfig->isLabelShown(), this); | 232 | AddLayoutDialog dialog(rules, | ||
233 | keyboardConfig->isFlagShown() ? flags : nullptr, | ||||
234 | keyboardConfig->keyboardModel, | ||||
235 | keyboardConfig->xkbOptions, | ||||
236 | keyboardConfig->isLabelShown(), | ||||
237 | this); | ||||
235 | dialog.setModal(true); | 238 | dialog.setModal(true); | ||
236 | if( dialog.exec() == QDialog::Accepted ) { | 239 | if( dialog.exec() == QDialog::Accepted ) { | ||
237 | keyboardConfig->layouts.append( dialog.getSelectedLayoutUnit() ); | 240 | keyboardConfig->layouts.append( dialog.getSelectedLayoutUnit() ); | ||
238 | layoutsTableModel->refresh(); | 241 | layoutsTableModel->refresh(); | ||
239 | uiWidget->layoutsTableView->resizeRowsToContents(); | 242 | uiWidget->layoutsTableView->resizeRowsToContents(); | ||
240 | uiChanged(); | 243 | uiChanged(); | ||
241 | } | 244 | } | ||
242 | 245 | | |||
▲ Show 20 Lines • Show All 87 Lines • ▼ Show 20 Line(s) | |||||
330 | // connect(uiWidget->layoutsTable, SIGNAL(itemSelectionChanged()), this, SLOT(layoutSelectionChanged())); | 333 | // connect(uiWidget->layoutsTable, SIGNAL(itemSelectionChanged()), this, SLOT(layoutSelectionChanged())); | ||
331 | connect(uiWidget->layoutsTableView->selectionModel(), &QItemSelectionModel::selectionChanged, this, &KCMKeyboardWidget::layoutSelectionChanged); | 334 | connect(uiWidget->layoutsTableView->selectionModel(), &QItemSelectionModel::selectionChanged, this, &KCMKeyboardWidget::layoutSelectionChanged); | ||
332 | 335 | | |||
333 | // connect(uiWidget->moveUpBtn, SIGNAL(triggered(QAction*)), this, SLOT(moveUp())); | 336 | // connect(uiWidget->moveUpBtn, SIGNAL(triggered(QAction*)), this, SLOT(moveUp())); | ||
334 | // connect(uiWidget->moveDownBtn, SIGNAL(triggered(QAction*)), this, SLOT(moveDown())); | 337 | // connect(uiWidget->moveDownBtn, SIGNAL(triggered(QAction*)), this, SLOT(moveDown())); | ||
335 | connect(uiWidget->moveUpBtn, &QAbstractButton::clicked, this, &KCMKeyboardWidget::moveUp); | 338 | connect(uiWidget->moveUpBtn, &QAbstractButton::clicked, this, &KCMKeyboardWidget::moveUp); | ||
336 | connect(uiWidget->moveDownBtn, &QAbstractButton::clicked, this, &KCMKeyboardWidget::moveDown); | 339 | connect(uiWidget->moveDownBtn, &QAbstractButton::clicked, this, &KCMKeyboardWidget::moveDown); | ||
337 | 340 | | |||
338 | #ifdef NEW_GEOMETRY | | |||
339 | connect(uiWidget->previewButton, &QAbstractButton::clicked, this, &KCMKeyboardWidget::previewLayout); | 341 | connect(uiWidget->previewButton, &QAbstractButton::clicked, this, &KCMKeyboardWidget::previewLayout); | ||
340 | #endif | | |||
341 | connect(uiWidget->xkbGrpClearBtn, &QAbstractButton::clicked, this, &KCMKeyboardWidget::clearGroupShortcuts); | 342 | connect(uiWidget->xkbGrpClearBtn, &QAbstractButton::clicked, this, &KCMKeyboardWidget::clearGroupShortcuts); | ||
342 | connect(uiWidget->xkb3rdLevelClearBtn, &QAbstractButton::clicked, this, &KCMKeyboardWidget::clear3rdLevelShortcuts); | 343 | connect(uiWidget->xkb3rdLevelClearBtn, &QAbstractButton::clicked, this, &KCMKeyboardWidget::clear3rdLevelShortcuts); | ||
343 | 344 | | |||
344 | // connect(uiWidget->xkbGrpClearBtn, SIGNAL(triggered(QAction*)), this, SLOT(uiChanged())); | 345 | // connect(uiWidget->xkbGrpClearBtn, SIGNAL(triggered(QAction*)), this, SLOT(uiChanged())); | ||
345 | // connect(uiWidget->xkb3rdLevelClearBtn, SIGNAL(triggered(QAction*)), this, SLOT(uiChanged())); | 346 | // connect(uiWidget->xkb3rdLevelClearBtn, SIGNAL(triggered(QAction*)), this, SLOT(uiChanged())); | ||
346 | connect(uiWidget->kdeKeySequence, &KKeySequenceWidget::keySequenceChanged, this, &KCMKeyboardWidget::uiChanged); | 347 | connect(uiWidget->kdeKeySequence, &KKeySequenceWidget::keySequenceChanged, this, &KCMKeyboardWidget::uiChanged); | ||
347 | connect(uiWidget->switchingPolicyButtonGroup, SIGNAL(buttonClicked(int)), this, SLOT(uiChanged())); | 348 | connect(uiWidget->switchingPolicyButtonGroup, SIGNAL(buttonClicked(int)), this, SLOT(uiChanged())); | ||
348 | connect(uiWidget->xkbGrpShortcutBtn, &QAbstractButton::clicked, this, &KCMKeyboardWidget::scrollToGroupShortcut); | 349 | connect(uiWidget->xkbGrpShortcutBtn, &QAbstractButton::clicked, this, &KCMKeyboardWidget::scrollToGroupShortcut); | ||
349 | connect(uiWidget->xkb3rdLevelShortcutBtn, &QAbstractButton::clicked, this, &KCMKeyboardWidget::scrollTo3rdLevelShortcut); | 350 | connect(uiWidget->xkb3rdLevelShortcutBtn, &QAbstractButton::clicked, this, &KCMKeyboardWidget::scrollTo3rdLevelShortcut); | ||
350 | 351 | | |||
351 | // connect(uiWidget->configureLayoutsChk, SIGNAL(toggled(bool)), uiWidget->layoutsGroupBox, SLOT(setEnabled(bool))); | 352 | // connect(uiWidget->configureLayoutsChk, SIGNAL(toggled(bool)), uiWidget->layoutsGroupBox, SLOT(setEnabled(bool))); | ||
352 | connect(uiWidget->layoutsGroupBox, &QGroupBox::toggled, this, &KCMKeyboardWidget::configureLayoutsChanged); | 353 | connect(uiWidget->layoutsGroupBox, &QGroupBox::toggled, this, &KCMKeyboardWidget::configureLayoutsChanged); | ||
353 | 354 | | |||
354 | connect(uiWidget->showIndicatorChk, &QAbstractButton::clicked, this, &KCMKeyboardWidget::uiChanged); | 355 | connect(uiWidget->showIndicatorChk, &QAbstractButton::clicked, this, &KCMKeyboardWidget::uiChanged); | ||
355 | connect(uiWidget->showIndicatorChk, &QAbstractButton::toggled, uiWidget->showSingleChk, &QWidget::setEnabled); | 356 | connect(uiWidget->showIndicatorChk, &QAbstractButton::toggled, uiWidget->showSingleChk, &QWidget::setEnabled); | ||
356 | connect(uiWidget->showFlagRadioBtn, &QAbstractButton::clicked, this, &KCMKeyboardWidget::uiChanged); | 357 | connect(uiWidget->showFlagRadioBtn, &QAbstractButton::clicked, this, &KCMKeyboardWidget::uiChanged); | ||
357 | connect(uiWidget->showLabelRadioBtn, &QAbstractButton::clicked, this, &KCMKeyboardWidget::uiChanged); | 358 | connect(uiWidget->showLabelRadioBtn, &QAbstractButton::clicked, this, &KCMKeyboardWidget::uiChanged); | ||
358 | connect(uiWidget->showLabelOnFlagRadioBtn, &QAbstractButton::clicked, this, &KCMKeyboardWidget::uiChanged); | 359 | connect(uiWidget->showLabelOnFlagRadioBtn, &QAbstractButton::clicked, this, &KCMKeyboardWidget::uiChanged); | ||
359 | connect(uiWidget->showSingleChk, &QAbstractButton::toggled, this, &KCMKeyboardWidget::uiChanged); | 360 | connect(uiWidget->showSingleChk, &QAbstractButton::toggled, this, &KCMKeyboardWidget::uiChanged); | ||
360 | 361 | | |||
361 | connect(uiWidget->layoutLoopingCheckBox, &QAbstractButton::clicked, this, &KCMKeyboardWidget::uiChanged); | 362 | connect(uiWidget->layoutLoopingCheckBox, &QAbstractButton::clicked, this, &KCMKeyboardWidget::uiChanged); | ||
362 | connect(uiWidget->layoutLoopCountSpinBox, SIGNAL(valueChanged(int)), this, SLOT(uiChanged())); | 363 | connect(uiWidget->layoutLoopCountSpinBox, SIGNAL(valueChanged(int)), this, SLOT(uiChanged())); | ||
363 | } | 364 | } | ||
364 | 365 | | |||
365 | #ifdef NEW_GEOMETRY | 366 | void KCMKeyboardWidget::previewLayout() | ||
366 | void KCMKeyboardWidget::previewLayout(){ | 367 | { | ||
367 | QModelIndex index = uiWidget->layoutsTableView->currentIndex(); | 368 | QModelIndex index = uiWidget->layoutsTableView->currentIndex(); | ||
368 | 369 | | |||
369 | QModelIndex idcountry = index.sibling(index.row(),0) ; | 370 | QModelIndex idcountry = index.sibling(index.row(),0) ; | ||
370 | QString country=uiWidget->layoutsTableView->model()->data(idcountry).toString(); | 371 | const QString country=uiWidget->layoutsTableView->model()->data(idcountry).toString(); | ||
371 | QModelIndex idvariant = index.sibling(index.row(),2) ; | 372 | const QModelIndex idvariant = index.sibling(index.row(),2) ; | ||
372 | QString variant=uiWidget->layoutsTableView->model()->data(idvariant).toString(); | 373 | QString variant=uiWidget->layoutsTableView->model()->data(idvariant).toString(); | ||
373 | QString model = keyboardConfig->keyboardModel; | 374 | const QString model = keyboardConfig->keyboardModel; | ||
375 | const QStringList options = keyboardConfig->xkbOptions; | ||||
374 | 376 | | |||
375 | KeyboardPainter layoutPreview; | | |||
376 | const LayoutInfo* layoutInfo = rules->getLayoutInfo(country); | 377 | const LayoutInfo* layoutInfo = rules->getLayoutInfo(country); | ||
377 | if (!layoutInfo) { | 378 | if (!layoutInfo) { | ||
378 | return; | 379 | return; | ||
379 | } | 380 | } | ||
380 | 381 | | |||
381 | foreach(const VariantInfo* variantInfo, layoutInfo->variantInfos) { | 382 | for (const VariantInfo *variantInfo : layoutInfo->variantInfos) { | ||
382 | if(variant==variantInfo->description){ | 383 | if (variant == variantInfo->description) { | ||
383 | variant=variantInfo->name; | 384 | variant = variantInfo->name; | ||
384 | break; | 385 | break; | ||
385 | } | 386 | } | ||
386 | } | 387 | } | ||
387 | 388 | | |||
388 | QString title = Flags::getLongText( LayoutUnit(country, variant), rules ); | 389 | const QString title = Flags::getLongText( LayoutUnit(country, variant), rules ); | ||
389 | layoutPreview.generateKeyboardLayout(country,variant, model, title); | 390 | Tastenbrett::launch(model, country, variant, options.join(','), title); | ||
390 | layoutPreview.setModal(true); | | |||
391 | layoutPreview.exec(); | | |||
392 | } | 391 | } | ||
393 | #endif | | |||
394 | 392 | | |||
395 | void KCMKeyboardWidget::configureLayoutsChanged() | 393 | void KCMKeyboardWidget::configureLayoutsChanged() | ||
396 | { | 394 | { | ||
397 | if( uiWidget->layoutsGroupBox->isChecked() && keyboardConfig->layouts.isEmpty() ) { | 395 | if( uiWidget->layoutsGroupBox->isChecked() && keyboardConfig->layouts.isEmpty() ) { | ||
398 | populateWithCurrentLayouts(); | 396 | populateWithCurrentLayouts(); | ||
399 | } | 397 | } | ||
400 | uiChanged(); | 398 | uiChanged(); | ||
401 | } | 399 | } | ||
Show All 13 Lines | |||||
415 | } | 413 | } | ||
416 | 414 | | |||
417 | void KCMKeyboardWidget::layoutSelectionChanged() | 415 | void KCMKeyboardWidget::layoutSelectionChanged() | ||
418 | { | 416 | { | ||
419 | QModelIndexList selected = uiWidget->layoutsTableView->selectionModel()->selectedIndexes(); | 417 | QModelIndexList selected = uiWidget->layoutsTableView->selectionModel()->selectedIndexes(); | ||
420 | uiWidget->removeLayoutBtn->setEnabled( ! selected.isEmpty() ); | 418 | uiWidget->removeLayoutBtn->setEnabled( ! selected.isEmpty() ); | ||
421 | QPair<int, int> rowsRange( getSelectedRowRange(selected) ); | 419 | QPair<int, int> rowsRange( getSelectedRowRange(selected) ); | ||
422 | uiWidget->moveUpBtn->setEnabled( ! selected.isEmpty() && rowsRange.first > 0); | 420 | uiWidget->moveUpBtn->setEnabled( ! selected.isEmpty() && rowsRange.first > 0); | ||
423 | #ifdef NEW_GEOMETRY | | |||
424 | uiWidget->previewButton->setEnabled( uiWidget->layoutsTableView->selectionModel()->selectedRows().size() == 1 ); | 421 | uiWidget->previewButton->setEnabled( uiWidget->layoutsTableView->selectionModel()->selectedRows().size() == 1 ); | ||
425 | #else | 422 | uiWidget->previewButton->setVisible(Tastenbrett::exists()); | ||
426 | uiWidget->previewButton->setVisible(false); | | |||
427 | #endif | | |||
428 | uiWidget->moveDownBtn->setEnabled( ! selected.isEmpty() && rowsRange.second < keyboardConfig->layouts.size()-1 ); | 423 | uiWidget->moveDownBtn->setEnabled( ! selected.isEmpty() && rowsRange.second < keyboardConfig->layouts.size()-1 ); | ||
429 | } | 424 | } | ||
430 | 425 | | |||
431 | void KCMKeyboardWidget::removeLayout() | 426 | void KCMKeyboardWidget::removeLayout() | ||
432 | { | 427 | { | ||
433 | if( ! uiWidget->layoutsTableView->selectionModel()->hasSelection() ) | 428 | if( ! uiWidget->layoutsTableView->selectionModel()->hasSelection() ) | ||
434 | return; | 429 | return; | ||
435 | 430 | | |||
▲ Show 20 Lines • Show All 273 Lines • Show Last 20 Lines |