~ubuntu-branches/ubuntu/quantal/psi/quantal

« back to all changes in this revision

Viewing changes to src/widgets/psitabbar.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jan Niehusmann
  • Date: 2008-04-14 18:57:30 UTC
  • mfrom: (2.1.9 hardy)
  • Revision ID: james.westby@ubuntu.com-20080414185730-528re3zp0m2hdlhi
Tags: 0.11-8
* added CONFIG -= link_prl to .pro files and removed dependencies
  which are made unnecessary by this change
* Fix segfault when closing last chat tab with qt4.4
  (This is from upstream svn, rev. 1101) (Closes: Bug#476122)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * psitabbar.cpp - Tabbar child for Psi
 
3
 * Copyright (C) 2006  Kevin Smith
 
4
 *
 
5
 * This program is free software; you can redistribute it and/or
 
6
 * modify it under the terms of the GNU General Public License
 
7
 * as published by the Free Software Foundation; either version 2
 
8
 * of the License, or (at your option) any later version.
 
9
 *
 
10
 * This program is distributed in the hope that it will be useful,
 
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
 * GNU General Public License for more details.
 
14
 *
 
15
 * You should have received a copy of the GNU General Public License
 
16
 * along with this library; if not, write to the Free Software
 
17
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
18
 *
 
19
 */
 
20
 
 
21
#include "psitabbar.h"
 
22
#include "psitabwidget.h"
 
23
#include <QMouseEvent>
 
24
#include <QApplication>
 
25
 
 
26
/**
 
27
 * Constructor
 
28
 */
 
29
PsiTabBar::PsiTabBar(PsiTabWidget *parent)
 
30
        : QTabBar(parent)
 
31
{
 
32
        //acceptDrops();
 
33
}
 
34
 
 
35
/**
 
36
 * Destructor
 
37
 */
 
38
PsiTabBar::~PsiTabBar()
 
39
{
 
40
        
 
41
}
 
42
 
 
43
/**
 
44
 * Returns the parent PsiTabWidget.
 
45
 */
 
46
PsiTabWidget* PsiTabBar::psiTabWidget()
 
47
{
 
48
        return dynamic_cast<PsiTabWidget*> (parent());
 
49
}
 
50
 
 
51
/**
 
52
 * Overriding this allows us to emit signals for double clicks
 
53
 */
 
54
void PsiTabBar::mouseDoubleClickEvent( QMouseEvent* event )
 
55
{
 
56
        const QPoint pos = event->pos();
 
57
        int tab = findTabUnder( pos );
 
58
        if ( tab >=0 && tab < count() )
 
59
                emit mouseDoubleClickTab(tab);
 
60
}
 
61
 
 
62
/*
 
63
 * Returns the index of the tab at a position, or -1 if out of bounds.
 
64
 */
 
65
int PsiTabBar::findTabUnder( const QPoint& pos )
 
66
{
 
67
        for (int i = 0; i < count(); i++)
 
68
        {
 
69
                if ( tabRect(i).contains(pos) )
 
70
                                return i;
 
71
        }
 
72
        return -1;
 
73
 
74
 
 
75
void PsiTabBar::mousePressEvent(QMouseEvent *event)
 
76
{
 
77
    if (event->button() == Qt::LeftButton) {
 
78
                int tabno = findTabUnder( event->pos() );
 
79
        dragStartPosition_ = event->pos();
 
80
                dragTab_ = tabno;
 
81
                if (tabno != -1) setCurrentIndex( tabno );
 
82
        }
 
83
        event->accept();
 
84
}
 
85
 
 
86
/*
 
87
 * Used for starting drags of tabs
 
88
 */ 
 
89
void PsiTabBar::mouseMoveEvent(QMouseEvent *event)
 
90
 {
 
91
        if (!(event->buttons() & Qt::LeftButton))
 
92
                return;
 
93
        if ( (event->pos() - dragStartPosition_).manhattanLength() 
 
94
                < QApplication::startDragDistance() )
 
95
                return;
 
96
 
 
97
        if (dragTab_ != -1) {
 
98
 
 
99
                QDrag *drag = new QDrag(this);
 
100
                QMimeData *mimeData = new QMimeData;
 
101
                QByteArray data;
 
102
                QPixmap icon;
 
103
        
 
104
                data.setNum(dragTab_);
 
105
        
 
106
                mimeData->setData("psiTabDrag",data);
 
107
                drag->setMimeData(mimeData);
 
108
                drag->setPixmap(icon);
 
109
                        
 
110
                Qt::DropAction dropAction = drag->start(Qt::MoveAction);
 
111
                Q_UNUSED(dropAction);
 
112
        }
 
113
 
 
114
        event->accept();
 
115
 }
 
116
 
 
117
void PsiTabBar::contextMenuEvent ( QContextMenuEvent * event )
 
118
{
 
119
        event->accept();
 
120
        emit contextMenu(event, findTabUnder(event->pos()));
 
121
}
 
122
 
 
123
void PsiTabBar::wheelEvent(QWheelEvent *event)
 
124
{
 
125
        int numDegrees = event->delta() / 8;
 
126
        int numSteps = numDegrees / 15;
 
127
        
 
128
        int newIndex = currentIndex() - numSteps;
 
129
 
 
130
        while (newIndex < 0) newIndex += count();
 
131
        newIndex = newIndex % count();
 
132
 
 
133
        setCurrentIndex(newIndex);
 
134
 
 
135
        event->accept();        
 
136
}
 
137
 
 
138