nicer font sizes, message box for error messaging!
This commit is contained in:
parent
a6b6d0e889
commit
4011a17f13
@ -25,6 +25,7 @@
|
||||
# include <QtPrintSupport/qtprintsupportglobal.h>
|
||||
|
||||
# if QT_CONFIG(printdialog)
|
||||
#include <QDateTime>
|
||||
# include <QPrintDialog>
|
||||
# endif
|
||||
#endif
|
||||
@ -60,34 +61,51 @@ PylonRecorder::PylonRecorder(QWidget *parent)
|
||||
preassureBar = new QProgressBar(this);
|
||||
preassureBar->setRange(0, 100);
|
||||
preassureBar->setTextVisible(true);
|
||||
preassureBar->setFixedSize(200, 25);
|
||||
QColor color = progressColor(0);
|
||||
QPalette progressPalette = preassureBar->palette();
|
||||
progressPalette.setBrush(QPalette::Highlight, QBrush(color));
|
||||
preassureBar->setPalette(progressPalette);
|
||||
QLabel *preassureLabel = new QLabel("Buffer preassure:", this);
|
||||
|
||||
preassureLabel->setStyleSheet("QLabel{font-size: 11px;font-family: Arial;font-weight: Bold}");
|
||||
loadBar = new QProgressBar(this);
|
||||
loadBar->setRange(0, 1000);
|
||||
loadBar->setRange(0, defaultBufferSize);
|
||||
loadBar->setFixedSize(200, 25);
|
||||
QLabel *loadLabel = new QLabel("Load:", this);
|
||||
loadLabel->setStyleSheet("QLabel{font-size: 11px;font-family: Arial;font-weight: Bold}");
|
||||
|
||||
writingLabel = new QLabel("writing");
|
||||
writingLabel->setEnabled(false);
|
||||
writingLabel->setStyleSheet("QLabel{font-size: 11px;font-family: Arial;}");
|
||||
grabbingLabel = new QLabel("grabbing");
|
||||
//grabbingLabel->setStyleSheet("QLabel { color : gray; }");
|
||||
grabbingLabel->setEnabled(false);
|
||||
grabbingLabel->setStyleSheet("QLabel{font-size: 11px;font-family: Arial;}");
|
||||
labelSwitch = false;
|
||||
cameraConnectedLabel = new QLabel("not connected");
|
||||
cameraConnectedLabel->setStyleSheet("QLabel { color : red; }");
|
||||
cameraConnectedLabel->setStyleSheet("QLabel{font-size: 11px;font-family: Arial;}");
|
||||
|
||||
fileLabel = new QLabel();
|
||||
fileLabel->setStyleSheet("QLabel{font-size: 11px;font-family: Arial;}");
|
||||
|
||||
QLabel *camHeader = new QLabel("Camera:");
|
||||
camHeader->setStyleSheet("QLabel{font-size: 11px;font-family: Arial; font-weight: Bold}");
|
||||
QLabel *statusHeader = new QLabel("Status:");
|
||||
statusHeader->setStyleSheet("QLabel{font-size: 11px;font-family: Arial; font-weight: Bold}");
|
||||
QLabel *fileHeader = new QLabel("Output file:");
|
||||
fileHeader->setStyleSheet("QLabel{font-size: 11px;font-family: Arial; font-weight: Bold}");
|
||||
|
||||
statusBar()->addWidget(new QLabel("Camera:"));
|
||||
statusBar()->addWidget(camHeader);
|
||||
statusBar()->addWidget(cameraConnectedLabel);
|
||||
statusBar()->addWidget(preassureLabel);
|
||||
statusBar()->addWidget(preassureBar);
|
||||
statusBar()->addWidget(loadLabel);
|
||||
statusBar()->addWidget(loadBar);
|
||||
statusBar()->addWidget(statusHeader);
|
||||
statusBar()->addWidget(grabbingLabel);
|
||||
statusBar()->addWidget(writingLabel);
|
||||
|
||||
statusBar()->addWidget(fileHeader);
|
||||
statusBar()->addWidget(fileLabel);
|
||||
resize(QGuiApplication::primaryScreen()->availableSize() * 3 / 5);
|
||||
}
|
||||
|
||||
@ -269,19 +287,14 @@ void PylonRecorder::fitToWindow() {
|
||||
}
|
||||
|
||||
void PylonRecorder::about() {
|
||||
QMessageBox::about(this, tr("About Image Viewer"),
|
||||
tr("<p>The <b>Image Viewer</b> example shows how to combine QLabel "
|
||||
"and QScrollArea to display an image. QLabel is typically used "
|
||||
"for displaying a text, but it can also display an image. "
|
||||
"QScrollArea provides a scrolling view around another widget. "
|
||||
"If the child widget exceeds the size of the frame, QScrollArea "
|
||||
"automatically provides scroll bars. </p><p>The example "
|
||||
"demonstrates how QLabel's ability to scale its contents "
|
||||
"(QLabel::scaledContents), and QScrollArea's ability to "
|
||||
"automatically resize its contents "
|
||||
"(QScrollArea::widgetResizable), can be used to implement "
|
||||
"zooming and scaling features. </p><p>In addition the example "
|
||||
"shows how to use QPainter to print an image.</p>"));
|
||||
QMessageBox::about(this, tr("About Pylon Recorder"),
|
||||
tr("<p><b>Pylon Recorder</b><br> Simple recorder for video grabbing from pylon USB3 monochrome camera."
|
||||
"Usage: In order to grab image, a camera device needs to be opened, press the connect button to do so. Push the reord button to record conituously.</p>"
|
||||
"<p> videos are stored in the same folder as the tool is. Videos are compressed to mp4."
|
||||
" As the buffer preassure reaches 100% frames will be lost! You may want to increase the buffer size"
|
||||
" or reduce the framerate.</p><p>In order to run you need to install the pylon libraries"
|
||||
" and the mp4 video codec avalable for download at <a href='https://www.baslerweb.com/de/'>Basler website</a></p>"
|
||||
"<p>by Jan Grewe, <a href='http://www.neuroetho.uni-tuebingen.de'>Neuroethology Lab</a>, University of Tuebingen.</p>"));
|
||||
}
|
||||
|
||||
void PylonRecorder::createActions() {
|
||||
@ -351,17 +364,16 @@ void PylonRecorder::createActions() {
|
||||
grab_continuous_action = camera_menu->addAction(grab_icon, tr("&grab continuous"), this, &PylonRecorder::startRecording);
|
||||
grab_continuous_action->setShortcut(tr("Ctrl+Enter"));
|
||||
grab_stop_action = camera_menu->addAction(stop_icon, tr("&stop grabbing"), this, &PylonRecorder::stopRecording);
|
||||
grab_stop_action->setShortcut(tr("Ctrl+Shift+Enter"));
|
||||
|
||||
QMenu *helpMenu = menuBar()->addMenu(tr("&Help"));
|
||||
helpMenu->addAction(tr("&About"), this, &PylonRecorder::about);
|
||||
helpMenu->addAction(tr("About &Qt"), &QApplication::aboutQt);
|
||||
|
||||
|
||||
framerateSpinner = new QSpinBox();
|
||||
framerateSpinner->setRange(1, 120);
|
||||
framerateSpinner->setSuffix("Hz");
|
||||
framerateSpinner->setFixedWidth(120);
|
||||
framerateSpinner->setFixedHeight(30);
|
||||
framerateSpinner->setFixedSize(120, 25);
|
||||
framerateSpinner->setValue(defaultFrameRate);
|
||||
framerateSpinner->setStyleSheet("QSpinBox{font-size: 10px;font-family: Arial;color: rgb(0, 0, 0);background-color: rgb(255,255,255);}");
|
||||
//framerateSpinner->setStyleSheet("QSpinBox{font-size: 10px;font-family: Arial;color: rgb(255, 255, 255);background-color: rgb(38,56,76);}");
|
||||
@ -370,7 +382,7 @@ void PylonRecorder::createActions() {
|
||||
buffersizeSpinner->setRange(100, 5000);
|
||||
buffersizeSpinner->setSingleStep(25);
|
||||
buffersizeSpinner->setValue(defaultBufferSize);
|
||||
buffersizeSpinner->setFixedSize(120, 30);
|
||||
buffersizeSpinner->setFixedSize(120, 25);
|
||||
buffersizeSpinner->setStyleSheet("QSpinBox{font-size: 10px;font-family: Arial;color: rgb(0, 0, 0);background-color: rgb(255,255,255);}");
|
||||
|
||||
QToolBar *toolbar = addToolBar("main toolbar");
|
||||
@ -385,6 +397,7 @@ void PylonRecorder::createActions() {
|
||||
toolbar->addSeparator();
|
||||
toolbar->addWidget(new QLabel("frame rate:"));
|
||||
toolbar->addWidget(framerateSpinner);
|
||||
toolbar->addSeparator();
|
||||
toolbar->addWidget(new QLabel("buffer size:"));
|
||||
toolbar->addWidget(buffersizeSpinner);
|
||||
}
|
||||
@ -438,7 +451,13 @@ void PylonRecorder::connectCamera() {
|
||||
bool success = pylon->openCamera(message);
|
||||
if (success) {
|
||||
cameraConnectedLabel->setText("connected");
|
||||
cameraConnectedLabel->setStyleSheet("QLabel { color : green; }");
|
||||
cameraConnectedLabel->setStyleSheet("QLabel { font-size: 10px;font-family: Arial;color: green;}");
|
||||
}
|
||||
else {
|
||||
QMessageBox msgBox;
|
||||
QString msg = "<p><b>Could not open camera device!</b><p><p>" + QString::fromStdString(message) + "</p>";
|
||||
msgBox.setText(msg);
|
||||
msgBox.exec();
|
||||
}
|
||||
statusBar()->showMessage(QString::fromStdString(message));
|
||||
updateActions();
|
||||
@ -448,22 +467,27 @@ void PylonRecorder::disconnectCamera() {
|
||||
pylon->closeCamera();
|
||||
statusBar()->showMessage(tr("Camera closed!"));
|
||||
cameraConnectedLabel->setText("not connected");
|
||||
cameraConnectedLabel->setStyleSheet("QLabel { color : red; }");
|
||||
cameraConnectedLabel->setStyleSheet("QLabel { font-size: 10px;font-family: Arial;color: red;}");
|
||||
updateActions();
|
||||
}
|
||||
|
||||
void PylonRecorder::startRecording() {
|
||||
std::string filename = createFilename();
|
||||
std::cerr << filename << std::endl;
|
||||
fileLabel->setText(QString::fromStdString(filename));
|
||||
VideoSpecs specs;
|
||||
specs.fps = 25;
|
||||
specs.filename = "Test.mp4";
|
||||
specs.filename = filename;
|
||||
ImageSettings settings = pylon->getImageSettings();
|
||||
specs.width = static_cast<uint32_t>(settings.width);
|
||||
specs.height= static_cast<uint32_t>(settings.height);
|
||||
specs.pixelType = settings.pixelType;
|
||||
specs.orientation = settings.orientation;
|
||||
specs.quality = 95;
|
||||
if (buffersizeSpinner->value() != static_cast<int>(buffer->capacity()))
|
||||
if (buffersizeSpinner->value() != static_cast<int>(buffer->capacity())) {
|
||||
buffer->resize(static_cast<size_t>(buffersizeSpinner->value()));
|
||||
loadBar->setRange(0, buffersizeSpinner->value());
|
||||
}
|
||||
if (framerateSpinner->value() != grabber->currentFramerate())
|
||||
grabber->setFrameRate(framerateSpinner->value());
|
||||
writer->setVideoSpecs(specs);
|
||||
@ -533,6 +557,20 @@ QColor PylonRecorder::progressColor(int value) {
|
||||
return QColor::fromCmyk(c, m, y, k);
|
||||
}
|
||||
|
||||
std::string PylonRecorder::createFilename() {
|
||||
QDateTime dt(QDateTime::currentDateTimeUtc());
|
||||
QDate date = dt.date();
|
||||
std::string base = (date.toString("yyyy.MM.dd") + "_").toStdString();
|
||||
std::string extension = ".mp4";
|
||||
QString idx = QString::number(movieCount);
|
||||
std::string fname = base + idx.toStdString() + extension;
|
||||
while (QFile::exists(QString::fromStdString(fname))) {
|
||||
movieCount++;
|
||||
fname = base + QString::number(movieCount).toStdString() + extension;
|
||||
}
|
||||
return fname;
|
||||
}
|
||||
|
||||
void PylonRecorder::displayBufferPreassure() {
|
||||
int value = static_cast<int>(round(buffer->bufferPreassure()));
|
||||
preassureBar->setValue(value);
|
||||
|
@ -67,6 +67,7 @@ private:
|
||||
void createToolBar();
|
||||
void updateActions();
|
||||
QColor progressColor(int value);
|
||||
std::string createFilename();
|
||||
|
||||
bool saveFile(const QString &fileName);
|
||||
void setImage(const QImage &newImage);
|
||||
@ -74,10 +75,10 @@ private:
|
||||
void applyScaling();
|
||||
void adjustScrollBar(QScrollBar *scrollBar, double factor);
|
||||
|
||||
int defaultBufferSize = 1000, defaultFrameRate = 50;
|
||||
int defaultBufferSize = 1000, defaultFrameRate = 30, movieCount = 0;
|
||||
QImage image;
|
||||
QTimer *frameTimer, *preassureTimer, *labelTimer;
|
||||
QLabel *imageLabel, *writingLabel, *grabbingLabel, *cameraConnectedLabel;
|
||||
QLabel *imageLabel, *writingLabel, *grabbingLabel, *cameraConnectedLabel, *fileLabel;
|
||||
QProgressBar *preassureBar;
|
||||
QProgressBar *loadBar;
|
||||
QScrollArea *scrollArea;
|
||||
@ -88,9 +89,9 @@ private:
|
||||
Writer *writer;
|
||||
bool grabbing, stopRequest, writing, labelSwitch;
|
||||
QPalette progressPalette;
|
||||
QString activeLabelStyleHigh = "QLabel { color : red; }";
|
||||
QString activeLabelStyleLow = "QLabel { color : cmyk(0, 255, 255, 0, 50); }";
|
||||
QString inactiveLabelStyle = ("QLabel { color :gray; }");
|
||||
QString activeLabelStyleHigh = "QLabel { font-size: 10px;font-family: Arial; color : red; }";
|
||||
QString activeLabelStyleLow = "QLabel { font-size: 10px;font-family: Arial; color : cmyk(0, 255, 255, 0, 50); }";
|
||||
QString inactiveLabelStyle = ("QLabel { font-size: 10px;font-family: Arial; color :gray; }");
|
||||
QSpinBox *framerateSpinner, *buffersizeSpinner;
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user