Skip to content

Commit

Permalink
Re #6162. Corrected shape selection. Added image to cursor
Browse files Browse the repository at this point in the history
  • Loading branch information
mantid-roman committed Jan 3, 2013
1 parent e9551b5 commit bb53650
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -299,28 +299,31 @@ InputControllerErase::InputControllerErase(QObject *parent):
InputController(parent),
m_max_size(32),
m_size(30),
m_isButtonPressed(false)
m_isButtonPressed(false),
m_isActive(true),
m_rect( 0, 0, m_size, m_size )
{
m_pixmap = new QPixmap(m_max_size,m_max_size);
m_cursor = new QPixmap(m_max_size,m_max_size);
drawCursor();
m_image = new QPixmap(":/PickTools/eraser.png");
}

InputControllerErase::~InputControllerErase()
{
delete m_pixmap;
delete m_cursor;
delete m_image;
}

/**
* Process the mouse press event.
*/
void InputControllerErase::mousePressEvent(QMouseEvent *event)
{
m_rect.moveTopLeft(QPoint(event->x(),event->y()));
if (event->button() == Qt::LeftButton)
{
m_isButtonPressed = true;
QRect rect(m_rect);
rect.moveTopLeft(QPoint(event->x(),event->y()));
emit erase( rect );
emit erase( m_rect );
}
}

Expand All @@ -329,11 +332,10 @@ void InputControllerErase::mousePressEvent(QMouseEvent *event)
*/
void InputControllerErase::mouseMoveEvent(QMouseEvent *event)
{
m_rect.moveTopLeft(QPoint(event->x(),event->y()));
if ( m_isButtonPressed )
{
QRect rect(m_rect);
rect.moveTopLeft(QPoint(event->x(),event->y()));
emit erase( rect );
emit erase( m_rect );
}
}

Expand All @@ -353,31 +355,35 @@ void InputControllerErase::wheelEvent(QWheelEvent *event)
m_size = d;
drawCursor();
QApplication::restoreOverrideCursor();
QApplication::setOverrideCursor(QCursor( *m_pixmap, 0, 0 ));
QApplication::setOverrideCursor(QCursor( *m_cursor, 0, 0 ));
}
}

void InputControllerErase::onPaint(QPainter&)
void InputControllerErase::onPaint(QPainter& painter)
{
//painter.drawEllipse(m_x,m_y,m_size,m_size);
if ( m_isActive && !m_isButtonPressed )
{
painter.drawPixmap(m_rect.bottomRight(),*m_image);
}
}

void InputControllerErase::enterEvent(QEvent *)
{
QApplication::setOverrideCursor(QCursor( *m_pixmap, 0, 0 ));
QApplication::setOverrideCursor(QCursor( *m_cursor, 0, 0 ));
m_isActive = true;
}

void InputControllerErase::leaveEvent(QEvent *)
{
QApplication::restoreOverrideCursor();
m_isActive = false;
}

void InputControllerErase::drawCursor()
{
m_pixmap->fill(QColor(255,255,255,0));
QPainter painter( m_pixmap );
//int x = (m_max_size - m_size) / 2;
m_rect = QRect( 0, 0, m_size, m_size );
painter.fillRect( m_rect, QColor(255,255,255,100) );
m_cursor->fill(QColor(255,255,255,0));
QPainter painter( m_cursor );
painter.fillRect( QRect( 0, 0, m_size, m_size ), QColor(255,255,255,100) );
m_rect.setSize( QSize(m_size,m_size) );
}

Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,10 @@ class InputControllerErase: public InputController
const int m_max_size;
int m_size; ///< Size of the eraser
bool m_isButtonPressed;
bool m_isActive;
QRect m_rect;
QPixmap *m_pixmap;
QPixmap *m_cursor;
QPixmap *m_image;
};

#endif // INPUTCONTROLLER_H
Original file line number Diff line number Diff line change
Expand Up @@ -130,15 +130,12 @@ void PeakOverlay::removeShapes(const QList<Shape2D*>& shapeList)
{
// vectors of rows to delete from the peaks workspace.
std::vector<size_t> rows;
std::cerr << "Removing ";
foreach(Shape2D* shape, shapeList)
{
PeakMarker2D* marker = dynamic_cast<PeakMarker2D*>(shape);
if ( !marker ) throw std::logic_error("Wrong shape type found.");
rows.push_back( static_cast<size_t>( marker->getRow() ) );
std::cerr << rows.back() << ' ';
}
std::cerr << std::endl;

// Run the DeleteTableRows algorithm to delete the peak.
auto alg = Mantid::API::AlgorithmManager::Instance().create("DeleteTableRows",-1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ void Projection3D::resize(int w, int h)
{
m_viewport->resize(w,h);
m_viewport->issueGL();
updateView();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ void ProjectionSurface::draw(MantidGLWidget *widget,bool picking)const
// Discard any error generated here
glGetError();
}

}

/**
Expand Down Expand Up @@ -250,6 +251,11 @@ void ProjectionSurface::drawSimple(QWidget* widget)const
painter.end();
}

void ProjectionSurface::resize(int, int)
{
updateView();
}

/**
* Draw the surface onto an image without OpenGL
* @param image :: Image to draw on.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class ProjectionSurface: public QObject
/// draw the surface onto a normal widget
virtual void drawSimple(QWidget* widget)const;
/// called when the gl widget gets resized
virtual void resize(int, int){}
virtual void resize(int, int);
/// redraw surface without recalulationg of colours, etc
virtual void updateView();
/// full update and redraw of the surface
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class Shape2D
virtual bool selectAt(const QPointF& )const{return false;}
// is a point inside the shape (closed line)
virtual bool contains(const QPointF& )const{return false;}
// is a point "masked" by the shape. Only filled regians of a shape mask a point
// is a point "masked" by the shape. Only filled regions of a shape mask a point
virtual bool isMasked(const QPointF& )const;

// --- Public methods --- //
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -338,12 +338,25 @@ bool Shape2DCollection::selectAtXY(int x,int y)
*/
bool Shape2DCollection::selectIn(const QRect& rect)
{
RectF r( m_transform.inverted().mapRect( rect ) );
RectF untransformedRect = QRectF(rect);
RectF r( m_transform.inverted().mapRect( QRectF(rect) ) );
bool selected = false;
deselectAll();
foreach(Shape2D* shape,m_shapes)
{
if ( r.contains( shape->getBoundingRect() ) )
bool sel = false;
if ( shape->isScalable() )
{
sel = r.contains( shape->getBoundingRect() );
}
else
{
QPointF dp = m_transform.map( shape->origin() ) - shape->origin();
RectF br = shape->getBoundingRect();
br.translate( dp );
sel = untransformedRect.contains( br );
}
if ( sel )
{
shape->edit( true );
selected = true;
Expand Down

0 comments on commit bb53650

Please sign in to comment.