File indexing completed on 2024-05-12 16:39:55
0001 /* This file is part of the KDE project 0002 Copyright (C) 2011-2018 Jarosław Staniek <staniek@kde.org> 0003 0004 This program is free software; you can redistribute it and/or 0005 modify it under the terms of the GNU Library General Public 0006 License as published by the Free Software Foundation; either 0007 version 2 of the License, or (at your option) any later version. 0008 0009 This program is distributed in the hope that it will be useful, 0010 but WITHOUT ANY WARRANTY; without even the implied warranty of 0011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0012 Library General Public License for more details. 0013 0014 You should have received a copy of the GNU Library General Public License 0015 along with this program; see the file COPYING. If not, write to 0016 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0017 * Boston, MA 02110-1301, USA. 0018 */ 0019 0020 #include "KexiAssistantWidget.h" 0021 #include "KexiAssistantPage.h" 0022 #include "KexiAnimatedLayout.h" 0023 #include <kexiutils/utils.h> 0024 0025 #include <QDebug> 0026 #include <QStyle> 0027 #include <QStack> 0028 #include <QPointer> 0029 0030 class Q_DECL_HIDDEN KexiAssistantWidget::Private 0031 { 0032 public: 0033 explicit Private(KexiAssistantWidget *qq) 0034 : q(qq) 0035 { 0036 } 0037 0038 ~Private() 0039 { 0040 } 0041 0042 void addPage(KexiAssistantPage* page) { 0043 lyr->addWidget(page); 0044 connect(page, &KexiAssistantPage::backRequested, q, &KexiAssistantWidget::previousPageRequested); 0045 connect(page, &KexiAssistantPage::tryBackRequested, q, &KexiAssistantWidget::tryPreviousPageRequested); 0046 connect(page, &KexiAssistantPage::nextRequested, q, &KexiAssistantWidget::nextPageRequested); 0047 connect(page, &KexiAssistantPage::cancelledRequested, q, &KexiAssistantWidget::cancelRequested); 0048 } 0049 0050 KexiAnimatedLayout *lyr; 0051 QStack< QPointer<KexiAssistantPage> > stack; 0052 0053 private: 0054 KexiAssistantWidget* q; 0055 }; 0056 0057 // ---- 0058 0059 KexiAssistantWidget::KexiAssistantWidget(QWidget* parent) 0060 : QWidget(parent) 0061 , d(new Private(this)) 0062 { 0063 QVBoxLayout *mainLyr = new QVBoxLayout(this); 0064 d->lyr = new KexiAnimatedLayout; 0065 mainLyr->addLayout(d->lyr); 0066 int margin = style()->pixelMetric(QStyle::PM_MenuPanelWidth, 0, 0) 0067 + KexiUtils::marginHint(); 0068 mainLyr->setContentsMargins(margin, margin, margin, margin); 0069 } 0070 0071 KexiAssistantWidget::~KexiAssistantWidget() 0072 { 0073 delete d; 0074 } 0075 0076 void KexiAssistantWidget::addPage(KexiAssistantPage* page) 0077 { 0078 d->addPage(page); 0079 } 0080 0081 void KexiAssistantWidget::previousPageRequested(KexiAssistantPage* page) 0082 { 0083 if (d->stack.count() < 2) { 0084 qWarning() << "Page stack's' count < 2"; 0085 return; 0086 } 0087 tryPreviousPageRequested(page); 0088 } 0089 0090 void KexiAssistantWidget::tryPreviousPageRequested(KexiAssistantPage* page) 0091 { 0092 Q_UNUSED(page); 0093 if (d->stack.count() < 2) { 0094 return; 0095 } 0096 d->stack.pop(); 0097 setCurrentPage(d->stack.top()); 0098 } 0099 0100 void KexiAssistantWidget::nextPageRequested(KexiAssistantPage* page) 0101 { 0102 Q_UNUSED(page); 0103 } 0104 0105 void KexiAssistantWidget::cancelRequested(KexiAssistantPage* page) 0106 { 0107 Q_UNUSED(page); 0108 } 0109 0110 KexiAssistantPage* KexiAssistantWidget::currentPage() const 0111 { 0112 return dynamic_cast<KexiAssistantPage*>(d->lyr->currentWidget()); 0113 } 0114 0115 void KexiAssistantWidget::setCurrentPage(KexiAssistantPage* page) 0116 { 0117 if (!page) { 0118 qWarning() << "!page"; 0119 return; 0120 } 0121 if (currentPage() && currentPage() != page) { 0122 QWidget *actualFocusWidget = currentPage()->focusWidget(); 0123 if (actualFocusWidget) { 0124 currentPage()->setRecentFocusWidget(actualFocusWidget); 0125 } 0126 } 0127 d->lyr->setCurrentWidget(page); 0128 if (page->recentFocusWidget()) { 0129 page->focusRecentFocusWidget(); 0130 } else { 0131 qWarning() << "Missing recent focus widget for" << page 0132 << "-- this cat lead to usability isses; please call " 0133 "KexiAssistantPage::setRecentFocusWidget() for that page."; 0134 } 0135 if (d->stack.isEmpty() || d->stack.top() != page) { 0136 int index = d->stack.indexOf(page); 0137 if (index != -1) { 0138 d->stack.remove(index); 0139 } 0140 d->stack.push(page); 0141 } 0142 } 0143