summaryrefslogtreecommitdiffstats
path: root/src/Dialog.cpp
blob: afe34bd7fe7b6f3e1c8e87edadeeb380402b5005 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/*
 * Copyright (c) 2010,2011 - RZ Uni Freiburg
 * Copyright (c) 2010,2011 - OpenSLX Project
 *
 * This program/file is free software distributed under the GPL version 2.
 * See http://gpl.openslx.org/
 *
 * If you have any feedback please consult http://feedback.openslx.org/ and
 * send your feedback to feedback@openslx.org
 *
 * General information about OpenSLX - libChooser can be found under
 * http://openslx.org
 *
 */

#include <QtGui>
#include <QSizeGrip>
#include <QSettings>
#include <QRect>
#include <QWebView>

#include <VSession.h>

#include "JavaScriptInterface.h"
#include "Globals.h"

#include "Dialog.h"

void
Dialog::setTheme()
{

}

void
Dialog::addItems(const QList<Session *> entries)
{
  jsi->addItems(entries);
}

void
Dialog::center()
{
  QRect desktopRect = QApplication::desktop()->availableGeometry(this);
  QPoint center = desktopRect.center();
  move(center.x() - width() * 0.5, center.y() - height() * 0.5);
}

void
Dialog::createLayout()
{
  layout = new QVBoxLayout(this);
  layout->setSpacing(0);
  layout->setContentsMargins(0, 0, 0, 0);
  layout->setMargin(0);
}

Dialog::Dialog(QWidget *parent) :
    QDialog(parent)
{
  setMinimumSize(940, 740);
  //setStyleSheet("border-color:lightgray");
  setWindowFlags(Qt::FramelessWindowHint);

  createLayout();
  QWebView *webView = new QWebView(parent);

#ifdef DEBUG
  QWebSettings::globalSettings()->setAttribute(QWebSettings::DeveloperExtrasEnabled, true);
#else
  webView->setContextMenuPolicy(Qt::NoContextMenu);
#endif

#if QT_VERSION >= 0x040700
  QWebSettings::globalSettings()->setAttribute(
      QWebSettings::LocalContentCanAccessFileUrls, true);
#endif
  QWebSettings::globalSettings()->setAttribute(
      QWebSettings::LocalContentCanAccessRemoteUrls, true);

  //QWebSettings::globalSettings()->setAttribute(, true);
  webView->setUrl(QUrl("qrc:/html/index.html"));
  webView->show();
  layout->addWidget(webView);

  setLayout(layout);

  jsi = new JavaScriptInterface(webView);
  QObject::connect(webView->page()->mainFrame(),
      SIGNAL(javaScriptWindowObjectCleared()), jsi, SLOT(attachToDOM()));
  QObject::connect(jsi, SIGNAL(hideMainWindow()), this, SLOT(hide()));
}