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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
|
/* -*- 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
#include <vector>
#include <QtCore/QObject>
#include <QtWidgets/QDialog>
#include <QtWidgets/QDialogButtonBox>
#include <QtWidgets/QDoubleSpinBox>
#include <QtWidgets/QGridLayout>
#include <QtWidgets/QMenu>
#include <QtWidgets/QMessageBox>
#include <QtWidgets/QPushButton>
#include <QtWidgets/QSlider>
#include <QtWidgets/QToolButton>
#include <rtl/ustring.hxx>
#include <unotools/resmgr.hxx>
#include <vcl/builder.hxx>
class QtBuilder : public WidgetBuilder<QObject, QObject*, QMenu, QMenu*>
{
private:
QWidget* get_by_name(std::u16string_view sID);
struct WinAndId
{
OUString m_sID;
QWidget* m_pWidget;
WinAndId(OUString sId, QWidget* pWidget)
: m_sID(std::move(sId))
, m_pWidget(pWidget)
{
}
};
std::vector<WinAndId> m_aChildren;
// vector of pairs, each containing:
// * a widget to remove from the widget hierarchy and delete (first item)
// * the widget to put in its place instead (second item)
std::vector<std::pair<QWidget*, QWidget*>> m_aWidgetReplacements;
public:
QtBuilder(QObject* pParent, std::u16string_view sUIRoot, const OUString& rUIFile);
virtual ~QtBuilder();
template <typename T = QObject> T* get(std::u16string_view sID);
QObject* makeObject(QObject* pParent, std::u16string_view sName, std::string_view sType,
const OUString& sID, stringmap& rMap);
virtual void applyAtkProperties(QObject* pObject, const stringmap& rProperties,
bool bToolbarItem) override;
virtual void applyPackingProperties(QObject* pCurrentChild, QObject* pParent,
const stringmap& rPackingProperties) override;
virtual void applyTabChildProperties(QObject* pParent, const std::vector<OUString>& rIDs,
std::vector<vcl::EnumContext::Context>& rContext,
stringmap& rProperties,
stringmap& rAtkProperties) override;
virtual void insertComboBoxOrListBoxItems(QObject* pObject, stringmap& rMap,
const std::vector<ComboBoxTextItem>& rItems) override;
virtual QObject* insertObject(QObject* pParent, const OUString& rClass, std::string_view sType,
const OUString& rID, stringmap& rProps,
stringmap& rPangoAttributes, stringmap& rAtkProps) override;
void tweakInsertedChild(QObject* pParent, QObject* pCurrentChild, std::string_view sType,
std::string_view sInternalChild) override;
virtual void setMnemonicWidget(const OUString& rLabelId,
const OUString& rMnemonicWidgetId) override;
virtual void setRadioButtonGroup(const OUString& rRadioButtonId,
const OUString& rRadioGroupId) override;
virtual void setPriority(QObject* pObject, int nPriority) override;
virtual void setContext(QObject* pObject,
std::vector<vcl::EnumContext::Context>&& aContext) override;
virtual bool isHorizontalTabControl(QObject* pObject) override;
virtual QMenu* createMenu(const OUString& rId) override;
virtual void insertMenuObject(QMenu* pParent, QMenu* pSubMenu, const OUString& rClass,
const OUString& rID, stringmap& rProps, stringmap& rAtkProps,
accelmap& rAccels) override;
virtual void set_response(std::u16string_view sID, short nResponse) override;
private:
static void deleteObject(QObject* pObject);
// remove pOldWidget from the widget hierarchy and set (child widget) pNewWidget in its place
static void replaceWidget(QWidget* pOldWidget, QWidget* pNewWidget);
static void setProperties(QObject* obj, stringmap& rProps);
void setButtonProperties(QAbstractButton& rButton, stringmap& rProps);
static void setEntryProperties(QLineEdit& rLineEdit, stringmap& rProps);
static void setLabelProperties(QLabel& rLabel, stringmap& rProps);
void setMenuButtonProperties(QToolButton& rButton, stringmap& rProps);
void setScaleProperties(QSlider& rSlider, stringmap& rProps);
void setSpinButtonProperties(QDoubleSpinBox& rSpinBox, stringmap& rProps);
static QWidget* windowForObject(QObject* pObject);
static QDialogButtonBox* findButtonBox(QDialog* pDialog);
static void applyGridPackingProperties(QWidget* pCurrentChild, QGridLayout& rGrid,
const stringmap& rPackingProperties);
};
template <typename T> inline T* QtBuilder::get(std::u16string_view sID)
{
QObject* w = get_by_name(sID);
return static_cast<T*>(w);
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
|