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
|
/* This file is part of the KDE project
Copyright (C) 2004 Cedric Pasteur <[email protected]>
Copyright (C) 2004 Alexander Dymo <[email protected]>
Copyright (C) 2005 Jaroslaw Staniek <[email protected]>
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 "fontedit.h"
#include "editoritem.h"
#include <tqpushbutton.h>
#include <tqpainter.h>
#include <tqlayout.h>
#include <tqvariant.h>
#include <tqfont.h>
#include <tqfontmetrics.h>
#include <tqlabel.h>
#include <tqtooltip.h>
#include <kdeversion.h>
#include <kfontrequester.h>
#include <kaccelmanager.h>
#include <klocale.h>
//! @internal
//! reimplemented to better button and label's positioning
namespace KoProperty {
class FontEditRequester : public KFontRequester
{
public:
FontEditRequester(TQWidget* parent)
: KFontRequester(parent)
{
label()->setPaletteBackgroundColor(tqpalette().active().base());
label()->setMinimumWidth(0);
label()->setFrameShape(TQFrame::Box);
label()->setIndent(-1);
#if TDE_VERSION >= KDE_MAKE_VERSION(3,4,0)
label()->setFocusPolicy(TQ_ClickFocus);
KAcceleratorManager::setNoAccel(label());
#endif
tqlayout()->remove(label());
tqlayout()->remove(button());//->reparent(this, 0, TQPoint(0,0));
delete tqlayout();
button()->setText(i18n("..."));
TQToolTip::add(button(), i18n("Change font"));
button()->setFocusPolicy(TQ_NoFocus);
button()->tqsetSizePolicy(TQSizePolicy::Fixed, TQSizePolicy::Fixed);
TQFontMetrics fm(button()->font());
button()->setFixedWidth(fm.width(button()->text()+' '));
}
virtual void resizeEvent(TQResizeEvent *e)
{
KFontRequester::resizeEvent(e);
label()->move(0,0);
label()->resize(e->size()-TQSize(button()->width(),-1));
button()->move(label()->width(),0);
button()->setFixedSize(button()->width(), height());
}
};
}
using namespace KoProperty;
FontEdit::FontEdit(Property *property, TQWidget *parent, const char *name)
: Widget(property, parent, name)
{
m_edit = new FontEditRequester(this);
m_edit->setMinimumHeight(5);
setEditor(m_edit);
setFocusWidget(m_edit->label());
connect(m_edit, TQT_SIGNAL(fontSelected(const TQFont& )), this, TQT_SLOT(slotValueChanged(const TQFont&)));
}
FontEdit::~FontEdit()
{}
TQVariant
FontEdit::value() const
{
return m_edit->font();
}
static TQString sampleText(const TQVariant &value)
{
TQFontInfo fi(value.toFont());
return fi.family() + (fi.bold() ? " " + i18n("Bold") : TQString()) +
(fi.italic() ? " " + i18n("Italic") : TQString()) +
" " + TQString::number(fi.pointSize());
}
void
FontEdit::setValue(const TQVariant &value, bool emitChange)
{
m_edit->blockSignals(true);
m_edit->setFont(value.toFont());
m_edit->blockSignals(false);
m_edit->setSampleText(sampleText(value));
if (emitChange)
emit valueChanged(this);
}
void
FontEdit::drawViewer(TQPainter *p, const TQColorGroup &, const TQRect &r, const TQVariant &value)
{
p->eraseRect(r);
p->setFont(value.toFont());
TQRect r2(r);
r2.setLeft(r2.left()+KPROPEDITOR_ITEM_MARGIN);
r2.setBottom(r2.bottom()+1);
p->drawText(r2, TQt::AlignLeft | TQt::AlignVCenter | TQt::SingleLine, sampleText(value));
}
void
FontEdit::slotValueChanged(const TQFont &)
{
emit valueChanged(this);
}
bool
FontEdit::eventFilter(TQObject* watched, TQEvent* e)
{
if(e->type() == TQEvent::KeyPress) {
TQKeyEvent* ev = TQT_TQKEYEVENT(e);
if(ev->key() == Key_Space) {
m_edit->button()->animateClick();
return true;
}
}
return Widget::eventFilter(watched, e);
}
void
FontEdit::setReadOnlyInternal(bool readOnly)
{
setVisibleFlag(!readOnly);
}
#include "fontedit.moc"
|