#pragma once #include "FractoriumPch.h" /// /// EmberTreeWidgetItem /// /// /// A thin derivation of QTreeWidgetItem for a tree of embers in an open file. /// The tree is intended to contain one open ember file at a time. /// This is a non-templated base for casting purposes. /// class EmberTreeWidgetItemBase : public QTreeWidgetItem { public: /// /// Constructor that takes a pointer to a QTreeWidget as a parent widget. /// This is meant to be a root level item. /// /// The parent widget of this item explicit EmberTreeWidgetItemBase(QTreeWidget* p) : QTreeWidgetItem(p) { } /// /// Constructor that takes a pointer to a QTreeWidgetItem as a parent widget. /// This is meant to be the child of a root level item. /// /// The parent widget of this item explicit EmberTreeWidgetItemBase(QTreeWidgetItem* p) : QTreeWidgetItem(p) { } /// /// Set the preview image for the tree widget item. /// /// The vector containing the RGB pixels [0..255] which will make up the preview image /// The width of the image in pixels /// The height of the image in pixels void SetImage(vector& v, uint width, uint height) { int size = 64; m_Image = QImage(width, height, QImage::Format_RGBA8888); memcpy(m_Image.scanLine(0), v.data(), SizeOf(v));//Memcpy the data in. m_Pixmap = QPixmap::fromImage(m_Image).scaled(QSize(size, size), Qt::IgnoreAspectRatio, Qt::SmoothTransformation);//Create a QPixmap out of the QImage, scaled to size. setData(0, Qt::DecorationRole, m_Pixmap); } protected: QImage m_Image; QPixmap m_Pixmap; }; /// /// A thin derivation of QTreeWidgetItem for a tree of embers in an open file. /// The tree is intended to contain one open ember file at a time. /// template class EmberTreeWidgetItem : public EmberTreeWidgetItemBase { public: /// /// Constructor that takes a pointer to an ember and a QTreeWidget as a parent widget. /// This is meant to be a root level item. /// /// A pointer to the ember this item will represent /// The parent widget of this item explicit EmberTreeWidgetItem(Ember* ember, QTreeWidget* p = nullptr) : EmberTreeWidgetItemBase(p), m_Ember(ember) { setFlags(Qt::ItemIsEnabled | Qt::ItemIsEditable | Qt::ItemIsSelectable | Qt::ItemIsDragEnabled); setCheckState(0, Qt::Unchecked); } /// /// Constructor that takes a pointer to an ember and a QTreeWidgetItem as a parent widget. /// This is meant to be the child of a root level item. /// /// A pointer to the ember this item will represent /// The parent widget of this item explicit EmberTreeWidgetItem(Ember* ember, QTreeWidgetItem* p = nullptr) : EmberTreeWidgetItemBase(p), m_Ember(ember) { setFlags(Qt::ItemIsEnabled | Qt::ItemIsEditable | Qt::ItemIsSelectable | Qt::ItemIsDragEnabled); setCheckState(0, Qt::Unchecked); } /// /// Copy the text of the tree item to the name of the ember. /// void UpdateEmberName() { m_Ember->m_Name = text(0).toStdString(); } /// /// Set the text of the tree item. /// void UpdateEditText() { setText(0, QString::fromStdString(m_Ember->m_Name)); } /// /// Get a pointer to the ember held by the tree item. /// Ember* GetEmber() const { return m_Ember; } /// /// Perform a deep copy from the passed in ember to the dereferenced /// ember pointer of the tree item. /// /// The ember to copy void SetEmber(Ember& ember) { *m_Ember = ember; } /// /// Set the ember pointer member to point to the passed in ember pointer. /// /// The ember to point to void SetEmberPointer(Ember* ember) { m_Ember = ember; } private: Ember* m_Ember; };