1 /***************************************************************************
2 ksayitsystemtray.cpp - description
5 copyright : (C) 2003 by Robert Vogl
6 email : voglrobe@saphir
7 ***************************************************************************/
9 /***************************************************************************
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
16 ***************************************************************************/
20 #include <qtranslator.h>
22 #include <QMouseEvent>
28 // App specific includes
29 #include "ksayitsystemtray.h"
31 KSayItSystemTray::KSayItSystemTray(QWidget
*parent
, const char *name
)
32 : KSystemTray(parent
,name
)
35 changeState( StateCLIPEMPTY::Instance() );
38 KSayItSystemTray::~KSayItSystemTray()
40 delete StateWAIT::Instance();
41 delete StateSAY::Instance();
42 delete StateCLIPEMPTY::Instance();
45 void KSayItSystemTray::initActions()
48 menu
= this->contextMenu();
49 help
= new KHelpMenu(this, kapp
->aboutData(), false, actionCollection());
51 settings
= KStdAction::preferences(this, SLOT(slotPreferences()), actionCollection());
52 help_about
= KStdAction::aboutApp(help
, SLOT(aboutApplication()), actionCollection());
53 help_kde
= KStdAction::aboutKDE(help
, SLOT(aboutKDE()), actionCollection());
55 // User defined actions
56 say
= new KAction(i18n("Say"),
59 this, SLOT (slotSayActivated()),
63 shutup
= new KAction(i18n("Shut Up"),
66 this, SLOT (slotStopActivated()),
70 pause
= new KAction (i18n("Pause"),
73 this, SLOT (slotPauseActivated()),
77 next_sentence
= new KAction (i18n("Next Sentence"),
80 this, SLOT (slotNextSentenceActivated()),
85 prev_sentence
= new KAction (i18n("Previous Sentence"),
88 this, SLOT(slotPrevSentenceActivated()),
92 // Actions -> Context-menu
93 settings
->plug(menu
); menu
->insertSeparator();
97 next_sentence
->plug(menu
);
98 prev_sentence
->plug(menu
); menu
->insertSeparator();
99 help_about
->plug(menu
);
100 help_kde
->plug(menu
);
102 // default enables/disables
103 say
->setEnabled(false);
104 shutup
->setEnabled(false);
105 pause
->setEnabled(false);
106 next_sentence
->setEnabled(false);
107 prev_sentence
->setEnabled(false);
111 void KSayItSystemTray::slotPreferences()
114 emit
signalCallPreferences();
117 void KSayItSystemTray::mousePressEvent(QMouseEvent
*me
)
119 _state
->mousePressEvent(this, me
);
122 void KSayItSystemTray::mouseReleaseEvent(QMouseEvent
*me
)
124 _state
->mouseReleaseEvent(this, me
);
127 void KSayItSystemTray::slotSayActivated()
129 // start to say content of clipboard
130 emit
signalSayActivated();
133 void KSayItSystemTray::slotStopActivated()
136 emit
signalShutUpActivated();
139 void KSayItSystemTray::slotPauseActivated()
142 emit
signalPauseActivated();
145 void KSayItSystemTray::slotNextSentenceActivated()
148 emit
signalNextActivated();
151 void KSayItSystemTray::slotPrevSentenceActivated()
154 emit
signalPrevActivated();
158 void KSayItSystemTray::changeState(State
*state
)
161 _state
->setContext(this);
164 void KSayItSystemTray::setActions(bool sayEnabled
, bool pauseEnabled
, bool shutupEnabled
,
165 bool nextEnabled
, bool prevEnabled
)
167 say
->setEnabled(sayEnabled
);
168 pause
->setEnabled(pauseEnabled
);
169 shutup
->setEnabled(shutupEnabled
);
170 next_sentence
->setEnabled(nextEnabled
);
171 prev_sentence
->setEnabled(prevEnabled
);
175 void KSayItSystemTray::normalMousePressEvent(QMouseEvent
*e
)
177 KSystemTray::mousePressEvent(e
);
180 void KSayItSystemTray::normalMouseReleaseEvent(QMouseEvent
*e
)
182 KSystemTray::mouseReleaseEvent(e
);
185 void KSayItSystemTray::sayClipboard()
187 emit
signalSayClipboard();
193 ////////////////////////////////////////////
199 void State::mousePressEvent(KSayItSystemTray
*caller
, QMouseEvent
*e
)
201 // reimplemented by subclasses
204 void State::mouseReleaseEvent(KSayItSystemTray
*caller
, QMouseEvent
*e
)
206 // reimplemented by subclasses
209 void State::setContext(KSayItSystemTray
*caller
)
211 // reimplemented by subclasses
214 void State::changeState(KSayItSystemTray
*caller
, State
*state
)
216 caller
->changeState(state
);
219 void State::say(KSayItSystemTray
*caller
)
221 caller
->sayClipboard();
224 void State::mousePressEventCall(KSayItSystemTray
*caller
, QMouseEvent
*e
)
226 caller
->normalMousePressEvent(e
);
229 void State::mouseReleaseEventCall(KSayItSystemTray
*caller
, QMouseEvent
*e
)
231 caller
->normalMouseReleaseEvent(e
);
235 ////////////////////////////////////////////
236 StateWAIT::StateWAIT(){
237 m_traypixmap
= KGlobal::iconLoader()->loadIcon("ksayit", KIcon::Toolbar
);
239 StateWAIT::~StateWAIT(){
241 StateWAIT
* StateWAIT::_instance
= 0;
243 StateWAIT
* StateWAIT::Instance()
246 _instance
= new StateWAIT();
251 void StateWAIT::setContext(KSayItSystemTray
*caller
)
253 caller
->setPixmap( m_traypixmap
);
256 void StateWAIT::mousePressEvent(KSayItSystemTray
*caller
, QMouseEvent
*e
)
258 if (e
->button()==Qt::LeftButton
){ // left Mouse-button pressed
259 QWidget::mousePressEvent(e
); // do nothing (see mouseReleaseEvent)
261 mousePressEventCall(caller
, e
); // normal mouse-handling
265 void StateWAIT::mouseReleaseEvent(KSayItSystemTray
*caller
, QMouseEvent
*e
)
267 if (e
->button()==Qt::LeftButton
){ // left Mouse-button released
270 mouseReleaseEventCall(caller
, e
); // normal mouse-handling
276 ////////////////////////////////////////////
277 StateSAY::StateSAY(){
278 m_traypixmap
= KGlobal::iconLoader()->loadIcon("ksayit_talking", KIcon::Toolbar
);
280 StateSAY::~StateSAY(){
282 StateSAY
* StateSAY::_instance
= 0;
284 StateSAY
* StateSAY::Instance()
287 _instance
= new StateSAY();
292 void StateSAY::setContext(KSayItSystemTray
*caller
)
294 caller
->setPixmap( m_traypixmap
);
297 void StateSAY::mousePressEvent(KSayItSystemTray
*caller
, QMouseEvent
*e
)
299 if (e
->button()==Qt::LeftButton
){ // left Mouse-button pressed
300 QWidget::mousePressEvent(e
); // do nothing (see mouseReleaseEvent)
302 mousePressEventCall(caller
, e
); // normal mouse-handling
306 void StateSAY::mouseReleaseEvent(KSayItSystemTray
*caller
, QMouseEvent
*e
)
308 if (e
->button()==Qt::LeftButton
){ // left Mouse-button released
309 QWidget::mouseReleaseEvent(e
); // do nothing (see mouseReleaseEvent)
311 mouseReleaseEventCall(caller
, e
); // normal mouse-handling
318 ////////////////////////////////////////////
319 StateCLIPEMPTY::StateCLIPEMPTY(){
320 m_traypixmap
= KGlobal::iconLoader()->loadIcon("ksayit_clipempty", KIcon::Toolbar
);
322 StateCLIPEMPTY::~StateCLIPEMPTY(){
324 StateCLIPEMPTY
* StateCLIPEMPTY::_instance
= 0;
326 StateCLIPEMPTY
* StateCLIPEMPTY::Instance()
329 _instance
= new StateCLIPEMPTY();
334 void StateCLIPEMPTY::setContext(KSayItSystemTray
*caller
)
336 caller
->setPixmap( m_traypixmap
);
339 void StateCLIPEMPTY::mousePressEvent(KSayItSystemTray
*caller
, QMouseEvent
*e
)
341 if (e
->button()==Qt::LeftButton
){ // left Mouse-button pressed
342 QWidget::mousePressEvent(e
); // do nothing (see mouseReleaseEvent)
344 mousePressEventCall(caller
, e
); // normal mouse-handling
348 void StateCLIPEMPTY::mouseReleaseEvent(KSayItSystemTray
*caller
, QMouseEvent
*e
)
350 if (e
->button()==Qt::LeftButton
){ // left Mouse-button released
351 QWidget::mouseReleaseEvent(e
); // do nothing (see mouseReleaseEvent)
353 mouseReleaseEventCall(caller
, e
); // normal mouse-handling
358 #include "ksayitsystemtray.moc"