Skip to content

Commit

Permalink
bug#3348447, cleanup for zoom panning and mouse hints
Browse files Browse the repository at this point in the history
  • Loading branch information
dxli committed Sep 7, 2011
1 parent dc8bdb4 commit bfa6abb
Show file tree
Hide file tree
Showing 9 changed files with 82 additions and 50 deletions.
4 changes: 2 additions & 2 deletions src/actions/rs_actionsetrelativezero.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,10 @@ void RS_ActionSetRelativeZero::coordinateEvent(RS_CoordinateEvent* e) {
void RS_ActionSetRelativeZero::updateMouseButtonHints() {
switch (getStatus()) {
case 0:
RS_DIALOGFACTORY->updateMouseWidget(tr("Set relative Zero"), tr("Cancel"));
RS_DIALOGFACTORY->updateMouseWidget(tr("Set relative Zero"), tr("Cancel"),false);
break;
default:
RS_DIALOGFACTORY->updateMouseWidget();
RS_DIALOGFACTORY->restoreMouseWidget();
break;
}
}
Expand Down
57 changes: 37 additions & 20 deletions src/actions/rs_actionzoompan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,19 @@

#include <QAction>
#include "rs_graphicview.h"

#include "rs_dialogfactory.h"
#include "rs_graphicview.h"
#include "rs_commands.h"
#include "rs_commandevent.h"

RS_ActionZoomPan::RS_ActionZoomPan(RS_EntityContainer& container,
RS_GraphicView& graphicView)
:RS_ActionInterface("Zoom Pan", container, graphicView) {}
:RS_ActionInterface("Zoom Panning", container, graphicView) {}


QAction* RS_ActionZoomPan::createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/) {
// tr("Pan Zoom")
QAction* action = new QAction(tr("&Pan Zoom"), NULL);
QAction* action = new QAction(tr("Zoom &Panning"), NULL);
action->setIcon(QIcon(":/actions/zoompan.png"));
//action->zetStatusTip(tr("Realtime Panning"));

Expand All @@ -52,6 +55,7 @@ void RS_ActionZoomPan::init(int status) {
//v1 = v2 = RS_Vector(false);
x1 = y1 = x2 = y2 = -1;
//graphicView->saveView();
setStatus(SetPanStart);
}


Expand All @@ -61,9 +65,12 @@ void RS_ActionZoomPan::trigger() {
graphicView->zoomPan(v2-v1);
v1 = v2;
}*/
if (getStatus()==SetPanning && (abs(x2-x1)>7 || abs(y2-y1)>7)) {
graphicView->zoomPan(x2-x1, y2-y1);
x1 = x2;
y1 = y2;
}
if(getStatus()==SetPanEnd) finish();
}


Expand All @@ -73,13 +80,14 @@ void RS_ActionZoomPan::mouseMoveEvent(QMouseEvent* e) {
x2 = e->x();
y2 = e->y();
//if (getStatus()==1 && graphicView->toGuiDX((v2-v1).magnitude())>10) {
if (getStatus()==1 && (abs(x2-x1)>7 || abs(y2-y1)>7)) {
if (getStatus()==SetPanning ) {
if (abs(x2-x1)>7 || abs(y2-y1)>7) {
trigger();
}
}
}



void RS_ActionZoomPan::mousePressEvent(QMouseEvent* e) {
#if QT_VERSION < 0x040700
if (e->button()==Qt::MidButton ||
Expand All @@ -90,33 +98,42 @@ void RS_ActionZoomPan::mousePressEvent(QMouseEvent* e) {
//v1 = snapPoint(e);
x1 = e->x();
y1 = e->y();
setStatus(1);
setStatus(SetPanning);
}
}



void RS_ActionZoomPan::mouseReleaseEvent(QMouseEvent* e) {
if (e->button()==Qt::RightButton) {
init(getStatus()-1);
#if QT_VERSION < 0x040700
} else if (e->button()==Qt::MidButton) {
#else
} else if (e->button()==Qt::MiddleButton) {
#endif
init(-1);
} else {
setStatus(0);
}

void RS_ActionZoomPan::mouseReleaseEvent(QMouseEvent* /*e*/) {
setStatus(SetPanEnd);
trigger();
//RS_DEBUG->print("RS_ActionZoomPan::mousePressEvent(): %f %f", v1.x, v1.y);
}

void RS_ActionZoomPan::updateMouseButtonHints()
{
switch (getStatus()) {
case SetPanStart:
RS_DIALOGFACTORY->updateMouseWidget(tr("Click and drag to pan zoom"),
tr("Cancel"),
false);
break;
case SetPanning:
RS_DIALOGFACTORY->updateMouseWidget(tr("Zoom panning"),
tr("Cancel"),
false);
break;
default:
RS_DIALOGFACTORY->restoreMouseWidget();//restore previous mouse button hints
}
}


void RS_ActionZoomPan::updateMouseCursor() {
#ifndef __APPLE__
graphicView->setMouseCursor(RS2::SizeAllCursor);
if(getStatus()==SetPanning) {
graphicView->setMouseCursor(RS2::MovingHandCursor);
}
#endif
}

Expand Down
11 changes: 11 additions & 0 deletions src/actions/rs_actionzoompan.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,16 @@
*/
class RS_ActionZoomPan : public RS_ActionInterface {
Q_OBJECT
public:
/*
** Action States.
*/
enum Status {
SetPanStart, /**< Setting Start. */
SetPanning, /**< Setting panning. */
SetPanEnd, /**< Setting End */
};

public:
RS_ActionZoomPan(RS_EntityContainer& container,
RS_GraphicView& graphicView);
Expand All @@ -49,6 +59,7 @@ class RS_ActionZoomPan : public RS_ActionInterface {
virtual void mouseMoveEvent(QMouseEvent* e);
virtual void mousePressEvent(QMouseEvent* e);
virtual void mouseReleaseEvent(QMouseEvent* e);
virtual void updateMouseButtonHints();
virtual void updateMouseCursor();

protected:
Expand Down
2 changes: 1 addition & 1 deletion src/actions/rs_actionzoomprevious.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ RS_ActionZoomPrevious::RS_ActionZoomPrevious(RS_EntityContainer& container,

QAction* RS_ActionZoomPrevious::createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/) {
// tr("Previous View")
QAction* action = new QAction(tr("&Previous View"), NULL);
QAction* action = new QAction(tr("Previous &View"), NULL);
#if QT_VERSION >= 0x040600
action->setIcon(QIcon::fromTheme("zoom-previous", QIcon(":/actions/zoomprevious.png")));
#else
Expand Down
6 changes: 3 additions & 3 deletions src/actions/rs_actionzoomwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,13 +152,13 @@ void RS_ActionZoomWindow::updateMouseButtonHints() {

switch (getStatus()) {
case 0:
RS_DIALOGFACTORY->updateMouseWidget(tr("Specify first edge"), tr("Cancel"));
RS_DIALOGFACTORY->updateMouseWidget(tr("Specify first edge"), tr("Cancel"),false);
break;
case 1:
RS_DIALOGFACTORY->updateMouseWidget(tr("Specify second edge"), tr("Back"));
RS_DIALOGFACTORY->updateMouseWidget(tr("Specify second edge"), tr("Back"),false);
break;
default:
RS_DIALOGFACTORY->updateMouseWidget("", "");
RS_DIALOGFACTORY->restoreMouseWidget();
break;
}
}
Expand Down
9 changes: 4 additions & 5 deletions src/lib/gui/rs_dialogfactoryadapter.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,11 @@ class RS_DialogFactoryAdapter : public RS_DialogFactoryInterface {
virtual bool requestHatchDialog(RS_Hatch* ) { return false; }
virtual void requestOptionsGeneralDialog() {}
virtual void requestOptionsDrawingDialog(RS_Graphic& ) {}
virtual void updateCoordinateWidget(const RS_Vector& ,
const RS_Vector& ,
bool =false) {}
virtual void updateCoordinateWidget(const RS_Vector& , const RS_Vector& , bool =false) {}
virtual void updateMouseWidget(const QString& ,
const QString& ) {}
virtual void updateMouseWidget(void) {}
const QString& ,
bool) {}
virtual void restoreMouseWidget(void) {}
virtual void updateSelectionWidget(int ) {}
virtual void commandMessage(const QString& ) {}
virtual bool isAdapter() { return true; }
Expand Down
9 changes: 4 additions & 5 deletions src/lib/gui/rs_dialogfactoryinterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -365,9 +365,7 @@ class RS_DialogFactoryInterface {
* point it snaps to.
* @param rel Relative coordiante.
*/
virtual void updateCoordinateWidget(const RS_Vector& abs,
const RS_Vector& rel,
bool updateFormat=false) = 0;
virtual void updateCoordinateWidget(const RS_Vector& abs, const RS_Vector& rel, bool updateFormat=false) = 0;

/**
* This virtual method must be overwritten if the graphic view has
Expand All @@ -379,8 +377,9 @@ class RS_DialogFactoryInterface {
* @param right Help text for the right mouse button.
*/
virtual void updateMouseWidget(const QString& left,
const QString& right) = 0;
virtual void updateMouseWidget(void)=0;
const QString& right,
bool keeping=true) = 0;
virtual void restoreMouseWidget(void)=0;

/**
* This virtual method must be overwritten if the graphic view has
Expand Down
23 changes: 15 additions & 8 deletions src/ui/qg_dialogfactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ QG_DialogFactory::QG_DialogFactory(QWidget* parent, QToolBar* ow)
rightHintCurrent=new QString("");
leftHintSaved=new QString("");
rightHintSaved=new QString("");
hintKeeping=new bool(true);
RS_DEBUG->print("QG_DialogFactory::QG_DialogFactory: OK");
}

Expand All @@ -133,6 +134,7 @@ QG_DialogFactory::~QG_DialogFactory() {
delete rightHintCurrent;
delete leftHintSaved;
delete rightHintSaved;
delete hintKeeping;
RS_DEBUG->print("QG_DialogFactory::~QG_DialogFactory");
RS_DEBUG->print("QG_DialogFactory::~QG_DialogFactory: OK");
}
Expand Down Expand Up @@ -1690,35 +1692,40 @@ void QG_DialogFactory::updateCoordinateWidget(const RS_Vector& abs,

/**
* Called when an action has a mouse hint.
* @left mouse hint for left button
* @right mouse hint for right button
* @keeping whether to keep the mouse hints to be restored after interruption, default to true
*/
void QG_DialogFactory::updateMouseWidget(const QString& left,
const QString& right) {
if ( left != *leftHintCurrent || right != *rightHintCurrent ) {
if ( *leftHintSaved != *leftHintCurrent
|| *rightHintSaved != *rightHintCurrent ) {
const QString& right, bool keeping) {
if ( left != *leftHintCurrent || right != *rightHintCurrent ) {
if ( *hintKeeping ) {//whether the current hints should be save to HintSaved
*leftHintSaved=*leftHintCurrent;
*rightHintSaved=*rightHintCurrent;
*hintKeeping=keeping;
}
*leftHintCurrent=left;
*rightHintCurrent=right;
}
if (mouseWidget!=NULL) {
mouseWidget->setHelp(left, right);
}
if (commandWidget!=NULL) {
commandWidget->setCommand(left);
}
}
}

/**
* Called to restore saved mouse hint.
*/
void QG_DialogFactory::updateMouseWidget(void) {
void QG_DialogFactory::restoreMouseWidget(void) {
*leftHintCurrent=*leftHintSaved;
*rightHintCurrent=*rightHintSaved;
if (mouseWidget!=NULL) {
mouseWidget->setHelp(*leftHintSaved, *rightHintSaved);
mouseWidget->setHelp(*leftHintCurrent, *rightHintCurrent);
}
if (commandWidget!=NULL) {
commandWidget->setCommand(*leftHintSaved);
commandWidget->setCommand(*leftHintCurrent);
}
}

Expand Down
11 changes: 5 additions & 6 deletions src/ui/qg_dialogfactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -242,13 +242,11 @@ class QG_DialogFactory: public RS_DialogFactoryInterface {
virtual void requestOptionsDrawingDialog(RS_Graphic& graphic);

virtual void requestPreviousMenu();

virtual void updateCoordinateWidget(const RS_Vector& abs,
const RS_Vector& rel,
bool updateFormat=false);
virtual void updateCoordinateWidget(const RS_Vector& abs, const RS_Vector& rel, bool updateFormat=false);
virtual void updateMouseWidget(const QString& left,
const QString& right);
virtual void updateMouseWidget(void);
const QString& right,
bool keeping=true);
virtual void restoreMouseWidget(void);
virtual void updateSelectionWidget(int num);
virtual void commandMessage(const QString& message);
virtual bool isAdapter() { return false; }
Expand Down Expand Up @@ -276,6 +274,7 @@ class QG_DialogFactory: public RS_DialogFactoryInterface {
private:
QString *leftHintCurrent, *rightHintCurrent;
QString *leftHintSaved, *rightHintSaved;
bool *hintKeeping;
};

#endif

0 comments on commit bfa6abb

Please sign in to comment.