Source Code (Use browser search to find items of interest.)
Class Index
katalog'Katalog (./kdegraphics/katalog/katalog.h:20)
class Katalog : public KTMainWindow {
Q_OBJECT
MainView *mMainView;
public:
Katalog();
~Katalog();
void loadFile(const KURL & url);
bool empty();
bool queryClose();
public slots:
void slotView(int id);
void dragEnterEvent( QDragEnterEvent *e );
void dropEvent( QDropEvent *);
void slotLoadFile();
void slotAddImage();
void slotSaveFile();
void slotSaveAs();
void slotCloseFile();
void slotNewWindow();
void slotToolbarClicked(int);
protected:
void updateTM();
void updateView();
void saveProperties(KConfig*);
void readProperties(KConfig*);
private:
enum {TOOLBAR_EXIT, TOOLBAR_OPEN, TOOLBAR_SAVE, TOOLBAR_SAVE_AS, TOOLBAR_CLOSE};
enum {ID_VIEW_NAME, ID_VIEW_SIZE, ID_VIEW_FILESIZE, ID_VIEW_DESC };
int mCatalogId;
int mNewId;
int mOpenId;
int mSaveId;
int mSaveAsId;
int mCloseId;
QString mLastDir;
KURL mLocation;
};
katalog'Katalog::Katalog() (./kdegraphics/katalog/katalog.cpp:68)
Katalog::Katalog()
{
windowCount++;
printf("Window Count = %d\n", windowCount);
mMainView = new MainView(this);
setView(mMainView);
QTime timeBase = QTime::currentTime();
#if 0
KThreadWorker *work = new KThreadWorker();
KThread *thread = new KThread(work);
KThreadWorker *work2 = new KThreadWorker();
KThread *thread2 = new KThread(work2);
thread2->start();
thread->start();
if (thread->finish(500))
{
printf("Finished in time! (%d sec passed)",
timeBase.msecsTo(QTime::currentTime()));
}
else
{
printf("Not finished in time. (%d sec passed)\n",
timeBase.msecsTo(QTime::currentTime()));
}
#endif
//---------------------------------------------------
// Drag'n'Drop as implemented by Qt (XDnD)
setAcceptDrops(TRUE);
//---------------------------------------------------
// build a menubar
// a menubar consists of popup menus. So we need a
// popup menu first
QPopupMenu* p = new QPopupMenu;
// the new way in KDE post 1.1. KAccel is a very flexible class to handle
// keyboard accelerations. These are completely configurable by the
// user. Please see the kaccel documentation for further
// details. The major advantage: With a single line of code calling
// KKeyDialog::configureKeys(KAccel*) you can popup a keybinding
// editor for your application.
//
// In kless we use KAccel only for some global defined standard
// bindings.
// create a kaccel object and bind the standard actions to our slots
KAccel *a = new KAccel( this );
a->connectItem(KStdAccel::New, this, SLOT( slotNewWindow() ) );
a->connectItem(KStdAccel::Open, this, SLOT( slotLoadFile() ) );
a->connectItem(KStdAccel::Save, this, SLOT( slotSaveFile() ) );
// a->connectItem(KStdAccel::SaveAs, this, SLOT( slotSaveAs() ) );
a->connectItem(KStdAccel::Quit, this, SLOT( close() ) );
a->connectItem(KStdAccel::Close, this, SLOT( close() ) );
// create the file menu. Tell kaccel to show the accelerators in the
// menu as well. The advantage over doing that directly in Qt is,
// that kaccels accelerators are internationalized.
int id;
id = p->insertItem(i18n("&New"),this, SLOT(slotNewWindow()));
a->changeMenuAccel(p, id, KStdAccel::New );
mNewId = id;
id = p->insertItem(i18n("&Open"),this, SLOT(slotLoadFile()));
a->changeMenuAccel(p, id, KStdAccel::Open );
mOpenId = id;
p->insertSeparator();
id = p->insertItem(i18n("&Add image"),this, SLOT(slotAddImage()));
// mAddImageId = id;
p->insertSeparator();
id = p->insertItem(i18n("&Save"),this, SLOT(slotSaveFile()));
a->changeMenuAccel(p, id, KStdAccel::Save );
mSaveId = id;
id = p->insertItem(i18n("S&ave as"),this, SLOT(slotSaveAs()));
// a->changeMenuAccel(p, id, KStdAccel::SaveAs );
mSaveAsId = id;
id = p->insertItem(i18n("&Close"),this, SLOT(slotCloseFile()));
// a->changeMenuAccel(p, id, KStdAccel::Quit );
mCloseId = id;
p->insertSeparator();
id = p->insertItem(i18n("&Quit"),this, SLOT(close()));
a->changeMenuAccel(p, id, KStdAccel::Quit );
// put the popupmenu as File-menu into the menu bar
menuBar()->insertItem(i18n("&File"), p);
#if 0
p = new QPopupMenu;
id = p->insertItem(i18n("&New"),this, SLOT(slotNewWindow()));
a->changeMenuAccel(p, id, KStdAccel::New );
id = p->insertItem(i18n("&Close"),this, SLOT(close()));
a->changeMenuAccel(p, id, KStdAccel::Close );
// put the popupmenu as Window-menu into the menu bar
menuBar()->insertItem(i18n("&Window"), p);
#endif
p = new QPopupMenu;
p->insertItem(i18n("Show &name"), ID_VIEW_NAME);
p->insertItem(i18n("Show &size"), ID_VIEW_SIZE);
p->insertItem(i18n("Show &filesize"), ID_VIEW_FILESIZE);
p->insertItem(i18n("Show &description"), ID_VIEW_DESC);
connect( p, SIGNAL(activated(int)), this, SLOT( slotView(int)));
// put the popupmenu as Catalog-menu into the menu bar
menuBar()->insertItem(i18n("&View"), p);
p = new QPopupMenu;
id = p->insertItem(i18n("&Thumbnail size..."),this, SLOT(slotNewWindow()));
// put the popupmenu as Catalog-menu into the menu bar
mCatalogId = menuBar()->insertItem(i18n("&Catalog"), p);
menuBar()->insertSeparator();
// we let KDE generate a nifty help menu
p = helpMenu(
i18n("katalog --- An Image Cataloging Program\n\n"
"(c) 1999 Waldo Bastian"));
menuBar()->insertItem(i18n("&Help"), p);
//---------------------------------------------------
// build a small toolbar
// insert some buttons, the icons are from the standard KDE toolbar.
toolBar()->insertButton(BarIcon("fileopen"),TOOLBAR_OPEN, true,i18n("Open Catalog"));
toolBar()->insertButton(BarIcon("filefloppy"),TOOLBAR_SAVE, true,i18n("Save Catalog"));
// Hint: toolBar() returns toolBar(0). If you want another toolbar, simply
// use toolBar(1), toolBar(2) and so on.
// we connect the entire toolbar to one single slot. We could also
// connect the single toolbar buttons to special slots in the
// insertButton call above, for example:
// insertButton(Icon("exit"),TOOLBAR_EXIT,
// SIGNAL(clicked()), kapp, SLOT(quit()),
// true,"Exit")
// This would be even better for this simple toolbar. We have chosen
// the other design --- which is more flexible for bigger toolbars ---
// for demonstration purposes in kless.
connect(toolBar(), SIGNAL(clicked(int)), SLOT(slotToolbarClicked(int)));
updateTM();
}
katalog'Katalog::~Katalog() (./kdegraphics/katalog/katalog.cpp:221)
Katalog::~Katalog()
{
windowCount--;
printf("Window Count = %d\n", windowCount);
}
bool
katalog'Katalog::empty() (./kdegraphics/katalog/katalog.cpp:228)
Katalog::empty()
{
return mMainView->catalog()->empty();
}
katalog'Katalog::updateTM() (./kdegraphics/katalog/katalog.cpp:233)
void Katalog::updateTM()
{
if (!mMainView->catalog())
mMainView->setCatalog( new Catalog());
bool catalogOk = !empty();
Catalog *cat = mMainView->catalog();
// toolBar()->setItemEnabled(TOOLBAR_OPEN, !catalogOk );
toolBar()->setItemEnabled(TOOLBAR_SAVE, catalogOk );
// menuBar()->setItemEnabled(mOpenId, !catalogOk );
menuBar()->setItemEnabled(mSaveId, catalogOk );
menuBar()->setItemEnabled(mSaveAsId, catalogOk );
menuBar()->setItemEnabled(mCloseId, catalogOk );
menuBar()->setItemEnabled(mCatalogId, catalogOk );
menuBar()->setItemChecked(ID_VIEW_NAME, cat->viewName() );
menuBar()->setItemChecked(ID_VIEW_SIZE, cat->viewSize() );
menuBar()->setItemChecked(ID_VIEW_FILESIZE, cat->viewFilesize() );
menuBar()->setItemChecked(ID_VIEW_DESC, cat->viewDesc() );
}
katalog'Katalog::slotView() (./kdegraphics/katalog/katalog.cpp:253)
void Katalog::slotView(int id)
{
bool bOn;
Catalog *cat = mMainView->catalog();
switch(id)
{
case ID_VIEW_NAME: bOn = !cat->viewName(); cat->viewName(bOn); break;
case ID_VIEW_SIZE: bOn = !cat->viewSize(); cat->viewSize(bOn); break;
case ID_VIEW_FILESIZE: bOn = !cat->viewFilesize(); cat->viewFilesize(bOn); break;
case ID_VIEW_DESC: bOn = !cat->viewDesc(); cat->viewDesc(bOn); break;
}
updateTM();
mMainView->updateView();
}
katalog'Katalog::slotToolbarClicked() (./kdegraphics/katalog/katalog.cpp:268)
void Katalog::slotToolbarClicked(int item){
switch (item) {
case TOOLBAR_OPEN:
slotLoadFile();
break;
case TOOLBAR_SAVE:
slotSaveFile();
break;
case TOOLBAR_SAVE_AS:
slotSaveAs();
break;
case TOOLBAR_CLOSE:
slotCloseFile();
break;
case TOOLBAR_EXIT:
close();
break;
}
}
katalog'Katalog::loadFile() (./kdegraphics/katalog/katalog.cpp:301)
void Katalog::loadFile(const KURL & url)
{
mLocation = url;
setCaption(url.url());
#if 0
ThreadLoadFile workerThread(filename);
KThread thread(&workerThread);
thread.start();
while (!thread.finish(400))
{
KMessageBox::information(mMainView, i18n("Please wait..."));
printf("KMessageBox returned...\n");
}
mMainView->setCatalog( workerThread.catalog );
#else
QString tempFile;
KIO::NetAccess::download( url, tempFile );
Catalog *catalog = new Catalog();
catalog->load(tempFile);
mMainView->setCatalog( catalog );
KIO::NetAccess::removeTempFile( tempFile );
#endif
updateTM();
}
katalog'Katalog::dragEnterEvent() (./kdegraphics/katalog/katalog.cpp:334)
void Katalog::dragEnterEvent( QDragEnterEvent *e )
{
printf("dragEnterEvent!\n");
// Check if we want the drag...
if (QUriDrag::canDecode( e ) ||
QImageDrag::canDecode( e ))
{
e->accept();
}
}
katalog'Katalog::dropEvent() (./kdegraphics/katalog/katalog.cpp:346)
void Katalog::dropEvent( QDropEvent *event){
// the user dropped something on our window.
// So we simply use KIO slaves to download the stuff wherever it is.
// The following code respects Qt's DnD tutorial
printf("Got dropevent!\n");
QImage im;
QString txt, u, tgt;
QStrList uri;
if(QUriDrag::canDecode(event) && QUriDrag::decode(event, uri))
{
kapp->setOverrideCursor( QCursor(waitCursor) );
for(u = uri.first(); u; u = uri.next())
{
printf("URL = %s\n", u.ascii());
mMainView->addImage(KURL(u));
}
#if 0
if (KIO::NetAccess::download(u, tgt)){
setCaption(u);
loadFile(tgt);
KIO::NetAccess::removeTempFile(tgt);
}
#endif
kapp->restoreOverrideCursor();
}
printf("Test image...\n");
if(QImageDrag::decode(event, im) )
{
kapp->setOverrideCursor( QCursor(waitCursor) );
printf("Image = %p\n", &im);
mMainView->addImage(im);
kapp->restoreOverrideCursor();
}
updateTM();
}
katalog'Katalog::slotNewWindow() (./kdegraphics/katalog/katalog.cpp:386)
void Katalog::slotNewWindow(){
// this slot is invoked from File->New_Winodw
(new Katalog)->show();
}
katalog'Katalog::slotLoadFile() (./kdegraphics/katalog/katalog.cpp:392)
void Katalog::slotLoadFile(){
// this slot is invoked from File->Open
// ask kfiledialog for a filename. We pass "this" to the function
// to indicate the window manager that the file dialog belongs
// to our application window.
KURL u = KFileDialog::getOpenURL(QString::null, "*.kat", this, i18n("Open Katalog"));
if (u.isEmpty())
{ // no filename, user hit "Cancel" or pressed "Escape"
return;
}
if (empty())
{
// Load in current window
loadFile(u);
}
else
{
// Load in new window
Katalog *katalog = new Katalog();
katalog->show();
katalog->loadFile(u);
}
}
katalog'Katalog::slotAddImage() (./kdegraphics/katalog/katalog.cpp:419)
void Katalog::slotAddImage(){
// this slot is invoked from File->Add Image
QString dir;
if (mMainView->catalog())
dir = mMainView->catalog()->addImageDir();
printf("Old DIR = %s\n", dir.ascii());
// ask kfiledialog for a filename. We pass "this" to the function
// to indicate the window manager that the file dialog belongs
// to our application window.
// QStringList files = KFileDialog::getOpenFileNames(0, 0, this);
QValueList<KURL> files;
QString filter = KImageIO::pattern();
KFileDialog dlg(dir, filter, mMainView, "filedialog", true);
dlg.setCaption(i18n("Add Image"));
dlg.exec();
KURL oneFile = dlg.selectedURL();
if (!oneFile.isMalformed())
{
files.append(oneFile);
dir = dlg.baseURL().url();
if (!mMainView->catalog())
mMainView->setCatalog( new Catalog() );
mMainView->catalog()->addImageDir(dir);
printf("New DIR = %s\n", dir.ascii());
}
printf("File count = %d\n", files.count());
if (files.count() == 0)
{ // no filename, user hit "Cancel" or pressed "Escape"
return;
}
kapp->setOverrideCursor( QCursor(waitCursor) );
for(QValueList<KURL>::ConstIterator it = files.begin();
it != files.end();
it++)
{
KURL u( *it );
printf("URL = %s\n", u.url().ascii());
mMainView->addImage(u);
}
kapp->restoreOverrideCursor();
updateTM();
}
katalog'Katalog::slotSaveFile() (./kdegraphics/katalog/katalog.cpp:475)
void Katalog::slotSaveFile(){
// this slot is invoked from File->Save
if (empty()) return;
if (mLocation.isEmpty())
{
slotSaveAs();
}
else
{
if (mLocation.isLocalFile())
{
QString s = mLocation.path();
mMainView->catalog()->saveAs(s);
}
else
{
KMessageBox::sorry(mMainView, i18n("Saving to remote locations is not yet supported.\n"));
}
}
}
katalog'Katalog::slotSaveAs() (./kdegraphics/katalog/katalog.cpp:500)
void Katalog::slotSaveAs()
{
// this slot is invoked from File->SaveAs
if (empty()) return;
QString filter = i18n("*.kat|Katalog files\n*|All Files");
KFileDialog dlg(mLastDir, filter, mMainView, "filedialog", true);
dlg.setCaption(i18n("Save Katalog As"));
dlg.exec();
KURL u = dlg.selectedURL();
if (!u.isEmpty()){ // no filename, user hit "Cancel" or pressed "Escape"
if (dlg.baseURL().isLocalFile())
{
mLastDir = dlg.baseURL().url();
}
mLocation = u;
setCaption(u.url());
if (mLocation.isLocalFile())
{
QString s = mLocation.path();
mMainView->catalog()->saveAs(s);
}
else
{
KMessageBox::sorry(mMainView, i18n("Saving to remote locations is not yet supported.\n"));
}
}
}
katalog'Katalog::slotCloseFile() (./kdegraphics/katalog/katalog.cpp:535)
void Katalog::slotCloseFile(){
// this slot is invoked from File->Close
if (empty()) return;
Catalog *catalog = mMainView->catalog();
if (catalog->dirty())
{
int result = KMessageBox::warningYesNoCancel(mMainView,
i18n("The catalog has been changed.\n"
"Do you want to save the catalog or discard the changes?"),
i18n("Save catalog?"), i18n("&Save"), i18n("&Discard") );
switch(result)
{
case KMessageBox::Yes:
slotSaveFile();
if (catalog->dirty())
return; // Cancel
break; // Yes
case KMessageBox::No:
break; // No
default:
return; // Cancel
}
}
delete catalog;
setCaption(QString::null);
updateTM();
}
katalog'Katalog::queryClose() (./kdegraphics/katalog/katalog.cpp:569)
bool Katalog::queryClose(){
slotCloseFile();
if (!empty())
return false;
return true;
}
katalog'Katalog::saveProperties() (./kdegraphics/katalog/katalog.cpp:577)
void Katalog::saveProperties(KConfig* /* config */){
};
katalog'Katalog::readProperties() (./kdegraphics/katalog/katalog.cpp:580)
void Katalog::readProperties(KConfig* /* config */){
};