Remove this line
[kdeaccessibility.git] / ksayit / src / ksayitsystemtray.cpp
blobb6cd71c060ef074b11a324b037a5b9673db327bb
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 ***************************************************************************/
18 #include <iostream>
20 // QT includes
21 #include <QtCore/QTranslator>
22 #include <QtGui/QMouseEvent>
24 // KDE includes
25 #include <kglobal.h>
26 #include <klocale.h>
27 #include <kstandardaction.h>
29 // App specific includes
30 #include "ksayitsystemtray.h"
32 KSayItSystemTray::KSayItSystemTray(QWidget *parent, const char *name)
33 : KSystemTray(parent)
35 setObjectName(name);
36 initActions();
37 changeState( StateCLIPEMPTY::Instance() );
40 KSayItSystemTray::~KSayItSystemTray()
42 delete StateWAIT::Instance();
43 delete StateSAY::Instance();
44 delete StateCLIPEMPTY::Instance();
47 void KSayItSystemTray::initActions()
49 // Context-menu
50 menu = this->contextMenu();
51 help = new KHelpMenu(this, KGlobal::mainComponent().aboutData(), false, actionCollection());
52 // Standard actions
53 settings = KStandardAction::preferences(this, SLOT(slotPreferences()), actionCollection());
54 help_about = KStandardAction::aboutApp(help, SLOT(aboutApplication()), actionCollection());
55 help_kde = KStandardAction::aboutKDE(help, SLOT(aboutKDE()), actionCollection());
57 // User defined actions
58 say = new KAction(i18n("Say"),
59 "media-playback-start",
61 this, SLOT (slotSayActivated()),
62 actionCollection(),
63 "say_it");
65 shutup = new KAction(i18n("Shut Up"),
66 "media-playback-stop",
68 this, SLOT (slotStopActivated()),
69 actionCollection(),
70 "shut_up");
72 pause = new KAction (i18n("Pause"),
73 "media-playback-pause",
75 this, SLOT (slotPauseActivated()),
76 actionCollection(),
77 "pause");
79 next_sentence = new KAction (i18n("Next Sentence"),
80 "media-skip-forward",
82 this, SLOT (slotNextSentenceActivated()),
83 actionCollection(),
84 "next_sentence");
87 prev_sentence = new KAction (i18n("Previous Sentence"),
88 "media-skip-backward",
90 this, SLOT(slotPrevSentenceActivated()),
91 actionCollection(),
92 "prev_sentence");
94 // Actions -> Context-menu
95 settings->plug(menu); menu->insertSeparator();
96 say->plug(menu);
97 shutup->plug(menu);
98 pause->plug(menu);
99 next_sentence->plug(menu);
100 prev_sentence->plug(menu); menu->insertSeparator();
101 help_about->plug(menu);
102 help_kde->plug(menu);
104 // default enables/disables
105 say ->setEnabled(false);
106 shutup ->setEnabled(false);
107 pause ->setEnabled(false);
108 next_sentence->setEnabled(false);
109 prev_sentence->setEnabled(false);
113 void KSayItSystemTray::slotPreferences()
115 // call Preferences
116 emit signalCallPreferences();
119 void KSayItSystemTray::mousePressEvent(QMouseEvent *me)
121 _state->mousePressEvent(this, me);
124 void KSayItSystemTray::mouseReleaseEvent(QMouseEvent *me)
126 _state->mouseReleaseEvent(this, me);
129 void KSayItSystemTray::slotSayActivated()
131 // start to say content of clipboard
132 emit signalSayActivated();
135 void KSayItSystemTray::slotStopActivated()
137 // stop saying
138 emit signalShutUpActivated();
141 void KSayItSystemTray::slotPauseActivated()
143 // pause saying
144 emit signalPauseActivated();
147 void KSayItSystemTray::slotNextSentenceActivated()
149 // next sentence
150 emit signalNextActivated();
153 void KSayItSystemTray::slotPrevSentenceActivated()
155 // previous sentence
156 emit signalPrevActivated();
160 void KSayItSystemTray::changeState(State *state)
162 _state = state;
163 _state->setContext(this);
166 void KSayItSystemTray::setActions(bool sayEnabled, bool pauseEnabled, bool shutupEnabled,
167 bool nextEnabled, bool prevEnabled)
169 say ->setEnabled(sayEnabled);
170 pause ->setEnabled(pauseEnabled);
171 shutup ->setEnabled(shutupEnabled);
172 next_sentence->setEnabled(nextEnabled);
173 prev_sentence->setEnabled(prevEnabled);
177 void KSayItSystemTray::normalMousePressEvent(QMouseEvent *e)
179 KSystemTray::mousePressEvent(e);
182 void KSayItSystemTray::normalMouseReleaseEvent(QMouseEvent *e)
184 KSystemTray::mouseReleaseEvent(e);
187 void KSayItSystemTray::sayClipboard()
189 emit signalSayClipboard();
195 ////////////////////////////////////////////
196 State::State(){
198 State::~State(){
201 void State::mousePressEvent(KSayItSystemTray *caller, QMouseEvent *e)
203 // reimplemented by subclasses
206 void State::mouseReleaseEvent(KSayItSystemTray *caller, QMouseEvent *e)
208 // reimplemented by subclasses
211 void State::setContext(KSayItSystemTray *caller)
213 // reimplemented by subclasses
216 void State::changeState(KSayItSystemTray *caller, State *state)
218 caller->changeState(state);
221 void State::say(KSayItSystemTray *caller)
223 caller->sayClipboard();
226 void State::mousePressEventCall(KSayItSystemTray *caller, QMouseEvent *e)
228 caller->normalMousePressEvent(e);
231 void State::mouseReleaseEventCall(KSayItSystemTray *caller, QMouseEvent *e)
233 caller->normalMouseReleaseEvent(e);
237 ////////////////////////////////////////////
238 StateWAIT::StateWAIT(){
239 m_traypixmap = KIconLoader::global()->loadIcon("ksayit", K3Icon::Toolbar);
241 StateWAIT::~StateWAIT(){
243 StateWAIT* StateWAIT::_instance = 0;
245 StateWAIT* StateWAIT::Instance()
247 if (_instance == 0){
248 _instance = new StateWAIT();
250 return _instance;
253 void StateWAIT::setContext(KSayItSystemTray *caller)
255 caller->setPixmap( m_traypixmap );
258 void StateWAIT::mousePressEvent(KSayItSystemTray *caller, QMouseEvent *e)
260 if (e->button()==Qt::LeftButton){ // left Mouse-button pressed
261 QWidget::mousePressEvent(e); // do nothing (see mouseReleaseEvent)
262 } else {
263 mousePressEventCall(caller, e); // normal mouse-handling
267 void StateWAIT::mouseReleaseEvent(KSayItSystemTray *caller, QMouseEvent *e)
269 if (e->button()==Qt::LeftButton){ // left Mouse-button released
270 say(caller);
271 } else {
272 mouseReleaseEventCall(caller, e); // normal mouse-handling
278 ////////////////////////////////////////////
279 StateSAY::StateSAY(){
280 m_traypixmap = KIconLoader::global()->loadIcon("ksayit_talking", K3Icon::Toolbar);
282 StateSAY::~StateSAY(){
284 StateSAY* StateSAY::_instance = 0;
286 StateSAY* StateSAY::Instance()
288 if (_instance == 0){
289 _instance = new StateSAY();
291 return _instance;
294 void StateSAY::setContext(KSayItSystemTray *caller)
296 caller->setPixmap( m_traypixmap );
299 void StateSAY::mousePressEvent(KSayItSystemTray *caller, QMouseEvent *e)
301 if (e->button()==Qt::LeftButton){ // left Mouse-button pressed
302 QWidget::mousePressEvent(e); // do nothing (see mouseReleaseEvent)
303 } else {
304 mousePressEventCall(caller, e); // normal mouse-handling
308 void StateSAY::mouseReleaseEvent(KSayItSystemTray *caller, QMouseEvent *e)
310 if (e->button()==Qt::LeftButton){ // left Mouse-button released
311 QWidget::mouseReleaseEvent(e); // do nothing (see mouseReleaseEvent)
312 } else {
313 mouseReleaseEventCall(caller, e); // normal mouse-handling
320 ////////////////////////////////////////////
321 StateCLIPEMPTY::StateCLIPEMPTY(){
322 m_traypixmap = KIconLoader::global()->loadIcon("ksayit_clipempty", K3Icon::Toolbar);
324 StateCLIPEMPTY::~StateCLIPEMPTY(){
326 StateCLIPEMPTY* StateCLIPEMPTY::_instance = 0;
328 StateCLIPEMPTY* StateCLIPEMPTY::Instance()
330 if (_instance == 0){
331 _instance = new StateCLIPEMPTY();
333 return _instance;
336 void StateCLIPEMPTY::setContext(KSayItSystemTray *caller)
338 caller->setPixmap( m_traypixmap );
341 void StateCLIPEMPTY::mousePressEvent(KSayItSystemTray *caller, QMouseEvent *e)
343 if (e->button()==Qt::LeftButton){ // left Mouse-button pressed
344 QWidget::mousePressEvent(e); // do nothing (see mouseReleaseEvent)
345 } else {
346 mousePressEventCall(caller, e); // normal mouse-handling
350 void StateCLIPEMPTY::mouseReleaseEvent(KSayItSystemTray *caller, QMouseEvent *e)
352 if (e->button()==Qt::LeftButton){ // left Mouse-button released
353 QWidget::mouseReleaseEvent(e); // do nothing (see mouseReleaseEvent)
354 } else {
355 mouseReleaseEventCall(caller, e); // normal mouse-handling
360 #include "ksayitsystemtray.moc"