• Skip to content
  • Skip to link menu
KDE 4.1 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

Konsole

ViewContainer.h

Go to the documentation of this file.
00001 /*
00002     This file is part of the Konsole Terminal.
00003     
00004     Copyright 2006-2008 Robert Knight <robertknight@gmail.com>
00005 
00006     This program is free software; you can redistribute it and/or modify
00007     it under the terms of the GNU General Public License as published by
00008     the Free Software Foundation; either version 2 of the License, or
00009     (at your option) any later version.
00010 
00011     This program is distributed in the hope that it will be useful,
00012     but WITHOUT ANY WARRANTY; without even the implied warranty of
00013     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014     GNU General Public License for more details.
00015 
00016     You should have received a copy of the GNU General Public License
00017     along with this program; if not, write to the Free Software
00018     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00019     02110-1301  USA.
00020 */
00021 
00022 #ifndef VIEWCONTAINER_H
00023 #define VIEWCONTAINER_H
00024 
00025 // Qt
00026 #include <QtCore/QObject>
00027 #include <QtCore/QHash>
00028 #include <QtCore/QList>
00029 #include <QtGui/QBoxLayout>
00030 
00031 // KDE
00032 #include <KTabBar>
00033 #include <KPushButton>
00034 
00035 class QSpacerItem;
00036 class QStackedWidget;
00037 class QWidget;
00038 class QLabel;
00039 
00040 // TabbedViewContainer
00041     // Qt
00042     class QAction;
00043     class QPoint;
00044     class QWidgetAction;
00045     class QToolButton;
00046     class QMenu;
00047 
00048     // KDE
00049     class KTabWidget;
00050     class KColorCells;
00051     class KMenu;
00052 
00053 // ListViewContainer
00054     class QSplitter;
00055     class QListWidget;
00056 
00057 namespace Konsole
00058 {
00059     class ViewProperties;
00070 class ViewContainer : public QObject
00071 {
00072 Q_OBJECT
00073     
00074 public:
00075 
00080     enum NavigationPosition
00081     {
00083         NavigationPositionTop,
00085         NavigationPositionBottom,
00087         NavigationPositionLeft,
00089         NavigationPositionRight
00090     };
00091 
00098     ViewContainer(NavigationPosition position , QObject* parent);
00099 
00105     virtual ~ViewContainer();
00106 
00108     virtual QWidget* containerWidget() const = 0;
00109 
00114     enum NavigationDisplayMode
00115     {
00117         AlwaysShowNavigation,
00119         AlwaysHideNavigation,
00121         ShowNavigationAsNeeded
00122     };
00123     /*
00124      * Sets the visibility of the view container's navigation widget.
00125      *
00126      * The ViewContainer sub-class is responsible for ensuring that this
00127      * setting is respected as views are added or removed from the 
00128      * container.
00129      *
00130      * ViewContainer sub-classes should reimplement the 
00131      * navigationDisplayModeChanged() method to respond to changes 
00132      * of this property.
00133      */
00134     void setNavigationDisplayMode(NavigationDisplayMode mode);
00139     NavigationDisplayMode navigationDisplayMode() const;
00140     
00154     void setNavigationPosition(NavigationPosition position);
00155 
00160     NavigationPosition navigationPosition() const;
00161 
00169     virtual QList<NavigationPosition> supportedNavigationPositions() const;
00170 
00172     void addView(QWidget* view , ViewProperties* navigationItem, int index = -1);
00173  
00175     void removeView(QWidget* view);
00176 
00178     ViewProperties* viewProperties(  QWidget* view );   
00179     
00181     const QList<QWidget*> views();
00182    
00187     virtual QWidget* activeView() const = 0;
00188 
00193     virtual void setActiveView(QWidget* widget) = 0;
00194 
00196     void activateNextView();
00197 
00199     void activatePreviousView();
00200 
00206     enum MoveDirection
00207     {
00209         MoveViewLeft,
00211         MoveViewRight
00212     };
00213 
00221     void moveActiveView( MoveDirection direction );
00222 
00225     enum Feature
00226     {
00229         QuickNewView = 1,
00231         QuickCloseView = 2
00232     };
00233     Q_DECLARE_FLAGS(Features,Feature)
00239     virtual void setFeatures(Features features);
00241     Features features() const;
00244     virtual Features supportedFeatures() const
00245     { return 0; }
00249     virtual void setNewViewMenu(QMenu* menu) { Q_UNUSED(menu); }
00250 
00251 signals:
00253     void destroyed(ViewContainer* container);
00254 
00256     void empty(ViewContainer* container);
00257 
00259     void duplicateRequest( ViewProperties* properties );
00260 
00262     void closeRequest(QWidget* activeView);
00263 
00265     void newViewRequest();
00266 
00279     void moveViewRequest(int index,int id,bool& success);
00280 
00282     void activeViewChanged( QWidget* view );
00283 
00285     void viewAdded(QWidget* view , ViewProperties* properties);
00286 
00288     void viewRemoved(QWidget* view);
00289 
00290 protected:
00295     virtual void addViewWidget(QWidget* view,int index) = 0;
00300     virtual void removeViewWidget(QWidget* view) = 0;
00301    
00306     virtual void navigationDisplayModeChanged(NavigationDisplayMode) {}
00307 
00313     virtual void navigationPositionChanged(NavigationPosition) {}
00314 
00316     QList<QWidget*> widgetsForItem( ViewProperties* item ) const;
00317 
00324     virtual void moveViewWidget( int fromIndex , int toIndex );
00325 
00326 private slots:
00327     void viewDestroyed(QObject* view);
00328 
00329 private:
00330     NavigationDisplayMode _navigationDisplayMode;
00331     NavigationPosition _navigationPosition;
00332     QList<QWidget*> _views;
00333     QHash<QWidget*,ViewProperties*> _navigation;
00334     Features _features;
00335 };
00336 Q_DECLARE_OPERATORS_FOR_FLAGS(ViewContainer::Features)
00337 
00338 
00342 class TabbedViewContainer : public ViewContainer  
00343 {
00344     Q_OBJECT
00345 
00346 public:
00347     TabbedViewContainer(NavigationPosition position , QObject* parent);
00348     virtual ~TabbedViewContainer();
00349     
00350     virtual QWidget* containerWidget() const;
00351     virtual QWidget* activeView() const;
00352     virtual void setActiveView(QWidget* view);
00353 
00354     void setNewSessionMenu(QMenu* menu);
00355      
00356 protected:
00357     virtual void addViewWidget( QWidget* view , int index);
00358     virtual void removeViewWidget( QWidget* view ); 
00359 
00360 private slots:
00361     void updateTitle(ViewProperties* item);
00362     void updateIcon(ViewProperties* item);
00363     void closeTabClicked();
00364     void selectTabColor();
00365     void prepareColorCells();
00366     void showContextMenu(QWidget* widget , const QPoint& position);
00367     void currentTabChanged(int index);
00368 
00369 private:
00370     KTabWidget* _tabWidget; 
00371     QList<QAction*> _viewActions;
00372 
00373     QToolButton*    _newSessionButton;
00374     QMenu*          _newSessionMenu;
00375 
00376     KMenu*          _tabContextMenu;
00377     KMenu*          _tabSelectColorMenu;
00378     QWidgetAction*  _tabColorSelector; 
00379     KColorCells*    _tabColorCells;
00380 
00381     int _contextMenuTab;
00382 };
00383 
00384 class TabbedViewContainerV2;
00385 
00386 // internal class,
00387 // to allow for tweaks to the tab bar required by TabbedViewContainerV2.
00388 class ViewContainerTabBar : public KTabBar
00389 {
00390 Q_OBJECT
00391 
00392 public:
00393     ViewContainerTabBar(QWidget* parent,TabbedViewContainerV2* container);
00394 
00395     // returns a pixmap image of a tab for use with QDrag 
00396     QPixmap dragDropPixmap(int tab);
00397 
00398 protected:
00399     virtual QSize tabSizeHint(int index) const;
00400     virtual void dragEnterEvent(QDragEnterEvent* event);
00401     virtual void dragLeaveEvent(QDragLeaveEvent* event);
00402     virtual void dragMoveEvent(QDragMoveEvent* event);
00403     virtual void dropEvent(QDropEvent* event);
00404 
00405 private:
00406     // show the indicator arrow which shows where a dropped tab will
00407     // be inserted at 'index'
00408     void setDropIndicator(int index, bool drawDisabled = false);
00409     // returns the index at which a tab will be inserted if the mouse
00410     // in a drag-drop operation is released at 'pos'
00411     int dropIndex(const QPoint& pos) const;
00412     // returns true if the tab to be dropped in a drag-drop operation
00413     // is the same as the tab at the drop location
00414     bool proposedDropIsSameTab(const QDropEvent* event) const;
00415 
00416     TabbedViewContainerV2* _container;
00417     QLabel* _dropIndicator;
00418     int _dropIndicatorIndex;
00419     bool _drawIndicatorDisabled;
00420 };
00421 
00422 // internal
00423 // this class provides a work-around for a problem in Qt 4.x
00424 // where the insertItem() method only has protected access - 
00425 // and the TabbedViewContainerV2 class needs to call it.
00426 //
00427 // and presumably for binary compatibility reasons will
00428 // not be fixed until Qt 5. 
00429 class TabbedViewContainerV2Layout : public QVBoxLayout
00430 {
00431 public:
00432     void insertItemAt( int index , QLayoutItem* item )
00433     {
00434         insertItem(index,item);
00435     }
00436 };
00437 
00442 class TabbedViewContainerV2 : public ViewContainer
00443 {
00444     Q_OBJECT
00445 
00446 friend class ViewContainerTabBar;
00447 
00448 public:
00453     TabbedViewContainerV2(NavigationPosition position , QObject* parent);
00454     virtual ~TabbedViewContainerV2();
00455 
00456     virtual QWidget* containerWidget() const;
00457     virtual QWidget* activeView() const;
00458     virtual void setActiveView(QWidget* view);
00459     virtual QList<NavigationPosition> supportedNavigationPositions() const;
00460     virtual void setFeatures(Features features);
00461     virtual Features supportedFeatures() const;
00462     virtual void setNewViewMenu(QMenu* menu);
00463 protected:
00464     virtual void addViewWidget(QWidget* view , int index);
00465     virtual void removeViewWidget(QWidget* view);
00466     virtual void navigationDisplayModeChanged(NavigationDisplayMode mode);
00467     virtual void navigationPositionChanged(NavigationPosition position);
00468     virtual void moveViewWidget( int fromIndex , int toIndex );
00469 
00470 private slots:
00471     void updateTitle(ViewProperties* item);
00472     void updateIcon(ViewProperties* item);
00473     void updateActivity(ViewProperties* item);
00474     void currentTabChanged(int index);
00475     void closeTab(int index);
00476     void closeCurrentTab();
00477     void wheelScrolled(int delta);
00478    
00479     void tabDoubleClicked(int index);
00480 
00481     void startTabDrag(int index);
00482 private:
00483     void dynamicTabBarVisibility();
00484     void setTabBarVisible(bool visible);
00485     void setTabActivity(int index,bool activity);
00486 
00487     ViewContainerTabBar* _tabBar;
00488     QStackedWidget* _stackWidget;
00489     QWidget* _containerWidget;
00490     QSpacerItem* _tabBarSpacer;
00491     TabbedViewContainerV2Layout* _layout;
00492     QHBoxLayout* _tabBarLayout;
00493     KPushButton* _newTabButton;
00494     KPushButton* _closeTabButton;
00495 
00496     static const int TabBarSpace = 2;
00497 };
00498 
00500 class StackedViewContainer : public ViewContainer
00501 {
00502 public:
00503     StackedViewContainer(QObject* parent);
00504     virtual ~StackedViewContainer();
00505 
00506     virtual QWidget* containerWidget() const;
00507     virtual QWidget* activeView() const;
00508     virtual void setActiveView(QWidget* view);
00509 
00510 protected:
00511     virtual void addViewWidget( QWidget* view , int index);
00512     virtual void removeViewWidget( QWidget* view );
00513 
00514 private:
00515     QStackedWidget* _stackWidget;
00516 };
00517 
00522 class ListViewContainer : public ViewContainer
00523 {
00524 Q_OBJECT
00525 
00526 public:
00527     ListViewContainer(NavigationPosition position , QObject* parent);
00528     virtual ~ListViewContainer();
00529 
00530     virtual QWidget* containerWidget() const;
00531     virtual QWidget* activeView() const;
00532     virtual void setActiveView(QWidget* view);
00533 
00534 protected:
00535     virtual void addViewWidget( QWidget* view , int index);
00536     virtual void removeViewWidget( QWidget* view );
00537 
00538 private slots:
00539     void rowChanged( int row );
00540     void updateTitle( ViewProperties* );
00541     void updateIcon( ViewProperties* );
00542 
00543 private:
00544     QBrush randomItemBackground(int randomIndex);
00545 
00546     QStackedWidget* _stackWidget;
00547     QSplitter* _splitter;
00548     QListWidget* _listWidget;
00549 };
00550 
00551 }
00552 #endif //VIEWCONTAINER_H

Konsole

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

API Reference

Skip menu "API Reference"
  • Konsole
  • Libraries
  •   libkonq
Generated for API Reference by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal