Пример #1
0
void MyMdiArea::addSubWindow(MyMdiSubWindow* window)
{
	Q_ASSERT(subWindows_.contains(window) == false);

	currentWidget_->hide();
	layout_->removeWidget(currentWidget_);

	layout_->addWidget(window);
	window->show();
	currentWidget_ = window;

	bool blocked = tabBar_->blockSignals(true);
	tabBar_->addTab(tabText(window));
	tabBar_->setCurrentIndex(tabBar_->count() - 1);
	tabBar_->blockSignals(blocked);

	QWidget* left = tabBar_->tabButton(tabBar_->count() - 1, QTabBar::LeftSide);
	QWidget* right = tabBar_->tabButton(tabBar_->count() - 1, QTabBar::RightSide);

	subWindows_.append(window);

	connect(window, SIGNAL(windowTitleChanged(const QString&)), this, SLOT(onWindowModified()));
	connect(window, SIGNAL(modifiedChanged(bool)), this, SLOT(onWindowModified()));
	connect(window, SIGNAL(destroyed(QObject*)), this, SLOT(onDestroyed(QObject*)));

	emit subWindowActivated(activeSubWindow());
}
Пример #2
0
void MyMdiArea::onCurrentChanged(int index)
{
	currentWidget_->hide();
	layout_->removeWidget(currentWidget_);

	currentWidget_ = subWindows_[index];
	layout_->addWidget(currentWidget_);
	currentWidget_->show();

	emit subWindowActivated(activeSubWindow());
}
Пример #3
0
void CWindowStack::removeSubWindow(QWidget *sw)
{
    int index=subWindowList.indexOf(sw);
    if (index>-1)
    {
        sw->disconnect();
        subWindowList.removeAt(index);
        delete sw;
        activeIndex=-1;
    }
    if (subWindowList.count()) setActiveSubWindow(subWindowList.first());
    emit subWindowActivated(0);
}
Пример #4
0
QWidget* CWindowStack::closeSubWindow(QWidget *sw)
{
    if (subWindowList.count()<2) return sw;
    int index=subWindowList.indexOf(sw);
    if (index>-1)
    {
        if (!sw->close()) return sw;
        sw->disconnect();
        subWindowList.removeAt(index);
        delete sw;
        activeIndex=-1;
        if (subWindowList.count()) return setActiveSubWindow(subWindowList.first());
        emit subWindowActivated(0);
        return 0;
    }
    return sw;
}
Пример #5
0
void MyMdiArea::removeFromTab(MyMdiSubWindow* window)
{
	int index = subWindows_.indexOf(window);

	if (index >= 0)
	{
		subWindows_.removeAt(index);

		bool blocked = tabBar_->blockSignals(true);
		tabBar_->removeTab(index);
		tabBar_->blockSignals(blocked);

		layout_->removeWidget(window);

		currentWidget_ = (tabBar_->count() == 0) ? emptyWidget_ : subWindows_[tabBar_->currentIndex()];
		layout_->addWidget(currentWidget_);
		currentWidget_->show();

		emit subWindowActivated(activeSubWindow());
	}
}
Пример #6
0
QWidget* CWindowStack::setActiveSubWindow(QWidget *sw)
{
    int index=subWindowList.indexOf(sw);
    if (index>-1)
    {
        activeIndex=index;
        for (int i=0;i<subWindowList.count();i++)
        {
            subWindowList[i]->disconnect();
            if (i != index)
            {
                subWindowList[i]->setVisible(false);
                subWindowList[i]->blockSignals(true);
                subWindowList[i]->setEnabled(false);
            }
        }
        sw->setVisible(true);
        sw->blockSignals(false);
        sw->setEnabled(true);
        emit subWindowActivated(sw);
    }
    return sw;
}