16
|
1 |
#include "WindowsView.h"
|
|
2 |
#include "BrowserWindow.h"
|
|
3 |
#include "GWebContentView.h"
|
|
4 |
#include "ViewStack.h"
|
|
5 |
|
|
6 |
//For page created signal
|
|
7 |
#include "wrtbrowsercontainer.h"
|
|
8 |
#include "webpagecontroller.h"
|
|
9 |
|
|
10 |
//For shared chrome object
|
|
11 |
#include "ChromeWidget.h"
|
|
12 |
#include "ChromeView.h"
|
|
13 |
|
|
14 |
#include <QDebug>
|
|
15 |
|
|
16 |
namespace GVA {
|
|
17 |
|
|
18 |
WindowsView::WindowsView(ChromeWidget * chrome, QObject * parent, const QString & objectName)
|
|
19 |
: ControllableViewBase(parent),
|
|
20 |
m_current(0),
|
|
21 |
m_chrome(chrome),
|
|
22 |
m_menu(0)
|
|
23 |
{
|
|
24 |
setObjectName(objectName);
|
|
25 |
}
|
|
26 |
|
|
27 |
WindowsView::~WindowsView()
|
|
28 |
{
|
|
29 |
foreach (QMainWindow * window, m_windows){
|
|
30 |
delete window;
|
|
31 |
}
|
|
32 |
}
|
|
33 |
|
|
34 |
void WindowsView::activate(BrowserWindow * window)
|
|
35 |
{
|
|
36 |
|
|
37 |
ViewStack * viewStack = ViewStack::getSingleton();
|
|
38 |
GWebContentView* webView = contentView();
|
|
39 |
if(webView) {
|
|
40 |
if(contentView()->currentPageIsSuperPage()){
|
|
41 |
webView->showNormalPage();
|
|
42 |
webView->setGesturesEnabled(true);
|
|
43 |
window->setView("WebView");
|
|
44 |
viewStack->switchView(window->view(), viewStack->getViewController()->currentViewName());
|
|
45 |
}
|
|
46 |
else {
|
|
47 |
viewStack->getViewController()->currentView()->deactivate();
|
|
48 |
}
|
|
49 |
window->setTitle(viewStack->getViewController()->currentView()->title());
|
|
50 |
}
|
|
51 |
// Let the chrome take focus, or whatever it wants to do.
|
|
52 |
m_chrome->activate();
|
|
53 |
}
|
|
54 |
|
|
55 |
void WindowsView::deactivate(BrowserWindow * window)
|
|
56 |
{
|
|
57 |
ViewStack * viewStack = ViewStack::getSingleton();
|
|
58 |
/*
|
|
59 |
if(m_current != window){
|
|
60 |
m_current = window;
|
|
61 |
viewStack->switchView(window->view(), viewStack->getViewController()->currentViewName());
|
|
62 |
}
|
|
63 |
else */
|
|
64 |
//#ifndef BEDROCK_TILED_BACKING_STORE
|
|
65 |
if(viewStack->getViewController()->currentView())
|
|
66 |
viewStack->getViewController()->currentView()->activate();
|
|
67 |
//#endif
|
|
68 |
}
|
|
69 |
|
|
70 |
|
|
71 |
void WindowsView::setMenu(QMenu * menu)
|
|
72 |
{
|
|
73 |
m_menu = menu;
|
|
74 |
if(m_menu){
|
|
75 |
m_menu->addAction("New Window", this, SLOT(onWindowAction()));
|
|
76 |
}
|
|
77 |
}
|
|
78 |
|
|
79 |
void WindowsView::setMenuEnabled(bool enabled)
|
|
80 |
{
|
|
81 |
m_menu->setEnabled(enabled);
|
|
82 |
m_current->setMenuEnabled(enabled);
|
|
83 |
}
|
|
84 |
|
|
85 |
bool WindowsView::isMenuEnabled() const {
|
|
86 |
return m_menu->isEnabled();
|
|
87 |
}
|
|
88 |
|
|
89 |
void WindowsView::handlePageEvents(bool handleEvents){
|
|
90 |
|
|
91 |
if(handleEvents){
|
|
92 |
connect(WebPageController::getSingleton(), SIGNAL(pageCreated(WRT::WrtBrowserContainer *)),
|
|
93 |
this, SLOT(onPageCreated(WRT::WrtBrowserContainer *)));
|
|
94 |
}else{
|
|
95 |
disconnect(WebPageController::getSingleton(), SIGNAL(pageCreated(WRT::WrtBrowserContainer *)),
|
|
96 |
this, SLOT(onPageCreated(WRT::WrtBrowserContainer *)));
|
|
97 |
}
|
|
98 |
}
|
|
99 |
|
|
100 |
BrowserWindow * WindowsView::addWindow(WRT::WrtBrowserContainer * page)
|
|
101 |
{
|
|
102 |
BrowserWindow * window = new BrowserWindow(m_chrome, this);
|
|
103 |
window->setPage(page);
|
|
104 |
window->menuBar()->addMenu(m_menu);
|
|
105 |
m_windows[page] = window;
|
|
106 |
m_current = window;
|
|
107 |
m_current->show();
|
|
108 |
deactivate(window);
|
|
109 |
return window;
|
|
110 |
}
|
|
111 |
|
|
112 |
GWebContentView * WindowsView::contentView()
|
|
113 |
{
|
|
114 |
return static_cast<GWebContentView*>(ViewStack::getSingleton()->getViewController()->view("WebView"));
|
|
115 |
}
|
|
116 |
|
|
117 |
void WindowsView::onWindowAction()
|
|
118 |
{
|
|
119 |
//Tell the page controller to create a new QWebPage.
|
|
120 |
//The controller emits pageCreated when this happens
|
|
121 |
//The onPageCreated slot actually creates the window
|
|
122 |
WebPageController::getSingleton()->openPage();
|
|
123 |
}
|
|
124 |
|
|
125 |
void WindowsView::onPageCreated(WRT::WrtBrowserContainer * page)
|
|
126 |
{
|
|
127 |
addWindow(page);
|
|
128 |
//WebPageController::getSingleton()->loadFromHistory();
|
|
129 |
}
|
|
130 |
|
|
131 |
void WindowsView::onPageDeleted(WRT::WrtBrowserContainer * page)
|
|
132 |
{
|
|
133 |
assert(m_windows.contains(page));
|
|
134 |
delete m_windows.take(page);
|
|
135 |
}
|
|
136 |
|
|
137 |
};
|