From 39e2a78383295f86c5aa2dadbeac6f02b53eb7a4 Mon Sep 17 00:00:00 2001 From: Manuel Nickschas Date: Thu, 24 Jul 2008 23:14:50 +0200 Subject: [PATCH] Introduce column separator items; change most of ChatView to use qreal 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 | 2 ++ src/qtui/chatitem.cpp | 1 + src/qtui/chatline.cpp | 52 ++++++++--------------------------- src/qtui/chatline.h | 2 +- src/qtui/chatscene.cpp | 36 +++++++++++++++++------- src/qtui/chatscene.h | 16 +++++++---- src/qtui/chatview.cpp | 6 ++-- src/qtui/chatview.h | 2 +- src/qtui/columnhandleitem.cpp | 47 +++++++++++++++++++++++++++++++ src/qtui/columnhandleitem.h | 51 ++++++++++++++++++++++++++++++++++ src/qtui/qtuistyle.h | 4 +-- 11 files changed, 157 insertions(+), 62 deletions(-) create mode 100644 src/qtui/columnhandleitem.cpp create mode 100644 src/qtui/columnhandleitem.h diff --git a/src/qtui/CMakeLists.txt b/src/qtui/CMakeLists.txt index f67b91f8..81e7c27e 100644 --- a/src/qtui/CMakeLists.txt +++ b/src/qtui/CMakeLists.txt @@ -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) diff --git a/src/qtui/chatitem.cpp b/src/qtui/chatitem.cpp index a3f3d307..487c2f2f 100644 --- a/src/qtui/chatitem.cpp +++ b/src/qtui/chatitem.cpp @@ -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); diff --git a/src/qtui/chatline.cpp b/src/qtui/chatline.cpp index cf3c3fa3..237fad68 100644 --- a/src/qtui/chatline.cpp +++ b/src/qtui/chatline.cpp @@ -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; -} -*/ - - diff --git a/src/qtui/chatline.h b/src/qtui/chatline.h index 7f837357..c7ac49b7 100644 --- a/src/qtui/chatline.h +++ b/src/qtui/chatline.h @@ -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); } diff --git a/src/qtui/chatscene.cpp b/src/qtui/chatscene.cpp index 72099e67..d7ad76a1 100644 --- a/src/qtui/chatscene.cpp +++ b/src/qtui/chatscene.cpp @@ -25,18 +25,29 @@ #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 ) { diff --git a/src/qtui/chatscene.h b/src/qtui/chatscene.h index 5f8057ab..daabba7f 100644 --- a/src/qtui/chatscene.h +++ b/src/qtui/chatscene.h @@ -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 _lines; + ColumnHandleItem *firstColHandle, *secondColHandle; + qreal firstColHandlePos, secondColHandlePos; }; #endif diff --git a/src/qtui/chatview.cpp b/src/qtui/chatview.cpp index fe15416b..eeaaf565 100644 --- a/src/qtui/chatview.cpp +++ b/src/qtui/chatview.cpp @@ -35,13 +35,14 @@ ChatView::ChatView(Buffer *buf, QWidget *parent) : QGraphicsView(parent), Abstra |QGraphicsView::DontSavePainterState |QGraphicsView::DontAdjustForAntialiasing); setAlignment(Qt::AlignBottom); + setInteractive(true); QList 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()); diff --git a/src/qtui/chatview.h b/src/qtui/chatview.h index 100b311b..88a7e23a 100644 --- a/src/qtui/chatview.h +++ b/src/qtui/chatview.h @@ -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 index 00000000..16cec89d --- /dev/null +++ b/src/qtui/columnhandleitem.cpp @@ -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 +#include + +#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 index 00000000..81c411ed --- /dev/null +++ b/src/qtui/columnhandleitem.h @@ -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 + +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 diff --git a/src/qtui/qtuistyle.h b/src/qtui/qtuistyle.h index d2b9fe2e..0f3d60ab 100644 --- a/src/qtui/qtuistyle.h +++ b/src/qtui/qtuistyle.h @@ -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 -- 2.20.1