Ejemplo n.º 1
0
void TabWidget::slotDetachTab()
{
    Frame* frame = d->frames.value( d->selectedWidget() );

    if (frame && frame->url().isValid() && frame->isRemovable())
    {
        OpenUrlRequest request;
        request.setUrl(frame->url());
        request.setOptions(OpenUrlRequest::ExternalBrowser);
        emit signalOpenUrlRequest(request);
        slotCloseTab();
    }
}
Ejemplo n.º 2
0
TabWidget::TabWidget(configTreeView *parent)
        : QTabWidget(parent), m_mainImpl( parent )
{
    setMouseTracking( true );
    cross = new QToolButton(this);
    cross->hide();
    cross->setIcon( QIcon(":/images/cross.png") );
    connect(cross, SIGNAL(clicked()), this, SLOT(slotCloseTab()) );
    cross->setGeometry(0,0,15,15);
    tabBar()->installEventFilter(this);
    m_clickedItem = -1;
    m_closeButtonInTabs = true;
}
Ejemplo n.º 3
0
bool TabWidget::eventFilter(QObject *obj, QEvent *event)
{
    if (obj==tabBar())
    {
        // this code handles the tab movement
        if (event->type() == QEvent::Leave)
        {
            QPoint point = cross->mapToGlobal( QPoint(0, 0) );
            QRect rect(point.x(), point.y(), cross->width(), cross->height() );
            if ( !rect.contains( QCursor::pos() ) )
                cross->hide();
        }
        else if (event->type() == QEvent::HoverMove && m_closeButtonInTabs )
        {
            QHoverEvent *mouseEvent = static_cast<QHoverEvent *>(event);
            mousePos = mouseEvent->pos();
            for (int i=0; i<tabBar()->count(); i++)
            {
                if ( tabBar()->tabRect(i).contains( mouseEvent->pos() ) )
                {
                    m_clickedItem= i;
                    break;
                }
            }
            cross->setGeometry(tabBar()->tabRect(m_clickedItem).x()+tabBar()->tabRect(m_clickedItem).width()-cross->width()-5,
                               //tabBar()->height()-(tabBar()->tabRect(m_clickedItem).height()/2),
                               5,
                               cross->width(),
                               cross->height());
            cross->show();
        }
        else if (event->type() == QEvent::MouseButtonRelease )
        {
            qApp->restoreOverrideCursor();
        }
        else if (event->type() == QEvent::MouseButtonPress )
        {
            QMouseEvent *mouseEvent = static_cast<QMouseEvent *>(event);
            for (int i=0; i<tabBar()->count(); i++)
            {
                if ( tabBar()->tabRect(i).contains( mouseEvent->pos() ) )
                {
                    m_clickedItem = i;
                    break;
                }
            }
            if ( mouseEvent->button() == Qt::LeftButton )
                qApp->setOverrideCursor( Qt::OpenHandCursor );
            if ( mouseEvent->button() == Qt::RightButton )
            {
                QMenu *menu = new QMenu(this);
                connect(menu->addAction(QIcon(":/images/cross.png"), tr("Close Tab")), SIGNAL(triggered()), this, SLOT(slotCloseTab()) );
                connect(menu->addAction(QIcon(":/images/fileclose.png"), tr("Close Other Tabs")), SIGNAL(triggered()), this, SLOT(slotCloseOtherTab()) );
                connect(menu->addAction(QIcon(":/images/fileclose.png"), tr("Close All Tabs")), SIGNAL(triggered()), this, SLOT(slotCloseAllTab()) );
                menu->exec(mouseEvent->globalPos());
                delete menu;
            }
        }
        else if (event->type() == QEvent::MouseMove )
        {
            QMouseEvent *mouseEvent = static_cast<QMouseEvent *>(event);
            for (int i=0; i<tabBar()->count(); i++)
            {
                if ( tabBar()->tabRect(i).contains( mouseEvent->pos() ) )
                {
                    if ( swapTabs(i, m_clickedItem) )
                    {
                        setCurrentWidget(widget(i));
                        update();
                        int x;
                        if ( !tabBar()->tabRect(i).contains( mouseEvent->pos() ) )
                        {
                            if ( tabBar()->tabRect(m_clickedItem).x() < tabBar()->tabRect(i).x() )
                                x = tabBar()->tabRect(i).x();
                            else
                                x = tabBar()->tabRect(i).x()+(tabBar()->tabRect(i).width()-(qAbs(tabBar()->tabRect(i).width()-tabBar()->tabRect(m_clickedItem).width())));
                            QPoint point =  QPoint(
                                                x,
                                                mouseEvent->pos().y()
                                            );
                            point =  widget(i)->mapToGlobal( point );
                            m_clickedItem = i;
                            QCursor::setPos ( point.x(), QCursor::pos().y() );
                        }
                        m_clickedItem = i;
                        break;
                    }
                }
            }
        }
    }
    return QTabWidget::eventFilter( obj, event);
}