Added some static files to the chat example.

This commit is contained in:
Nathan Osman
2015-07-08 22:50:22 -07:00
parent 61a536fbd0
commit 61a5f9ad74
7 changed files with 117 additions and 3 deletions

View File

@@ -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

View File

@@ -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();
}

View 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>

View 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;
}

View 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>

View 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

File diff suppressed because one or more lines are too long