summaryrefslogtreecommitdiffstats
path: root/ksysv/ksvdraglist.h
blob: f5474b87d1847f845f47f72934bf03aed4f3b1eb (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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
/*
** Copyright (C) 2000 Peter Putzer <putzer@kde.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.
**
** 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 in a file called COPYING; if not, write to
** the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
** MA 02110-1301, USA.
*/

/*
** Bug reports and questions can be sent to kde-devel@kde.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; version 2.                              *
 *                                                                         *
 ***************************************************************************/

#ifndef KSVDRAGLIST_H
#define KSVDRAGLIST_H

#include <qstring.h>
#include <qcolor.h>
#include <qpixmap.h>

#include <klistview.h>

#include "Data.h"

class QPen;
class KSVAction;
class SimpleAction;
class KSVDragList;
class KPopupMenu;
class KSVConfig;
class KDLToolTip;

class KSVItem : public QListViewItem
{
public:
  typedef enum {
	SortNumber = 0,
	Icon,
	ServiceName,
	FileName,

	// insert additional columns here

	Last
  } Columns;

  KSVItem (KListView*);
  KSVItem (const KSVItem&);
  explicit KSVItem (KSVDragList*, const KSVData&);
  KSVItem (KListView* view, QString file, QString path, QString label, Q_INT8 nr );
  virtual ~KSVItem ();

  virtual QString key (int col, bool ascending) const;

  inline bool isChanged() const { return mData->changed(); }
  
  inline bool isNumChanged() const { return mData->numberChanged(); }
  inline bool isLabelChanged() const { return mData->labelChanged(); }
  inline bool isNew() const { return mData->newEntry(); }

  inline const QString& oldFilename() const { return mData->oldFilename(); }
  inline const QString& filename() const { return mData->filename(); }
  inline const QString& oldLabel() const { return mData->oldLabel(); }
  inline const QString& label() const { return mData->label(); }
  inline const QString& runlevel() const { return mData->runlevel(); }
  
  inline QString filenameAndPath() const { return mData->filenameAndPath (); }

  inline const QString& path() const { return mData->path(); }

  inline Q_INT8 number() const { return mData->number(); }
  inline Q_INT8 oldNumber() const { return mData->oldNumber(); }

  void copy (const KSVData&);

  KSVData* data () { return mData; }
  const KSVData* data () const { return mData; }

  QString toString () const;

  inline bool operator== (const KSVItem & rhs) const { return mData == rhs.mData; }

  inline const QColor& newNormalColor () const
  {
    return mNewNormalColor;
  }

  inline const QColor& changedNormalColor () const
  {
    return mChangedNormalColor;
  }

  inline QString originalRunlevel() const { return mData->originalRunlevel(); }  
  
  void setIcon (const QPixmap& icon);
  void setLabel (const QString& label);
  void setFilename (const QString& file);
  void setRunlevel (const QString& runlevel);
  void setNumber (Q_INT8 nr);
  void setPath (const QString& path);
  void setChanged (bool);
  void setNewNormalColor (const QColor&);
  void setChangedNormalColor (const QColor&);
  void setNewSelectedColor (const QColor&);
  void setChangedSelectedColor (const QColor&);
  void setNew (bool);
  void setOriginalRunlevel (const QString&);

  inline void setNumberChanged (bool val) { mData->setNumberChanged (val); }

  QString tooltip () const;
  virtual void paintCell (QPainter* p, const QColorGroup& cg, int column, int width, int align);

protected:
  friend class KSVDragList;
  friend class KServiceDragList;

  QPixmap paintDragIcon (const QFont& f, const QColorGroup& g) const;

private:
  friend class KSVDrag;

  KSVData* mData;
  KSVConfig* mConfig;

  QColor mNewNormalColor;
  QColor mNewSelectedColor;
  QColor mChangedNormalColor;
  QColor mChangedSelectedColor;
};

class KSVDragList : public KListView
{
  Q_OBJECT

public:
  KSVDragList ( QWidget* parent = 0, const char* name = 0 );
  virtual ~KSVDragList();

  virtual void clear();

  inline bool displayToolTips () const { return mDisplayToolTips; }
  inline bool commonToolTips () const { return mCommonToolTips; }

  inline const QString& tooltip () const { return mToolTip; }
  inline const QString& horizontalScrollBarTip () const { return mHorizontalTip; }
  inline const QString& verticalScrollBarTip () const { return mVerticalTip; }

  virtual void initItem (QString file, QString path, QString name, Q_INT8 nr);
  QPtrList<KSVData>& getDeletedItems() { return mRMList; }
  
  /**
   * @return whether this is the currently "selected" KSVDragList.
   */
  inline bool isOrigin() const { return mOrigin; }

  inline KSVItem* currentItem() { return static_cast<KSVItem*> (KListView::currentItem()); }

  inline KSVItem* lastItem () { return static_cast<KSVItem*> (KListView::lastItem()); }

  /**
   * @return true if the insertion was successful.
   */
  bool insert (const KSVData& data, const KSVData* above = 0L, const KSVData* below = 0L);

  bool insert (const KSVData& data, const KSVItem* where, KSVAction*& action);

  inline const QPixmap& defaultIcon() const { return mIcon; }

  bool removeFromRMList (const KSVData&);
  bool addToRMList (const KSVData&);
  void clearRMList();

  KSVItem* match (const KSVData&);

  inline void setDisplayToolTips (bool val) { mDisplayToolTips = val; }
  inline void setCommonToolTips (bool val) { mCommonToolTips = val; }
  inline void setHorizontalScrollBarTip (const QString& t) { mHorizontalTip = t; }
  inline void setVerticalScrollBarTip (const QString& t) { mVerticalTip = t; }
  inline void setToolTip (const QString& t) { mToolTip = t; }

public slots:
  void setNewNormalColor (const QColor &);
  void setChangedNormalColor (const QColor &);
  void setNewSelectedColor (const QColor &);
  void setChangedSelectedColor (const QColor &);

  void setOrigin (bool);
  inline void slotNewOrigin() { setOrigin (false); }

  void setDefaultIcon (const QPixmap& icon);

  void drop (QDropEvent*, QListViewItem*);

  virtual void setEnabled (bool);

protected:
  virtual void focusInEvent (QFocusEvent*);
  virtual bool acceptDrag (QDropEvent*) const;
  virtual QDragObject* dragObject ();
//  virtual KSVDrag* dragObject ();

  virtual void startDrag ();

  /**
   * Generates a sorting number for an item at
   * the given index by taking the average of the item
   * above and the item below.
   */
  Q_INT8 generateNumber (Q_INT8 high, Q_INT8 low) const;

  /**
   * A convenience function that also takes the label into account
   */
  Q_INT8 generateNumber (const QString& label, const KSVData* itemAbove, const KSVData* itemBelow) const;
  
  KSVItem* mItemToDrag;

private:
  QPixmap mIcon;
  
  bool mOrigin;
  QPtrList<KSVData> mRMList;

  QColor mNewNormalColor;
  QColor mNewSelectedColor;
  QColor mChangedNormalColor;
  QColor mChangedSelectedColor;

  KPopupMenu* mDragMenu;
  KPopupMenu* mDragCopyMenu;
  KPopupMenu* mDragMoveMenu;
  KDLToolTip* toolTip;
  typedef enum { Copy, Move } DragAction;

  QString mToolTip, mHorizontalTip, mVerticalTip;
  bool mDisplayToolTips, mCommonToolTips;

signals:
  void newOrigin();
  void newOrigin (KSVDragList*);

  void cannotGenerateNumber();
  void undoAction(KSVAction*);
};

class KServiceDragList : public KSVDragList
{
public:
  KServiceDragList (QWidget* parent = 0L, const char* name = 0L);
  virtual ~KServiceDragList ();

protected:
  virtual void startDrag ();
};

#endif