1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
|
/*
* This file is part of the KDE project
* Copyright (C) 2010 Sebastian Sauer <sebsauer@kdab.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Library 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.
*/
#include "AutoResizeCommand.h"
#include "TextShape.h"
#include <klocale.h>
//#include <KAction>
AutoResizeCommand::AutoResizeCommand(KoTextShapeData *shapeData, KoTextShapeData::ResizeMethod resizeMethod, bool enabled)
: KUndo2Command()
, m_shapeData(shapeData)
, m_resizeMethod(resizeMethod)
, m_enabled(enabled)
, m_first(true)
, m_prevResizeMethod(KoTextShapeData::NoResize)
{
Q_ASSERT(m_shapeData);
const QString s = m_enabled ? i18nc("Enable Shrink To Fit", "Enable") : i18nc("Disable Shrink To Fit", "Disable");
switch (m_resizeMethod) {
case KoTextShapeData::AutoGrowWidth:
setText(i18nc("(qtundo-format) Enable/Disable Grow To Fit Width", "%1 Grow To Fit Width", s));
break;
case KoTextShapeData::AutoGrowHeight:
setText(i18nc("(qtundo-format) Enable/Disable Grow To Fit Height", "%1 Grow To Fit Height", s));
break;
case KoTextShapeData::ShrinkToFitResize:
setText(i18nc("(qtundo-format) Enable/Disable Shrink To Fit", "%1 Shrink To Fit", s));
break;
default:
Q_ASSERT_X(false, __FUNCTION__, QString("The resize-method '%1' is unsupported by this command").arg(resizeMethod).toUtf8());
break;
}
}
void AutoResizeCommand::undo()
{
m_shapeData->setResizeMethod(m_prevResizeMethod);
}
void AutoResizeCommand::redo()
{
if (m_first) {
m_first = false;
m_prevResizeMethod = m_shapeData->resizeMethod();
}
KoTextShapeData::ResizeMethod resize = m_enabled ? m_resizeMethod : KoTextShapeData::NoResize;
if (m_resizeMethod == KoTextShapeData::AutoGrowWidth || m_resizeMethod == KoTextShapeData::AutoGrowHeight) {
if (m_enabled) {
if ((m_shapeData->resizeMethod() == KoTextShapeData::AutoGrowWidth || m_shapeData->resizeMethod() == KoTextShapeData::AutoGrowHeight) && m_resizeMethod != m_shapeData->resizeMethod())
resize = KoTextShapeData::AutoGrowWidthAndHeight;
} else {
if (m_shapeData->resizeMethod() == KoTextShapeData::AutoGrowWidthAndHeight)
resize = m_resizeMethod == KoTextShapeData::AutoGrowWidth ? KoTextShapeData::AutoGrowHeight : KoTextShapeData::AutoGrowWidth;
}
}
m_shapeData->setResizeMethod(resize);
}
|