File indexing completed on 2025-03-16 13:13:04
0001 /******************************************************************************** 0002 * Copyright (C) 2012-2015 by Stephen Allewell * 0003 * steve.allewell@gmail.com * 0004 * * 0005 * This program is free software; you can redistribute it and/or modify * 0006 * it under the terms of the GNU General Public License as published by * 0007 * the Free Software Foundation; either version 2 of the License, or * 0008 * (at your option) any later version. * 0009 ********************************************************************************/ 0010 0011 0012 /** 0013 * @file 0014 * Header file for the SymbolListWidget class. 0015 */ 0016 0017 0018 #ifndef SymbolListWidget_H 0019 #define SymbolListWidget_H 0020 0021 0022 #include <QListWidget> 0023 0024 0025 class QMimeData; 0026 0027 class SymbolLibrary; 0028 class Symbol; 0029 0030 0031 /** 0032 * @brief An extension to the QListWidget to view and select Symbols. 0033 * 0034 * This widget is an extension to the QListWidget that can be populated from 0035 * a SymbolLibrary to display the contained Symbols and allow selection of one 0036 * of the Symbols for further processing. 0037 * 0038 * Additional Symbols can be added individually and all Symbols will be sorted 0039 * in the view by their index value. 0040 * 0041 * Symbols can be removed by their index value. 0042 */ 0043 class SymbolListWidget : public QListWidget 0044 { 0045 public: 0046 explicit SymbolListWidget(QWidget *parent); 0047 ~SymbolListWidget(); 0048 0049 void setIconSize(int size); 0050 void loadFromLibrary(SymbolLibrary *library); 0051 void addSymbol(qint16 index, const Symbol &symbol); 0052 void removeSymbol(qint16 index); 0053 0054 static QIcon createIcon(const Symbol &symbol, int size); 0055 0056 protected: 0057 virtual QStringList mimeTypes() const; 0058 virtual Qt::DropActions supportedDropActions() const; 0059 virtual QMimeData *mimeData(const QList<QListWidgetItem *> items) const; 0060 virtual bool dropMimeData(int index, const QMimeData *mimeData, Qt::DropAction action); 0061 virtual bool event(QEvent *e); 0062 0063 private: 0064 QListWidgetItem *createItem(qint16 index); 0065 void updateIcons(); 0066 0067 int m_size; /**< size of icons generated in the view */ 0068 SymbolLibrary *m_library; /**< pointer to the library the items belong to */ 0069 0070 qint16 m_lastIndex; /**< the last index in the list */ 0071 0072 QMap<qint16, QListWidgetItem*> m_items; /**< map of index to QListWidgetItem */ 0073 }; 0074 0075 0076 #endif