diff options
Diffstat (limited to 'tdeui/tdefontdialog.cpp')
| -rw-r--r-- | tdeui/tdefontdialog.cpp | 114 |
1 files changed, 78 insertions, 36 deletions
diff --git a/tdeui/tdefontdialog.cpp b/tdeui/tdefontdialog.cpp index fcd50b16e..b903a3a90 100644 --- a/tdeui/tdefontdialog.cpp +++ b/tdeui/tdefontdialog.cpp @@ -1,3 +1,4 @@ + /* Requires the Qt widget libraries, available at no cost at @@ -50,7 +51,7 @@ #include <tqlineedit.h> #include <tdelistbox.h> #include <tdelocale.h> -#include <kstandarddirs.h> +#include <tdestandarddirs.h> #include <kdebug.h> #include <knuminput.h> @@ -84,8 +85,8 @@ class TDEFontChooser::TDEFontChooserPrivate { public: TDEFontChooserPrivate() - { m_palette.setColor(TQPalette::Active, TQColorGroup::Text, Qt::black); - m_palette.setColor(TQPalette::Active, TQColorGroup::Base, Qt::white); } + { m_palette.setColor(TQPalette::Active, TQColorGroup::Text, TQt::black); + m_palette.setColor(TQPalette::Active, TQColorGroup::Base, TQt::white); } TQPalette m_palette; }; @@ -130,8 +131,8 @@ TDEFontChooser::TDEFontChooser(TQWidget *parent, const char *name, familyLayout->addSpacing( checkBoxGap ); if (diff) { familyCheckbox = new TQCheckBox(i18n("Font"), page); - connect(familyCheckbox, TQT_SIGNAL(toggled(bool)), TQT_SLOT(toggled_checkbox())); - familyLayout->addWidget(familyCheckbox, 0, Qt::AlignLeft); + connect(familyCheckbox, TQ_SIGNAL(toggled(bool)), TQ_SLOT(toggled_checkbox())); + familyLayout->addWidget(familyCheckbox, 0, TQt::AlignLeft); TQString familyCBToolTipText = i18n("Change font family?"); TQString familyCBWhatsThisText = @@ -142,15 +143,15 @@ TDEFontChooser::TDEFontChooser(TQWidget *parent, const char *name, } else { familyCheckbox = 0; familyLabel = new TQLabel( i18n("Font:"), page, "familyLabel" ); - familyLayout->addWidget(familyLabel, 1, Qt::AlignLeft); + familyLayout->addWidget(familyLabel, 1, TQt::AlignLeft); } gridLayout->addLayout(familyLayout, row, 0 ); TQHBoxLayout *styleLayout = new TQHBoxLayout(); if (diff) { styleCheckbox = new TQCheckBox(i18n("Font style"), page); - connect(styleCheckbox, TQT_SIGNAL(toggled(bool)), TQT_SLOT(toggled_checkbox())); - styleLayout->addWidget(styleCheckbox, 0, Qt::AlignLeft); + connect(styleCheckbox, TQ_SIGNAL(toggled(bool)), TQ_SLOT(toggled_checkbox())); + styleLayout->addWidget(styleCheckbox, 0, TQt::AlignLeft); TQString styleCBToolTipText = i18n("Change font style?"); TQString styleCBWhatsThisText = @@ -161,7 +162,7 @@ TDEFontChooser::TDEFontChooser(TQWidget *parent, const char *name, } else { styleCheckbox = 0; styleLabel = new TQLabel( i18n("Font style:"), page, "styleLabel"); - styleLayout->addWidget(styleLabel, 1, Qt::AlignLeft); + styleLayout->addWidget(styleLabel, 1, TQt::AlignLeft); } styleLayout->addSpacing( checkBoxGap ); gridLayout->addLayout(styleLayout, row, 1 ); @@ -169,8 +170,8 @@ TDEFontChooser::TDEFontChooser(TQWidget *parent, const char *name, TQHBoxLayout *sizeLayout = new TQHBoxLayout(); if (diff) { sizeCheckbox = new TQCheckBox(i18n("Size"),page); - connect(sizeCheckbox, TQT_SIGNAL(toggled(bool)), TQT_SLOT(toggled_checkbox())); - sizeLayout->addWidget(sizeCheckbox, 0, Qt::AlignLeft); + connect(sizeCheckbox, TQ_SIGNAL(toggled(bool)), TQ_SLOT(toggled_checkbox())); + sizeLayout->addWidget(sizeCheckbox, 0, TQt::AlignLeft); TQString sizeCBToolTipText = i18n("Change font size?"); TQString sizeCBWhatsThisText = @@ -181,7 +182,7 @@ TDEFontChooser::TDEFontChooser(TQWidget *parent, const char *name, } else { sizeCheckbox = 0; sizeLabel = new TQLabel( i18n("Size:"), page, "sizeLabel"); - sizeLayout->addWidget(sizeLabel, 1, Qt::AlignLeft); + sizeLayout->addWidget(sizeLabel, 1, TQt::AlignLeft); } sizeLayout->addSpacing( checkBoxGap ); sizeLayout->addSpacing( checkBoxGap ); // prevent label from eating border @@ -199,8 +200,8 @@ TDEFontChooser::TDEFontChooser(TQWidget *parent, const char *name, i18n("Here you can choose the font family to be used." ); TQWhatsThis::add( familyListBox, fontFamilyWhatsThisText ); TQWhatsThis::add(diff?(TQWidget *) familyCheckbox:(TQWidget *) familyLabel, fontFamilyWhatsThisText ); - connect(familyListBox, TQT_SIGNAL(highlighted(const TQString &)), - TQT_SLOT(family_chosen_slot(const TQString &))); + connect(familyListBox, TQ_SIGNAL(highlighted(const TQString &)), + TQ_SLOT(family_chosen_slot(const TQString &))); if(!fontList.isEmpty()) { familyListBox->insertStringList(fontList); @@ -229,8 +230,8 @@ TDEFontChooser::TDEFontChooser(TQWidget *parent, const char *name, styleListBox->setMinimumHeight( minimumListHeight( styleListBox, visibleListSize ) ); - connect(styleListBox, TQT_SIGNAL(highlighted(const TQString &)), - TQT_SLOT(style_chosen_slot(const TQString &))); + connect(styleListBox, TQ_SIGNAL(highlighted(const TQString &)), + TQ_SLOT(style_chosen_slot(const TQString &))); sizeListBox = new TDEListBox( page, "sizeListBox"); @@ -257,7 +258,7 @@ TDEFontChooser::TDEFontChooser(TQWidget *parent, const char *name, sizeLayout2->setColStretch( 1, 1 ); // to prevent text from eating the right border sizeLayout2->addMultiCellWidget( sizeOfFont, 0, 0, 0, 1); sizeLayout2->addMultiCellWidget(sizeListBox, 1,1, 0,1); - sizeLayout2->addWidget(sizeIsRelativeCheckBox, 2, 0, Qt::AlignLeft); + sizeLayout2->addWidget(sizeIsRelativeCheckBox, 2, 0, TQt::AlignLeft); TQWhatsThis::add( sizeIsRelativeCheckBox, sizeIsRelativeCBWhatsThisText ); TQToolTip::add( sizeIsRelativeCheckBox, sizeIsRelativeCBToolTipText ); } @@ -279,11 +280,11 @@ TDEFontChooser::TDEFontChooser(TQWidget *parent, const char *name, sizeListBox->setMinimumHeight( minimumListHeight( sizeListBox, visibleListSize ) ); - connect( sizeOfFont, TQT_SIGNAL( valueChanged(int) ), - TQT_SLOT(size_value_slot(int))); + connect( sizeOfFont, TQ_SIGNAL( valueChanged(int) ), + TQ_SLOT(size_value_slot(int))); - connect( sizeListBox, TQT_SIGNAL(highlighted(const TQString&)), - TQT_SLOT(size_chosen_slot(const TQString&)) ); + connect( sizeListBox, TQ_SIGNAL(highlighted(const TQString&)), + TQ_SLOT(size_chosen_slot(const TQString&)) ); sizeListBox->setSelected(sizeListBox->findItem(TQString::number(10)), true); // default to 10pt. row ++; @@ -295,14 +296,14 @@ TDEFontChooser::TDEFontChooser(TQWidget *parent, const char *name, //i18n: This is a classical test phrase. (It contains all letters from A to Z.) sampleEdit->setText(i18n("The Quick Brown Fox Jumps Over The Lazy Dog")); sampleEdit->setMinimumHeight( sampleEdit->fontMetrics().lineSpacing() ); - sampleEdit->setAlignment(Qt::AlignCenter); + sampleEdit->setAlignment(TQt::AlignCenter); gridLayout->addMultiCellWidget(sampleEdit, 4, 4, 0, 2); TQString sampleEditWhatsThisText = i18n("This sample text illustrates the current settings. " "You may edit it to test special characters." ); TQWhatsThis::add( sampleEdit, sampleEditWhatsThisText ); - connect(this, TQT_SIGNAL(fontSelected(const TQFont &)), - TQT_SLOT(displaySample(const TQFont &))); + connect(this, TQ_SIGNAL(fontSelected(const TQFont &)), + TQ_SLOT(displaySample(const TQFont &))); TQVBoxLayout *vbox; if( makeFrame ) @@ -461,23 +462,36 @@ void TDEFontChooser::toggled_checkbox() sizeOfFont->setEnabled( sizeCheckbox->isChecked() ); } +TQString TDEFontChooser::style_name(const TQString &style) +{ + return i18n( + TQString(style).replace("Plain", "Regular") + .replace("Normal", "Regular") + .replace("Oblique", "Italic") + .utf8()); +} + void TDEFontChooser::family_chosen_slot(const TQString& family) { + TQString currentFamily; + if (family.isEmpty()) + { + currentFamily = familyListBox->currentText(); + } + else + { + currentFamily = family; + } + TQFontDatabase dbase; - TQStringList styles = TQStringList(dbase.styles(family)); + 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) { @@ -488,12 +502,21 @@ void TDEFontChooser::family_chosen_slot(const TQString& family) styleListBox->blockSignals(true); TQListBoxItem *item = styleListBox->findItem(selectedStyle); if (item) + { styleListBox->setSelected(styleListBox->findItem(selectedStyle), true); + } else + { styleListBox->setSelected(0, true); + } styleListBox->blockSignals(false); style_chosen_slot(TQString::null); + + if (!family.isEmpty() ) + { + selectedFamily = family; + } } void TDEFontChooser::size_chosen_slot(const TQString& size){ @@ -565,8 +588,9 @@ void TDEFontChooser::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(); @@ -624,7 +648,16 @@ void TDEFontChooser::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++){ @@ -671,6 +704,15 @@ void TDEFontChooser::getFontList( TQStringList &list, uint fontListCriteria) list = lstSys; } +void TDEFontChooser::setFamilyList( TQStringList list ) +{ + familyListBox->blockSignals(true); + familyListBox->clear(); + familyListBox->insertStringList(list); + setFont( TDEGlobalSettings::generalFont(), usingFixed ); + familyListBox->blockSignals(false); +} + void TDEFontChooser::addFont( TQStringList &list, const char *xfont ) { const char *ptr = strchr( xfont, '-' ); |
