Audio plugin host https://kx.studio/carla
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.

juce_HyperlinkButton.cpp 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE 6 technical preview.
  4. Copyright (c) 2020 - Raw Material Software Limited
  5. You may use this code under the terms of the GPL v3
  6. (see www.gnu.org/licenses).
  7. For this technical preview, this file is not subject to commercial licensing.
  8. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  9. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  10. DISCLAIMED.
  11. ==============================================================================
  12. */
  13. namespace juce
  14. {
  15. HyperlinkButton::HyperlinkButton (const String& linkText,
  16. const URL& linkURL)
  17. : Button (linkText),
  18. url (linkURL),
  19. font (14.0f, Font::underlined),
  20. resizeFont (true),
  21. justification (Justification::centred)
  22. {
  23. setMouseCursor (MouseCursor::PointingHandCursor);
  24. setTooltip (linkURL.toString (false));
  25. }
  26. HyperlinkButton::HyperlinkButton()
  27. : Button (String()),
  28. font (14.0f, Font::underlined),
  29. resizeFont (true),
  30. justification (Justification::centred)
  31. {
  32. setMouseCursor (MouseCursor::PointingHandCursor);
  33. }
  34. HyperlinkButton::~HyperlinkButton()
  35. {
  36. }
  37. //==============================================================================
  38. void HyperlinkButton::setFont (const Font& newFont,
  39. const bool resizeToMatchComponentHeight,
  40. Justification justificationType)
  41. {
  42. font = newFont;
  43. resizeFont = resizeToMatchComponentHeight;
  44. justification = justificationType;
  45. repaint();
  46. }
  47. void HyperlinkButton::setURL (const URL& newURL) noexcept
  48. {
  49. url = newURL;
  50. setTooltip (newURL.toString (false));
  51. }
  52. Font HyperlinkButton::getFontToUse() const
  53. {
  54. if (resizeFont)
  55. return font.withHeight (getHeight() * 0.7f);
  56. return font;
  57. }
  58. void HyperlinkButton::changeWidthToFitText()
  59. {
  60. setSize (getFontToUse().getStringWidth (getButtonText()) + 6, getHeight());
  61. }
  62. void HyperlinkButton::setJustificationType (Justification newJustification)
  63. {
  64. if (justification != newJustification)
  65. {
  66. justification = newJustification;
  67. repaint();
  68. }
  69. }
  70. void HyperlinkButton::colourChanged()
  71. {
  72. repaint();
  73. }
  74. //==============================================================================
  75. void HyperlinkButton::clicked()
  76. {
  77. if (url.isWellFormed())
  78. url.launchInDefaultBrowser();
  79. }
  80. void HyperlinkButton::paintButton (Graphics& g,
  81. bool shouldDrawButtonAsHighlighted,
  82. bool shouldDrawButtonAsDown)
  83. {
  84. const Colour textColour (findColour (textColourId));
  85. if (isEnabled())
  86. g.setColour ((shouldDrawButtonAsHighlighted) ? textColour.darker ((shouldDrawButtonAsDown) ? 1.3f : 0.4f)
  87. : textColour);
  88. else
  89. g.setColour (textColour.withMultipliedAlpha (0.4f));
  90. g.setFont (getFontToUse());
  91. g.drawText (getButtonText(), getLocalBounds().reduced (1, 0),
  92. justification.getOnlyHorizontalFlags() | Justification::verticallyCentred,
  93. true);
  94. }
  95. } // namespace juce