File: anim_dlg.cpp

package info (click to toggle)
mathgl 8.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 248,044 kB
  • sloc: cpp: 87,365; ansic: 3,299; javascript: 3,284; pascal: 1,562; python: 52; sh: 51; makefile: 47; f90: 22
file content (141 lines) | stat: -rw-r--r-- 6,303 bytes parent folder | download
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/***************************************************************************
 *   Copyright (C) 2008 by Alexey Balakin                                  *
 *   mathgl.abalakin@gmail.com                                             *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/
#include <QLabel>
#include <QLayout>
#include <QLineEdit>
#include <QTextEdit>
#include <QPushButton>
#include <QRadioButton>
#include <QMessageBox>
#include <QCheckBox>
//-----------------------------------------------------------------------------
#include "anim_dlg.h"
#undef sprintf	// fix libintl bug of defining sprintf
extern int animDelay;
//-----------------------------------------------------------------------------
AnimParam::AnimParam(QWidget *parent) : QDialog(parent)
{
	setWindowTitle(_("UDAV - Animation setup"));
	QHBoxLayout *a;
	QVBoxLayout *o, *g;
	QLabel *lbl;
	QPushButton *b;
	o = new QVBoxLayout(this);
	lbl = new QLabel(_("Redraw picture for $0 equal to"),this);
	o->addWidget(lbl);
	a = new QHBoxLayout();		o->addLayout(a);
	g = new QVBoxLayout();		a->addLayout(g);
	rbt = new QRadioButton(_("strings"),this);
	connect(rbt, SIGNAL(clicked()),this, SLOT(setRBT()));
	g->addWidget(rbt);
	text = new QTextEdit(this);	g->addWidget(text);
	connect(text,SIGNAL(textChanged()),this,SLOT(setRBT()));

	g = new QVBoxLayout();		a->addLayout(g);
	rbf = new QRadioButton(_("values"),this);
	connect(rbf, SIGNAL(clicked()),this, SLOT(setRBF()));
	g->addWidget(rbf);
	lbl = new QLabel(_("from"),this);
	g->addWidget(lbl, Qt::AlignLeft);
	p1 = new QLineEdit(this);	g->addWidget(p1);
	connect(p1,SIGNAL(textChanged(QString)),this,SLOT(setRBF()));
	lbl = new QLabel(_("to"),this);
	g->addWidget(lbl, Qt::AlignLeft);
	p2 = new QLineEdit(this);	g->addWidget(p2);
	connect(p2,SIGNAL(textChanged(QString)),this,SLOT(setRBF()));
	lbl = new QLabel(_("with step"),this);
	g->addWidget(lbl, Qt::AlignLeft);
	dp = new QLineEdit(this);	g->addWidget(dp);	dp->setText("1");
	connect(dp,SIGNAL(textChanged(QString)),this,SLOT(setRBF()));
	b = new QPushButton(_("Cancel"), this);	g->addWidget(b);
	connect(b, SIGNAL(clicked()),this, SLOT(reject()));
	b = new QPushButton(_("OK"), this);	g->addWidget(b);
	connect(b, SIGNAL(clicked()),this, SLOT(fillRes()));
	b->setDefault(true);
	// general
	a = new QHBoxLayout();		o->addLayout(a);
	b = new QPushButton(_("Put to script"), this);	a->addWidget(b);
	connect(b, SIGNAL(clicked()),this, SLOT(putTxt()));
	lbl = new QLabel(_("Delay (in ms)"),this);	a->addWidget(lbl);
	delay = new QLineEdit(this);	a->addWidget(delay);
	QString s = QString("%1").arg(animDelay);	delay->setText(s);
	// export to gif/jpeg
	a = new QHBoxLayout();		o->addLayout(a);
//	fname = new QLineEdit(this);	a->addWidget(fname);
	gif = new QCheckBox(_("Export to GIF"), this);		a->addWidget(gif);
	jpg = new QCheckBox(_("Save JPEG frames"), this);	a->addWidget(jpg);
	gifOn = jpgOn = false;
}
//-----------------------------------------------------------------------------
AnimParam::~AnimParam()	{}
//-----------------------------------------------------------------------------
void AnimParam::fillRes()
{
//	gifName = fname->text();
	gifOn = gif->isChecked();
	jpgOn = jpg->isChecked();
	animDelay = delay->text().toInt();
	if(rbt->isChecked())	{	res = text->toPlainText();	accept();	}
	else if(rbf->isChecked())
	{
		res = "";
		double x, x2=p2->text().toDouble(), dx=dp->text().toDouble();
		for(x=p1->text().toDouble();x<x2;x+=dx)
			res = res+QString::number(x,'g',4)+"\n";
		accept();
	}
	else	QMessageBox::warning(this,_("UDAV - animation"),
								 _("You should select one of case"));
}
//-----------------------------------------------------------------------------
void AnimParam::putTxt()
{
	QString s, t;
	if(!p1->text().isEmpty() && !p2->text().isEmpty() && !dp->text().isEmpty())
	{
		s = "##c "+p1->text()+" "+p2->text()+" "+dp->text()+"\n";
		emit putText(s);
	}
	if(text->toPlainText().isEmpty())	return;
	int i, n = text->toPlainText().count('\n')+1;
	for(i=0;i<n;i++)
	{
		t = text->toPlainText().section('\n',i,i);
		if(!t.isEmpty())	s = s+"##a "+t+"\n";
	}
	emit putText(s);
}
//-----------------------------------------------------------------------------
void AnimParam::setRBF()	{	rbt->setChecked(false);	rbf->setChecked(true);	}
//-----------------------------------------------------------------------------
void AnimParam::setRBT()	{	rbf->setChecked(false);	rbt->setChecked(true);	}
//-----------------------------------------------------------------------------
void AnimParam::setResult(const QString &s)
{	text->setText(s);	rbf->setChecked(false);	rbt->setChecked(true);	}
//-----------------------------------------------------------------------------
void AnimParam::setResult(double a1, double a2, double da)
{
	p1->setText(QString::number(a1));
	p2->setText(QString::number(a2));
	dp->setText(QString::number(da));
	rbt->setChecked(false);	rbf->setChecked(true);
}
//-----------------------------------------------------------------------------