mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-28 13:10:19 +00:00
05a1626c7e
This implements different zoom levels for the dive photos tab as suggested by Stefan Fuchs <sfuchs@gmx.de> in #898. The zoom level can be changed using a slider or CTRL+mousewheel. Zoom levels range from a third of the standard thumbnail size to thrice the standard thumbnail size. Thumbnails are cached in maximum resolution and scaled down on the fly. Because the profile widget took its pictures from the photo list model, an extra picture copy with a fixed size had to be introduced. The UI is still a bit crude. Reported-by: Stefan Fuchs <sfuchs@gmx.de> Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
109 lines
3.1 KiB
C++
109 lines
3.1 KiB
C++
// SPDX-License-Identifier: GPL-2.0
|
|
#include "TabDivePhotos.h"
|
|
#include "ui_TabDivePhotos.h"
|
|
|
|
#include <qt-models/divepicturemodel.h>
|
|
|
|
#include <QDesktopServices>
|
|
#include <QContextMenuEvent>
|
|
#include <QMenu>
|
|
#include <QUrl>
|
|
#include <QMessageBox>
|
|
|
|
//TODO: Remove those in the future.
|
|
#include "../mainwindow.h"
|
|
#include "../divelistview.h"
|
|
|
|
TabDivePhotos::TabDivePhotos(QWidget *parent)
|
|
: TabBase(parent),
|
|
ui(new Ui::TabDivePhotos()),
|
|
divePictureModel(DivePictureModel::instance())
|
|
{
|
|
ui->setupUi(this);
|
|
ui->photosView->setModel(divePictureModel);
|
|
ui->photosView->setSelectionMode(QAbstractItemView::ExtendedSelection);
|
|
ui->photosView->setResizeMode(QListView::Adjust);
|
|
|
|
connect(ui->photosView, &DivePictureWidget::photoDoubleClicked,
|
|
[](const QString& path) {
|
|
QDesktopServices::openUrl(QUrl::fromLocalFile(path));
|
|
}
|
|
);
|
|
connect(ui->photosView, &DivePictureWidget::zoomLevelChanged,
|
|
this, &TabDivePhotos::changeZoomLevel);
|
|
connect(ui->zoomSlider, &QAbstractSlider::valueChanged,
|
|
DivePictureModel::instance(), &DivePictureModel::setZoomLevel);
|
|
}
|
|
|
|
TabDivePhotos::~TabDivePhotos()
|
|
{
|
|
delete ui;
|
|
}
|
|
|
|
void TabDivePhotos::clear()
|
|
{
|
|
updateData();
|
|
}
|
|
|
|
void TabDivePhotos::contextMenuEvent(QContextMenuEvent *event)
|
|
{
|
|
QMenu popup(this);
|
|
popup.addAction(tr("Load image(s) from file(s)"), this, SLOT(addPhotosFromFile()));
|
|
popup.addAction(tr("Load image(s) from web"), this, SLOT(addPhotosFromURL()));
|
|
popup.addSeparator();
|
|
popup.addAction(tr("Delete selected images"), this, SLOT(removeSelectedPhotos()));
|
|
popup.addAction(tr("Delete all images"), this, SLOT(removeAllPhotos()));
|
|
popup.exec(event->globalPos());
|
|
event->accept();
|
|
}
|
|
|
|
void TabDivePhotos::removeSelectedPhotos()
|
|
{
|
|
bool last = false;
|
|
if (!ui->photosView->selectionModel()->hasSelection())
|
|
return;
|
|
QModelIndexList indexes = ui->photosView->selectionModel()->selectedRows();
|
|
if (indexes.count() == 0)
|
|
indexes = ui->photosView->selectionModel()->selectedIndexes();
|
|
QModelIndex photo = indexes.first();
|
|
do {
|
|
photo = indexes.first();
|
|
last = indexes.count() == 1;
|
|
if (photo.isValid()) {
|
|
QString fileUrl = photo.data(Qt::DisplayPropertyRole).toString();
|
|
if (fileUrl.length() > 0)
|
|
DivePictureModel::instance()->removePicture(fileUrl, last);
|
|
}
|
|
indexes.removeFirst();
|
|
} while(!indexes.isEmpty());
|
|
}
|
|
|
|
//TODO: This looks overly wrong. We shouldn't call MainWindow to retrieve the DiveList to add Images.
|
|
void TabDivePhotos::addPhotosFromFile()
|
|
{
|
|
MainWindow::instance()->dive_list()->loadImages();
|
|
}
|
|
|
|
void TabDivePhotos::addPhotosFromURL()
|
|
{
|
|
MainWindow::instance()->dive_list()->loadWebImages();
|
|
}
|
|
|
|
void TabDivePhotos::removeAllPhotos()
|
|
{
|
|
if (QMessageBox::warning(this, tr("Deleting Images"), tr("Are you sure you want to delete all images?"), QMessageBox::Cancel | QMessageBox::Ok, QMessageBox::Cancel) != QMessageBox::Cancel ) {
|
|
ui->photosView->selectAll();
|
|
removeSelectedPhotos();
|
|
}
|
|
}
|
|
|
|
void TabDivePhotos::updateData()
|
|
{
|
|
divePictureModel->updateDivePictures();
|
|
}
|
|
|
|
void TabDivePhotos::changeZoomLevel(int delta)
|
|
{
|
|
// We count on QSlider doing bound checks
|
|
ui->zoomSlider->setValue(ui->zoomSlider->value() + delta);
|
|
}
|