23#include <tqstringlist.h>
24#include <tqtoolbutton.h>
27#include <tdeapplication.h>
28#include <kiconloader.h>
29#include <tdefiledialog.h>
31#include <kicondialog.h>
33#include <kicontheme.h>
35#include <tdepopupmenu.h>
38#include <tdemessagebox.h>
40#include "pixmapcollection.h"
44 : TQObject(parent, name)
46 m_name = collectionName;
50PixmapCollection::addPixmapPath(
const KURL &url)
52 TQString name = url.filename();
53 while(m_pixmaps.contains(name))
56 int num = name.right(1).toInt(&ok, 10);
58 name = name.left(name.length()-1) + TQString::number(num+1);
63 m_pixmaps.insert(name, qMakePair(url.path(), 0));
68PixmapCollection::addPixmapName(
const TQString &icon,
int size)
71 while(m_pixmaps.contains(name))
74 int num = name.right(1).toInt(&ok, 10);
76 name = name.left(name.length()-1) + TQString::number(num+1);
81 m_pixmaps.insert(name, qMakePair(icon, size));
86PixmapCollection::removePixmap(
const TQString &name)
88 m_pixmaps.remove(name);
92PixmapCollection::getPixmap(
const TQString &name)
94 if(!m_pixmaps.contains(name))
96 kdDebug() <<
" The icon " << name <<
" you requested is not in the collection" << endl;
100 if(m_pixmaps[name].second != 0)
102 return kapp->iconLoader()->loadIcon(m_pixmaps[name].first, TDEIcon::NoGroup, m_pixmaps[name].second);
105 return TQPixmap(m_pixmaps[name].first);
109PixmapCollection::contains(
const TQString &name)
111 return m_pixmaps.contains(name);
115PixmapCollection::save(TQDomNode parentNode)
117 if(m_pixmaps.isEmpty())
120 TQDomDocument domDoc = parentNode.ownerDocument();
121 TQDomElement collection = domDoc.createElement(
"collection");
122 parentNode.appendChild(collection);
124 PixmapMap::ConstIterator it;
125 PixmapMap::ConstIterator endIt = m_pixmaps.constEnd();
126 for(it = m_pixmaps.constBegin(); it != endIt; ++it)
128 TQDomElement item = domDoc.createElement(
"pixmap");
129 collection.appendChild(item);
130 item.setAttribute(
"name", it.key());
131 if(it.data().second != 0)
132 item.setAttribute(
"size", TQString::number(it.data().second));
134 TQString text = it.data().first;
135 TQDomText textNode = domDoc.createTextNode(text);
136 item.appendChild(textNode);
141PixmapCollection::load(TQDomNode node)
143 TQDomDocument domDoc = node.ownerDocument();
144 for(TQDomNode n = node.firstChild(); !n.isNull(); n = n.nextSibling())
146 TQDomElement el = n.toElement();
147 TQPair<TQString, int> pair = qMakePair(el.text(), el.attribute(
"size").toInt());
148 m_pixmaps[el.attribute(
"name")] = pair;
153LoadIconDialog::LoadIconDialog(TQWidget *parent)
154: KDialogBase(parent,
"loadicon_dialog", true, i18n(
"Load KDE Icon by Name"), Ok|Cancel, Ok, false)
156 TQFrame *frame = makeMainWidget();
157 TQGridLayout *l =
new TQGridLayout(frame, 2, 3, 0, 6);
160 TQLabel *name =
new TQLabel(i18n(
"&Name:"), frame);
161 l->addWidget(name, 0, 0);
162 name->setAlignment(TQt::AlignRight|TQt::AlignVCenter);
163 m_nameInput =
new KLineEdit(
"kexi", frame);
164 l->addWidget(m_nameInput, 0, 1);
165 name->setBuddy(m_nameInput);
168 TQLabel *size =
new TQLabel(i18n(
"&Size:"), frame);
169 l->addWidget(size, 1, 0);
170 size->setAlignment(TQt::AlignRight|TQt::AlignVCenter);
172 KComboBox *combo =
new KComboBox(frame);
173 l->addWidget(combo, 1, 1);
174 size->setBuddy(combo);
176 list << i18n(
"Small") << i18n(
"Medium") << i18n(
"Large") << i18n(
"Huge");
177 combo->insertStringList(list);
178 combo->setCurrentItem(2);
179 connect(combo, TQ_SIGNAL(activated(
int)),
this, TQ_SLOT(changeIconSize(
int)));
183 m_button =
new TDEIconButton(frame);
184 m_button->setIcon(
"kexi");
185 m_button->setIconSize(TDEIcon::SizeMedium);
186 l->addMultiCellWidget(m_button, 0, 1, 2, 2);
187 connect(m_button, TQ_SIGNAL(iconChanged(TQString)),
this, TQ_SLOT(updateIconName(TQString)));
188 connect(m_nameInput, TQ_SIGNAL(textChanged(
const TQString &)),
this, TQ_SLOT(setIcon(
const TQString &)));
192LoadIconDialog::updateIconName(TQString icon)
194 m_nameInput->setText(icon);
198LoadIconDialog::setIcon(
const TQString &icon)
200 m_button->setIcon(icon);
204LoadIconDialog::changeIconSize(
int index)
206 int size = TDEIcon::SizeMedium;
209 case 0: size = TDEIcon::SizeSmall;
break;
211 case 1: size = TDEIcon::SizeMedium;
break;
212 case 2: size = TDEIcon::SizeLarge;
break;
213#if !defined(TQ_WS_WIN) && KDE_IS_VERSION(3,1,9)
214 case 3: size = TDEIcon::SizeHuge;
break;
219 m_button->setIconSize(size);
222int LoadIconDialog::iconSize()
224 return m_button->iconSize();
227TQString LoadIconDialog::iconName()
229 return m_button->icon();
234: KDialogBase(parent,
"pixcollection_dialog", true,
235 i18n(
"Edit Pixmap Collection: %1").arg(collection->collectionName()), Close, Close, false)
237 m_collection = collection;
238 TQFrame *frame = makeMainWidget();
239 TQHBoxLayout *l =
new TQHBoxLayout(frame, 0, 6);
240 setInitialSize(TQSize(400, 200),
true);
243 TQVBoxLayout *vlayout =
new TQVBoxLayout(l, 3);
244 TQToolButton *newItemPath =
new TQToolButton(frame);
245 newItemPath->setIconSet(BarIconSet(
"document-open"));
246 newItemPath->setTextLabel(i18n(
"&Add File"),
true);
247 vlayout->addWidget(newItemPath);
248 m_buttons.insert(BNewItemPath, newItemPath);
249 connect(newItemPath, TQ_SIGNAL(clicked()),
this, TQ_SLOT(newItemByPath()));
251 TQToolButton *newItemName =
new TQToolButton(frame);
252 newItemName->setIconSet(BarIconSet(
"icons"));
253 newItemName->setTextLabel(i18n(
"&Add an Icon"),
true);
254 vlayout->addWidget(newItemName);
255 m_buttons.insert(BNewItemName, newItemName);
256 connect(newItemName, TQ_SIGNAL(clicked()),
this, TQ_SLOT(newItemByName()));
258 TQToolButton *delItem =
new TQToolButton(frame);
259 delItem->setIconSet(BarIconSet(
"edit_remove"));
260 delItem->setTextLabel(i18n(
"&Remove Selected Item"),
true);
261 vlayout->addWidget(delItem);
262 m_buttons.insert(BDelItem, delItem);
263 connect(delItem, TQ_SIGNAL(clicked()),
this, TQ_SLOT(removeItem()));
264 vlayout->addStretch();
267 m_iconView =
new TDEIconView(frame,
"pixcollection_iconView");
268 m_iconView->resize(100,100);
269 m_iconView->setArrangement(TQIconView::LeftToRight);
270 m_iconView->setAutoArrange(
true);
271 m_iconView->setMode(TDEIconView::Select);
272 l->addWidget(m_iconView);
273 connect(m_iconView, TQ_SIGNAL(contextMenuRequested(TQIconViewItem*,
const TQPoint&)),
this, TQ_SLOT(displayMenu(TQIconViewItem*,
const TQPoint&)));
274 connect(m_iconView, TQ_SIGNAL(itemRenamed(TQIconViewItem*,
const TQString &)),
this, TQ_SLOT(renameCollectionItem(TQIconViewItem*,
const TQString&)));
276 PixmapMap::ConstIterator it;
277 PixmapMap::ConstIterator endIt = collection->m_pixmaps.end();
278 for(it = collection->m_pixmaps.constBegin(); it != endIt; ++it)
279 createIconViewItem(it.key());
283PixmapCollectionEditor::newItemByName()
286 if(d.exec()== TQDialog::Accepted)
288 if(d.iconName().isEmpty())
291 TQString name = m_collection->addPixmapName(d.iconName(), d.iconSize());
292 createIconViewItem(name);
297PixmapCollectionEditor::newItemByPath()
299 KURL url = KFileDialog::getImageOpenURL(
"::kexi", parentWidget());
302 TQString name = m_collection->addPixmapPath(url);
303 createIconViewItem(name);
307PixmapCollectionEditor::removeItem()
309 TQIconViewItem *item = m_iconView->currentItem();
313 int confirm = KMessageBox::questionYesNo(parentWidget(), TQString(
"<qt>")+
314 i18n(
"Do you want to remove item \"%1\" from collection \"%2\"?")
315 .arg(item->text()).arg(m_collection->collectionName()) +
"</qt>");
316 if(confirm == KMessageBox::No)
319 m_collection->removePixmap(item->text());
324PixmapCollectionEditor::renameItem()
326 if(m_iconView->currentItem())
327 m_iconView->currentItem()->rename();
331PixmapCollectionEditor::createIconViewItem(
const TQString &name)
334 item->setRenameEnabled(
true);
338PixmapCollectionEditor::getPixmap(
const TQString &name)
340 TQPixmap pixmap = m_collection->getPixmap(name);
341 if((pixmap.width() <= 48) && (pixmap.height() <= 48))
345 TQImage image = io.convertToImage(pixmap);
346 pixmap = io.convertToPixmap(image.scale(48, 48, TQImage::ScaleMin));
351PixmapCollectionEditor::renameCollectionItem(TQIconViewItem *it,
const TQString &name)
354 if(!m_collection->m_pixmaps.contains(item->name()))
358 TQPair<TQString, int> pair = m_collection->m_pixmaps[item->name()];
359 m_collection->m_pixmaps.remove(item->name());
360 m_collection->m_pixmaps[name] = pair;
365PixmapCollectionEditor::displayMenu(TQIconViewItem *it,
const TQPoint &p)
368 TDEPopupMenu *menu =
new TDEPopupMenu();
369 menu->insertItem(SmallIconSet(
"edit"), i18n(
"Rename Item"),
this, TQ_SLOT(renameItem()));
370 menu->insertItem(SmallIconSet(
"remove"), i18n(
"Remove Item"),
this, TQ_SLOT(removeItem()));
375PixmapCollectionChooser::PixmapCollectionChooser(
PixmapCollection *collection,
const TQString &selectedItem, TQWidget *parent)
376: KDialogBase(parent,
"pixchoose_dialog", true, i18n(
"Select Pixmap From %1").arg(collection->collectionName()),
377 User1|Ok|Cancel, Ok, false, KGuiItem(i18n(
"Edit Collection...")))
379 m_collection = collection;
380 setInitialSize(TQSize(400, 200),
true);
382 m_iconView =
new TDEIconView(
this,
"pixchooser_iconView");
383 setMainWidget(m_iconView);
384 m_iconView->setArrangement(TQIconView::LeftToRight);
385 m_iconView->setAutoArrange(
true);
386 m_iconView->setMode(TDEIconView::Select);
388 PixmapMap::ConstIterator it;
389 PixmapMap::ConstIterator endIt = collection->m_pixmaps.constEnd();
390 for(it = collection->m_pixmaps.constBegin(); it != endIt; ++it)
393 TQIconViewItem *item = m_iconView->findItem(selectedItem, TQt::ExactMatch);
394 if(item && !selectedItem.isEmpty())
395 m_iconView->setCurrentItem(item);
399PixmapCollectionChooser::pixmap()
401 if(! m_iconView->currentItem())
403 TQString name = m_iconView->currentItem()->text();
404 return m_collection->getPixmap(name);
408PixmapCollectionChooser::pixmapName()
410 return m_iconView->currentItem() ? m_iconView->currentItem()->text() : TQString(
"");
414PixmapCollectionChooser::getPixmap(
const TQString &name)
416 TQPixmap pixmap = m_collection->getPixmap(name);
417 if((pixmap.width() <= 48) && (pixmap.height() <= 48))
422 TQImage image = io.convertToImage(pixmap);
423 pixmap = io.convertToPixmap(image.scale(48, 48, TQImage::ScaleMin));
428PixmapCollectionChooser::slotUser1()
434 PixmapMap::ConstIterator it;
435 PixmapMap::ConstIterator endIt = m_collection->m_pixmaps.constEnd();
436 for(it = m_collection->m_pixmaps.constBegin(); it != endIt; ++it)
440#include "pixmapcollection.moc"
A simple dialog to choose a KDE icon.
A dialog to edit the contents of a PixmapCollection.
PixmapCollectionEditor(PixmapCollection *collection, TQWidget *parent=0)
Pixmap Collection Editor Dialog.
A class that store pixmaps (by path or by name for KDE icons)
PixmapCollection(const TQString &collectionName, TQObject *parent=0, const char *name=0)
Pixmap Collection.
A Special TDEIconViewItem that holds the name of its associated pixmap (to allow renaming)