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.

166 lines
4.6KB

  1. /*
  2. * Carla Style, based on Qt5 fusion style
  3. * Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies)
  4. * Copyright (C) 2013-2014 Filipe Coelho <falktx@falktx.com>
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU Lesser General Public License for more details.
  14. *
  15. * For a full copy of the license see the doc/LGPL.txt file
  16. */
  17. #ifndef CARLA_STYLE_PRIVATE_HPP_INCLUDED
  18. #define CARLA_STYLE_PRIVATE_HPP_INCLUDED
  19. #include "CarlaStyle.hpp"
  20. #include "CarlaStyleAnimations.hpp"
  21. #include <QtCore/QHash>
  22. class QStyleAnimation;
  23. class CarlaStylePrivate : public QObject
  24. {
  25. #if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0)) && defined(__clang_major__) && __clang_major__ >= 4
  26. # pragma clang diagnostic push
  27. # pragma clang diagnostic ignored "-Winconsistent-missing-override"
  28. #endif
  29. Q_OBJECT
  30. #if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0)) && defined(__clang_major__) && __clang_major__ >= 4
  31. # pragma clang diagnostic pop
  32. #endif
  33. public:
  34. enum {
  35. menuItemHMargin = 3, // menu item hor text margin
  36. menuArrowHMargin = 6, // menu arrow horizontal margin
  37. menuRightBorder = 15, // right border on menus
  38. menuCheckMarkWidth = 12 // checkmarks width on menus
  39. };
  40. CarlaStylePrivate(CarlaStyle* const style)
  41. : fStyle(style),
  42. fAnimationFps(60)
  43. {
  44. }
  45. ~CarlaStylePrivate() override
  46. {
  47. qDeleteAll(fAnimations);
  48. }
  49. int animationFps() const
  50. {
  51. return fAnimationFps;
  52. }
  53. // Used for grip handles
  54. QColor lightShade() const
  55. {
  56. return QColor(255, 255, 255, 36);
  57. }
  58. QColor darkShade() const
  59. {
  60. return QColor(0, 0, 0, 60);
  61. }
  62. QColor topShadow() const
  63. {
  64. return QColor(0, 0, 0, 18);
  65. }
  66. QColor innerContrastLine() const
  67. {
  68. return QColor(255, 255, 255, 30);
  69. }
  70. QColor highlight(const QPalette& pal) const
  71. {
  72. return pal.color(QPalette::Active, QPalette::Highlight);
  73. }
  74. QColor highlightedText(const QPalette& pal) const
  75. {
  76. return pal.color(QPalette::Active, QPalette::HighlightedText);
  77. }
  78. QColor outline(const QPalette& pal) const
  79. {
  80. if (! pal.window().texture().isNull())
  81. return QColor(0, 0, 0, 160);
  82. return pal.background().color().darker(140);
  83. }
  84. QColor highlightedOutline(const QPalette &pal) const
  85. {
  86. QColor highlightedOutline = highlight(pal).darker(125);
  87. if (highlightedOutline.value() > 160)
  88. highlightedOutline.setHsl(highlightedOutline.hue(), highlightedOutline.saturation(), 160);
  89. return highlightedOutline;
  90. }
  91. QColor tabFrameColor(const QPalette& pal) const
  92. {
  93. if (! pal.button().texture().isNull())
  94. return QColor(255, 255, 255, 8);
  95. return buttonColor(pal).lighter(104);
  96. }
  97. QColor buttonColor(const QPalette& pal) const
  98. {
  99. QColor buttonColor = pal.button().color();
  100. const int val = qGray(buttonColor.rgb());
  101. buttonColor = buttonColor.lighter(100 + qMax(1, (180 - val)/6));
  102. buttonColor.setHsv(buttonColor.hue(), buttonColor.saturation() * 0.75, buttonColor.value());
  103. return buttonColor;
  104. }
  105. QIcon tabBarcloseButtonIcon;
  106. QList<const QObject*> animationTargets() const
  107. {
  108. return fAnimations.keys();
  109. }
  110. CarlaStyleAnimation* animation(const QObject* target) const
  111. {
  112. return fAnimations.value(target);
  113. }
  114. void startAnimation(CarlaStyleAnimation* animation) const
  115. {
  116. stopAnimation(animation->target());
  117. fStyle->connect(animation, SIGNAL(destroyed()), SLOT(_removeAnimation()), Qt::UniqueConnection);
  118. fAnimations.insert(animation->target(), animation);
  119. animation->start();
  120. }
  121. void stopAnimation(const QObject* target) const
  122. {
  123. CarlaStyleAnimation* const animation = fAnimations.take(target);
  124. if (animation != nullptr && animation->state() != QAbstractAnimation::Stopped)
  125. animation->stop();
  126. }
  127. private:
  128. CarlaStyle* const fStyle;
  129. int fAnimationFps;
  130. mutable QHash<const QObject*, CarlaStyleAnimation*> fAnimations;
  131. private slots:
  132. void _removeAnimation()
  133. {
  134. if (QObject* const animation = fStyle->sender())
  135. fAnimations.remove(animation->parent());
  136. }
  137. };
  138. #endif // CARLA_STYLE_PRIVATE_HPP_INCLUDED