summaryrefslogtreecommitdiff
path: root/libopie2
authorar <ar>2005-01-21 20:19:00 (UTC)
committer ar <ar>2005-01-21 20:19:00 (UTC)
commit55eccecc08f839878e5743d6e6be25af386b5a3f (patch) (side-by-side diff)
treefd663ded2a2c097ce53bac6c021ca652ef5b5508 /libopie2
parentcd51d382be50bc021739395309e23760f1619759 (diff)
downloadopie-55eccecc08f839878e5743d6e6be25af386b5a3f.zip
opie-55eccecc08f839878e5743d6e6be25af386b5a3f.tar.gz
opie-55eccecc08f839878e5743d6e6be25af386b5a3f.tar.bz2
- make opie compilable against qte 2.3.10 snapshot
change QT_VERSION > 290 into QT_VERSION <= 0x030000
Diffstat (limited to 'libopie2') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opieui/olistview.cpp8
-rw-r--r--libopie2/opieui/opopupmenu.cpp4
-rw-r--r--libopie2/opieui/oselector.cpp2
-rw-r--r--libopie2/opieui/oselector.h4
-rw-r--r--libopie2/qt3/opiecore/osortablevaluelist.h2
-rw-r--r--libopie2/qt3/opieui/ocombobox.cpp6
-rw-r--r--libopie2/qt3/opieui/oeditlistbox.cpp6
-rw-r--r--libopie2/qt3/opieui/olineedit.cpp6
8 files changed, 19 insertions, 19 deletions
diff --git a/libopie2/opieui/olistview.cpp b/libopie2/opieui/olistview.cpp
index 67b4b83..4386e0e 100644
--- a/libopie2/opieui/olistview.cpp
+++ b/libopie2/opieui/olistview.cpp
@@ -1,768 +1,768 @@
/*
                This file is part of the Opie Project
=. (C) 2003-2004 Michael 'Mickey' Lauer <mickey@Vanille.de>
.=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 <qpixmap.h>
/* OPIE */
#include <opie2/odebug.h>
#include <opie2/olistview.h>
using namespace Opie::Core;
namespace Opie {
namespace Ui {
/*======================================================================================
* OListView
*======================================================================================*/
OListView::OListView( QWidget *parent, const char *name, WFlags fl )
:QListView( parent, name, fl )
{
//FIXME: get from global settings and calculate ==> see oglobalsettings.*
m_alternateBackground = QColor( 238, 246, 255 );
m_columnSeparator = QPen( QColor( 150, 160, 170 ), 0, DotLine );
m_fullWidth = true;
connect( this, SIGNAL(expanded(QListViewItem*)), SLOT(expand(QListViewItem*)));
}
OListView::~OListView()
{
}
void OListView::setFullWidth( bool fullWidth )
{
m_fullWidth = fullWidth;
- #if QT_VERSION > 290
+ #if QT_VERSION >= 0x030000
header()->setStretchEnabled( fullWidth, columns()-1 );
#endif
}
bool OListView::fullWidth() const
{
return m_fullWidth;
}
int OListView::addColumn( const QString& label, int width )
{
int result = QListView::addColumn( label, width );
- #if QT_VERSION > 290
+ #if QT_VERSION >= 0x030000
if (m_fullWidth) {
header()->setStretchEnabled( false, columns()-2 );
header()->setStretchEnabled( true, columns()-1 );
}
#endif
return result;
}
int OListView::addColumn( const QIconSet& iconset, const QString& label, int width )
{
int result = QListView::addColumn( iconset, label, width );
- #if QT_VERSION > 290
+ #if QT_VERSION >= 0x030000
if (m_fullWidth) {
header()->setStretchEnabled( false, columns()-2 );
header()->setStretchEnabled( true, columns()-1 );
}
#endif
return result;
}
void OListView::removeColumn( int index )
{
QListView::removeColumn(index);
- #if QT_VERSION > 290
+ #if QT_VERSION >= 0x030000
if ( m_fullWidth && index == columns() )
{
header()->setStretchEnabled( true, columns()-1 );
}
#endif
}
const QColor& OListView::alternateBackground() const
{
return m_alternateBackground;
}
void OListView::setAlternateBackground( const QColor &c )
{
m_alternateBackground = c;
repaint();
}
const QPen& OListView::columnSeparator() const
{
return m_columnSeparator;
}
void OListView::setColumnSeparator( const QPen& p )
{
m_columnSeparator = p;
repaint();
}
void OListView::expand(QListViewItem *item)
{
((OListViewItem*)item)->expand();
}
OListViewItem* OListView::childFactory()
{
return new OListViewItem( this );
}
#ifndef QT_NO_DATASTREAM
void OListView::serializeTo( QDataStream& s ) const
{
#warning Caution... the binary format is still under construction...
odebug << "storing OListView..." << oendl;
// store number of columns and the labels
s << columns();
for ( int i = 0; i < columns(); ++i )
s << columnText( i );
// calculate the number of top-level items to serialize
int items = 0;
QListViewItem* item = firstChild();
while ( item )
{
item = item->nextSibling();
items++;
}
// store number of items and the items itself
s << items;
item = firstChild();
for ( int i = 0; i < items; ++i )
{
s << *static_cast<OListViewItem*>( item );
item = item->nextSibling();
}
odebug << "OListview stored." << oendl;
}
void OListView::serializeFrom( QDataStream& s )
{
#warning Caution... the binary format is still under construction...
odebug << "loading OListView..." << oendl;
int cols;
s >> cols;
odebug << "read number of columns = " << cols << oendl;
while ( columns() < cols ) addColumn( QString::null );
for ( int i = 0; i < cols; ++i )
{
QString coltext;
s >> coltext;
odebug << "read text '" << coltext << "' for column " << i << "" << oendl;
setColumnText( i, coltext );
}
int items;
s >> items;
odebug << "read number of items = " << items << oendl;
for ( int i = 0; i < items; ++i )
{
OListViewItem* item = childFactory();
s >> *item;
}
odebug << "OListView loaded." << oendl;
}
void OListView::expand()
{
odebug << "OListView::expand" << oendl;
QListViewItemIterator it( this );
while ( it.current() ) {
it.current()->setOpen( true );
++it;
}
}
void OListView::collapse()
{
odebug << "OListView::collapse" << oendl;
QListViewItemIterator it( this );
while ( it.current() ) {
it.current()->setOpen( false );
++it;
}
}
QDataStream& operator<<( QDataStream& s, const OListView& lv )
{
lv.serializeTo( s );
return s;
}
QDataStream& operator>>( QDataStream& s, OListView& lv )
{
lv.serializeFrom( s );
return s;
}
#endif // QT_NO_DATASTREAM
/*======================================================================================
* OListViewItem
*======================================================================================*/
OListViewItem::OListViewItem(QListView *parent)
: QListViewItem(parent)
{
init();
}
OListViewItem::OListViewItem(QListViewItem *parent)
: QListViewItem(parent)
{
init();
}
OListViewItem::OListViewItem(QListView *parent, QListViewItem *after)
: QListViewItem(parent, after)
{
init();
}
OListViewItem::OListViewItem(QListViewItem *parent, QListViewItem *after)
: QListViewItem(parent, after)
{
init();
}
OListViewItem::OListViewItem(QListView *parent,
QString label1, QString label2, QString label3, QString label4,
QString label5, QString label6, QString label7, QString label8)
: QListViewItem(parent, label1, label2, label3, label4, label5, label6, label7, label8)
{
init();
}
OListViewItem::OListViewItem(QListViewItem *parent,
QString label1, QString label2, QString label3, QString label4,
QString label5, QString label6, QString label7, QString label8)
: QListViewItem(parent, label1, label2, label3, label4, label5, label6, label7, label8)
{
init();
}
OListViewItem::OListViewItem(QListView *parent, QListViewItem *after,
QString label1, QString label2, QString label3, QString label4,
QString label5, QString label6, QString label7, QString label8)
: QListViewItem(parent, after, label1, label2, label3, label4, label5, label6, label7, label8)
{
init();
}
OListViewItem::OListViewItem(QListViewItem *parent, QListViewItem *after,
QString label1, QString label2, QString label3, QString label4,
QString label5, QString label6, QString label7, QString label8)
: QListViewItem(parent, after, label1, label2, label3, label4, label5, label6, label7, label8)
{
init();
}
OListViewItem::~OListViewItem()
{
}
void OListViewItem::init()
{
m_known = false;
}
const QColor &OListViewItem::backgroundColor()
{
return isAlternate() ? static_cast<OListView*>(listView())->alternateBackground() :
listView()->viewport()->colorGroup().base();
}
bool OListViewItem::isAlternate()
{
OListView *lv = static_cast<OListView*>( listView() );
// check if the item above is an OListViewItem
OListViewItem *above = static_cast<OListViewItem*>( itemAbove() );
/*if (! itemAbove()->inherits( "OListViewItem" )) return false;*/
// check if we have a valid alternate background color
if (!(lv && lv->alternateBackground().isValid())) return false;
m_known = above ? above->m_known : true;
if (m_known)
{
m_odd = above ? !above->m_odd : false;
}
else
{
OListViewItem *item;
bool previous = true;
if (parent())
{
item = static_cast<OListViewItem *>(parent());
if ( item /*&& item->inherits( "OListViewItem" )*/ ) previous = item->m_odd;
item = static_cast<OListViewItem *>(parent()->firstChild());
/* if ( !item.inherits( "OListViewItem" ) item = 0; */
}
else
{
item = static_cast<OListViewItem *>(lv->firstChild());
}
while(item)
{
item->m_odd = previous = !previous;
item->m_known = true;
item = static_cast<OListViewItem *>(item->nextSibling());
/* if (!item.inherits( "OListViewItem" ) ) break; */
}
}
return m_odd;
}
void OListViewItem::paintCell(QPainter *p, const QColorGroup &cg, int column, int width, int alignment)
{
QColorGroup _cg = cg;
const QPixmap *pm = listView()->viewport()->backgroundPixmap();
if (pm && !pm->isNull())
{
_cg.setBrush( QColorGroup::Base, QBrush(backgroundColor(), *pm) );
p->setBrushOrigin( -listView()->contentsX(), -listView()->contentsY() );
}
else if ( isAlternate() )
{
_cg.setColor( QColorGroup::Base, static_cast<OListView*>( listView() )->alternateBackground() );
}
QListViewItem::paintCell( p, _cg, column, width, alignment );
//FIXME: Use styling here!
const QPen& pen = static_cast<OListView*>( listView() )->columnSeparator();
p->setPen( pen );
p->drawLine( width-1, 0, width-1, height() );
}
OListViewItem* OListViewItem::childFactory()
{
return new OListViewItem( this );
}
#ifndef QT_NO_DATASTREAM
void OListViewItem::serializeTo( QDataStream& s ) const
{
#warning Caution... the binary format is still under construction...
odebug << "storing OListViewItem..." << oendl;
// store item text
for ( int i = 0; i < listView()->columns(); ++i )
{
s << text( i );
}
// calculate the number of children to serialize
int items = 0;
QListViewItem* item = firstChild();
while ( item )
{
item = item->nextSibling();
items++;
}
// store number of items and the items itself
s << items;
item = firstChild();
for ( int i = 0; i < items; ++i )
{
s << *static_cast<OListViewItem*>( item );
item = item->nextSibling();
}
odebug << "OListviewItem stored." << oendl;
}
void OListViewItem::serializeFrom( QDataStream& s )
{
#warning Caution... the binary format is still under construction...
odebug << "loading OListViewItem..." << oendl;
for ( int i = 0; i < listView()->columns(); ++i )
{
QString coltext;
s >> coltext;
odebug << "read text '" << coltext << "' for column " << i << "" << oendl;
setText( i, coltext );
}
int items;
s >> items;
odebug << "read number of items = " << items << "" << oendl;
for ( int i = 0; i < items; ++i )
{
OListViewItem* item = childFactory();
s >> (*item);
}
odebug << "OListViewItem loaded." << oendl;
}
QDataStream& operator<<( QDataStream& s, const OListViewItem& lvi )
{
lvi.serializeTo( s );
return s;
}
QDataStream& operator>>( QDataStream& s, OListViewItem& lvi )
{
lvi.serializeFrom( s );
return s;
}
#endif // QT_NO_DATASTREAM
/*======================================================================================
* OCheckListItem
*======================================================================================*/
OCheckListItem::OCheckListItem( QCheckListItem* parent, const QString& text, Type t )
:QCheckListItem( parent, text, t )
{
init();
}
OCheckListItem::OCheckListItem( QListViewItem* parent, const QString& text, Type t)
:QCheckListItem( parent, text, t )
{
init();
}
OCheckListItem::OCheckListItem( QListView* parent, const QString& text, Type t )
:QCheckListItem( parent, text, t )
{
init();
}
OCheckListItem::OCheckListItem( QListViewItem* parent, const QString& text, const QPixmap& p )
:QCheckListItem( parent, text, p )
{
init();
}
OCheckListItem::OCheckListItem( QListView* parent, const QString& text, const QPixmap& p )
:QCheckListItem( parent, text, p )
{
init();
}
OCheckListItem::~OCheckListItem()
{
}
void OCheckListItem::init()
{
m_known = false;
}
const QColor &OCheckListItem::backgroundColor()
{
return isAlternate() ? static_cast<OListView*>(listView())->alternateBackground() :
listView()->viewport()->colorGroup().base();
}
bool OCheckListItem::isAlternate()
{
OListView *lv = static_cast<OListView*>( listView() );
// check if the item above is an OCheckListItem
OCheckListItem *above = static_cast<OCheckListItem*>( itemAbove() );
/*if (! itemAbove()->inherits( "OCheckListItem" )) return false;*/
// check if we have a valid alternate background color
if (!(lv && lv->alternateBackground().isValid())) return false;
m_known = above ? above->m_known : true;
if (m_known)
{
m_odd = above ? !above->m_odd : false;
}
else
{
OCheckListItem *item;
bool previous = true;
if (parent())
{
item = static_cast<OCheckListItem *>(parent());
if ( item /*&& item->inherits( "OCheckListItem" )*/ ) previous = item->m_odd;
item = static_cast<OCheckListItem *>(parent()->firstChild());
/* if ( !item.inherits( "OCheckListItem" ) item = 0; */
}
else
{
item = static_cast<OCheckListItem *>(lv->firstChild());
}
while(item)
{
item->m_odd = previous = !previous;
item->m_known = true;
item = static_cast<OCheckListItem *>(item->nextSibling());
/* if (!item.inherits( "OCheckListItem" ) ) break; */
}
}
return m_odd;
}
void OCheckListItem::paintCell(QPainter *p, const QColorGroup &cg, int column, int width, int alignment)
{
QColorGroup _cg = cg;
const QPixmap *pm = listView()->viewport()->backgroundPixmap();
if (pm && !pm->isNull())
{
_cg.setBrush( QColorGroup::Base, QBrush(backgroundColor(), *pm) );
p->setBrushOrigin( -listView()->contentsX(), -listView()->contentsY() );
}
else if ( isAlternate() )
{
_cg.setColor( QColorGroup::Base, static_cast<OListView*>( listView() )->alternateBackground() );
}
QCheckListItem::paintCell( p, _cg, column, width, alignment );
//FIXME: Use styling here!
const QPen& pen = static_cast<OListView*>( listView() )->columnSeparator();
p->setPen( pen );
p->drawLine( width-1, 0, width-1, height() );
}
/*======================================================================================
* ONamedListView
*======================================================================================*/
ONamedListView::ONamedListView( QWidget *parent, const char *name )
:OListView( parent, name )
{
}
ONamedListView::~ONamedListView()
{
}
void ONamedListView::addColumns( const QStringList& columns )
{
for ( QStringList::ConstIterator it = columns.begin(); it != columns.end(); ++it )
{
odebug << "adding column " << *it << "" << oendl;
addColumn( *it );
}
}
int ONamedListView::findColumn( const QString& text ) const
{
//FIXME: If used excessively, this will slow down performance of updates
//FIXME: because of the linear search over all column texts.
//FIXME: I will optimize later by using a hash map.
for ( int i = 0; i < columns(); ++i )
if ( columnText( i ) == text )
return i;
return -1;
}
ONamedListViewItem* ONamedListView::find( int column, const QString& text, int recurse ) const
{
return find( (ONamedListViewItem*) firstChild(), column, text, recurse );
}
ONamedListViewItem* ONamedListView::find( ONamedListViewItem* item, int column, const QString& text, int recurse ) const
{
ONamedListViewItem* result;
while ( item && item->text( column ) != text )
{
odebug << "checked " << item->text( column ) << "" << oendl;
if ( recurse < 0 || recurse > 0 )
{
odebug << "recursion is " << recurse << " - recursing into..." << oendl;
result = find( (ONamedListViewItem*) item->firstChild(), column, text, recurse-1 );
if ( result ) return result;
}
item = (ONamedListViewItem*) item->itemBelow();
}
if ( item && item->text( column ) == text )
return item;
else
return 0;
}
ONamedListViewItem* ONamedListView::find( const QString& column, const QString& text, int recurse ) const
{
int col = findColumn( column );
if ( col != -1 )
return find( (ONamedListViewItem*) firstChild(), col, text, recurse );
else
return 0;
}
ONamedListViewItem* ONamedListView::find( ONamedListViewItem* item, const QString& column, const QString& text, int recurse ) const
{
int col = findColumn( column );
if ( col != -1 )
return find( item, col, text, recurse );
else
return 0;
}
/*======================================================================================
* ONamedListViewItem
*======================================================================================*/
ONamedListViewItem::ONamedListViewItem( QListView* parent, const QStringList& texts )
:OListViewItem( parent )
{
setText( texts );
}
ONamedListViewItem::ONamedListViewItem( QListViewItem* parent, const QStringList& texts )
:OListViewItem( parent )
{
setText( texts );
}
ONamedListViewItem::ONamedListViewItem( QListView* parent, QListViewItem* after, const QStringList& texts )
:OListViewItem( parent, after )
{
setText( texts );
}
ONamedListViewItem::ONamedListViewItem( QListViewItem* parent, QListViewItem* after, const QStringList& texts )
:OListViewItem( parent, after )
{
setText( texts );
}
ONamedListViewItem::~ONamedListViewItem()
{
}
void ONamedListViewItem::setText( const QStringList& texts )
{
int col = 0;
for ( QStringList::ConstIterator it = texts.begin(); it != texts.end(); ++it )
{
odebug << "setting column " << col << " = text " << *it << "" << oendl;
OListViewItem::setText( col++, *it );
}
}
void ONamedListViewItem::setText( const QString& column, const QString& text )
{
//FIXME: If used excessively, this will slow down performance of updates
//FIXME: because of the linear search over all column texts.
//FIXME: I will optimize later by using a hash map.
int col = ( (ONamedListView*) listView() )->findColumn( column );
if ( col != -1 )
OListViewItem::setText( col, text );
else
owarn << "ONamedListViewItem::setText(): Warning! Columntext '" << column << "' not found." << oendl;
}
ONamedListViewItem* ONamedListViewItem::find( int column, const QString& text, int recurse ) const
{
return ( (ONamedListView*) listView() )->find( (ONamedListViewItem*) firstChild(), column, text, recurse );
}
ONamedListViewItem* ONamedListViewItem::find( const QString& column, const QString& text, int recurse ) const
{
int col = ( (ONamedListView*) listView() )->findColumn( column );
if ( col != -1 )
return ( (ONamedListView*) listView() )->find( (ONamedListViewItem*) firstChild(), col, text, recurse );
else
return 0;
}
}
}
diff --git a/libopie2/opieui/opopupmenu.cpp b/libopie2/opieui/opopupmenu.cpp
index 50c613f..5ce048e 100644
--- a/libopie2/opieui/opopupmenu.cpp
+++ b/libopie2/opieui/opopupmenu.cpp
@@ -1,600 +1,600 @@
/* This file is part of the KDE libraries
Copyright (C) 2000 Daniel M. Duley <mosfet@kde.org>
Copyright (C) 2002 Hamish Rodda <meddie@yoyo.its.monash.edu.au>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License version 2 as published by the Free Software Foundation.
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.
*/
/* OPIE */
#include <opie2/opopupmenu.h>
#include <opie2/oconfig.h>
#include <opie2/odebug.h>
/* QT */
#include <qdrawutil.h>
#include <qtimer.h>
using namespace Opie::Core;
using namespace Opie::Ui;
OPopupTitle::OPopupTitle(QWidget *parent, const char *name)
: QWidget(parent, name)
{
setMinimumSize(16, fontMetrics().height()+8);
}
OPopupTitle::OPopupTitle(OPixmapEffect::GradientType /* gradient */,
const QColor &/* color */, const QColor &/* textColor */,
QWidget *parent, const char *name)
: QWidget(parent, name)
{
setMinimumSize(16, fontMetrics().height()+8);
}
OPopupTitle::OPopupTitle(const OPixmap & /* background */, const QColor &/* color */,
const QColor &/* textColor */, QWidget *parent,
const char *name)
: QWidget(parent, name)
{
setMinimumSize(16, fontMetrics().height()+8);
}
void OPopupTitle::setTitle(const QString &text, const QPixmap *icon)
{
titleStr = text;
if (icon)
miniicon = *icon;
else
miniicon.resize(0, 0);
int w = miniicon.width()+fontMetrics().width(titleStr);
int h = QMAX( fontMetrics().height(), miniicon.height() );
setMinimumSize( w+16, h+8 );
}
void OPopupTitle::setText( const QString &text )
{
titleStr = text;
int w = miniicon.width()+fontMetrics().width(titleStr);
int h = QMAX( fontMetrics().height(), miniicon.height() );
setMinimumSize( w+16, h+8 );
}
void OPopupTitle::setIcon( const QPixmap &pix )
{
miniicon = pix;
int w = miniicon.width()+fontMetrics().width(titleStr);
int h = QMAX( fontMetrics().height(), miniicon.height() );
setMinimumSize( w+16, h+8 );
}
void OPopupTitle::paintEvent(QPaintEvent *)
{
QRect r(rect());
QPainter p(this);
- #if QT_VERSION > 290
+ #if QT_VERSION >= 0x030000
qApp->style().drawPrimitive(QStyle::PE_HeaderSection, &p, r, palette().active());
#else
#warning OPopupMenu is not fully functional on Qt2
#endif
if (!miniicon.isNull())
p.drawPixmap(4, (r.height()-miniicon.height())/2, miniicon);
if (!titleStr.isNull())
{
p.setPen(palette().active().text());
QFont f = p.font();
f.setBold(true);
p.setFont(f);
if(!miniicon.isNull())
{
p.drawText(miniicon.width()+8, 0, width()-(miniicon.width()+8),
height(), AlignLeft | AlignVCenter | SingleLine,
titleStr);
}
else
{
p.drawText(0, 0, width(), height(),
AlignCenter | SingleLine, titleStr);
}
}
p.setPen(palette().active().highlight());
p.drawLine(0, 0, r.right(), 0);
}
QSize OPopupTitle::sizeHint() const
{
return(minimumSize());
}
class OPopupMenu::OPopupMenuPrivate
{
public:
OPopupMenuPrivate ()
: noMatches(false)
, shortcuts(false)
, autoExec(false)
, lastHitIndex(-1)
, m_ctxMenu(0)
{}
~OPopupMenuPrivate ()
{
delete m_ctxMenu;
}
QString m_lastTitle;
// variables for keyboard navigation
QTimer clearTimer;
bool noMatches : 1;
bool shortcuts : 1;
bool autoExec : 1;
QString keySeq;
QString originalText;
int lastHitIndex;
// support for RMB menus on menus
QPopupMenu* m_ctxMenu;
static bool s_continueCtxMenuShow;
static int s_highlightedItem;
static OPopupMenu* s_contextedMenu;
};
int OPopupMenu::OPopupMenuPrivate::s_highlightedItem(-1);
OPopupMenu* OPopupMenu::OPopupMenuPrivate::s_contextedMenu(0);
bool OPopupMenu::OPopupMenuPrivate::s_continueCtxMenuShow(true);
OPopupMenu::OPopupMenu(QWidget *parent, const char *name)
: QPopupMenu(parent, name)
{
d = new OPopupMenuPrivate;
resetKeyboardVars();
connect(&(d->clearTimer), SIGNAL(timeout()), SLOT(resetKeyboardVars()));
}
OPopupMenu::~OPopupMenu()
{
if (OPopupMenuPrivate::s_contextedMenu == this)
{
OPopupMenuPrivate::s_contextedMenu = 0;
OPopupMenuPrivate::s_highlightedItem = -1;
}
delete d;
}
int OPopupMenu::insertTitle(const QString &text, int id, int index)
{
OPopupTitle *titleItem = new OPopupTitle();
titleItem->setTitle(text);
int ret = insertItem(titleItem, id, index);
setItemEnabled(id, false);
return ret;
}
int OPopupMenu::insertTitle(const QPixmap &icon, const QString &text, int id,
int index)
{
OPopupTitle *titleItem = new OPopupTitle();
titleItem->setTitle(text, &icon);
int ret = insertItem(titleItem, id, index);
setItemEnabled(id, false);
return ret;
}
void OPopupMenu::changeTitle(int id, const QString &text)
{
QMenuItem *item = findItem(id);
if(item){
if(item->widget())
((OPopupTitle *)item->widget())->setTitle(text);
#ifndef NDEBUG
else
owarn << "KPopupMenu: changeTitle() called with non-title id " << id << "" << oendl;
#endif
}
#ifndef NDEBUG
else
owarn << "KPopupMenu: changeTitle() called with invalid id " << id << "" << oendl;
#endif
}
void OPopupMenu::changeTitle(int id, const QPixmap &icon, const QString &text)
{
QMenuItem *item = findItem(id);
if(item){
if(item->widget())
((OPopupTitle *)item->widget())->setTitle(text, &icon);
#ifndef NDEBUG
else
owarn << "KPopupMenu: changeTitle() called with non-title id " << id << "" << oendl;
#endif
}
#ifndef NDEBUG
else
owarn << "KPopupMenu: changeTitle() called with invalid id " << id << "" << oendl;
#endif
}
QString OPopupMenu::title(int id) const
{
if(id == -1) // obsolete
return(d->m_lastTitle);
QMenuItem *item = findItem(id);
if(item){
if(item->widget())
return(((OPopupTitle *)item->widget())->title());
else
owarn << "OPopupMenu: title() called with non-title id " << id << "." << oendl;
}
else
owarn << "OPopupMenu: title() called with invalid id " << id << "." << oendl;
return(QString::null);
}
QPixmap OPopupMenu::titlePixmap(int id) const
{
QMenuItem *item = findItem(id);
if(item){
if(item->widget())
return(((OPopupTitle *)item->widget())->icon());
else
owarn << "KPopupMenu: titlePixmap() called with non-title id " << id << "." << oendl;
}
else
owarn << "KPopupMenu: titlePixmap() called with invalid id " << id << "." << oendl;
QPixmap tmp;
return(tmp);
}
/**
* This is re-implemented for keyboard navigation.
*/
void OPopupMenu::closeEvent(QCloseEvent*e)
{
if (d->shortcuts)
resetKeyboardVars();
QPopupMenu::closeEvent(e);
}
void OPopupMenu::keyPressEvent(QKeyEvent* e)
{
if (!d->shortcuts) {
// continue event processing by Qpopup
//e->ignore();
QPopupMenu::keyPressEvent(e);
return;
}
int i = 0;
bool firstpass = true;
QString keyString = e->text();
// check for common commands dealt with by QPopup
int key = e->key();
if (key == Key_Escape || key == Key_Return || key == Key_Enter
|| key == Key_Up || key == Key_Down || key == Key_Left
|| key == Key_Right || key == Key_F1) {
resetKeyboardVars();
// continue event processing by Qpopup
//e->ignore();
QPopupMenu::keyPressEvent(e);
return;
}
// check to see if the user wants to remove a key from the sequence (backspace)
// or clear the sequence (delete)
if (!d->keySeq.isNull()) {
if (key == Key_Backspace) {
if (d->keySeq.length() == 1) {
resetKeyboardVars();
return;
}
// keep the last sequence in keyString
keyString = d->keySeq.left(d->keySeq.length() - 1);
// allow sequence matching to be tried again
resetKeyboardVars();
} else if (key == Key_Delete) {
resetKeyboardVars();
// clear active item
setActiveItem(0);
return;
} else if (d->noMatches) {
// clear if there are no matches
resetKeyboardVars();
// clear active item
setActiveItem(0);
} else {
// the key sequence is not a null string
// therefore the lastHitIndex is valid
i = d->lastHitIndex;
}
} else if (key == Key_Backspace && parentMenu) {
// backspace with no chars in the buffer... go back a menu.
hide();
resetKeyboardVars();
return;
}
d->keySeq += keyString;
int seqLen = d->keySeq.length();
for (; i < (int)count(); i++) {
// compare typed text with text of this entry
int j = idAt(i);
// don't search disabled entries
if (!isItemEnabled(j))
continue;
QString thisText;
// retrieve the right text
// (the last selected item one may have additional ampersands)
if (i == d->lastHitIndex)
thisText = d->originalText;
else
thisText = text(j);
// if there is an accelerator present, remove it
if ((int)accel(j) != 0)
thisText = thisText.replace(QRegExp("&"), "");
// chop text to the search length
thisText = thisText.left(seqLen);
// do the search
if (thisText.find(d->keySeq, 0, false) == 0) {
if (firstpass) {
// match
setActiveItem(i);
// check to see if we're underlining a different item
if (d->lastHitIndex != i)
// yes; revert the underlining
changeItem(idAt(d->lastHitIndex), d->originalText);
// set the original text if it's a different item
if (d->lastHitIndex != i || d->lastHitIndex == -1)
d->originalText = text(j);
// underline the currently selected item
changeItem(j, underlineText(d->originalText, d->keySeq.length()));
// remeber what's going on
d->lastHitIndex = i;
// start/restart the clear timer
d->clearTimer.start(5000, true);
// go around for another try, to see if we can execute
firstpass = false;
} else {
// don't allow execution
return;
}
}
// fall through to allow execution
}
if (!firstpass) {
if (d->autoExec) {
// activate anything
activateItemAt(d->lastHitIndex);
resetKeyboardVars();
} else if (findItem(idAt(d->lastHitIndex)) &&
findItem(idAt(d->lastHitIndex))->popup()) {
// only activate sub-menus
activateItemAt(d->lastHitIndex);
resetKeyboardVars();
}
return;
}
// no matches whatsoever, clean up
resetKeyboardVars(true);
//e->ignore();
QPopupMenu::keyPressEvent(e);
}
QString OPopupMenu::underlineText(const QString& text, uint length)
{
QString ret = text;
for (uint i = 0; i < length; i++) {
if (ret[2*i] != '&')
ret.insert(2*i, "&");
}
return ret;
}
void OPopupMenu::resetKeyboardVars(bool noMatches /* = false */)
{
// Clean up keyboard variables
if (d->lastHitIndex != -1) {
changeItem(idAt(d->lastHitIndex), d->originalText);
d->lastHitIndex = -1;
}
if (!noMatches) {
d->keySeq = QString::null;
}
d->noMatches = noMatches;
}
void OPopupMenu::setKeyboardShortcutsEnabled(bool enable)
{
d->shortcuts = enable;
}
void OPopupMenu::setKeyboardShortcutsExecute(bool enable)
{
d->autoExec = enable;
}
/**
* End keyboard navigation.
*/
/**
* RMB menus on menus
*/
QPopupMenu* OPopupMenu::contextMenu()
{
if (!d->m_ctxMenu)
{
d->m_ctxMenu = new QPopupMenu(this);
installEventFilter(this);
connect(d->m_ctxMenu, SIGNAL(aboutToHide()), this, SLOT(ctxMenuHiding()));
}
return d->m_ctxMenu;
}
void OPopupMenu::cancelContextMenuShow()
{
OPopupMenuPrivate::s_continueCtxMenuShow = false;
}
int OPopupMenu::contextMenuFocusItem()
{
return OPopupMenuPrivate::s_highlightedItem;
}
OPopupMenu* OPopupMenu::contextMenuFocus()
{
return OPopupMenuPrivate::s_contextedMenu;
}
void OPopupMenu::itemHighlighted(int /* whichItem */)
{
if (!d->m_ctxMenu || !d->m_ctxMenu->isVisible())
{
return;
}
d->m_ctxMenu->hide();
showCtxMenu(mapFromGlobal(QCursor::pos()));
}
void OPopupMenu::showCtxMenu(QPoint pos)
{
OPopupMenuPrivate::s_highlightedItem = idAt(pos);
if (OPopupMenuPrivate::s_highlightedItem == -1)
{
OPopupMenuPrivate::s_contextedMenu = 0;
return;
}
emit aboutToShowContextMenu(this, OPopupMenuPrivate::s_highlightedItem, d->m_ctxMenu);
if (!OPopupMenuPrivate::s_continueCtxMenuShow)
{
OPopupMenuPrivate::s_continueCtxMenuShow = true;
return;
}
OPopupMenuPrivate::s_contextedMenu = this;
d->m_ctxMenu->popup(this->mapToGlobal(pos));
connect(this, SIGNAL(highlighted(int)), this, SLOT(itemHighlighted(int)));
}
void OPopupMenu::ctxMenuHiding()
{
disconnect(this, SIGNAL(highlighted(int)), this, SLOT(itemHighlighted(int)));
OPopupMenuPrivate::s_continueCtxMenuShow = true;
}
bool OPopupMenu::eventFilter(QObject* obj, QEvent* event)
{
if (d->m_ctxMenu && obj == this)
{
if (event->type() == QEvent::MouseButtonRelease)
{
if (d->m_ctxMenu->isVisible())
{
return true;
}
}
- #if QT_VERSION > 290
+ #if QT_VERSION >= 0x030000
else if (event->type() == QEvent::ContextMenu)
#else
else if ( (event->type() == QEvent::MouseButtonPress) &&
( (QMouseEvent*) event )->button() == QMouseEvent::RightButton )
#endif
{
showCtxMenu(mapFromGlobal(QCursor::pos()));
return true;
}
}
return QWidget::eventFilter(obj, event);
}
void OPopupMenu::hideEvent(QHideEvent*)
{
if (d->m_ctxMenu)
{
d->m_ctxMenu->hide();
}
}
/**
* end of RMB menus on menus support
*/
// Obsolete
OPopupMenu::OPopupMenu(const QString& title, QWidget *parent, const char *name)
: QPopupMenu(parent, name)
{
d = new OPopupMenuPrivate;
setTitle(title);
}
// Obsolete
void OPopupMenu::setTitle(const QString &title)
{
OPopupTitle *titleItem = new OPopupTitle();
titleItem->setTitle(title);
insertItem(titleItem);
d->m_lastTitle = title;
}
void OPopupTitle::virtual_hook( int, void* )
{ /*BASE::virtual_hook( id, data );*/ }
void OPopupMenu::virtual_hook( int, void* )
{ /*BASE::virtual_hook( id, data );*/ }
diff --git a/libopie2/opieui/oselector.cpp b/libopie2/opieui/oselector.cpp
index 05543c5..936dfe6 100644
--- a/libopie2/opieui/oselector.cpp
+++ b/libopie2/opieui/oselector.cpp
@@ -1,719 +1,719 @@
/* This file is part of the KDE libraries
Copyright (C) 1997 Martin Jones (mjones@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 <qimage.h>
#include <qdrawutil.h>
/* OPIE */
#include <opie2/oimageeffect.h>
#include <opie2/oselector.h>
#define STORE_W 8
#define STORE_W2 STORE_W * 2
//-----------------------------------------------------------------------------
/*
* 2D value selector.
* The contents of the selector are drawn by derived class.
*/
using namespace Opie::Ui;
OXYSelector::OXYSelector( QWidget *parent, const char *name )
: QWidget( parent, name )
{
xPos = 0;
yPos = 0;
minX = 0;
minY = 0;
maxX = 100;
maxY = 100;
store.setOptimization( QPixmap::BestOptim );
store.resize( STORE_W2, STORE_W2 );
}
OXYSelector::~OXYSelector()
{}
void OXYSelector::setRange( int _minX, int _minY, int _maxX, int _maxY )
{
px = 2;
py = 2;
minX = _minX;
minY = _minY;
maxX = _maxX;
maxY = _maxY;
}
void OXYSelector::setValues( int _xPos, int _yPos )
{
xPos = _xPos;
yPos = _yPos;
if ( xPos > maxX )
xPos = maxX;
else if ( xPos < minX )
xPos = minX;
if ( yPos > maxY )
yPos = maxY;
else if ( yPos < minY )
yPos = minY;
int xp = 2 + (width() - 4) * xPos / (maxX - minX);
int yp = height() - 2 - (height() - 4) * yPos / (maxY - minY);
setPosition( xp, yp );
}
QRect OXYSelector::contentsRect() const
{
return QRect( 2, 2, width()-4, height()-4 );
}
void OXYSelector::paintEvent( QPaintEvent *ev )
{
QRect cursorRect( px - STORE_W, py - STORE_W, STORE_W2, STORE_W2);
QRect paintRect = ev->rect();
QPainter painter;
painter.begin( this );
QBrush brush;
qDrawShadePanel( &painter, 0, 0, width(), height(), colorGroup(),
TRUE, 2, &brush );
drawContents( &painter );
if (paintRect.contains(cursorRect))
{
bitBlt( &store, 0, 0, this, px - STORE_W, py - STORE_W,
STORE_W2, STORE_W2, CopyROP );
drawCursor( &painter, px, py );
}
else if (paintRect.intersects(cursorRect))
{
repaint( cursorRect, false);
}
painter.end();
}
void OXYSelector::mousePressEvent( QMouseEvent *e )
{
int xVal, yVal;
valuesFromPosition( e->pos().x() - 2, e->pos().y() - 2, xVal, yVal );
setValues( xVal, yVal );
emit valueChanged( xPos, yPos );
}
void OXYSelector::mouseMoveEvent( QMouseEvent *e )
{
int xVal, yVal;
valuesFromPosition( e->pos().x() - 2, e->pos().y() - 2, xVal, yVal );
setValues( xVal, yVal );
emit valueChanged( xPos, yPos );
}
void OXYSelector::wheelEvent( QWheelEvent *e )
{
- #if QT_VERSION > 290
+ #if QT_VERSION >= 0x030000
if ( e->orientation() == Qt::Horizontal )
setValues( xValue() + e->delta()/120, yValue() );
else
setValues( xValue(), yValue() + e->delta()/120 );
emit valueChanged( xPos, yPos );
#else
Q_UNUSED( e )
#endif
}
void OXYSelector::valuesFromPosition( int x, int y, int &xVal, int &yVal ) const
{
xVal = ( (maxX-minX) * (x-2) ) / ( width()-4 );
yVal = maxY - ( ( (maxY-minY) * (y-2) ) / ( height()-4 ) );
if ( xVal > maxX )
xVal = maxX;
else if ( xVal < minX )
xVal = minX;
if ( yVal > maxY )
yVal = maxY;
else if ( yVal < minY )
yVal = minY;
}
void OXYSelector::setPosition( int xp, int yp )
{
if ( xp < 2 )
xp = 2;
else if ( xp > width() - 2 )
xp = width() - 2;
if ( yp < 2 )
yp = 2;
else if ( yp > height() - 2 )
yp = height() - 2;
QPainter painter;
painter.begin( this );
bitBlt( this, px - STORE_W, py - STORE_W, &store, 0, 0,
STORE_W2, STORE_W2, CopyROP );
bitBlt( &store, 0, 0, this, xp - STORE_W, yp - STORE_W,
STORE_W2, STORE_W2, CopyROP );
drawCursor( &painter, xp, yp );
px = xp;
py = yp;
painter.end();
}
void OXYSelector::drawContents( QPainter * )
{}
void OXYSelector::drawCursor( QPainter *p, int xp, int yp )
{
p->setPen( QPen( white ) );
p->drawLine( xp - 6, yp - 6, xp - 2, yp - 2 );
p->drawLine( xp - 6, yp + 6, xp - 2, yp + 2 );
p->drawLine( xp + 6, yp - 6, xp + 2, yp - 2 );
p->drawLine( xp + 6, yp + 6, xp + 2, yp + 2 );
}
//-----------------------------------------------------------------------------
/*
* 1D value selector with contents drawn by derived class.
* See OColorDialog for example.
*/
OSelector::OSelector( QWidget *parent, const char *name )
: QWidget( parent, name ), QRangeControl()
{
_orientation = Horizontal;
_indent = TRUE;
}
OSelector::OSelector( Orientation o, QWidget *parent, const char *name )
: QWidget( parent, name ), QRangeControl()
{
_orientation = o;
_indent = TRUE;
}
OSelector::~OSelector()
{}
QRect OSelector::contentsRect() const
{
if ( orientation() == Vertical )
return QRect( 2, 5, width()-9, height()-10 );
else
return QRect( 5, 2, width()-10, height()-9 );
}
void OSelector::paintEvent( QPaintEvent * )
{
QPainter painter;
painter.begin( this );
drawContents( &painter );
QBrush brush;
if ( indent() )
{
if ( orientation() == Vertical )
qDrawShadePanel( &painter, 0, 3, width()-5, height()-6,
colorGroup(), TRUE, 2, &brush );
else
qDrawShadePanel( &painter, 3, 0, width()-6, height()-5,
colorGroup(), TRUE, 2, &brush );
}
QPoint pos = calcArrowPos( value() );
drawArrow( &painter, TRUE, pos );
painter.end();
}
void OSelector::mousePressEvent( QMouseEvent *e )
{
moveArrow( e->pos() );
}
void OSelector::mouseMoveEvent( QMouseEvent *e )
{
moveArrow( e->pos() );
}
void OSelector::wheelEvent( QWheelEvent *e )
{
int val = value() + e->delta()/120;
emit valueChanged( val );
setValue( val );
}
void OSelector::valueChange()
{
QPainter painter;
QPoint pos;
painter.begin( this );
pos = calcArrowPos( prevValue() );
drawArrow( &painter, FALSE, pos );
pos = calcArrowPos( value() );
drawArrow( &painter, TRUE, pos );
painter.end();
}
void OSelector::moveArrow( const QPoint &pos )
{
int val;
if ( orientation() == Vertical )
val = ( maxValue() - minValue() ) * (height()-pos.y()-3)
/ (height()-10) + minValue();
else
val = ( maxValue() - minValue() ) * (width()-pos.x()-3)
/ (width()-10) + minValue();
if ( val > maxValue() )
val = maxValue();
if ( val < minValue() )
val = minValue();
emit valueChanged( val );
setValue( val );
}
QPoint OSelector::calcArrowPos( int val )
{
QPoint p;
if ( orientation() == Vertical )
{
p.setY( height() - ( (height()-10) * val
/ ( maxValue() - minValue() ) + 5 ) );
p.setX( width() - 5 );
}
else
{
p.setX( width() - ( (width()-10) * val
/ ( maxValue() - minValue() ) + 5 ) );
p.setY( height() - 5 );
}
return p;
}
void OSelector::drawContents( QPainter * )
{}
void OSelector::drawArrow( QPainter *painter, bool show, const QPoint &pos )
{
if ( show )
{
QPointArray array(3);
painter->setPen( QPen() );
painter->setBrush( QBrush( colorGroup().buttonText() ) );
if ( orientation() == Vertical )
{
array.setPoint( 0, pos.x()+0, pos.y()+0 );
array.setPoint( 1, pos.x()+5, pos.y()+5 );
array.setPoint( 2, pos.x()+5, pos.y()-5 );
}
else
{
array.setPoint( 0, pos.x()+0, pos.y()+0 );
array.setPoint( 1, pos.x()+5, pos.y()+5 );
array.setPoint( 2, pos.x()-5, pos.y()+5 );
}
painter->drawPolygon( array );
}
else
{
if ( orientation() == Vertical )
{
repaint(pos.x(), pos.y()-5, 6, 11, true);
}
else
{
repaint(pos.x()-5, pos.y(), 11, 6, true);
}
}
}
//----------------------------------------------------------------------------
OGradientSelector::OGradientSelector( QWidget *parent, const char *name )
: OSelector( parent, name )
{
init();
}
OGradientSelector::OGradientSelector( Orientation o, QWidget *parent,
const char *name )
: OSelector( o, parent, name )
{
init();
}
OGradientSelector::~OGradientSelector()
{}
void OGradientSelector::init()
{
color1.setRgb( 0, 0, 0 );
color2.setRgb( 255, 255, 255 );
text1 = text2 = "";
}
void OGradientSelector::drawContents( QPainter *painter )
{
QImage image( contentsRect().width(), contentsRect().height(), 32 );
QColor col;
float scale;
int redDiff = color2.red() - color1.red();
int greenDiff = color2.green() - color1.green();
int blueDiff = color2.blue() - color1.blue();
if ( orientation() == Vertical )
{
for ( int y = 0; y < image.height(); y++ )
{
scale = 1.0 * y / image.height();
col.setRgb( color1.red() + int(redDiff*scale),
color1.green() + int(greenDiff*scale),
color1.blue() + int(blueDiff*scale) );
unsigned int *p = (uint *) image.scanLine( y );
for ( int x = 0; x < image.width(); x++ )
*p++ = col.rgb();
}
}
else
{
unsigned int *p = (uint *) image.scanLine( 0 );
for ( int x = 0; x < image.width(); x++ )
{
scale = 1.0 * x / image.width();
col.setRgb( color1.red() + int(redDiff*scale),
color1.green() + int(greenDiff*scale),
color1.blue() + int(blueDiff*scale) );
*p++ = col.rgb();
}
for ( int y = 1; y < image.height(); y++ )
memcpy( image.scanLine( y ), image.scanLine( y - 1),
sizeof( unsigned int ) * image.width() );
}
QColor ditherPalette[8];
for ( int s = 0; s < 8; s++ )
ditherPalette[s].setRgb( color1.red() + redDiff * s / 8,
color1.green() + greenDiff * s / 8,
color1.blue() + blueDiff * s / 8 );
OImageEffect::dither( image, ditherPalette, 8 );
QPixmap p;
p.convertFromImage( image );
painter->drawPixmap( contentsRect().x(), contentsRect().y(), p );
if ( orientation() == Vertical )
{
int yPos = contentsRect().top() + painter->fontMetrics().ascent() + 2;
int xPos = contentsRect().left() + (contentsRect().width() -
painter->fontMetrics().width( text2 )) / 2;
QPen pen( color2 );
painter->setPen( pen );
painter->drawText( xPos, yPos, text2 );
yPos = contentsRect().bottom() - painter->fontMetrics().descent() - 2;
xPos = contentsRect().left() + (contentsRect().width() -
painter->fontMetrics().width( text1 )) / 2;
pen.setColor( color1 );
painter->setPen( pen );
painter->drawText( xPos, yPos, text1 );
}
else
{
int yPos = contentsRect().bottom()-painter->fontMetrics().descent()-2;
QPen pen( color2 );
painter->setPen( pen );
painter->drawText( contentsRect().left() + 2, yPos, text1 );
pen.setColor( color1 );
painter->setPen( pen );
painter->drawText( contentsRect().right() -
painter->fontMetrics().width( text2 ) - 2, yPos, text2 );
}
}
//-----------------------------------------------------------------------------
static QColor *standardPalette = 0;
#define STANDARD_PAL_SIZE 17
OColor::OColor()
: QColor()
{
r = 0; g = 0; b = 0; h = 0; s = 0; v = 0;
};
OColor::OColor( const OColor &col)
: QColor( col )
{
h = col.h; s = col.s; v = col.v;
r = col.r; g = col.g; b = col.b;
};
OColor::OColor( const QColor &col)
: QColor( col )
{
QColor::rgb(&r, &g, &b);
QColor::hsv(&h, &s, &v);
};
bool OColor::operator==(const OColor& col) const
{
return (h == col.h) && (s == col.s) && (v == col.v) &&
(r == col.r) && (g == col.g) && (b == col.b);
}
OColor& OColor::operator=(const OColor& col)
{
*(QColor *)this = col;
h = col.h; s = col.s; v = col.v;
r = col.r; g = col.g; b = col.b;
return *this;
}
void
OColor::setHsv(int _h, int _s, int _v)
{
h = _h; s = _s; v = _v;
QColor::setHsv(h, s, v);
QColor::rgb(&r, &g, &b);
};
void
OColor::setRgb(int _r, int _g, int _b)
{
r = _r; g = _g; b = _b;
QColor::setRgb(r, g, b);
QColor::hsv(&h, &s, &v);
}
void
OColor::rgb(int *_r, int *_g, int *_b) const
{
*_r = r; *_g = g; *_b = b;
}
void
OColor::hsv(int *_h, int *_s, int *_v) const
{
*_h = h; *_s = s; *_v = v;
}
static void createStandardPalette()
{
if ( standardPalette )
return;
standardPalette = new QColor[STANDARD_PAL_SIZE];
int i = 0;
standardPalette[i++] = Qt::red;
standardPalette[i++] = Qt::green;
standardPalette[i++] = Qt::blue;
standardPalette[i++] = Qt::cyan;
standardPalette[i++] = Qt::magenta;
standardPalette[i++] = Qt::yellow;
standardPalette[i++] = Qt::darkRed;
standardPalette[i++] = Qt::darkGreen;
standardPalette[i++] = Qt::darkBlue;
standardPalette[i++] = Qt::darkCyan;
standardPalette[i++] = Qt::darkMagenta;
standardPalette[i++] = Qt::darkYellow;
standardPalette[i++] = Qt::white;
standardPalette[i++] = Qt::lightGray;
standardPalette[i++] = Qt::gray;
standardPalette[i++] = Qt::darkGray;
standardPalette[i++] = Qt::black;
}
OHSSelector::OHSSelector( QWidget *parent, const char *name )
: OXYSelector( parent, name )
{
setRange( 0, 0, 359, 255 );
}
void OHSSelector::updateContents()
{
drawPalette(&pixmap);
}
void OHSSelector::resizeEvent( QResizeEvent * )
{
updateContents();
}
void OHSSelector::drawContents( QPainter *painter )
{
painter->drawPixmap( contentsRect().x(), contentsRect().y(), pixmap );
}
void OHSSelector::drawPalette( QPixmap *pixmap )
{
int xSize = contentsRect().width(), ySize = contentsRect().height();
QImage image( xSize, ySize, 32 );
QColor col;
int h, s;
uint *p;
for ( s = ySize-1; s >= 0; s-- )
{
p = (uint *) image.scanLine( ySize - s - 1 );
for( h = 0; h < xSize; h++ )
{
col.setHsv( 359*h/(xSize-1), 255*s/(ySize-1), 192 );
*p = col.rgb();
p++;
}
}
if ( QColor::numBitPlanes() <= 8 )
{
createStandardPalette();
OImageEffect::dither( image, standardPalette, STANDARD_PAL_SIZE );
}
pixmap->convertFromImage( image );
}
//-----------------------------------------------------------------------------
OValueSelector::OValueSelector( QWidget *parent, const char *name )
: OSelector( OSelector::Vertical, parent, name ), _hue(0), _sat(0)
{
setRange( 0, 255 );
pixmap.setOptimization( QPixmap::BestOptim );
}
OValueSelector::OValueSelector(Orientation o, QWidget *parent, const char *name
)
: OSelector( o, parent, name), _hue(0), _sat(0)
{
setRange( 0, 255 );
pixmap.setOptimization( QPixmap::BestOptim );
}
void OValueSelector::updateContents()
{
drawPalette(&pixmap);
}
void OValueSelector::resizeEvent( QResizeEvent * )
{
updateContents();
}
void OValueSelector::drawContents( QPainter *painter )
{
painter->drawPixmap( contentsRect().x(), contentsRect().y(), pixmap );
}
void OValueSelector::drawPalette( QPixmap *pixmap )
{
int xSize = contentsRect().width(), ySize = contentsRect().height();
QImage image( xSize, ySize, 32 );
QColor col;
uint *p;
QRgb rgb;
if ( orientation() == OSelector::Horizontal )
{
for ( int v = 0; v < ySize; v++ )
{
p = (uint *) image.scanLine( ySize - v - 1 );
for( int x = 0; x < xSize; x++ )
{
col.setHsv( _hue, _sat, 255*x/(xSize-1) );
rgb = col.rgb();
*p++ = rgb;
}
}
}
if( orientation() == OSelector::Vertical )
{
for ( int v = 0; v < ySize; v++ )
{
p = (uint *) image.scanLine( ySize - v - 1 );
col.setHsv( _hue, _sat, 255*v/(ySize-1) );
rgb = col.rgb();
for ( int i = 0; i < xSize; i++ )
*p++ = rgb;
}
}
if ( QColor::numBitPlanes() <= 8 )
{
createStandardPalette();
OImageEffect::dither( image, standardPalette, STANDARD_PAL_SIZE );
}
pixmap->convertFromImage( image );
}
diff --git a/libopie2/opieui/oselector.h b/libopie2/opieui/oselector.h
index fe75a46..3dbdb38 100644
--- a/libopie2/opieui/oselector.h
+++ b/libopie2/opieui/oselector.h
@@ -1,523 +1,523 @@
/* This file is part of the KDE libraries
Copyright (C) 1997 Martin Jones (mjones@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.
*/
//-----------------------------------------------------------------------------
// Selector widgets for KDE Color Selector, but probably useful for other
// stuff also.
#ifndef __OSELECT_H__
#define __OSELECT_H__
#include <qwidget.h>
#include <qrangecontrol.h>
#include <qpixmap.h>
namespace Opie {
namespace Ui {
/**
* OXYSelector is the base class for other widgets which
* provides the ability to choose from a two-dimensional
* range of values. The currently chosen value is indicated
* by a cross. An example is the @ref OHSSelector which
* allows to choose from a range of colors, and which is
* used in OColorDialog.
*
* A custom drawing routine for the widget surface has
* to be provided by the subclass.
*/
class OXYSelector : public QWidget
{
Q_OBJECT
public:
/**
* Constructs a two-dimensional selector widget which
* has a value range of [0..100] in both directions.
*/
OXYSelector( QWidget *parent=0, const char *name=0 );
/**
* Destructs the widget.
*/
~OXYSelector();
/**
* Sets the current values in horizontal and
* vertical direction.
*/
void setValues( int xPos, int yPos );
/**
* Sets the range of possible values.
*/
void setRange( int minX, int minY, int maxX, int maxY );
/**
* @return the current value in horizontal direction.
*/
int xValue() const { return xPos; }
/**
* @return the current value in vertical direction.
*/
int yValue() const { return yPos; }
/**
* @return the rectangle on which subclasses should draw.
*/
QRect contentsRect() const;
signals:
/**
* This signal is emitted whenever the user chooses a value,
* e.g. by clicking with the mouse on the widget.
*/
void valueChanged( int x, int y );
protected:
/**
* Override this function to draw the contents of the widget.
* The default implementation does nothing.
*
* Draw within @ref contentsRect() only.
*/
virtual void drawContents( QPainter * );
/**
* Override this function to draw the cursor which
* indicates the currently selected value pair.
*/
virtual void drawCursor( QPainter *p, int xp, int yp );
/**
* @reimplemented
*/
virtual void paintEvent( QPaintEvent *e );
/**
* @reimplemented
*/
virtual void mousePressEvent( QMouseEvent *e );
/**
* @reimplemented
*/
virtual void mouseMoveEvent( QMouseEvent *e );
/**
* @reimplemented
*/
virtual void wheelEvent( QWheelEvent * );
/**
* Converts a pixel position to its corresponding values.
*/
void valuesFromPosition( int x, int y, int& xVal, int& yVal ) const;
private:
void setPosition( int xp, int yp );
int px;
int py;
int xPos;
int yPos;
int minX;
int maxX;
int minY;
int maxY;
QPixmap store;
private:
class OXYSelectorPrivate;
OXYSelectorPrivate *d;
};
/**
* OSelector is the base class for other widgets which
* provides the ability to choose from a one-dimensional
* range of values. An example is the @ref OGradientSelector
* which allows to choose from a range of colors.
*
* A custom drawing routine for the widget surface has
* to be provided by the subclass.
*/
class OSelector : public QWidget, public QRangeControl
{
Q_OBJECT
Q_PROPERTY( int value READ value WRITE setValue )
Q_PROPERTY( int minValue READ minValue WRITE setMinValue )
Q_PROPERTY( int maxValue READ maxValue WRITE setMaxValue )
public:
/**
* Constructs a horizontal one-dimensional selection widget.
*/
OSelector( QWidget *parent=0, const char *name=0 );
/**
* Constructs a one-dimensional selection widget with
* a given orientation.
*/
OSelector( Orientation o, QWidget *parent = 0L, const char *name = 0L );
/*
* Destructs the widget.
*/
~OSelector();
/**
* @return the orientation of the widget.
*/
Orientation orientation() const
{ return _orientation; }
/**
* @return the rectangle on which subclasses should draw.
*/
QRect contentsRect() const;
/**
* Sets the indent option of the widget to i.
* This determines whether a shaded frame is drawn.
*/
void setIndent( bool i )
{ _indent = i; }
/**
* @return whether the indent option is set.
*/
bool indent() const
{ return _indent; }
/**
* Sets the value.
*/
void setValue(int value)
{ QRangeControl::setValue(value); }
/**
* @returns the value.
*/
int value() const
{ return QRangeControl::value(); }
/**
* Sets the min value.
*/
- #if ( QT_VERSION > 290 )
+ #if ( QT_VERSION >= 0x030000 )
void setMinValue(int value) { QRangeControl::setMinValue(value); }
#else
void setMinValue(int value) { QRangeControl::setRange(value,QRangeControl::maxValue()); }
#endif
/**
* @return the min value.
*/
int minValue() const
{ return QRangeControl::minValue(); }
/**
* Sets the max value.
*/
- #if ( QT_VERSION > 290 )
+ #if ( QT_VERSION >= 0x030000 )
void setMaxValue(int value) { QRangeControl::setMaxValue(value); }
#else
void setMaxValue(int value) { QRangeControl::setRange(QRangeControl::minValue(),value); }
#endif
/**
* @return the max value.
*/
int maxValue() const
{ return QRangeControl::maxValue(); }
signals:
/**
* This signal is emitted whenever the user chooses a value,
* e.g. by clicking with the mouse on the widget.
*/
void valueChanged( int value );
protected:
/**
* Override this function to draw the contents of the control.
* The default implementation does nothing.
*
* Draw only within contentsRect().
*/
virtual void drawContents( QPainter * );
/**
* Override this function to draw the cursor which
* indicates the current value. This function is
* always called twice, once with argument show=false
* to clear the old cursor, once with argument show=true
* to draw the new one.
*/
virtual void drawArrow( QPainter *painter, bool show, const QPoint &pos );
/**
* @reimplemented
*/
virtual void valueChange();
/**
* @reimplemented
*/
virtual void paintEvent( QPaintEvent * );
/**
* @reimplemented
*/
virtual void mousePressEvent( QMouseEvent *e );
/**
* @reimplemented
*/
virtual void mouseMoveEvent( QMouseEvent *e );
/**
* @reimplemented
*/
virtual void wheelEvent( QWheelEvent * );
private:
QPoint calcArrowPos( int val );
void moveArrow( const QPoint &pos );
Orientation _orientation;
bool _indent;
private:
class OSelectorPrivate;
OSelectorPrivate *d;
};
/**
* The OGradientSelector widget allows the user to choose
* from a one-dimensional range of colors which is given as a
* gradient between two colors provided by the programmer.
*/
class OGradientSelector : public OSelector
{
Q_OBJECT
Q_PROPERTY( QColor firstColor READ firstColor WRITE setFirstColor )
Q_PROPERTY( QColor secondColor READ secondColor WRITE setSecondColor )
Q_PROPERTY( QString firstText READ firstText WRITE setFirstText )
Q_PROPERTY( QString secondText READ secondText WRITE setSecondText )
public:
/**
* Constructs a horizontal color selector which
* contains a gradient between white and black.
*/
OGradientSelector( QWidget *parent=0, const char *name=0 );
/**
* Constructs a colors selector with orientation o which
* contains a gradient between white and black.
*/
OGradientSelector( Orientation o, QWidget *parent=0, const char *name=0 );
/**
* Destructs the widget.
*/
~OGradientSelector();
/**
* Sets the two colors which span the gradient.
*/
void setColors( const QColor &col1, const QColor &col2 )
{ color1 = col1; color2 = col2; update();}
void setText( const QString &t1, const QString &t2 )
{ text1 = t1; text2 = t2; update(); }
/**
* Set each color on its own.
*/
void setFirstColor( const QColor &col )
{ color1 = col; update(); }
void setSecondColor( const QColor &col )
{ color2 = col; update(); }
/**
* Set each description on its own
*/
void setFirstText( const QString &t )
{ text1 = t; update(); }
void setSecondText( const QString &t )
{ text2 = t; update(); }
const QColor firstColor() const
{ return color1; }
const QColor secondColor() const
{ return color2; }
const QString firstText() const
{ return text1; }
const QString secondText() const
{ return text2; }
protected:
/**
* @reimplemented
*/
virtual void drawContents( QPainter * );
/**
* @reimplemented
*/
virtual QSize minimumSize() const
{ return sizeHint(); }
private:
void init();
QColor color1;
QColor color2;
QString text1;
QString text2;
private:
class OGradientSelectorPrivate;
OGradientSelectorPrivate *d;
};
/**
* Widget for Hue/Saturation selection.
* The actual values can be fetched using the inherited xValue and yValue
* methods.
*
* @see OXYSelector, OValueSelector, OColorDialog
* @author Martin Jones (mjones@kde.org)
* @version $Id$
*/
class OHSSelector : public OXYSelector
{
Q_OBJECT
public:
/**
* Constructs a hue/saturation selection widget.
*/
OHSSelector( QWidget *parent=0, const char *name=0 );
protected:
/**
* Draws the contents of the widget on a pixmap,
* which is used for buffering.
*/
virtual void drawPalette( QPixmap *pixmap );
/**
* @reimplemented
*/
virtual void resizeEvent( QResizeEvent * );
/**
* Reimplemented from OXYSelector. This drawing is
* buffered in a pixmap here. As real drawing
* routine, drawPalette() is used.
*/
virtual void drawContents( QPainter *painter );
private:
void updateContents();
QPixmap pixmap;
private:
class OHSSelectorPrivate;
OHSSelectorPrivate *d;
};
class OValueSelectorPrivate;
/**
* Widget for color value selection.
*
* @see OHSSelector, OColorDialog
* @author Martin Jones (mjones@kde.org)
* @version $Id$
*/
class OValueSelector : public OSelector
{
Q_OBJECT
public:
/**
* Constructs a widget for color selection.
*/
OValueSelector( QWidget *parent=0, const char *name=0 );
/**
* Constructs a widget for color selection with a given orientation
*/
OValueSelector( Orientation o, QWidget *parent = 0, const char *name = 0 );
int hue() const
{ return _hue; }
void setHue( int h )
{ _hue = h; }
int saturation() const
{ return _sat; }
void setSaturation( int s )
{ _sat = s; }
void updateContents();
protected:
/**
* Draws the contents of the widget on a pixmap,
* which is used for buffering.
*/
virtual void drawPalette( QPixmap *pixmap );
/**
* @reimplemented
*/
virtual void resizeEvent( QResizeEvent * );
/**
* Reimplemented from OSelector. The drawing is
* buffered in a pixmap here. As real drawing
* routine, drawPalette() is used.
*/
virtual void drawContents( QPainter *painter );
private:
int _hue;
int _sat;
QPixmap pixmap;
private:
class OValueSelectorPrivate;
OValueSelectorPrivate *d;
};
class OColor : public QColor
{
public:
OColor();
OColor( const OColor &col);
OColor( const QColor &col);
OColor& operator=( const OColor& col);
bool operator==( const OColor& col) const;
void setHsv(int _h, int _s, int _v);
void setRgb(int _r, int _g, int _b);
void rgb(int *_r, int *_g, int *_b) const;
void hsv(int *_h, int *_s, int *_v) const;
protected:
int h;
int s;
int v;
int r;
int g;
int b;
private:
class OColorPrivate;
OColorPrivate *d;
};
}
}
#endif // __OSELECT_H__
diff --git a/libopie2/qt3/opiecore/osortablevaluelist.h b/libopie2/qt3/opiecore/osortablevaluelist.h
index f66cf25..a3f75b4 100644
--- a/libopie2/qt3/opiecore/osortablevaluelist.h
+++ b/libopie2/qt3/opiecore/osortablevaluelist.h
@@ -1,117 +1,117 @@
/*
                This file is part of the Opie Project
Originally a part of the KDE Project
(C) 2001 Carsten Pfeiffer <pfeiffer@kde.org>
=.
.=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.
*/
#ifndef OSORTABLEVALUELIST_H
#define OSORTABLEVALUELIST_H
-#if QT_VERSION > 290
+#if QT_VERSION >= 0x030000
#include <qtl.h>
#include <qpair.h>
#else
#include <opie2/otl.h>
#include <opie2/opair.h>
#endif
#include <qvaluelist.h>
template<class T, class Key = int> class OSortableItem : public QPair<Key,T>
{
public:
OSortableItem( Key i, const T& t ) : QPair<Key, T>( i, t ) {}
OSortableItem( const OSortableItem<T, Key> &rhs )
: QPair<Key,T>( rhs.first, rhs.second ) {}
OSortableItem() {}
OSortableItem<T, Key> &operator=( const OSortableItem<T, Key>& i ) {
first = i.first;
second = i.second;
return *this;
}
// operators for sorting
bool operator> ( const OSortableItem<T, Key>& i2 ) const {
return (i2.first < first);
}
bool operator< ( const OSortableItem<T, Key>& i2 ) const {
return (first < i2.first);
}
bool operator>= ( const OSortableItem<T, Key>& i2 ) const {
return (first >= i2.first);
}
bool operator<= ( const OSortableItem<T, Key>& i2 ) const {
return !(i2.first < first);
}
bool operator== ( const OSortableItem<T, Key>& i2 ) const {
return (first == i2.first);
}
bool operator!= ( const OSortableItem<T, Key>& i2 ) const {
return (first != i2.first);
}
T& value() {
return second;
}
const T& value() const {
return second;
}
Key index() const {
return first;
}
};
// convenience
template <class T, class Key = int>
class OSortableValueList : public QValueList<OSortableItem<T, Key> >
{
public:
void insert( Key i, const T& t ) {
QValueList<OSortableItem<T, Key> >::append( OSortableItem<T, Key>( i, t ) );
}
// add more as you please...
T& operator[]( Key i ) {
return QValueList<OSortableItem<T, Key> >::operator[]( i ).value();
}
const T& operator[]( Key i ) const {
return QValueList<OSortableItem<T, Key> >::operator[]( i ).value();
}
void sort() {
qHeapSort( *this );
}
};
// template <class T> class OSortableValueListIterator : public QValueListIterator<OSortableItem<T> >
// {
// };
#endif // OSORTABLEVALUELIST_H
diff --git a/libopie2/qt3/opieui/ocombobox.cpp b/libopie2/qt3/opieui/ocombobox.cpp
index bd330e0..130112c 100644
--- a/libopie2/qt3/opieui/ocombobox.cpp
+++ b/libopie2/qt3/opieui/ocombobox.cpp
@@ -1,669 +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
+ #if QT_VERSION >= 0x030000
QComboBox::setLineEdit( 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 QT_VERSION >= 0x030000
if ( lineEdit()->hasSelectedText() )
#else
if ( lineEdit()->hasMarkedText() )
#endif
{
lineEdit()->del();
}
}
void OComboBox::deleteWordBack()
{
lineEdit()->cursorWordBackward(TRUE);
- #if QT_VERSION > 290
+ #if QT_VERSION >= 0x030000
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 0e95274..dcc697d 100644
--- a/libopie2/qt3/opieui/oeditlistbox.cpp
+++ b/libopie2/qt3/opieui/oeditlistbox.cpp
@@ -1,417 +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
+ #if QT_VERSION >= 0x030000
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
+ #if QT_VERSION >= 0x030000
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 QT_VERSION >= 0x030000
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;
assert( combo->lineEdit()->inherits( "OLineEdit" ) );
m_lineEdit = static_cast<OLineEdit*>( combo->lineEdit() );
}
diff --git a/libopie2/qt3/opieui/olineedit.cpp b/libopie2/qt3/opieui/olineedit.cpp
index 6f66fc7..b150987 100644
--- a/libopie2/qt3/opieui/olineedit.cpp
+++ b/libopie2/qt3/opieui/olineedit.cpp
@@ -1,729 +1,729 @@
/*
This file Copyright (C) 2003 Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de>
is part of the Copyright (C) 2001 Carsten Pfeiffer <pfeiffer@kde.org>, Dawit Alemayehu <adawit@kde.org>
Opie Project Copyright (C) 1999 Preston Brown <pbrown@kde.org>, Patrick Ward <PAT_WARD@HP-USA-om5.om.hp.com>
Copyright (C) 1997 Sven Radej (sven.radej@iname.com)
=.
.=l. Originally part of the KDE Project
           .>+-=
 _;:,     .>    :=|. 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 <qapplication.h>
#include <qclipboard.h>
#include <qtimer.h>
#include <qpopupmenu.h>
/* OPIE */
#include <opie2/ocompletionbox.h>
#include <opie2/olineedit.h>
#include <opie2/oglobalsettings.h>
typedef QString KURL; //FIXME: Revise for Opie
/*======================================================================================
* OLineEditPrivate
*======================================================================================*/
class OLineEdit::OLineEditPrivate
{
public:
OLineEditPrivate()
{
grabReturnKeyEvents = false;
handleURLDrops = true;
completionBox = 0L;
}
~OLineEditPrivate()
{
delete completionBox;
}
bool grabReturnKeyEvents;
bool handleURLDrops;
OCompletionBox *completionBox;
};
/*======================================================================================
* OLineEdit
*======================================================================================*/
OLineEdit::OLineEdit( const QString &string, QWidget *parent, const char *name )
: QLineEdit( string, parent, name )
{
init();
}
OLineEdit::OLineEdit( QWidget *parent, const char *name )
: QLineEdit( parent, name )
{
init();
}
OLineEdit::~OLineEdit ()
{
delete d;
}
void OLineEdit::init()
{
d = new OLineEditPrivate;
possibleTripleClick = false;
// Enable the context menu by default.
setContextMenuEnabled( true );
//OCursor::setAutoHideCursor( this, true, true );
installEventFilter( this );
}
void OLineEdit::setCompletionMode( OGlobalSettings::Completion mode )
{
OGlobalSettings::Completion oldMode = completionMode();
if ( oldMode != mode && oldMode == OGlobalSettings::CompletionPopup &&
d->completionBox && d->completionBox->isVisible() )
d->completionBox->hide();
// If the widgets echo mode is not Normal, no completion
// feature will be enabled even if one is requested.
if ( echoMode() != QLineEdit::Normal )
mode = OGlobalSettings::CompletionNone; // Override the request.
OCompletionBase::setCompletionMode( mode );
}
void OLineEdit::setCompletedText( const QString& t, bool marked )
{
QString txt = text();
if ( t != txt )
{
int curpos = marked ? txt.length() : t.length();
validateAndSet( t, curpos, curpos, t.length() );
}
}
void OLineEdit::setCompletedText( const QString& text )
{
OGlobalSettings::Completion mode = completionMode();
bool marked = ( mode == OGlobalSettings::CompletionAuto ||
mode == OGlobalSettings::CompletionMan ||
mode == OGlobalSettings::CompletionPopup );
setCompletedText( text, marked );
}
void OLineEdit::rotateText( OCompletionBase::KeyBindingType type )
{
OCompletion* comp = compObj();
if ( comp &&
(type == OCompletionBase::PrevCompletionMatch ||
type == OCompletionBase::NextCompletionMatch ) )
{
QString input = (type == OCompletionBase::PrevCompletionMatch) ? comp->previousMatch() : comp->nextMatch();
// Skip rotation if previous/next match is null or the same text
if ( input.isNull() || input == displayText() )
return;
- #if QT_VERSION > 290
+ #if QT_VERSION >= 0x030000
setCompletedText( input, hasSelectedText() );
#else
setCompletedText( input, hasMarkedText() );
#endif
}
}
void OLineEdit::makeCompletion( const QString& text )
{
OCompletion *comp = compObj();
if ( !comp )
return; // No completion object...
QString match = comp->makeCompletion( text );
OGlobalSettings::Completion mode = completionMode();
if ( mode == OGlobalSettings::CompletionPopup )
{
if ( match.isNull() )
{
if ( d->completionBox ) {
d->completionBox->hide();
d->completionBox->clear();
}
}
else
setCompletedItems( comp->allMatches() );
}
else
{
// all other completion modes
// If no match or the same match, simply return without completing.
if ( match.isNull() || match == text )
return;
setCompletedText( match );
}
}
void OLineEdit::setReadOnly(bool readOnly)
{
QPalette p = palette();
if (readOnly)
{
QColor color = p.color(QPalette::Disabled, QColorGroup::Background);
p.setColor(QColorGroup::Base, color);
p.setColor(QColorGroup::Background, color);
}
else
{
QColor color = p.color(QPalette::Normal, QColorGroup::Base);
p.setColor(QColorGroup::Base, color);
p.setColor(QColorGroup::Background, color);
}
setPalette(p);
QLineEdit::setReadOnly (readOnly);
}
void OLineEdit::keyPressEvent( QKeyEvent *e )
{
qDebug( "OLineEdit::keyPressEvent()" );
/*
KKey key( e );
if ( KStdAccel::copy().contains( key ) ) {
copy();
return;
}
else if ( KStdAccel::paste().contains( key ) ) {
paste();
return;
}
else if ( KStdAccel::cut().contains( key ) ) {
cut();
return;
}
else if ( KStdAccel::undo().contains( key ) ) {
undo();
return;
}
else if ( KStdAccel::redo().contains( key ) ) {
redo();
return;
}
else if ( KStdAccel::deleteWordBack().contains( key ) )
{
cursorWordBackward(TRUE);
if ( hasSelectedText() )
del();
e->accept();
return;
}
else if ( KStdAccel::deleteWordForward().contains( key ) )
{
// Workaround for QT bug where
cursorWordForward(TRUE);
if ( hasSelectedText() )
del();
e->accept();
return;
}
*/
// Filter key-events if EchoMode is normal &
// completion mode is not set to CompletionNone
if ( echoMode() == QLineEdit::Normal &&
completionMode() != OGlobalSettings::CompletionNone )
{
KeyBindingMap keys = getKeyBindings();
OGlobalSettings::Completion mode = completionMode();
bool noModifier = (e->state() == NoButton || e->state()== ShiftButton);
if ( (mode == OGlobalSettings::CompletionAuto ||
mode == OGlobalSettings::CompletionMan) && noModifier )
{
QString keycode = e->text();
if ( !keycode.isNull() && keycode.unicode()->isPrint() )
{
QLineEdit::keyPressEvent ( e );
QString txt = text();
int len = txt.length();
- #if QT_VERSION > 290
+ #if QT_VERSION >= 0x030000
if ( !hasSelectedText() && len && cursorPosition() == len )
#else
if ( !hasMarkedText() && len && cursorPosition() == len )
#endif
{
if ( emitSignals() )
emit completion( txt );
if ( handleSignals() )
makeCompletion( txt );
e->accept();
}
return;
}
}
else if ( mode == OGlobalSettings::CompletionPopup && noModifier )
{
qDebug( "OLineEdit::keyPressEvent() - global settings = CompletionPopup & noModifier" );
QString old_txt = text();
QLineEdit::keyPressEvent ( e );
QString txt = text();
int len = txt.length();
QString keycode = e->text();
if ( txt != old_txt && len && cursorPosition() == len &&
( (!keycode.isNull() && keycode.unicode()->isPrint()) ||
e->key() == Key_Backspace ) )
{
if ( emitSignals() )
emit completion( txt ); // emit when requested...
if ( handleSignals() )
makeCompletion( txt ); // handle when requested...
e->accept();
}
else if (!len && d->completionBox && d->completionBox->isVisible())
d->completionBox->hide();
return;
}
/*else if ( mode == OGlobalSettings::CompletionShell )
{
// Handles completion.
KShortcut cut;
if ( keys[TextCompletion].isNull() )
cut = KStdAccel::shortcut(KStdAccel::TextCompletion);
else
cut = keys[TextCompletion];
if ( cut.contains( key ) )
{
// Emit completion if the completion mode is CompletionShell
// and the cursor is at the end of the string.
QString txt = text();
int len = txt.length();
if ( cursorPosition() == len && len != 0 )
{
if ( emitSignals() )
emit completion( txt );
if ( handleSignals() )
makeCompletion( txt );
return;
}
}
else if ( d->completionBox )
d->completionBox->hide();
}
// handle rotation
if ( mode != OGlobalSettings::CompletionNone )
{
// Handles previous match
KShortcut cut;
if ( keys[PrevCompletionMatch].isNull() )
cut = KStdAccel::shortcut(KStdAccel::PrevCompletion);
else
cut = keys[PrevCompletionMatch];
if ( cut.contains( key ) )
{
if ( emitSignals() )
emit textRotation( OCompletionBase::PrevCompletionMatch );
if ( handleSignals() )
rotateText( OCompletionBase::PrevCompletionMatch );
return;
}
// Handles next match
if ( keys[NextCompletionMatch].isNull() )
cut = KStdAccel::key(KStdAccel::NextCompletion);
else
cut = keys[NextCompletionMatch];
if ( cut.contains( key ) )
{
if ( emitSignals() )
emit textRotation( OCompletionBase::NextCompletionMatch );
if ( handleSignals() )
rotateText( OCompletionBase::NextCompletionMatch );
return;
}
}
// substring completion
if ( compObj() )
{
KShortcut cut;
if ( keys[SubstringCompletion].isNull() )
cut = KStdAccel::shortcut(KStdAccel::SubstringCompletion);
else
cut = keys[SubstringCompletion];
if ( cut.contains( key ) )
{
if ( emitSignals() )
emit substringCompletion( text() );
if ( handleSignals() )
{
setCompletedItems( compObj()->substringCompletion(text()));
e->accept();
}
return;
}
} */
}
// Let QLineEdit handle any other keys events.
QLineEdit::keyPressEvent ( e );
}
void OLineEdit::mouseDoubleClickEvent( QMouseEvent* e )
{
if ( e->button() == Qt::LeftButton )
{
possibleTripleClick=true;
QTimer::singleShot( QApplication::doubleClickInterval(),this,
SLOT(tripleClickTimeout()) );
}
QLineEdit::mouseDoubleClickEvent( e );
}
void OLineEdit::mousePressEvent( QMouseEvent* e )
{
if ( possibleTripleClick && e->button() == Qt::LeftButton )
{
selectAll();
return;
}
QLineEdit::mousePressEvent( e );
}
void OLineEdit::tripleClickTimeout()
{
possibleTripleClick=false;
}
QPopupMenu *OLineEdit::createPopupMenu()
{
// Return if popup menu is not enabled !!
if ( !m_bEnableMenu )
return 0;
- #if QT_VERSION > 290
+ #if QT_VERSION >= 0x030000
QPopupMenu *popup = QLineEdit::createPopupMenu();
#else
QPopupMenu *popup = new QPopupMenu();
#warning OLineEdit is not fully functional on Qt2
#endif
// completion object is present.
if ( compObj() )
{
QPopupMenu *subMenu = new QPopupMenu( popup );
connect( subMenu, SIGNAL( activated(int) ),
this, SLOT( completionMenuActivated(int) ) );
popup->insertSeparator();
//popup->insertItem( SmallIconSet("completion"), i18n("Text Completion"),
// subMenu );
popup->insertItem( tr("Text Completion"), subMenu );
subMenu->insertItem( tr("None"), NoCompletion );
subMenu->insertItem( tr("Manual"), ShellCompletion );
subMenu->insertItem( tr("Automatic"), AutoCompletion );
subMenu->insertItem( tr("Dropdown List"), PopupCompletion );
subMenu->insertItem( tr("Short Automatic"), SemiAutoCompletion );
//subMenu->setAccel( KStdAccel::completion(), ShellCompletion );
subMenu->setAccel( Key_Tab, ShellCompletion );
OGlobalSettings::Completion mode = completionMode();
subMenu->setItemChecked( NoCompletion,
mode == OGlobalSettings::CompletionNone );
subMenu->setItemChecked( ShellCompletion,
mode == OGlobalSettings::CompletionShell );
subMenu->setItemChecked( PopupCompletion,
mode == OGlobalSettings::CompletionPopup );
subMenu->setItemChecked( AutoCompletion,
mode == OGlobalSettings::CompletionAuto );
subMenu->setItemChecked( SemiAutoCompletion,
mode == OGlobalSettings::CompletionMan );
if ( mode != OGlobalSettings::completionMode() )
{
subMenu->insertSeparator();
subMenu->insertItem( tr("Default"), Default );
}
}
// ### do we really need this? Yes, Please do not remove! This
// allows applications to extend the popup menu without having to
// inherit from this class! (DA)
emit aboutToShowContextMenu( popup );
return popup;
}
void OLineEdit::completionMenuActivated( int id )
{
OGlobalSettings::Completion oldMode = completionMode();
switch ( id )
{
case Default:
setCompletionMode( OGlobalSettings::completionMode() ); break;
case NoCompletion:
setCompletionMode( OGlobalSettings::CompletionNone ); break;
case AutoCompletion:
setCompletionMode( OGlobalSettings::CompletionAuto ); break;
case SemiAutoCompletion:
setCompletionMode( OGlobalSettings::CompletionMan ); break;
case ShellCompletion:
setCompletionMode( OGlobalSettings::CompletionShell ); break;
case PopupCompletion:
setCompletionMode( OGlobalSettings::CompletionPopup ); break;
default: return;
}
if ( oldMode != completionMode() )
{
if ( oldMode == OGlobalSettings::CompletionPopup &&
d->completionBox && d->completionBox->isVisible() )
d->completionBox->hide();
emit completionModeChanged( completionMode() );
}
}
/*void OLineEdit::dropEvent(QDropEvent *e)
{
KURL::List urlList;
if( d->handleURLDrops && KURLDrag::decode( e, urlList ) )
{
QString dropText = text();
KURL::List::ConstIterator it;
for( it = urlList.begin() ; it != urlList.end() ; ++it )
{
if(!dropText.isEmpty())
dropText+=' ';
dropText += (*it).prettyURL();
}
validateAndSet( dropText, dropText.length(), 0, 0);
e->accept();
}
else
QLineEdit::dropEvent(e);
}*/
bool OLineEdit::eventFilter( QObject* o, QEvent* ev )
{
if( o == this )
{
//OCursor::autoHideEventFilter( this, ev );
if ( ev->type() == QEvent::AccelOverride )
{
QKeyEvent *e = static_cast<QKeyEvent *>( ev );
// if (overrideAccel (e))
// {
// e->accept();
// return true;
// }
}
else if( ev->type() == QEvent::KeyPress )
{
QKeyEvent *e = static_cast<QKeyEvent *>( ev );
if( e->key() == Qt::Key_Return || e->key() == Qt::Key_Enter )
{
bool trap = d->completionBox && d->completionBox->isVisible();
// Qt will emit returnPressed() itself if we return false
if ( d->grabReturnKeyEvents || trap )
emit QLineEdit::returnPressed();
emit returnPressed( displayText() );
if ( trap )
d->completionBox->hide();
// Eat the event if the user asked for it, or if a completionbox was visible
return d->grabReturnKeyEvents || trap;
}
}
}
return QLineEdit::eventFilter( o, ev );
}
void OLineEdit::setURLDropsEnabled(bool enable)
{
d->handleURLDrops=enable;
}
bool OLineEdit::isURLDropsEnabled() const
{
return d->handleURLDrops;
}
void OLineEdit::setTrapReturnKey( bool grab )
{
d->grabReturnKeyEvents = grab;
}
bool OLineEdit::trapReturnKey() const
{
return d->grabReturnKeyEvents;
}
/*void OLineEdit::setURL( const KURL& url )
{
QLineEdit::setText( url.prettyURL() );
}*/
void OLineEdit::makeCompletionBox()
{
if ( d->completionBox )
return;
d->completionBox = new OCompletionBox( this, "completion box" );
if ( handleSignals() )
{
connect( d->completionBox, SIGNAL(highlighted(const QString&)),
SLOT(setText(const QString&)) );
connect( d->completionBox, SIGNAL(userCancelled(const QString&)),
SLOT(setText(const QString&)) );
// Nice lil' hacklet ;) KComboBox doesn't know when the completionbox
// is created (childEvent() is even more hacky, IMHO), so we simply
// forward the completionbox' activated signal from here.
if ( parentWidget() && parentWidget()->inherits("KComboBox") )
connect( d->completionBox, SIGNAL( activated(const QString&)),
parentWidget(), SIGNAL( activated(const QString&)));
}
}
/*bool OLineEdit::overrideAccel (const QKeyEvent* e)
{
KShortcut scKey;
KKey key( e );
KeyBindingMap keys = getKeyBindings();
if (keys[TextCompletion].isNull())
scKey = KStdAccel::shortcut(KStdAccel::TextCompletion);
else
scKey = keys[TextCompletion];
if (scKey.contains( key ))
return true;
if (keys[NextCompletionMatch].isNull())
scKey = KStdAccel::shortcut(KStdAccel::NextCompletion);
else
scKey = keys[NextCompletionMatch];
if (scKey.contains( key ))
return true;
if (keys[PrevCompletionMatch].isNull())
scKey = KStdAccel::shortcut(KStdAccel::PrevCompletion);
else
scKey = keys[PrevCompletionMatch];
if (scKey.contains( key ))
return true;
if (KStdAccel::deleteWordBack().contains( key ))
return true;
if (KStdAccel::deleteWordForward().contains( key ))
return true;
if (d->completionBox && d->completionBox->isVisible ())
if (e->key () == Key_Backtab)
return true;
return false;
}*/
void OLineEdit::setCompletedItems( const QStringList& items )
{
QString txt = text();
if ( !items.isEmpty() &&
!(items.count() == 1 && txt == items.first()) )
{
if ( !d->completionBox )
makeCompletionBox();
if ( !txt.isEmpty() )
d->completionBox->setCancelledText( txt );
d->completionBox->setItems( items );
d->completionBox->popup();
}
else
{
if ( d->completionBox && d->completionBox->isVisible() )
d->completionBox->hide();
}
}
OCompletionBox * OLineEdit::completionBox( bool create )
{
if ( create )
makeCompletionBox();
return d->completionBox;
}
void OLineEdit::setCompletionObject( OCompletion* comp, bool hsig )
{
OCompletion *oldComp = compObj();
if ( oldComp && handleSignals() )
disconnect( oldComp, SIGNAL( matches(const QStringList&)),
this, SLOT( setCompletedItems(const QStringList&)));
if ( comp && hsig )
connect( comp, SIGNAL( matches(const QStringList&)),
this, SLOT( setCompletedItems(const QStringList&)));
OCompletionBase::setCompletionObject( comp, hsig );
}
// QWidget::create() turns off mouse-Tracking which would break auto-hiding
void OLineEdit::create( WId id, bool initializeWindow, bool destroyOldWindow )
{
QLineEdit::create( id, initializeWindow, destroyOldWindow );
//OCursor::setAutoHideCursor( this, true, true );
}
void OLineEdit::clear()
{
setText( QString::null );
}