author | Michael Krelin <hacker@klever.net> | 2007-07-04 11:23:42 (UTC) |
---|---|---|
committer | Michael Krelin <hacker@klever.net> | 2007-07-04 11:23:42 (UTC) |
commit | a08aff328d4393031d5ba7d622c2b05705a89d73 (patch) (unidiff) | |
tree | 8ee90d686081c52e7c69b5ce946e9b1a7d690001 /korganizer/journalentry.cpp | |
parent | 11edc920afe4f274c0964436633aa632c8288a40 (diff) | |
download | kdepimpi-a08aff328d4393031d5ba7d622c2b05705a89d73.zip kdepimpi-a08aff328d4393031d5ba7d622c2b05705a89d73.tar.gz kdepimpi-a08aff328d4393031d5ba7d622c2b05705a89d73.tar.bz2 |
initial public commit of qt4 portp1
-rw-r--r-- | korganizer/journalentry.cpp | 39 |
1 files changed, 23 insertions, 16 deletions
diff --git a/korganizer/journalentry.cpp b/korganizer/journalentry.cpp index 5269af7..2814c61 100644 --- a/korganizer/journalentry.cpp +++ b/korganizer/journalentry.cpp | |||
@@ -13,77 +13,84 @@ | |||
13 | GNU General Public License for more details. | 13 | GNU General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU General Public License | 15 | You should have received a copy of the GNU General Public License |
16 | along with this program; if not, write to the Free Software | 16 | along with this program; if not, write to the Free Software |
17 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | 17 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
18 | 18 | ||
19 | As a special exception, permission is given to link this program | 19 | As a special exception, permission is given to link this program |
20 | with any edition of Qt, and distribute the resulting executable, | 20 | with any edition of Qt, and distribute the resulting executable, |
21 | without including the source code for Qt in the source distribution. | 21 | without including the source code for Qt in the source distribution. |
22 | */ | 22 | */ |
23 | 23 | ||
24 | // | 24 | // |
25 | // Journal Entry | 25 | // Journal Entry |
26 | 26 | ||
27 | #include <qlabel.h> | 27 | #include <qlabel.h> |
28 | #include <qlayout.h> | 28 | #include <qlayout.h> |
29 | #include <qvbox.h> | 29 | #include <q3vbox.h> |
30 | #include <qfile.h> | 30 | #include <qfile.h> |
31 | #include <qdir.h> | 31 | #include <qdir.h> |
32 | #include <qtextstream.h> | 32 | #include <q3textstream.h> |
33 | #include <qtextcodec.h> | 33 | #include <qtextcodec.h> |
34 | #include <qpixmap.h> | 34 | #include <qpixmap.h> |
35 | #include <qpushbutton.h> | 35 | #include <qpushbutton.h> |
36 | #include <qapplication.h> | 36 | #include <qapplication.h> |
37 | #include <QDesktopWidget> | ||
38 | //Added by qt3to4: | ||
39 | #include <QResizeEvent> | ||
40 | #include <Q3Frame> | ||
41 | #include <QKeyEvent> | ||
42 | #include <QEvent> | ||
43 | #include <Q3VBoxLayout> | ||
37 | 44 | ||
38 | #include <kdebug.h> | 45 | #include <kdebug.h> |
39 | #include <kglobal.h> | 46 | #include <kglobal.h> |
40 | #include <klocale.h> | 47 | #include <klocale.h> |
41 | #include <ktextedit.h> | 48 | #include <ktextedit.h> |
42 | #include <kfiledialog.h> | 49 | #include <kfiledialog.h> |
43 | #include <kmessagebox.h> | 50 | #include <kmessagebox.h> |
44 | #include "koprefs.h" | 51 | #include "koprefs.h" |
45 | #include <klineedit.h> | 52 | #include <klineedit.h> |
46 | #include <kdialog.h> | 53 | #include <kdialog.h> |
47 | #include "kolocationbox.h" | 54 | #include "kolocationbox.h" |
48 | 55 | ||
49 | #include <libkcal/journal.h> | 56 | #include <libkcal/journal.h> |
50 | #include <libkcal/calendarresources.h> | 57 | #include <libkcal/calendarresources.h> |
51 | #include <libkcal/resourcecalendar.h> | 58 | #include <libkcal/resourcecalendar.h> |
52 | #include <kresources/resourceselectdialog.h> | 59 | #include <kresources/resourceselectdialog.h> |
53 | 60 | ||
54 | #include "journalentry.h" | 61 | #include "journalentry.h" |
55 | //#include "journalentry.moc" | 62 | //#include "journalentry.moc" |
56 | #ifndef DESKTOP_VERSION | 63 | #ifndef DESKTOP_VERSION |
57 | #include <qpe/qpeapplication.h> | 64 | #include <qpe/qpeapplication.h> |
58 | #endif | 65 | #endif |
59 | JournalEntry::JournalEntry(Calendar *calendar,QWidget *parent) : | 66 | JournalEntry::JournalEntry(Calendar *calendar,QWidget *parent) : |
60 | QFrame(parent) | 67 | Q3Frame(parent) |
61 | { | 68 | { |
62 | 69 | ||
63 | int fac = 5; | 70 | int fac = 5; |
64 | heiHint = QApplication::desktop()->height(); | 71 | heiHint = QApplication::desktop()->height(); |
65 | if ( heiHint > 800 ) | 72 | if ( heiHint > 800 ) |
66 | fac += 2; | 73 | fac += 2; |
67 | heiHint = heiHint / fac; | 74 | heiHint = heiHint / fac; |
68 | 75 | ||
69 | showOnlyMode = false; | 76 | showOnlyMode = false; |
70 | mCalendar = calendar; | 77 | mCalendar = calendar; |
71 | mJournal = 0; | 78 | mJournal = 0; |
72 | visibleMode = true; | 79 | visibleMode = true; |
73 | QHBox * vb = new QHBox ( this ); | 80 | Q3HBox * vb = new Q3HBox ( this ); |
74 | QPixmap iconp; | 81 | QPixmap iconp; |
75 | vb->setMargin ( KDialog::marginHint()-1 ); | 82 | vb->setMargin ( KDialog::marginHint()-1 ); |
76 | QPushButton * toggleJournal = new QPushButton( vb ); | 83 | QPushButton * toggleJournal = new QPushButton( vb ); |
77 | iconp = SmallIcon("1updownarrow"); | 84 | iconp = SmallIcon("1updownarrow"); |
78 | toggleJournal->setPixmap (iconp ) ; | 85 | toggleJournal->setPixmap (iconp ) ; |
79 | QLabel* textLabel = new QLabel(" "+i18n("Title: "),vb); | 86 | QLabel* textLabel = new QLabel(" "+i18n("Title: "),vb); |
80 | mTitle = new KOLocationBox(TRUE, vb, 30); | 87 | mTitle = new KOLocationBox(TRUE, vb, 30); |
81 | mTitle->setSizePolicy( QSizePolicy( QSizePolicy::Preferred ,QSizePolicy::Fixed ,FALSE) ); | 88 | mTitle->setSizePolicy( QSizePolicy( QSizePolicy::Preferred ,QSizePolicy::Fixed ,FALSE) ); |
82 | mCalendarBox = new QComboBox(vb); | 89 | mCalendarBox = new QComboBox(vb); |
83 | mCalendarBox->setSizePolicy( QSizePolicy( QSizePolicy::Preferred ,QSizePolicy::Fixed ,FALSE) ); | 90 | mCalendarBox->setSizePolicy( QSizePolicy( QSizePolicy::Preferred ,QSizePolicy::Fixed ,FALSE) ); |
84 | #ifndef DESKTOP_VERSION | 91 | #ifndef DESKTOP_VERSION |
85 | mTitle->setSizeLimit( 8 ); | 92 | mTitle->setSizeLimit( 8 ); |
86 | mCalendarBox->setSizeLimit( 8 ); | 93 | mCalendarBox->setSizeLimit( 8 ); |
87 | #endif | 94 | #endif |
88 | vb->setStretchFactor ( mTitle, 8 ); | 95 | vb->setStretchFactor ( mTitle, 8 ); |
89 | int limit = 3; | 96 | int limit = 3; |
@@ -116,117 +123,117 @@ JournalEntry::JournalEntry(Calendar *calendar,QWidget *parent) : | |||
116 | mEditor = new KTextEdit(this); | 123 | mEditor = new KTextEdit(this); |
117 | #ifndef DESKTOP_VERSION | 124 | #ifndef DESKTOP_VERSION |
118 | QPEApplication::setStylusOperation( mEditor, QPEApplication::RightOnHold ); | 125 | QPEApplication::setStylusOperation( mEditor, QPEApplication::RightOnHold ); |
119 | #endif | 126 | #endif |
120 | mMaxWidDiff = 3*size - 2*frameWidth() - textLabel->sizeHint().width(); | 127 | mMaxWidDiff = 3*size - 2*frameWidth() - textLabel->sizeHint().width(); |
121 | mDeskWid = QApplication::desktop()->width(); | 128 | mDeskWid = QApplication::desktop()->width(); |
122 | int maxwid = mDeskWid - mMaxWidDiff; | 129 | int maxwid = mDeskWid - mMaxWidDiff; |
123 | if ( QApplication::desktop()->width() < 640 ) { | 130 | if ( QApplication::desktop()->width() < 640 ) { |
124 | mTitle->setMaximumWidth( maxwid/2 +20 ); | 131 | mTitle->setMaximumWidth( maxwid/2 +20 ); |
125 | mCalendarBox->setMaximumWidth( maxwid/2 -20); | 132 | mCalendarBox->setMaximumWidth( maxwid/2 -20); |
126 | } else { | 133 | } else { |
127 | mTitle->setMaximumWidth( (maxwid/4)*3); | 134 | mTitle->setMaximumWidth( (maxwid/4)*3); |
128 | mCalendarBox->setMaximumWidth( maxwid/2 ); | 135 | mCalendarBox->setMaximumWidth( maxwid/2 ); |
129 | } | 136 | } |
130 | //mCalendarBox->setMaximumWidth( maxwid/2 -20 ); | 137 | //mCalendarBox->setMaximumWidth( maxwid/2 -20 ); |
131 | mEditor->setWordWrap( KTextEdit::WidgetWidth ); | 138 | mEditor->setWordWrap( KTextEdit::WidgetWidth ); |
132 | QBoxLayout *topLayout = new QVBoxLayout(this); | 139 | Q3BoxLayout *topLayout = new Q3VBoxLayout(this); |
133 | topLayout->addWidget(vb); | 140 | topLayout->addWidget(vb); |
134 | topLayout->addWidget(mEditor); | 141 | topLayout->addWidget(mEditor); |
135 | mEditor->installEventFilter(this); | 142 | mEditor->installEventFilter(this); |
136 | installEventFilter(this); | 143 | installEventFilter(this); |
137 | mTitle->installEventFilter(this); | 144 | mTitle->installEventFilter(this); |
138 | setFocusPolicy (QWidget::NoFocus); | 145 | setFocusPolicy (Qt::NoFocus); |
139 | 146 | ||
140 | connect( saveTemplate, SIGNAL( clicked() ), this , SLOT( slotSaveTemplate() ) ); | 147 | connect( saveTemplate, SIGNAL( clicked() ), this , SLOT( slotSaveTemplate() ) ); |
141 | connect( loadTemplate, SIGNAL( clicked() ), this , SLOT( slotLoadTemplate() ) ); | 148 | connect( loadTemplate, SIGNAL( clicked() ), this , SLOT( slotLoadTemplate() ) ); |
142 | connect( toggleJournal, SIGNAL( clicked() ), this , SLOT( toggleShowJournal() ) ); | 149 | connect( toggleJournal, SIGNAL( clicked() ), this , SLOT( toggleShowJournal() ) ); |
143 | mTitle->load( KOLocationBox::SUMMARYJOURNAL ); | 150 | mTitle->load( KOLocationBox::SUMMARYJOURNAL ); |
144 | mTitle->lineEdit ()->setText(""); | 151 | mTitle->lineEdit ()->setText(""); |
145 | } | 152 | } |
146 | 153 | ||
147 | JournalEntry::~JournalEntry() | 154 | JournalEntry::~JournalEntry() |
148 | { | 155 | { |
149 | //qDebug("JournalEntry::~JournalEntry() "); | 156 | //qDebug("JournalEntry::~JournalEntry() "); |
150 | } | 157 | } |
151 | void JournalEntry::resizeEvent(QResizeEvent* e ) | 158 | void JournalEntry::resizeEvent(QResizeEvent* e ) |
152 | { | 159 | { |
153 | #ifndef DESKTOP_VERSION | 160 | #ifndef DESKTOP_VERSION |
154 | 161 | ||
155 | if ( mDeskWid != QApplication::desktop()->width() ) { | 162 | if ( mDeskWid != QApplication::desktop()->width() ) { |
156 | mDeskWid == QApplication::desktop()->width(); | 163 | mDeskWid == QApplication::desktop()->width(); |
157 | int maxwid = mDeskWid - mMaxWidDiff; | 164 | int maxwid = mDeskWid - mMaxWidDiff; |
158 | if ( QApplication::desktop()->width() < 640 ) { | 165 | if ( QApplication::desktop()->width() < 640 ) { |
159 | mTitle->setMaximumWidth( maxwid/2 +20 ); | 166 | mTitle->setMaximumWidth( maxwid/2 +20 ); |
160 | mCalendarBox->setMaximumWidth( maxwid/2 -20); | 167 | mCalendarBox->setMaximumWidth( maxwid/2 -20); |
161 | } | 168 | } |
162 | else { | 169 | else { |
163 | mTitle->setMaximumWidth( (maxwid/4)*3); | 170 | mTitle->setMaximumWidth( (maxwid/4)*3); |
164 | mCalendarBox->setMaximumWidth( maxwid/2 ); | 171 | mCalendarBox->setMaximumWidth( maxwid/2 ); |
165 | } | 172 | } |
166 | //mCalendarBox->setMaximumWidth( maxwid/2 -20 ); | 173 | //mCalendarBox->setMaximumWidth( maxwid/2 -20 ); |
167 | } | 174 | } |
168 | //setMaximumWidth( QApplication::desktop()->width() ); | 175 | //setMaximumWidth( QApplication::desktop()->width() ); |
169 | //qDebug("MAXXX %d ", QApplication::desktop()->width()); | 176 | //qDebug("MAXXX %d ", QApplication::desktop()->width()); |
170 | #endif | 177 | #endif |
171 | QFrame::resizeEvent( e ); | 178 | Q3Frame::resizeEvent( e ); |
172 | } | 179 | } |
173 | QSize JournalEntry::sizeHint() const | 180 | QSize JournalEntry::sizeHint() const |
174 | { | 181 | { |
175 | return QSize ( 240, heiHint ); | 182 | return QSize ( 240, heiHint ); |
176 | } | 183 | } |
177 | void JournalEntry::slotSaveTemplate() | 184 | void JournalEntry::slotSaveTemplate() |
178 | { | 185 | { |
179 | QString fileName =locateLocal( "templates", "journals" ); | 186 | QString fileName =locateLocal( "templates", "journals" ); |
180 | QDir t_dir; | 187 | QDir t_dir; |
181 | if ( !t_dir.exists(fileName) ) | 188 | if ( !t_dir.exists(fileName) ) |
182 | t_dir.mkdir ( fileName ); | 189 | t_dir.mkdir ( fileName ); |
183 | fileName += "/journal"; | 190 | fileName += "/journal"; |
184 | fileName = KFileDialog::getSaveFileName( fileName , i18n("Save as Journal template"), this ); | 191 | fileName = KFileDialog::getSaveFileName( fileName , i18n("Save as Journal template"), this ); |
185 | if ( fileName.length() == 0 ) | 192 | if ( fileName.length() == 0 ) |
186 | return; | 193 | return; |
187 | 194 | ||
188 | QFile fileIn( fileName ); | 195 | QFile fileIn( fileName ); |
189 | if (!fileIn.open( IO_WriteOnly ) ) { | 196 | if (!fileIn.open( QIODevice::WriteOnly ) ) { |
190 | KMessageBox::error( this, i18n("Error saving template file\n '%1'.") | 197 | KMessageBox::error( this, i18n("Error saving template file\n '%1'.") |
191 | .arg( fileName ) ); | 198 | .arg( fileName ) ); |
192 | return; | 199 | return; |
193 | } | 200 | } |
194 | // QString text; | 201 | // QString text; |
195 | QTextStream tsIn( &fileIn ); | 202 | Q3TextStream tsIn( &fileIn ); |
196 | tsIn.setCodec( QTextCodec::codecForName("utf8") ); | 203 | tsIn.setCodec( QTextCodec::codecForName("utf8") ); |
197 | tsIn << mEditor->text(); | 204 | tsIn << mEditor->text(); |
198 | fileIn.close(); | 205 | fileIn.close(); |
199 | } | 206 | } |
200 | void JournalEntry::slotLoadTemplate() | 207 | void JournalEntry::slotLoadTemplate() |
201 | { | 208 | { |
202 | QString fileName =locateLocal( "templates", "journals" ); | 209 | QString fileName =locateLocal( "templates", "journals" ); |
203 | QDir t_dir; | 210 | QDir t_dir; |
204 | if ( !t_dir.exists(fileName) ) | 211 | if ( !t_dir.exists(fileName) ) |
205 | t_dir.mkdir ( fileName ); | 212 | t_dir.mkdir ( fileName ); |
206 | fileName += "/journal"; | 213 | fileName += "/journal"; |
207 | fileName = KFileDialog::getOpenFileName( fileName , i18n("Insert Journal template"), this ); | 214 | fileName = KFileDialog::getOpenFileName( fileName , i18n("Insert Journal template"), this ); |
208 | if ( fileName.length() == 0 ) | 215 | if ( fileName.length() == 0 ) |
209 | return; | 216 | return; |
210 | QFile fileIn( fileName ); | 217 | QFile fileIn( fileName ); |
211 | if (!fileIn.open( IO_ReadOnly ) ) { | 218 | if (!fileIn.open( QIODevice::ReadOnly ) ) { |
212 | KMessageBox::error( this, i18n("Error loading template file\n '%1'.") | 219 | KMessageBox::error( this, i18n("Error loading template file\n '%1'.") |
213 | .arg( fileName ) ); | 220 | .arg( fileName ) ); |
214 | return; | 221 | return; |
215 | } | 222 | } |
216 | QTextStream tsIn( &fileIn ); | 223 | Q3TextStream tsIn( &fileIn ); |
217 | tsIn.setCodec( QTextCodec::codecForName("utf8") ); | 224 | tsIn.setCodec( QTextCodec::codecForName("utf8") ); |
218 | QString text = tsIn.read(); | 225 | QString text = tsIn.read(); |
219 | fileIn.close(); | 226 | fileIn.close(); |
220 | int line, col; | 227 | int line, col; |
221 | mEditor->getCursorPosition (& line, & col ); | 228 | mEditor->getCursorPosition (& line, & col ); |
222 | mEditor-> insertAt ( text, line, col, true ); | 229 | mEditor-> insertAt ( text, line, col, true ); |
223 | //mEditor->setIgnoreMark( true ); | 230 | //mEditor->setIgnoreMark( true ); |
224 | } | 231 | } |
225 | void JournalEntry::setDate(const QDate &date) | 232 | void JournalEntry::setDate(const QDate &date) |
226 | { | 233 | { |
227 | showOnlyMode = false; | 234 | showOnlyMode = false; |
228 | writeJournal(); | 235 | writeJournal(); |
229 | mDate = date; | 236 | mDate = date; |
230 | fillCalendar( mCalendar->defaultCalendar() ); | 237 | fillCalendar( mCalendar->defaultCalendar() ); |
231 | } | 238 | } |
232 | void JournalEntry::fillCalendar( int setToID ) | 239 | void JournalEntry::fillCalendar( int setToID ) |
@@ -303,52 +310,52 @@ Journal *JournalEntry::journal() const | |||
303 | return mJournal; | 310 | return mJournal; |
304 | } | 311 | } |
305 | 312 | ||
306 | 313 | ||
307 | void JournalEntry::clear() | 314 | void JournalEntry::clear() |
308 | { | 315 | { |
309 | mJournal = 0; | 316 | mJournal = 0; |
310 | mEditor->setText(""); | 317 | mEditor->setText(""); |
311 | mTitle->load( KOLocationBox::SUMMARYJOURNAL ); | 318 | mTitle->load( KOLocationBox::SUMMARYJOURNAL ); |
312 | mTitle->lineEdit ()->setText(""); | 319 | mTitle->lineEdit ()->setText(""); |
313 | } | 320 | } |
314 | 321 | ||
315 | bool JournalEntry::eventFilter( QObject *o, QEvent *e ) | 322 | bool JournalEntry::eventFilter( QObject *o, QEvent *e ) |
316 | { | 323 | { |
317 | // kdDebug() << "JournalEntry::event received " << e->type() << endl; | 324 | // kdDebug() << "JournalEntry::event received " << e->type() << endl; |
318 | if ( isVisible() ) { | 325 | if ( isVisible() ) { |
319 | mEditor->setFocusPolicy (QWidget::StrongFocus); | 326 | mEditor->setFocusPolicy (Qt::StrongFocus); |
320 | mTitle->setFocusPolicy (QWidget::StrongFocus); | 327 | mTitle->setFocusPolicy (Qt::StrongFocus); |
321 | } else { | 328 | } else { |
322 | mEditor->setFocusPolicy (QWidget::NoFocus); | 329 | mEditor->setFocusPolicy (Qt::NoFocus); |
323 | mTitle->setFocusPolicy (QWidget::NoFocus); | 330 | mTitle->setFocusPolicy (Qt::NoFocus); |
324 | } | 331 | } |
325 | if ( e->type() == QEvent::FocusOut ) { | 332 | if ( e->type() == QEvent::FocusOut ) { |
326 | writeJournal(); | 333 | writeJournal(); |
327 | } | 334 | } |
328 | if ( e->type() == QEvent::KeyPress ) { | 335 | if ( e->type() == QEvent::KeyPress ) { |
329 | QKeyEvent * k = (QKeyEvent *) e; | 336 | QKeyEvent * k = (QKeyEvent *) e; |
330 | if ( !isVisible() ) | 337 | if ( !isVisible() ) |
331 | return true; | 338 | return true; |
332 | if ( k->state() == Qt::ControlButton ) { | 339 | if ( k->state() == Qt::ControlButton ) { |
333 | k->ignore(); | 340 | k->ignore(); |
334 | //return true; | 341 | //return true; |
335 | } | 342 | } |
336 | } | 343 | } |
337 | 344 | ||
338 | return QFrame::eventFilter( o, e ); // standard event processing | 345 | return Q3Frame::eventFilter( o, e ); // standard event processing |
339 | } | 346 | } |
340 | 347 | ||
341 | void JournalEntry::writeJournal() | 348 | void JournalEntry::writeJournal() |
342 | { | 349 | { |
343 | if ( !visibleMode ) return; | 350 | if ( !visibleMode ) return; |
344 | if ( !mTitle->isEnabled() ) return; | 351 | if ( !mTitle->isEnabled() ) return; |
345 | if (mEditor->text().isEmpty() && mTitle->currentText().isEmpty()) { | 352 | if (mEditor->text().isEmpty() && mTitle->currentText().isEmpty()) { |
346 | if ( mJournal ) { | 353 | if ( mJournal ) { |
347 | Journal* j = mJournal; | 354 | Journal* j = mJournal; |
348 | mJournal = 0; | 355 | mJournal = 0; |
349 | bool conf = KOPrefs::instance()->mConfirm; | 356 | bool conf = KOPrefs::instance()->mConfirm; |
350 | KOPrefs::instance()->mConfirm = false; | 357 | KOPrefs::instance()->mConfirm = false; |
351 | emit deleteJournal(j); | 358 | emit deleteJournal(j); |
352 | KOPrefs::instance()->mConfirm = conf; | 359 | KOPrefs::instance()->mConfirm = conf; |
353 | } | 360 | } |
354 | return; | 361 | return; |