1 /***************************************************************************
2  *   Copyright (C) 2004-2005 by David Saxton                               *
3  *   david@bluehaze.org                                                    *
4  *                                                                         *
5  *   This program is free software; you can redistribute it and/or modify  *
6  *   it under the terms of the GNU General Public License as published by  *
7  *   the Free Software Foundation; either version 2 of the License, or     *
8  *   (at your option) any later version.                                   *
9  ***************************************************************************/
10 
11 #ifndef ITEMINTERFACE_H
12 #define ITEMINTERFACE_H
13 
14 #include <QPointer>
15 #include <QMap>
16 
17 #include "itemgroup.h"
18 
19 class CNItemGroup;
20 class DoubleSpinBox;
21 class Item;
22 class ItemDocument;
23 class ItemGroup;
24 class ItemInterface;
25 class KTechlab;
26 class MechanicsGroup;
27 class Variant;
28 
29 class ColorCombo;
30 class KComboBox;
31 class KToolBar;
32 class KUrlRequester;
33 class QCheckBox;
34 class LineEdit;
35 class QSpinBox;
36 
37 
38 typedef QMap<QString, Variant*> VariantDataMap;
39 typedef QMap<QString, KComboBox*> KComboBoxMap;
40 typedef QMap<QString, LineEdit*> LineEditMap;
41 typedef QMap<QString, DoubleSpinBox*> DoubleSpinBoxMap;
42 typedef QMap<QString, QSpinBox*> IntSpinBoxMap;
43 typedef QMap<QString, ColorCombo*> ColorComboMap;
44 typedef QMap<QString, KUrlRequester*> KUrlReqMap;
45 typedef QMap<QString, QCheckBox*> QCheckBoxMap;
46 
47 /**
48 This acts as an interface between the ItemDocument's and the associated
49 Items's, and the various objects that like to know about them
50 (e.g. ContextHelp, ItemEditor, ItemEditTB)
51 @author David Saxton
52 */
53 class ItemInterface : public QObject
54 {
55 	Q_OBJECT
56 	public:
57 		~ItemInterface() override;
58 		static ItemInterface * self();
59 		/**
60 		 * The current item group in use (or null if none).
61 		 */
itemGroup()62 		ItemGroup * itemGroup() const { return p_itemGroup; }
63 		/**
64 		 * Sets the orientation of all flowparts in the group.
65 		 */
66 		void setFlowPartOrientation( unsigned orientation );
67 		/**
68 		 * Sets the orientation of all components in the group.
69 		 */
70 		void setComponentOrientation( int angleDegrees, bool flipped );
71 		/**
72 		 * Updates actions based on the items currently selected (e.g. rotate,
73 		 * flip, etc)
74 		 */
75 		void updateItemActions();
76 		/**
77 		 * Returns a configuration widget for the component for insertion into te
78 		 * ItemEditTB.
79 		 */
80 		virtual QWidget * configWidget();
81 
82 	public slots:
83 		/**
84 		 * If cnItemsAreSameType() returns true, then set the
85 		 * data with the given id for all the CNItems in the group.
86 		 * Else, it only sets the data for the activeCNItem()
87 		 */
88 		void slotSetData( const QString &id, QVariant value );
89 		/**
90 		 * Essentially the same as slotSetData.
91 		 */
92 		void setProperty( Variant * v );
93 		/**
94 		 * Called when the ItemEditTB is cleared. This clears all widget maps.
95 		 */
96 		void itemEditTBCleared();
97 		void tbDataChanged();
98 		void slotItemDocumentChanged( ItemDocument *view );
99 		void slotUpdateItemInterface();
100 		void slotClearAll();
101 		void slotMultipleSelected();
102 		void clearItemEditorToolBar();
103 
104 	protected:
105 		/**
106 		 * Connects the specified widget to either tbDataChanged or advDataChanged
107 		 * as specified by mi.
108 		 */
109 		void connectMapWidget( QWidget *widget, const char *_signal);
110 
111 		// Widget maps.
112 		LineEditMap m_stringLineEditMap;
113 		KComboBoxMap m_stringComboBoxMap;
114 		KUrlReqMap m_stringURLReqMap;
115 		DoubleSpinBoxMap m_doubleSpinBoxMap;
116 		IntSpinBoxMap m_intSpinBoxMap;
117 		ColorComboMap m_colorComboMap;
118 		QCheckBoxMap m_boolCheckMap;
119 
120 		// Use by item editor toolbar
121 		QPointer<KToolBar> m_pActiveItemEditorToolBar;
122 		int m_toolBarWidgetID;
123 
124 
125 	protected slots:
126 		void slotGetActionTicket();
127 
128 	private:
129 		ItemInterface();
130 		static ItemInterface * m_pSelf;
131 
132 		QPointer<ItemDocument> p_cvb;
133 		QPointer<ItemGroup> p_itemGroup;
134 		QPointer<Item> p_lastItem;
135 		int m_currentActionTicket;
136         bool m_isInTbDataChanged;
137 };
138 
139 #endif
140