-
Notifications
You must be signed in to change notification settings - Fork 122
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refs #5167 ellipse overlay prototype
- Loading branch information
1 parent
8ef224b
commit 9a3d55b
Showing
5 changed files
with
222 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
104 changes: 104 additions & 0 deletions
104
Code/Mantid/MantidQt/SliceViewer/inc/MantidQtSliceViewer/PeakOverlay.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 © 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_ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters