diff --git a/src/Editor/StringEditor/CStringDelegate.cpp b/src/Editor/StringEditor/CStringDelegate.cpp index e062504c..fbbcd6d0 100644 --- a/src/Editor/StringEditor/CStringDelegate.cpp +++ b/src/Editor/StringEditor/CStringDelegate.cpp @@ -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); diff --git a/src/Editor/StringEditor/CStringEditor.cpp b/src/Editor/StringEditor/CStringEditor.cpp index e44d3812..862c6929 100644 --- a/src/Editor/StringEditor/CStringEditor.cpp +++ b/src/Editor/StringEditor/CStringEditor.cpp @@ -3,7 +3,6 @@ #include "CStringDelegate.h" #include "Editor/UICommon.h" -#include "Editor/Widgets/CSizeableTabBar.h" #include @@ -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::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::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 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::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() diff --git a/src/Editor/StringEditor/CStringEditor.h b/src/Editor/StringEditor/CStringEditor.h index 0a522759..e2719a47 100644 --- a/src/Editor/StringEditor/CStringEditor.h +++ b/src/Editor/StringEditor/CStringEditor.h @@ -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); diff --git a/src/Editor/StringEditor/CStringEditor.ui b/src/Editor/StringEditor/CStringEditor.ui index a0565333..6e9c254b 100644 --- a/src/Editor/StringEditor/CStringEditor.ui +++ b/src/Editor/StringEditor/CStringEditor.ui @@ -6,8 +6,8 @@ 0 0 - 609 - 444 + 512 + 626 @@ -137,7 +137,7 @@ 0 - + @@ -202,6 +202,14 @@ + + + QTabBar + QWidget +
QTabBar
+ 1 +
+