Introduce column separator items; change most of ChatView to use qreal
authorManuel Nickschas <sputnick@quassel-irc.org>
Thu, 24 Jul 2008 21:14:50 +0000 (23:14 +0200)
committerManuel Nickschas <sputnick@quassel-irc.org>
Sat, 2 Aug 2008 13:17:10 +0000 (15:17 +0200)
These items will be used to drag the columns; also they will display a fancy
vertical line at some point (this FR is years old!).

Also changed most (or all?) our geometry-related values to qreal rather than int,
since QGV operates on qreals. Dunno if that is less efficient though; needs evaluation.

src/qtui/CMakeLists.txt
src/qtui/chatitem.cpp
src/qtui/chatline.cpp
src/qtui/chatline.h
src/qtui/chatscene.cpp
src/qtui/chatscene.h
src/qtui/chatview.cpp
src/qtui/chatview.h
src/qtui/columnhandleitem.cpp [new file with mode: 0644]
src/qtui/columnhandleitem.h [new file with mode: 0644]
src/qtui/qtuistyle.h

index f67b91f..81e7c27 100644 (file)
@@ -15,6 +15,7 @@ set(SOURCES
     chatlinemodelitem.cpp
     chatscene.cpp
     chatview.cpp
+    columnhandleitem.cpp
     coreconfigwizard.cpp
     coreconnectdlg.cpp
     coreinfodlg.cpp
@@ -60,6 +61,7 @@ set(HEADERS
     chatitem.h
     chatline.h
     chatlinemodelitem.h
+    columnhandleitem.h
     qtuisettings.h
     qtuistyle.h)
 
index a3f3d30..487c2f2 100644 (file)
@@ -47,6 +47,7 @@ QVariant ChatItem::data(int role) const {
 
 int ChatItem::setWidth(int w) {
   if(w == _boundingRect.width()) return _boundingRect.height();
+  prepareGeometryChange();
   _boundingRect.setWidth(w);
   int h = heightForWidth(w);
   _boundingRect.setHeight(h);
index cf3c3fa..237fad6 100644 (file)
@@ -47,52 +47,22 @@ QRectF ChatLine::boundingRect () const {
   return QRectF(0, 0, _width, _height);
 }
 
-int ChatLine::setColumnWidths(int ts, int sender, int contents) {
-  _timestampItem->setWidth(ts);
-  _senderItem->setWidth(sender);
-  _height = _contentsItem->setWidth(contents);
+qreal ChatLine::setGeometry(qreal width, qreal firstHandlePos, qreal secondHandlePos) {
+  if(width != _width) prepareGeometryChange();
+  qreal firstsep = QtUi::style()->firstColumnSeparator()/2;
+  qreal secondsep = QtUi::style()->secondColumnSeparator()/2;
 
-  _senderItem->setPos(ts, 0);
-  _contentsItem->setPos(ts + sender, 0);
+  _timestampItem->setWidth(firstHandlePos - firstsep);
+  _senderItem->setWidth(secondHandlePos - firstHandlePos - (firstsep+secondsep));
+  _height = _contentsItem->setWidth(width - secondHandlePos - secondsep);
 
-  _width = ts + sender + contents;
+  _senderItem->setPos(firstHandlePos + firstsep, 0);
+  _contentsItem->setPos(secondHandlePos + secondsep, 0);
+
+  _width = width;
   return _height;
 }
 
 void ChatLine::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) {
 
 }
-
-/*
-void ChatLine::setColumnWidths(int tsColWidth, int senderColWidth, int textColWidth) {
-  if(tsColWidth >= 0) {
-    _tsColWidth = tsColWidth;
-    _tsItem->setWidth(tsColWidth);
-  }
-  if(senderColWidth >= 0) {
-    _senderColWidth = senderColWidth;
-    _senderItem->setWidth(senderColWidth);
-  }
-  if(textColWidth >= 0) {
-    _textColWidth = textColWidth;
-    _textItem->setWidth(textColWidth);
-  }
-  layout();
-}
-
-void ChatLine::layout() {
-  prepareGeometryChange();
-  _tsItem->setPos(QPointF(0, 0));
-  _senderItem->setPos(QPointF(_tsColWidth + QtUi::style()->sepTsSender(), 0));
-  _textItem->setPos(QPointF(_tsColWidth + QtUi::style()->sepTsSender() + _senderColWidth + QtUi::style()->sepSenderText(), 0));
-}
-
-
-bool ChatLine::sceneEvent ( QEvent * event ) {
-  qDebug() <<(void*)this<< "receiving event";
-  event->ignore();
-  return false;
-}
-*/
-
-
index 7f83735..c7ac49b 100644 (file)
@@ -41,7 +41,7 @@ class ChatLine : public QGraphicsItem {
     //void layout();
 
     // returns height
-    int setColumnWidths(int tsColWidth, int senderColWidth, int textColWidth);
+    qreal setGeometry(qreal width, qreal firstColPos, qreal secondColPos);
 
     //void myMousePressEvent ( QGraphicsSceneMouseEvent * event ) { qDebug() << "press"; mousePressEvent(event); }
 
index 72099e6..d7ad76a 100644 (file)
 #include "chatitem.h"
 #include "chatlinemodelitem.h"
 #include "chatscene.h"
-#include "quasselui.h"
+#include "columnhandleitem.h"
+#include "qtui.h"
 
 ChatScene::ChatScene(QAbstractItemModel *model, QObject *parent) : QGraphicsScene(parent), _model(model) {
   _width = 0;
-  _timestampWidth = 60;
-  _senderWidth = 80;
+  connect(this, SIGNAL(sceneRectChanged(const QRectF &)), this, SLOT(rectChanged(const QRectF &)));
+
   connect(model, SIGNAL(rowsInserted(const QModelIndex &, int, int)), this, SLOT(rowsInserted(const QModelIndex &, int, int)));
   for(int i = 0; i < model->rowCount(); i++) {
     ChatLine *line = new ChatLine(model->index(i, 0));
     _lines.append(line);
     addItem(line);
   }
+
+  firstColHandlePos = 80;
+  secondColHandlePos = 200;
+
+  firstColHandle = new ColumnHandleItem(QtUi::style()->firstColumnSeparator()); addItem(firstColHandle);
+  secondColHandle = new ColumnHandleItem(QtUi::style()->secondColumnSeparator()); addItem(secondColHandle);
+
+  firstColHandle->setXPos(firstColHandlePos);
+  secondColHandle->setXPos(secondColHandlePos);
+
   emit heightChanged(height());
 }
 
@@ -50,8 +61,8 @@ void ChatScene::rowsInserted(const QModelIndex &index, int start, int end) {
   // maybe make this more efficient by prepending stuff with negative yval
   // dunno if that's worth not guranteeing that 0 is on the top...
   // TODO bulk inserts, iterators
-  int h = 0;
-  int y = 0;
+  qreal h = 0;
+  qreal y = 0;
   if(_width && start > 0) y = _lines.value(start - 1)->y() + _lines.value(start - 1)->height();
   for(int i = start; i <= end; i++) {
     ChatLine *line = new ChatLine(model()->index(i, 0));
@@ -59,7 +70,7 @@ void ChatScene::rowsInserted(const QModelIndex &index, int start, int end) {
     addItem(line);
     if(_width > 0) {
       line->setPos(0, y+h);
-      h += line->setColumnWidths(_timestampWidth, _senderWidth, _width - _timestampWidth - _senderWidth);
+      h += line->setGeometry(_width, firstColHandlePos, secondColHandlePos);
     }
   }
   if(h > 0) {
@@ -68,19 +79,24 @@ void ChatScene::rowsInserted(const QModelIndex &index, int start, int end) {
       _lines.value(i)->moveBy(0, h);
     }
     setSceneRect(QRectF(0, 0, _width, _height));
-    emit heightChanged(height());
+    emit heightChanged(_height);
   }
 }
 
-void ChatScene::setWidth(int w) {
+void ChatScene::setWidth(qreal w) {
   _width = w;
   _height = 0;
   foreach(ChatLine *line, _lines) {
     line->setPos(0, _height);
-    _height += line->setColumnWidths(_timestampWidth, _senderWidth, w - _timestampWidth - _senderWidth);
+    _height += line->setGeometry(_width, firstColHandlePos, secondColHandlePos);
   }
   setSceneRect(QRectF(0, 0, w, _height));
-  emit heightChanged(height());
+  emit heightChanged(_height);
+}
+
+void ChatScene::rectChanged(const QRectF &rect) {
+  firstColHandle->sceneRectChanged(rect);
+  secondColHandle->sceneRectChanged(rect);
 }
 
 void ChatScene::mousePressEvent ( QGraphicsSceneMouseEvent * mouseEvent ) {
index 5f8057a..daabba7 100644 (file)
@@ -28,6 +28,8 @@ class AbstractUiMsg;
 class Buffer;
 class ChatItem;
 class ChatLine;
+class ColumnHandleItem;
+
 class QGraphicsSceneMouseEvent;
 
 class ChatScene : public QGraphicsScene {
@@ -41,21 +43,25 @@ class ChatScene : public QGraphicsScene {
     inline QAbstractItemModel *model() const { return _model; }
 
   public slots:
-    void setWidth(int);
+    void setWidth(qreal);
+
+  private slots:
+    void rectChanged(const QRectF &);
 
   signals:
-    void heightChanged(int height);
+    void heightChanged(qreal height);
 
   protected slots:
     void rowsInserted(const QModelIndex &, int, int);
-    void mousePressEvent ( QGraphicsSceneMouseEvent * mouseEvent );
+    void mousePressEvent(QGraphicsSceneMouseEvent * mouseEvent);
 
   private:
-    int _width, _height;
-    int _timestampWidth, _senderWidth;
+    qreal _width, _height;
     QAbstractItemModel *_model;
     QList<ChatLine *> _lines;
 
+    ColumnHandleItem *firstColHandle, *secondColHandle;
+    qreal firstColHandlePos, secondColHandlePos;
 };
 
 #endif
index fe15416..eeaaf56 100644 (file)
@@ -35,13 +35,14 @@ ChatView::ChatView(Buffer *buf, QWidget *parent) : QGraphicsView(parent), Abstra
       |QGraphicsView::DontSavePainterState
       |QGraphicsView::DontAdjustForAntialiasing);
   setAlignment(Qt::AlignBottom);
+  setInteractive(true);
 
   QList<BufferId> filterList;
   filterList.append(buf->bufferInfo().bufferId());
   MessageFilter *filter = new MessageFilter(Client::messageModel(), filterList, this);
 
   _scene = new ChatScene(filter, this);
-  connect(_scene, SIGNAL(heightChanged(int)), this, SLOT(sceneHeightChanged(int)));
+  connect(_scene, SIGNAL(heightChanged(qreal)), this, SLOT(sceneHeightChanged(qreal)));
   setScene(_scene);
 }
 
@@ -60,7 +61,8 @@ void ChatView::resizeEvent(QResizeEvent *event) {
   verticalScrollBar()->setValue(verticalScrollBar()->maximum());
 }
 
-void ChatView::sceneHeightChanged(int h) {
+void ChatView::sceneHeightChanged(qreal h) {
+  Q_UNUSED(h)
   bool scrollable = verticalScrollBar()->value() == verticalScrollBar()->maximum();
   setSceneRect(scene()->sceneRect());
   if(scrollable) verticalScrollBar()->setValue(verticalScrollBar()->maximum());
index 100b311..88a7e23 100644 (file)
@@ -57,7 +57,7 @@ class ChatView : public QGraphicsView, public AbstractChatView {
     virtual void resizeEvent(QResizeEvent *event);
 
   protected slots:
-    virtual void sceneHeightChanged(int height);
+    virtual void sceneHeightChanged(qreal height);
 
   private:
     ChatScene *_scene;
diff --git a/src/qtui/columnhandleitem.cpp b/src/qtui/columnhandleitem.cpp
new file mode 100644 (file)
index 0000000..16cec89
--- /dev/null
@@ -0,0 +1,47 @@
+/***************************************************************************
+*   Copyright (C) 2005-08 by the Quassel IRC Team                         *
+*   devel@quassel-irc.org                                                 *
+*                                                                         *
+*   This program is free software; you can redistribute it and/or modify  *
+*   it under the terms of the GNU General Public License as published by  *
+*   the Free Software Foundation; either version 2 of the License, or     *
+*   (at your option) version 3.                                           *
+*                                                                         *
+*   This program 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 General Public License for more details.                          *
+*                                                                         *
+*   You should have received a copy of the GNU General Public License     *
+*   along with this program; if not, write to the                         *
+*   Free Software Foundation, Inc.,                                       *
+*   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
+***************************************************************************/
+
+#include <QGraphicsScene>
+#include <QPainter>
+
+#include "columnhandleitem.h"
+
+ColumnHandleItem::ColumnHandleItem(qreal w, QGraphicsItem *parent) : QGraphicsItem(parent) {
+  _width = w;
+
+}
+
+void ColumnHandleItem::setXPos(qreal xpos) {
+  setPos(xpos - width()/2, (qreal)0);
+}
+
+void ColumnHandleItem::sceneRectChanged(const QRectF &rect) {
+  if(rect.height() != boundingRect().height())
+    prepareGeometryChange();
+}
+
+void ColumnHandleItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) {
+  Q_UNUSED(option);
+  Q_UNUSED(widget);
+
+  painter->drawRect(boundingRect());
+
+
+}
diff --git a/src/qtui/columnhandleitem.h b/src/qtui/columnhandleitem.h
new file mode 100644 (file)
index 0000000..81c411e
--- /dev/null
@@ -0,0 +1,51 @@
+/***************************************************************************
+*   Copyright (C) 2005-08 by the Quassel IRC Team                         *
+*   devel@quassel-irc.org                                                 *
+*                                                                         *
+*   This program is free software; you can redistribute it and/or modify  *
+*   it under the terms of the GNU General Public License as published by  *
+*   the Free Software Foundation; either version 2 of the License, or     *
+*   (at your option) version 3.                                           *
+*                                                                         *
+*   This program 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 General Public License for more details.                          *
+*                                                                         *
+*   You should have received a copy of the GNU General Public License     *
+*   along with this program; if not, write to the                         *
+*   Free Software Foundation, Inc.,                                       *
+*   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
+***************************************************************************/
+
+#ifndef COLUMNHANDLEITEM_H_
+#define COLUMNHANDLEITEM_H_
+
+#include <QGraphicsItem>
+
+class ColumnHandleItem : public QGraphicsItem {
+
+  public:
+    ColumnHandleItem(qreal width, QGraphicsItem *parent = 0);
+
+    inline qreal width() const;
+    inline QRectF boundingRect() const;
+    void setXPos(qreal xpos);
+
+    virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
+
+    void sceneRectChanged(const QRectF &);
+
+  private:
+    qreal _width;
+};
+
+qreal ColumnHandleItem::width() const {
+  return _width;
+}
+
+QRectF ColumnHandleItem::boundingRect() const {
+  return QRectF(0, 0, _width, scene()->height());
+}
+
+#endif
index d2b9fe2..0f3d60a 100644 (file)
@@ -29,8 +29,8 @@ class QtUiStyle : public UiStyle {
     QtUiStyle();
     virtual ~QtUiStyle();
 
-    virtual int sepTsSender() { return 10; }
-    virtual int sepSenderText() { return 10; }
+    virtual inline qreal firstColumnSeparator() const { return 10; }
+    virtual inline qreal secondColumnSeparator() const { return 10; }
 };
 
 #endif