• 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 class KSystemTrayPrivate
45 {
46 public:
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 
61 KSystemTray::KSystemTray( TQWidget* parent, const char* name )
62  : TQLabel( parent, name, (WFlags)WType_TopLevel )
63 {
64 #ifdef Q_WS_X11
65  QXEmbed::initialize();
66 #endif
67 
68  d = new KSystemTrayPrivate;
69  d->actionCollection = new TDEActionCollection(this);
70 
71 #ifdef Q_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( kapp->miniIcon(), kapp->caption() );
79  move( -1000, -1000 );
80  KStdAction::quit(TQT_TQOBJECT(this), TQT_SLOT(maybeQuit()), d->actionCollection);
81 
82  if (parentWidget())
83  {
84  new TDEAction(i18n("Minimize"), "view-restore", TDEShortcut(),
85  TQT_TQOBJECT(this), TQT_SLOT( minimizeRestoreAction() ),
86  d->actionCollection, "minimizeRestore");
87 #ifdef Q_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() | Qt::AlignVCenter | Qt::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 
105 KSystemTray::~KSystemTray()
106 {
107  delete d;
108 }
109 
110 
111 void 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
134 void KSystemTray::enterEvent( TQEvent* e )
135 {
136  TQLabel::enterEvent( e );
137 }
138 
139 TDEPopupMenu* KSystemTray::contextMenu() const
140 {
141  return menu;
142 }
143 
144 
145 void KSystemTray::mousePressEvent( TQMouseEvent *e )
146 {
147  if ( !rect().contains( e->pos() ) )
148  return;
149 
150  switch ( e->button() ) {
151  case Qt::LeftButton:
152  toggleActive();
153  break;
154  case Qt::MidButton:
155  // fall through
156  case Qt::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 
173 void KSystemTray::mouseReleaseEvent( TQMouseEvent * )
174 {
175 }
176 
177 
178 void 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"
185 void KSystemTray::minimizeRestoreAction()
186 {
187  if ( parentWidget() ) {
188  bool restore = !( parentWidget()->isVisible() );
189  minimizeRestore( restore );
190  }
191 }
192 
193 void KSystemTray::maybeQuit()
194 {
195  TQString query = i18n("<qt>Are you sure you want to quit <b>%1</b>?</qt>")
196  .arg(kapp->caption());
197  if (KMessageBox::warningContinueCancel(this, query,
198  i18n("Confirm Quit From System Tray"),
199  KStdGuiItem::quit(),
200  TQString("systemtrayquit%1")
201  .arg(kapp->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 
222 void KSystemTray::toggleActive()
223 {
224  activateOrHide();
225 }
226 
227 void KSystemTray::setActive()
228 {
229  minimizeRestore( true );
230 }
231 
232 void 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
240 void KSystemTray::activateOrHide()
241 {
242  TQWidget *pw = parentWidget();
243 
244  if ( !pw )
245  return;
246 
247 #ifdef Q_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 
286 void KSystemTray::minimizeRestore( bool restore )
287 {
288  TQWidget* pw = parentWidget();
289  if( !pw )
290  return;
291 #ifdef Q_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 
310 TDEActionCollection* KSystemTray::actionCollection()
311 {
312  return d->actionCollection;
313 }
314 
315 TQPixmap KSystemTray::loadIcon( const TQString &icon, TDEInstance *instance )
316 {
317  TDEConfig *appCfg = kapp->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 
323 TQPixmap KSystemTray::loadSizedIcon( const TQString &icon, int iconWidth, TDEInstance *instance )
324 {
325  return instance->iconLoader()->loadIcon( icon, TDEIcon::Panel, iconWidth );
326 }
327 
328 void 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 Q_WS_X11
337  KWin::setIcons( winId(), iconPixmapToSet, TQPixmap());
338 #endif
339 }
340 
341 void KSystemTray::setCaption( const TQString& s )
342 {
343  TQLabel::setCaption( s );
344 }
345 
346 void KSystemTray::virtual_hook( int, void* )
347 { /*BASE::virtual_hook( id, data );*/ }
348 
349 #include "ksystemtray.moc"
350 #include "kdockwindow.moc"
KWin::WindowInfo
KWin::WindowInfo::mappingState
NET::MappingState mappingState() const
TDEConfig
KSystemTray::setInactive
void setInactive()
Hides the window associated with this system tray icon, regardless of its current state...
Definition: ksystemtray.cpp:232
NET::KeepAbove
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::actionCollection
TDEActionCollection * actionCollection()
Easy access to the actions in the context menu Currently includes KStdAction::Quit and minimizeRestor...
Definition: ksystemtray.cpp:310
TDEConfigGroupSaver
TDEIcon::Panel
KSystemTray::contextMenu
TDEPopupMenu * contextMenu() const
Access to the context menu.
Definition: ksystemtray.cpp:139
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
KWin::WindowInfo::geometry
TQRect geometry() const
KSystemTray::setCaption
virtual void setCaption(const TQString &title)
Changes the tray's text description (which can be seen e.g.
Definition: ksystemtray.cpp:341
TDEActionCollection
A managed set of TDEAction objects.
Definition: tdeactioncollection.h:78
TDEAction
Class to encapsulate user-driven action or event.
Definition: tdeaction.h:202
KImageEffect::convertToPremultipliedAlpha
static TQImage convertToPremultipliedAlpha(TQImage input)
KWinModule
NET::WindowType
WindowType
tdelocale.h
KSystemTray::setPixmap
virtual void setPixmap(const TQPixmap &icon)
Changes the tray's icon.
Definition: ksystemtray.cpp:328
TDEPopupMenu::insertTitle
int insertTitle(const TQString &text, int id=-1, int index=-1)
Inserts a title item with no icon.
Definition: tdepopupmenu.cpp:185
KSystemTray::mouseReleaseEvent
void mouseReleaseEvent(TQMouseEvent *)
Reimplemented to provide the standard show/raise behavior for the parentWidget() and the context menu...
Definition: ksystemtray.cpp:173
TDEGlobal::instance
static TDEInstance * instance()
KWinModule::stackingOrder
const TQValueList< WId > & stackingOrder() const
KWin::setSystemTrayWindowFor
static void setSystemTrayWindowFor(WId trayWin, WId forWin)
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
TDEAction::setText
virtual void setText(const TQString &text)
Sets the text associated with this action.
Definition: tdeaction.cpp:879
KWin::WindowInfo::onAllDesktops
bool onAllDesktops() const
KWin::setCurrentDesktop
static void setCurrentDesktop(int desktop)
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
KStdAction::quit
TDEAction * quit(const TQObject *recvr, const char *slot, TDEActionCollection *parent, const char *name)
Quit the program.
Definition: kstdaction.cpp:162
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
KStdAction::name
const char * name(StdAction id)
This will return the internal name of a given standard action.
Definition: kstdaction.cpp:136
KWin::setOnAllDesktops
static void setOnAllDesktops(WId win, bool b)
KWin::WindowInfo::hasState
bool hasState(unsigned long s) const
KSystemTray::showEvent
void showEvent(TQShowEvent *)
Reimplemented for internal reasons.
Definition: ksystemtray.cpp:111
KWin::WindowInfo::windowType
NET::WindowType windowType(int supported_types) const
KWin::activateWindow
static void activateWindow(WId win, long time=0)
TDEShortcut
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
KWin::WindowInfo::desktop
int desktop() const
KSystemTray::quitSelected
void quitSelected()
Emitted when quit is selected in the menu.
KWin::windowInfo
static WindowInfo windowInfo(WId win, unsigned long properties=0, unsigned long properties2=0)
KWin::WindowInfo::isMinimized
bool isMinimized() const
TDEPopupMenu
A menu with title items.
Definition: tdepopupmenu.h:123
KSystemTray::setActive
void setActive()
Activates the window associated with this system tray icon, regardless of its current state...
Definition: ksystemtray.cpp:227
KSystemTray::KSystemTray
KSystemTray(TQWidget *parent=0, const char *name=0)
Construct a KSystemTray widget just like any other widget.
Definition: ksystemtray.cpp:61
TDEAction::plug
virtual int plug(TQWidget *widget, int index=-1)
"Plug" or insert this action into a given widget.
Definition: tdeaction.cpp:628
KWin::setIcons
static void setIcons(WId win, const TQPixmap &icon, const TQPixmap &miniIcon)
TDEInstance

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
  •     tdecore
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  • tdeioslave
  •   http
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdeui by doxygen 1.8.8
This website is maintained by Timothy Pearson.