fixed up Chat Dialogs Formating features, cleaned up Formating codes and removed not needed experiments with formating.

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@426 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
defnax 2008-03-27 01:29:04 +00:00
parent 6a6299046c
commit 9001ee6d24
6 changed files with 221 additions and 238 deletions

View File

@ -52,6 +52,8 @@ ChatDialog::ChatDialog(QWidget *parent)
/* Invoke the Qt Designer generated object setup routine */
ui.setupUi(this);
setWindowIcon(QIcon(QString(":/images/rstray3.png")));
//connect(ui.lineEdit, SIGNAL(returnPressed( ) ), this, SLOT(sendMsg( ) ));
connect(ui.Sendbtn, SIGNAL(clicked()), this, SLOT(sendMsg()));
connect(ui.actionSend, SIGNAL( triggered (bool)), this, SLOT( sendMsg( ) ) );
@ -60,12 +62,12 @@ ChatDialog::ChatDialog(QWidget *parent)
connect( ui.msgSendList, SIGNAL( customContextMenuRequested( QPoint ) ), this, SLOT( msgSendListCostumPopupMenu( QPoint ) ) );
#ifdef CHAT_IMPROVEMENTS
connect(ui.textboldChatButton, SIGNAL(clicked()), this, SLOT(setFont()));
connect(ui.textunderlineChatButton, SIGNAL(clicked()), this, SLOT(setFont()));
connect(ui.textitalicChatButton, SIGNAL(clicked()), this, SLOT(setFont()));
connect(ui.fontsButton, SIGNAL(clicked()), this, SLOT(getFont()));
connect(ui.colorChatButton, SIGNAL(clicked()), this, SLOT(setColor()));
connect(ui.textboldChatButton, SIGNAL(clicked()), this, SLOT(insertBold()));
connect(ui.textunderlineChatButton, SIGNAL(clicked()), this, SLOT(insertUnderline()));
connect(ui.textitalicChatButton, SIGNAL(clicked()), this, SLOT(insertItalic()));
#endif
connect(ui.fontsButton, SIGNAL(clicked()), this, SLOT(setFont()));
ui.fontsButton->setIcon(QIcon(QString(":/images/fonts.png")));
@ -85,6 +87,8 @@ ChatDialog::ChatDialog(QWidget *parent)
pxm.fill(textColor);
ui.colorChatButton->setIcon(pxm);
QFont font = QFont("Comic Sans MS", 10);
/* Hide platform specific features */
#ifdef Q_WS_WIN
@ -136,10 +140,6 @@ void ChatDialog::insertChat()
QTextEdit *msgWidget = ui.msgText;
std::list<ChatInfo>::iterator it;
//QString color = ci.messageColor.name();
//QString nickColor;
//QString font = ci.messageFont.family();
//QString fontSize = QString::number(ci.messageFont.pointSize());
/* add in lines at the bottom */
for(it = newchat.begin(); it != newchat.end(); it++)
@ -183,20 +183,12 @@ void ChatDialog::sendMsg()
{
QTextEdit *lineWidget = ui.lineEdit;
QFont font = QFont("Comic Sans MS", 10);
font.setBold(ui.textboldChatButton->isChecked());
font.setUnderline(ui.textunderlineChatButton->isChecked());
font.setItalic(ui.textitalicChatButton->isChecked());
ChatInfo ci;
//ci.msg = lineWidget->Text().toStdWString();
ci.msg = lineWidget->toHtml().toStdWString();
ci.chatflags = RS_CHAT_PUBLIC;
//ci.messageFont = font;
//ci.messageColor = textColor;
rsMsgs -> ChatSend(ci);
//lineWidget -> setText(QString(""));
ui.lineEdit->clear();
/* redraw send list */
@ -289,18 +281,6 @@ void ChatDialog::toggleSendItem( QTreeWidgetItem *item, int col )
return;
}
void ChatDialog::setColor()
{
textColor = QColorDialog::getColor(Qt::black, this);
QPixmap pxm(24,24);
pxm.fill(textColor);
ui.lineEdit->setText(QString(tr("<a style=\"color:")) + (textColor.name()));
this->insertAutour(tr("\">"), tr("</style>"));
this->ui.lineEdit->setFocus();
ui.colorChatButton->setIcon(pxm);
}
void ChatDialog::privchat()
{
@ -340,50 +320,15 @@ void ChatDialog::clearOldChats()
}
void ChatDialog::insertBold()
void ChatDialog::setColor()
{
this->insertAutour(tr("<b>"), tr("</b>"));
this->ui.lineEdit->setFocus();
textColor = QColorDialog::getColor(Qt::black, this);
QPixmap pxm(24,24);
pxm.fill(textColor);
ui.colorChatButton->setIcon(pxm);
}
void ChatDialog::insertItalic()
{
this->insertAutour(tr("<i>"), tr("</i>"));
this->ui.lineEdit->setFocus();
}
void ChatDialog::insertUnderline()
{
this->insertAutour(tr("<u>"), tr("</u>"));
this->ui.lineEdit->setFocus();
}
void ChatDialog::insertStrike()
{
this->insertAutour(tr("<s>"), tr("</s>"));
this->ui.lineEdit->setFocus();
}
void ChatDialog::insertAutour(QString leftTruc,QString rightTruc)
{
/*int p0 = */ui.lineEdit->textCursor();
QString stringToInsert = leftTruc ;
stringToInsert.append(rightTruc);
ui.lineEdit->insertPlainText(stringToInsert);
//ui.lineEdit->setCursorPosition(p0 + leftTruc.size());
}
void ChatDialog::setFont()
void ChatDialog::getFont()
{
bool ok;
QFont font = QFontDialog::getFont(&ok, QFont(ui.lineEdit->toHtml()), this);
@ -391,3 +336,19 @@ void ChatDialog::setFont()
ui.lineEdit->setFont(font);
}
}
void ChatDialog::setFont()
{
QFont font = QFont("Comic Sans MS", 10);
font.setBold(ui.textboldChatButton->isChecked());
font.setUnderline(ui.textunderlineChatButton->isChecked());
font.setItalic(ui.textitalicChatButton->isChecked());
ui.lineEdit->setFont(font);
}

View File

@ -58,13 +58,9 @@ void toggleSendItem( QTreeWidgetItem *item, int col );
void sendMsg();
void privchat();
void insertBold();
void insertItalic();
void insertUnderline();
void insertStrike();
void insertAutour(QString leftTruc,QString rightTruc);
void setFont();
void getFont();
private:

View File

@ -831,6 +831,9 @@
<height>24</height>
</size>
</property>
<property name="toolTip" >
<string>Underline</string>
</property>
<property name="text" >
<string/>
</property>
@ -838,7 +841,7 @@
<iconset resource="images.qrc" >:/images/edit-underline.png</iconset>
</property>
<property name="checkable" >
<bool>false</bool>
<bool>true</bool>
</property>
</widget>
</item>
@ -856,6 +859,9 @@
<height>24</height>
</size>
</property>
<property name="toolTip" >
<string>Italic</string>
</property>
<property name="text" >
<string/>
</property>
@ -863,7 +869,7 @@
<iconset resource="images.qrc" >:/images/edit-italic.png</iconset>
</property>
<property name="checkable" >
<bool>false</bool>
<bool>true</bool>
</property>
</widget>
</item>
@ -881,6 +887,9 @@
<height>24</height>
</size>
</property>
<property name="toolTip" >
<string>Bold</string>
</property>
<property name="text" >
<string/>
</property>
@ -888,7 +897,7 @@
<iconset resource="images.qrc" >:/images/edit-bold.png</iconset>
</property>
<property name="checkable" >
<bool>false</bool>
<bool>true</bool>
</property>
</widget>
</item>
@ -906,6 +915,9 @@
<height>24</height>
</size>
</property>
<property name="toolTip" >
<string>Text Color</string>
</property>
<property name="text" >
<string/>
</property>
@ -925,6 +937,9 @@
<height>24</height>
</size>
</property>
<property name="toolTip" >
<string>Font</string>
</property>
<property name="text" >
<string/>
</property>

View File

@ -53,21 +53,15 @@ PopupChatDialog::PopupChatDialog(std::string id, std::string name,
showAvatarFrame(true);
connect(ui.avatarFrameButton, SIGNAL(toggled(bool)), this, SLOT(showAvatarFrame(bool)));
connect(ui.lineEdit, SIGNAL(returnPressed( ) ), this, SLOT(sendChat( ) ));
//connect(ui.chattextEdit, SIGNAL(returnPressed( ) ), this, SLOT(sendChat( ) ));
connect(ui.sendButton, SIGNAL(clicked( ) ), this, SLOT(sendChat( ) ));
connect(ui.textboldButton, SIGNAL(clicked()), this, SLOT(setFont()));
connect(ui.textunderlineButton, SIGNAL(clicked()), this, SLOT(setFont()));
connect(ui.textitalicButton, SIGNAL(clicked()), this, SLOT(setFont()));
connect(ui.fontButton, SIGNAL(clicked()), this, SLOT(getFont()));
connect(ui.colorButton, SIGNAL(clicked()), this, SLOT(setColor()));
//connect(ui.fontButton, SIGNAL(clicked()), this, SLOT(setFont()));
connect(ui.textboldButton, SIGNAL(clicked()), this, SLOT(insertBold()));
connect(ui.textunderlineButton, SIGNAL(clicked()), this, SLOT(insertUnderline()));
connect(ui.textitalicButton, SIGNAL(clicked()), this, SLOT(insertItalic()));
connect(ui.actionBold, SIGNAL(triggered()), this, SLOT(insertBold()));
connect(ui.actionItalic, SIGNAL(triggered()), this, SLOT(insertItalic()));
connect(ui.actionUnderline, SIGNAL(triggered()), this, SLOT(insertUnderline()));
connect(ui.actionStrike, SIGNAL(triggered()), this, SLOT(insertStrike()));
// Create the status bar
std::ostringstream statusstr;
@ -82,24 +76,28 @@ PopupChatDialog::PopupChatDialog(std::string id, std::string name,
//ui.avatarlabel->setPixmap(QPixmap(":/images/retrosharelogo1.png"));
setWindowIcon(QIcon(QString(":/images/rstray3.png")));
ui.textboldButton->setIcon(QIcon(QString(":/images/edit-bold.png")));
ui.textunderlineButton->setIcon(QIcon(QString(":/images/edit-underline.png")));
ui.textitalicButton->setIcon(QIcon(QString(":/images/edit-italic.png")));
ui.fontButton->setIcon(QIcon(QString(":/images/fonts.png")));
ui.actionBold->setIcon(QIcon(":/images/edit-bold.png"));
ui.actionUnderline->setIcon(QIcon(":/images/edit-underline.png"));
ui.actionItalic->setIcon(QIcon(":/images/edit-italic.png"));
//ui.actionStrike->setIcon(QIcon(":/exit.png"));
ui.textboldButton->setCheckable(true);
ui.textunderlineButton->setCheckable(true);
ui.textitalicButton->setCheckable(true);
QMenu * fontmenu = new QMenu();
/*QMenu * fontmenu = new QMenu();
fontmenu->addAction(ui.actionBold);
fontmenu->addAction(ui.actionUnderline);
fontmenu->addAction(ui.actionItalic);
fontmenu->addAction(ui.actionStrike);
ui.fontButton->setMenu(fontmenu);
ui.fontButton->setMenu(fontmenu);*/
QPixmap pxm(24,24);
pxm.fill(Qt::black);
ui.colorButton->setIcon(pxm);
QFont font = QFont("Comic Sans MS", 10);
}
@ -131,40 +129,6 @@ void PopupChatDialog::closeEvent (QCloseEvent * event)
event->ignore();
}
void PopupChatDialog::setColor()
{
QColor col = QColorDialog::getColor(Qt::green, this);
if (col.isValid()) {
ui.colorButton->setPalette(QPalette(col));
ui.lineEdit->setText(QString(tr("<a style=\"color:")) + (col.name()));
this->insertAutour(tr("\">"), tr("</style>"));
this->ui.lineEdit->setFocus();
QTextCharFormat fmt;
fmt.setForeground(col);
colorChanged(col);
}
}
void PopupChatDialog::setFont()
{
bool ok;
QFont font = QFontDialog::getFont(&ok, QFont(ui.lineEdit->text()), this);
if (ok) {
//ui.lineEdit->setText(font.key());
ui.lineEdit->setFont(font);
}
}
void PopupChatDialog::colorChanged(const QColor &c)
{
QPixmap pix(16, 16);
pix.fill(c);
ui.colorButton->setIcon(pix);
}
void PopupChatDialog::updateChat()
{
/* get chat off queue */
@ -211,7 +175,7 @@ void PopupChatDialog::addChatMsg(ChatInfo *ci)
//QString pre = tr("Peer:" );
QString name = QString::fromStdString(ci->name);
QString line = "<span style=\"color:#1D84C9\"><strong>" + timestamp +
" " + name + "</strong></span> \n<br>";
" " + name + "</strong></span>";
extraTxt += line;
@ -231,7 +195,7 @@ void PopupChatDialog::addChatMsg(ChatInfo *ci)
void PopupChatDialog::sendChat()
{
QLineEdit *lineWidget = ui.lineEdit;
QTextEdit *chatWidget = ui.chattextEdit;
ChatInfo ci;
@ -245,7 +209,7 @@ void PopupChatDialog::sendChat()
rsiface->unlockData(); /* Unlock Interface */
}
ci.msg = lineWidget->text().toStdWString();
ci.msg = chatWidget->toHtml().toStdWString();
ci.chatflags = RS_CHAT_PRIVATE;
addChatMsg(&ci);
@ -255,7 +219,7 @@ void PopupChatDialog::sendChat()
ci.name = dialogName;
rsMsgs -> ChatSend(ci);
lineWidget -> setText(QString(""));
chatWidget ->clear();
/* redraw send list */
}
@ -278,47 +242,52 @@ void PopupChatDialog::showAvatarFrame(bool show)
}
}
void PopupChatDialog::insertBold()
void PopupChatDialog::setColor()
{
QColor col = QColorDialog::getColor(Qt::black, this);
if (col.isValid()) {
this->insertAutour(tr("<b>"), tr("</b>"));
this->ui.lineEdit->setFocus();
ui.colorButton->setPalette(QPalette(col));
ui.chattextEdit->setTextColor(QColor(col));
QTextCharFormat fmt;
fmt.setForeground(col);
mergeFormatOnWordOrSelection(fmt);
colorChanged(col);
}
}
void PopupChatDialog::insertItalic()
void PopupChatDialog::colorChanged(const QColor &c)
{
this->insertAutour(tr("<i>"), tr("</i>"));
this->ui.lineEdit->setFocus();
QPixmap pix(16, 16);
pix.fill(c);
ui.colorButton->setIcon(pix);
}
void PopupChatDialog::insertUnderline()
void PopupChatDialog::mergeFormatOnWordOrSelection(const QTextCharFormat &format)
{
this->insertAutour(tr("<u>"), tr("</u>"));
this->ui.lineEdit->setFocus();
QTextCursor cursor = ui.chattextEdit->textCursor();
if (!cursor.hasSelection())
cursor.select(QTextCursor::WordUnderCursor);
cursor.mergeCharFormat(format);
ui.chattextEdit->mergeCurrentCharFormat(format);
}
void PopupChatDialog::insertStrike()
void PopupChatDialog::getFont()
{
this->insertAutour(tr("<s>"), tr("</s>"));
this->ui.lineEdit->setFocus();
bool ok;
QFont font = QFontDialog::getFont(&ok, QFont(ui.chattextEdit->toHtml()), this);
if (ok) {
ui.chattextEdit->setFont(font);
}
}
void PopupChatDialog::insertAutour(QString leftTruc,QString rightTruc)
void PopupChatDialog::setFont()
{
int p0 = ui.lineEdit->cursorPosition();
QString stringToInsert = leftTruc ;
stringToInsert.append(rightTruc);
ui.lineEdit->insert(stringToInsert);
ui.lineEdit->setCursorPosition(p0 + leftTruc.size());
QFont font = QFont("Comic Sans MS", 10);
font.setBold(ui.textboldButton->isChecked());
font.setUnderline(ui.textunderlineButton->isChecked());
font.setItalic(ui.textitalicButton->isChecked());
ui.chattextEdit->setFont(font);
}

View File

@ -50,17 +50,10 @@ public:
void updateChat();
void addChatMsg(ChatInfo *ci);
public slots:
/** Overloaded QWidget.show */
void show();
void insertBold();
void insertItalic();
void insertUnderline();
void insertStrike();
void insertAutour(QString leftTruc,QString rightTruc);
protected:
void closeEvent (QCloseEvent * event);
@ -70,6 +63,7 @@ private slots:
void showAvatarFrame(bool show);
void setColor();
void getFont();
void setFont();
void sendChat();
@ -77,7 +71,7 @@ private slots:
private:
void mergeFormatOnWordOrSelection(const QTextCharFormat &format);
void colorChanged(const QColor &c);
QAction *actionTextBold;

View File

@ -5,8 +5,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>565</width>
<height>349</height>
<width>560</width>
<height>410</height>
</rect>
</property>
<property name="windowTitle" >
@ -14,40 +14,19 @@
</property>
<widget class="QWidget" name="centralwidget" >
<layout class="QGridLayout" >
<property name="leftMargin" >
<number>0</number>
</property>
<property name="topMargin" >
<number>0</number>
</property>
<property name="rightMargin" >
<number>0</number>
</property>
<property name="bottomMargin" >
<number>0</number>
</property>
<property name="horizontalSpacing" >
<number>0</number>
</property>
<property name="verticalSpacing" >
<number>0</number>
</property>
<item row="0" column="0" >
<layout class="QGridLayout" >
<property name="leftMargin" >
<number>9</number>
</property>
<property name="topMargin" >
<number>9</number>
</property>
<property name="rightMargin" >
<number>0</number>
</property>
<property name="bottomMargin" >
<number>9</number>
</property>
<item row="0" column="0" >
<widget class="QTextBrowser" name="textBrowser" >
<property name="sizePolicy" >
<sizepolicy vsizetype="MinimumExpanding" hsizetype="Expanding" >
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize" >
<size>
<width>0</width>
@ -64,12 +43,6 @@
</item>
<item row="1" column="0" >
<layout class="QGridLayout" >
<property name="horizontalSpacing" >
<number>0</number>
</property>
<property name="verticalSpacing" >
<number>0</number>
</property>
<item row="0" column="0" >
<widget class="QWidget" native="1" name="widget" >
<property name="maximumSize" >
@ -82,6 +55,21 @@
<string/>
</property>
<layout class="QGridLayout" >
<property name="leftMargin" >
<number>0</number>
</property>
<property name="topMargin" >
<number>0</number>
</property>
<property name="rightMargin" >
<number>0</number>
</property>
<property name="bottomMargin" >
<number>0</number>
</property>
<property name="horizontalSpacing" >
<number>6</number>
</property>
<item row="0" column="0" >
<spacer>
<property name="orientation" >
@ -109,6 +97,9 @@
<height>24</height>
</size>
</property>
<property name="toolTip" >
<string>Bold</string>
</property>
<property name="text" >
<string/>
</property>
@ -134,6 +125,9 @@
<height>24</height>
</size>
</property>
<property name="toolTip" >
<string>Underline</string>
</property>
<property name="text" >
<string/>
</property>
@ -159,6 +153,9 @@
<height>24</height>
</size>
</property>
<property name="toolTip" >
<string>Italic</string>
</property>
<property name="text" >
<string/>
</property>
@ -184,6 +181,9 @@
<height>24</height>
</size>
</property>
<property name="toolTip" >
<string>Italic</string>
</property>
<property name="text" >
<string/>
</property>
@ -209,6 +209,9 @@
<height>24</height>
</size>
</property>
<property name="toolTip" >
<string>Text Color</string>
</property>
<property name="text" >
<string/>
</property>
@ -218,9 +221,31 @@
</widget>
</item>
<item row="1" column="0" >
<widget class="QTextEdit" name="chattextEdit" >
<property name="sizePolicy" >
<sizepolicy vsizetype="Maximum" hsizetype="Expanding" >
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
</layout>
</item>
<item row="2" column="0" >
<layout class="QGridLayout" >
<item row="0" column="0" >
<widget class="QLineEdit" name="lineEdit" />
<spacer>
<property name="orientation" >
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" >
<size>
<width>351</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="0" column="1" >
<widget class="QPushButton" name="sendButton" >
@ -233,8 +258,6 @@
</item>
</layout>
</item>
</layout>
</item>
<item row="0" column="1" >
<widget class="QFrame" name="avatarframe" >
<property name="frameShape" >
@ -244,6 +267,18 @@
<enum>QFrame::Raised</enum>
</property>
<layout class="QGridLayout" >
<property name="leftMargin" >
<number>0</number>
</property>
<property name="topMargin" >
<number>9</number>
</property>
<property name="rightMargin" >
<number>9</number>
</property>
<property name="bottomMargin" >
<number>9</number>
</property>
<item row="0" column="0" >
<widget class="QLabel" name="avatarlabel" >
<property name="minimumSize" >
@ -279,8 +314,8 @@ border-image: url(:/images/mystatus_bg.png);
</property>
<property name="sizeHint" >
<size>
<width>71</width>
<height>138</height>
<width>61</width>
<height>141</height>
</size>
</property>
</spacer>
@ -313,6 +348,19 @@ border-image: url(:/images/mystatus_bg.png);
</property>
</widget>
</item>
<item row="3" column="0" >
<spacer>
<property name="orientation" >
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" >
<size>
<width>61</width>
<height>41</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>