kdeui: format and indent

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2024-03-31 04:40:19 +03:00
parent bb11a3e5f4
commit fc6d82d8cb
7 changed files with 601 additions and 640 deletions

View file

@ -27,17 +27,15 @@
#ifdef NEVERDEFINE // never true
// Font names up for translation, listed for extraction.
// i18n: Generic non-fixed font presented in font choosers. When selected,
// the system will choose a real font, mandated by distro settings.
I18N_NOOP2("@item Font name", "DejaVu Sans")
// i18n: Generic fixed font presented in font choosers. When selected,
// the system will choose a real font, mandated by distro settings.
I18N_NOOP2("@item Font name", "DejaVu Sans Mono")
#endif
void splitFontString (const QString &name, QString *family, QString *foundry)
void splitFontString(const QString &name, QString *family, QString *foundry)
{
int p1 = name.indexOf('[');
if (p1 < 0) {
@ -59,7 +57,7 @@ void splitFontString (const QString &name, QString *family, QString *foundry)
}
}
QString translateFontName (const QString &name)
QString translateFontName(const QString &name)
{
QString family, foundry;
splitFontString(name, &family, &foundry);
@ -80,8 +78,7 @@ QString translateFontName (const QString &name)
} else {
// i18n: Filter by which the translators can translate, or otherwise
// operate on the font names not put up for regular translation.
trfont = i18nc("@item Font name [foundry]", "%1 [%2]",
trFamily, trFoundry);
trfont = i18nc("@item Font name [foundry]", "%1 [%2]", trFamily, trFoundry);
}
return trfont;
}
@ -92,8 +89,8 @@ static bool fontLocaleLessThan (const QString &a, const QString &b)
return QString::localeAwareCompare(a, b) < 0;
}
QStringList translateFontNameList (const QStringList &names,
QHash<QString, QString> *trToRawNames)
QStringList translateFontNameList(const QStringList &names,
QHash<QString, QString> *trToRawNames)
{
// Generic fonts, in the inverse of desired order.
QStringList genericNames;

View file

@ -29,40 +29,40 @@
#include <QHash>
/**
* @internal
*
* Split the compound raw font name into family and foundry.
*
* @param name the raw font name reported by Qt
* @param family the storage for family name
* @param foundry the storage for foundry name
*/
void splitFontString (const QString &name,
QString *family, QString *foundry = NULL);
* @internal
*
* Split the compound raw font name into family and foundry.
*
* @param name the raw font name reported by Qt
* @param family the storage for family name
* @param foundry the storage for foundry name
*/
void splitFontString(const QString &name,
QString *family, QString *foundry = nullptr);
/**
* @internal
*
* Translate the font name for the user.
* Primarily for generic fonts like Serif, Sans-Serif, etc.
*
* @param name the raw font name reported by Qt
* @return translated font name
*/
QString translateFontName (const QString &name);
* @internal
*
* Translate the font name for the user.
* Primarily for generic fonts like Serif, Sans-Serif, etc.
*
* @param name the raw font name reported by Qt
* @return translated font name
*/
QString translateFontName(const QString &name);
/**
* @internal
*
* Compose locale-aware sorted list of translated font names,
* with generic fonts handled in a special way.
* The mapping of translated to raw names can be reported too if required.
*
* @param names raw font names as reported by Qt
* @param trToRawNames storage for mapping of translated to raw names
* @return sorted list of translated font names
*/
QStringList translateFontNameList (const QStringList &names,
QHash<QString, QString> *trToRawNames = NULL);
* @internal
*
* Compose locale-aware sorted list of translated font names,
* with generic fonts handled in a special way.
* The mapping of translated to raw names can be reported too if required.
*
* @param names raw font names as reported by Qt
* @param trToRawNames storage for mapping of translated to raw names
* @return sorted list of translated font names
*/
QStringList translateFontNameList(const QStringList &names,
QHash<QString, QString> *trToRawNames = nullptr);
# endif

View file

@ -47,30 +47,34 @@ Boston, MA 02110-1301, USA.
// When message extraction needs to be avoided.
#define I18NC_NOX i18nc
static int minimumListWidth( const QListWidget *list )
static int minimumListWidth(const QListWidget *list)
{
int w=0;
for( int i=0; i<list->count(); i++ )
{
int w = 0;
for(int i = 0; i < list->count(); i++) {
int itemWidth = list->visualItemRect(list->item(i)).width();
// ...and add a space on both sides for not too tight look.
itemWidth += list->fontMetrics().width(' ') * 2;
itemWidth += (list->fontMetrics().width(' ') * 2);
w = qMax(w,itemWidth);
}
if( w == 0 ) { w = 40; }
w += list->frameWidth() * 2;
if (w == 0) {
w = 40;
}
w += (list->frameWidth() * 2);
w += list->verticalScrollBar()->sizeHint().width();
return w;
}
static int minimumListHeight( const QListWidget *list, int numVisibleEntry )
static int minimumListHeight(const QListWidget *list, int numVisibleEntry)
{
int w = list->count() > 0 ? list->visualItemRect(list->item(0)).height() :
list->fontMetrics().lineSpacing();
int w = (list->count() > 0 ? list->visualItemRect(list->item(0)).height() : list->fontMetrics().lineSpacing());
if( w < 0 ) { w = 10; }
if( numVisibleEntry <= 0 ) { numVisibleEntry = 4; }
return ( w * numVisibleEntry + 2 * list->frameWidth() );
if (w < 0 ) {
w = 10;
}
if (numVisibleEntry <= 0) {
numVisibleEntry = 4;
}
return (w * numVisibleEntry + 2 * list->frameWidth());
}
static QString formatFontSize(const qreal size)
@ -81,8 +85,8 @@ static QString formatFontSize(const qreal size)
class KFontChooser::Private
{
public:
Private( KFontChooser* qq )
: q( qq )
Private(KFontChooser *qq)
: q(qq)
{
m_palette.setColor(QPalette::Active, QPalette::Text, Qt::black);
m_palette.setColor(QPalette::Active, QPalette::Base, Qt::white);
@ -110,9 +114,9 @@ public:
KFontChooser *q;
QPalette m_palette;
bool signalsAllowed:1;
bool signalsAllowed;
bool usingFixed:1;
bool usingFixed;
KDoubleNumInput *sizeOfFont;
@ -146,16 +150,16 @@ public:
};
KFontChooser::KFontChooser( QWidget *parent,
const DisplayFlags& flags,
const QStringList &fontList,
int visibleListSize,
Qt::CheckState *sizeIsRelativeState )
KFontChooser::KFontChooser(QWidget *parent,
const DisplayFlags flags,
const QStringList &fontList,
int visibleListSize,
Qt::CheckState *sizeIsRelativeState)
: QWidget(parent),
d( new KFontChooser::Private( this ) )
d(new KFontChooser::Private(this))
{
d->usingFixed = flags & FixedFontsOnly;
setWhatsThis(i18nc("@info:whatsthis", "Here you can choose the font to be used." ));
d->usingFixed = (flags & FixedFontsOnly);
setWhatsThis(i18nc("@info:whatsthis", "Here you can choose the font to be used."));
// The top layout is divided vertically into a splitter with font
// attribute widgets and preview on the top, and fonts at the bottom.
@ -171,120 +175,108 @@ KFontChooser::KFontChooser( QWidget *parent,
topLayout->addWidget(splitter);
// Build the grid of font attribute widgets for the upper splitter part.
//
QWidget *page;
QGridLayout *gridLayout;
int row = 0;
if( flags & DisplayFrame )
{
page = new QGroupBox( i18n("Requested Font"), this );
if (flags & DisplayFrame) {
page = new QGroupBox(i18n("Requested Font"), this);
splitter->addWidget(page);
gridLayout = new QGridLayout( page );
row = 1;
}
else
{
page = new QWidget( this );
} else {
page = new QWidget(this);
splitter->addWidget(page);
gridLayout = new QGridLayout( page );
gridLayout->setMargin( 0 );
gridLayout = new QGridLayout(page);
gridLayout->setMargin(0);
}
//
// first, create the labels across the top
//
QHBoxLayout *familyLayout = new QHBoxLayout();
familyLayout->addSpacing( checkBoxGap );
if ( flags & ShowDifferences ) {
familyLayout->addSpacing(checkBoxGap);
if (flags & ShowDifferences) {
d->familyCheckbox = new QCheckBox(i18nc("@option:check","Font"), page);
connect(d->familyCheckbox, SIGNAL(toggled(bool)),
this, SLOT(_k_toggled_checkbox()));
connect(d->familyCheckbox, SIGNAL(toggled(bool)), this, SLOT(_k_toggled_checkbox()));
familyLayout->addWidget(d->familyCheckbox, 0, Qt::AlignLeft);
d->familyCheckbox->setWhatsThis(i18nc("@info:whatsthis","Enable this checkbox to change the font family settings."));
d->familyCheckbox->setToolTip(i18nc("@info:tooltip","Change font family?") );
d->familyLabel = 0;
d->familyLabel = nullptr;
} else {
d->familyCheckbox = 0;
d->familyLabel = new QLabel( i18nc("@label","Font:"), page );
d->familyCheckbox = nullptr;
d->familyLabel = new QLabel(i18nc("@label","Font:"), page);
familyLayout->addWidget(d->familyLabel, 1, Qt::AlignLeft);
}
gridLayout->addLayout(familyLayout, row, 0 );
gridLayout->addLayout(familyLayout, row, 0);
QHBoxLayout *styleLayout = new QHBoxLayout();
if ( flags & ShowDifferences ) {
if (flags & ShowDifferences) {
d->styleCheckbox = new QCheckBox(i18nc("@option:check","Font style"), page);
connect(d->styleCheckbox, SIGNAL(toggled(bool)),
this, SLOT(_k_toggled_checkbox()));
connect(d->styleCheckbox, SIGNAL(toggled(bool)), this, SLOT(_k_toggled_checkbox()));
styleLayout->addWidget(d->styleCheckbox, 0, Qt::AlignLeft);
d->styleCheckbox->setWhatsThis(i18nc("@info:whatsthis","Enable this checkbox to change the font style settings."));
d->styleCheckbox->setToolTip(i18nc("@info:tooltip","Change font style?"));
d->styleLabel = 0;
d->styleLabel = nullptr;
} else {
d->styleCheckbox = 0;
d->styleLabel = new QLabel(i18n("Font style:"), page );
d->styleCheckbox = nullptr;
d->styleLabel = new QLabel(i18n("Font style:"), page);
styleLayout->addWidget(d->styleLabel, 1, Qt::AlignLeft);
}
styleLayout->addSpacing( checkBoxGap );
gridLayout->addLayout(styleLayout, row, 1 );
styleLayout->addSpacing(checkBoxGap);
gridLayout->addLayout(styleLayout, row, 1);
QHBoxLayout *sizeLayout = new QHBoxLayout();
if ( flags & ShowDifferences ) {
d->sizeCheckbox = new QCheckBox(i18nc("@option:check","Size"),page);
connect(d->sizeCheckbox, SIGNAL(toggled(bool)),
this, SLOT(_k_toggled_checkbox()));
connect(d->sizeCheckbox, SIGNAL(toggled(bool)), this, SLOT(_k_toggled_checkbox()));
sizeLayout->addWidget(d->sizeCheckbox, 0, Qt::AlignLeft);
d->sizeCheckbox->setWhatsThis(i18nc("@info:whatsthis","Enable this checkbox to change the font size settings."));
d->sizeCheckbox->setToolTip(i18nc("@info:tooltip","Change font size?"));
d->sizeLabel = 0;
d->sizeLabel = nullptr;
} else {
d->sizeCheckbox = 0;
d->sizeLabel = new QLabel(i18nc("@label:listbox Font size", "Size:"), page );
d->sizeCheckbox = nullptr;
d->sizeLabel = new QLabel(i18nc("@label:listbox Font size", "Size:"), page);
sizeLayout->addWidget(d->sizeLabel, 1, Qt::AlignLeft);
}
sizeLayout->addSpacing( checkBoxGap );
sizeLayout->addSpacing( checkBoxGap ); // prevent label from eating border
gridLayout->addLayout(sizeLayout, row, 2 );
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
//
d->familyListBox = new KListWidget( page );
d->familyListBox->setEnabled( flags ^ ShowDifferences );
gridLayout->addWidget( d->familyListBox, row, 0 );
QString fontFamilyWhatsThisText (
i18nc("@info:whatsthis","Here you can choose the font family to be used." ));
d->familyListBox->setWhatsThis(fontFamilyWhatsThisText );
d->familyListBox = new KListWidget(page);
d->familyListBox->setEnabled(flags ^ ShowDifferences);
gridLayout->addWidget(d->familyListBox, row, 0);
QString fontFamilyWhatsThisText = i18nc("@info:whatsthis","Here you can choose the font family to be used.");
d->familyListBox->setWhatsThis(fontFamilyWhatsThisText);
if ( flags & ShowDifferences ) {
d->familyCheckbox->setWhatsThis(fontFamilyWhatsThisText );
if (flags & ShowDifferences) {
d->familyCheckbox->setWhatsThis(fontFamilyWhatsThisText);
} else {
d->familyLabel->setWhatsThis(fontFamilyWhatsThisText );
d->familyLabel->setWhatsThis(fontFamilyWhatsThisText);
}
connect(d->familyListBox, SIGNAL(currentTextChanged(QString)),
this, SLOT(_k_family_chosen_slot(QString)));
if ( !fontList.isEmpty() ) {
connect(d->familyListBox, SIGNAL(currentTextChanged(QString)), this, SLOT(_k_family_chosen_slot(QString)));
if (!fontList.isEmpty()) {
d->setFamilyBoxItems(fontList);
}
else
{
d->fillFamilyListBox( flags & FixedFontsOnly );
}
d->familyListBox->setMinimumWidth( minimumListWidth( d->familyListBox ) );
d->familyListBox->setMinimumHeight(
minimumListHeight( d->familyListBox, visibleListSize ) );
d->styleListBox = new KListWidget( page );
d->styleListBox->setEnabled( flags ^ ShowDifferences );
gridLayout->addWidget(d->styleListBox, row, 1);
d->styleListBox->setWhatsThis(i18nc("@info:whatsthis","Here you can choose the font style to be used." ));
if ( flags & ShowDifferences ) {
((QWidget *)d->styleCheckbox)->setWhatsThis(fontFamilyWhatsThisText );
} else {
((QWidget *)d->styleLabel)->setWhatsThis( fontFamilyWhatsThisText );
d->fillFamilyListBox(flags & FixedFontsOnly);
}
d->familyListBox->setMinimumWidth(minimumListWidth(d->familyListBox));
d->familyListBox->setMinimumHeight(minimumListHeight(d->familyListBox, visibleListSize));
d->styleListBox = new KListWidget(page);
d->styleListBox->setEnabled(flags ^ ShowDifferences);
gridLayout->addWidget(d->styleListBox, row, 1);
d->styleListBox->setWhatsThis(i18nc("@info:whatsthis","Here you can choose the font style to be used."));
if ( flags & ShowDifferences) {
d->styleCheckbox->setWhatsThis(fontFamilyWhatsThisText);
} else {
d->styleLabel->setWhatsThis(fontFamilyWhatsThisText);
}
// Populate usual styles, to determine minimum list width;
// will be replaced later with correct styles.
@ -293,15 +285,13 @@ KFontChooser::KFontChooser( QWidget *parent,
d->styleListBox->addItem(i18nc("@item font","Oblique"));
d->styleListBox->addItem(i18nc("@item font","Bold"));
d->styleListBox->addItem(i18nc("@item font","Bold Italic"));
d->styleListBox->setMinimumWidth( minimumListWidth( d->styleListBox ) );
d->styleListBox->setMinimumHeight(
minimumListHeight( d->styleListBox, visibleListSize ) );
d->styleListBox->setMinimumWidth(minimumListWidth( d->styleListBox));
d->styleListBox->setMinimumHeight(minimumListHeight(d->styleListBox, visibleListSize));
connect(d->styleListBox, SIGNAL(currentTextChanged(QString)),
this, SLOT(_k_style_chosen_slot(QString)));
connect(d->styleListBox, SIGNAL(currentTextChanged(QString)), this, SLOT(_k_style_chosen_slot(QString)));
d->sizeListBox = new KListWidget( page );
d->sizeListBox = new KListWidget(page);
d->sizeOfFont = new KDoubleNumInput(page);
d->sizeOfFont->setMinimum(4);
d->sizeOfFont->setMaximum(999);
@ -309,68 +299,58 @@ KFontChooser::KFontChooser( QWidget *parent,
d->sizeOfFont->setSingleStep(1);
d->sizeOfFont->setSliderEnabled(false);
d->sizeListBox->setEnabled( flags ^ ShowDifferences );
d->sizeOfFont->setEnabled( flags ^ ShowDifferences );
d->sizeListBox->setEnabled(flags ^ ShowDifferences);
d->sizeOfFont->setEnabled(flags ^ ShowDifferences);
if( sizeIsRelativeState ) {
QString sizeIsRelativeCBText =
i18nc("@item font size","Relative");
QString sizeIsRelativeCBToolTipText =
i18n("Font size<br /><i>fixed</i> or <i>relative</i><br />to environment");
QString 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)." );
d->sizeIsRelativeCheckBox = new QCheckBox( sizeIsRelativeCBText,
page );
d->sizeIsRelativeCheckBox->setTristate( flags & ShowDifferences );
QString sizeIsRelativeCBText = i18nc("@item font size","Relative");
QString sizeIsRelativeCBToolTipText = i18n("Font size<br /><i>fixed</i> or <i>relative</i><br />to environment");
QString 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)."
);
d->sizeIsRelativeCheckBox = new QCheckBox(sizeIsRelativeCBText, page);
d->sizeIsRelativeCheckBox->setTristate(flags & ShowDifferences);
QGridLayout *sizeLayout2 = new QGridLayout();
sizeLayout2->setSpacing( KDialog::spacingHint()/2 );
sizeLayout2->setSpacing( KDialog::spacingHint() / 2);
gridLayout->addLayout(sizeLayout2, row, 2);
sizeLayout2->setColumnStretch( 1, 1 ); // to prevent text from eating the right border
sizeLayout2->setColumnStretch(1, 1); // to prevent text from eating the right border
sizeLayout2->addWidget( d->sizeOfFont, 0, 0, 1, 2);
sizeLayout2->addWidget(d->sizeListBox, 1,0, 1,2);
sizeLayout2->addWidget(d->sizeIsRelativeCheckBox, 2, 0, Qt::AlignLeft);
d->sizeIsRelativeCheckBox->setWhatsThis(sizeIsRelativeCBWhatsThisText );
d->sizeIsRelativeCheckBox->setToolTip( sizeIsRelativeCBToolTipText );
}
else {
d->sizeIsRelativeCheckBox = 0L;
d->sizeIsRelativeCheckBox->setWhatsThis(sizeIsRelativeCBWhatsThisText);
d->sizeIsRelativeCheckBox->setToolTip(sizeIsRelativeCBToolTipText);
} else {
d->sizeIsRelativeCheckBox = nullptr;
QGridLayout *sizeLayout2 = new QGridLayout();
sizeLayout2->setSpacing( KDialog::spacingHint()/2 );
sizeLayout2->setSpacing( KDialog::spacingHint() / 2);
gridLayout->addLayout(sizeLayout2, row, 2);
sizeLayout2->addWidget( d->sizeOfFont, 0, 0);
sizeLayout2->addWidget(d->sizeListBox, 1,0);
}
QString fontSizeWhatsThisText =
i18n("Here you can choose the font size to be used." );
d->sizeListBox->setWhatsThis(fontSizeWhatsThisText );
QString fontSizeWhatsThisText = i18n("Here you can choose the font size to be used.");
d->sizeListBox->setWhatsThis(fontSizeWhatsThisText);
if ( flags & ShowDifferences ) {
((QWidget *)d->sizeCheckbox)->setWhatsThis(fontSizeWhatsThisText );
d->sizeCheckbox->setWhatsThis(fontSizeWhatsThisText);
} else {
((QWidget *)d->sizeLabel)->setWhatsThis( fontSizeWhatsThisText );
d->sizeLabel->setWhatsThis(fontSizeWhatsThisText);
}
// Populate with usual sizes, to determine minimum list width;
// will be replaced later with correct sizes.
d->fillSizeList();
d->sizeListBox->setMinimumWidth( minimumListWidth(d->sizeListBox) +
d->sizeListBox->fontMetrics().maxWidth() );
d->sizeListBox->setMinimumHeight(
minimumListHeight( d->sizeListBox, visibleListSize ) );
d->sizeListBox->setMinimumWidth(minimumListWidth(d->sizeListBox) + d->sizeListBox->fontMetrics().maxWidth());
d->sizeListBox->setMinimumHeight(minimumListHeight(d->sizeListBox, visibleListSize));
connect( d->sizeOfFont, SIGNAL(valueChanged(double)),
this, SLOT(_k_size_value_slot(double)));
connect(d->sizeOfFont, SIGNAL(valueChanged(double)), this, SLOT(_k_size_value_slot(double)));
connect( d->sizeListBox, SIGNAL(currentTextChanged(QString)),
this, SLOT(_k_size_chosen_slot(QString)) );
connect(d->sizeListBox, SIGNAL(currentTextChanged(QString)), this, SLOT(_k_size_chosen_slot(QString)) );
row ++;
//
row++;
// Completed the font attribute grid.
// Add the font preview into the lower part of the splitter.
//
d->sampleEdit = new SampleEdit(page);
d->sampleEdit->setAcceptRichText(false);
QFont tmpFont( KGlobalSettings::generalFont().family(), 64, QFont::Black );
@ -382,24 +362,24 @@ KFontChooser::KFontChooser( QWidget *parent,
// If you wish, you can input several lines of text separated by \n.
setSampleText(i18n("The Quick Brown Fox Jumps Over The Lazy Dog"));
d->sampleEdit->setTextCursor(QTextCursor(d->sampleEdit->document()));
QString sampleEditWhatsThisText =
i18n("This sample text illustrates the current settings. "
"You may edit it to test special characters." );
QString sampleEditWhatsThisText = i18n(
"This sample text illustrates the current settings. "
"You may edit it to test special characters."
);
d->sampleEdit->setWhatsThis(sampleEditWhatsThisText );
connect(this, SIGNAL(fontSelected(QFont)),
this, SLOT(_k_displaySample(QFont)));
connect(this, SIGNAL(fontSelected(QFont)), this, SLOT(_k_displaySample(QFont)));
splitter->addWidget(d->sampleEdit);
//
// Finished setting up the splitter.
// lets initialize the display if possible
setFont( d->usingFixed ? KGlobalSettings::fixedFont() : KGlobalSettings::generalFont(), d->usingFixed );
setFont(d->usingFixed ? KGlobalSettings::fixedFont() : KGlobalSettings::generalFont(), d->usingFixed);
// check or uncheck or gray out the "relative" checkbox
if( sizeIsRelativeState && d->sizeIsRelativeCheckBox )
setSizeIsRelative( *sizeIsRelativeState );
if (sizeIsRelativeState && d->sizeIsRelativeCheckBox) {
setSizeIsRelative(*sizeIsRelativeState);
}
// Set focus to the size list as this is the most commonly changed property
d->sizeListBox->setFocus();
@ -424,38 +404,40 @@ void KFontChooser::setColor( const QColor & col )
QColor KFontChooser::color() const
{
return d->m_palette.color( QPalette::Active, QPalette::Text );
return d->m_palette.color(QPalette::Active, QPalette::Text);
}
void KFontChooser::setBackgroundColor( const QColor & col )
void KFontChooser::setBackgroundColor(const QColor &col)
{
d->m_palette.setColor( QPalette::Active, QPalette::Base, col );
d->m_palette.setColor(QPalette::Active, QPalette::Base, col);
QPalette pal = d->sampleEdit->palette();
pal.setColor( QPalette::Active, QPalette::Base, col );
d->sampleEdit->setPalette( pal );
pal.setColor(QPalette::Active, QPalette::Base, col);
d->sampleEdit->setPalette(pal);
}
QColor KFontChooser::backgroundColor() const
{
return d->m_palette.color( QPalette::Active, QPalette::Base );
return d->m_palette.color(QPalette::Active, QPalette::Base);
}
void KFontChooser::setSizeIsRelative( Qt::CheckState relative )
void KFontChooser::setSizeIsRelative(const Qt::CheckState relative)
{
// check or uncheck or gray out the "relative" checkbox
if( d->sizeIsRelativeCheckBox ) {
if( Qt::PartiallyChecked == relative )
if (d->sizeIsRelativeCheckBox) {
if (Qt::PartiallyChecked == relative) {
d->sizeIsRelativeCheckBox->setCheckState(Qt::PartiallyChecked);
else
d->sizeIsRelativeCheckBox->setCheckState( (Qt::Checked == relative ) ? Qt::Checked : Qt::Unchecked);
} else {
d->sizeIsRelativeCheckBox->setCheckState(Qt::Checked == relative ? Qt::Checked : Qt::Unchecked);
}
}
}
Qt::CheckState KFontChooser::sizeIsRelative() const
{
return d->sizeIsRelativeCheckBox
? d->sizeIsRelativeCheckBox->checkState()
: Qt::PartiallyChecked;
if (d->sizeIsRelativeCheckBox) {
return d->sizeIsRelativeCheckBox->checkState();
}
return Qt::PartiallyChecked;
}
QString KFontChooser::sampleText() const
@ -463,41 +445,37 @@ QString KFontChooser::sampleText() const
return d->sampleEdit->toPlainText();
}
void KFontChooser::setSampleText( const QString &text )
void KFontChooser::setSampleText(const QString &text)
{
d->sampleEdit->setPlainText(text);
}
void KFontChooser::setSampleBoxVisible( bool visible )
void KFontChooser::setSampleBoxVisible(bool visible)
{
d->sampleEdit->setVisible( visible );
d->sampleEdit->setVisible(visible);
}
QSize KFontChooser::sizeHint( void ) const
QSize KFontChooser::sizeHint() const
{
return minimumSizeHint();
}
void KFontChooser::enableColumn( int column, bool state )
void KFontChooser::enableColumn(int column, bool state)
{
if( column & FamilyList )
{
if (column & FamilyList) {
d->familyListBox->setEnabled(state);
}
if( column & StyleList )
{
if (column & StyleList) {
d->styleListBox->setEnabled(state);
}
if( column & SizeList )
{
if (column & SizeList) {
d->sizeListBox->setEnabled(state);
d->sizeOfFont->setEnabled(state);
}
}
void KFontChooser::setFont( const QFont& aFont, bool onlyFixed )
void KFontChooser::setFont(const QFont &aFont, bool onlyFixed)
{
d->selFont = aFont;
d->selectedSize=aFont.pointSizeF();
@ -505,31 +483,25 @@ void KFontChooser::setFont( const QFont& aFont, bool onlyFixed )
d->selectedSize = d->fontdb.font(aFont.family(), aFont.styleName(), aFont.pointSize()).pointSizeF();
}
if( onlyFixed != d->usingFixed)
{
if (onlyFixed != d->usingFixed) {
d->usingFixed = onlyFixed;
d->fillFamilyListBox(d->usingFixed);
}
d->setupDisplay();
}
KFontChooser::FontDiffFlags KFontChooser::fontDiffFlags() const
{
FontDiffFlags diffFlags = NoFontDiffFlags;
if ( d->familyCheckbox && d->familyCheckbox->isChecked() ) {
if (d->familyCheckbox && d->familyCheckbox->isChecked()) {
diffFlags |= FontDiffFamily;
}
if ( d->styleCheckbox && d->styleCheckbox->isChecked() ) {
if (d->styleCheckbox && d->styleCheckbox->isChecked()) {
diffFlags |= FontDiffStyle;
}
if ( d->sizeCheckbox && d->sizeCheckbox->isChecked() ) {
if (d->sizeCheckbox && d->sizeCheckbox->isChecked()) {
diffFlags |= FontDiffSize;
}
return diffFlags;
}
@ -540,27 +512,26 @@ QFont KFontChooser::font() const
void KFontChooser::Private::_k_toggled_checkbox()
{
familyListBox->setEnabled( familyCheckbox->isChecked() );
styleListBox->setEnabled( styleCheckbox->isChecked() );
sizeListBox->setEnabled( sizeCheckbox->isChecked() );
sizeOfFont->setEnabled( sizeCheckbox->isChecked() );
familyListBox->setEnabled(familyCheckbox->isChecked());
styleListBox->setEnabled(styleCheckbox->isChecked());
sizeListBox->setEnabled(sizeCheckbox->isChecked());
sizeOfFont->setEnabled(sizeCheckbox->isChecked());
}
void KFontChooser::Private::_k_family_chosen_slot(const QString& family)
void KFontChooser::Private::_k_family_chosen_slot(const QString &family)
{
if ( !signalsAllowed ) {
if (!signalsAllowed) {
return;
}
signalsAllowed = false;
QString currentFamily;
if (family.isEmpty()) {
Q_ASSERT( familyListBox->currentItem() );
Q_ASSERT(familyListBox->currentItem());
if (familyListBox->currentItem()) {
currentFamily = qtFamilies[familyListBox->currentItem()->text()];
currentFamily = qtFamilies[familyListBox->currentItem()->text()];
}
}
else {
} else {
currentFamily = qtFamilies[family];
}
@ -638,9 +609,9 @@ void KFontChooser::Private::_k_family_chosen_slot(const QString& family)
signalsAllowed = true;
}
void KFontChooser::Private::_k_style_chosen_slot(const QString& style)
void KFontChooser::Private::_k_style_chosen_slot(const QString &style)
{
if ( !signalsAllowed ) {
if (!signalsAllowed) {
return;
}
signalsAllowed = false;
@ -670,9 +641,9 @@ void KFontChooser::Private::_k_style_chosen_slot(const QString& style)
signalsAllowed = true;
}
void KFontChooser::Private::_k_size_chosen_slot(const QString& size)
void KFontChooser::Private::_k_size_chosen_slot(const QString &size)
{
if ( !signalsAllowed ) {
if (!signalsAllowed) {
return;
}
@ -704,7 +675,7 @@ void KFontChooser::Private::_k_size_chosen_slot(const QString& size)
void KFontChooser::Private::_k_size_value_slot(double dval)
{
if ( !signalsAllowed ) {
if (!signalsAllowed) {
return;
}
signalsAllowed = false;
@ -734,14 +705,14 @@ void KFontChooser::Private::_k_size_value_slot(double dval)
signalsAllowed = true;
}
void KFontChooser::Private::_k_displaySample( const QFont& font )
void KFontChooser::Private::_k_displaySample(const QFont &font)
{
sampleEdit->setFont(font);
// sampleEdit->setCursorPosition(0);
// kDebug() << "font:" << font.toString();
}
int KFontChooser::Private::nearestSizeRow (qreal val, bool customize)
int KFontChooser::Private::nearestSizeRow(qreal val, bool customize)
{
qreal diff = 1000;
int row = 0;
@ -761,10 +732,10 @@ int KFontChooser::Private::nearestSizeRow (qreal val, bool customize)
return row;
}
qreal KFontChooser::Private::fillSizeList (const QList<qreal> &sizes_)
qreal KFontChooser::Private::fillSizeList(const QList<qreal> &sizes_)
{
if ( !sizeListBox ) {
return 0; //assertion.
if (!sizeListBox) {
return 0; // assertion.
}
QList<qreal> sizes = sizes_;
@ -805,15 +776,15 @@ qreal KFontChooser::Private::fillSizeList (const QList<qreal> &sizes_)
return KGlobal::locale()->readNumber(sizeListBox->item(row)->text());
}
qreal KFontChooser::Private::setupSizeListBox (const QString& family, const QString& style)
qreal KFontChooser::Private::setupSizeListBox(const QString &family, const QString &style)
{
QList<qreal> sizes;
if (fontdb.isScalable(family, style)) {
// A vector font.
//>sampleEdit->setPaletteBackgroundPixmap( VectorPixmap ); // TODO
// sampleEdit->setPaletteBackgroundPixmap( VectorPixmap ); // TODO
} else {
// A bitmap font.
//sampleEdit->setPaletteBackgroundPixmap( BitmapPixmap ); // TODO
// sampleEdit->setPaletteBackgroundPixmap( BitmapPixmap ); // TODO
QList<int> pointSizes = fontdb.pointSizes(family, style);
foreach (const int size, pointSizes) {
sizes.append(qreal(size));
@ -825,9 +796,7 @@ qreal KFontChooser::Private::setupSizeListBox (const QString& family, const QStr
qreal bestFitSize = fillSizeList(sizes);
// Set the best fit size as current in the listbox if available.
const QList<QListWidgetItem*> selectedSizeList =
sizeListBox->findItems( formatFontSize(bestFitSize),
Qt::MatchExactly );
const QList<QListWidgetItem*> selectedSizeList = sizeListBox->findItems(formatFontSize(bestFitSize), Qt::MatchExactly);
if ( !selectedSizeList.isEmpty() ) {
sizeListBox->setCurrentItem(selectedSizeList.first());
}
@ -857,10 +826,8 @@ void KFontChooser::Private::setupDisplay()
}
// 1st family fallback.
if ( i == numEntries )
{
if (family.contains('['))
{
if (i == numEntries) {
if (family.contains('[')) {
family = family.left(family.indexOf('[')).trimmed();
for (i = 0; i < numEntries; i++) {
if (family == qtFamilies[familyListBox->item(i)->text()].toLower()) {
@ -872,8 +839,7 @@ void KFontChooser::Private::setupDisplay()
}
// 2nd family fallback.
if ( i == numEntries )
{
if (i == numEntries) {
QString fallback = family+" [";
for (i = 0; i < numEntries; i++) {
if (qtFamilies[familyListBox->item(i)->text()].toLower().startsWith(fallback)) {
@ -884,8 +850,7 @@ void KFontChooser::Private::setupDisplay()
}
// 3rd family fallback.
if ( i == numEntries )
{
if (i == numEntries) {
for (i = 0; i < numEntries; i++) {
if (qtFamilies[familyListBox->item(i)->text()].toLower().startsWith(family)) {
familyListBox->setCurrentRow(i);
@ -895,8 +860,8 @@ void KFontChooser::Private::setupDisplay()
}
// Family fallback in case nothing matched. Otherwise, diff doesn't work
if ( i == numEntries ) {
familyListBox->setCurrentRow( 0 );
if (i == numEntries) {
familyListBox->setCurrentRow(0);
}
// By setting the current item in the family box, the available
@ -929,17 +894,15 @@ void KFontChooser::Private::setupDisplay()
}
void KFontChooser::getFontList( QStringList &list, uint fontListCriteria)
void KFontChooser::getFontList(QStringList &list, const uint fontListCriteria)
{
QFontDatabase fdb;
QStringList lstSys(fdb.families());
// if we have criteria; then check fonts before adding
if (fontListCriteria)
{
if (fontListCriteria) {
QStringList lstFonts;
for (QStringList::const_iterator it = lstSys.constBegin(); it != lstSys.constEnd(); ++it)
{
for (QStringList::const_iterator it = lstSys.constBegin(); it != lstSys.constEnd(); ++it) {
if ((fontListCriteria & FixedWidthFonts) > 0 && !fdb.isFixedPitch(*it)) continue;
if ((fontListCriteria & SmoothScalableFonts) > 0 && !fdb.isScalable(*it)) continue;
lstFonts.append(*it);
@ -948,8 +911,9 @@ void KFontChooser::getFontList( QStringList &list, uint fontListCriteria)
if((fontListCriteria & FixedWidthFonts) > 0) {
// Fallback.. if there are no fixed fonts found, it's probably a
// bug in the font server or Qt. In this case, just use 'fixed'
if (lstFonts.count() == 0)
if (lstFonts.count() == 0) {
lstFonts.append("fixed");
}
}
lstSys = lstFonts;
@ -974,7 +938,7 @@ void KFontChooser::Private::setFamilyBoxItems(const QStringList &fonts)
void KFontChooser::Private::fillFamilyListBox(bool onlyFixedFonts)
{
QStringList fontList;
getFontList(fontList, onlyFixedFonts?FixedWidthFonts:0);
getFontList(fontList, onlyFixedFonts ? FixedWidthFonts : 0);
setFamilyBoxItems(fontList);
}

View file

@ -21,8 +21,8 @@
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#ifndef K_FONT_CHOOSER_H
#define K_FONT_CHOOSER_H
#ifndef KFONTCHOOSER_H
#define KFONTCHOOSER_H
#include <kdeui_export.h>
#include <QtGui/QWidget>
@ -46,220 +46,229 @@
*/
class KDEUI_EXPORT KFontChooser : public QWidget
{
Q_OBJECT
Q_PROPERTY( QFont font READ font WRITE setFont NOTIFY fontSelected USER true )
Q_PROPERTY( QColor color READ color WRITE setColor )
Q_PROPERTY( QColor backgroundColor READ backgroundColor WRITE setBackgroundColor )
Q_PROPERTY( Qt::CheckState sizeIsRelative READ sizeIsRelative WRITE setSizeIsRelative )
Q_PROPERTY( QString sampleText READ sampleText WRITE setSampleText )
Q_OBJECT
Q_PROPERTY(QFont font READ font WRITE setFont NOTIFY fontSelected USER true)
Q_PROPERTY(QColor color READ color WRITE setColor)
Q_PROPERTY(QColor backgroundColor READ backgroundColor WRITE setBackgroundColor)
Q_PROPERTY(Qt::CheckState sizeIsRelative READ sizeIsRelative WRITE setSizeIsRelative)
Q_PROPERTY(QString sampleText READ sampleText WRITE setSampleText)
public:
/**
* 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 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,
SmoothScalableFonts = 0x02
};
/**
* @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};
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 { NoFontDiffFlags = 0,
FontDiffFamily = 1,
FontDiffStyle = 2,
FontDiffSize = 4,
AllFontDiffs = FontDiffFamily | FontDiffStyle | FontDiffSize };
Q_DECLARE_FLAGS( FontDiffFlags, FontDiff )
enum FontDiff {
NoFontDiffFlags = 0,
FontDiffFamily = 1,
FontDiffStyle = 2,
FontDiffSize = 4,
AllFontDiffs = FontDiffFamily | FontDiffStyle | FontDiffSize
};
Q_DECLARE_FLAGS(FontDiffFlags, FontDiff)
/**
* @li @p FixedFontsOnly only show fixed fonts, excluding proportional fonts
* @li @p DisplayFrame show a visual frame around the chooser
* @li @p ShowDifferences display the font differences interfaces
*/
enum DisplayFlag { NoDisplayFlags = 0,
FixedFontsOnly = 1,
DisplayFrame = 2,
ShowDifferences = 4 };
Q_DECLARE_FLAGS( DisplayFlags, DisplayFlag )
enum DisplayFlag {
NoDisplayFlags = 0,
FixedFontsOnly = 1,
DisplayFrame = 2,
ShowDifferences = 4
};
Q_DECLARE_FLAGS(DisplayFlags, DisplayFlag)
/**
* 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
* QStringList list;
* KFontChooser::getFontList(list, KFontChooser::SmoothScalableFonts);
* KFontChooser *chooseFont = new KFontChooser(0, NoDisplayFlags, list);
* \endcode
* <p>
* The above creates a font chooser dialog with only SmoothScaleble fonts.
*
* @param parent The parent widget.
* @param flags Defines how the font chooser is displayed. @see DisplayFlags
* @param fontList A list of fonts families to display. If the list is
* empty, all fonts available on the system are displayed.
* @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().
*/
explicit KFontChooser( QWidget *parent = 0L,
const DisplayFlags& flags = DisplayFrame,
const QStringList &fontList = QStringList(),
int visibleListSize = 8,
Qt::CheckState *sizeIsRelativeState = 0L );
/**
* 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
* QStringList list;
* KFontChooser::getFontList(list, KFontChooser::SmoothScalableFonts);
* KFontChooser *chooseFont = new KFontChooser(0, NoDisplayFlags, list);
* \endcode
* <p>
* The above creates a font chooser dialog with only SmoothScaleble fonts.
*
* @param parent The parent widget.
* @param flags Defines how the font chooser is displayed. @see DisplayFlags
* @param fontList A list of fonts families to display. If the list is
* empty, all fonts available on the system are displayed.
* @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().
*/
explicit KFontChooser(QWidget *parent = nullptr,
const DisplayFlags flags = DisplayFrame,
const QStringList &fontList = QStringList(),
int visibleListSize = 8,
Qt::CheckState *sizeIsRelativeState = nullptr);
/**
* Destructs the font chooser.
*/
virtual ~KFontChooser();
/**
* Destructs the font chooser.
*/
virtual ~KFontChooser();
/**
* 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 );
/**
* 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 QFont &font, bool onlyFixed = false );
/**
* 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 QFont &font, bool onlyFixed = false);
/**
* @return The bitmask corresponding to the attributes the user
* wishes to change.
*/
FontDiffFlags fontDiffFlags() const;
/**
* @return The bitmask corresponding to the attributes the user
* wishes to change.
*/
FontDiffFlags fontDiffFlags() const;
/**
* @return The currently selected font in the chooser.
*/
QFont font() const;
/**
* @return The currently selected font in the chooser.
*/
QFont font() const;
/**
* Sets the color to use in the preview.
*/
void setColor( const QColor & col );
/**
* Sets the color to use in the preview.
*/
void setColor(const QColor &col);
/**
* @return The color currently used in the preview (default: the text
* color of the active color group)
*/
QColor color() const;
/**
* @return The color currently used in the preview (default: the text
* color of the active color group)
*/
QColor color() const;
/**
* Sets the background color to use in the preview.
*/
void setBackgroundColor( const QColor & col );
/**
* Sets the background color to use in the preview.
*/
void setBackgroundColor(const QColor &col);
/**
* @return The background color currently used in the preview (default:
* the base color of the active colorgroup)
*/
QColor backgroundColor() const;
/**
* @return The background color currently used in the preview (default:
* the base color of the active colorgroup)
*/
QColor 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( Qt::CheckState relative );
/**
* 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(const Qt::CheckState relative);
/**
* @return Whether the font size is to be interpreted as relative size
* (default: QButton:Off)
*/
Qt::CheckState sizeIsRelative() const;
/**
* @return Whether the font size is to be interpreted as relative size
* (default: QButton:Off)
*/
Qt::CheckState sizeIsRelative() const;
/**
* @return The current text in the sample text input area.
*/
QString sampleText() const;
/**
* @return The current text in the sample text input area.
*/
QString sampleText() const;
/**
* 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 QString &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 QString &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);
/**
* 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 );
/**
* 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 KFontChooser::FontListCriteria for the individual values
*/
static void getFontList(QStringList &list, const uint fontListCriteria);
/**
* 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 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, SmoothScalableFonts=0x02 };
/**
* 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 KFontChooser::FontListCriteria for the individual values
*/
static void getFontList( QStringList &list, uint fontListCriteria);
/**
* Reimplemented for internal reasons.
*/
virtual QSize sizeHint( void ) const;
/**
* Reimplemented for internal reasons.
*/
virtual QSize sizeHint() const;
Q_SIGNALS:
/**
* Emitted whenever the selected font changes.
*/
void fontSelected( const QFont &font );
/**
* Emitted whenever the selected font changes.
*/
void fontSelected(const QFont &font);
private:
Q_DISABLE_COPY(KFontChooser)
class Private;
Private * const d;
Q_DISABLE_COPY(KFontChooser)
Q_PRIVATE_SLOT(d, void _k_toggled_checkbox())
Q_PRIVATE_SLOT(d, void _k_family_chosen_slot(const QString&))
Q_PRIVATE_SLOT(d, void _k_size_chosen_slot(const QString&))
Q_PRIVATE_SLOT(d, void _k_style_chosen_slot(const QString&))
Q_PRIVATE_SLOT(d, void _k_family_chosen_slot(const QString &))
Q_PRIVATE_SLOT(d, void _k_size_chosen_slot(const QString &))
Q_PRIVATE_SLOT(d, void _k_style_chosen_slot(const QString &))
Q_PRIVATE_SLOT(d, void _k_displaySample(const QFont &font))
Q_PRIVATE_SLOT(d, void _k_size_value_slot(double))
};
Q_DECLARE_OPERATORS_FOR_FLAGS( KFontChooser::DisplayFlags )
Q_DECLARE_OPERATORS_FOR_FLAGS(KFontChooser::DisplayFlags)
#endif
#endif // KFONTCHOOSER_H

View file

@ -57,30 +57,29 @@ class KFontDialog::Private
{
public:
Private()
: chooser( 0 )
: chooser(nullptr)
{
}
KFontChooser *chooser;
};
KFontDialog::KFontDialog( QWidget *parent,
const KFontChooser::DisplayFlags& flags,
const QStringList &fontList,
Qt::CheckState *sizeIsRelativeState )
: KDialog( parent ),
d( new Private )
KFontDialog::KFontDialog(QWidget *parent,
const KFontChooser::DisplayFlags flags,
const QStringList &fontList,
Qt::CheckState *sizeIsRelativeState)
: KDialog(parent),
d(new Private())
{
setCaption( i18n("Select Font") );
setButtons( Ok | Cancel );
setDefaultButton(Ok);
d->chooser = new KFontChooser( this, flags, fontList, 8,
sizeIsRelativeState );
d->chooser->setObjectName( "fontChooser" );
setCaption(i18n("Select Font"));
setButtons(KDialog::Ok | KDialog::Cancel);
setDefaultButton(KDialog::Ok);
d->chooser = new KFontChooser(this, flags, fontList, 8, sizeIsRelativeState);
d->chooser->setObjectName("fontChooser");
connect( d->chooser , SIGNAL(fontSelected(QFont)) , this , SIGNAL(fontSelected(QFont)) );
connect(d->chooser , SIGNAL(fontSelected(QFont)), this , SIGNAL(fontSelected(QFont)));
setMainWidget( d->chooser );
setMainWidget(d->chooser);
}
KFontDialog::~KFontDialog()
@ -88,7 +87,7 @@ KFontDialog::~KFontDialog()
delete d;
}
void KFontDialog::setFont( const QFont &font, bool onlyFixed)
void KFontDialog::setFont(const QFont &font, bool onlyFixed)
{
d->chooser->setFont(font, onlyFixed);
}
@ -98,9 +97,9 @@ QFont KFontDialog::font() const
return d->chooser->font();
}
void KFontDialog::setSizeIsRelative( Qt::CheckState relative )
void KFontDialog::setSizeIsRelative(const Qt::CheckState relative)
{
d->chooser->setSizeIsRelative( relative );
d->chooser->setSizeIsRelative(relative);
}
Qt::CheckState KFontDialog::sizeIsRelative() const
@ -108,69 +107,65 @@ Qt::CheckState KFontDialog::sizeIsRelative() const
return d->chooser->sizeIsRelative();
}
int KFontDialog::getFontDiff( QFont &theFont,
KFontChooser::FontDiffFlags& diffFlags,
const KFontChooser::DisplayFlags& flags,
QWidget *parent,
Qt::CheckState *sizeIsRelativeState )
int KFontDialog::getFontDiff(QFont &theFont,
KFontChooser::FontDiffFlags& diffFlags,
const KFontChooser::DisplayFlags flags,
QWidget *parent,
Qt::CheckState *sizeIsRelativeState )
{
KFontDialog dlg( parent, flags | KFontChooser::ShowDifferences,
QStringList(), sizeIsRelativeState );
dlg.setModal( true );
dlg.setObjectName( "Font Selector" );
dlg.setFont( theFont, flags & KFontChooser::FixedFontsOnly );
KFontDialog dlg(parent, flags | KFontChooser::ShowDifferences, QStringList(), sizeIsRelativeState);
dlg.setModal(true);
dlg.setObjectName("Font Selector");
dlg.setFont(theFont, flags & KFontChooser::FixedFontsOnly);
int result = dlg.exec();
if( result == Accepted )
{
const int result = dlg.exec();
if (result == KDialog::Accepted) {
theFont = dlg.d->chooser->font();
diffFlags = dlg.d->chooser->fontDiffFlags();
if( sizeIsRelativeState )
if (sizeIsRelativeState) {
*sizeIsRelativeState = dlg.d->chooser->sizeIsRelative();
}
}
return result;
}
int KFontDialog::getFont( QFont &theFont,
const KFontChooser::DisplayFlags& flags,
QWidget *parent,
Qt::CheckState *sizeIsRelativeState )
int KFontDialog::getFont(QFont &theFont,
const KFontChooser::DisplayFlags flags,
QWidget *parent,
Qt::CheckState *sizeIsRelativeState)
{
KFontDialog dlg( parent, flags, QStringList(), sizeIsRelativeState );
dlg.setModal( true );
dlg.setObjectName( "Font Selector" );
dlg.setFont( theFont, flags & KFontChooser::FixedFontsOnly );
KFontDialog dlg(parent, flags, QStringList(), sizeIsRelativeState);
dlg.setModal(true);
dlg.setObjectName("Font Selector");
dlg.setFont(theFont, flags & KFontChooser::FixedFontsOnly);
int result = dlg.exec();
if( result == Accepted )
{
const int result = dlg.exec();
if (result == KDialog::Accepted) {
theFont = dlg.d->chooser->font();
if( sizeIsRelativeState )
if (sizeIsRelativeState) {
*sizeIsRelativeState = dlg.d->chooser->sizeIsRelative();
}
}
return result;
}
int KFontDialog::getFontAndText( QFont &theFont, QString &theString,
const KFontChooser::DisplayFlags& flags,
QWidget *parent,
Qt::CheckState *sizeIsRelativeState )
int KFontDialog::getFontAndText(QFont &theFont, QString &theString,
const KFontChooser::DisplayFlags flags,
QWidget *parent,
Qt::CheckState *sizeIsRelativeState)
{
KFontDialog dlg( parent, flags,
QStringList(), sizeIsRelativeState );
dlg.setModal( true );
dlg.setObjectName( "Font and Text Selector" );
dlg.setFont( theFont, flags & KFontChooser::FixedFontsOnly );
KFontDialog dlg(parent, flags, QStringList(), sizeIsRelativeState );
dlg.setModal(true);
dlg.setObjectName("Font and Text Selector");
dlg.setFont(theFont, flags & KFontChooser::FixedFontsOnly);
int result = dlg.exec();
if( result == Accepted )
{
theFont = dlg.d->chooser->font();
const int result = dlg.exec();
if( result == KDialog::Accepted) {
theFont = dlg.d->chooser->font();
theString = dlg.d->chooser->sampleText();
if( sizeIsRelativeState )
if (sizeIsRelativeState) {
*sizeIsRelativeState = dlg.d->chooser->sizeIsRelative();
}
}
return result;
}

View file

@ -21,8 +21,8 @@
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#ifndef K_FONT_DIALOG_H
#define K_FONT_DIALOG_H
#ifndef KFONTDIALOG_H
#define KFONTDIALOG_H
#include <kdialog.h>
#include <kfontchooser.h>
@ -53,166 +53,162 @@
*
* @author Preston Brown <pbrown@kde.org>, Bernd Wuebben <wuebben@kde.org>
*/
class KDEUI_EXPORT KFontDialog : public KDialog {
class KDEUI_EXPORT KFontDialog : public KDialog
{
Q_OBJECT
public:
/**
* Constructs a font selection dialog.
*
* @param parent The parent widget of the dialog, if any.
* @param flags Defines how the font chooser is displayed.
* @see KFontChooser::DisplayFlags
* @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 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().
*
*/
explicit KFontDialog( QWidget *parent = 0,
const KFontChooser::DisplayFlags& flags =
KFontChooser::NoDisplayFlags,
const QStringList &fontlist = QStringList(),
Qt::CheckState *sizeIsRelativeState = 0 );
/**
* Constructs a font selection dialog.
*
* @param parent The parent widget of the dialog, if any.
* @param flags Defines how the font chooser is displayed.
* @see KFontChooser::DisplayFlags
* @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 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().
*
*/
explicit KFontDialog(QWidget *parent = nullptr,
const KFontChooser::DisplayFlags flags = KFontChooser::NoDisplayFlags,
const QStringList &fontlist = QStringList(),
Qt::CheckState *sizeIsRelativeState = nullptr);
~KFontDialog();
/**
* 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 QFont &font, bool onlyFixed = false );
~KFontDialog();
/**
* @return The currently selected font in the dialog.
*/
QFont font() const;
/**
* 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 QFont &font, bool onlyFixed = false);
/**
* 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( Qt::CheckState relative );
/**
* @return The currently selected font in the dialog.
*/
QFont font() const;
/**
* @return Whether the font size is to be interpreted as relative size
* (default: false)
*/
Qt::CheckState sizeIsRelative() 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 dialog this setting will be ignored.
*/
void setSizeIsRelative(const Qt::CheckState relative);
/**
* 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 flags Defines how the font chooser is displayed.
* @see KFontChooser::DisplayFlags
* @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 QDialog::result().
*/
static int getFont( QFont &theFont,
const KFontChooser::DisplayFlags& flags =
KFontChooser::NoDisplayFlags,
QWidget *parent = 0L,
Qt::CheckState *sizeIsRelativeState = 0L );
/**
* @return Whether the font size is to be interpreted as relative size
* (default: false)
*/
Qt::CheckState sizeIsRelative() const;
/**
* 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 flags Defines how the font chooser is displayed.
* @see KFontChooser::DisplayFlags
* @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 & KFontChooser::FontDiffFamily )
* [...]
* if ( diffFlags & KFontChooser::FontDiffStyle )
* [...]
* if ( diffFlags & KFontChooser::FontDiffSize )
* [...]
* \endcode
* @param parent Parent widget of the dialog. Specifying a widget different
* from 0 (Null) improves centering (looks better).
* @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 QDialog::result().
*/
static int getFontDiff( QFont &theFont,
KFontChooser::FontDiffFlags& diffFlags,
const KFontChooser::DisplayFlags& flags =
KFontChooser::NoDisplayFlags,
QWidget *parent = 0L,
Qt::CheckState *sizeIsRelativeState = 0L );
/**
* 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 flags Defines how the font chooser is displayed.
* @see KFontChooser::DisplayFlags
* @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 QDialog::result().
*/
static int getFont(QFont &theFont,
const KFontChooser::DisplayFlags flags = KFontChooser::NoDisplayFlags,
QWidget *parent = nullptr,
Qt::CheckState *sizeIsRelativeState = nullptr);
/**
* 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 flags Defines how the font chooser is displayed.
* @see KFontChooser::DisplayFlags
* @param parent Parent widget of the dialog. Specifying a widget different
* from 0 (Null) improves centering (looks better).
* @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( QFont &theFont, QString &theString,
const KFontChooser::DisplayFlags& flags =
KFontChooser::NoDisplayFlags,
QWidget *parent = 0L,
Qt::CheckState *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 flags Defines how the font chooser is displayed.
* @see KFontChooser::DisplayFlags
* @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 & KFontChooser::FontDiffFamily )
* [...]
* if ( diffFlags & KFontChooser::FontDiffStyle )
* [...]
* if ( diffFlags & KFontChooser::FontDiffSize )
* [...]
* \endcode
* @param parent Parent widget of the dialog. Specifying a widget different
* from 0 (Null) improves centering (looks better).
* @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 QDialog::result().
*/
static int getFontDiff(QFont &theFont,
KFontChooser::FontDiffFlags& diffFlags,
const KFontChooser::DisplayFlags flags = KFontChooser::NoDisplayFlags,
QWidget *parent = nullptr,
Qt::CheckState *sizeIsRelativeState = nullptr);
/**
* 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 flags Defines how the font chooser is displayed.
* @see KFontChooser::DisplayFlags
* @param parent Parent widget of the dialog. Specifying a widget different
* from 0 (Null) improves centering (looks better).
* @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(QFont &theFont, QString &theString,
const KFontChooser::DisplayFlags flags = KFontChooser::NoDisplayFlags,
QWidget *parent = nullptr,
Qt::CheckState *sizeIsRelativeState = nullptr);
Q_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 QFont &font );
/**
* 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 QFont &font);
private:
class Private;
Private * const d;
Q_DISABLE_COPY(KFontDialog)
Q_DISABLE_COPY(KFontDialog)
class Private;
Private * const d;
};
#endif
#endif // KFONTDIALOG_H

View file

@ -56,7 +56,7 @@ public:
* @param onlyFixed Only display fonts which have fixed-width character
* sizes.
*/
explicit KFontRequester(QWidget *parent = 0L, bool onlyFixed = false);
explicit KFontRequester(QWidget *parent = nullptr, bool onlyFixed = false);
~KFontRequester();