• Skip to content
  • Skip to link menu
KDE 4.1 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 void KateArgumentHintTree::updateGeometry(QRect geom) {
00084   //Avoid recursive calls of updateGeometry
00085   static bool updatingGeometry = false;
00086   if( updatingGeometry ) return;
00087   updatingGeometry = true;
00088   
00089   if( model()->rowCount(QModelIndex()) == 0 ) {
00090 /*  kDebug( 13035 ) << "KateArgumentHintTree:: empty model";*/
00091     hide();
00092     setGeometry(geom);
00093     updatingGeometry = false;
00094     return;
00095   }
00096 
00097   setUpdatesEnabled(false);
00098   show();
00099   int bottom = geom.bottom();
00100   int totalWidth = resizeColumns();
00101   QRect topRect = visualRect(model()->index(0, 0));
00102   QRect contentRect = visualRect(model()->index(model()->rowCount(QModelIndex())-1, 0));
00103   
00104   geom.setHeight(contentRect.bottom() + 5 - topRect.top());
00105 
00106   geom.moveBottom(bottom);
00107   if( totalWidth > geom.width() )
00108     geom.setWidth(totalWidth);
00109 
00110   //Resize and move so it fits the screen horizontally
00111   int maxWidth = (QApplication::desktop()->screenGeometry(m_parent->view()).width()*3)/4;
00112   if( geom.width() > maxWidth ) {
00113     geom.setWidth(maxWidth);
00114     geom.setHeight(geom.height() + horizontalScrollBar()->height() +2);
00115     geom.moveBottom(bottom);
00116     setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOn );
00117   }else{
00118     setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
00119   }
00120 
00121   if (geom.right() > QApplication::desktop()->screenGeometry(m_parent->view()).right())
00122     geom.moveRight( QApplication::desktop()->screenGeometry(m_parent->view()).right() );
00123 
00124   if( geom.left() < QApplication::desktop()->screenGeometry(m_parent->view()).left() )
00125     geom.moveLeft(QApplication::desktop()->screenGeometry(m_parent->view()).left());
00126 
00127   //Resize and move so it fits the screen vertically
00128   bool resized = false;
00129   if( geom.top() < QApplication::desktop()->screenGeometry(this).top() ) {
00130     int offset = QApplication::desktop()->screenGeometry(this).top() - geom.top();
00131     geom.setBottom( geom.bottom() - offset );
00132     geom.moveTo(geom.left(), QApplication::desktop()->screenGeometry(this).top());
00133     resized = true;
00134   }
00135   
00136 /*  kDebug( 13035 ) << "KateArgumentHintTree::updateGeometry: updating geometry to " << geom;*/
00137   setGeometry(geom);
00138   
00139   if( resized && currentIndex().isValid() )
00140     scrollTo(currentIndex());
00141   
00142   show();
00143   updatingGeometry = false;
00144   setUpdatesEnabled(true);
00145 }
00146 
00147 int KateArgumentHintTree::resizeColumns() {
00148   int totalSize = 0;
00149   for( int a  = 0; a < header()->count(); a++ ) {
00150     resizeColumnToContents(a);
00151     totalSize += columnWidth(a);
00152   }
00153   return totalSize;
00154 }
00155 
00156 void KateArgumentHintTree::updateGeometry() {
00157   updateGeometry( geometry() );
00158 }
00159 
00160 bool KateArgumentHintTree::nextCompletion()
00161 {
00162   QModelIndex current;
00163   QModelIndex firstCurrent = currentIndex();
00164 
00165   do {
00166     QModelIndex oldCurrent = currentIndex();
00167 
00168     current = moveCursor(MoveDown, Qt::NoModifier);
00169 
00170     if (current != oldCurrent && current.isValid()) {
00171       setCurrentIndex(current);
00172 
00173     } else {
00174       if (firstCurrent.isValid())
00175         setCurrentIndex(firstCurrent);
00176       return false;
00177     }
00178 
00179   } while (!model()->indexIsItem(current));
00180 
00181   return true;
00182 }
00183 
00184 bool KateArgumentHintTree::previousCompletion()
00185 {
00186   QModelIndex current;
00187   QModelIndex firstCurrent = currentIndex();
00188 
00189   do {
00190     QModelIndex oldCurrent = currentIndex();
00191 
00192     current = moveCursor(MoveUp, Qt::NoModifier);
00193 
00194     if (current != oldCurrent && current.isValid()) {
00195       setCurrentIndex(current);
00196 
00197     } else {
00198       if (firstCurrent.isValid())
00199         setCurrentIndex(firstCurrent);
00200       return false;
00201     }
00202 
00203   } while (!model()->indexIsItem(current));
00204 
00205   return true;
00206 }
00207 
00208 bool KateArgumentHintTree::pageDown( )
00209 {
00210   QModelIndex old = currentIndex();
00211   QModelIndex current = moveCursor(MovePageDown, Qt::NoModifier);
00212 
00213   if (current.isValid()) {
00214     setCurrentIndex(current);
00215     if (!model()->indexIsItem(current))
00216       if (!nextCompletion())
00217         previousCompletion();
00218   }
00219 
00220   return current != old;
00221 }
00222 
00223 bool KateArgumentHintTree::pageUp( )
00224 {
00225   QModelIndex old = currentIndex();
00226   QModelIndex current = moveCursor(MovePageUp, Qt::NoModifier);
00227 
00228   if (current.isValid()) {
00229     setCurrentIndex(current);
00230     if (!model()->indexIsItem(current))
00231       if (!previousCompletion())
00232         nextCompletion();
00233   }
00234   return current != old;
00235 }
00236 
00237 void KateArgumentHintTree::top( )
00238 {
00239   QModelIndex current = moveCursor(MoveHome, Qt::NoModifier);
00240   setCurrentIndex(current);
00241 
00242   if (current.isValid()) {
00243     setCurrentIndex(current);
00244     if (!model()->indexIsItem(current))
00245       nextCompletion();
00246   }
00247 }
00248 
00249 void KateArgumentHintTree::bottom( )
00250 {
00251   QModelIndex current = moveCursor(MoveEnd, Qt::NoModifier);
00252   setCurrentIndex(current);
00253 
00254   if (current.isValid()) {
00255     setCurrentIndex(current);
00256     if (!model()->indexIsItem(current))
00257       previousCompletion();
00258   }
00259 }
00260 
00261 #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
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.5.4
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