PrimeWorldEditor/UI/WStringPreviewPanel.cpp

51 lines
1.3 KiB
C++
Raw Normal View History

#include "WStringPreviewPanel.h"
#include <QFontMetrics>
#include <QTextLayout>
#include <Resource/CStringTable.h>
WStringPreviewPanel::WStringPreviewPanel(QWidget *pParent) : IPreviewPanel(pParent)
{
mpLayout = new QVBoxLayout(this);
mpLayout->setAlignment(Qt::AlignTop);
mpLayout->setSpacing(0);
setLayout(mpLayout);
}
WStringPreviewPanel::~WStringPreviewPanel()
{
}
2015-07-28 05:47:48 +00:00
QSize WStringPreviewPanel::sizeHint() const
{
return QSize(400, 0);
}
EResType WStringPreviewPanel::ResType()
{
return eStringTable;
}
void WStringPreviewPanel::SetResource(CResource *pRes)
{
foreach(const QLabel *pLabel, mLabels)
delete pLabel;
mLabels.clear();
2015-07-28 05:47:48 +00:00
if (pRes && (pRes->Type() == eStringTable))
{
CStringTable *pString = static_cast<CStringTable*>(pRes);
mLabels.reserve(pString->GetStringCount());
2015-07-28 05:47:48 +00:00
for (u32 iStr = 0; iStr < pString->GetStringCount(); iStr++)
{
QString text = QString::fromStdWString(pString->GetString(0, iStr));
QLabel *pLabel = new QLabel(text, this);
pLabel->setWordWrap(true);
pLabel->setFrameStyle(QFrame::Plain | QFrame::Box);
pLabel->setMargin(3);
mLabels.push_back(pLabel);
mpLayout->addWidget(pLabel);
}
}
}