/
litetabwidget.h
113 lines (106 loc) · 3.21 KB
/
litetabwidget.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/**************************************************************************
** This file is part of LiteIDE
**
** Copyright (c) 2011-2015 LiteIDE Team. All rights reserved.
**
** This library is free software; you can redistribute it and/or
** modify it under the terms of the GNU Lesser General Public
** License as published by the Free Software Foundation; either
** version 2.1 of the License, or (at your option) any later version.
**
** This library is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
** Lesser General Public License for more details.
**
** In addition, as a special exception, that plugins developed for LiteIDE,
** are allowed to remain closed sourced and can be distributed under any license .
** These rights are included in the file LGPL_EXCEPTION.txt in this package.
**
**************************************************************************/
// Module: litetabwidget.h
// Creator: visualfc <visualfc@gmail.com>
#ifndef LITETABWIDGET_H
#define LITETABWIDGET_H
#include <QWidget>
#include <QMap>
#include <QPointer>
#include <QTabBar>
class QMenu;
class QTabBar;
class QHBoxLayout;
class QStackedLayout;
class QStackedWidget;
class QToolButton;
class QToolBar;
class QAction;
class QActionGroup;
//header : headerWidget
//body: stackedWidget
class TabBar : public QTabBar
{
public:
TabBar(QWidget *parent = 0) : QTabBar(parent)
{
m_enableWheel = true;
}
void wheelEvent(QWheelEvent *event)
{
if (!m_enableWheel) {
return;
}
QTabBar::wheelEvent(event);
}
void setEnableWheel(bool b) {
m_enableWheel = b;
}
bool enableWheel() const {
return m_enableWheel;
}
protected:
bool m_enableWheel;
};
class LiteTabWidget : public QObject
{
Q_OBJECT
public:
explicit LiteTabWidget(QSize iconSize, QObject *parent = 0);
virtual ~LiteTabWidget();
int addTab(QWidget *w,const QString & label, const QString &tip);
int addTab(QWidget *w,const QIcon & icon, const QString & label,const QString &tip);
void removeTab(int index);
int indexOf(QWidget *w);
QWidget *widget(int index);
QWidget *currentWidget();
TabBar *tabBar();
void setTabText(int index, const QString & text);
QList<QWidget*> widgetList() const;
QWidget *stackedWidget();
QWidget *tabBarWidget();
signals:
void currentChanged(int index);
void tabCloseRequested(int index);
void tabAddRequest();
public slots:
void setCurrentWidget(QWidget *w);
void setCurrentIndex(int index);
void tabMoved(int,int);
public slots:
void closeCurrentTab();
void selectListActGroup(QAction*);
void tabCurrentChanged(int);
protected:
QToolBar *m_dumpToolBar;
QWidget *m_tabBarWidget;
TabBar *m_tabBar;
QToolButton *m_listButton;
QToolButton *m_closeButton;
QStackedWidget *m_stackedWidget;
QList<QWidget*> m_widgetList;
QAction *m_closeTabAct;
QAction *m_addTabAct;
QMenu *m_listActMenu;
QActionGroup *m_listActGroup;
QPointer<QWidget> m_currentWidget;
};
#endif // LITETABWIDGET_H