diff options
author | Michele Calgaro <michele.calgaro@yahoo.it> | 2014-05-25 15:37:31 +0900 |
---|---|---|
committer | Michele Calgaro <michele.calgaro@yahoo.it> | 2014-05-25 15:37:31 +0900 |
commit | 6392f5a9dfce2bf83617d49bb7f332181ec6004e (patch) | |
tree | ab69e390f7962b7e7dda1a3a64f035c61c751cf4 /kdevdesigner/designer/qcompletionedit.cpp | |
parent | aba2788b428dc53243407902e9ccbb20b97a69fd (diff) | |
download | tdevelop-6392f5a9dfce2bf83617d49bb7f332181ec6004e.tar.gz tdevelop-6392f5a9dfce2bf83617d49bb7f332181ec6004e.zip |
Revert "Finish renaming tdevelop components"
This reverts commit 722ce1efbac31c61b1d4b13f7e075c9f311e3e73.
Diffstat (limited to 'kdevdesigner/designer/qcompletionedit.cpp')
-rw-r--r-- | kdevdesigner/designer/qcompletionedit.cpp | 210 |
1 files changed, 210 insertions, 0 deletions
diff --git a/kdevdesigner/designer/qcompletionedit.cpp b/kdevdesigner/designer/qcompletionedit.cpp new file mode 100644 index 00000000..ed0c986e --- /dev/null +++ b/kdevdesigner/designer/qcompletionedit.cpp @@ -0,0 +1,210 @@ +/********************************************************************** +** Copyright (C) 2001 Trolltech AS. All rights reserved. +** +** This file is part of TQt Designer. +** +** This file may be distributed and/or modified under the terms of the +** GNU General Public License version 2 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. +** +** Licensees holding valid TQt Enterprise Edition or TQt Professional Edition +** licenses may use this file in accordance with the TQt Commercial License +** Agreement provided with the Software. +** +** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +** See http://www.trolltech.com/gpl/ for GPL licensing information. +** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for +** information about TQt Commercial License Agreements. +** +** Contact info@trolltech.com if any conditions of this licensing are +** not clear to you. +** +**********************************************************************/ + +#include "qcompletionedit.h" +#include <tqlistbox.h> +#include <tqsizegrip.h> +#include <tqapplication.h> +#include <tqvbox.h> + +QCompletionEdit::QCompletionEdit( TQWidget *parent, const char *name ) + : TQLineEdit( parent, name ), aAdd( FALSE ), caseSensitive( FALSE ) +{ + popup = new TQVBox( 0, 0, WType_Popup ); + popup->setFrameStyle( TQFrame::Box | TQFrame::Plain ); + popup->setLineWidth( 1 ); + popup->hide(); + + listbox = new TQListBox( popup ); + listbox->setFrameStyle( TQFrame::NoFrame ); + listbox->setLineWidth( 1 ); + listbox->installEventFilter( this ); + listbox->setHScrollBarMode( TQScrollView::AlwaysOn ); + listbox->setVScrollBarMode( TQScrollView::AlwaysOn ); + listbox->setCornerWidget( new TQSizeGrip( listbox, "completion sizegrip" ) ); + connect( this, TQT_SIGNAL( textChanged( const TQString & ) ), + this, TQT_SLOT( textDidChange( const TQString & ) ) ); + popup->setFocusProxy( listbox ); + installEventFilter( this ); +} + +bool QCompletionEdit::autoAdd() const +{ + return aAdd; +} + +TQStringList QCompletionEdit::completionList() const +{ + return compList; +} + +void QCompletionEdit::setCompletionList( const TQStringList &l ) +{ + compList = l; +} + +void QCompletionEdit::setAutoAdd( bool add ) +{ + aAdd = add; +} + +void QCompletionEdit::textDidChange( const TQString &text ) +{ + if ( text.isEmpty() ) { + popup->close(); + return; + } + updateListBox(); + placeListBox(); +} + +void QCompletionEdit::placeListBox() +{ + if ( listbox->count() == 0 ) { + popup->close(); + return; + } + + popup->resize( TQMAX( listbox->sizeHint().width() + listbox->verticalScrollBar()->width() + 4, width() ), + listbox->sizeHint().height() + listbox->horizontalScrollBar()->height() + 4 ); + + TQPoint p( mapToGlobal( TQPoint( 0, 0 ) ) ); + if ( p.y() + height() + popup->height() <= TQApplication::desktop()->height() ) + popup->move( p.x(), p.y() + height() ); + else + popup->move( p.x(), p.y() - listbox->height() ); + popup->show(); + listbox->setCurrentItem( 0 ); + listbox->setSelected( 0, TRUE ); + setFocus(); +} + +void QCompletionEdit::updateListBox() +{ + listbox->clear(); + if ( compList.isEmpty() ) + return; + for ( TQStringList::Iterator it = compList.begin(); it != compList.end(); ++it ) { + if ( caseSensitive && (*it).left( text().length() ) == text() || + !caseSensitive && (*it).left( text().length() ).lower() == text().lower() ) + listbox->insertItem( *it ); + } +} + +bool QCompletionEdit::eventFilter( TQObject *o, TQEvent *e ) +{ + if ( TQT_BASE_OBJECT(o) == TQT_BASE_OBJECT(popup) || TQT_BASE_OBJECT(o) == TQT_BASE_OBJECT(listbox) || TQT_BASE_OBJECT(o) == TQT_BASE_OBJECT(listbox->viewport()) ) { + if ( e->type() == TQEvent::KeyPress ) { + TQKeyEvent *ke = (TQKeyEvent*)e; + if ( ke->key() == Key_Enter || ke->key() == Key_Return || ke->key() == Key_Tab ) { + if ( ke->key() == Key_Tab && listbox->count() > 1 && + listbox->currentItem() < (int)listbox->count() - 1 ) { + listbox->setCurrentItem( listbox->currentItem() + 1 ); + return TRUE; + } + popup->close(); + setFocus(); + blockSignals( TRUE ); + setText( listbox->currentText() ); + blockSignals( FALSE ); + emit chosen( text() ); + return TRUE; + } else if ( ke->key() == Key_Left || ke->key() == Key_Right || + ke->key() == Key_Up || ke->key() == Key_Down || + ke->key() == Key_Home || ke->key() == Key_End || + ke->key() == Key_Prior || ke->key() == Key_Next ) { + return FALSE; + } else if ( ke->key() == Key_Escape ) { + popup->close(); + setFocus(); + } else if ( ke->key() != Key_Shift && ke->key() != Key_Control && + ke->key() != Key_Alt ) { + updateListBox(); + if ( listbox->count() == 0 || text().length() == 0 ) { + popup->close(); + setFocus(); + } + TQApplication::sendEvent( this, e ); + return TRUE; + } + } else if ( e->type() == TQEvent::MouseButtonDblClick ) { + popup->close(); + setFocus(); + blockSignals( TRUE ); + setText( listbox->currentText() ); + blockSignals( FALSE ); + emit chosen( text() ); + return TRUE; + } + } else if ( TQT_BASE_OBJECT(o) == TQT_BASE_OBJECT(this) ) { + if ( e->type() == TQEvent::KeyPress ) { + TQKeyEvent *ke = (TQKeyEvent*)e; + if ( ke->key() == Key_Up || + ke->key() == Key_Down || + ke->key() == Key_Prior || + ke->key() == Key_Next || + ke->key() == Key_Return || + ke->key() == Key_Enter || + ke->key() == Key_Tab || + ke->key() == Key_Escape ) { + TQApplication::sendEvent( listbox, e ); + return TRUE; + } + } + } + return TQLineEdit::eventFilter( o, e ); +} + +void QCompletionEdit::addCompletionEntry( const TQString &entry ) +{ + if ( compList.find( entry ) == compList.end() ) { + compList << entry; + compList.sort(); + } +} + +void QCompletionEdit::removeCompletionEntry( const TQString &entry ) +{ + TQStringList::Iterator it = compList.find( entry ); + if ( it != compList.end() ) + compList.remove( it ); +} + +void QCompletionEdit::setCaseSensitive( bool b ) +{ + caseSensitive = b; +} + +bool QCompletionEdit::isCaseSensitive() const +{ + return caseSensitive; +} + +void QCompletionEdit::clear() +{ + TQLineEdit::clear(); + compList.clear(); +} |