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.
119 lines
3.0 KiB
119 lines
3.0 KiB
15 years ago
|
/*
|
||
|
* This file is part of the KDE libraries
|
||
13 years ago
|
* Copyright (c) 2001 Michael Goffioul <tdeprint@swing.be>
|
||
15 years ago
|
*
|
||
|
* 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 "kiconselectaction.h"
|
||
|
|
||
15 years ago
|
#include <tqpopupmenu.h>
|
||
15 years ago
|
#include <kiconloader.h>
|
||
|
#include <kdebug.h>
|
||
|
#include <ktoolbar.h>
|
||
|
#include <ktoolbarbutton.h>
|
||
|
|
||
|
class KIconSelectActionPrivate
|
||
|
{
|
||
|
public:
|
||
|
KIconSelectActionPrivate()
|
||
|
{
|
||
|
m_menu = 0;
|
||
|
}
|
||
14 years ago
|
TQStringList m_iconlst;
|
||
15 years ago
|
TQPopupMenu* m_menu;
|
||
15 years ago
|
};
|
||
|
|
||
15 years ago
|
KIconSelectAction::KIconSelectAction(const TQString& text, int accel, TQObject* parent, const char* name)
|
||
15 years ago
|
: KSelectAction(text, accel, parent, name)
|
||
|
{
|
||
|
d = new KIconSelectActionPrivate;
|
||
|
}
|
||
|
|
||
|
KIconSelectAction::~KIconSelectAction()
|
||
|
{
|
||
|
delete d;
|
||
|
}
|
||
|
|
||
|
void KIconSelectAction::updateIcons()
|
||
|
{
|
||
|
if (d->m_menu)
|
||
|
{
|
||
14 years ago
|
TQStringList lst = items();
|
||
15 years ago
|
for (uint id=0; id<lst.count(); ++id)
|
||
|
d->m_menu->changeItem(id, SmallIconSet(d->m_iconlst[id]), lst[id]);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void KIconSelectAction::createPopupMenu()
|
||
|
{
|
||
|
if (!d->m_menu)
|
||
|
{
|
||
|
d->m_menu = popupMenu();
|
||
|
updateIcons();
|
||
|
}
|
||
|
}
|
||
|
|
||
15 years ago
|
void KIconSelectAction::setItems(const TQStringList& lst, const TQStringList& iconlst)
|
||
15 years ago
|
{
|
||
|
KSelectAction::setItems(lst);
|
||
|
d->m_iconlst = iconlst;
|
||
|
updateIcons();
|
||
|
}
|
||
|
|
||
15 years ago
|
int KIconSelectAction::plug(TQWidget* widget, int index)
|
||
15 years ago
|
{
|
||
|
int value(-1);
|
||
14 years ago
|
if (widget->inherits(TQPOPUPMENU_OBJECT_NAME_STRING))
|
||
15 years ago
|
{
|
||
|
createPopupMenu();
|
||
|
value = KSelectAction::plug(widget, index);
|
||
|
}
|
||
|
else if (widget->inherits("KToolBar"))
|
||
|
{
|
||
|
KToolBar* bar = static_cast<KToolBar*>(widget);
|
||
|
int id = KAction::getToolButtonID();
|
||
14 years ago
|
// To have a correct layout in the toolbar, a non
|
||
15 years ago
|
// empty icon has to be used. Use "unknown" by default.
|
||
14 years ago
|
TQString iconName = (currentItem() != -1 ? d->m_iconlst[currentItem()] : "unknown");
|
||
15 years ago
|
|
||
|
createPopupMenu();
|
||
|
bar->insertButton(iconName, id, true, plainText(), index);
|
||
|
bar->getButton(id)->setPopup(d->m_menu, true);
|
||
|
bar->setItemEnabled(id, isEnabled());
|
||
|
addContainer(bar, id);
|
||
15 years ago
|
connect(bar, TQT_SIGNAL(destroyed()), TQT_SLOT(slotDestroyed()));
|
||
15 years ago
|
|
||
|
value = containerCount()-1;
|
||
|
}
|
||
|
return value;
|
||
|
}
|
||
|
|
||
|
void KIconSelectAction::updateCurrentItem(int id)
|
||
|
{
|
||
15 years ago
|
TQWidget* w = container(id);
|
||
15 years ago
|
if (w->inherits("KToolBar"))
|
||
|
static_cast<KToolBar*>(w)->getButton(itemId(id))->setIcon(d->m_iconlst[currentItem()]);
|
||
|
else
|
||
|
KSelectAction::updateCurrentItem(id);
|
||
|
}
|
||
|
|
||
|
void KIconSelectAction::setCurrentItem(int index)
|
||
|
{
|
||
|
KSelectAction::setCurrentItem(index);
|
||
|
}
|
||
|
|
||
|
#include "kiconselectaction.moc"
|