-
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.
- Loading branch information
Janik Zikovsky
committed
Oct 31, 2011
1 parent
5429444
commit 86bd358
Showing
6 changed files
with
260 additions
and
1 deletion.
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
49 changes: 49 additions & 0 deletions
49
Code/Mantid/MantidQt/SliceViewer/inc/MantidQtSliceViewer/ColorBarWidget.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,49 @@ | ||
#ifndef COLORBARWIDGET_H | ||
#define COLORBARWIDGET_H | ||
|
||
#include <QtGui/QWidget> | ||
#include "ui_ColorBarWidget.h" | ||
#include <qwt_color_map.h> | ||
#include <qwt_scale_widget.h> | ||
|
||
class ColorBarWidget : public QWidget | ||
{ | ||
Q_OBJECT | ||
|
||
public: | ||
ColorBarWidget(QWidget *parent = 0); | ||
~ColorBarWidget(); | ||
|
||
void setColorMap(QwtColorMap * colorMap); | ||
void setDataRange(double min, double max); | ||
void setViewRange(double min, double max); | ||
void setLog(bool log); | ||
|
||
void update(); | ||
|
||
private: | ||
Ui::ColorBarWidgetClass ui; | ||
|
||
// The color bar widget from QWT | ||
QwtScaleWidget * m_colorBar; | ||
|
||
/// Color map being displayed | ||
QwtColorMap * m_colorMap; | ||
|
||
/// Logarithmic scale? | ||
bool m_log; | ||
|
||
/// Min value in the data shown | ||
double m_rangeMin; | ||
|
||
/// Max value in the data shown | ||
double m_rangeMax; | ||
|
||
/// Min value being displayed | ||
double m_min; | ||
|
||
/// Min value being displayed | ||
double m_max; | ||
}; | ||
|
||
#endif // COLORBARWIDGET_H |
51 changes: 51 additions & 0 deletions
51
Code/Mantid/MantidQt/SliceViewer/inc/MantidQtSliceViewer/ColorBarWidget.ui
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,51 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<ui version="4.0"> | ||
<class>ColorBarWidgetClass</class> | ||
<widget class="QWidget" name="ColorBarWidgetClass"> | ||
<property name="geometry"> | ||
<rect> | ||
<x>0</x> | ||
<y>0</y> | ||
<width>64</width> | ||
<height>286</height> | ||
</rect> | ||
</property> | ||
<property name="windowTitle"> | ||
<string>ColorBarWidget</string> | ||
</property> | ||
<layout class="QVBoxLayout" name="verticalLayout_2"> | ||
<property name="spacing"> | ||
<number>0</number> | ||
</property> | ||
<property name="margin"> | ||
<number>0</number> | ||
</property> | ||
<item> | ||
<layout class="QVBoxLayout" name="verticalLayout"> | ||
<property name="spacing"> | ||
<number>3</number> | ||
</property> | ||
<item> | ||
<widget class="QCheckBox" name="checkLog"> | ||
<property name="toolTip"> | ||
<string>Use a logarithmic color scale (when checked)</string> | ||
</property> | ||
<property name="text"> | ||
<string>Log</string> | ||
</property> | ||
</widget> | ||
</item> | ||
<item> | ||
<widget class="QDoubleSpinBox" name="valMax"/> | ||
</item> | ||
<item> | ||
<widget class="QDoubleSpinBox" name="valMin"/> | ||
</item> | ||
</layout> | ||
</item> | ||
</layout> | ||
</widget> | ||
<layoutdefault spacing="6" margin="11"/> | ||
<resources/> | ||
<connections/> | ||
</ui> |
103 changes: 103 additions & 0 deletions
103
Code/Mantid/MantidQt/SliceViewer/src/ColorBarWidget.cpp
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,103 @@ | ||
#include "MantidQtSliceViewer/ColorBarWidget.h" | ||
#include <qwt_scale_widget.h> | ||
#include "qwt_scale_div.h" | ||
#include <qwt_scale_map.h> | ||
|
||
ColorBarWidget::ColorBarWidget(QWidget *parent) | ||
: QWidget(parent) | ||
{ | ||
ui.setupUi(this); | ||
|
||
// Default values. | ||
m_colorMap = new QwtLinearColorMap(Qt::blue, Qt::red); | ||
m_min = 0; | ||
m_max = 10; | ||
|
||
// Create and add the color bar | ||
m_colorBar = new QwtScaleWidget(); | ||
ui.verticalLayout->insertWidget(2,m_colorBar, 1,0 ); | ||
|
||
this->update(); | ||
} | ||
|
||
|
||
/** Change the color map shown | ||
* | ||
* @param colorMap | ||
*/ | ||
void ColorBarWidget::setColorMap(QwtColorMap * colorMap) | ||
{ | ||
if (m_colorMap) delete m_colorMap; | ||
m_colorMap = colorMap; | ||
update(); | ||
} | ||
|
||
|
||
/** Set the range of values in the overall data (limits to selections) | ||
* | ||
* @param min | ||
* @param max | ||
*/ | ||
void ColorBarWidget::setDataRange(double min, double max) | ||
{ | ||
m_rangeMin = min; | ||
m_rangeMax = max; | ||
ui.valMin->setMinimum( m_rangeMin ); | ||
ui.valMin->setMaximum( m_rangeMax ); | ||
ui.valMax->setMinimum( m_rangeMin ); | ||
ui.valMax->setMaximum( m_rangeMax ); | ||
} | ||
|
||
/** Set the range of values viewed in the color bar | ||
* | ||
* @param min :: min value = start of the color map | ||
* @param max :: max value = end of the color map | ||
*/ | ||
void ColorBarWidget::setViewRange(double min, double max) | ||
{ | ||
m_min = min; | ||
m_max = max; | ||
update(); | ||
} | ||
|
||
/** Set the color bar to use log scale | ||
* | ||
* @param log :: true to use log scale | ||
*/ | ||
void ColorBarWidget::setLog(bool log) | ||
{ | ||
m_log = log; | ||
update(); | ||
} | ||
|
||
|
||
|
||
/** Update the widget when the color map is changed in any way */ | ||
void ColorBarWidget::update() | ||
{ | ||
m_colorBar->setColorBarEnabled(true); | ||
m_colorBar->setColorMap( QwtDoubleInterval(m_min, m_max), *m_colorMap); | ||
m_colorBar->setColorBarWidth(15); | ||
|
||
QwtScaleDiv scaleDiv; | ||
scaleDiv.setInterval(m_min, m_max); | ||
m_colorBar->setScaleDiv(new QwtScaleTransformation(QwtScaleTransformation::Linear), scaleDiv); | ||
|
||
ui.valMin->setValue( m_min ); | ||
ui.valMax->setValue( m_max ); | ||
|
||
// QList<double> ticks; | ||
// ticks.push_back(1); | ||
// ticks.push_back(2); | ||
// ticks.push_back(3); | ||
// ticks.push_back(4); | ||
// ticks.push_back(5); | ||
// scaleDiv.setTicks(QwtScaleDiv::MajorTick, ticks); | ||
|
||
} | ||
|
||
|
||
ColorBarWidget::~ColorBarWidget() | ||
{ | ||
|
||
} |
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
47 changes: 47 additions & 0 deletions
47
Code/Mantid/MantidQt/SliceViewer/src/main_ColorBarWidget.cpp
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,47 @@ | ||
#include "MantidQtSliceViewer/ColorBarWidget.h" | ||
#include "qmainwindow.h" | ||
#include <iostream> | ||
#include <QApplication> | ||
#include <QDir> | ||
#include <QMessageBox> | ||
#include <QSplashScreen> | ||
#include <QThread> | ||
|
||
/** Demo application for quickly testing the ColorBarWidget GUI. | ||
* | ||
* @author Janik Zikovsky | ||
* @date Oct 3, 2011 | ||
*/ | ||
|
||
|
||
/** Main application | ||
* | ||
* @param argc :: ignored | ||
* @param argv :: ignored | ||
* @return return code | ||
*/ | ||
int main( int argc, char ** argv ) | ||
{ | ||
QApplication app(argc, argv); | ||
app.setOrganizationName("MantidProject"); | ||
app.setApplicationName("Color Bar Widget Example"); | ||
QMainWindow * mainWin = new QMainWindow(); | ||
|
||
QFrame * frame = new QFrame(mainWin); | ||
mainWin->setCentralWidget(frame); | ||
|
||
QLayout * layout = new QVBoxLayout(frame); | ||
frame->setLayout(layout); | ||
|
||
ColorBarWidget * widget = new ColorBarWidget(frame); | ||
layout->addWidget(widget); | ||
mainWin->move(100, 100); | ||
mainWin->resize(40, 500); | ||
mainWin->show(); | ||
|
||
app.exec(); | ||
|
||
mainWin->close(); | ||
delete mainWin; | ||
return 0; | ||
} |