summaryrefslogtreecommitdiff
authorchicken <chicken>2004-03-01 19:44:43 (UTC)
committer chicken <chicken>2004-03-01 19:44:43 (UTC)
commit18ea562480a63f504f4dc8e3f46c1db9d2cd6276 (patch) (unidiff)
treede22b70f1da5adeb072f0c30517bd92e9c7a839b
parent8ac7ec5e055dacd8c92d5a28336257cfe3e716e5 (diff)
downloadopie-18ea562480a63f504f4dc8e3f46c1db9d2cd6276.zip
opie-18ea562480a63f504f4dc8e3f46c1db9d2cd6276.tar.gz
opie-18ea562480a63f504f4dc8e3f46c1db9d2cd6276.tar.bz2
fix includes
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/opie-write/qcomplextext.cpp3
-rw-r--r--noncore/apps/opie-write/qrichtext.cpp15
-rw-r--r--noncore/apps/opie-write/qstylesheet.cpp2
-rw-r--r--noncore/apps/opie-write/qtextedit.cpp20
-rw-r--r--noncore/apps/oxygen/calcdlgui.cpp1
-rw-r--r--noncore/apps/oxygen/dataTable.cpp3
-rw-r--r--noncore/apps/oxygen/datawidgetui.cpp5
-rw-r--r--noncore/apps/oxygen/kmolcalc.cpp3
-rw-r--r--noncore/apps/oxygen/oxyframe.cpp2
-rw-r--r--noncore/apps/oxygen/oxygen.cpp2
-rw-r--r--noncore/apps/oxygen/psewidget.cpp2
-rwxr-xr-xnoncore/apps/qashmoney/account.cpp2
-rwxr-xr-xnoncore/apps/qashmoney/accountdisplay.cpp2
-rwxr-xr-xnoncore/apps/qashmoney/budgetdisplay.cpp3
-rwxr-xr-xnoncore/apps/qashmoney/newaccount.cpp3
-rwxr-xr-xnoncore/apps/qashmoney/newtransaction.cpp2
-rwxr-xr-xnoncore/apps/qashmoney/preferencedialogs.cpp1
-rwxr-xr-xnoncore/apps/qashmoney/transactiondisplay.cpp3
-rwxr-xr-xnoncore/apps/qashmoney/transferdialog.cpp2
-rw-r--r--noncore/apps/tableviewer/tableviewer.cpp1
20 files changed, 0 insertions, 77 deletions
diff --git a/noncore/apps/opie-write/qcomplextext.cpp b/noncore/apps/opie-write/qcomplextext.cpp
index e8b94da..473f184 100644
--- a/noncore/apps/opie-write/qcomplextext.cpp
+++ b/noncore/apps/opie-write/qcomplextext.cpp
@@ -1,149 +1,146 @@
1/**************************************************************************** 1/****************************************************************************
2** $Id$ 2** $Id$
3** 3**
4** Implementation of some internal classes 4** Implementation of some internal classes
5** 5**
6** Created : 6** Created :
7** 7**
8** Copyright (C) 2001 Trolltech AS. All rights reserved. 8** Copyright (C) 2001 Trolltech AS. All rights reserved.
9** 9**
10** This file is part of the kernel module of the Qt GUI Toolkit. 10** This file is part of the kernel module of the Qt GUI Toolkit.
11** 11**
12** This file may be distributed under the terms of the Q Public License 12** This file may be distributed under the terms of the Q Public License
13** as defined by Trolltech AS of Norway and appearing in the file 13** as defined by Trolltech AS of Norway and appearing in the file
14** LICENSE.QPL included in the packaging of this file. 14** LICENSE.QPL included in the packaging of this file.
15** 15**
16** This file may be distributed and/or modified under the terms of the 16** This file may be distributed and/or modified under the terms of the
17** GNU General Public License version 2 as published by the Free Software 17** GNU General Public License version 2 as published by the Free Software
18** Foundation and appearing in the file LICENSE.GPL included in the 18** Foundation and appearing in the file LICENSE.GPL included in the
19** packaging of this file. 19** packaging of this file.
20** 20**
21** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition 21** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
22** licenses may use this file in accordance with the Qt Commercial License 22** licenses may use this file in accordance with the Qt Commercial License
23** Agreement provided with the Software. 23** Agreement provided with the Software.
24** 24**
25** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 25** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
26** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 26** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
27** 27**
28** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for 28** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
29** information about Qt Commercial License Agreements. 29** information about Qt Commercial License Agreements.
30** See http://www.trolltech.com/qpl/ for QPL licensing information. 30** See http://www.trolltech.com/qpl/ for QPL licensing information.
31** See http://www.trolltech.com/gpl/ for GPL licensing information. 31** See http://www.trolltech.com/gpl/ for GPL licensing information.
32** 32**
33** Contact info@trolltech.com if any conditions of this licensing are 33** Contact info@trolltech.com if any conditions of this licensing are
34** not clear to you. 34** not clear to you.
35** 35**
36**********************************************************************/ 36**********************************************************************/
37 37
38#include "qcomplextext_p.h"
39 38
40#include "qrichtext_p.h" 39#include "qrichtext_p.h"
41#include "qfontmetrics.h"
42#include "qrect.h"
43 40
44#include <stdlib.h> 41#include <stdlib.h>
45 42
46using namespace Qt3; 43using namespace Qt3;
47 44
48// ----------------------------------------------------- 45// -----------------------------------------------------
49 46
50/* a small helper class used internally to resolve Bidi embedding levels. 47/* a small helper class used internally to resolve Bidi embedding levels.
51 Each line of text caches the embedding level at the start of the line for faster 48 Each line of text caches the embedding level at the start of the line for faster
52 relayouting 49 relayouting
53*/ 50*/
54QBidiContext::QBidiContext( uchar l, QChar::Direction e, QBidiContext *p, bool o ) 51QBidiContext::QBidiContext( uchar l, QChar::Direction e, QBidiContext *p, bool o )
55 : level(l) , override(o), dir(e) 52 : level(l) , override(o), dir(e)
56{ 53{
57 if ( p ) 54 if ( p )
58 p->ref(); 55 p->ref();
59 parent = p; 56 parent = p;
60 count = 0; 57 count = 0;
61} 58}
62 59
63QBidiContext::~QBidiContext() 60QBidiContext::~QBidiContext()
64{ 61{
65 if( parent && parent->deref() ) 62 if( parent && parent->deref() )
66 delete parent; 63 delete parent;
67} 64}
68 65
69/* 66/*
70 Arabic shaping obeys a number of rules according to the joining classes (see Unicode book, section on 67 Arabic shaping obeys a number of rules according to the joining classes (see Unicode book, section on
71 arabic). 68 arabic).
72 69
73 Each unicode char has a joining class (right, dual (left&right), center (joincausing) or transparent). 70 Each unicode char has a joining class (right, dual (left&right), center (joincausing) or transparent).
74 transparent joining is not encoded in QChar::joining(), but applies to all combining marks and format marks. 71 transparent joining is not encoded in QChar::joining(), but applies to all combining marks and format marks.
75 72
76 Right join-causing: dual + center 73 Right join-causing: dual + center
77 Left join-causing: dual + right + center 74 Left join-causing: dual + right + center
78 75
79 Rules are as follows (for a string already in visual order, as we have it here): 76 Rules are as follows (for a string already in visual order, as we have it here):
80 77
81 R1 Transparent characters do not affect joining behaviour. 78 R1 Transparent characters do not affect joining behaviour.
82 R2 A right joining character, that has a right join-causing char on the right will get form XRight 79 R2 A right joining character, that has a right join-causing char on the right will get form XRight
83 (R3 A left joining character, that has a left join-causing char on the left will get form XLeft) 80 (R3 A left joining character, that has a left join-causing char on the left will get form XLeft)
84 Note: the above rule is meaningless, as there are no pure left joining characters defined in Unicode 81 Note: the above rule is meaningless, as there are no pure left joining characters defined in Unicode
85 R4 A dual joining character, that has a left join-causing char on the left and a right join-causing char on 82 R4 A dual joining character, that has a left join-causing char on the left and a right join-causing char on
86 the right will get form XMedial 83 the right will get form XMedial
87 R5 A dual joining character, that has a right join causing char on the right, and no left join causing char on the left 84 R5 A dual joining character, that has a right join causing char on the right, and no left join causing char on the left
88 will get form XRight 85 will get form XRight
89 R6 A dual joining character, that has a left join causing char on the left, and no right join causing char on the right 86 R6 A dual joining character, that has a left join causing char on the left, and no right join causing char on the right
90 will get form XLeft 87 will get form XLeft
91 R7 Otherwise the character will get form XIsolated 88 R7 Otherwise the character will get form XIsolated
92 89
93 Additionally we have to do the minimal ligature support for lam-alef ligatures: 90 Additionally we have to do the minimal ligature support for lam-alef ligatures:
94 91
95 L1 Transparent characters do not affect ligature behaviour. 92 L1 Transparent characters do not affect ligature behaviour.
96 L2 Any sequence of Alef(XRight) + Lam(XMedial) will form the ligature Alef.Lam(XLeft) 93 L2 Any sequence of Alef(XRight) + Lam(XMedial) will form the ligature Alef.Lam(XLeft)
97 L3 Any sequence of Alef(XRight) + Lam(XLeft) will form the ligature Alef.Lam(XIsolated) 94 L3 Any sequence of Alef(XRight) + Lam(XLeft) will form the ligature Alef.Lam(XIsolated)
98 95
99 The two functions defined in this class do shaping in visual and logical order. For logical order just replace right with 96 The two functions defined in this class do shaping in visual and logical order. For logical order just replace right with
100 previous and left with next in the above rules ;-) 97 previous and left with next in the above rules ;-)
101*/ 98*/
102 99
103/* 100/*
104 Two small helper functions for arabic shaping. They get the next shape causing character on either 101 Two small helper functions for arabic shaping. They get the next shape causing character on either
105 side of the char in question. Implements rule R1. 102 side of the char in question. Implements rule R1.
106 103
107 leftChar() returns true if the char to the left is a left join-causing char 104 leftChar() returns true if the char to the left is a left join-causing char
108 rightChar() returns true if the char to the right is a right join-causing char 105 rightChar() returns true if the char to the right is a right join-causing char
109*/ 106*/
110static inline const QChar *prevChar( const QString &str, int pos ) 107static inline const QChar *prevChar( const QString &str, int pos )
111{ 108{
112 //qDebug("leftChar: pos=%d", pos); 109 //qDebug("leftChar: pos=%d", pos);
113 pos--; 110 pos--;
114 const QChar *ch = str.unicode() + pos; 111 const QChar *ch = str.unicode() + pos;
115 while( pos > -1 ) { 112 while( pos > -1 ) {
116 if( !ch->isMark() ) 113 if( !ch->isMark() )
117 return ch; 114 return ch;
118 pos--; 115 pos--;
119 ch--; 116 ch--;
120 } 117 }
121 return &QChar::replacement; 118 return &QChar::replacement;
122} 119}
123 120
124static inline const QChar *nextChar( const QString &str, int pos) 121static inline const QChar *nextChar( const QString &str, int pos)
125{ 122{
126 pos++; 123 pos++;
127 int len = str.length(); 124 int len = str.length();
128 const QChar *ch = str.unicode() + pos; 125 const QChar *ch = str.unicode() + pos;
129 while( pos < len ) { 126 while( pos < len ) {
130 //qDebug("rightChar: %d isLetter=%d, joining=%d", pos, ch.isLetter(), ch.joining()); 127 //qDebug("rightChar: %d isLetter=%d, joining=%d", pos, ch.isLetter(), ch.joining());
131 if( !ch->isMark() ) 128 if( !ch->isMark() )
132 return ch; 129 return ch;
133 // assume it's a transparent char, this might not be 100% correct 130 // assume it's a transparent char, this might not be 100% correct
134 pos++; 131 pos++;
135 ch++; 132 ch++;
136 } 133 }
137 return &QChar::replacement; 134 return &QChar::replacement;
138} 135}
139 136
140static inline bool prevVisualCharJoins( const QString &str, int pos) 137static inline bool prevVisualCharJoins( const QString &str, int pos)
141{ 138{
142 return ( prevChar( str, pos )->joining() != QChar::OtherJoining ); 139 return ( prevChar( str, pos )->joining() != QChar::OtherJoining );
143} 140}
144 141
145static inline bool nextVisualCharJoins( const QString &str, int pos) 142static inline bool nextVisualCharJoins( const QString &str, int pos)
146{ 143{
147 QChar::Joining join = nextChar( str, pos )->joining(); 144 QChar::Joining join = nextChar( str, pos )->joining();
148 return ( join == QChar::Dual || join == QChar::Center ); 145 return ( join == QChar::Dual || join == QChar::Center );
149} 146}
diff --git a/noncore/apps/opie-write/qrichtext.cpp b/noncore/apps/opie-write/qrichtext.cpp
index 3b044c3..b77a0fc 100644
--- a/noncore/apps/opie-write/qrichtext.cpp
+++ b/noncore/apps/opie-write/qrichtext.cpp
@@ -1,825 +1,810 @@
1/**************************************************************************** 1/****************************************************************************
2** $Id$ 2** $Id$
3** 3**
4** Implementation of the internal Qt classes dealing with rich text 4** Implementation of the internal Qt classes dealing with rich text
5** 5**
6** Created : 990101 6** Created : 990101
7** 7**
8** Copyright (C) 1992-2000 Trolltech AS. All rights reserved. 8** Copyright (C) 1992-2000 Trolltech AS. All rights reserved.
9** 9**
10** This file is part of the kernel module of the Qt GUI Toolkit. 10** This file is part of the kernel module of the Qt GUI Toolkit.
11** 11**
12** This file may be distributed under the terms of the Q Public License 12** This file may be distributed under the terms of the Q Public License
13** as defined by Trolltech AS of Norway and appearing in the file 13** as defined by Trolltech AS of Norway and appearing in the file
14** LICENSE.QPL included in the packaging of this file. 14** LICENSE.QPL included in the packaging of this file.
15** 15**
16** This file may be distributed and/or modified under the terms of the 16** This file may be distributed and/or modified under the terms of the
17** GNU General Public License version 2 as published by the Free Software 17** GNU General Public License version 2 as published by the Free Software
18** Foundation and appearing in the file LICENSE.GPL included in the 18** Foundation and appearing in the file LICENSE.GPL included in the
19** packaging of this file. 19** packaging of this file.
20** 20**
21** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition 21** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
22** licenses may use this file in accordance with the Qt Commercial License 22** licenses may use this file in accordance with the Qt Commercial License
23** Agreement provided with the Software. 23** Agreement provided with the Software.
24** 24**
25** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 25** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
26** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 26** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
27** 27**
28** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for 28** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
29** information about Qt Commercial License Agreements. 29** information about Qt Commercial License Agreements.
30** See http://www.trolltech.com/qpl/ for QPL licensing information. 30** See http://www.trolltech.com/qpl/ for QPL licensing information.
31** See http://www.trolltech.com/gpl/ for GPL licensing information. 31** See http://www.trolltech.com/gpl/ for GPL licensing information.
32** 32**
33** Contact info@trolltech.com if any conditions of this licensing are 33** Contact info@trolltech.com if any conditions of this licensing are
34** not clear to you. 34** not clear to you.
35** 35**
36**********************************************************************/ 36**********************************************************************/
37 37
38#include "qrichtext_p.h" 38#include "qrichtext_p.h"
39 39
40#include "qstringlist.h"
41#include "qfont.h"
42#include "qtextstream.h"
43#include "qfile.h"
44#include "qapplication.h"
45#include "qmap.h"
46#include "qfileinfo.h"
47#include "qstylesheet.h"
48#include "qmime.h"
49#include "qimage.h"
50#include "qdragobject.h" 40#include "qdragobject.h"
51#include "qpaintdevicemetrics.h" 41#include "qpaintdevicemetrics.h"
52#include "qpainter.h"
53#include "qdrawutil.h" 42#include "qdrawutil.h"
54#include "qcursor.h"
55#include "qstack.h"
56#include "qstyle.h"
57#include "qcomplextext_p.h"
58#include "qcleanuphandler.h" 43#include "qcleanuphandler.h"
59 44
60#include <stdlib.h> 45#include <stdlib.h>
61 46
62using namespace Qt3; 47using namespace Qt3;
63 48
64static QTextCursor* richTextExportStart = 0; 49static QTextCursor* richTextExportStart = 0;
65static QTextCursor* richTextExportEnd = 0; 50static QTextCursor* richTextExportEnd = 0;
66 51
67static QTextFormatCollection *qFormatCollection = 0; 52static QTextFormatCollection *qFormatCollection = 0;
68 53
69const int border_tolerance = 2; 54const int border_tolerance = 2;
70 55
71#ifdef Q_WS_WIN 56#ifdef Q_WS_WIN
72#include "qt_windows.h" 57#include "qt_windows.h"
73#endif 58#endif
74 59
75#define QChar_linesep QChar(0x2028U) 60#define QChar_linesep QChar(0x2028U)
76 61
77static inline bool is_printer( QPainter *p ) 62static inline bool is_printer( QPainter *p )
78{ 63{
79 if ( !p || !p->device() ) 64 if ( !p || !p->device() )
80 return FALSE; 65 return FALSE;
81 return p->device()->devType() == QInternal::Printer; 66 return p->device()->devType() == QInternal::Printer;
82} 67}
83 68
84static inline int scale( int value, QPainter *painter ) 69static inline int scale( int value, QPainter *painter )
85{ 70{
86 if ( is_printer( painter ) ) { 71 if ( is_printer( painter ) ) {
87 QPaintDeviceMetrics metrics( painter->device() ); 72 QPaintDeviceMetrics metrics( painter->device() );
88#if defined(Q_WS_X11) 73#if defined(Q_WS_X11)
89 value = value * metrics.logicalDpiY() / QPaintDevice::x11AppDpiY(); 74 value = value * metrics.logicalDpiY() / QPaintDevice::x11AppDpiY();
90#elif defined (Q_WS_WIN) 75#elif defined (Q_WS_WIN)
91 HDC hdc = GetDC( 0 ); 76 HDC hdc = GetDC( 0 );
92 int gdc = GetDeviceCaps( hdc, LOGPIXELSY ); 77 int gdc = GetDeviceCaps( hdc, LOGPIXELSY );
93 if ( gdc ) 78 if ( gdc )
94 value = value * metrics.logicalDpiY() / gdc; 79 value = value * metrics.logicalDpiY() / gdc;
95 ReleaseDC( 0, hdc ); 80 ReleaseDC( 0, hdc );
96#elif defined (Q_WS_MAC) 81#elif defined (Q_WS_MAC)
97 value = value * metrics.logicalDpiY() / 75; // ##### FIXME 82 value = value * metrics.logicalDpiY() / 75; // ##### FIXME
98#elif defined (Q_WS_QWS) 83#elif defined (Q_WS_QWS)
99 value = value * metrics.logicalDpiY() / 75; 84 value = value * metrics.logicalDpiY() / 75;
100#endif 85#endif
101 } 86 }
102 return value; 87 return value;
103} 88}
104 89
105// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 90// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
106 91
107void QTextCommandHistory::addCommand( QTextCommand *cmd ) 92void QTextCommandHistory::addCommand( QTextCommand *cmd )
108{ 93{
109 if ( current < (int)history.count() - 1 ) { 94 if ( current < (int)history.count() - 1 ) {
110 QPtrList<QTextCommand> commands; 95 QPtrList<QTextCommand> commands;
111 commands.setAutoDelete( FALSE ); 96 commands.setAutoDelete( FALSE );
112 97
113 for( int i = 0; i <= current; ++i ) { 98 for( int i = 0; i <= current; ++i ) {
114 commands.insert( i, history.at( 0 ) ); 99 commands.insert( i, history.at( 0 ) );
115 history.take( 0 ); 100 history.take( 0 );
116 } 101 }
117 102
118 commands.append( cmd ); 103 commands.append( cmd );
119 history.clear(); 104 history.clear();
120 history = commands; 105 history = commands;
121 history.setAutoDelete( TRUE ); 106 history.setAutoDelete( TRUE );
122 } else { 107 } else {
123 history.append( cmd ); 108 history.append( cmd );
124 } 109 }
125 110
126 if ( (int)history.count() > steps ) 111 if ( (int)history.count() > steps )
127 history.removeFirst(); 112 history.removeFirst();
128 else 113 else
129 ++current; 114 ++current;
130} 115}
131 116
132QTextCursor *QTextCommandHistory::undo( QTextCursor *c ) 117QTextCursor *QTextCommandHistory::undo( QTextCursor *c )
133{ 118{
134 if ( current > -1 ) { 119 if ( current > -1 ) {
135 QTextCursor *c2 = history.at( current )->unexecute( c ); 120 QTextCursor *c2 = history.at( current )->unexecute( c );
136 --current; 121 --current;
137 return c2; 122 return c2;
138 } 123 }
139 return 0; 124 return 0;
140} 125}
141 126
142QTextCursor *QTextCommandHistory::redo( QTextCursor *c ) 127QTextCursor *QTextCommandHistory::redo( QTextCursor *c )
143{ 128{
144 if ( current > -1 ) { 129 if ( current > -1 ) {
145 if ( current < (int)history.count() - 1 ) { 130 if ( current < (int)history.count() - 1 ) {
146 ++current; 131 ++current;
147 return history.at( current )->execute( c ); 132 return history.at( current )->execute( c );
148 } 133 }
149 } else { 134 } else {
150 if ( history.count() > 0 ) { 135 if ( history.count() > 0 ) {
151 ++current; 136 ++current;
152 return history.at( current )->execute( c ); 137 return history.at( current )->execute( c );
153 } 138 }
154 } 139 }
155 return 0; 140 return 0;
156} 141}
157 142
158bool QTextCommandHistory::isUndoAvailable() 143bool QTextCommandHistory::isUndoAvailable()
159{ 144{
160 return current > -1; 145 return current > -1;
161} 146}
162 147
163bool QTextCommandHistory::isRedoAvailable() 148bool QTextCommandHistory::isRedoAvailable()
164{ 149{
165 return current > -1 && current < (int)history.count() - 1 || current == -1 && history.count() > 0; 150 return current > -1 && current < (int)history.count() - 1 || current == -1 && history.count() > 0;
166} 151}
167 152
168// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 153// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
169 154
170QTextDeleteCommand::QTextDeleteCommand( QTextDocument *d, int i, int idx, const QMemArray<QTextStringChar> &str, 155QTextDeleteCommand::QTextDeleteCommand( QTextDocument *d, int i, int idx, const QMemArray<QTextStringChar> &str,
171 const QByteArray& oldStyleInfo ) 156 const QByteArray& oldStyleInfo )
172 : QTextCommand( d ), id( i ), index( idx ), parag( 0 ), text( str ), styleInformation( oldStyleInfo ) 157 : QTextCommand( d ), id( i ), index( idx ), parag( 0 ), text( str ), styleInformation( oldStyleInfo )
173{ 158{
174 for ( int j = 0; j < (int)text.size(); ++j ) { 159 for ( int j = 0; j < (int)text.size(); ++j ) {
175 if ( text[ j ].format() ) 160 if ( text[ j ].format() )
176 text[ j ].format()->addRef(); 161 text[ j ].format()->addRef();
177 } 162 }
178} 163}
179 164
180QTextDeleteCommand::QTextDeleteCommand( QTextParagraph *p, int idx, const QMemArray<QTextStringChar> &str ) 165QTextDeleteCommand::QTextDeleteCommand( QTextParagraph *p, int idx, const QMemArray<QTextStringChar> &str )
181 : QTextCommand( 0 ), id( -1 ), index( idx ), parag( p ), text( str ) 166 : QTextCommand( 0 ), id( -1 ), index( idx ), parag( p ), text( str )
182{ 167{
183 for ( int i = 0; i < (int)text.size(); ++i ) { 168 for ( int i = 0; i < (int)text.size(); ++i ) {
184 if ( text[ i ].format() ) 169 if ( text[ i ].format() )
185 text[ i ].format()->addRef(); 170 text[ i ].format()->addRef();
186 } 171 }
187} 172}
188 173
189QTextDeleteCommand::~QTextDeleteCommand() 174QTextDeleteCommand::~QTextDeleteCommand()
190{ 175{
191 for ( int i = 0; i < (int)text.size(); ++i ) { 176 for ( int i = 0; i < (int)text.size(); ++i ) {
192 if ( text[ i ].format() ) 177 if ( text[ i ].format() )
193 text[ i ].format()->removeRef(); 178 text[ i ].format()->removeRef();
194 } 179 }
195 text.resize( 0 ); 180 text.resize( 0 );
196} 181}
197 182
198QTextCursor *QTextDeleteCommand::execute( QTextCursor *c ) 183QTextCursor *QTextDeleteCommand::execute( QTextCursor *c )
199{ 184{
200 QTextParagraph *s = doc ? doc->paragAt( id ) : parag; 185 QTextParagraph *s = doc ? doc->paragAt( id ) : parag;
201 if ( !s ) { 186 if ( !s ) {
202 qWarning( "can't locate parag at %d, last parag: %d", id, doc->lastParagraph()->paragId() ); 187 qWarning( "can't locate parag at %d, last parag: %d", id, doc->lastParagraph()->paragId() );
203 return 0; 188 return 0;
204 } 189 }
205 190
206 cursor.setParagraph( s ); 191 cursor.setParagraph( s );
207 cursor.setIndex( index ); 192 cursor.setIndex( index );
208 int len = text.size(); 193 int len = text.size();
209 if ( c ) 194 if ( c )
210 *c = cursor; 195 *c = cursor;
211 if ( doc ) { 196 if ( doc ) {
212 doc->setSelectionStart( QTextDocument::Temp, cursor ); 197 doc->setSelectionStart( QTextDocument::Temp, cursor );
213 for ( int i = 0; i < len; ++i ) 198 for ( int i = 0; i < len; ++i )
214 cursor.gotoNextLetter(); 199 cursor.gotoNextLetter();
215 doc->setSelectionEnd( QTextDocument::Temp, cursor ); 200 doc->setSelectionEnd( QTextDocument::Temp, cursor );
216 doc->removeSelectedText( QTextDocument::Temp, &cursor ); 201 doc->removeSelectedText( QTextDocument::Temp, &cursor );
217 if ( c ) 202 if ( c )
218 *c = cursor; 203 *c = cursor;
219 } else { 204 } else {
220 s->remove( index, len ); 205 s->remove( index, len );
221 } 206 }
222 207
223 return c; 208 return c;
224} 209}
225 210
226QTextCursor *QTextDeleteCommand::unexecute( QTextCursor *c ) 211QTextCursor *QTextDeleteCommand::unexecute( QTextCursor *c )
227{ 212{
228 QTextParagraph *s = doc ? doc->paragAt( id ) : parag; 213 QTextParagraph *s = doc ? doc->paragAt( id ) : parag;
229 if ( !s ) { 214 if ( !s ) {
230 qWarning( "can't locate parag at %d, last parag: %d", id, doc->lastParagraph()->paragId() ); 215 qWarning( "can't locate parag at %d, last parag: %d", id, doc->lastParagraph()->paragId() );
231 return 0; 216 return 0;
232 } 217 }
233 218
234 cursor.setParagraph( s ); 219 cursor.setParagraph( s );
235 cursor.setIndex( index ); 220 cursor.setIndex( index );
236 QString str = QTextString::toString( text ); 221 QString str = QTextString::toString( text );
237 cursor.insert( str, TRUE, &text ); 222 cursor.insert( str, TRUE, &text );
238 cursor.setParagraph( s ); 223 cursor.setParagraph( s );
239 cursor.setIndex( index ); 224 cursor.setIndex( index );
240 if ( c ) { 225 if ( c ) {
241 c->setParagraph( s ); 226 c->setParagraph( s );
242 c->setIndex( index ); 227 c->setIndex( index );
243 for ( int i = 0; i < (int)text.size(); ++i ) 228 for ( int i = 0; i < (int)text.size(); ++i )
244 c->gotoNextLetter(); 229 c->gotoNextLetter();
245 } 230 }
246 231
247 if ( !styleInformation.isEmpty() ) { 232 if ( !styleInformation.isEmpty() ) {
248 QDataStream styleStream( styleInformation, IO_ReadOnly ); 233 QDataStream styleStream( styleInformation, IO_ReadOnly );
249 int num; 234 int num;
250 styleStream >> num; 235 styleStream >> num;
251 QTextParagraph *p = s; 236 QTextParagraph *p = s;
252 while ( num-- && p ) { 237 while ( num-- && p ) {
253 p->readStyleInformation( styleStream ); 238 p->readStyleInformation( styleStream );
254 p = p->next(); 239 p = p->next();
255 } 240 }
256 } 241 }
257 s = cursor.paragraph(); 242 s = cursor.paragraph();
258 while ( s ) { 243 while ( s ) {
259 s->format(); 244 s->format();
260 s->setChanged( TRUE ); 245 s->setChanged( TRUE );
261 if ( s == c->paragraph() ) 246 if ( s == c->paragraph() )
262 break; 247 break;
263 s = s->next(); 248 s = s->next();
264 } 249 }
265 250
266 return &cursor; 251 return &cursor;
267} 252}
268 253
269QTextFormatCommand::QTextFormatCommand( QTextDocument *d, int sid, int sidx, int eid, int eidx, 254QTextFormatCommand::QTextFormatCommand( QTextDocument *d, int sid, int sidx, int eid, int eidx,
270 const QMemArray<QTextStringChar> &old, QTextFormat *f, int fl ) 255 const QMemArray<QTextStringChar> &old, QTextFormat *f, int fl )
271 : QTextCommand( d ), startId( sid ), startIndex( sidx ), endId( eid ), endIndex( eidx ), format( f ), oldFormats( old ), flags( fl ) 256 : QTextCommand( d ), startId( sid ), startIndex( sidx ), endId( eid ), endIndex( eidx ), format( f ), oldFormats( old ), flags( fl )
272{ 257{
273 format = d->formatCollection()->format( f ); 258 format = d->formatCollection()->format( f );
274 for ( int j = 0; j < (int)oldFormats.size(); ++j ) { 259 for ( int j = 0; j < (int)oldFormats.size(); ++j ) {
275 if ( oldFormats[ j ].format() ) 260 if ( oldFormats[ j ].format() )
276 oldFormats[ j ].format()->addRef(); 261 oldFormats[ j ].format()->addRef();
277 } 262 }
278} 263}
279 264
280QTextFormatCommand::~QTextFormatCommand() 265QTextFormatCommand::~QTextFormatCommand()
281{ 266{
282 format->removeRef(); 267 format->removeRef();
283 for ( int j = 0; j < (int)oldFormats.size(); ++j ) { 268 for ( int j = 0; j < (int)oldFormats.size(); ++j ) {
284 if ( oldFormats[ j ].format() ) 269 if ( oldFormats[ j ].format() )
285 oldFormats[ j ].format()->removeRef(); 270 oldFormats[ j ].format()->removeRef();
286 } 271 }
287} 272}
288 273
289QTextCursor *QTextFormatCommand::execute( QTextCursor *c ) 274QTextCursor *QTextFormatCommand::execute( QTextCursor *c )
290{ 275{
291 QTextParagraph *sp = doc->paragAt( startId ); 276 QTextParagraph *sp = doc->paragAt( startId );
292 QTextParagraph *ep = doc->paragAt( endId ); 277 QTextParagraph *ep = doc->paragAt( endId );
293 if ( !sp || !ep ) 278 if ( !sp || !ep )
294 return c; 279 return c;
295 280
296 QTextCursor start( doc ); 281 QTextCursor start( doc );
297 start.setParagraph( sp ); 282 start.setParagraph( sp );
298 start.setIndex( startIndex ); 283 start.setIndex( startIndex );
299 QTextCursor end( doc ); 284 QTextCursor end( doc );
300 end.setParagraph( ep ); 285 end.setParagraph( ep );
301 end.setIndex( endIndex ); 286 end.setIndex( endIndex );
302 287
303 doc->setSelectionStart( QTextDocument::Temp, start ); 288 doc->setSelectionStart( QTextDocument::Temp, start );
304 doc->setSelectionEnd( QTextDocument::Temp, end ); 289 doc->setSelectionEnd( QTextDocument::Temp, end );
305 doc->setFormat( QTextDocument::Temp, format, flags ); 290 doc->setFormat( QTextDocument::Temp, format, flags );
306 doc->removeSelection( QTextDocument::Temp ); 291 doc->removeSelection( QTextDocument::Temp );
307 if ( endIndex == ep->length() ) 292 if ( endIndex == ep->length() )
308 end.gotoLeft(); 293 end.gotoLeft();
309 *c = end; 294 *c = end;
310 return c; 295 return c;
311} 296}
312 297
313QTextCursor *QTextFormatCommand::unexecute( QTextCursor *c ) 298QTextCursor *QTextFormatCommand::unexecute( QTextCursor *c )
314{ 299{
315 QTextParagraph *sp = doc->paragAt( startId ); 300 QTextParagraph *sp = doc->paragAt( startId );
316 QTextParagraph *ep = doc->paragAt( endId ); 301 QTextParagraph *ep = doc->paragAt( endId );
317 if ( !sp || !ep ) 302 if ( !sp || !ep )
318 return 0; 303 return 0;
319 304
320 int idx = startIndex; 305 int idx = startIndex;
321 int fIndex = 0; 306 int fIndex = 0;
322 for ( ;; ) { 307 for ( ;; ) {
323 if ( oldFormats.at( fIndex ).c == '\n' ) { 308 if ( oldFormats.at( fIndex ).c == '\n' ) {
324 if ( idx > 0 ) { 309 if ( idx > 0 ) {
325 if ( idx < sp->length() && fIndex > 0 ) 310 if ( idx < sp->length() && fIndex > 0 )
326 sp->setFormat( idx, 1, oldFormats.at( fIndex - 1 ).format() ); 311 sp->setFormat( idx, 1, oldFormats.at( fIndex - 1 ).format() );
327 if ( sp == ep ) 312 if ( sp == ep )
328 break; 313 break;
329 sp = sp->next(); 314 sp = sp->next();
330 idx = 0; 315 idx = 0;
331 } 316 }
332 fIndex++; 317 fIndex++;
333 } 318 }
334 if ( oldFormats.at( fIndex ).format() ) 319 if ( oldFormats.at( fIndex ).format() )
335 sp->setFormat( idx, 1, oldFormats.at( fIndex ).format() ); 320 sp->setFormat( idx, 1, oldFormats.at( fIndex ).format() );
336 idx++; 321 idx++;
337 fIndex++; 322 fIndex++;
338 if ( fIndex >= (int)oldFormats.size() ) 323 if ( fIndex >= (int)oldFormats.size() )
339 break; 324 break;
340 if ( idx >= sp->length() ) { 325 if ( idx >= sp->length() ) {
341 if ( sp == ep ) 326 if ( sp == ep )
342 break; 327 break;
343 sp = sp->next(); 328 sp = sp->next();
344 idx = 0; 329 idx = 0;
345 } 330 }
346 } 331 }
347 332
348 QTextCursor end( doc ); 333 QTextCursor end( doc );
349 end.setParagraph( ep ); 334 end.setParagraph( ep );
350 end.setIndex( endIndex ); 335 end.setIndex( endIndex );
351 if ( endIndex == ep->length() ) 336 if ( endIndex == ep->length() )
352 end.gotoLeft(); 337 end.gotoLeft();
353 *c = end; 338 *c = end;
354 return c; 339 return c;
355} 340}
356 341
357QTextStyleCommand::QTextStyleCommand( QTextDocument *d, int fParag, int lParag, const QByteArray& beforeChange ) 342QTextStyleCommand::QTextStyleCommand( QTextDocument *d, int fParag, int lParag, const QByteArray& beforeChange )
358 : QTextCommand( d ), firstParag( fParag ), lastParag( lParag ), before( beforeChange ) 343 : QTextCommand( d ), firstParag( fParag ), lastParag( lParag ), before( beforeChange )
359{ 344{
360 after = readStyleInformation( d, fParag, lParag ); 345 after = readStyleInformation( d, fParag, lParag );
361} 346}
362 347
363 348
364QByteArray QTextStyleCommand::readStyleInformation( QTextDocument* doc, int fParag, int lParag ) 349QByteArray QTextStyleCommand::readStyleInformation( QTextDocument* doc, int fParag, int lParag )
365{ 350{
366 QByteArray style; 351 QByteArray style;
367 QTextParagraph *p = doc->paragAt( fParag ); 352 QTextParagraph *p = doc->paragAt( fParag );
368 if ( !p ) 353 if ( !p )
369 return style; 354 return style;
370 QDataStream styleStream( style, IO_WriteOnly ); 355 QDataStream styleStream( style, IO_WriteOnly );
371 int num = lParag - fParag + 1; 356 int num = lParag - fParag + 1;
372 styleStream << num; 357 styleStream << num;
373 while ( num -- && p ) { 358 while ( num -- && p ) {
374 p->writeStyleInformation( styleStream ); 359 p->writeStyleInformation( styleStream );
375 p = p->next(); 360 p = p->next();
376 } 361 }
377 return style; 362 return style;
378} 363}
379 364
380void QTextStyleCommand::writeStyleInformation( QTextDocument* doc, int fParag, const QByteArray& style ) 365void QTextStyleCommand::writeStyleInformation( QTextDocument* doc, int fParag, const QByteArray& style )
381{ 366{
382 QTextParagraph *p = doc->paragAt( fParag ); 367 QTextParagraph *p = doc->paragAt( fParag );
383 if ( !p ) 368 if ( !p )
384 return; 369 return;
385 QDataStream styleStream( style, IO_ReadOnly ); 370 QDataStream styleStream( style, IO_ReadOnly );
386 int num; 371 int num;
387 styleStream >> num; 372 styleStream >> num;
388 while ( num-- && p ) { 373 while ( num-- && p ) {
389 p->readStyleInformation( styleStream ); 374 p->readStyleInformation( styleStream );
390 p = p->next(); 375 p = p->next();
391 } 376 }
392} 377}
393 378
394QTextCursor *QTextStyleCommand::execute( QTextCursor *c ) 379QTextCursor *QTextStyleCommand::execute( QTextCursor *c )
395{ 380{
396 writeStyleInformation( doc, firstParag, after ); 381 writeStyleInformation( doc, firstParag, after );
397 return c; 382 return c;
398} 383}
399 384
400QTextCursor *QTextStyleCommand::unexecute( QTextCursor *c ) 385QTextCursor *QTextStyleCommand::unexecute( QTextCursor *c )
401{ 386{
402 writeStyleInformation( doc, firstParag, before ); 387 writeStyleInformation( doc, firstParag, before );
403 return c; 388 return c;
404} 389}
405 390
406// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 391// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
407 392
408QTextCursor::QTextCursor( QTextDocument *d ) 393QTextCursor::QTextCursor( QTextDocument *d )
409 : idx( 0 ), tmpIndex( -1 ), ox( 0 ), oy( 0 ), 394 : idx( 0 ), tmpIndex( -1 ), ox( 0 ), oy( 0 ),
410 valid( TRUE ) 395 valid( TRUE )
411{ 396{
412 para = d ? d->firstParagraph() : 0; 397 para = d ? d->firstParagraph() : 0;
413} 398}
414 399
415QTextCursor::QTextCursor( const QTextCursor &c ) 400QTextCursor::QTextCursor( const QTextCursor &c )
416{ 401{
417 ox = c.ox; 402 ox = c.ox;
418 oy = c.oy; 403 oy = c.oy;
419 idx = c.idx; 404 idx = c.idx;
420 para = c.para; 405 para = c.para;
421 tmpIndex = c.tmpIndex; 406 tmpIndex = c.tmpIndex;
422 indices = c.indices; 407 indices = c.indices;
423 paras = c.paras; 408 paras = c.paras;
424 xOffsets = c.xOffsets; 409 xOffsets = c.xOffsets;
425 yOffsets = c.yOffsets; 410 yOffsets = c.yOffsets;
426 valid = c.valid; 411 valid = c.valid;
427} 412}
428 413
429QTextCursor &QTextCursor::operator=( const QTextCursor &c ) 414QTextCursor &QTextCursor::operator=( const QTextCursor &c )
430{ 415{
431 ox = c.ox; 416 ox = c.ox;
432 oy = c.oy; 417 oy = c.oy;
433 idx = c.idx; 418 idx = c.idx;
434 para = c.para; 419 para = c.para;
435 tmpIndex = c.tmpIndex; 420 tmpIndex = c.tmpIndex;
436 indices = c.indices; 421 indices = c.indices;
437 paras = c.paras; 422 paras = c.paras;
438 xOffsets = c.xOffsets; 423 xOffsets = c.xOffsets;
439 yOffsets = c.yOffsets; 424 yOffsets = c.yOffsets;
440 valid = c.valid; 425 valid = c.valid;
441 426
442 return *this; 427 return *this;
443} 428}
444 429
445bool QTextCursor::operator==( const QTextCursor &c ) const 430bool QTextCursor::operator==( const QTextCursor &c ) const
446{ 431{
447 return para == c.para && idx == c.idx; 432 return para == c.para && idx == c.idx;
448} 433}
449 434
450int QTextCursor::totalOffsetX() const 435int QTextCursor::totalOffsetX() const
451{ 436{
452 int xoff = ox; 437 int xoff = ox;
453 for ( QValueStack<int>::ConstIterator xit = xOffsets.begin(); xit != xOffsets.end(); ++xit ) 438 for ( QValueStack<int>::ConstIterator xit = xOffsets.begin(); xit != xOffsets.end(); ++xit )
454 xoff += *xit; 439 xoff += *xit;
455 return xoff; 440 return xoff;
456} 441}
457 442
458int QTextCursor::totalOffsetY() const 443int QTextCursor::totalOffsetY() const
459{ 444{
460 int yoff = oy; 445 int yoff = oy;
461 for ( QValueStack<int>::ConstIterator yit = yOffsets.begin(); yit != yOffsets.end(); ++yit ) 446 for ( QValueStack<int>::ConstIterator yit = yOffsets.begin(); yit != yOffsets.end(); ++yit )
462 yoff += *yit; 447 yoff += *yit;
463 return yoff; 448 return yoff;
464} 449}
465 450
466void QTextCursor::gotoIntoNested( const QPoint &globalPos ) 451void QTextCursor::gotoIntoNested( const QPoint &globalPos )
467{ 452{
468 if ( !para ) 453 if ( !para )
469 return; 454 return;
470 push(); 455 push();
471 ox = 0; 456 ox = 0;
472 int bl, y; 457 int bl, y;
473 para->lineHeightOfChar( idx, &bl, &y ); 458 para->lineHeightOfChar( idx, &bl, &y );
474 oy = y + para->rect().y(); 459 oy = y + para->rect().y();
475 QPoint p( globalPos.x() - offsetX(), globalPos.y() - offsetY() ); 460 QPoint p( globalPos.x() - offsetX(), globalPos.y() - offsetY() );
476 Q_ASSERT( para->at( idx )->isCustom() ); 461 Q_ASSERT( para->at( idx )->isCustom() );
477 ox = para->at( idx )->x; 462 ox = para->at( idx )->x;
478 463
479 QTextDocument* doc = document(); 464 QTextDocument* doc = document();
480 para->at( idx )->customItem()->enterAt( this, doc, para, idx, ox, oy, p ); 465 para->at( idx )->customItem()->enterAt( this, doc, para, idx, ox, oy, p );
481} 466}
482 467
483void QTextCursor::invalidateNested() 468void QTextCursor::invalidateNested()
484{ 469{
485 QValueStack<QTextParagraph*>::Iterator it = paras.begin(); 470 QValueStack<QTextParagraph*>::Iterator it = paras.begin();
486 QValueStack<int>::Iterator it2 = indices.begin(); 471 QValueStack<int>::Iterator it2 = indices.begin();
487 for ( ; it != paras.end(); ++it, ++it2 ) { 472 for ( ; it != paras.end(); ++it, ++it2 ) {
488 if ( *it == para ) 473 if ( *it == para )
489 continue; 474 continue;
490 (*it)->invalidate( 0 ); 475 (*it)->invalidate( 0 );
491 if ( (*it)->at( *it2 )->isCustom() ) 476 if ( (*it)->at( *it2 )->isCustom() )
492 (*it)->at( *it2 )->customItem()->invalidate(); 477 (*it)->at( *it2 )->customItem()->invalidate();
493 } 478 }
494} 479}
495 480
496void QTextCursor::insert( const QString &str, bool checkNewLine, QMemArray<QTextStringChar> *formatting ) 481void QTextCursor::insert( const QString &str, bool checkNewLine, QMemArray<QTextStringChar> *formatting )
497{ 482{
498 tmpIndex = -1; 483 tmpIndex = -1;
499 bool justInsert = TRUE; 484 bool justInsert = TRUE;
500 QString s( str ); 485 QString s( str );
501#if defined(Q_WS_WIN) 486#if defined(Q_WS_WIN)
502 if ( checkNewLine ) { 487 if ( checkNewLine ) {
503 int i = 0; 488 int i = 0;
504 while ( ( i = s.find( '\r', i ) ) != -1 ) 489 while ( ( i = s.find( '\r', i ) ) != -1 )
505 s.remove( i ,1 ); 490 s.remove( i ,1 );
506 } 491 }
507#endif 492#endif
508 if ( checkNewLine ) 493 if ( checkNewLine )
509 justInsert = s.find( '\n' ) == -1; 494 justInsert = s.find( '\n' ) == -1;
510 if ( justInsert ) { // we ignore new lines and insert all in the current para at the current index 495 if ( justInsert ) { // we ignore new lines and insert all in the current para at the current index
511 para->insert( idx, s.unicode(), s.length() ); 496 para->insert( idx, s.unicode(), s.length() );
512 if ( formatting ) { 497 if ( formatting ) {
513 for ( int i = 0; i < (int)s.length(); ++i ) { 498 for ( int i = 0; i < (int)s.length(); ++i ) {
514 if ( formatting->at( i ).format() ) { 499 if ( formatting->at( i ).format() ) {
515 formatting->at( i ).format()->addRef(); 500 formatting->at( i ).format()->addRef();
516 para->string()->setFormat( idx + i, formatting->at( i ).format(), TRUE ); 501 para->string()->setFormat( idx + i, formatting->at( i ).format(), TRUE );
517 } 502 }
518 } 503 }
519 } 504 }
520 idx += s.length(); 505 idx += s.length();
521 } else { // we split at new lines 506 } else { // we split at new lines
522 int start = -1; 507 int start = -1;
523 int end; 508 int end;
524 int y = para->rect().y() + para->rect().height(); 509 int y = para->rect().y() + para->rect().height();
525 int lastIndex = 0; 510 int lastIndex = 0;
526 do { 511 do {
527 end = s.find( '\n', start + 1 ); // find line break 512 end = s.find( '\n', start + 1 ); // find line break
528 if ( end == -1 ) // didn't find one, so end of line is end of string 513 if ( end == -1 ) // didn't find one, so end of line is end of string
529 end = s.length(); 514 end = s.length();
530 int len = (start == -1 ? end : end - start - 1); 515 int len = (start == -1 ? end : end - start - 1);
531 if ( len > 0 ) // insert the line 516 if ( len > 0 ) // insert the line
532 para->insert( idx, s.unicode() + start + 1, len ); 517 para->insert( idx, s.unicode() + start + 1, len );
533 else 518 else
534 para->invalidate( 0 ); 519 para->invalidate( 0 );
535 if ( formatting ) { // set formats to the chars of the line 520 if ( formatting ) { // set formats to the chars of the line
536 for ( int i = 0; i < len; ++i ) { 521 for ( int i = 0; i < len; ++i ) {
537 if ( formatting->at( i + lastIndex ).format() ) { 522 if ( formatting->at( i + lastIndex ).format() ) {
538 formatting->at( i + lastIndex ).format()->addRef(); 523 formatting->at( i + lastIndex ).format()->addRef();
539 para->string()->setFormat( i + idx, formatting->at( i + lastIndex ).format(), TRUE ); 524 para->string()->setFormat( i + idx, formatting->at( i + lastIndex ).format(), TRUE );
540 } 525 }
541 } 526 }
542 lastIndex += len; 527 lastIndex += len;
543 } 528 }
544 start = end; // next start is at the end of this line 529 start = end; // next start is at the end of this line
545 idx += len; // increase the index of the cursor to the end of the inserted text 530 idx += len; // increase the index of the cursor to the end of the inserted text
546 if ( s[end] == '\n' ) { // if at the end was a line break, break the line 531 if ( s[end] == '\n' ) { // if at the end was a line break, break the line
547 splitAndInsertEmptyParagraph( FALSE, TRUE ); 532 splitAndInsertEmptyParagraph( FALSE, TRUE );
548 para->setEndState( -1 ); 533 para->setEndState( -1 );
549 para->prev()->format( -1, FALSE ); 534 para->prev()->format( -1, FALSE );
550 lastIndex++; 535 lastIndex++;
551 } 536 }
552 537
553 } while ( end < (int)s.length() ); 538 } while ( end < (int)s.length() );
554 539
555 para->format( -1, FALSE ); 540 para->format( -1, FALSE );
556 int dy = para->rect().y() + para->rect().height() - y; 541 int dy = para->rect().y() + para->rect().height() - y;
557 QTextParagraph *p = para; 542 QTextParagraph *p = para;
558 p->setParagId( p->prev() ? p->prev()->paragId() + 1 : 0 ); 543 p->setParagId( p->prev() ? p->prev()->paragId() + 1 : 0 );
559 p = p->next(); 544 p = p->next();
560 while ( p ) { 545 while ( p ) {
561 p->setParagId( p->prev()->paragId() + 1 ); 546 p->setParagId( p->prev()->paragId() + 1 );
562 p->move( dy ); 547 p->move( dy );
563 p->invalidate( 0 ); 548 p->invalidate( 0 );
564 p->setEndState( -1 ); 549 p->setEndState( -1 );
565 p = p->next(); 550 p = p->next();
566 } 551 }
567 } 552 }
568 553
569 int h = para->rect().height(); 554 int h = para->rect().height();
570 para->format( -1, TRUE ); 555 para->format( -1, TRUE );
571 if ( h != para->rect().height() ) 556 if ( h != para->rect().height() )
572 invalidateNested(); 557 invalidateNested();
573 else if ( para->document() && para->document()->parent() ) 558 else if ( para->document() && para->document()->parent() )
574 para->document()->nextDoubleBuffered = TRUE; 559 para->document()->nextDoubleBuffered = TRUE;
575} 560}
576 561
577void QTextCursor::gotoLeft() 562void QTextCursor::gotoLeft()
578{ 563{
579 if ( para->string()->isRightToLeft() ) 564 if ( para->string()->isRightToLeft() )
580 gotoNextLetter(); 565 gotoNextLetter();
581 else 566 else
582 gotoPreviousLetter(); 567 gotoPreviousLetter();
583} 568}
584 569
585void QTextCursor::gotoPreviousLetter() 570void QTextCursor::gotoPreviousLetter()
586{ 571{
587 tmpIndex = -1; 572 tmpIndex = -1;
588 573
589 if ( idx > 0 ) { 574 if ( idx > 0 ) {
590 idx--; 575 idx--;
591 const QTextStringChar *tsc = para->at( idx ); 576 const QTextStringChar *tsc = para->at( idx );
592 if ( tsc && tsc->isCustom() && tsc->customItem()->isNested() ) 577 if ( tsc && tsc->isCustom() && tsc->customItem()->isNested() )
593 processNesting( EnterEnd ); 578 processNesting( EnterEnd );
594 } else if ( para->prev() ) { 579 } else if ( para->prev() ) {
595 para = para->prev(); 580 para = para->prev();
596 while ( !para->isVisible() && para->prev() ) 581 while ( !para->isVisible() && para->prev() )
597 para = para->prev(); 582 para = para->prev();
598 idx = para->length() - 1; 583 idx = para->length() - 1;
599 } else if ( nestedDepth() ) { 584 } else if ( nestedDepth() ) {
600 pop(); 585 pop();
601 processNesting( Prev ); 586 processNesting( Prev );
602 if ( idx == -1 ) { 587 if ( idx == -1 ) {
603 pop(); 588 pop();
604 if ( idx > 0 ) { 589 if ( idx > 0 ) {
605 idx--; 590 idx--;
606 } else if ( para->prev() ) { 591 } else if ( para->prev() ) {
607 para = para->prev(); 592 para = para->prev();
608 idx = para->length() - 1; 593 idx = para->length() - 1;
609 } 594 }
610 } 595 }
611 } 596 }
612} 597}
613 598
614void QTextCursor::push() 599void QTextCursor::push()
615{ 600{
616 indices.push( idx ); 601 indices.push( idx );
617 paras.push( para ); 602 paras.push( para );
618 xOffsets.push( ox ); 603 xOffsets.push( ox );
619 yOffsets.push( oy ); 604 yOffsets.push( oy );
620} 605}
621 606
622void QTextCursor::pop() 607void QTextCursor::pop()
623{ 608{
624 if ( indices.isEmpty() ) 609 if ( indices.isEmpty() )
625 return; 610 return;
626 idx = indices.pop(); 611 idx = indices.pop();
627 para = paras.pop(); 612 para = paras.pop();
628 ox = xOffsets.pop(); 613 ox = xOffsets.pop();
629 oy = yOffsets.pop(); 614 oy = yOffsets.pop();
630} 615}
631 616
632void QTextCursor::restoreState() 617void QTextCursor::restoreState()
633{ 618{
634 while ( !indices.isEmpty() ) 619 while ( !indices.isEmpty() )
635 pop(); 620 pop();
636} 621}
637 622
638bool QTextCursor::place( const QPoint &p, QTextParagraph *s, bool link ) 623bool QTextCursor::place( const QPoint &p, QTextParagraph *s, bool link )
639{ 624{
640 QPoint pos( p ); 625 QPoint pos( p );
641 QRect r; 626 QRect r;
642 QTextParagraph *str = s; 627 QTextParagraph *str = s;
643 if ( pos.y() < s->rect().y() ) 628 if ( pos.y() < s->rect().y() )
644 pos.setY( s->rect().y() ); 629 pos.setY( s->rect().y() );
645 while ( s ) { 630 while ( s ) {
646 r = s->rect(); 631 r = s->rect();
647 r.setWidth( document() ? document()->width() : QWIDGETSIZE_MAX ); 632 r.setWidth( document() ? document()->width() : QWIDGETSIZE_MAX );
648 if ( s->isVisible() ) 633 if ( s->isVisible() )
649 str = s; 634 str = s;
650 if ( pos.y() >= r.y() && pos.y() <= r.y() + r.height() || !s->next() ) 635 if ( pos.y() >= r.y() && pos.y() <= r.y() + r.height() || !s->next() )
651 break; 636 break;
652 s = s->next(); 637 s = s->next();
653 } 638 }
654 639
655 if ( !s || !str ) 640 if ( !s || !str )
656 return FALSE; 641 return FALSE;
657 642
658 s = str; 643 s = str;
659 644
660 setParagraph( s ); 645 setParagraph( s );
661 int y = s->rect().y(); 646 int y = s->rect().y();
662 int lines = s->lines(); 647 int lines = s->lines();
663 QTextStringChar *chr = 0; 648 QTextStringChar *chr = 0;
664 int index = 0; 649 int index = 0;
665 int i = 0; 650 int i = 0;
666 int cy = 0; 651 int cy = 0;
667 int ch = 0; 652 int ch = 0;
668 for ( ; i < lines; ++i ) { 653 for ( ; i < lines; ++i ) {
669 chr = s->lineStartOfLine( i, &index ); 654 chr = s->lineStartOfLine( i, &index );
670 cy = s->lineY( i ); 655 cy = s->lineY( i );
671 ch = s->lineHeight( i ); 656 ch = s->lineHeight( i );
672 if ( !chr ) 657 if ( !chr )
673 return FALSE; 658 return FALSE;
674 if ( pos.y() <= y + cy + ch ) 659 if ( pos.y() <= y + cy + ch )
675 break; 660 break;
676 } 661 }
677 int nextLine; 662 int nextLine;
678 if ( i < lines - 1 ) 663 if ( i < lines - 1 )
679 s->lineStartOfLine( i+1, &nextLine ); 664 s->lineStartOfLine( i+1, &nextLine );
680 else 665 else
681 nextLine = s->length(); 666 nextLine = s->length();
682 i = index; 667 i = index;
683 int x = s->rect().x(); 668 int x = s->rect().x();
684 if ( pos.x() < x ) 669 if ( pos.x() < x )
685 pos.setX( x + 1 ); 670 pos.setX( x + 1 );
686 int cw; 671 int cw;
687 int curpos = s->length()-1; 672 int curpos = s->length()-1;
688 int dist = 10000000; 673 int dist = 10000000;
689 bool inCustom = FALSE; 674 bool inCustom = FALSE;
690 while ( i < nextLine ) { 675 while ( i < nextLine ) {
691 chr = s->at(i); 676 chr = s->at(i);
692 int cpos = x + chr->x; 677 int cpos = x + chr->x;
693 cw = s->string()->width( i ); 678 cw = s->string()->width( i );
694 if ( chr->isCustom() && chr->customItem()->isNested() ) { 679 if ( chr->isCustom() && chr->customItem()->isNested() ) {
695 if ( pos.x() >= cpos && pos.x() <= cpos + cw && 680 if ( pos.x() >= cpos && pos.x() <= cpos + cw &&
696 pos.y() >= y + cy && pos.y() <= y + cy + chr->height() ) { 681 pos.y() >= y + cy && pos.y() <= y + cy + chr->height() ) {
697 inCustom = TRUE; 682 inCustom = TRUE;
698 curpos = i; 683 curpos = i;
699 break; 684 break;
700 } 685 }
701 } else { 686 } else {
702 if( chr->rightToLeft ) 687 if( chr->rightToLeft )
703 cpos += cw; 688 cpos += cw;
704 int d = cpos - pos.x(); 689 int d = cpos - pos.x();
705 bool dm = d < 0 ? !chr->rightToLeft : chr->rightToLeft; 690 bool dm = d < 0 ? !chr->rightToLeft : chr->rightToLeft;
706 if ( QABS( d ) < dist || (dist == d && dm == TRUE ) ) { 691 if ( QABS( d ) < dist || (dist == d && dm == TRUE ) ) {
707 dist = QABS( d ); 692 dist = QABS( d );
708 if ( !link || pos.x() >= x + chr->x ) 693 if ( !link || pos.x() >= x + chr->x )
709 curpos = i; 694 curpos = i;
710 } 695 }
711 } 696 }
712 i++; 697 i++;
713 } 698 }
714 setIndex( curpos ); 699 setIndex( curpos );
715 700
716 if ( inCustom && para->document() && para->at( curpos )->isCustom() && para->at( curpos )->customItem()->isNested() ) { 701 if ( inCustom && para->document() && para->at( curpos )->isCustom() && para->at( curpos )->customItem()->isNested() ) {
717 QTextDocument *oldDoc = para->document(); 702 QTextDocument *oldDoc = para->document();
718 gotoIntoNested( pos ); 703 gotoIntoNested( pos );
719 if ( oldDoc == para->document() ) 704 if ( oldDoc == para->document() )
720 return TRUE; 705 return TRUE;
721 QPoint p( pos.x() - offsetX(), pos.y() - offsetY() ); 706 QPoint p( pos.x() - offsetX(), pos.y() - offsetY() );
722 if ( !place( p, document()->firstParagraph(), link ) ) 707 if ( !place( p, document()->firstParagraph(), link ) )
723 pop(); 708 pop();
724 } 709 }
725 return TRUE; 710 return TRUE;
726} 711}
727 712
728void QTextCursor::processNesting( Operation op ) 713void QTextCursor::processNesting( Operation op )
729{ 714{
730 if ( !para->document() ) 715 if ( !para->document() )
731 return; 716 return;
732 QTextDocument* doc = para->document(); 717 QTextDocument* doc = para->document();
733 push(); 718 push();
734 ox = para->at( idx )->x; 719 ox = para->at( idx )->x;
735 int bl, y; 720 int bl, y;
736 para->lineHeightOfChar( idx, &bl, &y ); 721 para->lineHeightOfChar( idx, &bl, &y );
737 oy = y + para->rect().y(); 722 oy = y + para->rect().y();
738 bool ok = FALSE; 723 bool ok = FALSE;
739 724
740 switch ( op ) { 725 switch ( op ) {
741 case EnterBegin: 726 case EnterBegin:
742 ok = para->at( idx )->customItem()->enter( this, doc, para, idx, ox, oy ); 727 ok = para->at( idx )->customItem()->enter( this, doc, para, idx, ox, oy );
743 break; 728 break;
744 case EnterEnd: 729 case EnterEnd:
745 ok = para->at( idx )->customItem()->enter( this, doc, para, idx, ox, oy, TRUE ); 730 ok = para->at( idx )->customItem()->enter( this, doc, para, idx, ox, oy, TRUE );
746 break; 731 break;
747 case Next: 732 case Next:
748 ok = para->at( idx )->customItem()->next( this, doc, para, idx, ox, oy ); 733 ok = para->at( idx )->customItem()->next( this, doc, para, idx, ox, oy );
749 break; 734 break;
750 case Prev: 735 case Prev:
751 ok = para->at( idx )->customItem()->prev( this, doc, para, idx, ox, oy ); 736 ok = para->at( idx )->customItem()->prev( this, doc, para, idx, ox, oy );
752 break; 737 break;
753 case Down: 738 case Down:
754 ok = para->at( idx )->customItem()->down( this, doc, para, idx, ox, oy ); 739 ok = para->at( idx )->customItem()->down( this, doc, para, idx, ox, oy );
755 break; 740 break;
756 case Up: 741 case Up:
757 ok = para->at( idx )->customItem()->up( this, doc, para, idx, ox, oy ); 742 ok = para->at( idx )->customItem()->up( this, doc, para, idx, ox, oy );
758 break; 743 break;
759 } 744 }
760 if ( !ok ) 745 if ( !ok )
761 pop(); 746 pop();
762} 747}
763 748
764void QTextCursor::gotoRight() 749void QTextCursor::gotoRight()
765{ 750{
766 if ( para->string()->isRightToLeft() ) 751 if ( para->string()->isRightToLeft() )
767 gotoPreviousLetter(); 752 gotoPreviousLetter();
768 else 753 else
769 gotoNextLetter(); 754 gotoNextLetter();
770} 755}
771 756
772void QTextCursor::gotoNextLetter() 757void QTextCursor::gotoNextLetter()
773{ 758{
774 tmpIndex = -1; 759 tmpIndex = -1;
775 760
776 const QTextStringChar *tsc = para->at( idx ); 761 const QTextStringChar *tsc = para->at( idx );
777 if ( tsc && tsc->isCustom() && tsc->customItem()->isNested() ) { 762 if ( tsc && tsc->isCustom() && tsc->customItem()->isNested() ) {
778 processNesting( EnterBegin ); 763 processNesting( EnterBegin );
779 return; 764 return;
780 } 765 }
781 766
782 if ( idx < para->length() - 1 ) { 767 if ( idx < para->length() - 1 ) {
783 idx++; 768 idx++;
784 } else if ( para->next() ) { 769 } else if ( para->next() ) {
785 para = para->next(); 770 para = para->next();
786 while ( !para->isVisible() && para->next() ) 771 while ( !para->isVisible() && para->next() )
787 para = para->next(); 772 para = para->next();
788 idx = 0; 773 idx = 0;
789 } else if ( nestedDepth() ) { 774 } else if ( nestedDepth() ) {
790 pop(); 775 pop();
791 processNesting( Next ); 776 processNesting( Next );
792 if ( idx == -1 ) { 777 if ( idx == -1 ) {
793 pop(); 778 pop();
794 if ( idx < para->length() - 1 ) { 779 if ( idx < para->length() - 1 ) {
795 idx++; 780 idx++;
796 } else if ( para->next() ) { 781 } else if ( para->next() ) {
797 para = para->next(); 782 para = para->next();
798 idx = 0; 783 idx = 0;
799 } 784 }
800 } 785 }
801 } 786 }
802} 787}
803 788
804void QTextCursor::gotoUp() 789void QTextCursor::gotoUp()
805{ 790{
806 int indexOfLineStart; 791 int indexOfLineStart;
807 int line; 792 int line;
808 QTextStringChar *c = para->lineStartOfChar( idx, &indexOfLineStart, &line ); 793 QTextStringChar *c = para->lineStartOfChar( idx, &indexOfLineStart, &line );
809 if ( !c ) 794 if ( !c )
810 return; 795 return;
811 796
812 tmpIndex = QMAX( tmpIndex, idx - indexOfLineStart ); 797 tmpIndex = QMAX( tmpIndex, idx - indexOfLineStart );
813 if ( indexOfLineStart == 0 ) { 798 if ( indexOfLineStart == 0 ) {
814 if ( !para->prev() ) { 799 if ( !para->prev() ) {
815 if ( !nestedDepth() ) 800 if ( !nestedDepth() )
816 return; 801 return;
817 pop(); 802 pop();
818 processNesting( Up ); 803 processNesting( Up );
819 if ( idx == -1 ) { 804 if ( idx == -1 ) {
820 pop(); 805 pop();
821 if ( !para->prev() ) 806 if ( !para->prev() )
822 return; 807 return;
823 idx = tmpIndex = 0; 808 idx = tmpIndex = 0;
824 } else { 809 } else {
825 tmpIndex = -1; 810 tmpIndex = -1;
diff --git a/noncore/apps/opie-write/qstylesheet.cpp b/noncore/apps/opie-write/qstylesheet.cpp
index 67cd828..ca634f7 100644
--- a/noncore/apps/opie-write/qstylesheet.cpp
+++ b/noncore/apps/opie-write/qstylesheet.cpp
@@ -1,810 +1,808 @@
1/**************************************************************************** 1/****************************************************************************
2** $Id$ 2** $Id$
3** 3**
4** Implementation of the QStyleSheet class 4** Implementation of the QStyleSheet class
5** 5**
6** Created : 990101 6** Created : 990101
7** 7**
8** Copyright (C) 1992-2000 Trolltech AS. All rights reserved. 8** Copyright (C) 1992-2000 Trolltech AS. All rights reserved.
9** 9**
10** This file is part of the kernel module of the Qt GUI Toolkit. 10** This file is part of the kernel module of the Qt GUI Toolkit.
11** 11**
12** This file may be distributed under the terms of the Q Public License 12** This file may be distributed under the terms of the Q Public License
13** as defined by Trolltech AS of Norway and appearing in the file 13** as defined by Trolltech AS of Norway and appearing in the file
14** LICENSE.QPL included in the packaging of this file. 14** LICENSE.QPL included in the packaging of this file.
15** 15**
16** This file may be distributed and/or modified under the terms of the 16** This file may be distributed and/or modified under the terms of the
17** GNU General Public License version 2 as published by the Free Software 17** GNU General Public License version 2 as published by the Free Software
18** Foundation and appearing in the file LICENSE.GPL included in the 18** Foundation and appearing in the file LICENSE.GPL included in the
19** packaging of this file. 19** packaging of this file.
20** 20**
21** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition 21** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
22** licenses may use this file in accordance with the Qt Commercial License 22** licenses may use this file in accordance with the Qt Commercial License
23** Agreement provided with the Software. 23** Agreement provided with the Software.
24** 24**
25** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 25** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
26** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 26** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
27** 27**
28** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for 28** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
29** information about Qt Commercial License Agreements. 29** information about Qt Commercial License Agreements.
30** See http://www.trolltech.com/qpl/ for QPL licensing information. 30** See http://www.trolltech.com/qpl/ for QPL licensing information.
31** See http://www.trolltech.com/gpl/ for GPL licensing information. 31** See http://www.trolltech.com/gpl/ for GPL licensing information.
32** 32**
33** Contact info@trolltech.com if any conditions of this licensing are 33** Contact info@trolltech.com if any conditions of this licensing are
34** not clear to you. 34** not clear to you.
35** 35**
36**********************************************************************/ 36**********************************************************************/
37 37
38#include "qstylesheet.h" 38#include "qstylesheet.h"
39 39
40#include "qrichtext_p.h" 40#include "qrichtext_p.h"
41#include "qlayout.h"
42#include "qpainter.h"
43#include "qcleanuphandler.h" 41#include "qcleanuphandler.h"
44 42
45#include <stdio.h> 43#include <stdio.h>
46 44
47using namespace Qt3; 45using namespace Qt3;
48 46
49namespace Qt3 { 47namespace Qt3 {
50 48
51class QStyleSheetItemData 49class QStyleSheetItemData
52{ 50{
53public: 51public:
54 QStyleSheetItem::DisplayMode disp; 52 QStyleSheetItem::DisplayMode disp;
55 int fontitalic; 53 int fontitalic;
56 int fontunderline; 54 int fontunderline;
57 int fontstrikeout; 55 int fontstrikeout;
58 int fontweight; 56 int fontweight;
59 int fontsize; 57 int fontsize;
60 int fontsizelog; 58 int fontsizelog;
61 int fontsizestep; 59 int fontsizestep;
62 int lineSpacing; 60 int lineSpacing;
63 QString fontfamily; 61 QString fontfamily;
64 QStyleSheetItem *parentstyle; 62 QStyleSheetItem *parentstyle;
65 QString stylename; 63 QString stylename;
66 int ncolumns; 64 int ncolumns;
67 QColor col; 65 QColor col;
68 bool anchor; 66 bool anchor;
69 int align; 67 int align;
70 QStyleSheetItem::VerticalAlignment valign; 68 QStyleSheetItem::VerticalAlignment valign;
71 int margin[5]; 69 int margin[5];
72 QStyleSheetItem::ListStyle list; 70 QStyleSheetItem::ListStyle list;
73 QStyleSheetItem::WhiteSpaceMode whitespacemode; 71 QStyleSheetItem::WhiteSpaceMode whitespacemode;
74 QString contxt; 72 QString contxt;
75 bool selfnest; 73 bool selfnest;
76 QStyleSheet* sheet; 74 QStyleSheet* sheet;
77}; 75};
78 76
79} 77}
80 78
81/*! 79/*!
82 \class QStyleSheetItem qstylesheet.h 80 \class QStyleSheetItem qstylesheet.h
83 \brief The QStyleSheetItem class provides an encapsulation of a set of text styles. 81 \brief The QStyleSheetItem class provides an encapsulation of a set of text styles.
84 82
85 \ingroup text 83 \ingroup text
86 84
87 A style sheet item consists of a name and a set of attributes that 85 A style sheet item consists of a name and a set of attributes that
88 specifiy its font, color, etc. When used in a \link QStyleSheet 86 specifiy its font, color, etc. When used in a \link QStyleSheet
89 style sheet\endlink (see styleSheet()), items define the name() of 87 style sheet\endlink (see styleSheet()), items define the name() of
90 a rich text tag and the display property changes associated with 88 a rich text tag and the display property changes associated with
91 it. 89 it.
92 90
93 The \link QStyleSheetItem::DisplayMode display mode\endlink 91 The \link QStyleSheetItem::DisplayMode display mode\endlink
94 attribute indicates whether the item is a block, an inline element 92 attribute indicates whether the item is a block, an inline element
95 or a list element; see setDisplayMode(). The treatment of 93 or a list element; see setDisplayMode(). The treatment of
96 whitespace is controlled by the \link 94 whitespace is controlled by the \link
97 QStyleSheetItem::WhiteSpaceMode white space mode\endlink; see 95 QStyleSheetItem::WhiteSpaceMode white space mode\endlink; see
98 setWhiteSpaceMode(). An item's margins are set with setMargin(), 96 setWhiteSpaceMode(). An item's margins are set with setMargin(),
99 In the case of list items, the list style is set with 97 In the case of list items, the list style is set with
100 setListStyle(). An item may be a hypertext link anchor; see 98 setListStyle(). An item may be a hypertext link anchor; see
101 setAnchor(). Other attributes are set with setAlignment(), 99 setAnchor(). Other attributes are set with setAlignment(),
102 setVerticalAlignment(), setFontFamily(), setFontSize(), 100 setVerticalAlignment(), setFontFamily(), setFontSize(),
103 setFontWeight(), setFontItalic(), setFontUnderline(), 101 setFontWeight(), setFontItalic(), setFontUnderline(),
104 setFontStrikeOut and setColor(). 102 setFontStrikeOut and setColor().
105*/ 103*/
106 104
107/*! \enum QStyleSheetItem::AdditionalStyleValues 105/*! \enum QStyleSheetItem::AdditionalStyleValues
108 \internal 106 \internal
109*/ 107*/
110 108
111/*! 109/*!
112 \enum QStyleSheetItem::WhiteSpaceMode 110 \enum QStyleSheetItem::WhiteSpaceMode
113 111
114 This enum defines the ways in which QStyleSheet can treat 112 This enum defines the ways in which QStyleSheet can treat
115 whitespace. 113 whitespace.
116 114
117 \value WhiteSpaceNormal any sequence of whitespace (including 115 \value WhiteSpaceNormal any sequence of whitespace (including
118 line-breaks) is equivalent to a single space. 116 line-breaks) is equivalent to a single space.
119 117
120 \value WhiteSpacePre whitespace must be output exactly as given 118 \value WhiteSpacePre whitespace must be output exactly as given
121 in the input. 119 in the input.
122 120
123 \value WhiteSpaceNoWrap multiple spaces are collapsed as with 121 \value WhiteSpaceNoWrap multiple spaces are collapsed as with
124 WhiteSpaceNormal, but no automatic line-breaks occur. To break 122 WhiteSpaceNormal, but no automatic line-breaks occur. To break
125 lines manually, use the \c{<br>} tag. 123 lines manually, use the \c{<br>} tag.
126 124
127*/ 125*/
128 126
129/*! 127/*!
130 \enum QStyleSheetItem::Margin 128 \enum QStyleSheetItem::Margin
131 129
132 \value MarginLeft left margin 130 \value MarginLeft left margin
133 \value MarginRight right margin 131 \value MarginRight right margin
134 \value MarginTop top margin 132 \value MarginTop top margin
135 \value MarginBottom bottom margin 133 \value MarginBottom bottom margin
136 \value MarginAll all margins (left, right, top and bottom) 134 \value MarginAll all margins (left, right, top and bottom)
137 \value MarginVertical top and bottom margins 135 \value MarginVertical top and bottom margins
138 \value MarginHorizontal left and right margins 136 \value MarginHorizontal left and right margins
139 \value MarginFirstLine margin (indentation) of the first line of 137 \value MarginFirstLine margin (indentation) of the first line of
140 a paragarph (in addition to the MarginLeft of the paragraph) 138 a paragarph (in addition to the MarginLeft of the paragraph)
141*/ 139*/
142 140
143/*! 141/*!
144 Constructs a new style called \a name for the stylesheet \a 142 Constructs a new style called \a name for the stylesheet \a
145 parent. 143 parent.
146 144
147 All properties in QStyleSheetItem are initially in the "do not 145 All properties in QStyleSheetItem are initially in the "do not
148 change" state, except \link QStyleSheetItem::DisplayMode display 146 change" state, except \link QStyleSheetItem::DisplayMode display
149 mode\endlink, which defaults to \c DisplayInline. 147 mode\endlink, which defaults to \c DisplayInline.
150*/ 148*/
151QStyleSheetItem::QStyleSheetItem( QStyleSheet* parent, const QString& name ) 149QStyleSheetItem::QStyleSheetItem( QStyleSheet* parent, const QString& name )
152{ 150{
153 d = new QStyleSheetItemData; 151 d = new QStyleSheetItemData;
154 d->stylename = name.lower(); 152 d->stylename = name.lower();
155 d->sheet = parent; 153 d->sheet = parent;
156 init(); 154 init();
157 if (parent) 155 if (parent)
158 parent->insert( this ); 156 parent->insert( this );
159} 157}
160 158
161/*! 159/*!
162 Copy constructor. Constructs a copy of \a other that is not bound 160 Copy constructor. Constructs a copy of \a other that is not bound
163 to any style sheet. 161 to any style sheet.
164*/ 162*/
165QStyleSheetItem::QStyleSheetItem( const QStyleSheetItem & other ) 163QStyleSheetItem::QStyleSheetItem( const QStyleSheetItem & other )
166{ 164{
167 d = new QStyleSheetItemData; 165 d = new QStyleSheetItemData;
168 *d = *other.d; 166 *d = *other.d;
169} 167}
170 168
171 169
172/*! 170/*!
173 Destroys the style. Note that QStyleSheetItem objects become 171 Destroys the style. Note that QStyleSheetItem objects become
174 owned by QStyleSheet when they are created. 172 owned by QStyleSheet when they are created.
175*/ 173*/
176QStyleSheetItem::~QStyleSheetItem() 174QStyleSheetItem::~QStyleSheetItem()
177{ 175{
178 delete d; 176 delete d;
179} 177}
180 178
181 179
182 180
183/*! 181/*!
184 Returns the style sheet this item is in. 182 Returns the style sheet this item is in.
185*/ 183*/
186QStyleSheet* QStyleSheetItem::styleSheet() 184QStyleSheet* QStyleSheetItem::styleSheet()
187{ 185{
188 return d->sheet; 186 return d->sheet;
189} 187}
190 188
191/*! 189/*!
192 \overload 190 \overload
193 191
194 Returns the style sheet this item is in. 192 Returns the style sheet this item is in.
195*/ 193*/
196const QStyleSheet* QStyleSheetItem::styleSheet() const 194const QStyleSheet* QStyleSheetItem::styleSheet() const
197{ 195{
198 return d->sheet; 196 return d->sheet;
199} 197}
200 198
201/*! 199/*!
202 \internal 200 \internal
203 Internal initialization 201 Internal initialization
204 */ 202 */
205void QStyleSheetItem::init() 203void QStyleSheetItem::init()
206{ 204{
207 d->disp = DisplayInline; 205 d->disp = DisplayInline;
208 206
209 d->fontitalic = Undefined; 207 d->fontitalic = Undefined;
210 d->fontunderline = Undefined; 208 d->fontunderline = Undefined;
211 d->fontstrikeout = Undefined; 209 d->fontstrikeout = Undefined;
212 d->fontweight = Undefined; 210 d->fontweight = Undefined;
213 d->fontsize = Undefined; 211 d->fontsize = Undefined;
214 d->fontsizelog = Undefined; 212 d->fontsizelog = Undefined;
215 d->fontsizestep = 0; 213 d->fontsizestep = 0;
216 d->ncolumns = Undefined; 214 d->ncolumns = Undefined;
217 d->col = QColor(); // !isValid() 215 d->col = QColor(); // !isValid()
218 d->anchor = FALSE; 216 d->anchor = FALSE;
219 d->align = Undefined; 217 d->align = Undefined;
220 d->valign = VAlignBaseline; 218 d->valign = VAlignBaseline;
221 d->margin[0] = Undefined; 219 d->margin[0] = Undefined;
222 d->margin[1] = Undefined; 220 d->margin[1] = Undefined;
223 d->margin[2] = Undefined; 221 d->margin[2] = Undefined;
224 d->margin[3] = Undefined; 222 d->margin[3] = Undefined;
225 d->margin[4] = Undefined; 223 d->margin[4] = Undefined;
226 d->list = (ListStyle) Undefined; 224 d->list = (ListStyle) Undefined;
227 d->whitespacemode = (WhiteSpaceMode) Undefined; 225 d->whitespacemode = (WhiteSpaceMode) Undefined;
228 d->selfnest = TRUE; 226 d->selfnest = TRUE;
229 d->lineSpacing = Undefined; 227 d->lineSpacing = Undefined;
230} 228}
231 229
232/*! 230/*!
233 Returns the name of the style item. 231 Returns the name of the style item.
234*/ 232*/
235QString QStyleSheetItem::name() const 233QString QStyleSheetItem::name() const
236{ 234{
237 return d->stylename; 235 return d->stylename;
238} 236}
239 237
240/*! 238/*!
241 Returns the \link QStyleSheetItem::DisplayMode display 239 Returns the \link QStyleSheetItem::DisplayMode display
242 mode\endlink of the style. 240 mode\endlink of the style.
243 241
244 \sa setDisplayMode() 242 \sa setDisplayMode()
245*/ 243*/
246QStyleSheetItem::DisplayMode QStyleSheetItem::displayMode() const 244QStyleSheetItem::DisplayMode QStyleSheetItem::displayMode() const
247{ 245{
248 return d->disp; 246 return d->disp;
249} 247}
250 248
251/*! 249/*!
252 \enum QStyleSheetItem::DisplayMode 250 \enum QStyleSheetItem::DisplayMode
253 251
254 This enum type defines the way adjacent elements are displayed. 252 This enum type defines the way adjacent elements are displayed.
255 253
256 \value DisplayBlock elements are displayed as a rectangular block 254 \value DisplayBlock elements are displayed as a rectangular block
257 (e.g. \c{<p>...</p>}). 255 (e.g. \c{<p>...</p>}).
258 256
259 \value DisplayInline elements are displayed in a horizontally 257 \value DisplayInline elements are displayed in a horizontally
260 flowing sequence (e.g. \c{<em>...</em>}). 258 flowing sequence (e.g. \c{<em>...</em>}).
261 259
262 \value DisplayListItem elements are displayed in a vertical 260 \value DisplayListItem elements are displayed in a vertical
263 sequence (e.g. \c{<li>...</li>}). 261 sequence (e.g. \c{<li>...</li>}).
264 262
265 \value DisplayNone elements are not displayed at all. 263 \value DisplayNone elements are not displayed at all.
266*/ 264*/
267 265
268/*! 266/*!
269 Sets the display mode of the style to \a m. 267 Sets the display mode of the style to \a m.
270 268
271 \sa displayMode() 269 \sa displayMode()
272 */ 270 */
273void QStyleSheetItem::setDisplayMode(DisplayMode m) 271void QStyleSheetItem::setDisplayMode(DisplayMode m)
274{ 272{
275 d->disp=m; 273 d->disp=m;
276} 274}
277 275
278 276
279/*! 277/*!
280 Returns the alignment of this style. Possible values are \c 278 Returns the alignment of this style. Possible values are \c
281 AlignAuto, \c AlignLeft, \c AlignRight, \c AlignCenter or \c 279 AlignAuto, \c AlignLeft, \c AlignRight, \c AlignCenter or \c
282 AlignJustify. 280 AlignJustify.
283 281
284 \sa setAlignment(), Qt::AlignmentFlags 282 \sa setAlignment(), Qt::AlignmentFlags
285*/ 283*/
286int QStyleSheetItem::alignment() const 284int QStyleSheetItem::alignment() const
287{ 285{
288 return d->align; 286 return d->align;
289} 287}
290 288
291/*! 289/*!
292 Sets the alignment to \a f. This only makes sense for styles with 290 Sets the alignment to \a f. This only makes sense for styles with
293 a \link QStyleSheetItem::DisplayMode display mode\endlink of 291 a \link QStyleSheetItem::DisplayMode display mode\endlink of
294 DisplayBlock. Possible values are \c AlignAuto, \c AlignLeft, 292 DisplayBlock. Possible values are \c AlignAuto, \c AlignLeft,
295 \c AlignRight, \c AlignCenter or \c AlignJustify. 293 \c AlignRight, \c AlignCenter or \c AlignJustify.
296 294
297 \sa alignment(), displayMode(), Qt::AlignmentFlags 295 \sa alignment(), displayMode(), Qt::AlignmentFlags
298*/ 296*/
299void QStyleSheetItem::setAlignment( int f ) 297void QStyleSheetItem::setAlignment( int f )
300{ 298{
301 d->align = f; 299 d->align = f;
302} 300}
303 301
304 302
305/*! 303/*!
306 Returns the vertical alignment of the style. Possible values are 304 Returns the vertical alignment of the style. Possible values are
307 \c VAlignBaseline, \c VAlignSub or \c VAlignSuper. 305 \c VAlignBaseline, \c VAlignSub or \c VAlignSuper.
308 306
309 \sa setVerticalAlignment() 307 \sa setVerticalAlignment()
310*/ 308*/
311QStyleSheetItem::VerticalAlignment QStyleSheetItem::verticalAlignment() const 309QStyleSheetItem::VerticalAlignment QStyleSheetItem::verticalAlignment() const
312{ 310{
313 return d->valign; 311 return d->valign;
314} 312}
315 313
316/*! 314/*!
317 \enum QStyleSheetItem::VerticalAlignment 315 \enum QStyleSheetItem::VerticalAlignment
318 316
319 This enum type defines the way elements are aligned vertically. 317 This enum type defines the way elements are aligned vertically.
320 This is only supported for text elements. 318 This is only supported for text elements.
321 319
322 \value VAlignBaseline align the baseline of the element (or the 320 \value VAlignBaseline align the baseline of the element (or the
323 bottom, if the element doesn't have a baseline) with the 321 bottom, if the element doesn't have a baseline) with the
324 baseline of the parent 322 baseline of the parent
325 323
326 \value VAlignSub subscript the element 324 \value VAlignSub subscript the element
327 325
328 \value VAlignSuper superscript the element 326 \value VAlignSuper superscript the element
329 327
330*/ 328*/
331 329
332 330
333/*! 331/*!
334 Sets the vertical alignment to \a valign. Possible values are 332 Sets the vertical alignment to \a valign. Possible values are
335 \c VAlignBaseline, \c VAlignSub or \c VAlignSuper. 333 \c VAlignBaseline, \c VAlignSub or \c VAlignSuper.
336 334
337 The vertical alignment property is not inherited. 335 The vertical alignment property is not inherited.
338 336
339 \sa verticalAlignment() 337 \sa verticalAlignment()
340*/ 338*/
341void QStyleSheetItem::setVerticalAlignment( VerticalAlignment valign ) 339void QStyleSheetItem::setVerticalAlignment( VerticalAlignment valign )
342{ 340{
343 d->valign = valign; 341 d->valign = valign;
344} 342}
345 343
346 344
347/*! 345/*!
348 Returns TRUE if the style sets an italic font; otherwise returns 346 Returns TRUE if the style sets an italic font; otherwise returns
349 FALSE. 347 FALSE.
350 348
351 \sa setFontItalic(), definesFontItalic() 349 \sa setFontItalic(), definesFontItalic()
352*/ 350*/
353bool QStyleSheetItem::fontItalic() const 351bool QStyleSheetItem::fontItalic() const
354{ 352{
355 return d->fontitalic > 0; 353 return d->fontitalic > 0;
356} 354}
357 355
358/*! 356/*!
359 If \a italic is TRUE sets italic for the style; otherwise sets 357 If \a italic is TRUE sets italic for the style; otherwise sets
360 upright. 358 upright.
361 359
362 \sa fontItalic(), definesFontItalic() 360 \sa fontItalic(), definesFontItalic()
363*/ 361*/
364void QStyleSheetItem::setFontItalic(bool italic) 362void QStyleSheetItem::setFontItalic(bool italic)
365{ 363{
366 d->fontitalic = italic?1:0; 364 d->fontitalic = italic?1:0;
367} 365}
368 366
369/*! 367/*!
370 Returns TRUE if the style defines a font shape; otherwise returns 368 Returns TRUE if the style defines a font shape; otherwise returns
371 FALSE. A style does not define any shape until setFontItalic() is 369 FALSE. A style does not define any shape until setFontItalic() is
372 called. 370 called.
373 371
374 \sa setFontItalic(), fontItalic() 372 \sa setFontItalic(), fontItalic()
375*/ 373*/
376bool QStyleSheetItem::definesFontItalic() const 374bool QStyleSheetItem::definesFontItalic() const
377{ 375{
378 return d->fontitalic != Undefined; 376 return d->fontitalic != Undefined;
379} 377}
380 378
381/*! 379/*!
382 Returns TRUE if the style sets an underlined font; otherwise 380 Returns TRUE if the style sets an underlined font; otherwise
383 returns FALSE. 381 returns FALSE.
384 382
385 \sa setFontUnderline(), definesFontUnderline() 383 \sa setFontUnderline(), definesFontUnderline()
386*/ 384*/
387bool QStyleSheetItem::fontUnderline() const 385bool QStyleSheetItem::fontUnderline() const
388{ 386{
389 return d->fontunderline > 0; 387 return d->fontunderline > 0;
390} 388}
391 389
392/*! 390/*!
393 If \a underline is TRUE, sets underline for the style; otherwise 391 If \a underline is TRUE, sets underline for the style; otherwise
394 sets no underline. 392 sets no underline.
395 393
396 \sa fontUnderline(), definesFontUnderline() 394 \sa fontUnderline(), definesFontUnderline()
397*/ 395*/
398void QStyleSheetItem::setFontUnderline(bool underline) 396void QStyleSheetItem::setFontUnderline(bool underline)
399{ 397{
400 d->fontunderline = underline?1:0; 398 d->fontunderline = underline?1:0;
401} 399}
402 400
403/*! 401/*!
404 Returns TRUE if the style defines a setting for the underline 402 Returns TRUE if the style defines a setting for the underline
405 property of the font; otherwise returns FALSE. A style does not 403 property of the font; otherwise returns FALSE. A style does not
406 define this until setFontUnderline() is called. 404 define this until setFontUnderline() is called.
407 405
408 \sa setFontUnderline(), fontUnderline() 406 \sa setFontUnderline(), fontUnderline()
409*/ 407*/
410bool QStyleSheetItem::definesFontUnderline() const 408bool QStyleSheetItem::definesFontUnderline() const
411{ 409{
412 return d->fontunderline != Undefined; 410 return d->fontunderline != Undefined;
413} 411}
414 412
415 413
416/*! 414/*!
417 Returns TRUE if the style sets a strike out font; otherwise 415 Returns TRUE if the style sets a strike out font; otherwise
418 returns FALSE. 416 returns FALSE.
419 417
420 \sa setFontStrikeOut(), definesFontStrikeOut() 418 \sa setFontStrikeOut(), definesFontStrikeOut()
421*/ 419*/
422bool QStyleSheetItem::fontStrikeOut() const 420bool QStyleSheetItem::fontStrikeOut() const
423{ 421{
424 return d->fontstrikeout > 0; 422 return d->fontstrikeout > 0;
425} 423}
426 424
427/*! 425/*!
428 If \a strikeOut is TRUE, sets strike out for the style; otherwise 426 If \a strikeOut is TRUE, sets strike out for the style; otherwise
429 sets no strike out. 427 sets no strike out.
430 428
431 \sa fontStrikeOut(), definesFontStrikeOut() 429 \sa fontStrikeOut(), definesFontStrikeOut()
432*/ 430*/
433void QStyleSheetItem::setFontStrikeOut(bool strikeOut) 431void QStyleSheetItem::setFontStrikeOut(bool strikeOut)
434{ 432{
435 d->fontstrikeout = strikeOut?1:0; 433 d->fontstrikeout = strikeOut?1:0;
436} 434}
437 435
438/*! 436/*!
439 Returns TRUE if the style defines a setting for the strikeOut 437 Returns TRUE if the style defines a setting for the strikeOut
440 property of the font; otherwise returns FALSE. A style does not 438 property of the font; otherwise returns FALSE. A style does not
441 define this until setFontStrikeOut() is called. 439 define this until setFontStrikeOut() is called.
442 440
443 \sa setFontStrikeOut(), fontStrikeOut() 441 \sa setFontStrikeOut(), fontStrikeOut()
444*/ 442*/
445bool QStyleSheetItem::definesFontStrikeOut() const 443bool QStyleSheetItem::definesFontStrikeOut() const
446{ 444{
447 return d->fontstrikeout != Undefined; 445 return d->fontstrikeout != Undefined;
448} 446}
449 447
450 448
451/*! 449/*!
452 Returns the font weight setting of the style. This is either a 450 Returns the font weight setting of the style. This is either a
453 valid \c QFont::Weight or the value \c QStyleSheetItem::Undefined. 451 valid \c QFont::Weight or the value \c QStyleSheetItem::Undefined.
454 452
455 \sa setFontWeight(), QFont 453 \sa setFontWeight(), QFont
456*/ 454*/
457int QStyleSheetItem::fontWeight() const 455int QStyleSheetItem::fontWeight() const
458{ 456{
459 return d->fontweight; 457 return d->fontweight;
460} 458}
461 459
462/*! 460/*!
463 Sets the font weight setting of the style to \a w. Valid values 461 Sets the font weight setting of the style to \a w. Valid values
464 are those defined by \c QFont::Weight. 462 are those defined by \c QFont::Weight.
465 463
466 \sa QFont, fontWeight() 464 \sa QFont, fontWeight()
467*/ 465*/
468void QStyleSheetItem::setFontWeight(int w) 466void QStyleSheetItem::setFontWeight(int w)
469{ 467{
470 d->fontweight = w; 468 d->fontweight = w;
471} 469}
472 470
473/*! 471/*!
474 Returns the logical font size setting of the style. This is either 472 Returns the logical font size setting of the style. This is either
475 a valid size between 1 and 7 or \c QStyleSheetItem::Undefined. 473 a valid size between 1 and 7 or \c QStyleSheetItem::Undefined.
476 474
477 \sa setLogicalFontSize(), setLogicalFontSizeStep(), QFont::pointSize(), QFont::setPointSize() 475 \sa setLogicalFontSize(), setLogicalFontSizeStep(), QFont::pointSize(), QFont::setPointSize()
478*/ 476*/
479int QStyleSheetItem::logicalFontSize() const 477int QStyleSheetItem::logicalFontSize() const
480{ 478{
481 return d->fontsizelog; 479 return d->fontsizelog;
482} 480}
483 481
484 482
485/*! 483/*!
486 Sets the logical font size setting of the style to \a s. Valid 484 Sets the logical font size setting of the style to \a s. Valid
487 logical sizes are 1 to 7. 485 logical sizes are 1 to 7.
488 486
489 \sa logicalFontSize(), QFont::pointSize(), QFont::setPointSize() 487 \sa logicalFontSize(), QFont::pointSize(), QFont::setPointSize()
490*/ 488*/
491void QStyleSheetItem::setLogicalFontSize(int s) 489void QStyleSheetItem::setLogicalFontSize(int s)
492{ 490{
493 d->fontsizelog = s; 491 d->fontsizelog = s;
494} 492}
495 493
496/*! 494/*!
497 Returns the logical font size step of this style. 495 Returns the logical font size step of this style.
498 496
499 The default is 0. Tags such as \c big define \c +1; \c small 497 The default is 0. Tags such as \c big define \c +1; \c small
500 defines \c -1. 498 defines \c -1.
501 499
502 \sa setLogicalFontSizeStep() 500 \sa setLogicalFontSizeStep()
503*/ 501*/
504int QStyleSheetItem::logicalFontSizeStep() const 502int QStyleSheetItem::logicalFontSizeStep() const
505{ 503{
506 return d->fontsizestep; 504 return d->fontsizestep;
507} 505}
508 506
509/*! 507/*!
510 Sets the logical font size step of this style to \a s. 508 Sets the logical font size step of this style to \a s.
511 509
512 \sa logicalFontSizeStep() 510 \sa logicalFontSizeStep()
513*/ 511*/
514void QStyleSheetItem::setLogicalFontSizeStep( int s ) 512void QStyleSheetItem::setLogicalFontSizeStep( int s )
515{ 513{
516 d->fontsizestep = s; 514 d->fontsizestep = s;
517} 515}
518 516
519 517
520 518
521/*! 519/*!
522 Sets the font size setting of the style to \a s points. 520 Sets the font size setting of the style to \a s points.
523 521
524 \sa fontSize(), QFont::pointSize(), QFont::setPointSize() 522 \sa fontSize(), QFont::pointSize(), QFont::setPointSize()
525*/ 523*/
526void QStyleSheetItem::setFontSize(int s) 524void QStyleSheetItem::setFontSize(int s)
527{ 525{
528 d->fontsize = s; 526 d->fontsize = s;
529} 527}
530 528
531/*! 529/*!
532 Returns the font size setting of the style. This is either a valid 530 Returns the font size setting of the style. This is either a valid
533 point size or \c QStyleSheetItem::Undefined. 531 point size or \c QStyleSheetItem::Undefined.
534 532
535 \sa setFontSize(), QFont::pointSize(), QFont::setPointSize() 533 \sa setFontSize(), QFont::pointSize(), QFont::setPointSize()
536*/ 534*/
537int QStyleSheetItem::fontSize() const 535int QStyleSheetItem::fontSize() const
538{ 536{
539 return d->fontsize; 537 return d->fontsize;
540} 538}
541 539
542 540
543/*! 541/*!
544 Returns the font family setting of the style. This is either a 542 Returns the font family setting of the style. This is either a
545 valid font family or QString::null if no family has been set. 543 valid font family or QString::null if no family has been set.
546 544
547 \sa setFontFamily(), QFont::family(), QFont::setFamily() 545 \sa setFontFamily(), QFont::family(), QFont::setFamily()
548*/ 546*/
549QString QStyleSheetItem::fontFamily() const 547QString QStyleSheetItem::fontFamily() const
550{ 548{
551 return d->fontfamily; 549 return d->fontfamily;
552} 550}
553 551
554/*! 552/*!
555 Sets the font family setting of the style to \a fam. 553 Sets the font family setting of the style to \a fam.
556 554
557 \sa fontFamily(), QFont::family(), QFont::setFamily() 555 \sa fontFamily(), QFont::family(), QFont::setFamily()
558*/ 556*/
559void QStyleSheetItem::setFontFamily( const QString& fam) 557void QStyleSheetItem::setFontFamily( const QString& fam)
560{ 558{
561 d->fontfamily = fam; 559 d->fontfamily = fam;
562} 560}
563 561
564 562
565/*!\obsolete 563/*!\obsolete
566 Returns the number of columns for this style. 564 Returns the number of columns for this style.
567 565
568 \sa setNumberOfColumns(), displayMode(), setDisplayMode() 566 \sa setNumberOfColumns(), displayMode(), setDisplayMode()
569 567
570 */ 568 */
571int QStyleSheetItem::numberOfColumns() const 569int QStyleSheetItem::numberOfColumns() const
572{ 570{
573 return d->ncolumns; 571 return d->ncolumns;
574} 572}
575 573
576 574
577/*!\obsolete 575/*!\obsolete
578 Sets the number of columns for this style. Elements in the style 576 Sets the number of columns for this style. Elements in the style
579 are divided into columns. 577 are divided into columns.
580 578
581 This makes sense only if the style uses a block display mode 579 This makes sense only if the style uses a block display mode
582 (see QStyleSheetItem::DisplayMode). 580 (see QStyleSheetItem::DisplayMode).
583 581
584 \sa numberOfColumns() 582 \sa numberOfColumns()
585 */ 583 */
586void QStyleSheetItem::setNumberOfColumns(int ncols) 584void QStyleSheetItem::setNumberOfColumns(int ncols)
587{ 585{
588 if (ncols > 0) 586 if (ncols > 0)
589 d->ncolumns = ncols; 587 d->ncolumns = ncols;
590} 588}
591 589
592 590
593/*! 591/*!
594 Returns the text color of this style or an invalid color if no 592 Returns the text color of this style or an invalid color if no
595 color has been set. 593 color has been set.
596 594
597 \sa setColor() QColor::isValid() 595 \sa setColor() QColor::isValid()
598*/ 596*/
599QColor QStyleSheetItem::color() const 597QColor QStyleSheetItem::color() const
600{ 598{
601 return d->col; 599 return d->col;
602} 600}
603 601
604/*! 602/*!
605 Sets the text color of this style to \a c. 603 Sets the text color of this style to \a c.
606 604
607 \sa color() 605 \sa color()
608*/ 606*/
609void QStyleSheetItem::setColor( const QColor &c) 607void QStyleSheetItem::setColor( const QColor &c)
610{ 608{
611 d->col = c; 609 d->col = c;
612} 610}
613 611
614/*! 612/*!
615 Returns whether this style is an anchor. 613 Returns whether this style is an anchor.
616 614
617 \sa setAnchor() 615 \sa setAnchor()
618*/ 616*/
619bool QStyleSheetItem::isAnchor() const 617bool QStyleSheetItem::isAnchor() const
620{ 618{
621 return d->anchor; 619 return d->anchor;
622} 620}
623 621
624/*! 622/*!
625 If \a anc is TRUE, sets this style to be an anchor (hypertext 623 If \a anc is TRUE, sets this style to be an anchor (hypertext
626 link); otherwise sets it to not be an anchor. Elements in this 624 link); otherwise sets it to not be an anchor. Elements in this
627 style link to other documents or anchors. 625 style link to other documents or anchors.
628 626
629 \sa isAnchor() 627 \sa isAnchor()
630*/ 628*/
631void QStyleSheetItem::setAnchor(bool anc) 629void QStyleSheetItem::setAnchor(bool anc)
632{ 630{
633 d->anchor = anc; 631 d->anchor = anc;
634} 632}
635 633
636 634
637/*! 635/*!
638 Returns the whitespace mode. 636 Returns the whitespace mode.
639 637
640 \sa setWhiteSpaceMode() WhiteSpaceMode 638 \sa setWhiteSpaceMode() WhiteSpaceMode
641*/ 639*/
642QStyleSheetItem::WhiteSpaceMode QStyleSheetItem::whiteSpaceMode() const 640QStyleSheetItem::WhiteSpaceMode QStyleSheetItem::whiteSpaceMode() const
643{ 641{
644 return d->whitespacemode; 642 return d->whitespacemode;
645} 643}
646 644
647/*! 645/*!
648 Sets the whitespace mode to \a m. 646 Sets the whitespace mode to \a m.
649 647
650 \sa WhiteSpaceMode 648 \sa WhiteSpaceMode
651*/ 649*/
652void QStyleSheetItem::setWhiteSpaceMode(WhiteSpaceMode m) 650void QStyleSheetItem::setWhiteSpaceMode(WhiteSpaceMode m)
653{ 651{
654 d->whitespacemode = m; 652 d->whitespacemode = m;
655} 653}
656 654
657 655
658/*! 656/*!
659 Returns the width of margin \a m in pixels. 657 Returns the width of margin \a m in pixels.
660 658
661 The margin, \a m, can be \c MarginLeft, \c MarginRight, \c 659 The margin, \a m, can be \c MarginLeft, \c MarginRight, \c
662 MarginTop, \c MarginBottom, \c MarginAll, \c MarginVertical or \c 660 MarginTop, \c MarginBottom, \c MarginAll, \c MarginVertical or \c
663 MarginHorizontal. 661 MarginHorizontal.
664 662
665 \sa setMargin() Margin 663 \sa setMargin() Margin
666*/ 664*/
667int QStyleSheetItem::margin(Margin m) const 665int QStyleSheetItem::margin(Margin m) const
668{ 666{
669 return d->margin[m]; 667 return d->margin[m];
670} 668}
671 669
672 670
673/*! 671/*!
674 Sets the width of margin \a m to \a v pixels. 672 Sets the width of margin \a m to \a v pixels.
675 673
676 The margin, \a m, can be \c MarginLeft, \c MarginRight, \c 674 The margin, \a m, can be \c MarginLeft, \c MarginRight, \c
677 MarginTop, \c MarginBottom, \c MarginAll, \c MarginVertical or \c 675 MarginTop, \c MarginBottom, \c MarginAll, \c MarginVertical or \c
678 MarginHorizontal. The value \a v must be >= 0. 676 MarginHorizontal. The value \a v must be >= 0.
679 677
680 \sa margin() 678 \sa margin()
681*/ 679*/
682void QStyleSheetItem::setMargin(Margin m, int v) 680void QStyleSheetItem::setMargin(Margin m, int v)
683{ 681{
684 if (m == MarginAll ) { 682 if (m == MarginAll ) {
685 d->margin[0] = v; 683 d->margin[0] = v;
686 d->margin[1] = v; 684 d->margin[1] = v;
687 d->margin[2] = v; 685 d->margin[2] = v;
688 d->margin[3] = v; 686 d->margin[3] = v;
689 d->margin[4] = v; 687 d->margin[4] = v;
690 } else if (m == MarginVertical ) { 688 } else if (m == MarginVertical ) {
691 d->margin[MarginTop] = v; 689 d->margin[MarginTop] = v;
692 d->margin[MarginBottom] = v; 690 d->margin[MarginBottom] = v;
693 } else if (m == MarginHorizontal ) { 691 } else if (m == MarginHorizontal ) {
694 d->margin[MarginLeft] = v; 692 d->margin[MarginLeft] = v;
695 d->margin[MarginRight] = v; 693 d->margin[MarginRight] = v;
696 } else { 694 } else {
697 d->margin[m] = v; 695 d->margin[m] = v;
698 } 696 }
699} 697}
700 698
701 699
702/*! 700/*!
703 Returns the list style of the style. 701 Returns the list style of the style.
704 702
705 \sa setListStyle() ListStyle 703 \sa setListStyle() ListStyle
706 */ 704 */
707QStyleSheetItem::ListStyle QStyleSheetItem::listStyle() const 705QStyleSheetItem::ListStyle QStyleSheetItem::listStyle() const
708{ 706{
709 return d->list; 707 return d->list;
710} 708}
711 709
712/*! 710/*!
713 \enum QStyleSheetItem::ListStyle 711 \enum QStyleSheetItem::ListStyle
714 712
715 This enum type defines how the items in a list are prefixed when 713 This enum type defines how the items in a list are prefixed when
716 displayed. 714 displayed.
717 715
718 \value ListDisc a filled circle (i.e. a bullet) 716 \value ListDisc a filled circle (i.e. a bullet)
719 \value ListCircle an unfilled circle 717 \value ListCircle an unfilled circle
720 \value ListSquare a filled square 718 \value ListSquare a filled square
721 \value ListDecimal an integer in base 10: \e 1, \e 2, \e 3, ... 719 \value ListDecimal an integer in base 10: \e 1, \e 2, \e 3, ...
722 \value ListLowerAlpha a lowercase letter: \e a, \e b, \e c, ... 720 \value ListLowerAlpha a lowercase letter: \e a, \e b, \e c, ...
723 \value ListUpperAlpha an uppercase letter: \e A, \e B, \e C, ... 721 \value ListUpperAlpha an uppercase letter: \e A, \e B, \e C, ...
724*/ 722*/
725 723
726/*! 724/*!
727 Sets the list style of the style to \a s. 725 Sets the list style of the style to \a s.
728 726
729 This is used by nested elements that have a display mode of \c 727 This is used by nested elements that have a display mode of \c
730 DisplayListItem. 728 DisplayListItem.
731 729
732 \sa listStyle() DisplayMode ListStyle 730 \sa listStyle() DisplayMode ListStyle
733*/ 731*/
734void QStyleSheetItem::setListStyle(ListStyle s) 732void QStyleSheetItem::setListStyle(ListStyle s)
735{ 733{
736 d->list=s; 734 d->list=s;
737} 735}
738 736
739 737
740/*! 738/*!
741 Returns a space-separated list of names of styles that may contain 739 Returns a space-separated list of names of styles that may contain
742 elements of this style. If nothing has been set, contexts() 740 elements of this style. If nothing has been set, contexts()
743 returns an empty string, which indicates that this style can be 741 returns an empty string, which indicates that this style can be
744 nested everywhere. 742 nested everywhere.
745 743
746 \sa setContexts() 744 \sa setContexts()
747*/ 745*/
748QString QStyleSheetItem::contexts() const 746QString QStyleSheetItem::contexts() const
749{ 747{
750 return d->contxt; 748 return d->contxt;
751} 749}
752 750
753/*! 751/*!
754 Sets a space-separated list of names of styles that may contain 752 Sets a space-separated list of names of styles that may contain
755 elements of this style. If \a c is empty, the style can be nested 753 elements of this style. If \a c is empty, the style can be nested
756 everywhere. 754 everywhere.
757 755
758 \sa contexts() 756 \sa contexts()
759*/ 757*/
760void QStyleSheetItem::setContexts( const QString& c) 758void QStyleSheetItem::setContexts( const QString& c)
761{ 759{
762 d->contxt = QChar(' ') + c + QChar(' '); 760 d->contxt = QChar(' ') + c + QChar(' ');
763} 761}
764 762
765/*! 763/*!
766 Returns TRUE if this style can be nested into an element of style 764 Returns TRUE if this style can be nested into an element of style
767 \a s; otherwise returns FALSE. 765 \a s; otherwise returns FALSE.
768 766
769 \sa contexts(), setContexts() 767 \sa contexts(), setContexts()
770*/ 768*/
771bool QStyleSheetItem::allowedInContext( const QStyleSheetItem* s) const 769bool QStyleSheetItem::allowedInContext( const QStyleSheetItem* s) const
772{ 770{
773 if ( d->contxt.isEmpty() ) 771 if ( d->contxt.isEmpty() )
774 return TRUE; 772 return TRUE;
775 return d->contxt.find( QChar(' ')+s->name()+QChar(' ')) != -1; 773 return d->contxt.find( QChar(' ')+s->name()+QChar(' ')) != -1;
776} 774}
777 775
778 776
779/*! 777/*!
780 Returns TRUE if this style has self-nesting enabled; otherwise 778 Returns TRUE if this style has self-nesting enabled; otherwise
781 returns FALSE. 779 returns FALSE.
782 780
783 \sa setSelfNesting() 781 \sa setSelfNesting()
784*/ 782*/
785bool QStyleSheetItem::selfNesting() const 783bool QStyleSheetItem::selfNesting() const
786{ 784{
787 return d->selfnest; 785 return d->selfnest;
788} 786}
789 787
790/*! 788/*!
791 Sets the self-nesting property for this style to \a nesting. 789 Sets the self-nesting property for this style to \a nesting.
792 790
793 In order to support "dirty" HTML, paragraphs \c{<p>} and list 791 In order to support "dirty" HTML, paragraphs \c{<p>} and list
794 items \c{<li>} are not self-nesting. This means that starting a 792 items \c{<li>} are not self-nesting. This means that starting a
795 new paragraph or list item automatically closes the previous one. 793 new paragraph or list item automatically closes the previous one.
796 794
797 \sa selfNesting() 795 \sa selfNesting()
798*/ 796*/
799void QStyleSheetItem::setSelfNesting( bool nesting ) 797void QStyleSheetItem::setSelfNesting( bool nesting )
800{ 798{
801 d->selfnest = nesting; 799 d->selfnest = nesting;
802} 800}
803 801
804/* 802/*
805 Sets the linespacing to be at least \a ls pixels. 803 Sets the linespacing to be at least \a ls pixels.
806 804
807 For compatibility with previous Qt releases, small values get 805 For compatibility with previous Qt releases, small values get
808 treated differently: If \a ls is smaller than the default font 806 treated differently: If \a ls is smaller than the default font
809 line spacing in pixels at parse time, the resulting line spacing 807 line spacing in pixels at parse time, the resulting line spacing
810 is the sum of the default line spacing plus \a ls. We recommend 808 is the sum of the default line spacing plus \a ls. We recommend
diff --git a/noncore/apps/opie-write/qtextedit.cpp b/noncore/apps/opie-write/qtextedit.cpp
index 82401c6..27dd515 100644
--- a/noncore/apps/opie-write/qtextedit.cpp
+++ b/noncore/apps/opie-write/qtextedit.cpp
@@ -1,830 +1,810 @@
1/**************************************************************************** 1/****************************************************************************
2** $Id$ 2** $Id$
3** 3**
4** Implementation of the QTextEdit class 4** Implementation of the QTextEdit class
5** 5**
6** Created : 990101 6** Created : 990101
7** 7**
8** Copyright (C) 1992-2000 Trolltech AS. All rights reserved. 8** Copyright (C) 1992-2000 Trolltech AS. All rights reserved.
9** 9**
10** This file is part of the widgets module of the Qt GUI Toolkit. 10** This file is part of the widgets module of the Qt GUI Toolkit.
11** 11**
12** This file may be distributed under the terms of the Q Public License 12** This file may be distributed under the terms of the Q Public License
13** as defined by Trolltech AS of Norway and appearing in the file 13** as defined by Trolltech AS of Norway and appearing in the file
14** LICENSE.QPL included in the packaging of this file. 14** LICENSE.QPL included in the packaging of this file.
15** 15**
16** This file may be distributed and/or modified under the terms of the 16** This file may be distributed and/or modified under the terms of the
17** GNU General Public License version 2 as published by the Free Software 17** GNU General Public License version 2 as published by the Free Software
18** Foundation and appearing in the file LICENSE.GPL included in the 18** Foundation and appearing in the file LICENSE.GPL included in the
19** packaging of this file. 19** packaging of this file.
20** 20**
21** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition 21** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
22** licenses may use this file in accordance with the Qt Commercial License 22** licenses may use this file in accordance with the Qt Commercial License
23** Agreement provided with the Software. 23** Agreement provided with the Software.
24** 24**
25** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 25** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
26** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 26** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
27** 27**
28** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for 28** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
29** information about Qt Commercial License Agreements. 29** information about Qt Commercial License Agreements.
30** See http://www.trolltech.com/qpl/ for QPL licensing information. 30** See http://www.trolltech.com/qpl/ for QPL licensing information.
31** See http://www.trolltech.com/gpl/ for GPL licensing information. 31** See http://www.trolltech.com/gpl/ for GPL licensing information.
32** 32**
33** Contact info@trolltech.com if any conditions of this licensing are 33** Contact info@trolltech.com if any conditions of this licensing are
34** not clear to you. 34** not clear to you.
35** 35**
36**********************************************************************/ 36**********************************************************************/
37 37
38#include "qtextedit.h" 38#include "qtextedit.h"
39 39
40#include "qrichtext_p.h" 40#include "qrichtext_p.h"
41#include "qpainter.h"
42#include "qpen.h"
43#include "qbrush.h"
44#include "qpixmap.h"
45#include "qfont.h"
46#include "qcolor.h"
47#include "qstyle.h"
48#include "qsize.h"
49#include "qevent.h"
50#include "qtimer.h"
51#include "qapplication.h"
52#include "qlistbox.h" 41#include "qlistbox.h"
53#include "qvbox.h"
54#include "qapplication.h"
55#include "qclipboard.h" 42#include "qclipboard.h"
56#include "qcolordialog.h"
57#include "qfontdialog.h"
58#include "qstylesheet.h"
59#include "qdragobject.h"
60#include "qurl.h"
61#include "qcursor.h"
62#include "qregexp.h"
63#include "qpopupmenu.h" 43#include "qpopupmenu.h"
64 44
65#define ACCEL_KEY(k) "\t" + QString("Ctrl+" #k) 45#define ACCEL_KEY(k) "\t" + QString("Ctrl+" #k)
66 46
67using namespace Qt3; 47using namespace Qt3;
68 48
69static bool qt_enable_richtext_copy = FALSE; 49static bool qt_enable_richtext_copy = FALSE;
70 50
71struct QUndoRedoInfoPrivate 51struct QUndoRedoInfoPrivate
72{ 52{
73 QTextString text; 53 QTextString text;
74}; 54};
75 55
76namespace Qt3 { 56namespace Qt3 {
77 57
78class QTextEditPrivate 58class QTextEditPrivate
79{ 59{
80public: 60public:
81 QTextEditPrivate() 61 QTextEditPrivate()
82 :preeditStart(-1),preeditLength(-1),ensureCursorVisibleInShowEvent(FALSE) 62 :preeditStart(-1),preeditLength(-1),ensureCursorVisibleInShowEvent(FALSE)
83 { 63 {
84 for ( int i=0; i<7; i++ ) 64 for ( int i=0; i<7; i++ )
85 id[i] = 0; 65 id[i] = 0;
86 } 66 }
87 int id[ 7 ]; 67 int id[ 7 ];
88 int preeditStart; 68 int preeditStart;
89 int preeditLength; 69 int preeditLength;
90 bool ensureCursorVisibleInShowEvent; 70 bool ensureCursorVisibleInShowEvent;
91 QString scrollToAnchor; // used to deferr scrollToAnchor() until the show event when we are resized 71 QString scrollToAnchor; // used to deferr scrollToAnchor() until the show event when we are resized
92}; 72};
93 73
94} 74}
95 75
96static bool block_set_alignment = FALSE; 76static bool block_set_alignment = FALSE;
97 77
98/*! 78/*!
99 \class QTextEdit qtextedit.h 79 \class QTextEdit qtextedit.h
100 \brief The QTextEdit widget provides a powerful single-page rich text editor. 80 \brief The QTextEdit widget provides a powerful single-page rich text editor.
101 81
102 \ingroup basic 82 \ingroup basic
103 \ingroup text 83 \ingroup text
104 \mainclass 84 \mainclass
105 85
106 \tableofcontents 86 \tableofcontents
107 87
108 \section1 Introduction and Concepts 88 \section1 Introduction and Concepts
109 89
110 QTextEdit is an advanced WYSIWYG viewer/editor supporting rich 90 QTextEdit is an advanced WYSIWYG viewer/editor supporting rich
111 text formatting using HTML-style tags. It is optimized to handle 91 text formatting using HTML-style tags. It is optimized to handle
112 large documents and to respond quickly to user input. 92 large documents and to respond quickly to user input.
113 93
114 QTextEdit has three modes of operation: 94 QTextEdit has three modes of operation:
115 \table 95 \table
116 \header \i Mode \i Command \i Notes 96 \header \i Mode \i Command \i Notes
117 \row \i Plain Text Editor \i setTextFormat(PlainText) 97 \row \i Plain Text Editor \i setTextFormat(PlainText)
118 \i Set text with setText(); text() returns plain text. Text 98 \i Set text with setText(); text() returns plain text. Text
119 attributes (e.g. colors) can be set, but plain text is always 99 attributes (e.g. colors) can be set, but plain text is always
120 returned.<sup>1.</sup> 100 returned.<sup>1.</sup>
121 \row \i Rich Text Editor \i setTextFormat(RichText) 101 \row \i Rich Text Editor \i setTextFormat(RichText)
122 \i Set text with setText(); text() returns rich text. Rich 102 \i Set text with setText(); text() returns rich text. Rich
123 text editing is fairly limited. You can't set margins or 103 text editing is fairly limited. You can't set margins or
124 insert images for example (although you can read and 104 insert images for example (although you can read and
125 correctly display files that have margins set and that 105 correctly display files that have margins set and that
126 include images). This mode is mostly useful for editing small 106 include images). This mode is mostly useful for editing small
127 amounts of rich text. <sup>2.</sup> 107 amounts of rich text. <sup>2.</sup>
128 \row \i Text Viewer<sup>3.</sup> \i setReadOnly(TRUE) 108 \row \i Text Viewer<sup>3.</sup> \i setReadOnly(TRUE)
129 \i Set text with setText() or append() (which has no undo 109 \i Set text with setText() or append() (which has no undo
130 history so is faster and uses less memory); text() returns 110 history so is faster and uses less memory); text() returns
131 plain or rich text depending on the textFormat(). This mode 111 plain or rich text depending on the textFormat(). This mode
132 can correctly display a large subset of HTML tags. 112 can correctly display a large subset of HTML tags.
133 \endtable 113 \endtable
134 114
135 <sup>1.</sup><small>We do \e not recommend using QTextEdit to 115 <sup>1.</sup><small>We do \e not recommend using QTextEdit to
136 create syntax highlighting editors because the current API is 116 create syntax highlighting editors because the current API is
137 insufficient for this purpose. We hope to release a more complete 117 insufficient for this purpose. We hope to release a more complete
138 API that will support syntax highlighting in a later 118 API that will support syntax highlighting in a later
139 release.</small> 119 release.</small>
140 120
141 <sup>2.</sup><small>A more complete API that supports setting 121 <sup>2.</sup><small>A more complete API that supports setting
142 margins, images, etc., is planned for a later Qt release.</small> 122 margins, images, etc., is planned for a later Qt release.</small>
143 123
144 <sup>3.</sup><small>Qt 3.1 will provide a Log Viewer mode which is 124 <sup>3.</sup><small>Qt 3.1 will provide a Log Viewer mode which is
145 optimised for the fast and memory efficient display of large 125 optimised for the fast and memory efficient display of large
146 amounts of read only text.</small> 126 amounts of read only text.</small>
147 127
148 We recommend that you always call setTextFormat() to set the mode 128 We recommend that you always call setTextFormat() to set the mode
149 you want to use. If you use \c AutoText then setText() and 129 you want to use. If you use \c AutoText then setText() and
150 append() will try to determine whether the text they are given is 130 append() will try to determine whether the text they are given is
151 plain text or rich text. If you use \c RichText then setText() and 131 plain text or rich text. If you use \c RichText then setText() and
152 append() will assume that the text they are given is rich text. 132 append() will assume that the text they are given is rich text.
153 insert() simply inserts the text it is given. 133 insert() simply inserts the text it is given.
154 134
155 QTextEdit works on paragraphs and characters. A paragraph is a 135 QTextEdit works on paragraphs and characters. A paragraph is a
156 formatted string which is word-wrapped to fit into the width of 136 formatted string which is word-wrapped to fit into the width of
157 the widget. By default when reading plain text, two newlines 137 the widget. By default when reading plain text, two newlines
158 signify a paragraph. A document consists of zero or more 138 signify a paragraph. A document consists of zero or more
159 paragraphs, indexed from 0. Characters are indexed on a 139 paragraphs, indexed from 0. Characters are indexed on a
160 per-paragraph basis, also indexed from 0. The words in the 140 per-paragraph basis, also indexed from 0. The words in the
161 paragraph are aligned in accordance with the paragraph's 141 paragraph are aligned in accordance with the paragraph's
162 alignment(). Paragraphs are separated by hard line breaks. Each 142 alignment(). Paragraphs are separated by hard line breaks. Each
163 character within a paragraph has its own attributes, for example, 143 character within a paragraph has its own attributes, for example,
164 font and color. 144 font and color.
165 145
166 The text edit documentation uses the following concepts: 146 The text edit documentation uses the following concepts:
167 \list 147 \list
168 \i \e{current format} -- 148 \i \e{current format} --
169 this is the format at the current cursor position, \e and it 149 this is the format at the current cursor position, \e and it
170 is the format of the selected text if any. 150 is the format of the selected text if any.
171 \i \e{current paragraph} -- the paragraph which contains the 151 \i \e{current paragraph} -- the paragraph which contains the
172 cursor. 152 cursor.
173 \endlist 153 \endlist
174 154
175 QTextEdit can display images (using QMimeSourceFactory), lists and 155 QTextEdit can display images (using QMimeSourceFactory), lists and
176 tables. If the text is too large to view within the text edit's 156 tables. If the text is too large to view within the text edit's
177 viewport, scrollbars will appear. The text edit can load both 157 viewport, scrollbars will appear. The text edit can load both
178 plain text and HTML files (a subset of HTML 3.2 and 4). The 158 plain text and HTML files (a subset of HTML 3.2 and 4). The
179 rendering style and the set of valid tags are defined by a 159 rendering style and the set of valid tags are defined by a
180 styleSheet(). Custom tags can be created and placed in a custom 160 styleSheet(). Custom tags can be created and placed in a custom
181 style sheet. Change the style sheet with \l{setStyleSheet()}; see 161 style sheet. Change the style sheet with \l{setStyleSheet()}; see
182 QStyleSheet for details. The images identified by image tags are 162 QStyleSheet for details. The images identified by image tags are
183 displayed if they can be interpreted using the text edit's 163 displayed if they can be interpreted using the text edit's
184 \l{QMimeSourceFactory}; see setMimeSourceFactory(). 164 \l{QMimeSourceFactory}; see setMimeSourceFactory().
185 165
186 If you want a text browser with more navigation use QTextBrowser. 166 If you want a text browser with more navigation use QTextBrowser.
187 If you just need to display a small piece of rich text use QLabel 167 If you just need to display a small piece of rich text use QLabel
188 or QSimpleRichText. 168 or QSimpleRichText.
189 169
190 If you create a new QTextEdit, and want to allow the user to edit 170 If you create a new QTextEdit, and want to allow the user to edit
191 rich text, call setTextFormat(Qt::RichText) to ensure that the 171 rich text, call setTextFormat(Qt::RichText) to ensure that the
192 text is treated as rich text. (Rich text uses HTML tags to set 172 text is treated as rich text. (Rich text uses HTML tags to set
193 text formatting attributes. See QStyleSheet for information on the 173 text formatting attributes. See QStyleSheet for information on the
194 HTML tags that are supported.). If you don't call setTextFormat() 174 HTML tags that are supported.). If you don't call setTextFormat()
195 explicitly the text edit will guess from the text itself whether 175 explicitly the text edit will guess from the text itself whether
196 it is rich text or plain text. This means that if the text looks 176 it is rich text or plain text. This means that if the text looks
197 like HTML or XML it will probably be interpreted as rich text, so 177 like HTML or XML it will probably be interpreted as rich text, so
198 you should call setTextFormat(Qt::PlainText) to preserve such 178 you should call setTextFormat(Qt::PlainText) to preserve such
199 text. 179 text.
200 180
201 Note that we do not intend to add a full-featured web browser 181 Note that we do not intend to add a full-featured web browser
202 widget to Qt (because that would easily double Qt's size and only 182 widget to Qt (because that would easily double Qt's size and only
203 a few applications would benefit from it). The rich 183 a few applications would benefit from it). The rich
204 text support in Qt is designed to provide a fast, portable and 184 text support in Qt is designed to provide a fast, portable and
205 efficient way to add reasonable online help facilities to 185 efficient way to add reasonable online help facilities to
206 applications, and to provide a basis for rich text editors. 186 applications, and to provide a basis for rich text editors.
207 \section1 Using QTextEdit as a Display Widget 187 \section1 Using QTextEdit as a Display Widget
208 188
209 QTextEdit can display a large HTML subset, including tables and 189 QTextEdit can display a large HTML subset, including tables and
210 images. 190 images.
211 191
212 The text is set or replaced using setText() which deletes any 192 The text is set or replaced using setText() which deletes any
213 existing text and replaces it with the text passed in the 193 existing text and replaces it with the text passed in the
214 setText() call. If you call setText() with legacy HTML (with 194 setText() call. If you call setText() with legacy HTML (with
215 setTextFormat(RichText) in force), and then call text(), the text 195 setTextFormat(RichText) in force), and then call text(), the text
216 that is returned may have different markup, but will render the 196 that is returned may have different markup, but will render the
217 same. Text can be inserted with insert(), paste(), pasteSubType() 197 same. Text can be inserted with insert(), paste(), pasteSubType()
218 and append(). Text that is appended does not go into the undo 198 and append(). Text that is appended does not go into the undo
219 history; this makes append() faster and consumes less memory. Text 199 history; this makes append() faster and consumes less memory. Text
220 can also be cut(). The entire text is deleted with clear() and the 200 can also be cut(). The entire text is deleted with clear() and the
221 selected text is deleted with removeSelectedText(). Selected 201 selected text is deleted with removeSelectedText(). Selected
222 (marked) text can also be deleted with del() (which will delete 202 (marked) text can also be deleted with del() (which will delete
223 the character to the right of the cursor if no text is selected). 203 the character to the right of the cursor if no text is selected).
224 204
225 Loading and saving text is achieved using setText() and text(), 205 Loading and saving text is achieved using setText() and text(),
226 for example: 206 for example:
227 \code 207 \code
228 QFile file( fileName ); // Read the text from a file 208 QFile file( fileName ); // Read the text from a file
229 if ( file.open( IO_ReadOnly ) ) { 209 if ( file.open( IO_ReadOnly ) ) {
230 QTextStream ts( &file ); 210 QTextStream ts( &file );
231 textEdit->setText( ts.read() ); 211 textEdit->setText( ts.read() );
232 } 212 }
233 \endcode 213 \endcode
234 \code 214 \code
235 QFile file( fileName ); // Write the text to a file 215 QFile file( fileName ); // Write the text to a file
236 if ( file.open( IO_WriteOnly ) ) { 216 if ( file.open( IO_WriteOnly ) ) {
237 QTextStream ts( &file ); 217 QTextStream ts( &file );
238 ts << textEdit->text(); 218 ts << textEdit->text();
239 textEdit->setModified( FALSE ); 219 textEdit->setModified( FALSE );
240 } 220 }
241 \endcode 221 \endcode
242 222
243 By default the text edit wraps words at whitespace to fit within 223 By default the text edit wraps words at whitespace to fit within
244 the text edit widget. The setWordWrap() function is used to 224 the text edit widget. The setWordWrap() function is used to
245 specify the kind of word wrap you want, or \c NoWrap if you don't 225 specify the kind of word wrap you want, or \c NoWrap if you don't
246 want any wrapping. Call setWordWrap() to set a fixed pixel width 226 want any wrapping. Call setWordWrap() to set a fixed pixel width
247 \c FixedPixelWidth, or character column (e.g. 80 column) \c 227 \c FixedPixelWidth, or character column (e.g. 80 column) \c
248 FixedColumnWidth with the pixels or columns specified with 228 FixedColumnWidth with the pixels or columns specified with
249 setWrapColumnOrWidth(). If you use word wrap to the widget's width 229 setWrapColumnOrWidth(). If you use word wrap to the widget's width
250 \c WidgetWidth, you can specify whether to break on whitespace or 230 \c WidgetWidth, you can specify whether to break on whitespace or
251 anywhere with setWrapPolicy(). 231 anywhere with setWrapPolicy().
252 232
253 The background color is set differently than other widgets, using 233 The background color is set differently than other widgets, using
254 setPaper(). You specify a brush style which could be a plain color 234 setPaper(). You specify a brush style which could be a plain color
255 or a complex pixmap. 235 or a complex pixmap.
256 236
257 Hypertext links are automatically underlined; this can be changed 237 Hypertext links are automatically underlined; this can be changed
258 with setLinkUnderline(). The tab stop width is set with 238 with setLinkUnderline(). The tab stop width is set with
259 setTabStopWidth(). 239 setTabStopWidth().
260 240
261 The zoomIn() and zoomOut() functions can be used to resize the 241 The zoomIn() and zoomOut() functions can be used to resize the
262 text by increasing (decreasing for zoomOut()) the point size used. 242 text by increasing (decreasing for zoomOut()) the point size used.
263 Images are not affected by the zoom functions. 243 Images are not affected by the zoom functions.
264 244
265 The lines() function returns the number of lines in the text and 245 The lines() function returns the number of lines in the text and
266 paragraphs() returns the number of paragraphs. The number of lines 246 paragraphs() returns the number of paragraphs. The number of lines
267 within a particular paragraph is returned by linesOfParagraph(). 247 within a particular paragraph is returned by linesOfParagraph().
268 The length of the entire text in characters is returned by 248 The length of the entire text in characters is returned by
269 length(). 249 length().
270 250
271 You can scroll to an anchor in the text, e.g. \c{<a 251 You can scroll to an anchor in the text, e.g. \c{<a
272 name="anchor">} with scrollToAnchor(). The find() function can be 252 name="anchor">} with scrollToAnchor(). The find() function can be
273 used to find and select a given string within the text. 253 used to find and select a given string within the text.
274 254
275 A read-only QTextEdit provides the same functionality as the 255 A read-only QTextEdit provides the same functionality as the
276 (obsolete) QTextView. (QTextView is still supplied for 256 (obsolete) QTextView. (QTextView is still supplied for
277 compatibility with old code.) 257 compatibility with old code.)
278 258
279 \section2 Read-only key bindings 259 \section2 Read-only key bindings
280 260
281 When QTextEdit is used read-only the key-bindings are limited to 261 When QTextEdit is used read-only the key-bindings are limited to
282 navigation, and text may only be selected with the mouse: 262 navigation, and text may only be selected with the mouse:
283 \table 263 \table
284 \header \i Keypresses \i Action 264 \header \i Keypresses \i Action
285 \row \i \e{UpArrow} \i Move one line up 265 \row \i \e{UpArrow} \i Move one line up
286 \row \i \e{DownArrow} \i Move one line down 266 \row \i \e{DownArrow} \i Move one line down
287 \row \i \e{LeftArrow} \i Move one character left 267 \row \i \e{LeftArrow} \i Move one character left
288 \row \i \e{RightArrow} \i Move one character right 268 \row \i \e{RightArrow} \i Move one character right
289 \row \i \e{PageUp} \i Move one (viewport) page up 269 \row \i \e{PageUp} \i Move one (viewport) page up
290 \row \i \e{PageDown} \i Move one (viewport) page down 270 \row \i \e{PageDown} \i Move one (viewport) page down
291 \row \i \e{Home} \i Move to the beginning of the text 271 \row \i \e{Home} \i Move to the beginning of the text
292 \row \i \e{End} \i Move to the end of the text 272 \row \i \e{End} \i Move to the end of the text
293 \row \i \e{Shift+Wheel} \i Scroll the page horizontally (the Wheel is the mouse wheel) 273 \row \i \e{Shift+Wheel} \i Scroll the page horizontally (the Wheel is the mouse wheel)
294 \row \i \e{Ctrl+Wheel} \i Zoom the text 274 \row \i \e{Ctrl+Wheel} \i Zoom the text
295 \endtable 275 \endtable
296 276
297 The text edit may be able to provide some meta-information. For 277 The text edit may be able to provide some meta-information. For
298 example, the documentTitle() function will return the text from 278 example, the documentTitle() function will return the text from
299 within HTML \c{<title>} tags. 279 within HTML \c{<title>} tags.
300 280
301 The text displayed in a text edit has a \e context. The context is 281 The text displayed in a text edit has a \e context. The context is
302 a path which the text edit's QMimeSourceFactory uses to resolve 282 a path which the text edit's QMimeSourceFactory uses to resolve
303 the locations of files and images. It is passed to the 283 the locations of files and images. It is passed to the
304 mimeSourceFactory() when quering data. (See QTextEdit() and 284 mimeSourceFactory() when quering data. (See QTextEdit() and
305 \l{context()}.) 285 \l{context()}.)
306 286
307 \section1 Using QTextEdit as an Editor 287 \section1 Using QTextEdit as an Editor
308 288
309 All the information about using QTextEdit as a display widget also 289 All the information about using QTextEdit as a display widget also
310 applies here. 290 applies here.
311 291
312 The current format's attributes are set with setItalic(), 292 The current format's attributes are set with setItalic(),
313 setBold(), setUnderline(), setFamily() (font family), 293 setBold(), setUnderline(), setFamily() (font family),
314 setPointSize(), setColor() and setCurrentFont(). The current 294 setPointSize(), setColor() and setCurrentFont(). The current
315 paragraph's alignment is set with setAlignment(). 295 paragraph's alignment is set with setAlignment().
316 296
317 Use setSelection() to select text. The setSelectionAttributes() 297 Use setSelection() to select text. The setSelectionAttributes()
318 function is used to indicate how selected text should be 298 function is used to indicate how selected text should be
319 displayed. Use hasSelectedText() to find out if any text is 299 displayed. Use hasSelectedText() to find out if any text is
320 selected. The currently selected text's position is available 300 selected. The currently selected text's position is available
321 using getSelection() and the selected text itself is returned by 301 using getSelection() and the selected text itself is returned by
322 selectedText(). The selection can be copied to the clipboard with 302 selectedText(). The selection can be copied to the clipboard with
323 copy(), or cut to the clipboard with cut(). It can be deleted with 303 copy(), or cut to the clipboard with cut(). It can be deleted with
324 removeSelectedText(). The entire text can be selected (or 304 removeSelectedText(). The entire text can be selected (or
325 unselected) using selectAll(). QTextEdit supports multiple 305 unselected) using selectAll(). QTextEdit supports multiple
326 selections. Most of the selection functions operate on the default 306 selections. Most of the selection functions operate on the default
327 selection, selection 0. If the user presses a non-selecting key, 307 selection, selection 0. If the user presses a non-selecting key,
328 e.g. a cursor key without also holding down Shift, all selections 308 e.g. a cursor key without also holding down Shift, all selections
329 are cleared. 309 are cleared.
330 310
331 Set and get the position of the cursor with setCursorPosition() 311 Set and get the position of the cursor with setCursorPosition()
332 and getCursorPosition() respectively. When the cursor is moved, 312 and getCursorPosition() respectively. When the cursor is moved,
333 the signals currentFontChanged(), currentColorChanged() and 313 the signals currentFontChanged(), currentColorChanged() and
334 currentAlignmentChanged() are emitted to reflect the font, color 314 currentAlignmentChanged() are emitted to reflect the font, color
335 and alignment at the new cursor position. 315 and alignment at the new cursor position.
336 316
337 If the text changes, the textChanged() signal is emitted, and if 317 If the text changes, the textChanged() signal is emitted, and if
338 the user inserts a new line by pressing Return or Enter, 318 the user inserts a new line by pressing Return or Enter,
339 returnPressed() is emitted. The isModified() function will return 319 returnPressed() is emitted. The isModified() function will return
340 TRUE if the text has been modified. 320 TRUE if the text has been modified.
341 321
342 QTextEdit provides command-based undo and redo. To set the depth 322 QTextEdit provides command-based undo and redo. To set the depth
343 of the command history use setUndoDepth() which defaults to 100 323 of the command history use setUndoDepth() which defaults to 100
344 steps. To undo or redo the last operation call undo() or redo(). 324 steps. To undo or redo the last operation call undo() or redo().
345 The signals undoAvailable() and redoAvailable() indicate whether 325 The signals undoAvailable() and redoAvailable() indicate whether
346 the undo and redo operations can be executed. 326 the undo and redo operations can be executed.
347 327
348 The indent() function is used to reindent a paragraph. It is 328 The indent() function is used to reindent a paragraph. It is
349 useful for code editors, for example in <em>Qt Designer</em>'s 329 useful for code editors, for example in <em>Qt Designer</em>'s
350 code editor \e{Ctrl+I} invokes the indent() function. 330 code editor \e{Ctrl+I} invokes the indent() function.
351 331
352 \section2 Editing key bindings 332 \section2 Editing key bindings
353 333
354 The list of key-bindings which are implemented for editing: 334 The list of key-bindings which are implemented for editing:
355 \table 335 \table
356 \header \i Keypresses \i Action 336 \header \i Keypresses \i Action
357 \row \i \e{Backspace} \i Delete the character to the left of the cursor 337 \row \i \e{Backspace} \i Delete the character to the left of the cursor
358 \row \i \e{Delete} \i Delete the character to the right of the cursor 338 \row \i \e{Delete} \i Delete the character to the right of the cursor
359 \row \i \e{Ctrl+A} \i Move the cursor to the beginning of the line 339 \row \i \e{Ctrl+A} \i Move the cursor to the beginning of the line
360 \row \i \e{Ctrl+B} \i Move the cursor one character left 340 \row \i \e{Ctrl+B} \i Move the cursor one character left
361 \row \i \e{Ctrl+C} \i Copy the marked text to the clipboard (also 341 \row \i \e{Ctrl+C} \i Copy the marked text to the clipboard (also
362 \e{Ctrl+Insert} under Windows) 342 \e{Ctrl+Insert} under Windows)
363 \row \i \e{Ctrl+D} \i Delete the character to the right of the cursor 343 \row \i \e{Ctrl+D} \i Delete the character to the right of the cursor
364 \row \i \e{Ctrl+E} \i Move the cursor to the end of the line 344 \row \i \e{Ctrl+E} \i Move the cursor to the end of the line
365 \row \i \e{Ctrl+F} \i Move the cursor one character right 345 \row \i \e{Ctrl+F} \i Move the cursor one character right
366 \row \i \e{Ctrl+H} \i Delete the character to the left of the cursor 346 \row \i \e{Ctrl+H} \i Delete the character to the left of the cursor
367 \row \i \e{Ctrl+K} \i Delete to end of line 347 \row \i \e{Ctrl+K} \i Delete to end of line
368 \row \i \e{Ctrl+N} \i Move the cursor one line down 348 \row \i \e{Ctrl+N} \i Move the cursor one line down
369 \row \i \e{Ctrl+P} \i Move the cursor one line up 349 \row \i \e{Ctrl+P} \i Move the cursor one line up
370 \row \i \e{Ctrl+V} \i Paste the clipboard text into line edit 350 \row \i \e{Ctrl+V} \i Paste the clipboard text into line edit
371 (also \e{Shift+Insert} under Windows) 351 (also \e{Shift+Insert} under Windows)
372 \row \i \e{Ctrl+X} \i Cut the marked text, copy to clipboard 352 \row \i \e{Ctrl+X} \i Cut the marked text, copy to clipboard
373 (also \e{Shift+Delete} under Windows) 353 (also \e{Shift+Delete} under Windows)
374 \row \i \e{Ctrl+Z} \i Undo the last operation 354 \row \i \e{Ctrl+Z} \i Undo the last operation
375 \row \i \e{Ctrl+Y} \i Redo the last operation 355 \row \i \e{Ctrl+Y} \i Redo the last operation
376 \row \i \e{LeftArrow} \i Move the cursor one character left 356 \row \i \e{LeftArrow} \i Move the cursor one character left
377 \row \i \e{Ctrl+LeftArrow} \i Move the cursor one word left 357 \row \i \e{Ctrl+LeftArrow} \i Move the cursor one word left
378 \row \i \e{RightArrow} \i Move the cursor one character right 358 \row \i \e{RightArrow} \i Move the cursor one character right
379 \row \i \e{Ctrl+RightArrow} \i Move the cursor one word right 359 \row \i \e{Ctrl+RightArrow} \i Move the cursor one word right
380 \row \i \e{UpArrow} \i Move the cursor one line up 360 \row \i \e{UpArrow} \i Move the cursor one line up
381 \row \i \e{Ctrl+UpArrow} \i Move the cursor one word up 361 \row \i \e{Ctrl+UpArrow} \i Move the cursor one word up
382 \row \i \e{DownArrow} \i Move the cursor one line down 362 \row \i \e{DownArrow} \i Move the cursor one line down
383 \row \i \e{Ctrl+Down Arrow} \i Move the cursor one word down 363 \row \i \e{Ctrl+Down Arrow} \i Move the cursor one word down
384 \row \i \e{PageUp} \i Move the cursor one page up 364 \row \i \e{PageUp} \i Move the cursor one page up
385 \row \i \e{PageDown} \i Move the cursor one page down 365 \row \i \e{PageDown} \i Move the cursor one page down
386 \row \i \e{Home} \i Move the cursor to the beginning of the line 366 \row \i \e{Home} \i Move the cursor to the beginning of the line
387 \row \i \e{Ctrl+Home} \i Move the cursor to the beginning of the text 367 \row \i \e{Ctrl+Home} \i Move the cursor to the beginning of the text
388 \row \i \e{End} \i Move the cursor to the end of the line 368 \row \i \e{End} \i Move the cursor to the end of the line
389 \row \i \e{Ctrl+End} \i Move the cursor to the end of the text 369 \row \i \e{Ctrl+End} \i Move the cursor to the end of the text
390 \row \i \e{Shift+Wheel} \i Scroll the page horizontally 370 \row \i \e{Shift+Wheel} \i Scroll the page horizontally
391 (the Wheel is the mouse wheel) 371 (the Wheel is the mouse wheel)
392 \row \i \e{Ctrl+Wheel} \i Zoom the text 372 \row \i \e{Ctrl+Wheel} \i Zoom the text
393 \endtable 373 \endtable
394 374
395 To select (mark) text hold down the Shift key whilst pressing one 375 To select (mark) text hold down the Shift key whilst pressing one
396 of the movement keystrokes, for example, <i>Shift+Right Arrow</i> 376 of the movement keystrokes, for example, <i>Shift+Right Arrow</i>
397 will select the character to the right, and <i>Shift+Ctrl+Right 377 will select the character to the right, and <i>Shift+Ctrl+Right
398 Arrow</i> will select the word to the right, etc. 378 Arrow</i> will select the word to the right, etc.
399 379
400 By default the text edit widget operates in insert mode so all 380 By default the text edit widget operates in insert mode so all
401 text that the user enters is inserted into the text edit and any 381 text that the user enters is inserted into the text edit and any
402 text to the right of the cursor is moved out of the way. The mode 382 text to the right of the cursor is moved out of the way. The mode
403 can be changed to overwrite, where new text overwrites any text to 383 can be changed to overwrite, where new text overwrites any text to
404 the right of the cursor, using setOverwriteMode(). 384 the right of the cursor, using setOverwriteMode().
405 385
406*/ 386*/
407 387
408/*! \enum QTextEdit::KeyboardAction 388/*! \enum QTextEdit::KeyboardAction
409 389
410 This enum is used by doKeyboardAction() to specify which action 390 This enum is used by doKeyboardAction() to specify which action
411 should be executed: 391 should be executed:
412 392
413 \value ActionBackspace Delete the character to the left of the 393 \value ActionBackspace Delete the character to the left of the
414 cursor. 394 cursor.
415 395
416 \value ActionDelete Delete the character to the right of the cursor. 396 \value ActionDelete Delete the character to the right of the cursor.
417 397
418 \value ActionReturn Split the paragraph at the cursor position. 398 \value ActionReturn Split the paragraph at the cursor position.
419 399
420 \value ActionKill If the cursor is not at the end of the paragraph, 400 \value ActionKill If the cursor is not at the end of the paragraph,
421 delete the text from the cursor position until the end of the 401 delete the text from the cursor position until the end of the
422 paragraph. If the cursor is at the end of the paragraph, delete the 402 paragraph. If the cursor is at the end of the paragraph, delete the
423 hard line break at the end of the paragraph - this will cause this 403 hard line break at the end of the paragraph - this will cause this
424 paragraph to be joined with the following paragraph. 404 paragraph to be joined with the following paragraph.
425*/ 405*/
426 406
427/*! \enum QTextEdit::VerticalAlignment 407/*! \enum QTextEdit::VerticalAlignment
428 408
429 This enum is used to set the vertical alignment of the text. 409 This enum is used to set the vertical alignment of the text.
430 410
431 \value AlignNormal Normal alignment 411 \value AlignNormal Normal alignment
432 \value AlignSuperScript Superscript 412 \value AlignSuperScript Superscript
433 \value AlignSubScript Subscript 413 \value AlignSubScript Subscript
434*/ 414*/
435 415
436/*! \fn void QTextEdit::copyAvailable (bool yes) 416/*! \fn void QTextEdit::copyAvailable (bool yes)
437 417
438 This signal is emitted when text is selected or de-selected in the text 418 This signal is emitted when text is selected or de-selected in the text
439 edit. 419 edit.
440 420
441 When text is selected this signal will be emitted with \a yes set to 421 When text is selected this signal will be emitted with \a yes set to
442 TRUE. If no text has been selected or if the selected text is 422 TRUE. If no text has been selected or if the selected text is
443 de-selected this signal is emitted with \a yes set to FALSE. 423 de-selected this signal is emitted with \a yes set to FALSE.
444 424
445 If \a yes is TRUE then copy() can be used to copy the selection to the 425 If \a yes is TRUE then copy() can be used to copy the selection to the
446 clipboard. If \a yes is FALSE then copy() does nothing. 426 clipboard. If \a yes is FALSE then copy() does nothing.
447 427
448 \sa selectionChanged() 428 \sa selectionChanged()
449*/ 429*/
450 430
451 431
452/*! \fn void QTextEdit::textChanged() 432/*! \fn void QTextEdit::textChanged()
453 433
454 This signal is emitted whenever the text in the text edit changes. 434 This signal is emitted whenever the text in the text edit changes.
455 435
456 \sa setText() append() 436 \sa setText() append()
457 */ 437 */
458 438
459/*! \fn void QTextEdit::selectionChanged() 439/*! \fn void QTextEdit::selectionChanged()
460 440
461 This signal is emitted whenever the selection changes. 441 This signal is emitted whenever the selection changes.
462 442
463 \sa setSelection() copyAvailable() 443 \sa setSelection() copyAvailable()
464*/ 444*/
465 445
466/*! \fn QTextDocument *QTextEdit::document() const 446/*! \fn QTextDocument *QTextEdit::document() const
467 447
468 \internal 448 \internal
469 449
470 This function returns the QTextDocument which is used by the text 450 This function returns the QTextDocument which is used by the text
471 edit. 451 edit.
472*/ 452*/
473 453
474/*! \fn void QTextEdit::setDocument( QTextDocument *doc ) 454/*! \fn void QTextEdit::setDocument( QTextDocument *doc )
475 455
476 \internal 456 \internal
477 457
478 This function sets the QTextDocument which should be used by the text 458 This function sets the QTextDocument which should be used by the text
479 edit to \a doc. This can be used, for example, if you want to 459 edit to \a doc. This can be used, for example, if you want to
480 display a document using multiple views. You would create a 460 display a document using multiple views. You would create a
481 QTextDocument and set it to the text edits which should display it. 461 QTextDocument and set it to the text edits which should display it.
482 You would need to connect to the textChanged() and 462 You would need to connect to the textChanged() and
483 selectionChanged() signals of all the text edits and update them all 463 selectionChanged() signals of all the text edits and update them all
484 accordingly (preferably with a slight delay for efficiency reasons). 464 accordingly (preferably with a slight delay for efficiency reasons).
485*/ 465*/
486 466
487/*! \enum QTextEdit::CursorAction 467/*! \enum QTextEdit::CursorAction
488 468
489 This enum is used by moveCursor() to specify in which direction 469 This enum is used by moveCursor() to specify in which direction
490 the cursor should be moved: 470 the cursor should be moved:
491 471
492 \value MoveBackward Moves the cursor one character backward 472 \value MoveBackward Moves the cursor one character backward
493 473
494 \value MoveWordBackward Moves the cursor one word backward 474 \value MoveWordBackward Moves the cursor one word backward
495 475
496 \value MoveForward Moves the cursor one character forward 476 \value MoveForward Moves the cursor one character forward
497 477
498 \value MoveWordForward Moves the cursor one word forward 478 \value MoveWordForward Moves the cursor one word forward
499 479
500 \value MoveUp Moves the cursor up one line 480 \value MoveUp Moves the cursor up one line
501 481
502 \value MoveDown Moves the cursor down one line 482 \value MoveDown Moves the cursor down one line
503 483
504 \value MoveLineStart Moves the cursor to the beginning of the line 484 \value MoveLineStart Moves the cursor to the beginning of the line
505 485
506 \value MoveLineEnd Moves the cursor to the end of the line 486 \value MoveLineEnd Moves the cursor to the end of the line
507 487
508 \value MoveHome Moves the cursor to the beginning of the document 488 \value MoveHome Moves the cursor to the beginning of the document
509 489
510 \value MoveEnd Moves the cursor to the end of the document 490 \value MoveEnd Moves the cursor to the end of the document
511 491
512 \value MovePgUp Moves the cursor one page up 492 \value MovePgUp Moves the cursor one page up
513 493
514 \value MovePgDown Moves the cursor one page down 494 \value MovePgDown Moves the cursor one page down
515*/ 495*/
516 496
517 497
518/*! 498/*!
519 \property QTextEdit::overwriteMode 499 \property QTextEdit::overwriteMode
520 \brief the text edit's overwrite mode 500 \brief the text edit's overwrite mode
521 501
522 If FALSE (the default) characters entered by the user are inserted 502 If FALSE (the default) characters entered by the user are inserted
523 with any characters to the right being moved out of the way. 503 with any characters to the right being moved out of the way.
524 If TRUE, the editor is in overwrite mode, i.e. characters entered by 504 If TRUE, the editor is in overwrite mode, i.e. characters entered by
525 the user overwrite any characters to the right of the cursor position. 505 the user overwrite any characters to the right of the cursor position.
526*/ 506*/
527 507
528/*! \fn void QTextEdit::setCurrentFont( const QFont &f ) 508/*! \fn void QTextEdit::setCurrentFont( const QFont &f )
529 509
530 Sets the font of the current format to \a f. 510 Sets the font of the current format to \a f.
531 511
532 \sa font() setPointSize() setFamily() 512 \sa font() setPointSize() setFamily()
533*/ 513*/
534 514
535/*! 515/*!
536 \property QTextEdit::undoDepth 516 \property QTextEdit::undoDepth
537 \brief the depth of the undo history 517 \brief the depth of the undo history
538 518
539 The maximum number of steps in the undo/redo history. 519 The maximum number of steps in the undo/redo history.
540 The default is 100. 520 The default is 100.
541 521
542 \sa undo() redo() 522 \sa undo() redo()
543*/ 523*/
544 524
545/*! \fn void QTextEdit::undoAvailable( bool yes ) 525/*! \fn void QTextEdit::undoAvailable( bool yes )
546 526
547 This signal is emitted when the availability of undo changes. If \a 527 This signal is emitted when the availability of undo changes. If \a
548 yes is TRUE, then undo() will work until undoAvailable( FALSE ) is 528 yes is TRUE, then undo() will work until undoAvailable( FALSE ) is
549 next emitted. 529 next emitted.
550 530
551 \sa undo() undoDepth() 531 \sa undo() undoDepth()
552*/ 532*/
553 533
554/*! \fn void QTextEdit::modificationChanged( bool m ) 534/*! \fn void QTextEdit::modificationChanged( bool m )
555 535
556 This signal is emitted when the modification of the document 536 This signal is emitted when the modification of the document
557 changed. If \a m is TRUE, the document was modified, otherwise the 537 changed. If \a m is TRUE, the document was modified, otherwise the
558 modification state has been reset to unmodified. 538 modification state has been reset to unmodified.
559 539
560 \sa modified 540 \sa modified
561*/ 541*/
562 542
563/*! \fn void QTextEdit::redoAvailable( bool yes ) 543/*! \fn void QTextEdit::redoAvailable( bool yes )
564 544
565 This signal is emitted when the availability of redo changes. If \a 545 This signal is emitted when the availability of redo changes. If \a
566 yes is TRUE, then redo() will work until redoAvailable( FALSE ) is 546 yes is TRUE, then redo() will work until redoAvailable( FALSE ) is
567 next emitted. 547 next emitted.
568 548
569 \sa redo() undoDepth() 549 \sa redo() undoDepth()
570*/ 550*/
571 551
572/*! \fn void QTextEdit::currentFontChanged( const QFont &f ) 552/*! \fn void QTextEdit::currentFontChanged( const QFont &f )
573 553
574 This signal is emitted if the font of the current format has changed. 554 This signal is emitted if the font of the current format has changed.
575 555
576 The new font is \a f. 556 The new font is \a f.
577 557
578 \sa setCurrentFont() 558 \sa setCurrentFont()
579*/ 559*/
580 560
581/*! \fn void QTextEdit::currentColorChanged( const QColor &c ) 561/*! \fn void QTextEdit::currentColorChanged( const QColor &c )
582 562
583 This signal is emitted if the color of the current format has changed. 563 This signal is emitted if the color of the current format has changed.
584 564
585 The new color is \a c. 565 The new color is \a c.
586 566
587 \sa setColor() 567 \sa setColor()
588*/ 568*/
589 569
590/*! \fn void QTextEdit::currentVerticalAlignmentChanged( VerticalAlignment a ) 570/*! \fn void QTextEdit::currentVerticalAlignmentChanged( VerticalAlignment a )
591 571
592 This signal is emitted if the vertical alignment of the current 572 This signal is emitted if the vertical alignment of the current
593 format has changed. 573 format has changed.
594 574
595 The new vertical alignment is \a a. 575 The new vertical alignment is \a a.
596 576
597 \sa setVerticalAlignment() 577 \sa setVerticalAlignment()
598*/ 578*/
599 579
600/*! \fn void QTextEdit::currentAlignmentChanged( int a ) 580/*! \fn void QTextEdit::currentAlignmentChanged( int a )
601 581
602 This signal is emitted if the alignment of the current paragraph 582 This signal is emitted if the alignment of the current paragraph
603 has changed. 583 has changed.
604 584
605 The new alignment is \a a. 585 The new alignment is \a a.
606 586
607 \sa setAlignment() 587 \sa setAlignment()
608*/ 588*/
609 589
610/*! \fn void QTextEdit::cursorPositionChanged( QTextCursor *c ) 590/*! \fn void QTextEdit::cursorPositionChanged( QTextCursor *c )
611 591
612 This signal is emitted if the position of the cursor changed. \a c 592 This signal is emitted if the position of the cursor changed. \a c
613 points to the text cursor object. 593 points to the text cursor object.
614 594
615 \sa setCursorPosition() 595 \sa setCursorPosition()
616*/ 596*/
617 597
618/*! \overload void QTextEdit::cursorPositionChanged( int para, int pos ) 598/*! \overload void QTextEdit::cursorPositionChanged( int para, int pos )
619 599
620 This signal is emitted if the position of the cursor changed. \a 600 This signal is emitted if the position of the cursor changed. \a
621 para contains the paragraph index and \a pos contains the character 601 para contains the paragraph index and \a pos contains the character
622 position within the paragraph. 602 position within the paragraph.
623 603
624 \sa setCursorPosition() 604 \sa setCursorPosition()
625*/ 605*/
626 606
627/*! \fn void QTextEdit::returnPressed() 607/*! \fn void QTextEdit::returnPressed()
628 608
629 This signal is emitted if the user pressed the Return or the Enter key. 609 This signal is emitted if the user pressed the Return or the Enter key.
630*/ 610*/
631 611
632/*! 612/*!
633 \fn QTextCursor *QTextEdit::textCursor() const 613 \fn QTextCursor *QTextEdit::textCursor() const
634 614
635 Returns the text edit's text cursor. 615 Returns the text edit's text cursor.
636 616
637 \warning QTextCursor is not in the public API, but in special 617 \warning QTextCursor is not in the public API, but in special
638 circumstances you might wish to use it. 618 circumstances you might wish to use it.
639*/ 619*/
640 620
641/*! Constructs an empty QTextEdit with parent \a parent and name \a 621/*! Constructs an empty QTextEdit with parent \a parent and name \a
642 name. 622 name.
643*/ 623*/
644 624
645QTextEdit::QTextEdit( QWidget *parent, const char *name ) 625QTextEdit::QTextEdit( QWidget *parent, const char *name )
646 : QScrollView( parent, name, WStaticContents | WRepaintNoErase | WResizeNoErase ), 626 : QScrollView( parent, name, WStaticContents | WRepaintNoErase | WResizeNoErase ),
647 doc( new QTextDocument( 0 ) ), undoRedoInfo( doc ) 627 doc( new QTextDocument( 0 ) ), undoRedoInfo( doc )
648{ 628{
649 init(); 629 init();
650} 630}
651 631
652/*! 632/*!
653 Constructs a QTextEdit with parent \a parent and name \a name. The 633 Constructs a QTextEdit with parent \a parent and name \a name. The
654 text edit will display the text \a text using context \a context. 634 text edit will display the text \a text using context \a context.
655 635
656 The \a context is a path which the text edit's QMimeSourceFactory 636 The \a context is a path which the text edit's QMimeSourceFactory
657 uses to resolve the locations of files and images. It is passed to 637 uses to resolve the locations of files and images. It is passed to
658 the mimeSourceFactory() when quering data. 638 the mimeSourceFactory() when quering data.
659 639
660 For example if the text contains an image tag, 640 For example if the text contains an image tag,
661 \c{<img src="image.png">}, and the context is "path/to/look/in", the 641 \c{<img src="image.png">}, and the context is "path/to/look/in", the
662 QMimeSourceFactory will try to load the image from 642 QMimeSourceFactory will try to load the image from
663 "path/to/look/in/image.png". If the tag was 643 "path/to/look/in/image.png". If the tag was
664 \c{<img src="/image.png">}, the context will not be used (because 644 \c{<img src="/image.png">}, the context will not be used (because
665 QMimeSourceFactory recognizes that we have used an absolute path) 645 QMimeSourceFactory recognizes that we have used an absolute path)
666 and will try to load "/image.png". The context is applied in exactly 646 and will try to load "/image.png". The context is applied in exactly
667 the same way to \e hrefs, for example, 647 the same way to \e hrefs, for example,
668 \c{<a href="target.html">Target</a>}, would resolve to 648 \c{<a href="target.html">Target</a>}, would resolve to
669 "path/to/look/in/target.html". 649 "path/to/look/in/target.html".
670 650
671*/ 651*/
672 652
673QTextEdit::QTextEdit( const QString& text, const QString& context, 653QTextEdit::QTextEdit( const QString& text, const QString& context,
674 QWidget *parent, const char *name) 654 QWidget *parent, const char *name)
675 : QScrollView( parent, name, WStaticContents | WRepaintNoErase | WResizeNoErase ), 655 : QScrollView( parent, name, WStaticContents | WRepaintNoErase | WResizeNoErase ),
676 doc( new QTextDocument( 0 ) ), undoRedoInfo( doc ) 656 doc( new QTextDocument( 0 ) ), undoRedoInfo( doc )
677{ 657{
678 init(); 658 init();
679 setText( text, context ); 659 setText( text, context );
680} 660}
681 661
682/*! \reimp */ 662/*! \reimp */
683 663
684QTextEdit::~QTextEdit() 664QTextEdit::~QTextEdit()
685{ 665{
686 delete undoRedoInfo.d; 666 delete undoRedoInfo.d;
687 undoRedoInfo.d = 0; 667 undoRedoInfo.d = 0;
688 delete cursor; 668 delete cursor;
689 delete doc; 669 delete doc;
690 delete d; 670 delete d;
691} 671}
692 672
693void QTextEdit::init() 673void QTextEdit::init()
694{ 674{
695 setFrameStyle( Sunken ); 675 setFrameStyle( Sunken );
696 undoEnabled = TRUE; 676 undoEnabled = TRUE;
697 readonly = TRUE; 677 readonly = TRUE;
698 setReadOnly( FALSE ); 678 setReadOnly( FALSE );
699 d = new QTextEditPrivate; 679 d = new QTextEditPrivate;
700 connect( doc, SIGNAL( minimumWidthChanged( int ) ), 680 connect( doc, SIGNAL( minimumWidthChanged( int ) ),
701 this, SLOT( documentWidthChanged( int ) ) ); 681 this, SLOT( documentWidthChanged( int ) ) );
702 682
703 mousePressed = FALSE; 683 mousePressed = FALSE;
704 inDoubleClick = FALSE; 684 inDoubleClick = FALSE;
705 modified = FALSE; 685 modified = FALSE;
706 onLink = QString::null; 686 onLink = QString::null;
707 overWrite = FALSE; 687 overWrite = FALSE;
708 wrapMode = WidgetWidth; 688 wrapMode = WidgetWidth;
709 wrapWidth = -1; 689 wrapWidth = -1;
710 wPolicy = AtWhiteSpace; 690 wPolicy = AtWhiteSpace;
711 inDnD = FALSE; 691 inDnD = FALSE;
712 692
713 doc->setFormatter( new QTextFormatterBreakWords ); 693 doc->setFormatter( new QTextFormatterBreakWords );
714 doc->formatCollection()->defaultFormat()->setFont( QScrollView::font() ); 694 doc->formatCollection()->defaultFormat()->setFont( QScrollView::font() );
715 doc->formatCollection()->defaultFormat()->setColor( colorGroup().color( QColorGroup::Text ) ); 695 doc->formatCollection()->defaultFormat()->setColor( colorGroup().color( QColorGroup::Text ) );
716 currentFormat = doc->formatCollection()->defaultFormat(); 696 currentFormat = doc->formatCollection()->defaultFormat();
717 currentAlignment = Qt3::AlignAuto; 697 currentAlignment = Qt3::AlignAuto;
718 698
719 viewport()->setBackgroundMode( PaletteBase ); 699 viewport()->setBackgroundMode( PaletteBase );
720 viewport()->setAcceptDrops( TRUE ); 700 viewport()->setAcceptDrops( TRUE );
721 resizeContents( 0, doc->lastParagraph() ? 701 resizeContents( 0, doc->lastParagraph() ?
722 ( doc->lastParagraph()->paragId() + 1 ) * doc->formatCollection()->defaultFormat()->height() : 0 ); 702 ( doc->lastParagraph()->paragId() + 1 ) * doc->formatCollection()->defaultFormat()->height() : 0 );
723 703
724 setKeyCompression( TRUE ); 704 setKeyCompression( TRUE );
725 viewport()->setMouseTracking( TRUE ); 705 viewport()->setMouseTracking( TRUE );
726#ifndef QT_NO_CURSOR 706#ifndef QT_NO_CURSOR
727 viewport()->setCursor( isReadOnly() ? arrowCursor : ibeamCursor ); 707 viewport()->setCursor( isReadOnly() ? arrowCursor : ibeamCursor );
728#endif 708#endif
729 cursor = new QTextCursor( doc ); 709 cursor = new QTextCursor( doc );
730 710
731 formatTimer = new QTimer( this ); 711 formatTimer = new QTimer( this );
732 connect( formatTimer, SIGNAL( timeout() ), 712 connect( formatTimer, SIGNAL( timeout() ),
733 this, SLOT( formatMore() ) ); 713 this, SLOT( formatMore() ) );
734 lastFormatted = doc->firstParagraph(); 714 lastFormatted = doc->firstParagraph();
735 715
736 scrollTimer = new QTimer( this ); 716 scrollTimer = new QTimer( this );
737 connect( scrollTimer, SIGNAL( timeout() ), 717 connect( scrollTimer, SIGNAL( timeout() ),
738 this, SLOT( autoScrollTimerDone() ) ); 718 this, SLOT( autoScrollTimerDone() ) );
739 719
740 interval = 0; 720 interval = 0;
741 changeIntervalTimer = new QTimer( this ); 721 changeIntervalTimer = new QTimer( this );
742 connect( changeIntervalTimer, SIGNAL( timeout() ), 722 connect( changeIntervalTimer, SIGNAL( timeout() ),
743 this, SLOT( doChangeInterval() ) ); 723 this, SLOT( doChangeInterval() ) );
744 724
745 cursorVisible = TRUE; 725 cursorVisible = TRUE;
746 blinkTimer = new QTimer( this ); 726 blinkTimer = new QTimer( this );
747 connect( blinkTimer, SIGNAL( timeout() ), 727 connect( blinkTimer, SIGNAL( timeout() ),
748 this, SLOT( blinkCursor() ) ); 728 this, SLOT( blinkCursor() ) );
749 729
750#ifndef QT_NO_DRAGANDDROP 730#ifndef QT_NO_DRAGANDDROP
751 dragStartTimer = new QTimer( this ); 731 dragStartTimer = new QTimer( this );
752 connect( dragStartTimer, SIGNAL( timeout() ), 732 connect( dragStartTimer, SIGNAL( timeout() ),
753 this, SLOT( startDrag() ) ); 733 this, SLOT( startDrag() ) );
754#endif 734#endif
755 735
756 736
757 formatMore(); 737 formatMore();
758 738
759 blinkCursorVisible = FALSE; 739 blinkCursorVisible = FALSE;
760 740
761 viewport()->setFocusProxy( this ); 741 viewport()->setFocusProxy( this );
762 viewport()->setFocusPolicy( WheelFocus ); 742 viewport()->setFocusPolicy( WheelFocus );
763 viewport()->installEventFilter( this ); 743 viewport()->installEventFilter( this );
764 installEventFilter( this ); 744 installEventFilter( this );
765} 745}
766 746
767void QTextEdit::paintDocument( bool drawAll, QPainter *p, int cx, int cy, int cw, int ch ) 747void QTextEdit::paintDocument( bool drawAll, QPainter *p, int cx, int cy, int cw, int ch )
768{ 748{
769 bool drawCur = hasFocus() || viewport()->hasFocus(); 749 bool drawCur = hasFocus() || viewport()->hasFocus();
770 if ( hasSelectedText() || isReadOnly() || !cursorVisible ) 750 if ( hasSelectedText() || isReadOnly() || !cursorVisible )
771 drawCur = FALSE; 751 drawCur = FALSE;
772 QColorGroup g = colorGroup(); 752 QColorGroup g = colorGroup();
773 if ( doc->paper() ) 753 if ( doc->paper() )
774 g.setBrush( QColorGroup::Base, *doc->paper() ); 754 g.setBrush( QColorGroup::Base, *doc->paper() );
775 755
776 if ( contentsY() < doc->y() ) { 756 if ( contentsY() < doc->y() ) {
777 p->fillRect( contentsX(), contentsY(), visibleWidth(), doc->y(), 757 p->fillRect( contentsX(), contentsY(), visibleWidth(), doc->y(),
778 g.brush( QColorGroup::Base ) ); 758 g.brush( QColorGroup::Base ) );
779 } 759 }
780 if ( drawAll && doc->width() - contentsX() < cx + cw ) { 760 if ( drawAll && doc->width() - contentsX() < cx + cw ) {
781 p->fillRect( doc->width() - contentsX(), cy, cx + cw - doc->width() + contentsX(), ch, 761 p->fillRect( doc->width() - contentsX(), cy, cx + cw - doc->width() + contentsX(), ch,
782 g.brush( QColorGroup::Base ) ); 762 g.brush( QColorGroup::Base ) );
783 } 763 }
784 764
785 p->setBrushOrigin( -contentsX(), -contentsY() ); 765 p->setBrushOrigin( -contentsX(), -contentsY() );
786 766
787 lastFormatted = doc->draw( p, cx, cy, cw, ch, g, !drawAll, drawCur, cursor ); 767 lastFormatted = doc->draw( p, cx, cy, cw, ch, g, !drawAll, drawCur, cursor );
788 768
789 if ( lastFormatted == doc->lastParagraph() ) 769 if ( lastFormatted == doc->lastParagraph() )
790 resizeContents( contentsWidth(), doc->height() ); 770 resizeContents( contentsWidth(), doc->height() );
791 771
792 if ( contentsHeight() < visibleHeight() && ( !doc->lastParagraph() || doc->lastParagraph()->isValid() ) && drawAll ) 772 if ( contentsHeight() < visibleHeight() && ( !doc->lastParagraph() || doc->lastParagraph()->isValid() ) && drawAll )
793 p->fillRect( 0, contentsHeight(), visibleWidth(), 773 p->fillRect( 0, contentsHeight(), visibleWidth(),
794 visibleHeight() - contentsHeight(), g.brush( QColorGroup::Base ) ); 774 visibleHeight() - contentsHeight(), g.brush( QColorGroup::Base ) );
795} 775}
796 776
797/*! \reimp */ 777/*! \reimp */
798 778
799void QTextEdit::drawContents( QPainter *p, int cx, int cy, int cw, int ch ) 779void QTextEdit::drawContents( QPainter *p, int cx, int cy, int cw, int ch )
800{ 780{
801 paintDocument( TRUE, p, cx, cy, cw, ch ); 781 paintDocument( TRUE, p, cx, cy, cw, ch );
802 int v; 782 int v;
803 p->setPen( foregroundColor() ); 783 p->setPen( foregroundColor() );
804 if ( document()->isPageBreakEnabled() && ( v = document()->flow()->pageSize() ) > 0 ) { 784 if ( document()->isPageBreakEnabled() && ( v = document()->flow()->pageSize() ) > 0 ) {
805 int l = int(cy / v) * v; 785 int l = int(cy / v) * v;
806 while ( l < cy + ch ) { 786 while ( l < cy + ch ) {
807 p->drawLine( cx, l, cx + cw - 1, l ); 787 p->drawLine( cx, l, cx + cw - 1, l );
808 l += v; 788 l += v;
809 } 789 }
810 } 790 }
811 791
812} 792}
813 793
814/*! \reimp */ 794/*! \reimp */
815 795
816void QTextEdit::drawContents( QPainter * ) 796void QTextEdit::drawContents( QPainter * )
817{ 797{
818} 798}
819 799
820/*! \reimp */ 800/*! \reimp */
821 801
822bool QTextEdit::event( QEvent *e ) 802bool QTextEdit::event( QEvent *e )
823{ 803{
824 if ( e->type() == QEvent::AccelOverride && !isReadOnly() ) { 804 if ( e->type() == QEvent::AccelOverride && !isReadOnly() ) {
825 QKeyEvent* ke = (QKeyEvent*) e; 805 QKeyEvent* ke = (QKeyEvent*) e;
826 if ( ke->state() == NoButton || ke->state() == Keypad ) { 806 if ( ke->state() == NoButton || ke->state() == Keypad ) {
827 if ( ke->key() < Key_Escape ) { 807 if ( ke->key() < Key_Escape ) {
828 ke->accept(); 808 ke->accept();
829 } else { 809 } else {
830 switch ( ke->key() ) { 810 switch ( ke->key() ) {
diff --git a/noncore/apps/oxygen/calcdlgui.cpp b/noncore/apps/oxygen/calcdlgui.cpp
index f8dfde5..2bb8337 100644
--- a/noncore/apps/oxygen/calcdlgui.cpp
+++ b/noncore/apps/oxygen/calcdlgui.cpp
@@ -1,64 +1,63 @@
1/*************************************************************************** 1/***************************************************************************
2 application: : Oxygen 2 application: : Oxygen
3 3
4 begin : September 2002 4 begin : September 2002
5 copyright : ( C ) 2002 by Carsten Niehaus 5 copyright : ( C ) 2002 by Carsten Niehaus
6 email : cniehaus@handhelds.org 6 email : cniehaus@handhelds.org
7 **************************************************************************/ 7 **************************************************************************/
8 8
9/*************************************************************************** 9/***************************************************************************
10 * * 10 * *
11 * This program is free software; you can redistribute it and/or modify * 11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by * 12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or * 13 * the Free Software Foundation; either version 2 of the License, or *
14 * ( at your option ) any later version. * 14 * ( at your option ) any later version. *
15 * * 15 * *
16 **************************************************************************/ 16 **************************************************************************/
17#include "oxygen.h"
18 17
19#include "calcdlgui.h" 18#include "calcdlgui.h"
20#include "kmolcalc.h" 19#include "kmolcalc.h"
21#include <qlineedit.h> 20#include <qlineedit.h>
22#include <qmultilineedit.h> 21#include <qmultilineedit.h>
23#include <qpushbutton.h> 22#include <qpushbutton.h>
24 23
25calcDlgUI::calcDlgUI() : CalcDlg() 24calcDlgUI::calcDlgUI() : CalcDlg()
26{ 25{
27 kmolcalc = new KMolCalc; 26 kmolcalc = new KMolCalc;
28 connect( calculate, SIGNAL( clicked() ), this, SLOT( calc() ) ); 27 connect( calculate, SIGNAL( clicked() ), this, SLOT( calc() ) );
29 connect( clear_fields, SIGNAL( clicked() ), this, SLOT( clear() ) ); 28 connect( clear_fields, SIGNAL( clicked() ), this, SLOT( clear() ) );
30 result->setReadOnly( true ); 29 result->setReadOnly( true );
31} 30}
32 31
33void calcDlgUI::calc() 32void calcDlgUI::calc()
34{ 33{
35 QString compound( formula->text() ); 34 QString compound( formula->text() );
36 if ( compound.isEmpty() ) { 35 if ( compound.isEmpty() ) {
37 clear(); 36 clear();
38 return; 37 return;
39 } 38 }
40 QString errors( kmolcalc->readFormula( compound ) ); 39 QString errors( kmolcalc->readFormula( compound ) );
41 QString mw, ea; 40 QString mw, ea;
42 double weight = kmolcalc->getWeight(); 41 double weight = kmolcalc->getWeight();
43 if ( errors == "OK" ) { 42 if ( errors == "OK" ) {
44 mw.setNum( weight ); 43 mw.setNum( weight );
45 ea = kmolcalc->getEmpFormula() + " :\n" + kmolcalc->getEA(); 44 ea = kmolcalc->getEmpFormula() + " :\n" + kmolcalc->getEA();
46 } else { 45 } else {
47 mw = "???"; 46 mw = "???";
48 ea = tr( "ERROR: \n" ).arg( errors )+ "\n"; 47 ea = tr( "ERROR: \n" ).arg( errors )+ "\n";
49 } 48 }
50 result->setText( mw ); 49 result->setText( mw );
51 anal_display->setText( ea ); 50 anal_display->setText( ea );
52} 51}
53 52
54/** 53/**
55 * * Clear all text entry / result fields. 54 * * Clear all text entry / result fields.
56 * */ 55 * */
57void calcDlgUI::clear() 56void calcDlgUI::clear()
58{ 57{
59 formula->clear(); 58 formula->clear();
60 result->clear(); 59 result->clear();
61 anal_display->clear(); 60 anal_display->clear();
62} 61}
63 62
64 63
diff --git a/noncore/apps/oxygen/dataTable.cpp b/noncore/apps/oxygen/dataTable.cpp
index e3906be..48e2b20 100644
--- a/noncore/apps/oxygen/dataTable.cpp
+++ b/noncore/apps/oxygen/dataTable.cpp
@@ -1,152 +1,149 @@
1/*************************************************************************** 1/***************************************************************************
2 application: : Oxygen 2 application: : Oxygen
3 3
4 begin : September 2002 4 begin : September 2002
5 copyright : ( C ) 2002 by Carsten Niehaus 5 copyright : ( C ) 2002 by Carsten Niehaus
6 email : cniehaus@handhelds.org 6 email : cniehaus@handhelds.org
7 **************************************************************************/ 7 **************************************************************************/
8 8
9/*************************************************************************** 9/***************************************************************************
10 * * 10 * *
11 * This program is free software; you can redistribute it and/or modify * 11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by * 12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or * 13 * the Free Software Foundation; either version 2 of the License, or *
14 * ( at your option ) any later version. * 14 * ( at your option ) any later version. *
15 * * 15 * *
16 **************************************************************************/ 16 **************************************************************************/
17 17
18#include <qpe/config.h> 18#include <qpe/config.h>
19 19
20#include "dataTable.h" 20#include "dataTable.h"
21#include <qwidget.h>
22#include <qhbox.h> 21#include <qhbox.h>
23#include <qlabel.h> 22#include <qlabel.h>
24#include <qfont.h>
25#include <qlayout.h> 23#include <qlayout.h>
26#include <qpe/qpeapplication.h> 24#include <qpe/qpeapplication.h>
27 25
28#include <qstringlist.h>
29 26
30OxydataWidget::OxydataWidget(QWidget *parent, const char *name, const QStringList &list ) : QWidget( parent,name ), names( list ) 27OxydataWidget::OxydataWidget(QWidget *parent, const char *name, const QStringList &list ) : QWidget( parent,name ), names( list )
31{ 28{
32 QGridLayout *qgrid = new QGridLayout( this, 2,1 ); 29 QGridLayout *qgrid = new QGridLayout( this, 2,1 );
33 30
34 QHBox *hbox = new QHBox( this ); 31 QHBox *hbox = new QHBox( this );
35 left = new QLabel( hbox ); 32 left = new QLabel( hbox );
36 middle = new QLabel( hbox ); 33 middle = new QLabel( hbox );
37 right = new QLabel( hbox ); 34 right = new QLabel( hbox );
38 35
39 right->setAlignment( AlignRight ); 36 right->setAlignment( AlignRight );
40 middle->setAlignment( AlignHCenter ); 37 middle->setAlignment( AlignHCenter );
41 38
42 QFont bf; 39 QFont bf;
43 bf.setBold( true ); 40 bf.setBold( true );
44 bf.setPointSize( bf.pointSize()+2 ); 41 bf.setPointSize( bf.pointSize()+2 );
45 middle->setFont( bf ); 42 middle->setFont( bf );
46 43
47 DataTable = new OxydataTable( 9,2, this ); 44 DataTable = new OxydataTable( 9,2, this );
48 setTable(); 45 setTable();
49 46
50 qgrid->addWidget( hbox,0,0 ); 47 qgrid->addWidget( hbox,0,0 );
51 qgrid->addWidget( DataTable,1,0 ); 48 qgrid->addWidget( DataTable,1,0 );
52} 49}
53 50
54void OxydataWidget::setElement( int el ) 51void OxydataWidget::setElement( int el )
55{ 52{
56 QStringList::ConstIterator it = names.at(el); 53 QStringList::ConstIterator it = names.at(el);
57 Config configobj( QPEApplication::qpeDir() +"share/oxygen/oxygendata", Config::File ); 54 Config configobj( QPEApplication::qpeDir() +"share/oxygen/oxygendata", Config::File );
58 55
59 configobj.setGroup( QString::number( el+1 )); 56 configobj.setGroup( QString::number( el+1 ));
60 57
61 left->setText( configobj.readEntry( "Symbol" ) ); 58 left->setText( configobj.readEntry( "Symbol" ) );
62 middle->setText( *it ); 59 middle->setText( *it );
63 right->setText( QString::number( el+1 ) ); 60 right->setText( QString::number( el+1 ) );
64 61
65 62
66 DataTable->setText( 0,1,tr( "%1 u" ).arg( configobj.readEntry( "Weight" ) ) ); 63 DataTable->setText( 0,1,tr( "%1 u" ).arg( configobj.readEntry( "Weight" ) ) );
67 DataTable->setText( 1,1,configobj.readEntry( "Block" ) ); 64 DataTable->setText( 1,1,configobj.readEntry( "Block" ) );
68 DataTable->setText( 2,1,configobj.readEntry( "Group" ) ); 65 DataTable->setText( 2,1,configobj.readEntry( "Group" ) );
69 DataTable->setText( 3,1,configobj.readEntry( "EN" ) ); 66 DataTable->setText( 3,1,configobj.readEntry( "EN" ) );
70 DataTable->setText( 4,1,tr( "%1 pm" ).arg( configobj.readEntry( "AR" ) ) ) ; 67 DataTable->setText( 4,1,tr( "%1 pm" ).arg( configobj.readEntry( "AR" ) ) ) ;
71 DataTable->setText( 5,1,tr( "%1 J" ).arg( configobj.readEntry( "IE" ) ) ); 68 DataTable->setText( 5,1,tr( "%1 J" ).arg( configobj.readEntry( "IE" ) ) );
72 DataTable->setText( 6,1,tr( "%1 g/cm^3" ).arg( configobj.readEntry( "Density" ) ) ); 69 DataTable->setText( 6,1,tr( "%1 g/cm^3" ).arg( configobj.readEntry( "Density" ) ) );
73 DataTable->setText( 7,1,tr( "%1 K" ).arg( configobj.readEntry( "BP" ) ) ); 70 DataTable->setText( 7,1,tr( "%1 K" ).arg( configobj.readEntry( "BP" ) ) );
74 DataTable->setText( 8,1,tr( "%1 K" ).arg( configobj.readEntry( "MP" ) ) ); 71 DataTable->setText( 8,1,tr( "%1 K" ).arg( configobj.readEntry( "MP" ) ) );
75} 72}
76 73
77void OxydataWidget::setTable() const 74void OxydataWidget::setTable() const
78{ 75{
79 DataTable->setText( 0,0, tr( "Weight" ) ); 76 DataTable->setText( 0,0, tr( "Weight" ) );
80 DataTable->setText( 1,0, tr( "Block" )) ; 77 DataTable->setText( 1,0, tr( "Block" )) ;
81 DataTable->setText( 2,0, tr( "Group" )) ; 78 DataTable->setText( 2,0, tr( "Group" )) ;
82 DataTable->setText( 3,0, tr( "Electronegativity" )) ; 79 DataTable->setText( 3,0, tr( "Electronegativity" )) ;
83 DataTable->setText( 4,0, tr( "Atomic radius" )) ; 80 DataTable->setText( 4,0, tr( "Atomic radius" )) ;
84 DataTable->setText( 5,0, tr( "Ionization Energy" )) ; 81 DataTable->setText( 5,0, tr( "Ionization Energy" )) ;
85 DataTable->setText( 6,0, tr( "Density" )) ; 82 DataTable->setText( 6,0, tr( "Density" )) ;
86 DataTable->setText( 7,0, tr( "Boiling point" ) ); 83 DataTable->setText( 7,0, tr( "Boiling point" ) );
87 DataTable->setText( 8,0, tr( "Melting point" ) ); 84 DataTable->setText( 8,0, tr( "Melting point" ) );
88} 85}
89 86
90void OxydataWidget::setLayout() 87void OxydataWidget::setLayout()
91{ 88{
92#warning this is not working and I have no idea why! 89#warning this is not working and I have no idea why!
93// DataTable->setColumnWidth ( 0 , this->width()/2 ); 90// DataTable->setColumnWidth ( 0 , this->width()/2 );
94// DataTable->setColumnWidth ( 1 , this->width()/2 ); 91// DataTable->setColumnWidth ( 1 , this->width()/2 );
95 92
96//X DataTable->setColumnWidth ( 0 , 110 ); 93//X DataTable->setColumnWidth ( 0 , 110 );
97//X DataTable->setColumnWidth ( 1 , 110 ); 94//X DataTable->setColumnWidth ( 1 , 110 );
98} 95}
99 96
100OxydataTable::OxydataTable(int numRows, int numCols, QWidget *parent, 97OxydataTable::OxydataTable(int numRows, int numCols, QWidget *parent,
101 const char *name) : QTable(numRows, numCols,parent, name) 98 const char *name) : QTable(numRows, numCols,parent, name)
102{ 99{
103 100
104 for (int zeile = 0; zeile < numRows; zeile++) 101 for (int zeile = 0; zeile < numRows; zeile++)
105 for ( int spalte = 0; spalte < numCols; spalte++ ) 102 for ( int spalte = 0; spalte < numCols; spalte++ )
106 { 103 {
107 OxydataQTI *testus = new OxydataQTI (this, OxydataQTI::Never, "hm" ); 104 OxydataQTI *testus = new OxydataQTI (this, OxydataQTI::Never, "hm" );
108 setItem(zeile, spalte, (QTableItem*)testus); 105 setItem(zeile, spalte, (QTableItem*)testus);
109 } 106 }
110 107
111 108
112 this->setShowGrid( false ); 109 this->setShowGrid( false );
113 this->setHScrollBarMode(QScrollView::AlwaysOff); 110 this->setHScrollBarMode(QScrollView::AlwaysOff);
114 this->horizontalHeader()->hide(); 111 this->horizontalHeader()->hide();
115 this->verticalHeader()->hide(); 112 this->verticalHeader()->hide();
116 this->setTopMargin( 0 ); 113 this->setTopMargin( 0 );
117 this->setLeftMargin( 0 ); 114 this->setLeftMargin( 0 );
118} 115}
119 116
120void OxydataTable::paintCell( QPainter *p, int row, int col, const QRect &cr, bool selected) 117void OxydataTable::paintCell( QPainter *p, int row, int col, const QRect &cr, bool selected)
121{ 118{
122 if ( cr.width() == 0 || cr.height() == 0 ) 119 if ( cr.width() == 0 || cr.height() == 0 )
123 return; 120 return;
124 selected = FALSE; 121 selected = FALSE;
125 122
126 QTableItem *itm = item( row, col ); 123 QTableItem *itm = item( row, col );
127 QColorGroup colgrp = colorGroup(); 124 QColorGroup colgrp = colorGroup();
128 if ( itm ) 125 if ( itm )
129 { 126 {
130 if ( row%2 ) 127 if ( row%2 )
131 colgrp.setColor( QColorGroup::Base, QColor( 180,200,210 ) ); 128 colgrp.setColor( QColorGroup::Base, QColor( 180,200,210 ) );
132 else 129 else
133 colgrp.setColor( QColorGroup::Base, QColor( 230,235,235 ) ); 130 colgrp.setColor( QColorGroup::Base, QColor( 230,235,235 ) );
134 p->save(); 131 p->save();
135 itm->paint( p, colgrp, cr, selected ); 132 itm->paint( p, colgrp, cr, selected );
136 p->restore(); 133 p->restore();
137 } 134 }
138} 135}
139 136
140OxydataQTI::OxydataQTI(QTable * table, EditType et, const QString & text ) 137OxydataQTI::OxydataQTI(QTable * table, EditType et, const QString & text )
141 : QTableItem ( table, et, text ) 138 : QTableItem ( table, et, text )
142{ 139{
143} 140}
144 141
145int OxydataQTI::alignment() const 142int OxydataQTI::alignment() const
146{ 143{
147 if ( col()%2 ) 144 if ( col()%2 )
148 { 145 {
149 return AlignRight | AlignVCenter; 146 return AlignRight | AlignVCenter;
150 }else return AlignLeft | AlignVCenter; 147 }else return AlignLeft | AlignVCenter;
151}; 148};
152 149
diff --git a/noncore/apps/oxygen/datawidgetui.cpp b/noncore/apps/oxygen/datawidgetui.cpp
index e1d6e41..dcb80e5 100644
--- a/noncore/apps/oxygen/datawidgetui.cpp
+++ b/noncore/apps/oxygen/datawidgetui.cpp
@@ -1,53 +1,48 @@
1/*************************************************************************** 1/***************************************************************************
2 application: : Oxygen 2 application: : Oxygen
3 3
4 begin : September 2002 4 begin : September 2002
5 copyright : ( C ) 2002 by Carsten Niehaus 5 copyright : ( C ) 2002 by Carsten Niehaus
6 email : cniehaus@handhelds.org 6 email : cniehaus@handhelds.org
7 **************************************************************************/ 7 **************************************************************************/
8 8
9/*************************************************************************** 9/***************************************************************************
10 * * 10 * *
11 * This program is free software; you can redistribute it and/or modify * 11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by * 12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or * 13 * the Free Software Foundation; either version 2 of the License, or *
14 * ( at your option ) any later version. * 14 * ( at your option ) any later version. *
15 * * 15 * *
16 **************************************************************************/ 16 **************************************************************************/
17 17
18#include "datawidgetui.h" 18#include "datawidgetui.h"
19#include "dataTable.h" 19#include "dataTable.h"
20 20
21#include <qpe/config.h>
22#include <qstring.h>
23#include <qcombobox.h> 21#include <qcombobox.h>
24#include <qlayout.h> 22#include <qlayout.h>
25#include <qhbox.h>
26#include <qlabel.h>
27#include <qpe/qpeapplication.h>
28 23
29dataWidgetUI::dataWidgetUI(const QStringList &list) : QWidget() 24dataWidgetUI::dataWidgetUI(const QStringList &list) : QWidget()
30{ 25{
31 names = list; 26 names = list;
32 27
33 this->setCaption( tr( "Chemical Data" )); 28 this->setCaption( tr( "Chemical Data" ));
34 QGridLayout *qgrid = new QGridLayout( this, 2,1 ); 29 QGridLayout *qgrid = new QGridLayout( this, 2,1 );
35 30
36 dataCombo = new QComboBox( this ); 31 dataCombo = new QComboBox( this );
37 32
38 //read in all names of the 118 elements 33 //read in all names of the 118 elements
39 int i = 0; 34 int i = 0;
40 for ( QStringList::ConstIterator it = names.begin() ; it != names.end() ; ++it,i++) 35 for ( QStringList::ConstIterator it = names.begin() ; it != names.end() ; ++it,i++)
41 { 36 {
42 dataCombo->insertItem( QString::number( i+1 )+" - "+*it ); 37 dataCombo->insertItem( QString::number( i+1 )+" - "+*it );
43 } 38 }
44 OxydataWidget *oxyDW = new OxydataWidget(this, "OxydataWidget_oxyDW", names); 39 OxydataWidget *oxyDW = new OxydataWidget(this, "OxydataWidget_oxyDW", names);
45 connect ( dataCombo, SIGNAL( activated(int) ), oxyDW, SLOT( setElement(int) ) ); 40 connect ( dataCombo, SIGNAL( activated(int) ), oxyDW, SLOT( setElement(int) ) );
46 oxyDW->setElement( 0 ); 41 oxyDW->setElement( 0 );
47 oxyDW->setLayout(); 42 oxyDW->setLayout();
48 43
49 qgrid->addWidget( dataCombo, 0,0); 44 qgrid->addWidget( dataCombo, 0,0);
50 qgrid->addWidget( oxyDW , 1,0 ); 45 qgrid->addWidget( oxyDW , 1,0 );
51} 46}
52 47
53 48
diff --git a/noncore/apps/oxygen/kmolcalc.cpp b/noncore/apps/oxygen/kmolcalc.cpp
index 7a47942..b9f5209 100644
--- a/noncore/apps/oxygen/kmolcalc.cpp
+++ b/noncore/apps/oxygen/kmolcalc.cpp
@@ -1,199 +1,196 @@
1/* 1/*
2 * kmolcalc.cpp 2 * kmolcalc.cpp
3 * 3 *
4 * Copyright (C) 2000,2001 Tomislav Gountchev <tomi@idiom.com> 4 * Copyright (C) 2000,2001 Tomislav Gountchev <tomi@idiom.com>
5 * Copyright (C) 2002 Carsten Niehaus <cniehaus@handhelds.org> 5 * Copyright (C) 2002 Carsten Niehaus <cniehaus@handhelds.org>
6 */ 6 */
7 7
8/** 8/**
9 * KMOLCALC is the calculation engine. It knows about a hashtable of user defined atomic 9 * KMOLCALC is the calculation engine. It knows about a hashtable of user defined atomic
10 * weights and group definitions ELSTABLE, and the currently processed formula, stored 10 * weights and group definitions ELSTABLE, and the currently processed formula, stored
11 * as a list of elements and their coefficients, ELEMENTS. 11 * as a list of elements and their coefficients, ELEMENTS.
12 */ 12 */
13 13
14#include "kmolcalc.h" 14#include "kmolcalc.h"
15#include <qdict.h>
16#include <qdir.h>
17#include <qfile.h>
18#include <qpe/qpeapplication.h> 15#include <qpe/qpeapplication.h>
19 16
20 17
21/** 18/**
22 * Construct a new calculator object. 19 * Construct a new calculator object.
23 */ 20 */
24KMolCalc::KMolCalc() { 21KMolCalc::KMolCalc() {
25 elements = new ElementList; 22 elements = new ElementList;
26 elstable = NULL; 23 elstable = NULL;
27 readElstable(); 24 readElstable();
28} 25}
29 26
30KMolCalc::~KMolCalc() { 27KMolCalc::~KMolCalc() {
31 delete elements; 28 delete elements;
32} 29}
33 30
34void KMolCalc::readElstable() { 31void KMolCalc::readElstable() {
35 weight = -1; // not calculated yet 32 weight = -1; // not calculated yet
36 if (elstable) delete elstable; 33 if (elstable) delete elstable;
37 elstable = new QDict<SubUnit> (197, TRUE); 34 elstable = new QDict<SubUnit> (197, TRUE);
38 elstable->setAutoDelete(TRUE); 35 elstable->setAutoDelete(TRUE);
39 mwfile = QPEApplication::qpeDir() +"share/oxygen/kmolweights"; 36 mwfile = QPEApplication::qpeDir() +"share/oxygen/kmolweights";
40 QFile f(mwfile); 37 QFile f(mwfile);
41 if (f.exists()) readMwfile(f); 38 if (f.exists()) readMwfile(f);
42} 39}
43 40
44 41
45/** 42/**
46 * Parse a string S and construct the ElementList this->ELEMENTS, representing the 43 * Parse a string S and construct the ElementList this->ELEMENTS, representing the
47 * composition of S. Returns 0 if successful, or an error code (currently -1) if 44 * composition of S. Returns 0 if successful, or an error code (currently -1) if
48 * parsing failed. 45 * parsing failed.
49 * The elements is S must be valid element or group symbols, as stored in this->ELSTABLE. 46 * The elements is S must be valid element or group symbols, as stored in this->ELSTABLE.
50 * See help files for correct formula syntax. 47 * See help files for correct formula syntax.
51 */ 48 */
52QString KMolCalc::readFormula(const QString& s) { 49QString KMolCalc::readFormula(const QString& s) {
53 weight = -1; 50 weight = -1;
54 if (elements) delete elements; 51 if (elements) delete elements;
55 elements = new ElementList; 52 elements = new ElementList;
56 return KMolCalc::readGroup(s, elements); 53 return KMolCalc::readGroup(s, elements);
57} 54}
58 55
59// read a formula group recursively. Called by readFormula. 56// read a formula group recursively. Called by readFormula.
60QString KMolCalc::readGroup(const QString& s, ElementList* els) { 57QString KMolCalc::readGroup(const QString& s, ElementList* els) {
61 if (s.isEmpty()) return QString ("Enter a formula."); //ERROR 58 if (s.isEmpty()) return QString ("Enter a formula."); //ERROR
62 int sl = s.length(); 59 int sl = s.length();
63 int i = 0; 60 int i = 0;
64 QString errors ("OK"); 61 QString errors ("OK");
65 bool ok = TRUE; 62 bool ok = TRUE;
66 while (i < sl && ((s[i] <= '9' && s[i] >= '0') || s[i] == '.')) i++; 63 while (i < sl && ((s[i] <= '9' && s[i] >= '0') || s[i] == '.')) i++;
67 double prefix = (i == 0 ? 1 : s.left(i).toDouble(&ok)); 64 double prefix = (i == 0 ? 1 : s.left(i).toDouble(&ok));
68 if (! ok || i == sl || prefix == 0) return QString ("Bad formula."); // ERROR 65 if (! ok || i == sl || prefix == 0) return QString ("Bad formula."); // ERROR
69 ElementList* elstemp = new ElementList; 66 ElementList* elstemp = new ElementList;
70 while (i < sl) { 67 while (i < sl) {
71 int j = i; 68 int j = i;
72 if (s[i] == '(') { 69 if (s[i] == '(') {
73 ElementList* inner = new ElementList; 70 ElementList* inner = new ElementList;
74 int level = 1; // count levels of nested ( ). 71 int level = 1; // count levels of nested ( ).
75 while (1) { 72 while (1) {
76 if (i++ == sl) { 73 if (i++ == sl) {
77 delete inner; 74 delete inner;
78 delete elstemp; 75 delete elstemp;
79 return QString ("Bad formula."); //ERROR 76 return QString ("Bad formula."); //ERROR
80 } 77 }
81 if (s[i] == '(') level++; 78 if (s[i] == '(') level++;
82 if (s[i] == ')') level--; 79 if (s[i] == ')') level--;
83 if (level == 0) break; 80 if (level == 0) break;
84 } 81 }
85 errors = KMolCalc::readGroup(s.mid(j+1, i-j-1), inner); 82 errors = KMolCalc::readGroup(s.mid(j+1, i-j-1), inner);
86 j = ++i; 83 j = ++i;
87 while (i < sl && ((s[i] <= '9' && s[i] >= '0') || s[i] == '.')) i++; 84 while (i < sl && ((s[i] <= '9' && s[i] >= '0') || s[i] == '.')) i++;
88 double suffix = (i == j ? 1 : s.mid(j, i-j).toDouble(&ok)); 85 double suffix = (i == j ? 1 : s.mid(j, i-j).toDouble(&ok));
89 if (! ok || suffix == 0) { 86 if (! ok || suffix == 0) {
90 delete inner; 87 delete inner;
91 delete elstemp; 88 delete elstemp;
92 return QString ("Bad formula."); // ERROR 89 return QString ("Bad formula."); // ERROR
93 } 90 }
94 inner->addTo(*elstemp, suffix); 91 inner->addTo(*elstemp, suffix);
95 delete inner; 92 delete inner;
96 inner = NULL; 93 inner = NULL;
97 } else if ((s[i] >= 'A' && s[i] <= 'Z') || (s[i] >= 'a' && s[i] <= 'z')) { 94 } else if ((s[i] >= 'A' && s[i] <= 'Z') || (s[i] >= 'a' && s[i] <= 'z')) {
98 while (++i < sl && ((s[i] >= 'a' && s[i] <= 'z') || s[i] == '*' || 95 while (++i < sl && ((s[i] >= 'a' && s[i] <= 'z') || s[i] == '*' ||
99 s[i] == '\'')); 96 s[i] == '\''));
100 QString elname = s.mid(j, i-j); 97 QString elname = s.mid(j, i-j);
101 j = i; 98 j = i;
102 while (i < sl && ((s[i] <= '9' && s[i] >= '0') || s[i] == '.')) i++; 99 while (i < sl && ((s[i] <= '9' && s[i] >= '0') || s[i] == '.')) i++;
103 double suffix = (i == j ? 1 : s.mid(j, i-j).toDouble(&ok)); 100 double suffix = (i == j ? 1 : s.mid(j, i-j).toDouble(&ok));
104 if (! ok || suffix == 0) { 101 if (! ok || suffix == 0) {
105 delete elstemp; 102 delete elstemp;
106 return QString ("Bad formula."); // ERROR 103 return QString ("Bad formula."); // ERROR
107 } 104 }
108 SubUnit* group = elstable->find(elname); 105 SubUnit* group = elstable->find(elname);
109 if (group == 0) { 106 if (group == 0) {
110 delete elstemp; 107 delete elstemp;
111 return QString ("Undefined symbol: ") + elname; //ERROR 108 return QString ("Undefined symbol: ") + elname; //ERROR
112 } 109 }
113 group->addTo(*elstemp, suffix); 110 group->addTo(*elstemp, suffix);
114 } else if (s[i] == '+') { 111 } else if (s[i] == '+') {
115 if (elstemp->isEmpty()) { 112 if (elstemp->isEmpty()) {
116 delete elstemp; 113 delete elstemp;
117 return QString ("Bad formula."); //ERROR 114 return QString ("Bad formula."); //ERROR
118 } 115 }
119 elstemp->addTo(*els, prefix); 116 elstemp->addTo(*els, prefix);
120 delete elstemp; 117 delete elstemp;
121 errors = KMolCalc::readGroup(s.mid(i+1, sl-i-1), els); 118 errors = KMolCalc::readGroup(s.mid(i+1, sl-i-1), els);
122 return errors; 119 return errors;
123 } else { 120 } else {
124 delete elstemp; 121 delete elstemp;
125 return QString ("Bad formula."); //ERROR 122 return QString ("Bad formula."); //ERROR
126 } 123 }
127 } 124 }
128 elstemp->addTo(*els, prefix); 125 elstemp->addTo(*els, prefix);
129 delete elstemp; 126 delete elstemp;
130 return errors; 127 return errors;
131} 128}
132 129
133/** 130/**
134 * Calculate and return the molecular weight of the current chemical formula. 131 * Calculate and return the molecular weight of the current chemical formula.
135 */ 132 */
136double KMolCalc::getWeight() { 133double KMolCalc::getWeight() {
137 if (weight == -1) weight = elements->getWeight(elstable); 134 if (weight == -1) weight = elements->getWeight(elstable);
138 return weight; 135 return weight;
139} 136}
140 137
141/** 138/**
142 * Return the elemental composition of the current formula, as a string of tab-separated 139 * Return the elemental composition of the current formula, as a string of tab-separated
143 * element - percentage pairs, separated by newlines. 140 * element - percentage pairs, separated by newlines.
144 */ 141 */
145QString KMolCalc::getEA() { 142QString KMolCalc::getEA() {
146 if (weight == -1) weight = elements->getWeight(elstable); 143 if (weight == -1) weight = elements->getWeight(elstable);
147 if (weight == -1) return QString("ERROR: Couldn't get Mw..."); // ERROR 144 if (weight == -1) return QString("ERROR: Couldn't get Mw..."); // ERROR
148 return elements->getEA(elstable, weight); 145 return elements->getEA(elstable, weight);
149} 146}
150 147
151/** 148/**
152 * Return the empirical formula of the current compound as a QString. 149 * Return the empirical formula of the current compound as a QString.
153 */ 150 */
154QString KMolCalc::getEmpFormula() { 151QString KMolCalc::getEmpFormula() {
155 return elements->getEmpFormula(); 152 return elements->getEmpFormula();
156} 153}
157 154
158// Read the element definition file. 155// Read the element definition file.
159void KMolCalc::readMwfile(QFile& f) { 156void KMolCalc::readMwfile(QFile& f) {
160 if (! f.open(IO_ReadOnly)) return; //ERROR 157 if (! f.open(IO_ReadOnly)) return; //ERROR
161 QTextStream fs (&f); 158 QTextStream fs (&f);
162 QString line; 159 QString line;
163 while (! fs.eof()) { 160 while (! fs.eof()) {
164 line = fs.readLine(); 161 line = fs.readLine();
165 SubUnit* s = SubUnit::makeSubUnit(line); 162 SubUnit* s = SubUnit::makeSubUnit(line);
166 elstable->replace(s->getName(), s); 163 elstable->replace(s->getName(), s);
167 } 164 }
168 f.close(); 165 f.close();
169} 166}
170 167
171/** 168/**
172 * Remove a group or element definition from ELSTABLE. 169 * Remove a group or element definition from ELSTABLE.
173 */ 170 */
174void KMolCalc::undefineGroup (const QString& name) { 171void KMolCalc::undefineGroup (const QString& name) {
175 elstable->remove (name); 172 elstable->remove (name);
176} 173}
177 174
178/** 175/**
179 * Add a new element name - atomic weight record to the ELSTABLE hashtable. Assumes 176 * Add a new element name - atomic weight record to the ELSTABLE hashtable. Assumes
180 * NAME has valid syntax. 177 * NAME has valid syntax.
181 178
182 */ 179 */
183void KMolCalc::defineElement (const QString& name, double weight) { 180void KMolCalc::defineElement (const QString& name, double weight) {
184 Element* el = new Element(name, weight); 181 Element* el = new Element(name, weight);
185 elstable->replace(name, el); 182 elstable->replace(name, el);
186} 183}
187 184
188/** 185/**
189 * Add a new group definition to the ELSTABLE. Returns 0 if OK, -1 if parsing FORMULA 186 * Add a new group definition to the ELSTABLE. Returns 0 if OK, -1 if parsing FORMULA
190 * fails. Assumes the syntax of grpname is correct. 187 * fails. Assumes the syntax of grpname is correct.
191 */ 188 */
192QString KMolCalc::defineGroup (const QString& grpname, const QString& formula) { 189QString KMolCalc::defineGroup (const QString& grpname, const QString& formula) {
193 ElementList* els = new ElementList(grpname); 190 ElementList* els = new ElementList(grpname);
194 QString error = readGroup(formula, els); 191 QString error = readGroup(formula, els);
195 if (error != "OK") return error; 192 if (error != "OK") return error;
196 if (els->contains(grpname)) return QString("Can't define a group recursively!\n"); 193 if (els->contains(grpname)) return QString("Can't define a group recursively!\n");
197 elstable->replace(grpname, els); 194 elstable->replace(grpname, els);
198 return QString("OK"); 195 return QString("OK");
199} 196}
diff --git a/noncore/apps/oxygen/oxyframe.cpp b/noncore/apps/oxygen/oxyframe.cpp
index 5a4dbbe..8cc520e 100644
--- a/noncore/apps/oxygen/oxyframe.cpp
+++ b/noncore/apps/oxygen/oxyframe.cpp
@@ -1,41 +1,39 @@
1/*************************************************************************** 1/***************************************************************************
2 application: : Oxygen 2 application: : Oxygen
3 3
4 begin : September 2002 4 begin : September 2002
5 copyright : ( C ) 2002 by Carsten Niehaus 5 copyright : ( C ) 2002 by Carsten Niehaus
6 email : cniehaus@handhelds.org 6 email : cniehaus@handhelds.org
7 **************************************************************************/ 7 **************************************************************************/
8 8
9/*************************************************************************** 9/***************************************************************************
10 * * 10 * *
11 * This program is free software; you can redistribute it and/or modify * 11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by * 12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or * 13 * the Free Software Foundation; either version 2 of the License, or *
14 * ( at your option ) any later version. * 14 * ( at your option ) any later version. *
15 * * 15 * *
16 **************************************************************************/ 16 **************************************************************************/
17#include "oxygen.h"
18 17
19#include <qpe/config.h>
20#include "oxyframe.h" 18#include "oxyframe.h"
21 19
22OxyFrame::OxyFrame(QWidget *parent, const char *name, QString symbol ) 20OxyFrame::OxyFrame(QWidget *parent, const char *name, QString symbol )
23 : QLabel(parent,name) 21 : QLabel(parent,name)
24{ 22{
25 N = name; 23 N = name;
26 this->setFrameStyle( QFrame::Box ); 24 this->setFrameStyle( QFrame::Box );
27 this->setLineWidth( 0 ); 25 this->setLineWidth( 0 );
28 this->setMidLineWidth( 1 ); 26 this->setMidLineWidth( 1 );
29 this->setFrameShadow( QFrame::Sunken ); 27 this->setFrameShadow( QFrame::Sunken );
30 setMinimumSize(6,6); 28 setMinimumSize(6,6);
31 setScaledContents( true ); 29 setScaledContents( true );
32 QFont font; 30 QFont font;
33 font.setWeight(QFont::Light); 31 font.setWeight(QFont::Light);
34 font.setPixelSize(3); 32 font.setPixelSize(3);
35 setFont( font ); 33 setFont( font );
36 setText( symbol ); 34 setText( symbol );
37} 35}
38 36
39void OxyFrame::mousePressEvent ( QMouseEvent* /*e*/ ){ 37void OxyFrame::mousePressEvent ( QMouseEvent* /*e*/ ){
40 emit num( N ); 38 emit num( N );
41}; 39};
diff --git a/noncore/apps/oxygen/oxygen.cpp b/noncore/apps/oxygen/oxygen.cpp
index 5bdc2aa..5ea97bf 100644
--- a/noncore/apps/oxygen/oxygen.cpp
+++ b/noncore/apps/oxygen/oxygen.cpp
@@ -1,157 +1,155 @@
1/*************************************************************************** 1/***************************************************************************
2 application: : Oxygen 2 application: : Oxygen
3 3
4 begin : September 2002 4 begin : September 2002
5 copyright : ( C ) 2002 by Carsten Niehaus 5 copyright : ( C ) 2002 by Carsten Niehaus
6 email : cniehaus@handhelds.org 6 email : cniehaus@handhelds.org
7 **************************************************************************/ 7 **************************************************************************/
8 8
9/*************************************************************************** 9/***************************************************************************
10 * * 10 * *
11 * This program is free software; you can redistribute it and/or modify * 11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by * 12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or * 13 * the Free Software Foundation; either version 2 of the License, or *
14 * ( at your option ) any later version. * 14 * ( at your option ) any later version. *
15 * * 15 * *
16 **************************************************************************/ 16 **************************************************************************/
17#include "oxygen.h" 17#include "oxygen.h"
18 18
19#include <qapplication.h>
20#include <qtabwidget.h> 19#include <qtabwidget.h>
21 20
22#include "calcdlg.h"
23#include "calcdlgui.h" 21#include "calcdlgui.h"
24#include "datawidgetui.h" 22#include "datawidgetui.h"
25#include "psewidget.h" 23#include "psewidget.h"
26 24
27 25
28Oxygen::Oxygen( QWidget *parent, const char *name, WFlags f) : QMainWindow( parent, name, f ) 26Oxygen::Oxygen( QWidget *parent, const char *name, WFlags f) : QMainWindow( parent, name, f )
29{ 27{
30 loadNames(); 28 loadNames();
31 calcDlgUI *CalcDlgUI = new calcDlgUI(); 29 calcDlgUI *CalcDlgUI = new calcDlgUI();
32 PSEWidget *pse = new PSEWidget(names); 30 PSEWidget *pse = new PSEWidget(names);
33 dataWidgetUI *DataWidgetUI = new dataWidgetUI(names); 31 dataWidgetUI *DataWidgetUI = new dataWidgetUI(names);
34 32
35 setCaption( tr( "Oxygen" ) ); 33 setCaption( tr( "Oxygen" ) );
36 34
37 QTabWidget *tabw = new QTabWidget( this , "qtab" ); 35 QTabWidget *tabw = new QTabWidget( this , "qtab" );
38 tabw->addTab( pse, tr( "PSE" )); 36 tabw->addTab( pse, tr( "PSE" ));
39 tabw->addTab( DataWidgetUI , tr( "Data" ) ); 37 tabw->addTab( DataWidgetUI , tr( "Data" ) );
40 tabw->addTab( CalcDlgUI, tr( "Calculations" ) ); 38 tabw->addTab( CalcDlgUI, tr( "Calculations" ) );
41 setCentralWidget( tabw ); 39 setCentralWidget( tabw );
42} 40}
43 41
44void Oxygen::loadNames() 42void Oxygen::loadNames()
45{ 43{
46 names.clear(); 44 names.clear();
47 names.append( tr("Hydrogen") ); 45 names.append( tr("Hydrogen") );
48 names.append( tr("Helium") ); 46 names.append( tr("Helium") );
49 names.append( tr("Lithium") ); 47 names.append( tr("Lithium") );
50 names.append( tr("Beryllium") ); 48 names.append( tr("Beryllium") );
51 names.append( tr("Boron") ); 49 names.append( tr("Boron") );
52 names.append( tr("Carbon") ); 50 names.append( tr("Carbon") );
53 names.append( tr("Nitrogen") ); 51 names.append( tr("Nitrogen") );
54 names.append( tr("Oxygen") ); 52 names.append( tr("Oxygen") );
55 names.append( tr("Fluorine") ); 53 names.append( tr("Fluorine") );
56 names.append( tr("Neon") ); 54 names.append( tr("Neon") );
57 names.append( tr("Sodium") ); 55 names.append( tr("Sodium") );
58 names.append( tr("Magnesium") ); 56 names.append( tr("Magnesium") );
59 names.append( tr("Aluminum") ); 57 names.append( tr("Aluminum") );
60 names.append( tr("Silicon") ); 58 names.append( tr("Silicon") );
61 names.append( tr("Phosphorus") ); 59 names.append( tr("Phosphorus") );
62 names.append( tr("Sulfur") ); 60 names.append( tr("Sulfur") );
63 names.append( tr("Chlorine") ); 61 names.append( tr("Chlorine") );
64 names.append( tr("Argon") ); 62 names.append( tr("Argon") );
65 names.append( tr("Potassium") ); 63 names.append( tr("Potassium") );
66 names.append( tr("Calcium") ); 64 names.append( tr("Calcium") );
67 names.append( tr("Scandium") ); 65 names.append( tr("Scandium") );
68 names.append( tr("Titanium") ); 66 names.append( tr("Titanium") );
69 names.append( tr("Vanadium") ); 67 names.append( tr("Vanadium") );
70 names.append( tr("Chromium") ); 68 names.append( tr("Chromium") );
71 names.append( tr("Manganese") ); 69 names.append( tr("Manganese") );
72 names.append( tr("Iron") ); 70 names.append( tr("Iron") );
73 names.append( tr("Cobalt") ); 71 names.append( tr("Cobalt") );
74 names.append( tr("Nickel") ); 72 names.append( tr("Nickel") );
75 names.append( tr("Copper") ); 73 names.append( tr("Copper") );
76 names.append( tr("Zinc") ); 74 names.append( tr("Zinc") );
77 names.append( tr("Gallium") ); 75 names.append( tr("Gallium") );
78 names.append( tr("Germanium") ); 76 names.append( tr("Germanium") );
79 names.append( tr("Arsenic") ); 77 names.append( tr("Arsenic") );
80 names.append( tr("Selenium") ); 78 names.append( tr("Selenium") );
81 names.append( tr("Bromine") ); 79 names.append( tr("Bromine") );
82 names.append( tr("Krypton") ); 80 names.append( tr("Krypton") );
83 names.append( tr("Rubidium") ); 81 names.append( tr("Rubidium") );
84 names.append( tr("Strontium") ); 82 names.append( tr("Strontium") );
85 names.append( tr("Yttrium") ); 83 names.append( tr("Yttrium") );
86 names.append( tr("Zirconium") ); 84 names.append( tr("Zirconium") );
87 names.append( tr("Niobium") ); 85 names.append( tr("Niobium") );
88 names.append( tr("Molybdenum") ); 86 names.append( tr("Molybdenum") );
89 names.append( tr("Technetium") ); 87 names.append( tr("Technetium") );
90 names.append( tr("Ruthenium") ); 88 names.append( tr("Ruthenium") );
91 names.append( tr("Rhodium") ); 89 names.append( tr("Rhodium") );
92 names.append( tr("Palladium") ); 90 names.append( tr("Palladium") );
93 names.append( tr("Silver") ); 91 names.append( tr("Silver") );
94 names.append( tr("Cadmium") ); 92 names.append( tr("Cadmium") );
95 names.append( tr("Indium") ); 93 names.append( tr("Indium") );
96 names.append( tr("Tin") ); 94 names.append( tr("Tin") );
97 names.append( tr("Antimony") ); 95 names.append( tr("Antimony") );
98 names.append( tr("Tellurium") ); 96 names.append( tr("Tellurium") );
99 names.append( tr("Iodine") ); 97 names.append( tr("Iodine") );
100 names.append( tr("Xenon") ); 98 names.append( tr("Xenon") );
101 names.append( tr("Cesium") ); 99 names.append( tr("Cesium") );
102 names.append( tr("Barium") ); 100 names.append( tr("Barium") );
103 names.append( tr("Lanthanum") ); 101 names.append( tr("Lanthanum") );
104 names.append( tr("Cerium") ); 102 names.append( tr("Cerium") );
105 names.append( tr("Praseodymium") ); 103 names.append( tr("Praseodymium") );
106 names.append( tr("Neodymium") ); 104 names.append( tr("Neodymium") );
107 names.append( tr("Promethium") ); 105 names.append( tr("Promethium") );
108 names.append( tr("Samarium") ); 106 names.append( tr("Samarium") );
109 names.append( tr("Europium") ); 107 names.append( tr("Europium") );
110 names.append( tr("Gadolinium") ); 108 names.append( tr("Gadolinium") );
111 names.append( tr("Terbium") ); 109 names.append( tr("Terbium") );
112 names.append( tr("Dysprosium") ); 110 names.append( tr("Dysprosium") );
113 names.append( tr("Holmium") ); 111 names.append( tr("Holmium") );
114 names.append( tr("Erbium") ); 112 names.append( tr("Erbium") );
115 names.append( tr("Thulium") ); 113 names.append( tr("Thulium") );
116 names.append( tr("Ytterbium") ); 114 names.append( tr("Ytterbium") );
117 names.append( tr("Lutetium") ); 115 names.append( tr("Lutetium") );
118 names.append( tr("Hafnium") ); 116 names.append( tr("Hafnium") );
119 names.append( tr("Tantalum") ); 117 names.append( tr("Tantalum") );
120 names.append( tr("Tungsten") ); 118 names.append( tr("Tungsten") );
121 names.append( tr("Rhenium") ); 119 names.append( tr("Rhenium") );
122 names.append( tr("Osmium") ); 120 names.append( tr("Osmium") );
123 names.append( tr("Iridium") ); 121 names.append( tr("Iridium") );
124 names.append( tr("Platinum") ); 122 names.append( tr("Platinum") );
125 names.append( tr("Gold") ); 123 names.append( tr("Gold") );
126 names.append( tr("Mercury") ); 124 names.append( tr("Mercury") );
127 names.append( tr("Thallium") ); 125 names.append( tr("Thallium") );
128 names.append( tr("Lead") ); 126 names.append( tr("Lead") );
129 names.append( tr("Bismuth") ); 127 names.append( tr("Bismuth") );
130 names.append( tr("Polonium") ); 128 names.append( tr("Polonium") );
131 names.append( tr("Astatine") ); 129 names.append( tr("Astatine") );
132 names.append( tr("Radon") ); 130 names.append( tr("Radon") );
133 names.append( tr("Francium") ); 131 names.append( tr("Francium") );
134 names.append( tr("Radium") ); 132 names.append( tr("Radium") );
135 names.append( tr("Actinium") ); 133 names.append( tr("Actinium") );
136 names.append( tr("Thorium") ); 134 names.append( tr("Thorium") );
137 names.append( tr("Protactinium") ); 135 names.append( tr("Protactinium") );
138 names.append( tr("Uranium") ); 136 names.append( tr("Uranium") );
139 names.append( tr("Neptunium") ); 137 names.append( tr("Neptunium") );
140 names.append( tr("Plutonium") ); 138 names.append( tr("Plutonium") );
141 names.append( tr("Americium") ); 139 names.append( tr("Americium") );
142 names.append( tr("Curium") ); 140 names.append( tr("Curium") );
143 names.append( tr("Berkelium") ); 141 names.append( tr("Berkelium") );
144 names.append( tr("Californium") ); 142 names.append( tr("Californium") );
145 names.append( tr("Einsteinium") ); 143 names.append( tr("Einsteinium") );
146 names.append( tr("Fermium") ); 144 names.append( tr("Fermium") );
147 names.append( tr("Mendelevium") ); 145 names.append( tr("Mendelevium") );
148 names.append( tr("Nobelium") ); 146 names.append( tr("Nobelium") );
149 names.append( tr("Lawrencium") ); 147 names.append( tr("Lawrencium") );
150 names.append( tr("Rutherfordium") ); 148 names.append( tr("Rutherfordium") );
151 names.append( tr("Dubnium") ); 149 names.append( tr("Dubnium") );
152 names.append( tr("Seaborgium") ); 150 names.append( tr("Seaborgium") );
153 names.append( tr("Bohrium") ); 151 names.append( tr("Bohrium") );
154 names.append( tr("Hassium") ); 152 names.append( tr("Hassium") );
155 names.append( tr("Meitnerium") ); 153 names.append( tr("Meitnerium") );
156} 154}
157 155
diff --git a/noncore/apps/oxygen/psewidget.cpp b/noncore/apps/oxygen/psewidget.cpp
index be5185b..7f7ae0c 100644
--- a/noncore/apps/oxygen/psewidget.cpp
+++ b/noncore/apps/oxygen/psewidget.cpp
@@ -1,198 +1,196 @@
1/*************************************************************************** 1/***************************************************************************
2 application: : Oxygen 2 application: : Oxygen
3 3
4 begin : September 2002 4 begin : September 2002
5 copyright : ( C ) 2002, 2003 by Carsten Niehaus 5 copyright : ( C ) 2002, 2003 by Carsten Niehaus
6 email : cniehaus@handhelds.org 6 email : cniehaus@handhelds.org
7 **************************************************************************/ 7 **************************************************************************/
8 8
9/*************************************************************************** 9/***************************************************************************
10 * * 10 * *
11 * This program is free software; you can redistribute it and/or modify * 11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by * 12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or * 13 * the Free Software Foundation; either version 2 of the License, or *
14 * ( at your option ) any later version. * 14 * ( at your option ) any later version. *
15 * * 15 * *
16 **************************************************************************/ 16 **************************************************************************/
17 17
18#include <qpe/config.h> 18#include <qpe/config.h>
19#include <qlayout.h> 19#include <qlayout.h>
20#include <qpe/qpeapplication.h> 20#include <qpe/qpeapplication.h>
21#include <qlist.h>
22#include "dataTable.h" 21#include "dataTable.h"
23#include "psewidget.h" 22#include "psewidget.h"
24#include "oxyframe.h"
25 23
26 24
27PSEWidget::PSEWidget(const QStringList &list) : QWidget() 25PSEWidget::PSEWidget(const QStringList &list) : QWidget()
28{ 26{
29 this->setCaption( tr( "Periodic System" ) ); 27 this->setCaption( tr( "Periodic System" ) );
30 28
31 lastElement=1; 29 lastElement=1;
32 names = list; 30 names = list;
33 31
34 QVBoxLayout *vlay = new QVBoxLayout( this ); 32 QVBoxLayout *vlay = new QVBoxLayout( this );
35 33
36 QGridLayout *grid = new QGridLayout( 18,10 ); 34 QGridLayout *grid = new QGridLayout( 18,10 );
37 int h=0, v=0; 35 int h=0, v=0;
38 36
39 Config configobj( QPEApplication::qpeDir() +"share/oxygen/oxygendata", Config::File ); 37 Config configobj( QPEApplication::qpeDir() +"share/oxygen/oxygendata", Config::File );
40 for( int n = 0 ; n < 109 ; n++ ) 38 for( int n = 0 ; n < 109 ; n++ )
41 { 39 {
42 configobj.setGroup( QString::number( n+1 )); 40 configobj.setGroup( QString::number( n+1 ));
43 41
44 position( n+1,h,v ); 42 position( n+1,h,v );
45 PSEframe.append( new OxyFrame( this , QString::number(n), configobj.readEntry( "Symbol" ) ) ); 43 PSEframe.append( new OxyFrame( this , QString::number(n), configobj.readEntry( "Symbol" ) ) );
46 grid->addWidget( PSEframe.current() , v/40+1 , h/40 ); 44 grid->addWidget( PSEframe.current() , v/40+1 , h/40 );
47 PSEframe.current()->setMinimumHeight( 11 ); 45 PSEframe.current()->setMinimumHeight( 11 );
48 PSEframe.current()->setPalette( QPalette( PSEColor( configobj.readEntry( "Block" ) ) ) ); 46 PSEframe.current()->setPalette( QPalette( PSEColor( configobj.readEntry( "Block" ) ) ) );
49 connect( PSEframe.current(), SIGNAL( num(QString) ), this, SLOT( slotShowElement(QString) )); 47 connect( PSEframe.current(), SIGNAL( num(QString) ), this, SLOT( slotShowElement(QString) ));
50 connect( PSEframe.current(), SIGNAL( num(QString) ), this, SLOT( inverseColor(QString) )); 48 connect( PSEframe.current(), SIGNAL( num(QString) ), this, SLOT( inverseColor(QString) ));
51 } 49 }
52 50
53 oxyDW = new OxydataWidget(this, "PSEWidget_oxyDW", names); 51 oxyDW = new OxydataWidget(this, "PSEWidget_oxyDW", names);
54 oxyDW->setElement( 0 ); 52 oxyDW->setElement( 0 );
55 oxyDW->setLayout(); 53 oxyDW->setLayout();
56 54
57 vlay->addLayout( grid ); 55 vlay->addLayout( grid );
58 vlay->addWidget( oxyDW ); 56 vlay->addWidget( oxyDW );
59} 57}
60 58
61QColor PSEWidget::PSEColor( QString block ) const 59QColor PSEWidget::PSEColor( QString block ) const
62{ 60{
63 QColor c; 61 QColor c;
64 if ( block == "s" ) c.setRgb( 213 , 233 , 231 ); 62 if ( block == "s" ) c.setRgb( 213 , 233 , 231 );
65 else if ( block == "d" ) c.setRgb( 200,230,160 ); 63 else if ( block == "d" ) c.setRgb( 200,230,160 );
66 else if ( block == "p" ) c.setRgb( 238,146,138 ); 64 else if ( block == "p" ) c.setRgb( 238,146,138 );
67 else if ( block == "f" ) c.setRgb( 190 , 190 , 190 ); 65 else if ( block == "f" ) c.setRgb( 190 , 190 , 190 );
68 return c; 66 return c;
69}; 67};
70 68
71void PSEWidget::inverseColor( QString number) 69void PSEWidget::inverseColor( QString number)
72{ 70{
73 Config configobj( QPEApplication::qpeDir() +"share/oxygen/oxygendata", Config::File ); 71 Config configobj( QPEApplication::qpeDir() +"share/oxygen/oxygendata", Config::File );
74 configobj.setGroup( number ); 72 configobj.setGroup( number );
75 QString block = configobj.readEntry( "Block" ); 73 QString block = configobj.readEntry( "Block" );
76 QColor c, d; 74 QColor c, d;
77 c = PSEColor( block ); 75 c = PSEColor( block );
78 d = c.dark(); 76 d = c.dark();
79 77
80 PSEframe.at( number.toUInt() )->setPalette( QPalette( d ) ); 78 PSEframe.at( number.toUInt() )->setPalette( QPalette( d ) );
81 79
82 configobj.setGroup( QString::number( lastElement+1 ) ); 80 configobj.setGroup( QString::number( lastElement+1 ) );
83 block = configobj.readEntry( "Block" ); 81 block = configobj.readEntry( "Block" );
84 c = PSEColor( block ); 82 c = PSEColor( block );
85 PSEframe.at( lastElement )->setPalette( QPalette( c ) ); 83 PSEframe.at( lastElement )->setPalette( QPalette( c ) );
86 84
87 lastElement=number.toInt(); 85 lastElement=number.toInt();
88} 86}
89 87
90void PSEWidget::slotShowElement(QString number) 88void PSEWidget::slotShowElement(QString number)
91{ 89{
92 oxyDW->setElement( number.toInt() ); 90 oxyDW->setElement( number.toInt() );
93}; 91};
94 92
95void PSEWidget::position(int n, int& h, int& v) 93void PSEWidget::position(int n, int& h, int& v)
96{ 94{
97 //Hydrogen 95 //Hydrogen
98 if (n == 1) 96 if (n == 1)
99 { 97 {
100 h=0; v=0; 98 h=0; v=0;
101 } 99 }
102 100
103 101
104 //Helium 102 //Helium
105 if (n == 2) 103 if (n == 2)
106 { 104 {
107 h=680; v=0; 105 h=680; v=0;
108 } 106 }
109 107
110 108
111 //Lithium 109 //Lithium
112 if (n == 3) 110 if (n == 3)
113 { 111 {
114 h=0; v=40; 112 h=0; v=40;
115 } 113 }
116 114
117 115
118 //Beryllium 116 //Beryllium
119 if (n == 4) 117 if (n == 4)
120 { 118 {
121 h=40; v=40; 119 h=40; v=40;
122 } 120 }
123 121
124 122
125 //Boron-->Neon or Aluminum --> Argon 123 //Boron-->Neon or Aluminum --> Argon
126 if ((n >= 5 && n <= 10) || (n >= 13 && n <= 18)) 124 if ((n >= 5 && n <= 10) || (n >= 13 && n <= 18))
127 for (int i = 1; i <= (6-(10-n)); i++) 125 for (int i = 1; i <= (6-(10-n)); i++)
128 { 126 {
129 h=((i*40)+440); 127 h=((i*40)+440);
130 v = 40; 128 v = 40;
131 if (n >= 13) 129 if (n >= 13)
132 { 130 {
133 v=80; 131 v=80;
134 h=(h-320); 132 h=(h-320);
135 } 133 }
136 } 134 }
137 135
138 136
139 //Sodium 137 //Sodium
140 if (n == 11) 138 if (n == 11)
141 { 139 {
142 h=0; v=80; 140 h=0; v=80;
143 } 141 }
144 142
145 143
146 //Magnesium 144 //Magnesium
147 if (n == 12) 145 if (n == 12)
148 { 146 {
149 h=40; v=80; 147 h=40; v=80;
150 } 148 }
151 149
152 150
153 //Potassium --> Uuo without La and Ac 151 //Potassium --> Uuo without La and Ac
154 if ((n >= 19 && n <= 57) || (n >= 72 && n <= 89) || n >= 104) 152 if ((n >= 19 && n <= 57) || (n >= 72 && n <= 89) || n >= 104)
155 for (int i = 1; i <= 18; i++) 153 for (int i = 1; i <= 18; i++)
156 { 154 {
157 int f = n; 155 int f = n;
158 if (n > 18) 156 if (n > 18)
159 f = n-18; 157 f = n-18;
160 if (n > 36) 158 if (n > 36)
161 f = n-36; 159 f = n-36;
162 if (n > 54) 160 if (n > 54)
163 f = n-54; 161 f = n-54;
164 if (n > 71) 162 if (n > 71)
165 f = n-68; 163 f = n-68;
166 if (n > 86) 164 if (n > 86)
167 f = n-86; 165 f = n-86;
168 if (n > 103) 166 if (n > 103)
169 f = n-100; 167 f = n-100;
170 168
171 h=((f*40)-40); 169 h=((f*40)-40);
172 170
173 v = 120; 171 v = 120;
174 if (n >= 37) 172 if (n >= 37)
175 v=160; 173 v=160;
176 if (n >= 55) 174 if (n >= 55)
177 v=200; 175 v=200;
178 if (n >= 87) 176 if (n >= 87)
179 v=240; 177 v=240;
180 } 178 }
181 179
182 180
183 //Lanthanum --> Lutetium and Actinum --> Lawrencium 181 //Lanthanum --> Lutetium and Actinum --> Lawrencium
184 if ((n >= 58 && n <= 71) || (n >= 90 && n <= 103)) 182 if ((n >= 58 && n <= 71) || (n >= 90 && n <= 103))
185 for (int i = 1; i <= 14; i++) 183 for (int i = 1; i <= 14; i++)
186 { 184 {
187 int f = n; 185 int f = n;
188 if (n > 57) 186 if (n > 57)
189 f = n-55; 187 f = n-55;
190 if (n > 88) 188 if (n > 88)
191 f = n-87; 189 f = n-87;
192 h=(f*40); 190 h=(f*40);
193 v = 290; 191 v = 290;
194 if (n >= 90) 192 if (n >= 90)
195 v=330; 193 v=330;
196 } 194 }
197 v += 10; 195 v += 10;
198} 196}
diff --git a/noncore/apps/qashmoney/account.cpp b/noncore/apps/qashmoney/account.cpp
index 181be23..f21598e 100755
--- a/noncore/apps/qashmoney/account.cpp
+++ b/noncore/apps/qashmoney/account.cpp
@@ -1,376 +1,374 @@
1#include "account.h" 1#include "account.h"
2#include "transaction.h"
3#include "transfer.h"
4#include "preferences.h" 2#include "preferences.h"
5 3
6#include <qpixmap.h> 4#include <qpixmap.h>
7#include <stdlib.h> 5#include <stdlib.h>
8 6
9extern Preferences *preferences; 7extern Preferences *preferences;
10 8
11Account::Account () 9Account::Account ()
12 { 10 {
13 adb = sqlite_open ( "qmaccounts.db", 0, NULL ); 11 adb = sqlite_open ( "qmaccounts.db", 0, NULL );
14 } 12 }
15 13
16Account::~Account () 14Account::~Account ()
17 { 15 {
18 sqlite_close ( adb ); 16 sqlite_close ( adb );
19 } 17 }
20 18
21void Account::addAccount ( QString name, int parentid, float balance, int type, QString description, float creditlimit, 19void Account::addAccount ( QString name, int parentid, float balance, int type, QString description, float creditlimit,
22 int statementyear, int statementmonth, int statementday, float statementbalance, const char *currency ) 20 int statementyear, int statementmonth, int statementday, float statementbalance, const char *currency )
23 { 21 {
24 sqlite_exec_printf ( adb, "insert into accounts2 values ( '%q', %i, %.2f, %i, '%q', %.2f, %i, %i, %i, %.2f, '%q', 0, 0, 0, 0, 0, NULL );", 0, 0, 0, 22 sqlite_exec_printf ( adb, "insert into accounts2 values ( '%q', %i, %.2f, %i, '%q', %.2f, %i, %i, %i, %.2f, '%q', 0, 0, 0, 0, 0, NULL );", 0, 0, 0,
25 (const char *) name, parentid, balance, type, (const char *) description, creditlimit, statementyear, statementmonth, statementday, statementbalance, currency ); 23 (const char *) name, parentid, balance, type, (const char *) description, creditlimit, statementyear, statementmonth, statementday, statementbalance, currency );
26 } 24 }
27 25
28void Account::updateAccount ( QString name, QString description, QString currencycode, int accountid ) 26void Account::updateAccount ( QString name, QString description, QString currencycode, int accountid )
29 { 27 {
30 sqlite_exec_printf ( adb, "update accounts2 set name = '%q', description = '%q', currency = '%q' where accountid = %i;", 0, 0, 0, ( const char * ) name, ( const char * ) description, ( const char * ) currencycode, accountid ); 28 sqlite_exec_printf ( adb, "update accounts2 set name = '%q', description = '%q', currency = '%q' where accountid = %i;", 0, 0, 0, ( const char * ) name, ( const char * ) description, ( const char * ) currencycode, accountid );
31 } 29 }
32 30
33void Account::deleteAccount ( int accountid ) 31void Account::deleteAccount ( int accountid )
34 { 32 {
35 sqlite_exec_printf ( adb, "delete from accounts2 where accountid = %i;", 0, 0, 0, accountid ); 33 sqlite_exec_printf ( adb, "delete from accounts2 where accountid = %i;", 0, 0, 0, accountid );
36 } 34 }
37 35
38void Account::setAccountExpanded ( int expanded, int accountid ) 36void Account::setAccountExpanded ( int expanded, int accountid )
39 { 37 {
40 sqlite_exec_printf ( adb, "update accounts2 set r1 = %i where accountid = %i;", 0, 0, 0, expanded, accountid ); 38 sqlite_exec_printf ( adb, "update accounts2 set r1 = %i where accountid = %i;", 0, 0, 0, expanded, accountid );
41 } 39 }
42 40
43int Account::getAccountExpanded ( int id ) 41int Account::getAccountExpanded ( int id )
44 { 42 {
45 char **results; 43 char **results;
46 sqlite_get_table_printf ( adb, "select r1 from accounts2 where accountid = %i;", &results, 0, 0, 0, id ); 44 sqlite_get_table_printf ( adb, "select r1 from accounts2 where accountid = %i;", &results, 0, 0, 0, id );
47 if ( strlen ( results [1] ) == 0 ) 45 if ( strlen ( results [1] ) == 0 )
48 return 0; 46 return 0;
49 else 47 else
50 return atoi ( results [ 1 ] ); 48 return atoi ( results [ 1 ] );
51 } 49 }
52 50
53int Account::getNumberOfAccounts () 51int Account::getNumberOfAccounts ()
54 { 52 {
55 char **results; 53 char **results;
56 sqlite_get_table ( adb, "select count() from accounts2;", &results, NULL, NULL, NULL ); 54 sqlite_get_table ( adb, "select count() from accounts2;", &results, NULL, NULL, NULL );
57 return atoi ( results [ 1 ] ); 55 return atoi ( results [ 1 ] );
58 } 56 }
59 57
60int Account::getNumberOfChildAccounts ( int id ) 58int Account::getNumberOfChildAccounts ( int id )
61 { 59 {
62 char **results; 60 char **results;
63 sqlite_get_table_printf ( adb, "select count() from accounts2 where parent = %i;", &results, NULL, NULL, NULL, id ); 61 sqlite_get_table_printf ( adb, "select count() from accounts2 where parent = %i;", &results, NULL, NULL, NULL, id );
64 return atoi ( results [ 1 ] ); 62 return atoi ( results [ 1 ] );
65 } 63 }
66 64
67void Account::updateAccountBalance ( int accountid ) 65void Account::updateAccountBalance ( int accountid )
68 { 66 {
69 // Here, we'll get a balance for the transactions in an account 67 // Here, we'll get a balance for the transactions in an account
70 sqlite *tdb = sqlite_open ( "qmtransactions.db", 0, NULL ); 68 sqlite *tdb = sqlite_open ( "qmtransactions.db", 0, NULL );
71 int rows, columns; 69 int rows, columns;
72 char **results; 70 char **results;
73 sqlite_get_table_printf ( tdb, "select sum (amount) from transactions where accountid= %i;", &results, &rows, &columns, NULL, accountid ); 71 sqlite_get_table_printf ( tdb, "select sum (amount) from transactions where accountid= %i;", &results, &rows, &columns, NULL, accountid );
74 float transactionsbalance = strtod ( results [ 1 ], 0 ); 72 float transactionsbalance = strtod ( results [ 1 ], 0 );
75 sqlite_close ( tdb ); 73 sqlite_close ( tdb );
76 74
77 // next, we'll get a balance for all the transfers from the account 75 // next, we'll get a balance for all the transfers from the account
78 sqlite *trdb = sqlite_open ( "qmtransfers.db", 0, NULL ); 76 sqlite *trdb = sqlite_open ( "qmtransfers.db", 0, NULL );
79 rows = 0; 77 rows = 0;
80 columns = 0; 78 columns = 0;
81 char **results2; 79 char **results2;
82 sqlite_get_table_printf ( trdb, "select sum (amount) from transfers where fromaccount = %i;", &results2, &rows, &columns, NULL, accountid ); 80 sqlite_get_table_printf ( trdb, "select sum (amount) from transfers where fromaccount = %i;", &results2, &rows, &columns, NULL, accountid );
83 float fromtransfersbalance = ( strtod ( results2 [ 1 ], 0 ) * -1 ); 81 float fromtransfersbalance = ( strtod ( results2 [ 1 ], 0 ) * -1 );
84 82
85 // finally, we'll get a balance for all the transfers into the account 83 // finally, we'll get a balance for all the transfers into the account
86 rows = 0; 84 rows = 0;
87 columns= 0; 85 columns= 0;
88 char **results3; 86 char **results3;
89 sqlite_get_table_printf ( trdb, "select sum (amount) from transfers where toaccount = %i;", &results3, &rows, &columns, NULL, accountid ); 87 sqlite_get_table_printf ( trdb, "select sum (amount) from transfers where toaccount = %i;", &results3, &rows, &columns, NULL, accountid );
90 float totransfersbalance = strtod ( results3 [ 1 ], 0 ); 88 float totransfersbalance = strtod ( results3 [ 1 ], 0 );
91 89
92 sqlite_close ( trdb ); 90 sqlite_close ( trdb );
93 91
94 // calculate and update new balance 92 // calculate and update new balance
95 sqlite_exec_printf ( adb, "update accounts2 set balance = %.2f where accountid = %i;", 0, 0, 0, 93 sqlite_exec_printf ( adb, "update accounts2 set balance = %.2f where accountid = %i;", 0, 0, 0,
96 ( transactionsbalance + fromtransfersbalance + totransfersbalance + getStatementBalance ( accountid ) ), accountid ); 94 ( transactionsbalance + fromtransfersbalance + totransfersbalance + getStatementBalance ( accountid ) ), accountid );
97 } 95 }
98 96
99void Account::changeParentAccountBalance ( int parentid ) 97void Account::changeParentAccountBalance ( int parentid )
100 { 98 {
101 // select all child balances that share the parent of the current child account 99 // select all child balances that share the parent of the current child account
102 char **results; 100 char **results;
103 int rows; 101 int rows;
104 sqlite_get_table_printf ( adb, "select sum ( balance ) from accounts2 where parent = %i;", &results, &rows, NULL, NULL, parentid ); 102 sqlite_get_table_printf ( adb, "select sum ( balance ) from accounts2 where parent = %i;", &results, &rows, NULL, NULL, parentid );
105 sqlite_exec_printf ( adb, "update accounts2 set balance = %.2f where accountid = %i;", 0, 0, 0, strtod ( results[ 1 ], NULL ), parentid ); 103 sqlite_exec_printf ( adb, "update accounts2 set balance = %.2f where accountid = %i;", 0, 0, 0, strtod ( results[ 1 ], NULL ), parentid );
106 } 104 }
107 105
108int Account::getParentAccountID ( int id ) 106int Account::getParentAccountID ( int id )
109 { 107 {
110 char **results; 108 char **results;
111 sqlite_get_table_printf ( adb, "select parent from accounts2 where accountid = %i;", &results, NULL, NULL, NULL, id ); 109 sqlite_get_table_printf ( adb, "select parent from accounts2 where accountid = %i;", &results, NULL, NULL, NULL, id );
112 return atoi ( results [ 1 ] ); 110 return atoi ( results [ 1 ] );
113 } 111 }
114 112
115int Account::getParentAccountID ( QString accountname ) 113int Account::getParentAccountID ( QString accountname )
116 { 114 {
117 char **results; 115 char **results;
118 sqlite_get_table_printf ( adb, "select parent from accounts2 where name= '%q';", &results, NULL, NULL, NULL, ( const char * ) accountname ); 116 sqlite_get_table_printf ( adb, "select parent from accounts2 where name= '%q';", &results, NULL, NULL, NULL, ( const char * ) accountname );
119 return atoi ( results [ 1 ] ); 117 return atoi ( results [ 1 ] );
120 } 118 }
121 119
122void Account::displayAccounts ( QListView *listview ) 120void Account::displayAccounts ( QListView *listview )
123 { 121 {
124 char **results; 122 char **results;
125 int rows, columns; 123 int rows, columns;
126 sqlite_get_table ( adb, "select name, parent, balance, accountid, currency from accounts2;", &results, &rows, &columns, 0 ); 124 sqlite_get_table ( adb, "select name, parent, balance, accountid, currency from accounts2;", &results, &rows, &columns, 0 );
127 125
128 // determine if we are using currency support 126 // determine if we are using currency support
129 int currency = preferences->getPreference ( 4 ); 127 int currency = preferences->getPreference ( 4 );
130 128
131 // remove all columns from the account display 129 // remove all columns from the account display
132 int counter; 130 int counter;
133 for ( counter = 0; counter <= columns; counter++ ) 131 for ( counter = 0; counter <= columns; counter++ )
134 listview->removeColumn ( 0 ); 132 listview->removeColumn ( 0 );
135 133
136 // add columns to the account display 134 // add columns to the account display
137 listview->addColumn ( "Account", 0 ); 135 listview->addColumn ( "Account", 0 );
138 int columntoalign = 1; 136 int columntoalign = 1;
139 if ( preferences->getPreference ( 4 ) == 1 ) // add the currency column if the user wants it 137 if ( preferences->getPreference ( 4 ) == 1 ) // add the currency column if the user wants it
140 { 138 {
141 listview->addColumn ( "C", 0 ); 139 listview->addColumn ( "C", 0 );
142 columntoalign = 2; 140 columntoalign = 2;
143 } 141 }
144 listview->addColumn ( "Balance", 0 ); 142 listview->addColumn ( "Balance", 0 );
145 listview->addColumn ( "", 0 ); 143 listview->addColumn ( "", 0 );
146 listview->setColumnAlignment ( columntoalign, Qt::AlignRight ); 144 listview->setColumnAlignment ( columntoalign, Qt::AlignRight );
147 counter = 5; 145 counter = 5;
148 int total = ( rows + 1 ) * columns; 146 int total = ( rows + 1 ) * columns;
149 while ( counter < total ) 147 while ( counter < total )
150 { 148 {
151 int accountid = atoi ( results [ counter + 3 ] ); 149 int accountid = atoi ( results [ counter + 3 ] );
152 if ( atoi ( results [ counter + 1 ] ) == -1 ) 150 if ( atoi ( results [ counter + 1 ] ) == -1 )
153 { 151 {
154 QListViewItem *parent = new QListViewItem ( listview ); 152 QListViewItem *parent = new QListViewItem ( listview );
155 parent->setText ( 0, results [ counter ] ); 153 parent->setText ( 0, results [ counter ] );
156 if ( currency == 0 ) 154 if ( currency == 0 )
157 { 155 {
158 parent->setText ( 1, results [ counter + 2 ] ); 156 parent->setText ( 1, results [ counter + 2 ] );
159 parent->setText ( 2, results [ counter + 3 ] ); 157 parent->setText ( 2, results [ counter + 3 ] );
160 } 158 }
161 else 159 else
162 { 160 {
163 if ( getNumberOfChildAccounts ( accountid ) == 0 ) // add the currency flag if this is a parent with no children 161 if ( getNumberOfChildAccounts ( accountid ) == 0 ) // add the currency flag if this is a parent with no children
164 { 162 {
165 // create the string we'll use to set the currency pixmap 163 // create the string we'll use to set the currency pixmap
166 QString filename = "/opt/QtPalmtop/pics/flags/"; 164 QString filename = "/opt/QtPalmtop/pics/flags/";
167 QString flag = results [ counter + 4 ]; 165 QString flag = results [ counter + 4 ];
168 filename.append ( flag ); 166 filename.append ( flag );
169 filename.append ( ".png" ); 167 filename.append ( ".png" );
170 parent->setPixmap ( 1, QPixmap ( filename ) ); 168 parent->setPixmap ( 1, QPixmap ( filename ) );
171 parent->setText ( 1, flag ); 169 parent->setText ( 1, flag );
172 } 170 }
173 parent->setText ( 2, results [ counter + 2 ] ); 171 parent->setText ( 2, results [ counter + 2 ] );
174 parent->setText ( 3, results [ counter + 3 ] ); 172 parent->setText ( 3, results [ counter + 3 ] );
175 } 173 }
176 174
177 if ( getAccountExpanded ( accountid ) == 1 ) 175 if ( getAccountExpanded ( accountid ) == 1 )
178 parent->setOpen ( TRUE ); 176 parent->setOpen ( TRUE );
179 177
180 //Start display child accounts for this parent 178 //Start display child accounts for this parent
181 int childcounter = 5; 179 int childcounter = 5;
182 while ( childcounter < total ) 180 while ( childcounter < total )
183 { 181 {
184 if ( atoi ( results [ childcounter + 1 ] ) == accountid ) 182 if ( atoi ( results [ childcounter + 1 ] ) == accountid )
185 { 183 {
186 if ( currency == 0 ) 184 if ( currency == 0 )
187 QListViewItem *child = new QListViewItem ( parent, results [ childcounter ], results [ childcounter + 2 ], results [ childcounter + 3 ] ); 185 QListViewItem *child = new QListViewItem ( parent, results [ childcounter ], results [ childcounter + 2 ], results [ childcounter + 3 ] );
188 else 186 else
189 { 187 {
190 // create the string we'll use to set the currency pixmap 188 // create the string we'll use to set the currency pixmap
191 QString filename = "/opt/QtPalmtop/pics/flags/"; 189 QString filename = "/opt/QtPalmtop/pics/flags/";
192 QString flag = results [ childcounter + 4 ]; 190 QString flag = results [ childcounter + 4 ];
193 filename.append ( flag ); 191 filename.append ( flag );
194 filename.append ( ".png" ); 192 filename.append ( ".png" );
195 QListViewItem *child = new QListViewItem ( parent, results [ childcounter ], "", results [ childcounter + 2 ], results [ childcounter + 3 ] ); 193 QListViewItem *child = new QListViewItem ( parent, results [ childcounter ], "", results [ childcounter + 2 ], results [ childcounter + 3 ] );
196 child->setPixmap ( 1, QPixmap ( filename ) ); 194 child->setPixmap ( 1, QPixmap ( filename ) );
197 child->setText ( 1, flag ); 195 child->setText ( 1, flag );
198 } 196 }
199 } 197 }
200 childcounter = childcounter + 5; 198 childcounter = childcounter + 5;
201 } 199 }
202 //End display child accounts 200 //End display child accounts
203 } 201 }
204 counter = counter + 5; 202 counter = counter + 5;
205 } 203 }
206 204
207 // resize all columns appropriately 205 // resize all columns appropriately
208 if ( preferences->getPreference ( 4 ) == 0 ) 206 if ( preferences->getPreference ( 4 ) == 0 )
209 { 207 {
210 listview->setColumnWidth ( 0, preferences->getColumnPreference ( 1 ) ); 208 listview->setColumnWidth ( 0, preferences->getColumnPreference ( 1 ) );
211 listview->setColumnWidthMode ( 0, QListView::Manual ); 209 listview->setColumnWidthMode ( 0, QListView::Manual );
212 listview->setColumnWidth ( 1, preferences->getColumnPreference ( 2 ) ); 210 listview->setColumnWidth ( 1, preferences->getColumnPreference ( 2 ) );
213 listview->setColumnWidthMode ( 1, QListView::Manual ); 211 listview->setColumnWidthMode ( 1, QListView::Manual );
214 listview->setColumnWidthMode ( 2, QListView::Manual ); 212 listview->setColumnWidthMode ( 2, QListView::Manual );
215 } 213 }
216 else 214 else
217 { 215 {
218 listview->setColumnWidth ( 0, preferences->getColumnPreference ( 10 ) ); 216 listview->setColumnWidth ( 0, preferences->getColumnPreference ( 10 ) );
219 listview->setColumnWidthMode ( 0, QListView::Manual ); 217 listview->setColumnWidthMode ( 0, QListView::Manual );
220 listview->setColumnWidth ( 1, preferences->getColumnPreference ( 11 ) ); 218 listview->setColumnWidth ( 1, preferences->getColumnPreference ( 11 ) );
221 listview->setColumnWidthMode ( 1, QListView::Manual ); 219 listview->setColumnWidthMode ( 1, QListView::Manual );
222 listview->setColumnWidth ( 2, preferences->getColumnPreference ( 12 ) ); 220 listview->setColumnWidth ( 2, preferences->getColumnPreference ( 12 ) );
223 listview->setColumnWidthMode ( 2, QListView::Manual ); 221 listview->setColumnWidthMode ( 2, QListView::Manual );
224 listview->setColumnWidthMode ( 3, QListView::Manual ); 222 listview->setColumnWidthMode ( 3, QListView::Manual );
225 } 223 }
226 224
227 // Now reset the column sorting to user preference 225 // Now reset the column sorting to user preference
228 int column = 0; 226 int column = 0;
229 int direction = 0; 227 int direction = 0;
230 preferences->getSortingPreference ( 1, &column, &direction ); 228 preferences->getSortingPreference ( 1, &column, &direction );
231 listview->setSorting ( column, direction ); 229 listview->setSorting ( column, direction );
232 } 230 }
233 231
234int Account::displayParentAccountNames ( QComboBox *combobox, QString indexstring ) 232int Account::displayParentAccountNames ( QComboBox *combobox, QString indexstring )
235 { 233 {
236 char **results; 234 char **results;
237 int rows, columns, index; 235 int rows, columns, index;
238 index = 0; 236 index = 0;
239 sqlite_get_table ( adb, "select name from accounts2 order by name asc;", &results, &rows, &columns, NULL ); 237 sqlite_get_table ( adb, "select name from accounts2 order by name asc;", &results, &rows, &columns, NULL );
240 int counter = 1; 238 int counter = 1;
241 int indexcounter = 1; 239 int indexcounter = 1;
242 int total = ( rows + 1 ) * columns; 240 int total = ( rows + 1 ) * columns;
243 while ( counter < total ) 241 while ( counter < total )
244 { 242 {
245 if ( getParentAccountID ( results [ counter ] ) == -1 ) 243 if ( getParentAccountID ( results [ counter ] ) == -1 )
246 { 244 {
247 combobox->insertItem ( results [ counter ], -1 ); 245 combobox->insertItem ( results [ counter ], -1 );
248 if ( strcmp ( results [ counter ], indexstring ) == 0 ) 246 if ( strcmp ( results [ counter ], indexstring ) == 0 )
249 index = indexcounter; 247 index = indexcounter;
250 indexcounter++; 248 indexcounter++;
251 } 249 }
252 counter ++; 250 counter ++;
253 } 251 }
254 return index; 252 return index;
255 } 253 }
256 254
257int Account::getAccountType ( int accountid ) 255int Account::getAccountType ( int accountid )
258 { 256 {
259 char **results; 257 char **results;
260 sqlite_get_table_printf ( adb, "select type from accounts2 where accountid= %i;", &results, NULL, NULL, NULL, accountid ); 258 sqlite_get_table_printf ( adb, "select type from accounts2 where accountid= %i;", &results, NULL, NULL, NULL, accountid );
261 return atoi ( results [ 1 ] ); 259 return atoi ( results [ 1 ] );
262 } 260 }
263 261
264int Account::getStatementDay ( int accountid ) 262int Account::getStatementDay ( int accountid )
265 { 263 {
266 char **results; 264 char **results;
267 sqlite_get_table_printf ( adb, "select statementday from accounts2 where accountid= %i;", &results, NULL, NULL, NULL, accountid ); 265 sqlite_get_table_printf ( adb, "select statementday from accounts2 where accountid= %i;", &results, NULL, NULL, NULL, accountid );
268 return atoi ( results [ 1 ] ); 266 return atoi ( results [ 1 ] );
269 } 267 }
270 268
271int Account::getStatementMonth ( int accountid ) 269int Account::getStatementMonth ( int accountid )
272 { 270 {
273 char **results; 271 char **results;
274 sqlite_get_table_printf ( adb, "select statementmonth from accounts2 where accountid= %i;", &results, NULL, NULL, NULL, accountid ); 272 sqlite_get_table_printf ( adb, "select statementmonth from accounts2 where accountid= %i;", &results, NULL, NULL, NULL, accountid );
275 return atoi ( results [ 1 ] ); 273 return atoi ( results [ 1 ] );
276 } 274 }
277 275
278int Account::getStatementYear ( int accountid ) 276int Account::getStatementYear ( int accountid )
279 { 277 {
280 char **results; 278 char **results;
281 sqlite_get_table_printf ( adb, "select statementyear from accounts2 where accountid= %i;", &results, NULL, NULL, NULL, accountid ); 279 sqlite_get_table_printf ( adb, "select statementyear from accounts2 where accountid= %i;", &results, NULL, NULL, NULL, accountid );
282 return atoi ( results [ 1 ] ); 280 return atoi ( results [ 1 ] );
283 } 281 }
284 282
285QString Account::getAccountDescription ( int accountid ) 283QString Account::getAccountDescription ( int accountid )
286 { 284 {
287 char **results; 285 char **results;
288 sqlite_get_table_printf ( adb, "select description from accounts2 where accountid= %i;", &results, NULL, NULL, NULL, accountid ); 286 sqlite_get_table_printf ( adb, "select description from accounts2 where accountid= %i;", &results, NULL, NULL, NULL, accountid );
289 return ( QString ) results [ 1 ]; 287 return ( QString ) results [ 1 ];
290 } 288 }
291 289
292QString Account::getCurrencyCode ( int accountid ) 290QString Account::getCurrencyCode ( int accountid )
293 { 291 {
294 char **results; 292 char **results;
295 sqlite_get_table_printf ( adb, "select currency from accounts2 where accountid= %i;", &results, NULL, NULL, NULL, accountid ); 293 sqlite_get_table_printf ( adb, "select currency from accounts2 where accountid= %i;", &results, NULL, NULL, NULL, accountid );
296 return ( QString ) results [ 1 ]; 294 return ( QString ) results [ 1 ];
297 } 295 }
298 296
299QString Account::getAccountName ( int accountid ) 297QString Account::getAccountName ( int accountid )
300 { 298 {
301 char **results; 299 char **results;
302 sqlite_get_table_printf ( adb, "select name from accounts2 where accountid= %i;", &results, NULL, NULL, NULL, accountid ); 300 sqlite_get_table_printf ( adb, "select name from accounts2 where accountid= %i;", &results, NULL, NULL, NULL, accountid );
303 return ( QString ) results [ 1 ]; 301 return ( QString ) results [ 1 ];
304 } 302 }
305 303
306QString Account::getAccountBalance ( int accountid ) 304QString Account::getAccountBalance ( int accountid )
307 { 305 {
308 char **results; 306 char **results;
309 sqlite_get_table_printf ( adb, "select balance from accounts2 where accountid= %i;", &results, NULL, NULL, NULL, accountid ); 307 sqlite_get_table_printf ( adb, "select balance from accounts2 where accountid= %i;", &results, NULL, NULL, NULL, accountid );
310 return ( QString ) results [ 1 ]; 308 return ( QString ) results [ 1 ];
311 } 309 }
312 310
313float Account::getAccountCreditLimit ( int accountid ) 311float Account::getAccountCreditLimit ( int accountid )
314 { 312 {
315 char **results; 313 char **results;
316 sqlite_get_table_printf ( adb, "select creditlimit from accounts2 where accountid = %i;", &results, NULL, NULL, NULL, accountid ); 314 sqlite_get_table_printf ( adb, "select creditlimit from accounts2 where accountid = %i;", &results, NULL, NULL, NULL, accountid );
317 return strtod ( results [ 1 ], NULL ); 315 return strtod ( results [ 1 ], NULL );
318 } 316 }
319 317
320float Account::getStatementBalance ( int accountid ) 318float Account::getStatementBalance ( int accountid )
321 { 319 {
322 char **results; 320 char **results;
323 sqlite_get_table_printf ( adb, "select statementbalance from accounts2 where accountid = %i;", &results, NULL, NULL, NULL, accountid ); 321 sqlite_get_table_printf ( adb, "select statementbalance from accounts2 where accountid = %i;", &results, NULL, NULL, NULL, accountid );
324 return strtod ( results [ 1 ], NULL ); 322 return strtod ( results [ 1 ], NULL );
325 } 323 }
326 324
327GreyBackgroundItem::GreyBackgroundItem ( QListView *parent ) 325GreyBackgroundItem::GreyBackgroundItem ( QListView *parent )
328 : QListViewItem ( parent ) 326 : QListViewItem ( parent )
329 { 327 {
330 } 328 }
331 329
332GreyBackgroundItem::GreyBackgroundItem ( QListView *parent, QString label1, QString label2, QString label3 ) 330GreyBackgroundItem::GreyBackgroundItem ( QListView *parent, QString label1, QString label2, QString label3 )
333 : QListViewItem ( parent, label1, label2, label3 ) 331 : QListViewItem ( parent, label1, label2, label3 )
334 { 332 {
335 } 333 }
336 334
337GreyBackgroundItem::GreyBackgroundItem ( QListView *parent, QString label1, QString label2, QString label3, QString label4 ) 335GreyBackgroundItem::GreyBackgroundItem ( QListView *parent, QString label1, QString label2, QString label3, QString label4 )
338 : QListViewItem ( parent, label1, label2, label3, label4 ) 336 : QListViewItem ( parent, label1, label2, label3, label4 )
339 { 337 {
340 } 338 }
341 339
342GreyBackgroundItem::GreyBackgroundItem ( QListView *parent, QString label1, QString label2, QString label3, QString label4, QString label5 ) 340GreyBackgroundItem::GreyBackgroundItem ( QListView *parent, QString label1, QString label2, QString label3, QString label4, QString label5 )
343 : QListViewItem ( parent, label1, label2, label3, label4, label5 ) 341 : QListViewItem ( parent, label1, label2, label3, label4, label5 )
344 { 342 {
345 } 343 }
346 344
347void GreyBackgroundItem::paintCell ( QPainter *p, const QColorGroup &cg, int column, int width, int alignment ) 345void GreyBackgroundItem::paintCell ( QPainter *p, const QColorGroup &cg, int column, int width, int alignment )
348 { 346 {
349 QColorGroup _cg ( cg ); 347 QColorGroup _cg ( cg );
350 _cg.setColor ( QColorGroup::Base, Qt::lightGray ); 348 _cg.setColor ( QColorGroup::Base, Qt::lightGray );
351 QListViewItem::paintCell ( p, _cg, column, width, alignment ); 349 QListViewItem::paintCell ( p, _cg, column, width, alignment );
352 } 350 }
353 351
354QStringList Account::getAccountNames () 352QStringList Account::getAccountNames ()
355 { 353 {
356 QStringList accountnames; 354 QStringList accountnames;
357 char **results; 355 char **results;
358 int rows, counter; 356 int rows, counter;
359 sqlite_get_table ( adb, "select name from accounts2;", &results, &rows, 0, 0 ); 357 sqlite_get_table ( adb, "select name from accounts2;", &results, &rows, 0, 0 );
360 for ( counter = 0; counter < rows; counter++ ) 358 for ( counter = 0; counter < rows; counter++ )
361 accountnames.append ( results [ counter+1 ] ); 359 accountnames.append ( results [ counter+1 ] );
362 return accountnames; 360 return accountnames;
363 } 361 }
364 362
365QStringList Account::getAccountIDs () 363QStringList Account::getAccountIDs ()
366 { 364 {
367 QStringList accountids; 365 QStringList accountids;
368 char **results; 366 char **results;
369 int rows, counter; 367 int rows, counter;
370 sqlite_get_table ( adb, "select accountid from accounts2;", &results, &rows, 0, 0 ); 368 sqlite_get_table ( adb, "select accountid from accounts2;", &results, &rows, 0, 0 );
371 for ( counter = 0; counter < rows; counter++ ) 369 for ( counter = 0; counter < rows; counter++ )
372 accountids.append ( results [ counter+1 ] ); 370 accountids.append ( results [ counter+1 ] );
373 return accountids; 371 return accountids;
374 } 372 }
375 373
376 374
diff --git a/noncore/apps/qashmoney/accountdisplay.cpp b/noncore/apps/qashmoney/accountdisplay.cpp
index d0ba82a..5ef5454 100755
--- a/noncore/apps/qashmoney/accountdisplay.cpp
+++ b/noncore/apps/qashmoney/accountdisplay.cpp
@@ -1,448 +1,446 @@
1#include <qdatetime.h>
2#include <qmessagebox.h> 1#include <qmessagebox.h>
3#include <qheader.h> 2#include <qheader.h>
4 3
5#include "accountdisplay.h" 4#include "accountdisplay.h"
6#include "newaccount.h" 5#include "newaccount.h"
7#include "transaction.h" 6#include "transaction.h"
8#include "transferdialog.h" 7#include "transferdialog.h"
9#include "preferences.h"
10#include "transfer.h" 8#include "transfer.h"
11 9
12extern Account *account; 10extern Account *account;
13extern Transaction *transaction; 11extern Transaction *transaction;
14extern Transfer *transfer; 12extern Transfer *transfer;
15extern Preferences *preferences; 13extern Preferences *preferences;
16 14
17AccountDisplay::AccountDisplay ( QWidget *parent ) : QWidget ( parent ) 15AccountDisplay::AccountDisplay ( QWidget *parent ) : QWidget ( parent )
18 { 16 {
19 cleared = 0; 17 cleared = 0;
20 18
21 firstline = new QHBox ( this ); 19 firstline = new QHBox ( this );
22 firstline->setSpacing ( 2 ); 20 firstline->setSpacing ( 2 );
23 21
24 newaccount = new QPushButton ( firstline ); 22 newaccount = new QPushButton ( firstline );
25 newaccount->setPixmap ( QPixmap ("/opt/QtPalmtop/pics/new.png") ); 23 newaccount->setPixmap ( QPixmap ("/opt/QtPalmtop/pics/new.png") );
26 connect ( newaccount, SIGNAL ( released () ), this, SLOT ( addAccount () ) ); 24 connect ( newaccount, SIGNAL ( released () ), this, SLOT ( addAccount () ) );
27 25
28 editaccount = new QPushButton ( firstline ); 26 editaccount = new QPushButton ( firstline );
29 editaccount->setPixmap ( QPixmap ("/opt/QtPalmtop/pics/edit.png") ); 27 editaccount->setPixmap ( QPixmap ("/opt/QtPalmtop/pics/edit.png") );
30 connect ( editaccount, SIGNAL ( released () ), this, SLOT ( editAccount () ) ); 28 connect ( editaccount, SIGNAL ( released () ), this, SLOT ( editAccount () ) );
31 29
32 deleteaccount = new QPushButton ( firstline ); 30 deleteaccount = new QPushButton ( firstline );
33 deleteaccount->setPixmap( QPixmap ( "/opt/QtPalmtop/pics/delete.png") ); 31 deleteaccount->setPixmap( QPixmap ( "/opt/QtPalmtop/pics/delete.png") );
34 connect ( deleteaccount, SIGNAL ( released () ), this, SLOT ( deleteAccount () ) ); 32 connect ( deleteaccount, SIGNAL ( released () ), this, SLOT ( deleteAccount () ) );
35 33
36 transferbutton = new QPushButton ( firstline ); 34 transferbutton = new QPushButton ( firstline );
37 transferbutton->setPixmap( QPixmap ( "/opt/QtPalmtop/pics/transfer.png") ); 35 transferbutton->setPixmap( QPixmap ( "/opt/QtPalmtop/pics/transfer.png") );
38 transferbutton->setToggleButton ( TRUE ); 36 transferbutton->setToggleButton ( TRUE );
39 connect ( transferbutton, SIGNAL ( toggled ( bool ) ), this, SLOT ( accountTransfer ( bool ) ) ); 37 connect ( transferbutton, SIGNAL ( toggled ( bool ) ), this, SLOT ( accountTransfer ( bool ) ) );
40 38
41 listview = new QListView ( this ); 39 listview = new QListView ( this );
42 listview->setAllColumnsShowFocus ( TRUE ); 40 listview->setAllColumnsShowFocus ( TRUE );
43 listview->setShowSortIndicator ( TRUE ); 41 listview->setShowSortIndicator ( TRUE );
44 listview->setRootIsDecorated ( TRUE ); 42 listview->setRootIsDecorated ( TRUE );
45 listview->setMultiSelection ( FALSE ); 43 listview->setMultiSelection ( FALSE );
46 connect ( listview, SIGNAL ( expanded ( QListViewItem * ) ), this, SLOT ( setAccountExpanded ( QListViewItem * ) ) ); 44 connect ( listview, SIGNAL ( expanded ( QListViewItem * ) ), this, SLOT ( setAccountExpanded ( QListViewItem * ) ) );
47 connect ( listview, SIGNAL ( collapsed ( QListViewItem * ) ), this, SLOT ( setAccountCollapsed ( QListViewItem * ) ) ); 45 connect ( listview, SIGNAL ( collapsed ( QListViewItem * ) ), this, SLOT ( setAccountCollapsed ( QListViewItem * ) ) );
48 46
49 listview->header()->setTracking ( FALSE ); 47 listview->header()->setTracking ( FALSE );
50 connect ( listview->header(), SIGNAL ( sizeChange ( int, int, int ) ), this, SLOT ( saveColumnSize ( int, int, int ) ) ); 48 connect ( listview->header(), SIGNAL ( sizeChange ( int, int, int ) ), this, SLOT ( saveColumnSize ( int, int, int ) ) );
51 connect ( listview->header(), SIGNAL ( clicked ( int ) ), this, SLOT ( saveSortingPreference ( int ) ) ); 49 connect ( listview->header(), SIGNAL ( clicked ( int ) ), this, SLOT ( saveSortingPreference ( int ) ) );
52 50
53 layout = new QVBoxLayout ( this, 2, 5 ); 51 layout = new QVBoxLayout ( this, 2, 5 );
54 layout->addWidget ( firstline ); 52 layout->addWidget ( firstline );
55 layout->addWidget ( listview ); 53 layout->addWidget ( listview );
56 } 54 }
57 55
58void AccountDisplay::setTabs ( QWidget *newtab2, QTabWidget *newtabs ) 56void AccountDisplay::setTabs ( QWidget *newtab2, QTabWidget *newtabs )
59 { 57 {
60 tab2 = newtab2; 58 tab2 = newtab2;
61 maintabs = newtabs; 59 maintabs = newtabs;
62 } 60 }
63 61
64void AccountDisplay::addAccount () 62void AccountDisplay::addAccount ()
65 { 63 {
66 // initialize local variables 64 // initialize local variables
67 int parentid = 0; 65 int parentid = 0;
68 type = 0; 66 type = 0;
69 QString parentlist [ listview->childCount() + 1 ] [ 3 ] ; 67 QString parentlist [ listview->childCount() + 1 ] [ 3 ] ;
70 68
71 // create new account window for entering data 69 // create new account window for entering data
72 NewAccount *newaccount = new NewAccount ( this ); 70 NewAccount *newaccount = new NewAccount ( this );
73 int width = this->width(); 71 int width = this->width();
74 newaccount->accountbox->setMaximumWidth ( ( int ) ( width * 0.5 ) ); 72 newaccount->accountbox->setMaximumWidth ( ( int ) ( width * 0.5 ) );
75 newaccount->datebox->setMaximumWidth ( ( int ) ( width * 0.4 ) ); 73 newaccount->datebox->setMaximumWidth ( ( int ) ( width * 0.4 ) );
76 newaccount->childbox->setMaximumWidth ( ( int ) ( width * 0.5 ) ); 74 newaccount->childbox->setMaximumWidth ( ( int ) ( width * 0.5 ) );
77 newaccount->balancebox->setMaximumWidth ( ( int ) ( width * 0.4 ) ); 75 newaccount->balancebox->setMaximumWidth ( ( int ) ( width * 0.4 ) );
78 newaccount->creditlimitbox->setMaximumWidth ( ( int ) ( width * 0.4 ) ); 76 newaccount->creditlimitbox->setMaximumWidth ( ( int ) ( width * 0.4 ) );
79 77
80 // if there are no accounts, disable the child check box 78 // if there are no accounts, disable the child check box
81 if ( account->getNumberOfAccounts () == 0 ) 79 if ( account->getNumberOfAccounts () == 0 )
82 newaccount->childcheckbox->setEnabled ( FALSE ); 80 newaccount->childcheckbox->setEnabled ( FALSE );
83 81
84 // if there are accounts, fill up the pulldown menu for 82 // if there are accounts, fill up the pulldown menu for
85 // selecting a parent account. We should only add those parents without transactions 83 // selecting a parent account. We should only add those parents without transactions
86 else 84 else
87 { 85 {
88 int c = 0; 86 int c = 0;
89 QListViewItemIterator it ( listview ); 87 QListViewItemIterator it ( listview );
90 for ( ; it.current(); ++it ) 88 for ( ; it.current(); ++it )
91 { 89 {
92 int id = it.current()->text ( getIDColumn() ).toInt(); 90 int id = it.current()->text ( getIDColumn() ).toInt();
93 // iterate through accountdisplay listview and add parents with no transactions 91 // iterate through accountdisplay listview and add parents with no transactions
94 // add this item to the list box only if it is a parent and has no transactions 92 // add this item to the list box only if it is a parent and has no transactions
95 if ( transfer->getNumberOfTransfers ( id ) == 0 && transaction->getNumberOfTransactions ( id ) == 0 && it.current()->parent() == 0 ) 93 if ( transfer->getNumberOfTransfers ( id ) == 0 && transaction->getNumberOfTransactions ( id ) == 0 && it.current()->parent() == 0 )
96 { 94 {
97 newaccount->childbox->insertItem ( it.current()->text ( 0 ) ); 95 newaccount->childbox->insertItem ( it.current()->text ( 0 ) );
98 parentlist [ c ] [ 0 ] = it.current()->text ( 0 ); 96 parentlist [ c ] [ 0 ] = it.current()->text ( 0 );
99 parentlist [ c ] [ 1 ] = it.current()->text ( getIDColumn() ); 97 parentlist [ c ] [ 1 ] = it.current()->text ( getIDColumn() );
100 parentlist [ c ] [ 2 ] = QString::number ( c ); 98 parentlist [ c ] [ 2 ] = QString::number ( c );
101 c++; 99 c++;
102 } 100 }
103 } 101 }
104 } 102 }
105 103
106 if ( preferences->getPreference ( 4 ) == 0 ) 104 if ( preferences->getPreference ( 4 ) == 0 )
107 newaccount->currencybox->setEnabled ( FALSE ); 105 newaccount->currencybox->setEnabled ( FALSE );
108 106
109 // enter today's date in the date box as default 107 // enter today's date in the date box as default
110 QDate today = QDate::currentDate (); 108 QDate today = QDate::currentDate ();
111 int defaultday = today.day(); 109 int defaultday = today.day();
112 int defaultmonth = today.month(); 110 int defaultmonth = today.month();
113 int defaultyear = today.year(); 111 int defaultyear = today.year();
114 newaccount->startdate->setText ( preferences->getDate ( defaultyear, defaultmonth, defaultday ) ); 112 newaccount->startdate->setText ( preferences->getDate ( defaultyear, defaultmonth, defaultday ) );
115 113
116 //add account information if user pushes OK button 114 //add account information if user pushes OK button
117 if ( newaccount->exec() == QDialog::Accepted ) 115 if ( newaccount->exec() == QDialog::Accepted )
118 { 116 {
119 if ( newaccount->childcheckbox->isChecked () == TRUE ) // set a parent id and type for a child account 117 if ( newaccount->childcheckbox->isChecked () == TRUE ) // set a parent id and type for a child account
120 { 118 {
121 // go through the parentlist we created and determine the parent accountid 119 // go through the parentlist we created and determine the parent accountid
122 // we can't use the name of the account because there may be two accounts 120 // we can't use the name of the account because there may be two accounts
123 // with the same name. This function does it all by accountid 121 // with the same name. This function does it all by accountid
124 int counter; 122 int counter;
125 for ( counter = 0; counter < listview->childCount() + 1; counter++ ) 123 for ( counter = 0; counter < listview->childCount() + 1; counter++ )
126 if ( ( parentlist [ counter ] [ 2 ].toInt() ) == newaccount->childbox->currentItem() ) 124 if ( ( parentlist [ counter ] [ 2 ].toInt() ) == newaccount->childbox->currentItem() )
127 { 125 {
128 parentid = parentlist [ counter ] [ 1 ].toInt(); 126 parentid = parentlist [ counter ] [ 1 ].toInt();
129 break; 127 break;
130 } 128 }
131 type = ( newaccount->accounttype->currentItem() ) + 6; // sets account ids for child accounts. See accountdisplay.h for types 129 type = ( newaccount->accounttype->currentItem() ) + 6; // sets account ids for child accounts. See accountdisplay.h for types
132 } 130 }
133 else 131 else
134 { 132 {
135 parentid = -1; 133 parentid = -1;
136 type = newaccount->accounttype->currentItem(); // sets account ids for parent accounts 134 type = newaccount->accounttype->currentItem(); // sets account ids for parent accounts
137 } 135 }
138 136
139 // add the new account 137 // add the new account
140 if ( newaccount->getDateEdited () == TRUE ) 138 if ( newaccount->getDateEdited () == TRUE )
141 account->addAccount ( newaccount->accountname->text(), parentid, newaccount->accountbalance->text().toFloat(), type, 139 account->addAccount ( newaccount->accountname->text(), parentid, newaccount->accountbalance->text().toFloat(), type,
142 newaccount->getDescription(), newaccount->creditlimit->text().toFloat(), newaccount->getYear(), 140 newaccount->getDescription(), newaccount->creditlimit->text().toFloat(), newaccount->getYear(),
143 newaccount->getMonth(), newaccount->getDay(), newaccount->accountbalance->text().toFloat(), newaccount->currencybox->currencybox->currentText() ); 141 newaccount->getMonth(), newaccount->getDay(), newaccount->accountbalance->text().toFloat(), newaccount->currencybox->currencybox->currentText() );
144 else 142 else
145 account->addAccount ( newaccount->accountname->text (), parentid, newaccount->accountbalance->text().toFloat(), type, 143 account->addAccount ( newaccount->accountname->text (), parentid, newaccount->accountbalance->text().toFloat(), type,
146 newaccount->getDescription(), newaccount->creditlimit->text().toFloat(), defaultyear, 144 newaccount->getDescription(), newaccount->creditlimit->text().toFloat(), defaultyear,
147 defaultmonth, defaultday, newaccount->accountbalance->text().toFloat(), newaccount->currencybox->currencybox->currentText() ); 145 defaultmonth, defaultday, newaccount->accountbalance->text().toFloat(), newaccount->currencybox->currencybox->currentText() );
148 146
149 if ( parentid != -1 ) 147 if ( parentid != -1 )
150 account->changeParentAccountBalance ( parentid ); 148 account->changeParentAccountBalance ( parentid );
151 149
152 // redisplay accounts 150 // redisplay accounts
153 // this function clears the account display first 151 // this function clears the account display first
154 account->displayAccounts ( listview ); 152 account->displayAccounts ( listview );
155 setToggleButton(); 153 setToggleButton();
156 } 154 }
157 maintabs->setTabEnabled ( tab2, FALSE ); 155 maintabs->setTabEnabled ( tab2, FALSE );
158 } 156 }
159 157
160void AccountDisplay::deleteAccount () 158void AccountDisplay::deleteAccount ()
161 { 159 {
162 if ( listview->selectedItem() == 0 ) 160 if ( listview->selectedItem() == 0 )
163 QMessageBox::warning ( this, "QashMoney", "Please select an account\nto delete."); 161 QMessageBox::warning ( this, "QashMoney", "Please select an account\nto delete.");
164 else if ( listview->selectedItem()->parent() == 0 && listview->selectedItem()->childCount() != 0 ) 162 else if ( listview->selectedItem()->parent() == 0 && listview->selectedItem()->childCount() != 0 )
165 QMessageBox::warning ( this, "QashMoney", "Can't delete parent accounts\nwith children"); 163 QMessageBox::warning ( this, "QashMoney", "Can't delete parent accounts\nwith children");
166 else 164 else
167 { 165 {
168 QMessageBox mb ( "Delete Account", "This will delete all transactions\nand transfers for this account.", QMessageBox::Information, QMessageBox::Ok, QMessageBox::Cancel, QMessageBox::NoButton ); 166 QMessageBox mb ( "Delete Account", "This will delete all transactions\nand transfers for this account.", QMessageBox::Information, QMessageBox::Ok, QMessageBox::Cancel, QMessageBox::NoButton );
169 if ( mb.exec() == QMessageBox::Ok ) 167 if ( mb.exec() == QMessageBox::Ok )
170 { 168 {
171 int accountid = listview->selectedItem()->text ( getIDColumn() ).toInt (); 169 int accountid = listview->selectedItem()->text ( getIDColumn() ).toInt ();
172 int parentid = account->getParentAccountID ( accountid ); 170 int parentid = account->getParentAccountID ( accountid );
173 171
174 // delete all the transactions and transfers for the account 172 // delete all the transactions and transfers for the account
175 transaction->deleteAllTransactions ( accountid ); 173 transaction->deleteAllTransactions ( accountid );
176 transfer->deleteAllTransfers ( accountid ); 174 transfer->deleteAllTransfers ( accountid );
177 175
178 // delete the account 176 // delete the account
179 account->deleteAccount ( accountid ); 177 account->deleteAccount ( accountid );
180 178
181 // update account balances 179 // update account balances
182 if ( parentid != -1 ) 180 if ( parentid != -1 )
183 account->changeParentAccountBalance ( parentid ); 181 account->changeParentAccountBalance ( parentid );
184 182
185 //redisplay accounts 183 //redisplay accounts
186 account->displayAccounts ( listview ); 184 account->displayAccounts ( listview );
187 185
188 //remove all the columns from the accountdisplay if there are not any accounts 186 //remove all the columns from the accountdisplay if there are not any accounts
189 if ( account->getNumberOfAccounts() == 0 ) 187 if ( account->getNumberOfAccounts() == 0 )
190 { 188 {
191 int columns = listview->columns(); 189 int columns = listview->columns();
192 int counter; 190 int counter;
193 for ( counter = 0; counter <= columns; counter++ ) 191 for ( counter = 0; counter <= columns; counter++ )
194 listview->removeColumn ( 0 ); 192 listview->removeColumn ( 0 );
195 } 193 }
196 194
197 setToggleButton(); 195 setToggleButton();
198 } 196 }
199 } 197 }
200 maintabs->setTabEnabled ( tab2, FALSE ); 198 maintabs->setTabEnabled ( tab2, FALSE );
201 } 199 }
202 200
203void AccountDisplay::setToggleButton () 201void AccountDisplay::setToggleButton ()
204 { 202 {
205 // iterate through account display and determine how many "transferable" accounts we have 203 // iterate through account display and determine how many "transferable" accounts we have
206 // if there are less than two, disable the transfer button 204 // if there are less than two, disable the transfer button
207 QListViewItemIterator it ( listview ); 205 QListViewItemIterator it ( listview );
208 int counter = 0; 206 int counter = 0;
209 for ( ; it.current(); ++it ) 207 for ( ; it.current(); ++it )
210 { 208 {
211 // add one to counter if we find a transferable account 209 // add one to counter if we find a transferable account
212 if ( it.current()->parent() != 0 || ( it.current()->childCount() ) == 0 ) 210 if ( it.current()->parent() != 0 || ( it.current()->childCount() ) == 0 )
213 counter++; 211 counter++;
214 } 212 }
215 if ( counter > 1 ) 213 if ( counter > 1 )
216 transferbutton->show(); 214 transferbutton->show();
217 else 215 else
218 transferbutton->hide(); 216 transferbutton->hide();
219 } 217 }
220 218
221void AccountDisplay::accountTransfer ( bool state ) 219void AccountDisplay::accountTransfer ( bool state )
222 { 220 {
223 if ( state == TRUE ) 221 if ( state == TRUE )
224 { 222 {
225 firstaccountid = -1; 223 firstaccountid = -1;
226 secondaccountid = -1; 224 secondaccountid = -1;
227 listview->clearSelection (); 225 listview->clearSelection ();
228 listview->setMultiSelection ( TRUE ); 226 listview->setMultiSelection ( TRUE );
229 disableParentsWithChildren (); 227 disableParentsWithChildren ();
230 connect ( listview, SIGNAL ( clicked ( QListViewItem * ) ), this, SLOT ( getTransferAccounts ( QListViewItem * ) ) ); 228 connect ( listview, SIGNAL ( clicked ( QListViewItem * ) ), this, SLOT ( getTransferAccounts ( QListViewItem * ) ) );
231 } 229 }
232 else 230 else
233 { 231 {
234 firstaccountid = -1; 232 firstaccountid = -1;
235 secondaccountid = -1; 233 secondaccountid = -1;
236 listview->clearSelection (); 234 listview->clearSelection ();
237 listview->setMultiSelection ( FALSE ); 235 listview->setMultiSelection ( FALSE );
238 enableAccounts (); 236 enableAccounts ();
239 disconnect ( listview, SIGNAL ( clicked ( QListViewItem * ) ), this, SLOT ( getTransferAccounts ( QListViewItem * ) ) ); 237 disconnect ( listview, SIGNAL ( clicked ( QListViewItem * ) ), this, SLOT ( getTransferAccounts ( QListViewItem * ) ) );
240 } 238 }
241 } 239 }
242 240
243void AccountDisplay::getTransferAccounts ( QListViewItem * item ) 241void AccountDisplay::getTransferAccounts ( QListViewItem * item )
244 { 242 {
245 if ( item->parent() != 0 || item->childCount() == 0 ) // only set an account for transfer if its a child or parent with no children 243 if ( item->parent() != 0 || item->childCount() == 0 ) // only set an account for transfer if its a child or parent with no children
246 { 244 {
247 if ( firstaccountid == -1 ) 245 if ( firstaccountid == -1 )
248 firstaccountid = item->text ( getIDColumn() ).toInt(); // set first account if we've selected a valid account 246 firstaccountid = item->text ( getIDColumn() ).toInt(); // set first account if we've selected a valid account
249 else 247 else
250 if ( item->text ( getIDColumn() ).toInt() != firstaccountid ) // set the second account if its not equal to the first 248 if ( item->text ( getIDColumn() ).toInt() != firstaccountid ) // set the second account if its not equal to the first
251 secondaccountid = item->text ( getIDColumn() ).toInt(); 249 secondaccountid = item->text ( getIDColumn() ).toInt();
252 } 250 }
253 251
254 // open transfer window if both accounts are set 252 // open transfer window if both accounts are set
255 if ( firstaccountid != -1 && secondaccountid != -1 ) 253 if ( firstaccountid != -1 && secondaccountid != -1 )
256 { 254 {
257 // construct the transferdialog window 255 // construct the transferdialog window
258 TransferDialog *td = new TransferDialog ( this, firstaccountid, secondaccountid ); 256 TransferDialog *td = new TransferDialog ( this, firstaccountid, secondaccountid );
259 257
260 // enter today's date in the date box as default 258 // enter today's date in the date box as default
261 QDate today = QDate::currentDate (); 259 QDate today = QDate::currentDate ();
262 int defaultday = today.day(); 260 int defaultday = today.day();
263 int defaultmonth = today.month(); 261 int defaultmonth = today.month();
264 int defaultyear = today.year(); 262 int defaultyear = today.year();
265 td->date->setText ( preferences->getDate ( defaultyear, defaultmonth, defaultday ) ); 263 td->date->setText ( preferences->getDate ( defaultyear, defaultmonth, defaultday ) );
266 264
267 if ( td->exec() == QDialog::Accepted ) 265 if ( td->exec() == QDialog::Accepted )
268 { 266 {
269 // set the cleared integer if the checkbox is checked 267 // set the cleared integer if the checkbox is checked
270 if ( td->clearedcheckbox->isChecked() == TRUE ) 268 if ( td->clearedcheckbox->isChecked() == TRUE )
271 cleared = 1; 269 cleared = 1;
272 qDebug("Year from transferdialog = %i",td->getYear()); 270 qDebug("Year from transferdialog = %i",td->getYear());
273 // add the transfer with a new date if its been edited or use the default date 271 // add the transfer with a new date if its been edited or use the default date
274 if ( td->getDateEdited () == TRUE ) 272 if ( td->getDateEdited () == TRUE )
275 transfer->addTransfer ( firstaccountid, account->getParentAccountID ( firstaccountid ), secondaccountid, account->getParentAccountID ( secondaccountid ), td->getDay(), td->getMonth(), td->getYear(), td->amount->text().toFloat(), cleared ); 273 transfer->addTransfer ( firstaccountid, account->getParentAccountID ( firstaccountid ), secondaccountid, account->getParentAccountID ( secondaccountid ), td->getDay(), td->getMonth(), td->getYear(), td->amount->text().toFloat(), cleared );
276 else 274 else
277 transfer->addTransfer ( firstaccountid, account->getParentAccountID ( firstaccountid ), secondaccountid, account->getParentAccountID ( secondaccountid ), defaultday, defaultmonth, defaultyear, td->amount->text().toFloat(), cleared ); 275 transfer->addTransfer ( firstaccountid, account->getParentAccountID ( firstaccountid ), secondaccountid, account->getParentAccountID ( secondaccountid ), defaultday, defaultmonth, defaultyear, td->amount->text().toFloat(), cleared );
278 276
279 // update account balances of both accounts and parents if necessary 277 // update account balances of both accounts and parents if necessary
280 account->updateAccountBalance ( firstaccountid ); 278 account->updateAccountBalance ( firstaccountid );
281 if ( account->getParentAccountID ( firstaccountid ) != -1 ) 279 if ( account->getParentAccountID ( firstaccountid ) != -1 )
282 account->changeParentAccountBalance ( account->getParentAccountID ( firstaccountid ) ); 280 account->changeParentAccountBalance ( account->getParentAccountID ( firstaccountid ) );
283 account->updateAccountBalance ( secondaccountid ); 281 account->updateAccountBalance ( secondaccountid );
284 if ( account->getParentAccountID ( secondaccountid ) != -1 ) 282 if ( account->getParentAccountID ( secondaccountid ) != -1 )
285 account->changeParentAccountBalance ( account->getParentAccountID ( secondaccountid ) ); 283 account->changeParentAccountBalance ( account->getParentAccountID ( secondaccountid ) );
286 284
287 // redisplay accounts 285 // redisplay accounts
288 account->displayAccounts ( listview ); 286 account->displayAccounts ( listview );
289 } 287 }
290 else 288 else
291 { 289 {
292 firstaccountid = -1; 290 firstaccountid = -1;
293 secondaccountid = -1; 291 secondaccountid = -1;
294 listview->clearSelection (); 292 listview->clearSelection ();
295 listview->setMultiSelection ( FALSE ); 293 listview->setMultiSelection ( FALSE );
296 disconnect ( listview, SIGNAL ( clicked ( QListViewItem * ) ), this, SLOT ( getTransferAccounts ( QListViewItem * ) ) ); 294 disconnect ( listview, SIGNAL ( clicked ( QListViewItem * ) ), this, SLOT ( getTransferAccounts ( QListViewItem * ) ) );
297 } 295 }
298 296
299 // reset the accounts display window 297 // reset the accounts display window
300 transferbutton->toggle(); // toggling this button with clear the window as well 298 transferbutton->toggle(); // toggling this button with clear the window as well
301 299
302 // reenable all the accounts so the transaction tab will be properly set 300 // reenable all the accounts so the transaction tab will be properly set
303 enableAccounts (); 301 enableAccounts ();
304 } 302 }
305 } 303 }
306 304
307void AccountDisplay::disableParentsWithChildren () 305void AccountDisplay::disableParentsWithChildren ()
308 { 306 {
309 // iterate through accountdisplay listview and disable all the parents that have children 307 // iterate through accountdisplay listview and disable all the parents that have children
310 QListViewItemIterator it ( listview ); 308 QListViewItemIterator it ( listview );
311 for ( ; it.current(); ++it ) 309 for ( ; it.current(); ++it )
312 { 310 {
313 if ( it.current()->parent() == 0 && it.current()->childCount() != 0 ) 311 if ( it.current()->parent() == 0 && it.current()->childCount() != 0 )
314 it.current()->setSelectable ( FALSE ); 312 it.current()->setSelectable ( FALSE );
315 } 313 }
316 } 314 }
317 315
318void AccountDisplay::enableAccounts () 316void AccountDisplay::enableAccounts ()
319 { 317 {
320 // iterate through accountdisplay listview and enable all accounts 318 // iterate through accountdisplay listview and enable all accounts
321 QListViewItemIterator it ( listview ); 319 QListViewItemIterator it ( listview );
322 for ( ; it.current(); ++it ) 320 for ( ; it.current(); ++it )
323 it.current()->setSelectable ( TRUE ); 321 it.current()->setSelectable ( TRUE );
324 } 322 }
325 323
326void AccountDisplay::saveColumnSize ( int column, int oldsize, int newsize ) 324void AccountDisplay::saveColumnSize ( int column, int oldsize, int newsize )
327 { 325 {
328 switch ( column ) 326 switch ( column )
329 { 327 {
330 case 0: 328 case 0:
331 if ( listview->columns() == 3 ) 329 if ( listview->columns() == 3 )
332 preferences->changeColumnPreference ( 1, newsize ); 330 preferences->changeColumnPreference ( 1, newsize );
333 else 331 else
334 preferences->changeColumnPreference ( 10, newsize ); 332 preferences->changeColumnPreference ( 10, newsize );
335 break; 333 break;
336 case 1: 334 case 1:
337 if ( listview->columns() == 3 ) 335 if ( listview->columns() == 3 )
338 preferences->changeColumnPreference ( 2, newsize ); 336 preferences->changeColumnPreference ( 2, newsize );
339 else 337 else
340 preferences->changeColumnPreference ( 11, newsize ); 338 preferences->changeColumnPreference ( 11, newsize );
341 break; 339 break;
342 case 2: 340 case 2:
343 preferences->changeColumnPreference ( 12, newsize ); 341 preferences->changeColumnPreference ( 12, newsize );
344 break; 342 break;
345 } 343 }
346 344
347 } 345 }
348 346
349void AccountDisplay::saveSortingPreference ( int column ) 347void AccountDisplay::saveSortingPreference ( int column )
350 { 348 {
351 preferences->changeSortingPreference ( 1, column ); 349 preferences->changeSortingPreference ( 1, column );
352 } 350 }
353 351
354int AccountDisplay::getIDColumn () 352int AccountDisplay::getIDColumn ()
355 { 353 {
356 int counter; 354 int counter;
357 int columns = listview->columns(); 355 int columns = listview->columns();
358 for ( counter = 0; counter <= columns; counter++ ) 356 for ( counter = 0; counter <= columns; counter++ )
359 if ( listview->header()->label ( counter ).length() == 0 ) 357 if ( listview->header()->label ( counter ).length() == 0 )
360 return counter; 358 return counter;
361 } 359 }
362 360
363void AccountDisplay::editAccount () 361void AccountDisplay::editAccount ()
364 { 362 {
365 if ( listview->selectedItem() == 0 ) 363 if ( listview->selectedItem() == 0 )
366 QMessageBox::warning ( this, "QashMoney", "Please select an account\nto edit."); 364 QMessageBox::warning ( this, "QashMoney", "Please select an account\nto edit.");
367 else 365 else
368 { 366 {
369 // set the accountid 367 // set the accountid
370 int accountid = listview->selectedItem()->text ( getIDColumn() ).toInt(); 368 int accountid = listview->selectedItem()->text ( getIDColumn() ).toInt();
371 369
372 //construct new dialog box 370 //construct new dialog box
373 QDialog *editaccountwindow = new QDialog ( this, 0, TRUE ); 371 QDialog *editaccountwindow = new QDialog ( this, 0, TRUE );
374 editaccountwindow->setCaption ( "Edit Account" ); 372 editaccountwindow->setCaption ( "Edit Account" );
375 373
376 // construct the items which will go in the dialog bix 374 // construct the items which will go in the dialog bix
377 QLabel *namelabel = new QLabel ( "Account Name", editaccountwindow ); 375 QLabel *namelabel = new QLabel ( "Account Name", editaccountwindow );
378 QLineEdit *accountname = new QLineEdit ( editaccountwindow ); 376 QLineEdit *accountname = new QLineEdit ( editaccountwindow );
379 QLabel *descriptionlabel = new QLabel ( "Account Description", editaccountwindow ); 377 QLabel *descriptionlabel = new QLabel ( "Account Description", editaccountwindow );
380 QLineEdit *accountdescription = new QLineEdit ( editaccountwindow ); 378 QLineEdit *accountdescription = new QLineEdit ( editaccountwindow );
381 Currency *currencybox = new Currency ( editaccountwindow ); 379 Currency *currencybox = new Currency ( editaccountwindow );
382 380
383 QVBoxLayout *layout = new QVBoxLayout ( editaccountwindow, 5, 2 ); 381 QVBoxLayout *layout = new QVBoxLayout ( editaccountwindow, 5, 2 );
384 layout->addWidget ( namelabel ); 382 layout->addWidget ( namelabel );
385 layout->addWidget ( accountname ); 383 layout->addWidget ( accountname );
386 layout->addWidget ( descriptionlabel ); 384 layout->addWidget ( descriptionlabel );
387 layout->addWidget ( accountdescription ); 385 layout->addWidget ( accountdescription );
388 layout->addWidget ( currencybox ); 386 layout->addWidget ( currencybox );
389 387
390 //set the account name 388 //set the account name
391 accountname->setText ( listview->selectedItem()->text ( 0 ) ); 389 accountname->setText ( listview->selectedItem()->text ( 0 ) );
392 390
393 //set the account description 391 //set the account description
394 accountdescription->setText ( account->getAccountDescription ( accountid ) ); 392 accountdescription->setText ( account->getAccountDescription ( accountid ) );
395 393
396 if ( preferences->getPreference ( 4 ) == 1 ) 394 if ( preferences->getPreference ( 4 ) == 1 )
397 { 395 {
398 // get currency code for this account then iterate through the currency box 396 // get currency code for this account then iterate through the currency box
399 // to find the one we want 397 // to find the one we want
400 int count = currencybox->currencybox->count(); 398 int count = currencybox->currencybox->count();
401 QString code = account->getCurrencyCode ( accountid ); 399 QString code = account->getCurrencyCode ( accountid );
402 for ( int counter = 0; count - 1; counter++ ) 400 for ( int counter = 0; count - 1; counter++ )
403 { 401 {
404 if ( QString::compare ( currencybox->currencybox->text ( counter ), code ) == 0 ) 402 if ( QString::compare ( currencybox->currencybox->text ( counter ), code ) == 0 )
405 { 403 {
406 currencybox->currencybox->setCurrentItem ( counter ); 404 currencybox->currencybox->setCurrentItem ( counter );
407 break; 405 break;
408 } 406 }
409 } 407 }
410 } 408 }
411 else 409 else
412 currencybox->setEnabled ( FALSE ); 410 currencybox->setEnabled ( FALSE );
413 411
414 //execute the dialog box 412 //execute the dialog box
415 int response = editaccountwindow->exec(); 413 int response = editaccountwindow->exec();
416 if ( response == 1 ) 414 if ( response == 1 )
417 { 415 {
418 account->updateAccount ( accountname->text(), accountdescription->text(), currencybox->currencybox->currentText(), accountid ); 416 account->updateAccount ( accountname->text(), accountdescription->text(), currencybox->currencybox->currentText(), accountid );
419 account->displayAccounts ( listview ); 417 account->displayAccounts ( listview );
420 418
421 // Try and select the same account that was just edited 419 // Try and select the same account that was just edited
422 QListViewItemIterator it ( listview ); 420 QListViewItemIterator it ( listview );
423 for ( ; it.current(); ++it ) 421 for ( ; it.current(); ++it )
424 { 422 {
425 if ( it.current()->text ( 0 ) == accountname->text() ) 423 if ( it.current()->text ( 0 ) == accountname->text() )
426 { 424 {
427 listview->setSelected ( it.current(), TRUE ); 425 listview->setSelected ( it.current(), TRUE );
428 return; 426 return;
429 } 427 }
430 } 428 }
431 maintabs->setTabEnabled ( tab2, FALSE ); 429 maintabs->setTabEnabled ( tab2, FALSE );
432 } 430 }
433 } 431 }
434 } 432 }
435 433
436void AccountDisplay::setAccountExpanded ( QListViewItem *item ) 434void AccountDisplay::setAccountExpanded ( QListViewItem *item )
437 { 435 {
438 int accountid = item->text ( getIDColumn() ).toInt(); 436 int accountid = item->text ( getIDColumn() ).toInt();
439 account->setAccountExpanded ( 1, accountid ); 437 account->setAccountExpanded ( 1, accountid );
440 } 438 }
441 439
442void AccountDisplay::setAccountCollapsed ( QListViewItem *item ) 440void AccountDisplay::setAccountCollapsed ( QListViewItem *item )
443 { 441 {
444 int accountid = item->text ( getIDColumn() ).toInt(); 442 int accountid = item->text ( getIDColumn() ).toInt();
445 account->setAccountExpanded ( 0, accountid ); 443 account->setAccountExpanded ( 0, accountid );
446 } 444 }
447 445
448 446
diff --git a/noncore/apps/qashmoney/budgetdisplay.cpp b/noncore/apps/qashmoney/budgetdisplay.cpp
index 492595a..d4047bf 100755
--- a/noncore/apps/qashmoney/budgetdisplay.cpp
+++ b/noncore/apps/qashmoney/budgetdisplay.cpp
@@ -1,420 +1,417 @@
1#include <qmessagebox.h> 1#include <qmessagebox.h>
2#include <qheader.h> 2#include <qheader.h>
3#include <qfont.h>
4#include <sqlite.h> 3#include <sqlite.h>
5 4
6#include "budgetdisplay.h" 5#include "budgetdisplay.h"
7#include "budget.h" 6#include "budget.h"
8#include "newaccount.h"
9#include "datepicker.h" 7#include "datepicker.h"
10#include "preferences.h"
11#include "transaction.h" 8#include "transaction.h"
12 9
13extern Preferences *preferences; 10extern Preferences *preferences;
14extern Budget *budget; 11extern Budget *budget;
15extern Transaction *transaction; 12extern Transaction *transaction;
16 13
17BudgetDisplay::BudgetDisplay ( QWidget *parent ) : QWidget ( parent ) 14BudgetDisplay::BudgetDisplay ( QWidget *parent ) : QWidget ( parent )
18 { 15 {
19 QFont font = this->font(); 16 QFont font = this->font();
20 font.setWeight ( QFont::Bold ); 17 font.setWeight ( QFont::Bold );
21 18
22 //set the default date to today 19 //set the default date to today
23 newDate = QDate::currentDate (); 20 newDate = QDate::currentDate ();
24 year = newDate.year(); 21 year = newDate.year();
25 month = newDate.month(); 22 month = newDate.month();
26 day = newDate.day(); 23 day = newDate.day();
27 datelabel = preferences->getDate ( year, month ); 24 datelabel = preferences->getDate ( year, month );
28 25
29 setCaption ( "Budget" ); 26 setCaption ( "Budget" );
30 27
31 firstline = new QHBox ( this ); 28 firstline = new QHBox ( this );
32 firstline->setSpacing ( 2 ); 29 firstline->setSpacing ( 2 );
33 secondline = new QHBox ( this ); 30 secondline = new QHBox ( this );
34 secondline->setSpacing ( 10 ); 31 secondline->setSpacing ( 10 );
35 32
36 menu = new QMenuBar ( this ); 33 menu = new QMenuBar ( this );
37 menu->setFrameStyle ( QFrame::Box | QFrame::Sunken ); 34 menu->setFrameStyle ( QFrame::Box | QFrame::Sunken );
38 budgetmenu = new QPopupMenu ( this ); 35 budgetmenu = new QPopupMenu ( this );
39 lineitemsmenu = new QPopupMenu ( this ); 36 lineitemsmenu = new QPopupMenu ( this );
40 datemenu = new QPopupMenu ( this ); 37 datemenu = new QPopupMenu ( this );
41 menu->insertItem ( "Budget", budgetmenu ); 38 menu->insertItem ( "Budget", budgetmenu );
42 menu->insertItem ( "Line Item", lineitemsmenu ); 39 menu->insertItem ( "Line Item", lineitemsmenu );
43 menu->insertItem ( "Date", datemenu ); 40 menu->insertItem ( "Date", datemenu );
44 budgetmenu->insertItem ( "New", this, SLOT ( newBudget () ), 0, 1 ); 41 budgetmenu->insertItem ( "New", this, SLOT ( newBudget () ), 0, 1 );
45 budgetmenu->insertItem ( "Edit", this, SLOT ( editBudget () ), 0, 2 ); 42 budgetmenu->insertItem ( "Edit", this, SLOT ( editBudget () ), 0, 2 );
46 budgetmenu->insertItem ( "Delete", this, SLOT ( deleteBudget () ), 0, 3 ); 43 budgetmenu->insertItem ( "Delete", this, SLOT ( deleteBudget () ), 0, 3 );
47 lineitemsmenu->insertItem ( "New", this, SLOT ( newLineItem () ), 0, 1 ); 44 lineitemsmenu->insertItem ( "New", this, SLOT ( newLineItem () ), 0, 1 );
48 lineitemsmenu->insertItem ( "Edit", this, SLOT ( editLineItem () ), 0, 2 ); 45 lineitemsmenu->insertItem ( "Edit", this, SLOT ( editLineItem () ), 0, 2 );
49 lineitemsmenu->insertItem ( "Delete", this, SLOT ( deleteLineItem () ), 0, 3 ); 46 lineitemsmenu->insertItem ( "Delete", this, SLOT ( deleteLineItem () ), 0, 3 );
50 datemenu->insertItem ( "Change", this, SLOT ( showCalendar() ) ); 47 datemenu->insertItem ( "Change", this, SLOT ( showCalendar() ) );
51 48
52 budgetbox = new QComboBox ( firstline ); 49 budgetbox = new QComboBox ( firstline );
53 connect ( budgetbox, SIGNAL ( activated ( int ) ), this, SLOT ( setCurrentBudget ( int ) ) ); 50 connect ( budgetbox, SIGNAL ( activated ( int ) ), this, SLOT ( setCurrentBudget ( int ) ) );
54 51
55 budgetview = new QComboBox ( firstline ); 52 budgetview = new QComboBox ( firstline );
56 budgetview->insertItem ( "Month" ); 53 budgetview->insertItem ( "Month" );
57 budgetview->insertItem ( "Year" ); 54 budgetview->insertItem ( "Year" );
58 connect ( budgetview, SIGNAL ( activated ( int ) ), this, SLOT ( setCurrentView ( int ) ) ); 55 connect ( budgetview, SIGNAL ( activated ( int ) ), this, SLOT ( setCurrentView ( int ) ) );
59 56
60 budgeted = new QLabel ( secondline ); 57 budgeted = new QLabel ( secondline );
61 budgeted->setFont ( font ); 58 budgeted->setFont ( font );
62 actual = new QLabel ( secondline ); 59 actual = new QLabel ( secondline );
63 actual->setFont ( font ); 60 actual->setFont ( font );
64 date = new QLabel ( secondline ); 61 date = new QLabel ( secondline );
65 date->setFont ( font ); 62 date->setFont ( font );
66 63
67 listview = new QListView ( this ); 64 listview = new QListView ( this );
68 listview->setAllColumnsShowFocus ( TRUE ); 65 listview->setAllColumnsShowFocus ( TRUE );
69 listview->setShowSortIndicator ( TRUE ); 66 listview->setShowSortIndicator ( TRUE );
70 listview->setRootIsDecorated ( TRUE ); 67 listview->setRootIsDecorated ( TRUE );
71 listview->setMultiSelection ( FALSE ); 68 listview->setMultiSelection ( FALSE );
72 listview->addColumn ( "Line Item", preferences->getColumnPreference ( 13 ) ); // column id 13 69 listview->addColumn ( "Line Item", preferences->getColumnPreference ( 13 ) ); // column id 13
73 listview->addColumn ( "Budget", preferences->getColumnPreference ( 14 ) ); // column id 14 70 listview->addColumn ( "Budget", preferences->getColumnPreference ( 14 ) ); // column id 14
74 listview->addColumn ( "Actual", preferences->getColumnPreference ( 15 ) ); // column id 15 71 listview->addColumn ( "Actual", preferences->getColumnPreference ( 15 ) ); // column id 15
75 listview->addColumn ( "", 0 ); // line item ids 72 listview->addColumn ( "", 0 ); // line item ids
76 listview->setColumnWidthMode ( 0, QListView::Manual ); 73 listview->setColumnWidthMode ( 0, QListView::Manual );
77 listview->setColumnWidthMode ( 1, QListView::Manual ); 74 listview->setColumnWidthMode ( 1, QListView::Manual );
78 listview->setColumnWidthMode ( 2, QListView::Manual ); 75 listview->setColumnWidthMode ( 2, QListView::Manual );
79 listview->setColumnAlignment ( 1, Qt::AlignRight ); 76 listview->setColumnAlignment ( 1, Qt::AlignRight );
80 listview->setColumnAlignment ( 2, Qt::AlignRight ); 77 listview->setColumnAlignment ( 2, Qt::AlignRight );
81 listview->setColumnWidthMode ( 3, QListView::Manual ); 78 listview->setColumnWidthMode ( 3, QListView::Manual );
82 79
83 listview->header()->setTracking ( FALSE ); 80 listview->header()->setTracking ( FALSE );
84 connect ( listview->header(), SIGNAL ( sizeChange ( int, int, int ) ), this, SLOT ( saveColumnSize ( int, int, int ) ) ); 81 connect ( listview->header(), SIGNAL ( sizeChange ( int, int, int ) ), this, SLOT ( saveColumnSize ( int, int, int ) ) );
85 connect ( listview->header(), SIGNAL ( clicked ( int ) ), this, SLOT ( saveSortingPreference ( int ) ) ); 82 connect ( listview->header(), SIGNAL ( clicked ( int ) ), this, SLOT ( saveSortingPreference ( int ) ) );
86 83
87 // pull the column sorting preference from the preferences table, and configure the listview accordingly 84 // pull the column sorting preference from the preferences table, and configure the listview accordingly
88 int column = 0; 85 int column = 0;
89 int direction = 0; 86 int direction = 0;
90 preferences->getSortingPreference ( 3, &column, &direction ); 87 preferences->getSortingPreference ( 3, &column, &direction );
91 listview->setSorting ( column, direction ); 88 listview->setSorting ( column, direction );
92 89
93 displayBudgetNames(); 90 displayBudgetNames();
94 91
95 layout = new QVBoxLayout ( this, 2, 2 ); 92 layout = new QVBoxLayout ( this, 2, 2 );
96 layout->setMenuBar ( menu ); 93 layout->setMenuBar ( menu );
97 layout->addWidget ( firstline ); 94 layout->addWidget ( firstline );
98 layout->addWidget ( secondline ); 95 layout->addWidget ( secondline );
99 layout->addWidget ( listview ); 96 layout->addWidget ( listview );
100 } 97 }
101 98
102void BudgetDisplay::deleteBudget () 99void BudgetDisplay::deleteBudget ()
103 { 100 {
104 listview->clear(); 101 listview->clear();
105 transaction->clearBudgetIDs ( currentbudget ); 102 transaction->clearBudgetIDs ( currentbudget );
106 budget->deleteBudget ( currentbudget ); 103 budget->deleteBudget ( currentbudget );
107 if ( budgetbox->count() != 0 ) 104 if ( budgetbox->count() != 0 )
108 displayBudgetNames(); 105 displayBudgetNames();
109 checkBudgets(); 106 checkBudgets();
110 } 107 }
111 108
112void BudgetDisplay::saveColumnSize ( int column, int oldsize, int newsize ) 109void BudgetDisplay::saveColumnSize ( int column, int oldsize, int newsize )
113 { 110 {
114 switch ( column ) 111 switch ( column )
115 { 112 {
116 case 0: 113 case 0:
117 preferences->changeColumnPreference ( 13, newsize ); 114 preferences->changeColumnPreference ( 13, newsize );
118 break; 115 break;
119 case 1: 116 case 1:
120 preferences->changeColumnPreference ( 14, newsize ); 117 preferences->changeColumnPreference ( 14, newsize );
121 break; 118 break;
122 case 2: 119 case 2:
123 preferences->changeColumnPreference ( 15, newsize ); 120 preferences->changeColumnPreference ( 15, newsize );
124 break; 121 break;
125 } 122 }
126 } 123 }
127 124
128void BudgetDisplay::saveSortingPreference ( int column ) 125void BudgetDisplay::saveSortingPreference ( int column )
129 { 126 {
130 preferences->changeSortingPreference ( 3, column ); 127 preferences->changeSortingPreference ( 3, column );
131 } 128 }
132 129
133int BudgetDisplay::getIDColumn () 130int BudgetDisplay::getIDColumn ()
134 { 131 {
135 int counter; 132 int counter;
136 int columns = listview->columns(); 133 int columns = listview->columns();
137 for ( counter = 0; counter <= columns; counter++ ) 134 for ( counter = 0; counter <= columns; counter++ )
138 if ( listview->header()->label ( counter ).length() == 0 ) 135 if ( listview->header()->label ( counter ).length() == 0 )
139 return counter; 136 return counter;
140 } 137 }
141 138
142void BudgetDisplay::newBudget () 139void BudgetDisplay::newBudget ()
143 { 140 {
144 constructBudgetWindow(); 141 constructBudgetWindow();
145 int response = nb->exec(); 142 int response = nb->exec();
146 if ( response == 1 ) 143 if ( response == 1 )
147 { 144 {
148 // open a new budget object 145 // open a new budget object
149 int addedbudget = budget->addBudget ( budgetname->text(), 0, description->text(), currencybox->currencybox->currentText(), day, month, year, day, month, year, 0 ); 146 int addedbudget = budget->addBudget ( budgetname->text(), 0, description->text(), currencybox->currencybox->currentText(), day, month, year, day, month, year, 0 );
150 transaction->clearBudgetIDs ( addedbudget ); 147 transaction->clearBudgetIDs ( addedbudget );
151 displayBudgetNames(); 148 displayBudgetNames();
152 } 149 }
153 checkBudgets(); 150 checkBudgets();
154 } 151 }
155 152
156void BudgetDisplay::constructBudgetWindow () 153void BudgetDisplay::constructBudgetWindow ()
157 { 154 {
158 //construct and format the new budget window 155 //construct and format the new budget window
159 nb = new QDialog ( this, 0, TRUE ); 156 nb = new QDialog ( this, 0, TRUE );
160 nb->setCaption ( "Budget" ); 157 nb->setCaption ( "Budget" );
161 QLabel *namelabel = new QLabel ( "Budget Name", nb ); 158 QLabel *namelabel = new QLabel ( "Budget Name", nb );
162 budgetname = new QLineEdit ( nb ); 159 budgetname = new QLineEdit ( nb );
163 QLabel *descriptionlabel = new QLabel ( "Description", nb ); 160 QLabel *descriptionlabel = new QLabel ( "Description", nb );
164 description = new QLineEdit ( nb ); 161 description = new QLineEdit ( nb );
165 currencybox = new Currency ( nb ); 162 currencybox = new Currency ( nb );
166 QBoxLayout *layout = new QVBoxLayout ( nb, 2, 2 ); 163 QBoxLayout *layout = new QVBoxLayout ( nb, 2, 2 );
167 layout->addWidget ( namelabel ); 164 layout->addWidget ( namelabel );
168 layout->addWidget ( budgetname ); 165 layout->addWidget ( budgetname );
169 layout->addWidget ( descriptionlabel ); 166 layout->addWidget ( descriptionlabel );
170 layout->addWidget ( description ); 167 layout->addWidget ( description );
171 layout->addWidget ( currencybox ); 168 layout->addWidget ( currencybox );
172 } 169 }
173 170
174void BudgetDisplay::displayBudgetNames () 171void BudgetDisplay::displayBudgetNames ()
175 { 172 {
176 budgetbox->clear(); 173 budgetbox->clear();
177 if ( budget->getNumberOfBudgets() != 0 ) 174 if ( budget->getNumberOfBudgets() != 0 )
178 { 175 {
179 ids = budget->getBudgetIDs(); 176 ids = budget->getBudgetIDs();
180 for ( QStringList::Iterator it = ids->begin(); it != ids->end(); ++it ) 177 for ( QStringList::Iterator it = ids->begin(); it != ids->end(); ++it )
181 { 178 {
182 QString flag = "/opt/QtPalmtop/pics/flags/"; 179 QString flag = "/opt/QtPalmtop/pics/flags/";
183 flag.append ( budget->getCurrency ( (*it).toInt() ) ); 180 flag.append ( budget->getCurrency ( (*it).toInt() ) );
184 flag.append ( ".png" ); 181 flag.append ( ".png" );
185 budgetbox->insertItem ( QPixmap ( flag ), budget->getBudgetName ( (*it).toInt() ) ); 182 budgetbox->insertItem ( QPixmap ( flag ), budget->getBudgetName ( (*it).toInt() ) );
186 } 183 }
187 setCurrentBudget ( 0 ); 184 setCurrentBudget ( 0 );
188 } 185 }
189 else 186 else
190 checkBudgets(); 187 checkBudgets();
191 } 188 }
192 189
193void BudgetDisplay::setCurrentBudget ( int index ) 190void BudgetDisplay::setCurrentBudget ( int index )
194 { 191 {
195 currentbudget = ( ids->operator[] ( index ).toInt() ); 192 currentbudget = ( ids->operator[] ( index ).toInt() );
196 displayLineItems(); 193 displayLineItems();
197 } 194 }
198 195
199void BudgetDisplay::setCurrentView ( int index ) 196void BudgetDisplay::setCurrentView ( int index )
200 { 197 {
201 displayLineItems(); 198 displayLineItems();
202 } 199 }
203 200
204void BudgetDisplay::showCalendar () 201void BudgetDisplay::showCalendar ()
205 { 202 {
206 // create new calendar object and show it 203 // create new calendar object and show it
207 DatePicker *dp = new DatePicker ( QDate ( year, month, day ) ); 204 DatePicker *dp = new DatePicker ( QDate ( year, month, day ) );
208 dp->daylabel->hide(); 205 dp->daylabel->hide();
209 dp->daybox->hide(); 206 dp->daybox->hide();
210 if ( budgetview->currentItem() == 1 ) 207 if ( budgetview->currentItem() == 1 )
211 { 208 {
212 dp->monthlabel->hide(); 209 dp->monthlabel->hide();
213 dp->monthbox->hide(); 210 dp->monthbox->hide();
214 } 211 }
215 dp->setMaximumWidth ( ( int ) ( this->size().width() * 0.9 ) ); 212 dp->setMaximumWidth ( ( int ) ( this->size().width() * 0.9 ) );
216 213
217 int response = dp->exec(); 214 int response = dp->exec();
218 if ( response == 1 ) 215 if ( response == 1 )
219 { 216 {
220 // Set date integers 217 // Set date integers
221 year = dp->getYear(); 218 year = dp->getYear();
222 if ( budgetview->currentItem() == 0 ) 219 if ( budgetview->currentItem() == 0 )
223 month = dp->getMonth(); 220 month = dp->getMonth();
224 else 221 else
225 month = newDate.month(); 222 month = newDate.month();
226 datelabel = preferences->getDate ( year, month ); 223 datelabel = preferences->getDate ( year, month );
227 displayLineItems(); 224 displayLineItems();
228 } 225 }
229 } 226 }
230 227
231void BudgetDisplay::newLineItem () 228void BudgetDisplay::newLineItem ()
232 { 229 {
233 //construct and format the new line item window 230 //construct and format the new line item window
234 constructLineItemWindow (); 231 constructLineItemWindow ();
235 232
236 int response = newlineitem->exec(); 233 int response = newlineitem->exec();
237 if ( response == 1 ) 234 if ( response == 1 )
238 { 235 {
239 float amount; 236 float amount;
240 if ( lineitemtime->currentItem() == 0 ) 237 if ( lineitemtime->currentItem() == 0 )
241 amount = lineitemamount->text().toFloat(); 238 amount = lineitemamount->text().toFloat();
242 else if ( lineitemtime->currentItem() == 1 ) 239 else if ( lineitemtime->currentItem() == 1 )
243 amount = lineitemamount->text().toFloat() * 12; 240 amount = lineitemamount->text().toFloat() * 12;
244 else 241 else
245 amount = lineitemamount->text().toFloat() * 52; 242 amount = lineitemamount->text().toFloat() * 52;
246 int lineitemadded = budget->addLineItem ( currentbudget, lineitemname->text(), amount, lineitemtime->currentItem() ); 243 int lineitemadded = budget->addLineItem ( currentbudget, lineitemname->text(), amount, lineitemtime->currentItem() );
247 transaction->clearBudgetIDs ( currentbudget, lineitemadded ); 244 transaction->clearBudgetIDs ( currentbudget, lineitemadded );
248 displayLineItems(); 245 displayLineItems();
249 } 246 }
250 checkBudgets(); 247 checkBudgets();
251 } 248 }
252 249
253void BudgetDisplay::constructLineItemWindow () 250void BudgetDisplay::constructLineItemWindow ()
254 { 251 {
255 //construct and format the new budget window 252 //construct and format the new budget window
256 newlineitem = new QDialog ( this, 0, TRUE ); 253 newlineitem = new QDialog ( this, 0, TRUE );
257 newlineitem->setCaption ( "Line Item" ); 254 newlineitem->setCaption ( "Line Item" );
258 QLabel *namelabel = new QLabel ( "Line Item Name", newlineitem ); 255 QLabel *namelabel = new QLabel ( "Line Item Name", newlineitem );
259 lineitemname = new QLineEdit ( newlineitem ); 256 lineitemname = new QLineEdit ( newlineitem );
260 QLabel *budgetamountlabel = new QLabel ( "Budget Amount", newlineitem ); 257 QLabel *budgetamountlabel = new QLabel ( "Budget Amount", newlineitem );
261 lineitemamount = new QLineEdit ( newlineitem ); 258 lineitemamount = new QLineEdit ( newlineitem );
262 QLabel *lineitemtimelabel = new QLabel ( "Per:", newlineitem ); 259 QLabel *lineitemtimelabel = new QLabel ( "Per:", newlineitem );
263 lineitemtime = new QComboBox ( newlineitem ); 260 lineitemtime = new QComboBox ( newlineitem );
264 lineitemtime->insertItem ( "Year" ); // type 0 261 lineitemtime->insertItem ( "Year" ); // type 0
265 lineitemtime->insertItem ( "Month" ); // type 1 262 lineitemtime->insertItem ( "Month" ); // type 1
266 lineitemtime->insertItem ( "Week" ); // type 2 263 lineitemtime->insertItem ( "Week" ); // type 2
267 QBoxLayout *layout = new QVBoxLayout ( newlineitem, 2, 2 ); 264 QBoxLayout *layout = new QVBoxLayout ( newlineitem, 2, 2 );
268 layout->addWidget ( namelabel ); 265 layout->addWidget ( namelabel );
269 layout->addWidget ( lineitemname ); 266 layout->addWidget ( lineitemname );
270 layout->addWidget ( budgetamountlabel ); 267 layout->addWidget ( budgetamountlabel );
271 layout->addWidget ( lineitemamount ); 268 layout->addWidget ( lineitemamount );
272 layout->addWidget ( lineitemtimelabel ); 269 layout->addWidget ( lineitemtimelabel );
273 layout->addWidget ( lineitemtime ); 270 layout->addWidget ( lineitemtime );
274 } 271 }
275 272
276void BudgetDisplay::deleteLineItem () 273void BudgetDisplay::deleteLineItem ()
277 { 274 {
278 if ( listview->selectedItem() != 0 ) 275 if ( listview->selectedItem() != 0 )
279 { 276 {
280 int lineitemid = listview->selectedItem()->text ( getIDColumn() ).toInt(); 277 int lineitemid = listview->selectedItem()->text ( getIDColumn() ).toInt();
281 transaction->clearBudgetIDs ( currentbudget, lineitemid ); 278 transaction->clearBudgetIDs ( currentbudget, lineitemid );
282 budget->deleteLineItem ( currentbudget, lineitemid ); 279 budget->deleteLineItem ( currentbudget, lineitemid );
283 displayBudgetNames(); 280 displayBudgetNames();
284 } 281 }
285 else 282 else
286 QMessageBox::warning ( this, "QashMoney", "Please select a line item to delete." ); 283 QMessageBox::warning ( this, "QashMoney", "Please select a line item to delete." );
287 checkBudgets(); 284 checkBudgets();
288 } 285 }
289 286
290void BudgetDisplay::displayLineItems () 287void BudgetDisplay::displayLineItems ()
291 { 288 {
292 listview->clear(); 289 listview->clear();
293 if ( budget->getNumberOfBudgets() != 0 ) 290 if ( budget->getNumberOfBudgets() != 0 )
294 { 291 {
295 QString budgettable = budgetbox->currentText(); 292 QString budgettable = budgetbox->currentText();
296 budgettable.append ( QString::number ( currentbudget ) ); 293 budgettable.append ( QString::number ( currentbudget ) );
297 budget->displayLineItems ( currentbudget, listview, month, year, budgetview->currentItem() ); 294 budget->displayLineItems ( currentbudget, listview, month, year, budgetview->currentItem() );
298 totalactual = transaction->getActualTotal ( currentbudget, year, month, budgetview->currentItem() ); 295 totalactual = transaction->getActualTotal ( currentbudget, year, month, budgetview->currentItem() );
299 totalbudget = budget->getBudgetTotal ( currentbudget, budgetview->currentItem() ); 296 totalbudget = budget->getBudgetTotal ( currentbudget, budgetview->currentItem() );
300 updateBudgetInformation(); 297 updateBudgetInformation();
301 } 298 }
302 } 299 }
303 300
304void BudgetDisplay::checkBudgets () 301void BudgetDisplay::checkBudgets ()
305 { 302 {
306 if ( budget->getNumberOfBudgets() == 0 ) 303 if ( budget->getNumberOfBudgets() == 0 )
307 { 304 {
308 budgetview->setEnabled ( FALSE ); 305 budgetview->setEnabled ( FALSE );
309 budgetmenu->setItemEnabled ( 2, FALSE ); 306 budgetmenu->setItemEnabled ( 2, FALSE );
310 budgetmenu->setItemEnabled ( 3, FALSE ); 307 budgetmenu->setItemEnabled ( 3, FALSE );
311 lineitemsmenu->setItemEnabled ( 1, FALSE ); 308 lineitemsmenu->setItemEnabled ( 1, FALSE );
312 lineitemsmenu->setItemEnabled ( 2, FALSE ); 309 lineitemsmenu->setItemEnabled ( 2, FALSE );
313 lineitemsmenu->setItemEnabled ( 3, FALSE ); 310 lineitemsmenu->setItemEnabled ( 3, FALSE );
314 } 311 }
315 else 312 else
316 { 313 {
317 budgetview->setEnabled ( TRUE ); 314 budgetview->setEnabled ( TRUE );
318 budgetmenu->setItemEnabled ( 2, TRUE ); 315 budgetmenu->setItemEnabled ( 2, TRUE );
319 budgetmenu->setItemEnabled ( 3, TRUE ); 316 budgetmenu->setItemEnabled ( 3, TRUE );
320 lineitemsmenu->setItemEnabled ( 1, TRUE ); 317 lineitemsmenu->setItemEnabled ( 1, TRUE );
321 lineitemsmenu->setItemEnabled ( 2, FALSE ); 318 lineitemsmenu->setItemEnabled ( 2, FALSE );
322 lineitemsmenu->setItemEnabled ( 3, FALSE ); 319 lineitemsmenu->setItemEnabled ( 3, FALSE );
323 320
324 if ( budget->getNumberOfLineItems ( currentbudget ) != 0 ) 321 if ( budget->getNumberOfLineItems ( currentbudget ) != 0 )
325 { 322 {
326 lineitemsmenu->setItemEnabled ( 2, TRUE ); 323 lineitemsmenu->setItemEnabled ( 2, TRUE );
327 lineitemsmenu->setItemEnabled ( 3, TRUE ); 324 lineitemsmenu->setItemEnabled ( 3, TRUE );
328 } 325 }
329 } 326 }
330 } 327 }
331 328
332void BudgetDisplay::updateBudgetInformation () 329void BudgetDisplay::updateBudgetInformation ()
333 { 330 {
334 if ( budgetview->currentItem() == 0 ) 331 if ( budgetview->currentItem() == 0 )
335 { 332 {
336 datelabel = preferences->getDate ( year, month ); 333 datelabel = preferences->getDate ( year, month );
337 datelabel.prepend ( "Date: " ); 334 datelabel.prepend ( "Date: " );
338 date->setText ( datelabel ); 335 date->setText ( datelabel );
339 } 336 }
340 else 337 else
341 date->setText ( QString::number ( year ) ); 338 date->setText ( QString::number ( year ) );
342 339
343 QString budget = "Budget: "; 340 QString budget = "Budget: ";
344 budget.append ( totalbudget ); 341 budget.append ( totalbudget );
345 budgeted->setText ( budget ); 342 budgeted->setText ( budget );
346 343
347 QString actualamount = "Actual: "; 344 QString actualamount = "Actual: ";
348 actualamount.append ( totalactual ); 345 actualamount.append ( totalactual );
349 actual->setText ( actualamount ); 346 actual->setText ( actualamount );
350 } 347 }
351 348
352void BudgetDisplay::editBudget () 349void BudgetDisplay::editBudget ()
353 { 350 {
354 constructBudgetWindow(); 351 constructBudgetWindow();
355 352
356 //set the title 353 //set the title
357 budgetname->setText ( budget->getBudgetName ( currentbudget ) ); 354 budgetname->setText ( budget->getBudgetName ( currentbudget ) );
358 //set the description 355 //set the description
359 description->setText ( budget->getBudgetDescription ( currentbudget ) ); 356 description->setText ( budget->getBudgetDescription ( currentbudget ) );
360 // retrieve the two character currency code then 357 // retrieve the two character currency code then
361 // go through the currencty box and find the code 358 // go through the currencty box and find the code
362 //set the currency box to that index number 359 //set the currency box to that index number
363 int count = currencybox->currencybox->count(); 360 int count = currencybox->currencybox->count();
364 QString code = budget->getCurrency ( currentbudget ); 361 QString code = budget->getCurrency ( currentbudget );
365 for ( int counter = 0; count - 1; counter++ ) 362 for ( int counter = 0; count - 1; counter++ )
366 { 363 {
367 if ( QString::compare (currencybox->currencybox->text ( counter ), code ) == 0 ) 364 if ( QString::compare (currencybox->currencybox->text ( counter ), code ) == 0 )
368 { 365 {
369 currencybox->currencybox->setCurrentItem ( counter ); 366 currencybox->currencybox->setCurrentItem ( counter );
370 break; 367 break;
371 } 368 }
372 } 369 }
373 int response = nb->exec(); 370 int response = nb->exec();
374 if ( response == 1 ) 371 if ( response == 1 )
375 { 372 {
376 budget->updateBudget ( budgetname->text(), description->text(), currencybox->currencybox->currentText(), currentbudget ); 373 budget->updateBudget ( budgetname->text(), description->text(), currencybox->currencybox->currentText(), currentbudget );
377 displayBudgetNames(); 374 displayBudgetNames();
378 } 375 }
379 } 376 }
380 377
381void BudgetDisplay::editLineItem () 378void BudgetDisplay::editLineItem ()
382 { 379 {
383 if ( listview->selectedItem() != 0 ) 380 if ( listview->selectedItem() != 0 )
384 { 381 {
385 constructLineItemWindow(); 382 constructLineItemWindow();
386 383
387 // set the line item name 384 // set the line item name
388 lineitemname->setText ( listview->selectedItem()->text( 0 ) ); 385 lineitemname->setText ( listview->selectedItem()->text( 0 ) );
389 386
390 // set the line item time combobox 387 // set the line item time combobox
391 int lineitemtype = budget->getLineItemTime ( currentbudget, listview->selectedItem()->text ( 3 ).toInt() ); 388 int lineitemtype = budget->getLineItemTime ( currentbudget, listview->selectedItem()->text ( 3 ).toInt() );
392 lineitemtime->setCurrentItem ( lineitemtype ); 389 lineitemtime->setCurrentItem ( lineitemtype );
393 390
394 // set the line item amount 391 // set the line item amount
395 float amount = budget->getLineItemAmount ( currentbudget, listview->selectedItem()->text ( 3 ).toInt() ); 392 float amount = budget->getLineItemAmount ( currentbudget, listview->selectedItem()->text ( 3 ).toInt() );
396 if ( lineitemtype == 1 ) 393 if ( lineitemtype == 1 )
397 amount = amount / 12; 394 amount = amount / 12;
398 else if ( lineitemtype == 2 ) 395 else if ( lineitemtype == 2 )
399 amount = amount / 52; 396 amount = amount / 52;
400 lineitemamount->setText ( QString::number ( amount ) ); 397 lineitemamount->setText ( QString::number ( amount ) );
401 398
402 int response = newlineitem->exec(); 399 int response = newlineitem->exec();
403 if ( response == 1 ) 400 if ( response == 1 )
404 { 401 {
405 float amount; 402 float amount;
406 if ( lineitemtime->currentItem() == 0 ) 403 if ( lineitemtime->currentItem() == 0 )
407 amount = lineitemamount->text().toFloat(); 404 amount = lineitemamount->text().toFloat();
408 else if ( lineitemtime->currentItem() == 1 ) 405 else if ( lineitemtime->currentItem() == 1 )
409 amount = lineitemamount->text().toFloat() * 12; 406 amount = lineitemamount->text().toFloat() * 12;
410 else 407 else
411 amount = lineitemamount->text().toFloat() * 52; 408 amount = lineitemamount->text().toFloat() * 52;
412 budget->updateLineItem ( lineitemname->text(), amount, lineitemtime->currentItem(), currentbudget, listview->selectedItem()->text ( 3 ).toInt() ); 409 budget->updateLineItem ( lineitemname->text(), amount, lineitemtime->currentItem(), currentbudget, listview->selectedItem()->text ( 3 ).toInt() );
413 displayLineItems(); 410 displayLineItems();
414 } 411 }
415 } 412 }
416 else 413 else
417 QMessageBox::warning ( this, "QashMoney", "Please select a line item to edit." ); 414 QMessageBox::warning ( this, "QashMoney", "Please select a line item to edit." );
418 } 415 }
419 416
420 417
diff --git a/noncore/apps/qashmoney/newaccount.cpp b/noncore/apps/qashmoney/newaccount.cpp
index 2ad8f60..7e57a18 100755
--- a/noncore/apps/qashmoney/newaccount.cpp
+++ b/noncore/apps/qashmoney/newaccount.cpp
@@ -1,209 +1,206 @@
1#include "newaccount.h" 1#include "newaccount.h"
2#include "calculator.h" 2#include "calculator.h"
3#include "datepicker.h" 3#include "datepicker.h"
4#include "transaction.h"
5#include "preferences.h"
6#include <qdatetime.h>
7#include <qmultilineedit.h> 4#include <qmultilineedit.h>
8 5
9extern Preferences *preferences; 6extern Preferences *preferences;
10 7
11NewAccount::NewAccount ( QWidget *parent, const char *name, bool modal ) : QDialog ( parent, name, modal ) 8NewAccount::NewAccount ( QWidget *parent, const char *name, bool modal ) : QDialog ( parent, name, modal )
12 { 9 {
13 accountdescription = ""; 10 accountdescription = "";
14 dateedited = FALSE; 11 dateedited = FALSE;
15 setCaption( tr( "Account" ) ); 12 setCaption( tr( "Account" ) );
16 13
17 namelabel = new QLabel ( "Account Name", this ); 14 namelabel = new QLabel ( "Account Name", this );
18 15
19 accountbox = new QHBox ( this ); 16 accountbox = new QHBox ( this );
20 accountname = new QLineEdit ( accountbox ); 17 accountname = new QLineEdit ( accountbox );
21 descriptionbutton = new QPushButton ( accountbox ); 18 descriptionbutton = new QPushButton ( accountbox );
22 descriptionbutton->setPixmap ( QPixmap ( "/opt/QtPalmtop/pics/info.png" ) ); 19 descriptionbutton->setPixmap ( QPixmap ( "/opt/QtPalmtop/pics/info.png" ) );
23 20
24 datelabel = new QLabel ( "Date", this ); 21 datelabel = new QLabel ( "Date", this );
25 22
26 datebox = new QHBox ( this ); 23 datebox = new QHBox ( this );
27 startdate = new QLineEdit ( datebox ); 24 startdate = new QLineEdit ( datebox );
28 startdate->setDisabled ( TRUE ); 25 startdate->setDisabled ( TRUE );
29 datebutton = new QPushButton ( datebox ); 26 datebutton = new QPushButton ( datebox );
30 datebutton->setPixmap ( QPixmap ( "/opt/QtPalmtop/pics/date.png" ) ); 27 datebutton->setPixmap ( QPixmap ( "/opt/QtPalmtop/pics/date.png" ) );
31 28
32 childcheckbox = new QCheckBox ( this ); 29 childcheckbox = new QCheckBox ( this );
33 childcheckbox->setText( tr ( "Child Account" ) ); 30 childcheckbox->setText( tr ( "Child Account" ) );
34 31
35 childlabel = new QLabel ( "Child of", this ); 32 childlabel = new QLabel ( "Child of", this );
36 childbox = new QComboBox ( FALSE, this ); 33 childbox = new QComboBox ( FALSE, this );
37 hideChildPulldownMenu (); 34 hideChildPulldownMenu ();
38 35
39 balancelabel = new QLabel ( "Balance", this ); 36 balancelabel = new QLabel ( "Balance", this );
40 37
41 balancebox = new QHBox ( this ); 38 balancebox = new QHBox ( this );
42 accountbalance = new QLineEdit ( balancebox ); 39 accountbalance = new QLineEdit ( balancebox );
43 accountbalance->setText ( "0.00" ); 40 accountbalance->setText ( "0.00" );
44 balancecalculator = new QPushButton( balancebox ); 41 balancecalculator = new QPushButton( balancebox );
45 balancecalculator->setPixmap ( QPixmap ( "/opt/QtPalmtop/pics/kcalc.png" ) ); 42 balancecalculator->setPixmap ( QPixmap ( "/opt/QtPalmtop/pics/kcalc.png" ) );
46 43
47 creditlimitlabel = new QLabel ( "Credit Limit", this ); 44 creditlimitlabel = new QLabel ( "Credit Limit", this );
48 45
49 creditlimitbox = new QHBox ( this ); 46 creditlimitbox = new QHBox ( this );
50 creditlimit = new QLineEdit ( creditlimitbox ); 47 creditlimit = new QLineEdit ( creditlimitbox );
51 creditlimitbox->setEnabled ( FALSE ); 48 creditlimitbox->setEnabled ( FALSE );
52 creditlimitcalculator = new QPushButton( creditlimitbox ); 49 creditlimitcalculator = new QPushButton( creditlimitbox );
53 creditlimitcalculator->setPixmap ( QPixmap ( "/opt/QtPalmtop/pics/kcalc.png" ) ); 50 creditlimitcalculator->setPixmap ( QPixmap ( "/opt/QtPalmtop/pics/kcalc.png" ) );
54 51
55 currencybox = new Currency ( this ); 52 currencybox = new Currency ( this );
56 53
57 typelabel = new QLabel ( "Type", this ); 54 typelabel = new QLabel ( "Type", this );
58 accounttype = new QComboBox ( FALSE, this ); 55 accounttype = new QComboBox ( FALSE, this );
59 accounttype->insertItem( tr( "Bank" ) ); 56 accounttype->insertItem( tr( "Bank" ) );
60 accounttype->insertItem( tr( "Cash" ) ); 57 accounttype->insertItem( tr( "Cash" ) );
61 accounttype->insertItem( tr( "Credit Card" ) ); 58 accounttype->insertItem( tr( "Credit Card" ) );
62 accounttype->insertItem( tr( "Equity" ) ); 59 accounttype->insertItem( tr( "Equity" ) );
63 accounttype->insertItem( tr( "Asset" ) ); 60 accounttype->insertItem( tr( "Asset" ) );
64 accounttype->insertItem( tr( "Liability" ) ); 61 accounttype->insertItem( tr( "Liability" ) );
65 62
66 layout = new QGridLayout ( this, 7, 2, 4, 2 ); 63 layout = new QGridLayout ( this, 7, 2, 4, 2 );
67 layout->addWidget ( namelabel , 0, 0, Qt::AlignLeft ); 64 layout->addWidget ( namelabel , 0, 0, Qt::AlignLeft );
68 layout->addWidget ( accountbox, 1, 0, Qt::AlignLeft ); 65 layout->addWidget ( accountbox, 1, 0, Qt::AlignLeft );
69 layout->addWidget ( datelabel, 2, 0, Qt::AlignLeft ); 66 layout->addWidget ( datelabel, 2, 0, Qt::AlignLeft );
70 layout->addWidget ( datebox, 3, 0, Qt::AlignLeft ); 67 layout->addWidget ( datebox, 3, 0, Qt::AlignLeft );
71 layout->addWidget ( childcheckbox, 4, 0, Qt::AlignLeft ); 68 layout->addWidget ( childcheckbox, 4, 0, Qt::AlignLeft );
72 layout->addWidget ( childlabel, 5, 0, Qt::AlignLeft ); 69 layout->addWidget ( childlabel, 5, 0, Qt::AlignLeft );
73 layout->addWidget ( childbox, 6, 0, Qt::AlignLeft ); 70 layout->addWidget ( childbox, 6, 0, Qt::AlignLeft );
74 layout->addWidget ( balancelabel, 0, 1, Qt::AlignLeft ); 71 layout->addWidget ( balancelabel, 0, 1, Qt::AlignLeft );
75 layout->addWidget ( balancebox, 1, 1, Qt::AlignLeft ); 72 layout->addWidget ( balancebox, 1, 1, Qt::AlignLeft );
76 layout->addWidget ( creditlimitlabel, 2, 1, Qt::AlignLeft ); 73 layout->addWidget ( creditlimitlabel, 2, 1, Qt::AlignLeft );
77 layout->addWidget ( creditlimitbox, 3, 1, Qt::AlignLeft ); 74 layout->addWidget ( creditlimitbox, 3, 1, Qt::AlignLeft );
78 layout->addWidget ( currencybox, 4, 1, Qt::AlignLeft ); 75 layout->addWidget ( currencybox, 4, 1, Qt::AlignLeft );
79 layout->addWidget ( typelabel, 5, 1, Qt::AlignLeft ); 76 layout->addWidget ( typelabel, 5, 1, Qt::AlignLeft );
80 layout->addWidget ( accounttype, 6, 1, Qt::AlignLeft ); 77 layout->addWidget ( accounttype, 6, 1, Qt::AlignLeft );
81 78
82 connect ( childcheckbox, SIGNAL ( clicked () ), this, SLOT ( showChildPulldownMenu() ) ); 79 connect ( childcheckbox, SIGNAL ( clicked () ), this, SLOT ( showChildPulldownMenu() ) );
83 connect ( balancecalculator, SIGNAL ( released() ), this, SLOT ( showCalculator() ) ); 80 connect ( balancecalculator, SIGNAL ( released() ), this, SLOT ( showCalculator() ) );
84 connect ( creditlimitcalculator, SIGNAL ( released() ), this, SLOT ( showCreditLimitCalculator() ) ); 81 connect ( creditlimitcalculator, SIGNAL ( released() ), this, SLOT ( showCreditLimitCalculator() ) );
85 connect ( accounttype, SIGNAL ( activated ( int ) ), this, SLOT ( activateCreditLimit ( int ) ) ); 82 connect ( accounttype, SIGNAL ( activated ( int ) ), this, SLOT ( activateCreditLimit ( int ) ) );
86 connect ( datebutton, SIGNAL ( released () ), this, SLOT ( showCalendar () ) ); 83 connect ( datebutton, SIGNAL ( released () ), this, SLOT ( showCalendar () ) );
87 connect ( descriptionbutton, SIGNAL ( released () ), this, SLOT ( addAccountDescription() ) ); 84 connect ( descriptionbutton, SIGNAL ( released () ), this, SLOT ( addAccountDescription() ) );
88} 85}
89 86
90NewAccount::~NewAccount () 87NewAccount::~NewAccount ()
91 { 88 {
92 } 89 }
93 90
94void NewAccount::showChildPulldownMenu () 91void NewAccount::showChildPulldownMenu ()
95 { 92 {
96 if ( childcheckbox->isChecked() == TRUE ) 93 if ( childcheckbox->isChecked() == TRUE )
97 { 94 {
98 childlabel->setEnabled ( TRUE ); 95 childlabel->setEnabled ( TRUE );
99 childbox->setEnabled ( TRUE ); 96 childbox->setEnabled ( TRUE );
100 } 97 }
101 else 98 else
102 hideChildPulldownMenu(); 99 hideChildPulldownMenu();
103 } 100 }
104 101
105void NewAccount::hideChildPulldownMenu () 102void NewAccount::hideChildPulldownMenu ()
106 { 103 {
107 childlabel->setEnabled ( FALSE ); 104 childlabel->setEnabled ( FALSE );
108 childbox->setEnabled ( FALSE ); 105 childbox->setEnabled ( FALSE );
109 } 106 }
110 107
111void NewAccount::showCalculator () 108void NewAccount::showCalculator ()
112 { 109 {
113 Calculator *calculator = new Calculator ( this ); 110 Calculator *calculator = new Calculator ( this );
114 calculator->setMaximumWidth ( ( int ) ( this->size().width() * 0.9 ) ); 111 calculator->setMaximumWidth ( ( int ) ( this->size().width() * 0.9 ) );
115 if ( calculator->exec () == QDialog::Accepted ) 112 if ( calculator->exec () == QDialog::Accepted )
116 accountbalance->setText ( calculator->display->text() ); 113 accountbalance->setText ( calculator->display->text() );
117 } 114 }
118 115
119void NewAccount::showCreditLimitCalculator () 116void NewAccount::showCreditLimitCalculator ()
120 { 117 {
121 Calculator *calculator = new Calculator ( this ); 118 Calculator *calculator = new Calculator ( this );
122 calculator->setMaximumWidth ( ( int ) ( this->size().width() * 0.9 ) ); 119 calculator->setMaximumWidth ( ( int ) ( this->size().width() * 0.9 ) );
123 if ( calculator->exec () == QDialog::Accepted ) 120 if ( calculator->exec () == QDialog::Accepted )
124 creditlimit->setText ( calculator->display->text() ); 121 creditlimit->setText ( calculator->display->text() );
125 } 122 }
126 123
127void NewAccount::activateCreditLimit ( int index ) 124void NewAccount::activateCreditLimit ( int index )
128 { 125 {
129 if ( index == 2 || index == 5 ) 126 if ( index == 2 || index == 5 )
130 creditlimitbox->setEnabled ( TRUE ); 127 creditlimitbox->setEnabled ( TRUE );
131 else 128 else
132 { 129 {
133 creditlimit->clear (); 130 creditlimit->clear ();
134 creditlimitbox->setEnabled ( FALSE ); 131 creditlimitbox->setEnabled ( FALSE );
135 } 132 }
136 } 133 }
137 134
138void NewAccount::showCalendar () 135void NewAccount::showCalendar ()
139 { 136 {
140 QDate newDate = QDate::currentDate (); 137 QDate newDate = QDate::currentDate ();
141 DatePicker *dp = new DatePicker ( newDate ); 138 DatePicker *dp = new DatePicker ( newDate );
142 dp->setMaximumWidth ( ( int ) ( this->size().width() * 0.9 ) ); 139 dp->setMaximumWidth ( ( int ) ( this->size().width() * 0.9 ) );
143 140
144 int response = dp->exec(); 141 int response = dp->exec();
145 if ( response == QDialog::Accepted ) 142 if ( response == QDialog::Accepted )
146 { 143 {
147 // Set date integers 144 // Set date integers
148 year = dp->getYear(); 145 year = dp->getYear();
149 month = dp->getMonth(); 146 month = dp->getMonth();
150 day = dp->getDay(); 147 day = dp->getDay();
151 148
152 // Set dateedited to TRUE 149 // Set dateedited to TRUE
153 // This tells the accountdisplay object that the user edited an account 150 // This tells the accountdisplay object that the user edited an account
154 // and did change the date 151 // and did change the date
155 dateedited = TRUE; 152 dateedited = TRUE;
156 153
157 // Display date with our selected format 154 // Display date with our selected format
158 startdate->setText ( preferences->getDate ( year, month, day ) ); 155 startdate->setText ( preferences->getDate ( year, month, day ) );
159 } 156 }
160 } 157 }
161 158
162bool NewAccount::getDateEdited () 159bool NewAccount::getDateEdited ()
163 { 160 {
164 return dateedited; 161 return dateedited;
165 } 162 }
166 163
167int NewAccount::getDay () 164int NewAccount::getDay ()
168 { 165 {
169 return day; 166 return day;
170 } 167 }
171 168
172int NewAccount::getMonth () 169int NewAccount::getMonth ()
173 { 170 {
174 return month; 171 return month;
175 } 172 }
176 173
177int NewAccount::getYear () 174int NewAccount::getYear ()
178 { 175 {
179 return year; 176 return year;
180 } 177 }
181 178
182QString NewAccount::getDescription () 179QString NewAccount::getDescription ()
183 { 180 {
184 return accountdescription; 181 return accountdescription;
185 } 182 }
186 183
187void NewAccount::setDescription ( QString description ) 184void NewAccount::setDescription ( QString description )
188 { 185 {
189 accountdescription = description; 186 accountdescription = description;
190 } 187 }
191 188
192void NewAccount::addAccountDescription () 189void NewAccount::addAccountDescription ()
193 { 190 {
194 // Function for adding or editing an account description. 191 // Function for adding or editing an account description.
195 QDialog *description = new QDialog ( this, "description", TRUE ); 192 QDialog *description = new QDialog ( this, "description", TRUE );
196 description->setCaption ( "Notes" ); 193 description->setCaption ( "Notes" );
197 QMultiLineEdit *enter = new QMultiLineEdit ( description ); 194 QMultiLineEdit *enter = new QMultiLineEdit ( description );
198 enter->setFixedSize ( ( int ) (this->width() * 0.75 ), ( int ) ( this->height() * 0.5 ) ); 195 enter->setFixedSize ( ( int ) (this->width() * 0.75 ), ( int ) ( this->height() * 0.5 ) );
199 enter->setWrapColumnOrWidth ( ( int ) (this->width() * 0.75 ) ); 196 enter->setWrapColumnOrWidth ( ( int ) (this->width() * 0.75 ) );
200 enter->setWordWrap ( QMultiLineEdit::WidgetWidth ); 197 enter->setWordWrap ( QMultiLineEdit::WidgetWidth );
201 if ( accountdescription != "(NULL)" ) 198 if ( accountdescription != "(NULL)" )
202 enter->setText ( accountdescription ); 199 enter->setText ( accountdescription );
203 if ( description->exec () == QDialog::Accepted ) 200 if ( description->exec () == QDialog::Accepted )
204 accountdescription = enter->text (); 201 accountdescription = enter->text ();
205 } 202 }
206 203
207 204
208 205
209 206
diff --git a/noncore/apps/qashmoney/newtransaction.cpp b/noncore/apps/qashmoney/newtransaction.cpp
index 630a8b8..5c78139 100755
--- a/noncore/apps/qashmoney/newtransaction.cpp
+++ b/noncore/apps/qashmoney/newtransaction.cpp
@@ -1,276 +1,274 @@
1#include "newtransaction.h" 1#include "newtransaction.h"
2#include "calculator.h" 2#include "calculator.h"
3#include "datepicker.h" 3#include "datepicker.h"
4#include "memory.h"
5#include "budget.h" 4#include "budget.h"
6 5
7#include <qdatetime.h>
8#include <qmultilineedit.h> 6#include <qmultilineedit.h>
9 7
10extern Budget *budget; 8extern Budget *budget;
11extern Preferences *preferences; 9extern Preferences *preferences;
12 10
13NewTransaction::NewTransaction ( QWidget* parent ) : QDialog ( parent, 0, TRUE ) 11NewTransaction::NewTransaction ( QWidget* parent ) : QDialog ( parent, 0, TRUE )
14 { 12 {
15 transactiondescription = ""; 13 transactiondescription = "";
16 currentlineitem = -1; 14 currentlineitem = -1;
17 currentbudget = -1; 15 currentbudget = -1;
18 dateedited = FALSE; 16 dateedited = FALSE;
19 setCaption( tr( "Transaction" ) ); 17 setCaption( tr( "Transaction" ) );
20 18
21 // START FIRST COLUMN 19 // START FIRST COLUMN
22 20
23 namelabel = new QLabel ( "Transaction", this ); 21 namelabel = new QLabel ( "Transaction", this );
24 22
25 transactionnamebox = new QHBox ( this ); 23 transactionnamebox = new QHBox ( this );
26 transactionname = new QComboBox ( transactionnamebox ); 24 transactionname = new QComboBox ( transactionnamebox );
27 transactionname->setEditable ( TRUE ); 25 transactionname->setEditable ( TRUE );
28 descriptionbutton = new QPushButton ( transactionnamebox ); 26 descriptionbutton = new QPushButton ( transactionnamebox );
29 descriptionbutton->setPixmap ( QPixmap ( "/opt/QtPalmtop/pics/info.png" ) ); 27 descriptionbutton->setPixmap ( QPixmap ( "/opt/QtPalmtop/pics/info.png" ) );
30 connect ( descriptionbutton, SIGNAL ( released () ), this, SLOT ( addTransactionDescription() ) ); 28 connect ( descriptionbutton, SIGNAL ( released () ), this, SLOT ( addTransactionDescription() ) );
31 29
32 amountlabel = new QLabel ( "Amount", this ); 30 amountlabel = new QLabel ( "Amount", this );
33 31
34 transactionamountbox = new QHBox ( this ); 32 transactionamountbox = new QHBox ( this );
35 transactionamount = new QLineEdit ( transactionamountbox ); 33 transactionamount = new QLineEdit ( transactionamountbox );
36 transactionamount->setAlignment ( Qt::AlignRight ); 34 transactionamount->setAlignment ( Qt::AlignRight );
37 transactionamount->setText ( "0.00" ); 35 transactionamount->setText ( "0.00" );
38 calculatorbutton = new QPushButton( transactionamountbox ); 36 calculatorbutton = new QPushButton( transactionamountbox );
39 calculatorbutton->setPixmap ( QPixmap ( "/opt/QtPalmtop/pics/kcalc.png" ) ); 37 calculatorbutton->setPixmap ( QPixmap ( "/opt/QtPalmtop/pics/kcalc.png" ) );
40 connect ( calculatorbutton, SIGNAL ( released() ), this, SLOT ( showCalculator() ) ); 38 connect ( calculatorbutton, SIGNAL ( released() ), this, SLOT ( showCalculator() ) );
41 39
42 datelabel = new QLabel ( "Date", this ); 40 datelabel = new QLabel ( "Date", this );
43 41
44 transactiondatebox = new QHBox ( this ); 42 transactiondatebox = new QHBox ( this );
45 transactiondate = new QLineEdit ( transactiondatebox ); 43 transactiondate = new QLineEdit ( transactiondatebox );
46 transactiondate->setAlignment ( Qt::AlignRight ); 44 transactiondate->setAlignment ( Qt::AlignRight );
47 transactiondate->setDisabled ( TRUE ); 45 transactiondate->setDisabled ( TRUE );
48 datebutton = new QPushButton( transactiondatebox ); 46 datebutton = new QPushButton( transactiondatebox );
49 datebutton->setPixmap ( QPixmap ( "/opt/QtPalmtop/pics/date.png" ) ); 47 datebutton->setPixmap ( QPixmap ( "/opt/QtPalmtop/pics/date.png" ) );
50 connect ( datebutton, SIGNAL ( released () ), this, SLOT ( showCalendar () ) ); 48 connect ( datebutton, SIGNAL ( released () ), this, SLOT ( showCalendar () ) );
51 49
52 clearedcheckbox = new QCheckBox ( "Cleared", this ); 50 clearedcheckbox = new QCheckBox ( "Cleared", this );
53 depositbox = new QCheckBox ( "Credit", this ); 51 depositbox = new QCheckBox ( "Credit", this );
54 52
55 // START SECOND COLUMN 53 // START SECOND COLUMN
56 54
57 numberlabel = new QLabel ( "Number", this ); 55 numberlabel = new QLabel ( "Number", this );
58 transactionnumber = new QLineEdit ( this ); 56 transactionnumber = new QLineEdit ( this );
59 57
60 budgetlabel = new QLabel ( "Budget", this ); 58 budgetlabel = new QLabel ( "Budget", this );
61 budgetbox = new QComboBox ( FALSE, this ); 59 budgetbox = new QComboBox ( FALSE, this );
62 60
63 lineitemlabel = new QLabel ( "LineItem", this ); 61 lineitemlabel = new QLabel ( "LineItem", this );
64 lineitembox = new QComboBox ( FALSE, this ); 62 lineitembox = new QComboBox ( FALSE, this );
65 63
66 layout = new QGridLayout ( this, 7, 2, 2, 2 ); 64 layout = new QGridLayout ( this, 7, 2, 2, 2 );
67 layout->addWidget ( namelabel, 0, 0, Qt::AlignLeft ); 65 layout->addWidget ( namelabel, 0, 0, Qt::AlignLeft );
68 layout->addWidget ( transactionnamebox, 1, 0, Qt::AlignLeft ); 66 layout->addWidget ( transactionnamebox, 1, 0, Qt::AlignLeft );
69 layout->addWidget ( amountlabel, 2, 0, Qt::AlignLeft ); 67 layout->addWidget ( amountlabel, 2, 0, Qt::AlignLeft );
70 layout->addWidget ( transactionamountbox, 3, 0, Qt::AlignLeft ); 68 layout->addWidget ( transactionamountbox, 3, 0, Qt::AlignLeft );
71 layout->addWidget ( datelabel, 4, 0, Qt::AlignLeft ); 69 layout->addWidget ( datelabel, 4, 0, Qt::AlignLeft );
72 layout->addWidget ( transactiondatebox, 5, 0, Qt::AlignLeft ); 70 layout->addWidget ( transactiondatebox, 5, 0, Qt::AlignLeft );
73 layout->addWidget ( clearedcheckbox, 6, 0, Qt::AlignLeft ); 71 layout->addWidget ( clearedcheckbox, 6, 0, Qt::AlignLeft );
74 layout->addWidget ( numberlabel, 0, 1, Qt::AlignLeft ); 72 layout->addWidget ( numberlabel, 0, 1, Qt::AlignLeft );
75 layout->addWidget ( transactionnumber, 1, 1, Qt::AlignLeft ); 73 layout->addWidget ( transactionnumber, 1, 1, Qt::AlignLeft );
76 layout->addWidget ( budgetlabel, 2, 1, Qt::AlignLeft ); 74 layout->addWidget ( budgetlabel, 2, 1, Qt::AlignLeft );
77 layout->addWidget ( budgetbox, 3, 1, Qt::AlignLeft ); 75 layout->addWidget ( budgetbox, 3, 1, Qt::AlignLeft );
78 layout->addWidget ( lineitemlabel, 4, 1, Qt::AlignLeft ); 76 layout->addWidget ( lineitemlabel, 4, 1, Qt::AlignLeft );
79 layout->addWidget ( lineitembox, 5, 1, Qt::AlignLeft ); 77 layout->addWidget ( lineitembox, 5, 1, Qt::AlignLeft );
80 layout->addWidget ( depositbox, 6, 1, Qt::AlignLeft ); 78 layout->addWidget ( depositbox, 6, 1, Qt::AlignLeft );
81 79
82 if ( budget->getNumberOfBudgets() != 0 ) 80 if ( budget->getNumberOfBudgets() != 0 )
83 { 81 {
84 budgetnameslist = budget->getBudgetNames(); 82 budgetnameslist = budget->getBudgetNames();
85 budgetidslist = budget->getBudgetIDs(); 83 budgetidslist = budget->getBudgetIDs();
86 budgetbox->insertStringList ( *budgetnameslist ); 84 budgetbox->insertStringList ( *budgetnameslist );
87 lineitemlabel->setEnabled ( FALSE ); 85 lineitemlabel->setEnabled ( FALSE );
88 lineitembox->setEnabled ( FALSE ); 86 lineitembox->setEnabled ( FALSE );
89 connect ( budgetbox, SIGNAL ( activated ( int ) ), this, SLOT ( setCurrentBudget ( int ) ) ); 87 connect ( budgetbox, SIGNAL ( activated ( int ) ), this, SLOT ( setCurrentBudget ( int ) ) );
90 connect ( lineitembox, SIGNAL ( activated ( int ) ), this, SLOT ( setCurrentLineItem ( int ) ) ); 88 connect ( lineitembox, SIGNAL ( activated ( int ) ), this, SLOT ( setCurrentLineItem ( int ) ) );
91 } 89 }
92 else 90 else
93 { 91 {
94 budgetlabel->setEnabled ( FALSE ); 92 budgetlabel->setEnabled ( FALSE );
95 budgetbox->setEnabled ( FALSE ); 93 budgetbox->setEnabled ( FALSE );
96 lineitemlabel->setEnabled ( FALSE ); 94 lineitemlabel->setEnabled ( FALSE );
97 lineitembox->setEnabled ( FALSE ); 95 lineitembox->setEnabled ( FALSE );
98 } 96 }
99 97
100} 98}
101 99
102NewTransaction::~NewTransaction () 100NewTransaction::~NewTransaction ()
103 { 101 {
104 } 102 }
105 103
106void NewTransaction::showCalculator () 104void NewTransaction::showCalculator ()
107{ 105{
108 Calculator *calculator = new Calculator ( this ); 106 Calculator *calculator = new Calculator ( this );
109 calculator->setMaximumWidth ( ( int ) ( this->size().width() * 0.9 ) ); 107 calculator->setMaximumWidth ( ( int ) ( this->size().width() * 0.9 ) );
110 if ( calculator->exec () == QDialog::Accepted ) 108 if ( calculator->exec () == QDialog::Accepted )
111 transactionamount->setText ( calculator->display->text() ); 109 transactionamount->setText ( calculator->display->text() );
112} 110}
113 111
114void NewTransaction::showCalendar () 112void NewTransaction::showCalendar ()
115 { 113 {
116 QDate newDate = QDate::currentDate (); 114 QDate newDate = QDate::currentDate ();
117 DatePicker *dp = new DatePicker ( newDate ); 115 DatePicker *dp = new DatePicker ( newDate );
118 dp->setMaximumWidth ( ( int ) ( this->size().width() * 0.9 ) ); 116 dp->setMaximumWidth ( ( int ) ( this->size().width() * 0.9 ) );
119 117
120 int response = dp->exec(); 118 int response = dp->exec();
121 if ( response == QDialog::Accepted ) 119 if ( response == QDialog::Accepted )
122 { 120 {
123 // Set date integers 121 // Set date integers
124 year = dp->getYear(); 122 year = dp->getYear();
125 month = dp->getMonth(); 123 month = dp->getMonth();
126 day = dp->getDay(); 124 day = dp->getDay();
127 125
128 // Set dateedited to TRUE 126 // Set dateedited to TRUE
129 // This tells the transactiondisplay object that the user edited an transaction 127 // This tells the transactiondisplay object that the user edited an transaction
130 // and did change the date3 128 // and did change the date3
131 dateedited = TRUE; 129 dateedited = TRUE;
132 130
133 // Display date with our selected format 131 // Display date with our selected format
134 transactiondate->setText ( preferences->getDate ( year, month, day ) ); 132 transactiondate->setText ( preferences->getDate ( year, month, day ) );
135 } 133 }
136 } 134 }
137 135
138bool NewTransaction::getDateEdited () 136bool NewTransaction::getDateEdited ()
139 { 137 {
140 return dateedited; 138 return dateedited;
141 } 139 }
142 140
143int NewTransaction::getDay () 141int NewTransaction::getDay ()
144 { 142 {
145 return day; 143 return day;
146 } 144 }
147 145
148int NewTransaction::getMonth () 146int NewTransaction::getMonth ()
149 { 147 {
150 return month; 148 return month;
151 } 149 }
152 150
153int NewTransaction::getYear () 151int NewTransaction::getYear ()
154 { 152 {
155 return year; 153 return year;
156 } 154 }
157 155
158QString NewTransaction::getDescription () 156QString NewTransaction::getDescription ()
159 { 157 {
160 return transactiondescription; 158 return transactiondescription;
161 } 159 }
162 160
163void NewTransaction::setDescription ( QString description ) 161void NewTransaction::setDescription ( QString description )
164 { 162 {
165 transactiondescription = description; 163 transactiondescription = description;
166 } 164 }
167 165
168void NewTransaction::addTransactionDescription () 166void NewTransaction::addTransactionDescription ()
169 { 167 {
170 // Function for adding or editing an transaction description. 168 // Function for adding or editing an transaction description.
171 QDialog *description = new QDialog ( this, "description", TRUE ); 169 QDialog *description = new QDialog ( this, "description", TRUE );
172 description->setCaption ( "Notes" ); 170 description->setCaption ( "Notes" );
173 QMultiLineEdit *enter = new QMultiLineEdit ( description ); 171 QMultiLineEdit *enter = new QMultiLineEdit ( description );
174 enter->setFixedSize ( ( int ) (this->width() * 0.75 ), ( int ) ( this->height() * 0.5 ) ); 172 enter->setFixedSize ( ( int ) (this->width() * 0.75 ), ( int ) ( this->height() * 0.5 ) );
175 enter->setWrapColumnOrWidth ( ( int ) (this->width() * 0.75 ) ); 173 enter->setWrapColumnOrWidth ( ( int ) (this->width() * 0.75 ) );
176 enter->setWordWrap ( QMultiLineEdit::WidgetWidth ); 174 enter->setWordWrap ( QMultiLineEdit::WidgetWidth );
177 if ( transactiondescription != "(NULL)" ) 175 if ( transactiondescription != "(NULL)" )
178 enter->setText ( transactiondescription ); 176 enter->setText ( transactiondescription );
179 if ( description->exec () == QDialog::Accepted ) 177 if ( description->exec () == QDialog::Accepted )
180 transactiondescription = enter->text (); 178 transactiondescription = enter->text ();
181 } 179 }
182 180
183int NewTransaction::getNameIndex ( QString name ) 181int NewTransaction::getNameIndex ( QString name )
184 { 182 {
185 int counter; 183 int counter;
186 int items = transactionname->count(); 184 int items = transactionname->count();
187 for ( counter = 0; ( items - 1 ); counter++ ) 185 for ( counter = 0; ( items - 1 ); counter++ )
188 { 186 {
189 if ( name == transactionname->text ( counter ) ) 187 if ( name == transactionname->text ( counter ) )
190 { 188 {
191 return counter; 189 return counter;
192 break; 190 break;
193 } 191 }
194 } 192 }
195 return 0; 193 return 0;
196 } 194 }
197 195
198void NewTransaction::setCurrentBudget ( int index ) 196void NewTransaction::setCurrentBudget ( int index )
199 { 197 {
200 if ( index != 0 ) 198 if ( index != 0 )
201 { 199 {
202 currentbudget = budgetidslist->operator[] ( index - 1 ).toInt(); 200 currentbudget = budgetidslist->operator[] ( index - 1 ).toInt();
203 lineitemslist = budget->getLineItems ( currentbudget ); 201 lineitemslist = budget->getLineItems ( currentbudget );
204 lineitemidslist = budget->getLineItemIDs ( currentbudget ); 202 lineitemidslist = budget->getLineItemIDs ( currentbudget );
205 lineitemlabel->setEnabled ( TRUE ); 203 lineitemlabel->setEnabled ( TRUE );
206 lineitembox->setEnabled ( TRUE ); 204 lineitembox->setEnabled ( TRUE );
207 lineitembox->clear(); 205 lineitembox->clear();
208 lineitembox->insertStringList ( lineitemslist ); 206 lineitembox->insertStringList ( lineitemslist );
209 setCurrentLineItem ( 0 ); 207 setCurrentLineItem ( 0 );
210 } 208 }
211 else 209 else
212 { 210 {
213 lineitembox->clear(); 211 lineitembox->clear();
214 lineitemlabel->setEnabled ( FALSE ); 212 lineitemlabel->setEnabled ( FALSE );
215 lineitembox->setEnabled ( FALSE ); 213 lineitembox->setEnabled ( FALSE );
216 currentlineitem = -1; 214 currentlineitem = -1;
217 currentbudget = -1; 215 currentbudget = -1;
218 } 216 }
219 } 217 }
220 218
221void NewTransaction::setCurrentLineItem ( int index ) 219void NewTransaction::setCurrentLineItem ( int index )
222 { 220 {
223 currentlineitem = ( lineitemidslist.operator[] ( index ).toInt() ); 221 currentlineitem = ( lineitemidslist.operator[] ( index ).toInt() );
224 } 222 }
225 223
226int NewTransaction::getCurrentBudget () 224int NewTransaction::getCurrentBudget ()
227 { 225 {
228 return currentbudget; 226 return currentbudget;
229 } 227 }
230 228
231int NewTransaction::getBudgetIndex ( int budgetid ) 229int NewTransaction::getBudgetIndex ( int budgetid )
232 { 230 {
233 currentbudget = budgetid; 231 currentbudget = budgetid;
234 const QString budget = QString::number ( budgetid ); 232 const QString budget = QString::number ( budgetid );
235 return budgetidslist->findIndex ( budget ); 233 return budgetidslist->findIndex ( budget );
236 } 234 }
237 235
238int NewTransaction::getLineItemIndex ( int lineitemid ) 236int NewTransaction::getLineItemIndex ( int lineitemid )
239 { 237 {
240 currentlineitem = lineitemid; 238 currentlineitem = lineitemid;
241 const QString lineitem = QString::number ( lineitemid ); 239 const QString lineitem = QString::number ( lineitemid );
242 return lineitemidslist.findIndex ( lineitem ); 240 return lineitemidslist.findIndex ( lineitem );
243 } 241 }
244 242
245void NewTransaction::setLineItems () 243void NewTransaction::setLineItems ()
246 { 244 {
247 lineitemslist = budget->getLineItems ( currentbudget ); 245 lineitemslist = budget->getLineItems ( currentbudget );
248 lineitemidslist = budget->getLineItemIDs ( currentbudget ); 246 lineitemidslist = budget->getLineItemIDs ( currentbudget );
249 lineitemlabel->setEnabled ( TRUE ); 247 lineitemlabel->setEnabled ( TRUE );
250 lineitembox->setEnabled ( TRUE ); 248 lineitembox->setEnabled ( TRUE );
251 lineitembox->clear(); 249 lineitembox->clear();
252 lineitembox->insertStringList ( lineitemslist ); 250 lineitembox->insertStringList ( lineitemslist );
253 } 251 }
254 252
255int NewTransaction::getCurrentLineItem () 253int NewTransaction::getCurrentLineItem ()
256 { 254 {
257 return currentlineitem; 255 return currentlineitem;
258 } 256 }
259 257
260void NewTransaction::setComboBoxes ( int budgetid, int lineitemid ) 258void NewTransaction::setComboBoxes ( int budgetid, int lineitemid )
261 { 259 {
262 const QString budgetname = QString::number ( budgetid ); 260 const QString budgetname = QString::number ( budgetid );
263 budgetbox->setCurrentItem ( ( budgetidslist->findIndex ( budgetname ) ) ); 261 budgetbox->setCurrentItem ( ( budgetidslist->findIndex ( budgetname ) ) );
264 currentbudget = budgetidslist->operator[] ( budgetbox->currentItem() - 1 ).toInt(); 262 currentbudget = budgetidslist->operator[] ( budgetbox->currentItem() - 1 ).toInt();
265 263
266 lineitemslist = budget->getLineItems ( currentbudget ); 264 lineitemslist = budget->getLineItems ( currentbudget );
267 lineitemidslist = budget->getLineItemIDs ( currentbudget ); 265 lineitemidslist = budget->getLineItemIDs ( currentbudget );
268 lineitemlabel->setEnabled ( TRUE ); 266 lineitemlabel->setEnabled ( TRUE );
269 lineitembox->setEnabled ( TRUE ); 267 lineitembox->setEnabled ( TRUE );
270 lineitembox->clear(); 268 lineitembox->clear();
271 lineitembox->insertStringList ( lineitemslist ); 269 lineitembox->insertStringList ( lineitemslist );
272 270
273 const QString lineitem = QString::number ( lineitemid ); 271 const QString lineitem = QString::number ( lineitemid );
274 lineitembox->setCurrentItem ( lineitemidslist.findIndex ( lineitem ) ); 272 lineitembox->setCurrentItem ( lineitemidslist.findIndex ( lineitem ) );
275 currentlineitem = ( lineitemidslist.operator[] ( lineitembox->currentItem() ).toInt() ); 273 currentlineitem = ( lineitemidslist.operator[] ( lineitembox->currentItem() ).toInt() );
276 } 274 }
diff --git a/noncore/apps/qashmoney/preferencedialogs.cpp b/noncore/apps/qashmoney/preferencedialogs.cpp
index d7c66d3..5408a5b 100755
--- a/noncore/apps/qashmoney/preferencedialogs.cpp
+++ b/noncore/apps/qashmoney/preferencedialogs.cpp
@@ -1,217 +1,216 @@
1#include "preferencedialogs.h" 1#include "preferencedialogs.h"
2#include "preferences.h" 2#include "preferences.h"
3#include <qlabel.h>
4 3
5extern Preferences *preferences; 4extern Preferences *preferences;
6 5
7DatePreferences::DatePreferences ( QWidget* parent ) : QDialog ( parent, 0, TRUE ) 6DatePreferences::DatePreferences ( QWidget* parent ) : QDialog ( parent, 0, TRUE )
8 { 7 {
9 setCaption( tr( "Date" ) ); 8 setCaption( tr( "Date" ) );
10 9
11 QLabel *datelabel = new QLabel ( "Format", this ); 10 QLabel *datelabel = new QLabel ( "Format", this );
12 dateformat = new QComboBox ( this ); 11 dateformat = new QComboBox ( this );
13 dateformat->setEditable ( FALSE ); 12 dateformat->setEditable ( FALSE );
14 dateformat->insertItem ( "yyyymmdd" ); 13 dateformat->insertItem ( "yyyymmdd" );
15 dateformat->insertItem ( "yymmdd" ); 14 dateformat->insertItem ( "yymmdd" );
16 dateformat->insertItem ( "mmddyyyy" ); 15 dateformat->insertItem ( "mmddyyyy" );
17 dateformat->insertItem ( "mmddyy" ); 16 dateformat->insertItem ( "mmddyy" );
18 dateformat->insertItem ( "yyyyddmm" ); 17 dateformat->insertItem ( "yyyyddmm" );
19 dateformat->insertItem ( "yyddmm" ); 18 dateformat->insertItem ( "yyddmm" );
20 dateformat->insertItem ( "ddmmyyyy" ); 19 dateformat->insertItem ( "ddmmyyyy" );
21 dateformat->insertItem ( "ddmmyy" ); 20 dateformat->insertItem ( "ddmmyy" );
22 connect ( dateformat, SIGNAL ( activated ( int ) ), this, SLOT ( changeDateFormat ( int ) ) ); 21 connect ( dateformat, SIGNAL ( activated ( int ) ), this, SLOT ( changeDateFormat ( int ) ) );
23 22
24 QLabel *dateseparatorlabel = new QLabel ( "Separator", this ); 23 QLabel *dateseparatorlabel = new QLabel ( "Separator", this );
25 dateseparator = new QComboBox ( this ); 24 dateseparator = new QComboBox ( this );
26 dateseparator->insertItem ( "/" ); 25 dateseparator->insertItem ( "/" );
27 dateseparator->insertItem ( "-" ); 26 dateseparator->insertItem ( "-" );
28 dateseparator->insertItem ( "." ); 27 dateseparator->insertItem ( "." );
29 connect ( dateseparator, SIGNAL ( activated ( int ) ), this, SLOT ( changeDateSeparator ( int ) ) ); 28 connect ( dateseparator, SIGNAL ( activated ( int ) ), this, SLOT ( changeDateSeparator ( int ) ) );
30 29
31 defaults = new QPushButton ( QPixmap ( "/opt/QtPalmtop/pics/defaults.png" ), "Defaults", this ); 30 defaults = new QPushButton ( QPixmap ( "/opt/QtPalmtop/pics/defaults.png" ), "Defaults", this );
32 connect ( defaults, SIGNAL ( released () ), this, SLOT ( setDefaultDatePreferences () ) ); 31 connect ( defaults, SIGNAL ( released () ), this, SLOT ( setDefaultDatePreferences () ) );
33 32
34 dateformat->setCurrentItem ( ( preferences->getPreference ( 1 ) ) - 1 ); 33 dateformat->setCurrentItem ( ( preferences->getPreference ( 1 ) ) - 1 );
35 dateseparator->setCurrentItem ( ( preferences->getPreference ( 2 ) ) - 1 ); 34 dateseparator->setCurrentItem ( ( preferences->getPreference ( 2 ) ) - 1 );
36 35
37 layout = new QVBoxLayout ( this, 2, 2 ); 36 layout = new QVBoxLayout ( this, 2, 2 );
38 layout->addWidget ( datelabel ); 37 layout->addWidget ( datelabel );
39 layout->addWidget ( dateformat ); 38 layout->addWidget ( dateformat );
40 layout->addWidget ( dateseparatorlabel ); 39 layout->addWidget ( dateseparatorlabel );
41 layout->addWidget ( dateseparator ); 40 layout->addWidget ( dateseparator );
42 layout->insertSpacing ( 4, 5 ); 41 layout->insertSpacing ( 4, 5 );
43 layout->addWidget ( defaults ); 42 layout->addWidget ( defaults );
44 43
45 } 44 }
46 45
47DatePreferences::~DatePreferences () 46DatePreferences::~DatePreferences ()
48 { 47 {
49 } 48 }
50 49
51void DatePreferences::changeDateFormat ( int index ) 50void DatePreferences::changeDateFormat ( int index )
52 { 51 {
53 index ++; 52 index ++;
54 preferences->changePreference ( 1, index ); 53 preferences->changePreference ( 1, index );
55 } 54 }
56 55
57void DatePreferences::changeDateSeparator ( int index ) 56void DatePreferences::changeDateSeparator ( int index )
58 { 57 {
59 index ++; 58 index ++;
60 preferences->changePreference ( 2, index ); 59 preferences->changePreference ( 2, index );
61 } 60 }
62 61
63void DatePreferences::setDefaultDatePreferences () 62void DatePreferences::setDefaultDatePreferences ()
64 { 63 {
65 preferences->setDefaultDatePreferences (); 64 preferences->setDefaultDatePreferences ();
66 dateformat->setCurrentItem ( ( preferences->getPreference ( 1 ) ) - 1 ); 65 dateformat->setCurrentItem ( ( preferences->getPreference ( 1 ) ) - 1 );
67 dateseparator->setCurrentItem ( ( preferences->getPreference ( 2 ) ) - 1 ); 66 dateseparator->setCurrentItem ( ( preferences->getPreference ( 2 ) ) - 1 );
68 } 67 }
69 68
70// START TRANSACTION PREFERENCES 69// START TRANSACTION PREFERENCES
71 70
72TransactionPreferences::TransactionPreferences ( QWidget* parent ) : QDialog ( parent, 0, TRUE ) 71TransactionPreferences::TransactionPreferences ( QWidget* parent ) : QDialog ( parent, 0, TRUE )
73{ 72{
74 setCaption( tr ( "Transaction" ) ); 73 setCaption( tr ( "Transaction" ) );
75 74
76 showclearedtransactions = new QCheckBox ( this ); 75 showclearedtransactions = new QCheckBox ( this );
77 showclearedtransactions->setText ( "Show Cleared Transactions" ); 76 showclearedtransactions->setText ( "Show Cleared Transactions" );
78 77
79 limittransactionsbox = new QHBox ( this ); 78 limittransactionsbox = new QHBox ( this );
80 limittransactionsbox->setSpacing ( 2 ); 79 limittransactionsbox->setSpacing ( 2 );
81 limittransactionslabel = new QLabel ( "Show ", limittransactionsbox ); 80 limittransactionslabel = new QLabel ( "Show ", limittransactionsbox );
82 limittransactions = new QComboBox ( limittransactionsbox ); 81 limittransactions = new QComboBox ( limittransactionsbox );
83 QLabel *limittransactionslabel2 = new QLabel ( "of cleared transactions. ", limittransactionsbox ); 82 QLabel *limittransactionslabel2 = new QLabel ( "of cleared transactions. ", limittransactionsbox );
84 limittransactions->insertItem ( "14 days" ); 83 limittransactions->insertItem ( "14 days" );
85 limittransactions->insertItem ( "30 days" ); 84 limittransactions->insertItem ( "30 days" );
86 limittransactions->insertItem ( "90 days" ); 85 limittransactions->insertItem ( "90 days" );
87 limittransactions->insertItem ( "180 days" ); 86 limittransactions->insertItem ( "180 days" );
88 limittransactions->insertItem ( "365 days" ); 87 limittransactions->insertItem ( "365 days" );
89 limittransactions->insertItem ( "All" ); 88 limittransactions->insertItem ( "All" );
90 limittransactions->setCurrentItem ( preferences->getPreference ( 7 ) ); 89 limittransactions->setCurrentItem ( preferences->getPreference ( 7 ) );
91 90
92 excludetransfers = new QCheckBox ( this ); 91 excludetransfers = new QCheckBox ( this );
93 excludetransfers->setText ( "Include Transfers In Limit View" ); 92 excludetransfers->setText ( "Include Transfers In Limit View" );
94 93
95 if ( preferences->getPreference ( 3 ) == 1 ) 94 if ( preferences->getPreference ( 3 ) == 1 )
96 showclearedtransactions->setChecked ( TRUE ); 95 showclearedtransactions->setChecked ( TRUE );
97 else 96 else
98 showclearedtransactions->setChecked ( FALSE ); 97 showclearedtransactions->setChecked ( FALSE );
99 98
100 if ( preferences->getPreference ( 6 ) == 1 ) 99 if ( preferences->getPreference ( 6 ) == 1 )
101 excludetransfers->setChecked ( TRUE ); 100 excludetransfers->setChecked ( TRUE );
102 else 101 else
103 excludetransfers->setChecked ( FALSE ); 102 excludetransfers->setChecked ( FALSE );
104 103
105 defaults = new QPushButton ( QPixmap ( "/opt/QtPalmtop/pics/defaults.png" ), "Defaults", this ); 104 defaults = new QPushButton ( QPixmap ( "/opt/QtPalmtop/pics/defaults.png" ), "Defaults", this );
106 connect ( defaults, SIGNAL ( released () ), this, SLOT ( setDefaultTransactionPreferences () ) ); 105 connect ( defaults, SIGNAL ( released () ), this, SLOT ( setDefaultTransactionPreferences () ) );
107 106
108 layout = new QVBoxLayout ( this, 2, 2 ); 107 layout = new QVBoxLayout ( this, 2, 2 );
109 layout->addWidget ( showclearedtransactions ); 108 layout->addWidget ( showclearedtransactions );
110 layout->addWidget ( limittransactionsbox ); 109 layout->addWidget ( limittransactionsbox );
111 layout->addWidget ( excludetransfers ); 110 layout->addWidget ( excludetransfers );
112 layout->insertSpacing ( 3, 5 ); 111 layout->insertSpacing ( 3, 5 );
113 layout->addWidget ( defaults ); 112 layout->addWidget ( defaults );
114 113
115 connect ( showclearedtransactions, SIGNAL ( toggled ( bool ) ), this, SLOT ( changeShowClearedPreference ( bool ) ) ); 114 connect ( showclearedtransactions, SIGNAL ( toggled ( bool ) ), this, SLOT ( changeShowClearedPreference ( bool ) ) );
116 connect ( excludetransfers, SIGNAL ( toggled ( bool ) ), this, SLOT ( changeExcludeTranfersPreference ( bool ) ) ); 115 connect ( excludetransfers, SIGNAL ( toggled ( bool ) ), this, SLOT ( changeExcludeTranfersPreference ( bool ) ) );
117 connect ( limittransactions, SIGNAL ( activated ( int ) ), this, SLOT ( changeLimitTransactionsPreference ( int ) ) ); 116 connect ( limittransactions, SIGNAL ( activated ( int ) ), this, SLOT ( changeLimitTransactionsPreference ( int ) ) );
118} 117}
119 118
120TransactionPreferences::~TransactionPreferences () 119TransactionPreferences::~TransactionPreferences ()
121 { 120 {
122 } 121 }
123 122
124void TransactionPreferences::changeLimitTransactionsPreference ( int pref ) 123void TransactionPreferences::changeLimitTransactionsPreference ( int pref )
125 { 124 {
126 preferences->changePreference ( 7, pref ); 125 preferences->changePreference ( 7, pref );
127 } 126 }
128 127
129void TransactionPreferences::changeShowClearedPreference ( bool state ) 128void TransactionPreferences::changeShowClearedPreference ( bool state )
130 { 129 {
131 if ( state == TRUE ) 130 if ( state == TRUE )
132 preferences->changePreference ( 3, 1 ); 131 preferences->changePreference ( 3, 1 );
133 else 132 else
134 preferences->changePreference ( 3, 0 ); 133 preferences->changePreference ( 3, 0 );
135 } 134 }
136 135
137void TransactionPreferences::changeExcludeTranfersPreference ( bool state ) 136void TransactionPreferences::changeExcludeTranfersPreference ( bool state )
138 { 137 {
139 if ( state == TRUE ) 138 if ( state == TRUE )
140 preferences->changePreference ( 6, 1 ); 139 preferences->changePreference ( 6, 1 );
141 else 140 else
142 preferences->changePreference ( 6, 0 ); 141 preferences->changePreference ( 6, 0 );
143 } 142 }
144 143
145void TransactionPreferences::setDefaultTransactionPreferences () 144void TransactionPreferences::setDefaultTransactionPreferences ()
146 { 145 {
147 preferences->changePreference ( 3, 0 ); 146 preferences->changePreference ( 3, 0 );
148 preferences->changePreference ( 6, 0 ); 147 preferences->changePreference ( 6, 0 );
149 preferences->changePreference ( 7, 0 ); 148 preferences->changePreference ( 7, 0 );
150 showclearedtransactions->setChecked ( FALSE ); 149 showclearedtransactions->setChecked ( FALSE );
151 limittransactions->setCurrentItem ( 0 ); 150 limittransactions->setCurrentItem ( 0 );
152 } 151 }
153 152
154// START ACCOUNT PREFERNCES 153// START ACCOUNT PREFERNCES
155 154
156AccountPreferences::AccountPreferences ( QWidget* parent ) : QDialog ( parent, 0, TRUE ) 155AccountPreferences::AccountPreferences ( QWidget* parent ) : QDialog ( parent, 0, TRUE )
157{ 156{
158 157
159 setCaption( tr ( "Account" ) ); 158 setCaption( tr ( "Account" ) );
160 159
161 currencysupport = new QCheckBox ( this ); 160 currencysupport = new QCheckBox ( this );
162 currencysupport->setText ( "Enable Currency Support" ); 161 currencysupport->setText ( "Enable Currency Support" );
163 162
164 onetouch = new QCheckBox ( this ); 163 onetouch = new QCheckBox ( this );
165 onetouch->setText ( "One Touch Account Viewing" ); 164 onetouch->setText ( "One Touch Account Viewing" );
166 165
167 if ( preferences->getPreference ( 4 ) == 1 ) 166 if ( preferences->getPreference ( 4 ) == 1 )
168 currencysupport->setChecked ( TRUE ); 167 currencysupport->setChecked ( TRUE );
169 else 168 else
170 currencysupport->setChecked ( FALSE ); 169 currencysupport->setChecked ( FALSE );
171 170
172 if ( preferences->getPreference ( 5 ) == 1 ) 171 if ( preferences->getPreference ( 5 ) == 1 )
173 onetouch->setChecked ( TRUE ); 172 onetouch->setChecked ( TRUE );
174 else 173 else
175 onetouch->setChecked ( FALSE ); 174 onetouch->setChecked ( FALSE );
176 175
177 defaults = new QPushButton ( QPixmap ( "/opt/QtPalmtop/pics/defaults.png" ), "Defaults", this ); 176 defaults = new QPushButton ( QPixmap ( "/opt/QtPalmtop/pics/defaults.png" ), "Defaults", this );
178 connect ( defaults, SIGNAL ( released () ), this, SLOT ( setDefaultAccountPreferences () ) ); 177 connect ( defaults, SIGNAL ( released () ), this, SLOT ( setDefaultAccountPreferences () ) );
179 178
180 layout = new QVBoxLayout ( this, 2, 2 ); 179 layout = new QVBoxLayout ( this, 2, 2 );
181 layout->addWidget ( currencysupport ); 180 layout->addWidget ( currencysupport );
182 layout->addWidget ( onetouch ); 181 layout->addWidget ( onetouch );
183 layout->insertSpacing ( 2, 5 ); 182 layout->insertSpacing ( 2, 5 );
184 layout->addWidget ( defaults ); 183 layout->addWidget ( defaults );
185 184
186 connect ( currencysupport, SIGNAL ( toggled ( bool ) ), this, SLOT ( changeCurrencySupport ( bool ) ) ); 185 connect ( currencysupport, SIGNAL ( toggled ( bool ) ), this, SLOT ( changeCurrencySupport ( bool ) ) );
187 connect ( onetouch, SIGNAL ( toggled ( bool ) ), this, SLOT ( changeOneTouchViewing ( bool ) ) ); 186 connect ( onetouch, SIGNAL ( toggled ( bool ) ), this, SLOT ( changeOneTouchViewing ( bool ) ) );
188} 187}
189 188
190AccountPreferences::~AccountPreferences () 189AccountPreferences::~AccountPreferences ()
191 { 190 {
192 } 191 }
193 192
194void AccountPreferences::changeCurrencySupport ( bool state ) 193void AccountPreferences::changeCurrencySupport ( bool state )
195 { 194 {
196 if ( state == TRUE ) 195 if ( state == TRUE )
197 preferences->changePreference ( 4, 1 ); 196 preferences->changePreference ( 4, 1 );
198 else 197 else
199 preferences->changePreference ( 4, 0 ); 198 preferences->changePreference ( 4, 0 );
200 } 199 }
201 200
202void AccountPreferences::changeOneTouchViewing ( bool state ) 201void AccountPreferences::changeOneTouchViewing ( bool state )
203 { 202 {
204 if ( state == TRUE ) 203 if ( state == TRUE )
205 preferences->changePreference ( 5, 1 ); 204 preferences->changePreference ( 5, 1 );
206 else 205 else
207 preferences->changePreference ( 5, 0 ); 206 preferences->changePreference ( 5, 0 );
208 } 207 }
209 208
210void AccountPreferences::setDefaultAccountPreferences () 209void AccountPreferences::setDefaultAccountPreferences ()
211 { 210 {
212 preferences->changePreference ( 4, 0 ); 211 preferences->changePreference ( 4, 0 );
213 preferences->changePreference ( 5, 0 ); 212 preferences->changePreference ( 5, 0 );
214 currencysupport->setChecked ( FALSE ); 213 currencysupport->setChecked ( FALSE );
215 onetouch->setChecked ( FALSE ); 214 onetouch->setChecked ( FALSE );
216 } 215 }
217 216
diff --git a/noncore/apps/qashmoney/transactiondisplay.cpp b/noncore/apps/qashmoney/transactiondisplay.cpp
index 78b8a00..474f11e 100755
--- a/noncore/apps/qashmoney/transactiondisplay.cpp
+++ b/noncore/apps/qashmoney/transactiondisplay.cpp
@@ -1,628 +1,625 @@
1#include "transactiondisplay.h" 1#include "transactiondisplay.h"
2#include "newtransaction.h" 2#include "newtransaction.h"
3#include "account.h" 3#include "account.h"
4#include "budget.h" 4#include "budget.h"
5#include "memory.h" 5#include "memory.h"
6#include "transfer.h" 6#include "transfer.h"
7#include "preferences.h"
8#include "calculator.h" 7#include "calculator.h"
9#include "datepicker.h" 8#include "datepicker.h"
10 9
11#include <qdatetime.h>
12#include <qmessagebox.h> 10#include <qmessagebox.h>
13#include <qheader.h> 11#include <qheader.h>
14#include <qmultilineedit.h> 12#include <qmultilineedit.h>
15#include <qdatetime.h>
16 13
17extern Transaction *transaction; 14extern Transaction *transaction;
18extern Budget *budget; 15extern Budget *budget;
19extern Account *account; 16extern Account *account;
20extern Preferences *preferences; 17extern Preferences *preferences;
21extern Memory *memory; 18extern Memory *memory;
22extern Transfer *transfer; 19extern Transfer *transfer;
23 20
24TransactionDisplay::TransactionDisplay ( QWidget* parent ) : QWidget ( parent ) 21TransactionDisplay::TransactionDisplay ( QWidget* parent ) : QWidget ( parent )
25 { 22 {
26 // set transactiondisplay variables; 23 // set transactiondisplay variables;
27 accountid = 0; 24 accountid = 0;
28 children = TRUE; 25 children = TRUE;
29 26
30 firstline = new QHBox ( this ); 27 firstline = new QHBox ( this );
31 firstline->setSpacing ( 2 ); 28 firstline->setSpacing ( 2 );
32 29
33 newtransaction = new QPushButton ( firstline ); 30 newtransaction = new QPushButton ( firstline );
34 newtransaction->setPixmap ( QPixmap ("/opt/QtPalmtop/pics/new.png") ); 31 newtransaction->setPixmap ( QPixmap ("/opt/QtPalmtop/pics/new.png") );
35 connect ( newtransaction, SIGNAL ( released () ), this, SLOT ( addTransaction () ) ); 32 connect ( newtransaction, SIGNAL ( released () ), this, SLOT ( addTransaction () ) );
36 33
37 edittransaction = new QPushButton ( firstline ); 34 edittransaction = new QPushButton ( firstline );
38 edittransaction->setPixmap( QPixmap ("/opt/QtPalmtop/pics/edit.png") ); 35 edittransaction->setPixmap( QPixmap ("/opt/QtPalmtop/pics/edit.png") );
39 connect ( edittransaction, SIGNAL ( released () ), this, SLOT ( checkListViewEdit () ) ); 36 connect ( edittransaction, SIGNAL ( released () ), this, SLOT ( checkListViewEdit () ) );
40 37
41 deletetransaction = new QPushButton ( firstline ); 38 deletetransaction = new QPushButton ( firstline );
42 deletetransaction->setPixmap( QPixmap ( "/opt/QtPalmtop/pics/delete.png") ); 39 deletetransaction->setPixmap( QPixmap ( "/opt/QtPalmtop/pics/delete.png") );
43 connect ( deletetransaction, SIGNAL ( released () ), this, SLOT ( checkListViewDelete () ) ); 40 connect ( deletetransaction, SIGNAL ( released () ), this, SLOT ( checkListViewDelete () ) );
44 41
45 toggletransaction = new QPushButton ( firstline ); 42 toggletransaction = new QPushButton ( firstline );
46 toggletransaction->setPixmap( QPixmap ( "/opt/QtPalmtop/pics/redo.png") ); 43 toggletransaction->setPixmap( QPixmap ( "/opt/QtPalmtop/pics/redo.png") );
47 connect ( toggletransaction, SIGNAL ( released () ), this, SLOT ( checkListViewToggle () ) ); 44 connect ( toggletransaction, SIGNAL ( released () ), this, SLOT ( checkListViewToggle () ) );
48 45
49 viewtransactionnotes = new QPushButton ( firstline ); 46 viewtransactionnotes = new QPushButton ( firstline );
50 viewtransactionnotes->setPixmap( QPixmap ( "/opt/QtPalmtop/pics/info.png") ); 47 viewtransactionnotes->setPixmap( QPixmap ( "/opt/QtPalmtop/pics/info.png") );
51 connect ( viewtransactionnotes, SIGNAL ( released () ), this, SLOT ( showTransactionNotes () ) ); 48 connect ( viewtransactionnotes, SIGNAL ( released () ), this, SLOT ( showTransactionNotes () ) );
52 49
53 secondline = new QHBox ( this ); 50 secondline = new QHBox ( this );
54 secondline->setSpacing ( 5 ); 51 secondline->setSpacing ( 5 );
55 52
56 name = new QLabel ( secondline ); 53 name = new QLabel ( secondline );
57 balance = new QLabel ( secondline ); 54 balance = new QLabel ( secondline );
58 55
59 QLabel *limit = new QLabel ( "Limit", secondline ); 56 QLabel *limit = new QLabel ( "Limit", secondline );
60 limitbox = new QLineEdit ( secondline ); 57 limitbox = new QLineEdit ( secondline );
61 limitbox->setMinimumWidth ( ( int ) ( this->width() / 6 ) ); 58 limitbox->setMinimumWidth ( ( int ) ( this->width() / 6 ) );
62 connect ( limitbox, SIGNAL ( textChanged ( const QString & ) ), this, SLOT ( limitDisplay ( const QString & ) ) ); 59 connect ( limitbox, SIGNAL ( textChanged ( const QString & ) ), this, SLOT ( limitDisplay ( const QString & ) ) );
63 60
64 listview = new QListView ( this ); 61 listview = new QListView ( this );
65 listview->setAllColumnsShowFocus ( TRUE ); 62 listview->setAllColumnsShowFocus ( TRUE );
66 listview->setShowSortIndicator ( TRUE ); 63 listview->setShowSortIndicator ( TRUE );
67 listview->header()->setTracking ( FALSE ); 64 listview->header()->setTracking ( FALSE );
68 connect ( listview->header(), SIGNAL ( sizeChange ( int, int, int ) ), this, SLOT ( saveColumnSize ( int, int, int ) ) ); 65 connect ( listview->header(), SIGNAL ( sizeChange ( int, int, int ) ), this, SLOT ( saveColumnSize ( int, int, int ) ) );
69 connect ( listview->header(), SIGNAL ( clicked ( int ) ), this, SLOT ( saveSortingPreference ( int ) ) ); 66 connect ( listview->header(), SIGNAL ( clicked ( int ) ), this, SLOT ( saveSortingPreference ( int ) ) );
70 67
71 layout = new QVBoxLayout ( this, 2, 2 ); 68 layout = new QVBoxLayout ( this, 2, 2 );
72 layout->addWidget ( firstline ); 69 layout->addWidget ( firstline );
73 layout->addWidget ( secondline ); 70 layout->addWidget ( secondline );
74 layout->addWidget ( listview ); 71 layout->addWidget ( listview );
75 } 72 }
76 73
77void TransactionDisplay::addTransaction () 74void TransactionDisplay::addTransaction ()
78 { 75 {
79 // create local variables 76 // create local variables
80 int cleared = -1; 77 int cleared = -1;
81 78
82 // create new transaction window 79 // create new transaction window
83 NewTransaction *newtransaction = new NewTransaction ( this ); 80 NewTransaction *newtransaction = new NewTransaction ( this );
84 int width = this->size().width(); 81 int width = this->size().width();
85 newtransaction->transactionname->setMaximumWidth ( ( int ) ( width * 0.45 ) ); 82 newtransaction->transactionname->setMaximumWidth ( ( int ) ( width * 0.45 ) );
86 newtransaction->transactionname->setMinimumWidth ( ( int ) ( width * 0.35 ) ); 83 newtransaction->transactionname->setMinimumWidth ( ( int ) ( width * 0.35 ) );
87 newtransaction->lineitembox->setMaximumWidth ( ( int ) ( width * 0.45 ) ); 84 newtransaction->lineitembox->setMaximumWidth ( ( int ) ( width * 0.45 ) );
88 newtransaction->transactiondatebox->setMaximumWidth ( ( int ) ( width * 0.4 ) ); 85 newtransaction->transactiondatebox->setMaximumWidth ( ( int ) ( width * 0.4 ) );
89 newtransaction->transactionamountbox->setMaximumWidth ( ( int ) ( width * 0.4 ) ); 86 newtransaction->transactionamountbox->setMaximumWidth ( ( int ) ( width * 0.4 ) );
90 newtransaction->transactionnumber->setMaximumWidth ( ( int ) ( width * 0.25 ) ); 87 newtransaction->transactionnumber->setMaximumWidth ( ( int ) ( width * 0.25 ) );
91 88
92 // enter today's date in the date box as defaul 89 // enter today's date in the date box as defaul
93 QDate today = QDate::currentDate (); 90 QDate today = QDate::currentDate ();
94 int defaultday = today.day(); 91 int defaultday = today.day();
95 int defaultmonth = today.month(); 92 int defaultmonth = today.month();
96 int defaultyear = today.year(); 93 int defaultyear = today.year();
97 newtransaction->transactiondate->setText ( preferences->getDate ( defaultyear, defaultmonth, defaultday ) ); 94 newtransaction->transactiondate->setText ( preferences->getDate ( defaultyear, defaultmonth, defaultday ) );
98 95
99 // add memory items to the transactionname combobox 96 // add memory items to the transactionname combobox
100 memory->displayMemoryItems ( newtransaction->transactionname ); 97 memory->displayMemoryItems ( newtransaction->transactionname );
101 newtransaction->transactionname->insertItem ( "", 0 ); 98 newtransaction->transactionname->insertItem ( "", 0 );
102 99
103 if ( newtransaction->exec () == QDialog::Accepted ) 100 if ( newtransaction->exec () == QDialog::Accepted )
104 { 101 {
105 if ( newtransaction->clearedcheckbox->isChecked () == TRUE ) // set a parent id and type for a child transaction 102 if ( newtransaction->clearedcheckbox->isChecked () == TRUE ) // set a parent id and type for a child transaction
106 cleared = 1; 103 cleared = 1;
107 else 104 else
108 cleared = 0; 105 cleared = 0;
109 106
110 float amount = newtransaction->transactionamount->text().toFloat(); 107 float amount = newtransaction->transactionamount->text().toFloat();
111 if ( newtransaction->depositbox->isChecked() == FALSE ) 108 if ( newtransaction->depositbox->isChecked() == FALSE )
112 amount = amount * -1; 109 amount = amount * -1;
113 110
114 // add the transaction name to the memory items 111 // add the transaction name to the memory items
115 memory->addMemoryItem ( newtransaction->transactionname->currentText() ); 112 memory->addMemoryItem ( newtransaction->transactionname->currentText() );
116 113
117 // add the transaction 114 // add the transaction
118 if ( newtransaction->getDateEdited () == TRUE ) 115 if ( newtransaction->getDateEdited () == TRUE )
119 transaction->addTransaction ( newtransaction->getDescription(), newtransaction->transactionname->currentText(), accountid, account->getParentAccountID ( accountid ), 116 transaction->addTransaction ( newtransaction->getDescription(), newtransaction->transactionname->currentText(), accountid, account->getParentAccountID ( accountid ),
120 newtransaction->transactionnumber->text().toInt(), newtransaction->getDay(), newtransaction->getMonth(), newtransaction->getYear(), amount, cleared, newtransaction->getCurrentBudget(), 117 newtransaction->transactionnumber->text().toInt(), newtransaction->getDay(), newtransaction->getMonth(), newtransaction->getYear(), amount, cleared, newtransaction->getCurrentBudget(),
121 newtransaction->getCurrentLineItem() ); 118 newtransaction->getCurrentLineItem() );
122 else 119 else
123 transaction->addTransaction ( newtransaction->getDescription(), newtransaction->transactionname->currentText(), accountid, account->getParentAccountID ( accountid ), 120 transaction->addTransaction ( newtransaction->getDescription(), newtransaction->transactionname->currentText(), accountid, account->getParentAccountID ( accountid ),
124 newtransaction->transactionnumber->text().toInt(), defaultday, defaultmonth, defaultyear, amount, cleared, newtransaction->getCurrentBudget(), newtransaction->getCurrentLineItem() ); 121 newtransaction->transactionnumber->text().toInt(), defaultday, defaultmonth, defaultyear, amount, cleared, newtransaction->getCurrentBudget(), newtransaction->getCurrentLineItem() );
125 122
126 // redisplay transactions 123 // redisplay transactions
127 listview->clear(); 124 listview->clear();
128 QString displaytext = "%"; 125 QString displaytext = "%";
129 displaytext.prepend ( limitbox->text() ); 126 displaytext.prepend ( limitbox->text() );
130 setTransactionDisplayDate (); 127 setTransactionDisplayDate ();
131 if ( transaction->getNumberOfTransactions() > 0 ) 128 if ( transaction->getNumberOfTransactions() > 0 )
132 transaction->displayTransactions ( listview, accountid, children, displaytext, displaydate ); 129 transaction->displayTransactions ( listview, accountid, children, displaytext, displaydate );
133 130
134 // redisplay transfers 131 // redisplay transfers
135 if ( transfer->getNumberOfTransfers() > 0 ) 132 if ( transfer->getNumberOfTransfers() > 0 )
136 transfer->displayTransfers ( listview, accountid, children, displaydate ); 133 transfer->displayTransfers ( listview, accountid, children, displaydate );
137 134
138 // add the transaction amount to the account it's associated with 135 // add the transaction amount to the account it's associated with
139 // and update its parent account balance if necessary 136 // and update its parent account balance if necessary
140 account->updateAccountBalance ( accountid ); 137 account->updateAccountBalance ( accountid );
141 if ( account->getParentAccountID ( accountid ) != -1 ) 138 if ( account->getParentAccountID ( accountid ) != -1 )
142 account->changeParentAccountBalance ( account->getParentAccountID ( accountid ) ); 139 account->changeParentAccountBalance ( account->getParentAccountID ( accountid ) );
143 140
144 // format then reset the account balance 141 // format then reset the account balance
145 redisplayAccountBalance (); 142 redisplayAccountBalance ();
146 } 143 }
147 } 144 }
148 145
149void TransactionDisplay::checkListViewEdit () 146void TransactionDisplay::checkListViewEdit ()
150 { 147 {
151 if ( listview->selectedItem() == 0 ) 148 if ( listview->selectedItem() == 0 )
152 QMessageBox::warning ( this, "QashMoney", "Please select a transaction\nto edit."); 149 QMessageBox::warning ( this, "QashMoney", "Please select a transaction\nto edit.");
153 else if ( listview->currentItem()->text ( getIDColumn() ).toInt() < 0 ) 150 else if ( listview->currentItem()->text ( getIDColumn() ).toInt() < 0 )
154 editTransfer (); 151 editTransfer ();
155 else 152 else
156 editTransaction(); 153 editTransaction();
157 } 154 }
158 155
159void TransactionDisplay::showCalculator () 156void TransactionDisplay::showCalculator ()
160 { 157 {
161 Calculator *calculator = new Calculator ( this ); 158 Calculator *calculator = new Calculator ( this );
162 if ( calculator->exec () == QDialog::Accepted ) 159 if ( calculator->exec () == QDialog::Accepted )
163 amount->setText ( calculator->display->text() ); 160 amount->setText ( calculator->display->text() );
164 } 161 }
165 162
166void TransactionDisplay::showCalendar () 163void TransactionDisplay::showCalendar ()
167 { 164 {
168 QDate newDate = QDate::currentDate (); 165 QDate newDate = QDate::currentDate ();
169 DatePicker *dp = new DatePicker ( newDate ); 166 DatePicker *dp = new DatePicker ( newDate );
170 if ( dp->exec () == QDialog::Accepted ) 167 if ( dp->exec () == QDialog::Accepted )
171 { 168 {
172 year = dp->getYear(); 169 year = dp->getYear();
173 month = dp->getMonth(); 170 month = dp->getMonth();
174 day = dp->getDay(); 171 day = dp->getDay();
175 date->setText ( preferences->getDate ( year, month, day ) ); 172 date->setText ( preferences->getDate ( year, month, day ) );
176 } 173 }
177 } 174 }
178 175
179void TransactionDisplay::editTransfer () 176void TransactionDisplay::editTransfer ()
180 { 177 {
181 transferid = listview->currentItem()->text ( getIDColumn() ).toInt(); 178 transferid = listview->currentItem()->text ( getIDColumn() ).toInt();
182 fromaccount = transfer->getFromAccountID ( transferid ); 179 fromaccount = transfer->getFromAccountID ( transferid );
183 toaccount = transfer->getToAccountID ( transferid ); 180 toaccount = transfer->getToAccountID ( transferid );
184 year = transfer->getYear ( transferid ); 181 year = transfer->getYear ( transferid );
185 month = transfer->getMonth ( transferid ); 182 month = transfer->getMonth ( transferid );
186 day = transfer->getDay ( transferid ); 183 day = transfer->getDay ( transferid );
187 184
188 QDialog *editransfer = new QDialog ( this, "edittransfer", TRUE ); 185 QDialog *editransfer = new QDialog ( this, "edittransfer", TRUE );
189 editransfer->setCaption ( "Transfer" ); 186 editransfer->setCaption ( "Transfer" );
190 187
191 QStringList accountnames = account->getAccountNames(); 188 QStringList accountnames = account->getAccountNames();
192 QStringList accountids = account->getAccountIDs(); 189 QStringList accountids = account->getAccountIDs();
193 190
194 QLabel *fromaccountlabel = new QLabel ( "From Account:", editransfer ); 191 QLabel *fromaccountlabel = new QLabel ( "From Account:", editransfer );
195 QFont f = this->font(); 192 QFont f = this->font();
196 f.setWeight ( QFont::Bold ); 193 f.setWeight ( QFont::Bold );
197 fromaccountlabel->setFont ( f ); 194 fromaccountlabel->setFont ( f );
198 195
199 QComboBox *fromaccountbox = new QComboBox ( editransfer ); 196 QComboBox *fromaccountbox = new QComboBox ( editransfer );
200 fromaccountbox->insertStringList ( accountnames ); 197 fromaccountbox->insertStringList ( accountnames );
201 fromaccountbox->setCurrentItem ( accountids.findIndex ( QString::number ( fromaccount ) ) ); 198 fromaccountbox->setCurrentItem ( accountids.findIndex ( QString::number ( fromaccount ) ) );
202 199
203 QLabel *toaccountlabel = new QLabel ( "To Account:", editransfer ); 200 QLabel *toaccountlabel = new QLabel ( "To Account:", editransfer );
204 toaccountlabel->setFont ( f ); 201 toaccountlabel->setFont ( f );
205 202
206 QComboBox *toaccountbox = new QComboBox ( editransfer ); 203 QComboBox *toaccountbox = new QComboBox ( editransfer );
207 toaccountbox->insertStringList ( accountnames ); 204 toaccountbox->insertStringList ( accountnames );
208 toaccountbox->setCurrentItem ( accountids.findIndex ( QString::number ( toaccount ) ) ); 205 toaccountbox->setCurrentItem ( accountids.findIndex ( QString::number ( toaccount ) ) );
209 206
210 QLabel *datelabel = new QLabel ( "Date", editransfer ); 207 QLabel *datelabel = new QLabel ( "Date", editransfer );
211 QHBox *datebox = new QHBox ( editransfer ); 208 QHBox *datebox = new QHBox ( editransfer );
212 datebox->setSpacing ( 2 ); 209 datebox->setSpacing ( 2 );
213 date = new QLineEdit ( datebox ); 210 date = new QLineEdit ( datebox );
214 date->setAlignment ( Qt::AlignRight ); 211 date->setAlignment ( Qt::AlignRight );
215 date->setDisabled ( TRUE ); 212 date->setDisabled ( TRUE );
216 date->setText ( preferences->getDate ( year, month, day ) ); 213 date->setText ( preferences->getDate ( year, month, day ) );
217 QPushButton *datebutton = new QPushButton ( datebox ); 214 QPushButton *datebutton = new QPushButton ( datebox );
218 datebutton->setPixmap ( QPixmap ( "/opt/QtPalmtop/pics/date.png" ) ); 215 datebutton->setPixmap ( QPixmap ( "/opt/QtPalmtop/pics/date.png" ) );
219 connect ( datebutton, SIGNAL ( released () ), this, SLOT ( showCalendar () ) ); 216 connect ( datebutton, SIGNAL ( released () ), this, SLOT ( showCalendar () ) );
220 217
221 QLabel *amounttlabel = new QLabel ( "Amount", editransfer ); 218 QLabel *amounttlabel = new QLabel ( "Amount", editransfer );
222 219
223 QHBox *amountbox = new QHBox ( editransfer ); 220 QHBox *amountbox = new QHBox ( editransfer );
224 amountbox->setSpacing ( 2 ); 221 amountbox->setSpacing ( 2 );
225 amount = new QLineEdit ( amountbox ); 222 amount = new QLineEdit ( amountbox );
226 amount->setAlignment ( Qt::AlignRight ); 223 amount->setAlignment ( Qt::AlignRight );
227 amount->setText ( transfer->getAmount ( transferid ) ); 224 amount->setText ( transfer->getAmount ( transferid ) );
228 QPushButton *calculatorbutton = new QPushButton( amountbox ); 225 QPushButton *calculatorbutton = new QPushButton( amountbox );
229 calculatorbutton->setPixmap ( QPixmap ( "/opt/QtPalmtop/pics/kcalc.png" ) ); 226 calculatorbutton->setPixmap ( QPixmap ( "/opt/QtPalmtop/pics/kcalc.png" ) );
230 connect ( calculatorbutton, SIGNAL ( released() ), this, SLOT ( showCalculator() ) ); 227 connect ( calculatorbutton, SIGNAL ( released() ), this, SLOT ( showCalculator() ) );
231 228
232 QCheckBox *clearedcheckbox = new QCheckBox ( "Cleared", editransfer ); 229 QCheckBox *clearedcheckbox = new QCheckBox ( "Cleared", editransfer );
233 230
234 QBoxLayout *layout = new QVBoxLayout ( editransfer, 4, 2 ); 231 QBoxLayout *layout = new QVBoxLayout ( editransfer, 4, 2 );
235 layout->addWidget ( fromaccountlabel, Qt::AlignLeft ); 232 layout->addWidget ( fromaccountlabel, Qt::AlignLeft );
236 layout->addWidget ( fromaccountbox, Qt::AlignLeft ); 233 layout->addWidget ( fromaccountbox, Qt::AlignLeft );
237 layout->addWidget ( toaccountlabel, Qt::AlignLeft ); 234 layout->addWidget ( toaccountlabel, Qt::AlignLeft );
238 layout->addWidget ( toaccountbox, Qt::AlignLeft ); 235 layout->addWidget ( toaccountbox, Qt::AlignLeft );
239 layout->addSpacing ( 5 ); 236 layout->addSpacing ( 5 );
240 layout->addWidget ( datelabel, Qt::AlignLeft ); 237 layout->addWidget ( datelabel, Qt::AlignLeft );
241 layout->addWidget ( datebox, Qt::AlignLeft ); 238 layout->addWidget ( datebox, Qt::AlignLeft );
242 layout->addWidget ( amounttlabel, Qt::AlignLeft ); 239 layout->addWidget ( amounttlabel, Qt::AlignLeft );
243 layout->addWidget ( amountbox, Qt::AlignLeft ); 240 layout->addWidget ( amountbox, Qt::AlignLeft );
244 layout->addWidget ( clearedcheckbox, Qt::AlignLeft ); 241 layout->addWidget ( clearedcheckbox, Qt::AlignLeft );
245 242
246 if ( editransfer->exec() == QDialog::Accepted ) 243 if ( editransfer->exec() == QDialog::Accepted )
247 { 244 {
248 //get fromaccount 245 //get fromaccount
249 fromaccount = ( accountids.operator[] ( fromaccountbox->currentItem() ) ).toInt(); 246 fromaccount = ( accountids.operator[] ( fromaccountbox->currentItem() ) ).toInt();
250 247
251 //get to account 248 //get to account
252 toaccount = ( accountids.operator[] ( toaccountbox->currentItem() ) ).toInt(); 249 toaccount = ( accountids.operator[] ( toaccountbox->currentItem() ) ).toInt();
253 250
254 //set cleared flag 251 //set cleared flag
255 int cleared = 0; 252 int cleared = 0;
256 if ( clearedcheckbox->isChecked() == TRUE ) 253 if ( clearedcheckbox->isChecked() == TRUE )
257 cleared = 1; 254 cleared = 1;
258 255
259 //update transfer 256 //update transfer
260 transfer->updateTransfer ( fromaccount, account->getParentAccountID ( fromaccount ), toaccount, account->getParentAccountID ( toaccount ), 257 transfer->updateTransfer ( fromaccount, account->getParentAccountID ( fromaccount ), toaccount, account->getParentAccountID ( toaccount ),
261 day, month, year, amount->text().toFloat(), cleared, transferid ); 258 day, month, year, amount->text().toFloat(), cleared, transferid );
262 259
263 account->updateAccountBalance ( fromaccount ); 260 account->updateAccountBalance ( fromaccount );
264 if ( account->getParentAccountID ( fromaccount ) != -1 ) 261 if ( account->getParentAccountID ( fromaccount ) != -1 )
265 account->changeParentAccountBalance ( account->getParentAccountID ( fromaccount ) ); 262 account->changeParentAccountBalance ( account->getParentAccountID ( fromaccount ) );
266 263
267 updateAndDisplay ( toaccount ); 264 updateAndDisplay ( toaccount );
268 } 265 }
269 } 266 }
270 267
271void TransactionDisplay::editTransaction () 268void TransactionDisplay::editTransaction ()
272 { 269 {
273 int cleared; 270 int cleared;
274 271
275 // set the transaction id and budgetid 272 // set the transaction id and budgetid
276 int transactionid = listview->currentItem()->text ( getIDColumn() ).toInt(); 273 int transactionid = listview->currentItem()->text ( getIDColumn() ).toInt();
277 int budgetid = transaction->getBudgetID ( transactionid ); 274 int budgetid = transaction->getBudgetID ( transactionid );
278 int lineitemid = transaction->getLineItemID ( transactionid ); 275 int lineitemid = transaction->getLineItemID ( transactionid );
279 276
280 // create edit transaction window 277 // create edit transaction window
281 NewTransaction *newtransaction = new NewTransaction ( this ); 278 NewTransaction *newtransaction = new NewTransaction ( this );
282 int width = this->width(); 279 int width = this->width();
283 newtransaction->transactionname->setMaximumWidth ( ( int ) ( width * 0.45 ) ); 280 newtransaction->transactionname->setMaximumWidth ( ( int ) ( width * 0.45 ) );
284 newtransaction->transactionname->setMinimumWidth ( ( int ) ( width * 0.35 ) ); 281 newtransaction->transactionname->setMinimumWidth ( ( int ) ( width * 0.35 ) );
285 newtransaction->lineitembox->setMaximumWidth ( ( int ) ( width * 0.45 ) ); 282 newtransaction->lineitembox->setMaximumWidth ( ( int ) ( width * 0.45 ) );
286 newtransaction->transactiondatebox->setMaximumWidth ( ( int ) ( width * 0.4 ) ); 283 newtransaction->transactiondatebox->setMaximumWidth ( ( int ) ( width * 0.4 ) );
287 newtransaction->transactionamountbox->setMaximumWidth ( ( int ) ( width * 0.4 ) ); 284 newtransaction->transactionamountbox->setMaximumWidth ( ( int ) ( width * 0.4 ) );
288 newtransaction->transactionnumber->setMaximumWidth ( ( int ) ( width * 0.25 ) ); 285 newtransaction->transactionnumber->setMaximumWidth ( ( int ) ( width * 0.25 ) );
289 286
290 // enter the date in the date box 287 // enter the date in the date box
291 newtransaction->year = transaction->getYear ( transactionid ); 288 newtransaction->year = transaction->getYear ( transactionid );
292 newtransaction->month = transaction->getMonth ( transactionid ); 289 newtransaction->month = transaction->getMonth ( transactionid );
293 newtransaction->day = transaction->getDay ( transactionid ); 290 newtransaction->day = transaction->getDay ( transactionid );
294 newtransaction->transactiondate->setText ( preferences->getDate ( newtransaction->year, newtransaction->month, newtransaction->day ) ); 291 newtransaction->transactiondate->setText ( preferences->getDate ( newtransaction->year, newtransaction->month, newtransaction->day ) );
295 292
296 // set the description 293 // set the description
297 newtransaction->setDescription ( transaction->getTransactionDescription ( transactionid ) ); 294 newtransaction->setDescription ( transaction->getTransactionDescription ( transactionid ) );
298 295
299 // add memory items to the transactionname combobox 296 // add memory items to the transactionname combobox
300 memory->displayMemoryItems ( newtransaction->transactionname ); 297 memory->displayMemoryItems ( newtransaction->transactionname );
301 298
302 // add correct transaction name 299 // add correct transaction name
303 newtransaction->transactionname->setEditText ( transaction->getPayee ( transactionid ) ); 300 newtransaction->transactionname->setEditText ( transaction->getPayee ( transactionid ) );
304 301
305 // add transaction number 302 // add transaction number
306 newtransaction->transactionnumber->setText ( transaction->getNumber ( transactionid ) ); 303 newtransaction->transactionnumber->setText ( transaction->getNumber ( transactionid ) );
307 304
308 // add transaction amount 305 // add transaction amount
309 newtransaction->transactionamount->setText ( transaction->getAbsoluteAmount ( transactionid ) ); 306 newtransaction->transactionamount->setText ( transaction->getAbsoluteAmount ( transactionid ) );
310 307
311 // check for and set the correct budget 308 // check for and set the correct budget
312 if ( budgetid >= 1 ) // only do it if this transaction has a budget and line item 309 if ( budgetid >= 1 ) // only do it if this transaction has a budget and line item
313 { 310 {
314 newtransaction->budgetbox->setCurrentItem ( newtransaction->getBudgetIndex ( budgetid ) + 1 ); 311 newtransaction->budgetbox->setCurrentItem ( newtransaction->getBudgetIndex ( budgetid ) + 1 );
315 if ( lineitemid >= 1 ) 312 if ( lineitemid >= 1 )
316 { 313 {
317 newtransaction->setLineItems (); 314 newtransaction->setLineItems ();
318 newtransaction->lineitembox->setCurrentItem ( newtransaction->getLineItemIndex ( lineitemid ) ); 315 newtransaction->lineitembox->setCurrentItem ( newtransaction->getLineItemIndex ( lineitemid ) );
319 } 316 }
320 else 317 else
321 { 318 {
322 newtransaction->lineitemlabel->setEnabled ( FALSE ); 319 newtransaction->lineitemlabel->setEnabled ( FALSE );
323 newtransaction->lineitembox->setEnabled ( FALSE ); 320 newtransaction->lineitembox->setEnabled ( FALSE );
324 } 321 }
325 } 322 }
326 else 323 else
327 { 324 {
328 newtransaction->lineitemlabel->setEnabled ( FALSE ); 325 newtransaction->lineitemlabel->setEnabled ( FALSE );
329 newtransaction->lineitembox->setEnabled ( FALSE ); 326 newtransaction->lineitembox->setEnabled ( FALSE );
330 } 327 }
331 328
332 // check cleared checkbox if necessary 329 // check cleared checkbox if necessary
333 if ( transaction->getCleared ( transactionid ) == 1 ) 330 if ( transaction->getCleared ( transactionid ) == 1 )
334 newtransaction->clearedcheckbox->setChecked ( TRUE ); 331 newtransaction->clearedcheckbox->setChecked ( TRUE );
335 332
336 // check deposit box if necessary 333 // check deposit box if necessary
337 if ( transaction->getAmount ( transactionid ).toFloat() > 0 ) 334 if ( transaction->getAmount ( transactionid ).toFloat() > 0 )
338 newtransaction->depositbox->setChecked ( TRUE ); 335 newtransaction->depositbox->setChecked ( TRUE );
339 336
340 if ( newtransaction->exec () == QDialog::Accepted ) 337 if ( newtransaction->exec () == QDialog::Accepted )
341 { 338 {
342 if ( newtransaction->clearedcheckbox->isChecked () == TRUE ) 339 if ( newtransaction->clearedcheckbox->isChecked () == TRUE )
343 cleared = 1; 340 cleared = 1;
344 else 341 else
345 cleared = 0; 342 cleared = 0;
346 343
347 float amount = newtransaction->transactionamount->text().toFloat(); 344 float amount = newtransaction->transactionamount->text().toFloat();
348 if ( newtransaction->depositbox->isChecked() == FALSE ) 345 if ( newtransaction->depositbox->isChecked() == FALSE )
349 amount = amount * -1; 346 amount = amount * -1;
350 347
351 // add the transaction name to the memory items 348 // add the transaction name to the memory items
352 memory->addMemoryItem ( newtransaction->transactionname->currentText() ); 349 memory->addMemoryItem ( newtransaction->transactionname->currentText() );
353 350
354 // update the transaction 351 // update the transaction
355 transaction->updateTransaction ( newtransaction->getDescription(), newtransaction->transactionname->currentText(), newtransaction->transactionnumber->text().toInt(), 352 transaction->updateTransaction ( newtransaction->getDescription(), newtransaction->transactionname->currentText(), newtransaction->transactionnumber->text().toInt(),
356 newtransaction->getDay(), newtransaction->getMonth(), newtransaction->getYear(), 353 newtransaction->getDay(), newtransaction->getMonth(), newtransaction->getYear(),
357 amount, cleared, newtransaction->getCurrentBudget(), newtransaction->getCurrentLineItem(), transactionid ); 354 amount, cleared, newtransaction->getCurrentBudget(), newtransaction->getCurrentLineItem(), transactionid );
358 355
359 updateAndDisplay ( transaction->getAccountID ( transactionid ) ); 356 updateAndDisplay ( transaction->getAccountID ( transactionid ) );
360 } 357 }
361 } 358 }
362 359
363void TransactionDisplay::updateAndDisplay ( int id ) 360void TransactionDisplay::updateAndDisplay ( int id )
364 { 361 {
365 // redisplay transactions 362 // redisplay transactions
366 listview->clear(); 363 listview->clear();
367 QString displaytext = "%"; 364 QString displaytext = "%";
368 displaytext.prepend ( limitbox->text() ); 365 displaytext.prepend ( limitbox->text() );
369 setTransactionDisplayDate (); 366 setTransactionDisplayDate ();
370 if ( transaction->getNumberOfTransactions() > 0 ) 367 if ( transaction->getNumberOfTransactions() > 0 )
371 transaction->displayTransactions ( listview, accountid, children, displaytext, displaydate ); 368 transaction->displayTransactions ( listview, accountid, children, displaytext, displaydate );
372 369
373 // redisplay transfers 370 // redisplay transfers
374 if ( transfer->getNumberOfTransfers() > 0 ) 371 if ( transfer->getNumberOfTransfers() > 0 )
375 transfer->displayTransfers ( listview, accountid, children, displaydate ); 372 transfer->displayTransfers ( listview, accountid, children, displaydate );
376 373
377 // add the transaction amount to the account it's associated with 374 // add the transaction amount to the account it's associated with
378 // and update its parent account balance if necessary 375 // and update its parent account balance if necessary
379 account->updateAccountBalance ( id ); 376 account->updateAccountBalance ( id );
380 if ( account->getParentAccountID ( id ) != -1 ) 377 if ( account->getParentAccountID ( id ) != -1 )
381 account->changeParentAccountBalance ( account->getParentAccountID ( id ) ); 378 account->changeParentAccountBalance ( account->getParentAccountID ( id ) );
382 379
383 // format then reset the account balance 380 // format then reset the account balance
384 redisplayAccountBalance (); 381 redisplayAccountBalance ();
385 } 382 }
386 383
387void TransactionDisplay::checkListViewDelete () 384void TransactionDisplay::checkListViewDelete ()
388 { 385 {
389 if ( listview->selectedItem() == 0 ) 386 if ( listview->selectedItem() == 0 )
390 QMessageBox::warning ( this, "QashMoney", "Please select a transaction to\ndelete."); 387 QMessageBox::warning ( this, "QashMoney", "Please select a transaction to\ndelete.");
391 else 388 else
392 deleteTransaction (); 389 deleteTransaction ();
393 } 390 }
394 391
395void TransactionDisplay::deleteTransaction () 392void TransactionDisplay::deleteTransaction ()
396 { 393 {
397 int transactionid = listview->currentItem()->text ( getIDColumn() ).toInt(); 394 int transactionid = listview->currentItem()->text ( getIDColumn() ).toInt();
398 395
399 if ( transactionid > 0 ) // takes care of deleting transactions 396 if ( transactionid > 0 ) // takes care of deleting transactions
400 { 397 {
401 // check if we are viewing child transactions through a parent 398 // check if we are viewing child transactions through a parent
402 // in that case we will have to update balances for the parent 399 // in that case we will have to update balances for the parent
403 // which is represented by accountid and the child account 400 // which is represented by accountid and the child account
404 // which will be represented by childaccountid 401 // which will be represented by childaccountid
405 int childaccountid = -1; 402 int childaccountid = -1;
406 if ( listview->columns() == 5 ) 403 if ( listview->columns() == 5 )
407 childaccountid = transaction->getAccountID ( transactionid ); 404 childaccountid = transaction->getAccountID ( transactionid );
408 405
409 transaction->deleteTransaction ( transactionid ); 406 transaction->deleteTransaction ( transactionid );
410 407
411 listview->clear(); 408 listview->clear();
412 QString displaytext = "%"; 409 QString displaytext = "%";
413 displaytext.prepend ( limitbox->text() ); 410 displaytext.prepend ( limitbox->text() );
414 setTransactionDisplayDate (); 411 setTransactionDisplayDate ();
415 if ( transaction->getNumberOfTransactions() > 0 ) 412 if ( transaction->getNumberOfTransactions() > 0 )
416 transaction->displayTransactions ( listview, accountid, children, displaytext, displaydate ); 413 transaction->displayTransactions ( listview, accountid, children, displaytext, displaydate );
417 414
418 if ( transfer->getNumberOfTransfers() > 0 ) 415 if ( transfer->getNumberOfTransfers() > 0 )
419 transfer->displayTransfers ( listview, accountid, children, displaydate ); 416 transfer->displayTransfers ( listview, accountid, children, displaydate );
420 417
421 // if we are viewing different child accounts through the parent account 418 // if we are viewing different child accounts through the parent account
422 // ie if there are five columns and the parentid is -1 419 // ie if there are five columns and the parentid is -1
423 // update the accountid ( which is the parent ) and update the child account 420 // update the accountid ( which is the parent ) and update the child account
424 // balance. Get its accountid from the transactionid 421 // balance. Get its accountid from the transactionid
425 account->updateAccountBalance ( accountid ); // will update either a parent or child 422 account->updateAccountBalance ( accountid ); // will update either a parent or child
426 if ( account->getParentAccountID ( accountid ) != -1 ) // update its parent if there is one 423 if ( account->getParentAccountID ( accountid ) != -1 ) // update its parent if there is one
427 account->changeParentAccountBalance ( account->getParentAccountID ( accountid ) ); 424 account->changeParentAccountBalance ( account->getParentAccountID ( accountid ) );
428 if ( childaccountid != -1 ) // we've set childaccountid 425 if ( childaccountid != -1 ) // we've set childaccountid
429 account->updateAccountBalance ( childaccountid ); 426 account->updateAccountBalance ( childaccountid );
430 427
431 // format then reset the account balance 428 // format then reset the account balance
432 redisplayAccountBalance (); 429 redisplayAccountBalance ();
433 } 430 }
434 else // takes care of deleting transfers 431 else // takes care of deleting transfers
435 { 432 {
436 // get the accountids before we delete the transfer 433 // get the accountids before we delete the transfer
437 int fromaccountid = transfer->getFromAccountID ( transactionid ); 434 int fromaccountid = transfer->getFromAccountID ( transactionid );
438 int toaccountid = transfer->getToAccountID ( transactionid ); 435 int toaccountid = transfer->getToAccountID ( transactionid );
439 436
440 // delete the transfer and redisplay transactions 437 // delete the transfer and redisplay transactions
441 transfer->deleteTransfer ( transactionid ); 438 transfer->deleteTransfer ( transactionid );
442 439
443 listview->clear(); 440 listview->clear();
444 QString displaytext = "%"; 441 QString displaytext = "%";
445 displaytext.prepend ( limitbox->text() ); 442 displaytext.prepend ( limitbox->text() );
446 setTransactionDisplayDate (); 443 setTransactionDisplayDate ();
447 if ( transaction->getNumberOfTransactions() > 0 ) 444 if ( transaction->getNumberOfTransactions() > 0 )
448 transaction->displayTransactions ( listview, accountid, children, displaytext, displaydate ); 445 transaction->displayTransactions ( listview, accountid, children, displaytext, displaydate );
449 446
450 if ( transfer->getNumberOfTransfers() > 0 ) 447 if ( transfer->getNumberOfTransfers() > 0 )
451 transfer->displayTransfers ( listview, accountid, children, displaydate ); 448 transfer->displayTransfers ( listview, accountid, children, displaydate );
452 449
453 // for the from account 450 // for the from account
454 account->updateAccountBalance ( fromaccountid ); 451 account->updateAccountBalance ( fromaccountid );
455 if ( account->getParentAccountID ( fromaccountid ) != -1 ) 452 if ( account->getParentAccountID ( fromaccountid ) != -1 )
456 account->changeParentAccountBalance ( account->getParentAccountID ( fromaccountid ) ); 453 account->changeParentAccountBalance ( account->getParentAccountID ( fromaccountid ) );
457 454
458 // for the to account 455 // for the to account
459 account->updateAccountBalance ( toaccountid ); 456 account->updateAccountBalance ( toaccountid );
460 if ( account->getParentAccountID ( toaccountid ) != -1 ) 457 if ( account->getParentAccountID ( toaccountid ) != -1 )
461 account->changeParentAccountBalance ( account->getParentAccountID ( toaccountid ) ); 458 account->changeParentAccountBalance ( account->getParentAccountID ( toaccountid ) );
462 459
463 // format then reset the account balance 460 // format then reset the account balance
464 redisplayAccountBalance (); 461 redisplayAccountBalance ();
465 } 462 }
466 } 463 }
467 464
468void TransactionDisplay::checkListViewToggle () 465void TransactionDisplay::checkListViewToggle ()
469 { 466 {
470 if ( listview->selectedItem() == 0 ) 467 if ( listview->selectedItem() == 0 )
471 QMessageBox::warning ( this, "QashMoney", "Please select a transaction to\nclear or reset."); 468 QMessageBox::warning ( this, "QashMoney", "Please select a transaction to\nclear or reset.");
472 else 469 else
473 toggleTransaction (); 470 toggleTransaction ();
474 } 471 }
475 472
476void TransactionDisplay::toggleTransaction () 473void TransactionDisplay::toggleTransaction ()
477 { 474 {
478 //get the transaction of the selected transaction to determine if its a transaction or transfer 475 //get the transaction of the selected transaction to determine if its a transaction or transfer
479 int transactionid = listview->currentItem()->text ( getIDColumn() ).toInt(); 476 int transactionid = listview->currentItem()->text ( getIDColumn() ).toInt();
480 477
481 if ( transactionid > 0 ) // if this is a transaction 478 if ( transactionid > 0 ) // if this is a transaction
482 { 479 {
483 if ( transaction->getCleared ( transactionid ) == 0 ) 480 if ( transaction->getCleared ( transactionid ) == 0 )
484 transaction->setCleared ( transactionid, 1 ); 481 transaction->setCleared ( transactionid, 1 );
485 else 482 else
486 transaction->setCleared ( transactionid, 0 ); 483 transaction->setCleared ( transactionid, 0 );
487 } 484 }
488 else 485 else
489 { 486 {
490 if ( transfer->getCleared ( transactionid ) == 0 ) 487 if ( transfer->getCleared ( transactionid ) == 0 )
491 transfer->setCleared ( transactionid, 1 ); 488 transfer->setCleared ( transactionid, 1 );
492 else 489 else
493 transfer->setCleared ( transactionid, 0 ); 490 transfer->setCleared ( transactionid, 0 );
494 } 491 }
495 492
496 listview->clear(); 493 listview->clear();
497 QString displaytext = "%"; 494 QString displaytext = "%";
498 displaytext.prepend ( limitbox->text() ); 495 displaytext.prepend ( limitbox->text() );
499 setTransactionDisplayDate (); 496 setTransactionDisplayDate ();
500 if ( transaction->getNumberOfTransactions() > 0 ) 497 if ( transaction->getNumberOfTransactions() > 0 )
501 transaction->displayTransactions ( listview, accountid, children, displaytext, displaydate ); 498 transaction->displayTransactions ( listview, accountid, children, displaytext, displaydate );
502 499
503 if ( transfer->getNumberOfTransfers() != 0 ) 500 if ( transfer->getNumberOfTransfers() != 0 )
504 transfer->displayTransfers ( listview, accountid, children, displaydate ); 501 transfer->displayTransfers ( listview, accountid, children, displaydate );
505 } 502 }
506 503
507void TransactionDisplay::redisplayAccountBalance () 504void TransactionDisplay::redisplayAccountBalance ()
508 { 505 {
509 QString accountbalance = account->getAccountBalance ( accountid ); 506 QString accountbalance = account->getAccountBalance ( accountid );
510 balance->setText ( accountbalance ); 507 balance->setText ( accountbalance );
511 } 508 }
512 509
513void TransactionDisplay::setChildren ( bool c ) 510void TransactionDisplay::setChildren ( bool c )
514 { 511 {
515 children = c; 512 children = c;
516 } 513 }
517 514
518void TransactionDisplay::setAccountID ( int id ) 515void TransactionDisplay::setAccountID ( int id )
519 { 516 {
520 accountid = id; 517 accountid = id;
521 } 518 }
522 519
523ColorListItem::ColorListItem ( QListView *parent ) : QListViewItem ( parent ) 520ColorListItem::ColorListItem ( QListView *parent ) : QListViewItem ( parent )
524 { 521 {
525 } 522 }
526 523
527ColorListItem::ColorListItem ( QListView *parent, QString label1, QString label2, QString label3, QString label4 ) 524ColorListItem::ColorListItem ( QListView *parent, QString label1, QString label2, QString label3, QString label4 )
528 : QListViewItem ( parent, label1, label2, label3, label4 ) 525 : QListViewItem ( parent, label1, label2, label3, label4 )
529 { 526 {
530 } 527 }
531 528
532ColorListItem::ColorListItem ( QListView *parent, QString label1, QString label2, QString label3, QString label4, QString label5 ) 529ColorListItem::ColorListItem ( QListView *parent, QString label1, QString label2, QString label3, QString label4, QString label5 )
533 : QListViewItem ( parent, label1, label2, label3, label4, label5 ) 530 : QListViewItem ( parent, label1, label2, label3, label4, label5 )
534 { 531 {
535 } 532 }
536 533
537void ColorListItem::paintCell ( QPainter *p, const QColorGroup &cg, int column, int width, int alignment ) 534void ColorListItem::paintCell ( QPainter *p, const QColorGroup &cg, int column, int width, int alignment )
538 { 535 {
539 QColorGroup _cg ( cg ); 536 QColorGroup _cg ( cg );
540 _cg.setColor ( QColorGroup::Text, Qt::red ); 537 _cg.setColor ( QColorGroup::Text, Qt::red );
541 QListViewItem::paintCell ( p, _cg, column, width, alignment ); 538 QListViewItem::paintCell ( p, _cg, column, width, alignment );
542 } 539 }
543 540
544void TransactionDisplay::saveColumnSize ( int column, int oldsize, int newsize ) 541void TransactionDisplay::saveColumnSize ( int column, int oldsize, int newsize )
545 { 542 {
546 if ( listview->columns() == 4 ) 543 if ( listview->columns() == 4 )
547 preferences->changeColumnPreference ( column + 3, newsize ); 544 preferences->changeColumnPreference ( column + 3, newsize );
548 else if ( listview->columns() == 5 && column != 4 ) 545 else if ( listview->columns() == 5 && column != 4 )
549 preferences->changeColumnPreference ( column + 6, newsize ); 546 preferences->changeColumnPreference ( column + 6, newsize );
550 else 547 else
551 preferences->changeColumnPreference ( 9, newsize ); 548 preferences->changeColumnPreference ( 9, newsize );
552 } 549 }
553 550
554void TransactionDisplay::saveSortingPreference ( int column ) 551void TransactionDisplay::saveSortingPreference ( int column )
555 { 552 {
556 preferences->changeSortingPreference ( 2, column ); 553 preferences->changeSortingPreference ( 2, column );
557 } 554 }
558 555
559void TransactionDisplay::limitDisplay ( const QString &text ) 556void TransactionDisplay::limitDisplay ( const QString &text )
560 { 557 {
561 listview->clear (); 558 listview->clear ();
562 QString displaytext = "%"; 559 QString displaytext = "%";
563 displaytext.prepend ( text ); 560 displaytext.prepend ( text );
564 setTransactionDisplayDate (); 561 setTransactionDisplayDate ();
565 if ( transaction->getNumberOfTransactions() > 0 ) 562 if ( transaction->getNumberOfTransactions() > 0 )
566 transaction->displayTransactions ( listview, accountid, children, displaytext, displaydate ); 563 transaction->displayTransactions ( listview, accountid, children, displaytext, displaydate );
567 564
568 if ( displaytext.length() == 1 || preferences->getPreference ( 6 ) == 1 ) 565 if ( displaytext.length() == 1 || preferences->getPreference ( 6 ) == 1 )
569 transfer->displayTransfers ( listview, accountid, children, displaydate ); 566 transfer->displayTransfers ( listview, accountid, children, displaydate );
570 } 567 }
571 568
572int TransactionDisplay::getIDColumn () 569int TransactionDisplay::getIDColumn ()
573 { 570 {
574 int counter; 571 int counter;
575 int columns = listview->columns(); 572 int columns = listview->columns();
576 for ( counter = 0; counter <= columns; counter++ ) 573 for ( counter = 0; counter <= columns; counter++ )
577 if ( listview->header()->label ( counter ).length() == 0 ) 574 if ( listview->header()->label ( counter ).length() == 0 )
578 return counter; 575 return counter;
579 } 576 }
580 577
581void TransactionDisplay::showTransactionNotes () 578void TransactionDisplay::showTransactionNotes ()
582 { 579 {
583 if ( listview->selectedItem() == 0 || listview->currentItem()->text ( getIDColumn() ).toInt() < 0 ) 580 if ( listview->selectedItem() == 0 || listview->currentItem()->text ( getIDColumn() ).toInt() < 0 )
584 QMessageBox::warning ( this, "QashMoney", "Please select a valid\ntransaction to view notes."); 581 QMessageBox::warning ( this, "QashMoney", "Please select a valid\ntransaction to view notes.");
585 else 582 else
586 { 583 {
587 int transactionid = listview->selectedItem()->text ( getIDColumn() ).toInt (); 584 int transactionid = listview->selectedItem()->text ( getIDColumn() ).toInt ();
588 QDialog *description = new QDialog ( this, "description", TRUE ); 585 QDialog *description = new QDialog ( this, "description", TRUE );
589 description->setCaption ( "Notes" ); 586 description->setCaption ( "Notes" );
590 QMultiLineEdit *notes = new QMultiLineEdit ( description ); 587 QMultiLineEdit *notes = new QMultiLineEdit ( description );
591 notes->setFixedSize ( ( int ) (this->width() * 0.75 ), ( int ) ( this->height() * 0.5 ) ); 588 notes->setFixedSize ( ( int ) (this->width() * 0.75 ), ( int ) ( this->height() * 0.5 ) );
592 notes->setWrapColumnOrWidth ( ( int ) (this->width() * 0.75 ) ); 589 notes->setWrapColumnOrWidth ( ( int ) (this->width() * 0.75 ) );
593 notes->setWordWrap ( QMultiLineEdit::WidgetWidth ); 590 notes->setWordWrap ( QMultiLineEdit::WidgetWidth );
594 notes->setEnabled ( FALSE ); 591 notes->setEnabled ( FALSE );
595 notes->setText ( transaction->getTransactionDescription ( transactionid ) ); 592 notes->setText ( transaction->getTransactionDescription ( transactionid ) );
596 description->show(); 593 description->show();
597 } 594 }
598 } 595 }
599 596
600void TransactionDisplay::setTransactionDisplayDate () 597void TransactionDisplay::setTransactionDisplayDate ()
601 { 598 {
602 // determine how many days of transactions to show 599 // determine how many days of transactions to show
603 int limittype = preferences->getPreference ( 7 ); 600 int limittype = preferences->getPreference ( 7 );
604 if ( limittype != 5 ) // set today's date if we are not showing all transactions 601 if ( limittype != 5 ) // set today's date if we are not showing all transactions
605 { 602 {
606 QDate today = QDate::currentDate (); 603 QDate today = QDate::currentDate ();
607 switch ( limittype ) // if we are not showing all transactions 604 switch ( limittype ) // if we are not showing all transactions
608 { 605 {
609 case 0: // viewing two weeks 606 case 0: // viewing two weeks
610 displaydate = today.addDays ( -14 ); 607 displaydate = today.addDays ( -14 );
611 break; 608 break;
612 case 1: // viewing one month 609 case 1: // viewing one month
613 displaydate = today.addDays ( -30 ); 610 displaydate = today.addDays ( -30 );
614 break; 611 break;
615 case 2: // three months 612 case 2: // three months
616 displaydate = today.addDays ( -90 ); 613 displaydate = today.addDays ( -90 );
617 break; 614 break;
618 case 3: // six months 615 case 3: // six months
619 displaydate = today.addDays ( -180 ); 616 displaydate = today.addDays ( -180 );
620 break; 617 break;
621 case 4: // one year 618 case 4: // one year
622 displaydate = today.addDays ( -365 ); 619 displaydate = today.addDays ( -365 );
623 break; 620 break;
624 } 621 }
625 } 622 }
626 else 623 else
627 displaydate = QDate ( 1900, 1, 1 ); 624 displaydate = QDate ( 1900, 1, 1 );
628 } 625 }
diff --git a/noncore/apps/qashmoney/transferdialog.cpp b/noncore/apps/qashmoney/transferdialog.cpp
index f85c740..558abec 100755
--- a/noncore/apps/qashmoney/transferdialog.cpp
+++ b/noncore/apps/qashmoney/transferdialog.cpp
@@ -1,114 +1,112 @@
1#include "transferdialog.h" 1#include "transferdialog.h"
2#include "datepicker.h" 2#include "datepicker.h"
3#include "calculator.h" 3#include "calculator.h"
4 4
5#include <qdatetime.h>
6#include <qfont.h>
7 5
8extern Preferences *preferences; 6extern Preferences *preferences;
9extern Account *account; 7extern Account *account;
10 8
11TransferDialog::TransferDialog ( QWidget *parent, int fromaccountid, int toaccountid ) : QDialog ( parent, 0, TRUE ) 9TransferDialog::TransferDialog ( QWidget *parent, int fromaccountid, int toaccountid ) : QDialog ( parent, 0, TRUE )
12 { 10 {
13 dateedited = FALSE; 11 dateedited = FALSE;
14 setCaption ( "Transfer" ); 12 setCaption ( "Transfer" );
15 13
16 fromaccountlabel = new QLabel ( "From account:", this ); 14 fromaccountlabel = new QLabel ( "From account:", this );
17 QFont f = this->font(); 15 QFont f = this->font();
18 f.setWeight ( QFont::Bold ); 16 f.setWeight ( QFont::Bold );
19 fromaccountlabel->setFont ( f ); 17 fromaccountlabel->setFont ( f );
20 fromaccount = new QLabel ( account->getAccountName ( fromaccountid ), this ); 18 fromaccount = new QLabel ( account->getAccountName ( fromaccountid ), this );
21 19
22 toaccountlabel = new QLabel ( "To Account:", this ); 20 toaccountlabel = new QLabel ( "To Account:", this );
23 toaccountlabel->setFont ( f ); 21 toaccountlabel->setFont ( f );
24 toaccount = new QLabel ( account->getAccountName ( toaccountid ), this ); 22 toaccount = new QLabel ( account->getAccountName ( toaccountid ), this );
25 23
26 datelabel = new QLabel ( "Date", this ); 24 datelabel = new QLabel ( "Date", this );
27 25
28 datebox = new QHBox ( this ); 26 datebox = new QHBox ( this );
29 datebox->setSpacing ( 2 ); 27 datebox->setSpacing ( 2 );
30 date = new QLineEdit ( datebox ); 28 date = new QLineEdit ( datebox );
31 date->setAlignment ( Qt::AlignRight ); 29 date->setAlignment ( Qt::AlignRight );
32 date->setDisabled ( TRUE ); 30 date->setDisabled ( TRUE );
33 datebutton = new QPushButton ( datebox ); 31 datebutton = new QPushButton ( datebox );
34 datebutton->setPixmap ( QPixmap ( "/opt/QtPalmtop/pics/date.png" ) ); 32 datebutton->setPixmap ( QPixmap ( "/opt/QtPalmtop/pics/date.png" ) );
35 connect ( datebutton, SIGNAL ( released () ), this, SLOT ( showCalendar () ) ); 33 connect ( datebutton, SIGNAL ( released () ), this, SLOT ( showCalendar () ) );
36 34
37 amounttlabel = new QLabel ( "Amount", this ); 35 amounttlabel = new QLabel ( "Amount", this );
38 36
39 amountbox = new QHBox ( this ); 37 amountbox = new QHBox ( this );
40 amountbox->setSpacing ( 2 ); 38 amountbox->setSpacing ( 2 );
41 amount = new QLineEdit ( amountbox ); 39 amount = new QLineEdit ( amountbox );
42 amount->setAlignment ( Qt::AlignRight ); 40 amount->setAlignment ( Qt::AlignRight );
43 calculatorbutton = new QPushButton( amountbox ); 41 calculatorbutton = new QPushButton( amountbox );
44 calculatorbutton->setPixmap ( QPixmap ( "/opt/QtPalmtop/pics/kcalc.png" ) ); 42 calculatorbutton->setPixmap ( QPixmap ( "/opt/QtPalmtop/pics/kcalc.png" ) );
45 connect ( calculatorbutton, SIGNAL ( released() ), this, SLOT ( showCalculator() ) ); 43 connect ( calculatorbutton, SIGNAL ( released() ), this, SLOT ( showCalculator() ) );
46 44
47 clearedcheckbox = new QCheckBox ( "Cleared", this ); 45 clearedcheckbox = new QCheckBox ( "Cleared", this );
48 46
49 layout = new QVBoxLayout ( this, 4, 2 ); 47 layout = new QVBoxLayout ( this, 4, 2 );
50 layout->addWidget ( fromaccountlabel, Qt::AlignLeft ); 48 layout->addWidget ( fromaccountlabel, Qt::AlignLeft );
51 layout->addWidget ( fromaccount, Qt::AlignLeft ); 49 layout->addWidget ( fromaccount, Qt::AlignLeft );
52 layout->addWidget ( toaccountlabel, Qt::AlignLeft ); 50 layout->addWidget ( toaccountlabel, Qt::AlignLeft );
53 layout->addWidget ( toaccount, Qt::AlignLeft ); 51 layout->addWidget ( toaccount, Qt::AlignLeft );
54 layout->addSpacing ( 5 ); 52 layout->addSpacing ( 5 );
55 layout->addWidget ( datelabel, Qt::AlignLeft ); 53 layout->addWidget ( datelabel, Qt::AlignLeft );
56 layout->addWidget ( datebox, Qt::AlignLeft ); 54 layout->addWidget ( datebox, Qt::AlignLeft );
57 layout->addWidget ( amounttlabel, Qt::AlignLeft ); 55 layout->addWidget ( amounttlabel, Qt::AlignLeft );
58 layout->addWidget ( amountbox, Qt::AlignLeft ); 56 layout->addWidget ( amountbox, Qt::AlignLeft );
59 layout->addWidget ( clearedcheckbox, Qt::AlignLeft ); 57 layout->addWidget ( clearedcheckbox, Qt::AlignLeft );
60 } 58 }
61 59
62bool TransferDialog::getDateEdited () 60bool TransferDialog::getDateEdited ()
63 { 61 {
64 return dateedited; 62 return dateedited;
65 } 63 }
66 64
67void TransferDialog::showCalendar () 65void TransferDialog::showCalendar ()
68 { 66 {
69 QDate newDate = QDate::currentDate (); 67 QDate newDate = QDate::currentDate ();
70 DatePicker *dp = new DatePicker ( newDate ); 68 DatePicker *dp = new DatePicker ( newDate );
71 if ( dp->exec () == QDialog::Accepted ) 69 if ( dp->exec () == QDialog::Accepted )
72 { 70 {
73 // Set date integers 71 // Set date integers
74 year = dp->getYear(); 72 year = dp->getYear();
75 month = dp->getMonth(); 73 month = dp->getMonth();
76 day = dp->getDay(); 74 day = dp->getDay();
77 75
78 // Set dateedited to TRUE 76 // Set dateedited to TRUE
79 // This tells the accountdisplay object that the user edited an account 77 // This tells the accountdisplay object that the user edited an account
80 // and did change the date 78 // and did change the date
81 dateedited = TRUE; 79 dateedited = TRUE;
82 80
83 // Display date with our selected format 81 // Display date with our selected format
84 date->setText ( preferences->getDate ( year, month, day ) ); 82 date->setText ( preferences->getDate ( year, month, day ) );
85 } 83 }
86 } 84 }
87 85
88int TransferDialog::getDay () 86int TransferDialog::getDay ()
89 { 87 {
90 return day; 88 return day;
91 } 89 }
92 90
93int TransferDialog::getMonth () 91int TransferDialog::getMonth ()
94 { 92 {
95 return month; 93 return month;
96 } 94 }
97 95
98int TransferDialog::getYear () 96int TransferDialog::getYear ()
99 { 97 {
100 return year; 98 return year;
101 } 99 }
102 100
103void TransferDialog::showCalculator () 101void TransferDialog::showCalculator ()
104 { 102 {
105 Calculator *calculator = new Calculator ( this ); 103 Calculator *calculator = new Calculator ( this );
106 if ( calculator->exec () == QDialog::Accepted ) 104 if ( calculator->exec () == QDialog::Accepted )
107 amount->setText ( calculator->display->text() ); 105 amount->setText ( calculator->display->text() );
108 } 106 }
109 107
110 108
111 109
112 110
113 111
114 112
diff --git a/noncore/apps/tableviewer/tableviewer.cpp b/noncore/apps/tableviewer/tableviewer.cpp
index 207172d..f35dfcd 100644
--- a/noncore/apps/tableviewer/tableviewer.cpp
+++ b/noncore/apps/tableviewer/tableviewer.cpp
@@ -1,481 +1,480 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved. 2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qtopia Environment. 4** This file is part of Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20 20
21/* local includes */ 21/* local includes */
22#include "tableviewer.h" 22#include "tableviewer.h"
23#include "ui/tvbrowseview.h" 23#include "ui/tvbrowseview.h"
24#include "ui/tvfilterview.h" 24#include "ui/tvfilterview.h"
25#include "ui/tvlistview.h" 25#include "ui/tvlistview.h"
26#include "ui/tveditview.h" 26#include "ui/tveditview.h"
27#include "ui/tvkeyedit.h" 27#include "ui/tvkeyedit.h"
28#include "db/datacache.h" 28#include "db/datacache.h"
29 29
30/* QPE includes */ 30/* QPE includes */
31#include <qpe/fileselector.h> 31#include <qpe/fileselector.h>
32#include <qpe/resource.h> 32#include <qpe/resource.h>
33#include <qpe/qpetoolbar.h> 33#include <qpe/qpetoolbar.h>
34 34
35/* QTE includes */ 35/* QTE includes */
36#include <qmenubar.h> 36#include <qmenubar.h>
37#include <qpe/qpetoolbar.h>
38#include <qpopupmenu.h> 37#include <qpopupmenu.h>
39#include <qapplication.h> 38#include <qapplication.h>
40#include <qwidgetstack.h> 39#include <qwidgetstack.h>
41#include <qlayout.h> 40#include <qlayout.h>
42#include <qbuffer.h> 41#include <qbuffer.h>
43/*! 42/*!
44 \class TableViewerWindow 43 \class TableViewerWindow
45 \brief The main window widget of the application 44 \brief The main window widget of the application
46 45
47 This is the main widget of the table viewer application. 46 This is the main widget of the table viewer application.
48 It is the co-ordination point. 47 It is the co-ordination point.
49*/ 48*/
50 49
51/*! 50/*!
52 Constructs a new TableViewerWindow 51 Constructs a new TableViewerWindow
53*/ 52*/
54TableViewerWindow::TableViewerWindow(QWidget *parent, const char *name, WFlags f) 53TableViewerWindow::TableViewerWindow(QWidget *parent, const char *name, WFlags f)
55 : QMainWindow(parent, name, f) 54 : QMainWindow(parent, name, f)
56{ 55{
57 setCaption(tr("Table Viewer")); 56 setCaption(tr("Table Viewer"));
58 57
59/* Build data */ 58/* Build data */
60 ds = new DBStore(); 59 ds = new DBStore();
61 doc.setType("text/x-xml-tableviewer"); 60 doc.setType("text/x-xml-tableviewer");
62 doc.setName("table"); 61 doc.setName("table");
63 62
64 dirty = FALSE; 63 dirty = FALSE;
65 ts.current_column = 0; 64 ts.current_column = 0;
66 ts.kRep = ds->getKeys(); 65 ts.kRep = ds->getKeys();
67 66
68/* build menus */ 67/* build menus */
69 menu = new QMenuBar(this, 0); 68 menu = new QMenuBar(this, 0);
70 69
71 QPopupMenu *file_menu = new QPopupMenu; 70 QPopupMenu *file_menu = new QPopupMenu;
72 file_menu->insertItem("New", this, SLOT(newDocument())); 71 file_menu->insertItem("New", this, SLOT(newDocument()));
73 72
74 file_menu->insertItem("Open", this, SLOT(selectDocument())); 73 file_menu->insertItem("Open", this, SLOT(selectDocument()));
75 file_menu->insertSeparator(); 74 file_menu->insertSeparator();
76 file_menu->insertItem("Properties"); 75 file_menu->insertItem("Properties");
77 76
78 /* later will want to set this up to clean up first via this, SLOT(quit) */ 77 /* later will want to set this up to clean up first via this, SLOT(quit) */
79 menu->insertItem("Document", file_menu); 78 menu->insertItem("Document", file_menu);
80 79
81 QPopupMenu *edit_menu = new QPopupMenu; 80 QPopupMenu *edit_menu = new QPopupMenu;
82 edit_menu->insertItem("Edit Item", this, SLOT(editItemSlot())); 81 edit_menu->insertItem("Edit Item", this, SLOT(editItemSlot()));
83 edit_menu->insertItem("Edit Keys", this, SLOT(editKeysSlot())); 82 edit_menu->insertItem("Edit Keys", this, SLOT(editKeysSlot()));
84 edit_menu->insertItem("Edit filters", this, SLOT(filterViewSlot())); 83 edit_menu->insertItem("Edit filters", this, SLOT(filterViewSlot()));
85 menu->insertItem("Edit", edit_menu); 84 menu->insertItem("Edit", edit_menu);
86 85
87 QPopupMenu *view_menu = new QPopupMenu; 86 QPopupMenu *view_menu = new QPopupMenu;
88 view_menu->insertItem("Browse View", this, SLOT(browseViewSlot())); 87 view_menu->insertItem("Browse View", this, SLOT(browseViewSlot()));
89 view_menu->insertItem("List View", this, SLOT(listViewSlot())); 88 view_menu->insertItem("List View", this, SLOT(listViewSlot()));
90 menu->insertItem("View", view_menu); 89 menu->insertItem("View", view_menu);
91 90
92 QVBoxLayout *main_layout = new QVBoxLayout; 91 QVBoxLayout *main_layout = new QVBoxLayout;
93 92
94 /* Build tool bar */ 93 /* Build tool bar */
95 navigation = new QToolBar(this, "navigation"); 94 navigation = new QToolBar(this, "navigation");
96 QToolButton *newItemButton = new QToolButton( 95 QToolButton *newItemButton = new QToolButton(
97 QIconSet(Resource::loadPixmap("new")), "New Item", QString::null, 96 QIconSet(Resource::loadPixmap("new")), "New Item", QString::null,
98 this, SLOT(newItemSlot()), navigation, "New Item"); 97 this, SLOT(newItemSlot()), navigation, "New Item");
99 QToolButton *editItemButton = new QToolButton( 98 QToolButton *editItemButton = new QToolButton(
100 QIconSet(Resource::loadPixmap("edit")), "Edit Item", QString::null, 99 QIconSet(Resource::loadPixmap("edit")), "Edit Item", QString::null,
101 this, SLOT(editItemSlot()), navigation, "Edit Item"); 100 this, SLOT(editItemSlot()), navigation, "Edit Item");
102 QToolButton *deleteItemButton = new QToolButton( 101 QToolButton *deleteItemButton = new QToolButton(
103 QIconSet(Resource::loadPixmap("trash")), "Delete Item", 102 QIconSet(Resource::loadPixmap("trash")), "Delete Item",
104 QString::null, this, 103 QString::null, this,
105 SLOT(deleteItemSlot()), navigation, "Delete Item"); 104 SLOT(deleteItemSlot()), navigation, "Delete Item");
106 105
107 navigation->addSeparator(); 106 navigation->addSeparator();
108 107
109 QToolButton *firstItemButton = new QToolButton( 108 QToolButton *firstItemButton = new QToolButton(
110 QIconSet(Resource::loadPixmap("fastback")), "First Item", 109 QIconSet(Resource::loadPixmap("fastback")), "First Item",
111 QString::null, this, 110 QString::null, this,
112 SLOT(firstItem()), navigation, "First Item"); 111 SLOT(firstItem()), navigation, "First Item");
113 QToolButton *previousItemButton = new QToolButton( 112 QToolButton *previousItemButton = new QToolButton(
114 QIconSet(Resource::loadPixmap("back")), "Previous Item", 113 QIconSet(Resource::loadPixmap("back")), "Previous Item",
115 QString::null, this, 114 QString::null, this,
116 SLOT(previousItem()), navigation, "Previous Item"); 115 SLOT(previousItem()), navigation, "Previous Item");
117 QToolButton *nextItemButton = new QToolButton( 116 QToolButton *nextItemButton = new QToolButton(
118 QIconSet(Resource::loadPixmap("forward")), "Next Item", 117 QIconSet(Resource::loadPixmap("forward")), "Next Item",
119 QString::null, this, 118 QString::null, this,
120 SLOT(nextItem()), navigation, "Next Item"); 119 SLOT(nextItem()), navigation, "Next Item");
121 QToolButton *lastItemButton = new QToolButton( 120 QToolButton *lastItemButton = new QToolButton(
122 QIconSet(Resource::loadPixmap("fastforward")), "Last Item", 121 QIconSet(Resource::loadPixmap("fastforward")), "Last Item",
123 QString::null, this, 122 QString::null, this,
124 SLOT(lastItem()), navigation, "Last Item"); 123 SLOT(lastItem()), navigation, "Last Item");
125 124
126 navigation->addSeparator(); 125 navigation->addSeparator();
127 QToolButton *browseButton = new QToolButton( 126 QToolButton *browseButton = new QToolButton(
128 QIconSet(Resource::loadPixmap("day")), "View Single Item", 127 QIconSet(Resource::loadPixmap("day")), "View Single Item",
129 QString::null, this, 128 QString::null, this,
130 SLOT(browseViewSlot()), navigation, "View Single Item"); 129 SLOT(browseViewSlot()), navigation, "View Single Item");
131 QToolButton *listButton = new QToolButton( 130 QToolButton *listButton = new QToolButton(
132 QIconSet(Resource::loadPixmap("month")), "View Multiple Items", 131 QIconSet(Resource::loadPixmap("month")), "View Multiple Items",
133 QString::null, this, 132 QString::null, this,
134 SLOT(listViewSlot()), navigation, "View Multiple Items"); 133 SLOT(listViewSlot()), navigation, "View Multiple Items");
135 134
136 setToolBarsMovable(FALSE); 135 setToolBarsMovable(FALSE);
137 setToolBarsMovable(FALSE); 136 setToolBarsMovable(FALSE);
138 setToolBarsMovable(FALSE); 137 setToolBarsMovable(FALSE);
139 138
140/* Build widgets */ 139/* Build widgets */
141 browseView = new TVBrowseView(&ts, this, 0); 140 browseView = new TVBrowseView(&ts, this, 0);
142 listView = new TVListView(&ts, this, 0); 141 listView = new TVListView(&ts, this, 0);
143 filterView = new TVFilterView(&ts, this, 0); 142 filterView = new TVFilterView(&ts, this, 0);
144 fileSelector = new FileSelector("text/csv;text/x-xml-tableviewer", 143 fileSelector = new FileSelector("text/csv;text/x-xml-tableviewer",
145 this, "fileselector"); 144 this, "fileselector");
146 fileSelector->setNewVisible(FALSE); 145 fileSelector->setNewVisible(FALSE);
147 fileSelector->setCloseVisible(FALSE); 146 fileSelector->setCloseVisible(FALSE);
148 147
149 cw = new QWidgetStack(this, 0); 148 cw = new QWidgetStack(this, 0);
150 cw->addWidget(listView, ListState); 149 cw->addWidget(listView, ListState);
151 cw->addWidget(browseView, BrowseState); 150 cw->addWidget(browseView, BrowseState);
152 cw->addWidget(filterView, FilterState); 151 cw->addWidget(filterView, FilterState);
153 cw->addWidget(fileSelector, FileState); 152 cw->addWidget(fileSelector, FileState);
154 153
155 current_view = FileState; 154 current_view = FileState;
156 cw->raiseWidget(current_view); 155 cw->raiseWidget(current_view);
157 fileSelector->reread(); 156 fileSelector->reread();
158 157
159 connect(browseView, SIGNAL(searchOnKey(int, TVVariant)), 158 connect(browseView, SIGNAL(searchOnKey(int, TVVariant)),
160 this, SLOT(searchOnKey(int, TVVariant))); 159 this, SLOT(searchOnKey(int, TVVariant)));
161 connect(browseView, SIGNAL(sortChanged(int)), 160 connect(browseView, SIGNAL(sortChanged(int)),
162 this, SLOT(setPrimaryKey(int))); 161 this, SLOT(setPrimaryKey(int)));
163 162
164 connect(fileSelector, SIGNAL(closeMe()), this, SLOT(browseViewSlot())); 163 connect(fileSelector, SIGNAL(closeMe()), this, SLOT(browseViewSlot()));
165 connect(fileSelector, SIGNAL(fileSelected(const DocLnk &)), 164 connect(fileSelector, SIGNAL(fileSelected(const DocLnk &)),
166 this, SLOT(openDocument(const DocLnk &))); 165 this, SLOT(openDocument(const DocLnk &)));
167 166
168 main_layout->addWidget(menu); 167 main_layout->addWidget(menu);
169 main_layout->addWidget(cw); 168 main_layout->addWidget(cw);
170 169
171 setCentralWidget(cw); 170 setCentralWidget(cw);
172 171
173} 172}
174 173
175/*! 174/*!
176 Destroys the TableViewerWindow 175 Destroys the TableViewerWindow
177*/ 176*/
178TableViewerWindow::~TableViewerWindow() 177TableViewerWindow::~TableViewerWindow()
179{ 178{
180 if(dirty) 179 if(dirty)
181 saveDocument(); 180 saveDocument();
182} 181}
183 182
184/*! 183/*!
185 Opens a file dialog and loads the file specified by the dialog 184 Opens a file dialog and loads the file specified by the dialog
186*/ 185*/
187void TableViewerWindow::selectDocument() 186void TableViewerWindow::selectDocument()
188{ 187{
189 if(dirty) 188 if(dirty)
190 saveDocument(); 189 saveDocument();
191 current_view = FileState; 190 current_view = FileState;
192 cw->raiseWidget(current_view); 191 cw->raiseWidget(current_view);
193 fileSelector->reread(); 192 fileSelector->reread();
194} 193}
195 194
196void TableViewerWindow::saveDocument() 195void TableViewerWindow::saveDocument()
197{ 196{
198 if(!dirty) 197 if(!dirty)
199 return; 198 return;
200 199
201 FileManager fm; 200 FileManager fm;
202 QIODevice *dev = fm.saveFile(doc); 201 QIODevice *dev = fm.saveFile(doc);
203 202
204 if(!ds->saveSource(dev, doc.type())){ 203 if(!ds->saveSource(dev, doc.type())){
205 qWarning("Save unsuccessful"); 204 qWarning("Save unsuccessful");
206 return; 205 return;
207 } 206 }
208 dev->close(); 207 dev->close();
209 dirty = FALSE; 208 dirty = FALSE;
210} 209}
211 210
212void TableViewerWindow::newDocument() 211void TableViewerWindow::newDocument()
213{ 212{
214 DocLnk nf; 213 DocLnk nf;
215 nf.setType("text/x-xml-tableviewer"); 214 nf.setType("text/x-xml-tableviewer");
216 nf.setName("table"); 215 nf.setName("table");
217 216
218 delete ds; 217 delete ds;
219 ds = new DBStore(); 218 ds = new DBStore();
220 219
221 ts.current_column = 0; 220 ts.current_column = 0;
222 ts.kRep = ds->getKeys(); 221 ts.kRep = ds->getKeys();
223 browseView->reset(); 222 browseView->reset();
224 listView->reset(); 223 listView->reset();
225 filterView->reset(); 224 filterView->reset();
226 225
227 doc = nf; 226 doc = nf;
228 dirty = FALSE; 227 dirty = FALSE;
229 228
230 current_view = BrowseState; 229 current_view = BrowseState;
231 cw->raiseWidget(current_view); 230 cw->raiseWidget(current_view);
232 231
233 /* now set up for editing the keys */ 232 /* now set up for editing the keys */
234 ts.kRep->addKey("key", TVVariant::String); 233 ts.kRep->addKey("key", TVVariant::String);
235 editKeysSlot(); 234 editKeysSlot();
236} 235}
237 236
238void TableViewerWindow::setDocument(const QString &f) 237void TableViewerWindow::setDocument(const QString &f)
239{ 238{
240 openDocument(DocLnk(f, TRUE)); 239 openDocument(DocLnk(f, TRUE));
241} 240}
242 241
243void TableViewerWindow::openDocument(const DocLnk &f) 242void TableViewerWindow::openDocument(const DocLnk &f)
244{ 243{
245 244
246 if (!f.isValid()) 245 if (!f.isValid())
247 return; 246 return;
248 247
249 FileManager fm; 248 FileManager fm;
250 QIODevice *dev = fm.openFile(f); 249 QIODevice *dev = fm.openFile(f);
251 doc = f; 250 doc = f;
252 251
253 if(ds->openSource(dev, doc.type())) { 252 if(ds->openSource(dev, doc.type())) {
254 DataElem *d; 253 DataElem *d;
255 254
256 browseView->reset(); 255 browseView->reset();
257 listView->reset(); 256 listView->reset();
258 filterView->reset(); 257 filterView->reset();
259 258
260 current_view = BrowseState; 259 current_view = BrowseState;
261 cw->raiseWidget(current_view); 260 cw->raiseWidget(current_view);
262 261
263 /* set up new table state and ensure sub widgets have a reference */ 262 /* set up new table state and ensure sub widgets have a reference */
264 ts.current_column = 0; 263 ts.current_column = 0;
265 ts.kRep = ds->getKeys(); 264 ts.kRep = ds->getKeys();
266 browseView->rebuildKeys(); 265 browseView->rebuildKeys();
267 listView->rebuildKeys(); 266 listView->rebuildKeys();
268 filterView->rebuildKeys(); 267 filterView->rebuildKeys();
269 268
270 ds->first(); 269 ds->first();
271 /* set up the list view */ 270 /* set up the list view */
272 listView->clearItems(); 271 listView->clearItems();
273 do { 272 do {
274 d = ds->getCurrentData(); 273 d = ds->getCurrentData();
275 if(d) 274 if(d)
276 listView->addItem(d); 275 listView->addItem(d);
277 } while(ds->next()); 276 } while(ds->next());
278 277
279 /* Set up browse view, Will be based of structure of listView */ 278 /* Set up browse view, Will be based of structure of listView */
280 listView->first(); 279 listView->first();
281 ts.current_elem = listView->getCurrentData(); 280 ts.current_elem = listView->getCurrentData();
282 browseView->rebuildData(); 281 browseView->rebuildData();
283 listView->rebuildData(); 282 listView->rebuildData();
284 283
285 QString scratch = "Table Viewer";/* later take from constant */ 284 QString scratch = "Table Viewer";/* later take from constant */
286 scratch += " - "; 285 scratch += " - ";
287 scratch += ds->getName(); 286 scratch += ds->getName();
288 setCaption(tr(scratch)); 287 setCaption(tr(scratch));
289 288
290 dirty = FALSE; 289 dirty = FALSE;
291 } else { 290 } else {
292 qWarning(tr("could not load Document")); 291 qWarning(tr("could not load Document"));
293 } 292 }
294 dev->close(); 293 dev->close();
295} 294}
296 295
297/*! 296/*!
298 Moves to the first item of the current table 297 Moves to the first item of the current table
299*/ 298*/
300void TableViewerWindow::firstItem() 299void TableViewerWindow::firstItem()
301{ 300{
302 listView->first(); 301 listView->first();
303 ts.current_elem = listView->getCurrentData(); 302 ts.current_elem = listView->getCurrentData();
304 browseView->rebuildData(); 303 browseView->rebuildData();
305} 304}
306 305
307/*! 306/*!
308 Moves to the lat item of the current table 307 Moves to the lat item of the current table
309*/ 308*/
310void TableViewerWindow::lastItem() 309void TableViewerWindow::lastItem()
311{ 310{
312 listView->last(); 311 listView->last();
313 ts.current_elem = listView->getCurrentData(); 312 ts.current_elem = listView->getCurrentData();
314 browseView->rebuildData(); 313 browseView->rebuildData();
315} 314}
316 315
317/*! 316/*!
318 Moves to the next item of the current table 317 Moves to the next item of the current table
319*/ 318*/
320void TableViewerWindow::nextItem() 319void TableViewerWindow::nextItem()
321{ 320{
322 listView->next(); 321 listView->next();
323 ts.current_elem = listView->getCurrentData(); 322 ts.current_elem = listView->getCurrentData();
324 browseView->rebuildData(); 323 browseView->rebuildData();
325} 324}
326 325
327/*! 326/*!
328 Moves to the previous item of the current table 327 Moves to the previous item of the current table
329*/ 328*/
330void TableViewerWindow::previousItem() 329void TableViewerWindow::previousItem()
331{ 330{
332 listView->previous(); 331 listView->previous();
333 ts.current_elem = listView->getCurrentData(); 332 ts.current_elem = listView->getCurrentData();
334 browseView->rebuildData(); 333 browseView->rebuildData();
335} 334}
336 335
337/*! 336/*!
338 Raises the List View. This is a mode change for the application. 337 Raises the List View. This is a mode change for the application.
339*/ 338*/
340void TableViewerWindow::listViewSlot() 339void TableViewerWindow::listViewSlot()
341{ 340{
342 if(current_view == FilterState) 341 if(current_view == FilterState)
343 applyFilter(); 342 applyFilter();
344 current_view = ListState; 343 current_view = ListState;
345 cw->raiseWidget(current_view); 344 cw->raiseWidget(current_view);
346} 345}
347 346
348void TableViewerWindow::applyFilter() 347void TableViewerWindow::applyFilter()
349{ 348{
350 DataElem *d; 349 DataElem *d;
351 350
352 listView->clearItems(); 351 listView->clearItems();
353 ds->first(); 352 ds->first();
354 do { 353 do {
355 d = ds->getCurrentData(); 354 d = ds->getCurrentData();
356 if(d) 355 if(d)
357 if(filterView->passesFilter(d)) 356 if(filterView->passesFilter(d))
358 listView->addItem(d); 357 listView->addItem(d);
359 } while(ds->next()); 358 } while(ds->next());
360 listView->first(); 359 listView->first();
361 listView->rebuildData(); 360 listView->rebuildData();
362} 361}
363 362
364/*! 363/*!
365 Raises the Browse View. This is a mode change for the application. 364 Raises the Browse View. This is a mode change for the application.
366*/ 365*/
367void TableViewerWindow::browseViewSlot() 366void TableViewerWindow::browseViewSlot()
368{ 367{
369 if(current_view == FilterState) 368 if(current_view == FilterState)
370 applyFilter(); 369 applyFilter();
371 370
372 ts.current_elem = listView->getCurrentData(); 371 ts.current_elem = listView->getCurrentData();
373 browseView->rebuildData(); 372 browseView->rebuildData();
374 373
375 current_view = BrowseState; 374 current_view = BrowseState;
376 cw->raiseWidget(current_view); 375 cw->raiseWidget(current_view);
377} 376}
378 377
379/*! 378/*!
380 Raises the List View. This is a mode change for the application. 379 Raises the List View. This is a mode change for the application.
381*/ 380*/
382void TableViewerWindow::filterViewSlot() 381void TableViewerWindow::filterViewSlot()
383{ 382{
384 current_view = FilterState; 383 current_view = FilterState;
385 cw->raiseWidget(current_view); 384 cw->raiseWidget(current_view);
386} 385}
387 386
388 387
389 388
390 389
391void TableViewerWindow::editItemSlot() 390void TableViewerWindow::editItemSlot()
392{ 391{
393 if(TVEditView::openEditItemDialog(&ts, ts.current_elem, this)) { 392 if(TVEditView::openEditItemDialog(&ts, ts.current_elem, this)) {
394 listView->rebuildData(); 393 listView->rebuildData();
395 browseView->rebuildData(); 394 browseView->rebuildData();
396 dirty = TRUE; 395 dirty = TRUE;
397 } 396 }
398} 397}
399 398
400void TableViewerWindow::newItemSlot() 399void TableViewerWindow::newItemSlot()
401{ 400{
402 DataElem *d = new DataElem(ds); 401 DataElem *d = new DataElem(ds);
403 if (TVEditView::openEditItemDialog(&ts, d, this)) { 402 if (TVEditView::openEditItemDialog(&ts, d, this)) {
404 403
405 ds->addItem(d); 404 ds->addItem(d);
406 ts.current_elem = d; 405 ts.current_elem = d;
407 applyFilter(); 406 applyFilter();
408 listView->rebuildData(); 407 listView->rebuildData();
409 browseView->rebuildData(); 408 browseView->rebuildData();
410 dirty = TRUE; 409 dirty = TRUE;
411 } 410 }
412} 411}
413 412
414void TableViewerWindow::deleteItemSlot() 413void TableViewerWindow::deleteItemSlot()
415{ 414{
416 /* delete the actual item, then do a 'filter' */ 415 /* delete the actual item, then do a 'filter' */
417 DataElem *to_remove = ts.current_elem; 416 DataElem *to_remove = ts.current_elem;
418 417
419 if(!to_remove) 418 if(!to_remove)
420 return; 419 return;
421 420
422 listView->removeItem(); 421 listView->removeItem();
423 ds->removeItem(to_remove); 422 ds->removeItem(to_remove);
424 423
425 applyFilter(); 424 applyFilter();
426 listView->rebuildData(); 425 listView->rebuildData();
427 browseView->rebuildData(); 426 browseView->rebuildData();
428 dirty = TRUE; 427 dirty = TRUE;
429} 428}
430 429
431void TableViewerWindow::editKeysSlot() 430void TableViewerWindow::editKeysSlot()
432{ 431{
433 DataElem *d; 432 DataElem *d;
434 KeyList *k = TVKeyEdit::openEditKeysDialog(&ts, this); 433 KeyList *k = TVKeyEdit::openEditKeysDialog(&ts, this);
435 434
436 if(k) { 435 if(k) {
437 /* set as new keys */ 436 /* set as new keys */
438 ds->setKeys(k); 437 ds->setKeys(k);
439 438
440 ts.current_column = 0; 439 ts.current_column = 0;
441 ts.kRep = k; 440 ts.kRep = k;
442 441
443 browseView->reset(); 442 browseView->reset();
444 listView->reset(); 443 listView->reset();
445 filterView->reset(); 444 filterView->reset();
446 445
447 browseView->rebuildKeys(); 446 browseView->rebuildKeys();
448 listView->rebuildKeys(); 447 listView->rebuildKeys();
449 filterView->rebuildKeys(); 448 filterView->rebuildKeys();
450 449
451 ds->first(); 450 ds->first();
452 /* set up the list view */ 451 /* set up the list view */
453 listView->clearItems(); 452 listView->clearItems();
454 do { 453 do {
455 d = ds->getCurrentData(); 454 d = ds->getCurrentData();
456 if(d) 455 if(d)
457 listView->addItem(d); 456 listView->addItem(d);
458 } while(ds->next()); 457 } while(ds->next());
459 458
460 /* Set up browse view, Will be based of structure of listView */ 459 /* Set up browse view, Will be based of structure of listView */
461 dirty = TRUE; 460 dirty = TRUE;
462 } 461 }
463} 462}
464 463
465/*! 464/*!
466 A Slot that allows for widgets above to indicate a search should be 465 A Slot that allows for widgets above to indicate a search should be
467 done on a specified key index for a specified value 466 done on a specified key index for a specified value
468*/ 467*/
469void TableViewerWindow::searchOnKey(int i, TVVariant v) 468void TableViewerWindow::searchOnKey(int i, TVVariant v)
470{ 469{
471 listView->findItem(i, v); 470 listView->findItem(i, v);
472 ts.current_elem = listView->getCurrentData(); 471 ts.current_elem = listView->getCurrentData();
473 browseView->rebuildData(); 472 browseView->rebuildData();
474} 473}
475 474
476void TableViewerWindow::setPrimaryKey(int i) 475void TableViewerWindow::setPrimaryKey(int i)
477{ 476{
478 ts.current_column = i; 477 ts.current_column = i;
479 listView->rebuildData(); 478 listView->rebuildData();
480 browseView->rebuildData(); 479 browseView->rebuildData();
481} 480}