diff options
author | Slávek Banko <[email protected]> | 2016-03-26 13:50:43 +0100 |
---|---|---|
committer | Slávek Banko <[email protected]> | 2016-03-26 13:50:43 +0100 |
commit | d62c8c002c51fb7c36487839eeeb4ac89f044dee (patch) | |
tree | bb4d1f5c631ab1f22a3018ba39e6a806035f80fd /part/actions.cpp | |
download | kxmleditor-d62c8c002c51fb7c36487839eeeb4ac89f044dee.tar.gz kxmleditor-d62c8c002c51fb7c36487839eeeb4ac89f044dee.zip |
Initial import of kxmleditor 1.1.4
Diffstat (limited to 'part/actions.cpp')
-rw-r--r-- | part/actions.cpp | 229 |
1 files changed, 229 insertions, 0 deletions
diff --git a/part/actions.cpp b/part/actions.cpp new file mode 100644 index 0000000..8b6abcb --- /dev/null +++ b/part/actions.cpp @@ -0,0 +1,229 @@ +/*************************************************************************** + actions.cpp - description + ------------------- + begin : Tue Jul 10 2001 + copyright : (C) 2001, 2002, 2003 by The KXMLEditor Team + email : [email protected] + ***************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + +#include "actions.h" + +// include files for QT + +#include <qwhatsthis.h> +#include <qdragobject.h> +#include <qcombobox.h> +#include <qapplication.h> + +// include files for KDE +#include <ktoolbar.h> +#include <kiconloader.h> +#include <kmimetype.h> +#include <kdebug.h> + +//------------------------------------------------------------------- +// +// KXmlEditorComboAction member functions +// +//------------------------------------------------------------------- + +KXmlEditorComboAction::KXmlEditorComboAction(const QString& text, + int accel, + const QObject *receiver, + const char *member, + QObject* parent, + const char* name) + : KAction(text, accel, parent, name), + m_pCombo(0) +{ + m_receiver = receiver; + m_member = member; +} + +KXmlEditorComboAction::~KXmlEditorComboAction() +{ + //delete m_pCombo; // L.V. this cause crash !!! +} + +QComboBox* KXmlEditorComboAction::comboBox() +{ + return m_pCombo; +} + +int KXmlEditorComboAction::plug(QWidget *w, int index) +{ + // if ( !w->inherits( "KToolBar" ) ); + // return -1; + + KToolBar *toolBar = (KToolBar *) w; + + int id = KAction::getToolButtonID(); + //kdDebug() << "KXmlEditorComboAction::plug id=" << id << endl; + + m_pCombo = new QComboBox( toolBar, "Path Combo" ); + m_pCombo->setEditable(true); + m_pCombo->setInsertionPolicy(QComboBox::NoInsertion); + toolBar->insertWidget( id, 70, m_pCombo, index ); + connect( m_pCombo, SIGNAL(activated(const QString&)), m_receiver, m_member ); + + addContainer( toolBar, id ); + + connect(toolBar, SIGNAL(destroyed()), this, SLOT(slotDestroyed())); + + toolBar->setItemAutoSized(id, true); + + QWhatsThis::add( m_pCombo, whatsThis() ); + + return containerCount() - 1; +} + +void KXmlEditorComboAction::unplug(QWidget *w) +{ +// if ( !w->inherits( "KToolBar" ) ) +// return; + + KToolBar *toolBar = (KToolBar *)w; + + int idx = findContainer( w ); + //kdDebug() << "KXmlEditorComboAction::unplug idx=" << idx << " menuId=" << menuId(idx) << endl; + + toolBar->removeItem( menuId( idx ) ); + + removeContainer( idx ); + m_pCombo = 0; +} + +void KXmlEditorComboAction::slotClear() +{ + if ( containerCount() == 0 ) + { + kdWarning() << "[KXmlEditorComboAction::slotClear] action not plugged" << endl; + return; + } + + m_pCombo->clear(); +} + +void KXmlEditorComboAction::slotClearEdit() +{ + if ( containerCount() == 0 ) + { + kdWarning() << "[KXmlEditorComboAction::slotClearEdit] action not plugged" << endl; + return; + } + + m_pCombo->clearEdit(); +} + +void KXmlEditorComboAction::slotFocusEdit() +{ + if ( containerCount() == 0 ) + { + kdWarning() << "[KXmlEditorComboAction::slotFocusEdit] action not plugged" << endl; + return; + } + + m_pCombo->setFocus(); +} + +QString KXmlEditorComboAction::currentText() const +{ + if ( containerCount() == 0 ) + { + kdWarning() << "[KXmlEditorComboAction::currentText] action not plugged" << endl; + return QString::null; + } + + return m_pCombo->currentText(); +} + +const QPixmap * KXmlEditorComboAction::currentPixmap() const +{ + if ( containerCount() == 0 ) + { + kdWarning() << "[KXmlEditorComboAction::currentPixmap] action not plugged" << endl; + return 0; + } + + return m_pCombo->pixmap( m_pCombo->currentItem() ); +} + +void KXmlEditorComboAction::insertItem( const QPixmap & pixmap, const QString & text ) +{ + if ( containerCount() == 0 ) + { + kdWarning() << "[KXmlEditorComboAction::insertItem] action not plugged" << endl; + return; + } + + if ( text.isEmpty() ) + kdWarning() << "[KXmlEditorComboAction::insertItem] empty string as parameter" << endl; + + int nIndex = findItem(text); + if ( nIndex != -1 ) + m_pCombo->removeItem(nIndex); + + m_pCombo->insertItem( pixmap, text, 0 ); + m_pCombo->setCurrentItem(0); + + if ( m_pCombo->count() > 15 ) + m_pCombo->removeItem(15); +} + +void KXmlEditorComboAction::removeItem( const QString & text ) +{ + if ( containerCount() == 0 ) + { + kdWarning() << "[KXmlEditorComboAction::removeItem] action not plugged" << endl; + return; + } + + int nIndex = findItem(text); + if ( nIndex == -1 ) + { + kdDebug() << "KXmlEditorComboAction::removeItem] item not found" << endl; + return; + } + + m_pCombo->removeItem(nIndex); +} + +int KXmlEditorComboAction::findItem( const QString & text ) +{ + if ( containerCount() == 0 ) + { + kdWarning() << "[KXmlEditorComboAction::findItem] action not plugged" << endl; + return -1; + } + + int nIndex = -1; + int i=0; + while ( ( i < m_pCombo->count() ) && ( nIndex == -1 ) ) + { + if ( m_pCombo->text(i) == text ) + nIndex = i; + i++; + } + + return nIndex; +} + +ToolbarLabel::ToolbarLabel( const QString& text ) + : QLabel( text, 0L, "kde toolbar widget" ) // Use this name for it to be styled! +// , m_mw(mw) +{ + setBackgroundMode( Qt::PaletteButton ); + setAlignment( (QApplication::reverseLayout() ? Qt::AlignRight : Qt::AlignLeft) | + Qt::AlignVCenter | Qt::ShowPrefix ); + adjustSize(); + } + |