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
), m_editable(editable
), m_autoSized(autoSized
), m_compMode(KGlobalSettings::completionMode())
34 DictComboAction::~DictComboAction()
39 int DictComboAction::plug( QWidget
*widget
, int index
)
41 if ( widget
->inherits( "KToolBar" ) )
43 KToolBar
* bar
= static_cast<KToolBar
*>( widget
);
44 int id_
= KAction::getToolButtonID();
46 m_combo
= new KComboBox(m_editable
,bar
);
47 m_combo
->setCompletionMode(m_compMode
);
49 bar
->insertWidget( id_
, m_combo
->sizeHint().width(), m_combo
, index
);
50 bar
->setItemAutoSized(id_
,m_autoSized
);
53 connect(bar
->getCombo(id_
), SIGNAL(activated(const QString
&)), SLOT(slotComboActivated(const QString
&)));
54 connect(bar
->getCombo(id_
), SIGNAL(activated(int)), SLOT(slotComboActivated(int)));
57 m_combo
->setInsertionPolicy( QComboBox::NoInsertion
);
60 addContainer( bar
, id_
);
61 connect( bar
, SIGNAL( destroyed() ), this, SLOT( slotDestroyed() ) );
62 return containerCount() - 1;
69 void DictComboAction::unplug( QWidget
*widget
)
71 if ( widget
->inherits( "KToolBar" ) )
73 KToolBar
*bar
= (KToolBar
*)widget
;
75 int idx
= findContainer( bar
);
79 bar
->removeItem( itemId( idx
) );
80 removeContainer( idx
);
88 QWidget
* DictComboAction::widget()
94 void DictComboAction::setFocus()
101 QString
DictComboAction::currentText() const
104 return m_combo
->currentText();
106 return QString::null
;
109 void DictComboAction::selectAll()
113 m_combo
->lineEdit()->selectAll();
114 m_combo
->lineEdit()->setFocus();
119 void DictComboAction::setEditText(const QString
&s
)
121 if (m_combo
&& m_editable
)
122 m_combo
->setEditText(s
);
126 void DictComboAction::setCurrentItem(int index
)
129 m_combo
->setCurrentItem(index
);
133 void DictComboAction::clearEdit()
135 if (m_combo
&& m_editable
)
136 m_combo
->clearEdit();
140 void DictComboAction::clear()
144 if (m_editable
&& m_combo
->completionObject())
145 m_combo
->completionObject()->clear();
150 void DictComboAction::setList(QStringList items
)
154 m_combo
->insertStringList(items
);
155 if (m_editable
&& m_combo
->completionObject())
156 m_combo
->completionObject()->setItems(items
);
158 m_combo
->setFixedWidth(m_combo
->sizeHint().width());
163 KGlobalSettings::Completion
DictComboAction::completionMode()
166 return m_combo
->completionMode();
172 void DictComboAction::setCompletionMode(KGlobalSettings::Completion mode
)
175 m_combo
->setCompletionMode(mode
);
181 void DictComboAction::slotComboActivated(int i
)
187 void DictComboAction::slotComboActivated(const QString
&s
)
193 //*********************************************************************************
196 DictLabelAction::DictLabelAction( const QString
&text
, QObject
*parent
, const char *name
)
197 : KAction( text
, 0, parent
, name
)
202 DictLabelAction::~DictLabelAction()
207 int DictLabelAction::plug( QWidget
*widget
, int index
)
209 if ( widget
->inherits( "KToolBar" ) )
211 KToolBar
*tb
= (KToolBar
*)widget
;
213 int id
= KAction::getToolButtonID();
215 QLabel
*label
= new QLabel( text(), widget
, "kde toolbar widget" );
216 label
->setMinimumWidth(label
->sizeHint().width());
217 label
->setBackgroundMode( Qt::PaletteButton
);
218 label
->setAlignment(AlignCenter
| AlignVCenter
);
221 tb
->insertWidget( id
, label
->width(), label
, index
);
223 addContainer( tb
, id
);
225 connect( tb
, SIGNAL( destroyed() ), this, SLOT( slotDestroyed() ) );
229 return containerCount() - 1;
236 void DictLabelAction::unplug( QWidget
*widget
)
238 if ( widget
->inherits( "KToolBar" ) )
240 KToolBar
*bar
= (KToolBar
*)widget
;
242 int idx
= findContainer( bar
);
246 bar
->removeItem( itemId( idx
) );
247 removeContainer( idx
);
255 void DictLabelAction::setBuddy(QWidget
*buddy
)
257 if (m_label
&& buddy
)
258 m_label
->setBuddy(buddy
);
262 //*********************************************************************************
265 DictButtonAction::DictButtonAction( const QString
& text
, QObject
* receiver
,
266 const char* slot
, QObject
* parent
, const char* name
)
267 : KAction( text
, 0, receiver
, slot
, parent
, name
)
272 DictButtonAction::~DictButtonAction()
277 int DictButtonAction::plug( QWidget
*widget
, int index
)
279 if ( widget
->inherits( "KToolBar" ) )
281 KToolBar
*tb
= (KToolBar
*)widget
;
283 int id
= KAction::getToolButtonID();
285 QPushButton
*button
= new QPushButton( text(), widget
);
286 button
->adjustSize();
287 connect(button
,SIGNAL(clicked()),this,SLOT(activate()));
288 tb
->insertWidget( id
, button
->width(), button
, index
);
290 addContainer( tb
, id
);
292 connect( tb
, SIGNAL( destroyed() ), this, SLOT( slotDestroyed() ) );
296 return containerCount() - 1;
303 void DictButtonAction::unplug( QWidget
*widget
)
305 if ( widget
->inherits( "KToolBar" ) )
307 KToolBar
*bar
= (KToolBar
*)widget
;
309 int idx
= findContainer( bar
);
313 bar
->removeItem( itemId( idx
) );
314 removeContainer( idx
);
320 int DictButtonAction::widthHint()
323 return m_button
->sizeHint().width();
329 void DictButtonAction::setWidth(int width
)
332 m_button
->setFixedWidth(width
);
335 #include "actions.moc"