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

Applets

systemtray.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   systemtray.cpp                                                        *
00003  *                                                                         *
00004  *   Copyright (C) 2007 Alexander Rodin <rodin.alexander@gmail.com>        *
00005  *   Copyright (C) 2007 Jason Stubbs <jasonbstubbs@gmail.com>              *
00006  *                                                                         *
00007  *   This program is free software; you can redistribute it and/or modify  *
00008  *   it under the terms of the GNU General Public License as published by  *
00009  *   the Free Software Foundation; either version 2 of the License, or     *
00010  *   (at your option) any later version.                                   *
00011  *                                                                         *
00012  *   This program is distributed in the hope that it will be useful,       *
00013  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00014  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00015  *   GNU General Public License for more details.                          *
00016  *                                                                         *
00017  *   You should have received a copy of the GNU General Public License     *
00018  *   along with this program; if not, write to the                         *
00019  *   Free Software Foundation, Inc.,                                       *
00020  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA .        *
00021  ***************************************************************************/
00022 
00023 // Own
00024 #include "systemtray.h"
00025 
00026 // Qt
00027 #include <QGraphicsView>
00028 #include <QTimer>
00029 
00030 //Plasma
00031 #include <plasma/panelsvg.h>
00032 
00033 SystemTray::SystemTray(QObject *parent, const QVariantList &arguments)
00034     : Plasma::Applet(parent, arguments),
00035       m_startUpDelayShowTimer(0),
00036       m_showOwnBackground(false)
00037 {
00038     m_background = new Plasma::PanelSvg(this);
00039     m_background->setImagePath("widgets/systemtray");
00040     connect(this, SIGNAL(geometryChanged()), this, SLOT(updateWidgetGeometry()));
00041 }
00042 
00043 SystemTray::~SystemTray()
00044 {
00045     // Get rid of our SystemTrayWidget if we still have one
00046     delete m_systemTrayWidget;
00047 }
00048 
00049 void SystemTray::constraintsEvent(Plasma::Constraints constraints)
00050 {
00051     if (constraints & Plasma::SizeConstraint) {
00052     }
00053 
00054     if (constraints & (Plasma::LocationConstraint | Plasma::FormFactorConstraint)) {
00055         updateWidgetOrientation();
00056     }
00057 
00058     if (constraints & Plasma::StartupCompletedConstraint) {
00059         updateWidgetGeometry();
00060     }
00061 }
00062 
00063 void SystemTray::paintInterface(QPainter *painter,
00064                                 const QStyleOptionGraphicsItem *option,
00065                                 const QRect& contentsRect)
00066 {
00067     Q_UNUSED(option)
00068 
00069     if (m_showOwnBackground) {
00070         m_background->paintPanel(painter, contentsRect);
00071     }
00072 }
00073 
00074 void SystemTray::updateWidgetOrientation()
00075 {
00076     if (!m_systemTrayWidget) {
00077         return;
00078     }
00079     // TODO: Handle other form factors
00080     if (formFactor() == Plasma::Horizontal) {
00081         m_systemTrayWidget->setOrientation(Qt::Horizontal);
00082     } else {
00083         m_systemTrayWidget->setOrientation(Qt::Vertical);
00084     }
00085 }
00086 
00087 void SystemTray::updateWidgetGeometry()
00088 {
00089     QGraphicsView *parentView = view();
00090     if (!parentView) {
00091         kDebug() << "Problem view is NULL";
00092         return;
00093     }
00094 
00095     if (!m_systemTrayWidget || m_systemTrayWidget->parentWidget() != parentView) {
00096         delete m_systemTrayWidget;
00097         m_systemTrayWidget = new SystemTrayWidget(parentView);
00098         updateWidgetOrientation();
00099         connect(m_systemTrayWidget, SIGNAL(sizeShouldChange()),
00100                 this, SLOT(updateWidgetGeometry()));
00101 
00102         if (! m_startUpDelayShowTimer) {
00103             m_startUpDelayShowTimer = new QTimer(this);
00104             connect(m_startUpDelayShowTimer, SIGNAL(timeout()), this, SLOT(startupDelayer()));
00105         }
00106     }
00107 
00108     if (m_startUpDelayShowTimer) {
00109         kDebug() << "start up delay";
00110         m_startUpDelayShowTimer->start(STARTUP_TIMER_DELAY);
00111         return; // don't relayout yet.
00112     }
00113 
00114     // Figure out the margins set by the background svg and disable the svg
00115     // if there won't be enough room for a single row of icons
00116     qreal leftMargin, topMargin, rightMargin, bottomMargin;
00117     if (formFactor() == Plasma::Vertical || formFactor() == Plasma::Horizontal) {
00118         m_background->setElementPrefix(QString());
00119         m_background->getMargins(leftMargin, topMargin, rightMargin, bottomMargin);
00120 
00121         if (geometry().width() - leftMargin - rightMargin < 22 ||
00122             geometry().height() - topMargin - bottomMargin < 22) {
00123             m_showOwnBackground = false;
00124             leftMargin = topMargin = rightMargin = bottomMargin = 0;
00125         } else {
00126             m_showOwnBackground = true;
00127             m_background->resizePanel(size());
00128             update();
00129         }
00130     } else {
00131         getContentsMargins(&leftMargin, &topMargin, &rightMargin, &bottomMargin);
00132     }
00133 
00134     // Update our preferred size based on the wystem tray widget's size and any margins
00135     QRectF rf = mapFromView(parentView, QRect(m_systemTrayWidget->pos(),
00136                                               m_systemTrayWidget->minimumSize()));
00137     rf.setWidth(rf.width() + leftMargin + rightMargin);
00138     rf.setHeight(rf.height() + topMargin + bottomMargin);
00139 
00140     if (formFactor() == Plasma::Vertical) {
00141         setMinimumHeight(rf.height());
00142         setMinimumWidth(22);
00143     } else if (formFactor() == Plasma::Horizontal) {
00144         setMinimumWidth(rf.width());
00145         setMinimumHeight(22);
00146     }
00147     setPreferredSize(rf.size());
00148 
00149     // Calculate the rect usable by the system tray widget
00150     rf = rect();
00151     rf.moveLeft(rf.left() + leftMargin);
00152     rf.setWidth(rf.width() - leftMargin - rightMargin);
00153     rf.moveTop(rf.top() + topMargin);
00154     rf.setHeight(rf.height() - topMargin - bottomMargin);
00155 
00156     // Set the widget's maximum size to the size to the available size.
00157     // The widget will use this size to calculate how many rows/columns
00158     // can be displayed.
00159     QRect r = mapToView(parentView, rf);
00160     m_systemTrayWidget->setMaximumSize(r.size());
00161 
00162     // Center the widget within the available area
00163     QSize s = m_systemTrayWidget->minimumSize();
00164     r.moveLeft(r.left() + (r.width() - s.width()) / 2);
00165     r.moveTop(r.top() + (r.height() - s.height()) / 2);
00166     r.setSize(s);
00167     m_systemTrayWidget->setGeometry(r);
00168 }
00169 
00170 void SystemTray::startupDelayer()
00171 {
00172     delete m_startUpDelayShowTimer;
00173     m_startUpDelayShowTimer = 0;
00174     m_systemTrayWidget->setVisible(true);
00175     m_systemTrayWidget->init();
00176 }
00177 
00178 #include "systemtray.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
  •   libplasma
  •   libsolidcontrol
  •   libtaskmanager
  • Plasma
  •   Animators
  •   Applets
  •   Engines
  • Solid Modules
Generated for API Reference by doxygen 1.5.4
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