Starting from 2021-07-01, all LRZ GitLab users will be required to explicitly accept the GitLab Terms of Service. Please see the detailed information at https://doku.lrz.de/display/PUBLIC/GitLab and make sure that your projects conform to the requirements.

Commit b7aa2254 authored by schultezub's avatar schultezub
Browse files

* introducing QtColorTools

* introducing transfer function editors: AbstractTransferFunctionEditor, SimpleTransferFunctionEditor and TransferFunctionEditorFactory
* added editor usage to TransferFunctionPropertyWidget

git-svn-id: https://camplinux.in.tum.de/svn/campvis/trunk@212 bb408c1c-ae56-11e1-83d9-df6b3e0c105e
parent 89be8373
......@@ -19,9 +19,12 @@ FILE(GLOB TUMVIS_APPLICATION_HEADERS
SET(TUMVIS_APPLICATION_TO_BE_MOCCED
gui/mainwindow.h
gui/pipelinetreewidget.h
gui/qtcolortools.h
gui/properties/abstractpropertywidget.h
gui/properties/abstracttransferfunctioneditor.h
gui/properties/intpropertywidget.h
gui/properties/propertycollectionwidget.h
gui/properties/simpletransferfunctioneditor.h
gui/properties/stringpropertywidget.h
gui/properties/transferfunctionpropertywidget.h
)
......
#include "abstracttransferfunctioneditor.h"
#include "core/classification/abstracttransferfunction.h"
namespace TUMVis {
AbstractTransferFunctionEditor::AbstractTransferFunctionEditor(AbstractTransferFunction* tf, QWidget* parent /*= 0*/)
: QWidget(parent)
, _transferFunction(tf)
, _ignorePropertyUpdates(false)
{
_transferFunction->s_changed.connect(this, &AbstractTransferFunctionEditor::onTFChanged);
}
AbstractTransferFunctionEditor::~AbstractTransferFunctionEditor() {
_transferFunction->s_changed.disconnect(this);
}
void AbstractTransferFunctionEditor::onTFChanged() {
if (!_ignorePropertyUpdates)
updateWidgetFromProperty();
}
}
\ No newline at end of file
#ifndef ABSTRACTTRANSFERFUNCTIONEDITOR_H__
#define ABSTRACTTRANSFERFUNCTIONEDITOR_H__
#include "sigslot/sigslot.h"
#include <QBoxLayout>
#include <QLabel>
#include <QWidget>
namespace TUMVis {
class AbstractProperty;
class AbstractTransferFunction;
/**
* Abstract base class for transfer function editors.
*/
class AbstractTransferFunctionEditor : public QWidget, public sigslot::has_slots<> {
Q_OBJECT;
public:
/**
* Creates a new editor widget for the for the AbstractTransferFunction \a tf.
* \param tf The transfer function the editor shall handle.
* \param parent Parent Qt widget
*/
AbstractTransferFunctionEditor(AbstractTransferFunction* tf, QWidget* parent = 0);
/**
* Destructor
*/
virtual ~AbstractTransferFunctionEditor();
protected:
/**
* Gets called when the property has changed, so that widget can update its state.
*/
virtual void updateWidgetFromProperty() = 0;
AbstractTransferFunction* _transferFunction; ///< The transfer function this widget handles
// TODO: This flag is not thread-safe, it probably should be...
bool _ignorePropertyUpdates; ///< Flag whether the widget shall ignore incoming signals from properties being updated.
private:
/// Slot getting called when the transfer function has changed, so that the widget can be updated.
virtual void onTFChanged();
};
}
#endif // ABSTRACTTRANSFERFUNCTIONEDITOR_H__
#include "simpletransferfunctioneditor.h"
#include "application/gui/qtcolortools.h"
#include "core/classification/simpletransferfunction.h"
#include "core/properties/transferfunctionproperty.h"
#include <QGridLayout>
#include <QLabel>
namespace TUMVis {
SimpleTransferFunctionEditor::SimpleTransferFunctionEditor(SimpleTransferFunction* tf, QWidget* parent /*= 0*/)
: AbstractTransferFunctionEditor(tf, parent)
, _layout(0)
, _lblColorLeft(0)
, _lblColorRight(0)
, _cpwColorLeft(0)
, _cpwColorRight(0)
{
_layout = new QGridLayout(this);
setLayout(_layout);
_lblColorLeft = new QLabel("Left Color: ", this);
_lblColorRight = new QLabel("Right Color: ", this);
_cpwColorLeft = new ColorPickerWidget(QtColorTools::toQColor(tf->getLeftColor()), this);
_cpwColorRight = new ColorPickerWidget(QtColorTools::toQColor(tf->getRightColor()), this);
_layout->addWidget(_lblColorLeft, 0, 0);
_layout->addWidget(_cpwColorLeft, 0, 1);
_layout->addWidget(_lblColorRight, 1, 0);
_layout->addWidget(_cpwColorRight, 1, 1);
connect(_cpwColorLeft, SIGNAL(colorChanged(const QColor&)), this, SLOT(onLeftColorChanged(const QColor&)));
connect(_cpwColorRight, SIGNAL(colorChanged(const QColor&)), this, SLOT(onRightColorChanged(const QColor&)));
}
SimpleTransferFunctionEditor::~SimpleTransferFunctionEditor() {
}
void SimpleTransferFunctionEditor::updateWidgetFromProperty() {
SimpleTransferFunction* stf = static_cast<SimpleTransferFunction*>(_transferFunction);
_cpwColorLeft->blockSignals(true);
_cpwColorRight->blockSignals(true);
_cpwColorLeft->setColor(QtColorTools::toQColor(static_cast<SimpleTransferFunction*>(_transferFunction)->getLeftColor()));
_cpwColorRight->setColor(QtColorTools::toQColor(static_cast<SimpleTransferFunction*>(_transferFunction)->getRightColor()));
_cpwColorLeft->blockSignals(false);
_cpwColorRight->blockSignals(false);
}
void SimpleTransferFunctionEditor::onLeftColorChanged(const QColor& color) {
_ignorePropertyUpdates = true;
static_cast<SimpleTransferFunction*>(_transferFunction)->setLeftColor(QtColorTools::toTgtColor(_cpwColorLeft->color()));
_ignorePropertyUpdates = false;
}
void SimpleTransferFunctionEditor::onRightColorChanged(const QColor& color) {
_ignorePropertyUpdates = true;
static_cast<SimpleTransferFunction*>(_transferFunction)->setRightColor(QtColorTools::toTgtColor(_cpwColorRight->color()));
_ignorePropertyUpdates = false;
}
}
\ No newline at end of file
#ifndef SIMPLETRANSFERFUNCTIONEDITOR_H__
#define SIMPLETRANSFERFUNCTIONEDITOR_H__
#include "application/gui/properties/abstracttransferfunctioneditor.h"
#include <QWidget>
class QGridLayout;
class QLabel;
namespace TUMVis {
class ColorPickerWidget;
class SimpleTransferFunction;
/**
* Editor widget for a SimpleTransferFunction.
*/
class SimpleTransferFunctionEditor : public AbstractTransferFunctionEditor {
Q_OBJECT;
public:
/**
* Creates a new editor widget for the for the TransferFunctionProperty \a property.
* \param tf The transfer function the editor shall handle.
* \param parent Parent Qt widget
*/
SimpleTransferFunctionEditor(SimpleTransferFunction* tf, QWidget* parent = 0);
/**
* Destructor
*/
virtual ~SimpleTransferFunctionEditor();
protected:
/**
* Gets called when the property has changed, so that widget can update its state.
*/
virtual void updateWidgetFromProperty();
private slots:
void onLeftColorChanged(const QColor& color);
void onRightColorChanged(const QColor& color);
private:
QGridLayout* _layout;
QLabel* _lblColorLeft;
QLabel* _lblColorRight;
ColorPickerWidget* _cpwColorLeft;
ColorPickerWidget* _cpwColorRight;
};
}
#endif // SIMPLETRANSFERFUNCTIONEDITOR_H__
#include "transferfunctioneditorfactory.h"
#include "application/gui/properties/abstracttransferfunctioneditor.h"
#include "application/gui/properties/simpletransferfunctioneditor.h"
#include "core/classification/abstracttransferfunction.h"
#include "core/classification/simpletransferfunction.h"
namespace TUMVis {
AbstractTransferFunctionEditor* TransferFunctionEditorFactory::createEditor(AbstractTransferFunction* tf) {
tgtAssert(tf != 0, "Transfer function must not be 0.");
if (SimpleTransferFunction* tester = dynamic_cast<SimpleTransferFunction*>(tf)) {
return new SimpleTransferFunctionEditor(tester);
}
return 0;
}
}
#ifndef TRANSFERFUNCTIONEDITORFACTORY_H__
#define TRANSFERFUNCTIONEDITORFACTORY_H__
namespace TUMVis {
class AbstractTransferFunction;
class AbstractTransferFunctionEditor;
class TransferFunctionEditorFactory {
public:
/**
*
* \param property
* \return
*/
static AbstractTransferFunctionEditor* createEditor(AbstractTransferFunction* tf);
};
}
#endif // TRANSFERFUNCTIONEDITORFACTORY_H__
#include "transferfunctionpropertywidget.h"
#include "application/gui/properties/abstracttransferfunctioneditor.h"
#include "application/gui/properties/transferfunctioneditorfactory.h"
#include <QDockWidget>
#include <QDoubleSpinBox>
#include <QGridLayout>
#include <QLabel>
#include <QPushButton>
namespace TUMVis {
TransferFunctionPropertyWidget::TransferFunctionPropertyWidget(TransferFunctionProperty* property, QWidget* parent /*= 0*/)
: AbstractPropertyWidget(property, parent)
......@@ -9,6 +17,8 @@ namespace TUMVis {
, _spinDomainLeft(0)
, _spinDomainRight(0)
, _btnEditTF(0)
,_dockWidget(0)
, _editor(0)
{
_widget = new QWidget(this);
_gridLayout = new QGridLayout(_widget);
......@@ -43,7 +53,8 @@ namespace TUMVis {
}
TransferFunctionPropertyWidget::~TransferFunctionPropertyWidget() {
delete _dockWidget;
delete _editor;
}
void TransferFunctionPropertyWidget::updateWidgetFromProperty() {
......@@ -73,7 +84,15 @@ namespace TUMVis {
}
void TransferFunctionPropertyWidget::onEditClicked(bool checked) {
// open editor window
if (_editor == 0) {
TransferFunctionProperty* prop = static_cast<TransferFunctionProperty*>(_property);
_editor = TransferFunctionEditorFactory::createEditor(prop->getTF());
_dockWidget = new QDockWidget("Transfer Function Editor");
_dockWidget->setWidget(_editor);
}
_dockWidget->setVisible(true);
}
......
......@@ -4,12 +4,15 @@
#include "application/gui/properties/abstractpropertywidget.h"
#include "core/properties/transferfunctionproperty.h"
#include <QDoubleSpinBox>
#include <QGridLayout>
#include <QLabel>
#include <QPushButton>
class QDockWidget;
class QDoubleSpinBox;
class QGridLayout;
class QLabel;
class QPushButton;
namespace TUMVis {
class AbstractTransferFunctionEditor;
/**
* Widget for a TransferFunctionProperty
*/
......@@ -50,6 +53,8 @@ namespace TUMVis {
QDoubleSpinBox* _spinDomainRight; ///< spin edit for intensity domain upper bound
QPushButton* _btnEditTF; ///< button for showing the TF editor widget
QDockWidget* _dockWidget; ///< DockWidget for transfer function editor
AbstractTransferFunctionEditor* _editor; ///< Transfer function editor
};
}
......
#include "qtcolortools.h"
#include <QColorDialog>
#include <QMouseEvent>
#include <QPainter>
namespace TUMVis {
tgt::col4 QtColorTools::toTgtColor(const QColor& color) {
return tgt::col4(color.red(),color.green(),color.blue(), color.alpha());
}
QColor QtColorTools::toQColor(const tgt::col4& color) {
return QColor(color.r, color.g, color.b, color.a);
}
ColorPickerWidget::ColorPickerWidget(const QColor& color /*= QColor::fromRgba(qRgba(0, 0, 0, 255))*/, QWidget* parent/*=0*/, Qt::WindowFlags f/*=0*/)
: QLabel(parent, f)
, _color(color)
{
setMinimumHeight(16);
}
const QColor& ColorPickerWidget::color() const {
return _color;
}
void ColorPickerWidget::setColor(const QColor& color) {
_color = color;
update();
}
void ColorPickerWidget::mousePressEvent(QMouseEvent* e) {
if (e->button() == Qt::LeftButton) {
// launch a color picker dialog and set new color on success
QColor newColor = QColorDialog::getColor(_color, this, "Select New Color", QColorDialog::ShowAlphaChannel);
if(newColor.isValid()) {
_color = newColor;
emit colorChanged(_color);
}
}
}
void ColorPickerWidget::paintEvent(QPaintEvent* event) {
QPainter painter(this);
painter.setBrush(_color);
painter.drawRect(1, 1, rect().width() - 2, rect().height() - 2);
}
}
\ No newline at end of file
#ifndef QTCOLORTOOLS_H__
#define QTCOLORTOOLS_H__
#include "tgt/vector.h"
#include <QColor>
#include <QLabel>
namespace TUMVis {
/**
* Some helper methods for Qt colors.
*/
struct QtColorTools {
/**
* Converts the QColor \a color to a tgt::col4.
* \param color Color to convert
* \return tgt::col4 version of \a color.
*/
static tgt::col4 toTgtColor(const QColor& color);
/**
* Converts the tgt::col4 color \a color to a QColor.
* \param color Color to convert
* \return QColor version of \a color.
*/
static QColor toQColor(const tgt::col4& color);
};
/**
* Qt widget for showing and editing a QColor.
* When clicking the widget a QColorDialog appears to change the color.
*/
class ColorPickerWidget : public QLabel {
Q_OBJECT
public:
/**
* Creates a new ColorPickerWidget.
* \param color Initial color
* \param parent Parent Qt widget
* \param f Qt WindowFlags
*/
ColorPickerWidget(const QColor& color = QColor::fromRgba(qRgba(0, 0, 0, 255)), QWidget* parent=0, Qt::WindowFlags f=0);
/**
* Returns the current color of the widget.
* \return _color
*/
const QColor& color() const;
/**
* Sets the current color of the widget.
* \param color New color of the widget.
*/
void setColor(const QColor& color);
signals:
/**
* Signal emitted when the color of the widget has changed.
* \param color New color of the widget.
*/
void colorChanged(const QColor& color);
private:
/// \override
void mousePressEvent(QMouseEvent* e);
/// \override
void paintEvent(QPaintEvent* event);
QColor _color; ///< Current color of the widget
};
}
#endif // QTCOLORTOOLS_H__
......@@ -54,7 +54,7 @@ namespace TUMVis {
tbb::mutex::scoped_lock lock(_localMutex);
_intensityDomain = newDomain;
}
s_Changed();
s_changed();
}
const tgt::vec2& AbstractTransferFunction::getIntensityDomain() const {
......
......@@ -79,7 +79,7 @@ namespace TUMVis {
const tgt::vec2& getIntensityDomain() const;
/// Signal emitted when transfer function has changed.
sigslot::signal0<> s_Changed;
sigslot::signal0<> s_changed;
protected:
/**
......
......@@ -50,15 +50,25 @@ namespace TUMVis {
tbb::mutex::scoped_lock lock(_localMutex);
_leftColor = color;
}
s_Changed;
_dirty = true;
s_changed();
}
void SimpleTransferFunction::setRightColor(const tgt::col4& color) {
{
tbb::mutex::scoped_lock lock(_localMutex);
_leftColor = color;
_rightColor = color;
}
s_Changed;
_dirty = true;
s_changed();
}
const tgt::col4& SimpleTransferFunction::getLeftColor() const {
return _leftColor;
}
const tgt::col4& SimpleTransferFunction::getRightColor() const {
return _rightColor;
}
}
\ No newline at end of file
......@@ -28,7 +28,9 @@ namespace TUMVis {
*/
virtual size_t getDimensionality() const;
const tgt::col4& getLeftColor() const;
void setLeftColor(const tgt::col4& color);
const tgt::col4& getRightColor() const;
void setRightColor(const tgt::col4& color);
protected:
......
......@@ -9,7 +9,7 @@ namespace TUMVis {
, _transferFunction(tf)
{
tgtAssert(tf != 0, "Assigned transfer function must not be 0.");
tf->s_Changed.connect(this, &TransferFunctionProperty::onTFChanged);
tf->s_changed.connect(this, &TransferFunctionProperty::onTFChanged);
}
TransferFunctionProperty::~TransferFunctionProperty() {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment