Move userhandling directly to OverlayUserGroup

This commit is contained in:
Thorvald Natvig 2010-03-04 15:00:50 +01:00
parent 44558542ad
commit 7efcd5268f
3 changed files with 173 additions and 103 deletions

View File

@ -1533,6 +1533,21 @@ QRectF OverlayGroup::boundingRect() const {
OverlayUserGroup::OverlayUserGroup() : OverlayGroup() {
bShowExamples = false;
}
OverlayUserGroup::~OverlayUserGroup() {
reset();
}
void OverlayUserGroup::reset() {
foreach(OverlayUser *ou, qlExampleUsers)
delete ou;
qlExampleUsers.clear();
foreach(OverlayUser *ou, qmUsers)
delete ou;
qmUsers.clear();
}
int OverlayUserGroup::type() const {
@ -1575,6 +1590,103 @@ void OverlayUserGroup::wheelEvent(QGraphicsSceneWheelEvent *event) {
g.o->forceSettings();
}
void OverlayUserGroup::updateUsers() {
QRectF sr = scene()->sceneRect();
unsigned int uiHeight = iroundf(sr.height());
QList<QGraphicsItem *> items;
foreach(QGraphicsItem *qgi, childItems())
items << qgi;
QList<OverlayUser *> users;
if (bShowExamples) {
if (qlExampleUsers.isEmpty()) {
qlExampleUsers << new OverlayUser(Settings::Passive, uiHeight);
qlExampleUsers << new OverlayUser(Settings::Talking, uiHeight);
qlExampleUsers << new OverlayUser(Settings::WhisperPrivate, uiHeight);
qlExampleUsers << new OverlayUser(Settings::WhisperChannel, uiHeight);
}
users = qlExampleUsers;
foreach(OverlayUser *ou, users)
items.removeAll(ou);
}
ClientUser *self = ClientUser::get(g.uiSession);
if (self) {
Channel *home = ClientUser::get(g.uiSession)->cChannel;
QList<ClientUser *> showusers;
foreach(Channel *c, home->allLinks()) {
foreach(User *p, c->qlUsers)
showusers << static_cast<ClientUser *>(p);
}
foreach(ClientUser *cu, showusers) {
OverlayUser *ou = qmUsers.value(cu);
if (! ou) {
ou = new OverlayUser(cu, uiHeight);
connect(cu, SIGNAL(destroyed(QObject *)), this, SLOT(userDestroyed(QObject *)));
qmUsers.insert(cu, ou);
ou->hide();
} else {
items.removeAll(ou);
}
users << ou;
}
}
foreach(QGraphicsItem *qgi, items) {
scene()->removeItem(qgi);
qgi->hide();
}
QRectF children = g.s.os.qrfAvatar | g.s.os.qrfChannel | g.s.os.qrfMutedDeafened | g.s.os.qrfUserName;
int pad = g.s.os.bBox ? iroundf(uiHeight * g.s.os.fHeight * (g.s.os.fBoxPad + g.s.os.fBoxPenWidth)) : 0;
int width = iroundf(children.width() * uiHeight * g.s.os.fHeight) + 2 * pad;
int height = iroundf(children.height() * uiHeight * g.s.os.fHeight) + 2 * pad;
int xofs = - iroundf(children.left() * uiHeight * g.s.os.fHeight) + pad;
int yofs = - iroundf(children.top() * uiHeight * g.s.os.fHeight) + pad;
int y = 0;
int x = 0;
foreach(OverlayUser *ou, users) {
if (ou->parentItem() == NULL)
ou->setParentItem(this);
ou->setPos(x * (width+4) + xofs, y * (height + 4) + yofs);
ou->updateUser();
ou->show();
if (x) {
x = 0;
++y;
} else {
x = 1;
}
}
QRectF br = boundingRect();
int basex = qBound<int>(0, iroundf(sr.width() * g.s.os.fX), iroundf(sr.width() - br.width()));
int basey = qBound<int>(0, iroundf(sr.height() * g.s.os.fY), iroundf(sr.height() - br.height()));
setPos(basex, basey);
}
void OverlayUserGroup::userDestroyed(QObject *obj) {
OverlayUser *ou = qmUsers.take(obj);
if (ou)
delete ou;
}
OverlayClient::OverlayClient(QLocalSocket *socket, QObject *p) : QObject(p) {
qlsSocket = socket;
@ -1615,14 +1727,8 @@ OverlayClient::OverlayClient(QLocalSocket *socket, QObject *p) : QObject(p) {
OverlayClient::~OverlayClient() {
qlsSocket->abort();
foreach(OverlayUser *ou, qlExampleUsers)
delete ou;
qlExampleUsers.clear();
foreach(OverlayUser *ou, qmUsers)
delete ou;
qmUsers.clear();
ougUsers.reset();
}
bool OverlayClient::eventFilter(QObject *o, QEvent *e) {
@ -1758,6 +1864,8 @@ void OverlayClient::showGui() {
qgv.setAttribute(Qt::WA_WState_Hidden, false);
qApp->setActiveWindow(&qgv);
qgv.setFocus();
ougUsers.bShowExamples = true;
setupScene();
@ -1769,6 +1877,7 @@ void OverlayClient::showGui() {
void OverlayClient::hideGui() {
qgpiCursor->hide();
#if defined(QT3_SUPPORT) || defined(Q_WS_WIN)
if (QCoreApplication::loopLevel() > 1) {
QCoreApplication::exit_loop();
@ -1777,6 +1886,8 @@ void OverlayClient::hideGui() {
}
#endif
ougUsers.bShowExamples = false;
QList<QWidget *> widgetlist;
foreach(QGraphicsItem *qgi, qgs.items(Qt::DescendingOrder)) {
@ -1915,18 +2026,12 @@ void OverlayClient::reset() {
if (! uiWidth || ! uiHeight || ! smMem)
return;
foreach(OverlayUser *ou, qmUsers)
delete ou;
qmUsers.clear();
if (qgpiLogo) {
delete qgpiLogo;
qgpiLogo = NULL;
}
foreach(OverlayUser *ou, qlExampleUsers)
delete ou;
qlExampleUsers.clear();
ougUsers.reset();
setupScene();
}
@ -1955,19 +2060,13 @@ void OverlayClient::setupScene() {
qgs.addItem(qgpiLogo);
}
qgpiLogo->show();
if (qlExampleUsers.isEmpty()) {
qlExampleUsers << new OverlayUser(Settings::Passive, uiHeight);
qlExampleUsers << new OverlayUser(Settings::Talking, uiHeight);
qlExampleUsers << new OverlayUser(Settings::WhisperPrivate, uiHeight);
qlExampleUsers << new OverlayUser(Settings::WhisperChannel, uiHeight);
}
} else {
qgs.setBackgroundBrush(Qt::NoBrush);
if (qgpiLogo)
qgpiLogo->hide();
}
ougUsers.updateUsers();
}
void OverlayClient::setupRender() {
@ -1995,74 +2094,8 @@ void OverlayClient::setupRender() {
bool OverlayClient::setTexts(const QList<OverlayTextLine> &lines) {
if (! uiWidth || ! uiHeight || ! smMem)
return true;
QList<QGraphicsItem *> items;
foreach(QGraphicsItem *qgi, ougUsers.childItems())
items << qgi;
QList<OverlayUser *> users;
if (qgpiCursor->isVisible()) {
users = qlExampleUsers;
foreach(OverlayUser *ou, users)
items.removeAll(ou);
}
foreach(const OverlayTextLine &e, lines) {
if (e.uiSession != 0) {
ClientUser *cu = ClientUser::get(e.uiSession);
OverlayUser *ou = qmUsers.value(cu);
if (! ou) {
ou = new OverlayUser(cu, uiHeight);
connect(cu, SIGNAL(destroyed(QObject *)), this, SLOT(userDestroyed(QObject *)));
qmUsers.insert(cu, ou);
ou->hide();
} else {
items.removeAll(ou);
}
users << ou;
}
}
foreach(QGraphicsItem *qgi, items) {
qgs.removeItem(qgi);
qgi->hide();
}
QRectF children = g.s.os.qrfAvatar | g.s.os.qrfChannel | g.s.os.qrfMutedDeafened | g.s.os.qrfUserName;
int pad = g.s.os.bBox ? iroundf(uiHeight * g.s.os.fHeight * (g.s.os.fBoxPad + g.s.os.fBoxPenWidth)) : 0;
int width = iroundf(children.width() * uiHeight * g.s.os.fHeight) + 2 * pad;
int height = iroundf(children.height() * uiHeight * g.s.os.fHeight) + 2 * pad;
int xofs = - iroundf(children.left() * uiHeight * g.s.os.fHeight) + pad;
int yofs = - iroundf(children.top() * uiHeight * g.s.os.fHeight) + pad;
int y = 0;
int x = 0;
foreach(OverlayUser *ou, users) {
if (ou->parentItem() == NULL)
ou->setParentItem(&ougUsers);
ou->setPos(x * (width+4) + xofs, y * (height + 4) + yofs);
ou->updateUser();
ou->show();
if (x) {
x = 0;
++y;
} else {
x = 1;
}
}
QRectF br = ougUsers.boundingRect();
int basex = qBound<int>(0, iroundf(uiWidth * g.s.os.fX), iroundf(uiWidth - br.width()));
int basey = qBound<int>(0, iroundf(uiHeight * g.s.os.fY), iroundf(uiHeight - br.height()));
ougUsers.setPos(basex, basey);
ougUsers.updateUsers();
if (qlsSocket->bytesToWrite() > 1024) {
return (t.elapsed() <= 5000000ULL);
@ -2159,12 +2192,6 @@ void OverlayClient::render() {
qlsSocket->flush();
}
void OverlayClient::userDestroyed(QObject *obj) {
OverlayUser *ou = qmUsers.take(obj);
if (ou)
delete ou;
}
void OverlayClient::openEditor() {
OverlayEditor oe(g.mw, &ougUsers);

View File

@ -90,17 +90,31 @@ class OverlayUser : public OverlayGroup {
static QPointF alignedPosition(const QRectF &box, const QRectF &item, Qt::Alignment a);
};
class OverlayUserGroup : public OverlayGroup {
class OverlayUserGroup : public QObject, public OverlayGroup {
private:
Q_OBJECT
Q_DISABLE_COPY(OverlayUserGroup);
public:
enum { Type = UserType + 3 };
protected:
QMap<QObject *, OverlayUser *> qmUsers;
QList<OverlayUser *> qlExampleUsers;
void contextMenuEvent(QGraphicsSceneContextMenuEvent *);
void wheelEvent(QGraphicsSceneWheelEvent *);
protected slots:
void userDestroyed(QObject *);
public:
bool bShowExamples;
OverlayUserGroup();
~OverlayUserGroup();
int type() const;
public slots:
void reset();
void updateUsers();
};
class OverlayEditorScene : public QGraphicsScene {
@ -251,8 +265,6 @@ class OverlayClient : public QObject {
quint64 uiPid;
QGraphicsScene qgs;
OverlayUserGroup ougUsers;
QMap<QObject *, OverlayUser *> qmUsers;
QList<OverlayUser *> qlExampleUsers;
bool bWasVisible;
bool bDelete;
@ -265,7 +277,6 @@ class OverlayClient : public QObject {
QList<QRectF> qlDirty;
protected slots:
void readyRead();
void userDestroyed(QObject *);
void changed(const QList<QRectF> &);
void render();
public:

View File

@ -6,7 +6,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>383</width>
<width>395</width>
<height>591</height>
</rect>
</property>
@ -62,7 +62,7 @@
<item>
<widget class="QGroupBox" name="qgbPosition">
<property name="title">
<string>Position</string>
<string>Layout</string>
</property>
<layout class="QGridLayout">
<item row="0" column="2" rowspan="2">
@ -97,6 +97,38 @@
</property>
</widget>
</item>
<item row="0" column="0" colspan="2">
<widget class="QGraphicsView" name="qgvView"/>
</item>
<item row="3" column="0">
<widget class="QPushButton" name="qpbEdit">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Edit...</string>
</property>
</widget>
</item>
<item row="3" column="1" colspan="2">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Expanding</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>