+void ApplicationWindow::PrintPreview(void)
+{
+ QPrintPreviewDialog * dlg = new QPrintPreviewDialog(this);
+
+ connect(dlg, SIGNAL(paintRequested(QPrinter *)), this, SLOT(HandlePrintRequest(QPrinter *)));
+
+ dlg->exec();
+}
+
+void ApplicationWindow::HandlePrintRequest(QPrinter * printer)
+{
+ QPainter qtPainter(printer);
+ Painter painter(&qtPainter);
+
+ // Save vars for screen
+ Point originSave = Global::origin;
+ double zoomSave = Global::zoom;
+ Vector screenSizeSave = Global::screenSize;
+
+ // Adjust zoom + origin to fit the paper (or NxM pages if we have 'em)
+ Rect r = drawing->GetObjectExtents((Object *)(&(drawing->document)));
+
+ QPageLayout pageLayout = printer->pageLayout();
+ QRect pageRect = pageLayout.paintRectPixels(printer->resolution());
+
+ Global::origin = r.BottomLeft();
+ Global::screenSize.x = pageRect.width();
+ Global::screenSize.y = pageRect.height();
+
+ double xScale = (double)pageRect.width() / r.Width();
+ double yScale = (double)pageRect.height() / r.Height();
+ Global::zoom = qMin(xScale, yScale);
+
+ if (xScale < yScale)
+ Global::origin.y -= (((double)pageRect.height() / Global::zoom) - r.Height()) / 2.0;
+ else
+ Global::origin.x -= (((double)pageRect.width() / Global::zoom) - r.Width()) / 2.0;
+
+ // Do object rendering...
+ for(int i=0; i<Global::numLayers; i++)
+ drawing->RenderObjects(&painter, drawing->document.objects, i);
+
+ // Restore vars
+ Global::origin = originSave;
+ Global::zoom = zoomSave;
+ Global::screenSize = screenSizeSave;
+}
+
+//
+// Right-click menu
+//
+void ApplicationWindow::contextMenuEvent(QContextMenuEvent * event)
+{
+ // Proof of concept, still need to code up the real thing
+ QMenu menu(this);
+
+ VPVector hovered = drawing->GetHovered();
+
+ if ((drawing->select.size() > 0) || (hovered.size() > 0))
+ {
+ QMenu * layerMenu = menu.addMenu("To layer");
+
+ layerAct.clear();
+
+ for(int i=0; i<Global::numLayers; i++)
+ {
+ QAction * act = new QAction(QIcon(), Global::layerName[i].c_str(), this);
+ act->setData(i);
+ layerMenu->addAction(act);
+ layerAct.append(act);
+ connect(act, SIGNAL(triggered()), this, SLOT(MoveToLayer()));
+ }
+ }
+
+ menu.addAction(mirrorAct);
+ menu.addAction(rotateAct);
+ menu.addAction(trimAct);
+ menu.exec(event->globalPos());
+}
+
+void ApplicationWindow::MoveToLayer(void)
+{
+ QAction * act = qobject_cast<QAction *>(sender());
+
+ drawing->MoveSelectedToLayer(act->data().toInt());
+ drawing->update();
+}
+
+void ApplicationWindow::UpdateFromCommand(void)
+{
+ cw->SetToolPrompt();
+ drawing->update();
+}