4 SubWindow::SubWindow(Serve
*ser
, QString str
)
10 QStringList s
=str
.split(":");
11 qDebug()<<"s.at(0) address:"<<s
.at(0);
12 msgmng
->username
= s
.at(1);
13 msgmng
->hostname
= s
.at(1);
14 msgmng
->address
= (QHostAddress
)s
.at(0);
15 connect(service
, SIGNAL(msgSendMsg(MsgMng
*)) , this, SLOT(showMessage(MsgMng
*)));
18 void SubWindow::showMessage(MsgMng
*msg
)
20 qDebug()<<"["<<QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss")<<"] "<<msg
->username
<<":\n"<<msg
->extend
;
21 recordTextEdit
->append("[" + QDateTime::currentDateTime().toString(tr("yyyy-MM-dd hh:mm:ss"))
22 + tr("] ") +msg
->username
+" :");
23 recordTextEdit
->append(msg
->extend
);
27 void SubWindow::closeEvent(QCloseEvent
*event
)
30 /*MsgMng *msg = new MsgMng;
31 msg->command = IPMSG_BR_EXIT;
33 service->broadcast(6291458, NULL);*/
35 QString str
=msgmng
->address
.toString()+":"+msgmng
->username
;
37 qDebug()<<"emit delSub(str)";
38 //service->udpSocket->close();
44 void SubWindow::sendMessage()
46 qDebug()<<"sendMessage():"<<msgmng
->hostname
<<":"<<msgmng
->username
;
47 if(msgmng
->hostname
.endsWith("*"))
48 message
= inputTextEdit
->toHtml();
50 message
= inputTextEdit
->toPlainText();
51 //char *m = inputTextEdit->toPlainText();
52 //message=message.toUtf8();
53 //message = m->fromUtf8(m, -1);
54 recordTextEdit
->append("[" + QDateTime::currentDateTime().toString(tr("yyyy-MM-dd hh:mm:ss"))
55 + tr("] ") + (QHostInfo::localHostName()));
56 recordTextEdit
->append(message
);
57 //connect(fontComboBox, SIGNAL(activated(const QString &)),inputTextEdit, SLOT(setFontFamily(const QString &)));
58 MsgMng
*msg
= new MsgMng
;
59 //msg->command=IPMSG_SENDMSG;
63 msg
->address
=msgmng
->address
;
64 //QString str=msg->address.toString()+":"+msg->username;
65 qDebug()<<"sendMessage() msgmng->address"<<msgmng
->address
;
66 qDebug()<<"sendMessage() msg->address"<<msg
->address
;
67 service
->sendUdp(msg
);
68 qDebug()<<"End of sendUdp";
70 inputTextEdit
->clear();
75 void SubWindow::about()
77 QMessageBox::information(this, tr("About"),tr("This project is on Linux+QT4 platform, which was used for transfer files on Internet, providing communication with IP MSG, FeiQ or other clients. It is written for KDE envirenment. This software is released under GPL lisence, for more details about the license, please see the content of file COPYING."));
81 void SubWindow::enabledSendButton()
83 sendButton
->setEnabled(true);
87 void SubWindow::setFontColor()
89 QColor col
= QColorDialog::getColor(inputTextEdit
->textColor(), this);
94 inputTextEdit
->setTextColor(col
);
98 colorButton
->setIcon(pix
);
102 void SubWindow::openImage()
104 //实现图像同步的策略为,先复制图像到自己和别人机器的 temp-image/ 下,然后在数据包中加入HTML的显示本地图像代码
105 QString image
= QFileDialog::getOpenFileName(this, tr("Open Image File..."),
106 "temp-image/", tr("Image-Files (*.png *.gif *.bmp *.jpeg *.jpg)"));
107 QFile::copy(image
, QString("temp-image/") + QFileInfo(image
).fileName());
112 inputTextEdit
->append("<img src='temp-image/" + QFileInfo(image
).fileName() + "' />");
117 QDataStream
out(&datagram
,QIODevice::WriteOnly
);
121 out
<< QFileInfo(image
).fileName();
123 QImageReader
imageReader(image
);
124 imageReader
.setFormat(QFileInfo(image
).suffix().toAscii());
125 out
<< imageReader
.read();
128 void SubWindow::sendFile()
130 QString file
= QFileDialog::getOpenFileName(this, tr("Send File..."),
131 "~", tr("Image-Files (*)"));
132 //QFile::copy(image, QString("temp-image/") + QFileInfo(image).fileName());
135 qDebug()<<"file is empty";
139 recordTextEdit
->append("[" + QDateTime::currentDateTime().toString(tr("yyyy-MM-dd hh:mm:ss"))
140 + tr("] ") + (QHostInfo::localHostName())+tr(":\n") +"Send File: "+file
);
141 //inputTextEdit->append("Send file: "+file);
142 //inputTextEdit->append("Send file: "+QFileInfo(file).fileName());
143 MsgMng
*msg
= new MsgMng
;
144 //msg->command=IPMSG_SENDMSG;
145 msg
->command
=2097440;
148 msg
->address
=msgmng
->address
;
149 //QString str=msg->address.toString()+":"+msg->username;
150 qDebug()<<"sendMessage() msgmng->address"<<msgmng
->address
;
151 qDebug()<<"sendMessage() msg->address"<<msg
->address
;
152 service
->sendTcp(msg
, file
);
153 qDebug()<<"End of sendTcp";
158 void SubWindow::setFontSize(const QString
&size
)
160 inputTextEdit
->setFontPointSize(size
.toFloat());
164 void SubWindow::setBoldFont(bool flag
)
168 inputTextEdit
->setFontWeight(QFont::Bold
);
171 inputTextEdit
->setFontWeight(QFont::Normal
);
175 void SubWindow::initialize()
179 setMinimumSize(620,600);
180 setMaximumSize(620,600);
181 setWindowTitle(tr("Pigeons by Xiyou-Linux-Group"));
183 messageWindow
= new QWidget(this);
184 messageWindow
->resize(620,600);
185 messageWindow
->setMinimumSize(620,600);
186 messageWindow
->setMaximumSize(620,600);
188 recordTextEdit
= new QTextEdit(messageWindow
);
189 recordTextEdit
->setReadOnly(true);
190 recordTextEdit
->setMinimumSize(600,300);
192 inputTextEdit
= new QTextEdit(messageWindow
);
193 inputTextEdit
->setMinimumSize(490,100);
194 inputTextEdit
->setMaximumSize(600,180);
196 editToolBar
= new QToolBar(messageWindow
);
199 fontComboBox
= new QComboBox(editToolBar
);
200 editToolBar
->addWidget(fontComboBox
);
201 fontComboBox
->setEditable(true);
202 QFontDatabase fontDB
;
203 fontComboBox
->addItems(fontDB
.families());
204 connect(fontComboBox
, SIGNAL(activated(const QString
&)),
205 inputTextEdit
, SLOT(setFontFamily(const QString
&)));
206 fontComboBox
->setCurrentIndex(fontComboBox
->findText(QApplication::font().family()));
209 sizeComboBox
= new QComboBox(editToolBar
);
210 editToolBar
->addWidget(sizeComboBox
);
211 sizeComboBox
->setEditable(true);
212 foreach(int size
, fontDB
.standardSizes())
213 sizeComboBox
->addItem(QString::number(size
));
214 connect(sizeComboBox
, SIGNAL(activated(const QString
&)),
215 this, SLOT(setFontSize(const QString
&)));
216 sizeComboBox
->setCurrentIndex(sizeComboBox
->findText(QString::number(QApplication::font().pointSize())));
219 boldButton
= new QToolButton(editToolBar
);
220 editToolBar
->addWidget(boldButton
);
221 boldButton
->setCheckable(true);
222 boldButton
->setIcon(QIcon(":/data/textbold.png"));
223 connect(boldButton
, SIGNAL(toggled(bool)), this, SLOT(setBoldFont(bool)));
226 italicButton
= new QToolButton(editToolBar
);
227 editToolBar
->addWidget(italicButton
);
228 italicButton
->setCheckable(true);
229 italicButton
->setIcon(QIcon(":/data/textitalic.png"));
230 connect(italicButton
, SIGNAL(toggled(bool)), inputTextEdit
, SLOT(setFontItalic(bool)));
233 underlineButton
= new QToolButton(editToolBar
);
234 editToolBar
->addWidget(underlineButton
);
235 underlineButton
->setCheckable(true);
236 underlineButton
->setIcon(QIcon(":/data/textunder.png"));
237 connect(underlineButton
, SIGNAL(toggled(bool)), inputTextEdit
, SLOT(setFontUnderline(bool)));
240 colorButton
= new QToolButton(editToolBar
);
241 editToolBar
->addWidget(colorButton
);
242 colorButton
->setIcon(QIcon(":/data/textcolor.png"));
243 connect(colorButton
, SIGNAL(clicked()), this, SLOT(setFontColor()));
246 imageButton
= new QToolButton(editToolBar
);
247 editToolBar
->addWidget(imageButton
);
248 imageButton
->setIcon(QIcon(":/data/openimage.png"));
249 connect(imageButton
, SIGNAL(clicked()), this, SLOT(openImage()));
252 fileButton
= new QToolButton(editToolBar
);
253 editToolBar
->addWidget(fileButton
);
254 fileButton
->setIcon(QIcon(":/data/file.png"));
255 connect(fileButton
, SIGNAL(clicked()), this, SLOT(sendFile()));
258 sendButton
= new QPushButton(tr("&Send"), messageWindow
);
259 sendButton
->setEnabled(false);
260 connect(inputTextEdit
, SIGNAL(textChanged()), this, SLOT(enabledSendButton()));
261 connect(sendButton
, SIGNAL(clicked()), this, SLOT(sendMessage()));
264 aboutButton
= new QPushButton(tr("&About"),messageWindow
);
265 connect(aboutButton
, SIGNAL(clicked()), this, SLOT(about()));
268 //userListWidget = new QListWidget(messageWindow);
269 //userListWidget->setMinimumSize(120,420);
270 //userListWidget->setMaximumSize(180,600);
273 quitButton
= new QPushButton(tr("&Quit"),messageWindow
);
274 connect(quitButton
,SIGNAL(clicked()), this, SLOT(close()));
277 QHBoxLayout
*buttonLayout
= new QHBoxLayout
;
278 buttonLayout
->addWidget(aboutButton
);
279 buttonLayout
->addStretch(3);
280 buttonLayout
->addWidget(sendButton
);
281 buttonLayout
->addStretch(1);
282 buttonLayout
->addWidget(quitButton
);
284 QVBoxLayout
*leftLayout
= new QVBoxLayout
;
285 leftLayout
->addWidget(recordTextEdit
);
286 leftLayout
->addWidget(editToolBar
);
287 leftLayout
->addWidget(inputTextEdit
);
289 QGridLayout
*mainLayout
= new QGridLayout
;
290 mainLayout
->addLayout(leftLayout
,0,0);
291 //mainLayout->addWidget(userListWidget,0,1);
292 mainLayout
->addLayout(buttonLayout
,1,0,1,2);
293 mainLayout
->setSizeConstraint(QLayout::SetFixedSize
);
295 messageWindow
->setLayout(mainLayout
);
296 messageWindow
->show();