You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
544 lines
12 KiB
544 lines
12 KiB
15 years ago
|
/*
|
||
13 years ago
|
TDE Icon Editor - a small graphics drawing program for the TDE
|
||
15 years ago
|
Copyright (C) 1998 Thomas Tanghus (tanghus@kde.org)
|
||
|
|
||
|
This program is free software; you can redistribute it and/or
|
||
|
modify it under the terms of the GNU General Public
|
||
|
License as published by the Free Software Foundation; either
|
||
|
version 2 of the License, or (at your option) any later version.
|
||
|
|
||
|
This program is distributed in the hope that it will be useful,
|
||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||
|
General Public License for more details.
|
||
|
|
||
|
You should have received a copy of the GNU Library General Public License
|
||
|
along with this library; see the file COPYING.LIB. If not, write to
|
||
|
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||
|
Boston, MA 02110-1301, USA.
|
||
|
*/
|
||
|
|
||
15 years ago
|
#include <tqpaintdevicemetrics.h>
|
||
|
#include <tqpainter.h>
|
||
15 years ago
|
|
||
|
#include <kkeydialog.h>
|
||
12 years ago
|
#include <tdelocale.h>
|
||
|
#include <tdemessagebox.h>
|
||
15 years ago
|
#include <kdebug.h>
|
||
|
#include <kprinter.h>
|
||
|
#include <kurldrag.h>
|
||
|
|
||
11 years ago
|
#include "tdeiconedit.h"
|
||
|
#include "tdeiconcolors.h"
|
||
15 years ago
|
#include "palettetoolbar.h"
|
||
|
|
||
|
#ifndef PICS_INCLUDED
|
||
|
#define PICS_INCLUDED
|
||
|
#include "pics/logo.xpm"
|
||
|
#endif
|
||
|
|
||
12 years ago
|
void TDEIconEdit::updateProperties()
|
||
15 years ago
|
{
|
||
12 years ago
|
TDEIconEditProperties *props = TDEIconEditProperties::self();
|
||
15 years ago
|
gridview->setShowRulers(props->showRulers());
|
||
15 years ago
|
if(props->bgMode() == TQWidget::FixedPixmap)
|
||
15 years ago
|
{
|
||
15 years ago
|
TQPixmap pix(props->bgPixmap());
|
||
15 years ago
|
if(pix.isNull())
|
||
|
{
|
||
15 years ago
|
TQPixmap pmlogo((const char**)logo);
|
||
15 years ago
|
pix = pmlogo;
|
||
|
}
|
||
|
gridview->viewPortWidget()->viewport()->setBackgroundPixmap(pix);
|
||
|
m_paletteToolBar->setPreviewBackground(pix);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
gridview->viewPortWidget()->viewport()
|
||
|
->setBackgroundColor(props->bgColor());
|
||
|
m_paletteToolBar->setPreviewBackground(props->bgColor());
|
||
|
}
|
||
|
grid->setTransparencyDisplayType(props->transparencyDisplayType());
|
||
|
grid->setTransparencySolidColor(props->transparencySolidColor());
|
||
|
grid->setCheckerboardColor1(props->checkerboardColor1());
|
||
|
grid->setCheckerboardColor2(props->checkerboardColor2());
|
||
|
grid->setCheckerboardSize(props->checkerboardSize());
|
||
|
grid->update();
|
||
|
}
|
||
|
|
||
12 years ago
|
void TDEIconEdit::slotNewWin(const TQString & url)
|
||
15 years ago
|
{
|
||
12 years ago
|
//kdDebug(4640) << "TDEIconEdit::openNewWin() - " << url << endl;
|
||
15 years ago
|
|
||
11 years ago
|
TDEIconEdit *w = new TDEIconEdit(KURL(url), "tdeiconedit");
|
||
13 years ago
|
TQ_CHECK_PTR(w);
|
||
15 years ago
|
}
|
||
|
|
||
|
|
||
12 years ago
|
void TDEIconEdit::slotNew()
|
||
15 years ago
|
{
|
||
|
bool cancel = false;
|
||
|
if (grid->isModified())
|
||
|
{
|
||
|
int r = KMessageBox::warningYesNoCancel(this,
|
||
14 years ago
|
i18n("The current file has been modified.\nDo you want to save it?"), TQString(), KStdGuiItem::save(), KStdGuiItem::discard());
|
||
15 years ago
|
|
||
|
switch(r)
|
||
|
{
|
||
|
case KMessageBox::Yes:
|
||
|
if(!icon->save(&grid->image()))
|
||
|
{
|
||
|
cancel = true;
|
||
|
}
|
||
|
break;
|
||
|
|
||
|
case KMessageBox::No:
|
||
|
break;
|
||
|
|
||
|
case KMessageBox::Cancel:
|
||
|
cancel = true;
|
||
|
break;
|
||
|
|
||
|
default:
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
if(!cancel)
|
||
|
{
|
||
|
KNewIcon newicon(this);
|
||
|
if(newicon.exec())
|
||
|
{
|
||
|
int r = newicon.openStyle();
|
||
|
if(r == KNewIcon::Blank)
|
||
|
{
|
||
|
grid->editClear();
|
||
15 years ago
|
const TQSize s = newicon.templateSize();
|
||
15 years ago
|
//kdDebug(4640) << "Size: " << s.width() << " x " << s.height() << endl;
|
||
|
grid->setSize(s);
|
||
|
grid->setModified(false);
|
||
|
}
|
||
|
else if(r == KNewIcon::Template)
|
||
|
{
|
||
15 years ago
|
TQString str = newicon.templatePath();
|
||
15 years ago
|
icon->open(&grid->image(), KURL( str ));
|
||
|
}
|
||
|
icon->setUrl("");
|
||
|
emit newname(i18n("Untitled"));
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
12 years ago
|
void TDEIconEdit::slotOpen()
|
||
15 years ago
|
{
|
||
|
bool cancel = false;
|
||
|
|
||
|
if( grid->isModified() )
|
||
|
{
|
||
|
int r = KMessageBox::warningYesNoCancel(this,
|
||
14 years ago
|
i18n("The current file has been modified.\nDo you want to save it?"),TQString(), KStdGuiItem::save(), KStdGuiItem::discard());
|
||
15 years ago
|
|
||
|
switch( r )
|
||
|
{
|
||
|
case KMessageBox::Yes:
|
||
|
if(!icon->save( &grid->image() ))
|
||
|
{
|
||
|
cancel = true;
|
||
|
}
|
||
|
break;
|
||
|
|
||
|
case KMessageBox::No:
|
||
|
break;
|
||
|
|
||
|
case KMessageBox::Cancel:
|
||
|
cancel = true;
|
||
|
break;
|
||
|
|
||
|
default:
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if( !cancel )
|
||
|
{
|
||
|
if (icon->promptForFile( &grid->image() ))
|
||
|
{
|
||
|
grid->setModified(false);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/*
|
||
|
close only the current window
|
||
|
*/
|
||
12 years ago
|
void TDEIconEdit::slotClose()
|
||
15 years ago
|
{
|
||
12 years ago
|
//kdDebug(4640) << "TDEIconEdit: Closing " << endl;
|
||
15 years ago
|
close();
|
||
|
}
|
||
|
|
||
12 years ago
|
void TDEIconEdit::slotSave()
|
||
15 years ago
|
{
|
||
12 years ago
|
//kdDebug(4640) << "TDEIconEdit: slotSave() " << endl;
|
||
15 years ago
|
icon->save(&grid->image());
|
||
|
}
|
||
|
|
||
|
|
||
12 years ago
|
void TDEIconEdit::slotSaveAs()
|
||
15 years ago
|
{
|
||
12 years ago
|
//kdDebug(4640) << "TDEIconEdit: slotSaveAs() " << endl;
|
||
15 years ago
|
icon->saveAs(&grid->image());
|
||
|
}
|
||
|
|
||
|
|
||
12 years ago
|
void TDEIconEdit::slotPrint()
|
||
15 years ago
|
{
|
||
|
KPrinter printer;
|
||
|
|
||
13 years ago
|
if ( printer.setup(this, i18n("Print %1").arg(icon->url().section('/', -1))) )
|
||
15 years ago
|
{
|
||
|
int margin = 10, yPos = 0;
|
||
13 years ago
|
printer.setCreator("TDE Icon Editor");
|
||
15 years ago
|
|
||
15 years ago
|
TQPainter p;
|
||
15 years ago
|
p.begin( &printer );
|
||
15 years ago
|
TQFontMetrics fm = p.fontMetrics();
|
||
15 years ago
|
// need width/height
|
||
15 years ago
|
TQPaintDeviceMetrics metrics( &printer );
|
||
15 years ago
|
|
||
|
p.drawText( margin, margin + yPos, metrics.width(), fm.lineSpacing(),
|
||
|
ExpandTabs | DontClip, icon->url() );
|
||
|
yPos = yPos + fm.lineSpacing();
|
||
|
p.drawPixmap( margin, margin + yPos, grid->pixmap() );
|
||
|
p.end();
|
||
|
}
|
||
|
}
|
||
|
|
||
12 years ago
|
void TDEIconEdit::slotZoomIn()
|
||
15 years ago
|
{
|
||
|
grid->zoom(DirIn);
|
||
|
}
|
||
|
|
||
12 years ago
|
void TDEIconEdit::slotZoomOut()
|
||
15 years ago
|
{
|
||
|
grid->zoom(DirOut);
|
||
|
}
|
||
|
|
||
12 years ago
|
void TDEIconEdit::slotZoom1()
|
||
15 years ago
|
{
|
||
|
grid->zoomTo(1);
|
||
|
}
|
||
|
|
||
12 years ago
|
void TDEIconEdit::slotZoom2()
|
||
15 years ago
|
{
|
||
|
grid->zoomTo(2);
|
||
|
}
|
||
|
|
||
12 years ago
|
void TDEIconEdit::slotZoom5()
|
||
15 years ago
|
{
|
||
|
grid->zoomTo(5);
|
||
|
}
|
||
|
|
||
12 years ago
|
void TDEIconEdit::slotZoom10()
|
||
15 years ago
|
{
|
||
|
grid->zoomTo(10);
|
||
|
}
|
||
|
|
||
12 years ago
|
void TDEIconEdit::slotCopy()
|
||
15 years ago
|
{
|
||
|
grid->editCopy();
|
||
|
}
|
||
|
|
||
12 years ago
|
void TDEIconEdit::slotCut()
|
||
15 years ago
|
{
|
||
|
grid->editCopy(true);
|
||
|
}
|
||
|
|
||
12 years ago
|
void TDEIconEdit::slotPaste()
|
||
15 years ago
|
{
|
||
12 years ago
|
static_cast<TDERadioAction*>(actionCollection()
|
||
15 years ago
|
->action("tool_find_pixel"))->setChecked(true);
|
||
12 years ago
|
grid->setTool(TDEIconEditGrid::Find);
|
||
15 years ago
|
grid->editPaste();
|
||
|
}
|
||
|
|
||
12 years ago
|
void TDEIconEdit::slotClear()
|
||
15 years ago
|
{
|
||
|
grid->editClear();
|
||
|
}
|
||
|
|
||
12 years ago
|
void TDEIconEdit::slotSelectAll()
|
||
15 years ago
|
{
|
||
12 years ago
|
grid->setTool(TDEIconEditGrid::SelectRect);
|
||
15 years ago
|
grid->editSelectAll();
|
||
|
}
|
||
|
|
||
12 years ago
|
void TDEIconEdit::slotOpenRecent(const KURL& iconFile)
|
||
15 years ago
|
{
|
||
|
bool cancel = false;
|
||
|
|
||
|
if( grid->isModified() )
|
||
|
{
|
||
|
int r = KMessageBox::warningYesNoCancel(this,
|
||
14 years ago
|
i18n("The current file has been modified.\nDo you want to save it?"),TQString(), KStdGuiItem::save(), KStdGuiItem::discard());
|
||
15 years ago
|
|
||
|
switch( r )
|
||
|
{
|
||
|
case KMessageBox::Yes:
|
||
|
if (!icon->save( &grid->image() ))
|
||
|
{
|
||
|
cancel = true;
|
||
|
}
|
||
|
break;
|
||
|
|
||
|
case KMessageBox::No:
|
||
|
break;
|
||
|
|
||
|
case KMessageBox::Cancel:
|
||
|
cancel = true;
|
||
|
break;
|
||
|
|
||
|
default:
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if( !cancel )
|
||
|
{
|
||
|
if(icon->open(&grid->image(), iconFile))
|
||
|
{
|
||
|
grid->setModified(false);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
12 years ago
|
void TDEIconEdit::slotConfigureSettings()
|
||
15 years ago
|
{
|
||
12 years ago
|
TDEIconConfig* c = new TDEIconConfig(this);
|
||
15 years ago
|
c->exec();
|
||
|
delete c;
|
||
|
}
|
||
|
|
||
12 years ago
|
void TDEIconEdit::slotConfigureKeys()
|
||
15 years ago
|
{
|
||
|
KKeyDialog::configure(actionCollection());
|
||
|
|
||
12 years ago
|
TDEIconEdit *ki = 0L;
|
||
15 years ago
|
for (ki = windowList.first(); ki; ki = windowList.next())
|
||
|
{
|
||
|
if (ki != this)
|
||
|
{
|
||
|
ki->updateAccels();
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
12 years ago
|
void TDEIconEdit::slotShowGrid()
|
||
15 years ago
|
{
|
||
12 years ago
|
bool b = TDEIconEditProperties::self()->showGrid();
|
||
15 years ago
|
grid->setGrid( !b );
|
||
12 years ago
|
TDEIconEditProperties::self()->setShowGrid( !b );
|
||
15 years ago
|
}
|
||
|
|
||
12 years ago
|
void TDEIconEdit::slotToolPointer()
|
||
15 years ago
|
{
|
||
12 years ago
|
grid->setTool(TDEIconEditGrid::Find);
|
||
15 years ago
|
}
|
||
|
|
||
12 years ago
|
void TDEIconEdit::slotToolFreehand()
|
||
15 years ago
|
{
|
||
12 years ago
|
grid->setTool(TDEIconEditGrid::Freehand);
|
||
15 years ago
|
}
|
||
|
|
||
12 years ago
|
void TDEIconEdit::slotToolRectangle()
|
||
15 years ago
|
{
|
||
12 years ago
|
grid->setTool(TDEIconEditGrid::Rect);
|
||
15 years ago
|
}
|
||
|
|
||
12 years ago
|
void TDEIconEdit::slotToolFilledRectangle()
|
||
15 years ago
|
{
|
||
12 years ago
|
grid->setTool(TDEIconEditGrid::FilledRect);
|
||
15 years ago
|
}
|
||
|
|
||
12 years ago
|
void TDEIconEdit::slotToolCircle()
|
||
15 years ago
|
{
|
||
12 years ago
|
grid->setTool(TDEIconEditGrid::Circle);
|
||
15 years ago
|
}
|
||
|
|
||
12 years ago
|
void TDEIconEdit::slotToolFilledCircle()
|
||
15 years ago
|
{
|
||
12 years ago
|
grid->setTool(TDEIconEditGrid::FilledCircle);
|
||
15 years ago
|
}
|
||
|
|
||
12 years ago
|
void TDEIconEdit::slotToolEllipse()
|
||
15 years ago
|
{
|
||
12 years ago
|
grid->setTool(TDEIconEditGrid::Ellipse);
|
||
15 years ago
|
}
|
||
|
|
||
12 years ago
|
void TDEIconEdit::slotToolFilledEllipse()
|
||
15 years ago
|
{
|
||
12 years ago
|
grid->setTool(TDEIconEditGrid::FilledEllipse);
|
||
15 years ago
|
}
|
||
|
|
||
12 years ago
|
void TDEIconEdit::slotToolSpray()
|
||
15 years ago
|
{
|
||
12 years ago
|
grid->setTool(TDEIconEditGrid::Spray);
|
||
15 years ago
|
}
|
||
|
|
||
12 years ago
|
void TDEIconEdit::slotToolFlood()
|
||
15 years ago
|
{
|
||
12 years ago
|
grid->setTool(TDEIconEditGrid::FloodFill);
|
||
15 years ago
|
}
|
||
|
|
||
12 years ago
|
void TDEIconEdit::slotToolLine()
|
||
15 years ago
|
{
|
||
12 years ago
|
grid->setTool(TDEIconEditGrid::Line);
|
||
15 years ago
|
}
|
||
|
|
||
12 years ago
|
void TDEIconEdit::slotToolEraser()
|
||
15 years ago
|
{
|
||
12 years ago
|
grid->setTool(TDEIconEditGrid::Eraser);
|
||
15 years ago
|
}
|
||
|
|
||
12 years ago
|
void TDEIconEdit::slotToolSelectRect()
|
||
15 years ago
|
{
|
||
12 years ago
|
grid->setTool(TDEIconEditGrid::SelectRect);
|
||
15 years ago
|
}
|
||
|
|
||
12 years ago
|
void TDEIconEdit::slotToolSelectCircle()
|
||
15 years ago
|
{
|
||
12 years ago
|
grid->setTool(TDEIconEditGrid::SelectCircle);
|
||
15 years ago
|
}
|
||
|
|
||
12 years ago
|
void TDEIconEdit::slotSaved()
|
||
15 years ago
|
{
|
||
|
grid->setModified(false);
|
||
|
}
|
||
|
|
||
12 years ago
|
void TDEIconEdit::slotUpdateZoom( int s )
|
||
15 years ago
|
{
|
||
|
m_actZoomOut->setEnabled( s>1 );
|
||
|
}
|
||
|
|
||
12 years ago
|
void TDEIconEdit::slotUpdateStatusPos(int x, int y)
|
||
15 years ago
|
{
|
||
13 years ago
|
TQString str = i18n("Status Position", "%1, %2").arg(x).arg(y);
|
||
15 years ago
|
statusbar->changeItem( str, 0);
|
||
|
}
|
||
|
|
||
12 years ago
|
void TDEIconEdit::slotUpdateStatusSize(int x, int y)
|
||
15 years ago
|
{
|
||
13 years ago
|
TQString str = i18n("Status Size", "%1 x %2").arg(x).arg(y);
|
||
15 years ago
|
statusbar->changeItem( str, 1);
|
||
|
}
|
||
|
|
||
12 years ago
|
void TDEIconEdit::slotUpdateStatusScaling(int s)
|
||
15 years ago
|
{
|
||
12 years ago
|
TDEIconEditProperties::self()->setGridScale( s );
|
||
15 years ago
|
TQString str;
|
||
15 years ago
|
|
||
|
str.sprintf("1:%d", s);
|
||
|
statusbar->changeItem( str, 2);
|
||
|
}
|
||
|
|
||
12 years ago
|
void TDEIconEdit::slotUpdateStatusColors(uint)
|
||
15 years ago
|
{
|
||
13 years ago
|
TQString str = i18n("Colors: %1").arg(grid->numColors());
|
||
15 years ago
|
statusbar->changeItem( str, 3);
|
||
|
}
|
||
|
|
||
12 years ago
|
void TDEIconEdit::slotUpdateStatusColors(uint n, uint *)
|
||
15 years ago
|
{
|
||
13 years ago
|
TQString str = i18n("Colors: %1").arg(n);
|
||
15 years ago
|
statusbar->changeItem( str, 3);
|
||
|
}
|
||
|
|
||
|
|
||
12 years ago
|
void TDEIconEdit::slotUpdateStatusMessage(const TQString & msg)
|
||
15 years ago
|
{
|
||
|
statusbar->changeItem( msg, 4);
|
||
|
}
|
||
|
|
||
|
|
||
12 years ago
|
void TDEIconEdit::slotUpdateStatusName(const TQString & name)
|
||
15 years ago
|
{
|
||
|
m_name = name;
|
||
|
|
||
15 years ago
|
TQString text = m_name;
|
||
15 years ago
|
|
||
|
if(grid->isModified())
|
||
|
{
|
||
|
text += " ["+i18n("modified")+"]";
|
||
|
}
|
||
|
|
||
|
setCaption(text);
|
||
|
}
|
||
|
|
||
|
|
||
12 years ago
|
void TDEIconEdit::slotUpdateStatusModified(bool)
|
||
15 years ago
|
{
|
||
|
slotUpdateStatusName(m_name);
|
||
|
}
|
||
|
|
||
12 years ago
|
void TDEIconEdit::slotUpdatePaste(bool state)
|
||
15 years ago
|
{
|
||
|
m_actPaste->setEnabled(state);
|
||
|
m_actPasteNew->setEnabled(state);
|
||
|
}
|
||
|
|
||
|
|
||
12 years ago
|
void TDEIconEdit::slotUpdateCopy(bool state)
|
||
15 years ago
|
{
|
||
|
m_actCopy->setEnabled(state);
|
||
|
m_actCut->setEnabled(state);
|
||
|
}
|
||
|
|
||
|
|
||
12 years ago
|
void TDEIconEdit::slotOpenBlank(const TQSize s)
|
||
15 years ago
|
{
|
||
|
grid->loadBlank( s.width(), s.height());
|
||
|
}
|
||
|
|
||
|
|
||
12 years ago
|
void TDEIconEdit::dragEnterEvent(TQDragEnterEvent* e)
|
||
15 years ago
|
{
|
||
|
e->accept(KURLDrag::canDecode(e));
|
||
|
}
|
||
|
|
||
|
|
||
|
/*
|
||
|
accept drop of a file - opens file in current window
|
||
|
old code to drop image, as image, should be removed
|
||
|
*/
|
||
12 years ago
|
void TDEIconEdit::dropEvent( TQDropEvent *e )
|
||
15 years ago
|
{
|
||
14 years ago
|
//kdDebug(4640) << "Got TQDropEvent!" << endl;
|
||
15 years ago
|
|
||
|
KURL::List fileList;
|
||
|
bool loadedinthis = false;
|
||
|
|
||
|
if(KURLDrag::decode(e, fileList))
|
||
|
{
|
||
|
for(KURL::List::ConstIterator it = fileList.begin();
|
||
|
it != fileList.end(); ++it)
|
||
|
{
|
||
|
//kdDebug(4640) << "In dropEvent for " << (*it).prettyURL() << endl;
|
||
|
const KURL &url = *it;
|
||
|
if(url.isValid())
|
||
|
{
|
||
|
if (!grid->isModified() && !loadedinthis)
|
||
|
{
|
||
|
icon->open(&grid->image(), url);
|
||
|
loadedinthis = true;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
slotNewWin(url.url());
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|