/* * NotifyWidget.cpp * * Copyright (C) 2021 Emanoil Kotsev * * * This file is part of kdbusnotification. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include #include #include #include #include "NotifyWidget.h" #include "NotificationsService.h" #define FADE_SPEED 5 NotifyWidget::NotifyWidget(TQWidget *parent, const char *name, NotificationsService *ns, TQ_INT32 id ) : TQLabel( parent, name, WStyle_Customize | TQt::WStyle_StaysOnTop | TQt::WStyle_NoBorder), mName(TQString(name)), notificationService(ns), mId(id) { // TODO Auto-generated constructor stub TQDesktopWidget *d = TQApplication::desktop(); mPosition=TQPoint(d->width()-50, d->height()-20); move(mPosition); TQTimer::singleShot(100, this, TQ_SLOT(fadeAway())); } NotifyWidget::~NotifyWidget() { // TODO Auto-generated destructor stub } void NotifyWidget::mousePressEvent( TQMouseEvent *e ) { if (e->button() == TQMouseEvent::LeftButton) { // The notification was dismissed by the user. notificationService->closeNotifyWidget(mId, 2); } } void NotifyWidget::timeout() { notificationService->closeNotifyWidget(mId, 1); // The notification expired. } void NotifyWidget::fadeAway() { mPosition.setY(mPosition.y()-1); move(mPosition); TQTimer::singleShot(FADE_SPEED, this, TQ_SLOT(fadeAway())); } void NotifyWidget::setAutoMask(bool b) { if (b) setBackgroundMode( PaletteForeground ); else setBackgroundMode( PaletteBackground ); TQWidget::setAutoMask(b); } bool NotifyWidget::setIcon(const TQString& icon) { mIcon = icon; TQPixmap pixmap; if ( pixmap.load(mIcon) ) { this->setPixmap(pixmap); } else { tqDebug("Could not load notification icon"); return false; } return true; } void NotifyWidget::setActions(const TQStringList& actions) { mActions = actions; // TODO handle actions } void NotifyWidget::setHints(const TQMap< TQString, TQT_DBusVariant >& hints) { mHints = hints; // TODO handle hints } void NotifyWidget::setTimeout(TQ_INT32 t) { TDEApplication::kApplication()->setTopWidget(this); TQTimer::singleShot(t, this, TQ_SLOT(timeout())); } #include "NotifyWidget.moc"