]> Shamusworld >> Repos - architektonas/blobdiff - src/mainapp/applicationwindow.cpp
Fixed problem with MDI activation.
[architektonas] / src / mainapp / applicationwindow.cpp
index 0566beb287f12d6aba77a1d1c78b6f1d4cac238e..6a3fa71df35331dcba076281b1c42de222473744 100644 (file)
 #include "applicationwindow.h"
 
 #include <fstream>
+#include <stdint.h>
 #include "actiondrawlinefree.h"
 #include "actionlibraryinsert.h"
 #include "actionprintpreview.h"
-#include "rs_creation.h"
-#include "rs_dialogfactory.h"
-#include "rs_dimaligned.h"
-#include "rs_dimlinear.h"
-#include "rs_dimradial.h"
-#include "rs_ellipse.h"
-#include "rs_fileio.h"
-#include "rs_hatch.h"
-#include "rs_insert.h"
-#include "rs_image.h"
+#include "creation.h"
+#include "dialogfactory.h"
+#include "dimaligned.h"
+#include "dimlinear.h"
+#include "dimradial.h"
+#include "ellipse.h"
+#include "fileio.h"
+#include "hatch.h"
+#include "insert.h"
+#include "image.h"
 #include "paintinterface.h"
-#include "rs_script.h"
-#include "rs_scriptlist.h"
+#include "script.h"
+#include "scriptlist.h"
 #include "settings.h"
-#include "rs_solid.h"
-#include "rs_staticgraphicview.h"
-#include "rs_system.h"
-#include "rs_text.h"
-#include "rs_units.h"
+#include "solid.h"
+#include "staticgraphicview.h"
+#include "system.h"
+#include "text.h"
+#include "units.h"
 
 #ifdef RS_CAM
-#include "rs_camdialog.h"
-#include "rs_simulationcontrols.h"
+#include "camdialog.h"
+#include "simulationcontrols.h"
 #endif
 
 #include "colorbox.h"
 #include "mdiwindow.h"
 
 ApplicationWindow * ApplicationWindow::appWindow = NULL;
-
-#ifndef QC_APP_ICON
-# define QC_APP_ICON "qcad.png"
-#endif
-#ifndef QC_APP_ICON16
-# define QC_APP_ICON16 "qcad16.png"
-#endif
-
 extern QSplashScreen * splash;
 
 /**
  * Constructor. Initializes the app.
  */
 ApplicationWindow::ApplicationWindow():
-//     Q3MainWindow(0, "", Qt::WDestructiveClose), QG_MainWindowInterface()
        QMainWindow((QWidget *)NULL/*,this is not a Qt::WindowFlags --> Qt::WA_DeleteOnClose*/), QG_MainWindowInterface()
 {
-       RS_DEBUG->print("ApplicationWindow::ApplicationWindow");
+       DEBUG->print("ApplicationWindow::ApplicationWindow");
 
        appWindow = this;
-//no    assistant = NULL;
        workspace = NULL;
 
-       RS_DEBUG->print("ApplicationWindow::ApplicationWindow: setting icon");
-//     setIcon(qPixmapFromMimeSource(QC_APP_ICON));
-//     setWindowIcon(qPixmapFromMimeSource(QC_APP_ICON));
-       setWindowIcon(QIcon(":/res/" QC_APP_ICON));
+#warning "!!! Need to create new application icon !!!"
+       DEBUG->print("ApplicationWindow::ApplicationWindow: setting icon");
+       setWindowIcon(QIcon(":/res/qcad.png"));
        CreateQtActions(this);
 
-       RS_DEBUG->print("ApplicationWindow::ApplicationWindow: creating action handler");
+       DEBUG->print("ApplicationWindow::ApplicationWindow: creating action handler");
        actionHandler = new ActionHandler(this);
-       RS_DEBUG->print("ApplicationWindow::ApplicationWindow: creating action handler: OK");
+       DEBUG->print("ApplicationWindow::ApplicationWindow: creating action handler: OK");
 
-#ifdef RS_SCRIPTING
-       RS_DEBUG->print("ApplicationWindow::ApplicationWindow: creating scripter");
+#ifdef SCRIPTING
+       DEBUG->print("ApplicationWindow::ApplicationWindow: creating scripter");
        scripter = new QS_Scripter(this, this);
-       RS_DEBUG->print("ApplicationWindow::ApplicationWindow: creating scripter: OK");
+       DEBUG->print("ApplicationWindow::ApplicationWindow: creating scripter: OK");
 #endif
 
-       RS_DEBUG->print("ApplicationWindow::ApplicationWindow: init view");
+       DEBUG->print("ApplicationWindow::ApplicationWindow: init view");
        initView();
-       RS_DEBUG->print("ApplicationWindow::ApplicationWindow: init toolbar");
+       DEBUG->print("ApplicationWindow::ApplicationWindow: init toolbar");
        initToolBar();
-       RS_DEBUG->print("ApplicationWindow::ApplicationWindow: init actions");
+       DEBUG->print("ApplicationWindow::ApplicationWindow: init actions");
        initActions();
-       RS_DEBUG->print("ApplicationWindow::ApplicationWindow: init menu bar");
+       DEBUG->print("ApplicationWindow::ApplicationWindow: init menu bar");
        initMenuBar();
-       RS_DEBUG->print("ApplicationWindow::ApplicationWindow: init status bar");
+       DEBUG->print("ApplicationWindow::ApplicationWindow: init status bar");
        initStatusBar();
 
-       RS_DEBUG->print("ApplicationWindow::ApplicationWindow: creating dialogFactory");
+       DEBUG->print("ApplicationWindow::ApplicationWindow: creating dialogFactory");
        dialogFactory = new QC_DialogFactory(this, optionWidget);
-       RS_DEBUG->print("ApplicationWindow::ApplicationWindow: creating dialogFactory: OK");
-       RS_DEBUG->print("setting dialog factory object");
-
-       if (RS_DialogFactory::instance() == NULL)
-               RS_DEBUG->print("no RS_DialogFactory instance");
-       else
-               RS_DEBUG->print("got RS_DialogFactory instance");
-
-       RS_DialogFactory::instance()->setFactoryObject(dialogFactory);
-       RS_DEBUG->print("setting dialog factory object: OK");
+       DEBUG->print("ApplicationWindow::ApplicationWindow: creating dialogFactory: OK");
+       DEBUG->print("setting dialog factory object");
+       DEBUG->print("%s DialogFactory instance", (DialogFactory::instance() ? "got" : "no"));
+       DialogFactory::instance()->setFactoryObject(dialogFactory);
+       DEBUG->print("setting dialog factory object: OK");
 
-       RS_DEBUG->print("ApplicationWindow::ApplicationWindow: init settings");
+       DEBUG->print("ApplicationWindow::ApplicationWindow: init settings");
        initSettings();
-
-       RS_DEBUG->print("ApplicationWindow::ApplicationWindow: init MDI");
+       DEBUG->print("ApplicationWindow::ApplicationWindow: init MDI");
        initMDI();
 
        // Disable menu and toolbar items
-       emit windowsChanged(FALSE);
+       emit windowsChanged(false);
 
-//FAIL    statusBar()->showMessage(QC_APPNAME " Ready", 2000);
        statusBar()->showMessage("Architektonas Ready", 2000);
        //setFocusPolicy(WheelFocus);
 }
@@ -147,29 +130,22 @@ ApplicationWindow::ApplicationWindow():
  */
 ApplicationWindow::~ApplicationWindow()
 {
-       RS_DEBUG->print("ApplicationWindow::~ApplicationWindow");
-#ifdef RS_SCRIPTING
-       RS_DEBUG->print("ApplicationWindow::~ApplicationWindow: deleting scripter");
+       DEBUG->print("ApplicationWindow::~ApplicationWindow");
+#ifdef SCRIPTING
+       DEBUG->print("ApplicationWindow::~ApplicationWindow: deleting scripter");
        delete scripter;
-       RS_DEBUG->print("ApplicationWindow::~ApplicationWindow: deleting scripter: OK");
+       DEBUG->print("ApplicationWindow::~ApplicationWindow: deleting scripter: OK");
 #endif
 
-       RS_DEBUG->print("ApplicationWindow::~ApplicationWindow: deleting action handler");
+       DEBUG->print("ApplicationWindow::~ApplicationWindow: deleting action handler");
        delete actionHandler;
-       RS_DEBUG->print("ApplicationWindow::~ApplicationWindow: deleting action handler: OK");
+       DEBUG->print("ApplicationWindow::~ApplicationWindow: deleting action handler: OK");
 
-       RS_DEBUG->print("ApplicationWindow::~ApplicationWindow: deleting dialog factory");
+       DEBUG->print("ApplicationWindow::~ApplicationWindow: deleting dialog factory");
        delete dialogFactory;
-       RS_DEBUG->print("ApplicationWindow::~ApplicationWindow: deleting dialog factory: OK");
-
-//no    RS_DEBUG->print("ApplicationWindow::~ApplicationWindow: "
-//                    "deleting assistant..");
-//    if (assistant!=NULL) {
-//        delete assistant;
-//    }
-//    RS_DEBUG->print("ApplicationWindow::~ApplicationWindow: "
-//                    "deleting assistant: OK");
-       RS_DEBUG->print("ApplicationWindow::~ApplicationWindow: OK");
+       DEBUG->print("ApplicationWindow::~ApplicationWindow: deleting dialog factory: OK");
+       
+       DEBUG->print("ApplicationWindow::~ApplicationWindow: OK");
 }
 
 /**
@@ -186,14 +162,14 @@ void ApplicationWindow::slotRunStartScript()
  */
 void ApplicationWindow::slotRunScript()
 {
-       RS_DEBUG->print("ApplicationWindow::slotRunScript");
+       DEBUG->print("ApplicationWindow::slotRunScript");
 
        const QObject * s = sender();
 
        if (s != NULL)
        {
                QString script = ((QAction *)s)->text();
-               RS_DEBUG->print("ApplicationWindow::slotRunScript: %s", script.toLatin1().data());
+               DEBUG->print("ApplicationWindow::slotRunScript: %s", script.toLatin1().data());
                slotRunScript(script);
        }
 }
@@ -203,28 +179,28 @@ void ApplicationWindow::slotRunScript()
  */
 void ApplicationWindow::slotRunScript(const QString & name)
 {
-#ifdef RS_SCRIPTING
-       RS_DEBUG->print("ApplicationWindow::slotRunScript");
+#ifdef SCRIPTING
+       DEBUG->print("ApplicationWindow::slotRunScript");
 
        if (scripter == NULL)
        {
-               RS_DEBUG->print(RS_Debug::D_WARNING, "ApplicationWindow::slotRunScript: scripter not initialized");
+               DEBUG->print(Debug::D_WARNING, "ApplicationWindow::slotRunScript: scripter not initialized");
                return;
        }
 
     statusBar()->showMessage(tr("Running script '%1'").arg(name), 2000);
 
-       QStringList scriptList = RS_SYSTEM->getScriptList();
-       scriptList.append(RS_SYSTEM->getHomeDir() + "/.architektonas/" + name);
+       QStringList scriptList = SYSTEM->getScriptList();
+       scriptList.append(SYSTEM->getHomeDir() + "/.architektonas/" + name);
 
        for (QStringList::Iterator it = scriptList.begin(); it!=scriptList.end(); ++it)
        {
-               RS_DEBUG->print("ApplicationWindow::slotRunScript: checking script '%s'", (*it).toLatin1().data();
+               DEBUG->print("ApplicationWindow::slotRunScript: checking script '%s'", (*it).toLatin1().data();
                QFileInfo fi(*it);
 
                if (fi.exists() && fi.fileName() == name)
                {
-                       RS_DEBUG->print("ApplicationWindow::slotRunScript: running '%s'", (*it).toLatin1().data());
+                       DEBUG->print("ApplicationWindow::slotRunScript: running '%s'", (*it).toLatin1().data());
                        scripter->runScript(*it, "main");
                }
        }
@@ -242,7 +218,7 @@ void ApplicationWindow::slotInsertBlock()
        if (s != NULL)
        {
                QString block = ((QAction *)s)->text();
-               RS_DEBUG->print("ApplicationWindow::slotInsertBlock: %s", block.toLatin1().data());
+               DEBUG->print("ApplicationWindow::slotInsertBlock: %s", block.toLatin1().data());
                slotInsertBlock(block);
        }
 }
@@ -252,12 +228,12 @@ void ApplicationWindow::slotInsertBlock()
  */
 void ApplicationWindow::slotInsertBlock(const QString & name)
 {
-       RS_DEBUG->print("ApplicationWindow::slotInsertBlock: '%s'", name.toLatin1().data());
+       DEBUG->print("ApplicationWindow::slotInsertBlock: '%s'", name.toLatin1().data());
 
        statusBar()->showMessage(tr("Inserting block '%1'").arg(name), 2000);
 
        GraphicView * graphicView = getGraphicView();
-       RS_Document * document = getDocument();
+       Document * document = getDocument();
 
        if (graphicView && document)
        {
@@ -314,9 +290,9 @@ void ApplicationWindow::finishSplashScreen()
  */
 void ApplicationWindow::closeEvent(QCloseEvent * /*ce*/)
 {
-       RS_DEBUG->print("ApplicationWindow::closeEvent()");
+       DEBUG->print("ApplicationWindow::closeEvent()");
        slotFileQuit();
-       RS_DEBUG->print("ApplicationWindow::closeEvent(): OK");
+       DEBUG->print("ApplicationWindow::closeEvent(): OK");
 }
 
 /**
@@ -335,7 +311,7 @@ void ApplicationWindow::mouseReleaseEvent(QMouseEvent * e)
  */
 void ApplicationWindow::initMDI()
 {
-       RS_DEBUG->print("ApplicationWindow::initMDI() begin");
+       DEBUG->print("ApplicationWindow::initMDI() begin");
 
 /* Could use QVBoxLayout instead of Q3VBox, but do we even need to? */
 //     Q3VBox * vb = new Q3VBox(this);
@@ -345,14 +321,14 @@ void ApplicationWindow::initMDI()
 //     workspace->setScrollBarsEnabled(true);
 //     setCentralWidget(vb);
        setCentralWidget(workspace);//JLH:hmm. (Yes, it works! \o/)
-       RS_DEBUG->print("ApplicationWindow::initMDI(): workspace=%08X", workspace);
+       DEBUG->print("ApplicationWindow::initMDI(): workspace=%08X", workspace);
 
 //#warning "Object::connect: No such signal QMdiArea::windowActivated(QWidget *)"
 //     connect(workspace, SIGNAL(windowActivated(QWidget *)), this, SLOT(slotWindowActivated(QWidget *)));
        connect(workspace, SIGNAL(subWindowActivated(QMdiSubWindow *)), this,
                SLOT(slotWindowActivated(QMdiSubWindow *)));
 
-       RS_DEBUG->print("ApplicationWindow::initMDI() end");
+       DEBUG->print("ApplicationWindow::initMDI() end");
 }
 
 /**
@@ -362,7 +338,7 @@ void ApplicationWindow::initMDI()
  */
 void ApplicationWindow::initActions()
 {
-       RS_DEBUG->print("ApplicationWindow::initActions()");
+       DEBUG->print("ApplicationWindow::initActions()");
 
        //
        // File actions:
@@ -404,7 +380,7 @@ void ApplicationWindow::initActions()
        menu->addAction(actionFilePrintPreview);
        tb->addAction(actionFilePrintPreview);
        connect(actionFilePrintPreview, SIGNAL(toggled(bool)), this, SLOT(slotFilePrintPreview(bool)));
-       connect(this, SIGNAL(printPreviewChanged(bool)), actionFilePrintPreview, SLOT(setOn(bool)));
+//???  connect(this, SIGNAL(printPreviewChanged(bool)), actionFilePrintPreview, SLOT(setOn(bool)));
        connect(this, SIGNAL(windowsChanged(bool)), actionFilePrintPreview, SLOT(setEnabled(bool)));
 
        menu->addSeparator();
@@ -486,7 +462,7 @@ void ApplicationWindow::initActions()
        tb->addAction(actionViewGrid);
        actionViewGrid->setChecked(true);
        connect(actionViewGrid, SIGNAL(toggled(bool)), this, SLOT(slotViewGrid(bool)));
-       connect(this, SIGNAL(gridChanged(bool)), actionViewGrid, SLOT(setOn(bool)));
+//???  connect(this, SIGNAL(gridChanged(bool)), actionViewGrid, SLOT(setOn(bool)));
        connect(this, SIGNAL(windowsChanged(bool)), actionViewGrid, SLOT(setEnabled(bool)));
 
        settings.beginGroup("Appearance");
@@ -498,23 +474,9 @@ void ApplicationWindow::initActions()
        tb->addAction(actionViewDraft);
        actionViewDraft->setChecked(draftMode);
        connect(actionViewDraft, SIGNAL(toggled(bool)), this, SLOT(slotViewDraft(bool)));
-       connect(this, SIGNAL(draftChanged(bool)), actionViewDraft, SLOT(setOn(bool)));
+//???  connect(this, SIGNAL(draftChanged(bool)), actionViewDraft, SLOT(setOn(bool)));
        connect(this, SIGNAL(windowsChanged(bool)), actionViewDraft, SLOT(setEnabled(bool)));
 
-    /*
-       action = actionFactory.createAction(RS2::ActionViewLayerList, this);
-       action->addTo(menu);
-       action->setChecked(true);
-       action = actionFactory.createAction(RS2::ActionViewBlockList, this);
-       action->addTo(menu);
-       action->setChecked(true);
-       action = actionFactory.createAction(RS2::ActionViewOptionToolbar, this);
-       action->addTo(menu);
-       action->setChecked(true);
-       action = actionFactory.createAction(RS2::ActionViewCommandLine, this);
-       action->addTo(menu);
-       action->setChecked(true);*/
-
 //     action = actionFactory.createAction(RS2::ActionZoomRedraw, actionHandler);
        menu->addAction(actionZoomRedraw);
        tb->addAction(actionZoomRedraw);
@@ -765,6 +727,9 @@ void ApplicationWindow::initActions()
        subMenu->addAction(actionPolylineAdd);
        connect(actionPolylineAdd, SIGNAL(activated()), actionHandler, SLOT(slotPolylineAdd()));
        connect(this, SIGNAL(windowsChanged(bool)), actionPolylineAdd, SLOT(setEnabled(bool)));
+       subMenu->addAction(actionPolylineAppend);
+       connect(actionPolylineAppend, SIGNAL(activated()), actionHandler, SLOT(slotPolylineAppend()));
+       connect(this, SIGNAL(windowsChanged(bool)), actionPolylineAppend, SLOT(setEnabled(bool)));
 //     action = actionFactory.createAction(RS2::ActionPolylineDel, actionHandler);
        subMenu->addAction(actionPolylineDel);
        connect(actionPolylineDel, SIGNAL(activated()), actionHandler, SLOT(slotPolylineDel()));
@@ -804,35 +769,27 @@ void ApplicationWindow::initActions()
 #endif
 
        menu = new QMenu(tr("&Dimension"), this);
-//     action = actionFactory.createAction(RS2::ActionDimAligned, actionHandler);
        menu->addAction(actionDimAligned);
        connect(actionDimAligned, SIGNAL(activated()), actionHandler, SLOT(slotDimAligned()));
        connect(this, SIGNAL(windowsChanged(bool)), actionDimAligned, SLOT(setEnabled(bool)));
-//     action = actionFactory.createAction(RS2::ActionDimLinear, actionHandler);
        menu->addAction(actionDimLinear);
        connect(actionDimLinear, SIGNAL(activated()), actionHandler, SLOT(slotDimLinear()));
        connect(this, SIGNAL(windowsChanged(bool)), actionDimLinear, SLOT(setEnabled(bool)));
-//     action = actionFactory.createAction(RS2::ActionDimLinearHor, actionHandler);
        menu->addAction(actionDimLinearHor);
        connect(actionDimLinearHor, SIGNAL(activated()), actionHandler, SLOT(slotDimLinearHor()));
        connect(this, SIGNAL(windowsChanged(bool)), actionDimLinearHor, SLOT(setEnabled(bool)));
-//     action = actionFactory.createAction(RS2::ActionDimLinearVer, actionHandler);
        menu->addAction(actionDimLinearVer);
        connect(actionDimLinearVer, SIGNAL(activated()), actionHandler, SLOT(slotDimLinearVer()));
        connect(this, SIGNAL(windowsChanged(bool)), actionDimLinearVer, SLOT(setEnabled(bool)));
-//     action = actionFactory.createAction(RS2::ActionDimRadial, actionHandler);
        menu->addAction(actionDimRadial);
        connect(actionDimRadial, SIGNAL(activated()), actionHandler, SLOT(slotDimRadial()));
        connect(this, SIGNAL(windowsChanged(bool)), actionDimRadial, SLOT(setEnabled(bool)));
-//     action = actionFactory.createAction(RS2::ActionDimDiametric, actionHandler);
        menu->addAction(actionDimDiametric);
        connect(actionDimDiametric, SIGNAL(activated()), actionHandler, SLOT(slotDimDiametric()));
        connect(this, SIGNAL(windowsChanged(bool)), actionDimDiametric, SLOT(setEnabled(bool)));
-//     action = actionFactory.createAction(RS2::ActionDimAngular, actionHandler);
        menu->addAction(actionDimAngular);
        connect(actionDimAngular, SIGNAL(activated()), actionHandler, SLOT(slotDimAngular()));
        connect(this, SIGNAL(windowsChanged(bool)), actionDimAngular, SLOT(setEnabled(bool)));
-//     action = actionFactory.createAction(RS2::ActionDimLeader, actionHandler);
        menu->addAction(actionDimLeader);
        connect(actionDimLeader, SIGNAL(activated()), actionHandler, SLOT(slotDimLeader()));
        connect(this, SIGNAL(windowsChanged(bool)), actionDimLeader, SLOT(setEnabled(bool)));
@@ -845,81 +802,60 @@ void ApplicationWindow::initActions()
        // Modifying actions:
        //
        menu = new QMenu(tr("&Modify"), this);
-//     action = actionFactory.createAction(RS2::ActionModifyMove, actionHandler);
        menu->addAction(actionModifyMove);
        connect(actionModifyMove, SIGNAL(activated()), actionHandler, SLOT(slotModifyMove()));
        connect(this, SIGNAL(windowsChanged(bool)), actionModifyMove, SLOT(setEnabled(bool)));
-//     action = actionFactory.createAction(RS2::ActionModifyRotate, actionHandler);
        menu->addAction(actionModifyRotate);
        connect(actionModifyRotate, SIGNAL(activated()), actionHandler, SLOT(slotModifyRotate()));
        connect(this, SIGNAL(windowsChanged(bool)), actionModifyRotate, SLOT(setEnabled(bool)));
-//     action = actionFactory.createAction(RS2::ActionModifyScale, actionHandler);
        menu->addAction(actionModifyScale);
        connect(actionModifyScale, SIGNAL(activated()), actionHandler, SLOT(slotModifyScale()));
        connect(this, SIGNAL(windowsChanged(bool)), actionModifyScale, SLOT(setEnabled(bool)));
-//     action = actionFactory.createAction(RS2::ActionModifyMirror, actionHandler);
        menu->addAction(actionModifyMirror);
        connect(actionModifyMirror, SIGNAL(activated()), actionHandler, SLOT(slotModifyMirror()));
        connect(this, SIGNAL(windowsChanged(bool)), actionModifyMirror, SLOT(setEnabled(bool)));
-//     action = actionFactory.createAction(RS2::ActionModifyMoveRotate, actionHandler);
        menu->addAction(actionModifyMoveRotate);
        connect(actionModifyMoveRotate, SIGNAL(activated()), actionHandler, SLOT(slotModifyMoveRotate()));
        connect(this, SIGNAL(windowsChanged(bool)), actionModifyMoveRotate, SLOT(setEnabled(bool)));
-//     action = actionFactory.createAction(RS2::ActionModifyRotate2, actionHandler);
        menu->addAction(actionModifyRotate2);
        connect(actionModifyRotate2, SIGNAL(activated()), actionHandler, SLOT(slotModifyRotate2()));
        connect(this, SIGNAL(windowsChanged(bool)), actionModifyRotate2, SLOT(setEnabled(bool)));
-//     action = actionFactory.createAction(RS2::ActionModifyTrim, actionHandler);
        menu->addAction(actionModifyTrim);
        connect(actionModifyTrim, SIGNAL(activated()), actionHandler, SLOT(slotModifyTrim()));
        connect(this, SIGNAL(windowsChanged(bool)), actionModifyTrim, SLOT(setEnabled(bool)));
-//     action = actionFactory.createAction(RS2::ActionModifyTrim2, actionHandler);
        menu->addAction(actionModifyTrim2);
        connect(actionModifyTrim2, SIGNAL(activated()), actionHandler, SLOT(slotModifyTrim2()));
        connect(this, SIGNAL(windowsChanged(bool)), actionModifyTrim2, SLOT(setEnabled(bool)));
-//     action = actionFactory.createAction(RS2::ActionModifyTrimAmount, actionHandler);
        menu->addAction(actionModifyTrimAmount);
        connect(actionModifyTrimAmount, SIGNAL(activated()), actionHandler, SLOT(slotModifyTrimAmount()));
        connect(this, SIGNAL(windowsChanged(bool)), actionModifyTrimAmount, SLOT(setEnabled(bool)));
-//     action = actionFactory.createAction(RS2::ActionModifyBevel, actionHandler);
        menu->addAction(actionModifyBevel);
        connect(actionModifyBevel, SIGNAL(activated()), actionHandler, SLOT(slotModifyBevel()));
        connect(this, SIGNAL(windowsChanged(bool)), actionModifyBevel, SLOT(setEnabled(bool)));
-//     action = actionFactory.createAction(RS2::ActionModifyRound, actionHandler);
        menu->addAction(actionModifyRound);
        connect(actionModifyRound, SIGNAL(activated()), actionHandler, SLOT(slotModifyRound()));
        connect(this, SIGNAL(windowsChanged(bool)), actionModifyRound, SLOT(setEnabled(bool)));
-//     action = actionFactory.createAction(RS2::ActionModifyCut, actionHandler);
        menu->addAction(actionModifyCut);
        connect(actionModifyCut, SIGNAL(activated()), actionHandler, SLOT(slotModifyCut()));
        connect(this, SIGNAL(windowsChanged(bool)), actionModifyCut, SLOT(setEnabled(bool)));
-//     action = actionFactory.createAction(RS2::ActionModifyStretch, actionHandler);
        menu->addAction(actionModifyStretch);
        connect(actionModifyStretch, SIGNAL(activated()), actionHandler, SLOT(slotModifyStretch()));
        connect(this, SIGNAL(windowsChanged(bool)), actionModifyStretch, SLOT(setEnabled(bool)));
-//     action = actionFactory.createAction(RS2::ActionModifyEntity, actionHandler);
        menu->addAction(actionModifyEntity);
        connect(actionModifyEntity, SIGNAL(activated()), actionHandler, SLOT(slotModifyEntity()));
        connect(this, SIGNAL(windowsChanged(bool)), actionModifyEntity, SLOT(setEnabled(bool)));
-//     action = actionFactory.createAction(RS2::ActionModifyAttributes, actionHandler);
        menu->addAction(actionModifyAttributes);
        connect(actionModifyAttributes, SIGNAL(activated()), actionHandler, SLOT(slotModifyAttributes()));
        connect(this, SIGNAL(windowsChanged(bool)), actionModifyAttributes, SLOT(setEnabled(bool)));
-//     action = actionFactory.createAction(RS2::ActionModifyDelete, actionHandler);
        menu->addAction(actionModifyDelete);
        connect(actionModifyDelete, SIGNAL(activated()), actionHandler, SLOT(slotModifyDelete()));
        connect(this, SIGNAL(windowsChanged(bool)), actionModifyDelete, SLOT(setEnabled(bool)));
-//     action = actionFactory.createAction(RS2::ActionModifyDeleteQuick, actionHandler);
        menu->addAction(actionModifyDeleteQuick);
        connect(actionModifyDeleteQuick, SIGNAL(activated()), actionHandler, SLOT(slotModifyDeleteQuick()));
        connect(this, SIGNAL(windowsChanged(bool)), actionModifyDeleteQuick, SLOT(setEnabled(bool)));
-//     action = actionFactory.createAction(RS2::ActionModifyExplodeText, actionHandler);
        menu->addAction(actionModifyExplodeText);
        connect(actionModifyExplodeText, SIGNAL(activated()), actionHandler, SLOT(slotModifyExplodeText()));
        connect(this, SIGNAL(windowsChanged(bool)), actionModifyExplodeText, SLOT(setEnabled(bool)));
-////   action = actionFactory.createAction(RS2::ActionModifyDeleteFree, actionHandler);
-////   menu->addAction(action);
-//     action = actionFactory.createAction(RS2::ActionBlocksExplode, actionHandler);
        menu->addAction(actionBlocksExplode);
        connect(actionBlocksExplode, SIGNAL(activated()), actionHandler, SLOT(slotBlocksExplode()));
        connect(this, SIGNAL(windowsChanged(bool)), actionBlocksExplode, SLOT(setEnabled(bool)));
@@ -928,48 +864,39 @@ void ApplicationWindow::initActions()
        // Snapping actions:
        //
        menu = new QMenu(tr("&Snap"), this);
-//     action = actionFactory.createAction(RS2::ActionSnapFree, actionHandler);
        menu->addAction(actionSnapFree);
        actionHandler->setActionSnapFree(actionSnapFree); // ???Why???
        connect(actionSnapFree, SIGNAL(activated()), actionHandler, SLOT(slotSnapFree()));
        connect(this, SIGNAL(windowsChanged(bool)), actionSnapFree, SLOT(setEnabled(bool)));
        actionSnapFree->setChecked(true);
-//     action = actionFactory.createAction(RS2::ActionSnapGrid, actionHandler);
        menu->addAction(actionSnapGrid);
        actionHandler->setActionSnapGrid(actionSnapGrid); // ???Why???
        connect(actionSnapGrid, SIGNAL(activated()), actionHandler, SLOT(slotSnapGrid()));
        connect(this, SIGNAL(windowsChanged(bool)), actionSnapGrid, SLOT(setEnabled(bool)));
-//     action = actionFactory.createAction(RS2::ActionSnapEndpoint, actionHandler);
        menu->addAction(actionSnapEndpoint);
        actionHandler->setActionSnapEndpoint(actionSnapEndpoint); // ???Why???
        connect(actionSnapEndpoint, SIGNAL(activated()), actionHandler, SLOT(slotSnapEndpoint()));
        connect(this, SIGNAL(windowsChanged(bool)), actionSnapEndpoint, SLOT(setEnabled(bool)));
-//     action = actionFactory.createAction(RS2::ActionSnapOnEntity, actionHandler);
        menu->addAction(actionSnapOnEntity);
        actionHandler->setActionSnapOnEntity(actionSnapOnEntity); // ???Why???
        connect(actionSnapOnEntity, SIGNAL(activated()), actionHandler, SLOT(slotSnapOnEntity()));
        connect(this, SIGNAL(windowsChanged(bool)), actionSnapOnEntity, SLOT(setEnabled(bool)));
-//     action = actionFactory.createAction(RS2::ActionSnapCenter, actionHandler);
        menu->addAction(actionSnapCenter);
        actionHandler->setActionSnapCenter(actionSnapCenter); // ???Why???
        connect(actionSnapCenter, SIGNAL(activated()), actionHandler, SLOT(slotSnapCenter()));
        connect(this, SIGNAL(windowsChanged(bool)), actionSnapCenter, SLOT(setEnabled(bool)));
-//     action = actionFactory.createAction(RS2::ActionSnapMiddle, actionHandler);
        menu->addAction(actionSnapMiddle);
        actionHandler->setActionSnapMiddle(actionSnapMiddle); // ???Why???
        connect(actionSnapMiddle, SIGNAL(activated()), actionHandler, SLOT(slotSnapMiddle()));
        connect(this, SIGNAL(windowsChanged(bool)), actionSnapMiddle, SLOT(setEnabled(bool)));
-//     action = actionFactory.createAction(RS2::ActionSnapDist, actionHandler);
        menu->addAction(actionSnapDist);
        actionHandler->setActionSnapDist(actionSnapDist); // ???Why???
        connect(actionSnapDist, SIGNAL(activated()), actionHandler, SLOT(slotSnapDist()));
        connect(this, SIGNAL(windowsChanged(bool)), actionSnapDist, SLOT(setEnabled(bool)));
-//     action = actionFactory.createAction(RS2::ActionSnapIntersection, actionHandler);
        menu->addAction(actionSnapIntersection);
        actionHandler->setActionSnapIntersection(actionSnapIntersection); // ???Why???
        connect(actionSnapIntersection, SIGNAL(activated()), actionHandler, SLOT(slotSnapIntersection()));
        connect(this, SIGNAL(windowsChanged(bool)), actionSnapIntersection, SLOT(setEnabled(bool)));
-//     action = actionFactory.createAction(RS2::ActionSnapIntersectionManual, actionHandler);
        menu->addAction(actionSnapIntersectionManual);
        actionHandler->setActionSnapIntersectionManual(actionSnapIntersectionManual); // ???Why???
        connect(actionSnapIntersectionManual, SIGNAL(activated()), actionHandler, SLOT(slotSnapIntersectionManual()));
@@ -977,23 +904,19 @@ void ApplicationWindow::initActions()
 
        menu->addSeparator();
 
-//     action = actionFactory.createAction(RS2::ActionRestrictNothing, actionHandler);
        menu->addAction(actionRestrictNothing);
        actionHandler->setActionRestrictNothing(actionRestrictNothing); // ???WHY???
        connect(actionRestrictNothing, SIGNAL(activated()), actionHandler, SLOT(slotRestrictNothing()));
        connect(this, SIGNAL(windowsChanged(bool)), actionRestrictNothing, SLOT(setEnabled(bool)));
        actionRestrictNothing->setChecked(true);
-//     action = actionFactory.createAction(RS2::ActionRestrictOrthogonal, actionHandler);
        menu->addAction(actionRestrictOrthogonal);
        actionHandler->setActionRestrictOrthogonal(actionRestrictOrthogonal); // ???WHY???
        connect(actionRestrictOrthogonal, SIGNAL(activated()), actionHandler, SLOT(slotRestrictOrthogonal()));
        connect(this, SIGNAL(windowsChanged(bool)), actionRestrictOrthogonal, SLOT(setEnabled(bool)));
-//     action = actionFactory.createAction(RS2::ActionRestrictHorizontal, actionHandler);
        menu->addAction(actionRestrictHorizontal);
        actionHandler->setActionRestrictHorizontal(actionRestrictHorizontal); // ???WHY???
        connect(actionRestrictHorizontal, SIGNAL(activated()), actionHandler, SLOT(slotRestrictHorizontal()));
        connect(this, SIGNAL(windowsChanged(bool)), actionRestrictHorizontal, SLOT(setEnabled(bool)));
-//     action = actionFactory.createAction(RS2::ActionRestrictVertical, actionHandler);
        menu->addAction(actionRestrictVertical);
        actionHandler->setActionRestrictVertical(actionRestrictVertical); // ???WHY???
        connect(actionRestrictVertical, SIGNAL(activated()), actionHandler, SLOT(slotRestrictVertical()));
@@ -1001,11 +924,9 @@ void ApplicationWindow::initActions()
 
        menu->addSeparator();
 
-//     action = actionFactory.createAction(RS2::ActionSetRelativeZero, actionHandler);
        menu->addAction(actionSetRelativeZero);
        connect(actionSetRelativeZero, SIGNAL(activated()), actionHandler, SLOT(slotSetRelativeZero()));
        connect(this, SIGNAL(windowsChanged(bool)), actionSetRelativeZero, SLOT(setEnabled(bool)));
-//     action = actionFactory.createAction(RS2::ActionLockRelativeZero, actionHandler);
        menu->addAction(actionLockRelativeZero);
        actionHandler->setActionLockRelativeZero(actionLockRelativeZero);
        connect(actionLockRelativeZero, SIGNAL(toggled(bool)), actionHandler, SLOT(slotLockRelativeZero(bool))); // ???WHY???
@@ -1016,8 +937,6 @@ void ApplicationWindow::initActions()
        // Info actions:
        //
        menu = new QMenu(tr("&Info"), this);
-       //action = actionFactory.createAction(RS2::ActionInfoInside, actionHandler);
-       //menu->addAction(action);
        menu->addAction(actionInfoDist);
        connect(actionInfoDist, SIGNAL(activated()), actionHandler, SLOT(slotInfoDist()));
        connect(this, SIGNAL(windowsChanged(bool)), actionInfoDist, SLOT(setEnabled(bool)));
@@ -1039,27 +958,21 @@ void ApplicationWindow::initActions()
        // Layer actions:
        //
        menu = new QMenu(tr("&Layer"), this);
-//     action = actionFactory.createAction(RS2::ActionLayersDefreezeAll, actionHandler);
        menu->addAction(actionLayersDefreezeAll);
        connect(actionLayersDefreezeAll, SIGNAL(activated()), actionHandler, SLOT(slotLayersDefreezeAll()));
        connect(this, SIGNAL(windowsChanged(bool)), actionLayersDefreezeAll, SLOT(setEnabled(bool)));
-//     action = actionFactory.createAction(RS2::ActionLayersFreezeAll, actionHandler);
        menu->addAction(actionLayersFreezeAll);
        connect(actionLayersFreezeAll, SIGNAL(activated()), actionHandler, SLOT(slotLayersFreezeAll()));
        connect(this, SIGNAL(windowsChanged(bool)), actionLayersFreezeAll, SLOT(setEnabled(bool)));
-//     action = actionFactory.createAction(RS2::ActionLayersAdd, actionHandler);
        menu->addAction(actionLayersAdd);
        connect(actionLayersAdd, SIGNAL(activated()), actionHandler, SLOT(slotLayersAdd()));
        connect(this, SIGNAL(windowsChanged(bool)), actionLayersAdd, SLOT(setEnabled(bool)));
-//     action = actionFactory.createAction(RS2::ActionLayersRemove, actionHandler);
        menu->addAction(actionLayersRemove);
        connect(actionLayersRemove, SIGNAL(activated()), actionHandler, SLOT(slotLayersRemove()));
        connect(this, SIGNAL(windowsChanged(bool)), actionLayersRemove, SLOT(setEnabled(bool)));
-//     action = actionFactory.createAction(RS2::ActionLayersEdit, actionHandler);
        menu->addAction(actionLayersEdit);
        connect(actionLayersEdit, SIGNAL(activated()), actionHandler, SLOT(slotLayersEdit()));
        connect(this, SIGNAL(windowsChanged(bool)), actionLayersEdit, SLOT(setEnabled(bool)));
-//     action = actionFactory.createAction(RS2::ActionLayersToggleView, actionHandler);
        menu->addAction(actionLayersToggleView);
        connect(actionLayersToggleView, SIGNAL(activated()), actionHandler, SLOT(slotLayersToggleView()));
        connect(this, SIGNAL(windowsChanged(bool)), actionLayersToggleView, SLOT(setEnabled(bool)));
@@ -1068,39 +981,30 @@ void ApplicationWindow::initActions()
        // Block actions:
        //
        menu = new QMenu(tr("&Block"), this);
-//     action = actionFactory.createAction(RS2::ActionBlocksDefreezeAll, actionHandler);
        menu->addAction(actionBlocksDefreezeAll);
        connect(actionBlocksDefreezeAll, SIGNAL(activated()), actionHandler, SLOT(slotBlocksDefreezeAll()));
        connect(this, SIGNAL(windowsChanged(bool)), actionBlocksDefreezeAll, SLOT(setEnabled(bool)));
-//     action = actionFactory.createAction(RS2::ActionBlocksFreezeAll, actionHandler);
        menu->addAction(actionBlocksFreezeAll);
        connect(actionBlocksFreezeAll, SIGNAL(activated()), actionHandler, SLOT(slotBlocksFreezeAll()));
        connect(this, SIGNAL(windowsChanged(bool)), actionBlocksFreezeAll, SLOT(setEnabled(bool)));
-//     action = actionFactory.createAction(RS2::ActionBlocksAdd, actionHandler);
        menu->addAction(actionBlocksAdd);
        connect(actionBlocksAdd, SIGNAL(activated()), actionHandler, SLOT(slotBlocksAdd()));
        connect(this, SIGNAL(windowsChanged(bool)), actionBlocksAdd, SLOT(setEnabled(bool)));
-//     action = actionFactory.createAction(RS2::ActionBlocksRemove, actionHandler);
        menu->addAction(actionBlocksRemove);
        connect(actionBlocksRemove, SIGNAL(activated()), actionHandler, SLOT(slotBlocksRemove()));
        connect(this, SIGNAL(windowsChanged(bool)), actionBlocksRemove, SLOT(setEnabled(bool)));
-//     action = actionFactory.createAction(RS2::ActionBlocksAttributes, actionHandler);
        menu->addAction(actionBlocksAttributes);
        connect(actionBlocksAttributes, SIGNAL(activated()), actionHandler, SLOT(slotBlocksAttributes()));
        connect(this, SIGNAL(windowsChanged(bool)), actionBlocksAttributes, SLOT(setEnabled(bool)));
-//     action = actionFactory.createAction(RS2::ActionBlocksInsert, actionHandler);
        menu->addAction(actionBlocksInsert);
        connect(actionBlocksInsert, SIGNAL(activated()), actionHandler, SLOT(slotBlocksInsert()));
        connect(this, SIGNAL(windowsChanged(bool)), actionBlocksInsert, SLOT(setEnabled(bool)));
-//     action = actionFactory.createAction(RS2::ActionBlocksEdit, actionHandler);
        menu->addAction(actionBlocksEdit);
        connect(actionBlocksEdit, SIGNAL(activated()), actionHandler, SLOT(slotBlocksEdit()));
        connect(this, SIGNAL(windowsChanged(bool)), actionBlocksEdit, SLOT(setEnabled(bool)));
-//     action = actionFactory.createAction(RS2::ActionBlocksCreate, actionHandler);
        menu->addAction(actionBlocksCreate);
        connect(actionBlocksCreate, SIGNAL(activated()), actionHandler, SLOT(slotBlocksCreate()));
        connect(this, SIGNAL(windowsChanged(bool)), actionBlocksCreate, SLOT(setEnabled(bool)));
-//     action = actionFactory.createAction(RS2::ActionBlocksExplode, actionHandler);
        menu->addAction(actionBlocksExplode);
        connect(actionBlocksExplode, SIGNAL(activated()), actionHandler, SLOT(slotBlocksExplode()));
        connect(this, SIGNAL(windowsChanged(bool)), actionBlocksExplode, SLOT(setEnabled(bool)));
@@ -1113,7 +1017,7 @@ void ApplicationWindow::initActions()
        addToolBar(Qt::TopToolBarArea, (QToolBar *)penToolBar); // hmm.
        addToolBar(Qt::TopToolBarArea, optionWidget);
 
-#ifdef RS_SCRIPTING
+#ifdef SCRIPTING
        // Scripts menu:
        //
        scriptMenu = new QMenu(this);
@@ -1141,7 +1045,7 @@ void ApplicationWindow::initActions()
 
        // Help menu:
        //
-       helpAboutApp = new QAction(QIcon(QC_APP_ICON16), tr("&About Architektonas"), this);
+       helpAboutApp = new QAction(QIcon("qcad16.png"), tr("&About Architektonas"), this);
 //    helpAboutApp = new QAction(tr("About"), qPixmapFromMimeSource(QC_APP_ICON16), tr("&About %1").arg(QC_APPNAME), 0, this);
        helpAboutApp->setStatusTip(tr("About the application"));
        //helpAboutApp->setWhatsThis(tr("About\n\nAbout the application"));
@@ -1154,55 +1058,30 @@ void ApplicationWindow::initActions()
        connect(helpManual, SIGNAL(activated()), this, SLOT(slotHelpManual()));
 
        testDumpEntities = new QAction("Dump &Entities", this);
-//    testDumpEntities = new QAction("Dump Entities", "Dump &Entities", 0, this);
        connect(testDumpEntities, SIGNAL(activated()), this, SLOT(slotTestDumpEntities()));
-
        testDumpUndo = new QAction("Undo Info", this);
-//     testDumpUndo = new QAction("Dump Undo Info", "Undo Info", 0, this);
        connect(testDumpUndo, SIGNAL(activated()), this, SLOT(slotTestDumpUndo()));
-
        testUpdateInserts = new QAction("&Update Inserts", this);
-//    testUpdateInserts = new QAction("Update Inserts", "&Update Inserts", 0, this);
        connect(testUpdateInserts, SIGNAL(activated()), this, SLOT(slotTestUpdateInserts()));
-
        testDrawFreehand = new QAction("Draw Freehand", this);
-//    testDrawFreehand = new QAction("Draw Freehand", "Draw Freehand", 0, this);
        connect(testDrawFreehand, SIGNAL(activated()), this, SLOT(slotTestDrawFreehand()));
-
        testInsertBlock = new QAction("Insert Block", this);
-//    testInsertBlock = new QAction("Insert Block", "Insert Block", 0, this);
        connect(testInsertBlock, SIGNAL(activated()), this, SLOT(slotTestInsertBlock()));
-
        testInsertText = new QAction("Insert Text", this);
-//    testInsertText = new QAction("Insert Text", "Insert Text", 0, this);
        connect(testInsertText, SIGNAL(activated()), this, SLOT(slotTestInsertText()));
-
        testInsertImage = new QAction("Insert Image", this);
-//    testInsertImage = new QAction("Insert Image", "Insert Image", 0, this);
        connect(testInsertImage, SIGNAL(activated()), this, SLOT(slotTestInsertImage()));
-
        testUnicode = new QAction("Unicode", this);
-//    testUnicode = new QAction("Unicode", "Unicode", 0, this);
        connect(testUnicode, SIGNAL(activated()), this, SLOT(slotTestUnicode()));
-
        testInsertEllipse = new QAction("Insert Ellipse", this);
-//    testInsertEllipse = new QAction("Insert Ellipse", "Insert Ellipse", 0, this);
        connect(testInsertEllipse, SIGNAL(activated()), this, SLOT(slotTestInsertEllipse()));
-
        testMath01 = new QAction("Math01", this);
-//    testMath01 = new QAction("Math01", "Math01", 0, this);
        connect(testMath01, SIGNAL(activated()), this, SLOT(slotTestMath01()));
-
        testResize640 = new QAction("Resize 1", this);
-//    testResize640 = new QAction("Resize to 640x480", "Resize 1", 0, this);
        connect(testResize640, SIGNAL(activated()), this, SLOT(slotTestResize640()));
-
        testResize800 = new QAction("Resize 2", this);
-//    testResize800 = new QAction("Resize to 800x600", "Resize 2", 0, this);
        connect(testResize800, SIGNAL(activated()), this, SLOT(slotTestResize800()));
-
        testResize1024 = new QAction("Resize 3", this);
-//    testResize1024 = new QAction("Resize to 1024x768", "Resize 3", 0, this);
        connect(testResize1024, SIGNAL(activated()), this, SLOT(slotTestResize1024()));
 }
 
@@ -1211,7 +1090,7 @@ void ApplicationWindow::initActions()
  */
 void ApplicationWindow::initMenuBar()
 {
-       RS_DEBUG->print("ApplicationWindow::initMenuBar()");
+       DEBUG->print("ApplicationWindow::initMenuBar()");
 
        // menuBar entry windowsMenu
        windowsMenu = new QMenu(tr("&Window"), this);
@@ -1227,43 +1106,35 @@ void ApplicationWindow::initMenuBar()
 
        // menuBar entry helpMenu
        helpMenu = new QMenu(tr("&Help"), this);
-       helpMenu->addAction(helpManual);//helpManual->addTo(helpMenu);
-
-//     helpMenu->insertSeparator(helpManual);
+       helpMenu->addAction(helpManual);
        helpMenu->addSeparator();
-
-       helpMenu->addAction(helpAboutApp);//helpAboutApp->addTo(helpMenu);
+       helpMenu->addAction(helpAboutApp);
 
        // menuBar entry test menu
        testMenu = new QMenu(tr("De&bugging"), this);
-       testMenu->addAction(testDumpEntities);//testDumpEntities->addTo(testMenu);
-       testMenu->addAction(testDumpUndo);//testDumpUndo->addTo(testMenu);
-       testMenu->addAction(testUpdateInserts);//testUpdateInserts->addTo(testMenu);
-       testMenu->addAction(testDrawFreehand);//testDrawFreehand->addTo(testMenu);
-       testMenu->addAction(testInsertBlock);//testInsertBlock->addTo(testMenu);
-       testMenu->addAction(testInsertText);//testInsertText->addTo(testMenu);
-       testMenu->addAction(testInsertImage);//testInsertImage->addTo(testMenu);
-       testMenu->addAction(testInsertEllipse);//testInsertEllipse->addTo(testMenu);
-       testMenu->addAction(testUnicode);//testUnicode->addTo(testMenu);
-       testMenu->addAction(testMath01);//testMath01->addTo(testMenu);
-       testMenu->addAction(testResize640);//testResize640->addTo(testMenu);
-       testMenu->addAction(testResize800);//testResize800->addTo(testMenu);
-       testMenu->addAction(testResize1024);//testResize1024->addTo(testMenu);
+       testMenu->addAction(testDumpEntities);
+       testMenu->addAction(testDumpUndo);
+       testMenu->addAction(testUpdateInserts);
+       testMenu->addAction(testDrawFreehand);
+       testMenu->addAction(testInsertBlock);
+       testMenu->addAction(testInsertText);
+       testMenu->addAction(testInsertImage);
+       testMenu->addAction(testInsertEllipse);
+       testMenu->addAction(testUnicode);
+       testMenu->addAction(testMath01);
+       testMenu->addAction(testResize640);
+       testMenu->addAction(testResize800);
+       testMenu->addAction(testResize1024);
 
        // menuBar configuration
-#ifdef RS_SCRIPTING
-//     menuBar()->insertItem(tr("&Scripts"), scriptMenu);
+#ifdef SCRIPTING
        menuBar()->addMenu(scriptMenu);
 #endif
-//     menuBar()->insertItem(tr("&Window"), windowsMenu);
        menuBar()->addMenu(windowsMenu);
 #warning "!!!"
-//     menuBar()->insertSeparator();
-//     menuBar()->insertItem(tr("&Help"), helpMenu);
        menuBar()->addMenu(helpMenu);
 
        if (QC_DEBUGGING)
-//             menuBar()->insertItem(tr("De&bugging"), testMenu);
                menuBar()->addMenu(testMenu);
 
        recentFiles = new RecentFiles(this, fileMenu);
@@ -1274,21 +1145,18 @@ void ApplicationWindow::initMenuBar()
  */
 void ApplicationWindow::initToolBar()
 {
-       RS_DEBUG->print("ApplicationWindow::initToolBar()");
+       DEBUG->print("ApplicationWindow::initToolBar()");
 
-//     fileToolBar = new Q3ToolBar(this, "File Operations");
        fileToolBar = addToolBar(tr("File Operations"));
        fileToolBar->setObjectName("file");
-//     editToolBar = new Q3ToolBar(this, "Edit Operations");
        editToolBar = addToolBar(tr("Edit Operations"));
        editToolBar->setObjectName("edit");
-//     zoomToolBar = new Q3ToolBar(this, "Zoom Operations");
        zoomToolBar = addToolBar(tr("Zoom Operations"));
        zoomToolBar->setObjectName("zoom");
        penToolBar = new PenToolBar(this, "Pen Selection");
        penToolBar->setObjectName("pen");
 
-       connect(penToolBar, SIGNAL(penChanged(RS_Pen)), this, SLOT(slotPenChanged(RS_Pen)));
+       connect(penToolBar, SIGNAL(penChanged(Pen)), this, SLOT(slotPenChanged(Pen)));
 
 //     optionWidget = new Q3ToolBar(this, "Tool Options");
 //addToolBarBreak() does nothing...
@@ -1335,24 +1203,26 @@ void ApplicationWindow::initToolBar()
  */
 void ApplicationWindow::initStatusBar()
 {
-       RS_DEBUG->print("ApplicationWindow::initStatusBar()");
+       DEBUG->print("ApplicationWindow::initStatusBar()");
 
        statusBar()->setMinimumHeight(32);
-       coordinateWidget = new CoordinateWidget(statusBar());//, "coordinates");
+       coordinateWidget = new CoordinateWidget(statusBar());
        statusBar()->addWidget(coordinateWidget);
-       mouseWidget = new MouseWidget(statusBar());//, "mouse info");
+       mouseWidget = new MouseWidget(statusBar());
        statusBar()->addWidget(mouseWidget);
-       selectionWidget = new SelectionWidget(statusBar());//, "selections");
+       selectionWidget = new SelectionWidget(statusBar());
        statusBar()->addWidget(selectionWidget);
 }
 
 /**
  * Initializes the global application settings from the
  * config file (unix, mac) or registry (windows).
+ * (Actually, this uses the Qt settings subsystem, so we don't have to worry
+ * about that crap.)
  */
 void ApplicationWindow::initSettings()
 {
-       RS_DEBUG->print("ApplicationWindow::initSettings()");
+       DEBUG->print("ApplicationWindow::initSettings()");
        settings.beginGroup("RecentFiles");
 
        for(int i=0; i<recentFiles->Maximum(); ++i)
@@ -1360,14 +1230,12 @@ void ApplicationWindow::initSettings()
                QString filename = settings.value(QString("File") + QString::number(i + 1)).toString();
 
                if (!filename.isEmpty())
-//                     recentFiles->add(filename);
                        recentFiles->add(filename);
        }
 
        settings.endGroup();
 
        if (recentFiles->count() > 0)
-//             updateRecentFilesMenu();
                recentFiles->UpdateGUI();
 
        settings.beginGroup("Geometry");
@@ -1377,8 +1245,6 @@ void ApplicationWindow::initSettings()
        settings.endGroup();
 
 #ifdef __APPLE__
-//     if (windowY < 30)
-//             windowY = 30;
        if (windowSize.y() < 30)
                windowSize.y() = 30;
 #endif
@@ -1392,7 +1258,7 @@ void ApplicationWindow::initSettings()
  */
 void ApplicationWindow::storeSettings()
 {
-       RS_DEBUG->print("ApplicationWindow::storeSettings()");
+       DEBUG->print("ApplicationWindow::storeSettings()");
 
        settings.beginGroup("RecentFiles");
 
@@ -1407,7 +1273,7 @@ void ApplicationWindow::storeSettings()
        settings.setValue("DockWindows", saveState());
        settings.endGroup();
 
-       RS_DEBUG->print("ApplicationWindow::storeSettings(): OK");
+       DEBUG->print("ApplicationWindow::storeSettings(): OK");
 }
 
 /**
@@ -1415,9 +1281,9 @@ void ApplicationWindow::storeSettings()
  */
 void ApplicationWindow::initView()
 {
-       RS_DEBUG->print("ApplicationWindow::initView()");
+       DEBUG->print("ApplicationWindow::initView()");
 
-       RS_DEBUG->print("init view..");
+       DEBUG->print("init view..");
        QDockWidget * dw;
        layerWidget = NULL;
        blockWidget = NULL;
@@ -1428,7 +1294,7 @@ void ApplicationWindow::initView()
 #endif
 
 #ifdef RS_CAM
-       RS_DEBUG->print("  simulation widget..");
+       DEBUG->print("  simulation widget..");
        dw = new QDockWidget(QDockWidget::InDock, this, "Simulation");
        simulationControls = new RS_SimulationControls(dw, "Simulation");
        simulationControls->setFocusPolicy(Qt::NoFocus);
@@ -1446,7 +1312,7 @@ void ApplicationWindow::initView()
        //simulationDockWindow->hide();
 #endif
 
-       RS_DEBUG->print("  layer widget..");
+       DEBUG->print("  layer widget..");
 //     dw = new QDockWidget(QDockWidget::InDock, this, "Layer");
        dw = new QDockWidget(tr("Layer List"), this);
        dw->setObjectName("layer");
@@ -1463,7 +1329,7 @@ void ApplicationWindow::initView()
        addDockWidget(Qt::RightDockWidgetArea, dw);
        layerDockWindow = dw;
 
-       RS_DEBUG->print("  block widget..");
+       DEBUG->print("  block widget..");
 //     dw = new QDockWidget(QDockWidget::InDock, this, "Block");
        dw = new QDockWidget(tr("Block List"), this);
        dw->setObjectName("block");
@@ -1480,7 +1346,7 @@ void ApplicationWindow::initView()
        addDockWidget(Qt::RightDockWidgetArea, dw);
        blockDockWindow = dw;
 
-       RS_DEBUG->print("  library widget..");
+       DEBUG->print("  library widget..");
 //     dw = new QDockWidget(QDockWidget::OutsideDock, this, "Library");
        dw = new QDockWidget(tr("Library Browser"), this);
        dw->setObjectName("library");
@@ -1504,7 +1370,7 @@ void ApplicationWindow::initView()
        libraryDockWindow = dw;
 //     libraryDockWindow->hide();
 
-       RS_DEBUG->print("  command widget..");
+       DEBUG->print("  command widget..");
 //     dw = new QDockWidget(QDockWidget::InDock, this, "Command");
        dw = new QDockWidget(tr("Command line"), this);
        dw->setObjectName("command");
@@ -1523,33 +1389,9 @@ void ApplicationWindow::initView()
        commandDockWindow = dw;
        addDockWidget(Qt::BottomDockWidgetArea, dw);
 
-       RS_DEBUG->print("  done");
+       DEBUG->print("  done");
 }
 
-/**
- * Creates a new toolbar.
- * Implementation from QG_MainWindowInterface.
- * Can be called from scripts to add individual GUI elements.
- */
-/*QToolBar* ApplicationWindow::createToolBar(const QString& name) {
-    QToolBar* tb = new QToolBar(this, name);
-       tb->setLabel(name);
-       return tb;
-}*/
-
-/**
- * Creates a new button in the given tool bar for running a script.
- */
-/*void ApplicationWindow::addToolBarButton(QToolBar* tb) {
-       if (tb!=NULL) {
-       QAction* action = new QAction("Blah",
-                       QPixmap::fromMimeSource("zoomwindow.png"),
-            "&Blah", QKeySequence(), NULL);
-       action->setStatusTip("Blah blah");
-               action->addTo(tb);
-       }
-}*/
-
 /**
  * Goes back to the previous menu or one step in the current action.
  */
@@ -1603,55 +1445,55 @@ void ApplicationWindow::slotError(const QString & msg)
 }
 
 /**
- * Hands focus back to the application window. In the rare event
- * of a escape press from the layer widget (e.g after switching desktops
- * in XP).
+ * Hands focus back to the application window. In the rare event of a escape
+ * press from the layer widget (e.g after switching desktops in XP).
  */
 void ApplicationWindow::slotFocus()
 {
-    //QG_GraphicView* graphicView = getGraphicView();
-    /*if (graphicView!=NULL) {
-        graphicView->setFocus();
-}
-    else {*/
        setFocus();
-    //}
 }
 
 /**
  * Called when a document window was activated.
  */
-void ApplicationWindow::slotWindowActivated(QMdiSubWindow * /*w*/)
+//void ApplicationWindow::slotWindowActivated(QMdiSubWindow * /*w*/)
+void ApplicationWindow::slotWindowActivated(QMdiSubWindow * sw)
 {
-       RS_DEBUG->print("ApplicationWindow::slotWindowActivated begin");
+//This passes in a QMdiSubWindow, so why don't we use it???
+// Now, we do. :-)
+//#warning "!!! ApplicationWindow::slotWindowActivated() ignores passed in value !!!"
+       DEBUG->print("ApplicationWindow::slotWindowActivated begin");
 
 //the following does: return (MDIWindow *)workspace->activeSubWindow();
 //which means the subwindow is NOT being activated!!!
-       MDIWindow * m = getMDIWindow();
-       RS_DEBUG->print(/*RS_Debug::D_CRITICAL,*/ "ApplicationWindow::slotWindowActivated m=%08X", m);
-
-       if (m)
-               RS_DEBUG->print(/*RS_Debug::D_CRITICAL,*/ "ApplicationWindow::slotWindowActivated m->getDoc=%08X", m->getDocument());
+//     MDIWindow * m = getMDIWindow();
+       MDIWindow * m = (MDIWindow *)sw;
+//     MDIWindow * m = (MDIWindow *)(sw->widget());
+       DEBUG->print(/*Debug::D_CRITICAL,*/ "ApplicationWindow::slotWindowActivated m=%08X", m);
+       DEBUG->print(/*Debug::D_CRITICAL,*/ "ApplicationWindow::slotWindowActivated m->getDoc=%08X",
+               (m ? m->getDocument() : 0));
 
        if (m && m->getDocument())
        {
                //m->setWindowState(WindowMaximized);
 
-               RS_DEBUG->print("ApplicationWindow::slotWindowActivated: document: %d", m->getDocument()->getId());
+               DEBUG->print("ApplicationWindow::slotWindowActivated: document: %d", m->getDocument()->getId());
 
                bool showByBlock = m->getDocument()->rtti() == RS2::EntityBlock;
                layerWidget->setLayerList(m->getDocument()->getLayerList(), showByBlock);
-               coordinateWidget->setGraphic(m->getGraphic());
+               coordinateWidget->setGraphic(m->GetDrawing());
 
 #ifdef RS_CAM
                simulationControls->setGraphicView(m->getGraphicView());
 #endif
 
                // Only graphics show blocks. (blocks don't)
-               if (m->getDocument()->rtti() == RS2::EntityGraphic)
-                       blockWidget->setBlockList(m->getDocument()->getBlockList());
-               else
-                       blockWidget->setBlockList(NULL);
+//             if (m->getDocument()->rtti() == RS2::EntityDrawing)
+//                     blockWidget->setBlockList(m->getDocument()->getBlockList());
+//             else
+//                     blockWidget->setBlockList(NULL);
+               blockWidget->setBlockList(m->getDocument()->rtti() == RS2::EntityDrawing
+                       ? m->getDocument()->getBlockList() : NULL);
 
                // Update all inserts in this graphic (blocks might have changed):
                m->getDocument()->updateInserts();
@@ -1664,19 +1506,37 @@ void ApplicationWindow::slotWindowActivated(QMdiSubWindow * /*w*/)
                slotPenChanged(penToolBar->getPen());
 
                // update toggle button status:
-               if (m->getGraphic())
+               if (m->GetDrawing())
                {
-                       emit(gridChanged(m->getGraphic()->isGridOn()));
-                       emit(printPreviewChanged(m->getGraphicView()->isPrintPreview()));
+//This is odd... why do this when you can just call the function directly? It's
+//IN this class after all...
+//                     emit(gridChanged(m->GetDrawing()->isGridOn()));
+//                     emit(printPreviewChanged(m->getGraphicView()->isPrintPreview()));
+                       actionViewGrid->setChecked(m->GetDrawing()->isGridOn());
+                       actionFilePrintPreview->setChecked(m->getGraphicView()->isPrintPreview());
                }
        }
 
+//This works, but for some reason after this function is over, the subwindow is no
+//longer activated. Need to find out why.
+//OK, I can see that the workspace isn't getting this window as activated or current.
+//Which means that something is definitely wrong here...
+
 //Seems to work now.
 //#warning "This is failing... !!! FIX !!!"
+printf("slotWindowActivated(QMdiSubWindow *): m=%08X, m->getDocument()=%08X...\n", (uint)m, (uint)(m ? m->getDocument() : 0));
+printf("slotWindowActivated(QMdiSubWindow *): activeWindow=%08X...\n", (uint)workspace->activeSubWindow());
+printf("slotWindowActivated(QMdiSubWindow *): currentWindow=%08X...\n", (uint)workspace->currentSubWindow());
+// slotWindowActivated(QMdiSubWindow * /*w*/): m=00000000, m->getDocument()=00000000...
+
        // Disable/Enable menu and toolbar items
-       emit windowsChanged(m != NULL && m->getDocument() != NULL);
+//This is odd... why do this when you can just call the function directly? It's
+//IN this class after all...
+//In this case it makes a little sense, as the signal is connected to all the actions'
+//setEnabled() function calls.
+       emit(windowsChanged(m != NULL && m->getDocument() != NULL));
 
-       RS_DEBUG->print("ApplicationWindow::slotWindowActivated end");
+       DEBUG->print("ApplicationWindow::slotWindowActivated end");
 }
 
 /**
@@ -1685,7 +1545,7 @@ void ApplicationWindow::slotWindowActivated(QMdiSubWindow * /*w*/)
  */
 void ApplicationWindow::slotWindowsMenuAboutToShow()
 {
-       RS_DEBUG->print("ApplicationWindow::slotWindowsMenuAboutToShow");
+       DEBUG->print("ApplicationWindow::slotWindowsMenuAboutToShow");
 
        windowsMenu->clear();
 #if 0
@@ -1705,11 +1565,14 @@ void ApplicationWindow::slotWindowsMenuAboutToShow()
 #warning "!!! Qt4 implementation of insertItem is vastly different from Qt3--FIX !!!"
 #endif
        QList<QMdiSubWindow *> windows = workspace->subWindowList();
+//printf("ApplicationWindow::slotWindowsMenuAboutToShow(): workspace->activeSubWindow = %08X\n", workspace->activeSubWindow());
+//printf("ApplicationWindow::slotWindowsMenuAboutToShow(): workspace->currentSubWindow = %08X\n", workspace->currentSubWindow());
 
 //#warning "Need to add window numbers underlined so can access windows via keyboard. !!! FIX !!!"
 //[DONE]
-       for(int i=0; i<int(windows.count()); ++i)
+       for(int i=0; i<int(windows.count()); i++)
        {
+//printf("--> Windows.at(i) = %08X\n", windows.at(i));
 //             int id = windowsMenu->insertItem(windows.at(i)->caption(), this, SLOT(slotWindowsMenuActivated(int)));
 //For some reason the triggered() signal created here is type bool... Dunno why...
 //It's signalling using the QAction signal, which is type bool (checked or not).
@@ -1719,7 +1582,9 @@ void ApplicationWindow::slotWindowsMenuAboutToShow()
                QAction * action = new QAction(actionName, this);
                action->setCheckable(true);
                action->setData(i);
-               action->setChecked(workspace->activeSubWindow() == windows.at(i));
+//Neither of these work...
+//             action->setChecked(workspace->activeSubWindow() == windows.at(i));
+               action->setChecked(workspace->currentSubWindow() == windows.at(i));
                windowsMenu->addAction(action);
                connect(windowsMenu, SIGNAL(triggered(QAction *)), this, SLOT(slotWindowsMenuActivated(QAction *)));
 //     connect(blockWidget, SIGNAL(escape()), this, SLOT(slotFocus()));
@@ -1742,14 +1607,17 @@ void ApplicationWindow::slotWindowsMenuAboutToShow()
  */
 void ApplicationWindow::slotWindowsMenuActivated(QAction * id)
 {
-       RS_DEBUG->print("ApplicationWindow::slotWindowsMenuActivated");
+       DEBUG->print("ApplicationWindow::slotWindowsMenuActivated");
 
 //     QMdiSubWindow * w = workspace->subWindowList().at(id);
        QMdiSubWindow * w = workspace->subWindowList().at(id->data().toInt());
+printf("ApplicationWindow::slotWindowsMenuActivated: QMdiSubWindow * w = %08X\n", (uint32_t)w);
 
        if (w != NULL)
-               w->showMaximized();
+               workspace->setActiveSubWindow(w);
+//             w->showMaximized();
 //             w->setFocus();
+printf("--> w is%s activated (activeSW=%08X)\n", (workspace->activeSubWindow() ? "" : " NOT"), (uint32_t)(workspace->activeSubWindow()));
 }
 
 /**
@@ -1757,7 +1625,7 @@ void ApplicationWindow::slotWindowsMenuActivated(QAction * id)
  */
 void ApplicationWindow::slotTileHorizontal()
 {
-       RS_DEBUG->print("ApplicationWindow::slotTileHorizontal");
+       DEBUG->print("ApplicationWindow::slotTileHorizontal");
 
 #if 0
        // primitive horizontal tiling
@@ -1843,7 +1711,7 @@ void ApplicationWindow::slotTileVertical()
 void ApplicationWindow::slotCamExportAuto() {
     printf("CAM export..\n");
 
-    RS_Document* d = getDocument();
+    Document* d = getDocument();
     if (d!=NULL) {
         Drawing* graphic = (Drawing*)d;
 
@@ -1855,36 +1723,36 @@ void ApplicationWindow::slotCamExportAuto() {
 */
 
 /**
- * Called when something changed in the pen tool bar
- * (e.g. color, width, style).
+ * Called when something changed in the pen tool bar (e.g. color, width,
+ * style).
  */
-void ApplicationWindow::slotPenChanged(RS_Pen pen)
+void ApplicationWindow::slotPenChanged(Pen pen)
 {
-       RS_DEBUG->print("ApplicationWindow::slotPenChanged() begin");
-       RS_DEBUG->print("Setting active pen...");
+       DEBUG->print("ApplicationWindow::slotPenChanged() begin");
+       DEBUG->print("Setting active pen...");
        MDIWindow * m = getMDIWindow();
 
        if (m != NULL)
                m->slotPenChanged(pen);
 
-       RS_DEBUG->print("ApplicationWindow::slotPenChanged() end");
+       DEBUG->print("ApplicationWindow::slotPenChanged() end");
 }
 
 /**
- * Creates a new MDI window with the given document or a new
- *  document if 'doc' is NULL.
+ * Creates a new MDI window with the given document or a new document if 'doc'
+ * is NULL.
  */
-MDIWindow * ApplicationWindow::slotFileNew(RS_Document * doc)
+MDIWindow * ApplicationWindow::slotFileNew(Document * doc/*= NULL*/)
 {
-       RS_DEBUG->print("ApplicationWindow::slotFileNew() begin");
+       DEBUG->print("ApplicationWindow::slotFileNew() begin");
 
        static int id = 0;
        id++;
 
        statusBar()->showMessage(tr("Creating new file..."));
 
-#warning "QWidget::setMinimumSize: (/QMdi::ControlLabel) Negative sizes (-1,-1) are not possible"
-       RS_DEBUG->print("  creating MDI window");
+//#warning "QWidget::setMinimumSize: (/QMdi::ControlLabel) Negative sizes (-1,-1) are not possible"
+       DEBUG->print("  creating MDI window");
 //     MDIWindow * w = new MDIWindow(doc, workspace, 0, Qt::WA_DeleteOnClose);
        MDIWindow * w = new MDIWindow(doc, workspace, 0, Qt::SubWindow);
        w->setAttribute(Qt::WA_DeleteOnClose);
@@ -1892,21 +1760,17 @@ MDIWindow * ApplicationWindow::slotFileNew(RS_Document * doc)
        connect(w, SIGNAL(signalClosing()), this, SLOT(slotFileClosing()));
 
        if (w->getDocument()->rtti() == RS2::EntityBlock)
-//             w->setCaption(tr("Block '%1'").arg(((RS_Block *)(w->getDocument()))->getName()));
-               w->setWindowTitle(tr("Block '%1'").arg(((RS_Block *)(w->getDocument()))->getName()));
+               w->setWindowTitle(tr("Block '%1'").arg(((Block *)(w->getDocument()))->getName()));
        else
-//             w->setCaption(tr("unnamed document %1").arg(id));
-               w->setWindowTitle(tr("unnamed document %1").arg(id));
+               w->setWindowTitle(tr("Untitled Document %1").arg(id));
 
-//     w->setIcon(qPixmapFromMimeSource("document.png"));
-//     w->setWindowIcon(qPixmapFromMimeSource("document.png"));
        w->setWindowIcon(QIcon(":/res/document.png"));
 
+#if 0
        // only graphics offer block lists, blocks don't
-       RS_DEBUG->print("  adding listeners");
+       DEBUG->print("  adding listeners");
        Drawing * graphic = w->getDocument()->getGraphic();
 
-#if 0
        if (graphic != NULL)
        {
                // Link the graphic's layer list to the pen tool bar
@@ -1933,12 +1797,13 @@ MDIWindow * ApplicationWindow::slotFileNew(RS_Document * doc)
        QG_DIALOGFACTORY->setMainWindow(this);
 
 #if 1 //bugfix for Qt3->4 conversion
-       RS_DEBUG->print(/*RS_Debug::D_CRITICAL,*/ "ApplicationWindow::slotFileNew: adding window to workspace...");
+       DEBUG->print(/*Debug::D_CRITICAL,*/ "ApplicationWindow::slotFileNew: adding window to workspace...");
 //     workspace->addWindow(w);
-       workspace->addSubWindow(w);
+       QMdiSubWindow * sw = workspace->addSubWindow(w);
+printf("MDIWindow=%08X, QMdiSubWindow=%08X\n", (uint)w, (uint)sw);
 #endif
 
-       RS_DEBUG->print("  showing MDI window");
+       DEBUG->print("  showing MDI window");
 
 #if 0
 #warning "w->showMaximized() doesn't seem to do anything here..."
@@ -1955,13 +1820,25 @@ MDIWindow * ApplicationWindow::slotFileNew(RS_Document * doc)
 //     w->setFocus();
 //printf("--> ApplicationWindow::slotFileNew(): w %s focus...\n", (w->hasFocus() ? "has" : "DOES NOT HAVE"));
 #endif
-
-#warning "!!! Parameter to slotWindowActivated() is ignored !!!"
-       slotWindowActivated(w);
+//neither of these work either
+//w->activateWindow();
+//w->setFocus();
+//w->activateWindow();
+//w->raise();
+//will wok?
+/*printf("FileNew: Setting active subwindow... (w=%08X)\n", (uint)w);
+workspace->setActiveSubWindow(w);
+printf("FileNew: Workspace active window = %08X\n", (uint)(workspace->activeSubWindow()));
+//*/
+
+//not anymore... #warning "!!! Parameter to slotWindowActivated() is ignored !!!"
+//Hm, this should be called when the window is actually activated by the QMdiArea...
+//Not sure why this isn't happening...
+//     slotWindowActivated(w);
        statusBar()->showMessage(tr("New Drawing created."), 2000);
 
-       RS_DEBUG->print("ApplicationWindow::slotFileNew() OK");
-       setFocus();
+       DEBUG->print("ApplicationWindow::slotFileNew() OK");
+//     setFocus();
 
        return w;
 }
@@ -1971,15 +1848,15 @@ MDIWindow * ApplicationWindow::slotFileNew(RS_Document * doc)
  */
 void ApplicationWindow::slotFileOpen()
 {
-       RS_DEBUG->print("ApplicationWindow::slotFileOpen()");
+       DEBUG->print("ApplicationWindow::slotFileOpen()");
 
-       RS_DEBUG->print("ApplicationWindow::slotFileOpen() 001");
+       DEBUG->print("ApplicationWindow::slotFileOpen() 001");
        RS2::FormatType type = RS2::FormatUnknown;
-       RS_DEBUG->print("ApplicationWindow::slotFileOpen() 002");
+       DEBUG->print("ApplicationWindow::slotFileOpen() 002");
        QString fileName = FileDialog::getOpenFileName(this, &type);
-       RS_DEBUG->print("ApplicationWindow::slotFileOpen() 003");
+       DEBUG->print("ApplicationWindow::slotFileOpen() 003");
        slotFileOpen(fileName, type);
-       RS_DEBUG->print("ApplicationWindow::slotFileOpen(): OK");
+       DEBUG->print("ApplicationWindow::slotFileOpen(): OK");
 }
 
 /**
@@ -1989,7 +1866,7 @@ void ApplicationWindow::slotFileOpen()
 void ApplicationWindow::slotFileOpenRecent(void)
 {
 #if 0
-       RS_DEBUG->print("ApplicationWindow::slotFileOpenRecent()");
+       DEBUG->print("ApplicationWindow::slotFileOpenRecent()");
 
        statusBar()->showMessage(tr("Opening recent file..."));
        QString fileName = recentFiles->get(id);
@@ -2020,26 +1897,26 @@ void ApplicationWindow::slotFileOpenRecent(void)
  */
 void ApplicationWindow::slotFileOpen(const QString & fileName, RS2::FormatType type)
 {
-       RS_DEBUG->print("ApplicationWindow::slotFileOpen(..)");
+       DEBUG->print("ApplicationWindow::slotFileOpen(..)");
        QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
 
        if (!fileName.isEmpty())
        {
-               RS_DEBUG->print("ApplicationWindow::slotFileOpen: creating new doc window");
+               DEBUG->print("ApplicationWindow::slotFileOpen: creating new doc window");
                // Create new document window:
                MDIWindow * w = slotFileNew();
-               RS_DEBUG->print("ApplicationWindow::slotFileOpen: linking layer list");
+               DEBUG->print("ApplicationWindow::slotFileOpen: linking layer list");
                // link the layer widget to the new document:
                layerWidget->setLayerList(w->getDocument()->getLayerList(), false);
                // link the block widget to the new document:
                blockWidget->setBlockList(w->getDocument()->getBlockList());
                // link coordinate widget to graphic
-               coordinateWidget->setGraphic(w->getGraphic());
+               coordinateWidget->setGraphic(w->GetDrawing());
 #ifdef RS_CAM
                // link the layer widget to the new document:
                simulationControls->setGraphicView(w->getGraphicView());
 #endif
-               RS_DEBUG->print("ApplicationWindow::slotFileOpen: open file");
+               DEBUG->print("ApplicationWindow::slotFileOpen: open file");
 
                // Open the file in the new view:
                if (!w->slotFileOpen(fileName, type))
@@ -2048,13 +1925,13 @@ void ApplicationWindow::slotFileOpen(const QString & fileName, RS2::FormatType t
                        QApplication::restoreOverrideCursor();
                        QMessageBox::information(this, QMessageBox::tr("Warning"),
                                tr("Cannot open the file\n%1\nPlease check the permissions.") .arg(fileName), QMessageBox::Ok);
-                       w->setForceClosing(true);
+//                     w->setForceClosing(true);
                        w->close();
                        return;
                }
 
-               RS_DEBUG->print("ApplicationWindow::slotFileOpen: open file: OK");
-               RS_DEBUG->print("ApplicationWindow::slotFileOpen: update recent file menu: 1");
+               DEBUG->print("ApplicationWindow::slotFileOpen: open file: OK");
+               DEBUG->print("ApplicationWindow::slotFileOpen: update recent file menu: 1");
 
                // update recent files menu:
                if (type == RS2::FormatDXF1)
@@ -2062,17 +1939,17 @@ void ApplicationWindow::slotFileOpen(const QString & fileName, RS2::FormatType t
                else
                        recentFiles->add(fileName);
 
-               RS_DEBUG->print("ApplicationWindow::slotFileOpen: update recent file menu: 2");
+               DEBUG->print("ApplicationWindow::slotFileOpen: update recent file menu: 2");
                recentFiles->UpdateGUI();
-               RS_DEBUG->print("ApplicationWindow::slotFileOpen: update recent file menu: OK");
-               RS_DEBUG->print("ApplicationWindow::slotFileOpen: set caption");
+               DEBUG->print("ApplicationWindow::slotFileOpen: update recent file menu: OK");
+               DEBUG->print("ApplicationWindow::slotFileOpen: set caption");
                // update caption:
                w->setWindowTitle(fileName);
-               RS_DEBUG->print("ApplicationWindow::slotFileOpen: set caption: OK");
-               RS_DEBUG->print("ApplicationWindow::slotFileOpen: update coordinate widget");
+               DEBUG->print("ApplicationWindow::slotFileOpen: set caption: OK");
+               DEBUG->print("ApplicationWindow::slotFileOpen: update coordinate widget");
                // update coordinate widget format:
-               RS_DIALOGFACTORY->updateCoordinateWidget(Vector(0.0, 0.0), Vector(0.0, 0.0), true);
-               RS_DEBUG->print("ApplicationWindow::slotFileOpen: update coordinate widget: OK");
+               DIALOGFACTORY->updateCoordinateWidget(Vector(0.0, 0.0), Vector(0.0, 0.0), true);
+               DEBUG->print("ApplicationWindow::slotFileOpen: update coordinate widget: OK");
                // Update the layer and block widgets (document just loaded may have some)
                layerWidget->update();
                blockWidget->update();
@@ -2087,7 +1964,7 @@ void ApplicationWindow::slotFileOpen(const QString & fileName, RS2::FormatType t
        }
 
        QApplication::restoreOverrideCursor();
-       RS_DEBUG->print("ApplicationWindow::slotFileOpen(..) OK");
+       DEBUG->print("ApplicationWindow::slotFileOpen(..) OK");
 }
 
 /**
@@ -2095,7 +1972,7 @@ void ApplicationWindow::slotFileOpen(const QString & fileName, RS2::FormatType t
  */
 void ApplicationWindow::slotFileSave()
 {
-       RS_DEBUG->print("ApplicationWindow::slotFileSave()");
+       DEBUG->print("ApplicationWindow::slotFileSave()");
 
        statusBar()->showMessage(tr("Saving drawing..."));
 
@@ -2134,7 +2011,7 @@ void ApplicationWindow::slotFileSave()
  */
 void ApplicationWindow::slotFileSaveAs()
 {
-       RS_DEBUG->print("ApplicationWindow::slotFileSaveAs()");
+       DEBUG->print("ApplicationWindow::slotFileSaveAs()");
 
        statusBar()->showMessage(tr("Saving drawing under new filename..."));
 
@@ -2176,7 +2053,7 @@ void ApplicationWindow::slotFileSaveAs()
  */
 void ApplicationWindow::slotFileExport()
 {
-       RS_DEBUG->print("ApplicationWindow::slotFileExport()");
+       DEBUG->print("ApplicationWindow::slotFileExport()");
        statusBar()->showMessage(tr("Exporting drawing..."));
        MDIWindow * w = getMDIWindow();
 
@@ -2185,7 +2062,7 @@ void ApplicationWindow::slotFileExport()
                QString fn;
                // read default settings:
                settings.beginGroup("Paths");
-               QString defDir = settings.value("ExportImage", RS_SYSTEM->getHomeDir()).toString();
+               QString defDir = settings.value("ExportImage", SYSTEM->getHomeDir()).toString();
                QString defFilter = settings.value("ExportImageFilter", "Portable Network Graphic (*.png)").toString();
                settings.endGroup();
 
@@ -2280,7 +2157,7 @@ void ApplicationWindow::slotFileExport()
 
                        // show options dialog:
                        ImageOptionsDialog dlg(this);
-                       dlg.setGraphicSize(w->getGraphic()->getSize());
+                       dlg.setGraphicSize(w->GetDrawing()->getSize());
 
                        if (dlg.exec())
                        {
@@ -2312,15 +2189,15 @@ bool ApplicationWindow::slotFileExport(const QString & name, const QString & for
 
        if (!w)
        {
-               RS_DEBUG->print(RS_Debug::D_WARNING, "ApplicationWindow::slotFileExport: no window opened");
+               DEBUG->print(Debug::D_WARNING, "ApplicationWindow::slotFileExport: no window opened");
                return false;
        }
 
-       Drawing * graphic = w->getDocument()->getGraphic();
+       Drawing * drawing = w->getDocument()->GetDrawing();
 
-       if (!graphic)
+       if (!drawing)
        {
-               RS_DEBUG->print(RS_Debug::D_WARNING, "ApplicationWindow::slotFileExport: no graphic");
+               DEBUG->print(Debug::D_WARNING, "ApplicationWindow::slotFileExport: no drawing");
                return false;
        }
 
@@ -2335,13 +2212,13 @@ bool ApplicationWindow::slotFileExport(const QString & name, const QString & for
 
        // black background:
        if (black)
-//             painter->setBackgroundColor(RS_Color(0, 0, 0));
-//             qpntr.setBackgroundColor(RS_Color(0, 0, 0));
+//             painter->setBackgroundColor(Color(0, 0, 0));
+//             qpntr.setBackgroundColor(Color(0, 0, 0));
                qpntr.setBackground(QBrush(QColor(0, 0, 0)));
        // white background:
        else
-//             painter->setBackgroundColor(RS_Color(255, 255, 255));
-//             qpntr.setBackgroundColor(RS_Color(255, 255, 255));
+//             painter->setBackgroundColor(Color(255, 255, 255));
+//             qpntr.setBackgroundColor(Color(255, 255, 255));
                qpntr.setBackground(QBrush(QColor(255, 255, 255)));
 
        // black/white:
@@ -2351,16 +2228,16 @@ bool ApplicationWindow::slotFileExport(const QString & name, const QString & for
 //     painter->eraseRect(0, 0, size.width(), size.height());
        qpntr.eraseRect(0, 0, size.width(), size.height());
 
-       RS_StaticGraphicView gv(size.width(), size.height(), painter);
+       StaticGraphicView gv(size.width(), size.height(), painter);
 
        if (black)
-               gv.setBackground(RS_Color(0, 0, 0));
+               gv.setBackground(Color(0, 0, 0));
        else
-               gv.setBackground(RS_Color(255, 255, 255));
+               gv.setBackground(Color(255, 255, 255));
 
-       gv.setContainer(graphic);
+       gv.setContainer(drawing);
        gv.zoomAuto(false);
-       gv.drawEntity(graphic, true);
+       gv.drawEntity(drawing, true);
 
 #if 0
        QImageIO iio;
@@ -2375,14 +2252,20 @@ bool ApplicationWindow::slotFileExport(const QString & name, const QString & for
                ret = true;
        }
 #else
-#warning "ApplicationWindow::slotFileExport(): Need to port to Qt4... !!! FIX !!!"
+//#warning "ApplicationWindow::slotFileExport(): Need to port to Qt4... !!! FIX !!!"
+//     QImage image = buffer->toImage();
+//     QImageWriter writer;
+//     writer.setFileName(name);
+//     writer.setFormat(format.toAscii().data());
+       QImageWriter writer(name, format.toAscii().data());
+
+//     if (writer.write(image))
+       if (writer.write(buffer->toImage()))
+               ret = true;
 #endif
 
        QApplication::restoreOverrideCursor();
 
-       // GraphicView deletes painter
-//     painter->end();
-       //no, it doesn't
        delete painter;
        delete buffer;
 
@@ -2399,7 +2282,7 @@ bool ApplicationWindow::slotFileExport(const QString & name, const QString & for
  */
 void ApplicationWindow::slotFileClose()
 {
-       RS_DEBUG->print("ApplicationWindow::slotFileClose()");
+       DEBUG->print("ApplicationWindow::slotFileClose()");
 
        MDIWindow * m = getMDIWindow();
 
@@ -2422,9 +2305,9 @@ void ApplicationWindow::slotFileClose()
  */
 void ApplicationWindow::slotFileClosing()
 {
-       RS_DEBUG->print("ApplicationWindow::slotFileClosing()");
+       DEBUG->print("ApplicationWindow::slotFileClosing()");
 
-       RS_DEBUG->print("detaching lists");
+       DEBUG->print("detaching lists");
        layerWidget->setLayerList(NULL, false);
        blockWidget->setBlockList(NULL);
        coordinateWidget->setGraphic(NULL);
@@ -2438,28 +2321,28 @@ void ApplicationWindow::slotFileClosing()
  */
 void ApplicationWindow::slotFilePrint()
 {
-       RS_DEBUG->print("ApplicationWindow::slotFilePrint()");
+       DEBUG->print("ApplicationWindow::slotFilePrint()");
 
        MDIWindow * w = getMDIWindow();
 
        if (w == NULL)
        {
-               RS_DEBUG->print(RS_Debug::D_WARNING, "ApplicationWindow::slotFilePrint: no window opened");
+               DEBUG->print(Debug::D_WARNING, "ApplicationWindow::slotFilePrint: no window opened");
                return;
        }
 
-       Drawing * graphic = w->getDocument()->getGraphic();
+       Drawing * drawing = w->getDocument()->GetDrawing();
 
-       if (graphic == NULL)
+       if (drawing == NULL)
        {
-               RS_DEBUG->print(RS_Debug::D_WARNING, "ApplicationWindow::slotFilePrint: no graphic");
+               DEBUG->print(Debug::D_WARNING, "ApplicationWindow::slotFilePrint: no drawing");
                return;
        }
 
        statusBar()->showMessage(tr("Printing..."));
        QPrinter * printer = new QPrinter(QPrinter::HighResolution);
        bool landscape = false;
-       printer->setPageSize(RS2::rsToQtPaperFormat(graphic->getPaperFormat(&landscape)));
+       printer->setPageSize(RS2::rsToQtPaperFormat(drawing->getPaperFormat(&landscape)));
 
        if (landscape)
                printer->setOrientation(QPrinter::Landscape);
@@ -2492,27 +2375,24 @@ void ApplicationWindow::slotFilePrint()
                PaintInterface * painter = new PaintInterface(&qpntr);
                painter->setDrawingMode(w->getGraphicView()->getDrawingMode());
 
-//             RS_StaticGraphicView gv(metr.width(), metr.height(), painter);
-               RS_StaticGraphicView gv(printer->width(), printer->height(), painter);
+//             StaticGraphicView gv(metr.width(), metr.height(), painter);
+               StaticGraphicView gv(printer->width(), printer->height(), painter);
                gv.setPrinting(true);
                gv.setBorders(0, 0, 0, 0);
 
-//             double fx = (double)metr.width() / metr.widthMM() * RS_Units::getFactorToMM(graphic->getUnit());
-//             double fy = (double)metr.height() / metr.heightMM() * RS_Units::getFactorToMM(graphic->getUnit());
-               double fx = (double)printer->width() / printer->widthMM() * RS_Units::getFactorToMM(graphic->getUnit());
-               double fy = (double)printer->height() / printer->heightMM() * RS_Units::getFactorToMM(graphic->getUnit());
+//             double fx = (double)metr.width() / metr.widthMM() * Units::getFactorToMM(graphic->getUnit());
+//             double fy = (double)metr.height() / metr.heightMM() * Units::getFactorToMM(graphic->getUnit());
+               double fx = (double)printer->width() / printer->widthMM() * Units::getFactorToMM(drawing->getUnit());
+               double fy = (double)printer->height() / printer->heightMM() * Units::getFactorToMM(drawing->getUnit());
                double f = (fx + fy) / 2;
-               double scale = graphic->getPaperScale();
+               double scale = drawing->getPaperScale();
 
-               gv.setOffset((int)(graphic->getPaperInsertionBase().x * f),
-                       (int)(graphic->getPaperInsertionBase().y * f));
+               gv.setOffset((int)(drawing->getPaperInsertionBase().x * f),
+                       (int)(drawing->getPaperInsertionBase().y * f));
                gv.setFactor(f * scale);
-               gv.setContainer(graphic);
-               gv.drawEntity(graphic, true);
+               gv.setContainer(drawing);
+               gv.drawEntity(drawing, true);
 
-               // GraphicView deletes painter
-//             painter->end();
-               //no
                delete painter;
 
                settings.beginGroup("Print");
@@ -2534,29 +2414,29 @@ void ApplicationWindow::slotFilePrint()
  */
 void ApplicationWindow::slotFilePrintPreview(bool on)
 {
-       RS_DEBUG->print("ApplicationWindow::slotFilePrintPreview()");
+       DEBUG->print("ApplicationWindow::slotFilePrintPreview()");
 
-       RS_DEBUG->print("  creating MDI window");
+       DEBUG->print("  creating MDI window");
        MDIWindow * parent = getMDIWindow();
 
        if (!parent)
        {
-               RS_DEBUG->print(RS_Debug::D_WARNING, "ApplicationWindow::slotFilePrintPreview: no window opened");
+               DEBUG->print(Debug::D_WARNING, "ApplicationWindow::slotFilePrintPreview: no window opened");
                return;
        }
 
-       // close print preview:
+       // Close print preview:
        if (!on)
        {
-               RS_DEBUG->print("ApplicationWindow::slotFilePrintPreview(): off");
+               DEBUG->print("ApplicationWindow::slotFilePrintPreview(): off");
 
                if (parent->getGraphicView()->isPrintPreview())
                {
-                       RS_DEBUG->print("ApplicationWindow::slotFilePrintPreview(): close");
+                       DEBUG->print("ApplicationWindow::slotFilePrintPreview(): close");
                        slotFileClose();
                }
        }
-       // open print preview:
+       // Open print preview:
        else
        {
                // look for an existing print preview:
@@ -2564,7 +2444,7 @@ void ApplicationWindow::slotFilePrintPreview(bool on)
 
                if (ppv != NULL)
                {
-                       RS_DEBUG->print("ApplicationWindow::slotFilePrintPreview(): show existing");
+                       DEBUG->print("ApplicationWindow::slotFilePrintPreview(): show existing");
                        slotWindowActivated(ppv);
                        ppv->showNormal();
                }
@@ -2572,13 +2452,11 @@ void ApplicationWindow::slotFilePrintPreview(bool on)
                {
                        if (!parent->getGraphicView()->isPrintPreview())
                        {
-                               RS_DEBUG->print("ApplicationWindow::slotFilePrintPreview(): create");
+                               DEBUG->print("ApplicationWindow::slotFilePrintPreview(): create");
 
                                MDIWindow * w = new MDIWindow(parent->getDocument(), workspace, 0, Qt::SubWindow);
                                w->setAttribute(Qt::WA_DeleteOnClose);
                                parent->addChildWindow(w);
-                               //connect(w, SIGNAL(signalClosing()),
-                               //        this, SLOT(slotFileClosing()));
 
 //                             w->setCaption(tr("Print preview for %1").arg(parent->caption()));
                                w->setWindowTitle(tr("Print preview for %1").arg(parent->windowTitle()));
@@ -2586,25 +2464,17 @@ void ApplicationWindow::slotFilePrintPreview(bool on)
 //                             w->setWindowIcon(qPixmapFromMimeSource("document.png"));
                                w->setWindowIcon(QIcon(":/res/document.png"));
                                w->getGraphicView()->setPrintPreview(true);
-                               w->getGraphicView()->setBackground(RS_Color(255, 255, 255));
+                               w->getGraphicView()->setBackground(Color(255, 255, 255));
                                w->getGraphicView()->setDefaultAction(new ActionPrintPreview(*w->getDocument(), *w->getGraphicView()));
 
-                               // only graphics offer block lists, blocks don't
-                               RS_DEBUG->print("  adding listeners");
-                               Drawing * graphic = w->getDocument()->getGraphic();
+                               // Only drawings offer block lists; blocks themselves don't
+//                             DEBUG->print("  adding listeners");
+                               Drawing * drawing = w->getDocument()->GetDrawing();
 
-                               if (graphic)
+                               if (drawing)
                                {
-#if 0
-                                       // Link the layer list to the pen tool bar
-                                       graphic->addLayerListListener(penToolBar);
-                                       // Link the layer list to the layer widget
-                                       graphic->addLayerListListener(layerWidget);
-                                       // Link the block list to the block widget
-                                       graphic->addBlockListListener(blockWidget);
-#endif
                                        // Center by default:
-                                       graphic->centerToPage();
+                                       drawing->centerToPage();
                                }
 
                                // Link the graphic view to the mouse widget:
@@ -2619,7 +2489,7 @@ void ApplicationWindow::slotFilePrintPreview(bool on)
                                // Link the graphic view to the command widget:
                                QG_DIALOGFACTORY->setCommandWidget(commandWidget);
 
-                               RS_DEBUG->print("  showing MDI window");
+                               DEBUG->print("  showing MDI window");
 
                                if (workspace->subWindowList().isEmpty())
                                        w->showMaximized();
@@ -2640,68 +2510,47 @@ void ApplicationWindow::slotFilePrintPreview(bool on)
  */
 void ApplicationWindow::slotFileQuit()
 {
-       RS_DEBUG->print("ApplicationWindow::slotFileQuit()");
+       DEBUG->print("ApplicationWindow::slotFileQuit()");
 
        statusBar()->showMessage(tr("Exiting application..."));
 
-       if (queryExit(false))
+       if (QueryExit())
                qApp->exit(0);
 }
 
-#if 0
 /**
- * Forces termination of QCad (demo version).
- */
-void ApplicationWindow::slotFileDemoQuit()
-{
-       statusBar()->showMessage(tr("Exiting application..."));
-
-       queryExit(true);
-       qApp->exit(0);
-}
-#endif
-
-/**
- * Shows / hides the grid.
+ * Shows/hides the grid.
  *
  * @param toggle true: show, false: hide.
  */
 void ApplicationWindow::slotViewGrid(bool toggle)
 {
-       RS_DEBUG->print("ApplicationWindow::slotViewGrid()");
+       DEBUG->print("ApplicationWindow::slotViewGrid()");
 
        MDIWindow * m = getMDIWindow();
 
        if (m != NULL)
        {
-               Drawing * g = m->getGraphic();
+               Drawing * d = m->GetDrawing();
 
-               if (g != NULL)
-                       g->setGridOn(toggle);
+               if (d != NULL)
+                       d->setGridOn(toggle);
        }
 
        updateGrids();
        redrawAll();
 
-       RS_DEBUG->print("ApplicationWindow::slotViewGrid() OK");
+       DEBUG->print("ApplicationWindow::slotViewGrid() OK");
 }
 
 /**
- * Enables / disables the draft mode.
+ * Enables/disables draft mode.
  *
  * @param toggle true: enable, false: disable.
  */
 void ApplicationWindow::slotViewDraft(bool toggle)
 {
-       RS_DEBUG->print("ApplicationWindow::slotViewDraft()");
-
-    /*MDIWindow* m = getMDIWindow();
-    if (m!=NULL) {
-        Drawing* g = m->getGraphic();
-        if (g!=NULL) {
-            g->setDraftOn(toggle);
-        }
-}*/
+       DEBUG->print("ApplicationWindow::slotViewDraft()");
 
        settings.beginGroup("Appearance");
        settings.setValue("DraftMode", toggle);
@@ -2711,26 +2560,21 @@ void ApplicationWindow::slotViewDraft(bool toggle)
 }
 
 /**
- * Redraws all mdi windows.
+ * Redraws all MDI windows.
  */
 void ApplicationWindow::redrawAll()
 {
-       if (workspace)
-       {
-               QList<QMdiSubWindow *> windows = workspace->subWindowList();
+       if (workspace == NULL)
+               return;
 
-               for(int i=0; i<int(windows.count()); ++i)
-               {
-                       MDIWindow * m = (MDIWindow *)windows.at(i);
+       QList<QMdiSubWindow *> windows = workspace->subWindowList();
 
-                       if (m)
-                       {
-                               QG_GraphicView * gv = m->getGraphicView();
+       for(int i=0; i<windows.count(); i++)
+       {
+               QG_GraphicView * gv = ((MDIWindow *)windows.at(i))->getGraphicView();
 
-                               if (gv)
-                                       gv->redraw();
-                       }
-               }
+               if (gv)
+                       gv->redraw();
        }
 }
 
@@ -2739,22 +2583,17 @@ void ApplicationWindow::redrawAll()
  */
 void ApplicationWindow::updateGrids()
 {
-       if (workspace)
-       {
-               QList<QMdiSubWindow *> windows = workspace->subWindowList();
+       if (workspace == NULL)
+               return;
 
-               for(int i=0; i<int(windows.count()); ++i)
-               {
-                       MDIWindow * m = (MDIWindow *)windows.at(i);
+       QList<QMdiSubWindow *> windows = workspace->subWindowList();
 
-                       if (m)
-                       {
-                               QG_GraphicView * gv = m->getGraphicView();
+       for(int i=0; i<windows.count(); i++)
+       {
+               QG_GraphicView * gv = ((MDIWindow *)windows.at(i))->getGraphicView();
 
-                               if (gv)
-                                       gv->updateGrid();
-                       }
-               }
+               if (gv)
+                       gv->updateGrid();
        }
 }
 
@@ -2765,7 +2604,7 @@ void ApplicationWindow::updateGrids()
  */
 void ApplicationWindow::slotViewStatusBar(bool showSB)
 {
-       RS_DEBUG->print("ApplicationWindow::slotViewStatusBar()");
+       DEBUG->print("ApplicationWindow::slotViewStatusBar()");
 
        if (showSB)
                statusBar()->show();
@@ -2773,110 +2612,14 @@ void ApplicationWindow::slotViewStatusBar(bool showSB)
                statusBar()->hide();
 }
 
-/**
- * Shows / hides the layer list.
- *
- * @param toggle true: show, false: hide.
- */
-/*void ApplicationWindow::slotViewLayerList(bool toggle) {
-    RS_DEBUG->print("ApplicationWindow::slotViewLayerList()");
-
-    if (toggle==false) {
-        layerDockWindow->hide();
-    } else {
-        layerDockWindow->show();
-    }
-}
-*/
-
-/**
- * Shows / hides the block list.
- *
- * @param toggle true: show, false: hide.
- */
-/*
-void ApplicationWindow::slotViewBlockList(bool toggle) {
-    RS_DEBUG->print("ApplicationWindow::slotViewBlockList()");
-
-    if (toggle==false) {
-        blockDockWindow->hide();
-    } else {
-        blockDockWindow->show();
-    }
-}
-*/
-
-/**
- * Shows / hides the command line.
- *
- * @param toggle true: show, false: hide.
- */
-/*
-void ApplicationWindow::slotViewCommandLine(bool toggle) {
-    RS_DEBUG->print("ApplicationWindow::slotViewCommandLine()");
-
-    if (toggle==false) {
-        commandDockWindow->hide();
-        //QG_GraphicView* graphicView = getGraphicView();
-        //if (graphicView!=NULL) {
-        //graphicView->setFocus();
-        //}
-        setFocus();
-    } else {
-        commandDockWindow->show();
-    }
-}
-*/
-
-/**
- * Shows / hides the option toolbar.
- *
- * @param toggle true: show, false: hide.
- */
-/*
-void ApplicationWindow::slotViewOptionToolbar(bool toggle) {
-    RS_DEBUG->print("ApplicationWindow::slotViewOptionToolbar()");
-
-    if (toggle==false) {
-        optionWidget->hide();
-    } else {
-        optionWidget->show();
-    }
-}
-*/
-
-/**
- * Creates a new MDI window for editing the selected block.
- */
-/*
-void ApplicationWindow::slotBlocksEdit() {
-    RS_DEBUG->print("ApplicationWindow::slotBlocksEdit()");
-
-    MDIWindow* parent = getMDIWindow();
-    if (parent!=NULL) {
-        RS_BlockList* blist = blockWidget->getBlockList();
-        if (blist!=NULL) {
-            RS_Block* blk = blist->getActiveBlock();
-            if (blk!=NULL) {
-                MDIWindow* w = slotFileNew(blk);
-                // the parent needs a pointer to the block window and
-                //   vice versa
-                parent->addChildWindow(w);
-                w->getGraphicView()->zoomAuto();
-            }
-        }
-    }
-}
-*/
-
 /**
  * Shows the dialog for general application preferences.
  */
 void ApplicationWindow::slotOptionsGeneral()
 {
-       RS_DIALOGFACTORY->requestOptionsGeneralDialog();
+       DIALOGFACTORY->requestOptionsGeneralDialog();
 
-       // update background color of all open drawings:
+       // Update background color of all open drawings:
        settings.beginGroup("Appearance");
        QColor color(settings.value("BackgroundColor", "#000000").toString());
        QColor gridColor(settings.value("GridColor", "Gray").toString());
@@ -2887,7 +2630,7 @@ void ApplicationWindow::slotOptionsGeneral()
 
        QList<QMdiSubWindow *> windows = workspace->subWindowList();
 
-       for(int i=0; i<int(windows.count()); ++i)
+       for(int i=0; i<int(windows.count()); i++)
        {
                MDIWindow * m = (MDIWindow *)windows.at(i);
 
@@ -2914,7 +2657,7 @@ void ApplicationWindow::slotOptionsGeneral()
  */
 void ApplicationWindow::slotScriptOpenIDE()
 {
-#ifdef RS_SCRIPTING
+#ifdef SCRIPTING
        scripter->openIDE();
 #endif
 }
@@ -2924,7 +2667,7 @@ void ApplicationWindow::slotScriptOpenIDE()
  */
 void ApplicationWindow::slotScriptRun()
 {
-#ifdef RS_SCRIPTING
+#ifdef SCRIPTING
        scripter->runScript();
 #endif
 }
@@ -2934,14 +2677,15 @@ void ApplicationWindow::slotScriptRun()
  */
 void ApplicationWindow::slotHelpAbout()
 {
-       RS_DEBUG->print("ApplicationWindow::slotHelpAbout()");
+       DEBUG->print("ApplicationWindow::slotHelpAbout()");
+#if 0
        QStringList modules;
 
 #ifdef RS_CAM
        modules += "CAM";
 #endif
 
-#ifdef RS_SCRIPTING
+#ifdef SCRIPTING
        modules += "Scripting";
 #endif
 
@@ -2951,26 +2695,16 @@ void ApplicationWindow::slotHelpAbout()
                modulesString = modules.join(", ");
        else
                modulesString = tr("None");
+#endif
 
        QMessageBox box(this);
        box.setWindowTitle(tr("About..."));
-       box.setText(QString("<qt>") +  // no center for main stream QCad
-#ifdef QC_ABOUT_HEADER
-               QString("<center>") +
-               QString(QC_ABOUT_HEADER) +
-#else
-//FAIL                       "<h2>"+ QC_APPNAME+ "</h2>" +
-               "<h2>Architektonas</h2>" +
-#endif
-               tr("Version: %1").arg("1.0.0") + "<br>" +
-               tr("Date: %1").arg(__DATE__) + "<br>" +
-               QString("&copy; 2010 Underground Software,<br>James Hammons") +
-               "<br>" +
-               QString("Portions &copy; 2001-2003 RibbonSoft") +
-               "<br>"
-#ifdef QC_ABOUT_ADD_COMPANY
-               + QString("<br>") + QC_ABOUT_ADD_COMPANY
-#endif
+       box.setText(QString("<center>")
+               + "<h2>Architektonas</h2>"
+               + tr("Version: %1").arg("1.0.0") + "<br>"
+               + tr("Date: %1").arg(__DATE__) + "<br>"
+               + QString("&copy; 2010 Underground Software,<br>James Hammons") + "<br>"
+               + QString("Portions &copy; 2001-2003 RibbonSoft") + "<br>"
                + QString("</center>")
                );
 #ifndef QC_ABOUT_HEADER
@@ -2989,17 +2723,17 @@ void ApplicationWindow::slotHelpManual()
 {
 #warning "No help system ported to Qt4... !!! FIX !!!"
 #if 0
-    RS_DEBUG->print("ApplicationWindow::slotHelpManual()");
+    DEBUG->print("ApplicationWindow::slotHelpManual()");
 
     if (assistant == NULL)
        {
-        RS_DEBUG->print("ApplicationWindow::slotHelpManual(): appdir: %s", RS_SYSTEM->getAppDir().toLatin1().data());
-        RS_DEBUG->print("ApplicationWindow::slotHelpManual(): appdir: %s", RS_SYSTEM->getAppDir().toLatin1().data());
-        assistant = new QAssistantClient(RS_SYSTEM->getAppDir()+"/bin", this);
+        DEBUG->print("ApplicationWindow::slotHelpManual(): appdir: %s", SYSTEM->getAppDir().toLatin1().data());
+        DEBUG->print("ApplicationWindow::slotHelpManual(): appdir: %s", SYSTEM->getAppDir().toLatin1().data());
+        assistant = new QAssistantClient(SYSTEM->getAppDir()+"/bin", this);
                connect(assistant, SIGNAL(error(const QString&)), this, SLOT(slotError(const QString&)));
         QStringList args;
         args << "-profile";
-        args << QDir::convertSeparators(RS_SYSTEM->getDocPath() + "/qcaddoc.adp");
+        args << QDir::convertSeparators(SYSTEM->getDocPath() + "/qcaddoc.adp");
 //        args << QString("doc") + QDir::separator() + QString("qcaddoc.adp");
 
 #if QT_VERSION>=0x030200
@@ -3014,9 +2748,9 @@ void ApplicationWindow::slotHelpManual()
 /**
  * Testing function.
  */
-void ApplicationWindow::slotTestDumpEntities(RS_EntityContainer * d)
+void ApplicationWindow::slotTestDumpEntities(EntityContainer * d)
 {
-       RS_DEBUG->print("ApplicationWindow::slotTestDumpEntities()");
+       DEBUG->print("ApplicationWindow::slotTestDumpEntities()");
        static int level = 0;
        std::ofstream dumpFile;
 
@@ -3040,7 +2774,7 @@ void ApplicationWindow::slotTestDumpEntities(RS_EntityContainer * d)
                        dumpFile << "<body>\n";
                }
 
-               for (RS_Entity* e=d->firstEntity();
+               for (Entity* e=d->firstEntity();
                                e!=NULL;
                                e=d->nextEntity())
                {
@@ -3072,7 +2806,7 @@ void ApplicationWindow::slotTestDumpEntities(RS_EntityContainer * d)
                        {
                        case RS2::EntityPoint:
                        {
-                                       RS_Point* p = (RS_Point*)e;
+                                       Point* p = (Point*)e;
                                        dumpFile
                                        << "<table><tr><td>"
                                        << "<b>Point:</b>"
@@ -3088,7 +2822,7 @@ void ApplicationWindow::slotTestDumpEntities(RS_EntityContainer * d)
 
                        case RS2::EntityLine:
                        {
-                                       RS_Line* l = (RS_Line*)e;
+                                       Line* l = (Line*)e;
                                        dumpFile
                                        << "<table><tr><td>"
                                        << "<b>Line:</b>"
@@ -3106,7 +2840,7 @@ void ApplicationWindow::slotTestDumpEntities(RS_EntityContainer * d)
                                break;
 
                        case RS2::EntityArc: {
-                                       RS_Arc* a = (RS_Arc*)e;
+                                       Arc* a = (Arc*)e;
                                        dumpFile
                                        << "<table><tr><td>"
                                        << "<b>Arc:</b>"
@@ -3139,7 +2873,7 @@ void ApplicationWindow::slotTestDumpEntities(RS_EntityContainer * d)
                                break;
 
                        case RS2::EntityCircle: {
-                                       RS_Circle* c = (RS_Circle*)e;
+                                       Circle* c = (Circle*)e;
                                        dumpFile
                                        << "<table><tr><td>"
                                        << "<b>Circle:</b>"
@@ -3157,7 +2891,7 @@ void ApplicationWindow::slotTestDumpEntities(RS_EntityContainer * d)
                                break;
 
                        case RS2::EntityDimAligned: {
-                                       RS_DimAligned* d = (RS_DimAligned*)e;
+                                       DimAligned* d = (DimAligned*)e;
                                        dumpFile
                                        << "<table><tr><td>"
                                        << "<b>Dimension / Aligned:</b>"
@@ -3185,7 +2919,7 @@ void ApplicationWindow::slotTestDumpEntities(RS_EntityContainer * d)
 
                        case RS2::EntityDimLinear:
                        {
-                                       RS_DimLinear* d = (RS_DimLinear*)e;
+                                       DimLinear* d = (DimLinear*)e;
                                        dumpFile
                                        << "<table><tr><td>"
                                        << "<b>Dimension / Linear:</b>"
@@ -3212,7 +2946,7 @@ void ApplicationWindow::slotTestDumpEntities(RS_EntityContainer * d)
                                break;
 
                        case RS2::EntityInsert: {
-                                       RS_Insert* i = (RS_Insert*)e;
+                                       Insert* i = (Insert*)e;
                                        dumpFile
                                        << "<table><tr><td>"
                                        << "<b>Insert:</b>"
@@ -3227,7 +2961,7 @@ void ApplicationWindow::slotTestDumpEntities(RS_EntityContainer * d)
                                break;
 
                        case RS2::EntityText: {
-                                       RS_Text* t = (RS_Text*)e;
+                                       Text* t = (Text*)e;
                                        dumpFile
                                        << "<table><tr><td>"
                                        << "<b>Text:</b>"
@@ -3245,7 +2979,7 @@ void ApplicationWindow::slotTestDumpEntities(RS_EntityContainer * d)
                                break;
 
                        case RS2::EntityHatch: {
-                                       RS_Hatch* h = (RS_Hatch*)e;
+                                       Hatch* h = (Hatch*)e;
                                        dumpFile
                                        << "<table><tr><td>"
                                        << "<b>Hatch:</b>"
@@ -3274,7 +3008,7 @@ void ApplicationWindow::slotTestDumpEntities(RS_EntityContainer * d)
                        }
 
                        if (e->isContainer() || e->rtti()==RS2::EntityHatch) {
-                               RS_EntityContainer* ec = (RS_EntityContainer*)e;
+                               EntityContainer* ec = (EntityContainer*)e;
                                dumpFile << "<table><tr><td valign=\"top\">&nbsp;&nbsp;&nbsp;&nbsp;Contents:</td><td>\n";
                                dumpFile.close();
                                slotTestDumpEntities(ec);
@@ -3302,13 +3036,13 @@ void ApplicationWindow::slotTestDumpEntities(RS_EntityContainer * d)
  */
 void ApplicationWindow::slotTestDumpUndo()
 {
-       RS_DEBUG->print("ApplicationWindow::slotTestDumpUndo()");
+       DEBUG->print("ApplicationWindow::slotTestDumpUndo()");
 
-       RS_Document * d = getDocument();
+       Document * d = getDocument();
 
        if (d != NULL)
        {
-               std::cout << *(RS_Undo*)d;
+               std::cout << *(Undo*)d;
                std::cout << std::endl;
        }
 }
@@ -3318,9 +3052,9 @@ void ApplicationWindow::slotTestDumpUndo()
  */
 void ApplicationWindow::slotTestUpdateInserts()
 {
-       RS_DEBUG->print("ApplicationWindow::slotTestUpdateInserts()");
+       DEBUG->print("ApplicationWindow::slotTestUpdateInserts()");
 
-       RS_Document * d = getDocument();
+       Document * d = getDocument();
 
        if (d != NULL)
                d->updateInserts();
@@ -3331,7 +3065,7 @@ void ApplicationWindow::slotTestUpdateInserts()
  */
 void ApplicationWindow::slotTestDrawFreehand()
 {
-       RS_DEBUG->print("ApplicationWindow::slotTestDrawFreehand()");
+       DEBUG->print("ApplicationWindow::slotTestDrawFreehand()");
 
     //Drawing* g = document->getMarking();
     /*
@@ -3388,92 +3122,92 @@ void ApplicationWindow::slotTestDrawFreehand()
  */
 void ApplicationWindow::slotTestInsertBlock()
 {
-       RS_DEBUG->print("ApplicationWindow::slotTestInsertBlock()");
+       DEBUG->print("ApplicationWindow::slotTestInsertBlock()");
 
-       RS_Document * d = getDocument();
+       Document * d = getDocument();
 
-       if (d != NULL && d->rtti() == RS2::EntityGraphic)
+       if (d != NULL && d->rtti() == RS2::EntityDrawing)
        {
                Drawing * graphic = (Drawing *)d;
 
                if (graphic == NULL)
                        return;
 
-               graphic->addLayer(new RS_Layer("default"));
-               RS_Block * block = new RS_Block(graphic, RS_BlockData("debugblock", Vector(0.0, 0.0), true));
+               graphic->addLayer(new Layer("default"));
+               Block * block = new Block(graphic, BlockData("debugblock", Vector(0.0, 0.0), true));
 
-               RS_Line * line;
-               RS_Arc * arc;
-               RS_Circle * circle;
+               Line * line;
+               Arc * arc;
+               Circle * circle;
 
                // Add one red line:
-               line = new RS_Line(block, RS_LineData(Vector(0.0, 0.0), Vector(50.0, 0.0)));
+               line = new Line(block, LineData(Vector(0.0, 0.0), Vector(50.0, 0.0)));
                line->setLayerToActive();
-               line->setPen(RS_Pen(RS_Color(255, 0, 0), RS2::Width01, RS2::SolidLine));
+               line->setPen(Pen(Color(255, 0, 0), RS2::Width01, RS2::SolidLine));
                block->addEntity(line);
 
                // Add one line with attributes from block:
-               line = new RS_Line(block, RS_LineData(Vector(50.0, 0.0), Vector(50.0, 50.0)));
-               line->setPen(RS_Pen(RS_Color(RS2::FlagByBlock), RS2::WidthByBlock, RS2::LineByBlock));
+               line = new Line(block, LineData(Vector(50.0, 0.0), Vector(50.0, 50.0)));
+               line->setPen(Pen(Color(RS2::FlagByBlock), RS2::WidthByBlock, RS2::LineByBlock));
                block->addEntity(line);
 
                // Add one arc with attributes from block:
-               RS_ArcData d(Vector(50.0, 0.0), 50.0, M_PI / 2.0, M_PI, false);
-               arc = new RS_Arc(block, d);
-               arc->setPen(RS_Pen(RS_Color(RS2::FlagByBlock), RS2::WidthByBlock, RS2::LineByBlock));
+               ArcData d(Vector(50.0, 0.0), 50.0, M_PI / 2.0, M_PI, false);
+               arc = new Arc(block, d);
+               arc->setPen(Pen(Color(RS2::FlagByBlock), RS2::WidthByBlock, RS2::LineByBlock));
                block->addEntity(arc);
 
                // Add one blue circle:
-               RS_CircleData circleData(Vector(20.0, 15.0), 12.5);
-               circle = new RS_Circle(block, circleData);
+               CircleData circleData(Vector(20.0, 15.0), 12.5);
+               circle = new Circle(block, circleData);
                circle->setLayerToActive();
-               circle->setPen(RS_Pen(RS_Color(0, 0, 255), RS2::Width01, RS2::SolidLine));
+               circle->setPen(Pen(Color(0, 0, 255), RS2::Width01, RS2::SolidLine));
                block->addEntity(circle);
 
                graphic->addBlock(block);
 
-               RS_Insert * ins;
-               RS_InsertData insData("debugblock", Vector(0.0, 0.0), Vector(1.0, 1.0), 0.0, 1, 1, Vector(0.0, 0.0), NULL, RS2::NoUpdate);
+               Insert * ins;
+               InsertData insData("debugblock", Vector(0.0, 0.0), Vector(1.0, 1.0), 0.0, 1, 1, Vector(0.0, 0.0), NULL, RS2::NoUpdate);
 
                // insert one magenta instance of the block (original):
-               ins = new RS_Insert(graphic, insData);
+               ins = new Insert(graphic, insData);
                ins->setLayerToActive();
-               ins->setPen(RS_Pen(RS_Color(255, 0, 255), RS2::Width02, RS2::SolidLine));
+               ins->setPen(Pen(Color(255, 0, 255), RS2::Width02, RS2::SolidLine));
                ins->update();
                graphic->addEntity(ins);
 
                // insert one green instance of the block (rotate):
-               insData = RS_InsertData("debugblock", Vector(-50.0, 20.0), Vector(1.0, 1.0), 30.0 / ARAD, 1, 1, Vector(0.0, 0.0), NULL, RS2::NoUpdate);
-               ins = new RS_Insert(graphic, insData);
+               insData = InsertData("debugblock", Vector(-50.0, 20.0), Vector(1.0, 1.0), 30.0 / ARAD, 1, 1, Vector(0.0, 0.0), NULL, RS2::NoUpdate);
+               ins = new Insert(graphic, insData);
                ins->setLayerToActive();
-               ins->setPen(RS_Pen(RS_Color(0, 255, 0), RS2::Width02, RS2::SolidLine));
+               ins->setPen(Pen(Color(0, 255, 0), RS2::Width02, RS2::SolidLine));
                ins->update();
                graphic->addEntity(ins);
 
                // insert one cyan instance of the block (move):
-               insData = RS_InsertData("debugblock", Vector(10.0, 20.0), Vector(1.0, 1.0), 0.0, 1, 1, Vector(0.0, 0.0), NULL, RS2::NoUpdate);
-               ins = new RS_Insert(graphic, insData);
+               insData = InsertData("debugblock", Vector(10.0, 20.0), Vector(1.0, 1.0), 0.0, 1, 1, Vector(0.0, 0.0), NULL, RS2::NoUpdate);
+               ins = new Insert(graphic, insData);
                ins->setLayerToActive();
-               ins->setPen(RS_Pen(RS_Color(0, 255, 255), RS2::Width02, RS2::SolidLine));
+               ins->setPen(Pen(Color(0, 255, 255), RS2::Width02, RS2::SolidLine));
                ins->update();
                graphic->addEntity(ins);
 
                // insert one blue instance of the block:
                for(double a=0.0; a<360.0; a+=45.0)
                {
-                       insData = RS_InsertData("debugblock", Vector(60.0, 0.0), Vector(2.0 / 5, 2.0 / 5), a/ARAD, 1, 1, Vector(0.0, 0.0), NULL, RS2::NoUpdate);
-                       ins = new RS_Insert(graphic, insData);
+                       insData = InsertData("debugblock", Vector(60.0, 0.0), Vector(2.0 / 5, 2.0 / 5), a/ARAD, 1, 1, Vector(0.0, 0.0), NULL, RS2::NoUpdate);
+                       ins = new Insert(graphic, insData);
                        ins->setLayerToActive();
-                       ins->setPen(RS_Pen(RS_Color(0, 0, 255), RS2::Width05, RS2::SolidLine));
+                       ins->setPen(Pen(Color(0, 0, 255), RS2::Width05, RS2::SolidLine));
                        ins->update();
                        graphic->addEntity(ins);
                }
 
                // insert an array of yellow instances of the block:
-               insData = RS_InsertData("debugblock", Vector(-100.0, -100.0), Vector(0.2, 0.2), M_PI / 6.0, 6, 4, Vector(100.0, 100.0), NULL, RS2::NoUpdate);
-               ins = new RS_Insert(graphic, insData);
+               insData = InsertData("debugblock", Vector(-100.0, -100.0), Vector(0.2, 0.2), M_PI / 6.0, 6, 4, Vector(100.0, 100.0), NULL, RS2::NoUpdate);
+               ins = new Insert(graphic, insData);
                ins->setLayerToActive();
-               ins->setPen(RS_Pen(RS_Color(255, 255, 0), RS2::Width01, RS2::SolidLine));
+               ins->setPen(Pen(Color(255, 255, 0), RS2::Width01, RS2::SolidLine));
                ins->update();
                graphic->addEntity(ins);
 
@@ -3489,9 +3223,9 @@ void ApplicationWindow::slotTestInsertBlock()
  */
 void ApplicationWindow::slotTestInsertEllipse()
 {
-       RS_DEBUG->print("ApplicationWindow::slotTestInsertEllipse()");
+       DEBUG->print("ApplicationWindow::slotTestInsertEllipse()");
 
-       RS_Document * d = getDocument();
+       Document * d = getDocument();
 
        if (d != NULL)
        {
@@ -3500,8 +3234,8 @@ void ApplicationWindow::slotTestInsertEllipse()
                if (graphic == NULL)
                        return;
 
-               RS_Ellipse * ellipse;
-               RS_Line * line;
+               Ellipse * ellipse;
+               Line * line;
 
                for (double a=0.0; a<2*M_PI; a+=0.1)
                {
@@ -3509,39 +3243,39 @@ void ApplicationWindow::slotTestInsertEllipse()
                        v.setPolar(50.0, a);
                        double xp = 1000.0*a;
 
-                       RS_EllipseData ellipseData(Vector(xp, 0.0), v, 0.5, 0.0, 2 * M_PI, false);
-                       ellipse = new RS_Ellipse(graphic, ellipseData);
+                       EllipseData ellipseData(Vector(xp, 0.0), v, 0.5, 0.0, 2 * M_PI, false);
+                       ellipse = new Ellipse(graphic, ellipseData);
 
-                       ellipse->setPen(RS_Pen(RS_Color(255, 0, 255), RS2::Width01, RS2::SolidLine));
+                       ellipse->setPen(Pen(Color(255, 0, 255), RS2::Width01, RS2::SolidLine));
 
                        graphic->addEntity(ellipse);
-                       //graphic->addEntity(new RS_Point(graphic, ellipse->getMax()));
-                       //graphic->addEntity(new RS_Point(graphic, ellipse->getMin()));
+                       //graphic->addEntity(new Point(graphic, ellipse->getMax()));
+                       //graphic->addEntity(new Point(graphic, ellipse->getMin()));
 
-                       line = new RS_Line(graphic, RS_LineData(Vector(xp, 0.0), Vector(xp, 0.0) + v));
-                       line->setPen(RS_Pen(RS_Color(128, 128, 128), RS2::Width01, RS2::SolidLine));
+                       line = new Line(graphic, LineData(Vector(xp, 0.0), Vector(xp, 0.0) + v));
+                       line->setPen(Pen(Color(128, 128, 128), RS2::Width01, RS2::SolidLine));
                        graphic->addEntity(line);
 
 /*
                        for (double mx=-60.0; mx<60.0; mx+=1.0) {
                                //for (double mx=0.0; mx<1.0; mx+=2.5) {
                                VectorSolutions sol = ellipse->mapX(xp + mx);
-                               //graphic->addEntity(new RS_Point(graphic,
+                               //graphic->addEntity(new Point(graphic,
                                //                   sol.vector2 + Vector(a*500.0, 0.0)));
-                               //graphic->addEntity(new RS_Point(graphic,
+                               //graphic->addEntity(new Point(graphic,
                                //                   sol.vector3 + Vector(a*500.0, 0.0)));
-                               //graphic->addEntity(new RS_Point(graphic,
+                               //graphic->addEntity(new Point(graphic,
                                //                   sol.vector4 + Vector(a*500.0, 0.0)));
 
-                               line = new RS_Line(graphic,
-                                                               RS_LineData(Vector(xp+mx,-50.0),
+                               line = new Line(graphic,
+                                                               LineData(Vector(xp+mx,-50.0),
                                                                                        Vector(xp+mx,50.0)));
-                               line->setPen(RS_Pen(RS_Color(60, 60, 60),
+                               line->setPen(Pen(Color(60, 60, 60),
                                                                        RS2::Width01,
                                                                        RS2::SolidLine));
                                graphic->addEntity(line);
 
-                               graphic->addEntity(new RS_Point(graphic,
+                               graphic->addEntity(new Point(graphic,
                                                                                                sol.get(0)));
                        }
 */
@@ -3554,22 +3288,22 @@ void ApplicationWindow::slotTestInsertEllipse()
                                        for (x=-250.0; x<=250.0; x+=50.0) {
                                                Vector v(x, y);
 
-                                               ellipse = new RS_Ellipse(graphic,
+                                               ellipse = new Ellipse(graphic,
                                                                                                v,
                                                                                                Vector((x/5+50.0)/2.0, 0.0),
                                                                                        fabs(x/y),
                                                                                                0.0, 2*M_PI,
                                                                                                false);
 
-                               ellipse->setPen(RS_Pen(RS_Color(255, 255, 0),
+                               ellipse->setPen(Pen(Color(255, 255, 0),
                                                                                RS2::Width01,
                                                                                RS2::DashDotLine));
 
                                                graphic->addEntity(ellipse);
-                                               graphic->addEntity(new RS_Point(graphic, ellipse->getMax()));
-                                               graphic->addEntity(new RS_Point(graphic, ellipse->getMin()));
+                                               graphic->addEntity(new Point(graphic, ellipse->getMax()));
+                                               graphic->addEntity(new Point(graphic, ellipse->getMin()));
 
-                               ellipse = new RS_Ellipse(graphic,
+                               ellipse = new Ellipse(graphic,
                                                                                                v + Vector(750.0, 0.0),
                                                                                                Vector((x/5+50.0)/2.0, 0.0),
                                                                                                fabs(x/y),
@@ -3577,8 +3311,8 @@ void ApplicationWindow::slotTestInsertEllipse()
                                                                                                true);
 
                                                graphic->addEntity(ellipse);
-                                               graphic->addEntity(new RS_Point(graphic, ellipse->getMax()));
-                                               graphic->addEntity(new RS_Point(graphic, ellipse->getMin()));
+                                               graphic->addEntity(new Point(graphic, ellipse->getMax()));
+                                               graphic->addEntity(new Point(graphic, ellipse->getMin()));
                                        }
                                }
                */
@@ -3587,15 +3321,15 @@ void ApplicationWindow::slotTestInsertEllipse()
                                // different rotation angles:
                                double rot;
                                for (rot=0.0; rot<=2*M_PI+0.1; rot+=(M_PI/8)) {
-                                       ellipse = new RS_Ellipse(graphic,
+                                       ellipse = new Ellipse(graphic,
                                                                                        Vector(rot*200, 500.0),
                                                                                        Vector(50.0, 0.0).rotate(rot),
                                                                                        0.3,
                                                                                        0.0, 2*M_PI,
                                                                                        false);
                                        graphic->addEntity(ellipse);
-                                       graphic->addEntity(new RS_Point(graphic, ellipse->getMax()));
-                                       graphic->addEntity(new RS_Point(graphic, ellipse->getMin()));
+                                       graphic->addEntity(new Point(graphic, ellipse->getMax()));
+                                       graphic->addEntity(new Point(graphic, ellipse->getMin()));
                                }
 
 
@@ -3604,7 +3338,7 @@ void ApplicationWindow::slotTestInsertEllipse()
                                for (rot=0.0; rot<=2*M_PI+0.1; rot+=(M_PI/8)) {
                                        for (a1=0.0; a1<=2*M_PI+0.1; a1+=(M_PI/8)) {
                                                for (a2=a1+M_PI/8; a2<=2*M_PI+a1+0.1; a2+=(M_PI/8)) {
-                                                       ellipse = new RS_Ellipse(graphic,
+                                                       ellipse = new Ellipse(graphic,
                                                                                                        Vector(-500.0-a1*200.0-5000.0*rot,
                                                                                                                                500.0-a2*200.0),
                                                                                                        Vector(50.0, 0.0).rotate(rot),
@@ -3612,8 +3346,8 @@ void ApplicationWindow::slotTestInsertEllipse()
                                                                                                        a1, a2,
                                                                                                        false);
                                                        graphic->addEntity(ellipse);
-                                                       graphic->addEntity(new RS_Point(graphic, ellipse->getMax()));
-                                                       graphic->addEntity(new RS_Point(graphic, ellipse->getMin()));
+                                                       graphic->addEntity(new Point(graphic, ellipse->getMax()));
+                                                       graphic->addEntity(new Point(graphic, ellipse->getMin()));
                                                }
                                        }
                                }
@@ -3631,9 +3365,9 @@ void ApplicationWindow::slotTestInsertEllipse()
  */
 void ApplicationWindow::slotTestInsertText()
 {
-       RS_DEBUG->print("ApplicationWindow::slotTestInsertText()");
+       DEBUG->print("ApplicationWindow::slotTestInsertText()");
 
-       RS_Document * d = getDocument();
+       Document * d = getDocument();
 
        if (d != NULL)
        {
@@ -3642,13 +3376,13 @@ void ApplicationWindow::slotTestInsertText()
                if (graphic == NULL)
                        return;
 
-               RS_Text * text;
-               RS_TextData textData;
+               Text * text;
+               TextData textData;
 
-               textData = RS_TextData(Vector(10.0, 10.0), 10.0, 100.0, RS2::VAlignTop, RS2::HAlignLeft, RS2::LeftToRight, RS2::Exact, 1.0, "Andrew", "normal", 0.0);
-               text = new RS_Text(graphic, textData);
+               textData = TextData(Vector(10.0, 10.0), 10.0, 100.0, RS2::VAlignTop, RS2::HAlignLeft, RS2::LeftToRight, RS2::Exact, 1.0, "Andrew", "normal", 0.0);
+               text = new Text(graphic, textData);
                text->setLayerToActive();
-               text->setPen(RS_Pen(RS_Color(255, 0, 0), RS2::Width01, RS2::SolidLine));
+               text->setPen(Pen(Color(255, 0, 0), RS2::Width01, RS2::SolidLine));
                graphic->addEntity(text);
 
 /*
@@ -3657,7 +3391,7 @@ void ApplicationWindow::slotTestInsertText()
                        for (x=-250.0; x<=250.0; x+=50.0) {
                                Vector v(x, y);
 
-                               textData = RS_TextData(v,
+                               textData = TextData(v,
                                                                                10.0, 100.0,
                                                                                RS2::VAlignTop,
                                                                                RS2::HAlignLeft,
@@ -3668,28 +3402,28 @@ void ApplicationWindow::slotTestInsertText()
                                                                                "normal",
                                                                                0.0);
 
-                               text = new RS_Text(graphic, textData);
+                               text = new Text(graphic, textData);
 
                                text->setLayerToActive();
-                               text->setPen(RS_Pen(RS_Color(255, 0, 0),
+                               text->setPen(Pen(Color(255, 0, 0),
                                                                        RS2::Width01,
                                                                        RS2::SolidLine));
                                graphic->addEntity(text);
                        }
                }
 
-               RS_Line* line;
+               Line* line;
                for (x=0.0; x<M_PI*2.0; x+=0.2) {
                        Vector v(600.0+cos(x)*50.0, 0.0+sin(x)*50.0);
 
-                       line = new RS_Line(graphic,
-                                                               RS_LineData(Vector(600.0,0.0),
+                       line = new Line(graphic,
+                                                               LineData(Vector(600.0,0.0),
                                                                                        v));
                        line->setLayerToActive();
                        line->setPenToActive();
                        graphic->addEntity(line);
 
-                       textData = RS_TextData(v,
+                       textData = TextData(v,
                                                                        5.0, 50.0,
                                                                        RS2::VAlignTop,
                                                                        RS2::HAlignLeft,
@@ -3700,23 +3434,23 @@ void ApplicationWindow::slotTestInsertText()
                                                                        "normal",
                                                                        x);
 
-                       text = new RS_Text(graphic, textData);
+                       text = new Text(graphic, textData);
 
                        text->setLayerToActive();
-                       text->setPen(RS_Pen(RS_Color(255, 0, 0),
+                       text->setPen(Pen(Color(255, 0, 0),
                                                                RS2::Width01,
                                                                RS2::SolidLine));
                        graphic->addEntity(text);
                }
 
-               RS_SolidData solidData = RS_SolidData(Vector(5.0, 10.0),
+               SolidData solidData = SolidData(Vector(5.0, 10.0),
                                                                                        Vector(25.0, 15.0),
                                                                                        Vector(15.0, 30.0));
 
-               RS_Solid* s = new RS_Solid(graphic, solidData);
+               Solid* s = new Solid(graphic, solidData);
 
                s->setLayerToActive();
-               s->setPen(RS_Pen(RS_Color(255, 255, 0),
+               s->setPen(Pen(Color(255, 255, 0),
                                                RS2::Width01,
                                                RS2::SolidLine));
                graphic->addEntity(s);
@@ -3734,27 +3468,27 @@ void ApplicationWindow::slotTestInsertText()
  */
 void ApplicationWindow::slotTestInsertImage()
 {
-       RS_DEBUG->print("ApplicationWindow::slotTestInsertImage()");
+       DEBUG->print("ApplicationWindow::slotTestInsertImage()");
 
-       RS_Document * d = getDocument();
+       Document * d = getDocument();
 
-       if (d != NULL)
-       {
-               Drawing * graphic = (Drawing *)d;
+       if (d == NULL)
+               return;
 
-               if (graphic == NULL)
-                       return;
+       Drawing * drawing = (Drawing *)d;
 
-               RS_Image * image;
-               RS_ImageData imageData;
+       if (drawing == NULL)
+               return;
 
-               imageData = RS_ImageData(0, Vector(50.0, 30.0), Vector(0.5, 0.5), Vector(-0.5, 0.5), Vector(640, 480), "/home/andrew/data/image.png", 50, 50, 0);
-               image = new RS_Image(graphic, imageData);
+       Image * image;
+       ImageData imageData;
 
-               image->setLayerToActive();
-               image->setPen(RS_Pen(RS_Color(255, 0, 0), RS2::Width01, RS2::SolidLine));
-               graphic->addEntity(image);
-       }
+       imageData = ImageData(0, Vector(50.0, 30.0), Vector(0.5, 0.5), Vector(-0.5, 0.5), Vector(640, 480), "/home/andrew/data/image.png", 50, 50, 0);
+       image = new Image(drawing, imageData);
+
+       image->setLayerToActive();
+       image->setPen(Pen(Color(255, 0, 0), RS2::Width01, RS2::SolidLine));
+       drawing->addEntity(image);
 }
 
 /**
@@ -3762,17 +3496,17 @@ void ApplicationWindow::slotTestInsertImage()
  */
 void ApplicationWindow::slotTestUnicode()
 {
-    RS_DEBUG->print("ApplicationWindow::slotTestUnicode()");
+    DEBUG->print("ApplicationWindow::slotTestUnicode()");
 
     slotFileOpen("./fonts/unicode.cxf", RS2::FormatCXF);
-    RS_Document* d = getDocument();
+    Document* d = getDocument();
     if (d!=NULL) {
         Drawing* graphic = (Drawing*)d;
         if (graphic==NULL) {
             return;
         }
 
-        RS_Insert* ins;
+        Insert* ins;
 
         int col;
         int row;
@@ -3796,14 +3530,14 @@ void ApplicationWindow::slotTestUnicode()
                 strCode = "[" + strCode + "] " + uCode;
 
                 if (graphic->findBlock(strCode)!=NULL) {
-                    RS_InsertData d(strCode,
+                    InsertData d(strCode,
                                     Vector(col/0x10*20.0,row*20.0),
                                     Vector(1.0,1.0), 0.0,
                                     1, 1, Vector(0.0, 0.0),
                                     NULL, RS2::NoUpdate);
-                    ins = new RS_Insert(graphic, d);
+                    ins = new Insert(graphic, d);
                     ins->setLayerToActive();
-                    ins->setPen(RS_Pen(RS_Color(255, 255, 255),
+                    ins->setPen(Pen(Color(255, 255, 255),
                                        RS2::Width01,
                                        RS2::SolidLine));
                     ins->update();
@@ -3821,9 +3555,9 @@ void ApplicationWindow::slotTestUnicode()
  */
 void ApplicationWindow::slotTestMath01()
 {
-    RS_DEBUG->print("ApplicationWindow::slotTestMath01()");
+    DEBUG->print("ApplicationWindow::slotTestMath01()");
 
-    RS_Document* d = getDocument();
+    Document* d = getDocument();
     if (d!=NULL) {
         Drawing* graphic = (Drawing*)d;
         if (graphic==NULL) {
@@ -3831,11 +3565,11 @@ void ApplicationWindow::slotTestMath01()
         }
 
         // axis
-        graphic->addEntity(new RS_Line(graphic,
-                                       RS_LineData(Vector(0.0,0.0),
+        graphic->addEntity(new Line(graphic,
+                                       LineData(Vector(0.0,0.0),
                                                    Vector(2*M_PI,0.0))));
-        graphic->addEntity(new RS_Line(graphic,
-                                       RS_LineData(Vector(0.0,-1.0),
+        graphic->addEntity(new Line(graphic,
+                                       LineData(Vector(0.0,-1.0),
                                                    Vector(0.0,1.0))));
 
         // cos
@@ -3844,29 +3578,29 @@ void ApplicationWindow::slotTestMath01()
         double x_0 = 60.0/ARAD;
         for (a=0.01; a<2*M_PI; a+=0.01) {
             // cos curve:
-            RS_Line* line = new RS_Line(graphic,
-                                        RS_LineData(Vector(a-0.01, cos(a-0.01)),
+            Line* line = new Line(graphic,
+                                        LineData(Vector(a-0.01, cos(a-0.01)),
                                                     Vector(a, cos(a))));
             graphic->addEntity(line);
 
             // tangent:
-            graphic->addEntity(new RS_Line(graphic,
-                                           RS_LineData(Vector(a-0.01,cos(x_0)-sin(x_0)*(a-0.01-x_0)),
+            graphic->addEntity(new Line(graphic,
+                                           LineData(Vector(a-0.01,cos(x_0)-sin(x_0)*(a-0.01-x_0)),
                                                        Vector(a,cos(x_0)-sin(x_0)*(a-x_0)))));
         }
 
         // 59.0 deg
-        graphic->addEntity(new RS_Line(graphic,
-                                       RS_LineData(Vector(x,0.0),
+        graphic->addEntity(new Line(graphic,
+                                       LineData(Vector(x,0.0),
                                                    Vector(x,1.0))));
 
         // 60.0 deg
-        graphic->addEntity(new RS_Line(graphic,
-                                       RS_LineData(Vector(x_0,0.0),
+        graphic->addEntity(new Line(graphic,
+                                       LineData(Vector(x_0,0.0),
                                                    Vector(x_0,1.0))));
 
         // tangent
-        //graphic->addEntity(new RS_Line(graphic,
+        //graphic->addEntity(new Line(graphic,
         //                   Vector(0.0,cos(x_0)-sin(x_0)*(0.0-x_0)),
         //                   Vector(6.0,cos(x_0)-sin(x_0)*(6.0-x_0))));
 
@@ -3883,7 +3617,7 @@ void ApplicationWindow::slotTestMath01()
  */
 void ApplicationWindow::slotTestResize640()
 {
-    RS_DEBUG->print("ApplicationWindow::slotTestResize640()");
+    DEBUG->print("ApplicationWindow::slotTestResize640()");
 
     resize(640, 480);
 }
@@ -3893,7 +3627,7 @@ void ApplicationWindow::slotTestResize640()
  */
 void ApplicationWindow::slotTestResize800()
 {
-    RS_DEBUG->print("ApplicationWindow::slotTestResize800()");
+    DEBUG->print("ApplicationWindow::slotTestResize800()");
 
     resize(800, 600);
 }
@@ -3903,7 +3637,7 @@ void ApplicationWindow::slotTestResize800()
  */
 void ApplicationWindow::slotTestResize1024()
 {
-    RS_DEBUG->print("ApplicationWindow::slotTestResize1024()");
+    DEBUG->print("ApplicationWindow::slotTestResize1024()");
 
     resize(1024, 768);
 }
@@ -3911,49 +3645,27 @@ void ApplicationWindow::slotTestResize1024()
 /**
  * overloaded for Message box on last window exit.
  */
-bool ApplicationWindow::queryExit(bool force)
+bool ApplicationWindow::QueryExit(void)
 {
-       RS_DEBUG->print("ApplicationWindow::queryExit()");
-
-       bool succ = true;
-
-       // demo:
-       if (force)
-       {
-               QMessageBox::information(this, QMessageBox::tr("Warning"),
-                       tr("This is a %1 version "
-                       "which terminates\n"
-                       "automatically after 10min. This software is\n"
-                       "not intended for production use. Please buy\n"
-                       "a full version of the application from\n%2.\n"
-                       "You can save your work now.")
-//FAIL                                 .arg(QC_APPNAME)
-                       .arg("Architektonas")
-#ifdef QC_CUSTOM_VENDOR
-                       .arg(QC_CUSTOM_VENDOR),
-#else
-                       .arg("RibbonSoft, http://www.ribbonsoft.com"),
-#endif
-                       QMessageBox::Ok);
-    }
+       DEBUG->print("ApplicationWindow::queryExit()");
 
+       bool success = true;
        QList<QMdiSubWindow *> list = workspace->subWindowList();
 
-//     for(QWidget * w=list.first(); w!=NULL; w=list.next())
        for(int i=0; i<list.size(); i++)
        {
-               succ = ((MDIWindow *)list[i])->closeMDI(force);
+               success = ((MDIWindow *)list[i])->CloseMDI();
 
-               if (!succ)
+               if (!success)
                        break;
        }
 
-       if (succ)
+       if (success)
                storeSettings();
 
-       RS_DEBUG->print("ApplicationWindow::queryExit(): OK");
+       DEBUG->print("ApplicationWindow::queryExit(): OK");
 
-       return succ;
+       return success;
 }
 
 /**
@@ -3983,7 +3695,7 @@ void ApplicationWindow::keyPressEvent(QKeyEvent * e)
                GraphicView * graphicView = getGraphicView();
 
                if (graphicView)
-                       graphicView->keyPressEvent(e);
+                       graphicView->_keyPressEvent(e);
 
                e->accept();
        }
@@ -4073,13 +3785,15 @@ void ApplicationWindow::keyReleaseEvent(QKeyEvent * e)
                GraphicView * graphicView = getGraphicView();
 
                if (graphicView)
-                       graphicView->keyReleaseEvent(e);
+                       graphicView->_keyReleaseEvent(e);
 
                e->accept();
        }
                break;
        }
 
+// THIS LOOKS LIKE A BUG TO ME...
+#warning "!!! keyPressEvent called in keyReleaseEvent !!!"
 //     Q3MainWindow::keyPressEvent(e);
        QMainWindow::keyPressEvent(e);
 }
@@ -4101,25 +3815,28 @@ QMdiArea * ApplicationWindow::getWorkspace()
 }
 
 /**
- * @return Pointer to the currently active MDI Window or NULL if no
- * MDI Window is active.
+ * @return Pointer to the currently active MDI Window or NULL if no MDI Window
+ * is active.
  */
 MDIWindow * ApplicationWindow::getMDIWindow()
 {
-       RS_DEBUG->print(/*RS_Debug::D_CRITICAL,*/ "ApplicationWindow::getMDIWindow: workspace=%08X", workspace);
+       DEBUG->print(/*Debug::D_CRITICAL,*/ "ApplicationWindow::getMDIWindow: workspace=%08X", workspace);
 
+// Here is the problem: Window isn't active...
        if (workspace)
        {
-               RS_DEBUG->print("ApplicationWindow::getMDIWindow: activeSubWindow=%08X", workspace->activeSubWindow());
+printf("ApplicationWindow::getMDIWindow: activeSubWindow =%08X\n", (uint)workspace->activeSubWindow());
+printf("ApplicationWindow::getMDIWindow: currentSubWindow=%08X\n", (uint)workspace->currentSubWindow());
+               DEBUG->print("ApplicationWindow::getMDIWindow: activeSubWindow=%08X", workspace->activeSubWindow());
                return (MDIWindow *)workspace->activeSubWindow();
        }
 
-       RS_DEBUG->print("ApplicationWindow::getMDIWindow: activeSubWindow=??? (workspace == NULL)");
+       DEBUG->print("ApplicationWindow::getMDIWindow: activeSubWindow=??? (workspace == NULL)");
        return NULL;
 }
 
 /**
- * Implementation from RS_MainWindowInterface (and QS_ScripterHostInterface).
+ * Implementation from MainWindowInterface (and QS_ScripterHostInterface).
  *
  * @return Pointer to the graphic view of the currently active document
  * window or NULL if no window is available.
@@ -4132,12 +3849,12 @@ MDIWindow * ApplicationWindow::getMDIWindow()
 }
 
 /**
- * Implementation from RS_MainWindowInterface (and QS_ScripterHostInterface).
+ * Implementation from MainWindowInterface (and QS_ScripterHostInterface).
  *
  * @return Pointer to the graphic document of the currently active document
  * window or NULL if no window is available.
  */
-/*virtual*/ RS_Document * ApplicationWindow::getDocument()
+/*virtual*/ Document * ApplicationWindow::getDocument()
 {
        MDIWindow * m = getMDIWindow();
 
@@ -4145,10 +3862,10 @@ MDIWindow * ApplicationWindow::getMDIWindow()
 }
 
 /**
- * Creates a new document. Implementation from RS_MainWindowInterface.
+ * Creates a new document. Implementation from MainWindowInterface.
  */
 /*virtual*/ void ApplicationWindow::createNewDocument(const QString & fileName/*= QString::null*/,
-       RS_Document * doc/*= NULL*/)
+       Document * doc/*= NULL*/)
 {
        slotFileNew(doc);
 
@@ -4156,6 +3873,7 @@ MDIWindow * ApplicationWindow::getMDIWindow()
                getDocument()->setFilename(fileName);
 }
 
+#if 0
 /**
  * Implementation from QG_MainWindowInterface.
  *
@@ -4173,6 +3891,7 @@ MDIWindow * ApplicationWindow::getMDIWindow()
 {
        return actionHandler;
 }
+#endif
 
 /**
  * Implementation from QG_MainWindowInterface.
@@ -4184,7 +3903,7 @@ MDIWindow * ApplicationWindow::getMDIWindow()
 #endif
 }
 
-#ifdef RS_SCRIPTING
+#ifdef SCRIPTING
 /**
  * @return Pointer to the qsa object.
  */