• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • tdeui
 

tdeui

  • tdeui
ksystemtray.cpp
1/* This file is part of the KDE libraries
2
3 Copyright (C) 1999 Matthias Ettrich (ettrich@kde.org)
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
19*/
20
21#include "config.h"
22#include "tdeaction.h"
23#include "tdemessagebox.h"
24#include "tdeshortcut.h"
25#include "ksystemtray.h"
26#include "tdepopupmenu.h"
27#include "tdeapplication.h"
28#include "tdelocale.h"
29#include "tdeaboutdata.h"
30
31#ifdef TQ_WS_X11
32#include <twin.h>
33#include <twinmodule.h>
34#include <qxembed.h>
35#endif
36
37#include <kimageeffect.h>
38#include <kiconloader.h>
39#include <tdeconfig.h>
40
41#include <tqapplication.h>
42#include <tqbitmap.h>
43
44class KSystemTrayPrivate
45{
46public:
47 KSystemTrayPrivate()
48 {
49 actionCollection = 0;
50 }
51
52 ~KSystemTrayPrivate()
53 {
54 delete actionCollection;
55 }
56
57 TDEActionCollection* actionCollection;
58 bool on_all_desktops; // valid only when the parent widget was hidden
59};
60
61KSystemTray::KSystemTray( TQWidget* parent, const char* name )
62 : TQLabel( parent, name, (WFlags)WType_TopLevel )
63{
64#ifdef TQ_WS_X11
65 QXEmbed::initialize();
66#endif
67
68 d = new KSystemTrayPrivate;
69 d->actionCollection = new TDEActionCollection(this);
70
71#ifdef TQ_WS_X11
72 KWin::setSystemTrayWindowFor( winId(), parent?parent->topLevelWidget()->winId(): tqt_xrootwin() );
73#endif
74 setBackgroundMode(X11ParentRelative);
75 setBackgroundOrigin(WindowOrigin);
76 hasQuit = 0;
77 menu = new TDEPopupMenu( this );
78 menu->insertTitle( tdeApp->miniIcon(), tdeApp->caption() );
79 move( -1000, -1000 );
80 KStdAction::quit(this, TQ_SLOT(maybeQuit()), d->actionCollection);
81
82 if (parentWidget())
83 {
84 new TDEAction(i18n("Minimize"), "view-restore", TDEShortcut(),
85 this, TQ_SLOT( minimizeRestoreAction() ),
86 d->actionCollection, "minimizeRestore");
87#ifdef TQ_WS_X11
88 KWin::WindowInfo info = KWin::windowInfo( parentWidget()->winId() );
89 d->on_all_desktops = info.onAllDesktops();
90#else
91 d->on_all_desktops = false;
92#endif
93 }
94 else
95 {
96 d->on_all_desktops = false;
97 }
98 setCaption( TDEGlobal::instance()->aboutData()->programName());
99 setAlignment( alignment() | TQt::AlignVCenter | TQt::AlignHCenter );
100
101 // Handle the possibility that the requested system tray size is something other than 22x22 pixels, per the Free Desktop specifications
102 setScaledContents(true);
103}
104
105KSystemTray::~KSystemTray()
106{
107 delete d;
108}
109
110
111void KSystemTray::showEvent( TQShowEvent * )
112{
113 if ( !hasQuit ) {
114 menu->insertSeparator();
115 TDEAction* action = d->actionCollection->action("minimizeRestore");
116
117 if (action)
118 {
119 action->plug(menu);
120 }
121
122 action = d->actionCollection->action(KStdAction::name(KStdAction::Quit));
123
124 if (action)
125 {
126 action->plug(menu);
127 }
128
129 hasQuit = 1;
130 }
131}
132
133// KDE4 remove
134void KSystemTray::enterEvent( TQEvent* e )
135{
136 TQLabel::enterEvent( e );
137}
138
139TDEPopupMenu* KSystemTray::contextMenu() const
140{
141 return menu;
142}
143
144
145void KSystemTray::mousePressEvent( TQMouseEvent *e )
146{
147 if ( !rect().contains( e->pos() ) )
148 return;
149
150 switch ( e->button() ) {
151 case TQt::LeftButton:
152 toggleActive();
153 break;
154 case TQt::MidButton:
155 // fall through
156 case TQt::RightButton:
157 if ( parentWidget() ) {
158 TDEAction* action = d->actionCollection->action("minimizeRestore");
159 if ( parentWidget()->isVisible() )
160 action->setText( i18n("&Minimize") );
161 else
162 action->setText( i18n("&Restore") );
163 }
164 contextMenuAboutToShow( menu );
165 menu->popup( e->globalPos() );
166 break;
167 default:
168 // nothing
169 break;
170 }
171}
172
173void KSystemTray::mouseReleaseEvent( TQMouseEvent * )
174{
175}
176
177
178void KSystemTray::contextMenuAboutToShow( TDEPopupMenu* )
179{
180}
181
182// called from the popup menu - always do what the menu entry says,
183// i.e. if the window is shown, no matter if active or not, the menu
184// entry is "minimize", otherwise it's "restore"
185void KSystemTray::minimizeRestoreAction()
186{
187 if ( parentWidget() ) {
188 bool restore = !( parentWidget()->isVisible() );
189 minimizeRestore( restore );
190 }
191}
192
193void KSystemTray::maybeQuit()
194{
195 TQString query = i18n("<qt>Are you sure you want to quit <b>%1</b>?</qt>")
196 .arg(tdeApp->caption());
197 if (KMessageBox::warningContinueCancel(this, query,
198 i18n("Confirm Quit From System Tray"),
199 KStdGuiItem::quit(),
200 TQString("systemtrayquit%1")
201 .arg(tdeApp->caption())) !=
202 KMessageBox::Continue)
203 {
204 return;
205 }
206
207 emit quitSelected();
208
209 // KDE4: stop closing the parent widget? it results in complex application code
210 // instead make applications connect to the quitSelected() signal
211
212 if (parentWidget())
213 {
214 parentWidget()->close();
215 }
216 else
217 {
218 tqApp->closeAllWindows();
219 }
220}
221
222void KSystemTray::toggleActive()
223{
224 activateOrHide();
225}
226
227void KSystemTray::setActive()
228{
229 minimizeRestore( true );
230}
231
232void KSystemTray::setInactive()
233{
234 minimizeRestore( false );
235}
236
237// called when left-clicking the tray icon
238// if the window is not the active one, show it if needed, and activate it
239// (just like taskbar); otherwise hide it
240void KSystemTray::activateOrHide()
241{
242 TQWidget *pw = parentWidget();
243
244 if ( !pw )
245 return;
246
247#ifdef TQ_WS_X11
248 KWin::WindowInfo info1 = KWin::windowInfo( pw->winId(), NET::XAWMState | NET::WMState );
249 // mapped = visible (but possibly obscured)
250 bool mapped = (info1.mappingState() == NET::Visible) && !info1.isMinimized();
251// - not mapped -> show, raise, focus
252// - mapped
253// - obscured -> raise, focus
254// - not obscured -> hide
255 if( !mapped )
256 minimizeRestore( true );
257 else
258 {
259 KWinModule module;
260 for( TQValueList< WId >::ConstIterator it = module.stackingOrder().fromLast();
261 it != module.stackingOrder().end() && (*it) != pw->winId();
262 --it )
263 {
264 KWin::WindowInfo info2 = KWin::windowInfo( *it,
265 NET::WMGeometry | NET::XAWMState | NET::WMState | NET::WMWindowType );
266 if( info2.mappingState() != NET::Visible )
267 continue; // not visible on current desktop -> ignore
268 if( !info2.geometry().intersects( pw->geometry()))
269 continue; // not obscuring the window -> ignore
270 if( !info1.hasState( NET::KeepAbove ) && info2.hasState( NET::KeepAbove ))
271 continue; // obscured by window kept above -> ignore
272 NET::WindowType type = info2.windowType( NET::NormalMask | NET::DesktopMask
273 | NET::DockMask | NET::ToolbarMask | NET::MenuMask | NET::DialogMask
274 | NET::OverrideMask | NET::TopMenuMask | NET::UtilityMask | NET::SplashMask );
275 if( type == NET::Dock || type == NET::TopMenu )
276 continue; // obscured by dock or topmenu -> ignore
277 pw->raise();
278 KWin::activateWindow( pw->winId());
279 return;
280 }
281 minimizeRestore( false ); // hide
282 }
283#endif
284}
285
286void KSystemTray::minimizeRestore( bool restore )
287{
288 TQWidget* pw = parentWidget();
289 if( !pw )
290 return;
291#ifdef TQ_WS_X11
292 KWin::WindowInfo info = KWin::windowInfo( pw->winId(), NET::WMGeometry | NET::WMDesktop );
293 if ( restore )
294 {
295 if( d->on_all_desktops )
296 KWin::setOnAllDesktops( pw->winId(), true );
297 else
298 KWin::setCurrentDesktop( info.desktop() );
299 pw->move( info.geometry().topLeft() ); // avoid placement policies
300 pw->show();
301 pw->raise();
302 KWin::activateWindow( pw->winId() );
303 } else {
304 d->on_all_desktops = info.onAllDesktops();
305 pw->hide();
306 }
307#endif
308}
309
310TDEActionCollection* KSystemTray::actionCollection()
311{
312 return d->actionCollection;
313}
314
315TQPixmap KSystemTray::loadIcon( const TQString &icon, TDEInstance *instance )
316{
317 TDEConfig *appCfg = tdeApp->config();
318 TDEConfigGroupSaver configSaver(appCfg, "System Tray");
319 int iconWidth = appCfg->readNumEntry("systrayIconWidth", 22);
320 return instance->iconLoader()->loadIcon( icon, TDEIcon::Panel, iconWidth );
321}
322
323TQPixmap KSystemTray::loadSizedIcon( const TQString &icon, int iconWidth, TDEInstance *instance )
324{
325 return instance->iconLoader()->loadIcon( icon, TDEIcon::Panel, iconWidth );
326}
327
328void KSystemTray::setPixmap( const TQPixmap& p )
329{
330 TQPixmap iconPixmapToSet = p;
331 if (TQPaintDevice::x11AppDepth() == 32) {
332 TQImage correctedImage = KImageEffect::convertToPremultipliedAlpha( iconPixmapToSet.convertToImage() );
333 iconPixmapToSet.convertFromImage(correctedImage);
334 }
335 TQLabel::setPixmap( iconPixmapToSet );
336#ifdef TQ_WS_X11
337 KWin::setIcons( winId(), iconPixmapToSet, TQPixmap());
338#endif
339}
340
341void KSystemTray::setCaption( const TQString& s )
342{
343 TQLabel::setCaption( s );
344}
345
346void KSystemTray::virtual_hook( int, void* )
347{ /*BASE::virtual_hook( id, data );*/ }
348
349#include "ksystemtray.moc"
350#include "kdockwindow.moc"
KImageEffect::convertToPremultipliedAlpha
static TQImage convertToPremultipliedAlpha(TQImage input)
KMessageBox::warningContinueCancel
static int warningContinueCancel(TQWidget *parent, const TQString &text, const TQString &caption=TQString::null, const KGuiItem &buttonContinue=KStdGuiItem::cont(), const TQString &dontAskAgainName=TQString::null, int options=Notify)
Display a "warning" dialog.
Definition: tdemessagebox.cpp:585
KSystemTray::loadSizedIcon
static TQPixmap loadSizedIcon(const TQString &icon, int iconWidth, TDEInstance *instance=TDEGlobal::instance())
Loads an icon icon using the icon loader class of the given instance instance.
Definition: ksystemtray.cpp:323
KSystemTray::KSystemTray
KSystemTray(TQWidget *parent=0, const char *name=0)
Construct a KSystemTray widget just like any other widget.
Definition: ksystemtray.cpp:61
KSystemTray::toggleActive
void toggleActive()
Toggles the state of the window associated with this system tray icon (hides it, shows it or activate...
Definition: ksystemtray.cpp:222
KSystemTray::setInactive
void setInactive()
Hides the window associated with this system tray icon, regardless of its current state.
Definition: ksystemtray.cpp:232
KSystemTray::showEvent
void showEvent(TQShowEvent *)
Reimplemented for internal reasons.
Definition: ksystemtray.cpp:111
KSystemTray::contextMenu
TDEPopupMenu * contextMenu() const
Access to the context menu.
Definition: ksystemtray.cpp:139
KSystemTray::contextMenuAboutToShow
virtual void contextMenuAboutToShow(TDEPopupMenu *menu)
Makes it easy to adjust some menu items right before the context menu becomes visible.
Definition: ksystemtray.cpp:178
KSystemTray::actionCollection
TDEActionCollection * actionCollection()
Easy access to the actions in the context menu Currently includes KStdAction::Quit and minimizeRestor...
Definition: ksystemtray.cpp:310
KSystemTray::quitSelected
void quitSelected()
Emitted when quit is selected in the menu.
KSystemTray::mouseReleaseEvent
void mouseReleaseEvent(TQMouseEvent *)
Reimplemented to provide the standard show/raise behavior for the parentWidget() and the context menu...
Definition: ksystemtray.cpp:173
KSystemTray::setPixmap
virtual void setPixmap(const TQPixmap &icon)
Changes the tray's icon.
Definition: ksystemtray.cpp:328
KSystemTray::loadIcon
static TQPixmap loadIcon(const TQString &icon, TDEInstance *instance=TDEGlobal::instance())
Loads an icon icon using the icon loader class of the given instance instance.
Definition: ksystemtray.cpp:315
KSystemTray::enterEvent
void enterEvent(TQEvent *)
Reimplemented for internal reasons.
Definition: ksystemtray.cpp:134
KSystemTray::mousePressEvent
void mousePressEvent(TQMouseEvent *)
Reimplemented to provide the standard show/raise behavior for the parentWidget() and the context menu...
Definition: ksystemtray.cpp:145
KSystemTray::setCaption
virtual void setCaption(const TQString &title)
Changes the tray's text description (which can be seen e.g.
Definition: ksystemtray.cpp:341
KSystemTray::setActive
void setActive()
Activates the window associated with this system tray icon, regardless of its current state.
Definition: ksystemtray.cpp:227
KWinModule
KWinModule::stackingOrder
const TQValueList< WId > & stackingOrder() const
KWin::WindowInfo
KWin::WindowInfo::windowType
NET::WindowType windowType(int supported_types) const
KWin::WindowInfo::isMinimized
bool isMinimized() const
KWin::WindowInfo::mappingState
NET::MappingState mappingState() const
KWin::WindowInfo::hasState
bool hasState(unsigned long s) const
KWin::WindowInfo::geometry
TQRect geometry() const
KWin::WindowInfo::desktop
int desktop() const
KWin::WindowInfo::onAllDesktops
bool onAllDesktops() const
KWin::setCurrentDesktop
static void setCurrentDesktop(int desktop)
KWin::activateWindow
static void activateWindow(WId win, long time=0)
KWin::setOnAllDesktops
static void setOnAllDesktops(WId win, bool b)
KWin::windowInfo
static WindowInfo windowInfo(WId win, unsigned long properties=0, unsigned long properties2=0)
KWin::setSystemTrayWindowFor
static void setSystemTrayWindowFor(WId trayWin, WId forWin)
KWin::setIcons
static void setIcons(WId win, const TQPixmap &icon, const TQPixmap &miniIcon)
NET::KeepAbove
KeepAbove
NET::WindowType
WindowType
TDEActionCollection
A managed set of TDEAction objects.
Definition: tdeactioncollection.h:79
TDEAction
Class to encapsulate user-driven action or event.
Definition: tdeaction.h:203
TDEConfigBase::readNumEntry
int readNumEntry(const TQString &pKey, int nDefault=0) const
TDEConfigGroupSaver
TDEConfig
TDEGlobal::instance
static TDEInstance * instance()
TDEIconLoader::loadIcon
TQPixmap loadIcon(const TQString &name, TDEIcon::Group group, int size=0, int state=TDEIcon::DefaultState, TQString *path_store=0L, bool canReturnNull=false) const
TDEIcon::Panel
Panel
TDEInstance
TDEInstance::iconLoader
TDEIconLoader * iconLoader() const
TDEPopupMenu
A menu with title items.
Definition: tdepopupmenu.h:123
TDEPopupMenu::insertTitle
int insertTitle(const TQString &text, int id=-1, int index=-1)
Inserts a title item with no icon.
Definition: tdepopupmenu.cpp:181
TDEShortcut
KStdAction::quit
TDEAction * quit(const TQObject *recvr, const char *slot, TDEActionCollection *parent, const char *name)
Quit the program.
Definition: kstdaction.cpp:162
KStdAction::name
const char * name(StdAction id)
This will return the internal name of a given standard action.
Definition: kstdaction.cpp:136
tdelocale.h

tdeui

Skip menu "tdeui"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

tdeui

Skip menu "tdeui"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdeui by doxygen 1.9.4
This website is maintained by Timothy Pearson.