nicer font sizes, message box for error messaging!

This commit is contained in:
Jan Grewe 2020-03-16 14:45:29 +01:00
parent a6b6d0e889
commit 4011a17f13
2 changed files with 70 additions and 31 deletions

View File

@ -25,6 +25,7 @@
# include <QtPrintSupport/qtprintsupportglobal.h> # include <QtPrintSupport/qtprintsupportglobal.h>
# if QT_CONFIG(printdialog) # if QT_CONFIG(printdialog)
#include <QDateTime>
# include <QPrintDialog> # include <QPrintDialog>
# endif # endif
#endif #endif
@ -60,34 +61,51 @@ PylonRecorder::PylonRecorder(QWidget *parent)
preassureBar = new QProgressBar(this); preassureBar = new QProgressBar(this);
preassureBar->setRange(0, 100); preassureBar->setRange(0, 100);
preassureBar->setTextVisible(true); preassureBar->setTextVisible(true);
preassureBar->setFixedSize(200, 25);
QColor color = progressColor(0); QColor color = progressColor(0);
QPalette progressPalette = preassureBar->palette(); QPalette progressPalette = preassureBar->palette();
progressPalette.setBrush(QPalette::Highlight, QBrush(color)); progressPalette.setBrush(QPalette::Highlight, QBrush(color));
preassureBar->setPalette(progressPalette); preassureBar->setPalette(progressPalette);
QLabel *preassureLabel = new QLabel("Buffer preassure:", this); QLabel *preassureLabel = new QLabel("Buffer preassure:", this);
preassureLabel->setStyleSheet("QLabel{font-size: 11px;font-family: Arial;font-weight: Bold}");
loadBar = new QProgressBar(this); loadBar = new QProgressBar(this);
loadBar->setRange(0, 1000); loadBar->setRange(0, defaultBufferSize);
loadBar->setFixedSize(200, 25);
QLabel *loadLabel = new QLabel("Load:", this); QLabel *loadLabel = new QLabel("Load:", this);
loadLabel->setStyleSheet("QLabel{font-size: 11px;font-family: Arial;font-weight: Bold}");
writingLabel = new QLabel("writing"); writingLabel = new QLabel("writing");
writingLabel->setEnabled(false); writingLabel->setEnabled(false);
writingLabel->setStyleSheet("QLabel{font-size: 11px;font-family: Arial;}");
grabbingLabel = new QLabel("grabbing"); grabbingLabel = new QLabel("grabbing");
//grabbingLabel->setStyleSheet("QLabel { color : gray; }");
grabbingLabel->setEnabled(false); grabbingLabel->setEnabled(false);
grabbingLabel->setStyleSheet("QLabel{font-size: 11px;font-family: Arial;}");
labelSwitch = false; labelSwitch = false;
cameraConnectedLabel = new QLabel("not connected"); cameraConnectedLabel = new QLabel("not connected");
cameraConnectedLabel->setStyleSheet("QLabel { color : red; }"); 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(cameraConnectedLabel);
statusBar()->addWidget(preassureLabel); statusBar()->addWidget(preassureLabel);
statusBar()->addWidget(preassureBar); statusBar()->addWidget(preassureBar);
statusBar()->addWidget(loadLabel); statusBar()->addWidget(loadLabel);
statusBar()->addWidget(loadBar); statusBar()->addWidget(loadBar);
statusBar()->addWidget(statusHeader);
statusBar()->addWidget(grabbingLabel); statusBar()->addWidget(grabbingLabel);
statusBar()->addWidget(writingLabel); statusBar()->addWidget(writingLabel);
statusBar()->addWidget(fileHeader);
statusBar()->addWidget(fileLabel);
resize(QGuiApplication::primaryScreen()->availableSize() * 3 / 5); resize(QGuiApplication::primaryScreen()->availableSize() * 3 / 5);
} }
@ -269,19 +287,14 @@ void PylonRecorder::fitToWindow() {
} }
void PylonRecorder::about() { void PylonRecorder::about() {
QMessageBox::about(this, tr("About Image Viewer"), QMessageBox::about(this, tr("About Pylon Recorder"),
tr("<p>The <b>Image Viewer</b> example shows how to combine QLabel " tr("<p><b>Pylon Recorder</b><br> Simple recorder for video grabbing from pylon USB3 monochrome camera."
"and QScrollArea to display an image. QLabel is typically used " "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>"
"for displaying a text, but it can also display an image. " "<p> videos are stored in the same folder as the tool is. Videos are compressed to mp4."
"QScrollArea provides a scrolling view around another widget. " " As the buffer preassure reaches 100% frames will be lost! You may want to increase the buffer size"
"If the child widget exceeds the size of the frame, QScrollArea " " or reduce the framerate.</p><p>In order to run you need to install the pylon libraries"
"automatically provides scroll bars. </p><p>The example " " and the mp4 video codec avalable for download at <a href='https://www.baslerweb.com/de/'>Basler website</a></p>"
"demonstrates how QLabel's ability to scale its contents " "<p>by Jan Grewe, <a href='http://www.neuroetho.uni-tuebingen.de'>Neuroethology Lab</a>, University of Tuebingen.</p>"));
"(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>"));
} }
void PylonRecorder::createActions() { 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 = camera_menu->addAction(grab_icon, tr("&grab continuous"), this, &PylonRecorder::startRecording);
grab_continuous_action->setShortcut(tr("Ctrl+Enter")); grab_continuous_action->setShortcut(tr("Ctrl+Enter"));
grab_stop_action = camera_menu->addAction(stop_icon, tr("&stop grabbing"), this, &PylonRecorder::stopRecording); 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")); QMenu *helpMenu = menuBar()->addMenu(tr("&Help"));
helpMenu->addAction(tr("&About"), this, &PylonRecorder::about); helpMenu->addAction(tr("&About"), this, &PylonRecorder::about);
helpMenu->addAction(tr("About &Qt"), &QApplication::aboutQt); helpMenu->addAction(tr("About &Qt"), &QApplication::aboutQt);
framerateSpinner = new QSpinBox(); framerateSpinner = new QSpinBox();
framerateSpinner->setRange(1, 120); framerateSpinner->setRange(1, 120);
framerateSpinner->setSuffix("Hz"); framerateSpinner->setSuffix("Hz");
framerateSpinner->setFixedWidth(120); framerateSpinner->setFixedSize(120, 25);
framerateSpinner->setFixedHeight(30);
framerateSpinner->setValue(defaultFrameRate); 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(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);}"); //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->setRange(100, 5000);
buffersizeSpinner->setSingleStep(25); buffersizeSpinner->setSingleStep(25);
buffersizeSpinner->setValue(defaultBufferSize); 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);}"); 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"); QToolBar *toolbar = addToolBar("main toolbar");
@ -385,6 +397,7 @@ void PylonRecorder::createActions() {
toolbar->addSeparator(); toolbar->addSeparator();
toolbar->addWidget(new QLabel("frame rate:")); toolbar->addWidget(new QLabel("frame rate:"));
toolbar->addWidget(framerateSpinner); toolbar->addWidget(framerateSpinner);
toolbar->addSeparator();
toolbar->addWidget(new QLabel("buffer size:")); toolbar->addWidget(new QLabel("buffer size:"));
toolbar->addWidget(buffersizeSpinner); toolbar->addWidget(buffersizeSpinner);
} }
@ -438,7 +451,13 @@ void PylonRecorder::connectCamera() {
bool success = pylon->openCamera(message); bool success = pylon->openCamera(message);
if (success) { if (success) {
cameraConnectedLabel->setText("connected"); 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)); statusBar()->showMessage(QString::fromStdString(message));
updateActions(); updateActions();
@ -448,22 +467,27 @@ void PylonRecorder::disconnectCamera() {
pylon->closeCamera(); pylon->closeCamera();
statusBar()->showMessage(tr("Camera closed!")); statusBar()->showMessage(tr("Camera closed!"));
cameraConnectedLabel->setText("not connected"); cameraConnectedLabel->setText("not connected");
cameraConnectedLabel->setStyleSheet("QLabel { color : red; }"); cameraConnectedLabel->setStyleSheet("QLabel { font-size: 10px;font-family: Arial;color: red;}");
updateActions(); updateActions();
} }
void PylonRecorder::startRecording() { void PylonRecorder::startRecording() {
std::string filename = createFilename();
std::cerr << filename << std::endl;
fileLabel->setText(QString::fromStdString(filename));
VideoSpecs specs; VideoSpecs specs;
specs.fps = 25; specs.fps = 25;
specs.filename = "Test.mp4"; specs.filename = filename;
ImageSettings settings = pylon->getImageSettings(); ImageSettings settings = pylon->getImageSettings();
specs.width = static_cast<uint32_t>(settings.width); specs.width = static_cast<uint32_t>(settings.width);
specs.height= static_cast<uint32_t>(settings.height); specs.height= static_cast<uint32_t>(settings.height);
specs.pixelType = settings.pixelType; specs.pixelType = settings.pixelType;
specs.orientation = settings.orientation; specs.orientation = settings.orientation;
specs.quality = 95; 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())); buffer->resize(static_cast<size_t>(buffersizeSpinner->value()));
loadBar->setRange(0, buffersizeSpinner->value());
}
if (framerateSpinner->value() != grabber->currentFramerate()) if (framerateSpinner->value() != grabber->currentFramerate())
grabber->setFrameRate(framerateSpinner->value()); grabber->setFrameRate(framerateSpinner->value());
writer->setVideoSpecs(specs); writer->setVideoSpecs(specs);
@ -533,6 +557,20 @@ QColor PylonRecorder::progressColor(int value) {
return QColor::fromCmyk(c, m, y, k); 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() { void PylonRecorder::displayBufferPreassure() {
int value = static_cast<int>(round(buffer->bufferPreassure())); int value = static_cast<int>(round(buffer->bufferPreassure()));
preassureBar->setValue(value); preassureBar->setValue(value);

View File

@ -67,6 +67,7 @@ private:
void createToolBar(); void createToolBar();
void updateActions(); void updateActions();
QColor progressColor(int value); QColor progressColor(int value);
std::string createFilename();
bool saveFile(const QString &fileName); bool saveFile(const QString &fileName);
void setImage(const QImage &newImage); void setImage(const QImage &newImage);
@ -74,10 +75,10 @@ private:
void applyScaling(); void applyScaling();
void adjustScrollBar(QScrollBar *scrollBar, double factor); void adjustScrollBar(QScrollBar *scrollBar, double factor);
int defaultBufferSize = 1000, defaultFrameRate = 50; int defaultBufferSize = 1000, defaultFrameRate = 30, movieCount = 0;
QImage image; QImage image;
QTimer *frameTimer, *preassureTimer, *labelTimer; QTimer *frameTimer, *preassureTimer, *labelTimer;
QLabel *imageLabel, *writingLabel, *grabbingLabel, *cameraConnectedLabel; QLabel *imageLabel, *writingLabel, *grabbingLabel, *cameraConnectedLabel, *fileLabel;
QProgressBar *preassureBar; QProgressBar *preassureBar;
QProgressBar *loadBar; QProgressBar *loadBar;
QScrollArea *scrollArea; QScrollArea *scrollArea;
@ -88,9 +89,9 @@ private:
Writer *writer; Writer *writer;
bool grabbing, stopRequest, writing, labelSwitch; bool grabbing, stopRequest, writing, labelSwitch;
QPalette progressPalette; QPalette progressPalette;
QString activeLabelStyleHigh = "QLabel { color : red; }"; QString activeLabelStyleHigh = "QLabel { font-size: 10px;font-family: Arial; color : red; }";
QString activeLabelStyleLow = "QLabel { color : cmyk(0, 255, 255, 0, 50); }"; QString activeLabelStyleLow = "QLabel { font-size: 10px;font-family: Arial; color : cmyk(0, 255, 255, 0, 50); }";
QString inactiveLabelStyle = ("QLabel { color :gray; }"); QString inactiveLabelStyle = ("QLabel { font-size: 10px;font-family: Arial; color :gray; }");
QSpinBox *framerateSpinner, *buffersizeSpinner; QSpinBox *framerateSpinner, *buffersizeSpinner;