Commit 43428259 authored by Matt Edman's avatar Matt Edman
Browse files

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.


svn:r1256
parent 7ffa79e7
Loading
Loading
Loading
Loading
+5 −1
Changes for src/gui/log/logtreeitem.cpp: 5 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -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 @@ LogTreeItem::toString()
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 @@ void
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. */
+40 −0
Changes for src/util/string.cpp: 40 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -76,3 +76,43 @@ scrub_email_addr(QString email)
  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();
}
+5 −0
Changes for src/util/string.h: 5 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -45,5 +45,10 @@ QString scrub_email_addr(QString email);
 * 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