From e321944e15211065b802a8dde6038d63bd4988fa Mon Sep 17 00:00:00 2001 From: Manjeet Dahiya Date: Sun, 12 Sep 2010 08:54:47 +0000 Subject: eol fix --- examples/GuiClient/GuiClient.pro | 110 +-- examples/GuiClient/avatarWidget.cpp | 130 +-- examples/GuiClient/avatarWidget.h | 76 +- examples/GuiClient/chatDialog.cpp | 308 +++---- examples/GuiClient/chatDialog.h | 160 ++-- examples/GuiClient/chatDialog.ui | 164 ++-- examples/GuiClient/chatGraphicsScene.cpp | 170 ++-- examples/GuiClient/chatGraphicsScene.h | 98 +-- examples/GuiClient/chatGraphicsView.cpp | 134 +-- examples/GuiClient/chatGraphicsView.h | 88 +- examples/GuiClient/customLabel.cpp | 216 ++--- examples/GuiClient/customLabel.h | 120 +-- examples/GuiClient/customListView.cpp | 214 ++--- examples/GuiClient/customListView.h | 126 +-- examples/GuiClient/customPushButton.cpp | 192 ++--- examples/GuiClient/customPushButton.h | 82 +- examples/GuiClient/customToolButton.cpp | 150 ++-- examples/GuiClient/customToolButton.h | 76 +- examples/GuiClient/main.cpp | 88 +- examples/GuiClient/mainDialog.cpp | 948 ++++++++++----------- examples/GuiClient/mainDialog.h | 188 ++-- examples/GuiClient/mainDialog.ui | 704 +++++++-------- examples/GuiClient/messageGraphicsItem.cpp | 622 +++++++------- examples/GuiClient/messageGraphicsItem.h | 174 ++-- examples/GuiClient/profileDialog.cpp | 180 ++-- examples/GuiClient/profileDialog.h | 82 +- examples/GuiClient/profileDialog.ui | 344 ++++---- examples/GuiClient/rosterItem.cpp | 472 +++++----- examples/GuiClient/rosterItem.h | 138 +-- examples/GuiClient/rosterItemModel.cpp | 222 ++--- examples/GuiClient/rosterItemModel.h | 102 +-- .../GuiClient/rosterItemSortFilterProxyModel.cpp | 130 +-- .../GuiClient/rosterItemSortFilterProxyModel.h | 74 +- examples/GuiClient/searchLineEdit.cpp | 154 ++-- examples/GuiClient/searchLineEdit.h | 164 ++-- examples/GuiClient/statusTextWidget.cpp | 336 ++++---- examples/GuiClient/statusTextWidget.h | 270 +++--- examples/GuiClient/statusWidget.cpp | 308 +++---- examples/GuiClient/statusWidget.h | 106 +-- examples/GuiClient/statusWidget.ui | 426 ++++----- examples/GuiClient/utils.cpp | 302 +++---- examples/GuiClient/utils.h | 90 +- examples/GuiClient/vCardManager.h | 130 +-- 43 files changed, 4684 insertions(+), 4684 deletions(-) (limited to 'examples/GuiClient') diff --git a/examples/GuiClient/GuiClient.pro b/examples/GuiClient/GuiClient.pro index da5a6970..36e652be 100644 --- a/examples/GuiClient/GuiClient.pro +++ b/examples/GuiClient/GuiClient.pro @@ -1,55 +1,55 @@ -include(../examples.pri) - -TARGET = GuiClient -TEMPLATE = app - -SOURCES += main.cpp \ - messageGraphicsItem.cpp \ - chatGraphicsScene.cpp \ - chatGraphicsView.cpp \ - chatDialog.cpp \ - mainDialog.cpp \ - rosterItemModel.cpp \ - rosterItem.cpp \ - rosterItemSortFilterProxyModel.cpp \ - utils.cpp \ - customListView.cpp \ - searchLineEdit.cpp \ - statusWidget.cpp \ - customPushButton.cpp \ - customLabel.cpp \ - avatarWidget.cpp \ - statusTextWidget.cpp \ - customToolButton.cpp \ - vCardManager.cpp \ - profileDialog.cpp - -HEADERS += messageGraphicsItem.h \ - chatGraphicsScene.h \ - chatGraphicsView.h \ - chatDialog.h \ - mainDialog.h \ - rosterItemModel.h \ - rosterItem.h \ - rosterItemSortFilterProxyModel.h \ - utils.h \ - customListView.h \ - searchLineEdit.h \ - statusWidget.h \ - customPushButton.h \ - customLabel.h \ - avatarWidget.h \ - statusTextWidget.h \ - customToolButton.h \ - vCardManager.h \ - profileDialog.h - -FORMS += mainDialog.ui \ - chatDialog.ui \ - statusWidget.ui \ - profileDialog.ui - -QT += network \ - xml - -RESOURCES += resources.qrc +include(../examples.pri) + +TARGET = GuiClient +TEMPLATE = app + +SOURCES += main.cpp \ + messageGraphicsItem.cpp \ + chatGraphicsScene.cpp \ + chatGraphicsView.cpp \ + chatDialog.cpp \ + mainDialog.cpp \ + rosterItemModel.cpp \ + rosterItem.cpp \ + rosterItemSortFilterProxyModel.cpp \ + utils.cpp \ + customListView.cpp \ + searchLineEdit.cpp \ + statusWidget.cpp \ + customPushButton.cpp \ + customLabel.cpp \ + avatarWidget.cpp \ + statusTextWidget.cpp \ + customToolButton.cpp \ + vCardManager.cpp \ + profileDialog.cpp + +HEADERS += messageGraphicsItem.h \ + chatGraphicsScene.h \ + chatGraphicsView.h \ + chatDialog.h \ + mainDialog.h \ + rosterItemModel.h \ + rosterItem.h \ + rosterItemSortFilterProxyModel.h \ + utils.h \ + customListView.h \ + searchLineEdit.h \ + statusWidget.h \ + customPushButton.h \ + customLabel.h \ + avatarWidget.h \ + statusTextWidget.h \ + customToolButton.h \ + vCardManager.h \ + profileDialog.h + +FORMS += mainDialog.ui \ + chatDialog.ui \ + statusWidget.ui \ + profileDialog.ui + +QT += network \ + xml + +RESOURCES += resources.qrc diff --git a/examples/GuiClient/avatarWidget.cpp b/examples/GuiClient/avatarWidget.cpp index fed4be47..4312a5c5 100644 --- a/examples/GuiClient/avatarWidget.cpp +++ b/examples/GuiClient/avatarWidget.cpp @@ -1,65 +1,65 @@ -/* - * Copyright (C) 2008-2010 The QXmpp developers - * - * Author: - * Manjeet Dahiya - * - * Source: - * http://code.google.com/p/qxmpp - * - * This file is a part of QXmpp library. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - */ - - -#include "avatarWidget.h" -#include - -avatarWidget::avatarWidget(QWidget* parent) - : QPushButton(parent) -{ -} - -void avatarWidget::paintEvent(QPaintEvent* event) -{ - Q_UNUSED(event); - QPainter painter(this); - - QRect r = rect(); - - QPixmap pixmap = icon().pixmap(sizeHint(), QIcon::Normal, QIcon::On); - if(pixmap.isNull()) - pixmap = QPixmap(":/icons/resource/avatar.png"); - QRect pixRect(0, 0, 32, 32); - pixRect.moveCenter(r.center()); - painter.drawPixmap(pixRect, pixmap); - - if(underMouse() && !isDown()) - { - painter.drawRect(pixRect.adjusted(0, 0, -1, -1)); - QColor col(Qt::white); - col.setAlpha(80); - painter.fillRect(pixRect.adjusted(0, 0, -1, -1), col); - } - if(isDown()) - { - QColor col(Qt::white); - col.setAlpha(50); - painter.drawRect(pixRect.adjusted(1, 1, -2, -2)); - } -} - -QSize avatarWidget::sizeHint() const -{ - return QSize(32, 32); -} +/* + * Copyright (C) 2008-2010 The QXmpp developers + * + * Author: + * Manjeet Dahiya + * + * Source: + * http://code.google.com/p/qxmpp + * + * This file is a part of QXmpp library. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + */ + + +#include "avatarWidget.h" +#include + +avatarWidget::avatarWidget(QWidget* parent) + : QPushButton(parent) +{ +} + +void avatarWidget::paintEvent(QPaintEvent* event) +{ + Q_UNUSED(event); + QPainter painter(this); + + QRect r = rect(); + + QPixmap pixmap = icon().pixmap(sizeHint(), QIcon::Normal, QIcon::On); + if(pixmap.isNull()) + pixmap = QPixmap(":/icons/resource/avatar.png"); + QRect pixRect(0, 0, 32, 32); + pixRect.moveCenter(r.center()); + painter.drawPixmap(pixRect, pixmap); + + if(underMouse() && !isDown()) + { + painter.drawRect(pixRect.adjusted(0, 0, -1, -1)); + QColor col(Qt::white); + col.setAlpha(80); + painter.fillRect(pixRect.adjusted(0, 0, -1, -1), col); + } + if(isDown()) + { + QColor col(Qt::white); + col.setAlpha(50); + painter.drawRect(pixRect.adjusted(1, 1, -2, -2)); + } +} + +QSize avatarWidget::sizeHint() const +{ + return QSize(32, 32); +} diff --git a/examples/GuiClient/avatarWidget.h b/examples/GuiClient/avatarWidget.h index 6cfca610..26fc7b80 100644 --- a/examples/GuiClient/avatarWidget.h +++ b/examples/GuiClient/avatarWidget.h @@ -1,38 +1,38 @@ -/* - * Copyright (C) 2008-2010 The QXmpp developers - * - * Author: - * Manjeet Dahiya - * - * Source: - * http://code.google.com/p/qxmpp - * - * This file is a part of QXmpp library. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - */ - - -#ifndef AVATARWIDGET_H -#define AVATARWIDGET_H - -#include - -class avatarWidget : public QPushButton -{ -public: - avatarWidget(QWidget* parent = 0); - void paintEvent(QPaintEvent* event); - QSize sizeHint() const; -}; - -#endif // AVATARWIDGET_H +/* + * Copyright (C) 2008-2010 The QXmpp developers + * + * Author: + * Manjeet Dahiya + * + * Source: + * http://code.google.com/p/qxmpp + * + * This file is a part of QXmpp library. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + */ + + +#ifndef AVATARWIDGET_H +#define AVATARWIDGET_H + +#include + +class avatarWidget : public QPushButton +{ +public: + avatarWidget(QWidget* parent = 0); + void paintEvent(QPaintEvent* event); + QSize sizeHint() const; +}; + +#endif // AVATARWIDGET_H diff --git a/examples/GuiClient/chatDialog.cpp b/examples/GuiClient/chatDialog.cpp index 84aca502..5df867f4 100644 --- a/examples/GuiClient/chatDialog.cpp +++ b/examples/GuiClient/chatDialog.cpp @@ -1,154 +1,154 @@ -/* - * Copyright (C) 2008-2010 The QXmpp developers - * - * Author: - * Manjeet Dahiya - * - * Source: - * http://code.google.com/p/qxmpp - * - * This file is a part of QXmpp library. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - */ - - -#include "chatDialog.h" -#include "ui_chatDialog.h" - -#include "chatGraphicsView.h" -#include "chatGraphicsScene.h" -#include "QXmppClient.h" -#include -#include - -chatDialog::chatDialog(QWidget *parent): QDialog(parent, Qt::Window), - ui(new Ui::chatDialogClass), m_view(0), m_scene(0), m_pushButtonSend(0), m_client(0) -{ - ui->setupUi(this); - m_view = new chatGraphicsView(this); - m_scene = new chatGraphicsScene(this); - m_view->setChatGraphicsScene(m_scene); - m_pushButtonSend = new QPushButton("Send", this); -// m_pushButtonSend->setFixedHeight(); -// m_pushButtonSend->setFixedWidth(); - QRect rect = ui->lineEdit->geometry(); - rect.setLeft(rect.right()); - rect.setWidth(60); - m_pushButtonSend->setGeometry(rect); - ui->lineEdit->setFocus(); - ui->verticalLayout->insertWidget(0, m_view); - bool check = connect(m_pushButtonSend, SIGNAL(clicked(bool)), SLOT(sendMessage())); - Q_ASSERT(check); - updateSendButtonGeomerty(); -} - -void chatDialog::show() -{ - QDialog::show(); -} - -QString chatDialog::getBareJid() const -{ - return m_bareJid; -} - -QString chatDialog::getDisplayName() const -{ - return m_displayName; -} - -void chatDialog::setBareJid(const QString& str) -{ - m_bareJid = str; -} - -void chatDialog::setDisplayName(const QString& str) -{ - m_displayName = str; - setWindowTitle(QString("Chat with %1").arg(m_bareJid)); - - QFont font; - font.setBold(true); - QFontMetrics fontMetrics(font); - QRect rect = fontMetrics.boundingRect(m_displayName); - int width = rect.width(); - - if(m_scene) - m_scene->setBoxStartLength(width); -// ui->horizontalSpacer_2->changeSize(width+20, 10); - ui->lineEdit->setFixedWidth(350 - width - 25); - updateSendButtonGeomerty(); -} - -void chatDialog::setQXmppClient(QXmppClient* client) -{ - m_client = client; -} - -void chatDialog::sendMessage() -{ - if(m_client) - m_client->sendMessage(getBareJid(), ui->lineEdit->text()); - - m_view->addMessage("Me", ui->lineEdit->text()); - ui->lineEdit->clear(); -} - -void chatDialog::messageReceived(const QString& msg) -{ - m_view->addMessage(getDisplayName(), msg); -} - -void chatDialog::keyPressEvent(QKeyEvent* event1) -{ - ui->lineEdit->setFocus(); - ui->lineEdit->event(event1); - - if(event1->key() == Qt::Key_Return) - { - m_pushButtonSend->click(); - } - else if(event1->key() == Qt::Key_Escape) - { - hide(); - } -} - -void chatDialog::paintEvent(QPaintEvent* event) -{ - QDialog::paintEvent(event); - QPainter p(this); - p.setPen(Qt::gray); - p.drawRect(rect().adjusted(5, 5, -6, -6)); -} - -void chatDialog::resizeEvent(QResizeEvent *) -{ - updateSendButtonGeomerty(); -} - -void chatDialog::moveEvent(QMoveEvent *) -{ - updateSendButtonGeomerty(); -} - -void chatDialog::updateSendButtonGeomerty() -{ - QRect rect = ui->lineEdit->geometry(); - rect.setLeft(rect.right() + 6); - rect.setWidth(60); - QRect rect2 = rect; - rect2.setHeight(25); - rect2.moveCenter(rect.center()); - m_pushButtonSend->setGeometry(rect2); -} +/* + * Copyright (C) 2008-2010 The QXmpp developers + * + * Author: + * Manjeet Dahiya + * + * Source: + * http://code.google.com/p/qxmpp + * + * This file is a part of QXmpp library. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + */ + + +#include "chatDialog.h" +#include "ui_chatDialog.h" + +#include "chatGraphicsView.h" +#include "chatGraphicsScene.h" +#include "QXmppClient.h" +#include +#include + +chatDialog::chatDialog(QWidget *parent): QDialog(parent, Qt::Window), + ui(new Ui::chatDialogClass), m_view(0), m_scene(0), m_pushButtonSend(0), m_client(0) +{ + ui->setupUi(this); + m_view = new chatGraphicsView(this); + m_scene = new chatGraphicsScene(this); + m_view->setChatGraphicsScene(m_scene); + m_pushButtonSend = new QPushButton("Send", this); +// m_pushButtonSend->setFixedHeight(); +// m_pushButtonSend->setFixedWidth(); + QRect rect = ui->lineEdit->geometry(); + rect.setLeft(rect.right()); + rect.setWidth(60); + m_pushButtonSend->setGeometry(rect); + ui->lineEdit->setFocus(); + ui->verticalLayout->insertWidget(0, m_view); + bool check = connect(m_pushButtonSend, SIGNAL(clicked(bool)), SLOT(sendMessage())); + Q_ASSERT(check); + updateSendButtonGeomerty(); +} + +void chatDialog::show() +{ + QDialog::show(); +} + +QString chatDialog::getBareJid() const +{ + return m_bareJid; +} + +QString chatDialog::getDisplayName() const +{ + return m_displayName; +} + +void chatDialog::setBareJid(const QString& str) +{ + m_bareJid = str; +} + +void chatDialog::setDisplayName(const QString& str) +{ + m_displayName = str; + setWindowTitle(QString("Chat with %1").arg(m_bareJid)); + + QFont font; + font.setBold(true); + QFontMetrics fontMetrics(font); + QRect rect = fontMetrics.boundingRect(m_displayName); + int width = rect.width(); + + if(m_scene) + m_scene->setBoxStartLength(width); +// ui->horizontalSpacer_2->changeSize(width+20, 10); + ui->lineEdit->setFixedWidth(350 - width - 25); + updateSendButtonGeomerty(); +} + +void chatDialog::setQXmppClient(QXmppClient* client) +{ + m_client = client; +} + +void chatDialog::sendMessage() +{ + if(m_client) + m_client->sendMessage(getBareJid(), ui->lineEdit->text()); + + m_view->addMessage("Me", ui->lineEdit->text()); + ui->lineEdit->clear(); +} + +void chatDialog::messageReceived(const QString& msg) +{ + m_view->addMessage(getDisplayName(), msg); +} + +void chatDialog::keyPressEvent(QKeyEvent* event1) +{ + ui->lineEdit->setFocus(); + ui->lineEdit->event(event1); + + if(event1->key() == Qt::Key_Return) + { + m_pushButtonSend->click(); + } + else if(event1->key() == Qt::Key_Escape) + { + hide(); + } +} + +void chatDialog::paintEvent(QPaintEvent* event) +{ + QDialog::paintEvent(event); + QPainter p(this); + p.setPen(Qt::gray); + p.drawRect(rect().adjusted(5, 5, -6, -6)); +} + +void chatDialog::resizeEvent(QResizeEvent *) +{ + updateSendButtonGeomerty(); +} + +void chatDialog::moveEvent(QMoveEvent *) +{ + updateSendButtonGeomerty(); +} + +void chatDialog::updateSendButtonGeomerty() +{ + QRect rect = ui->lineEdit->geometry(); + rect.setLeft(rect.right() + 6); + rect.setWidth(60); + QRect rect2 = rect; + rect2.setHeight(25); + rect2.moveCenter(rect.center()); + m_pushButtonSend->setGeometry(rect2); +} diff --git a/examples/GuiClient/chatDialog.h b/examples/GuiClient/chatDialog.h index 65ee13f3..b2ff2a21 100644 --- a/examples/GuiClient/chatDialog.h +++ b/examples/GuiClient/chatDialog.h @@ -1,80 +1,80 @@ -/* - * Copyright (C) 2008-2010 The QXmpp developers - * - * Author: - * Manjeet Dahiya - * - * Source: - * http://code.google.com/p/qxmpp - * - * This file is a part of QXmpp library. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - */ - - -#ifndef CHATDIALOG_H -#define CHATDIALOG_H - -#include -#include - -namespace Ui -{ - class chatDialogClass; -} - -class chatGraphicsView; -class chatGraphicsScene; -class QXmppClient; -class QPushButton; - -class chatDialog : public QDialog -{ - Q_OBJECT - -public: - chatDialog(QWidget *parent = 0); - void show(); - - QString getBareJid() const; - QString getDisplayName() const; - void setBareJid(const QString&); - void setDisplayName(const QString&); - void setQXmppClient(QXmppClient* client); - void messageReceived(const QString& msg); - -private slots: - void sendMessage(); - -protected: - void keyPressEvent(QKeyEvent*); - void paintEvent(QPaintEvent* event); - virtual void resizeEvent(QResizeEvent*); - virtual void moveEvent(QMoveEvent*); - -private: - void updateSendButtonGeomerty(); - - Ui::chatDialogClass *ui; - chatGraphicsView* m_view; - chatGraphicsScene* m_scene; - QPushButton* m_pushButtonSend; - - // holds a reference to the the connected client - QXmppClient* m_client; - - QString m_bareJid; - QString m_displayName; -}; - -#endif // CHATDIALOG_H +/* + * Copyright (C) 2008-2010 The QXmpp developers + * + * Author: + * Manjeet Dahiya + * + * Source: + * http://code.google.com/p/qxmpp + * + * This file is a part of QXmpp library. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + */ + + +#ifndef CHATDIALOG_H +#define CHATDIALOG_H + +#include +#include + +namespace Ui +{ + class chatDialogClass; +} + +class chatGraphicsView; +class chatGraphicsScene; +class QXmppClient; +class QPushButton; + +class chatDialog : public QDialog +{ + Q_OBJECT + +public: + chatDialog(QWidget *parent = 0); + void show(); + + QString getBareJid() const; + QString getDisplayName() const; + void setBareJid(const QString&); + void setDisplayName(const QString&); + void setQXmppClient(QXmppClient* client); + void messageReceived(const QString& msg); + +private slots: + void sendMessage(); + +protected: + void keyPressEvent(QKeyEvent*); + void paintEvent(QPaintEvent* event); + virtual void resizeEvent(QResizeEvent*); + virtual void moveEvent(QMoveEvent*); + +private: + void updateSendButtonGeomerty(); + + Ui::chatDialogClass *ui; + chatGraphicsView* m_view; + chatGraphicsScene* m_scene; + QPushButton* m_pushButtonSend; + + // holds a reference to the the connected client + QXmppClient* m_client; + + QString m_bareJid; + QString m_displayName; +}; + +#endif // CHATDIALOG_H diff --git a/examples/GuiClient/chatDialog.ui b/examples/GuiClient/chatDialog.ui index 0bca14fa..2cdb8fcc 100644 --- a/examples/GuiClient/chatDialog.ui +++ b/examples/GuiClient/chatDialog.ui @@ -1,82 +1,82 @@ - - - chatDialogClass - - - - 0 - 0 - 445 - 291 - - - - - 445 - 0 - - - - Dialog - - - alternate-background-color: rgb(255, 255, 255); - - - - 0 - - - 6 - - - - - 0 - - - - - - 0 - 0 - - - - background-color: rgb(255, 255, 255); - - - - - - - - 0 - 50 - - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop - - - - - - - - 0 - 0 - - - - background-color: rgb(255, 255, 255); - - - - - - - - - - + + + chatDialogClass + + + + 0 + 0 + 445 + 291 + + + + + 445 + 0 + + + + Dialog + + + alternate-background-color: rgb(255, 255, 255); + + + + 0 + + + 6 + + + + + 0 + + + + + + 0 + 0 + + + + background-color: rgb(255, 255, 255); + + + + + + + + 0 + 50 + + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop + + + + + + + + 0 + 0 + + + + background-color: rgb(255, 255, 255); + + + + + + + + + + diff --git a/examples/GuiClient/chatGraphicsScene.cpp b/examples/GuiClient/chatGraphicsScene.cpp index d9712d37..6681fa4b 100644 --- a/examples/GuiClient/chatGraphicsScene.cpp +++ b/examples/GuiClient/chatGraphicsScene.cpp @@ -1,85 +1,85 @@ -/* - * Copyright (C) 2008-2010 The QXmpp developers - * - * Author: - * Manjeet Dahiya - * - * Source: - * http://code.google.com/p/qxmpp - * - * This file is a part of QXmpp library. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - */ - - -#include "chatGraphicsScene.h" -#include "messageGraphicsItem.h" -#include "chatGraphicsView.h" - -chatGraphicsScene::chatGraphicsScene(QObject* parent) : QGraphicsScene(parent), - m_verticalPosForNewMessage(0), m_verticalSpacing(5) -{ -} - -void chatGraphicsScene::addMessage(const QString& user, const QString& message) -{ - messageGraphicsItem* item = new messageGraphicsItem(); - m_items.append(item); - item->setName(user); - item->setBoxStartLength(m_boxStartLength); - item->setText(message); - item->setViewWidth(350); -// item->setViewWidth(views().at(0)->size().width()); - item->setPos(0, m_verticalPosForNewMessage); - int height = item->boundingRect().height(); - m_verticalPosForNewMessage = m_verticalPosForNewMessage + height + m_verticalSpacing; - addItem(item); - - QRectF rect = sceneRect(); - rect.setHeight(m_verticalPosForNewMessage); - setSceneRect(rect); -} - -void chatGraphicsScene::setWidthResize(int newWidth, int oldWidth) -{ -// verticalReposition(); -} - -void chatGraphicsScene::verticalReposition() -{ - m_verticalPosForNewMessage = 0; - - messageGraphicsItem* item = 0; - for(int i = 0; i < m_items.size(); ++i) - { - item = m_items.at(i); - item->setViewWidth(views().at(0)->size().width()); - item->setPos(0, m_verticalPosForNewMessage); - int height = item->boundingRect().height(); - m_verticalPosForNewMessage = m_verticalPosForNewMessage + height + m_verticalSpacing; - } - - QRectF rect = sceneRect(); - if(item) - { - rect.setHeight(m_verticalPosForNewMessage); - rect.setWidth(item->getMaxWidth() + item->getBoxStartLength() - 4); - setSceneRect(rect); - } -} - -void chatGraphicsScene::setBoxStartLength(int length) -{ - m_boxStartLength = length; -} - +/* + * Copyright (C) 2008-2010 The QXmpp developers + * + * Author: + * Manjeet Dahiya + * + * Source: + * http://code.google.com/p/qxmpp + * + * This file is a part of QXmpp library. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + */ + + +#include "chatGraphicsScene.h" +#include "messageGraphicsItem.h" +#include "chatGraphicsView.h" + +chatGraphicsScene::chatGraphicsScene(QObject* parent) : QGraphicsScene(parent), + m_verticalPosForNewMessage(0), m_verticalSpacing(5) +{ +} + +void chatGraphicsScene::addMessage(const QString& user, const QString& message) +{ + messageGraphicsItem* item = new messageGraphicsItem(); + m_items.append(item); + item->setName(user); + item->setBoxStartLength(m_boxStartLength); + item->setText(message); + item->setViewWidth(350); +// item->setViewWidth(views().at(0)->size().width()); + item->setPos(0, m_verticalPosForNewMessage); + int height = item->boundingRect().height(); + m_verticalPosForNewMessage = m_verticalPosForNewMessage + height + m_verticalSpacing; + addItem(item); + + QRectF rect = sceneRect(); + rect.setHeight(m_verticalPosForNewMessage); + setSceneRect(rect); +} + +void chatGraphicsScene::setWidthResize(int newWidth, int oldWidth) +{ +// verticalReposition(); +} + +void chatGraphicsScene::verticalReposition() +{ + m_verticalPosForNewMessage = 0; + + messageGraphicsItem* item = 0; + for(int i = 0; i < m_items.size(); ++i) + { + item = m_items.at(i); + item->setViewWidth(views().at(0)->size().width()); + item->setPos(0, m_verticalPosForNewMessage); + int height = item->boundingRect().height(); + m_verticalPosForNewMessage = m_verticalPosForNewMessage + height + m_verticalSpacing; + } + + QRectF rect = sceneRect(); + if(item) + { + rect.setHeight(m_verticalPosForNewMessage); + rect.setWidth(item->getMaxWidth() + item->getBoxStartLength() - 4); + setSceneRect(rect); + } +} + +void chatGraphicsScene::setBoxStartLength(int length) +{ + m_boxStartLength = length; +} + diff --git a/examples/GuiClient/chatGraphicsScene.h b/examples/GuiClient/chatGraphicsScene.h index 97b80ce8..82b9a401 100644 --- a/examples/GuiClient/chatGraphicsScene.h +++ b/examples/GuiClient/chatGraphicsScene.h @@ -1,49 +1,49 @@ -/* - * Copyright (C) 2008-2010 The QXmpp developers - * - * Author: - * Manjeet Dahiya - * - * Source: - * http://code.google.com/p/qxmpp - * - * This file is a part of QXmpp library. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - */ - - -#ifndef CHATGRAPHICSSCENE_H -#define CHATGRAPHICSSCENE_H - -#include -#include - -class messageGraphicsItem; - -class chatGraphicsScene : public QGraphicsScene -{ -public: - chatGraphicsScene(QObject* parent = 0); - void addMessage(const QString& user, const QString& message); - void setWidthResize(int newWidth, int oldWidth); - void verticalReposition(); - void setBoxStartLength(int length); - -private: - int m_verticalPosForNewMessage; - int m_verticalSpacing; - int m_boxStartLength; - QList m_items; -}; - -#endif // CHATGRAPHICSSCENE_H +/* + * Copyright (C) 2008-2010 The QXmpp developers + * + * Author: + * Manjeet Dahiya + * + * Source: + * http://code.google.com/p/qxmpp + * + * This file is a part of QXmpp library. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + */ + + +#ifndef CHATGRAPHICSSCENE_H +#define CHATGRAPHICSSCENE_H + +#include +#include + +class messageGraphicsItem; + +class chatGraphicsScene : public QGraphicsScene +{ +public: + chatGraphicsScene(QObject* parent = 0); + void addMessage(const QString& user, const QString& message); + void setWidthResize(int newWidth, int oldWidth); + void verticalReposition(); + void setBoxStartLength(int length); + +private: + int m_verticalPosForNewMessage; + int m_verticalSpacing; + int m_boxStartLength; + QList m_items; +}; + +#endif // CHATGRAPHICSSCENE_H diff --git a/examples/GuiClient/chatGraphicsView.cpp b/examples/GuiClient/chatGraphicsView.cpp index 10af2b7a..caa046be 100644 --- a/examples/GuiClient/chatGraphicsView.cpp +++ b/examples/GuiClient/chatGraphicsView.cpp @@ -1,67 +1,67 @@ -/* - * Copyright (C) 2008-2010 The QXmpp developers - * - * Author: - * Manjeet Dahiya - * - * Source: - * http://code.google.com/p/qxmpp - * - * This file is a part of QXmpp library. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - */ - - -#include "chatGraphicsView.h" -#include "chatGraphicsScene.h" -#include - -chatGraphicsView::chatGraphicsView(QWidget* parent) : QGraphicsView(parent) -{ - setAlignment(Qt::AlignHCenter|Qt::AlignTop); - setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn); - setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); - setFrameStyle(QFrame::NoFrame); -} - -void chatGraphicsView::setChatGraphicsScene(chatGraphicsScene* scene) -{ - m_scene = scene; - setScene(m_scene); -} - -void chatGraphicsView::addMessage(const QString& user, const QString& message) -{ - if(m_scene) - m_scene->addMessage(user, message); - - QRectF rect = scene()->sceneRect(); - rect.adjust(-4, -4, 4, 4); - setSceneRect(rect); - - rect = sceneRect(); - rect.setTop(sceneRect().height() - 20); - rect.setWidth(20); - ensureVisible(rect, 50, 50); -} - -void chatGraphicsView::resizeEvent(QResizeEvent *event) -{ -// pass this to scene - m_scene->setWidthResize(event->size().width(), event->oldSize().width()); - QGraphicsView::resizeEvent(event); - - QRectF rect = scene()->sceneRect(); - rect.adjust(-4, -4, 4, 4); - setSceneRect(rect); -} +/* + * Copyright (C) 2008-2010 The QXmpp developers + * + * Author: + * Manjeet Dahiya + * + * Source: + * http://code.google.com/p/qxmpp + * + * This file is a part of QXmpp library. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + */ + + +#include "chatGraphicsView.h" +#include "chatGraphicsScene.h" +#include + +chatGraphicsView::chatGraphicsView(QWidget* parent) : QGraphicsView(parent) +{ + setAlignment(Qt::AlignHCenter|Qt::AlignTop); + setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn); + setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + setFrameStyle(QFrame::NoFrame); +} + +void chatGraphicsView::setChatGraphicsScene(chatGraphicsScene* scene) +{ + m_scene = scene; + setScene(m_scene); +} + +void chatGraphicsView::addMessage(const QString& user, const QString& message) +{ + if(m_scene) + m_scene->addMessage(user, message); + + QRectF rect = scene()->sceneRect(); + rect.adjust(-4, -4, 4, 4); + setSceneRect(rect); + + rect = sceneRect(); + rect.setTop(sceneRect().height() - 20); + rect.setWidth(20); + ensureVisible(rect, 50, 50); +} + +void chatGraphicsView::resizeEvent(QResizeEvent *event) +{ +// pass this to scene + m_scene->setWidthResize(event->size().width(), event->oldSize().width()); + QGraphicsView::resizeEvent(event); + + QRectF rect = scene()->sceneRect(); + rect.adjust(-4, -4, 4, 4); + setSceneRect(rect); +} diff --git a/examples/GuiClient/chatGraphicsView.h b/examples/GuiClient/chatGraphicsView.h index 20e612c9..927bf44a 100644 --- a/examples/GuiClient/chatGraphicsView.h +++ b/examples/GuiClient/chatGraphicsView.h @@ -1,44 +1,44 @@ -/* - * Copyright (C) 2008-2010 The QXmpp developers - * - * Author: - * Manjeet Dahiya - * - * Source: - * http://code.google.com/p/qxmpp - * - * This file is a part of QXmpp library. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - */ - - -#ifndef CHATGRAPHICSVIEW_H -#define CHATGRAPHICSVIEW_H - -#include -class chatGraphicsScene; - -class chatGraphicsView : public QGraphicsView -{ -public: - chatGraphicsView(QWidget* parent = 0); - void setChatGraphicsScene(chatGraphicsScene* scene); - void addMessage(const QString& user, const QString& message); - -private: - void resizeEvent(QResizeEvent *event); - - chatGraphicsScene* m_scene; -}; - -#endif // CHATGRAPHICSVIEW_H +/* + * Copyright (C) 2008-2010 The QXmpp developers + * + * Author: + * Manjeet Dahiya + * + * Source: + * http://code.google.com/p/qxmpp + * + * This file is a part of QXmpp library. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + */ + + +#ifndef CHATGRAPHICSVIEW_H +#define CHATGRAPHICSVIEW_H + +#include +class chatGraphicsScene; + +class chatGraphicsView : public QGraphicsView +{ +public: + chatGraphicsView(QWidget* parent = 0); + void setChatGraphicsScene(chatGraphicsScene* scene); + void addMessage(const QString& user, const QString& message); + +private: + void resizeEvent(QResizeEvent *event); + + chatGraphicsScene* m_scene; +}; + +#endif // CHATGRAPHICSVIEW_H diff --git a/examples/GuiClient/customLabel.cpp b/examples/GuiClient/customLabel.cpp index 76834fac..383d033d 100644 --- a/examples/GuiClient/customLabel.cpp +++ b/examples/GuiClient/customLabel.cpp @@ -1,108 +1,108 @@ -/* - * Copyright (C) 2008-2010 The QXmpp developers - * - * Author: - * Manjeet Dahiya - * - * Source: - * http://code.google.com/p/qxmpp - * - * This file is a part of QXmpp library. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - */ - - -#include "customLabel.h" -#include - -customLabel::customLabel(QWidget* parent):QLabel(parent), m_timer(this), - m_option(None) -{ - m_timer.setSingleShot(false); - - bool check = connect(&m_timer, SIGNAL(timeout()), SLOT(timeout())); - Q_ASSERT(check); -} - -void customLabel::setCustomText(const QString& text, customLabel::Option op, - int countDown) -{ - m_text = text; - m_option = op; - m_countDown = countDown; - switch(op) - { - case None: - m_timer.stop(); - m_postfix = ""; - break; - case WithProgressEllipsis: -// m_timer.start(400); - m_postfix = ""; - break; - case CountDown: - m_timer.start(1000); - m_postfix = ""; - break; - default: - m_timer.stop(); - m_postfix = ""; - break; - } - - if(m_option == CountDown) - setText(m_text.arg(m_countDown) + m_postfix); - else - setText(m_text + m_postfix); - - updateGeometry(); -} - -void customLabel::timeout() -{ - switch(m_option) - { - case None: - break; - case WithProgressEllipsis: - if(m_postfix == "") - m_postfix = "."; - else if(m_postfix == ".") - m_postfix = ".."; - else if(m_postfix == "..") - m_postfix = "..."; - else if(m_postfix == "...") - m_postfix = ""; - break; - case CountDown: - if(m_countDown == 0) - m_timer.stop(); - --m_countDown; - break; - default: - break; - } - - if(m_option == CountDown) - setText(m_text.arg(m_countDown) + m_postfix); - else - setText(m_text + m_postfix); - updateGeometry(); -} - -//QSize customLabel::sizeHint() const -//{ -// QFont font; -// QFontMetrics fm(font); -// return QSize(fm.width(m_text) + 15, 20); -//} +/* + * Copyright (C) 2008-2010 The QXmpp developers + * + * Author: + * Manjeet Dahiya + * + * Source: + * http://code.google.com/p/qxmpp + * + * This file is a part of QXmpp library. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + */ + + +#include "customLabel.h" +#include + +customLabel::customLabel(QWidget* parent):QLabel(parent), m_timer(this), + m_option(None) +{ + m_timer.setSingleShot(false); + + bool check = connect(&m_timer, SIGNAL(timeout()), SLOT(timeout())); + Q_ASSERT(check); +} + +void customLabel::setCustomText(const QString& text, customLabel::Option op, + int countDown) +{ + m_text = text; + m_option = op; + m_countDown = countDown; + switch(op) + { + case None: + m_timer.stop(); + m_postfix = ""; + break; + case WithProgressEllipsis: +// m_timer.start(400); + m_postfix = ""; + break; + case CountDown: + m_timer.start(1000); + m_postfix = ""; + break; + default: + m_timer.stop(); + m_postfix = ""; + break; + } + + if(m_option == CountDown) + setText(m_text.arg(m_countDown) + m_postfix); + else + setText(m_text + m_postfix); + + updateGeometry(); +} + +void customLabel::timeout() +{ + switch(m_option) + { + case None: + break; + case WithProgressEllipsis: + if(m_postfix == "") + m_postfix = "."; + else if(m_postfix == ".") + m_postfix = ".."; + else if(m_postfix == "..") + m_postfix = "..."; + else if(m_postfix == "...") + m_postfix = ""; + break; + case CountDown: + if(m_countDown == 0) + m_timer.stop(); + --m_countDown; + break; + default: + break; + } + + if(m_option == CountDown) + setText(m_text.arg(m_countDown) + m_postfix); + else + setText(m_text + m_postfix); + updateGeometry(); +} + +//QSize customLabel::sizeHint() const +//{ +// QFont font; +// QFontMetrics fm(font); +// return QSize(fm.width(m_text) + 15, 20); +//} diff --git a/examples/GuiClient/customLabel.h b/examples/GuiClient/customLabel.h index cf8cbf51..7d4ead81 100644 --- a/examples/GuiClient/customLabel.h +++ b/examples/GuiClient/customLabel.h @@ -1,60 +1,60 @@ -/* - * Copyright (C) 2008-2010 The QXmpp developers - * - * Author: - * Manjeet Dahiya - * - * Source: - * http://code.google.com/p/qxmpp - * - * This file is a part of QXmpp library. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - */ - - -#ifndef CUSTOMLABEL_H -#define CUSTOMLABEL_H - -#include -#include - -class customLabel : public QLabel -{ - Q_OBJECT - -public: - enum Option - { - None = 0, - WithProgressEllipsis, - CountDown - }; - customLabel(QWidget* parent = 0); - - void setCustomText(const QString& text, customLabel::Option op = None, - int countDown = 0); - -// QSize sizeHint() const; - -private slots: - void timeout(); - -private: - QTimer m_timer; - customLabel::Option m_option; - QString m_text; - QString m_postfix; - int m_countDown; -}; - -#endif // CUSTOMLABEL_H +/* + * Copyright (C) 2008-2010 The QXmpp developers + * + * Author: + * Manjeet Dahiya + * + * Source: + * http://code.google.com/p/qxmpp + * + * This file is a part of QXmpp library. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + */ + + +#ifndef CUSTOMLABEL_H +#define CUSTOMLABEL_H + +#include +#include + +class customLabel : public QLabel +{ + Q_OBJECT + +public: + enum Option + { + None = 0, + WithProgressEllipsis, + CountDown + }; + customLabel(QWidget* parent = 0); + + void setCustomText(const QString& text, customLabel::Option op = None, + int countDown = 0); + +// QSize sizeHint() const; + +private slots: + void timeout(); + +private: + QTimer m_timer; + customLabel::Option m_option; + QString m_text; + QString m_postfix; + int m_countDown; +}; + +#endif // CUSTOMLABEL_H diff --git a/examples/GuiClient/customListView.cpp b/examples/GuiClient/customListView.cpp index 825402d3..a071722f 100644 --- a/examples/GuiClient/customListView.cpp +++ b/examples/GuiClient/customListView.cpp @@ -1,107 +1,107 @@ -/* - * Copyright (C) 2008-2010 The QXmpp developers - * - * Author: - * Manjeet Dahiya - * - * Source: - * http://code.google.com/p/qxmpp - * - * This file is a part of QXmpp library. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - */ - - -#include "customListView.h" -#include "rosterItem.h" -#include -#include -#include - -customListView::customListView(QWidget* parent):QListView(parent), m_chat("Chat", this), m_profile("View Profile", this) -{ - bool check = connect(this, SIGNAL(pressed(const QModelIndex&)), this, - SLOT(mousePressed(const QModelIndex&))); - Q_ASSERT(check); - check = connect(this, SIGNAL(doubleClicked(const QModelIndex&)), this, - SLOT(doubleClicked(const QModelIndex&))); - Q_ASSERT(check); - check = connect(this, SIGNAL(clicked(const QModelIndex&)), this, - SLOT(clicked(const QModelIndex&))); - Q_ASSERT(check); - check = connect(&m_chat, SIGNAL(triggered()), this, - SLOT(showChatDialog_helper())); - Q_ASSERT(check); - - check = connect(&m_profile, SIGNAL(triggered()), this, - SLOT(showProfile_helper())); - Q_ASSERT(check); -} - -bool customListView::event(QEvent* e) -{ - return QListView::event(e); -} - -void customListView::mousePressed(const QModelIndex& index) -{ - if(QApplication::mouseButtons() == Qt::RightButton) - { - QString bareJid = index.data().toString(); - QMenu menu(this); - menu.addAction(&m_chat); - menu.setDefaultAction(&m_chat); - menu.addAction(&m_profile); - menu.exec(QCursor::pos()); - } -} - -void customListView::doubleClicked(const QModelIndex& index) -{ - m_chat.trigger(); -} - -void customListView::clicked(const QModelIndex& index) -{ -} - -QString customListView::selectedBareJid() -{ - if(selectedIndexes().size() > 0) - return selectedIndexes().at(0).data(rosterItem::BareJid).toString(); - else - return ""; -} - -void customListView::showChatDialog_helper() -{ - QString bareJid = selectedBareJid(); - if(!bareJid.isEmpty()) - emit showChatDialog(bareJid); -} - -void customListView::showProfile_helper() -{ - QString bareJid = selectedBareJid(); - if(!bareJid.isEmpty()) - emit showProfile(bareJid); -} - -void customListView::keyPressEvent(QKeyEvent* event1) -{ - if(event1->key() == Qt::Key_Return) - { - showChatDialog_helper(); - } - QListView::keyPressEvent(event1); -} +/* + * Copyright (C) 2008-2010 The QXmpp developers + * + * Author: + * Manjeet Dahiya + * + * Source: + * http://code.google.com/p/qxmpp + * + * This file is a part of QXmpp library. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + */ + + +#include "customListView.h" +#include "rosterItem.h" +#include +#include +#include + +customListView::customListView(QWidget* parent):QListView(parent), m_chat("Chat", this), m_profile("View Profile", this) +{ + bool check = connect(this, SIGNAL(pressed(const QModelIndex&)), this, + SLOT(mousePressed(const QModelIndex&))); + Q_ASSERT(check); + check = connect(this, SIGNAL(doubleClicked(const QModelIndex&)), this, + SLOT(doubleClicked(const QModelIndex&))); + Q_ASSERT(check); + check = connect(this, SIGNAL(clicked(const QModelIndex&)), this, + SLOT(clicked(const QModelIndex&))); + Q_ASSERT(check); + check = connect(&m_chat, SIGNAL(triggered()), this, + SLOT(showChatDialog_helper())); + Q_ASSERT(check); + + check = connect(&m_profile, SIGNAL(triggered()), this, + SLOT(showProfile_helper())); + Q_ASSERT(check); +} + +bool customListView::event(QEvent* e) +{ + return QListView::event(e); +} + +void customListView::mousePressed(const QModelIndex& index) +{ + if(QApplication::mouseButtons() == Qt::RightButton) + { + QString bareJid = index.data().toString(); + QMenu menu(this); + menu.addAction(&m_chat); + menu.setDefaultAction(&m_chat); + menu.addAction(&m_profile); + menu.exec(QCursor::pos()); + } +} + +void customListView::doubleClicked(const QModelIndex& index) +{ + m_chat.trigger(); +} + +void customListView::clicked(const QModelIndex& index) +{ +} + +QString customListView::selectedBareJid() +{ + if(selectedIndexes().size() > 0) + return selectedIndexes().at(0).data(rosterItem::BareJid).toString(); + else + return ""; +} + +void customListView::showChatDialog_helper() +{ + QString bareJid = selectedBareJid(); + if(!bareJid.isEmpty()) + emit showChatDialog(bareJid); +} + +void customListView::showProfile_helper() +{ + QString bareJid = selectedBareJid(); + if(!bareJid.isEmpty()) + emit showProfile(bareJid); +} + +void customListView::keyPressEvent(QKeyEvent* event1) +{ + if(event1->key() == Qt::Key_Return) + { + showChatDialog_helper(); + } + QListView::keyPressEvent(event1); +} diff --git a/examples/GuiClient/customListView.h b/examples/GuiClient/customListView.h index 764792a5..d088eeb6 100644 --- a/examples/GuiClient/customListView.h +++ b/examples/GuiClient/customListView.h @@ -1,63 +1,63 @@ -/* - * Copyright (C) 2008-2010 The QXmpp developers - * - * Author: - * Manjeet Dahiya - * - * Source: - * http://code.google.com/p/qxmpp - * - * This file is a part of QXmpp library. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - */ - - -#ifndef CUSTOMLISTVIEW_H -#define CUSTOMLISTVIEW_H - -#include -#include - -class customListView : public QListView -{ - Q_OBJECT - -public: - customListView(QWidget* parent = 0); - bool event(QEvent* e); - -public slots: - void mousePressed(const QModelIndex& index); - void doubleClicked(const QModelIndex& index); - void clicked(const QModelIndex& index); - -private slots: - void showChatDialog_helper(); - void showProfile_helper(); - -protected: - void keyPressEvent(QKeyEvent*); - -signals: - void showChatDialog(const QString& bareJid); - void showProfile(const QString& bareJid); - -private: - QString selectedBareJid(); - -private: - QAction m_chat; - QAction m_profile; -}; - -#endif // CUSTOMLISTVIEW_H +/* + * Copyright (C) 2008-2010 The QXmpp developers + * + * Author: + * Manjeet Dahiya + * + * Source: + * http://code.google.com/p/qxmpp + * + * This file is a part of QXmpp library. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + */ + + +#ifndef CUSTOMLISTVIEW_H +#define CUSTOMLISTVIEW_H + +#include +#include + +class customListView : public QListView +{ + Q_OBJECT + +public: + customListView(QWidget* parent = 0); + bool event(QEvent* e); + +public slots: + void mousePressed(const QModelIndex& index); + void doubleClicked(const QModelIndex& index); + void clicked(const QModelIndex& index); + +private slots: + void showChatDialog_helper(); + void showProfile_helper(); + +protected: + void keyPressEvent(QKeyEvent*); + +signals: + void showChatDialog(const QString& bareJid); + void showProfile(const QString& bareJid); + +private: + QString selectedBareJid(); + +private: + QAction m_chat; + QAction m_profile; +}; + +#endif // CUSTOMLISTVIEW_H diff --git a/examples/GuiClient/customPushButton.cpp b/examples/GuiClient/customPushButton.cpp index 5aec648d..d08ef89b 100644 --- a/examples/GuiClient/customPushButton.cpp +++ b/examples/GuiClient/customPushButton.cpp @@ -1,96 +1,96 @@ -/* - * Copyright (C) 2008-2010 The QXmpp developers - * - * Author: - * Manjeet Dahiya - * - * Source: - * http://code.google.com/p/qxmpp - * - * This file is a part of QXmpp library. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - */ - - -#include "customPushButton.h" -#include -#include -#include - -customPushButton::customPushButton(QWidget* parent) - : QPushButton(parent) -{ - setMinimumSize(QSize(20, 18)); -} - -void customPushButton::paintEvent(QPaintEvent* event) -{ - Q_UNUSED(event); - QPainter painter(this); -// painter.setRenderHint(QPainter::Antialiasing); - - QFont font; - painter.setFont(font); - QStyleOptionButton panel; - initStyleOption(&panel); - QRect r = style()->subElementRect(QStyle::SE_PushButtonFocusRect, &panel, this); - painter.setPen(Qt::gray); - - QRect rectSize(0, 0, sizeHint().width(), sizeHint().height()); - rectSize.moveCenter(r.center()); - r = rectSize; - r.adjust(0, 0, -1, -1); - if(underMouse() && !isDown()) - { - QRectF rr = r; - painter.drawRoundedRect(r, 3, 3); - QColor col(Qt::white); - col.setAlpha(80); - rr.adjust(1, 1, -1, -1); - painter.fillRect(rr, col); - } - if(isDown()) - { - QRectF rr = r; -// rr.adjust(1, 1, -1, -1); - painter.drawRoundedRect(rr, 3, 3); - QColor col(Qt::white); - col.setAlpha(80); - rr.adjust(1, 1, -1, -1); - painter.fillRect(rr, col); - } - painter.setPen(Qt::black); - painter.setBrush(Qt::black); - r.moveLeft(r.left() + 3); - font.setBold(true); - painter.setFont(font); - painter.drawText(r, Qt::AlignVCenter|Qt::TextSingleLine, text()); - - QImage image(":/icons/resource/downArrow.png"); - QRect rectDelta(0, 0, 7, 4); - rectDelta.moveRight(r.right() - 4); - rectDelta.moveCenter(QPoint(rectDelta.center().x(), r.center().y())); - painter.drawImage(rectDelta, image); -} - -QSize customPushButton::sizeHint() const -{ - QFont font; - font.setBold(true); - QFontMetrics fm(font); - int width = fm.width(text()); - if(width <= (160 - 8 - 9)) - return QSize(width+8+9, 18); - else - return QSize(160, 18); -} +/* + * Copyright (C) 2008-2010 The QXmpp developers + * + * Author: + * Manjeet Dahiya + * + * Source: + * http://code.google.com/p/qxmpp + * + * This file is a part of QXmpp library. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + */ + + +#include "customPushButton.h" +#include +#include +#include + +customPushButton::customPushButton(QWidget* parent) + : QPushButton(parent) +{ + setMinimumSize(QSize(20, 18)); +} + +void customPushButton::paintEvent(QPaintEvent* event) +{ + Q_UNUSED(event); + QPainter painter(this); +// painter.setRenderHint(QPainter::Antialiasing); + + QFont font; + painter.setFont(font); + QStyleOptionButton panel; + initStyleOption(&panel); + QRect r = style()->subElementRect(QStyle::SE_PushButtonFocusRect, &panel, this); + painter.setPen(Qt::gray); + + QRect rectSize(0, 0, sizeHint().width(), sizeHint().height()); + rectSize.moveCenter(r.center()); + r = rectSize; + r.adjust(0, 0, -1, -1); + if(underMouse() && !isDown()) + { + QRectF rr = r; + painter.drawRoundedRect(r, 3, 3); + QColor col(Qt::white); + col.setAlpha(80); + rr.adjust(1, 1, -1, -1); + painter.fillRect(rr, col); + } + if(isDown()) + { + QRectF rr = r; +// rr.adjust(1, 1, -1, -1); + painter.drawRoundedRect(rr, 3, 3); + QColor col(Qt::white); + col.setAlpha(80); + rr.adjust(1, 1, -1, -1); + painter.fillRect(rr, col); + } + painter.setPen(Qt::black); + painter.setBrush(Qt::black); + r.moveLeft(r.left() + 3); + font.setBold(true); + painter.setFont(font); + painter.drawText(r, Qt::AlignVCenter|Qt::TextSingleLine, text()); + + QImage image(":/icons/resource/downArrow.png"); + QRect rectDelta(0, 0, 7, 4); + rectDelta.moveRight(r.right() - 4); + rectDelta.moveCenter(QPoint(rectDelta.center().x(), r.center().y())); + painter.drawImage(rectDelta, image); +} + +QSize customPushButton::sizeHint() const +{ + QFont font; + font.setBold(true); + QFontMetrics fm(font); + int width = fm.width(text()); + if(width <= (160 - 8 - 9)) + return QSize(width+8+9, 18); + else + return QSize(160, 18); +} diff --git a/examples/GuiClient/customPushButton.h b/examples/GuiClient/customPushButton.h index 9eab8da0..c34974d3 100644 --- a/examples/GuiClient/customPushButton.h +++ b/examples/GuiClient/customPushButton.h @@ -1,41 +1,41 @@ -/* - * Copyright (C) 2008-2010 The QXmpp developers - * - * Author: - * Manjeet Dahiya - * - * Source: - * http://code.google.com/p/qxmpp - * - * This file is a part of QXmpp library. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - */ - - -#ifndef CUSTOMPUSHBUTTON_H -#define CUSTOMPUSHBUTTON_H - -#include -#include - -class customPushButton : public QPushButton -{ - Q_OBJECT - -public: - customPushButton(QWidget* parent = 0); - void paintEvent(QPaintEvent* event); - QSize sizeHint() const; -}; - -#endif // CUSTOMPUSHBUTTON_H +/* + * Copyright (C) 2008-2010 The QXmpp developers + * + * Author: + * Manjeet Dahiya + * + * Source: + * http://code.google.com/p/qxmpp + * + * This file is a part of QXmpp library. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + */ + + +#ifndef CUSTOMPUSHBUTTON_H +#define CUSTOMPUSHBUTTON_H + +#include +#include + +class customPushButton : public QPushButton +{ + Q_OBJECT + +public: + customPushButton(QWidget* parent = 0); + void paintEvent(QPaintEvent* event); + QSize sizeHint() const; +}; + +#endif // CUSTOMPUSHBUTTON_H diff --git a/examples/GuiClient/customToolButton.cpp b/examples/GuiClient/customToolButton.cpp index 5dfa4a08..f5e8018c 100644 --- a/examples/GuiClient/customToolButton.cpp +++ b/examples/GuiClient/customToolButton.cpp @@ -1,75 +1,75 @@ -/* - * Copyright (C) 2008-2010 The QXmpp developers - * - * Author: - * Manjeet Dahiya - * - * Source: - * http://code.google.com/p/qxmpp - * - * This file is a part of QXmpp library. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - */ - - -#include "customToolButton.h" -#include -#include -#include - -customToolButton::customToolButton(QWidget* parent) : QToolButton(parent) -{ - setMinimumSize(QSize(20, 18)); -} - -void customToolButton::paintEvent(QPaintEvent* event) -{ - Q_UNUSED(event); - QPainter painter(this); - QStyleOptionToolButton panel; - initStyleOption(&panel); - style()->drawPrimitive(QStyle::PE_PanelButtonTool, &panel, &painter, this); - QRect r = rect(); - QFont font; - painter.setFont(font); - painter.setPen(Qt::gray); - - QRect rectSize(0, 0, sizeHint().width(), sizeHint().height()); - rectSize.moveCenter(r.center()); - r = rectSize; - r.adjust(0, 0, -1, -1); - painter.setPen(Qt::black); - painter.setBrush(Qt::black); - r.moveLeft(r.left() + 3); - font.setBold(true); - painter.setFont(font); - painter.drawText(r, Qt::AlignVCenter|Qt::TextSingleLine, text()); - - QImage image(":/icons/resource/downArrow.png"); - QRect rectDelta(0, 0, 7, 4); - rectDelta.moveRight(r.right() - 4); - rectDelta.moveCenter(QPoint(rectDelta.center().x(), r.center().y())); - painter.drawImage(rectDelta, image); -} - -QSize customToolButton::sizeHint() const -{ - QFont font; - font.setBold(true); - QFontMetrics fm(font); - int width = fm.width(text()); - if(width <= (160 - 8 - 9)) - return QSize(width+8+9, 18); - else - return QSize(160, 18); -} +/* + * Copyright (C) 2008-2010 The QXmpp developers + * + * Author: + * Manjeet Dahiya + * + * Source: + * http://code.google.com/p/qxmpp + * + * This file is a part of QXmpp library. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + */ + + +#include "customToolButton.h" +#include +#include +#include + +customToolButton::customToolButton(QWidget* parent) : QToolButton(parent) +{ + setMinimumSize(QSize(20, 18)); +} + +void customToolButton::paintEvent(QPaintEvent* event) +{ + Q_UNUSED(event); + QPainter painter(this); + QStyleOptionToolButton panel; + initStyleOption(&panel); + style()->drawPrimitive(QStyle::PE_PanelButtonTool, &panel, &painter, this); + QRect r = rect(); + QFont font; + painter.setFont(font); + painter.setPen(Qt::gray); + + QRect rectSize(0, 0, sizeHint().width(), sizeHint().height()); + rectSize.moveCenter(r.center()); + r = rectSize; + r.adjust(0, 0, -1, -1); + painter.setPen(Qt::black); + painter.setBrush(Qt::black); + r.moveLeft(r.left() + 3); + font.setBold(true); + painter.setFont(font); + painter.drawText(r, Qt::AlignVCenter|Qt::TextSingleLine, text()); + + QImage image(":/icons/resource/downArrow.png"); + QRect rectDelta(0, 0, 7, 4); + rectDelta.moveRight(r.right() - 4); + rectDelta.moveCenter(QPoint(rectDelta.center().x(), r.center().y())); + painter.drawImage(rectDelta, image); +} + +QSize customToolButton::sizeHint() const +{ + QFont font; + font.setBold(true); + QFontMetrics fm(font); + int width = fm.width(text()); + if(width <= (160 - 8 - 9)) + return QSize(width+8+9, 18); + else + return QSize(160, 18); +} diff --git a/examples/GuiClient/customToolButton.h b/examples/GuiClient/customToolButton.h index 9eae4d59..0fd3d958 100644 --- a/examples/GuiClient/customToolButton.h +++ b/examples/GuiClient/customToolButton.h @@ -1,38 +1,38 @@ -/* - * Copyright (C) 2008-2010 The QXmpp developers - * - * Author: - * Manjeet Dahiya - * - * Source: - * http://code.google.com/p/qxmpp - * - * This file is a part of QXmpp library. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - */ - - -#ifndef CUSTOMTOOLBUTTON_H -#define CUSTOMTOOLBUTTON_H - -#include - -class customToolButton : public QToolButton -{ -public: - customToolButton(QWidget* parent = 0); - void paintEvent(QPaintEvent* event); - QSize sizeHint() const; -}; - -#endif // CUSTOMTOOLBUTTON_H +/* + * Copyright (C) 2008-2010 The QXmpp developers + * + * Author: + * Manjeet Dahiya + * + * Source: + * http://code.google.com/p/qxmpp + * + * This file is a part of QXmpp library. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + */ + + +#ifndef CUSTOMTOOLBUTTON_H +#define CUSTOMTOOLBUTTON_H + +#include + +class customToolButton : public QToolButton +{ +public: + customToolButton(QWidget* parent = 0); + void paintEvent(QPaintEvent* event); + QSize sizeHint() const; +}; + +#endif // CUSTOMTOOLBUTTON_H diff --git a/examples/GuiClient/main.cpp b/examples/GuiClient/main.cpp index 9769e2de..e5cf7e04 100644 --- a/examples/GuiClient/main.cpp +++ b/examples/GuiClient/main.cpp @@ -1,44 +1,44 @@ -/* - * Copyright (C) 2008-2010 The QXmpp developers - * - * Author: - * Manjeet Dahiya - * - * Source: - * http://code.google.com/p/qxmpp - * - * This file is a part of QXmpp library. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - */ - - -#include -#include -#include "chatDialog.h" -#include "chatGraphicsView.h" -#include "chatGraphicsScene.h" -#include "mainDialog.h" -#include "statusTextWidget.h" -#include "utils.h" - -int main(int argc, char *argv[]) -{ - QDir dir; - if(!dir.exists(getSettingsDir())) - dir.mkpath(getSettingsDir()); - - QApplication a(argc, argv); - mainDialog cw; - cw.show(); - return a.exec(); -} +/* + * Copyright (C) 2008-2010 The QXmpp developers + * + * Author: + * Manjeet Dahiya + * + * Source: + * http://code.google.com/p/qxmpp + * + * This file is a part of QXmpp library. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + */ + + +#include +#include +#include "chatDialog.h" +#include "chatGraphicsView.h" +#include "chatGraphicsScene.h" +#include "mainDialog.h" +#include "statusTextWidget.h" +#include "utils.h" + +int main(int argc, char *argv[]) +{ + QDir dir; + if(!dir.exists(getSettingsDir())) + dir.mkpath(getSettingsDir()); + + QApplication a(argc, argv); + mainDialog cw; + cw.show(); + return a.exec(); +} diff --git a/examples/GuiClient/mainDialog.cpp b/examples/GuiClient/mainDialog.cpp index 8cd5e75e..8d68d338 100644 --- a/examples/GuiClient/mainDialog.cpp +++ b/examples/GuiClient/mainDialog.cpp @@ -1,474 +1,474 @@ -/* - * Copyright (C) 2008-2010 The QXmpp developers - * - * Author: - * Manjeet Dahiya - * - * Source: - * http://code.google.com/p/qxmpp - * - * This file is a part of QXmpp library. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - */ - - -#include "mainDialog.h" -#include "ui_mainDialog.h" -#include "QXmppRosterManager.h" -#include "QXmppPresence.h" -#include "QXmppMessage.h" -#include "QXmppUtils.h" -#include "utils.h" -#include "QXmppReconnectionManager.h" -#include "QXmppVCardManager.h" -#include "QXmppLogger.h" -#include "QXmppVCardIq.h" -#include "QXmppRosterManager.h" -#include "QXmppRosterIq.h" - -#include "profileDialog.h" - -#include - -mainDialog::mainDialog(QWidget *parent): QDialog(parent, Qt::Window), - ui(new Ui::mainDialogClass), m_rosterItemModel(this), - m_rosterItemSortFilterModel(this), m_vCardManager(&m_xmppClient) -{ - ui->setupUi(this); - ui->pushButton_cancel->setDisabled(true); - ui->label_throbber->setMovie(new QMovie(":/icons/resource/ajax-loader.gif")); - ui->label_throbber->movie()->start(); - showSignInPage(); - - bool check = connect(&m_xmppClient.rosterManager(), - SIGNAL(rosterReceived()), - this, SLOT(rosterReceived())); - - check = connect(&m_xmppClient.rosterManager(), - SIGNAL(rosterChanged(const QString&)), - this, SLOT(rosterChanged(const QString&))); - Q_ASSERT(check); - - QXmppLogger::getLogger()->setLoggingType(QXmppLogger::FileLogging); - - - check = connect(&m_xmppClient.rosterManager(), - SIGNAL(presenceChanged(const QString&, const QString&)), - this, SLOT(presenceChanged(const QString&, const QString&))); - Q_ASSERT(check); - - check = connect(ui->pushButton_view, SIGNAL(clicked()), this, SLOT(sort())); - Q_ASSERT(check); - - check = connect(ui->lineEdit_filter, SIGNAL(textChanged(const QString&)), - this, SLOT(filterChanged(const QString&))); - Q_ASSERT(check); - - check = connect(ui->listView, SIGNAL(showChatDialog(const QString&)), - this, SLOT(showChatDialog(const QString&))); - Q_ASSERT(check); - - check = connect(ui->listView, SIGNAL(showProfile(const QString&)), - this, SLOT(showProfile(const QString&))); - Q_ASSERT(check); - - check = connect(&m_xmppClient, SIGNAL(messageReceived(const QXmppMessage&)), - SLOT(messageReceived(const QXmppMessage&))); - Q_ASSERT(check); - - check = connect(ui->pushButton_signIn, SIGNAL(clicked(bool)), SLOT(signIn())); - Q_ASSERT(check); - - check = connect(ui->pushButton_cancel, SIGNAL(clicked(bool)), - SLOT(cancelSignIn())); - Q_ASSERT(check); - - m_rosterItemSortFilterModel.setSourceModel(&m_rosterItemModel); - ui->listView->setModel(&m_rosterItemSortFilterModel); - sort(); - - ItemDelegate *delegate = new ItemDelegate(); - ui->listView->setItemDelegate(delegate); - ui->listView->setFocus(); - ui->verticalLayout_3->insertWidget(0, &m_statusWidget); - - check = connect(&m_statusWidget, SIGNAL(statusTextChanged(const QString&)), - SLOT(statusTextChanged(const QString&))); - Q_ASSERT(check); - check = connect(&m_statusWidget, SIGNAL(presenceTypeChanged(QXmppPresence::Type)), - SLOT(presenceTypeChanged(QXmppPresence::Type))); - Q_ASSERT(check); - check = connect(&m_statusWidget, - SIGNAL(presenceStatusTypeChanged(QXmppPresence::Status::Type)), - SLOT(presenceStatusTypeChanged(QXmppPresence::Status::Type))); - Q_ASSERT(check); - check = connect(&m_statusWidget, - SIGNAL(avatarChanged(const QImage&)), - SLOT(avatarChanged(const QImage&))); - Q_ASSERT(check); - - check = connect(&m_xmppClient, SIGNAL(connected()), SLOT(updateStatusWidget())); - Q_ASSERT(check); - - check = connect(&m_xmppClient, SIGNAL(connected()), SLOT(showRosterPage())); - Q_ASSERT(check); - - check = connect(m_xmppClient.reconnectionManager(), - SIGNAL(reconnectingIn(int)), - SLOT(showSignInPageForAutoReconnection(int))); - Q_ASSERT(check); - - check = connect(m_xmppClient.reconnectionManager(), - SIGNAL(reconnectingNow()), - SLOT(showSignInPageForAutoReconnectionNow())); - Q_ASSERT(check); - - check = connect(&m_xmppClient.vCardManager(), - SIGNAL(vCardReceived(const QXmppVCardIq&)), &m_vCardManager, - SLOT(vCardReceived(const QXmppVCardIq&))); - Q_ASSERT(check); - - check = connect(&m_vCardManager, - SIGNAL(vCardReadyToUse(const QString&)), - SLOT(updateVCard(const QString&))); - Q_ASSERT(check); -} - -void mainDialog::rosterChanged(const QString& bareJid) -{ - m_rosterItemModel.updateRosterEntry(bareJid, m_xmppClient.rosterManager(). - getRosterEntry(bareJid)); - - bool check = m_vCardManager.isVCardAvailable(bareJid); - if(check) - { - updateVCard(bareJid); - } - else - { - m_vCardManager.requestVCard(bareJid); - } -} - -void mainDialog::rosterReceived() -{ - QStringList list = m_xmppClient.rosterManager().getRosterBareJids(); - QString bareJid; - foreach(bareJid, list) - rosterChanged(bareJid); -} - -void mainDialog::presenceChanged(const QString& bareJid, const QString& resource) -{ - if(bareJid == m_xmppClient.configuration().jidBare()) - return; - - if(!m_rosterItemModel.getRosterItemFromBareJid(bareJid)) - return; - - QMap presences = m_xmppClient.rosterManager(). - getAllPresencesForBareJid(bareJid); - m_rosterItemModel.updatePresence(bareJid, presences); - -// QXmppPresence::Type presenceType = presences.begin().value().getType(); - -// if(!m_vCardManager.isVCardAvailable(bareJid) && -// presenceType == QXmppPresence::Available) -// { -// m_rosterItemModel.updateAvatar(bareJid, -// m_vCardManager.getVCard(bareJid).image); -// } -} - -void mainDialog::sort() -{ - m_rosterItemSortFilterModel.sort(0); -} - -void mainDialog::filterChanged(const QString& filter) -{ - m_rosterItemSortFilterModel.setFilterRegExp(filter); - ui->listView->selectionModel()->select(ui->listView->model()->index(0, 0), - QItemSelectionModel::ClearAndSelect); -} - -void mainDialog::keyPressEvent(QKeyEvent* event1) -{ - if(ui->stackedWidget->currentIndex() == 1) // sign in page - { - QDialog::keyPressEvent(event1); - return; - } - - if(event1->matches(QKeySequence::Find) ||( - event1->key() <= Qt::Key_9 && event1->key() >= Qt::Key_1) || - (event1->key() <= Qt::Key_Z && event1->key() >= Qt::Key_At) || - event1->key() == Qt::Key_Backspace) - { - ui->lineEdit_filter->setFocus(); - ui->lineEdit_filter->event(event1); - } - else if(event1->key() == Qt::Key_Escape) - { - ui->lineEdit_filter->clear(); - ui->listView->setFocus(); - } - else if(event1->key() == Qt::Key_Up || - event1->key() == Qt::Key_Down || - event1->key() == Qt::Key_PageUp || - event1->key() == Qt::Key_PageDown) - { - ui->listView->setFocus(); - ui->listView->event(event1); - } - else if(event1->key() == Qt::Key_Return && ui->listView->hasFocus()) - { - ui->listView->event(event1); - } -} - -chatDialog* mainDialog::getChatDialog(const QString& bareJid) -{ - if(!m_chatDlgsList.contains(bareJid)) - { - m_chatDlgsList[bareJid] = new chatDialog(); - m_chatDlgsList[bareJid]->setBareJid(bareJid); - - if(!m_rosterItemModel.getRosterItemFromBareJid(bareJid)) - return 0; - - if(!m_rosterItemModel.getRosterItemFromBareJid(bareJid)-> - getName().isEmpty()) - m_chatDlgsList[bareJid]->setDisplayName(m_rosterItemModel. - getRosterItemFromBareJid(bareJid)->getName()); - else - m_chatDlgsList[bareJid]->setDisplayName(jidToUser(bareJid)); - - m_chatDlgsList[bareJid]->setQXmppClient(&m_xmppClient); - } - - return m_chatDlgsList[bareJid]; -} - -void mainDialog::showChatDialog(const QString& bareJid) -{ - if(!bareJid.isEmpty()) - getChatDialog(bareJid)->show(); -} - -void mainDialog::messageReceived(const QXmppMessage& msg) -{ - QString from = msg.from(); - getChatDialog(jidToBareJid(from))->show(); - getChatDialog(jidToBareJid(from))->messageReceived(msg.body()); -} - -void mainDialog::statusTextChanged(const QString& status) -{ - QXmppPresence presence = m_xmppClient.clientPresence(); - presence.status().setStatusText(status); - m_xmppClient.setClientPresence(presence); -} - -void mainDialog::presenceTypeChanged(QXmppPresence::Type presenceType) -{ - if(presenceType == QXmppPresence::Unavailable) - { - m_xmppClient.disconnectFromServer(); - showSignInPageAfterUserDisconnection(); - } - else - { - QXmppPresence newPresence = m_xmppClient.clientPresence(); - newPresence.setType(presenceType); - m_xmppClient.setClientPresence(newPresence); - } - m_statusWidget.setStatusText( - presenceToStatusText(m_xmppClient.clientPresence())); -} - -void mainDialog::presenceStatusTypeChanged(QXmppPresence::Status::Type statusType) -{ - QXmppPresence presence = m_xmppClient.clientPresence(); - if(statusType == QXmppPresence::Status::Offline) - presence.setType(QXmppPresence::Unavailable); - else - presence.setType(QXmppPresence::Available); - presence.status().setType(statusType); - m_xmppClient.setClientPresence(presence); -} - -void mainDialog::avatarChanged(const QImage& image) -{ - QXmppVCardIq vcard; - vcard.setType(QXmppIq::Set); - - QByteArray ba; - QBuffer buffer(&ba); - buffer.open(QIODevice::WriteOnly); - image.save(&buffer, "PNG"); - vcard.setPhoto(ba); - - m_xmppClient.sendPacket(vcard); - m_statusWidget.setAvatar(image); -} - -void mainDialog::updateStatusWidget() -{ - // fetch selfVCard - m_xmppClient.vCardManager().requestVCard(); - - m_statusWidget.setDisplayName(m_xmppClient.configuration().jidBare()); - m_statusWidget.setStatusText(presenceToStatusText(m_xmppClient.clientPresence())); - m_statusWidget.setPresenceAndStatusType(m_xmppClient.clientPresence().type(), - m_xmppClient.clientPresence().status().type()); -} - -void mainDialog::signIn() -{ - ui->label_throbber->show(); - ui->pushButton_signIn->setDisabled(true); - ui->pushButton_cancel->setDisabled(false); - ui->lineEdit_userName->setDisabled(true); - ui->lineEdit_password->setDisabled(true); - ui->checkBox->setDisabled(true); - showLoginStatusWithProgress("Connecting"); - - QString bareJid = ui->lineEdit_userName->text(); - QString passwd = ui->lineEdit_password->text(); - - m_xmppClient.configuration().setJid(bareJid); - m_xmppClient.configuration().setPassword(passwd); - - m_rosterItemModel.clear(); - - m_vCardManager.loadAllFromCache(); - - startConnection(); -} - -void mainDialog::cancelSignIn() -{ - ui->label_throbber->hide(); - m_xmppClient.reconnectionManager()->cancelReconnection(); - m_xmppClient.disconnectFromServer(); - showSignInPage(); - showLoginStatus("Sign in cancelled"); -} - -void mainDialog::showSignInPage() -{ - ui->label_throbber->hide(); - ui->pushButton_signIn->setDisabled(false); - ui->pushButton_cancel->setDisabled(true); - ui->lineEdit_userName->setDisabled(false); - ui->lineEdit_password->setDisabled(false); - ui->checkBox->setDisabled(false); - ui->stackedWidget->setCurrentIndex(1); -} - -void mainDialog::showSignInPageAfterUserDisconnection() -{ - ui->label_throbber->hide(); - showLoginStatus("Disconnected"); - showSignInPage(); -} - -void mainDialog::showSignInPageForAutoReconnection(int i) -{ - ui->label_throbber->hide(); - ui->pushButton_signIn->setDisabled(true); - ui->pushButton_cancel->setDisabled(false); - ui->lineEdit_userName->setDisabled(true); - ui->lineEdit_password->setDisabled(true); - ui->checkBox->setDisabled(true); - showLoginStatusWithCounter(QString("Reconnecting in %1 sec..."), i); - ui->stackedWidget->setCurrentIndex(1); -} - -void mainDialog::showSignInPageForAutoReconnectionNow() -{ - ui->label_throbber->show(); - ui->pushButton_signIn->setDisabled(true); - ui->pushButton_cancel->setDisabled(false); - ui->lineEdit_userName->setDisabled(true); - ui->lineEdit_password->setDisabled(true); - ui->checkBox->setDisabled(true); - showLoginStatusWithProgress(QString("Connecting")); - ui->stackedWidget->setCurrentIndex(1); -} - -void mainDialog::showRosterPage() -{ - ui->stackedWidget->setCurrentIndex(0); -} - -void mainDialog::startConnection() -{ -// m_xmppClient.setClientPresence(QXmppPresence()); - m_xmppClient.connectToServer(m_xmppClient.configuration()); -} - -void mainDialog::showLoginStatus(const QString& msg) -{ - ui->label_status->setCustomText(msg, customLabel::None); -} - -void mainDialog::showLoginStatusWithProgress(const QString& msg) -{ - ui->label_status->setCustomText(msg, customLabel::WithProgressEllipsis); -} - -void mainDialog::showLoginStatusWithCounter(const QString& msg, int time) -{ - ui->label_status->setCustomText(msg, customLabel::CountDown, time); -} - -void mainDialog::updateVCard(const QString& bareJid) -{ - if(bareJid != m_xmppClient.configuration().jidBare()) - { - m_rosterItemModel.updateAvatar(bareJid, - m_vCardManager.getAvatar(bareJid)); - m_rosterItemModel.updateName(bareJid, m_vCardManager.getVCard(bareJid).fullName()); - } - else - { - if(m_vCardManager.getSelfFullName().isEmpty()) - m_statusWidget.setDisplayName(m_xmppClient.configuration().jidBare()); - else - m_statusWidget.setDisplayName(m_vCardManager.getSelfFullName()); - - m_statusWidget.setAvatar(m_vCardManager.getAvatar(bareJid)); - } -} - -void mainDialog::showProfile(const QString& bareJid) -{ - if(bareJid.isEmpty()) - return; - - profileDialog dlg(this, bareJid, m_xmppClient); - dlg.setBareJid(bareJid); - // TODO use original image - if(!m_vCardManager.getAvatar(bareJid).isNull()) - dlg.setAvatar(m_vCardManager.getAvatar(bareJid)); - QStringList resources = m_xmppClient.rosterManager().getResources(bareJid); - - dlg.setFullName(m_vCardManager.getVCard(bareJid).fullName()); - - if(m_vCardManager.getVCard(bareJid).fullName().isEmpty()) - dlg.setFullName(m_xmppClient.rosterManager().getRosterEntry(bareJid).name()); - - dlg.exec(); -} +/* + * Copyright (C) 2008-2010 The QXmpp developers + * + * Author: + * Manjeet Dahiya + * + * Source: + * http://code.google.com/p/qxmpp + * + * This file is a part of QXmpp library. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + */ + + +#include "mainDialog.h" +#include "ui_mainDialog.h" +#include "QXmppRosterManager.h" +#include "QXmppPresence.h" +#include "QXmppMessage.h" +#include "QXmppUtils.h" +#include "utils.h" +#include "QXmppReconnectionManager.h" +#include "QXmppVCardManager.h" +#include "QXmppLogger.h" +#include "QXmppVCardIq.h" +#include "QXmppRosterManager.h" +#include "QXmppRosterIq.h" + +#include "profileDialog.h" + +#include + +mainDialog::mainDialog(QWidget *parent): QDialog(parent, Qt::Window), + ui(new Ui::mainDialogClass), m_rosterItemModel(this), + m_rosterItemSortFilterModel(this), m_vCardManager(&m_xmppClient) +{ + ui->setupUi(this); + ui->pushButton_cancel->setDisabled(true); + ui->label_throbber->setMovie(new QMovie(":/icons/resource/ajax-loader.gif")); + ui->label_throbber->movie()->start(); + showSignInPage(); + + bool check = connect(&m_xmppClient.rosterManager(), + SIGNAL(rosterReceived()), + this, SLOT(rosterReceived())); + + check = connect(&m_xmppClient.rosterManager(), + SIGNAL(rosterChanged(const QString&)), + this, SLOT(rosterChanged(const QString&))); + Q_ASSERT(check); + + QXmppLogger::getLogger()->setLoggingType(QXmppLogger::FileLogging); + + + check = connect(&m_xmppClient.rosterManager(), + SIGNAL(presenceChanged(const QString&, const QString&)), + this, SLOT(presenceChanged(const QString&, const QString&))); + Q_ASSERT(check); + + check = connect(ui->pushButton_view, SIGNAL(clicked()), this, SLOT(sort())); + Q_ASSERT(check); + + check = connect(ui->lineEdit_filter, SIGNAL(textChanged(const QString&)), + this, SLOT(filterChanged(const QString&))); + Q_ASSERT(check); + + check = connect(ui->listView, SIGNAL(showChatDialog(const QString&)), + this, SLOT(showChatDialog(const QString&))); + Q_ASSERT(check); + + check = connect(ui->listView, SIGNAL(showProfile(const QString&)), + this, SLOT(showProfile(const QString&))); + Q_ASSERT(check); + + check = connect(&m_xmppClient, SIGNAL(messageReceived(const QXmppMessage&)), + SLOT(messageReceived(const QXmppMessage&))); + Q_ASSERT(check); + + check = connect(ui->pushButton_signIn, SIGNAL(clicked(bool)), SLOT(signIn())); + Q_ASSERT(check); + + check = connect(ui->pushButton_cancel, SIGNAL(clicked(bool)), + SLOT(cancelSignIn())); + Q_ASSERT(check); + + m_rosterItemSortFilterModel.setSourceModel(&m_rosterItemModel); + ui->listView->setModel(&m_rosterItemSortFilterModel); + sort(); + + ItemDelegate *delegate = new ItemDelegate(); + ui->listView->setItemDelegate(delegate); + ui->listView->setFocus(); + ui->verticalLayout_3->insertWidget(0, &m_statusWidget); + + check = connect(&m_statusWidget, SIGNAL(statusTextChanged(const QString&)), + SLOT(statusTextChanged(const QString&))); + Q_ASSERT(check); + check = connect(&m_statusWidget, SIGNAL(presenceTypeChanged(QXmppPresence::Type)), + SLOT(presenceTypeChanged(QXmppPresence::Type))); + Q_ASSERT(check); + check = connect(&m_statusWidget, + SIGNAL(presenceStatusTypeChanged(QXmppPresence::Status::Type)), + SLOT(presenceStatusTypeChanged(QXmppPresence::Status::Type))); + Q_ASSERT(check); + check = connect(&m_statusWidget, + SIGNAL(avatarChanged(const QImage&)), + SLOT(avatarChanged(const QImage&))); + Q_ASSERT(check); + + check = connect(&m_xmppClient, SIGNAL(connected()), SLOT(updateStatusWidget())); + Q_ASSERT(check); + + check = connect(&m_xmppClient, SIGNAL(connected()), SLOT(showRosterPage())); + Q_ASSERT(check); + + check = connect(m_xmppClient.reconnectionManager(), + SIGNAL(reconnectingIn(int)), + SLOT(showSignInPageForAutoReconnection(int))); + Q_ASSERT(check); + + check = connect(m_xmppClient.reconnectionManager(), + SIGNAL(reconnectingNow()), + SLOT(showSignInPageForAutoReconnectionNow())); + Q_ASSERT(check); + + check = connect(&m_xmppClient.vCardManager(), + SIGNAL(vCardReceived(const QXmppVCardIq&)), &m_vCardManager, + SLOT(vCardReceived(const QXmppVCardIq&))); + Q_ASSERT(check); + + check = connect(&m_vCardManager, + SIGNAL(vCardReadyToUse(const QString&)), + SLOT(updateVCard(const QString&))); + Q_ASSERT(check); +} + +void mainDialog::rosterChanged(const QString& bareJid) +{ + m_rosterItemModel.updateRosterEntry(bareJid, m_xmppClient.rosterManager(). + getRosterEntry(bareJid)); + + bool check = m_vCardManager.isVCardAvailable(bareJid); + if(check) + { + updateVCard(bareJid); + } + else + { + m_vCardManager.requestVCard(bareJid); + } +} + +void mainDialog::rosterReceived() +{ + QStringList list = m_xmppClient.rosterManager().getRosterBareJids(); + QString bareJid; + foreach(bareJid, list) + rosterChanged(bareJid); +} + +void mainDialog::presenceChanged(const QString& bareJid, const QString& resource) +{ + if(bareJid == m_xmppClient.configuration().jidBare()) + return; + + if(!m_rosterItemModel.getRosterItemFromBareJid(bareJid)) + return; + + QMap presences = m_xmppClient.rosterManager(). + getAllPresencesForBareJid(bareJid); + m_rosterItemModel.updatePresence(bareJid, presences); + +// QXmppPresence::Type presenceType = presences.begin().value().getType(); + +// if(!m_vCardManager.isVCardAvailable(bareJid) && +// presenceType == QXmppPresence::Available) +// { +// m_rosterItemModel.updateAvatar(bareJid, +// m_vCardManager.getVCard(bareJid).image); +// } +} + +void mainDialog::sort() +{ + m_rosterItemSortFilterModel.sort(0); +} + +void mainDialog::filterChanged(const QString& filter) +{ + m_rosterItemSortFilterModel.setFilterRegExp(filter); + ui->listView->selectionModel()->select(ui->listView->model()->index(0, 0), + QItemSelectionModel::ClearAndSelect); +} + +void mainDialog::keyPressEvent(QKeyEvent* event1) +{ + if(ui->stackedWidget->currentIndex() == 1) // sign in page + { + QDialog::keyPressEvent(event1); + return; + } + + if(event1->matches(QKeySequence::Find) ||( + event1->key() <= Qt::Key_9 && event1->key() >= Qt::Key_1) || + (event1->key() <= Qt::Key_Z && event1->key() >= Qt::Key_At) || + event1->key() == Qt::Key_Backspace) + { + ui->lineEdit_filter->setFocus(); + ui->lineEdit_filter->event(event1); + } + else if(event1->key() == Qt::Key_Escape) + { + ui->lineEdit_filter->clear(); + ui->listView->setFocus(); + } + else if(event1->key() == Qt::Key_Up || + event1->key() == Qt::Key_Down || + event1->key() == Qt::Key_PageUp || + event1->key() == Qt::Key_PageDown) + { + ui->listView->setFocus(); + ui->listView->event(event1); + } + else if(event1->key() == Qt::Key_Return && ui->listView->hasFocus()) + { + ui->listView->event(event1); + } +} + +chatDialog* mainDialog::getChatDialog(const QString& bareJid) +{ + if(!m_chatDlgsList.contains(bareJid)) + { + m_chatDlgsList[bareJid] = new chatDialog(); + m_chatDlgsList[bareJid]->setBareJid(bareJid); + + if(!m_rosterItemModel.getRosterItemFromBareJid(bareJid)) + return 0; + + if(!m_rosterItemModel.getRosterItemFromBareJid(bareJid)-> + getName().isEmpty()) + m_chatDlgsList[bareJid]->setDisplayName(m_rosterItemModel. + getRosterItemFromBareJid(bareJid)->getName()); + else + m_chatDlgsList[bareJid]->setDisplayName(jidToUser(bareJid)); + + m_chatDlgsList[bareJid]->setQXmppClient(&m_xmppClient); + } + + return m_chatDlgsList[bareJid]; +} + +void mainDialog::showChatDialog(const QString& bareJid) +{ + if(!bareJid.isEmpty()) + getChatDialog(bareJid)->show(); +} + +void mainDialog::messageReceived(const QXmppMessage& msg) +{ + QString from = msg.from(); + getChatDialog(jidToBareJid(from))->show(); + getChatDialog(jidToBareJid(from))->messageReceived(msg.body()); +} + +void mainDialog::statusTextChanged(const QString& status) +{ + QXmppPresence presence = m_xmppClient.clientPresence(); + presence.status().setStatusText(status); + m_xmppClient.setClientPresence(presence); +} + +void mainDialog::presenceTypeChanged(QXmppPresence::Type presenceType) +{ + if(presenceType == QXmppPresence::Unavailable) + { + m_xmppClient.disconnectFromServer(); + showSignInPageAfterUserDisconnection(); + } + else + { + QXmppPresence newPresence = m_xmppClient.clientPresence(); + newPresence.setType(presenceType); + m_xmppClient.setClientPresence(newPresence); + } + m_statusWidget.setStatusText( + presenceToStatusText(m_xmppClient.clientPresence())); +} + +void mainDialog::presenceStatusTypeChanged(QXmppPresence::Status::Type statusType) +{ + QXmppPresence presence = m_xmppClient.clientPresence(); + if(statusType == QXmppPresence::Status::Offline) + presence.setType(QXmppPresence::Unavailable); + else + presence.setType(QXmppPresence::Available); + presence.status().setType(statusType); + m_xmppClient.setClientPresence(presence); +} + +void mainDialog::avatarChanged(const QImage& image) +{ + QXmppVCardIq vcard; + vcard.setType(QXmppIq::Set); + + QByteArray ba; + QBuffer buffer(&ba); + buffer.open(QIODevice::WriteOnly); + image.save(&buffer, "PNG"); + vcard.setPhoto(ba); + + m_xmppClient.sendPacket(vcard); + m_statusWidget.setAvatar(image); +} + +void mainDialog::updateStatusWidget() +{ + // fetch selfVCard + m_xmppClient.vCardManager().requestVCard(); + + m_statusWidget.setDisplayName(m_xmppClient.configuration().jidBare()); + m_statusWidget.setStatusText(presenceToStatusText(m_xmppClient.clientPresence())); + m_statusWidget.setPresenceAndStatusType(m_xmppClient.clientPresence().type(), + m_xmppClient.clientPresence().status().type()); +} + +void mainDialog::signIn() +{ + ui->label_throbber->show(); + ui->pushButton_signIn->setDisabled(true); + ui->pushButton_cancel->setDisabled(false); + ui->lineEdit_userName->setDisabled(true); + ui->lineEdit_password->setDisabled(true); + ui->checkBox->setDisabled(true); + showLoginStatusWithProgress("Connecting"); + + QString bareJid = ui->lineEdit_userName->text(); + QString passwd = ui->lineEdit_password->text(); + + m_xmppClient.configuration().setJid(bareJid); + m_xmppClient.configuration().setPassword(passwd); + + m_rosterItemModel.clear(); + + m_vCardManager.loadAllFromCache(); + + startConnection(); +} + +void mainDialog::cancelSignIn() +{ + ui->label_throbber->hide(); + m_xmppClient.reconnectionManager()->cancelReconnection(); + m_xmppClient.disconnectFromServer(); + showSignInPage(); + showLoginStatus("Sign in cancelled"); +} + +void mainDialog::showSignInPage() +{ + ui->label_throbber->hide(); + ui->pushButton_signIn->setDisabled(false); + ui->pushButton_cancel->setDisabled(true); + ui->lineEdit_userName->setDisabled(false); + ui->lineEdit_password->setDisabled(false); + ui->checkBox->setDisabled(false); + ui->stackedWidget->setCurrentIndex(1); +} + +void mainDialog::showSignInPageAfterUserDisconnection() +{ + ui->label_throbber->hide(); + showLoginStatus("Disconnected"); + showSignInPage(); +} + +void mainDialog::showSignInPageForAutoReconnection(int i) +{ + ui->label_throbber->hide(); + ui->pushButton_signIn->setDisabled(true); + ui->pushButton_cancel->setDisabled(false); + ui->lineEdit_userName->setDisabled(true); + ui->lineEdit_password->setDisabled(true); + ui->checkBox->setDisabled(true); + showLoginStatusWithCounter(QString("Reconnecting in %1 sec..."), i); + ui->stackedWidget->setCurrentIndex(1); +} + +void mainDialog::showSignInPageForAutoReconnectionNow() +{ + ui->label_throbber->show(); + ui->pushButton_signIn->setDisabled(true); + ui->pushButton_cancel->setDisabled(false); + ui->lineEdit_userName->setDisabled(true); + ui->lineEdit_password->setDisabled(true); + ui->checkBox->setDisabled(true); + showLoginStatusWithProgress(QString("Connecting")); + ui->stackedWidget->setCurrentIndex(1); +} + +void mainDialog::showRosterPage() +{ + ui->stackedWidget->setCurrentIndex(0); +} + +void mainDialog::startConnection() +{ +// m_xmppClient.setClientPresence(QXmppPresence()); + m_xmppClient.connectToServer(m_xmppClient.configuration()); +} + +void mainDialog::showLoginStatus(const QString& msg) +{ + ui->label_status->setCustomText(msg, customLabel::None); +} + +void mainDialog::showLoginStatusWithProgress(const QString& msg) +{ + ui->label_status->setCustomText(msg, customLabel::WithProgressEllipsis); +} + +void mainDialog::showLoginStatusWithCounter(const QString& msg, int time) +{ + ui->label_status->setCustomText(msg, customLabel::CountDown, time); +} + +void mainDialog::updateVCard(const QString& bareJid) +{ + if(bareJid != m_xmppClient.configuration().jidBare()) + { + m_rosterItemModel.updateAvatar(bareJid, + m_vCardManager.getAvatar(bareJid)); + m_rosterItemModel.updateName(bareJid, m_vCardManager.getVCard(bareJid).fullName()); + } + else + { + if(m_vCardManager.getSelfFullName().isEmpty()) + m_statusWidget.setDisplayName(m_xmppClient.configuration().jidBare()); + else + m_statusWidget.setDisplayName(m_vCardManager.getSelfFullName()); + + m_statusWidget.setAvatar(m_vCardManager.getAvatar(bareJid)); + } +} + +void mainDialog::showProfile(const QString& bareJid) +{ + if(bareJid.isEmpty()) + return; + + profileDialog dlg(this, bareJid, m_xmppClient); + dlg.setBareJid(bareJid); + // TODO use original image + if(!m_vCardManager.getAvatar(bareJid).isNull()) + dlg.setAvatar(m_vCardManager.getAvatar(bareJid)); + QStringList resources = m_xmppClient.rosterManager().getResources(bareJid); + + dlg.setFullName(m_vCardManager.getVCard(bareJid).fullName()); + + if(m_vCardManager.getVCard(bareJid).fullName().isEmpty()) + dlg.setFullName(m_xmppClient.rosterManager().getRosterEntry(bareJid).name()); + + dlg.exec(); +} diff --git a/examples/GuiClient/mainDialog.h b/examples/GuiClient/mainDialog.h index 4cc85aa6..edb56ce5 100644 --- a/examples/GuiClient/mainDialog.h +++ b/examples/GuiClient/mainDialog.h @@ -1,94 +1,94 @@ -/* - * Copyright (C) 2008-2010 The QXmpp developers - * - * Author: - * Manjeet Dahiya - * - * Source: - * http://code.google.com/p/qxmpp - * - * This file is a part of QXmpp library. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - */ - - -#ifndef MAINDIALOG_H -#define MAINDIALOG_H - -#include -#include "QXmppClient.h" -#include "rosterItemModel.h" -#include "rosterItemSortFilterProxyModel.h" -#include -#include -#include "statusWidget.h" -#include "chatDialog.h" -#include "vCardManager.h" - -namespace Ui -{ - class mainDialogClass; -} - -class mainDialog : public QDialog -{ - Q_OBJECT - -public: - mainDialog(QWidget *parent = 0); - -protected: - void keyPressEvent(QKeyEvent*); - -private slots: - void rosterChanged(const QString& bareJid); - void rosterReceived(); - void presenceChanged(const QString&, const QString&); - void sort(); - void filterChanged(const QString& filter); - void showChatDialog(const QString& bareJid); - void messageReceived(const QXmppMessage& msg); - void statusTextChanged(const QString&); - void presenceTypeChanged(QXmppPresence::Type); - void presenceStatusTypeChanged(QXmppPresence::Status::Type); - void signIn(); - void cancelSignIn(); - void showSignInPage(); - void showSignInPageAfterUserDisconnection(); - void showSignInPageForAutoReconnection(int); - void showSignInPageForAutoReconnectionNow(); - void showRosterPage(); - void startConnection(); - void updateStatusWidget(); - void showLoginStatusWithProgress(const QString& msg); - void showLoginStatus(const QString& msg); - void showLoginStatusWithCounter(const QString& msg, int time); - void updateVCard(const QString& bareJid); - void avatarChanged(const QImage&); - void showProfile(const QString& bareJid); - -private: - chatDialog* getChatDialog(const QString& bareJid); - - Ui::mainDialogClass* ui; - QXmppClient m_xmppClient; - rosterItemModel m_rosterItemModel; - rosterItemSortFilterProxyModel m_rosterItemSortFilterModel; - statusWidget m_statusWidget; - vCardManager m_vCardManager; - - // map of bare jids and respective chatdlg - QMap m_chatDlgsList; -}; - -#endif // MAINDIALOG_H +/* + * Copyright (C) 2008-2010 The QXmpp developers + * + * Author: + * Manjeet Dahiya + * + * Source: + * http://code.google.com/p/qxmpp + * + * This file is a part of QXmpp library. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + */ + + +#ifndef MAINDIALOG_H +#define MAINDIALOG_H + +#include +#include "QXmppClient.h" +#include "rosterItemModel.h" +#include "rosterItemSortFilterProxyModel.h" +#include +#include +#include "statusWidget.h" +#include "chatDialog.h" +#include "vCardManager.h" + +namespace Ui +{ + class mainDialogClass; +} + +class mainDialog : public QDialog +{ + Q_OBJECT + +public: + mainDialog(QWidget *parent = 0); + +protected: + void keyPressEvent(QKeyEvent*); + +private slots: + void rosterChanged(const QString& bareJid); + void rosterReceived(); + void presenceChanged(const QString&, const QString&); + void sort(); + void filterChanged(const QString& filter); + void showChatDialog(const QString& bareJid); + void messageReceived(const QXmppMessage& msg); + void statusTextChanged(const QString&); + void presenceTypeChanged(QXmppPresence::Type); + void presenceStatusTypeChanged(QXmppPresence::Status::Type); + void signIn(); + void cancelSignIn(); + void showSignInPage(); + void showSignInPageAfterUserDisconnection(); + void showSignInPageForAutoReconnection(int); + void showSignInPageForAutoReconnectionNow(); + void showRosterPage(); + void startConnection(); + void updateStatusWidget(); + void showLoginStatusWithProgress(const QString& msg); + void showLoginStatus(const QString& msg); + void showLoginStatusWithCounter(const QString& msg, int time); + void updateVCard(const QString& bareJid); + void avatarChanged(const QImage&); + void showProfile(const QString& bareJid); + +private: + chatDialog* getChatDialog(const QString& bareJid); + + Ui::mainDialogClass* ui; + QXmppClient m_xmppClient; + rosterItemModel m_rosterItemModel; + rosterItemSortFilterProxyModel m_rosterItemSortFilterModel; + statusWidget m_statusWidget; + vCardManager m_vCardManager; + + // map of bare jids and respective chatdlg + QMap m_chatDlgsList; +}; + +#endif // MAINDIALOG_H diff --git a/examples/GuiClient/mainDialog.ui b/examples/GuiClient/mainDialog.ui index fbf203b8..4baa3bfc 100644 --- a/examples/GuiClient/mainDialog.ui +++ b/examples/GuiClient/mainDialog.ui @@ -1,352 +1,352 @@ - - - mainDialogClass - - - true - - - - 0 - 0 - 263 - 487 - - - - QXmpp - - - - 6 - - - - - 1 - - - - - 6 - - - 0 - - - 4 - - - 0 - - - 0 - - - - - true - - - - - - - QAbstractItemView::NoEditTriggers - - - QAbstractItemView::ScrollPerPixel - - - - - - - - - + - - - - - - - View - - - false - - - - - - - Settings - - - false - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - - - 20 - - - 20 - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - Username: - - - - - - - qxmpp.test1@gmail.com - - - - - - - Password: - - - - - - - qxmpp123 - - - QLineEdit::Password - - - - - - - Remember password - - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - Sign in - - - - - - - Cancel - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - 0 - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - - - - - - movie - - - - - - - - 0 - 0 - - - - - 0 - 35 - - - - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - Qt::Vertical - - - - 20 - 70 - - - - - - - - - - - - - customListView - QListView -
customListView.h
-
- - searchLineEdit - QLineEdit -
searchLineEdit.h
-
- - customLabel - QLabel -
customLabel.h
-
-
- - -
+ + + mainDialogClass + + + true + + + + 0 + 0 + 263 + 487 + + + + QXmpp + + + + 6 + + + + + 1 + + + + + 6 + + + 0 + + + 4 + + + 0 + + + 0 + + + + + true + + + + + + + QAbstractItemView::NoEditTriggers + + + QAbstractItemView::ScrollPerPixel + + + + + + + + + + + + + + + + + View + + + false + + + + + + + Settings + + + false + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + 20 + + + 20 + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + Username: + + + + + + + qxmpp.test1@gmail.com + + + + + + + Password: + + + + + + + qxmpp123 + + + QLineEdit::Password + + + + + + + Remember password + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Sign in + + + + + + + Cancel + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + 0 + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + + + + movie + + + + + + + + 0 + 0 + + + + + 0 + 35 + + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + Qt::Vertical + + + + 20 + 70 + + + + + + + + + + + + + customListView + QListView +
customListView.h
+
+ + searchLineEdit + QLineEdit +
searchLineEdit.h
+
+ + customLabel + QLabel +
customLabel.h
+
+
+ + +
diff --git a/examples/GuiClient/messageGraphicsItem.cpp b/examples/GuiClient/messageGraphicsItem.cpp index 4fb8661b..26a8c782 100644 --- a/examples/GuiClient/messageGraphicsItem.cpp +++ b/examples/GuiClient/messageGraphicsItem.cpp @@ -1,311 +1,311 @@ -/* - * Copyright (C) 2008-2010 The QXmpp developers - * - * Author: - * Manjeet Dahiya - * - * Source: - * http://code.google.com/p/qxmpp - * - * This file is a part of QXmpp library. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - */ - - -#include "messageGraphicsItem.h" -#include -#include -#include -#include -#include -#include - -QLinearGradient getGradient(const QColor &col, const QRectF &rect) -{ - QLinearGradient g(rect.topLeft(), rect.bottomLeft()); - - qreal hue = col.hueF(); - qreal value = col.valueF(); - qreal saturation = col.saturationF(); - - QColor c = col; - c.setHsvF(hue, 0.42 * saturation, 0.98 * value); - g.setColorAt(0, c); - c.setHsvF(hue, 0.58 * saturation, 0.95 * value); - g.setColorAt(0.25, c); - c.setHsvF(hue, 0.70 * saturation, 0.93 * value); - g.setColorAt(0.5, c); - - c.setHsvF(hue, 0.95 * saturation, 0.9 * value); - g.setColorAt(0.501, c); - c.setHsvF(hue * 0.95, 0.95 * saturation, 0.95 * value); - g.setColorAt(0.75, c); - c.setHsvF(hue * 0.90, 0.95 * saturation, 1 * value); - g.setColorAt(1.0, c); - - return g; -} - -QLinearGradient darken(const QLinearGradient &gradient) -{ - QGradientStops stops = gradient.stops(); - for (int i = 0; i < stops.size(); ++i) { - QColor color = stops.at(i).second; - stops[i].second = color.darker(160); - } - - QLinearGradient g = gradient; - g.setStops(stops); - return g; -} - -void drawPath(QPainter *p, const QPainterPath &path, - const QColor &col, const QString &name, int textWidth, - bool dark = false) -{ - const QRectF pathRect = path.boundingRect(); - - const QLinearGradient baseGradient = getGradient(col, pathRect); - const QLinearGradient darkGradient = darken(baseGradient); - - p->save(); - - // p->setOpacity(0.25); - - //glow -// if (dark) -// p->strokePath(path, QPen(darkGradient, 6)); -// else -// p->strokePath(path, QPen(baseGradient, 6)); - - p->setOpacity(1.0); - - //fill - if (dark) - p->fillPath(path, darkGradient); - else - p->fillPath(path, baseGradient); - - QLinearGradient g(pathRect.topLeft(), pathRect.topRight()); - g.setCoordinateMode(QGradient::ObjectBoundingMode); - - p->setOpacity(0.2); - p->fillPath(path, g); - - p->setOpacity(0.5); - - // highlight -// if (dark) -// p->strokePath(path, QPen(col.lighter(160).darker(160), 2)); -// else -// p->strokePath(path, QPen(col.lighter(160), 2)); - - p->setOpacity(1.0); - - p->restore(); -} - -messageGraphicsItem::messageGraphicsItem(QGraphicsItem * parent):QGraphicsPathItem(parent), - m_spikeWidth(9), - m_spikeHeight(6), - m_cornerRadius(10), - m_textSpacing(4), m_color(Qt::yellow) -{ - setPath(createPath()); -// setFlags(QGraphicsItem::ItemIsMovable); - - QFont font; - QFontMetrics fm(font); - m_timeStampWidth = fm.width(getTime()) + 4; -} - -void messageGraphicsItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) -{ - painter->setRenderHint(QPainter::Antialiasing); - drawPath(painter, path(), m_color, getText(), getTextWidth()); - -// int spike_x = m_spikeWidth; -// int spike_y = m_spikeHeight; -// int corner = m_cornerRadius; -// int length = m_width - spike_x; -// int offset = spike_x; - QFont font; - font.setBold(true); - QTextDocument textDoc(getText()); - QTextOption textOp; - textOp.setWrapMode(QTextOption::WrapAnywhere); - textOp.setAlignment(Qt::AlignLeft); - textDoc.setDefaultTextOption(textOp); - textDoc.setTextWidth(getTextWidth()); - textDoc.setDefaultFont(font); - - painter->setPen(Qt::white); - painter->setFont(font); - int height = (int) textDoc.size().height(); - painter->drawText(m_spikeWidth + m_cornerRadius, 4, getTextWidth(), height, - Qt::AlignLeft|Qt::TextWrapAnywhere, getText()); - -// painter->setPen(Qt::gray); - painter->setPen(Qt::black); - -// font.setBold(false); - painter->setFont(font); - painter->drawText(-m_boxStartLength, 0, m_boxStartLength, m_height, - Qt::AlignRight|Qt::AlignBottom, getName()); - - font.setBold(false); - painter->setPen(Qt::gray); - painter->setFont(font); - - int timeWidth; - if(m_timeStampWidth > m_boxStartLength) - timeWidth = m_timeStampWidth; - else - timeWidth = m_boxStartLength; - - painter->drawText(getMaxWidth() + 6, 0, timeWidth - 6, m_height, - Qt::AlignBottom|Qt::AlignLeft, getTime()); -} - -void messageGraphicsItem::setText(const QString& text) -{ - m_text = text; - calculateWidth(); - setPath(createPath()); -} - -void messageGraphicsItem::setMaxWidth(int width) -{ - m_maxWidth = width; - setPath(createPath()); -} - -void messageGraphicsItem::setViewWidth(int width) -{ - //25 for scrollbar - setMaxWidth(width - getBoxStartLength() - 25); -} - -int messageGraphicsItem::getMaxWidth() const -{ - return m_maxWidth; -} - -void messageGraphicsItem::setAlignment(Alignment align) -{ - m_alignment = align; - setPath(createPath()); -} - -QPainterPath messageGraphicsItem::createPath() -{ - calculateWidth(); - int spike_x = m_spikeWidth; - int spike_y = m_spikeHeight; - int corner = m_cornerRadius; - int length = m_width - spike_x; - int offset = spike_x; - - QPainterPath messageBoxPath; - messageBoxPath.moveTo(0 + offset, m_height - corner); - QRectF rect(offset - 2*spike_x, m_height - corner - spike_y, 2*spike_x, 2*spike_y); - messageBoxPath.arcMoveTo(rect, -90.0); - messageBoxPath.arcTo(rect, 270, 90.0); - messageBoxPath.lineTo(0 + offset, corner); - messageBoxPath.arcTo(0 + offset, 0, 2*corner, 2*corner, 180, -90.0); - messageBoxPath.lineTo(length - corner, 0); - messageBoxPath.arcTo(length + offset - corner*2, 0, 2*corner, 2*corner, 90, -90.0); - messageBoxPath.lineTo(length + offset, m_height - corner); - messageBoxPath.arcTo(length + offset - corner*2, m_height - 2*corner, 2*corner, 2*corner, 0, -90.0); - messageBoxPath.lineTo(offset + corner, m_height); - messageBoxPath.arcTo(offset, m_height - 2*corner, 2*corner, 2*corner, 270, -45.0); - messageBoxPath.closeSubpath(); - - return messageBoxPath; -} - -QString messageGraphicsItem::getText() const -{ - return m_text; -} - -int messageGraphicsItem::getTextWidth() const -{ - return getMaxWidth() - m_spikeWidth - m_cornerRadius*2; -} - -void messageGraphicsItem::calculateWidth() -{ - QFont font; - font.setBold(true); - QTextDocument textDoc(m_text); - textDoc.setDefaultFont(font); - int idealWidth = (int)textDoc.size().width(); - textDoc.setTextWidth(getTextWidth()); - m_height = (int)textDoc.size().height(); - - if(idealWidth < getTextWidth()) - { - m_width = idealWidth + m_spikeWidth + m_cornerRadius; - } - else - m_width = getMaxWidth(); -} - -void messageGraphicsItem::setName(const QString& name) -{ - m_name = name; - if(name != "Me") - m_color = QColor(0, 210, 250); - else - m_color = QColor(250, 188, 239); -} - -QString messageGraphicsItem::getName() const -{ - return m_name; -} - -QString messageGraphicsItem::getTime() const -{ - return QTime::currentTime().toString("hh:mm"); -} - -void messageGraphicsItem::setBoxStartLength(int length) -{ - m_boxStartLength = length; -} - -int messageGraphicsItem::getBoxStartLength() const -{ - return m_boxStartLength; -} - -void messageGraphicsItem::setColor(const QColor& color) -{ - m_color = color; -} - -QRectF messageGraphicsItem::boundingRect() const -{ - QRectF rect = QGraphicsPathItem::boundingRect(); - rect.setLeft(-getBoxStartLength()); - - int timeWidth; - if(m_timeStampWidth > m_boxStartLength) - timeWidth = m_timeStampWidth; - else - timeWidth = m_boxStartLength; - rect.setRight(getMaxWidth() + timeWidth); - return rect; -} +/* + * Copyright (C) 2008-2010 The QXmpp developers + * + * Author: + * Manjeet Dahiya + * + * Source: + * http://code.google.com/p/qxmpp + * + * This file is a part of QXmpp library. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + */ + + +#include "messageGraphicsItem.h" +#include +#include +#include +#include +#include +#include + +QLinearGradient getGradient(const QColor &col, const QRectF &rect) +{ + QLinearGradient g(rect.topLeft(), rect.bottomLeft()); + + qreal hue = col.hueF(); + qreal value = col.valueF(); + qreal saturation = col.saturationF(); + + QColor c = col; + c.setHsvF(hue, 0.42 * saturation, 0.98 * value); + g.setColorAt(0, c); + c.setHsvF(hue, 0.58 * saturation, 0.95 * value); + g.setColorAt(0.25, c); + c.setHsvF(hue, 0.70 * saturation, 0.93 * value); + g.setColorAt(0.5, c); + + c.setHsvF(hue, 0.95 * saturation, 0.9 * value); + g.setColorAt(0.501, c); + c.setHsvF(hue * 0.95, 0.95 * saturation, 0.95 * value); + g.setColorAt(0.75, c); + c.setHsvF(hue * 0.90, 0.95 * saturation, 1 * value); + g.setColorAt(1.0, c); + + return g; +} + +QLinearGradient darken(const QLinearGradient &gradient) +{ + QGradientStops stops = gradient.stops(); + for (int i = 0; i < stops.size(); ++i) { + QColor color = stops.at(i).second; + stops[i].second = color.darker(160); + } + + QLinearGradient g = gradient; + g.setStops(stops); + return g; +} + +void drawPath(QPainter *p, const QPainterPath &path, + const QColor &col, const QString &name, int textWidth, + bool dark = false) +{ + const QRectF pathRect = path.boundingRect(); + + const QLinearGradient baseGradient = getGradient(col, pathRect); + const QLinearGradient darkGradient = darken(baseGradient); + + p->save(); + + // p->setOpacity(0.25); + + //glow +// if (dark) +// p->strokePath(path, QPen(darkGradient, 6)); +// else +// p->strokePath(path, QPen(baseGradient, 6)); + + p->setOpacity(1.0); + + //fill + if (dark) + p->fillPath(path, darkGradient); + else + p->fillPath(path, baseGradient); + + QLinearGradient g(pathRect.topLeft(), pathRect.topRight()); + g.setCoordinateMode(QGradient::ObjectBoundingMode); + + p->setOpacity(0.2); + p->fillPath(path, g); + + p->setOpacity(0.5); + + // highlight +// if (dark) +// p->strokePath(path, QPen(col.lighter(160).darker(160), 2)); +// else +// p->strokePath(path, QPen(col.lighter(160), 2)); + + p->setOpacity(1.0); + + p->restore(); +} + +messageGraphicsItem::messageGraphicsItem(QGraphicsItem * parent):QGraphicsPathItem(parent), + m_spikeWidth(9), + m_spikeHeight(6), + m_cornerRadius(10), + m_textSpacing(4), m_color(Qt::yellow) +{ + setPath(createPath()); +// setFlags(QGraphicsItem::ItemIsMovable); + + QFont font; + QFontMetrics fm(font); + m_timeStampWidth = fm.width(getTime()) + 4; +} + +void messageGraphicsItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) +{ + painter->setRenderHint(QPainter::Antialiasing); + drawPath(painter, path(), m_color, getText(), getTextWidth()); + +// int spike_x = m_spikeWidth; +// int spike_y = m_spikeHeight; +// int corner = m_cornerRadius; +// int length = m_width - spike_x; +// int offset = spike_x; + QFont font; + font.setBold(true); + QTextDocument textDoc(getText()); + QTextOption textOp; + textOp.setWrapMode(QTextOption::WrapAnywhere); + textOp.setAlignment(Qt::AlignLeft); + textDoc.setDefaultTextOption(textOp); + textDoc.setTextWidth(getTextWidth()); + textDoc.setDefaultFont(font); + + painter->setPen(Qt::white); + painter->setFont(font); + int height = (int) textDoc.size().height(); + painter->drawText(m_spikeWidth + m_cornerRadius, 4, getTextWidth(), height, + Qt::AlignLeft|Qt::TextWrapAnywhere, getText()); + +// painter->setPen(Qt::gray); + painter->setPen(Qt::black); + +// font.setBold(false); + painter->setFont(font); + painter->drawText(-m_boxStartLength, 0, m_boxStartLength, m_height, + Qt::AlignRight|Qt::AlignBottom, getName()); + + font.setBold(false); + painter->setPen(Qt::gray); + painter->setFont(font); + + int timeWidth; + if(m_timeStampWidth > m_boxStartLength) + timeWidth = m_timeStampWidth; + else + timeWidth = m_boxStartLength; + + painter->drawText(getMaxWidth() + 6, 0, timeWidth - 6, m_height, + Qt::AlignBottom|Qt::AlignLeft, getTime()); +} + +void messageGraphicsItem::setText(const QString& text) +{ + m_text = text; + calculateWidth(); + setPath(createPath()); +} + +void messageGraphicsItem::setMaxWidth(int width) +{ + m_maxWidth = width; + setPath(createPath()); +} + +void messageGraphicsItem::setViewWidth(int width) +{ + //25 for scrollbar + setMaxWidth(width - getBoxStartLength() - 25); +} + +int messageGraphicsItem::getMaxWidth() const +{ + return m_maxWidth; +} + +void messageGraphicsItem::setAlignment(Alignment align) +{ + m_alignment = align; + setPath(createPath()); +} + +QPainterPath messageGraphicsItem::createPath() +{ + calculateWidth(); + int spike_x = m_spikeWidth; + int spike_y = m_spikeHeight; + int corner = m_cornerRadius; + int length = m_width - spike_x; + int offset = spike_x; + + QPainterPath messageBoxPath; + messageBoxPath.moveTo(0 + offset, m_height - corner); + QRectF rect(offset - 2*spike_x, m_height - corner - spike_y, 2*spike_x, 2*spike_y); + messageBoxPath.arcMoveTo(rect, -90.0); + messageBoxPath.arcTo(rect, 270, 90.0); + messageBoxPath.lineTo(0 + offset, corner); + messageBoxPath.arcTo(0 + offset, 0, 2*corner, 2*corner, 180, -90.0); + messageBoxPath.lineTo(length - corner, 0); + messageBoxPath.arcTo(length + offset - corner*2, 0, 2*corner, 2*corner, 90, -90.0); + messageBoxPath.lineTo(length + offset, m_height - corner); + messageBoxPath.arcTo(length + offset - corner*2, m_height - 2*corner, 2*corner, 2*corner, 0, -90.0); + messageBoxPath.lineTo(offset + corner, m_height); + messageBoxPath.arcTo(offset, m_height - 2*corner, 2*corner, 2*corner, 270, -45.0); + messageBoxPath.closeSubpath(); + + return messageBoxPath; +} + +QString messageGraphicsItem::getText() const +{ + return m_text; +} + +int messageGraphicsItem::getTextWidth() const +{ + return getMaxWidth() - m_spikeWidth - m_cornerRadius*2; +} + +void messageGraphicsItem::calculateWidth() +{ + QFont font; + font.setBold(true); + QTextDocument textDoc(m_text); + textDoc.setDefaultFont(font); + int idealWidth = (int)textDoc.size().width(); + textDoc.setTextWidth(getTextWidth()); + m_height = (int)textDoc.size().height(); + + if(idealWidth < getTextWidth()) + { + m_width = idealWidth + m_spikeWidth + m_cornerRadius; + } + else + m_width = getMaxWidth(); +} + +void messageGraphicsItem::setName(const QString& name) +{ + m_name = name; + if(name != "Me") + m_color = QColor(0, 210, 250); + else + m_color = QColor(250, 188, 239); +} + +QString messageGraphicsItem::getName() const +{ + return m_name; +} + +QString messageGraphicsItem::getTime() const +{ + return QTime::currentTime().toString("hh:mm"); +} + +void messageGraphicsItem::setBoxStartLength(int length) +{ + m_boxStartLength = length; +} + +int messageGraphicsItem::getBoxStartLength() const +{ + return m_boxStartLength; +} + +void messageGraphicsItem::setColor(const QColor& color) +{ + m_color = color; +} + +QRectF messageGraphicsItem::boundingRect() const +{ + QRectF rect = QGraphicsPathItem::boundingRect(); + rect.setLeft(-getBoxStartLength()); + + int timeWidth; + if(m_timeStampWidth > m_boxStartLength) + timeWidth = m_timeStampWidth; + else + timeWidth = m_boxStartLength; + rect.setRight(getMaxWidth() + timeWidth); + return rect; +} diff --git a/examples/GuiClient/messageGraphicsItem.h b/examples/GuiClient/messageGraphicsItem.h index dccf63f6..d0b03960 100644 --- a/examples/GuiClient/messageGraphicsItem.h +++ b/examples/GuiClient/messageGraphicsItem.h @@ -1,87 +1,87 @@ -/* - * Copyright (C) 2008-2010 The QXmpp developers - * - * Author: - * Manjeet Dahiya - * - * Source: - * http://code.google.com/p/qxmpp - * - * This file is a part of QXmpp library. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - */ - - -#ifndef MESSAGEGRAPHICSITEM_H -#define MESSAGEGRAPHICSITEM_H - -#include - -class messageGraphicsItem : public QGraphicsPathItem -{ -public: - enum Alignment - { - LEFT = 0, - RIGHT - }; - - messageGraphicsItem(QGraphicsItem * parent = 0); - void setText(const QString& text); - void setName(const QString& name); - QString getName() const; - QString getText() const; - - void setMaxWidth(int width); - int getMaxWidth() const; - void setViewWidth(int viewWidth); - - void setAlignment(Alignment align); - - void setBoxStartLength(int length); - int getBoxStartLength() const; - - void setColor(const QColor&); - - virtual QRectF boundingRect() const; - -private: - void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); - QPainterPath createPath(); - int getTextWidth() const; - void calculateWidth(); - QString getTime() const; - - // max width of bubble including the spike - int m_maxWidth; - - // actual width - int m_width; - - // height of bubble - int m_height; - int m_spikeWidth; - int m_spikeHeight; - int m_cornerRadius; - int m_textSpacing; - int m_boxStartLength; - int m_timeStampWidth; - QColor m_color; - - QString m_text; - QString m_name; - int m_length; - Alignment m_alignment; -}; - -#endif // MESSAGEGRAPHICSITEM_H +/* + * Copyright (C) 2008-2010 The QXmpp developers + * + * Author: + * Manjeet Dahiya + * + * Source: + * http://code.google.com/p/qxmpp + * + * This file is a part of QXmpp library. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + */ + + +#ifndef MESSAGEGRAPHICSITEM_H +#define MESSAGEGRAPHICSITEM_H + +#include + +class messageGraphicsItem : public QGraphicsPathItem +{ +public: + enum Alignment + { + LEFT = 0, + RIGHT + }; + + messageGraphicsItem(QGraphicsItem * parent = 0); + void setText(const QString& text); + void setName(const QString& name); + QString getName() const; + QString getText() const; + + void setMaxWidth(int width); + int getMaxWidth() const; + void setViewWidth(int viewWidth); + + void setAlignment(Alignment align); + + void setBoxStartLength(int length); + int getBoxStartLength() const; + + void setColor(const QColor&); + + virtual QRectF boundingRect() const; + +private: + void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); + QPainterPath createPath(); + int getTextWidth() const; + void calculateWidth(); + QString getTime() const; + + // max width of bubble including the spike + int m_maxWidth; + + // actual width + int m_width; + + // height of bubble + int m_height; + int m_spikeWidth; + int m_spikeHeight; + int m_cornerRadius; + int m_textSpacing; + int m_boxStartLength; + int m_timeStampWidth; + QColor m_color; + + QString m_text; + QString m_name; + int m_length; + Alignment m_alignment; +}; + +#endif // MESSAGEGRAPHICSITEM_H diff --git a/examples/GuiClient/profileDialog.cpp b/examples/GuiClient/profileDialog.cpp index 1826fc27..65743bf6 100644 --- a/examples/GuiClient/profileDialog.cpp +++ b/examples/GuiClient/profileDialog.cpp @@ -1,90 +1,90 @@ -#include "profileDialog.h" -#include "ui_profileDialog.h" -#include "utils.h" - -#include "QXmppClient.h" -#include "QXmppVersionIq.h" -#include "QXmppVersionManager.h" -#include "QXmppRosterManager.h" -#include "QXmppUtils.h" - -profileDialog::profileDialog(QWidget *parent, const QString& bareJid, QXmppClient& client) : - QDialog(parent, Qt::WindowTitleHint|Qt::WindowSystemMenuHint), - ui(new Ui::profileDialog), m_bareJid(bareJid), m_xmppClient(client) -{ - ui->setupUi(this); - - bool check = connect(&m_xmppClient.versionManager(), SIGNAL(versionReceived(const QXmppVersionIq&)), - SLOT(versionReceived(const QXmppVersionIq&))); - Q_ASSERT(check); - - QStringList resources = m_xmppClient.rosterManager().getResources(bareJid); - foreach(QString resource, resources) - { - m_xmppClient.versionManager().requestVersion(bareJid + "/" + resource); - } - updateText(); -} - -profileDialog::~profileDialog() -{ - delete ui; -} - -void profileDialog::setAvatar(const QImage& image) -{ - ui->label_avatar->setPixmap(QPixmap::fromImage(image)); -} - -void profileDialog::setBareJid(const QString& bareJid) -{ - ui->label_jid->setText(bareJid); - setWindowTitle(bareJid); -} - -void profileDialog::setFullName(const QString& fullName) -{ - if(fullName.isEmpty()) - ui->label_fullName->hide(); - else - ui->label_fullName->show(); - - ui->label_fullName->setText(fullName); -} - -void profileDialog::setStatusText(const QString& status) -{ - ui->label_status->setText(status); -} - -void profileDialog::versionReceived(const QXmppVersionIq& ver) -{ - m_versions[jidToResource(ver.from())] = ver; - if(ver.type() == QXmppIq::Result) - updateText(); -} - -void profileDialog::updateText() -{ - QStringList resources = m_xmppClient.rosterManager().getResources(m_bareJid); - QString statusText; - for(int i = 0; i < resources.count(); ++i) - { - QString resource = resources.at(i); - statusText += "Resource: " + resource; - statusText += "
"; - QXmppPresence presence = m_xmppClient.rosterManager().getPresence(m_bareJid, resource); - statusText += "Status: " + presenceToStatusText(presence); - statusText += "
"; - if(m_versions.contains(resource)) - statusText += "Software: " + QString("%1 %2 %3"). - arg(m_versions[resource].name()). - arg(m_versions[resource].version()). - arg(m_versions[resource].os()); - - if(i < resources.count() - 1) // skip for the last item - statusText += "

"; - } - setStatusText(statusText); -} - +#include "profileDialog.h" +#include "ui_profileDialog.h" +#include "utils.h" + +#include "QXmppClient.h" +#include "QXmppVersionIq.h" +#include "QXmppVersionManager.h" +#include "QXmppRosterManager.h" +#include "QXmppUtils.h" + +profileDialog::profileDialog(QWidget *parent, const QString& bareJid, QXmppClient& client) : + QDialog(parent, Qt::WindowTitleHint|Qt::WindowSystemMenuHint), + ui(new Ui::profileDialog), m_bareJid(bareJid), m_xmppClient(client) +{ + ui->setupUi(this); + + bool check = connect(&m_xmppClient.versionManager(), SIGNAL(versionReceived(const QXmppVersionIq&)), + SLOT(versionReceived(const QXmppVersionIq&))); + Q_ASSERT(check); + + QStringList resources = m_xmppClient.rosterManager().getResources(bareJid); + foreach(QString resource, resources) + { + m_xmppClient.versionManager().requestVersion(bareJid + "/" + resource); + } + updateText(); +} + +profileDialog::~profileDialog() +{ + delete ui; +} + +void profileDialog::setAvatar(const QImage& image) +{ + ui->label_avatar->setPixmap(QPixmap::fromImage(image)); +} + +void profileDialog::setBareJid(const QString& bareJid) +{ + ui->label_jid->setText(bareJid); + setWindowTitle(bareJid); +} + +void profileDialog::setFullName(const QString& fullName) +{ + if(fullName.isEmpty()) + ui->label_fullName->hide(); + else + ui->label_fullName->show(); + + ui->label_fullName->setText(fullName); +} + +void profileDialog::setStatusText(const QString& status) +{ + ui->label_status->setText(status); +} + +void profileDialog::versionReceived(const QXmppVersionIq& ver) +{ + m_versions[jidToResource(ver.from())] = ver; + if(ver.type() == QXmppIq::Result) + updateText(); +} + +void profileDialog::updateText() +{ + QStringList resources = m_xmppClient.rosterManager().getResources(m_bareJid); + QString statusText; + for(int i = 0; i < resources.count(); ++i) + { + QString resource = resources.at(i); + statusText += "Resource: " + resource; + statusText += "
"; + QXmppPresence presence = m_xmppClient.rosterManager().getPresence(m_bareJid, resource); + statusText += "Status: " + presenceToStatusText(presence); + statusText += "
"; + if(m_versions.contains(resource)) + statusText += "Software: " + QString("%1 %2 %3"). + arg(m_versions[resource].name()). + arg(m_versions[resource].version()). + arg(m_versions[resource].os()); + + if(i < resources.count() - 1) // skip for the last item + statusText += "

"; + } + setStatusText(statusText); +} + diff --git a/examples/GuiClient/profileDialog.h b/examples/GuiClient/profileDialog.h index 57718202..86b2bba5 100644 --- a/examples/GuiClient/profileDialog.h +++ b/examples/GuiClient/profileDialog.h @@ -1,41 +1,41 @@ -#ifndef PROFILEDIALOG_H -#define PROFILEDIALOG_H - -#include -#include - -namespace Ui { - class profileDialog; -} - -class QXmppClient; -class QXmppVersionIq; - -class profileDialog : public QDialog -{ - Q_OBJECT - -public: - explicit profileDialog(QWidget *parent, const QString& bareJid, QXmppClient& client); - ~profileDialog(); - - void setClientRef(QXmppClient& m_xmppClient); - void setAvatar(const QImage&); - void setBareJid(const QString&); - void setFullName(const QString&); - void setStatusText(const QString&); - -private slots: - void versionReceived(const QXmppVersionIq&); - -private: - void updateText(); - -private: - Ui::profileDialog *ui; - QString m_bareJid; - QXmppClient& m_xmppClient; // reference to the active QXmppClient (No ownership) - QMap m_versions; -}; - -#endif // PROFILEDIALOG_H +#ifndef PROFILEDIALOG_H +#define PROFILEDIALOG_H + +#include +#include + +namespace Ui { + class profileDialog; +} + +class QXmppClient; +class QXmppVersionIq; + +class profileDialog : public QDialog +{ + Q_OBJECT + +public: + explicit profileDialog(QWidget *parent, const QString& bareJid, QXmppClient& client); + ~profileDialog(); + + void setClientRef(QXmppClient& m_xmppClient); + void setAvatar(const QImage&); + void setBareJid(const QString&); + void setFullName(const QString&); + void setStatusText(const QString&); + +private slots: + void versionReceived(const QXmppVersionIq&); + +private: + void updateText(); + +private: + Ui::profileDialog *ui; + QString m_bareJid; + QXmppClient& m_xmppClient; // reference to the active QXmppClient (No ownership) + QMap m_versions; +}; + +#endif // PROFILEDIALOG_H diff --git a/examples/GuiClient/profileDialog.ui b/examples/GuiClient/profileDialog.ui index b21428a9..592976c7 100644 --- a/examples/GuiClient/profileDialog.ui +++ b/examples/GuiClient/profileDialog.ui @@ -1,172 +1,172 @@ - - - profileDialog - - - - 0 - 0 - 297 - 174 - - - - Profile - - - - - - - - QLayout::SetFixedSize - - - - - - 0 - 0 - - - - - 96 - 96 - - - - - 96 - 96 - - - - - - - :/icons/resource/avatar.png - - - true - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop - - - - - - - Qt::Vertical - - - - 0 - 0 - - - - - - - - - - - - TextLabel - - - - - - - TextLabel - - - - - - - TextLabel - - - true - - - Qt::LinksAccessibleByMouse|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse - - - - - - - Qt::Vertical - - - - 0 - 0 - - - - - - - - - - - - - - Qt::Horizontal - - - QDialogButtonBox::Close - - - - - - - - - - - - - buttonBox - accepted() - profileDialog - accept() - - - 343 - 215 - - - 301 - 191 - - - - - buttonBox - rejected() - profileDialog - close() - - - 237 - 216 - - - 230 - 172 - - - - - + + + profileDialog + + + + 0 + 0 + 297 + 174 + + + + Profile + + + + + + + + QLayout::SetFixedSize + + + + + + 0 + 0 + + + + + 96 + 96 + + + + + 96 + 96 + + + + + + + :/icons/resource/avatar.png + + + true + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop + + + + + + + Qt::Vertical + + + + 0 + 0 + + + + + + + + + + + + TextLabel + + + + + + + TextLabel + + + + + + + TextLabel + + + true + + + Qt::LinksAccessibleByMouse|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse + + + + + + + Qt::Vertical + + + + 0 + 0 + + + + + + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Close + + + + + + + + + + + + + buttonBox + accepted() + profileDialog + accept() + + + 343 + 215 + + + 301 + 191 + + + + + buttonBox + rejected() + profileDialog + close() + + + 237 + 216 + + + 230 + 172 + + + + + diff --git a/examples/GuiClient/rosterItem.cpp b/examples/GuiClient/rosterItem.cpp index 0468f671..c3c15807 100644 --- a/examples/GuiClient/rosterItem.cpp +++ b/examples/GuiClient/rosterItem.cpp @@ -1,236 +1,236 @@ -/* - * Copyright (C) 2008-2010 The QXmpp developers - * - * Author: - * Manjeet Dahiya - * - * Source: - * http://code.google.com/p/qxmpp - * - * This file is a part of QXmpp library. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - */ - - -#include "rosterItem.h" -#include - -rosterItem::rosterItem(const QString& bareJid) //: QStandardItem(bareJid) -{ - setStatusType(QXmppPresence::Status::Offline); - setStatusText("Offline"); -} - -void rosterItem::setName(const QString& name) -{ - setText(name); -} - -QString rosterItem::getName() -{ - return text(); -} - -void rosterItem::setBareJid(const QString& bareJid) -{ - setData(bareJid, rosterItem::BareJid); -} - -void rosterItem::setStatusText(const QString& text) -{ - setData(text, rosterItem::StatusText); -} - -QString rosterItem::getBareJid() -{ - return data(rosterItem::BareJid).toString(); -} - -QString rosterItem::getStatusText() -{ - return data(rosterItem::StatusText).toString(); -} - -void rosterItem::setStatusType(QXmppPresence::Status::Type type) -{ - setData(static_cast(type), StatusType); - QString icon; - switch(type) - { - case QXmppPresence::Status::Online: - case QXmppPresence::Status::Chat: - icon = "green"; - break; - case QXmppPresence::Status::Away: - case QXmppPresence::Status::XA: - icon = "orange"; - break; - case QXmppPresence::Status::DND: - icon = "red"; - break; - case QXmppPresence::Status::Invisible: - case QXmppPresence::Status::Offline: - icon = "gray"; - break; - } - if(!icon.isEmpty()) - setIcon(QIcon(":/icons/resource/"+icon+".png")); -} - -QXmppPresence::Status::Type rosterItem::getStatusType() -{ - return static_cast(data(StatusType).toInt()); -} - -void rosterItem::setPresenceType(QXmppPresence::Type type) -{ - setData(static_cast(type), PresenceType); - QString icon; - switch(type) - { - case QXmppPresence::Available: - break; - case QXmppPresence::Unavailable: - icon = "gray"; - break; - case QXmppPresence::Error: - case QXmppPresence::Subscribe: - case QXmppPresence::Subscribed: - case QXmppPresence::Unsubscribe: - case QXmppPresence::Unsubscribed: - case QXmppPresence::Probe: - break; - } - if(!icon.isEmpty()) - setIcon(QIcon(":/icons/resource/"+icon+".png")); -} - -QXmppPresence::Type rosterItem::getPresenceType() -{ - return static_cast(data(PresenceType).toInt()); -} - -void rosterItem::setAvatar(const QImage& image) -{ - setData(QVariant(image), rosterItem::Avatar); -} - -QImage rosterItem::getAvatar() -{ - return qvariant_cast(data(rosterItem::Avatar)); -} - -ItemDelegate::ItemDelegate() -{ -} - -QSize ItemDelegate::sizeHint(const QStyleOptionViewItem& option, const QModelIndex & index) const -{ - return QSize(44, 36); -} - -void ItemDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const -{ - painter->save(); - painter->setRenderHint(QPainter::TextAntialiasing); - QVariant value = index.data(Qt::DecorationRole); - - QColor selectedBg(60, 140, 222); - QColor alternateBg(239, 245, 254); - QColor selectedText(Qt::white); - - QColor nameTextColor(Qt::black); - QColor statusTextColor(Qt::darkGray); - - QPixmap pixmap; - if(value.type() == QVariant::Icon) - { - QIcon icon = qvariant_cast(value); - pixmap = icon.pixmap(QSize(16, 16), QIcon::Normal, QIcon::On); - } - - QPen penDivision; -// if(index.row() % 2) -// painter->fillRect(option.rect, alternateBg); - - if (option.state & QStyle::State_Selected) - { - painter->fillRect(option.rect, selectedBg); -// painter->fillRect(option.rect, option.palette.highlight()); -// penDivision.setColor(option.palette.highlight().color()); - penDivision.setColor(selectedBg); - nameTextColor = selectedText; - statusTextColor = selectedText; - } - else - { - penDivision.setColor(QColor(244, 244, 244)); - } - - QRect rect = option.rect; - rect.setWidth(pixmap.width()); - rect.setHeight(pixmap.height()); - rect.moveTop(rect.y() + (option.rect.height() - pixmap.height())/2); - rect.moveLeft(rect.left() + 2); - painter->drawPixmap(rect, pixmap); - - rect = option.rect; - rect.setLeft(rect.x() + pixmap.width() + 8); - rect.moveTop(rect.y() + 3); - QFont font; - painter->setFont(font); - painter->setPen(nameTextColor); - if(!index.data(Qt::DisplayRole).toString().isEmpty()) - painter->drawText(rect, index.data(Qt::DisplayRole).toString()); - else - painter->drawText(rect, index.data(rosterItem::BareJid).toString()); - - painter->setPen(statusTextColor); - rect.setTop(rect.y() + rect.height()/2); - rect.moveTop(rect.y() - 3); - QString statusText = index.data(rosterItem::StatusText).toString(); - QFontMetrics fontMetrics(font); - statusText = fontMetrics.elidedText(statusText, Qt::ElideRight, rect.width() - 34); - painter->drawText(rect, statusText); - - penDivision.setWidth(0); - painter->setPen(penDivision); - - rect = option.rect; - QPoint left = rect.bottomLeft(); - left.setX(left.x() + 4); - QPoint right = rect.bottomRight(); - right.setX(right.x() - 4); - painter->drawLine(left, right); - - QImage image; - value = index.data(rosterItem::Avatar); - if(value.type() == QVariant::Image) - { - image = qvariant_cast(value); - } - - pixmap = QPixmap(":/icons/resource/avatar.png"); - rect = option.rect; - rect.setWidth(pixmap.width()); - rect.setHeight(pixmap.height()); - rect.moveTop(rect.y() + (option.rect.height() - pixmap.height())/2); - rect.moveLeft(option.rect.x() + option.rect.width() - pixmap.width() - 2); - -// if(image.isNull()) -// painter->drawPixmap(rect, pixmap); -// else - painter->drawImage(rect, image); - - painter->restore(); -} +/* + * Copyright (C) 2008-2010 The QXmpp developers + * + * Author: + * Manjeet Dahiya + * + * Source: + * http://code.google.com/p/qxmpp + * + * This file is a part of QXmpp library. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + */ + + +#include "rosterItem.h" +#include + +rosterItem::rosterItem(const QString& bareJid) //: QStandardItem(bareJid) +{ + setStatusType(QXmppPresence::Status::Offline); + setStatusText("Offline"); +} + +void rosterItem::setName(const QString& name) +{ + setText(name); +} + +QString rosterItem::getName() +{ + return text(); +} + +void rosterItem::setBareJid(const QString& bareJid) +{ + setData(bareJid, rosterItem::BareJid); +} + +void rosterItem::setStatusText(const QString& text) +{ + setData(text, rosterItem::StatusText); +} + +QString rosterItem::getBareJid() +{ + return data(rosterItem::BareJid).toString(); +} + +QString rosterItem::getStatusText() +{ + return data(rosterItem::StatusText).toString(); +} + +void rosterItem::setStatusType(QXmppPresence::Status::Type type) +{ + setData(static_cast(type), StatusType); + QString icon; + switch(type) + { + case QXmppPresence::Status::Online: + case QXmppPresence::Status::Chat: + icon = "green"; + break; + case QXmppPresence::Status::Away: + case QXmppPresence::Status::XA: + icon = "orange"; + break; + case QXmppPresence::Status::DND: + icon = "red"; + break; + case QXmppPresence::Status::Invisible: + case QXmppPresence::Status::Offline: + icon = "gray"; + break; + } + if(!icon.isEmpty()) + setIcon(QIcon(":/icons/resource/"+icon+".png")); +} + +QXmppPresence::Status::Type rosterItem::getStatusType() +{ + return static_cast(data(StatusType).toInt()); +} + +void rosterItem::setPresenceType(QXmppPresence::Type type) +{ + setData(static_cast(type), PresenceType); + QString icon; + switch(type) + { + case QXmppPresence::Available: + break; + case QXmppPresence::Unavailable: + icon = "gray"; + break; + case QXmppPresence::Error: + case QXmppPresence::Subscribe: + case QXmppPresence::Subscribed: + case QXmppPresence::Unsubscribe: + case QXmppPresence::Unsubscribed: + case QXmppPresence::Probe: + break; + } + if(!icon.isEmpty()) + setIcon(QIcon(":/icons/resource/"+icon+".png")); +} + +QXmppPresence::Type rosterItem::getPresenceType() +{ + return static_cast(data(PresenceType).toInt()); +} + +void rosterItem::setAvatar(const QImage& image) +{ + setData(QVariant(image), rosterItem::Avatar); +} + +QImage rosterItem::getAvatar() +{ + return qvariant_cast(data(rosterItem::Avatar)); +} + +ItemDelegate::ItemDelegate() +{ +} + +QSize ItemDelegate::sizeHint(const QStyleOptionViewItem& option, const QModelIndex & index) const +{ + return QSize(44, 36); +} + +void ItemDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const +{ + painter->save(); + painter->setRenderHint(QPainter::TextAntialiasing); + QVariant value = index.data(Qt::DecorationRole); + + QColor selectedBg(60, 140, 222); + QColor alternateBg(239, 245, 254); + QColor selectedText(Qt::white); + + QColor nameTextColor(Qt::black); + QColor statusTextColor(Qt::darkGray); + + QPixmap pixmap; + if(value.type() == QVariant::Icon) + { + QIcon icon = qvariant_cast(value); + pixmap = icon.pixmap(QSize(16, 16), QIcon::Normal, QIcon::On); + } + + QPen penDivision; +// if(index.row() % 2) +// painter->fillRect(option.rect, alternateBg); + + if (option.state & QStyle::State_Selected) + { + painter->fillRect(option.rect, selectedBg); +// painter->fillRect(option.rect, option.palette.highlight()); +// penDivision.setColor(option.palette.highlight().color()); + penDivision.setColor(selectedBg); + nameTextColor = selectedText; + statusTextColor = selectedText; + } + else + { + penDivision.setColor(QColor(244, 244, 244)); + } + + QRect rect = option.rect; + rect.setWidth(pixmap.width()); + rect.setHeight(pixmap.height()); + rect.moveTop(rect.y() + (option.rect.height() - pixmap.height())/2); + rect.moveLeft(rect.left() + 2); + painter->drawPixmap(rect, pixmap); + + rect = option.rect; + rect.setLeft(rect.x() + pixmap.width() + 8); + rect.moveTop(rect.y() + 3); + QFont font; + painter->setFont(font); + painter->setPen(nameTextColor); + if(!index.data(Qt::DisplayRole).toString().isEmpty()) + painter->drawText(rect, index.data(Qt::DisplayRole).toString()); + else + painter->drawText(rect, index.data(rosterItem::BareJid).toString()); + + painter->setPen(statusTextColor); + rect.setTop(rect.y() + rect.height()/2); + rect.moveTop(rect.y() - 3); + QString statusText = index.data(rosterItem::StatusText).toString(); + QFontMetrics fontMetrics(font); + statusText = fontMetrics.elidedText(statusText, Qt::ElideRight, rect.width() - 34); + painter->drawText(rect, statusText); + + penDivision.setWidth(0); + painter->setPen(penDivision); + + rect = option.rect; + QPoint left = rect.bottomLeft(); + left.setX(left.x() + 4); + QPoint right = rect.bottomRight(); + right.setX(right.x() - 4); + painter->drawLine(left, right); + + QImage image; + value = index.data(rosterItem::Avatar); + if(value.type() == QVariant::Image) + { + image = qvariant_cast(value); + } + + pixmap = QPixmap(":/icons/resource/avatar.png"); + rect = option.rect; + rect.setWidth(pixmap.width()); + rect.setHeight(pixmap.height()); + rect.moveTop(rect.y() + (option.rect.height() - pixmap.height())/2); + rect.moveLeft(option.rect.x() + option.rect.width() - pixmap.width() - 2); + +// if(image.isNull()) +// painter->drawPixmap(rect, pixmap); +// else + painter->drawImage(rect, image); + + painter->restore(); +} diff --git a/examples/GuiClient/rosterItem.h b/examples/GuiClient/rosterItem.h index c3655ba7..3573e88e 100644 --- a/examples/GuiClient/rosterItem.h +++ b/examples/GuiClient/rosterItem.h @@ -1,69 +1,69 @@ -/* - * Copyright (C) 2008-2010 The QXmpp developers - * - * Author: - * Manjeet Dahiya - * - * Source: - * http://code.google.com/p/qxmpp - * - * This file is a part of QXmpp library. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - */ - - -#ifndef ROSTERITEM_H -#define ROSTERITEM_H - -#include -#include -#include -#include "QXmppPresence.h" - -class rosterItem : public QStandardItem -{ -public: - enum userRoles - { - StatusText = Qt::UserRole + 2, - StatusType, - PresenceType, - BareJid, - Avatar - }; - - rosterItem(const QString& bareJid); - - void setName(const QString& name); - QString getName(); - void setBareJid(const QString& bareJid); - void setStatusText(const QString& text); - void setStatusType(QXmppPresence::Status::Type type); - void setPresenceType(QXmppPresence::Type type); - void setAvatar(const QImage& image); - QImage getAvatar(); - QString getBareJid(); - QString getStatusText(); - QXmppPresence::Status::Type getStatusType(); - QXmppPresence::Type getPresenceType(); -}; - -class ItemDelegate : public QItemDelegate -{ -public: - ItemDelegate(); - QSize sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const; - void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const; -}; - -#endif // ROSTERITEM_H +/* + * Copyright (C) 2008-2010 The QXmpp developers + * + * Author: + * Manjeet Dahiya + * + * Source: + * http://code.google.com/p/qxmpp + * + * This file is a part of QXmpp library. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + */ + + +#ifndef ROSTERITEM_H +#define ROSTERITEM_H + +#include +#include +#include +#include "QXmppPresence.h" + +class rosterItem : public QStandardItem +{ +public: + enum userRoles + { + StatusText = Qt::UserRole + 2, + StatusType, + PresenceType, + BareJid, + Avatar + }; + + rosterItem(const QString& bareJid); + + void setName(const QString& name); + QString getName(); + void setBareJid(const QString& bareJid); + void setStatusText(const QString& text); + void setStatusType(QXmppPresence::Status::Type type); + void setPresenceType(QXmppPresence::Type type); + void setAvatar(const QImage& image); + QImage getAvatar(); + QString getBareJid(); + QString getStatusText(); + QXmppPresence::Status::Type getStatusType(); + QXmppPresence::Type getPresenceType(); +}; + +class ItemDelegate : public QItemDelegate +{ +public: + ItemDelegate(); + QSize sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const; + void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const; +}; + +#endif // ROSTERITEM_H diff --git a/examples/GuiClient/rosterItemModel.cpp b/examples/GuiClient/rosterItemModel.cpp index 7282758f..fbd2bed6 100644 --- a/examples/GuiClient/rosterItemModel.cpp +++ b/examples/GuiClient/rosterItemModel.cpp @@ -1,111 +1,111 @@ -/* - * Copyright (C) 2008-2010 The QXmpp developers - * - * Author: - * Manjeet Dahiya - * - * Source: - * http://code.google.com/p/qxmpp - * - * This file is a part of QXmpp library. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - */ - - -#include "rosterItemModel.h" - -rosterItemModel::rosterItemModel(QObject* parent) : QStandardItemModel(parent) -{ -// addRosterItemIfDontExist("jkhjkhkhkhk"); -// addRosterItemIfDontExist("uuuu"); -// addRosterItemIfDontExist("kkkkkkk"); -// addRosterItemIfDontExist("jjjjjjjj"); -} - -rosterItem* rosterItemModel::getRosterItemFromBareJid(const QString& bareJid) -{ - if(m_jidRosterItemMap.contains(bareJid)) - return m_jidRosterItemMap[bareJid]; - else - return 0; -} - -void rosterItemModel::addRosterItemIfDontExist(const QString& bareJid) -{ - if(!m_jidRosterItemMap.contains(bareJid)) - { - rosterItem* item = new rosterItem(bareJid); - m_jidRosterItemMap[bareJid] = item; - appendRow(item); - item->setStatusText("Offline"); - item->setBareJid(bareJid); - } -} - -void rosterItemModel::updatePresence(const QString& bareJid, const QMap& presences) -{ - addRosterItemIfDontExist(bareJid); - - if(presences.count() > 0) - { - QString statusText = presences.begin().value().status().statusText(); - QXmppPresence::Status::Type statusType = presences.begin().value().status().type(); - QXmppPresence::Type presenceType = presences.begin().value().type(); - - if(statusText.isEmpty()) - { - if(presenceType == QXmppPresence::Available) - statusText = "Available"; - else if(presenceType == QXmppPresence::Unavailable) - statusText = "Offline"; - } - getRosterItemFromBareJid(bareJid)->setStatusText(statusText); - getRosterItemFromBareJid(bareJid)->setStatusType(statusType); - getRosterItemFromBareJid(bareJid)->setPresenceType(presenceType); - } -} - -void rosterItemModel::updateRosterEntry(const QString& bareJid, const QXmppRosterIq::Item& rosterEntry) -{ - addRosterItemIfDontExist(bareJid); - - QString name = rosterEntry.name(); - if(getRosterItemFromBareJid(bareJid)) - getRosterItemFromBareJid(bareJid)->setName(name); -} - -void rosterItemModel::updateAvatar(const QString& bareJid, const QImage& image) -{ - addRosterItemIfDontExist(bareJid); - - if(image.isNull()) - return; - - getRosterItemFromBareJid(bareJid)->setAvatar(image); -} - -void rosterItemModel::updateName(const QString& bareJid, const QString& name) -{ - addRosterItemIfDontExist(bareJid); - - if(name.isEmpty()) - return; - - getRosterItemFromBareJid(bareJid)->setName(name); -} - -void rosterItemModel::clear() -{ - QStandardItemModel::clear(); - m_jidRosterItemMap.clear(); -} +/* + * Copyright (C) 2008-2010 The QXmpp developers + * + * Author: + * Manjeet Dahiya + * + * Source: + * http://code.google.com/p/qxmpp + * + * This file is a part of QXmpp library. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + */ + + +#include "rosterItemModel.h" + +rosterItemModel::rosterItemModel(QObject* parent) : QStandardItemModel(parent) +{ +// addRosterItemIfDontExist("jkhjkhkhkhk"); +// addRosterItemIfDontExist("uuuu"); +// addRosterItemIfDontExist("kkkkkkk"); +// addRosterItemIfDontExist("jjjjjjjj"); +} + +rosterItem* rosterItemModel::getRosterItemFromBareJid(const QString& bareJid) +{ + if(m_jidRosterItemMap.contains(bareJid)) + return m_jidRosterItemMap[bareJid]; + else + return 0; +} + +void rosterItemModel::addRosterItemIfDontExist(const QString& bareJid) +{ + if(!m_jidRosterItemMap.contains(bareJid)) + { + rosterItem* item = new rosterItem(bareJid); + m_jidRosterItemMap[bareJid] = item; + appendRow(item); + item->setStatusText("Offline"); + item->setBareJid(bareJid); + } +} + +void rosterItemModel::updatePresence(const QString& bareJid, const QMap& presences) +{ + addRosterItemIfDontExist(bareJid); + + if(presences.count() > 0) + { + QString statusText = presences.begin().value().status().statusText(); + QXmppPresence::Status::Type statusType = presences.begin().value().status().type(); + QXmppPresence::Type presenceType = presences.begin().value().type(); + + if(statusText.isEmpty()) + { + if(presenceType == QXmppPresence::Available) + statusText = "Available"; + else if(presenceType == QXmppPresence::Unavailable) + statusText = "Offline"; + } + getRosterItemFromBareJid(bareJid)->setStatusText(statusText); + getRosterItemFromBareJid(bareJid)->setStatusType(statusType); + getRosterItemFromBareJid(bareJid)->setPresenceType(presenceType); + } +} + +void rosterItemModel::updateRosterEntry(const QString& bareJid, const QXmppRosterIq::Item& rosterEntry) +{ + addRosterItemIfDontExist(bareJid); + + QString name = rosterEntry.name(); + if(getRosterItemFromBareJid(bareJid)) + getRosterItemFromBareJid(bareJid)->setName(name); +} + +void rosterItemModel::updateAvatar(const QString& bareJid, const QImage& image) +{ + addRosterItemIfDontExist(bareJid); + + if(image.isNull()) + return; + + getRosterItemFromBareJid(bareJid)->setAvatar(image); +} + +void rosterItemModel::updateName(const QString& bareJid, const QString& name) +{ + addRosterItemIfDontExist(bareJid); + + if(name.isEmpty()) + return; + + getRosterItemFromBareJid(bareJid)->setName(name); +} + +void rosterItemModel::clear() +{ + QStandardItemModel::clear(); + m_jidRosterItemMap.clear(); +} diff --git a/examples/GuiClient/rosterItemModel.h b/examples/GuiClient/rosterItemModel.h index 13e8ccbe..54fdeef9 100644 --- a/examples/GuiClient/rosterItemModel.h +++ b/examples/GuiClient/rosterItemModel.h @@ -1,51 +1,51 @@ -/* - * Copyright (C) 2008-2010 The QXmpp developers - * - * Author: - * Manjeet Dahiya - * - * Source: - * http://code.google.com/p/qxmpp - * - * This file is a part of QXmpp library. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - */ - - -#ifndef ROSTERITEMMODEL_H -#define ROSTERITEMMODEL_H - -#include -#include "rosterItem.h" -#include "QXmppRosterManager.h" -#include "QXmppPresence.h" - -class rosterItemModel : public QStandardItemModel -{ -public: - rosterItemModel(QObject* parent); - rosterItem* getRosterItemFromBareJid(const QString& bareJid); - - void updatePresence(const QString& bareJid, const QMap& presences); - void updateRosterEntry(const QString& bareJid, const QXmppRosterIq::Item& rosterEntry); - void updateAvatar(const QString& bareJid, const QImage& image); - void updateName(const QString& bareJid, const QString& name); - - void clear(); - -private: - QMap m_jidRosterItemMap; - void addRosterItemIfDontExist(const QString& bareJid); -}; - -#endif // ROSTERITEMMODEL_H +/* + * Copyright (C) 2008-2010 The QXmpp developers + * + * Author: + * Manjeet Dahiya + * + * Source: + * http://code.google.com/p/qxmpp + * + * This file is a part of QXmpp library. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + */ + + +#ifndef ROSTERITEMMODEL_H +#define ROSTERITEMMODEL_H + +#include +#include "rosterItem.h" +#include "QXmppRosterManager.h" +#include "QXmppPresence.h" + +class rosterItemModel : public QStandardItemModel +{ +public: + rosterItemModel(QObject* parent); + rosterItem* getRosterItemFromBareJid(const QString& bareJid); + + void updatePresence(const QString& bareJid, const QMap& presences); + void updateRosterEntry(const QString& bareJid, const QXmppRosterIq::Item& rosterEntry); + void updateAvatar(const QString& bareJid, const QImage& image); + void updateName(const QString& bareJid, const QString& name); + + void clear(); + +private: + QMap m_jidRosterItemMap; + void addRosterItemIfDontExist(const QString& bareJid); +}; + +#endif // ROSTERITEMMODEL_H diff --git a/examples/GuiClient/rosterItemSortFilterProxyModel.cpp b/examples/GuiClient/rosterItemSortFilterProxyModel.cpp index e54221f1..70d3112c 100644 --- a/examples/GuiClient/rosterItemSortFilterProxyModel.cpp +++ b/examples/GuiClient/rosterItemSortFilterProxyModel.cpp @@ -1,65 +1,65 @@ -/* - * Copyright (C) 2008-2010 The QXmpp developers - * - * Author: - * Manjeet Dahiya - * - * Source: - * http://code.google.com/p/qxmpp - * - * This file is a part of QXmpp library. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - */ - - -#include "rosterItemSortFilterProxyModel.h" -#include "rosterItem.h" -#include "utils.h" - -rosterItemSortFilterProxyModel::rosterItemSortFilterProxyModel(QObject* parent): - QSortFilterProxyModel(parent) -{ - setDynamicSortFilter(true); - setFilterRole(Qt::DisplayRole); - setFilterCaseSensitivity(Qt::CaseInsensitive); -} - -bool rosterItemSortFilterProxyModel::lessThan(const QModelIndex &left, const QModelIndex &right) const -{ - int leftPresenceType = sourceModel()->data(left, rosterItem::PresenceType).toInt(); - int leftStatusType = sourceModel()->data(left, rosterItem::StatusType).toInt(); - int rightPresenceType = sourceModel()->data(right, rosterItem::PresenceType).toInt(); - int rightStatusType = sourceModel()->data(right, rosterItem::StatusType).toInt(); - - if(leftPresenceType == rightPresenceType) - { - if(leftStatusType == rightStatusType) - { - // based on display text - int compare = left.data().toString().compare(right.data().toString(), Qt::CaseInsensitive); - if(compare < 0) - return true; - else - return false; - } - else - { - return comparisonWeightsPresenceStatusType(static_cast(leftStatusType)) < - comparisonWeightsPresenceStatusType(static_cast(rightStatusType)); - } - } - else - return comparisonWeightsPresenceType(static_cast(leftPresenceType)) < - comparisonWeightsPresenceType(static_cast(rightPresenceType)); -} - +/* + * Copyright (C) 2008-2010 The QXmpp developers + * + * Author: + * Manjeet Dahiya + * + * Source: + * http://code.google.com/p/qxmpp + * + * This file is a part of QXmpp library. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + */ + + +#include "rosterItemSortFilterProxyModel.h" +#include "rosterItem.h" +#include "utils.h" + +rosterItemSortFilterProxyModel::rosterItemSortFilterProxyModel(QObject* parent): + QSortFilterProxyModel(parent) +{ + setDynamicSortFilter(true); + setFilterRole(Qt::DisplayRole); + setFilterCaseSensitivity(Qt::CaseInsensitive); +} + +bool rosterItemSortFilterProxyModel::lessThan(const QModelIndex &left, const QModelIndex &right) const +{ + int leftPresenceType = sourceModel()->data(left, rosterItem::PresenceType).toInt(); + int leftStatusType = sourceModel()->data(left, rosterItem::StatusType).toInt(); + int rightPresenceType = sourceModel()->data(right, rosterItem::PresenceType).toInt(); + int rightStatusType = sourceModel()->data(right, rosterItem::StatusType).toInt(); + + if(leftPresenceType == rightPresenceType) + { + if(leftStatusType == rightStatusType) + { + // based on display text + int compare = left.data().toString().compare(right.data().toString(), Qt::CaseInsensitive); + if(compare < 0) + return true; + else + return false; + } + else + { + return comparisonWeightsPresenceStatusType(static_cast(leftStatusType)) < + comparisonWeightsPresenceStatusType(static_cast(rightStatusType)); + } + } + else + return comparisonWeightsPresenceType(static_cast(leftPresenceType)) < + comparisonWeightsPresenceType(static_cast(rightPresenceType)); +} + diff --git a/examples/GuiClient/rosterItemSortFilterProxyModel.h b/examples/GuiClient/rosterItemSortFilterProxyModel.h index e4e9e08e..7a639a21 100644 --- a/examples/GuiClient/rosterItemSortFilterProxyModel.h +++ b/examples/GuiClient/rosterItemSortFilterProxyModel.h @@ -1,37 +1,37 @@ -/* - * Copyright (C) 2008-2010 The QXmpp developers - * - * Author: - * Manjeet Dahiya - * - * Source: - * http://code.google.com/p/qxmpp - * - * This file is a part of QXmpp library. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - */ - - -#ifndef ROSTERITEMSORTFILTERPROXYMODEL_H -#define ROSTERITEMSORTFILTERPROXYMODEL_H - -#include - -class rosterItemSortFilterProxyModel : public QSortFilterProxyModel -{ -public: - rosterItemSortFilterProxyModel(QObject* parent = 0); - bool lessThan(const QModelIndex &left, const QModelIndex &right) const; -}; - -#endif // ROSTERITEMSORTFILTERPROXYMODEL_H +/* + * Copyright (C) 2008-2010 The QXmpp developers + * + * Author: + * Manjeet Dahiya + * + * Source: + * http://code.google.com/p/qxmpp + * + * This file is a part of QXmpp library. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + */ + + +#ifndef ROSTERITEMSORTFILTERPROXYMODEL_H +#define ROSTERITEMSORTFILTERPROXYMODEL_H + +#include + +class rosterItemSortFilterProxyModel : public QSortFilterProxyModel +{ +public: + rosterItemSortFilterProxyModel(QObject* parent = 0); + bool lessThan(const QModelIndex &left, const QModelIndex &right) const; +}; + +#endif // ROSTERITEMSORTFILTERPROXYMODEL_H diff --git a/examples/GuiClient/searchLineEdit.cpp b/examples/GuiClient/searchLineEdit.cpp index 8f6ff64a..5e755f76 100644 --- a/examples/GuiClient/searchLineEdit.cpp +++ b/examples/GuiClient/searchLineEdit.cpp @@ -1,77 +1,77 @@ -/* - * Copyright (C) 2008-2010 The QXmpp developers - * - * Author: - * Manjeet Dahiya - * - * Source: - * http://code.google.com/p/qxmpp - * - * This file is a part of QXmpp library. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - */ - - -#include "searchLineEdit.h" - -searchLineEdit::searchLineEdit(QWidget* parent):QLineEdit(parent) -{ - setMinimumSize(QSize(20, 24)); - setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); - - setStyleSheet(":enabled { padding-right: 20px; padding-left: 20px }"); - clearButton = new ClearButton(this); - clearButton->setVisible(true); - - clearButton->setCursor(Qt::ArrowCursor); - clearButton->setToolTip("Clear"); - connect(clearButton, SIGNAL(clicked()), this, SLOT(clear())); -} - -void searchLineEdit::paintEvent(QPaintEvent *e) { - QLineEdit::paintEvent(e); - QPainter painter(this); - - QImage image(":/icons/resource/searchIcon.png"); - - QRectF target(image.rect()); - target.moveCenter(QPointF(target.center().x()+2, target.center().y()+3)); - painter.drawImage(target, image, image.rect()); - - if (text().length() == 0 && (!hasFocus()) ) - { - painter.setPen(Qt::gray); - QRect r = rect(); - painter.drawText(24, r.height()/2+4, "Search Contacts"); - } - - if(text().isEmpty()) - clearButton->setVisible(false); - else - clearButton->setVisible(true); -} - -void searchLineEdit::resizeEvent(QResizeEvent*) -{ - clearButton->setParent(this); - clearButton->setGeometry(QRect(width()-23, - 0, - 24, 24)); -} - -void searchLineEdit::moveEvent(QMoveEvent*) -{ - clearButton->setParent(this); - clearButton->setGeometry(QRect(width()-23, 1, - 24, 24)); -} +/* + * Copyright (C) 2008-2010 The QXmpp developers + * + * Author: + * Manjeet Dahiya + * + * Source: + * http://code.google.com/p/qxmpp + * + * This file is a part of QXmpp library. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + */ + + +#include "searchLineEdit.h" + +searchLineEdit::searchLineEdit(QWidget* parent):QLineEdit(parent) +{ + setMinimumSize(QSize(20, 24)); + setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); + + setStyleSheet(":enabled { padding-right: 20px; padding-left: 20px }"); + clearButton = new ClearButton(this); + clearButton->setVisible(true); + + clearButton->setCursor(Qt::ArrowCursor); + clearButton->setToolTip("Clear"); + connect(clearButton, SIGNAL(clicked()), this, SLOT(clear())); +} + +void searchLineEdit::paintEvent(QPaintEvent *e) { + QLineEdit::paintEvent(e); + QPainter painter(this); + + QImage image(":/icons/resource/searchIcon.png"); + + QRectF target(image.rect()); + target.moveCenter(QPointF(target.center().x()+2, target.center().y()+3)); + painter.drawImage(target, image, image.rect()); + + if (text().length() == 0 && (!hasFocus()) ) + { + painter.setPen(Qt::gray); + QRect r = rect(); + painter.drawText(24, r.height()/2+4, "Search Contacts"); + } + + if(text().isEmpty()) + clearButton->setVisible(false); + else + clearButton->setVisible(true); +} + +void searchLineEdit::resizeEvent(QResizeEvent*) +{ + clearButton->setParent(this); + clearButton->setGeometry(QRect(width()-23, + 0, + 24, 24)); +} + +void searchLineEdit::moveEvent(QMoveEvent*) +{ + clearButton->setParent(this); + clearButton->setGeometry(QRect(width()-23, 1, + 24, 24)); +} diff --git a/examples/GuiClient/searchLineEdit.h b/examples/GuiClient/searchLineEdit.h index e1946d5b..e950196e 100644 --- a/examples/GuiClient/searchLineEdit.h +++ b/examples/GuiClient/searchLineEdit.h @@ -1,82 +1,82 @@ -/* - * Copyright (C) 2008-2010 The QXmpp developers - * - * Author: - * Manjeet Dahiya - * - * Source: - * http://code.google.com/p/qxmpp - * - * This file is a part of QXmpp library. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - */ - - -#ifndef SEARCHLINEEDIT_H -#define SEARCHLINEEDIT_H - -#include -#include -#include - -class ClearButton : public QPushButton -{ - Q_OBJECT - -public: - ClearButton(QWidget *w) - : QPushButton(w) - { - setMinimumSize(24, 24); - setFixedSize(24, 24); - setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); - } - void paintEvent(QPaintEvent *event) - { - Q_UNUSED(event); - QPainter painter(this); - int height = parentWidget()->geometry().height(); - int width = height; //parentWidget()->geometry().width(); - - painter.setRenderHint(QPainter::Antialiasing, true); - painter.setPen(Qt::white); - - float penwidth = isDown() ? 1.2 : - underMouse() ? 1.6 : 1.2; - painter.setBrush(Qt::red); - //painter.drawEllipse(4, 4, width - 8, height - 8); - QPen pen; - pen.setWidthF(penwidth); - pen.setColor(Qt::black); - painter.setPen(pen); - int border = 7; - painter.drawLine(border, border, width - border, height - border); - painter.drawLine(border, height - border, width - border, border); - } -}; - -class searchLineEdit : public QLineEdit -{ -public: - searchLineEdit(QWidget* parent = 0); - -protected: - virtual void paintEvent(QPaintEvent* e); - virtual void resizeEvent(QResizeEvent*); - virtual void moveEvent(QMoveEvent*); - -private: - QPushButton *clearButton; -}; - -#endif // SEARCHLINEEDIT_H +/* + * Copyright (C) 2008-2010 The QXmpp developers + * + * Author: + * Manjeet Dahiya + * + * Source: + * http://code.google.com/p/qxmpp + * + * This file is a part of QXmpp library. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + */ + + +#ifndef SEARCHLINEEDIT_H +#define SEARCHLINEEDIT_H + +#include +#include +#include + +class ClearButton : public QPushButton +{ + Q_OBJECT + +public: + ClearButton(QWidget *w) + : QPushButton(w) + { + setMinimumSize(24, 24); + setFixedSize(24, 24); + setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); + } + void paintEvent(QPaintEvent *event) + { + Q_UNUSED(event); + QPainter painter(this); + int height = parentWidget()->geometry().height(); + int width = height; //parentWidget()->geometry().width(); + + painter.setRenderHint(QPainter::Antialiasing, true); + painter.setPen(Qt::white); + + float penwidth = isDown() ? 1.2 : + underMouse() ? 1.6 : 1.2; + painter.setBrush(Qt::red); + //painter.drawEllipse(4, 4, width - 8, height - 8); + QPen pen; + pen.setWidthF(penwidth); + pen.setColor(Qt::black); + painter.setPen(pen); + int border = 7; + painter.drawLine(border, border, width - border, height - border); + painter.drawLine(border, height - border, width - border, border); + } +}; + +class searchLineEdit : public QLineEdit +{ +public: + searchLineEdit(QWidget* parent = 0); + +protected: + virtual void paintEvent(QPaintEvent* e); + virtual void resizeEvent(QResizeEvent*); + virtual void moveEvent(QMoveEvent*); + +private: + QPushButton *clearButton; +}; + +#endif // SEARCHLINEEDIT_H diff --git a/examples/GuiClient/statusTextWidget.cpp b/examples/GuiClient/statusTextWidget.cpp index 7ebfbc54..17a36dc7 100644 --- a/examples/GuiClient/statusTextWidget.cpp +++ b/examples/GuiClient/statusTextWidget.cpp @@ -1,168 +1,168 @@ -/* - * Copyright (C) 2008-2010 The QXmpp developers - * - * Author: - * Manjeet Dahiya - * - * Source: - * http://code.google.com/p/qxmpp - * - * This file is a part of QXmpp library. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - */ - - -#include "statusTextWidget.h" -#include -#include - -#include -#include - -QSize statusLineEdit::sizeHint() const -{ - QFont font; - QFontMetrics fm(font); - int width = fm.width(text()); - if(width <= (160 - 8)) - return QSize(width+8, 18); - else - return QSize(160, 18); -} - -void statusLineEditButton::paintEvent(QPaintEvent* event) -{ - Q_UNUSED(event); - QPainter painter(this); - - QStyleOptionButton panel; - initStyleOption(&panel); - QRect r = style()->subElementRect(QStyle::SE_PushButtonFocusRect, &panel, this); - - QImage image(":/icons/resource/downArrow.png"); - QRect rectDelta(0, 0, 7, 4); - rectDelta.moveCenter(r.center()); - painter.drawImage(rectDelta, image); -} - -void statusLineEdit::focusInEvent(QFocusEvent* event) -{ - QLineEdit::focusInEvent(event); - QLineEdit::selectAll(); -} - -void statusLineEdit::mousePressEvent(QMouseEvent* event) -{ - QLineEdit::mousePressEvent(event); - QLineEdit::selectAll(); -} - -statusTextWidget::statusTextWidget(QWidget* parent) : QWidget(parent), - m_statusLineEdit(0), m_statusButton(0), m_clearStatusTextHistory("Clear Status Message", this) -{ - m_statusLineEdit = new statusLineEdit(this); - QHBoxLayout* layout = new QHBoxLayout; - layout->addWidget(m_statusLineEdit); - layout->setSpacing(0); - layout->setContentsMargins(0, 0, 0, 0); - m_statusButton = new statusLineEditButton(this); - layout->addWidget(m_statusButton); - setLayout(layout); - - bool check = connect(m_statusButton, SIGNAL(clicked(bool)), SLOT(showMenu())); - Q_ASSERT(check); - check = connect(m_statusLineEdit, SIGNAL(textChanged(const QString&)), SLOT(textChanged())); - Q_ASSERT(check); - check = connect(m_statusLineEdit, SIGNAL(editingFinished()), SLOT(statusTextChanged_helper())); - Q_ASSERT(check); - check = connect(&m_clearStatusTextHistory, SIGNAL(triggered()), SLOT(clearStatusTextHistory())); - Q_ASSERT(check); -} - -void statusTextWidget::showMenu() -{ - QMenu menu(this); - - int size = m_statusTextActionList.size(); - for(int i = 0; i < size; ++i) - { - menu.addAction(m_statusTextActionList.at(size - 1 - i)); - } - - menu.addSeparator(); - menu.addAction(&m_clearStatusTextHistory); - m_clearStatusTextHistory.setDisabled(size == 0); - menu.exec(m_statusLineEdit->mapToGlobal(QPoint(0, m_statusLineEdit->height()))); -} - -void statusTextWidget::textChanged() -{ - m_statusLineEdit->updateGeometry(); -} - -void statusTextWidget::statusTextChanged_helper() -{ - addStatusTextToList(m_statusLineEdit->text()); - emit statusTextChanged(m_statusLineEdit->text()); - parentWidget()->setFocus(); -} - -void statusTextWidget::setStatusText(const QString& statusText) -{ - m_statusLineEdit->setText(statusText); -} - -void statusTextWidget::addStatusTextToList(const QString& status) -{ - for(int i = 0; i < m_statusTextActionList.size(); ++i) - { - if(m_statusTextActionList.at(i)->data().toString() == status) - { - QAction* action = m_statusTextActionList.takeAt(i); - m_statusTextActionList.append(action); - return; - } - } - - QAction* action = new QAction(status, this); - action->setData(status); - bool check = connect(action, SIGNAL(triggered()), SLOT(statusTextChanged_menuClick())); - Q_ASSERT(check); - m_statusTextActionList.append(action); -} - -void statusTextWidget::statusTextChanged_menuClick() -{ - QAction* action = qobject_cast(sender()); - if(action) - { - int i = 0; - while(i < m_statusTextActionList.size() && action != m_statusTextActionList.at(i)) - { - ++i; - } - - if(action == m_statusTextActionList.at(i)) - { - m_statusTextActionList.removeAt(i); - m_statusTextActionList.append(action); - } - m_statusLineEdit->setText(action->data().toString()); - emit statusTextChanged(action->data().toString()); - } -} - -void statusTextWidget::clearStatusTextHistory() -{ - emit statusTextChanged(""); -} +/* + * Copyright (C) 2008-2010 The QXmpp developers + * + * Author: + * Manjeet Dahiya + * + * Source: + * http://code.google.com/p/qxmpp + * + * This file is a part of QXmpp library. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + */ + + +#include "statusTextWidget.h" +#include +#include + +#include +#include + +QSize statusLineEdit::sizeHint() const +{ + QFont font; + QFontMetrics fm(font); + int width = fm.width(text()); + if(width <= (160 - 8)) + return QSize(width+8, 18); + else + return QSize(160, 18); +} + +void statusLineEditButton::paintEvent(QPaintEvent* event) +{ + Q_UNUSED(event); + QPainter painter(this); + + QStyleOptionButton panel; + initStyleOption(&panel); + QRect r = style()->subElementRect(QStyle::SE_PushButtonFocusRect, &panel, this); + + QImage image(":/icons/resource/downArrow.png"); + QRect rectDelta(0, 0, 7, 4); + rectDelta.moveCenter(r.center()); + painter.drawImage(rectDelta, image); +} + +void statusLineEdit::focusInEvent(QFocusEvent* event) +{ + QLineEdit::focusInEvent(event); + QLineEdit::selectAll(); +} + +void statusLineEdit::mousePressEvent(QMouseEvent* event) +{ + QLineEdit::mousePressEvent(event); + QLineEdit::selectAll(); +} + +statusTextWidget::statusTextWidget(QWidget* parent) : QWidget(parent), + m_statusLineEdit(0), m_statusButton(0), m_clearStatusTextHistory("Clear Status Message", this) +{ + m_statusLineEdit = new statusLineEdit(this); + QHBoxLayout* layout = new QHBoxLayout; + layout->addWidget(m_statusLineEdit); + layout->setSpacing(0); + layout->setContentsMargins(0, 0, 0, 0); + m_statusButton = new statusLineEditButton(this); + layout->addWidget(m_statusButton); + setLayout(layout); + + bool check = connect(m_statusButton, SIGNAL(clicked(bool)), SLOT(showMenu())); + Q_ASSERT(check); + check = connect(m_statusLineEdit, SIGNAL(textChanged(const QString&)), SLOT(textChanged())); + Q_ASSERT(check); + check = connect(m_statusLineEdit, SIGNAL(editingFinished()), SLOT(statusTextChanged_helper())); + Q_ASSERT(check); + check = connect(&m_clearStatusTextHistory, SIGNAL(triggered()), SLOT(clearStatusTextHistory())); + Q_ASSERT(check); +} + +void statusTextWidget::showMenu() +{ + QMenu menu(this); + + int size = m_statusTextActionList.size(); + for(int i = 0; i < size; ++i) + { + menu.addAction(m_statusTextActionList.at(size - 1 - i)); + } + + menu.addSeparator(); + menu.addAction(&m_clearStatusTextHistory); + m_clearStatusTextHistory.setDisabled(size == 0); + menu.exec(m_statusLineEdit->mapToGlobal(QPoint(0, m_statusLineEdit->height()))); +} + +void statusTextWidget::textChanged() +{ + m_statusLineEdit->updateGeometry(); +} + +void statusTextWidget::statusTextChanged_helper() +{ + addStatusTextToList(m_statusLineEdit->text()); + emit statusTextChanged(m_statusLineEdit->text()); + parentWidget()->setFocus(); +} + +void statusTextWidget::setStatusText(const QString& statusText) +{ + m_statusLineEdit->setText(statusText); +} + +void statusTextWidget::addStatusTextToList(const QString& status) +{ + for(int i = 0; i < m_statusTextActionList.size(); ++i) + { + if(m_statusTextActionList.at(i)->data().toString() == status) + { + QAction* action = m_statusTextActionList.takeAt(i); + m_statusTextActionList.append(action); + return; + } + } + + QAction* action = new QAction(status, this); + action->setData(status); + bool check = connect(action, SIGNAL(triggered()), SLOT(statusTextChanged_menuClick())); + Q_ASSERT(check); + m_statusTextActionList.append(action); +} + +void statusTextWidget::statusTextChanged_menuClick() +{ + QAction* action = qobject_cast(sender()); + if(action) + { + int i = 0; + while(i < m_statusTextActionList.size() && action != m_statusTextActionList.at(i)) + { + ++i; + } + + if(action == m_statusTextActionList.at(i)) + { + m_statusTextActionList.removeAt(i); + m_statusTextActionList.append(action); + } + m_statusLineEdit->setText(action->data().toString()); + emit statusTextChanged(action->data().toString()); + } +} + +void statusTextWidget::clearStatusTextHistory() +{ + emit statusTextChanged(""); +} diff --git a/examples/GuiClient/statusTextWidget.h b/examples/GuiClient/statusTextWidget.h index db62f1b0..3c9348ad 100644 --- a/examples/GuiClient/statusTextWidget.h +++ b/examples/GuiClient/statusTextWidget.h @@ -1,135 +1,135 @@ -/* - * Copyright (C) 2008-2010 The QXmpp developers - * - * Author: - * Manjeet Dahiya - * - * Source: - * http://code.google.com/p/qxmpp - * - * This file is a part of QXmpp library. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - */ - - -#ifndef STATUSTEXTWIDGET_H -#define STATUSTEXTWIDGET_H - -#include -#include -#include -#include -#include -#include -#include - - -class statusLineEditButton : public QPushButton -{ - Q_OBJECT - -public: - statusLineEditButton(QWidget* parent = 0): QPushButton(parent) - { - setCursor(Qt::PointingHandCursor); - } - void paintEvent(QPaintEvent* event); - QSize sizeHint() const - { - return QSize(14, 14); - } -}; - -class statusLineEdit : public QLineEdit -{ -public: - statusLineEdit(QWidget* parent = 0) : QLineEdit(parent) - { - setAttribute(Qt::WA_Hover, true); - setText("Available"); - setMinimumSize(QSize(20, 18)); - } - void focusInEvent(QFocusEvent* event); - void mousePressEvent(QMouseEvent* event); - - void paintEvent(QPaintEvent* event) - { - if(hasFocus()) - { - QLineEdit::paintEvent(event); - } - else - { - QPainter p(this); - QRect r = rect(); - QPalette pal = palette(); - - QStyleOptionFrameV2 panel; - initStyleOption(&panel); - r = style()->subElementRect(QStyle::SE_LineEditContents, &panel, this); - r.adjust(-1, -1, 0, 0); - r.setLeft(r.left() + 4); - p.setPen(Qt::darkGray); - p.drawText(r, Qt::AlignVCenter, text()); - } - - if(underMouse() && !hasFocus()) - { - QPainter p(this); - QRect r = rect(); - QPalette pal = palette(); - - QStyleOptionFrameV2 panel; - initStyleOption(&panel); - r = style()->subElementRect(QStyle::SE_LineEditContents, &panel, this); - r.adjust(-1, -1, 0, 0); - p.setPen(Qt::gray); - p.drawRect(r); - r.setLeft(r.left() + 4); - p.setPen(Qt::darkGray); - p.drawText(r, Qt::AlignVCenter, text()); - } - } - QSize sizeHint() const; -}; - -class statusTextWidget : public QWidget -{ - Q_OBJECT - -public: - statusTextWidget(QWidget* parent = 0); - void setStatusText(const QString& statusText); - -public slots: - void showMenu(); - void textChanged(); - -private slots: - void statusTextChanged_helper(); - void statusTextChanged_menuClick(); - void clearStatusTextHistory(); - -signals: - void statusTextChanged(const QString&); - -private: - void addStatusTextToList(const QString& status); - statusLineEdit* m_statusLineEdit; - statusLineEditButton* m_statusButton; - - QList m_statusTextActionList; - QAction m_clearStatusTextHistory; -}; - -#endif // STATUSTEXTWIDGET_H +/* + * Copyright (C) 2008-2010 The QXmpp developers + * + * Author: + * Manjeet Dahiya + * + * Source: + * http://code.google.com/p/qxmpp + * + * This file is a part of QXmpp library. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + */ + + +#ifndef STATUSTEXTWIDGET_H +#define STATUSTEXTWIDGET_H + +#include +#include +#include +#include +#include +#include +#include + + +class statusLineEditButton : public QPushButton +{ + Q_OBJECT + +public: + statusLineEditButton(QWidget* parent = 0): QPushButton(parent) + { + setCursor(Qt::PointingHandCursor); + } + void paintEvent(QPaintEvent* event); + QSize sizeHint() const + { + return QSize(14, 14); + } +}; + +class statusLineEdit : public QLineEdit +{ +public: + statusLineEdit(QWidget* parent = 0) : QLineEdit(parent) + { + setAttribute(Qt::WA_Hover, true); + setText("Available"); + setMinimumSize(QSize(20, 18)); + } + void focusInEvent(QFocusEvent* event); + void mousePressEvent(QMouseEvent* event); + + void paintEvent(QPaintEvent* event) + { + if(hasFocus()) + { + QLineEdit::paintEvent(event); + } + else + { + QPainter p(this); + QRect r = rect(); + QPalette pal = palette(); + + QStyleOptionFrameV2 panel; + initStyleOption(&panel); + r = style()->subElementRect(QStyle::SE_LineEditContents, &panel, this); + r.adjust(-1, -1, 0, 0); + r.setLeft(r.left() + 4); + p.setPen(Qt::darkGray); + p.drawText(r, Qt::AlignVCenter, text()); + } + + if(underMouse() && !hasFocus()) + { + QPainter p(this); + QRect r = rect(); + QPalette pal = palette(); + + QStyleOptionFrameV2 panel; + initStyleOption(&panel); + r = style()->subElementRect(QStyle::SE_LineEditContents, &panel, this); + r.adjust(-1, -1, 0, 0); + p.setPen(Qt::gray); + p.drawRect(r); + r.setLeft(r.left() + 4); + p.setPen(Qt::darkGray); + p.drawText(r, Qt::AlignVCenter, text()); + } + } + QSize sizeHint() const; +}; + +class statusTextWidget : public QWidget +{ + Q_OBJECT + +public: + statusTextWidget(QWidget* parent = 0); + void setStatusText(const QString& statusText); + +public slots: + void showMenu(); + void textChanged(); + +private slots: + void statusTextChanged_helper(); + void statusTextChanged_menuClick(); + void clearStatusTextHistory(); + +signals: + void statusTextChanged(const QString&); + +private: + void addStatusTextToList(const QString& status); + statusLineEdit* m_statusLineEdit; + statusLineEditButton* m_statusButton; + + QList m_statusTextActionList; + QAction m_clearStatusTextHistory; +}; + +#endif // STATUSTEXTWIDGET_H diff --git a/examples/GuiClient/statusWidget.cpp b/examples/GuiClient/statusWidget.cpp index 960be0d3..e3e47940 100644 --- a/examples/GuiClient/statusWidget.cpp +++ b/examples/GuiClient/statusWidget.cpp @@ -1,154 +1,154 @@ -/* - * Copyright (C) 2008-2010 The QXmpp developers - * - * Author: - * Manjeet Dahiya - * - * Source: - * http://code.google.com/p/qxmpp - * - * This file is a part of QXmpp library. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - */ - - -#include "statusWidget.h" -#include -#include -#include - -statusWidget::statusWidget(QWidget* parent) -{ - setupUi(this); - QMenu* menu = new QMenu(this); - menu->addAction(actionAvailable); - menu->addAction(actionBusy); - menu->addAction(actionAway); -// menu->addAction(actionInvisible); - menu->addSeparator(); - menu->addAction(actionSign_out); - toolButton_userName->setMenu(menu); - - bool check = connect(statusTextWidgetObject, SIGNAL(statusTextChanged(const QString&)), SIGNAL(statusTextChanged(const QString&))); - Q_ASSERT(check); - - check = connect(actionAvailable, SIGNAL(triggered()), SLOT(presenceMenuTriggered())); - Q_ASSERT(check); - check = connect(actionBusy, SIGNAL(triggered()), SLOT(presenceMenuTriggered())); - Q_ASSERT(check); - check = connect(actionAway, SIGNAL(triggered()), SLOT(presenceMenuTriggered())); - Q_ASSERT(check); - check = connect(actionInvisible, SIGNAL(triggered()), SLOT(presenceMenuTriggered())); - Q_ASSERT(check); - check = connect(actionSign_out, SIGNAL(triggered()), SLOT(presenceMenuTriggered())); - Q_ASSERT(check); - - check = connect(pushButton_avatar, SIGNAL(clicked()), SLOT(avatarSelection())); - Q_ASSERT(check); -} - -void statusWidget::setStatusText(const QString& statusText) -{ - statusTextWidgetObject->setStatusText(statusText); -} - -void statusWidget::presenceMenuTriggered() -{ - QString icon = "green"; - QAction* action = qobject_cast(sender()); - if(action == actionAvailable) - { - emit presenceTypeChanged(QXmppPresence::Available); - icon = "green"; - } - else if(action == actionBusy) - { - emit presenceStatusTypeChanged(QXmppPresence::Status::DND); - icon = "red"; - } - else if(action == actionAway) - { - emit presenceStatusTypeChanged(QXmppPresence::Status::Away); - icon = "orange"; - } - else if(action == actionInvisible) - { - emit presenceStatusTypeChanged(QXmppPresence::Status::Invisible); - icon = "gray"; - } - else if(action == actionSign_out) - { - emit presenceTypeChanged(QXmppPresence::Unavailable); - icon = "gray"; - } - label->setPixmap(QPixmap(":/icons/resource/"+icon+".png")); -} - -void statusWidget::setPresenceAndStatusType(QXmppPresence::Type presenceType, - QXmppPresence::Status::Type statusType) -{ - if(presenceType == QXmppPresence::Available) - { - QString icon = "green"; - switch(statusType) - { - case QXmppPresence::Status::Online: - case QXmppPresence::Status::Chat: - icon = "green"; - break; - case QXmppPresence::Status::Away: - case QXmppPresence::Status::XA: - icon = "orange"; - break; - case QXmppPresence::Status::DND: - icon = "red"; - break; - case QXmppPresence::Status::Invisible: - case QXmppPresence::Status::Offline: - icon = "gray"; - break; - } - label->setPixmap(QPixmap(":/icons/resource/"+icon+".png")); - } - else if(presenceType == QXmppPresence::Unavailable) - { - label->setPixmap(QPixmap(":/icons/resource/gray.png")); - } -} - -void statusWidget::avatarSelection() -{ - QString file = QFileDialog::getOpenFileName(this, "Select your avatar"); - if(file.isEmpty()) - return; - - QImage image; - if(image.load(file)) - { - QImage scaled = image.scaled(QSize(96, 96), Qt::KeepAspectRatio, - Qt::SmoothTransformation); - emit avatarChanged(scaled); - } - else - QMessageBox::information(this, "Avatar selection", "Invalid image file"); -} - -void statusWidget::setDisplayName(const QString& name) -{ - toolButton_userName->setText(name); -} - -void statusWidget::setAvatar(const QImage& image) -{ - pushButton_avatar->setIcon(QIcon(QPixmap::fromImage(image))); -} +/* + * Copyright (C) 2008-2010 The QXmpp developers + * + * Author: + * Manjeet Dahiya + * + * Source: + * http://code.google.com/p/qxmpp + * + * This file is a part of QXmpp library. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + */ + + +#include "statusWidget.h" +#include +#include +#include + +statusWidget::statusWidget(QWidget* parent) +{ + setupUi(this); + QMenu* menu = new QMenu(this); + menu->addAction(actionAvailable); + menu->addAction(actionBusy); + menu->addAction(actionAway); +// menu->addAction(actionInvisible); + menu->addSeparator(); + menu->addAction(actionSign_out); + toolButton_userName->setMenu(menu); + + bool check = connect(statusTextWidgetObject, SIGNAL(statusTextChanged(const QString&)), SIGNAL(statusTextChanged(const QString&))); + Q_ASSERT(check); + + check = connect(actionAvailable, SIGNAL(triggered()), SLOT(presenceMenuTriggered())); + Q_ASSERT(check); + check = connect(actionBusy, SIGNAL(triggered()), SLOT(presenceMenuTriggered())); + Q_ASSERT(check); + check = connect(actionAway, SIGNAL(triggered()), SLOT(presenceMenuTriggered())); + Q_ASSERT(check); + check = connect(actionInvisible, SIGNAL(triggered()), SLOT(presenceMenuTriggered())); + Q_ASSERT(check); + check = connect(actionSign_out, SIGNAL(triggered()), SLOT(presenceMenuTriggered())); + Q_ASSERT(check); + + check = connect(pushButton_avatar, SIGNAL(clicked()), SLOT(avatarSelection())); + Q_ASSERT(check); +} + +void statusWidget::setStatusText(const QString& statusText) +{ + statusTextWidgetObject->setStatusText(statusText); +} + +void statusWidget::presenceMenuTriggered() +{ + QString icon = "green"; + QAction* action = qobject_cast(sender()); + if(action == actionAvailable) + { + emit presenceTypeChanged(QXmppPresence::Available); + icon = "green"; + } + else if(action == actionBusy) + { + emit presenceStatusTypeChanged(QXmppPresence::Status::DND); + icon = "red"; + } + else if(action == actionAway) + { + emit presenceStatusTypeChanged(QXmppPresence::Status::Away); + icon = "orange"; + } + else if(action == actionInvisible) + { + emit presenceStatusTypeChanged(QXmppPresence::Status::Invisible); + icon = "gray"; + } + else if(action == actionSign_out) + { + emit presenceTypeChanged(QXmppPresence::Unavailable); + icon = "gray"; + } + label->setPixmap(QPixmap(":/icons/resource/"+icon+".png")); +} + +void statusWidget::setPresenceAndStatusType(QXmppPresence::Type presenceType, + QXmppPresence::Status::Type statusType) +{ + if(presenceType == QXmppPresence::Available) + { + QString icon = "green"; + switch(statusType) + { + case QXmppPresence::Status::Online: + case QXmppPresence::Status::Chat: + icon = "green"; + break; + case QXmppPresence::Status::Away: + case QXmppPresence::Status::XA: + icon = "orange"; + break; + case QXmppPresence::Status::DND: + icon = "red"; + break; + case QXmppPresence::Status::Invisible: + case QXmppPresence::Status::Offline: + icon = "gray"; + break; + } + label->setPixmap(QPixmap(":/icons/resource/"+icon+".png")); + } + else if(presenceType == QXmppPresence::Unavailable) + { + label->setPixmap(QPixmap(":/icons/resource/gray.png")); + } +} + +void statusWidget::avatarSelection() +{ + QString file = QFileDialog::getOpenFileName(this, "Select your avatar"); + if(file.isEmpty()) + return; + + QImage image; + if(image.load(file)) + { + QImage scaled = image.scaled(QSize(96, 96), Qt::KeepAspectRatio, + Qt::SmoothTransformation); + emit avatarChanged(scaled); + } + else + QMessageBox::information(this, "Avatar selection", "Invalid image file"); +} + +void statusWidget::setDisplayName(const QString& name) +{ + toolButton_userName->setText(name); +} + +void statusWidget::setAvatar(const QImage& image) +{ + pushButton_avatar->setIcon(QIcon(QPixmap::fromImage(image))); +} diff --git a/examples/GuiClient/statusWidget.h b/examples/GuiClient/statusWidget.h index de31fbcf..d2d20810 100644 --- a/examples/GuiClient/statusWidget.h +++ b/examples/GuiClient/statusWidget.h @@ -1,53 +1,53 @@ -/* - * Copyright (C) 2008-2010 The QXmpp developers - * - * Author: - * Manjeet Dahiya - * - * Source: - * http://code.google.com/p/qxmpp - * - * This file is a part of QXmpp library. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - */ - - -#ifndef STATUSWIDGET_H -#define STATUSWIDGET_H -#include "ui_statusWidget.h" -#include "QXmppPresence.h" - -class statusWidget : public QWidget, public Ui::statusWidgetClass -{ - Q_OBJECT - -public: - statusWidget(QWidget* parent = 0); - void setDisplayName(const QString& name); - void setStatusText(const QString& statusText); - void setPresenceAndStatusType(QXmppPresence::Type presenceType, - QXmppPresence::Status::Type statusType); - void setAvatar(const QImage&); - -private slots: - void presenceMenuTriggered(); - void avatarSelection(); - -signals: - void statusTextChanged(const QString&); - void presenceTypeChanged(QXmppPresence::Type); - void presenceStatusTypeChanged(QXmppPresence::Status::Type); - void avatarChanged(const QImage&); -}; - -#endif // STATUSWIDGET_H +/* + * Copyright (C) 2008-2010 The QXmpp developers + * + * Author: + * Manjeet Dahiya + * + * Source: + * http://code.google.com/p/qxmpp + * + * This file is a part of QXmpp library. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + */ + + +#ifndef STATUSWIDGET_H +#define STATUSWIDGET_H +#include "ui_statusWidget.h" +#include "QXmppPresence.h" + +class statusWidget : public QWidget, public Ui::statusWidgetClass +{ + Q_OBJECT + +public: + statusWidget(QWidget* parent = 0); + void setDisplayName(const QString& name); + void setStatusText(const QString& statusText); + void setPresenceAndStatusType(QXmppPresence::Type presenceType, + QXmppPresence::Status::Type statusType); + void setAvatar(const QImage&); + +private slots: + void presenceMenuTriggered(); + void avatarSelection(); + +signals: + void statusTextChanged(const QString&); + void presenceTypeChanged(QXmppPresence::Type); + void presenceStatusTypeChanged(QXmppPresence::Status::Type); + void avatarChanged(const QImage&); +}; + +#endif // STATUSWIDGET_H diff --git a/examples/GuiClient/statusWidget.ui b/examples/GuiClient/statusWidget.ui index 758fa63b..32e27d9c 100644 --- a/examples/GuiClient/statusWidget.ui +++ b/examples/GuiClient/statusWidget.ui @@ -1,213 +1,213 @@ - - - statusWidgetClass - - - - 0 - 0 - 251 - 40 - - - - Form - - - - 0 - - - 4 - - - 0 - - - 4 - - - 0 - - - - - - 0 - 0 - - - - - - - :/icons/resource/green.png - - - - - - - 0 - - - 3 - - - - - 0 - - - - - toolbutton - - - QToolButton::InstantPopup - - - Qt::ToolButtonTextBesideIcon - - - true - - - Qt::DownArrow - - - - - - - Qt::Horizontal - - - - 40 - 10 - - - - - - - - - - 0 - - - - - - 0 - 0 - - - - - - - - Qt::Horizontal - - - - 40 - 10 - - - - - - - - - - - - - - - - :/icons/resource/avatar.png:/icons/resource/avatar.png - - - - 32 - 32 - - - - - - - - - :/icons/resource/red.png:/icons/resource/red.png - - - Busy - - - - - - :/icons/resource/green.png:/icons/resource/green.png - - - Available - - - - - - :/icons/resource/gray.png:/icons/resource/gray.png - - - Invisible - - - - - - :/icons/resource/gray.png:/icons/resource/gray.png - - - Sign out - - - - - - :/icons/resource/orange.png:/icons/resource/orange.png - - - Away - - - - - - avatarWidget - QPushButton -
avatarWidget.h
-
- - statusTextWidget - QWidget -
statusTextWidget.h
- 1 -
- - customToolButton - QToolButton -
customToolButton.h
-
-
- - - - -
+ + + statusWidgetClass + + + + 0 + 0 + 251 + 40 + + + + Form + + + + 0 + + + 4 + + + 0 + + + 4 + + + 0 + + + + + + 0 + 0 + + + + + + + :/icons/resource/green.png + + + + + + + 0 + + + 3 + + + + + 0 + + + + + toolbutton + + + QToolButton::InstantPopup + + + Qt::ToolButtonTextBesideIcon + + + true + + + Qt::DownArrow + + + + + + + Qt::Horizontal + + + + 40 + 10 + + + + + + + + + + 0 + + + + + + 0 + 0 + + + + + + + + Qt::Horizontal + + + + 40 + 10 + + + + + + + + + + + + + + + + :/icons/resource/avatar.png:/icons/resource/avatar.png + + + + 32 + 32 + + + + + + + + + :/icons/resource/red.png:/icons/resource/red.png + + + Busy + + + + + + :/icons/resource/green.png:/icons/resource/green.png + + + Available + + + + + + :/icons/resource/gray.png:/icons/resource/gray.png + + + Invisible + + + + + + :/icons/resource/gray.png:/icons/resource/gray.png + + + Sign out + + + + + + :/icons/resource/orange.png:/icons/resource/orange.png + + + Away + + + + + + avatarWidget + QPushButton +
avatarWidget.h
+
+ + statusTextWidget + QWidget +
statusTextWidget.h
+ 1 +
+ + customToolButton + QToolButton +
customToolButton.h
+
+
+ + + + +
diff --git a/examples/GuiClient/utils.cpp b/examples/GuiClient/utils.cpp index 251a7366..cea1c48a 100644 --- a/examples/GuiClient/utils.cpp +++ b/examples/GuiClient/utils.cpp @@ -1,151 +1,151 @@ -/* - * Copyright (C) 2008-2010 The QXmpp developers - * - * Author: - * Manjeet Dahiya - * - * Source: - * http://code.google.com/p/qxmpp - * - * This file is a part of QXmpp library. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - */ - - -#include "utils.h" -#include -#include - -int comparisonWeightsPresenceStatusType(QXmppPresence::Status::Type statusType) -{ - switch(statusType) - { - case QXmppPresence::Status::Online: - case QXmppPresence::Status::Chat: - return 0; - case QXmppPresence::Status::DND: - return 1; - case QXmppPresence::Status::Away: - case QXmppPresence::Status::XA: - return 2; - case QXmppPresence::Status::Offline: - case QXmppPresence::Status::Invisible: - return 3; - default: - return 5; - } -} - -int comparisonWeightsPresenceType(QXmppPresence::Type type) -{ - switch(type) - { - case QXmppPresence::Available: - return 0; - case QXmppPresence::Unavailable: - return 1; - case QXmppPresence::Error: - case QXmppPresence::Subscribe: - case QXmppPresence::Subscribed: - case QXmppPresence::Unsubscribe: - case QXmppPresence::Unsubscribed: - case QXmppPresence::Probe: - return 3; - default: - return 5; - } -} - -QString presenceToStatusText(const QXmppPresence& presence) -{ - QString statusText = presence.status().statusText(); - if(statusText.isEmpty()) - { - if(presence.type() == QXmppPresence::Available) - { - switch(presence.status().type()) - { - case QXmppPresence::Status::Invisible: - case QXmppPresence::Status::Offline: - statusText = "Offline"; - break; - case QXmppPresence::Status::Online: - case QXmppPresence::Status::Chat: - statusText = "Available"; - break; - case QXmppPresence::Status::Away: - case QXmppPresence::Status::XA: - statusText = "Idle"; - break; - case QXmppPresence::Status::DND: - statusText = "Busy"; - break; - } - } - else - statusText = "Offline"; - } - - return statusText; -} - -QString getSettingsDir(const QString& bareJid) -{ - if(bareJid.isEmpty()) - return "appCache/"; - else - return QString("appCache/%1/").arg(bareJid); -} - -QString getImageHash(const QByteArray& image) -{ - if(image.isEmpty()) - return ""; - else - return QString(QCryptographicHash::hash(image, - QCryptographicHash::Sha1).toHex()); -} - -QImage getImageFromByteArray(const QByteArray& image) -{ - QBuffer buffer; - buffer.setData(image); - buffer.open(QIODevice::ReadOnly); - QImageReader imageReader(&buffer); - return imageReader.read(); -} - -QString getImageType1(const QByteArray& image) -{ - QBuffer buffer; - buffer.setData(image); - buffer.open(QIODevice::ReadOnly); - QString format = QImageReader::imageFormat(&buffer); - - if(format.toUpper() == "PNG") - return "image/png"; - else if(format.toUpper() == "MNG") - return "video/x-mng"; - else if(format.toUpper() == "GIF") - return "image/gif"; - else if(format.toUpper() == "BMP") - return "image/bmp"; - else if(format.toUpper() == "XPM") - return "image/x-xpm"; - else if(format.toUpper() == "SVG") - return "image/svg+xml"; - else if(format.toUpper() == "JPEG") - return "image/jpeg"; - - return "image/unknown"; -} +/* + * Copyright (C) 2008-2010 The QXmpp developers + * + * Author: + * Manjeet Dahiya + * + * Source: + * http://code.google.com/p/qxmpp + * + * This file is a part of QXmpp library. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + */ + + +#include "utils.h" +#include +#include + +int comparisonWeightsPresenceStatusType(QXmppPresence::Status::Type statusType) +{ + switch(statusType) + { + case QXmppPresence::Status::Online: + case QXmppPresence::Status::Chat: + return 0; + case QXmppPresence::Status::DND: + return 1; + case QXmppPresence::Status::Away: + case QXmppPresence::Status::XA: + return 2; + case QXmppPresence::Status::Offline: + case QXmppPresence::Status::Invisible: + return 3; + default: + return 5; + } +} + +int comparisonWeightsPresenceType(QXmppPresence::Type type) +{ + switch(type) + { + case QXmppPresence::Available: + return 0; + case QXmppPresence::Unavailable: + return 1; + case QXmppPresence::Error: + case QXmppPresence::Subscribe: + case QXmppPresence::Subscribed: + case QXmppPresence::Unsubscribe: + case QXmppPresence::Unsubscribed: + case QXmppPresence::Probe: + return 3; + default: + return 5; + } +} + +QString presenceToStatusText(const QXmppPresence& presence) +{ + QString statusText = presence.status().statusText(); + if(statusText.isEmpty()) + { + if(presence.type() == QXmppPresence::Available) + { + switch(presence.status().type()) + { + case QXmppPresence::Status::Invisible: + case QXmppPresence::Status::Offline: + statusText = "Offline"; + break; + case QXmppPresence::Status::Online: + case QXmppPresence::Status::Chat: + statusText = "Available"; + break; + case QXmppPresence::Status::Away: + case QXmppPresence::Status::XA: + statusText = "Idle"; + break; + case QXmppPresence::Status::DND: + statusText = "Busy"; + break; + } + } + else + statusText = "Offline"; + } + + return statusText; +} + +QString getSettingsDir(const QString& bareJid) +{ + if(bareJid.isEmpty()) + return "appCache/"; + else + return QString("appCache/%1/").arg(bareJid); +} + +QString getImageHash(const QByteArray& image) +{ + if(image.isEmpty()) + return ""; + else + return QString(QCryptographicHash::hash(image, + QCryptographicHash::Sha1).toHex()); +} + +QImage getImageFromByteArray(const QByteArray& image) +{ + QBuffer buffer; + buffer.setData(image); + buffer.open(QIODevice::ReadOnly); + QImageReader imageReader(&buffer); + return imageReader.read(); +} + +QString getImageType1(const QByteArray& image) +{ + QBuffer buffer; + buffer.setData(image); + buffer.open(QIODevice::ReadOnly); + QString format = QImageReader::imageFormat(&buffer); + + if(format.toUpper() == "PNG") + return "image/png"; + else if(format.toUpper() == "MNG") + return "video/x-mng"; + else if(format.toUpper() == "GIF") + return "image/gif"; + else if(format.toUpper() == "BMP") + return "image/bmp"; + else if(format.toUpper() == "XPM") + return "image/x-xpm"; + else if(format.toUpper() == "SVG") + return "image/svg+xml"; + else if(format.toUpper() == "JPEG") + return "image/jpeg"; + + return "image/unknown"; +} diff --git a/examples/GuiClient/utils.h b/examples/GuiClient/utils.h index 020811df..195f2ee6 100644 --- a/examples/GuiClient/utils.h +++ b/examples/GuiClient/utils.h @@ -1,45 +1,45 @@ -/* - * Copyright (C) 2008-2010 The QXmpp developers - * - * Author: - * Manjeet Dahiya - * - * Source: - * http://code.google.com/p/qxmpp - * - * This file is a part of QXmpp library. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - */ - - -#ifndef CLIENTUTILS_H -#define CLIENTUTILS_H - -#include "QXmppPresence.h" - -#include -#include -#include - -int comparisonWeightsPresenceStatusType(QXmppPresence::Status::Type); -int comparisonWeightsPresenceType(QXmppPresence::Type); - -QString presenceToStatusText(const QXmppPresence& presence); - -QString getSettingsDir(const QString& bareJid = ""); - -QString getImageHash(const QByteArray& image); -QImage getImageFromByteArray(const QByteArray& image); -QString getImageType1(const QByteArray& image); - -#endif // CLIENTUTILS_H +/* + * Copyright (C) 2008-2010 The QXmpp developers + * + * Author: + * Manjeet Dahiya + * + * Source: + * http://code.google.com/p/qxmpp + * + * This file is a part of QXmpp library. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + */ + + +#ifndef CLIENTUTILS_H +#define CLIENTUTILS_H + +#include "QXmppPresence.h" + +#include +#include +#include + +int comparisonWeightsPresenceStatusType(QXmppPresence::Status::Type); +int comparisonWeightsPresenceType(QXmppPresence::Type); + +QString presenceToStatusText(const QXmppPresence& presence); + +QString getSettingsDir(const QString& bareJid = ""); + +QString getImageHash(const QByteArray& image); +QImage getImageFromByteArray(const QByteArray& image); +QString getImageType1(const QByteArray& image); + +#endif // CLIENTUTILS_H diff --git a/examples/GuiClient/vCardManager.h b/examples/GuiClient/vCardManager.h index aecde92a..0c589e44 100644 --- a/examples/GuiClient/vCardManager.h +++ b/examples/GuiClient/vCardManager.h @@ -1,65 +1,65 @@ -/* - * Copyright (C) 2008-2010 The QXmpp developers - * - * Author: - * Manjeet Dahiya - * - * Source: - * http://code.google.com/p/qxmpp - * - * This file is a part of QXmpp library. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - */ - - -#ifndef VCARDMANAGER_H -#define VCARDMANAGER_H - -#include -#include -#include -#include "QXmppVCardIq.h" - -// use sqlite - -class QXmppClient; - -class vCardManager : public QObject -{ - Q_OBJECT - -public: - vCardManager(QXmppClient* client); - void requestVCard(const QString& bareJid); -// bool isVCardReceived(const QString& bareJid); - bool isVCardAvailable(const QString& bareJid); - QImage getAvatar(const QString& bareJid) const; - QXmppVCardIq& getVCard(const QString& bareJid); - void loadAllFromCache(); - void saveToCache(const QString& bareJid); - QString getSelfFullName(); - -signals: - void vCardReadyToUse(const QString& bareJid); - -public slots: - void vCardReceived(const QXmppVCardIq&); - -private: - QString m_selfFullName; - QXmppClient* m_client; - - QMap m_mapBareJidVcard; -}; - -#endif // VCARDMANAGER_H +/* + * Copyright (C) 2008-2010 The QXmpp developers + * + * Author: + * Manjeet Dahiya + * + * Source: + * http://code.google.com/p/qxmpp + * + * This file is a part of QXmpp library. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + */ + + +#ifndef VCARDMANAGER_H +#define VCARDMANAGER_H + +#include +#include +#include +#include "QXmppVCardIq.h" + +// use sqlite + +class QXmppClient; + +class vCardManager : public QObject +{ + Q_OBJECT + +public: + vCardManager(QXmppClient* client); + void requestVCard(const QString& bareJid); +// bool isVCardReceived(const QString& bareJid); + bool isVCardAvailable(const QString& bareJid); + QImage getAvatar(const QString& bareJid) const; + QXmppVCardIq& getVCard(const QString& bareJid); + void loadAllFromCache(); + void saveToCache(const QString& bareJid); + QString getSelfFullName(); + +signals: + void vCardReadyToUse(const QString& bareJid); + +public slots: + void vCardReceived(const QXmppVCardIq&); + +private: + QString m_selfFullName; + QXmppClient* m_client; + + QMap m_mapBareJidVcard; +}; + +#endif // VCARDMANAGER_H -- cgit v1.2.3