1 #include "vogleditor_qtrimdialog.h"
2 #include "ui_vogleditor_qtrimdialog.h"
6 vogleditor_QTrimDialog::vogleditor_QTrimDialog(QString parentTraceFile, uint maxFrameIndex, uint maxTrimLength, QWidget *parent) :
8 ui(new Ui::vogleditor_QTrimDialog),
9 m_maxFrameIndex(maxFrameIndex),
10 m_maxTrimLength(maxTrimLength),
15 ui->trimFrameLineEdit->setText(m_trim_frame);
16 ui->trimLenLineEdit->setText(m_trim_len);
18 QString trimFilename = parentTraceFile;
19 trimFilename.insert(trimFilename.lastIndexOf("."), "-trim");
20 ui->trimFileLineEdit->setText(trimFilename);
23 vogleditor_QTrimDialog::~vogleditor_QTrimDialog()
28 void vogleditor_QTrimDialog::on_buttonBox_clicked(QAbstractButton *button)
30 if (button == ui->buttonBox->button(QDialogButtonBox::Ok))
32 // validate the trim start frame
33 bool bValidFrame = false;
34 uint tmpFrame = ui->trimFrameLineEdit->text().toUInt(&bValidFrame);
35 bValidFrame = bValidFrame && (tmpFrame <= m_maxFrameIndex);
39 QMessageBox::warning(this, tr("Invalid Trim Frame"), tr("Please enter a valid frame number at which to start the trim."),
40 QMessageBox::Ok, QMessageBox::Ok);
41 ui->trimFrameLineEdit->setFocus();
45 // validate the trim length
46 bool bValidLen = false;
47 uint tmpLen = ui->trimLenLineEdit->text().toUInt(&bValidLen);
48 bValidLen = bValidLen && (tmpLen > 0 && tmpLen <= m_maxTrimLength);
52 QMessageBox::warning(this, tr("Invalid Trim Count"), tr("Please enter a valid nubmer of frames to trim."),
53 QMessageBox::Ok, QMessageBox::Ok);
54 ui->trimLenLineEdit->setFocus();
58 // validate the filename
59 QFile file(ui->trimFileLineEdit->text());
62 QString message = ui->trimFileLineEdit->text();
63 message += " already exits.\nWould you like to overwrite it?";
64 int ret = QMessageBox::warning(this, tr("File Already Exists"), tr(message.toStdString().c_str()),
65 QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
67 if (ret == QMessageBox::No)
69 // return so that the user can update the path
70 ui->trimFileLineEdit->setFocus();
75 m_trim_frame = ui->trimFrameLineEdit->text();
76 m_trim_len = ui->trimLenLineEdit->text();
77 m_trim_file = ui->trimFileLineEdit->text();
82 void vogleditor_QTrimDialog::on_buttonBox_rejected()
87 void vogleditor_QTrimDialog::on_pickTrimFileButton_pressed()
90 QString suggestedName = ui->trimFileLineEdit->text();
91 QString selectedName = QFileDialog::getSaveFileName(this, tr("Save Trim File"), suggestedName, tr("Trace file (*.bin)"));
93 if (!selectedName.isEmpty())
95 ui->trimFileLineEdit->setText(selectedName);
99 void vogleditor_QTrimDialog::on_trimLenLineEdit_textChanged(const QString &arg1)
101 bool bConverted = false;
102 uint trimLen = arg1.toUInt(&bConverted);
104 // make sure the length could be converted to a UINT, and that it isn't more than the allowed length
105 if (bConverted == false || trimLen > m_maxTrimLength)
107 // turn background red
108 QPalette palette(ui->trimLenLineEdit->palette());
109 palette.setColor(QPalette::Base, Qt::red);
110 ui->trimLenLineEdit->setPalette(palette);
114 // restore background color
115 QPalette palette(ui->trimLenLineEdit->palette());
116 palette.setColor(QPalette::Base, Qt::white);
117 ui->trimLenLineEdit->setPalette(palette);
121 void vogleditor_QTrimDialog::on_trimFrameLineEdit_textChanged(const QString &arg1)
123 bool bConverted = false;
124 uint trimFrame = arg1.toUInt(&bConverted);
126 // make sure frame could be converted to a UINT, and that it isn't greater than the number of frames in the trace
127 if (bConverted == false || trimFrame > m_maxFrameIndex)
129 // turn background red
130 QPalette palette(ui->trimFrameLineEdit->palette());
131 palette.setColor(QPalette::Base, Qt::red);
132 ui->trimFrameLineEdit->setPalette(palette);
136 // restore background color
137 QPalette palette(ui->trimFrameLineEdit->palette());
138 palette.setColor(QPalette::Base, Qt::white);
139 ui->trimFrameLineEdit->setPalette(palette);