Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix QPainter issue with Qt4 #2

Merged
merged 1 commit into from
Nov 1, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/command.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class View2D;
class PinEditDoc;
class Group;
class Shape3D;
class QPainter;

/** @author Henrik Enqvist */
class CommandContext {
Expand Down Expand Up @@ -84,7 +85,7 @@ class Command {
virtual void execute(const CommandContext & context) = 0;
/** Some commands wishes to generate a preview of the action onto a View2D. E.g.
* movement of objects. */
virtual void preview(const CommandContext & context, View2D * view2d) = 0;
virtual void preview(const CommandContext & context, View2D * view2d, QPainter& painter) = 0;
/** Returns the name of the command subclass. Subclasses should implement
* this function by returning a name that exaclty matches the name of
* the class. */
Expand Down
7 changes: 3 additions & 4 deletions src/commandaddselect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,10 @@ void CommandAddSelect::execute(const CommandContext & context) {
" to " << context.x2 <<" "<< context.y2 <<" "<< context.z2);
}

void CommandAddSelect::preview(const CommandContext & context, View2D * view2d) {
void CommandAddSelect::preview(const CommandContext & context, View2D * /*view2d*/, QPainter &painter) {
EM_CERR("CommandAddSelect::preview");
view2d->getPainter()->setPen(Qt::blue);
view2d->getPainter()->drawRect(context.sx1, context.sy1,
context.sx2 - context.sx1, context.sy2 - context.sy1);
painter.setPen(Qt::blue);
painter.drawRect(context.sx1, context.sy1, context.sx2 - context.sx1, context.sy2 - context.sy1);
}

void CommandAddSelect::undo() {
Expand Down
4 changes: 2 additions & 2 deletions src/commandaddselect.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ class CommandAddSelect : public Command {
Command * build();
void undo();
void execute(const CommandContext & context);
void preview(const CommandContext & context, View2D * view2d);
void preview(const CommandContext & context, View2D * view2d, QPainter& painter);
void clearObjects();
const char * type() { return "CommandAddSelect"; };
const char * type() { return "CommandAddSelect"; }
};

#endif
4 changes: 2 additions & 2 deletions src/commandcopy.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ class CommandCopy : public Command {
void undo();
void clearObjects();
void execute(const CommandContext & context);
void preview (const CommandContext &, View2D *) {};
virtual const char * type() { return "CommandCopy"; };
void preview (const CommandContext &, View2D *, QPainter&) {}
virtual const char * type() { return "CommandCopy"; }
};

#endif
4 changes: 2 additions & 2 deletions src/commanddeletegroup.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ class CommandDeleteGroup : public Command {
void undo();
void clearObjects();
void execute(const CommandContext & context);
void preview(const CommandContext &, View2D *) {};
const char * type() { return "CommandDeleteGroup"; };
void preview(const CommandContext &, View2D *, QPainter&) {}
const char * type() { return "CommandDeleteGroup"; }
};

#endif
4 changes: 2 additions & 2 deletions src/commanddeletepolygon.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ class CommandDeletePolygon : public Command {
void undo();
void clearObjects();
void execute(const CommandContext & context);
void preview(const CommandContext &, View2D *) {};
const char * type() { return "CommandDeletePolygon"; };
void preview(const CommandContext &, View2D *, QPainter&) {}
const char * type() { return "CommandDeletePolygon"; }
private:
vector<Polygon3D*> m_vPolygon;
};
Expand Down
4 changes: 2 additions & 2 deletions src/commanddeleteshape.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ class CommandDeleteShape : public Command {
void undo();
void clearObjects();
void execute(const CommandContext & context);
void preview(const CommandContext &, View2D *) {};
const char * type() { return "CommandDeleteShape"; };
void preview(const CommandContext &, View2D *, QPainter&) {}
const char * type() { return "CommandDeleteShape"; }
};

#endif
4 changes: 2 additions & 2 deletions src/commanddeletevertex.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ class CommandDeleteVertex : public Command {
void undo();
void clearObjects();
void execute(const CommandContext & context);
void preview(const CommandContext &, View2D *) {};
const char * type() { return "CommandDeleteVertex"; };
void preview(const CommandContext &, View2D *, QPainter&) {}
const char * type() { return "CommandDeleteVertex"; }
private:
vector<Vertex3D> m_vVertex;
vector<Color> m_vColor;
Expand Down
4 changes: 2 additions & 2 deletions src/commandextrude.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ class CommandExtrude : public Command {
void undo();
void clearObjects();
void execute(const CommandContext & context);
void preview (const CommandContext &, View2D *) {};
virtual const char * type() { return "CommandExtrude"; };
void preview (const CommandContext &, View2D *, QPainter&) {}
virtual const char * type() { return "CommandExtrude"; }
private:
vector<int> m_vNewVertex;
vector<Polygon3D*> m_vPolygon;
Expand Down
4 changes: 2 additions & 2 deletions src/commandflip.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ class CommandFlip : public Command {
void undo();
void clearObjects();
void execute(const CommandContext & context);
void preview (const CommandContext &, View2D *) {};
const char * type() { return "CommandFlip"; };
void preview (const CommandContext &, View2D *, QPainter&) {}
const char * type() { return "CommandFlip"; }
private:
vector<Polygon3D*> m_vPolygon;
};
Expand Down
4 changes: 2 additions & 2 deletions src/commandflipsmart.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ class CommandFlipSmart : public Command {
void undo();
void clearObjects();
void execute(const CommandContext & context);
void preview (const CommandContext &, View2D *) {};
const char * type() { return "CommandFlipSmart"; };
void preview (const CommandContext &, View2D *, QPainter&) {}
const char * type() { return "CommandFlipSmart"; }
private:
vector<Polygon3D*> m_vPolygon;
};
Expand Down
2 changes: 1 addition & 1 deletion src/commandhideselected.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ void CommandHideSelected::execute(const CommandContext & context) {
// but selection is made correct !!!
}

void CommandHideSelected::preview(const CommandContext &, View2D *) {
void CommandHideSelected::preview(const CommandContext &, View2D *, QPainter &) {
EM_CERR("CommandHideSelected::preview");
}

Expand Down
4 changes: 2 additions & 2 deletions src/commandhideselected.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ class CommandHideSelected : public Command {
void undo();
void clearObjects() {};
void execute(const CommandContext & context);
void preview(const CommandContext & context, View2D * view2d);
const char * type() { return "CommandHideSelected"; };
void preview(const CommandContext & context, View2D * view2d, QPainter& painter);
const char * type() { return "CommandHideSelected"; }
};

#endif
6 changes: 3 additions & 3 deletions src/commandmirror.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ class CommandMirror : public Command {
void undo();
void clearObjects();
void execute(const CommandContext & context);
void preview (const CommandContext &, View2D *) {};
void preview (const CommandContext &, View2D *, QPainter&) {}
/** 0 = x, 1 = y, 2 = z; */
void setXYZ(int xyz) { m_iXYZ = xyz; };
const char * type() { return "CommandMirror"; };
void setXYZ(int xyz) { m_iXYZ = xyz; }
const char * type() { return "CommandMirror"; }
private:
int m_iXYZ;
vector<int> m_vIndex;
Expand Down
6 changes: 3 additions & 3 deletions src/commandmirrorlocal.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ class CommandMirrorLocal : public Command {
void undo();
void clearObjects();
void execute(const CommandContext & context);
void preview (const CommandContext &, View2D *) {};
void preview (const CommandContext &, View2D *, QPainter&) {}
/** 0 = x, 1 = y, 2 = z; */
void setXYZ(int xyz) { m_iXYZ = xyz; };
const char * type() { return "CommandMirrorLocal"; };
void setXYZ(int xyz) { m_iXYZ = xyz; }
const char * type() { return "CommandMirrorLocal"; }
private:
int m_iXYZ;
Vertex3D m_vtxCenter;
Expand Down
12 changes: 6 additions & 6 deletions src/commandmove.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ void CommandMove::execute(const CommandContext & context) {
" to " << context.x2 <<" "<< context.y2 <<" "<< context.z2);
}

void CommandMove::preview(const CommandContext & context, View2D * view2d) {
void CommandMove::preview(const CommandContext & context, View2D * view2d, QPainter& painter) {
if (context.shape == NULL) return;
p_Context->copy(context);
p_Context->copy(context);
// build matrix stack for temporary translation
// mtxB is global rotion matrix, mtxC fixes the translation in local rotation
// mtxC is the final matrix
Expand All @@ -76,11 +76,11 @@ void CommandMove::preview(const CommandContext & context, View2D * view2d) {
EMath::getTransformationMatrix(mtxA, vtxTA, vtxRA, vtxSA);

// draw selected polygons
view2d->getPainter()->setPen(Qt::green);
painter.setPen(Qt::green);
int index = 0;
Polygon3D * poly = p_Doc->getSelectedPolygon(index);
while (poly != NULL) {
view2d->drawPolygon(context.shape, poly, mtxA);
view2d->drawPolygon(painter, context.shape, poly, mtxA);
index++;
poly = p_Doc->getSelectedPolygon(index);
}
Expand All @@ -89,11 +89,11 @@ void CommandMove::preview(const CommandContext & context, View2D * view2d) {
Vertex3D * vtx = context.shape->getVertex3D(p_Doc->getSelectedVertex(index));
while (vtx != NULL) {
// the matrix will rotate and reapply the translation
view2d->drawVertex(context.shape, *vtx, mtxA);
view2d->drawVertex(painter, context.shape, *vtx, mtxA);
index++;
vtx = context.shape->getVertex3D(p_Doc->getSelectedVertex(index));
}
EM_CERR("commandmove::preview");
EM_CERR("commandmove::preview");
}

void CommandMove::undo() {
Expand Down
2 changes: 1 addition & 1 deletion src/commandmove.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class CommandMove : public Command {
void undo();
void clearObjects();
void execute(const CommandContext & context);
void preview(const CommandContext & context, View2D * view2d);
void preview(const CommandContext & context, View2D * view2d, QPainter &painter);
virtual const char * type() { return "CommandMove"; };
private:
vector<Vertex3D> m_vVertex;
Expand Down
10 changes: 5 additions & 5 deletions src/commandmovegroup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ void CommandMoveGroup::execute(const CommandContext & context) {
" to " << context.x2 <<" "<< context.y2 <<" "<< context.z2);
}

void CommandMoveGroup::preview(const CommandContext & context, View2D * view2d) {
void CommandMoveGroup::preview(const CommandContext & context, View2D * view2d, QPainter &painter) {
EM_CERR("CommandMoveGroup::preview");
if (context.group == NULL) return;
if (context.group == NULL) return;
context.group->getTranslation(m_vtxTrans.x, m_vtxTrans.y, m_vtxTrans.z);

Matrix mtxA = EMath::identityMatrix;
Expand Down Expand Up @@ -84,20 +84,20 @@ void CommandMoveGroup::preview(const CommandContext & context, View2D * view2d)
g = context.group;

// draw all polygons
view2d->getPainter()->setPen(Qt::green);
painter.setPen(Qt::green);
int shindex = 0;
Shape3D * shape = g->getShape3D(shindex);
while (shape != NULL) {
int polyindex = 0;
Polygon3D * poly = shape->getPolygon(polyindex);
while (poly != NULL) {
view2d->drawPolygon(shape, poly, mtxC);
view2d->drawPolygon(painter, shape, poly, mtxC);
polyindex++;
poly = shape->getPolygon(polyindex);
}
shindex++;
shape = g->getShape3D(shindex);
}
}
}

void CommandMoveGroup::undo() {
Expand Down
4 changes: 2 additions & 2 deletions src/commandmovegroup.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ class CommandMoveGroup : public Command {
void undo();
void clearObjects();
void execute(const CommandContext & context);
void preview(const CommandContext & context, View2D * view2d);
const char * type() { return "CommandMoveGroup"; };
void preview(const CommandContext & context, View2D * view2d, QPainter& painter);
const char * type() { return "CommandMoveGroup"; }
private:
Vertex3D m_vtxTrans;
};
Expand Down
8 changes: 4 additions & 4 deletions src/commandnewbehavior.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ class CommandNewBehavior : public Command {
~CommandNewBehavior();
Command * build();
void clearObjects();
inline void setBehaviorType(int t) { m_iBehaviorType = t; };
inline void setBehaviorType(int t) { m_iBehaviorType = t; }
/** Gets the behavior, the command must be executed before a behavior will exist. */
inline Behavior * getBehavior() { return p_Behavior; };
inline Behavior * getBehavior() { return p_Behavior; }
void undo();
void execute(const CommandContext & context);
void preview (const CommandContext &, View2D *) {};
const char * type() { return "CommandNewBehavior"; };
void preview (const CommandContext &, View2D *, QPainter&) {}
const char * type() { return "CommandNewBehavior"; }
private:
Group * p_Group;
Behavior * p_Behavior;
Expand Down
4 changes: 2 additions & 2 deletions src/commandnewgroup.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ class CommandNewGroup : public Command {
void undo();
void clearObjects();
void execute(const CommandContext & context);
const char * type() { return "CommandNewGroup"; };
void preview (const CommandContext &, View2D *) {};
const char * type() { return "CommandNewGroup"; }
void preview (const CommandContext &, View2D *, QPainter&) {}
private:
Group * p_Group;
};
Expand Down
4 changes: 2 additions & 2 deletions src/commandnewpolygon.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ class CommandNewPolygon : public Command {
void undo();
void clearObjects();
void execute(const CommandContext & context);
void preview (const CommandContext &, View2D *) {};
const char * type() { return "CommandNewPolygon"; };
void preview (const CommandContext &, View2D *, QPainter&) {}
const char * type() { return "CommandNewPolygon"; }
private:
Polygon3D * p_Polygon;
};
Expand Down
6 changes: 3 additions & 3 deletions src/commandnewshape.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ class CommandNewShape : public Command {
~CommandNewShape();
Command * build();
void undo();
void setType(int type) { m_iType = type; };
void setType(int type) { m_iType = type; }
void clearObjects();
void execute(const CommandContext & context);
void preview (const CommandContext &, View2D *) {};
const char * type() { return "CommandNewShape"; };
void preview (const CommandContext &, View2D *, QPainter&) {}
const char * type() { return "CommandNewShape"; }
private:
int m_iType;
};
Expand Down
4 changes: 2 additions & 2 deletions src/commandnewvertex.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ class CommandNewVertex : public Command {
void undo();
void clearObjects();
void execute(const CommandContext & context);
void preview (const CommandContext &, View2D *) {};
const char * type() { return "CommandNewVertex"; };
void preview (const CommandContext &, View2D *, QPainter&) {}
const char * type() { return "CommandNewVertex"; }
private:
int m_iVtxIndex;
};
Expand Down
4 changes: 2 additions & 2 deletions src/commandpaste.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ class CommandPaste : public Command {
void undo();
void clearObjects();
void execute(const CommandContext & context);
void preview (const CommandContext &, View2D *) {};
virtual const char * type() { return "CommandPaste"; };
void preview (const CommandContext &, View2D *, QPainter&) {}
virtual const char * type() { return "CommandPaste"; }
private:
int m_iUndoIndex;
//vector<int> m_vNewVertex;
Expand Down
14 changes: 7 additions & 7 deletions src/commandresize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,13 @@ void CommandResize::execute(const CommandContext & context) {
" to " << context.x2 <<" "<< context.y2 <<" "<< context.z2);
}

void CommandResize::preview(const CommandContext & context, View2D * view2d) {
void CommandResize::preview(const CommandContext & context, View2D * view2d, QPainter & painter) {
assert(view2d != NULL);
if (context.shape == NULL) return;
if (context.shape == NULL) return;
float dx = context.x2 - context.x1;
float dy = context.y2 - context.y1;
float dz = context.z2 - context.z1;
view2d->getPainter()->setPen(Qt::green);
painter.setPen(Qt::green);
int index = 0;
Vertex3D * vtx = context.shape->getVertex3D(p_Doc->getSelectedVertex(index));
Vertex3D vtxA;
Expand All @@ -76,19 +76,19 @@ void CommandResize::preview(const CommandContext & context, View2D * view2d) {
vtxA.z = vtx->z * (float)(PE_RESIZE_FACTOR + dz)/PE_RESIZE_FACTOR;
//EM_CERR(vtx->x <<" "<< vtx->y <<" "<< vtx->z);
switch (context.type) {
case XY: view2d->getPainter()->drawRect(view2d->screenx(vtxA.x)-1,
case XY: painter.drawRect(view2d->screenx(vtxA.x)-1,
view2d->screeny(-vtxA.y)-1,
3, 3); break;
case XZ: view2d->getPainter()->drawRect(view2d->screenx(vtxA.x)-1,
case XZ: painter.drawRect(view2d->screenx(vtxA.x)-1,
view2d->screeny(vtxA.z)-1,
3, 3); break;
case ZY: view2d->getPainter()->drawRect(view2d->screenx(vtxA.z)-1,
case ZY: painter.drawRect(view2d->screenx(vtxA.z)-1,
view2d->screeny(-vtxA.y)-1,
3, 3); break;
}
index++;
vtx = context.shape->getVertex3D(p_Doc->getSelectedVertex(index));
}
}
EM_CERR("commandmove::preview");
}

Expand Down
Loading