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.2KB

10 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. /*
  2. * Carla Style, based on Qt5 fusion style
  3. * Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies)
  4. * Copyright (C) 2013 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. Q_OBJECT
  26. public:
  27. enum {
  28. menuItemHMargin = 3, // menu item hor text margin
  29. menuArrowHMargin = 6, // menu arrow horizontal margin
  30. menuRightBorder = 15, // right border on menus
  31. menuCheckMarkWidth = 12 // checkmarks width on menus
  32. };
  33. CarlaStylePrivate(CarlaStyle* const style)
  34. : fStyle(style),
  35. fAnimationFps(60)
  36. {
  37. }
  38. ~CarlaStylePrivate() override
  39. {
  40. qDeleteAll(fAnimations);
  41. }
  42. int animationFps() const
  43. {
  44. return fAnimationFps;
  45. }
  46. // Used for grip handles
  47. QColor lightShade() const
  48. {
  49. return QColor(102, 102, 102, 90);
  50. }
  51. QColor darkShade() const
  52. {
  53. return QColor(0, 0, 0, 60);
  54. }
  55. QColor topShadow() const
  56. {
  57. return QColor(0, 0, 0, 18);
  58. }
  59. QColor innerContrastLine() const
  60. {
  61. return QColor(255, 255, 255, 30);
  62. }
  63. QColor highlight(const QPalette& pal) const
  64. {
  65. return pal.color(QPalette::Active, QPalette::Highlight);
  66. }
  67. QColor highlightedText(const QPalette& pal) const
  68. {
  69. return pal.color(QPalette::Active, QPalette::HighlightedText);
  70. }
  71. QColor outline(const QPalette& pal) const
  72. {
  73. if (! pal.window().texture().isNull())
  74. return QColor(0, 0, 0, 160);
  75. return pal.background().color().darker(140);
  76. }
  77. QColor highlightedOutline(const QPalette &pal) const
  78. {
  79. QColor highlightedOutline = highlight(pal).darker(125);
  80. if (highlightedOutline.value() > 160)
  81. highlightedOutline.setHsl(highlightedOutline.hue(), highlightedOutline.saturation(), 160);
  82. return highlightedOutline;
  83. }
  84. QColor tabFrameColor(const QPalette& pal) const
  85. {
  86. if (! pal.button().texture().isNull())
  87. return QColor(255, 255, 255, 8);
  88. return buttonColor(pal).lighter(104);
  89. }
  90. QColor buttonColor(const QPalette& pal) const
  91. {
  92. QColor buttonColor = pal.button().color();
  93. const int val = qGray(buttonColor.rgb());
  94. buttonColor = buttonColor.lighter(100 + qMax(1, (180 - val)/6));
  95. buttonColor.setHsv(buttonColor.hue(), buttonColor.saturation() * 0.75, buttonColor.value());
  96. return buttonColor;
  97. }
  98. QIcon tabBarcloseButtonIcon;
  99. QList<const QObject*> animationTargets() const
  100. {
  101. return fAnimations.keys();
  102. }
  103. CarlaStyleAnimation* animation(const QObject* target) const
  104. {
  105. return fAnimations.value(target);
  106. }
  107. void startAnimation(CarlaStyleAnimation* animation) const
  108. {
  109. stopAnimation(animation->target());
  110. fStyle->connect(animation, SIGNAL(destroyed()), SLOT(_removeAnimation()), Qt::UniqueConnection);
  111. fAnimations.insert(animation->target(), animation);
  112. animation->start();
  113. }
  114. void stopAnimation(const QObject* target) const
  115. {
  116. CarlaStyleAnimation* const animation = fAnimations.take(target);
  117. if (animation != nullptr && animation->state() != QAbstractAnimation::Stopped)
  118. animation->stop();
  119. }
  120. private:
  121. CarlaStyle* const fStyle;
  122. int fAnimationFps;
  123. mutable QHash<const QObject*, CarlaStyleAnimation*> fAnimations;
  124. private slots:
  125. void _removeAnimation()
  126. {
  127. if (QObject* const animation = fStyle->sender())
  128. fAnimations.remove(animation->parent());
  129. }
  130. };
  131. #endif // CARLA_STYLE_PRIVATE_HPP_INCLUDED