36
PsiTabWidget::PsiTabWidget(QWidget *parent) : QWidget(parent)
37
//: QTabWidget(parent)
36
PsiTabWidget::PsiTabWidget(QWidget *parent)
39
38
tabsPosition_ = QTabWidget::East; // impossible => uninitialised state
40
39
tabBar_ = new PsiTabBar(this);
41
40
tabBar_->setUsesScrollButtons(true);
49
48
barLayout_->setAlignment(Qt::AlignLeft);
51
50
int buttonwidth = qMax(tabBar_->style()->pixelMetric(QStyle::PM_TabBarScrollButtonWidth, 0, tabBar_),
52
QApplication::globalStrut().width());
51
QApplication::globalStrut().width());
54
53
downButton_ = new QToolButton(this);
55
54
downButton_->setMinimumSize(3,3);
97
94
* \param tab Widget for the tab to change.
98
95
* \param color Color to set text.
100
void PsiTabWidget::setTabTextColor( QWidget* tab, const QColor& color)
102
for (int i=0; i < count(); i++) {
103
if ( widget(i) == tab ) {
104
tabBar_->setTabTextColor(i,color);
97
void PsiTabWidget::setTabTextColor( QWidget* tab, const QColor& color) {
98
for (int i = 0; i < count(); i++) {
99
if (widget(i) == tab) {
100
tabBar_->setTabTextColor(i, color);
111
107
* \param index Widget to return.
112
108
* \return Specified widget.
114
QWidget* PsiTabWidget::widget(int index)
110
QWidget *PsiTabWidget::widget(int index) {
116
111
return widgets_[index];
119
void PsiTabWidget::mouseDoubleClickTab( int tab )
114
void PsiTabWidget::mouseDoubleClickTab(int tab) {
121
115
emit mouseDoubleClickTab(widget(tab));
125
119
* Number of tabs/widgets
127
int PsiTabWidget::count()
121
int PsiTabWidget::count() {
129
122
return tabBar_->count();
133
126
* Returns the widget of the current page
135
QWidget* PsiTabWidget::currentPage()
128
QWidget *PsiTabWidget::currentPage() {
129
if (currentPageIndex() == -1)
137
131
return widgets_[currentPageIndex()];
140
void PsiTabWidget::tab_currentChanged( int tab )
134
void PsiTabWidget::tab_currentChanged(int tab) {
142
135
// qt 4.4 sends -1 i case of an empty QTabbar, ignore that case.
143
136
if (tab == -1) return;
144
137
setCurrentPage(tab);
145
138
emit currentChanged(currentPage());
150
142
* Returns the index of the current page
152
int PsiTabWidget::currentPageIndex()
144
int PsiTabWidget::currentPageIndex() {
154
145
return tabBar_->currentIndex();
158
149
* Add the Widget to the tab stack.
160
void PsiTabWidget::addTab(QWidget* widget, QString name)
151
void PsiTabWidget::addTab(QWidget *widget, QString name) {
162
152
Q_ASSERT(widget);
163
153
if (widgets_.contains(widget)) {
173
163
* Selects the page for the specified widget.
175
165
void PsiTabWidget::showPage(QWidget* widget) {
176
for (int i=0; i < count(); i++) {
166
for (int i = 0; i < count(); i++) {
177
167
if (widgets_[i] == widget) {
178
168
showPageDirectly(widget);
179
169
tabBar_->setCurrentIndex(i);
226
216
* Set the text of the tab.
228
void PsiTabWidget::setTabLabel(QWidget* widget, const QString& label) {
218
void PsiTabWidget::setTabText(QWidget* widget, const QString& label) {
229
219
int index = getIndex(widget);
230
220
if (index == -1) {
242
232
removePage(currentPage());
245
void PsiTabWidget::setTabPosition(QTabWidget::TabPosition pos)
247
if (tabsPosition_ == pos) return;
235
void PsiTabWidget::setTabPosition(QTabWidget::TabPosition pos) {
236
if (tabsPosition_ == pos) {
249
240
tabsPosition_ = pos;
250
241
tabBar_->setShape(tabsPosition_ == QTabWidget::Top ? QTabBar::RoundedNorth : QTabBar::RoundedSouth);
267
void PsiTabWidget::menu_aboutToShow()
258
void PsiTabWidget::menu_aboutToShow() {
270
260
bool vis = false;
271
for (int i=0; i < tabBar_->count(); i++) {
261
for (int i = 0; i < tabBar_->count(); i++) {
272
262
QRect r = tabBar_->tabRect(i);
273
263
bool newvis = tabBar_->rect().contains(r);
274
264
if (newvis != vis) {
280
270
emit aboutToShowMenu(menu_);
283
void PsiTabWidget::menu_triggered(QAction *act)
273
void PsiTabWidget::menu_triggered(QAction *act) {
285
274
int idx = act->data().toInt();
286
275
if (idx <= 0 || idx > tabBar_->count()) {
295
void PsiTabWidget::tab_contextMenu( QContextMenuEvent * event, int tab)
283
void PsiTabWidget::tab_contextMenu( QContextMenuEvent * event, int tab) {
297
284
emit tabContextMenu(tab, tabBar_->mapToGlobal(event->pos()), event);
302
287
QWidget* PsiTabWidget::page(int index) {
303
288
Q_ASSERT(index >=0 && index < count());
304
289
return widgets_[index];
293
* Show/hide the tab bar of this widget
295
void PsiTabWidget::setTabBarShown(bool shown) {
296
if (shown && tabBar_->isHidden()) {
298
} else if (!shown && !tabBar_->isHidden()) {
304
* Show/hide the menu and close buttons that appear next to the tab bar
306
void PsiTabWidget::setTabButtonsShown(bool shown) {
307
if (shown && downButton_->isHidden()) {
309
closeButton_->show();
310
} else if (!shown && !downButton_->isHidden()) {
312
closeButton_->hide();
317
* Enable/disable dragging of tabs
319
void PsiTabWidget::setDragsEnabled(bool enabled) {
320
((PsiTabBar *)tabBar_)->setDragsEnabled(enabled);