OSDN Git Service

940cc4dd6a454fe988cd640e4c9621f44956f7f2
[qt-creator-jp/qt-creator-jp.git] / src / plugins / coreplugin / fancytabwidget.h
1 /**************************************************************************
2 **
3 ** This file is part of Qt Creator
4 **
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
6 **
7 ** Contact: Nokia Corporation (qt-info@nokia.com)
8 **
9 ** No Commercial Usage
10 **
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
14 ** this package.
15 **
16 ** GNU Lesser General Public License Usage
17 **
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file.  Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Nokia gives you certain additional
26 ** rights.  These rights are described in the Nokia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
31 **
32 **************************************************************************/
33
34 #ifndef FANCYTABWIDGET_H
35 #define FANCYTABWIDGET_H
36
37 #include <QtGui/QIcon>
38 #include <QtGui/QWidget>
39
40 #include <QtCore/QTimer>
41 #include <QtCore/QPropertyAnimation>
42
43 QT_BEGIN_NAMESPACE
44 class QPainter;
45 class QStackedLayout;
46 class QStatusBar;
47 QT_END_NAMESPACE
48
49 namespace Core {
50 namespace Internal {
51
52 class FancyTab : public QObject
53 {
54     Q_OBJECT
55
56     Q_PROPERTY(float fader READ fader WRITE setFader)
57 public:
58     FancyTab(QWidget *tabbar) : enabled(false), tabbar(tabbar), m_fader(0) {
59         animator.setPropertyName("fader");
60         animator.setTargetObject(this);
61     }
62     float fader() { return m_fader; }
63     void setFader(float value);
64
65     void fadeIn();
66     void fadeOut();
67
68     QIcon icon;
69     QString text;
70     QString toolTip;
71     bool enabled;
72
73 private:
74     QPropertyAnimation animator;
75     QWidget *tabbar;
76     float m_fader;
77 };
78
79 class FancyTabBar : public QWidget
80 {
81     Q_OBJECT
82
83 public:
84     FancyTabBar(QWidget *parent = 0);
85     ~FancyTabBar();
86
87     bool event(QEvent *event);
88
89     void paintEvent(QPaintEvent *event);
90     void paintTab(QPainter *painter, int tabIndex) const;
91     void mousePressEvent(QMouseEvent *);
92     void mouseMoveEvent(QMouseEvent *);
93     void enterEvent(QEvent *);
94     void leaveEvent(QEvent *);
95     bool validIndex(int index) const { return index >= 0 && index < m_tabs.count(); }
96
97     QSize sizeHint() const;
98     QSize minimumSizeHint() const;
99
100     void setTabEnabled(int index, bool enable);
101     bool isTabEnabled(int index) const;
102
103     void insertTab(int index, const QIcon &icon, const QString &label) {
104         FancyTab *tab = new FancyTab(this);
105         tab->icon = icon;
106         tab->text = label;
107         m_tabs.insert(index, tab);
108     }
109     void setEnabled(int index, bool enabled);
110     void removeTab(int index) {
111         FancyTab *tab = m_tabs.takeAt(index);
112         delete tab;
113     }
114     void setCurrentIndex(int index);
115     int currentIndex() const { return m_currentIndex; }
116
117     void setTabToolTip(int index, QString toolTip) { m_tabs[index]->toolTip = toolTip; }
118     QString tabToolTip(int index) const { return m_tabs.at(index)->toolTip; }
119
120     QIcon tabIcon(int index) const { return m_tabs.at(index)->icon; }
121     QString tabText(int index) const { return m_tabs.at(index)->text; }
122     int count() const {return m_tabs.count(); }
123     QRect tabRect(int index) const;
124
125 signals:
126     void currentChanged(int);
127
128 public slots:
129     void emitCurrentIndex();
130
131 private:
132     static const int m_rounding;
133     static const int m_textPadding;
134     QRect m_hoverRect;
135     int m_hoverIndex;
136     int m_currentIndex;
137     QList<FancyTab*> m_tabs;
138     QTimer m_triggerTimer;
139     QSize tabSizeHint(bool minimum = false) const;
140
141 };
142
143 class FancyTabWidget : public QWidget
144 {
145     Q_OBJECT
146
147 public:
148     FancyTabWidget(QWidget *parent = 0);
149
150     void insertTab(int index, QWidget *tab, const QIcon &icon, const QString &label);
151     void removeTab(int index);
152     void setBackgroundBrush(const QBrush &brush);
153     void addCornerWidget(QWidget *widget);
154     void insertCornerWidget(int pos, QWidget *widget);
155     int cornerWidgetCount() const;
156     void setTabToolTip(int index, const QString &toolTip);
157
158     void paintEvent(QPaintEvent *event);
159
160     int currentIndex() const;
161     QStatusBar *statusBar() const;
162
163     void setTabEnabled(int index, bool enable);
164     bool isTabEnabled(int index) const;
165
166 signals:
167     void currentAboutToShow(int index);
168     void currentChanged(int index);
169
170 public slots:
171     void setCurrentIndex(int index);
172
173 private slots:
174     void showWidget(int index);
175
176 private:
177     FancyTabBar *m_tabBar;
178     QWidget *m_cornerWidgetContainer;
179     QStackedLayout *m_modesStack;
180     QWidget *m_selectionWidget;
181     QStatusBar *m_statusBar;
182 };
183
184 } // namespace Internal
185 } // namespace Core
186
187 #endif // FANCYTABWIDGET_H