You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
2422 lines
67 KiB
2422 lines
67 KiB
15 years ago
|
/* This file is part of the KDE libraries
|
||
|
Copyright (C) 1999 Reginald Stadlbauer <reggie@kde.org>
|
||
|
(C) 1999 Simon Hausmann <hausmann@kde.org>
|
||
|
(C) 2000 Nicolas Hadacek <haadcek@kde.org>
|
||
|
(C) 2000 Kurt Granroth <granroth@kde.org>
|
||
|
(C) 2000 Michael Koch <koch@kde.org>
|
||
|
(C) 2001 Holger Freyther <freyther@kde.org>
|
||
|
(C) 2002 Ellis Whitehead <ellis@kde.org>
|
||
|
(C) 2002 Joseph Wenninger <jowenn@kde.org>
|
||
|
(C) 2003 Andras Mantia <amantia@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., 51 Franklin Street, Fifth Floor,
|
||
|
Boston, MA 02110-1301, USA.
|
||
|
*/
|
||
|
|
||
|
#include "kactionclasses.h"
|
||
|
|
||
|
#include <assert.h>
|
||
14 years ago
|
#include <ft2build.h>
|
||
|
#include <fontconfig/fontconfig.h>
|
||
15 years ago
|
|
||
15 years ago
|
#include <tqcursor.h>
|
||
|
#include <tqclipboard.h>
|
||
|
#include <tqfontdatabase.h>
|
||
|
#include <tqobjectlist.h>
|
||
|
#include <tqwhatsthis.h>
|
||
|
#include <tqtimer.h>
|
||
|
#include <tqfile.h>
|
||
14 years ago
|
#include <tqregexp.h>
|
||
15 years ago
|
|
||
|
#include <dcopclient.h>
|
||
|
#include <dcopref.h>
|
||
|
#include <kaccel.h>
|
||
|
#include <kapplication.h>
|
||
|
#include <kconfig.h>
|
||
|
#include <kdebug.h>
|
||
|
#include <kfontcombo.h>
|
||
|
#include <kfontdialog.h>
|
||
|
#include <klocale.h>
|
||
|
#include <kmainwindow.h>
|
||
|
#include <kmenubar.h>
|
||
|
#include <kpopupmenu.h>
|
||
|
#include <ktoolbar.h>
|
||
|
#include <ktoolbarbutton.h>
|
||
|
#include <kurl.h>
|
||
|
#include <kstandarddirs.h>
|
||
|
#include <kstringhandler.h>
|
||
|
|
||
|
class KToggleAction::KToggleActionPrivate
|
||
|
{
|
||
|
public:
|
||
|
KToggleActionPrivate()
|
||
|
{
|
||
|
m_checked = false;
|
||
|
m_checkedGuiItem = 0;
|
||
|
}
|
||
|
|
||
|
bool m_checked;
|
||
15 years ago
|
TQString m_exclusiveGroup;
|
||
15 years ago
|
KGuiItem* m_checkedGuiItem;
|
||
|
};
|
||
|
|
||
15 years ago
|
KToggleAction::KToggleAction( const TQString& text, const KShortcut& cut,
|
||
|
TQObject* parent,
|
||
15 years ago
|
const char* name )
|
||
|
: KAction( text, cut, parent, name )
|
||
|
{
|
||
|
d = new KToggleActionPrivate;
|
||
|
}
|
||
|
|
||
15 years ago
|
KToggleAction::KToggleAction( const TQString& text, const KShortcut& cut,
|
||
|
const TQObject* receiver, const char* slot,
|
||
|
TQObject* parent, const char* name )
|
||
15 years ago
|
: KAction( text, cut, receiver, slot, parent, name )
|
||
|
{
|
||
|
d = new KToggleActionPrivate;
|
||
|
}
|
||
|
|
||
15 years ago
|
KToggleAction::KToggleAction( const TQString& text, const TQIconSet& pix,
|
||
15 years ago
|
const KShortcut& cut,
|
||
15 years ago
|
TQObject* parent, const char* name )
|
||
15 years ago
|
: KAction( text, pix, cut, parent, name )
|
||
|
{
|
||
|
d = new KToggleActionPrivate;
|
||
|
}
|
||
|
|
||
15 years ago
|
KToggleAction::KToggleAction( const TQString& text, const TQString& pix,
|
||
15 years ago
|
const KShortcut& cut,
|
||
15 years ago
|
TQObject* parent, const char* name )
|
||
15 years ago
|
: KAction( text, pix, cut, parent, name )
|
||
|
{
|
||
|
d = new KToggleActionPrivate;
|
||
|
}
|
||
|
|
||
15 years ago
|
KToggleAction::KToggleAction( const TQString& text, const TQIconSet& pix,
|
||
15 years ago
|
const KShortcut& cut,
|
||
15 years ago
|
const TQObject* receiver,
|
||
|
const char* slot, TQObject* parent,
|
||
15 years ago
|
const char* name )
|
||
|
: KAction( text, pix, cut, receiver, slot, parent, name )
|
||
|
{
|
||
|
d = new KToggleActionPrivate;
|
||
|
}
|
||
|
|
||
15 years ago
|
KToggleAction::KToggleAction( const TQString& text, const TQString& pix,
|
||
15 years ago
|
const KShortcut& cut,
|
||
15 years ago
|
const TQObject* receiver,
|
||
|
const char* slot, TQObject* parent,
|
||
15 years ago
|
const char* name )
|
||
|
: KAction( text, pix, cut, receiver, slot, parent, name )
|
||
|
{
|
||
|
d = new KToggleActionPrivate;
|
||
|
}
|
||
|
|
||
15 years ago
|
KToggleAction::KToggleAction( TQObject* parent, const char* name )
|
||
15 years ago
|
: KAction( parent, name )
|
||
|
{
|
||
|
d = new KToggleActionPrivate;
|
||
|
}
|
||
|
|
||
|
KToggleAction::~KToggleAction()
|
||
|
{
|
||
|
delete d->m_checkedGuiItem;
|
||
|
delete d;
|
||
|
}
|
||
|
|
||
15 years ago
|
int KToggleAction::plug( TQWidget* widget, int index )
|
||
15 years ago
|
{
|
||
14 years ago
|
if ( !::tqqt_cast<TQPopupMenu *>( widget ) && !::tqqt_cast<KToolBar *>( widget ) )
|
||
15 years ago
|
{
|
||
|
kdWarning() << "Can not plug KToggleAction in " << widget->className() << endl;
|
||
|
return -1;
|
||
|
}
|
||
|
if (kapp && !kapp->authorizeKAction(name()))
|
||
|
return -1;
|
||
|
|
||
|
int _index = KAction::plug( widget, index );
|
||
|
if ( _index == -1 )
|
||
|
return _index;
|
||
|
|
||
14 years ago
|
if ( ::tqqt_cast<KToolBar *>( widget ) ) {
|
||
15 years ago
|
KToolBar *bar = static_cast<KToolBar *>( widget );
|
||
|
|
||
|
bar->setToggle( itemId( _index ), true );
|
||
|
bar->setButton( itemId( _index ), isChecked() );
|
||
|
}
|
||
|
|
||
|
if ( d->m_checked )
|
||
|
updateChecked( _index );
|
||
|
|
||
|
return _index;
|
||
|
}
|
||
|
|
||
|
void KToggleAction::setChecked( bool c )
|
||
|
{
|
||
|
if ( c == d->m_checked )
|
||
|
return;
|
||
|
//kdDebug(129) << "KToggleAction::setChecked(" << c << ") " << this << " " << name() << endl;
|
||
|
|
||
|
d->m_checked = c;
|
||
|
|
||
|
int len = containerCount();
|
||
|
|
||
|
for( int i = 0; i < len; ++i )
|
||
|
updateChecked( i );
|
||
|
|
||
|
if ( c && parent() && !exclusiveGroup().isEmpty() ) {
|
||
13 years ago
|
const TQObjectList list = parent()->childrenListObject();
|
||
14 years ago
|
if ( !list.isEmpty() ) {
|
||
|
TQObjectListIt it( list );
|
||
15 years ago
|
for( ; it.current(); ++it ) {
|
||
14 years ago
|
if ( ::tqqt_cast<KToggleAction *>( it.current() ) && it.current() != this &&
|
||
15 years ago
|
static_cast<KToggleAction*>(it.current())->exclusiveGroup() == exclusiveGroup() ) {
|
||
|
KToggleAction *a = static_cast<KToggleAction*>(it.current());
|
||
|
if( a->isChecked() ) {
|
||
|
a->setChecked( false );
|
||
|
emit a->toggled( false );
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void KToggleAction::updateChecked( int id )
|
||
|
{
|
||
15 years ago
|
TQWidget *w = container( id );
|
||
15 years ago
|
|
||
14 years ago
|
if ( ::tqqt_cast<TQPopupMenu *>( w ) ) {
|
||
15 years ago
|
TQPopupMenu* pm = static_cast<TQPopupMenu*>(w);
|
||
15 years ago
|
int itemId_ = itemId( id );
|
||
|
if ( !d->m_checkedGuiItem )
|
||
|
pm->setItemChecked( itemId_, d->m_checked );
|
||
|
else {
|
||
|
const KGuiItem* gui = d->m_checked ? d->m_checkedGuiItem : &guiItem();
|
||
|
if ( d->m_checkedGuiItem->hasIcon() )
|
||
|
pm->changeItem( itemId_, gui->iconSet( KIcon::Small ), gui->text() );
|
||
|
else
|
||
|
pm->changeItem( itemId_, gui->text() );
|
||
|
|
||
|
// If the text doesn't change, then set the icon to be "pressed", otherwise
|
||
|
// there is too little difference between checked and unchecked.
|
||
|
if ( d->m_checkedGuiItem->text() == guiItem().text() )
|
||
|
pm->setItemChecked( itemId_, d->m_checked );
|
||
|
|
||
|
if ( !d->m_checkedGuiItem->whatsThis().isEmpty() ) // if empty, we keep the initial one
|
||
14 years ago
|
pm->TQMenuData::setWhatsThis( itemId_, gui->whatsThis() );
|
||
15 years ago
|
updateShortcut( pm, itemId_ );
|
||
|
}
|
||
|
}
|
||
14 years ago
|
else if ( ::tqqt_cast<TQMenuBar *>( w ) ) // not handled in plug...
|
||
15 years ago
|
static_cast<TQMenuBar*>(w)->setItemChecked( itemId( id ), d->m_checked );
|
||
14 years ago
|
else if ( ::tqqt_cast<KToolBar *>( w ) )
|
||
15 years ago
|
{
|
||
15 years ago
|
TQWidget* r = static_cast<KToolBar*>( w )->getButton( itemId( id ) );
|
||
14 years ago
|
if ( r && ::tqqt_cast<KToolBarButton *>( r ) ) {
|
||
15 years ago
|
static_cast<KToolBar*>( w )->setButton( itemId( id ), d->m_checked );
|
||
|
if ( d->m_checkedGuiItem && d->m_checkedGuiItem->hasIcon() ) {
|
||
|
const KGuiItem* gui = d->m_checked ? d->m_checkedGuiItem : &guiItem();
|
||
|
static_cast<KToolBar*>( w )->setButtonIconSet( itemId( id ), gui->iconSet( KIcon::Toolbar ) );
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void KToggleAction::slotActivated()
|
||
|
{
|
||
|
setChecked( !isChecked() );
|
||
|
KAction::slotActivated();
|
||
|
emit toggled( isChecked() );
|
||
|
}
|
||
|
|
||
|
bool KToggleAction::isChecked() const
|
||
|
{
|
||
|
return d->m_checked;
|
||
|
}
|
||
|
|
||
15 years ago
|
void KToggleAction::setExclusiveGroup( const TQString& name )
|
||
15 years ago
|
{
|
||
|
d->m_exclusiveGroup = name;
|
||
|
}
|
||
|
|
||
15 years ago
|
TQString KToggleAction::exclusiveGroup() const
|
||
15 years ago
|
{
|
||
|
return d->m_exclusiveGroup;
|
||
|
}
|
||
|
|
||
|
void KToggleAction::setCheckedState( const KGuiItem& checkedItem )
|
||
|
{
|
||
|
delete d->m_checkedGuiItem;
|
||
|
d->m_checkedGuiItem = new KGuiItem( checkedItem );
|
||
|
}
|
||
|
|
||
15 years ago
|
TQString KToggleAction::toolTip() const
|
||
15 years ago
|
{
|
||
|
if ( d->m_checkedGuiItem && d->m_checked )
|
||
|
return d->m_checkedGuiItem->toolTip();
|
||
|
else
|
||
|
return KAction::toolTip();
|
||
|
}
|
||
|
|
||
15 years ago
|
KRadioAction::KRadioAction( const TQString& text, const KShortcut& cut,
|
||
|
TQObject* parent, const char* name )
|
||
15 years ago
|
: KToggleAction( text, cut, parent, name )
|
||
|
{
|
||
|
}
|
||
|
|
||
15 years ago
|
KRadioAction::KRadioAction( const TQString& text, const KShortcut& cut,
|
||
|
const TQObject* receiver, const char* slot,
|
||
|
TQObject* parent, const char* name )
|
||
15 years ago
|
: KToggleAction( text, cut, receiver, slot, parent, name )
|
||
|
{
|
||
|
}
|
||
|
|
||
15 years ago
|
KRadioAction::KRadioAction( const TQString& text, const TQIconSet& pix,
|
||
15 years ago
|
const KShortcut& cut,
|
||
15 years ago
|
TQObject* parent, const char* name )
|
||
15 years ago
|
: KToggleAction( text, pix, cut, parent, name )
|
||
|
{
|
||
|
}
|
||
|
|
||
15 years ago
|
KRadioAction::KRadioAction( const TQString& text, const TQString& pix,
|
||
15 years ago
|
const KShortcut& cut,
|
||
15 years ago
|
TQObject* parent, const char* name )
|
||
15 years ago
|
: KToggleAction( text, pix, cut, parent, name )
|
||
|
{
|
||
|
}
|
||
|
|
||
15 years ago
|
KRadioAction::KRadioAction( const TQString& text, const TQIconSet& pix,
|
||
15 years ago
|
const KShortcut& cut,
|
||
15 years ago
|
const TQObject* receiver, const char* slot,
|
||
|
TQObject* parent, const char* name )
|
||
15 years ago
|
: KToggleAction( text, pix, cut, receiver, slot, parent, name )
|
||
|
{
|
||
|
}
|
||
|
|
||
15 years ago
|
KRadioAction::KRadioAction( const TQString& text, const TQString& pix,
|
||
15 years ago
|
const KShortcut& cut,
|
||
15 years ago
|
const TQObject* receiver, const char* slot,
|
||
|
TQObject* parent, const char* name )
|
||
15 years ago
|
: KToggleAction( text, pix, cut, receiver, slot, parent, name )
|
||
|
{
|
||
|
}
|
||
|
|
||
15 years ago
|
KRadioAction::KRadioAction( TQObject* parent, const char* name )
|
||
15 years ago
|
: KToggleAction( parent, name )
|
||
|
{
|
||
|
}
|
||
|
|
||
|
void KRadioAction::slotActivated()
|
||
|
{
|
||
|
if ( isChecked() )
|
||
|
{
|
||
14 years ago
|
const TQObject *senderObj = TQT_TQOBJECT_CONST(sender());
|
||
15 years ago
|
|
||
14 years ago
|
if ( !senderObj || !::tqqt_cast<const KToolBarButton *>( senderObj ) )
|
||
15 years ago
|
return;
|
||
|
|
||
14 years ago
|
const_cast<KToolBarButton *>( static_cast<const KToolBarButton *>( TQT_TQWIDGET_CONST(senderObj) ) )->on( true );
|
||
15 years ago
|
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
KToggleAction::slotActivated();
|
||
|
}
|
||
|
|
||
|
class KSelectAction::KSelectActionPrivate
|
||
|
{
|
||
|
public:
|
||
|
KSelectActionPrivate()
|
||
|
{
|
||
|
m_edit = false;
|
||
|
m_menuAccelsEnabled = true;
|
||
|
m_menu = 0;
|
||
|
m_current = -1;
|
||
|
m_comboWidth = -1;
|
||
|
m_maxComboViewCount = -1;
|
||
|
}
|
||
|
bool m_edit;
|
||
|
bool m_menuAccelsEnabled;
|
||
15 years ago
|
TQPopupMenu *m_menu;
|
||
15 years ago
|
int m_current;
|
||
|
int m_comboWidth;
|
||
15 years ago
|
TQStringList m_list;
|
||
15 years ago
|
int m_maxComboViewCount;
|
||
|
|
||
15 years ago
|
TQString makeMenuText( const TQString &_text )
|
||
15 years ago
|
{
|
||
|
if ( m_menuAccelsEnabled )
|
||
|
return _text;
|
||
15 years ago
|
TQString text = _text;
|
||
15 years ago
|
uint i = 0;
|
||
|
while ( i < text.length() ) {
|
||
|
if ( text[ i ] == '&' ) {
|
||
|
text.insert( i, '&' );
|
||
|
i += 2;
|
||
|
}
|
||
|
else
|
||
|
++i;
|
||
|
}
|
||
|
return text;
|
||
|
}
|
||
|
};
|
||
|
|
||
15 years ago
|
KSelectAction::KSelectAction( const TQString& text, const KShortcut& cut,
|
||
|
TQObject* parent, const char* name )
|
||
15 years ago
|
: KAction( text, cut, parent, name )
|
||
|
{
|
||
|
d = new KSelectActionPrivate;
|
||
|
}
|
||
|
|
||
15 years ago
|
KSelectAction::KSelectAction( const TQString& text, const KShortcut& cut,
|
||
|
const TQObject* receiver, const char* slot,
|
||
|
TQObject* parent, const char* name )
|
||
15 years ago
|
: KAction( text, cut, receiver, slot, parent, name )
|
||
|
{
|
||
|
d = new KSelectActionPrivate;
|
||
|
}
|
||
|
|
||
15 years ago
|
KSelectAction::KSelectAction( const TQString& text, const TQIconSet& pix,
|
||
15 years ago
|
const KShortcut& cut,
|
||
15 years ago
|
TQObject* parent, const char* name )
|
||
15 years ago
|
: KAction( text, pix, cut, parent, name )
|
||
|
{
|
||
|
d = new KSelectActionPrivate;
|
||
|
}
|
||
|
|
||
15 years ago
|
KSelectAction::KSelectAction( const TQString& text, const TQString& pix,
|
||
15 years ago
|
const KShortcut& cut,
|
||
15 years ago
|
TQObject* parent, const char* name )
|
||
15 years ago
|
: KAction( text, pix, cut, parent, name )
|
||
|
{
|
||
|
d = new KSelectActionPrivate;
|
||
|
}
|
||
|
|
||
15 years ago
|
KSelectAction::KSelectAction( const TQString& text, const TQIconSet& pix,
|
||
15 years ago
|
const KShortcut& cut,
|
||
15 years ago
|
const TQObject* receiver,
|
||
|
const char* slot, TQObject* parent,
|
||
15 years ago
|
const char* name )
|
||
|
: KAction( text, pix, cut, receiver, slot, parent, name )
|
||
|
{
|
||
|
d = new KSelectActionPrivate;
|
||
|
}
|
||
|
|
||
15 years ago
|
KSelectAction::KSelectAction( const TQString& text, const TQString& pix,
|
||
15 years ago
|
const KShortcut& cut,
|
||
15 years ago
|
const TQObject* receiver,
|
||
|
const char* slot, TQObject* parent,
|
||
15 years ago
|
const char* name )
|
||
|
: KAction( text, pix, cut, receiver, slot, parent, name )
|
||
|
{
|
||
|
d = new KSelectActionPrivate;
|
||
|
}
|
||
|
|
||
15 years ago
|
KSelectAction::KSelectAction( TQObject* parent, const char* name )
|
||
15 years ago
|
: KAction( parent, name )
|
||
|
{
|
||
|
d = new KSelectActionPrivate;
|
||
|
}
|
||
|
|
||
|
KSelectAction::~KSelectAction()
|
||
|
{
|
||
|
assert(d);
|
||
|
delete d->m_menu;
|
||
|
delete d; d = 0;
|
||
|
}
|
||
|
|
||
|
void KSelectAction::setCurrentItem( int id )
|
||
|
{
|
||
|
if ( id >= (int)d->m_list.count() ) {
|
||
|
Q_ASSERT(id < (int)d->m_list.count());
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
if ( d->m_menu )
|
||
|
{
|
||
|
if ( d->m_current >= 0 )
|
||
|
d->m_menu->setItemChecked( d->m_current, false );
|
||
|
if ( id >= 0 )
|
||
|
d->m_menu->setItemChecked( id, true );
|
||
|
}
|
||
|
|
||
|
d->m_current = id;
|
||
|
|
||
|
int len = containerCount();
|
||
|
|
||
|
for( int i = 0; i < len; ++i )
|
||
|
updateCurrentItem( i );
|
||
|
|
||
|
// emit KAction::activated();
|
||
|
// emit activated( currentItem() );
|
||
|
// emit activated( currentText() );
|
||
|
}
|
||
|
|
||
|
void KSelectAction::setComboWidth( int width )
|
||
|
{
|
||
|
if ( width < 0 )
|
||
|
return;
|
||
|
|
||
|
d->m_comboWidth=width;
|
||
|
|
||
|
int len = containerCount();
|
||
|
|
||
|
for( int i = 0; i < len; ++i )
|
||
|
updateComboWidth( i );
|
||
|
|
||
|
}
|
||
|
|
||
|
void KSelectAction::setMaxComboViewCount( int n )
|
||
|
{
|
||
|
d->m_maxComboViewCount = n;
|
||
|
}
|
||
|
|
||
15 years ago
|
TQPopupMenu* KSelectAction::popupMenu() const
|
||
15 years ago
|
{
|
||
|
kdDebug(129) << "KAction::popupMenu()" << endl; // remove -- ellis
|
||
|
if ( !d->m_menu )
|
||
|
{
|
||
|
d->m_menu = new KPopupMenu(0L, "KSelectAction::popupMenu()");
|
||
|
setupMenu();
|
||
|
if ( d->m_current >= 0 )
|
||
|
d->m_menu->setItemChecked( d->m_current, true );
|
||
|
}
|
||
|
|
||
|
return d->m_menu;
|
||
|
}
|
||
|
|
||
|
void KSelectAction::setupMenu() const
|
||
|
{
|
||
|
if ( !d->m_menu )
|
||
|
return;
|
||
|
d->m_menu->clear();
|
||
|
|
||
15 years ago
|
TQStringList::ConstIterator it = d->m_list.begin();
|
||
15 years ago
|
for( uint id = 0; it != d->m_list.end(); ++it, ++id ) {
|
||
15 years ago
|
TQString text = *it;
|
||
15 years ago
|
if ( !text.isEmpty() )
|
||
15 years ago
|
d->m_menu->insertItem( d->makeMenuText( text ), this, TQT_SLOT( slotActivated( int ) ), 0, id );
|
||
15 years ago
|
else
|
||
|
d->m_menu->insertSeparator();
|
||
|
}
|
||
|
}
|
||
|
|
||
15 years ago
|
void KSelectAction::changeItem( int index, const TQString& text )
|
||
15 years ago
|
{
|
||
|
if ( index < 0 || index >= (int)d->m_list.count() )
|
||
|
{
|
||
|
kdWarning() << "KSelectAction::changeItem Index out of scope" << endl;
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
d->m_list[ index ] = text;
|
||
|
|
||
|
if ( d->m_menu )
|
||
|
d->m_menu->changeItem( index, d->makeMenuText( text ) );
|
||
|
|
||
|
int len = containerCount();
|
||
|
for( int i = 0; i < len; ++i )
|
||
|
changeItem( i, index, text );
|
||
|
}
|
||
|
|
||
15 years ago
|
void KSelectAction::changeItem( int id, int index, const TQString& text)
|
||
15 years ago
|
{
|
||
|
if ( index < 0 )
|
||
|
return;
|
||
|
|
||
15 years ago
|
TQWidget* w = container( id );
|
||
14 years ago
|
if ( ::tqqt_cast<KToolBar *>( w ) )
|
||
15 years ago
|
{
|
||
15 years ago
|
TQWidget* r = (static_cast<KToolBar*>( w ))->getWidget( itemId( id ) );
|
||
14 years ago
|
if ( ::tqqt_cast<TQComboBox *>( r ) )
|
||
15 years ago
|
{
|
||
15 years ago
|
TQComboBox *b = static_cast<TQComboBox*>( r );
|
||
15 years ago
|
b->changeItem(text, index );
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
15 years ago
|
void KSelectAction::setItems( const TQStringList &lst )
|
||
15 years ago
|
{
|
||
|
d->m_list = lst;
|
||
|
d->m_current = -1;
|
||
|
|
||
|
setupMenu();
|
||
|
|
||
|
int len = containerCount();
|
||
|
for( int i = 0; i < len; ++i )
|
||
|
updateItems( i );
|
||
|
|
||
|
// Disable if empty and not editable
|
||
|
setEnabled ( lst.count() > 0 || d->m_edit );
|
||
|
}
|
||
|
|
||
15 years ago
|
TQStringList KSelectAction::items() const
|
||
15 years ago
|
{
|
||
|
return d->m_list;
|
||
|
}
|
||
|
|
||
15 years ago
|
TQString KSelectAction::currentText() const
|
||
15 years ago
|
{
|
||
|
if ( currentItem() < 0 )
|
||
15 years ago
|
return TQString::null;
|
||
15 years ago
|
|
||
|
return d->m_list[ currentItem() ];
|
||
|
}
|
||
|
|
||
|
int KSelectAction::currentItem() const
|
||
|
{
|
||
|
return d->m_current;
|
||
|
}
|
||
|
|
||
|
void KSelectAction::updateCurrentItem( int id )
|
||
|
{
|
||
|
if ( d->m_current < 0 )
|
||
|
return;
|
||
|
|
||
15 years ago
|
TQWidget* w = container( id );
|
||
14 years ago
|
if ( ::tqqt_cast<KToolBar *>( w ) ) {
|
||
15 years ago
|
TQWidget* r = static_cast<KToolBar*>( w )->getWidget( itemId( id ) );
|
||
14 years ago
|
if ( ::tqqt_cast<TQComboBox *>( r ) ) {
|
||
15 years ago
|
TQComboBox *b = static_cast<TQComboBox*>( r );
|
||
15 years ago
|
b->setCurrentItem( d->m_current );
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
int KSelectAction::comboWidth() const
|
||
|
{
|
||
|
return d->m_comboWidth;
|
||
|
}
|
||
|
|
||
|
void KSelectAction::updateComboWidth( int id )
|
||
|
{
|
||
15 years ago
|
TQWidget* w = container( id );
|
||
14 years ago
|
if ( ::tqqt_cast<KToolBar *>( w ) ) {
|
||
15 years ago
|
TQWidget* r = static_cast<KToolBar*>( w )->getWidget( itemId( id ) );
|
||
14 years ago
|
if ( ::tqqt_cast<TQComboBox *>( r ) ) {
|
||
15 years ago
|
TQComboBox *cb = static_cast<TQComboBox*>( r );
|
||
15 years ago
|
cb->setMinimumWidth( d->m_comboWidth );
|
||
|
cb->setMaximumWidth( d->m_comboWidth );
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void KSelectAction::updateItems( int id )
|
||
|
{
|
||
|
kdDebug(129) << "KAction::updateItems( " << id << ", lst )" << endl; // remove -- ellis
|
||
15 years ago
|
TQWidget* w = container( id );
|
||
14 years ago
|
if ( ::tqqt_cast<KToolBar *>( w ) ) {
|
||
15 years ago
|
TQWidget* r = static_cast<KToolBar*>( w )->getWidget( itemId( id ) );
|
||
14 years ago
|
if ( ::tqqt_cast<TQComboBox *>( r ) ) {
|
||
15 years ago
|
TQComboBox *cb = static_cast<TQComboBox*>( r );
|
||
15 years ago
|
cb->clear();
|
||
15 years ago
|
TQStringList lst = comboItems();
|
||
|
TQStringList::ConstIterator it = lst.begin();
|
||
15 years ago
|
for( ; it != lst.end(); ++it )
|
||
|
cb->insertItem( *it );
|
||
14 years ago
|
// qt caches and never recalculates the tqsizeHint()
|
||
|
// qcombobox.cpp recommends calling setFont to tqinvalidate the tqsizeHint
|
||
15 years ago
|
// setFont sets own_font = True, so we're a bit mean and calll
|
||
|
// unsetFont which calls setFont and then overwrites the own_font
|
||
|
cb->unsetFont();
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
15 years ago
|
int KSelectAction::plug( TQWidget *widget, int index )
|
||
15 years ago
|
{
|
||
|
if (kapp && !kapp->authorizeKAction(name()))
|
||
|
return -1;
|
||
|
kdDebug(129) << "KSelectAction::plug( " << widget << ", " << index << " )" << endl; // remove -- ellis
|
||
14 years ago
|
if ( ::tqqt_cast<TQPopupMenu *>( widget) )
|
||
15 years ago
|
{
|
||
|
// Create the PopupMenu and store it in m_menu
|
||
|
(void)popupMenu();
|
||
|
|
||
15 years ago
|
TQPopupMenu* menu = static_cast<TQPopupMenu*>( widget );
|
||
15 years ago
|
int id;
|
||
|
if ( hasIcon() )
|
||
|
id = menu->insertItem( iconSet(), text(), d->m_menu, -1, index );
|
||
|
else
|
||
|
id = menu->insertItem( text(), d->m_menu, -1, index );
|
||
|
|
||
|
if ( !isEnabled() )
|
||
|
menu->setItemEnabled( id, false );
|
||
|
|
||
15 years ago
|
TQString wth = whatsThis();
|
||
15 years ago
|
if ( !wth.isEmpty() )
|
||
14 years ago
|
menu->TQMenuData::setWhatsThis( id, wth );
|
||
15 years ago
|
|
||
|
addContainer( menu, id );
|
||
15 years ago
|
connect( menu, TQT_SIGNAL( destroyed() ), this, TQT_SLOT( slotDestroyed() ) );
|
||
15 years ago
|
|
||
|
return containerCount() - 1;
|
||
|
}
|
||
14 years ago
|
else if ( ::tqqt_cast<KToolBar *>( widget ) )
|
||
15 years ago
|
{
|
||
|
KToolBar* bar = static_cast<KToolBar*>( widget );
|
||
|
int id_ = KAction::getToolButtonID();
|
||
|
bar->insertCombo( comboItems(), id_, isEditable(),
|
||
15 years ago
|
TQT_SIGNAL( activated( const TQString & ) ), this,
|
||
|
TQT_SLOT( slotActivated( const TQString & ) ), isEnabled(),
|
||
15 years ago
|
toolTip(), -1, index );
|
||
|
|
||
15 years ago
|
TQComboBox *cb = bar->getCombo( id_ );
|
||
15 years ago
|
if ( cb )
|
||
|
{
|
||
14 years ago
|
if (!isEditable()) cb->setFocusPolicy(TQ_NoFocus);
|
||
|
cb->setMinimumWidth( cb->tqsizeHint().width() );
|
||
15 years ago
|
if ( d->m_comboWidth > 0 )
|
||
|
{
|
||
|
cb->setMinimumWidth( d->m_comboWidth );
|
||
|
cb->setMaximumWidth( d->m_comboWidth );
|
||
|
}
|
||
15 years ago
|
cb->setInsertionPolicy( TQComboBox::NoInsertion );
|
||
|
TQWhatsThis::add( cb, whatsThis() );
|
||
15 years ago
|
if ( d->m_maxComboViewCount != -1 ) cb->setSizeLimit( d->m_maxComboViewCount );
|
||
|
}
|
||
|
|
||
|
addContainer( bar, id_ );
|
||
|
|
||
15 years ago
|
connect( bar, TQT_SIGNAL( destroyed() ), this, TQT_SLOT( slotDestroyed() ) );
|
||
15 years ago
|
|
||
|
updateCurrentItem( containerCount() - 1 );
|
||
|
|
||
|
return containerCount() - 1;
|
||
|
}
|
||
14 years ago
|
else if ( ::tqqt_cast<TQMenuBar *>( widget ) )
|
||
15 years ago
|
{
|
||
|
// Create the PopupMenu and store it in m_menu
|
||
|
(void)popupMenu();
|
||
|
|
||
15 years ago
|
TQMenuBar* menu = static_cast<TQMenuBar*>( widget );
|
||
15 years ago
|
int id = menu->insertItem( text(), d->m_menu, -1, index );
|
||
|
|
||
|
if ( !isEnabled() )
|
||
|
menu->setItemEnabled( id, false );
|
||
|
|
||
15 years ago
|
TQString wth = whatsThis();
|
||
15 years ago
|
if ( !wth.isEmpty() )
|
||
14 years ago
|
menu->TQMenuData::setWhatsThis( id, wth );
|
||
15 years ago
|
|
||
|
addContainer( menu, id );
|
||
15 years ago
|
connect( menu, TQT_SIGNAL( destroyed() ), this, TQT_SLOT( slotDestroyed() ) );
|
||
15 years ago
|
|
||
|
return containerCount() - 1;
|
||
|
}
|
||
|
|
||
|
kdWarning() << "Can not plug KAction in " << widget->className() << endl;
|
||
|
return -1;
|
||
|
}
|
||
|
|
||
15 years ago
|
TQStringList KSelectAction::comboItems() const
|
||
15 years ago
|
{
|
||
|
if( d->m_menuAccelsEnabled ) {
|
||
15 years ago
|
TQStringList lst;
|
||
|
TQStringList::ConstIterator it = d->m_list.begin();
|
||
15 years ago
|
for( ; it != d->m_list.end(); ++it )
|
||
|
{
|
||
15 years ago
|
TQString item = *it;
|
||
13 years ago
|
int i = item.find( '&' );
|
||
15 years ago
|
if ( i > -1 )
|
||
|
item = item.remove( i, 1 );
|
||
|
lst.append( item );
|
||
|
}
|
||
|
return lst;
|
||
|
}
|
||
|
else
|
||
|
return d->m_list;
|
||
|
}
|
||
|
|
||
|
void KSelectAction::clear()
|
||
|
{
|
||
|
if ( d->m_menu )
|
||
|
d->m_menu->clear();
|
||
|
|
||
|
int len = containerCount();
|
||
|
for( int i = 0; i < len; ++i )
|
||
|
updateClear( i );
|
||
|
}
|
||
|
|
||
|
void KSelectAction::updateClear( int id )
|
||
|
{
|
||
15 years ago
|
TQWidget* w = container( id );
|
||
14 years ago
|
if ( ::tqqt_cast<KToolBar *>( w ) ) {
|
||
15 years ago
|
TQWidget* r = static_cast<KToolBar*>( w )->getWidget( itemId( id ) );
|
||
14 years ago
|
if ( ::tqqt_cast<TQComboBox *>( r ) ) {
|
||
15 years ago
|
TQComboBox *b = static_cast<TQComboBox*>( r );
|
||
15 years ago
|
b->clear();
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void KSelectAction::slotActivated( int id )
|
||
|
{
|
||
|
if ( d->m_current == id )
|
||
|
return;
|
||
|
|
||
|
setCurrentItem( id );
|
||
|
// Delay this. Especially useful when the slot connected to activated() will re-create
|
||
|
// the menu, e.g. in the recent files action. This prevents a crash.
|
||
15 years ago
|
TQTimer::singleShot( 0, this, TQT_SLOT( slotActivated() ) );
|
||
15 years ago
|
}
|
||
|
|
||
15 years ago
|
void KSelectAction::slotActivated( const TQString &text )
|
||
15 years ago
|
{
|
||
|
if ( isEditable() )
|
||
|
{
|
||
15 years ago
|
TQStringList lst = d->m_list;
|
||
13 years ago
|
if(!lst.contains(text))
|
||
15 years ago
|
{
|
||
|
lst.append( text );
|
||
|
setItems( lst );
|
||
|
}
|
||
|
}
|
||
|
|
||
13 years ago
|
int i = d->m_list.findIndex( text );
|
||
15 years ago
|
if ( i > -1 )
|
||
|
setCurrentItem( i );
|
||
|
else
|
||
13 years ago
|
setCurrentItem( comboItems().findIndex( text ) );
|
||
15 years ago
|
// Delay this. Especially useful when the slot connected to activated() will re-create
|
||
|
// the menu, e.g. in the recent files action. This prevents a crash.
|
||
15 years ago
|
TQTimer::singleShot( 0, this, TQT_SLOT( slotActivated() ) );
|
||
15 years ago
|
}
|
||
|
|
||
|
void KSelectAction::slotActivated()
|
||
|
{
|
||
|
KAction::slotActivated();
|
||
|
kdDebug(129) << "KSelectAction::slotActivated currentItem=" << currentItem() << " currentText=" << currentText() << endl;
|
||
|
emit activated( currentItem() );
|
||
|
emit activated( currentText() );
|
||
|
}
|
||
|
|
||
|
void KSelectAction::setEditable( bool edit )
|
||
|
{
|
||
|
d->m_edit = edit;
|
||
|
}
|
||
|
|
||
|
bool KSelectAction::isEditable() const
|
||
|
{
|
||
|
return d->m_edit;
|
||
|
}
|
||
|
|
||
|
void KSelectAction::setRemoveAmpersandsInCombo( bool b )
|
||
|
{
|
||
|
setMenuAccelsEnabled( b );
|
||
|
}
|
||
|
|
||
|
bool KSelectAction::removeAmpersandsInCombo() const
|
||
|
{
|
||
|
return menuAccelsEnabled( );
|
||
|
}
|
||
|
|
||
|
void KSelectAction::setMenuAccelsEnabled( bool b )
|
||
|
{
|
||
|
d->m_menuAccelsEnabled = b;
|
||
|
}
|
||
|
|
||
|
bool KSelectAction::menuAccelsEnabled() const
|
||
|
{
|
||
|
return d->m_menuAccelsEnabled;
|
||
|
}
|
||
|
|
||
|
class KListAction::KListActionPrivate
|
||
|
{
|
||
|
public:
|
||
|
KListActionPrivate()
|
||
|
{
|
||
|
m_current = 0;
|
||
|
}
|
||
|
int m_current;
|
||
|
};
|
||
|
|
||
15 years ago
|
KListAction::KListAction( const TQString& text, const KShortcut& cut,
|
||
|
TQObject* parent, const char* name )
|
||
15 years ago
|
: KSelectAction( text, cut, parent, name )
|
||
|
{
|
||
|
d = new KListActionPrivate;
|
||
|
}
|
||
|
|
||
15 years ago
|
KListAction::KListAction( const TQString& text, const KShortcut& cut,
|
||
|
const TQObject* receiver, const char* slot,
|
||
|
TQObject* parent, const char* name )
|
||
15 years ago
|
: KSelectAction( text, cut, parent, name )
|
||
|
{
|
||
|
d = new KListActionPrivate;
|
||
|
if ( receiver )
|
||
15 years ago
|
connect( this, TQT_SIGNAL( activated( int ) ), receiver, slot );
|
||
15 years ago
|
}
|
||
|
|
||
15 years ago
|
KListAction::KListAction( const TQString& text, const TQIconSet& pix,
|
||
15 years ago
|
const KShortcut& cut,
|
||
15 years ago
|
TQObject* parent, const char* name )
|
||
15 years ago
|
: KSelectAction( text, pix, cut, parent, name )
|
||
|
{
|
||
|
d = new KListActionPrivate;
|
||
|
}
|
||
|
|
||
15 years ago
|
KListAction::KListAction( const TQString& text, const TQString& pix,
|
||
15 years ago
|
const KShortcut& cut,
|
||
15 years ago
|
TQObject* parent, const char* name )
|
||
15 years ago
|
: KSelectAction( text, pix, cut, parent, name )
|
||
|
{
|
||
|
d = new KListActionPrivate;
|
||
|
}
|
||
|
|
||
15 years ago
|
KListAction::KListAction( const TQString& text, const TQIconSet& pix,
|
||
|
const KShortcut& cut, const TQObject* receiver,
|
||
|
const char* slot, TQObject* parent,
|
||
15 years ago
|
const char* name )
|
||
|
: KSelectAction( text, pix, cut, parent, name )
|
||
|
{
|
||
|
d = new KListActionPrivate;
|
||
|
if ( receiver )
|
||
15 years ago
|
connect( this, TQT_SIGNAL( activated( int ) ), receiver, slot );
|
||
15 years ago
|
}
|
||
|
|
||
15 years ago
|
KListAction::KListAction( const TQString& text, const TQString& pix,
|
||
|
const KShortcut& cut, const TQObject* receiver,
|
||
|
const char* slot, TQObject* parent,
|
||
15 years ago
|
const char* name )
|
||
|
: KSelectAction( text, pix, cut, parent, name )
|
||
|
{
|
||
|
d = new KListActionPrivate;
|
||
|
if ( receiver )
|
||
15 years ago
|
connect( this, TQT_SIGNAL( activated( int ) ), receiver, slot );
|
||
15 years ago
|
}
|
||
|
|
||
15 years ago
|
KListAction::KListAction( TQObject* parent, const char* name )
|
||
15 years ago
|
: KSelectAction( parent, name )
|
||
|
{
|
||
|
d = new KListActionPrivate;
|
||
|
}
|
||
|
|
||
|
KListAction::~KListAction()
|
||
|
{
|
||
|
delete d; d = 0;
|
||
|
}
|
||
|
|
||
|
void KListAction::setCurrentItem( int index )
|
||
|
{
|
||
|
KSelectAction::setCurrentItem( index );
|
||
|
d->m_current = index;
|
||
|
|
||
|
// emit KAction::activated();
|
||
|
// emit activated( currentItem() );
|
||
|
// emit activated( currentText() );
|
||
|
}
|
||
|
|
||
15 years ago
|
TQString KListAction::currentText() const
|
||
15 years ago
|
{
|
||
|
return KSelectAction::currentText();
|
||
|
}
|
||
|
|
||
|
int KListAction::currentItem() const
|
||
|
{
|
||
|
return d->m_current;
|
||
|
}
|
||
|
|
||
|
class KRecentFilesAction::KRecentFilesActionPrivate
|
||
|
{
|
||
|
public:
|
||
|
KRecentFilesActionPrivate()
|
||
|
{
|
||
|
m_maxItems = 0;
|
||
|
m_popup = 0;
|
||
|
}
|
||
|
uint m_maxItems;
|
||
|
KPopupMenu *m_popup;
|
||
15 years ago
|
TQMap<TQString, TQString> m_shortNames;
|
||
|
TQMap<TQString, KURL> m_urls;
|
||
15 years ago
|
};
|
||
|
|
||
15 years ago
|
KRecentFilesAction::KRecentFilesAction( const TQString& text,
|
||
15 years ago
|
const KShortcut& cut,
|
||
15 years ago
|
TQObject* parent, const char* name,
|
||
15 years ago
|
uint maxItems )
|
||
|
: KListAction( text, cut, parent, name)
|
||
|
{
|
||
|
d = new KRecentFilesActionPrivate;
|
||
|
d->m_maxItems = maxItems;
|
||
|
|
||
|
init();
|
||
|
}
|
||
|
|
||
15 years ago
|
KRecentFilesAction::KRecentFilesAction( const TQString& text,
|
||
15 years ago
|
const KShortcut& cut,
|
||
15 years ago
|
const TQObject* receiver,
|
||
15 years ago
|
const char* slot,
|
||
15 years ago
|
TQObject* parent, const char* name,
|
||
15 years ago
|
uint maxItems )
|
||
|
: KListAction( text, cut, parent, name)
|
||
|
{
|
||
|
d = new KRecentFilesActionPrivate;
|
||
|
d->m_maxItems = maxItems;
|
||
|
|
||
|
init();
|
||
|
|
||
|
if ( receiver )
|
||
15 years ago
|
connect( this, TQT_SIGNAL(urlSelected(const KURL&)),
|
||
15 years ago
|
receiver, slot );
|
||
|
}
|
||
|
|
||
15 years ago
|
KRecentFilesAction::KRecentFilesAction( const TQString& text,
|
||
|
const TQIconSet& pix,
|
||
15 years ago
|
const KShortcut& cut,
|
||
15 years ago
|
TQObject* parent, const char* name,
|
||
15 years ago
|
uint maxItems )
|
||
|
: KListAction( text, pix, cut, parent, name)
|
||
|
{
|
||
|
d = new KRecentFilesActionPrivate;
|
||
|
d->m_maxItems = maxItems;
|
||
|
|
||
|
init();
|
||
|
}
|
||
|
|
||
15 years ago
|
KRecentFilesAction::KRecentFilesAction( const TQString& text,
|
||
|
const TQString& pix,
|
||
15 years ago
|
const KShortcut& cut,
|
||
15 years ago
|
TQObject* parent, const char* name,
|
||
15 years ago
|
uint maxItems )
|
||
|
: KListAction( text, pix, cut, parent, name)
|
||
|
{
|
||
|
d = new KRecentFilesActionPrivate;
|
||
|
d->m_maxItems = maxItems;
|
||
|
|
||
|
init();
|
||
|
}
|
||
|
|
||
15 years ago
|
KRecentFilesAction::KRecentFilesAction( const TQString& text,
|
||
|
const TQIconSet& pix,
|
||
15 years ago
|
const KShortcut& cut,
|
||
15 years ago
|
const TQObject* receiver,
|
||
15 years ago
|
const char* slot,
|
||
15 years ago
|
TQObject* parent, const char* name,
|
||
15 years ago
|
uint maxItems )
|
||
|
: KListAction( text, pix, cut, parent, name)
|
||
|
{
|
||
|
d = new KRecentFilesActionPrivate;
|
||
|
d->m_maxItems = maxItems;
|
||
|
|
||
|
init();
|
||
|
|
||
|
if ( receiver )
|
||
15 years ago
|
connect( this, TQT_SIGNAL(urlSelected(const KURL&)),
|
||
15 years ago
|
receiver, slot );
|
||
|
}
|
||
|
|
||
15 years ago
|
KRecentFilesAction::KRecentFilesAction( const TQString& text,
|
||
|
const TQString& pix,
|
||
15 years ago
|
const KShortcut& cut,
|
||
15 years ago
|
const TQObject* receiver,
|
||
15 years ago
|
const char* slot,
|
||
15 years ago
|
TQObject* parent, const char* name,
|
||
15 years ago
|
uint maxItems )
|
||
|
: KListAction( text, pix, cut, parent, name)
|
||
|
{
|
||
|
d = new KRecentFilesActionPrivate;
|
||
|
d->m_maxItems = maxItems;
|
||
|
|
||
|
init();
|
||
|
|
||
|
if ( receiver )
|
||
15 years ago
|
connect( this, TQT_SIGNAL(urlSelected(const KURL&)),
|
||
15 years ago
|
receiver, slot );
|
||
|
}
|
||
|
|
||
15 years ago
|
KRecentFilesAction::KRecentFilesAction( TQObject* parent, const char* name,
|
||
15 years ago
|
uint maxItems )
|
||
|
: KListAction( parent, name )
|
||
|
{
|
||
|
d = new KRecentFilesActionPrivate;
|
||
|
d->m_maxItems = maxItems;
|
||
|
|
||
|
init();
|
||
|
}
|
||
|
|
||
|
void KRecentFilesAction::init()
|
||
|
{
|
||
|
KRecentFilesAction *that = const_cast<KRecentFilesAction*>(this);
|
||
|
that->d->m_popup = new KPopupMenu;
|
||
15 years ago
|
connect(d->m_popup, TQT_SIGNAL(aboutToShow()), this, TQT_SLOT(menuAboutToShow()));
|
||
|
connect(d->m_popup, TQT_SIGNAL(activated(int)), this, TQT_SLOT(menuItemActivated(int)));
|
||
|
connect( this, TQT_SIGNAL( activated( const TQString& ) ),
|
||
|
this, TQT_SLOT( itemSelected( const TQString& ) ) );
|
||
15 years ago
|
|
||
|
setMenuAccelsEnabled( false );
|
||
|
}
|
||
|
|
||
|
KRecentFilesAction::~KRecentFilesAction()
|
||
|
{
|
||
|
delete d->m_popup;
|
||
|
delete d; d = 0;
|
||
|
}
|
||
|
|
||
|
uint KRecentFilesAction::maxItems() const
|
||
|
{
|
||
|
return d->m_maxItems;
|
||
|
}
|
||
|
|
||
|
void KRecentFilesAction::setMaxItems( uint maxItems )
|
||
|
{
|
||
15 years ago
|
TQStringList lst = KSelectAction::items();
|
||
15 years ago
|
uint oldCount = lst.count();
|
||
|
|
||
|
// set new maxItems
|
||
|
d->m_maxItems = maxItems;
|
||
|
|
||
|
// remove all items that are too much
|
||
|
while( lst.count() > maxItems )
|
||
|
{
|
||
|
// remove last item
|
||
15 years ago
|
TQString lastItem = lst.last();
|
||
15 years ago
|
d->m_shortNames.erase( lastItem );
|
||
|
d->m_urls.erase( lastItem );
|
||
|
lst.remove( lastItem );
|
||
|
}
|
||
|
|
||
|
// set new list if changed
|
||
|
if( lst.count() != oldCount )
|
||
|
setItems( lst );
|
||
|
}
|
||
|
|
||
|
void KRecentFilesAction::addURL( const KURL& url )
|
||
|
{
|
||
|
addURL( url, url.fileName() );
|
||
|
}
|
||
|
|
||
15 years ago
|
void KRecentFilesAction::addURL( const KURL& url, const TQString& name )
|
||
15 years ago
|
{
|
||
|
if ( url.isLocalFile() && !KGlobal::dirs()->relativeLocation("tmp", url.path()).startsWith("/"))
|
||
|
return;
|
||
15 years ago
|
const TQString file = url.pathOrURL();
|
||
|
TQStringList lst = KSelectAction::items();
|
||
15 years ago
|
|
||
|
// remove file if already in list
|
||
15 years ago
|
const TQStringList::Iterator end = lst.end();
|
||
|
for ( TQStringList::Iterator it = lst.begin(); it != end; ++it )
|
||
15 years ago
|
{
|
||
15 years ago
|
TQString title = (*it);
|
||
15 years ago
|
if ( title.endsWith( file + "]" ) )
|
||
|
{
|
||
|
lst.remove( it );
|
||
|
d->m_urls.erase( title );
|
||
|
d->m_shortNames.erase( title );
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
// remove last item if already maxitems in list
|
||
|
if( lst.count() == d->m_maxItems )
|
||
|
{
|
||
|
// remove last item
|
||
15 years ago
|
const TQString lastItem = lst.last();
|
||
15 years ago
|
d->m_shortNames.erase( lastItem );
|
||
|
d->m_urls.erase( lastItem );
|
||
|
lst.remove( lastItem );
|
||
|
}
|
||
|
|
||
|
// add file to list
|
||
15 years ago
|
const TQString title = name + " [" + file + "]";
|
||
15 years ago
|
d->m_shortNames.insert( title, name );
|
||
|
d->m_urls.insert( title, url );
|
||
|
lst.prepend( title );
|
||
|
setItems( lst );
|
||
|
}
|
||
|
|
||
|
void KRecentFilesAction::removeURL( const KURL& url )
|
||
|
{
|
||
15 years ago
|
TQStringList lst = KSelectAction::items();
|
||
|
TQString file = url.pathOrURL();
|
||
15 years ago
|
|
||
|
// remove url
|
||
15 years ago
|
TQStringList::Iterator end = lst.end();
|
||
|
for ( TQStringList::Iterator it = lst.begin(); it != end; ++it )
|
||
15 years ago
|
{
|
||
|
if ( (*it).endsWith( file + "]" ))
|
||
|
{
|
||
|
d->m_shortNames.erase( (*it) );
|
||
|
d->m_urls.erase( (*it) );
|
||
|
lst.remove( it );
|
||
|
setItems( lst );
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void KRecentFilesAction::clearURLList()
|
||
|
{
|
||
|
clear();
|
||
|
d->m_shortNames.clear();
|
||
|
d->m_urls.clear();
|
||
|
}
|
||
|
|
||
15 years ago
|
void KRecentFilesAction::loadEntries( KConfig* config, TQString groupname)
|
||
15 years ago
|
{
|
||
15 years ago
|
TQString key;
|
||
|
TQString value;
|
||
|
TQString nameKey;
|
||
|
TQString nameValue;
|
||
|
TQString title;
|
||
|
TQString oldGroup;
|
||
|
TQStringList lst;
|
||
15 years ago
|
KURL url;
|
||
|
|
||
|
oldGroup = config->group();
|
||
|
|
||
|
if (groupname.isEmpty())
|
||
|
groupname = "RecentFiles";
|
||
|
config->setGroup( groupname );
|
||
|
|
||
|
// read file list
|
||
|
for( unsigned int i = 1 ; i <= d->m_maxItems ; i++ )
|
||
|
{
|
||
15 years ago
|
key = TQString( "File%1" ).arg( i );
|
||
15 years ago
|
value = config->readPathEntry( key );
|
||
|
url = KURL::fromPathOrURL( value );
|
||
|
|
||
|
// Don't restore if file doesn't exist anymore
|
||
15 years ago
|
if (url.isLocalFile() && !TQFile::exists(url.path()))
|
||
15 years ago
|
continue;
|
||
|
|
||
15 years ago
|
nameKey = TQString( "Name%1" ).arg( i );
|
||
15 years ago
|
nameValue = config->readPathEntry( nameKey, url.fileName() );
|
||
|
title = nameValue + " [" + value + "]";
|
||
|
if (!value.isNull())
|
||
|
{
|
||
|
lst.append( title );
|
||
|
d->m_shortNames.insert( title, nameValue );
|
||
|
d->m_urls.insert( title, url );
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// set file
|
||
|
setItems( lst );
|
||
|
|
||
|
config->setGroup( oldGroup );
|
||
|
}
|
||
|
|
||
15 years ago
|
void KRecentFilesAction::saveEntries( KConfig* config, TQString groupname )
|
||
15 years ago
|
{
|
||
15 years ago
|
TQString key;
|
||
|
TQString value;
|
||
|
TQString oldGroup;
|
||
|
TQStringList lst = KSelectAction::items();
|
||
15 years ago
|
|
||
|
oldGroup = config->group();
|
||
|
|
||
|
if (groupname.isEmpty())
|
||
|
groupname = "RecentFiles";
|
||
|
config->deleteGroup( groupname, true );
|
||
|
config->setGroup( groupname );
|
||
|
|
||
|
// write file list
|
||
|
for( unsigned int i = 1 ; i <= lst.count() ; i++ )
|
||
|
{
|
||
|
//kdDebug(129) << "Entry for " << lst[i-1] << d->m_urls[ lst[ i - 1 ] ] << endl;
|
||
15 years ago
|
key = TQString( "File%1" ).arg( i );
|
||
15 years ago
|
value = d->m_urls[ lst[ i - 1 ] ].pathOrURL();
|
||
|
config->writePathEntry( key, value );
|
||
15 years ago
|
key = TQString( "Name%1" ).arg( i );
|
||
15 years ago
|
value = d->m_shortNames[ lst[ i - 1 ] ];
|
||
|
config->writePathEntry( key, value );
|
||
|
}
|
||
|
|
||
|
config->setGroup( oldGroup );
|
||
|
}
|
||
|
|
||
15 years ago
|
void KRecentFilesAction::itemSelected( const TQString& text )
|
||
15 years ago
|
{
|
||
|
//return a copy of the URL since the slot where it is connected might call
|
||
|
//addURL or removeURL where the d->m_urls.erase( title ) could destroy the
|
||
|
//d->m_urls[ text ] and the emitted URL will be invalid in the rest of the slot
|
||
|
emit urlSelected( KURL(d->m_urls[ text ]) );
|
||
|
}
|
||
|
|
||
|
void KRecentFilesAction::menuItemActivated( int id )
|
||
|
{
|
||
15 years ago
|
TQString text = d->m_popup->text(id);
|
||
15 years ago
|
//return a copy of the URL since the slot where it is connected might call
|
||
|
//addURL or removeURL where the d->m_urls.erase( title ) could destroy the
|
||
|
//d->m_urls[ text ] and the emitted URL will be invalid in the rest of the slot
|
||
|
emit urlSelected( KURL(d->m_urls[ text ]) );
|
||
|
}
|
||
|
|
||
|
void KRecentFilesAction::menuAboutToShow()
|
||
|
{
|
||
|
KPopupMenu *menu = d->m_popup;
|
||
|
menu->clear();
|
||
15 years ago
|
TQStringList list = KSelectAction::items();
|
||
|
for ( TQStringList::Iterator it = list.begin(); it != list.end(); ++it )
|
||
15 years ago
|
{
|
||
|
menu->insertItem(*it);
|
||
|
}
|
||
|
}
|
||
|
|
||
15 years ago
|
int KRecentFilesAction::plug( TQWidget *widget, int index )
|
||
15 years ago
|
{
|
||
|
if (kapp && !kapp->authorizeKAction(name()))
|
||
|
return -1;
|
||
|
// This is very related to KActionMenu::plug.
|
||
|
// In fact this class could be an interesting base class for KActionMenu
|
||
14 years ago
|
if ( ::tqqt_cast<KToolBar *>( widget ) )
|
||
15 years ago
|
{
|
||
|
KToolBar *bar = (KToolBar *)widget;
|
||
|
|
||
|
int id_ = KAction::getToolButtonID();
|
||
|
|
||
|
KInstance * instance;
|
||
|
if ( m_parentCollection )
|
||
|
instance = m_parentCollection->instance();
|
||
|
else
|
||
|
instance = KGlobal::instance();
|
||
|
|
||
15 years ago
|
bar->insertButton( icon(), id_, TQT_SIGNAL( clicked() ), this,
|
||
|
TQT_SLOT( slotClicked() ), isEnabled(), plainText(),
|
||
15 years ago
|
index, instance );
|
||
|
|
||
|
addContainer( bar, id_ );
|
||
|
|
||
15 years ago
|
connect( bar, TQT_SIGNAL( destroyed() ), this, TQT_SLOT( slotDestroyed() ) );
|
||
15 years ago
|
|
||
|
bar->setDelayedPopup( id_, d->m_popup, true);
|
||
|
|
||
|
if ( !whatsThis().isEmpty() )
|
||
15 years ago
|
TQWhatsThis::add( bar->getButton( id_ ), whatsThisWithIcon() );
|
||
15 years ago
|
|
||
|
return containerCount() - 1;
|
||
|
}
|
||
|
|
||
|
return KListAction::plug( widget, index );
|
||
|
}
|
||
|
|
||
|
void KRecentFilesAction::slotClicked()
|
||
|
{
|
||
|
KAction::slotActivated();
|
||
|
}
|
||
|
|
||
15 years ago
|
void KRecentFilesAction::slotActivated(const TQString& text)
|
||
15 years ago
|
{
|
||
|
KListAction::slotActivated(text);
|
||
|
}
|
||
|
|
||
|
|
||
|
void KRecentFilesAction::slotActivated(int id)
|
||
|
{
|
||
|
KListAction::slotActivated(id);
|
||
|
}
|
||
|
|
||
|
|
||
|
void KRecentFilesAction::slotActivated()
|
||
|
{
|
||
|
emit activated( currentItem() );
|
||
|
emit activated( currentText() );
|
||
|
}
|
||
|
|
||
|
//KDE4: rename to urls() and return a KURL::List
|
||
15 years ago
|
TQStringList KRecentFilesAction::items() const
|
||
15 years ago
|
{
|
||
15 years ago
|
TQStringList lst = KSelectAction::items();
|
||
|
TQStringList result;
|
||
15 years ago
|
|
||
|
for( unsigned int i = 1 ; i <= lst.count() ; i++ )
|
||
|
{
|
||
|
result += d->m_urls[ lst[ i - 1 ] ].prettyURL(0, KURL::StripFileProtocol);
|
||
|
}
|
||
|
|
||
|
return result;
|
||
|
}
|
||
|
|
||
|
//KDE4: remove
|
||
15 years ago
|
TQStringList KRecentFilesAction::completeItems() const
|
||
15 years ago
|
{
|
||
|
return KSelectAction::items();
|
||
|
}
|
||
|
|
||
|
|
||
|
class KFontAction::KFontActionPrivate
|
||
|
{
|
||
|
public:
|
||
|
KFontActionPrivate()
|
||
|
{
|
||
|
}
|
||
15 years ago
|
TQStringList m_fonts;
|
||
15 years ago
|
};
|
||
|
|
||
15 years ago
|
KFontAction::KFontAction( const TQString& text,
|
||
|
const KShortcut& cut, TQObject* parent,
|
||
15 years ago
|
const char* name )
|
||
|
: KSelectAction( text, cut, parent, name )
|
||
|
{
|
||
|
d = new KFontActionPrivate;
|
||
|
KFontChooser::getFontList( d->m_fonts, 0 );
|
||
|
KSelectAction::setItems( d->m_fonts );
|
||
|
setEditable( true );
|
||
|
}
|
||
|
|
||
15 years ago
|
KFontAction::KFontAction( const TQString& text, const KShortcut& cut,
|
||
|
const TQObject* receiver, const char* slot,
|
||
|
TQObject* parent, const char* name )
|
||
15 years ago
|
: KSelectAction( text, cut, receiver, slot, parent, name )
|
||
|
{
|
||
|
d = new KFontActionPrivate;
|
||
|
KFontChooser::getFontList( d->m_fonts, 0 );
|
||
|
KSelectAction::setItems( d->m_fonts );
|
||
|
setEditable( true );
|
||
|
}
|
||
|
|
||
15 years ago
|
KFontAction::KFontAction( const TQString& text, const TQIconSet& pix,
|
||
15 years ago
|
const KShortcut& cut,
|
||
15 years ago
|
TQObject* parent, const char* name )
|
||
15 years ago
|
: KSelectAction( text, pix, cut, parent, name )
|
||
|
{
|
||
|
d = new KFontActionPrivate;
|
||
|
KFontChooser::getFontList( d->m_fonts, 0 );
|
||
|
KSelectAction::setItems( d->m_fonts );
|
||
|
setEditable( true );
|
||
|
}
|
||
|
|
||
15 years ago
|
KFontAction::KFontAction( const TQString& text, const TQString& pix,
|
||
15 years ago
|
const KShortcut& cut,
|
||
15 years ago
|
TQObject* parent, const char* name )
|
||
15 years ago
|
: KSelectAction( text, pix, cut, parent, name )
|
||
|
{
|
||
|
d = new KFontActionPrivate;
|
||
|
KFontChooser::getFontList( d->m_fonts, 0 );
|
||
|
KSelectAction::setItems( d->m_fonts );
|
||
|
setEditable( true );
|
||
|
}
|
||
|
|
||
15 years ago
|
KFontAction::KFontAction( const TQString& text, const TQIconSet& pix,
|
||
15 years ago
|
const KShortcut& cut,
|
||
15 years ago
|
const TQObject* receiver, const char* slot,
|
||
|
TQObject* parent, const char* name )
|
||
15 years ago
|
: KSelectAction( text, pix, cut, receiver, slot, parent, name )
|
||
|
{
|
||
|
d = new KFontActionPrivate;
|
||
|
KFontChooser::getFontList( d->m_fonts, 0 );
|
||
|
KSelectAction::setItems( d->m_fonts );
|
||
|
setEditable( true );
|
||
|
}
|
||
|
|
||
15 years ago
|
KFontAction::KFontAction( const TQString& text, const TQString& pix,
|
||
15 years ago
|
const KShortcut& cut,
|
||
15 years ago
|
const TQObject* receiver, const char* slot,
|
||
|
TQObject* parent, const char* name )
|
||
15 years ago
|
: KSelectAction( text, pix, cut, receiver, slot, parent, name )
|
||
|
{
|
||
|
d = new KFontActionPrivate;
|
||
|
KFontChooser::getFontList( d->m_fonts, 0 );
|
||
|
KSelectAction::setItems( d->m_fonts );
|
||
|
setEditable( true );
|
||
|
}
|
||
|
|
||
15 years ago
|
KFontAction::KFontAction( uint fontListCriteria, const TQString& text,
|
||
|
const KShortcut& cut, TQObject* parent,
|
||
15 years ago
|
const char* name )
|
||
|
: KSelectAction( text, cut, parent, name )
|
||
|
{
|
||
|
d = new KFontActionPrivate;
|
||
|
KFontChooser::getFontList( d->m_fonts, fontListCriteria );
|
||
|
KSelectAction::setItems( d->m_fonts );
|
||
|
setEditable( true );
|
||
|
}
|
||
|
|
||
15 years ago
|
KFontAction::KFontAction( uint fontListCriteria, const TQString& text, const TQString& pix,
|
||
15 years ago
|
const KShortcut& cut,
|
||
15 years ago
|
TQObject* parent, const char* name )
|
||
15 years ago
|
: KSelectAction( text, pix, cut, parent, name )
|
||
|
{
|
||
|
d = new KFontActionPrivate;
|
||
|
KFontChooser::getFontList( d->m_fonts, fontListCriteria );
|
||
|
KSelectAction::setItems( d->m_fonts );
|
||
|
setEditable( true );
|
||
|
}
|
||
|
|
||
15 years ago
|
KFontAction::KFontAction( TQObject* parent, const char* name )
|
||
15 years ago
|
: KSelectAction( parent, name )
|
||
|
{
|
||
|
d = new KFontActionPrivate;
|
||
|
KFontChooser::getFontList( d->m_fonts, 0 );
|
||
|
KSelectAction::setItems( d->m_fonts );
|
||
|
setEditable( true );
|
||
|
}
|
||
|
|
||
|
KFontAction::~KFontAction()
|
||
|
{
|
||
|
delete d;
|
||
|
d = 0;
|
||
|
}
|
||
|
|
||
|
/*
|
||
|
* Maintenance note: Keep in sync with KFontCombo::setCurrentFont()
|
||
|
*/
|
||
15 years ago
|
void KFontAction::setFont( const TQString &family )
|
||
15 years ago
|
{
|
||
15 years ago
|
TQString lowerName = family.lower();
|
||
15 years ago
|
int i = 0;
|
||
15 years ago
|
for ( TQStringList::Iterator it = d->m_fonts.begin(); it != d->m_fonts.end(); ++it, ++i )
|
||
15 years ago
|
{
|
||
|
if ((*it).lower() == lowerName)
|
||
|
{
|
||
|
setCurrentItem(i);
|
||
|
return;
|
||
|
}
|
||
|
}
|
||
13 years ago
|
i = lowerName.find(" [");
|
||
15 years ago
|
if (i>-1)
|
||
|
{
|
||
|
lowerName = lowerName.left(i);
|
||
|
i = 0;
|
||
15 years ago
|
for ( TQStringList::Iterator it = d->m_fonts.begin(); it != d->m_fonts.end(); ++it, ++i )
|
||
15 years ago
|
{
|
||
|
if ((*it).lower() == lowerName)
|
||
|
{
|
||
|
setCurrentItem(i);
|
||
|
return;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
lowerName += " [";
|
||
|
i = 0;
|
||
15 years ago
|
for ( TQStringList::Iterator it = d->m_fonts.begin(); it != d->m_fonts.end(); ++it, ++i )
|
||
15 years ago
|
{
|
||
|
if ((*it).lower().startsWith(lowerName))
|
||
|
{
|
||
|
setCurrentItem(i);
|
||
|
return;
|
||
|
}
|
||
|
}
|
||
14 years ago
|
|
||
|
// nothing matched yet, try a fontconfig reverse lookup and
|
||
|
// check again to solve an alias
|
||
|
FcPattern *pattern = NULL;
|
||
|
FcConfig *config = NULL;
|
||
|
TQString realFamily;
|
||
|
TQRegExp regExp("[-:]");
|
||
|
pattern = FcNameParse( (unsigned char*) family.ascii() );
|
||
|
FcDefaultSubstitute(pattern);
|
||
|
FcConfigSubstitute (config, pattern, FcMatchPattern);
|
||
|
pattern = FcFontMatch(NULL, pattern, NULL);
|
||
|
realFamily = (char*)FcNameUnparse(pattern);
|
||
13 years ago
|
realFamily.remove(realFamily.find(regExp), realFamily.length());
|
||
14 years ago
|
|
||
|
if ( !realFamily.isEmpty() && realFamily != family )
|
||
|
setFont( realFamily );
|
||
|
else
|
||
|
kdDebug(129) << "Font not found " << family.lower() << endl;
|
||
15 years ago
|
}
|
||
|
|
||
15 years ago
|
int KFontAction::plug( TQWidget *w, int index )
|
||
15 years ago
|
{
|
||
|
if (kapp && !kapp->authorizeKAction(name()))
|
||
|
return -1;
|
||
14 years ago
|
if ( ::tqqt_cast<KToolBar *>( w ) )
|
||
15 years ago
|
{
|
||
|
KToolBar* bar = static_cast<KToolBar*>( w );
|
||
|
int id_ = KAction::getToolButtonID();
|
||
|
KFontCombo *cb = new KFontCombo( items(), bar );
|
||
15 years ago
|
connect( cb, TQT_SIGNAL( activated( const TQString & ) ),
|
||
|
TQT_SLOT( slotActivated( const TQString & ) ) );
|
||
15 years ago
|
cb->setEnabled( isEnabled() );
|
||
|
bar->insertWidget( id_, comboWidth(), cb, index );
|
||
14 years ago
|
cb->setMinimumWidth( cb->tqsizeHint().width() );
|
||
15 years ago
|
|
||
|
addContainer( bar, id_ );
|
||
|
|
||
15 years ago
|
connect( bar, TQT_SIGNAL( destroyed() ), this, TQT_SLOT( slotDestroyed() ) );
|
||
15 years ago
|
|
||
|
updateCurrentItem( containerCount() - 1 );
|
||
|
|
||
|
return containerCount() - 1;
|
||
|
}
|
||
|
else return KSelectAction::plug( w, index );
|
||
|
}
|
||
|
|
||
|
class KFontSizeAction::KFontSizeActionPrivate
|
||
|
{
|
||
|
public:
|
||
|
KFontSizeActionPrivate()
|
||
|
{
|
||
|
}
|
||
|
};
|
||
|
|
||
15 years ago
|
KFontSizeAction::KFontSizeAction( const TQString& text,
|
||
15 years ago
|
const KShortcut& cut,
|
||
15 years ago
|
TQObject* parent, const char* name )
|
||
15 years ago
|
: KSelectAction( text, cut, parent, name )
|
||
|
{
|
||
|
init();
|
||
|
}
|
||
|
|
||
15 years ago
|
KFontSizeAction::KFontSizeAction( const TQString& text,
|
||
15 years ago
|
const KShortcut& cut,
|
||
15 years ago
|
const TQObject* receiver, const char* slot,
|
||
|
TQObject* parent, const char* name )
|
||
15 years ago
|
: KSelectAction( text, cut, receiver, slot, parent, name )
|
||
|
{
|
||
|
init();
|
||
|
}
|
||
|
|
||
15 years ago
|
KFontSizeAction::KFontSizeAction( const TQString& text, const TQIconSet& pix,
|
||
15 years ago
|
const KShortcut& cut,
|
||
15 years ago
|
TQObject* parent, const char* name )
|
||
15 years ago
|
: KSelectAction( text, pix, cut, parent, name )
|
||
|
{
|
||
|
init();
|
||
|
}
|
||
|
|
||
15 years ago
|
KFontSizeAction::KFontSizeAction( const TQString& text, const TQString& pix,
|
||
15 years ago
|
const KShortcut& cut,
|
||
15 years ago
|
TQObject* parent, const char* name )
|
||
15 years ago
|
: KSelectAction( text, pix, cut, parent, name )
|
||
|
{
|
||
|
init();
|
||
|
}
|
||
|
|
||
15 years ago
|
KFontSizeAction::KFontSizeAction( const TQString& text, const TQIconSet& pix,
|
||
15 years ago
|
const KShortcut& cut,
|
||
15 years ago
|
const TQObject* receiver,
|
||
|
const char* slot, TQObject* parent,
|
||
15 years ago
|
const char* name )
|
||
|
: KSelectAction( text, pix, cut, receiver, slot, parent, name )
|
||
|
{
|
||
|
init();
|
||
|
}
|
||
|
|
||
15 years ago
|
KFontSizeAction::KFontSizeAction( const TQString& text, const TQString& pix,
|
||
15 years ago
|
const KShortcut& cut,
|
||
15 years ago
|
const TQObject* receiver,
|
||
|
const char* slot, TQObject* parent,
|
||
15 years ago
|
const char* name )
|
||
|
: KSelectAction( text, pix, cut, receiver, slot, parent, name )
|
||
|
{
|
||
|
init();
|
||
|
}
|
||
|
|
||
15 years ago
|
KFontSizeAction::KFontSizeAction( TQObject* parent, const char* name )
|
||
15 years ago
|
: KSelectAction( parent, name )
|
||
|
{
|
||
|
init();
|
||
|
}
|
||
|
|
||
|
KFontSizeAction::~KFontSizeAction()
|
||
|
{
|
||
|
delete d;
|
||
|
d = 0;
|
||
|
}
|
||
|
|
||
|
void KFontSizeAction::init()
|
||
|
{
|
||
|
d = new KFontSizeActionPrivate;
|
||
|
|
||
|
setEditable( true );
|
||
15 years ago
|
TQFontDatabase fontDB;
|
||
14 years ago
|
TQValueList<int> sizes = fontDB.tqstandardSizes();
|
||
15 years ago
|
TQStringList lst;
|
||
|
for ( TQValueList<int>::Iterator it = sizes.begin(); it != sizes.end(); ++it )
|
||
|
lst.append( TQString::number( *it ) );
|
||
15 years ago
|
|
||
|
setItems( lst );
|
||
|
}
|
||
|
|
||
|
void KFontSizeAction::setFontSize( int size )
|
||
|
{
|
||
|
if ( size == fontSize() ) {
|
||
13 years ago
|
setCurrentItem( items().findIndex( TQString::number( size ) ) );
|
||
15 years ago
|
return;
|
||
|
}
|
||
|
|
||
|
if ( size < 1 ) {
|
||
|
kdWarning() << "KFontSizeAction: Size " << size << " is out of range" << endl;
|
||
|
return;
|
||
|
}
|
||
|
|
||
13 years ago
|
int index = items().findIndex( TQString::number( size ) );
|
||
15 years ago
|
if ( index == -1 ) {
|
||
|
// Insert at the correct position in the list (to keep sorting)
|
||
15 years ago
|
TQValueList<int> lst;
|
||
15 years ago
|
// Convert to list of ints
|
||
15 years ago
|
TQStringList itemsList = items();
|
||
|
for (TQStringList::Iterator it = itemsList.begin() ; it != itemsList.end() ; ++it)
|
||
15 years ago
|
lst.append( (*it).toInt() );
|
||
|
// New size
|
||
|
lst.append( size );
|
||
|
// Sort the list
|
||
|
qHeapSort( lst );
|
||
|
// Convert back to string list
|
||
15 years ago
|
TQStringList strLst;
|
||
|
for (TQValueList<int>::Iterator it = lst.begin() ; it != lst.end() ; ++it)
|
||
|
strLst.append( TQString::number(*it) );
|
||
15 years ago
|
KSelectAction::setItems( strLst );
|
||
|
// Find new current item
|
||
13 years ago
|
index = lst.findIndex( size );
|
||
15 years ago
|
setCurrentItem( index );
|
||
|
}
|
||
|
else
|
||
|
setCurrentItem( index );
|
||
|
|
||
|
|
||
|
//emit KAction::activated();
|
||
|
//emit activated( index );
|
||
15 years ago
|
//emit activated( TQString::number( size ) );
|
||
15 years ago
|
//emit fontSizeChanged( size );
|
||
|
}
|
||
|
|
||
|
int KFontSizeAction::fontSize() const
|
||
|
{
|
||
|
return currentText().toInt();
|
||
|
}
|
||
|
|
||
|
void KFontSizeAction::slotActivated( int index )
|
||
|
{
|
||
|
KSelectAction::slotActivated( index );
|
||
|
|
||
|
emit fontSizeChanged( items()[ index ].toInt() );
|
||
|
}
|
||
|
|
||
15 years ago
|
void KFontSizeAction::slotActivated( const TQString& size )
|
||
15 years ago
|
{
|
||
|
setFontSize( size.toInt() ); // insert sorted first
|
||
|
KSelectAction::slotActivated( size );
|
||
|
emit fontSizeChanged( size.toInt() );
|
||
|
}
|
||
|
|
||
|
class KActionMenu::KActionMenuPrivate
|
||
|
{
|
||
|
public:
|
||
|
KActionMenuPrivate()
|
||
|
{
|
||
|
m_popup = new KPopupMenu(0L,"KActionMenu::KActionMenuPrivate");
|
||
|
m_delayed = true;
|
||
|
m_stickyMenu = true;
|
||
|
}
|
||
|
~KActionMenuPrivate()
|
||
|
{
|
||
|
delete m_popup; m_popup = 0;
|
||
|
}
|
||
|
KPopupMenu *m_popup;
|
||
|
bool m_delayed;
|
||
|
bool m_stickyMenu;
|
||
|
};
|
||
|
|
||
15 years ago
|
KActionMenu::KActionMenu( TQObject* parent, const char* name )
|
||
15 years ago
|
: KAction( parent, name )
|
||
|
{
|
||
|
d = new KActionMenuPrivate;
|
||
|
setShortcutConfigurable( false );
|
||
|
}
|
||
|
|
||
15 years ago
|
KActionMenu::KActionMenu( const TQString& text, TQObject* parent,
|
||
15 years ago
|
const char* name )
|
||
|
: KAction( text, 0, parent, name )
|
||
|
{
|
||
|
d = new KActionMenuPrivate;
|
||
|
setShortcutConfigurable( false );
|
||
|
}
|
||
|
|
||
15 years ago
|
KActionMenu::KActionMenu( const TQString& text, const TQIconSet& icon,
|
||
|
TQObject* parent, const char* name )
|
||
15 years ago
|
: KAction( text, icon, 0, parent, name )
|
||
|
{
|
||
|
d = new KActionMenuPrivate;
|
||
|
setShortcutConfigurable( false );
|
||
|
}
|
||
|
|
||
15 years ago
|
KActionMenu::KActionMenu( const TQString& text, const TQString& icon,
|
||
|
TQObject* parent, const char* name )
|
||
15 years ago
|
: KAction( text, icon, 0, parent, name )
|
||
|
{
|
||
|
d = new KActionMenuPrivate;
|
||
|
setShortcutConfigurable( false );
|
||
|
}
|
||
|
|
||
|
KActionMenu::~KActionMenu()
|
||
|
{
|
||
|
unplugAll();
|
||
|
kdDebug(129) << "KActionMenu::~KActionMenu()" << endl; // ellis
|
||
|
delete d; d = 0;
|
||
|
}
|
||
|
|
||
15 years ago
|
void KActionMenu::popup( const TQPoint& global )
|
||
15 years ago
|
{
|
||
|
popupMenu()->popup( global );
|
||
|
}
|
||
|
|
||
|
KPopupMenu* KActionMenu::popupMenu() const
|
||
|
{
|
||
|
return d->m_popup;
|
||
|
}
|
||
|
|
||
|
void KActionMenu::insert( KAction* cmd, int index )
|
||
|
{
|
||
|
if ( cmd )
|
||
|
cmd->plug( d->m_popup, index );
|
||
|
}
|
||
|
|
||
|
void KActionMenu::remove( KAction* cmd )
|
||
|
{
|
||
|
if ( cmd )
|
||
|
cmd->unplug( d->m_popup );
|
||
|
}
|
||
|
|
||
|
bool KActionMenu::delayed() const {
|
||
|
return d->m_delayed;
|
||
|
}
|
||
|
|
||
|
void KActionMenu::setDelayed(bool _delayed) {
|
||
|
d->m_delayed = _delayed;
|
||
|
}
|
||
|
|
||
|
bool KActionMenu::stickyMenu() const {
|
||
|
return d->m_stickyMenu;
|
||
|
}
|
||
|
|
||
|
void KActionMenu::setStickyMenu(bool sticky) {
|
||
|
d->m_stickyMenu = sticky;
|
||
|
}
|
||
|
|
||
15 years ago
|
int KActionMenu::plug( TQWidget* widget, int index )
|
||
15 years ago
|
{
|
||
|
if (kapp && !kapp->authorizeKAction(name()))
|
||
|
return -1;
|
||
|
kdDebug(129) << "KActionMenu::plug( " << widget << ", " << index << " )" << endl; // remove -- ellis
|
||
14 years ago
|
if ( ::tqqt_cast<TQPopupMenu *>( widget ) )
|
||
15 years ago
|
{
|
||
15 years ago
|
TQPopupMenu* menu = static_cast<TQPopupMenu*>( widget );
|
||
15 years ago
|
int id;
|
||
|
if ( hasIcon() )
|
||
|
id = menu->insertItem( iconSet(), text(), d->m_popup, -1, index );
|
||
|
else
|
||
|
id = menu->insertItem( text(), d->m_popup, -1, index );
|
||
|
|
||
|
if ( !isEnabled() )
|
||
|
menu->setItemEnabled( id, false );
|
||
|
|
||
|
addContainer( menu, id );
|
||
15 years ago
|
connect( menu, TQT_SIGNAL( destroyed() ), this, TQT_SLOT( slotDestroyed() ) );
|
||
15 years ago
|
|
||
|
if ( m_parentCollection )
|
||
|
m_parentCollection->connectHighlight( menu, this );
|
||
|
|
||
|
return containerCount() - 1;
|
||
|
}
|
||
14 years ago
|
else if ( ::tqqt_cast<KToolBar *>( widget ) )
|
||
15 years ago
|
{
|
||
|
KToolBar *bar = static_cast<KToolBar *>( widget );
|
||
|
|
||
|
int id_ = KAction::getToolButtonID();
|
||
|
|
||
|
if ( icon().isEmpty() && !iconSet().isNull() )
|
||
15 years ago
|
bar->insertButton( iconSet().pixmap(), id_, TQT_SIGNAL( clicked() ), this,
|
||
|
TQT_SLOT( slotActivated() ), isEnabled(), plainText(),
|
||
15 years ago
|
index );
|
||
|
else
|
||
|
{
|
||
|
KInstance *instance;
|
||
|
|
||
|
if ( m_parentCollection )
|
||
|
instance = m_parentCollection->instance();
|
||
|
else
|
||
|
instance = KGlobal::instance();
|
||
|
|
||
15 years ago
|
bar->insertButton( icon(), id_, TQT_SIGNAL( clicked() ), this,
|
||
|
TQT_SLOT( slotActivated() ), isEnabled(), plainText(),
|
||
15 years ago
|
index, instance );
|
||
|
}
|
||
|
|
||
|
addContainer( bar, id_ );
|
||
|
|
||
|
if (!whatsThis().isEmpty())
|
||
15 years ago
|
TQWhatsThis::add( bar->getButton(id_), whatsThis() );
|
||
15 years ago
|
|
||
15 years ago
|
connect( bar, TQT_SIGNAL( destroyed() ), this, TQT_SLOT( slotDestroyed() ) );
|
||
15 years ago
|
|
||
|
if (delayed()) {
|
||
|
bar->setDelayedPopup( id_, popupMenu(), stickyMenu() );
|
||
|
} else {
|
||
|
bar->getButton(id_)->setPopup(popupMenu(), stickyMenu() );
|
||
|
}
|
||
|
|
||
|
if ( m_parentCollection )
|
||
|
m_parentCollection->connectHighlight( bar, this );
|
||
|
|
||
|
return containerCount() - 1;
|
||
|
}
|
||
14 years ago
|
else if ( ::tqqt_cast<TQMenuBar *>( widget ) )
|
||
15 years ago
|
{
|
||
15 years ago
|
TQMenuBar *bar = static_cast<TQMenuBar *>( widget );
|
||
15 years ago
|
|
||
|
int id;
|
||
|
|
||
|
id = bar->insertItem( text(), popupMenu(), -1, index );
|
||
|
|
||
|
if ( !isEnabled() )
|
||
|
bar->setItemEnabled( id, false );
|
||
|
|
||
|
addContainer( bar, id );
|
||
15 years ago
|
connect( bar, TQT_SIGNAL( destroyed() ), this, TQT_SLOT( slotDestroyed() ) );
|
||
15 years ago
|
|
||
|
return containerCount() - 1;
|
||
|
}
|
||
|
|
||
|
return -1;
|
||
|
}
|
||
|
|
||
|
////////
|
||
|
|
||
15 years ago
|
KToolBarPopupAction::KToolBarPopupAction( const TQString& text,
|
||
|
const TQString& icon,
|
||
15 years ago
|
const KShortcut& cut,
|
||
15 years ago
|
TQObject* parent, const char* name )
|
||
15 years ago
|
: KAction( text, icon, cut, parent, name )
|
||
|
{
|
||
|
m_popup = 0;
|
||
|
m_delayed = true;
|
||
|
m_stickyMenu = true;
|
||
|
}
|
||
|
|
||
15 years ago
|
KToolBarPopupAction::KToolBarPopupAction( const TQString& text,
|
||
|
const TQString& icon,
|
||
15 years ago
|
const KShortcut& cut,
|
||
15 years ago
|
const TQObject* receiver,
|
||
|
const char* slot, TQObject* parent,
|
||
15 years ago
|
const char* name )
|
||
|
: KAction( text, icon, cut, receiver, slot, parent, name )
|
||
|
{
|
||
|
m_popup = 0;
|
||
|
m_delayed = true;
|
||
|
m_stickyMenu = true;
|
||
|
}
|
||
|
|
||
|
KToolBarPopupAction::KToolBarPopupAction( const KGuiItem& item,
|
||
|
const KShortcut& cut,
|
||
15 years ago
|
const TQObject* receiver,
|
||
15 years ago
|
const char* slot, KActionCollection* parent,
|
||
|
const char* name )
|
||
|
: KAction( item, cut, receiver, slot, parent, name )
|
||
|
{
|
||
|
m_popup = 0;
|
||
|
m_delayed = true;
|
||
|
m_stickyMenu = true;
|
||
|
}
|
||
|
|
||
|
KToolBarPopupAction::~KToolBarPopupAction()
|
||
|
{
|
||
|
delete m_popup;
|
||
|
}
|
||
|
|
||
|
bool KToolBarPopupAction::delayed() const {
|
||
|
return m_delayed;
|
||
|
}
|
||
|
|
||
|
void KToolBarPopupAction::setDelayed(bool delayed) {
|
||
|
m_delayed = delayed;
|
||
|
}
|
||
|
|
||
|
bool KToolBarPopupAction::stickyMenu() const {
|
||
|
return m_stickyMenu;
|
||
|
}
|
||
|
|
||
|
void KToolBarPopupAction::setStickyMenu(bool sticky) {
|
||
|
m_stickyMenu = sticky;
|
||
|
}
|
||
|
|
||
15 years ago
|
int KToolBarPopupAction::plug( TQWidget *widget, int index )
|
||
15 years ago
|
{
|
||
|
if (kapp && !kapp->authorizeKAction(name()))
|
||
|
return -1;
|
||
|
// This is very related to KActionMenu::plug.
|
||
|
// In fact this class could be an interesting base class for KActionMenu
|
||
14 years ago
|
if ( ::tqqt_cast<KToolBar *>( widget ) )
|
||
15 years ago
|
{
|
||
|
KToolBar *bar = (KToolBar *)widget;
|
||
|
|
||
|
int id_ = KAction::getToolButtonID();
|
||
|
|
||
|
if ( icon().isEmpty() && !iconSet().isNull() ) {
|
||
14 years ago
|
bar->insertButton( iconSet().pixmap(), id_, TQT_SIGNAL( buttonClicked(int, TQt::ButtonState) ), this,
|
||
|
TQT_SLOT( slotButtonClicked(int, TQt::ButtonState) ),
|
||
15 years ago
|
isEnabled(), plainText(),
|
||
|
index );
|
||
|
} else {
|
||
|
KInstance * instance;
|
||
|
if ( m_parentCollection )
|
||
|
instance = m_parentCollection->instance();
|
||
|
else
|
||
|
instance = KGlobal::instance();
|
||
|
|
||
14 years ago
|
bar->insertButton( icon(), id_, TQT_SIGNAL( buttonClicked(int, TQt::ButtonState) ), this,
|
||
|
TQT_SLOT( slotButtonClicked(int, TQt::ButtonState) ),
|
||
15 years ago
|
isEnabled(), plainText(),
|
||
|
index, instance );
|
||
|
}
|
||
|
|
||
|
addContainer( bar, id_ );
|
||
|
|
||
15 years ago
|
connect( bar, TQT_SIGNAL( destroyed() ), this, TQT_SLOT( slotDestroyed() ) );
|
||
15 years ago
|
|
||
|
if (delayed()) {
|
||
|
bar->setDelayedPopup( id_, popupMenu(), stickyMenu() );
|
||
|
} else {
|
||
|
bar->getButton(id_)->setPopup(popupMenu(), stickyMenu());
|
||
|
}
|
||
|
|
||
|
if ( !whatsThis().isEmpty() )
|
||
15 years ago
|
TQWhatsThis::add( bar->getButton( id_ ), whatsThisWithIcon() );
|
||
15 years ago
|
|
||
|
return containerCount() - 1;
|
||
|
}
|
||
|
|
||
|
return KAction::plug( widget, index );
|
||
|
}
|
||
|
|
||
|
KPopupMenu *KToolBarPopupAction::popupMenu() const
|
||
|
{
|
||
|
if ( !m_popup ) {
|
||
|
KToolBarPopupAction *that = const_cast<KToolBarPopupAction*>(this);
|
||
|
that->m_popup = new KPopupMenu;
|
||
|
}
|
||
|
return m_popup;
|
||
|
}
|
||
|
|
||
|
////////
|
||
|
|
||
|
KToggleToolBarAction::KToggleToolBarAction( const char* toolBarName,
|
||
15 years ago
|
const TQString& text, KActionCollection* parent, const char* name )
|
||
15 years ago
|
: KToggleAction( text, KShortcut(), parent, name )
|
||
|
, m_toolBarName( toolBarName )
|
||
|
, m_toolBar( 0L )
|
||
|
{
|
||
|
}
|
||
|
|
||
15 years ago
|
KToggleToolBarAction::KToggleToolBarAction( KToolBar *toolBar, const TQString &text,
|
||
15 years ago
|
KActionCollection *parent, const char *name )
|
||
|
: KToggleAction( text, KShortcut(), parent, name )
|
||
|
, m_toolBarName( 0 ), m_toolBar( toolBar )
|
||
|
{
|
||
|
}
|
||
|
|
||
|
KToggleToolBarAction::~KToggleToolBarAction()
|
||
|
{
|
||
|
}
|
||
|
|
||
15 years ago
|
int KToggleToolBarAction::plug( TQWidget* w, int index )
|
||
15 years ago
|
{
|
||
|
if (kapp && !kapp->authorizeKAction(name()))
|
||
|
return -1;
|
||
|
|
||
|
if ( !m_toolBar ) {
|
||
14 years ago
|
// Note: tqtopLevelWidget() stops too early, we can't use it.
|
||
15 years ago
|
TQWidget * tl = w;
|
||
|
TQWidget * n;
|
||
14 years ago
|
while ( !tl->isDialog() && ( n = tl->parentWidget() ) ) // lookup parent and store
|
||
15 years ago
|
tl = n;
|
||
|
|
||
14 years ago
|
KMainWindow * mw = tqt_dynamic_cast<KMainWindow *>(tl); // try to see if it's a kmainwindow
|
||
15 years ago
|
|
||
|
if ( mw )
|
||
|
m_toolBar = mw->toolBar( m_toolBarName );
|
||
|
}
|
||
|
|
||
|
if( m_toolBar ) {
|
||
|
setChecked( m_toolBar->isVisible() );
|
||
15 years ago
|
connect( m_toolBar, TQT_SIGNAL(visibilityChanged(bool)), this, TQT_SLOT(setChecked(bool)) );
|
||
15 years ago
|
// Also emit toggled when the toolbar's visibility changes (see comment in header)
|
||
15 years ago
|
connect( m_toolBar, TQT_SIGNAL(visibilityChanged(bool)), this, TQT_SIGNAL(toggled(bool)) );
|
||
15 years ago
|
} else {
|
||
|
setEnabled( false );
|
||
|
}
|
||
|
|
||
|
return KToggleAction::plug( w, index );
|
||
|
}
|
||
|
|
||
|
void KToggleToolBarAction::setChecked( bool c )
|
||
|
{
|
||
|
if( m_toolBar && c != m_toolBar->isVisible() ) {
|
||
|
if( c ) {
|
||
|
m_toolBar->show();
|
||
|
} else {
|
||
|
m_toolBar->hide();
|
||
|
}
|
||
15 years ago
|
TQMainWindow* mw = m_toolBar->mainWindow();
|
||
14 years ago
|
if ( mw && ::tqqt_cast<KMainWindow *>( mw ) )
|
||
15 years ago
|
static_cast<KMainWindow *>( mw )->setSettingsDirty();
|
||
|
}
|
||
|
KToggleAction::setChecked( c );
|
||
|
}
|
||
|
|
||
|
////////
|
||
|
|
||
|
KToggleFullScreenAction::KToggleFullScreenAction( const KShortcut &cut,
|
||
15 years ago
|
const TQObject* receiver, const char* slot,
|
||
|
TQObject* parent, TQWidget* window,
|
||
15 years ago
|
const char* name )
|
||
15 years ago
|
: KToggleAction( TQString::null, cut, receiver, slot, parent, name ),
|
||
15 years ago
|
window( NULL )
|
||
|
{
|
||
|
setWindow( window );
|
||
|
}
|
||
|
|
||
|
KToggleFullScreenAction::~KToggleFullScreenAction()
|
||
|
{
|
||
|
}
|
||
|
|
||
15 years ago
|
void KToggleFullScreenAction::setWindow( TQWidget* w )
|
||
15 years ago
|
{
|
||
|
if( window )
|
||
|
window->removeEventFilter( this );
|
||
|
window = w;
|
||
|
if( window )
|
||
|
window->installEventFilter( this );
|
||
|
}
|
||
|
|
||
|
void KToggleFullScreenAction::setChecked( bool c )
|
||
|
{
|
||
|
if (c)
|
||
|
{
|
||
|
setText(i18n("Exit F&ull Screen Mode"));
|
||
|
setIcon("window_nofullscreen");
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
setText(i18n("F&ull Screen Mode"));
|
||
|
setIcon("window_fullscreen");
|
||
|
}
|
||
|
KToggleAction::setChecked( c );
|
||
|
}
|
||
|
|
||
15 years ago
|
bool KToggleFullScreenAction::eventFilter( TQObject* o, TQEvent* e )
|
||
15 years ago
|
{
|
||
14 years ago
|
if( TQT_BASE_OBJECT(o) == TQT_BASE_OBJECT(window) )
|
||
15 years ago
|
if( e->type() == TQEvent::WindowStateChange )
|
||
15 years ago
|
{
|
||
|
if( window->isFullScreen() != isChecked())
|
||
|
slotActivated(); // setChecked( window->isFullScreen()) wouldn't emit signals
|
||
|
}
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
////////
|
||
|
|
||
15 years ago
|
KWidgetAction::KWidgetAction( TQWidget* widget,
|
||
|
const TQString& text, const KShortcut& cut,
|
||
|
const TQObject* receiver, const char* slot,
|
||
15 years ago
|
KActionCollection* parent, const char* name )
|
||
|
: KAction( text, cut, receiver, slot, parent, name )
|
||
|
, m_widget( widget )
|
||
|
, m_autoSized( false )
|
||
|
{
|
||
15 years ago
|
connect( this, TQT_SIGNAL(enabled(bool)), widget, TQT_SLOT(setEnabled(bool)) );
|
||
15 years ago
|
}
|
||
|
|
||
|
KWidgetAction::~KWidgetAction()
|
||
|
{
|
||
|
}
|
||
|
|
||
|
void KWidgetAction::setAutoSized( bool autoSized )
|
||
|
{
|
||
|
if( m_autoSized == autoSized )
|
||
|
return;
|
||
|
|
||
|
m_autoSized = autoSized;
|
||
|
|
||
|
if( !m_widget || !isPlugged() )
|
||
|
return;
|
||
|
|
||
|
KToolBar* toolBar = (KToolBar*)m_widget->parent();
|
||
14 years ago
|
int i = findContainer( toolBar );
|
||
15 years ago
|
if ( i == -1 )
|
||
|
return;
|
||
|
int id = itemId( i );
|
||
|
|
||
|
toolBar->setItemAutoSized( id, m_autoSized );
|
||
|
}
|
||
|
|
||
15 years ago
|
int KWidgetAction::plug( TQWidget* w, int index )
|
||
15 years ago
|
{
|
||
|
if (kapp && !kapp->authorizeKAction(name()))
|
||
|
return -1;
|
||
|
|
||
14 years ago
|
if ( !::tqqt_cast<KToolBar *>( w ) ) {
|
||
15 years ago
|
kdError() << "KWidgetAction::plug: KWidgetAction must be plugged into KToolBar." << endl;
|
||
|
return -1;
|
||
|
}
|
||
|
if ( !m_widget ) {
|
||
|
kdError() << "KWidgetAction::plug: Widget was deleted or null!" << endl;
|
||
|
return -1;
|
||
|
}
|
||
|
|
||
|
KToolBar* toolBar = static_cast<KToolBar*>( w );
|
||
|
|
||
|
int id = KAction::getToolButtonID();
|
||
|
|
||
15 years ago
|
m_widget->reparent( toolBar, TQPoint() );
|
||
15 years ago
|
toolBar->insertWidget( id, 0, m_widget, index );
|
||
|
toolBar->setItemAutoSized( id, m_autoSized );
|
||
|
|
||
15 years ago
|
TQWhatsThis::add( m_widget, whatsThis() );
|
||
15 years ago
|
addContainer( toolBar, id );
|
||
|
|
||
15 years ago
|
connect( toolBar, TQT_SIGNAL( toolbarDestroyed() ), this, TQT_SLOT( slotToolbarDestroyed() ) );
|
||
|
connect( toolBar, TQT_SIGNAL( destroyed() ), this, TQT_SLOT( slotDestroyed() ) );
|
||
15 years ago
|
|
||
|
return containerCount() - 1;
|
||
|
}
|
||
|
|
||
15 years ago
|
void KWidgetAction::unplug( TQWidget *w )
|
||
15 years ago
|
{
|
||
|
if( !m_widget || !isPlugged() )
|
||
|
return;
|
||
|
|
||
|
KToolBar* toolBar = (KToolBar*)m_widget->parent();
|
||
|
if ( toolBar == w )
|
||
|
{
|
||
15 years ago
|
disconnect( toolBar, TQT_SIGNAL( toolbarDestroyed() ), this, TQT_SLOT( slotToolbarDestroyed() ) );
|
||
|
m_widget->reparent( 0L, TQPoint(), false /*showIt*/ );
|
||
15 years ago
|
}
|
||
|
KAction::unplug( w );
|
||
|
}
|
||
|
|
||
|
void KWidgetAction::slotToolbarDestroyed()
|
||
|
{
|
||
|
//Q_ASSERT( m_widget ); // When exiting the app the widget could be destroyed before the toolbar.
|
||
|
Q_ASSERT( isPlugged() );
|
||
|
if( !m_widget || !isPlugged() )
|
||
|
return;
|
||
|
|
||
|
// Don't let a toolbar being destroyed, delete my widget.
|
||
15 years ago
|
m_widget->reparent( 0L, TQPoint(), false /*showIt*/ );
|
||
15 years ago
|
}
|
||
|
|
||
|
////////
|
||
|
|
||
15 years ago
|
KActionSeparator::KActionSeparator( TQObject *parent, const char *name )
|
||
15 years ago
|
: KAction( parent, name )
|
||
|
{
|
||
|
}
|
||
|
|
||
|
KActionSeparator::~KActionSeparator()
|
||
|
{
|
||
|
}
|
||
|
|
||
15 years ago
|
int KActionSeparator::plug( TQWidget *widget, int index )
|
||
15 years ago
|
{
|
||
14 years ago
|
if ( ::tqqt_cast<TQPopupMenu *>( widget) )
|
||
15 years ago
|
{
|
||
15 years ago
|
TQPopupMenu* menu = static_cast<TQPopupMenu*>( widget );
|
||
15 years ago
|
|
||
|
int id = menu->insertSeparator( index );
|
||
|
|
||
|
addContainer( menu, id );
|
||
15 years ago
|
connect( menu, TQT_SIGNAL( destroyed() ), this, TQT_SLOT( slotDestroyed() ) );
|
||
15 years ago
|
|
||
|
return containerCount() - 1;
|
||
|
}
|
||
14 years ago
|
else if ( ::tqqt_cast<TQMenuBar *>( widget ) )
|
||
15 years ago
|
{
|
||
15 years ago
|
TQMenuBar *menuBar = static_cast<TQMenuBar *>( widget );
|
||
15 years ago
|
|
||
|
int id = menuBar->insertSeparator( index );
|
||
|
|
||
|
addContainer( menuBar, id );
|
||
|
|
||
15 years ago
|
connect( menuBar, TQT_SIGNAL( destroyed() ), this, TQT_SLOT( slotDestroyed() ) );
|
||
15 years ago
|
|
||
|
return containerCount() - 1;
|
||
|
}
|
||
14 years ago
|
else if ( ::tqqt_cast<KToolBar *>( widget ) )
|
||
15 years ago
|
{
|
||
|
KToolBar *toolBar = static_cast<KToolBar *>( widget );
|
||
|
|
||
|
int id = toolBar->insertSeparator( index );
|
||
|
|
||
|
addContainer( toolBar, id );
|
||
|
|
||
15 years ago
|
connect( toolBar, TQT_SIGNAL( destroyed() ), this, TQT_SLOT( slotDestroyed() ) );
|
||
15 years ago
|
|
||
|
return containerCount() - 1;
|
||
|
}
|
||
|
|
||
|
return -1;
|
||
|
}
|
||
|
|
||
15 years ago
|
KPasteTextAction::KPasteTextAction( const TQString& text,
|
||
|
const TQString& icon,
|
||
15 years ago
|
const KShortcut& cut,
|
||
15 years ago
|
const TQObject* receiver,
|
||
|
const char* slot, TQObject* parent,
|
||
15 years ago
|
const char* name)
|
||
|
: KAction( text, icon, cut, receiver, slot, parent, name )
|
||
|
{
|
||
|
m_popup = new KPopupMenu;
|
||
15 years ago
|
connect(m_popup, TQT_SIGNAL(aboutToShow()), this, TQT_SLOT(menuAboutToShow()));
|
||
|
connect(m_popup, TQT_SIGNAL(activated(int)), this, TQT_SLOT(menuItemActivated(int)));
|
||
15 years ago
|
m_popup->setCheckable(true);
|
||
|
m_mixedMode = true;
|
||
|
}
|
||
|
|
||
|
KPasteTextAction::~KPasteTextAction()
|
||
|
{
|
||
|
delete m_popup;
|
||
|
}
|
||
|
|
||
|
void KPasteTextAction::setMixedMode(bool mode)
|
||
|
{
|
||
|
m_mixedMode = mode;
|
||
|
}
|
||
|
|
||
15 years ago
|
int KPasteTextAction::plug( TQWidget *widget, int index )
|
||
15 years ago
|
{
|
||
|
if (kapp && !kapp->authorizeKAction(name()))
|
||
|
return -1;
|
||
14 years ago
|
if ( ::tqqt_cast<KToolBar *>( widget ) )
|
||
15 years ago
|
{
|
||
|
KToolBar *bar = (KToolBar *)widget;
|
||
|
|
||
|
int id_ = KAction::getToolButtonID();
|
||
|
|
||
|
KInstance * instance;
|
||
|
if ( m_parentCollection )
|
||
|
instance = m_parentCollection->instance();
|
||
|
else
|
||
|
instance = KGlobal::instance();
|
||
|
|
||
15 years ago
|
bar->insertButton( icon(), id_, TQT_SIGNAL( clicked() ), this,
|
||
|
TQT_SLOT( slotActivated() ), isEnabled(), plainText(),
|
||
15 years ago
|
index, instance );
|
||
|
|
||
|
addContainer( bar, id_ );
|
||
|
|
||
15 years ago
|
connect( bar, TQT_SIGNAL( destroyed() ), this, TQT_SLOT( slotDestroyed() ) );
|
||
15 years ago
|
|
||
|
bar->setDelayedPopup( id_, m_popup, true );
|
||
|
|
||
|
if ( !whatsThis().isEmpty() )
|
||
15 years ago
|
TQWhatsThis::add( bar->getButton( id_ ), whatsThisWithIcon() );
|
||
15 years ago
|
|
||
|
return containerCount() - 1;
|
||
|
}
|
||
|
|
||
|
return KAction::plug( widget, index );
|
||
|
}
|
||
|
|
||
|
void KPasteTextAction::menuAboutToShow()
|
||
|
{
|
||
|
m_popup->clear();
|
||
15 years ago
|
TQStringList list;
|
||
15 years ago
|
DCOPClient *client = kapp->dcopClient();
|
||
|
if (client->isAttached() && client->isApplicationRegistered("klipper")) {
|
||
|
DCOPRef klipper("klipper","klipper");
|
||
|
DCOPReply reply = klipper.call("getClipboardHistoryMenu");
|
||
|
if (reply.isValid())
|
||
|
list = reply;
|
||
|
}
|
||
14 years ago
|
TQString clipboardText = tqApp->tqclipboard()->text(TQClipboard::Clipboard);
|
||
15 years ago
|
if (list.isEmpty())
|
||
|
list << clipboardText;
|
||
|
bool found = false;
|
||
15 years ago
|
for ( TQStringList::ConstIterator it = list.begin(); it != list.end(); ++it )
|
||
15 years ago
|
{
|
||
15 years ago
|
TQString text = KStringHandler::cEmSqueeze((*it).simplifyWhiteSpace(), m_popup->fontMetrics(), 20);
|
||
14 years ago
|
text.replace("&", "&&");
|
||
15 years ago
|
int id = m_popup->insertItem(text);
|
||
|
if (!found && *it == clipboardText)
|
||
|
{
|
||
|
m_popup->setItemChecked(id, true);
|
||
|
found = true;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void KPasteTextAction::menuItemActivated( int id)
|
||
|
{
|
||
|
DCOPClient *client = kapp->dcopClient();
|
||
|
if (client->isAttached() && client->isApplicationRegistered("klipper")) {
|
||
|
DCOPRef klipper("klipper","klipper");
|
||
|
DCOPReply reply = klipper.call("getClipboardHistoryItem(int)", m_popup->indexOf(id));
|
||
|
if (!reply.isValid())
|
||
|
return;
|
||
15 years ago
|
TQString clipboardText = reply;
|
||
|
reply = klipper.call("setClipboardContents(TQString)", clipboardText);
|
||
15 years ago
|
if (reply.isValid())
|
||
14 years ago
|
kdDebug(129) << "Clipboard: " << TQString(tqApp->tqclipboard()->text(TQClipboard::Clipboard)) << endl;
|
||
15 years ago
|
}
|
||
15 years ago
|
TQTimer::singleShot(20, this, TQT_SLOT(slotActivated()));
|
||
15 years ago
|
}
|
||
|
|
||
|
void KPasteTextAction::slotActivated()
|
||
|
{
|
||
|
if (!m_mixedMode) {
|
||
14 years ago
|
TQWidget *w = tqApp->widgetAt(TQCursor::pos(), true);
|
||
|
TQMimeSource *data = TQApplication::tqclipboard()->data();
|
||
15 years ago
|
if (!data->provides("text/plain") && w) {
|
||
15 years ago
|
m_popup->popup(w->mapToGlobal(TQPoint(0, w->height())));
|
||
15 years ago
|
} else
|
||
|
KAction::slotActivated();
|
||
|
} else
|
||
|
KAction::slotActivated();
|
||
|
}
|
||
|
|
||
|
|
||
|
void KToggleAction::virtual_hook( int id, void* data )
|
||
|
{ KAction::virtual_hook( id, data ); }
|
||
|
|
||
|
void KRadioAction::virtual_hook( int id, void* data )
|
||
|
{ KToggleAction::virtual_hook( id, data ); }
|
||
|
|
||
|
void KSelectAction::virtual_hook( int id, void* data )
|
||
|
{ KAction::virtual_hook( id, data ); }
|
||
|
|
||
|
void KListAction::virtual_hook( int id, void* data )
|
||
|
{ KSelectAction::virtual_hook( id, data ); }
|
||
|
|
||
|
void KRecentFilesAction::virtual_hook( int id, void* data )
|
||
|
{ KListAction::virtual_hook( id, data ); }
|
||
|
|
||
|
void KFontAction::virtual_hook( int id, void* data )
|
||
|
{ KSelectAction::virtual_hook( id, data ); }
|
||
|
|
||
|
void KFontSizeAction::virtual_hook( int id, void* data )
|
||
|
{ KSelectAction::virtual_hook( id, data ); }
|
||
|
|
||
|
void KActionMenu::virtual_hook( int id, void* data )
|
||
|
{ KAction::virtual_hook( id, data ); }
|
||
|
|
||
|
void KToolBarPopupAction::virtual_hook( int id, void* data )
|
||
|
{ KAction::virtual_hook( id, data ); }
|
||
|
|
||
|
void KToggleToolBarAction::virtual_hook( int id, void* data )
|
||
|
{ KToggleAction::virtual_hook( id, data ); }
|
||
|
|
||
|
void KToggleFullScreenAction::virtual_hook( int id, void* data )
|
||
|
{ KToggleAction::virtual_hook( id, data ); }
|
||
|
|
||
|
void KWidgetAction::virtual_hook( int id, void* data )
|
||
|
{ KAction::virtual_hook( id, data ); }
|
||
|
|
||
|
void KActionSeparator::virtual_hook( int id, void* data )
|
||
|
{ KAction::virtual_hook( id, data ); }
|
||
|
|
||
|
void KPasteTextAction::virtual_hook( int id, void* data )
|
||
|
{ KAction::virtual_hook( id, data ); }
|
||
|
|
||
|
/* vim: et sw=2 ts=2
|
||
|
*/
|
||
|
|
||
|
#include "kactionclasses.moc"
|