Added some static files to the chat example.
This commit is contained in:
@@ -2,7 +2,9 @@ set(SRC
|
||||
main.cpp
|
||||
)
|
||||
|
||||
add_executable(chat ${SRC})
|
||||
qt5_add_resources(QRC resources.qrc)
|
||||
|
||||
add_executable(chat ${SRC} ${QRC})
|
||||
target_link_libraries(chat qhttpengine)
|
||||
|
||||
set_target_properties(chat PROPERTIES
|
||||
|
||||
@@ -25,13 +25,19 @@
|
||||
#include <QFilesystemHandler>
|
||||
#include <QHttpHandler>
|
||||
#include <QHttpServer>
|
||||
#include <QObjectHandler>
|
||||
|
||||
int main(int argc, char * argv[])
|
||||
{
|
||||
QCoreApplication a(argc, argv);
|
||||
|
||||
//...
|
||||
QFilesystemHandler handler(":/static");
|
||||
QHttpServer server(&handler);
|
||||
|
||||
// Listen on the specified port
|
||||
if(!server.listen(QHostAddress::Any, 8000)) {
|
||||
qCritical("Unable to listen on the specified port.");
|
||||
return 1;
|
||||
}
|
||||
|
||||
return a.exec();
|
||||
}
|
||||
|
||||
8
examples/chat/resources.qrc
Normal file
8
examples/chat/resources.qrc
Normal file
@@ -0,0 +1,8 @@
|
||||
<RCC>
|
||||
<qresource prefix="/">
|
||||
<file>static/index.html</file>
|
||||
<file>static/css/style.css</file>
|
||||
<file>static/js/jquery.min.js</file>
|
||||
<file>static/js/chat.js</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
48
examples/chat/static/css/style.css
Normal file
48
examples/chat/static/css/style.css
Normal file
@@ -0,0 +1,48 @@
|
||||
* {
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
html, body {
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
body {
|
||||
background-color: #dec;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
#input {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.footer {
|
||||
background-color: #ac9;
|
||||
box-shadow: 0 0 5px #333;
|
||||
padding: 10px;
|
||||
position: fixed;
|
||||
bottom: 0;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.footer textarea {
|
||||
background-color: #dec;
|
||||
border: none;
|
||||
border-radius: 4px;
|
||||
padding: 4px;
|
||||
}
|
||||
|
||||
.messages {
|
||||
padding: 10px;
|
||||
}
|
||||
|
||||
.message {
|
||||
background-color: #efd;
|
||||
border-radius: 4px;
|
||||
font-size: 10pt;
|
||||
margin-bottom: 4px;
|
||||
padding: 8px 16px;
|
||||
}
|
||||
|
||||
.message.system {
|
||||
color: #777;
|
||||
}
|
||||
25
examples/chat/static/index.html
Normal file
25
examples/chat/static/index.html
Normal file
@@ -0,0 +1,25 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
|
||||
<title>QHttpEngine Chat</title>
|
||||
|
||||
<link rel="stylesheet" href="css/style.css">
|
||||
</head>
|
||||
<body>
|
||||
<div class="footer">
|
||||
<textarea id="input" placeholder="Type here and press enter..."></textarea>
|
||||
</div>
|
||||
|
||||
<div class="messages">
|
||||
<div class="message system">
|
||||
Greetings! Welcome to the QHttpEngine chat demo. Please type a message using the entry box below.
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="js/jquery.min.js"></script>
|
||||
<script src="js/chat.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
21
examples/chat/static/js/chat.js
Normal file
21
examples/chat/static/js/chat.js
Normal file
@@ -0,0 +1,21 @@
|
||||
$(function() {
|
||||
|
||||
// Find the list of messages
|
||||
var $messages = $('.messages');
|
||||
|
||||
// Find the message input box and set the appropriate handler for [enter]
|
||||
var $input = $('#input').focus().keypress(function(e) {
|
||||
if(e.which == 13) {
|
||||
|
||||
// Create the new message to append
|
||||
$('<div>')
|
||||
.addClass('message')
|
||||
.text($(this).val())
|
||||
.appendTo($messages);
|
||||
|
||||
// Clear the contents
|
||||
$(this).val('');
|
||||
return false;
|
||||
}
|
||||
});
|
||||
});
|
||||
4
examples/chat/static/js/jquery.min.js
vendored
Normal file
4
examples/chat/static/js/jquery.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user