2013-06-04 21:51:27 +00:00
|
|
|
#include "simplewidgets.h"
|
|
|
|
|
|
|
|
#include <QLabel>
|
|
|
|
#include <QLabel>
|
|
|
|
#include <QFormLayout>
|
|
|
|
#include <QIcon>
|
2013-06-17 16:41:00 +00:00
|
|
|
#include <QAbstractButton>
|
|
|
|
#include <QSpinBox>
|
|
|
|
#include <QButtonGroup>
|
|
|
|
#include <QDebug>
|
2013-09-27 15:52:01 +00:00
|
|
|
#include <QProcess>
|
|
|
|
#include <QStringList>
|
|
|
|
#include <QDebug>
|
2014-02-12 15:46:17 +00:00
|
|
|
#include <QTime>
|
2014-02-13 15:43:55 +00:00
|
|
|
#include <QFileDialog>
|
|
|
|
#include <QDateTime>
|
|
|
|
#include "exif.h"
|
2013-06-17 16:41:00 +00:00
|
|
|
#include "../dive.h"
|
2014-02-13 15:43:55 +00:00
|
|
|
#include "../file.h"
|
2013-11-18 13:53:05 +00:00
|
|
|
#include "mainwindow.h"
|
2014-03-20 20:57:49 +00:00
|
|
|
#include "helpers.h"
|
2013-06-17 16:41:00 +00:00
|
|
|
|
2014-01-16 04:50:56 +00:00
|
|
|
class MinMaxAvgWidgetPrivate {
|
2013-06-04 21:51:27 +00:00
|
|
|
public:
|
|
|
|
QLabel *avgIco, *avgValue;
|
|
|
|
QLabel *minIco, *minValue;
|
|
|
|
QLabel *maxIco, *maxValue;
|
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
MinMaxAvgWidgetPrivate(MinMaxAvgWidget *owner)
|
|
|
|
{
|
2013-06-04 21:51:27 +00:00
|
|
|
avgIco = new QLabel(owner);
|
2014-02-28 04:09:57 +00:00
|
|
|
avgIco->setPixmap(QIcon(":/average").pixmap(16, 16));
|
2013-06-04 21:51:27 +00:00
|
|
|
avgIco->setToolTip(QObject::tr("Average"));
|
|
|
|
minIco = new QLabel(owner);
|
2014-02-28 04:09:57 +00:00
|
|
|
minIco->setPixmap(QIcon(":/minimum").pixmap(16, 16));
|
2013-06-04 21:51:27 +00:00
|
|
|
minIco->setToolTip(QObject::tr("Minimum"));
|
|
|
|
maxIco = new QLabel(owner);
|
2014-02-28 04:09:57 +00:00
|
|
|
maxIco->setPixmap(QIcon(":/maximum").pixmap(16, 16));
|
2013-06-04 21:51:27 +00:00
|
|
|
maxIco->setToolTip(QObject::tr("Maximum"));
|
|
|
|
avgValue = new QLabel(owner);
|
|
|
|
minValue = new QLabel(owner);
|
|
|
|
maxValue = new QLabel(owner);
|
2013-06-17 16:41:00 +00:00
|
|
|
|
2013-06-04 21:51:27 +00:00
|
|
|
QGridLayout *formLayout = new QGridLayout();
|
|
|
|
formLayout->addWidget(maxIco, 0, 0);
|
|
|
|
formLayout->addWidget(maxValue, 0, 1);
|
|
|
|
formLayout->addWidget(avgIco, 1, 0);
|
|
|
|
formLayout->addWidget(avgValue, 1, 1);
|
|
|
|
formLayout->addWidget(minIco, 2, 0);
|
|
|
|
formLayout->addWidget(minValue, 2, 1);
|
|
|
|
owner->setLayout(formLayout);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
double MinMaxAvgWidget::average() const
|
|
|
|
{
|
|
|
|
return d->avgValue->text().toDouble();
|
|
|
|
}
|
|
|
|
|
|
|
|
double MinMaxAvgWidget::maximum() const
|
|
|
|
{
|
|
|
|
return d->maxValue->text().toDouble();
|
|
|
|
}
|
|
|
|
double MinMaxAvgWidget::minimum() const
|
|
|
|
{
|
|
|
|
return d->minValue->text().toDouble();
|
|
|
|
}
|
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
MinMaxAvgWidget::MinMaxAvgWidget(QWidget *parent) : d(new MinMaxAvgWidgetPrivate(this))
|
2014-01-16 04:50:56 +00:00
|
|
|
{
|
2013-11-30 17:18:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
MinMaxAvgWidget::~MinMaxAvgWidget()
|
|
|
|
{
|
2013-06-04 21:51:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MinMaxAvgWidget::clear()
|
|
|
|
{
|
|
|
|
d->avgValue->setText(QString());
|
|
|
|
d->maxValue->setText(QString());
|
|
|
|
d->minValue->setText(QString());
|
|
|
|
}
|
|
|
|
|
|
|
|
void MinMaxAvgWidget::setAverage(double average)
|
|
|
|
{
|
|
|
|
d->avgValue->setText(QString::number(average));
|
|
|
|
}
|
|
|
|
|
|
|
|
void MinMaxAvgWidget::setMaximum(double maximum)
|
|
|
|
{
|
|
|
|
d->maxValue->setText(QString::number(maximum));
|
|
|
|
}
|
|
|
|
void MinMaxAvgWidget::setMinimum(double minimum)
|
|
|
|
{
|
|
|
|
d->minValue->setText(QString::number(minimum));
|
|
|
|
}
|
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
void MinMaxAvgWidget::setAverage(const QString &average)
|
2013-06-04 21:51:27 +00:00
|
|
|
{
|
|
|
|
d->avgValue->setText(average);
|
|
|
|
}
|
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
void MinMaxAvgWidget::setMaximum(const QString &maximum)
|
2013-06-04 21:51:27 +00:00
|
|
|
{
|
|
|
|
d->maxValue->setText(maximum);
|
|
|
|
}
|
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
void MinMaxAvgWidget::setMinimum(const QString &minimum)
|
2013-06-04 21:51:27 +00:00
|
|
|
{
|
|
|
|
d->minValue->setText(minimum);
|
|
|
|
}
|
2013-06-17 16:41:00 +00:00
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
RenumberDialog *RenumberDialog::instance()
|
2013-06-17 16:41:00 +00:00
|
|
|
{
|
2014-02-28 04:09:57 +00:00
|
|
|
static RenumberDialog *self = new RenumberDialog(MainWindow::instance());
|
2013-06-17 16:41:00 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
void RenumberDialog::buttonClicked(QAbstractButton *button)
|
2013-06-17 16:41:00 +00:00
|
|
|
{
|
2014-01-16 04:50:56 +00:00
|
|
|
if (ui.buttonBox->buttonRole(button) == QDialogButtonBox::AcceptRole) {
|
2013-06-17 16:41:00 +00:00
|
|
|
qDebug() << "Renumbering.";
|
2013-10-03 18:54:25 +00:00
|
|
|
renumber_dives(ui.spinBox->value());
|
2013-06-17 16:41:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
RenumberDialog::RenumberDialog(QWidget *parent) : QDialog(parent)
|
2013-06-17 16:41:00 +00:00
|
|
|
{
|
2013-10-03 18:54:25 +00:00
|
|
|
ui.setupUi(this);
|
2014-02-28 04:09:57 +00:00
|
|
|
connect(ui.buttonBox, SIGNAL(clicked(QAbstractButton *)), this, SLOT(buttonClicked(QAbstractButton *)));
|
2013-06-17 16:41:00 +00:00
|
|
|
}
|
2013-09-27 15:52:01 +00:00
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
ShiftTimesDialog *ShiftTimesDialog::instance()
|
2013-11-18 13:53:05 +00:00
|
|
|
{
|
2014-02-28 04:09:57 +00:00
|
|
|
static ShiftTimesDialog *self = new ShiftTimesDialog(MainWindow::instance());
|
2013-11-18 13:53:05 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
void ShiftTimesDialog::buttonClicked(QAbstractButton *button)
|
2013-11-18 13:53:05 +00:00
|
|
|
{
|
|
|
|
int amount;
|
|
|
|
|
2014-01-16 04:50:56 +00:00
|
|
|
if (ui.buttonBox->buttonRole(button) == QDialogButtonBox::AcceptRole) {
|
2013-11-18 13:53:05 +00:00
|
|
|
amount = ui.timeEdit->time().hour() * 3600 + ui.timeEdit->time().minute() * 60;
|
|
|
|
if (ui.backwards->isChecked())
|
|
|
|
amount *= -1;
|
2013-11-18 18:00:39 +00:00
|
|
|
if (amount != 0) {
|
|
|
|
// DANGER, DANGER - this could get our dive_table unsorted...
|
|
|
|
shift_times(amount);
|
|
|
|
sort_table(&dive_table);
|
2014-01-15 08:30:42 +00:00
|
|
|
mark_divelist_changed(true);
|
2014-02-12 14:22:54 +00:00
|
|
|
MainWindow::instance()->dive_list()->rememberSelection();
|
|
|
|
MainWindow::instance()->refreshDisplay();
|
|
|
|
MainWindow::instance()->dive_list()->restoreSelection();
|
2013-11-18 18:00:39 +00:00
|
|
|
}
|
2013-11-18 13:53:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-20 20:57:49 +00:00
|
|
|
void ShiftTimesDialog::showEvent(QShowEvent * event)
|
|
|
|
{
|
|
|
|
ui.timeEdit->setTime(QTime(0, 0, 0, 0));
|
|
|
|
when = get_times();//get time of first selected dive
|
|
|
|
ui.currentTime->setText(get_dive_date_string(when));
|
|
|
|
ui.shiftedTime->setText(get_dive_date_string(when));
|
|
|
|
}
|
|
|
|
|
|
|
|
void ShiftTimesDialog::changeTime()
|
|
|
|
{
|
|
|
|
int amount;
|
|
|
|
|
|
|
|
amount = ui.timeEdit->time().hour() * 3600 + ui.timeEdit->time().minute() * 60;
|
|
|
|
if (ui.backwards->isChecked())
|
|
|
|
amount *= -1;
|
|
|
|
|
|
|
|
ui.shiftedTime->setText (get_dive_date_string(amount+when));
|
|
|
|
}
|
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
ShiftTimesDialog::ShiftTimesDialog(QWidget *parent) : QDialog(parent)
|
2013-11-18 13:53:05 +00:00
|
|
|
{
|
|
|
|
ui.setupUi(this);
|
2014-02-28 04:09:57 +00:00
|
|
|
connect(ui.buttonBox, SIGNAL(clicked(QAbstractButton *)), this, SLOT(buttonClicked(QAbstractButton *)));
|
2014-03-20 20:57:49 +00:00
|
|
|
connect(ui.timeEdit, SIGNAL(timeChanged(const QTime)), this, SLOT(changeTime()));
|
|
|
|
connect(ui.backwards, SIGNAL(toggled(bool)), this, SLOT(changeTime()));
|
2013-11-18 13:53:05 +00:00
|
|
|
}
|
2014-01-27 13:44:26 +00:00
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
void ShiftImageTimesDialog::buttonClicked(QAbstractButton *button)
|
2014-01-27 13:44:26 +00:00
|
|
|
{
|
|
|
|
if (ui.buttonBox->buttonRole(button) == QDialogButtonBox::AcceptRole) {
|
2014-02-08 22:56:47 +00:00
|
|
|
m_amount = ui.timeEdit->time().hour() * 3600 + ui.timeEdit->time().minute() * 60;
|
2014-01-27 13:44:26 +00:00
|
|
|
if (ui.backwards->isChecked())
|
2014-02-08 22:56:47 +00:00
|
|
|
m_amount *= -1;
|
2014-01-27 13:44:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-13 15:43:55 +00:00
|
|
|
void ShiftImageTimesDialog::syncCameraClicked()
|
|
|
|
{
|
|
|
|
struct memblock mem;
|
|
|
|
EXIFInfo exiv;
|
|
|
|
int retval;
|
|
|
|
QPixmap picture;
|
2014-02-18 05:50:35 +00:00
|
|
|
QDateTime dcDateTime = QDateTime();
|
2014-02-13 15:43:55 +00:00
|
|
|
QStringList fileNames = QFileDialog::getOpenFileNames(this,
|
|
|
|
tr("Open Image File"),
|
2014-02-18 23:26:36 +00:00
|
|
|
DiveListView::lastUsedImageDir(),
|
2014-02-13 15:43:55 +00:00
|
|
|
tr("Image Files (*.jpg *.jpeg *.pnm *.tif *.tiff)"));
|
|
|
|
if (fileNames.isEmpty())
|
|
|
|
return;
|
|
|
|
|
|
|
|
picture.load(fileNames.at(0));
|
2014-02-19 10:34:54 +00:00
|
|
|
ui.displayDC->setEnabled(true);
|
2014-02-28 04:09:57 +00:00
|
|
|
QGraphicsScene *scene = new QGraphicsScene(this);
|
2014-02-13 15:43:55 +00:00
|
|
|
|
|
|
|
scene->addPixmap(picture.scaled(ui.DCImage->size()));
|
|
|
|
ui.DCImage->setScene(scene);
|
|
|
|
if (readfile(fileNames.at(0).toUtf8().data(), &mem) <= 0)
|
|
|
|
return;
|
2014-02-28 04:09:57 +00:00
|
|
|
retval = exiv.parseFrom((const unsigned char *)mem.buffer, (unsigned)mem.size);
|
2014-02-13 15:43:55 +00:00
|
|
|
free(mem.buffer);
|
|
|
|
if (retval != PARSE_EXIF_SUCCESS)
|
|
|
|
return;
|
|
|
|
dcImageEpoch = epochFromExiv(&exiv);
|
|
|
|
dcDateTime.setTime_t(dcImageEpoch);
|
|
|
|
ui.dcTime->setDateTime(dcDateTime);
|
|
|
|
connect(ui.dcTime, SIGNAL(dateTimeChanged(const QDateTime &)), this, SLOT(dcDateTimeChanged(const QDateTime &)));
|
|
|
|
}
|
|
|
|
|
2014-04-17 02:56:42 +00:00
|
|
|
//TODO: This should be moved to C-Code.
|
2014-02-13 15:43:55 +00:00
|
|
|
time_t ShiftImageTimesDialog::epochFromExiv(EXIFInfo *exif)
|
|
|
|
{
|
|
|
|
struct tm tm;
|
|
|
|
int year, month, day, hour, min, sec;
|
|
|
|
|
2014-02-18 05:50:36 +00:00
|
|
|
if (strlen(exif->DateTime.c_str()))
|
|
|
|
sscanf(exif->DateTime.c_str(), "%d:%d:%d %d:%d:%d", &year, &month, &day, &hour, &min, &sec);
|
|
|
|
else
|
|
|
|
sscanf(exif->DateTimeOriginal.c_str(), "%d:%d:%d %d:%d:%d", &year, &month, &day, &hour, &min, &sec);
|
2014-02-13 15:43:55 +00:00
|
|
|
tm.tm_year = year;
|
|
|
|
tm.tm_mon = month - 1;
|
|
|
|
tm.tm_mday = day;
|
|
|
|
tm.tm_hour = hour;
|
|
|
|
tm.tm_min = min;
|
|
|
|
tm.tm_sec = sec;
|
|
|
|
return (utc_mktime(&tm));
|
|
|
|
}
|
|
|
|
|
|
|
|
void ShiftImageTimesDialog::dcDateTimeChanged(const QDateTime &newDateTime)
|
|
|
|
{
|
|
|
|
if (!dcImageEpoch)
|
|
|
|
return;
|
|
|
|
setOffset(newDateTime.toTime_t() - dcImageEpoch);
|
|
|
|
}
|
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
ShiftImageTimesDialog::ShiftImageTimesDialog(QWidget *parent) : QDialog(parent), m_amount(0)
|
2014-01-27 13:44:26 +00:00
|
|
|
{
|
|
|
|
ui.setupUi(this);
|
2014-02-28 04:09:57 +00:00
|
|
|
connect(ui.buttonBox, SIGNAL(clicked(QAbstractButton *)), this, SLOT(buttonClicked(QAbstractButton *)));
|
2014-02-13 15:43:55 +00:00
|
|
|
connect(ui.syncCamera, SIGNAL(clicked()), this, SLOT(syncCameraClicked()));
|
2014-02-28 04:09:57 +00:00
|
|
|
dcImageEpoch = (time_t)0;
|
2014-01-27 13:44:26 +00:00
|
|
|
}
|
2013-11-18 13:53:05 +00:00
|
|
|
|
2014-02-13 15:43:55 +00:00
|
|
|
time_t ShiftImageTimesDialog::amount() const
|
2014-02-08 22:56:47 +00:00
|
|
|
{
|
|
|
|
return m_amount;
|
|
|
|
}
|
|
|
|
|
2014-02-13 15:43:55 +00:00
|
|
|
void ShiftImageTimesDialog::setOffset(time_t offset)
|
2014-02-12 15:46:17 +00:00
|
|
|
{
|
|
|
|
if (offset >= 0) {
|
2014-02-19 10:34:54 +00:00
|
|
|
ui.forward->setChecked(true);
|
2014-02-12 15:46:17 +00:00
|
|
|
} else {
|
2014-02-19 10:34:54 +00:00
|
|
|
ui.backwards->setChecked(true);
|
2014-02-12 15:46:17 +00:00
|
|
|
offset *= -1;
|
|
|
|
}
|
2014-02-18 05:50:35 +00:00
|
|
|
ui.timeEdit->setTime(QTime(offset / 3600, (offset % 3600) / 60, offset % 60));
|
2014-02-12 15:46:17 +00:00
|
|
|
}
|
|
|
|
|
2013-09-27 15:52:01 +00:00
|
|
|
bool isGnome3Session()
|
|
|
|
{
|
|
|
|
#if defined(QT_OS_WIW) || defined(QT_OS_MAC)
|
|
|
|
return false;
|
|
|
|
#else
|
|
|
|
if (qApp->style()->objectName() != "gtk+")
|
|
|
|
return false;
|
|
|
|
QProcess p;
|
2014-02-28 04:09:57 +00:00
|
|
|
p.start("pidof", QStringList() << "gnome-shell");
|
2013-09-27 15:52:01 +00:00
|
|
|
p.waitForFinished(-1);
|
|
|
|
QString p_stdout = p.readAllStandardOutput();
|
|
|
|
return !p_stdout.isEmpty();
|
|
|
|
#endif
|
|
|
|
}
|