12 #include "ui_fotobox.h"
23 , m_ui(new
Ui::FotoBoxDialog)
25 , m_workerThread(this)
33 setWindowTitle(QStringLiteral(
"%1 v%2 (Copyright 2016 %3)").arg(QApplication::applicationName(), QApplication::applicationVersion(), QApplication::organizationName()));
39 setAttribute(Qt::WA_DeleteOnClose);
42 connect(m_ui->statusBar, &QStatusBar::messageChanged,
this, [&](
const QString &i_message) { i_message.isNull() ? m_ui->statusBar->hide() : m_ui->statusBar->show(); });
44 m_ui->statusBar->hide();
50 #if defined(BUZZER_AVAILABLE)
60 void FotoBox::buttons()
64 connect(m_ui->btnStart, &QPushButton::clicked,
this, &FotoBox::start);
65 connect(m_ui->btnPreferencesDialog, &QPushButton::clicked,
this, &FotoBox::preferenceDialog);
66 connect(m_ui->btnQuitApp, &QPushButton::clicked, QCoreApplication::instance(), &QCoreApplication::quit);
69 QGuiApplication::setOverrideCursor(Qt::BlankCursor);
71 m_ui->btnStart->hide();
72 m_ui->btnPreferencesDialog->hide();
73 m_ui->btnQuitApp->hide();
77 void FotoBox::buzzer()
79 #if defined(BUZZER_AVAILABLE)
80 if (m_workerThread.isRunning()) {
84 if (!m_buzzer.initialise()) {
86 m_ui->statusBar->showMessage(tr(
"Buzzer isn't working. Please check 'pigpio' deamon."), STATUSBAR_MSG_TIMEOUT);
91 m_buzzer.moveToThread(&m_workerThread);
98 m_workerThread.start();
106 void FotoBox::countdown()
109 m_ui->lcdCountdown->hide();
118 connect(&m_countdown, &
Countdown::update,
this, [&](
const unsigned int i_timeLeft) {
120 m_ui->lblPhoto->hide();
121 m_ui->lcdCountdown->show();
122 m_ui->lcdCountdown->display(QString::number(i_timeLeft));
126 auto palette = m_ui->lcdCountdown->palette();
128 m_ui->lcdCountdown->setPalette(palette);
131 connect(
this, &FotoBox::start,
this, &FotoBox::photo);
137 #if defined(BUZZER_AVAILABLE)
144 m_workerThread.quit();
145 m_workerThread.wait();
151 void FotoBox::keyPressEvent(QKeyEvent *event)
154 if (!event->isAutoRepeat()) {
156 if (std::any_of(m_triggerKey.cbegin(), m_triggerKey.cend(), [&](
const Qt::Key i_key) ->
bool { return event->key() == i_key; })) {
162 if (std::any_of(m_preferenceKey.cbegin(), m_preferenceKey.cend(), [&](
const Qt::Key i_key) ->
bool { return event->key() == i_key; })) {
168 if (std::any_of(m_quitKey.cbegin(), m_quitKey.cend(), [&](
const Qt::Key i_key) ->
bool { return event->key() == i_key; })) {
169 if (event->modifiers() == Qt::ShiftModifier) {
170 QCoreApplication::quit();
172 m_ui->statusBar->showMessage(tr(
"To quit the application, please hold down the Shift key while press Escape key."), STATUSBAR_MSG_TIMEOUT);
178 void FotoBox::mouseReleaseEvent(QMouseEvent *event)
186 QWidget::mouseReleaseEvent(event);
189 void FotoBox::preferenceDialog()
195 QApplication::restoreOverrideCursor();
200 #if defined(Q_OS_MACOS)
202 closeFullscreenWindowOnMac();
208 void FotoBox::photo()
211 m_ui->lcdCountdown->hide();
212 QCoreApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
215 m_ui->lblPhoto->show();
216 m_ui->lblPhoto->clear();
217 m_ui->lblPhoto->repaint();
220 if (m_camera.shootPhoto()) {
222 loadPhoto(m_photoDir + m_camera.currentPhoto());
224 m_ui->statusBar->showMessage(tr(
"Error: Taking a photo isn't working correctly!"), STATUSBAR_MSG_TIMEOUT);
231 #if defined(BUZZER_AVAILABLE)
238 void FotoBox::loadPhoto(
const QString &i_filePath)
241 if (m_photo.load(i_filePath)) {
243 QSize size(m_ui->lblPhoto->width(), m_ui->lblPhoto->height());
247 const auto grey = m_photo.toImage().convertToFormat(QImage::Format_Grayscale8);
248 m_photo.convertFromImage(grey);
252 m_photo = m_photo.scaled(size, Qt::KeepAspectRatio, Qt::SmoothTransformation);
253 m_ui->lblPhoto->setPixmap(m_photo);
254 m_ui->lblPhoto->repaint();
256 m_ui->statusBar->showMessage(tr(
"Couldn't load the photo."), STATUSBAR_MSG_TIMEOUT);
260 void FotoBox::drawText(
const QString &i_text)
263 QPainter painter(&m_photo);
269 QFont font = painter.font();
270 const auto size = calculateFontSize(m_photo.rect().width(), painter.fontMetrics().boundingRect(i_text).width());
271 font.setPointSizeF(font.pointSizeF() * size);
272 painter.setFont(font);
275 painter.drawText(m_photo.rect(), Qt::AlignCenter, i_text);
277 m_ui->lblPhoto->setPixmap(m_photo);
280 auto FotoBox::calculateFontSize(
const double i_width,
const double i_widthFont) ->
double
282 auto factor = i_width / i_widthFont;
283 if ((factor < 1) || (factor > COMPARE)) {
void queryPin()
Query the Raspberry Pi pin.
void triggered()
Buzzer was pressed.
auto start() -> bool
Start countdown.
void elapsed()
Countdown elapsed.
void update(unsigned int)
Update countdown.
The FotoBox class Main class to control UI and controll the process.
Preference who stores the preferences.
static PreferenceProvider & instance()
get instance (Meyers Singleton)
Preference class to change and store the application settings.