#include "mainwindow.h"#include "ui_mainwindow.h"MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow){ ui->setupUi(this); mdiArea = new QMdiArea; setCentralWidget(mdiArea); connect(mdiArea,SIGNAL(subWindowActivated(QMdiSubWindow*)),this, SLOT(updateMenus())); windowMapper = new QSignalMapper(this); connect(windowMapper,SIGNAL(mapped(QWidget*)),this,SLOT(setActiveSubWindow(QWidget*))); mdiArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded); mdiArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded); createActions(); createMenus(); createToolBars(); createStatusBar(); updateMenus(); setWindowTitle(tr("MDI")); setGeometry(200,200,400,200); /*p_lblX = new QLabel(this); p_lblY = new QLabel(this); */}MainWindow::~MainWindow(){ delete ui;}void MainWindow::mouseMoveEvent(QMouseEvent *pe){ //p_lblX->setText("X="+QString().setNum(pe->x())); //p_lblY->setText("Y="+QString().setNum(pe->y()));}void MainWindow::closeEvent(QCloseEvent *pe){ //??????????????????????????? mdiArea->closeAllSubWindows(); //if(activeMdiChild()) //{ // pe->ignore(); //} //else //{ // pe->accept(); //}}void MainWindow::newFile(){ MdiChildJournal* child = createMdiChild(); child->newFile(); child->show();}void MainWindow::about(){}void MainWindow::updateMenus(){}void MainWindow::updateWindowMenu(){ windowMenu->clear(); windowMenu->addAction(closeAct); windowMenu->addAction(closeAllAct); windowMenu->addSeparator(); windowMenu->addAction(nextAct); /*QList<QMdiSubWindow*>winList = mdiArea->subWindowList(); separatorAct->setVisible(!winList.isEmpty()); for(int i = 0; i<winList.size(); ++i) { MdiChildJournal* child = qobject_cast<MdiChildJournal*>(winList.at(i)->widget()); 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,winList.at(i)); } */}MdiChildJournal* MainWindow::createMdiChild(){ MdiChildJournal*child = new MdiChildJournal(); mdiArea->addSubWindow(child); return child;}void MainWindow::createActions(){ newAct = new QAction(tr("&New"),this); newAct->setShortcut(tr("Ctrl+N")); newAct->setStatusTip(tr("Create new journal")); connect(newAct,SIGNAL(triggered()),this,SLOT(newFile())); exitAct = new QAction(tr("&Exit"),this); exitAct->setShortcut(tr("Alt+X")); exitAct->setStatusTip(tr("Exit")); closeAct = new QAction(tr("&Close"),this); closeAct->setShortcut(tr("Alt+C")); closeAct->setStatusTip(tr("Close Window")); closeAllAct = new QAction(tr("&Close All"),this); closeAllAct->setShortcut(tr("Alt+A")); closeAllAct->setStatusTip(tr("Close All Window")); nextAct = new QAction(tr("&Next"),this); nextAct->setShortcut(tr("Shift+N")); nextAct->setStatusTip(tr("Next Window"));}void MainWindow::createMenus(){ fileMenu = menuBar()->addMenu(tr("&File")); fileMenu->addAction(newAct); fileMenu->addSeparator(); fileMenu->addAction(exitAct); windowMenu = menuBar()->addMenu(tr("&Window")); updateMenus(); connect(windowMenu,SIGNAL(aboutToShow()),this,SLOT(updateWindowMenu())); menuBar()->addSeparator();}void MainWindow::createToolBars(){}void MainWindow::createStatusBar(){}MdiChildJournal*MainWindow::activeMdiChild(){}QMdiSubWindow*MainWindow::findMdiChild(const QString &fileName){}void MainWindow::setActiveSubWindow(QWidget *window){}