File indexing completed on 2024-04-28 04:32:09

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  * @file
0013  * Header file for the SymbolListWidget class.
0014  */
0015 
0016 #ifndef SymbolListWidget_H
0017 #define SymbolListWidget_H
0018 
0019 #include <QListWidget>
0020 
0021 class SymbolLibrary;
0022 class Symbol;
0023 
0024 /**
0025  * @brief An extension to the QListWidget to view and select Symbols.
0026  *
0027  * This widget is an extension to the QListWidget that can be populated from
0028  * a SymbolLibrary to display the contained Symbols and allow selection of one
0029  * of the Symbols for further processing.
0030  *
0031  * Additional Symbols can be added individually and all Symbols will be sorted
0032  * in the view by their index value.
0033  *
0034  * Symbols can be removed by their index value.
0035  */
0036 class SymbolListWidget : public QListWidget
0037 {
0038 public:
0039     explicit SymbolListWidget(QWidget *parent);
0040     virtual ~SymbolListWidget() = default;
0041 
0042     void setIconSize(int size);
0043     void loadFromLibrary(SymbolLibrary *library);
0044     QListWidgetItem *addSymbol(qint16 index, const Symbol &symbol);
0045     void enableItem(qint16 index);
0046     void disableItem(qint16 index);
0047     void removeSymbol(qint16 index);
0048     void setCurrent(qint16 index);
0049 
0050     static QIcon createIcon(const Symbol &symbol, int size);
0051 
0052 protected:
0053     virtual bool event(QEvent *e) Q_DECL_OVERRIDE;
0054 
0055 private:
0056     QListWidgetItem *createItem(qint16 index);
0057     void updateIcons();
0058 
0059     int m_size; /**< size of icons generated in the view */
0060     SymbolLibrary *m_library; /**< pointer to the library the items belong to */
0061 
0062     qint16 m_lastIndex; /**< the last index in the list */
0063 
0064     QMap<qint16, QListWidgetItem *> m_items; /**< map of index to QListWidgetItem */
0065 };
0066 
0067 #endif