summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMavridis Philippe <mavridisf@gmail.com>2022-05-09 12:47:18 +0300
committerMavridis Philippe <mavridisf@gmail.com>2022-05-11 18:23:56 +0300
commitde8a8ab3e5e70b6cafc3d95bfec600c31f90d736 (patch)
tree25f049d017f03d9cf9ab3a7153dc2fa47cc1b60f
parent56b40453cd73523406a7dfb02ceb03a006d4a17a (diff)
downloadkoffice-de8a8ab3e5e70b6cafc3d95bfec600c31f90d736.tar.gz
koffice-de8a8ab3e5e70b6cafc3d95bfec600c31f90d736.zip
TDEFontChooser_local: Fix font style matching
This applies the same fix as in tdelibs for TDEFontDialog. This resolves issue #22. Signed-off-by: Mavridis Philippe <mavridisf@gmail.com>
-rw-r--r--lib/kotext/TDEFontDialog_local.cpp38
-rw-r--r--lib/kotext/TDEFontDialog_local.h1
2 files changed, 27 insertions, 12 deletions
diff --git a/lib/kotext/TDEFontDialog_local.cpp b/lib/kotext/TDEFontDialog_local.cpp
index a5db6523..f3231408 100644
--- a/lib/kotext/TDEFontDialog_local.cpp
+++ b/lib/kotext/TDEFontDialog_local.cpp
@@ -1,3 +1,4 @@
+
/*
Requires the TQt widget libraries, available at no cost at
@@ -463,6 +464,15 @@ void TDEFontChooser_local::toggled_checkbox()
sizeOfFont->setEnabled( sizeCheckbox->isChecked() );
}
+TQString TDEFontChooser_local::style_name(const TQString &style)
+{
+ return i18n(
+ TQString(style).replace("Plain", "Regular")
+ .replace("Normal", "Regular")
+ .replace("Oblique", "Italic")
+ .utf8());
+}
+
void TDEFontChooser_local::family_chosen_slot(const TQString& family)
{
TQString currentFamily;
@@ -473,20 +483,14 @@ void TDEFontChooser_local::family_chosen_slot(const TQString& family)
TQFontDatabase dbase;
- TQStringList styles = TQStringList(dbase.styles(currentFamily));
+ TQStringList styles = dbase.styles(currentFamily);
styleListBox->clear();
currentStyles.clear();
for ( TQStringList::Iterator it = styles.begin(); it != styles.end(); ++it ) {
- TQString style = *it;
- int pos = style.find("Plain");
- if(pos >=0) style = style.replace(pos,5,i18n("Regular"));
- pos = style.find("Normal");
- if(pos >=0) style = style.replace(pos,6,i18n("Regular"));
- pos = style.find("Oblique");
- if(pos >=0) style = style.replace(pos,7,i18n("Italic"));
+ TQString style = style_name(*it);
if(!styleListBox->findItem(style)) {
- styleListBox->insertItem(i18n(style.utf8()));
- currentStyles.insert(i18n(style.utf8()), *it);
+ styleListBox->insertItem(style);
+ currentStyles.insert(style, *it);
}
}
if(styleListBox->count()==0) {
@@ -578,8 +582,9 @@ void TDEFontChooser_local::setupDisplay()
{
// Calling familyListBox->setCurrentItem() causes the value of selFont
// to change, so we save the family, style and size beforehand.
+ TQFontDatabase dbase;
TQString family = TQString(selFont.family()).lower();
- int style = (selFont.bold() ? 2 : 0) + (selFont.italic() ? 1 : 0);
+ TQString style = style_name(dbase.styleString(selFont));
int size = selFont.pointSize();
if (size == -1)
size = TQFontInfo(selFont).pointSize();
@@ -637,7 +642,16 @@ void TDEFontChooser_local::setupDisplay()
if ( i == numEntries )
familyListBox->setCurrentItem( 0 );
- styleListBox->setCurrentItem(style);
+ int item = 0;
+ for (int i = 0; i < (int)styleListBox->count(); ++i)
+ {
+ if (styleListBox->text(i) == style)
+ {
+ item = i;
+ break;
+ }
+ }
+ styleListBox->setCurrentItem(item);
numEntries = sizeListBox->count();
for (i = 0; i < numEntries; i++){
diff --git a/lib/kotext/TDEFontDialog_local.h b/lib/kotext/TDEFontDialog_local.h
index a9001e71..5075ea11 100644
--- a/lib/kotext/TDEFontDialog_local.h
+++ b/lib/kotext/TDEFontDialog_local.h
@@ -282,6 +282,7 @@ private slots:
private:
void fillFamilyListBox(bool onlyFixedFonts = false);
void fillSizeList();
+ TQString style_name(const TQString &name);
// This one must be static since getFontList( TQStringList, char*) is so
static void addFont( TQStringList &list, const char *xfont );