QtCanpool
3.3.0
载入中...
搜索中...
未找到
ribbontabbar.cpp
浏览该文件的文档.
1
5
#include "
ribbontabbar.h
"
6
7
#include <QTimer>
8
#include <QWheelEvent>
9
10
QX_RIBBON_BEGIN_NAMESPACE
11
12
RibbonTabBar::RibbonTabBar(QWidget *parent)
13
: QTabBar(parent)
14
, m_tabMargin(6, 0, 0, 0)
15
{
16
setExpanding(
false
);
17
18
// sentry tab
19
QTabBar::addTab(QString());
20
// Disable tab to prevent tab from being clicked
21
setTabEnabled(0,
false
);
22
}
23
24
const
QMargins &
RibbonTabBar::tabMargin
()
const
25
{
26
return
m_tabMargin;
27
}
28
29
void
RibbonTabBar::setTabMargin
(
const
QMargins &margin)
30
{
31
m_tabMargin = margin;
32
}
33
34
int
RibbonTabBar::addTab
(
const
QString &
text
)
35
{
36
return
insertTab
(-1,
text
);
37
}
38
39
int
RibbonTabBar::insertTab
(
int
index,
const
QString &
text
)
40
{
41
int
validCnt =
count
();
42
if
(index < 0 || index > validCnt) {
43
index = validCnt;
44
}
45
int
newIndex = QTabBar::insertTab(index,
text
);
46
if
(validCnt == 0) {
47
setCurrentIndex
(0);
48
}
49
return
newIndex;
50
}
51
52
int
RibbonTabBar::currentIndex
()
const
53
{
54
int
index = QTabBar::currentIndex();
55
if
(index ==
count
()) {
56
return
-1;
57
}
else
{
58
return
index;
59
}
60
}
61
62
int
RibbonTabBar::count
()
const
63
{
64
// valid count does not include sentry tab
65
return
QTabBar::count() - 1;
66
}
67
68
void
RibbonTabBar::setCurrentIndex
(
int
index)
69
{
70
if
(index == -1) {
71
blockSignals(
true
);
72
QTabBar::setCurrentIndex(
count
());
73
blockSignals(
false
);
74
}
else
{
75
QTabBar::setCurrentIndex(index);
76
}
77
}
78
79
QSize
RibbonTabBar::tabSizeHint
(
int
index)
const
80
{
81
QSize sz = QTabBar::tabSizeHint(index);
82
sz.setHeight(this->height());
83
84
return
sz;
85
}
86
87
void
RibbonTabBar::wheelEvent
(QWheelEvent *event)
88
{
89
// prevent scrolling to the sentry tab
90
if
(
currentIndex
() ==
count
() - 1) {
91
if
(event->angleDelta().y() <= 0) {
92
return
;
93
}
94
}
95
QTabBar::wheelEvent(event);
96
}
97
98
QX_RIBBON_END_NAMESPACE
QxRibbon::RibbonTabBar::setCurrentIndex
void setCurrentIndex(int index)
Definition
ribbontabbar.cpp:68
QxRibbon::RibbonTabBar::tabSizeHint
virtual QSize tabSizeHint(int index) const override
Definition
ribbontabbar.cpp:79
QxRibbon::RibbonTabBar::setTabMargin
void setTabMargin(const QMargins &margin)
Definition
ribbontabbar.cpp:29
QxRibbon::RibbonTabBar::count
int count() const
Definition
ribbontabbar.cpp:62
QxRibbon::RibbonTabBar::tabMargin
const QMargins & tabMargin() const
Definition
ribbontabbar.cpp:24
QxRibbon::RibbonTabBar::insertTab
int insertTab(int index, const QString &text)
Definition
ribbontabbar.cpp:39
QxRibbon::RibbonTabBar::addTab
int addTab(const QString &text)
Definition
ribbontabbar.cpp:34
QxRibbon::RibbonTabBar::wheelEvent
void wheelEvent(QWheelEvent *event) override
Definition
ribbontabbar.cpp:87
QxRibbon::RibbonTabBar::currentIndex
int currentIndex() const
Definition
ribbontabbar.cpp:52
QX_RIBBON_END_NAMESPACE
#define QX_RIBBON_END_NAMESPACE
Definition
qxribbon_global.h:63
QX_RIBBON_BEGIN_NAMESPACE
#define QX_RIBBON_BEGIN_NAMESPACE
Definition
qxribbon_global.h:60
text
QColor text
Definition
qxthemepalette.cpp:20
ribbontabbar.h
src
libs
qxribbon
ribbontabbar.cpp
制作者
1.9.8