summaryrefslogtreecommitdiff
path: root/src/mainwindow.cc
blob: 77b8d946806b697280c792dbaa5aa34a16203c89 (plain)
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/***************************************************************************
 *            mainwindow.cc
 *
 *  Sat Aug 21 19:49:34 2004
 *  Copyright  2004  deva
 *  deva@aasimon.org
 ****************************************************************************/

/*
 *  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 Library 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 <config.h>
#ifdef USE_GUI

#include "mainwindow.h"

#include <qpainter.h>
#include <qpicture.h>

#include <qpushbutton.h>
#include <qfont.h>
#include <qpixmap.h>
#include <qimage.h>
#include <qlayout.h>
#include <qstatusbar.h>

//#include "mgui_alert.h"
//#include "mgui_datasocket.h"

#include "miav_config.h"

#include <config.h>
//"miav-grab.h"


//#define WITH_DV
MainWindow::MainWindow( QWidget* parent, const char* name )
	: QWidget( parent, name, WStyle_Customize | WStyle_NoBorder )
{
  //  statusBar();
  // statusBar()->message("fisk");
  // statusBar()->setSizeGripEnabled(false);

  MiavConfig cfg("miav.conf");
  /** / 
  int resolution_w = 1280; // TODO: Read actual resolution
  int resolution_h = 1024; // TODO: Read actual resolution
  /**/
  /**/
  int resolution_w = 1024; // TODO: Read actual resolution
  int resolution_h = 768; // TODO: Read actual resolution
  /**/
  unit = ((float)resolution_w / (float)(cfg.readFloat("screensize") * 3.1f));

  move(0,0);
  resize(resolution_w, resolution_h);

  // Load images
  pix_record = new QPixmap();
  pix_record->load( "record.png" );
/*
	QPainter *paint = new QPainter();
	QPicture *pic = new QPicture();
	pic->load(fname, "svg");
	paint->begin(this);
	paint->setWindow(pic->boundingRect());
	paint->drawPicture(0, 0, *pic);
	paint->end();
 */

  pix_stop = new QPixmap();
  pix_stop->load( "stop.png" );

  pix_camera = new QPixmap();
  pix_camera->load( "camera.png" );

  pix_dummy = new QPixmap();
  pix_dummy->load( "dummy.png" );
  
  pix_logo = new QPixmap();
  pix_logo->load( "miav-logo-64x64.png" );

  createGui();
  show();

  //  camera = new Camera("192.168.0.10", 30000);

  recording = false;
  frozen = false;

  aboutwindow = NULL;

  //  CPRQueryDialog dlg(lbl_cpr, lbl_name, this, "CPRQueryDialog");
  //  dlg.exec();
  // Open the CPR Dialog
  cpr_clicked();
}

MainWindow::~MainWindow()
{
  if(camera) delete camera;
  delete btn_cpr;
  if(aboutwindow) delete aboutwindow;
}

void MainWindow::createGui()
{
  // Layout widgets

  /*  _________________________________________________
   *(0) __________________________  |  ______________  |
   * | |        |        |        | | |              | |
   * |(1)       |        |        | |(2)             | |
   * | |        |        |        | | |              | |
   * | |        |        |        | | |              | |
   * | |        |        |        | | |______________| |
   * | |        |        |        | | |              | |
   * | |        |        |        | | |              | |
   * | |        |        |        | | |              | |
   * | |________|________|________| | |              | |
   * | |        |        |        | | |______________| |
   * | |________|________|________| | |              | |
   * | |        |        |        | | |              | |
   * | |________|________|________| | |              | |
   * | |        |        |        | | |              | |
   * | |________|________|________| | |______________| |
   * |______________________________|__________________|
   * |______________________________|__________________|
   */

	QGridLayout *g0 = new QGridLayout(this, 2, 2, 0, -1, "g0");
	QGridLayout *g1 = new QGridLayout(3, 4, -1, "g1");
  g0->addLayout(g1, 0, 0);
	QGridLayout *g2 = new QGridLayout(1, NUM_HISTORY, -1, "g2");
  g0->addLayout(g2, 0, 1);

  img_recedge = new QLabel(this);
  img_recedge->setBackgroundColor(QColor(160,160,160));
  img_recedge->setFixedSize(740,596);
  
  img_live = new VideoWidget(img_recedge);
  //  img_live->setErasePixmap( *pix_dummy );
  img_live->setFixedSize(720,576);
  img_live->move(10,10);
  g1->addMultiCellWidget ( img_recedge, 0, 0, 0, 2, Qt::AlignHCenter);

  // CPR/NAME LABEL + CPR button
  lbl_cpr = createLabel("200379-1613", 18, 3);
  g1->addMultiCellWidget ( lbl_cpr, 1, 1, 0, 1);

  btn_cpr = createButton("NYT CPR", 8, 3);
  btn_cpr->setFocus();
  QObject::connect( btn_cpr, SIGNAL(clicked()), this, SLOT(cpr_clicked()) );
  // Will also be connected in the MGUI code
  g1->addWidget(btn_cpr, 1, 2);

  lbl_name = createLabel("Bent Bisballe Kjær Nyeng Jensen", 18, 2);
  g1->addMultiCellWidget ( lbl_name, 2, 2, 0, 2);

  // Rec + Shot + Freeze buttons
  btn_rec = createButton("", 8, 3);
  btn_rec->setPixmap(*pix_record);
  QObject::connect( btn_rec, SIGNAL(clicked()), this, SLOT(rec_clicked()) );
  g1->addWidget(btn_rec, 3, 0);
  
  btn_shoot = createButton("", 8, 3);
  btn_shoot->setPixmap(*pix_camera);
  QObject::connect( btn_shoot, SIGNAL(clicked()), this, SLOT(shoot_clicked()) );
  g1->addWidget(btn_shoot, 3, 1);
  
  btn_freeze = createButton("FREEZE", 8, 3);
  //  btn_freeze->setPixmap(*pix_logo);
  QObject::connect( btn_freeze, SIGNAL(clicked()), this, SLOT(freeze_clicked()) );
  g1->addWidget(btn_freeze, 3, 2);
  
  // History widgets
  for(int i = 0; i < NUM_HISTORY; i++) {
    img_history[i] = new QLabel(this);
    img_history[i]->setPixmap(*pix_dummy);
    img_history[i]->setFixedSize(240,192);
    g2->addWidget(img_history[i], i, 0, Qt::AlignHCenter);
  }

  // Statusbar
  lbl_status = createLabel("STATUS", 18, 1);
	lbl_status->setFrameStyle(QFrame::TabWidgetPanel | QFrame::Sunken);
	lbl_status->setLineWidth(1);
  g0->addWidget(lbl_status, 4, 0);

  lbl_version = createLabel("MIaV-Grab v" VERSION, 18, 1);
	lbl_version->setFrameStyle(QFrame::TabWidgetPanel | QFrame::Sunken);
	lbl_version->setLineWidth(1);
  lbl_version->setFixedHeight((int)unit);
  g0->addWidget(lbl_version, 4, 1);

  /* // About icon
  btn_logo = new QPushButton("", this);
  btn_logo->setPixmap(*pix_logo);
  btn_logo->setFixedSize(74,74);
  btn_logo->move(940,10);
  btn_logo->setFlat(true);
  QObject::connect( btn_logo, SIGNAL(clicked()), this, SLOT(logo_clicked()) );
  */
  //lbl_version->setFont( QFont( "Arial", 8, QFont::Light ) );
  //lbl_version->setFixedSize(90,10);
  //lbl_version->move(928,81);

}

QPushButton *MainWindow::createButton(char *caption, int width, int height)
{
  QPushButton *btn = new QPushButton(caption, this);
  btn->setFont( QFont( "Arial", (int)(unit * height / 2), QFont::Bold ) );
  btn->setFixedHeight((int)(unit * height));
  return btn;
}

QLabel *MainWindow::createLabel(char *caption, int width, int height)
{
  QLabel *lbl = new QLabel(caption, this);
  lbl->setFont( QFont( "Arial", (int)(unit * height / 2), (height>1)?QFont::Bold:QFont::Normal ) );
  lbl->setFixedHeight((int)(unit * height));
  return lbl;
}

void MainWindow::message(char *msg)
{
  lbl_status->setText(msg);
}

void MainWindow::logo_clicked()
{
  if(aboutwindow)
    delete aboutwindow;
  aboutwindow = new AboutWindow(0, "About MIAV-Grab");
}

void MainWindow::cpr_clicked()
{
  CPRQueryDialog dlg(lbl_cpr, lbl_name, this, "CPRQueryDialog");
  printf("Cpr Dialog returned: %d\n", dlg.exec());
}

void MainWindow::rec_clicked()
{
  recording = 1 - recording;
  if(recording) {
    img_recedge->setBackgroundColor(red);
    btn_rec->setPixmap(*pix_stop);
    camera->stop();
  } else {
    img_recedge->setBackgroundColor(QColor(160,160,160));
    btn_rec->setPixmap(*pix_record);
    camera->start();
  }
}

void MainWindow::shoot_clicked()
{
  QImage image;

  camera->snapshot();

  image = img_live->getScreenshot();
  image = image.smoothScale(img_history[0]->width(), img_history[0]->height());

  QPixmap pixmap;
  for(int cnt = (NUM_HISTORY-1); cnt > 0; cnt--) {
    pixmap = *img_history[cnt-1]->pixmap();
    img_history[cnt]->setPixmap(pixmap);
  }
  img_history[0]->setPixmap(image);

  if(frozen) {
    camera->unfreeze();
    btn_freeze->setOn(false);
    frozen = false;
  }
}

void MainWindow::freeze_clicked()
{
  if(frozen) {
    camera->unfreeze();
    frozen = false;
  } else {
    camera->freeze();
    frozen = true;
  }
}

#endif /*USE_GUI*/