1 /* -------------------------------------------------------------
3 actions.cpp (part of The KDE Dictionary Client)
5 Copyright (C) 2000-2001 Christian Gebauer <gebauer@kde.org>
7 This file is distributed under the Artistic License.
8 See LICENSE for details.
10 -------------------------------------------------------------
12 DictComboAction, special KAction subclasses used
13 DictLabelAction, in the toolbar
16 ------------------------------------------------------------- */
21 #include <qpushbutton.h>
23 #include <kcombobox.h>
27 DictComboAction::DictComboAction( const QString
&text
, QObject
*parent
, const char *name
,
28 bool editable
, bool autoSized
)
29 : KAction( text
, 0, parent
, name
),
31 m_autoSized(autoSized
),
32 m_compMode(KGlobalSettings::completionMode())
37 DictComboAction::~DictComboAction()
42 int DictComboAction::plug( QWidget
*widget
, int index
)
44 if ( widget
->inherits( "KToolBar" ) )
46 KToolBar
* bar
= static_cast<KToolBar
*>( widget
);
47 int id_
= KAction::getToolButtonID();
49 m_combo
= new KComboBox(m_editable
,bar
);
50 m_combo
->setCompletionMode(m_compMode
);
52 bar
->insertWidget( id_
, m_combo
->sizeHint().width(), m_combo
, index
);
53 bar
->setItemAutoSized(id_
,m_autoSized
);
56 connect(bar
->getCombo(id_
), SIGNAL(activated(const QString
&)), SLOT(slotComboActivated(const QString
&)));
57 connect(bar
->getCombo(id_
), SIGNAL(activated(int)), SLOT(slotComboActivated(int)));
60 m_combo
->setInsertionPolicy( QComboBox::NoInsertion
);
63 addContainer( bar
, id_
);
64 connect( bar
, SIGNAL( destroyed() ), this, SLOT( slotDestroyed() ) );
65 return containerCount() - 1;
72 void DictComboAction::unplug( QWidget
*widget
)
74 if ( widget
->inherits( "KToolBar" ) )
76 KToolBar
*bar
= (KToolBar
*)widget
;
78 int idx
= findContainer( bar
);
82 bar
->removeItem( itemId( idx
) );
83 removeContainer( idx
);
91 QWidget
* DictComboAction::widget()
97 void DictComboAction::setFocus()
104 QString
DictComboAction::currentText() const
107 return m_combo
->currentText();
112 void DictComboAction::selectAll()
116 m_combo
->lineEdit()->selectAll();
117 m_combo
->lineEdit()->setFocus();
122 void DictComboAction::setEditText(const QString
&s
)
124 if (m_combo
&& m_editable
)
125 m_combo
->setEditText(s
);
129 void DictComboAction::setCurrentItem(int index
)
132 m_combo
->setCurrentItem(index
);
136 void DictComboAction::clearEdit()
138 if (m_combo
&& m_editable
)
139 m_combo
->clearEdit();
143 void DictComboAction::clear()
147 if (m_editable
&& m_combo
->completionObject())
148 m_combo
->completionObject()->clear();
153 void DictComboAction::setList(QStringList items
)
157 m_combo
->insertStringList(items
);
158 if (m_editable
&& m_combo
->completionObject())
159 m_combo
->completionObject()->setItems(items
);
161 m_combo
->setFixedWidth(m_combo
->sizeHint().width());
166 KGlobalSettings::Completion
DictComboAction::completionMode()
169 return m_combo
->completionMode();
175 void DictComboAction::setCompletionMode(KGlobalSettings::Completion mode
)
178 m_combo
->setCompletionMode(mode
);
184 void DictComboAction::slotComboActivated(int i
)
190 void DictComboAction::slotComboActivated(const QString
&s
)
196 //*********************************************************************************
199 DictLabelAction::DictLabelAction( const QString
&text
, QObject
*parent
, const char *name
)
200 : KAction( text
, 0, parent
, name
)
205 DictLabelAction::~DictLabelAction()
210 int DictLabelAction::plug( QWidget
*widget
, int index
)
212 if ( widget
->inherits( "KToolBar" ) )
214 KToolBar
*tb
= (KToolBar
*)widget
;
216 int id
= KAction::getToolButtonID();
218 QLabel
*label
= new QLabel( text(), widget
, "kde toolbar widget" );
219 label
->setMinimumWidth(label
->sizeHint().width());
220 label
->setBackgroundMode( Qt::PaletteButton
);
221 label
->setAlignment(Qt::AlignCenter
| Qt::AlignVCenter
);
224 tb
->insertWidget( id
, label
->width(), label
, index
);
226 addContainer( tb
, id
);
228 connect( tb
, SIGNAL( destroyed() ), this, SLOT( slotDestroyed() ) );
232 return containerCount() - 1;
239 void DictLabelAction::unplug( QWidget
*widget
)
241 if ( widget
->inherits( "KToolBar" ) )
243 KToolBar
*bar
= (KToolBar
*)widget
;
245 int idx
= findContainer( bar
);
249 bar
->removeItem( itemId( idx
) );
250 removeContainer( idx
);
258 void DictLabelAction::setBuddy(QWidget
*buddy
)
260 if (m_label
&& buddy
)
261 m_label
->setBuddy(buddy
);
265 //*********************************************************************************
268 DictButtonAction::DictButtonAction( const QString
& text
, QObject
* receiver
,
269 const char* slot
, QObject
* parent
, const char* name
)
270 : KAction( text
, 0, receiver
, slot
, parent
, name
)
275 DictButtonAction::~DictButtonAction()
280 int DictButtonAction::plug( QWidget
*widget
, int index
)
282 if ( widget
->inherits( "KToolBar" ) )
284 KToolBar
*tb
= (KToolBar
*)widget
;
286 int id
= KAction::getToolButtonID();
288 QPushButton
*button
= new QPushButton( text(), widget
);
289 button
->adjustSize();
290 connect(button
,SIGNAL(clicked()),this,SLOT(activate()));
291 tb
->insertWidget( id
, button
->width(), button
, index
);
293 addContainer( tb
, id
);
295 connect( tb
, SIGNAL( destroyed() ), this, SLOT( slotDestroyed() ) );
299 return containerCount() - 1;
306 void DictButtonAction::unplug( QWidget
*widget
)
308 if ( widget
->inherits( "KToolBar" ) )
310 KToolBar
*bar
= (KToolBar
*)widget
;
312 int idx
= findContainer( bar
);
316 bar
->removeItem( itemId( idx
) );
317 removeContainer( idx
);
323 int DictButtonAction::widthHint()
326 return m_button
->sizeHint().width();
332 void DictButtonAction::setWidth(int width
)
335 m_button
->setFixedWidth(width
);
338 #include "actions.moc"