• 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 Q_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
44#include <stdlib.h>
45
46#include "../q4os/dpi1.cc"
47
48class KSystemTrayPrivate
49{
50public:
51 KSystemTrayPrivate()
52 {
53 actionCollection = 0;
54 }
55
56 ~KSystemTrayPrivate()
57 {
58 delete actionCollection;
59 }
60
61 TDEActionCollection* actionCollection;
62 bool on_all_desktops; // valid only when the parent widget was hidden
63};
64
65KSystemTray::KSystemTray( TQWidget* parent, const char* name )
66 : TQLabel( parent, name, (WFlags)WType_TopLevel )
67{
68#ifdef Q_WS_X11
69 QXEmbed::initialize();
70#endif
71
72 d = new KSystemTrayPrivate;
73 d->actionCollection = new TDEActionCollection(this);
74
75#ifdef Q_WS_X11
76 KWin::setSystemTrayWindowFor( winId(), parent?parent->topLevelWidget()->winId(): tqt_xrootwin() );
77#endif
78 setBackgroundMode(X11ParentRelative);
79 setBackgroundOrigin(WindowOrigin);
80 hasQuit = 0;
81 menu = new TDEPopupMenu( this );
82 menu->insertTitle( kapp->miniIcon(), kapp->caption() );
83 move( -1000, -1000 );
84 KStdAction::quit(TQT_TQOBJECT(this), TQT_SLOT(maybeQuit()), d->actionCollection);
85
86 if (parentWidget())
87 {
88 new TDEAction(i18n("Minimize"), "view-restore", TDEShortcut(),
89 TQT_TQOBJECT(this), TQT_SLOT( minimizeRestoreAction() ),
90 d->actionCollection, "minimizeRestore");
91#ifdef Q_WS_X11
92 KWin::WindowInfo info = KWin::windowInfo( parentWidget()->winId() );
93 d->on_all_desktops = info.onAllDesktops();
94#else
95 d->on_all_desktops = false;
96#endif
97 }
98 else
99 {
100 d->on_all_desktops = false;
101 }
102 setCaption( TDEGlobal::instance()->aboutData()->programName());
103 setAlignment( alignment() | Qt::AlignVCenter | Qt::AlignHCenter );
104
105 // Handle the possibility that the requested system tray size is something other than 22x22 pixels, per the Free Desktop specifications
106 setScaledContents(true);
107}
108
109KSystemTray::~KSystemTray()
110{
111 delete d;
112}
113
114
115void KSystemTray::showEvent( TQShowEvent * )
116{
117 if ( !hasQuit ) {
118 menu->insertSeparator();
119 TDEAction* action = d->actionCollection->action("minimizeRestore");
120
121 if (action)
122 {
123 action->plug(menu);
124 }
125
126 action = d->actionCollection->action(KStdAction::name(KStdAction::Quit));
127
128 if (action)
129 {
130 action->plug(menu);
131 }
132
133 hasQuit = 1;
134 }
135}
136
137// KDE4 remove
138void KSystemTray::enterEvent( TQEvent* e )
139{
140 TQLabel::enterEvent( e );
141}
142
143TDEPopupMenu* KSystemTray::contextMenu() const
144{
145 return menu;
146}
147
148
149void KSystemTray::mousePressEvent( TQMouseEvent *e )
150{
151 if ( !rect().contains( e->pos() ) )
152 return;
153
154 switch ( e->button() ) {
155 case Qt::LeftButton:
156 toggleActive();
157 break;
158 case Qt::MidButton:
159 // fall through
160 case Qt::RightButton:
161 if ( parentWidget() ) {
162 TDEAction* action = d->actionCollection->action("minimizeRestore");
163 if ( parentWidget()->isVisible() )
164 action->setText( i18n("&Minimize") );
165 else
166 action->setText( i18n("&Restore") );
167 }
168 contextMenuAboutToShow( menu );
169 menu->popup( e->globalPos() );
170 break;
171 default:
172 // nothing
173 break;
174 }
175}
176
177void KSystemTray::mouseReleaseEvent( TQMouseEvent * )
178{
179}
180
181
182void KSystemTray::contextMenuAboutToShow( TDEPopupMenu* )
183{
184}
185
186// called from the popup menu - always do what the menu entry says,
187// i.e. if the window is shown, no matter if active or not, the menu
188// entry is "minimize", otherwise it's "restore"
189void KSystemTray::minimizeRestoreAction()
190{
191 if ( parentWidget() ) {
192 bool restore = !( parentWidget()->isVisible() );
193 minimizeRestore( restore );
194 }
195}
196
197void KSystemTray::maybeQuit()
198{
199 TQString query = i18n("<qt>Are you sure you want to quit <b>%1</b>?</qt>")
200 .arg(kapp->caption());
201 if (KMessageBox::warningContinueCancel(this, query,
202 i18n("Confirm Quit From System Tray"),
203 KStdGuiItem::quit(),
204 TQString("systemtrayquit%1")
205 .arg(kapp->caption())) !=
206 KMessageBox::Continue)
207 {
208 return;
209 }
210
211 emit quitSelected();
212
213 // KDE4: stop closing the parent widget? it results in complex application code
214 // instead make applications connect to the quitSelected() signal
215
216 if (parentWidget())
217 {
218 parentWidget()->close();
219 }
220 else
221 {
222 tqApp->closeAllWindows();
223 }
224}
225
226void KSystemTray::toggleActive()
227{
228 activateOrHide();
229}
230
231void KSystemTray::setActive()
232{
233 minimizeRestore( true );
234}
235
236void KSystemTray::setInactive()
237{
238 minimizeRestore( false );
239}
240
241// called when left-clicking the tray icon
242// if the window is not the active one, show it if needed, and activate it
243// (just like taskbar); otherwise hide it
244void KSystemTray::activateOrHide()
245{
246 TQWidget *pw = parentWidget();
247
248 if ( !pw )
249 return;
250
251#ifdef Q_WS_X11
252 KWin::WindowInfo info1 = KWin::windowInfo( pw->winId(), NET::XAWMState | NET::WMState );
253 // mapped = visible (but possibly obscured)
254 bool mapped = (info1.mappingState() == NET::Visible) && !info1.isMinimized();
255// - not mapped -> show, raise, focus
256// - mapped
257// - obscured -> raise, focus
258// - not obscured -> hide
259 if( !mapped )
260 minimizeRestore( true );
261 else
262 {
263 KWinModule module;
264 for( TQValueList< WId >::ConstIterator it = module.stackingOrder().fromLast();
265 it != module.stackingOrder().end() && (*it) != pw->winId();
266 --it )
267 {
268 KWin::WindowInfo info2 = KWin::windowInfo( *it,
269 NET::WMGeometry | NET::XAWMState | NET::WMState | NET::WMWindowType );
270 if( info2.mappingState() != NET::Visible )
271 continue; // not visible on current desktop -> ignore
272 if( !info2.geometry().intersects( pw->geometry()))
273 continue; // not obscuring the window -> ignore
274 if( !info1.hasState( NET::KeepAbove ) && info2.hasState( NET::KeepAbove ))
275 continue; // obscured by window kept above -> ignore
276 NET::WindowType type = info2.windowType( NET::NormalMask | NET::DesktopMask
277 | NET::DockMask | NET::ToolbarMask | NET::MenuMask | NET::DialogMask
278 | NET::OverrideMask | NET::TopMenuMask | NET::UtilityMask | NET::SplashMask );
279 if( type == NET::Dock || type == NET::TopMenu )
280 continue; // obscured by dock or topmenu -> ignore
281 pw->raise();
282 KWin::activateWindow( pw->winId());
283 return;
284 }
285 minimizeRestore( false ); // hide
286 }
287#endif
288}
289
290void KSystemTray::minimizeRestore( bool restore )
291{
292 TQWidget* pw = parentWidget();
293 if( !pw )
294 return;
295#ifdef Q_WS_X11
296 KWin::WindowInfo info = KWin::windowInfo( pw->winId(), NET::WMGeometry | NET::WMDesktop );
297 if ( restore )
298 {
299 if( d->on_all_desktops )
300 KWin::setOnAllDesktops( pw->winId(), true );
301 else
302 KWin::setCurrentDesktop( info.desktop() );
303 pw->move( info.geometry().topLeft() ); // avoid placement policies
304 pw->show();
305 pw->raise();
306 KWin::activateWindow( pw->winId() );
307 } else {
308 d->on_all_desktops = info.onAllDesktops();
309 pw->hide();
310 }
311#endif
312}
313
314TDEActionCollection* KSystemTray::actionCollection()
315{
316 return d->actionCollection;
317}
318
319TQPixmap KSystemTray::loadIcon( const TQString &icon, TDEInstance *instance )
320{
321 TDEConfig *appCfg = kapp->config();
322 TDEConfigGroupSaver configSaver(appCfg, "System Tray");
323 int iconWidth = appCfg->readNumEntry("systrayIconWidth", 22);
324
325 iconWidth = recalculate_iconsize_by_dpi( iconWidth, get_q4dpi() );
326
327 return instance->iconLoader()->loadIcon( icon, TDEIcon::Panel, iconWidth );
328}
329
330TQPixmap KSystemTray::loadSizedIcon( const TQString &icon, int iconWidth, TDEInstance *instance )
331{
332 return instance->iconLoader()->loadIcon( icon, TDEIcon::Panel, iconWidth );
333}
334
335void KSystemTray::setPixmap( const TQPixmap& p )
336{
337 TQPixmap iconPixmapToSet = p;
338 if (TQPaintDevice::x11AppDepth() == 32) {
339 TQImage correctedImage = KImageEffect::convertToPremultipliedAlpha( iconPixmapToSet.convertToImage() );
340 iconPixmapToSet.convertFromImage(correctedImage);
341 }
342 TQLabel::setPixmap( iconPixmapToSet );
343#ifdef Q_WS_X11
344 KWin::setIcons( winId(), iconPixmapToSet, TQPixmap());
345#endif
346}
347
348void KSystemTray::setCaption( const TQString& s )
349{
350 TQLabel::setCaption( s );
351}
352
353void KSystemTray::virtual_hook( int, void* )
354{ /*BASE::virtual_hook( id, data );*/ }
355
356#include "ksystemtray.moc"
357#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:330
KSystemTray::KSystemTray
KSystemTray(TQWidget *parent=0, const char *name=0)
Construct a KSystemTray widget just like any other widget.
Definition: ksystemtray.cpp:65
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:226
KSystemTray::setInactive
void setInactive()
Hides the window associated with this system tray icon, regardless of its current state.
Definition: ksystemtray.cpp:236
KSystemTray::showEvent
void showEvent(TQShowEvent *)
Reimplemented for internal reasons.
Definition: ksystemtray.cpp:115
KSystemTray::contextMenu
TDEPopupMenu * contextMenu() const
Access to the context menu.
Definition: ksystemtray.cpp:143
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:182
KSystemTray::actionCollection
TDEActionCollection * actionCollection()
Easy access to the actions in the context menu Currently includes KStdAction::Quit and minimizeRestor...
Definition: ksystemtray.cpp:314
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:177
KSystemTray::setPixmap
virtual void setPixmap(const TQPixmap &icon)
Changes the tray's icon.
Definition: ksystemtray.cpp:335
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:319
KSystemTray::enterEvent
void enterEvent(TQEvent *)
Reimplemented for internal reasons.
Definition: ksystemtray.cpp:138
KSystemTray::mousePressEvent
void mousePressEvent(TQMouseEvent *)
Reimplemented to provide the standard show/raise behavior for the parentWidget() and the context menu...
Definition: ksystemtray.cpp:149
KSystemTray::setCaption
virtual void setCaption(const TQString &title)
Changes the tray's text description (which can be seen e.g.
Definition: ksystemtray.cpp:348
KSystemTray::setActive
void setActive()
Activates the window associated with this system tray icon, regardless of its current state.
Definition: ksystemtray.cpp:231
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.