You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
137 lines
3.7 KiB
137 lines
3.7 KiB
/*
|
|
* status.cpp
|
|
* Copyright (C) 1999-2008 Kurt Granroth <granroth@kde.org>
|
|
*
|
|
* This file contains the implementation of the KBiffStatus
|
|
* widget
|
|
*/
|
|
#include "status.h"
|
|
#include "status.moc"
|
|
|
|
#include <kapp.h>
|
|
#include <klocale.h>
|
|
|
|
#include <qdesktopwidget.h>
|
|
#include <qpoint.h>
|
|
#include <qrect.h>
|
|
|
|
#include <qheader.h>
|
|
#include <qlabel.h>
|
|
#include <qlayout.h>
|
|
#include <qlistview.h>
|
|
#include <qpoint.h>
|
|
|
|
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()
|
|
{
|
|
}
|