Commit 28461e23 authored by Yann Boucher's avatar Yann Boucher
Browse files

Added a preview of structures

parent d1ad2ab7
......@@ -106,9 +106,45 @@
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Size : </string>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QLabel" name="struct_size">
<property name="text">
<string/>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QLabel" name="preview">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>2</verstretch>
</sizepolicy>
</property>
<property name="frameShape">
<enum>QFrame::Box</enum>
</property>
<property name="lineWidth">
<number>0</number>
</property>
<property name="text">
<string/>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="button_copy">
<property name="enabled">
......
......@@ -31,6 +31,7 @@ private:
void load_structures();
QTreeWidgetItem *add_directory_contents(const QDir& dir);
bool load_structure(const QString& filename, Structure& s);
void update_preview(const Structure& s);
private slots:
void update_info(QTreeWidgetItem* item, int column);
......
#N Gosper glider gun
#C This was the first gun discovered.
#O Bill Gosper
x = 36, y = 9, rule = B3/S23
24bo$22bobo$12b2o6b2o12b2o$11bo3bo4b2o12b2o$2o8bo5bo3b2o$2o8bo3bob2o4b
obo$10bo5bo7bo$11bo3bo$12b2o!
\ No newline at end of file
......@@ -116,11 +116,12 @@ GridView::GridView(QWidget *parent)
m_view = new GridGraphicsView(*this, this);
m_view->setRenderHint(QPainter::Antialiasing, false);
m_view->setDragMode(QGraphicsView::RubberBandDrag);
m_view->setOptimizationFlags(QGraphicsView::DontSavePainterState);
m_view->setOptimizationFlags(QGraphicsView::DontSavePainterState|QGraphicsView::DontAdjustForAntialiasing);
m_view->setViewportUpdateMode(QGraphicsView::SmartViewportUpdate);
m_view->setTransformationAnchor(QGraphicsView::AnchorUnderMouse);
m_view->setScene(m_scene);
m_view->viewport()->setCursor(Qt::ArrowCursor);
m_view->setBackgroundBrush(QBrush(Qt::gray));
detail::Graphics_view_zoom* z = new detail::Graphics_view_zoom(m_view);
(void)z;
......
......@@ -8,6 +8,8 @@
#include <QFile>
#include <QTextStream>
#include <QPixmap>
#include <QImage>
#include <QDebug>
StructureLibraryView::StructureLibraryView(QWidget *parent) :
......@@ -122,6 +124,23 @@ bool StructureLibraryView::load_structure(const QString &filename, Structure &s)
return false;
}
void StructureLibraryView::update_preview(const Structure &s)
{
QPixmap pix;
QImage img(s.width(), s.height(), QImage::Format_RGB32);
img.fill(Qt::white);
for (const auto& cell : s)
img.setPixel(cell.first.x, cell.first.y, Qt::black);
/** to check wether load ok */
if(pix.convertFromImage(img)){
/** 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);
}
}
void StructureLibraryView::update_info(QTreeWidgetItem *item, int column)
{
(void)column;
......@@ -136,7 +155,7 @@ void StructureLibraryView::update_info(QTreeWidgetItem *item, int column)
ui->struct_title->setText(QString::fromStdString(s.title));
else
{
QString filename = QFileInfo(item->data(0, Qt::UserRole).toString()).fileName();
QString filename = QFileInfo(item->data(0, Qt::UserRole).toString()).baseName();
if (!filename.isEmpty()) // failsafe, in case it actually is empty
filename.replace(0, 1, filename[0].toUpper());
ui->struct_title->setText(filename);
......@@ -144,6 +163,9 @@ void StructureLibraryView::update_info(QTreeWidgetItem *item, int column)
ui->struct_author->setText(QString::fromStdString(s.author));
ui->struct_date->setText(QString::fromStdString(s.date));
ui->struct_desc->setPlainText(QString::fromStdString(s.desc));
ui->struct_size->setText(QString::number(s.width()) + "x" + QString::number(s.height()));
update_preview(s);
ui->button_copy->setEnabled(true);
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment