Collection of tools useful for audio production
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

135 lines
3.5KB

  1. /*
  2. * Patchbay Canvas engine using QGraphicsView/Scene
  3. * Copyright (C) 2010-2012 Filipe Coelho <falktx@falktx.com>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * For a full copy of the GNU General Public License see the COPYING file
  16. */
  17. #include "canvasicon.h"
  18. #include <QtGui/QPainter>
  19. #include <QtGui/QGraphicsColorizeEffect>
  20. #include <QtSvg/QSvgRenderer>
  21. START_NAMESPACE_PATCHCANVAS
  22. CanvasIcon::CanvasIcon(Icon icon, QString name, QGraphicsItem* parent) :
  23. QGraphicsSvgItem(parent)
  24. {
  25. m_renderer = 0;
  26. p_size = QRectF(0, 0, 0, 0);
  27. m_colorFX = new QGraphicsColorizeEffect(this);
  28. m_colorFX->setColor(canvas.theme->box_text.color());
  29. setGraphicsEffect(m_colorFX);
  30. setIcon(icon, name);
  31. }
  32. CanvasIcon::~CanvasIcon()
  33. {
  34. if (m_renderer)
  35. delete m_renderer;
  36. delete m_colorFX;
  37. }
  38. void CanvasIcon::setIcon(Icon icon, QString name)
  39. {
  40. name = name.toLower();
  41. QString icon_path;
  42. if (icon == ICON_APPLICATION)
  43. {
  44. p_size = QRectF(3, 2, 19, 18);
  45. if (name.contains("audacious"))
  46. {
  47. p_size = QRectF(5, 4, 16, 16);
  48. icon_path = ":/scalable/pb_audacious.svg";
  49. }
  50. else if (name.contains("clementine"))
  51. {
  52. p_size = QRectF(5, 4, 16, 16);
  53. icon_path = ":/scalable/pb_clementine.svg";
  54. }
  55. else if (name.contains("jamin"))
  56. {
  57. p_size = QRectF(5, 3, 16, 16);
  58. icon_path = ":/scalable/pb_jamin.svg";
  59. }
  60. else if (name.contains("mplayer"))
  61. {
  62. p_size = QRectF(5, 4, 16, 16);
  63. icon_path = ":/scalable/pb_mplayer.svg";
  64. }
  65. else if (name.contains("vlc"))
  66. {
  67. p_size = QRectF(5, 3, 16, 16);
  68. icon_path = ":/scalable/pb_vlc.svg";
  69. }
  70. else
  71. {
  72. p_size = QRectF(5, 3, 16, 16);
  73. icon_path = ":/scalable/pb_generic.svg";
  74. }
  75. }
  76. else if (icon == ICON_HARDWARE)
  77. {
  78. p_size = QRectF(5, 2, 16, 16);
  79. icon_path = ":/scalable/pb_hardware.svg";
  80. }
  81. else if (icon == ICON_LADISH_ROOM)
  82. {
  83. p_size = QRectF(5, 2, 16, 16);
  84. icon_path = ":/scalable/pb_hardware.svg";
  85. }
  86. else
  87. {
  88. p_size = QRectF(0, 0, 0, 0);
  89. qCritical("PatchCanvas::CanvasIcon->setIcon(%s, %s) - unsupported Icon requested", icon2str(icon), name.toUtf8().constData());
  90. return;
  91. }
  92. if (m_renderer)
  93. delete m_renderer;
  94. m_renderer = new QSvgRenderer(icon_path, canvas.scene);
  95. setSharedRenderer(m_renderer);
  96. update();
  97. }
  98. int CanvasIcon::type() const
  99. {
  100. return CanvasIconType;
  101. }
  102. QRectF CanvasIcon::boundingRect() const
  103. {
  104. return p_size;
  105. }
  106. void CanvasIcon::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
  107. {
  108. if (m_renderer)
  109. {
  110. painter->setRenderHint(QPainter::Antialiasing, false);
  111. painter->setRenderHint(QPainter::TextAntialiasing, false);
  112. m_renderer->render(painter, p_size);
  113. }
  114. else
  115. QGraphicsSvgItem::paint(painter, option, widget);
  116. }
  117. END_NAMESPACE_PATCHCANVAS