added for Privat chat html and css feature to can make styles for Chat Window.

added first basic default style.
style Button disabled need to be fix.

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@500 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
defnax 2008-04-12 14:19:08 +00:00
parent 13eb45f294
commit a20ff44567
10 changed files with 224 additions and 24 deletions

View File

@ -37,6 +37,7 @@
#include "rsiface/rspeers.h"
#include "rsiface/rsmsgs.h"
#define appDir QApplication::applicationDirPath()
/* Define the format used for displaying the date and time */
#define DATETIME_FMT "MMM dd hh:mm:ss"
@ -56,6 +57,8 @@ PopupChatDialog::PopupChatDialog(std::string id, std::string name,
loadEmoticons();
styleHtm = appDir + "/style/chat/default.htm";
/* Hide ToolBox frame */
showAvatarFrame(true);
connect(ui.avatarFrameButton, SIGNAL(toggled(bool)), this, SLOT(showAvatarFrame(bool)));
@ -70,6 +73,7 @@ PopupChatDialog::PopupChatDialog(std::string id, std::string name,
connect(ui.fontButton, SIGNAL(clicked()), this, SLOT(getFont()));
connect(ui.colorButton, SIGNAL(clicked()), this, SLOT(setColor()));
connect(ui.emoteiconButton, SIGNAL(clicked()), this, SLOT(smileyWidget()));
connect(ui.styleButton, SIGNAL(clicked()), SLOT(changeStyle()));
// Create the status bar
std::ostringstream statusstr;
@ -90,11 +94,15 @@ PopupChatDialog::PopupChatDialog(std::string id, std::string name,
ui.textitalicButton->setIcon(QIcon(QString(":/images/edit-italic.png")));
ui.fontButton->setIcon(QIcon(QString(":/images/fonts.png")));
ui.emoteiconButton->setIcon(QIcon(QString(":/images/emoticons/kopete/kopete020.png")));
ui.styleButton->setIcon(QIcon(QString(":/images/looknfeel.png")));
ui.textboldButton->setCheckable(true);
ui.textunderlineButton->setCheckable(true);
ui.textitalicButton->setCheckable(true);
/*Disabled style Button when will switch style RetroShare will crash need to be fix */
ui.styleButton->setEnabled(false);
/*QMenu * fontmenu = new QMenu();
fontmenu->addAction(ui.actionBold);
fontmenu->addAction(ui.actionUnderline);
@ -147,16 +155,15 @@ void PopupChatDialog::updateChat()
}
void PopupChatDialog::addChatMsg(ChatInfo *ci)
{
QTextEdit *msgWidget = ui.textBrowser;
//QTextBrowser *msgWidget = ui.textBrowser;
QString currenttxt = msgWidget->toHtml();
//QString message = msgWidget->toHtml();
/* add in lines at the bottom */
QString extraTxt;
//QString extraTxt;
bool offline = true;
@ -177,34 +184,44 @@ void PopupChatDialog::addChatMsg(ChatInfo *ci)
{
QString line = "<br>\n<span style=\"color:#1D84C9\"><strong> ----- PEER OFFLINE (Chat will be lost) -----</strong></span> \n<br>";
extraTxt += line;
//extraTxt += line;
}
QString timestamp = "[" + QDateTime::currentDateTime().toString("hh:mm:ss") + "]";
//QString pre = tr("Peer:" );
QString name = QString::fromStdString(ci ->name);
QString line = "<span style=\"color:#C00000\"><strong>" + timestamp + "</strong></span>" +
"<span style=\"color:#2D84C9\"><strong>" + " " + name + "</strong></span>";
//QString line = "<span style=\"color:#C00000\"><strong>" + timestamp + "</strong></span>" +
// "<span style=\"color:#2D84C9\"><strong>" + " " + name + "</strong></span>";
//extraTxt += line;
extraTxt += line;
QString message = QString::fromStdWString(ci -> msg);
extraTxt += QString::fromStdWString(ci -> msg);
currenttxt += extraTxt;
//currenttxt += extraTxt;
QHashIterator<QString, QString> i(smileys);
while(i.hasNext())
{
i.next();
currenttxt.replace(i.key(), "<img src=\"" + i.value() + "\">");
message.replace(i.key(), "<img src=\"" + i.value() + "\">");
}
history /*<< nickColor << color << font << fontSize*/ << timestamp << name << message;
msgWidget->setHtml(currenttxt);
QString formatMsg = loadEmptyStyle()/*.replace(nickColor)
.replace(color)
.replace(font)
.replace(fontSize)*/
.replace("%timestamp%", timestamp)
.replace("%name%", name)
.replace("%message%", message);
QScrollBar *qsb = msgWidget->verticalScrollBar();
qsb -> setValue(qsb->maximum());
ui.textBrowser->setHtml(ui.textBrowser->toHtml() + formatMsg + "\n");
QTextCursor cursor = ui.textBrowser->textCursor();
cursor.movePosition(QTextCursor::End);
ui.textBrowser->setTextCursor(cursor);
//QScrollBar *qsb = ui.textBrowser->verticalScrollBar();
//qsb -> setValue(qsb->maximum());
}
void PopupChatDialog::checkChat()
@ -377,3 +394,46 @@ void PopupChatDialog::addSmiley()
{
ui.chattextEdit->setText(ui.chattextEdit->toHtml() + qobject_cast<QPushButton*>(sender())->toolTip());
}
QString PopupChatDialog::loadEmptyStyle()
{
QString ret;
QFile file(styleHtm);
file.open(QIODevice::ReadOnly);
ret = file.readAll();
file.close();
QString styleTmp = styleHtm;
QString styleCss = styleTmp.remove(styleHtm.lastIndexOf("."), styleHtm.length()-styleHtm.lastIndexOf(".")) + ".css";
qDebug() << styleCss.toAscii();
QFile css(styleCss);
css.open(QIODevice::ReadOnly);
QString tmp = css.readAll();
css.close();
ret.replace("%css-style%", tmp);
return ret;
}
void PopupChatDialog::changeStyle()
{
QString newStyle = QFileDialog::getOpenFileName(this, tr("Open Style"),
appDir + "/style/chat/",
tr("Styles (*.htm)"));
if(!newStyle.isEmpty())
{
QString wholeChat;
styleHtm = newStyle;
for(int i = 0; i < history.size(); i+=4)
{
QString formatMsg = loadEmptyStyle();
wholeChat += formatMsg.replace("%timestamp%", history.at(i+1))
.replace("%name%", history.at(i+2))
.replace("%message%", history.at(i+3)) + "\n";
}
ui.textBrowser->setHtml(wholeChat);
}
QTextCursor cursor = ui.textBrowser->textCursor();
cursor.movePosition(QTextCursor::End);
ui.textBrowser->setTextCursor(cursor);
}

View File

@ -54,6 +54,7 @@ public:
void loadEmoticons();
QString loadEmptyStyle();
public slots:
/** Overloaded QWidget.show */
@ -62,6 +63,7 @@ public slots:
void smileyWidget();
void addSmiley();
void changeStyle();
protected:
void closeEvent (QCloseEvent * event);
@ -94,6 +96,11 @@ private:
QColor mCurrentColor;
QFont mCurrentFont;
QString styleHtm;
QString emptyStyle;
QStringList history;
QString wholeChat;
/** Qt Designer generated object */
Ui::PopupChatDialog ui;
};

View File

@ -83,7 +83,7 @@
</property>
</spacer>
</item>
<item row="0" column="2" >
<item row="0" column="3" >
<widget class="QPushButton" name="textboldButton" >
<property name="minimumSize" >
<size>
@ -111,7 +111,7 @@
</property>
</widget>
</item>
<item row="0" column="3" >
<item row="0" column="4" >
<widget class="QPushButton" name="textunderlineButton" >
<property name="minimumSize" >
<size>
@ -139,7 +139,7 @@
</property>
</widget>
</item>
<item row="0" column="4" >
<item row="0" column="5" >
<widget class="QPushButton" name="textitalicButton" >
<property name="minimumSize" >
<size>
@ -167,7 +167,7 @@
</property>
</widget>
</item>
<item row="0" column="5" >
<item row="0" column="6" >
<widget class="QPushButton" name="fontButton" >
<property name="minimumSize" >
<size>
@ -195,7 +195,7 @@
</property>
</widget>
</item>
<item row="0" column="6" >
<item row="0" column="7" >
<widget class="QPushButton" name="colorButton" >
<property name="minimumSize" >
<size>
@ -248,6 +248,37 @@
</property>
</widget>
</item>
<item row="0" column="2" >
<widget class="QPushButton" name="styleButton" >
<property name="minimumSize" >
<size>
<width>28</width>
<height>28</height>
</size>
</property>
<property name="maximumSize" >
<size>
<width>28</width>
<height>28</height>
</size>
</property>
<property name="toolTip" >
<string>&lt;html>&lt;head>&lt;meta name="qrichtext" content="1" />&lt;style type="text/css">
p, li { white-space: pre-wrap; }
&lt;/style>&lt;/head>&lt;body style=" font-family:'MS Shell Dlg 2'; font-size:8.25pt; font-weight:400; font-style:normal;">
&lt;p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Set Chat Window Style&lt;/p>&lt;/body>&lt;/html></string>
</property>
<property name="text" >
<string/>
</property>
<property name="iconSize" >
<size>
<width>24</width>
<height>24</height>
</size>
</property>
</widget>
</item>
</layout>
</widget>
</item>

View File

@ -137,6 +137,7 @@
<file>images/ktorrent32.png</file>
<file>images/loadcert16.png</file>
<file>images/locale.png</file>
<file>images/looknfeel.png</file>
<file>images/lphoto.png</file>
<file>images/lphoto16.png</file>
<file>images/lphoto24.png</file>

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

View File

@ -0,0 +1,26 @@
.header {
font-weight: bold;
}
.time {
}
.incomingHeader {
background-color:#dfedff;
border-color:#fafafa #d1dfef #d1dfef #fafafa;
color: #295b07;
}
.incomingTime {
color: #295b07;
}
.outgoingHeader {
background-color:#f5f5f5;
border-color:#fafafa #e3e3e3 #e3e3e3 #fafafa;
color: #244578;
}
.outgoingTime {
color: #244578;
}

View File

@ -0,0 +1,23 @@
<style type="text/css">
%css-style%
</style>
<table width='100%' cellpadding='0' cellspacing='0'>
<tr>
<td class='header incomingHeader'>
%name%
</td>
</tr>
<tr>
<td>
<table width='100%' cellpadding='0' cellspacing='0'>
<tr>
<td>%message%</td>
<td width='50' align='left' class='time incomingTime'>%timestamp%</td>
</tr>
</table>
</td>
</tr>
</table>

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

View File

@ -0,0 +1,24 @@
.header {
font-weight: bold;
}
.time {
}
.incomingHeader {
background-color: #B2B2B2;
color: #000033;
}
.incomingTime {
color: #CCD9D9;
}
.outgoingHeader {
background-color: #c2d9fa;
color: #244578;
}
.outgoingTime {
color: #244578;
}

View File

@ -0,0 +1,28 @@
<style type="text/css">
%css-style%
</style>
<table width='100%' cellpadding='0' cellspacing='0'>
<tr>
<td align='right' width='32' bgcolor='white' rowspan='2'>
<div>
<img src='%avatar%'>
</div>
</td>
<td class='header incomingHeader'>
%name%
</td>
</tr>
<tr>
<td>
<table width='100%' cellpadding='0' cellspacing='0'>
<tr>
<td>%message%</td>
<td width='50' align='left' class='time incomingTime'>%timestamp%</td>
</tr>
</table>
</td>
</tr>
</table>