Mark some Calc slots as inactive in readonly mode
[LibreOffice.git] / vcl / qt5 / QtExpander.cxx
blob1b690ecdc888b3fcf80bc7b28164cece18dd6397
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 */
10 #include <QtExpander.hxx>
11 #include <QtExpander.moc>
13 QtExpander::QtExpander(QWidget* pParent)
14 : QWidget(pParent)
15 , m_pContentWidget(nullptr)
16 , m_bExpanded(false)
18 m_pLayout = new QGridLayout;
19 setLayout(m_pLayout);
21 m_pButton = new QPushButton;
22 m_pButton->setFlat(true);
23 m_pButton->setSizePolicy(QSizePolicy::Policy::Maximum, QSizePolicy::Policy::Maximum);
24 m_pLayout->addWidget(m_pButton, 0, 0);
25 m_pLayout->addItem(new QSpacerItem(0, 0, QSizePolicy::Policy::MinimumExpanding,
26 QSizePolicy::Policy::MinimumExpanding),
27 0, 1);
29 update();
31 connect(m_pButton, &QAbstractButton::clicked, this, &QtExpander::handleButtonClick);
34 void QtExpander::setContentWidget(QWidget* pWidget)
36 assert(pWidget);
37 m_pContentWidget = pWidget;
38 m_pLayout->addWidget(m_pContentWidget, 1, 0, 1, 2);
39 update();
42 void QtExpander::setText(const QString& rText) { m_pButton->setText(rText); }
44 QString QtExpander::text() const { return m_pButton->text(); }
46 void QtExpander::setExpanded(bool bExpand)
48 if (m_bExpanded == bExpand)
49 return;
51 m_bExpanded = bExpand;
52 update();
54 emit expandedChanged(isExpanded());
57 bool QtExpander::isExpanded() const { return m_bExpanded; }
59 void QtExpander::update()
61 const QString sIcon = m_bExpanded ? "go-down" : "go-next";
62 m_pButton->setIcon(QIcon::fromTheme(sIcon));
64 if (m_pContentWidget)
65 m_pContentWidget->setVisible(m_bExpanded);
68 void QtExpander::handleButtonClick()
70 // toggle
71 setExpanded(!isExpanded());
74 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */