#include <QGraphicsSceneMouseEvent>
#include <QMenu>
#include <QPersistentModelIndex>
-#include <QWebView>
+
+#ifdef HAVE_WEBKIT
+# include <QWebView>
+#endif
#include "chatitem.h"
#include "chatline.h"
#include "client.h"
#include "clientbacklogmanager.h"
#include "columnhandleitem.h"
+#include "contextmenuactionprovider.h"
#include "iconloader.h"
#include "messagefilter.h"
#include "qtui.h"
this, SLOT(rowsInserted(const QModelIndex &, int, int)));
connect(model, SIGNAL(rowsAboutToBeRemoved(const QModelIndex &, int, int)),
this, SLOT(rowsAboutToBeRemoved(const QModelIndex &, int, int)));
+ connect(model, SIGNAL(dataChanged(QModelIndex, QModelIndex)), SLOT(dataChanged(QModelIndex, QModelIndex)));
if(model->rowCount() > 0)
rowsInserted(QModelIndex(), 0, model->rowCount() - 1);
updateSceneRect();
}
+void ChatScene::dataChanged(const QModelIndex &tl, const QModelIndex &br) {
+ layout(tl.row(), br.row(), _sceneRect.width());
+}
+
void ChatScene::updateForViewport(qreal width, qreal height) {
_viewportHeight = height;
setWidth(width);
void ChatScene::setWidth(qreal width) {
if(width == _sceneRect.width())
return;
+ layout(0, _lines.count()-1, width);
+}
+void ChatScene::layout(int start, int end, qreal width) {
// clock_t startT = clock();
// disabling the index while doing this complex updates is about
// 2 to 10 times faster!
//setItemIndexMethod(QGraphicsScene::NoIndex);
- QList<ChatLine *>::iterator lineIter = _lines.end();
- QList<ChatLine *>::iterator lineIterBegin = _lines.begin();
- qreal linePos = _sceneRect.y() + _sceneRect.height();
- qreal contentsWidth = width - secondColumnHandle()->sceneRight();
- while(lineIter != lineIterBegin) {
- lineIter--;
- (*lineIter)->setGeometryByWidth(width, contentsWidth, linePos);
+ if(end >= 0) {
+ int row = end;
+ qreal linePos = _lines.at(row)->scenePos().y() + _lines.at(row)->height();
+ qreal contentsWidth = width - secondColumnHandle()->sceneRight();
+ while(row >= start) {
+ _lines.at(row--)->setGeometryByWidth(width, contentsWidth, linePos);
+ }
+
+ if(row >= 0) {
+ // remaining items don't need geometry changes, but maybe repositioning?
+ ChatLine *line = _lines.at(row);
+ qreal offset = linePos - (line->scenePos().y() + line->height());
+ if(offset != 0) {
+ while(row >= 0) {
+ line = _lines.at(row--);
+ line->setPos(0, line->scenePos().y() + offset);
+ }
+ }
+ }
}
+
//setItemIndexMethod(QGraphicsScene::BspTreeIndex);
updateSceneRect(width);
item->addActionsToMenu(&menu, item->mapFromScene(pos));
else
// no item -> default scene actions
- Client::mainUi()->actionProvider()->addActions(&menu, filter(), BufferId());
+ GraphicalUi::contextMenuActionProvider()->addActions(&menu, filter(), BufferId());
menu.exec(event->screenPos());
stringToClipboard(selection(), mode);
}
-void ChatScene::stringToClipboard(const QString &str, QClipboard::Mode mode) {
+void ChatScene::stringToClipboard(const QString &str_, QClipboard::Mode mode) {
+ QString str = str_;
+ // remove trailing linefeeds
+ if(str.endsWith('\n'))
+ str.chop(1);
+
switch(mode) {
case QClipboard::Clipboard:
QApplication::clipboard()->setText(str);
if(webPreview.url != url) {
webPreview.url = url;
// prepare to load a different URL
- if(webPreview.previewItem && webPreview.previewItem->scene()) {
- removeItem(webPreview.previewItem);
+ if(webPreview.previewItem) {
+ if(webPreview.previewItem->scene())
+ removeItem(webPreview.previewItem);
delete webPreview.previewItem;
webPreview.previewItem = 0;
}