~wallch/wallpaper-changer/trunk

« back to all changes in this revision

Viewing changes to src/tools/markitem.cpp

  • Committer: Alex Solanos
  • Date: 2015-08-18 17:06:11 UTC
  • Revision ID: alexsol.developer@gmail.com-20150818170611-0t0118wfwoipzjrr
Added rotation and scaling features to location tagging. Also it now
really works.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
Wallch - Wallpaper Changer
 
3
A tool for changing Desktop Wallpapers automatically
 
4
with lots of features
 
5
Copyright © 2010-2014 by Alex Solanos and Leon Vitanos
 
6
 
 
7
This program is free software; you can redistribute it and/or
 
8
modify it under the terms of the GNU General Public License
 
9
as published by the Free Software Foundation; either version 3
 
10
of the License, or (at your option) any later version.
 
11
 
 
12
This program is distributed in the hope that it will be useful,
 
13
but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
GNU General Public License for more details.
 
16
 
 
17
You should have received a copy of the GNU General Public License
 
18
along with this program; if not, write to the Free Software
 
19
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
20
*/
 
21
 
 
22
#define QT_NO_KEYWORDS
 
23
 
 
24
#include <QDebug>
 
25
#include <QPainter>
 
26
#include <QCursor>
 
27
#include <QRect>
 
28
#include <QMenu>
 
29
#include <QGraphicsScene>
 
30
 
 
31
#include "markitem.h"
 
32
 
 
33
MarkItem::MarkItem()
 
34
{
 
35
    this->setFlag(QGraphicsItem::ItemIsMovable, true);
 
36
    this->setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);
 
37
    this->setFlag(QGraphicsItem::ItemIsFocusable, true);
 
38
    this->setFlag(QGraphicsItem::ItemIsSelectable, true);
 
39
    this->setFocus(Qt::MouseFocusReason);
 
40
    this->setAcceptHoverEvents(true);
 
41
}
 
42
 
 
43
void MarkItem::hoverEnterEvent(QGraphicsSceneHoverEvent *){
 
44
    setCursor(QCursor(Qt::SizeAllCursor));
 
45
    this->update(this->boundingRect());
 
46
}
 
47
 
 
48
void MarkItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *){
 
49
    this->update(this->boundingRect());
 
50
}
 
51
 
 
52
void MarkItem::contextMenuEvent(QGraphicsSceneContextMenuEvent *event){
 
53
    QMenu menu;
 
54
     QAction *deleteAction = menu.addAction("Delete");
 
55
     QAction *selectedAction = menu.exec(event->screenPos());
 
56
     if(deleteAction == selectedAction){
 
57
         this->scene()->removeItem(this);
 
58
     }
 
59
}
 
60
 
 
61
void MarkItem::setPointType(PointItemType::Value type, const QString &path /* = QString()*/){
 
62
    pointType_ = type;
 
63
 
 
64
    switch(type){
 
65
    default:
 
66
    case PointItemType::Point1:
 
67
        imagePath_ = ":/images/point1.png";
 
68
        break;
 
69
    case PointItemType::Point2:
 
70
        imagePath_ = ":/images/point2.png";
 
71
        break;
 
72
    case PointItemType::CustomPoint:
 
73
        imagePath_ = path;
 
74
        break;
 
75
    }
 
76
 
 
77
    this->setPixmap(QPixmap(imagePath_));
 
78
}
 
79
 
 
80
PointItemType::Value MarkItem::getType(){
 
81
    return pointType_;
 
82
}
 
83
 
 
84
QString MarkItem::imagePath(){
 
85
    return imagePath_;
 
86
}
 
87
 
 
88
bool MarkItem::willFinallyBeVisible(){
 
89
    return this->scene()->sceneRect().intersects(this->sceneBoundingRect());
 
90
}