24 #include <QtCore/QTimer>
25 #include <QtGui/QApplication>
26 #include <QtGui/QCursor>
27 #include <QtGui/QMouseEvent>
31 class KTabBar::Private
35 : mReorderStartTab( -1 ),
36 mReorderPreviousTab( -1 ),
38 mActivateDragSwitchTabTimer( 0 ),
39 mTabReorderingEnabled( false ),
40 mMiddleMouseTabMoveInProgress( false)
46 int mReorderPreviousTab;
48 QTimer *mActivateDragSwitchTabTimer;
50 bool mTabReorderingEnabled : 1;
51 bool mMiddleMouseTabMoveInProgress : 1;
59 setAcceptDrops(
true );
60 setMouseTracking(
true );
62 d->mActivateDragSwitchTabTimer =
new QTimer(
this );
63 d->mActivateDragSwitchTabTimer->setSingleShot(
true );
65 #ifndef KDE_NO_DEPRECATED
66 connect(
this, SIGNAL(tabCloseRequested(
int)),
this, SIGNAL(
closeRequest(
int)));
79 if ( event->button() != Qt::LeftButton )
87 #ifndef KDE_NO_DEPRECATED
93 QTabBar::mouseDoubleClickEvent( event );
98 if ( event->button() == Qt::LeftButton ) {
99 d->mDragStart =
event->pos();
100 }
else if( event->button() == Qt::RightButton ) {
103 emit
contextMenu( tab, mapToGlobal( event->pos() ) );
108 }
else if (QTabBar::isMovable() && event->button() == Qt::MidButton) {
111 QMouseEvent fakedMouseEvent(event->type(),
event->pos(), Qt::LeftButton, Qt::LeftButton,
event->modifiers());
112 QCoreApplication::sendEvent(
this, &fakedMouseEvent);
115 QTabBar::mousePressEvent( event );
120 if ( event->buttons() == Qt::LeftButton && !isMovable() ) {
122 if ( d->mDragSwitchTab && tab != d->mDragSwitchTab ) {
123 d->mActivateDragSwitchTabTimer->stop();
124 d->mDragSwitchTab = 0;
128 QPoint newPos =
event->pos();
129 if ( newPos.x() > d->mDragStart.x() + delay || newPos.x() < d->mDragStart.x() - delay ||
130 newPos.y() > d->mDragStart.y() + delay || newPos.y() < d->mDragStart.y() - delay ) {
136 }
else if ( event->buttons() == Qt::MidButton && !isMovable() ) {
137 if ( d->mReorderStartTab == -1 ) {
139 QPoint newPos =
event->pos();
141 if ( newPos.x() > d->mDragStart.x() + delay || newPos.x() < d->mDragStart.x() - delay ||
142 newPos.y() > d->mDragStart.y() + delay || newPos.y() < d->mDragStart.y() - delay ) {
144 if ( tab != -1 && d->mTabReorderingEnabled ) {
145 d->mReorderStartTab = tab;
146 grabMouse( Qt::SizeAllCursor );
153 int reorderStopTab = tab;
154 if ( d->mReorderStartTab != reorderStopTab && d->mReorderPreviousTab != reorderStopTab ) {
155 emit
moveTab( d->mReorderStartTab, reorderStopTab );
157 d->mReorderPreviousTab = d->mReorderStartTab;
158 d->mReorderStartTab = reorderStopTab;
164 }
else if ( event->button() == Qt::NoButton &&
event->buttons() == Qt::MidButton && isMovable() ) {
166 d->mMiddleMouseTabMoveInProgress =
true;
168 QMouseEvent fakedMouseEvent(event->type(),
event->pos(),
event->button(), Qt::LeftButton,
event->modifiers());
169 QCoreApplication::sendEvent(
this, &fakedMouseEvent);
173 QTabBar::mouseMoveEvent( event );
177 #ifndef KDE_NO_DEPRECATED
185 #ifndef KDE_NO_DEPRECATED
195 int tab =
selectTab( mapFromGlobal( QCursor::pos() ) );
196 if ( tab != -1 && d->mDragSwitchTab == tab )
197 setCurrentIndex( d->mDragSwitchTab );
199 d->mDragSwitchTab = 0;
204 switch ( event->button() ) {
209 if (d->mMiddleMouseTabMoveInProgress && QTabBar::isMovable()) {
211 d->mMiddleMouseTabMoveInProgress =
false;
213 QMouseEvent fakedMouseEvent(event->type(),
event->pos(), Qt::LeftButton, Qt::LeftButton,
event->modifiers());
214 QCoreApplication::sendEvent(
this, &fakedMouseEvent);
217 if ( d->mReorderStartTab == -1 ) {
221 if (QTabBar::isMovable()) {
222 QMouseEvent fakedMouseEvent(event->type(),
event->pos(), Qt::LeftButton, Qt::LeftButton,
event->modifiers());
223 QCoreApplication::sendEvent(
this, &fakedMouseEvent);
230 setCursor( Qt::ArrowCursor );
231 d->mReorderStartTab = -1;
232 d->mReorderPreviousTab = -1;
240 QTabBar::mouseReleaseEvent( event );
251 if ( accept && tab != currentIndex() ) {
252 d->mDragSwitchTab = tab;
253 d->mActivateDragSwitchTabTimer->start( QApplication::doubleClickInterval() * 2 );
256 event->setAccepted( accept );
260 QTabBar::dragEnterEvent( event );
271 if ( accept && tab != currentIndex() ) {
272 d->mDragSwitchTab = tab;
273 d->mActivateDragSwitchTabTimer->start( QApplication::doubleClickInterval() * 2 );
276 event->setAccepted( accept );
280 QTabBar::dragMoveEvent( event );
287 d->mActivateDragSwitchTabTimer->stop();
288 d->mDragSwitchTab = 0;
293 QTabBar::dropEvent( event );
298 QTabBar::paintEvent( event );
303 QTabBar::leaveEvent( event );
308 QSize size = QTabBar::tabSizeHint( index );
313 #ifndef QT_NO_WHEELEVENT
316 if ( !( event->orientation() == Qt::Horizontal ) ) {
321 int lastIndex = count() - 1;
323 int targetIndex = -1;
324 bool forward =
event->delta() < 0;
325 if ( forward && lastIndex == currentIndex() ) {
328 else if ( !forward && 0 == currentIndex() ) {
329 targetIndex = lastIndex;
332 setCurrentIndex( targetIndex );
334 if ( targetIndex != currentIndex() || !isTabEnabled( targetIndex ) ) {
335 QTabBar::wheelEvent( event );
344 #ifndef KDE_NO_DEPRECATED
347 return d->mTabReorderingEnabled;
351 #ifndef KDE_NO_DEPRECATED
354 d->mTabReorderingEnabled = on;
358 #ifndef KDE_NO_DEPRECATED
361 return selectionBehaviorOnRemove() == QTabBar::SelectPreviousTab;
365 #ifndef KDE_NO_DEPRECATED
368 setSelectionBehaviorOnRemove(on ? QTabBar::SelectPreviousTab : QTabBar::SelectRightTab);
373 #ifndef KDE_NO_DEPRECATED
377 setTabsClosable(button);
381 #ifndef KDE_NO_DEPRECATED
385 return tabsClosable();
389 #ifndef KDE_NO_DEPRECATED
397 #ifndef KDE_NO_DEPRECATED
405 #ifndef KDE_NO_DEPRECATED
408 QTabBar::setTabsClosable(enable);
412 #ifndef KDE_NO_DEPRECATED
415 return QTabBar::tabsClosable();
421 d->mActivateDragSwitchTabTimer->stop();
422 d->mDragSwitchTab = 0;
427 const int tabCount = count();
428 for (
int i = 0; i < tabCount; ++i )
429 if ( tabRect( i ).contains( pos ) )
435 QPoint KTabBar::closeButtonPos(
int tabIndex )
const
441 QRect KTabBar::closeButtonRect(
int tabIndex )
const
447 #include "ktabbar.moc"
void setHoverCloseButtonDelayed(bool)
If enabled, the close button cannot get clicked until a minor delay has been passed.
virtual void activateDragSwitchTab()
void testCanDecode(const QDragMoveEvent *, bool &)
virtual QSize tabSizeHint(int index) const
QT_MOC_COMPAT void closeButtonClicked()
bool isCloseButtonEnabled() const
Returns true if the close button is shown on tabs.
virtual void mouseReleaseEvent(QMouseEvent *event)
bool hoverCloseButton() const
virtual void paintEvent(QPaintEvent *event)
void mouseMiddleClick(int index)
A double middle mouse button click was performed over the tab with the.
void contextMenu(int index, const QPoint &globalPos)
A right mouse button click was performed over the tab with the.
int selectTab(const QPoint &position) const
Selects the tab which has a tab header at given.
KTabBar(QWidget *parent=0)
Creates a new tab bar.
void setCloseButtonEnabled(bool)
If enabled, a close button is available for each tab.
void setTabReorderingEnabled(bool enable)
Sets the tab reordering enabled or disabled.
virtual void dragEnterEvent(QDragEnterEvent *event)
QT_MOC_COMPAT void enableCloseButton()
virtual void leaveEvent(QEvent *event)
bool tabCloseActivatePrevious() const
Returns whether the 'activate previous tab on close' feature is enabled.
void moveTab(int, int)
Used internally by KTabBar's/KTabWidget's middle-click tab moving mechanism.
bool isTabReorderingEnabled() const
Returns whether tab reordering is enabled.
virtual void mouseMoveEvent(QMouseEvent *event)
QT_MOC_COMPAT void closeRequest(int)
KAction * forward(const QObject *recvr, const char *slot, QObject *parent)
Move forward (web style menu).
bool hoverCloseButtonDelayed() const
virtual void tabLayoutChange()
virtual void wheelEvent(QWheelEvent *event)
QT_MOC_COMPAT void mouseDoubleClick(int)
virtual ~KTabBar()
Destroys the tab bar.
virtual void dropEvent(QDropEvent *event)
void tabDoubleClicked(int index)
A double left mouse button click was performed over the tab with the.
virtual void mousePressEvent(QMouseEvent *event)
virtual void dragMoveEvent(QDragMoveEvent *event)
void emptyAreaContextMenu(const QPoint &globalPos)
A right mouse button click was performed over the empty area on the tab bar.
virtual void mouseDoubleClickEvent(QMouseEvent *event)
void setHoverCloseButton(bool)
If enabled, a close button is shown above the tab icon.
void setTabCloseActivatePrevious(bool)
Sets the 'activate previous tab on close' feature enabled or disabled.
static int dndEventDelay()
Returns a threshold in pixels for drag & drop operations.
void receivedDropEvent(int, QDropEvent *)
void newTabRequest()
A double left mouse button click was performed over the empty area on the tab bar.