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
|
/* -*- 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/.
*/
#include <QtInstanceButton.hxx>
#include <vcl/qt/QtUtils.hxx>
// Name of QObject property to indicate whether a click handler
// was set on the QPushButton: If that property is set and has a value
// of true, then a custom click handler is set, otherwise not.
const char* const PROPERTY_CLICK_HANDLER_SET = "click-handler-set";
QtInstanceButton::QtInstanceButton(QPushButton* pButton)
: QtInstanceWidget(pButton)
, m_pButton(pButton)
{
assert(m_pButton);
connect(m_pButton, &QPushButton::clicked, this, &QtInstanceButton::buttonClicked);
}
void QtInstanceButton::set_label(const OUString& rText)
{
SolarMutexGuard g;
QtInstance& rQtInstance = GetQtInstance();
if (!rQtInstance.IsMainThread())
{
rQtInstance.RunInMainThread([&] { set_label(rText); });
return;
}
assert(m_pButton);
m_pButton->setText(toQString(rText));
}
void QtInstanceButton::set_image(VirtualDevice* /*pDevice*/)
{
assert(false && "Not implemented yet");
}
void QtInstanceButton::set_image(const css::uno::Reference<css::graphic::XGraphic>& /*rImage*/)
{
assert(false && "Not implemented yet");
}
void QtInstanceButton::set_from_icon_name(const OUString& rIconName)
{
SolarMutexGuard g;
GetQtInstance().RunInMainThread([&] {
QPixmap aIcon = loadQPixmapIcon(rIconName);
m_pButton->setIcon(aIcon);
});
}
OUString QtInstanceButton::get_label() const
{
SolarMutexGuard g;
QtInstance& rQtInstance = GetQtInstance();
if (!rQtInstance.IsMainThread())
{
OUString sLabel;
rQtInstance.RunInMainThread([&] { sLabel = get_label(); });
return sLabel;
}
assert(m_pButton);
return toOUString(m_pButton->text());
}
void QtInstanceButton::set_font(const vcl::Font& /*rFont*/)
{
assert(false && "Not implemented yet");
}
void QtInstanceButton::set_custom_button(VirtualDevice* /*pDevice*/)
{
assert(false && "Not implemented yet");
}
void QtInstanceButton::connect_clicked(const Link<Button&, void>& rLink)
{
weld::Button::connect_clicked(rLink);
m_pButton->setProperty(PROPERTY_CLICK_HANDLER_SET, QVariant::fromValue(rLink.IsSet()));
}
bool QtInstanceButton::hasCustomClickHandler(QAbstractButton& rButton)
{
QVariant aProp = rButton.property(PROPERTY_CLICK_HANDLER_SET);
if (!aProp.isValid())
return false;
assert(aProp.canConvert<bool>());
return aProp.toBool();
}
void QtInstanceButton::buttonClicked()
{
SolarMutexGuard g;
signal_clicked();
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
|