]> Shamusworld >> Repos - architektonas/blob - src/mainapp/qc_dialogfactory.cpp
Fixed problem with MDI activation.
[architektonas] / src / mainapp / qc_dialogfactory.cpp
1 // qc_dialogfactory.cpp
2 //
3 // Part of the Architektonas Project
4 // Originally part of QCad Community Edition by Andrew Mustun
5 // Extensively rewritten and refactored by James L. Hammons
6 // Portions copyright (C) 2001-2003 RibbonSoft
7 // Copyright (C) 2010 Underground Software
8 // See the README and GPLv2 files for licensing and warranty information
9 //
10 // JLH = James L. Hammons <jlhamm@acm.org>
11 //
12 // Who  When        What
13 // ---  ----------  -----------------------------------------------------------
14 // JLH  05/17/2010  Added this text. :-)
15 //
16
17 #include "qc_dialogfactory.h"
18
19 #include "applicationwindow.h"
20 #include "blocklist.h"
21 #include "qg_graphicview.h"
22
23 QC_DialogFactory::QC_DialogFactory(QWidget * parent, QToolBar * ow): QG_DialogFactory(parent, ow)
24 {
25 }
26
27 /*virtual*/ QC_DialogFactory::~QC_DialogFactory()
28 {
29 }
30
31 /**
32  * Provides a new window for editing the active block.
33  */
34 void QC_DialogFactory::requestEditBlockWindow(BlockList * blockList)
35 {
36         DEBUG->print("QC_DialogFactory::requestEditBlockWindow()");
37
38         ApplicationWindow * appWindow = ApplicationWindow::getAppWindow();
39         MDIWindow * parent = appWindow->getMDIWindow();
40
41         if (parent && blockList)
42         {
43                 Block * block = blockList->getActive();
44
45                 if (block)
46                 {
47                         MDIWindow * w = appWindow->slotFileNew(block);
48                         // the parent needs a pointer to the block window and vice versa
49                         parent->addChildWindow(w);
50                         w->getGraphicView()->zoomAuto(false);
51                 }
52         }
53 }
54
55 /**
56  * Closes all windows that are editing the given block.
57  */
58 void QC_DialogFactory::closeEditBlockWindow(Block * block)
59 {
60         DEBUG->print("QC_DialogFactory::closeEditBlockWindow");
61
62         ApplicationWindow * appWindow = ApplicationWindow::getAppWindow();
63         QMdiArea * workspace = appWindow->getWorkspace();
64
65         if (workspace)
66         {
67                 DEBUG->print("QC_DialogFactory::closeEditBlockWindow: workspace found");
68
69                 QList<QMdiSubWindow *> windows = workspace->subWindowList();
70
71                 for(int i=0; i<windows.count(); i++)
72                 {
73                         DEBUG->print("QC_DialogFactory::closeEditBlockWindow: window: %d", i);
74                         MDIWindow * m = (MDIWindow *)windows.at(i);
75
76                         if (m)
77                         {
78                                 DEBUG->print("QC_DialogFactory::closeEditBlockWindow: got mdi");
79
80                                 if (m->getDocument() == block)
81                                 {
82                                         DEBUG->print("QC_DialogFactory::closeEditBlockWindow: closing mdi");
83                                         //m->closeMDI(true, false);
84 //                                      m->close(true);
85                                         m->close();
86                                 }
87                         }
88                 }
89         }
90
91         appWindow->slotWindowActivated(NULL);
92
93         DEBUG->print("QC_DialogFactory::closeEditBlockWindow: OK");
94 }