1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
|
/***************************************************************************
fontfamilychooser.cpp - description
-------------------
begin : mer lug 23 11:20:17 CEST 2003
copyright : (C) |YEAR| by si2003 email : gulmini.luciano@student.unife.it
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include "fontfamilychooser.h"
#include <tqfontdatabase.h>
#include <tqstringlist.h>
#include <tqlistbox.h>
#include <tqfont.h>
#include <klocale.h>
#include <tqiconset.h>
#include <tqpixmap.h>
#include <kiconloader.h>
#include <kpushbutton.h>
#include <kglobalsettings.h>
#include <tqregexp.h>
#include <tqlineedit.h>
#include <tqwhatsthis.h>
#include<kdebug.h>
fontFamilyChooser::fontFamilyChooser(TQWidget* parent, const char *name) : fontFamilyChooserS(parent,name){
TQFont tmpFont( KGlobalSettings::generalFont().family(), 64, TQFont::Black );
lePreview->setMinimumHeight( lePreview->fontMetrics().lineSpacing() );
lePreview->setAlignment(Qt::AlignCenter);
TQFont font;
font.setPointSize(20);
lePreview->setFont(font);
lePreview->setText(i18n("The Quick Brown Fox Jumps Over The Lazy Dog"));
TQFontDatabase fdb;
TQStringList families = fdb.families();
for ( TQStringList::Iterator it = families.begin(); it != families.end(); ++it ) {
if( (*it).contains('[') !=0 )
it = families.remove(it);
}
if( families.count() != 0 ) lbAvailable->insertStringList(families);
TQIconSet iconSet = SmallIconSet(TQString::fromLatin1("forward"));
TQPixmap pixMap = iconSet.pixmap( TQIconSet::Small, TQIconSet::Normal );
pbAdd->setIconSet(iconSet);
pbAdd->setFixedSize( pixMap.width()+8, pixMap.height()+8 );
iconSet = SmallIconSet(TQString::fromLatin1("back"));
pbRemove->setIconSet(iconSet);
pbRemove->setFixedSize( pixMap.width()+8, pixMap.height()+8 );
iconSet = SmallIconSet(TQString::fromLatin1("up"));
pbMoveUp->setIconSet(iconSet);
pbMoveUp->setFixedSize( pixMap.width()+8, pixMap.height()+8 );
iconSet = SmallIconSet(TQString::fromLatin1("down"));
pbMoveDown->setIconSet(iconSet);
pbMoveDown->setFixedSize( pixMap.width()+8, pixMap.height()+8 );
connect(pbAdd, TQT_SIGNAL(clicked()), this ,TQT_SLOT( addFont() ));
connect( lbAvailable, TQT_SIGNAL( highlighted( const TQString& ) ), this, TQT_SLOT( updatePreview( const TQString&) ) );
connect( lbAvailable, TQT_SIGNAL( highlighted( const TQString& ) ), this, TQT_SLOT( setCurrentSelectedAvailableFamilyFont( const TQString&) ) );
connect( lbGeneric, TQT_SIGNAL( highlighted( const TQString& ) ), this, TQT_SLOT( updatePreview( const TQString&) ) );
connect( lbGeneric, TQT_SIGNAL( highlighted( const TQString& ) ), this, TQT_SLOT( setCurrentSelectedGenericFamilyFont( const TQString&) ) );
connect( lbSelected, TQT_SIGNAL( highlighted( const TQString& ) ), this, TQT_SLOT( updatePreview( const TQString&) ) );
connect( lbSelected, TQT_SIGNAL( highlighted( int ) ), this, TQT_SLOT( setCurrentSelectedFont( int ) ) );
connect( lbSelected, TQT_SIGNAL( highlighted( const TQString& ) ), this, TQT_SLOT( setCurrentSelectedFont( const TQString&) ) );
connect( pbRemove, TQT_SIGNAL( clicked() ), this, TQT_SLOT( removeFont() ) );
connect( pbMoveUp, TQT_SIGNAL( clicked() ), this, TQT_SLOT( moveFontUp() ) );
connect( pbMoveDown, TQT_SIGNAL( clicked() ), this, TQT_SLOT( moveFontDown() ) );
TQWhatsThis::add(lbAvailable,i18n("These are the names of the available fonts on your system"));
TQWhatsThis::add(lbGeneric,i18n("These are the names of the generic fonts "));
TQWhatsThis::add(lbSelected,i18n("These are the names of the generic fonts you have selected "));
TQWhatsThis::add(pbAdd,i18n("Click this to add a font to your style sheet"));
TQWhatsThis::add(pbRemove,i18n("Click this to remove a font from your style sheet"));
TQWhatsThis::add(pbMoveUp,i18n("Click this to make the font more preferable than the preceeding one"));
TQWhatsThis::add(pbMoveDown,i18n("Click this to make the font less preferable than the following one"));
}
fontFamilyChooser::~fontFamilyChooser(){}
void fontFamilyChooser::updatePreview(const TQString& s){
lePreview->setFont(TQFont(s,20));
}
void fontFamilyChooser::addFont(){
lbSelected->insertItem( m_currentSelectedFont );
switch(m_fontOrigin) {
case available: lbAvailable->removeItem(lbAvailable->index(lbAvailable->findItem(m_currentSelectedFont)));
break;
case generic : lbGeneric->removeItem(lbGeneric->index(lbGeneric->findItem(m_currentSelectedFont)));
break;
}
}
void fontFamilyChooser::setCurrentSelectedAvailableFamilyFont(const TQString& f){
m_fontOrigin = available;
m_currentSelectedFont = f;
m_selectedFontMap[f] = available;
}
void fontFamilyChooser::setCurrentSelectedGenericFamilyFont(const TQString& f){
m_fontOrigin = generic;
m_currentSelectedFont =f;
m_selectedFontMap[f] = generic;
}
void fontFamilyChooser::moveFontUp(){
if(m_currentSelectedFontIndex == 0) return;
int dummyIndex = m_currentSelectedFontIndex;
lbSelected->insertItem( lbSelected->text(m_currentSelectedFontIndex ), dummyIndex -1);
lbSelected->removeItem(dummyIndex + 1);
lbSelected->setSelected( dummyIndex -1, true);
}
void fontFamilyChooser::moveFontDown(){
if((unsigned int)m_currentSelectedFontIndex == lbSelected->count()) return;
int dummyIndex = m_currentSelectedFontIndex;
lbSelected->insertItem( lbSelected->text(m_currentSelectedFontIndex ), dummyIndex + 2);
lbSelected->removeItem(dummyIndex);
lbSelected->setSelected(dummyIndex +1, true);
}
void fontFamilyChooser::removeFont(){
TQString dummyFont(m_currentSelectedFont);// since removeItem emits highlighted signal, after
// removeItem call the value of m_currentSelectedFont
// is actually the font after m_currentSelectedFont and so
// we must save m_currentSelectedFont value in dummyFont
lbSelected->removeItem( m_currentSelectedFontIndex );
switch(m_selectedFontMap[dummyFont]) {
case available: lbAvailable->insertItem(dummyFont);
lbAvailable->sort();
break;
case generic : lbGeneric->insertItem(dummyFont);
lbGeneric->sort();
break;
}
}
TQStringList fontFamilyChooser::fontList(){
TQStringList list;
TQListBoxItem *item = lbSelected->firstItem();
while( item != 0 ){
if( item->text().contains( TQRegExp("\\W") ) ) list.append( "'" + item->text() + "'" );
else list.append( item->text() );
item = item->next();
}
return list;
}
void fontFamilyChooser::setInitialValue(const TQString& s){
TQStringList familyList = TQStringList::split(",",s);
for ( TQStringList::Iterator it = familyList.begin(); it != familyList.end(); ++it ) {
(*it).remove("'");
(*it).remove("\"");
lbSelected->insertItem((*it).stripWhiteSpace());
}
}
#include "fontfamilychooser.moc"
|