OBSHotkeyLabel.cpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /******************************************************************************
  2. Copyright (C) 2014-2015 by Ruwen Hahn <[email protected]>
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation, either version 2 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. ******************************************************************************/
  14. #include "OBSHotkeyLabel.hpp"
  15. #include "OBSHotkeyWidget.hpp"
  16. #include <QEnterEvent>
  17. #include <QStyle>
  18. #include "moc_OBSHotkeyLabel.cpp"
  19. static inline void updateStyle(QWidget *widget)
  20. {
  21. auto style = widget->style();
  22. style->unpolish(widget);
  23. style->polish(widget);
  24. widget->update();
  25. }
  26. void OBSHotkeyLabel::highlightPair(bool highlight)
  27. {
  28. if (!pairPartner)
  29. return;
  30. pairPartner->setProperty("class", highlight ? "text-bright" : "");
  31. updateStyle(pairPartner);
  32. setProperty("class", highlight ? "text-bright" : "");
  33. updateStyle(this);
  34. }
  35. void OBSHotkeyLabel::enterEvent(QEnterEvent *event)
  36. {
  37. if (!pairPartner)
  38. return;
  39. event->accept();
  40. highlightPair(true);
  41. }
  42. void OBSHotkeyLabel::leaveEvent(QEvent *event)
  43. {
  44. if (!pairPartner)
  45. return;
  46. event->accept();
  47. highlightPair(false);
  48. }
  49. void OBSHotkeyLabel::setToolTip(const QString &toolTip)
  50. {
  51. QLabel::setToolTip(toolTip);
  52. if (widget)
  53. widget->setToolTip(toolTip);
  54. }