示例#1
0
ViewContainer* ViewSplitter::activeContainer() const
{
    if (QWidget* focusW = focusWidget()) {
        ViewContainer* focusContainer = 0;

        while (focusW != 0) {
            QListIterator<ViewContainer*> containerIter(_containers);
            while (containerIter.hasNext()) {
                ViewContainer* nextContainer = containerIter.next();

                if (nextContainer->containerWidget() == focusW) {
                    focusContainer = nextContainer;
                    break;
                }
            }
            focusW = focusW->parentWidget();
        }

        if (focusContainer)
            return focusContainer;
    }

    QList<ViewSplitter*> splitters = findChildren<ViewSplitter*>();

    if (splitters.count() > 0) {
        return splitters.last()->activeContainer();
    } else {
        if (_containers.count() > 0)
            return _containers.last();
        else
            return 0;
    }
}
示例#2
0
void ViewSplitter::addContainer( ViewContainer* container , 
                                 Qt::Orientation containerOrientation )
{
   ViewSplitter* splitter = activeSplitter();   

    if ( splitter->count() < 2 || 
         containerOrientation == splitter->orientation() ||
         !_recursiveSplitting )
    {
        splitter->registerContainer(container); 
        splitter->addWidget(container->containerWidget());

        if ( splitter->orientation() != containerOrientation )
            splitter->setOrientation( containerOrientation );

        splitter->updateSizes();
    }
    else
    {
        ViewSplitter* newSplitter = new ViewSplitter(this);
        connect( newSplitter , SIGNAL(empty(ViewSplitter*)) , splitter , SLOT(childEmpty(ViewSplitter*)) );

        ViewContainer* oldContainer = splitter->activeContainer();
        int oldContainerIndex = splitter->indexOf(oldContainer->containerWidget());

        splitter->unregisterContainer(oldContainer);   

        newSplitter->registerContainer(oldContainer);
        newSplitter->registerContainer(container);

        newSplitter->addWidget(oldContainer->containerWidget());
        newSplitter->addWidget(container->containerWidget());
        newSplitter->setOrientation(containerOrientation); 
        newSplitter->updateSizes();
        newSplitter->show();

        splitter->insertWidget(oldContainerIndex,newSplitter);
    }

}
示例#3
0
void ViewManager::splitView(Qt::Orientation orientation)
{
    // iterate over each session which has a view in the current active
    // container and create a new view for that session in a new container
    QListIterator<QWidget*> existingViewIter(_viewSplitter->activeContainer()->views());

    ViewContainer* container = 0;

    while (existingViewIter.hasNext()) {
        Session* session = _sessionMap[(TerminalDisplay*)existingViewIter.next()];
        TerminalDisplay* display = createTerminalDisplay(session);
        const Profile::Ptr profile = SessionManager::instance()->sessionProfile(session);
        applyProfileToView(display, profile);
        ViewProperties* properties = createController(session, display);

        _sessionMap[display] = session;

        // create a container using settings from the first
        // session in the previous container
        if (!container) {
            container = createContainer(profile);
            applyProfileToContainer(container, profile);
        }

        container->addView(display, properties);
        session->addView(display);
    }

    _viewSplitter->addContainer(container, orientation);
    emit splitViewToggle(_viewSplitter->containers().count() > 0);

    // focus the new container
    container->containerWidget()->setFocus();

    // ensure that the active view is focused after the split / unsplit
    ViewContainer* activeContainer = _viewSplitter->activeContainer();
    QWidget* activeView = activeContainer ? activeContainer->activeView() : 0;

    if (activeView)
        activeView->setFocus(Qt::OtherFocusReason);
}