/* flip - pageflipper for TIFF animations * Copyright (C) 1999 Mark B. Allan (mba@reptilelabour.com) * * "flip" is free software; you can redistribute it and/or use * it and/or modify it under the terms of the "Artistic License" */ #include "FlipPreferences.h" #include #include #include "define.h" #include "Config.h" #include "MainWindow.h" //==================================================================== FlipPreferences::FlipPreferences(QWidget *parent, const char* name) : QDialog(parent, name, true) { int i; QString caption = APP_NAME; caption += " Preferences"; setCaption(caption); topLayout = new QVBoxLayout(this, 5, 5); butLayout = new QHBoxLayout(5); gridLayout = new QGridLayout(NumFields, 3, 3); for(i = 0; i < (int)NumFields; i++) { QLabel *tmpLabel = newLabel((Field)i); gridLayout->addWidget(tmpLabel, i, 0); } mpegExecEdit = new QLineEdit(this); mpegExecBut = new QToolButton(this); mpegExecBut->setText("..."); loadFramesSpin = new QSpinBox(1, 10000, 10, this); fileHistSpin = new QSpinBox(1, 16, 1, this); fpsCombo = new QComboBox(this); fpsCombo->setFixedHeight(mpegExecEdit->sizeHint().height()); for(i = 0; i < (int)MainWindow::NumFPS; i++) { char buff[32]; snprintf(buff, 32, " %g ", MainWindow::fpsVal[i]); fpsCombo->insertItem(buff); } okBut = new QPushButton("&ok", this); okBut->setDefault(true); cancelBut = new QPushButton("&cancel", this); //-- Connect ------------- QObject::connect(okBut, SIGNAL(clicked()), this, SLOT(okPressed()) ); QObject::connect(cancelBut, SIGNAL(clicked()), this, SLOT(cancelPressed()) ); QObject::connect(mpegExecBut, SIGNAL(clicked()), this, SLOT(browseForMpeg()) ); //-- Layout -------------- topLayout->addLayout(gridLayout, 0); gridLayout->addWidget(mpegExecEdit, (int)MpegExec, 1); gridLayout->addWidget(mpegExecBut, (int)MpegExec, 2); gridLayout->addWidget(loadFramesSpin, (int)LoadFrames, 1); gridLayout->addWidget(fileHistSpin, (int)FileHist, 1); gridLayout->addWidget(fpsCombo, (int)FramesPerSec, 1); topLayout->addStretch(1); topLayout->addLayout(butLayout, 0); butLayout->addWidget(okBut, 0); butLayout->addStretch(1); butLayout->addWidget(cancelBut, 0); setCurrent(); resize(350, 150); } FlipPreferences::~FlipPreferences() { } //---------------------------------------------------------- QLabel *FlipPreferences::newLabel(Field field) { QLabel *tmpLabel; QString text; switch(field) { case MpegExec: text = "mpeg_encode executable : "; break; case LoadFrames: text = "default # frames to load : "; break; case FileHist: text = "# recent dirs : "; break; case FramesPerSec: text = "default fps : "; break; default: text = "ERROR"; break; } tmpLabel = new QLabel(this); tmpLabel->setAlignment(AlignVCenter | AlignRight); tmpLabel->setText(text); tmpLabel->setMinimumHeight(25); tmpLabel->setMinimumWidth(100); return tmpLabel; } //---------------------------------------------------------- void FlipPreferences::show() { setCurrent(); QDialog::show(); } //---------------------------------------------------------- void FlipPreferences::exec() { setCurrent(); QDialog::exec(); } //---------------------------------------------------------- void FlipPreferences::setCurrent() { Config *cfg = Config::getInstance(); mpegExecEdit->setText(cfg->mpegExec); loadFramesSpin->setValue(cfg->loadFrames); fileHistSpin->setValue(cfg->fileHist); fpsCombo->setCurrentItem((int)cfg->flipFPS); } //---------------------------------------------------------- void FlipPreferences::okPressed() { Config *cfg = Config::getInstance(); cfg->mpegExec = mpegExecEdit->text(); if(!Config::hasMpeg()) { char buffer[512]; snprintf(buffer, 512, "WARNING:\n\"%s\"\nis not a valid executable.", (const char*)cfg->mpegExec); QMessageBox::warning(this, APP_NAME, buffer); } cfg->loadFrames = loadFramesSpin->value(); cfg->fileHist = fileHistSpin->value(); cfg->flipFPS = (MainWindow::FPS)fpsCombo->currentItem(); Config::commit(); accept(); } //---------------------------------------------------------- void FlipPreferences::cancelPressed() { reject(); } //---------------------------------------------------------- void FlipPreferences::browseForMpeg() { QString fileName; fileName = QFileDialog::getSaveFileName(mpegExecEdit->text(), "mpeg_encode", this); if(!fileName.isEmpty()) mpegExecEdit->setText(fileName); }