#include "rm_test_dialog.h" #if (RM_TESTING) #include #include #include #include #include #include #include #include #include #include "../rm_app.h" #include "../rm_settings.h" RMDialogTest::RMDialogTest(QWidget *parent) : QDialog(parent) { QString version; version.sprintf("model:%s %d.%d.%d.%d",WINDOW_TITLE,RM_MODEL_VERSION_0,RM_MODEL_VERSION_1,RM_MODEL_VERSION_1,RM_MODEL_SVN_VERSION); this->setWindowModality(Qt::NonModal); this->setWindowTitle("DVR TESTER (" + version + ")"); this->setWindowFlags(Qt::Window | Qt::Tool | Qt::CustomizeWindowHint | Qt::WindowTitleHint); this->setWindowModality(Qt::NonModal); setMinimumSize(300,500); _layout = new QVBoxLayout(this); _layout->setAlignment(Qt::AlignTop | Qt::AlignLeft); _layout->setMargin(0); _layout->setSpacing(0); createToolbar(); createInfoPanel(); createLogConsole(); createFilterEditor(); _process = NULL; } void RMDialogTest::createToolbar() { _toolbar = new QWidget(this); _toolbar->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Fixed); _toolbar->setFixedHeight(36); _layout->addWidget(_toolbar); _toolbar->setStyleSheet("background-color: #818181;"); //_toolbar->setObjectName("test_widget"); QHBoxLayout* toolLayout = new QHBoxLayout(_toolbar); toolLayout->setAlignment(Qt::AlignLeft | Qt::AlignVCenter); toolLayout->setSpacing(6); toolLayout->setMargin(2); QPushButton* btn; _runButton = button(_toolbar,toolLayout,"RUN"); _runButton->setEnabled(false); _openButton = button(_toolbar,toolLayout,"OPEN"); _reloadButton = button(_toolbar,toolLayout,"RELOAD"); _stopButton = button(_toolbar,toolLayout,"STOP"); _stopButton->setEnabled(false); btn = button(_toolbar,toolLayout,"CLEAR"); btn = button(_toolbar,toolLayout,"DIR"); } void RMDialogTest::createInfoPanel() { QWidget* info = new QWidget(this); info->setStyleSheet("background-color: #616161;"); //info->setObjectName("test_widget"); info->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Preferred); //info->setFixedHeight(48); _layout->addWidget(info); QVBoxLayout* infoLayout = new QVBoxLayout(info); infoLayout->setAlignment(Qt::AlignLeft | Qt::AlignTop); infoLayout->setSpacing(2); infoLayout->setMargin(2); _scriptLabel = label(info,infoLayout,"Script:","NONE"); _statusLabel = label(info,infoLayout,"Status:","----"); _timerLabel = label(info,infoLayout,"Timer:","00:00:00"); _loopLabel = label(info,infoLayout,"Loop:","000"); } void RMDialogTest::createFilterEditor() { QWidget* filter = new QWidget(this); filter->setStyleSheet("background-color: #818181;"); _layout->addWidget(filter); QHBoxLayout* filterLayout = new QHBoxLayout(filter); filterLayout->setMargin(0); filterLayout->setSpacing(0); _filterEdit = new QLineEdit(filter); _filterEdit->setStyleSheet("font-family: Fixedsys;color : #6666FF;background-color: #111111;border:1px;border-style:solid;border-color:#313131;"); _filterEdit->setText("format=pix_fmts=rgb24,lenscorrection=cx=0.5:cy=0.5:k1=-.8:k2=-.0"); filterLayout->addWidget(_filterEdit); button(filter,filterLayout,"FA"); button(filter,filterLayout,"FC"); } void RMDialogTest::createLogConsole() { _logTextEdit = new QPlainTextEdit(this); _logTextEdit->setReadOnly(true); _logTextEdit->setStyleSheet("font-family: Fixedsys;color : #00FF00;background-color: #111111;border:1px;border-style:solid;border-color:#313131;"); _logTextEdit->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding); _layout->addWidget(_logTextEdit); QString scrollStyle = "QScrollBar:vertical\ {\ border-width: 0px;\ border-style: solid;\ background: #3B3B3B;\ width: 10px;\ margin: 21px 0 21px 0;\ }\ QScrollBar::handle:vertical:disabled{background: #3B3B3B;}\ QScrollBar::handle:vertical\ {\ border-width: 0px;\ background: #6A74FF;\ min-height: 25px;\ }\ QScrollBar::add-line:vertical\ {\ border: none;\ background: none;\ height: 20px;\ width: 15px;\ subcontrol-position: bottom;\ subcontrol-origin: margin;\ }\ QScrollBar::sub-line:vertical\ {\ border: none;\ background: none;\ height: 20px;\ width: 15px;\ subcontrol-position: top;\ subcontrol-origin: margin;\ }\ QScrollBar::add-page:vertical, QScrollBar::sub-page:vertical\ {\ background: none;\ }\ QScrollBar::up-arrow:vertical\ {\ border: none;\ background: #5A5A5A;\ }\ QScrollBar::down-arrow:vertical\ {\ border: none;\ background: #5A5A5A;\ }"; _logTextEdit->verticalScrollBar()->setStyleSheet(scrollStyle); } QLabel* RMDialogTest::label(QWidget* parent,QLayout* layout,QString title,QString text) { QWidget* row = new QWidget(parent); layout->addWidget(row); QHBoxLayout* hLayout = new QHBoxLayout(row); hLayout->setMargin(0); hLayout->setSpacing(0); hLayout->setAlignment(Qt::AlignLeft | Qt::AlignVCenter); QLabel* label = new QLabel(row); label->setText(title); label->setStyleSheet("font-family: Fixedsys;color : #F0F0F0;"); hLayout->addWidget(label); label->setFixedWidth(72); QLabel* textLabel = new QLabel(row); textLabel->setText(text); textLabel->setStyleSheet("font-family: Fixedsys;color : white;"); hLayout->addWidget(textLabel); return textLabel; } QPushButton* RMDialogTest::button(QWidget* parent,QLayout* layout,QString title) { QPushButton* btn = new QPushButton(parent); btn->setText(title); //btn->setStyleSheet("font-family: Arial;font-size: 9px;"); btn->setStyleSheet("QPushButton{font-family: Fixedsys;color : white;}" "QPushButton[enabled=\"false\"]{color : #AAAAAA;}"); btn->setFixedWidth(title.length() * 10); layout->addWidget(btn); connect(btn,SIGNAL(clicked()),SLOT(onButton())); return btn; } void RMDialogTest::onButton() { QPushButton* btn = qobject_cast(sender()); QString cmd = btn->text().toUpper(); if(cmd == "DIR") { QDesktopServices::openUrl(QUrl::fromLocalFile(RMApp::instance()->appPath(RMApp::SCRIPT))); } else if(cmd == "OPEN") { QString fileName = QFileDialog::getOpenFileName( this, "OPEN", RMApp::instance()->appPath(RMApp::SCRIPT), "SCRIPT (*.txt)"); if(fileName.length() > 0) { openScript(fileName); } } else if(cmd == "RELOAD" && _process != NULL) { openScript(_process->filePath); } else if(cmd == "CLEAR") { _logTextEdit->clear(); } else if (cmd == "FA") { RMPlayer::instance()->applyTestFilter(_filterEdit->text()); } else if (cmd == "FC") { RMPlayer::instance()->applyTestFilter(""); } } void RMDialogTest::onStatusMessage(QString message) { _statusLabel->setText(message); } void RMDialogTest::clearProcess() { if (_process != NULL) { disconnect(_runButton,SIGNAL(clicked()),this,SLOT(onRunProcess())); disconnect(_stopButton,SIGNAL(clicked()),this,SLOT(onStopProcess())); disconnect(_process,SIGNAL(statusChange(QString)),this,SLOT(onStatusMessage(QString))); disconnect(_process,SIGNAL(log(QString)),this,SLOT(onLog(QString))); disconnect(_process,SIGNAL(error(QString)),this,SLOT(onError(QString))); delete _process; _process = NULL; } } void RMDialogTest::openScript(QString path) { clearProcess(); _process = new RMTestProcess(this,path); connect(_runButton,SIGNAL(clicked()),SLOT(onRunProcess())); connect(_stopButton,SIGNAL(clicked()),SLOT(onStopProcess())); connect(_process,SIGNAL(statusChange(QString)),this,SLOT(onStatusMessage(QString))); connect(_process,SIGNAL(log(QString)),this,SLOT(onLog(QString))); connect(_process,SIGNAL(error(QString)),this,SLOT(onError(QString))); refreshRunStopButton(); QFileInfo fi(path); _scriptLabel->setText(fi.baseName() + "(" + QString::number(_process->count()) + ")"); RMSettings::instance()->setLastScript(path); } void RMDialogTest::refreshRunStopButton() { _runButton->setEnabled((_process != NULL && _process->isRunning() == false)); _runButton->style()->unpolish(_runButton); _runButton->style()->polish(_runButton); _openButton->setEnabled((_process == NULL || _process->isRunning() == false)); _openButton->style()->unpolish(_openButton); _openButton->style()->polish(_openButton); _reloadButton->setEnabled((_process != NULL && _process->isRunning() == false)); _reloadButton->style()->unpolish(_reloadButton); _reloadButton->style()->polish(_reloadButton); _stopButton->setEnabled((_process != NULL && _process->isRunning() == true)); _stopButton->style()->unpolish(_stopButton); _stopButton->style()->polish(_stopButton); _statusLabel->setText((_process != NULL && _process->isRunning()) ? "running" : "stopped"); } void RMDialogTest::onRunProcess() { if(_process == NULL || _process->isRunning()) { return; } connect(_process,SIGNAL(timer(qint64)),SLOT(onTimer(qint64))); connect(_process,SIGNAL(loopChange(int)),SLOT(onLoopChange(int))); _process->onRun(); refreshRunStopButton(); } void RMDialogTest::onStopProcess() { if(_process == NULL || _process->isRunning() == false) { return; } disconnect(_process,SIGNAL(timer(qint64)),this,SLOT(onTimer(qint64))); disconnect(_process,SIGNAL(loopChange(int)),this,SLOT(onLoopChange(int))); _process->onStop(); refreshRunStopButton(); } void RMDialogTest::onTimer(qint64 msec) { int sec = msec; int h = 0; int m = 0; int s = 0; if(sec > 3600000) { h = sec / 3600000; sec = sec - (h * 3600000); } if(sec > 60) { m = sec / 60000; sec = sec - (m * 60000); } s = sec; QString timeString; timeString.sprintf("%02d:%02d:%04.1f",h,m,(double)s/1000.0); _timerLabel->setText(timeString); } void RMDialogTest::onLoopChange(int loop) { QString str; str.sprintf("%03d",loop); _loopLabel->setText(str); } void RMDialogTest::onLog(QString log) { _logTextEdit->appendPlainText(log); } void RMDialogTest::onError(QString message) { // 일단 정지 // if(RMPlayer::instance()->playerF()->isPaused() == false) // { // RMPlayer::instance()->onPlayOrPause(); // } ::Beep(500,1000); onStopProcess(); clearProcess(); refreshRunStopButton(); QMessageBox::warning(this,"ERROR",message,QMessageBox::Ok,QMessageBox::NoButton); } RMDialogTest* RMDialogTest::instance(QWidget* parent) { static RMDialogTest * _instance = NULL; if ( _instance == NULL ) { _instance = new RMDialogTest(parent); } return _instance; } void RMDialogTest::showEvent(QShowEvent * event) { Q_UNUSED(event) QRect r = RMApp::instance()->pMainWindow->geometry(); r.moveLeft(460); r.moveTop(190); setGeometry(r.right(),r.top(),300,500); QString script = RMSettings::instance()->lastScript(); if(script.length() > 0 && QFile::exists(script)) { openScript(script); } } #endif // #if (RM_TESTING)