| 
									
										
										
										
											2013-06-04 18:51:27 -03:00
										 |  |  | #include "simplewidgets.h"
 | 
					
						
							| 
									
										
										
										
											2014-11-13 16:31:03 -02:00
										 |  |  | #include "filtermodels.h"
 | 
					
						
							| 
									
										
										
										
											2013-06-04 18:51:27 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-09-27 12:52:01 -03:00
										 |  |  | #include <QProcess>
 | 
					
						
							| 
									
										
										
										
											2014-02-13 16:43:55 +01:00
										 |  |  | #include <QFileDialog>
 | 
					
						
							| 
									
										
										
										
											2014-04-25 19:39:40 +02:00
										 |  |  | #include <QShortcut>
 | 
					
						
							| 
									
										
										
										
											2014-06-19 15:42:05 -03:00
										 |  |  | #include <QCalendarWidget>
 | 
					
						
							| 
									
										
										
										
											2015-01-17 22:43:52 +13:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-20 06:11:32 +09:00
										 |  |  | #include "file.h"
 | 
					
						
							| 
									
										
										
										
											2013-11-18 14:53:05 +01:00
										 |  |  | #include "mainwindow.h"
 | 
					
						
							| 
									
										
										
										
											2014-03-20 22:57:49 +02:00
										 |  |  | #include "helpers.h"
 | 
					
						
							| 
									
										
										
										
											2014-11-25 21:22:02 +01:00
										 |  |  | #include "libdivecomputer/parser.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-17 13:41:00 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-16 11:50:56 +07:00
										 |  |  | class MinMaxAvgWidgetPrivate { | 
					
						
							| 
									
										
										
										
											2013-06-04 18:51:27 -03:00
										 |  |  | public: | 
					
						
							|  |  |  | 	QLabel *avgIco, *avgValue; | 
					
						
							|  |  |  | 	QLabel *minIco, *minValue; | 
					
						
							|  |  |  | 	QLabel *maxIco, *maxValue; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | 	MinMaxAvgWidgetPrivate(MinMaxAvgWidget *owner) | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2013-06-04 18:51:27 -03:00
										 |  |  | 		avgIco = new QLabel(owner); | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | 		avgIco->setPixmap(QIcon(":/average").pixmap(16, 16)); | 
					
						
							| 
									
										
										
										
											2013-06-04 18:51:27 -03:00
										 |  |  | 		avgIco->setToolTip(QObject::tr("Average")); | 
					
						
							|  |  |  | 		minIco = new QLabel(owner); | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | 		minIco->setPixmap(QIcon(":/minimum").pixmap(16, 16)); | 
					
						
							| 
									
										
										
										
											2013-06-04 18:51:27 -03:00
										 |  |  | 		minIco->setToolTip(QObject::tr("Minimum")); | 
					
						
							|  |  |  | 		maxIco = new QLabel(owner); | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | 		maxIco->setPixmap(QIcon(":/maximum").pixmap(16, 16)); | 
					
						
							| 
									
										
										
										
											2013-06-04 18:51:27 -03:00
										 |  |  | 		maxIco->setToolTip(QObject::tr("Maximum")); | 
					
						
							|  |  |  | 		avgValue = new QLabel(owner); | 
					
						
							|  |  |  | 		minValue = new QLabel(owner); | 
					
						
							|  |  |  | 		maxValue = new QLabel(owner); | 
					
						
							| 
									
										
										
										
											2013-06-17 13:41:00 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-04 18:51:27 -03: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-27 20:09:57 -08:00
										 |  |  | MinMaxAvgWidget::MinMaxAvgWidget(QWidget *parent) : d(new MinMaxAvgWidgetPrivate(this)) | 
					
						
							| 
									
										
										
										
											2014-01-16 11:50:56 +07:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2013-11-30 09:18:02 -08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | MinMaxAvgWidget::~MinMaxAvgWidget() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2013-06-04 18:51:27 -03: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-27 20:09:57 -08:00
										 |  |  | void MinMaxAvgWidget::setAverage(const QString &average) | 
					
						
							| 
									
										
										
										
											2013-06-04 18:51:27 -03:00
										 |  |  | { | 
					
						
							|  |  |  | 	d->avgValue->setText(average); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | void MinMaxAvgWidget::setMaximum(const QString &maximum) | 
					
						
							| 
									
										
										
										
											2013-06-04 18:51:27 -03:00
										 |  |  | { | 
					
						
							|  |  |  | 	d->maxValue->setText(maximum); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | void MinMaxAvgWidget::setMinimum(const QString &minimum) | 
					
						
							| 
									
										
										
										
											2013-06-04 18:51:27 -03:00
										 |  |  | { | 
					
						
							|  |  |  | 	d->minValue->setText(minimum); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2013-06-17 13:41:00 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-30 23:46:55 +01:00
										 |  |  | void MinMaxAvgWidget::overrideMinToolTipText(const QString &newTip) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	d->minIco->setToolTip(newTip); | 
					
						
							| 
									
										
										
										
											2014-11-17 18:40:08 +00:00
										 |  |  | 	d->minValue->setToolTip(newTip); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void MinMaxAvgWidget::overrideAvgToolTipText(const QString &newTip) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	d->avgIco->setToolTip(newTip); | 
					
						
							|  |  |  | 	d->avgValue->setToolTip(newTip); | 
					
						
							| 
									
										
										
										
											2014-05-30 23:46:55 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void MinMaxAvgWidget::overrideMaxToolTipText(const QString &newTip) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	d->maxIco->setToolTip(newTip); | 
					
						
							| 
									
										
										
										
											2014-11-17 18:40:08 +00:00
										 |  |  | 	d->maxValue->setToolTip(newTip); | 
					
						
							| 
									
										
										
										
											2014-05-30 23:46:55 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | RenumberDialog *RenumberDialog::instance() | 
					
						
							| 
									
										
										
										
											2013-06-17 13:41:00 -03:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | 	static RenumberDialog *self = new RenumberDialog(MainWindow::instance()); | 
					
						
							| 
									
										
										
										
											2013-06-17 13:41:00 -03:00
										 |  |  | 	return self; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-20 06:11:32 +09:00
										 |  |  | void RenumberDialog::renumberOnlySelected(bool selected) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if (selected && amount_selected == 1) | 
					
						
							|  |  |  | 		ui.groupBox->setTitle(tr("New number")); | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 		ui.groupBox->setTitle(tr("New starting number")); | 
					
						
							|  |  |  | 	selectedOnly = selected; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | void RenumberDialog::buttonClicked(QAbstractButton *button) | 
					
						
							| 
									
										
										
										
											2013-06-17 13:41:00 -03:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2014-12-15 23:38:38 +01:00
										 |  |  | 	if (ui.buttonBox->buttonRole(button) == QDialogButtonBox::AcceptRole) | 
					
						
							| 
									
										
										
										
											2014-05-20 06:11:32 +09:00
										 |  |  | 		renumber_dives(ui.spinBox->value(), selectedOnly); | 
					
						
							| 
									
										
										
										
											2013-06-17 13:41:00 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-20 06:11:32 +09:00
										 |  |  | RenumberDialog::RenumberDialog(QWidget *parent) : QDialog(parent), selectedOnly(false) | 
					
						
							| 
									
										
										
										
											2014-11-25 21:22:02 +01:00
										 |  |  | { | 
					
						
							|  |  |  | 	ui.setupUi(this); | 
					
						
							|  |  |  | 	connect(ui.buttonBox, SIGNAL(clicked(QAbstractButton *)), this, SLOT(buttonClicked(QAbstractButton *))); | 
					
						
							|  |  |  | 	QShortcut *close = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_W), this); | 
					
						
							|  |  |  | 	connect(close, SIGNAL(activated()), this, SLOT(close())); | 
					
						
							|  |  |  | 	QShortcut *quit = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_Q), this); | 
					
						
							|  |  |  | 	connect(quit, SIGNAL(activated()), parent, SLOT(close())); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | SetpointDialog *SetpointDialog::instance() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	static SetpointDialog *self = new SetpointDialog(MainWindow::instance()); | 
					
						
							|  |  |  | 	return self; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void SetpointDialog::setpointData(struct divecomputer *divecomputer, int second) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	dc = divecomputer; | 
					
						
							| 
									
										
										
										
											2014-12-15 23:33:16 +01:00
										 |  |  | 	time = second < 0 ? 0 : second; | 
					
						
							| 
									
										
										
										
											2014-11-25 21:22:02 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void SetpointDialog::buttonClicked(QAbstractButton *button) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2014-12-15 23:38:38 +01:00
										 |  |  | 	if (ui.buttonBox->buttonRole(button) == QDialogButtonBox::AcceptRole) | 
					
						
							| 
									
										
										
										
											2014-11-26 14:22:41 +01:00
										 |  |  | 		add_event(dc, time, SAMPLE_EVENT_PO2, 0, (int)(1000.0 * ui.spinbox->value()), "SP change"); | 
					
						
							|  |  |  | 	mark_divelist_changed(true); | 
					
						
							|  |  |  | 	MainWindow::instance()->graphics()->replot(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-11-25 21:22:02 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | SetpointDialog::SetpointDialog(QWidget *parent) : QDialog(parent) | 
					
						
							| 
									
										
										
										
											2013-06-17 13:41:00 -03:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2013-10-03 11:54:25 -07:00
										 |  |  | 	ui.setupUi(this); | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | 	connect(ui.buttonBox, SIGNAL(clicked(QAbstractButton *)), this, SLOT(buttonClicked(QAbstractButton *))); | 
					
						
							| 
									
										
										
										
											2014-04-25 20:32:02 +02:00
										 |  |  | 	QShortcut *close = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_W), this); | 
					
						
							|  |  |  | 	connect(close, SIGNAL(activated()), this, SLOT(close())); | 
					
						
							|  |  |  | 	QShortcut *quit = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_Q), this); | 
					
						
							|  |  |  | 	connect(quit, SIGNAL(activated()), parent, SLOT(close())); | 
					
						
							| 
									
										
										
										
											2013-06-17 13:41:00 -03:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2013-09-27 12:52:01 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | ShiftTimesDialog *ShiftTimesDialog::instance() | 
					
						
							| 
									
										
										
										
											2013-11-18 14:53:05 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | 	static ShiftTimesDialog *self = new ShiftTimesDialog(MainWindow::instance()); | 
					
						
							| 
									
										
										
										
											2013-11-18 14:53:05 +01:00
										 |  |  | 	return self; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | void ShiftTimesDialog::buttonClicked(QAbstractButton *button) | 
					
						
							| 
									
										
										
										
											2013-11-18 14:53:05 +01:00
										 |  |  | { | 
					
						
							|  |  |  | 	int amount; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-16 11:50:56 +07:00
										 |  |  | 	if (ui.buttonBox->buttonRole(button) == QDialogButtonBox::AcceptRole) { | 
					
						
							| 
									
										
										
										
											2013-11-18 14:53:05 +01:00
										 |  |  | 		amount = ui.timeEdit->time().hour() * 3600 + ui.timeEdit->time().minute() * 60; | 
					
						
							|  |  |  | 		if (ui.backwards->isChecked()) | 
					
						
							|  |  |  | 			amount *= -1; | 
					
						
							| 
									
										
										
										
											2013-11-18 10:00:39 -08:00
										 |  |  | 		if (amount != 0) { | 
					
						
							|  |  |  | 			// DANGER, DANGER - this could get our dive_table unsorted...
 | 
					
						
							|  |  |  | 			shift_times(amount); | 
					
						
							|  |  |  | 			sort_table(&dive_table); | 
					
						
							| 
									
										
										
										
											2014-01-15 09:30:42 +01:00
										 |  |  | 			mark_divelist_changed(true); | 
					
						
							| 
									
										
										
										
											2014-02-12 15:22:54 +01:00
										 |  |  | 			MainWindow::instance()->dive_list()->rememberSelection(); | 
					
						
							|  |  |  | 			MainWindow::instance()->refreshDisplay(); | 
					
						
							|  |  |  | 			MainWindow::instance()->dive_list()->restoreSelection(); | 
					
						
							| 
									
										
										
										
											2013-11-18 10:00:39 -08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2013-11-18 14:53:05 +01:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-22 11:40:22 -07:00
										 |  |  | void ShiftTimesDialog::showEvent(QShowEvent *event) | 
					
						
							| 
									
										
										
										
											2014-03-20 22:57:49 +02:00
										 |  |  | { | 
					
						
							|  |  |  | 	ui.timeEdit->setTime(QTime(0, 0, 0, 0)); | 
					
						
							| 
									
										
										
										
											2014-05-22 11:40:22 -07:00
										 |  |  | 	when = get_times(); //get time of first selected dive
 | 
					
						
							| 
									
										
										
										
											2014-03-20 22:57:49 +02:00
										 |  |  | 	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; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-22 11:40:22 -07:00
										 |  |  | 	ui.shiftedTime->setText(get_dive_date_string(amount + when)); | 
					
						
							| 
									
										
										
										
											2014-03-20 22:57:49 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | ShiftTimesDialog::ShiftTimesDialog(QWidget *parent) : QDialog(parent) | 
					
						
							| 
									
										
										
										
											2013-11-18 14:53:05 +01:00
										 |  |  | { | 
					
						
							|  |  |  | 	ui.setupUi(this); | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | 	connect(ui.buttonBox, SIGNAL(clicked(QAbstractButton *)), this, SLOT(buttonClicked(QAbstractButton *))); | 
					
						
							| 
									
										
										
										
											2014-03-20 22:57:49 +02:00
										 |  |  | 	connect(ui.timeEdit, SIGNAL(timeChanged(const QTime)), this, SLOT(changeTime())); | 
					
						
							|  |  |  | 	connect(ui.backwards, SIGNAL(toggled(bool)), this, SLOT(changeTime())); | 
					
						
							| 
									
										
										
										
											2014-04-25 19:39:40 +02:00
										 |  |  | 	QShortcut *close = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_W), this); | 
					
						
							|  |  |  | 	connect(close, SIGNAL(activated()), this, SLOT(close())); | 
					
						
							|  |  |  | 	QShortcut *quit = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_Q), this); | 
					
						
							|  |  |  | 	connect(quit, SIGNAL(activated()), parent, SLOT(close())); | 
					
						
							| 
									
										
										
										
											2013-11-18 14:53:05 +01:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2014-01-27 14:44:26 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | void ShiftImageTimesDialog::buttonClicked(QAbstractButton *button) | 
					
						
							| 
									
										
										
										
											2014-01-27 14:44:26 +01:00
										 |  |  | { | 
					
						
							|  |  |  | 	if (ui.buttonBox->buttonRole(button) == QDialogButtonBox::AcceptRole) { | 
					
						
							| 
									
										
										
										
											2014-02-08 23:56:47 +01:00
										 |  |  | 		m_amount = ui.timeEdit->time().hour() * 3600 + ui.timeEdit->time().minute() * 60; | 
					
						
							| 
									
										
										
										
											2014-01-27 14:44:26 +01:00
										 |  |  | 		if (ui.backwards->isChecked()) | 
					
						
							| 
									
										
										
										
											2014-02-08 23:56:47 +01:00
										 |  |  | 			m_amount *= -1; | 
					
						
							| 
									
										
										
										
											2014-01-27 14:44:26 +01:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-13 16:43:55 +01:00
										 |  |  | void ShiftImageTimesDialog::syncCameraClicked() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct memblock mem; | 
					
						
							|  |  |  | 	EXIFInfo exiv; | 
					
						
							|  |  |  | 	int retval; | 
					
						
							|  |  |  | 	QPixmap picture; | 
					
						
							| 
									
										
										
										
											2014-02-18 07:50:35 +02:00
										 |  |  | 	QDateTime dcDateTime = QDateTime(); | 
					
						
							| 
									
										
										
										
											2014-02-13 16:43:55 +01:00
										 |  |  | 	QStringList fileNames = QFileDialog::getOpenFileNames(this, | 
					
						
							| 
									
										
										
										
											2014-07-11 18:39:03 +01:00
										 |  |  | 							      tr("Open image file"), | 
					
						
							| 
									
										
										
										
											2014-02-19 00:26:36 +01:00
										 |  |  | 							      DiveListView::lastUsedImageDir(), | 
					
						
							| 
									
										
										
										
											2014-07-11 18:39:03 +01:00
										 |  |  | 							      tr("Image files (*.jpg *.jpeg *.pnm *.tif *.tiff)")); | 
					
						
							| 
									
										
										
										
											2014-02-13 16:43:55 +01:00
										 |  |  | 	if (fileNames.isEmpty()) | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	picture.load(fileNames.at(0)); | 
					
						
							| 
									
										
										
										
											2014-02-19 11:34:54 +01:00
										 |  |  | 	ui.displayDC->setEnabled(true); | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | 	QGraphicsScene *scene = new QGraphicsScene(this); | 
					
						
							| 
									
										
										
										
											2014-02-13 16:43:55 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	scene->addPixmap(picture.scaled(ui.DCImage->size())); | 
					
						
							|  |  |  | 	ui.DCImage->setScene(scene); | 
					
						
							|  |  |  | 	if (readfile(fileNames.at(0).toUtf8().data(), &mem) <= 0) | 
					
						
							|  |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | 	retval = exiv.parseFrom((const unsigned char *)mem.buffer, (unsigned)mem.size); | 
					
						
							| 
									
										
										
										
											2014-02-13 16:43:55 +01:00
										 |  |  | 	free(mem.buffer); | 
					
						
							|  |  |  | 	if (retval != PARSE_EXIF_SUCCESS) | 
					
						
							|  |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2014-06-02 18:28:02 -03:00
										 |  |  | 	dcImageEpoch = exiv.epoch(); | 
					
						
							| 
									
										
										
										
											2014-02-13 16:43:55 +01:00
										 |  |  | 	dcDateTime.setTime_t(dcImageEpoch); | 
					
						
							|  |  |  | 	ui.dcTime->setDateTime(dcDateTime); | 
					
						
							|  |  |  | 	connect(ui.dcTime, SIGNAL(dateTimeChanged(const QDateTime &)), this, SLOT(dcDateTimeChanged(const QDateTime &))); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void ShiftImageTimesDialog::dcDateTimeChanged(const QDateTime &newDateTime) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if (!dcImageEpoch) | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 	setOffset(newDateTime.toTime_t() - dcImageEpoch); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | ShiftImageTimesDialog::ShiftImageTimesDialog(QWidget *parent) : QDialog(parent), m_amount(0) | 
					
						
							| 
									
										
										
										
											2014-01-27 14:44:26 +01:00
										 |  |  | { | 
					
						
							|  |  |  | 	ui.setupUi(this); | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | 	connect(ui.buttonBox, SIGNAL(clicked(QAbstractButton *)), this, SLOT(buttonClicked(QAbstractButton *))); | 
					
						
							| 
									
										
										
										
											2014-02-13 16:43:55 +01:00
										 |  |  | 	connect(ui.syncCamera, SIGNAL(clicked()), this, SLOT(syncCameraClicked())); | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | 	dcImageEpoch = (time_t)0; | 
					
						
							| 
									
										
										
										
											2014-01-27 14:44:26 +01:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2013-11-18 14:53:05 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-13 16:43:55 +01:00
										 |  |  | time_t ShiftImageTimesDialog::amount() const | 
					
						
							| 
									
										
										
										
											2014-02-08 23:56:47 +01:00
										 |  |  | { | 
					
						
							|  |  |  | 	return m_amount; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-13 16:43:55 +01:00
										 |  |  | void ShiftImageTimesDialog::setOffset(time_t offset) | 
					
						
							| 
									
										
										
										
											2014-02-12 16:46:17 +01:00
										 |  |  | { | 
					
						
							|  |  |  | 	if (offset >= 0) { | 
					
						
							| 
									
										
										
										
											2014-02-19 11:34:54 +01:00
										 |  |  | 		ui.forward->setChecked(true); | 
					
						
							| 
									
										
										
										
											2014-02-12 16:46:17 +01:00
										 |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											2014-02-19 11:34:54 +01:00
										 |  |  | 		ui.backwards->setChecked(true); | 
					
						
							| 
									
										
										
										
											2014-02-12 16:46:17 +01:00
										 |  |  | 		offset *= -1; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-02-18 07:50:35 +02:00
										 |  |  | 	ui.timeEdit->setTime(QTime(offset / 3600, (offset % 3600) / 60, offset % 60)); | 
					
						
							| 
									
										
										
										
											2014-02-12 16:46:17 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-09-27 12:52:01 -03: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-27 20:09:57 -08:00
										 |  |  | 	p.start("pidof", QStringList() << "gnome-shell"); | 
					
						
							| 
									
										
										
										
											2013-09-27 12:52:01 -03:00
										 |  |  | 	p.waitForFinished(-1); | 
					
						
							|  |  |  | 	QString p_stdout = p.readAllStandardOutput(); | 
					
						
							|  |  |  | 	return !p_stdout.isEmpty(); | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2014-06-19 13:42:49 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-19 15:42:05 -03:00
										 |  |  | DateWidget::DateWidget(QWidget *parent) : QWidget(parent), | 
					
						
							|  |  |  | 	calendarWidget(new QCalendarWidget()) | 
					
						
							| 
									
										
										
										
											2014-06-19 13:42:49 -03:00
										 |  |  | { | 
					
						
							|  |  |  | 	setDate(QDate::currentDate()); | 
					
						
							| 
									
										
										
										
											2014-09-17 15:39:49 -07:00
										 |  |  | 	setMinimumSize(QSize(80, 64)); | 
					
						
							| 
									
										
										
										
											2014-06-19 15:52:30 -03:00
										 |  |  | 	setFocusPolicy(Qt::StrongFocus); | 
					
						
							| 
									
										
										
										
											2014-06-30 18:20:17 -03:00
										 |  |  | 	calendarWidget->setWindowFlags(Qt::FramelessWindowHint); | 
					
						
							| 
									
										
										
										
											2014-06-28 08:35:59 -07:00
										 |  |  | 	calendarWidget->setFirstDayOfWeek(getLocale().firstDayOfWeek()); | 
					
						
							| 
									
										
										
										
											2014-06-28 08:41:10 -07:00
										 |  |  | 	calendarWidget->setVerticalHeaderFormat(QCalendarWidget::NoVerticalHeader); | 
					
						
							| 
									
										
										
										
											2014-06-19 15:42:05 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	connect(calendarWidget, SIGNAL(activated(QDate)), calendarWidget, SLOT(hide())); | 
					
						
							|  |  |  | 	connect(calendarWidget, SIGNAL(clicked(QDate)), calendarWidget, SLOT(hide())); | 
					
						
							|  |  |  | 	connect(calendarWidget, SIGNAL(activated(QDate)), this, SLOT(setDate(QDate))); | 
					
						
							|  |  |  | 	connect(calendarWidget, SIGNAL(clicked(QDate)), this, SLOT(setDate(QDate))); | 
					
						
							| 
									
										
										
										
											2014-06-30 18:20:17 -03:00
										 |  |  | 	calendarWidget->installEventFilter(this); | 
					
						
							| 
									
										
										
										
											2014-06-19 13:42:49 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-30 18:20:17 -03:00
										 |  |  | bool DateWidget::eventFilter(QObject *object, QEvent *event) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2014-09-17 15:39:49 -07:00
										 |  |  | 	if (event->type() == QEvent::FocusOut) { | 
					
						
							| 
									
										
										
										
											2014-06-30 18:20:17 -03:00
										 |  |  | 		calendarWidget->hide(); | 
					
						
							|  |  |  | 		return true; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-09-17 15:39:49 -07:00
										 |  |  | 	if (event->type() == QEvent::KeyPress) { | 
					
						
							|  |  |  | 		QKeyEvent *ev = static_cast<QKeyEvent *>(event); | 
					
						
							|  |  |  | 		if (ev->key() == Qt::Key_Escape) { | 
					
						
							| 
									
										
										
										
											2014-06-30 18:28:13 -03:00
										 |  |  | 			calendarWidget->hide(); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-06-30 18:20:17 -03:00
										 |  |  | 	return QObject::eventFilter(object, event); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-09-17 15:39:49 -07:00
										 |  |  | void DateWidget::setDate(const QDate &date) | 
					
						
							| 
									
										
										
										
											2014-06-19 13:42:49 -03:00
										 |  |  | { | 
					
						
							|  |  |  | 	mDate = date; | 
					
						
							|  |  |  | 	update(); | 
					
						
							| 
									
										
										
										
											2014-06-19 15:42:05 -03:00
										 |  |  | 	emit dateChanged(mDate); | 
					
						
							| 
									
										
										
										
											2014-06-19 13:42:49 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | QDate DateWidget::date() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return mDate; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-19 19:57:53 -03:00
										 |  |  | void DateWidget::changeEvent(QEvent *event) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2014-09-17 15:39:49 -07:00
										 |  |  | 	if (event->type() == QEvent::EnabledChange) { | 
					
						
							| 
									
										
										
										
											2014-06-19 19:57:53 -03:00
										 |  |  | 		update(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-26 16:14:44 -07:00
										 |  |  | #define DATEWIDGETWIDTH 80
 | 
					
						
							| 
									
										
										
										
											2014-06-19 13:42:49 -03:00
										 |  |  | void DateWidget::paintEvent(QPaintEvent *event) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2014-09-17 15:39:49 -07:00
										 |  |  | 	static QPixmap pix = QPixmap(":/calendar").scaled(DATEWIDGETWIDTH, 64); | 
					
						
							| 
									
										
										
										
											2014-06-19 13:42:49 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	QPainter painter(this); | 
					
						
							| 
									
										
										
										
											2014-06-19 18:45:26 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-09-17 15:39:49 -07:00
										 |  |  | 	painter.drawPixmap(QPoint(0, 0), isEnabled() ? pix : QPixmap::fromImage(grayImage(pix.toImage()))); | 
					
						
							| 
									
										
										
										
											2014-06-19 13:42:49 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	QString month = mDate.toString("MMM"); | 
					
						
							|  |  |  | 	QString year = mDate.toString("yyyy"); | 
					
						
							|  |  |  | 	QString day = mDate.toString("dd"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-26 16:14:44 -07:00
										 |  |  | 	QFont font = QFont("monospace", 10); | 
					
						
							| 
									
										
										
										
											2014-06-19 13:42:49 -03:00
										 |  |  | 	QFontMetrics metrics = QFontMetrics(font); | 
					
						
							|  |  |  | 	painter.setFont(font); | 
					
						
							|  |  |  | 	painter.setPen(QPen(QBrush(Qt::white), 0)); | 
					
						
							|  |  |  | 	painter.setBrush(QBrush(Qt::white)); | 
					
						
							| 
									
										
										
										
											2014-06-26 16:14:44 -07:00
										 |  |  | 	painter.drawText(QPoint(6, metrics.height() + 1), month); | 
					
						
							|  |  |  | 	painter.drawText(QPoint(DATEWIDGETWIDTH - metrics.width(year) - 6, metrics.height() + 1), year); | 
					
						
							| 
									
										
										
										
											2014-06-19 13:42:49 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	font.setPointSize(14); | 
					
						
							|  |  |  | 	metrics = QFontMetrics(font); | 
					
						
							| 
									
										
										
										
											2014-09-17 15:39:49 -07:00
										 |  |  | 	painter.setPen(QPen(QBrush(Qt::black), 0)); | 
					
						
							| 
									
										
										
										
											2014-06-19 13:42:49 -03:00
										 |  |  | 	painter.setBrush(Qt::black); | 
					
						
							|  |  |  | 	painter.setFont(font); | 
					
						
							| 
									
										
										
										
											2014-06-26 16:14:44 -07:00
										 |  |  | 	painter.drawText(QPoint(DATEWIDGETWIDTH / 2 - metrics.width(day) / 2, 45), day); | 
					
						
							| 
									
										
										
										
											2014-06-19 15:52:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-19 18:11:44 -03:00
										 |  |  | 	if (hasFocus()) { | 
					
						
							|  |  |  | 		QStyleOptionFocusRect option; | 
					
						
							|  |  |  | 		option.initFrom(this); | 
					
						
							|  |  |  | 		option.backgroundColor = palette().color(QPalette::Background); | 
					
						
							|  |  |  | 		style()->drawPrimitive(QStyle::PE_FrameFocusRect, &option, &painter, this); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-06-19 15:42:05 -03:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2014-06-19 13:42:49 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-19 15:42:05 -03:00
										 |  |  | void DateWidget::mousePressEvent(QMouseEvent *event) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2014-06-30 18:31:29 -03:00
										 |  |  | 	calendarWidget->setSelectedDate(mDate); | 
					
						
							| 
									
										
										
										
											2014-06-19 15:42:05 -03:00
										 |  |  | 	calendarWidget->move(event->globalPos()); | 
					
						
							|  |  |  | 	calendarWidget->show(); | 
					
						
							| 
									
										
										
										
											2014-06-30 18:20:17 -03:00
										 |  |  | 	calendarWidget->raise(); | 
					
						
							|  |  |  | 	calendarWidget->setFocus(); | 
					
						
							| 
									
										
										
										
											2014-06-19 13:42:49 -03:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2014-06-19 15:42:05 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-19 15:52:30 -03:00
										 |  |  | void DateWidget::focusInEvent(QFocusEvent *event) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	setFocus(); | 
					
						
							|  |  |  | 	QWidget::focusInEvent(event); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void DateWidget::focusOutEvent(QFocusEvent *event) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	QWidget::focusOutEvent(event); | 
					
						
							| 
									
										
										
										
											2014-06-19 15:58:27 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void DateWidget::keyPressEvent(QKeyEvent *event) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2014-09-17 15:39:49 -07:00
										 |  |  | 	if (event->key() == Qt::Key_Return || | 
					
						
							|  |  |  | 	    event->key() == Qt::Key_Enter || | 
					
						
							|  |  |  | 	    event->key() == Qt::Key_Space) { | 
					
						
							|  |  |  | 		calendarWidget->move(mapToGlobal(QPoint(0, 64))); | 
					
						
							| 
									
										
										
										
											2014-06-19 15:58:27 -03:00
										 |  |  | 		calendarWidget->show(); | 
					
						
							|  |  |  | 		event->setAccepted(true); | 
					
						
							| 
									
										
										
										
											2014-09-17 15:39:49 -07:00
										 |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											2014-06-19 15:58:27 -03:00
										 |  |  | 		QWidget::keyPressEvent(event); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2014-08-16 09:32:23 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | #define COMPONENT_FROM_UI(_component) what->_component = ui._component->isChecked()
 | 
					
						
							|  |  |  | #define UI_FROM_COMPONENT(_component) ui._component->setChecked(what->_component)
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-09-17 15:39:49 -07:00
										 |  |  | DiveComponentSelection::DiveComponentSelection(QWidget *parent, struct dive *target, struct dive_components *_what) : targetDive(target) | 
					
						
							| 
									
										
										
										
											2014-08-16 09:32:23 -06:00
										 |  |  | { | 
					
						
							|  |  |  | 	ui.setupUi(this); | 
					
						
							|  |  |  | 	what = _what; | 
					
						
							|  |  |  | 	UI_FROM_COMPONENT(location); | 
					
						
							|  |  |  | 	UI_FROM_COMPONENT(gps); | 
					
						
							|  |  |  | 	UI_FROM_COMPONENT(divemaster); | 
					
						
							|  |  |  | 	UI_FROM_COMPONENT(buddy); | 
					
						
							|  |  |  | 	UI_FROM_COMPONENT(rating); | 
					
						
							|  |  |  | 	UI_FROM_COMPONENT(visibility); | 
					
						
							|  |  |  | 	UI_FROM_COMPONENT(notes); | 
					
						
							|  |  |  | 	UI_FROM_COMPONENT(suit); | 
					
						
							| 
									
										
										
										
											2014-08-16 18:35:44 -06:00
										 |  |  | 	UI_FROM_COMPONENT(tags); | 
					
						
							| 
									
										
										
										
											2014-08-16 09:32:23 -06:00
										 |  |  | 	UI_FROM_COMPONENT(cylinders); | 
					
						
							|  |  |  | 	UI_FROM_COMPONENT(weights); | 
					
						
							|  |  |  | 	connect(ui.buttonBox, SIGNAL(clicked(QAbstractButton *)), this, SLOT(buttonClicked(QAbstractButton *))); | 
					
						
							|  |  |  | 	QShortcut *close = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_W), this); | 
					
						
							|  |  |  | 	connect(close, SIGNAL(activated()), this, SLOT(close())); | 
					
						
							|  |  |  | 	QShortcut *quit = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_Q), this); | 
					
						
							|  |  |  | 	connect(quit, SIGNAL(activated()), parent, SLOT(close())); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void DiveComponentSelection::buttonClicked(QAbstractButton *button) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if (ui.buttonBox->buttonRole(button) == QDialogButtonBox::AcceptRole) { | 
					
						
							|  |  |  | 		COMPONENT_FROM_UI(location); | 
					
						
							|  |  |  | 		COMPONENT_FROM_UI(gps); | 
					
						
							|  |  |  | 		COMPONENT_FROM_UI(divemaster); | 
					
						
							|  |  |  | 		COMPONENT_FROM_UI(buddy); | 
					
						
							|  |  |  | 		COMPONENT_FROM_UI(rating); | 
					
						
							|  |  |  | 		COMPONENT_FROM_UI(visibility); | 
					
						
							|  |  |  | 		COMPONENT_FROM_UI(notes); | 
					
						
							|  |  |  | 		COMPONENT_FROM_UI(suit); | 
					
						
							| 
									
										
										
										
											2014-08-16 18:35:44 -06:00
										 |  |  | 		COMPONENT_FROM_UI(tags); | 
					
						
							| 
									
										
										
										
											2014-08-16 09:32:23 -06:00
										 |  |  | 		COMPONENT_FROM_UI(cylinders); | 
					
						
							|  |  |  | 		COMPONENT_FROM_UI(weights); | 
					
						
							| 
									
										
										
										
											2014-08-16 18:33:09 -06:00
										 |  |  | 		selective_copy_dive(&displayed_dive, targetDive, *what, true); | 
					
						
							| 
									
										
										
										
											2014-08-16 09:32:23 -06:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2014-09-17 14:17:41 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-09-17 15:39:49 -07:00
										 |  |  | TagFilter::TagFilter(QWidget *parent) : QWidget(parent) | 
					
						
							| 
									
										
										
										
											2014-09-17 14:17:41 -03:00
										 |  |  | { | 
					
						
							|  |  |  | 	ui.setupUi(this); | 
					
						
							| 
									
										
										
										
											2014-10-31 15:40:57 -02:00
										 |  |  | 	ui.label->setText(tr("Tags: ")); | 
					
						
							| 
									
										
										
										
											2014-10-31 16:01:28 -02:00
										 |  |  | #if QT_VERSION >= 0x050000
 | 
					
						
							|  |  |  | 	ui.filterInternalList->setClearButtonEnabled(true); | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2014-09-17 15:45:18 -03:00
										 |  |  | 	QSortFilterProxyModel *filter = new QSortFilterProxyModel(); | 
					
						
							|  |  |  | 	filter->setSourceModel(TagFilterModel::instance()); | 
					
						
							| 
									
										
										
										
											2014-12-09 21:23:12 -07:00
										 |  |  | 	filter->setFilterCaseSensitivity(Qt::CaseInsensitive); | 
					
						
							| 
									
										
										
										
											2014-10-31 15:40:57 -02:00
										 |  |  | 	connect(ui.filterInternalList, SIGNAL(textChanged(QString)), filter, SLOT(setFilterFixedString(QString))); | 
					
						
							|  |  |  | 	ui.filterList->setModel(filter); | 
					
						
							| 
									
										
										
										
											2014-09-17 14:17:41 -03:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2014-10-01 16:23:02 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | void TagFilter::showEvent(QShowEvent *event) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2014-10-31 15:27:33 -02:00
										 |  |  | 	MultiFilterSortModel::instance()->addFilterModel(TagFilterModel::instance()); | 
					
						
							| 
									
										
										
										
											2014-10-01 16:23:02 -03:00
										 |  |  | 	QWidget::showEvent(event); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void TagFilter::hideEvent(QHideEvent *event) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2014-10-31 15:27:33 -02:00
										 |  |  | 	MultiFilterSortModel::instance()->removeFilterModel(TagFilterModel::instance()); | 
					
						
							| 
									
										
										
										
											2014-10-01 16:23:02 -03:00
										 |  |  | 	QWidget::hideEvent(event); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2014-10-31 15:22:21 -02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-10-31 16:49:52 -02:00
										 |  |  | BuddyFilter::BuddyFilter(QWidget *parent) : QWidget(parent) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	ui.setupUi(this); | 
					
						
							| 
									
										
										
										
											2014-10-31 17:13:09 -02:00
										 |  |  | 	ui.label->setText(tr("Person: ")); | 
					
						
							| 
									
										
										
										
											2014-11-01 00:07:15 +00:00
										 |  |  | 	ui.label->setToolTip(tr("Searches for buddies and divemasters")); | 
					
						
							| 
									
										
										
										
											2014-10-31 16:49:52 -02:00
										 |  |  | #if QT_VERSION >= 0x050000
 | 
					
						
							|  |  |  | 	ui.filterInternalList->setClearButtonEnabled(true); | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 	QSortFilterProxyModel *filter = new QSortFilterProxyModel(); | 
					
						
							|  |  |  | 	filter->setSourceModel(BuddyFilterModel::instance()); | 
					
						
							| 
									
										
										
										
											2014-12-09 21:23:12 -07:00
										 |  |  | 	filter->setFilterCaseSensitivity(Qt::CaseInsensitive); | 
					
						
							| 
									
										
										
										
											2014-10-31 16:49:52 -02:00
										 |  |  | 	connect(ui.filterInternalList, SIGNAL(textChanged(QString)), filter, SLOT(setFilterFixedString(QString))); | 
					
						
							|  |  |  | 	ui.filterList->setModel(filter); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void BuddyFilter::showEvent(QShowEvent *event) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	MultiFilterSortModel::instance()->addFilterModel(BuddyFilterModel::instance()); | 
					
						
							|  |  |  | 	QWidget::showEvent(event); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void BuddyFilter::hideEvent(QHideEvent *event) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	MultiFilterSortModel::instance()->removeFilterModel(BuddyFilterModel::instance()); | 
					
						
							|  |  |  | 	QWidget::hideEvent(event); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-10-31 17:45:39 -02:00
										 |  |  | LocationFilter::LocationFilter(QWidget *parent) : QWidget(parent) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	ui.setupUi(this); | 
					
						
							|  |  |  | 	ui.label->setText(tr("Location: ")); | 
					
						
							|  |  |  | #if QT_VERSION >= 0x050000
 | 
					
						
							|  |  |  | 	ui.filterInternalList->setClearButtonEnabled(true); | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 	QSortFilterProxyModel *filter = new QSortFilterProxyModel(); | 
					
						
							| 
									
										
										
										
											2014-10-31 17:48:44 -02:00
										 |  |  | 	filter->setSourceModel(LocationFilterModel::instance()); | 
					
						
							| 
									
										
										
										
											2014-12-09 21:23:12 -07:00
										 |  |  | 	filter->setFilterCaseSensitivity(Qt::CaseInsensitive); | 
					
						
							| 
									
										
										
										
											2014-10-31 17:45:39 -02:00
										 |  |  | 	connect(ui.filterInternalList, SIGNAL(textChanged(QString)), filter, SLOT(setFilterFixedString(QString))); | 
					
						
							|  |  |  | 	ui.filterList->setModel(filter); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void LocationFilter::showEvent(QShowEvent *event) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	MultiFilterSortModel::instance()->addFilterModel(LocationFilterModel::instance()); | 
					
						
							|  |  |  | 	QWidget::showEvent(event); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void LocationFilter::hideEvent(QHideEvent *event) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	MultiFilterSortModel::instance()->removeFilterModel(LocationFilterModel::instance()); | 
					
						
							|  |  |  | 	QWidget::hideEvent(event); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2014-11-11 16:07:45 -02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-11-13 17:32:17 -02:00
										 |  |  | SuitFilter::SuitFilter(QWidget *parent) : QWidget(parent) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	ui.setupUi(this); | 
					
						
							|  |  |  | 	ui.label->setText(tr("Suits: ")); | 
					
						
							|  |  |  | #if QT_VERSION >= 0x050000
 | 
					
						
							|  |  |  | 	ui.filterInternalList->setClearButtonEnabled(true); | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 	QSortFilterProxyModel *filter = new QSortFilterProxyModel(); | 
					
						
							|  |  |  | 	filter->setSourceModel(SuitsFilterModel::instance()); | 
					
						
							| 
									
										
										
										
											2014-12-09 21:23:12 -07:00
										 |  |  | 	filter->setFilterCaseSensitivity(Qt::CaseInsensitive); | 
					
						
							| 
									
										
										
										
											2014-11-13 17:32:17 -02:00
										 |  |  | 	connect(ui.filterInternalList, SIGNAL(textChanged(QString)), filter, SLOT(setFilterFixedString(QString))); | 
					
						
							|  |  |  | 	ui.filterList->setModel(filter); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void SuitFilter::showEvent(QShowEvent *event) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	MultiFilterSortModel::instance()->addFilterModel(SuitsFilterModel::instance()); | 
					
						
							|  |  |  | 	QWidget::showEvent(event); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void SuitFilter::hideEvent(QHideEvent *event) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	MultiFilterSortModel::instance()->removeFilterModel(SuitsFilterModel::instance()); | 
					
						
							|  |  |  | 	QWidget::hideEvent(event); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-11-16 14:04:06 -02:00
										 |  |  | MultiFilter::MultiFilter(QWidget *parent) : QWidget(parent) | 
					
						
							| 
									
										
										
										
											2014-10-31 15:22:21 -02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2014-12-18 08:47:52 +01:00
										 |  |  | 	ui.setupUi(this); | 
					
						
							| 
									
										
										
										
											2014-11-16 14:04:06 -02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-11-11 17:06:28 -02:00
										 |  |  | 	QWidget *expandedWidget = new QWidget(); | 
					
						
							| 
									
										
										
										
											2014-10-31 15:22:21 -02:00
										 |  |  | 	QHBoxLayout *l = new QHBoxLayout(); | 
					
						
							| 
									
										
										
										
											2014-11-11 16:07:45 -02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-12-18 10:47:00 -08:00
										 |  |  | 	TagFilter *tagFilter = new TagFilter(this); | 
					
						
							| 
									
										
										
										
											2014-11-03 17:39:31 -02:00
										 |  |  | 	int minimumHeight = tagFilter->ui.filterInternalList->height() + | 
					
						
							| 
									
										
										
										
											2014-11-16 14:04:06 -02:00
										 |  |  | 			tagFilter->ui.verticalLayout->spacing() * tagFilter->ui.verticalLayout->count(); | 
					
						
							| 
									
										
										
										
											2014-11-03 17:39:31 -02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	QListView *dummyList = new QListView(); | 
					
						
							|  |  |  | 	QStringListModel *dummy = new QStringListModel(QStringList() << "Dummy Text"); | 
					
						
							|  |  |  | 	dummyList->setModel(dummy); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-12-18 08:47:52 +01:00
										 |  |  | 	connect(ui.close, SIGNAL(clicked(bool)), this, SLOT(closeFilter())); | 
					
						
							|  |  |  | 	connect(ui.clear, SIGNAL(clicked(bool)), MultiFilterSortModel::instance(), SLOT(clearFilter())); | 
					
						
							|  |  |  | 	connect(ui.maximize, SIGNAL(clicked(bool)), this, SLOT(adjustHeight())); | 
					
						
							| 
									
										
										
										
											2014-11-16 14:04:06 -02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-11-03 17:39:31 -02:00
										 |  |  | 	l->addWidget(tagFilter); | 
					
						
							| 
									
										
										
										
											2014-10-31 16:49:52 -02:00
										 |  |  | 	l->addWidget(new BuddyFilter()); | 
					
						
							| 
									
										
										
										
											2014-10-31 17:48:44 -02:00
										 |  |  | 	l->addWidget(new LocationFilter()); | 
					
						
							| 
									
										
										
										
											2014-11-13 17:32:17 -02:00
										 |  |  | 	l->addWidget(new SuitFilter()); | 
					
						
							| 
									
										
										
										
											2014-10-31 14:28:39 -07:00
										 |  |  | 	l->setContentsMargins(0, 0, 0, 0); | 
					
						
							| 
									
										
										
										
											2014-11-03 17:39:31 -02:00
										 |  |  | 	l->setSpacing(0); | 
					
						
							| 
									
										
										
										
											2014-11-11 17:06:28 -02:00
										 |  |  | 	expandedWidget->setLayout(l); | 
					
						
							| 
									
										
										
										
											2014-11-16 14:04:06 -02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-12-18 08:47:52 +01:00
										 |  |  | 	ui.scrollArea->setWidget(expandedWidget); | 
					
						
							| 
									
										
										
										
											2014-11-11 17:06:28 -02:00
										 |  |  | 	expandedWidget->resize(expandedWidget->width(), minimumHeight + dummyList->sizeHintForRow(0) * 5 ); | 
					
						
							| 
									
										
										
										
											2014-12-18 08:47:52 +01:00
										 |  |  | 	ui.scrollArea->setMinimumHeight(expandedWidget->height() + 5); | 
					
						
							| 
									
										
										
										
											2014-11-03 17:39:31 -02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-11-16 14:04:06 -02:00
										 |  |  | 	connect(MultiFilterSortModel::instance(), SIGNAL(filterFinished()), this, SLOT(filterFinished())); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void MultiFilter::filterFinished() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2014-12-18 08:47:52 +01:00
										 |  |  | 	ui.filterText->setText(tr("Filter shows %1 (of %2) dives").arg(MultiFilterSortModel::instance()->divesDisplayed).arg(dive_table.nr)); | 
					
						
							| 
									
										
										
										
											2014-11-16 14:04:06 -02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void MultiFilter::adjustHeight() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2014-12-18 08:47:52 +01:00
										 |  |  | 	ui.scrollArea->setVisible(!ui.scrollArea->isVisible()); | 
					
						
							| 
									
										
										
										
											2014-10-31 15:22:21 -02:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2014-11-13 13:45:32 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  | void MultiFilter::closeFilter() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	MultiFilterSortModel::instance()->clearFilter(); | 
					
						
							|  |  |  | 	hide(); | 
					
						
							|  |  |  | } |