1 /*
2  * psitabwidget.h - Customised QTabWidget for Psi
3  * Copyright (C) 2006  Kevin Smith
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * as published by the Free Software Foundation; either version 2
8  * of the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this library; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18  *
19  */
20 
21 #ifndef PSITABWIDGET_H
22 #define PSITABWIDGET_H
23 
24 #include <QTabWidget>
25 #include <QTabBar>
26 #include <QDragEnterEvent>
27 #include "psitabbar.h"
28 
29 class QVBoxLayout;
30 class QHBoxLayout;
31 class QToolButton;
32 class QStackedLayout;
33 class QMenu;
34 
35 /**
36  * \class PsiTabWidget
37  * \brief
38  */
39 class PsiTabWidget : public QWidget //: public QTabWidget
40 {
41 	Q_OBJECT
42 public:
43 	PsiTabWidget(QWidget *parent = 0);
44 	~PsiTabWidget();
45 
46 	void setTabTextColor(QWidget *tab, const QColor &color);
47 	int count();
48 	QWidget *currentPage();
49 	int currentPageIndex();
50 	QWidget *widget(int index);
51 	void addTab(QWidget *, QString, const QIcon &icon = QIcon());
52 	void showPage(QWidget *);
53 	void showPageDirectly(QWidget *);
54 
55 	void removePage(QWidget *);
56 	QWidget* page(int index);
57 	int getIndex(QWidget *);
58 	void setTabText(QWidget *, const QString &);
59 	void setTabIcon(QWidget *, const QIcon &);
60 	void setTabPosition(QTabWidget::TabPosition pos);
61 	void setCloseIcon(const QIcon &);
62 
63 	void setTabBarShown(bool shown);     // default shown
64 	void setTabButtonsShown(bool shown); // default shown
65 	void setDragsEnabled(bool enabled);  // default enabled
66 
67 public slots:
68 	void setCurrentPage(int);
69 	void removeCurrentPage();
70 	void setLooks();
71 
72 signals:
73 	void mouseDoubleClickTab(QWidget *tab);
74 	void mouseMiddleClickTab(QWidget *tab);
75 	void currentChanged(QWidget *selected);
76 	void closeButtonClicked();
77 	void aboutToShowMenu(QMenu *);
78 	void tabCloseRequested(int i);
79 
80 	// context menu on the blank space will have tab==-1
81 	void tabContextMenu(int tab, QPoint pos, QContextMenuEvent *event);
82 
83 private slots:
84 	void mouseDoubleClickTab(int tab);
85 	void mouseMiddleClickTab(int tab);
86 	void tab_currentChanged(int tab);
87 	void tab_contextMenu(QContextMenuEvent *event, int tab);
88 	void menu_aboutToShow();
89 	void menu_triggered(QAction *act);
90 	void widgetMoved(int from, int to);
91 
92 private:
93 	QVector<QWidget*> widgets_;
94 	QTabBar *tabBar_;
95 	QVBoxLayout *layout_;
96 	QHBoxLayout *barLayout_;
97 	QStackedLayout *stacked_;
98 	QToolButton *closeButton_;
99 	QToolButton *downButton_;
100 	QTabWidget::TabPosition tabsPosition_;
101 	QMenu *menu_;
102 };
103 
104 
105 #define PSITABDRAGMIMETYPE "x-drag-drop/x-psi-tab-drag"
106 
107 #endif
108