1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
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/.
10 #include <QtExpander.hxx>
11 #include <QtExpander.moc>
13 QtExpander::QtExpander(QWidget
* pParent
)
15 , m_pContentWidget(nullptr)
18 m_pLayout
= new QGridLayout
;
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
),
31 connect(m_pButton
, &QAbstractButton::clicked
, this, &QtExpander::handleButtonClick
);
34 void QtExpander::setContentWidget(QWidget
* pWidget
)
37 m_pContentWidget
= pWidget
;
38 m_pLayout
->addWidget(m_pContentWidget
, 1, 0, 1, 2);
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
)
51 m_bExpanded
= bExpand
;
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
));
65 m_pContentWidget
->setVisible(m_bExpanded
);
68 void QtExpander::handleButtonClick()
71 setExpanded(!isExpanded());
74 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */