Skip to content

Commit

Permalink
Refs #3882 ColorBarWidget
Browse files Browse the repository at this point in the history
  • Loading branch information
Janik Zikovsky committed Oct 31, 2011
1 parent 5429444 commit 86bd358
Show file tree
Hide file tree
Showing 6 changed files with 260 additions and 1 deletion.
8 changes: 8 additions & 0 deletions Code/Mantid/MantidQt/SliceViewer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ set ( SRC_FILES
src/DimensionSliceWidget.cpp
src/QwtRasterDataMD.cpp
src/SliceViewer.cpp
src/ColorBarWidget.cpp
)

# Include files aren't required, but this makes them appear in Visual Studio
Expand All @@ -11,17 +12,20 @@ set ( INC_FILES
inc/MantidQtSliceViewer/DimensionSliceWidget.h
inc/MantidQtSliceViewer/QwtRasterDataMD.h
inc/MantidQtSliceViewer/SliceViewer.h
inc/MantidQtSliceViewer/ColorBarWidget.h
)

set ( MOC_FILES
inc/MantidQtSliceViewer/CustomTools.h
inc/MantidQtSliceViewer/DimensionSliceWidget.h
inc/MantidQtSliceViewer/SliceViewer.h
inc/MantidQtSliceViewer/ColorBarWidget.h
)

set ( UI_FILES
inc/MantidQtSliceViewer/DimensionSliceWidget.ui
inc/MantidQtSliceViewer/SliceViewer.ui
inc/MantidQtSliceViewer/ColorBarWidget.ui
)


Expand All @@ -42,6 +46,10 @@ add_library ( MantidQtSliceViewer ${ALL_SRC} ${INC_FILES} ${UI_HDRS} )

target_link_libraries ( MantidQtSliceViewer MantidQtAPI QtPropertyBrowser ${QT_LIBRARIES} ${QWT_LIBRARIES} )

# Extra, optional target for demoing a GUI element
add_executable ( ColorBarWidgetDemo EXCLUDE_FROM_ALL ${ALL_SRC} src/main_ColorBarWidget.cpp ${INC_FILES} ${QTIPLOT_C_SRC} ${UI_HDRS})
target_link_libraries ( ColorBarWidgetDemo MantidQtAPI QtPropertyBrowser ${QT_LIBRARIES} ${QWT_LIBRARIES} )

###########################################################################
# Installation settings
###########################################################################
Expand Down
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
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 Code/Mantid/MantidQt/SliceViewer/src/ColorBarWidget.cpp
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()
{

}
3 changes: 2 additions & 1 deletion Code/Mantid/MantidQt/SliceViewer/src/SliceViewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "MantidAPI/IMDIterator.h"
#include "MantidGeometry/MDGeometry/IMDDimension.h"
#include "MantidGeometry/MDGeometry/MDBoxImplicitFunction.h"
#include "MantidGeometry/MDGeometry/MDHistoDimension.h"
#include "MantidGeometry/MDGeometry/MDTypes.h"
#include "MantidKernel/VMD.h"
#include "MantidQtSliceViewer/CustomTools.h"
Expand All @@ -22,9 +23,9 @@
#include <qwt_plot_zoomer.h>
#include <qwt_plot.h>
#include <qwt_scale_engine.h>
#include <qwt_scale_map.h>
#include <sstream>
#include <vector>
#include "MantidGeometry/MDGeometry/MDHistoDimension.h"

using namespace Mantid;
using namespace Mantid::Kernel;
Expand Down
47 changes: 47 additions & 0 deletions Code/Mantid/MantidQt/SliceViewer/src/main_ColorBarWidget.cpp
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;
}

0 comments on commit 86bd358

Please sign in to comment.