Browse Source

颜色区分消息是自己发送的还是接收自好友的

tags/v1.0
chenyong 8 years ago
parent
commit
76bafb5fb7
3 changed files with 33 additions and 16 deletions
  1. +3
    -0
      mainwindow.ui
  2. +28
    -16
      recvtextedit.cpp
  3. +2
    -0
      recvtextedit.h

+ 3
- 0
mainwindow.ui View File

@@ -146,6 +146,9 @@
<property name="text"> <property name="text">
<string>查找</string> <string>查找</string>
</property> </property>
<property name="shortcut">
<string>Ctrl+S</string>
</property>
</action> </action>
<action name="actionSettings"> <action name="actionSettings">
<property name="text"> <property name="text">


+ 28
- 16
recvtextedit.cpp View File

@@ -27,33 +27,45 @@ void RecvTextEdit::mouseReleaseEvent(QMouseEvent *e)


void RecvTextEdit::addFellowContent(const Content *content, long long msSinceEpoch) void RecvTextEdit::addFellowContent(const Content *content, long long msSinceEpoch)
{ {
addContent(content, msSinceEpoch, false);
}

void RecvTextEdit::addMyContent(const Content *content, long long msSinceEpoch)
{
addContent(content, msSinceEpoch, true);
}

void RecvTextEdit::addContent(const Content *content, long long msSinceEpoch, bool mySelf)
{
drawDaySeperatorIfNewDay(msSinceEpoch); drawDaySeperatorIfNewDay(msSinceEpoch);


QString hint = "";
if (mFellow)
hint = mFellow->getName().c_str();
else
hint = "匿名";
hint = hint+" <font color=gray>"+ timeStr(msSinceEpoch)+"</font>";
moveCursor(QTextCursor::End);
insertHtml(hint);
append("");
showContent(content, false);
showHint(msSinceEpoch, mySelf);

showContent(content, mySelf);
append("\n"); append("\n");
moveCursor(QTextCursor::End); moveCursor(QTextCursor::End);
} }


void RecvTextEdit::addMyContent(const Content *content, long long msSinceEpoch)
void RecvTextEdit::showHint(long long msSinceEpoch, bool mySelf)
{ {
drawDaySeperatorIfNewDay(msSinceEpoch);
QString name("");
QString color("black");
if (mySelf)
{
name = "我";
color = "blue";
}
else
{
name = mFellow == nullptr ? "匿名" : mFellow->getName().c_str();
color = "green";
}

QString hint = "<font color="+color+">"+ name+" "+timeStr(msSinceEpoch)+"</font>";


QString hint = "我 <font color=gray>"+timeStr(msSinceEpoch)+"</font>";
moveCursor(QTextCursor::End); moveCursor(QTextCursor::End);
insertHtml(hint); insertHtml(hint);
append(""); append("");
showContent(content, true);
append("\n");
moveCursor(QTextCursor::End);
} }


void RecvTextEdit::setCurFellow(const Fellow *fellow) void RecvTextEdit::setCurFellow(const Fellow *fellow)


+ 2
- 0
recvtextedit.h View File

@@ -31,6 +31,8 @@ signals:


private: private:
QString timeStr(long long msSinceEpoch); QString timeStr(long long msSinceEpoch);
void addContent(const Content* content, long long msSinceEpoch, bool mySelf);
void showHint(long long msSinceEpoch, bool mySelf);
void showContent(const Content* content, bool mySelf); void showContent(const Content* content, bool mySelf);
void showFile(const FileContent* content, bool fromMySelf); void showFile(const FileContent* content, bool fromMySelf);
void showImage(const ImageContent* content); void showImage(const ImageContent* content);


Loading…
Cancel
Save