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>
|
2013-06-17 16:41:00 +00:00
|
|
|
|
|
|
|
#include "../dive.h"
|
2013-11-18 13:53:05 +00:00
|
|
|
#include "mainwindow.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-01-16 04:50:56 +00:00
|
|
|
MinMaxAvgWidgetPrivate(MinMaxAvgWidget *owner) {
|
2013-06-04 21:51:27 +00:00
|
|
|
avgIco = new QLabel(owner);
|
|
|
|
avgIco->setPixmap(QIcon(":/average").pixmap(16,16));
|
|
|
|
avgIco->setToolTip(QObject::tr("Average"));
|
|
|
|
minIco = new QLabel(owner);
|
|
|
|
minIco->setPixmap(QIcon(":/minimum").pixmap(16,16));
|
|
|
|
minIco->setToolTip(QObject::tr("Minimum"));
|
|
|
|
maxIco = new QLabel(owner);
|
|
|
|
maxIco->setPixmap(QIcon(":/maximum").pixmap(16,16));
|
|
|
|
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-01-16 04:50:56 +00:00
|
|
|
MinMaxAvgWidget::MinMaxAvgWidget(QWidget* parent) : d(new MinMaxAvgWidgetPrivate(this))
|
|
|
|
{
|
|
|
|
|
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));
|
|
|
|
}
|
|
|
|
|
|
|
|
void MinMaxAvgWidget::setAverage(const QString& average)
|
|
|
|
{
|
|
|
|
d->avgValue->setText(average);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MinMaxAvgWidget::setMaximum(const QString& maximum)
|
|
|
|
{
|
|
|
|
d->maxValue->setText(maximum);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MinMaxAvgWidget::setMinimum(const QString& minimum)
|
|
|
|
{
|
|
|
|
d->minValue->setText(minimum);
|
|
|
|
}
|
2013-06-17 16:41:00 +00:00
|
|
|
|
|
|
|
RenumberDialog* RenumberDialog::instance()
|
|
|
|
{
|
2013-11-30 17:18:04 +00:00
|
|
|
static RenumberDialog* self = new RenumberDialog(mainWindow());
|
2013-06-17 16:41:00 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
void RenumberDialog::buttonClicked(QAbstractButton* button)
|
|
|
|
{
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-30 17:18:04 +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);
|
|
|
|
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
|
|
|
|
2013-11-18 13:53:05 +00:00
|
|
|
ShiftTimesDialog* ShiftTimesDialog::instance()
|
|
|
|
{
|
2013-11-30 17:18:04 +00:00
|
|
|
static ShiftTimesDialog* self = new ShiftTimesDialog(mainWindow());
|
2013-11-18 13:53:05 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ShiftTimesDialog::buttonClicked(QAbstractButton* button)
|
|
|
|
{
|
|
|
|
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);
|
2013-11-18 18:00:39 +00:00
|
|
|
mainWindow()->dive_list()->rememberSelection();
|
|
|
|
mainWindow()->refreshDisplay();
|
|
|
|
mainWindow()->dive_list()->restoreSelection();
|
|
|
|
}
|
2013-11-18 13:53:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-30 17:18:04 +00:00
|
|
|
ShiftTimesDialog::ShiftTimesDialog(QWidget *parent): QDialog(parent)
|
2013-11-18 13:53:05 +00:00
|
|
|
{
|
|
|
|
ui.setupUi(this);
|
|
|
|
connect(ui.buttonBox, SIGNAL(clicked(QAbstractButton*)), this, SLOT(buttonClicked(QAbstractButton*)));
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
p.start("pidof", QStringList() << "gnome-shell" );
|
|
|
|
p.waitForFinished(-1);
|
|
|
|
QString p_stdout = p.readAllStandardOutput();
|
|
|
|
return !p_stdout.isEmpty();
|
|
|
|
#endif
|
|
|
|
}
|