Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
S
skylivex
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
astronomy
skylivex
Commits
db966445
Commit
db966445
authored
Feb 24, 2013
by
Franco (nextime) Lanza
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make mainwin a derived class from a generic webwin class
parent
c7aac7f8
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
15 additions
and
183 deletions
+15
-183
jsbridge.cpp
src/jsbridge.cpp
+4
-4
jsbridge.h
src/jsbridge.h
+3
-2
mainwin.cpp
src/mainwin.cpp
+2
-140
mainwin.h
src/mainwin.h
+2
-36
skylivex.pro
src/skylivex.pro
+4
-1
No files found.
src/jsbridge.cpp
View file @
db966445
...
...
@@ -49,21 +49,21 @@ void JSBridge::pushLogin(QString username, QString password)
SKMessage
loginmsg
(
"putlogin"
);
loginmsg
.
parameters
.
insert
(
"username"
,
username
);
loginmsg
.
parameters
.
insert
(
"password"
,
password
);
m
win
->
sendMessage
(
loginmsg
);
w
win
->
sendMessage
(
loginmsg
);
}
void
JSBridge
::
resizeWin
(
int
width
,
int
height
)
{
m
win
->
resize
(
width
,
height
);
w
win
->
resize
(
width
,
height
);
}
void
JSBridge
::
toggleBorders
(
bool
borders
)
{
m
win
->
toggleBorders
(
borders
);
w
win
->
toggleBorders
(
borders
);
}
void
JSBridge
::
toggleTransparentBackground
(
bool
transparentbg
)
{
m
win
->
toggleTransparentBackground
(
transparentbg
);
w
win
->
toggleTransparentBackground
(
transparentbg
);
}
src/jsbridge.h
View file @
db966445
...
...
@@ -37,8 +37,9 @@
#include <QObject>
#include <QString>
#include "webwin.h"
class
Main
Win
;
// forward declaration for typedef
class
Web
Win
;
// forward declaration for typedef
/*
* class JSBridge
...
...
@@ -50,7 +51,7 @@ class JSBridge : public QObject
Q_OBJECT
public
:
MainWin
*
m
win
;
WebWin
*
w
win
;
void
changePageContent
(
QString
elementid
,
QString
content
);
signals
:
...
...
src/mainwin.cpp
View file @
db966445
...
...
@@ -33,7 +33,7 @@
*
*/
#include "mainwin.h"
#include
<QWebView>
#include
"webwin.h"
#include <QWebFrame>
#include <QFile>
#include <QUrl>
...
...
@@ -48,28 +48,8 @@
#define SENDER "maingui"
MainWin
::
MainWin
(
QString
&
htmlfile
)
:
QWebView
(
0
)
:
WebWin
(
htmlfile
)
{
baseUrl
=
QUrl
::
fromLocalFile
(
QDir
::
current
().
absoluteFilePath
(
"gui/dummy.html"
));
QPalette
pal
=
palette
();
pal
.
setBrush
(
QPalette
::
Base
,
Qt
::
transparent
);
setWindowFlags
(
Qt
::
FramelessWindowHint
);
page
()
->
setPalette
(
pal
);
setAttribute
(
Qt
::
WA_TranslucentBackground
,
true
);
setAttribute
(
Qt
::
WA_OpaquePaintEvent
,
false
);
setHtmlFile
(
htmlfile
);
resize
(
250
,
200
);
//jsbridge.mwin=qobject_cast<MainWin *>(this);
//page()->mainFrame()->addToJavaScriptWindowObject("SkyliveX", &jsbridge);
jsbridge
=
new
JSBridge
();
jsbridge
->
mwin
=
qobject_cast
<
MainWin
*>
(
this
);
page
()
->
mainFrame
()
->
addToJavaScriptWindowObject
(
"SkyliveX"
,
jsbridge
);
connect
(
page
()
->
mainFrame
(),
SIGNAL
(
javaScriptWindowObjectCleared
()),
this
,
SLOT
(
refreshJsObject
()));
registerHandler
((
QString
)
"coreStarted"
,
(
SKHandlerFunction
)
&
MainWin
::
handle_corestarted
);
registerHandler
((
QString
)
"telescopeConnected"
,
(
SKHandlerFunction
)
&
MainWin
::
handle_connected
);
...
...
@@ -89,123 +69,11 @@ MainWin::~MainWin()
}
// XXX This can be used in future to permit
// to drag a window borderless on the desktop.
/*
void MainWin::dragMoveEvent(QDragMoveEvent *ev)
{
std::cout << "Drag Move Event " << ev->pos().x() << std::endl;
}
*/
void
MainWin
::
refreshJsObject
()
{
//page()->mainFrame()->addToJavaScriptWindowObject("SkyliveX", &jsbridge);
jsbridge
=
new
JSBridge
();
jsbridge
->
mwin
=
qobject_cast
<
MainWin
*>
(
this
);
page
()
->
mainFrame
()
->
addToJavaScriptWindowObject
(
"SkyliveX"
,
jsbridge
);
}
void
MainWin
::
setHtmlFile
(
QString
&
fname
)
{
QFile
filename
(
fname
);
filename
.
open
(
QIODevice
::
ReadOnly
);
htmlFileCont
=
QString
::
fromUtf8
(
filename
.
readAll
().
constData
());
setHtml
(
htmlFileCont
,
baseUrl
);
//page()->mainFrame()->addToJavaScriptWindowObject("SkyliveX", &jsbridge);
//jsbridge.mwin=qobject_cast<MainWin *>(this);
}
void
MainWin
::
setHtmlFile
(
QString
&
fname
,
bool
borders
,
bool
transparentbg
)
{
toggleBorders
(
borders
);
toggleTransparentBackground
(
transparentbg
);
setHtmlFile
(
fname
);
}
void
MainWin
::
setHtmlCont
(
QString
cont
,
QUrl
baseUrl
,
bool
borders
,
bool
transparentbg
)
{
toggleBorders
(
borders
);
toggleTransparentBackground
(
transparentbg
);
setHtml
(
cont
,
baseUrl
);
}
void
MainWin
::
msgFromCore
(
SKMessage
&
msg
)
{
std
::
cout
<<
"MainWindow msg reveived: "
<<
msg
.
handle
.
toStdString
()
<<
std
::
endl
;
if
(
_handlers
.
contains
(
msg
.
handle
)
&&
msg
.
sender
!=
SENDER
)
{
SKHandlerFunction
mf
=
_handlers
[
msg
.
handle
];
(
this
->*
mf
)(
msg
);
}
}
void
MainWin
::
toggleBorders
(
bool
borders
)
{
Qt
::
WindowFlags
flags
=
windowFlags
();
if
(
borders
)
{
if
(
flags
&
Qt
::
FramelessWindowHint
)
{
flags
&=
~
Qt
::
FramelessWindowHint
;
setWindowFlags
(
flags
);
show
();
}
}
else
{
if
(
!
(
flags
&
Qt
::
FramelessWindowHint
))
{
flags
&=
Qt
::
FramelessWindowHint
;
setWindowFlags
(
flags
);
show
();
}
}
}
void
MainWin
::
toggleTransparentBackground
(
bool
transparentbg
)
{
QPalette
pal
=
palette
();
if
(
transparentbg
)
{
pal
.
setBrush
(
QPalette
::
Base
,
Qt
::
transparent
);
setAttribute
(
Qt
::
WA_TranslucentBackground
,
true
);
setAttribute
(
Qt
::
WA_OpaquePaintEvent
,
false
);
}
else
{
pal
.
setBrush
(
QPalette
::
Base
,
Qt
::
white
);
setAttribute
(
Qt
::
WA_TranslucentBackground
,
false
);
setAttribute
(
Qt
::
WA_OpaquePaintEvent
,
true
);
}
page
()
->
setPalette
(
pal
);
}
void
MainWin
::
sendMessage
(
SKMessage
&
msg
)
{
msg
.
sender
=
SENDER
;
emit
putMessage
(
msg
);
}
void
MainWin
::
registerHandler
(
QString
type
,
SKHandlerFunction
handler
)
{
_handlers
[
type
]
=
handler
;
}
void
MainWin
::
handle_corestarted
(
SKMessage
&
msg
)
{
msg
.
handle
=
"connectTelescopes"
;
sendMessage
(
msg
);
//jsbridge.notify("Connecting...");
jsbridge
->
notify
(
"Connecting..."
);
}
...
...
@@ -213,14 +81,12 @@ void MainWin::handle_corestarted(SKMessage &msg)
void
MainWin
::
handle_connected
(
SKMessage
&
msg
)
{
std
::
cout
<<
"Connected by "
<<
msg
.
sender
.
toStdString
()
<<
std
::
endl
;
//jsbridge.notify("Connected");
jsbridge
->
notify
(
"Connected"
);
}
void
MainWin
::
handle_asklogin
(
SKMessage
&
msg
)
{
std
::
cout
<<
"asklogin by "
<<
msg
.
sender
.
toStdString
()
<<
std
::
endl
;
//jsbridge.notify("Logging in");
jsbridge
->
notify
(
"Logging in"
);
QString
html
(
"gui/login.html"
);
setHtmlFile
(
html
,
true
,
false
);
...
...
@@ -231,14 +97,12 @@ void MainWin::handle_asklogin(SKMessage &msg)
void
MainWin
::
handle_alert
(
SKMessage
&
msg
)
{
if
(
msg
.
parameters
.
contains
(
"msg"
))
//jsbridge.alertmsg(msg.parameters["msg"]);
jsbridge
->
alertmsg
(
msg
.
parameters
[
"msg"
]);
}
void
MainWin
::
handle_notify
(
SKMessage
&
msg
)
{
if
(
msg
.
parameters
.
contains
(
"msg"
))
//jsbridge.notify(msg.parameters["msg"]);
jsbridge
->
notify
(
msg
.
parameters
[
"msg"
]);
}
...
...
@@ -246,7 +110,6 @@ void MainWin::handle_loginres(SKMessage &msg)
{
if
(
msg
.
handle
==
"loginok"
)
{
//std::cout << "LOGIN OK" << std::endl;
QString
html
(
"gui/maingui.html"
);
setHtmlFile
(
html
,
true
,
false
);
resize
(
800
,
600
);
...
...
@@ -263,7 +126,6 @@ void MainWin::handle_chatreceived(SKMessage &msg)
{
if
(
msg
.
parameters
.
contains
(
"msg"
)
&&
msg
.
parameters
.
contains
(
"username"
))
{
//jsbridge.public_received(msg.parameters["username"], msg.parameters["msg"]);
jsbridge
->
public_received
(
msg
.
parameters
[
"username"
],
msg
.
parameters
[
"msg"
]);
}
}
...
...
src/mainwin.h
View file @
db966445
...
...
@@ -35,48 +35,28 @@
#ifndef MAINWIN_H
#define MAINWIN_H
#include <QWebView>
#include <QUrl>
#include <QFile>
#include <QHash>
#include <QString>
#include <QObject>
#include <ipcmsg.h>
#include "webwin.h"
#include "jsbridge.h"
class
MainWin
;
// forward declaration for typedef
// This is for member pointers to map messages
typedef
void
(
MainWin
::*
SKHandlerFunction
)(
SKMessage
&
);
//typedef int (MainWin::*SKHandlerFunction)(SKMessage&);
/*
* class MainWin
* This is just a little webkit transparent window
* to show the splash screen
*/
class
MainWin
:
public
QWebView
class
MainWin
:
public
WebWin
{
Q_OBJECT
QUrl
baseUrl
;
QString
htmlfile
;
QString
htmlFileCont
;
//JSBridge jsbridge;
JSBridge
*
jsbridge
;
private
:
QHash
<
QString
,
SKHandlerFunction
>
_handlers
;
void
setHtmlFile
(
QString
&
fname
);
void
setHtmlFile
(
QString
&
fname
,
bool
borders
,
bool
transparentbg
);
void
setHtmlCont
(
QString
cont
,
QUrl
baseUrl
,
bool
borders
,
bool
transparentbg
);
public
:
MainWin
(
QString
&
htmlfile
);
~
MainWin
();
void
sendMessage
(
SKMessage
&
msg
);
void
registerHandler
(
QString
type
,
SKHandlerFunction
handler
);
void
handle_corestarted
(
SKMessage
&
msg
);
void
handle_connected
(
SKMessage
&
msg
);
void
handle_asklogin
(
SKMessage
&
msg
);
...
...
@@ -84,21 +64,7 @@ class MainWin : public QWebView
void
handle_notify
(
SKMessage
&
msg
);
void
handle_loginres
(
SKMessage
&
msg
);
void
handle_chatreceived
(
SKMessage
&
msg
);
void
toggleBorders
(
bool
borders
);
void
toggleTransparentBackground
(
bool
transparentbg
);
private
slots
:
void
refreshJsObject
();
public
slots
:
void
msgFromCore
(
SKMessage
&
msg
);
signals
:
void
putMessage
(
SKMessage
&
msg
);
// XXX Future usage
//protected:
// void dragMoveEvent(QDragMoveEvent *ev);
};
...
...
src/skylivex.pro
View file @
db966445
SOURCES
=
main
.
cpp
\
webwin
.
cpp
\
mainwin
.
cpp
\
skylivex
.
cpp
\
ipcmsg
.
cpp
ipcmsg
.
cpp
\
jsbridge
.
cpp
HEADERS
=
skylivex
.
h
\
webwin
.
h
\
mainwin
.
h
\
pluginsinterfaces
.
h
\
ipcmsg
.
h
\
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment