• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • applications API Reference
  • KDE Home
  • Contact Us
 

Kate

  • kde-4.14
  • applications
  • kate
  • part
  • completion
kateargumenthinttree.cpp
Go to the documentation of this file.
1 /* This file is part of the KDE libraries and the Kate part.
2  *
3  * Copyright (C) 2007 David Nolden <david.nolden.kdevelop@art-master.de>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Library General Public License for more details.
14  *
15  * You should have received a copy of the GNU Library General Public License
16  * along with this library; see the file COPYING.LIB. If not, write to
17  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18  * Boston, MA 02110-1301, USA.
19  */
20 
21 #include "kateargumenthinttree.h"
22 
23 #include <QHeaderView>
24 #include <QApplication>
25 #include <QDesktopWidget>
26 #include <QScrollBar>
27 
28 #include "kateargumenthintmodel.h"
29 #include "katecompletionwidget.h"
30 #include "expandingtree/expandingwidgetmodel.h"
31 #include "katecompletiondelegate.h"
32 #include "kateview.h"
33 #include <QModelIndex>
34 
35 
36 KateArgumentHintTree::KateArgumentHintTree( KateCompletionWidget* parent ) : ExpandingTree(0), m_parent(parent) { //Do not use the completion-widget as widget-parent, because the argument-hint-tree will be rendered separately
37 
38  setFrameStyle( QFrame::Box | QFrame::Plain );
39  setLineWidth( 1 );
40 
41  connect( parent, SIGNAL(destroyed(QObject*)), this, SLOT(deleteLater()) );
42  setFrameStyle(QFrame::NoFrame);
43  setFrameStyle( QFrame::Box | QFrame::Plain );
44  setFocusPolicy(Qt::NoFocus);
45  setWindowFlags(Qt::Tool | Qt::FramelessWindowHint);
46  setUniformRowHeights(false);
47  setVerticalScrollMode(QAbstractItemView::ScrollPerPixel);
48  header()->hide();
49  setRootIsDecorated(false);
50  setIndentation(0);
51  setAllColumnsShowFocus(true);
52  setAlternatingRowColors(true);
53  setItemDelegate(new KateCompletionDelegate(parent->argumentHintModel(), parent));
54 }
55 
56 void KateArgumentHintTree::clearCompletion() {
57  setCurrentIndex(QModelIndex());
58 }
59 
60 KateArgumentHintModel* KateArgumentHintTree::model() const {
61  return m_parent->argumentHintModel();
62 }
63 
64 void KateArgumentHintTree::paintEvent ( QPaintEvent * event ) {
65  QTreeView::paintEvent(event);
66  updateGeometry();
67 }
68 
69 void KateArgumentHintTree::dataChanged ( const QModelIndex & topLeft, const QModelIndex & bottomRight ) {
70  QTreeView::dataChanged(topLeft,bottomRight);
71  //updateGeometry();
72 }
73 
74 void KateArgumentHintTree::currentChanged ( const QModelIndex & current, const QModelIndex & previous ) {
75 /* kDebug( 13035 ) << "currentChanged()";*/
76  static_cast<ExpandingWidgetModel*>(model())->rowSelected(current);
77  QTreeView::currentChanged(current, previous);
78 }
79 
80 void KateArgumentHintTree::rowsInserted ( const QModelIndex & parent, int start, int end ) {
81  QTreeView::rowsInserted(parent, start, end);
82  updateGeometry();
83 }
84 
85 int KateArgumentHintTree::sizeHintForColumn(int column) const {
86  return QTreeView::sizeHintForColumn(column);
87 }
88 
89 unsigned int KateArgumentHintTree::rowHeight(const QModelIndex& index) const {
90  uint max = sizeHintForIndex(index).height();
91 
92  for(int a = 0; a < index.model()->columnCount(index.parent()); ++a) {
93  QModelIndex i = index.sibling(index.row(), a);
94  uint cSize = sizeHintForIndex(i).height();
95  if(cSize > max)
96  max = cSize;
97  }
98  return max;
99 }
100 
101 void KateArgumentHintTree::updateGeometry(QRect geom) {
102  //Avoid recursive calls of updateGeometry
103  static bool updatingGeometry = false;
104  if( updatingGeometry ) return;
105  updatingGeometry = true;
106 
107  if( model()->rowCount(QModelIndex()) == 0 ) {
108 /* kDebug( 13035 ) << "KateArgumentHintTree:: empty model";*/
109  hide();
110  setGeometry(geom);
111  updatingGeometry = false;
112  return;
113  }
114 
115  int bottom = geom.bottom();
116  int totalWidth = resizeColumns();
117  int totalHeight = 0;
118  for(int a = 0; a < model()->rowCount( QModelIndex() ); ++a) {
119  QModelIndex index(model()->index(a, 0));
120  totalHeight += rowHeight(index);
121  for(int b = 0; b < model()->rowCount(index); ++b) {
122  QModelIndex childIndex = index.child(b, 0);
123  totalHeight += rowHeight(childIndex);
124  }
125  }
126 
127  totalHeight += frameWidth()*2;
128 
129  geom.setHeight(totalHeight);
130 
131  geom.moveBottom(bottom);
132 // if( totalWidth > geom.width() )
133  geom.setWidth(totalWidth);
134 
135  bool enableScrollBars = false;
136 
137  //Resize and move so it fits the screen horizontally
138  int maxWidth = (QApplication::desktop()->screenGeometry(m_parent->view()).width()*3)/4;
139  if( geom.width() > maxWidth ) {
140  geom.setWidth(maxWidth);
141  geom.setHeight(geom.height() + horizontalScrollBar()->height() +2);
142  geom.moveBottom(bottom);
143  enableScrollBars = true;
144  }
145 
146  if (geom.right() > QApplication::desktop()->screenGeometry(m_parent->view()).right())
147  geom.moveRight( QApplication::desktop()->screenGeometry(m_parent->view()).right() );
148 
149  if( geom.left() < QApplication::desktop()->screenGeometry(m_parent->view()).left() )
150  geom.moveLeft(QApplication::desktop()->screenGeometry(m_parent->view()).left());
151 
152  //Resize and move so it fits the screen vertically
153  bool resized = false;
154  if( geom.top() < QApplication::desktop()->screenGeometry(this).top() ) {
155  int offset = QApplication::desktop()->screenGeometry(this).top() - geom.top();
156  geom.setBottom( geom.bottom() - offset );
157  geom.moveTo(geom.left(), QApplication::desktop()->screenGeometry(this).top());
158  resized = true;
159  }
160 
161  if(geom != geometry())
162  {
163  setUpdatesEnabled(false);
164  setAnimated(false);
165 
166  setHorizontalScrollBarPolicy( enableScrollBars ? Qt::ScrollBarAlwaysOn : Qt::ScrollBarAlwaysOff );
167 
168  /* kDebug( 13035 ) << "KateArgumentHintTree::updateGeometry: updating geometry to " << geom;*/
169  setGeometry(geom);
170 
171  if( resized && currentIndex().isValid() )
172  scrollTo(currentIndex());
173 
174  setUpdatesEnabled(true);
175  }
176 
177  updatingGeometry = false;
178 }
179 
180 int KateArgumentHintTree::resizeColumns() {
181  int totalSize = 0;
182  for( int a = 0; a < header()->count(); a++ ) {
183  int columnSize = sizeHintForColumn(a);
184  setColumnWidth(a, columnSize);
185  totalSize += columnSize;
186  }
187  return totalSize;
188 }
189 
190 void KateArgumentHintTree::updateGeometry() {
191  updateGeometry( geometry() );
192 }
193 
194 bool KateArgumentHintTree::nextCompletion()
195 {
196  QModelIndex current;
197  QModelIndex firstCurrent = currentIndex();
198 
199  do {
200  QModelIndex oldCurrent = currentIndex();
201 
202  current = moveCursor(MoveDown, Qt::NoModifier);
203 
204  if (current != oldCurrent && current.isValid()) {
205  setCurrentIndex(current);
206 
207  } else {
208  if (firstCurrent.isValid())
209  setCurrentIndex(firstCurrent);
210  return false;
211  }
212 
213  } while (!model()->indexIsItem(current));
214 
215  return true;
216 }
217 
218 bool KateArgumentHintTree::previousCompletion()
219 {
220  QModelIndex current;
221  QModelIndex firstCurrent = currentIndex();
222 
223  do {
224  QModelIndex oldCurrent = currentIndex();
225 
226  current = moveCursor(MoveUp, Qt::NoModifier);
227 
228  if (current != oldCurrent && current.isValid()) {
229  setCurrentIndex(current);
230 
231  } else {
232  if (firstCurrent.isValid())
233  setCurrentIndex(firstCurrent);
234  return false;
235  }
236 
237  } while (!model()->indexIsItem(current));
238 
239  return true;
240 }
241 
242 bool KateArgumentHintTree::pageDown( )
243 {
244  QModelIndex old = currentIndex();
245  QModelIndex current = moveCursor(MovePageDown, Qt::NoModifier);
246 
247  if (current.isValid()) {
248  setCurrentIndex(current);
249  if (!model()->indexIsItem(current))
250  if (!nextCompletion())
251  previousCompletion();
252  }
253 
254  return current != old;
255 }
256 
257 bool KateArgumentHintTree::pageUp( )
258 {
259  QModelIndex old = currentIndex();
260  QModelIndex current = moveCursor(MovePageUp, Qt::NoModifier);
261 
262  if (current.isValid()) {
263  setCurrentIndex(current);
264  if (!model()->indexIsItem(current))
265  if (!previousCompletion())
266  nextCompletion();
267  }
268  return current != old;
269 }
270 
271 void KateArgumentHintTree::top( )
272 {
273  QModelIndex current = moveCursor(MoveHome, Qt::NoModifier);
274  setCurrentIndex(current);
275 
276  if (current.isValid()) {
277  setCurrentIndex(current);
278  if (!model()->indexIsItem(current))
279  nextCompletion();
280  }
281 }
282 
283 void KateArgumentHintTree::bottom( )
284 {
285  QModelIndex current = moveCursor(MoveEnd, Qt::NoModifier);
286  setCurrentIndex(current);
287 
288  if (current.isValid()) {
289  setCurrentIndex(current);
290  if (!model()->indexIsItem(current))
291  previousCompletion();
292  }
293 }
294 
295 #include "kateargumenthinttree.moc"
QRect::moveBottom
void moveBottom(int y)
QModelIndex
QRect::setBottom
void setBottom(int y)
kateview.h
QDesktopWidget::screenGeometry
const QRect screenGeometry(int screen) const
QTreeView::paintEvent
virtual void paintEvent(QPaintEvent *event)
QAbstractItemView::setAlternatingRowColors
void setAlternatingRowColors(bool enable)
KateArgumentHintTree::pageDown
bool pageDown()
Definition: kateargumenthinttree.cpp:242
KateArgumentHintTree::rowsInserted
virtual void rowsInserted(const QModelIndex &parent, int start, int end)
Definition: kateargumenthinttree.cpp:80
KateArgumentHintModel
Definition: kateargumenthintmodel.h:30
QAbstractItemView::setCurrentIndex
void setCurrentIndex(const QModelIndex &index)
QTreeView::moveCursor
virtual QModelIndex moveCursor(CursorAction cursorAction, QFlags< Qt::KeyboardModifier > modifiers)
QRect::right
int right() const
QTreeView::dataChanged
virtual void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
QTreeView::currentChanged
virtual void currentChanged(const QModelIndex &current, const QModelIndex &previous)
QWidget::setFocusPolicy
void setFocusPolicy(Qt::FocusPolicy policy)
KateArgumentHintTree::paintEvent
virtual void paintEvent(QPaintEvent *event)
Definition: kateargumenthinttree.cpp:64
katecompletiondelegate.h
ExpandingTree
Definition: expandingtree.h:28
KateArgumentHintTree::pageUp
bool pageUp()
Definition: kateargumenthinttree.cpp:257
kateargumenthintmodel.h
QTreeView::setUniformRowHeights
void setUniformRowHeights(bool uniform)
QRect::height
int height() const
QTreeView::setAnimated
void setAnimated(bool enable)
KateArgumentHintTree::clearCompletion
void clearCompletion()
Definition: kateargumenthinttree.cpp:56
QAbstractItemView::setVerticalScrollMode
void setVerticalScrollMode(ScrollMode mode)
QFrame::setFrameStyle
void setFrameStyle(int style)
QFrame::setLineWidth
void setLineWidth(int)
expandingwidgetmodel.h
QRect::moveLeft
void moveLeft(int x)
QWidget::setGeometry
void setGeometry(int x, int y, int w, int h)
QRect::moveTo
void moveTo(int x, int y)
QWidget::width
int width() const
QTreeView::sizeHintForColumn
virtual int sizeHintForColumn(int column) const
QRect
QModelIndex::isValid
bool isValid() const
QTreeView::setColumnWidth
void setColumnWidth(int column, int width)
KateCompletionWidget
This is the code completion's main widget, and also contains the core interface logic.
Definition: katecompletionwidget.h:55
KateArgumentHintTree::dataChanged
virtual void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
Definition: kateargumenthinttree.cpp:69
kateargumenthinttree.h
KateArgumentHintTree::KateArgumentHintTree
KateArgumentHintTree(KateCompletionWidget *parent)
Definition: kateargumenthinttree.cpp:36
QRect::top
int top() const
KateArgumentHintModel::rowCount
virtual int rowCount(const QModelIndex &parent) const
Definition: kateargumenthintmodel.cpp:226
KateArgumentHintTree::updateGeometry
void updateGeometry()
Definition: kateargumenthinttree.cpp:190
KateArgumentHintTree::bottom
void bottom()
Definition: kateargumenthinttree.cpp:283
QWidget::setUpdatesEnabled
void setUpdatesEnabled(bool enable)
QObject
KateCompletionWidget::view
KateView * view() const
Definition: katecompletionwidget.cpp:271
QRect::left
int left() const
QTreeView::rowsInserted
virtual void rowsInserted(const QModelIndex &parent, int start, int end)
QAbstractScrollArea::setHorizontalScrollBarPolicy
void setHorizontalScrollBarPolicy(Qt::ScrollBarPolicy)
QRect::setWidth
void setWidth(int width)
QAbstractItemView::setItemDelegate
void setItemDelegate(QAbstractItemDelegate *delegate)
QModelIndex::row
int row() const
KateArgumentHintTree::previousCompletion
bool previousCompletion()
Definition: kateargumenthinttree.cpp:218
katecompletionwidget.h
QObject::deleteLater
void deleteLater()
QTreeView::setAllColumnsShowFocus
void setAllColumnsShowFocus(bool enable)
QWidget::hide
void hide()
QModelIndex::parent
QModelIndex parent() const
QAbstractItemView::sizeHintForIndex
QSize sizeHintForIndex(const QModelIndex &index) const
QTreeView::setIndentation
void setIndentation(int i)
QTreeView::scrollTo
virtual void scrollTo(const QModelIndex &index, ScrollHint hint)
QModelIndex::child
QModelIndex child(int row, int column) const
KateArgumentHintTree::top
void top()
Definition: kateargumenthinttree.cpp:271
KateCompletionWidget::argumentHintModel
KateArgumentHintModel * argumentHintModel() const
Definition: katecompletionwidget.cpp:248
QWidget::setWindowFlags
void setWindowFlags(QFlags< Qt::WindowType > type)
KateArgumentHintTree::currentChanged
virtual void currentChanged(const QModelIndex &current, const QModelIndex &previous)
Definition: kateargumenthinttree.cpp:74
QRect::width
int width() const
QModelIndex::model
const QAbstractItemModel * model() const
QFrame::frameWidth
int frameWidth() const
QApplication::desktop
QDesktopWidget * desktop()
QModelIndex::sibling
QModelIndex sibling(int row, int column) const
QRect::setHeight
void setHeight(int height)
KateArgumentHintModel::indexIsItem
virtual bool indexIsItem(const QModelIndex &index) const
Should return true if the given row should be painted like a contained item(as opposed to label-rows ...
Definition: kateargumenthintmodel.cpp:253
QAbstractItemModel::columnCount
virtual int columnCount(const QModelIndex &parent) const =0
QSize::height
int height() const
QRect::bottom
int bottom() const
QAbstractScrollArea::horizontalScrollBar
QScrollBar * horizontalScrollBar() const
QTreeView::header
QHeaderView * header() const
QRect::moveRight
void moveRight(int x)
QPaintEvent
QAbstractItemView::currentIndex
QModelIndex currentIndex() const
QTreeView::setRootIsDecorated
void setRootIsDecorated(bool show)
KateArgumentHintTree::resizeColumns
int resizeColumns()
Definition: kateargumenthinttree.cpp:180
KateArgumentHintTree::nextCompletion
bool nextCompletion()
Definition: kateargumenthinttree.cpp:194
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QObject::parent
QObject * parent() const
KateCompletionDelegate
Definition: katecompletiondelegate.h:26
QObject::destroyed
void destroyed(QObject *obj)
QHeaderView::count
int count() const
QWidget::height
height
ExpandingWidgetModel
Cares about expanding/un-expanding items in a tree-view together with ExpandingDelegate.
Definition: expandingwidgetmodel.h:36
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Sat May 9 2020 03:56:57 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

Kate

Skip menu "Kate"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

applications API Reference

Skip menu "applications API Reference"
  •   kate
  •       kate
  •   KTextEditor
  •   Kate
  • Konsole

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal