Skip to content

Commit

Permalink
Merge pull request #504 from alysogorov/fix_wire_edit_bugs
Browse files Browse the repository at this point in the history
fixed 2 bugs in wire editing
  • Loading branch information
guitorri authored Nov 3, 2016
2 parents 8d87623 + 4fd691a commit 7552363
Showing 1 changed file with 73 additions and 19 deletions.
92 changes: 73 additions & 19 deletions qucs/qucs/mouseactions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,43 @@ void MouseActions::MMoveElement(Schematic *Doc, QMouseEvent *Event)
Doc->viewport()->update();
}

/**
* @brief draws wire aiming cross on Document view
* @param Doc - pointer to Schematics object
* @param fx - document x-coordinate of center
* @param fy - document x-coordinate of center
*/
static void paintAim(Schematic *Doc, int fx,int fy){
//let we reserve couple of points at the edges of lines for some aesthetics,
//and visual check that our calculations has fit the widget window.
const int ldelta = 2;

//left and upper edges of our lines
int lx0 = DOC_X_POS(Doc->contentsX()+ldelta);
int ly0 = DOC_Y_POS(Doc->contentsY()+ldelta);

//right and bottom edges
int lx1 = DOC_X_POS(Doc->contentsX()+Doc->viewport()->width()-1-ldelta);
int ly1 = DOC_Y_POS(Doc->contentsY()+Doc->viewport()->height()-1-ldelta);

//post line paint events
Doc->PostPaintEvent (_Line, lx0, fy, lx1, fy);
Doc->PostPaintEvent (_Line, fx, ly0, fx, ly1);
}

//paint ghost line - horizontal
static void paintGhostLineH(Schematic *Doc, int fx,int fy, int fxx){
Doc->PostPaintEvent (_Line, fx, fy-1, fxx, fy-1);
Doc->PostPaintEvent (_Line, fx, fy+1, fxx, fy+1);
}

//paint ghost line - vertical
static void paintGhostLineV(Schematic *Doc, int fx, int fy, int fyy){
Doc->PostPaintEvent (_Line, fx-1, fy, fx-1, fyy);
Doc->PostPaintEvent (_Line, fx+1, fy, fx+1, fyy);
}


// -----------------------------------------------------------
/**
* @brief MouseActions::MMoveWire2 Paint wire as it is being drawn with mouse.
Expand All @@ -322,14 +359,18 @@ void MouseActions::MMoveWire2(Schematic *Doc, QMouseEvent *Event)
MAx2 = DOC_X_POS(Event->pos().x());
MAy2 = DOC_Y_POS(Event->pos().y());
Doc->setOnGrid(MAx2, MAy2);
paintAim(Doc,MAx2,MAy2); //let we paint aim cross

//because cross slightly masks a wire, let we make wire thicker
//better to make it by increasing of pen, but here we cannot access
//pen
if(MAx1 == 0) {
Doc->PostPaintEvent (_Line, MAx3, MAy3, MAx3, MAy2); // paint
Doc->PostPaintEvent (_Line, MAx3, MAy2, MAx2, MAy2); // paint
paintGhostLineV(Doc,MAx3,MAy3,MAy2);
paintGhostLineH(Doc,MAx3,MAy2,MAx2);
}
else {
Doc->PostPaintEvent (_Line, MAx3, MAy3, MAx2, MAy3); // paint
Doc->PostPaintEvent (_Line, MAx2, MAy3, MAx2, MAy2); // paint
paintGhostLineH(Doc,MAx3,MAy3,MAx2);
paintGhostLineV(Doc,MAx2,MAy3,MAy2);
}

QucsMain->MouseDoubleClickAction = &MouseActions::MDoubleClickWire2;
Expand All @@ -347,12 +388,9 @@ void MouseActions::MMoveWire1(Schematic *Doc, QMouseEvent *Event)
MAx3 = DOC_X_POS(Event->pos().x());
MAy3 = DOC_Y_POS(Event->pos().y());
Doc->setOnGrid(MAx3, MAy3);

MAx2 = DOC_X_POS(Doc->viewport()->width());
MAy2 = DOC_Y_POS(Doc->viewport()->height());

Doc->PostPaintEvent (_Line, Doc->ViewX1, MAy3, MAx2, MAy3);
Doc->PostPaintEvent (_Line, MAx3, Doc->ViewY1, MAx3, MAy2);
paintAim(Doc,MAx3,MAy3);
MAx2 = DOC_X_POS(Doc->contentsX()+Doc->viewport()->width()-1-2);
MAx2 = DOC_Y_POS(Doc->contentsY()+Doc->viewport()->height()-1-2);
Doc->viewport()->update();
}

Expand Down Expand Up @@ -1303,8 +1341,10 @@ void MouseActions::MPressWire1(Schematic *Doc, QMouseEvent*, float fX, float fY)
//Doc->PostPaintEvent (_DotLine);
//Doc->PostPaintEvent (_NotRop);
//if(drawn) {
Doc->PostPaintEvent (_Line, 0, MAy3, MAx2, MAy3); // erase old mouse cross
#if 0 //ALYS - it draws some garbage, not deleted because of possible questions
Doc->PostPaintEvent (_Line, 0, MAy3, MAx2, MAy3); // erase old mouse cross
Doc->PostPaintEvent (_Line, MAx3, 0, MAx3, MAy2);
#endif
//}
//drawn = false;

Expand All @@ -1313,6 +1353,10 @@ void MouseActions::MPressWire1(Schematic *Doc, QMouseEvent*, float fX, float fY)
MAy3 = int(fY);
Doc->setOnGrid(MAx3, MAy3);

//ALYS - draw aiming cross
paintAim(Doc,MAx3, MAy3);
//#######################

formerAction = 0; // keep wire action active after first wire finished
QucsMain->MouseMoveAction = &MouseActions::MMoveWire2;
QucsMain->MousePressAction = &MouseActions::MPressWire2;
Expand Down Expand Up @@ -1366,41 +1410,51 @@ void MouseActions::MPressWire2(Schematic *Doc, QMouseEvent *Event, float fX, flo
}
}

Doc->viewport()->update();
drawn = false;
//ALYS: excessive update. end of function does it.
//Doc->viewport()->update();

drawn = false;
if(set1 | set2) Doc->setChanged(true, true);
MAx3 = MAx2;
MAy3 = MAy2;
break;

/// \todo document right mouse button changes the wire corner
case Qt::RightButton :
if(MAx1 == 0) {

#if 0
//ALYS - old code preserved because isn't clear - what it was???
//looks like deletion via painting.
//i'll delete it after possible clarification from team
if(MAx1 == 0) {
Doc->PostPaintEvent (_Line, MAx3, MAy3, MAx3, MAy2); // erase old
Doc->PostPaintEvent (_Line, MAx3, MAy2, MAx2, MAy2); // erase old
}
else {
Doc->PostPaintEvent (_Line, MAx3, MAy3, MAx2, MAy3); // erase old
Doc->PostPaintEvent (_Line, MAx2, MAy3, MAx2, MAy2); // erase old
}
#endif

MAx2 = int(fX);
MAy2 = int(fY);
Doc->setOnGrid(MAx2, MAy2);

MAx1 ^= 1; // change the painting direction of wire corner
if(MAx1 == 0) {
Doc->PostPaintEvent (_Line, MAx3, MAy3, MAx3, MAy2); // paint
Doc->PostPaintEvent (_Line, MAx3, MAy2, MAx2, MAy2); // paint
if(MAx1 == 0) {
paintGhostLineV(Doc,MAx3,MAy3,MAy2);
paintGhostLineH(Doc,MAx3,MAy2,MAx2);
}
else {
Doc->PostPaintEvent (_Line, MAx3, MAy3, MAx2, MAy3); // paint
Doc->PostPaintEvent (_Line, MAx2, MAy3, MAx2, MAy2); // paint
paintGhostLineH(Doc,MAx3,MAy3,MAx2);
paintGhostLineV(Doc,MAx2,MAy3,MAy2);
}
break;

default: ; // avoids compiler warnings
}

paintAim(Doc,MAx2,MAy2); //ALYS - added missed aiming cross
Doc->viewport()->update();
}

Expand Down

0 comments on commit 7552363

Please sign in to comment.