2017-04-27 18:26:05 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2016-04-05 05:02:03 +00:00
|
|
|
#include "desktop-widgets/simplewidgets.h"
|
|
|
|
#include "qt-models/filtermodels.h"
|
2013-06-04 21:51:27 +00:00
|
|
|
|
2013-09-27 15:52:01 +00:00
|
|
|
#include <QProcess>
|
2014-02-13 15:43:55 +00:00
|
|
|
#include <QFileDialog>
|
2014-04-25 17:39:40 +00:00
|
|
|
#include <QShortcut>
|
2014-06-19 18:42:05 +00:00
|
|
|
#include <QCalendarWidget>
|
2015-02-09 20:58:40 +00:00
|
|
|
#include <QKeyEvent>
|
2015-02-11 15:58:23 +00:00
|
|
|
#include <QAction>
|
2015-11-16 04:56:24 +00:00
|
|
|
#include <QDesktopServices>
|
|
|
|
#include <QToolTip>
|
2015-01-17 09:43:52 +00:00
|
|
|
|
2016-04-05 05:02:03 +00:00
|
|
|
#include "core/file.h"
|
|
|
|
#include "desktop-widgets/mainwindow.h"
|
2018-06-03 20:15:19 +00:00
|
|
|
#include "core/qthelper.h"
|
2014-11-25 20:22:02 +00:00
|
|
|
#include "libdivecomputer/parser.h"
|
2016-04-05 05:02:03 +00:00
|
|
|
#include "desktop-widgets/divelistview.h"
|
|
|
|
#include "core/display.h"
|
2015-09-03 18:56:37 +00:00
|
|
|
#include "profile-widget/profilewidget2.h"
|
2016-04-05 05:02:03 +00:00
|
|
|
#include "desktop-widgets/undocommands.h"
|
2018-03-15 19:21:40 +00:00
|
|
|
#include "core/metadata.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);
|
2017-11-29 09:57:08 +00:00
|
|
|
avgIco->setPixmap(QIcon(":value-average-icon").pixmap(16, 16));
|
2018-07-03 14:52:20 +00:00
|
|
|
avgIco->setToolTip(gettextFromC::tr("Average"));
|
2013-06-04 21:51:27 +00:00
|
|
|
minIco = new QLabel(owner);
|
2017-11-29 09:57:08 +00:00
|
|
|
minIco->setPixmap(QIcon(":value-minimum-icon").pixmap(16, 16));
|
2018-07-03 14:52:20 +00:00
|
|
|
minIco->setToolTip(gettextFromC::tr("Minimum"));
|
2013-06-04 21:51:27 +00:00
|
|
|
maxIco = new QLabel(owner);
|
2017-11-29 09:57:08 +00:00
|
|
|
maxIco->setPixmap(QIcon(":value-maximum-icon").pixmap(16, 16));
|
2018-07-03 14:52:20 +00:00
|
|
|
maxIco->setToolTip(gettextFromC::tr("Maximum"));
|
2013-06-04 21:51:27 +00:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2018-05-21 16:09:09 +00:00
|
|
|
MinMaxAvgWidget::MinMaxAvgWidget(QWidget*) : 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-05-30 22:46:55 +00: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 22:46:55 +00: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 22:46:55 +00:00
|
|
|
}
|
|
|
|
|
2017-01-10 15:56:55 +00:00
|
|
|
void MinMaxAvgWidget::setAvgVisibility(const bool visible)
|
|
|
|
{
|
|
|
|
d->avgIco->setVisible(visible);
|
|
|
|
d->avgValue->setVisible(visible);
|
|
|
|
}
|
|
|
|
|
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-05-19 21:11:32 +00:00
|
|
|
void RenumberDialog::renumberOnlySelected(bool selected)
|
|
|
|
{
|
|
|
|
if (selected && amount_selected == 1)
|
2016-12-27 21:10:18 +00:00
|
|
|
ui.renumberText->setText(tr("New number"));
|
2014-05-19 21:11:32 +00:00
|
|
|
else
|
2016-12-27 21:10:18 +00:00
|
|
|
ui.renumberText->setText(tr("New starting number"));
|
|
|
|
|
|
|
|
if (selected)
|
|
|
|
ui.groupBox->setTitle(tr("Renumber selected dives"));
|
|
|
|
else
|
|
|
|
ui.groupBox->setTitle(tr("Renumber all dives"));
|
|
|
|
|
2014-05-19 21:11:32 +00:00
|
|
|
selectedOnly = selected;
|
|
|
|
}
|
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
void RenumberDialog::buttonClicked(QAbstractButton *button)
|
2013-06-17 16:41:00 +00:00
|
|
|
{
|
2015-02-28 04:42:37 +00:00
|
|
|
if (ui.buttonBox->buttonRole(button) == QDialogButtonBox::AcceptRole) {
|
2015-08-19 16:58:08 +00:00
|
|
|
MainWindow::instance()->dive_list()->rememberSelection();
|
2015-06-15 04:49:34 +00:00
|
|
|
// we remember a map from dive uuid to a pair of old number / new number
|
2017-12-24 16:39:21 +00:00
|
|
|
QMap<int, QPair<int, int>> renumberedDives;
|
2015-02-28 04:42:37 +00:00
|
|
|
int i;
|
2015-06-15 04:49:34 +00:00
|
|
|
int newNr = ui.spinBox->value();
|
2015-02-28 04:42:37 +00:00
|
|
|
struct dive *dive = NULL;
|
|
|
|
for_each_dive (i, dive) {
|
2016-04-03 22:31:59 +00:00
|
|
|
if (!selectedOnly || dive->selected) {
|
|
|
|
invalidate_dive_cache(dive);
|
2017-12-24 16:39:21 +00:00
|
|
|
renumberedDives.insert(dive->id, QPair<int, int>(dive->number, newNr++));
|
2016-04-03 22:31:59 +00:00
|
|
|
}
|
2015-02-28 04:42:37 +00:00
|
|
|
}
|
2015-06-15 04:49:34 +00:00
|
|
|
UndoRenumberDives *undoCommand = new UndoRenumberDives(renumberedDives);
|
2015-02-28 04:42:37 +00:00
|
|
|
MainWindow::instance()->undoStack->push(undoCommand);
|
2015-08-19 16:58:08 +00:00
|
|
|
|
|
|
|
mark_divelist_changed(true);
|
|
|
|
MainWindow::instance()->dive_list()->restoreSelection();
|
2015-02-28 04:42:37 +00:00
|
|
|
}
|
2013-06-17 16:41:00 +00:00
|
|
|
}
|
|
|
|
|
2014-05-19 21:11:32 +00:00
|
|
|
RenumberDialog::RenumberDialog(QWidget *parent) : QDialog(parent), selectedOnly(false)
|
2014-11-25 20:22:02 +00: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 22:33:16 +00:00
|
|
|
time = second < 0 ? 0 : second;
|
2014-11-25 20:22:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SetpointDialog::buttonClicked(QAbstractButton *button)
|
|
|
|
{
|
2016-04-03 22:31:59 +00:00
|
|
|
if (ui.buttonBox->buttonRole(button) == QDialogButtonBox::AcceptRole && dc) {
|
2017-02-21 17:04:00 +00:00
|
|
|
add_event(dc, time, SAMPLE_EVENT_PO2, 0, (int)(1000.0 * ui.spinbox->value()),
|
|
|
|
QT_TRANSLATE_NOOP("gettextFromC", "SP change"));
|
2016-04-03 22:31:59 +00:00
|
|
|
invalidate_dive_cache(current_dive);
|
|
|
|
}
|
2014-11-26 13:22:41 +00:00
|
|
|
mark_divelist_changed(true);
|
|
|
|
MainWindow::instance()->graphics()->replot();
|
2014-11-25 20:22:02 +00:00
|
|
|
}
|
|
|
|
|
2017-12-24 16:39:21 +00:00
|
|
|
SetpointDialog::SetpointDialog(QWidget *parent) : QDialog(parent),
|
2017-12-28 18:32:05 +00:00
|
|
|
dc(0), time(0)
|
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 *)));
|
2014-04-25 18:32:02 +00: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 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...
|
2015-02-14 17:12:05 +00:00
|
|
|
int i;
|
|
|
|
struct dive *dive;
|
|
|
|
QList<int> affectedDives;
|
|
|
|
for_each_dive (i, dive) {
|
|
|
|
if (!dive->selected)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
affectedDives.append(dive->id);
|
|
|
|
}
|
|
|
|
MainWindow::instance()->undoStack->push(new UndoShiftTime(affectedDives, amount));
|
2013-11-18 18:00:39 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-21 16:09:09 +00:00
|
|
|
void ShiftTimesDialog::showEvent(QShowEvent*)
|
2014-03-20 20:57:49 +00:00
|
|
|
{
|
|
|
|
ui.timeEdit->setTime(QTime(0, 0, 0, 0));
|
2014-05-22 18:40:22 +00:00
|
|
|
when = get_times(); //get time of first selected dive
|
2014-03-20 20:57:49 +00: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 18:40:22 +00:00
|
|
|
ui.shiftedTime->setText(get_dive_date_string(amount + when));
|
2014-03-20 20:57:49 +00:00
|
|
|
}
|
|
|
|
|
2017-12-24 16:39:21 +00:00
|
|
|
ShiftTimesDialog::ShiftTimesDialog(QWidget *parent) : QDialog(parent),
|
2015-06-22 05:19:59 +00:00
|
|
|
when(0)
|
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()));
|
2014-04-25 17:39:40 +00: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 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()
|
|
|
|
{
|
|
|
|
QPixmap picture;
|
|
|
|
QStringList fileNames = QFileDialog::getOpenFileNames(this,
|
2014-07-11 17:39:03 +00:00
|
|
|
tr("Open image file"),
|
2014-02-18 23:26:36 +00:00
|
|
|
DiveListView::lastUsedImageDir(),
|
2017-10-27 12:52:27 +00:00
|
|
|
tr("Image files") + " (*.jpg *.jpeg)");
|
2014-02-13 15:43:55 +00:00
|
|
|
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);
|
2015-03-14 14:35:47 +00:00
|
|
|
|
2018-02-25 12:51:41 +00:00
|
|
|
dcImageEpoch = picture_get_timestamp(qPrintable(fileNames.at(0)));
|
2016-06-22 20:46:22 +00:00
|
|
|
QDateTime dcDateTime = QDateTime::fromTime_t(dcImageEpoch, Qt::UTC);
|
2014-02-13 15:43:55 +00:00
|
|
|
ui.dcTime->setDateTime(dcDateTime);
|
|
|
|
connect(ui.dcTime, SIGNAL(dateTimeChanged(const QDateTime &)), this, SLOT(dcDateTimeChanged(const QDateTime &)));
|
|
|
|
}
|
|
|
|
|
|
|
|
void ShiftImageTimesDialog::dcDateTimeChanged(const QDateTime &newDateTime)
|
|
|
|
{
|
2015-09-21 15:46:17 +00:00
|
|
|
QDateTime newtime(newDateTime);
|
2014-02-13 15:43:55 +00:00
|
|
|
if (!dcImageEpoch)
|
|
|
|
return;
|
2015-09-21 15:46:17 +00:00
|
|
|
newtime.setTimeSpec(Qt::UTC);
|
2015-10-21 13:52:09 +00:00
|
|
|
setOffset(newtime.toTime_t() - dcImageEpoch);
|
2014-02-13 15:43:55 +00:00
|
|
|
}
|
|
|
|
|
2015-09-11 09:31:02 +00:00
|
|
|
void ShiftImageTimesDialog::matchAllImagesToggled(bool state)
|
|
|
|
{
|
|
|
|
matchAllImages = state;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ShiftImageTimesDialog::matchAll()
|
|
|
|
{
|
|
|
|
return matchAllImages;
|
|
|
|
}
|
|
|
|
|
2017-12-24 16:39:21 +00:00
|
|
|
ShiftImageTimesDialog::ShiftImageTimesDialog(QWidget *parent, QStringList fileNames) : QDialog(parent),
|
2015-10-02 02:02:26 +00:00
|
|
|
fileNames(fileNames),
|
|
|
|
m_amount(0),
|
|
|
|
matchAllImages(false)
|
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()));
|
2015-03-14 16:44:24 +00:00
|
|
|
connect(ui.timeEdit, SIGNAL(timeChanged(const QTime &)), this, SLOT(timeEditChanged(const QTime &)));
|
2017-04-30 20:24:08 +00:00
|
|
|
connect(ui.backwards, SIGNAL(toggled(bool)), this, SLOT(timeEditChanged()));
|
2015-09-11 09:31:02 +00:00
|
|
|
connect(ui.matchAllImages, SIGNAL(toggled(bool)), this, SLOT(matchAllImagesToggled(bool)));
|
2014-02-28 04:09:57 +00:00
|
|
|
dcImageEpoch = (time_t)0;
|
2017-12-24 16:39:21 +00:00
|
|
|
|
2017-04-30 20:24:08 +00:00
|
|
|
updateInvalid();
|
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
|
|
|
}
|
|
|
|
|
2015-03-14 16:44:24 +00:00
|
|
|
void ShiftImageTimesDialog::updateInvalid()
|
|
|
|
{
|
|
|
|
timestamp_t timestamp;
|
|
|
|
bool allValid = true;
|
|
|
|
ui.warningLabel->hide();
|
2017-04-30 18:31:56 +00:00
|
|
|
ui.invalidFilesText->hide();
|
2017-04-30 20:24:08 +00:00
|
|
|
QDateTime time_first = QDateTime::fromTime_t(first_selected_dive()->when, Qt::UTC);
|
|
|
|
QDateTime time_last = QDateTime::fromTime_t(last_selected_dive()->when, Qt::UTC);
|
|
|
|
if (first_selected_dive() == last_selected_dive())
|
|
|
|
ui.invalidFilesText->setPlainText(tr("Selected dive date/time") + ": " + time_first.toString());
|
|
|
|
else {
|
|
|
|
ui.invalidFilesText->setPlainText(tr("First selected dive date/time") + ": " + time_first.toString());
|
|
|
|
ui.invalidFilesText->append(tr("Last selected dive date/time") + ": " + time_last.toString());
|
|
|
|
}
|
|
|
|
ui.invalidFilesText->append(tr("\nFiles with inappropriate date/time") + ":");
|
2015-03-14 16:44:24 +00:00
|
|
|
|
|
|
|
Q_FOREACH (const QString &fileName, fileNames) {
|
2018-02-25 12:51:41 +00:00
|
|
|
if (picture_check_valid(qPrintable(fileName), m_amount))
|
2015-03-14 16:44:24 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
// We've found invalid image
|
2018-02-25 12:51:41 +00:00
|
|
|
timestamp = picture_get_timestamp(qPrintable(fileName));
|
2017-04-30 20:24:08 +00:00
|
|
|
time_first.setTime_t(timestamp + m_amount);
|
2017-05-05 16:50:51 +00:00
|
|
|
if (timestamp == 0)
|
|
|
|
ui.invalidFilesText->append(fileName + " - " + tr("No Exif date/time found"));
|
|
|
|
else
|
|
|
|
ui.invalidFilesText->append(fileName + " - " + time_first.toString());
|
2015-03-14 16:44:24 +00:00
|
|
|
allValid = false;
|
|
|
|
}
|
|
|
|
|
2017-12-24 16:39:21 +00:00
|
|
|
if (!allValid) {
|
2015-03-14 16:44:24 +00:00
|
|
|
ui.warningLabel->show();
|
2017-04-30 18:31:56 +00:00
|
|
|
ui.invalidFilesText->show();
|
2015-03-14 16:44:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ShiftImageTimesDialog::timeEditChanged(const QTime &time)
|
|
|
|
{
|
2018-06-17 18:22:55 +00:00
|
|
|
QDateTimeEdit::Section timeEditSection = ui.timeEdit->currentSection();
|
|
|
|
ui.timeEdit->setEnabled(false);
|
2015-03-14 16:44:24 +00:00
|
|
|
m_amount = time.hour() * 3600 + time.minute() * 60;
|
|
|
|
if (ui.backwards->isChecked())
|
2017-12-24 16:39:21 +00:00
|
|
|
m_amount *= -1;
|
2015-03-14 16:44:24 +00:00
|
|
|
updateInvalid();
|
2018-06-17 18:22:55 +00:00
|
|
|
ui.timeEdit->setEnabled(true);
|
|
|
|
ui.timeEdit->setFocus();
|
|
|
|
ui.timeEdit->setSelectedSection(timeEditSection);
|
2015-03-14 16:44:24 +00:00
|
|
|
}
|
|
|
|
|
2017-04-30 20:24:08 +00:00
|
|
|
void ShiftImageTimesDialog::timeEditChanged()
|
|
|
|
{
|
2017-06-10 20:02:23 +00:00
|
|
|
if ((m_amount > 0) == ui.backwards->isChecked())
|
2017-12-24 16:39:21 +00:00
|
|
|
m_amount *= -1;
|
|
|
|
if (m_amount)
|
|
|
|
updateInvalid();
|
2017-04-30 20:24:08 +00:00
|
|
|
}
|
|
|
|
|
2015-04-24 15:10:55 +00:00
|
|
|
URLDialog::URLDialog(QWidget *parent) : QDialog(parent)
|
|
|
|
{
|
|
|
|
ui.setupUi(this);
|
|
|
|
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()));
|
|
|
|
}
|
|
|
|
|
|
|
|
QString URLDialog::url() const
|
|
|
|
{
|
2017-01-11 09:25:07 +00:00
|
|
|
return ui.urlField->text();
|
2015-04-24 15:10:55 +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
|
|
|
|
}
|
2014-06-19 16:42:49 +00:00
|
|
|
|
2014-08-16 15:32:23 +00:00
|
|
|
#define COMPONENT_FROM_UI(_component) what->_component = ui._component->isChecked()
|
|
|
|
#define UI_FROM_COMPONENT(_component) ui._component->setChecked(what->_component)
|
|
|
|
|
2014-09-17 22:39:49 +00:00
|
|
|
DiveComponentSelection::DiveComponentSelection(QWidget *parent, struct dive *target, struct dive_components *_what) : targetDive(target)
|
2014-08-16 15:32:23 +00:00
|
|
|
{
|
|
|
|
ui.setupUi(this);
|
|
|
|
what = _what;
|
2015-02-13 04:58:03 +00:00
|
|
|
UI_FROM_COMPONENT(divesite);
|
2014-08-16 15:32:23 +00:00
|
|
|
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-17 00:35:44 +00:00
|
|
|
UI_FROM_COMPONENT(tags);
|
2014-08-16 15:32:23 +00: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) {
|
2015-02-13 04:58:03 +00:00
|
|
|
COMPONENT_FROM_UI(divesite);
|
2014-08-16 15:32:23 +00:00
|
|
|
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-17 00:35:44 +00:00
|
|
|
COMPONENT_FROM_UI(tags);
|
2014-08-16 15:32:23 +00:00
|
|
|
COMPONENT_FROM_UI(cylinders);
|
|
|
|
COMPONENT_FROM_UI(weights);
|
2014-08-17 00:33:09 +00:00
|
|
|
selective_copy_dive(&displayed_dive, targetDive, *what, true);
|
2014-08-16 15:32:23 +00:00
|
|
|
}
|
|
|
|
}
|
2014-09-17 17:17:41 +00:00
|
|
|
|
2017-12-24 13:34:53 +00:00
|
|
|
void FilterBase::addContextMenuEntry(const QString &s, void (FilterModelBase::*fn)())
|
|
|
|
{
|
|
|
|
QAction *act = new QAction(s, this);
|
|
|
|
connect(act, &QAction::triggered, model, fn);
|
|
|
|
ui.filterList->addAction(act);
|
|
|
|
}
|
|
|
|
|
2017-12-24 16:39:21 +00:00
|
|
|
FilterBase::FilterBase(FilterModelBase *model_, QWidget *parent) : QWidget(parent),
|
|
|
|
model(model_)
|
2014-09-17 17:17:41 +00:00
|
|
|
{
|
|
|
|
ui.setupUi(this);
|
2015-02-17 11:31:23 +00:00
|
|
|
#if QT_VERSION >= 0x050200
|
2014-10-31 18:01:28 +00:00
|
|
|
ui.filterInternalList->setClearButtonEnabled(true);
|
|
|
|
#endif
|
2014-09-17 18:45:18 +00:00
|
|
|
QSortFilterProxyModel *filter = new QSortFilterProxyModel();
|
2017-12-23 13:17:23 +00:00
|
|
|
filter->setSourceModel(model);
|
2014-12-10 04:23:12 +00:00
|
|
|
filter->setFilterCaseSensitivity(Qt::CaseInsensitive);
|
2014-10-31 17:40:57 +00:00
|
|
|
connect(ui.filterInternalList, SIGNAL(textChanged(QString)), filter, SLOT(setFilterFixedString(QString)));
|
2017-12-24 13:35:59 +00:00
|
|
|
connect(ui.notButton, &QToolButton::toggled, model, &FilterModelBase::setNegate);
|
2014-10-31 17:40:57 +00:00
|
|
|
ui.filterList->setModel(filter);
|
2017-12-23 14:49:21 +00:00
|
|
|
|
2017-12-24 13:34:53 +00:00
|
|
|
addContextMenuEntry(tr("Select All"), &FilterModelBase::selectAll);
|
|
|
|
addContextMenuEntry(tr("Unselect All"), &FilterModelBase::clearFilter);
|
|
|
|
addContextMenuEntry(tr("Invert Selection"), &FilterModelBase::invertSelection);
|
|
|
|
ui.filterList->setContextMenuPolicy(Qt::ActionsContextMenu);
|
2014-09-17 17:17:41 +00:00
|
|
|
}
|
2014-10-01 19:23:02 +00:00
|
|
|
|
2017-12-23 13:17:23 +00:00
|
|
|
void FilterBase::showEvent(QShowEvent *event)
|
2014-10-01 19:23:02 +00:00
|
|
|
{
|
2017-12-23 13:17:23 +00:00
|
|
|
MultiFilterSortModel::instance()->addFilterModel(model);
|
2014-10-01 19:23:02 +00:00
|
|
|
QWidget::showEvent(event);
|
|
|
|
}
|
|
|
|
|
2017-12-23 13:17:23 +00:00
|
|
|
void FilterBase::hideEvent(QHideEvent *event)
|
2014-10-01 19:23:02 +00:00
|
|
|
{
|
2017-12-23 13:17:23 +00:00
|
|
|
MultiFilterSortModel::instance()->removeFilterModel(model);
|
2014-10-01 19:23:02 +00:00
|
|
|
QWidget::hideEvent(event);
|
|
|
|
}
|
2014-10-31 17:22:21 +00:00
|
|
|
|
2017-12-23 13:17:23 +00:00
|
|
|
TagFilter::TagFilter(QWidget *parent) : FilterBase(TagFilterModel::instance(), parent)
|
2014-10-31 18:49:52 +00:00
|
|
|
{
|
2017-12-23 13:17:23 +00:00
|
|
|
ui.label->setText(tr("Tags: "));
|
2014-10-31 18:49:52 +00:00
|
|
|
}
|
|
|
|
|
2017-12-23 13:17:23 +00:00
|
|
|
BuddyFilter::BuddyFilter(QWidget *parent) : FilterBase(BuddyFilterModel::instance(), parent)
|
2014-10-31 18:49:52 +00:00
|
|
|
{
|
2017-12-23 13:17:23 +00:00
|
|
|
ui.label->setText(tr("Person: "));
|
|
|
|
ui.label->setToolTip(tr("Searches for buddies and divemasters"));
|
2014-10-31 18:49:52 +00:00
|
|
|
}
|
|
|
|
|
2017-12-23 13:17:23 +00:00
|
|
|
LocationFilter::LocationFilter(QWidget *parent) : FilterBase(LocationFilterModel::instance(), parent)
|
2014-10-31 19:45:39 +00:00
|
|
|
{
|
|
|
|
ui.label->setText(tr("Location: "));
|
|
|
|
}
|
|
|
|
|
2017-12-23 13:17:23 +00:00
|
|
|
SuitFilter::SuitFilter(QWidget *parent) : FilterBase(SuitsFilterModel::instance(), parent)
|
2014-10-31 19:45:39 +00:00
|
|
|
{
|
2014-11-13 19:32:17 +00:00
|
|
|
ui.label->setText(tr("Suits: "));
|
|
|
|
}
|
|
|
|
|
2014-11-16 16:04:06 +00:00
|
|
|
MultiFilter::MultiFilter(QWidget *parent) : QWidget(parent)
|
2014-10-31 17:22:21 +00:00
|
|
|
{
|
2014-12-18 07:47:52 +00:00
|
|
|
ui.setupUi(this);
|
2014-11-16 16:04:06 +00:00
|
|
|
|
2014-11-11 19:06:28 +00:00
|
|
|
QWidget *expandedWidget = new QWidget();
|
2014-10-31 17:22:21 +00:00
|
|
|
QHBoxLayout *l = new QHBoxLayout();
|
2014-11-11 18:07:45 +00:00
|
|
|
|
2014-12-18 18:47:00 +00:00
|
|
|
TagFilter *tagFilter = new TagFilter(this);
|
2014-11-03 19:39:31 +00:00
|
|
|
int minimumHeight = tagFilter->ui.filterInternalList->height() +
|
2017-12-24 16:39:21 +00:00
|
|
|
tagFilter->ui.verticalLayout->spacing() * tagFilter->ui.verticalLayout->count();
|
2014-11-03 19:39:31 +00:00
|
|
|
|
|
|
|
QListView *dummyList = new QListView();
|
|
|
|
QStringListModel *dummy = new QStringListModel(QStringList() << "Dummy Text");
|
|
|
|
dummyList->setModel(dummy);
|
|
|
|
|
2014-12-18 07:47:52 +00: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 16:04:06 +00:00
|
|
|
|
2014-11-03 19:39:31 +00:00
|
|
|
l->addWidget(tagFilter);
|
2014-10-31 18:49:52 +00:00
|
|
|
l->addWidget(new BuddyFilter());
|
2014-10-31 19:48:44 +00:00
|
|
|
l->addWidget(new LocationFilter());
|
2014-11-13 19:32:17 +00:00
|
|
|
l->addWidget(new SuitFilter());
|
2014-10-31 21:28:39 +00:00
|
|
|
l->setContentsMargins(0, 0, 0, 0);
|
2014-11-03 19:39:31 +00:00
|
|
|
l->setSpacing(0);
|
2014-11-11 19:06:28 +00:00
|
|
|
expandedWidget->setLayout(l);
|
2014-11-16 16:04:06 +00:00
|
|
|
|
2014-12-18 07:47:52 +00:00
|
|
|
ui.scrollArea->setWidget(expandedWidget);
|
2017-12-24 16:39:21 +00:00
|
|
|
expandedWidget->resize(expandedWidget->width(), minimumHeight + dummyList->sizeHintForRow(0) * 5);
|
2014-12-18 07:47:52 +00:00
|
|
|
ui.scrollArea->setMinimumHeight(expandedWidget->height() + 5);
|
2014-11-03 19:39:31 +00:00
|
|
|
|
2014-11-16 16:04:06 +00:00
|
|
|
connect(MultiFilterSortModel::instance(), SIGNAL(filterFinished()), this, SLOT(filterFinished()));
|
|
|
|
}
|
|
|
|
|
|
|
|
void MultiFilter::filterFinished()
|
|
|
|
{
|
2014-12-18 07:47:52 +00:00
|
|
|
ui.filterText->setText(tr("Filter shows %1 (of %2) dives").arg(MultiFilterSortModel::instance()->divesDisplayed).arg(dive_table.nr));
|
2014-11-16 16:04:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MultiFilter::adjustHeight()
|
|
|
|
{
|
2014-12-18 07:47:52 +00:00
|
|
|
ui.scrollArea->setVisible(!ui.scrollArea->isVisible());
|
2014-10-31 17:22:21 +00:00
|
|
|
}
|
2014-11-13 21:45:32 +00:00
|
|
|
|
|
|
|
void MultiFilter::closeFilter()
|
|
|
|
{
|
|
|
|
MultiFilterSortModel::instance()->clearFilter();
|
|
|
|
hide();
|
2017-10-27 15:52:49 +00:00
|
|
|
MainWindow::instance()->setCheckedActionFilterTags(false);
|
2014-11-13 21:45:32 +00:00
|
|
|
}
|
2015-11-16 04:56:24 +00:00
|
|
|
|
|
|
|
TextHyperlinkEventFilter::TextHyperlinkEventFilter(QTextEdit *txtEdit) : QObject(txtEdit),
|
|
|
|
textEdit(txtEdit),
|
|
|
|
scrollView(textEdit->viewport())
|
|
|
|
{
|
|
|
|
// If you install the filter on textEdit, you fail to capture any clicks.
|
|
|
|
// The clicks go to the viewport. http://stackoverflow.com/a/31582977/10278
|
|
|
|
textEdit->viewport()->installEventFilter(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TextHyperlinkEventFilter::eventFilter(QObject *target, QEvent *evt)
|
|
|
|
{
|
|
|
|
if (target != scrollView)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (evt->type() != QEvent::MouseButtonPress &&
|
|
|
|
evt->type() != QEvent::ToolTip)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// --------------------
|
|
|
|
|
|
|
|
// Note: Qt knows that on Mac OSX, ctrl (and Control) are the command key.
|
|
|
|
const bool isCtrlClick = evt->type() == QEvent::MouseButtonPress &&
|
|
|
|
static_cast<QMouseEvent *>(evt)->modifiers() & Qt::ControlModifier &&
|
|
|
|
static_cast<QMouseEvent *>(evt)->button() == Qt::LeftButton;
|
|
|
|
|
|
|
|
const bool isTooltip = evt->type() == QEvent::ToolTip;
|
|
|
|
|
|
|
|
QString urlUnderCursor;
|
|
|
|
|
|
|
|
if (isCtrlClick || isTooltip) {
|
|
|
|
QTextCursor cursor = isCtrlClick ?
|
|
|
|
textEdit->cursorForPosition(static_cast<QMouseEvent *>(evt)->pos()) :
|
|
|
|
textEdit->cursorForPosition(static_cast<QHelpEvent *>(evt)->pos());
|
|
|
|
|
|
|
|
urlUnderCursor = tryToFormulateUrl(&cursor);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isCtrlClick) {
|
|
|
|
handleUrlClick(urlUnderCursor);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isTooltip) {
|
|
|
|
handleUrlTooltip(urlUnderCursor, static_cast<QHelpEvent *>(evt)->globalPos());
|
|
|
|
}
|
|
|
|
|
|
|
|
// 'return true' would mean that all event handling stops for this event.
|
|
|
|
// 'return false' lets Qt continue propagating the event to the target.
|
|
|
|
// Since our URL behavior is meant as 'additive' and not necessarily mutually
|
|
|
|
// exclusive with any default behaviors, it seems ok to return false to
|
|
|
|
// avoid unintentially hijacking any 'normal' event handling.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TextHyperlinkEventFilter::handleUrlClick(const QString &urlStr)
|
|
|
|
{
|
|
|
|
if (!urlStr.isEmpty()) {
|
|
|
|
QUrl url(urlStr, QUrl::StrictMode);
|
|
|
|
QDesktopServices::openUrl(url);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void TextHyperlinkEventFilter::handleUrlTooltip(const QString &urlStr, const QPoint &pos)
|
|
|
|
{
|
|
|
|
if (urlStr.isEmpty()) {
|
|
|
|
QToolTip::hideText();
|
|
|
|
} else {
|
|
|
|
// per Qt docs, QKeySequence::toString does localization "tr()" on strings like Ctrl.
|
|
|
|
// Note: Qt knows that on Mac OSX, ctrl (and Control) are the command key.
|
2018-01-01 20:49:19 +00:00
|
|
|
const QString ctrlKeyName = QKeySequence(Qt::CTRL).toString(QKeySequence::NativeText);
|
2015-11-16 04:56:24 +00:00
|
|
|
// ctrlKeyName comes with a trailing '+', as in: 'Ctrl+'
|
|
|
|
QToolTip::showText(pos, tr("%1click to visit %2").arg(ctrlKeyName).arg(urlStr));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TextHyperlinkEventFilter::stringMeetsOurUrlRequirements(const QString &maybeUrlStr)
|
|
|
|
{
|
|
|
|
QUrl url(maybeUrlStr, QUrl::StrictMode);
|
2017-04-18 21:41:55 +00:00
|
|
|
return url.isValid() && (!url.scheme().isEmpty()) && ((!url.authority().isEmpty()) || (!url.path().isEmpty()));
|
2015-11-16 04:56:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QString TextHyperlinkEventFilter::tryToFormulateUrl(QTextCursor *cursor)
|
|
|
|
{
|
|
|
|
// tryToFormulateUrl exists because WordUnderCursor will not
|
|
|
|
// treat "http://m.abc.def" as a word.
|
|
|
|
|
|
|
|
// tryToFormulateUrl invokes fromCursorTilWhitespace two times (once
|
|
|
|
// with a forward moving cursor and once in the backwards direction) in
|
|
|
|
// order to expand the selection to try to capture a complete string
|
|
|
|
// like "http://m.abc.def"
|
|
|
|
|
|
|
|
// loosely inspired by advice here: http://stackoverflow.com/q/19262064/10278
|
|
|
|
|
|
|
|
cursor->select(QTextCursor::WordUnderCursor);
|
|
|
|
QString maybeUrlStr = cursor->selectedText();
|
|
|
|
|
|
|
|
const bool soFarSoGood = !maybeUrlStr.simplified().replace(" ", "").isEmpty();
|
|
|
|
|
|
|
|
if (soFarSoGood && !stringMeetsOurUrlRequirements(maybeUrlStr)) {
|
|
|
|
// If we don't yet have a full url, try to expand til we get one. Note:
|
|
|
|
// after requesting WordUnderCursor, empirically (all platforms, in
|
|
|
|
// Qt5), the 'anchor' is just past the end of the word.
|
|
|
|
|
|
|
|
QTextCursor cursor2(*cursor);
|
|
|
|
QString left = fromCursorTilWhitespace(cursor, true /*searchBackwards*/);
|
|
|
|
QString right = fromCursorTilWhitespace(&cursor2, false);
|
|
|
|
maybeUrlStr = left + right;
|
|
|
|
}
|
|
|
|
|
|
|
|
return stringMeetsOurUrlRequirements(maybeUrlStr) ? maybeUrlStr : QString::null;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString TextHyperlinkEventFilter::fromCursorTilWhitespace(QTextCursor *cursor, const bool searchBackwards)
|
|
|
|
{
|
|
|
|
// fromCursorTilWhitespace calls cursor->movePosition repeatedly, while
|
|
|
|
// preserving the original 'anchor' (qt terminology) of the cursor.
|
|
|
|
// We widen the selection with 'movePosition' until hitting any whitespace.
|
|
|
|
|
|
|
|
QString result;
|
|
|
|
QString grownText;
|
|
|
|
QString noSpaces;
|
|
|
|
bool movedOk = false;
|
2017-04-18 21:35:43 +00:00
|
|
|
int oldSize = -1;
|
2015-11-16 04:56:24 +00:00
|
|
|
|
|
|
|
do {
|
|
|
|
result = grownText; // this is a no-op on the first visit.
|
|
|
|
|
|
|
|
if (searchBackwards) {
|
|
|
|
movedOk = cursor->movePosition(QTextCursor::PreviousWord, QTextCursor::KeepAnchor);
|
|
|
|
} else {
|
|
|
|
movedOk = cursor->movePosition(QTextCursor::NextWord, QTextCursor::KeepAnchor);
|
|
|
|
}
|
|
|
|
|
|
|
|
grownText = cursor->selectedText();
|
2017-12-24 16:39:21 +00:00
|
|
|
if (grownText.size() == oldSize)
|
|
|
|
movedOk = false;
|
2017-04-18 21:35:43 +00:00
|
|
|
oldSize = grownText.size();
|
2015-11-16 04:56:24 +00:00
|
|
|
noSpaces = grownText.simplified().replace(" ", "");
|
|
|
|
} while (grownText == noSpaces && movedOk);
|
|
|
|
|
|
|
|
// while growing the selection forwards, we have an extra step to do:
|
|
|
|
if (!searchBackwards) {
|
|
|
|
/*
|
|
|
|
The cursor keeps jumping to the start of the next word.
|
|
|
|
(for example) in the string "mn.abcd.edu is the spot" you land at
|
|
|
|
m,a,e,i (the 'i' in 'is). if we stop at e, then we only capture
|
|
|
|
"mn.abcd." for the url (wrong). So we have to go to 'i', to
|
|
|
|
capture "mn.abcd.edu " (with trailing space), and then clean it up.
|
|
|
|
*/
|
|
|
|
QStringList list = grownText.split(QRegExp("\\s"), QString::SkipEmptyParts);
|
|
|
|
if (!list.isEmpty()) {
|
|
|
|
result = list[0];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|