Add general Xtraz notification support.
[kdenetwork.git] / kdict / actions.cpp
blob37ba52910be37de6b3a80031e00e0dc91d3b849a
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
14 DictButtonAction
16 ------------------------------------------------------------- */
18 #include "actions.h"
20 #include <qlabel.h>
21 #include <qpushbutton.h>
23 #include <kcombobox.h>
24 #include <ktoolbar.h>
27 DictComboAction::DictComboAction( const QString &text, QObject *parent, const char *name,
28 bool editable, bool autoSized )
29 : KAction( text, 0, parent, name ),
30 m_editable(editable),
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);
55 if ( m_combo ) {
56 connect(bar->getCombo(id_), SIGNAL(activated(const QString&)), SLOT(slotComboActivated(const QString&)));
57 connect(bar->getCombo(id_), SIGNAL(activated(int)), SLOT(slotComboActivated(int)));
59 if (m_editable)
60 m_combo->setInsertionPolicy( QComboBox::NoInsertion );
63 addContainer( bar, id_ );
64 connect( bar, SIGNAL( destroyed() ), this, SLOT( slotDestroyed() ) );
65 return containerCount() - 1;
68 return -1;
72 void DictComboAction::unplug( QWidget *widget )
74 if ( widget->inherits( "KToolBar" ) )
76 KToolBar *bar = (KToolBar *)widget;
78 int idx = findContainer( bar );
80 if ( idx != -1 )
82 bar->removeItem( itemId( idx ) );
83 removeContainer( idx );
86 return;
91 QWidget* DictComboAction::widget()
93 return m_combo;
97 void DictComboAction::setFocus()
99 if (m_combo)
100 m_combo->setFocus();
104 QString DictComboAction::currentText() const
106 if (m_combo)
107 return m_combo->currentText();
108 else
109 return QString();
112 void DictComboAction::selectAll()
114 if (m_combo)
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)
131 if (m_combo)
132 m_combo->setCurrentItem(index);
136 void DictComboAction::clearEdit()
138 if (m_combo && m_editable)
139 m_combo->clearEdit();
143 void DictComboAction::clear()
145 if (m_combo) {
146 m_combo->clear();
147 if (m_editable && m_combo->completionObject())
148 m_combo->completionObject()->clear();
153 void DictComboAction::setList(QStringList items)
155 if (m_combo) {
156 m_combo->clear();
157 m_combo->insertStringList(items);
158 if (m_editable && m_combo->completionObject())
159 m_combo->completionObject()->setItems(items);
160 if (!m_autoSized)
161 m_combo->setFixedWidth(m_combo->sizeHint().width());
166 KGlobalSettings::Completion DictComboAction::completionMode()
168 if (m_combo)
169 return m_combo->completionMode();
170 else
171 return m_compMode;
175 void DictComboAction::setCompletionMode(KGlobalSettings::Completion mode)
177 if (m_combo)
178 m_combo->setCompletionMode(mode);
179 else
180 m_compMode = mode;
184 void DictComboAction::slotComboActivated(int i)
186 emit(activated(i));
190 void DictComboAction::slotComboActivated(const QString &s)
192 emit(activated(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);
222 label->adjustSize();
224 tb->insertWidget( id, label->width(), label, index );
226 addContainer( tb, id );
228 connect( tb, SIGNAL( destroyed() ), this, SLOT( slotDestroyed() ) );
230 m_label = label;
232 return containerCount() - 1;
235 return -1;
239 void DictLabelAction::unplug( QWidget *widget )
241 if ( widget->inherits( "KToolBar" ) )
243 KToolBar *bar = (KToolBar *)widget;
245 int idx = findContainer( bar );
247 if ( idx != -1 )
249 bar->removeItem( itemId( idx ) );
250 removeContainer( idx );
253 return;
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() ) );
297 m_button = button;
299 return containerCount() - 1;
302 return -1;
306 void DictButtonAction::unplug( QWidget *widget )
308 if ( widget->inherits( "KToolBar" ) )
310 KToolBar *bar = (KToolBar *)widget;
312 int idx = findContainer( bar );
314 if ( idx != -1 )
316 bar->removeItem( itemId( idx ) );
317 removeContainer( idx );
323 int DictButtonAction::widthHint()
325 if (m_button)
326 return m_button->sizeHint().width();
327 else
328 return 0;
332 void DictButtonAction::setWidth(int width)
334 if (m_button)
335 m_button->setFixedWidth(width);
338 #include "actions.moc"