File indexing completed on 2024-05-05 04:49:29

0001 /****************************************************************************************
0002  * Copyright (c) 2008 Téo Mrnjavac <teo@kde.org>                                        *
0003  * Copyright (c) 2009 Seb Ruiz <ruiz@kde.org>                                           *
0004  *                                                                                      *
0005  * This program is free software; you can redistribute it and/or modify it under        *
0006  * the terms of the GNU General Public License as published by the Free Software        *
0007  * Foundation; either version 2 of the License, or (at your option) any later           *
0008  * version.                                                                             *
0009  *                                                                                      *
0010  * This program is distributed in the hope that it will be useful, but WITHOUT ANY      *
0011  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A      *
0012  * PARTICULAR PURPOSE. See the GNU General Public License for more details.             *
0013  *                                                                                      *
0014  * You should have received a copy of the GNU General Public License along with         *
0015  * this program.  If not, see <http://www.gnu.org/licenses/>.                           *
0016  ****************************************************************************************/
0017 
0018 #ifndef TOKENPOOL_H
0019 #define TOKENPOOL_H
0020 
0021 #include "Token.h"
0022 
0023 #include <QListWidget>
0024 #include <QMap>
0025 
0026 //Holds a number of icons representing parts of the filename that will become tokens when dropped on the TokenLayoutWidget.
0027 class TokenPool : public QListWidget
0028 {
0029     Q_OBJECT
0030 
0031     public:
0032         explicit TokenPool( QWidget *parent = nullptr );
0033 
0034         /** Adds the \p token into the token pool.
0035             The TokenPool takes ownership of the token.
0036             Note: The color of the token representation is determined by the text color of the token at the time
0037             it is added.
0038         */
0039         void addToken( Token * token );
0040 
0041         QSize sizeHint() const override;
0042     protected:
0043         void mouseDoubleClickEvent( QMouseEvent *event ) override;
0044 
0045         /** Handles start of drag. */
0046         void mousePressEvent( QMouseEvent *event ) override;
0047 
0048         /** Handles start of drag. */
0049         void mouseMoveEvent( QMouseEvent *event ) override;
0050         void dragEnterEvent( QDragEnterEvent *event ) override;
0051         // void dragMoveEvent( QDragMoveEvent *event );
0052         void dropEvent( QDropEvent *event ) override;
0053 
0054     Q_SIGNALS:
0055         /** Emitted if somebody double clicks a token.
0056             The token parameter belongs to the token pool. Don't reparent it.
0057         */
0058         void onDoubleClick( Token *token );
0059 
0060     private:
0061         void performDrag();
0062 
0063         /** Position of the mouse press event
0064             (used for drag and drop) */
0065         QPoint m_startPos;
0066 
0067         QMap<QListWidgetItem*,Token*> m_itemTokenMap;
0068 };
0069 
0070 #endif
0071