pqTransferFunctionWidgetPropertyDialog.cxx 4.58 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
/*=========================================================================

   Program: ParaView
   Module: pqTransferFunctionWidgetPropertyWidget.cxx

   Copyright (c) 2005-2012 Kitware Inc.
   All rights reserved.

   ParaView is a free software; you can redistribute it and/or modify it
   under the terms of the ParaView license version 1.2.

   See License_v1.2.txt for the full ParaView license.
   A copy of this license can be obtained by contacting
   Kitware Inc.
   28 Corporate Drive
   Clifton Park, NY 12065
   USA

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

=========================================================================*/
#include "pqTransferFunctionWidgetPropertyDialog.h"
#include "ui_pqTransferFunctionWidgetPropertyDialog.h"

#include "pqTransferFunctionWidgetPropertyWidget.h"
#include "vtkPiecewiseFunction.h"

38
#include <QAction>
39
#include <QDoubleValidator>
40 41
#include <QString>
#include <QStyle>
42

43 44 45 46 47 48 49 50
class pqTransferFunctionWidgetPropertyDialog::pqInternals
{
public:
  Ui::TransferFunctionWidgetPropertyDialog Ui;

  pqInternals(pqTransferFunctionWidgetPropertyDialog* self) { this->Ui.setupUi(self); }
};

51
pqTransferFunctionWidgetPropertyDialog::pqTransferFunctionWidgetPropertyDialog(const QString& label,
52
  vtkPiecewiseFunction* transferFunction, QWidget* propertyWdg, QWidget* parentWdg)
53 54
  : QDialog(parentWdg)
  , TransferFunction(transferFunction)
55
  , PropertyWidget(propertyWdg)
56 57 58 59 60 61 62 63 64 65 66
  , Internals(new pqTransferFunctionWidgetPropertyDialog::pqInternals(this))
{
  this->setWindowTitle(label);
  this->Internals->Ui.Label->setText(this->Internals->Ui.Label->text().arg(label));
  this->Internals->Ui.TransferFunctionEditor->initialize(
    NULL, false, this->TransferFunction.GetPointer(), true);

  // Make sure the line edits only allow number inputs.
  QDoubleValidator* validator = new QDoubleValidator(this);
  this->Internals->Ui.minX->setValidator(validator);
  this->Internals->Ui.maxX->setValidator(validator);
67
  this->updateRange();
68

69 70 71 72
  QObject::connect(
    this->Internals->Ui.minX, SIGNAL(textChangedAndEditingFinished()), this, SLOT(onRangeEdited()));
  QObject::connect(
    this->Internals->Ui.maxX, SIGNAL(textChangedAndEditingFinished()), this, SLOT(onRangeEdited()));
73
  QObject::connect(this->Internals->Ui.TransferFunctionEditor, SIGNAL(controlPointsModified()),
74
    this->PropertyWidget, SLOT(propagateProxyPointsProperty()));
75 76 77 78 79 80 81 82 83 84 85 86 87 88

  QAction* resetActn = new QAction(this->Internals->Ui.resetButton);
  resetActn->setToolTip("Reset using current data values");
  resetActn->setIcon(
    this->Internals->Ui.resetButton->style()->standardIcon(QStyle::SP_BrowserReload));
  this->Internals->Ui.resetButton->addAction(resetActn);
  this->Internals->Ui.resetButton->setDefaultAction(resetActn);
  QObject::connect(this->PropertyWidget, SIGNAL(domainChanged()), this->Internals->Ui.resetButton,
    SLOT(highlight()));
  QObject::connect(this->Internals->Ui.resetButton, SIGNAL(clicked()),
    this->Internals->Ui.resetButton, SLOT(clear()));
  QObject::connect(
    resetActn, SIGNAL(triggered(bool)), this->PropertyWidget, SLOT(resetRangeToDomainDefault()));
  QObject::connect(resetActn, SIGNAL(triggered(bool)), this, SLOT(updateRange()));
89 90 91 92 93 94
}

pqTransferFunctionWidgetPropertyDialog::~pqTransferFunctionWidgetPropertyDialog()
{
}

95
void pqTransferFunctionWidgetPropertyDialog::updateRange()
96
{
97 98
  pqTransferFunctionWidgetPropertyWidget* propertyWdg =
    qobject_cast<pqTransferFunctionWidgetPropertyWidget*>(this->PropertyWidget);
99 100
  double range[2];
  propertyWdg->getRange(range);
101 102 103 104
  this->Internals->Ui.minX->setText(QString::number(range[0]));
  this->Internals->Ui.maxX->setText(QString::number(range[1]));
}

105
void pqTransferFunctionWidgetPropertyDialog::onRangeEdited()
106
{
107 108 109
  pqTransferFunctionWidgetPropertyWidget* propertyWdg =
    qobject_cast<pqTransferFunctionWidgetPropertyWidget*>(this->PropertyWidget);
  propertyWdg->setRange(
110 111
    this->Internals->Ui.minX->text().toDouble(), this->Internals->Ui.maxX->text().toDouble());
}