Path: blob/devel/ElmerGUI/Application/vtkpost/text.cpp
3203 views
/*****************************************************************************1* *2* Elmer, A Finite Element Software for Multiphysical Problems *3* *4* Copyright 1st April 1995 - , CSC - IT Center for Science Ltd., Finland *5* *6* This program is free software; you can redistribute it and/or *7* modify it under the terms of the GNU General Public License *8* as published by the Free Software Foundation; either version 2 *9* of the License, or (at your option) any later version. *10* *11* This program is distributed in the hope that it will be useful, *12* but WITHOUT ANY WARRANTY; without even the implied warranty of *13* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *14* GNU General Public License for more details. *15* *16* You should have received a copy of the GNU General Public License *17* along with this program (in file fem/GPL-2); if not, write to the *18* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, *19* Boston, MA 02110-1301, USA. *20* *21*****************************************************************************/2223/*****************************************************************************24* *25* ElmerGUI text *26* *27*****************************************************************************28* *29* Authors: Mikko Lyly, Juha Ruokolainen and Peter R�back *30* Email: [email protected] *31* Web: http://www.csc.fi/elmer *32* Address: CSC - IT Center for Science Ltd. *33* Keilaranta 14 *34* 02101 Espoo, Finland *35* *36* Original Date: 15 Mar 2008 *37* *38*****************************************************************************/3940#include <QtGui>41#include <iostream>42#include "vtkpost.h"43#include "text.h"4445#include <vtkTextActor.h>46#include <vtkTextProperty.h>4748using namespace std;4950Text::Text(QWidget *parent)51: QDialog(parent)52{53ui.setupUi(this);54setWindowTitle("Text");55setWindowIcon(QIcon(":/icons/Mesh3D.png"));5657connect(ui.applyButton, SIGNAL(clicked()), this, SLOT(applyButtonClicked()));58connect(ui.cancelButton, SIGNAL(clicked()), this, SLOT(cancelButtonClicked()));59connect(ui.okButton, SIGNAL(clicked()), this, SLOT(okButtonClicked()));6061red = 0.0;62green = 0.0;63blue = 0.0;6465ui.cancelButton->setIcon(QIcon::fromTheme("dialog-error-round"));66ui.applyButton->setIcon(QIcon::fromTheme("view-refresh"));67ui.okButton->setIcon(QIcon::fromTheme("dialog-accept"));68}6970Text::~Text()71{72}7374void Text::applyButtonClicked()75{76emit(drawTextSignal());77}7879void Text::cancelButtonClicked()80{81emit(hideTextSignal());82close();83}8485void Text::okButtonClicked()86{87applyButtonClicked();88close();89}9091void Text::draw(VtkPost* vtkPost)92{93QString message = ui.textEdit->text();94int posX = ui.posxEdit->text().toInt();95int posY = ui.posyEdit->text().toInt();96int size = ui.size->value();97bool left = ui.left->isChecked();98bool centered = ui.centered->isChecked();99bool right = ui.right->isChecked();100bool bold = ui.bold->isChecked();101bool italic = ui.italic->isChecked();102bool shadow = ui.shadow->isChecked();103104vtkTextActor* textActor = vtkPost->GetTextActor();105if(textActor == NULL) return;106107textActor->SetDisplayPosition(posX, posY);108109#if WITH_QT5 || WITH_QT6110textActor->SetInput(message.toLatin1().data());111#else112textActor->SetInput(message.toAscii().data());113#endif114115vtkTextProperty* tprop = textActor->GetTextProperty();116if(tprop == NULL) return;117118tprop->SetFontFamilyToArial();119tprop->SetFontSize(size);120121if(left) tprop->SetJustificationToLeft();122if(centered) tprop->SetJustificationToCentered();123if(right) tprop->SetJustificationToRight();124125if(bold) {126tprop->BoldOn();127} else {128tprop->BoldOff();129}130131if(italic) {132tprop->ItalicOn();133} else {134tprop->ItalicOff();135}136137if(shadow) {138tprop->ShadowOn();139} else {140tprop->ShadowOff();141}142143tprop->SetColor(red, green, blue);144}145146void Text::SetMessage(QString message)147{148ui.textEdit->setText(message);149}150151void Text::SetPosX(int x)152{153ui.posxEdit->setText(QString::number(x));154}155156void Text::SetPosY(int y)157{158ui.posyEdit->setText(QString::number(y));159}160161void Text::SetLeft()162{163ui.left->setChecked(true);164}165166void Text::SetCentered()167{168ui.centered->setChecked(true);169}170171void Text::SetRight()172{173ui.right->setChecked(true);174}175176void Text::SetSize(int n)177{178ui.size->setValue(n);179}180181void Text::SetBold(bool b)182{183ui.bold->setChecked(b);184}185186void Text::SetItalic(bool b)187{188ui.italic->setChecked(b);189}190191void Text::SetShadow(bool b)192{193ui.shadow->setChecked(b);194}195196void Text::SetRed(double d)197{198red = d;199if(red < 0.0) red = 0.0;200if(red > 1.0) red = 1.0;201202}203204void Text::SetGreen(double d)205{206green = d;207if(green < 0.0) green = 0.0;208if(green > 1.0) green = 1.0;209210}211212void Text::SetBlue(double d)213{214blue = d;215if(blue < 0.0) blue = 0.0;216if(blue > 1.0) blue = 1.0;217}218219void Text::SetRGB(double r, double g, double b)220{221this->SetRed(r);222this->SetGreen(g);223this->SetBlue(b);224}225226227