20#include "kexicontextmenuutils.h"
22#include <tdeactioncollection.h>
24#include <kiconloader.h>
25#include <tdefiledialog.h>
28#include <tdemessagebox.h>
30#include <tqfiledialog.h>
31#include <tqapplication.h>
34#include <win32_utils.h>
35#include <tderecentdirs.h>
39class KexiImageContextMenu::Private
42 Private(TQWidget *parent)
43 : actionCollection(parent)
47 TDEActionCollection actionCollection;
48 TDEAction *insertFromFileAction, *saveAsAction, *cutAction, *copyAction, *pasteAction,
50#ifdef KEXI_NO_UNFINISHED
58KexiImageContextMenu::KexiImageContextMenu(TQWidget* parent)
59 : TDEPopupMenu(parent)
60 , d( new Private(this) )
62 setName( "KexiImageContextMenu");
63 insertTitle(TQString());
65 d->insertFromFileAction = new TDEAction(i18n( "Insert From &File..."), SmallIconSet( "document-open"), 0,
66 this, TQ_SLOT(insertFromFile()), &d->actionCollection, "insert");
67 d->insertFromFileAction->plug( this);
68 d->saveAsAction = KStdAction::saveAs( this, TQ_SLOT(saveAs()), &d->actionCollection);
70 d->saveAsAction->plug( this);
72 d->cutAction = KStdAction::cut( this, TQ_SLOT(cut()), &d->actionCollection);
73 d->cutAction->plug( this);
74 d->copyAction = KStdAction::copy( this, TQ_SLOT(copy()), &d->actionCollection);
75 d->copyAction->plug( this);
76 d->pasteAction = KStdAction::paste( this, TQ_SLOT(paste()), &d->actionCollection);
77 d->pasteAction->plug( this);
78 d->deleteAction = new TDEAction(i18n( "&Clear"), SmallIconSet( "edit-delete"), 0,
79 this, TQ_SLOT(clear()), &d->actionCollection, "delete");
80 d->deleteAction->plug( this);
81#ifdef KEXI_NO_UNFINISHED
82 d->propertiesAction = 0;
85 d->propertiesAction = new TDEAction(i18n( "Properties"), 0, 0,
86 this, TQ_SLOT(showProperties()), &d->actionCollection, "properties");
87 d->propertiesAction->plug( this);
89 connect( this, TQ_SIGNAL(aboutToShow()), this, TQ_SLOT(updateActionsAvailability()));
92KexiImageContextMenu::~KexiImageContextMenu()
102 TQString fileName = TQFileDialog::getOpenFileName(
103 KFileDialog::getStartURL( ":LastVisitedImagePath", recentDir).path(),
104 convertKFileDialogFilterToTQFileDialogFilter(KImageIO::pattern(KImageIO::Reading)),
105 this, 0, i18n( "Insert Image From File"));
107 if (!fileName.isEmpty())
108 url.setPath( fileName );
110 KURL url( KFileDialog::getImageOpenURL(
111 ":LastVisitedImagePath", this, i18n( "Insert Image From File")) );
116 if (!url.isValid()) {
118 if (tqApp->mainWidget()) {
121 tqApp->mainWidget()->raise();
125 kexipluginsdbg << "fname=" << url.prettyURL() << endl;
130 if (url.isLocalFile())
131 TDERecentDirs::add( ":LastVisitedImagePath", url.directory());
135 if (tqApp->mainWidget()) {
138 tqApp->mainWidget()->raise();
144 TQString origFilename, fileExtension;
145 bool dataIsEmpty = false;
149 kdWarning() << "KexiImageContextMenu::saveAs(): no data!" << endl;
152 if (!origFilename.isEmpty())
153 origFilename = TQString( "/") + origFilename;
155 if (fileExtension.isEmpty()) {
157 fileExtension = "png";
162 TQString fileName = TQFileDialog::getSaveFileName(
163 KFileDialog::getStartURL( ":LastVisitedImagePath", recentDir).path() + origFilename,
164 convertKFileDialogFilterToTQFileDialogFilter(KImageIO::pattern(KImageIO::Writing)),
165 this, 0, i18n( "Save Image to File"));
168 TQString fileName = KFileDialog::getSaveFileName(
169 ":LastVisitedImagePath", KImageIO::pattern(KImageIO::Writing), this, i18n( "Save Image to File"));
171 if (fileName.isEmpty())
174 if (TQFileInfo(fileName).extension().isEmpty())
175 fileName += (TQString( ".")+fileExtension);
176 kdDebug() << fileName << endl;
178 url.setPath( fileName );
182 if (url.isLocalFile())
183 TDERecentDirs::add( ":LastVisitedImagePath", url.directory());
187 if (f.exists() && KMessageBox::Yes != KMessageBox::warningYesNo( this,
188 "<qt>"+i18n( "File \"%1\" already exists."
189 "<p>Do you want to replace it with a new one?")
190 .arg(TQDir::convertSeparators(fileName))+ "</qt>",0,
191 KGuiItem(i18n( "&Replace")), KGuiItem(i18n( "&Don't Replace"))))
200void KexiImageContextMenu::cut()
205void KexiImageContextMenu::copy()
210void KexiImageContextMenu::paste()
215void KexiImageContextMenu::clear()
220void KexiImageContextMenu::showProperties()
225void KexiImageContextMenu::updateActionsAvailability()
227 bool valueIsNull = true;
228 bool valueIsReadOnly = true;
231 d->insertFromFileAction->setEnabled( !valueIsReadOnly );
232 d->saveAsAction->setEnabled( !valueIsNull );
233 d->cutAction->setEnabled( !valueIsNull && !valueIsReadOnly );
234 d->copyAction->setEnabled( !valueIsNull );
235 d->pasteAction->setEnabled( !valueIsReadOnly );
236 d->deleteAction->setEnabled( !valueIsNull && !valueIsReadOnly );
237 if (d->propertiesAction)
238 d->propertiesAction->setEnabled( !valueIsNull );
241TDEActionCollection* KexiImageContextMenu::actionCollection() const
243 return &d->actionCollection;
256 const TQString& objectTypeName, const TQString& iconName)
258 if (!menu || objectName.isEmpty() || objectTypeName.isEmpty())
260 const int id = menu->idAt(0);
261 TQMenuItem *item = menu->findItem( id);
264 TDEPopupTitle *title = dynamic_cast<TDEPopupTitle * >(item->widget());
270 TQString realTitle( i18n( "Object name : Object type", "%1 : %2")
271 .arg( objectName[0].upper() + objectName.mid(1) )
272 .arg( objectTypeName ));
274 if (iconName.isEmpty())
275 title->setTitle(realTitle);
277 TQPixmap pixmap(SmallIcon( iconName ));
278 title->setTitle(realTitle, &pixmap);
283#include "kexicontextmenuutils.moc"
|