24 #define INCLUDE_MENUITEM_DEF
25 #include <tqpopupmenu.h>
27 #include <tqpushbutton.h>
29 #include "klanguagebutton.h"
30 #include "klanguagebutton.moc"
34 static void checkInsertPos( TQPopupMenu *popup,
const TQString & str,
41 int b = popup->count();
44 int w = ( a + b ) / 2;
46 int id = popup->idAt( w );
47 int j = str.localeAwareCompare( popup->text(
id ) );
60 static TQPopupMenu * checkInsertIndex( TQPopupMenu *popup,
61 const TQStringList *tags,
const TQString &submenu )
63 int pos = tags->findIndex( submenu );
68 TQMenuItem *p = popup->findItem( pos );
69 pi = p ? p->popup() : 0;
77 class KLanguageButtonPrivate
80 TQPushButton * button;
85 : TQWidget( parent, name )
91 : TQWidget( parent, name )
100 d->staticText =
true;
101 d->button->setText(text);
102 d->button->setIconSet(TQIconSet());
105 void KLanguageButton::init(
const char * name)
108 m_ids =
new TQStringList;
111 d =
new KLanguageButtonPrivate;
113 d->staticText =
false;
115 TQHBoxLayout *layout =
new TQHBoxLayout(
this, 0, 0);
116 layout->setAutoAdd(
true);
117 d->button =
new TQPushButton(
this, name );
131 void KLanguageButton::insertLanguage(
const TQString& path,
const TQString& name,
132 const TQString&,
const TQString &submenu,
int index )
134 TQString output = name + TQString::fromLatin1(
" (" ) + path +
135 TQString::fromLatin1(
")" );
138 TQPixmap flag(
locate(
"locale", sub + path +
139 TQString::fromLatin1(
"/flag.png" ) ) );
145 const TQString &
id,
const TQString &submenu,
int index )
147 TQPopupMenu *pi = checkInsertIndex( m_popup, m_ids, submenu );
148 checkInsertPos( pi, text, index );
149 pi->insertItem( icon, text, count(), index );
154 const TQString &submenu,
int index )
156 insertItem( TQIconSet(), text,
id, submenu, index );
161 TQPopupMenu *pi = checkInsertIndex( m_popup, m_ids, submenu );
162 pi->insertSeparator( index );
163 m_ids->append( TQString::null );
167 const TQString &text,
const TQString &
id,
168 const TQString &submenu,
int index )
170 TQPopupMenu *pi = checkInsertIndex( m_popup, m_ids, submenu );
171 TQPopupMenu *p =
new TQPopupMenu( pi );
172 checkInsertPos( pi, text, index );
173 pi->insertItem( icon, text, p, count(), index );
175 connect( p, TQ_SIGNAL(
activated(
int ) ),
176 TQ_SLOT( slotActivated(
int ) ) );
177 connect( p, TQ_SIGNAL( highlighted(
int ) ),
this,
178 TQ_SLOT( slotHighlighted(
int ) ) );
182 const TQString &submenu,
int index )
187 void KLanguageButton::slotActivated(
int index )
194 TQString
id = *m_ids->at( index );
198 void KLanguageButton::slotHighlighted(
int index )
202 TQString
id = *m_ids->at( index );
203 emit ( highlighted(
id) );
206 int KLanguageButton::count()
const
208 return m_ids->count();
216 m_oldPopup = m_popup;
217 m_popup =
new TQPopupMenu(
this );
219 d->button->setPopup( m_popup );
221 connect( m_popup, TQ_SIGNAL(
activated(
int ) ),
222 TQ_SLOT( slotActivated(
int ) ) );
223 connect( m_popup, TQ_SIGNAL( highlighted(
int ) ),
224 TQ_SLOT( slotHighlighted(
int ) ) );
226 if ( !d->staticText )
228 d->button->setText( TQString::null );
229 d->button->setIconSet( TQIconSet() );
235 return m_ids->contains(
id ) > 0;
240 return *m_ids->at( currentItem() );
244 TQString KLanguageButton::id(
int i )
const
246 if ( i < 0 || i >= count() )
248 kdDebug() <<
"KLanguageButton::tag(), unknown tag " << i <<
endl;
249 return TQString::null;
251 return *m_ids->at( i );
255 int KLanguageButton::currentItem()
const
262 if ( i < 0 || i >= count() )
266 if ( !d->staticText )
268 d->button->setText( m_popup->text( m_current ) );
269 TQIconSet *icon = m_popup->iconSet( m_current );
271 d->button->setIconSet( *icon );
273 d->button->setIconSet( TQIconSet() );
279 int i = m_ids->findIndex(
id );
kndbgstream & endl(kndbgstream &s)
kdbgstream kdDebug(int area=0)
TQString locate(const char *type, const TQString &filename, const TDEInstance *instance=TDEGlobal::instance())