Minor fix
[kdeaccessibility.git] / ksayit / src / ksayitsystemtray.cpp
blob2638056fe7fc7968ef22e6255a6a60876cfba98a
1 /***************************************************************************
2 ksayitsystemtray.cpp - description
3 -------------------
4 begin : Die Sep 2 2003
5 copyright : (C) 2003 by Robert Vogl
6 email : voglrobe@saphir
7 ***************************************************************************/
9 /***************************************************************************
10 * *
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. *
15 * *
16 ***************************************************************************/
17 #include <iostream>
19 // QT includes
20 #include <qtranslator.h>
21 //Added by qt3to4:
22 #include <QMouseEvent>
24 // KDE includes
25 #include <kglobal.h>
26 #include <klocale.h>
28 // App specific includes
29 #include "ksayitsystemtray.h"
31 KSayItSystemTray::KSayItSystemTray(QWidget *parent, const char *name)
32 : KSystemTray(parent,name)
34 initActions();
35 changeState( StateCLIPEMPTY::Instance() );
38 KSayItSystemTray::~KSayItSystemTray()
40 delete StateWAIT::Instance();
41 delete StateSAY::Instance();
42 delete StateCLIPEMPTY::Instance();
45 void KSayItSystemTray::initActions()
47 // Context-menu
48 menu = this->contextMenu();
49 help = new KHelpMenu(this, kapp->aboutData(), false, actionCollection());
50 // Standard actions
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"),
57 "player_play",
59 this, SLOT (slotSayActivated()),
60 actionCollection(),
61 "say_it");
63 shutup = new KAction(i18n("Shut Up"),
64 "player_stop",
66 this, SLOT (slotStopActivated()),
67 actionCollection(),
68 "shut_up");
70 pause = new KAction (i18n("Pause"),
71 "player_pause",
73 this, SLOT (slotPauseActivated()),
74 actionCollection(),
75 "pause");
77 next_sentence = new KAction (i18n("Next Sentence"),
78 "2rightarrow",
80 this, SLOT (slotNextSentenceActivated()),
81 actionCollection(),
82 "next_sentence");
85 prev_sentence = new KAction (i18n("Previous Sentence"),
86 "2leftarrow",
88 this, SLOT(slotPrevSentenceActivated()),
89 actionCollection(),
90 "prev_sentence");
92 // Actions -> Context-menu
93 settings->plug(menu); menu->insertSeparator();
94 say->plug(menu);
95 shutup->plug(menu);
96 pause->plug(menu);
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()
113 // call Preferences
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()
135 // stop saying
136 emit signalShutUpActivated();
139 void KSayItSystemTray::slotPauseActivated()
141 // pause saying
142 emit signalPauseActivated();
145 void KSayItSystemTray::slotNextSentenceActivated()
147 // next sentence
148 emit signalNextActivated();
151 void KSayItSystemTray::slotPrevSentenceActivated()
153 // previous sentence
154 emit signalPrevActivated();
158 void KSayItSystemTray::changeState(State *state)
160 _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 ////////////////////////////////////////////
194 State::State(){
196 State::~State(){
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()
245 if (_instance == 0){
246 _instance = new StateWAIT();
248 return _instance;
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)
260 } else {
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
268 say(caller);
269 } else {
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()
286 if (_instance == 0){
287 _instance = new StateSAY();
289 return _instance;
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)
301 } else {
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)
310 } else {
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()
328 if (_instance == 0){
329 _instance = new StateCLIPEMPTY();
331 return _instance;
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)
343 } else {
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)
352 } else {
353 mouseReleaseEventCall(caller, e); // normal mouse-handling
358 #include "ksayitsystemtray.moc"