summaryrefslogtreecommitdiffstats
path: root/lib/widgets/kdevtabwidget.cpp
blob: 49925115b8fb91f227eb67e886eb31849e91bd61 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/***************************************************************************
 *   Copyright (C) 2001-2003                                               *
 *   The KDevelop Team                                                     *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#include <qpopupmenu.h>

#include <kglobal.h>
#include <klocale.h>
#include <kicontheme.h>
#include <kiconloader.h>

#include "kdevtabwidget.h"

KDevTabWidget::KDevTabWidget(QWidget *parent, const char *name) : QTabWidget(parent,name)
{
  m_pTabBar = new KTabBar(this, "tabbar");
  setTabBar(m_pTabBar);
  connect(m_pTabBar, SIGNAL(closeWindow(const QWidget*)), this, SIGNAL(closeWindow(const QWidget*)));
  connect(m_pTabBar, SIGNAL(closeOthers(QWidget*)), this, SIGNAL(closeOthers(QWidget*)));
}

KTabBar::KTabBar(QWidget *parent, const char *name) : QTabBar(parent,name)
{
  m_pPopupMenu = new QPopupMenu(this);

  QPixmap closePixmap = KGlobal::instance()->iconLoader()->loadIcon( "tab_remove", KIcon::Small, 0, KIcon::DefaultState, 0, true ); 
  if (closePixmap.isNull())
    closePixmap = SmallIcon("fileclose");

  m_pPopupMenu->insertItem(closePixmap, i18n("&Close"), this, SLOT(closeWindowSlot()));
  m_pPopupMenu->insertItem(i18n("Close &Others"), this, SLOT(closeOthersSlot()));
}

void KTabBar::closeWindowSlot()
{
	emit closeWindow(m_pPage);
}

void KTabBar::closeOthersSlot()
{
	emit closeOthers(m_pPage);
}

void KTabBar::mousePressEvent(QMouseEvent *e)
{
  if(e->button() == Qt::RightButton) {

    QTab *tab = selectTab(e->pos() );
    if( tab == 0L ) return;
    
    m_pPage = ((KDevTabWidget*)parent())->page(indexOf(tab->identifier() ) );
    if(m_pPage == 0L) return;

    m_pPopupMenu->exec(mapToGlobal(e->pos()));
  }
  QTabBar::mousePressEvent(e);
}

#include "kdevtabwidget.moc"