~ubuntu-branches/ubuntu/wily/psi/wily-proposed

« back to all changes in this revision

Viewing changes to src/widgets/psitabwidget.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jan Niehusmann
  • Date: 2008-08-28 18:46:52 UTC
  • mfrom: (1.2.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20080828184652-iiik12dl91nq7cdi
Tags: 0.12-2
Uploading to unstable (Closes: Bug#494352)

Show diffs side-by-side

added added

removed removed

Lines of Context:
33
33
/**
34
34
 * Constructor
35
35
 */
36
 
PsiTabWidget::PsiTabWidget(QWidget *parent) : QWidget(parent)
37
 
        //: QTabWidget(parent)
38
 
{
 
36
PsiTabWidget::PsiTabWidget(QWidget *parent)
 
37
                : 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);
50
49
 
51
50
        int buttonwidth = qMax(tabBar_->style()->pixelMetric(QStyle::PM_TabBarScrollButtonWidth, 0, tabBar_),
52
 
                    QApplication::globalStrut().width());
 
51
                QApplication::globalStrut().width());
53
52
 
54
53
        downButton_ = new QToolButton(this);
55
54
        downButton_->setMinimumSize(3,3);
87
86
/**
88
87
 * Destructor
89
88
 */
90
 
PsiTabWidget::~PsiTabWidget()
91
 
{
92
 
        
 
89
PsiTabWidget::~PsiTabWidget() {
93
90
}
94
91
 
95
92
/**
97
94
 * \param tab Widget for the tab to change.
98
95
 * \param color Color to set text.
99
96
 */
100
 
void PsiTabWidget::setTabTextColor( QWidget* tab, const QColor& color)
101
 
{
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);
105
101
                }
106
102
        }
107
103
}
111
107
 * \param index Widget to return.
112
108
 * \return Specified widget. 
113
109
 */
114
 
QWidget* PsiTabWidget::widget(int index)
115
 
{
 
110
QWidget *PsiTabWidget::widget(int index) {
116
111
        return widgets_[index];
117
112
}
118
113
 
119
 
void PsiTabWidget::mouseDoubleClickTab( int tab )
120
 
{
 
114
void PsiTabWidget::mouseDoubleClickTab(int tab) {
121
115
        emit mouseDoubleClickTab(widget(tab));
122
116
}
123
117
 
124
118
/**
125
119
 * Number of tabs/widgets
126
120
 */
127
 
int PsiTabWidget::count()
128
 
{
 
121
int PsiTabWidget::count() {
129
122
        return tabBar_->count();
130
123
131
124
 
132
125
/**
133
126
 * Returns the widget of the current page
134
127
 */
135
 
QWidget* PsiTabWidget::currentPage()
136
 
{
 
128
QWidget *PsiTabWidget::currentPage() {
 
129
        if (currentPageIndex() == -1)
 
130
                return 0;
137
131
        return widgets_[currentPageIndex()];
138
132
}
139
133
 
140
 
void PsiTabWidget::tab_currentChanged( int tab )
141
 
{
 
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());
146
139
}
147
140
 
148
 
 
149
141
/**
150
142
 * Returns the index of the current page
151
143
 */
152
 
int PsiTabWidget::currentPageIndex()
153
 
{
 
144
int PsiTabWidget::currentPageIndex() {
154
145
        return tabBar_->currentIndex();
155
146
}
156
147
 
157
148
/**
158
149
 * Add the Widget to the tab stack.
159
150
 */
160
 
void PsiTabWidget::addTab(QWidget* widget, QString name) 
161
 
{
 
151
void PsiTabWidget::addTab(QWidget *widget, QString name) {
162
152
        Q_ASSERT(widget);
163
153
        if (widgets_.contains(widget)) {
164
154
                return;
173
163
 * Selects the page for the specified widget.
174
164
 */
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);
225
215
/**
226
216
 * Set the text of the tab.
227
217
 */
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) {
231
221
                return;
242
232
        removePage(currentPage());
243
233
}
244
234
 
245
 
void PsiTabWidget::setTabPosition(QTabWidget::TabPosition pos)
246
 
{
247
 
        if (tabsPosition_ == pos) return;
 
235
void PsiTabWidget::setTabPosition(QTabWidget::TabPosition pos) {
 
236
        if (tabsPosition_ == pos) {
 
237
                return;
 
238
        }
248
239
 
249
240
        tabsPosition_ = pos;
250
241
        tabBar_->setShape(tabsPosition_ == QTabWidget::Top ? QTabBar::RoundedNorth : QTabBar::RoundedSouth);
264
255
        }
265
256
}
266
257
 
267
 
void PsiTabWidget::menu_aboutToShow()
268
 
{
 
258
void PsiTabWidget::menu_aboutToShow() {
269
259
        menu_->clear();
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_);
281
271
}
282
272
 
283
 
void PsiTabWidget::menu_triggered(QAction *act)
284
 
{
 
273
void PsiTabWidget::menu_triggered(QAction *act) {
285
274
        int idx = act->data().toInt();
286
275
        if (idx <= 0 || idx > tabBar_->count()) {
287
276
                // out of range
291
280
        }
292
281
}
293
282
 
294
 
 
295
 
void PsiTabWidget::tab_contextMenu( QContextMenuEvent * event, int tab)
296
 
{
 
283
void PsiTabWidget::tab_contextMenu( QContextMenuEvent * event, int tab) {
297
284
        emit tabContextMenu(tab, tabBar_->mapToGlobal(event->pos()), event);
298
285
}
299
286
 
300
 
 
301
 
 
302
287
QWidget* PsiTabWidget::page(int index) {
303
288
        Q_ASSERT(index >=0 && index < count());
304
289
        return widgets_[index];
305
290
}
 
291
 
 
292
/**
 
293
 * Show/hide the tab bar of this widget
 
294
 */
 
295
void PsiTabWidget::setTabBarShown(bool shown) {
 
296
        if (shown && tabBar_->isHidden()) {
 
297
                tabBar_->show();
 
298
        } else if (!shown && !tabBar_->isHidden()) {
 
299
                tabBar_->hide();
 
300
        }
 
301
}
 
302
 
 
303
/**
 
304
 * Show/hide the menu and close buttons that appear next to the tab bar
 
305
 */
 
306
void PsiTabWidget::setTabButtonsShown(bool shown) {
 
307
        if (shown && downButton_->isHidden()) {
 
308
                downButton_->show();
 
309
                closeButton_->show();
 
310
        } else if (!shown && !downButton_->isHidden()) {
 
311
                downButton_->hide();
 
312
                closeButton_->hide();
 
313
        }
 
314
}
 
315
 
 
316
/**
 
317
 * Enable/disable dragging of tabs
 
318
 */
 
319
void PsiTabWidget::setDragsEnabled(bool enabled) {
 
320
        ((PsiTabBar *)tabBar_)->setDragsEnabled(enabled);
 
321
}