LCOV - code coverage report
Current view: top level - gui/source - extendedtabwidget.cpp (source / functions) Hit Total Coverage
Test: mcrl2_coverage.info.cleaned Lines: 0 48 0.0 %
Date: 2020-10-20 00:45:57 Functions: 0 3 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : // Author(s): Rimco Boudewijns
       2             : // Copyright: see the accompanying file COPYING or copy at
       3             : // https://github.com/mCRL2org/mCRL2/blob/master/COPYING
       4             : //
       5             : // Distributed under the Boost Software License, Version 1.0.
       6             : // (See accompanying file LICENSE_1_0.txt or copy at
       7             : // http://www.boost.org/LICENSE_1_0.txt)
       8             : //
       9             : 
      10             : #include "mcrl2/gui/extendedtabwidget.h"
      11             : #include <QTabBar>
      12             : #include <QEvent>
      13             : #include <QMouseEvent>
      14             : #include <QMenu>
      15             : #include <QAction>
      16             : 
      17             : using namespace mcrl2::gui::qt;
      18             : 
      19           0 : ExtendedTabWidget::ExtendedTabWidget(QWidget *parent) :
      20           0 :   QTabWidget(parent)
      21             : {
      22           0 :   setFocusPolicy(Qt::StrongFocus);
      23           0 :   tabBar()->installEventFilter(this);
      24           0 : }
      25             : 
      26           0 : bool ExtendedTabWidget::eventFilter(QObject *target, QEvent *event) {
      27           0 :   if(target == tabBar()) {
      28           0 :     if(event->type() == QEvent::MouseButtonPress) {
      29           0 :       QMouseEvent *mouseEvent = static_cast<QMouseEvent *>(event);
      30           0 :       if (mouseEvent->button() == Qt::RightButton)
      31             :       {
      32           0 :         QPoint position = mouseEvent->pos();
      33           0 :         int clickedItem = -1;
      34           0 :         for (int i=0; i < tabBar()->count(); i++)
      35             :         {
      36           0 :           if ( tabBar()->tabRect(i).contains( position ) )
      37             :           {
      38           0 :             clickedItem = i;
      39           0 :             break;
      40             :           }
      41             :         }
      42           0 :         if (clickedItem != -1)
      43             :         {
      44           0 :           QMenu menu(this);
      45           0 :           menu.addAction("Close tab");
      46           0 :           menu.addSeparator();
      47           0 :           menu.addAction("Close all tabs");
      48           0 :           menu.addAction("Close other tabs");
      49           0 :           menu.addAction("Close tabs on the left");
      50           0 :           menu.addAction("Close tabs on the right");
      51           0 :           QAction* act = menu.exec(mapToGlobal(position));
      52           0 :           if (act != 0)
      53             :           {
      54           0 :             if (act->text() == "Close tab")
      55             :             {
      56           0 :               emit(tabCloseRequested(clickedItem));
      57             :             }
      58           0 :             if (act->text() == "Close all tabs")
      59             :             {
      60           0 :               for (int i = count()-1; i >= 0; i--)
      61             :               {
      62           0 :                   emit(tabCloseRequested(i));
      63             :               }
      64             :             }
      65           0 :             if (act->text() == "Close other tabs")
      66             :             {
      67           0 :               for (int i = count()-1; i >= 0; i--)
      68             :               {
      69           0 :                 if (i != clickedItem)
      70           0 :                   emit(tabCloseRequested(i));
      71             :               }
      72             :             }
      73           0 :             if (act->text() == "Close tabs on the left")
      74             :             {
      75           0 :               for (int i = clickedItem-1; i >= 0; i--)
      76             :               {
      77           0 :                 emit(tabCloseRequested(i));
      78             :               }
      79             :             }
      80           0 :             if (act->text() == "Close tabs on the right")
      81             :             {
      82           0 :               for (int i = count()-1; i > clickedItem; i--)
      83             :               {
      84           0 :                 emit(tabCloseRequested(i));
      85             :               }
      86             :             }
      87             :           }
      88           0 :           return true;
      89             :         }
      90             :       }
      91             :     }
      92             :   }
      93           0 :   return false;
      94             : }
      95             : 
      96           0 : void ExtendedTabWidget::keyPressEvent(QKeyEvent *event)
      97             : {
      98           0 :   if (event->matches(QKeySequence::Close) && currentIndex() != -1)
      99             :   {
     100           0 :     emit(tabCloseRequested(currentIndex()));
     101             :   }
     102             :   else
     103             :   {
     104           0 :     QTabWidget::keyPressEvent(event);
     105             :   }
     106           0 : }

Generated by: LCOV version 1.13