Commit 57612d6d authored by Thomas Zander's avatar Thomas Zander

Scrap the 'shapes' subdir and move all its content into the plugins subdir.

svn path=/trunk/koffice/; revision=744390
parent 55b09399
......@@ -175,7 +175,6 @@ add_subdirectory(servicetypes)
add_subdirectory(templates)
add_subdirectory(tools)
add_subdirectory(filters)
add_subdirectory(shapes)
macro_optional_add_subdirectory(doc)
message( STATUS "Re-add koshell when ported")
......
EXCLUDE includes
......@@ -5,3 +5,8 @@ add_subdirectory( defaultTools )
add_subdirectory( dockers )
add_subdirectory( textediting )
add_subdirectory( simpletextedit )
add_subdirectory( pathshapes )
add_subdirectory( pictureshape )
add_subdirectory( textshape )
macro_optional_add_subdirectory( musicshape )
add_subdirectory( divineProportion )
project( divineProportion)
include_directories( ${KOMAIN_INCLUDES} ${FLAKE_INCLUDES} )
SET ( divineProportionShape_SRCS
DivineProportionPlugin.cpp
DivineProportionShape.cpp
DivineProportionShapeFactory.cpp
DivineProportionTool.cpp
DivineProportionToolFactory.cpp
Intro.cpp
)
kde4_add_ui_files(divineProportionShape_SRCS
Intro.ui
)
kde4_add_plugin(divineproportionshape ${divineProportionShape_SRCS})
target_link_libraries(divineproportionshape flake)
install(TARGETS divineproportionshape DESTINATION ${PLUGIN_INSTALL_DIR})
########### install files ###############
install( FILES divineproportionshape.desktop DESTINATION ${SERVICES_INSTALL_DIR})
#kde4_install_icons( ${DATA_INSTALL_DIR}/koffice/icons )
/* This file is part of the KDE project
* Copyright (C) 2007 Thomas Zander <zander@kde.org>
*
* 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 "DivineProportionPlugin.h"
#include "DivineProportionToolFactory.h"
#include "DivineProportionShapeFactory.h"
#include <KoShapeRegistry.h>
#include <KoToolRegistry.h>
#include <kgenericfactory.h>
K_EXPORT_COMPONENT_FACTORY(divineproportionshape, KGenericFactory<DivineProportionPlugin>( "DivineProportion" ) )
DivineProportionPlugin::DivineProportionPlugin(QObject * parent, const QStringList &)
: QObject(parent)
{
KoToolRegistry::instance()->add(new DivineProportionToolFactory(parent));
KoShapeRegistry::instance()->add(new DivineProportionShapeFactory(parent));
}
#include "DivineProportionPlugin.moc"
/* This file is part of the KDE project
* Copyright (C) 2007 Thomas Zander <zander@kde.org>
*
* 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.
*/
#ifndef PLUGIN_H
#define PLUGIN_H
#include <QObject>
class DivineProportionPlugin : public QObject {
Q_OBJECT
public:
DivineProportionPlugin(QObject * parent, const QStringList &);
~DivineProportionPlugin() {}
};
#endif
/* This file is part of the KDE project
* Copyright (C) 2006 Boudewijn Rempt <boud@valdyas.org>
* Copyright (C) 2006-2007 Thomas Zander <zander@kde.org>
*
* 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 "DivineProportionShape.h"
#include <QPen>
#include <QPainter>
#include <KDebug>
#include <math.h>
DivineProportionShape::DivineProportionShape()
: m_divineProportion( (1.0 + sqrt(5.0)) / 2.0),
m_orientation(TopRight),
m_printable(false)
{
setShapeId(DivineProportionShape_SHAPEID);
}
DivineProportionShape::~DivineProportionShape() {
}
void DivineProportionShape::paint(QPainter &painter, const KoViewConverter &converter) {
if(m_printable) {
applyConversion(painter, converter);
draw(painter);
}
}
void DivineProportionShape::paintDecorations(QPainter &painter, const KoViewConverter &converter, const KoCanvasBase *canvas) {
if(!m_printable) {
applyConversion(painter, converter);
painter.setRenderHint(QPainter::Antialiasing);
draw(painter);
}
}
void DivineProportionShape::draw(QPainter &painter) {
painter.setPen(QPen(QColor(172, 196, 206)));
QRectF rect(QPointF(0,0), size());
bool top, left;
switch(m_orientation) {
case BottomRight: top = false, left = false; break;
case BottomLeft: top = false, left = true; break;
case TopRight: top = true, left = false; break;
case TopLeft: top = true, left = true; break;
}
divideVertical(painter, rect, top, left);
painter.setPen(QPen(QColor(173, 123, 134)));
const double x1 = rect.width() / m_divineProportion;
const double x2 = rect.width() - x1;
if(top && !left || !top && left) {
painter.drawLine(rect.bottomLeft(), rect.topRight());
painter.drawLine(QPointF(x1, 0), rect.bottomRight());
painter.drawLine(QPointF(0,0), QPointF(x2, rect.bottom()));
}
else {
painter.drawLine(rect.topLeft(), rect.bottomRight());
painter.drawLine(QPointF(x2, 0), rect.bottomLeft());
painter.drawLine(QPointF(x1, rect.bottom()), rect.topRight());
}
}
void DivineProportionShape::saveOdf(KoShapeSavingContext & context) const {
// TODO
}
bool DivineProportionShape::loadOdf( const KoXmlElement & element, KoShapeLoadingContext &context ) {
return false; // TODO
}
void DivineProportionShape::divideHorizontal(QPainter &painter, const QRectF &rect, bool top, bool left) {
if(rect.height() < 2)
return;
const double y = rect.height() / m_divineProportion;
const double offset = top ? rect.bottom() - y : rect.top() + y;
// draw horizontal line.
painter.drawLine(QPointF(rect.left(), offset), QPointF(rect.right(), offset));
divideVertical(painter, QRectF( QPointF(rect.left(), top ? rect.top() : offset),
QSizeF(rect.width(), rect.height() - y)), !top, left);
}
void DivineProportionShape::divideVertical(QPainter &painter, const QRectF &rect, bool top, bool left) {
if(rect.width() < 2)
return;
const double x = rect.width() / m_divineProportion;
const double offset = left ? rect.right() - x : rect.left() + x;
// draw vertical line
painter.drawLine(QPointF(offset, rect.top()), QPointF(offset, rect.bottom()));
divideHorizontal(painter, QRectF(QPointF( left ? rect.left() : offset, rect.top()),
QSizeF(rect.width() - x, rect.height())), top, !left);
}
void DivineProportionShape::setOrientation(Orientation orientation) {
if(m_orientation == orientation)
return;
m_orientation = orientation;
update();
}
void DivineProportionShape::setPrintable(bool on) {
if(m_printable == on)
return;
m_printable = on;
update();
}
/* This file is part of the KDE project
* Copyright (C) 2007 Thomas Zander <zander@kde.org>
*
* 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.
*/
#ifndef SHAPE_H
#define SHAPE_H
#include <KoShape.h>
class QPainter;
#define DivineProportionShape_SHAPEID "DivineProportionShapeID"
class DivineProportionShape : public KoShape {
public:
DivineProportionShape();
virtual ~DivineProportionShape();
// Define where the disappearing point is.
enum Orientation {
BottomRight,
BottomLeft,
TopRight,
TopLeft
};
/// reimplemented to be empty (this shape is fully non-printing)
void paint(QPainter &painter, const KoViewConverter &converter);
/// reimplemented
void paintDecorations(QPainter &painter, const KoViewConverter &converter, const KoCanvasBase *canvas);
/// reimplemented
virtual void saveOdf(KoShapeSavingContext & context) const;
/// reimplemented
virtual bool loadOdf( const KoXmlElement & element, KoShapeLoadingContext &context );
void setOrientation(Orientation orientation);
Orientation orientation() const { return m_orientation; }
void setPrintable(bool on);
bool printable() const { return m_printable; }
private:
void divideHorizontal(QPainter &painter, const QRectF &rect, bool top, bool left);
void divideVertical(QPainter &painter, const QRectF &rect, bool top, bool left);
void draw(QPainter &painter);
const double m_divineProportion;
Orientation m_orientation;
bool m_printable;
};
#endif
/* This file is part of the KDE project
* Copyright (C) 2007 Thomas Zander <zander@kde.org>
*
* 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 "DivineProportionShapeFactory.h"
#include "DivineProportionShape.h"
#include "Intro.h"
#include <klocale.h>
DivineProportionShapeFactory::DivineProportionShapeFactory(QObject *parent)
: KoShapeFactory(parent, DivineProportionShape_SHAPEID, i18n("DivineProportion"))
{
setToolTip(i18n("A Shape That Shows DivineProportion"));
setIcon( "divine-shape" );
}
KoShape *DivineProportionShapeFactory::createDefaultShape() const {
DivineProportionShape *text = new DivineProportionShape();
return text;
}
KoShape *DivineProportionShapeFactory::createShape(const KoProperties * /*params*/) const {
return createDefaultShape();
}
QList<KoShapeConfigWidgetBase*> DivineProportionShapeFactory::createShapeOptionPanels() {
QList<KoShapeConfigWidgetBase*> answer;
answer.append(new Intro());
return answer;
}
#include "DivineProportionShapeFactory.moc"
/* This file is part of the KDE project
* Copyright (C) 2007 Thomas Zander <zander@kde.org>
*
* 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.
*/
#ifndef SHAPEFACTORY_H
#define SHAPEFACTORY_H
#include <KoShapeFactory.h>
class KoShape;
class DivineProportionShapeFactory : public KoShapeFactory {
Q_OBJECT
public:
/// constructor
explicit DivineProportionShapeFactory(QObject *parent);
~DivineProportionShapeFactory() {}
KoShape *createDefaultShape() const;
KoShape *createShape(const KoProperties * params) const;
QList<KoShapeConfigWidgetBase*> createShapeOptionPanels();
};
#endif
/* This file is part of the KDE project
* Copyright (C) 2007 Thomas Zander <zander@kde.org>
*
* 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 "DivineProportionTool.h"
#include <KoCanvasBase.h>
#include <KoSelection.h>
#include <KoShapeManager.h>
#include <KoPointerEvent.h>
#include <KLocale>
#include <KIcon>
#include <QAction>
#include <QGridLayout>
#include <QToolButton>
#include <QCheckBox>
DivineProportionTool::DivineProportionTool(KoCanvasBase *canvas)
: KoTool(canvas),
m_currentShape(0)
{
QActionGroup *group = new QActionGroup(this);
m_topLeftOrientation = new QAction(KIcon("golden-ratio-topleft"), i18n("Top Left"), this);
m_topLeftOrientation->setCheckable(true);
group->addAction(m_topLeftOrientation);
connect( m_topLeftOrientation, SIGNAL(toggled(bool)), this, SLOT(topLeftOrientationToggled(bool)) );
m_topRightOrientation = new QAction(KIcon("golden-ratio-topright"), i18n("Top Right"), this);
m_topRightOrientation->setCheckable(true);
group->addAction(m_topRightOrientation);
connect( m_topRightOrientation, SIGNAL(toggled(bool)), this, SLOT(topRightOrientationToggled(bool)) );
m_bottomRightOrientation = new QAction(KIcon("golden-ratio-bottomleft"), i18n("Bottom Right"), this);
m_bottomRightOrientation->setCheckable(true);
group->addAction(m_bottomRightOrientation);
connect( m_bottomRightOrientation, SIGNAL(toggled(bool)), this, SLOT(bottomRightOrientationToggled(bool)) );
m_bottomLeftOrientation = new QAction(KIcon("golden-ratio-bottomright"), i18n("Bottom Left"), this);
m_bottomLeftOrientation->setCheckable(true);
group->addAction(m_bottomLeftOrientation);
connect( m_bottomLeftOrientation, SIGNAL(toggled(bool)), this, SLOT(bottomLeftOrientationToggled(bool)) );
}
DivineProportionTool::~DivineProportionTool() {
}
void DivineProportionTool::paint( QPainter &painter, const KoViewConverter &converter) {
}
void DivineProportionTool::mousePressEvent( KoPointerEvent *event ) {
event->ignore();
}
void DivineProportionTool::mouseMoveEvent( KoPointerEvent *event ) {
event->ignore();
}
void DivineProportionTool::mouseReleaseEvent( KoPointerEvent *event ) {
event->ignore();
}
void DivineProportionTool::activate (bool) {
KoSelection *selection = m_canvas->shapeManager()->selection();
foreach(KoShape *shape, selection->selectedShapes()) {
m_currentShape = dynamic_cast<DivineProportionShape*> (shape);
if(m_currentShape)
break;
}
if(m_currentShape == 0) { // none found
emit done();
return;
}
//useCursor() // lets keep the forbidden cursor for now; as this tool doesn't really allow mouse interaction anyway
updateActions();
}
void DivineProportionTool::deactivate() {
m_currentShape = 0;
}
void DivineProportionTool::updateActions() {
switch(m_currentShape->orientation()) {
case DivineProportionShape::BottomRight: m_bottomRightOrientation->setChecked(true); break;
case DivineProportionShape::BottomLeft: m_bottomLeftOrientation->setChecked(true); break;
case DivineProportionShape::TopRight: m_topRightOrientation->setChecked(true); break;
case DivineProportionShape::TopLeft: m_topLeftOrientation->setChecked(true); break;
}
}
void DivineProportionTool::topLeftOrientationToggled(bool on) {
if(on && m_currentShape)
m_currentShape->setOrientation(DivineProportionShape::TopLeft);
}
void DivineProportionTool::topRightOrientationToggled(bool on) {
if(on && m_currentShape)
m_currentShape->setOrientation(DivineProportionShape::TopRight);
}
void DivineProportionTool::bottomLeftOrientationToggled(bool on) {
if(on && m_currentShape)
m_currentShape->setOrientation(DivineProportionShape::BottomLeft);
}