summaryrefslogtreecommitdiff
path: root/libopie2
authormickeyl <mickeyl>2003-03-30 02:54:37 (UTC)
committer mickeyl <mickeyl>2003-03-30 02:54:37 (UTC)
commit15ee85466704072173296ff4f0f446cd8fe81d1e (patch) (side-by-side diff)
treed497cb855ee8ee6533f2efd5b064cef4dc2bb16b /libopie2
parent1d5a00fa8db662c4a5f6490d26d4e2ef1836f118 (diff)
downloadopie-15ee85466704072173296ff4f0f446cd8fe81d1e.zip
opie-15ee85466704072173296ff4f0f446cd8fe81d1e.tar.gz
opie-15ee85466704072173296ff4f0f446cd8fe81d1e.tar.bz2
convert dynamic_cast<> to using QObject::inherits
Diffstat (limited to 'libopie2') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/qt3/opieui/ocombobox.cpp5
-rw-r--r--libopie2/qt3/opieui/oeditlistbox.cpp5
2 files changed, 7 insertions, 3 deletions
diff --git a/libopie2/qt3/opieui/ocombobox.cpp b/libopie2/qt3/opieui/ocombobox.cpp
index a1dd5f5..8dbda8f 100644
--- a/libopie2/qt3/opieui/ocombobox.cpp
+++ b/libopie2/qt3/opieui/ocombobox.cpp
@@ -1,666 +1,669 @@
/*
This file Copyright (C) 2003 Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de>
is part of the Copyright (C) 2000 Carsten Pfeiffer <pfeiffer@kde.org>
Opie Project Copyright (C) 2000 Dawit Alemayehu <adawit@kde.org>
=. Originally part of the KDE Project
.=l.
           .>+-=
 _;:,     .>    :=|. This program is free software; you can
.> <`_,   >  .   <= redistribute it and/or modify it under
:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
.="- .-=="i,     .._ License as published by the Free Software
 - .   .-<_>     .<> Foundation; either version 2 of the License,
     ._= =}       : or (at your option) any later version.
    .%`+i>       _;_.
    .i_,=:_.      -<s. This program is distributed in the hope that
     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
    : ..    .:,     . . . without even the implied warranty of
    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
..}^=.=       =       ; Library General Public License for more
++=   -.     .`     .: details.
 :     =  ...= . :.=-
 -.   .:....=;==+<; You should have received a copy of the GNU
  -_. . .   )=.  = Library General Public License along with
    --        :-=` this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
/* QT */
#include <qclipboard.h>
#include <qlistbox.h>
#include <qpopupmenu.h>
/* OPIE */
#include <opie2/ocompletionbox.h>
#include <opie2/olineedit.h>
#include <opie2/opixmapprovider.h>
#include <opie2/ocombobox.h>
/*======================================================================================
* OComboBoxPrivate
*======================================================================================*/
class OComboBox::OComboBoxPrivate
{
public:
OComboBoxPrivate()
{
olineEdit = 0L;
}
~OComboBoxPrivate()
{
}
OLineEdit *olineEdit;
};
/*======================================================================================
* OComboBox
*======================================================================================*/
OComboBox::OComboBox( QWidget *parent, const char *name )
: QComboBox( parent, name )
{
init();
}
OComboBox::OComboBox( bool rw, QWidget *parent, const char *name )
: QComboBox( rw, parent, name )
{
init();
if ( rw )
{
OLineEdit *edit = new OLineEdit( this, "combo lineedit" );
setLineEdit( edit );
}
}
OComboBox::~OComboBox()
{
delete d;
}
void OComboBox::init()
{
d = new OComboBoxPrivate;
// Permanently set some parameters in the parent object.
QComboBox::setAutoCompletion( false );
// Initialize enable popup menu to false.
// Below it will be enabled if the widget
// is editable.
m_bEnableMenu = false;
m_trapReturnKey = false;
// Enable context menu by default if widget
// is editable.
setContextMenuEnabled( true );
// for wheelscrolling
installEventFilter( this );
if ( lineEdit() )
lineEdit()->installEventFilter( this );
}
bool OComboBox::contains( const QString& _text ) const
{
if ( _text.isEmpty() )
return false;
for (int i = 0; i < count(); i++ ) {
if ( text(i) == _text )
return true;
}
return false;
}
void OComboBox::setAutoCompletion( bool autocomplete )
{
if ( d->olineEdit )
{
if ( autocomplete )
{
d->olineEdit->setCompletionMode( OGlobalSettings::CompletionAuto );
setCompletionMode( OGlobalSettings::CompletionAuto );
}
else
{
d->olineEdit->setCompletionMode( OGlobalSettings::completionMode() );
setCompletionMode( OGlobalSettings::completionMode() );
}
}
}
void OComboBox::setContextMenuEnabled( bool showMenu )
{
if( d->olineEdit )
{
d->olineEdit->setContextMenuEnabled( showMenu );
m_bEnableMenu = showMenu;
}
}
/*
void OComboBox::setURLDropsEnabled( bool enable )
{
if ( d->olineEdit )
d->olineEdit->setURLDropsEnabled( enable );
}
bool OComboBox::isURLDropsEnabled() const
{
return d->olineEdit && d->olineEdit->isURLDropsEnabled();
}
*/
void OComboBox::setCompletedText( const QString& text, bool marked )
{
if ( d->olineEdit )
d->olineEdit->setCompletedText( text, marked );
}
void OComboBox::setCompletedText( const QString& text )
{
if ( d->olineEdit )
d->olineEdit->setCompletedText( text );
}
void OComboBox::makeCompletion( const QString& text )
{
if( d->olineEdit )
d->olineEdit->makeCompletion( text );
else // read-only combo completion
{
if( text.isNull() || !listBox() )
return;
int index = listBox()->index( listBox()->findItem( text ) );
if( index >= 0 ) {
setCurrentItem( index );
}
}
}
void OComboBox::rotateText( OCompletionBase::KeyBindingType type )
{
if ( d->olineEdit )
d->olineEdit->rotateText( type );
}
bool OComboBox::eventFilter( QObject* o, QEvent* ev )
{
QLineEdit *edit = lineEdit();
int type = ev->type();
if ( o == edit )
{
//OCursor::autoHideEventFilter( edit, ev );
if ( type == QEvent::KeyPress )
{
QKeyEvent *e = static_cast<QKeyEvent *>( ev );
if ( e->key() == Key_Return || e->key() == Key_Enter)
{
// On Return pressed event, emit both
// returnPressed(const QString&) and returnPressed() signals
emit returnPressed();
emit returnPressed( currentText() );
if ( d->olineEdit && d->olineEdit->completionBox(false) &&
d->olineEdit->completionBox()->isVisible() )
d->olineEdit->completionBox()->hide();
return m_trapReturnKey;
}
}
}
// wheel-scrolling changes the current item
if ( type == QEvent::Wheel ) {
if ( !listBox() || listBox()->isHidden() ) {
QWheelEvent *e = static_cast<QWheelEvent*>( ev );
static const int WHEEL_DELTA = 120;
int skipItems = e->delta() / WHEEL_DELTA;
if ( e->state() & ControlButton ) // fast skipping
skipItems *= 10;
int newItem = currentItem() - skipItems;
if ( newItem < 0 )
newItem = 0;
else if ( newItem >= count() )
newItem = count() -1;
setCurrentItem( newItem );
if ( !text( newItem ).isNull() )
emit activated( text( newItem ) );
emit activated( newItem );
e->accept();
return true;
}
}
return QComboBox::eventFilter( o, ev );
}
void OComboBox::setTrapReturnKey( bool grab )
{
m_trapReturnKey = grab;
}
bool OComboBox::trapReturnKey() const
{
return m_trapReturnKey;
}
/*
void OComboBox::setEditURL( const OURL& url )
{
QComboBox::setEditText( url.prettyURL() );
}
void OComboBox::insertURL( const OURL& url, int index )
{
QComboBox::insertItem( url.prettyURL(), index );
}
void OComboBox::insertURL( const QPixmap& pixmap, const OURL& url, int index )
{
QComboBox::insertItem( pixmap, url.prettyURL(), index );
}
void OComboBox::changeURL( const OURL& url, int index )
{
QComboBox::changeItem( url.prettyURL(), index );
}
void OComboBox::changeURL( const QPixmap& pixmap, const OURL& url, int index )
{
QComboBox::changeItem( pixmap, url.prettyURL(), index );
}
*/
void OComboBox::setCompletedItems( const QStringList& items )
{
if ( d->olineEdit )
d->olineEdit->setCompletedItems( items );
}
OCompletionBox * OComboBox::completionBox( bool create )
{
if ( d->olineEdit )
return d->olineEdit->completionBox( create );
return 0;
}
// QWidget::create() turns off mouse-Tracking which would break auto-hiding
void OComboBox::create( WId id, bool initializeWindow, bool destroyOldWindow )
{
QComboBox::create( id, initializeWindow, destroyOldWindow );
//OCursor::setAutoHideCursor( lineEdit(), true, true );
}
void OComboBox::setLineEdit( OLineEdit *edit )
{
#if QT_VERSION > 290
QComboBox::setLineEdit( edit );
- d->olineEdit = dynamic_cast<OLineEdit*>( edit );
+ if ( !edit->inherits( "OLineEdit" ) )
+ d->olineEdit = 0;
+ else
+ d->olineEdit = static_cast<OLineEdit*>( edit );
setDelegate( d->olineEdit );
// forward some signals. We only emit returnPressed() ourselves.
if ( d->olineEdit ) {
connect( d->olineEdit, SIGNAL( completion( const QString& )),
SIGNAL( completion( const QString& )) );
connect( d->olineEdit, SIGNAL( substringCompletion( const QString& )),
SIGNAL( substringCompletion( const QString& )) );
connect( d->olineEdit,
SIGNAL( textRotation( OCompletionBase::KeyBindingType )),
SIGNAL( textRotation( OCompletionBase::KeyBindingType )) );
connect( d->olineEdit,
SIGNAL( completionModeChanged( OGlobalSettings::Completion )),
SIGNAL( completionModeChanged( OGlobalSettings::Completion)));
connect( d->olineEdit,
SIGNAL( aboutToShowContextMenu( QPopupMenu * )),
SIGNAL( aboutToShowContextMenu( QPopupMenu * )) );
}
#else
#warning OComboBox is not fully functional with Qt2
#endif
}
// Temporary functions until QT3 appears. - Seth Chaiklin 20 may 2001
void OComboBox::deleteWordForward()
{
lineEdit()->cursorWordForward(TRUE);
#if QT_VERSION > 290
if ( lineEdit()->hasSelectedText() )
#else
if ( lineEdit()->hasMarkedText() )
#endif
{
lineEdit()->del();
}
}
void OComboBox::deleteWordBack()
{
lineEdit()->cursorWordBackward(TRUE);
#if QT_VERSION > 290
if ( lineEdit()->hasSelectedText() )
#else
if ( lineEdit()->hasMarkedText() )
#endif
{
lineEdit()->del();
}
}
void OComboBox::setCurrentItem( const QString& item, bool insert, int index )
{
int sel = -1;
for (int i = 0; i < count(); ++i)
if (text(i) == item)
{
sel = i;
break;
}
if (sel == -1 && insert)
{
insertItem(item, index);
if (index >= 0)
sel = index;
else
sel = count() - 1;
}
setCurrentItem(sel);
}
void OComboBox::setCurrentItem(int index)
{
QComboBox::setCurrentItem(index);
}
/*======================================================================================
* OHistoryCombo
*======================================================================================*/
// we are always read-write
OHistoryCombo::OHistoryCombo( QWidget *parent, const char *name )
: OComboBox( true, parent, name )
{
init( true ); // using completion
}
// we are always read-write
OHistoryCombo::OHistoryCombo( bool useCompletion,
QWidget *parent, const char *name )
: OComboBox( true, parent, name )
{
init( useCompletion );
}
void OHistoryCombo::init( bool useCompletion )
{
if ( useCompletion )
completionObject()->setOrder( OCompletion::Weighted );
setInsertionPolicy( NoInsertion );
myIterateIndex = -1;
myRotated = false;
myPixProvider = 0L;
connect( this, SIGNAL(aboutToShowContextMenu(QPopupMenu*)),
SLOT(addContextMenuItems(QPopupMenu*)) );
connect( this, SIGNAL( activated(int) ), SLOT( slotReset() ));
connect( this, SIGNAL( returnPressed(const QString&) ), SLOT(slotReset()));
}
OHistoryCombo::~OHistoryCombo()
{
delete myPixProvider;
}
void OHistoryCombo::setHistoryItems( QStringList items,
bool setCompletionList )
{
OComboBox::clear();
// limit to maxCount()
while ( (int) items.count() > maxCount() && !items.isEmpty() )
items.remove( items.begin() );
insertItems( items );
if ( setCompletionList && useCompletion() ) {
// we don't have any weighting information here ;(
OCompletion *comp = completionObject();
comp->setOrder( OCompletion::Insertion );
comp->setItems( items );
comp->setOrder( OCompletion::Weighted );
}
clearEdit();
}
QStringList OHistoryCombo::historyItems() const
{
QStringList list;
for ( int i = 0; i < count(); i++ )
list.append( text( i ) );
return list;
}
void OHistoryCombo::clearHistory()
{
OComboBox::clear();
if ( useCompletion() )
completionObject()->clear();
}
void OHistoryCombo::addContextMenuItems( QPopupMenu* menu )
{
if ( menu &&!lineEdit()->text().isEmpty())
{
menu->insertSeparator();
menu->insertItem( tr("Empty Contents"), this, SLOT( slotClear()));
}
}
void OHistoryCombo::addToHistory( const QString& item )
{
if ( item.isEmpty() || (count() > 0 && item == text(0) ))
return;
// remove all existing items before adding
if ( !duplicatesEnabled() ) {
for ( int i = 0; i < count(); i++ ) {
if ( text( i ) == item )
removeItem( i );
}
}
// now add the item
if ( myPixProvider )
//insertItem( myPixProvider->pixmapFor(item, KIcon::SizeSmall), item, 0);
insertItem( myPixProvider->pixmapFor(item, 16), item, 0);
else
insertItem( item, 0 );
int last;
QString rmItem;
bool useComp = useCompletion();
while ( count() > maxCount() && count() > 0 ) {
// remove the last item, as long as we are longer than maxCount()
// remove the removed item from the completionObject if it isn't
// anymore available at all in the combobox.
last = count() - 1;
rmItem = text( last );
removeItem( last );
if ( useComp && !contains( rmItem ) )
completionObject()->removeItem( rmItem );
}
if ( useComp )
completionObject()->addItem( item );
}
bool OHistoryCombo::removeFromHistory( const QString& item )
{
if ( item.isEmpty() )
return false;
bool removed = false;
QString temp = currentText();
for ( int i = 0; i < count(); i++ ) {
while ( item == text( i ) ) {
removed = true;
removeItem( i );
}
}
if ( removed && useCompletion() )
completionObject()->removeItem( item );
setEditText( temp );
return removed;
}
void OHistoryCombo::keyPressEvent( QKeyEvent *e )
{
// save the current text in the lineedit
if ( myIterateIndex == -1 )
myText = currentText();
// going up in the history, rotating when reaching QListBox::count()
//if ( OStdAccel::isEqual( e, OStdAccel::rotateUp() ) ) {
if ( e->key() == Qt::Key_Up ) {
myIterateIndex++;
// skip duplicates/empty items
while ( myIterateIndex < count()-1 &&
(currentText() == text( myIterateIndex ) ||
text( myIterateIndex ).isEmpty()) )
myIterateIndex++;
if ( myIterateIndex >= count() ) {
myRotated = true;
myIterateIndex = -1;
// if the typed text is the same as the first item, skip the first
if ( myText == text(0) )
myIterateIndex = 0;
setEditText( myText );
}
else
setEditText( text( myIterateIndex ));
}
// going down in the history, no rotation possible. Last item will be
// the text that was in the lineedit before Up was called.
//else if ( OStdAccel::isEqual( e, OStdAccel::rotateDown() ) ) {
else if ( e->key() == Qt::Key_Down ) {
myIterateIndex--;
// skip duplicates/empty items
while ( myIterateIndex >= 0 &&
(currentText() == text( myIterateIndex ) ||
text( myIterateIndex ).isEmpty()) )
myIterateIndex--;
if ( myIterateIndex < 0 ) {
if ( myRotated && myIterateIndex == -2 ) {
myRotated = false;
myIterateIndex = count() - 1;
setEditText( text(myIterateIndex) );
}
else { // bottom of history
if ( myIterateIndex == -2 ) {
qDebug( "ONotifyClient is not implemented yet." );
//ONotifyClient::event( ONotifyClient::notification,
// i18n("No further item in the history."));
}
myIterateIndex = -1;
if ( currentText() != myText )
setEditText( myText );
}
}
else
setEditText( text( myIterateIndex ));
}
else
OComboBox::keyPressEvent( e );
}
void OHistoryCombo::slotReset()
{
myIterateIndex = -1;
myRotated = false;
}
void OHistoryCombo::setPixmapProvider( OPixmapProvider *prov )
{
if ( myPixProvider == prov )
return;
delete myPixProvider;
myPixProvider = prov;
// re-insert all the items with/without pixmap
// I would prefer to use changeItem(), but that doesn't honour the pixmap
// when using an editable combobox (what we do)
if ( count() > 0 ) {
QStringList items( historyItems() );
clear();
insertItems( items );
}
}
void OHistoryCombo::insertItems( const QStringList& items )
{
QStringList::ConstIterator it = items.begin();
QString item;
while ( it != items.end() ) {
item = *it;
if ( !item.isEmpty() ) { // only insert non-empty items
if ( myPixProvider )
// insertItem( myPixProvider->pixmapFor(item, OIcon::SizeSmall), item );
insertItem( myPixProvider->pixmapFor(item, 16), item );
else
insertItem( item );
}
++it;
}
}
void OHistoryCombo::slotClear()
{
clearHistory();
emit cleared();
}
diff --git a/libopie2/qt3/opieui/oeditlistbox.cpp b/libopie2/qt3/opieui/oeditlistbox.cpp
index 3c53552..0e95274 100644
--- a/libopie2/qt3/opieui/oeditlistbox.cpp
+++ b/libopie2/qt3/opieui/oeditlistbox.cpp
@@ -1,416 +1,417 @@
/* This file is part of the KDE libraries
Copyright (C) 2000 David Faure <faure@kde.org>, Alexander Neundorf <neundorf@kde.org>
2000, 2002 Carsten Pfeiffer <pfeiffer@kde.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
/* QT */
#include <qstringlist.h>
#include <qpushbutton.h>
#include <qlayout.h>
#include <qgroupbox.h>
#include <qlistbox.h>
#include <qwhatsthis.h>
#include <qlabel.h>
/* OPIE */
#include <opie2/ocombobox.h>
#include <opie2/odialog.h>
#include <opie2/olineedit.h>
#include <opie2/oeditlistbox.h>
/* UNIX */
#include <assert.h>
/*======================================================================================
* OEditListBoxPrivate
*======================================================================================*/
class OEditListBoxPrivate
{
public:
bool m_checkAtEntering;
int buttons;
};
/*======================================================================================
* OEditListBox
*======================================================================================*/
OEditListBox::OEditListBox(QWidget *parent, const char *name,
bool checkAtEntering, int buttons )
:QGroupBox(parent, name )
{
init( checkAtEntering, buttons );
}
OEditListBox::OEditListBox(const QString& title, QWidget *parent,
const char *name, bool checkAtEntering, int buttons)
:QGroupBox(title, parent, name )
{
init( checkAtEntering, buttons );
}
OEditListBox::OEditListBox(const QString& title, const CustomEditor& custom,
QWidget *parent, const char *name,
bool checkAtEntering, int buttons)
:QGroupBox(title, parent, name )
{
m_lineEdit = custom.lineEdit();
init( checkAtEntering, buttons, custom.representationWidget() );
}
OEditListBox::~OEditListBox()
{
delete d;
d=0;
}
void OEditListBox::init( bool checkAtEntering, int buttons,
QWidget *representationWidget )
{
d=new OEditListBoxPrivate;
d->m_checkAtEntering=checkAtEntering;
d->buttons = buttons;
int lostButtons = 0;
if ( (buttons & Add) == 0 )
lostButtons++;
if ( (buttons & Remove) == 0 )
lostButtons++;
if ( (buttons & UpDown) == 0 )
lostButtons += 2;
servNewButton = servRemoveButton = servUpButton = servDownButton = 0L;
setSizePolicy(QSizePolicy(QSizePolicy::MinimumExpanding,
QSizePolicy::MinimumExpanding));
QWidget * gb = this;
QGridLayout * grid = new QGridLayout(gb, 7 - lostButtons, 2,
ODialog::marginHint(),
ODialog::spacingHint());
grid->addRowSpacing(0, fontMetrics().lineSpacing());
for ( int i = 1; i < 7 - lostButtons; i++ )
grid->setRowStretch(i, 1);
grid->setMargin(15);
if ( representationWidget )
representationWidget->reparent( gb, QPoint(0,0) );
else
m_lineEdit=new OLineEdit(gb);
m_listBox = new QListBox(gb);
QWidget *editingWidget = representationWidget ?
representationWidget : m_lineEdit;
grid->addMultiCellWidget(editingWidget,1,1,0,1);
grid->addMultiCellWidget(m_listBox, 2, 6 - lostButtons, 0, 0);
int row = 2;
if ( buttons & Add ) {
servNewButton = new QPushButton(tr("&Add"), gb);
servNewButton->setEnabled(false);
connect(servNewButton, SIGNAL(clicked()), SLOT(addItem()));
grid->addWidget(servNewButton, row++, 1);
}
if ( buttons & Remove ) {
servRemoveButton = new QPushButton(tr("&Remove"), gb);
servRemoveButton->setEnabled(false);
connect(servRemoveButton, SIGNAL(clicked()), SLOT(removeItem()));
grid->addWidget(servRemoveButton, row++, 1);
}
if ( buttons & UpDown ) {
servUpButton = new QPushButton(tr("Move &Up"), gb);
servUpButton->setEnabled(false);
connect(servUpButton, SIGNAL(clicked()), SLOT(moveItemUp()));
servDownButton = new QPushButton(tr("Move &Down"), gb);
servDownButton->setEnabled(false);
connect(servDownButton, SIGNAL(clicked()), SLOT(moveItemDown()));
grid->addWidget(servUpButton, row++, 1);
grid->addWidget(servDownButton, row++, 1);
}
connect(m_lineEdit,SIGNAL(textChanged(const QString&)),this,SLOT(typedSomething(const QString&)));
m_lineEdit->setTrapReturnKey(true);
connect(m_lineEdit,SIGNAL(returnPressed()),this,SLOT(addItem()));
connect(m_listBox, SIGNAL(highlighted(int)), SLOT(enableMoveButtons(int)));
// maybe supplied lineedit has some text already
typedSomething( m_lineEdit->text() );
}
void OEditListBox::typedSomething(const QString& text)
{
if(currentItem() >= 0) {
if(currentText() != m_lineEdit->text())
{
// IMHO changeItem() shouldn't do anything with the value
// of currentItem() ... like changing it or emitting signals ...
// but TT disagree with me on this one (it's been that way since ages ... grrr)
bool block = m_listBox->signalsBlocked();
m_listBox->blockSignals( true );
m_listBox->changeItem(text, currentItem());
m_listBox->blockSignals( block );
emit changed();
}
}
if ( !servNewButton )
return;
if (!d->m_checkAtEntering)
servNewButton->setEnabled(!text.isEmpty());
else
{
if (text.isEmpty())
{
servNewButton->setEnabled(false);
}
else
{
#if QT_VERSION > 290
StringComparisonMode mode = (StringComparisonMode) (ExactMatch | CaseSensitive );
bool enable = (m_listBox->findItem( text, mode ) == 0L);
#else
bool enable = (m_listBox->findItem( text ) == 0L);
#endif
servNewButton->setEnabled( enable );
}
}
}
void OEditListBox::moveItemUp()
{
if (!m_listBox->isEnabled())
{
//ONotifyClient::beep();
return;
}
unsigned int selIndex = m_listBox->currentItem();
if (selIndex == 0)
{
//ONotifyClient::beep();
return;
}
QListBoxItem *selItem = m_listBox->item(selIndex);
m_listBox->takeItem(selItem);
m_listBox->insertItem(selItem, selIndex-1);
m_listBox->setCurrentItem(selIndex - 1);
emit changed();
}
void OEditListBox::moveItemDown()
{
if (!m_listBox->isEnabled())
{
//ONotifyClient::beep();
return;
}
unsigned int selIndex = m_listBox->currentItem();
if (selIndex == m_listBox->count() - 1)
{
//ONotifyClient::beep();
return;
}
QListBoxItem *selItem = m_listBox->item(selIndex);
m_listBox->takeItem(selItem);
m_listBox->insertItem(selItem, selIndex+1);
m_listBox->setCurrentItem(selIndex + 1);
emit changed();
}
void OEditListBox::addItem()
{
// when m_checkAtEntering is true, the add-button is disabled, but this
// slot can still be called through Key_Return/Key_Enter. So we guard
// against this.
if ( !servNewButton || !servNewButton->isEnabled() )
return;
const QString& currentTextLE=m_lineEdit->text();
bool alreadyInList(false);
//if we didn't check for dupes at the inserting we have to do it now
if (!d->m_checkAtEntering)
{
// first check current item instead of dumb iterating the entire list
if ( m_listBox->currentText() == currentTextLE )
alreadyInList = true;
else
{
#if QT_VERSION > 290
StringComparisonMode mode = (StringComparisonMode) (ExactMatch | CaseSensitive );
alreadyInList =(m_listBox->findItem(currentTextLE, mode) != 0);
#else
alreadyInList =(m_listBox->findItem(currentTextLE) != 0);
#endif
}
}
if ( servNewButton )
servNewButton->setEnabled(false);
bool block = m_lineEdit->signalsBlocked();
m_lineEdit->blockSignals(true);
m_lineEdit->clear();
m_lineEdit->blockSignals(block);
m_listBox->setSelected(currentItem(), false);
if (!alreadyInList)
{
block = m_listBox->signalsBlocked();
m_listBox->blockSignals( true );
m_listBox->insertItem(currentTextLE);
m_listBox->blockSignals( block );
emit changed();
emit added( currentTextLE );
}
}
int OEditListBox::currentItem() const
{
int nr = m_listBox->currentItem();
#if QT_VERSION > 290
if(nr >= 0 && !m_listBox->item(nr)->isSelected()) return -1;
#else
if(nr >= 0 && !m_listBox->isSelected(m_listBox->item(nr))) return -1;
#endif
return nr;
}
void OEditListBox::removeItem()
{
int selected = m_listBox->currentItem();
if ( selected >= 0 )
{
QString removedText = m_listBox->currentText();
m_listBox->removeItem( selected );
if ( count() > 0 )
m_listBox->setSelected( QMIN( selected, count() - 1 ), true );
emit changed();
emit removed( removedText );
}
if ( servRemoveButton && m_listBox->currentItem() == -1 )
servRemoveButton->setEnabled(false);
}
void OEditListBox::enableMoveButtons(int index)
{
// Update the lineEdit when we select a different line.
if(currentText() != m_lineEdit->text())
m_lineEdit->setText(currentText());
bool moveEnabled = servUpButton && servDownButton;
if (moveEnabled )
{
if (m_listBox->count() <= 1)
{
servUpButton->setEnabled(false);
servDownButton->setEnabled(false);
}
else if ((uint) index == (m_listBox->count() - 1))
{
servUpButton->setEnabled(true);
servDownButton->setEnabled(false);
}
else if (index == 0)
{
servUpButton->setEnabled(false);
servDownButton->setEnabled(true);
}
else
{
servUpButton->setEnabled(true);
servDownButton->setEnabled(true);
}
}
if ( servRemoveButton )
servRemoveButton->setEnabled(true);
}
void OEditListBox::clear()
{
m_lineEdit->clear();
m_listBox->clear();
emit changed();
}
void OEditListBox::insertStringList(const QStringList& list, int index)
{
m_listBox->insertStringList(list,index);
}
void OEditListBox::insertStrList(const QStrList* list, int index)
{
m_listBox->insertStrList(list,index);
}
void OEditListBox::insertStrList(const QStrList& list, int index)
{
m_listBox->insertStrList(list,index);
}
void OEditListBox::insertStrList(const char ** list, int numStrings, int index)
{
m_listBox->insertStrList(list,numStrings,index);
}
QStringList OEditListBox::items() const
{
QStringList list;
for ( uint i = 0; i < m_listBox->count(); i++ )
list.append( m_listBox->text( i ));
return list;
}
void OEditListBox::virtual_hook( int, void* )
{ /*BASE::virtual_hook( id, data );*/ }
/*======================================================================================
* CustomEditor
*======================================================================================*/
OEditListBox::CustomEditor::CustomEditor( OComboBox *combo )
{
m_representationWidget = combo;
- m_lineEdit = dynamic_cast<OLineEdit*>( combo->lineEdit() );
- assert( m_lineEdit );
+ assert( combo->lineEdit()->inherits( "OLineEdit" ) );
+ m_lineEdit = static_cast<OLineEdit*>( combo->lineEdit() );
+
}