diff --git a/include/structurelibraryview.hpp b/include/structurelibraryview.hpp index 1b1523e05a5120d945946fe666e1d62d52894a51..b8040f9674ce28f77e7ae602bb84da3442d63fa0 100644 --- a/include/structurelibraryview.hpp +++ b/include/structurelibraryview.hpp @@ -16,6 +16,7 @@ Widget de la bibliothèque de structures. #include <QFileSystemWatcher> #include "structure.hpp" +#include "alphabet.hpp" namespace Ui { class StructureLibraryView; @@ -32,6 +33,10 @@ public: explicit StructureLibraryView(QWidget *parent = nullptr); ~StructureLibraryView(); + //! \brief Spécifie l'alphabet à utiliser pour les couleurs de la preview + void set_alphabet(const Alphabet& alph) + { m_alph = alph; } + signals: //! \brief Signal émis lorsqu'une structure de la bibliothèque est copiée. //! \param s La structure copiée. @@ -47,7 +52,7 @@ private: QTreeWidgetItem *add_directory_contents(const QDir& dir); bool try_load_structure(const QString& filename, Structure& s); void update_preview(const Structure& s); - QImage create_preview_image(const Structure &s, QColor background); + QImage create_preview_image(const Structure &s, bool transparent); void create_drag(QTreeWidgetItem* item, int column); private slots: @@ -58,6 +63,7 @@ private: Ui::StructureLibraryView *ui; QFileSystemWatcher m_watcher; unsigned m_cell_pixel_size; + Alphabet m_alph; }; #endif // STRUCTURELIBRARYVIEW_HPP diff --git a/src/interface.cpp b/src/interface.cpp index 06791c865b750af62c88adfbb2a37364bfe4149c..2c8c170c5829b39f78ab125eddd580274781bf8b 100644 --- a/src/interface.cpp +++ b/src/interface.cpp @@ -501,6 +501,7 @@ void MainWindow::load_from_image() void MainWindow::ui_update_alphabet(const Alphabet &alpha) { simulation.setAlphabet(alpha); + ui->struct_library->set_alphabet(alpha); ui->grid_view->set_alphabet(alpha); ui->nbrStateComboBox->clear(); for (unsigned i = 0; i < alpha.taille(); ++i) diff --git a/src/structurelibraryview.cpp b/src/structurelibraryview.cpp index 7bd4b165335f655a7018a1f30268c9077f3e3d0a..7314f1142e777b835c55ad8d3ab1420ceb2bf13c 100644 --- a/src/structurelibraryview.cpp +++ b/src/structurelibraryview.cpp @@ -117,19 +117,26 @@ void StructureLibraryView::update_preview(const Structure &s) QPixmap pix; /** to check wether load ok */ - if(pix.convertFromImage(create_preview_image(s, Qt::white))){ + if(pix.convertFromImage(create_preview_image(s, false))){ /** scale pixmap to fit in label'size and keep ratio of pixmap */ pix = pix.scaled(ui->preview->size() - 2*QSize(ui->preview->lineWidth(), ui->preview->lineWidth()),Qt::KeepAspectRatio); ui->preview->setPixmap(pix); } } -QImage StructureLibraryView::create_preview_image(const Structure &s, QColor background) +QImage StructureLibraryView::create_preview_image(const Structure &s, bool transparent) { + stateColor bg = m_alph.getState(0).getColor(); QImage img(s.width(), s.height(), QImage::Format_ARGB32); - img.fill(background); + if (transparent) + img.fill(Qt::transparent); + else + img.fill(Qt::white); for (const auto& cell : s) - img.setPixelColor(cell.first.x, cell.first.y, QColor(Qt::black)); + { + stateColor s_c = m_alph.getState(cell.second % m_alph.taille()).getColor(); + img.setPixelColor(cell.first.x, cell.first.y, QColor(s_c.getRed(), s_c.getGreen(), s_c.getBlue())); + } return img; } @@ -193,7 +200,7 @@ void StructureLibraryView::create_drag(QTreeWidgetItem *item, int column) QString filename = QFileInfo(item->data(0, Qt::UserRole).toString()).absoluteFilePath(); QPixmap pix; - QImage img = create_preview_image(s, Qt::transparent); + QImage img = create_preview_image(s, true); pix.convertFromImage(img);