File indexing completed on 2024-05-05 04:49:29
0001 /**************************************************************************************** 0002 * Copyright (c) 2008 Téo Mrnjavac <teo@kde.org> * 0003 * Copyright (c) 2008-2009 Seb Ruiz <ruiz@kde.org> * 0004 * Copyright (c) 2009 Daniel Dewald <Daniel.Dewald@time-shift.de> * 0005 * * 0006 * This program is free software; you can redistribute it and/or modify it under * 0007 * the terms of the GNU General Public License as published by the Free Software * 0008 * Foundation; either version 2 of the License, or (at your option) any later * 0009 * version. * 0010 * * 0011 * This program is distributed in the hope that it will be useful, but WITHOUT ANY * 0012 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A * 0013 * PARTICULAR PURPOSE. See the GNU General Public License for more details. * 0014 * * 0015 * You should have received a copy of the GNU General Public License along with * 0016 * this program. If not, see <http://www.gnu.org/licenses/>. * 0017 ****************************************************************************************/ 0018 0019 #ifndef AMAROK_TOKEN_H 0020 #define AMAROK_TOKEN_H 0021 0022 #include <QIcon> 0023 #include <QWidget> 0024 #include <QLabel> 0025 #include <QPixmap> 0026 0027 class Token; 0028 class QMimeData; 0029 0030 /** The token factory is used by the TokenDropTarget to create suitable Token objects. 0031 The TokenWithLayout class has it's own TokenFactory to be used with the EditFilterDialog. 0032 */ 0033 class TokenFactory 0034 { 0035 0036 public: 0037 virtual ~TokenFactory() {} 0038 virtual Token* createToken( const QString &text, const QString &iconName, qint64 value, QWidget* parent = nullptr ) const; 0039 virtual Token* createTokenFromMime( const QMimeData* mimeData, QWidget* parent = nullptr ) const; 0040 }; 0041 0042 /** A widget that is used in the FilenameLayoutWidget to display part of a filename 0043 It is drag&droppable in the TokenDropTarget from the TokenPool widget. 0044 0045 Note: A disabled token cannot be dragged. See setEnabled(). 0046 */ 0047 class Token : public QWidget 0048 { 0049 Q_OBJECT 0050 0051 public: 0052 0053 explicit Token( const QString &text, const QString &iconName, qint64 value, QWidget *parent = nullptr ); 0054 0055 QIcon icon() const; 0056 QString iconName() const; 0057 QString name() const; 0058 qint64 value() const; 0059 0060 QColor textColor() const; 0061 void setTextColor( QColor textColor ); 0062 0063 /** Return true if somebody has previously set the text color */ 0064 bool hasCustomColor() const { return m_customColor; } 0065 0066 /** Returns the mime data for this token. 0067 Caller has to free the QMimeData object. 0068 */ 0069 QMimeData* mimeData() const; 0070 0071 /** Returns the mime type for an amarok tag token */ 0072 static QString mimeType(); 0073 0074 QSize sizeHint() const override; 0075 QSize minimumSizeHint() const override; 0076 0077 Q_SIGNALS: 0078 void changed(); 0079 void removed( Token *token ); 0080 0081 /** Emitted when the token get's the focus */ 0082 void gotFocus( Token* thisToken ); 0083 0084 protected: 0085 /** overloaded to update the cursor in case the token is set to inactive */ 0086 void changeEvent( QEvent* event = nullptr ) override; 0087 0088 void focusInEvent( QFocusEvent* event ) override; 0089 0090 void updateCursor(); 0091 0092 /** Handles start of drag. */ 0093 void mousePressEvent( QMouseEvent* event ) override; 0094 0095 /** Handles start of drag. */ 0096 void mouseMoveEvent( QMouseEvent* event ) override; 0097 0098 void paintEvent(QPaintEvent *pe) override; 0099 0100 void performDrag(); 0101 0102 protected: 0103 QString m_name; 0104 QIcon m_icon; 0105 QString m_iconName; 0106 qint64 m_value; // TODO: make this more typesave 0107 bool m_customColor; 0108 0109 QLabel *m_iconContainer; 0110 QLabel *m_label; 0111 0112 /** Position of the mouse press event 0113 (used for drag and drop) */ 0114 QPoint m_startPos; 0115 }; 0116 0117 #endif // AMAROK_TOKEN_H 0118