krita

kis_cmb_composite.cc

00001 /*
00002  *  kis_cmb_composite.cc - part of KImageShop/Krayon/Krita
00003  *
00004  *  Copyright (c) 2004 Boudewijn Rempt (boud@valdyas.org)
00005  *
00006  *  This program is free software; you can redistribute it and/or modify
00007  *  it under the terms of the GNU General Public License as published by
00008  *  the Free Software Foundation; either version 2 of the License, or
00009  *  (at your option) any later version.
00010  *
00011  *  This program is distributed in the hope that it will be useful,
00012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  *  GNU General Public License for more details.
00015  *
00016  *  You should have received a copy of the GNU General Public License
00017  *  along with this program; if not, write to the Free Software
00018  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00019  */
00020 
00021 #include <qcombobox.h>
00022 
00023 #include <klocale.h>
00024 #include <kdebug.h>
00025 
00026 #include "kis_cmb_composite.h"
00027 
00028 KisCmbComposite::KisCmbComposite(QWidget * parent, const char * name)
00029     : super( false, parent, name )
00030 {
00031     connect(this, SIGNAL(activated(int)), this, SLOT(slotOpActivated(int)));
00032     connect(this, SIGNAL(highlighted(int)), this, SLOT(slotOpHighlighted(int)));
00033 }
00034 
00035 KisCmbComposite::~KisCmbComposite()
00036 {
00037 }
00038 
00039 void KisCmbComposite::setCompositeOpList(const KisCompositeOpList & list)
00040 {
00041     super::clear();
00042     m_list = list;
00043     KisCompositeOpList::iterator it;
00044         for( it = m_list.begin(); it != m_list.end(); ++it )
00045         insertItem((*it).id().name());
00046 }
00047 
00048 KisCompositeOp KisCmbComposite::currentItem() const
00049 {
00050     Q_UINT32 i = super::currentItem();
00051     if (i > m_list.count()) return KisCompositeOp();
00052 
00053     return m_list[i];
00054 }
00055 
00056 void KisCmbComposite::setCurrentItem(const KisCompositeOp& op)
00057 {
00058     if (m_list.find(op) != m_list.end()) {
00059         super::setCurrentText(op.id().name());
00060     }
00061 }
00062 
00063 void KisCmbComposite::setCurrentText(const QString & s)
00064 {
00065     KisCompositeOpList::iterator it;
00066         for( it = m_list.begin(); it != m_list.end(); ++it )
00067         if ((*it).id().id() == s) {
00068             super::setCurrentText((*it).id().name());
00069         }
00070 }
00071 
00072 void KisCmbComposite::slotOpActivated(int i)
00073 {
00074     if ((Q_UINT32)i > m_list.count()) return;
00075 
00076     emit activated(m_list[i]);
00077 }
00078 
00079 void KisCmbComposite::slotOpHighlighted(int i)
00080 {
00081     if ((Q_UINT32)i > m_list.count()) return;
00082 
00083     emit highlighted(m_list[i]);
00084 }
00085 
00086 
00087 #include "kis_cmb_composite.moc"
00088 
KDE Home | KDE Accessibility Home | Description of Access Keys