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.

86 lines
2.7KB

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