|
//create new child window and add up to QWorkspace then return a pointer MdiChild *MainWindow::createMdiChild() { MdiChild *child = new MdiChild; workspace->addWindow(child);
connect(child, SIGNAL(copyAvailable(bool)), cutAct, SLOT(setEnabled(bool))); connect(child, SIGNAL(copyAvailable(bool)), copyAct, SLOT(setEnabled(bool)));
return child; }
//Get the current active window MdiChild *MainWindow::activeMdiChild() { return qobject_cast<MdiChild *>(workspace->activeWindow()); } //Find the specify window MdiChild *MainWindow::findMdiChild(const QString &fileName) { QString canonicalFilePath = QFileInfo(fileName).canonicalFilePath();
foreach (QWidget *window, workspace->windowList()) { MdiChild *mdiChild = qobject_cast<MdiChild *>(window); if (mdiChild->currentFile() == canonicalFilePath) return mdiChild; } return 0; }
//update window menu QList<QWidget *> windows = workspace->windowList(); separatorAct->setVisible(!windows.isEmpty());
for (int i = 0; i < windows.size(); ++i) { MdiChild *child = qobject_cast<MdiChild *>(windows.at(i));
QString text; if (i < 9) { text = tr("&%1. %2").arg(i + 1) .arg(child->userFriendlyCurrentFile()); } else { text = tr("%1. %2").arg(i + 1) .arg(child->userFriendlyCurrentFile()); } QAction *action = windowMenu->addAction(text); action->setCheckable(true); action ->setChecked(child == activeMdiChild()); connect(action, SIGNAL(triggered()), windowMapper, SLOT(map())); windowMapper->setMapping(action, child); }
|