* ./hurricane/src/hviewer :

- Change: In RulerCommand, key & mouse now mimic Cadence behavior.
This commit is contained in:
Jean-Paul Chaput 2009-12-03 11:19:54 +00:00
parent e208fbeb2f
commit dcf39378c5
3 changed files with 31 additions and 21 deletions

View File

@ -185,7 +185,7 @@ namespace Hurricane {
_clearRulersAction = new QAction ( tr("Clear Rulers"), this ); _clearRulersAction = new QAction ( tr("Clear Rulers"), this );
_clearRulersAction->setObjectName ( "viewer.menuBar.view.clearRulers" ); _clearRulersAction->setObjectName ( "viewer.menuBar.view.clearRulers" );
_clearRulersAction->setStatusTip ( tr("Remove all rulers") ); _clearRulersAction->setStatusTip ( tr("Remove all rulers") );
_clearRulersAction->setShortcut ( QKeySequence(tr("CTRL+R")) ); //_clearRulersAction->setShortcut ( QKeySequence(tr("K")) );
_controllerAction = new QAction ( tr("Controller"), this ); _controllerAction = new QAction ( tr("Controller"), this );
_controllerAction->setObjectName ( "viewer.menuBar.tools.controller" ); _controllerAction->setObjectName ( "viewer.menuBar.tools.controller" );

View File

@ -43,6 +43,7 @@ namespace Hurricane {
RulerCommand::RulerCommand () RulerCommand::RulerCommand ()
: Command () : Command ()
, _ruler () , _ruler ()
, _drawing(false)
{ } { }
@ -56,7 +57,7 @@ namespace Hurricane {
void RulerCommand::mouseMoveEvent ( QMouseEvent* event ) void RulerCommand::mouseMoveEvent ( QMouseEvent* event )
{ {
if ( !isActive() ) return; if ( not isActive() or not _drawing ) return;
_ruler->setExtremity ( _cellWidget->_onCursorGrid(_cellWidget->screenToDbuPoint(event->pos())) ); _ruler->setExtremity ( _cellWidget->_onCursorGrid(_cellWidget->screenToDbuPoint(event->pos())) );
_cellWidget->update (); _cellWidget->update ();
@ -65,38 +66,46 @@ namespace Hurricane {
void RulerCommand::mousePressEvent ( QMouseEvent* event ) void RulerCommand::mousePressEvent ( QMouseEvent* event )
{ {
if ( (event->modifiers() & Qt::ShiftModifier ) if ( not isActive() ) return;
and (event->button() == Qt::LeftButton ) ) {
setActive ( true ); if ( event->button() == Qt::LeftButton ) {
if ( not _drawing ) {
_drawing = true;
_ruler.reset ( new Ruler _ruler.reset ( new Ruler
(_cellWidget->_onCursorGrid(_cellWidget->screenToDbuPoint(_cellWidget->getMousePosition())) ) ); (_cellWidget->_onCursorGrid(_cellWidget->screenToDbuPoint(_cellWidget->getMousePosition())) ) );
return; } else {
}
if ( isActive() ) {
if ( event->button() != Qt::RightButton )
_cellWidget->addRuler ( _ruler );
setActive ( false ); setActive ( false );
_drawing = false;
_cellWidget->addRuler ( _ruler );
_ruler.reset (); _ruler.reset ();
} }
} }
}
void RulerCommand::keyPressEvent ( QKeyEvent* event ) void RulerCommand::keyPressEvent ( QKeyEvent* event )
{ {
if ( !isActive() ) return; if ( isActive() and (event->key() == Qt::Key_Escape) ) {
if ( event->key() == Qt::Key_Escape ) {
setActive ( false ); setActive ( false );
_drawing = false;
_ruler.reset (); _ruler.reset ();
return;
} }
if ( event->key() != Qt::Key_K ) return;
if ( event->modifiers() & Qt::ShiftModifier ) {
_cellWidget->clearRulers ();
return;
}
setActive ( true );
} }
void RulerCommand::draw () void RulerCommand::draw ()
{ {
if ( !isActive() ) return; if ( not _drawing ) return;
_cellWidget->drawRuler ( _ruler ); _cellWidget->drawRuler ( _ruler );
} }

View File

@ -47,9 +47,10 @@ namespace Hurricane {
private: private:
RulerCommand ( const RulerCommand& ); RulerCommand ( const RulerCommand& );
RulerCommand& operator= ( const RulerCommand& ); RulerCommand& operator= ( const RulerCommand& );
protected: private:
static string _name; static string _name;
std::tr1::shared_ptr<Ruler> _ruler; std::tr1::shared_ptr<Ruler> _ruler;
bool _drawing;
}; };