[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-core-devel
Subject: [patch] kfontdialog & kcontrol/fonts
From: Alexander Kellett <kelletta () eidetica ! com>
Date: 2001-09-16 22:29:37
[Download RAW message or body]
Attached are two patchs to make a change in kcontrol
that i've always wanted to add.
It adds a new function to KFontDialog - getFontDiff,
which lets the user to for example set all the fonts
to size 8 - the new dialog is in the attached gif.
To make use of this functionality i've also made a
few changes in kcontrol/fonts to use the dialog
to selectively change all of the font properties
at the same time.
I'm not really sure about the whole sc/bc thing so
i'll just send in the patch instead of worrying ;-)
thanks,
Alex
--
Eidetica kelletta@eidetica.com
Kruislaan 400 tel +31 20 888 4090 fax 4001
NL 1098 SM Amsterdam
http://www.eidetica.com/ Alexander Kellett
["snapshot1.png" (image/png)]
["kcontrol-font-adjust.patch" (text/plain)]
Index: fonts.cpp
===================================================================
RCS file: /home/kde/kdebase/kcontrol/fonts/fonts.cpp,v
retrieving revision 1.25
diff -u -3 -p -r1.25 fonts.cpp
--- fonts.cpp 2001/06/27 03:32:26 1.25
+++ fonts.cpp 2001/09/16 21:57:55
@@ -175,6 +175,22 @@ void FontUseItem::choose()
}
}
+void FontUseItem::applyFontDiff( const QFont &fnt, int fontDiffFlags )
+{
+ if (fontDiffFlags && KFontChooser::FontDiffSize) {
+ _font.setPointSize( fnt.pointSize() );
+ }
+ if (fontDiffFlags && KFontChooser::FontDiffFamily) {
+ if (!fixed) _font.setFamily( fnt.family() );
+ }
+ if (fontDiffFlags && KFontChooser::FontDiffStyle) {
+ _font.setBold( fnt.bold() );
+ _font.setItalic( fnt.italic() );
+ _font.setUnderline( fnt.underline() );
+ }
+ updateLabel();
+}
+
void FontUseItem::updateLabel()
{
QString fontDesc = _font.family() + ' ' + QString::number(_font.pointSize()) + ' ' + _charset;
@@ -296,6 +312,11 @@ KFonts::KFonts(QWidget *parent, const ch
++count;
}
+ QPushButton * fontAdjustButton = new QPushButton(i18n("Adjust all fonts"), this);
+ QWhatsThis::add(fontAdjustButton, i18n("Click to adjust fonts"));
+ connect(fontAdjustButton, SIGNAL(clicked()), this, SLOT(slotApplyFontDiff()));
+ layout->addWidget(fontAdjustButton);
+
cbAA = new QCheckBox( i18n( "Use A&nti-Aliasing for fonts and icons" ),this);
QWhatsThis::add(cbAA,
@@ -416,6 +437,21 @@ void KFonts::save()
int KFonts::buttons()
{
return KCModule::Help | KCModule::Default | KCModule::Apply;
+}
+
+void KFonts::slotApplyFontDiff()
+{
+ QFont font = QFont(fontUseList.first()->font());
+ int fontDiffFlags = 0;
+ int ret = KFontDialog::getFontDiff(font,fontDiffFlags);
+
+ if (ret && fontDiffFlags)
+ {
+ for ( int i = 0; i < (int) fontUseList.count(); i++ )
+ fontUseList.at( i )->applyFontDiff( font,fontDiffFlags );
+ _changed = true;
+ emit changed(true);
+ }
}
void KFonts::slotUseAntiAliasing()
Index: fonts.h
===================================================================
RCS file: /home/kde/kdebase/kcontrol/fonts/fonts.h,v
retrieving revision 1.5
diff -u -3 -p -r1.5 fonts.h
--- fonts.h 2001/05/15 15:57:13 1.5
+++ fonts.h 2001/09/16 21:57:55
@@ -27,6 +27,7 @@ public:
void writeFont();
void setDefault();
void setFont(const QFont &fnt ) { _font = fnt; }
+ void applyFontDiff(const QFont &fnt, int fontDiffFlags);
QFont font() { return _font; }
const QString& rcFile() { return _rcfile; }
@@ -80,6 +81,7 @@ signals:
protected slots:
void fontChanged();
+ void slotApplyFontDiff();
void slotUseAntiAliasing();
private:
["kfontdialog-fontdiff.patch" (text/plain)]
Index: kfontdialog.h
===================================================================
RCS file: /home/kde/kdelibs/kdeui/kfontdialog.h,v
retrieving revision 1.42
diff -u -3 -p -r1.42 kfontdialog.h
--- kfontdialog.h 2001/07/01 20:10:30 1.42
+++ kfontdialog.h 2001/09/16 22:22:05
@@ -27,6 +27,7 @@
#define _K_FONT_DIALOG_H_
#include <qlineedit.h>
+#include <qcheckbox.h>
#include <kdialogbase.h>
class QComboBox;
@@ -65,6 +66,8 @@ public:
enum FontColumn { FamilyList=0x01, StyleList=0x02, SizeList=0x04,
CharsetList=0x08 };
+ enum FontDiff { FontDiffFamily=0x01, FontDiffStyle=0x02, FontDiffSize=0x04 };
+
/**
* Constructs a font picker widget.
*
@@ -82,7 +85,7 @@ public:
KFontChooser(QWidget *parent = 0L, const char *name = 0L,
bool onlyFixed = false,
const QStringList &fontList = QStringList(),
- bool makeFrame = true, int visibleListSize=8 );
+ bool makeFrame = true, bool diff = false, int visibleListSize=8);
virtual ~KFontChooser();
@@ -108,6 +111,8 @@ public:
*/
void setFont( const QFont &font, bool onlyFixed = false );
+ int fontDiffFlags();
+
/**
* @return The currently selected font in the chooser.
*/
@@ -185,6 +190,7 @@ public:
virtual QSize sizeHint( void ) const;
private slots:
+ void toggled_checkbox();
void family_chosen_slot(const QString&);
void size_chosen_slot(const QString&);
void style_chosen_slot(const QString&);
@@ -217,6 +223,9 @@ private:
QLabel *familyLabel;
QLabel *styleLabel;
+ QCheckBox *familyCheckbox;
+ QCheckBox *styleCheckbox;
+ QCheckBox *sizeCheckbox;
QLabel *sizeLabel;
KListBox *familyListBox;
KListBox *styleListBox;
@@ -276,7 +285,7 @@ public:
KFontDialog( QWidget *parent = 0L, const char *name = 0,
bool onlyFixed = false, bool modal = false,
const QStringList &fontlist = QStringList(),
- bool makeFrame = true );
+ bool makeFrame = true, bool diff = false );
/**
* Sets the currently selected font in the dialog.
@@ -318,6 +327,9 @@ public:
* @returns @ref QDialog::result().
*/
static int getFont( QFont &theFont, bool onlyFixed = false,
+ QWidget *parent = 0L, bool makeFrame = true );
+
+ static int getFontDiff( QFont &theFont, int &diffFlags, bool onlyFixed = false,
QWidget *parent = 0L, bool makeFrame = true );
/**
Index: kfontdialog.cpp
===================================================================
RCS file: /home/kde/kdelibs/kdeui/kfontdialog.cpp,v
retrieving revision 1.64
diff -u -3 -p -r1.64 kfontdialog.cpp
--- kfontdialog.cpp 2001/07/19 10:20:35 1.64
+++ kfontdialog.cpp 2001/09/16 22:22:06
@@ -30,6 +30,7 @@
#include <stdlib.h>
#include <qcombobox.h>
+#include <qcheckbox.h>
#include <qfile.h>
#include <qfont.h>
#include <qgroupbox.h>
@@ -89,7 +90,7 @@ public:
KFontChooser::KFontChooser(QWidget *parent, const char *name,
bool onlyFixed, const QStringList &fontList,
- bool makeFrame, int visibleListSize )
+ bool makeFrame, bool diff, int visibleListSize )
: QWidget(parent, name), usingFixed(onlyFixed)
{
d = new KFontChooserPrivate;
@@ -116,12 +117,41 @@ KFontChooser::KFontChooser(QWidget *pare
//
// first, create the labels across the top
//
+ QHBoxLayout *familyLayout = new QHBoxLayout(page);
+ if (diff) {
+ familyCheckbox = new QCheckBox(page);
+ connect(familyCheckbox, SIGNAL(toggled(bool)), SLOT(toggled_checkbox()));
+ familyLayout->addWidget(familyCheckbox, 0);
+ }
familyLabel = new QLabel( i18n("Font"), page, "familyLabel" );
- gridLayout->addWidget(familyLabel, row, 0, AlignLeft );
+ familyLabel->setEnabled( !diff );
+ familyLayout->addSpacing(5);
+ familyLayout->addWidget(familyLabel, 1);
+ gridLayout->addLayout(familyLayout, row, 0 );
+
+ QHBoxLayout *styleLayout = new QHBoxLayout(page);
+ if (diff) {
+ styleCheckbox = new QCheckBox(page);
+ connect(styleCheckbox, SIGNAL(toggled(bool)), SLOT(toggled_checkbox()));
+ styleLayout->addWidget(styleCheckbox, 0);
+ }
styleLabel = new QLabel( i18n("Font style"), page, "styleLabel");
- gridLayout->addWidget(styleLabel, row, 1, AlignLeft);
+ styleLabel->setEnabled( !diff );
+ styleLayout->addSpacing(5);
+ styleLayout->addWidget(styleLabel, 0);
+ gridLayout->addLayout(styleLayout, row, 1 );
+
+ QHBoxLayout *sizeLayout = new QHBoxLayout(page);
+ if (diff) {
+ sizeCheckbox = new QCheckBox(page);
+ connect(sizeCheckbox, SIGNAL(toggled(bool)), SLOT(toggled_checkbox()));
+ sizeLayout->addWidget(sizeCheckbox, 0);
+ }
sizeLabel = new QLabel( i18n("Size"), page, "sizeLabel");
- gridLayout->addWidget(sizeLabel, row, 2, AlignLeft);
+ sizeLabel->setEnabled( !diff );
+ sizeLayout->addSpacing(5);
+ sizeLayout->addWidget(sizeLabel, 0);
+ gridLayout->addLayout(sizeLayout, row, 2 );
row ++;
@@ -129,6 +159,7 @@ KFontChooser::KFontChooser(QWidget *pare
// now create the actual boxes that hold the info
//
familyListBox = new KListBox( page, "familyListBox");
+ familyListBox->setEnabled( !diff );
gridLayout->addWidget( familyListBox, row, 0 );
connect(familyListBox, SIGNAL(highlighted(const QString &)),
SLOT(family_chosen_slot(const QString &)));
@@ -146,6 +177,7 @@ KFontChooser::KFontChooser(QWidget *pare
minimumListHeight( familyListBox, visibleListSize ) );
styleListBox = new KListBox( page, "styleListBox");
+ styleListBox->setEnabled( !diff );
gridLayout->addWidget(styleListBox, row, 1);
styleListBox->insertItem(i18n("Regular"));
styleListBox->insertItem(i18n("Italic"));
@@ -160,6 +192,7 @@ KFontChooser::KFontChooser(QWidget *pare
sizeListBox = new KListBox( page, "sizeListBox");
+ sizeListBox->setEnabled( !diff );
gridLayout->addWidget(sizeListBox, row, 2);
const char *c[] =
@@ -325,6 +358,16 @@ QString KFontChooser::charset() const
return charsetsCombo->currentText();
}
+int KFontChooser::fontDiffFlags() {
+ int diffFlags = 0;
+ if (familyCheckbox&&styleCheckbox&&sizeCheckbox) {
+ if (familyCheckbox->isChecked()) diffFlags |= FontDiffFamily;
+ if (styleCheckbox->isChecked()) diffFlags |= FontDiffStyle;
+ if (sizeCheckbox->isChecked()) diffFlags |= FontDiffSize;
+ }
+ return diffFlags;
+}
+
void KFontChooser::fillCharsetsCombo()
{
int i;
@@ -347,6 +390,16 @@ void KFontChooser::fillCharsetsCombo()
}
}
+void KFontChooser::toggled_checkbox()
+{
+ familyLabel->setEnabled( familyCheckbox->isChecked() );
+ familyListBox->setEnabled( familyCheckbox->isChecked() );
+ styleLabel->setEnabled( styleCheckbox->isChecked() );
+ styleListBox->setEnabled( styleCheckbox->isChecked() );
+ sizeLabel->setEnabled( sizeCheckbox->isChecked() );
+ sizeListBox->setEnabled( sizeCheckbox->isChecked() );
+}
+
void KFontChooser::family_chosen_slot(const QString& family)
{
selFont.setFamily(family);
@@ -531,13 +584,28 @@ void KFontChooser::showXLFDArea(bool sho
KFontDialog::KFontDialog( QWidget *parent, const char* name,
bool onlyFixed, bool modal,
- const QStringList &fontList, bool makeFrame )
+ const QStringList &fontList, bool makeFrame, bool diff )
: KDialogBase( parent, name, modal, i18n("Select Font"), Ok|Cancel, Ok )
{
- chooser = new KFontChooser(this,"fontChooser",onlyFixed,fontList,makeFrame);
+ chooser = new KFontChooser(this,"fontChooser",onlyFixed,fontList,makeFrame,diff);
setMainWidget(chooser);
}
+int KFontDialog::getFontDiff( QFont &theFont, int &diffFlags, bool onlyFixed,
+ QWidget *parent, bool makeFrame )
+{
+ KFontDialog dlg( parent, "Font Selector", onlyFixed, true, QStringList(),
+ makeFrame, true );
+ dlg.setFont( theFont, onlyFixed );
+
+ int result = dlg.exec();
+ if( result == Accepted )
+ {
+ theFont = dlg.chooser->font();
+ diffFlags = dlg.chooser->fontDiffFlags();
+ }
+ return( result );
+}
int KFontDialog::getFont( QFont &theFont, bool onlyFixed, QWidget *parent,
bool makeFrame )
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic