Advertisement
Guest User

Untitled

a guest
Jun 24th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.87 KB | None | 0 0
  1. #include <QGraphicsItem>
  2. #include <QPixmap>
  3. #include <QPointF>
  4. #include <QSizeF>
  5.  
  6. class Escena;
  7.  
  8. class Item: public QGraphicsItem{
  9. private:
  10. QString nombre;
  11. QPixmap imagen;
  12. bool seleccion;
  13. QPointF punto;
  14. QSizeF tamanio;
  15. public:
  16. Item(QPixmap imagen, QGraphicsItem *padre = nullptr);
  17. void setNombre(QString);
  18. QString getNombre();
  19. void setImagen(QPixmap);
  20. QPixmap getImagen();
  21. void setPunto(QPointF punto);
  22. QPointF getPunto();
  23. void setTamanio(QSizeF tamanio);
  24. QSizeF getTamanio();
  25. void setSeleccion(bool seleccion);
  26. bool getSeleccion();
  27. protected:
  28. QRectF boundingRect() const override;
  29. void paint(QPainter *painter, const QStyleOptionGraphicsItem
  30. *option,QWidget *widget) override;
  31. };
  32.  
  33. #include "item.h"
  34. #include "escena.h"
  35. #include <QDebug>
  36. #include <QPainter>
  37. #include <QPointF>
  38.  
  39. Item::Item(QPixmap imagen, QGraphicsItem *padre):QGraphicsItem (padre)
  40. {
  41. this->imagen = imagen;
  42. }
  43.  
  44. void Item::setNombre(QString nombre){
  45. this->nombre = nombre;
  46. }
  47.  
  48. QString Item::getNombre(){
  49. return nombre;
  50. }
  51.  
  52. void Item::setImagen(QPixmap imagen){
  53. this->imagen = imagen;
  54. }
  55.  
  56. QPixmap Item::getImagen(){
  57. return imagen;
  58. }
  59.  
  60. void Item::setPunto(QPointF punto){
  61. this->punto = punto;
  62. }
  63.  
  64. QPointF Item::getPunto(){
  65. return punto;
  66. }
  67.  
  68. void Item::setTamanio(QSizeF tamanio){
  69. this->tamanio = tamanio;
  70. }
  71.  
  72. QSizeF Item::getTamanio(){
  73. return tamanio;
  74. }
  75.  
  76. void Item::setSeleccion(bool seleccion){
  77. this->seleccion = seleccion;
  78. }
  79.  
  80. bool Item::getSeleccion(){
  81. return seleccion;
  82. }
  83.  
  84. QRectF Item::boundingRect() const{
  85.  
  86. return QRectF(punto.x(), punto.y(), tamanio.width(),
  87. tamanio.height());
  88. }
  89.  
  90. void Item::paint(QPainter *painter, const QStyleOptionGraphicsItem *,
  91. QWidget *){
  92. painter->drawPixmap(punto.x(), punto.y(), tamanio.width(),
  93. tamanio.height(),imagen);
  94. }
  95.  
  96. #include <QGraphicsScene>
  97. #include <QGraphicsItem>
  98. #include "item.h"
  99.  
  100. class Item;
  101.  
  102. class Escena : public QGraphicsScene{
  103. public:
  104. Escena(QObject *padre = nullptr);
  105. };
  106.  
  107. #include "escena.h"
  108. #include <QPixmap>
  109. #include <QGraphicsItem>
  110.  
  111. #define XPOS 0.0//constantes para las dimensiones de la escena
  112. #define YPOS 0.0
  113. #define WIDTH 663.0
  114. #define HEIGHT 410.0
  115.  
  116. Escena::Escena(QObject *padre):QGraphicsScene(XPOS, YPOS, WIDTH,
  117. HEIGHT, padre){
  118. Item *c = new Item(QPixmap(":/img/targetOff.png"));
  119. c->setPunto(QPointF(0.0,0.0));
  120. c->setTamanio(QSizeF(64.0,64.0));
  121. c->setNombre("A");
  122. c->setSeleccion(false);
  123.  
  124. c->setFlag(QGraphicsItem::ItemIsMovable,true);//Movilidad
  125. addItem(c);
  126.  
  127. Item *c2 = new Item(QPixmap(":/img/targetOff.png"));
  128. c2->setPunto(QPointF(300.0,200.0));
  129. c2->setTamanio(QSizeF(64.0,64.0));
  130. c2->setNombre("Item B");
  131. c2->setSeleccion(false);
  132. c2->setAcceptHoverEvents(true);
  133. c2->setFlag(QGraphicsItem::ItemIsMovable,true);//movilidad
  134. addItem(c2);
  135. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement