SubWindow.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*
  2. * SubWindow.h - Implementation of QMdiSubWindow that correctly tracks
  3. * the geometry that windows should be restored to.
  4. * Workaround for https://bugreports.qt.io/browse/QTBUG-256
  5. *
  6. * Copyright (c) 2015 Colin Wallace <wallace.colin.a@gmail.com>
  7. *
  8. * This file is part of LMMS - https://lmms.io
  9. *
  10. * This program is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU General Public
  12. * License as published by the Free Software Foundation; either
  13. * version 2 of the License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18. * General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public
  21. * License along with this program (see COPYING); if not, write to the
  22. * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  23. * Boston, MA 02110-1301 USA.
  24. *
  25. */
  26. #ifndef SUBWINDOW_H
  27. #define SUBWINDOW_H
  28. #include <QEvent>
  29. #include <QGraphicsDropShadowEffect>
  30. #include <QMdiSubWindow>
  31. #include <QLabel>
  32. #include <QPushButton>
  33. #include <QString>
  34. #include "lmms_export.h"
  35. class QMoveEvent;
  36. class QResizeEvent;
  37. class QWidget;
  38. /**
  39. * @brief The SubWindow class
  40. *
  41. * Because of a bug in the QMdiSubWindow class to save the right position and size
  42. * of a subwindow in a project and because of the inability
  43. * for cusomizing the title bar appearance, lmms implements its own subwindow
  44. * class.
  45. */
  46. class LMMS_EXPORT SubWindow : public QMdiSubWindow
  47. {
  48. Q_OBJECT
  49. Q_PROPERTY( QBrush activeColor READ activeColor WRITE setActiveColor )
  50. Q_PROPERTY( QColor textShadowColor READ textShadowColor WRITE setTextShadowColor )
  51. Q_PROPERTY( QColor borderColor READ borderColor WRITE setBorderColor )
  52. public:
  53. SubWindow( QWidget *parent = nullptr, Qt::WindowFlags windowFlags = QFlag(0) );
  54. // same as QWidet::normalGeometry, but works properly under X11 (see https://bugreports.qt.io/browse/QTBUG-256)
  55. QRect getTrueNormalGeometry() const;
  56. QBrush activeColor() const;
  57. QColor textShadowColor() const;
  58. QColor borderColor() const;
  59. void setActiveColor( const QBrush & b );
  60. void setTextShadowColor( const QColor &c );
  61. void setBorderColor( const QColor &c );
  62. protected:
  63. // hook the QWidget move/resize events to update the tracked geometry
  64. void moveEvent( QMoveEvent * event ) override;
  65. void resizeEvent( QResizeEvent * event ) override;
  66. void paintEvent( QPaintEvent * pe ) override;
  67. void changeEvent( QEvent * event ) override;
  68. signals:
  69. void focusLost();
  70. private:
  71. const QSize m_buttonSize;
  72. const int m_titleBarHeight;
  73. QPushButton * m_closeBtn;
  74. QPushButton * m_maximizeBtn;
  75. QPushButton * m_restoreBtn;
  76. QBrush m_activeColor;
  77. QColor m_textShadowColor;
  78. QColor m_borderColor;
  79. QPoint m_position;
  80. QRect m_trackedNormalGeom;
  81. QLabel * m_windowTitle;
  82. QGraphicsDropShadowEffect * m_shadow;
  83. bool m_hasFocus;
  84. static void elideText( QLabel *label, QString text );
  85. void adjustTitleBar();
  86. private slots:
  87. void focusChanged( QMdiSubWindow * subWindow );
  88. };
  89. #endif