Pimcommon

customtoolswidgetng.cpp
1/*
2 SPDX-FileCopyrightText: 2015-2024 Laurent Montel <montel@kde.org>
3
4 SPDX-License-Identifier: GPL-2.0-or-later
5*/
6
7#include "customtoolswidgetng.h"
8using namespace Qt::Literals::StringLiterals;
9
10#include "customtoolsplugin.h"
11#include "customtoolsviewinterface.h"
12
13#include <KToggleAction>
14
15#include <QHBoxLayout>
16#include <QStackedWidget>
17
18using namespace PimCommon;
19
20class PimCommon::CustomToolsWidgetNgPrivate
21{
22public:
23 CustomToolsWidgetNgPrivate() = default;
24
25 QStackedWidget *mStackedWidget = nullptr;
27};
28
29CustomToolsWidgetNg::CustomToolsWidgetNg(QWidget *parent)
30 : QWidget(parent)
31 , d(new PimCommon::CustomToolsWidgetNgPrivate)
32{
33 auto lay = new QHBoxLayout(this);
34 lay->setContentsMargins({});
35 d->mStackedWidget = new QStackedWidget;
36 d->mStackedWidget->setObjectName("stackedwidget"_L1);
37 lay->addWidget(d->mStackedWidget);
38 hide();
39}
40
41CustomToolsWidgetNg::~CustomToolsWidgetNg() = default;
42
43void CustomToolsWidgetNg::addCustomToolViewInterface(PimCommon::CustomToolsViewInterface *plugin)
44{
45 d->mListInterfaceView.append(plugin);
46 d->mStackedWidget->addWidget(plugin);
47}
48
49void CustomToolsWidgetNg::initializeView(KActionCollection *ac, const QList<CustomToolsPlugin *> &localPluginsList)
50{
51 for (CustomToolsPlugin *plugin : localPluginsList) {
52 PimCommon::CustomToolsViewInterface *localCreateView = plugin->createView(ac, this);
53 d->mListInterfaceView.append(localCreateView);
54 d->mStackedWidget->addWidget(localCreateView);
55 }
56}
57
58void CustomToolsWidgetNg::slotToolsWasClosed()
59{
60 for (PimCommon::CustomToolsViewInterface *interface : std::as_const(d->mListInterfaceView)) {
61 interface->action()->setChecked(false);
62 }
63 hide();
64}
65
66void CustomToolsWidgetNg::slotActivateView(QWidget *w)
67{
68 if (w) {
69 d->mStackedWidget->setCurrentWidget(w);
70 setVisible(true);
71 for (PimCommon::CustomToolsViewInterface *interface : std::as_const(d->mListInterfaceView)) {
72 if (interface != w) {
73 interface->action()->setChecked(false);
74 }
75 }
76 Q_EMIT toolActivated();
77 } else {
78 setVisible(false);
79 slotToolsWasClosed();
80 }
81}
82
83QList<KToggleAction *> CustomToolsWidgetNg::actionList() const
84{
85 QList<KToggleAction *> lstActions;
86 lstActions.reserve(d->mListInterfaceView.count());
87 for (PimCommon::CustomToolsViewInterface *interface : std::as_const(d->mListInterfaceView)) {
88 lstActions << interface->action();
89 }
90 return lstActions;
91}
92
93void CustomToolsWidgetNg::setText(const QString &text)
94{
95 if (isVisible()) {
96 auto currentWidget = d->mStackedWidget->currentWidget();
97 auto it = std::find_if(d->mListInterfaceView.cbegin(), d->mListInterfaceView.cend(), [currentWidget](auto interface) {
98 return interface == currentWidget;
99 });
100 if (it != d->mListInterfaceView.cend()) {
101 (*it)->setText(text);
102 }
103 }
104}
105
106#include "moc_customtoolswidgetng.cpp"
The CustomToolsPlugin class.
The CustomToolsViewInterface class.
folderdialogacltab.h
void reserve(qsizetype size)
Q_EMITQ_EMIT
void setObjectName(QAnyStringView name)
void hide()
virtual void setVisible(bool visible)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 4 2024 16:39:22 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.