TabWidget.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /*
  2. * TabWidget.h - LMMS-tabwidget
  3. *
  4. * Copyright (c) 2005-2008 Tobias Doerffel <tobydox/at/users.sourceforge.net>
  5. *
  6. * This file is part of LMMS - https://lmms.io
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public
  10. * License as published by the Free Software Foundation; either
  11. * version 2 of the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public
  19. * License along with this program (see COPYING); if not, write to the
  20. * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  21. * Boston, MA 02110-1301 USA.
  22. *
  23. */
  24. #ifndef TAB_WIDGET_H
  25. #define TAB_WIDGET_H
  26. #include <QWidget>
  27. #include <QtCore/QMap>
  28. const int TEXT_TAB_HEIGHT = 14;
  29. const int GRAPHIC_TAB_HEIGHT = 17;
  30. class TabWidget : public QWidget
  31. {
  32. Q_OBJECT
  33. public:
  34. //! @param resizable If true, the widget resizes to fit the size of all tabs
  35. //! If false, all child widget will be cut down to the TabWidget's size
  36. TabWidget( const QString & _caption, QWidget * _parent,
  37. bool usePixmap = false, bool resizable = false );
  38. virtual ~TabWidget() = default;
  39. void addTab( QWidget * w, const QString & name, const char *pixmap = nullptr, int idx = -1 );
  40. void setActiveTab( int idx );
  41. int findTabAtPos( const QPoint *pos );
  42. inline int activeTab() const
  43. {
  44. return( m_activeTab );
  45. }
  46. // Themeability
  47. Q_PROPERTY( QColor tabText READ tabText WRITE setTabText)
  48. Q_PROPERTY( QColor tabTitleText READ tabTitleText WRITE setTabTitleText)
  49. Q_PROPERTY( QColor tabSelected READ tabSelected WRITE setTabSelected)
  50. Q_PROPERTY( QColor tabBackground READ tabBackground WRITE setTabBackground)
  51. Q_PROPERTY( QColor tabBorder READ tabBorder WRITE setTabBorder)
  52. QColor tabText() const;
  53. void setTabText( const QColor & c );
  54. QColor tabTitleText() const;
  55. void setTabTitleText( const QColor & c );
  56. QColor tabSelected() const;
  57. void setTabSelected( const QColor & c );
  58. QColor tabBackground() const;
  59. void setTabBackground( const QColor & c );
  60. QColor tabBorder() const;
  61. void setTabBorder( const QColor & c );
  62. protected:
  63. bool event( QEvent * event ) override;
  64. void mousePressEvent( QMouseEvent * _me ) override;
  65. void paintEvent( QPaintEvent * _pe ) override;
  66. void resizeEvent( QResizeEvent * _re ) override;
  67. void wheelEvent( QWheelEvent * _we ) override;
  68. QSize minimumSizeHint() const override;
  69. QSize sizeHint() const override;
  70. private:
  71. struct widgetDesc
  72. {
  73. QWidget * w; // ptr to widget
  74. const char * pixmap; // artwork for the widget
  75. QString name; // name for widget
  76. int nwidth; // width of name when painting (only valid for text tab)
  77. } ;
  78. typedef QMap<int, widgetDesc> widgetStack;
  79. widgetStack m_widgets;
  80. bool m_resizable;
  81. int m_activeTab;
  82. QString m_caption; // Tab caption, used as the tooltip text on icon tabs
  83. quint8 m_tabbarHeight; // The height of the tab bar
  84. quint8 m_tabheight; // The height of the tabs
  85. bool m_usePixmap; // true if the tabs are to be displayed with icons. False for text tabs.
  86. QColor m_tabText; // The color of the tabs' text.
  87. QColor m_tabTitleText; // The color of the TabWidget's title text.
  88. QColor m_tabSelected; // The highlighting color for the selected tab.
  89. QColor m_tabBackground; // The TabWidget's background color.
  90. QColor m_tabBorder; // The TabWidget's borders color.
  91. } ;
  92. #endif