mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Added a button to hide a picture from the dive.
This patch hides a picture from the dive, it should actually remove it, but because I didn't found a quick way to remove a picture from the dive yet, it just hides it. To remove a picture from the dive, the DivePictureItem has to remember the QUrl of the original file, to remove that from the model, and currently it only has the QPixmap. this can be for 4.2.1 or we can postpone 4.2 a tiny bit since this is a important feature. Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
7f4b05f194
commit
75aafdc715
2 changed files with 82 additions and 0 deletions
|
@ -7,12 +7,44 @@
|
||||||
#include <QBrush>
|
#include <QBrush>
|
||||||
#include <QGraphicsDropShadowEffect>
|
#include <QGraphicsDropShadowEffect>
|
||||||
#include <QDesktopServices>
|
#include <QDesktopServices>
|
||||||
|
#include <QGraphicsScene>
|
||||||
|
#include <QGraphicsSceneMouseEvent>
|
||||||
|
#include <QGraphicsView>
|
||||||
#include <QUrl>
|
#include <QUrl>
|
||||||
|
|
||||||
DivePixmapItem::DivePixmapItem(QObject *parent) : QObject(parent), QGraphicsPixmapItem()
|
DivePixmapItem::DivePixmapItem(QObject *parent) : QObject(parent), QGraphicsPixmapItem()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DiveButtonItem::DiveButtonItem(QObject *parent): DivePixmapItem(parent)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void DiveButtonItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
||||||
|
{
|
||||||
|
QGraphicsItem::mousePressEvent(event);
|
||||||
|
emit clicked();
|
||||||
|
}
|
||||||
|
|
||||||
|
// If we have many many pictures on screen, maybe a shared-pixmap would be better to
|
||||||
|
// paint on screen, but for now, this.
|
||||||
|
CloseButtonItem::CloseButtonItem(QObject *parent): DiveButtonItem(parent)
|
||||||
|
{
|
||||||
|
static QPixmap p = QPixmap(":trash");
|
||||||
|
setPixmap(p);
|
||||||
|
setFlag(ItemIgnoresTransformations);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CloseButtonItem::hide()
|
||||||
|
{
|
||||||
|
DiveButtonItem::hide();
|
||||||
|
}
|
||||||
|
|
||||||
|
void CloseButtonItem::show()
|
||||||
|
{
|
||||||
|
DiveButtonItem::show();
|
||||||
|
}
|
||||||
|
|
||||||
DivePictureItem::DivePictureItem(int row, QObject *parent): DivePixmapItem(parent)
|
DivePictureItem::DivePictureItem(int row, QObject *parent): DivePixmapItem(parent)
|
||||||
{
|
{
|
||||||
setFlag(ItemIgnoresTransformations);
|
setFlag(ItemIgnoresTransformations);
|
||||||
|
@ -50,20 +82,50 @@ void DivePictureItem::setPixmap(const QPixmap &pix)
|
||||||
shadow->setZValue(-2);
|
shadow->setZValue(-2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CloseButtonItem *button = NULL;
|
||||||
void DivePictureItem::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
|
void DivePictureItem::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
|
||||||
{
|
{
|
||||||
Animations::scaleTo(this, 1.0);
|
Animations::scaleTo(this, 1.0);
|
||||||
setZValue(5);
|
setZValue(5);
|
||||||
|
|
||||||
|
if(!button) {
|
||||||
|
button = new CloseButtonItem();
|
||||||
|
button->setScale(0.2);
|
||||||
|
button->setZValue(7);
|
||||||
|
scene()->addItem(button);
|
||||||
|
}
|
||||||
|
button->setPos(mapToScene(0,0));
|
||||||
|
button->show();
|
||||||
|
button->disconnect();
|
||||||
|
connect(button, SIGNAL(clicked()), this, SLOT(removePicture()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void DivePictureItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
|
void DivePictureItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
|
||||||
{
|
{
|
||||||
Animations::scaleTo(this, 0.2);
|
Animations::scaleTo(this, 0.2);
|
||||||
setZValue(0);
|
setZValue(0);
|
||||||
|
if(button)
|
||||||
|
button->hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DivePictureItem::mousePressEvent(QGraphicsSceneMouseEvent *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();
|
QString filePath = DivePictureModel::instance()->index(rowOnModel,0).data(Qt::ToolTipRole).toString();
|
||||||
QDesktopServices::openUrl(QUrl::fromLocalFile(filePath));
|
QDesktopServices::openUrl(QUrl::fromLocalFile(filePath));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DivePictureItem::removePicture()
|
||||||
|
{
|
||||||
|
/* this is a WIP, it doesn't really *removes* anything, merely hides it.
|
||||||
|
* good workaround, I still need to figure out how to activelly remove
|
||||||
|
* it from the model. */
|
||||||
|
button->hide();
|
||||||
|
hide();
|
||||||
|
}
|
||||||
|
|
|
@ -22,6 +22,7 @@ public:
|
||||||
void setPixmap(const QPixmap& pix);
|
void setPixmap(const QPixmap& pix);
|
||||||
public slots:
|
public slots:
|
||||||
void settingsChanged();
|
void settingsChanged();
|
||||||
|
void removePicture();
|
||||||
protected:
|
protected:
|
||||||
void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
|
void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
|
||||||
void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
|
void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
|
||||||
|
@ -30,4 +31,23 @@ private:
|
||||||
int rowOnModel;
|
int rowOnModel;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class DiveButtonItem : public DivePixmapItem {
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
DiveButtonItem(QObject *parent = 0);
|
||||||
|
protected:
|
||||||
|
virtual void mousePressEvent(QGraphicsSceneMouseEvent *event);
|
||||||
|
signals:
|
||||||
|
void clicked();
|
||||||
|
};
|
||||||
|
|
||||||
|
class CloseButtonItem : public DiveButtonItem {
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
CloseButtonItem(QObject *parent = 0);
|
||||||
|
public slots:
|
||||||
|
void hide();
|
||||||
|
void show();
|
||||||
|
};
|
||||||
|
|
||||||
#endif // DIVEPIXMAPITEM_H
|
#endif // DIVEPIXMAPITEM_H
|
||||||
|
|
Loading…
Add table
Reference in a new issue