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.

187 lines
5.0KB

  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. static inline
  23. const QColor& qt_palette_bg_color(const QPalette& pal)
  24. {
  25. #if (QT_VERSION >= QT_VERSION_CHECK(5, 13, 0))
  26. return pal.window().color();
  27. #else
  28. return pal.background().color();
  29. #endif
  30. }
  31. static inline
  32. const QColor& qt_palette_fg_color(const QPalette& pal)
  33. {
  34. #if (QT_VERSION >= QT_VERSION_CHECK(5, 13, 0))
  35. return pal.windowText().color();
  36. #else
  37. return pal.foreground().color();
  38. #endif
  39. }
  40. class QStyleAnimation;
  41. class CarlaStylePrivate : public QObject
  42. {
  43. #if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0)) && defined(__clang_major__) && __clang_major__ >= 4
  44. # pragma clang diagnostic push
  45. # pragma clang diagnostic ignored "-Winconsistent-missing-override"
  46. #endif
  47. Q_OBJECT
  48. #if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0)) && defined(__clang_major__) && __clang_major__ >= 4
  49. # pragma clang diagnostic pop
  50. #endif
  51. public:
  52. enum {
  53. menuItemHMargin = 3, // menu item hor text margin
  54. menuArrowHMargin = 6, // menu arrow horizontal margin
  55. menuRightBorder = 15, // right border on menus
  56. menuCheckMarkWidth = 12 // checkmarks width on menus
  57. };
  58. CarlaStylePrivate(CarlaStyle* const style)
  59. : fStyle(style),
  60. fAnimationFps(60)
  61. {
  62. }
  63. ~CarlaStylePrivate() override
  64. {
  65. qDeleteAll(fAnimations);
  66. }
  67. int animationFps() const
  68. {
  69. return fAnimationFps;
  70. }
  71. // Used for grip handles
  72. QColor lightShade() const
  73. {
  74. return QColor(255, 255, 255, 36);
  75. }
  76. QColor darkShade() const
  77. {
  78. return QColor(0, 0, 0, 60);
  79. }
  80. QColor topShadow() const
  81. {
  82. return QColor(0, 0, 0, 18);
  83. }
  84. QColor innerContrastLine() const
  85. {
  86. return QColor(255, 255, 255, 30);
  87. }
  88. QColor highlight(const QPalette& pal) const
  89. {
  90. return pal.color(QPalette::Active, QPalette::Highlight);
  91. }
  92. QColor highlightedText(const QPalette& pal) const
  93. {
  94. return pal.color(QPalette::Active, QPalette::HighlightedText);
  95. }
  96. QColor outline(const QPalette& pal) const
  97. {
  98. if (! pal.window().texture().isNull())
  99. return QColor(0, 0, 0, 160);
  100. const QColor& col = qt_palette_bg_color(pal);
  101. return col.blackF() > 0.4 ? col.lighter(160) : col.darker(140);
  102. }
  103. QColor highlightedOutline(const QPalette &pal) const
  104. {
  105. QColor highlightedOutline = highlight(pal).darker(125);
  106. if (highlightedOutline.value() > 160)
  107. highlightedOutline.setHsl(highlightedOutline.hue(), highlightedOutline.saturation(), 160);
  108. return highlightedOutline;
  109. }
  110. QColor tabFrameColor(const QPalette& pal) const
  111. {
  112. if (! pal.button().texture().isNull())
  113. return QColor(255, 255, 255, 8);
  114. return buttonColor(pal).lighter(104);
  115. }
  116. QColor buttonColor(const QPalette& pal) const
  117. {
  118. QColor buttonColor = pal.button().color();
  119. const int val = qGray(buttonColor.rgb());
  120. buttonColor = buttonColor.lighter(100 + qMax(1, (180 - val)/6));
  121. buttonColor.setHsv(buttonColor.hue(), buttonColor.saturation() * 0.75, buttonColor.value());
  122. return buttonColor;
  123. }
  124. QIcon tabBarcloseButtonIcon;
  125. QList<const QObject*> animationTargets() const
  126. {
  127. return fAnimations.keys();
  128. }
  129. CarlaStyleAnimation* animation(const QObject* target) const
  130. {
  131. return fAnimations.value(target);
  132. }
  133. void startAnimation(CarlaStyleAnimation* animation) const
  134. {
  135. stopAnimation(animation->target());
  136. fStyle->connect(animation, SIGNAL(destroyed()), SLOT(_removeAnimation()), Qt::UniqueConnection);
  137. fAnimations.insert(animation->target(), animation);
  138. animation->start();
  139. }
  140. void stopAnimation(const QObject* target) const
  141. {
  142. CarlaStyleAnimation* const animation = fAnimations.take(target);
  143. if (animation != nullptr && animation->state() != QAbstractAnimation::Stopped)
  144. animation->stop();
  145. }
  146. private:
  147. CarlaStyle* const fStyle;
  148. int fAnimationFps;
  149. mutable QHash<const QObject*, CarlaStyleAnimation*> fAnimations;
  150. private slots:
  151. void _removeAnimation()
  152. {
  153. if (QObject* const animation = fStyle->sender())
  154. fAnimations.remove(animation->parent());
  155. }
  156. };
  157. #endif // CARLA_STYLE_PRIVATE_HPP_INCLUDED