27 #include <QtGui/QBrush>
28 #include <QtGui/QPainter>
29 #include <QStandardItem>
30 #include <QtCore/QTextCodec>
31 #include <QtGui/QLinearGradient>
32 #include <QtGui/QRadialGradient>
33 #include <QtCore/QTimer>
36 #include <kdeversion.h>
37 #if KDE_IS_VERSION(4, 9, 1)
38 #include <KCodecAction>
40 #include <kcodecaction.h>
43 #include <KFontDialog>
45 #include <KIconDialog>
46 #include <KFileDialog>
47 #include <KUrlCompletion>
48 #include <KWindowSystem>
50 #include <KMessageBox>
56 #include "ui_EditProfileDialog.h"
65 using namespace Konsole;
69 , _delayedPreviewTimer(new QTimer(this))
72 setCaption(i18n(
"Edit Profile"));
73 setButtons(KDialog::Ok | KDialog::Cancel | KDialog::Apply);
76 enableButtonApply(
false);
78 connect(
this, SIGNAL(applyClicked()),
this, SLOT(save()));
80 connect(_delayedPreviewTimer, SIGNAL(timeout()),
this, SLOT(delayedPreviewActivate()));
82 _ui =
new Ui::EditProfileDialog();
83 _ui->setupUi(mainWidget());
95 _pageNeedsUpdate.resize(_ui->tabWidget->count());
96 connect(_ui->tabWidget, SIGNAL(currentChanged(
int)),
this,
97 SLOT(preparePage(
int)));
105 void EditProfileDialog::save()
107 if (_tempProfile->isEmpty())
114 QHashIterator<Profile::Property, QVariant> iter(_tempProfile->setProperties());
115 while (iter.hasNext()) {
117 _previewedProperties.remove(iter.key());
122 enableButtonApply(
false);
132 Q_ASSERT(_tempProfile);
135 _tempProfile->name().isEmpty())
136 || (_profile->name().isEmpty() && _tempProfile->name().isEmpty())) {
137 KMessageBox::sorry(
this,
138 i18n(
"<p>Each profile must have a name before it can be saved "
146 QString EditProfileDialog::groupProfileNames(
const ProfileGroup::Ptr group,
int maxLength)
149 int count = group->profiles().count();
150 for (
int i = 0; i < count; i++) {
151 caption += group->profiles()[i]->name();
152 if (i < (count - 1)) {
155 if (maxLength > 0 && caption.length() > maxLength) {
163 void EditProfileDialog::updateCaption(
const Profile::Ptr profile)
165 const int MAX_GROUP_CAPTION_LENGTH = 25;
167 if (group && group->profiles().count() > 1) {
168 QString caption = groupProfileNames(group, MAX_GROUP_CAPTION_LENGTH);
169 setCaption(i18np(
"Editing profile: %2",
170 "Editing %1 profiles: %2",
171 group->profiles().count(),
174 setCaption(i18n(
"Edit Profile \"%1\"", profile->name()));
184 updateCaption(profile);
190 _pageNeedsUpdate.fill(
true);
191 preparePage(_ui->tabWidget->currentIndex());
201 void EditProfileDialog::preparePage(
int page)
205 Q_ASSERT(_pageNeedsUpdate.count() > page);
208 QWidget* pageWidget = _ui->tabWidget->widget(page);
210 if (_pageNeedsUpdate[page]) {
211 if (pageWidget == _ui->generalTab)
212 setupGeneralPage(profile);
213 else if (pageWidget == _ui->tabsTab)
214 setupTabsPage(profile);
215 else if (pageWidget == _ui->appearanceTab)
216 setupAppearancePage(profile);
217 else if (pageWidget == _ui->scrollingTab)
218 setupScrollingPage(profile);
219 else if (pageWidget == _ui->keyboardTab)
220 setupKeyboardPage(profile);
221 else if (pageWidget == _ui->mouseTab)
222 setupMousePage(profile);
223 else if (pageWidget == _ui->advancedTab)
224 setupAdvancedPage(profile);
228 _pageNeedsUpdate[page] =
false;
233 _ui->profileNameEdit->setFocus();
234 _ui->profileNameEdit->selectAll();
236 void EditProfileDialog::setupGeneralPage(
const Profile::Ptr profile)
240 _ui->emptyNameWarningWidget->setWordWrap(
false);
241 _ui->emptyNameWarningWidget->setCloseButtonVisible(
false);
242 _ui->emptyNameWarningWidget->setMessageType(KMessageWidget::Warning);
245 if (!group || group->profiles().count() < 2) {
246 _ui->profileNameEdit->setText(profile->name());
247 _ui->profileNameEdit->setClearButtonShown(
true);
249 _ui->emptyNameWarningWidget->setVisible(profile->name().isEmpty());
250 _ui->emptyNameWarningWidget->setText(i18n(
"Profile name is empty."));
252 _ui->profileNameEdit->setText(groupProfileNames(group, -1));
253 _ui->profileNameEdit->setEnabled(
false);
254 _ui->profileNameLabel->setEnabled(
false);
256 _ui->emptyNameWarningWidget->setVisible(
false);
260 ShellCommand command(profile->command() , profile->arguments());
261 _ui->commandEdit->setText(command.fullCommand());
262 KUrlCompletion* exeCompletion =
new KUrlCompletion(KUrlCompletion::ExeCompletion);
263 exeCompletion->setParent(
this);
264 exeCompletion->setDir(QString());
265 _ui->commandEdit->setCompletionObject(exeCompletion);
267 _ui->initialDirEdit->setText(profile->defaultWorkingDirectory());
268 KUrlCompletion* dirCompletion =
new KUrlCompletion(KUrlCompletion::DirCompletion);
269 dirCompletion->setParent(
this);
270 _ui->initialDirEdit->setCompletionObject(dirCompletion);
271 _ui->initialDirEdit->setClearButtonShown(
true);
273 _ui->dirSelectButton->setIcon(KIcon(
"folder-open"));
274 _ui->iconSelectButton->setIcon(KIcon(profile->icon()));
275 _ui->startInSameDirButton->setChecked(profile->startInCurrentSessionDir());
278 _ui->showTerminalSizeHintButton->setChecked(profile->showTerminalSizeHint());
279 _ui->saveGeometryOnExitButton->setChecked(profile->saveGeometryOnExit());
282 connect(_ui->dirSelectButton, SIGNAL(clicked()),
this, SLOT(selectInitialDir()));
283 connect(_ui->iconSelectButton, SIGNAL(clicked()),
this, SLOT(selectIcon()));
284 connect(_ui->startInSameDirButton, SIGNAL(toggled(
bool)),
this ,
285 SLOT(startInSameDir(
bool)));
286 connect(_ui->profileNameEdit, SIGNAL(textChanged(QString)),
this,
287 SLOT(profileNameChanged(QString)));
288 connect(_ui->initialDirEdit, SIGNAL(textChanged(QString)),
this,
289 SLOT(initialDirChanged(QString)));
290 connect(_ui->commandEdit, SIGNAL(textChanged(QString)),
this,
291 SLOT(commandChanged(QString)));
292 connect(_ui->environmentEditButton , SIGNAL(clicked()),
this,
293 SLOT(showEnvironmentEditor()));
295 connect(_ui->saveGeometryOnExitButton, SIGNAL(toggled(
bool)),
this,
296 SLOT(saveGeometryOnExit(
bool)));
297 connect(_ui->showTerminalSizeHintButton, SIGNAL(toggled(
bool)),
this,
298 SLOT(showTerminalSizeHint(
bool)));
300 void EditProfileDialog::showEnvironmentEditor()
304 QWeakPointer<KDialog> dialog =
new KDialog(
this);
305 KTextEdit* edit =
new KTextEdit(dialog.data());
307 QStringList currentEnvironment = profile->environment();
309 edit->setPlainText(currentEnvironment.join(
"\n"));
310 edit->setToolTip(i18nc(
"@info:tooltip",
"One environment variable per line"));
312 dialog.data()->setPlainCaption(i18n(
"Edit Environment"));
313 dialog.data()->setMainWidget(edit);
315 if (dialog.data()->exec() == QDialog::Accepted) {
316 QStringList newEnvironment = edit->toPlainText().split(
'\n');
320 delete dialog.data();
322 void EditProfileDialog::setupTabsPage(
const Profile::Ptr profile)
325 _ui->renameTabWidget->setTabTitleText(profile->localTabTitleFormat());
326 _ui->renameTabWidget->setRemoteTabTitleText(profile->remoteTabTitleFormat());
328 connect(_ui->renameTabWidget, SIGNAL(tabTitleFormatChanged(QString)),
this,
329 SLOT(tabTitleFormatChanged(QString)));
330 connect(_ui->renameTabWidget, SIGNAL(remoteTabTitleFormatChanged(QString)),
this,
331 SLOT(remoteTabTitleFormatChanged(QString)));
334 const int silenceSeconds = profile->silenceSeconds();
335 _ui->silenceSecondsSpinner->setValue(silenceSeconds);
336 _ui->silenceSecondsSpinner->setSuffix(ki18ncp(
"Unit of time",
" second",
" seconds"));
338 connect(_ui->silenceSecondsSpinner, SIGNAL(valueChanged(
int)),
339 this, SLOT(silenceSecondsChanged(
int)));
342 void EditProfileDialog::saveGeometryOnExit(
bool value)
346 void EditProfileDialog::showTerminalSizeHint(
bool value)
350 void EditProfileDialog::tabTitleFormatChanged(
const QString& format)
354 void EditProfileDialog::remoteTabTitleFormatChanged(
const QString& format)
359 void EditProfileDialog::silenceSecondsChanged(
int seconds)
364 void EditProfileDialog::selectIcon()
366 const QString& icon = KIconDialog::getIcon(KIconLoader::Desktop, KIconLoader::Application,
367 false, 0,
false,
this);
368 if (!icon.isEmpty()) {
369 _ui->iconSelectButton->setIcon(KIcon(icon));
373 void EditProfileDialog::profileNameChanged(
const QString& text)
375 _ui->emptyNameWarningWidget->setVisible(text.isEmpty());
379 updateCaption(_tempProfile);
381 void EditProfileDialog::startInSameDir(
bool sameDir)
385 void EditProfileDialog::initialDirChanged(
const QString& dir)
389 void EditProfileDialog::commandChanged(
const QString& command)
396 void EditProfileDialog::selectInitialDir()
398 const KUrl url = KFileDialog::getExistingDirectoryUrl(_ui->initialDirEdit->text(),
400 i18n(
"Select Initial Directory"));
403 _ui->initialDirEdit->setText(url.path());
405 void EditProfileDialog::setupAppearancePage(
const Profile::Ptr profile)
408 _ui->colorSchemeList->setItemDelegate(delegate);
410 _ui->transparencyWarningWidget->setVisible(
false);
411 _ui->transparencyWarningWidget->setWordWrap(
true);
412 _ui->transparencyWarningWidget->setCloseButtonVisible(
false);
413 _ui->transparencyWarningWidget->setMessageType(KMessageWidget::Warning);
415 _ui->editColorSchemeButton->setEnabled(
false);
416 _ui->removeColorSchemeButton->setEnabled(
false);
419 updateColorSchemeList(
true);
421 _ui->colorSchemeList->setMouseTracking(
true);
422 _ui->colorSchemeList->installEventFilter(
this);
423 _ui->colorSchemeList->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
425 connect(_ui->colorSchemeList->selectionModel(),
426 SIGNAL(selectionChanged(QItemSelection,QItemSelection)),
427 this, SLOT(colorSchemeSelected()));
428 connect(_ui->colorSchemeList, SIGNAL(entered(QModelIndex)),
this,
429 SLOT(previewColorScheme(QModelIndex)));
431 updateColorSchemeButtons();
433 connect(_ui->editColorSchemeButton, SIGNAL(clicked()),
this,
434 SLOT(editColorScheme()));
435 connect(_ui->removeColorSchemeButton, SIGNAL(clicked()),
this,
436 SLOT(removeColorScheme()));
437 connect(_ui->newColorSchemeButton, SIGNAL(clicked()),
this,
438 SLOT(newColorScheme()));
441 const bool antialias = profile->antiAliasFonts();
443 QFont profileFont = profile->font();
444 profileFont.setStyleStrategy(antialias ? QFont::PreferAntialias : QFont::NoAntialias);
446 _ui->fontPreviewLabel->installEventFilter(
this);
447 _ui->fontPreviewLabel->setFont(profileFont);
448 setFontInputValue(profileFont);
450 connect(_ui->fontSizeInput, SIGNAL(valueChanged(
double)),
this,
451 SLOT(setFontSize(
double)));
452 connect(_ui->selectFontButton, SIGNAL(clicked()),
this,
453 SLOT(showFontDialog()));
456 _ui->antialiasTextButton->setChecked(antialias);
457 connect(_ui->antialiasTextButton, SIGNAL(toggled(
bool)),
this,
458 SLOT(setAntialiasText(
bool)));
460 _ui->boldIntenseButton->setChecked(profile->boldIntense());
461 connect(_ui->boldIntenseButton, SIGNAL(toggled(
bool)),
this,
462 SLOT(setBoldIntense(
bool)));
463 _ui->enableMouseWheelZoomButton->setChecked(profile->mouseWheelZoomEnabled());
464 connect(_ui->enableMouseWheelZoomButton, SIGNAL(toggled(
bool)),
this,
465 SLOT(toggleMouseWheelZoom(
bool)));
467 void EditProfileDialog::setAntialiasText(
bool enable)
469 QFont profileFont = _ui->fontPreviewLabel->font();
470 profileFont.setStyleStrategy(enable ? QFont::PreferAntialias : QFont::NoAntialias);
473 fontSelected(profileFont);
476 void EditProfileDialog::setBoldIntense(
bool enable)
481 void EditProfileDialog::toggleMouseWheelZoom(
bool enable)
485 void EditProfileDialog::updateColorSchemeList(
bool selectCurrentScheme)
487 if (!_ui->colorSchemeList->model())
488 _ui->colorSchemeList->setModel(
new QStandardItemModel(
this));
493 QStandardItemModel* model = qobject_cast<QStandardItemModel*>(_ui->colorSchemeList->model());
499 QStandardItem* selectedItem = 0;
504 QStandardItem* item =
new QStandardItem(scheme->
description());
505 item->setData(QVariant::fromValue(scheme) , Qt::UserRole + 1);
506 item->setFlags(item->flags());
508 if (currentScheme == scheme)
511 model->appendRow(item);
516 if (selectCurrentScheme && selectedItem) {
517 _ui->colorSchemeList->updateGeometry();
518 _ui->colorSchemeList->selectionModel()->setCurrentIndex(selectedItem->index() ,
519 QItemSelectionModel::Select);
522 updateTransparencyWarning();
525 void EditProfileDialog::updateKeyBindingsList(
bool selectCurrentTranslator)
527 if (!_ui->keyBindingList->model())
528 _ui->keyBindingList->setModel(
new QStandardItemModel(
this));
535 QStandardItemModel* model = qobject_cast<QStandardItemModel*>(_ui->keyBindingList->model());
541 QStandardItem* selectedItem = 0;
544 foreach(
const QString& translatorName, translatorNames) {
547 QStandardItem* item =
new QStandardItem(translator->
description());
548 item->setEditable(
false);
549 item->setData(QVariant::fromValue(translator), Qt::UserRole + 1);
550 item->setIcon(KIcon(
"preferences-desktop-keyboard"));
552 if (translator == currentTranslator)
555 model->appendRow(item);
560 if (selectCurrentTranslator && selectedItem) {
561 _ui->keyBindingList->selectionModel()->setCurrentIndex(selectedItem->index() ,
562 QItemSelectionModel::Select);
567 if (watched == _ui->colorSchemeList && aEvent->type() == QEvent::Leave) {
573 if (watched == _ui->fontPreviewLabel && aEvent->type() == QEvent::FontChange) {
574 const QFont& labelFont = _ui->fontPreviewLabel->font();
575 _ui->fontPreviewLabel->setText(i18n(
"%1", labelFont.family()));
578 return KDialog::eventFilter(watched, aEvent);
580 void EditProfileDialog::unpreviewAll()
582 _delayedPreviewTimer->stop();
583 _delayedPreviewProperties.clear();
585 QHash<Profile::Property, QVariant> map;
586 QHashIterator<int, QVariant> iter(_previewedProperties);
587 while (iter.hasNext()) {
596 void EditProfileDialog::unpreview(
int aProperty)
598 _delayedPreviewProperties.remove(aProperty);
600 if (!_previewedProperties.contains(aProperty))
603 QHash<Profile::Property, QVariant> map;
607 _previewedProperties.remove(aProperty);
609 void EditProfileDialog::delayedPreview(
int aProperty ,
const QVariant& value)
611 _delayedPreviewProperties.insert(aProperty, value);
613 _delayedPreviewTimer->stop();
614 _delayedPreviewTimer->start(300);
616 void EditProfileDialog::delayedPreviewActivate()
618 Q_ASSERT(qobject_cast<QTimer*>(sender()));
620 QMutableHashIterator<int, QVariant> iter(_delayedPreviewProperties);
621 if (iter.hasNext()) {
623 preview(iter.key(), iter.value());
626 void EditProfileDialog::preview(
int aProperty ,
const QVariant& value)
628 QHash<Profile::Property, QVariant> map;
631 _delayedPreviewProperties.remove(aProperty);
640 if (group && group->profiles().count() > 1 &&
644 if (!_previewedProperties.contains(aProperty)) {
645 _previewedProperties.insert(aProperty , original->property<QVariant>((
Profile::Property)aProperty));
651 void EditProfileDialog::previewColorScheme(
const QModelIndex& index)
653 const QString& name = index.data(Qt::UserRole + 1).value<
const ColorScheme*>()->name();
657 void EditProfileDialog::removeColorScheme()
659 QModelIndexList selected = _ui->colorSchemeList->selectionModel()->selectedIndexes();
661 if (!selected.isEmpty()) {
662 const QString& name = selected.first().data(Qt::UserRole + 1).value<
const ColorScheme*>()->name();
665 _ui->colorSchemeList->model()->removeRow(selected.first().row());
668 void EditProfileDialog::showColorSchemeEditor(
bool isNewScheme)
671 QModelIndexList selected = _ui->colorSchemeList->selectionModel()->selectedIndexes();
672 QAbstractItemModel* model = _ui->colorSchemeList->model();
674 if (!selected.isEmpty())
675 colors = model->data(selected.first(), Qt::UserRole + 1).value<const ColorScheme*>();
684 closeColorSchemeEditor();
688 connect(_colorDialog, SIGNAL(colorSchemeSaveRequested(
ColorScheme,
bool)),
690 _colorDialog->
setup(colors, isNewScheme);
692 _colorDialog->show();
694 void EditProfileDialog::closeColorSchemeEditor()
697 _colorDialog->close();
701 void EditProfileDialog::newColorScheme()
703 showColorSchemeEditor(
true);
705 void EditProfileDialog::editColorScheme()
707 showColorSchemeEditor(
false);
709 void EditProfileDialog::saveColorScheme(
const ColorScheme& scheme,
bool isNewScheme)
720 updateColorSchemeList(
true);
724 void EditProfileDialog::colorSchemeSelected()
726 QModelIndexList selected = _ui->colorSchemeList->selectionModel()->selectedIndexes();
728 if (!selected.isEmpty()) {
729 QAbstractItemModel* model = _ui->colorSchemeList->model();
730 const ColorScheme* colors = model->data(selected.first(), Qt::UserRole + 1).value<const ColorScheme*>();
733 previewColorScheme(selected.first());
735 updateTransparencyWarning();
739 updateColorSchemeButtons();
741 void EditProfileDialog::updateColorSchemeButtons()
743 enableIfNonEmptySelection(_ui->editColorSchemeButton, _ui->colorSchemeList->selectionModel());
744 enableIfNonEmptySelection(_ui->removeColorSchemeButton, _ui->colorSchemeList->selectionModel());
746 void EditProfileDialog::updateKeyBindingsButtons()
748 enableIfNonEmptySelection(_ui->editKeyBindingsButton, _ui->keyBindingList->selectionModel());
749 enableIfNonEmptySelection(_ui->removeKeyBindingsButton, _ui->keyBindingList->selectionModel());
751 void EditProfileDialog::enableIfNonEmptySelection(
QWidget* widget, QItemSelectionModel* selectionModel)
753 widget->setEnabled(selectionModel->hasSelection());
755 void EditProfileDialog::updateTransparencyWarning()
758 foreach(
const QModelIndex & index , _ui->colorSchemeList->selectionModel()->selectedIndexes()) {
759 bool needTransparency = index.data(Qt::UserRole + 1).value<
const ColorScheme*>()->opacity() < 1.0;
761 if (!needTransparency) {
762 _ui->transparencyWarningWidget->setHidden(
true);
763 }
else if (!KWindowSystem::compositingActive()) {
764 _ui->transparencyWarningWidget->setText(i18n(
"This color scheme uses a transparent background"
765 " which does not appear to be supported on your"
767 _ui->transparencyWarningWidget->setHidden(
false);
769 _ui->transparencyWarningWidget->setText(i18n(
"Konsole was started before desktop effects were enabled."
770 " You need to restart Konsole to see transparent background."));
771 _ui->transparencyWarningWidget->setHidden(
false);
776 void EditProfileDialog::createTempProfile()
779 _tempProfile->setHidden(
true);
782 void EditProfileDialog::updateTempProfileProperty(
Profile::Property aProperty,
const QVariant & value)
784 _tempProfile->setProperty(aProperty, value);
788 void EditProfileDialog::updateButtonApply()
790 bool userModified =
false;
792 QHashIterator<Profile::Property, QVariant> iter(_tempProfile->setProperties());
793 while (iter.hasNext()) {
797 QVariant value = iter.value();
800 if (_previewedProperties.contains(static_cast<int>(aProperty))) {
801 if (value != _previewedProperties.value(static_cast<int>(aProperty))) {
806 }
else if ((value != _profile->property<QVariant>(aProperty))) {
812 enableButtonApply(userModified);
815 void EditProfileDialog::setupKeyboardPage(
const Profile::Ptr )
818 updateKeyBindingsList(
true);
820 connect(_ui->keyBindingList->selectionModel(),
821 SIGNAL(selectionChanged(QItemSelection,QItemSelection)),
822 SLOT(keyBindingSelected()));
823 connect(_ui->newKeyBindingsButton, SIGNAL(clicked()),
this,
824 SLOT(newKeyBinding()));
826 updateKeyBindingsButtons();
828 connect(_ui->editKeyBindingsButton, SIGNAL(clicked()),
this,
829 SLOT(editKeyBinding()));
830 connect(_ui->removeKeyBindingsButton, SIGNAL(clicked()),
this,
831 SLOT(removeKeyBinding()));
833 void EditProfileDialog::keyBindingSelected()
835 QModelIndexList selected = _ui->keyBindingList->selectionModel()->selectedIndexes();
837 if (!selected.isEmpty()) {
838 QAbstractItemModel* model = _ui->keyBindingList->model();
839 const KeyboardTranslator* translator = model->data(selected.first(), Qt::UserRole + 1)
840 .value<const KeyboardTranslator*>();
846 updateKeyBindingsButtons();
848 void EditProfileDialog::removeKeyBinding()
850 QModelIndexList selected = _ui->keyBindingList->selectionModel()->selectedIndexes();
852 if (!selected.isEmpty()) {
853 const QString& name = selected.first().data(Qt::UserRole + 1).value<
const KeyboardTranslator*>()->name();
855 _ui->keyBindingList->model()->removeRow(selected.first().row());
858 void EditProfileDialog::showKeyBindingEditor(
bool isNewTranslator)
860 QModelIndexList selected = _ui->keyBindingList->selectionModel()->selectedIndexes();
861 QAbstractItemModel* model = _ui->keyBindingList->model();
864 if (!selected.isEmpty())
865 translator = model->data(selected.first(), Qt::UserRole + 1).value<const KeyboardTranslator*>();
869 Q_ASSERT(translator);
871 QWeakPointer<KDialog> dialog =
new KDialog(
this);
874 dialog.data()->setCaption(i18n(
"New Key Binding List"));
876 dialog.data()->setCaption(i18n(
"Edit Key Binding List"));
879 dialog.data()->setMainWidget(editor);
882 editor->
setup(translator);
887 if (dialog.data()->exec() == QDialog::Accepted) {
895 updateKeyBindingsList();
900 if (newTranslator->
name() == currentTranslator) {
904 delete dialog.data();
906 void EditProfileDialog::newKeyBinding()
908 showKeyBindingEditor(
true);
910 void EditProfileDialog::editKeyBinding()
912 showKeyBindingEditor(
false);
914 void EditProfileDialog::setupCheckBoxes(BooleanOption* options ,
const Profile::Ptr profile)
916 while (options->button != 0) {
917 options->button->setChecked(profile->property<
bool>(options->property));
918 connect(options->button, SIGNAL(toggled(
bool)),
this, options->slot);
923 void EditProfileDialog::setupRadio(RadioOption* possibilities ,
int actual)
925 while (possibilities->button != 0) {
926 if (possibilities->value == actual)
927 possibilities->button->setChecked(
true);
929 possibilities->button->setChecked(
false);
931 connect(possibilities->button, SIGNAL(clicked()),
this, possibilities->slot);
937 void EditProfileDialog::setupScrollingPage(
const Profile::Ptr profile)
942 RadioOption positions[] = { {_ui->scrollBarHiddenButton,
Enum::ScrollBarHidden, SLOT(hideScrollBar())},
948 setupRadio(positions , scrollBarPosition);
957 const int historySize = profile->historySize();
958 _ui->historySizeWidget->setLineCount(historySize);
963 RadioOption pageamounts[] = {
969 setupRadio(pageamounts, scrollFullPage);
972 connect(_ui->historySizeWidget, SIGNAL(historySizeChanged(
int)),
973 this, SLOT(historySizeChanged(
int)));
976 void EditProfileDialog::historySizeChanged(
int lineCount)
984 void EditProfileDialog::hideScrollBar()
988 void EditProfileDialog::showScrollBarLeft()
992 void EditProfileDialog::showScrollBarRight()
996 void EditProfileDialog::scrollFullPage()
1000 void EditProfileDialog::scrollHalfPage()
1004 void EditProfileDialog::setupMousePage(
const Profile::Ptr profile)
1006 BooleanOption options[] = { {
1008 SLOT(toggleUnderlineLinks(
bool))
1012 SLOT(toggleCtrlRequiredForDrag(
bool))
1016 SLOT(toggleCopyTextToClipboard(
bool))
1020 SLOT(toggleTrimTrailingSpacesInSelectedText(
bool))
1024 SLOT(toggleOpenLinksByDirectClick(
bool))
1028 setupCheckBoxes(options , profile);
1032 RadioOption pasteModes[] = {
1037 setupRadio(pasteModes , middleClickPasteMode);
1040 _ui->wordCharacterEdit->setText(profile->wordCharacters());
1042 connect(_ui->wordCharacterEdit, SIGNAL(textChanged(QString)),
this,
1043 SLOT(wordCharactersChanged(QString)));
1046 _ui->tripleClickModeCombo->setCurrentIndex(tripleClickMode);
1048 connect(_ui->tripleClickModeCombo, SIGNAL(activated(
int)),
this,
1049 SLOT(TripleClickModeChanged(
int)));
1051 _ui->openLinksByDirectClickButton->setEnabled(_ui->underlineLinksButton->isChecked());
1053 _ui->enableMouseWheelZoomButton->setChecked(profile->mouseWheelZoomEnabled());
1054 connect(_ui->enableMouseWheelZoomButton, SIGNAL(toggled(
bool)),
this,
1055 SLOT(toggleMouseWheelZoom(
bool)));
1057 void EditProfileDialog::setupAdvancedPage(
const Profile::Ptr profile)
1059 BooleanOption options[] = { {
1061 SLOT(toggleBlinkingText(
bool))
1065 SLOT(toggleFlowControl(
bool))
1069 SLOT(toggleBlinkingCursor(
bool))
1073 SLOT(togglebidiRendering(
bool))
1077 setupCheckBoxes(options , profile);
1079 const int lineSpacing = profile->lineSpacing();
1080 _ui->lineSpacingSpinner->setValue(lineSpacing);
1082 connect(_ui->lineSpacingSpinner, SIGNAL(valueChanged(
int)),
1083 this, SLOT(lineSpacingChanged(
int)));
1086 if (profile->useCustomCursorColor())
1087 _ui->customCursorColorButton->setChecked(
true);
1089 _ui->autoCursorColorButton->setChecked(
true);
1091 _ui->customColorSelectButton->setColor(profile->customCursorColor());
1093 connect(_ui->customCursorColorButton, SIGNAL(clicked()),
this, SLOT(customCursorColor()));
1094 connect(_ui->autoCursorColorButton, SIGNAL(clicked()),
this, SLOT(autoCursorColor()));
1095 connect(_ui->customColorSelectButton, SIGNAL(changed(QColor)),
1096 SLOT(customCursorColorChanged(QColor)));
1099 _ui->cursorShapeCombo->setCurrentIndex(shape);
1101 connect(_ui->cursorShapeCombo, SIGNAL(activated(
int)),
this, SLOT(setCursorShape(
int)));
1104 QAction* codecAction =
new KCodecAction(
this);
1105 _ui->selectEncodingButton->setMenu(codecAction->menu());
1106 connect(codecAction, SIGNAL(triggered(QTextCodec*)),
this, SLOT(setDefaultCodec(QTextCodec*)));
1108 _ui->characterEncodingLabel->setText(profile->defaultEncoding());
1110 void EditProfileDialog::setDefaultCodec(QTextCodec* codec)
1112 QString name = QString(codec->name());
1115 _ui->characterEncodingLabel->setText(codec->name());
1117 void EditProfileDialog::customCursorColorChanged(
const QColor& color)
1122 _ui->customCursorColorButton->click();
1124 void EditProfileDialog::wordCharactersChanged(
const QString& text)
1128 void EditProfileDialog::autoCursorColor()
1132 void EditProfileDialog::customCursorColor()
1136 void EditProfileDialog::setCursorShape(
int index)
1140 void EditProfileDialog::togglebidiRendering(
bool enable)
1144 void EditProfileDialog::lineSpacingChanged(
int spacing)
1148 void EditProfileDialog::toggleBlinkingCursor(
bool enable)
1152 void EditProfileDialog::toggleUnderlineLinks(
bool enable)
1155 _ui->openLinksByDirectClickButton->setEnabled(enable);
1157 void EditProfileDialog::toggleCtrlRequiredForDrag(
bool enable)
1161 void EditProfileDialog::toggleOpenLinksByDirectClick(
bool enable)
1165 void EditProfileDialog::toggleCopyTextToClipboard(
bool enable)
1169 void EditProfileDialog::toggleTrimTrailingSpacesInSelectedText(
bool enable)
1173 void EditProfileDialog::pasteFromX11Selection()
1177 void EditProfileDialog::pasteFromClipboard()
1181 void EditProfileDialog::TripleClickModeChanged(
int newValue)
1185 void EditProfileDialog::toggleBlinkingText(
bool enable)
1189 void EditProfileDialog::toggleFlowControl(
bool enable)
1193 void EditProfileDialog::fontSelected(
const QFont& aFont)
1195 QFont previewFont = aFont;
1197 setFontInputValue(aFont);
1199 _ui->fontPreviewLabel->setFont(previewFont);
1204 void EditProfileDialog::showFontDialog()
1206 QString sampleText = QString(
"ell 'lL', one '1', little eye 'i', big eye");
1207 sampleText += QString(
"'I', lL1iI, Zero '0', little oh 'o', big oh 'O', 0oO");
1208 sampleText += QString(
"`~!@#$%^&*()_+-=[]\\{}|:\";'<>?,./");
1209 sampleText += QString(
"0123456789");
1210 sampleText += QString(
"\nThe Quick Brown Fox Jumps Over The Lazy Dog\n");
1211 sampleText += i18n(
"--- Type anything in this box ---");
1212 QFont currentFont = _ui->fontPreviewLabel->font();
1214 QWeakPointer<KFontDialog> dialog =
new KFontDialog(
this, KFontChooser::FixedFontsOnly);
1215 dialog.data()->setCaption(i18n(
"Select Fixed Width Font"));
1216 dialog.data()->setFont(currentFont,
true);
1222 if (!chooserList.isEmpty())
1223 chooserList.at(0)->setSampleText(sampleText);
1225 connect(dialog.data(), SIGNAL(fontSelected(QFont)),
this, SLOT(fontSelected(QFont)));
1227 if (dialog.data()->exec() == QDialog::Rejected)
1228 fontSelected(currentFont);
1229 delete dialog.data();
1231 void EditProfileDialog::setFontSize(
double pointSize)
1233 QFont newFont = _ui->fontPreviewLabel->font();
1234 newFont.setPointSizeF(pointSize);
1235 _ui->fontPreviewLabel->setFont(newFont);
1241 void EditProfileDialog::setFontInputValue(
const QFont& aFont)
1243 _ui->fontSizeInput->setValue(aFont.pointSizeF());
1252 const QModelIndex& index)
const
1259 bool transparencyAvailable = KWindowSystem::compositingActive();
1261 painter->setRenderHint(QPainter::Antialiasing);
1270 QRectF backgroundRect = QRectF(option.rect).adjusted(1.5, 1.5, -1.5, -1.5);
1272 QRadialGradient backgroundGradient(backgroundRect.center() , backgroundRect.width() / 2);
1273 backgroundGradient.setColorAt(0 , color.lighter(105));
1274 backgroundGradient.setColorAt(1 , color.darker(115));
1276 const int backgroundRectXRoundness = 4;
1277 const int backgroundRectYRoundness = 30;
1279 QPainterPath backgroundRectPath(backgroundRect.topLeft());
1280 backgroundRectPath.addRoundRect(backgroundRect , backgroundRectXRoundness , backgroundRectYRoundness);
1282 if (transparencyAvailable) {
1284 color.setAlphaF(scheme->
opacity());
1285 painter->setCompositionMode(QPainter::CompositionMode_Source);
1286 painter->setBrush(backgroundGradient);
1288 painter->drawPath(backgroundRectPath);
1291 painter->setBrush(backgroundGradient);
1292 painter->drawPath(backgroundRectPath);
1296 painter->setPen(QPen(Qt::NoPen));
1297 QPainterPath path(option.rect.topLeft());
1298 path.lineTo(option.rect.width() / 10.0 , option.rect.top());
1299 path.lineTo(option.rect.bottomLeft());
1300 path.lineTo(option.rect.topLeft());
1302 painter->drawPath(path.intersected(backgroundRectPath));
1306 QLinearGradient gradient(option.rect.topLeft() , option.rect.bottomLeft());
1307 gradient.setColorAt(0 , QColor(255, 255, 255, 90));
1308 gradient.setColorAt(1 , Qt::transparent);
1309 painter->setBrush(gradient);
1310 painter->drawRoundRect(backgroundRect , 4 , 30);
1313 const bool isSelected = option.state & QStyle::State_Selected;
1317 static const int selectedBorderWidth = 6;
1319 painter->setBrush(QBrush(Qt::NoBrush));
1322 QColor highlightColor = option.palette.highlight().color();
1325 highlightColor.setAlphaF(1.0);
1327 highlightColor.setAlphaF(0.7);
1329 pen.setBrush(highlightColor);
1330 pen.setWidth(selectedBorderWidth);
1331 pen.setJoinStyle(Qt::MiterJoin);
1333 painter->setPen(pen);
1335 painter->drawRect(option.rect.adjusted(selectedBorderWidth / 2,
1336 selectedBorderWidth / 2,
1337 -selectedBorderWidth / 2,
1338 -selectedBorderWidth / 2));
1343 painter->setPen(pen);
1345 painter->drawText(option.rect , Qt::AlignCenter ,
1346 index.data(Qt::DisplayRole).value<QString>());
1350 const QModelIndex& )
const
1352 const int width = 200;
1355 qreal heightForWidth = (colorWidth * 2) + option.fontMetrics.height() + margin;
1358 return QSize(width, static_cast<int>(heightForWidth));
1361 #include "EditProfileDialog.moc"
void addTranslator(KeyboardTranslator *translator)
Adds a new translator.
(HistoryModeEnum) Specifies the storage type used for keeping the output produced by terminal session...
(String) Default text codec
A converter which maps between key sequences pressed by the user and the character strings which shou...
(bool) Whether fonts should be aliased or not
(bool) Specifies whether show hint for terminal size after resizing the application window...
QString description() const
Returns the descriptive name of this keyboard translator.
(bool) Specifies whether the flow control keys (typically Ctrl+S, Ctrl+Q) have any effect...
(QColor) The color used by terminal displays to draw the cursor.
(QString) The format used for tab titles when the session is running a remote command (eg...
(bool) If true, trailing spaces are trimmed in selected text
KSharedPtr< ProfileGroup > Ptr
(QString) The name of the key bindings.
Paste from X11 Selection.
(QString) A string consisting of the characters used to delimit words when selecting text in the term...
(int) Specifies the threshold of detected silence in seconds.
virtual void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
(MiddleClickPasteModeEnum) Specifies the source from which mouse middle click pastes data...
(QFont) The font to use in terminal displays using this profile.
Represents a terminal set-up which can be used to set the initial state of new terminal sessions or a...
Property
This enum describes the available properties which a Profile may consist of.
ColorSchemeViewDelegate(QObject *parent=0)
Do not show the scroll-bar.
(QString) The initial working directory for sessions created using this profile.
KeyboardTranslator * translator() const
Returns the modified translator describing the changes to the bindings and other settings which the u...
(bool) Specifies whether text in terminal displays is allowed to blink.
(QString) The command to execute ( excluding arguments ) when creating a new terminal session using t...
(bool) If true, terminal displays use a fixed color to draw the cursor, specified by the CustomCursor...
EditProfileDialog(QWidget *parent=0)
Constructs a new dialog with the specified parent.
virtual bool eventFilter(QObject *watched, QEvent *event)
(QString) The untranslated name of this profile.
QList< const ColorScheme * > allColorSchemes()
Returns a list of the all the available color schemes.
void setName(const QString &name)
Sets the name of this keyboard translator.
A class to parse and extract information about shell commands.
qreal opacity() const
Returns the opacity level for this color scheme, see setOpacity() TODO: More documentation.
(bool) Specifies whether the cursor blinks ( in a manner similar to text editing applications ) ...
QStringList allTranslators()
Returns a list of the names of available keyboard translators.
void setDescription(const QString &description)
Sets the text of the editor's description field.
(bool) If true, automatically copy selected text into the clipboard
static ProfileManager * instance()
Returns the profile manager instance.
(bool) Whether new sessions should be started in the same directory as the currently active session...
(bool) If true, text that matches a link or an email address is underlined when hovered by the mouse ...
(bool) Whether character with intense colors should be rendered in bold font or just in bright color...
(bool) Specifies whether the PageUp/Down will scroll the full height or half height.
void setup(const KeyboardTranslator *translator)
Initializes the dialog with the bindings and other settings from the specified translator.
(int) Specifies the pixels between the terminal lines.
(QStringList) The arguments which are passed to the program specified by the Command property when cr...
void addColorScheme(ColorScheme *scheme)
Adds a new color scheme to the manager.
(QString) The name of the icon associated with this profile.
(TripleClickModeEnum) Specifies which part of current line should be selected with triple click actio...
void setup(const ColorScheme *scheme, bool isNewScheme)
Initializes the dialog with the properties of the specified color scheme.
(bool) Specifies whether the terminal will enable Bidirectional text display
QString description() const
Returns the descriptive name of the color scheme.
static const bool HAVE_TRANSPARENCY
void setName(const QString &name)
Sets the name of the color scheme.
HistoryModeEnum
This enum describes the modes available to remember lines of output produced by the terminal...
const KeyboardTranslator * defaultTranslator()
Returns the default translator for Konsole.
const Profile::Ptr lookupProfile() const
KSharedPtr< Profile > Ptr
virtual QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
const ColorScheme * findColorScheme(const QString &name)
Returns the color scheme with the given name or 0 if no scheme with that name exists.
QString name() const
Returns the name of this keyboard translator.
(int) Specifies the number of lines of output to remember in terminal sessions using this profile...
A delegate which can display and edit color schemes in a view.
void changeProfile(Profile::Ptr profile, QHash< Profile::Property, QVariant > propertyMap, bool persistent=true)
Updates a profile with the changes specified in propertyMap.
(CursorShapeEnum) The shape used by terminal displays to represent the cursor.
A dialog for editing color schemes.
virtual ~EditProfileDialog()
(ScrollBarPositionEnum) Specifies the position of the scroll bar in terminal displays using this prof...
void setProfile(Profile::Ptr profile)
Initializes the dialog with the settings for the specified session type.
(bool) Specifies whether the geometry information is saved when window is closed. ...
static KeyboardTranslatorManager * instance()
Returns the global KeyboardTranslatorManager instance.
(QString) The name of the color scheme to use in terminal displays using this profile.
(bool) If true, mouse wheel scroll with Ctrl key pressed increases/decreases the terminal font size...
QString name() const
Returns the name of the color scheme.
Show the scroll-bar on the right of the terminal display.
QColor backgroundColor() const
Convenience method.
(QString) The format used for tab titles when running normal commands.
QColor foregroundColor() const
Convenience method.
Manages the keyboard translations available for use by terminal sessions, see KeyboardTranslator.
A dialog which allows the user to edit a key bindings list which maps between key combinations input ...
Show the scroll-bar on the left of the terminal display.
(bool) If true, links can be opened by direct mouse click.
const ColorScheme * defaultColorScheme() const
Returns the default color scheme for Konsole.
void selectProfileName()
Selects the text in the profile name edit area.
(QString) The descriptive name of this profile.
static ColorSchemeManager * instance()
Returns the global color scheme manager instance.
Represents a color scheme for a terminal display.
(bool) If true, control key must be pressed to click and drag selected text.
(QStringList) Additional environment variables (in the form of NAME=VALUE pairs) which are passed to ...
const KeyboardTranslator * findTranslator(const QString &name)
Returns the keyboard translator with the given name or 0 if no translator with that name exists...