Skip to content

Commit

Permalink
refs #5167 ellipse overlay prototype
Browse files Browse the repository at this point in the history
  • Loading branch information
OwenArnold committed Aug 23, 2012
1 parent 8ef224b commit 9a3d55b
Show file tree
Hide file tree
Showing 5 changed files with 222 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Code/Mantid/MantidQt/SliceViewer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ set ( SRC_FILES
src/DimensionSliceWidget.cpp
src/LineOverlay.cpp
src/LineViewer.cpp
src/PeakOverlay.cpp
src/QScienceSpinBox.cpp
src/QwtRasterDataMD.cpp
src/SliceViewer.cpp
Expand All @@ -21,6 +22,7 @@ set ( INC_FILES
inc/MantidQtSliceViewer/LineOverlay.h
inc/MantidQtSliceViewer/LinePlotOptions.h
inc/MantidQtSliceViewer/LineViewer.h
inc/MantidQtSliceViewer/PeakOverlay.h
inc/MantidQtSliceViewer/QScienceSpinBox.h
inc/MantidQtSliceViewer/QwtRasterDataMD.h
inc/MantidQtSliceViewer/SliceViewer.h
Expand All @@ -35,6 +37,7 @@ set ( MOC_FILES
inc/MantidQtSliceViewer/LineOverlay.h
inc/MantidQtSliceViewer/LineViewer.h
inc/MantidQtSliceViewer/LinePlotOptions.h
inc/MantidQtSliceViewer/PeakOverlay.h
inc/MantidQtSliceViewer/SliceViewer.h
inc/MantidQtSliceViewer/SliceViewerWindow.h
inc/MantidQtSliceViewer/ColorBarWidget.h
Expand Down
104 changes: 104 additions & 0 deletions Code/Mantid/MantidQt/SliceViewer/inc/MantidQtSliceViewer/PeakOverlay.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
#ifndef MANTID_SLICEVIEWER_PEAKOVERLAY_H_
#define MANTID_SLICEVIEWER_PEAKOVERLAY_H_

#include "DllOption.h"
#include "MantidKernel/System.h"
#include <q3iconview.h>
#include <QtCore/QtCore>
#include <QtGui/qwidget.h>
#include <qwt_plot.h>
#include <qpainter.h>


namespace MantidQt
{
namespace SliceViewer
{

/** GUI for overlaying a peak circle on the plot.
@date 2012-08-22
Copyright &copy; 2011 ISIS Rutherford Appleton Laboratory & NScD Oak Ridge National Laboratory
This file is part of Mantid.
Mantid is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
Mantid is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
File change history is stored at: <https://svn.mantidproject.org/mantid/trunk/Code/Mantid>
Code Documentation is available at: <http://doxygen.mantidproject.org>
*/
class EXPORT_OPT_MANTIDQT_SLICEVIEWER PeakOverlay : public QWidget
{
Q_OBJECT

/// Enum giving IDs to the 4 handles on the widget
enum eHandleID
{
HandleNone = -1,
HandleA = 0,
HandleB = 1,
HandleWidthTop = 2,
HandleWidthBottom = 3,
HandleCenter = 4 // Anywhere inside the center
};

public:
PeakOverlay(QwtPlot * plot, QWidget * parent);
virtual ~PeakOverlay();

void reset();

void setOrigin(QPointF origin);
void setRadius(double radius);

const QPointF & getOrigin() const;
const double getRadius() const;

signals:


private:

//QRect drawHandle(QPainter & painter, QPointF coords, QColor brush);
void paintEvent(QPaintEvent *event);

//eHandleID mouseOverHandle(QPoint pos);
//bool mouseOverCenter(QPoint pos);
//void handleDrag(QMouseEvent * event);
//void mouseMoveEvent(QMouseEvent * event);
//void mousePressEvent(QMouseEvent * event);
//void mouseReleaseEvent(QMouseEvent * event);

QSize sizeHint() const;
QSize size() const;
int height() const;
int width() const;

protected:

/// QwtPlot containing this
QwtPlot * m_plot;

QPointF m_origin;

double m_radius;

};


} // namespace SliceViewer
} // namespace Mantid

#endif /* MANTID_SLICEVIEWER_PEAKOVERLAY_H_ */
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "MantidQtMantidWidgets/SafeQwtPlot.h"
#include "MantidQtAPI/SyncedCheckboxes.h"
#include "MantidQtSliceViewer/LineOverlay.h"
#include "MantidQtSliceViewer/PeakOverlay.h"
#include "QwtRasterDataMD.h"
#include "ui_SliceViewer.h"
#include <QtCore/QtCore>
Expand Down Expand Up @@ -185,6 +186,8 @@ public slots:
/// The LineOverlay widget for drawing the outline of the rebinned workspace
LineOverlay * m_overlayWSOutline;

PeakOverlay * m_peakOverlay;

/// Object for running algorithms in the background
MantidQt::API::AlgorithmRunner * m_algoRunner;

Expand Down
109 changes: 109 additions & 0 deletions Code/Mantid/MantidQt/SliceViewer/src/PeakOverlay.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
#include "MantidQtSliceViewer/PeakOverlay.h"
#include <qwt_plot.h>
#include <qwt_plot_canvas.h>
#include <iostream>
#include <qpainter.h>
#include <QRect>
#include <QShowEvent>
#include "MantidKernel/Utils.h"

using namespace Mantid::Kernel;


namespace MantidQt
{
namespace SliceViewer
{


//----------------------------------------------------------------------------------------------
/** Constructor
*/
PeakOverlay::PeakOverlay(QwtPlot * plot, QWidget * parent)
: QWidget( parent ),
m_plot(plot)
{
m_origin = QPointF(0.0, 0.0);
m_radius = 0.1;
//setAttribute(Qt::WA_TransparentForMouseEvents);
// We need mouse events all the time
setMouseTracking(true);
//setAttribute(Qt::WA_TransparentForMouseEvents);
// Make sure mouse propagates
setAttribute(Qt::WA_NoMousePropagation, false);
}

//----------------------------------------------------------------------------------------------
/** Destructor
*/
PeakOverlay::~PeakOverlay()
{
}

////----------------------------------------------------------------------------------------------
///** Reset the line. User will have to click to create it */
//void PeakOverlay::reset()
//{
// m_creation = true; // Will create with the mouse
// m_rightButton = false;
// m_dragHandle = HandleNone;
// this->update();
//}



void PeakOverlay::setOrigin(QPointF origin)
{
m_origin = origin;
this->update(); //repaint
}

void PeakOverlay::setRadius(double radius)
{
m_radius = radius;
this->update(); //repaint
}

const QPointF & PeakOverlay::getOrigin() const
{ return m_origin; }

const double PeakOverlay::getRadius() const
{ return m_radius; }

//----------------------------------------------------------------------------------------------
/// Return the recommended size of the widget
QSize PeakOverlay::sizeHint() const
{
//TODO: Is there a smarter way to find the right size?
return QSize(20000, 20000);
// Always as big as the canvas
//return m_plot->canvas()->size();
}

QSize PeakOverlay::size() const
{ return m_plot->canvas()->size(); }
int PeakOverlay::height() const
{ return m_plot->canvas()->height(); }
int PeakOverlay::width() const
{ return m_plot->canvas()->width(); }




//----------------------------------------------------------------------------------------------
/// Paint the overlay
void PeakOverlay::paintEvent(QPaintEvent * /*event*/)
{

QPainter painter(this);
painter.setRenderHint( QPainter::Antialiasing );

//painter.setPen( Qt::black );
painter.setBrush(Qt::red);
painter.drawEllipse( m_origin, width()/2, height()/2 );

}


} // namespace Mantid
} // namespace SliceViewer
3 changes: 3 additions & 0 deletions Code/Mantid/MantidQt/SliceViewer/src/SliceViewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "MantidQtSliceViewer/CustomTools.h"
#include "MantidQtSliceViewer/DimensionSliceWidget.h"
#include "MantidQtSliceViewer/LineOverlay.h"
#include "MantidQtSliceViewer/PeakOverlay.h"
#include "MantidQtSliceViewer/QwtRasterDataMD.h"
#include "MantidQtSliceViewer/SliceViewer.h"
#include "MantidQtSliceViewer/SnapToGridDialog.h"
Expand Down Expand Up @@ -138,6 +139,8 @@ SliceViewer::SliceViewer(QWidget *parent)
m_lineOverlay = new LineOverlay(m_plot, m_plot->canvas());
m_lineOverlay->setShown(false);

m_peakOverlay = new PeakOverlay(m_plot, m_plot->canvas());

m_overlayWSOutline = new LineOverlay(m_plot, m_lineOverlay);
m_overlayWSOutline->setShowHandles(false);
m_overlayWSOutline->setShowLine(false);
Expand Down

0 comments on commit 9a3d55b

Please sign in to comment.