Skip to content

Commit

Permalink
Merge pull request MichaelVoelkel#4 from michail-peterlis/master
Browse files Browse the repository at this point in the history
moved slot from lambda to a dinstinct public slot method to access it from outside
  • Loading branch information
MichaelVoelkel authored Oct 15, 2019
2 parents fbca134 + 1be698b commit 2e9f180
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
17 changes: 10 additions & 7 deletions Section.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
You should have received a copy of the GNU General Public License
along with Elypson/qt-collapsible-section. If not, see <http://www.gnu.org/licenses/>.
*/
*/

#include <QPropertyAnimation>

Expand Down Expand Up @@ -62,14 +62,17 @@ Section::Section(const QString & title, const int animationDuration, QWidget* pa
mainLayout->addWidget(contentArea, row, 0, 1, 3);
setLayout(mainLayout);

QObject::connect(toggleButton, &QToolButton::toggled, [this](const bool checked)
{
toggleButton->setArrowType(checked ? Qt::ArrowType::DownArrow : Qt::ArrowType::RightArrow);
toggleAnimation->setDirection(checked ? QAbstractAnimation::Forward : QAbstractAnimation::Backward);
toggleAnimation->start();
});
connect(toggleButton, &QToolButton::toggled, this, &Section::toggle);
}


void Section::toggle(bool collapsed) {
toggleButton->setArrowType(collapsed ? Qt::ArrowType::DownArrow : Qt::ArrowType::RightArrow);
toggleAnimation->setDirection(collapsed ? QAbstractAnimation::Forward : QAbstractAnimation::Backward);
toggleAnimation->start();
}


void Section::setContentLayout(QLayout & contentLayout)
{
delete contentArea->layout();
Expand Down
8 changes: 7 additions & 1 deletion Section.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
You should have received a copy of the GNU General Public License
along with Elypson/qt-collapsible-section. If not, see <http://www.gnu.org/licenses/>.
*/
*/

#ifndef SECTION_H
#define SECTION_H
Expand All @@ -39,6 +39,12 @@ class Section : public QWidget {
QScrollArea* contentArea;
int animationDuration;


public slots:

void toggle(bool collapsed);


public:
explicit Section(const QString & title = "", const int animationDuration = 100, QWidget* parent = 0);

Expand Down

0 comments on commit 2e9f180

Please sign in to comment.