• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • applications API Reference
  • KDE Home
  • Contact Us
 

Konsole

  • sources
  • kde-4.12
  • applications
  • konsole
  • src
EditProfileDialog.cpp
Go to the documentation of this file.
1 /*
2  Copyright 2007-2008 by Robert Knight <robertknight@gmail.com>
3 
4  This program is free software; you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation; either version 2 of the License, or
7  (at your option) any later version.
8 
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with this program; if not, write to the Free Software
16  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17  02110-1301 USA.
18 */
19 
20 // Own
21 #include "EditProfileDialog.h"
22 
23 // Standard
24 #include <cmath>
25 
26 // Qt
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>
34 
35 // KDE
36 #include <kdeversion.h>
37 #if KDE_IS_VERSION(4, 9, 1)
38 #include <KCodecAction>
39 #else
40 #include <kcodecaction.h>
41 #endif
42 
43 #include <KFontDialog>
44 #include <KIcon>
45 #include <KIconDialog>
46 #include <KFileDialog>
47 #include <KUrlCompletion>
48 #include <KWindowSystem>
49 #include <KTextEdit>
50 #include <KMessageBox>
51 
52 // Konsole
53 #include "ColorScheme.h"
54 #include "ColorSchemeManager.h"
55 #include "ColorSchemeEditor.h"
56 #include "ui_EditProfileDialog.h"
57 #include "KeyBindingEditor.h"
58 #include "KeyboardTranslator.h"
59 #include "KeyboardTranslatorManager.h"
60 #include "ProfileManager.h"
61 #include "ShellCommand.h"
62 #include "WindowSystemInfo.h"
63 #include "Enumeration.h"
64 
65 using namespace Konsole;
66 
67 EditProfileDialog::EditProfileDialog(QWidget* aParent)
68  : KDialog(aParent)
69  , _delayedPreviewTimer(new QTimer(this))
70  , _colorDialog(0)
71 {
72  setCaption(i18n("Edit Profile"));
73  setButtons(KDialog::Ok | KDialog::Cancel | KDialog::Apply);
74 
75  // disable the apply button , since no modification has been made
76  enableButtonApply(false);
77 
78  connect(this, SIGNAL(applyClicked()), this, SLOT(save()));
79 
80  connect(_delayedPreviewTimer, SIGNAL(timeout()), this, SLOT(delayedPreviewActivate()));
81 
82  _ui = new Ui::EditProfileDialog();
83  _ui->setupUi(mainWidget());
84 
85  // there are various setupXYZPage() methods to load the items
86  // for each page and update their states to match the profile
87  // being edited.
88  //
89  // these are only called when needed ( ie. when the user clicks
90  // the tab to move to that page ).
91  //
92  // the _pageNeedsUpdate vector keeps track of the pages that have
93  // not been updated since the last profile change and will need
94  // to be refreshed when the user switches to them
95  _pageNeedsUpdate.resize(_ui->tabWidget->count());
96  connect(_ui->tabWidget, SIGNAL(currentChanged(int)), this,
97  SLOT(preparePage(int)));
98 
99  createTempProfile();
100 }
101 EditProfileDialog::~EditProfileDialog()
102 {
103  delete _ui;
104 }
105 void EditProfileDialog::save()
106 {
107  if (_tempProfile->isEmpty())
108  return;
109 
110  ProfileManager::instance()->changeProfile(_profile, _tempProfile->setProperties());
111 
112  // ensure that these settings are not undone by a call
113  // to unpreview()
114  QHashIterator<Profile::Property, QVariant> iter(_tempProfile->setProperties());
115  while (iter.hasNext()) {
116  iter.next();
117  _previewedProperties.remove(iter.key());
118  }
119 
120  createTempProfile();
121 
122  enableButtonApply(false);
123 }
124 void EditProfileDialog::reject()
125 {
126  unpreviewAll();
127  KDialog::reject();
128 }
129 void EditProfileDialog::accept()
130 {
131  Q_ASSERT(_profile);
132  Q_ASSERT(_tempProfile);
133 
134  if ((_tempProfile->isPropertySet(Profile::Name) &&
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 "
139  "into disk.</p>"));
140  return;
141  }
142  save();
143  unpreviewAll();
144  KDialog::accept();
145 }
146 QString EditProfileDialog::groupProfileNames(const ProfileGroup::Ptr group, int maxLength)
147 {
148  QString caption;
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)) {
153  caption += ',';
154  // limit caption length to prevent very long window titles
155  if (maxLength > 0 && caption.length() > maxLength) {
156  caption += "...";
157  break;
158  }
159  }
160  }
161  return caption;
162 }
163 void EditProfileDialog::updateCaption(const Profile::Ptr profile)
164 {
165  const int MAX_GROUP_CAPTION_LENGTH = 25;
166  ProfileGroup::Ptr group = profile->asGroup();
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(),
172  caption));
173  } else {
174  setCaption(i18n("Edit Profile \"%1\"", profile->name()));
175  }
176 }
177 void EditProfileDialog::setProfile(Profile::Ptr profile)
178 {
179  Q_ASSERT(profile);
180 
181  _profile = profile;
182 
183  // update caption
184  updateCaption(profile);
185 
186  // mark each page of the dialog as out of date
187  // and force an update of the currently visible page
188  //
189  // the other pages will be updated as necessary
190  _pageNeedsUpdate.fill(true);
191  preparePage(_ui->tabWidget->currentIndex());
192 
193  if (_tempProfile) {
194  createTempProfile();
195  }
196 }
197 const Profile::Ptr EditProfileDialog::lookupProfile() const
198 {
199  return _profile;
200 }
201 void EditProfileDialog::preparePage(int page)
202 {
203  const Profile::Ptr profile = lookupProfile();
204 
205  Q_ASSERT(_pageNeedsUpdate.count() > page);
206  Q_ASSERT(profile);
207 
208  QWidget* pageWidget = _ui->tabWidget->widget(page);
209 
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);
225  else
226  Q_ASSERT(false);
227 
228  _pageNeedsUpdate[page] = false;
229  }
230 }
231 void EditProfileDialog::selectProfileName()
232 {
233  _ui->profileNameEdit->setFocus();
234  _ui->profileNameEdit->selectAll();
235 }
236 void EditProfileDialog::setupGeneralPage(const Profile::Ptr profile)
237 {
238  // basic profile options
239  {
240  _ui->emptyNameWarningWidget->setWordWrap(false);
241  _ui->emptyNameWarningWidget->setCloseButtonVisible(false);
242  _ui->emptyNameWarningWidget->setMessageType(KMessageWidget::Warning);
243 
244  ProfileGroup::Ptr group = profile->asGroup();
245  if (!group || group->profiles().count() < 2) {
246  _ui->profileNameEdit->setText(profile->name());
247  _ui->profileNameEdit->setClearButtonShown(true);
248 
249  _ui->emptyNameWarningWidget->setVisible(profile->name().isEmpty());
250  _ui->emptyNameWarningWidget->setText(i18n("Profile name is empty."));
251  } else {
252  _ui->profileNameEdit->setText(groupProfileNames(group, -1));
253  _ui->profileNameEdit->setEnabled(false);
254  _ui->profileNameLabel->setEnabled(false);
255 
256  _ui->emptyNameWarningWidget->setVisible(false);
257  }
258  }
259 
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);
266 
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);
272 
273  _ui->dirSelectButton->setIcon(KIcon("folder-open"));
274  _ui->iconSelectButton->setIcon(KIcon(profile->icon()));
275  _ui->startInSameDirButton->setChecked(profile->startInCurrentSessionDir());
276 
277  // window options
278  _ui->showTerminalSizeHintButton->setChecked(profile->showTerminalSizeHint());
279  _ui->saveGeometryOnExitButton->setChecked(profile->saveGeometryOnExit());
280 
281  // signals and slots
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()));
294 
295  connect(_ui->saveGeometryOnExitButton, SIGNAL(toggled(bool)), this,
296  SLOT(saveGeometryOnExit(bool)));
297  connect(_ui->showTerminalSizeHintButton, SIGNAL(toggled(bool)), this,
298  SLOT(showTerminalSizeHint(bool)));
299 }
300 void EditProfileDialog::showEnvironmentEditor()
301 {
302  const Profile::Ptr profile = lookupProfile();
303 
304  QWeakPointer<KDialog> dialog = new KDialog(this);
305  KTextEdit* edit = new KTextEdit(dialog.data());
306 
307  QStringList currentEnvironment = profile->environment();
308 
309  edit->setPlainText(currentEnvironment.join("\n"));
310  edit->setToolTip(i18nc("@info:tooltip", "One environment variable per line"));
311 
312  dialog.data()->setPlainCaption(i18n("Edit Environment"));
313  dialog.data()->setMainWidget(edit);
314 
315  if (dialog.data()->exec() == QDialog::Accepted) {
316  QStringList newEnvironment = edit->toPlainText().split('\n');
317  updateTempProfileProperty(Profile::Environment, newEnvironment);
318  }
319 
320  delete dialog.data();
321 }
322 void EditProfileDialog::setupTabsPage(const Profile::Ptr profile)
323 {
324  // tab title format
325  _ui->renameTabWidget->setTabTitleText(profile->localTabTitleFormat());
326  _ui->renameTabWidget->setRemoteTabTitleText(profile->remoteTabTitleFormat());
327 
328  connect(_ui->renameTabWidget, SIGNAL(tabTitleFormatChanged(QString)), this,
329  SLOT(tabTitleFormatChanged(QString)));
330  connect(_ui->renameTabWidget, SIGNAL(remoteTabTitleFormatChanged(QString)), this,
331  SLOT(remoteTabTitleFormatChanged(QString)));
332 
333  // tab monitoring
334  const int silenceSeconds = profile->silenceSeconds();
335  _ui->silenceSecondsSpinner->setValue(silenceSeconds);
336  _ui->silenceSecondsSpinner->setSuffix(ki18ncp("Unit of time", " second", " seconds"));
337 
338  connect(_ui->silenceSecondsSpinner, SIGNAL(valueChanged(int)),
339  this, SLOT(silenceSecondsChanged(int)));
340 }
341 
342 void EditProfileDialog::saveGeometryOnExit(bool value)
343 {
344  updateTempProfileProperty(Profile::SaveGeometryOnExit, value);
345 }
346 void EditProfileDialog::showTerminalSizeHint(bool value)
347 {
348  updateTempProfileProperty(Profile::ShowTerminalSizeHint, value);
349 }
350 void EditProfileDialog::tabTitleFormatChanged(const QString& format)
351 {
352  updateTempProfileProperty(Profile::LocalTabTitleFormat, format);
353 }
354 void EditProfileDialog::remoteTabTitleFormatChanged(const QString& format)
355 {
356  updateTempProfileProperty(Profile::RemoteTabTitleFormat, format);
357 }
358 
359 void EditProfileDialog::silenceSecondsChanged(int seconds)
360 {
361  updateTempProfileProperty(Profile::SilenceSeconds, seconds);
362 }
363 
364 void EditProfileDialog::selectIcon()
365 {
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));
370  updateTempProfileProperty(Profile::Icon, icon);
371  }
372 }
373 void EditProfileDialog::profileNameChanged(const QString& text)
374 {
375  _ui->emptyNameWarningWidget->setVisible(text.isEmpty());
376 
377  updateTempProfileProperty(Profile::Name, text);
378  updateTempProfileProperty(Profile::UntranslatedName, text);
379  updateCaption(_tempProfile);
380 }
381 void EditProfileDialog::startInSameDir(bool sameDir)
382 {
383  updateTempProfileProperty(Profile::StartInCurrentSessionDir, sameDir);
384 }
385 void EditProfileDialog::initialDirChanged(const QString& dir)
386 {
387  updateTempProfileProperty(Profile::Directory, dir);
388 }
389 void EditProfileDialog::commandChanged(const QString& command)
390 {
391  ShellCommand shellCommand(command);
392 
393  updateTempProfileProperty(Profile::Command, shellCommand.command());
394  updateTempProfileProperty(Profile::Arguments, shellCommand.arguments());
395 }
396 void EditProfileDialog::selectInitialDir()
397 {
398  const KUrl url = KFileDialog::getExistingDirectoryUrl(_ui->initialDirEdit->text(),
399  this,
400  i18n("Select Initial Directory"));
401 
402  if (!url.isEmpty())
403  _ui->initialDirEdit->setText(url.path());
404 }
405 void EditProfileDialog::setupAppearancePage(const Profile::Ptr profile)
406 {
407  ColorSchemeViewDelegate* delegate = new ColorSchemeViewDelegate(this);
408  _ui->colorSchemeList->setItemDelegate(delegate);
409 
410  _ui->transparencyWarningWidget->setVisible(false);
411  _ui->transparencyWarningWidget->setWordWrap(true);
412  _ui->transparencyWarningWidget->setCloseButtonVisible(false);
413  _ui->transparencyWarningWidget->setMessageType(KMessageWidget::Warning);
414 
415  _ui->editColorSchemeButton->setEnabled(false);
416  _ui->removeColorSchemeButton->setEnabled(false);
417 
418  // setup color list
419  updateColorSchemeList(true);
420 
421  _ui->colorSchemeList->setMouseTracking(true);
422  _ui->colorSchemeList->installEventFilter(this);
423  _ui->colorSchemeList->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
424 
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)));
430 
431  updateColorSchemeButtons();
432 
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()));
439 
440  // setup font preview
441  const bool antialias = profile->antiAliasFonts();
442 
443  QFont profileFont = profile->font();
444  profileFont.setStyleStrategy(antialias ? QFont::PreferAntialias : QFont::NoAntialias);
445 
446  _ui->fontPreviewLabel->installEventFilter(this);
447  _ui->fontPreviewLabel->setFont(profileFont);
448  setFontInputValue(profileFont);
449 
450  connect(_ui->fontSizeInput, SIGNAL(valueChanged(double)), this,
451  SLOT(setFontSize(double)));
452  connect(_ui->selectFontButton, SIGNAL(clicked()), this,
453  SLOT(showFontDialog()));
454 
455  // setup font smoothing
456  _ui->antialiasTextButton->setChecked(antialias);
457  connect(_ui->antialiasTextButton, SIGNAL(toggled(bool)), this,
458  SLOT(setAntialiasText(bool)));
459 
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)));
466 }
467 void EditProfileDialog::setAntialiasText(bool enable)
468 {
469  QFont profileFont = _ui->fontPreviewLabel->font();
470  profileFont.setStyleStrategy(enable ? QFont::PreferAntialias : QFont::NoAntialias);
471 
472  // update preview to reflect text smoothing state
473  fontSelected(profileFont);
474  updateTempProfileProperty(Profile::AntiAliasFonts, enable);
475 }
476 void EditProfileDialog::setBoldIntense(bool enable)
477 {
478  preview(Profile::BoldIntense, enable);
479  updateTempProfileProperty(Profile::BoldIntense, enable);
480 }
481 void EditProfileDialog::toggleMouseWheelZoom(bool enable)
482 {
483  updateTempProfileProperty(Profile::MouseWheelZoomEnabled, enable);
484 }
485 void EditProfileDialog::updateColorSchemeList(bool selectCurrentScheme)
486 {
487  if (!_ui->colorSchemeList->model())
488  _ui->colorSchemeList->setModel(new QStandardItemModel(this));
489 
490  const QString& name = lookupProfile()->colorScheme();
491  const ColorScheme* currentScheme = ColorSchemeManager::instance()->findColorScheme(name);
492 
493  QStandardItemModel* model = qobject_cast<QStandardItemModel*>(_ui->colorSchemeList->model());
494 
495  Q_ASSERT(model);
496 
497  model->clear();
498 
499  QStandardItem* selectedItem = 0;
500 
501  QList<const ColorScheme*> schemeList = ColorSchemeManager::instance()->allColorSchemes();
502 
503  foreach(const ColorScheme* scheme, schemeList) {
504  QStandardItem* item = new QStandardItem(scheme->description());
505  item->setData(QVariant::fromValue(scheme) , Qt::UserRole + 1);
506  item->setFlags(item->flags());
507 
508  if (currentScheme == scheme)
509  selectedItem = item;
510 
511  model->appendRow(item);
512  }
513 
514  model->sort(0);
515 
516  if (selectCurrentScheme && selectedItem) {
517  _ui->colorSchemeList->updateGeometry();
518  _ui->colorSchemeList->selectionModel()->setCurrentIndex(selectedItem->index() ,
519  QItemSelectionModel::Select);
520 
521  // update transparency warning label
522  updateTransparencyWarning();
523  }
524 }
525 void EditProfileDialog::updateKeyBindingsList(bool selectCurrentTranslator)
526 {
527  if (!_ui->keyBindingList->model())
528  _ui->keyBindingList->setModel(new QStandardItemModel(this));
529 
530  const QString& name = lookupProfile()->keyBindings();
531 
532  KeyboardTranslatorManager* keyManager = KeyboardTranslatorManager::instance();
533  const KeyboardTranslator* currentTranslator = keyManager->findTranslator(name);
534 
535  QStandardItemModel* model = qobject_cast<QStandardItemModel*>(_ui->keyBindingList->model());
536 
537  Q_ASSERT(model);
538 
539  model->clear();
540 
541  QStandardItem* selectedItem = 0;
542 
543  QStringList translatorNames = keyManager->allTranslators();
544  foreach(const QString& translatorName, translatorNames) {
545  const KeyboardTranslator* translator = keyManager->findTranslator(translatorName);
546 
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"));
551 
552  if (translator == currentTranslator)
553  selectedItem = item;
554 
555  model->appendRow(item);
556  }
557 
558  model->sort(0);
559 
560  if (selectCurrentTranslator && selectedItem) {
561  _ui->keyBindingList->selectionModel()->setCurrentIndex(selectedItem->index() ,
562  QItemSelectionModel::Select);
563  }
564 }
565 bool EditProfileDialog::eventFilter(QObject* watched , QEvent* aEvent)
566 {
567  if (watched == _ui->colorSchemeList && aEvent->type() == QEvent::Leave) {
568  if (_tempProfile->isPropertySet(Profile::ColorScheme))
569  preview(Profile::ColorScheme, _tempProfile->colorScheme());
570  else
571  unpreview(Profile::ColorScheme);
572  }
573  if (watched == _ui->fontPreviewLabel && aEvent->type() == QEvent::FontChange) {
574  const QFont& labelFont = _ui->fontPreviewLabel->font();
575  _ui->fontPreviewLabel->setText(i18n("%1", labelFont.family()));
576  }
577 
578  return KDialog::eventFilter(watched, aEvent);
579 }
580 void EditProfileDialog::unpreviewAll()
581 {
582  _delayedPreviewTimer->stop();
583  _delayedPreviewProperties.clear();
584 
585  QHash<Profile::Property, QVariant> map;
586  QHashIterator<int, QVariant> iter(_previewedProperties);
587  while (iter.hasNext()) {
588  iter.next();
589  map.insert((Profile::Property)iter.key(), iter.value());
590  }
591 
592  // undo any preview changes
593  if (!map.isEmpty())
594  ProfileManager::instance()->changeProfile(_profile, map, false);
595 }
596 void EditProfileDialog::unpreview(int aProperty)
597 {
598  _delayedPreviewProperties.remove(aProperty);
599 
600  if (!_previewedProperties.contains(aProperty))
601  return;
602 
603  QHash<Profile::Property, QVariant> map;
604  map.insert((Profile::Property)aProperty, _previewedProperties[aProperty]);
605  ProfileManager::instance()->changeProfile(_profile, map, false);
606 
607  _previewedProperties.remove(aProperty);
608 }
609 void EditProfileDialog::delayedPreview(int aProperty , const QVariant& value)
610 {
611  _delayedPreviewProperties.insert(aProperty, value);
612 
613  _delayedPreviewTimer->stop();
614  _delayedPreviewTimer->start(300);
615 }
616 void EditProfileDialog::delayedPreviewActivate()
617 {
618  Q_ASSERT(qobject_cast<QTimer*>(sender()));
619 
620  QMutableHashIterator<int, QVariant> iter(_delayedPreviewProperties);
621  if (iter.hasNext()) {
622  iter.next();
623  preview(iter.key(), iter.value());
624  }
625 }
626 void EditProfileDialog::preview(int aProperty , const QVariant& value)
627 {
628  QHash<Profile::Property, QVariant> map;
629  map.insert((Profile::Property)aProperty, value);
630 
631  _delayedPreviewProperties.remove(aProperty);
632 
633  const Profile::Ptr original = lookupProfile();
634 
635  // skip previews for profile groups if the profiles in the group
636  // have conflicting original values for the property
637  //
638  // TODO - Save the original values for each profile and use to unpreview properties
639  ProfileGroup::Ptr group = original->asGroup();
640  if (group && group->profiles().count() > 1 &&
641  original->property<QVariant>((Profile::Property)aProperty).isNull())
642  return;
643 
644  if (!_previewedProperties.contains(aProperty)) {
645  _previewedProperties.insert(aProperty , original->property<QVariant>((Profile::Property)aProperty));
646  }
647 
648  // temporary change to color scheme
649  ProfileManager::instance()->changeProfile(_profile , map , false);
650 }
651 void EditProfileDialog::previewColorScheme(const QModelIndex& index)
652 {
653  const QString& name = index.data(Qt::UserRole + 1).value<const ColorScheme*>()->name();
654 
655  delayedPreview(Profile::ColorScheme , name);
656 }
657 void EditProfileDialog::removeColorScheme()
658 {
659  QModelIndexList selected = _ui->colorSchemeList->selectionModel()->selectedIndexes();
660 
661  if (!selected.isEmpty()) {
662  const QString& name = selected.first().data(Qt::UserRole + 1).value<const ColorScheme*>()->name();
663 
664  if (ColorSchemeManager::instance()->deleteColorScheme(name))
665  _ui->colorSchemeList->model()->removeRow(selected.first().row());
666  }
667 }
668 void EditProfileDialog::showColorSchemeEditor(bool isNewScheme)
669 {
670  // Finding selected ColorScheme
671  QModelIndexList selected = _ui->colorSchemeList->selectionModel()->selectedIndexes();
672  QAbstractItemModel* model = _ui->colorSchemeList->model();
673  const ColorScheme* colors = 0;
674  if (!selected.isEmpty())
675  colors = model->data(selected.first(), Qt::UserRole + 1).value<const ColorScheme*>();
676  else
677  colors = ColorSchemeManager::instance()->defaultColorScheme();
678 
679  Q_ASSERT(colors);
680 
681  // Setting up ColorSchemeEditor ui
682  // close any running ColorSchemeEditor
683  if (_colorDialog) {
684  closeColorSchemeEditor();
685  }
686  _colorDialog = new ColorSchemeEditor(this);
687 
688  connect(_colorDialog, SIGNAL(colorSchemeSaveRequested(ColorScheme,bool)),
689  this, SLOT(saveColorScheme(ColorScheme,bool)));
690  _colorDialog->setup(colors, isNewScheme);
691 
692  _colorDialog->show();
693 }
694 void EditProfileDialog::closeColorSchemeEditor()
695 {
696  if (_colorDialog) {
697  _colorDialog->close();
698  delete _colorDialog;
699  }
700 }
701 void EditProfileDialog::newColorScheme()
702 {
703  showColorSchemeEditor(true);
704 }
705 void EditProfileDialog::editColorScheme()
706 {
707  showColorSchemeEditor(false);
708 }
709 void EditProfileDialog::saveColorScheme(const ColorScheme& scheme, bool isNewScheme)
710 {
711  ColorScheme* newScheme = new ColorScheme(scheme);
712 
713  // if this is a new color scheme, pick a name based on the description
714  if (isNewScheme) {
715  newScheme->setName(newScheme->description());
716  }
717 
718  ColorSchemeManager::instance()->addColorScheme(newScheme);
719 
720  updateColorSchemeList(true);
721 
722  preview(Profile::ColorScheme, newScheme->name());
723 }
724 void EditProfileDialog::colorSchemeSelected()
725 {
726  QModelIndexList selected = _ui->colorSchemeList->selectionModel()->selectedIndexes();
727 
728  if (!selected.isEmpty()) {
729  QAbstractItemModel* model = _ui->colorSchemeList->model();
730  const ColorScheme* colors = model->data(selected.first(), Qt::UserRole + 1).value<const ColorScheme*>();
731  if (colors) {
732  updateTempProfileProperty(Profile::ColorScheme, colors->name());
733  previewColorScheme(selected.first());
734 
735  updateTransparencyWarning();
736  }
737  }
738 
739  updateColorSchemeButtons();
740 }
741 void EditProfileDialog::updateColorSchemeButtons()
742 {
743  enableIfNonEmptySelection(_ui->editColorSchemeButton, _ui->colorSchemeList->selectionModel());
744  enableIfNonEmptySelection(_ui->removeColorSchemeButton, _ui->colorSchemeList->selectionModel());
745 }
746 void EditProfileDialog::updateKeyBindingsButtons()
747 {
748  enableIfNonEmptySelection(_ui->editKeyBindingsButton, _ui->keyBindingList->selectionModel());
749  enableIfNonEmptySelection(_ui->removeKeyBindingsButton, _ui->keyBindingList->selectionModel());
750 }
751 void EditProfileDialog::enableIfNonEmptySelection(QWidget* widget, QItemSelectionModel* selectionModel)
752 {
753  widget->setEnabled(selectionModel->hasSelection());
754 }
755 void EditProfileDialog::updateTransparencyWarning()
756 {
757  // zero or one indexes can be selected
758  foreach(const QModelIndex & index , _ui->colorSchemeList->selectionModel()->selectedIndexes()) {
759  bool needTransparency = index.data(Qt::UserRole + 1).value<const ColorScheme*>()->opacity() < 1.0;
760 
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"
766  " desktop"));
767  _ui->transparencyWarningWidget->setHidden(false);
768  } else if (!WindowSystemInfo::HAVE_TRANSPARENCY) {
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);
772  }
773  }
774 }
775 
776 void EditProfileDialog::createTempProfile()
777 {
778  _tempProfile = Profile::Ptr(new Profile);
779  _tempProfile->setHidden(true);
780 }
781 
782 void EditProfileDialog::updateTempProfileProperty(Profile::Property aProperty, const QVariant & value)
783 {
784  _tempProfile->setProperty(aProperty, value);
785  updateButtonApply();
786 }
787 
788 void EditProfileDialog::updateButtonApply()
789 {
790  bool userModified = false;
791 
792  QHashIterator<Profile::Property, QVariant> iter(_tempProfile->setProperties());
793  while (iter.hasNext()) {
794  iter.next();
795 
796  Profile::Property aProperty = iter.key();
797  QVariant value = iter.value();
798 
799  // for previewed property
800  if (_previewedProperties.contains(static_cast<int>(aProperty))) {
801  if (value != _previewedProperties.value(static_cast<int>(aProperty))) {
802  userModified = true;
803  break;
804  }
805  // for not-previewed property
806  } else if ((value != _profile->property<QVariant>(aProperty))) {
807  userModified = true;
808  break;
809  }
810  }
811 
812  enableButtonApply(userModified);
813 }
814 
815 void EditProfileDialog::setupKeyboardPage(const Profile::Ptr /* profile */)
816 {
817  // setup translator list
818  updateKeyBindingsList(true);
819 
820  connect(_ui->keyBindingList->selectionModel(),
821  SIGNAL(selectionChanged(QItemSelection,QItemSelection)),
822  SLOT(keyBindingSelected()));
823  connect(_ui->newKeyBindingsButton, SIGNAL(clicked()), this,
824  SLOT(newKeyBinding()));
825 
826  updateKeyBindingsButtons();
827 
828  connect(_ui->editKeyBindingsButton, SIGNAL(clicked()), this,
829  SLOT(editKeyBinding()));
830  connect(_ui->removeKeyBindingsButton, SIGNAL(clicked()), this,
831  SLOT(removeKeyBinding()));
832 }
833 void EditProfileDialog::keyBindingSelected()
834 {
835  QModelIndexList selected = _ui->keyBindingList->selectionModel()->selectedIndexes();
836 
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*>();
841  if (translator) {
842  updateTempProfileProperty(Profile::KeyBindings, translator->name());
843  }
844  }
845 
846  updateKeyBindingsButtons();
847 }
848 void EditProfileDialog::removeKeyBinding()
849 {
850  QModelIndexList selected = _ui->keyBindingList->selectionModel()->selectedIndexes();
851 
852  if (!selected.isEmpty()) {
853  const QString& name = selected.first().data(Qt::UserRole + 1).value<const KeyboardTranslator*>()->name();
854  if (KeyboardTranslatorManager::instance()->deleteTranslator(name))
855  _ui->keyBindingList->model()->removeRow(selected.first().row());
856  }
857 }
858 void EditProfileDialog::showKeyBindingEditor(bool isNewTranslator)
859 {
860  QModelIndexList selected = _ui->keyBindingList->selectionModel()->selectedIndexes();
861  QAbstractItemModel* model = _ui->keyBindingList->model();
862 
863  const KeyboardTranslator* translator = 0;
864  if (!selected.isEmpty())
865  translator = model->data(selected.first(), Qt::UserRole + 1).value<const KeyboardTranslator*>();
866  else
867  translator = KeyboardTranslatorManager::instance()->defaultTranslator();
868 
869  Q_ASSERT(translator);
870 
871  QWeakPointer<KDialog> dialog = new KDialog(this);
872 
873  if (isNewTranslator)
874  dialog.data()->setCaption(i18n("New Key Binding List"));
875  else
876  dialog.data()->setCaption(i18n("Edit Key Binding List"));
877 
878  KeyBindingEditor* editor = new KeyBindingEditor;
879  dialog.data()->setMainWidget(editor);
880 
881  if (translator)
882  editor->setup(translator);
883 
884  if (isNewTranslator)
885  editor->setDescription(i18n("New Key Binding List"));
886 
887  if (dialog.data()->exec() == QDialog::Accepted) {
888  KeyboardTranslator* newTranslator = new KeyboardTranslator(*editor->translator());
889 
890  if (isNewTranslator)
891  newTranslator->setName(newTranslator->description());
892 
893  KeyboardTranslatorManager::instance()->addTranslator(newTranslator);
894 
895  updateKeyBindingsList();
896 
897  const QString& currentTranslator = lookupProfile()
898  ->property<QString>(Profile::KeyBindings);
899 
900  if (newTranslator->name() == currentTranslator) {
901  updateTempProfileProperty(Profile::KeyBindings, newTranslator->name());
902  }
903  }
904  delete dialog.data();
905 }
906 void EditProfileDialog::newKeyBinding()
907 {
908  showKeyBindingEditor(true);
909 }
910 void EditProfileDialog::editKeyBinding()
911 {
912  showKeyBindingEditor(false);
913 }
914 void EditProfileDialog::setupCheckBoxes(BooleanOption* options , const Profile::Ptr profile)
915 {
916  while (options->button != 0) {
917  options->button->setChecked(profile->property<bool>(options->property));
918  connect(options->button, SIGNAL(toggled(bool)), this, options->slot);
919 
920  ++options;
921  }
922 }
923 void EditProfileDialog::setupRadio(RadioOption* possibilities , int actual)
924 {
925  while (possibilities->button != 0) {
926  if (possibilities->value == actual)
927  possibilities->button->setChecked(true);
928  else
929  possibilities->button->setChecked(false);
930 
931  connect(possibilities->button, SIGNAL(clicked()), this, possibilities->slot);
932 
933  ++possibilities;
934  }
935 }
936 
937 void EditProfileDialog::setupScrollingPage(const Profile::Ptr profile)
938 {
939  // setup scrollbar radio
940  int scrollBarPosition = profile->property<int>(Profile::ScrollBarPosition);
941 
942  RadioOption positions[] = { {_ui->scrollBarHiddenButton, Enum::ScrollBarHidden, SLOT(hideScrollBar())},
943  {_ui->scrollBarLeftButton, Enum::ScrollBarLeft, SLOT(showScrollBarLeft())},
944  {_ui->scrollBarRightButton, Enum::ScrollBarRight, SLOT(showScrollBarRight())},
945  {0, 0, 0}
946  };
947 
948  setupRadio(positions , scrollBarPosition);
949 
950  // setup scrollback type radio
951  int scrollBackType = profile->property<int>(Profile::HistoryMode);
952  _ui->historySizeWidget->setMode(Enum::HistoryModeEnum(scrollBackType));
953  connect(_ui->historySizeWidget, SIGNAL(historyModeChanged(Enum::HistoryModeEnum)),
954  this, SLOT(historyModeChanged(Enum::HistoryModeEnum)));
955 
956  // setup scrollback line count spinner
957  const int historySize = profile->historySize();
958  _ui->historySizeWidget->setLineCount(historySize);
959 
960  // setup scrollpageamount type radio
961  int scrollFullPage = profile->property<int>(Profile::ScrollFullPage);
962 
963  RadioOption pageamounts[] = {
964  {_ui->scrollHalfPage, Enum::ScrollPageHalf, SLOT(scrollHalfPage())},
965  {_ui->scrollFullPage, Enum::ScrollPageFull, SLOT(scrollFullPage())},
966  {0, 0, 0}
967  };
968 
969  setupRadio(pageamounts, scrollFullPage);
970 
971  // signals and slots
972  connect(_ui->historySizeWidget, SIGNAL(historySizeChanged(int)),
973  this, SLOT(historySizeChanged(int)));
974 }
975 
976 void EditProfileDialog::historySizeChanged(int lineCount)
977 {
978  updateTempProfileProperty(Profile::HistorySize , lineCount);
979 }
980 void EditProfileDialog::historyModeChanged(Enum::HistoryModeEnum mode)
981 {
982  updateTempProfileProperty(Profile::HistoryMode, mode);
983 }
984 void EditProfileDialog::hideScrollBar()
985 {
986  updateTempProfileProperty(Profile::ScrollBarPosition, Enum::ScrollBarHidden);
987 }
988 void EditProfileDialog::showScrollBarLeft()
989 {
990  updateTempProfileProperty(Profile::ScrollBarPosition, Enum::ScrollBarLeft);
991 }
992 void EditProfileDialog::showScrollBarRight()
993 {
994  updateTempProfileProperty(Profile::ScrollBarPosition, Enum::ScrollBarRight);
995 }
996 void EditProfileDialog::scrollFullPage()
997 {
998  updateTempProfileProperty(Profile::ScrollFullPage, Enum::ScrollPageFull);
999 }
1000 void EditProfileDialog::scrollHalfPage()
1001 {
1002  updateTempProfileProperty(Profile::ScrollFullPage, Enum::ScrollPageHalf);
1003 }
1004 void EditProfileDialog::setupMousePage(const Profile::Ptr profile)
1005 {
1006  BooleanOption options[] = { {
1007  _ui->underlineLinksButton , Profile::UnderlineLinksEnabled,
1008  SLOT(toggleUnderlineLinks(bool))
1009  },
1010  {
1011  _ui->ctrlRequiredForDragButton, Profile::CtrlRequiredForDrag,
1012  SLOT(toggleCtrlRequiredForDrag(bool))
1013  },
1014  {
1015  _ui->copyTextToClipboardButton , Profile::AutoCopySelectedText,
1016  SLOT(toggleCopyTextToClipboard(bool))
1017  },
1018  {
1019  _ui->trimTrailingSpacesButton , Profile::TrimTrailingSpacesInSelectedText,
1020  SLOT(toggleTrimTrailingSpacesInSelectedText(bool))
1021  },
1022  {
1023  _ui->openLinksByDirectClickButton , Profile::OpenLinksByDirectClickEnabled,
1024  SLOT(toggleOpenLinksByDirectClick(bool))
1025  },
1026  { 0 , Profile::Property(0) , 0 }
1027  };
1028  setupCheckBoxes(options , profile);
1029 
1030  // setup middle click paste mode
1031  const int middleClickPasteMode = profile->property<int>(Profile::MiddleClickPasteMode);
1032  RadioOption pasteModes[] = {
1033  {_ui->pasteFromX11SelectionButton, Enum::PasteFromX11Selection, SLOT(pasteFromX11Selection())},
1034  {_ui->pasteFromClipboardButton, Enum::PasteFromClipboard, SLOT(pasteFromClipboard())},
1035  {0, 0, 0}
1036  };
1037  setupRadio(pasteModes , middleClickPasteMode);
1038 
1039  // interaction options
1040  _ui->wordCharacterEdit->setText(profile->wordCharacters());
1041 
1042  connect(_ui->wordCharacterEdit, SIGNAL(textChanged(QString)), this,
1043  SLOT(wordCharactersChanged(QString)));
1044 
1045  int tripleClickMode = profile->property<int>(Profile::TripleClickMode);
1046  _ui->tripleClickModeCombo->setCurrentIndex(tripleClickMode);
1047 
1048  connect(_ui->tripleClickModeCombo, SIGNAL(activated(int)), this,
1049  SLOT(TripleClickModeChanged(int)));
1050 
1051  _ui->openLinksByDirectClickButton->setEnabled(_ui->underlineLinksButton->isChecked());
1052 
1053  _ui->enableMouseWheelZoomButton->setChecked(profile->mouseWheelZoomEnabled());
1054  connect(_ui->enableMouseWheelZoomButton, SIGNAL(toggled(bool)), this,
1055  SLOT(toggleMouseWheelZoom(bool)));
1056 }
1057 void EditProfileDialog::setupAdvancedPage(const Profile::Ptr profile)
1058 {
1059  BooleanOption options[] = { {
1060  _ui->enableBlinkingTextButton , Profile::BlinkingTextEnabled ,
1061  SLOT(toggleBlinkingText(bool))
1062  },
1063  {
1064  _ui->enableFlowControlButton , Profile::FlowControlEnabled ,
1065  SLOT(toggleFlowControl(bool))
1066  },
1067  {
1068  _ui->enableBlinkingCursorButton , Profile::BlinkingCursorEnabled ,
1069  SLOT(toggleBlinkingCursor(bool))
1070  },
1071  {
1072  _ui->enableBidiRenderingButton , Profile::BidiRenderingEnabled ,
1073  SLOT(togglebidiRendering(bool))
1074  },
1075  { 0 , Profile::Property(0) , 0 }
1076  };
1077  setupCheckBoxes(options , profile);
1078 
1079  const int lineSpacing = profile->lineSpacing();
1080  _ui->lineSpacingSpinner->setValue(lineSpacing);
1081 
1082  connect(_ui->lineSpacingSpinner, SIGNAL(valueChanged(int)),
1083  this, SLOT(lineSpacingChanged(int)));
1084 
1085  // cursor options
1086  if (profile->useCustomCursorColor())
1087  _ui->customCursorColorButton->setChecked(true);
1088  else
1089  _ui->autoCursorColorButton->setChecked(true);
1090 
1091  _ui->customColorSelectButton->setColor(profile->customCursorColor());
1092 
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)));
1097 
1098  int shape = profile->property<int>(Profile::CursorShape);
1099  _ui->cursorShapeCombo->setCurrentIndex(shape);
1100 
1101  connect(_ui->cursorShapeCombo, SIGNAL(activated(int)), this, SLOT(setCursorShape(int)));
1102 
1103  // encoding options
1104  QAction* codecAction = new KCodecAction(this);
1105  _ui->selectEncodingButton->setMenu(codecAction->menu());
1106  connect(codecAction, SIGNAL(triggered(QTextCodec*)), this, SLOT(setDefaultCodec(QTextCodec*)));
1107 
1108  _ui->characterEncodingLabel->setText(profile->defaultEncoding());
1109 }
1110 void EditProfileDialog::setDefaultCodec(QTextCodec* codec)
1111 {
1112  QString name = QString(codec->name());
1113 
1114  updateTempProfileProperty(Profile::DefaultEncoding, name);
1115  _ui->characterEncodingLabel->setText(codec->name());
1116 }
1117 void EditProfileDialog::customCursorColorChanged(const QColor& color)
1118 {
1119  updateTempProfileProperty(Profile::CustomCursorColor, color);
1120 
1121  // ensure that custom cursor colors are enabled
1122  _ui->customCursorColorButton->click();
1123 }
1124 void EditProfileDialog::wordCharactersChanged(const QString& text)
1125 {
1126  updateTempProfileProperty(Profile::WordCharacters, text);
1127 }
1128 void EditProfileDialog::autoCursorColor()
1129 {
1130  updateTempProfileProperty(Profile::UseCustomCursorColor, false);
1131 }
1132 void EditProfileDialog::customCursorColor()
1133 {
1134  updateTempProfileProperty(Profile::UseCustomCursorColor, true);
1135 }
1136 void EditProfileDialog::setCursorShape(int index)
1137 {
1138  updateTempProfileProperty(Profile::CursorShape, index);
1139 }
1140 void EditProfileDialog::togglebidiRendering(bool enable)
1141 {
1142  updateTempProfileProperty(Profile::BidiRenderingEnabled, enable);
1143 }
1144 void EditProfileDialog::lineSpacingChanged(int spacing)
1145 {
1146  updateTempProfileProperty(Profile::LineSpacing, spacing);
1147 }
1148 void EditProfileDialog::toggleBlinkingCursor(bool enable)
1149 {
1150  updateTempProfileProperty(Profile::BlinkingCursorEnabled, enable);
1151 }
1152 void EditProfileDialog::toggleUnderlineLinks(bool enable)
1153 {
1154  updateTempProfileProperty(Profile::UnderlineLinksEnabled, enable);
1155  _ui->openLinksByDirectClickButton->setEnabled(enable);
1156 }
1157 void EditProfileDialog::toggleCtrlRequiredForDrag(bool enable)
1158 {
1159  updateTempProfileProperty(Profile::CtrlRequiredForDrag, enable);
1160 }
1161 void EditProfileDialog::toggleOpenLinksByDirectClick(bool enable)
1162 {
1163  updateTempProfileProperty(Profile::OpenLinksByDirectClickEnabled, enable);
1164 }
1165 void EditProfileDialog::toggleCopyTextToClipboard(bool enable)
1166 {
1167  updateTempProfileProperty(Profile::AutoCopySelectedText, enable);
1168 }
1169 void EditProfileDialog::toggleTrimTrailingSpacesInSelectedText(bool enable)
1170 {
1171  updateTempProfileProperty(Profile::TrimTrailingSpacesInSelectedText, enable);
1172 }
1173 void EditProfileDialog::pasteFromX11Selection()
1174 {
1175  updateTempProfileProperty(Profile::MiddleClickPasteMode, Enum::PasteFromX11Selection);
1176 }
1177 void EditProfileDialog::pasteFromClipboard()
1178 {
1179  updateTempProfileProperty(Profile::MiddleClickPasteMode, Enum::PasteFromClipboard);
1180 }
1181 void EditProfileDialog::TripleClickModeChanged(int newValue)
1182 {
1183  updateTempProfileProperty(Profile::TripleClickMode, newValue);
1184 }
1185 void EditProfileDialog::toggleBlinkingText(bool enable)
1186 {
1187  updateTempProfileProperty(Profile::BlinkingTextEnabled, enable);
1188 }
1189 void EditProfileDialog::toggleFlowControl(bool enable)
1190 {
1191  updateTempProfileProperty(Profile::FlowControlEnabled, enable);
1192 }
1193 void EditProfileDialog::fontSelected(const QFont& aFont)
1194 {
1195  QFont previewFont = aFont;
1196 
1197  setFontInputValue(aFont);
1198 
1199  _ui->fontPreviewLabel->setFont(previewFont);
1200 
1201  preview(Profile::Font, aFont);
1202  updateTempProfileProperty(Profile::Font, aFont);
1203 }
1204 void EditProfileDialog::showFontDialog()
1205 {
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();
1213 
1214  QWeakPointer<KFontDialog> dialog = new KFontDialog(this, KFontChooser::FixedFontsOnly);
1215  dialog.data()->setCaption(i18n("Select Fixed Width Font"));
1216  dialog.data()->setFont(currentFont, true);
1217 
1218  // TODO (hindenburg): When https://git.reviewboard.kde.org/r/103357 is
1219  // committed, change the below.
1220  // Use text more fitting to show font differences in a terminal
1221  QList<KFontChooser*> chooserList = dialog.data()->findChildren<KFontChooser*>();
1222  if (!chooserList.isEmpty())
1223  chooserList.at(0)->setSampleText(sampleText);
1224 
1225  connect(dialog.data(), SIGNAL(fontSelected(QFont)), this, SLOT(fontSelected(QFont)));
1226 
1227  if (dialog.data()->exec() == QDialog::Rejected)
1228  fontSelected(currentFont);
1229  delete dialog.data();
1230 }
1231 void EditProfileDialog::setFontSize(double pointSize)
1232 {
1233  QFont newFont = _ui->fontPreviewLabel->font();
1234  newFont.setPointSizeF(pointSize);
1235  _ui->fontPreviewLabel->setFont(newFont);
1236 
1237  preview(Profile::Font, newFont);
1238  updateTempProfileProperty(Profile::Font, newFont);
1239 }
1240 
1241 void EditProfileDialog::setFontInputValue(const QFont& aFont)
1242 {
1243  _ui->fontSizeInput->setValue(aFont.pointSizeF());
1244 }
1245 
1246 ColorSchemeViewDelegate::ColorSchemeViewDelegate(QObject* aParent)
1247  : QAbstractItemDelegate(aParent)
1248 {
1249 }
1250 
1251 void ColorSchemeViewDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option,
1252  const QModelIndex& index) const
1253 {
1254  const ColorScheme* scheme = index.data(Qt::UserRole + 1).value<const ColorScheme*>();
1255  Q_ASSERT(scheme);
1256  if (!scheme)
1257  return;
1258 
1259  bool transparencyAvailable = KWindowSystem::compositingActive();
1260 
1261  painter->setRenderHint(QPainter::Antialiasing);
1262 
1263  // draw background
1264  painter->setPen(QPen(scheme->foregroundColor() , 1));
1265 
1266  // radial gradient for background
1267  // from a lightened version of the scheme's background color in the center to
1268  // a darker version at the outer edge
1269  QColor color = scheme->backgroundColor();
1270  QRectF backgroundRect = QRectF(option.rect).adjusted(1.5, 1.5, -1.5, -1.5);
1271 
1272  QRadialGradient backgroundGradient(backgroundRect.center() , backgroundRect.width() / 2);
1273  backgroundGradient.setColorAt(0 , color.lighter(105));
1274  backgroundGradient.setColorAt(1 , color.darker(115));
1275 
1276  const int backgroundRectXRoundness = 4;
1277  const int backgroundRectYRoundness = 30;
1278 
1279  QPainterPath backgroundRectPath(backgroundRect.topLeft());
1280  backgroundRectPath.addRoundRect(backgroundRect , backgroundRectXRoundness , backgroundRectYRoundness);
1281 
1282  if (transparencyAvailable) {
1283  painter->save();
1284  color.setAlphaF(scheme->opacity());
1285  painter->setCompositionMode(QPainter::CompositionMode_Source);
1286  painter->setBrush(backgroundGradient);
1287 
1288  painter->drawPath(backgroundRectPath);
1289  painter->restore();
1290  } else {
1291  painter->setBrush(backgroundGradient);
1292  painter->drawPath(backgroundRectPath);
1293  }
1294 
1295  // draw stripe at the side using scheme's foreground color
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());
1301  painter->setBrush(scheme->foregroundColor());
1302  painter->drawPath(path.intersected(backgroundRectPath));
1303 
1304  // draw highlight
1305  // with a linear gradient going from translucent white to transparent
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);
1311 
1312  //const bool isChecked = index.data(Qt::CheckStateRole) == Qt::Checked;
1313  const bool isSelected = option.state & QStyle::State_Selected;
1314 
1315  // draw border on selected items
1316  if (isSelected) { //|| isChecked )
1317  static const int selectedBorderWidth = 6;
1318 
1319  painter->setBrush(QBrush(Qt::NoBrush));
1320  QPen pen;
1321 
1322  QColor highlightColor = option.palette.highlight().color();
1323 
1324  if (isSelected)
1325  highlightColor.setAlphaF(1.0);
1326  else
1327  highlightColor.setAlphaF(0.7);
1328 
1329  pen.setBrush(highlightColor);
1330  pen.setWidth(selectedBorderWidth);
1331  pen.setJoinStyle(Qt::MiterJoin);
1332 
1333  painter->setPen(pen);
1334 
1335  painter->drawRect(option.rect.adjusted(selectedBorderWidth / 2,
1336  selectedBorderWidth / 2,
1337  -selectedBorderWidth / 2,
1338  -selectedBorderWidth / 2));
1339  }
1340 
1341  // draw color scheme name using scheme's foreground color
1342  QPen pen(scheme->foregroundColor());
1343  painter->setPen(pen);
1344 
1345  painter->drawText(option.rect , Qt::AlignCenter ,
1346  index.data(Qt::DisplayRole).value<QString>());
1347 }
1348 
1349 QSize ColorSchemeViewDelegate::sizeHint(const QStyleOptionViewItem& option,
1350  const QModelIndex& /*index*/) const
1351 {
1352  const int width = 200;
1353  qreal colorWidth = (qreal)width / TABLE_COLORS;
1354  int margin = 5;
1355  qreal heightForWidth = (colorWidth * 2) + option.fontMetrics.height() + margin;
1356 
1357  // temporary
1358  return QSize(width, static_cast<int>(heightForWidth));
1359 }
1360 
1361 #include "EditProfileDialog.moc"
Konsole::KeyboardTranslatorManager::addTranslator
void addTranslator(KeyboardTranslator *translator)
Adds a new translator.
Definition: KeyboardTranslatorManager.cpp:54
TABLE_COLORS
#define TABLE_COLORS
Definition: CharacterColor.h:118
Konsole::Profile::HistoryMode
(HistoryModeEnum) Specifies the storage type used for keeping the output produced by terminal session...
Definition: Profile.h:141
Konsole::Profile::DefaultEncoding
(String) Default text codec
Definition: Profile.h:225
Konsole::KeyboardTranslator
A converter which maps between key sequences pressed by the user and the character strings which shou...
Definition: KeyboardTranslator.h:52
QAbstractItemDelegate
Konsole::Profile::AntiAliasFonts
(bool) Whether fonts should be aliased or not
Definition: Profile.h:227
Konsole::Profile::ShowTerminalSizeHint
(bool) Specifies whether show hint for terminal size after resizing the application window...
Definition: Profile.h:120
Konsole::KeyboardTranslator::description
QString description() const
Returns the descriptive name of this keyboard translator.
Definition: KeyboardTranslator.cpp:641
Konsole::Profile::FlowControlEnabled
(bool) Specifies whether the flow control keys (typically Ctrl+S, Ctrl+Q) have any effect...
Definition: Profile.h:169
Konsole::Profile::CustomCursorColor
(QColor) The color used by terminal displays to draw the cursor.
Definition: Profile.h:191
KeyboardTranslatorManager.h
QWidget
Konsole::Profile::RemoteTabTitleFormat
(QString) The format used for tab titles when the session is running a remote command (eg...
Definition: Profile.h:116
Konsole::Profile::TrimTrailingSpacesInSelectedText
(bool) If true, trailing spaces are trimmed in selected text
Definition: Profile.h:213
Konsole::ProfileGroup::Ptr
KSharedPtr< ProfileGroup > Ptr
Definition: Profile.h:601
Konsole::Profile::KeyBindings
(QString) The name of the key bindings.
Definition: Profile.h:135
Konsole::Enum::ScrollPageFull
Scroll full page.
Definition: Enumeration.h:74
Konsole::Enum::PasteFromX11Selection
Paste from X11 Selection.
Definition: Enumeration.h:102
KDialog
Konsole::Profile::WordCharacters
(QString) A string consisting of the characters used to delimit words when selecting text in the term...
Definition: Profile.h:195
Konsole::Profile::SilenceSeconds
(int) Specifies the threshold of detected silence in seconds.
Definition: Profile.h:236
Konsole::ColorSchemeViewDelegate::paint
virtual void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
Definition: EditProfileDialog.cpp:1251
Konsole::Profile::MiddleClickPasteMode
(MiddleClickPasteModeEnum) Specifies the source from which mouse middle click pastes data...
Definition: Profile.h:223
Konsole::Profile::Font
(QFont) The font to use in terminal displays using this profile.
Definition: Profile.h:126
Konsole::Profile
Represents a terminal set-up which can be used to set the initial state of new terminal sessions or a...
Definition: Profile.h:60
QObject
ShellCommand.h
Konsole::Profile::Property
Property
This enum describes the available properties which a Profile may consist of.
Definition: Profile.h:77
Konsole::ColorSchemeViewDelegate::ColorSchemeViewDelegate
ColorSchemeViewDelegate(QObject *parent=0)
Definition: EditProfileDialog.cpp:1246
Konsole::Enum::ScrollBarHidden
Do not show the scroll-bar.
Definition: Enumeration.h:64
Konsole::Profile::Directory
(QString) The initial working directory for sessions created using this profile.
Definition: Profile.h:108
Konsole::KeyBindingEditor::translator
KeyboardTranslator * translator() const
Returns the modified translator describing the changes to the bindings and other settings which the u...
Definition: KeyBindingEditor.cpp:181
Konsole::Profile::BlinkingTextEnabled
(bool) Specifies whether text in terminal displays is allowed to blink.
Definition: Profile.h:165
ColorSchemeManager.h
Konsole::EditProfileDialog::accept
virtual void accept()
Definition: EditProfileDialog.cpp:129
Konsole::Enum::ScrollPageHalf
Scroll half page.
Definition: Enumeration.h:72
Konsole::Profile::Command
(QString) The command to execute ( excluding arguments ) when creating a new terminal session using t...
Definition: Profile.h:93
Konsole::Profile::UseCustomCursorColor
(bool) If true, terminal displays use a fixed color to draw the cursor, specified by the CustomCursor...
Definition: Profile.h:181
Konsole::EditProfileDialog::EditProfileDialog
EditProfileDialog(QWidget *parent=0)
Constructs a new dialog with the specified parent.
Definition: EditProfileDialog.cpp:67
Konsole::EditProfileDialog::eventFilter
virtual bool eventFilter(QObject *watched, QEvent *event)
Definition: EditProfileDialog.cpp:565
Konsole::Profile::UntranslatedName
(QString) The untranslated name of this profile.
Definition: Profile.h:85
Konsole::ColorSchemeManager::allColorSchemes
QList< const ColorScheme * > allColorSchemes()
Returns a list of the all the available color schemes.
Definition: ColorSchemeManager.cpp:204
Konsole::KeyboardTranslator::setName
void setName(const QString &name)
Sets the name of this keyboard translator.
Definition: KeyboardTranslator.cpp:646
Konsole::ShellCommand
A class to parse and extract information about shell commands.
Definition: ShellCommand.h:52
Konsole::ColorScheme::opacity
qreal opacity() const
Returns the opacity level for this color scheme, see setOpacity() TODO: More documentation.
Definition: ColorScheme.cpp:284
Konsole::Profile::BlinkingCursorEnabled
(bool) Specifies whether the cursor blinks ( in a manner similar to text editing applications ) ...
Definition: Profile.h:176
ColorSchemeEditor.h
Konsole::KeyboardTranslatorManager::allTranslators
QStringList allTranslators()
Returns a list of the names of available keyboard translators.
Definition: KeyboardTranslatorManager.cpp:188
Konsole::KeyBindingEditor::setDescription
void setDescription(const QString &description)
Sets the text of the editor's description field.
Definition: KeyBindingEditor.cpp:149
Konsole::Profile::AutoCopySelectedText
(bool) If true, automatically copy selected text into the clipboard
Definition: Profile.h:211
Konsole::ProfileManager::instance
static ProfileManager * instance()
Returns the profile manager instance.
Definition: ProfileManager.cpp:114
KeyboardTranslator.h
Konsole::Profile::StartInCurrentSessionDir
(bool) Whether new sessions should be started in the same directory as the currently active session...
Definition: Profile.h:234
Konsole::Profile::UnderlineLinksEnabled
(bool) If true, text that matches a link or an email address is underlined when hovered by the mouse ...
Definition: Profile.h:205
KeyBindingEditor.h
Konsole::Profile::BoldIntense
(bool) Whether character with intense colors should be rendered in bold font or just in bright color...
Definition: Profile.h:230
Konsole::Profile::ScrollFullPage
(bool) Specifies whether the PageUp/Down will scroll the full height or half height.
Definition: Profile.h:157
Konsole::KeyBindingEditor::setup
void setup(const KeyboardTranslator *translator)
Initializes the dialog with the bindings and other settings from the specified translator.
Definition: KeyBindingEditor.cpp:167
Konsole::Profile::LineSpacing
(int) Specifies the pixels between the terminal lines.
Definition: Profile.h:172
Konsole::Profile::Arguments
(QStringList) The arguments which are passed to the program specified by the Command property when cr...
Definition: Profile.h:98
Konsole::ColorSchemeManager::addColorScheme
void addColorScheme(ColorScheme *scheme)
Adds a new color scheme to the manager.
Definition: ColorSchemeManager.cpp:293
Konsole::Profile::Icon
(QString) The name of the icon associated with this profile.
Definition: Profile.h:89
EditProfileDialog.h
Konsole::Profile::TripleClickMode
(TripleClickModeEnum) Specifies which part of current line should be selected with triple click actio...
Definition: Profile.h:201
Enumeration.h
Konsole::ColorSchemeEditor::setup
void setup(const ColorScheme *scheme, bool isNewScheme)
Initializes the dialog with the properties of the specified color scheme.
Definition: ColorSchemeEditor.cpp:196
Konsole::Profile::BidiRenderingEnabled
(bool) Specifies whether the terminal will enable Bidirectional text display
Definition: Profile.h:161
Konsole::Enum::PasteFromClipboard
Paste from Clipboard.
Definition: Enumeration.h:104
Konsole::ColorScheme::description
QString description() const
Returns the descriptive name of the color scheme.
Definition: ColorScheme.cpp:166
Konsole::EditProfileDialog::reject
virtual void reject()
Definition: EditProfileDialog.cpp:124
Konsole::WindowSystemInfo::HAVE_TRANSPARENCY
static const bool HAVE_TRANSPARENCY
Definition: WindowSystemInfo.h:31
WindowSystemInfo.h
Konsole::ColorScheme::setName
void setName(const QString &name)
Sets the name of the color scheme.
Definition: ColorScheme.cpp:171
Konsole::Enum::HistoryModeEnum
HistoryModeEnum
This enum describes the modes available to remember lines of output produced by the terminal...
Definition: Enumeration.h:38
Konsole::KeyboardTranslatorManager::defaultTranslator
const KeyboardTranslator * defaultTranslator()
Returns the default translator for Konsole.
Definition: KeyboardTranslatorManager.cpp:177
Konsole::EditProfileDialog::lookupProfile
const Profile::Ptr lookupProfile() const
Definition: EditProfileDialog.cpp:197
ColorScheme.h
Konsole::Profile::Ptr
KSharedPtr< Profile > Ptr
Definition: Profile.h:67
Konsole::ColorSchemeViewDelegate::sizeHint
virtual QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
Definition: EditProfileDialog.cpp:1349
Konsole::ColorSchemeManager::findColorScheme
const ColorScheme * findColorScheme(const QString &name)
Returns the color scheme with the given name or 0 if no scheme with that name exists.
Definition: ColorSchemeManager.cpp:326
Konsole::KeyboardTranslator::name
QString name() const
Returns the name of this keyboard translator.
Definition: KeyboardTranslator.cpp:651
Konsole::Profile::HistorySize
(int) Specifies the number of lines of output to remember in terminal sessions using this profile...
Definition: Profile.h:147
Konsole::ColorSchemeViewDelegate
A delegate which can display and edit color schemes in a view.
Definition: EditProfileDialog.h:259
Konsole::ProfileManager::changeProfile
void changeProfile(Profile::Ptr profile, QHash< Profile::Property, QVariant > propertyMap, bool persistent=true)
Updates a profile with the changes specified in propertyMap.
Definition: ProfileManager.cpp:330
Konsole::Profile::CursorShape
(CursorShapeEnum) The shape used by terminal displays to represent the cursor.
Definition: Profile.h:187
ProfileManager.h
Konsole::ColorSchemeEditor
A dialog for editing color schemes.
Definition: ColorSchemeEditor.h:55
Konsole::EditProfileDialog::~EditProfileDialog
virtual ~EditProfileDialog()
Definition: EditProfileDialog.cpp:101
Konsole::Profile::ScrollBarPosition
(ScrollBarPositionEnum) Specifies the position of the scroll bar in terminal displays using this prof...
Definition: Profile.h:153
Konsole::EditProfileDialog::setProfile
void setProfile(Profile::Ptr profile)
Initializes the dialog with the settings for the specified session type.
Definition: EditProfileDialog.cpp:177
Konsole::Profile::SaveGeometryOnExit
(bool) Specifies whether the geometry information is saved when window is closed. ...
Definition: Profile.h:124
Konsole::KeyboardTranslatorManager::instance
static KeyboardTranslatorManager * instance()
Returns the global KeyboardTranslatorManager instance.
Definition: KeyboardTranslatorManager.cpp:49
Konsole::Profile::ColorScheme
(QString) The name of the color scheme to use in terminal displays using this profile.
Definition: Profile.h:131
Konsole::Profile::MouseWheelZoomEnabled
(bool) If true, mouse wheel scroll with Ctrl key pressed increases/decreases the terminal font size...
Definition: Profile.h:256
Konsole::ColorScheme::name
QString name() const
Returns the name of the color scheme.
Definition: ColorScheme.cpp:175
Konsole::Enum::ScrollBarRight
Show the scroll-bar on the right of the terminal display.
Definition: Enumeration.h:62
Konsole::ColorScheme::backgroundColor
QColor backgroundColor() const
Convenience method.
Definition: ColorScheme.cpp:270
Konsole::Profile::LocalTabTitleFormat
(QString) The format used for tab titles when running normal commands.
Definition: Profile.h:112
Konsole::ColorScheme::foregroundColor
QColor foregroundColor() const
Convenience method.
Definition: ColorScheme.cpp:266
Konsole::KeyboardTranslatorManager
Manages the keyboard translations available for use by terminal sessions, see KeyboardTranslator.
Definition: KeyboardTranslatorManager.h:41
Konsole::KeyBindingEditor
A dialog which allows the user to edit a key bindings list which maps between key combinations input ...
Definition: KeyBindingEditor.h:50
Konsole::Enum::ScrollBarLeft
Show the scroll-bar on the left of the terminal display.
Definition: Enumeration.h:60
Konsole::Profile::OpenLinksByDirectClickEnabled
(bool) If true, links can be opened by direct mouse click.
Definition: Profile.h:207
Konsole::ColorSchemeManager::defaultColorScheme
const ColorScheme * defaultColorScheme() const
Returns the default color scheme for Konsole.
Definition: ColorSchemeManager.cpp:288
Konsole::EditProfileDialog::selectProfileName
void selectProfileName()
Selects the text in the profile name edit area.
Definition: EditProfileDialog.cpp:231
Konsole::Profile::Name
(QString) The descriptive name of this profile.
Definition: Profile.h:81
Konsole::ColorSchemeManager::instance
static ColorSchemeManager * instance()
Returns the global color scheme manager instance.
Definition: ColorSchemeManager.cpp:172
QList
Konsole::ColorScheme
Represents a color scheme for a terminal display.
Definition: ColorScheme.h:72
Konsole::Profile::CtrlRequiredForDrag
(bool) If true, control key must be pressed to click and drag selected text.
Definition: Profile.h:209
Konsole::Profile::Environment
(QStringList) Additional environment variables (in the form of NAME=VALUE pairs) which are passed to ...
Definition: Profile.h:104
Konsole::KeyboardTranslatorManager::findTranslator
const KeyboardTranslator * findTranslator(const QString &name)
Returns the keyboard translator with the given name or 0 if no translator with that name exists...
Definition: KeyboardTranslatorManager.cpp:102
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:31:24 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

Konsole

Skip menu "Konsole"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

applications API Reference

Skip menu "applications API Reference"
  •   kate
  •       kate
  •   KTextEditor
  •   Kate
  • Applications
  •   Libraries
  •     libkonq
  • Konsole

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal