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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
|
/*
*
* $Id: k3bcutcombobox.cpp 619556 2007-01-03 17:38:12Z trueg $
* Copyright (C) 2003 Sebastian Trueg <trueg@k3b.org>
*
* This file is part of the K3b project.
* Copyright (C) 1998-2007 Sebastian Trueg <trueg@k3b.org>
*
* 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.
* See the file "COPYING" for the exact licensing terms.
*/
#include "k3bcutcombobox.h"
#include <k3bstringutils.h>
#include <tqfontmetrics.h>
#include <tqevent.h>
#include <tqstringlist.h>
#include <tqrect.h>
#include <tqsize.h>
#include <tqpixmap.h>
#include <tqstyle.h>
#include <tqsizepolicy.h>
class K3bCutComboBox::Private
{
public:
Private() {
method = CUT;
}
TQStringList originalItems;
int method;
int width;
};
K3bCutComboBox::K3bCutComboBox( TQWidget* tqparent, const char* name )
: KComboBox( tqparent, name )
{
d = new Private();
// tqsetSizePolicy( TQSizePolicy::Maximum, sizePolicy().horData(), sizePolicy().hasHeightForWidth() );
}
K3bCutComboBox::K3bCutComboBox( int method, TQWidget* tqparent, const char* name )
: KComboBox( tqparent, name )
{
d = new Private();
d->method = method;
}
K3bCutComboBox::~K3bCutComboBox()
{
delete d;
}
void K3bCutComboBox::setMethod( int m )
{
d->method = m;
cutText();
}
TQSize K3bCutComboBox::tqsizeHint() const
{
// TQSize s(KComboBox::tqsizeHint());
// for( int i = 0; i < count(); i++ ) {
// int w = fontMetrics().width(d->originalItems[i]) +
// ( d->pixmaps[i].isNull() ? 0 : d->pixmaps[i].width() + 4);
// if( w > s.width() )
// s.setWidth( w );
// }
return KComboBox::tqsizeHint();
}
TQSize K3bCutComboBox::tqminimumSizeHint() const
{
return KComboBox::tqminimumSizeHint();
}
void K3bCutComboBox::setCurrentText( const TQString& s )
{
int i;
for( i = 0; i < count(); i++ )
if ( d->originalItems[i] == s )
break;
if ( i < count() ) {
setCurrentItem(i);
}
else if( !d->originalItems.isEmpty() ) {
d->originalItems[currentItem()] = s;
cutText();
}
}
void K3bCutComboBox::insertStringList( const TQStringList&, int )
{
// FIXME
}
void K3bCutComboBox::insertStrList( const TQStrList&, int )
{
// FIXME
}
void K3bCutComboBox::insertStrList( const TQStrList*, int )
{
// FIXME
}
void K3bCutComboBox::insertStrList( const char**, int, int)
{
// FIXME
}
void K3bCutComboBox::insertItem( const TQString& text, int index )
{
insertItem( TQPixmap(), text, index );
}
void K3bCutComboBox::insertItem( const TQPixmap& pix, int i )
{
insertItem( pix, "", i );
}
void K3bCutComboBox::insertItem( const TQPixmap& pixmap, const TQString& text, int index )
{
if( index != -1 )
d->originalItems.insert( d->originalItems.at(index), text );
else
d->originalItems.append( text );
if( !pixmap.isNull() )
KComboBox::insertItem( pixmap, "xx", index );
else
KComboBox::insertItem( "xx", index );
cutText();
}
void K3bCutComboBox::removeItem( int i )
{
d->originalItems.erase( d->originalItems.at(i) );
KComboBox::removeItem( i );
}
void K3bCutComboBox::changeItem( const TQString& s, int i )
{
d->originalItems[i] = s;
cutText();
}
void K3bCutComboBox::changeItem( const TQPixmap& pix, const TQString& s, int i )
{
KComboBox::changeItem( pix, i );
changeItem( s, i );
}
TQString K3bCutComboBox::text( int i ) const
{
if( i < (int)d->originalItems.count() )
return d->originalItems[i];
else
return TQString();
}
TQString K3bCutComboBox::currentText() const
{
if( currentItem() < (int)d->originalItems.count() )
return d->originalItems[currentItem()];
else
return TQString();
}
void K3bCutComboBox::clear()
{
KComboBox::clear();
d->originalItems.clear();
}
void K3bCutComboBox::resizeEvent( TQResizeEvent* e )
{
cutText();
KComboBox::resizeEvent(e);
}
void K3bCutComboBox::cutText()
{
d->width = TQStyle::tqvisualRect( tqstyle().querySubControlMetrics(TQStyle::CC_ComboBox, this,
TQStyle::SC_ComboBoxEditField), this ).width();
for( int i = 0; i < (int)d->originalItems.count(); ++i ) {
int w = d->width;
if ( pixmap(i) && !pixmap(i)->isNull() )
w -= ( pixmap(i)->width() + 4 );
TQString text;
if( d->method == STQUEEZE )
text = K3b::squeezeTextToWidth( fontMetrics(), d->originalItems[i], w );
else
text = K3b::cutToWidth( fontMetrics(), d->originalItems[i], w );
// now insert the cut text
if( pixmap(i) )
KComboBox::changeItem( *pixmap(i), text, i );
else
KComboBox::changeItem( text, i );
}
}
#include "k3bcutcombobox.moc"
|