lib Library API Documentation

koTemplateChooseDia.cc

00001 /* This file is part of the KDE project
00002    Copyright (C) 1998, 1999 Reginald Stadlbauer <reggie@kde.org>
00003    2000, 2001 Werner Trobin <trobin@kde.org>
00004    2002, 2003 Thomas Nagy <tnagy@eleve.emn.fr>
00005 
00006    This library is free software; you can redistribute it and/or
00007    modify it under the terms of the GNU Library General Public
00008    License as published by the Free Software Foundation; either
00009    version 2 of the License, or (at your option) any later version.
00010 
00011    This library 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 GNU
00014    Library General Public License for more details.
00015 
00016    You should have received a copy of the GNU Library General Public License
00017    along with this library; see the file COPYING.LIB.  If not, write to
00018    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00019    Boston, MA 02111-1307, USA.
00020    */
00021 
00022 // Description: Template Choose Dialog
00023 
00024 /******************************************************************/
00025 
00026 #include <qlayout.h>
00027 #include <qtabwidget.h>
00028 #include <qcombobox.h>
00029 #include <qcheckbox.h>
00030 #include <qpoint.h>
00031 #include <qobjectlist.h>
00032 #include <qvgroupbox.h>
00033 
00034 #include <klocale.h>
00035 #include <kdeversion.h>
00036 #include <kfiledialog.h>
00037 #include <kinstance.h>
00038 #include <koFilterManager.h>
00039 #include <koTemplates.h>
00040 #include <koDocument.h>
00041 #include <kmainwindow.h>
00042 
00043 #include "koTemplateChooseDia.h"
00044 #include <kdebug.h>
00045 
00046 #include <kpushbutton.h>
00047 #include <kjanuswidget.h>
00048 #include <kglobalsettings.h>
00049 #include <ktextedit.h>
00050 #include <kfileiconview.h>
00051 #include <kfileitem.h>
00052 #include <kmessagebox.h>
00053 #include <qapplication.h>
00054 #include <qtooltip.h>
00055 #include <kapplication.h>
00056 
00057 class MyFileDialog : public KFileDialog
00058 {
00059     public :
00060         MyFileDialog(
00061                 const QString& startDir=0,
00062                 const QString& filter =0,
00063                 QWidget *parent=0,
00064                 const char *name=0,
00065                 bool modal=0)
00066             :  KFileDialog (startDir, filter, parent, name, modal) {}
00067 
00068         KURL currentURL()
00069         {
00070             setResult( QDialog::Accepted ); // selectedURL tests for it
00071             return KFileDialog::selectedURL();
00072         }
00073 
00074         // Return true if the current URL exists, show msg box if not
00075         bool checkURL()
00076         {
00077             bool ok = true;
00078             KURL url = currentURL();
00079             if ( url.isLocalFile() )
00080             {
00081                 ok = QFile::exists( url.path() );
00082                 if ( !ok ) {
00083                     // Maybe offer to create a new document with that name? (see alos KoDocument::openFile)
00084                     KMessageBox::error( this, i18n( "The file %1 doesn't exist." ).arg( url.path() ) );
00085                 }
00086             }
00087             return ok;
00088         }
00089     protected:
00090     // Typing a file that doesn't exist closes the file dialog, we have to
00091     // handle this case better here.
00092         virtual void accept() {
00093             if ( checkURL() )
00094                 KFileDialog::accept();
00095         }
00096 
00097         virtual void reject() {
00098         KFileDialog::reject();
00099         emit cancelClicked();
00100         }
00101 
00102 };
00103 
00104 /*================================================================*/
00105 
00106 /*================================================================*/
00107 
00108 class KoTemplateChooseDiaPrivate {
00109     public:
00110     KoTemplateChooseDiaPrivate(const QCString& templateType, KInstance* global,
00111         const QCString &format, const QString &nativePattern,
00112         const QString &nativeName,
00113         const KoTemplateChooseDia::DialogType &dialogType) :
00114         m_templateType(templateType), m_global(global), m_format(format),
00115     m_nativePattern(nativePattern), m_nativeName(nativeName),
00116     m_dialogType(dialogType), tree(0L), m_mainwidget(0L)
00117     {
00118         m_returnType = KoTemplateChooseDia::Empty;
00119         m_nostartupdlg = false;
00120         tree = 0;
00121         m_nodiag = 0;
00122     }
00123 
00124     ~KoTemplateChooseDiaPrivate() {}
00125 
00126     QCString m_templateType;
00127     KInstance* m_global;
00128     QCString m_format;
00129     QString m_nativePattern;
00130     QString m_nativeName;
00131     KoTemplateChooseDia::DialogType m_dialogType;
00132     KoTemplateTree *tree;
00133 
00134     QString m_templateName;
00135     QString m_fullTemplateName;
00136     KoTemplateChooseDia::ReturnType m_returnType;
00137 
00138     bool m_nostartupdlg;
00139 
00140     // the main widget
00141     QWidget *m_mainwidget;
00142 
00143     // do not show this dialog at startup
00144     QCheckBox *m_nodiag;
00145 
00146     // choose a template
00147     KJanusWidget * m_jwidget;
00148     KFileIconView *m_recent;
00149     QVGroupBox * boxdescription;
00150     KTextEdit * textedit;
00151 
00152     // choose a file
00153     MyFileDialog *m_filedialog;
00154 
00155     // for the layout
00156     QTabWidget* tabWidget;
00157     QWidget* newTab;
00158     QWidget* existingTab;
00159     QWidget* recentTab;
00160 
00161 };
00162 
00163 /******************************************************************/
00164 /* Class: KoTemplateChooseDia                                     */
00165 /******************************************************************/
00166 
00167 /*================================================================*/
00168 KoTemplateChooseDia::KoTemplateChooseDia(QWidget *parent, const char *name, KInstance* global,
00169     const QCString &format, const QString &nativePattern,
00170     const QString &nativeName, const DialogType &dialogType,
00171     const QCString& templateType) :
00172 KDialogBase(parent, name, true, i18n("Open Document"), KDialogBase::Ok | KDialogBase::Cancel,
00173     KDialogBase::Ok) {
00174 
00175     d = new KoTemplateChooseDiaPrivate(
00176         templateType,
00177         global,
00178         format,
00179         nativePattern,
00180         nativeName,
00181         dialogType);
00182 
00183     QPushButton* ok = actionButton( KDialogBase::Ok );
00184     QPushButton* cancel = actionButton( KDialogBase::Cancel );
00185     cancel->setAutoDefault(false);
00186     ok->setDefault(true);
00187     //enableButtonOK(false);
00188 
00189     if (!templateType.isNull() && !templateType.isEmpty() && dialogType!=NoTemplates)
00190     d->tree=new KoTemplateTree(templateType, global, true);
00191 
00192     d->m_mainwidget=makeMainWidget();
00193 
00194     d->m_templateName = "";
00195     d->m_fullTemplateName = "";
00196     d->m_returnType = Cancel;
00197 
00198     setupDialog();
00199 
00200 }
00201 
00202 KoTemplateChooseDia::~KoTemplateChooseDia()
00203 {
00204     delete d->tree;
00205     delete d;
00206     d=0L;
00207 }
00208 
00209 static bool cancelQuits() {
00210     bool onlyDoc = !KoDocument::documentList() || KoDocument::documentList()->count() <= 1;
00211     bool onlyMainWindow = !KMainWindow::memberList || KMainWindow::memberList->count() <= 1;
00212     return onlyDoc && onlyMainWindow && kapp->instanceName() != "koshell"; // hack for koshell
00213 }
00214 
00215 /*================================================================*/
00216 // static
00217 KoTemplateChooseDia::ReturnType KoTemplateChooseDia::choose(KInstance* global, QString &file,
00218     const QCString &format, const QString &nativePattern,
00219     const QString &nativeName,
00220     const KoTemplateChooseDia::DialogType &dialogType,
00221     const QCString& templateType) {
00222 
00223     KoTemplateChooseDia *dlg = new KoTemplateChooseDia( 0, "Choose", global, format, nativePattern,
00224         nativeName, dialogType, templateType);
00225 
00226     KoTemplateChooseDia::ReturnType rt = Cancel;
00227 
00228     if (dlg->noStartupDlg())
00229     {
00230     // start with the default template
00231     file = dlg->getFullTemplate();
00232     rt = dlg->getReturnType();
00233     }
00234     else
00235     {
00236     dlg->resize( 700, 480 );
00237     if ( dlg->exec() == QDialog::Accepted )
00238     {
00239         file = dlg->getFullTemplate();
00240         rt = dlg->getReturnType();
00241     }
00242     }
00243 
00244     delete dlg;
00245     if ( rt == Cancel && dialogType == Everything && cancelQuits() )
00246         // The button says quit, so let's quit
00247         kapp->quit();
00248 
00249     return rt;
00250 }
00251 
00252 bool KoTemplateChooseDia::noStartupDlg() const {
00253     return d->m_nostartupdlg;
00254 }
00255 
00256 
00257 QString KoTemplateChooseDia::getTemplate() const{
00258     return d->m_templateName;
00259 }
00260 
00261 QString KoTemplateChooseDia::getFullTemplate() const{
00262     return d->m_fullTemplateName;
00263 }
00264 
00265 KoTemplateChooseDia::ReturnType KoTemplateChooseDia::getReturnType() const {
00266     return d->m_returnType;
00267 }
00268 
00269 KoTemplateChooseDia::DialogType KoTemplateChooseDia::getDialogType() const {
00270     return d->m_dialogType;
00271 }
00272 
00273 /*================================================================*/
00274 // private
00275 void KoTemplateChooseDia::setupRecentDialog(QWidget * widgetbase, QGridLayout * layout)
00276 {
00277 
00278         d->m_recent = new KoTCDRecentFilesIconView(widgetbase, "recent files");
00279         // I prefer the icons to be in "most recent first" order (DF)
00280         d->m_recent->setSorting( static_cast<QDir::SortSpec>( QDir::Time | QDir::Reversed ) );
00281         layout->addWidget(d->m_recent,0,0);
00282 
00283         QString oldGroup = d->m_global->config()->group();
00284         d->m_global->config()->setGroup( "RecentFiles" );
00285 
00286         int i = 0;
00287         QString value;
00288         do {
00289                 QString key=QString( "File%1" ).arg( i );
00290                 value=d->m_global->config()->readPathEntry( key );
00291                 if ( !value.isEmpty() ) {
00292                         KURL url(value);
00293                         KFileItem *item = new KFileItem( KFileItem::Unknown, KFileItem::Unknown, url );
00294                         d->m_recent->insertItem(item);
00295                 }
00296                 i++;
00297         } while ( !value.isEmpty() || i<=10 );
00298 
00299         d->m_global->config()->setGroup( oldGroup );
00300         d->m_recent->showPreviews();
00301 
00302     connect(d->m_recent, SIGNAL( doubleClicked ( QIconViewItem * ) ),
00303             this, SLOT( recentSelected( QIconViewItem * ) ) );
00304 
00305 }
00306 
00307 /*================================================================*/
00308 // private
00309 void KoTemplateChooseDia::setupFileDialog(QWidget * widgetbase, QGridLayout * layout)
00310 {
00311     QString dir = QString::null;
00312     QPoint point( 0, 0 );
00313 
00314     d->m_filedialog=new MyFileDialog(dir,
00315         QString::null,
00316         widgetbase,
00317         "file dialog",
00318         false);
00319 
00320     layout->addWidget(d->m_filedialog,0,0);
00321     d->m_filedialog->reparent( widgetbase , point );
00322     //d->m_filedialog->setOperationMode( KFileDialog::Opening);
00323 
00324     QObjectList *l = d->m_filedialog->queryList( "QPushButton" );
00325     QObjectListIt it( *l );
00326     QObject *obj;
00327     while ( (obj = it.current()) != 0 ) {
00328     ++it;
00329     ((QPushButton*)obj)->hide();
00330     }
00331     delete l;
00332 
00333     d->m_filedialog->setSizeGripEnabled ( FALSE );
00334     d->m_filedialog->setMimeFilter(
00335         KoFilterManager::mimeFilter( d->m_format, KoFilterManager::Import ));
00336 
00337     connect(d->m_filedialog, SIGNAL(  okClicked() ),
00338         this, SLOT (  slotOk() ));
00339 
00340     connect(d->m_filedialog, SIGNAL( cancelClicked() ),
00341         this, SLOT (  slotCancel() ));
00342 
00343 }
00344 
00345 /*================================================================*/
00346 // private
00347 void KoTemplateChooseDia::setupTemplateDialog(QWidget * widgetbase, QGridLayout * layout)
00348 {
00349 
00350     d->m_jwidget = new KJanusWidget(
00351         widgetbase,
00352         "kjanuswidget",
00353         KJanusWidget::IconList);
00354     layout->addWidget(d->m_jwidget,0,0);
00355 
00356     d->boxdescription = new QVGroupBox(
00357         i18n("Selected Template"),
00358         widgetbase,
00359         "boxdescription");
00360     layout->addWidget(d->boxdescription, 1, 0 );
00361 
00362     // config
00363     KConfigGroup grp( d->m_global->config(), "TemplateChooserDialog" );
00364     int templateNum = grp.readEntry( "TemplateTab" ).toInt();
00365     QString templateName = grp.readPathEntry( "TemplateName" );
00366 
00367     // item which will be selected initially
00368     QIconViewItem * itemtoselect = 0;
00369 
00370     // count the templates inserted
00371     int entriesnumber = 0;
00372 
00373     for ( KoTemplateGroup *group = d->tree->first(); group!=0L; group=d->tree->next() )
00374     {
00375     if (group->isHidden())
00376         continue;
00377 
00378     QFrame * frame = d->m_jwidget->addPage (
00379         group->name(),
00380         group->name(),
00381         group->first()->loadPicture());
00382 
00383     QGridLayout * layout = new QGridLayout(frame);
00384     KoTCDIconCanvas *canvas = new KoTCDIconCanvas( frame );
00385     layout->addWidget(canvas,0,0);
00386 
00387     canvas->setBackgroundColor( colorGroup().base() );
00388     canvas->setResizeMode(QIconView::Adjust);
00389     canvas->setWordWrapIconText( true );
00390     canvas->show();
00391 
00392     QIconViewItem * tempitem = canvas->load(group, templateName);
00393     if (tempitem)
00394         itemtoselect = tempitem;
00395 
00396     canvas->sort();
00397     canvas->setSelectionMode(QIconView::Single);
00398 
00399     connect( canvas, SIGNAL( clicked ( QIconViewItem * ) ),
00400         this, SLOT( currentChanged( QIconViewItem * ) ) );
00401 
00402     connect( canvas, SIGNAL( doubleClicked( QIconViewItem * ) ),
00403         this, SLOT( chosen(QIconViewItem *) ) );
00404 
00405     entriesnumber++;
00406     }
00407 
00408     d->boxdescription->setInsideMargin ( 3 );
00409     d->boxdescription->setInsideSpacing ( 3 );
00410 
00411     d->textedit = new KTextEdit( d->boxdescription );
00412     d->textedit->setReadOnly(1);
00413     d->textedit->setText(descriptionText(i18n("Empty Document"), i18n("Creates an empty document")));
00414     d->textedit->setLineWidth(0);
00415     d->textedit->setMaximumHeight(50);
00416 
00417     // Hide the widget if there is no template available. This should never happen ;-)
00418     if (!entriesnumber)
00419     d->m_jwidget->hide();
00420 
00421     // Set the initially shown page, possibly from the last usage of the dialog
00422     if (entriesnumber >= templateNum)
00423     d->m_jwidget->showPage(templateNum);
00424 
00425     // Set the initially selected template, possibly from the last usage of the dialog
00426     currentChanged(itemtoselect);
00427 
00428     // setup the checkbox
00429     QString translatedstring = i18n("Always start %1 with the selected template").arg(d->m_nativeName);
00430 
00431     d->m_nodiag = new QCheckBox ( translatedstring , widgetbase);
00432     layout->addWidget(d->m_nodiag, 2, 0);
00433     QString  startwithoutdialog = grp.readEntry( "NoStartDlg" );
00434     d->m_nodiag->setChecked( startwithoutdialog == QString("yes") );
00435 }
00436 
00437 /*================================================================*/
00438 // private
00439 void KoTemplateChooseDia::setupDialog()
00440 {
00441 
00442     QGridLayout *maingrid=new QGridLayout( d->m_mainwidget, 1, 1, 2, 6);
00443     KConfigGroup grp( d->m_global->config(), "TemplateChooserDialog" );
00444 
00445     if (d->m_dialogType == Everything)
00446     {
00447 
00448     // the user may want to start with his favorite template
00449     if (grp.readEntry( "NoStartDlg" ) == QString("yes") )
00450     {
00451         d->m_nostartupdlg = true;
00452         d->m_returnType = Empty;
00453 
00454         // no default template, just start with an empty document
00455         if (grp.readEntry("LastReturnType") == QString("Empty") )
00456         return;
00457 
00458         // start with the default template
00459         d->m_templateName = grp.readPathEntry( "TemplateName" );
00460         d->m_fullTemplateName = grp.readPathEntry( "FullTemplateName" );
00461 
00462         // be paranoid : invalid template means empty template
00463         if (!QFile::exists(d->m_fullTemplateName))
00464         return;
00465 
00466         if (d->m_fullTemplateName.length() < 2)
00467         return;
00468 
00469         d->m_returnType = Template;
00470         return;
00471     }
00472 
00473     if ( cancelQuits() )
00474         setButtonCancelText(i18n("&Quit"));
00475 
00476     d->tabWidget = new QTabWidget( d->m_mainwidget, "tabWidget" );
00477     maingrid->addWidget( d->tabWidget, 0, 0 );
00478 
00479     // new document
00480     d->newTab = new QWidget( d->tabWidget, "newTab" );
00481     d->tabWidget->insertTab( d->newTab, i18n( "&Create Document" ) );
00482     QGridLayout * newTabLayout = new QGridLayout( d->newTab, 1, 1, KDialogBase::marginHint(), KDialogBase::spacingHint());
00483 
00484     // existing document
00485     d->existingTab = new QWidget( d->tabWidget, "existingTab" );
00486     d->tabWidget->insertTab( d->existingTab, i18n( "Open &Existing Document" ) );
00487     QGridLayout * existingTabLayout = new QGridLayout( d->existingTab, 1, 1, 0, KDialog::spacingHint());
00488 
00489         // recent document
00490         d->recentTab = new QWidget( d->tabWidget, "recentTab" );
00491         d->tabWidget->insertTab( d->recentTab, i18n( "Open &Recent Document" ) );
00492         QGridLayout * recentTabLayout = new QGridLayout( d->recentTab, 1, 1, KDialogBase::marginHint(), KDialog::spacingHint());
00493 
00494     setupTemplateDialog(d->newTab, newTabLayout);
00495     setupFileDialog(d->existingTab, existingTabLayout);
00496     setupRecentDialog(d->recentTab, recentTabLayout);
00497 
00498     QString tabhighlighted = grp.readEntry("LastReturnType");
00499     if ( tabhighlighted == "Template" )
00500         d->tabWidget->setCurrentPage(0); // CreateDocument tab
00501     else if (tabhighlighted == "File" )
00502         d->tabWidget->setCurrentPage(2); // RecentDocument tab
00503     else
00504         d->tabWidget->setCurrentPage(0); // ExistingDocument tab
00505     }
00506     else
00507     {
00508     // open a file
00509     if (d->m_dialogType == NoTemplates)
00510     {
00511         setupFileDialog(d->m_mainwidget, maingrid);
00512     }
00513     // create a new document from a template
00514     if (d->m_dialogType == OnlyTemplates)
00515     {
00516         setCaption(i18n( "Create Document" ));
00517         setupTemplateDialog(d->m_mainwidget, maingrid);
00518     }
00519     }
00520 }
00521 
00522 /*================================================================*/
00523 // private SLOT
00524 void KoTemplateChooseDia::currentChanged( QIconViewItem * item)
00525 {
00526     if (item)
00527     {
00528     QIconView* canvas =  item->iconView();
00529 
00530     // set text in the textarea
00531     d->textedit->setText( descriptionText(
00532                 item->text(),
00533                 ((KoTCDIconViewItem *) item)->getDescr()
00534                 ));
00535 
00536     // set the icon in the canvas selected
00537     if (canvas)
00538         canvas->setSelected(item,1,0);
00539 
00540     // register the current template
00541     d->m_templateName = item->text();
00542     d->m_fullTemplateName = ((KoTCDIconViewItem *) item)->getFName();
00543     }
00544 }
00545 
00546 /*================================================================*/
00547 // private SLOT
00548 void KoTemplateChooseDia::chosen(QIconViewItem * item)
00549 {
00550     // the user double clicked on a template
00551     if (item)
00552     {
00553     currentChanged(item);
00554     slotOk();
00555     }
00556 }
00557 
00558 /* */
00559 // private SLOT
00560 void KoTemplateChooseDia::recentSelected( QIconViewItem * item)
00561 {
00562     if (item)
00563     {
00564         slotOk();
00565     }
00566 }
00567 
00568 /*================================================================*/
00569 // protected SLOT
00570 void KoTemplateChooseDia::slotOk()
00571 {
00572     // Collect info from the dialog into d->m_returnType and d->m_templateName etc.
00573     if (collectInfo())
00574     {
00575     // Save it for the next time
00576     KConfigGroup grp( d->m_global->config(), "TemplateChooserDialog" );
00577     static const char* const s_returnTypes[] = { 0 /*Cancel ;)*/, "Template", "File", "Empty" };
00578     if ( d->m_returnType <= Empty )
00579     {
00580         grp.writeEntry( "LastReturnType", QString::fromLatin1(s_returnTypes[d->m_returnType]) );
00581         if (d->m_returnType == Template)
00582         {
00583         grp.writeEntry( "TemplateTab", d->m_jwidget->activePageIndex() );
00584 #if KDE_IS_VERSION(3,1,3)
00585         grp.writePathEntry( "TemplateName", d->m_templateName );
00586         grp.writePathEntry( "FullTemplateName", d->m_fullTemplateName);
00587 #else
00588         grp.writeEntry( "TemplateName", d->m_templateName );
00589         grp.writeEntry( "FullTemplateName", d->m_fullTemplateName);
00590 #endif
00591         }
00592 
00593         if (d->m_nodiag)
00594         {
00595         if (d->m_nodiag->isChecked())
00596             grp.writeEntry( "NoStartDlg", "yes");
00597         else
00598             grp.writeEntry( "NoStartDlg", "no");
00599         }
00600     }
00601     else
00602     {
00603         kdWarning(30003) << "Unsupported template chooser result: " << d->m_returnType << endl;
00604         grp.writeEntry( "LastReturnType", QString::null );
00605     }
00606     KDialogBase::slotOk();
00607     }
00608 }
00609 
00610 /*================================================================*/
00611 // private
00612 bool KoTemplateChooseDia::collectInfo()
00613 {
00614 
00615 
00616     // to determine what tab is selected in "Everything" mode
00617     bool newTabSelected = false;
00618     if ( d->m_dialogType == Everything)
00619     if ( d->tabWidget->currentPage() == d->newTab )
00620         newTabSelected = true;
00621 
00622     // is it a template or a file ?
00623     if ( d->m_dialogType==OnlyTemplates || newTabSelected )
00624     {
00625     // a template is chosen
00626     if (d->m_templateName.length() > 0)
00627         d->m_returnType = Template;
00628     else
00629         d->m_returnType=Empty;
00630 
00631     return true;
00632     }
00633     else if ( d->m_dialogType != OnlyTemplates )
00634     {
00635     // a file is chosen
00636     if (d->m_dialogType == Everything && d->tabWidget->currentPage() == d->recentTab)
00637     {
00638         // Recent file
00639         KFileItem * item = d->m_recent->currentFileItem();
00640         if (! item)
00641             return false;
00642         KURL url = item->url();
00643         if(url.isLocalFile() && !QFile::exists(url.path()))
00644         {
00645             KMessageBox::error( this, i18n( "The file %1 doesn't exist." ).arg( url.path() ) );
00646             return false;
00647         }
00648         d->m_fullTemplateName = url.url();
00649         d->m_returnType = File;
00650     }
00651     else
00652     {
00653         // Existing file from file dialog
00654         KURL url = d->m_filedialog->currentURL();
00655         d->m_fullTemplateName = url.url();
00656         d->m_returnType = File;
00657                 return d->m_filedialog->checkURL();
00658     }
00659     return true;
00660     }
00661 
00662     d->m_returnType=Empty;
00663     return false;
00664 }
00665 
00666 /*================================================================*/
00667 //private
00668 QString KoTemplateChooseDia::descriptionText(const QString &name, const QString &description)
00669 {
00670     QString descrText(i18n("Name:"));
00671     descrText += " " + name;
00672     descrText += "\n";
00673     descrText += i18n("Description:");
00674     if (description.isEmpty())
00675           descrText += " " + i18n("No description available");
00676     else
00677               descrText += " " + description;
00678     return descrText;
00679 }
00680 
00681 /*================================================================*/
00682 
00683 QIconViewItem * KoTCDIconCanvas::load( KoTemplateGroup *group, const QString& name)
00684 {
00685     QIconViewItem * itemtoreturn = 0;
00686 
00687     for (KoTemplate *t=group->first(); t!=0L; t=group->next()) {
00688     if (t->isHidden())
00689         continue;
00690     QIconViewItem *item = new KoTCDIconViewItem(
00691         this,
00692         t->name(),
00693         t->loadPicture(),
00694         t->description(),
00695         t->file());
00696 
00697     if (name == t->name())
00698     {
00699         itemtoreturn = item;
00700     }
00701 
00702     item->setKey(t->name());
00703     item->setDragEnabled(false);
00704     item->setDropEnabled(false);
00705     }
00706 
00707     return itemtoreturn;
00708 }
00709 
00710 /*================================================================*/
00711 
00712 KoTCDRecentFilesIconView::~KoTCDRecentFilesIconView()
00713 {
00714     removeToolTip();
00715 }
00716 
00717 void KoTCDRecentFilesIconView::showToolTip( QIconViewItem* item )
00718 {
00719     removeToolTip();
00720     if ( !item )
00721         return;
00722 
00723     // Mostly duplicated from KFileIconView, because it only shows tooltips
00724     // for truncated icon texts, and we want tooltips on all icons,
00725     // with the full path...
00726     // KFileIconView would need a virtual method for deciding if a tooltip should be shown,
00727     // and another one for deciding what's the text of the tooltip...
00728     const KFileItem *fi = ( (KFileIconViewItem*)item )->fileInfo();
00729     QString toolTipText = fi->url().prettyURL( 0, KURL::StripFileProtocol );
00730     toolTip = new QLabel( QString::fromLatin1(" %1 ").arg(toolTipText), 0,
00731                           "myToolTip",
00732                           WStyle_StaysOnTop | WStyle_Customize | WStyle_NoBorder | WStyle_Tool | WX11BypassWM );
00733     toolTip->setFrameStyle( QFrame::Plain | QFrame::Box );
00734     toolTip->setLineWidth( 1 );
00735     toolTip->setAlignment( AlignLeft | AlignTop );
00736     toolTip->move( QCursor::pos() + QPoint( 14, 14 ) );
00737     toolTip->adjustSize();
00738     QRect screen = QApplication::desktop()->screenGeometry(
00739         QApplication::desktop()->screenNumber(QCursor::pos()));
00740     if (toolTip->x()+toolTip->width() > screen.right()) {
00741         toolTip->move(toolTip->x()+screen.right()-toolTip->x()-toolTip->width(), toolTip->y());
00742     }
00743     if (toolTip->y()+toolTip->height() > screen.bottom()) {
00744         toolTip->move(toolTip->x(), screen.bottom()-toolTip->y()-toolTip->height()+toolTip->y());
00745     }
00746     toolTip->setFont( QToolTip::font() );
00747     toolTip->setPalette( QToolTip::palette(), TRUE );
00748     toolTip->show();
00749 }
00750 
00751 void KoTCDRecentFilesIconView::removeToolTip()
00752 {
00753     delete toolTip;
00754     toolTip = 0;
00755 }
00756 
00757 void KoTCDRecentFilesIconView::hideEvent( QHideEvent *ev )
00758 {
00759     removeToolTip();
00760     KFileIconView::hideEvent( ev );
00761 }
00762 
00763 #include "koTemplateChooseDia.moc"
KDE Logo
This file is part of the documentation for lib Library Version 1.3.5.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Fri Mar 11 11:47:44 2005 by doxygen 1.3.9.1 written by Dimitri van Heesch, © 1997-2003