SubWindow.h 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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 "export.h"
  36. class QMoveEvent;
  37. class QResizeEvent;
  38. class QWidget;
  39. class EXPORT SubWindow : public QMdiSubWindow
  40. {
  41. Q_OBJECT
  42. Q_PROPERTY( QBrush activeColor READ activeColor WRITE setActiveColor )
  43. Q_PROPERTY( QColor textShadowColor READ textShadowColor WRITE setTextShadowColor )
  44. Q_PROPERTY( QColor borderColor READ borderColor WRITE setBorderColor )
  45. public:
  46. SubWindow( QWidget *parent = NULL, Qt::WindowFlags windowFlags = 0 );
  47. // same as QWidet::normalGeometry, but works properly under X11 (see https://bugreports.qt.io/browse/QTBUG-256)
  48. QRect getTrueNormalGeometry() const;
  49. QBrush activeColor() const;
  50. QColor textShadowColor() const;
  51. QColor borderColor() const;
  52. void setActiveColor( const QBrush & b );
  53. void setTextShadowColor( const QColor &c );
  54. void setBorderColor( const QColor &c );
  55. protected:
  56. // hook the QWidget move/resize events to update the tracked geometry
  57. virtual void moveEvent( QMoveEvent * event );
  58. virtual void resizeEvent( QResizeEvent * event );
  59. virtual void paintEvent( QPaintEvent * pe );
  60. virtual void changeEvent( QEvent * event );
  61. private:
  62. const QSize m_buttonSize;
  63. const int m_titleBarHeight;
  64. QPushButton * m_closeBtn;
  65. QPushButton * m_maximizeBtn;
  66. QPushButton * m_restoreBtn;
  67. QBrush m_activeColor;
  68. QColor m_textShadowColor;
  69. QColor m_borderColor;
  70. QPoint m_position;
  71. QRect m_trackedNormalGeom;
  72. QLabel * m_windowTitle;
  73. QGraphicsDropShadowEffect * m_shadow;
  74. static void elideText( QLabel *label, QString text );
  75. void adjustTitleBar();
  76. };
  77. #endif