2
* psitabbar.cpp - Tabbar child for Psi
3
* Copyright (C) 2006 Kevin Smith
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.
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.
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
21
#include "psitabbar.h"
22
#include "psitabwidget.h"
23
#include <QMouseEvent>
24
#include <QApplication>
29
PsiTabBar::PsiTabBar(PsiTabWidget *parent)
38
PsiTabBar::~PsiTabBar()
44
* Returns the parent PsiTabWidget.
46
PsiTabWidget* PsiTabBar::psiTabWidget()
48
return dynamic_cast<PsiTabWidget*> (parent());
52
* Overriding this allows us to emit signals for double clicks
54
void PsiTabBar::mouseDoubleClickEvent( QMouseEvent* event )
56
const QPoint pos = event->pos();
57
int tab = findTabUnder( pos );
58
if ( tab >=0 && tab < count() )
59
emit mouseDoubleClickTab(tab);
63
* Returns the index of the tab at a position, or -1 if out of bounds.
65
int PsiTabBar::findTabUnder( const QPoint& pos )
67
for (int i = 0; i < count(); i++)
69
if ( tabRect(i).contains(pos) )
75
void PsiTabBar::mousePressEvent(QMouseEvent *event)
77
if (event->button() == Qt::LeftButton) {
78
int tabno = findTabUnder( event->pos() );
79
dragStartPosition_ = event->pos();
81
if (tabno != -1) setCurrentIndex( tabno );
87
* Used for starting drags of tabs
89
void PsiTabBar::mouseMoveEvent(QMouseEvent *event)
91
if (!(event->buttons() & Qt::LeftButton))
93
if ( (event->pos() - dragStartPosition_).manhattanLength()
94
< QApplication::startDragDistance() )
99
QDrag *drag = new QDrag(this);
100
QMimeData *mimeData = new QMimeData;
104
data.setNum(dragTab_);
106
mimeData->setData("psiTabDrag",data);
107
drag->setMimeData(mimeData);
108
drag->setPixmap(icon);
110
Qt::DropAction dropAction = drag->start(Qt::MoveAction);
111
Q_UNUSED(dropAction);
117
void PsiTabBar::contextMenuEvent ( QContextMenuEvent * event )
120
emit contextMenu(event, findTabUnder(event->pos()));
123
void PsiTabBar::wheelEvent(QWheelEvent *event)
125
int numDegrees = event->delta() / 8;
126
int numSteps = numDegrees / 15;
128
int newIndex = currentIndex() - numSteps;
130
while (newIndex < 0) newIndex += count();
131
newIndex = newIndex % count();
133
setCurrentIndex(newIndex);