1 #include "previewfiledialog.h"
4 #include <QPainterPath>
6 #include "charwindow.h"
8 #include "glyphpoints.h"
11 PreviewFileDialog::PreviewFileDialog(
13 const QString & caption,
14 const QString & directory,
15 const QString & filter):
16 QFileDialog(parent, caption, directory, filter)
18 setObjectName("PreviewFileDialog");
19 QVBoxLayout * box = new QVBoxLayout;
21 mpPreview = new QLabel(tr("Preview"), this);
22 mpPreview->setAlignment(Qt::AlignCenter);
23 mpPreview->setObjectName("labelPreview");
24 box->addWidget(mpPreview);
28 // add to QFileDialog layout
30 QGridLayout * layout = (QGridLayout *)this->layout();
31 layout->addLayout(box, 1, 3, 3, 1);
34 connect(this, SIGNAL(currentChanged(const QString &)), this, SLOT(HandleCurrentChanged(const QString &)));
38 void PreviewFileDialog::HandleCurrentChanged(const QString & path)
40 if (path.endsWith(".glyph") == false)
44 QPainterPath * glyphPath = NULL;
45 FILE * fp = fopen(path.toUtf8().data(), "r");
49 if (gp.LoadGlyphFromFile(fp) == true)
50 glyphPath = Global::charWnd->MakePathFromPoints(&gp);
55 QImage glyphImg(160, 160, QImage::Format_RGBA8888);
56 glyphImg.fill(Qt::transparent);
57 Global::charWnd->RenderPathInImage(glyphPath, &glyphImg);
58 QPixmap pixmap = QPixmap::fromImage(glyphImg);
60 if (pixmap.isNull() == false)
62 mpPreview->setPixmap(pixmap);//.scaled(mpPreview->width(), mpPreview->height(), Qt::KeepAspectRatio, Qt::SmoothTransformation));
66 // mpPreview->setText(QString("not an image"));//<br>%1").arg(path));