summaryrefslogtreecommitdiffstats
path: root/kicker/extensions/kasbar/kasclockitem.cpp
diff options
context:
space:
mode:
authortoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
committertoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
commit4aed2c8219774f5d797760606b8489a92ddc5163 (patch)
tree3f8c130f7d269626bf6a9447407ef6c35954426a /kicker/extensions/kasbar/kasclockitem.cpp
downloadtdebase-4aed2c8219774f5d797760606b8489a92ddc5163.tar.gz
tdebase-4aed2c8219774f5d797760606b8489a92ddc5163.zip
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdebase@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'kicker/extensions/kasbar/kasclockitem.cpp')
-rw-r--r--kicker/extensions/kasbar/kasclockitem.cpp120
1 files changed, 120 insertions, 0 deletions
diff --git a/kicker/extensions/kasbar/kasclockitem.cpp b/kicker/extensions/kasbar/kasclockitem.cpp
new file mode 100644
index 000000000..0292a93cb
--- /dev/null
+++ b/kicker/extensions/kasbar/kasclockitem.cpp
@@ -0,0 +1,120 @@
+#include <qpainter.h>
+#include <qbitmap.h>
+#include <qdatetime.h>
+#include <qdrawutil.h>
+#include <qlcdnumber.h>
+#include <qtimer.h>
+
+#include <kdatepicker.h>
+#include <kglobal.h>
+#include <kwin.h>
+#include <kiconloader.h>
+#include <kpixmap.h>
+#include <kpixmapeffect.h>
+#include <klocale.h>
+#include <kstandarddirs.h>
+#include <kpopupmenu.h>
+
+#include <taskmanager.h>
+
+#include "kaspopup.h"
+#include "kastasker.h"
+
+#include "kasclockitem.h"
+#include "kasclockitem.moc"
+
+class LCD : public QLCDNumber
+{
+public:
+ LCD( QWidget *parent, const char *name=0 )
+ : QLCDNumber(parent,name) {}
+ ~LCD() {}
+
+ void draw( QPainter *p ) { drawContents(p); }
+};
+
+KasClockItem::KasClockItem( KasBar *parent )
+ : KasItem( parent )
+{
+ setCustomPopup( true );
+
+ QTimer *t = new QTimer( this );
+ connect( t, SIGNAL( timeout() ), SLOT( updateTime() ) );
+ t->start( 1000 );
+
+ lcd = new LCD( parent );
+ lcd->hide();
+
+ lcd->setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum );
+ lcd->setBackgroundMode( NoBackground );
+ lcd->setFrameStyle( QFrame::NoFrame );
+ lcd->setSegmentStyle( QLCDNumber::Flat );
+ lcd->setNumDigits( 5 );
+ lcd->setAutoMask( true );
+ updateTime();
+
+ connect( this, SIGNAL(leftButtonClicked(QMouseEvent *)), SLOT(togglePopup()) );
+ connect( this, SIGNAL(rightButtonClicked(QMouseEvent *)), SLOT(showMenuAt(QMouseEvent *) ) );
+}
+
+KasClockItem::~KasClockItem()
+{
+ delete lcd;
+}
+
+KasPopup *KasClockItem::createPopup()
+{
+ KasPopup *pop = new KasPopup( this );
+ setPopup( pop );
+
+ (void) new KDatePicker( pop );
+ pop->adjustSize();
+
+ return pop;
+}
+
+void KasClockItem::updateTime()
+{
+ setText( KGlobal::locale()->formatDate( QDate::currentDate(), true /* shortFormat */ ) );
+ lcd->display( KGlobal::locale()->formatTime( QTime::currentTime(), false /* includeSecs */, false /* isDuration */) );
+
+ update();
+}
+
+void KasClockItem::paint( QPainter *p )
+{
+ KasItem::paint( p );
+
+ lcd->setGeometry( QRect( 0, 0, extent(), extent()-15 ) );
+
+ p->save();
+ p->translate( 3, 15 );
+ lcd->setPaletteForegroundColor( kasbar()->colorGroup().mid() );
+ lcd->draw( p );
+ p->restore();
+
+ p->save();
+ p->translate( 1, 13 );
+ lcd->setPaletteForegroundColor( resources()->activePenColor() );
+ lcd->draw( p );
+ p->restore();
+}
+
+void KasClockItem::showMenuAt( QMouseEvent *ev )
+{
+ hidePopup();
+ showMenuAt( ev->globalPos() );
+}
+
+void KasClockItem::showMenuAt( QPoint p )
+{
+ mouseLeave();
+ kasbar()->updateMouseOver();
+
+ KasTasker *bar = dynamic_cast<KasTasker *> (KasItem::kasbar());
+ if ( !bar )
+ return;
+
+ KPopupMenu *menu = bar->contextMenu();
+ menu->exec( p );
+}