scene_item_line.cpp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /*
  2. This file is part of Telegram Desktop,
  3. the official desktop application for the Telegram messaging service.
  4. For license and copyright information please follow this link:
  5. https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
  6. */
  7. #include "editor/scene/scene_item_line.h"
  8. #include <QGraphicsScene>
  9. namespace Editor {
  10. ItemLine::ItemLine(const QPixmap &&pixmap)
  11. : _pixmap(std::move(pixmap))
  12. , _rect(QPointF(), _pixmap.size() / float64(style::DevicePixelRatio())) {
  13. }
  14. QRectF ItemLine::boundingRect() const {
  15. return _rect;
  16. }
  17. void ItemLine::paint(
  18. QPainter *p,
  19. const QStyleOptionGraphicsItem *,
  20. QWidget *) {
  21. p->drawPixmap(0, 0, _pixmap);
  22. }
  23. bool ItemLine::collidesWithItem(
  24. const QGraphicsItem *,
  25. Qt::ItemSelectionMode) const {
  26. return false;
  27. }
  28. bool ItemLine::collidesWithPath(
  29. const QPainterPath &,
  30. Qt::ItemSelectionMode) const {
  31. return false;
  32. }
  33. void ItemLine::save(SaveState state) {
  34. auto &saved = (state == SaveState::Keep) ? _keeped : _saved;
  35. saved = {
  36. .saved = true,
  37. .status = status(),
  38. };
  39. }
  40. void ItemLine::restore(SaveState state) {
  41. if (!hasState(state)) {
  42. return;
  43. }
  44. const auto &saved = (state == SaveState::Keep) ? _keeped : _saved;
  45. setStatus(saved.status);
  46. }
  47. bool ItemLine::hasState(SaveState state) const {
  48. const auto &saved = (state == SaveState::Keep) ? _keeped : _saved;
  49. return saved.saved;
  50. }
  51. } // namespace Editor