/* -*- 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 #ifdef USE_GUI #include "mainwindow.h" #include #include #include #include #include #include #include #include //#include "mgui_alert.h" //#include "mgui_datasocket.h" #include "miav_config.h" #include //"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*/