KOffice: switch to global TDEFontChooser

Signed-off-by: Mavridis Philippe <mavridisf@gmail.com>
pull/27/head
Mavridis Philippe 2 years ago
parent 79949811e0
commit 69b99acba4
No known key found for this signature in database
GPG Key ID: F8D2D7E2F989A494

@ -23,9 +23,10 @@ KoFontTab::KoFontTab( uint fontListCriteria, TQWidget* parent, const char* name,
: KoFontTabBase( parent, name, fl )
{
TQStringList list;
TDEFontChooser_local::getFontList(list, fontListCriteria);
TDEFontChooser::getFontList(list, fontListCriteria);
characterFont->setFamilyList( list );
characterFont->setSampleBoxVisible(false);
comparisonFont = characterFont->font();
connect( characterFont, TQT_SIGNAL( fontSelected( const TQFont & ) ), this, TQT_SLOT( slotFontChanged( const TQFont & ) ) );
}

@ -12,7 +12,7 @@ libkotext_la_SOURCES = KoComplexText.cpp KoRichText.cpp \
KoParagDia.cpp KoVariable.cpp KoCustomVariablesDia.cpp \
KoChangeCaseDia.cpp KoStyleManager.cpp KoSearchDia.cpp \
timedateformatwidget.ui TimeFormatWidget.cpp DateFormatWidget.cpp \
TDEFontDialog_local.cpp kofonttabbase.ui KoFontTab.cpp kohighlightingtabbase.ui KoHighlightingTab.cpp \
kofonttabbase.ui KoFontTab.cpp kohighlightingtabbase.ui KoHighlightingTab.cpp \
kodecorationtabbase.ui KoDecorationTab.cpp kolayouttabbase.ui KoLayoutTab.cpp kolanguagetabbase.ui KoLanguageTab.cpp \
KoFontDiaPreview.cpp KoCompletionDia.cpp KoCompletionBase.ui \
KoTextViewIface.skel KoTextViewIface.cpp KoFontDia.cpp KoBgSpellCheck.cpp \

@ -1,835 +0,0 @@
/*
Requires the TQt widget libraries, available at no cost at
http://www.troll.no
Copyright (C) 1996 Bernd Johannes Wuebben <wuebben@kde.org>
Copyright (c) 1999 Preston Brown <pbrown@kde.org>
Copyright (c) 1999 Mario Weilguni <mweilguni@kde.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include <config.h>
#include <stdio.h>
#include <stdlib.h>
#include <tqcombobox.h>
#include <tqcheckbox.h>
#include <tqfile.h>
#include <tqfont.h>
#include <tqgroupbox.h>
#include <tqlabel.h>
#include <tqlayout.h>
#include <tqscrollbar.h>
#include <tqstringlist.h>
#include <tqfontdatabase.h>
#include <tqwhatsthis.h>
#include <tqtooltip.h>
#include <tdeapplication.h>
#include <kcharsets.h>
#include <tdeconfig.h>
#include <kdialog.h>
#include <tdeglobal.h>
#include <tdeglobalsettings.h>
#include <tqlineedit.h>
#include <tdelistbox.h>
#include <tdelocale.h>
#include <kstandarddirs.h>
#include <kdebug.h>
#include <knuminput.h>
#include <koffice_export.h>
#include "TDEFontDialog_local.h"
#include "TDEFontDialog_local.moc"
static int minimumListWidth( const TQListBox *list )
{
int w=0;
for( uint i=0; i<list->count(); i++ )
{
int itemWidth = list->item(i)->width(list);
w = TQMAX(w,itemWidth);
}
if( w == 0 ) { w = 40; }
w += list->frameWidth() * 2;
w += list->verticalScrollBar()->sizeHint().width();
return w;
}
static int minimumListHeight( const TQListBox *list, int numVisibleEntry )
{
int w = list->count() > 0 ? list->item(0)->height(list) :
list->fontMetrics().lineSpacing();
if( w < 0 ) { w = 10; }
if( numVisibleEntry <= 0 ) { numVisibleEntry = 4; }
return ( w * numVisibleEntry + 2 * list->frameWidth() );
}
class TDEFontChooser_local::TDEFontChooser_localPrivate
{
public:
TDEFontChooser_localPrivate()
{ m_palette.setColor(TQPalette::Active, TQColorGroup::Text, TQt::black);
m_palette.setColor(TQPalette::Active, TQColorGroup::Base, TQt::white); }
TQPalette m_palette;
};
TDEFontChooser_local::TDEFontChooser_local(TQWidget *parent, const char *name,
bool onlyFixed, const TQStringList &fontList,
bool makeFrame, int visibleListSize, bool diff,
TQButton::ToggleState *sizeIsRelativeState )
: TQWidget(parent, name), usingFixed(onlyFixed)
{
charsetsCombo = 0;
TQString mainWhatsThisText =
i18n( "Here you can choose the font to be used." );
TQWhatsThis::add( this, mainWhatsThisText );
d = new TDEFontChooser_localPrivate;
TQVBoxLayout *topLayout = new TQVBoxLayout( this, 0, KDialog::spacingHint() );
int checkBoxGap = KDialog::spacingHint() / 2;
TQWidget *page;
TQGridLayout *gridLayout;
int row = 0;
if( makeFrame )
{
page = new TQGroupBox( i18n("Requested Font"), this );
topLayout->addWidget(page);
gridLayout = new TQGridLayout( page, 5, 3, KDialog::marginHint(), KDialog::spacingHint() );
gridLayout->addRowSpacing( 0, fontMetrics().lineSpacing() );
row = 1;
}
else
{
page = new TQWidget( this );
topLayout->addWidget(page);
gridLayout = new TQGridLayout( page, 4, 3, 0, KDialog::spacingHint() );
}
//
// first, create the labels across the top
//
TQHBoxLayout *familyLayout = new TQHBoxLayout();
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, TQt::AlignLeft);
TQString familyCBToolTipText =
i18n("Change font family?");
TQString familyCBWhatsThisText =
i18n("Enable this checkbox to change the font family settings.");
TQWhatsThis::add( familyCheckbox, familyCBWhatsThisText );
TQToolTip::add( familyCheckbox, familyCBToolTipText );
familyLabel = 0;
} else {
familyCheckbox = 0;
familyLabel = new TQLabel( i18n("Font:"), page, "familyLabel" );
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, TQt::AlignLeft);
TQString styleCBToolTipText =
i18n("Change font style?");
TQString styleCBWhatsThisText =
i18n("Enable this checkbox to change the font style settings.");
TQWhatsThis::add( styleCheckbox, styleCBWhatsThisText );
TQToolTip::add( styleCheckbox, styleCBToolTipText );
styleLabel = 0;
} else {
styleCheckbox = 0;
styleLabel = new TQLabel( i18n("Font style:"), page, "styleLabel");
styleLayout->addWidget(styleLabel, 1, TQt::AlignLeft);
}
styleLayout->addSpacing( checkBoxGap );
gridLayout->addLayout(styleLayout, row, 1 );
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, TQt::AlignLeft);
TQString sizeCBToolTipText =
i18n("Change font size?");
TQString sizeCBWhatsThisText =
i18n("Enable this checkbox to change the font size settings.");
TQWhatsThis::add( sizeCheckbox, sizeCBWhatsThisText );
TQToolTip::add( sizeCheckbox, sizeCBToolTipText );
sizeLabel = 0;
} else {
sizeCheckbox = 0;
sizeLabel = new TQLabel( i18n("Size:"), page, "sizeLabel");
sizeLayout->addWidget(sizeLabel, 1, TQt::AlignLeft);
}
sizeLayout->addSpacing( checkBoxGap );
sizeLayout->addSpacing( checkBoxGap ); // prevent label from eating border
gridLayout->addLayout(sizeLayout, row, 2 );
row ++;
//
// now create the actual boxes that hold the info
//
familyListBox = new TDEListBox( page, "familyListBox");
familyListBox->setEnabled( !diff );
gridLayout->addWidget( familyListBox, row, 0 );
TQString fontFamilyWhatsThisText =
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 &)));
if(!fontList.isEmpty())
{
familyListBox->insertStringList(fontList);
}
else
{
fillFamilyListBox(onlyFixed);
}
familyListBox->setMinimumWidth( minimumListWidth( familyListBox ) );
familyListBox->setMinimumHeight(
minimumListHeight( familyListBox, visibleListSize ) );
styleListBox = new TDEListBox( page, "styleListBox");
styleListBox->setEnabled( !diff );
gridLayout->addWidget(styleListBox, row, 1);
TQString fontStyleWhatsThisText =
i18n("Here you can choose the font style to be used." );
TQWhatsThis::add( styleListBox, fontStyleWhatsThisText );
TQWhatsThis::add(diff?(TQWidget *)styleCheckbox:(TQWidget *)styleLabel, fontFamilyWhatsThisText );
styleListBox->insertItem(i18n("Regular"));
styleListBox->insertItem(i18n("Italic"));
styleListBox->insertItem(i18n("Bold"));
styleListBox->insertItem(i18n("Bold Italic"));
styleListBox->setMinimumWidth( minimumListWidth( styleListBox ) );
styleListBox->setMinimumHeight(
minimumListHeight( styleListBox, visibleListSize ) );
connect(styleListBox, TQT_SIGNAL(highlighted(const TQString &)),
TQT_SLOT(style_chosen_slot(const TQString &)));
sizeListBox = new TDEListBox( page, "sizeListBox");
sizeOfFont = new KIntNumInput( page, "sizeOfFont");
sizeOfFont->setMinValue(4);
sizeListBox->setEnabled( !diff );
sizeOfFont->setEnabled( !diff );
if( sizeIsRelativeState ) {
TQString sizeIsRelativeCBText =
i18n("Relative");
TQString sizeIsRelativeCBToolTipText =
i18n("Font size<br><i>fixed</i> or <i>relative</i><br>to environment");
TQString sizeIsRelativeCBWhatsThisText =
i18n("Here you can switch between fixed font size and font size "
"to be calculated dynamically and adjusted to changing "
"environment (e.g. widget dimensions, paper size)." );
sizeIsRelativeCheckBox = new TQCheckBox( sizeIsRelativeCBText,
page,
"sizeIsRelativeCheckBox" );
sizeIsRelativeCheckBox->setTristate( diff );
TQGridLayout *sizeLayout2 = new TQGridLayout( 3,2, KDialog::spacingHint()/2, "sizeLayout2" );
gridLayout->addLayout(sizeLayout2, row, 2);
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, TQt::AlignLeft);
TQWhatsThis::add( sizeIsRelativeCheckBox, sizeIsRelativeCBWhatsThisText );
TQToolTip::add( sizeIsRelativeCheckBox, sizeIsRelativeCBToolTipText );
}
else {
sizeIsRelativeCheckBox = 0L;
TQGridLayout *sizeLayout2 = new TQGridLayout( 2,1, KDialog::spacingHint()/2, "sizeLayout2" );
gridLayout->addLayout(sizeLayout2, row, 2);
sizeLayout2->addWidget( sizeOfFont, 0, 0);
sizeLayout2->addMultiCellWidget(sizeListBox, 1,1, 0,0);
}
TQString fontSizeWhatsThisText =
i18n("Here you can choose the font size to be used." );
TQWhatsThis::add( sizeListBox, fontSizeWhatsThisText );
TQWhatsThis::add( diff?(TQWidget *)sizeCheckbox:(TQWidget *)sizeLabel, fontSizeWhatsThisText );
fillSizeList();
sizeListBox->setMinimumWidth( minimumListWidth(sizeListBox) +
sizeListBox->fontMetrics().maxWidth() );
sizeListBox->setMinimumHeight(
minimumListHeight( sizeListBox, visibleListSize ) );
connect( sizeOfFont, TQT_SIGNAL( valueChanged(int) ),
TQT_SLOT(size_value_slot(int)));
connect( sizeListBox, TQT_SIGNAL(highlighted(const TQString&)),
TQT_SLOT(size_chosen_slot(const TQString&)) );
sizeListBox->setSelected(sizeListBox->findItem(TQString::number(10)), true); // default to 10pt.
row ++;
row ++;
sampleEdit = new TQLineEdit( page, "sampleEdit");
TQFont tmpFont( TDEGlobalSettings::generalFont().family(), 64, TQFont::Black );
sampleEdit->setFont(tmpFont);
sampleEdit->setText(i18n("The Quick Brown Fox Jumps Over The Lazy Dog"));
sampleEdit->setMinimumHeight( sampleEdit->fontMetrics().lineSpacing() );
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 &)));
TQVBoxLayout *vbox;
if( makeFrame )
{
page = new TQGroupBox( i18n("Actual Font"), this );
topLayout->addWidget(page);
vbox = new TQVBoxLayout( page, KDialog::spacingHint() );
vbox->addSpacing( fontMetrics().lineSpacing() );
}
else
{
page = new TQWidget( this );
topLayout->addWidget(page);
vbox = new TQVBoxLayout( page, 0, KDialog::spacingHint() );
TQLabel *label = new TQLabel( i18n("Actual Font"), page );
vbox->addWidget( label );
}
xlfdEdit = new TQLineEdit( page, "xlfdEdit" );
vbox->addWidget( xlfdEdit );
// lets initialize the display if possible
setFont( TDEGlobalSettings::generalFont(), usingFixed );
// check or uncheck or gray out the "relative" checkbox
if( sizeIsRelativeState && sizeIsRelativeCheckBox )
setSizeIsRelative( *sizeIsRelativeState );
TDEConfig *config = TDEGlobal::config();
TDEConfigGroupSaver saver(config, TQString::fromLatin1("General"));
showXLFDArea(config->readBoolEntry(TQString::fromLatin1("fontSelectorShowXLFD"), false));
}
TDEFontChooser_local::~TDEFontChooser_local()
{
delete d;
}
void TDEFontChooser_local::fillSizeList() {
if(! sizeListBox) return; //assertion.
static const int c[] =
{
4, 5, 6, 7,
8, 9, 10, 11,
12, 13, 14, 15,
16, 17, 18, 19,
20, 22, 24, 26,
28, 32, 48, 64,
0
};
for(int i = 0; c[i]; ++i)
{
sizeListBox->insertItem(TQString::number(c[i]));
}
}
void TDEFontChooser_local::setColor( const TQColor & col )
{
d->m_palette.setColor( TQPalette::Active, TQColorGroup::Text, col );
TQPalette pal = sampleEdit->palette();
pal.setColor( TQPalette::Active, TQColorGroup::Text, col );
sampleEdit->setPalette( pal );
}
TQColor TDEFontChooser_local::color() const
{
return d->m_palette.color( TQPalette::Active, TQColorGroup::Text );
}
void TDEFontChooser_local::setBackgroundColor( const TQColor & col )
{
d->m_palette.setColor( TQPalette::Active, TQColorGroup::Base, col );
TQPalette pal = sampleEdit->palette();
pal.setColor( TQPalette::Active, TQColorGroup::Base, col );
sampleEdit->setPalette( pal );
}
TQColor TDEFontChooser_local::backgroundColor() const
{
return d->m_palette.color( TQPalette::Active, TQColorGroup::Base );
}
void TDEFontChooser_local::setSizeIsRelative( TQButton::ToggleState relative )
{
// check or uncheck or gray out the "relative" checkbox
if( sizeIsRelativeCheckBox ) {
if( TQButton::NoChange == relative )
sizeIsRelativeCheckBox->setNoChange();
else
sizeIsRelativeCheckBox->setChecked( TQButton::On == relative );
}
}
TQButton::ToggleState TDEFontChooser_local::sizeIsRelative() const
{
return sizeIsRelativeCheckBox
? sizeIsRelativeCheckBox->state()
: TQButton::NoChange;
}
TQSize TDEFontChooser_local::sizeHint( void ) const
{
return minimumSizeHint();
}
void TDEFontChooser_local::enableColumn( int column, bool state )
{
if( column & FamilyList )
{
familyListBox->setEnabled(state);
}
if( column & StyleList )
{
styleListBox->setEnabled(state);
}
if( column & SizeList )
{
sizeListBox->setEnabled(state);
}
}
void TDEFontChooser_local::setFont( const TQFont& aFont, bool onlyFixed )
{
selFont = aFont;
selectedSize=aFont.pointSize();
if (selectedSize == -1)
selectedSize = TQFontInfo(aFont).pointSize();
if( onlyFixed != usingFixed)
{
usingFixed = onlyFixed;
fillFamilyListBox(usingFixed);
}
setupDisplay();
displaySample(selFont);
}
int TDEFontChooser_local::fontDiffFlags() {
int diffFlags = 0;
if (familyCheckbox && styleCheckbox && sizeCheckbox) {
diffFlags = (int)(familyCheckbox->isChecked() ? FontDiffFamily : 0)
| (int)( styleCheckbox->isChecked() ? FontDiffStyle : 0)
| (int)( sizeCheckbox->isChecked() ? FontDiffSize : 0);
}
return diffFlags;
}
void TDEFontChooser_local::toggled_checkbox()
{
familyListBox->setEnabled( familyCheckbox->isChecked() );
styleListBox->setEnabled( styleCheckbox->isChecked() );
sizeListBox->setEnabled( sizeCheckbox->isChecked() );
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;
if (family.isEmpty())
currentFamily = familyListBox->currentText();
else
currentFamily = family;
TQFontDatabase dbase;
TQStringList styles = dbase.styles(currentFamily);
styleListBox->clear();
currentStyles.clear();
for ( TQStringList::Iterator it = styles.begin(); it != styles.end(); ++it ) {
TQString style = style_name(*it);
if(!styleListBox->findItem(style)) {
styleListBox->insertItem(style);
currentStyles.insert(style, *it);
}
}
if(styleListBox->count()==0) {
styleListBox->insertItem(i18n("Regular"));
currentStyles.insert(i18n("Regular"), "Normal");
}
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());
if (!family.isEmpty() )
selectedFamily = family;
}
void TDEFontChooser_local::size_chosen_slot(const TQString& size){
selectedSize=size.toInt();
sizeOfFont->setValue(selectedSize);
selFont.setPointSize(selectedSize);
emit fontSelected(selFont);
}
void TDEFontChooser_local::size_value_slot(int val) {
selFont.setPointSize(val);
emit fontSelected(selFont);
}
void TDEFontChooser_local::style_chosen_slot(const TQString& style)
{
TQString currentStyle;
if (style.isEmpty())
currentStyle = styleListBox->currentText();
else
currentStyle = style;
int diff=0; // the difference between the font size requested and what we can show.
sizeListBox->clear();
TQFontDatabase dbase;
if(dbase.isSmoothlyScalable(familyListBox->currentText(), currentStyles[currentStyle])) { // is vector font
//sampleEdit->setPaletteBackgroundPixmap( VectorPixmap ); // TODO
fillSizeList();
} else { // is bitmap font.
//sampleEdit->setPaletteBackgroundPixmap( BitmapPixmap ); // TODO
TQValueList<int> sizes = dbase.smoothSizes(familyListBox->currentText(), currentStyles[currentStyle]);
if(sizes.count() > 0) {
TQValueList<int>::iterator it;
diff=1000;
for ( it = sizes.begin(); it != sizes.end(); ++it ) {
if(*it <= selectedSize || diff > *it - selectedSize) diff = selectedSize - *it;
sizeListBox->insertItem(TQString::number(*it));
}
} else // there are times QT does not provide the list..
fillSizeList();
}
sizeListBox->blockSignals(true);
sizeListBox->setSelected(sizeListBox->findItem(TQString::number(selectedSize)), true);
sizeListBox->blockSignals(false);
sizeListBox->ensureCurrentVisible();
//kdDebug() << "Showing: " << familyListBox->currentText() << ", " << currentStyles[currentStyle] << ", " << selectedSize-diff << endl;
selFont = dbase.font(familyListBox->currentText(), currentStyles[currentStyle], selectedSize-diff);
emit fontSelected(selFont);
if (!style.isEmpty())
selectedStyle = style;
}
void TDEFontChooser_local::displaySample(const TQFont& font)
{
sampleEdit->setFont(font);
sampleEdit->setCursorPosition(0);
xlfdEdit->setText(font.rawName());
xlfdEdit->setCursorPosition(0);
//TQFontInfo a = TQFontInfo(font);
//kdDebug() << "font: " << a.family () << ", " << a.pointSize () << endl;
//kdDebug() << " (" << font.toString() << ")\n";
}
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();
TQString style = style_name(dbase.styleString(selFont));
int size = selFont.pointSize();
if (size == -1)
size = TQFontInfo(selFont).pointSize();
TQString sizeStr = TQString::number(size);
int numEntries, i;
numEntries = familyListBox->count();
for (i = 0; i < numEntries; i++) {
if (family == familyListBox->text(i).lower()) {
familyListBox->setCurrentItem(i);
break;
}
}
// 1st Fallback
if ( (i == numEntries) )
{
if (family.contains('['))
{
family = family.left(family.find('[')).stripWhiteSpace();
for (i = 0; i < numEntries; i++) {
if (family == familyListBox->text(i).lower()) {
familyListBox->setCurrentItem(i);
break;
}
}
}
}
// 2nd Fallback
if ( (i == numEntries) )
{
TQString fallback = family+" [";
for (i = 0; i < numEntries; i++) {
if (familyListBox->text(i).lower().startsWith(fallback)) {
familyListBox->setCurrentItem(i);
break;
}
}
}
// 3rd Fallback
if ( (i == numEntries) )
{
for (i = 0; i < numEntries; i++) {
if (familyListBox->text(i).lower().startsWith(family)) {
familyListBox->setCurrentItem(i);
break;
}
}
}
// Fall back in case nothing matched. Otherwise, diff doesn't work
if ( i == numEntries )
familyListBox->setCurrentItem( 0 );
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++){
if (sizeStr == sizeListBox->text(i)) {
sizeListBox->setCurrentItem(i);
break;
}
}
sizeOfFont->setValue(size);
}
void TDEFontChooser_local::getFontList( TQStringList &list, uint fontListCriteria)
{
TQFontDatabase dbase;
TQStringList lstSys(dbase.families());
// if we have criteria; then check fonts before adding
if (fontListCriteria)
{
TQStringList lstFonts;
for (TQStringList::Iterator it = lstSys.begin(); it != lstSys.end(); ++it)
{
if ((fontListCriteria & FixedWidthFonts) > 0 && !dbase.isFixedPitch(*it)) continue;
if (((fontListCriteria & (SmoothScalableFonts | ScalableFonts)) == ScalableFonts) &&
!dbase.isBitmapScalable(*it)) continue;
if ((fontListCriteria & SmoothScalableFonts) > 0 && !dbase.isSmoothlyScalable(*it)) continue;
lstFonts.append(*it);
}
if((fontListCriteria & FixedWidthFonts) > 0) {
// Fallback.. if there are no fixed fonts found, it's probably a
// bug in the font server or TQt. In this case, just use 'fixed'
if (lstFonts.count() == 0)
lstFonts.append("fixed");
}
lstSys = lstFonts;
}
lstSys.sort();
list = lstSys;
}
void TDEFontChooser_local::addFont( TQStringList &list, const char *xfont )
{
const char *ptr = strchr( xfont, '-' );
if ( !ptr )
return;
ptr = strchr( ptr + 1, '-' );
if ( !ptr )
return;
TQString font = TQString::fromLatin1(ptr + 1);
int pos;
if ( ( pos = font.find( '-' ) ) > 0 ) {
font.truncate( pos );
if ( font.find( TQString::fromLatin1("open look"), 0, false ) >= 0 )
return;
TQStringList::Iterator it = list.begin();
for ( ; it != list.end(); ++it )
if ( *it == font )
return;
list.append( font );
}
}
void TDEFontChooser_local::fillFamilyListBox(bool onlyFixedFonts)
{
TQStringList fontList;
getFontList(fontList, onlyFixedFonts?FixedWidthFonts:0);
familyListBox->clear();
familyListBox->insertStringList(fontList);
}
void TDEFontChooser_local::setFamilyList( TQStringList list )
{
familyListBox->blockSignals( true );
familyListBox->clear();
familyListBox->insertStringList( list );
setFont( TDEGlobalSettings::generalFont(), usingFixed );
familyListBox->blockSignals( false );
}
void TDEFontChooser_local::showXLFDArea(bool show)
{
if( show )
{
xlfdEdit->parentWidget()->show();
}
else
{
xlfdEdit->parentWidget()->hide();
}
}
///////////////////////////////////////////////////////////////////////////////
TDEFontDialog_local::TDEFontDialog_local( TQWidget *parent, const char* name,
bool onlyFixed, bool modal,
const TQStringList &fontList, bool makeFrame, bool diff,
TQButton::ToggleState *sizeIsRelativeState )
: KDialogBase( parent, name, modal, i18n("Select Font"), Ok|Cancel, Ok )
{
chooser = new TDEFontChooser_local( this, "fontChooser",
onlyFixed, fontList, makeFrame, 8,
diff, sizeIsRelativeState );
setMainWidget(chooser);
}
int TDEFontDialog_local::getFontDiff( TQFont &theFont, int &diffFlags, bool onlyFixed,
TQWidget *parent, bool makeFrame,
TQButton::ToggleState *sizeIsRelativeState )
{
TDEFontDialog_local dlg( parent, "Font Selector", onlyFixed, true, TQStringList(),
makeFrame, true, sizeIsRelativeState );
dlg.setFont( theFont, onlyFixed );
int result = dlg.exec();
if( result == Accepted )
{
theFont = dlg.chooser->font();
diffFlags = dlg.chooser->fontDiffFlags();
if( sizeIsRelativeState )
*sizeIsRelativeState = dlg.chooser->sizeIsRelative();
}
return result;
}
int TDEFontDialog_local::getFont( TQFont &theFont, bool onlyFixed,
TQWidget *parent, bool makeFrame,
TQButton::ToggleState *sizeIsRelativeState )
{
TDEFontDialog_local dlg( parent, "Font Selector", onlyFixed, true, TQStringList(),
makeFrame, false, sizeIsRelativeState );
dlg.setFont( theFont, onlyFixed );
int result = dlg.exec();
if( result == Accepted )
{
theFont = dlg.chooser->font();
if( sizeIsRelativeState )
*sizeIsRelativeState = dlg.chooser->sizeIsRelative();
}
return result;
}
int TDEFontDialog_local::getFontAndText( TQFont &theFont, TQString &theString,
bool onlyFixed, TQWidget *parent,
bool makeFrame,
TQButton::ToggleState *sizeIsRelativeState )
{
TDEFontDialog_local dlg( parent, "Font and Text Selector", onlyFixed, true,
TQStringList(), makeFrame, false, sizeIsRelativeState );
dlg.setFont( theFont, onlyFixed );
int result = dlg.exec();
if( result == Accepted )
{
theFont = dlg.chooser->font();
theString = dlg.chooser->sampleText();
if( sizeIsRelativeState )
*sizeIsRelativeState = dlg.chooser->sizeIsRelative();
}
return result;
}
void TDEFontChooser_local::virtual_hook( int, void* )
{ /*BASE::virtual_hook( id, data );*/ }
void TDEFontDialog_local::virtual_hook( int id, void* data )
{ KDialogBase::virtual_hook( id, data ); }

@ -1,518 +0,0 @@
/*
$Id: tdefontdialog.h,v 1.71 2004/10/10 10:27:49 bhards Exp $
Requires the TQt widget libraries, available at no cost at
http://www.troll.no
Copyright (C) 1997 Bernd Johannes Wuebben <wuebben@kde.org>
Copyright (c) 1999 Preston Brown <pbrown@kde.org>
Copyright (c) 1999 Mario Weilguni <mweilguni@kde.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
/*This local copy has been added to be able to hide the preview pane of the font chooser. A patch has been made in tdelibs since 3.5. This local copy can be disposed of when we require tdelibs 3.5 and higher*/
#ifndef _K_FONT_DIALOG_LOCAL_H_
#define _K_FONT_DIALOG_LOCAL_H_
#include <tqlineedit.h>
#include <tqbutton.h>
#include <kdialogbase.h>
#include <koffice_export.h>
class TQComboBox;
class TQCheckBox;
class TQFont;
class TQGroupBox;
class TQLabel;
class TQStringList;
class TDEListBox;
class KIntNumInput;
/**
* @short A font selection widget.
*
* While TDEFontChooser_local as an ordinary widget can be embedded in
* custom dialogs and therefore is very flexible, in most cases
* it is preferable to use the convenience functions in
* TDEFontDialog_local.
*
* @author Preston Brown <pbrown@kde.org>, Bernd Wuebben <wuebben@kde.org>
* @version $Id: tdefontdialog.h,v 1.71 2004/10/10 10:27:49 bhards Exp $
*/
class KOTEXT_EXPORT TDEFontChooser_local : public TQWidget
{
Q_OBJECT
TQ_PROPERTY( TQFont font READ font WRITE setFont )
public:
/**
* @li @p FamilyList - Identifies the family (leftmost) list.
* @li @p StyleList - Identifies the style (center) list.
* @li @p SizeList - Identifies the size (rightmost) list.
*/
enum FontColumn { FamilyList=0x01, StyleList=0x02, SizeList=0x04};
/**
* @li @p FontDiffFamily - Identifies a requested change in the font family.
* @li @p FontDiffStyle - Identifies a requested change in the font style.
* @li @p FontDiffSize - Identifies a requested change in the font size.
*/
enum FontDiff { FontDiffFamily=0x01, FontDiffStyle=0x02, FontDiffSize=0x04 };
/**
* Constructs a font picker widget.
* It normally comes up with all font families present on the system; the
* getFont method below does allow some more fine-tuning of the selection of fonts
* that will be displayed in the dialog.
* <p>Consider the following code snippet;
* \code
* TQStringList list;
* TDEFontChooser_local::getFontList(list,SmoothScalableFonts);
* TDEFontChooser_local chooseFont = new TDEFontChooser_local(0, "FontList", false, list);
* \endcode
* <p>
* The above creates a font chooser dialog with only SmoothScaleble fonts.
*
* @param parent The parent widget.
* @param name The widget name.
* @param onlyFixed Only display fonts which have fixed-width
* character sizes.
* @param fontList A list of fonts to display, in XLFD format. If
* no list is formatted, the internal KDE font list is used.
* If that has not been created, X is queried, and all fonts
* available on the system are displayed.
* @param diff Display the difference version dialog.
* See TDEFontDialog_local::getFontDiff().
* @param makeFrame Draws a frame with titles around the contents.
* @param visibleListSize The minimum number of visible entries in the
* fontlists.
* @param sizeIsRelativeState If not zero the widget will show a
* checkbox where the user may choose whether the font size
* is to be interpreted as relative size.
* Initial state of this checkbox will be set according to
* *sizeIsRelativeState, user choice may be retrieved by
* calling sizeIsRelative().
*/
TDEFontChooser_local(TQWidget *parent = 0L, const char *name = 0L,
bool onlyFixed = false,
const TQStringList &fontList = TQStringList(),
bool makeFrame = true, int visibleListSize=8,
bool diff = false, TQButton::ToggleState *sizeIsRelativeState = 0L );
/**
* Destructs the font chooser.
*/
virtual ~TDEFontChooser_local();
/**
* Enables or disable a font column in the chooser.
*
* Use this
* function if your application does not need or supports all font
* properties.
*
* @param column Specify the columns. An or'ed combination of
* @p FamilyList, @p StyleList and @p SizeList is possible.
* @param state If @p false the columns are disabled.
*/
void enableColumn( int column, bool state );
/**
* Sets the currently selected font in the chooser.
*
* @param font The font to select.
* @param onlyFixed Readjust the font list to display only fixed
* width fonts if @p true, or vice-versa.
*/
void setFont( const TQFont &font, bool onlyFixed = false );
/**
* @return The bitmask corresponding to the attributes the user
* wishes to change.
*/
int fontDiffFlags();
/**
* @return The currently selected font in the chooser.
*/
TQFont font() const { return selFont; }
/**
* Sets the color to use in the preview.
*/
void setColor( const TQColor & col );
/**
* @return The color currently used in the preview (default: the text
* color of the active color group)
*/
TQColor color() const;
/**
* Sets the background color to use in the preview.
*/
void setBackgroundColor( const TQColor & col );
/**
* @return The background color currently used in the preview (default:
* the base color of the active colorgroup)
*/
TQColor backgroundColor() const;
/**
* Sets the state of the checkbox indicating whether the font size
* is to be interpreted as relative size.
* NOTE: If parameter sizeIsRelative was not set in the constructor
* of the widget this setting will be ignored.
*/
void setSizeIsRelative( TQButton::ToggleState relative );
/**
* @return Whether the font size is to be interpreted as relative size
* (default: TQButton:Off)
*/
TQButton::ToggleState sizeIsRelative() const;
/**
* @return The current text in the sample text input area.
*/
TQString sampleText() const { return sampleEdit->text(); }
/**
* Sets the sample text.
*
* Normally you should not change this
* text, but it can be better to do this if the default text is
* too large for the edit area when using the default font of your
* application.
*
* @param text The new sample text. The current will be removed.
*/
void setSampleText( const TQString &text )
{
sampleEdit->setText( text );
}
/**
* Shows or hides the sample text box.
*
* @param visible Set it to true to show the box, to false to hide it.
*/
void setSampleBoxVisible( bool visible )
{
( visible ) ? sampleEdit->show() : sampleEdit->hide();
}
/**
* Converts a TQFont into the corresponding X Logical Font
* Description (XLFD).
*
* @param theFont The font to convert.
* @return A string representing the given font in XLFD format.
*/
static TQString getXLFD( const TQFont &theFont )
{ return theFont.rawName(); }
/**
* The selection criteria for the font families shown in the dialog.
* @li @p FixedWidthFont when included only fixed-width fonts are returned.
* The fonts where the width of every character is equal.
* @li @p ScalableFont when included only scalable fonts are returned;
* certain configurations allow bitmap fonts to remain unscaled and
* thus these fonts have limited number of sizes.
* @li @p SmoothScalableFont when included only return smooth scalable fonts.
* this will return only non-bitmap fonts which are scalable to any size requested.
* Setting this option to true will mean the "scalable" flag is irrelavant.
*/
enum FontListCriteria { FixedWidthFonts=0x01, ScalableFonts=0x02, SmoothScalableFonts=0x04 };
/**
* Creates a list of font strings.
*
* @param list The list is returned here.
* @param fontListCriteria should contain all the restrictions for font selection as OR-ed values
* @see TDEFontChooser_local::FontListCriteria for the individual values
*/
static void getFontList( TQStringList &list, uint fontListCriteria);
/**
*
* Fill the font family list of the TDEFontChooser
*
* @param list The font list.
*/
void setFamilyList( TQStringList list );
/**
* Reimplemented for internal reasons.
*/
virtual TQSize sizeHint( void ) const;
signals:
/**
* Emitted whenever the selected font changes.
*/
void fontSelected( const TQFont &font );
private slots:
void toggled_checkbox();
void family_chosen_slot(const TQString&);
void size_chosen_slot(const TQString&);
void style_chosen_slot(const TQString&);
void displaySample(const TQFont &font);
void showXLFDArea(bool);
void size_value_slot(int);
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 );
void setupDisplay();
// pointer to an optinally supplied list of fonts to
// inserted into the fontdialog font-family combo-box
TQStringList fontList;
KIntNumInput *sizeOfFont;
TQLineEdit *sampleEdit;
TQLineEdit *xlfdEdit;
TQLabel *familyLabel;
TQLabel *styleLabel;
TQCheckBox *familyCheckbox;
TQCheckBox *styleCheckbox;
TQCheckBox *sizeCheckbox;
TQLabel *sizeLabel;
TDEListBox *familyListBox;
TDEListBox *styleListBox;
TDEListBox *sizeListBox;
TQComboBox *charsetsCombo; // BIC: remove in KDE4
TQCheckBox *sizeIsRelativeCheckBox;
TQFont selFont;
TQString selectedFamily;
TQString selectedStyle;
int selectedSize;
TQMap<TQString, TQString> currentStyles;
bool usingFixed;
protected:
virtual void virtual_hook( int id, void* data );
private:
class TDEFontChooser_localPrivate;
TDEFontChooser_localPrivate *d;
};
/**
* @short A font selection dialog.
*
* The TDEFontDialog_local provides a dialog for interactive font selection.
* It is basically a thin wrapper around the TDEFontChooser_local widget,
* which can also be used standalone. In most cases, the simplest
* use of this class is the static method TDEFontDialog_local::getFont(),
* which pops up the dialog, allows the user to select a font, and
* returns when the dialog is closed.
*
* Example:
*
* \code
* TQFont myFont;
* int result = TDEFontDialog_local::getFont( myFont );
* if ( result == TDEFontDialog_local::Accepted )
* ...
* \endcode
*
* \image html tdefontdialog.png "KDE Font Dialog"
*
* @author Preston Brown <pbrown@kde.org>, Bernd Wuebben <wuebben@kde.org>
* @version $Id: tdefontdialog.h,v 1.71 2004/10/10 10:27:49 bhards Exp $
*/
class KOTEXT_EXPORT TDEFontDialog_local : public KDialogBase {
Q_OBJECT
public:
/**
* Constructs a font selection dialog.
*
* @param parent The parent widget of the dialog, if any.
* @param name The name of the dialog.
* @param modal Specifies whether the dialog is modal or not.
* @param onlyFixed only display fonts which have fixed-width
* character sizes.
* @param fontlist a list of fonts to display, in XLFD format. If
* no list is formatted, the internal KDE font list is used.
* If that has not been created, X is queried, and all fonts
* available on the system are displayed.
* @param makeFrame Draws a frame with titles around the contents.
* @param diff Display the difference version dialog. See getFontDiff().
* @param sizeIsRelativeState If not zero the widget will show a
* checkbox where the user may choose whether the font size
* is to be interpreted as relative size.
* Initial state of this checkbox will be set according to
* *sizeIsRelativeState, user choice may be retrieved by
* calling sizeIsRelative().
*
*/
TDEFontDialog_local( TQWidget *parent = 0L, const char *name = 0,
bool onlyFixed = false, bool modal = false,
const TQStringList &fontlist = TQStringList(),
bool makeFrame = true, bool diff = false,
TQButton::ToggleState *sizeIsRelativeState = 0L );
/**
* Sets the currently selected font in the dialog.
*
* @param font The font to select.
* @param onlyFixed readjust the font list to display only fixed
* width fonts if true, or vice-versa
*/
void setFont( const TQFont &font, bool onlyFixed = false )
{ chooser->setFont(font, onlyFixed); }
/**
* @return The currently selected font in the dialog.
*/
TQFont font() const { return chooser->font(); }
/**
* Sets the state of the checkbox indicating whether the font size
* is to be interpreted as relative size.
* NOTE: If parameter sizeIsRelative was not set in the constructor
* of the dialog this setting will be ignored.
*/
void setSizeIsRelative( TQButton::ToggleState relative )
{ chooser->setSizeIsRelative( relative ); }
/**
* @return Whether the font size is to be interpreted as relative size
* (default: false)
*/
TQButton::ToggleState sizeIsRelative() const
{ return chooser->sizeIsRelative(); }
/**
* Creates a modal font dialog, lets the user choose a font,
* and returns when the dialog is closed.
*
* @param theFont a reference to the font to write the chosen font
* into.
* @param onlyFixed if true, only select from fixed-width fonts.
* @param parent Parent widget of the dialog. Specifying a widget different
* from 0 (Null) improves centering (looks better).
* @param makeFrame Draws a frame with titles around the contents.
* @param sizeIsRelativeState If not zero the widget will show a
* checkbox where the user may choose whether the font size
* is to be interpreted as relative size.
* Initial state of this checkbox will be set according to
* *sizeIsRelativeState and user choice will be returned
* therein.
*
* @return TQDialog::result().
*/
static int getFont( TQFont &theFont, bool onlyFixed = false,
TQWidget *parent = 0L, bool makeFrame = true,
TQButton::ToggleState *sizeIsRelativeState = 0L );
/**
* Creates a modal font difference dialog, lets the user choose a selection
* of changes that should be made to a set of fonts, and returns when the
* dialog is closed. Useful for choosing slight adjustments to the font set
* when the user would otherwise have to manually edit a number of fonts.
*
* @param theFont a reference to the font to write the chosen font
* into.
* @param diffFlags a reference to the int into which the chosen
* difference selection bitmask should be written.
* Check the returned bitmask like:
* \code
* if ( diffFlags & TDEFontChooser_local::FontDiffFamily )
* [...]
* if ( diffFlags & TDEFontChooser_local::FontDiffStyle )
* [...]
* if ( diffFlags & TDEFontChooser_local::FontDiffSize )
* [...]
* \endcode
* @param onlyFixed if true, only select from fixed-width fonts.
* @param parent Parent widget of the dialog. Specifying a widget different
* from 0 (Null) improves centering (looks better).
* @param makeFrame Draws a frame with titles around the contents.
* @param sizeIsRelativeState If not zero the widget will show a
* checkbox where the user may choose whether the font size
* is to be interpreted as relative size.
* Initial state of this checkbox will be set according to
* *sizeIsRelativeState and user choice will be returned
* therein.
*
* @returns TQDialog::result().
*/
static int getFontDiff( TQFont &theFont, int &diffFlags, bool onlyFixed = false,
TQWidget *parent = 0L, bool makeFrame = true,
TQButton::ToggleState *sizeIsRelativeState = 0L );
/**
* When you are not only interested in the font selected, but also
* in the example string typed in, you can call this method.
*
* @param theFont a reference to the font to write the chosen font
* into.
* @param theString a reference to the example text that was typed.
* @param onlyFixed if true, only select from fixed-width fonts.
* @param parent Parent widget of the dialog. Specifying a widget different
* from 0 (Null) improves centering (looks better).
* @param makeFrame Draws a frame with titles around the contents.
* @param sizeIsRelativeState If not zero the widget will show a
* checkbox where the user may choose whether the font size
* is to be interpreted as relative size.
* Initial state of this checkbox will be set according to
* *sizeIsRelativeState and user choice will be returned
* therein.
* @return The result of the dialog.
*/
static int getFontAndText( TQFont &theFont, TQString &theString,
bool onlyFixed = false, TQWidget *parent = 0L,
bool makeFrame = true,
TQButton::ToggleState *sizeIsRelativeState = 0L );
signals:
/**
* Emitted whenever the currently selected font changes.
* Connect to this to monitor the font as it is selected if you are
* not running modal.
*/
void fontSelected( const TQFont &font );
protected:
TDEFontChooser_local *chooser;
protected:
virtual void virtual_hook( int id, void* data );
private:
class TDEFontDialog_localPrivate;
TDEFontDialog_localPrivate *d;
};
#endif

@ -11,7 +11,7 @@
<property name="name">
<cstring>unnamed</cstring>
</property>
<widget class="TDEFontChooser_local">
<widget class="TDEFontChooser">
<property name="name">
<cstring>characterFont</cstring>
</property>
@ -20,6 +20,6 @@
</widget>
<layoutdefaults spacing="6" margin="11"/>
<includes>
<include location="local" impldecl="in declaration">TDEFontDialog_local.h</include>
<include location="global" impldecl="in declaration">tdefontdialog.h</include>
</includes>
</UI>

Loading…
Cancel
Save