Commit 66595e74 authored by Srikanth Tiyyagura's avatar Srikanth Tiyyagura

Improving the ImageSplit plugin

* Using the original filename_N instead imagesplit_N.kra
* Saving in various formats as requested by the user
* Added my copyright
parent 9ba09874
......@@ -2,6 +2,7 @@
* dlg_imagesplit.cc - part of KimageShop^WKrayon^WKrita
*
* Copyright (c) 2009 Boudewijn Rempt <boud@valdyas.org>
* Copyright (c) 2011 Srikanth Tiyyagura <srikanth.tulasiram@gmail.com>
*
* 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
......@@ -28,7 +29,7 @@
#include <kis_paint_device.h>
#include <kis_background.h>
DlgImagesplit::DlgImagesplit(KisView2* view)
DlgImagesplit::DlgImagesplit(KisView2* view,QString suffix,QStringList listMimeFilter)
: KDialog(view)
, m_view(view)
{
......@@ -42,10 +43,16 @@ DlgImagesplit::DlgImagesplit(KisView2* view)
connect(this, SIGNAL(applyClicked()),this, SLOT(applyClicked()));
setMainWidget(m_page);
m_page->setMinimumWidth (176);
m_page->setMinimumHeight(116);
m_page->lineEdit->setText(suffix);
m_page->setMinimumWidth (224);
m_page->setMinimumHeight(167);
resize(m_page->sizeHint());
m_page->cmbFileType->clear();
m_page->cmbFileType->addItems(listMimeFilter);
m_page->cmbFileType->setCurrentIndex(0);
connect(m_page->chkAutoSave,SIGNAL(stateChanged(int)),SLOT(lineEditEnable()));
connect(m_page->cmbFileType, SIGNAL(activated(int)), this, SLOT(setMimeType(int)));
}
DlgImagesplit::~DlgImagesplit()
......@@ -57,11 +64,15 @@ void DlgImagesplit::lineEditEnable()
if(m_page->chkAutoSave->isChecked()) {
m_page->lblSuffix->setEnabled(true);
m_page->lineEdit->setEnabled(true);
m_page->lblFileType->setEnabled(true);
m_page->cmbFileType->setEnabled(true);
}
else
{
m_page->lblSuffix->setEnabled(false);
m_page->lineEdit->setEnabled(false);
m_page->lblFileType->setEnabled(false);
m_page->cmbFileType->setEnabled(false);
}
}
......@@ -89,6 +100,11 @@ QString DlgImagesplit::suffix()
return m_page->lineEdit->text();
}
void DlgImagesplit::setMimeType(int index)
{
cmbIndex=index;
}
void DlgImagesplit::applyClicked()
{
accept();
......
......@@ -2,6 +2,7 @@
* dlg_imagesplit.h -- part of KimageShop^WKrayon^WKrita
*
* Copyright (c) 2009 Boudewijn Rempt <boud@valdyas.org>
* Copyright (c) 2011 Srikanth Tiyyagura <srikanth.tulasiram@gmail.com>
*
* 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
......@@ -38,17 +39,18 @@ class DlgImagesplit: public KDialog
public:
DlgImagesplit(KisView2* view);
DlgImagesplit(KisView2* view,QString suffix,QStringList listMimeType);
~DlgImagesplit();
bool autoSave();
int horizontalLines();
int verticalLines();
int cmbIndex;
QString suffix();
private slots:
void applyClicked();
void lineEditEnable();
void setMimeType(int index);
private:
KisView2* m_view;
WdgImagesplit* m_page;
......
......@@ -2,6 +2,7 @@
* imagesplit.cc -- Part of Krita
*
* Copyright (c) 2004 Boudewijn Rempt (boud@valdyas.org)
* Copyright (c) 2011 Srikanth Tiyyagura <srikanth.tulasiram@gmail.com>
*
* 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
......@@ -55,14 +56,12 @@ Imagesplit::Imagesplit(QObject *parent, const QVariantList &)
{
if (parent->inherits("KisView2")) {
setComponentData(ImagesplitFactory::componentData());
setXMLFile(KStandardDirs::locate("data", "kritaplugins/imagesplit.rc"), true);
KAction *action = new KAction(i18n("Image Split "), this);
actionCollection()->addAction("imagesplit", action);
connect(action, SIGNAL(triggered()), this, SLOT(slotImagesplit()));
m_view = (KisView2*) parent;
}
}
......@@ -94,8 +93,20 @@ void Imagesplit::saveAsImage(QRect imgSize,QString mimeType,KUrl url)
void Imagesplit::slotImagesplit()
{
// Taking the title - url from caption function and removing file extension
QStringList strList = ((m_view->document())->caption()).split(".");
QString suffix = strList.at(0);
// Getting all mime types and converting them into names which are displayed at combo box
QStringList listMimeFilter = KoFilterManager::mimeFilter("application/x-krita", KoFilterManager::Export);
QStringList listFileType;
foreach(const QString tempStr, listMimeFilter) {
QStringList tempStrList= tempStr.split("/");
listFileType.append((tempStrList.at(1)).toUpper()+ " IMAGE ");
}
DlgImagesplit * dlgImagesplit = new DlgImagesplit(m_view);
DlgImagesplit * dlgImagesplit = new DlgImagesplit(m_view,suffix,listFileType);
dlgImagesplit->setObjectName("Imagesplit");
Q_CHECK_PTR(dlgImagesplit);
......@@ -109,18 +120,16 @@ void Imagesplit::slotImagesplit()
int img_width = image->width()/(numVerticalLines+1);
int img_height = image->height()/(numHorizontalLines+1);
QStringList listMimeFilter = KoFilterManager::mimeFilter("application/x-krita", KoFilterManager::Export);
if (dlgImagesplit->autoSave()) {
for(int i=0,k=1;i<(numVerticalLines+1);i++) {
for(int j=0;j<(numHorizontalLines+1);j++,k++)
{
KUrl url( QDir::homePath());
QString fileName = dlgImagesplit->suffix()+"_"+ QString::number(k)+".kra";
QString fileName = dlgImagesplit->suffix()+"_"+ QString::number(k);
url.addPath( fileName );
KUrl kurl=url.url();
saveAsImage(QRect((i*img_width),(j*img_height),img_width,img_height),listMimeFilter.at(0),kurl);
saveAsImage(QRect((i*img_width),(j*img_height),img_width,img_height),listMimeFilter.at(dlgImagesplit->cmbIndex),kurl);
}
}
}
......@@ -150,10 +159,7 @@ void Imagesplit::slotImagesplit()
}
}
delete dlgImagesplit;
}
......
......@@ -2,6 +2,7 @@
* imagesplit.h -- Part of Krita
*
* Copyright (c) 2004 Boudewijn Rempt (boud@valdyas.org)
* Copyright (c) 2011 Srikanth Tiyyagura <srikanth.tulasiram@gmail.com>
*
* 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
......
......@@ -2,6 +2,7 @@
* dlg_imagesplit.cc - part of KimageShop^WKrayon^WKrita
*
* Copyright (c) 2009 Boudewijn Rempt <boud@valdyas.org>
* Copyright (c) 2011 Srikanth Tiyyagura <srikanth.tulasiram@gmail.com>
*
* 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
......
......@@ -2,6 +2,7 @@
* wdg_imagesplit.h -- part of KimageShop^WKrayon^WKrita
*
* Copyright (c) 2009 Boudewijn Rempt <boud@valdyas.org>
* Copyright (c) 2011 Srikanth Tiyyagura <srikanth.tulasiram@gmail.com>
*
* 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
......
......@@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>222</width>
<height>160</height>
<width>224</width>
<height>201</height>
</rect>
</property>
<property name="windowTitle">
......@@ -17,9 +17,9 @@
<property name="geometry">
<rect>
<x>11</x>
<y>12</y>
<width>207</width>
<height>147</height>
<y>14</y>
<width>196</width>
<height>176</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout">
......@@ -75,17 +75,27 @@
</property>
</widget>
</item>
<item row="3" column="1" colspan="2">
<item row="3" column="1" colspan="3">
<widget class="QLineEdit" name="lineEdit">
<property name="enabled">
<bool>true</bool>
</property>
<property name="text">
<string>imageSplit</string>
<string/>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="lblFileType">
<property name="text">
<string>File Type</string>
</property>
</widget>
</item>
<item row="4" column="1" colspan="3">
<widget class="QComboBox" name="cmbFileType"/>
</item>
<item row="5" column="1">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment