From 5ec5bc2080bbc41e025fb98e6571a2c281b775cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sl=C3=A1vek=20Banko?= Date: Tue, 2 Jul 2013 18:32:11 +0200 Subject: Initial import --- kbiff/status.cpp | 136 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 136 insertions(+) create mode 100644 kbiff/status.cpp (limited to 'kbiff/status.cpp') diff --git a/kbiff/status.cpp b/kbiff/status.cpp new file mode 100644 index 0000000..3919185 --- /dev/null +++ b/kbiff/status.cpp @@ -0,0 +1,136 @@ +/* + * status.cpp + * Copyright (C) 1999-2008 Kurt Granroth + * + * This file contains the implementation of the KBiffStatus + * widget + */ +#include "status.h" +#include "status.moc" + +#include +#include + +#include +#include +#include + +#include +#include +#include +#include +#include + +KBiffStatus::KBiffStatus(QWidget *parent_, const QString& profile, const KBiffStatusList& list) + : QFrame(parent_, 0, WType_Popup), + _listView(new QListView(this)) +{ + setFrameStyle(WinPanel|Raised); + QLabel *profile_label = new QLabel(profile, this); + profile_label->setFrameStyle(QFrame::Box | QFrame::Raised); + profile_label->setAlignment(AlignCenter); + + _listView->addColumn(i18n("Mailbox")); + _listView->addColumn(i18n("New")); + _listView->addColumn(i18n("Old")); + _listView->setColumnAlignment(1, AlignRight); + _listView->setColumnAlignment(2, AlignRight); + _listView->setSorting(1, FALSE); + _listView->setFrameStyle(QFrame::WinPanel | QFrame::Raised); + _listView->setVScrollBarMode(QScrollView::AlwaysOff); + _listView->setHScrollBarMode(QScrollView::AlwaysOff); + _listView->header()->hide(); + + updateListView(list); + + int list_height = (_listView->firstChild()->height() * list.count()) + 10; + _listView->setFixedSize(_listView->sizeHint().width() + 5, list_height); + resize(_listView->size()); + + QVBoxLayout *blayout = new QVBoxLayout(this, 0, 0); + blayout->addWidget(profile_label); + blayout->addWidget(_listView); +} + +KBiffStatus::~KBiffStatus() +{ +} + +void KBiffStatus::updateListView(const KBiffStatusList& list) +{ + _listView->clear(); + KBiffStatusListIterator it(list); + for(it.toFirst(); it.current(); ++it) + { + if (it.current()->newMessages() == "-1") + { + new QListViewItem(_listView, it.current()->mailbox(), + i18n("Disabled")); + } + else + { + new QListViewItem(_listView, it.current()->mailbox(), + it.current()->newMessages(),it.current()->curMessages()); + } + } +} + +void KBiffStatus::popup(const QPoint& pos_) +{ + QDesktopWidget *desktop = KApplication::desktop(); + int cx = pos_.x(), cy = pos_.y(); + + // for some reason, the width and height are incorrect until + // we do the show. so we show first (after hiding) and move later + move(-100, -100); + show(); + + // verify that the width is within the desktop + if (desktop->isVirtualDesktop()) + { + QRect scn = desktop->screenGeometry(QPoint(cx, cy)); + + if ((pos_.x() + width()) > (scn.x() + scn.width())) + { + cx = (scn.x() + scn.width()) - width(); + cx = (cx < 0) ? 0 : cx; + } + } + else + { + if ((pos_.x() + width()) > desktop->width()) + { + cx = pos_.x() - width(); + cx = (cx < 0) ? 0 : cx; + } + } + + // verify that that height is within tolerances + if ((pos_.y() + height()) > desktop->height()) + { + cy = pos_.y() - height() - 2; + cy = (cy < 0) ? 0 : cy; + } + + // now that we have *real* co-ordinates, we move to them + move(cx, cy+1); +} + +KBiffStatusItem::KBiffStatusItem(const QString& mailbox_, const int num_new,const int num_cur) + : QObject(), + _mailbox(mailbox_), + _newMessages(QString().setNum(num_new)), + _curMessages((num_cur==-1)?QString("?"):QString().setNum(num_cur)) +{ +} +KBiffStatusItem::KBiffStatusItem(const QString& mailbox_, const int num_new) + : QObject(), + _mailbox(mailbox_), + _newMessages(QString().setNum(num_new)), + _curMessages(QString("?")) +{ +} + +KBiffStatusItem::~KBiffStatusItem() +{ +} -- cgit v1.2.3