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 ***************************************************************************/
21 #include <QtCore/QTranslator>
22 #include <QtGui/QMouseEvent>
27 #include <kstandardaction.h>
29 // App specific includes
30 #include "ksayitsystemtray.h"
32 KSayItSystemTray::KSayItSystemTray(QWidget
*parent
, const char *name
)
37 changeState( StateCLIPEMPTY::Instance() );
40 KSayItSystemTray::~KSayItSystemTray()
42 delete StateWAIT::Instance();
43 delete StateSAY::Instance();
44 delete StateCLIPEMPTY::Instance();
47 void KSayItSystemTray::initActions()
50 menu
= this->contextMenu();
51 help
= new KHelpMenu(this, KGlobal::mainComponent().aboutData(), false, actionCollection());
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()),
65 shutup
= new KAction(i18n("Shut Up"),
66 "media-playback-stop",
68 this, SLOT (slotStopActivated()),
72 pause
= new KAction (i18n("Pause"),
73 "media-playback-pause",
75 this, SLOT (slotPauseActivated()),
79 next_sentence
= new KAction (i18n("Next Sentence"),
82 this, SLOT (slotNextSentenceActivated()),
87 prev_sentence
= new KAction (i18n("Previous Sentence"),
88 "media-skip-backward",
90 this, SLOT(slotPrevSentenceActivated()),
94 // Actions -> Context-menu
95 settings
->plug(menu
); menu
->insertSeparator();
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()
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()
138 emit
signalShutUpActivated();
141 void KSayItSystemTray::slotPauseActivated()
144 emit
signalPauseActivated();
147 void KSayItSystemTray::slotNextSentenceActivated()
150 emit
signalNextActivated();
153 void KSayItSystemTray::slotPrevSentenceActivated()
156 emit
signalPrevActivated();
160 void KSayItSystemTray::changeState(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 ////////////////////////////////////////////
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()
248 _instance
= new StateWAIT();
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)
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
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()
289 _instance
= new StateSAY();
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)
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)
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()
331 _instance
= new StateCLIPEMPTY();
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)
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)
355 mouseReleaseEventCall(caller
, e
); // normal mouse-handling
360 #include "ksayitsystemtray.moc"