summaryrefslogtreecommitdiff
path: root/src/mainwindow.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/mainwindow.cc')
-rw-r--r--src/mainwindow.cc159
1 files changed, 89 insertions, 70 deletions
diff --git a/src/mainwindow.cc b/src/mainwindow.cc
index 5e64a75..c8c427b 100644
--- a/src/mainwindow.cc
+++ b/src/mainwindow.cc
@@ -24,23 +24,20 @@
* along with MIaV; 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 <QPainter>
+#include <QPicture>
-#include <qpushbutton.h>
-#include <qfont.h>
-#include <qpixmap.h>
-#include <qbitmap.h>
-#include <qimage.h>
-#include <qlayout.h>
-#include <qgroupbox.h>
+#include <QPushButton>
+#include <QFont>
+#include <QPixmap>
+#include <QBitmap>
+#include <QImage>
+#include <QLayout>
+#include <QGroupBox>
-#include <qstatusbar.h>
+#include <QStatusBar>
#include <math.h>
@@ -53,10 +50,10 @@
//"miav-grab.h"
//#define WITH_DV
-MainWindow::MainWindow(QApplication *qApp, QWidget* parent, const char* name )
- : QWidget( parent, name, WStyle_Customize | WStyle_NoBorder )
+MainWindow::MainWindow(QApplication *_qApp, QWidget* parent, const char* name )
+ : QWidget( parent, Qt::FramelessWindowHint )
{
- info = new InfoGui(qApp, this, config);
+ info = new InfoGui(_qApp, this, config);
info->log("Starting MIaV v. %s.", VERSION);
@@ -128,7 +125,7 @@ MainWindow::~MainWindow()
info->log("MIaV is shut down.");
}
-QImage *MainWindow::loadButtonIcon( char *name, int height )
+QImage *MainWindow::loadButtonIcon( const char *name, int height )
{
QImage scaled;
@@ -140,14 +137,14 @@ QImage *MainWindow::loadButtonIcon( char *name, int height )
int h = (int)(height * unit);
int w = (int)((float)img->width() / (float)(img->height() / (float)h));
- scaled = img->smoothScale(w, h);
+ scaled = img->scaled(w, h, Qt::KeepAspectRatio, Qt::SmoothTransformation);
delete img;
img = new QImage(scaled);
return img;
}
-QImage *MainWindow::loadImage( char *name )
+QImage *MainWindow::loadImage( const char *name )
{
QImage *img;
@@ -159,6 +156,7 @@ QImage *MainWindow::loadImage( char *name )
void MainWindow::createGui()
{
+ QPixmap p;
// Layout widgets
/* __________________________________________________
@@ -182,20 +180,23 @@ void MainWindow::createGui()
* |_______________________________|__________________|
*/
- QGridLayout *g0 = new QGridLayout(this, 2, 2, 0, -1);
- QGridLayout *g1 = new QGridLayout(4, 4, -1);
+ QGridLayout *g0 = new QGridLayout(this);//, 2, 2, 0, -1);
+ QGridLayout *g1 = new QGridLayout();//4, 4, -1);
g0->addLayout(g1, 0, 0);
QGroupBox *gb = new QGroupBox(this);
+ gb->setLayout(new QVBoxLayout());
+ /* // TODO
// gb->setRows(NUM_HISTORY);
gb->setColumns(1);
// gb->setTitle("fisk");
// QGridLayout *g2 = new QGridLayout(1, NUM_HISTORY, -1);
// QVBoxLayout *g2 = new QVBoxLayout(this);
// g0->addLayout(g2, 0, 1);
-
+
gb->setInsideMargin(HISTORY_LIST_MARGIN);
gb->setInsideSpacing(HISTORY_LIST_SPACING);
+ */
gb->setFlat(true);
g0->addWidget(gb, 0, 1);
@@ -204,7 +205,7 @@ void MainWindow::createGui()
int output_width = resolution_w - // this->width() -
(int)(BUTTON_WIDTH * unit) -
- (gb->insideMargin() * 2) -
+ // (gb->insideMargin() * 2) - // TODO
g1->margin() * 2 -
g0->margin() * 2;
@@ -214,53 +215,56 @@ void MainWindow::createGui()
g0->margin() * 3;
img_recedge = new QLabel(this);
- img_recedge->setBackgroundColor(QColor(160,160,160));
+ //img_recedge->setBackgroundColor(QColor(160,160,160));
img_recedge->setFixedSize(output_width, output_height);
img_live = new VideoWidget(img_recedge, camera);
img_live->setFixedSize(output_width - 20, output_height - 20);
img_live->move(10,10);
- g1->addMultiCellWidget ( img_recedge, 0, 0, 0, 3, Qt::AlignHCenter);
+ //g1->addWidget ( img_recedge, 0, 0, 0, 3, Qt::AlignHCenter);
+ g1->addWidget ( img_recedge, 0, 0, 1, 4, Qt::AlignHCenter);
// QObject::connect( img_live, SIGNAL(clicked()), this, SLOT(live_clicked()) );
// CPR/NAME LABEL + CPR button
lbl_cpr = createLabel("", output_width - (int)(BUTTON_WIDTH * unit), BUTTON_HEIGHT);
- g1->addMultiCellWidget ( lbl_cpr, 1, 1, 0, 2);
+ //g1->addWidget ( lbl_cpr, 1, 1, 0, 2);
+ g1->addWidget ( lbl_cpr, 1, 0, 1, 2);
btn_cpr = createButton("");
btn_cpr->setFocus();
- btn_cpr->setPixmap(*img_cpr);
+ btn_cpr->setIcon(QPixmap(PIXMAP_CPR));
QObject::connect( btn_cpr, SIGNAL(clicked()), this, SLOT(cpr_clicked()) );
// Will also be connected in the MGUI code
g1->addWidget(btn_cpr, 1, 3);
lbl_name = createLabel("", output_width, (int)(BUTTON_HEIGHT * 0.8f));
- g1->addMultiCellWidget ( lbl_name, 2, 2, 0, 3);
+ //g1->addWidget ( lbl_name, 2, 2, 0, 3);
+ g1->addWidget ( lbl_name, 2, 0, 1, 2);
/*
btn_clear = createButton("");
- btn_clear->setPixmap(*img_clear);
+ btn_clear->setIcon(QPixmap(PIXMAP_CLEAR));
QObject::connect( btn_clear, SIGNAL(clicked()), this, SLOT(clear_clicked()) );
// Will also be connected in the MGUI code
g1->addWidget(btn_clear, 1, 2);
*/
// Rec + Shot + Freeze buttons
btn_rec = createButton("");
- btn_rec->setPixmap(*img_record);
+ btn_rec->setIcon(QPixmap(PIXMAP_RECORD));
QObject::connect( btn_rec, SIGNAL(clicked()), this, SLOT(rec_clicked()) );
g1->addWidget(btn_rec, 3, 0);
btn_shoot = createButton("");
- btn_shoot->setPixmap(*img_snapshot);
+ btn_shoot->setIcon(QPixmap(PIXMAP_SNAPSHOT));
QObject::connect( btn_shoot, SIGNAL(clicked()), this, SLOT(shoot_clicked()) );
g1->addWidget(btn_shoot, 3, 1);
btn_freeze = createButton("");
- btn_freeze->setPixmap(*img_freeze);
+ btn_freeze->setIcon(QPixmap(PIXMAP_FREEZE));
QObject::connect( btn_freeze, SIGNAL(clicked()), this, SLOT(freeze_clicked()) );
g1->addWidget(btn_freeze, 3, 2);
btn_mute = createButton("");
- btn_mute->setPixmap(*img_unmute);
+ btn_mute->setIcon(QPixmap(PIXMAP_UNMUTE));
QObject::connect( btn_mute, SIGNAL(clicked()), this, SLOT(mute_clicked()) );
g1->addWidget(btn_mute, 3, 3);
@@ -278,62 +282,70 @@ void MainWindow::createGui()
img_history[i] = new HistoryWidget(gb);
img_history[i]->set_image(img_dummy);
img_history[i]->setFixedSize(w, h);
+ img_history[i]->show();
+ gb->layout()->addWidget(img_history[i]);
}
// Clear button
btn_clear = createButton("", gb);
- btn_clear->setPixmap(*img_clear);
+ btn_clear->setIcon(QPixmap(PIXMAP_CLEAR));
QObject::connect( btn_clear, SIGNAL(clicked()), this, SLOT(clear_clicked()) );
+ gb->layout()->addWidget(btn_clear);
// Statusbar
status = new QStatusBar(this);
status->setSizeGripEnabled(FALSE);
// status->setFont(QFont( "Sans Serif", (int)(unit * height / 3), QFont::Normal ));
- g0->addMultiCellWidget(status, 4, 4, 0, 1);
+ //g0->addWidget(status, 4, 4, 0, 1);
+ g0->addWidget(status, 4, 0, 1, 2);
lbl_recordtime = createLabel("", BUTTON_WIDTH, 1);
+ /*
lbl_recordtime->setFixedWidth((int)(BUTTON_WIDTH * unit) +
- (gb->insideMargin() * 2) +
+ //(gb->insideMargin() * 2) +
g1->margin() * 2 +
g0->margin() * 2);
- status->addWidget(lbl_recordtime, 0, TRUE);
+ */
+ status->addPermanentWidget(lbl_recordtime);//, 0, TRUE);
// About button
btn_about = new QPushButton("", this);
btn_about->setFixedHeight((int)unit);
- btn_about->setPixmap(*img_logo);
+ btn_about->setIcon(QPixmap(PIXMAP_LOGO_SMALL));
QObject::connect( btn_about, SIGNAL(clicked()), this, SLOT(about_clicked()) );
- status->addWidget(btn_about, 0, TRUE);
+ status->addPermanentWidget(btn_about);//, 0, TRUE);
// Version label
lbl_version = createLabel("MIaV-Grab v" VERSION, BUTTON_WIDTH, 1);
lbl_version->setFixedWidth((int)(BUTTON_WIDTH * unit) +
- (gb->insideMargin() * 2) +
+ //(gb->insideMargin() * 2) +
g1->margin() * 2 +
g0->margin() * 2);
- status->addWidget(lbl_version, 0, TRUE);
+ status->addPermanentWidget(lbl_version);//, 0, TRUE);
- status->message( TXT_READY );
+ status->showMessage( TXT_READY );
}
-QPushButton *MainWindow::createButton(char *caption, int width, int height)
+QPushButton *MainWindow::createButton(const char *caption, int width, int height)
{
return createButton(caption, this);//, width, height);
}
-QPushButton *MainWindow::createButton(char *caption, QWidget *parent, int width, int height)
+QPushButton *MainWindow::createButton(const char *caption, QWidget *parent, int width, int height)
{
QPushButton *btn = new QPushButton(caption, parent);
btn->setFont( QFont( "Sans Serif", (int)(unit * height / 2), QFont::Bold ) );
btn->setFixedHeight((int)(unit * height));
// btn->setFixedWidth((int)(unit * width));
+ btn->setIconSize(QSize(2 * unit * height, unit * height));
+ btn->setContentsMargins(0,0,0,0);
return btn;
}
-QLabel *MainWindow::createLabel(char *caption, int width, int height)
+QLabel *MainWindow::createLabel(const char *caption, int width, int height)
{
QLabel *lbl = new QLabel(caption, this);
lbl->setFont( QFont( "Sans Serif",
@@ -385,16 +397,18 @@ void MainWindow::taskbar_update()
#define SPEED 0.07f
void MainWindow::redraw_edge()
{
+ /* // TODO
rec_edge_counter += SPEED;
float val = fabs(sin(rec_edge_counter));
img_recedge->setBackgroundColor(QColor((int) ((255 - GREY) * val + GREY),
(int) (GREY - (GREY * val)),
(int) (GREY - (GREY * val))));
+ */
}
void MainWindow::message(char *msg)
{
- status->message(msg);
+ status->showMessage(msg);
info->log("Message: %s", msg);
}
@@ -447,8 +461,8 @@ void MainWindow::cpr_clicked()
info->log("Activated CPR chooser.");
// Save CPR and name, from the labels.
- strcpy(oldname, lbl_name->text().ascii());
- strcpy(oldcpr, lbl_cpr->text().ascii());
+ strcpy(oldname, lbl_name->text().toStdString().c_str());
+ strcpy(oldcpr, lbl_cpr->text().toStdString().c_str());
clear();
@@ -462,25 +476,26 @@ void MainWindow::cpr_clicked()
info->log("Cancelled CPR chooser.");
} else {
// Change CPR camera.
- info->log("New CPR %s (old %s).", (char*)lbl_cpr->text().ascii(), oldcpr);
- strcpy(oldname, lbl_name->text().ascii());
- strcpy(oldcpr, lbl_cpr->text().ascii());
+ info->log("New CPR %s (old %s).", (char*)lbl_cpr->text().toStdString().c_str(), oldcpr);
+ strcpy(oldname, lbl_name->text().toStdString().c_str());
+ strcpy(oldcpr, lbl_cpr->text().toStdString().c_str());
clear();
lbl_name->setText(oldname);
lbl_cpr->setText(oldcpr);
- camera->setCpr((char*)lbl_cpr->text().ascii(), (char*)lbl_name->text().ascii());
+ camera->setCpr((char*)lbl_cpr->text().toStdString().c_str(), (char*)lbl_name->text().toStdString().c_str());
}
}
void MainWindow::rec_clicked()
{
+ QPixmap p;
if(!recording) {
info->log("Start recording.");
recording = 1;
// Start flashing the edge
rec_edge_counter = 0.0f;
timer->start(100);
- btn_rec->setPixmap(*img_stop);
+ btn_rec->setIcon(QPixmap(PIXMAP_STOP));
camera->start();
} else {
switch(MessageBox(this,
@@ -493,8 +508,8 @@ void MainWindow::rec_clicked()
recording = 0;
camera->stop(SAVE);
timer->stop();
- img_recedge->setBackgroundColor(QColor(160,160,160));
- btn_rec->setPixmap(*img_record);
+ //img_recedge->setBackgroundColor(QColor(160,160,160)); // TODO
+ btn_rec->setIcon(QPixmap(PIXMAP_RECORD));
break;
case MSG_NO:
@@ -502,8 +517,8 @@ void MainWindow::rec_clicked()
recording = 0;
camera->stop(DELETE);
timer->stop();
- img_recedge->setBackgroundColor(QColor(160,160,160));
- btn_rec->setPixmap(*img_record);
+ //img_recedge->setBackgroundColor(QColor(160,160,160));// TODO
+ btn_rec->setIcon(QPixmap(PIXMAP_RECORD));
break;
case MSG_MAYBE:
@@ -511,8 +526,8 @@ void MainWindow::rec_clicked()
recording = 0;
camera->stop(LATER);
timer->stop();
- img_recedge->setBackgroundColor(QColor(160,160,160));
- btn_rec->setPixmap(*img_record);
+ //img_recedge->setBackgroundColor(QColor(160,160,160));// TODO
+ btn_rec->setIcon(QPixmap(PIXMAP_RECORD));
break;
case MSG_CANCEL:
@@ -524,10 +539,11 @@ void MainWindow::rec_clicked()
void MainWindow::shoot_clicked()
{
+ QPixmap p;
// unsigned char pixels[720*576*3];
info->log("Snapshot (%s).", frozen?"frozen":"unfrozen");
- QImage screenshot(720, 576, 32);
+ QImage screenshot(720, 576, QImage::Format_RGB32);
camera->snapshot(screenshot.bits());
@@ -540,36 +556,39 @@ void MainWindow::shoot_clicked()
if(frozen) {
camera->unfreeze();
- btn_freeze->setPixmap(*img_freeze);
- btn_freeze->setOn(false);
+ btn_freeze->setIcon(QPixmap(PIXMAP_FREEZE));
+ btn_freeze->setChecked(false);
frozen = false;
}
}
void MainWindow::freeze_clicked()
{
+ QPixmap p;
if(frozen) {
info->log("Unfreeze.");
camera->unfreeze();
- btn_freeze->setPixmap(*img_freeze);
- btn_freeze->setOn(false);
+ btn_freeze->setIcon(QPixmap(PIXMAP_FREEZE));
+ btn_freeze->setChecked(false);
frozen = false;
} else {
info->log("Freeze.");
camera->freeze();
- btn_freeze->setPixmap(*img_unfreeze);
- btn_freeze->setOn(true);
+ btn_freeze->setIcon(QPixmap(PIXMAP_UNFREEZE));
+ btn_freeze->setChecked(true);
frozen = true;
}
}
void MainWindow::mute_clicked()
{
+ QPixmap p;
muted = !muted;
- if(muted) btn_mute->setPixmap(*img_mute);
- else btn_mute->setPixmap(*img_unmute);
+ if(muted) {
+ btn_mute->setIcon(QPixmap(PIXMAP_MUTE));
+ } else {
+ btn_mute->setIcon(QPixmap(PIXMAP_UNMUTE));
+ }
camera->setMute(muted);
}
-
-#endif /*USE_GUI*/