1 /***************************************************************************
2         postionviewwidget - inherited class for doc position views.
3                              -------------------
4     begin                : 2006-02-20
5     copyright            : (C) 2006 by Klaas Freitag
6     email                : freitag@kde.org
7  ***************************************************************************/
8 
9 /***************************************************************************
10  *                                                                         *
11  *   This program is free software; you can redistribute it and/or modify  *
12  *   it under the terms of the GNU General Public License as published by  *
13  *   the Free Software Foundation; either version 2 of the License, or     *
14  *   (at your option) any later version.                                   *
15  *                                                                         *
16  ***************************************************************************/
17 
18 
19 #ifndef POSITIONVIEWWIDGET_H
20 #define POSITIONVIEWWIDGET_H
21 
22 #include <QMap>
23 #include <QMenu>
24 #include <QAction>
25 #include <QPaintEvent>
26 #include <QObject>
27 
28 #include "geld.h"
29 #include "ui_positionwidget.h"
30 #include "docposition.h"
31 
32 /**
33 	@author Klaas Freitag <freitag@kde.org>
34 */
35 class KMenu;
36 class QAction;
37 class Geld;
38 class QLocale;
39 class DosPositionGuardedPtr;
40 
41 class PositionViewWidget : public QWidget, public Ui_positionWidget
42 {
43     Q_OBJECT
44 public:
45     enum State { Active, New, Deleted, Locked };
46     enum Kind  { Normal, Demand, Alternative, Invalid };
47 
48     PositionViewWidget( );
49     PositionViewWidget( int );
50 
51     void setDocPosition(DocPositionBase*);
52     virtual ~PositionViewWidget();
modified()53     bool modified() { return mModified; }
ordNumber()54     int ordNumber() { return mOrdNumber; }
55     void setOrdNumber( int  );
56 
deleted()57     bool deleted() { return mToDelete; }
position()58     DocPositionGuardedPtr position(){ return mPositionPtr; }
state()59     State state() { return mState; }
kind()60     Kind  kind()  { return mKind; }
61     QString kindString( Kind = Invalid ) const;
62     QString stateString( const State& state ) const;
63     QString kindLabel( Kind ) const;
64     void cleanKindString();
65     Geld currentPrice();
66     bool priceValid();
67     void setCurrentPrice( Geld );
68     Geld unitPrice();
tagList()69     QStringList tagList() { return mTags; }
70     QString extraDiscountTagRestriction();
71     DocPositionBase::TaxType taxType() const;
72 
73 public slots:
74     void slotSetOverallPrice( Geld );
75     void slotRefreshPrice();
76     void slotModified( bool emitSignal = true );
77     void slotExecButtonPressed();
78     void slotTaggingButtonPressed();
79     void slotMenuAboutToHide();
80     void slotMenuAboutToShow();
81     void slotSetState( State );
82     void slotSetEnabled( bool );
83     void slotEnableKindMenu( bool );
84     void slotAllowIndividualTax( bool );
85     void slotSetTax( DocPosition::TaxType );
86     void slotShowPrice( bool show );  // hide the price entries for certain doc types.
87 
88 protected slots:
89     void slotLockPosition();
90     void slotUnlockPosition();
91     void slotSetPositionNormal();
92     void slotSetPositionAlternative();
93     void slotSetPositionDemand();
94     void slotUpdateTagToolTip();
95     void paintEvent ( QPaintEvent* );
96 
97     void slotSetNilTax();
98     void slotSetReducedTax();
99     void slotSetFullTax();
100 
101 signals:
102     void positionModified();
103     void deletePosition();
104     void moveUp();
105     void moveDown();
106     void lockPosition();
107     void unlockPosition();
108     void priceChanged( const Geld& );
109     void positionStateNormal();
110     void positionStateAlternative();
111     void positionStateDemand();
112 
113 private:
114     bool mModified;
115     bool m_skipModifiedSignal;
116     bool mToDelete;
117     int  mOrdNumber;
118 
119     DocPositionGuardedPtr mPositionPtr;
120     QMenu *mExecPopup;
121     QMenu *mStateSubmenu;
122     QMenu *mTaxSubmenu;
123 
124     QStringList mTags;
125     QAction * mDeleteId;
126     QAction * mLockId;
127     QAction * mUnlockId;
128     QAction * mNilTaxAction;
129     QAction * mRedTaxAction;
130     QAction * mFullTaxAction;
131 
132     Geld mPositionPrice;  // only used for Discount items to store the result
133     State mState;
134     Kind  mKind;
135     bool mPositionPriceValid;
136     QLocale *mLocale;
137     DocPosition::TaxType mTax;
138 };
139 
140 class PositionViewWidgetList : public QList<PositionViewWidget*>
141 {
142   public:
143     PositionViewWidgetList();
144     PositionViewWidget* widgetFromPosition( DocPositionGuardedPtr );
145 
146     Geld nettoPrice();
147 };
148 
149 
150 typedef QListIterator<PositionViewWidget*> PositionViewWidgetListIterator;
151 
152 #endif
153