[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[vidalia-svn] r1256: Set the tooltip for the log message column to be the word-wr (in trunk/src: gui/log util)



Author: edmanm
Date: 2006-10-01 19:40:24 -0400 (Sun, 01 Oct 2006)
New Revision: 1256

Modified:
   trunk/src/gui/log/logtreeitem.cpp
   trunk/src/util/string.cpp
   trunk/src/util/string.h
Log:
Set the tooltip for the log message column to be the word-wrapped log message, so
you can see a whole log message without having to scroll horizontally. I
tooltipped the date column, too.


Modified: trunk/src/gui/log/logtreeitem.cpp
===================================================================
--- trunk/src/gui/log/logtreeitem.cpp	2006-10-01 23:12:42 UTC (rev 1255)
+++ trunk/src/gui/log/logtreeitem.cpp	2006-10-01 23:40:24 UTC (rev 1256)
@@ -25,6 +25,7 @@
  * \brief Item representing a single message in the message log
  */
 
+#include <util/string.h>
 #include "logtreeitem.h"
 #include "logtreewidget.h"
 
@@ -81,7 +82,9 @@
 void
 LogTreeItem::setTimestamp(QDateTime timestamp)
 {
-  setText(COL_TIME, timestamp.toString(DATETIME_FMT));
+  QString strtime = timestamp.toString(DATETIME_FMT);
+  setText(COL_TIME, strtime);
+  setToolTip(COL_TIME, strtime);
 }
 
 /** Sets the item's severity and the appropriate background color. */
@@ -112,6 +115,7 @@
 LogTreeItem::setMessage(QString message)
 {
   setText(COL_MESG, message);
+  setToolTip(COL_MESG, string_wrap(message, 80, " ", "\r\n"));
 }
 
 /** Returns the severity associated with this log item. */

Modified: trunk/src/util/string.cpp
===================================================================
--- trunk/src/util/string.cpp	2006-10-01 23:12:42 UTC (rev 1255)
+++ trunk/src/util/string.cpp	2006-10-01 23:40:24 UTC (rev 1256)
@@ -76,3 +76,43 @@
   scrubbed = scrubbed.replace(".", " dot ");
   return scrubbed;
 }
+
+/** Wraps <b>str</b> at <b>width</b> characters wide, using <b>sep</b> as the
+ * word separator (" ", for example), and placing the line ending <b>le</b> at
+ * the end of each line, except the last. */
+QString
+string_wrap(QString str, int width, QString sep, QString le)
+{
+  QString wrapped;
+  int pos, nextsep, wordlen, n;
+  int seplen = sep.length();
+ 
+  if (str.length() < width) {
+    return str;
+  }
+
+  pos = 0; 
+  n = width;
+  while (pos < str.length()) {
+    /* Get the length of a "word" */
+    nextsep = str.indexOf(sep, pos);
+    if (nextsep < 0) {
+      nextsep = str.length();
+    }
+    wordlen = nextsep-pos;
+
+    /* Check if there is room for the word on this line */
+    if (wordlen > n) {
+      /* Create a new line */
+      wrapped.append(le);
+      n = width;
+    }
+
+    /* Add the word to the current line */
+    wrapped.append(str.mid(pos, wordlen+seplen));
+    n = n - wordlen - seplen;
+    pos += wordlen + seplen;
+  }
+  return wrapped.trimmed();
+}
+

Modified: trunk/src/util/string.h
===================================================================
--- trunk/src/util/string.h	2006-10-01 23:12:42 UTC (rev 1255)
+++ trunk/src/util/string.h	2006-10-01 23:40:24 UTC (rev 1256)
@@ -45,5 +45,10 @@
  * false. */
 bool err(QString *str, QString errmsg);
 
+/** Wraps <b>str</b> at <b>width</b> characters wide, using <b>sep</b> as the
+ * word separator (" ", for example), and placing the line ending <b>le</b> at
+ * the end of each line, except the last.*/
+QString string_wrap(QString str, int width, QString sep, QString le);
+
 #endif