aboutsummaryrefslogtreecommitdiff
path: root/examples/GuiClient/chatGraphicsView.cpp
diff options
context:
space:
mode:
authorManjeet Dahiya <manjeetdahiya@gmail.com>2010-09-08 09:23:18 +0000
committerManjeet Dahiya <manjeetdahiya@gmail.com>2010-09-08 09:23:18 +0000
commitda88f5f0bb5e73bc69bf7ed3962691622b1ae4f9 (patch)
treec3686f7649785a2bfcc2c637a1588acdb8a721e8 /examples/GuiClient/chatGraphicsView.cpp
parent3431f5a37174b7eb8490672686db68df2b48e35f (diff)
downloadqxmpp-da88f5f0bb5e73bc69bf7ed3962691622b1ae4f9.tar.gz
add Gui Client example
Diffstat (limited to 'examples/GuiClient/chatGraphicsView.cpp')
-rw-r--r--examples/GuiClient/chatGraphicsView.cpp43
1 files changed, 43 insertions, 0 deletions
diff --git a/examples/GuiClient/chatGraphicsView.cpp b/examples/GuiClient/chatGraphicsView.cpp
new file mode 100644
index 00000000..786cc24f
--- /dev/null
+++ b/examples/GuiClient/chatGraphicsView.cpp
@@ -0,0 +1,43 @@
+#include "chatGraphicsView.h"
+#include "chatGraphicsScene.h"
+#include <QResizeEvent>
+
+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);
+}