Applets
systemtray.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "systemtray.h"
00025
00026
00027 #include <QGraphicsView>
00028 #include <QTimer>
00029
00030
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
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
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;
00112 }
00113
00114
00115
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
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
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
00157
00158
00159 QRect r = mapToView(parentView, rf);
00160 m_systemTrayWidget->setMaximumSize(r.size());
00161
00162
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"