Changeset View
Changeset View
Standalone View
Standalone View
src/EditProfileDialog.cpp
Show First 20 Lines • Show All 688 Lines • ▼ Show 20 Line(s) | 687 | if (selectedItem != nullptr) { | |||
---|---|---|---|---|---|
689 | _ui->colorSchemeList->selectionModel()->setCurrentIndex(selectedItem->index(), | 689 | _ui->colorSchemeList->selectionModel()->setCurrentIndex(selectedItem->index(), | ||
690 | QItemSelectionModel::Select); | 690 | QItemSelectionModel::Select); | ||
691 | 691 | | |||
692 | // update transparency warning label | 692 | // update transparency warning label | ||
693 | updateTransparencyWarning(); | 693 | updateTransparencyWarning(); | ||
694 | } | 694 | } | ||
695 | } | 695 | } | ||
696 | 696 | | |||
697 | void EditProfileDialog::updateKeyBindingsList(bool selectCurrentTranslator) | 697 | void EditProfileDialog::updateKeyBindingsList(const QString &selectKeyBindingsName) | ||
698 | { | 698 | { | ||
699 | if (_ui->keyBindingList->model() == nullptr) { | 699 | if (_ui->keyBindingList->model() == nullptr) { | ||
700 | _ui->keyBindingList->setModel(new QStandardItemModel(this)); | 700 | _ui->keyBindingList->setModel(new QStandardItemModel(this)); | ||
701 | } | 701 | } | ||
702 | 702 | | |||
703 | const QString &name = lookupProfile()->keyBindings(); | | |||
704 | | ||||
705 | KeyboardTranslatorManager *keyManager = KeyboardTranslatorManager::instance(); | | |||
706 | const KeyboardTranslator *currentTranslator = keyManager->findTranslator(name); | | |||
707 | | ||||
708 | QStandardItemModel *model = qobject_cast<QStandardItemModel *>(_ui->keyBindingList->model()); | 703 | QStandardItemModel *model = qobject_cast<QStandardItemModel *>(_ui->keyBindingList->model()); | ||
709 | 704 | | |||
710 | Q_ASSERT(model); | 705 | Q_ASSERT(model); | ||
711 | 706 | | |||
712 | model->clear(); | 707 | model->clear(); | ||
713 | 708 | | |||
714 | QStandardItem *selectedItem = nullptr; | 709 | QStandardItem *selectedItem = nullptr; | ||
715 | 710 | | |||
716 | QStringList translatorNames = keyManager->allTranslators(); | 711 | const QStringList &translatorNames = _keyManager->allTranslators(); | ||
717 | foreach (const QString &translatorName, translatorNames) { | 712 | for (const QString &translatorName : translatorNames) { | ||
718 | const KeyboardTranslator *translator = keyManager->findTranslator(translatorName); | 713 | const KeyboardTranslator *translator = _keyManager->findTranslator(translatorName); | ||
719 | if (translator == nullptr) { | 714 | if (translator == nullptr) { | ||
720 | continue; | 715 | continue; | ||
721 | } | 716 | } | ||
722 | 717 | | |||
723 | QStandardItem *item = new QStandardItem(translator->description()); | 718 | QStandardItem *item = new QStandardItem(translator->description()); | ||
724 | item->setEditable(false); | 719 | item->setEditable(false); | ||
725 | item->setData(QVariant::fromValue(translator), Qt::UserRole + 1); | 720 | item->setData(QVariant::fromValue(translator), Qt::UserRole + 1); | ||
721 | item->setData(QVariant::fromValue(_keyManager->findTranslatorPath(translatorName)), Qt::ToolTipRole); | ||||
726 | item->setData(QVariant::fromValue(_profile->font()), Qt::UserRole + 2); | 722 | item->setData(QVariant::fromValue(_profile->font()), Qt::UserRole + 2); | ||
727 | item->setIcon(QIcon::fromTheme(QStringLiteral("preferences-desktop-keyboard"))); | 723 | item->setIcon(QIcon::fromTheme(QStringLiteral("preferences-desktop-keyboard"))); | ||
728 | 724 | | |||
729 | if (translator == currentTranslator) { | 725 | if (selectKeyBindingsName == translatorName) { | ||
730 | selectedItem = item; | 726 | selectedItem = item; | ||
731 | } | 727 | } | ||
732 | 728 | | |||
733 | model->appendRow(item); | 729 | model->appendRow(item); | ||
734 | } | 730 | } | ||
735 | 731 | | |||
736 | model->sort(0); | 732 | model->sort(0); | ||
737 | 733 | | |||
738 | if (selectCurrentTranslator && (selectedItem != nullptr)) { | 734 | if (selectedItem != nullptr) { | ||
739 | _ui->keyBindingList->selectionModel()->setCurrentIndex(selectedItem->index(), | 735 | _ui->keyBindingList->selectionModel()->setCurrentIndex(selectedItem->index(), | ||
740 | QItemSelectionModel::Select); | 736 | QItemSelectionModel::Select); | ||
741 | } | 737 | } | ||
742 | } | 738 | } | ||
743 | 739 | | |||
744 | bool EditProfileDialog::eventFilter(QObject *watched, QEvent *event) | 740 | bool EditProfileDialog::eventFilter(QObject *watched, QEvent *event) | ||
745 | { | 741 | { | ||
746 | if (watched == _ui->colorSchemeList && event->type() == QEvent::Leave) { | 742 | if (watched == _ui->colorSchemeList && event->type() == QEvent::Leave) { | ||
▲ Show 20 Lines • Show All 312 Lines • ▼ Show 20 Line(s) | 1054 | } else { | |||
1059 | _ui->removeColorSchemeButton->setEnabled(false); | 1055 | _ui->removeColorSchemeButton->setEnabled(false); | ||
1060 | _ui->resetColorSchemeButton->setEnabled(false); | 1056 | _ui->resetColorSchemeButton->setEnabled(false); | ||
1061 | } | 1057 | } | ||
1062 | 1058 | | |||
1063 | } | 1059 | } | ||
1064 | 1060 | | |||
1065 | void EditProfileDialog::updateKeyBindingsButtons() | 1061 | void EditProfileDialog::updateKeyBindingsButtons() | ||
1066 | { | 1062 | { | ||
1067 | enableIfNonEmptySelection(_ui->editKeyBindingsButton, _ui->keyBindingList->selectionModel()); | 1063 | QModelIndexList selected = _ui->keyBindingList->selectionModel()->selectedIndexes(); | ||
1068 | enableIfNonEmptySelection(_ui->removeKeyBindingsButton, _ui->keyBindingList->selectionModel()); | 1064 | | ||
1065 | if (!selected.isEmpty()) { | ||||
1066 | _ui->editKeyBindingsButton->setEnabled(true); | ||||
1067 | | ||||
1068 | const QString &name = selected.first().data(Qt::UserRole + 1).value<const KeyboardTranslator *>()->name(); | ||||
1069 | | ||||
1070 | bool isResettable = _keyManager->isTranslatorResettable(name); | ||||
1071 | _ui->resetKeyBindingsButton->setEnabled(isResettable); | ||||
1072 | | ||||
1073 | bool isDeletable = _keyManager->isTranslatorDeletable(name); | ||||
1074 | | ||||
1075 | // if a key bindings scheme can be reset then it can't be deleted | ||||
1076 | _ui->removeKeyBindingsButton->setEnabled(isDeletable && !isResettable); | ||||
1077 | } | ||||
1069 | } | 1078 | } | ||
1070 | 1079 | | |||
1071 | void EditProfileDialog::enableIfNonEmptySelection(QWidget *widget, QItemSelectionModel *selectionModel) | 1080 | void EditProfileDialog::enableIfNonEmptySelection(QWidget *widget, QItemSelectionModel *selectionModel) | ||
1072 | { | 1081 | { | ||
1073 | widget->setEnabled(selectionModel->hasSelection()); | 1082 | widget->setEnabled(selectionModel->hasSelection()); | ||
1074 | } | 1083 | } | ||
1075 | 1084 | | |||
1076 | void EditProfileDialog::updateTransparencyWarning() | 1085 | void EditProfileDialog::updateTransparencyWarning() | ||
▲ Show 20 Lines • Show All 60 Lines • ▼ Show 20 Line(s) | 1121 | { | |||
1137 | } | 1146 | } | ||
1138 | 1147 | | |||
1139 | mButtonBox->button(QDialogButtonBox::Apply)->setEnabled(userModified); | 1148 | mButtonBox->button(QDialogButtonBox::Apply)->setEnabled(userModified); | ||
1140 | } | 1149 | } | ||
1141 | 1150 | | |||
1142 | void EditProfileDialog::setupKeyboardPage(const Profile::Ptr /* profile */) | 1151 | void EditProfileDialog::setupKeyboardPage(const Profile::Ptr /* profile */) | ||
1143 | { | 1152 | { | ||
1144 | // setup translator list | 1153 | // setup translator list | ||
1145 | updateKeyBindingsList(true); | 1154 | updateKeyBindingsList(lookupProfile()->keyBindings()); | ||
1146 | 1155 | | |||
1147 | connect(_ui->keyBindingList->selectionModel(), | 1156 | connect(_ui->keyBindingList->selectionModel(), | ||
1148 | &QItemSelectionModel::selectionChanged, this, | 1157 | &QItemSelectionModel::selectionChanged, this, | ||
1149 | &Konsole::EditProfileDialog::keyBindingSelected); | 1158 | &Konsole::EditProfileDialog::keyBindingSelected); | ||
1150 | connect(_ui->newKeyBindingsButton, &QPushButton::clicked, this, | 1159 | connect(_ui->newKeyBindingsButton, &QPushButton::clicked, this, | ||
1151 | &Konsole::EditProfileDialog::newKeyBinding); | 1160 | &Konsole::EditProfileDialog::newKeyBinding); | ||
1152 | 1161 | | |||
1162 | _ui->editKeyBindingsButton->setEnabled(false); | ||||
1163 | _ui->removeKeyBindingsButton->setEnabled(false); | ||||
1164 | _ui->resetKeyBindingsButton->setEnabled(false); | ||||
1165 | | ||||
1153 | updateKeyBindingsButtons(); | 1166 | updateKeyBindingsButtons(); | ||
1154 | 1167 | | |||
1155 | connect(_ui->editKeyBindingsButton, &QPushButton::clicked, this, | 1168 | connect(_ui->editKeyBindingsButton, &QPushButton::clicked, this, | ||
1156 | &Konsole::EditProfileDialog::editKeyBinding); | 1169 | &Konsole::EditProfileDialog::editKeyBinding); | ||
1157 | connect(_ui->removeKeyBindingsButton, &QPushButton::clicked, this, | 1170 | connect(_ui->removeKeyBindingsButton, &QPushButton::clicked, this, | ||
1158 | &Konsole::EditProfileDialog::removeKeyBinding); | 1171 | &Konsole::EditProfileDialog::removeKeyBinding); | ||
1172 | connect(_ui->resetKeyBindingsButton, &QPushButton::clicked, this, | ||||
1173 | &Konsole::EditProfileDialog::resetKeyBindings); | ||||
1159 | } | 1174 | } | ||
1160 | 1175 | | |||
1161 | void EditProfileDialog::keyBindingSelected() | 1176 | void EditProfileDialog::keyBindingSelected() | ||
1162 | { | 1177 | { | ||
1163 | QModelIndexList selected = _ui->keyBindingList->selectionModel()->selectedIndexes(); | 1178 | QModelIndexList selected = _ui->keyBindingList->selectionModel()->selectedIndexes(); | ||
1164 | 1179 | | |||
1165 | if (!selected.isEmpty()) { | 1180 | if (!selected.isEmpty()) { | ||
1166 | QAbstractItemModel *model = _ui->keyBindingList->model(); | 1181 | QAbstractItemModel *model = _ui->keyBindingList->model(); | ||
Show All 23 Lines | |||||
1190 | { | 1205 | { | ||
1191 | QModelIndexList selected = _ui->keyBindingList->selectionModel()->selectedIndexes(); | 1206 | QModelIndexList selected = _ui->keyBindingList->selectionModel()->selectedIndexes(); | ||
1192 | QAbstractItemModel *model = _ui->keyBindingList->model(); | 1207 | QAbstractItemModel *model = _ui->keyBindingList->model(); | ||
1193 | 1208 | | |||
1194 | const KeyboardTranslator *translator = nullptr; | 1209 | const KeyboardTranslator *translator = nullptr; | ||
1195 | if (!selected.isEmpty()) { | 1210 | if (!selected.isEmpty()) { | ||
1196 | translator = model->data(selected.first(), Qt::UserRole + 1).value<const KeyboardTranslator *>(); | 1211 | translator = model->data(selected.first(), Qt::UserRole + 1).value<const KeyboardTranslator *>(); | ||
1197 | } else { | 1212 | } else { | ||
1198 | translator = KeyboardTranslatorManager::instance()->defaultTranslator(); | 1213 | translator = _keyManager->defaultTranslator(); | ||
1199 | } | 1214 | } | ||
1200 | 1215 | | |||
1201 | Q_ASSERT(translator); | 1216 | Q_ASSERT(translator); | ||
1202 | 1217 | | |||
1203 | QPointer<QDialog> dialog = new QDialog(this); | 1218 | auto editor = new KeyBindingEditor(this); | ||
1204 | auto buttonBox = new QDialogButtonBox(dialog); | | |||
1205 | buttonBox->setStandardButtons(QDialogButtonBox::Ok | QDialogButtonBox::Cancel); | | |||
1206 | connect(buttonBox, &QDialogButtonBox::accepted, dialog.data(), &QDialog::accept); | | |||
1207 | connect(buttonBox, &QDialogButtonBox::rejected, dialog.data(), &QDialog::reject); | | |||
1208 | | ||||
1209 | if (isNewTranslator) { | | |||
1210 | dialog->setWindowTitle(i18n("New Key Binding List")); | | |||
1211 | } else { | | |||
1212 | dialog->setWindowTitle(i18n("Edit Key Binding List")); | | |||
1213 | } | | |||
1214 | | ||||
1215 | auto editor = new KeyBindingEditor; | | |||
1216 | 1219 | | |||
1217 | if (translator != nullptr) { | 1220 | if (translator != nullptr) { | ||
1218 | editor->setup(translator); | 1221 | editor->setup(translator, lookupProfile()->keyBindings(), isNewTranslator); | ||
1219 | } | | |||
1220 | | ||||
1221 | if (isNewTranslator) { | | |||
1222 | editor->setDescription(i18n("New Key Binding List")); | | |||
1223 | } | 1222 | } | ||
1224 | 1223 | | |||
1225 | auto layout = new QVBoxLayout; | 1224 | connect(editor, &Konsole::KeyBindingEditor::updateKeyBindingsListRequest, | ||
1226 | layout->addWidget(editor); | 1225 | this, &Konsole::EditProfileDialog::updateKeyBindingsList); | ||
1227 | layout->addWidget(buttonBox); | | |||
1228 | dialog->setLayout(layout); | | |||
1229 | // see also the size set in the KeyBindingEditor constructor | | |||
1230 | dialog->setMinimumSize(480, 430); | | |||
1231 | dialog->resize(500, 500); | | |||
1232 | 1226 | | |||
1233 | if (dialog->exec() == QDialog::Accepted) { | 1227 | connect(editor, &Konsole::KeyBindingEditor::updateTempProfileKeyBindingsRequest, | ||
1234 | auto newTranslator = new KeyboardTranslator(*editor->translator()); | 1228 | this, &Konsole::EditProfileDialog::updateTempProfileProperty); | ||
1235 | 1229 | | |||
1236 | if (isNewTranslator) { | 1230 | editor->exec(); | ||
1237 | newTranslator->setName(newTranslator->description()); | | |||
1238 | } | | |||
1239 | | ||||
1240 | KeyboardTranslatorManager::instance()->addTranslator(newTranslator); | | |||
1241 | | ||||
1242 | updateKeyBindingsList(); | | |||
1243 | | ||||
1244 | const QString ¤tTranslator = lookupProfile() | | |||
1245 | ->property<QString>(Profile::KeyBindings); | | |||
1246 | | ||||
1247 | if (newTranslator->name() == currentTranslator) { | | |||
1248 | updateTempProfileProperty(Profile::KeyBindings, newTranslator->name()); | | |||
1249 | } | | |||
1250 | } | | |||
1251 | delete dialog; | | |||
1252 | } | 1231 | } | ||
1253 | 1232 | | |||
1254 | void EditProfileDialog::newKeyBinding() | 1233 | void EditProfileDialog::newKeyBinding() | ||
1255 | { | 1234 | { | ||
1256 | showKeyBindingEditor(true); | 1235 | showKeyBindingEditor(true); | ||
1257 | } | 1236 | } | ||
1258 | 1237 | | |||
1259 | void EditProfileDialog::editKeyBinding() | 1238 | void EditProfileDialog::editKeyBinding() | ||
1260 | { | 1239 | { | ||
1261 | showKeyBindingEditor(false); | 1240 | showKeyBindingEditor(false); | ||
1262 | } | 1241 | } | ||
1263 | 1242 | | |||
1243 | void EditProfileDialog::resetKeyBindings() | ||||
1244 | { | ||||
1245 | QModelIndexList selected = _ui->keyBindingList->selectionModel()->selectedIndexes(); | ||||
1246 | | ||||
1247 | if (!selected.isEmpty()) { | ||||
1248 | const QString &name = selected.first().data(Qt::UserRole + 1).value<const KeyboardTranslator *>()->name(); | ||||
1249 | | ||||
1250 | _keyManager->deleteTranslator(name); | ||||
1251 | // find and load the translator | ||||
1252 | _keyManager->findTranslator(name); | ||||
1253 | | ||||
1254 | updateKeyBindingsList(name); | ||||
1255 | } | ||||
1256 | } | ||||
1257 | | ||||
1264 | void EditProfileDialog::setupCheckBoxes(BooleanOption *options, const Profile::Ptr profile) | 1258 | void EditProfileDialog::setupCheckBoxes(BooleanOption *options, const Profile::Ptr profile) | ||
1265 | { | 1259 | { | ||
1266 | while (options->button != nullptr) { | 1260 | while (options->button != nullptr) { | ||
1267 | options->button->setChecked(profile->property<bool>(options->property)); | 1261 | options->button->setChecked(profile->property<bool>(options->property)); | ||
1268 | connect(options->button, SIGNAL(toggled(bool)), this, options->slot); | 1262 | connect(options->button, SIGNAL(toggled(bool)), this, options->slot); | ||
1269 | 1263 | | |||
1270 | ++options; | 1264 | ++options; | ||
1271 | } | 1265 | } | ||
▲ Show 20 Lines • Show All 499 Lines • Show Last 20 Lines |