summaryrefslogtreecommitdiffabout
path: root/microkde
Side-by-side diff
Diffstat (limited to 'microkde') (more/less context) (show whitespace changes)
-rw-r--r--microkde/kapplication.cpp1
-rw-r--r--microkde/kdecore/klibloader.cpp10
-rw-r--r--microkde/kdeui/ktoolbar.cpp2
-rw-r--r--microkde/kdeui/ktoolbar.h2
4 files changed, 4 insertions, 11 deletions
diff --git a/microkde/kapplication.cpp b/microkde/kapplication.cpp
index 21aa0a4..f05b91b 100644
--- a/microkde/kapplication.cpp
+++ b/microkde/kapplication.cpp
@@ -1,110 +1,111 @@
#include <stdlib.h>
#include <stdio.h>
#include "kapplication.h"
#include "ktextedit.h"
#include <qapplication.h>
#include <qstring.h>
#include <qfile.h>
#include <qtextstream.h>
#include <qdialog.h>
#include <qlayout.h>
#include <qtextbrowser.h>
int KApplication::random()
{
return rand();
}
//US
QString KApplication::randomString(int length)
{
if (length <=0 ) return QString::null;
QString str;
while (length--)
{
int r=random() % 62;
r+=48;
if (r>57) r+=7;
if (r>90) r+=6;
str += char(r);
// so what if I work backwards?
}
return str;
}
int KApplication::execDialog( QDialog* d )
{
if (QApplication::desktop()->width() <= 640 )
d->showMaximized();
else
;//d->resize( 800, 600 );
return d->exec();
}
void KApplication::showLicence()
{
KApplication::showFile( "KDE-Pim/Pi licence", "kdepim/licence.txt" );
}
void KApplication::showFile(QString caption, QString fn)
{
QString text;
QString fileName;
#ifndef DESKTOP_VERSION
fileName = getenv("QPEDIR");
fileName += "/pics/" + fn ;
#else
fileName = qApp->applicationDirPath () + "/" + fn;
#endif
QFile file( fileName );
if (!file.open( IO_ReadOnly ) ) {
return ;
}
QTextStream ts( &file );
text = ts.read();
file.close();
KApplication::showText( caption, text );
}
bool KApplication::convert2latin1(QString fileName)
{
QString text;
QFile file( fileName );
if (!file.open( IO_ReadOnly ) ) {
return false;
}
QTextStream ts( &file );
ts.setEncoding( QTextStream::UnicodeUTF8 );
text = ts.read();
file.close();
if (!file.open( IO_WriteOnly ) ) {
return false;
}
QTextStream tsIn( &file );
tsIn.setEncoding( QTextStream::Latin1 );
tsIn << text.latin1();
file.close();
+ return true;
}
void KApplication::showText(QString caption, QString text)
{
QDialog dia( 0, "name", true ); ;
dia.setCaption( caption );
QVBoxLayout* lay = new QVBoxLayout( &dia );
lay->setSpacing( 3 );
lay->setMargin( 3 );
KTextEdit tb ( &dia );
tb.setWordWrap( QMultiLineEdit::WidgetWidth );
lay->addWidget( &tb );
tb.setText( text );
#ifdef DESKTOP_VERSION
dia.resize( 640, 480);
#else
dia.showMaximized();
#endif
dia.exec();
}
diff --git a/microkde/kdecore/klibloader.cpp b/microkde/kdecore/klibloader.cpp
index 1394154..6d0475a 100644
--- a/microkde/kdecore/klibloader.cpp
+++ b/microkde/kdecore/klibloader.cpp
@@ -1,661 +1,653 @@
/* This file is part of the KDE libraries
Copyright (C) 1999 Torben Weis <weis@kde.org>
Copyright (C) 2000 Michael Matz <matz@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 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.
*/
//US #include <config.h>
#include <qclipboard.h>
#include <qfile.h>
#include <qtimer.h>
#include <qobjectdict.h>
#include <qwidgetlist.h>
#include <qwidget.h>
#include "kapplication.h"
#include "klibloader.h"
#include "kstandarddirs.h"
#include "kdebug.h"
#include "klocale.h"
/*US
#ifndef NDEBUG
#include "ltdl.h"
#endif
*/
//US do everything through qlibrary
#ifndef DESKTOP_VERSION
#include <qpe/qpeapplication.h>
#include <qtopia/qlibrary.h>
#else
#include <qlibrary.h>
#endif
template class QAsciiDict<KLibrary>;
#include <stdlib.h> //getenv
/*US
#if HAVE_DLFCN_H
# include <dlfcn.h>
#endif
#ifdef RTLD_GLOBAL
# define LT_GLOBAL RTLD_GLOBAL
#else
# ifdef DL_GLOBAL
# define LT_GLOBAL DL_GLOBAL
# endif
#endif
#ifndef LT_GLOBAL
# define LT_GLOBAL 0
#endif
*/
/*US
extern "C" {
extern int lt_dlopen_flag;
}
*/
KLibFactory::KLibFactory( QObject* parent, const char* name )
: QObject( parent, name )
{
}
KLibFactory::~KLibFactory()
{
// kdDebug(150) << "Deleting KLibFactory " << this << endl;
}
QObject* KLibFactory::create( QObject* parent, const char* name, const char* classname, const QStringList &args )
{
QObject* obj = createObject( parent, name, classname, args );
if ( obj )
emit objectCreated( obj );
return obj;
}
QObject* KLibFactory::createObject( QObject*, const char*, const char*, const QStringList &)
{
return 0;
}
// -----------------------------------------------
//US KLibrary::KLibrary( const QString& libname, const QString& filename, void * handle )
KLibrary::KLibrary( const QString& libname, const QString& filename, QLibrary* handle )
{
/* Make sure, we have a KLibLoader */
(void) KLibLoader::self();
m_libname = libname;
m_filename = filename;
m_handle = handle;
m_factory = 0;
m_timer = 0;
}
KLibrary::~KLibrary()
{
// kdDebug(150) << "Deleting KLibrary " << this << " " << m_libname << endl;
if ( m_timer && m_timer->isActive() )
m_timer->stop();
// If any object is remaining, delete
if ( m_objs.count() > 0 )
{
QPtrListIterator<QObject> it( m_objs );
for ( ; it.current() ; ++it )
{
kdDebug(150) << "Factory still has object " << it.current() << " " << it.current()->name () << " Library = " << m_libname << endl;
disconnect( it.current(), SIGNAL( destroyed() ),
this, SLOT( slotObjectDestroyed() ) );
}
m_objs.setAutoDelete(true);
m_objs.clear();
}
if ( m_factory ) {
// kdDebug(150) << " ... deleting the factory " << m_factory << endl;
delete m_factory;
}
}
QString KLibrary::name() const
{
return m_libname;
}
QString KLibrary::fileName() const
{
return m_filename;
}
KLibFactory* KLibrary::factory()
{
if ( m_factory )
return m_factory;
QCString symname;
symname.sprintf("init_%s", name().latin1() );
void* sym = symbol( symname );
if ( !sym )
{
qDebug("KLibrary: The library %s does not offer an %s function", name().latin1(), symname.data());
#ifndef NDEBUG
//US qDebug("KLibrary: errorcode: %s", lt_dlerror());
#endif
kdWarning(150) << "KLibrary: The library " << name().latin1() << " does not offer an init_" << name().latin1() << " function" << endl;
return 0;
}
typedef KLibFactory* (*t_func)();
t_func func = (t_func)sym;
m_factory = func();
if( !m_factory )
{
kdWarning(150) << "KLibrary: The library " << name() << " does not offer a KDE compatible factory" << endl;
return 0;
}
connect( m_factory, SIGNAL( objectCreated( QObject * ) ),
this, SLOT( slotObjectCreated( QObject * ) ) );
return m_factory;
}
void* KLibrary::symbol( const char* symname ) const
{
//US void* sym = lt_dlsym( (lt_dlhandle) m_handle, symname );
void* sym = m_handle->resolve( symname );
if ( !sym )
{
//US kdWarning(150) << "KLibrary: " << lt_dlerror() << endl;
return 0;
}
return sym;
}
bool KLibrary::hasSymbol( const char* symname ) const
{
//US void* sym = lt_dlsym( (lt_dlhandle) m_handle, symname );
void* sym = m_handle->resolve( symname );
return (sym != 0L );
}
void KLibrary::unload() const
{
if (KLibLoader::s_self)
KLibLoader::s_self->unloadLibrary(QFile::encodeName(name()));
}
void KLibrary::slotObjectCreated( QObject *obj )
{
if ( !obj )
return;
if ( m_timer && m_timer->isActive() )
m_timer->stop();
if ( m_objs.containsRef( obj ) )
return; // we know this object already
connect( obj, SIGNAL( destroyed() ),
this, SLOT( slotObjectDestroyed() ) );
m_objs.append( obj );
}
void KLibrary::slotObjectDestroyed()
{
m_objs.removeRef( sender() );
if ( m_objs.count() == 0 )
{
// kdDebug(150) << "KLibrary: shutdown timer for " << name() << " started!"
// << endl;
if ( !m_timer )
{
m_timer = new QTimer( this, "klibrary_shutdown_timer" );
connect( m_timer, SIGNAL( timeout() ),
this, SLOT( slotTimeout() ) );
}
// as long as it's not stable make the timeout short, for debugging
// pleasure (matz)
//m_timer->start( 1000*60, true );
m_timer->start( 1000*10, true );
}
}
void KLibrary::slotTimeout()
{
if ( m_objs.count() != 0 )
return;
/* Don't go through KLibLoader::unloadLibrary(), because that uses the
ref counter, but this timeout means to unconditionally close this library
The destroyed() signal will take care to remove us from all lists.
*/
delete this;
}
// -------------------------------------------------
/* This helper class is needed, because KLibraries can go away without
being unloaded. So we need some info about KLibraries even after its
death. */
class KLibWrapPrivate
{
public:
//US KLibWrapPrivate(KLibrary *l, lt_dlhandle h);
KLibWrapPrivate(KLibrary *l, QLibrary* h);
KLibrary *lib;
enum {UNKNOWN, UNLOAD, DONT_UNLOAD} unload_mode;
int ref_count;
//US lt_dlhandle handle;
QLibrary *handle;
QString name;
QString filename;
};
//US KLibWrapPrivate::KLibWrapPrivate(KLibrary *l, lt_dlhandle h)
KLibWrapPrivate::KLibWrapPrivate(KLibrary *l, QLibrary* h)
: lib(l), ref_count(1), handle(h), name(l->name()), filename(l->fileName())
{
unload_mode = UNKNOWN;
/*US
if (lt_dlsym(handle, "__kde_do_not_unload") != 0) {
// kdDebug(150) << "Will not unload " << name << endl;
unload_mode = DONT_UNLOAD;
} else if (lt_dlsym(handle, "__kde_do_unload") != 0) {
unload_mode = UNLOAD;
}
*/
//US use instead:
if (h->resolve("__kde_do_not_unload") != 0) {
// kdDebug(150) << "Will not unload " << name << endl;
unload_mode = DONT_UNLOAD;
} else if (h->resolve("__kde_do_unload") != 0) {
unload_mode = UNLOAD;
}
}
class KLibLoaderPrivate
{
public:
QPtrList<KLibWrapPrivate> loaded_stack;
QPtrList<KLibWrapPrivate> pending_close;
enum {UNKNOWN, UNLOAD, DONT_UNLOAD} unload_mode;
QString errorMessage;
};
KLibLoader* KLibLoader::s_self = 0;
KLibLoader* KLibLoader::self()
{
if ( !s_self )
s_self = new KLibLoader;
return s_self;
}
void KLibLoader::cleanUp()
{
if ( !s_self )
return;
delete s_self;
s_self = 0;
}
KLibLoader::KLibLoader( QObject* parent, const char* name )
: QObject( parent, name )
{
s_self = this;
d = new KLibLoaderPrivate;
//US lt_dlinit();
d->unload_mode = KLibLoaderPrivate::UNKNOWN;
if (getenv("KDE_NOUNLOAD") != 0)
d->unload_mode = KLibLoaderPrivate::DONT_UNLOAD;
else if (getenv("KDE_DOUNLOAD") != 0)
d->unload_mode = KLibLoaderPrivate::UNLOAD;
d->loaded_stack.setAutoDelete( true );
}
KLibLoader::~KLibLoader()
{
// kdDebug(150) << "Deleting KLibLoader " << this << " " << name() << endl;
QAsciiDictIterator<KLibWrapPrivate> it( m_libs );
for (; it.current(); ++it )
{
kdDebug(150) << "The KLibLoader contains the library " << it.current()->name
<< " (" << it.current()->lib << ")" << endl;
d->pending_close.append(it.current());
}
close_pending(0);
delete d;
}
//static
QString KLibLoader::findLibrary( const char * name/*US , const KInstance * instance*/ )
{
QCString libname( name );
// only append ".la" if there is no extension
// this allows to load non-libtool libraries as well
// (mhk, 20000228)
int pos = libname.findRev('/');
if (pos < 0)
pos = 0;
/*US
if (libname.find('.', pos) < 0) {
libname += ".la";
}
*/
//US in the microedition we work only with shared libraries.
if (libname.find('.', pos) < 0) {
#ifdef _WIN32_
libname += ".dll";
#else
libname += ".so";
#endif
}
// only look up the file if it is not an absolute filename
// (mhk, 20000228)
QString libfile;
if (libname[0] == '/')
libfile = libname;
else
{
//US at this point the libname must exist as real filesname. No expansions will be made later
// in findResources. Because of that we prepend the lib prefix here to the name
//US I add also the "lib" prefix. I do not how could this could have worked before without it?
#ifndef _WIN32_
libname.insert(pos, "lib");
#endif
//US libfile = instance->dirs()->findResource( "module", libname );
//qDebug("libname = %s ",libname.data() );
libfile = KGlobal::dirs()->findResource( "module", libname );
//qDebug("libfile = %s ",libfile.latin1() );
if ( libfile.isEmpty() )
{
//US libfile = instance->dirs()->findResource( "lib", libname );
libfile = KGlobal::dirs()->findResource( "lib", libname );
//qDebug("libfile2 = %s ",libfile.latin1() );
#ifndef NDEBUG
if ( !libfile.isEmpty() && libname.left(3) == "lib" ) // don't warn for kdeinit modules
kdDebug(150) << "library " << libname << " not found under 'module' but under 'lib'" << endl;
#endif
}
if ( libfile.isEmpty() )
{
#ifndef NDEBUG
kdDebug(150) << "library=" << libname << ": No file names " << libname.data() << " found in paths." << endl;
self()->d->errorMessage = i18n("Library files for \"%1\" not found in paths").arg(libname);
qDebug("KLibLoader::library could not find library: %s", libname.data());
#endif
}
else
self()->d->errorMessage = QString::null;
}
//qDebug("return libfile = %s ",libfile.latin1() );
return libfile;
}
KLibrary* KLibLoader::globalLibrary( const char *name )
{
KLibrary *tmp;
/*US
int olt_dlopen_flag = lt_dlopen_flag;
lt_dlopen_flag |= LT_GLOBAL;
kdDebug(150) << "Loading the next library global with flag "
<< lt_dlopen_flag
<< "." << endl;
*/
tmp = library(name);
/*US
lt_dlopen_flag = olt_dlopen_flag;
*/
return tmp;
}
KLibrary* KLibLoader::library( const char *name )
{
if (!name)
return 0;
KLibWrapPrivate* wrap = m_libs[name];
if (wrap) {
/* Nothing to do to load the library. */
wrap->ref_count++;
return wrap->lib;
}
/* Test if this library was loaded at some time, but got
unloaded meanwhile, whithout being dlclose()'ed. */
QPtrListIterator<KLibWrapPrivate> it(d->loaded_stack);
for (; it.current(); ++it) {
if (it.current()->name == name)
wrap = it.current();
}
if (wrap) {
d->pending_close.removeRef(wrap);
if (!wrap->lib) {
/* This lib only was in loaded_stack, but not in m_libs. */
wrap->lib = new KLibrary( name, wrap->filename, wrap->handle );
}
wrap->ref_count++;
} else {
QString libfile = findLibrary( name );
if ( libfile.isEmpty() )
return 0;
#ifdef DESKTOP_VERSION
QLibrary *qlib = new QLibrary( libfile.latin1() );
#else
QLibrary *qlib = new QLibrary( libfile.latin1(), QLibrary::Immediately );
#endif
//US lt_dlhandle handle = lt_dlopen( libfile.latin1() );
//US if ( !handle )
if ( !qlib )
{
-//US const char* errmsg = lt_dlerror();
- char* errmsg;
- sprintf(errmsg, "KLibLoader::library could not load library: %s", libfile.latin1());
- qDebug(errmsg);
-
- if(errmsg)
- d->errorMessage = QString::fromLatin1(errmsg);
- else
+ qDebug( "KLibLoader::library could not load library: %s", libfile.latin1());
d->errorMessage = QString::null;
- kdWarning(150) << "library=" << name << ": file=" << libfile << ": " << d->errorMessage << endl;
return 0;
}
else
d->errorMessage = QString::null;
KLibrary *lib = new KLibrary( name, libfile, qlib );
wrap = new KLibWrapPrivate(lib, qlib);
d->loaded_stack.prepend(wrap);
}
m_libs.insert( name, wrap );
connect( wrap->lib, SIGNAL( destroyed() ),
this, SLOT( slotLibraryDestroyed() ) );
return wrap->lib;
}
QString KLibLoader::lastErrorMessage() const
{
return d->errorMessage;
}
void KLibLoader::unloadLibrary( const char *libname )
{
KLibWrapPrivate *wrap = m_libs[ libname ];
if (!wrap)
return;
if (--wrap->ref_count)
return;
// kdDebug(150) << "closing library " << libname << endl;
m_libs.remove( libname );
disconnect( wrap->lib, SIGNAL( destroyed() ),
this, SLOT( slotLibraryDestroyed() ) );
close_pending( wrap );
}
KLibFactory* KLibLoader::factory( const char* name )
{
KLibrary* lib = library( name );
if ( !lib )
return 0;
return lib->factory();
}
void KLibLoader::slotLibraryDestroyed()
{
const KLibrary *lib = static_cast<const KLibrary *>( sender() );
QAsciiDictIterator<KLibWrapPrivate> it( m_libs );
for (; it.current(); ++it )
if ( it.current()->lib == lib )
{
KLibWrapPrivate *wrap = it.current();
wrap->lib = 0; /* the KLibrary object is already away */
m_libs.remove( it.currentKey() );
close_pending( wrap );
return;
}
}
void KLibLoader::close_pending(KLibWrapPrivate *wrap)
{
if (wrap && !d->pending_close.containsRef( wrap ))
d->pending_close.append( wrap );
/* First delete all KLibrary objects in pending_close, but _don't_ unload
the DSO behind it. */
QPtrListIterator<KLibWrapPrivate> it(d->pending_close);
for (; it.current(); ++it) {
wrap = it.current();
if (wrap->lib) {
disconnect( wrap->lib, SIGNAL( destroyed() ),
this, SLOT( slotLibraryDestroyed() ) );
delete wrap->lib;
wrap->lib = 0;
}
}
if (d->unload_mode == KLibLoaderPrivate::DONT_UNLOAD) return;
bool deleted_one = false;
while ((wrap = d->loaded_stack.first())) {
/* Let's first see, if we want to try to unload this lib.
If the env. var KDE_DOUNLOAD is set, we try to unload every lib.
If not, we look at the lib itself, and unload it only, if it exports
the symbol __kde_do_unload. */
if (d->unload_mode != KLibLoaderPrivate::UNLOAD
&& wrap->unload_mode != KLibWrapPrivate::UNLOAD)
break;
/* Now ensure, that the libs are only unloaded in the reverse direction
they were loaded. */
if (!d->pending_close.containsRef( wrap )) {
if (!deleted_one)
/* Only diagnose, if we really haven't deleted anything. */
// kdDebug(150) << "try to dlclose " << wrap->name << ": not yet" << endl;
break;
}
// kdDebug(150) << "try to dlclose " << wrap->name << ": yes, done." << endl;
#if 0
#ifndef Q_WS_QWS
if ( !deleted_one ) {
/* Only do the hack once in this loop.
WABA: *HACK*
We need to make sure to clear the clipboard before unloading a DSO
because the DSO could have defined an object derived from QMimeSource
and placed that on the clipboard. */
/*kapp->clipboard()->clear();*/
/* Well.. let's do something more subtle... convert the clipboard context
to text. That should be safe as it only uses objects defined by Qt. */
QWidgetList *widgetlist = QApplication::topLevelWidgets();
QWidget *co = widgetlist->first();
while (co) {
if (qstrcmp(co->name(), "internal clipboard owner") == 0) {
if (XGetSelectionOwner(co->x11Display(), XA_PRIMARY) == co->winId())
kapp->clipboard()->setText(kapp->clipboard()->text());
break;
}
co = widgetlist->next();
}
delete widgetlist;
}
#else
// FIXME(E): Implement in Qt Embedded
#endif
#endif // 0
deleted_one = true;
//US lt_dlclose(wrap->handle);
wrap->handle->unload();
d->pending_close.removeRef(wrap);
/* loaded_stack is AutoDelete, so wrap is freed */
d->loaded_stack.remove();
}
}
void KLibLoader::virtual_hook( int, void* )
{ /*BASE::virtual_hook( id, data );*/ }
void KLibFactory::virtual_hook( int, void* )
{ /*BASE::virtual_hook( id, data );*/ }
//US #include "klibloader.moc"
diff --git a/microkde/kdeui/ktoolbar.cpp b/microkde/kdeui/ktoolbar.cpp
index 1ad1728..09ad0c8 100644
--- a/microkde/kdeui/ktoolbar.cpp
+++ b/microkde/kdeui/ktoolbar.cpp
@@ -369,1025 +369,1025 @@ int KToolBar::insertLined (const QString& text, int id,
bool enabled ,
const QString& toolTipText,
int size, int index )
{
KLineEdit *lined = new KLineEdit ( this, 0 );
if ( !toolTipText.isEmpty() )
QToolTip::add( lined, toolTipText );
if ( size > 0 )
lined->setMinimumWidth( size );
insertWidgetInternal( lined, index, id );
connect( lined, signal, receiver, slot );
lined->setText(text);
lined->setEnabled( enabled );
return index;
}
int KToolBar::insertCombo (const QStringList &list, int id, bool writable,
const char *signal, const QObject *receiver,
const char *slot, bool enabled,
const QString& tooltiptext,
int size, int index,
QComboBox::Policy policy )
{
//US KComboBox *combo = new KComboBox ( writable, this );
KComboBox *combo = new KComboBox ( this );
combo->setEditable(writable);
insertWidgetInternal( combo, index, id );
combo->insertStringList (list);
combo->setInsertionPolicy(policy);
combo->setEnabled( enabled );
if ( !tooltiptext.isEmpty() )
QToolTip::add( combo, tooltiptext );
if ( size > 0 )
combo->setMinimumWidth( size );
if (!tooltiptext.isNull())
QToolTip::add( combo, tooltiptext );
if ( signal && receiver && slot )
connect ( combo, signal, receiver, slot );
return index;
}
int KToolBar::insertCombo (const QString& text, int id, bool writable,
const char *signal, QObject *receiver,
const char *slot, bool enabled,
const QString& tooltiptext,
int size, int index,
QComboBox::Policy policy )
{
//US KComboBox *combo = new KComboBox ( writable, this );
KComboBox *combo = new KComboBox ( this );
combo->setEditable(writable);
insertWidgetInternal( combo, index, id );
combo->insertItem (text);
combo->setInsertionPolicy(policy);
combo->setEnabled( enabled );
if ( !tooltiptext.isEmpty() )
QToolTip::add( combo, tooltiptext );
if ( size > 0 )
combo->setMinimumWidth( size );
if (!tooltiptext.isNull())
QToolTip::add( combo, tooltiptext );
connect (combo, signal, receiver, slot);
return index;
}
int KToolBar::insertSeparator(int index, int id)
{
QWidget *w = new KToolBarSeparator( orientation(), FALSE, this, "tool bar separator" );
insertWidgetInternal( w, index, id );
return index;
}
int KToolBar::insertLineSeparator(int index, int id)
{
QWidget *w = new KToolBarSeparator( orientation(), TRUE, this, "tool bar separator" );
insertWidgetInternal( w, index, id );
return index;
}
int KToolBar::insertWidget(int id, int /*width*/, QWidget *widget, int index)
{
// removeWidgetInternal( widget ); // in case we already have it ?
insertWidgetInternal( widget, index, id );
return index;
}
/*US
int KToolBar::insertAnimatedWidget(int id, QObject *receiver, const char *slot,
const QString& icons, int index )
{
KAnimWidget *anim = new KAnimWidget( icons, d->m_iconSize, this );
insertWidgetInternal( anim, index, id );
if ( receiver )
connect( anim, SIGNAL(clicked()), receiver, slot);
return index;
}
KAnimWidget *KToolBar::animatedWidget( int id )
{
Id2WidgetMap::Iterator it = id2widget.find( id );
if ( it == id2widget.end() )
return 0;
if ( (*it) && (*it)->inherits( "KAnimWidget" ) )
return (KAnimWidget*)(*it);
QObjectList *l = queryList( "KAnimWidget" );
if ( !l || !l->first() ) {
delete l;
return 0;
}
for ( QObject *o = l->first(); o; o = l->next() ) {
if ( o->inherits( "KAnimWidget" ) )
{
delete l;
return (KAnimWidget*)o;
}
}
delete l;
return 0;
}
*/
void KToolBar::addConnection (int id, const char *signal,
const QObject *receiver, const char *slot)
{
Id2WidgetMap::Iterator it = id2widget.find( id );
if ( it == id2widget.end() )
return;
if ( (*it) )
connect( (*it), signal, receiver, slot );
}
void KToolBar::setItemEnabled( int id, bool enabled )
{
Id2WidgetMap::Iterator it = id2widget.find( id );
if ( it == id2widget.end() )
return;
if ( (*it) )
(*it)->setEnabled( enabled );
}
void KToolBar::setButtonPixmap( int id, const QPixmap& _pixmap )
{
Id2WidgetMap::Iterator it = id2widget.find( id );
if ( it == id2widget.end() )
return;
//US KToolBarButton * button = dynamic_cast<KToolBarButton *>( *it );
KToolBarButton * button = (KToolBarButton *)( *it );
if ( button )
button->setPixmap( _pixmap );
}
void KToolBar::setButtonIcon( int id, const QString& _icon )
{
Id2WidgetMap::Iterator it = id2widget.find( id );
if ( it == id2widget.end() )
return;
//US KToolBarButton * button = dynamic_cast<KToolBarButton *>( *it );
KToolBarButton * button = (KToolBarButton *)( *it );
if ( button )
button->setIcon( _icon );
}
void KToolBar::setButtonIconSet( int id, const QIconSet& iconset )
{
Id2WidgetMap::Iterator it = id2widget.find( id );
if ( it == id2widget.end() )
return;
//US KToolBarButton * button = dynamic_cast<KToolBarButton *>( *it );
KToolBarButton * button = (KToolBarButton *)( *it );
if ( button )
button->setIconSet( iconset );
}
void KToolBar::setDelayedPopup (int id , QPopupMenu *_popup, bool toggle )
{
Id2WidgetMap::Iterator it = id2widget.find( id );
if ( it == id2widget.end() )
return;
//US KToolBarButton * button = dynamic_cast<KToolBarButton *>( *it );
KToolBarButton * button = (KToolBarButton *)( *it );
if ( button )
button->setDelayedPopup( _popup, toggle );
}
void KToolBar::setAutoRepeat (int id, bool flag)
{
Id2WidgetMap::Iterator it = id2widget.find( id );
if ( it == id2widget.end() )
return;
//US KToolBarButton * button = dynamic_cast<KToolBarButton *>( *it );
KToolBarButton * button = (KToolBarButton *)( *it );
if ( button )
button->setAutoRepeat( flag );
}
void KToolBar::setToggle (int id, bool flag )
{
Id2WidgetMap::Iterator it = id2widget.find( id );
if ( it == id2widget.end() )
return;
//US KToolBarButton * button = dynamic_cast<KToolBarButton *>( *it );
KToolBarButton * button = (KToolBarButton *)( *it );
if ( button )
button->setToggle( flag );
}
void KToolBar::toggleButton (int id)
{
Id2WidgetMap::Iterator it = id2widget.find( id );
if ( it == id2widget.end() )
return;
//US KToolBarButton * button = dynamic_cast<KToolBarButton *>( *it );
KToolBarButton * button = (KToolBarButton *)( *it );
if ( button )
button->toggle();
}
void KToolBar::setButton (int id, bool flag)
{
Id2WidgetMap::Iterator it = id2widget.find( id );
if ( it == id2widget.end() )
return;
//US KToolBarButton * button = dynamic_cast<KToolBarButton *>( *it );
KToolBarButton * button = (KToolBarButton *)( *it );
if ( button )
button->on( flag );
}
bool KToolBar::isButtonOn (int id) const
{
Id2WidgetMap::ConstIterator it = id2widget.find( id );
if ( it == id2widget.end() )
return false;
//US KToolBarButton * button = dynamic_cast<KToolBarButton *>( *it );
KToolBarButton * button = (KToolBarButton *)( *it );
return button ? button->isOn() : false;
}
void KToolBar::setLinedText (int id, const QString& text)
{
Id2WidgetMap::Iterator it = id2widget.find( id );
if ( it == id2widget.end() )
return;
//US QLineEdit * lineEdit = dynamic_cast<QLineEdit *>( *it );
QLineEdit * lineEdit = (QLineEdit *)( *it );
if ( lineEdit )
lineEdit->setText( text );
}
QString KToolBar::getLinedText (int id) const
{
Id2WidgetMap::ConstIterator it = id2widget.find( id );
if ( it == id2widget.end() )
return QString::null;
//US QLineEdit * lineEdit = dynamic_cast<QLineEdit *>( *it );
QLineEdit * lineEdit = (QLineEdit *)( *it );
return lineEdit ? lineEdit->text() : QString::null;
}
void KToolBar::insertComboItem (int id, const QString& text, int index)
{
Id2WidgetMap::Iterator it = id2widget.find( id );
if ( it == id2widget.end() )
return;
//US QComboBox * comboBox = dynamic_cast<QComboBox *>( *it );
QComboBox * comboBox = (QComboBox *)( *it );
if (comboBox)
comboBox->insertItem( text, index );
}
void KToolBar::insertComboList (int id, const QStringList &list, int index)
{
Id2WidgetMap::Iterator it = id2widget.find( id );
if ( it == id2widget.end() )
return;
//US QComboBox * comboBox = dynamic_cast<QComboBox *>( *it );
QComboBox * comboBox = (QComboBox *)( *it );
if (comboBox)
comboBox->insertStringList( list, index );
}
void KToolBar::removeComboItem (int id, int index)
{
Id2WidgetMap::Iterator it = id2widget.find( id );
if ( it == id2widget.end() )
return;
//US QComboBox * comboBox = dynamic_cast<QComboBox *>( *it );
QComboBox * comboBox = (QComboBox *)( *it );
if (comboBox)
comboBox->removeItem( index );
}
void KToolBar::setCurrentComboItem (int id, int index)
{
Id2WidgetMap::Iterator it = id2widget.find( id );
if ( it == id2widget.end() )
return;
//US QComboBox * comboBox = dynamic_cast<QComboBox *>( *it );
QComboBox * comboBox = (QComboBox *)( *it );
if (comboBox)
comboBox->setCurrentItem( index );
}
void KToolBar::changeComboItem (int id, const QString& text, int index)
{
Id2WidgetMap::Iterator it = id2widget.find( id );
if ( it == id2widget.end() )
return;
//US QComboBox * comboBox = dynamic_cast<QComboBox *>( *it );
QComboBox * comboBox = (QComboBox *)( *it );
if (comboBox)
comboBox->changeItem( text, index );
}
void KToolBar::clearCombo (int id)
{
Id2WidgetMap::Iterator it = id2widget.find( id );
if ( it == id2widget.end() )
return;
//US QComboBox * comboBox = dynamic_cast<QComboBox *>( *it );
QComboBox * comboBox = (QComboBox *)( *it );
if (comboBox)
comboBox->clear();
}
QString KToolBar::getComboItem (int id, int index) const
{
Id2WidgetMap::ConstIterator it = id2widget.find( id );
if ( it == id2widget.end() )
return QString::null;
//US QComboBox * comboBox = dynamic_cast<QComboBox *>( *it );
QComboBox * comboBox = (QComboBox *)( *it );
return comboBox ? comboBox->text( index ) : QString::null;
}
KComboBox * KToolBar::getCombo(int id)
{
Id2WidgetMap::Iterator it = id2widget.find( id );
if ( it == id2widget.end() )
return 0;
//US return dynamic_cast<KComboBox *>( *it );
return (KComboBox *)( *it );
}
KLineEdit * KToolBar::getLined (int id)
{
Id2WidgetMap::Iterator it = id2widget.find( id );
if ( it == id2widget.end() )
return 0;
//US return dynamic_cast<KLineEdit *>( *it );
return (KLineEdit *)( *it );
}
KToolBarButton * KToolBar::getButton (int id)
{
Id2WidgetMap::Iterator it = id2widget.find( id );
if ( it == id2widget.end() )
return 0;
//US return dynamic_cast<KToolBarButton *>( *it );
return (KToolBarButton *)( *it );
}
void KToolBar::alignItemRight (int id, bool right )
{
Id2WidgetMap::Iterator it = id2widget.find( id );
if ( it == id2widget.end() )
return;
if ( rightAligned && !right && (*it) == rightAligned )
rightAligned = 0;
if ( (*it) && right )
rightAligned = (*it);
}
QWidget *KToolBar::getWidget (int id)
{
Id2WidgetMap::Iterator it = id2widget.find( id );
return ( it == id2widget.end() ) ? 0 : (*it);
}
void KToolBar::setItemAutoSized (int id, bool yes )
{
QWidget *w = getWidget(id);
if ( w && yes )
setStretchableWidget( w );
}
void KToolBar::clear ()
{
QToolBar::clear();
widget2id.clear();
id2widget.clear();
}
void KToolBar::removeItem(int id)
{
Id2WidgetMap::Iterator it = id2widget.find( id );
if ( it == id2widget.end() )
{
kdDebug(220) << "KToolBar::removeItem item " << id << " not found" << endl;
return;
}
QWidget * w = (*it);
id2widget.remove( id );
widget2id.remove( w );
widgets.removeRef( w );
delete w;
}
void KToolBar::removeItemDelayed(int id)
{
Id2WidgetMap::Iterator it = id2widget.find( id );
if ( it == id2widget.end() )
{
kdDebug(220) << "KToolBar::removeItem item " << id << " not found" << endl;
return;
}
QWidget * w = (*it);
id2widget.remove( id );
widget2id.remove( w );
widgets.removeRef( w );
w->blockSignals(true);
d->idleButtons.append(w);
layoutTimer->start( 50, TRUE );
}
void KToolBar::hideItem (int id)
{
QWidget *w = getWidget(id);
if ( w )
w->hide();
}
void KToolBar::showItem (int id)
{
QWidget *w = getWidget(id);
if ( w )
w->show();
}
int KToolBar::itemIndex (int id)
{
QWidget *w = getWidget(id);
return w ? widgets.findRef(w) : -1;
}
void KToolBar::setFullSize(bool flag )
{
setHorizontalStretchable( flag );
setVerticalStretchable( flag );
}
bool KToolBar::fullSize() const
{
return isHorizontalStretchable() || isVerticalStretchable();
}
void KToolBar::enableMoving(bool flag )
{
//US setMovingEnabled(flag);
this->mainWindow()->setToolBarsMovable(flag);
}
void KToolBar::setBarPos (BarPosition bpos)
{
if ( !mainWindow() )
return;
//US mainWindow()->moveDockWindow( this, (Dock)bpos );
mainWindow()->moveToolBar( this, (QMainWindow::ToolBarDock)bpos );
}
-KToolBar::BarPosition KToolBar::barPos()
+KToolBar::BarPosition KToolBar::barPos() const
{
if ( !(QMainWindow*)mainWindow() )
return KToolBar::Top;
//US Dock dock;
QMainWindow::ToolBarDock dock;
int dm1, dm2;
bool dm3;
((QMainWindow*)mainWindow())->getLocation( (QToolBar*)this, dock, dm1, dm3, dm2 );
//US if ( dock == DockUnmanaged ) {
if ( dock == QMainWindow::Unmanaged ) {
return (KToolBar::BarPosition)Top;
}
return (BarPosition)dock;
}
bool KToolBar::enable(BarStatus stat)
{
bool mystat = isVisible();
if ( (stat == Toggle && mystat) || stat == Hide )
hide();
else
show();
return isVisible() == mystat;
}
void KToolBar::setMaxHeight ( int h )
{
setMaximumHeight( h );
}
int KToolBar::maxHeight()
{
return maximumHeight();
}
void KToolBar::setMaxWidth (int dw)
{
setMaximumWidth( dw );
}
int KToolBar::maxWidth()
{
return maximumWidth();
}
void KToolBar::setTitle (const QString& _title)
{
setLabel( _title );
}
void KToolBar::enableFloating (bool )
{
}
void KToolBar::setIconText(IconText it)
{
setIconText( it, true );
}
void KToolBar::setIconText(IconText icontext, bool update)
{
bool doUpdate=false;
if (icontext != d->m_iconText) {
d->m_iconText = icontext;
doUpdate=true;
}
if (update == false)
return;
if (doUpdate)
emit modechange(); // tell buttons what happened
// ugly hack to force a QMainWindow::triggerLayout( TRUE )
if ( mainWindow() ) {
QMainWindow *mw = mainWindow();
mw->setUpdatesEnabled( FALSE );
mw->setToolBarsMovable( !mw->toolBarsMovable() );
mw->setToolBarsMovable( !mw->toolBarsMovable() );
mw->setUpdatesEnabled( TRUE );
}
}
KToolBar::IconText KToolBar::iconText() const
{
return d->m_iconText;
}
void KToolBar::setIconSize(int size)
{
setIconSize( size, true );
}
void KToolBar::setIconSize(int size, bool update)
{
bool doUpdate=false;
if ( size != d->m_iconSize ) {
d->m_iconSize = size;
doUpdate=true;
}
if (update == false)
return;
if (doUpdate)
emit modechange(); // tell buttons what happened
// ugly hack to force a QMainWindow::triggerLayout( TRUE )
if ( mainWindow() ) {
QMainWindow *mw = mainWindow();
mw->setUpdatesEnabled( FALSE );
mw->setToolBarsMovable( !mw->toolBarsMovable() );
mw->setToolBarsMovable( !mw->toolBarsMovable() );
mw->setUpdatesEnabled( TRUE );
}
}
int KToolBar::iconSize() const
{
/*US
if ( !d->m_iconSize ) // default value?
{
if (!::qstrcmp(QObject::name(), "mainToolBar"))
return KGlobal::iconLoader()->currentSize(KIcon::MainToolbar);
else
return KGlobal::iconLoader()->currentSize(KIcon::Toolbar);
}
return d->m_iconSize;
*/
int ret = 18;
if ( QApplication::desktop()->width() > 320 )
ret = 30;
return ret;
}
void KToolBar::setEnableContextMenu(bool enable )
{
d->m_enableContext = enable;
}
bool KToolBar::contextMenuEnabled() const
{
return d->m_enableContext;
}
void KToolBar::setItemNoStyle(int id, bool no_style )
{
Id2WidgetMap::Iterator it = id2widget.find( id );
if ( it == id2widget.end() )
return;
//US KToolBarButton * button = dynamic_cast<KToolBarButton *>( *it );
KToolBarButton * button = (KToolBarButton *)( *it );
if (button)
button->setNoStyle( no_style );
}
void KToolBar::setFlat (bool flag)
{
if ( !mainWindow() )
return;
if ( flag )
//US mainWindow()->moveDockWindow( this, DockMinimized );
mainWindow()->moveToolBar( this, QMainWindow::Minimized );
else
//US mainWindow()->moveDockWindow( this, DockTop );
mainWindow()->moveToolBar( this, QMainWindow::Top );
// And remember to save the new look later
/*US
if ( mainWindow()->inherits( "KMainWindow" ) )
static_cast<KMainWindow *>(mainWindow())->setSettingsDirty();
*/
}
int KToolBar::count() const
{
return id2widget.count();
}
void KToolBar::saveState()
{
/*US
// first, try to save to the xml file
if ( d->m_xmlguiClient && !d->m_xmlguiClient->xmlFile().isEmpty() ) {
// go down one level to get to the right tags
QDomElement elem = d->m_xmlguiClient->domDocument().documentElement().toElement();
elem = elem.firstChild().toElement();
QString barname(!::qstrcmp(name(), "unnamed") ? "mainToolBar" : name());
QDomElement current;
// now try to find our toolbar
d->modified = false;
for( ; !elem.isNull(); elem = elem.nextSibling().toElement() ) {
current = elem;
if ( current.tagName().lower() != "toolbar" )
continue;
QString curname(current.attribute( "name" ));
if ( curname == barname ) {
saveState( current );
break;
}
}
// if we didn't make changes, then just return
if ( !d->modified )
return;
// now we load in the (non-merged) local file
QString local_xml(KXMLGUIFactory::readConfigFile(d->m_xmlguiClient->xmlFile(), true, d->m_xmlguiClient->instance()));
QDomDocument local;
local.setContent(local_xml);
// make sure we don't append if this toolbar already exists locally
bool just_append = true;
elem = local.documentElement().toElement();
KXMLGUIFactory::removeDOMComments( elem );
elem = elem.firstChild().toElement();
for( ; !elem.isNull(); elem = elem.nextSibling().toElement() ) {
if ( elem.tagName().lower() != "toolbar" )
continue;
QString curname(elem.attribute( "name" ));
if ( curname == barname ) {
just_append = false;
local.documentElement().replaceChild( current, elem );
break;
}
}
if (just_append)
local.documentElement().appendChild( current );
KXMLGUIFactory::saveConfigFile(local, d->m_xmlguiClient->localXMLFile(), d->m_xmlguiClient->instance() );
return;
}
*/
// if that didn't work, we save to the config file
KConfig *config = KGlobal::config();
saveSettings(config, QString::null);
config->sync();
}
QString KToolBar::settingsGroup()
{
QString configGroup;
if (!::qstrcmp(name(), "unnamed") || !::qstrcmp(name(), "mainToolBar"))
configGroup = "Toolbar style";
else
configGroup = QString(name()) + " Toolbar style";
if ( this->mainWindow() )
{
configGroup.prepend(" ");
configGroup.prepend( this->mainWindow()->name() );
}
return configGroup;
}
void KToolBar::saveSettings(KConfig *config, const QString &_configGroup)
{
QString configGroup = _configGroup;
if (configGroup.isEmpty())
configGroup = settingsGroup();
//kdDebug(220) << "KToolBar::saveSettings group=" << _configGroup << " -> " << configGroup << endl;
QString position, icontext;
int index;
getAttributes( position, icontext, index );
//kdDebug(220) << "KToolBar::saveSettings " << name() << " newLine=" << newLine << endl;
KConfigGroupSaver saver(config, configGroup);
if ( position != d->PositionDefault )
config->writeEntry("Position", position);
else
config->deleteEntry("Position");
if ( icontext != d->IconTextDefault )
config->writeEntry("IconText", icontext);
else
config->deleteEntry("IconText");
if ( iconSize() != d->IconSizeDefault )
config->writeEntry("IconSize", iconSize());
else
config->deleteEntry("IconSize");
if ( isHidden() != d->HiddenDefault )
config->writeEntry("Hidden", isHidden());
else
config->deleteEntry("Hidden");
if ( index != d->IndexDefault )
config->writeEntry( "Index", index );
else
config->deleteEntry("Index");
//US the older version of KDE (used on the Zaurus) has no Offset property
/* if ( offset() != d->OffsetDefault )
config->writeEntry( "Offset", offset() );
else
*/
config->deleteEntry("Offset");
//US the older version of KDE (used on the Zaurus) has no NewLine property
/*
if ( newLine() != d->NewLineDefault )
config->writeEntry( "NewLine", newLine() );
else
*/
config->deleteEntry("NewLine");
}
void KToolBar::setXMLGUIClient( KXMLGUIClient *client )
{
d->m_xmlguiClient = client;
}
void KToolBar::setText( const QString & txt )
{
//US setLabel( txt + " ( " + kapp->caption() + " ) " );
setLabel( txt + " ( " + KGlobal::getAppName() + " ) " );
}
QString KToolBar::text() const
{
return label();
}
void KToolBar::doConnections( KToolBarButton *button )
{
connect(button, SIGNAL(clicked(int)), this, SIGNAL( clicked( int ) ) );
connect(button, SIGNAL(doubleClicked(int)), this, SIGNAL( doubleClicked( int ) ) );
connect(button, SIGNAL(released(int)), this, SIGNAL( released( int ) ) );
connect(button, SIGNAL(pressed(int)), this, SIGNAL( pressed( int ) ) );
connect(button, SIGNAL(toggled(int)), this, SIGNAL( toggled( int ) ) );
connect(button, SIGNAL(highlighted(int, bool)), this, SIGNAL( highlighted( int, bool ) ) );
}
void KToolBar::mousePressEvent ( QMouseEvent *m )
{
if ( !mainWindow() )
return;
QMainWindow *mw = mainWindow();
if ( mw->toolBarsMovable() && d->m_enableContext ) {
if ( m->button() == RightButton ) {
int i = contextMenu()->exec( m->globalPos(), 0 );
switch ( i ) {
case -1:
return; // popup cancelled
case CONTEXT_LEFT:
//US mw->moveDockWindow( this, DockLeft );
mw->moveToolBar( this, QMainWindow::Left );
break;
case CONTEXT_RIGHT:
//US mw->moveDockWindow( this, DockRight );
mw->moveToolBar( this, QMainWindow::Right );
break;
case CONTEXT_TOP:
//US mw->moveDockWindow( this, DockTop );
mw->moveToolBar( this, QMainWindow::Top );
break;
case CONTEXT_BOTTOM:
//US mw->moveDockWindow( this, DockBottom );
mw->moveToolBar( this, QMainWindow::Bottom );
break;
case CONTEXT_FLOAT:
break;
case CONTEXT_FLAT:
//US mw->moveDockWindow( this, DockMinimized );
mw->moveToolBar( this, QMainWindow::Minimized );
break;
case CONTEXT_ICONS:
setIconText( IconOnly );
break;
case CONTEXT_TEXTRIGHT:
setIconText( IconTextRight );
break;
case CONTEXT_TEXT:
setIconText( TextOnly );
break;
case CONTEXT_TEXTUNDER:
setIconText( IconTextBottom );
break;
default:
if ( i >= CONTEXT_ICONSIZES )
setIconSize( i - CONTEXT_ICONSIZES );
else
return; // assume this was an action handled elsewhere, no need for setSettingsDirty()
}
/*US
if ( mw->inherits("KMainWindow") )
static_cast<KMainWindow *>(mw)->setSettingsDirty();
*/
}
}
}
void KToolBar::rebuildLayout()
{
for(QWidget *w=d->idleButtons.first(); w; w=d->idleButtons.next())
w->blockSignals(false);
d->idleButtons.clear();
layoutTimer->stop();
QApplication::sendPostedEvents( this, QEvent::ChildInserted );
QBoxLayout *l = boxLayout();
l->setMargin( 1 );
// clear the old layout
QLayoutIterator it = l->iterator();
while ( it.current() ) {
it.deleteCurrent();
}
for ( QWidget *w = widgets.first(); w; w = widgets.next() ) {
if ( w == rightAligned ) {
continue;
}
if ( w->inherits( "KToolBarSeparator" ) &&
!( (KToolBarSeparator*)w )->showLine() ) {
l->addSpacing( 6 );
w->hide();
continue;
}
if ( w->inherits( "QPopupMenu" ) )
continue;
l->addWidget( w );
w->show();
}
if ( rightAligned ) {
l->addStretch();
l->addWidget( rightAligned );
rightAligned->show();
}
if ( fullSize() ) {
// This code sucks. It makes the last combo in a toolbar VERY big (e.g. zoom combo in kword).
//if ( !stretchableWidget && widgets.last() &&
// !widgets.last()->inherits( "QButton" ) && !widgets.last()->inherits( "KAnimWidget" ) )
// setStretchableWidget( widgets.last() );
if ( !rightAligned )
l->addStretch();
if ( stretchableWidget )
l->setStretchFactor( stretchableWidget, 10 );
}
l->invalidate();
QApplication::postEvent( this, new QEvent( QEvent::LayoutHint ) );
//#endif //DESKTOP_VERSION
}
void KToolBar::childEvent( QChildEvent *e )
{
if ( e->child()->isWidgetType() ) {
QWidget * w = (QWidget*)e->child();
if ( e->type() == QEvent::ChildInserted ) {
if ( !e->child()->inherits( "QPopupMenu" ) &&
::qstrcmp( "qt_dockwidget_internal", e->child()->name() ) != 0 ) {
// prevent items that have been explicitly inserted by insert*() from
// being inserted again
if ( !widget2id.contains( w ) )
{
int dummy = -1;
insertWidgetInternal( w, dummy, -1 );
}
}
} else {
removeWidgetInternal( w );
}
if ( isVisibleTo( 0 ) )
{
QBoxLayout *l = boxLayout();
// QLayout *l = layout();
// clear the old layout so that we don't get unnecassery layout
// changes till we have rebuild the thing
QLayoutIterator it = l->iterator();
while ( it.current() ) {
it.deleteCurrent();
}
layoutTimer->start( 50, TRUE );
}
}
QToolBar::childEvent( e );
}
diff --git a/microkde/kdeui/ktoolbar.h b/microkde/kdeui/ktoolbar.h
index 61b5ea3..49ff856 100644
--- a/microkde/kdeui/ktoolbar.h
+++ b/microkde/kdeui/ktoolbar.h
@@ -237,872 +237,872 @@ public:
* @param index The position of the button. (-1 = at end).
*
* @return The item index.
*/
int insertButton(const QString& icon, int id, const char *signal,
const QObject *receiver, const char *slot,
bool enabled = true, const QString& text = QString::null,
int index=-1/*US, KInstance *_instance = KGlobal::instance()*/ );
/**
* Inserts a button (a @ref KToolBarButton) with the specified
* pixmap. This pixmap will be used as the "active" one and the
* disabled and default ones will be autogenerated.
*
* It is recommended that you use the insertButton function that
* allows you to specify the icon name rather then the pixmap
* itself. Specifying the icon name is much more flexible.
*
* You should connect to one or more signals in KToolBar:
* @ref clicked() , @ref pressed() , @ref released() , or
* @ref highlighted() and if the button is a toggle button
* (@ref setToggle() ) @ref toggled() . Those signals have @p id
* of a button that caused the signal. If you want to bind a popup
* to button, see @ref setButton().
*
* @param pixmap The active pixmap
* @param id The id of this button
* @param enabled Enable or disable the button at startup
* @param text The tooltip or toolbar text (depending on state)
* @param index The position of the button. (-1 = at end).
*
* @return The item index.
*/
int insertButton(const QPixmap& pixmap, int id, bool enabled = true,
const QString& text = QString::null, int index=-1 );
/**
* This is the same as above, but with specified signals and
* slots to which this button will be connected.
*
* You can add more signals with @ref addConnection().
*
* @param icon The name of the icon to use as the active pixmap
* @param id The id of this button
* @param signal The signal to connect to
* @param receiver The slot's parent
* @param enabled Enable or disable the button at startup
* @param text The tooltip or toolbar text (depending on state)
* @param index The position of the button. (-1 = at end).
*
* @return The item index.
*/
int insertButton(const QPixmap& pixmap, int id, const char *signal,
const QObject *receiver, const char *slot,
bool enabled = true, const QString& text = QString::null,
int index=-1 );
/**
* Inserts a button with popupmenu.
*
* Button will have small
* triangle. You have to connect to popup's signals. The
* signals @ref KButton::pressed(), @ref KButton::released(),
* @ref KButton::clicked() or @ref KButton::doubleClicked() are @p not
* emmited by
* this button (see @ref setDelayedPopup() for that).
* You can add custom popups which inherit @ref QPopupMenu to get popups
* with tables, drawings etc. Just don't fiddle with events there.
*/
int insertButton(const QString& icon, int id, QPopupMenu *popup,
bool enabled, const QString&_text, int index=-1);
/**
* Inserts a button with popupmenu.
*
* Button will have small
* triangle. You have to connect to popup's signals. The
* signals @ref KButton::pressed(), @ref KButton::released(),
* @ref KButton::clicked() or @ref KButton::doubleClicked() are @p not
* emmited by
* this button (see @ref setDelayedPopup() for that).
* You can add custom popups which inherit @ref QPopupMenu to get popups
* with tables, drawings etc. Just don't fiddle with events there.
*/
int insertButton(const QPixmap& pixmap, int id, QPopupMenu *popup,
bool enabled, const QString&_text, int index=-1);
/**
* Inserts a @ref KLineEdit. You have to specify signals and slots to
* which KLineEdit will be connected. KLineEdit has all slots QLineEdit
* has, plus signals @ref KLineEdit::completion and @ref KLineEdit::textRotation
* KLineEdit can be set to autoresize itself to full free width
* in toolbar, that is to last right aligned item. For that,
* toolbar must be set to full width (which it is by default).
* @see setFullWidth()
* @see setItemAutoSized()
* @see KLineEdit
* @return Item index.
*/
int insertLined (const QString& text, int id,
const char *signal,
const QObject *receiver, const char *slot,
bool enabled = true,
const QString& toolTipText = QString::null,
int size = 70, int index =-1);
/**
* Inserts a @ref KComboBox with list.
*
* Can be writable, but cannot contain
* pixmaps. By default inserting policy is AtBottom, i.e. typed items
* are placed at the bottom of the list. Can be autosized. If the size
* argument is specified as -1, the width of the combobox is automatically
* computed.
*
* @see setFullWidth()
* @see setItemAutoSized()
* @see KComboBox
* @return Item index.
*/
int insertCombo (const QStringList &list, int id, bool writable,
const char *signal, const QObject *receiver,
const char *slot, bool enabled=true,
const QString& tooltiptext=QString::null,
int size=70, int index=-1,
QComboBox::Policy policy = QComboBox::AtBottom);
/**
* Insert a @ref KComboBox with text.
*
* The rest is the same as above.
* @see setItemAutoSized()
*
* @see KComboBox
* @return Item index.
*/
int insertCombo (const QString& text, int id, bool writable,
const char *signal, QObject *recevier,
const char *slot, bool enabled=true,
const QString& tooltiptext=QString::null,
int size=70, int index=-1,
QComboBox::Policy policy = QComboBox::AtBottom);
/**
* Inserts a separator into the toolbar with the given id.
* Returns the separator's index
*/
int insertSeparator( int index = -1, int id = -1 );
/**
* Inserts a line separator into the toolbar with the given id.
* Returns the separator's index
*/
int insertLineSeparator( int index = -1, int id = -1 );
/**
* Inserts a user-defined widget. The widget @p must have this
* toolbar as its parent.
*
* Widget must have a QWidget for base class. Widget can be
* autosized to full width. If you forget about it, you can get a
* pointer to this widget with @ref getWidget().
* @see setItemAutoSized()
* @return Item index.
*/
int insertWidget(int id, int width, QWidget *_widget, int index=-1);
/**
* Inserts an animated widget. A @ref KAnimWidget will be created
* internally using the icon name you provide.
* This will emit a signal (clicked()) whenever the
* animation widget is clicked.
*
* @see animatedWidget()
*
* @param id The id for this toolbar item
* @param receiver The parent of your slot
* @param slot The slot to receive the clicked() signal
* @param icons The name of the animation icon group to use
* @param index The item index
*
* @return The item index
*/
/*US
int insertAnimatedWidget(int id, QObject *receiver, const char *slot,
const QString& icons, int index = -1);
*/
/**
* This will return a pointer to the given animated widget, if it
* exists.
*
* @see insertAnimatedWidget
*
* @param id The id for the widget you want to get a pointer to
*
* @return A pointer to the current animated widget or 0L
*/
//US KAnimWidget *animatedWidget( int id );
/**
* Adds connections to items.
*
* It is important that you
* know the @p id of particular item. Nothing happens if you forget @p id.
*/
void addConnection (int id, const char *signal,
const QObject *receiver, const char *slot);
/**
* Enables/disables item.
*/
void setItemEnabled( int id, bool enabled );
/**
* Sets the icon for a button.
*
* Can be used while button is visible.
*/
void setButtonIcon( int id, const QString& _icon );
/**
* Sets button pixmap.
*
* Can be used while button is visible.
*/
void setButtonPixmap( int id, const QPixmap& _pixmap );
/**
* Sets a button icon from a QIconSet.
*
* Can be used while button is visible.
*/
void setButtonIconSet( int id, const QIconSet& iconset );
/**
* Sets a delayed popup for a button.
*
* Delayed popup is what you see in
* Netscape Navigator's Previous and Next buttons: If you click them you
* go back
* or forth. If you press them long enough, you get a history-menu.
* This is exactly what we do here.
*
* You will insert normal a button with connection (or use signals from
* toolbar):
* <pre>
* bar->insertButton(icon, id, SIGNAL(clicked ()), this,
* SLOT (slotClick()), true, "click or wait for popup");
* </pre> And then add a delayed popup:
* <pre>
* bar->setDelayedPopup (id, historyPopup); </pre>
*
* Don't add delayed popups to buttons which have normal popups.
*
* You may add popups which are derived from @ref QPopupMenu. You may
* add popups that are already in the menu bar or are submenus of
* other popups.
*/
void setDelayedPopup (int id , QPopupMenu *_popup, bool toggle = false);
/**
* Turns a button into an autorepeat button.
*
* Toggle buttons, buttons with menus, or
* buttons with delayed menus cannot be made into autorepeat buttons.
* Moreover, you can and will receive
* only the signal clicked(), but not pressed() or released().
* When the user presses this button, you will receive the signal clicked(),
* and if the button is still pressed after some time,
* you will receive more clicked() signals separated by regular
* intervals. Since this uses @ref QButton::setAutoRepeat() ,
* I can't quantify 'some'.
*/
void setAutoRepeat (int id, bool flag=true);
/**
* Turns button into a toggle button if @p flag is true.
*/
void setToggle (int id, bool flag = true);
/**
* Toggles a togglebutton.
*
* If the button is a toggle button (see @ref setToggle())
* the button state will be toggled. This will also cause the toolbar to
* emit the signal @ref KButton::toggled() with parameter @p id. You must connect to
* this signal, or use @ref addConnection() to connect directly to the
* button signal @ref KButton::toggled().
*/
void toggleButton (int id);
/**
* Sets a toggle button state.
*
* If the button is a toggle button (see @ref setToggle())
* this will set its state flag. This will also emit the signal
* @ref KButton::toggled().
*
* @see setToggle()
*/
void setButton (int id, bool flag);
/**
* @return @p true if button is on, @p false if button is off or if the
* button is not a toggle button.
* @see setToggle()
*/
bool isButtonOn (int id) const;
/**
* Sets the text of a line editor.
*
* Cursor is set at end of text.
*/
void setLinedText (int id, const QString& text);
/**
* Returns a line editor text.
*/
QString getLinedText (int id) const;
/**
* Inserts @p text in combobox @p id at position @p index.
*/
void insertComboItem (int id, const QString& text, int index);
/**
* Inserts @p list in combobox @p id at position @p index.
*/
void insertComboList (int id, const QStringList &list, int index);
/**
* Removes item @p index from combobox @p id.
*/
void removeComboItem (int id, int index);
/**
* Sets item @p index to be current item in combobox @p id.
*/
void setCurrentComboItem (int id, int index);
/**
* Changes item @p index in combobox @p id to text.
*
* @p index = -1 refers current item (one displayed in the button).
*/
void changeComboItem (int id, const QString& text, int index=-1);
/**
* Clears the combobox @p id.
*
* Does not delete it or hide it.
*/
void clearCombo (int id);
/**
* Returns text of item @p index from combobox @p id.
*
* @p index = -1 refers to current item.
*/
QString getComboItem (int id, int index=-1) const;
/**
* Returns a pointer to the combobox.
*
* Example:
* <pre>
* KComboBox *combo = toolbar->getCombo(combo_id);
* </pre>
* That way you can get access to other public methods
* that @ref KComboBox provides.
*/
KComboBox * getCombo(int id);
/**
* Returns a pointer to KToolBarLined.
*
* Example:
* <pre>
* KLineEdit * lined = toolbar->getKToolBarLined(lined_id);
* </pre>
* That way you can get access to other public methods
* that @ref KLineEdit provides. @ref KLineEdit is the same thing
* as @ref QLineEdit plus completion signals.
*/
KLineEdit * getLined (int id);
/**
* Returns a pointer to KToolBarButton.
*
* Example:
* <pre>
* KToolBarButton * button = toolbar->getButton(button_id);
* </pre>
* That way you can get access to other public methods
* that @ref KToolBarButton provides.
*
* Using this method is not recommended.
*/
KToolBarButton * getButton (int id);
/**
* Align item to the right.
*
* This works only if toolbar is set to full width.
* @see setFullWidth()
*/
void alignItemRight (int id, bool right = true);
/**
* Returns a pointer to an inserted widget.
*
* Wrong ids are not tested.
* You can do with this whatever you want,
* except change its height (hardcoded). If you change its width
* you will probably have to call QToolBar::updateRects(true)
* @see QWidget
* @see updateRects()
*
* KDE4: make this const!
*/
QWidget *getWidget (int id);
/**
* Set item autosized.
*
* This works only if the toolbar is set to full width.
* Only @p one item can be autosized, and it has to be
* the last left-aligned item. Items that come after this must be right
* aligned. Items that can be right aligned are Lineds, Frames, Widgets and
* Combos. An autosized item will resize itself whenever the toolbar geometry
* changes to the last right-aligned item (or to end of toolbar if there
* are no right-aligned items.)
* @see setFullWidth()
* @see alignItemRight()
*/
void setItemAutoSized (int id, bool yes = true);
/**
* Remove all items.
*
* The toolbar is redrawn after it.
*/
void clear ();
/**
* Remove item @p id.
*
* Item is deleted. Toolbar is redrawn after it.
*/
void removeItem (int id);
/**
* Remove item @p id.
*
* Item is deleted when toolbar is redrawn.
*/
void removeItemDelayed (int id);
/**
* Hide item.
*/
void hideItem (int id);
/**
* Show item.
*/
void showItem (int id);
/**
* Returns the index of the given item.
*
* KDE4: make this const!
*/
int itemIndex (int id);
/**
* Set toolbar to full parent size (default).
*
* In full size mode the bar
* extends over the parent's full width or height. If the mode is disabled
* the toolbar tries to take as much space as it needs without wrapping, but
* it does not exceed the parent box. You can force a certain width or
* height with @ref setMaxWidth() or @ref setMaxHeight().
*
* If you want to use right-aligned items or auto-sized items you must use
* full size mode.
*/
void setFullSize(bool flag = true);
/**
* @return @p true if the full-size mode is enabled. Otherwise
* it returns @false.
*/
bool fullSize() const;
/**
* @deprecated use setMovingEnabled(bool) instead.
* Enable or disable moving of toolbar.
*/
void enableMoving(bool flag = true);
/**
* Set position of toolbar.
* @see BarPosition()
*/
void setBarPos (BarPosition bpos);
/**
* Returns position of toolbar.
*/
- BarPosition barPos();
+ BarPosition barPos() const;
/**
* @deprecated
* Show, hide, or toggle toolbar.
*
* This method is provided for compatibility only,
* please use show() and/or hide() instead.
* @see BarStatus
*/
bool enable(BarStatus stat);
/**
* @deprecated
* Use setMaximumHeight() instead.
*/
void setMaxHeight (int h); // Set max height for vertical toolbars
/**
* @deprecated
* Use maximumHeight() instead.
* Returns the value that was set with @ref setMaxHeight().
*/
int maxHeight();
/**
* @deprecated
* Use setMaximumWidth() instead.
* Set maximal width of horizontal (top or bottom) toolbar.
*/
void setMaxWidth (int dw);
/**
* @deprecated
* Use maximumWidth() instead.
* Returns the value that was set with @ref setMaxWidth().
*/
int maxWidth();
/**
* Set title for toolbar when it floats.
*
* Titles are however not (yet)
* visible. You can't change toolbar's title while it's floating.
*/
void setTitle (const QString& _title);
/**
* @deprecated
* Use enableMoving() instead.
*/
void enableFloating (bool arrrrrrgh);
/**
* Set the kind of painting for buttons.
*
* Choose from:
* @li IconOnly (only icons),
* @li IconTextRight (icon and text, text is left from icons),
* @li TextOnly (only text),
* @li IconTextBottom (icons and text, text is under icons).
* @see IconText
*
*/
void setIconText(IconText it);
// Note: don't merge with the next one, it breaks Qt properties
/**
* Similar to @ref setIconText(IconText it) but allows you to
* disable or enable updating. If @p update is false, then the
* buttons will not be updated. This is useful only if you know
* that you will be forcing an update later.
*/
void setIconText(IconText it, bool update);
/**
* @return The current text style for buttons.
*/
IconText iconText() const;
/**
* Set the icon size to load. Usually you should not call
* this, the icon size is taken care of by KIconLoader
* and globally configured.
* By default, the toolbar will load icons of size 32 for main
* toolbars and 22 for other toolbars
* @see KIconLoader.
*
* @param size The size to use
*/
void setIconSize(int size);
// Note: don't merge with the next one, it breaks Qt properties
/**
* Same as @ref setIconText(int size) but allows you
* to disable the toolbar update.
*
* @param size The size to use
* @param update If true, then the toolbar will be updated after
* this
*/
void setIconSize(int size, bool update);
/**
* @return The current icon size for buttons.
*/
int iconSize() const;
/**
* This allows you to enable or disable the context menu.
*
* @param enable If false, then the context menu will be disabled
*/
void setEnableContextMenu(bool enable = true);
/**
* Returns whether or not the context menu is disabled
*
* @return The context menu state
*/
bool contextMenuEnabled() const;
/**
* This will inform a toolbar button to ignore certain style
* changes. Specifically, it will ignore IconText (always IconOnly)
* and will not allow image effects to apply.
*
* @param id The button to exclude from styles
* @param no_style If true, then it is excluded (default: true).
*/
void setItemNoStyle(int id, bool no_style = true);
void setFlat (bool flag);
/**
* @return the number of items in the toolbar
*/
int count() const;
/**
* Instruct the toolbar to save it's current state to either the app
* config file or to the XML-GUI resource file (whichever has
* precedence).
*/
void saveState();
/**
* Save the toolbar settings to group @p configGroup in @p config.
*/
void saveSettings(KConfig *config, const QString &configGroup);
/**
* Read the toolbar settings from group @p configGroup in @p config
* and apply them.
*/
void applySettings(KConfig *config, const QString &configGroup);
/**
* Tell the toolbar what XML-GUI resource file it should use to save
* it's state. The state of the toolbar (position, size, etc) is
* saved in KConfig files if the application does not use XML-GUI..
* but if the app does, then it's saved the XML file. This function
* allows this to happen.
*
* @param xmlfile The XML-GUI resource file to write to
* @param xml The DOM document for the XML-GUI building
*/
// void setXML(const QString& xmlfile, const QDomDocument& xml);
/* @internal */
void setXMLGUIClient( KXMLGUIClient *client );
/**
* Assign a (translated) text to this toolbar. This is used
* for the tooltip on the handle, and when listing the toolbars.
*/
void setText( const QString & txt );
/**
* @return the toolbar's text.
*/
QString text() const;
void setStretchableWidget( QWidget *w );
QSizePolicy sizePolicy() const;
bool highlight() const;
QSize sizeHint() const;
QSize minimumSizeHint() const;
QSize minimumSize() const;
void hide();
void show();
void updateRects( bool = FALSE ) {}
//US void loadState( const QDomElement &e );
//US void saveState( QDomElement &e );
/**
* @internal
*/
void positionYourself( bool force = false);
signals:
/**
* Emitted when button @p id is clicked.
*/
void clicked(int id);
/**
* Emitted when button @p id is double-clicked.
*
* Note: you will always
* recive two @ref clicked() , @ref pressed() and @ref released() signals.
* There is no way to avoid it - at least no easy way.
* If you need to resolve this all you can do is set up timers
* which wait for @ref QApplication::doubleClickInterval() to expire.
* If in that time you don't get this signal, you may belive that
* button was only clicked and not double-clicked.
* And please note that butons with popup menus do not emit this signal,
* but those with delayed popup do.
*/
void doubleClicked (int id);
/**
* Emitted when button @p id is pressed.
*/
void pressed(int);
/**
* Emits when button @p id is released.
*/
void released(int);
/**
* Emitted when a toggle button changes state.
*
* Emitted also if you change state
* with @ref setButton() or @ref toggleButton()
* If you make a button normal again, with
* setToggle(false), this signal won't
* be emitted.
*/
void toggled(int);
/**
* This signal is emitted when item id gets highlighted/unhighlighted
* (i.e when mouse enters/exits).
*
* Note that this signal is emitted from
* all buttons (normal, disabled and toggle) even when there is no visible
* change in buttons (i.e., buttons do not raise when mouse enters).
* The parameter @p isHighlighted is @p true when mouse enters and @p false when
* mouse exits.
*/
void highlighted(int id, bool isHighlighted);
/**
* This signal is emitted when item id gets highlighted/unhighlighted
* (i.e when mouse enters/exits).
*
* Note that this signal is emitted from
* all buttons (normal, disabled and toggle) even when there is no visible
* change in buttons (i.e., buttons do not raise when mouse enters).
*/
void highlighted(int id );
/**
* Emitted when toolbar changes position, or when
* an item is removed from toolbar.
*
* If you subclass @ref KMainWindow and reimplement
* @ref KMainWindow::resizeEvent() be sure to connect to
* this signal. Note: You can connect this signal to a slot that
* doesn't take parameter.
*/
void moved( BarPosition );
/**
* @internal
* This signal is emitted when toolbar detects changing of
* following parameters:
* highlighting, button-size, button-mode. This signal is
* internal, aimed to buttons.
*/
void modechange ();
/**
* This signal is emitted when the toolbar is getting deleted,
* and before ~KToolbar finishes (so it's still time to remove
* widgets from the toolbar).
* Used by KWidgetAction.
* @since 3.2
*/
void toolbarDestroyed();
public:
/**
* @return global setting for "Highlight buttons under mouse"
*/
void repaintMe();
static bool highlightSetting();
/**
* @return global setting for "Toolbars transparent when moving"
*/
static bool transparentSetting();
/**
* @return global setting for "Icon Text"
*/
static IconText iconTextSetting();
public slots:
virtual void setIconText( const QString &txt )
{ QToolBar::setIconText( txt ); }
void slotRepaint();
protected:
void mousePressEvent( QMouseEvent * );
void childEvent( QChildEvent *e );
void showEvent( QShowEvent *e );
void resizeEvent( QResizeEvent *e );
bool event( QEvent *e );
void applyAppearanceSettings(KConfig *config, const QString &_configGroup, bool forceGlobal = false);
QString settingsGroup();
private slots:
void rebuildLayout();
void slotReadConfig ();
void slotAppearanceChanged();
void slotIconChanged(int);
void toolBarPosChanged( QToolBar *tb );
void slotContextAboutToShow();
void widgetDestroyed();
private:
void init( bool readConfig = true, bool honorStyle = false );
void doConnections( KToolBarButton *button );
void insertWidgetInternal( QWidget *w, int &index, int id );
void removeWidgetInternal( QWidget *w );
void getAttributes( QString &position, QString &icontext, int &index );
//US KPopupMenu *contextMenu();
QPopupMenu *contextMenu();
QMap<QWidget*, int > widget2id;
typedef QMap<int, QWidget* > Id2WidgetMap;
Id2WidgetMap id2widget;
//US KPopupMenu *context;
QPopupMenu *context;
QPtrList<QWidget> widgets;
QTimer *layoutTimer;
QGuardedPtr<QWidget> stretchableWidget, rightAligned;
protected:
virtual void virtual_hook( int id, void* data );
private:
KToolBarPrivate *d;
bool inshutdownprocess;
};
#endif