123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267 |
- /*=========================================================================
- Library: CTK
- Copyright (c) Kitware Inc.
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
- http://www.apache.org/licenses/LICENSE-2.0.txt
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
- =========================================================================*/
- // Qt includes
- // CTK includes
- #include "ctkVTKScalarBarWidget.h"
- #include "ui_ctkVTKScalarBarWidget.h"
- // VTK includes
- #include <vtkScalarBarActor.h>
- #include <vtkScalarBarWidget.h>
- //-----------------------------------------------------------------------------
- class ctkVTKScalarBarWidgetPrivate: public Ui_ctkVTKScalarBarWidget
- {
- Q_DECLARE_PUBLIC(ctkVTKScalarBarWidget);
- protected:
- ctkVTKScalarBarWidget* const q_ptr;
- public:
- ctkVTKScalarBarWidgetPrivate(ctkVTKScalarBarWidget& object);
- void init();
- void updateFromScalarBarWidget();
- vtkScalarBarWidget* ScalarBarWidget;
- };
- //-----------------------------------------------------------------------------
- ctkVTKScalarBarWidgetPrivate::ctkVTKScalarBarWidgetPrivate(ctkVTKScalarBarWidget& object)
- :q_ptr(&object)
- {
- this->ScalarBarWidget = 0;
- }
- //-----------------------------------------------------------------------------
- void ctkVTKScalarBarWidgetPrivate::init()
- {
- Q_Q(ctkVTKScalarBarWidget);
- this->setupUi(q);
- q->setEnabled(this->ScalarBarWidget != 0);
- QObject::connect(this->DisplayScalarBarCheckBox, SIGNAL(toggled(bool)),
- q, SLOT(setDisplay(bool)));
- QObject::connect(this->MaxNumberOfColorsSpinBox, SIGNAL(valueChanged(int)),
- q, SLOT(setMaxNumberOfColors(int)));
- QObject::connect(this->NumberOfLabelsSpinBox, SIGNAL(valueChanged(int)),
- q, SLOT(setNumberOfLabels(int)));
- QObject::connect(this->TitleTextPropertyWidget, SIGNAL(textChanged(QString)),
- q, SLOT(setTitle(QString)));
-
- QObject::connect(this->LabelsTextPropertyWidget, SIGNAL(textChanged(QString)),
- q, SLOT(setLabelsFormat(QString)));
- QObject::connect(this->LabelsTextPropertyWidget, SIGNAL(colorChanged(QColor)),
- q, SIGNAL(modified()));
- QObject::connect(this->LabelsTextPropertyWidget, SIGNAL(opacityChanged(double)),
- q, SIGNAL(modified()));
- QObject::connect(this->LabelsTextPropertyWidget, SIGNAL(fontFamilyChanged(QString)),
- q, SIGNAL(modified()));
- QObject::connect(this->LabelsTextPropertyWidget, SIGNAL(boldChanged(bool)),
- q, SIGNAL(modified()));
- QObject::connect(this->LabelsTextPropertyWidget, SIGNAL(italicChanged(bool)),
- q, SIGNAL(modified()));
- QObject::connect(this->LabelsTextPropertyWidget, SIGNAL(shadowChanged(bool)),
- q, SIGNAL(modified()));
- }
- //-----------------------------------------------------------------------------
- void ctkVTKScalarBarWidgetPrivate::updateFromScalarBarWidget()
- {
- Q_Q(ctkVTKScalarBarWidget);
- vtkScalarBarActor* actor =
- this->ScalarBarWidget ? this->ScalarBarWidget->GetScalarBarActor() : 0;
- q->setEnabled(actor != 0);
- if (actor == 0)
- {
- return;
- }
- this->DisplayScalarBarCheckBox->setChecked(this->ScalarBarWidget->GetEnabled() != 0);
- this->MaxNumberOfColorsSpinBox->setValue(actor->GetMaximumNumberOfColors());
- this->NumberOfLabelsSpinBox->setValue(actor->GetNumberOfLabels());
- this->TitleTextPropertyWidget->setTextProperty(
- actor->GetTitleTextProperty());
- this->LabelsTextPropertyWidget->setTextProperty(
- actor->GetLabelTextProperty());
- this->TitleTextPropertyWidget->setText(actor->GetTitle());
- this->LabelsTextPropertyWidget->setText(actor->GetLabelFormat());
- }
- //-----------------------------------------------------------------------------
- ctkVTKScalarBarWidget::ctkVTKScalarBarWidget(QWidget* parentWidget)
- :QWidget(parentWidget)
- , d_ptr(new ctkVTKScalarBarWidgetPrivate(*this))
- {
- Q_D(ctkVTKScalarBarWidget);
- d->init();
- }
- //-----------------------------------------------------------------------------
- ctkVTKScalarBarWidget::ctkVTKScalarBarWidget(vtkScalarBarWidget* scalarBarWidget, QWidget* parentWidget)
- :QWidget(parentWidget)
- , d_ptr(new ctkVTKScalarBarWidgetPrivate(*this))
- {
- Q_D(ctkVTKScalarBarWidget);
- d->init();
- this->setScalarBarWidget(scalarBarWidget);
- }
- //-----------------------------------------------------------------------------
- ctkVTKScalarBarWidget::~ctkVTKScalarBarWidget()
- {
- }
- //-----------------------------------------------------------------------------
- void ctkVTKScalarBarWidget::setScalarBarWidget(vtkScalarBarWidget* scalarBarWidget)
- {
- Q_D(ctkVTKScalarBarWidget);
- if (scalarBarWidget == d->ScalarBarWidget)
- {
- return;
- }
- vtkScalarBarActor* oldActor =
- d->ScalarBarWidget ? d->ScalarBarWidget->GetScalarBarActor() : 0;
- vtkScalarBarActor* newActor =
- scalarBarWidget ? scalarBarWidget->GetScalarBarActor() : 0;
- qvtkReconnect(d->ScalarBarWidget, scalarBarWidget, vtkCommand::EnableEvent,
- this, SLOT(onScalarBarModified()));
- qvtkReconnect(d->ScalarBarWidget, scalarBarWidget, vtkCommand::DisableEvent,
- this, SLOT(onScalarBarModified()));
- qvtkReconnect(oldActor, newActor, vtkCommand::ModifiedEvent,
- this, SLOT(onScalarBarModified()));
- d->ScalarBarWidget = scalarBarWidget;
- this->onScalarBarModified();
- }
- //-----------------------------------------------------------------------------
- vtkScalarBarWidget* ctkVTKScalarBarWidget::scalarBarWidget()const
- {
- Q_D(const ctkVTKScalarBarWidget);
- return d->ScalarBarWidget;
- }
- //-----------------------------------------------------------------------------
- void ctkVTKScalarBarWidget::onScalarBarModified()
- {
- Q_D(ctkVTKScalarBarWidget);
- d->updateFromScalarBarWidget();
- emit modified();
- }
- //-----------------------------------------------------------------------------
- void ctkVTKScalarBarWidget::setDisplay(bool visible)
- {
- Q_D(ctkVTKScalarBarWidget);
- if (d->ScalarBarWidget == 0)
- {
- return;
- }
- d->ScalarBarWidget->SetEnabled(visible);
- // calling SetEnabled might fail, make sure the checkbox is up-to-date
- d->DisplayScalarBarCheckBox->setChecked(d->ScalarBarWidget->GetEnabled());
- }
- //-----------------------------------------------------------------------------
- bool ctkVTKScalarBarWidget::display()const
- {
- Q_D(const ctkVTKScalarBarWidget);
- return d->DisplayScalarBarCheckBox->isChecked();
- }
- //-----------------------------------------------------------------------------
- void ctkVTKScalarBarWidget::setMaxNumberOfColors(int colorCount)
- {
- Q_D(ctkVTKScalarBarWidget);
- vtkScalarBarActor* actor =
- d->ScalarBarWidget ? d->ScalarBarWidget->GetScalarBarActor() : 0;
- if (actor == 0)
- {
- return;
- }
- actor->SetMaximumNumberOfColors(colorCount);
- }
- //-----------------------------------------------------------------------------
- int ctkVTKScalarBarWidget::maxNumberOfColors()const
- {
- Q_D(const ctkVTKScalarBarWidget);
- return d->MaxNumberOfColorsSpinBox->value();
- }
- //-----------------------------------------------------------------------------
- void ctkVTKScalarBarWidget::setNumberOfLabels(int labelCount)
- {
- Q_D(ctkVTKScalarBarWidget);
- vtkScalarBarActor* actor =
- d->ScalarBarWidget ? d->ScalarBarWidget->GetScalarBarActor() : 0;
- if (actor == 0)
- {
- return;
- }
- actor->SetNumberOfLabels(labelCount);
- }
- //-----------------------------------------------------------------------------
- int ctkVTKScalarBarWidget::numberOfLabels()const
- {
- Q_D(const ctkVTKScalarBarWidget);
- return d->NumberOfLabelsSpinBox->value();
- }
- //-----------------------------------------------------------------------------
- void ctkVTKScalarBarWidget::setTitle(const QString& title)
- {
- Q_D(ctkVTKScalarBarWidget);
- vtkScalarBarActor* actor =
- d->ScalarBarWidget ? d->ScalarBarWidget->GetScalarBarActor() : 0;
- if (actor == 0)
- {
- return;
- }
- actor->SetTitle(title.toLatin1());
- }
- //-----------------------------------------------------------------------------
- QString ctkVTKScalarBarWidget::title()const
- {
- Q_D(const ctkVTKScalarBarWidget);
- return d->TitleTextPropertyWidget->text();
- }
- //-----------------------------------------------------------------------------
- void ctkVTKScalarBarWidget::setLabelsFormat(const QString& format)
- {
- Q_D(ctkVTKScalarBarWidget);
- vtkScalarBarActor* actor =
- d->ScalarBarWidget ? d->ScalarBarWidget->GetScalarBarActor() : 0;
- if (actor == 0)
- {
- return;
- }
- actor->SetLabelFormat(format.toLatin1());
- }
- //-----------------------------------------------------------------------------
- QString ctkVTKScalarBarWidget::labelsFormat()const
- {
- Q_D(const ctkVTKScalarBarWidget);
- return d->LabelsTextPropertyWidget->text();
- }
|