From d5e986620ca1379988aed5c701253516c263904b Mon Sep 17 00:00:00 2001 From: Mavridis Philippe Date: Thu, 14 Jan 2021 22:21:56 +0200 Subject: [PATCH] Implemented tabs context menu Signed-off-by: Mavridis Philippe --- src/tabwidget.cpp | 27 +++++++++++++++++++++++---- src/tabwidget.h | 5 ++++- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/src/tabwidget.cpp b/src/tabwidget.cpp index e1c079f..d024b07 100644 --- a/src/tabwidget.cpp +++ b/src/tabwidget.cpp @@ -147,16 +147,35 @@ void TabWidget::setTitle( const TQString &title , TQWidget* sender) void TabWidget::contextMenu(int i, const TQPoint &p) { + currentItemId = i; currentItem = page(i); TDEPopupMenu popup; - int closeTab = popup.insertItem( SmallIcon("tab_remove"), i18n("Close Tab"), this, SLOT( slotCloseTab() ) ); - if(indexOf(currentItem) == 0) { // you can't detach or close articles tab.. - popup.setItemEnabled(closeTab, false); - } + int moveTabLeft = popup.insertItem( SmallIcon("back"), i18n("Move Tab &Left"), this, SLOT(slotMoveTabLeft()) ); + int moveTabRight = popup.insertItem( SmallIcon("forward"), i18n("Move Tab &Right"), this, SLOT(slotMoveTabRight()) ); + popup.insertSeparator(); + int closeTab = popup.insertItem( SmallIcon("tab_remove"), i18n("Close Tab"), this, SLOT(slotCloseTab()) ); + + if(currentItemId == 0) + popup.setItemEnabled(moveTabLeft, false); + + if(currentItemId == count() - 1) + popup.setItemEnabled(moveTabRight, false); + popup.exec(p); } + +void TabWidget::slotMoveTabLeft() { + if( currentItemId > 0 ) + moveTab(currentItemId, currentItemId-1); +} + +void TabWidget::slotMoveTabRight() { + if( currentItemId < count() - 1 ) + moveTab(currentItemId, currentItemId+1); +} + void TabWidget::slotCloseTab() { if(!currentItem) return; diff --git a/src/tabwidget.h b/src/tabwidget.h index c16a2f8..1e2490b 100644 --- a/src/tabwidget.h +++ b/src/tabwidget.h @@ -27,7 +27,7 @@ class TabWidget:public KTabWidget void addFrame(Frame *f); Frame *currentFrame(); void removeFrame(Frame *f); - + unsigned int tabBarWidthForMaxChars( uint maxLength ); void setTitle( const TQString &title , TQWidget* sender); @@ -42,6 +42,8 @@ class TabWidget:public KTabWidget private slots: + void slotMoveTabLeft(); + void slotMoveTabRight(); void slotCloseTab(); void slotCloseRequest(TQWidget* widget); void contextMenu (int item, const TQPoint &p); @@ -51,6 +53,7 @@ class TabWidget:public KTabWidget TQPtrDict m_frames; unsigned int m_CurrentMaxLength; + int currentItemId; TQWidget* currentItem; };