From abc6cea5b1bc3018ee20c6a0dd6272059fc34169 Mon Sep 17 00:00:00 2001 From: Manjeet Dahiya Date: Mon, 11 Oct 2010 15:17:44 +0000 Subject: align class name --- examples/GuiClient/GuiClient.pro | 4 +- examples/GuiClient/chatGraphicsScene.cpp | 6 +- examples/GuiClient/chatGraphicsScene.h | 4 +- examples/GuiClient/chatMsgGraphicsItem.cpp | 311 +++++++++++++++++++++++++++++ examples/GuiClient/chatMsgGraphicsItem.h | 87 ++++++++ examples/GuiClient/messageGraphicsItem.cpp | 311 ----------------------------- examples/GuiClient/messageGraphicsItem.h | 87 -------- 7 files changed, 405 insertions(+), 405 deletions(-) create mode 100644 examples/GuiClient/chatMsgGraphicsItem.cpp create mode 100644 examples/GuiClient/chatMsgGraphicsItem.h delete mode 100644 examples/GuiClient/messageGraphicsItem.cpp delete mode 100644 examples/GuiClient/messageGraphicsItem.h (limited to 'examples/GuiClient') diff --git a/examples/GuiClient/GuiClient.pro b/examples/GuiClient/GuiClient.pro index 09591c5e..bb17ac5f 100644 --- a/examples/GuiClient/GuiClient.pro +++ b/examples/GuiClient/GuiClient.pro @@ -4,7 +4,7 @@ TARGET = GuiClient TEMPLATE = app SOURCES += main.cpp \ - messageGraphicsItem.cpp \ + chatMsgGraphicsItem.cpp \ chatGraphicsScene.cpp \ chatGraphicsView.cpp \ chatDialog.cpp \ @@ -26,7 +26,7 @@ SOURCES += main.cpp \ accountsCache.cpp \ xmlConsoleDialog.cpp -HEADERS += messageGraphicsItem.h \ +HEADERS += chatMsgGraphicsItem.h \ chatGraphicsScene.h \ chatGraphicsView.h \ chatDialog.h \ diff --git a/examples/GuiClient/chatGraphicsScene.cpp b/examples/GuiClient/chatGraphicsScene.cpp index 6681fa4b..87406bc6 100644 --- a/examples/GuiClient/chatGraphicsScene.cpp +++ b/examples/GuiClient/chatGraphicsScene.cpp @@ -23,7 +23,7 @@ #include "chatGraphicsScene.h" -#include "messageGraphicsItem.h" +#include "chatMsgGraphicsItem.h" #include "chatGraphicsView.h" chatGraphicsScene::chatGraphicsScene(QObject* parent) : QGraphicsScene(parent), @@ -33,7 +33,7 @@ chatGraphicsScene::chatGraphicsScene(QObject* parent) : QGraphicsScene(parent), void chatGraphicsScene::addMessage(const QString& user, const QString& message) { - messageGraphicsItem* item = new messageGraphicsItem(); + chatMsgGraphicsItem* item = new chatMsgGraphicsItem(); m_items.append(item); item->setName(user); item->setBoxStartLength(m_boxStartLength); @@ -59,7 +59,7 @@ void chatGraphicsScene::verticalReposition() { m_verticalPosForNewMessage = 0; - messageGraphicsItem* item = 0; + chatMsgGraphicsItem* item = 0; for(int i = 0; i < m_items.size(); ++i) { item = m_items.at(i); diff --git a/examples/GuiClient/chatGraphicsScene.h b/examples/GuiClient/chatGraphicsScene.h index 82b9a401..0488f833 100644 --- a/examples/GuiClient/chatGraphicsScene.h +++ b/examples/GuiClient/chatGraphicsScene.h @@ -28,7 +28,7 @@ #include #include -class messageGraphicsItem; +class chatMsgGraphicsItem; class chatGraphicsScene : public QGraphicsScene { @@ -43,7 +43,7 @@ private: int m_verticalPosForNewMessage; int m_verticalSpacing; int m_boxStartLength; - QList m_items; + QList m_items; }; #endif // CHATGRAPHICSSCENE_H diff --git a/examples/GuiClient/chatMsgGraphicsItem.cpp b/examples/GuiClient/chatMsgGraphicsItem.cpp new file mode 100644 index 00000000..05041804 --- /dev/null +++ b/examples/GuiClient/chatMsgGraphicsItem.cpp @@ -0,0 +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 "chatMsgGraphicsItem.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(); +} + +chatMsgGraphicsItem::chatMsgGraphicsItem(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 chatMsgGraphicsItem::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 chatMsgGraphicsItem::setText(const QString& text) +{ + m_text = text; + calculateWidth(); + setPath(createPath()); +} + +void chatMsgGraphicsItem::setMaxWidth(int width) +{ + m_maxWidth = width; + setPath(createPath()); +} + +void chatMsgGraphicsItem::setViewWidth(int width) +{ + //25 for scrollbar + setMaxWidth(width - getBoxStartLength() - 25); +} + +int chatMsgGraphicsItem::getMaxWidth() const +{ + return m_maxWidth; +} + +void chatMsgGraphicsItem::setAlignment(Alignment align) +{ + m_alignment = align; + setPath(createPath()); +} + +QPainterPath chatMsgGraphicsItem::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 chatMsgGraphicsItem::getText() const +{ + return m_text; +} + +int chatMsgGraphicsItem::getTextWidth() const +{ + return getMaxWidth() - m_spikeWidth - m_cornerRadius*2; +} + +void chatMsgGraphicsItem::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 chatMsgGraphicsItem::setName(const QString& name) +{ + m_name = name; + if(name != "Me") + m_color = QColor(0, 210, 250); + else + m_color = QColor(250, 188, 239); +} + +QString chatMsgGraphicsItem::getName() const +{ + return m_name; +} + +QString chatMsgGraphicsItem::getTime() const +{ + return QTime::currentTime().toString("hh:mm"); +} + +void chatMsgGraphicsItem::setBoxStartLength(int length) +{ + m_boxStartLength = length; +} + +int chatMsgGraphicsItem::getBoxStartLength() const +{ + return m_boxStartLength; +} + +void chatMsgGraphicsItem::setColor(const QColor& color) +{ + m_color = color; +} + +QRectF chatMsgGraphicsItem::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/chatMsgGraphicsItem.h b/examples/GuiClient/chatMsgGraphicsItem.h new file mode 100644 index 00000000..b035ab4e --- /dev/null +++ b/examples/GuiClient/chatMsgGraphicsItem.h @@ -0,0 +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 chatMsgGraphicsItem : public QGraphicsPathItem +{ +public: + enum Alignment + { + LEFT = 0, + RIGHT + }; + + chatMsgGraphicsItem(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/messageGraphicsItem.cpp b/examples/GuiClient/messageGraphicsItem.cpp deleted file mode 100644 index 26a8c782..00000000 --- a/examples/GuiClient/messageGraphicsItem.cpp +++ /dev/null @@ -1,311 +0,0 @@ -/* - * 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 deleted file mode 100644 index d0b03960..00000000 --- a/examples/GuiClient/messageGraphicsItem.h +++ /dev/null @@ -1,87 +0,0 @@ -/* - * 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 -- cgit v1.2.3