summaryrefslogtreecommitdiffstats
path: root/tdeprint/management/kmconfigfonts.cpp
blob: b933cab0042f51b09717fa8fab4f989886545556 (plain)
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
176
177
178
179
180
181
182
/*
 *  This file is part of the KDE libraries
 *  Copyright (c) 2001 Michael Goffioul <tdeprint@swing.be>
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Library General Public
 *  License version 2 as published by the Free Software Foundation.
 *
 *  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 "kmconfigfonts.h"

#include <tqgroupbox.h>
#include <kpushbutton.h>
#include <tqlayout.h>
#include <tqheader.h>
#include <tqlabel.h>
#include <tqcheckbox.h>
#include <tqsettings.h>
#include <tqwhatsthis.h>

#include <klocale.h>
#include <kconfig.h>
#include <kiconloader.h>
#include <kurlrequester.h>
#include <kfile.h>
#include <klistview.h>
#include <kdialog.h>

KMConfigFonts::KMConfigFonts(TQWidget *parent, const char *name)
: KMConfigPage(parent, name)
{
	setPageName(i18n("Fonts"));
	setPageHeader(i18n("Font Settings"));
	setPagePixmap("fonts");

	TQGroupBox	*box = new TQGroupBox(0, Qt::Vertical, i18n("Fonts Embedding"), this);
	TQGroupBox	*box2 = new TQGroupBox(0, Qt::Vertical, i18n("Fonts Path"), this);

	m_embedfonts = new TQCheckBox(i18n("&Embed fonts in PostScript data when printing"), box);
	m_fontpath = new KListView(box2);
	m_fontpath->addColumn("");
	m_fontpath->header()->setStretchEnabled(true, 0);
	m_fontpath->header()->hide();
	m_fontpath->setSorting(-1);
	m_addpath = new KURLRequester(box2);
	m_addpath->setMode(KFile::Directory|KFile::ExistingOnly|KFile::LocalOnly);
	m_up = new KPushButton(KGuiItem(i18n("&Up"), "up"), box2);
	m_down = new KPushButton(KGuiItem(i18n("&Down"), "down"), box2);
	m_add = new KPushButton(KGuiItem(i18n("&Add"), "add"), box2);
	m_remove = new KPushButton(KGuiItem(i18n("&Remove"), "editdelete"), box2);
	TQLabel	*lab0 = new TQLabel(i18n("Additional director&y:"), box2);
	lab0->setBuddy(m_addpath);

	TQVBoxLayout	*l0 = new TQVBoxLayout(TQT_TQLAYOUT(box->layout()), KDialog::spacingHint());
	l0->addWidget(m_embedfonts);
	TQVBoxLayout	*l1 = new TQVBoxLayout(TQT_TQLAYOUT(box2->layout()), KDialog::spacingHint());
	l1->addWidget(m_fontpath);
	TQHBoxLayout	*l2 = new TQHBoxLayout(0, 0, KDialog::spacingHint());
	l1->addLayout(l2);
	l2->addWidget(m_up);
	l2->addWidget(m_down);
	l2->addWidget(m_remove);
	l1->addSpacing(10);
	l1->addWidget(lab0);
	l1->addWidget(m_addpath);
	TQHBoxLayout	*l3 = new TQHBoxLayout(0, 0, KDialog::spacingHint());
	l1->addLayout(l3);
	l3->addStretch(1);
	l3->addWidget(m_add);
	TQVBoxLayout	*l4 = new TQVBoxLayout(this, 0, KDialog::spacingHint());
	l4->addWidget(box);
	l4->addWidget(box2);

	TQWhatsThis::add(m_embedfonts,
			i18n("These options will automatically put fonts in the PostScript file "
                             "which are not present on the printer. Font embedding usually produces better print results "
			     "(closer to what you see on the screen), but larger print data as well."));
	TQWhatsThis::add(m_fontpath, 
			i18n("When using font embedding you can select additional directories where "
			     "KDE should search for embeddable font files. By default, the X server "
			     "font path is used, so adding those directories is not needed. The default "
			     "search path should be sufficient in most cases."));

	connect(m_remove, TQT_SIGNAL(clicked()), TQT_SLOT(slotRemove()));
	connect(m_add, TQT_SIGNAL(clicked()), TQT_SLOT(slotAdd()));
	connect(m_up, TQT_SIGNAL(clicked()), TQT_SLOT(slotUp()));
	connect(m_down, TQT_SIGNAL(clicked()), TQT_SLOT(slotDown()));
	connect(m_fontpath, TQT_SIGNAL(selectionChanged()), TQT_SLOT(slotSelected()));
	connect(m_addpath, TQT_SIGNAL(textChanged(const TQString&)), TQT_SLOT(slotTextChanged(const TQString&)));
	m_add->setEnabled(false);
	m_remove->setEnabled(false);
	m_up->setEnabled(false);
	m_down->setEnabled(false);
}

void KMConfigFonts::loadConfig(TDEConfig *)
{
	TQSettings	settings;
	m_embedfonts->setChecked(settings.readBoolEntry("/qt/embedFonts", true));
	TQStringList	paths = settings.readListEntry("/qt/fontPath", ':');
	TQListViewItem	*item(0);
	for (TQStringList::ConstIterator it=paths.begin(); it!=paths.end(); ++it)
		item = new TQListViewItem(m_fontpath, item, *it);
}

void KMConfigFonts::saveConfig(TDEConfig *)
{
	TQSettings	settings;
	settings.writeEntry("/qt/embedFonts", m_embedfonts->isChecked());
	TQStringList	l;
	TQListViewItem	*item = m_fontpath->firstChild();
	while (item)
	{
		l << item->text(0);
		item = item->nextSibling();
	}
	settings.writeEntry("/qt/fontPath", l, ':');
}

void KMConfigFonts::slotSelected()
{
	TQListViewItem	*item = m_fontpath->selectedItem();
	m_remove->setEnabled(item);
	m_up->setEnabled(item && item->itemAbove());
	m_down->setEnabled(item && item->itemBelow());
}

void KMConfigFonts::slotAdd()
{
	if (m_addpath->url().isEmpty())
		return;
	TQListViewItem	*lastItem(m_fontpath->firstChild());
	while (lastItem && lastItem->nextSibling())
		lastItem = lastItem->nextSibling();
	TQListViewItem	*item = new TQListViewItem(m_fontpath, lastItem, m_addpath->url());
	m_fontpath->setSelected(item, true);
}

void KMConfigFonts::slotRemove()
{
	delete m_fontpath->selectedItem();
	if (m_fontpath->currentItem())
		m_fontpath->setSelected(m_fontpath->currentItem(), true);
	slotSelected();
}

void KMConfigFonts::slotUp()
{
	TQListViewItem	*citem = m_fontpath->selectedItem(), *nitem = 0;
	if (!citem || !citem->itemAbove())
		return;
	nitem = new TQListViewItem(m_fontpath, citem->itemAbove()->itemAbove(), citem->text(0));
	delete citem;
	m_fontpath->setSelected(nitem, true);
}

void KMConfigFonts::slotDown()
{
	TQListViewItem	*citem = m_fontpath->selectedItem(), *nitem = 0;
	if (!citem || !citem->itemBelow())
		return;
	nitem = new TQListViewItem(m_fontpath, citem->itemBelow(), citem->text(0));
	delete citem;
	m_fontpath->setSelected(nitem, true);
}

void KMConfigFonts::slotTextChanged(const TQString& t)
{
	m_add->setEnabled(!t.isEmpty());
}

#include "kmconfigfonts.moc"