X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fqtui%2Fchatwidget.cpp;h=722f502aadd017febe93c4f7045f5b1813b9b66c;hp=68d63da39e442506305c8c3f8a6b0fa18323cd61;hb=43159be08b173c4c1c973eb3ea26cdaae191fc2f;hpb=fee1002dcb914ef9d47ceae97080b8c140e3b1ed diff --git a/src/qtui/chatwidget.cpp b/src/qtui/chatwidget.cpp index 68d63da3..722f502a 100644 --- a/src/qtui/chatwidget.cpp +++ b/src/qtui/chatwidget.cpp @@ -1,11 +1,11 @@ /*************************************************************************** - * Copyright (C) 2005-07 by The Quassel Team * + * Copyright (C) 2005-08 by the Quassel Project * * 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) any later version. * + * (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 * @@ -20,9 +20,9 @@ #include "util.h" #include "chatwidget.h" -#include "chatline.h" +#include "chatline-old.h" #include "qtui.h" - +#include "uisettings.h" ChatWidget::ChatWidget(QWidget *parent) : QAbstractScrollArea(parent) { //setAutoFillBackground(false); @@ -32,9 +32,9 @@ ChatWidget::ChatWidget(QWidget *parent) : QAbstractScrollArea(parent) { scrollTimer = new QTimer(this); scrollTimer->setSingleShot(false); scrollTimer->setInterval(100); + // setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding); - setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); - setMinimumSize(QSize(400,400)); + setMinimumSize(QSize(20,20)); setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn); bottomLine = -1; @@ -45,13 +45,15 @@ ChatWidget::ChatWidget(QWidget *parent) : QAbstractScrollArea(parent) { connect(verticalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(scrollBarValChanged(int))); } -void ChatWidget::init(QString netname, QString bufname) { - networkName = netname; - bufferName = bufname; +void ChatWidget::init(BufferId id) { + bufferId = id; setBackgroundRole(QPalette::Base); setFont(QFont("Fixed")); - tsWidth = 90; - senderWidth = 100; + UiSettings s; + QVariant tsDef = s.value("DefaultTimestampColumnWidth", 90); + QVariant senderDef = s.value("DefaultSenderColumnWidth", 100); + tsWidth = s.value(QString("%1/TimestampColumnWidth").arg(bufferId.toInt()), tsDef).toInt(); + senderWidth = s.value(QString("%1/SenderColumnWidth").arg(bufferId.toInt()), senderDef).toInt(); computePositions(); adjustScrollBar(); verticalScrollBar()->setValue(verticalScrollBar()->maximum()); @@ -60,7 +62,7 @@ void ChatWidget::init(QString netname, QString bufname) { //verticalScrollBar()->setMinimum(0); //verticalScrollBar()->setMaximum((int)height - verticalScrollBar()->pageStep()); - setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); + // setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); setMouseTracking(true); mouseMode = Normal; selectionMode = NoSelection; @@ -72,13 +74,22 @@ ChatWidget::~ChatWidget() { //foreach(ChatLine *l, lines) { // delete l; //} + UiSettings s; + s.setValue("DefaultTimestampColumnWidth", tsWidth); // FIXME stupid dirty quicky + s.setValue("DefaultSenderColumnWidth", senderWidth); + s.setValue(QString("%1/TimestampColumnWidth").arg(bufferId.toInt()), tsWidth); + s.setValue(QString("%1/SenderColumnWidth").arg(bufferId.toInt()), senderWidth); } -QSize ChatWidget::sizeHint() const { - //qDebug() << size(); - return size(); +QSize ChatWidget::minimumSizeHint() const { + return QSize(20, 20); } +// QSize ChatWidget::sizeHint() const { +// //qDebug() << size(); +// return size(); +// } + void ChatWidget::adjustScrollBar() { verticalScrollBar()->setPageStep(viewport()->height()); verticalScrollBar()->setSingleStep(20); @@ -245,7 +256,7 @@ void ChatWidget::resizeEvent(QResizeEvent *event) { /*if(event->oldSize().isValid())*/ //contents->setWidth(event->size().width()); //setAlignment(Qt::AlignBottom); - if(event->size().width() != event->oldSize().width()) { + if(event->size() != event->oldSize()) { computePositions(); layout(); } @@ -324,10 +335,42 @@ void ChatWidget::mousePressEvent(QMouseEvent *event) { } } -void ChatWidget::mouseDoubleClickEvent(QMouseEvent * /*event*/) { - +void ChatWidget::mouseDoubleClickEvent(QMouseEvent *event) { + // dirty and fast hack to make http:// urls klickable + if(lines.isEmpty()) + return; + QPoint pos = event->pos() + QPoint(0, verticalScrollBar()->value()); + int x = pos.x(); + int y = pos.y(); + int l = yToLineIdx(y); + if(lines.count() <= l) + return; + + ChatLine *line = lines[l]; + QString text = line->text(); + int cursorAt = qMax(0, line->posToCursor(QPointF(x, y - ycoords[l])) - 1); + + int start = 0; + if(cursorAt > 0) { + for(int i = cursorAt; i > 0; i--) { + if(text[i] == ' ') { + start = i + 1; + break; + } + } + } + int end = text.indexOf(" ", start); + int len = -1; + if(end != -1) { + len = end - start; + } + QString word = text.mid(start, len); + if(word.startsWith("http://")) { + QDesktopServices::openUrl(QUrl(word)); + } + } void ChatWidget::mouseReleaseEvent(QMouseEvent *event) { @@ -534,8 +577,8 @@ QString ChatWidget::selectionToString() { if(selectionMode == LinesSelected) { QString result; for(int l = selectionStart; l <= selectionEnd; l++) { - result += QString("[%1] %2 %3\n").arg(lines[l]->timeStamp().toLocalTime().toString("hh:mm:ss")) - .arg(lines[l]->sender()).arg(lines[l]->text()); + result += QString("[%1] %2 %3\n").arg(lines[l]->timestamp().toLocalTime().toString("hh:mm:ss")) + . arg(lines[l]->sender()).arg(lines[l]->text()); } return result; }