More string editor UI
This commit is contained in:
parent
76bc2b50f8
commit
d6340dced9
|
@ -36,14 +36,36 @@ void CStringDelegate::paint(QPainter* pPainter, const QStyleOptionViewItem& kOpt
|
|||
SDelegateFontInfo FontInfo = GetFontInfo(kOption);
|
||||
QString StringName = kIndex.model()->data(kIndex, Qt::DisplayRole).toString();
|
||||
QString StringText = kIndex.model()->data(kIndex, Qt::UserRole).toString();
|
||||
QRect InnerRect = kOption.rect.adjusted(gkMargin, gkMargin, -gkMargin, -gkMargin);
|
||||
|
||||
// Create font for the string number
|
||||
QFont NumberFont = FontInfo.NameFont;
|
||||
NumberFont.setPixelSize(InnerRect.height() * 0.6);
|
||||
|
||||
// Dumb algorithm to calculate the number of digits
|
||||
int TotalNumStrings = kIndex.model()->rowCount();
|
||||
int NumDigits = 1;
|
||||
|
||||
while (TotalNumStrings >= 10)
|
||||
{
|
||||
TotalNumStrings /= 10;
|
||||
NumDigits++;
|
||||
}
|
||||
|
||||
// Add a buffer of one extra digit
|
||||
NumDigits++;
|
||||
|
||||
int NumberWidth = QFontMetrics(NumberFont).averageCharWidth() * NumDigits;
|
||||
QRect NumRect(InnerRect.left(), InnerRect.top(), NumberWidth, InnerRect.height());
|
||||
|
||||
// Calculate rects
|
||||
int X = kOption.rect.left() + gkMargin;
|
||||
int Width = kOption.rect.width() - (gkMargin * 2);
|
||||
int X = InnerRect.left() + NumberWidth + gkMargin;
|
||||
int Width = InnerRect.width() - (X + gkMargin);
|
||||
int NameHeight = FontInfo.NameFontMetrics.height();
|
||||
int TextHeight = FontInfo.InfoFontMetrics.height();
|
||||
int NameY = kOption.rect.top() + gkMargin;
|
||||
int TextY = NameY + NameHeight + gkSpacing;
|
||||
|
||||
QRect NameRect(X, NameY, Width, NameHeight);
|
||||
QRect TextRect(X, TextY, Width, TextHeight);
|
||||
|
||||
|
@ -57,6 +79,11 @@ void CStringDelegate::paint(QPainter* pPainter, const QStyleOptionViewItem& kOpt
|
|||
pPainter->fillRect( kOption.rect, kOption.palette.highlight() );
|
||||
}
|
||||
|
||||
// Draw number
|
||||
pPainter->setFont(NumberFont);
|
||||
pPainter->setPen(FontInfo.NamePen);
|
||||
pPainter->drawText(NumRect, Qt::AlignCenter, QString::number(kIndex.row() + 1));
|
||||
|
||||
// Draw string info
|
||||
pPainter->setFont(FontInfo.NameFont);
|
||||
pPainter->setPen(FontInfo.NamePen);
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
|
||||
#include "CStringDelegate.h"
|
||||
#include "Editor/UICommon.h"
|
||||
#include "Editor/Widgets/CSizeableTabBar.h"
|
||||
|
||||
#include <QSettings>
|
||||
|
||||
|
@ -23,7 +22,6 @@ CStringEditor::CStringEditor(CStringTable* pStringTable, QWidget* pParent)
|
|||
|
||||
InitUI();
|
||||
LoadSettings();
|
||||
UpdateUI();
|
||||
}
|
||||
|
||||
CStringEditor::~CStringEditor()
|
||||
|
@ -36,54 +34,51 @@ void CStringEditor::InitUI()
|
|||
mpUI->StringNameListView->setModel(mpListModel);
|
||||
mpUI->StringNameListView->setItemDelegate( new CStringDelegate(this) );
|
||||
|
||||
#if 0
|
||||
// Set up language combo box
|
||||
// Set up language tabs
|
||||
mpUI->EditLanguageTabBar->setExpanding(false);
|
||||
|
||||
for (uint LanguageIdx = 0; LanguageIdx < mpStringTable->NumLanguages(); LanguageIdx++)
|
||||
{
|
||||
ELanguage Language = mpStringTable->LanguageByIndex(LanguageIdx);
|
||||
const char* pkLanguageName = TEnumReflection<ELanguage>::ConvertValueToString(Language);
|
||||
mpUI->LanguageComboBox->addItem(pkLanguageName);
|
||||
mpUI->EditLanguageTabBar->addTab(pkLanguageName);
|
||||
}
|
||||
#else
|
||||
QTabBar* pTabBar = new QTabBar(this);
|
||||
pTabBar->setExpanding(false);
|
||||
|
||||
// Set up language combo box
|
||||
for (uint LanguageIdx = 0; LanguageIdx < mpStringTable->NumLanguages(); LanguageIdx++)
|
||||
{
|
||||
ELanguage Language = mpStringTable->LanguageByIndex(LanguageIdx);
|
||||
const char* pkLanguageName = TEnumReflection<ELanguage>::ConvertValueToString(Language);
|
||||
pTabBar->addTab(pkLanguageName);
|
||||
}
|
||||
|
||||
QVBoxLayout* pTabLayout = new QVBoxLayout(mpUI->TabsContainerWidget);
|
||||
pTabLayout->setContentsMargins(0,0,0,0);
|
||||
pTabLayout->addWidget(pTabBar);
|
||||
|
||||
#endif
|
||||
|
||||
// Connect signals & slots
|
||||
connect( mpUI->StringNameListView->selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)),
|
||||
this, SLOT(OnStringSelected(QModelIndex)) );
|
||||
|
||||
// connect( mpUI->LanguageComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(OnLanguageChanged(int)) );
|
||||
connect( pTabBar, SIGNAL(currentChanged(int)), this, SLOT(OnLanguageChanged(int)) );
|
||||
connect( mpUI->EditLanguageTabBar, SIGNAL(currentChanged(int)), this, SLOT(OnLanguageChanged(int)) );
|
||||
|
||||
// Update window title
|
||||
QString WindowTitle = "%APP_FULL_NAME% - String Editor - %1[*]";
|
||||
WindowTitle = WindowTitle.arg( TO_QSTRING(mpStringTable->Entry()->CookedAssetPath(true).GetFileName()) );
|
||||
SET_WINDOWTITLE_APPVARS(WindowTitle);
|
||||
|
||||
// Initialize the splitter so top split takes as much space as possible
|
||||
QList<int> SplitterSizes;
|
||||
SplitterSizes << (height() * 0.95) << (height() * 0.05);
|
||||
mpUI->splitter->setSizes(SplitterSizes);
|
||||
|
||||
// Initialize status bar
|
||||
UpdateStatusBar();
|
||||
}
|
||||
|
||||
void CStringEditor::UpdateStatusBar()
|
||||
{
|
||||
// Update status bar
|
||||
QString StatusText = QString("%1 languages, %2 strings")
|
||||
.arg(mpStringTable->NumLanguages())
|
||||
.arg(mpStringTable->NumStrings());
|
||||
|
||||
mpUI->StatusBar->setStatusTip(StatusText);
|
||||
}
|
||||
if (mCurrentStringIndex >= 0)
|
||||
{
|
||||
StatusText += QString("; editing string #%1 in %2")
|
||||
.arg(mCurrentStringIndex + 1)
|
||||
.arg(TEnumReflection<ELanguage>::ConvertValueToString(mCurrentLanguage));
|
||||
}
|
||||
|
||||
void CStringEditor::UpdateUI()
|
||||
{
|
||||
mpUI->StatusBar->showMessage(StatusText);
|
||||
}
|
||||
|
||||
void CStringEditor::SetActiveLanguage(ELanguage Language)
|
||||
|
@ -94,6 +89,7 @@ void CStringEditor::SetActiveLanguage(ELanguage Language)
|
|||
|
||||
// Force UI to update with the correct string for the new language
|
||||
SetActiveString( mCurrentStringIndex );
|
||||
SaveSettings();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -104,12 +100,24 @@ void CStringEditor::SetActiveString(int StringIndex)
|
|||
TString StringData = mpStringTable->GetString(mCurrentLanguage, mCurrentStringIndex);
|
||||
mpUI->StringNameLineEdit->setText( TO_QSTRING(StringName) );
|
||||
mpUI->StringTextEdit->setPlainText( TO_QSTRING(StringData) );
|
||||
UpdateStatusBar();
|
||||
}
|
||||
|
||||
void CStringEditor::LoadSettings()
|
||||
{
|
||||
QSettings Settings;
|
||||
|
||||
// Set language
|
||||
mCurrentLanguage = (ELanguage) Settings.value(gkpLanguageSetting, (int) ELanguage::English).toInt();
|
||||
|
||||
for (uint LanguageIdx = 0; LanguageIdx < mpStringTable->NumLanguages(); LanguageIdx++)
|
||||
{
|
||||
if (mpStringTable->LanguageByIndex(LanguageIdx) == mCurrentLanguage)
|
||||
{
|
||||
mpUI->EditLanguageTabBar->setCurrentIndex(LanguageIdx);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CStringEditor::SaveSettings()
|
||||
|
|
|
@ -36,7 +36,7 @@ public:
|
|||
explicit CStringEditor(CStringTable* pStringTable, QWidget* pParent = 0);
|
||||
~CStringEditor();
|
||||
void InitUI();
|
||||
void UpdateUI();
|
||||
void UpdateStatusBar();
|
||||
void SetActiveLanguage(ELanguage Language);
|
||||
void SetActiveString(int StringIndex);
|
||||
|
||||
|
|
|
@ -6,8 +6,8 @@
|
|||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>609</width>
|
||||
<height>444</height>
|
||||
<width>512</width>
|
||||
<height>626</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
|
@ -137,7 +137,7 @@
|
|||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QWidget" name="TabsContainerWidget" native="true"/>
|
||||
<widget class="QTabBar" name="EditLanguageTabBar" native="true"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPlainTextEdit" name="StringTextEdit">
|
||||
|
@ -202,6 +202,14 @@
|
|||
</property>
|
||||
</action>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>QTabBar</class>
|
||||
<extends>QWidget</extends>
|
||||
<header location="global">QTabBar</header>
|
||||
<container>1</container>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources>
|
||||
<include location="../Icons.qrc"/>
|
||||
</resources>
|
||||
|
|
Loading…
Reference in New Issue