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.

131 lines
4.1KB

  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. BEGIN_JUCE_NAMESPACE
  19. //==============================================================================
  20. HyperlinkButton::HyperlinkButton (const String& linkText,
  21. const URL& linkURL)
  22. : Button (linkText),
  23. url (linkURL),
  24. font (14.0f, Font::underlined),
  25. resizeFont (true),
  26. justification (Justification::centred)
  27. {
  28. setMouseCursor (MouseCursor::PointingHandCursor);
  29. setTooltip (linkURL.toString (false));
  30. }
  31. HyperlinkButton::HyperlinkButton ()
  32. : Button (String::empty),
  33. font (14.0f, Font::underlined),
  34. resizeFont (true),
  35. justification (Justification::centred)
  36. {
  37. setMouseCursor (MouseCursor::PointingHandCursor);
  38. }
  39. HyperlinkButton::~HyperlinkButton()
  40. {
  41. }
  42. //==============================================================================
  43. void HyperlinkButton::setFont (const Font& newFont,
  44. const bool resizeToMatchComponentHeight,
  45. const Justification& justificationType)
  46. {
  47. font = newFont;
  48. resizeFont = resizeToMatchComponentHeight;
  49. justification = justificationType;
  50. repaint();
  51. }
  52. void HyperlinkButton::setURL (const URL& newURL) noexcept
  53. {
  54. url = newURL;
  55. setTooltip (newURL.toString (false));
  56. }
  57. Font HyperlinkButton::getFontToUse() const
  58. {
  59. Font f (font);
  60. if (resizeFont)
  61. f.setHeight (getHeight() * 0.7f);
  62. return f;
  63. }
  64. void HyperlinkButton::changeWidthToFitText()
  65. {
  66. setSize (getFontToUse().getStringWidth (getName()) + 6, getHeight());
  67. }
  68. void HyperlinkButton::colourChanged()
  69. {
  70. repaint();
  71. }
  72. //==============================================================================
  73. void HyperlinkButton::clicked()
  74. {
  75. if (url.isWellFormed())
  76. url.launchInDefaultBrowser();
  77. }
  78. void HyperlinkButton::paintButton (Graphics& g,
  79. bool isMouseOverButton,
  80. bool isButtonDown)
  81. {
  82. const Colour textColour (findColour (textColourId));
  83. if (isEnabled())
  84. g.setColour ((isMouseOverButton) ? textColour.darker ((isButtonDown) ? 1.3f : 0.4f)
  85. : textColour);
  86. else
  87. g.setColour (textColour.withMultipliedAlpha (0.4f));
  88. g.setFont (getFontToUse());
  89. g.drawText (getButtonText(),
  90. 2, 0, getWidth() - 2, getHeight(),
  91. justification.getOnlyHorizontalFlags() | Justification::verticallyCentred,
  92. true);
  93. }
  94. const Identifier HyperlinkButton::Ids::tagType ("HYPERLINKBUTTON");
  95. const Identifier HyperlinkButton::Ids::text ("text");
  96. const Identifier HyperlinkButton::Ids::url ("url");
  97. void HyperlinkButton::refreshFromValueTree (const ValueTree& state, ComponentBuilder&)
  98. {
  99. ComponentBuilder::refreshBasicComponentProperties (*this, state);
  100. setButtonText (state [Ids::text].toString());
  101. setURL (URL (state [Ids::url].toString()));
  102. }
  103. END_JUCE_NAMESPACE