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.

167 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. const QColor& col = pal.background().color();
  83. return col.blackF() > 0.4 ? col.lighter(160) : col.darker(140);
  84. }
  85. QColor highlightedOutline(const QPalette &pal) const
  86. {
  87. QColor highlightedOutline = highlight(pal).darker(125);
  88. if (highlightedOutline.value() > 160)
  89. highlightedOutline.setHsl(highlightedOutline.hue(), highlightedOutline.saturation(), 160);
  90. return highlightedOutline;
  91. }
  92. QColor tabFrameColor(const QPalette& pal) const
  93. {
  94. if (! pal.button().texture().isNull())
  95. return QColor(255, 255, 255, 8);
  96. return buttonColor(pal).lighter(104);
  97. }
  98. QColor buttonColor(const QPalette& pal) const
  99. {
  100. QColor buttonColor = pal.button().color();
  101. const int val = qGray(buttonColor.rgb());
  102. buttonColor = buttonColor.lighter(100 + qMax(1, (180 - val)/6));
  103. buttonColor.setHsv(buttonColor.hue(), buttonColor.saturation() * 0.75, buttonColor.value());
  104. return buttonColor;
  105. }
  106. QIcon tabBarcloseButtonIcon;
  107. QList<const QObject*> animationTargets() const
  108. {
  109. return fAnimations.keys();
  110. }
  111. CarlaStyleAnimation* animation(const QObject* target) const
  112. {
  113. return fAnimations.value(target);
  114. }
  115. void startAnimation(CarlaStyleAnimation* animation) const
  116. {
  117. stopAnimation(animation->target());
  118. fStyle->connect(animation, SIGNAL(destroyed()), SLOT(_removeAnimation()), Qt::UniqueConnection);
  119. fAnimations.insert(animation->target(), animation);
  120. animation->start();
  121. }
  122. void stopAnimation(const QObject* target) const
  123. {
  124. CarlaStyleAnimation* const animation = fAnimations.take(target);
  125. if (animation != nullptr && animation->state() != QAbstractAnimation::Stopped)
  126. animation->stop();
  127. }
  128. private:
  129. CarlaStyle* const fStyle;
  130. int fAnimationFps;
  131. mutable QHash<const QObject*, CarlaStyleAnimation*> fAnimations;
  132. private slots:
  133. void _removeAnimation()
  134. {
  135. if (QObject* const animation = fStyle->sender())
  136. fAnimations.remove(animation->parent());
  137. }
  138. };
  139. #endif // CARLA_STYLE_PRIVATE_HPP_INCLUDED