Fixed restore-to-defaults in settings dialog.
[quassel.git] / src / qtui / chatwidget.cpp
index e488f03..722f502 100644 (file)
@@ -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;
@@ -62,7 +62,7 @@ void ChatWidget::init(BufferId id) {
   //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;
@@ -81,11 +81,15 @@ ChatWidget::~ChatWidget() {
   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);
@@ -252,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();
   }
@@ -331,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) {