• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • kdelibs
  • Sitemap
  • Contact Us
 

Kate

kateargumenthinttree.cpp

Go to the documentation of this file.
00001 /* This file is part of the KDE libraries
00002    Copyright (C) 2007 David Nolden <david.nolden.kdevelop@art-master.de>
00003 
00004    This library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Library General Public
00006    License version 2 as published by the Free Software Foundation.
00007 
00008    This library is distributed in the hope that it will be useful,
00009    but WITHOUT ANY WARRANTY; without even the implied warranty of
00010    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011    Library General Public License for more details.
00012 
00013    You should have received a copy of the GNU Library General Public License
00014    along with this library; see the file COPYING.LIB.  If not, write to
00015    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00016    Boston, MA 02110-1301, USA.
00017 */
00018 
00019 #include "kateargumenthinttree.h"
00020 
00021 #include <QHeaderView>
00022 #include <QApplication>
00023 #include <QDesktopWidget>
00024 #include <QScrollBar>
00025 
00026 #include "kateargumenthintmodel.h"
00027 #include "katecompletionwidget.h"
00028 #include "expandingtree/expandingwidgetmodel.h"
00029 #include "katecompletiondelegate.h"
00030 #include "kateview.h"
00031 #include <QModelIndex>
00032 
00033 
00034 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
00035 
00036   setFrameStyle( QFrame::Box | QFrame::Plain );
00037   setLineWidth( 1 );
00038   
00039   connect( parent, SIGNAL(destroyed(QObject*)), this, SLOT(deleteLater()) );
00040   setFrameStyle(QFrame::NoFrame);
00041   setFrameStyle( QFrame::Box | QFrame::Plain );
00042   setFocusPolicy(Qt::NoFocus);
00043   setWindowFlags(Qt::Tool | Qt::FramelessWindowHint);
00044   setUniformRowHeights(false);
00045   setVerticalScrollMode(QAbstractItemView::ScrollPerPixel);
00046   header()->hide();
00047   setRootIsDecorated(false);
00048   setIndentation(0);
00049   setAllColumnsShowFocus(true);
00050   setAlternatingRowColors(true);
00051   setItemDelegate(new KateCompletionDelegate(parent->argumentHintModel(), parent));
00052 }
00053 
00054 void KateArgumentHintTree::clearCompletion() {
00055   setCurrentIndex(QModelIndex());
00056 }
00057 
00058 KateArgumentHintModel* KateArgumentHintTree::model() const {
00059   return m_parent->argumentHintModel();
00060 }
00061 
00062 void KateArgumentHintTree::paintEvent ( QPaintEvent * event ) {
00063   QTreeView::paintEvent(event);
00064   updateGeometry(); 
00065 }
00066 
00067 void KateArgumentHintTree::dataChanged ( const QModelIndex & topLeft, const QModelIndex & bottomRight ) {
00068   QTreeView::dataChanged(topLeft,bottomRight);
00069   //updateGeometry();
00070 }
00071 
00072 void KateArgumentHintTree::currentChanged ( const QModelIndex & current, const QModelIndex & previous ) {
00073 /*  kDebug( 13035 ) << "currentChanged()";*/
00074   static_cast<ExpandingWidgetModel*>(model())->rowSelected(current);
00075   QTreeView::currentChanged(current, previous);
00076 }
00077 
00078 void KateArgumentHintTree::rowsInserted ( const QModelIndex & parent, int start, int end ) {
00079   QTreeView::rowsInserted(parent, start, end);
00080   updateGeometry();
00081 }
00082 
00083 int KateArgumentHintTree::sizeHintForColumn(int column) const {
00084   return QTreeView::sizeHintForColumn(column);
00085 }
00086 
00087 unsigned int KateArgumentHintTree::rowHeight(const QModelIndex& index) const {
00088   uint max = sizeHintForIndex(index).height();
00089 
00090   for(int a = 0; a < index.model()->columnCount(index.parent()); ++a) {
00091     QModelIndex i = index.sibling(index.row(), a);
00092     uint cSize = sizeHintForIndex(i).height();
00093     if(cSize > max)
00094       max = cSize;
00095   }
00096   return max;
00097 }
00098 
00099 void KateArgumentHintTree::updateGeometry(QRect geom) {
00100   setAnimated(false);
00101   //Avoid recursive calls of updateGeometry
00102   static bool updatingGeometry = false;
00103   if( updatingGeometry ) return;
00104   updatingGeometry = true;
00105   
00106   if( model()->rowCount(QModelIndex()) == 0 ) {
00107 /*  kDebug( 13035 ) << "KateArgumentHintTree:: empty model";*/
00108     hide();
00109     setGeometry(geom);
00110     updatingGeometry = false;
00111     return;
00112   }
00113 
00114   setUpdatesEnabled(false);
00115 
00116   int bottom = geom.bottom();
00117   int totalWidth = resizeColumns();
00118   int totalHeight = 0;
00119   for(int a = 0; a < model()->rowCount( QModelIndex() ); ++a) {
00120     QModelIndex index(model()->index(a, 0));
00121     totalHeight += rowHeight(index);
00122     for(int b = 0; b < model()->rowCount(index); ++b) {
00123       QModelIndex childIndex = index.child(b, 0);
00124       totalHeight += rowHeight(childIndex);
00125     }
00126   }
00127   
00128   totalHeight += frameWidth()*2;
00129   
00130   QRect topRect = visualRect(model()->index(0, 0));
00131   QRect contentRect = visualRect(model()->index(model()->rowCount(QModelIndex())-1, 0));
00132   
00133   geom.setHeight(totalHeight);
00134 
00135   geom.moveBottom(bottom);
00136 //   if( totalWidth > geom.width() )
00137     geom.setWidth(totalWidth);
00138 
00139   //Resize and move so it fits the screen horizontally
00140   int maxWidth = (QApplication::desktop()->screenGeometry(m_parent->view()).width()*3)/4;
00141   if( geom.width() > maxWidth ) {
00142     geom.setWidth(maxWidth);
00143     geom.setHeight(geom.height() + horizontalScrollBar()->height() +2);
00144     geom.moveBottom(bottom);
00145     setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOn );
00146   }else{
00147     setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
00148   }
00149 
00150   if (geom.right() > QApplication::desktop()->screenGeometry(m_parent->view()).right())
00151     geom.moveRight( QApplication::desktop()->screenGeometry(m_parent->view()).right() );
00152 
00153   if( geom.left() < QApplication::desktop()->screenGeometry(m_parent->view()).left() )
00154     geom.moveLeft(QApplication::desktop()->screenGeometry(m_parent->view()).left());
00155 
00156   //Resize and move so it fits the screen vertically
00157   bool resized = false;
00158   if( geom.top() < QApplication::desktop()->screenGeometry(this).top() ) {
00159     int offset = QApplication::desktop()->screenGeometry(this).top() - geom.top();
00160     geom.setBottom( geom.bottom() - offset );
00161     geom.moveTo(geom.left(), QApplication::desktop()->screenGeometry(this).top());
00162     resized = true;
00163   }
00164   
00165 /*  kDebug( 13035 ) << "KateArgumentHintTree::updateGeometry: updating geometry to " << geom;*/
00166   setGeometry(geom);
00167   
00168   if( resized && currentIndex().isValid() )
00169     scrollTo(currentIndex());
00170   
00171   updatingGeometry = false;
00172   setUpdatesEnabled(true);
00173 }
00174 
00175 int KateArgumentHintTree::resizeColumns() {
00176   int totalSize = 0;
00177   for( int a  = 0; a < header()->count(); a++ ) {
00178     int columnSize = sizeHintForColumn(a);
00179     setColumnWidth(a, columnSize);
00180     totalSize += columnSize;
00181   }
00182   return totalSize;
00183 }
00184 
00185 void KateArgumentHintTree::updateGeometry() {
00186   updateGeometry( geometry() );
00187 }
00188 
00189 bool KateArgumentHintTree::nextCompletion()
00190 {
00191   QModelIndex current;
00192   QModelIndex firstCurrent = currentIndex();
00193 
00194   do {
00195     QModelIndex oldCurrent = currentIndex();
00196 
00197     current = moveCursor(MoveDown, Qt::NoModifier);
00198 
00199     if (current != oldCurrent && current.isValid()) {
00200       setCurrentIndex(current);
00201 
00202     } else {
00203       if (firstCurrent.isValid())
00204         setCurrentIndex(firstCurrent);
00205       return false;
00206     }
00207 
00208   } while (!model()->indexIsItem(current));
00209 
00210   return true;
00211 }
00212 
00213 bool KateArgumentHintTree::previousCompletion()
00214 {
00215   QModelIndex current;
00216   QModelIndex firstCurrent = currentIndex();
00217 
00218   do {
00219     QModelIndex oldCurrent = currentIndex();
00220 
00221     current = moveCursor(MoveUp, Qt::NoModifier);
00222 
00223     if (current != oldCurrent && current.isValid()) {
00224       setCurrentIndex(current);
00225 
00226     } else {
00227       if (firstCurrent.isValid())
00228         setCurrentIndex(firstCurrent);
00229       return false;
00230     }
00231 
00232   } while (!model()->indexIsItem(current));
00233 
00234   return true;
00235 }
00236 
00237 bool KateArgumentHintTree::pageDown( )
00238 {
00239   QModelIndex old = currentIndex();
00240   QModelIndex current = moveCursor(MovePageDown, Qt::NoModifier);
00241 
00242   if (current.isValid()) {
00243     setCurrentIndex(current);
00244     if (!model()->indexIsItem(current))
00245       if (!nextCompletion())
00246         previousCompletion();
00247   }
00248 
00249   return current != old;
00250 }
00251 
00252 bool KateArgumentHintTree::pageUp( )
00253 {
00254   QModelIndex old = currentIndex();
00255   QModelIndex current = moveCursor(MovePageUp, Qt::NoModifier);
00256 
00257   if (current.isValid()) {
00258     setCurrentIndex(current);
00259     if (!model()->indexIsItem(current))
00260       if (!previousCompletion())
00261         nextCompletion();
00262   }
00263   return current != old;
00264 }
00265 
00266 void KateArgumentHintTree::top( )
00267 {
00268   QModelIndex current = moveCursor(MoveHome, Qt::NoModifier);
00269   setCurrentIndex(current);
00270 
00271   if (current.isValid()) {
00272     setCurrentIndex(current);
00273     if (!model()->indexIsItem(current))
00274       nextCompletion();
00275   }
00276 }
00277 
00278 void KateArgumentHintTree::bottom( )
00279 {
00280   QModelIndex current = moveCursor(MoveEnd, Qt::NoModifier);
00281   setCurrentIndex(current);
00282 
00283   if (current.isValid()) {
00284     setCurrentIndex(current);
00285     if (!model()->indexIsItem(current))
00286       previousCompletion();
00287   }
00288 }
00289 
00290 #include "kateargumenthinttree.moc"

Kate

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

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • Kross
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.5.7
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal