-rw-r--r-- | noncore/apps/opie-write/qcomplextext.cpp | 3 | ||||
-rw-r--r-- | noncore/apps/opie-write/qrichtext.cpp | 15 | ||||
-rw-r--r-- | noncore/apps/opie-write/qstylesheet.cpp | 2 | ||||
-rw-r--r-- | noncore/apps/opie-write/qtextedit.cpp | 20 | ||||
-rw-r--r-- | noncore/apps/oxygen/calcdlgui.cpp | 1 | ||||
-rw-r--r-- | noncore/apps/oxygen/dataTable.cpp | 3 | ||||
-rw-r--r-- | noncore/apps/oxygen/datawidgetui.cpp | 5 | ||||
-rw-r--r-- | noncore/apps/oxygen/kmolcalc.cpp | 3 | ||||
-rw-r--r-- | noncore/apps/oxygen/oxyframe.cpp | 2 | ||||
-rw-r--r-- | noncore/apps/oxygen/oxygen.cpp | 2 | ||||
-rw-r--r-- | noncore/apps/oxygen/psewidget.cpp | 2 | ||||
-rwxr-xr-x | noncore/apps/qashmoney/account.cpp | 2 | ||||
-rwxr-xr-x | noncore/apps/qashmoney/accountdisplay.cpp | 2 | ||||
-rwxr-xr-x | noncore/apps/qashmoney/budgetdisplay.cpp | 3 | ||||
-rwxr-xr-x | noncore/apps/qashmoney/newaccount.cpp | 3 | ||||
-rwxr-xr-x | noncore/apps/qashmoney/newtransaction.cpp | 2 | ||||
-rwxr-xr-x | noncore/apps/qashmoney/preferencedialogs.cpp | 1 | ||||
-rwxr-xr-x | noncore/apps/qashmoney/transactiondisplay.cpp | 3 | ||||
-rwxr-xr-x | noncore/apps/qashmoney/transferdialog.cpp | 2 | ||||
-rw-r--r-- | noncore/apps/tableviewer/tableviewer.cpp | 1 |
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 @@ /**************************************************************************** ** $Id$ ** ** Implementation of some internal classes ** ** Created : ** ** Copyright (C) 2001 Trolltech AS. All rights reserved. ** ** This file is part of the kernel module of the Qt GUI Toolkit. ** ** This file may be distributed under the terms of the Q Public License ** as defined by Trolltech AS of Norway and appearing in the file ** LICENSE.QPL included in the packaging of this file. ** ** This file may be distributed and/or modified under the terms of the ** GNU General Public License version 2 as published by the Free Software ** Foundation and appearing in the file LICENSE.GPL included in the ** packaging of this file. ** ** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition ** licenses may use this file in accordance with the Qt Commercial License ** Agreement provided with the Software. ** ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ** ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for ** information about Qt Commercial License Agreements. ** See http://www.trolltech.com/qpl/ for QPL licensing information. ** See http://www.trolltech.com/gpl/ for GPL licensing information. ** ** Contact info@trolltech.com if any conditions of this licensing are ** not clear to you. ** **********************************************************************/ -#include "qcomplextext_p.h" #include "qrichtext_p.h" -#include "qfontmetrics.h" -#include "qrect.h" #include <stdlib.h> using namespace Qt3; // ----------------------------------------------------- /* a small helper class used internally to resolve Bidi embedding levels. Each line of text caches the embedding level at the start of the line for faster relayouting */ QBidiContext::QBidiContext( uchar l, QChar::Direction e, QBidiContext *p, bool o ) : level(l) , override(o), dir(e) { if ( p ) p->ref(); parent = p; count = 0; } QBidiContext::~QBidiContext() { if( parent && parent->deref() ) delete parent; } /* Arabic shaping obeys a number of rules according to the joining classes (see Unicode book, section on arabic). Each unicode char has a joining class (right, dual (left&right), center (joincausing) or transparent). transparent joining is not encoded in QChar::joining(), but applies to all combining marks and format marks. Right join-causing: dual + center Left join-causing: dual + right + center Rules are as follows (for a string already in visual order, as we have it here): R1 Transparent characters do not affect joining behaviour. R2 A right joining character, that has a right join-causing char on the right will get form XRight (R3 A left joining character, that has a left join-causing char on the left will get form XLeft) Note: the above rule is meaningless, as there are no pure left joining characters defined in Unicode R4 A dual joining character, that has a left join-causing char on the left and a right join-causing char on the right will get form XMedial R5 A dual joining character, that has a right join causing char on the right, and no left join causing char on the left will get form XRight R6 A dual joining character, that has a left join causing char on the left, and no right join causing char on the right will get form XLeft R7 Otherwise the character will get form XIsolated Additionally we have to do the minimal ligature support for lam-alef ligatures: L1 Transparent characters do not affect ligature behaviour. L2 Any sequence of Alef(XRight) + Lam(XMedial) will form the ligature Alef.Lam(XLeft) L3 Any sequence of Alef(XRight) + Lam(XLeft) will form the ligature Alef.Lam(XIsolated) The two functions defined in this class do shaping in visual and logical order. For logical order just replace right with previous and left with next in the above rules ;-) */ /* Two small helper functions for arabic shaping. They get the next shape causing character on either side of the char in question. Implements rule R1. leftChar() returns true if the char to the left is a left join-causing char rightChar() returns true if the char to the right is a right join-causing char */ static inline const QChar *prevChar( const QString &str, int pos ) { //qDebug("leftChar: pos=%d", pos); pos--; const QChar *ch = str.unicode() + pos; while( pos > -1 ) { if( !ch->isMark() ) return ch; pos--; ch--; } return &QChar::replacement; } static inline const QChar *nextChar( const QString &str, int pos) { pos++; int len = str.length(); const QChar *ch = str.unicode() + pos; while( pos < len ) { //qDebug("rightChar: %d isLetter=%d, joining=%d", pos, ch.isLetter(), ch.joining()); if( !ch->isMark() ) return ch; // assume it's a transparent char, this might not be 100% correct pos++; ch++; } return &QChar::replacement; } static inline bool prevVisualCharJoins( const QString &str, int pos) { return ( prevChar( str, pos )->joining() != QChar::OtherJoining ); } static inline bool nextVisualCharJoins( const QString &str, int pos) { QChar::Joining join = nextChar( str, pos )->joining(); return ( join == QChar::Dual || join == QChar::Center ); } 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,441 +1,426 @@ /**************************************************************************** ** $Id$ ** ** Implementation of the internal Qt classes dealing with rich text ** ** Created : 990101 ** ** Copyright (C) 1992-2000 Trolltech AS. All rights reserved. ** ** This file is part of the kernel module of the Qt GUI Toolkit. ** ** This file may be distributed under the terms of the Q Public License ** as defined by Trolltech AS of Norway and appearing in the file ** LICENSE.QPL included in the packaging of this file. ** ** This file may be distributed and/or modified under the terms of the ** GNU General Public License version 2 as published by the Free Software ** Foundation and appearing in the file LICENSE.GPL included in the ** packaging of this file. ** ** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition ** licenses may use this file in accordance with the Qt Commercial License ** Agreement provided with the Software. ** ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ** ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for ** information about Qt Commercial License Agreements. ** See http://www.trolltech.com/qpl/ for QPL licensing information. ** See http://www.trolltech.com/gpl/ for GPL licensing information. ** ** Contact info@trolltech.com if any conditions of this licensing are ** not clear to you. ** **********************************************************************/ #include "qrichtext_p.h" -#include "qstringlist.h" -#include "qfont.h" -#include "qtextstream.h" -#include "qfile.h" -#include "qapplication.h" -#include "qmap.h" -#include "qfileinfo.h" -#include "qstylesheet.h" -#include "qmime.h" -#include "qimage.h" #include "qdragobject.h" #include "qpaintdevicemetrics.h" -#include "qpainter.h" #include "qdrawutil.h" -#include "qcursor.h" -#include "qstack.h" -#include "qstyle.h" -#include "qcomplextext_p.h" #include "qcleanuphandler.h" #include <stdlib.h> using namespace Qt3; static QTextCursor* richTextExportStart = 0; static QTextCursor* richTextExportEnd = 0; static QTextFormatCollection *qFormatCollection = 0; const int border_tolerance = 2; #ifdef Q_WS_WIN #include "qt_windows.h" #endif #define QChar_linesep QChar(0x2028U) static inline bool is_printer( QPainter *p ) { if ( !p || !p->device() ) return FALSE; return p->device()->devType() == QInternal::Printer; } static inline int scale( int value, QPainter *painter ) { if ( is_printer( painter ) ) { QPaintDeviceMetrics metrics( painter->device() ); #if defined(Q_WS_X11) value = value * metrics.logicalDpiY() / QPaintDevice::x11AppDpiY(); #elif defined (Q_WS_WIN) HDC hdc = GetDC( 0 ); int gdc = GetDeviceCaps( hdc, LOGPIXELSY ); if ( gdc ) value = value * metrics.logicalDpiY() / gdc; ReleaseDC( 0, hdc ); #elif defined (Q_WS_MAC) value = value * metrics.logicalDpiY() / 75; // ##### FIXME #elif defined (Q_WS_QWS) value = value * metrics.logicalDpiY() / 75; #endif } return value; } // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ void QTextCommandHistory::addCommand( QTextCommand *cmd ) { if ( current < (int)history.count() - 1 ) { QPtrList<QTextCommand> commands; commands.setAutoDelete( FALSE ); for( int i = 0; i <= current; ++i ) { commands.insert( i, history.at( 0 ) ); history.take( 0 ); } commands.append( cmd ); history.clear(); history = commands; history.setAutoDelete( TRUE ); } else { history.append( cmd ); } if ( (int)history.count() > steps ) history.removeFirst(); else ++current; } QTextCursor *QTextCommandHistory::undo( QTextCursor *c ) { if ( current > -1 ) { QTextCursor *c2 = history.at( current )->unexecute( c ); --current; return c2; } return 0; } QTextCursor *QTextCommandHistory::redo( QTextCursor *c ) { if ( current > -1 ) { if ( current < (int)history.count() - 1 ) { ++current; return history.at( current )->execute( c ); } } else { if ( history.count() > 0 ) { ++current; return history.at( current )->execute( c ); } } return 0; } bool QTextCommandHistory::isUndoAvailable() { return current > -1; } bool QTextCommandHistory::isRedoAvailable() { return current > -1 && current < (int)history.count() - 1 || current == -1 && history.count() > 0; } // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ QTextDeleteCommand::QTextDeleteCommand( QTextDocument *d, int i, int idx, const QMemArray<QTextStringChar> &str, const QByteArray& oldStyleInfo ) : QTextCommand( d ), id( i ), index( idx ), parag( 0 ), text( str ), styleInformation( oldStyleInfo ) { for ( int j = 0; j < (int)text.size(); ++j ) { if ( text[ j ].format() ) text[ j ].format()->addRef(); } } QTextDeleteCommand::QTextDeleteCommand( QTextParagraph *p, int idx, const QMemArray<QTextStringChar> &str ) : QTextCommand( 0 ), id( -1 ), index( idx ), parag( p ), text( str ) { for ( int i = 0; i < (int)text.size(); ++i ) { if ( text[ i ].format() ) text[ i ].format()->addRef(); } } QTextDeleteCommand::~QTextDeleteCommand() { for ( int i = 0; i < (int)text.size(); ++i ) { if ( text[ i ].format() ) text[ i ].format()->removeRef(); } text.resize( 0 ); } QTextCursor *QTextDeleteCommand::execute( QTextCursor *c ) { QTextParagraph *s = doc ? doc->paragAt( id ) : parag; if ( !s ) { qWarning( "can't locate parag at %d, last parag: %d", id, doc->lastParagraph()->paragId() ); return 0; } cursor.setParagraph( s ); cursor.setIndex( index ); int len = text.size(); if ( c ) *c = cursor; if ( doc ) { doc->setSelectionStart( QTextDocument::Temp, cursor ); for ( int i = 0; i < len; ++i ) cursor.gotoNextLetter(); doc->setSelectionEnd( QTextDocument::Temp, cursor ); doc->removeSelectedText( QTextDocument::Temp, &cursor ); if ( c ) *c = cursor; } else { s->remove( index, len ); } return c; } QTextCursor *QTextDeleteCommand::unexecute( QTextCursor *c ) { QTextParagraph *s = doc ? doc->paragAt( id ) : parag; if ( !s ) { qWarning( "can't locate parag at %d, last parag: %d", id, doc->lastParagraph()->paragId() ); return 0; } cursor.setParagraph( s ); cursor.setIndex( index ); QString str = QTextString::toString( text ); cursor.insert( str, TRUE, &text ); cursor.setParagraph( s ); cursor.setIndex( index ); if ( c ) { c->setParagraph( s ); c->setIndex( index ); for ( int i = 0; i < (int)text.size(); ++i ) c->gotoNextLetter(); } if ( !styleInformation.isEmpty() ) { QDataStream styleStream( styleInformation, IO_ReadOnly ); int num; styleStream >> num; QTextParagraph *p = s; while ( num-- && p ) { p->readStyleInformation( styleStream ); p = p->next(); } } s = cursor.paragraph(); while ( s ) { s->format(); s->setChanged( TRUE ); if ( s == c->paragraph() ) break; s = s->next(); } return &cursor; } QTextFormatCommand::QTextFormatCommand( QTextDocument *d, int sid, int sidx, int eid, int eidx, const QMemArray<QTextStringChar> &old, QTextFormat *f, int fl ) : QTextCommand( d ), startId( sid ), startIndex( sidx ), endId( eid ), endIndex( eidx ), format( f ), oldFormats( old ), flags( fl ) { format = d->formatCollection()->format( f ); for ( int j = 0; j < (int)oldFormats.size(); ++j ) { if ( oldFormats[ j ].format() ) oldFormats[ j ].format()->addRef(); } } QTextFormatCommand::~QTextFormatCommand() { format->removeRef(); for ( int j = 0; j < (int)oldFormats.size(); ++j ) { if ( oldFormats[ j ].format() ) oldFormats[ j ].format()->removeRef(); } } QTextCursor *QTextFormatCommand::execute( QTextCursor *c ) { QTextParagraph *sp = doc->paragAt( startId ); QTextParagraph *ep = doc->paragAt( endId ); if ( !sp || !ep ) return c; QTextCursor start( doc ); start.setParagraph( sp ); start.setIndex( startIndex ); QTextCursor end( doc ); end.setParagraph( ep ); end.setIndex( endIndex ); doc->setSelectionStart( QTextDocument::Temp, start ); doc->setSelectionEnd( QTextDocument::Temp, end ); doc->setFormat( QTextDocument::Temp, format, flags ); doc->removeSelection( QTextDocument::Temp ); if ( endIndex == ep->length() ) end.gotoLeft(); *c = end; return c; } QTextCursor *QTextFormatCommand::unexecute( QTextCursor *c ) { QTextParagraph *sp = doc->paragAt( startId ); QTextParagraph *ep = doc->paragAt( endId ); if ( !sp || !ep ) return 0; int idx = startIndex; int fIndex = 0; for ( ;; ) { if ( oldFormats.at( fIndex ).c == '\n' ) { if ( idx > 0 ) { if ( idx < sp->length() && fIndex > 0 ) sp->setFormat( idx, 1, oldFormats.at( fIndex - 1 ).format() ); if ( sp == ep ) break; sp = sp->next(); idx = 0; } fIndex++; } if ( oldFormats.at( fIndex ).format() ) sp->setFormat( idx, 1, oldFormats.at( fIndex ).format() ); idx++; fIndex++; if ( fIndex >= (int)oldFormats.size() ) break; if ( idx >= sp->length() ) { if ( sp == ep ) break; sp = sp->next(); idx = 0; } } QTextCursor end( doc ); end.setParagraph( ep ); end.setIndex( endIndex ); if ( endIndex == ep->length() ) end.gotoLeft(); *c = end; return c; } QTextStyleCommand::QTextStyleCommand( QTextDocument *d, int fParag, int lParag, const QByteArray& beforeChange ) : QTextCommand( d ), firstParag( fParag ), lastParag( lParag ), before( beforeChange ) { after = readStyleInformation( d, fParag, lParag ); } QByteArray QTextStyleCommand::readStyleInformation( QTextDocument* doc, int fParag, int lParag ) { QByteArray style; QTextParagraph *p = doc->paragAt( fParag ); if ( !p ) return style; QDataStream styleStream( style, IO_WriteOnly ); int num = lParag - fParag + 1; styleStream << num; while ( num -- && p ) { p->writeStyleInformation( styleStream ); p = p->next(); } return style; } void QTextStyleCommand::writeStyleInformation( QTextDocument* doc, int fParag, const QByteArray& style ) { QTextParagraph *p = doc->paragAt( fParag ); if ( !p ) return; QDataStream styleStream( style, IO_ReadOnly ); int num; styleStream >> num; while ( num-- && p ) { p->readStyleInformation( styleStream ); p = p->next(); } } QTextCursor *QTextStyleCommand::execute( QTextCursor *c ) { writeStyleInformation( doc, firstParag, after ); return c; } QTextCursor *QTextStyleCommand::unexecute( QTextCursor *c ) { writeStyleInformation( doc, firstParag, before ); return c; } // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ QTextCursor::QTextCursor( QTextDocument *d ) : idx( 0 ), tmpIndex( -1 ), ox( 0 ), oy( 0 ), valid( TRUE ) { para = d ? d->firstParagraph() : 0; } QTextCursor::QTextCursor( const QTextCursor &c ) { ox = c.ox; oy = c.oy; idx = c.idx; para = c.para; tmpIndex = c.tmpIndex; indices = c.indices; paras = c.paras; xOffsets = c.xOffsets; yOffsets = c.yOffsets; valid = c.valid; } QTextCursor &QTextCursor::operator=( const QTextCursor &c ) { ox = c.ox; oy = c.oy; idx = c.idx; para = c.para; tmpIndex = c.tmpIndex; indices = c.indices; paras = c.paras; xOffsets = c.xOffsets; yOffsets = c.yOffsets; valid = c.valid; 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,426 +1,424 @@ /**************************************************************************** ** $Id$ ** ** Implementation of the QStyleSheet class ** ** Created : 990101 ** ** Copyright (C) 1992-2000 Trolltech AS. All rights reserved. ** ** This file is part of the kernel module of the Qt GUI Toolkit. ** ** This file may be distributed under the terms of the Q Public License ** as defined by Trolltech AS of Norway and appearing in the file ** LICENSE.QPL included in the packaging of this file. ** ** This file may be distributed and/or modified under the terms of the ** GNU General Public License version 2 as published by the Free Software ** Foundation and appearing in the file LICENSE.GPL included in the ** packaging of this file. ** ** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition ** licenses may use this file in accordance with the Qt Commercial License ** Agreement provided with the Software. ** ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ** ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for ** information about Qt Commercial License Agreements. ** See http://www.trolltech.com/qpl/ for QPL licensing information. ** See http://www.trolltech.com/gpl/ for GPL licensing information. ** ** Contact info@trolltech.com if any conditions of this licensing are ** not clear to you. ** **********************************************************************/ #include "qstylesheet.h" #include "qrichtext_p.h" -#include "qlayout.h" -#include "qpainter.h" #include "qcleanuphandler.h" #include <stdio.h> using namespace Qt3; namespace Qt3 { class QStyleSheetItemData { public: QStyleSheetItem::DisplayMode disp; int fontitalic; int fontunderline; int fontstrikeout; int fontweight; int fontsize; int fontsizelog; int fontsizestep; int lineSpacing; QString fontfamily; QStyleSheetItem *parentstyle; QString stylename; int ncolumns; QColor col; bool anchor; int align; QStyleSheetItem::VerticalAlignment valign; int margin[5]; QStyleSheetItem::ListStyle list; QStyleSheetItem::WhiteSpaceMode whitespacemode; QString contxt; bool selfnest; QStyleSheet* sheet; }; } /*! \class QStyleSheetItem qstylesheet.h \brief The QStyleSheetItem class provides an encapsulation of a set of text styles. \ingroup text A style sheet item consists of a name and a set of attributes that specifiy its font, color, etc. When used in a \link QStyleSheet style sheet\endlink (see styleSheet()), items define the name() of a rich text tag and the display property changes associated with it. The \link QStyleSheetItem::DisplayMode display mode\endlink attribute indicates whether the item is a block, an inline element or a list element; see setDisplayMode(). The treatment of whitespace is controlled by the \link QStyleSheetItem::WhiteSpaceMode white space mode\endlink; see setWhiteSpaceMode(). An item's margins are set with setMargin(), In the case of list items, the list style is set with setListStyle(). An item may be a hypertext link anchor; see setAnchor(). Other attributes are set with setAlignment(), setVerticalAlignment(), setFontFamily(), setFontSize(), setFontWeight(), setFontItalic(), setFontUnderline(), setFontStrikeOut and setColor(). */ /*! \enum QStyleSheetItem::AdditionalStyleValues \internal */ /*! \enum QStyleSheetItem::WhiteSpaceMode This enum defines the ways in which QStyleSheet can treat whitespace. \value WhiteSpaceNormal any sequence of whitespace (including line-breaks) is equivalent to a single space. \value WhiteSpacePre whitespace must be output exactly as given in the input. \value WhiteSpaceNoWrap multiple spaces are collapsed as with WhiteSpaceNormal, but no automatic line-breaks occur. To break lines manually, use the \c{<br>} tag. */ /*! \enum QStyleSheetItem::Margin \value MarginLeft left margin \value MarginRight right margin \value MarginTop top margin \value MarginBottom bottom margin \value MarginAll all margins (left, right, top and bottom) \value MarginVertical top and bottom margins \value MarginHorizontal left and right margins \value MarginFirstLine margin (indentation) of the first line of a paragarph (in addition to the MarginLeft of the paragraph) */ /*! Constructs a new style called \a name for the stylesheet \a parent. All properties in QStyleSheetItem are initially in the "do not change" state, except \link QStyleSheetItem::DisplayMode display mode\endlink, which defaults to \c DisplayInline. */ QStyleSheetItem::QStyleSheetItem( QStyleSheet* parent, const QString& name ) { d = new QStyleSheetItemData; d->stylename = name.lower(); d->sheet = parent; init(); if (parent) parent->insert( this ); } /*! Copy constructor. Constructs a copy of \a other that is not bound to any style sheet. */ QStyleSheetItem::QStyleSheetItem( const QStyleSheetItem & other ) { d = new QStyleSheetItemData; *d = *other.d; } /*! Destroys the style. Note that QStyleSheetItem objects become owned by QStyleSheet when they are created. */ QStyleSheetItem::~QStyleSheetItem() { delete d; } /*! Returns the style sheet this item is in. */ QStyleSheet* QStyleSheetItem::styleSheet() { return d->sheet; } /*! \overload Returns the style sheet this item is in. */ const QStyleSheet* QStyleSheetItem::styleSheet() const { return d->sheet; } /*! \internal Internal initialization */ void QStyleSheetItem::init() { d->disp = DisplayInline; d->fontitalic = Undefined; d->fontunderline = Undefined; d->fontstrikeout = Undefined; d->fontweight = Undefined; d->fontsize = Undefined; d->fontsizelog = Undefined; d->fontsizestep = 0; d->ncolumns = Undefined; d->col = QColor(); // !isValid() d->anchor = FALSE; d->align = Undefined; d->valign = VAlignBaseline; d->margin[0] = Undefined; d->margin[1] = Undefined; d->margin[2] = Undefined; d->margin[3] = Undefined; d->margin[4] = Undefined; d->list = (ListStyle) Undefined; d->whitespacemode = (WhiteSpaceMode) Undefined; d->selfnest = TRUE; d->lineSpacing = Undefined; } /*! Returns the name of the style item. */ QString QStyleSheetItem::name() const { return d->stylename; } /*! Returns the \link QStyleSheetItem::DisplayMode display mode\endlink of the style. \sa setDisplayMode() */ QStyleSheetItem::DisplayMode QStyleSheetItem::displayMode() const { return d->disp; } /*! \enum QStyleSheetItem::DisplayMode This enum type defines the way adjacent elements are displayed. \value DisplayBlock elements are displayed as a rectangular block (e.g. \c{<p>...</p>}). \value DisplayInline elements are displayed in a horizontally flowing sequence (e.g. \c{<em>...</em>}). \value DisplayListItem elements are displayed in a vertical sequence (e.g. \c{<li>...</li>}). \value DisplayNone elements are not displayed at all. */ /*! Sets the display mode of the style to \a m. \sa displayMode() */ void QStyleSheetItem::setDisplayMode(DisplayMode m) { d->disp=m; } /*! Returns the alignment of this style. Possible values are \c AlignAuto, \c AlignLeft, \c AlignRight, \c AlignCenter or \c AlignJustify. \sa setAlignment(), Qt::AlignmentFlags */ int QStyleSheetItem::alignment() const { return d->align; } /*! Sets the alignment to \a f. This only makes sense for styles with a \link QStyleSheetItem::DisplayMode display mode\endlink of DisplayBlock. Possible values are \c AlignAuto, \c AlignLeft, \c AlignRight, \c AlignCenter or \c AlignJustify. \sa alignment(), displayMode(), Qt::AlignmentFlags */ void QStyleSheetItem::setAlignment( int f ) { d->align = f; } /*! Returns the vertical alignment of the style. Possible values are \c VAlignBaseline, \c VAlignSub or \c VAlignSuper. \sa setVerticalAlignment() */ QStyleSheetItem::VerticalAlignment QStyleSheetItem::verticalAlignment() const { return d->valign; } /*! \enum QStyleSheetItem::VerticalAlignment This enum type defines the way elements are aligned vertically. This is only supported for text elements. \value VAlignBaseline align the baseline of the element (or the bottom, if the element doesn't have a baseline) with the baseline of the parent \value VAlignSub subscript the element \value VAlignSuper superscript the element */ /*! Sets the vertical alignment to \a valign. Possible values are \c VAlignBaseline, \c VAlignSub or \c VAlignSuper. The vertical alignment property is not inherited. \sa verticalAlignment() */ void QStyleSheetItem::setVerticalAlignment( VerticalAlignment valign ) { d->valign = valign; } /*! Returns TRUE if the style sets an italic font; otherwise returns FALSE. \sa setFontItalic(), definesFontItalic() */ bool QStyleSheetItem::fontItalic() const { return d->fontitalic > 0; } /*! If \a italic is TRUE sets italic for the style; otherwise sets upright. \sa fontItalic(), definesFontItalic() */ void QStyleSheetItem::setFontItalic(bool italic) { d->fontitalic = italic?1:0; } /*! Returns TRUE if the style defines a font shape; otherwise returns FALSE. A style does not define any shape until setFontItalic() is called. \sa setFontItalic(), fontItalic() */ bool QStyleSheetItem::definesFontItalic() const { return d->fontitalic != Undefined; } /*! Returns TRUE if the style sets an underlined font; otherwise returns FALSE. \sa setFontUnderline(), definesFontUnderline() */ bool QStyleSheetItem::fontUnderline() const { return d->fontunderline > 0; } /*! If \a underline is TRUE, sets underline for the style; otherwise sets no underline. \sa fontUnderline(), definesFontUnderline() */ void QStyleSheetItem::setFontUnderline(bool underline) { d->fontunderline = underline?1:0; } /*! Returns TRUE if the style defines a setting for the underline property of the font; otherwise returns FALSE. A style does not define this until setFontUnderline() is called. \sa setFontUnderline(), fontUnderline() */ bool QStyleSheetItem::definesFontUnderline() const { return d->fontunderline != Undefined; } /*! Returns TRUE if the style sets a strike out font; otherwise returns FALSE. \sa setFontStrikeOut(), definesFontStrikeOut() */ bool QStyleSheetItem::fontStrikeOut() const { return d->fontstrikeout > 0; } 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,446 +1,426 @@ /**************************************************************************** ** $Id$ ** ** Implementation of the QTextEdit class ** ** Created : 990101 ** ** Copyright (C) 1992-2000 Trolltech AS. All rights reserved. ** ** This file is part of the widgets module of the Qt GUI Toolkit. ** ** This file may be distributed under the terms of the Q Public License ** as defined by Trolltech AS of Norway and appearing in the file ** LICENSE.QPL included in the packaging of this file. ** ** This file may be distributed and/or modified under the terms of the ** GNU General Public License version 2 as published by the Free Software ** Foundation and appearing in the file LICENSE.GPL included in the ** packaging of this file. ** ** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition ** licenses may use this file in accordance with the Qt Commercial License ** Agreement provided with the Software. ** ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ** ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for ** information about Qt Commercial License Agreements. ** See http://www.trolltech.com/qpl/ for QPL licensing information. ** See http://www.trolltech.com/gpl/ for GPL licensing information. ** ** Contact info@trolltech.com if any conditions of this licensing are ** not clear to you. ** **********************************************************************/ #include "qtextedit.h" #include "qrichtext_p.h" -#include "qpainter.h" -#include "qpen.h" -#include "qbrush.h" -#include "qpixmap.h" -#include "qfont.h" -#include "qcolor.h" -#include "qstyle.h" -#include "qsize.h" -#include "qevent.h" -#include "qtimer.h" -#include "qapplication.h" #include "qlistbox.h" -#include "qvbox.h" -#include "qapplication.h" #include "qclipboard.h" -#include "qcolordialog.h" -#include "qfontdialog.h" -#include "qstylesheet.h" -#include "qdragobject.h" -#include "qurl.h" -#include "qcursor.h" -#include "qregexp.h" #include "qpopupmenu.h" #define ACCEL_KEY(k) "\t" + QString("Ctrl+" #k) using namespace Qt3; static bool qt_enable_richtext_copy = FALSE; struct QUndoRedoInfoPrivate { QTextString text; }; namespace Qt3 { class QTextEditPrivate { public: QTextEditPrivate() :preeditStart(-1),preeditLength(-1),ensureCursorVisibleInShowEvent(FALSE) { for ( int i=0; i<7; i++ ) id[i] = 0; } int id[ 7 ]; int preeditStart; int preeditLength; bool ensureCursorVisibleInShowEvent; QString scrollToAnchor; // used to deferr scrollToAnchor() until the show event when we are resized }; } static bool block_set_alignment = FALSE; /*! \class QTextEdit qtextedit.h \brief The QTextEdit widget provides a powerful single-page rich text editor. \ingroup basic \ingroup text \mainclass \tableofcontents \section1 Introduction and Concepts QTextEdit is an advanced WYSIWYG viewer/editor supporting rich text formatting using HTML-style tags. It is optimized to handle large documents and to respond quickly to user input. QTextEdit has three modes of operation: \table \header \i Mode \i Command \i Notes \row \i Plain Text Editor \i setTextFormat(PlainText) \i Set text with setText(); text() returns plain text. Text attributes (e.g. colors) can be set, but plain text is always returned.<sup>1.</sup> \row \i Rich Text Editor \i setTextFormat(RichText) \i Set text with setText(); text() returns rich text. Rich text editing is fairly limited. You can't set margins or insert images for example (although you can read and correctly display files that have margins set and that include images). This mode is mostly useful for editing small amounts of rich text. <sup>2.</sup> \row \i Text Viewer<sup>3.</sup> \i setReadOnly(TRUE) \i Set text with setText() or append() (which has no undo history so is faster and uses less memory); text() returns plain or rich text depending on the textFormat(). This mode can correctly display a large subset of HTML tags. \endtable <sup>1.</sup><small>We do \e not recommend using QTextEdit to create syntax highlighting editors because the current API is insufficient for this purpose. We hope to release a more complete API that will support syntax highlighting in a later release.</small> <sup>2.</sup><small>A more complete API that supports setting margins, images, etc., is planned for a later Qt release.</small> <sup>3.</sup><small>Qt 3.1 will provide a Log Viewer mode which is optimised for the fast and memory efficient display of large amounts of read only text.</small> We recommend that you always call setTextFormat() to set the mode you want to use. If you use \c AutoText then setText() and append() will try to determine whether the text they are given is plain text or rich text. If you use \c RichText then setText() and append() will assume that the text they are given is rich text. insert() simply inserts the text it is given. QTextEdit works on paragraphs and characters. A paragraph is a formatted string which is word-wrapped to fit into the width of the widget. By default when reading plain text, two newlines signify a paragraph. A document consists of zero or more paragraphs, indexed from 0. Characters are indexed on a per-paragraph basis, also indexed from 0. The words in the paragraph are aligned in accordance with the paragraph's alignment(). Paragraphs are separated by hard line breaks. Each character within a paragraph has its own attributes, for example, font and color. The text edit documentation uses the following concepts: \list \i \e{current format} -- this is the format at the current cursor position, \e and it is the format of the selected text if any. \i \e{current paragraph} -- the paragraph which contains the cursor. \endlist QTextEdit can display images (using QMimeSourceFactory), lists and tables. If the text is too large to view within the text edit's viewport, scrollbars will appear. The text edit can load both plain text and HTML files (a subset of HTML 3.2 and 4). The rendering style and the set of valid tags are defined by a styleSheet(). Custom tags can be created and placed in a custom style sheet. Change the style sheet with \l{setStyleSheet()}; see QStyleSheet for details. The images identified by image tags are displayed if they can be interpreted using the text edit's \l{QMimeSourceFactory}; see setMimeSourceFactory(). If you want a text browser with more navigation use QTextBrowser. If you just need to display a small piece of rich text use QLabel or QSimpleRichText. If you create a new QTextEdit, and want to allow the user to edit rich text, call setTextFormat(Qt::RichText) to ensure that the text is treated as rich text. (Rich text uses HTML tags to set text formatting attributes. See QStyleSheet for information on the HTML tags that are supported.). If you don't call setTextFormat() explicitly the text edit will guess from the text itself whether it is rich text or plain text. This means that if the text looks like HTML or XML it will probably be interpreted as rich text, so you should call setTextFormat(Qt::PlainText) to preserve such text. Note that we do not intend to add a full-featured web browser widget to Qt (because that would easily double Qt's size and only a few applications would benefit from it). The rich text support in Qt is designed to provide a fast, portable and efficient way to add reasonable online help facilities to applications, and to provide a basis for rich text editors. \section1 Using QTextEdit as a Display Widget QTextEdit can display a large HTML subset, including tables and images. The text is set or replaced using setText() which deletes any existing text and replaces it with the text passed in the setText() call. If you call setText() with legacy HTML (with setTextFormat(RichText) in force), and then call text(), the text that is returned may have different markup, but will render the same. Text can be inserted with insert(), paste(), pasteSubType() and append(). Text that is appended does not go into the undo history; this makes append() faster and consumes less memory. Text can also be cut(). The entire text is deleted with clear() and the selected text is deleted with removeSelectedText(). Selected (marked) text can also be deleted with del() (which will delete the character to the right of the cursor if no text is selected). Loading and saving text is achieved using setText() and text(), for example: \code QFile file( fileName ); // Read the text from a file if ( file.open( IO_ReadOnly ) ) { QTextStream ts( &file ); textEdit->setText( ts.read() ); } \endcode \code QFile file( fileName ); // Write the text to a file if ( file.open( IO_WriteOnly ) ) { QTextStream ts( &file ); ts << textEdit->text(); textEdit->setModified( FALSE ); } \endcode By default the text edit wraps words at whitespace to fit within the text edit widget. The setWordWrap() function is used to specify the kind of word wrap you want, or \c NoWrap if you don't want any wrapping. Call setWordWrap() to set a fixed pixel width \c FixedPixelWidth, or character column (e.g. 80 column) \c FixedColumnWidth with the pixels or columns specified with setWrapColumnOrWidth(). If you use word wrap to the widget's width \c WidgetWidth, you can specify whether to break on whitespace or anywhere with setWrapPolicy(). The background color is set differently than other widgets, using setPaper(). You specify a brush style which could be a plain color or a complex pixmap. Hypertext links are automatically underlined; this can be changed with setLinkUnderline(). The tab stop width is set with setTabStopWidth(). The zoomIn() and zoomOut() functions can be used to resize the text by increasing (decreasing for zoomOut()) the point size used. Images are not affected by the zoom functions. The lines() function returns the number of lines in the text and paragraphs() returns the number of paragraphs. The number of lines within a particular paragraph is returned by linesOfParagraph(). The length of the entire text in characters is returned by length(). You can scroll to an anchor in the text, e.g. \c{<a name="anchor">} with scrollToAnchor(). The find() function can be used to find and select a given string within the text. A read-only QTextEdit provides the same functionality as the (obsolete) QTextView. (QTextView is still supplied for compatibility with old code.) \section2 Read-only key bindings When QTextEdit is used read-only the key-bindings are limited to navigation, and text may only be selected with the mouse: \table \header \i Keypresses \i Action \row \i \e{UpArrow} \i Move one line up \row \i \e{DownArrow} \i Move one line down \row \i \e{LeftArrow} \i Move one character left \row \i \e{RightArrow} \i Move one character right \row \i \e{PageUp} \i Move one (viewport) page up \row \i \e{PageDown} \i Move one (viewport) page down \row \i \e{Home} \i Move to the beginning of the text \row \i \e{End} \i Move to the end of the text \row \i \e{Shift+Wheel} \i Scroll the page horizontally (the Wheel is the mouse wheel) \row \i \e{Ctrl+Wheel} \i Zoom the text \endtable The text edit may be able to provide some meta-information. For example, the documentTitle() function will return the text from within HTML \c{<title>} tags. The text displayed in a text edit has a \e context. The context is a path which the text edit's QMimeSourceFactory uses to resolve the locations of files and images. It is passed to the mimeSourceFactory() when quering data. (See QTextEdit() and \l{context()}.) \section1 Using QTextEdit as an Editor All the information about using QTextEdit as a display widget also applies here. The current format's attributes are set with setItalic(), setBold(), setUnderline(), setFamily() (font family), setPointSize(), setColor() and setCurrentFont(). The current paragraph's alignment is set with setAlignment(). Use setSelection() to select text. The setSelectionAttributes() function is used to indicate how selected text should be displayed. Use hasSelectedText() to find out if any text is selected. The currently selected text's position is available using getSelection() and the selected text itself is returned by selectedText(). The selection can be copied to the clipboard with copy(), or cut to the clipboard with cut(). It can be deleted with removeSelectedText(). The entire text can be selected (or unselected) using selectAll(). QTextEdit supports multiple selections. Most of the selection functions operate on the default selection, selection 0. If the user presses a non-selecting key, e.g. a cursor key without also holding down Shift, all selections are cleared. Set and get the position of the cursor with setCursorPosition() and getCursorPosition() respectively. When the cursor is moved, the signals currentFontChanged(), currentColorChanged() and currentAlignmentChanged() are emitted to reflect the font, color and alignment at the new cursor position. If the text changes, the textChanged() signal is emitted, and if the user inserts a new line by pressing Return or Enter, returnPressed() is emitted. The isModified() function will return TRUE if the text has been modified. QTextEdit provides command-based undo and redo. To set the depth of the command history use setUndoDepth() which defaults to 100 steps. To undo or redo the last operation call undo() or redo(). The signals undoAvailable() and redoAvailable() indicate whether the undo and redo operations can be executed. The indent() function is used to reindent a paragraph. It is useful for code editors, for example in <em>Qt Designer</em>'s code editor \e{Ctrl+I} invokes the indent() function. \section2 Editing key bindings The list of key-bindings which are implemented for editing: \table \header \i Keypresses \i Action \row \i \e{Backspace} \i Delete the character to the left of the cursor \row \i \e{Delete} \i Delete the character to the right of the cursor \row \i \e{Ctrl+A} \i Move the cursor to the beginning of the line \row \i \e{Ctrl+B} \i Move the cursor one character left \row \i \e{Ctrl+C} \i Copy the marked text to the clipboard (also \e{Ctrl+Insert} under Windows) \row \i \e{Ctrl+D} \i Delete the character to the right of the cursor \row \i \e{Ctrl+E} \i Move the cursor to the end of the line \row \i \e{Ctrl+F} \i Move the cursor one character right \row \i \e{Ctrl+H} \i Delete the character to the left of the cursor \row \i \e{Ctrl+K} \i Delete to end of line \row \i \e{Ctrl+N} \i Move the cursor one line down \row \i \e{Ctrl+P} \i Move the cursor one line up \row \i \e{Ctrl+V} \i Paste the clipboard text into line edit (also \e{Shift+Insert} under Windows) \row \i \e{Ctrl+X} \i Cut the marked text, copy to clipboard (also \e{Shift+Delete} under Windows) \row \i \e{Ctrl+Z} \i Undo the last operation \row \i \e{Ctrl+Y} \i Redo the last operation \row \i \e{LeftArrow} \i Move the cursor one character left \row \i \e{Ctrl+LeftArrow} \i Move the cursor one word left \row \i \e{RightArrow} \i Move the cursor one character right \row \i \e{Ctrl+RightArrow} \i Move the cursor one word right \row \i \e{UpArrow} \i Move the cursor one line up \row \i \e{Ctrl+UpArrow} \i Move the cursor one word up \row \i \e{DownArrow} \i Move the cursor one line down \row \i \e{Ctrl+Down Arrow} \i Move the cursor one word down \row \i \e{PageUp} \i Move the cursor one page up \row \i \e{PageDown} \i Move the cursor one page down \row \i \e{Home} \i Move the cursor to the beginning of the line \row \i \e{Ctrl+Home} \i Move the cursor to the beginning of the text \row \i \e{End} \i Move the cursor to the end of the line \row \i \e{Ctrl+End} \i Move the cursor to the end of the text \row \i \e{Shift+Wheel} \i Scroll the page horizontally (the Wheel is the mouse wheel) \row \i \e{Ctrl+Wheel} \i Zoom the text \endtable To select (mark) text hold down the Shift key whilst pressing one of the movement keystrokes, for example, <i>Shift+Right Arrow</i> will select the character to the right, and <i>Shift+Ctrl+Right Arrow</i> will select the word to the right, etc. By default the text edit widget operates in insert mode so all text that the user enters is inserted into the text edit and any text to the right of the cursor is moved out of the way. The mode can be changed to overwrite, where new text overwrites any text to the right of the cursor, using setOverwriteMode(). */ /*! \enum QTextEdit::KeyboardAction This enum is used by doKeyboardAction() to specify which action should be executed: \value ActionBackspace Delete the character to the left of the cursor. \value ActionDelete Delete the character to the right of the cursor. \value ActionReturn Split the paragraph at the cursor position. \value ActionKill If the cursor is not at the end of the paragraph, delete the text from the cursor position until the end of the paragraph. If the cursor is at the end of the paragraph, delete the hard line break at the end of the paragraph - this will cause this paragraph to be joined with the following paragraph. */ /*! \enum QTextEdit::VerticalAlignment This enum is used to set the vertical alignment of the text. \value AlignNormal Normal alignment \value AlignSuperScript Superscript \value AlignSubScript Subscript */ /*! \fn void QTextEdit::copyAvailable (bool yes) This signal is emitted when text is selected or de-selected in the text edit. When text is selected this signal will be emitted with \a yes set to TRUE. If no text has been selected or if the selected text is de-selected this signal is emitted with \a yes set to FALSE. If \a yes is TRUE then copy() can be used to copy the selection to the clipboard. If \a yes is FALSE then copy() does nothing. 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 @@ /*************************************************************************** application: : Oxygen begin : September 2002 copyright : ( C ) 2002 by Carsten Niehaus email : cniehaus@handhelds.org **************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * ( at your option ) any later version. * * * **************************************************************************/ -#include "oxygen.h" #include "calcdlgui.h" #include "kmolcalc.h" #include <qlineedit.h> #include <qmultilineedit.h> #include <qpushbutton.h> calcDlgUI::calcDlgUI() : CalcDlg() { kmolcalc = new KMolCalc; connect( calculate, SIGNAL( clicked() ), this, SLOT( calc() ) ); connect( clear_fields, SIGNAL( clicked() ), this, SLOT( clear() ) ); result->setReadOnly( true ); } void calcDlgUI::calc() { QString compound( formula->text() ); if ( compound.isEmpty() ) { clear(); return; } QString errors( kmolcalc->readFormula( compound ) ); QString mw, ea; double weight = kmolcalc->getWeight(); if ( errors == "OK" ) { mw.setNum( weight ); ea = kmolcalc->getEmpFormula() + " :\n" + kmolcalc->getEA(); } else { mw = "???"; ea = tr( "ERROR: \n" ).arg( errors )+ "\n"; } result->setText( mw ); anal_display->setText( ea ); } /** * * Clear all text entry / result fields. * */ void calcDlgUI::clear() { formula->clear(); result->clear(); anal_display->clear(); } 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 @@ /*************************************************************************** application: : Oxygen begin : September 2002 copyright : ( C ) 2002 by Carsten Niehaus email : cniehaus@handhelds.org **************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * ( at your option ) any later version. * * * **************************************************************************/ #include <qpe/config.h> #include "dataTable.h" -#include <qwidget.h> #include <qhbox.h> #include <qlabel.h> -#include <qfont.h> #include <qlayout.h> #include <qpe/qpeapplication.h> -#include <qstringlist.h> OxydataWidget::OxydataWidget(QWidget *parent, const char *name, const QStringList &list ) : QWidget( parent,name ), names( list ) { QGridLayout *qgrid = new QGridLayout( this, 2,1 ); QHBox *hbox = new QHBox( this ); left = new QLabel( hbox ); middle = new QLabel( hbox ); right = new QLabel( hbox ); right->setAlignment( AlignRight ); middle->setAlignment( AlignHCenter ); QFont bf; bf.setBold( true ); bf.setPointSize( bf.pointSize()+2 ); middle->setFont( bf ); DataTable = new OxydataTable( 9,2, this ); setTable(); qgrid->addWidget( hbox,0,0 ); qgrid->addWidget( DataTable,1,0 ); } void OxydataWidget::setElement( int el ) { QStringList::ConstIterator it = names.at(el); Config configobj( QPEApplication::qpeDir() +"share/oxygen/oxygendata", Config::File ); configobj.setGroup( QString::number( el+1 )); left->setText( configobj.readEntry( "Symbol" ) ); middle->setText( *it ); right->setText( QString::number( el+1 ) ); DataTable->setText( 0,1,tr( "%1 u" ).arg( configobj.readEntry( "Weight" ) ) ); DataTable->setText( 1,1,configobj.readEntry( "Block" ) ); DataTable->setText( 2,1,configobj.readEntry( "Group" ) ); DataTable->setText( 3,1,configobj.readEntry( "EN" ) ); DataTable->setText( 4,1,tr( "%1 pm" ).arg( configobj.readEntry( "AR" ) ) ) ; DataTable->setText( 5,1,tr( "%1 J" ).arg( configobj.readEntry( "IE" ) ) ); DataTable->setText( 6,1,tr( "%1 g/cm^3" ).arg( configobj.readEntry( "Density" ) ) ); DataTable->setText( 7,1,tr( "%1 K" ).arg( configobj.readEntry( "BP" ) ) ); DataTable->setText( 8,1,tr( "%1 K" ).arg( configobj.readEntry( "MP" ) ) ); } void OxydataWidget::setTable() const { DataTable->setText( 0,0, tr( "Weight" ) ); DataTable->setText( 1,0, tr( "Block" )) ; DataTable->setText( 2,0, tr( "Group" )) ; DataTable->setText( 3,0, tr( "Electronegativity" )) ; DataTable->setText( 4,0, tr( "Atomic radius" )) ; DataTable->setText( 5,0, tr( "Ionization Energy" )) ; DataTable->setText( 6,0, tr( "Density" )) ; DataTable->setText( 7,0, tr( "Boiling point" ) ); DataTable->setText( 8,0, tr( "Melting point" ) ); } void OxydataWidget::setLayout() { #warning this is not working and I have no idea why! // DataTable->setColumnWidth ( 0 , this->width()/2 ); // DataTable->setColumnWidth ( 1 , this->width()/2 ); //X DataTable->setColumnWidth ( 0 , 110 ); //X DataTable->setColumnWidth ( 1 , 110 ); } OxydataTable::OxydataTable(int numRows, int numCols, QWidget *parent, const char *name) : QTable(numRows, numCols,parent, name) { for (int zeile = 0; zeile < numRows; zeile++) for ( int spalte = 0; spalte < numCols; spalte++ ) { OxydataQTI *testus = new OxydataQTI (this, OxydataQTI::Never, "hm" ); setItem(zeile, spalte, (QTableItem*)testus); } this->setShowGrid( false ); this->setHScrollBarMode(QScrollView::AlwaysOff); this->horizontalHeader()->hide(); this->verticalHeader()->hide(); this->setTopMargin( 0 ); this->setLeftMargin( 0 ); } void OxydataTable::paintCell( QPainter *p, int row, int col, const QRect &cr, bool selected) { if ( cr.width() == 0 || cr.height() == 0 ) return; selected = FALSE; QTableItem *itm = item( row, col ); QColorGroup colgrp = colorGroup(); if ( itm ) { if ( row%2 ) colgrp.setColor( QColorGroup::Base, QColor( 180,200,210 ) ); else colgrp.setColor( QColorGroup::Base, QColor( 230,235,235 ) ); p->save(); itm->paint( p, colgrp, cr, selected ); p->restore(); } } OxydataQTI::OxydataQTI(QTable * table, EditType et, const QString & text ) : QTableItem ( table, et, text ) { } int OxydataQTI::alignment() const { if ( col()%2 ) { return AlignRight | AlignVCenter; }else return AlignLeft | AlignVCenter; }; 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 @@ /*************************************************************************** application: : Oxygen begin : September 2002 copyright : ( C ) 2002 by Carsten Niehaus email : cniehaus@handhelds.org **************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * ( at your option ) any later version. * * * **************************************************************************/ #include "datawidgetui.h" #include "dataTable.h" -#include <qpe/config.h> -#include <qstring.h> #include <qcombobox.h> #include <qlayout.h> -#include <qhbox.h> -#include <qlabel.h> -#include <qpe/qpeapplication.h> dataWidgetUI::dataWidgetUI(const QStringList &list) : QWidget() { names = list; this->setCaption( tr( "Chemical Data" )); QGridLayout *qgrid = new QGridLayout( this, 2,1 ); dataCombo = new QComboBox( this ); //read in all names of the 118 elements int i = 0; for ( QStringList::ConstIterator it = names.begin() ; it != names.end() ; ++it,i++) { dataCombo->insertItem( QString::number( i+1 )+" - "+*it ); } OxydataWidget *oxyDW = new OxydataWidget(this, "OxydataWidget_oxyDW", names); connect ( dataCombo, SIGNAL( activated(int) ), oxyDW, SLOT( setElement(int) ) ); oxyDW->setElement( 0 ); oxyDW->setLayout(); qgrid->addWidget( dataCombo, 0,0); qgrid->addWidget( oxyDW , 1,0 ); } 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 @@ /* * kmolcalc.cpp * * Copyright (C) 2000,2001 Tomislav Gountchev <tomi@idiom.com> * Copyright (C) 2002 Carsten Niehaus <cniehaus@handhelds.org> */ /** * KMOLCALC is the calculation engine. It knows about a hashtable of user defined atomic * weights and group definitions ELSTABLE, and the currently processed formula, stored * as a list of elements and their coefficients, ELEMENTS. */ #include "kmolcalc.h" -#include <qdict.h> -#include <qdir.h> -#include <qfile.h> #include <qpe/qpeapplication.h> /** * Construct a new calculator object. */ KMolCalc::KMolCalc() { elements = new ElementList; elstable = NULL; readElstable(); } KMolCalc::~KMolCalc() { delete elements; } void KMolCalc::readElstable() { weight = -1; // not calculated yet if (elstable) delete elstable; elstable = new QDict<SubUnit> (197, TRUE); elstable->setAutoDelete(TRUE); mwfile = QPEApplication::qpeDir() +"share/oxygen/kmolweights"; QFile f(mwfile); if (f.exists()) readMwfile(f); } /** * Parse a string S and construct the ElementList this->ELEMENTS, representing the * composition of S. Returns 0 if successful, or an error code (currently -1) if * parsing failed. * The elements is S must be valid element or group symbols, as stored in this->ELSTABLE. * See help files for correct formula syntax. */ QString KMolCalc::readFormula(const QString& s) { weight = -1; if (elements) delete elements; elements = new ElementList; return KMolCalc::readGroup(s, elements); } // read a formula group recursively. Called by readFormula. QString KMolCalc::readGroup(const QString& s, ElementList* els) { if (s.isEmpty()) return QString ("Enter a formula."); //ERROR int sl = s.length(); int i = 0; QString errors ("OK"); bool ok = TRUE; while (i < sl && ((s[i] <= '9' && s[i] >= '0') || s[i] == '.')) i++; double prefix = (i == 0 ? 1 : s.left(i).toDouble(&ok)); if (! ok || i == sl || prefix == 0) return QString ("Bad formula."); // ERROR ElementList* elstemp = new ElementList; while (i < sl) { int j = i; if (s[i] == '(') { ElementList* inner = new ElementList; int level = 1; // count levels of nested ( ). while (1) { if (i++ == sl) { delete inner; delete elstemp; return QString ("Bad formula."); //ERROR } if (s[i] == '(') level++; if (s[i] == ')') level--; if (level == 0) break; } errors = KMolCalc::readGroup(s.mid(j+1, i-j-1), inner); j = ++i; while (i < sl && ((s[i] <= '9' && s[i] >= '0') || s[i] == '.')) i++; double suffix = (i == j ? 1 : s.mid(j, i-j).toDouble(&ok)); if (! ok || suffix == 0) { delete inner; delete elstemp; return QString ("Bad formula."); // ERROR } inner->addTo(*elstemp, suffix); delete inner; inner = NULL; } else if ((s[i] >= 'A' && s[i] <= 'Z') || (s[i] >= 'a' && s[i] <= 'z')) { while (++i < sl && ((s[i] >= 'a' && s[i] <= 'z') || s[i] == '*' || s[i] == '\'')); QString elname = s.mid(j, i-j); j = i; while (i < sl && ((s[i] <= '9' && s[i] >= '0') || s[i] == '.')) i++; double suffix = (i == j ? 1 : s.mid(j, i-j).toDouble(&ok)); if (! ok || suffix == 0) { delete elstemp; return QString ("Bad formula."); // ERROR } SubUnit* group = elstable->find(elname); if (group == 0) { delete elstemp; return QString ("Undefined symbol: ") + elname; //ERROR } group->addTo(*elstemp, suffix); } else if (s[i] == '+') { if (elstemp->isEmpty()) { delete elstemp; return QString ("Bad formula."); //ERROR } elstemp->addTo(*els, prefix); delete elstemp; errors = KMolCalc::readGroup(s.mid(i+1, sl-i-1), els); return errors; } else { delete elstemp; return QString ("Bad formula."); //ERROR } } elstemp->addTo(*els, prefix); delete elstemp; return errors; } /** * Calculate and return the molecular weight of the current chemical formula. */ double KMolCalc::getWeight() { if (weight == -1) weight = elements->getWeight(elstable); return weight; } /** * Return the elemental composition of the current formula, as a string of tab-separated * element - percentage pairs, separated by newlines. */ QString KMolCalc::getEA() { if (weight == -1) weight = elements->getWeight(elstable); if (weight == -1) return QString("ERROR: Couldn't get Mw..."); // ERROR return elements->getEA(elstable, weight); } /** * Return the empirical formula of the current compound as a QString. */ QString KMolCalc::getEmpFormula() { return elements->getEmpFormula(); } // Read the element definition file. void KMolCalc::readMwfile(QFile& f) { if (! f.open(IO_ReadOnly)) return; //ERROR QTextStream fs (&f); QString line; while (! fs.eof()) { line = fs.readLine(); SubUnit* s = SubUnit::makeSubUnit(line); elstable->replace(s->getName(), s); } f.close(); } /** * Remove a group or element definition from ELSTABLE. */ void KMolCalc::undefineGroup (const QString& name) { elstable->remove (name); } /** * Add a new element name - atomic weight record to the ELSTABLE hashtable. Assumes * NAME has valid syntax. */ void KMolCalc::defineElement (const QString& name, double weight) { Element* el = new Element(name, weight); elstable->replace(name, el); } /** * Add a new group definition to the ELSTABLE. Returns 0 if OK, -1 if parsing FORMULA * fails. Assumes the syntax of grpname is correct. */ QString KMolCalc::defineGroup (const QString& grpname, const QString& formula) { ElementList* els = new ElementList(grpname); QString error = readGroup(formula, els); if (error != "OK") return error; if (els->contains(grpname)) return QString("Can't define a group recursively!\n"); elstable->replace(grpname, els); return QString("OK"); } 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 @@ /*************************************************************************** application: : Oxygen begin : September 2002 copyright : ( C ) 2002 by Carsten Niehaus email : cniehaus@handhelds.org **************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * ( at your option ) any later version. * * * **************************************************************************/ -#include "oxygen.h" -#include <qpe/config.h> #include "oxyframe.h" OxyFrame::OxyFrame(QWidget *parent, const char *name, QString symbol ) : QLabel(parent,name) { N = name; this->setFrameStyle( QFrame::Box ); this->setLineWidth( 0 ); this->setMidLineWidth( 1 ); this->setFrameShadow( QFrame::Sunken ); setMinimumSize(6,6); setScaledContents( true ); QFont font; font.setWeight(QFont::Light); font.setPixelSize(3); setFont( font ); setText( symbol ); } void OxyFrame::mousePressEvent ( QMouseEvent* /*e*/ ){ emit num( N ); }; 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 @@ /*************************************************************************** application: : Oxygen begin : September 2002 copyright : ( C ) 2002 by Carsten Niehaus email : cniehaus@handhelds.org **************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * ( at your option ) any later version. * * * **************************************************************************/ #include "oxygen.h" -#include <qapplication.h> #include <qtabwidget.h> -#include "calcdlg.h" #include "calcdlgui.h" #include "datawidgetui.h" #include "psewidget.h" Oxygen::Oxygen( QWidget *parent, const char *name, WFlags f) : QMainWindow( parent, name, f ) { loadNames(); calcDlgUI *CalcDlgUI = new calcDlgUI(); PSEWidget *pse = new PSEWidget(names); dataWidgetUI *DataWidgetUI = new dataWidgetUI(names); setCaption( tr( "Oxygen" ) ); QTabWidget *tabw = new QTabWidget( this , "qtab" ); tabw->addTab( pse, tr( "PSE" )); tabw->addTab( DataWidgetUI , tr( "Data" ) ); tabw->addTab( CalcDlgUI, tr( "Calculations" ) ); setCentralWidget( tabw ); } void Oxygen::loadNames() { names.clear(); names.append( tr("Hydrogen") ); names.append( tr("Helium") ); names.append( tr("Lithium") ); names.append( tr("Beryllium") ); names.append( tr("Boron") ); names.append( tr("Carbon") ); names.append( tr("Nitrogen") ); names.append( tr("Oxygen") ); names.append( tr("Fluorine") ); names.append( tr("Neon") ); names.append( tr("Sodium") ); names.append( tr("Magnesium") ); names.append( tr("Aluminum") ); names.append( tr("Silicon") ); names.append( tr("Phosphorus") ); names.append( tr("Sulfur") ); names.append( tr("Chlorine") ); names.append( tr("Argon") ); names.append( tr("Potassium") ); names.append( tr("Calcium") ); names.append( tr("Scandium") ); names.append( tr("Titanium") ); names.append( tr("Vanadium") ); names.append( tr("Chromium") ); names.append( tr("Manganese") ); names.append( tr("Iron") ); names.append( tr("Cobalt") ); names.append( tr("Nickel") ); names.append( tr("Copper") ); names.append( tr("Zinc") ); names.append( tr("Gallium") ); names.append( tr("Germanium") ); names.append( tr("Arsenic") ); names.append( tr("Selenium") ); names.append( tr("Bromine") ); names.append( tr("Krypton") ); names.append( tr("Rubidium") ); names.append( tr("Strontium") ); names.append( tr("Yttrium") ); names.append( tr("Zirconium") ); names.append( tr("Niobium") ); names.append( tr("Molybdenum") ); names.append( tr("Technetium") ); names.append( tr("Ruthenium") ); names.append( tr("Rhodium") ); names.append( tr("Palladium") ); names.append( tr("Silver") ); names.append( tr("Cadmium") ); names.append( tr("Indium") ); names.append( tr("Tin") ); names.append( tr("Antimony") ); names.append( tr("Tellurium") ); names.append( tr("Iodine") ); names.append( tr("Xenon") ); names.append( tr("Cesium") ); names.append( tr("Barium") ); names.append( tr("Lanthanum") ); names.append( tr("Cerium") ); names.append( tr("Praseodymium") ); names.append( tr("Neodymium") ); names.append( tr("Promethium") ); names.append( tr("Samarium") ); names.append( tr("Europium") ); names.append( tr("Gadolinium") ); names.append( tr("Terbium") ); names.append( tr("Dysprosium") ); names.append( tr("Holmium") ); names.append( tr("Erbium") ); names.append( tr("Thulium") ); names.append( tr("Ytterbium") ); names.append( tr("Lutetium") ); names.append( tr("Hafnium") ); names.append( tr("Tantalum") ); names.append( tr("Tungsten") ); names.append( tr("Rhenium") ); names.append( tr("Osmium") ); names.append( tr("Iridium") ); names.append( tr("Platinum") ); names.append( tr("Gold") ); names.append( tr("Mercury") ); names.append( tr("Thallium") ); names.append( tr("Lead") ); names.append( tr("Bismuth") ); names.append( tr("Polonium") ); names.append( tr("Astatine") ); names.append( tr("Radon") ); names.append( tr("Francium") ); names.append( tr("Radium") ); names.append( tr("Actinium") ); names.append( tr("Thorium") ); names.append( tr("Protactinium") ); names.append( tr("Uranium") ); names.append( tr("Neptunium") ); names.append( tr("Plutonium") ); names.append( tr("Americium") ); names.append( tr("Curium") ); names.append( tr("Berkelium") ); names.append( tr("Californium") ); names.append( tr("Einsteinium") ); names.append( tr("Fermium") ); names.append( tr("Mendelevium") ); names.append( tr("Nobelium") ); names.append( tr("Lawrencium") ); names.append( tr("Rutherfordium") ); names.append( tr("Dubnium") ); names.append( tr("Seaborgium") ); names.append( tr("Bohrium") ); names.append( tr("Hassium") ); names.append( tr("Meitnerium") ); } 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 @@ /*************************************************************************** application: : Oxygen begin : September 2002 copyright : ( C ) 2002, 2003 by Carsten Niehaus email : cniehaus@handhelds.org **************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * ( at your option ) any later version. * * * **************************************************************************/ #include <qpe/config.h> #include <qlayout.h> #include <qpe/qpeapplication.h> -#include <qlist.h> #include "dataTable.h" #include "psewidget.h" -#include "oxyframe.h" PSEWidget::PSEWidget(const QStringList &list) : QWidget() { this->setCaption( tr( "Periodic System" ) ); lastElement=1; names = list; QVBoxLayout *vlay = new QVBoxLayout( this ); QGridLayout *grid = new QGridLayout( 18,10 ); int h=0, v=0; Config configobj( QPEApplication::qpeDir() +"share/oxygen/oxygendata", Config::File ); for( int n = 0 ; n < 109 ; n++ ) { configobj.setGroup( QString::number( n+1 )); position( n+1,h,v ); PSEframe.append( new OxyFrame( this , QString::number(n), configobj.readEntry( "Symbol" ) ) ); grid->addWidget( PSEframe.current() , v/40+1 , h/40 ); PSEframe.current()->setMinimumHeight( 11 ); PSEframe.current()->setPalette( QPalette( PSEColor( configobj.readEntry( "Block" ) ) ) ); connect( PSEframe.current(), SIGNAL( num(QString) ), this, SLOT( slotShowElement(QString) )); connect( PSEframe.current(), SIGNAL( num(QString) ), this, SLOT( inverseColor(QString) )); } oxyDW = new OxydataWidget(this, "PSEWidget_oxyDW", names); oxyDW->setElement( 0 ); oxyDW->setLayout(); vlay->addLayout( grid ); vlay->addWidget( oxyDW ); } QColor PSEWidget::PSEColor( QString block ) const { QColor c; if ( block == "s" ) c.setRgb( 213 , 233 , 231 ); else if ( block == "d" ) c.setRgb( 200,230,160 ); else if ( block == "p" ) c.setRgb( 238,146,138 ); else if ( block == "f" ) c.setRgb( 190 , 190 , 190 ); return c; }; void PSEWidget::inverseColor( QString number) { Config configobj( QPEApplication::qpeDir() +"share/oxygen/oxygendata", Config::File ); configobj.setGroup( number ); QString block = configobj.readEntry( "Block" ); QColor c, d; c = PSEColor( block ); d = c.dark(); PSEframe.at( number.toUInt() )->setPalette( QPalette( d ) ); configobj.setGroup( QString::number( lastElement+1 ) ); block = configobj.readEntry( "Block" ); c = PSEColor( block ); PSEframe.at( lastElement )->setPalette( QPalette( c ) ); lastElement=number.toInt(); } void PSEWidget::slotShowElement(QString number) { oxyDW->setElement( number.toInt() ); }; void PSEWidget::position(int n, int& h, int& v) { //Hydrogen if (n == 1) { h=0; v=0; } //Helium if (n == 2) { h=680; v=0; } //Lithium if (n == 3) { h=0; v=40; } //Beryllium if (n == 4) { h=40; v=40; } //Boron-->Neon or Aluminum --> Argon if ((n >= 5 && n <= 10) || (n >= 13 && n <= 18)) for (int i = 1; i <= (6-(10-n)); i++) { h=((i*40)+440); v = 40; if (n >= 13) { v=80; h=(h-320); } } //Sodium if (n == 11) { h=0; v=80; } //Magnesium if (n == 12) { h=40; v=80; } //Potassium --> Uuo without La and Ac if ((n >= 19 && n <= 57) || (n >= 72 && n <= 89) || n >= 104) for (int i = 1; i <= 18; i++) { int f = n; if (n > 18) f = n-18; if (n > 36) f = n-36; if (n > 54) f = n-54; if (n > 71) f = n-68; if (n > 86) f = n-86; if (n > 103) f = n-100; h=((f*40)-40); v = 120; if (n >= 37) v=160; if (n >= 55) v=200; if (n >= 87) v=240; } //Lanthanum --> Lutetium and Actinum --> Lawrencium if ((n >= 58 && n <= 71) || (n >= 90 && n <= 103)) for (int i = 1; i <= 14; i++) { int f = n; if (n > 57) f = n-55; if (n > 88) f = n-87; h=(f*40); v = 290; if (n >= 90) v=330; } v += 10; } 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 @@ #include "account.h" -#include "transaction.h" -#include "transfer.h" #include "preferences.h" #include <qpixmap.h> #include <stdlib.h> extern Preferences *preferences; Account::Account () { adb = sqlite_open ( "qmaccounts.db", 0, NULL ); } Account::~Account () { sqlite_close ( adb ); } void Account::addAccount ( QString name, int parentid, float balance, int type, QString description, float creditlimit, int statementyear, int statementmonth, int statementday, float statementbalance, const char *currency ) { 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, (const char *) name, parentid, balance, type, (const char *) description, creditlimit, statementyear, statementmonth, statementday, statementbalance, currency ); } void Account::updateAccount ( QString name, QString description, QString currencycode, int accountid ) { 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 ); } void Account::deleteAccount ( int accountid ) { sqlite_exec_printf ( adb, "delete from accounts2 where accountid = %i;", 0, 0, 0, accountid ); } void Account::setAccountExpanded ( int expanded, int accountid ) { sqlite_exec_printf ( adb, "update accounts2 set r1 = %i where accountid = %i;", 0, 0, 0, expanded, accountid ); } int Account::getAccountExpanded ( int id ) { char **results; sqlite_get_table_printf ( adb, "select r1 from accounts2 where accountid = %i;", &results, 0, 0, 0, id ); if ( strlen ( results [1] ) == 0 ) return 0; else return atoi ( results [ 1 ] ); } int Account::getNumberOfAccounts () { char **results; sqlite_get_table ( adb, "select count() from accounts2;", &results, NULL, NULL, NULL ); return atoi ( results [ 1 ] ); } int Account::getNumberOfChildAccounts ( int id ) { char **results; sqlite_get_table_printf ( adb, "select count() from accounts2 where parent = %i;", &results, NULL, NULL, NULL, id ); return atoi ( results [ 1 ] ); } void Account::updateAccountBalance ( int accountid ) { // Here, we'll get a balance for the transactions in an account sqlite *tdb = sqlite_open ( "qmtransactions.db", 0, NULL ); int rows, columns; char **results; sqlite_get_table_printf ( tdb, "select sum (amount) from transactions where accountid= %i;", &results, &rows, &columns, NULL, accountid ); float transactionsbalance = strtod ( results [ 1 ], 0 ); sqlite_close ( tdb ); // next, we'll get a balance for all the transfers from the account sqlite *trdb = sqlite_open ( "qmtransfers.db", 0, NULL ); rows = 0; columns = 0; char **results2; sqlite_get_table_printf ( trdb, "select sum (amount) from transfers where fromaccount = %i;", &results2, &rows, &columns, NULL, accountid ); float fromtransfersbalance = ( strtod ( results2 [ 1 ], 0 ) * -1 ); // finally, we'll get a balance for all the transfers into the account rows = 0; columns= 0; char **results3; sqlite_get_table_printf ( trdb, "select sum (amount) from transfers where toaccount = %i;", &results3, &rows, &columns, NULL, accountid ); float totransfersbalance = strtod ( results3 [ 1 ], 0 ); sqlite_close ( trdb ); // calculate and update new balance sqlite_exec_printf ( adb, "update accounts2 set balance = %.2f where accountid = %i;", 0, 0, 0, ( transactionsbalance + fromtransfersbalance + totransfersbalance + getStatementBalance ( accountid ) ), accountid ); } void Account::changeParentAccountBalance ( int parentid ) { // select all child balances that share the parent of the current child account char **results; int rows; sqlite_get_table_printf ( adb, "select sum ( balance ) from accounts2 where parent = %i;", &results, &rows, NULL, NULL, parentid ); sqlite_exec_printf ( adb, "update accounts2 set balance = %.2f where accountid = %i;", 0, 0, 0, strtod ( results[ 1 ], NULL ), parentid ); } int Account::getParentAccountID ( int id ) { char **results; sqlite_get_table_printf ( adb, "select parent from accounts2 where accountid = %i;", &results, NULL, NULL, NULL, id ); return atoi ( results [ 1 ] ); } int Account::getParentAccountID ( QString accountname ) { char **results; sqlite_get_table_printf ( adb, "select parent from accounts2 where name= '%q';", &results, NULL, NULL, NULL, ( const char * ) accountname ); return atoi ( results [ 1 ] ); } void Account::displayAccounts ( QListView *listview ) { char **results; int rows, columns; sqlite_get_table ( adb, "select name, parent, balance, accountid, currency from accounts2;", &results, &rows, &columns, 0 ); // determine if we are using currency support int currency = preferences->getPreference ( 4 ); // remove all columns from the account display int counter; for ( counter = 0; counter <= columns; counter++ ) listview->removeColumn ( 0 ); // add columns to the account display listview->addColumn ( "Account", 0 ); int columntoalign = 1; if ( preferences->getPreference ( 4 ) == 1 ) // add the currency column if the user wants it { listview->addColumn ( "C", 0 ); columntoalign = 2; } listview->addColumn ( "Balance", 0 ); listview->addColumn ( "", 0 ); listview->setColumnAlignment ( columntoalign, Qt::AlignRight ); counter = 5; int total = ( rows + 1 ) * columns; while ( counter < total ) { int accountid = atoi ( results [ counter + 3 ] ); if ( atoi ( results [ counter + 1 ] ) == -1 ) { QListViewItem *parent = new QListViewItem ( listview ); parent->setText ( 0, results [ counter ] ); if ( currency == 0 ) { parent->setText ( 1, results [ counter + 2 ] ); parent->setText ( 2, results [ counter + 3 ] ); } else { if ( getNumberOfChildAccounts ( accountid ) == 0 ) // add the currency flag if this is a parent with no children { // create the string we'll use to set the currency pixmap QString filename = "/opt/QtPalmtop/pics/flags/"; QString flag = results [ counter + 4 ]; filename.append ( flag ); filename.append ( ".png" ); parent->setPixmap ( 1, QPixmap ( filename ) ); parent->setText ( 1, flag ); } parent->setText ( 2, results [ counter + 2 ] ); parent->setText ( 3, results [ counter + 3 ] ); } if ( getAccountExpanded ( accountid ) == 1 ) parent->setOpen ( TRUE ); //Start display child accounts for this parent int childcounter = 5; while ( childcounter < total ) { if ( atoi ( results [ childcounter + 1 ] ) == accountid ) { if ( currency == 0 ) QListViewItem *child = new QListViewItem ( parent, results [ childcounter ], results [ childcounter + 2 ], results [ childcounter + 3 ] ); else { // create the string we'll use to set the currency pixmap QString filename = "/opt/QtPalmtop/pics/flags/"; QString flag = results [ childcounter + 4 ]; filename.append ( flag ); filename.append ( ".png" ); QListViewItem *child = new QListViewItem ( parent, results [ childcounter ], "", results [ childcounter + 2 ], results [ childcounter + 3 ] ); child->setPixmap ( 1, QPixmap ( filename ) ); child->setText ( 1, flag ); } } childcounter = childcounter + 5; } //End display child accounts } counter = counter + 5; } // resize all columns appropriately if ( preferences->getPreference ( 4 ) == 0 ) { listview->setColumnWidth ( 0, preferences->getColumnPreference ( 1 ) ); listview->setColumnWidthMode ( 0, QListView::Manual ); listview->setColumnWidth ( 1, preferences->getColumnPreference ( 2 ) ); listview->setColumnWidthMode ( 1, QListView::Manual ); listview->setColumnWidthMode ( 2, QListView::Manual ); } else { listview->setColumnWidth ( 0, preferences->getColumnPreference ( 10 ) ); listview->setColumnWidthMode ( 0, QListView::Manual ); listview->setColumnWidth ( 1, preferences->getColumnPreference ( 11 ) ); listview->setColumnWidthMode ( 1, QListView::Manual ); listview->setColumnWidth ( 2, preferences->getColumnPreference ( 12 ) ); listview->setColumnWidthMode ( 2, QListView::Manual ); listview->setColumnWidthMode ( 3, QListView::Manual ); } // Now reset the column sorting to user preference int column = 0; int direction = 0; preferences->getSortingPreference ( 1, &column, &direction ); listview->setSorting ( column, direction ); } int Account::displayParentAccountNames ( QComboBox *combobox, QString indexstring ) { char **results; int rows, columns, index; index = 0; sqlite_get_table ( adb, "select name from accounts2 order by name asc;", &results, &rows, &columns, NULL ); int counter = 1; int indexcounter = 1; int total = ( rows + 1 ) * columns; while ( counter < total ) { if ( getParentAccountID ( results [ counter ] ) == -1 ) { combobox->insertItem ( results [ counter ], -1 ); if ( strcmp ( results [ counter ], indexstring ) == 0 ) index = indexcounter; indexcounter++; } counter ++; } return index; } int Account::getAccountType ( int accountid ) { char **results; sqlite_get_table_printf ( adb, "select type from accounts2 where accountid= %i;", &results, NULL, NULL, NULL, accountid ); return atoi ( results [ 1 ] ); } int Account::getStatementDay ( int accountid ) { char **results; sqlite_get_table_printf ( adb, "select statementday from accounts2 where accountid= %i;", &results, NULL, NULL, NULL, accountid ); return atoi ( results [ 1 ] ); } int Account::getStatementMonth ( int accountid ) { char **results; sqlite_get_table_printf ( adb, "select statementmonth from accounts2 where accountid= %i;", &results, NULL, NULL, NULL, accountid ); return atoi ( results [ 1 ] ); } int Account::getStatementYear ( int accountid ) { char **results; sqlite_get_table_printf ( adb, "select statementyear from accounts2 where accountid= %i;", &results, NULL, NULL, NULL, accountid ); return atoi ( results [ 1 ] ); } QString Account::getAccountDescription ( int accountid ) { char **results; sqlite_get_table_printf ( adb, "select description from accounts2 where accountid= %i;", &results, NULL, NULL, NULL, accountid ); return ( QString ) results [ 1 ]; } QString Account::getCurrencyCode ( int accountid ) { char **results; sqlite_get_table_printf ( adb, "select currency from accounts2 where accountid= %i;", &results, NULL, NULL, NULL, accountid ); return ( QString ) results [ 1 ]; } QString Account::getAccountName ( int accountid ) { char **results; sqlite_get_table_printf ( adb, "select name from accounts2 where accountid= %i;", &results, NULL, NULL, NULL, accountid ); return ( QString ) results [ 1 ]; } QString Account::getAccountBalance ( int accountid ) { char **results; sqlite_get_table_printf ( adb, "select balance from accounts2 where accountid= %i;", &results, NULL, NULL, NULL, accountid ); return ( QString ) results [ 1 ]; } float Account::getAccountCreditLimit ( int accountid ) { char **results; sqlite_get_table_printf ( adb, "select creditlimit from accounts2 where accountid = %i;", &results, NULL, NULL, NULL, accountid ); return strtod ( results [ 1 ], NULL ); } float Account::getStatementBalance ( int accountid ) { char **results; sqlite_get_table_printf ( adb, "select statementbalance from accounts2 where accountid = %i;", &results, NULL, NULL, NULL, accountid ); return strtod ( results [ 1 ], NULL ); } GreyBackgroundItem::GreyBackgroundItem ( QListView *parent ) : QListViewItem ( parent ) { } GreyBackgroundItem::GreyBackgroundItem ( QListView *parent, QString label1, QString label2, QString label3 ) : QListViewItem ( parent, label1, label2, label3 ) { } GreyBackgroundItem::GreyBackgroundItem ( QListView *parent, QString label1, QString label2, QString label3, QString label4 ) : QListViewItem ( parent, label1, label2, label3, label4 ) { } GreyBackgroundItem::GreyBackgroundItem ( QListView *parent, QString label1, QString label2, QString label3, QString label4, QString label5 ) : QListViewItem ( parent, label1, label2, label3, label4, label5 ) { } void GreyBackgroundItem::paintCell ( QPainter *p, const QColorGroup &cg, int column, int width, int alignment ) { QColorGroup _cg ( cg ); _cg.setColor ( QColorGroup::Base, Qt::lightGray ); QListViewItem::paintCell ( p, _cg, column, width, alignment ); } QStringList Account::getAccountNames () { QStringList accountnames; char **results; int rows, counter; sqlite_get_table ( adb, "select name from accounts2;", &results, &rows, 0, 0 ); for ( counter = 0; counter < rows; counter++ ) accountnames.append ( results [ counter+1 ] ); return accountnames; } QStringList Account::getAccountIDs () { QStringList accountids; char **results; int rows, counter; sqlite_get_table ( adb, "select accountid from accounts2;", &results, &rows, 0, 0 ); for ( counter = 0; counter < rows; counter++ ) accountids.append ( results [ counter+1 ] ); return accountids; } 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,393 +1,391 @@ -#include <qdatetime.h> #include <qmessagebox.h> #include <qheader.h> #include "accountdisplay.h" #include "newaccount.h" #include "transaction.h" #include "transferdialog.h" -#include "preferences.h" #include "transfer.h" extern Account *account; extern Transaction *transaction; extern Transfer *transfer; extern Preferences *preferences; AccountDisplay::AccountDisplay ( QWidget *parent ) : QWidget ( parent ) { cleared = 0; firstline = new QHBox ( this ); firstline->setSpacing ( 2 ); newaccount = new QPushButton ( firstline ); newaccount->setPixmap ( QPixmap ("/opt/QtPalmtop/pics/new.png") ); connect ( newaccount, SIGNAL ( released () ), this, SLOT ( addAccount () ) ); editaccount = new QPushButton ( firstline ); editaccount->setPixmap ( QPixmap ("/opt/QtPalmtop/pics/edit.png") ); connect ( editaccount, SIGNAL ( released () ), this, SLOT ( editAccount () ) ); deleteaccount = new QPushButton ( firstline ); deleteaccount->setPixmap( QPixmap ( "/opt/QtPalmtop/pics/delete.png") ); connect ( deleteaccount, SIGNAL ( released () ), this, SLOT ( deleteAccount () ) ); transferbutton = new QPushButton ( firstline ); transferbutton->setPixmap( QPixmap ( "/opt/QtPalmtop/pics/transfer.png") ); transferbutton->setToggleButton ( TRUE ); connect ( transferbutton, SIGNAL ( toggled ( bool ) ), this, SLOT ( accountTransfer ( bool ) ) ); listview = new QListView ( this ); listview->setAllColumnsShowFocus ( TRUE ); listview->setShowSortIndicator ( TRUE ); listview->setRootIsDecorated ( TRUE ); listview->setMultiSelection ( FALSE ); connect ( listview, SIGNAL ( expanded ( QListViewItem * ) ), this, SLOT ( setAccountExpanded ( QListViewItem * ) ) ); connect ( listview, SIGNAL ( collapsed ( QListViewItem * ) ), this, SLOT ( setAccountCollapsed ( QListViewItem * ) ) ); listview->header()->setTracking ( FALSE ); connect ( listview->header(), SIGNAL ( sizeChange ( int, int, int ) ), this, SLOT ( saveColumnSize ( int, int, int ) ) ); connect ( listview->header(), SIGNAL ( clicked ( int ) ), this, SLOT ( saveSortingPreference ( int ) ) ); layout = new QVBoxLayout ( this, 2, 5 ); layout->addWidget ( firstline ); layout->addWidget ( listview ); } void AccountDisplay::setTabs ( QWidget *newtab2, QTabWidget *newtabs ) { tab2 = newtab2; maintabs = newtabs; } void AccountDisplay::addAccount () { // initialize local variables int parentid = 0; type = 0; QString parentlist [ listview->childCount() + 1 ] [ 3 ] ; // create new account window for entering data NewAccount *newaccount = new NewAccount ( this ); int width = this->width(); newaccount->accountbox->setMaximumWidth ( ( int ) ( width * 0.5 ) ); newaccount->datebox->setMaximumWidth ( ( int ) ( width * 0.4 ) ); newaccount->childbox->setMaximumWidth ( ( int ) ( width * 0.5 ) ); newaccount->balancebox->setMaximumWidth ( ( int ) ( width * 0.4 ) ); newaccount->creditlimitbox->setMaximumWidth ( ( int ) ( width * 0.4 ) ); // if there are no accounts, disable the child check box if ( account->getNumberOfAccounts () == 0 ) newaccount->childcheckbox->setEnabled ( FALSE ); // if there are accounts, fill up the pulldown menu for // selecting a parent account. We should only add those parents without transactions else { int c = 0; QListViewItemIterator it ( listview ); for ( ; it.current(); ++it ) { int id = it.current()->text ( getIDColumn() ).toInt(); // iterate through accountdisplay listview and add parents with no transactions // add this item to the list box only if it is a parent and has no transactions if ( transfer->getNumberOfTransfers ( id ) == 0 && transaction->getNumberOfTransactions ( id ) == 0 && it.current()->parent() == 0 ) { newaccount->childbox->insertItem ( it.current()->text ( 0 ) ); parentlist [ c ] [ 0 ] = it.current()->text ( 0 ); parentlist [ c ] [ 1 ] = it.current()->text ( getIDColumn() ); parentlist [ c ] [ 2 ] = QString::number ( c ); c++; } } } if ( preferences->getPreference ( 4 ) == 0 ) newaccount->currencybox->setEnabled ( FALSE ); // enter today's date in the date box as default QDate today = QDate::currentDate (); int defaultday = today.day(); int defaultmonth = today.month(); int defaultyear = today.year(); newaccount->startdate->setText ( preferences->getDate ( defaultyear, defaultmonth, defaultday ) ); //add account information if user pushes OK button if ( newaccount->exec() == QDialog::Accepted ) { if ( newaccount->childcheckbox->isChecked () == TRUE ) // set a parent id and type for a child account { // go through the parentlist we created and determine the parent accountid // we can't use the name of the account because there may be two accounts // with the same name. This function does it all by accountid int counter; for ( counter = 0; counter < listview->childCount() + 1; counter++ ) if ( ( parentlist [ counter ] [ 2 ].toInt() ) == newaccount->childbox->currentItem() ) { parentid = parentlist [ counter ] [ 1 ].toInt(); break; } type = ( newaccount->accounttype->currentItem() ) + 6; // sets account ids for child accounts. See accountdisplay.h for types } else { parentid = -1; type = newaccount->accounttype->currentItem(); // sets account ids for parent accounts } // add the new account if ( newaccount->getDateEdited () == TRUE ) account->addAccount ( newaccount->accountname->text(), parentid, newaccount->accountbalance->text().toFloat(), type, newaccount->getDescription(), newaccount->creditlimit->text().toFloat(), newaccount->getYear(), newaccount->getMonth(), newaccount->getDay(), newaccount->accountbalance->text().toFloat(), newaccount->currencybox->currencybox->currentText() ); else account->addAccount ( newaccount->accountname->text (), parentid, newaccount->accountbalance->text().toFloat(), type, newaccount->getDescription(), newaccount->creditlimit->text().toFloat(), defaultyear, defaultmonth, defaultday, newaccount->accountbalance->text().toFloat(), newaccount->currencybox->currencybox->currentText() ); if ( parentid != -1 ) account->changeParentAccountBalance ( parentid ); // redisplay accounts // this function clears the account display first account->displayAccounts ( listview ); setToggleButton(); } maintabs->setTabEnabled ( tab2, FALSE ); } void AccountDisplay::deleteAccount () { if ( listview->selectedItem() == 0 ) QMessageBox::warning ( this, "QashMoney", "Please select an account\nto delete."); else if ( listview->selectedItem()->parent() == 0 && listview->selectedItem()->childCount() != 0 ) QMessageBox::warning ( this, "QashMoney", "Can't delete parent accounts\nwith children"); else { QMessageBox mb ( "Delete Account", "This will delete all transactions\nand transfers for this account.", QMessageBox::Information, QMessageBox::Ok, QMessageBox::Cancel, QMessageBox::NoButton ); if ( mb.exec() == QMessageBox::Ok ) { int accountid = listview->selectedItem()->text ( getIDColumn() ).toInt (); int parentid = account->getParentAccountID ( accountid ); // delete all the transactions and transfers for the account transaction->deleteAllTransactions ( accountid ); transfer->deleteAllTransfers ( accountid ); // delete the account account->deleteAccount ( accountid ); // update account balances if ( parentid != -1 ) account->changeParentAccountBalance ( parentid ); //redisplay accounts account->displayAccounts ( listview ); //remove all the columns from the accountdisplay if there are not any accounts if ( account->getNumberOfAccounts() == 0 ) { int columns = listview->columns(); int counter; for ( counter = 0; counter <= columns; counter++ ) listview->removeColumn ( 0 ); } setToggleButton(); } } maintabs->setTabEnabled ( tab2, FALSE ); } void AccountDisplay::setToggleButton () { // iterate through account display and determine how many "transferable" accounts we have // if there are less than two, disable the transfer button QListViewItemIterator it ( listview ); int counter = 0; for ( ; it.current(); ++it ) { // add one to counter if we find a transferable account if ( it.current()->parent() != 0 || ( it.current()->childCount() ) == 0 ) counter++; } if ( counter > 1 ) transferbutton->show(); else transferbutton->hide(); } void AccountDisplay::accountTransfer ( bool state ) { if ( state == TRUE ) { firstaccountid = -1; secondaccountid = -1; listview->clearSelection (); listview->setMultiSelection ( TRUE ); disableParentsWithChildren (); connect ( listview, SIGNAL ( clicked ( QListViewItem * ) ), this, SLOT ( getTransferAccounts ( QListViewItem * ) ) ); } else { firstaccountid = -1; secondaccountid = -1; listview->clearSelection (); listview->setMultiSelection ( FALSE ); enableAccounts (); disconnect ( listview, SIGNAL ( clicked ( QListViewItem * ) ), this, SLOT ( getTransferAccounts ( QListViewItem * ) ) ); } } void AccountDisplay::getTransferAccounts ( QListViewItem * item ) { if ( item->parent() != 0 || item->childCount() == 0 ) // only set an account for transfer if its a child or parent with no children { if ( firstaccountid == -1 ) firstaccountid = item->text ( getIDColumn() ).toInt(); // set first account if we've selected a valid account else if ( item->text ( getIDColumn() ).toInt() != firstaccountid ) // set the second account if its not equal to the first secondaccountid = item->text ( getIDColumn() ).toInt(); } // open transfer window if both accounts are set if ( firstaccountid != -1 && secondaccountid != -1 ) { // construct the transferdialog window TransferDialog *td = new TransferDialog ( this, firstaccountid, secondaccountid ); // enter today's date in the date box as default QDate today = QDate::currentDate (); int defaultday = today.day(); int defaultmonth = today.month(); int defaultyear = today.year(); td->date->setText ( preferences->getDate ( defaultyear, defaultmonth, defaultday ) ); if ( td->exec() == QDialog::Accepted ) { // set the cleared integer if the checkbox is checked if ( td->clearedcheckbox->isChecked() == TRUE ) cleared = 1; qDebug("Year from transferdialog = %i",td->getYear()); // add the transfer with a new date if its been edited or use the default date if ( td->getDateEdited () == TRUE ) transfer->addTransfer ( firstaccountid, account->getParentAccountID ( firstaccountid ), secondaccountid, account->getParentAccountID ( secondaccountid ), td->getDay(), td->getMonth(), td->getYear(), td->amount->text().toFloat(), cleared ); else transfer->addTransfer ( firstaccountid, account->getParentAccountID ( firstaccountid ), secondaccountid, account->getParentAccountID ( secondaccountid ), defaultday, defaultmonth, defaultyear, td->amount->text().toFloat(), cleared ); // update account balances of both accounts and parents if necessary account->updateAccountBalance ( firstaccountid ); if ( account->getParentAccountID ( firstaccountid ) != -1 ) account->changeParentAccountBalance ( account->getParentAccountID ( firstaccountid ) ); account->updateAccountBalance ( secondaccountid ); if ( account->getParentAccountID ( secondaccountid ) != -1 ) account->changeParentAccountBalance ( account->getParentAccountID ( secondaccountid ) ); // redisplay accounts account->displayAccounts ( listview ); } else { firstaccountid = -1; secondaccountid = -1; listview->clearSelection (); listview->setMultiSelection ( FALSE ); disconnect ( listview, SIGNAL ( clicked ( QListViewItem * ) ), this, SLOT ( getTransferAccounts ( QListViewItem * ) ) ); } // reset the accounts display window transferbutton->toggle(); // toggling this button with clear the window as well // reenable all the accounts so the transaction tab will be properly set enableAccounts (); } } void AccountDisplay::disableParentsWithChildren () { // iterate through accountdisplay listview and disable all the parents that have children QListViewItemIterator it ( listview ); for ( ; it.current(); ++it ) { if ( it.current()->parent() == 0 && it.current()->childCount() != 0 ) it.current()->setSelectable ( FALSE ); } } void AccountDisplay::enableAccounts () { // iterate through accountdisplay listview and enable all accounts QListViewItemIterator it ( listview ); for ( ; it.current(); ++it ) it.current()->setSelectable ( TRUE ); } void AccountDisplay::saveColumnSize ( int column, int oldsize, int newsize ) { switch ( column ) { case 0: if ( listview->columns() == 3 ) preferences->changeColumnPreference ( 1, newsize ); else preferences->changeColumnPreference ( 10, newsize ); break; case 1: if ( listview->columns() == 3 ) preferences->changeColumnPreference ( 2, newsize ); else preferences->changeColumnPreference ( 11, newsize ); break; case 2: preferences->changeColumnPreference ( 12, newsize ); break; } } void AccountDisplay::saveSortingPreference ( int column ) { preferences->changeSortingPreference ( 1, column ); } int AccountDisplay::getIDColumn () { int counter; int columns = listview->columns(); for ( counter = 0; counter <= columns; counter++ ) if ( listview->header()->label ( counter ).length() == 0 ) return counter; } void AccountDisplay::editAccount () { if ( listview->selectedItem() == 0 ) QMessageBox::warning ( this, "QashMoney", "Please select an account\nto edit."); else { // set the accountid int accountid = listview->selectedItem()->text ( getIDColumn() ).toInt(); //construct new dialog box QDialog *editaccountwindow = new QDialog ( this, 0, TRUE ); editaccountwindow->setCaption ( "Edit Account" ); // construct the items which will go in the dialog bix QLabel *namelabel = new QLabel ( "Account Name", editaccountwindow ); QLineEdit *accountname = new QLineEdit ( editaccountwindow ); QLabel *descriptionlabel = new QLabel ( "Account Description", editaccountwindow ); QLineEdit *accountdescription = new QLineEdit ( editaccountwindow ); Currency *currencybox = new Currency ( editaccountwindow ); QVBoxLayout *layout = new QVBoxLayout ( editaccountwindow, 5, 2 ); layout->addWidget ( namelabel ); layout->addWidget ( accountname ); layout->addWidget ( descriptionlabel ); layout->addWidget ( accountdescription ); layout->addWidget ( currencybox ); //set the account name accountname->setText ( listview->selectedItem()->text ( 0 ) ); //set the account description 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,394 +1,391 @@ #include <qmessagebox.h> #include <qheader.h> -#include <qfont.h> #include <sqlite.h> #include "budgetdisplay.h" #include "budget.h" -#include "newaccount.h" #include "datepicker.h" -#include "preferences.h" #include "transaction.h" extern Preferences *preferences; extern Budget *budget; extern Transaction *transaction; BudgetDisplay::BudgetDisplay ( QWidget *parent ) : QWidget ( parent ) { QFont font = this->font(); font.setWeight ( QFont::Bold ); //set the default date to today newDate = QDate::currentDate (); year = newDate.year(); month = newDate.month(); day = newDate.day(); datelabel = preferences->getDate ( year, month ); setCaption ( "Budget" ); firstline = new QHBox ( this ); firstline->setSpacing ( 2 ); secondline = new QHBox ( this ); secondline->setSpacing ( 10 ); menu = new QMenuBar ( this ); menu->setFrameStyle ( QFrame::Box | QFrame::Sunken ); budgetmenu = new QPopupMenu ( this ); lineitemsmenu = new QPopupMenu ( this ); datemenu = new QPopupMenu ( this ); menu->insertItem ( "Budget", budgetmenu ); menu->insertItem ( "Line Item", lineitemsmenu ); menu->insertItem ( "Date", datemenu ); budgetmenu->insertItem ( "New", this, SLOT ( newBudget () ), 0, 1 ); budgetmenu->insertItem ( "Edit", this, SLOT ( editBudget () ), 0, 2 ); budgetmenu->insertItem ( "Delete", this, SLOT ( deleteBudget () ), 0, 3 ); lineitemsmenu->insertItem ( "New", this, SLOT ( newLineItem () ), 0, 1 ); lineitemsmenu->insertItem ( "Edit", this, SLOT ( editLineItem () ), 0, 2 ); lineitemsmenu->insertItem ( "Delete", this, SLOT ( deleteLineItem () ), 0, 3 ); datemenu->insertItem ( "Change", this, SLOT ( showCalendar() ) ); budgetbox = new QComboBox ( firstline ); connect ( budgetbox, SIGNAL ( activated ( int ) ), this, SLOT ( setCurrentBudget ( int ) ) ); budgetview = new QComboBox ( firstline ); budgetview->insertItem ( "Month" ); budgetview->insertItem ( "Year" ); connect ( budgetview, SIGNAL ( activated ( int ) ), this, SLOT ( setCurrentView ( int ) ) ); budgeted = new QLabel ( secondline ); budgeted->setFont ( font ); actual = new QLabel ( secondline ); actual->setFont ( font ); date = new QLabel ( secondline ); date->setFont ( font ); listview = new QListView ( this ); listview->setAllColumnsShowFocus ( TRUE ); listview->setShowSortIndicator ( TRUE ); listview->setRootIsDecorated ( TRUE ); listview->setMultiSelection ( FALSE ); listview->addColumn ( "Line Item", preferences->getColumnPreference ( 13 ) ); // column id 13 listview->addColumn ( "Budget", preferences->getColumnPreference ( 14 ) ); // column id 14 listview->addColumn ( "Actual", preferences->getColumnPreference ( 15 ) ); // column id 15 listview->addColumn ( "", 0 ); // line item ids listview->setColumnWidthMode ( 0, QListView::Manual ); listview->setColumnWidthMode ( 1, QListView::Manual ); listview->setColumnWidthMode ( 2, QListView::Manual ); listview->setColumnAlignment ( 1, Qt::AlignRight ); listview->setColumnAlignment ( 2, Qt::AlignRight ); listview->setColumnWidthMode ( 3, QListView::Manual ); listview->header()->setTracking ( FALSE ); connect ( listview->header(), SIGNAL ( sizeChange ( int, int, int ) ), this, SLOT ( saveColumnSize ( int, int, int ) ) ); connect ( listview->header(), SIGNAL ( clicked ( int ) ), this, SLOT ( saveSortingPreference ( int ) ) ); // pull the column sorting preference from the preferences table, and configure the listview accordingly int column = 0; int direction = 0; preferences->getSortingPreference ( 3, &column, &direction ); listview->setSorting ( column, direction ); displayBudgetNames(); layout = new QVBoxLayout ( this, 2, 2 ); layout->setMenuBar ( menu ); layout->addWidget ( firstline ); layout->addWidget ( secondline ); layout->addWidget ( listview ); } void BudgetDisplay::deleteBudget () { listview->clear(); transaction->clearBudgetIDs ( currentbudget ); budget->deleteBudget ( currentbudget ); if ( budgetbox->count() != 0 ) displayBudgetNames(); checkBudgets(); } void BudgetDisplay::saveColumnSize ( int column, int oldsize, int newsize ) { switch ( column ) { case 0: preferences->changeColumnPreference ( 13, newsize ); break; case 1: preferences->changeColumnPreference ( 14, newsize ); break; case 2: preferences->changeColumnPreference ( 15, newsize ); break; } } void BudgetDisplay::saveSortingPreference ( int column ) { preferences->changeSortingPreference ( 3, column ); } int BudgetDisplay::getIDColumn () { int counter; int columns = listview->columns(); for ( counter = 0; counter <= columns; counter++ ) if ( listview->header()->label ( counter ).length() == 0 ) return counter; } void BudgetDisplay::newBudget () { constructBudgetWindow(); int response = nb->exec(); if ( response == 1 ) { // open a new budget object int addedbudget = budget->addBudget ( budgetname->text(), 0, description->text(), currencybox->currencybox->currentText(), day, month, year, day, month, year, 0 ); transaction->clearBudgetIDs ( addedbudget ); displayBudgetNames(); } checkBudgets(); } void BudgetDisplay::constructBudgetWindow () { //construct and format the new budget window nb = new QDialog ( this, 0, TRUE ); nb->setCaption ( "Budget" ); QLabel *namelabel = new QLabel ( "Budget Name", nb ); budgetname = new QLineEdit ( nb ); QLabel *descriptionlabel = new QLabel ( "Description", nb ); description = new QLineEdit ( nb ); currencybox = new Currency ( nb ); QBoxLayout *layout = new QVBoxLayout ( nb, 2, 2 ); layout->addWidget ( namelabel ); layout->addWidget ( budgetname ); layout->addWidget ( descriptionlabel ); layout->addWidget ( description ); layout->addWidget ( currencybox ); } void BudgetDisplay::displayBudgetNames () { budgetbox->clear(); if ( budget->getNumberOfBudgets() != 0 ) { ids = budget->getBudgetIDs(); for ( QStringList::Iterator it = ids->begin(); it != ids->end(); ++it ) { QString flag = "/opt/QtPalmtop/pics/flags/"; flag.append ( budget->getCurrency ( (*it).toInt() ) ); flag.append ( ".png" ); budgetbox->insertItem ( QPixmap ( flag ), budget->getBudgetName ( (*it).toInt() ) ); } setCurrentBudget ( 0 ); } else checkBudgets(); } void BudgetDisplay::setCurrentBudget ( int index ) { currentbudget = ( ids->operator[] ( index ).toInt() ); displayLineItems(); } void BudgetDisplay::setCurrentView ( int index ) { displayLineItems(); } void BudgetDisplay::showCalendar () { // create new calendar object and show it DatePicker *dp = new DatePicker ( QDate ( year, month, day ) ); dp->daylabel->hide(); dp->daybox->hide(); if ( budgetview->currentItem() == 1 ) { dp->monthlabel->hide(); dp->monthbox->hide(); } dp->setMaximumWidth ( ( int ) ( this->size().width() * 0.9 ) ); int response = dp->exec(); if ( response == 1 ) { // Set date integers year = dp->getYear(); if ( budgetview->currentItem() == 0 ) month = dp->getMonth(); else month = newDate.month(); datelabel = preferences->getDate ( year, month ); displayLineItems(); } } void BudgetDisplay::newLineItem () { //construct and format the new line item window constructLineItemWindow (); int response = newlineitem->exec(); if ( response == 1 ) { float amount; if ( lineitemtime->currentItem() == 0 ) amount = lineitemamount->text().toFloat(); else if ( lineitemtime->currentItem() == 1 ) amount = lineitemamount->text().toFloat() * 12; else amount = lineitemamount->text().toFloat() * 52; int lineitemadded = budget->addLineItem ( currentbudget, lineitemname->text(), amount, lineitemtime->currentItem() ); transaction->clearBudgetIDs ( currentbudget, lineitemadded ); displayLineItems(); } checkBudgets(); } void BudgetDisplay::constructLineItemWindow () { //construct and format the new budget window newlineitem = new QDialog ( this, 0, TRUE ); newlineitem->setCaption ( "Line Item" ); QLabel *namelabel = new QLabel ( "Line Item Name", newlineitem ); lineitemname = new QLineEdit ( newlineitem ); QLabel *budgetamountlabel = new QLabel ( "Budget Amount", newlineitem ); lineitemamount = new QLineEdit ( newlineitem ); QLabel *lineitemtimelabel = new QLabel ( "Per:", newlineitem ); lineitemtime = new QComboBox ( newlineitem ); lineitemtime->insertItem ( "Year" ); // type 0 lineitemtime->insertItem ( "Month" ); // type 1 lineitemtime->insertItem ( "Week" ); // type 2 QBoxLayout *layout = new QVBoxLayout ( newlineitem, 2, 2 ); layout->addWidget ( namelabel ); layout->addWidget ( lineitemname ); layout->addWidget ( budgetamountlabel ); layout->addWidget ( lineitemamount ); layout->addWidget ( lineitemtimelabel ); layout->addWidget ( lineitemtime ); } void BudgetDisplay::deleteLineItem () { if ( listview->selectedItem() != 0 ) { int lineitemid = listview->selectedItem()->text ( getIDColumn() ).toInt(); transaction->clearBudgetIDs ( currentbudget, lineitemid ); budget->deleteLineItem ( currentbudget, lineitemid ); displayBudgetNames(); } else QMessageBox::warning ( this, "QashMoney", "Please select a line item to delete." ); checkBudgets(); } void BudgetDisplay::displayLineItems () { listview->clear(); if ( budget->getNumberOfBudgets() != 0 ) { QString budgettable = budgetbox->currentText(); budgettable.append ( QString::number ( currentbudget ) ); budget->displayLineItems ( currentbudget, listview, month, year, budgetview->currentItem() ); totalactual = transaction->getActualTotal ( currentbudget, year, month, budgetview->currentItem() ); totalbudget = budget->getBudgetTotal ( currentbudget, budgetview->currentItem() ); updateBudgetInformation(); } } void BudgetDisplay::checkBudgets () { if ( budget->getNumberOfBudgets() == 0 ) { budgetview->setEnabled ( FALSE ); budgetmenu->setItemEnabled ( 2, FALSE ); budgetmenu->setItemEnabled ( 3, FALSE ); lineitemsmenu->setItemEnabled ( 1, FALSE ); lineitemsmenu->setItemEnabled ( 2, FALSE ); lineitemsmenu->setItemEnabled ( 3, FALSE ); } else { budgetview->setEnabled ( TRUE ); budgetmenu->setItemEnabled ( 2, TRUE ); budgetmenu->setItemEnabled ( 3, TRUE ); lineitemsmenu->setItemEnabled ( 1, TRUE ); lineitemsmenu->setItemEnabled ( 2, FALSE ); lineitemsmenu->setItemEnabled ( 3, FALSE ); if ( budget->getNumberOfLineItems ( currentbudget ) != 0 ) { lineitemsmenu->setItemEnabled ( 2, TRUE ); lineitemsmenu->setItemEnabled ( 3, TRUE ); } } } void BudgetDisplay::updateBudgetInformation () { if ( budgetview->currentItem() == 0 ) { datelabel = preferences->getDate ( year, month ); datelabel.prepend ( "Date: " ); date->setText ( datelabel ); } else date->setText ( QString::number ( year ) ); QString budget = "Budget: "; budget.append ( totalbudget ); budgeted->setText ( budget ); QString actualamount = "Actual: "; actualamount.append ( totalactual ); actual->setText ( actualamount ); } void BudgetDisplay::editBudget () { constructBudgetWindow(); //set the title budgetname->setText ( budget->getBudgetName ( currentbudget ) ); //set the description description->setText ( budget->getBudgetDescription ( currentbudget ) ); // retrieve the two character currency code then // go through the currencty box and find the code //set the currency box to that index number int count = currencybox->currencybox->count(); QString code = budget->getCurrency ( currentbudget ); for ( int counter = 0; count - 1; counter++ ) { if ( QString::compare (currencybox->currencybox->text ( counter ), code ) == 0 ) { currencybox->currencybox->setCurrentItem ( counter ); break; } } int response = nb->exec(); if ( response == 1 ) { budget->updateBudget ( budgetname->text(), description->text(), currencybox->currencybox->currentText(), currentbudget ); displayBudgetNames(); } } void BudgetDisplay::editLineItem () { if ( listview->selectedItem() != 0 ) { constructLineItemWindow(); // set the line item name lineitemname->setText ( listview->selectedItem()->text( 0 ) ); // set the line item time combobox int lineitemtype = budget->getLineItemTime ( currentbudget, listview->selectedItem()->text ( 3 ).toInt() ); lineitemtime->setCurrentItem ( lineitemtype ); // set the line item amount 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 @@ #include "newaccount.h" #include "calculator.h" #include "datepicker.h" -#include "transaction.h" -#include "preferences.h" -#include <qdatetime.h> #include <qmultilineedit.h> extern Preferences *preferences; NewAccount::NewAccount ( QWidget *parent, const char *name, bool modal ) : QDialog ( parent, name, modal ) { accountdescription = ""; dateedited = FALSE; setCaption( tr( "Account" ) ); namelabel = new QLabel ( "Account Name", this ); accountbox = new QHBox ( this ); accountname = new QLineEdit ( accountbox ); descriptionbutton = new QPushButton ( accountbox ); descriptionbutton->setPixmap ( QPixmap ( "/opt/QtPalmtop/pics/info.png" ) ); datelabel = new QLabel ( "Date", this ); datebox = new QHBox ( this ); startdate = new QLineEdit ( datebox ); startdate->setDisabled ( TRUE ); datebutton = new QPushButton ( datebox ); datebutton->setPixmap ( QPixmap ( "/opt/QtPalmtop/pics/date.png" ) ); childcheckbox = new QCheckBox ( this ); childcheckbox->setText( tr ( "Child Account" ) ); childlabel = new QLabel ( "Child of", this ); childbox = new QComboBox ( FALSE, this ); hideChildPulldownMenu (); balancelabel = new QLabel ( "Balance", this ); balancebox = new QHBox ( this ); accountbalance = new QLineEdit ( balancebox ); accountbalance->setText ( "0.00" ); balancecalculator = new QPushButton( balancebox ); balancecalculator->setPixmap ( QPixmap ( "/opt/QtPalmtop/pics/kcalc.png" ) ); creditlimitlabel = new QLabel ( "Credit Limit", this ); creditlimitbox = new QHBox ( this ); creditlimit = new QLineEdit ( creditlimitbox ); creditlimitbox->setEnabled ( FALSE ); creditlimitcalculator = new QPushButton( creditlimitbox ); creditlimitcalculator->setPixmap ( QPixmap ( "/opt/QtPalmtop/pics/kcalc.png" ) ); currencybox = new Currency ( this ); typelabel = new QLabel ( "Type", this ); accounttype = new QComboBox ( FALSE, this ); accounttype->insertItem( tr( "Bank" ) ); accounttype->insertItem( tr( "Cash" ) ); accounttype->insertItem( tr( "Credit Card" ) ); accounttype->insertItem( tr( "Equity" ) ); accounttype->insertItem( tr( "Asset" ) ); accounttype->insertItem( tr( "Liability" ) ); layout = new QGridLayout ( this, 7, 2, 4, 2 ); layout->addWidget ( namelabel , 0, 0, Qt::AlignLeft ); layout->addWidget ( accountbox, 1, 0, Qt::AlignLeft ); layout->addWidget ( datelabel, 2, 0, Qt::AlignLeft ); layout->addWidget ( datebox, 3, 0, Qt::AlignLeft ); layout->addWidget ( childcheckbox, 4, 0, Qt::AlignLeft ); layout->addWidget ( childlabel, 5, 0, Qt::AlignLeft ); layout->addWidget ( childbox, 6, 0, Qt::AlignLeft ); layout->addWidget ( balancelabel, 0, 1, Qt::AlignLeft ); layout->addWidget ( balancebox, 1, 1, Qt::AlignLeft ); layout->addWidget ( creditlimitlabel, 2, 1, Qt::AlignLeft ); layout->addWidget ( creditlimitbox, 3, 1, Qt::AlignLeft ); layout->addWidget ( currencybox, 4, 1, Qt::AlignLeft ); layout->addWidget ( typelabel, 5, 1, Qt::AlignLeft ); layout->addWidget ( accounttype, 6, 1, Qt::AlignLeft ); connect ( childcheckbox, SIGNAL ( clicked () ), this, SLOT ( showChildPulldownMenu() ) ); connect ( balancecalculator, SIGNAL ( released() ), this, SLOT ( showCalculator() ) ); connect ( creditlimitcalculator, SIGNAL ( released() ), this, SLOT ( showCreditLimitCalculator() ) ); connect ( accounttype, SIGNAL ( activated ( int ) ), this, SLOT ( activateCreditLimit ( int ) ) ); connect ( datebutton, SIGNAL ( released () ), this, SLOT ( showCalendar () ) ); connect ( descriptionbutton, SIGNAL ( released () ), this, SLOT ( addAccountDescription() ) ); } NewAccount::~NewAccount () { } void NewAccount::showChildPulldownMenu () { if ( childcheckbox->isChecked() == TRUE ) { childlabel->setEnabled ( TRUE ); childbox->setEnabled ( TRUE ); } else hideChildPulldownMenu(); } void NewAccount::hideChildPulldownMenu () { childlabel->setEnabled ( FALSE ); childbox->setEnabled ( FALSE ); } void NewAccount::showCalculator () { Calculator *calculator = new Calculator ( this ); calculator->setMaximumWidth ( ( int ) ( this->size().width() * 0.9 ) ); if ( calculator->exec () == QDialog::Accepted ) accountbalance->setText ( calculator->display->text() ); } void NewAccount::showCreditLimitCalculator () { Calculator *calculator = new Calculator ( this ); calculator->setMaximumWidth ( ( int ) ( this->size().width() * 0.9 ) ); if ( calculator->exec () == QDialog::Accepted ) creditlimit->setText ( calculator->display->text() ); } void NewAccount::activateCreditLimit ( int index ) { if ( index == 2 || index == 5 ) creditlimitbox->setEnabled ( TRUE ); else { creditlimit->clear (); creditlimitbox->setEnabled ( FALSE ); } } void NewAccount::showCalendar () { QDate newDate = QDate::currentDate (); DatePicker *dp = new DatePicker ( newDate ); dp->setMaximumWidth ( ( int ) ( this->size().width() * 0.9 ) ); int response = dp->exec(); if ( response == QDialog::Accepted ) { // Set date integers year = dp->getYear(); month = dp->getMonth(); day = dp->getDay(); // Set dateedited to TRUE // This tells the accountdisplay object that the user edited an account // and did change the date dateedited = TRUE; // Display date with our selected format startdate->setText ( preferences->getDate ( year, month, day ) ); } } bool NewAccount::getDateEdited () { return dateedited; } int NewAccount::getDay () { return day; } int NewAccount::getMonth () { return month; } int NewAccount::getYear () { return year; } QString NewAccount::getDescription () { return accountdescription; } void NewAccount::setDescription ( QString description ) { accountdescription = description; } void NewAccount::addAccountDescription () { // Function for adding or editing an account description. QDialog *description = new QDialog ( this, "description", TRUE ); description->setCaption ( "Notes" ); QMultiLineEdit *enter = new QMultiLineEdit ( description ); enter->setFixedSize ( ( int ) (this->width() * 0.75 ), ( int ) ( this->height() * 0.5 ) ); enter->setWrapColumnOrWidth ( ( int ) (this->width() * 0.75 ) ); enter->setWordWrap ( QMultiLineEdit::WidgetWidth ); if ( accountdescription != "(NULL)" ) enter->setText ( accountdescription ); if ( description->exec () == QDialog::Accepted ) accountdescription = enter->text (); } 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 @@ #include "newtransaction.h" #include "calculator.h" #include "datepicker.h" -#include "memory.h" #include "budget.h" -#include <qdatetime.h> #include <qmultilineedit.h> extern Budget *budget; extern Preferences *preferences; NewTransaction::NewTransaction ( QWidget* parent ) : QDialog ( parent, 0, TRUE ) { transactiondescription = ""; currentlineitem = -1; currentbudget = -1; dateedited = FALSE; setCaption( tr( "Transaction" ) ); // START FIRST COLUMN namelabel = new QLabel ( "Transaction", this ); transactionnamebox = new QHBox ( this ); transactionname = new QComboBox ( transactionnamebox ); transactionname->setEditable ( TRUE ); descriptionbutton = new QPushButton ( transactionnamebox ); descriptionbutton->setPixmap ( QPixmap ( "/opt/QtPalmtop/pics/info.png" ) ); connect ( descriptionbutton, SIGNAL ( released () ), this, SLOT ( addTransactionDescription() ) ); amountlabel = new QLabel ( "Amount", this ); transactionamountbox = new QHBox ( this ); transactionamount = new QLineEdit ( transactionamountbox ); transactionamount->setAlignment ( Qt::AlignRight ); transactionamount->setText ( "0.00" ); calculatorbutton = new QPushButton( transactionamountbox ); calculatorbutton->setPixmap ( QPixmap ( "/opt/QtPalmtop/pics/kcalc.png" ) ); connect ( calculatorbutton, SIGNAL ( released() ), this, SLOT ( showCalculator() ) ); datelabel = new QLabel ( "Date", this ); transactiondatebox = new QHBox ( this ); transactiondate = new QLineEdit ( transactiondatebox ); transactiondate->setAlignment ( Qt::AlignRight ); transactiondate->setDisabled ( TRUE ); datebutton = new QPushButton( transactiondatebox ); datebutton->setPixmap ( QPixmap ( "/opt/QtPalmtop/pics/date.png" ) ); connect ( datebutton, SIGNAL ( released () ), this, SLOT ( showCalendar () ) ); clearedcheckbox = new QCheckBox ( "Cleared", this ); depositbox = new QCheckBox ( "Credit", this ); // START SECOND COLUMN numberlabel = new QLabel ( "Number", this ); transactionnumber = new QLineEdit ( this ); budgetlabel = new QLabel ( "Budget", this ); budgetbox = new QComboBox ( FALSE, this ); lineitemlabel = new QLabel ( "LineItem", this ); lineitembox = new QComboBox ( FALSE, this ); layout = new QGridLayout ( this, 7, 2, 2, 2 ); layout->addWidget ( namelabel, 0, 0, Qt::AlignLeft ); layout->addWidget ( transactionnamebox, 1, 0, Qt::AlignLeft ); layout->addWidget ( amountlabel, 2, 0, Qt::AlignLeft ); layout->addWidget ( transactionamountbox, 3, 0, Qt::AlignLeft ); layout->addWidget ( datelabel, 4, 0, Qt::AlignLeft ); layout->addWidget ( transactiondatebox, 5, 0, Qt::AlignLeft ); layout->addWidget ( clearedcheckbox, 6, 0, Qt::AlignLeft ); layout->addWidget ( numberlabel, 0, 1, Qt::AlignLeft ); layout->addWidget ( transactionnumber, 1, 1, Qt::AlignLeft ); layout->addWidget ( budgetlabel, 2, 1, Qt::AlignLeft ); layout->addWidget ( budgetbox, 3, 1, Qt::AlignLeft ); layout->addWidget ( lineitemlabel, 4, 1, Qt::AlignLeft ); layout->addWidget ( lineitembox, 5, 1, Qt::AlignLeft ); layout->addWidget ( depositbox, 6, 1, Qt::AlignLeft ); if ( budget->getNumberOfBudgets() != 0 ) { budgetnameslist = budget->getBudgetNames(); budgetidslist = budget->getBudgetIDs(); budgetbox->insertStringList ( *budgetnameslist ); lineitemlabel->setEnabled ( FALSE ); lineitembox->setEnabled ( FALSE ); connect ( budgetbox, SIGNAL ( activated ( int ) ), this, SLOT ( setCurrentBudget ( int ) ) ); connect ( lineitembox, SIGNAL ( activated ( int ) ), this, SLOT ( setCurrentLineItem ( int ) ) ); } else { budgetlabel->setEnabled ( FALSE ); budgetbox->setEnabled ( FALSE ); lineitemlabel->setEnabled ( FALSE ); lineitembox->setEnabled ( FALSE ); } } NewTransaction::~NewTransaction () { } void NewTransaction::showCalculator () { Calculator *calculator = new Calculator ( this ); calculator->setMaximumWidth ( ( int ) ( this->size().width() * 0.9 ) ); if ( calculator->exec () == QDialog::Accepted ) transactionamount->setText ( calculator->display->text() ); } void NewTransaction::showCalendar () { QDate newDate = QDate::currentDate (); DatePicker *dp = new DatePicker ( newDate ); dp->setMaximumWidth ( ( int ) ( this->size().width() * 0.9 ) ); int response = dp->exec(); if ( response == QDialog::Accepted ) { // Set date integers year = dp->getYear(); month = dp->getMonth(); day = dp->getDay(); // Set dateedited to TRUE // This tells the transactiondisplay object that the user edited an transaction // and did change the date3 dateedited = TRUE; // Display date with our selected format transactiondate->setText ( preferences->getDate ( year, month, day ) ); } } bool NewTransaction::getDateEdited () { return dateedited; } int NewTransaction::getDay () { return day; } int NewTransaction::getMonth () { return month; } int NewTransaction::getYear () { return year; } QString NewTransaction::getDescription () { return transactiondescription; } void NewTransaction::setDescription ( QString description ) { transactiondescription = description; } void NewTransaction::addTransactionDescription () { // Function for adding or editing an transaction description. QDialog *description = new QDialog ( this, "description", TRUE ); description->setCaption ( "Notes" ); QMultiLineEdit *enter = new QMultiLineEdit ( description ); enter->setFixedSize ( ( int ) (this->width() * 0.75 ), ( int ) ( this->height() * 0.5 ) ); enter->setWrapColumnOrWidth ( ( int ) (this->width() * 0.75 ) ); enter->setWordWrap ( QMultiLineEdit::WidgetWidth ); if ( transactiondescription != "(NULL)" ) enter->setText ( transactiondescription ); if ( description->exec () == QDialog::Accepted ) transactiondescription = enter->text (); } int NewTransaction::getNameIndex ( QString name ) { int counter; int items = transactionname->count(); for ( counter = 0; ( items - 1 ); counter++ ) { if ( name == transactionname->text ( counter ) ) { return counter; break; } } return 0; } void NewTransaction::setCurrentBudget ( int index ) { if ( index != 0 ) { currentbudget = budgetidslist->operator[] ( index - 1 ).toInt(); lineitemslist = budget->getLineItems ( currentbudget ); lineitemidslist = budget->getLineItemIDs ( currentbudget ); lineitemlabel->setEnabled ( TRUE ); lineitembox->setEnabled ( TRUE ); lineitembox->clear(); lineitembox->insertStringList ( lineitemslist ); setCurrentLineItem ( 0 ); } else { lineitembox->clear(); lineitemlabel->setEnabled ( FALSE ); lineitembox->setEnabled ( FALSE ); currentlineitem = -1; currentbudget = -1; } } void NewTransaction::setCurrentLineItem ( int index ) { currentlineitem = ( lineitemidslist.operator[] ( index ).toInt() ); } int NewTransaction::getCurrentBudget () { return currentbudget; } int NewTransaction::getBudgetIndex ( int budgetid ) { currentbudget = budgetid; const QString budget = QString::number ( budgetid ); return budgetidslist->findIndex ( budget ); } int NewTransaction::getLineItemIndex ( int lineitemid ) { currentlineitem = lineitemid; const QString lineitem = QString::number ( lineitemid ); return lineitemidslist.findIndex ( lineitem ); } void NewTransaction::setLineItems () { lineitemslist = budget->getLineItems ( currentbudget ); lineitemidslist = budget->getLineItemIDs ( currentbudget ); lineitemlabel->setEnabled ( TRUE ); lineitembox->setEnabled ( TRUE ); lineitembox->clear(); lineitembox->insertStringList ( lineitemslist ); } int NewTransaction::getCurrentLineItem () { return currentlineitem; } void NewTransaction::setComboBoxes ( int budgetid, int lineitemid ) { const QString budgetname = QString::number ( budgetid ); budgetbox->setCurrentItem ( ( budgetidslist->findIndex ( budgetname ) ) ); currentbudget = budgetidslist->operator[] ( budgetbox->currentItem() - 1 ).toInt(); lineitemslist = budget->getLineItems ( currentbudget ); lineitemidslist = budget->getLineItemIDs ( currentbudget ); lineitemlabel->setEnabled ( TRUE ); lineitembox->setEnabled ( TRUE ); lineitembox->clear(); lineitembox->insertStringList ( lineitemslist ); const QString lineitem = QString::number ( lineitemid ); lineitembox->setCurrentItem ( lineitemidslist.findIndex ( lineitem ) ); currentlineitem = ( lineitemidslist.operator[] ( lineitembox->currentItem() ).toInt() ); } 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 @@ #include "preferencedialogs.h" #include "preferences.h" -#include <qlabel.h> extern Preferences *preferences; DatePreferences::DatePreferences ( QWidget* parent ) : QDialog ( parent, 0, TRUE ) { setCaption( tr( "Date" ) ); QLabel *datelabel = new QLabel ( "Format", this ); dateformat = new QComboBox ( this ); dateformat->setEditable ( FALSE ); dateformat->insertItem ( "yyyymmdd" ); dateformat->insertItem ( "yymmdd" ); dateformat->insertItem ( "mmddyyyy" ); dateformat->insertItem ( "mmddyy" ); dateformat->insertItem ( "yyyyddmm" ); dateformat->insertItem ( "yyddmm" ); dateformat->insertItem ( "ddmmyyyy" ); dateformat->insertItem ( "ddmmyy" ); connect ( dateformat, SIGNAL ( activated ( int ) ), this, SLOT ( changeDateFormat ( int ) ) ); QLabel *dateseparatorlabel = new QLabel ( "Separator", this ); dateseparator = new QComboBox ( this ); dateseparator->insertItem ( "/" ); dateseparator->insertItem ( "-" ); dateseparator->insertItem ( "." ); connect ( dateseparator, SIGNAL ( activated ( int ) ), this, SLOT ( changeDateSeparator ( int ) ) ); defaults = new QPushButton ( QPixmap ( "/opt/QtPalmtop/pics/defaults.png" ), "Defaults", this ); connect ( defaults, SIGNAL ( released () ), this, SLOT ( setDefaultDatePreferences () ) ); dateformat->setCurrentItem ( ( preferences->getPreference ( 1 ) ) - 1 ); dateseparator->setCurrentItem ( ( preferences->getPreference ( 2 ) ) - 1 ); layout = new QVBoxLayout ( this, 2, 2 ); layout->addWidget ( datelabel ); layout->addWidget ( dateformat ); layout->addWidget ( dateseparatorlabel ); layout->addWidget ( dateseparator ); layout->insertSpacing ( 4, 5 ); layout->addWidget ( defaults ); } DatePreferences::~DatePreferences () { } void DatePreferences::changeDateFormat ( int index ) { index ++; preferences->changePreference ( 1, index ); } void DatePreferences::changeDateSeparator ( int index ) { index ++; preferences->changePreference ( 2, index ); } void DatePreferences::setDefaultDatePreferences () { preferences->setDefaultDatePreferences (); dateformat->setCurrentItem ( ( preferences->getPreference ( 1 ) ) - 1 ); dateseparator->setCurrentItem ( ( preferences->getPreference ( 2 ) ) - 1 ); } // START TRANSACTION PREFERENCES TransactionPreferences::TransactionPreferences ( QWidget* parent ) : QDialog ( parent, 0, TRUE ) { setCaption( tr ( "Transaction" ) ); showclearedtransactions = new QCheckBox ( this ); showclearedtransactions->setText ( "Show Cleared Transactions" ); limittransactionsbox = new QHBox ( this ); limittransactionsbox->setSpacing ( 2 ); limittransactionslabel = new QLabel ( "Show ", limittransactionsbox ); limittransactions = new QComboBox ( limittransactionsbox ); QLabel *limittransactionslabel2 = new QLabel ( "of cleared transactions. ", limittransactionsbox ); limittransactions->insertItem ( "14 days" ); limittransactions->insertItem ( "30 days" ); limittransactions->insertItem ( "90 days" ); limittransactions->insertItem ( "180 days" ); limittransactions->insertItem ( "365 days" ); limittransactions->insertItem ( "All" ); limittransactions->setCurrentItem ( preferences->getPreference ( 7 ) ); excludetransfers = new QCheckBox ( this ); excludetransfers->setText ( "Include Transfers In Limit View" ); if ( preferences->getPreference ( 3 ) == 1 ) showclearedtransactions->setChecked ( TRUE ); else showclearedtransactions->setChecked ( FALSE ); if ( preferences->getPreference ( 6 ) == 1 ) excludetransfers->setChecked ( TRUE ); else excludetransfers->setChecked ( FALSE ); defaults = new QPushButton ( QPixmap ( "/opt/QtPalmtop/pics/defaults.png" ), "Defaults", this ); connect ( defaults, SIGNAL ( released () ), this, SLOT ( setDefaultTransactionPreferences () ) ); layout = new QVBoxLayout ( this, 2, 2 ); layout->addWidget ( showclearedtransactions ); layout->addWidget ( limittransactionsbox ); layout->addWidget ( excludetransfers ); layout->insertSpacing ( 3, 5 ); layout->addWidget ( defaults ); connect ( showclearedtransactions, SIGNAL ( toggled ( bool ) ), this, SLOT ( changeShowClearedPreference ( bool ) ) ); connect ( excludetransfers, SIGNAL ( toggled ( bool ) ), this, SLOT ( changeExcludeTranfersPreference ( bool ) ) ); connect ( limittransactions, SIGNAL ( activated ( int ) ), this, SLOT ( changeLimitTransactionsPreference ( int ) ) ); } TransactionPreferences::~TransactionPreferences () { } void TransactionPreferences::changeLimitTransactionsPreference ( int pref ) { preferences->changePreference ( 7, pref ); } void TransactionPreferences::changeShowClearedPreference ( bool state ) { if ( state == TRUE ) preferences->changePreference ( 3, 1 ); else preferences->changePreference ( 3, 0 ); } void TransactionPreferences::changeExcludeTranfersPreference ( bool state ) { if ( state == TRUE ) preferences->changePreference ( 6, 1 ); else preferences->changePreference ( 6, 0 ); } void TransactionPreferences::setDefaultTransactionPreferences () { preferences->changePreference ( 3, 0 ); preferences->changePreference ( 6, 0 ); preferences->changePreference ( 7, 0 ); showclearedtransactions->setChecked ( FALSE ); limittransactions->setCurrentItem ( 0 ); } // START ACCOUNT PREFERNCES AccountPreferences::AccountPreferences ( QWidget* parent ) : QDialog ( parent, 0, TRUE ) { setCaption( tr ( "Account" ) ); currencysupport = new QCheckBox ( this ); currencysupport->setText ( "Enable Currency Support" ); onetouch = new QCheckBox ( this ); onetouch->setText ( "One Touch Account Viewing" ); if ( preferences->getPreference ( 4 ) == 1 ) currencysupport->setChecked ( TRUE ); else currencysupport->setChecked ( FALSE ); if ( preferences->getPreference ( 5 ) == 1 ) onetouch->setChecked ( TRUE ); else onetouch->setChecked ( FALSE ); defaults = new QPushButton ( QPixmap ( "/opt/QtPalmtop/pics/defaults.png" ), "Defaults", this ); connect ( defaults, SIGNAL ( released () ), this, SLOT ( setDefaultAccountPreferences () ) ); layout = new QVBoxLayout ( this, 2, 2 ); layout->addWidget ( currencysupport ); layout->addWidget ( onetouch ); layout->insertSpacing ( 2, 5 ); layout->addWidget ( defaults ); connect ( currencysupport, SIGNAL ( toggled ( bool ) ), this, SLOT ( changeCurrencySupport ( bool ) ) ); connect ( onetouch, SIGNAL ( toggled ( bool ) ), this, SLOT ( changeOneTouchViewing ( bool ) ) ); } AccountPreferences::~AccountPreferences () { } void AccountPreferences::changeCurrencySupport ( bool state ) { if ( state == TRUE ) preferences->changePreference ( 4, 1 ); else preferences->changePreference ( 4, 0 ); } void AccountPreferences::changeOneTouchViewing ( bool state ) { if ( state == TRUE ) preferences->changePreference ( 5, 1 ); else preferences->changePreference ( 5, 0 ); } void AccountPreferences::setDefaultAccountPreferences () { preferences->changePreference ( 4, 0 ); preferences->changePreference ( 5, 0 ); currencysupport->setChecked ( FALSE ); onetouch->setChecked ( FALSE ); } 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,399 +1,396 @@ #include "transactiondisplay.h" #include "newtransaction.h" #include "account.h" #include "budget.h" #include "memory.h" #include "transfer.h" -#include "preferences.h" #include "calculator.h" #include "datepicker.h" -#include <qdatetime.h> #include <qmessagebox.h> #include <qheader.h> #include <qmultilineedit.h> -#include <qdatetime.h> extern Transaction *transaction; extern Budget *budget; extern Account *account; extern Preferences *preferences; extern Memory *memory; extern Transfer *transfer; TransactionDisplay::TransactionDisplay ( QWidget* parent ) : QWidget ( parent ) { // set transactiondisplay variables; accountid = 0; children = TRUE; firstline = new QHBox ( this ); firstline->setSpacing ( 2 ); newtransaction = new QPushButton ( firstline ); newtransaction->setPixmap ( QPixmap ("/opt/QtPalmtop/pics/new.png") ); connect ( newtransaction, SIGNAL ( released () ), this, SLOT ( addTransaction () ) ); edittransaction = new QPushButton ( firstline ); edittransaction->setPixmap( QPixmap ("/opt/QtPalmtop/pics/edit.png") ); connect ( edittransaction, SIGNAL ( released () ), this, SLOT ( checkListViewEdit () ) ); deletetransaction = new QPushButton ( firstline ); deletetransaction->setPixmap( QPixmap ( "/opt/QtPalmtop/pics/delete.png") ); connect ( deletetransaction, SIGNAL ( released () ), this, SLOT ( checkListViewDelete () ) ); toggletransaction = new QPushButton ( firstline ); toggletransaction->setPixmap( QPixmap ( "/opt/QtPalmtop/pics/redo.png") ); connect ( toggletransaction, SIGNAL ( released () ), this, SLOT ( checkListViewToggle () ) ); viewtransactionnotes = new QPushButton ( firstline ); viewtransactionnotes->setPixmap( QPixmap ( "/opt/QtPalmtop/pics/info.png") ); connect ( viewtransactionnotes, SIGNAL ( released () ), this, SLOT ( showTransactionNotes () ) ); secondline = new QHBox ( this ); secondline->setSpacing ( 5 ); name = new QLabel ( secondline ); balance = new QLabel ( secondline ); QLabel *limit = new QLabel ( "Limit", secondline ); limitbox = new QLineEdit ( secondline ); limitbox->setMinimumWidth ( ( int ) ( this->width() / 6 ) ); connect ( limitbox, SIGNAL ( textChanged ( const QString & ) ), this, SLOT ( limitDisplay ( const QString & ) ) ); listview = new QListView ( this ); listview->setAllColumnsShowFocus ( TRUE ); listview->setShowSortIndicator ( TRUE ); listview->header()->setTracking ( FALSE ); connect ( listview->header(), SIGNAL ( sizeChange ( int, int, int ) ), this, SLOT ( saveColumnSize ( int, int, int ) ) ); connect ( listview->header(), SIGNAL ( clicked ( int ) ), this, SLOT ( saveSortingPreference ( int ) ) ); layout = new QVBoxLayout ( this, 2, 2 ); layout->addWidget ( firstline ); layout->addWidget ( secondline ); layout->addWidget ( listview ); } void TransactionDisplay::addTransaction () { // create local variables int cleared = -1; // create new transaction window NewTransaction *newtransaction = new NewTransaction ( this ); int width = this->size().width(); newtransaction->transactionname->setMaximumWidth ( ( int ) ( width * 0.45 ) ); newtransaction->transactionname->setMinimumWidth ( ( int ) ( width * 0.35 ) ); newtransaction->lineitembox->setMaximumWidth ( ( int ) ( width * 0.45 ) ); newtransaction->transactiondatebox->setMaximumWidth ( ( int ) ( width * 0.4 ) ); newtransaction->transactionamountbox->setMaximumWidth ( ( int ) ( width * 0.4 ) ); newtransaction->transactionnumber->setMaximumWidth ( ( int ) ( width * 0.25 ) ); // enter today's date in the date box as defaul QDate today = QDate::currentDate (); int defaultday = today.day(); int defaultmonth = today.month(); int defaultyear = today.year(); newtransaction->transactiondate->setText ( preferences->getDate ( defaultyear, defaultmonth, defaultday ) ); // add memory items to the transactionname combobox memory->displayMemoryItems ( newtransaction->transactionname ); newtransaction->transactionname->insertItem ( "", 0 ); if ( newtransaction->exec () == QDialog::Accepted ) { if ( newtransaction->clearedcheckbox->isChecked () == TRUE ) // set a parent id and type for a child transaction cleared = 1; else cleared = 0; float amount = newtransaction->transactionamount->text().toFloat(); if ( newtransaction->depositbox->isChecked() == FALSE ) amount = amount * -1; // add the transaction name to the memory items memory->addMemoryItem ( newtransaction->transactionname->currentText() ); // add the transaction if ( newtransaction->getDateEdited () == TRUE ) transaction->addTransaction ( newtransaction->getDescription(), newtransaction->transactionname->currentText(), accountid, account->getParentAccountID ( accountid ), newtransaction->transactionnumber->text().toInt(), newtransaction->getDay(), newtransaction->getMonth(), newtransaction->getYear(), amount, cleared, newtransaction->getCurrentBudget(), newtransaction->getCurrentLineItem() ); else transaction->addTransaction ( newtransaction->getDescription(), newtransaction->transactionname->currentText(), accountid, account->getParentAccountID ( accountid ), newtransaction->transactionnumber->text().toInt(), defaultday, defaultmonth, defaultyear, amount, cleared, newtransaction->getCurrentBudget(), newtransaction->getCurrentLineItem() ); // redisplay transactions listview->clear(); QString displaytext = "%"; displaytext.prepend ( limitbox->text() ); setTransactionDisplayDate (); if ( transaction->getNumberOfTransactions() > 0 ) transaction->displayTransactions ( listview, accountid, children, displaytext, displaydate ); // redisplay transfers if ( transfer->getNumberOfTransfers() > 0 ) transfer->displayTransfers ( listview, accountid, children, displaydate ); // add the transaction amount to the account it's associated with // and update its parent account balance if necessary account->updateAccountBalance ( accountid ); if ( account->getParentAccountID ( accountid ) != -1 ) account->changeParentAccountBalance ( account->getParentAccountID ( accountid ) ); // format then reset the account balance redisplayAccountBalance (); } } void TransactionDisplay::checkListViewEdit () { if ( listview->selectedItem() == 0 ) QMessageBox::warning ( this, "QashMoney", "Please select a transaction\nto edit."); else if ( listview->currentItem()->text ( getIDColumn() ).toInt() < 0 ) editTransfer (); else editTransaction(); } void TransactionDisplay::showCalculator () { Calculator *calculator = new Calculator ( this ); if ( calculator->exec () == QDialog::Accepted ) amount->setText ( calculator->display->text() ); } void TransactionDisplay::showCalendar () { QDate newDate = QDate::currentDate (); DatePicker *dp = new DatePicker ( newDate ); if ( dp->exec () == QDialog::Accepted ) { year = dp->getYear(); month = dp->getMonth(); day = dp->getDay(); date->setText ( preferences->getDate ( year, month, day ) ); } } void TransactionDisplay::editTransfer () { transferid = listview->currentItem()->text ( getIDColumn() ).toInt(); fromaccount = transfer->getFromAccountID ( transferid ); toaccount = transfer->getToAccountID ( transferid ); year = transfer->getYear ( transferid ); month = transfer->getMonth ( transferid ); day = transfer->getDay ( transferid ); QDialog *editransfer = new QDialog ( this, "edittransfer", TRUE ); editransfer->setCaption ( "Transfer" ); QStringList accountnames = account->getAccountNames(); QStringList accountids = account->getAccountIDs(); QLabel *fromaccountlabel = new QLabel ( "From Account:", editransfer ); QFont f = this->font(); f.setWeight ( QFont::Bold ); fromaccountlabel->setFont ( f ); QComboBox *fromaccountbox = new QComboBox ( editransfer ); fromaccountbox->insertStringList ( accountnames ); fromaccountbox->setCurrentItem ( accountids.findIndex ( QString::number ( fromaccount ) ) ); QLabel *toaccountlabel = new QLabel ( "To Account:", editransfer ); toaccountlabel->setFont ( f ); QComboBox *toaccountbox = new QComboBox ( editransfer ); toaccountbox->insertStringList ( accountnames ); toaccountbox->setCurrentItem ( accountids.findIndex ( QString::number ( toaccount ) ) ); QLabel *datelabel = new QLabel ( "Date", editransfer ); QHBox *datebox = new QHBox ( editransfer ); datebox->setSpacing ( 2 ); date = new QLineEdit ( datebox ); date->setAlignment ( Qt::AlignRight ); date->setDisabled ( TRUE ); date->setText ( preferences->getDate ( year, month, day ) ); QPushButton *datebutton = new QPushButton ( datebox ); datebutton->setPixmap ( QPixmap ( "/opt/QtPalmtop/pics/date.png" ) ); connect ( datebutton, SIGNAL ( released () ), this, SLOT ( showCalendar () ) ); QLabel *amounttlabel = new QLabel ( "Amount", editransfer ); QHBox *amountbox = new QHBox ( editransfer ); amountbox->setSpacing ( 2 ); amount = new QLineEdit ( amountbox ); amount->setAlignment ( Qt::AlignRight ); amount->setText ( transfer->getAmount ( transferid ) ); QPushButton *calculatorbutton = new QPushButton( amountbox ); calculatorbutton->setPixmap ( QPixmap ( "/opt/QtPalmtop/pics/kcalc.png" ) ); connect ( calculatorbutton, SIGNAL ( released() ), this, SLOT ( showCalculator() ) ); QCheckBox *clearedcheckbox = new QCheckBox ( "Cleared", editransfer ); QBoxLayout *layout = new QVBoxLayout ( editransfer, 4, 2 ); layout->addWidget ( fromaccountlabel, Qt::AlignLeft ); layout->addWidget ( fromaccountbox, Qt::AlignLeft ); layout->addWidget ( toaccountlabel, Qt::AlignLeft ); layout->addWidget ( toaccountbox, Qt::AlignLeft ); layout->addSpacing ( 5 ); layout->addWidget ( datelabel, Qt::AlignLeft ); layout->addWidget ( datebox, Qt::AlignLeft ); layout->addWidget ( amounttlabel, Qt::AlignLeft ); layout->addWidget ( amountbox, Qt::AlignLeft ); layout->addWidget ( clearedcheckbox, Qt::AlignLeft ); if ( editransfer->exec() == QDialog::Accepted ) { //get fromaccount fromaccount = ( accountids.operator[] ( fromaccountbox->currentItem() ) ).toInt(); //get to account toaccount = ( accountids.operator[] ( toaccountbox->currentItem() ) ).toInt(); //set cleared flag int cleared = 0; if ( clearedcheckbox->isChecked() == TRUE ) cleared = 1; //update transfer transfer->updateTransfer ( fromaccount, account->getParentAccountID ( fromaccount ), toaccount, account->getParentAccountID ( toaccount ), day, month, year, amount->text().toFloat(), cleared, transferid ); account->updateAccountBalance ( fromaccount ); if ( account->getParentAccountID ( fromaccount ) != -1 ) account->changeParentAccountBalance ( account->getParentAccountID ( fromaccount ) ); updateAndDisplay ( toaccount ); } } void TransactionDisplay::editTransaction () { int cleared; // set the transaction id and budgetid int transactionid = listview->currentItem()->text ( getIDColumn() ).toInt(); int budgetid = transaction->getBudgetID ( transactionid ); int lineitemid = transaction->getLineItemID ( transactionid ); // create edit transaction window NewTransaction *newtransaction = new NewTransaction ( this ); int width = this->width(); newtransaction->transactionname->setMaximumWidth ( ( int ) ( width * 0.45 ) ); newtransaction->transactionname->setMinimumWidth ( ( int ) ( width * 0.35 ) ); newtransaction->lineitembox->setMaximumWidth ( ( int ) ( width * 0.45 ) ); newtransaction->transactiondatebox->setMaximumWidth ( ( int ) ( width * 0.4 ) ); newtransaction->transactionamountbox->setMaximumWidth ( ( int ) ( width * 0.4 ) ); newtransaction->transactionnumber->setMaximumWidth ( ( int ) ( width * 0.25 ) ); // enter the date in the date box newtransaction->year = transaction->getYear ( transactionid ); newtransaction->month = transaction->getMonth ( transactionid ); newtransaction->day = transaction->getDay ( transactionid ); newtransaction->transactiondate->setText ( preferences->getDate ( newtransaction->year, newtransaction->month, newtransaction->day ) ); // set the description newtransaction->setDescription ( transaction->getTransactionDescription ( transactionid ) ); // add memory items to the transactionname combobox memory->displayMemoryItems ( newtransaction->transactionname ); // add correct transaction name newtransaction->transactionname->setEditText ( transaction->getPayee ( transactionid ) ); // add transaction number newtransaction->transactionnumber->setText ( transaction->getNumber ( transactionid ) ); // add transaction amount newtransaction->transactionamount->setText ( transaction->getAbsoluteAmount ( transactionid ) ); // check for and set the correct budget if ( budgetid >= 1 ) // only do it if this transaction has a budget and line item { newtransaction->budgetbox->setCurrentItem ( newtransaction->getBudgetIndex ( budgetid ) + 1 ); if ( lineitemid >= 1 ) { newtransaction->setLineItems (); newtransaction->lineitembox->setCurrentItem ( newtransaction->getLineItemIndex ( lineitemid ) ); } else { newtransaction->lineitemlabel->setEnabled ( FALSE ); newtransaction->lineitembox->setEnabled ( FALSE ); } } else { newtransaction->lineitemlabel->setEnabled ( FALSE ); newtransaction->lineitembox->setEnabled ( FALSE ); } // check cleared checkbox if necessary if ( transaction->getCleared ( transactionid ) == 1 ) newtransaction->clearedcheckbox->setChecked ( TRUE ); // check deposit box if necessary if ( transaction->getAmount ( transactionid ).toFloat() > 0 ) newtransaction->depositbox->setChecked ( TRUE ); if ( newtransaction->exec () == QDialog::Accepted ) { if ( newtransaction->clearedcheckbox->isChecked () == TRUE ) cleared = 1; else cleared = 0; float amount = newtransaction->transactionamount->text().toFloat(); if ( newtransaction->depositbox->isChecked() == FALSE ) amount = amount * -1; // add the transaction name to the memory items memory->addMemoryItem ( newtransaction->transactionname->currentText() ); // update the transaction transaction->updateTransaction ( newtransaction->getDescription(), newtransaction->transactionname->currentText(), newtransaction->transactionnumber->text().toInt(), newtransaction->getDay(), newtransaction->getMonth(), newtransaction->getYear(), amount, cleared, newtransaction->getCurrentBudget(), newtransaction->getCurrentLineItem(), transactionid ); updateAndDisplay ( transaction->getAccountID ( transactionid ) ); } } void TransactionDisplay::updateAndDisplay ( int id ) { // redisplay transactions listview->clear(); QString displaytext = "%"; displaytext.prepend ( limitbox->text() ); setTransactionDisplayDate (); if ( transaction->getNumberOfTransactions() > 0 ) transaction->displayTransactions ( listview, accountid, children, displaytext, displaydate ); // redisplay transfers if ( transfer->getNumberOfTransfers() > 0 ) transfer->displayTransfers ( listview, accountid, children, displaydate ); // add the transaction amount to the account it's associated with // and update its parent account balance if necessary account->updateAccountBalance ( id ); if ( account->getParentAccountID ( id ) != -1 ) account->changeParentAccountBalance ( account->getParentAccountID ( id ) ); // format then reset the account balance redisplayAccountBalance (); } void TransactionDisplay::checkListViewDelete () { if ( listview->selectedItem() == 0 ) QMessageBox::warning ( this, "QashMoney", "Please select a transaction to\ndelete."); else deleteTransaction (); } void TransactionDisplay::deleteTransaction () { int transactionid = listview->currentItem()->text ( getIDColumn() ).toInt(); if ( transactionid > 0 ) // takes care of deleting transactions 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 @@ #include "transferdialog.h" #include "datepicker.h" #include "calculator.h" -#include <qdatetime.h> -#include <qfont.h> extern Preferences *preferences; extern Account *account; TransferDialog::TransferDialog ( QWidget *parent, int fromaccountid, int toaccountid ) : QDialog ( parent, 0, TRUE ) { dateedited = FALSE; setCaption ( "Transfer" ); fromaccountlabel = new QLabel ( "From account:", this ); QFont f = this->font(); f.setWeight ( QFont::Bold ); fromaccountlabel->setFont ( f ); fromaccount = new QLabel ( account->getAccountName ( fromaccountid ), this ); toaccountlabel = new QLabel ( "To Account:", this ); toaccountlabel->setFont ( f ); toaccount = new QLabel ( account->getAccountName ( toaccountid ), this ); datelabel = new QLabel ( "Date", this ); datebox = new QHBox ( this ); datebox->setSpacing ( 2 ); date = new QLineEdit ( datebox ); date->setAlignment ( Qt::AlignRight ); date->setDisabled ( TRUE ); datebutton = new QPushButton ( datebox ); datebutton->setPixmap ( QPixmap ( "/opt/QtPalmtop/pics/date.png" ) ); connect ( datebutton, SIGNAL ( released () ), this, SLOT ( showCalendar () ) ); amounttlabel = new QLabel ( "Amount", this ); amountbox = new QHBox ( this ); amountbox->setSpacing ( 2 ); amount = new QLineEdit ( amountbox ); amount->setAlignment ( Qt::AlignRight ); calculatorbutton = new QPushButton( amountbox ); calculatorbutton->setPixmap ( QPixmap ( "/opt/QtPalmtop/pics/kcalc.png" ) ); connect ( calculatorbutton, SIGNAL ( released() ), this, SLOT ( showCalculator() ) ); clearedcheckbox = new QCheckBox ( "Cleared", this ); layout = new QVBoxLayout ( this, 4, 2 ); layout->addWidget ( fromaccountlabel, Qt::AlignLeft ); layout->addWidget ( fromaccount, Qt::AlignLeft ); layout->addWidget ( toaccountlabel, Qt::AlignLeft ); layout->addWidget ( toaccount, Qt::AlignLeft ); layout->addSpacing ( 5 ); layout->addWidget ( datelabel, Qt::AlignLeft ); layout->addWidget ( datebox, Qt::AlignLeft ); layout->addWidget ( amounttlabel, Qt::AlignLeft ); layout->addWidget ( amountbox, Qt::AlignLeft ); layout->addWidget ( clearedcheckbox, Qt::AlignLeft ); } bool TransferDialog::getDateEdited () { return dateedited; } void TransferDialog::showCalendar () { QDate newDate = QDate::currentDate (); DatePicker *dp = new DatePicker ( newDate ); if ( dp->exec () == QDialog::Accepted ) { // Set date integers year = dp->getYear(); month = dp->getMonth(); day = dp->getDay(); // Set dateedited to TRUE // This tells the accountdisplay object that the user edited an account // and did change the date dateedited = TRUE; // Display date with our selected format date->setText ( preferences->getDate ( year, month, day ) ); } } int TransferDialog::getDay () { return day; } int TransferDialog::getMonth () { return month; } int TransferDialog::getYear () { return year; } void TransferDialog::showCalculator () { Calculator *calculator = new Calculator ( this ); if ( calculator->exec () == QDialog::Accepted ) amount->setText ( calculator->display->text() ); } 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,421 +1,420 @@ /********************************************************************** ** Copyright (C) 2000 Trolltech AS. All rights reserved. ** ** This file is part of Qtopia Environment. ** ** This file may be distributed and/or modified under the terms of the ** GNU General Public License version 2 as published by the Free Software ** Foundation and appearing in the file LICENSE.GPL included in the ** packaging of this file. ** ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ** ** See http://www.trolltech.com/gpl/ for GPL licensing information. ** ** Contact info@trolltech.com if any conditions of this licensing are ** not clear to you. ** **********************************************************************/ /* local includes */ #include "tableviewer.h" #include "ui/tvbrowseview.h" #include "ui/tvfilterview.h" #include "ui/tvlistview.h" #include "ui/tveditview.h" #include "ui/tvkeyedit.h" #include "db/datacache.h" /* QPE includes */ #include <qpe/fileselector.h> #include <qpe/resource.h> #include <qpe/qpetoolbar.h> /* QTE includes */ #include <qmenubar.h> -#include <qpe/qpetoolbar.h> #include <qpopupmenu.h> #include <qapplication.h> #include <qwidgetstack.h> #include <qlayout.h> #include <qbuffer.h> /*! \class TableViewerWindow \brief The main window widget of the application This is the main widget of the table viewer application. It is the co-ordination point. */ /*! Constructs a new TableViewerWindow */ TableViewerWindow::TableViewerWindow(QWidget *parent, const char *name, WFlags f) : QMainWindow(parent, name, f) { setCaption(tr("Table Viewer")); /* Build data */ ds = new DBStore(); doc.setType("text/x-xml-tableviewer"); doc.setName("table"); dirty = FALSE; ts.current_column = 0; ts.kRep = ds->getKeys(); /* build menus */ menu = new QMenuBar(this, 0); QPopupMenu *file_menu = new QPopupMenu; file_menu->insertItem("New", this, SLOT(newDocument())); file_menu->insertItem("Open", this, SLOT(selectDocument())); file_menu->insertSeparator(); file_menu->insertItem("Properties"); /* later will want to set this up to clean up first via this, SLOT(quit) */ menu->insertItem("Document", file_menu); QPopupMenu *edit_menu = new QPopupMenu; edit_menu->insertItem("Edit Item", this, SLOT(editItemSlot())); edit_menu->insertItem("Edit Keys", this, SLOT(editKeysSlot())); edit_menu->insertItem("Edit filters", this, SLOT(filterViewSlot())); menu->insertItem("Edit", edit_menu); QPopupMenu *view_menu = new QPopupMenu; view_menu->insertItem("Browse View", this, SLOT(browseViewSlot())); view_menu->insertItem("List View", this, SLOT(listViewSlot())); menu->insertItem("View", view_menu); QVBoxLayout *main_layout = new QVBoxLayout; /* Build tool bar */ navigation = new QToolBar(this, "navigation"); QToolButton *newItemButton = new QToolButton( QIconSet(Resource::loadPixmap("new")), "New Item", QString::null, this, SLOT(newItemSlot()), navigation, "New Item"); QToolButton *editItemButton = new QToolButton( QIconSet(Resource::loadPixmap("edit")), "Edit Item", QString::null, this, SLOT(editItemSlot()), navigation, "Edit Item"); QToolButton *deleteItemButton = new QToolButton( QIconSet(Resource::loadPixmap("trash")), "Delete Item", QString::null, this, SLOT(deleteItemSlot()), navigation, "Delete Item"); navigation->addSeparator(); QToolButton *firstItemButton = new QToolButton( QIconSet(Resource::loadPixmap("fastback")), "First Item", QString::null, this, SLOT(firstItem()), navigation, "First Item"); QToolButton *previousItemButton = new QToolButton( QIconSet(Resource::loadPixmap("back")), "Previous Item", QString::null, this, SLOT(previousItem()), navigation, "Previous Item"); QToolButton *nextItemButton = new QToolButton( QIconSet(Resource::loadPixmap("forward")), "Next Item", QString::null, this, SLOT(nextItem()), navigation, "Next Item"); QToolButton *lastItemButton = new QToolButton( QIconSet(Resource::loadPixmap("fastforward")), "Last Item", QString::null, this, SLOT(lastItem()), navigation, "Last Item"); navigation->addSeparator(); QToolButton *browseButton = new QToolButton( QIconSet(Resource::loadPixmap("day")), "View Single Item", QString::null, this, SLOT(browseViewSlot()), navigation, "View Single Item"); QToolButton *listButton = new QToolButton( QIconSet(Resource::loadPixmap("month")), "View Multiple Items", QString::null, this, SLOT(listViewSlot()), navigation, "View Multiple Items"); setToolBarsMovable(FALSE); setToolBarsMovable(FALSE); setToolBarsMovable(FALSE); /* Build widgets */ browseView = new TVBrowseView(&ts, this, 0); listView = new TVListView(&ts, this, 0); filterView = new TVFilterView(&ts, this, 0); fileSelector = new FileSelector("text/csv;text/x-xml-tableviewer", this, "fileselector"); fileSelector->setNewVisible(FALSE); fileSelector->setCloseVisible(FALSE); cw = new QWidgetStack(this, 0); cw->addWidget(listView, ListState); cw->addWidget(browseView, BrowseState); cw->addWidget(filterView, FilterState); cw->addWidget(fileSelector, FileState); current_view = FileState; cw->raiseWidget(current_view); fileSelector->reread(); connect(browseView, SIGNAL(searchOnKey(int, TVVariant)), this, SLOT(searchOnKey(int, TVVariant))); connect(browseView, SIGNAL(sortChanged(int)), this, SLOT(setPrimaryKey(int))); connect(fileSelector, SIGNAL(closeMe()), this, SLOT(browseViewSlot())); connect(fileSelector, SIGNAL(fileSelected(const DocLnk &)), this, SLOT(openDocument(const DocLnk &))); main_layout->addWidget(menu); main_layout->addWidget(cw); setCentralWidget(cw); } /*! Destroys the TableViewerWindow */ TableViewerWindow::~TableViewerWindow() { if(dirty) saveDocument(); } /*! Opens a file dialog and loads the file specified by the dialog */ void TableViewerWindow::selectDocument() { if(dirty) saveDocument(); current_view = FileState; cw->raiseWidget(current_view); fileSelector->reread(); } void TableViewerWindow::saveDocument() { if(!dirty) return; FileManager fm; QIODevice *dev = fm.saveFile(doc); if(!ds->saveSource(dev, doc.type())){ qWarning("Save unsuccessful"); return; } dev->close(); dirty = FALSE; } void TableViewerWindow::newDocument() { DocLnk nf; nf.setType("text/x-xml-tableviewer"); nf.setName("table"); delete ds; ds = new DBStore(); ts.current_column = 0; ts.kRep = ds->getKeys(); browseView->reset(); listView->reset(); filterView->reset(); doc = nf; dirty = FALSE; current_view = BrowseState; cw->raiseWidget(current_view); /* now set up for editing the keys */ ts.kRep->addKey("key", TVVariant::String); editKeysSlot(); } void TableViewerWindow::setDocument(const QString &f) { openDocument(DocLnk(f, TRUE)); } void TableViewerWindow::openDocument(const DocLnk &f) { if (!f.isValid()) return; FileManager fm; QIODevice *dev = fm.openFile(f); doc = f; if(ds->openSource(dev, doc.type())) { DataElem *d; browseView->reset(); listView->reset(); filterView->reset(); current_view = BrowseState; cw->raiseWidget(current_view); /* set up new table state and ensure sub widgets have a reference */ ts.current_column = 0; ts.kRep = ds->getKeys(); browseView->rebuildKeys(); listView->rebuildKeys(); filterView->rebuildKeys(); ds->first(); /* set up the list view */ listView->clearItems(); do { d = ds->getCurrentData(); if(d) listView->addItem(d); } while(ds->next()); /* Set up browse view, Will be based of structure of listView */ listView->first(); ts.current_elem = listView->getCurrentData(); browseView->rebuildData(); listView->rebuildData(); QString scratch = "Table Viewer";/* later take from constant */ scratch += " - "; scratch += ds->getName(); setCaption(tr(scratch)); dirty = FALSE; } else { qWarning(tr("could not load Document")); } dev->close(); } /*! Moves to the first item of the current table */ void TableViewerWindow::firstItem() { listView->first(); ts.current_elem = listView->getCurrentData(); browseView->rebuildData(); } /*! Moves to the lat item of the current table */ void TableViewerWindow::lastItem() { listView->last(); ts.current_elem = listView->getCurrentData(); browseView->rebuildData(); } /*! Moves to the next item of the current table */ void TableViewerWindow::nextItem() { listView->next(); ts.current_elem = listView->getCurrentData(); browseView->rebuildData(); } /*! Moves to the previous item of the current table */ void TableViewerWindow::previousItem() { listView->previous(); ts.current_elem = listView->getCurrentData(); browseView->rebuildData(); } /*! Raises the List View. This is a mode change for the application. */ void TableViewerWindow::listViewSlot() { if(current_view == FilterState) applyFilter(); current_view = ListState; cw->raiseWidget(current_view); } void TableViewerWindow::applyFilter() { DataElem *d; listView->clearItems(); ds->first(); do { d = ds->getCurrentData(); if(d) if(filterView->passesFilter(d)) listView->addItem(d); } while(ds->next()); listView->first(); listView->rebuildData(); } /*! Raises the Browse View. This is a mode change for the application. */ void TableViewerWindow::browseViewSlot() { if(current_view == FilterState) applyFilter(); ts.current_elem = listView->getCurrentData(); browseView->rebuildData(); current_view = BrowseState; cw->raiseWidget(current_view); } /*! Raises the List View. This is a mode change for the application. */ void TableViewerWindow::filterViewSlot() { current_view = FilterState; cw->raiseWidget(current_view); } void TableViewerWindow::editItemSlot() { if(TVEditView::openEditItemDialog(&ts, ts.current_elem, this)) { listView->rebuildData(); browseView->rebuildData(); dirty = TRUE; } } void TableViewerWindow::newItemSlot() { DataElem *d = new DataElem(ds); if (TVEditView::openEditItemDialog(&ts, d, this)) { ds->addItem(d); ts.current_elem = d; applyFilter(); listView->rebuildData(); browseView->rebuildData(); dirty = TRUE; } } void TableViewerWindow::deleteItemSlot() { /* delete the actual item, then do a 'filter' */ DataElem *to_remove = ts.current_elem; if(!to_remove) return; |