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
3d3bb04e
Commit
3d3bb04e
authored
Feb 24, 2013
by
Stefy Lanza (nextime / spora )
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added generic webwin class
parent
db966445
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
288 additions
and
0 deletions
+288
-0
webwin.cpp
src/webwin.cpp
+190
-0
webwin.h
src/webwin.h
+98
-0
No files found.
src/webwin.cpp
0 → 100644
View file @
3d3bb04e
/* ____ _ _ _ __ __
* / ___|| | ___ _| (_)_ _____\ \/ /
* \___ \| |/ / | | | | \ \ / / _ \\ /
* ___) | <| |_| | | |\ V / __// \ Remote Telescopes
* |____/|_|\_\\__, |_|_| \_/ \___/_/\_\ For the masses
* |___/
*
* Copyright (C) 2013 Franco (nextime) Lanza <nextime@nexlab.it>
* Copyright (C) 2013 Ivan Bellia <skylive@skylive.it>
*
* All rights reserved.
*
* This file is part of SkyliveX.
*
* SkyliveX is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Foobar is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Foobar. If not, see <http://www.gnu.org/licenses/>.
*
********************************************************************
*
* File: splashpage.cpp
*
* Purpose:
*
*/
#include "webwin.h"
#include <QWebView>
#include <QWebFrame>
#include <QFile>
#include <QUrl>
#include <QDir>
#include <QString>
#include <QPalette>
#include <QDragMoveEvent>
#include <iostream>
#include "ipcmsg.h"
#include "jsbridge.h"
#define SENDER "webwin"
WebWin
::
WebWin
(
QString
&
htmlfile
)
:
QWebView
(
0
)
{
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
=
new
JSBridge
();
jsbridge
->
wwin
=
qobject_cast
<
WebWin
*>
(
this
);
page
()
->
mainFrame
()
->
addToJavaScriptWindowObject
(
"SkyliveX"
,
jsbridge
);
connect
(
page
()
->
mainFrame
(),
SIGNAL
(
javaScriptWindowObjectCleared
()),
this
,
SLOT
(
refreshJsObject
()));
}
WebWin
::~
WebWin
()
{
}
// XXX This can be used in future to permit
// to drag a window borderless on the desktop.
/*
void WebWin::dragMoveEvent(QDragMoveEvent *ev)
{
std::cout << "Drag Move Event " << ev->pos().x() << std::endl;
}
*/
void
WebWin
::
refreshJsObject
()
{
//page()->mainFrame()->addToJavaScriptWindowObject("SkyliveX", &jsbridge);
jsbridge
=
new
JSBridge
();
jsbridge
->
wwin
=
qobject_cast
<
WebWin
*>
(
this
);
page
()
->
mainFrame
()
->
addToJavaScriptWindowObject
(
"SkyliveX"
,
jsbridge
);
}
void
WebWin
::
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<WebWin *>(this);
}
void
WebWin
::
setHtmlFile
(
QString
&
fname
,
bool
borders
,
bool
transparentbg
)
{
toggleBorders
(
borders
);
toggleTransparentBackground
(
transparentbg
);
setHtmlFile
(
fname
);
}
void
WebWin
::
setHtmlCont
(
QString
cont
,
QUrl
baseUrl
,
bool
borders
,
bool
transparentbg
)
{
toggleBorders
(
borders
);
toggleTransparentBackground
(
transparentbg
);
setHtml
(
cont
,
baseUrl
);
}
void
WebWin
::
msgFromCore
(
SKMessage
&
msg
)
{
std
::
cout
<<
"WebWindow msg reveived: "
<<
msg
.
handle
.
toStdString
()
<<
std
::
endl
;
if
(
_handlers
.
contains
(
msg
.
handle
)
&&
msg
.
sender
!=
SENDER
)
{
SKHandlerFunction
mf
=
_handlers
[
msg
.
handle
];
(
this
->*
mf
)(
msg
);
}
}
void
WebWin
::
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
WebWin
::
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
WebWin
::
sendMessage
(
SKMessage
&
msg
)
{
msg
.
sender
=
SENDER
;
emit
putMessage
(
msg
);
}
void
WebWin
::
registerHandler
(
QString
type
,
SKHandlerFunction
handler
)
{
_handlers
[
type
]
=
handler
;
}
src/webwin.h
0 → 100644
View file @
3d3bb04e
/* ____ _ _ _ __ __
* / ___|| | ___ _| (_)_ _____\ \/ /
* \___ \| |/ / | | | | \ \ / / _ \\ /
* ___) | <| |_| | | |\ V / __// \ Remote Telescopes
* |____/|_|\_\\__, |_|_| \_/ \___/_/\_\ For the masses
* |___/
*
* Copyright (C) 2013 Franco (nextime) Lanza <nextime@nexlab.it>
* Copyright (C) 2013 Ivan Bellia <skylive@skylive.it>
*
* All rights reserved.
*
* This file is part of SkyliveX.
*
* SkyliveX is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Foobar is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Foobar. If not, see <http://www.gnu.org/licenses/>.
*
********************************************************************
*
* File: skylivex.h
*
* Purpose:
*
*/
#ifndef WEBWIN_H
#define WEBWIN_H
#include <QWebView>
#include <QUrl>
#include <QFile>
#include <QHash>
#include <QString>
#include <QObject>
#include <ipcmsg.h>
#include "jsbridge.h"
class
WebWin
;
// forward declaration for typedef
class
JSBridge
;
// forward declaration
// This is for member pointers to map messages
typedef
void
(
WebWin
::*
SKHandlerFunction
)(
SKMessage
&
);
//typedef int (WebWin::*SKHandlerFunction)(SKMessage&);
/*
* class WebWin
* This is just a little webkit transparent window
* to show the splash screen
*/
class
WebWin
:
public
QWebView
{
Q_OBJECT
QUrl
baseUrl
;
QString
htmlfile
;
QString
htmlFileCont
;
private
:
QHash
<
QString
,
SKHandlerFunction
>
_handlers
;
public
:
WebWin
(
QString
&
htmlfile
);
~
WebWin
();
void
setHtmlFile
(
QString
&
fname
);
void
setHtmlFile
(
QString
&
fname
,
bool
borders
,
bool
transparentbg
);
void
setHtmlCont
(
QString
cont
,
QUrl
baseUrl
,
bool
borders
,
bool
transparentbg
);
void
sendMessage
(
SKMessage
&
msg
);
void
registerHandler
(
QString
type
,
SKHandlerFunction
handler
);
void
toggleBorders
(
bool
borders
);
void
toggleTransparentBackground
(
bool
transparentbg
);
JSBridge
*
jsbridge
;
private
slots
:
void
refreshJsObject
();
public
slots
:
void
msgFromCore
(
SKMessage
&
msg
);
signals
:
void
putMessage
(
SKMessage
&
msg
);
// XXX Future usage
//protected:
// void dragMoveEvent(QDragMoveEvent *ev);
};
#endif
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