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

Konsole

  • kde-4.14
  • applications
  • konsole
  • src
ViewContainer.cpp
Go to the documentation of this file.
1 /*
2  This file is part of the Konsole Terminal.
3 
4  Copyright 2006-2008 Robert Knight <robertknight@gmail.com>
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with this program; if not, write to the Free Software
18  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19  02110-1301 USA.
20 */
21 
22 // Own
23 #include "ViewContainer.h"
24 
25 #include <config-konsole.h>
26 
27 // Qt
28 #include <QStackedWidget>
29 #include <QToolButton>
30 #include <QtGui/QDrag>
31 #include <QtGui/QDragMoveEvent>
32 #include <QtCore/QMimeData>
33 #include <QHBoxLayout>
34 #include <QVBoxLayout>
35 
36 // KDE
37 #include <KColorScheme>
38 #include <KColorUtils>
39 #include <KLocalizedString>
40 #include <KMenu>
41 #include <KIcon>
42 
43 // Konsole
44 #include "IncrementalSearchBar.h"
45 #include "ViewProperties.h"
46 #include "ViewContainerTabBar.h"
47 #include "ProfileList.h"
48 #include "ViewManager.h"
49 
50 // TODO Perhaps move everything which is Konsole-specific into different files
51 
52 using namespace Konsole;
53 
54 ViewContainer::ViewContainer(NavigationPosition position , QObject* parent)
55  : QObject(parent)
56  , _navigationVisibility(AlwaysShowNavigation)
57  , _navigationPosition(position)
58  , _searchBar(0)
59 {
60 }
61 
62 ViewContainer::~ViewContainer()
63 {
64  foreach(QWidget * view , _views) {
65  disconnect(view, SIGNAL(destroyed(QObject*)), this, SLOT(viewDestroyed(QObject*)));
66  }
67 
68  if (_searchBar) {
69  _searchBar->deleteLater();
70  }
71 
72  emit destroyed(this);
73 }
74 void ViewContainer::moveViewWidget(int , int) {}
75 void ViewContainer::setFeatures(Features features)
76 {
77  _features = features;
78 }
79 ViewContainer::Features ViewContainer::features() const
80 {
81  return _features;
82 }
83 void ViewContainer::moveActiveView(MoveDirection direction)
84 {
85  const int currentIndex = _views.indexOf(activeView());
86  int newIndex = -1;
87 
88  switch (direction) {
89  case MoveViewLeft:
90  newIndex = qMax(currentIndex - 1 , 0);
91  break;
92  case MoveViewRight:
93  newIndex = qMin(currentIndex + 1 , _views.count() - 1);
94  break;
95  }
96 
97  Q_ASSERT(newIndex != -1);
98 
99  moveViewWidget(currentIndex , newIndex);
100 
101  _views.swap(currentIndex, newIndex);
102 
103  setActiveView(_views[newIndex]);
104 }
105 
106 void ViewContainer::setNavigationVisibility(NavigationVisibility mode)
107 {
108  _navigationVisibility = mode;
109  navigationVisibilityChanged(mode);
110 }
111 ViewContainer::NavigationPosition ViewContainer::navigationPosition() const
112 {
113  return _navigationPosition;
114 }
115 void ViewContainer::setNavigationPosition(NavigationPosition position)
116 {
117  // assert that this position is supported
118  Q_ASSERT(supportedNavigationPositions().contains(position));
119 
120  _navigationPosition = position;
121 
122  navigationPositionChanged(position);
123 }
124 QList<ViewContainer::NavigationPosition> ViewContainer::supportedNavigationPositions() const
125 {
126  return QList<NavigationPosition>() << NavigationPositionTop;
127 }
128 ViewContainer::NavigationVisibility ViewContainer::navigationVisibility() const
129 {
130  return _navigationVisibility;
131 }
132 
133 void ViewContainer::setNavigationTextMode(bool mode)
134 {
135  navigationTextModeChanged(mode);
136 }
137 
138 void ViewContainer::addView(QWidget* view , ViewProperties* item, int index)
139 {
140  if (index == -1)
141  _views.append(view);
142  else
143  _views.insert(index, view);
144 
145  _navigation[view] = item;
146 
147  connect(view, SIGNAL(destroyed(QObject*)), this, SLOT(viewDestroyed(QObject*)));
148 
149  addViewWidget(view, index);
150 
151  emit viewAdded(view, item);
152 }
153 void ViewContainer::viewDestroyed(QObject* object)
154 {
155  QWidget* widget = static_cast<QWidget*>(object);
156 
157  _views.removeAll(widget);
158  _navigation.remove(widget);
159 
160  // FIXME This can result in ViewContainerSubClass::removeViewWidget() being
161  // called after the widget's parent has been deleted or partially deleted
162  // in the ViewContainerSubClass instance's destructor.
163  //
164  // Currently deleteLater() is used to remove child widgets in the subclass
165  // constructors to get around the problem, but this is a hack and needs
166  // to be fixed.
167  removeViewWidget(widget);
168 
169  emit viewRemoved(widget);
170 
171  if (_views.count() == 0)
172  emit empty(this);
173 }
174 void ViewContainer::removeView(QWidget* view)
175 {
176  _views.removeAll(view);
177  _navigation.remove(view);
178 
179  disconnect(view, SIGNAL(destroyed(QObject*)), this, SLOT(viewDestroyed(QObject*)));
180 
181  removeViewWidget(view);
182 
183  emit viewRemoved(view);
184 
185  if (_views.count() == 0)
186  emit empty(this);
187 }
188 
189 const QList<QWidget*> ViewContainer::views() const
190 {
191  return _views;
192 }
193 
194 IncrementalSearchBar* ViewContainer::searchBar()
195 {
196  if (!_searchBar) {
197  _searchBar = new IncrementalSearchBar(0);
198  _searchBar->setVisible(false);
199  connect(_searchBar, SIGNAL(destroyed(QObject*)), this, SLOT(searchBarDestroyed()));
200  }
201  return _searchBar;
202 }
203 
204 void ViewContainer::searchBarDestroyed()
205 {
206  _searchBar = 0;
207 }
208 
209 void ViewContainer::activateNextView()
210 {
211  QWidget* active = activeView();
212 
213  int index = _views.indexOf(active);
214 
215  if (index == -1)
216  return;
217 
218  if (index == _views.count() - 1)
219  index = 0;
220  else
221  index++;
222 
223  setActiveView(_views.at(index));
224 }
225 
226 void ViewContainer::activateLastView()
227 {
228  setActiveView(_views.at(_views.count() - 1));
229 }
230 
231 void ViewContainer::activatePreviousView()
232 {
233  QWidget* active = activeView();
234 
235  int index = _views.indexOf(active);
236 
237  if (index == -1)
238  return;
239 
240  if (index == 0)
241  index = _views.count() - 1;
242  else
243  index--;
244 
245  setActiveView(_views.at(index));
246 }
247 
248 ViewProperties* ViewContainer::viewProperties(QWidget* widget) const
249 {
250  Q_ASSERT(_navigation.contains(widget));
251 
252  return _navigation[widget];
253 }
254 
255 QList<QWidget*> ViewContainer::widgetsForItem(ViewProperties* item) const
256 {
257  return _navigation.keys(item);
258 }
259 
260 TabbedViewContainer::TabbedViewContainer(NavigationPosition position, ViewManager* connectedViewManager, QObject* parent)
261  : ViewContainer(position, parent)
262  , _connectedViewManager(connectedViewManager)
263  , _contextMenuTabIndex(0)
264 {
265  _containerWidget = new QWidget;
266  _stackWidget = new QStackedWidget();
267 
268  // The tab bar
269  _tabBar = new ViewContainerTabBar(_containerWidget, this);
270  _tabBar->setSupportedMimeType(ViewProperties::mimeType());
271 
272  connect(_tabBar, SIGNAL(currentChanged(int)), this, SLOT(currentTabChanged(int)));
273  connect(_tabBar, SIGNAL(tabDoubleClicked(int)), this, SLOT(tabDoubleClicked(int)));
274  connect(_tabBar, SIGNAL(newTabRequest()), this, SIGNAL(newViewRequest()));
275  connect(_tabBar, SIGNAL(wheelDelta(int)), this, SLOT(wheelScrolled(int)));
276  connect(_tabBar, SIGNAL(initiateDrag(int)), this, SLOT(startTabDrag(int)));
277  connect(_tabBar, SIGNAL(querySourceIndex(const QDropEvent*,int&)),
278  this, SLOT(querySourceIndex(const QDropEvent*,int&)));
279  connect(_tabBar, SIGNAL(moveViewRequest(int,const QDropEvent*,bool&,TabbedViewContainer*)),
280  this, SLOT(onMoveViewRequest(int,const QDropEvent*,bool&,TabbedViewContainer*)));
281  connect(_tabBar, SIGNAL(contextMenu(int,QPoint)), this,
282  SLOT(openTabContextMenu(int,QPoint)));
283 
284  // The context menu of tab bar
285  _contextPopupMenu = new KMenu(_tabBar);
286 
287 #if defined(ENABLE_DETACHING)
288  _contextPopupMenu->addAction(KIcon("tab-detach"),
289  i18nc("@action:inmenu", "&Detach Tab"), this,
290  SLOT(tabContextMenuDetachTab()));
291 #endif
292 
293  _contextPopupMenu->addAction(KIcon("edit-rename"),
294  i18nc("@action:inmenu", "&Rename Tab..."), this,
295  SLOT(tabContextMenuRenameTab()));
296 
297  _contextPopupMenu->addSeparator();
298 
299  _contextPopupMenu->addAction(KIcon("tab-close"),
300  i18nc("@action:inmenu", "&Close Tab"), this,
301  SLOT(tabContextMenuCloseTab()));
302 
303  // The 'new tab' and 'close tab' button
304  _newTabButton = new QToolButton(_containerWidget);
305  _newTabButton->setFocusPolicy(Qt::NoFocus);
306  _newTabButton->setIcon(KIcon("tab-new"));
307  _newTabButton->setToolTip(i18nc("@info:tooltip", "Create new tab"));
308  _newTabButton->setWhatsThis(i18nc("@info:whatsthis", "Create a new tab. Press and hold to select profile from menu"));
309  _newTabButton->adjustSize();
310 
311  QMenu* profileMenu = new QMenu(_newTabButton);
312  ProfileList* profileList = new ProfileList(false, profileMenu);
313  profileList->syncWidgetActions(profileMenu, true);
314  connect(profileList, SIGNAL(profileSelected(Profile::Ptr)),
315  this, SIGNAL(newViewRequest(Profile::Ptr)));
316  setNewViewMenu(profileMenu);
317 
318  _closeTabButton = new QToolButton(_containerWidget);
319  _closeTabButton->setFocusPolicy(Qt::NoFocus);
320  _closeTabButton->setIcon(KIcon("tab-close"));
321  _closeTabButton->setToolTip(i18nc("@info:tooltip", "Close tab"));
322  _closeTabButton->setWhatsThis(i18nc("@info:whatsthis", "Close the active tab"));
323  _closeTabButton->adjustSize();
324 
325  // 'new tab' button is initially hidden. It will be shown when setFeatures()
326  // is called with the QuickNewView flag enabled. The 'close tab' is the same.
327  _newTabButton->setHidden(true);
328  _closeTabButton->setHidden(true);
329 
330  connect(_newTabButton, SIGNAL(clicked()), this, SIGNAL(newViewRequest()));
331  connect(_closeTabButton, SIGNAL(clicked()), this, SLOT(closeCurrentTab()));
332 
333  // Combine tab bar and 'new/close tab' buttons
334  _tabBarLayout = new QHBoxLayout;
335  _tabBarLayout->setSpacing(0);
336  _tabBarLayout->setContentsMargins(0, 0, 0, 0);
337  _tabBarLayout->addWidget(_newTabButton);
338  _tabBarLayout->addWidget(_tabBar);
339  _tabBarLayout->addWidget(_closeTabButton);
340 
341  // The search bar
342  searchBar()->setParent(_containerWidget);
343 
344  // The overall layout
345  _layout = new QVBoxLayout;
346  _layout->setSpacing(0);
347  _layout->setContentsMargins(0, 0, 0, 0);
348 
349  setNavigationPosition(position);
350 
351  _containerWidget->setLayout(_layout);
352 }
353 void TabbedViewContainer::setNewViewMenu(QMenu* menu)
354 {
355  _newTabButton->setMenu(menu);
356 }
357 ViewContainer::Features TabbedViewContainer::supportedFeatures() const
358 {
359  return QuickNewView | QuickCloseView;
360 }
361 void TabbedViewContainer::setFeatures(Features features)
362 {
363  ViewContainer::setFeatures(features);
364  updateVisibilityOfQuickButtons();
365 }
366 
367 void TabbedViewContainer::closeCurrentTab()
368 {
369  if (_stackWidget->currentIndex() != -1) {
370  emit closeTab(this, _stackWidget->widget(_stackWidget->currentIndex()));
371  }
372 }
373 
374 void TabbedViewContainer::updateVisibilityOfQuickButtons()
375 {
376  const bool tabBarHidden = _tabBar->isHidden();
377  _newTabButton->setVisible(!tabBarHidden && (features() & QuickNewView));
378  _closeTabButton->setVisible(!tabBarHidden && (features() & QuickCloseView));
379 }
380 
381 void TabbedViewContainer::setTabBarVisible(bool visible)
382 {
383  _tabBar->setVisible(visible);
384  updateVisibilityOfQuickButtons();
385 }
386 QList<ViewContainer::NavigationPosition> TabbedViewContainer::supportedNavigationPositions() const
387 {
388  return QList<NavigationPosition>() << NavigationPositionTop << NavigationPositionBottom;
389 }
390 
391 void TabbedViewContainer::navigationPositionChanged(NavigationPosition position)
392 {
393  // this method assumes that there are three or zero items in the layout
394  Q_ASSERT(_layout->count() == 3 || _layout->count() == 0);
395 
396  // clear all existing items from the layout
397  _layout->removeItem(_tabBarLayout);
398  _tabBarLayout->setParent(0); // suppress the warning of "already has a parent"
399  _layout->removeWidget(_stackWidget);
400  _layout->removeWidget(searchBar());
401 
402  if (position == NavigationPositionTop) {
403  _layout->insertLayout(-1, _tabBarLayout);
404  _layout->insertWidget(-1, _stackWidget);
405  _layout->insertWidget(-1, searchBar());
406  _tabBar->setShape(QTabBar::RoundedNorth);
407  } else if (position == NavigationPositionBottom) {
408  _layout->insertWidget(-1, _stackWidget);
409  _layout->insertWidget(-1, searchBar());
410  _layout->insertLayout(-1, _tabBarLayout);
411  _tabBar->setShape(QTabBar::RoundedSouth);
412  } else {
413  Q_ASSERT(false); // should never reach here
414  }
415 }
416 void TabbedViewContainer::navigationVisibilityChanged(NavigationVisibility mode)
417 {
418  if (mode == AlwaysShowNavigation && _tabBar->isHidden())
419  setTabBarVisible(true);
420 
421  if (mode == AlwaysHideNavigation && !_tabBar->isHidden())
422  setTabBarVisible(false);
423 
424  if (mode == ShowNavigationAsNeeded)
425  dynamicTabBarVisibility();
426 }
427 void TabbedViewContainer::dynamicTabBarVisibility()
428 {
429  if (_tabBar->count() > 1 && _tabBar->isHidden())
430  setTabBarVisible(true);
431 
432  if (_tabBar->count() < 2 && !_tabBar->isHidden())
433  setTabBarVisible(false);
434 }
435 
436 void TabbedViewContainer::setStyleSheet(const QString& styleSheet)
437 {
438  _tabBar->setStyleSheet(styleSheet);
439 }
440 
441 void TabbedViewContainer::navigationTextModeChanged(bool useTextWidth)
442 {
443  if (useTextWidth) {
444  _tabBar->setStyleSheet("QTabBar::tab { }");
445  _tabBar->setExpanding(false);
446  _tabBar->setElideMode(Qt::ElideNone);
447  } else {
448  _tabBar->setStyleSheet("QTabBar::tab { min-width: 2em; max-width: 25em }");
449  _tabBar->setExpanding(true);
450  _tabBar->setElideMode(Qt::ElideLeft);
451  }
452 }
453 
454 TabbedViewContainer::~TabbedViewContainer()
455 {
456  if (!_containerWidget.isNull())
457  _containerWidget->deleteLater();
458 }
459 
460 void TabbedViewContainer::startTabDrag(int tab)
461 {
462  QDrag* drag = new QDrag(_tabBar);
463  const QRect tabRect = _tabBar->tabRect(tab);
464  QPixmap tabPixmap = _tabBar->dragDropPixmap(tab);
465 
466  drag->setPixmap(tabPixmap);
467 
468  // offset the tab position so the tab will follow the cursor exactly
469  // where it was clicked (as opposed to centering on the origin of the pixmap)
470  QPoint mappedPos = _tabBar->mapFromGlobal(QCursor::pos());
471  mappedPos.rx() -= tabRect.x();
472 
473  drag->setHotSpot(mappedPos);
474 
475  const int id = viewProperties(views()[tab])->identifier();
476  QWidget* view = views()[tab];
477  drag->setMimeData(ViewProperties::createMimeData(id));
478 
479  // start dragging
480  const Qt::DropAction action = drag->exec();
481 
482  if (drag->target()) {
483  switch (action) {
484  case Qt::MoveAction:
485  // The MoveAction indicates the widget has been successfully
486  // moved into another tabbar/container, so remove the widget in
487  // current tabbar/container.
488  //
489  // Deleting the view may cause the view container to be deleted,
490  // which will also delete the QDrag object. This can cause a
491  // crash if Qt's internal drag-and-drop handling tries to delete
492  // it later.
493  //
494  // For now set the QDrag's parent to 0 so that it won't be
495  // deleted if this view container is destroyed.
496  //
497  // FIXME: Resolve this properly
498  drag->setParent(0);
499  removeView(view);
500  break;
501  case Qt::IgnoreAction:
502  // The IgnoreAction is used by the tabbar to indicate the
503  // special case of dropping one tab into its existing position.
504  // So nothing need to do here.
505  break;
506  default:
507  break;
508  }
509  } else {
510  // if the tab is dragged onto something that does not accept this
511  // drop(for example, a different application or a different konsole
512  // process), then detach the tab to achieve the effect of "dragging tab
513  // out of current window and into its own window"
514  //
515  // It feels unnatural to do the detach when this is only one tab in the
516  // tabbar
517  if (_tabBar->count() > 1)
518  emit detachTab(this, view);
519  }
520 }
521 
522 void TabbedViewContainer::querySourceIndex(const QDropEvent* event, int& sourceIndex)
523 {
524  const int droppedId = ViewProperties::decodeMimeData(event->mimeData());
525 
526  const QList<QWidget*> viewList = views();
527  const int count = viewList.count();
528  int index = -1;
529  for (index = 0; index < count; index++) {
530  const int id = viewProperties(viewList[index])->identifier();
531  if (id == droppedId)
532  break;
533  }
534 
535  sourceIndex = index;
536 }
537 
538 void TabbedViewContainer::onMoveViewRequest(int index, const QDropEvent* event ,bool& success, TabbedViewContainer* sourceTabbedContainer)
539 {
540  const int droppedId = ViewProperties::decodeMimeData(event->mimeData());
541  emit moveViewRequest(index, droppedId, success, sourceTabbedContainer);
542 }
543 
544 void TabbedViewContainer::tabDoubleClicked(int index)
545 {
546  renameTab(index);
547 }
548 
549 void TabbedViewContainer::renameTab(int index)
550 {
551  viewProperties(views()[index])->rename();
552 }
553 
554 void TabbedViewContainer::openTabContextMenu(int index, const QPoint& pos)
555 {
556  _contextMenuTabIndex = index;
557 
558 #if defined(ENABLE_DETACHING)
559  // Enable 'Detach Tab' menu item only if there is more than 1 tab
560  // Note: the code is coupled with that action's position within the menu
561  QAction* detachAction = _contextPopupMenu->actions().first();
562  detachAction->setEnabled(_tabBar->count() > 1);
563 #endif
564 
565  _contextPopupMenu->exec(pos);
566 }
567 
568 void TabbedViewContainer::tabContextMenuCloseTab()
569 {
570  _tabBar->setCurrentIndex(_contextMenuTabIndex);// Required for this to work
571  emit closeTab(this, _stackWidget->widget(_contextMenuTabIndex));
572 }
573 
574 void TabbedViewContainer::tabContextMenuDetachTab()
575 {
576  emit detachTab(this, _stackWidget->widget(_contextMenuTabIndex));
577 }
578 
579 void TabbedViewContainer::tabContextMenuRenameTab()
580 {
581  renameTab(_contextMenuTabIndex);
582 }
583 
584 void TabbedViewContainer::moveViewWidget(int fromIndex , int toIndex)
585 {
586  QString text = _tabBar->tabText(fromIndex);
587  QIcon icon = _tabBar->tabIcon(fromIndex);
588 
589  // FIXME - This will lose properties of the tab other than
590  // their text and icon when moving them
591 
592  _tabBar->removeTab(fromIndex);
593  _tabBar->insertTab(toIndex, icon, text);
594 
595  QWidget* widget = _stackWidget->widget(fromIndex);
596  _stackWidget->removeWidget(widget);
597  _stackWidget->insertWidget(toIndex, widget);
598 }
599 void TabbedViewContainer::currentTabChanged(int index)
600 {
601  _stackWidget->setCurrentIndex(index);
602  if (_stackWidget->widget(index))
603  emit activeViewChanged(_stackWidget->widget(index));
604 
605  // clear activity indicators
606  setTabActivity(index, false);
607 }
608 
609 void TabbedViewContainer::wheelScrolled(int delta)
610 {
611  if (delta < 0)
612  activateNextView();
613  else
614  activatePreviousView();
615 }
616 
617 QWidget* TabbedViewContainer::containerWidget() const
618 {
619  return _containerWidget;
620 }
621 QWidget* TabbedViewContainer::activeView() const
622 {
623  return _stackWidget->currentWidget();
624 }
625 void TabbedViewContainer::setActiveView(QWidget* view)
626 {
627  const int index = _stackWidget->indexOf(view);
628 
629  Q_ASSERT(index != -1);
630 
631  _stackWidget->setCurrentWidget(view);
632  _tabBar->setCurrentIndex(index);
633 }
634 void TabbedViewContainer::addViewWidget(QWidget* view , int index)
635 {
636  _stackWidget->insertWidget(index, view);
637  _stackWidget->updateGeometry();
638 
639  ViewProperties* item = viewProperties(view);
640  connect(item, SIGNAL(titleChanged(ViewProperties*)), this ,
641  SLOT(updateTitle(ViewProperties*)));
642  connect(item, SIGNAL(iconChanged(ViewProperties*)), this ,
643  SLOT(updateIcon(ViewProperties*)));
644  connect(item, SIGNAL(activity(ViewProperties*)), this ,
645  SLOT(updateActivity(ViewProperties*)));
646 
647  _tabBar->insertTab(index , item->icon() , item->title());
648 
649  if (navigationVisibility() == ShowNavigationAsNeeded)
650  dynamicTabBarVisibility();
651 }
652 void TabbedViewContainer::removeViewWidget(QWidget* view)
653 {
654  if (!_stackWidget)
655  return;
656  const int index = _stackWidget->indexOf(view);
657 
658  Q_ASSERT(index != -1);
659 
660  _stackWidget->removeWidget(view);
661  _tabBar->removeTab(index);
662 
663  if (navigationVisibility() == ShowNavigationAsNeeded)
664  dynamicTabBarVisibility();
665 }
666 
667 void TabbedViewContainer::setTabActivity(int index , bool activity)
668 {
669  const QPalette& palette = _tabBar->palette();
670  KColorScheme colorScheme(palette.currentColorGroup());
671  const QColor colorSchemeActive = colorScheme.foreground(KColorScheme::ActiveText).color();
672 
673  const QColor normalColor = palette.text().color();
674  const QColor activityColor = KColorUtils::mix(normalColor, colorSchemeActive);
675 
676  QColor color = activity ? activityColor : QColor();
677 
678  if (color != _tabBar->tabTextColor(index))
679  _tabBar->setTabTextColor(index, color);
680 }
681 
682 void TabbedViewContainer::updateActivity(ViewProperties* item)
683 {
684  foreach(QWidget* widget, widgetsForItem(item)) {
685  const int index = _stackWidget->indexOf(widget);
686 
687  if (index != _stackWidget->currentIndex()) {
688  setTabActivity(index, true);
689  }
690  }
691 }
692 
693 void TabbedViewContainer::updateTitle(ViewProperties* item)
694 {
695  foreach(QWidget* widget, widgetsForItem(item)) {
696  const int index = _stackWidget->indexOf(widget);
697  QString tabText = item->title();
698 
699  _tabBar->setTabToolTip(index , tabText);
700 
701  // To avoid having & replaced with _ (shortcut indicator)
702  tabText.replace('&', "&&");
703  _tabBar->setTabText(index , tabText);
704  }
705 }
706 void TabbedViewContainer::updateIcon(ViewProperties* item)
707 {
708  foreach(QWidget* widget, widgetsForItem(item)) {
709  const int index = _stackWidget->indexOf(widget);
710  _tabBar->setTabIcon(index , item->icon());
711  }
712 }
713 
714 ViewManager* TabbedViewContainer::connectedViewManager()
715 {
716  return _connectedViewManager;
717 }
718 
719 StackedViewContainer::StackedViewContainer(QObject* parent)
720  : ViewContainer(NavigationPositionTop, parent)
721 {
722  _containerWidget = new QWidget;
723  QVBoxLayout* layout = new QVBoxLayout(_containerWidget);
724 
725  _stackWidget = new QStackedWidget(_containerWidget);
726 
727  searchBar()->setParent(_containerWidget);
728  layout->addWidget(searchBar());
729  layout->addWidget(_stackWidget);
730  layout->setContentsMargins(0, 0, 0, 0);
731 }
732 StackedViewContainer::~StackedViewContainer()
733 {
734  if (!_containerWidget.isNull())
735  _containerWidget->deleteLater();
736 }
737 QWidget* StackedViewContainer::containerWidget() const
738 {
739  return _containerWidget;
740 }
741 QWidget* StackedViewContainer::activeView() const
742 {
743  return _stackWidget->currentWidget();
744 }
745 void StackedViewContainer::setActiveView(QWidget* view)
746 {
747  _stackWidget->setCurrentWidget(view);
748 }
749 void StackedViewContainer::addViewWidget(QWidget* view , int)
750 {
751  _stackWidget->addWidget(view);
752 }
753 void StackedViewContainer::removeViewWidget(QWidget* view)
754 {
755  if (!_stackWidget)
756  return;
757  const int index = _stackWidget->indexOf(view);
758 
759  Q_ASSERT(index != -1);
760  Q_UNUSED(index);
761 
762  _stackWidget->removeWidget(view);
763 }
764 
765 #include "ViewContainer.moc"
Konsole::ViewContainer::navigationPositionChanged
virtual void navigationPositionChanged(NavigationPosition)
Called when the navigation position changes to re-layout the container and place the navigation widge...
Definition: ViewContainer.h:325
Konsole::TabbedViewContainer::addViewWidget
virtual void addViewWidget(QWidget *view, int index)
Performs the task of adding the view widget to the container widget.
Definition: ViewContainer.cpp:634
QDrag::setHotSpot
void setHotSpot(const QPoint &hotspot)
QWidget
Konsole::ViewContainer::navigationVisibility
NavigationVisibility navigationVisibility() const
Returns the current mode for controlling the visibility of the the view container's navigation widget...
Definition: ViewContainer.cpp:128
Konsole::ViewProperties::title
QString title() const
Returns the title associated with a view.
Definition: ViewProperties.cpp:85
QToolButton::setMenu
void setMenu(QMenu *menu)
Konsole::ViewContainer::empty
void empty(ViewContainer *container)
Emitted when the container has no more children.
QLayout::setContentsMargins
void setContentsMargins(int left, int top, int right, int bottom)
QPoint::rx
int & rx()
QPalette::text
const QBrush & text() const
QDropEvent::mimeData
const QMimeData * mimeData() const
Konsole::StackedViewContainer::~StackedViewContainer
virtual ~StackedViewContainer()
Definition: ViewContainer.cpp:732
Konsole::ViewProperties::mimeType
static QString mimeType()
Name of mime format to use in drag-and-drop operations.
Definition: ViewProperties.h:89
Konsole::TabbedViewContainer::navigationTextModeChanged
virtual void navigationTextModeChanged(bool mode)
Definition: ViewContainer.cpp:441
Konsole::StackedViewContainer::setActiveView
virtual void setActiveView(QWidget *view)
Changes the focus to the specified view and updates navigation aids to reflect the change...
Definition: ViewContainer.cpp:745
QDrag::setMimeData
void setMimeData(QMimeData *data)
Konsole::ViewContainer::moveViewRequest
void moveViewRequest(int index, int id, bool &success, TabbedViewContainer *sourceContainer)
Emitted when the user requests to move a view from another container into this container.
Konsole::StackedViewContainer::StackedViewContainer
StackedViewContainer(QObject *parent)
Definition: ViewContainer.cpp:719
Konsole::TabbedViewContainer
An alternative tabbed view container which uses a QTabBar and QStackedWidget combination for navigati...
Definition: ViewContainer.h:361
Konsole::ViewContainer::activateNextView
void activateNextView()
Changes the active view to the next view.
Definition: ViewContainer.cpp:209
Konsole::ViewProperties::rename
virtual void rename()
Requests the renaming of this view.
Definition: ViewProperties.cpp:55
QWidget::setFocusPolicy
void setFocusPolicy(Qt::FocusPolicy policy)
Konsole::TabbedViewContainer::setActiveView
virtual void setActiveView(QWidget *view)
Changes the focus to the specified view and updates navigation aids to reflect the change...
Definition: ViewContainer.cpp:625
QDrag::setPixmap
void setPixmap(const QPixmap &pixmap)
QList::at
const T & at(int i) const
Konsole::ViewContainer::addView
void addView(QWidget *view, ViewProperties *navigationItem, int index=-1)
Adds a new view to the container widget.
Definition: ViewContainer.cpp:138
Konsole::TabbedViewContainer::supportedFeatures
virtual Features supportedFeatures() const
Returns a bitwise-OR of supported extra UI features.
Definition: ViewContainer.cpp:357
Konsole::ProfileList
ProfileList provides a list of actions which represent session profiles that a SessionManager can cre...
Definition: ProfileList.h:51
Konsole::ViewContainer::destroyed
void destroyed(ViewContainer *container)
Emitted when the container is deleted.
QWidget::setVisible
virtual void setVisible(bool visible)
QBoxLayout::insertLayout
void insertLayout(int index, QLayout *layout, int stretch)
QHBoxLayout
Konsole::ViewContainer::activeViewChanged
void activeViewChanged(QWidget *view)
Emitted when the active view changes.
QRect::x
int x() const
QPoint
Konsole::ViewContainer::newViewRequest
void newViewRequest()
Emitted when the user requests to open a new view.
QBoxLayout::count
virtual int count() const
Konsole::ViewContainer::navigationTextModeChanged
virtual void navigationTextModeChanged(bool)
Definition: ViewContainer.h:327
Konsole::TabbedViewContainer::closeTab
void closeTab(ViewContainer *self, QWidget *activeView)
Konsole::IncrementalSearchBar::setVisible
virtual void setVisible(bool visible)
Definition: IncrementalSearchBar.cpp:233
Konsole::TabbedViewContainer::setFeatures
virtual void setFeatures(Features features)
Sets which additional features are enabled in this container.
Definition: ViewContainer.cpp:361
QWidget::adjustSize
void adjustSize()
QObject::disconnect
bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *method)
QAbstractButton::setIcon
void setIcon(const QIcon &icon)
Konsole::ViewContainer::setFeatures
virtual void setFeatures(Features features)
Sets which additional features are enabled in this container.
Definition: ViewContainer.cpp:75
IncrementalSearchBar.h
QWidget::setParent
void setParent(QWidget *parent)
Konsole::ProfileList::syncWidgetActions
void syncWidgetActions(QWidget *widget, bool sync)
TODO: Document me.
Definition: ProfileList.cpp:114
Konsole::ViewContainerTabBar::setSupportedMimeType
void setSupportedMimeType(const QString &mimeType)
Definition: ViewContainerTabBar.cpp:167
Konsole::ViewContainerTabBar::dragDropPixmap
QPixmap dragDropPixmap(int tab)
Definition: ViewContainerTabBar.cpp:207
Konsole::ViewContainer::NavigationPositionBottom
Position the navigation widget below the views.
Definition: ViewContainer.h:77
Konsole::ViewContainer::moveActiveView
void moveActiveView(MoveDirection direction)
Moves the active view within the container and updates the order in which the views are shown in the ...
Definition: ViewContainer.cpp:83
Konsole::ViewManager
Manages the terminal display widgets in a Konsole window or part.
Definition: ViewManager.h:66
Konsole::ViewContainer
An interface for container widgets which can hold one or more views.
Definition: ViewContainer.h:64
Konsole::ViewContainer::AlwaysShowNavigation
Always show the navigation widget.
Definition: ViewContainer.h:108
Konsole::ViewContainer::ShowNavigationAsNeeded
Show the navigation widget only when the container has more than one view.
Definition: ViewContainer.h:110
QList::indexOf
int indexOf(const T &value, int from) const
QBrush::color
const QColor & color() const
Konsole::StackedViewContainer::activeView
virtual QWidget * activeView() const
Returns the view which currently has the focus or 0 if none of the child views have the focus...
Definition: ViewContainer.cpp:741
Konsole::TabbedViewContainer::connectedViewManager
ViewManager * connectedViewManager()
Definition: ViewContainer.cpp:714
QDrag::exec
Qt::DropAction exec(QFlags< Qt::DropAction > supportedActions)
QPalette::currentColorGroup
ColorGroup currentColorGroup() const
Konsole::StackedViewContainer::removeViewWidget
virtual void removeViewWidget(QWidget *view)
Performs the task of removing the view widget from the container widget.
Definition: ViewContainer.cpp:753
QLayout::removeWidget
void removeWidget(QWidget *widget)
QRect
Konsole::ViewContainer::viewAdded
void viewAdded(QWidget *view, ViewProperties *properties)
Emitted when a view is added to the container.
QBoxLayout::addWidget
void addWidget(QWidget *widget, int stretch, QFlags< Qt::AlignmentFlag > alignment)
QList::count
int count(const T &value) const
Konsole::ViewProperties::createMimeData
static QMimeData * createMimeData(int id)
Returns a new QMimeData instance which represents the view with the given id (See identifier())...
Definition: ViewProperties.h:97
QList::append
void append(const T &value)
Konsole::ViewContainer::QuickNewView
Provides a button which can be clicked to create new views quickly.
Definition: ViewContainer.h:240
Konsole::TabbedViewContainer::moveViewWidget
virtual void moveViewWidget(int fromIndex, int toIndex)
Rearranges the order of widgets in the container.
Definition: ViewContainer.cpp:584
QLayout::removeItem
void removeItem(QLayoutItem *item)
Konsole::TabbedViewContainer::setStyleSheet
virtual void setStyleSheet(const QString &styleSheet)
Sets the stylesheet for visual appearance.
Definition: ViewContainer.cpp:436
ProfileList.h
QDrag::target
QWidget * target() const
QObject
QPointer::isNull
bool isNull() const
QDropEvent
Konsole::ViewContainer::viewRemoved
void viewRemoved(QWidget *view)
Emitted when a view is removed from the container.
QDrag
QList::removeAll
int removeAll(const T &value)
Konsole::ViewProperties::decodeMimeData
static int decodeMimeData(const QMimeData *mimeData)
Decodes a QMimeData instance created with createMimeData() and returns the identifier of the associat...
Definition: ViewProperties.h:109
Konsole::ViewContainer::setNavigationPosition
void setNavigationPosition(NavigationPosition position)
Sets the position of the navigation widget with respect to the main content area. ...
Definition: ViewContainer.cpp:115
Konsole::ViewContainer::activatePreviousView
void activatePreviousView()
Changes the active view to the previous view.
Definition: ViewContainer.cpp:231
Konsole::ViewContainer::activeView
virtual QWidget * activeView() const =0
Returns the view which currently has the focus or 0 if none of the child views have the focus...
QVBoxLayout
Konsole::ViewContainer::searchBar
IncrementalSearchBar * searchBar()
Definition: ViewContainer.cpp:194
QStackedWidget
QObject::deleteLater
void deleteLater()
QString
QList
Konsole::ViewContainerTabBar
Definition: ViewContainerTabBar.h:34
QColor
Konsole::TabbedViewContainer::setNewViewMenu
virtual void setNewViewMenu(QMenu *menu)
Sets the menu to be shown when the new view button is clicked.
Definition: ViewContainer.cpp:353
Konsole::ViewContainer::QuickCloseView
Provides a button which can be clicked to close views quickly.
Definition: ViewContainer.h:242
Konsole::ViewProperties
Encapsulates user-visible information about the terminal session currently being displayed in a view...
Definition: ViewProperties.h:44
QPixmap
Konsole::TabbedViewContainer::detachTab
void detachTab(ViewContainer *self, QWidget *activeView)
Konsole::IncrementalSearchBar
A widget which allows users to search incrementally through a document for a a text string or regular...
Definition: IncrementalSearchBar.h:56
QToolButton
QMenu
QObject::setParent
void setParent(QObject *parent)
ViewContainerTabBar.h
Konsole::ViewContainer::moveViewWidget
virtual void moveViewWidget(int fromIndex, int toIndex)
Rearranges the order of widgets in the container.
Definition: ViewContainer.cpp:74
Konsole::ViewContainer::addViewWidget
virtual void addViewWidget(QWidget *view, int index)=0
Performs the task of adding the view widget to the container widget.
Konsole::TabbedViewContainer::navigationPositionChanged
virtual void navigationPositionChanged(NavigationPosition position)
Called when the navigation position changes to re-layout the container and place the navigation widge...
Definition: ViewContainer.cpp:391
Konsole::Profile::Ptr
KSharedPtr< Profile > Ptr
Definition: Profile.h:67
QString::replace
QString & replace(int position, int n, QChar after)
Konsole::TabbedViewContainer::~TabbedViewContainer
virtual ~TabbedViewContainer()
Definition: ViewContainer.cpp:454
Konsole::ViewContainer::supportedNavigationPositions
virtual QList< NavigationPosition > supportedNavigationPositions() const
Returns the list of supported navigation positions.
Definition: ViewContainer.cpp:124
Konsole::TabbedViewContainer::containerWidget
virtual QWidget * containerWidget() const
Returns the widget which contains the view widgets.
Definition: ViewContainer.cpp:617
Konsole::ViewContainer::setNavigationVisibility
void setNavigationVisibility(NavigationVisibility mode)
Definition: ViewContainer.cpp:106
QWidget::setWhatsThis
void setWhatsThis(const QString &)
QCursor::pos
QPoint pos()
Konsole::ViewContainer::widgetsForItem
QList< QWidget * > widgetsForItem(ViewProperties *item) const
Returns the widgets which are associated with a particular navigation item.
Definition: ViewContainer.cpp:255
Konsole::ViewProperties::identifier
int identifier() const
A unique identifier associated with this ViewProperties instance.
Definition: ViewProperties.cpp:93
QList::swap
void swap(QList< T > &other)
Konsole::ViewContainer::removeViewWidget
virtual void removeViewWidget(QWidget *view)=0
Performs the task of removing the view widget from the container widget.
QList::insert
void insert(int i, const T &value)
ViewManager.h
Konsole::ViewContainer::activateLastView
void activateLastView()
Changes the active view to the last view.
Definition: ViewContainer.cpp:226
Konsole::ViewContainer::ViewContainer
ViewContainer(NavigationPosition position, QObject *parent)
Constructs a new view container with the specified parent.
Definition: ViewContainer.cpp:54
QAction
Konsole::TabbedViewContainer::navigationVisibilityChanged
virtual void navigationVisibilityChanged(NavigationVisibility mode)
Called when the navigation display mode changes.
Definition: ViewContainer.cpp:416
Konsole::ViewContainer::MoveViewLeft
Moves the view to the left.
Definition: ViewContainer.h:221
Konsole::ViewContainer::MoveDirection
MoveDirection
This enum describes the directions in which views can be re-arranged within the container using the m...
Definition: ViewContainer.h:219
Konsole::ViewContainer::~ViewContainer
virtual ~ViewContainer()
Called when the ViewContainer is destroyed.
Definition: ViewContainer.cpp:62
Konsole::ViewContainer::setActiveView
virtual void setActiveView(QWidget *widget)=0
Changes the focus to the specified view and updates navigation aids to reflect the change...
Konsole::ViewContainer::views
const QList< QWidget * > views() const
Returns a list of the contained views.
Definition: ViewContainer.cpp:189
Konsole::ViewContainer::setNavigationTextMode
void setNavigationTextMode(bool mode)
Sets the navigation text mode If mode is true, use the width of the title; otherwise use the default ...
Definition: ViewContainer.cpp:133
Konsole::ViewContainer::viewProperties
ViewProperties * viewProperties(QWidget *view) const
Returns the ViewProperties instance associated with a particular view in the container.
Definition: ViewContainer.cpp:248
ViewContainer.h
Konsole::ViewContainer::navigationVisibilityChanged
virtual void navigationVisibilityChanged(NavigationVisibility)
Called when the navigation display mode changes.
Definition: ViewContainer.h:318
Konsole::ViewContainer::navigationPosition
NavigationPosition navigationPosition() const
Returns the position of the navigation widget with respect to the main content area.
Definition: ViewContainer.cpp:111
QBoxLayout::insertWidget
void insertWidget(int index, QWidget *widget, int stretch, QFlags< Qt::AlignmentFlag > alignment)
Konsole::StackedViewContainer::addViewWidget
virtual void addViewWidget(QWidget *view, int index)
Performs the task of adding the view widget to the container widget.
Definition: ViewContainer.cpp:749
QWidget::setToolTip
void setToolTip(const QString &)
Konsole::ViewContainer::AlwaysHideNavigation
Always hide the navigation widget.
Definition: ViewContainer.h:112
Konsole::ViewContainer::NavigationVisibility
NavigationVisibility
This enum describes the options for showing or hiding the container's navigation widget.
Definition: ViewContainer.h:106
Konsole::ViewContainer::features
Features features() const
Returns a bitwise-OR of enabled extra UI features.
Definition: ViewContainer.cpp:79
Konsole::StackedViewContainer::containerWidget
virtual QWidget * containerWidget() const
Returns the widget which contains the view widgets.
Definition: ViewContainer.cpp:737
Konsole::ViewContainer::NavigationPositionTop
Position the navigation widget above the views.
Definition: ViewContainer.h:75
Konsole::TabbedViewContainer::supportedNavigationPositions
virtual QList< NavigationPosition > supportedNavigationPositions() const
Returns the list of supported navigation positions.
Definition: ViewContainer.cpp:386
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
ViewProperties.h
QWidget::setHidden
void setHidden(bool hidden)
Konsole::ViewContainer::NavigationPosition
NavigationPosition
This enum describes the options for positioning the container's navigation widget.
Definition: ViewContainer.h:73
QAction::setEnabled
void setEnabled(bool)
QPalette
QBoxLayout::setSpacing
void setSpacing(int spacing)
Konsole::ViewContainer::MoveViewRight
Moves the view to the right.
Definition: ViewContainer.h:223
QIcon
Konsole::ViewProperties::icon
QIcon icon() const
Returns the icon associated with a view.
Definition: ViewProperties.cpp:89
Konsole::TabbedViewContainer::removeViewWidget
virtual void removeViewWidget(QWidget *view)
Performs the task of removing the view widget from the container widget.
Definition: ViewContainer.cpp:652
Konsole::ViewContainer::removeView
void removeView(QWidget *view)
Removes a view from the container.
Definition: ViewContainer.cpp:174
Konsole::TabbedViewContainer::activeView
virtual QWidget * activeView() const
Returns the view which currently has the focus or 0 if none of the child views have the focus...
Definition: ViewContainer.cpp:621
Konsole::TabbedViewContainer::TabbedViewContainer
TabbedViewContainer(NavigationPosition position, ViewManager *connectedViewManager, QObject *parent)
Constructs a new tabbed view container.
Definition: ViewContainer.cpp:260
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Sat May 9 2020 03:56:27 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
  • 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