24#include <tqtextstream.h>
26#include <tqwhatsthis.h>
29#include <ksimpleconfig.h>
31#include <kstandarddirs.h>
32#include <kicondialog.h>
34#include <KPrFactory.h>
36AFChoose::AFChoose(TQWidget *parent,
const TQString &caption,
const char *name)
37 : TQTabDialog(parent,name,true)
40 setCancelButton(i18n(
"&Cancel"));
41 setOkButton(i18n(
"&OK"));
42 groupList.setAutoDelete(
true);
45 connect(
this,TQ_SIGNAL(applyButtonPressed()),
this,TQ_SLOT(chosen()));
46 connect(
this,TQ_SIGNAL(cancelButtonPressed()),
this,TQ_SLOT(cancelClicked()));
53void AFChoose::getGroups()
56 TQString afDir = locate(
"autoforms",
".autoforms", KPrFactory::global() );
59 if ( f.open(IO_ReadOnly) ) {
66 TQString directory=TQFileInfo( afDir ).dirPath() +
"/" + s.simplifyWhiteSpace();
67 grpPtr->dir.setFile(directory);
69 if(d.exists(
".directory")) {
70 KSimpleConfig config(d.absPath()+
"/.directory",
true);
71 config.setDesktopGroup();
72 grpPtr->name=config.readEntry(
"Name");
74 groupList.append( grpPtr );
81void AFChoose::setupTabs()
83 if (!groupList.isEmpty())
85 for (grpPtr=groupList.first();grpPtr != 0;grpPtr=groupList.next())
87 grpPtr->tab =
new TQVBox(
this);
88 TQWhatsThis::add(grpPtr->tab, i18n(
"Choose a predefined shape by clicking on it then clicking the OK button (or just double-click on the shape). You can then insert the shape onto your slide by drawing the area with the mouse pointer." ) );
89 grpPtr->loadWid =
new TDEIconCanvas(grpPtr->tab);
91 TQDir d( grpPtr->dir.absFilePath() );
92 d.setNameFilter(
"*.desktop" );
94 TQStringList files=d.entryList( TQDir::Files | TQDir::Readable, TQDir::Name );
95 for(
unsigned int i=0; i<files.count(); ++i) {
96 TQString path=grpPtr->dir.absFilePath() + TQChar(
'/');
97 files[i]=path + files[i];
98 KSimpleConfig config(files[i]);
99 config.setDesktopGroup();
100 if (config.readEntry(
"Type")==
"Link") {
101 TQString text=config.readEntry(
"Name");
102 TQString icon=config.readEntry(
"Icon");
105 TQString filename=config.readPathEntry(
"URL");
106 if(filename[0]!=
'/') {
107 if(filename.left(6)==
"file:/")
108 filename=filename.right(filename.length()-6);
109 filename=path + filename;
111 grpPtr->entries.insert(text, filename);
117 kdWarning() <<
"Couldn't find icon " << icon << endl;
120 if (img.width() > 60 || img.height() > 60) {
121 if (img.width() > img.height()) {
122 int height = (int) ((60.0 / img.width()) * img.height());
123 img = img.smoothScale(60, height);
125 int width = (int) ((60.0 / img.height()) * img.width());
126 img = img.smoothScale(width, 60);
130 pic.convertFromImage(img);
131 TQIconViewItem *item =
new TQIconViewItem(grpPtr->loadWid, text, pic);
133 item->setDragEnabled(
false);
134 item->setDropEnabled(
false);
139 grpPtr->loadWid->setBackgroundColor(colorGroup().base());
140 grpPtr->loadWid->setResizeMode(TQIconView::Adjust);
141 grpPtr->loadWid->sort();
142 connect(grpPtr->loadWid,TQ_SIGNAL(nameChanged(TQString)),
143 this,TQ_SLOT(nameChanged(TQString)));
144 connect(
this, TQ_SIGNAL(currentChanged(TQWidget *)),
this,
145 TQ_SLOT(tabChanged(TQWidget*)));
146 connect(grpPtr->loadWid,TQ_SIGNAL( doubleClicked ( TQIconViewItem *)),
this,
147 TQ_SLOT(slotDoubleClick()));
148 grpPtr->label =
new TQLabel(grpPtr->tab);
149 grpPtr->label->setText(
" ");
150 grpPtr->label->setMaximumHeight(grpPtr->label->sizeHint().height());
151 addTab(grpPtr->tab,grpPtr->name);
156void AFChoose::slotDoubleClick()
162void AFChoose::nameChanged(TQString name)
164 for (grpPtr=groupList.first();grpPtr != 0;grpPtr=groupList.next())
165 grpPtr->label->setText(name);
168void AFChoose::tabChanged(TQWidget *w) {
170 for(grpPtr=groupList.first();grpPtr != 0;grpPtr=groupList.next()) {
172 grpPtr->label->setText(grpPtr->loadWid->getCurrent());
176void AFChoose::chosen()
178 if (!groupList.isEmpty())
180 for (grpPtr=groupList.first();grpPtr != 0;grpPtr=groupList.next())
182 if (grpPtr->tab->isVisible() && !grpPtr->loadWid->getCurrent().isEmpty())
183 emit formChosen(grpPtr->entries[grpPtr->loadWid->getCurrent()]);
185 emit afchooseCanceled();
190void AFChoose::cancelClicked()
192 emit afchooseCanceled();
195void AFChoose::closeEvent ( TQCloseEvent *e )
197 emit afchooseCanceled();
198 TQTabDialog::closeEvent ( e );
201#include "AFChoose.moc"