File indexing completed on 2024-05-05 04:48:42
0001 /**************************************************************************************** 0002 * Copyright (c) 2009 Téo Mrnjavac <teo@kde.org> * 0003 * * 0004 * This program is free software; you can redistribute it and/or modify it under * 0005 * the terms of the GNU General Public License as published by the Free Software * 0006 * Foundation; either version 2 of the License, or (at your option) any later * 0007 * version. * 0008 * * 0009 * This program is distributed in the hope that it will be useful, but WITHOUT ANY * 0010 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A * 0011 * PARTICULAR PURPOSE. See the GNU General Public License for more details. * 0012 * * 0013 * You should have received a copy of the GNU General Public License along with * 0014 * this program. If not, see <http://www.gnu.org/licenses/>. * 0015 ****************************************************************************************/ 0016 0017 #ifndef PLAYLISTBREADCRUMBITEMSORTBUTTON_H 0018 #define PLAYLISTBREADCRUMBITEMSORTBUTTON_H 0019 0020 #include "widgets/BreadcrumbItemButton.h" 0021 0022 #include <QRect> 0023 0024 namespace Playlist 0025 { 0026 0027 /** 0028 * A button that implements the non-menu part of the playlist breadcrumb item. 0029 * @author Téo Mrnjavac <teo@kde.org> 0030 */ 0031 class BreadcrumbItemSortButton : public BreadcrumbItemButton 0032 { 0033 Q_OBJECT 0034 0035 public: 0036 /** 0037 * Constructor. 0038 * @param parent the parent QWidget. 0039 */ 0040 explicit BreadcrumbItemSortButton( QWidget *parent ); 0041 0042 /** 0043 * Constructor, nontrivial. 0044 * @param icon the icon to paint on the button. 0045 * @param text the text to show on the button. 0046 * @param parent the parent QWidget. 0047 */ 0048 BreadcrumbItemSortButton( const QIcon &icon, const QString &text, QWidget *parent ); 0049 0050 /** 0051 * Destructor. 0052 */ 0053 ~BreadcrumbItemSortButton() override; 0054 0055 /** 0056 * Returns the recommended size for the button depending on the contents. 0057 * @return the recommended size. 0058 */ 0059 QSize sizeHint() const override; 0060 0061 /** 0062 * Returns the state of the sort order defined by the order inversion arrow. 0063 * @return the sort order. 0064 */ 0065 Qt::SortOrder orderState() const; 0066 0067 /** 0068 * Flips the Qt::SortOrder. 0069 */ 0070 void invertOrder(); 0071 0072 Q_SIGNALS: 0073 /** 0074 * Emitted when the order inversion arrow has been toggled. 0075 * @p sortOrder the new sort order based on the position of the arrow. 0076 */ 0077 void arrowToggled( Qt::SortOrder ); 0078 0079 protected: 0080 /** 0081 * Repaints the widget. 0082 * @param event the triggered QPaintEvent as provided by Qt. 0083 */ 0084 void paintEvent( QPaintEvent *event ) override; 0085 0086 /** 0087 * Checks if the mouse is hovering the arrow rectangle. 0088 * @param e the triggered QMouseEvent as provided by Qt. 0089 */ 0090 void mouseMoveEvent( QMouseEvent *e ) override; 0091 0092 /** 0093 * Handles the beginning of a mouse click. 0094 * @param e the triggered QMouseEvent as provided by Qt. 0095 */ 0096 void mousePressEvent( QMouseEvent *e ) override; 0097 0098 /** 0099 * Handles the release of the mouse button which completes a click action. 0100 * @param e the triggered QMouseEvent as provided by Qt. 0101 */ 0102 void mouseReleaseEvent( QMouseEvent *e ) override; 0103 0104 /** 0105 * Reimplemented from BreadcrumbItemButton, handles the painting of the widget's 0106 * background, used by paintEvent(). 0107 * @param painter the QPainter object used by paintEvent(). 0108 */ 0109 void drawHoverBackground( QPainter *painter ) override; 0110 0111 private: 0112 /** 0113 * Common initialization method, called by every constructor. 0114 */ 0115 void init(); 0116 Qt::SortOrder m_order; 0117 QRect m_arrowRect; //!< the QRect that contains the order inversion arrow primitive. 0118 QPoint m_pressedPos; //!< the position of the last mousePressEvent, for handling clicks. 0119 bool m_arrowPressed; 0120 bool m_arrowHovered; //!< is the arrow rect hovered? 0121 int m_arrowWidth; 0122 int m_arrowHeight; 0123 }; 0124 0125 } //namespace Playlist 0126 0127 #endif //PLAYLISTBREADCRUMBITEMSORTBUTTON_H