SubWindow.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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 <QPainter>
  33. #include <QPushButton>
  34. #include <QString>
  35. #include "lmms_export.h"
  36. class QMoveEvent;
  37. class QResizeEvent;
  38. class QWidget;
  39. /**
  40. * @brief The SubWindow class
  41. *
  42. * Because of a bug in the QMdiSubWindow class to save the right position and size
  43. * of a subwindow in a project and because of the inability
  44. * for cusomizing the title bar appearance, lmms implements its own subwindow
  45. * class.
  46. */
  47. class LMMS_EXPORT SubWindow : public QMdiSubWindow
  48. {
  49. Q_OBJECT
  50. Q_PROPERTY( QBrush activeColor READ activeColor WRITE setActiveColor )
  51. Q_PROPERTY( QColor textShadowColor READ textShadowColor WRITE setTextShadowColor )
  52. Q_PROPERTY( QColor borderColor READ borderColor WRITE setBorderColor )
  53. public:
  54. SubWindow( QWidget *parent = NULL, Qt::WindowFlags windowFlags = 0 );
  55. // same as QWidet::normalGeometry, but works properly under X11 (see https://bugreports.qt.io/browse/QTBUG-256)
  56. QRect getTrueNormalGeometry() const;
  57. QBrush activeColor() const;
  58. QColor textShadowColor() const;
  59. QColor borderColor() const;
  60. void setActiveColor( const QBrush & b );
  61. void setTextShadowColor( const QColor &c );
  62. void setBorderColor( const QColor &c );
  63. protected:
  64. // hook the QWidget move/resize events to update the tracked geometry
  65. virtual void moveEvent( QMoveEvent * event );
  66. virtual void resizeEvent( QResizeEvent * event );
  67. virtual void paintEvent( QPaintEvent * pe );
  68. virtual void changeEvent( QEvent * event );
  69. signals:
  70. void focusLost();
  71. private:
  72. const QSize m_buttonSize;
  73. const int m_titleBarHeight;
  74. QPushButton * m_closeBtn;
  75. QPushButton * m_maximizeBtn;
  76. QPushButton * m_restoreBtn;
  77. QBrush m_activeColor;
  78. QColor m_textShadowColor;
  79. QColor m_borderColor;
  80. QPoint m_position;
  81. QRect m_trackedNormalGeom;
  82. QLabel * m_windowTitle;
  83. QGraphicsDropShadowEffect * m_shadow;
  84. bool m_hasFocus;
  85. static void elideText( QLabel *label, QString text );
  86. bool isMaximized();
  87. void adjustTitleBar();
  88. private slots:
  89. void focusChanged( QMdiSubWindow * subWindow );
  90. };
  91. #endif