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.

111 lines
3.5KB

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