diff --git a/src/commands/creategroupcommand.cpp b/src/commands/creategroupcommand.cpp index 34a4508ac..3ad86f42b 100644 --- a/src/commands/creategroupcommand.cpp +++ b/src/commands/creategroupcommand.cpp @@ -1,116 +1,118 @@ /* This file is part of Kleopatra, the KDE keymanager SPDX-FileCopyrightText: 2024 g10 Code GmbH SPDX-FileContributor: Tobias Fella SPDX-License-Identifier: GPL-2.0-or-later */ #include "creategroupcommand.h" #include "command_p.h" #include "dialogs/editgroupdialog.h" #include #include #include #include #include using namespace Kleo; using namespace GpgME; using namespace Kleo::Dialogs; class CreateGroupCommand::Private : public Command::Private { friend class ::CreateGroupCommand; CreateGroupCommand *q_func() const { return static_cast(q); } public: using Command::Private::Private; ~Private() override; KeyGroup showEditGroupDialog(const std::vector &keys, KeyGroup group, const QString &windowTitle, EditGroupDialog::FocusWidget focusWidget); }; CreateGroupCommand::Private *CreateGroupCommand::d_func() { return static_cast(d.get()); } const CreateGroupCommand::Private *CreateGroupCommand::d_func() const { return static_cast(d.get()); } #define d d_func() #define q q_func() CreateGroupCommand::Private::~Private() = default; CreateGroupCommand::CreateGroupCommand(QAbstractItemView *v, KeyListController *p) : Command(v, new Private(this, p)) { } CreateGroupCommand::~CreateGroupCommand() = default; void CreateGroupCommand::doCancel() { } KeyGroup CreateGroupCommand::Private::showEditGroupDialog(const std::vector &keys, KeyGroup group, const QString &windowTitle, EditGroupDialog::FocusWidget focusWidget) { auto dialog = std::make_unique(parentWidgetOrView()); dialog->setWindowTitle(windowTitle); dialog->setGroupName(group.name()); dialog->setInitialFocus(focusWidget); dialog->setGroupKeys(keys); const int result = dialog->exec(); if (result == QDialog::Rejected) { return KeyGroup(); } group.setName(dialog->groupName()); group.setKeys(dialog->groupKeys()); return group; } void CreateGroupCommand::doStart() { auto keys = d->keys(); auto removed = std::erase_if(keys, [](const auto &key) { return !Kleo::keyHasEncrypt(key); }); if (removed == d->keys().size()) { KMessageBox::information(d->parentWidgetOrView(), i18n("None of the selected certificates can be used for encryption. No group will be created.")); return; } if (removed > 0) { KMessageBox::information(d->parentWidgetOrView(), i18n("Some of the selected certificates cannot be used for encryption. These will not be added to the group.")); } const KeyGroup::Id newId = KRandom::randomString(8); KeyGroup group = KeyGroup(newId, i18nc("default name for new group of keys", "New Group"), {}, KeyGroup::ApplicationConfig); group.setIsImmutable(false); const KeyGroup newGroup = d->showEditGroupDialog(keys, group, i18nc("@title:window a group of keys", "New Group"), EditGroupDialog::GroupName); if (!newGroup.isNull()) { auto groups = KeyCache::instance()->configurableGroups(); groups.push_back(newGroup); KeyCache::mutableInstance()->saveConfigurableGroups(groups); } d->finished(); } + +#include "moc_creategroupcommand.cpp" diff --git a/src/conf/kleoconfigmodule.cpp b/src/conf/kleoconfigmodule.cpp index 1d5962f91..3b43514d7 100644 --- a/src/conf/kleoconfigmodule.cpp +++ b/src/conf/kleoconfigmodule.cpp @@ -1,5 +1,7 @@ // SPDX-FileCopyrightText: 2024 g10 Code GmbH // SPDX-FileContributor: Tobias Fella // SPDX-License-Identifier: GPL-2.0-or-later #include "kleoconfigmodule.h" + +#include "moc_kleoconfigmodule.cpp" diff --git a/src/dialogs/animatedexpander.cpp b/src/dialogs/animatedexpander.cpp index e1d775ab3..828181a45 100644 --- a/src/dialogs/animatedexpander.cpp +++ b/src/dialogs/animatedexpander.cpp @@ -1,111 +1,113 @@ /* This file is part of Kleopatra, the KDE keymanager SPDX-FileCopyrightText: 2019, 2021 g10 Code GmbH SPDX-FileContributor: Ingo Klöcker SPDX-License-Identifier: GPL-2.0-or-later */ #include "dialogs/animatedexpander.h" #include void AnimatedExpander::setContentLayout(QLayout *contentLayout) { delete contentArea.layout(); contentArea.setLayout(contentLayout); } bool AnimatedExpander::isExpanded() const { return toggleButton.isChecked(); } void AnimatedExpander::setExpanded(bool expanded) { toggleButton.setChecked(expanded); } AnimatedExpander::AnimatedExpander(const QString &title, const QString &accessibleTitle, QWidget *parent) : QWidget{parent} { #ifdef Q_OS_WIN // draw dotted focus frame if button has focus; otherwise, draw invisible frame using background color 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; }")); #endif toggleButton.setToolButtonStyle(Qt::ToolButtonTextBesideIcon); toggleButton.setArrowType(Qt::ArrowType::RightArrow); toggleButton.setText(title); if (!accessibleTitle.isEmpty()) { toggleButton.setAccessibleName(accessibleTitle); } toggleButton.setCheckable(true); toggleButton.setChecked(false); headerLine.setFrameShape(QFrame::HLine); headerLine.setFrameShadow(QFrame::Sunken); headerLine.setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum); contentArea.setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); // start out collapsed contentArea.setMaximumHeight(0); contentArea.setMinimumHeight(0); 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")); mainLayout.setVerticalSpacing(0); 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) { Q_EMIT startExpanding(); if (checked) { // make the content visible when expanding starts 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(toggleAnimation.animationAt(i)); expanderAnimation->setDuration(duration); expanderAnimation->setStartValue(collapsedHeight); expanderAnimation->setEndValue(collapsedHeight + contentHeight); } auto contentAnimation = static_cast(toggleAnimation.animationAt(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(); }); connect(&toggleAnimation, &QAbstractAnimation::finished, this, [this]() { // hide the content area when it is fully collapsed if (!toggleButton.isChecked()) { contentArea.setVisible(false); } }); } int AnimatedExpander::contentHeight() const { return contentArea.layout()->sizeHint().height(); } + +#include "moc_animatedexpander.cpp"