summaryrefslogtreecommitdiffstats
path: root/qt-ui
diff options
context:
space:
mode:
authorGravatar Tomaz Canabrava <tomaz.canabrava@intel.com>2014-07-29 22:13:14 -0300
committerGravatar Dirk Hohndel <dirk@hohndel.org>2014-07-30 12:34:43 -0700
commit1e6986d87010a636d151f77b3da2a40d52a95178 (patch)
tree72fba4d0f44d5bb4bdfe4c7e7e45477c5c449f98 /qt-ui
parent75aafdc7152747f423e0dacc524c61c5619382e8 (diff)
downloadsubsurface-1e6986d87010a636d151f77b3da2a40d52a95178.tar.gz
Instead of holding the index, hold the URL.
Since the idea is to remove the picture in the future, we need to not hold the row on the model, as when we delete one, the other pictures will change the row. but the QUrl is unique. Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'qt-ui')
-rw-r--r--qt-ui/profile/divepixmapitem.cpp18
-rw-r--r--qt-ui/profile/divepixmapitem.h5
-rw-r--r--qt-ui/profile/profilewidget2.cpp3
3 files changed, 12 insertions, 14 deletions
diff --git a/qt-ui/profile/divepixmapitem.cpp b/qt-ui/profile/divepixmapitem.cpp
index 372cbd169..3fb06adb9 100644
--- a/qt-ui/profile/divepixmapitem.cpp
+++ b/qt-ui/profile/divepixmapitem.cpp
@@ -45,7 +45,7 @@ void CloseButtonItem::show()
DiveButtonItem::show();
}
-DivePictureItem::DivePictureItem(int row, QObject *parent): DivePixmapItem(parent)
+DivePictureItem::DivePictureItem(QObject *parent): DivePixmapItem(parent)
{
setFlag(ItemIgnoresTransformations);
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
@@ -53,7 +53,6 @@ DivePictureItem::DivePictureItem(int row, QObject *parent): DivePixmapItem(paren
#else
setAcceptHoverEvents(true);
#endif
- rowOnModel = row;
setScale(0.2);
connect(PreferencesDialog::instance(), SIGNAL(settingsChanged()), this, SLOT(settingsChanged()));
setVisible(prefs.show_pictures_in_profile);
@@ -100,6 +99,11 @@ void DivePictureItem::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
connect(button, SIGNAL(clicked()), this, SLOT(removePicture()));
}
+void DivePictureItem::setFileUrl(const QString &s)
+{
+ fileUrl = s;
+}
+
void DivePictureItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
{
Animations::scaleTo(this, 0.2);
@@ -110,15 +114,7 @@ void DivePictureItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
void DivePictureItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
- QGraphicsView *view = scene()->views().first();
- QList<QGraphicsItem*> items = view->items(view->mapFromScene(event->scenePos()));
- Q_FOREACH(QGraphicsItem *item, items){
- if (dynamic_cast<CloseButtonItem*>(item)){
- return;
- }
- }
- QString filePath = DivePictureModel::instance()->index(rowOnModel,0).data(Qt::ToolTipRole).toString();
- QDesktopServices::openUrl(QUrl::fromLocalFile(filePath));
+ QDesktopServices::openUrl(QUrl::fromLocalFile(fileUrl));
}
void DivePictureItem::removePicture()
diff --git a/qt-ui/profile/divepixmapitem.h b/qt-ui/profile/divepixmapitem.h
index b5bed37ce..d39f26db6 100644
--- a/qt-ui/profile/divepixmapitem.h
+++ b/qt-ui/profile/divepixmapitem.h
@@ -18,17 +18,18 @@ class DivePictureItem : public DivePixmapItem {
Q_OBJECT
Q_PROPERTY(qreal scale WRITE setScale READ scale)
public:
- DivePictureItem(int row, QObject *parent = 0);
+ DivePictureItem(QObject *parent = 0);
void setPixmap(const QPixmap& pix);
public slots:
void settingsChanged();
void removePicture();
+ void setFileUrl(const QString& s);
protected:
void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
void mousePressEvent(QGraphicsSceneMouseEvent *event);
private:
- int rowOnModel;
+ QString fileUrl;
};
class DiveButtonItem : public DivePixmapItem {
diff --git a/qt-ui/profile/profilewidget2.cpp b/qt-ui/profile/profilewidget2.cpp
index b601af36e..21f0cb4e4 100644
--- a/qt-ui/profile/profilewidget2.cpp
+++ b/qt-ui/profile/profilewidget2.cpp
@@ -1366,8 +1366,9 @@ void ProfileWidget2::plotPictures()
// information area.
if (!pic->offset.seconds)
continue;
- DivePictureItem *item = new DivePictureItem(i);
+ DivePictureItem *item = new DivePictureItem();
item->setPixmap(m->index(i,0).data(Qt::DecorationRole).value<QPixmap>());
+ item->setFileUrl(m->index(i,0).data(Qt::DisplayPropertyRole).toString());
// let's put the picture at the correct time, but at a fixed "depth" on the profile
// not sure this is ideal, but it seems to look right.
x = timeAxis->posAtValue(pic->offset.seconds);