Falkon Develop
Cross-platform Qt-based web browser
qmlwindow.cpp
Go to the documentation of this file.
1/* ============================================================
2* Falkon - Qt web browser
3* Copyright (C) 2018 Anmol Gautam <tarptaeya@gmail.com>
4*
5* This program is free software: you can redistribute it and/or modify
6* it under the terms of the GNU General Public License as published by
7* the Free Software Foundation, either version 3 of the License, or
8* (at your option) any later version.
9*
10* This program is distributed in the hope that it will be useful,
11* but WITHOUT ANY WARRANTY; without even the implied warranty of
12* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13* GNU General Public License for more details.
14*
15* You should have received a copy of the GNU General Public License
16* along with this program. If not, see <http://www.gnu.org/licenses/>.
17* ============================================================ */
18#include "qmlwindow.h"
19#include "mainapplication.h"
20#include "../tabs/qmltab.h"
21#include "tabwidget.h"
22#include "qml/qmlstaticdata.h"
23#include <QQmlEngine>
24
25QmlWindow::QmlWindow(BrowserWindow *window, QObject *parent)
26 : QObject(parent)
27 , m_window(window)
28{
29 QQmlEngine::setObjectOwnership(this, QQmlEngine::CppOwnership);
30}
31
32int QmlWindow::id() const
33{
34 if (!QmlStaticData::instance().windowIdHash().contains(m_window)) {
35 return -1;
36 }
37
38 return QmlStaticData::instance().windowIdHash().value(m_window, -1);
39}
40
41bool QmlWindow::incognito() const
42{
43 return mApp->isPrivate();
44}
45
46QString QmlWindow::title() const
47{
48 if (!m_window) {
49 return {};
50 }
51
52 return m_window->windowTitle();
53}
54
56{
57 if (!m_window) {
58 return QmlEnums::Invalid;
59 }
60
61 if (m_window->isFullScreen()) {
63 } else if (m_window->isMaximized()) {
65 } else if (m_window->isMinimized()) {
67 } else {
68 return QmlEnums::Normal;
69 }
70}
71
73{
74 if (!m_window) {
76 }
77
78 switch (m_window->windowType()) {
85 default:
87 }
88}
89
90QList<QObject*> QmlWindow::tabs() const
91{
92 if (!m_window) {
93 return {};
94 }
95
96 QList<QObject*> list;
97 const QList<WebTab*> allTabs = m_window->tabWidget()->allTabs(true);
98 list.reserve(allTabs.size());
99 for (WebTab *tab : allTabs) {
100 list.append(new QmlTab(tab));
101 }
102
103 return list;
104}
105
106bool QmlWindow::focussed() const
107{
108 if (!m_window) {
109 return false;
110 }
111
112 return m_window->isActiveWindow();
113}
114
115int QmlWindow::height() const
116{
117 if (!m_window) {
118 return -1;
119 }
120
121 return m_window->height();
122}
123
124int QmlWindow::width() const
125{
126 if (!m_window) {
127 return -1;
128 }
129
130 return m_window->width();
131}
Qz::BrowserWindowType windowType() const
TabWidget * tabWidget() const
WindowType
The WindowType enum.
Definition: qmlenums.h:45
@ FirstAppWindow
Represents first app window.
Definition: qmlenums.h:46
@ MacFirstWindow
Represents first mac window.
Definition: qmlenums.h:47
@ OtherRestoredWindow
Represents other restored window.
Definition: qmlenums.h:49
@ NewWindow
Represents new window.
Definition: qmlenums.h:48
WindowState
The WindowState enum.
Definition: qmlenums.h:33
@ Maximized
Represents maximized window.
Definition: qmlenums.h:35
@ Normal
Represents normal window.
Definition: qmlenums.h:37
@ FullScreen
Represents full screen window.
Definition: qmlenums.h:34
@ Invalid
Represents a invalid window.
Definition: qmlenums.h:38
@ Minimized
Represents minimized window.
Definition: qmlenums.h:36
QHash< BrowserWindow *, int > windowIdHash()
static QmlStaticData & instance()
The class exposing a browser tab to QML.
Definition: qmltab.h:32
int width
width of window
Definition: qmlwindow.h:73
int id
id of window
Definition: qmlwindow.h:33
int height
height of window
Definition: qmlwindow.h:68
QString title
title of window
Definition: qmlwindow.h:43
QmlWindow(BrowserWindow *window=nullptr, QObject *parent=nullptr)
Definition: qmlwindow.cpp:25
QmlEnums::WindowType type
window type of window
Definition: qmlwindow.h:53
QmlEnums::WindowState state
window state of window
Definition: qmlwindow.h:48
bool focussed
checks if the window is focused
Definition: qmlwindow.h:63
QList< QObject * > tabs
list of all tabs of window
Definition: qmlwindow.h:58
bool incognito
checks if the window is private
Definition: qmlwindow.h:38
QList< WebTab * > allTabs(bool withPinned=true)
Definition: tabwidget.cpp:833
Definition: webtab.h:40
#define mApp
@ BW_NewWindow
Definition: qzcommon.h:67
@ BW_FirstAppWindow
Definition: qzcommon.h:65
@ BW_MacFirstWindow
Definition: qzcommon.h:68