chatlinemodelitem.cpp
chatscene.cpp
chatview.cpp
+ columnhandleitem.cpp
coreconfigwizard.cpp
coreconnectdlg.cpp
coreinfodlg.cpp
chatitem.h
chatline.h
chatlinemodelitem.h
+ columnhandleitem.h
qtuisettings.h
qtuistyle.h)
int ChatItem::setWidth(int w) {
if(w == _boundingRect.width()) return _boundingRect.height();
+ prepareGeometryChange();
_boundingRect.setWidth(w);
int h = heightForWidth(w);
_boundingRect.setHeight(h);
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;
-}
-*/
-
-
//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); }
#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());
}
// 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));
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) {
_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 ) {
class Buffer;
class ChatItem;
class ChatLine;
+class ColumnHandleItem;
+
class QGraphicsSceneMouseEvent;
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
|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);
}
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());
virtual void resizeEvent(QResizeEvent *event);
protected slots:
- virtual void sceneHeightChanged(int height);
+ virtual void sceneHeightChanged(qreal height);
private:
ChatScene *_scene;
--- /dev/null
+/***************************************************************************
+* 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());
+
+
+}
--- /dev/null
+/***************************************************************************
+* 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
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