| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292 | 
							- /*=========================================================================
 
-   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
 
- #include <QDebug>
 
- // CTK includes
 
- #include "ctkVTKTextPropertyWidget.h"
 
- #include "ui_ctkVTKTextPropertyWidget.h"
 
- // VTK includes
 
- #include <vtkSmartPointer.h>
 
- #include <vtkTextProperty.h>
 
- //-----------------------------------------------------------------------------
 
- class ctkVTKTextPropertyWidgetPrivate: public Ui_ctkVTKTextPropertyWidget
 
- {
 
-   Q_DECLARE_PUBLIC(ctkVTKTextPropertyWidget);
 
- protected:
 
-   ctkVTKTextPropertyWidget* const q_ptr;
 
- public:
 
-   void init();
 
-   ctkVTKTextPropertyWidgetPrivate(ctkVTKTextPropertyWidget& object);
 
-   vtkSmartPointer<vtkTextProperty> TextProperty;
 
- };
 
- //-----------------------------------------------------------------------------
 
- ctkVTKTextPropertyWidgetPrivate::ctkVTKTextPropertyWidgetPrivate(ctkVTKTextPropertyWidget& object)
 
-   :q_ptr(&object)
 
- {
 
- }
 
- //-----------------------------------------------------------------------------
 
- ctkVTKTextPropertyWidget::~ctkVTKTextPropertyWidget()
 
- {
 
- }
 
- //-----------------------------------------------------------------------------
 
- void ctkVTKTextPropertyWidgetPrivate::init()
 
- {
 
-   Q_Q(ctkVTKTextPropertyWidget);
 
-   this->setupUi(q);
 
-   q->updateFromTextProperty();
 
-   QObject::connect(this->TextLineEdit, SIGNAL(textChanged(QString)),
 
-                    q, SIGNAL(textChanged(QString)));
 
-   QObject::connect(this->ColorPickerButton, SIGNAL(colorChanged(QColor)),
 
-                    q, SLOT(setColor(QColor)));
 
-   QObject::connect(this->OpacitySlider, SIGNAL(valueChanged(double)),
 
-                    q, SLOT(setOpacity(double)));
 
-   QObject::connect(this->FontComboBox, SIGNAL(currentIndexChanged(QString)),
 
-                    q, SLOT(setFont(QString)));
 
-   QObject::connect(this->BoldCheckBox, SIGNAL(toggled(bool)),
 
-                    q, SLOT(setBold(bool)));
 
-   QObject::connect(this->ItalicCheckBox, SIGNAL(toggled(bool)),
 
-                    q, SLOT(setItalic(bool)));
 
-   QObject::connect(this->ShadowCheckBox, SIGNAL(toggled(bool)),
 
-                    q, SLOT(setShadow(bool)));
 
- }
 
- //-----------------------------------------------------------------------------
 
- ctkVTKTextPropertyWidget::ctkVTKTextPropertyWidget(QWidget* parentWidget)
 
-   :QWidget(parentWidget)
 
-   , d_ptr(new ctkVTKTextPropertyWidgetPrivate(*this))
 
- {
 
-   Q_D(ctkVTKTextPropertyWidget);
 
-   d->init();
 
- }
 
- //-----------------------------------------------------------------------------
 
- ctkVTKTextPropertyWidget::ctkVTKTextPropertyWidget(vtkTextProperty* textProperty, QWidget* parentWidget)
 
-   :QWidget(parentWidget)
 
-   , d_ptr(new ctkVTKTextPropertyWidgetPrivate(*this))
 
- {
 
-   Q_D(ctkVTKTextPropertyWidget);
 
-   d->init();
 
-   this->setTextProperty(textProperty);
 
- }
 
- //-----------------------------------------------------------------------------
 
- void ctkVTKTextPropertyWidget::setTextProperty(vtkTextProperty* textProperty)
 
- {
 
-   Q_D(ctkVTKTextPropertyWidget);
 
-   qvtkReconnect(d->TextProperty, textProperty, vtkCommand::ModifiedEvent,
 
-                 this, SLOT(updateFromTextProperty()));
 
-   d->TextProperty = textProperty;
 
-   this->updateFromTextProperty();
 
- }
 
- //-----------------------------------------------------------------------------
 
- vtkTextProperty* ctkVTKTextPropertyWidget::textProperty()const
 
- {
 
-   Q_D(const ctkVTKTextPropertyWidget);
 
-   return d->TextProperty.GetPointer();
 
- }
 
- //-----------------------------------------------------------------------------
 
- void ctkVTKTextPropertyWidget::updateFromTextProperty()
 
- {
 
-   Q_D(ctkVTKTextPropertyWidget);
 
-   this->setEnabled(d->TextProperty.GetPointer() != 0);
 
-   if (d->TextProperty.GetPointer() == 0)
 
-     {
 
-     d->ColorPickerButton->setColor(QColor());
 
-     d->OpacitySlider->setValue(1.);
 
-     d->FontComboBox->setCurrentIndex(-1);
 
-     d->BoldCheckBox->setChecked(false);
 
-     d->ItalicCheckBox->setChecked(false);
 
-     d->ShadowCheckBox->setChecked(false);
 
-     return;
 
-     }
 
-   double* color = d->TextProperty->GetColor();
 
-   d->ColorPickerButton->setColor(
 
-     QColor::fromRgbF(color[0],color[1],color[2]));
 
-   d->OpacitySlider->setValue(d->TextProperty->GetOpacity());
 
-   d->FontComboBox->setCurrentIndex(
 
-     d->FontComboBox->findText(d->TextProperty->GetFontFamilyAsString()));
 
-   d->BoldCheckBox->setChecked(d->TextProperty->GetBold() != 0);
 
-   d->ItalicCheckBox->setChecked(d->TextProperty->GetItalic() != 0);
 
-   d->ShadowCheckBox->setChecked(d->TextProperty->GetShadow() != 0);
 
- }
 
- //-----------------------------------------------------------------------------
 
- void ctkVTKTextPropertyWidget::setTextVisible(bool visible)
 
- {
 
-   Q_D(ctkVTKTextPropertyWidget);
 
-   d->TextLabel->setVisible(visible);
 
-   d->TextLineEdit->setVisible(visible);
 
- }
 
- //-----------------------------------------------------------------------------
 
- bool ctkVTKTextPropertyWidget::isTextVisible()const
 
- {
 
-   Q_D(const ctkVTKTextPropertyWidget);
 
-   Q_ASSERT(d->TextLabel->isVisibleTo(const_cast<ctkVTKTextPropertyWidget*>(this))
 
-            == d->TextLineEdit->isVisibleTo(const_cast<ctkVTKTextPropertyWidget*>(this)));
 
-   return d->TextLineEdit->isVisibleTo(const_cast<ctkVTKTextPropertyWidget*>(this));
 
- }
 
- //-----------------------------------------------------------------------------
 
- void ctkVTKTextPropertyWidget::setText(const QString& textString)
 
- {
 
-   Q_D(ctkVTKTextPropertyWidget);
 
-   d->TextLineEdit->setText(textString);
 
- }
 
- //-----------------------------------------------------------------------------
 
- QString ctkVTKTextPropertyWidget::text()const
 
- {
 
-   Q_D(const ctkVTKTextPropertyWidget);
 
-   return d->TextLineEdit->text();
 
- }
 
- //-----------------------------------------------------------------------------
 
- void ctkVTKTextPropertyWidget::setTextLabel(const QString& label)
 
- {
 
-   Q_D(ctkVTKTextPropertyWidget);
 
-   d->TextLabel->setText(label);
 
- }
 
- //-----------------------------------------------------------------------------
 
- QString ctkVTKTextPropertyWidget::textLabel()const
 
- {
 
-   Q_D(const ctkVTKTextPropertyWidget);
 
-   return d->TextLabel->text();
 
- }
 
- //-----------------------------------------------------------------------------
 
- QColor ctkVTKTextPropertyWidget::color()const
 
- {
 
-   Q_D(const ctkVTKTextPropertyWidget);
 
-   return d->ColorPickerButton->color();
 
- }
 
- //-----------------------------------------------------------------------------
 
- void ctkVTKTextPropertyWidget::setColor(const QColor& color)
 
- {
 
-   Q_D(const ctkVTKTextPropertyWidget);
 
-   if (d->TextProperty.GetPointer() == 0)
 
-     {
 
-     return;
 
-     }
 
-   d->TextProperty->SetColor(color.redF(), color.greenF(), color.blueF());
 
- }
 
- //-----------------------------------------------------------------------------
 
- double ctkVTKTextPropertyWidget::opacity()const
 
- {
 
-   Q_D(const ctkVTKTextPropertyWidget);
 
-   return d->OpacitySlider->value();
 
- }
 
- //-----------------------------------------------------------------------------
 
- void ctkVTKTextPropertyWidget::setOpacity(double opacity)
 
- {
 
-   Q_D(const ctkVTKTextPropertyWidget);
 
-   if (d->TextProperty.GetPointer() == 0)
 
-     {
 
-     return;
 
-     }
 
-   d->TextProperty->SetOpacity(opacity);
 
- }
 
- //-----------------------------------------------------------------------------
 
- QString ctkVTKTextPropertyWidget::font()const
 
- {
 
-   Q_D(const ctkVTKTextPropertyWidget);
 
-   return d->FontComboBox->currentText();
 
- }
 
- //-----------------------------------------------------------------------------
 
- void ctkVTKTextPropertyWidget::setFont(const QString& font)
 
- {
 
-   Q_D(const ctkVTKTextPropertyWidget);
 
-   if (d->TextProperty.GetPointer() == 0)
 
-     {
 
-     return;
 
-     }
 
-   d->TextProperty->SetFontFamilyAsString(font.toStdString().data());
 
- }
 
- //-----------------------------------------------------------------------------
 
- bool ctkVTKTextPropertyWidget::isBold()const
 
- {
 
-   Q_D(const ctkVTKTextPropertyWidget);
 
-   return d->BoldCheckBox->isChecked();
 
- }
 
- //-----------------------------------------------------------------------------
 
- void ctkVTKTextPropertyWidget::setBold(bool enable)
 
- {
 
-   Q_D(const ctkVTKTextPropertyWidget);
 
-   if (d->TextProperty.GetPointer() == 0)
 
-     {
 
-     return;
 
-     }
 
-   d->TextProperty->SetBold(enable);
 
- }
 
- //-----------------------------------------------------------------------------
 
- bool ctkVTKTextPropertyWidget::isItalic()const
 
- {
 
-   Q_D(const ctkVTKTextPropertyWidget);
 
-   return d->ItalicCheckBox->isChecked();
 
- }
 
- //-----------------------------------------------------------------------------
 
- void ctkVTKTextPropertyWidget::setItalic(bool enable)
 
- {
 
-   Q_D(const ctkVTKTextPropertyWidget);
 
-   if (d->TextProperty.GetPointer() == 0)
 
-     {
 
-     return;
 
-     }
 
-   d->TextProperty->SetItalic(enable);
 
- }
 
- //-----------------------------------------------------------------------------
 
- bool ctkVTKTextPropertyWidget::hasShadow()const
 
- {
 
-   Q_D(const ctkVTKTextPropertyWidget);
 
-   return d->ShadowCheckBox->isChecked();
 
- }
 
- //-----------------------------------------------------------------------------
 
- void ctkVTKTextPropertyWidget::setShadow(bool enable)
 
- {
 
-   Q_D(const ctkVTKTextPropertyWidget);
 
-   if (d->TextProperty.GetPointer() == 0)
 
-     {
 
-     return;
 
-     }
 
-   d->TextProperty->SetShadow(enable);
 
- }
 
 
  |