~ubuntu-branches/debian/sid/calligraplan/sid

« back to all changes in this revision

Viewing changes to src/libs/ui/kptaccountsviewconfigdialog.cpp

  • Committer: Package Import Robot
  • Author(s): Pino Toscano
  • Date: 2018-02-01 18:20:19 UTC
  • Revision ID: package-import@ubuntu.com-20180201182019-1qo7qaim5wejm5k9
Tags: upstream-3.1.0
ImportĀ upstreamĀ versionĀ 3.1.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* This file is part of the KDE project
 
2
   Copyright (C) 2005, 2012 Dag Andersen <danders@get2net.dk>
 
3
 
 
4
   This library 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 library 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 library; see the file COPYING.LIB.  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 "kptaccountsviewconfigdialog.h"
 
21
 
 
22
#include "kptaccountsview.h"
 
23
#include "kptaccountsmodel.h"
 
24
#include "kptviewbase.h"
 
25
#include "kptdebug.h"
 
26
 
 
27
#include "KoPageLayoutWidget.h"
 
28
 
 
29
#include <KLocalizedString>
 
30
 
 
31
#include <QPushButton>
 
32
#include <QCheckBox>
 
33
#include <QString>
 
34
 
 
35
 
 
36
namespace KPlato
 
37
{
 
38
 
 
39
AccountsviewConfigDialog::AccountsviewConfigDialog( ViewBase *view, AccountsTreeView *treeview, QWidget *p, bool selectPrint)
 
40
    : KPageDialog(p),
 
41
    m_view( view ),
 
42
    m_treeview( treeview )
 
43
{
 
44
    setWindowTitle( i18n("Settings") );
 
45
    m_panel = new AccountsviewConfigPanel( this );
 
46
    switch ( treeview->startMode() ) {
 
47
        case CostBreakdownItemModel::StartMode_Project: 
 
48
            m_panel->ui_projectstartBtn->setChecked( true );
 
49
            m_panel->ui_startdate->setEnabled( false );
 
50
            break;
 
51
        case CostBreakdownItemModel::StartMode_Date:
 
52
            m_panel->ui_startdateBtn->setChecked( true );
 
53
            break;
 
54
    }
 
55
    switch ( treeview->endMode() ) {
 
56
        case CostBreakdownItemModel::EndMode_Project:
 
57
            m_panel->ui_projectendBtn->setChecked( true );
 
58
            m_panel->ui_enddate->setEnabled( false );
 
59
            break;
 
60
        case CostBreakdownItemModel::EndMode_Date:
 
61
            m_panel->ui_enddateBtn->setChecked( true );
 
62
            break;
 
63
        case CostBreakdownItemModel::EndMode_CurrentDate:
 
64
            m_panel->ui_currentdateBtn->setChecked( true );
 
65
            m_panel->ui_enddate->setEnabled( false );
 
66
            break;
 
67
    }
 
68
    m_panel->ui_startdate->setDate( treeview->startDate() );
 
69
    m_panel->ui_enddate->setDate( treeview->endDate() );
 
70
    m_panel->ui_periodBox->setCurrentIndex( treeview->periodType() );
 
71
    m_panel->ui_cumulative->setChecked( treeview->cumulative() );
 
72
    m_panel->ui_showBox->setCurrentIndex( treeview->showMode() );
 
73
 
 
74
    KPageWidgetItem *page = addPage( m_panel, i18n( "General" ) );
 
75
    page->setHeader( i18n( "View Settings" ) );
 
76
 
 
77
    QTabWidget *tab = new QTabWidget();
 
78
 
 
79
    QWidget *w = ViewBase::createPageLayoutWidget( view );
 
80
    tab->addTab( w, w->windowTitle() );
 
81
    m_pagelayout = w->findChild<KoPageLayoutWidget*>();
 
82
    Q_ASSERT( m_pagelayout );
 
83
 
 
84
    m_headerfooter = ViewBase::createHeaderFooterWidget( view );
 
85
    m_headerfooter->setOptions( view->printingOptions() );
 
86
    tab->addTab( m_headerfooter, m_headerfooter->windowTitle() );
 
87
 
 
88
    page = addPage( tab, i18n( "Printing" ) );
 
89
    page->setHeader( i18n( "Printing Options" ) );
 
90
    if (selectPrint) {
 
91
        setCurrentPage(page);
 
92
    }
 
93
    connect( this, SIGNAL(accepted()), this, SLOT(slotOk()));
 
94
 
 
95
    connect(m_panel, SIGNAL(changed(bool)), SLOT(enableOkButton(bool)));
 
96
}
 
97
 
 
98
void AccountsviewConfigDialog::enableOkButton(bool enabled)
 
99
{
 
100
    button( QDialogButtonBox::Ok )->setEnabled( enabled );
 
101
}
 
102
 
 
103
 
 
104
void AccountsviewConfigDialog::slotOk()
 
105
{
 
106
    debugPlan;
 
107
    m_treeview->setPeriodType( m_panel->ui_periodBox->currentIndex() );
 
108
    m_treeview->setCumulative( m_panel->ui_cumulative->isChecked() );
 
109
    m_treeview->setShowMode( m_panel->ui_showBox->currentIndex() );
 
110
    if ( m_panel->ui_startdateBtn->isChecked() ) {
 
111
        m_treeview->setStartDate( m_panel->ui_startdate->date() );
 
112
        m_treeview->setStartMode( CostBreakdownItemModel::StartMode_Date );
 
113
    } else {
 
114
        m_treeview->setStartMode( CostBreakdownItemModel::StartMode_Project );
 
115
    }
 
116
 
 
117
    if ( m_panel->ui_enddateBtn->isChecked() ) {
 
118
        m_treeview->setEndDate( m_panel->ui_enddate->date() );
 
119
        m_treeview->setEndMode( CostBreakdownItemModel::EndMode_Date );
 
120
    } else if ( m_panel->ui_currentdateBtn->isChecked() ) {
 
121
        m_treeview->setEndMode( CostBreakdownItemModel::EndMode_CurrentDate );
 
122
    } else {
 
123
        m_treeview->setEndMode( CostBreakdownItemModel::EndMode_Project );
 
124
    }
 
125
 
 
126
    m_view->setPageLayout( m_pagelayout->pageLayout() );
 
127
    m_view->setPrintingOptions( m_headerfooter->options() );
 
128
}
 
129
 
 
130
 
 
131
//----------------------------
 
132
AccountsviewConfigPanel::AccountsviewConfigPanel(QWidget *parent)
 
133
    : AccountsviewConfigurePanelBase(parent)
 
134
{
 
135
 
 
136
    connect(ui_startdate, SIGNAL(dateChanged(QDate)), SLOT(slotChanged()));
 
137
    connect(ui_enddate, SIGNAL(dateChanged(QDate)), SLOT(slotChanged()));
 
138
    connect(ui_periodBox, SIGNAL(activated(int)), SLOT(slotChanged()));
 
139
    connect(ui_cumulative, SIGNAL(clicked()), SLOT(slotChanged()));
 
140
 
 
141
    connect(ui_projectstartBtn, SIGNAL(clicked()), SLOT(slotChanged()));
 
142
    connect(ui_startdateBtn, SIGNAL(clicked()), SLOT(slotChanged()));
 
143
    connect(ui_projectendBtn, SIGNAL(clicked()), SLOT(slotChanged()));
 
144
    connect(ui_currentdateBtn, SIGNAL(clicked()), SLOT(slotChanged()));
 
145
    connect(ui_enddateBtn, SIGNAL(clicked()), SLOT(slotChanged()));
 
146
    connect(ui_showBox, SIGNAL(activated(int)), SLOT(slotChanged()));
 
147
    
 
148
    connect(ui_startdateBtn, SIGNAL(toggled(bool)), ui_startdate, SLOT(setEnabled(bool)));
 
149
    connect(ui_enddateBtn, SIGNAL(toggled(bool)), ui_enddate, SLOT(setEnabled(bool)));
 
150
}
 
151
 
 
152
void AccountsviewConfigPanel::slotChanged() {
 
153
    emit changed(true);
 
154
}
 
155
 
 
156
 
 
157
}  //KPlato namespace