More string editor UI

This commit is contained in:
Aruki 2018-12-27 00:00:43 -07:00
parent 76bc2b50f8
commit d6340dced9
4 changed files with 77 additions and 34 deletions

View File

@ -36,14 +36,36 @@ void CStringDelegate::paint(QPainter* pPainter, const QStyleOptionViewItem& kOpt
SDelegateFontInfo FontInfo = GetFontInfo(kOption); SDelegateFontInfo FontInfo = GetFontInfo(kOption);
QString StringName = kIndex.model()->data(kIndex, Qt::DisplayRole).toString(); QString StringName = kIndex.model()->data(kIndex, Qt::DisplayRole).toString();
QString StringText = kIndex.model()->data(kIndex, Qt::UserRole).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 // Calculate rects
int X = kOption.rect.left() + gkMargin; int X = InnerRect.left() + NumberWidth + gkMargin;
int Width = kOption.rect.width() - (gkMargin * 2); int Width = InnerRect.width() - (X + gkMargin);
int NameHeight = FontInfo.NameFontMetrics.height(); int NameHeight = FontInfo.NameFontMetrics.height();
int TextHeight = FontInfo.InfoFontMetrics.height(); int TextHeight = FontInfo.InfoFontMetrics.height();
int NameY = kOption.rect.top() + gkMargin; int NameY = kOption.rect.top() + gkMargin;
int TextY = NameY + NameHeight + gkSpacing; int TextY = NameY + NameHeight + gkSpacing;
QRect NameRect(X, NameY, Width, NameHeight); QRect NameRect(X, NameY, Width, NameHeight);
QRect TextRect(X, TextY, Width, TextHeight); 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() ); 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 // Draw string info
pPainter->setFont(FontInfo.NameFont); pPainter->setFont(FontInfo.NameFont);
pPainter->setPen(FontInfo.NamePen); pPainter->setPen(FontInfo.NamePen);

View File

@ -3,7 +3,6 @@
#include "CStringDelegate.h" #include "CStringDelegate.h"
#include "Editor/UICommon.h" #include "Editor/UICommon.h"
#include "Editor/Widgets/CSizeableTabBar.h"
#include <QSettings> #include <QSettings>
@ -23,7 +22,6 @@ CStringEditor::CStringEditor(CStringTable* pStringTable, QWidget* pParent)
InitUI(); InitUI();
LoadSettings(); LoadSettings();
UpdateUI();
} }
CStringEditor::~CStringEditor() CStringEditor::~CStringEditor()
@ -36,54 +34,51 @@ void CStringEditor::InitUI()
mpUI->StringNameListView->setModel(mpListModel); mpUI->StringNameListView->setModel(mpListModel);
mpUI->StringNameListView->setItemDelegate( new CStringDelegate(this) ); mpUI->StringNameListView->setItemDelegate( new CStringDelegate(this) );
#if 0 // Set up language tabs
// Set up language combo box mpUI->EditLanguageTabBar->setExpanding(false);
for (uint LanguageIdx = 0; LanguageIdx < mpStringTable->NumLanguages(); LanguageIdx++) for (uint LanguageIdx = 0; LanguageIdx < mpStringTable->NumLanguages(); LanguageIdx++)
{ {
ELanguage Language = mpStringTable->LanguageByIndex(LanguageIdx); ELanguage Language = mpStringTable->LanguageByIndex(LanguageIdx);
const char* pkLanguageName = TEnumReflection<ELanguage>::ConvertValueToString(Language); 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 signals & slots
connect( mpUI->StringNameListView->selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)), connect( mpUI->StringNameListView->selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)),
this, SLOT(OnStringSelected(QModelIndex)) ); this, SLOT(OnStringSelected(QModelIndex)) );
// connect( mpUI->LanguageComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(OnLanguageChanged(int)) ); connect( mpUI->EditLanguageTabBar, SIGNAL(currentChanged(int)), this, SLOT(OnLanguageChanged(int)) );
connect( pTabBar, SIGNAL(currentChanged(int)), this, SLOT(OnLanguageChanged(int)) );
// Update window title // Update window title
QString WindowTitle = "%APP_FULL_NAME% - String Editor - %1[*]"; QString WindowTitle = "%APP_FULL_NAME% - String Editor - %1[*]";
WindowTitle = WindowTitle.arg( TO_QSTRING(mpStringTable->Entry()->CookedAssetPath(true).GetFileName()) ); WindowTitle = WindowTitle.arg( TO_QSTRING(mpStringTable->Entry()->CookedAssetPath(true).GetFileName()) );
SET_WINDOWTITLE_APPVARS(WindowTitle); 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 // Update status bar
QString StatusText = QString("%1 languages, %2 strings") QString StatusText = QString("%1 languages, %2 strings")
.arg(mpStringTable->NumLanguages()) .arg(mpStringTable->NumLanguages())
.arg(mpStringTable->NumStrings()); .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) 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 // Force UI to update with the correct string for the new language
SetActiveString( mCurrentStringIndex ); SetActiveString( mCurrentStringIndex );
SaveSettings();
} }
} }
@ -104,12 +100,24 @@ void CStringEditor::SetActiveString(int StringIndex)
TString StringData = mpStringTable->GetString(mCurrentLanguage, mCurrentStringIndex); TString StringData = mpStringTable->GetString(mCurrentLanguage, mCurrentStringIndex);
mpUI->StringNameLineEdit->setText( TO_QSTRING(StringName) ); mpUI->StringNameLineEdit->setText( TO_QSTRING(StringName) );
mpUI->StringTextEdit->setPlainText( TO_QSTRING(StringData) ); mpUI->StringTextEdit->setPlainText( TO_QSTRING(StringData) );
UpdateStatusBar();
} }
void CStringEditor::LoadSettings() void CStringEditor::LoadSettings()
{ {
QSettings Settings; QSettings Settings;
// Set language
mCurrentLanguage = (ELanguage) Settings.value(gkpLanguageSetting, (int) ELanguage::English).toInt(); 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() void CStringEditor::SaveSettings()

View File

@ -36,7 +36,7 @@ public:
explicit CStringEditor(CStringTable* pStringTable, QWidget* pParent = 0); explicit CStringEditor(CStringTable* pStringTable, QWidget* pParent = 0);
~CStringEditor(); ~CStringEditor();
void InitUI(); void InitUI();
void UpdateUI(); void UpdateStatusBar();
void SetActiveLanguage(ELanguage Language); void SetActiveLanguage(ELanguage Language);
void SetActiveString(int StringIndex); void SetActiveString(int StringIndex);

View File

@ -6,8 +6,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>609</width> <width>512</width>
<height>444</height> <height>626</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
@ -137,7 +137,7 @@
<number>0</number> <number>0</number>
</property> </property>
<item> <item>
<widget class="QWidget" name="TabsContainerWidget" native="true"/> <widget class="QTabBar" name="EditLanguageTabBar" native="true"/>
</item> </item>
<item> <item>
<widget class="QPlainTextEdit" name="StringTextEdit"> <widget class="QPlainTextEdit" name="StringTextEdit">
@ -202,6 +202,14 @@
</property> </property>
</action> </action>
</widget> </widget>
<customwidgets>
<customwidget>
<class>QTabBar</class>
<extends>QWidget</extends>
<header location="global">QTabBar</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources> <resources>
<include location="../Icons.qrc"/> <include location="../Icons.qrc"/>
</resources> </resources>