Files
libreoffice/vcl/inc/qt5/QtInstanceNotebook.hxx

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

54 lines
1.9 KiB
C++
Raw Normal View History

/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#pragma once
tdf#130857 tdf#142608 qt weld: Implement QtInstanceNotebook logic Implement all of the QtInstanceNotebook methods, see also GtkInstanceNotebook and SalInstanceNotebook for the gtk3 and VCL implementations for comparison. Unlike weld::Notebook, QTabWidget doesn't have the concept of IDs for tabs in addition to indices. Introduce a PROPERTY_TAB_PAGE_ID property that gets set on the widget of the corresponding tabs and holds the tab identifier in order to support that. Implement QtBuilder::applyTabChildProperties to set the tab label and ID property by using the newly introduced QtInstanceNotebook::setTabIdAndLabel, so only QtInstanceNotebook needs to handle that property. The weld::Container* returned by QtInstanceNotebook::get_page is owned by QtInstanceNotebook, so keep create one on demand and keep a mapping between tab pages and the corresponding weld::Container. In QtInstanceNotebook::insert_page, create a new widget and set a QVBoxLayout for now. That could be changed to use a different QLayout class in the future if that turns out to be more useful. In QtBuilder::makeObject, as the tab pages are children of the "GtkNotebook" in the .ui file, they are initially created as child widgets of the QTabWidget. However, they need to be set via QTabWidget::setTab instead, so add special handling for that case towards the end and unset the parent relationship and call that method. Change-Id: I52e11ecf053a48940b88b7e6d1e6f9ba8778d9bb Reviewed-on: https://gerrit.libreoffice.org/c/core/+/176353 Tested-by: Jenkins Reviewed-by: Michael Weghorn <m.weghorn@posteo.de>
2024-11-10 18:54:28 +01:00
#include "QtInstanceContainer.hxx"
#include "QtInstanceWidget.hxx"
#include <QtWidgets/QTabWidget>
tdf#130857 tdf#142608 qt weld: Implement QtInstanceNotebook logic Implement all of the QtInstanceNotebook methods, see also GtkInstanceNotebook and SalInstanceNotebook for the gtk3 and VCL implementations for comparison. Unlike weld::Notebook, QTabWidget doesn't have the concept of IDs for tabs in addition to indices. Introduce a PROPERTY_TAB_PAGE_ID property that gets set on the widget of the corresponding tabs and holds the tab identifier in order to support that. Implement QtBuilder::applyTabChildProperties to set the tab label and ID property by using the newly introduced QtInstanceNotebook::setTabIdAndLabel, so only QtInstanceNotebook needs to handle that property. The weld::Container* returned by QtInstanceNotebook::get_page is owned by QtInstanceNotebook, so keep create one on demand and keep a mapping between tab pages and the corresponding weld::Container. In QtInstanceNotebook::insert_page, create a new widget and set a QVBoxLayout for now. That could be changed to use a different QLayout class in the future if that turns out to be more useful. In QtBuilder::makeObject, as the tab pages are children of the "GtkNotebook" in the .ui file, they are initially created as child widgets of the QTabWidget. However, they need to be set via QTabWidget::setTab instead, so add special handling for that case towards the end and unset the parent relationship and call that method. Change-Id: I52e11ecf053a48940b88b7e6d1e6f9ba8778d9bb Reviewed-on: https://gerrit.libreoffice.org/c/core/+/176353 Tested-by: Jenkins Reviewed-by: Michael Weghorn <m.weghorn@posteo.de>
2024-11-10 18:54:28 +01:00
#include <map>
class QtInstanceNotebook : public QtInstanceWidget, public virtual weld::Notebook
{
Q_OBJECT
QTabWidget* m_pTabWidget;
OUString m_sCurrentTabId;
tdf#130857 tdf#142608 qt weld: Implement QtInstanceNotebook logic Implement all of the QtInstanceNotebook methods, see also GtkInstanceNotebook and SalInstanceNotebook for the gtk3 and VCL implementations for comparison. Unlike weld::Notebook, QTabWidget doesn't have the concept of IDs for tabs in addition to indices. Introduce a PROPERTY_TAB_PAGE_ID property that gets set on the widget of the corresponding tabs and holds the tab identifier in order to support that. Implement QtBuilder::applyTabChildProperties to set the tab label and ID property by using the newly introduced QtInstanceNotebook::setTabIdAndLabel, so only QtInstanceNotebook needs to handle that property. The weld::Container* returned by QtInstanceNotebook::get_page is owned by QtInstanceNotebook, so keep create one on demand and keep a mapping between tab pages and the corresponding weld::Container. In QtInstanceNotebook::insert_page, create a new widget and set a QVBoxLayout for now. That could be changed to use a different QLayout class in the future if that turns out to be more useful. In QtBuilder::makeObject, as the tab pages are children of the "GtkNotebook" in the .ui file, they are initially created as child widgets of the QTabWidget. However, they need to be set via QTabWidget::setTab instead, so add special handling for that case towards the end and unset the parent relationship and call that method. Change-Id: I52e11ecf053a48940b88b7e6d1e6f9ba8778d9bb Reviewed-on: https://gerrit.libreoffice.org/c/core/+/176353 Tested-by: Jenkins Reviewed-by: Michael Weghorn <m.weghorn@posteo.de>
2024-11-10 18:54:28 +01:00
mutable std::map<QWidget*, std::unique_ptr<QtInstanceContainer>> m_aPageContainerInstances;
public:
QtInstanceNotebook(QTabWidget* pTabWidget);
virtual int get_current_page() const override;
virtual int get_page_index(const OUString& rIdent) const override;
virtual OUString get_page_ident(int nPage) const override;
virtual OUString get_current_page_ident() const override;
virtual void set_current_page(int nPage) override;
virtual void set_current_page(const OUString& rIdent) override;
virtual void remove_page(const OUString& rIdent) override;
virtual void insert_page(const OUString& rIdent, const OUString& rLabel, int nPos) override;
virtual void set_tab_label_text(const OUString& rIdent, const OUString& rLabel) override;
virtual OUString get_tab_label_text(const OUString& rIdent) const override;
virtual void set_show_tabs(bool bShow) override;
virtual int get_n_pages() const override;
virtual weld::Container* get_page(const OUString& rIdent) const override;
tdf#130857 tdf#142608 qt weld: Implement QtInstanceNotebook logic Implement all of the QtInstanceNotebook methods, see also GtkInstanceNotebook and SalInstanceNotebook for the gtk3 and VCL implementations for comparison. Unlike weld::Notebook, QTabWidget doesn't have the concept of IDs for tabs in addition to indices. Introduce a PROPERTY_TAB_PAGE_ID property that gets set on the widget of the corresponding tabs and holds the tab identifier in order to support that. Implement QtBuilder::applyTabChildProperties to set the tab label and ID property by using the newly introduced QtInstanceNotebook::setTabIdAndLabel, so only QtInstanceNotebook needs to handle that property. The weld::Container* returned by QtInstanceNotebook::get_page is owned by QtInstanceNotebook, so keep create one on demand and keep a mapping between tab pages and the corresponding weld::Container. In QtInstanceNotebook::insert_page, create a new widget and set a QVBoxLayout for now. That could be changed to use a different QLayout class in the future if that turns out to be more useful. In QtBuilder::makeObject, as the tab pages are children of the "GtkNotebook" in the .ui file, they are initially created as child widgets of the QTabWidget. However, they need to be set via QTabWidget::setTab instead, so add special handling for that case towards the end and unset the parent relationship and call that method. Change-Id: I52e11ecf053a48940b88b7e6d1e6f9ba8778d9bb Reviewed-on: https://gerrit.libreoffice.org/c/core/+/176353 Tested-by: Jenkins Reviewed-by: Michael Weghorn <m.weghorn@posteo.de>
2024-11-10 18:54:28 +01:00
static void setTabIdAndLabel(QTabWidget& rTabWidget, int nPage, const OUString& rIdent,
const OUString& rLabel);
private Q_SLOTS:
void currentTabChanged();
};
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */