• Skip to content
  • Skip to link menu
KDE 4.2 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/QPointer>
00028 #include <QtCore/QHash>
00029 #include <QtCore/QList>
00030 #include <QtGui/QBoxLayout>
00031 
00032 // KDE
00033 #include <KTabBar>
00034 #include <KPushButton>
00035 
00036 class QSpacerItem;
00037 class QStackedWidget;
00038 class QWidget;
00039 class QLabel;
00040 
00041 // TabbedViewContainer
00042     // Qt
00043     class QAction;
00044     class QPoint;
00045     class QWidgetAction;
00046     class QToolButton;
00047     class QMenu;
00048 
00049     // KDE
00050     class KTabWidget;
00051     class KColorCells;
00052     class KMenu;
00053 
00054 // ListViewContainer
00055     class QSplitter;
00056     class QListWidget;
00057 
00058 namespace Konsole
00059 {
00060     class IncrementalSearchBar;
00061     class ViewProperties;
00072 class ViewContainer : public QObject
00073 {
00074 Q_OBJECT
00075     
00076 public:
00077 
00082     enum NavigationPosition
00083     {
00085         NavigationPositionTop,
00087         NavigationPositionBottom,
00089         NavigationPositionLeft,
00091         NavigationPositionRight
00092     };
00093 
00100     ViewContainer(NavigationPosition position , QObject* parent);
00101 
00107     virtual ~ViewContainer();
00108 
00110     virtual QWidget* containerWidget() const = 0;
00111 
00116     enum NavigationDisplayMode
00117     {
00119         AlwaysShowNavigation,
00121         AlwaysHideNavigation,
00123         ShowNavigationAsNeeded
00124     };
00125     /*
00126      * Sets the visibility of the view container's navigation widget.
00127      *
00128      * The ViewContainer sub-class is responsible for ensuring that this
00129      * setting is respected as views are added or removed from the 
00130      * container.
00131      *
00132      * ViewContainer sub-classes should reimplement the 
00133      * navigationDisplayModeChanged() method to respond to changes 
00134      * of this property.
00135      */
00136     void setNavigationDisplayMode(NavigationDisplayMode mode);
00141     NavigationDisplayMode navigationDisplayMode() const;
00142     
00156     void setNavigationPosition(NavigationPosition position);
00157 
00162     NavigationPosition navigationPosition() const;
00163 
00171     virtual QList<NavigationPosition> supportedNavigationPositions() const;
00172 
00174     void addView(QWidget* view , ViewProperties* navigationItem, int index = -1);
00175  
00177     void removeView(QWidget* view);
00178 
00180     ViewProperties* viewProperties(  QWidget* view );   
00181     
00183     const QList<QWidget*> views();
00184    
00189     virtual QWidget* activeView() const = 0;
00190 
00195     virtual void setActiveView(QWidget* widget) = 0;
00196 
00200     IncrementalSearchBar* searchBar();
00201 
00203     void activateNextView();
00204 
00206     void activatePreviousView();
00207 
00213     enum MoveDirection
00214     {
00216         MoveViewLeft,
00218         MoveViewRight
00219     };
00220 
00228     void moveActiveView( MoveDirection direction );
00229 
00232     enum Feature
00233     {
00236         QuickNewView = 1,
00238         QuickCloseView = 2
00239     };
00240     Q_DECLARE_FLAGS(Features,Feature)
00246     virtual void setFeatures(Features features);
00248     Features features() const;
00251     virtual Features supportedFeatures() const
00252     { return 0; }
00256     virtual void setNewViewMenu(QMenu* menu) { Q_UNUSED(menu); }
00257 
00258 signals:
00260     void destroyed(ViewContainer* container);
00261 
00263     void empty(ViewContainer* container);
00264 
00266     void duplicateRequest( ViewProperties* properties );
00267 
00269     void closeRequest(QWidget* activeView);
00270 
00272     void newViewRequest();
00273 
00286     void moveViewRequest(int index,int id,bool& success);
00287 
00289     void activeViewChanged( QWidget* view );
00290 
00292     void viewAdded(QWidget* view , ViewProperties* properties);
00293 
00295     void viewRemoved(QWidget* view);
00296 
00297 protected:
00302     virtual void addViewWidget(QWidget* view,int index) = 0;
00307     virtual void removeViewWidget(QWidget* view) = 0;
00308    
00313     virtual void navigationDisplayModeChanged(NavigationDisplayMode) {}
00314 
00320     virtual void navigationPositionChanged(NavigationPosition) {}
00321 
00323     QList<QWidget*> widgetsForItem( ViewProperties* item ) const;
00324 
00331     virtual void moveViewWidget( int fromIndex , int toIndex );
00332 
00333 private slots:
00334     void viewDestroyed(QObject* view);
00335     void searchBarDestroyed();
00336 
00337 private:
00338     NavigationDisplayMode _navigationDisplayMode;
00339     NavigationPosition _navigationPosition;
00340     QList<QWidget*> _views;
00341     QHash<QWidget*,ViewProperties*> _navigation;
00342     Features _features;
00343     IncrementalSearchBar* _searchBar;
00344 };
00345 Q_DECLARE_OPERATORS_FOR_FLAGS(ViewContainer::Features)
00346 
00347 class TabbedViewContainer;
00348 
00349 // internal class,
00350 // to allow for tweaks to the tab bar required by TabbedViewContainer.
00351 class ViewContainerTabBar : public KTabBar
00352 {
00353 Q_OBJECT
00354 
00355 public:
00356     ViewContainerTabBar(QWidget* parent,TabbedViewContainer* container);
00357 
00358     // returns a pixmap image of a tab for use with QDrag 
00359     QPixmap dragDropPixmap(int tab);
00360 
00361 protected:
00362     virtual QSize tabSizeHint(int index) const;
00363     virtual void dragEnterEvent(QDragEnterEvent* event);
00364     virtual void dragLeaveEvent(QDragLeaveEvent* event);
00365     virtual void dragMoveEvent(QDragMoveEvent* event);
00366     virtual void dropEvent(QDropEvent* event);
00367 
00368 private:
00369     // show the indicator arrow which shows where a dropped tab will
00370     // be inserted at 'index'
00371     void setDropIndicator(int index, bool drawDisabled = false);
00372     // returns the index at which a tab will be inserted if the mouse
00373     // in a drag-drop operation is released at 'pos'
00374     int dropIndex(const QPoint& pos) const;
00375     // returns true if the tab to be dropped in a drag-drop operation
00376     // is the same as the tab at the drop location
00377     bool proposedDropIsSameTab(const QDropEvent* event) const;
00378 
00379     TabbedViewContainer* _container;
00380     QLabel* _dropIndicator;
00381     int _dropIndicatorIndex;
00382     bool _drawIndicatorDisabled;
00383 };
00384 
00385 // internal
00386 // this class provides a work-around for a problem in Qt 4.x
00387 // where the insertItem() method only has protected access - 
00388 // and the TabbedViewContainer class needs to call it.
00389 //
00390 // and presumably for binary compatibility reasons will
00391 // not be fixed until Qt 5. 
00392 class TabbedViewContainerLayout : public QVBoxLayout
00393 {
00394 public:
00395     void insertItemAt( int index , QLayoutItem* item )
00396     {
00397         insertItem(index,item);
00398     }
00399 };
00400 
00405 class TabbedViewContainer : public ViewContainer
00406 {
00407     Q_OBJECT
00408 
00409 friend class ViewContainerTabBar;
00410 
00411 public:
00416     TabbedViewContainer(NavigationPosition position , QObject* parent);
00417     virtual ~TabbedViewContainer();
00418 
00419     virtual QWidget* containerWidget() const;
00420     virtual QWidget* activeView() const;
00421     virtual void setActiveView(QWidget* view);
00422     virtual QList<NavigationPosition> supportedNavigationPositions() const;
00423     virtual void setFeatures(Features features);
00424     virtual Features supportedFeatures() const;
00425     virtual void setNewViewMenu(QMenu* menu);
00426 
00427 protected:
00428     virtual void addViewWidget(QWidget* view , int index);
00429     virtual void removeViewWidget(QWidget* view);
00430     virtual void navigationDisplayModeChanged(NavigationDisplayMode mode);
00431     virtual void navigationPositionChanged(NavigationPosition position);
00432     virtual void moveViewWidget( int fromIndex , int toIndex );
00433 
00434 private slots:
00435     void updateTitle(ViewProperties* item);
00436     void updateIcon(ViewProperties* item);
00437     void updateActivity(ViewProperties* item);
00438     void currentTabChanged(int index);
00439     void closeTab(int index);
00440     void closeCurrentTab();
00441     void wheelScrolled(int delta);
00442    
00443     void tabDoubleClicked(int index);
00444 
00445     void startTabDrag(int index);
00446 private:
00447     void dynamicTabBarVisibility();
00448     void setTabBarVisible(bool visible);
00449     void setTabActivity(int index,bool activity);
00450 
00451     ViewContainerTabBar* _tabBar;
00452     QPointer<QStackedWidget> _stackWidget;
00453     QPointer<QWidget> _containerWidget;
00454     QSpacerItem* _tabBarSpacer;
00455     TabbedViewContainerLayout* _layout;
00456     QHBoxLayout* _tabBarLayout;
00457     KPushButton* _newTabButton;
00458     KPushButton* _closeTabButton;
00459 
00460     static const int TabBarSpace = 2;
00461 };
00462 
00464 class StackedViewContainer : public ViewContainer
00465 {
00466 public:
00467     StackedViewContainer(QObject* parent);
00468     virtual ~StackedViewContainer();
00469 
00470     virtual QWidget* containerWidget() const;
00471     virtual QWidget* activeView() const;
00472     virtual void setActiveView(QWidget* view);
00473 
00474 protected:
00475     virtual void addViewWidget( QWidget* view , int index);
00476     virtual void removeViewWidget( QWidget* view );
00477 
00478 private:
00479     QPointer<QWidget> _containerWidget;
00480     QPointer<QStackedWidget> _stackWidget;
00481 };
00482 
00487 class ListViewContainer : public ViewContainer
00488 {
00489 Q_OBJECT
00490 
00491 public:
00492     ListViewContainer(NavigationPosition position , QObject* parent);
00493     virtual ~ListViewContainer();
00494 
00495     virtual QWidget* containerWidget() const;
00496     virtual QWidget* activeView() const;
00497     virtual void setActiveView(QWidget* view);
00498 
00499 protected:
00500     virtual void addViewWidget( QWidget* view , int index);
00501     virtual void removeViewWidget( QWidget* view );
00502 
00503 private slots:
00504     void rowChanged( int row );
00505     void updateTitle( ViewProperties* );
00506     void updateIcon( ViewProperties* );
00507 
00508 private:
00509     QBrush randomItemBackground(int randomIndex);
00510 
00511     QPointer<QStackedWidget> _stackWidget;
00512     QSplitter* _splitter;
00513     QListWidget* _listWidget;
00514 };
00515 
00516 }
00517 #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.7
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