X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fmainapp%2Fmdiwindow.cpp;h=b3d0ac4cb50e1b9ca862a6b084551eb7b58e406e;hb=a18a12fc3bcb18e5c7ca5494d7f97fb8b93f90a2;hp=d20e4e7055659bc165e3aae64771ce3970725291;hpb=5adb444f3e523d3fd028617ced72d1ea6661db21;p=architektonas diff --git a/src/mainapp/mdiwindow.cpp b/src/mainapp/mdiwindow.cpp index d20e4e7..b3d0ac4 100644 --- a/src/mainapp/mdiwindow.cpp +++ b/src/mainapp/mdiwindow.cpp @@ -30,15 +30,16 @@ int MDIWindow::idCounter = 0; * * @param doc Pointer to an existing document of NULL if a new * document shall be created for this window. - * @param parent Parent widget. Usually a workspace. + * @param parent Parent widget. Usually a workspace (QMdiArea). */ MDIWindow::MDIWindow(Document * doc, QWidget * parent, const char * name/*= NULL*/, Qt::WindowFlags wflags/*= Qt::WDestructiveClose*/): - QMdiSubWindow(parent, Qt::SubWindow), owner(false), forceClosing(false) + QMdiSubWindow(parent, Qt::SubWindow), owner(false)//, forceClosing(false) #warning "!!! wflags is ignored !!!" { +// This warning not longer occurs...! //This warning is most likely coming from the QMdiSubWindow() constructor above... -#warning "QWidget::setMinimumSize: (/QMdi::ControlLabel) Negative sizes (-1,-1) are not possible" +//#warning "QWidget::setMinimumSize: (/QMdi::ControlLabel) Negative sizes (-1,-1) are not possible" initDoc(doc); initView(); id = idCounter++; @@ -90,12 +91,10 @@ MDIWindow::~MDIWindow() */ void MDIWindow::addChildWindow(MDIWindow * w) { - DEBUG->print("RS_MDIWindow::addChildWindow()"); - - childWindows.append(w); - w->setParentWindow(this); - - DEBUG->print("children: %d", childWindows.count()); + DEBUG->print("RS_MDIWindow::addChildWindow()"); + childWindows.append(w); + w->setParentWindow(this); + DEBUG->print("children: %d", childWindows.count()); } /** @@ -105,13 +104,10 @@ void MDIWindow::addChildWindow(MDIWindow * w) */ void MDIWindow::removeChildWindow(MDIWindow * w) { - DEBUG->print("RS_MDIWindow::removeChildWindow()"); - -// bool suc = childWindows.remove(w); - bool suc = childWindows.removeOne(w); - DEBUG->print("successfully removed child window: %d", (int)suc); - - DEBUG->print("children: %d", childWindows.count()); + DEBUG->print("RS_MDIWindow::removeChildWindow()"); + bool success = childWindows.removeOne(w); + DEBUG->print("successfully removed child window: %s.", (success ? "yes" : "NO")); + DEBUG->print("# of children: %d", childWindows.count()); } /** @@ -119,11 +115,11 @@ void MDIWindow::removeChildWindow(MDIWindow * w) */ MDIWindow * MDIWindow::getPrintPreview() { - for(uint i=0; igetGraphicView()->isPrintPreview()) + if (childWindows.at(i)->getGraphicView()->isPrintPreview()) return childWindows.at(i); - } + } return NULL; } @@ -134,13 +130,13 @@ MDIWindow * MDIWindow::getPrintPreview() * @param force Disable cancel button (demo versions) * @param ask Ask user before closing. */ -bool MDIWindow::closeMDI(bool force, bool ask) +bool MDIWindow::CloseMDI(void) { - // should never happen: + // This should never happen: if (!document) return true; - bool ret = false; + bool closed = false; bool isBlock = (parentWindow != NULL); // This is a block and we don't need to ask the user for closing @@ -148,6 +144,7 @@ bool MDIWindow::closeMDI(bool force, bool ask) if (isBlock) { DEBUG->print(" closing block"); + // tell parent window we're not here anymore. if (parentWindow) { @@ -156,15 +153,14 @@ bool MDIWindow::closeMDI(bool force, bool ask) } emit(signalClosing()); - ret = true; + closed = true; } - // This is a graphic document. ask user for closing. - else if (!ask || slotFileClose(force)) + // This is a drawing document. Ask user for closing. + else if (slotFileClose()) { DEBUG->print(" closing graphic"); - // close all child windows: - bool done; + // Close all child windows: while (!childWindows.isEmpty()) { MDIWindow * child = childWindows.takeFirst(); @@ -174,15 +170,10 @@ bool MDIWindow::closeMDI(bool force, bool ask) } emit(signalClosing()); - ret = true; - } - // User decided not to close graphic document: - else - { - ret = false; + closed = true; } - return (ret || force); + return closed; } /** @@ -190,22 +181,15 @@ bool MDIWindow::closeMDI(bool force, bool ask) */ void MDIWindow::closeEvent(QCloseEvent * ce) { - DEBUG->print("MDIWindow::closeEvent begin"); + DEBUG->print("MDIWindow::closeEvent begin"); - if (closeMDI(false, !forceClosing)) - ce->accept(); - else - ce->ignore(); + (CloseMDI() ? ce->accept() : ce->ignore()); - DEBUG->print("MDIWindow::closeEvent end"); + DEBUG->print("MDIWindow::closeEvent end"); } /** - * Init the document. - * - * @param type Document type. RS:EntityGraphic or RS2::EntityBlock - * @param container Entity container to be used as document or NULL - * if a new document should be created. + * Initialize the document. */ void MDIWindow::initDoc(Document * doc) { @@ -213,7 +197,7 @@ void MDIWindow::initDoc(Document * doc) if (!doc) { - document = new Drawing(); + document = new Drawing(); // Drawing is derived from Document document->newDoc(); owner = true; } @@ -225,10 +209,11 @@ void MDIWindow::initDoc(Document * doc) } /** - * Init the view. + * Initialize the view. */ void MDIWindow::initView() { + // This is only called once: In the MDIWindow constructor. DEBUG->print("MDIWindow::initView()"); // graphicView = new QC_GraphicView(document, this); @@ -368,71 +353,63 @@ bool MDIWindow::slotFileSaveAs(bool & cancelled) /** * Requests the closing of this MDI window. - * - * @param force Force closing by disabling the cancel button (for demo versions). */ -bool MDIWindow::slotFileClose(bool force) +bool MDIWindow::slotFileClose(void) { DEBUG->print("MDIWindow::slotFileClose()"); + bool succeeded = true; + + if (document == NULL || !document->isModified()) + return succeeded; - bool succ = true; - int exit = 0; + ExitDialog dlg(this); - if (document && document->isModified()) + if (document->getFilename().isEmpty()) + dlg.setText(tr("Do you really want to discard this drawing?")); + else { - ExitDialog dlg(this); - dlg.setForce(force); + QString fn = document->getFilename(); - if (document->getFilename().isEmpty()) - dlg.setText(tr("Do you really want to close the drawing?")); - else - { - QString fn = document->getFilename(); + if (fn.length() > 50) + fn = QString("%1...%2").arg(fn.left(24)).arg(fn.right(24)); - if (fn.length() > 50) - fn = QString("%1...%2").arg(fn.left(24)).arg(fn.right(24)); + dlg.setText(tr("Do you really want to discard changes to the file\n%1?").arg(fn)); + } - dlg.setText(tr("Do you really want to close the file\n%1?").arg(fn)); - } + dlg.setTitle(tr("Close Drawing")); - dlg.setTitle(tr("Closing Drawing")); + bool again = false; - bool again; + do + { bool cancelled; + int exit = dlg.exec(); - do + switch (exit) { + case 0: // Cancel + succeeded = false; again = false; - exit = dlg.exec(); - - switch (exit) - { - case 0: // cancel - succ = false; - break; - case 1: // leave - succ = true; - break; - case 2: // save - succ = slotFileSave(cancelled); - again = !succ || cancelled; - break; - case 3: // save as - succ = slotFileSaveAs(cancelled); - again = !succ || cancelled; - break; - default: - break; - } + break; + case 1: // OK (Leave) + succeeded = true; + again = false; + break; + case 2: // Save + succeeded = slotFileSave(cancelled); + again = !succeeded || cancelled; + break; + case 3: // Save As + succeeded = slotFileSaveAs(cancelled); + again = !succeeded || cancelled; + break; + default: + break; } - while (again); - } - else - { - succ = true; } + while (again); - return succ; + return succeeded; } void MDIWindow::slotFilePrint() @@ -459,32 +436,37 @@ void MDIWindow::slotFilePrint() //statusBar()->message(tr("Ready.")); } -/** @return Pointer to graphic view */ +/** + * @return Pointer to graphic view + */ //QC_GraphicView * MDIWindow::getGraphicView() QG_GraphicView * MDIWindow::getGraphicView() { return graphicView; } -/** @return Pointer to document */ +/** + * @return Pointer to document + */ Document * MDIWindow::getDocument() { return document; } -/** @return Pointer to graphic or NULL */ -Drawing * MDIWindow::getGraphic() +/** + * @return Pointer to Drawing or NULL + */ +Drawing * MDIWindow::GetDrawing() { - return document->getGraphic(); + return document->GetDrawing(); } -/** @return Pointer to current event handler */ +/** + * @return Pointer to current event handler + */ EventHandler * MDIWindow::getEventHandler() { - if (graphicView) - return graphicView->getEventHandler(); - else - return NULL; + return (graphicView ? graphicView->getEventHandler() : NULL); } /** @@ -504,11 +486,6 @@ int MDIWindow::getId() return id; } -void MDIWindow::setForceClosing(bool on) -{ - forceClosing = on; -} - /** * Streams some info about an MDI window to stdout. */ @@ -521,7 +498,7 @@ std::ostream & operator<<(std::ostream & os, MDIWindow & w) else os << " parentWindow: NULL\n"; - for(uint i=0; igetId() << "\n"; return os;