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.

78 lines
2.7KB

  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. #include "../jucer_Headers.h"
  19. #include "jucer_FilePreviewComponent.h"
  20. //==============================================================================
  21. ItemPreviewComponent::ItemPreviewComponent (const File& file_)
  22. : file (file_)
  23. {
  24. tryToLoadImage();
  25. }
  26. void ItemPreviewComponent::tryToLoadImage()
  27. {
  28. facts.clear();
  29. facts.add (file.getFullPathName());
  30. image = Image();
  31. ScopedPointer <InputStream> input (file.createInputStream());
  32. if (input != nullptr)
  33. {
  34. const int64 totalSize = input->getTotalLength();
  35. ImageFileFormat* format = ImageFileFormat::findImageFormatForStream (*input);
  36. input = nullptr;
  37. String formatName;
  38. if (format != nullptr)
  39. formatName = " " + format->getFormatName();
  40. image = ImageCache::getFromFile (file);
  41. if (image.isValid())
  42. facts.add (String (image.getWidth()) + " x " + String (image.getHeight()) + formatName);
  43. if (totalSize > 0)
  44. facts.add (File::descriptionOfSizeInBytes (totalSize));
  45. }
  46. facts.removeEmptyStrings (true);
  47. }
  48. void ItemPreviewComponent::paint (Graphics& g)
  49. {
  50. g.drawImageWithin (image, 2, 22, getWidth() - 4, getHeight() - 24,
  51. RectanglePlacement::centred | RectanglePlacement::onlyReduceInSize,
  52. false);
  53. g.setFont (15.0f, Font::bold);
  54. g.setColour (Colours::white);
  55. g.drawMultiLineText (facts.joinIntoString ("\n"),
  56. 10, 15, getWidth() - 16);
  57. }