Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
ElmerCSC
GitHub Repository: ElmerCSC/elmerfem
Path: blob/devel/ElmerGUI/Application/vtkpost/text.cpp
3203 views
1
/*****************************************************************************
2
* *
3
* Elmer, A Finite Element Software for Multiphysical Problems *
4
* *
5
* Copyright 1st April 1995 - , CSC - IT Center for Science Ltd., Finland *
6
* *
7
* This program is free software; you can redistribute it and/or *
8
* modify it under the terms of the GNU General Public License *
9
* as published by the Free Software Foundation; either version 2 *
10
* of the License, or (at your option) any later version. *
11
* *
12
* This program is distributed in the hope that it will be useful, *
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15
* GNU General Public License for more details. *
16
* *
17
* You should have received a copy of the GNU General Public License *
18
* along with this program (in file fem/GPL-2); if not, write to the *
19
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, *
20
* Boston, MA 02110-1301, USA. *
21
* *
22
*****************************************************************************/
23
24
/*****************************************************************************
25
* *
26
* ElmerGUI text *
27
* *
28
*****************************************************************************
29
* *
30
* Authors: Mikko Lyly, Juha Ruokolainen and Peter R�back *
31
* Email: [email protected] *
32
* Web: http://www.csc.fi/elmer *
33
* Address: CSC - IT Center for Science Ltd. *
34
* Keilaranta 14 *
35
* 02101 Espoo, Finland *
36
* *
37
* Original Date: 15 Mar 2008 *
38
* *
39
*****************************************************************************/
40
41
#include <QtGui>
42
#include <iostream>
43
#include "vtkpost.h"
44
#include "text.h"
45
46
#include <vtkTextActor.h>
47
#include <vtkTextProperty.h>
48
49
using namespace std;
50
51
Text::Text(QWidget *parent)
52
: QDialog(parent)
53
{
54
ui.setupUi(this);
55
setWindowTitle("Text");
56
setWindowIcon(QIcon(":/icons/Mesh3D.png"));
57
58
connect(ui.applyButton, SIGNAL(clicked()), this, SLOT(applyButtonClicked()));
59
connect(ui.cancelButton, SIGNAL(clicked()), this, SLOT(cancelButtonClicked()));
60
connect(ui.okButton, SIGNAL(clicked()), this, SLOT(okButtonClicked()));
61
62
red = 0.0;
63
green = 0.0;
64
blue = 0.0;
65
66
ui.cancelButton->setIcon(QIcon::fromTheme("dialog-error-round"));
67
ui.applyButton->setIcon(QIcon::fromTheme("view-refresh"));
68
ui.okButton->setIcon(QIcon::fromTheme("dialog-accept"));
69
}
70
71
Text::~Text()
72
{
73
}
74
75
void Text::applyButtonClicked()
76
{
77
emit(drawTextSignal());
78
}
79
80
void Text::cancelButtonClicked()
81
{
82
emit(hideTextSignal());
83
close();
84
}
85
86
void Text::okButtonClicked()
87
{
88
applyButtonClicked();
89
close();
90
}
91
92
void Text::draw(VtkPost* vtkPost)
93
{
94
QString message = ui.textEdit->text();
95
int posX = ui.posxEdit->text().toInt();
96
int posY = ui.posyEdit->text().toInt();
97
int size = ui.size->value();
98
bool left = ui.left->isChecked();
99
bool centered = ui.centered->isChecked();
100
bool right = ui.right->isChecked();
101
bool bold = ui.bold->isChecked();
102
bool italic = ui.italic->isChecked();
103
bool shadow = ui.shadow->isChecked();
104
105
vtkTextActor* textActor = vtkPost->GetTextActor();
106
if(textActor == NULL) return;
107
108
textActor->SetDisplayPosition(posX, posY);
109
110
#if WITH_QT5 || WITH_QT6
111
textActor->SetInput(message.toLatin1().data());
112
#else
113
textActor->SetInput(message.toAscii().data());
114
#endif
115
116
vtkTextProperty* tprop = textActor->GetTextProperty();
117
if(tprop == NULL) return;
118
119
tprop->SetFontFamilyToArial();
120
tprop->SetFontSize(size);
121
122
if(left) tprop->SetJustificationToLeft();
123
if(centered) tprop->SetJustificationToCentered();
124
if(right) tprop->SetJustificationToRight();
125
126
if(bold) {
127
tprop->BoldOn();
128
} else {
129
tprop->BoldOff();
130
}
131
132
if(italic) {
133
tprop->ItalicOn();
134
} else {
135
tprop->ItalicOff();
136
}
137
138
if(shadow) {
139
tprop->ShadowOn();
140
} else {
141
tprop->ShadowOff();
142
}
143
144
tprop->SetColor(red, green, blue);
145
}
146
147
void Text::SetMessage(QString message)
148
{
149
ui.textEdit->setText(message);
150
}
151
152
void Text::SetPosX(int x)
153
{
154
ui.posxEdit->setText(QString::number(x));
155
}
156
157
void Text::SetPosY(int y)
158
{
159
ui.posyEdit->setText(QString::number(y));
160
}
161
162
void Text::SetLeft()
163
{
164
ui.left->setChecked(true);
165
}
166
167
void Text::SetCentered()
168
{
169
ui.centered->setChecked(true);
170
}
171
172
void Text::SetRight()
173
{
174
ui.right->setChecked(true);
175
}
176
177
void Text::SetSize(int n)
178
{
179
ui.size->setValue(n);
180
}
181
182
void Text::SetBold(bool b)
183
{
184
ui.bold->setChecked(b);
185
}
186
187
void Text::SetItalic(bool b)
188
{
189
ui.italic->setChecked(b);
190
}
191
192
void Text::SetShadow(bool b)
193
{
194
ui.shadow->setChecked(b);
195
}
196
197
void Text::SetRed(double d)
198
{
199
red = d;
200
if(red < 0.0) red = 0.0;
201
if(red > 1.0) red = 1.0;
202
203
}
204
205
void Text::SetGreen(double d)
206
{
207
green = d;
208
if(green < 0.0) green = 0.0;
209
if(green > 1.0) green = 1.0;
210
211
}
212
213
void Text::SetBlue(double d)
214
{
215
blue = d;
216
if(blue < 0.0) blue = 0.0;
217
if(blue > 1.0) blue = 1.0;
218
}
219
220
void Text::SetRGB(double r, double g, double b)
221
{
222
this->SetRed(r);
223
this->SetGreen(g);
224
this->SetBlue(b);
225
}
226
227