QtCanpool 3.3.0
载入中...
搜索中...
未找到
ribbontabbar.cpp
浏览该文件的文档.
1
5#include "ribbontabbar.h"
6
7#include <QTimer>
8#include <QWheelEvent>
9
11
12RibbonTabBar::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
24const QMargins &RibbonTabBar::tabMargin() const
25{
26 return m_tabMargin;
27}
28
29void RibbonTabBar::setTabMargin(const QMargins &margin)
30{
31 m_tabMargin = margin;
32}
33
34int RibbonTabBar::addTab(const QString &text)
35{
36 return insertTab(-1, text);
37}
38
39int 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) {
48 }
49 return newIndex;
50}
51
53{
54 int index = QTabBar::currentIndex();
55 if (index == count()) {
56 return -1;
57 } else {
58 return index;
59 }
60}
61
63{
64 // valid count does not include sentry tab
65 return QTabBar::count() - 1;
66}
67
69{
70 if (index == -1) {
71 blockSignals(true);
72 QTabBar::setCurrentIndex(count());
73 blockSignals(false);
74 } else {
75 QTabBar::setCurrentIndex(index);
76 }
77}
78
79QSize RibbonTabBar::tabSizeHint(int index) const
80{
81 QSize sz = QTabBar::tabSizeHint(index);
82 sz.setHeight(this->height());
83
84 return sz;
85}
86
87void 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
void setCurrentIndex(int index)
virtual QSize tabSizeHint(int index) const override
void setTabMargin(const QMargins &margin)
const QMargins & tabMargin() const
int insertTab(int index, const QString &text)
int addTab(const QString &text)
void wheelEvent(QWheelEvent *event) override
#define QX_RIBBON_END_NAMESPACE
#define QX_RIBBON_BEGIN_NAMESPACE
QColor text