summaryrefslogtreecommitdiff
path: root/noncore/unsupported/qashmoney/datepicker.cpp
blob: 7997c0bc524db97f6b4d4ce7b23627fd81d5d3d5 (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
#include "datepicker.h"

DatePicker::DatePicker ( QDate entrydate ) : QDialog ( 0, 0, TRUE )
  {
    setCaption ( "Select Date" );
    date = entrydate;
    day = date.day();
    month = date.month();
    year = date.year();

    daylabel = new QLabel ( "Day", this );
    monthlabel = new QLabel ( "Month", this );
    yearlabel = new QLabel ( "Year", this );

    daybox = new QComboBox ( this, "daybox" );
    connect ( daybox, SIGNAL ( activated(int) ), this, SLOT ( setDay(int) ) );
    displayDays ( daybox );
    monthbox = new QComboBox ( this, "monthbox" );
    connect ( monthbox, SIGNAL ( activated(int) ), this, SLOT ( setMonth(int) ) );
    displayMonths ( monthbox );
    yearbox = new QComboBox ( this, "yearbox" );
    connect ( yearbox, SIGNAL ( activated(int) ), this, SLOT ( setYear(int) ) );
    displayYears ( yearbox );

    layout = new QGridLayout ( this, 2, 3, 5, 5, "datepickerlayout" );
    layout->addWidget ( daylabel, 0, 2 );
    layout->addWidget ( monthlabel, 0, 1 );
    layout->addWidget ( yearlabel, 0, 0 );
    layout->addWidget ( daybox, 1, 2 );
    layout->addWidget ( monthbox, 1, 1 );
    layout->addWidget ( yearbox, 1, 0 );
  }

void DatePicker::displayDays ( QComboBox *daybox )
  {
    int counter;
    int days = date.daysInMonth();
    for ( counter = 1; counter <= days; counter++ )
      daybox->insertItem ( QString::number ( counter ) );
    daybox->setCurrentItem ( ( date.day() ) - 1 );
  }

void DatePicker::displayMonths ( QComboBox *monthbox )
  {
    int counter;
    for ( counter = 1; counter <= 12; counter++ )
      monthbox->insertItem ( QString::number ( counter ) );
    monthbox->setCurrentItem ( ( date.month() ) - 1 );
  }

void DatePicker::displayYears ( QComboBox *yearbox )
  {
    int counter;
    int indexcounter = 0;
    int yearindex = 0;
    int year = date.year();
    for ( counter = ( year - 1 ); counter <= ( year + 1 ); counter++ )
      {
        yearbox->insertItem ( QString::number ( counter ) );
        if ( date.year() == counter )
          yearindex = indexcounter;
        indexcounter ++;
      }
    yearbox->setCurrentItem ( yearindex );
  }

void DatePicker::setDay ( int index )
  {
    day = daybox->text ( index ).toInt();
  }

void DatePicker::setMonth ( int index )
  {
    month = monthbox->text( index ).toInt();
  }

void DatePicker::setYear ( int index )
  {
    year = yearbox->text ( index ).toInt();
  }

int DatePicker::getDay ()
  { return day; }

int DatePicker::getMonth ()
  { return month; }

int DatePicker::getYear ()
  { return year; }