Repository navigation
Expand file tree
/
Copy pathpreviewwidget.cpp
More file actions
88 lines (75 loc) · 2.89 KB
/
Copy pathpreviewwidget.cpp
File metadata and controls
88 lines (75 loc) · 2.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#include "previewwidget.h"
void PreviewWidget::resizeEvent(QResizeEvent *event)
{
Q_UNUSED(event);
// qDebug() << "Widget: W:" << event->size().width() << "H:" << event->size().height();
// qDebug() << "Scene: W:" << this->scene->width() << "H:" << this->scene->height();
// qDebug() << "View: W:" << this->view->width() << "H:" << this->view->height();
// i->setPlainText(QString("View Width: %1, Height: %2.").arg(this->view->width()).arg(this->view->height()));
// QRectF r = i->boundingRect();
// QSize v(this->view->width() - 20, this->view->height() - 20);
// QFont f = i->font();
// if(v.width() > v.height()){
// if(r.width() > r.height()){
// if(r.width() > v.width() && r.height() < v.height()){
// this->view->scale((qreal)v.width() / (qreal)r.width(), (qreal)v.width() / (qreal)r.width());
// }else if(r.width() > v.width() && r.height() > v.height()){
// qreal widthScale = v.width() / r.width();
// qreal heightScale = v.height() / r.height();
// this->view->scale(qMin(widthScale, heightScale), qMin(widthScale, heightScale));
// }else if(r.width() < v.width() && r.height() < v.height()){
// this->view->scale((qreal)v.width() / (qreal)r.width(), (qreal)v.width() / (qreal)r.width());
// }else if(r.width() < v.width() && r.height() > v.height()){
// qreal widthScale = v.width() / r.width();
// qreal heightScale = v.height() / r.height();
// this->view->scale(qMin(widthScale, heightScale), qMin(widthScale, heightScale));
// }
// }
// }
}
PreviewWidget::PreviewWidget(QWidget *parent) : QWidget(parent)
{
this->groupBox = new QGroupBox(tr("Preview"), this);
this->scene = new QGraphicsScene(this);
this->view = new QGraphicsView(this->scene, this);
QVBoxLayout *lay = new QVBoxLayout;
this->groupBox->setLayout(lay);
lay->addWidget(this->view);
QVBoxLayout *mainLay = new QVBoxLayout;
this->setLayout(mainLay);
mainLay->addWidget(this->groupBox);
QFont font;{
font.setFamily("A-OTF Folk Pro M, Microsoft YaHei");
font.setPixelSize(52);
}
i = new QGraphicsTextItem;
i->setPlainText("カンジ メーカー");
i->setFont(font);
//i->setFlag(QGraphicsItem::ItemIsMovable, true);
this->scene->addItem(i);
this->view->resize(this->scene->width(), this->scene->height());
}
void PreviewWidget::setKana(const QString &kana)
{
Q_UNUSED(kana);
//TODO: this function will fill after fix the preview widget scale problem.
}
void PreviewWidget::setKanji(const QString &kanji)
{
this->i->setPlainText(kanji);
QFont font = this->i->font();
//font.setPixelSize(40);
this->i->setFont(font);
this->i->setPos((this->view->size().width() - this->i->boundingRect().width()) * 0.5f,
(this->view->size().height() - this->i->boundingRect().height()) * 0.5f);
}
void PreviewWidget::setFontSize(int pixelSize)
{
QFont fnt = this->i->font();
fnt.setPixelSize(pixelSize);
this->i->setFont(fnt);
}
void PreviewWidget::setKanjiSlot(QString kanji)
{
this->setKanji(kanji);
}