~ubuntu-branches/debian/sid/kexi/sid

« back to all changes in this revision

Viewing changes to src/kexiutils/KexiAssistantWidget.cpp

  • Committer: Package Import Robot
  • Author(s): Pino Toscano
  • Date: 2017-06-24 20:10:10 UTC
  • Revision ID: package-import@ubuntu.com-20170624201010-5lrzd5r2vwthwifp
Tags: upstream-3.0.1.1
Import upstream version 3.0.1.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* This file is part of the KDE project
 
2
   Copyright (C) 2011-2013 Jarosław Staniek <staniek@kde.org>
 
3
 
 
4
   This program is free software; you can redistribute it and/or
 
5
   modify it under the terms of the GNU Library General Public
 
6
   License as published by the Free Software Foundation; either
 
7
   version 2 of the License, or (at your option) any later version.
 
8
 
 
9
   This program is distributed in the hope that it will be useful,
 
10
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
12
   Library General Public License for more details.
 
13
 
 
14
   You should have received a copy of the GNU Library General Public License
 
15
   along with this program; see the file COPYING.  If not, write to
 
16
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 
17
 * Boston, MA 02110-1301, USA.
 
18
 */
 
19
 
 
20
#include "KexiAssistantWidget.h"
 
21
#include "KexiAssistantPage.h"
 
22
#include "KexiAnimatedLayout.h"
 
23
#include <kexiutils/utils.h>
 
24
 
 
25
#include <QDebug>
 
26
#include <QStyle>
 
27
#include <QStack>
 
28
#include <QPointer>
 
29
 
 
30
class KexiAssistantWidget::Private
 
31
{
 
32
public:
 
33
    explicit Private(KexiAssistantWidget *qq)
 
34
        : q(qq)
 
35
    {
 
36
    }
 
37
 
 
38
    ~Private()
 
39
    {
 
40
    }
 
41
 
 
42
    void addPage(KexiAssistantPage* page) {
 
43
        lyr->addWidget(page);
 
44
        connect(page, SIGNAL(back(KexiAssistantPage*)), q, SLOT(previousPageRequested(KexiAssistantPage*)));
 
45
        connect(page, SIGNAL(next(KexiAssistantPage*)), q, SLOT(nextPageRequested(KexiAssistantPage*)));
 
46
        connect(page, SIGNAL(cancelled(KexiAssistantPage*)), q, SLOT(cancelRequested(KexiAssistantPage*)));
 
47
    }
 
48
 
 
49
    KexiAnimatedLayout *lyr;
 
50
    QStack< QPointer<KexiAssistantPage> > stack;
 
51
 
 
52
private:
 
53
    KexiAssistantWidget* q;
 
54
};
 
55
 
 
56
// ----
 
57
 
 
58
KexiAssistantWidget::KexiAssistantWidget(QWidget* parent)
 
59
 : QWidget(parent)
 
60
 , d(new Private(this))
 
61
{
 
62
    QVBoxLayout *mainLyr = new QVBoxLayout(this);
 
63
    d->lyr = new KexiAnimatedLayout;
 
64
    mainLyr->addLayout(d->lyr);
 
65
    int margin = style()->pixelMetric(QStyle::PM_MenuPanelWidth, 0, 0)
 
66
        + KexiUtils::marginHint();
 
67
    mainLyr->setContentsMargins(margin, margin, margin, margin);
 
68
}
 
69
 
 
70
KexiAssistantWidget::~KexiAssistantWidget()
 
71
{
 
72
    delete d;
 
73
}
 
74
 
 
75
void KexiAssistantWidget::addPage(KexiAssistantPage* page)
 
76
{
 
77
    d->addPage(page);
 
78
}
 
79
 
 
80
void KexiAssistantWidget::previousPageRequested(KexiAssistantPage* page)
 
81
{
 
82
    Q_UNUSED(page);
 
83
    if (d->stack.count() < 2) {
 
84
        qWarning() << "Page stack's' count < 2";
 
85
        return;
 
86
    }
 
87
    d->stack.pop();
 
88
    setCurrentPage(d->stack.top());
 
89
}
 
90
 
 
91
void KexiAssistantWidget::nextPageRequested(KexiAssistantPage* page)
 
92
{
 
93
    Q_UNUSED(page);
 
94
}
 
95
 
 
96
void KexiAssistantWidget::cancelRequested(KexiAssistantPage* page)
 
97
{
 
98
    Q_UNUSED(page);
 
99
}
 
100
 
 
101
KexiAssistantPage* KexiAssistantWidget::currentPage() const
 
102
{
 
103
    return dynamic_cast<KexiAssistantPage*>(d->lyr->currentWidget());
 
104
}
 
105
 
 
106
void KexiAssistantWidget::setCurrentPage(KexiAssistantPage* page)
 
107
{
 
108
    if (!page) {
 
109
        qWarning() << "!page";
 
110
        return;
 
111
    }
 
112
    d->lyr->setCurrentWidget(page);
 
113
    if (page->focusWidget()) {
 
114
        page->focusWidget()->setFocus();
 
115
    }
 
116
    if (d->stack.isEmpty() || d->stack.top() != page) {
 
117
        int index = d->stack.indexOf(page);
 
118
        if (index != -1) {
 
119
            d->stack.remove(index);
 
120
        }
 
121
        d->stack.push(page);
 
122
    }
 
123
}
 
124