summaryrefslogtreecommitdiffstats
path: root/src/kima.h
blob: ddb688c6c65b24a24d73c734c722f9dcd6d1f79c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
/***************************************************************************
 *   Copyright (C) 2005 by Ken Werner                                      *
 *   [email protected]                                                     *
 *                                                                         *
 *   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.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.             *
 ***************************************************************************/
#ifndef KIMA_H
#define KIMA_H

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <list>

#include <kpanelapplet.h>
#include "sources/source.h"
#include "cpufreqd/cpufreqd.h"

// TQt
#include <tqtooltip.h>
#include <tqfont.h>
#include <tqcolor.h>
#include <tqptrlist.h>
#include <tqlabel.h>

// Forward Declarations
class FlowLayout;
class KAboutApplication;
class TDEPopupMenu;
class TDESelectAction;
class TQMouseEvent;
class KDialogBase;
class Prefs;
class TQListViewItem;
class TDEConfig;
class TQLayoutItem;

/**
@author Ken Werner
*/
class Kima : public KPanelApplet, TQToolTip {
	Q_OBJECT
	 //macro which activates signals and slots (moc)

public:
	/**
	 * Construct a @ref KPanelApplet just like any other widget.
	 *
	 * @param configFile The configFile handed over in the factory function.
	 * @param Type The applet @ref type().
	 * @param actions Standard RMB menu actions supported by the applet (see @ref action() ).
	 * @param parent The pointer to the parent widget handed over in the factory function.
	 * @param name A TQt object name for your applet.
	 **/
	Kima(const TQString& inConfigFile, Type inType = Normal, int inActions = 0,
	           TQWidget* inParent = 0, const char* inName = 0);
	/** destructor */
	virtual ~Kima();

	/**
	 * Retrieve a suggested width for a given height.
	 *
	 * Every applet should reimplement this function.
	 *
	 * Depending on the panel orientation the height (horizontal panel) or the
	 * width (vertical panel) of the applets is fixed.
	 * The exact values of the fixed size component depend on the panel size.
	 *
	 * On a horizontal panel the applet height is fixed, the panel will
	 * call @ref widthForHeight(int height) with @p height
	 * equal to 'the fixed applet height'
	 * when laying out the applets.
	 *
	 * The applet can now choose the other size component (width)
	 * based on the given height.
	 *
	 * The width you return is granted.
	 **/
	virtual int widthForHeight(int inHeight) const;

	/**
	 * @return A suggested height for a given width.
	 *
	 * Every applet should reimplement this function.
	 *
	 * Depending on the panel orientation the height (horizontal panel) or the
	 * width (vertical panel) of the applets is fixed.
	 * The exact values of the fixed size component depend on the panel size.
	 *
	 * On a vertical panel the applet width is fixed, the panel will
	 * call @ref heightForWidth(int width) with @p width
	 * equal to 'the fixed applet width'
	 * when laying out the applets.
	 *
	 * The applet can now choose the other size component (height)
	 * based on the given width.
	 *
	 * The height you return is granted.
	 **/
	virtual int heightForWidth(int inWidth) const;

public slots:
	/**
	 * called if the preferences dialog is cancelled
	 **/
	void cancelPreferences();

	/**
	 * Saves the preferences
	 **/
	void savePreferences();

	/**
	 * Is called when the user selects "About" from the applets RMB menu.
	 * Reimplement this function to launch a about dialog.
	 *
	 * Note that this is called only when your applet supports the About action.
	 * See @ref Action and @ref KPanelApplet().
	 **/
	virtual void about();

	/**
	 * Is called when the user selects "Help" from the applets RMB menu.
	 * Reimplement this function to launch a manual or help page.
	 *
	 * Note that this is called only when your applet supports the Help action.
	 * See @ref Action and @ref KPanelApplet().
	 **/
	virtual void help();

	/**
	 * Is called when the user selects "Preferences" from the applets RMB menu.
	 * Reimplement this function to launch a preferences dialog or kcontrol module.
	 *
	 * Note that this is called only when your applet supports the preferences action.
	 * See @ref Action and @ref KPanelApplet().
	 **/
	virtual void preferences();

	/**
	 * raises the preferences widgets of the given list item
	 */	
	void raiseSourcePrefsWidget(TQListViewItem* inListViewItem);

	/**
	 * adds or removes the given source from the display (layout) of the kicker applet
	 */	
	void displaySource(bool inDisplay, Source* inSource);

protected:
	void paintEvent(TQPaintEvent* inEvent);
	void mousePressEvent(TQMouseEvent* inEvent);
	void mouseMoveEvent(TQMouseEvent* inEvent);
	void mouseReleaseEvent(TQMouseEvent* inEvent);
	void maybeTip(const TQPoint& inPos);
	void registerSource(Source* source);

protected slots:
	void updateSourceWidgets();

private:
	/**
	 * Adds the entries of given the STL to mSources
	 */
	void addSources(const std::list<Source*>& inList);

	/**
	 * Searches for the Source that has inWidget
	 * Returns the found Soucre, otherwise NULL
	 */
	Source* findSource(TQWidget* inWidget);
	/**
	 * Searches for the Source that has inPosition
	 * Returns the found Soucre, otherwise NULL
	 */
	Source* findSource(int inPosition);

	TDEConfig* mTDEConfig;
	FlowLayout* mLayout;
	mutable int mCachedWFH;
	mutable int mCachedHeight;
	KAboutApplication* mAboutDialog;
	TDEPopupMenu* mMenu;
	KDialogBase* mPrefsDlg;
	Prefs* mPrefs;

	/**
	 * stores sources
	 */
	TQPtrList<Source> mSources;

	/**
	 * points to the source which is currently
	 * dragged, otherwise NULL
	 */
	TQLayoutItem* mDraggedSourceItem;

	/**
	 * 'drag' threshold multiplier
	 */
	double mDragFactor;

	/**
	 * contains the cpufreq support
	 */
	CPUFreqd mCpufreqd;
};

#endif // KIMA_H