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.

CarlaStylePrivate.hpp 4.3KB

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