summaryrefslogtreecommitdiffstats
path: root/quanta/treeviews/structtreeview.h
blob: 4f59e7d3ccbd8d6c983413d90de476979ced16ac (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
/***************************************************************************
                          structtreeview.h  -  description
                             -------------------
    begin                : Sat Apr 29 2000
    copyright            : (C) 2000 by Yacovlev Alexander & Dmitry Poplavsky <pdima@mail.univ.kiev.ua>
                           (C) 2002, 2003 Andras Mantia <amantia@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 STRUCTTREEVIEW_H
#define STRUCTTREEVIEW_H

#include <qmap.h>
#include <qvaluelist.h>

#include <klistview.h>

/**view class of document structure
 *@author Andras Mantia & Paulo Moura Guedes & Yacovlev Alexander & Dmitry Poplavsky
 */

class KPopupMenu;
class KConfig;
class KURL;
class QTime;

class Node;
class StructTreeTag;
class Parser;
class Document;
struct DTDStruct;

class StructTreeView : public KListView  {
   Q_OBJECT
public:

  /**
   *  since this class is a singleton you must use this function to access it
   *
   *  the parameters are only used at the first call to create the class
   *
   */
  static StructTreeView* const ref(QWidget *parent = 0L, const char *name = 0L)
  {
    static StructTreeView *m_ref;
    if (!m_ref) m_ref = new StructTreeView (parent, name);
    return m_ref;
  }

  ~StructTreeView();


  void setFollowCursor(bool);
  bool followCursor() { return followCursorFlag; }
  /** Show the element in tree according to cursor position (x,y) */
  void showTagAtPos(Node *node);
  /** Delete the items */
  void deleteList(bool groupOnly);
  void setParsingDTDs(const QStringList &parsingDTDList);
  void showMessage(const QString& message);
  
  
  bool useOpenLevelSetting;

public slots: // Public slots
  /** repaint document structure */
  void slotReparse(Document *w, Node* node, int openLevel = 3,bool groupOnly=false);
  void slotMouseClicked(int button, QListViewItem*, const QPoint&, int);
  void slotDoubleClicked( QListViewItem * );

  // slots for RBM menu
  void slotReparseMenuItem();
  void slotSelectTag();
  void slotGotoTag( QListViewItem *item );
  void slotGotoClosingTag();
  /** Recursively open the tree and all its subtrees */
  void slotOpenSubTree();
  /** Recursively close the tree and all its subtrees */
  void slotCloseSubTree();
  void changeFollowCursor() { setFollowCursor(!followCursorFlag); }
  /** No descriptions */
  void slotCollapsed(QListViewItem *item);
  /** No descriptions */
  void slotExpanded(QListViewItem *);
  void slotOpenFile();
  void slotNodeTreeChanged();
  void slotRemoveTags();

signals:
  void newCursorPosition( int col, int row );
  void selectTagArea(Node* node);
  void selectArea(int col1, int row1, int col2, int row2 );
  void needReparse();
  void onTag( const QString &tag );
  void showGroupsForDTEP(const QString& dtep, bool show);
  void openFile(const KURL&);
  void openImage(const KURL&);
  void showProblemMessage(const QString&);
  void clearProblemOutput();

private:

  /** The constructor is private because we use singleton pattern.
   *  If you need the class use StructTreeView::ref() for
   *  construction and reference
   */
  StructTreeView(QWidget *parent=0, const char *name=0);
  /** builds the structure tree */
  void buildTree(Node *baseNode, int openLevel, bool groupOnly);
  /** Do the recursive opening or closing of the trees */
  void setOpenSubTree(QListViewItem *it, bool open);

  /** Make ctrl have the same behavior has shift */
  void setContiguousSelectedItems();
  
  void copySelectedItems(QListViewItem* parent, QListViewItem* after);
  void moveSelectedItems(QListViewItem* parent, QListViewItem* after);
  
private:

  int followCursorId;
  bool followCursorFlag;

  KPopupMenu *popupMenu;
  KPopupMenu *emptyAreaMenu;
  KPopupMenu *dtdMenu;
  StructTreeTag *lastTag;
  KConfig *config;
  QStringList dtdList;
  QValueList<const DTDStruct*> m_parsingDTDList;
  int openFileMenuId;
  QMap<QString, uint> groupIds;
  bool m_dirty;
  StructTreeTag *top;
  QValueList<StructTreeTag*> groups;
  uint groupsCount;

  bool topOpened;
  QValueList<bool> groupOpened;
  
  mutable QListViewItem* m_marker;       //track that has the drag/drop marker under it
  QListViewItem* m_draggedItem;
//   mutable QWidget* m_thisWidget; // non const this hack for acceptDrag

protected: // Protected methods
  /** Do a reparse before showing. */
  virtual void showEvent(QShowEvent*);
  /** Clear the problem output when hiding. */
  virtual void hideEvent(QHideEvent*);
  
  // drag functions  
  virtual bool acceptDrag(QDropEvent* e) const;
  virtual void startDrag();
  virtual void contentsMousePressEvent(QMouseEvent* e);

protected slots: // Protected slots
  /** The treeview DTD  has changed to id. */
  void slotDTDChanged(int id);
    
  void slotMouseClickedVPL(int button, QListViewItem*, const QPoint&, int);
  virtual void slotDropped(QDropEvent* e, QListViewItem* parent, QListViewItem* after);

protected: // Protected attributes
  Document *write;
  QTime *timer;
};

#endif