The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
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.

105 lines
3.6KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-11 by Raw Material Software Ltd.
  5. ------------------------------------------------------------------------------
  6. JUCE can be redistributed and/or modified under the terms of the GNU General
  7. Public License (Version 2), as published by the Free Software Foundation.
  8. A copy of the license is included in the JUCE distribution, or can be found
  9. online at www.gnu.org/licenses.
  10. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  11. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  12. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  13. ------------------------------------------------------------------------------
  14. To release a closed-source product which uses JUCE, commercial licenses are
  15. available: visit www.rawmaterialsoftware.com/juce for more information.
  16. ==============================================================================
  17. */
  18. #ifndef __JUCER_FILEPREVIEWCOMPONENT_JUCEHEADER__
  19. #define __JUCER_FILEPREVIEWCOMPONENT_JUCEHEADER__
  20. //==============================================================================
  21. /**
  22. */
  23. class ItemPreviewComponent : public Component
  24. {
  25. public:
  26. ItemPreviewComponent (const File& file_)
  27. : file (file_)
  28. {
  29. setOpaque (true);
  30. tryToLoadImage();
  31. }
  32. void paint (Graphics& g)
  33. {
  34. drawTexturedBackground (g);
  35. Rectangle<int> area = RectanglePlacement (RectanglePlacement::centred | RectanglePlacement::onlyReduceInSize)
  36. .appliedTo (image.getBounds(), Rectangle<int> (4, 22, getWidth() - 8, getHeight() - 26));
  37. Path p;
  38. p.addRectangle (area);
  39. DropShadow (Colours::black.withAlpha (0.5f), 6, Point<int> (0, 1)).drawForPath (g, p);
  40. g.fillCheckerBoard (area, 24, 24, Colour (0xffffffff), Colour (0xffeeeeee));
  41. g.setOpacity (1.0f);
  42. g.drawImageWithin (image, area.getX(), area.getY(), area.getWidth(), area.getHeight(),
  43. RectanglePlacement::stretchToFit, false);
  44. g.setFont (Font (14.0f, Font::bold));
  45. g.setColour (findColour (mainBackgroundColourId).contrasting());
  46. g.drawMultiLineText (facts.joinIntoString ("\n"), 10, 15, getWidth() - 16);
  47. }
  48. private:
  49. StringArray facts;
  50. File file;
  51. Image image;
  52. void tryToLoadImage()
  53. {
  54. facts.clear();
  55. facts.add (file.getFullPathName());
  56. image = Image();
  57. ScopedPointer <InputStream> input (file.createInputStream());
  58. if (input != nullptr)
  59. {
  60. const int64 totalSize = input->getTotalLength();
  61. ImageFileFormat* format = ImageFileFormat::findImageFormatForStream (*input);
  62. input = nullptr;
  63. String formatName;
  64. if (format != nullptr)
  65. formatName = " " + format->getFormatName();
  66. image = ImageCache::getFromFile (file);
  67. if (image.isValid())
  68. facts.add (String (image.getWidth()) + " x " + String (image.getHeight()) + formatName);
  69. if (totalSize > 0)
  70. facts.add (File::descriptionOfSizeInBytes (totalSize));
  71. }
  72. facts.removeEmptyStrings (true);
  73. }
  74. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ItemPreviewComponent);
  75. };
  76. #endif // __JUCER_FILEPREVIEWCOMPONENT_JUCEHEADER__