Page MenuHome GnuPG

No OneTemporary

diff --git a/src/dialogs/animatedexpander.cpp b/src/dialogs/animatedexpander.cpp
index 42700891a..6ed473c35 100644
--- a/src/dialogs/animatedexpander.cpp
+++ b/src/dialogs/animatedexpander.cpp
@@ -1,116 +1,135 @@
/*
This file is part of Kleopatra, the KDE keymanager
SPDX-FileCopyrightText: 2019, 2021 g10 Code GmbH
SPDX-FileContributor: Ingo Klöcker <dev@ingo-kloecker.de>
SPDX-License-Identifier: GPL-2.0-or-later
*/
#include "dialogs/animatedexpander.h"
+#include <QFrame>
+#include <QGridLayout>
+#include <QParallelAnimationGroup>
#include <QPropertyAnimation>
+#include <QToolButton>
+
+static const int animationDuration = 300;
+
+class AnimatedExpander::Private
+{
+public:
+ QGridLayout mainLayout;
+ QToolButton toggleButton;
+ QFrame headerLine;
+ QParallelAnimationGroup toggleAnimation;
+ QWidget contentArea;
+};
void AnimatedExpander::setContentLayout(QLayout *contentLayout)
{
- delete contentArea.layout();
- contentArea.setLayout(contentLayout);
+ delete d->contentArea.layout();
+ d->contentArea.setLayout(contentLayout);
}
bool AnimatedExpander::isExpanded() const
{
- return toggleButton.isChecked();
+ return d->toggleButton.isChecked();
}
void AnimatedExpander::setExpanded(bool expanded)
{
- toggleButton.setChecked(expanded);
+ d->toggleButton.setChecked(expanded);
}
AnimatedExpander::AnimatedExpander(const QString &title, const QString &accessibleTitle, QWidget *parent)
: QWidget{parent}
+ , d{std::make_unique<Private>()}
{
#ifdef Q_OS_WIN
// draw dotted focus frame if button has focus; otherwise, draw invisible frame using background color
- toggleButton.setStyleSheet(
+ d->toggleButton.setStyleSheet(
QStringLiteral("QToolButton { border: 1px solid palette(window); }"
"QToolButton:focus { border: 1px dotted palette(window-text); }"));
#else
// this works with Breeze style because Breeze draws the focus frame when drawing CE_ToolButtonLabel
// while the Windows styles (and Qt's common base style) draw the focus frame before drawing CE_ToolButtonLabel
- toggleButton.setStyleSheet(QStringLiteral("QToolButton { border: none; }"));
+ d->toggleButton.setStyleSheet(QStringLiteral("QToolButton { border: none; }"));
#endif
- toggleButton.setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
- toggleButton.setArrowType(Qt::ArrowType::RightArrow);
- toggleButton.setText(title);
+ d->toggleButton.setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
+ d->toggleButton.setArrowType(Qt::ArrowType::RightArrow);
+ d->toggleButton.setText(title);
if (!accessibleTitle.isEmpty()) {
- toggleButton.setAccessibleName(accessibleTitle);
+ d->toggleButton.setAccessibleName(accessibleTitle);
}
- toggleButton.setCheckable(true);
- toggleButton.setChecked(false);
+ d->toggleButton.setCheckable(true);
+ d->toggleButton.setChecked(false);
- headerLine.setFrameShape(QFrame::HLine);
- headerLine.setFrameShadow(QFrame::Sunken);
- headerLine.setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum);
+ d->headerLine.setFrameShape(QFrame::HLine);
+ d->headerLine.setFrameShadow(QFrame::Sunken);
+ d->headerLine.setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum);
- contentArea.setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
+ d->contentArea.setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
// start out collapsed
- contentArea.setMaximumHeight(0);
- contentArea.setMinimumHeight(0);
- contentArea.setVisible(false);
+ d->contentArea.setMaximumHeight(0);
+ d->contentArea.setMinimumHeight(0);
+ d->contentArea.setVisible(false);
// let the entire widget grow and shrink with its content
- toggleAnimation.addAnimation(new QPropertyAnimation(this, "minimumHeight"));
- toggleAnimation.addAnimation(new QPropertyAnimation(this, "maximumHeight"));
- toggleAnimation.addAnimation(new QPropertyAnimation(&contentArea, "maximumHeight"));
+ d->toggleAnimation.addAnimation(new QPropertyAnimation(this, "minimumHeight"));
+ d->toggleAnimation.addAnimation(new QPropertyAnimation(this, "maximumHeight"));
+ d->toggleAnimation.addAnimation(new QPropertyAnimation(&d->contentArea, "maximumHeight"));
- mainLayout.setVerticalSpacing(0);
- mainLayout.setContentsMargins(0, 0, 0, 0);
+ d->mainLayout.setVerticalSpacing(0);
+ d->mainLayout.setContentsMargins(0, 0, 0, 0);
int row = 0;
- mainLayout.addWidget(&toggleButton, row, 0, 1, 1, Qt::AlignLeft);
- mainLayout.addWidget(&headerLine, row++, 2, 1, 1);
- mainLayout.addWidget(&contentArea, row, 0, 1, 3);
- setLayout(&mainLayout);
- connect(&toggleButton, &QToolButton::toggled, this, [this](const bool checked) {
+ d->mainLayout.addWidget(&d->toggleButton, row, 0, 1, 1, Qt::AlignLeft);
+ d->mainLayout.addWidget(&d->headerLine, row++, 2, 1, 1);
+ d->mainLayout.addWidget(&d->contentArea, row, 0, 1, 3);
+ setLayout(&d->mainLayout);
+ connect(&d->toggleButton, &QToolButton::toggled, this, [this](const bool checked) {
if (checked) {
Q_EMIT startExpanding();
// make the content visible when expanding starts
- contentArea.setVisible(true);
+ d->contentArea.setVisible(true);
}
// use instant animation if widget isn't visible (e.g. before widget is shown)
const int duration = isVisible() ? animationDuration : 0;
// update the size of the content area
- const auto collapsedHeight = sizeHint().height() - contentArea.maximumHeight();
- const auto contentHeight = contentArea.layout()->sizeHint().height();
- for (int i = 0; i < toggleAnimation.animationCount() - 1; ++i) {
- auto expanderAnimation = static_cast<QPropertyAnimation *>(toggleAnimation.animationAt(i));
+ const auto collapsedHeight = sizeHint().height() - d->contentArea.maximumHeight();
+ const auto contentHeight = d->contentArea.layout()->sizeHint().height();
+ for (int i = 0; i < d->toggleAnimation.animationCount() - 1; ++i) {
+ auto expanderAnimation = static_cast<QPropertyAnimation *>(d->toggleAnimation.animationAt(i));
expanderAnimation->setDuration(duration);
expanderAnimation->setStartValue(collapsedHeight);
expanderAnimation->setEndValue(collapsedHeight + contentHeight);
}
- auto contentAnimation = static_cast<QPropertyAnimation *>(toggleAnimation.animationAt(toggleAnimation.animationCount() - 1));
+ auto contentAnimation = static_cast<QPropertyAnimation *>(d->toggleAnimation.animationAt(d->toggleAnimation.animationCount() - 1));
contentAnimation->setDuration(duration);
contentAnimation->setStartValue(0);
contentAnimation->setEndValue(contentHeight);
- toggleButton.setArrowType(checked ? Qt::ArrowType::DownArrow : Qt::ArrowType::RightArrow);
- toggleAnimation.setDirection(checked ? QAbstractAnimation::Forward : QAbstractAnimation::Backward);
- toggleAnimation.start();
+ d->toggleButton.setArrowType(checked ? Qt::ArrowType::DownArrow : Qt::ArrowType::RightArrow);
+ d->toggleAnimation.setDirection(checked ? QAbstractAnimation::Forward : QAbstractAnimation::Backward);
+ d->toggleAnimation.start();
});
- connect(&toggleAnimation, &QAbstractAnimation::finished, this, [this]() {
+ connect(&d->toggleAnimation, &QAbstractAnimation::finished, this, [this]() {
// hide the content area when it is fully collapsed
- if (!toggleButton.isChecked()) {
- contentArea.setVisible(false);
+ if (!d->toggleButton.isChecked()) {
+ d->contentArea.setVisible(false);
}
});
}
+AnimatedExpander::~AnimatedExpander() = default;
+
int AnimatedExpander::contentHeight() const
{
- return contentArea.layout()->sizeHint().height();
+ return d->contentArea.layout()->sizeHint().height();
}
int AnimatedExpander::contentWidth() const
{
- return contentArea.layout()->sizeHint().width();
+ return d->contentArea.layout()->sizeHint().width();
}
diff --git a/src/dialogs/animatedexpander.h b/src/dialogs/animatedexpander.h
index 718024634..2b38d597a 100644
--- a/src/dialogs/animatedexpander.h
+++ b/src/dialogs/animatedexpander.h
@@ -1,44 +1,39 @@
/*
This file is part of Kleopatra, the KDE keymanager
SPDX-FileCopyrightText: 2019, 2021 g10 Code GmbH
SPDX-FileContributor: Ingo Klöcker <dev@ingo-kloecker.de>
SPDX-License-Identifier: GPL-2.0-or-later
*/
#pragma once
-#include <QFrame>
-#include <QGridLayout>
-#include <QParallelAnimationGroup>
-#include <QToolButton>
#include <QWidget>
+class QLayout;
+class QString;
+
// based on code from StackOverflow
class AnimatedExpander : public QWidget
{
Q_OBJECT
public:
explicit AnimatedExpander(const QString &title, const QString &accessibleTitle = {}, QWidget *parent = nullptr);
+ ~AnimatedExpander() override;
void setContentLayout(QLayout *contentLayout);
bool isExpanded() const;
void setExpanded(bool expanded);
int contentHeight() const;
int contentWidth() const;
Q_SIGNALS:
void startExpanding();
private:
- static const int animationDuration = 300;
-
- QGridLayout mainLayout;
- QToolButton toggleButton;
- QFrame headerLine;
- QParallelAnimationGroup toggleAnimation;
- QWidget contentArea;
+ class Private;
+ const std::unique_ptr<Private> d;
};

File Metadata

Mime Type
text/x-diff
Expires
Sun, Jan 18, 3:58 PM (1 h, 58 m)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
5f/d5/555af3f0c2d8480f21fd9ffa04f0

Event Timeline