// Part of the Architektonas Project
// Originally part of QCad Community Edition by Andrew Mustun
// Extensively rewritten and refactored by James L. Hammons
-// (C) 2010 Underground Software
+// Portions copyright (C) 2001-2003 RibbonSoft
+// Copyright (C) 2010 Underground Software
+// See the README and GPLv2 files for licensing and warranty information
//
// JLH = James L. Hammons <jlhamm@acm.org>
//
#include "mdiwindow.h"
#include "drawing.h"
-#include "rs_eventhandler.h"
+#include "eventhandler.h"
#include "exitdialog.h"
-#include "qg_filedialog.h"
+#include "filedialog.h"
+#include "qg_graphicview.h"
// Class variable
int MDIWindow::idCounter = 0;
* document shall be created for this window.
* @param parent Parent widget. Usually a workspace.
*/
-MDIWindow::MDIWindow(RS_Document * doc, QWidget * parent, const char * name/*= NULL*/,
+MDIWindow::MDIWindow(Document * doc, QWidget * parent, const char * name/*= NULL*/,
Qt::WindowFlags wflags/*= Qt::WDestructiveClose*/):
- QMdiSubWindow(parent, Qt::SubWindow)
+ QMdiSubWindow(parent, Qt::SubWindow), owner(false), forceClosing(false)
#warning "!!! wflags is ignored !!!"
{
- owner = false;
- forceClosing = false;
//This warning is most likely coming from the QMdiSubWindow() constructor above...
#warning "QWidget::setMinimumSize: (/QMdi::ControlLabel) Negative sizes (-1,-1) are not possible"
initDoc(doc);
initView();
id = idCounter++;
-//No worries: Only need to be more vigilant if this were TRUE
-// childWindows.setAutoDelete(false);
parentWindow = NULL;
- if (document != NULL)
+//not using this anymore
+#if 0
+ if (document)
{
- if (document->getLayerList() != NULL)
+ if (document->getLayerList())
// Link the graphic view to the layer widget
document->getLayerList()->addListener(graphicView);
- if (document->getBlockList() != NULL)
+ if (document->getBlockList())
// Link the graphic view to the block widget
document->getBlockList()->addListener(graphicView);
}
+#endif
//hm.
setFocus(/*Qt::StrongFocus*/);
*/
MDIWindow::~MDIWindow()
{
- if (document->getLayerList() != NULL)
+#if 0
+ if (document->getLayerList())
document->getLayerList()->removeListener(graphicView);
- if (document->getBlockList() != NULL)
+ if (document->getBlockList())
document->getBlockList()->removeListener(graphicView);
+#endif
- if (owner == true && document != NULL)
+ if (owner && document)
delete document;
document = NULL;
*/
void MDIWindow::addChildWindow(MDIWindow * w)
{
- RS_DEBUG->print("RS_MDIWindow::addChildWindow()");
+ DEBUG->print("RS_MDIWindow::addChildWindow()");
childWindows.append(w);
w->setParentWindow(this);
- RS_DEBUG->print("children: %d", childWindows.count());
+ DEBUG->print("children: %d", childWindows.count());
}
/**
*/
void MDIWindow::removeChildWindow(MDIWindow * w)
{
- RS_DEBUG->print("RS_MDIWindow::removeChildWindow()");
+ DEBUG->print("RS_MDIWindow::removeChildWindow()");
// bool suc = childWindows.remove(w);
bool suc = childWindows.removeOne(w);
- RS_DEBUG->print("successfully removed child window: %d", (int)suc);
+ DEBUG->print("successfully removed child window: %d", (int)suc);
- RS_DEBUG->print("children: %d", childWindows.count());
+ DEBUG->print("children: %d", childWindows.count());
}
/**
bool MDIWindow::closeMDI(bool force, bool ask)
{
// should never happen:
- if (document == NULL)
+ if (!document)
return true;
bool ret = false;
bool isBlock = (parentWindow != NULL);
// This is a block and we don't need to ask the user for closing
- // since it's still available in the parent drawing after closing.
+ // since it's still available in the parent drawing after closing.
if (isBlock)
{
- RS_DEBUG->print(" closing block");
+ DEBUG->print(" closing block");
// tell parent window we're not here anymore.
- if (parentWindow != NULL)
+ if (parentWindow)
{
- RS_DEBUG->print(" notifying parent about closing this window");
+ DEBUG->print(" notifying parent about closing this window");
parentWindow->removeChildWindow(this);
}
// This is a graphic document. ask user for closing.
else if (!ask || slotFileClose(force))
{
- RS_DEBUG->print(" closing graphic");
+ DEBUG->print(" closing graphic");
// close all child windows:
bool done;
-#if 0 // UGH! WHY??!??!
- do
- {
- done = true;
-
- if (childWindows.at(0) != NULL)
- {
- childWindows.at(0)->close();
- done = false;
- }
- }
- while (!done);
-#else
while (!childWindows.isEmpty())
{
MDIWindow * child = childWindows.takeFirst();
if (child)
child->close();
}
-#endif
emit(signalClosing());
ret = true;
*/
void MDIWindow::closeEvent(QCloseEvent * ce)
{
- RS_DEBUG->print("MDIWindow::closeEvent begin");
+ DEBUG->print("MDIWindow::closeEvent begin");
if (closeMDI(false, !forceClosing))
ce->accept();
else
ce->ignore();
- RS_DEBUG->print("MDIWindow::closeEvent end");
+ DEBUG->print("MDIWindow::closeEvent end");
}
/**
* @param container Entity container to be used as document or NULL
* if a new document should be created.
*/
-void MDIWindow::initDoc(RS_Document * doc)
+void MDIWindow::initDoc(Document * doc)
{
- RS_DEBUG->print("MDIWindow::initDoc()");
+ DEBUG->print("MDIWindow::initDoc()");
- if (doc == NULL)
+ if (!doc)
{
document = new Drawing();
document->newDoc();
*/
void MDIWindow::initView()
{
- RS_DEBUG->print("MDIWindow::initView()");
+ DEBUG->print("MDIWindow::initView()");
- graphicView = new QC_GraphicView(document, this);
-// setCentralWidget(graphicView);
+// graphicView = new QC_GraphicView(document, this);
+ graphicView = new QG_GraphicView(document, this);
setWidget(graphicView);
graphicView->setFocus();
}
* Called when the current pen (color, style, width) has changed.
* Sets the active pen for the document in this MDI window.
*/
-void MDIWindow::slotPenChanged(RS_Pen pen)
+void MDIWindow::slotPenChanged(Pen pen)
{
- RS_DEBUG->print("MDIWindow::slotPenChanged() begin");
+ DEBUG->print("MDIWindow::slotPenChanged() begin");
- if (document != NULL)
+ if (document)
document->setActivePen(pen);
- RS_DEBUG->print("MDIWindow::slotPenChanged() end");
+ DEBUG->print("MDIWindow::slotPenChanged() end");
}
/**
*/
void MDIWindow::slotFileNew()
{
- RS_DEBUG->print("MDIWindow::slotFileNew begin");
+ DEBUG->print("MDIWindow::slotFileNew begin");
- if (document != NULL && graphicView != NULL)
+ if (document && graphicView)
{
document->newDoc();
graphicView->redraw();
}
- RS_DEBUG->print("MDIWindow::slotFileNew end");
+ DEBUG->print("MDIWindow::slotFileNew end");
}
/**
*/
bool MDIWindow::slotFileOpen(const QString & fileName, RS2::FormatType type)
{
- RS_DEBUG->print("MDIWindow::slotFileOpen");
+ DEBUG->print("MDIWindow::slotFileOpen");
bool ret = false;
if (document != NULL && !fileName.isEmpty())
{
document->newDoc();
-
- // cosmetics..
-//bah RS_APP->processEvents(QEventLoop::AllEvents, 1000);
-
ret = document->open(fileName, type);
if (ret)
//QString message=tr("Loaded document: ")+fileName;
//statusBar()->message(message, 2000);
- RS_DEBUG->print("MDIWindow::slotFileOpen: autoZoom");
+ DEBUG->print("MDIWindow::slotFileOpen: autoZoom");
graphicView->zoomAuto(false);
- RS_DEBUG->print("MDIWindow::slotFileOpen: autoZoom: OK");
+ DEBUG->print("MDIWindow::slotFileOpen: autoZoom: OK");
}
else
{
- RS_DEBUG->print("MDIWindow::slotFileOpen: failed");
+ DEBUG->print("MDIWindow::slotFileOpen: failed");
}
}
else
{
- RS_DEBUG->print("MDIWindow::slotFileOpen: cancelled");
+ DEBUG->print("MDIWindow::slotFileOpen: cancelled");
//statusBar()->message(tr("Opening aborted"), 2000);
}
- RS_DEBUG->print("MDIWindow::slotFileOpen: OK");
+ DEBUG->print("MDIWindow::slotFileOpen: OK");
return ret;
}
*/
bool MDIWindow::slotFileSave(bool & cancelled)
{
- RS_DEBUG->print("MDIWindow::slotFileSave()");
+ DEBUG->print("MDIWindow::slotFileSave()");
bool ret = false;
cancelled = false;
- if (document != NULL)
+ if (document)
{
if (document->getFilename().isEmpty())
ret = slotFileSaveAs(cancelled);
*/
bool MDIWindow::slotFileSaveAs(bool & cancelled)
{
- RS_DEBUG->print("MDIWindow::slotFileSaveAs");
+ DEBUG->print("MDIWindow::slotFileSaveAs");
bool ret = false;
cancelled = false;
RS2::FormatType t = RS2::FormatDXF;
- QString fn = QG_FileDialog::getSaveFileName(this, &t);
+ QString fn = FileDialog::getSaveFileName(this, &t);
if (document != NULL && !fn.isEmpty())
{
*/
bool MDIWindow::slotFileClose(bool force)
{
- RS_DEBUG->print("MDIWindow::slotFileClose()");
+ DEBUG->print("MDIWindow::slotFileClose()");
bool succ = true;
int exit = 0;
- if (document != NULL && document->isModified())
+ if (document && document->isModified())
{
ExitDialog dlg(this);
dlg.setForce(force);
void MDIWindow::slotFilePrint()
{
- RS_DEBUG->print("MDIWindow::slotFilePrint");
+ DEBUG->print("MDIWindow::slotFilePrint");
//statusBar()->message(tr("Printing..."));
QPrinter printer;
// TODO: Define printing by using the QPainter methods here
painter.end();
- };
+ }
//statusBar()->message(tr("Ready."));
}
/** @return Pointer to graphic view */
-QC_GraphicView * MDIWindow::getGraphicView()
+//QC_GraphicView * MDIWindow::getGraphicView()
+QG_GraphicView * MDIWindow::getGraphicView()
{
return graphicView;
}
/** @return Pointer to document */
-RS_Document * MDIWindow::getDocument()
+Document * MDIWindow::getDocument()
{
return document;
}
}
/** @return Pointer to current event handler */
-RS_EventHandler * MDIWindow::getEventHandler()
+EventHandler * MDIWindow::getEventHandler()
{
- if (graphicView != NULL)
+ if (graphicView)
return graphicView->getEventHandler();
else
return NULL;
*/
void MDIWindow::setParentWindow(MDIWindow * p)
{
- RS_DEBUG->print("setParentWindow");
+ DEBUG->print("setParentWindow");
parentWindow = p;
}
{
os << "MDIWindow[" << w.getId() << "]:\n";
- if (w.parentWindow!=NULL)
+ if (w.parentWindow)
os << " parentWindow: " << w.parentWindow->getId() << "\n";
else
os << " parentWindow: NULL\n";