/* * MathPlanner 3.1 - Mathematical design tool. * Copyright(C) 2002 Jarmo Nikkanen * * 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. * * You should have received a copy of the GNU General Public License with this program. * */ #include #include "ConfigReader.h" PaperImage::PaperImage(DataStorage *msg,ApplicationControl *a,Paper *p) :MathFrame(msg,a,p) { Enable(true,true,false); SetColor(QColor(0,0,255)); empty=false; QByteArray ba=msg->ReadQByteArray("image"); pixmap=ImageDragObject::Decode(ba,"image/png"); pixmap_orig = NULL; } DataStorage *PaperImage::BuildStorage() { DataStorage *msg=MathFrame::BuildStorage(); ImageDragObject ido(pixmap); msg->AddQByteArray("image",ido.encodedData("image/png")); return(msg); } void PaperImage::Activate() { if (!pixmap.save(config_path+"/temp.png","PNG")) ErrorReport("Save","Unable to save image"); QString image_editor=AppControl->Prefs->String("ImageEditor"); QString file(config_path+"/temp.png"); QProcess *proc = new QProcess(this); proc->addArgument(image_editor); proc->addArgument(file); connect(proc,SIGNAL(processExited()),this,SLOT(Reload())); if (!proc->start()) { ErrorReport("ImageEditor","Unable to execute program"); } } void PaperImage::Reload() { pixmap.load(config_path+"/temp.png"); /* image may have been resized in image editor */ SetBounds(QRect(Position(),pixmap.size())); paper->DrawFunction(this); } const QImage PaperImage::Pixmap() { return(pixmap); } PaperImage::PaperImage(QImage b,ApplicationControl *a,Paper *p) :MathFrame(PAPER_OBJECT_IMAGE,b.rect(),a,p) { Enable(true,true,false); SetColor(QColor(0,0,255)); empty=false; pixmap_orig=NULL; /*Will be allocated when resized for the first time */ pixmap=b.copy(); } void PaperImage::SetBounds(QRect r) { MathFrame::SetBounds(r); } void PaperImage::CalculateBounds() { MathFrame::CalculateBounds(); resizerect.setSize(QSize(10,10)); resizerect.moveBottomRight(bounds.bottomRight()); /* If we do not store the original pixmap, frequent resizing * will result in a visible loss of quality */ if(pixmap_orig == NULL) pixmap_orig = new QImage(pixmap); pixmap = pixmap_orig->smoothScale(bounds.size()); } PaperImage::~PaperImage() { if(pixmap_orig) delete pixmap_orig; } void PaperImage::MousePressed(QPoint p) { } void PaperImage::Draw(QPainter *paint) { if (AppControl->GetModeFlag(MPL_MF_ALPHA)==false) { QPixmap pm(pixmap.size()); pm.fill(); QPainter pa; pa.begin(&pm,this); pa.drawImage(0,0,pixmap); pa.end(); paint->drawPixmap(bounds.topLeft(),pm); } else paint->drawImage(bounds.topLeft(),pixmap); MathFrame::Draw(paint); }