summaryrefslogtreecommitdiffstats
path: root/src/common/gui/list_view.h
blob: c76ef46ce05c9ee529d197f77da5a216182fa58d (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
/***************************************************************************
 *   Copyright (C) 2006 Nicolas Hadacek <hadacek@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.                                   *
 ***************************************************************************/
#ifndef LIST_VIEW_H
#define LIST_VIEW_H

#include <tqtooltip.h>
#include <tqvaluevector.h>
#define private public
#define protected public
#include <klistview.h>
#undef private
#undef protected

//-----------------------------------------------------------------------------
class EditListViewItem;
class ListViewToolTip;

class ListView : public KListView
{
Q_OBJECT
  TQ_OBJECT
public:
  ListView(TQWidget *tqparent = 0, const char *name = 0);
  virtual ~ListView();
  virtual void clear();
  void stopRenaming(bool force);
  virtual TQString tooltip(const TQListViewItem &item, int column) const;

public slots:
  void cancelRenaming() { stopRenaming(false); }
  void finishRenaming() { stopRenaming(true); }

protected:
  virtual bool eventFilter(TQObject *o, TQEvent *e);

private:
  ListViewToolTip *_tooltip;
  TQValueList<EditListViewItem *> _editItems;

  friend class EditListViewItem;
};

//-----------------------------------------------------------------------------
class ListViewToolTip : public TQToolTip
{
public:
  ListViewToolTip(ListView *tqparent)
    : TQToolTip(tqparent->viewport()), _listView(tqparent) {}

protected:
  virtual void maybeTip(const TQPoint &p);

private:
  ListView *_listView;
};

//-----------------------------------------------------------------------------
class EditListViewItem : public KListViewItem
{
public:
  EditListViewItem(ListView *list);
  EditListViewItem(KListViewItem *item);
  virtual ~EditListViewItem();
  void startRename();
  bool isRenaming() const { return _renaming; }

protected:
  virtual TQWidget *editWidgetFactory(int col) const = 0;
  virtual bool alwaysAcceptEdit(int col) const = 0;
  virtual int width(const TQFontMetrics &fm, const TQListView *lv, int c) const;
  virtual void editDone(int col, const TQWidget *editWidget);
  virtual void paintCell(TQPainter *p, const TQColorGroup &cg, int column, int width, int align);

private:
  bool _renaming;
  TQValueVector<TQWidget *> _editWidgets;

  virtual void activate() { startRename(); }
  virtual void startRename(int) { startRename(); }
  virtual void okRename(int) { renameDone(true); }
  virtual void cancelRename(int) { renameDone(false); }
  void renameDone(bool force);
  void removeEditBox();

  friend class ListView;
};

#endif