18 QAction* pactNew =
new QAction(
"New File", 0);
19 pactNew->setText(
"&New");
20 pactNew->setShortcut(QKeySequence(
"CTRL+N"));
21 pactNew->setToolTip(
"New Document");
22 pactNew->setStatusTip(
"Create a new file");
23 pactNew->setWhatsThis(
"Create a new file");
24 pactNew->setIcon(QPixmap(
":/filenew.png"));
25 connect(pactNew, SIGNAL(triggered()), SLOT(slotNewDoc()));
27 QAction* pactOpen =
new QAction(
"Open File", 0);
28 pactOpen->setText(
"&Open...");
29 pactOpen->setShortcut(QKeySequence(
"CTRL+O"));
30 pactOpen->setToolTip(
"Open Document");
31 pactOpen->setStatusTip(
"Open an existing file");
32 pactOpen->setWhatsThis(
"Open an existing file");
33 pactOpen->setIcon(QPixmap(
":/fileopen.png"));
34 connect(pactOpen, SIGNAL(triggered()), SLOT(slotLoad()));
36 QAction* pactSave =
new QAction(
"Save File", 0);
37 pactSave->setText(
"&Save");
38 pactSave->setShortcut(QKeySequence(
"CTRL+S"));
39 pactSave->setToolTip(
"Save Document");
40 pactSave->setStatusTip(
"Save the file to disk");
41 pactSave->setWhatsThis(
"Save the file to disk");
42 pactSave->setIcon(QPixmap(
":/filesave.png"));
43 connect(pactSave, SIGNAL(triggered()), SLOT(slotSave()));
45 QToolBar* ptbFile =
new QToolBar(
"File Operations");
46 ptbFile->addAction(pactNew);
47 ptbFile->addAction(pactOpen);
48 ptbFile->addAction(pactSave);
49 addToolBar(Qt::TopToolBarArea, ptbFile);
51 QMenu* pmnuFile =
new QMenu(
"&File");
52 pmnuFile->addAction(pactNew);
53 pmnuFile->addAction(pactOpen);
54 pmnuFile->addAction(pactSave);
55 pmnuFile->addAction(
"Save &As...",
this, SLOT(slotSaveAs()));
56 pmnuFile->addSeparator();
57 pmnuFile->addAction(
"&Quit",
59 SLOT(closeAllWindows()),
60 QKeySequence(
"CTRL+Q")
62 menuBar()->addMenu(pmnuFile);
64 m_pmnuWindows =
new QMenu(
"&Windows");
65 menuBar()->addMenu(m_pmnuWindows);
66 connect(m_pmnuWindows, SIGNAL(aboutToShow()), SLOT(slotWindows()));
67 menuBar()->addSeparator();
69 QMenu* pmnuHelp =
new QMenu(
"&Help");
70 pmnuHelp->addAction(
"&About",
this, SLOT(slotAbout()), Qt::Key_F1);
71 menuBar()->addMenu(pmnuHelp);
74 m_pma->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);
75 m_pma->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
76 setCentralWidget(m_pma);
78 m_psigMapper =
new QSignalMapper(
this);
80 SIGNAL(mapped(QWidget*)),
82 SLOT(slotSetActiveSubWindow(QWidget*))
85 statusBar()->showMessage(
"Ready", 3000);
89 void MDIProgram::slotNewDoc()
91 createNewDoc()->show();
98 m_pma->addSubWindow(pdoc);
99 pdoc->setAttribute(Qt::WA_DeleteOnClose);
100 pdoc->setWindowTitle(
"Unnamed Document");
101 pdoc->setWindowIcon(QPixmap(
":/filenew.png"));
103 SIGNAL(changeWindowTitle(
const QString&)),
104 SLOT(slotChangeWindowTitle(
const QString&))
111 void MDIProgram::slotChangeWindowTitle(
const QString& str)
113 qobject_cast<
DocWindow*>(sender())->setWindowTitle(str);
117 void MDIProgram::slotLoad()
125 void MDIProgram::slotSave()
134 void MDIProgram::slotSaveAs()
143 void MDIProgram::slotAbout()
145 QMessageBox::about(
this,
"Application",
"MDI Example");
149 void MDIProgram::slotWindows()
151 m_pmnuWindows->clear();
153 QAction* pact = m_pmnuWindows->addAction(
"&Cascade",
155 SLOT(cascadeSubWindows())
157 pact->setEnabled(!m_pma->subWindowList().isEmpty());
159 pact = m_pmnuWindows->addAction(
"&Tile",
161 SLOT(tileSubWindows())
163 pact->setEnabled(!m_pma->subWindowList().isEmpty());
165 m_pmnuWindows->addSeparator();
167 QList<QMdiSubWindow*> listDoc = m_pma->subWindowList();
168 for (
int i = 0; i < listDoc.size(); ++i) {
169 pact = m_pmnuWindows->addAction(listDoc.at(i)->windowTitle());
170 pact->setCheckable(
true);
171 pact->setChecked(m_pma->activeSubWindow() == listDoc.at(i));
172 connect(pact, SIGNAL(triggered()), m_psigMapper, SLOT(map()));
173 m_psigMapper->setMapping(pact, listDoc.at(i));
178 void MDIProgram::slotSetActiveSubWindow(QWidget* pwgt)
181 m_pma->setActiveSubWindow(qobject_cast<QMdiSubWindow*>(pwgt));
MDIProgram(QWidget *pwgt=0)