1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
|
/* -------------------------------------------------------------
FireFlier KDE dock icon
(C) 2002 Martin Maurer and Peter Maurer
License: GPL
this file is based on KTeaTime (Mathias Hoelzer Kluepfel)
------------------------------------------------------------- */
#include <stdlib.h>
#include <qcheckbox.h>
#include <qdialog.h>
#include <qlabel.h>
#include <qlayout.h>
#include <qlineedit.h>
#include <qmenudata.h>
#include <qpainter.h>
#include <qpopupmenu.h>
#include <qpushbutton.h>
#include <qtooltip.h>
#include <qfile.h>
#include <qthread.h>
#include <iostream>
#include <qcursor.h>
#include <kconfig.h>
#include <kiconloader.h>
#include <klocale.h>
#include <kmessagebox.h>
//#include <knotifyclient.h>
#include <kwin.h>
#include <knuminput.h>
#include <kseparator.h>
#include "traywidget.h"
#include <kdialogbase.h>
#include "UT_running.xpm"
#include "UT_not_running.xpm"
traywidget::traywidget()
: KSystemTray()
{
setBackgroundMode(X11ParentRelative);
QString n;
unsigned int num;
pending=false;
menu = new QPopupMenu();
menu->setCheckable(true);
menu->insertItem(SmallIcon("1rightarrow"), i18n("&Hide/Show"), this, SLOT(start()));
menu->insertSeparator();
menu->insertItem(SmallIcon("exit"), i18n("Quit"), kapp, SLOT(quit()));
UT_runningPixmap = new QPixmap(UT_running);
UT_not_runningPixmap = new QPixmap(UT_not_running);
setToolTip(i18n("FireFlier Client"));
start();
}
void toggleMainWidget()
{
if (kapp)
{
QWidget *wdg=kapp->mainWidget();
if (wdg)
{
if (wdg->isHidden())
wdg->show();
else
wdg->hide();
}
}
}
traywidget::~traywidget()
{
delete menu;
delete(UT_runningPixmap);
delete(UT_not_runningPixmap);
}
void traywidget::setPacketPending(bool b)
{
pending=b;
repaint();
}
void traywidget::mousePressEvent(QMouseEvent *event)
{
if (event->button() == 1)
{
toggleMainWidget();
}
else
menu->popup(QCursor::pos());
}
void traywidget::paintEvent(QPaintEvent *)
{
QPixmap *pm;
if (pending)
pm = UT_runningPixmap;
else
pm=UT_not_runningPixmap;
QPainter p(this);
int x = 1 + (12 - pm->width()/2);
int y = 1 + (12 - pm->height()/2);
p.drawPixmap(x , y, *pm);
p.end();
}
void traywidget::start()
{
toggleMainWidget();
}
void traywidget::setToolTip(const QString &text)
{
if (lasttip == text)
return;
lasttip = text;
QToolTip::remove(this);
QToolTip::add(this, text);
}
|