- Add blocks
- Add page layout
- Add fill/hatch to Objects
- - Fix zooming to be more intuitive
- Add other Dimension types, like radial, diametric, leader
- Restrict movement horizontal/vertical tool (keyboard shortcut?)
- Fix Arc manipulator. Idea: split edge handles so that the inner half controls
remove it and it only, or to cut the entity at other entities crossing)
- Make Architektonas an MDI application
- Parallel tool (be able to make copy of object that's parallel to original)
+ - Pen marker doesn't set attributes on the highlighted part of the group.
Stuff That's Done
-----------------
+ - Fix zooming to be more intuitive [Shamus 2021]
- Group selection (kinda done, needs more work though) [Shamus 2020]
- Take movement code out of Objects and put it into top level Container
(actually I think this should be more of the state code handling. Have to
- Mirror tool (started, needs actual mirroring implementation) (Rotate tool is
also done :-D) [Shamus 2013-09-01]
+
+Things to Ponder
+----------------
+
+Grouping items on different layers currently makes the items *not* on the current layer disappear. Not sure how this should be handled... Maybe we should honor the top level Container's attributes, and not the attributes of the contained objects?
#CONFIG += qt warn_on release
RESOURCES += res/architektonas.qrc
#LIBS += -Ldxflib/lib -ldxf
-QT += widgets
+QT += widgets printsupport
# We stuff all the intermediate crap into obj/ so it won't confuse us mere mortals ;-)
OBJECTS_DIR = obj
<file>editcopy2.png</file>
<file>editpaste2.png</file>
<file>pen-stamp.png</file>
+ <file>pen-dropper.png</file>
+ <file>cursor-marker.png</file>
+ <file>cursor-dropper.png</file>
+ <file>print-preview.png</file>
</qresource>
</RCC>
#include "applicationwindow.h"
+#include <QPrintPreviewDialog>
#include "about.h"
#include "blockwidget.h"
#include "drawingview.h"
#include "structs.h"
#include "utils.h"
-
// Class variables
DrawingView * ApplicationWindow::drawing;
-
ApplicationWindow::ApplicationWindow():
baseUnitInput(new QLineEdit),
dimensionSizeInput(new QLineEdit),
connect(drawing, SIGNAL(NeedZoomUpdate()), this, SLOT(UpdateZoom()));
}
-
void ApplicationWindow::closeEvent(QCloseEvent * event)
{
WriteSettings();
//Do we have a memory leak here if we don't delete the font in the Object???
}
-
void ApplicationWindow::FileNew(void)
{
// Warn the user if drawing has changed and hasn't been saved...
statusBar()->showMessage(tr("New drawing is ready."));
}
-
void ApplicationWindow::FileOpen(void)
{
QString filename = QFileDialog::getOpenFileName(this, tr("Open Drawing"),
statusBar()->showMessage(tr("Drawing loaded."));
}
-
void ApplicationWindow::FileSave(void)
{
if (documentName.isEmpty())
statusBar()->showMessage(tr("Drawing saved."));
}
-
void ApplicationWindow::FileSaveAs(void)
{
QString filename = QFileDialog::getSaveFileName(this, tr("Save Drawing As"),
}
}
+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);
+
+ // Do object rendering...
+ for(int i=0; i<Global::numLayers; i++)
+ {
+// if (Global::layerHidden[i] == false)
+ drawing->RenderObjects(&painter, drawing->document.objects, i);
+ }
+}
void ApplicationWindow::contextMenuEvent(QContextMenuEvent * event)
{
menu.exec(event->globalPos());
}
-
void ApplicationWindow::SnapToGridTool(void)
{
Global::snapToGrid = snapToGridAct->isChecked();
}
-
void ApplicationWindow::FixAngle(void)
{
Global::fixedAngle = fixAngleAct->isChecked();
}
-
void ApplicationWindow::FixLength(void)
{
Global::fixedLength = fixLengthAct->isChecked();
}
-
void ApplicationWindow::DeleteTool(void)
{
// For this tool, we check first to see if anything is selected. If so, we
SetInternalToolStates();
}
-
void ApplicationWindow::DimensionTool(void)
{
ClearUIToolStatesExcept(addDimensionAct);
SetInternalToolStates();
}
-
void ApplicationWindow::RotateTool(void)
{
ClearUIToolStatesExcept(rotateAct);
SetInternalToolStates();
}
-
void ApplicationWindow::MirrorTool(void)
{
ClearUIToolStatesExcept(mirrorAct);
SetInternalToolStates();
}
-
void ApplicationWindow::TrimTool(void)
{
ClearUIToolStatesExcept(trimAct);
SetInternalToolStates();
}
-
void ApplicationWindow::TriangulateTool(void)
{
ClearUIToolStatesExcept(triangulateAct);
SetInternalToolStates();
}
-
void ApplicationWindow::AddLineTool(void)
{
ClearUIToolStatesExcept(addLineAct);
SetInternalToolStates();
}
-
void ApplicationWindow::AddCircleTool(void)
{
ClearUIToolStatesExcept(addCircleAct);
SetInternalToolStates();
}
-
void ApplicationWindow::AddArcTool(void)
{
ClearUIToolStatesExcept(addArcAct);
SetInternalToolStates();
}
-
void ApplicationWindow::AddPolygonTool(void)
{
ClearUIToolStatesExcept(addPolygonAct);
SetInternalToolStates();
}
-
void ApplicationWindow::AddSplineTool(void)
{
ClearUIToolStatesExcept(addSplineAct);
SetInternalToolStates();
}
-
void ApplicationWindow::ZoomInTool(void)
{
double zoomFactor = 1.20;
UpdateZoom();
}
-
void ApplicationWindow::ZoomOutTool(void)
{
double zoomFactor = 1.20;
UpdateZoom();
}
-
void ApplicationWindow::UpdateZoom(void)
{
// And now, a bunch of heuristics to select the right grid size--autogrid!
else
Global::gridSpacing = 0.015625;
- drawing->SetGridSize((double)(Global::gridSpacing * Global::zoom));
+// drawing->SetGridSize((double)(Global::gridSpacing * Global::zoom));
drawing->update();
zoomIndicator->setText(QString("Zoom: %1% Grid: %2\" BU: Inch").arg(Global::zoom * 100.0).arg(Global::gridSpacing));
// baseUnitInput->setText(QString("%1").arg(Global::gridSpacing));
}
-
void ApplicationWindow::ClearUIToolStatesExcept(QAction * exception)
{
QAction * actionList[] = {
}
}
-
void ApplicationWindow::SetInternalToolStates(void)
{
// We can be sure that if we've come here, then either an active tool is
drawing->update();
}
-
void ApplicationWindow::HelpAbout(void)
{
aboutWin->show();
}
-
void ApplicationWindow::Settings(void)
{
SettingsDialog dlg(this);
WriteSettings();
}
-
//
// Group a bunch of selected objects (which can include other groups) together
// or ungroup a selected group.
drawing->update();
}
-
void ApplicationWindow::HandleConnection(void)
{
#if 0
#endif
}
-
void ApplicationWindow::HandleDisconnection(void)
{
}
-
-void ApplicationWindow::HandleGridSizeInPixels(int size)
+void ApplicationWindow::HandleGridSizeInPixels(int /*size*/)
{
- drawing->SetGridSize((uint32_t)size);
+// drawing->SetGridSize((uint32_t)size);
drawing->update();
}
-
void ApplicationWindow::HandleGridSizeInBaseUnits(QString text)
{
// Parse the text...
// Painter::zoom = drawing->gridPixels / drawing->gridSpacing;
Global::gridSpacing = value;
Global::zoom = drawing->gridPixels / Global::gridSpacing;
- drawing->UpdateGridBackground();
+// drawing->UpdateGridBackground();
drawing->update();
}
-
void ApplicationWindow::HandleDimensionSize(QString text)
{
/*
}
}
-
void ApplicationWindow::EditCut(void)
{
if (drawing->select.size() > 0)
}
}
-
void ApplicationWindow::EditPaste(void)
{
if (clipboard.size() > 0)
}
}
-
//
// Select all *visible* objects. If an object is on a layer that is not
// visible, skip it.
drawing->update();
}
-
void ApplicationWindow::CreateActions(void)
{
exitAct = CreateAction(tr("&Quit"), tr("Quit"), tr("Exits the application."),
selectAllAct = CreateAction(tr("Select &All"), tr("Select All Objects"), tr("Select all objects in the drawing."), QIcon(), QKeySequence(tr("Ctrl+a")));
connect(selectAllAct, SIGNAL(triggered()), this, SLOT(SelectAllObjects()));
+ printPreviewAct = CreateAction(tr("&Print Preview"), tr("Print Preview"), tr("Shows preview of printing operation."), QIcon(":/res/print-preview.png"), QKeySequence(tr("Ctrl+p")));
+ connect(printPreviewAct, SIGNAL(triggered()), this, SLOT(PrintPreview()));
+
//Hm. I think we'll have to have separate logic to do the "Radio Group Toolbar" thing...
// Yup, in order to turn them off, we'd have to have an "OFF" toolbar button. Ick.
/* QActionGroup * group = new QActionGroup(this);
group->addAction(addArcAct);//*/
}
-
//
// Consolidates action creation from a multi-step process to a single-step one.
//
return action;
}
-
//
// This is essentially the same as the previous function, but this allows more
// than one key sequence to be added as key shortcuts.
return action;
}
-
void ApplicationWindow::CreateMenus(void)
{
QMenu * menu = menuBar()->addMenu(tr("&File"));
menu->addAction(fileSaveAsAct);
menu->addAction(fileCloseAct);
menu->addSeparator();
+ menu->addAction(printPreviewAct);
+ menu->addSeparator();
menu->addAction(exitAct);
menu = menuBar()->addMenu(tr("&View"));
menu->addAction(aboutAct);
}
-
void ApplicationWindow::CreateToolbars(void)
{
QToolBar * toolbar = addToolBar(tr("File"));
connect(pw, SIGNAL(WidthSelected(float)), drawing, SLOT(HandlePenWidth(float)));
connect(pw, SIGNAL(StyleSelected(int)), drawing, SLOT(HandlePenStyle(int)));
connect(pw, SIGNAL(ColorSelected(uint32_t)), drawing, SLOT(HandlePenColor(uint32_t)));
- connect(pw, SIGNAL(StampSelected(void)), drawing, SLOT(HandlePenStamp(void)));
+// connect(pw, SIGNAL(StampSelected(void)), drawing, SLOT(HandlePenStamp(QAction *)));
+ connect(pw->tbStamp, SIGNAL(triggered(QAction *)), drawing, SLOT(HandlePenStamp(QAction *)));
+ connect(pw->tbDropper, SIGNAL(triggered(QAction *)), drawing, SLOT(HandlePenDropper(QAction *)));
}
-
void ApplicationWindow::ReadSettings(void)
{
QPoint pos = settings.value("pos", QPoint(200, 200)).toPoint();
restoreState(settings.value("windowState").toByteArray());
}
-
void ApplicationWindow::WriteSettings(void)
{
settings.setValue("pos", pos());
settings.setValue("useAntialiasing", drawing->useAntialiasing);
settings.setValue("snapToGrid", snapToGridAct->isChecked());
}
-
#define __APPLICATIONWINDOW_H__
#include <QtWidgets>
+#include <QPrinter>
// Forward declarations
void FileOpen(void);
void FileSave(void);
void FileSaveAs(void);
+ void PrintPreview(void);
+ void HandlePrintRequest(QPrinter *);
void SnapToGridTool(void);
void FixAngle(void);
void FixLength(void);
QAction * editCopyAct;
QAction * editPasteAct;
QAction * selectAllAct;
+ QAction * printPreviewAct;
std::vector<void *> clipboard;
#include "global.h"
#include "mathconstants.h"
#include "painter.h"
+#include "penwidget.h"
#include "structs.h"
#include "utils.h"
-
#define BACKGROUND_MAX_SIZE 512
-
DrawingView::DrawingView(QWidget * parent/*= NULL*/): QWidget(parent),
// The value in the settings file will override this.
useAntialiasing(true), numHovered(0), shiftDown(false),
ctrlDown(false), altDown(false),
gridBackground(BACKGROUND_MAX_SIZE, BACKGROUND_MAX_SIZE),
- scale(1.0), offsetX(-10), offsetY(-10), document(true),
+ scale(1.0), offsetX(-10), offsetY(-10), supressSelected(false),
+ document(true),
gridPixels(0), collided(false), scrollDrag(false), hoverPointValid(false),
hoveringIntersection(false), dragged(NULL), draggingObject(false),
angleSnap(false), dirty(false)
setBackgroundRole(QPalette::Base);
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
+ curMarker = QCursor(QPixmap(":/res/cursor-marker.png"), 1, 18);
+ curDropper = QCursor(QPixmap(":/res/cursor-dropper.png"), 1, 20);
+
Global::gridSpacing = 12.0; // In base units (inch is default)
Line * line = new Line(Vector(5, 5), Vector(50, 40), 2.0, 0xFF7F00, LSDash);
we do! :-)
*/
- gridPixels = 12; //tmp
- SetGridSize(12.0); // This is in pixels
+// gridPixels = 12; //tmp???
+// SetGridSize(12.0); // This is in pixels
}
-
void DrawingView::DrawBackground(Painter * painter)
{
Point ul = Painter::QtToCartesianCoords(Vector(0, 0));
painter->DrawHLine(bottomy + i);
}
-
void DrawingView::DrawSubGrid(Painter * painter, uint32_t color, double step, Vector start, Vector size)
{
painter->SetPen(color, 1, 1);
painter->DrawHLine(start.y + i);
}
-
+#if 0
void DrawingView::SetGridSize(uint32_t size)
{
#if 0
#endif
}
-
void DrawingView::UpdateGridBackground(void)
{
#if 0
#endif
}
-
void DrawingView::SetGridSize(double size)
{
#if 0
setPalette(pal);
#endif
}
-
+#endif
//
// Basically, we just make a single pass through the Container. If the layer #
update();
}
-
void DrawingView::HandleLayerToggle(void)
{
// A layer's visibility was toggled, so update the screen...
update();
}
-
//
// A layer was moved up or down in the layer list, so we have to swap the
// document's object's layer numbers in the layers that were swapped.
//
void DrawingView::HandleLayerSwap(int layer1, int layer2)
{
-// !!! FIX !!! This doesn't properly handle container contents...
//printf("DrawingView: Swapping layers %i and %i.\n", layer1, layer2);
- for(VPVectorIter i=document.objects.begin(); i!=document.objects.end(); i++)
+ HandleLayerSwap(layer1, layer2, document.objects);
+}
+
+/*
+We can roll this into the main one above, by having the LayerWidget's emit() call sending NULL for the VPVector, which we can test for and set to document.objects to grab the top layer. Or, keep it a top level call and a recursive call. Which is worse? :-P
+*/
+void DrawingView::HandleLayerSwap(int layer1, int layer2, VPVector & v)
+{
+ for(VPVectorIter i=v.begin(); i!=v.end(); i++)
{
Object * obj = (Object *)(*i);
obj->layer = layer2;
else if (obj->layer == layer2)
obj->layer = layer1;
+
+ if (obj->type == OTContainer)
+ HandleLayerSwap(layer1, layer2, ((Container *)obj)->objects);
}
}
-
void DrawingView::HandlePenWidth(float width)
{
for(VPVectorIter i=select.begin(); i!=select.end(); i++)
Object * obj = (Object *)(*i);
obj->thickness = width;
}
-}
+ supressSelected = true;
+ update();
+}
void DrawingView::HandlePenStyle(int style)
{
Object * obj = (Object *)(*i);
obj->style = style;
}
-}
+ supressSelected = true;
+ update();
+}
void DrawingView::HandlePenColor(uint32_t color)
{
Object * obj = (Object *)(*i);
obj->color = color;
}
-}
+ supressSelected = true;
+ update();
+}
-void DrawingView::HandlePenStamp(void)
+void DrawingView::HandlePenStamp(QAction * action)
{
- VPVector flat = Flatten(select);
+ PenWidget * pw = (PenWidget *)action->parentWidget();
+ pw->dropperAction->setChecked(false);
+ Global::penDropper = false;
+ Global::penStamp = action->isChecked();
- for(VPVectorIter i=flat.begin(); i!=flat.end(); i++)
- {
- Object * obj = (Object *)(*i);
-
- if (obj->type != OTText)
- obj->thickness = Global::penWidth;
+ if (Global::penStamp)
+ setCursor(curMarker);
+ else
+ setCursor(Qt::ArrowCursor);
- obj->style = Global::penStyle;
- obj->color = Global::penColor;
- }
+ if (Global::penStamp == false)
+ ClearSelected(document.objects);
update();
}
+void DrawingView::HandlePenDropper(QAction * action)
+{
+ PenWidget * pw = (PenWidget *)action->parentWidget();
+ pw->stampAction->setChecked(false);
+ Global::penStamp = false;
+ Global::penDropper = action->isChecked();
+
+ if (Global::penDropper)
+ setCursor(curDropper);
+ else
+ setCursor(Qt::ArrowCursor);
+
+ update();
+}
QPoint DrawingView::GetAdjustedMousePosition(QMouseEvent * event)
{
return QPoint(offsetX + event->x(), offsetY + (size().height() - event->y()));
}
-
QPoint DrawingView::GetAdjustedClientPosition(int x, int y)
{
// VOODOO ALERT (ON Y COMPONENT!!!!) (eh?)
return QPoint(-offsetX + x, (size().height() - (-offsetY + y)) * +1.0);
}
-
void DrawingView::focusOutEvent(QFocusEvent * /*event*/)
{
// printf("DrawingView::focusOutEvent()...\n");
setCursor(Qt::ArrowCursor);
}
+void DrawingView::focusInEvent(QFocusEvent * /*event*/)
+{
+ if (Global::penStamp)
+ setCursor(curMarker);
+ else if (Global::penDropper)
+ setCursor(curDropper);
+//FocusOut already set this...
+// else
+// setCursor(Qt::ArrowCursor);
+}
void DrawingView::paintEvent(QPaintEvent * /*event*/)
{
painter.DrawInformativeText(informativeText);
}
-
//
// Renders objects in the passed in vector
//
painter->SetPen(obj->color, Global::zoom * scaledThickness, obj->style);
painter->SetBrush(obj->color);
- if (obj->selected || obj->hitObject)
+ // penStamp supresses object highlighting, so that changes can be seen.
+ if (supressSelected || Global::penStamp)
+ {
+ if (obj->hitObject)
+ {
+ painter->SetPen(Global::penColor, Global::zoom * Global::scale * Global::penWidth, Global::penStyle);
+ painter->SetBrush(Global::penColor);
+ }
+ }
+ else if (obj->selected || obj->hitObject)
painter->SetPen(0xFF0000, Global::zoom * scaledThickness, LSDash);
}
{
// Containers require recursive rendering...
Container * c = (Container *)obj;
-printf("About to render container: # objs=%i, layer=%i\n", (*c).objects.size(), layer);
+//printf("About to render container: # objs=%i, layer=%i\n", (*c).objects.size(), layer);
RenderObjects(painter, (*c).objects, layer, ignoreLayer);
//printf("Container extents: <%lf, %lf>, <%lf, %lf>\nsize: %i\n", r.l, r.t, r.r, r.b, c->objects.size());
break;
}
}
-}
+ supressSelected = false;
+}
//
// This toggles the selection being hovered (typically, only 1 object)
}
}
-
VPVector DrawingView::GetSelection(void)
{
VPVector v;
return v;
}
-
VPVector DrawingView::GetHovered(void)
{
VPVector v;
return v;
}
-
void DrawingView::resizeEvent(QResizeEvent * /*event*/)
{
Global::screenSize = Vector(size().width(), size().height());
- UpdateGridBackground();
+// UpdateGridBackground();
}
-
void DrawingView::ToolHandler(int mode, Point p)
{
// Drop angle snap until it's needed
ParallelHandler(mode, p);
}
-
void DrawingView::ToolDraw(Painter * painter)
{
if (Global::tool == TTLine)
}
}
-
void DrawingView::LineHandler(int mode, Point p)
{
switch (mode)
}
}
-
void DrawingView::CircleHandler(int mode, Point p)
{
switch (mode)
}
}
-
void DrawingView::ArcHandler(int mode, Point p)
{
switch (mode)
}
}
-
void DrawingView::RotateHandler(int mode, Point p)
{
switch (mode)
}
}
-
void DrawingView::MirrorHandler(int mode, Point p)
{
switch (mode)
}
}
-
void DrawingView::DimensionHandler(int mode, Point p)
{
switch (mode)
}
}
-
void DrawingView::TriangulateHandler(int mode, Point/*p*/)
{
switch (mode)
}
}
-
void DrawingView::TrimHandler(int mode, Point p)
{
/*
}
}
-
void DrawingView::ParallelHandler(int mode, Point /*p*/)
{
switch (mode)
}
}
-
void DrawingView::mousePressEvent(QMouseEvent * event)
{
if (event->button() == Qt::LeftButton)
//printf("mousePressEvent::numHovered > 0 (hover2[0]=$%llx, type=%s)\n", dragged, objName[dragged->type]);
// Alert the pen widget
- emit ObjectSelected(dragged);
+// Maybe do this with an eyedropper tool on the pen bar? [YES]
+// emit ObjectSelected(dragged);
+ if (Global::penDropper)
+ {
+ Global::penColor = dragged->color;
+ Global::penWidth = dragged->thickness;
+ Global::penStyle = dragged->style;
+ emit ObjectSelected(dragged);
+ ClearSelected(document.objects);
+ return;
+ }
+
+ if (Global::penStamp)
+ {
+ dragged->color = Global::penColor;
+ dragged->thickness = Global::penWidth;
+ dragged->style = Global::penStyle;
+ return;
+ }
// See if anything is using just a straight click on a handle
if (HandleObjectClicked())
}
}
-
void DrawingView::mouseMoveEvent(QMouseEvent * event)
{
// It seems that wheelEvent() triggers this for some reason...
delta.y = -delta.y;
Global::origin -= delta;
- UpdateGridBackground();
+// UpdateGridBackground();
update();
oldPoint = point;
return;
// Make sure previously selected objects stay selected (CTRL held)
for(VPVectorIter i=select.begin(); i!=select.end(); i++)
- ((Object *)(*i))->selected = true;
+ {
+ // Make sure *not* to select items on hidden layers
+ if (Global::layerHidden[((Object *)(*i))->layer] == false)
+ ((Object *)(*i))->selected = true;
+ }
update();
return;
update();
}
-
void DrawingView::mouseReleaseEvent(QMouseEvent * event)
{
if (event->button() == Qt::LeftButton)
else if (event->button() == Qt::MiddleButton)
{
scrollDrag = false;
- setCursor(Qt::ArrowCursor);
+
+ if (Global::penStamp)
+ setCursor(curMarker);
+ else if (Global::penDropper)
+ setCursor(curDropper);
+ else
+ setCursor(Qt::ArrowCursor);
+
// Need to convert this, since it's in Qt coordinates (for wheelEvent)
oldPoint = Painter::QtToCartesianCoords(oldPoint);
}
}
-
void DrawingView::wheelEvent(QWheelEvent * event)
{
double zoomFactor = 1.20;
emit(NeedZoomUpdate());
}
-
void DrawingView::keyPressEvent(QKeyEvent * event)
{
bool oldShift = shiftDown;
}
}
-
void DrawingView::keyReleaseEvent(QKeyEvent * event)
{
bool oldShift = shiftDown;
if (oldAlt != altDown)
{
scrollDrag = false;
- setCursor(Qt::ArrowCursor);
+
+ if (Global::penStamp)
+ setCursor(curMarker);
+ else if (Global::penDropper)
+ setCursor(curDropper);
+ else
+ setCursor(Qt::ArrowCursor);
}
}
-
//
// This looks strange, but it's really quite simple: We want a point that's
// more than half-way to the next grid point to snap there while conversely we
return point;
}
-
Point DrawingView::SnapPointToAngle(Point point)
{
// Snap to a single digit angle (using toolpoint #1 as the center)
return point;
}
-
Rect DrawingView::GetObjectExtents(Object * obj)
{
// Default to empty rect, if object checks below fail for some reason
return rect;
}
-
void DrawingView::CheckObjectBounds(void)
{
VPVectorIter i;
}
}
-
bool DrawingView::HitTestObjects(Point point)
{
VPVectorIter i;
return needUpdate;
}
-
bool DrawingView::HitTest(Object * obj, Point point)
{
bool needUpdate = false;
return needUpdate;
}
-
bool DrawingView::HandleObjectClicked(void)
{
if (dragged->type == OTDimension)
return false;
}
-
void DrawingView::HandleObjectMovement(Point point)
{
Point delta = point - oldPoint;
}
}
-
void DrawingView::AddDimensionTo(void * o)
{
Object * obj = (Object *)o;
break;
}
}
-
public:
void DrawBackground(Painter *);
- void SetGridSize(uint32_t);
- void SetGridSize(double);
- void UpdateGridBackground(void);
- void UpdateGridBackgroundF(void);
+// void SetGridSize(uint32_t);
+// void SetGridSize(double);
+// void UpdateGridBackground(void);
+// void UpdateGridBackgroundF(void);
Point SnapPointToGrid(Point);
Point SnapPointToAngle(Point);
void RenderObjects(Painter *, VPVector &, int, bool ignoreLayer = false);
void HandlePenWidth(float);
void HandlePenStyle(int);
void HandlePenColor(uint32_t);
- void HandlePenStamp(void);
+ void HandlePenStamp(QAction *);
+ void HandlePenDropper(QAction *);
signals:
void ObjectHovered(Object *);
protected:
void focusOutEvent(QFocusEvent * event);
+ void focusInEvent(QFocusEvent * event);
void paintEvent(QPaintEvent * event);
void resizeEvent(QResizeEvent * event);
void mousePressEvent(QMouseEvent * event);
void keyReleaseEvent(QKeyEvent * event);
private:
+ void HandleLayerSwap(int, int, VPVector &);
void DrawSubGrid(Painter *, uint32_t, double, Vector, Vector);
QPoint GetAdjustedMousePosition(QMouseEvent * event);
QPoint GetAdjustedClientPosition(int x, int y);
QPixmap gridBackground;
double scale; // Window scaling factor
int32_t offsetX, offsetY; // Window offsets
+ bool supressSelected;
+ QCursor curMarker;
+ QCursor curDropper;
public:
Container document;
uint32_t gridPixels; // Grid size in pixels
int Global::penStyle = 1;
uint32_t Global::penColor = 0x000000;
bool Global::penStamp = false;
+bool Global::penDropper = false;
Point Global::intersectPoint[16]; // Overkill, yes
double Global::intersectParam[16]; // Ditto
static int penStyle;
static uint32_t penColor;
static bool penStamp;
+ static bool penDropper;
static Point intersectPoint[16]; // Overkill, yes
static double intersectParam[16]; // Ditto
{
li->name->setText(result);
- int layer = (Global::numLayers - Global::activeLayer) - 1;
- std::vector<std::string>::iterator i = Global::layerName.begin() + layer;
+ // We don't reverse the layer # here, like elsewhere, because we're
+ // using the layer # directly instead of having to translate it from
+ // the widget.
+ std::vector<std::string>::iterator i = Global::layerName.begin() + Global::activeLayer;
(*i) = result.toUtf8().data();
}
}
#include "global.h"
#include "mathconstants.h"
-
Painter::Painter(QPainter * p/*= NULL*/): painter(p)
{
}
-
Painter::~Painter()
{
}
-
Vector Painter::CartesianToQtCoords(Vector v)
{
// Convert regular Cartesian coordinates to the inverted Y-axis Qt
return Vector((v.x - Global::origin.x) * Global::zoom, Global::screenSize.y - ((v.y - Global::origin.y) * Global::zoom));
}
-
Vector Painter::QtToCartesianCoords(Vector v)
{
// Convert screen location, with inverted Y-axis coordinates, to regular
*/
}
-
void Painter::SetRenderHint(int hint)
{
if (!painter)
painter->setRenderHint((QPainter::RenderHint)hint);
}
-
void Painter::SetPen(QPen pen)
{
if (!painter)
painter->setPen(pen);
}
-
void Painter::SetPen(uint32_t color, float size/*= 0*/, int style/*= 0*/)
{
if (!painter)
size, (Qt::PenStyle)style));
}
-
void Painter::SetBrush(QBrush brush)
{
if (!painter)
painter->setBrush(brush);
}
-
void Painter::SetBrush(uint32_t color)
{
if (!painter)
painter->setBrush(QBrush(QColor(color >> 16, (color >> 8) & 0xFF, color & 0xFF, 255)));
}
-
void Painter::SetFont(QFont font)
{
if (!painter)
painter->setFont(font);
}
-
void Painter::DrawAngledText(Vector center, double angle, QString text, double size)
{
if (!painter)
painter->restore();
}
-
//
// Draw angled text. Draws text using point p as the upper left corner.
// Size is point size, angle is in radians (defaults to 0).
p = CartesianToQtCoords(p);
painter->setFont(QFont("Arial", Global::zoom * size));
- int textWidth = QFontMetrics(painter->font()).width(text);
+ int textWidth = QFontMetrics(painter->font()).horizontalAdvance(text);
int textHeight = QFontMetrics(painter->font()).height();
QRectF textBox(0, 0, textWidth, textHeight);
painter->restore();
}
-
//
// Return the non-rotated rectangle containing the extents of the text in
// Cartesian coordiates (starting from <0, 0>, the lower left hand side)
return Rect();
painter->setFont(QFont("Arial", Global::zoom * size));
- int textWidth = QFontMetrics(painter->font()).width(text);
+ int textWidth = QFontMetrics(painter->font()).horizontalAdvance(text);
int textHeight = QFontMetrics(painter->font()).height();
- Point measured((double)textWidth / Global::zoom, (double)textHeight / Global::zoom);// = QtToCartesianCoords(Point(textWidth, textHeight));
-//printf("QFontMetrics w/h=%i/%i, measured=%lf/%lf\n", textWidth, textHeight, measured.x, measured.y);
+ Point measured((double)textWidth / Global::zoom, (double)textHeight / Global::zoom);
return Rect(Point(0, 0), measured);
}
-
void Painter::DrawArc(Vector center, double radius, double startAngle, double span)
{
if (!painter)
painter->drawArc(rectangle, angle1, angle2);
}
-
void Painter::DrawEllipse(Vector center, double axis1, double axis2)
{
if (!painter)
painter->drawEllipse(QPointF(center.x, center.y), axis1 * Global::zoom, axis2 * Global::zoom);
}
-
// This function is for drawing object handles without regard for zoom level;
// we don't want our object handle size to depend on the zoom level!
void Painter::DrawHandle(Vector center)
painter->drawEllipse(QPointF(center.x, center.y), 4.0, 4.0);
}
-
// This function is for drawing object handles without regard for zoom level;
// we don't want our object handle size to depend on the zoom level!
void Painter::DrawSmallHandle(Vector center)
painter->drawEllipse(QPointF(center.x, center.y), 2.0, 2.0);
}
-
// This function is for drawing feedback points without regard for zoom level;
// we don't want our feedback point size to depend on the zoom level!
void Painter::DrawCross(Vector point)
painter->drawLine(point.x, point.y - 8.0, point.x, point.y + 8.0);
}
-
// This function is for drawing feedback points without regard for zoom level;
// we don't want our feedback point size to depend on the zoom level!
void Painter::DrawRectCorners(Rect rect)
}
-
// This function is for drawing object handles without regard for zoom level;
// we don't want our object handle size to depend on the zoom level!
void Painter::DrawArrowHandle(Vector center, double angle)
painter->drawPolygon(arrow);
}
-
// This function is for drawing object handles without regard for zoom level;
// we don't want our object handle size to depend on the zoom level!
void Painter::DrawArrowToLineHandle(Vector center, double angle)
painter->drawLine(p2.x, p2.y, p3.x, p3.y);
}
-
void Painter::DrawLine(int x1, int y1, int x2, int y2)
{
if (!painter)
painter->drawLine(v1.x, v1.y, v2.x, v2.y);
}
-
void Painter::DrawLine(Vector v1, Vector v2)
{
if (!painter)
painter->drawLine(QPointF(v1.x, v1.y), QPointF(v2.x, v2.y));
}
-
void Painter::DrawHLine(double ypos)
{
double width = Global::screenSize.x / Global::zoom;
painter->drawLine(QPointF(v1.x, v1.y), QPointF(v2.x, v2.y));
}
-
void Painter::DrawVLine(double xpos)
{
double height = Global::screenSize.y / Global::zoom;
painter->drawLine(QPointF(v1.x, v1.y), QPointF(v2.x, v2.y));
}
-
void Painter::DrawPoint(int x, int y)
{
if (!painter)
painter->drawPoint(v.x, v.y);
}
-
// The rect passed in is in Qt coordinates...
void Painter::DrawRoundedRect(QRectF rect, double radiusX, double radiusY)
{
painter->drawRoundedRect(rect, radiusX, radiusY);
}
-
// The rect passed in is in Cartesian but we want to pad it by a set number of
// pixels (currently set at 8), so the pad looks the same regardless of zoom.
void Painter::DrawPaddedRect(QRectF rect)
painter->drawRect(screenRect);
}
-
void Painter::DrawRect(QRectF rect)
{
if (!painter)
painter->drawRect(screenRect);
}
-
void Painter::DrawText(QRectF rect, int type, QString text)
{
if (!painter)
painter->drawText(rect, (Qt::AlignmentFlag)type, text);
}
-
void Painter::DrawArrowhead(Vector head, Vector tail, double size)
{
if (!painter)
painter->drawPolygon(arrow);
}
-
// Point is given in Cartesian coordinates
void Painter::DrawCrosshair(Vector point)
{
painter->drawLine(screenPoint.x, 0, screenPoint.x, Global::screenSize.y);
}
-
void Painter::DrawInformativeText(QString text)
{
if (!painter)
painter->setPen(pen);
painter->drawText(bounds, Qt::AlignVCenter, text);
}
-
};
#endif // __PAINTER_H__
-
//
//maybe add a button to have it stamp attributes on all objects clicked on? [added Global::penStamp to facilitate this.]
//need to add to drawingview the ability to use attributes on new objects [DONE]
-//need to override the selection so you can see the attributes effects immediately when they are changed instead of having to deselect them to see
-
+//need to override the selection so you can see the attributes effects immediately when they are changed instead of having to deselect them to see [IN PROGRESS]
#include "penwidget.h"
-
-PenWidget::PenWidget(void): QWidget(), r(0), g(0), b(0), programChange(false)
+PenWidget::PenWidget(void): QWidget(), width(new QLineEdit("1.0")), red(new QLineEdit("00")), green(new QLineEdit("00")), blue(new QLineEdit("00")), style(new QComboBox), r(0), g(0), b(0), programChange(false), stampAction(new QAction(QIcon(":/res/pen-stamp.png"), tr(""), this)), dropperAction(new QAction(QIcon(":/res/pen-dropper.png"), tr(""), this)), tbStamp(new QToolButton(this)), tbDropper(new QToolButton(this))
{
- width = new QLineEdit("1.0");
- red = new QLineEdit("00");
- green = new QLineEdit("00");
- blue = new QLineEdit("00");
- style = new QComboBox;
-
QLabel * l1 = new QLabel(tr("Width:"));
QLabel * l2 = new QLabel(tr("RGB:"));
QLabel * l3 = new QLabel(tr("Style:"));
- QToolButton * qtb = new QToolButton(this);
- QAction * action = new QAction(QIcon(":/res/pen-stamp.png"), tr(""), this);
- action->setToolTip(tr("Stamp Selected"));
- action->setStatusTip(tr("Stamp selected objects with pen attributes."));
- action->setShortcut(QKeySequence(tr("p,p")));
-// action->setCheckable(checkable);
- qtb->setDefaultAction(action);
+ stampAction->setToolTip(tr("Stamp Selected"));
+ stampAction->setStatusTip(tr("Stamp selected objects with pen attributes."));
+ stampAction->setShortcut(QKeySequence(tr("p,p")));
+ stampAction->setCheckable(true);
+ tbStamp->setDefaultAction(stampAction);
+
+ dropperAction->setToolTip(tr("Color Picker"));
+ dropperAction->setStatusTip(tr("Get pen attributes from objects."));
+ dropperAction->setShortcut(QKeySequence(tr("d,d")));
+ dropperAction->setCheckable(true);
+ tbDropper->setDefaultAction(dropperAction);
style->insertItem(1, tr("Solid"));
style->insertItem(2, tr("Dash"));
style->setToolTip(tr("Sets pen style"));
QHBoxLayout * hbox1 = new QHBoxLayout;
- hbox1->addWidget(l1, 0, Qt::AlignLeft);
- hbox1->addWidget(width, 0, Qt::AlignLeft);
hbox1->addWidget(l2, 0, Qt::AlignLeft);
hbox1->addWidget(red, 0, Qt::AlignLeft);
hbox1->addWidget(green, 0, Qt::AlignLeft);
hbox1->addWidget(blue, 0, Qt::AlignLeft);
+ hbox1->addWidget(l1, 0, Qt::AlignLeft);
+ hbox1->addWidget(width, 0, Qt::AlignLeft);
hbox1->addWidget(l3, 0, Qt::AlignLeft);
hbox1->addWidget(style, 0, Qt::AlignLeft);
- hbox1->addWidget(qtb, 0, Qt::AlignLeft);
+ hbox1->addWidget(tbStamp, 0, Qt::AlignLeft);
+ hbox1->addWidget(tbDropper, 0, Qt::AlignLeft);
hbox1->addStretch(1);
setLayout(hbox1);
connect(green, SIGNAL(textEdited(QString)), this, SLOT(HandleGreenSelected(QString)));
connect(blue, SIGNAL(textEdited(QString)), this, SLOT(HandleBlueSelected(QString)));
connect(style, SIGNAL(currentIndexChanged(int)), this, SLOT(HandleStyleSelected(int)));
- connect(qtb, SIGNAL(triggered(QAction *)), this, SLOT(HandleStamp(QAction *)));
}
-
PenWidget::~PenWidget()
{
}
-
void PenWidget::SetFields(Object * obj)
{
// Sanity check
programChange = false;
}
-
void PenWidget::HandleWidthSelected(QString text)
{
// Parse the text in the control
emit WidthSelected(Global::penWidth);
}
-
void PenWidget::HandleStyleSelected(int selected)
{
// Change was programmatic, don't do anything
emit StyleSelected(Global::penStyle);
}
-
void PenWidget::HandleRedSelected(QString text)
{
// Parse the text in the control
emit ColorSelected(Global::penColor);
}
-
void PenWidget::HandleGreenSelected(QString text)
{
// Parse the text in the control
emit ColorSelected(Global::penColor);
}
-
void PenWidget::HandleBlueSelected(QString text)
{
// Parse the text in the control
Global::penColor = (r << 16) | (g << 8) | b;
emit ColorSelected(Global::penColor);
}
-
-
-void PenWidget::HandleStamp(QAction * /* action */)
-{
- emit StampSelected();
-}
-
#include <QtWidgets>
#include "structs.h"
-
class PenWidget: public QWidget
{
Q_OBJECT
void HandleRedSelected(QString);
void HandleGreenSelected(QString);
void HandleBlueSelected(QString);
- void HandleStamp(QAction *);
+// void HandleStamp(QAction *);
+// void HandleDropper(QAction *);
signals:
void WidthSelected(float);
void StyleSelected(int);
void ColorSelected(uint32_t);
void StampSelected(void);
+ void DropperSelected(void);
private:
QLineEdit * width;
QComboBox * style;
int r, g, b;
bool programChange;
+
+ public:
+ QAction * stampAction;
+ QAction * dropperAction;
+ QToolButton * tbStamp;
+ QToolButton * tbDropper;
};
#endif // __PENWIDGET_H__
-
#include <string.h> // For memcpy()
#include "geometry.h"
-
//
// Copy objects in one vector to another, creating copies and placing them in
// the other vector. Clearing & etc. of vectors is responsibility of the caller!
}
}
-
VPVector CopyObjects(VPVector & src)
{
VPVector copy;
return copy;
}
-
//
// Create a copy of the passed in object.
//
return (Object *)newObject;
}
-
//
// Create a copy of the passed in object. This version calls the second
// version of CopyObjects() (with one parameter and a vector return value).
return (Object *)newObject;
}
-
void MoveSelectedObjectsTo(VPVector & dest, VPVector & from)
{
VPVectorIter i = from.begin();
}
}
-
VPVector MoveSelectedObjectsFrom(VPVector & from)
{
VPVector objects;
return objects;
}
-
//hmm, this won't work, as these are just pointers...
//[should work now]
void CopySelectedObjectsTo(VPVector & dest, VPVector & from)
}
}
-
VPVector CopySelectedObjects(VPVector & src)
{
VPVector copy;
return copy;
}
-
void AddObjectsTo(VPVector & dest, VPVector & from)
{
for(VPVectorIter i=from.begin(); i!=from.end(); i++)
dest.push_back(*i);
}
-
void ClearSelected(VPVector & v)
{
for(VPVectorIter i=v.begin(); i!=v.end(); i++)
((Object *)(*i))->selected = false;
}
-
//
// Select all *visible* objects. If an object's layer is invisible, skip it.
//
}
}
-
//
// Recursively go down thru the Container's vectors, deleting all the objects
// contained therein. Once that is done, the main Container can be deleted.
v.clear();
}
-
void DeleteSelectedObjects(VPVector & v)
{
VPVectorIter i = v.begin();
}
}
-
//
// This is used to remove selected objects from one container in order to move
// them to a different container.
}
}
-
void SavePointsFrom(VPVector & v, std::vector<Object> & save)
{
save.clear();
}
}
-
void RestorePointsTo(VPVector & v, std::vector<Object> & s)
{
std::vector<Object>::iterator i;
}
}
-
void RestorePointsTo(VPVector & v, VPVector & s)
{
for(VPVectorIter i=s.begin(), j=v.begin(); i!=s.end(); i++, j++)
}
}
-
//
// Translate a single object; it it's a Container, translate all its contents,
// including subcontainers.
obj->p[1] += delta;
}
-
/*
So we need to make it so that we pick the container's point clicked on, and translate all the other parts *not* clicked on.
*/
TranslateObject((Object *)c, clickedDelta);
}
-
//
// Translate all objects in the passed in vector, including Containers and all
// the objects they contain.
}
}
-
//
// This does not *copy* the objects, it simply flattens out the pointers in the
// Container and all sub-Containers.
return flat;
}
-
//
// This does not *copy* the objects, it simply flattens out the pointers in the
// vector and all sub-Containers in the vector.
return flat;
}
-