iCub-main
Loading...
Searching...
No Matches
qavimator.cpp
Go to the documentation of this file.
1/*
2 * qavimator.cpp
3 */
4
5/*
6 * Copyright (C) 2009 RobotCub Consortium
7 * Copyright (c) 2014 iCub Facility - Istituto Italiano di Tecnologia
8 * Authors: Alessandro Scalzo <alessandro.scalzo@iit.it>
9 * Davide Perrone <dperrone@aitek.it>
10 * CopyPolicy: Released under the terms of the GNU GPL v2.0.
11 *
12 * Based on:
13 *
14 * Qavimator
15 * Copyright (C) 2006 by Zi Ree *
16 * Zi Ree @ SecondLife *
17 * Released under the terms of the GNU GPL v2.0.
18 */
19
20#include "qavimator.h"
21#include "ui_qavimator.h"
22
23#include <QEvent>
24#include <QMessageBox>
25#include <QMetaObject>
26#include <QSettings>
27#include <QCloseEvent>
28#include <QLabel>
29#include <QSpinBox>
30#include <QPushButton>
31
32
33#include "animationview.h"
34#include "settings.h"
35#include "settingsdialog.h"
36
37#define ANIM_FILTER "Animation Files (*.avm *.bvh)"
38#define PROP_FILTER "Props (*.prp)"
39#define PRECISION 100
40
41#define SVN_ID "$Id: qavimator.cpp,v 1.1 2014/12/19 10:33:13 dperrone Exp $"
42
43
44qavimator::qavimator(yarp::os::ResourceFinder &config, QWidget *parent) :
45 QMainWindow(parent),
46 ui(new Ui::qavimator)
47{
48 ui->setupUi(this);
50 ui->animationView->init(config);
51 nFPS=10;
52
53 width=850;
54 height=600;
55
56
58 // default size
59
60 if (config.check("name")){
61 GUI_NAME=std::string(config.find("name").asString().c_str());
62 }
63 if (GUI_NAME[0]!='/'){
64 GUI_NAME=std::string("/")+GUI_NAME;
65 }
66 if (config.check("width")){
67 width=config.find("width").asInt32();
68 }
69 if (config.check("height")){
70 height=config.find("height").asInt32();
71 }
72
73 //sanity check
74 if(width<100){
75 width=100;
76 }
77 if(height<100){
78 height=100;
79 }
80
81 this->resize(width, height);
82
83 int xpos=32,ypos=32;
84 if (config.check("xpos")){
85 xpos=config.find("xpos").asInt32();
86 }
87 if (config.check("ypos")){
88 ypos=config.find("ypos").asInt32();
89 }
90 this->move(xpos,ypos);
91
92 setWindowTitle(GUI_NAME.c_str());
93
94 connect(ui->animationView,SIGNAL(backgroundClicked()),this,SLOT(backgroundClicked()));
95 connect(this,SIGNAL(resetCamera()),ui->animationView,SLOT(resetCamera()));
96
97 ui->animationView->startTimer(1000/nFPS);
98
99
100}
101
103{
104 //if (animationView) delete animationView;
105 //animationView=0;
106 fileExit();
107
108 delete ui;
109
110
111}
112
114{
115 QToolBar *toolBar = ui->toolBar;
116 QLabel *label = new QLabel("FPS:",this);
117 QSpinBox *fpsSpin = new QSpinBox(this);
118 fpsSpin->setMaximum(1);
119 fpsSpin->setMaximum(50);
120 fpsSpin->setValue(10);
121 QIcon ico = QIcon(":/icons/resetcamera.png");
122 QPushButton *resetCamera = new QPushButton(ico,"",this);
123 resetCamera->setToolTip("Reset camera view to default position");
124 toolBar->addWidget(label);
125 toolBar->addWidget(fpsSpin);
126 toolBar->addSeparator();
127 toolBar->addWidget(resetCamera);
128 connect(fpsSpin,SIGNAL(valueChanged(int)),this,SLOT(onFpsSpinValueChanged(int)));
129 connect(resetCamera,SIGNAL(clicked()),this,SLOT(onResetCamera()));
130
131
132}
133
135{
136 QSettings settings("iCub","iCubGui");
137 settings.beginGroup("/qavimator");
138
139
140 // OpenGL presets
141 Settings::setFog(true);
143
144 // defaults for ease in/ease out
145 Settings::setEaseIn(false);
147
148 int figureType=0;
149
150 bool settingsFound=settings.value("/settings").toBool();
151 if(settingsFound){
152 width=settings.value("/mainwindow_width").toInt();
153 height=settings.value("/mainwindow_height").toInt();
154
155 // OpenGL settings
156 Settings::setFog(settings.value("/fog").toBool());
157 Settings::setFloorTranslucency(settings.value("/floor_translucency").toInt());
158
159 figureType=settings.value("/figure").toInt();
160
161 settings.endGroup();
162 }
163
164
165}
166
167
168// slot gets called by AnimationView::mouseButtonClicked()
170{
171 emit enableRotation(false);
172}
173
174
175
176
177
178
179// Menu Action: File / Exit
181{
182 QSettings settings("iCub","iCubGui");
183 settings.beginGroup("/qavimator");
184
185 // make sure we know next time, that there actually was a settings file
186 settings.setValue("/settings",true);
187
188 //settings.writeEntry("/figure",figureCombo->currentItem());
189 settings.setValue("/mainwindow_width",size().width());
190 settings.setValue("/mainwindow_height",size().height());
191
192
193 // OpenGL settings
194 settings.setValue("/fog",Settings::fog());
195 settings.setValue("/floor_translucency",Settings::floorTranslucency());
196
197 // settings for ease in/ease outFrame
198 settings.setValue("/ease_in",Settings::easeIn());
199 settings.setValue("/ease_out",Settings::easeOut());
200
201 settings.endGroup();
202
203
204 ui->animationView->stopTimer();
205
206 close();
207
208}
209
210
211// Menu Action: Options / Configure iCubGUI
213{
214 SettingsDialog dialog;
215 connect(&dialog,SIGNAL(configChanged()),this,SLOT(configChanged()));
216
217 dialog.exec();
218}
219
221{
222 ui->animationView->repaint();
223}
224
225// Menu Action: Help / About ...
227{
228 QMessageBox::about(this,QObject::tr("About iCubGui"),QObject::tr("iCubGui - joint gui for iCub<br />%1").arg(SVN_ID));
229}
230
231
232// prevent closing of main window if there are unsaved changes
233void qavimator::closeEvent(QCloseEvent* event)
234{
235 ui->animationView->stopTimer();
236 //animationView=0;
237 event->accept();
238}
239
241{
242 //qDebug("qavimator::fileExit() not implemented");
243 fileExit();
244}
245
250
255
256
258{
259 emit resetCamera();
260}
261
262
263
265{
266 setFPS(newValue);
267}
268void qavimator::setFPS(int fps)
269{
270 qDebug("qavimator::setFPS(%d)",fps);
271 if (fps<1) fps=1; else if (fps>50) fps=50;
272 nFPS=fps;
273
274 ui->animationView->stopTimer();
275 ui->animationView->startTimer(1000/nFPS);
276}
std::string GUI_NAME
static void setEaseIn(bool on)
Definition settings.cpp:58
static bool easeOut()
Definition settings.cpp:73
static void setFog(bool on)
Definition settings.cpp:38
static bool easeIn()
Definition settings.cpp:63
static void setEaseOut(bool on)
Definition settings.cpp:68
static void setFloorTranslucency(int value)
Definition settings.cpp:48
static bool fog()
Definition settings.cpp:43
static int floorTranslucency()
Definition settings.cpp:53
void enableRotation(bool)
void onFpsSpinValueChanged(int num)
void on_optionsConfigureiCubGUIAction_triggered()
void on_helpAboutAction_triggered()
void backgroundClicked()
void resetCamera()
void onResetCamera()
virtual void closeEvent(QCloseEvent *event)
void helpAbout()
void configChanged()
void readSettings()
qavimator(yarp::os::ResourceFinder &config, QWidget *parent=0)
Definition qavimator.cpp:44
void setFPS(int fps)
void configure()
void fileExit()
void on_fileExitAction_triggered()
void setupToolBar()
#define SVN_ID
Definition qavimator.cpp:41