summaryrefslogtreecommitdiff
path: root/core/pim/todo/taskeditoroverviewimpl.cpp
blob: 24b33860ce1a2f97c65675e0528970e08b489d15 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
#include <qapplication.h>
#include <qcheckbox.h>
#include <qcombobox.h>
#include <qpopupmenu.h>

#include <qpe/datebookmonth.h>
#include <qpe/categoryselect.h>
#include <qpe/timestring.h>

#include "taskeditoroverviewimpl.h"

/*
 * we need to hack
 */

TaskEditorOverViewImpl::TaskEditorOverViewImpl( QWidget* parent, const char* name )
    : TaskEditorOverView( parent, name ) {
    init();
}
TaskEditorOverViewImpl::~TaskEditorOverViewImpl() {
}
void TaskEditorOverViewImpl::load( const OTodo& todo) {
      /*
     * now that we're 'preloaded' we
     * need to disable the buttons
     * holding the dat
     */
    btnDue->  setEnabled( FALSE );
    btnComp-> setEnabled( FALSE );
    btnStart->setEnabled( FALSE );


    QDate date = QDate::currentDate();
    QString str = TimeString::longDateString( date );

    emit recurranceEnabled( FALSE );
    ckbStart->setChecked( FALSE );
    btnStart->setText( str );

    ckbComp->setChecked( FALSE );
    btnComp->setText( str );

    cmbProgress->setCurrentItem( todo.progress()/20 );
    cmbSum->insertItem( todo.summary(), 0 );
    cmbSum->setCurrentItem( 0 );

    ckbDue->setChecked( todo.hasDueDate() );
    btnDue->setText( TimeString::longDateString( todo.dueDate() ) );
    btnDue->setEnabled( todo.hasDueDate() );

    cmbPrio->setCurrentItem( todo.priority() -1 );
    ckbCompleted->setChecked( todo.isCompleted() );

    comboCategory->setCategories( todo.categories(), "Todo List", tr("Todo List") );

}
void TaskEditorOverViewImpl::save( OTodo& to) {
    qWarning("save it now");
    if ( ckbDue->isChecked() ) {
        to.setDueDate( m_due );
        to.setHasDueDate( true );
    }else
        to.setHasDueDate( false );
    if ( comboCategory->currentCategory() != -1 ) {
        QArray<int> arr = comboCategory->currentCategories();
        to.setCategories( arr );
    }
    to.setPriority( cmbPrio->currentItem() + 1 );
    to.setCompleted( ckbCompleted->isChecked() );
    to.setSummary( cmbSum->currentText() );
    to.setProgress( cmbProgress->currentItem() * 20 );
}
/*
 * here we will init the basic view
 * one Popup for each Date Button
 * and some other signal and slots connection
 */
void TaskEditorOverViewImpl::init() {
    QDate curDate = QDate::currentDate();
    m_start = m_comp = m_due = curDate;
    QString str = TimeString::longDateString( curDate );



    /* Start Date Picker */
    m_startPop = new QPopupMenu(this);
    m_startBook = new DateBookMonth(m_startPop, 0, TRUE );
    m_startPop->insertItem( m_startBook );
    connect( m_startBook, SIGNAL( dateClicked(int, int, int) ),
             this, SLOT(slotStartChanged(int, int, int) ) );


    /* Due Date Picker */
    m_duePop = new QPopupMenu(this);
    m_dueBook = new DateBookMonth(m_duePop, 0, TRUE );
    m_duePop->insertItem( m_dueBook );
    connect( m_dueBook, SIGNAL( dateClicked(int, int, int) ),
             this, SLOT(slotDueChanged(int, int, int) ) );

    m_compPop = new QPopupMenu(this);
    m_compBook = new DateBookMonth(m_compPop, 0, TRUE );
    m_compPop->insertItem(m_compBook );
    connect( m_compBook, SIGNAL(dateClicked(int, int, int) ),
             this, SLOT(slotCompletedChanged(int, int, int) ) );


    /*
     * another part of the hack
     * it's deprecated in Qt2 but
     * still available in my qt-copy of Qt3.1beta2
     */
    btnDue->setIsMenuButton( TRUE );
    btnStart->setIsMenuButton( TRUE );
    btnComp->setIsMenuButton( TRUE );

    /* now connect the hack */
    connect(btnDue, SIGNAL(clicked() ),
            this, SLOT(hackySlotHack2() ) );
    connect(btnStart, SIGNAL(clicked() ),
            this, SLOT(hackySlotHack1() ) );
    connect(btnComp, SIGNAL(clicked() ),
            this, SLOT(hackySlotHack3() ) );

    /* recurrance */
    connect(CheckBox7, SIGNAL(clicked() ),
            this, SLOT(slotRecClicked() ) );
}

void TaskEditorOverViewImpl::slotStartChecked() {
    qWarning("slotStartChecked");
    btnStart->setEnabled( ckbStart->isChecked() );
}
void TaskEditorOverViewImpl::slotStartChanged(int y, int m, int d) {
    m_start.setYMD( y, m, d );
    btnStart->setText( TimeString::longDateString( m_start ) );
}
void TaskEditorOverViewImpl::slotDueChecked() {
    btnDue->setEnabled( ckbDue->isChecked() );
    qWarning("slotDueChecked");
}
void TaskEditorOverViewImpl::slotDueChanged(int y, int m, int d ) {
    m_due.setYMD(y, m, d );
    btnDue->setText( TimeString::longDateString( m_due ) );
}
void TaskEditorOverViewImpl::slotCompletedChecked() {
    btnComp->setEnabled( ckbComp->isChecked() );
    qWarning("slotCompletedChecked");
}
void TaskEditorOverViewImpl::slotCompletedChanged(int y, int m, int d) {
    m_comp.setYMD( y, m, d );
    btnComp->setText( TimeString::longDateString( m_comp ) );
}
/*
 * called by a button pressed event...
 * three slots to avoid ugly name() tests
 * to sender()
 */
void TaskEditorOverViewImpl::hackySlotHack1() {
    btnStart->setDown( FALSE );
    popup( btnStart, m_startPop );
}
void TaskEditorOverViewImpl::hackySlotHack2() {
    btnDue->setDown( FALSE );
    popup( btnDue, m_duePop );
}
void TaskEditorOverViewImpl::hackySlotHack3() {
    btnComp->setDown( FALSE );
    popup( btnComp, m_compPop );
}
void TaskEditorOverViewImpl::slotRecClicked() {
    qWarning("enabled recurrance");
    emit recurranceEnabled( CheckBox7->isChecked() );
}
/*
 * GPL from TT QPushButton code
 */
void TaskEditorOverViewImpl::popup( QPushButton* pu,  QPopupMenu* pop) {
    if ( pu->mapToGlobal( QPoint(0, pu->rect().bottom() ) ).y()  + pop->sizeHint().height() <= qApp->desktop()->height() )
        pop->exec( pu->mapToGlobal( pu->rect().bottomLeft()  ) );
    else
        pop->exec( pu->mapToGlobal( pu->rect().topLeft() - QPoint(0, pu->sizeHint().height()  ) ) );
}