• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

Applets

fdographicswidget.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   fdographicswidget.cpp                                                 *
00003  *                                                                         *
00004  *   Copyright (C) 2008 Jason Stubbs <jasonbstubbs@gmail.com>              *
00005  *                                                                         *
00006  *   This program is free software; you can redistribute it and/or modify  *
00007  *   it under the terms of the GNU General Public License as published by  *
00008  *   the Free Software Foundation; either version 2 of the License, or     *
00009  *   (at your option) any later version.                                   *
00010  *                                                                         *
00011  *   This program is distributed in the hope that it will be useful,       *
00012  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00013  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00014  *   GNU General Public License for more details.                          *
00015  *                                                                         *
00016  *   You should have received a copy of the GNU General Public License     *
00017  *   along with this program; if not, write to the                         *
00018  *   Free Software Foundation, Inc.,                                       *
00019  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA .        *
00020  ***************************************************************************/
00021 
00022 #include "fdographicswidget.h"
00023 #include "x11embeddelegate.h"
00024 #include "x11embedcontainer.h"
00025 
00026 #include <QtCore/QPointer>
00027 #include <QtCore/QTimer>
00028 
00029 #include <QtGui/QApplication>
00030 #include <QtGui/QGraphicsView>
00031 
00032 #include <plasma/theme.h>
00033 
00034 
00035 namespace SystemTray
00036 {
00037 
00038 class FdoGraphicsWidget::Private
00039 {
00040 public:
00041     Private()
00042         : clientEmbedded(false)
00043     {
00044     }
00045 
00046     ~Private()
00047     {
00048         delete widget;
00049     }
00050 
00051     WId winId;
00052     bool clientEmbedded;
00053     QPointer<X11EmbedDelegate> widget;
00054 };
00055 
00056 FdoGraphicsWidget::FdoGraphicsWidget(WId winId, QGraphicsWidget *parent)
00057     : QGraphicsWidget(parent),
00058       d(new Private())
00059 {
00060     d->winId = winId;
00061 
00062     setMinimumSize(22, 22);
00063     setMaximumSize(22, 22);
00064     resize(22, 22);
00065 
00066     setCacheMode(QGraphicsItem::NoCache);
00067 
00068     connect(Plasma::Theme::defaultTheme(), SIGNAL(themeChanged()),
00069             this, SLOT(updateWidgetBackground()));
00070     QTimer::singleShot(0, this, SLOT(setupXEmbedDelegate()));
00071 }
00072 
00073 
00074 FdoGraphicsWidget::~FdoGraphicsWidget()
00075 {
00076     delete d;
00077 }
00078 
00079 
00080 void FdoGraphicsWidget::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *parentWidget)
00081 {
00082     QGraphicsWidget::paint(painter, option, parentWidget);
00083 
00084     QGraphicsView *parentView = 0;
00085     foreach (QGraphicsView *view, scene()->views()) {
00086         if (view->isVisible() && view->sceneRect().intersects(sceneBoundingRect())) {
00087             parentView = view;
00088         }
00089     }
00090 
00091     if (!parentView) {
00092         return;
00093     }
00094 
00095     if (!d->widget) {
00096         QTimer::singleShot(0, this, SLOT(setupXEmbedDelegate()));
00097         return;
00098     } else if (!d->clientEmbedded) {
00099         return;
00100     }
00101 
00102     if (d->widget->parentWidget() != parentView) {
00103         //kDebug() << "embedding into" << parentView->metaObject()->className() << "(" << d->winId << ")";
00104         d->widget->setParent(parentView);
00105     }
00106 
00107     QPoint pos = parentView->mapFromScene(scenePos());
00108     pos += parentView->viewport()->pos();
00109     if (d->widget->pos() != pos) {
00110         d->widget->move(pos);
00111     }
00112 
00113     if (!d->widget->isVisible()) {
00114         d->widget->show();
00115     }
00116 }
00117 
00118 void FdoGraphicsWidget::hideEvent(QHideEvent *event)
00119 {
00120     if (d->widget) {
00121         d->widget->hide();
00122     }
00123 }
00124 
00125 void FdoGraphicsWidget::showEvent(QShowEvent *event)
00126 {
00127     if (d->widget) {
00128         d->widget->show();
00129     }
00130 }
00131 
00132 void FdoGraphicsWidget::setupXEmbedDelegate()
00133 {
00134     if (d->widget) {
00135         return;
00136     }
00137 
00138 #if QT_VERSION < 0x040401
00139     const Qt::ApplicationAttribute attr = (Qt::ApplicationAttribute)4;
00140 #else
00141     const Qt::ApplicationAttribute attr = Qt::AA_DontCreateNativeWidgetSiblings;
00142 #endif
00143     if (!QApplication::testAttribute(attr)) {
00144         QApplication::setAttribute(attr);
00145     }
00146 
00147     d->widget = new X11EmbedDelegate();
00148     d->widget->setMinimumSize(22, 22);
00149     d->widget->setMaximumSize(22, 22);
00150     d->widget->resize(22, 22);
00151 
00152     connect(d->widget->container(), SIGNAL(clientIsEmbedded()),
00153             this, SLOT(handleClientEmbedded()));
00154     connect(d->widget->container(), SIGNAL(clientClosed()),
00155             this, SLOT(handleClientClosed()));
00156     connect(d->widget->container(), SIGNAL(error(QX11EmbedContainer::Error)),
00157             this, SLOT(handleClientError(QX11EmbedContainer::Error)));
00158 
00159     d->widget->container()->embedSystemTrayClient(d->winId);
00160 }
00161 
00162 void FdoGraphicsWidget::updateWidgetBackground()
00163 {
00164     if (!d->widget) {
00165         return;
00166     }
00167 
00168     QPalette palette = d->widget->palette();
00169     palette.setBrush(QPalette::Window, Plasma::Theme::defaultTheme()->color(Plasma::Theme::BackgroundColor));
00170     d->widget->setPalette(palette);
00171     d->widget->setBackgroundRole(QPalette::Window);
00172 }
00173 
00174 
00175 void FdoGraphicsWidget::handleClientEmbedded()
00176 {
00177     //kDebug() << "client embedded (" << d->winId << ")";
00178     d->clientEmbedded = true;
00179     update();
00180 }
00181 
00182 
00183 void FdoGraphicsWidget::handleClientClosed()
00184 {
00185     emit clientClosed();
00186     //kDebug() << "client closed (" << d->winId << ")";
00187 }
00188 
00189 
00190 void FdoGraphicsWidget::handleClientError(QX11EmbedContainer::Error error)
00191 {
00192     Q_UNUSED(error);
00193 
00194     //kDebug() << "client error (" << d->winId << ")";
00195     emit clientClosed();
00196 }
00197 
00198 }
00199 
00200 #include "fdographicswidget.moc"

Applets

Skip menu "Applets"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members

API Reference

Skip menu "API Reference"
  • KWin
  •   KWin Libraries
  • Libraries
  •   libkworkspace
  •   libsolidcontrol
  •   libtaskmanager
  • Plasma
  •   Animators
  •   Applets
  •   Engines
  • Solid Modules
Generated for API Reference by doxygen 1.5.7
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal