Export to JS some window settings

parent 02eafc95
...@@ -50,7 +50,6 @@ MainWin::MainWin(QString &htmlfile) ...@@ -50,7 +50,6 @@ MainWin::MainWin(QString &htmlfile)
{ {
baseUrl = QUrl::fromLocalFile(QDir::current().absoluteFilePath("gui/dummy.html")); baseUrl = QUrl::fromLocalFile(QDir::current().absoluteFilePath("gui/dummy.html"));
QPalette pal = palette(); QPalette pal = palette();
pal.setBrush(QPalette::Base, Qt::transparent); pal.setBrush(QPalette::Base, Qt::transparent);
...@@ -58,7 +57,6 @@ MainWin::MainWin(QString &htmlfile) ...@@ -58,7 +57,6 @@ MainWin::MainWin(QString &htmlfile)
page()->setPalette(pal); page()->setPalette(pal);
setAttribute(Qt::WA_TranslucentBackground, true); setAttribute(Qt::WA_TranslucentBackground, true);
setAttribute(Qt::WA_OpaquePaintEvent, false); setAttribute(Qt::WA_OpaquePaintEvent, false);
setHtmlFile(htmlfile); setHtmlFile(htmlfile);
resize(250,200); resize(250,200);
...@@ -85,6 +83,22 @@ void MainWin::setHtmlFile(QString &fname) ...@@ -85,6 +83,22 @@ void MainWin::setHtmlFile(QString &fname)
} }
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::SKMessage &msg) void MainWin::msgFromCore(SKMessage::SKMessage &msg)
{ {
std::cout << "MainWindow msg reveived: " << msg.handle.toStdString() << std::endl; std::cout << "MainWindow msg reveived: " << msg.handle.toStdString() << std::endl;
...@@ -96,6 +110,48 @@ void MainWin::msgFromCore(SKMessage::SKMessage &msg) ...@@ -96,6 +110,48 @@ void MainWin::msgFromCore(SKMessage::SKMessage &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::SKMessage &msg) void MainWin::sendMessage(SKMessage::SKMessage &msg)
{ {
...@@ -147,3 +203,19 @@ void JSBridge::pushLogin(QString username, QString password) ...@@ -147,3 +203,19 @@ void JSBridge::pushLogin(QString username, QString password)
loginmsg.parameters.insert("password", password); loginmsg.parameters.insert("password", password);
mwin->sendMessage(loginmsg); mwin->sendMessage(loginmsg);
} }
void JSBridge::resizeWin(int width, int height)
{
mwin->resize(width, height);
}
void JSBridge::toggleBorders(bool borders)
{
mwin->toggleBorders(borders);
}
void JSBridge::toggleTransparentBackground(bool transparentbg)
{
mwin->toggleTransparentBackground(transparentbg);
}
...@@ -67,6 +67,9 @@ class JSBridge : public QObject ...@@ -67,6 +67,9 @@ class JSBridge : public QObject
void notify(QString content); void notify(QString content);
public slots: public slots:
void pushLogin(QString username, QString password); void pushLogin(QString username, QString password);
void resizeWin(int width, int height);
void toggleBorders(bool borders);
void toggleTransparentBackground(bool transparentbg);
}; };
...@@ -89,6 +92,8 @@ class MainWin : public QWebView ...@@ -89,6 +92,8 @@ class MainWin : public QWebView
private: private:
QHash<QString, SKHandlerFunction> _handlers; QHash<QString, SKHandlerFunction> _handlers;
void setHtmlFile(QString &fname); void setHtmlFile(QString &fname);
void setHtmlFile(QString &fname, bool borders, bool transparentbg);
void setHtmlCont(QString cont, QUrl baseUrl, bool borders, bool transparentbg);
public: public:
MainWin(QString &htmlfile); MainWin(QString &htmlfile);
...@@ -98,6 +103,8 @@ class MainWin : public QWebView ...@@ -98,6 +103,8 @@ class MainWin : public QWebView
void handle_corestarted(SKMessage::SKMessage &msg); void handle_corestarted(SKMessage::SKMessage &msg);
void handle_connected(SKMessage::SKMessage &msg); void handle_connected(SKMessage::SKMessage &msg);
void handle_asklogin(SKMessage::SKMessage &msg); void handle_asklogin(SKMessage::SKMessage &msg);
void toggleBorders(bool borders);
void toggleTransparentBackground(bool transparentbg);
public slots: public slots:
void msgFromCore(SKMessage::SKMessage &msg); void msgFromCore(SKMessage::SKMessage &msg);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment