-rw-r--r-- | libkdepim/kdatepicker.cpp | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/libkdepim/kdatepicker.cpp b/libkdepim/kdatepicker.cpp index 3fe139c..d8bc9f5 100644 --- a/libkdepim/kdatepicker.cpp +++ b/libkdepim/kdatepicker.cpp | |||
@@ -20,138 +20,141 @@ | |||
20 | 20 | ||
21 | #include "kdatepicker.h" | 21 | #include "kdatepicker.h" |
22 | #include <kglobal.h> | 22 | #include <kglobal.h> |
23 | #include <kapplication.h> | 23 | #include <kapplication.h> |
24 | #include <klocale.h> | 24 | #include <klocale.h> |
25 | #include <kiconloader.h> | 25 | #include <kiconloader.h> |
26 | #include <qframe.h> | 26 | #include <qframe.h> |
27 | #include <qpainter.h> | 27 | #include <qpainter.h> |
28 | #include <qdialog.h> | 28 | #include <qdialog.h> |
29 | #include <qtoolbutton.h> | 29 | #include <qtoolbutton.h> |
30 | #include <qfont.h> | 30 | #include <qfont.h> |
31 | #include <qapplication.h> | 31 | #include <qapplication.h> |
32 | #include <qlineedit.h> | 32 | #include <qlineedit.h> |
33 | #include <qvalidator.h> | 33 | #include <qvalidator.h> |
34 | #include <kdebug.h> | 34 | #include <kdebug.h> |
35 | #include <knotifyclient.h> | 35 | #include <knotifyclient.h> |
36 | #include "kdatetbl.h" | 36 | #include "kdatetbl.h" |
37 | #include "kdateedit.h" | 37 | #include "kdateedit.h" |
38 | //#include "kdatepicker.moc" | 38 | //#include "kdatepicker.moc" |
39 | 39 | ||
40 | 40 | ||
41 | KDatePicker::KDatePicker(QWidget *parent, QDate dt, const char *name) | 41 | KDatePicker::KDatePicker(QWidget *parent, QDate dt, const char *name) |
42 | : QFrame(parent,name), | 42 | : QFrame(parent,name), |
43 | yearForward(new QToolButton(this)), | 43 | yearForward(new QToolButton(this)), |
44 | yearBackward(new QToolButton(this)), | 44 | yearBackward(new QToolButton(this)), |
45 | monthForward(new QToolButton(this)), | 45 | monthForward(new QToolButton(this)), |
46 | monthBackward(new QToolButton(this)), | 46 | monthBackward(new QToolButton(this)), |
47 | selectMonth(new QToolButton(this)), | 47 | selectMonth(new QToolButton(this)), |
48 | selectYear(new QToolButton(this)), | 48 | selectYear(new QToolButton(this)), |
49 | //line(new QLineEdit(this)), | 49 | //line(new QLineEdit(this)), |
50 | val(new KDateValidator(this)) | 50 | val(new KDateValidator(this)) |
51 | //table(new KDateTable(this)), | 51 | //table(new KDateTable(this)), |
52 | //fontsize(1) | 52 | //fontsize(1) |
53 | { | 53 | { |
54 | // ----- | 54 | // ----- |
55 | int size = 12; | 55 | int size = 12; |
56 | if ( QApplication::desktop()->width() >= 480 ) | 56 | if ( QApplication::desktop()->width() >= 480 ) |
57 | size = 18; | 57 | size = 18; |
58 | fontsize = size; | 58 | fontsize = size; |
59 | setFont ( QFont("helvetica",size) ); | 59 | setFont ( QFont("helvetica",size) ); |
60 | table = new KDateTable(this); | 60 | table = new KDateTable(this); |
61 | setFontSize(size); | 61 | setFontSize(size); |
62 | //line->setValidator(val); | 62 | //line->setValidator(val); |
63 | lineDate = new KDateEdit( this, "dateediipicker", true ); | 63 | lineDate = new KDateEdit( this, "dateediipicker", true ); |
64 | yearForward->setPixmap(SmallIcon("2rightarrowB")); | 64 | yearForward->setPixmap(SmallIcon("2rightarrowB")); |
65 | yearBackward->setPixmap(SmallIcon("2leftarrowB")); | 65 | yearBackward->setPixmap(SmallIcon("2leftarrowB")); |
66 | monthForward->setPixmap(SmallIcon("1rightarrowB")); | 66 | monthForward->setPixmap(SmallIcon("1rightarrowB")); |
67 | monthBackward->setPixmap(SmallIcon("1leftarrowB")); | 67 | monthBackward->setPixmap(SmallIcon("1leftarrowB")); |
68 | |||
69 | setDate(dt); // set button texts | 68 | setDate(dt); // set button texts |
70 | connect(table, SIGNAL(dateChanged(QDate)), SLOT(dateChangedSlot(QDate))); | 69 | connect(table, SIGNAL(dateChanged(QDate)), SLOT(dateChangedSlot(QDate))); |
71 | connect(table, SIGNAL(tableClicked()), SLOT(tableClickedSlot())); | 70 | connect(table, SIGNAL(tableClicked()), SLOT(tableClickedSlot())); |
72 | connect(monthForward, SIGNAL(clicked()), SLOT(monthForwardClicked())); | 71 | connect(monthForward, SIGNAL(clicked()), SLOT(monthForwardClicked())); |
73 | connect(monthBackward, SIGNAL(clicked()), SLOT(monthBackwardClicked())); | 72 | connect(monthBackward, SIGNAL(clicked()), SLOT(monthBackwardClicked())); |
74 | connect(yearForward, SIGNAL(clicked()), SLOT(yearForwardClicked())); | 73 | connect(yearForward, SIGNAL(clicked()), SLOT(yearForwardClicked())); |
75 | connect(yearBackward, SIGNAL(clicked()), SLOT(yearBackwardClicked())); | 74 | connect(yearBackward, SIGNAL(clicked()), SLOT(yearBackwardClicked())); |
76 | connect(selectMonth, SIGNAL(clicked()), SLOT(selectMonthClicked())); | 75 | connect(selectMonth, SIGNAL(clicked()), SLOT(selectMonthClicked())); |
77 | connect(selectYear, SIGNAL(clicked()), SLOT(selectYearClicked())); | 76 | connect(selectYear, SIGNAL(clicked()), SLOT(selectYearClicked())); |
78 | //connect(line, SIGNAL(returnPressed()), SLOT(lineEnterPressed())); | 77 | //connect(line, SIGNAL(returnPressed()), SLOT(lineEnterPressed())); |
79 | connect(lineDate, SIGNAL(dateChanged(QDate)), SLOT(slotSetDate(QDate))); | 78 | connect(lineDate, SIGNAL(dateChanged(QDate)), SLOT(slotSetDate(QDate))); |
80 | connect(lineDate, SIGNAL(returnPressed()), SLOT(lineEnterPressed())); | 79 | connect(lineDate, SIGNAL(returnPressed()), SLOT(lineEnterPressed())); |
81 | table->setFocus(); | 80 | table->setFocus(); |
82 | 81 | ||
83 | } | 82 | } |
84 | 83 | ||
85 | KDatePicker::~KDatePicker() | 84 | KDatePicker::~KDatePicker() |
86 | { | 85 | { |
87 | } | 86 | } |
88 | 87 | ||
89 | void | 88 | void |
90 | KDatePicker::resizeEvent(QResizeEvent*) | 89 | KDatePicker::resizeEvent(QResizeEvent*) |
91 | { | 90 | { |
92 | QWidget *buttons[] = { | 91 | QWidget *buttons[] = { |
93 | yearBackward, | 92 | yearBackward, |
94 | monthBackward, | 93 | monthBackward, |
95 | selectMonth, | 94 | selectMonth, |
96 | selectYear, | 95 | selectYear, |
97 | monthForward, | 96 | monthForward, |
98 | yearForward }; | 97 | yearForward }; |
99 | const int NoOfButtons=sizeof(buttons)/sizeof(buttons[0]); | 98 | const int NoOfButtons=sizeof(buttons)/sizeof(buttons[0]); |
100 | QSize sizes[NoOfButtons]; | 99 | QSize sizes[NoOfButtons]; |
101 | int buttonHeight=0; | 100 | int buttonHeight=0; |
102 | int count; | 101 | int count; |
103 | int w; | 102 | int w; |
104 | int x=0; | 103 | int x=0; |
105 | // ----- calculate button row height: | 104 | // ----- calculate button row height: |
106 | for(count=0; count<NoOfButtons; ++count) { | 105 | for(count=0; count<NoOfButtons; ++count) { |
107 | int xS = buttons[count]->sizeHint().width(); | 106 | int xS = buttons[count]->sizeHint().width(); |
108 | int yS = buttons[count]->sizeHint().height(); | 107 | int yS = buttons[count]->sizeHint().height(); |
109 | sizes[count]=QSize ( xS+10, yS ); | 108 | if ( QApplication::desktop()->width() < 320 ) |
109 | sizes[count]=QSize ( xS+4, yS ); | ||
110 | else | ||
111 | sizes[count]=QSize ( xS+10, yS ); | ||
112 | |||
110 | buttonHeight=QMAX(buttonHeight, sizes[count].height()); | 113 | buttonHeight=QMAX(buttonHeight, sizes[count].height()); |
111 | } | 114 | } |
112 | buttonHeight += 10; | 115 | buttonHeight += 10; |
113 | // ----- calculate size of the month button: | 116 | // ----- calculate size of the month button: |
114 | w=0; | 117 | w=0; |
115 | for(count=0; count<NoOfButtons; ++count) { | 118 | for(count=0; count<NoOfButtons; ++count) { |
116 | if(buttons[count]!=selectMonth) | 119 | if(buttons[count]!=selectMonth) |
117 | { | 120 | { |
118 | w+=sizes[count].width(); | 121 | w+=sizes[count].width(); |
119 | } else { | 122 | } else { |
120 | x=count; | 123 | x=count; |
121 | } | 124 | } |
122 | } | 125 | } |
123 | sizes[x].setWidth(width()-w); // stretch the month button | 126 | sizes[x].setWidth(width()-w); // stretch the month button |
124 | // ----- place the buttons: | 127 | // ----- place the buttons: |
125 | x=0; | 128 | x=0; |
126 | for(count=0; count<NoOfButtons; ++count) | 129 | for(count=0; count<NoOfButtons; ++count) |
127 | { | 130 | { |
128 | w=sizes[count].width(); | 131 | w=sizes[count].width(); |
129 | buttons[count]->setGeometry(x, 0, w, buttonHeight); | 132 | buttons[count]->setGeometry(x, 0, w, buttonHeight); |
130 | x+=w; | 133 | x+=w; |
131 | } | 134 | } |
132 | // ----- place the line edit for direct input: | 135 | // ----- place the line edit for direct input: |
133 | sizes[0]=lineDate->sizeHint(); | 136 | sizes[0]=lineDate->sizeHint(); |
134 | //line->setGeometry(0, height()-sizes[0].height(), width(), sizes[0].height()); | 137 | //line->setGeometry(0, height()-sizes[0].height(), width(), sizes[0].height()); |
135 | lineDate->setGeometry(0, height()-sizes[0].height(), width(), sizes[0].height()); | 138 | lineDate->setGeometry(0, height()-sizes[0].height(), width(), sizes[0].height()); |
136 | // ----- adjust the table: | 139 | // ----- adjust the table: |
137 | table->setGeometry(0, buttonHeight, width(), | 140 | table->setGeometry(0, buttonHeight, width(), |
138 | height()-buttonHeight-sizes[0].height()); | 141 | height()-buttonHeight-sizes[0].height()); |
139 | } | 142 | } |
140 | 143 | ||
141 | void | 144 | void |
142 | KDatePicker::dateChangedSlot(QDate date) | 145 | KDatePicker::dateChangedSlot(QDate date) |
143 | { | 146 | { |
144 | lineDate->setDate( date );//(KGlobal::locale()->formatDate(date, true)); | 147 | lineDate->setDate( date );//(KGlobal::locale()->formatDate(date, true)); |
145 | //line->setText(KGlobal::locale()->formatDate(date, true)); | 148 | //line->setText(KGlobal::locale()->formatDate(date, true)); |
146 | emit(dateChanged(date)); | 149 | emit(dateChanged(date)); |
147 | } | 150 | } |
148 | 151 | ||
149 | void | 152 | void |
150 | KDatePicker::tableClickedSlot() | 153 | KDatePicker::tableClickedSlot() |
151 | { | 154 | { |
152 | 155 | ||
153 | emit(dateSelected(table->getDate())); | 156 | emit(dateSelected(table->getDate())); |
154 | emit(tableClicked()); | 157 | emit(tableClicked()); |
155 | } | 158 | } |
156 | 159 | ||
157 | const QDate& | 160 | const QDate& |