File indexing completed on 2024-12-22 04:41:15
0001 /* ============================================================ 0002 * Falkon - Qt web browser 0003 * Copyright (C) 2018 Anmol Gautam <tarptaeya@gmail.com> 0004 * 0005 * This program is free software: you can redistribute it and/or modify 0006 * it under the terms of the GNU General Public License as published by 0007 * the Free Software Foundation, either version 3 of the License, or 0008 * (at your option) any later version. 0009 * 0010 * This program is distributed in the hope that it will be useful, 0011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0013 * GNU General Public License for more details. 0014 * 0015 * You should have received a copy of the GNU General Public License 0016 * along with this program. If not, see <http://www.gnu.org/licenses/>. 0017 * ============================================================ */ 0018 #include "qmlwindow.h" 0019 #include "mainapplication.h" 0020 #include "../tabs/qmltab.h" 0021 #include "tabwidget.h" 0022 #include "qml/qmlstaticdata.h" 0023 #include <QQmlEngine> 0024 0025 QmlWindow::QmlWindow(BrowserWindow *window, QObject *parent) 0026 : QObject(parent) 0027 , m_window(window) 0028 { 0029 QQmlEngine::setObjectOwnership(this, QQmlEngine::CppOwnership); 0030 } 0031 0032 int QmlWindow::id() const 0033 { 0034 if (!QmlStaticData::instance().windowIdHash().contains(m_window)) { 0035 return -1; 0036 } 0037 0038 return QmlStaticData::instance().windowIdHash().value(m_window, -1); 0039 } 0040 0041 bool QmlWindow::incognito() const 0042 { 0043 return mApp->isPrivate(); 0044 } 0045 0046 QString QmlWindow::title() const 0047 { 0048 if (!m_window) { 0049 return {}; 0050 } 0051 0052 return m_window->windowTitle(); 0053 } 0054 0055 QmlEnums::WindowState QmlWindow::state() const 0056 { 0057 if (!m_window) { 0058 return QmlEnums::Invalid; 0059 } 0060 0061 if (m_window->isFullScreen()) { 0062 return QmlEnums::FullScreen; 0063 } else if (m_window->isMaximized()) { 0064 return QmlEnums::Maximized; 0065 } else if (m_window->isMinimized()) { 0066 return QmlEnums::Minimized; 0067 } else { 0068 return QmlEnums::Normal; 0069 } 0070 } 0071 0072 QmlEnums::WindowType QmlWindow::type() const 0073 { 0074 if (!m_window) { 0075 return QmlEnums::OtherRestoredWindow; 0076 } 0077 0078 switch (m_window->windowType()) { 0079 case Qz::BW_FirstAppWindow: 0080 return QmlEnums::FirstAppWindow; 0081 case Qz::BW_MacFirstWindow: 0082 return QmlEnums::MacFirstWindow; 0083 case Qz::BW_NewWindow: 0084 return QmlEnums::NewWindow; 0085 default: 0086 return QmlEnums::OtherRestoredWindow; 0087 } 0088 } 0089 0090 QList<QObject*> QmlWindow::tabs() const 0091 { 0092 if (!m_window) { 0093 return {}; 0094 } 0095 0096 QList<QObject*> list; 0097 const QList<WebTab*> allTabs = m_window->tabWidget()->allTabs(true); 0098 list.reserve(allTabs.size()); 0099 for (WebTab *tab : allTabs) { 0100 list.append(new QmlTab(tab)); 0101 } 0102 0103 return list; 0104 } 0105 0106 bool QmlWindow::focussed() const 0107 { 0108 if (!m_window) { 0109 return false; 0110 } 0111 0112 return m_window->isActiveWindow(); 0113 } 0114 0115 int QmlWindow::height() const 0116 { 0117 if (!m_window) { 0118 return -1; 0119 } 0120 0121 return m_window->height(); 0122 } 0123 0124 int QmlWindow::width() const 0125 { 0126 if (!m_window) { 0127 return -1; 0128 } 0129 0130 return m_window->width(); 0131 }