SubWindow.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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 = NULL, Qt::WindowFlags windowFlags = 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. public slots:
  63. void detach();
  64. void attach();
  65. protected:
  66. // hook the QWidget move/resize events to update the tracked geometry
  67. void moveEvent( QMoveEvent * event ) override;
  68. void resizeEvent( QResizeEvent * event ) override;
  69. void paintEvent( QPaintEvent * pe ) override;
  70. void changeEvent( QEvent * event ) override;
  71. void showEvent( QShowEvent* event ) override;
  72. bool eventFilter( QObject * obj, QEvent * event ) override;
  73. bool isDetached() const;
  74. signals:
  75. void focusLost();
  76. private:
  77. const QSize m_buttonSize;
  78. const int m_titleBarHeight;
  79. QPushButton * m_closeBtn;
  80. QPushButton * m_maximizeBtn;
  81. QPushButton * m_restoreBtn;
  82. QPushButton * m_detachBtn;
  83. QBrush m_activeColor;
  84. QColor m_textShadowColor;
  85. QColor m_borderColor;
  86. QPoint m_position;
  87. QRect m_trackedNormalGeom;
  88. QLabel * m_windowTitle;
  89. QGraphicsDropShadowEffect * m_shadow;
  90. bool m_hasFocus;
  91. static void elideText( QLabel *label, QString text );
  92. void adjustTitleBar();
  93. private slots:
  94. void focusChanged( QMdiSubWindow * subWindow );
  95. };
  96. #endif