kplato

kptaccountsviewconfigdialog.cpp

Go to the documentation of this file.
00001 /* This file is part of the KDE project
00002    Copyright (C) 2005 Dag Andersen <danders@get2net.dk>
00003 
00004    This library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Library General Public
00006    License as published by the Free Software Foundation; either
00007    version 2 of the License, or (at your option) any later version.
00008 
00009    This library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Library General Public License for more details.
00013 
00014    You should have received a copy of the GNU Library General Public License
00015    along with this library; see the file COPYING.LIB.  If not, write to
00016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017  * Boston, MA 02110-1301, USA.
00018 */
00019 
00020 #include "kptaccountsviewconfigdialog.h"
00021 
00022 #include "kptaccountsview.h"
00023 #include "kptaccountsmodel.h"
00024 
00025 #include <QCheckBox>
00026 #include <qdatetime.h>
00027 #include <QString>
00028 
00029 #include <kdatewidget.h>
00030 #include <klocale.h>
00031 
00032 #include <kdebug.h>
00033 
00034 namespace KPlato
00035 {
00036 
00037 AccountsviewConfigDialog::AccountsviewConfigDialog( AccountsTreeView *view, QWidget *p)
00038     : KDialog(p),
00039     m_view( view )
00040 {
00041     setCaption( i18n("Settings") );
00042     setButtons( Ok|Cancel );
00043     setDefaultButton( Ok );
00044     showButtonSeparator( true );
00045     m_panel = new AccountsviewConfigPanel(this);
00046     switch ( view->startMode() ) {
00047         case CostBreakdownItemModel::StartMode_Project: 
00048             m_panel->ui_projectstartBtn->setChecked( true );
00049             m_panel->ui_startdate->setEnabled( false );
00050             break;
00051         case CostBreakdownItemModel::StartMode_Date:
00052             m_panel->ui_startdateBtn->setChecked( true );
00053             break;
00054     }
00055     switch ( view->endMode() ) {
00056         case CostBreakdownItemModel::EndMode_Project:
00057             m_panel->ui_projectendBtn->setChecked( true );
00058             m_panel->ui_enddate->setEnabled( false );
00059             break;
00060         case CostBreakdownItemModel::EndMode_Date:
00061             m_panel->ui_enddateBtn->setChecked( true );
00062             break;
00063         case CostBreakdownItemModel::EndMode_CurrentDate:
00064             m_panel->ui_currentdateBtn->setChecked( true );
00065             m_panel->ui_enddate->setEnabled( false );
00066             break;
00067     }
00068     m_panel->ui_startdate->setDate( view->startDate() );
00069     m_panel->ui_enddate->setDate( view->endDate() );
00070     m_panel->ui_periodBox->setCurrentIndex( view->periodType() );
00071     m_panel->ui_cumulative->setChecked( view->cumulative() );
00072     m_panel->ui_showBox->setCurrentIndex( view->showMode() );
00073     setMainWidget(m_panel);
00074 
00075     enableButtonOk(false);
00076 
00077     connect(m_panel, SIGNAL(changed(bool)), SLOT( enableButtonOk(bool)));
00078     connect( this, SIGNAL( okClicked() ), this, SLOT( slotOk() ) );
00079 }
00080 
00081 
00082 void AccountsviewConfigDialog::slotOk()
00083 {
00084     kDebug();
00085     m_view->setPeriodType( m_panel->ui_periodBox->currentIndex() );
00086     m_view->setCumulative( m_panel->ui_cumulative->isChecked() );
00087     m_view->setShowMode( m_panel->ui_showBox->currentIndex() );
00088     if ( m_panel->ui_startdateBtn->isChecked() ) {
00089         m_view->setStartDate( m_panel->ui_startdate->date() );
00090         m_view->setStartMode( CostBreakdownItemModel::StartMode_Date );
00091     } else {
00092         m_view->setStartMode( CostBreakdownItemModel::StartMode_Project );
00093     }
00094 
00095     if ( m_panel->ui_enddateBtn->isChecked() ) {
00096         m_view->setEndDate( m_panel->ui_enddate->date() );
00097         m_view->setEndMode( CostBreakdownItemModel::EndMode_Date );
00098     } else if ( m_panel->ui_currentdateBtn->isChecked() ) {
00099         m_view->setEndMode( CostBreakdownItemModel::EndMode_CurrentDate );
00100     } else {
00101         m_view->setEndMode( CostBreakdownItemModel::EndMode_Project );
00102     }
00103 }
00104 
00105 
00106 //----------------------------
00107 AccountsviewConfigPanel::AccountsviewConfigPanel(QWidget *parent)
00108     : AccountsviewConfigurePanelBase(parent)
00109 {
00110 
00111     connect(ui_startdate, SIGNAL(dateChanged(const QDate&)), SLOT(slotChanged()));
00112     connect(ui_enddate, SIGNAL(dateChanged(const QDate&)), SLOT(slotChanged()));
00113     connect(ui_periodBox, SIGNAL(activated(int)), SLOT(slotChanged()));
00114     connect(ui_cumulative, SIGNAL(clicked()), SLOT(slotChanged()));
00115 
00116     connect(ui_projectstartBtn, SIGNAL(clicked()), SLOT(slotChanged()));
00117     connect(ui_startdateBtn, SIGNAL(clicked()), SLOT(slotChanged()));
00118     connect(ui_projectendBtn, SIGNAL(clicked()), SLOT(slotChanged()));
00119     connect(ui_currentdateBtn, SIGNAL(clicked()), SLOT(slotChanged()));
00120     connect(ui_enddateBtn, SIGNAL(clicked()), SLOT(slotChanged()));
00121     connect(ui_showBox, SIGNAL(activated(int)), SLOT(slotChanged()));
00122     
00123     connect(ui_startdateBtn, SIGNAL(toggled(bool)), ui_startdate, SLOT(setEnabled(bool)));
00124     connect(ui_enddateBtn, SIGNAL(toggled(bool)), ui_enddate, SLOT(setEnabled(bool)));
00125 }
00126 
00127 void AccountsviewConfigPanel::slotChanged() {
00128     emit changed(true);
00129 }
00130 
00131 
00132 }  //KPlato namespace
00133 
00134 #include "kptaccountsviewconfigdialog.moc"