├── README.md ├── images ├── logo.png ├── play.png ├── rect.png ├── svg.png ├── text.png ├── arrow.png ├── camera.png ├── ellipse.png ├── forward.png ├── pause.png ├── raute.png ├── reverse.png ├── playhead.png ├── rectangle.png ├── autokeyframe.png ├── branch-open.png ├── raute-hohl.png ├── raute-hover.png ├── raute-weiss.png ├── trans-left.png ├── trans-right.png ├── autotransition.png ├── branch-closed.png └── expanderButton.png ├── Deploy └── AppImage │ ├── default.png │ ├── default.desktop │ └── create.sh ├── exception.cpp ├── exception.h ├── todo.txt ├── keyframe.cpp ├── images.qrc ├── colorrect.cpp ├── ellipse.h ├── colorrect.h ├── expander.h ├── rectangle.h ├── bitmap.h ├── ellipse.cpp ├── rectangle.cpp ├── colorpicker.h ├── vectorgraphic.h ├── playhead.h ├── keyframe.h ├── text.h ├── scenepropertyeditor.h ├── bitmap.cpp ├── main.cpp ├── transitionpanel.h ├── itemhandle.h ├── coloreditor.h ├── expander.cpp ├── transitionline.h ├── playhead.cpp ├── vectorgraphic.cpp ├── text.cpp ├── colorpicker.cpp ├── AnimationMaker.pro ├── itempropertyeditor.h ├── scenepropertyeditor.cpp ├── itemhandle.cpp ├── timeline.h ├── mainwindow.h ├── resizeableitem.h ├── animationscene.h ├── commands.h ├── transitionline.cpp ├── transitionpanel.cpp ├── encode.cpp ├── coloreditor.cpp ├── commands.cpp ├── itempropertyeditor.cpp ├── timeline.cpp └── animationscene.cpp /README.md: -------------------------------------------------------------------------------- 1 | # AnimationMaker 2 | -------------------------------------------------------------------------------- /images/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/probonopd/AnimationMaker/master/images/logo.png -------------------------------------------------------------------------------- /images/play.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/probonopd/AnimationMaker/master/images/play.png -------------------------------------------------------------------------------- /images/rect.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/probonopd/AnimationMaker/master/images/rect.png -------------------------------------------------------------------------------- /images/svg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/probonopd/AnimationMaker/master/images/svg.png -------------------------------------------------------------------------------- /images/text.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/probonopd/AnimationMaker/master/images/text.png -------------------------------------------------------------------------------- /images/arrow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/probonopd/AnimationMaker/master/images/arrow.png -------------------------------------------------------------------------------- /images/camera.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/probonopd/AnimationMaker/master/images/camera.png -------------------------------------------------------------------------------- /images/ellipse.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/probonopd/AnimationMaker/master/images/ellipse.png -------------------------------------------------------------------------------- /images/forward.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/probonopd/AnimationMaker/master/images/forward.png -------------------------------------------------------------------------------- /images/pause.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/probonopd/AnimationMaker/master/images/pause.png -------------------------------------------------------------------------------- /images/raute.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/probonopd/AnimationMaker/master/images/raute.png -------------------------------------------------------------------------------- /images/reverse.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/probonopd/AnimationMaker/master/images/reverse.png -------------------------------------------------------------------------------- /images/playhead.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/probonopd/AnimationMaker/master/images/playhead.png -------------------------------------------------------------------------------- /images/rectangle.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/probonopd/AnimationMaker/master/images/rectangle.png -------------------------------------------------------------------------------- /images/autokeyframe.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/probonopd/AnimationMaker/master/images/autokeyframe.png -------------------------------------------------------------------------------- /images/branch-open.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/probonopd/AnimationMaker/master/images/branch-open.png -------------------------------------------------------------------------------- /images/raute-hohl.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/probonopd/AnimationMaker/master/images/raute-hohl.png -------------------------------------------------------------------------------- /images/raute-hover.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/probonopd/AnimationMaker/master/images/raute-hover.png -------------------------------------------------------------------------------- /images/raute-weiss.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/probonopd/AnimationMaker/master/images/raute-weiss.png -------------------------------------------------------------------------------- /images/trans-left.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/probonopd/AnimationMaker/master/images/trans-left.png -------------------------------------------------------------------------------- /images/trans-right.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/probonopd/AnimationMaker/master/images/trans-right.png -------------------------------------------------------------------------------- /images/autotransition.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/probonopd/AnimationMaker/master/images/autotransition.png -------------------------------------------------------------------------------- /images/branch-closed.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/probonopd/AnimationMaker/master/images/branch-closed.png -------------------------------------------------------------------------------- /images/expanderButton.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/probonopd/AnimationMaker/master/images/expanderButton.png -------------------------------------------------------------------------------- /Deploy/AppImage/default.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/probonopd/AnimationMaker/master/Deploy/AppImage/default.png -------------------------------------------------------------------------------- /exception.cpp: -------------------------------------------------------------------------------- 1 | #include "exception.h" 2 | 3 | Exception::Exception(QString msg) 4 | { 5 | m_msg = msg; 6 | } 7 | -------------------------------------------------------------------------------- /Deploy/AppImage/default.desktop: -------------------------------------------------------------------------------- 1 | [Desktop Entry] 2 | Type=Application 3 | Name=Application 4 | Exec=AppRun %F 5 | Icon=default 6 | Comment=AnimationMaker 7 | Terminal=true 8 | -------------------------------------------------------------------------------- /exception.h: -------------------------------------------------------------------------------- 1 | #ifndef EXCEPTION_H 2 | #define EXCEPTION_H 3 | 4 | #include 5 | 6 | class Exception : QException 7 | { 8 | public: 9 | Exception(QString msg); 10 | 11 | QString msg() {return m_msg;} 12 | 13 | private: 14 | QString m_msg; 15 | }; 16 | 17 | #endif // EXCEPTION_H 18 | -------------------------------------------------------------------------------- /Deploy/AppImage/create.sh: -------------------------------------------------------------------------------- 1 | LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/olaf/Qt/5.8/gcc_64/lib 2 | export LD_LIBRARY_PATH 3 | PATH=$PATH:/home/olaf/Qt/5.8/gcc_64/bin 4 | export PATH 5 | /home/olaf/linuxdeployqt/linuxdeployqt-continuous-x86_64.AppImage AnimationMaker -appimage 6 | mv Application-x86_64.AppImage AnimationMaker-x86_64-1.0-alpha.AppImage 7 | 8 | -------------------------------------------------------------------------------- /todo.txt: -------------------------------------------------------------------------------- 1 | 2 | Icon integrate for each platform 3 | 4 | ColorAnimation ? 5 | 6 | additional properties? 7 | 8 | Install package 9 | 10 | 11 | 12 | Next release 13 | ------------ 14 | Treeview 15 | - Object make invisible 16 | - Object lock 17 | 18 | Export as plugin? 19 | 20 | Export HTML ? 21 | 22 | Rectangle new 23 | - create via mouse drag 24 | - pressing ALT-key mouse position will be used as center 25 | 26 | Toolbar for files (Save, Open) 27 | 28 | Items Translation like Rotate 29 | 30 | ScrollArea for PropertyPanel 31 | 32 | Scene Zoom, Minimum size of 20x20 not needed anymore if zoom is implemented 33 | 34 | Change Transition Easing 35 | -------------------------------------------------------------------------------- /keyframe.cpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** Copyright (C) 2016 Olaf Japp 3 | ** 4 | ** This file is part of AnimationMaker. 5 | ** 6 | ** AnimationMaker is free software: you can redistribute it and/or modify 7 | ** it under the terms of the GNU General Public License as published by 8 | ** the Free Software Foundation, either version 3 of the License, or 9 | ** (at your option) any later version. 10 | ** 11 | ** AnimationMaker is distributed in the hope that it will be useful, 12 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | ** GNU General Public License for more details. 15 | ** 16 | ** You should have received a copy of the GNU General Public License 17 | ** along with AnimationMaker. If not, see . 18 | ** 19 | ****************************************************************************/ 20 | 21 | #include "keyframe.h" 22 | 23 | KeyFrame::KeyFrame() 24 | { 25 | m_easing = -1; // no transition 26 | m_next = NULL; 27 | m_prev = NULL; 28 | } 29 | -------------------------------------------------------------------------------- /images.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | images/play.png 4 | images/rect.png 5 | images/arrow.png 6 | images/ellipse.png 7 | images/rectangle.png 8 | images/text.png 9 | images/camera.png 10 | images/svg.png 11 | images/forward.png 12 | images/reverse.png 13 | images/expanderButton.png 14 | images/branch-closed.png 15 | images/branch-open.png 16 | images/playhead.png 17 | images/raute.png 18 | images/raute-hover.png 19 | images/raute-weiss.png 20 | images/raute-hohl.png 21 | images/trans-left.png 22 | images/trans-right.png 23 | images/pause.png 24 | images/autokeyframe.png 25 | images/autotransition.png 26 | images/logo.png 27 | 28 | 29 | -------------------------------------------------------------------------------- /colorrect.cpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** Copyright (C) 2016 Olaf Japp 3 | ** 4 | ** This file is part of AnimationMaker. 5 | ** 6 | ** AnimationMaker is free software: you can redistribute it and/or modify 7 | ** it under the terms of the GNU General Public License as published by 8 | ** the Free Software Foundation, either version 3 of the License, or 9 | ** (at your option) any later version. 10 | ** 11 | ** AnimationMaker is distributed in the hope that it will be useful, 12 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | ** GNU General Public License for more details. 15 | ** 16 | ** You should have received a copy of the GNU General Public License 17 | ** along with AnimationMaker. If not, see . 18 | ** 19 | ****************************************************************************/ 20 | 21 | #include "colorrect.h" 22 | 23 | #include 24 | 25 | ColorRect::ColorRect() 26 | { 27 | m_color = Qt::black; 28 | setMinimumSize(18, 18); 29 | setMaximumSize(18, 18); 30 | } 31 | 32 | void ColorRect::paintEvent(QPaintEvent *) 33 | { 34 | QPainter painter(this); 35 | painter.fillRect(0, 0, width(), height(), m_color); 36 | } 37 | 38 | void ColorRect::mousePressEvent(QMouseEvent *) 39 | { 40 | emit mouseClicked(); 41 | } 42 | -------------------------------------------------------------------------------- /ellipse.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** Copyright (C) 2016 Olaf Japp 3 | ** 4 | ** This file is part of AnimationMaker. 5 | ** 6 | ** AnimationMaker is free software: you can redistribute it and/or modify 7 | ** it under the terms of the GNU General Public License as published by 8 | ** the Free Software Foundation, either version 3 of the License, or 9 | ** (at your option) any later version. 10 | ** 11 | ** AnimationMaker is distributed in the hope that it will be useful, 12 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | ** GNU General Public License for more details. 15 | ** 16 | ** You should have received a copy of the GNU General Public License 17 | ** along with AnimationMaker. If not, see . 18 | ** 19 | ****************************************************************************/ 20 | 21 | #ifndef ELLIPSE_H 22 | #define ELLIPSE_H 23 | 24 | #include 25 | #include "resizeableitem.h" 26 | 27 | class Ellipse : public ResizeableItem 28 | { 29 | public: 30 | Ellipse(qreal width, qreal height, AnimationScene *scene); 31 | 32 | void paint( QPainter *paint, const QStyleOptionGraphicsItem *, QWidget *); 33 | 34 | enum { Type = UserType + 2 }; 35 | int type() const Q_DECL_OVERRIDE; 36 | }; 37 | 38 | #endif // ELLIPSE_H 39 | -------------------------------------------------------------------------------- /colorrect.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** Copyright (C) 2016 Olaf Japp 3 | ** 4 | ** This file is part of AnimationMaker. 5 | ** 6 | ** AnimationMaker is free software: you can redistribute it and/or modify 7 | ** it under the terms of the GNU General Public License as published by 8 | ** the Free Software Foundation, either version 3 of the License, or 9 | ** (at your option) any later version. 10 | ** 11 | ** AnimationMaker is distributed in the hope that it will be useful, 12 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | ** GNU General Public License for more details. 15 | ** 16 | ** You should have received a copy of the GNU General Public License 17 | ** along with AnimationMaker. If not, see . 18 | ** 19 | ****************************************************************************/ 20 | 21 | #ifndef COLORRECT_H 22 | #define COLORRECT_H 23 | 24 | #include 25 | 26 | class ColorRect : public QWidget 27 | { 28 | Q_OBJECT 29 | public: 30 | ColorRect(); 31 | 32 | void paintEvent(QPaintEvent *ev); 33 | void mousePressEvent(QMouseEvent *ev); 34 | 35 | inline void setColor(QColor color) {m_color = color; update();} 36 | 37 | signals: 38 | void mouseClicked(); 39 | 40 | private: 41 | QColor m_color; 42 | }; 43 | 44 | #endif // COLORRECT_H 45 | -------------------------------------------------------------------------------- /expander.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** Copyright (C) 2016 Olaf Japp 3 | ** 4 | ** This file is part of AnimationMaker. 5 | ** 6 | ** AnimationMaker is free software: you can redistribute it and/or modify 7 | ** it under the terms of the GNU General Public License as published by 8 | ** the Free Software Foundation, either version 3 of the License, or 9 | ** (at your option) any later version. 10 | ** 11 | ** AnimationMaker is distributed in the hope that it will be useful, 12 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | ** GNU General Public License for more details. 15 | ** 16 | ** You should have received a copy of the GNU General Public License 17 | ** along with AnimationMaker. If not, see . 18 | ** 19 | ****************************************************************************/ 20 | 21 | #ifndef EXPANDER_H 22 | #define EXPANDER_H 23 | 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | class Expander : public QWidget 30 | { 31 | Q_OBJECT 32 | public: 33 | Expander(QString header); 34 | 35 | void addLayout(QLayout *l); 36 | 37 | public slots: 38 | void buttonClicked(bool); 39 | 40 | private : 41 | QWidget *m_content; 42 | QToolButton *m_button; 43 | bool m_isExpanded; 44 | }; 45 | 46 | #endif // EXPANDER_H 47 | -------------------------------------------------------------------------------- /rectangle.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** Copyright (C) 2016 Olaf Japp 3 | ** 4 | ** This file is part of AnimationMaker. 5 | ** 6 | ** AnimationMaker is free software: you can redistribute it and/or modify 7 | ** it under the terms of the GNU General Public License as published by 8 | ** the Free Software Foundation, either version 3 of the License, or 9 | ** (at your option) any later version. 10 | ** 11 | ** AnimationMaker is distributed in the hope that it will be useful, 12 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | ** GNU General Public License for more details. 15 | ** 16 | ** You should have received a copy of the GNU General Public License 17 | ** along with AnimationMaker. If not, see . 18 | ** 19 | ****************************************************************************/ 20 | 21 | #ifndef RECTANGLE_H 22 | #define RECTANGLE_H 23 | 24 | #include 25 | #include 26 | #include "resizeableitem.h" 27 | 28 | class Rectangle : public ResizeableItem 29 | { 30 | Q_OBJECT 31 | public: 32 | Rectangle(qreal width, qreal height, AnimationScene *scene); 33 | 34 | void paint( QPainter *paint, const QStyleOptionGraphicsItem *, QWidget *); 35 | 36 | enum { Type = UserType + 1 }; 37 | int type() const Q_DECL_OVERRIDE; 38 | }; 39 | 40 | #endif // RECTANGLE_H 41 | -------------------------------------------------------------------------------- /bitmap.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** Copyright (C) 2016 Olaf Japp 3 | ** 4 | ** This file is part of AnimationMaker. 5 | ** 6 | ** AnimationMaker is free software: you can redistribute it and/or modify 7 | ** it under the terms of the GNU General Public License as published by 8 | ** the Free Software Foundation, either version 3 of the License, or 9 | ** (at your option) any later version. 10 | ** 11 | ** AnimationMaker is distributed in the hope that it will be useful, 12 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | ** GNU General Public License for more details. 15 | ** 16 | ** You should have received a copy of the GNU General Public License 17 | ** along with AnimationMaker. If not, see . 18 | ** 19 | ****************************************************************************/ 20 | 21 | #ifndef BITMAP_H 22 | #define BITMAP_H 23 | 24 | #include 25 | #include "resizeableitem.h" 26 | 27 | class Bitmap : public ResizeableItem 28 | { 29 | public: 30 | Bitmap(QString filename, AnimationScene *scene); 31 | Bitmap(QImage img, qreal width, qreal height, AnimationScene *scene); 32 | 33 | void paint( QPainter *paint, const QStyleOptionGraphicsItem *, QWidget *); 34 | 35 | QImage getImage(); 36 | 37 | enum { Type = UserType + 4 }; 38 | int type() const Q_DECL_OVERRIDE; 39 | 40 | private: 41 | QImage m_image; 42 | }; 43 | 44 | #endif // BITMAP_H 45 | -------------------------------------------------------------------------------- /ellipse.cpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** Copyright (C) 2016 Olaf Japp 3 | ** 4 | ** This file is part of AnimationMaker. 5 | ** 6 | ** AnimationMaker is free software: you can redistribute it and/or modify 7 | ** it under the terms of the GNU General Public License as published by 8 | ** the Free Software Foundation, either version 3 of the License, or 9 | ** (at your option) any later version. 10 | ** 11 | ** AnimationMaker is distributed in the hope that it will be useful, 12 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | ** GNU General Public License for more details. 15 | ** 16 | ** You should have received a copy of the GNU General Public License 17 | ** along with AnimationMaker. If not, see . 18 | ** 19 | ****************************************************************************/ 20 | 21 | #include "ellipse.h" 22 | 23 | #include 24 | #include 25 | #include 26 | 27 | Ellipse::Ellipse(qreal width, qreal height, AnimationScene *scene) 28 | : ResizeableItem(scene) 29 | { 30 | setRect(0, 0, width, height); 31 | } 32 | 33 | int Ellipse::type() const 34 | { 35 | return Ellipse::Type; 36 | } 37 | 38 | void Ellipse::paint( QPainter *paint, const QStyleOptionGraphicsItem *option, QWidget *widget) 39 | { 40 | Q_UNUSED(widget); 41 | paint->setPen(pen()); 42 | paint->setBrush(brush()); 43 | paint->drawEllipse(rect()); 44 | 45 | if (option->state & QStyle::State_Selected) 46 | drawHighlightSelected(paint, option); 47 | } 48 | -------------------------------------------------------------------------------- /rectangle.cpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** Copyright (C) 2016 Olaf Japp 3 | ** 4 | ** This file is part of AnimationMaker. 5 | ** 6 | ** AnimationMaker is free software: you can redistribute it and/or modify 7 | ** it under the terms of the GNU General Public License as published by 8 | ** the Free Software Foundation, either version 3 of the License, or 9 | ** (at your option) any later version. 10 | ** 11 | ** AnimationMaker is distributed in the hope that it will be useful, 12 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | ** GNU General Public License for more details. 15 | ** 16 | ** You should have received a copy of the GNU General Public License 17 | ** along with AnimationMaker. If not, see . 18 | ** 19 | ****************************************************************************/ 20 | 21 | #include "rectangle.h" 22 | 23 | #include 24 | #include 25 | #include 26 | 27 | Rectangle::Rectangle(qreal width, qreal height, AnimationScene *scene) 28 | : ResizeableItem(scene) 29 | { 30 | setRect(0, 0, width, height); 31 | } 32 | 33 | int Rectangle::type() const 34 | { 35 | return Rectangle::Type; 36 | } 37 | 38 | void Rectangle::paint( QPainter *paint, const QStyleOptionGraphicsItem *option, QWidget *widget) 39 | { 40 | Q_UNUSED(option); 41 | Q_UNUSED(widget); 42 | paint->setPen(pen()); 43 | paint->setBrush(brush()); 44 | paint->drawRect(rect()); 45 | 46 | if (option->state & QStyle::State_Selected) 47 | drawHighlightSelected(paint, option); 48 | } 49 | -------------------------------------------------------------------------------- /colorpicker.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** Copyright (C) 2016 Olaf Japp 3 | ** 4 | ** This file is part of AnimationMaker. 5 | ** 6 | ** AnimationMaker is free software: you can redistribute it and/or modify 7 | ** it under the terms of the GNU General Public License as published by 8 | ** the Free Software Foundation, either version 3 of the License, or 9 | ** (at your option) any later version. 10 | ** 11 | ** AnimationMaker is distributed in the hope that it will be useful, 12 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | ** GNU General Public License for more details. 15 | ** 16 | ** You should have received a copy of the GNU General Public License 17 | ** along with AnimationMaker. If not, see . 18 | ** 19 | ****************************************************************************/ 20 | 21 | #ifndef COLORPICKER_H 22 | #define COLORPICKER_H 23 | 24 | #include 25 | #include 26 | 27 | class ColorPicker : public QWidget 28 | { 29 | Q_OBJECT 30 | public: 31 | ColorPicker(); 32 | 33 | void paintEvent(QPaintEvent *ev); 34 | virtual void mousePressEvent(QMouseEvent * event); 35 | virtual void mouseMoveEvent(QMouseEvent *event); 36 | virtual void mouseReleaseEvent(QMouseEvent *event); 37 | 38 | QSize sizeHint() const; 39 | 40 | qreal hue(); 41 | void setHue(qreal value); 42 | 43 | signals: 44 | void colorChanged(QColor color); 45 | void colorPicked(QColor color); 46 | 47 | private: 48 | qreal m_hue; 49 | bool m_lpressed; 50 | QColor getColor(QMouseEvent *event); 51 | }; 52 | 53 | #endif // COLORPICKER_H 54 | -------------------------------------------------------------------------------- /vectorgraphic.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** Copyright (C) 2016 Olaf Japp 3 | ** 4 | ** This file is part of AnimationMaker. 5 | ** 6 | ** AnimationMaker is free software: you can redistribute it and/or modify 7 | ** it under the terms of the GNU General Public License as published by 8 | ** the Free Software Foundation, either version 3 of the License, or 9 | ** (at your option) any later version. 10 | ** 11 | ** AnimationMaker is distributed in the hope that it will be useful, 12 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | ** GNU General Public License for more details. 15 | ** 16 | ** You should have received a copy of the GNU General Public License 17 | ** along with AnimationMaker. If not, see . 18 | ** 19 | ****************************************************************************/ 20 | 21 | #ifndef VECTORGRAPHIC_H 22 | #define VECTORGRAPHIC_H 23 | 24 | #include 25 | #include 26 | #include "resizeableitem.h" 27 | 28 | class Vectorgraphic : public ResizeableItem 29 | { 30 | public: 31 | Vectorgraphic(QString filename, AnimationScene *scene); 32 | Vectorgraphic(QByteArray arr, AnimationScene *scene); 33 | 34 | void paint( QPainter *paint, const QStyleOptionGraphicsItem *, QWidget *); 35 | void scaleObjects(); 36 | void setScale(qreal x, qreal y); 37 | QByteArray getData(); 38 | 39 | enum { Type = UserType + 5 }; 40 | int type() const Q_DECL_OVERRIDE; 41 | 42 | private: 43 | QGraphicsSvgItem *m_svg; 44 | QSvgRenderer *m_renderer; 45 | QByteArray m_data; 46 | }; 47 | 48 | #endif // VECTORGRAPHIC_H 49 | -------------------------------------------------------------------------------- /playhead.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** Copyright (C) 2016 Olaf Japp 3 | ** 4 | ** This file is part of AnimationMaker. 5 | ** 6 | ** AnimationMaker is free software: you can redistribute it and/or modify 7 | ** it under the terms of the GNU General Public License as published by 8 | ** the Free Software Foundation, either version 3 of the License, or 9 | ** (at your option) any later version. 10 | ** 11 | ** AnimationMaker is distributed in the hope that it will be useful, 12 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | ** GNU General Public License for more details. 15 | ** 16 | ** You should have received a copy of the GNU General Public License 17 | ** along with AnimationMaker. If not, see . 18 | ** 19 | ****************************************************************************/ 20 | 21 | #ifndef PLAYHEAD_H 22 | #define PLAYHEAD_H 23 | 24 | #include 25 | 26 | class PlayHead : public QWidget 27 | { 28 | Q_OBJECT 29 | public: 30 | PlayHead(); 31 | 32 | void paintEvent(QPaintEvent *ev); 33 | void mousePressEvent(QMouseEvent *ev); 34 | void mouseMoveEvent(QMouseEvent *ev); 35 | void mouseReleaseEvent(QMouseEvent *ev); 36 | 37 | inline void setValue(int value) {m_value = value; update(); emit valueChanged(value);} 38 | inline int value() {return m_value;} 39 | 40 | public slots: 41 | void scrollValueChanged(int pos); 42 | 43 | signals: 44 | void valueChanged(int val); 45 | 46 | private: 47 | QImage m_image; 48 | bool m_pressed; 49 | int m_value; 50 | int m_horizontalScrollPos; 51 | }; 52 | 53 | #endif // PLAYHEAD_H 54 | -------------------------------------------------------------------------------- /keyframe.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** Copyright (C) 2016 Olaf Japp 3 | ** 4 | ** This file is part of AnimationMaker. 5 | ** 6 | ** AnimationMaker is free software: you can redistribute it and/or modify 7 | ** it under the terms of the GNU General Public License as published by 8 | ** the Free Software Foundation, either version 3 of the License, or 9 | ** (at your option) any later version. 10 | ** 11 | ** AnimationMaker is distributed in the hope that it will be useful, 12 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | ** GNU General Public License for more details. 15 | ** 16 | ** You should have received a copy of the GNU General Public License 17 | ** along with AnimationMaker. If not, see . 18 | ** 19 | ****************************************************************************/ 20 | 21 | #ifndef KEYFRAME_H 22 | #define KEYFRAME_H 23 | 24 | #include 25 | 26 | class KeyFrame 27 | { 28 | public: 29 | KeyFrame(); 30 | 31 | inline QVariant value() {return m_value;} 32 | inline void setValue(QVariant value) {m_value = value;} 33 | inline int time() {return m_time;} 34 | inline void setTime(int value) {m_time = value;} 35 | inline int easing() {return m_easing;} 36 | inline void setEasing(int value) {m_easing = value;} 37 | inline KeyFrame *next() {return m_next;} 38 | inline void setNext(KeyFrame *value) {m_next = value;} 39 | inline KeyFrame *prev() {return m_prev;} 40 | inline void setPrev(KeyFrame *value) {m_prev = value;} 41 | 42 | private: 43 | QVariant m_value; 44 | int m_time; 45 | int m_easing; 46 | KeyFrame *m_next; 47 | KeyFrame *m_prev; 48 | }; 49 | 50 | #endif // KEYFRAME_H 51 | -------------------------------------------------------------------------------- /text.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** Copyright (C) 2016 Olaf Japp 3 | ** 4 | ** This file is part of AnimationMaker. 5 | ** 6 | ** AnimationMaker is free software: you can redistribute it and/or modify 7 | ** it under the terms of the GNU General Public License as published by 8 | ** the Free Software Foundation, either version 3 of the License, or 9 | ** (at your option) any later version. 10 | ** 11 | ** AnimationMaker is distributed in the hope that it will be useful, 12 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | ** GNU General Public License for more details. 15 | ** 16 | ** You should have received a copy of the GNU General Public License 17 | ** along with AnimationMaker. If not, see . 18 | ** 19 | ****************************************************************************/ 20 | 21 | #ifndef TEXT_H 22 | #define TEXT_H 23 | 24 | #include 25 | #include 26 | #include 27 | #include "itemhandle.h" 28 | #include "resizeableitem.h" 29 | 30 | class Text : public ResizeableItem 31 | { 32 | Q_OBJECT 33 | public: 34 | Text(QString text, AnimationScene *scene); 35 | 36 | void paint( QPainter *paint, const QStyleOptionGraphicsItem *, QWidget *); 37 | void scaleObjects(); 38 | void setScale(qreal x, qreal y); 39 | QString text(); 40 | void setText(QString text); 41 | 42 | QColor textcolor(); 43 | void setTextcolor(QColor textcolor); 44 | 45 | enum { Type = UserType + 3 }; 46 | int type() const Q_DECL_OVERRIDE; 47 | 48 | signals: 49 | void textcolorChanged(QColor); 50 | 51 | private: 52 | QFont m_font; 53 | QString m_text; 54 | QGraphicsSimpleTextItem *m_textitem; 55 | QColor m_textcolor; 56 | }; 57 | 58 | #endif // TEXT_H 59 | -------------------------------------------------------------------------------- /scenepropertyeditor.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** Copyright (C) 2016 Olaf Japp 3 | ** 4 | ** This file is part of AnimationMaker. 5 | ** 6 | ** AnimationMaker is free software: you can redistribute it and/or modify 7 | ** it under the terms of the GNU General Public License as published by 8 | ** the Free Software Foundation, either version 3 of the License, or 9 | ** (at your option) any later version. 10 | ** 11 | ** AnimationMaker is distributed in the hope that it will be useful, 12 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | ** GNU General Public License for more details. 15 | ** 16 | ** You should have received a copy of the GNU General Public License 17 | ** along with AnimationMaker. If not, see . 18 | ** 19 | ****************************************************************************/ 20 | 21 | #ifndef SCENEPROPERTYEDITOR_H 22 | #define SCENEPROPERTYEDITOR_H 23 | 24 | #include 25 | #include 26 | #include 27 | 28 | #include "animationscene.h" 29 | #include "colorpicker.h" 30 | #include "colorrect.h" 31 | #include "coloreditor.h" 32 | 33 | class ScenePropertyEditor : public QWidget 34 | { 35 | Q_OBJECT 36 | public: 37 | ScenePropertyEditor(); 38 | 39 | void setScene(AnimationScene *scene); 40 | private: 41 | bool m_initializing; 42 | ColorEditor *m_colorEditor; 43 | QSpinBox *m_width; 44 | QSpinBox *m_height; 45 | QSpinBox *m_fps; 46 | AnimationScene *m_scene; 47 | 48 | void setColorParts(QColor value); 49 | 50 | private slots: 51 | void widthChanged(int value); 52 | void heightChanged(int value); 53 | void fpsChanged(int value); 54 | void backgroundColorChanged(QColor color); 55 | void colorChanged(QColor color); 56 | }; 57 | 58 | #endif // SCENEPROPERTYEDITOR_H 59 | -------------------------------------------------------------------------------- /bitmap.cpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** Copyright (C) 2016 Olaf Japp 3 | ** 4 | ** This file is part of AnimationMaker. 5 | ** 6 | ** AnimationMaker is free software: you can redistribute it and/or modify 7 | ** it under the terms of the GNU General Public License as published by 8 | ** the Free Software Foundation, either version 3 of the License, or 9 | ** (at your option) any later version. 10 | ** 11 | ** AnimationMaker is distributed in the hope that it will be useful, 12 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | ** GNU General Public License for more details. 15 | ** 16 | ** You should have received a copy of the GNU General Public License 17 | ** along with AnimationMaker. If not, see . 18 | ** 19 | ****************************************************************************/ 20 | 21 | #include "bitmap.h" 22 | 23 | #include 24 | #include 25 | #include 26 | 27 | Bitmap::Bitmap(QString filename, AnimationScene *scene) 28 | : ResizeableItem(scene) 29 | { 30 | m_image.load(filename); 31 | setRect(0, 0, m_image.width(), m_image.height()); 32 | } 33 | 34 | Bitmap::Bitmap(QImage image, qreal width, qreal height, AnimationScene *scene) 35 | :ResizeableItem(scene) 36 | { 37 | m_image = image; 38 | setRect(0, 0, width, height); 39 | } 40 | 41 | int Bitmap::type() const 42 | { 43 | return Bitmap::Type; 44 | } 45 | 46 | void Bitmap::paint( QPainter *paint, const QStyleOptionGraphicsItem *option, QWidget *widget) 47 | { 48 | Q_UNUSED(widget); 49 | 50 | paint->drawImage(0, 0, m_image.scaled(rect().width(), rect().height())); 51 | 52 | if (option->state & QStyle::State_Selected) 53 | drawHighlightSelected(paint, option); 54 | } 55 | 56 | QImage Bitmap::getImage() 57 | { 58 | return m_image; 59 | } 60 | -------------------------------------------------------------------------------- /main.cpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** Copyright (C) 2016 Olaf Japp 3 | ** 4 | ** This file is part of AnimationMaker. 5 | ** 6 | ** AnimationMaker is free software: you can redistribute it and/or modify 7 | ** it under the terms of the GNU General Public License as published by 8 | ** the Free Software Foundation, either version 3 of the License, or 9 | ** (at your option) any later version. 10 | ** 11 | ** AnimationMaker is distributed in the hope that it will be useful, 12 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | ** GNU General Public License for more details. 15 | ** 16 | ** You should have received a copy of the GNU General Public License 17 | ** along with AnimationMaker. If not, see . 18 | ** 19 | ****************************************************************************/ 20 | 21 | #include "mainwindow.h" 22 | #include 23 | #include 24 | 25 | int main(int argc, char *argv[]) 26 | { 27 | QApplication a(argc, argv); 28 | 29 | QCoreApplication::setOrganizationName("CrowdWare"); 30 | QCoreApplication::setApplicationName("AnimationMaker"); 31 | QCoreApplication::setApplicationVersion("1.0"); 32 | 33 | a.setStyle(QStyleFactory::create("Fusion")); 34 | QPalette p = a.palette(); 35 | 36 | p.setColor(QPalette::Window, QColor(53,53,53)); 37 | p.setColor(QPalette::WindowText, Qt::white); 38 | p.setColor(QPalette::Base, QColor(64, 66, 68)); 39 | p.setColor(QPalette::AlternateBase, QColor(53,53,53)); 40 | p.setColor(QPalette::ToolTipBase, Qt::white); 41 | p.setColor(QPalette::ToolTipText, Qt::black); 42 | p.setColor(QPalette::Text, Qt::white); 43 | p.setColor(QPalette::Button, QColor(53,53,53)); 44 | p.setColor(QPalette::ButtonText, Qt::white); 45 | p.setColor(QPalette::BrightText, Qt::red); 46 | 47 | p.setColor(QPalette::Highlight, QColor(255,127,42)); 48 | p.setColor(QPalette::HighlightedText, Qt::black); 49 | 50 | p.setColor(QPalette::Disabled, QPalette::Text, Qt::darkGray); 51 | p.setColor(QPalette::Disabled, QPalette::ButtonText, Qt::darkGray); 52 | a.setPalette(p); 53 | 54 | 55 | MainWindow w; 56 | w.show(); 57 | 58 | return a.exec(); 59 | } 60 | -------------------------------------------------------------------------------- /transitionpanel.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** Copyright (C) 2016 Olaf Japp 3 | ** 4 | ** This file is part of AnimationMaker. 5 | ** 6 | ** AnimationMaker is free software: you can redistribute it and/or modify 7 | ** it under the terms of the GNU General Public License as published by 8 | ** the Free Software Foundation, either version 3 of the License, or 9 | ** (at your option) any later version. 10 | ** 11 | ** AnimationMaker is distributed in the hope that it will be useful, 12 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | ** GNU General Public License for more details. 15 | ** 16 | ** You should have received a copy of the GNU General Public License 17 | ** along with AnimationMaker. If not, see . 18 | ** 19 | ****************************************************************************/ 20 | 21 | #ifndef TRANSITIONPANEL_H 22 | #define TRANSITIONPANEL_H 23 | 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include "transitionline.h" 29 | 30 | class Timeline; 31 | class TransitionPanel : public QWidget 32 | { 33 | Q_OBJECT 34 | public: 35 | TransitionPanel(); 36 | 37 | void paintEvent(QPaintEvent*); 38 | void resizeEvent(QResizeEvent *); 39 | void setTreeWidget(QTreeWidget *tv); 40 | void reset(); 41 | void setPlayheadPosition(int value); 42 | void removeItem(ResizeableItem *item); 43 | inline void registerTimeline(Timeline *timeline) {m_timeline = timeline;} 44 | void transitionAdded(ResizeableItem *item, QString propertyName); 45 | void transitionDeleted(ResizeableItem *item, QString propertyName); 46 | 47 | public slots: 48 | void treeExpanded(QModelIndex); 49 | void treeCollapsed(QModelIndex); 50 | void treeScrollValueChanged(int); 51 | void keyframeAdded(ResizeableItem *item, QString propertyName); 52 | void keyframeDeleted(ResizeableItem *item, QString propertyName); 53 | void scrollValueChanged(int pos); 54 | 55 | private: 56 | int m_verticalScrollPos; 57 | int m_horizontalScrollPos; 58 | QTreeWidget *m_tree; 59 | QVBoxLayout *m_layout; 60 | Timeline *m_timeline; 61 | int m_playheadPosition; 62 | 63 | void enableDisableLines(); 64 | TransitionLine *getTransitionLine(ResizeableItem *item, QString propertyName); 65 | }; 66 | 67 | #endif // TRANSITIONPANEL_H 68 | -------------------------------------------------------------------------------- /itemhandle.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** Copyright (C) 2016 Olaf Japp 3 | ** 4 | ** This file is part of AnimationMaker. 5 | ** 6 | ** AnimationMaker is free software: you can redistribute it and/or modify 7 | ** it under the terms of the GNU General Public License as published by 8 | ** the Free Software Foundation, either version 3 of the License, or 9 | ** (at your option) any later version. 10 | ** 11 | ** AnimationMaker is distributed in the hope that it will be useful, 12 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | ** GNU General Public License for more details. 15 | ** 16 | ** You should have received a copy of the GNU General Public License 17 | ** along with AnimationMaker. If not, see . 18 | ** 19 | ****************************************************************************/ 20 | 21 | #ifndef ITEMHANDLE_H 22 | #define ITEMHANDLE_H 23 | 24 | 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | 36 | class ItemHandle : public QGraphicsItem 37 | { 38 | public: 39 | explicit ItemHandle(int corner = 0); 40 | 41 | int getCorner(); 42 | void setMouseState(int); 43 | int getMouseState(); 44 | 45 | qreal mouseDownX; 46 | qreal mouseDownY; 47 | 48 | enum {kMouseReleased=0, kMouseDown, kMouseMoving}; 49 | 50 | private: 51 | virtual QRectF boundingRect() const; 52 | virtual void paint (QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); 53 | virtual void hoverEnterEvent ( QGraphicsSceneHoverEvent * event ); 54 | virtual void hoverLeaveEvent ( QGraphicsSceneHoverEvent * event ); 55 | 56 | virtual void mouseMoveEvent ( QGraphicsSceneMouseEvent * event ); 57 | virtual void mouseMoveEvent(QGraphicsSceneDragDropEvent *event); 58 | virtual void mousePressEvent (QGraphicsSceneMouseEvent * event ); 59 | virtual void mousePressEvent(QGraphicsSceneDragDropEvent *event); 60 | virtual void mouseReleaseEvent (QGraphicsSceneMouseEvent * event ); 61 | 62 | QColor m_color; 63 | QPen m_pen; 64 | qreal m_width; 65 | qreal m_height; 66 | int m_corner; 67 | int m_mouseButtonState; 68 | }; 69 | 70 | #endif // ITEMHANDLE_H 71 | -------------------------------------------------------------------------------- /coloreditor.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** Copyright (C) 2016 Olaf Japp 3 | ** 4 | ** This file is part of AnimationMaker. 5 | ** 6 | ** AnimationMaker is free software: you can redistribute it and/or modify 7 | ** it under the terms of the GNU General Public License as published by 8 | ** the Free Software Foundation, either version 3 of the License, or 9 | ** (at your option) any later version. 10 | ** 11 | ** AnimationMaker is distributed in the hope that it will be useful, 12 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | ** GNU General Public License for more details. 15 | ** 16 | ** You should have received a copy of the GNU General Public License 17 | ** along with AnimationMaker. If not, see . 18 | ** 19 | ****************************************************************************/ 20 | 21 | #ifndef COLOREDITOR_H 22 | #define COLOREDITOR_H 23 | 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include "colorpicker.h" 29 | #include "colorrect.h" 30 | 31 | class ColorEditor : public QWidget 32 | { 33 | Q_OBJECT 34 | public: 35 | ColorEditor(QString label); 36 | 37 | void setExpanded(bool value); 38 | bool isExpanded(); 39 | void setColor(QColor color); 40 | 41 | signals: 42 | void colorChanged(QColor value); 43 | 44 | private: 45 | ColorPicker *m_colorPicker; 46 | QSlider *m_hueSlider; 47 | QSpinBox *m_hue; 48 | QSpinBox *m_saturation; 49 | QSpinBox *m_lightness; 50 | QSpinBox *m_red; 51 | QSpinBox *m_green; 52 | QSpinBox *m_blue; 53 | QLineEdit *m_color; 54 | ColorRect *m_rect; 55 | QLabel *m_labelHue; 56 | QLabel *m_labelSaturation; 57 | QLabel *m_labelLightness; 58 | QLabel *m_labelRed; 59 | QLabel *m_labelGreen; 60 | QLabel *m_labelBlue; 61 | 62 | void setColorParts(QColor value); 63 | void connectControls(); 64 | void disconnectControls(); 65 | 66 | private slots: 67 | void colorTextChanged(QString value); 68 | void colorPickerChanged(QColor value); 69 | void colorPicked(QColor value); 70 | void rectClicked(); 71 | void hueValueChanged(int value); 72 | void saturationValueChanged(int value); 73 | void lightnessValueChanged(int value); 74 | void redValueChanged(int value); 75 | void greenValueChanged(int value); 76 | void blueValueChanged(int value); 77 | void hueChanged(int); 78 | void huePicked(); 79 | }; 80 | 81 | #endif // COLOREDITOR_H 82 | -------------------------------------------------------------------------------- /expander.cpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** Copyright (C) 2016 Olaf Japp 3 | ** 4 | ** This file is part of AnimationMaker. 5 | ** 6 | ** AnimationMaker is free software: you can redistribute it and/or modify 7 | ** it under the terms of the GNU General Public License as published by 8 | ** the Free Software Foundation, either version 3 of the License, or 9 | ** (at your option) any later version. 10 | ** 11 | ** AnimationMaker is distributed in the hope that it will be useful, 12 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | ** GNU General Public License for more details. 15 | ** 16 | ** You should have received a copy of the GNU General Public License 17 | ** along with AnimationMaker. If not, see . 18 | ** 19 | ****************************************************************************/ 20 | 21 | #include "expander.h" 22 | 23 | #include 24 | #include 25 | 26 | 27 | Expander::Expander(QString header) 28 | { 29 | m_isExpanded = true; 30 | QPalette pal = palette(); 31 | pal.setColor(QPalette::Background, QColor(64, 66, 68)); 32 | this->setAutoFillBackground(true); 33 | this->setPalette(pal); 34 | QVBoxLayout *vbox = new QVBoxLayout(); 35 | QHBoxLayout *hbox = new QHBoxLayout(); 36 | m_button = new QToolButton(); 37 | m_button->setStyleSheet("QToolButton { border: none; }"); 38 | m_button->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); 39 | m_button->setArrowType(Qt::ArrowType::DownArrow); 40 | m_button->setText(header); 41 | m_button->setCheckable(true); 42 | m_button->setChecked(false); 43 | 44 | QFont headerFont = m_button->font(); 45 | headerFont.setBold(true); 46 | m_button->setFont(headerFont); 47 | 48 | hbox->addWidget(m_button); 49 | hbox->addStretch(); 50 | vbox->addLayout(hbox); 51 | m_content = new QWidget(); 52 | m_content->setStyleSheet("background-color: #4c4e50"); 53 | vbox->addWidget(m_content); 54 | this->setLayout(vbox); 55 | 56 | connect(m_button, SIGNAL(clicked(bool)), this, SLOT(buttonClicked(bool))); 57 | } 58 | 59 | void Expander::buttonClicked(bool) 60 | { 61 | if(m_isExpanded) 62 | m_isExpanded = false; 63 | else 64 | m_isExpanded = true; 65 | m_content->setHidden(!m_isExpanded); 66 | m_button->setArrowType(m_isExpanded ? Qt::ArrowType::DownArrow : Qt::ArrowType::RightArrow); 67 | } 68 | 69 | void Expander::addLayout(QLayout *l) 70 | { 71 | m_content->setLayout(l); 72 | } 73 | -------------------------------------------------------------------------------- /transitionline.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** Copyright (C) 2016 Olaf Japp 3 | ** 4 | ** This file is part of AnimationMaker. 5 | ** 6 | ** AnimationMaker is free software: you can redistribute it and/or modify 7 | ** it under the terms of the GNU General Public License as published by 8 | ** the Free Software Foundation, either version 3 of the License, or 9 | ** (at your option) any later version. 10 | ** 11 | ** AnimationMaker is distributed in the hope that it will be useful, 12 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | ** GNU General Public License for more details. 15 | ** 16 | ** You should have received a copy of the GNU General Public License 17 | ** along with AnimationMaker. If not, see . 18 | ** 19 | ****************************************************************************/ 20 | 21 | #ifndef TRANSITION_H 22 | #define TRANSITION_H 23 | 24 | #include 25 | #include "resizeableitem.h" 26 | 27 | class TransitionLine : public QWidget 28 | { 29 | Q_OBJECT 30 | public: 31 | TransitionLine(ResizeableItem *item, QString propertyName); 32 | 33 | void paintEvent(QPaintEvent *ev); 34 | void mousePressEvent(QMouseEvent *ev); 35 | void mouseMoveEvent(QMouseEvent *ev); 36 | void mouseReleaseEvent(QMouseEvent *ev); 37 | 38 | inline QString propertyName() {return m_propertyName;} 39 | inline ResizeableItem *item() {return m_item;} 40 | inline void setPlayheadPosition(int value) {m_playheadPosition = value; update();} 41 | inline void setScrollValue(int value) {m_horizontalScrollValue = value; update();} 42 | 43 | private slots: 44 | void onCustomContextMenu(const QPoint &point); 45 | void addTransition(); 46 | void deleteKeyframe(); 47 | void deleteTransition(); 48 | 49 | signals: 50 | void deleteKeyframe(ResizeableItem *item, QString propertyName, KeyFrame *frame); 51 | void deleteTransition(ResizeableItem *item, QString propertyName, KeyFrame *frame); 52 | void addTransition(ResizeableItem *item, QString propertyName, KeyFrame *frame); 53 | 54 | private: 55 | QImage m_imageRaute; 56 | QImage m_imageRauteHohl; 57 | QImage m_imageLeft; 58 | QImage m_imageRight; 59 | ResizeableItem *m_item; 60 | QString m_propertyName; 61 | KeyFrame *m_frame; 62 | int m_oldx; 63 | int m_playheadPosition; 64 | QMenu *m_contextMenu; 65 | QAction *m_transitionAct; 66 | QAction *m_delKeyframeAct; 67 | QAction *m_delTransitionAct; 68 | bool m_pressed; 69 | int m_horizontalScrollValue; 70 | }; 71 | 72 | #endif // TRANSITION_H 73 | -------------------------------------------------------------------------------- /playhead.cpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** Copyright (C) 2016 Olaf Japp 3 | ** 4 | ** This file is part of AnimationMaker. 5 | ** 6 | ** AnimationMaker is free software: you can redistribute it and/or modify 7 | ** it under the terms of the GNU General Public License as published by 8 | ** the Free Software Foundation, either version 3 of the License, or 9 | ** (at your option) any later version. 10 | ** 11 | ** AnimationMaker is distributed in the hope that it will be useful, 12 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | ** GNU General Public License for more details. 15 | ** 16 | ** You should have received a copy of the GNU General Public License 17 | ** along with AnimationMaker. If not, see . 18 | ** 19 | ****************************************************************************/ 20 | 21 | #include "playhead.h" 22 | #include 23 | #include 24 | #include 25 | 26 | PlayHead::PlayHead() 27 | { 28 | m_image = QImage(":/images/playhead.png"); 29 | m_pressed = false; 30 | m_value = 0; 31 | m_horizontalScrollPos = 0; 32 | } 33 | 34 | void PlayHead::paintEvent(QPaintEvent *) 35 | { 36 | QColor gray = QColor(64, 66, 68); 37 | int width = size().width(); 38 | int height = size().height(); 39 | int offset = m_horizontalScrollPos * 20; 40 | 41 | QPainter painter(this); 42 | 43 | painter.setPen(Qt::white); 44 | for(int i = 0 - offset; i < width; i+=20) 45 | { 46 | painter.drawLine(i, 0, i, 3); 47 | } 48 | for(int i = 0 - offset; i < width; i+=100) 49 | { 50 | painter.drawLine(i, 0, i, 8); 51 | } 52 | painter.setPen(QColor(41, 41, 41)); 53 | painter.fillRect(0, 10, width, height, gray); 54 | painter.drawRect(0, 10, width - 1, height - 1); 55 | painter.drawImage(m_value / 5 - 4 - offset, 4, m_image); 56 | } 57 | 58 | void PlayHead::scrollValueChanged(int pos) 59 | { 60 | m_horizontalScrollPos = pos; 61 | update(); 62 | } 63 | 64 | void PlayHead::mousePressEvent(QMouseEvent *event) 65 | { 66 | if(event->button() == Qt::LeftButton && event->x() + m_horizontalScrollPos * 20 > m_value / 5 - 4 && event->x() + m_horizontalScrollPos * 20 <= m_value / 5 + 5) 67 | m_pressed = true; 68 | } 69 | 70 | void PlayHead::mouseMoveEvent(QMouseEvent *event) 71 | { 72 | if(m_pressed) 73 | { 74 | int x = event->x(); 75 | if(x < 0) 76 | x = 0; 77 | if(x >= width()) 78 | x = width() - 1; 79 | x += m_horizontalScrollPos * 20; 80 | m_value = qRound((qreal)x * 5 / 100) * 100; 81 | if(m_value / 5 > width()) 82 | m_value -= 100; 83 | update(); 84 | emit valueChanged(m_value); 85 | } 86 | } 87 | 88 | void PlayHead::mouseReleaseEvent(QMouseEvent *) 89 | { 90 | m_pressed = false; 91 | } 92 | -------------------------------------------------------------------------------- /vectorgraphic.cpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** Copyright (C) 2016 Olaf Japp 3 | ** 4 | ** This file is part of AnimationMaker. 5 | ** 6 | ** AnimationMaker is free software: you can redistribute it and/or modify 7 | ** it under the terms of the GNU General Public License as published by 8 | ** the Free Software Foundation, either version 3 of the License, or 9 | ** (at your option) any later version. 10 | ** 11 | ** AnimationMaker is distributed in the hope that it will be useful, 12 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | ** GNU General Public License for more details. 15 | ** 16 | ** You should have received a copy of the GNU General Public License 17 | ** along with AnimationMaker. If not, see . 18 | ** 19 | ****************************************************************************/ 20 | 21 | #include "vectorgraphic.h" 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | Vectorgraphic::Vectorgraphic(QString filename, AnimationScene *scene) 29 | : ResizeableItem(scene) 30 | { 31 | QFile file(filename); 32 | file.open(QIODevice::ReadOnly); 33 | m_data = file.readAll(); 34 | m_renderer = new QSvgRenderer(); 35 | m_renderer->load(m_data); 36 | m_svg = new QGraphicsSvgItem(this); 37 | m_svg->setSharedRenderer(m_renderer); 38 | 39 | setRect(0, 0, m_svg->boundingRect().width(), m_svg->boundingRect().height()); 40 | } 41 | 42 | Vectorgraphic::Vectorgraphic(QByteArray arr, AnimationScene *scene) 43 | : ResizeableItem(scene) 44 | { 45 | m_data = arr; 46 | m_renderer = new QSvgRenderer(); 47 | m_renderer->load(m_data); 48 | m_svg = new QGraphicsSvgItem(this); 49 | m_svg->setSharedRenderer(m_renderer); 50 | 51 | setRect(0, 0, m_svg->boundingRect().width(), m_svg->boundingRect().height()); 52 | } 53 | 54 | 55 | int Vectorgraphic::type() const 56 | { 57 | return Vectorgraphic::Type; 58 | } 59 | 60 | void Vectorgraphic::paint( QPainter *paint, const QStyleOptionGraphicsItem *option, QWidget *widget) 61 | { 62 | Q_UNUSED(widget); 63 | 64 | if (option->state & QStyle::State_Selected) 65 | drawHighlightSelected(paint, option); 66 | } 67 | 68 | void Vectorgraphic::scaleObjects() 69 | { 70 | m_xscale = rect().width() / m_svg->boundingRect().width(); 71 | m_yscale = rect().height() / m_svg->boundingRect().height(); 72 | 73 | QTransform trans; 74 | trans.scale(m_xscale, m_yscale); 75 | m_svg->setTransform(trans); 76 | } 77 | 78 | void Vectorgraphic::setScale(qreal x, qreal y) 79 | { 80 | m_xscale = x; 81 | m_yscale = y; 82 | QTransform trans; 83 | trans.scale(m_xscale, m_yscale); 84 | m_svg->setTransform(trans); 85 | 86 | setRect(0, 0, m_svg->boundingRect().width() * x, m_svg->boundingRect().height() * y); 87 | } 88 | 89 | 90 | QByteArray Vectorgraphic::getData() 91 | { 92 | return m_data; 93 | } 94 | -------------------------------------------------------------------------------- /text.cpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** Copyright (C) 2016 Olaf Japp 3 | ** 4 | ** This file is part of AnimationMaker. 5 | ** 6 | ** AnimationMaker is free software: you can redistribute it and/or modify 7 | ** it under the terms of the GNU General Public License as published by 8 | ** the Free Software Foundation, either version 3 of the License, or 9 | ** (at your option) any later version. 10 | ** 11 | ** AnimationMaker is distributed in the hope that it will be useful, 12 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | ** GNU General Public License for more details. 15 | ** 16 | ** You should have received a copy of the GNU General Public License 17 | ** along with AnimationMaker. If not, see . 18 | ** 19 | ****************************************************************************/ 20 | 21 | #include "text.h" 22 | 23 | #include 24 | #include 25 | #include 26 | 27 | Text::Text(QString text, AnimationScene *scene) 28 | : ResizeableItem(scene) 29 | { 30 | m_font = QFont("Arial", 13); 31 | m_text = text; 32 | m_textcolor = QColor(Qt::black); 33 | QFontMetrics m(m_font); 34 | setRect(0, 0, m.width(m_text), m.height()); 35 | m_textitem = new QGraphicsSimpleTextItem(m_text, this); 36 | m_textitem->setFont(m_font); 37 | m_textitem->setBrush(QBrush(m_textcolor)); 38 | } 39 | 40 | int Text::type() const 41 | { 42 | return Text::Type; 43 | } 44 | 45 | void Text::paint( QPainter *paint, const QStyleOptionGraphicsItem *option, QWidget *widget) 46 | { 47 | Q_UNUSED(widget); 48 | 49 | if (option->state & QStyle::State_Selected) 50 | drawHighlightSelected(paint, option); 51 | } 52 | 53 | QString Text::text() 54 | { 55 | return m_text; 56 | } 57 | 58 | void Text::setText(QString text) 59 | { 60 | m_text = text; 61 | m_textitem->setText(text); 62 | QFontMetrics m(m_font); 63 | setRect(0, 0, m.width(m_text) * m_xscale, m.height() * m_yscale); 64 | setHandlePositions(); 65 | } 66 | 67 | QColor Text::textcolor() 68 | { 69 | return m_textcolor; 70 | } 71 | 72 | void Text::setTextcolor(QColor color) 73 | { 74 | m_textcolor = color; 75 | m_textitem->setBrush(QBrush(m_textcolor)); 76 | emit textcolorChanged(color); 77 | } 78 | 79 | void Text::setScale(qreal x, qreal y) 80 | { 81 | m_xscale = x; 82 | m_yscale = y; 83 | QTransform trans; 84 | trans.scale(m_xscale, m_yscale); 85 | m_textitem->setTransform(trans); 86 | 87 | QFontMetrics m(m_font); 88 | setRect(0, 0, m.width(m_text) * m_xscale, m.height() * m_yscale); 89 | } 90 | 91 | void Text::scaleObjects() 92 | { 93 | QFontMetrics m(m_font); 94 | m_xscale = rect().width() / m.width(m_text); 95 | m_yscale = rect().height() / m.height(); 96 | 97 | QTransform trans; 98 | trans.scale(m_xscale, m_yscale); 99 | m_textitem->setTransform(trans); 100 | } 101 | -------------------------------------------------------------------------------- /colorpicker.cpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** Copyright (C) 2016 Olaf Japp 3 | ** 4 | ** This file is part of AnimationMaker. 5 | ** 6 | ** AnimationMaker is free software: you can redistribute it and/or modify 7 | ** it under the terms of the GNU General Public License as published by 8 | ** the Free Software Foundation, either version 3 of the License, or 9 | ** (at your option) any later version. 10 | ** 11 | ** AnimationMaker is distributed in the hope that it will be useful, 12 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | ** GNU General Public License for more details. 15 | ** 16 | ** You should have received a copy of the GNU General Public License 17 | ** along with AnimationMaker. If not, see . 18 | ** 19 | ****************************************************************************/ 20 | 21 | #include "colorpicker.h" 22 | 23 | #include 24 | #include 25 | 26 | ColorPicker::ColorPicker() 27 | { 28 | m_hue = 0.0; 29 | m_lpressed = false; 30 | setMinimumSize(100, 100); 31 | } 32 | 33 | void ColorPicker::setHue(qreal value) 34 | { 35 | m_hue = value; 36 | update(); 37 | } 38 | 39 | qreal ColorPicker::hue() 40 | { 41 | return m_hue; 42 | } 43 | 44 | QSize ColorPicker::sizeHint() const 45 | { 46 | return QSize(100, 100); 47 | } 48 | 49 | void ColorPicker::paintEvent(QPaintEvent *) 50 | { 51 | QPainter painter(this); 52 | qreal s, l, a; 53 | 54 | QImage image(100, 100, QImage::Format_ARGB32); 55 | for(int x=0; x < 100; x++) 56 | { 57 | for(int y=0;y < 100; y++) 58 | { 59 | s = x / 100.0; 60 | l = (100 - y) / 100.0; 61 | a = 1.0; 62 | QColor color = QColor::fromHslF(m_hue, s, l, a); 63 | image.setPixel(x, y, color.rgba()); 64 | } 65 | } 66 | painter.drawImage(0, 0, image); 67 | } 68 | 69 | void ColorPicker::mousePressEvent(QMouseEvent * event) 70 | { 71 | if(event->button() == Qt::LeftButton) 72 | { 73 | m_lpressed = true; 74 | emit colorChanged(getColor(event)); 75 | } 76 | } 77 | 78 | void ColorPicker::mouseReleaseEvent(QMouseEvent * event) 79 | { 80 | if(m_lpressed) 81 | { 82 | m_lpressed = false; 83 | emit colorPicked(getColor(event)); 84 | } 85 | } 86 | 87 | QColor ColorPicker::getColor(QMouseEvent *event) 88 | { 89 | qreal s, l, a; 90 | int x, y; 91 | 92 | x = event->pos().x(); 93 | y = event->pos().y(); 94 | if(x < 0) 95 | x = 0; 96 | if(x > 100) 97 | x = 100; 98 | if(y < 0) 99 | y = 0; 100 | if(y > 100) 101 | y = 100; 102 | s = x / 100.0; 103 | l = (100 - y) / 100.0; 104 | a = 1.0; 105 | return QColor::fromHslF(m_hue, s, l, a); 106 | } 107 | 108 | void ColorPicker::mouseMoveEvent(QMouseEvent *event) 109 | { 110 | if ((event->buttons() & Qt::LeftButton) && m_lpressed) 111 | { 112 | emit colorChanged(getColor(event)); 113 | } 114 | } 115 | -------------------------------------------------------------------------------- /AnimationMaker.pro: -------------------------------------------------------------------------------- 1 | #------------------------------------------------- 2 | # 3 | # Project created by QtCreator 2016-12-19T11:03:34 4 | # 5 | #------------------------------------------------- 6 | # Copyright (C) 2016 Olaf Japp 7 | # https://facebook.com/artanidos 8 | # 9 | # This file is part of AnimationMaker. 10 | # 11 | # AnimationMaker is free software: you can redistribute it and/or modify 12 | # it under the terms of the GNU General Public License as published by 13 | # the Free Software Foundation, either version 3 of the License, or 14 | # (at your option) any later version. 15 | # 16 | # Foobar is distributed in the hope that it will be useful, 17 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | # GNU General Public License for more details. 20 | # 21 | # You should have received a copy of the GNU General Public License 22 | # along with Foobar. If not, see . 23 | 24 | QT += core gui svg 25 | QT += testlib 26 | 27 | greaterThan(QT_MAJOR_VERSION, 4): QT += widgets 28 | 29 | TARGET = AnimationMaker 30 | TEMPLATE = app 31 | 32 | SOURCES += main.cpp\ 33 | mainwindow.cpp \ 34 | encode.cpp \ 35 | animationscene.cpp \ 36 | rectangle.cpp \ 37 | itemhandle.cpp \ 38 | ellipse.cpp \ 39 | text.cpp \ 40 | resizeableitem.cpp \ 41 | bitmap.cpp \ 42 | vectorgraphic.cpp \ 43 | timeline.cpp \ 44 | expander.cpp \ 45 | itempropertyeditor.cpp \ 46 | scenepropertyeditor.cpp \ 47 | transitionpanel.cpp \ 48 | playhead.cpp \ 49 | colorpicker.cpp \ 50 | keyframe.cpp \ 51 | transitionline.cpp \ 52 | colorrect.cpp \ 53 | commands.cpp \ 54 | exception.cpp \ 55 | coloreditor.cpp \ 56 | handleitem.cpp \ 57 | keyframehandle.cpp \ 58 | serializeableitem.cpp \ 59 | textpropertyeditor.cpp \ 60 | timelinetreeview.cpp 61 | 62 | HEADERS += mainwindow.h \ 63 | animationscene.h \ 64 | rectangle.h \ 65 | itemhandle.h \ 66 | ellipse.h \ 67 | text.h \ 68 | resizeableitem.h \ 69 | bitmap.h \ 70 | vectorgraphic.h \ 71 | timeline.h \ 72 | expander.h \ 73 | itempropertyeditor.h \ 74 | scenepropertyeditor.h \ 75 | transitionpanel.h \ 76 | playhead.h \ 77 | colorpicker.h \ 78 | keyframe.h \ 79 | transitionline.h \ 80 | colorrect.h \ 81 | commands.h \ 82 | exception.h \ 83 | coloreditor.h \ 84 | handleitem.h \ 85 | keyframehandle.h \ 86 | scene.h \ 87 | serializeableitem.h \ 88 | textpropertyeditor.h \ 89 | timelinetreeview.h 90 | 91 | INCLUDEPATH += $$PWD/../../ffmpeg-3.2.2 92 | 93 | LIBS += -L$$PWD/lib/ 94 | 95 | 96 | LIBS += -lavutil 97 | LIBS += -lavformat 98 | LIBS += -lavcodec 99 | LIBS += -lswresample 100 | LIBS += -lavfilter 101 | LIBS += -lswscale 102 | LIBS += -lm 103 | LIBS += -ldl 104 | 105 | RESOURCES += \ 106 | images.qrc 107 | 108 | DISTFILES += \ 109 | todo.txt \ 110 | Deploy/AppImage/default.desktop \ 111 | Deploy/AppImage/create.sh \ 112 | Deploy/AppImage/default.png 113 | 114 | FORMS += 115 | 116 | -------------------------------------------------------------------------------- /itempropertyeditor.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** Copyright (C) 2016 Olaf Japp 3 | ** 4 | ** This file is part of AnimationMaker. 5 | ** 6 | ** AnimationMaker is free software: you can redistribute it and/or modify 7 | ** it under the terms of the GNU General Public License as published by 8 | ** the Free Software Foundation, either version 3 of the License, or 9 | ** (at your option) any later version. 10 | ** 11 | ** AnimationMaker is distributed in the hope that it will be useful, 12 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | ** GNU General Public License for more details. 15 | ** 16 | ** You should have received a copy of the GNU General Public License 17 | ** along with AnimationMaker. If not, see . 18 | ** 19 | ****************************************************************************/ 20 | 21 | #ifndef ITEMPROPERTYEDITOR_H 22 | #define ITEMPROPERTYEDITOR_H 23 | 24 | #include 25 | #include 26 | #include 27 | #include "resizeableitem.h" 28 | #include "expander.h" 29 | #include "text.h" 30 | #include "rectangle.h" 31 | #include "ellipse.h" 32 | #include "colorpicker.h" 33 | #include "colorrect.h" 34 | #include "coloreditor.h" 35 | 36 | class ItemPropertyEditor : public QWidget 37 | { 38 | Q_OBJECT 39 | public: 40 | ItemPropertyEditor(); 41 | 42 | void setItem(ResizeableItem *item); 43 | 44 | signals: 45 | void addKeyFrame(ResizeableItem*, QString, QVariant); 46 | 47 | private: 48 | bool m_initializing; 49 | ColorEditor *colorEditor; 50 | ColorEditor *borderColorEditor; 51 | ColorEditor *textcolorEditor; 52 | QLineEdit *m_id; 53 | QSpinBox *m_x; 54 | QSpinBox *m_y; 55 | QSpinBox *m_width; 56 | QSpinBox *m_height; 57 | QSpinBox *m_opacityText; 58 | QLabel *m_typ; 59 | QLineEdit *m_text; 60 | Expander *expText; 61 | Expander *expTextcolor; 62 | Expander *expColor; 63 | ResizeableItem *m_item; 64 | Text *m_textitem; 65 | Rectangle *m_rectangle; 66 | Ellipse *m_ellipse; 67 | QSlider *m_opacity; 68 | 69 | void changeBrush(QColor value); 70 | void changeOpacity(int opacity); 71 | 72 | private slots: 73 | void idChanged(QString value); 74 | void idChanged(ResizeableItem*,QString); 75 | void brushChanged(QColor color); 76 | void penChanged(QColor color); 77 | void textcolorChanged(QColor color); 78 | void xChanged(int value); 79 | void yChanged(int value); 80 | void widthChanged(int value); 81 | void heightChanged(int value); 82 | void textChanged(QString value); 83 | void addLeftKeyFrame(); 84 | void addTopKeyFrame(); 85 | void addWidthKeyFrame(); 86 | void addHeightKeyFrame(); 87 | void addOpacityKeyFrame(); 88 | void itemSizeChanged(qreal width, qreal height); 89 | void itemPositionChanged(qreal x, qreal y); 90 | void opacitySliderReleased(); 91 | void opacityTextChanged(int value); 92 | void opacityChanged(int value); 93 | void colorChanged(QColor); 94 | void borderColorChanged(QColor); 95 | void textColorChanged(QColor); 96 | }; 97 | 98 | #endif // ITEMPROPERTYEDITOR_H 99 | -------------------------------------------------------------------------------- /scenepropertyeditor.cpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** Copyright (C) 2016 Olaf Japp 3 | ** 4 | ** This file is part of AnimationMaker. 5 | ** 6 | ** AnimationMaker is free software: you can redistribute it and/or modify 7 | ** it under the terms of the GNU General Public License as published by 8 | ** the Free Software Foundation, either version 3 of the License, or 9 | ** (at your option) any later version. 10 | ** 11 | ** AnimationMaker is distributed in the hope that it will be useful, 12 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | ** GNU General Public License for more details. 15 | ** 16 | ** You should have received a copy of the GNU General Public License 17 | ** along with AnimationMaker. If not, see . 18 | ** 19 | ****************************************************************************/ 20 | 21 | #include "scenepropertyeditor.h" 22 | #include "expander.h" 23 | #include "commands.h" 24 | 25 | #include 26 | #include 27 | 28 | ScenePropertyEditor::ScenePropertyEditor() 29 | { 30 | QVBoxLayout *vbox = new QVBoxLayout(); 31 | Expander *exp = new Expander("Scene"); 32 | m_colorEditor = new ColorEditor("Backgroundcolor"); 33 | m_width = new QSpinBox(); 34 | m_height = new QSpinBox(); 35 | m_fps = new QSpinBox(); 36 | m_width->setMaximum(10000); 37 | m_height->setMaximum(10000); 38 | m_fps->setMaximum(60); 39 | QLabel *labelWidth = new QLabel("W"); 40 | QLabel *labelHeight = new QLabel("H"); 41 | labelWidth->setFixedWidth(15); 42 | labelHeight->setFixedWidth(15); 43 | QGridLayout *layout = new QGridLayout(); 44 | layout->addWidget(new QLabel("FPS"), 0, 0); 45 | layout->addWidget(m_fps, 0, 2); 46 | layout->addWidget(new QLabel("Size"), 1, 0); 47 | layout->addWidget(labelWidth, 1, 1); 48 | layout->addWidget(m_width, 1, 2); 49 | layout->addWidget(labelHeight, 1, 3); 50 | layout->addWidget(m_height, 1, 4); 51 | layout->addWidget(m_colorEditor, 2, 0, 1, 5); 52 | exp->addLayout(layout); 53 | vbox->addWidget(exp); 54 | vbox->addStretch(); 55 | this->setLayout(vbox); 56 | 57 | connect(m_width, SIGNAL(valueChanged(int)), this, SLOT(widthChanged(int))); 58 | connect(m_height, SIGNAL(valueChanged(int)), this, SLOT(heightChanged(int))); 59 | connect(m_fps, SIGNAL(valueChanged(int)), this, SLOT(fpsChanged(int))); 60 | connect(m_colorEditor, SIGNAL(colorChanged(QColor)), this, SLOT(colorChanged(QColor))); 61 | } 62 | 63 | void ScenePropertyEditor::setScene(AnimationScene *scene) 64 | { 65 | m_scene = scene; 66 | m_width->setValue(m_scene->width()); 67 | m_height->setValue(m_scene->height()); 68 | m_fps->setValue(m_scene->fps()); 69 | m_colorEditor->setColor(m_scene->backgroundColor()); 70 | connect(m_scene, SIGNAL(backgroundColorChanged(QColor)), this, SLOT(backgroundColorChanged(QColor))); 71 | } 72 | 73 | void ScenePropertyEditor::backgroundColorChanged(QColor color) 74 | { 75 | m_colorEditor->setColor(color); 76 | } 77 | 78 | void ScenePropertyEditor::widthChanged(int value) 79 | { 80 | m_scene->setWidth(value); 81 | } 82 | 83 | void ScenePropertyEditor::heightChanged(int value) 84 | { 85 | m_scene->setHeight(value); 86 | } 87 | 88 | void ScenePropertyEditor::fpsChanged(int value) 89 | { 90 | m_scene->setFps(value); 91 | } 92 | 93 | void ScenePropertyEditor::colorChanged(QColor color) 94 | { 95 | QUndoCommand *cmd = new ChangeSceneColorCommand(color, m_scene->backgroundColor(), m_scene); 96 | m_scene->undoStack()->push(cmd); 97 | } 98 | -------------------------------------------------------------------------------- /itemhandle.cpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** Copyright (C) 2016 Olaf Japp 3 | ** 4 | ** This file is part of AnimationMaker. 5 | ** 6 | ** AnimationMaker is free software: you can redistribute it and/or modify 7 | ** it under the terms of the GNU General Public License as published by 8 | ** the Free Software Foundation, either version 3 of the License, or 9 | ** (at your option) any later version. 10 | ** 11 | ** AnimationMaker is distributed in the hope that it will be useful, 12 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | ** GNU General Public License for more details. 15 | ** 16 | ** You should have received a copy of the GNU General Public License 17 | ** along with AnimationMaker. If not, see . 18 | ** 19 | ****************************************************************************/ 20 | 21 | #include "itemhandle.h" 22 | 23 | #include 24 | 25 | ItemHandle::ItemHandle(int corner) : 26 | mouseDownX(0), 27 | mouseDownY(0), 28 | m_color(Qt::black), 29 | m_pen(Qt::white), 30 | m_width(9), 31 | m_height(9), 32 | m_corner(corner), 33 | m_mouseButtonState(kMouseReleased) 34 | { 35 | m_pen.setWidth(1); 36 | this->setAcceptHoverEvents(true); 37 | setZValue(100); 38 | 39 | switch(corner) 40 | { 41 | case 0: 42 | case 2: 43 | setCursor(Qt::SizeFDiagCursor); 44 | break; 45 | case 1: 46 | case 3: 47 | setCursor(Qt::SizeBDiagCursor); 48 | break; 49 | case 4: 50 | case 6: 51 | setCursor(Qt::SizeVerCursor); 52 | break; 53 | case 5: 54 | case 7: 55 | setCursor(Qt::SizeHorCursor); 56 | break; 57 | } 58 | } 59 | 60 | void ItemHandle::setMouseState(int s) 61 | { 62 | m_mouseButtonState = s; 63 | } 64 | 65 | int ItemHandle::getMouseState() 66 | { 67 | return m_mouseButtonState; 68 | } 69 | 70 | int ItemHandle::getCorner() 71 | { 72 | return m_corner; 73 | } 74 | 75 | void ItemHandle::mouseMoveEvent(QGraphicsSceneDragDropEvent *event) 76 | { 77 | event->setAccepted(false); 78 | } 79 | 80 | void ItemHandle::mousePressEvent(QGraphicsSceneDragDropEvent *event) 81 | { 82 | event->setAccepted(false); 83 | } 84 | 85 | void ItemHandle::mouseReleaseEvent ( QGraphicsSceneMouseEvent * event ) 86 | { 87 | event->setAccepted(true); 88 | } 89 | 90 | void ItemHandle::mousePressEvent ( QGraphicsSceneMouseEvent * event ) 91 | { 92 | event->setAccepted(false); 93 | } 94 | 95 | void ItemHandle::mouseMoveEvent ( QGraphicsSceneMouseEvent * event ) 96 | { 97 | event->setAccepted(false); 98 | } 99 | 100 | void ItemHandle::hoverLeaveEvent ( QGraphicsSceneHoverEvent * ) 101 | { 102 | m_color = Qt::black; 103 | this->update(0, 0, m_width, m_height); 104 | } 105 | 106 | void ItemHandle::hoverEnterEvent ( QGraphicsSceneHoverEvent * ) 107 | { 108 | m_color = QColor(255, 127, 42); 109 | this->update(0, 0, m_width, m_height); 110 | } 111 | 112 | QRectF ItemHandle::boundingRect() const 113 | { 114 | return QRectF(0, 0, m_width, m_height); 115 | } 116 | 117 | void ItemHandle::paint (QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) 118 | { 119 | m_pen.setCapStyle(Qt::SquareCap); 120 | m_pen.setStyle(Qt::SolidLine); 121 | painter->setPen(m_pen); 122 | QPointF topLeft (0, 0); 123 | QPointF bottomRight (m_width, m_height); 124 | QRectF rect (topLeft, bottomRight); 125 | QBrush brush (Qt::SolidPattern); 126 | brush.setColor(m_color); 127 | painter->fillRect(rect,brush); 128 | } 129 | -------------------------------------------------------------------------------- /timeline.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** Copyright (C) 2016 Olaf Japp 3 | ** 4 | ** This file is part of AnimationMaker. 5 | ** 6 | ** AnimationMaker is free software: you can redistribute it and/or modify 7 | ** it under the terms of the GNU General Public License as published by 8 | ** the Free Software Foundation, either version 3 of the License, or 9 | ** (at your option) any later version. 10 | ** 11 | ** AnimationMaker is distributed in the hope that it will be useful, 12 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | ** GNU General Public License for more details. 15 | ** 16 | ** You should have received a copy of the GNU General Public License 17 | ** along with AnimationMaker. If not, see . 18 | ** 19 | ****************************************************************************/ 20 | 21 | #ifndef TIMELINE_H 22 | #define TIMELINE_H 23 | 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include "resizeableitem.h" 30 | #include "animationscene.h" 31 | #include "transitionpanel.h" 32 | #include "playhead.h" 33 | 34 | class Timeline : public QWidget 35 | { 36 | Q_OBJECT 37 | public: 38 | Timeline(AnimationScene *scene); 39 | 40 | void reset(); 41 | inline void setPlayheadPosition(int value) {m_playhead->setValue(value);} 42 | inline void expandTree() {m_tree->expandAll();} 43 | int lastKeyframe(); 44 | void removeItem(ResizeableItem *item); 45 | void selectItem(ResizeableItem *item); 46 | void addKeyFrame(ResizeableItem *item, QString propertyName, KeyFrame *frame); 47 | void deleteKeyFrame(ResizeableItem *item, QString propertyName, KeyFrame *frame); 48 | void addTransition(ResizeableItem *item, QString propertyName, KeyFrame *frame); 49 | void deleteTransition(ResizeableItem *item, QString propertyName, KeyFrame *frame); 50 | 51 | public slots: 52 | void onCustomContextMenu(const QPoint &point); 53 | void playAnimation(); 54 | void pauseAnimation(); 55 | void revertAnimation(); 56 | void forwardAnimation(); 57 | void playheadValueChanged(int val); 58 | void addKeyFrame(ResizeableItem *item,QString property, QVariant value); 59 | void autokeyframes(bool value); 60 | void autotransitions(bool value); 61 | void idChanged(ResizeableItem *item, QString value); 62 | void treeCurrentItemChanged(QTreeWidgetItem *currentItem, QTreeWidgetItem*); 63 | void keyframeAdded(ResizeableItem * item, QString propertyName, KeyFrame *key); 64 | void deleteKeyFrameSlot(ResizeableItem *item, QString propertyName, KeyFrame *frame); 65 | void deleteTransitionSlot(ResizeableItem *item, QString propertyName, KeyFrame *frame); 66 | void addTransitionSlot(ResizeableItem *item, QString propertyName, KeyFrame *frame); 67 | 68 | signals: 69 | void itemSelectionChanged(ResizeableItem *item); 70 | void keyframeAdded(ResizeableItem *item, QString propertyName); 71 | void keyframeDeleted(ResizeableItem *item, QString propertyName); 72 | void transitionDeleted(ResizeableItem *item, QString propertyName); 73 | 74 | private: 75 | QTreeWidget *m_tree; 76 | QMenu *m_contextMenu; 77 | QAction *m_delAct; 78 | AnimationScene *m_scene; 79 | TransitionPanel *m_transitionPanel; 80 | PlayHead *m_playhead; 81 | QLabel *m_time; 82 | bool m_playing; 83 | QToolButton *playButton; 84 | QToolButton *pauseButton; 85 | 86 | void addProperty(const QString name); 87 | void createAnimationGroup(); 88 | QTreeWidgetItem *search(ResizeableItem *item); 89 | QTreeWidgetItem *search(QTreeWidgetItem *treeItem, QString propertyName); 90 | }; 91 | 92 | #endif // TIMELINE_H 93 | -------------------------------------------------------------------------------- /mainwindow.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** Copyright (C) 2016 Olaf Japp 3 | ** 4 | ** This file is part of AnimationMaker. 5 | ** 6 | ** AnimationMaker is free software: you can redistribute it and/or modify 7 | ** it under the terms of the GNU General Public License as published by 8 | ** the Free Software Foundation, either version 3 of the License, or 9 | ** (at your option) any later version. 10 | ** 11 | ** AnimationMaker is distributed in the hope that it will be useful, 12 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | ** GNU General Public License for more details. 15 | ** 16 | ** You should have received a copy of the GNU General Public License 17 | ** along with AnimationMaker. If not, see . 18 | ** 19 | ****************************************************************************/ 20 | 21 | #ifndef MAINWINDOW_H 22 | #define MAINWINDOW_H 23 | 24 | #include 25 | #include 26 | #include "animationscene.h" 27 | #include "timeline.h" 28 | #include "itempropertyeditor.h" 29 | #include "scenepropertyeditor.h" 30 | 31 | namespace Ui 32 | { 33 | class MainWindow; 34 | } 35 | 36 | class MainWindow : public QMainWindow 37 | { 38 | Q_OBJECT 39 | 40 | public: 41 | explicit MainWindow(QWidget *parent = 0); 42 | ~MainWindow(); 43 | 44 | void setTitle(); 45 | 46 | protected: 47 | void closeEvent(QCloseEvent *event) Q_DECL_OVERRIDE; 48 | 49 | private: 50 | void createMenus(); 51 | void createActions(); 52 | void createStatusBar(); 53 | void createGui(); 54 | void writeSettings(); 55 | void readSettings(); 56 | void writeFile(QString fileName); 57 | void reset(); 58 | void fillTree(); 59 | 60 | QSplitter *splitter; 61 | QToolBar *toolbar; 62 | QTreeWidget *elementTree; 63 | AnimationScene *scene; 64 | QGraphicsView *view; 65 | QFileInfo loadedFile; 66 | Timeline *timeline; 67 | ItemPropertyEditor *m_itemPropertyEditor; 68 | ScenePropertyEditor *m_scenePropertyEditor; 69 | QDockWidget *propertiesdock; 70 | QDockWidget *tooldock; 71 | QTreeWidgetItem *root; 72 | 73 | 74 | QAction *openAct; 75 | QAction *newAct; 76 | QAction *saveAct; 77 | QAction *saveAsAct; 78 | QAction *exportAct; 79 | QAction *exitAct; 80 | QAction *aboutAct; 81 | QAction *selectAct; 82 | QAction *rectangleAct; 83 | QAction *ellipseAct; 84 | QAction *textAct; 85 | QAction *svgAct; 86 | QAction *bitmapAct; 87 | QAction *showPropertyPanelAct; 88 | QAction *showToolPanelAct; 89 | QAction *undoAct; 90 | QAction *redoAct; 91 | QAction *copyAct; 92 | QAction *pasteAct; 93 | QAction *delAct; 94 | QMenu *fileMenu; 95 | QMenu *editMenu; 96 | QMenu *helpMenu; 97 | QMenu *viewMenu; 98 | QUndoStack *undoStack; 99 | 100 | public slots: 101 | void exportAnimation(); 102 | void about(); 103 | void save(); 104 | void saveAs(); 105 | void open(); 106 | void newfile(); 107 | void setSelectMode(); 108 | void setRectangleMode(); 109 | void setEllipseMode(); 110 | void setTextMode(); 111 | void setBitmapMode(); 112 | void setSvgMode(); 113 | void elementTreeItemChanged(QTreeWidgetItem*, QTreeWidgetItem*); 114 | void sceneItemAdded(QGraphicsItem *); 115 | void showPropertyPanel(); 116 | void showToolPanel(); 117 | void sceneSelectionChanged(); 118 | void timelineSelectionChanged(ResizeableItem*); 119 | void copy(); 120 | void paste(); 121 | void del(); 122 | void sceneSizeChanged(int width, int height); 123 | void sceneItemRemoved(ResizeableItem *item); 124 | void idChanged(ResizeableItem *, QString); 125 | }; 126 | 127 | #endif // MAINWINDOW_H 128 | -------------------------------------------------------------------------------- /resizeableitem.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** Copyright (C) 2016 Olaf Japp 3 | ** 4 | ** This file is part of AnimationMaker. 5 | ** 6 | ** AnimationMaker is free software: you can redistribute it and/or modify 7 | ** it under the terms of the GNU General Public License as published by 8 | ** the Free Software Foundation, either version 3 of the License, or 9 | ** (at your option) any later version. 10 | ** 11 | ** AnimationMaker is distributed in the hope that it will be useful, 12 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | ** GNU General Public License for more details. 15 | ** 16 | ** You should have received a copy of the GNU General Public License 17 | ** along with AnimationMaker. If not, see . 18 | ** 19 | ****************************************************************************/ 20 | 21 | #ifndef RESIZEABLEITEM_H 22 | #define RESIZEABLEITEM_H 23 | 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include "itemhandle.h" 29 | #include "keyframe.h" 30 | 31 | class AnimationScene; 32 | class ResizeableItem : public QObject, public QGraphicsItem 33 | { 34 | Q_OBJECT 35 | Q_PROPERTY(qreal opacity READ opacity WRITE setOpacity) 36 | Q_PROPERTY(qreal left READ left WRITE setLeft) 37 | Q_PROPERTY(qreal top READ top WRITE setTop) 38 | public: 39 | ResizeableItem(AnimationScene *scene); 40 | ~ResizeableItem(); 41 | 42 | void drawHighlightSelected(QPainter *painter, const QStyleOptionGraphicsItem *option); 43 | void paint( QPainter *paint, const QStyleOptionGraphicsItem *, QWidget *); 44 | QRectF boundingRect() const; 45 | bool sceneEventFilter(QGraphicsItem * watched, QEvent * event); 46 | QVariant itemChange(GraphicsItemChange change, const QVariant &value); 47 | virtual void scaleObjects(); 48 | virtual void setScale(qreal x, qreal y); 49 | qreal xscale(); 50 | qreal yscale(); 51 | 52 | QString id() const; 53 | void setId(const QString value); 54 | 55 | QRectF rect() const; 56 | void setRect(qreal x, qreal y, qreal w, qreal h); 57 | 58 | QPen pen() const; 59 | void setPen(const QPen &pen); 60 | 61 | QBrush brush() const; 62 | void setBrush(const QBrush &brush); 63 | 64 | inline int opacity() {return m_opacity;} 65 | inline void setOpacity(int opacity) {m_opacity = opacity; QGraphicsItem::setOpacity((qreal)m_opacity / 100); emit opacityChanged(opacity);} 66 | 67 | inline qreal left() {return x();} 68 | inline qreal top() {return y();} 69 | inline void setLeft(qreal val) {setX(val);} 70 | inline void setTop(qreal val) {setY(val);} 71 | 72 | void setWidth(qreal value); 73 | void setHeight(qreal value); 74 | 75 | void addKeyframe(QString propertyName, KeyFrame *frame); 76 | bool deleteKeyframe(QString propertyName, KeyFrame *frame); 77 | inline QHash *keyframes() {return m_keyframes;} 78 | 79 | void adjustKeyframes(QString propertyName, QVariant value, int time, bool autokeyframes, bool autotransition); 80 | 81 | void posChanged(qreal x, qreal y); 82 | 83 | inline AnimationScene *scene() {return m_scene;} 84 | 85 | private: 86 | AnimationScene *m_scene; 87 | ItemHandle* m_handles[8]; 88 | bool m_hasHandles; 89 | QString m_id; 90 | QRectF m_rect; 91 | QPen m_pen; 92 | QBrush m_brush; 93 | QMenu *m_contextMenu; 94 | QAction *delAct; 95 | QAction *bringToFrontAct; 96 | QAction *sendToBackAct; 97 | QAction *lowerAct; 98 | QAction *raiseAct; 99 | QHash *m_keyframes; 100 | qreal m_oldx, m_oldy, m_oldwidth, m_oldheight; 101 | int m_opacity; 102 | 103 | private slots: 104 | void deleteItem(); 105 | void bringToFront(); 106 | void sendToBack(); 107 | void lower(); 108 | void raise(); 109 | 110 | signals: 111 | void addPropertyAnimation(ResizeableItem *item, const QString propertyName, qreal value, int min, int max); 112 | void idChanged(ResizeableItem *item, QString value); 113 | void sizeChanged(qreal width, qreal height); 114 | void positionChanged(qreal x, qreal y); 115 | void itemRemoved(ResizeableItem *item); 116 | void brushChanged(QColor); 117 | void penChanged(QColor); 118 | void opacityChanged(int opacity); 119 | 120 | protected: 121 | void setHandlePositions(); 122 | void contextMenuEvent(QGraphicsSceneContextMenuEvent *event) Q_DECL_OVERRIDE; 123 | qreal m_xscale; 124 | qreal m_yscale; 125 | 126 | }; 127 | 128 | #endif // RESIZEABLEITEM_H 129 | -------------------------------------------------------------------------------- /animationscene.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** Copyright (C) 2016 Olaf Japp 3 | ** 4 | ** This file is part of AnimationMaker. 5 | ** 6 | ** AnimationMaker is free software: you can redistribute it and/or modify 7 | ** it under the terms of the GNU General Public License as published by 8 | ** the Free Software Foundation, either version 3 of the License, or 9 | ** (at your option) any later version. 10 | ** 11 | ** AnimationMaker is distributed in the hope that it will be useful, 12 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | ** GNU General Public License for more details. 15 | ** 16 | ** You should have received a copy of the GNU General Public License 17 | ** along with AnimationMaker. If not, see . 18 | ** 19 | ****************************************************************************/ 20 | 21 | #ifndef ANIMATIONSCENE_H 22 | #define ANIMATIONSCENE_H 23 | 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | 33 | #include "resizeableitem.h" 34 | #include "keyframe.h" 35 | 36 | class AnimationScene : public QGraphicsScene 37 | { 38 | Q_OBJECT 39 | public: 40 | AnimationScene(); 41 | 42 | void reset(); 43 | 44 | enum ItemType { TypeItem, TypeRectangle, TypeEllipse, TypeText, TypeBitmap, TypeSvg }; 45 | enum EditMode { ModeSelect, ModeRectangle, ModeEllipse, ModeText, ModeBitmap, ModeSvg }; 46 | 47 | void setEditMode(EditMode mode); 48 | QDataStream& read(QDataStream &dataStream); 49 | QDataStream& write(QDataStream &dataStream) const; 50 | 51 | inline int fps() const {return m_fps;} 52 | inline void setFps(int value) {m_fps = value;} 53 | 54 | inline void setWidth(int value) {setSceneRect(0, 0, value, height()); m_rect->setRect(0,0,value, height()); emit sizeChanged(value, height());} 55 | inline void setHeight(int value) {setSceneRect(0, 0, width(), value); m_rect->setRect(0,0,width(), value); emit sizeChanged(width(), value);} 56 | 57 | inline QColor backgroundColor() const {return m_backgroundColor;} 58 | inline void setBackgroundColor(QColor value) 59 | { 60 | m_backgroundColor = value; 61 | m_rect->setBrush(QBrush(QColor(m_backgroundColor))); 62 | emit backgroundColorChanged(value); 63 | } 64 | 65 | inline int playheadPosition() {return m_playheadPosition;} 66 | 67 | void copyItem(); 68 | void pasteItem(); 69 | 70 | void deleteItem(ResizeableItem *item); 71 | inline bool autokeyframes() {return m_autokeyframes;} 72 | inline void setAutokeyframes(bool value) {m_autokeyframes = value;} 73 | 74 | inline bool autotransition() {return m_autotransitions;} 75 | inline void setAutotransition(bool value) {m_autotransitions = value;} 76 | 77 | inline void registerUndoStack(QUndoStack *stack) {m_undoStack = stack;} 78 | inline QUndoStack *undoStack() {return m_undoStack;} 79 | 80 | signals: 81 | void itemAdded(QGraphicsItem *item); 82 | void sizeChanged(int width, int height); 83 | void keyframeAdded(ResizeableItem *item, QString propertyName, KeyFrame *key); 84 | void itemRemoved(ResizeableItem *item); 85 | void backgroundColorChanged(QColor color); 86 | 87 | public slots: 88 | void setPlayheadPosition(int value); 89 | 90 | protected: 91 | void mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent) Q_DECL_OVERRIDE; 92 | void mouseMoveEvent(QGraphicsSceneMouseEvent *mouseEvent) Q_DECL_OVERRIDE; 93 | void mouseReleaseEvent(QGraphicsSceneMouseEvent *mouseEvent) Q_DECL_OVERRIDE; 94 | 95 | private: 96 | EditMode m_editMode; 97 | int m_fps; 98 | ResizeableItem *m_copy; 99 | QColor m_backgroundColor; 100 | QGraphicsRectItem *m_rect; 101 | int m_playheadPosition; 102 | KeyFrame *m_tempKeyFrame; 103 | bool m_autokeyframes; 104 | bool m_autotransitions; 105 | QUndoStack *m_undoStack; 106 | ResizeableItem *m_movingItem; 107 | QPointF m_oldPos; 108 | 109 | void initialize(); 110 | void addBackgroundRect(); 111 | void writeKeyframes(QDataStream &dataStream, ResizeableItem *item) const; 112 | void readKeyframes(QDataStream &dataStream, ResizeableItem *item); 113 | 114 | }; 115 | 116 | QDataStream &operator<<(QDataStream &, const AnimationScene *); 117 | QDataStream &operator>>(QDataStream &, AnimationScene *); 118 | QString getItemTypeName(ResizeableItem *item); 119 | bool isAnimationMakerItem(QGraphicsItem *item); 120 | 121 | #endif // ANIMATIONSCENE_H 122 | -------------------------------------------------------------------------------- /commands.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** Copyright (C) 2016 Olaf Japp 3 | ** 4 | ** This file is part of AnimationMaker. 5 | ** 6 | ** AnimationMaker is free software: you can redistribute it and/or modify 7 | ** it under the terms of the GNU General Public License as published by 8 | ** the Free Software Foundation, either version 3 of the License, or 9 | ** (at your option) any later version. 10 | ** 11 | ** AnimationMaker is distributed in the hope that it will be useful, 12 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | ** GNU General Public License for more details. 15 | ** 16 | ** You should have received a copy of the GNU General Public License 17 | ** along with AnimationMaker. If not, see . 18 | ** 19 | ****************************************************************************/ 20 | 21 | #ifndef COMMANDS_H 22 | #define COMMANDS_H 23 | 24 | #include 25 | #include "animationscene.h" 26 | #include "resizeableitem.h" 27 | #include "timeline.h" 28 | #include "text.h" 29 | 30 | class AddItemCommand : public QUndoCommand 31 | { 32 | public: 33 | AddItemCommand(qreal x, qreal y, AnimationScene::EditMode mode, QString fileName, AnimationScene *scene, QUndoCommand *parent = 0); 34 | 35 | void undo() override; 36 | void redo() override; 37 | 38 | private: 39 | ResizeableItem *m_item; 40 | AnimationScene *m_scene; 41 | }; 42 | 43 | 44 | class DeleteItemCommand : public QUndoCommand 45 | { 46 | public: 47 | DeleteItemCommand(ResizeableItem *item, AnimationScene *scene, QUndoCommand *parent = 0); 48 | 49 | void undo() override; 50 | void redo() override; 51 | 52 | private: 53 | ResizeableItem *m_item; 54 | AnimationScene *m_scene; 55 | }; 56 | 57 | 58 | class MoveItemCommand : public QUndoCommand 59 | { 60 | public: 61 | MoveItemCommand(qreal x, qreal y, qreal oldx, qreal oldy, AnimationScene *scene, ResizeableItem *item, QUndoCommand *parent = 0); 62 | 63 | void undo() override; 64 | void redo() override; 65 | 66 | private: 67 | ResizeableItem *m_item; 68 | qreal m_x, m_y, m_oldx, m_oldy; 69 | int m_time; 70 | bool m_autokeyframes; 71 | bool m_autotransition; 72 | }; 73 | 74 | 75 | class ResizeItemCommand : public QUndoCommand 76 | { 77 | public: 78 | ResizeItemCommand(qreal width, qreal height, qreal oldwidth, qreal oldheight, AnimationScene *scene, ResizeableItem *item, QUndoCommand *parent = 0); 79 | 80 | void undo() override; 81 | void redo() override; 82 | 83 | private: 84 | ResizeableItem *m_item; 85 | qreal m_width, m_height, m_oldwidth, m_oldheight; 86 | int m_time; 87 | bool m_autokeyframes; 88 | bool m_autotransition; 89 | }; 90 | 91 | 92 | class ScaleItemCommand : public QUndoCommand 93 | { 94 | public: 95 | ScaleItemCommand(qreal x, qreal y, qreal width, qreal height, qreal oldx, qreal oldy, qreal oldwidth, qreal oldheight, AnimationScene *scene, ResizeableItem *item, QUndoCommand *parent = 0); 96 | 97 | void undo() override; 98 | void redo() override; 99 | 100 | private: 101 | ResizeableItem *m_item; 102 | qreal m_x, m_y, m_width, m_height, m_oldx, m_oldy, m_oldwidth, m_oldheight; 103 | int m_time; 104 | bool m_autokeyframes; 105 | bool m_autotransition; 106 | }; 107 | 108 | 109 | class ChangeIdCommand : public QUndoCommand 110 | { 111 | public: 112 | ChangeIdCommand(QString id, QString oldid, ResizeableItem *item, QUndoCommand *parent = 0); 113 | 114 | void undo() override; 115 | void redo() override; 116 | 117 | private: 118 | ResizeableItem *m_item; 119 | QString m_id, m_oldid; 120 | }; 121 | 122 | class ChangeColorCommand : public QUndoCommand 123 | { 124 | public: 125 | ChangeColorCommand(QColor color, QColor oldcolor, ResizeableItem *item, QUndoCommand *parent = 0); 126 | 127 | void undo() override; 128 | void redo() override; 129 | 130 | private: 131 | ResizeableItem *m_item; 132 | QColor m_color, m_oldcolor; 133 | }; 134 | 135 | class ChangePenCommand : public QUndoCommand 136 | { 137 | public: 138 | ChangePenCommand(QColor color, QColor oldcolor, ResizeableItem *item, QUndoCommand *parent = 0); 139 | 140 | void undo() override; 141 | void redo() override; 142 | 143 | private: 144 | ResizeableItem *m_item; 145 | QColor m_color, m_oldcolor; 146 | }; 147 | 148 | class ChangeTextcolorCommand : public QUndoCommand 149 | { 150 | public: 151 | ChangeTextcolorCommand(QColor color, QColor oldcolor, Text *item, QUndoCommand *parent = 0); 152 | 153 | void undo() override; 154 | void redo() override; 155 | 156 | private: 157 | Text *m_item; 158 | QColor m_color, m_oldcolor; 159 | }; 160 | 161 | class ChangeSceneColorCommand : public QUndoCommand 162 | { 163 | public: 164 | ChangeSceneColorCommand(QColor color, QColor oldcolor, AnimationScene *scene, QUndoCommand *parent = 0); 165 | 166 | void undo() override; 167 | void redo() override; 168 | 169 | private: 170 | AnimationScene *m_scene; 171 | QColor m_color, m_oldcolor; 172 | }; 173 | 174 | class ChangeOpacityCommand : public QUndoCommand 175 | { 176 | public: 177 | ChangeOpacityCommand(int opacity, int oldopacity, AnimationScene *scene, ResizeableItem *item, QUndoCommand *parent = 0); 178 | 179 | void undo() override; 180 | void redo() override; 181 | 182 | private: 183 | ResizeableItem *m_item; 184 | int m_opacity, m_oldopacity; 185 | int m_time; 186 | bool m_autokeyframes; 187 | bool m_autotransition; 188 | }; 189 | 190 | class AddKeyframeCommand : public QUndoCommand 191 | { 192 | public: 193 | AddKeyframeCommand(QString propertyname, KeyFrame *frame, ResizeableItem *item, Timeline *timeline, QUndoCommand *parent = 0); 194 | 195 | void undo() override; 196 | void redo() override; 197 | 198 | private: 199 | ResizeableItem *m_item; 200 | QString m_propertyName; 201 | KeyFrame *m_frame; 202 | Timeline *m_timeline; 203 | }; 204 | 205 | class DeleteKeyframeCommand : public QUndoCommand 206 | { 207 | public: 208 | DeleteKeyframeCommand(QString propertyname, KeyFrame *frame, ResizeableItem *item, Timeline *timeline, QUndoCommand *parent = 0); 209 | 210 | void undo() override; 211 | void redo() override; 212 | 213 | private: 214 | ResizeableItem *m_item; 215 | QString m_propertyName; 216 | KeyFrame *m_frame; 217 | Timeline *m_timeline; 218 | }; 219 | 220 | class AddTransitionCommand : public QUndoCommand 221 | { 222 | public: 223 | AddTransitionCommand(QString propertyname, KeyFrame *frame, ResizeableItem *item, Timeline *timeline, QUndoCommand *parent = 0); 224 | 225 | void undo() override; 226 | void redo() override; 227 | 228 | private: 229 | ResizeableItem *m_item; 230 | QString m_propertyName; 231 | KeyFrame *m_frame; 232 | Timeline *m_timeline; 233 | }; 234 | 235 | class DeleteTransitionCommand : public QUndoCommand 236 | { 237 | public: 238 | DeleteTransitionCommand(QString propertyname, KeyFrame *frame, ResizeableItem *item, Timeline *timeline, QUndoCommand *parent = 0); 239 | 240 | void undo() override; 241 | void redo() override; 242 | 243 | private: 244 | ResizeableItem *m_item; 245 | QString m_propertyName; 246 | KeyFrame *m_frame; 247 | Timeline *m_timeline; 248 | }; 249 | 250 | 251 | #endif // COMMANDS_H 252 | -------------------------------------------------------------------------------- /transitionline.cpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** Copyright (C) 2016 Olaf Japp 3 | ** 4 | ** This file is part of AnimationMaker. 5 | ** 6 | ** AnimationMaker is free software: you can redistribute it and/or modify 7 | ** it under the terms of the GNU General Public License as published by 8 | ** the Free Software Foundation, either version 3 of the License, or 9 | ** (at your option) any later version. 10 | ** 11 | ** AnimationMaker is distributed in the hope that it will be useful, 12 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | ** GNU General Public License for more details. 15 | ** 16 | ** You should have received a copy of the GNU General Public License 17 | ** along with AnimationMaker. If not, see . 18 | ** 19 | ****************************************************************************/ 20 | 21 | #include "transitionline.h" 22 | #include "keyframehandle.h" 23 | #include "commands.h" 24 | 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | 31 | TransitionLine::TransitionLine(ResizeableItem *item, QString propertyName) 32 | { 33 | m_item = item; 34 | m_frame = NULL; 35 | m_propertyName = propertyName; 36 | m_playheadPosition = 0; 37 | m_pressed = false; 38 | 39 | setMouseTracking(true); 40 | 41 | setMaximumHeight(17); 42 | setMinimumHeight(17); 43 | 44 | m_imageRaute = QImage(":/images/raute-weiss.png"); 45 | m_imageRauteHohl = QImage(":/images/raute-hohl.png"); 46 | m_imageLeft = QImage(":/images/trans-left.png"); 47 | m_imageRight = QImage(":/images/trans-right.png"); 48 | 49 | m_contextMenu = new QMenu(); 50 | m_transitionAct = new QAction("Create transition"); 51 | m_delKeyframeAct = new QAction("Delete keyframe"); 52 | m_delTransitionAct = new QAction("Delete transition"); 53 | connect(m_transitionAct, SIGNAL(triggered(bool)), this, SLOT(addTransition())); 54 | connect(m_delKeyframeAct, SIGNAL(triggered(bool)), this, SLOT(deleteKeyframe())); 55 | connect(m_delTransitionAct, SIGNAL(triggered(bool)), this, SLOT(deleteTransition())); 56 | 57 | setContextMenuPolicy(Qt::CustomContextMenu); 58 | connect(this, SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(onCustomContextMenu(const QPoint &))); 59 | connect(item, SIGNAL(positionChanged(qreal,qreal)), this, SLOT(update())); 60 | connect(item, SIGNAL(sizeChanged(qreal,qreal)), this, SLOT(update())); 61 | } 62 | 63 | void TransitionLine::paintEvent(QPaintEvent *) 64 | { 65 | QColor orange(255, 102, 0, 150); 66 | QColor gray; 67 | if(m_propertyName.isEmpty()) 68 | gray = QColor(76, 78, 80); 69 | else 70 | gray = QColor(64, 66, 68); 71 | int width = size().width(); 72 | int height = size().height(); 73 | int offset = m_horizontalScrollValue * 20; 74 | 75 | QPainter painter(this); 76 | painter.fillRect(0, 0, width, height, gray); 77 | 78 | painter.setPen(QColor(41, 41, 41)); 79 | for(int k = 199 - offset; k < width; k+=200) 80 | { 81 | painter.drawLine(k, 0, k, height); 82 | } 83 | 84 | if(!m_propertyName.isEmpty()) 85 | { 86 | KeyFrame *first = m_item->keyframes()->value(m_propertyName); 87 | for(KeyFrame *frame = first; frame != NULL; frame = frame->next()) 88 | { 89 | if(frame->easing() >= 0) 90 | { 91 | painter.fillRect(frame->time() / 5 - offset, 1, (frame->next()->time() - frame->time()) / 5, height - 1, orange); 92 | painter.drawImage(frame->time() / 5 - offset, 1, m_imageLeft); 93 | painter.drawImage(frame->next()->time() / 5 - 5 - offset, 1, m_imageRight); 94 | } 95 | else if(frame->prev() == NULL || frame->prev()->easing() < 0) 96 | { 97 | if(frame->prev() == NULL || frame->prev()->value() == frame->value()) 98 | painter.drawImage(frame->time() / 5 - 6 - offset, 2, m_imageRaute); 99 | else 100 | painter.drawImage(frame->time() / 5 - 6 - offset, 2, m_imageRauteHohl); 101 | } 102 | } 103 | } 104 | 105 | painter.setPen(Qt::red); 106 | painter.drawLine(m_playheadPosition / 5 - 1 - offset, 0, m_playheadPosition / 5 - 1 - offset, height); 107 | } 108 | 109 | void TransitionLine::mousePressEvent(QMouseEvent *ev) 110 | { 111 | if(ev->button() == Qt::LeftButton) 112 | { 113 | if(!m_propertyName.isEmpty()) 114 | { 115 | int offset = m_horizontalScrollValue * 20; 116 | KeyFrame *first = m_item->keyframes()->value(m_propertyName); 117 | for(KeyFrame *frame = first; frame != NULL; frame = frame->next()) 118 | { 119 | int pos = frame->time() / 5 - 6; 120 | if(ev->pos().x() + offset >= pos && ev->pos().x() + offset <= pos + 11) 121 | { 122 | m_oldx = ev->pos().x(); 123 | m_frame = frame; 124 | m_pressed = true; 125 | break; 126 | } 127 | } 128 | } 129 | } 130 | } 131 | 132 | void TransitionLine::mouseMoveEvent(QMouseEvent *ev) 133 | { 134 | bool isOverKeyframe = false; 135 | 136 | if(m_pressed) 137 | { 138 | int x = ev->x(); 139 | if(x < 0) 140 | x = 0; 141 | if(x >= width()) 142 | x = width() - 1; 143 | x += m_horizontalScrollValue * 20; 144 | int time = qRound((qreal)x * 5 / 100) * 100; 145 | if(time / 5 > width()) 146 | time -= 100; 147 | m_frame->setTime(time); 148 | m_oldx = ev->pos().x(); 149 | update(); 150 | } 151 | 152 | if(!m_propertyName.isEmpty()) 153 | { 154 | int offset = m_horizontalScrollValue * 20; 155 | KeyFrame *first = m_item->keyframes()->value(m_propertyName); 156 | for(KeyFrame *frame = first; frame != NULL; frame = frame->next()) 157 | { 158 | int pos = frame->time() / 5 - 6; 159 | if(ev->pos().x() + offset >= pos && ev->pos().x() + offset <= pos + 11) 160 | { 161 | isOverKeyframe = true; 162 | break; 163 | } 164 | } 165 | } 166 | if(isOverKeyframe) 167 | setCursor(Qt::SizeHorCursor); 168 | else 169 | setCursor(Qt::ArrowCursor); 170 | } 171 | 172 | void TransitionLine::mouseReleaseEvent(QMouseEvent *) 173 | { 174 | m_pressed = false; 175 | } 176 | 177 | void TransitionLine::onCustomContextMenu(const QPoint &point) 178 | { 179 | KeyFrame *first = m_item->keyframes()->value(m_propertyName); 180 | for(KeyFrame *frame = first; frame != NULL; frame = frame->next()) 181 | { 182 | int pos = frame->time() / 5 - 6; 183 | if(point.x() + m_horizontalScrollValue * 20 >= pos && point.x() + m_horizontalScrollValue * 20 <= pos + 11) 184 | { 185 | m_frame = frame; 186 | m_contextMenu->clear(); 187 | m_contextMenu->addAction(m_delKeyframeAct); 188 | if(frame->prev() && frame->prev()->easing() < 0) 189 | m_contextMenu->addAction(m_transitionAct); 190 | m_contextMenu->exec(this->mapToGlobal(point)); 191 | break; 192 | } 193 | if(point.x() + m_horizontalScrollValue * 20 > pos + 11 && frame->next() && frame->easing() >=0 && point.x() + m_horizontalScrollValue * 20 < frame->next()->time() / 5 - 6) 194 | { 195 | m_frame = frame; 196 | m_contextMenu->clear(); 197 | m_contextMenu->addAction(m_delTransitionAct); 198 | m_contextMenu->exec(this->mapToGlobal(point)); 199 | break; 200 | } 201 | } 202 | } 203 | 204 | void TransitionLine::addTransition() 205 | { 206 | emit addTransition(m_item, m_propertyName, m_frame->prev()); 207 | update(); 208 | } 209 | 210 | void TransitionLine::deleteKeyframe() 211 | { 212 | emit deleteKeyframe(m_item, m_propertyName, m_frame); 213 | update(); 214 | } 215 | 216 | void TransitionLine::deleteTransition() 217 | { 218 | //m_frame->setEasing(-1); 219 | emit deleteTransition(m_item, m_propertyName, m_frame); 220 | update(); 221 | } 222 | -------------------------------------------------------------------------------- /transitionpanel.cpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** Copyright (C) 2016 Olaf Japp 3 | ** 4 | ** This file is part of AnimationMaker. 5 | ** 6 | ** AnimationMaker is free software: you can redistribute it and/or modify 7 | ** it under the terms of the GNU General Public License as published by 8 | ** the Free Software Foundation, either version 3 of the License, or 9 | ** (at your option) any later version. 10 | ** 11 | ** AnimationMaker is distributed in the hope that it will be useful, 12 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | ** GNU General Public License for more details. 15 | ** 16 | ** You should have received a copy of the GNU General Public License 17 | ** along with AnimationMaker. If not, see . 18 | ** 19 | ****************************************************************************/ 20 | 21 | #include "transitionpanel.h" 22 | #include "keyframe.h" 23 | #include "transitionline.h" 24 | #include "timeline.h" 25 | 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | 32 | TransitionPanel::TransitionPanel() 33 | { 34 | m_verticalScrollPos = 0; 35 | m_horizontalScrollPos = 0; 36 | setSizePolicy(QSizePolicy ::Expanding , QSizePolicy ::Expanding ); 37 | setMinimumWidth(100); 38 | setMinimumHeight(50); 39 | 40 | m_layout = new QVBoxLayout(); 41 | m_layout->setMargin(1); 42 | m_layout->setSpacing(1); 43 | m_layout->addStretch(); 44 | setLayout(m_layout); 45 | 46 | m_playheadPosition = 0; 47 | } 48 | 49 | void TransitionPanel::setTreeWidget(QTreeWidget *tv) 50 | { 51 | m_tree = tv; 52 | } 53 | 54 | void TransitionPanel::paintEvent(QPaintEvent *) 55 | { 56 | QPainter painter(this); 57 | QColor gray = QColor(64, 66, 68); 58 | 59 | int width = size().width(); 60 | int height = size().height(); 61 | int offset = m_horizontalScrollPos * 20; 62 | 63 | painter.setPen(QColor(41, 41, 41)); 64 | painter.fillRect(0, 0, width, height, gray); 65 | painter.drawRect(0, 0, width-1, height-1); 66 | painter.setPen(QColor(41, 41, 41)); 67 | for(int k = 200 - offset; k < width; k+=200) 68 | { 69 | painter.drawLine(k, 0, k, height); 70 | } 71 | 72 | painter.setPen(Qt::red); 73 | painter.drawLine(m_playheadPosition / 5 - offset, 1, m_playheadPosition / 5 - offset, height - 1); 74 | } 75 | 76 | void TransitionPanel::reset() 77 | { 78 | QLayoutItem *item; 79 | while((item = m_layout->takeAt(0))) 80 | { 81 | if(item->widget()) 82 | delete item->widget(); 83 | delete item; 84 | } 85 | m_layout->addStretch(); 86 | } 87 | 88 | void TransitionPanel::enableDisableLines() 89 | { 90 | for(int i = 0; i < m_layout->count(); i++) 91 | { 92 | TransitionLine *line = dynamic_cast(m_layout->itemAt(i)->widget()); 93 | if(line) 94 | line->setVisible(false); 95 | } 96 | 97 | int row = 0; 98 | int rows = m_tree->topLevelItemCount(); 99 | for(int i = 0; i < rows; i++) 100 | { 101 | QTreeWidgetItem *treeItem = m_tree->topLevelItem(i); 102 | ResizeableItem *item = (ResizeableItem *) treeItem->data(0, 1).value(); 103 | TransitionLine *line = getTransitionLine(item, ""); 104 | if(line) 105 | { 106 | if(m_verticalScrollPos <= row) 107 | line->setVisible(true); 108 | row++; 109 | if((row + 1 - m_verticalScrollPos) * 18 > height()) 110 | return; 111 | } 112 | if(treeItem->isExpanded()) 113 | { 114 | for(int j = 0; j < treeItem->childCount(); j++) 115 | { 116 | QTreeWidgetItem *childItem = treeItem->child(j); 117 | TransitionLine *line = getTransitionLine(item, childItem->text(0)); 118 | if(line) 119 | { 120 | if(m_verticalScrollPos <= row) 121 | line->setVisible(true); 122 | row++; 123 | if((row + 1 - m_verticalScrollPos) * 18 > height()) 124 | return; 125 | } 126 | } 127 | } 128 | } 129 | } 130 | 131 | TransitionLine *TransitionPanel::getTransitionLine(ResizeableItem *item, QString propertyName) 132 | { 133 | for(int i = 0; i < m_layout->count(); i++) 134 | { 135 | TransitionLine *line = dynamic_cast(m_layout->itemAt(i)->widget()); 136 | if(line && line->propertyName() == propertyName && line->item() == item) 137 | return line; 138 | } 139 | return NULL; 140 | } 141 | 142 | void TransitionPanel::treeExpanded(QModelIndex) 143 | { 144 | enableDisableLines(); 145 | } 146 | 147 | void TransitionPanel::treeCollapsed(QModelIndex) 148 | { 149 | enableDisableLines(); 150 | } 151 | 152 | void TransitionPanel::treeScrollValueChanged(int to) 153 | { 154 | m_verticalScrollPos = to; 155 | enableDisableLines(); 156 | } 157 | 158 | void TransitionPanel::scrollValueChanged(int pos) 159 | { 160 | m_horizontalScrollPos = pos; 161 | for(int i = 0; i < m_layout->count(); i++) 162 | { 163 | TransitionLine *line = dynamic_cast(m_layout->itemAt(i)->widget()); 164 | if(line) 165 | line->setScrollValue(pos); 166 | } 167 | update(); 168 | } 169 | 170 | void TransitionPanel::keyframeAdded(ResizeableItem *item, QString propertyName) 171 | { 172 | if(item) 173 | { 174 | TransitionLine *line = new TransitionLine(item, propertyName); 175 | line->setScrollValue(m_horizontalScrollPos); 176 | m_layout->insertWidget(m_layout->count() - 1, line); 177 | connect(line, SIGNAL(deleteKeyframe(ResizeableItem*,QString,KeyFrame*)), m_timeline, SLOT(deleteKeyFrameSlot(ResizeableItem*,QString,KeyFrame*))); 178 | connect(line, SIGNAL(deleteTransition(ResizeableItem*,QString,KeyFrame*)), m_timeline, SLOT(deleteTransitionSlot(ResizeableItem*,QString,KeyFrame*))); 179 | connect(line, SIGNAL(addTransition(ResizeableItem*,QString,KeyFrame*)), m_timeline, SLOT(addTransitionSlot(ResizeableItem*,QString,KeyFrame*))); 180 | enableDisableLines(); 181 | } 182 | else 183 | update(); 184 | } 185 | 186 | void TransitionPanel::transitionAdded(ResizeableItem *item, QString propertyName) 187 | { 188 | for(int i = 0; i < m_layout->count(); i++) 189 | { 190 | TransitionLine *line = dynamic_cast(m_layout->itemAt(i)->widget()); 191 | if(line && line->propertyName() == propertyName && line->item() == item) 192 | { 193 | line->update(); 194 | break; 195 | } 196 | } 197 | } 198 | 199 | 200 | void TransitionPanel::transitionDeleted(ResizeableItem *item, QString propertyName) 201 | { 202 | for(int i = 0; i < m_layout->count(); i++) 203 | { 204 | TransitionLine *line = dynamic_cast(m_layout->itemAt(i)->widget()); 205 | if(line && line->propertyName() == propertyName && line->item() == item) 206 | { 207 | line->update(); 208 | break; 209 | } 210 | } 211 | } 212 | 213 | void TransitionPanel::keyframeDeleted(ResizeableItem *item, QString propertyName) 214 | { 215 | if(!item->keyframes()->value(propertyName)) 216 | { 217 | for(int i = 0; i < m_layout->count(); i++) 218 | { 219 | TransitionLine *line = dynamic_cast(m_layout->itemAt(i)->widget()); 220 | if(line) 221 | { 222 | if(line->propertyName() == propertyName && line->item() == item) 223 | { 224 | m_layout->removeWidget(line); 225 | break; 226 | } 227 | } 228 | } 229 | } 230 | enableDisableLines(); 231 | update(); 232 | } 233 | 234 | void TransitionPanel::resizeEvent(QResizeEvent *) 235 | { 236 | enableDisableLines(); 237 | } 238 | 239 | void TransitionPanel::setPlayheadPosition(int value) 240 | { 241 | for(int i = 0; i < m_layout->count(); i++) 242 | { 243 | TransitionLine *line = dynamic_cast(m_layout->itemAt(i)->widget()); 244 | if(line) 245 | line->setPlayheadPosition(value); 246 | } 247 | m_playheadPosition = value; 248 | update(); 249 | } 250 | 251 | void TransitionPanel::removeItem(ResizeableItem *item) 252 | { 253 | for(int i = m_layout->count() - 1; i >= 0; i--) 254 | { 255 | TransitionLine *line = dynamic_cast(m_layout->itemAt(i)->widget()); 256 | if(line && line->item() == item) 257 | { 258 | m_layout->removeWidget(line); 259 | delete line; 260 | } 261 | } 262 | } 263 | -------------------------------------------------------------------------------- /encode.cpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** Copyright (C) 2016 Olaf Japp 3 | ** 4 | ** This file is part of AnimationMaker. 5 | ** 6 | ** AnimationMaker is free software: you can redistribute it and/or modify 7 | ** it under the terms of the GNU General Public License as published by 8 | ** the Free Software Foundation, either version 3 of the License, or 9 | ** (at your option) any later version. 10 | ** 11 | ** AnimationMaker is distributed in the hope that it will be useful, 12 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | ** GNU General Public License for more details. 15 | ** 16 | ** You should have received a copy of the GNU General Public License 17 | ** along with AnimationMaker. If not, see . 18 | ** 19 | ****************************************************************************/ 20 | 21 | #include 22 | #include "mainwindow.h" 23 | #include "exception.h" 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | 30 | #include 31 | #include 32 | #include 33 | 34 | extern "C" 35 | { 36 | #include 37 | #include 38 | #include 39 | #include 40 | #include 41 | #include 42 | #include 43 | #include 44 | #include 45 | #include 46 | #include 47 | #include 48 | #include 49 | } 50 | 51 | typedef struct OutputStream 52 | { 53 | AVStream *st; 54 | AVCodecContext *enc; 55 | int64_t next_pts; 56 | int samples_count; 57 | AVFrame *frame; 58 | float t, tincr, tincr2; 59 | struct SwsContext *sws_ctx; 60 | struct SwrContext *swr_ctx; 61 | } OutputStream; 62 | 63 | static AVFrame *alloc_picture(enum AVPixelFormat pix_fmt, int width, int height) 64 | { 65 | AVFrame *picture; 66 | int ret; 67 | picture = av_frame_alloc(); 68 | if (!picture) 69 | throw new Exception("Could not allocate frame data."); 70 | picture->format = pix_fmt; 71 | picture->width = width; 72 | picture->height = height; 73 | 74 | ret = av_frame_get_buffer(picture, 32); 75 | if (ret < 0) 76 | throw new Exception("Could not allocate frame data."); 77 | 78 | return picture; 79 | } 80 | 81 | static void add_stream(OutputStream *ost, AVFormatContext *oc, AVCodec **codec, enum AVCodecID codec_id, int fps, int width, int height) 82 | { 83 | AVCodecContext *c; 84 | 85 | *codec = avcodec_find_encoder(codec_id); 86 | if (!(*codec)) 87 | throw new Exception(QString("Could not find encoder for ") + avcodec_get_name(codec_id)); 88 | 89 | ost->st = avformat_new_stream(oc, NULL); 90 | if (!ost->st) 91 | throw new Exception("Could not allocate stream"); 92 | 93 | ost->st->id = oc->nb_streams-1; 94 | c = avcodec_alloc_context3(*codec); 95 | if (!c) 96 | throw new Exception("Could not alloc an encoding context"); 97 | 98 | ost->enc = c; 99 | switch ((*codec)->type) 100 | { 101 | 102 | case AVMEDIA_TYPE_VIDEO: 103 | c->codec_id = codec_id; 104 | c->bit_rate = 1600000;//400000; 105 | c->width = width; 106 | c->height = height; 107 | ost->st->time_base = (AVRational){ 1, fps }; 108 | c->time_base = ost->st->time_base; 109 | c->gop_size = 12; 110 | c->pix_fmt = AV_PIX_FMT_YUV420P; 111 | if (c->codec_id == AV_CODEC_ID_MPEG2VIDEO) 112 | { 113 | c->max_b_frames = 2; 114 | } 115 | if (c->codec_id == AV_CODEC_ID_MPEG1VIDEO) 116 | { 117 | c->mb_decision = 2; 118 | } 119 | break; 120 | default: 121 | break; 122 | } 123 | if (oc->oformat->flags & AVFMT_GLOBALHEADER) 124 | c->flags |= AV_CODEC_FLAG_GLOBAL_HEADER; 125 | } 126 | 127 | static void open_video(AVCodec *codec, OutputStream *ost, AVDictionary *opt_arg) 128 | { 129 | int ret; 130 | AVCodecContext *c = ost->enc; 131 | AVDictionary *opt = NULL; 132 | 133 | av_dict_copy(&opt, opt_arg, 0); 134 | ret = avcodec_open2(c, codec, &opt); 135 | av_dict_free(&opt); 136 | if (ret < 0) 137 | throw new Exception("Could not open video codec"); 138 | 139 | ost->frame = alloc_picture(c->pix_fmt, c->width, c->height); 140 | if (!ost->frame) 141 | throw new Exception("Could not allocate video frame"); 142 | 143 | ret = avcodec_parameters_from_context(ost->st->codecpar, c); 144 | if (ret < 0) 145 | throw new Exception("Could not copy the stream parameters"); 146 | } 147 | 148 | static AVFrame *get_video_frame(OutputStream *ost, QImage img) 149 | { 150 | AVCodecContext *c = ost->enc; 151 | 152 | if (av_frame_make_writable(ost->frame) < 0) 153 | throw new Exception("Could not make frame writeable"); 154 | 155 | uint8_t * inData[1] = { img.bits() }; 156 | int inLinesize[1] = { 4 * c->width }; 157 | 158 | if (!ost->sws_ctx) 159 | { 160 | ost->sws_ctx = sws_getContext(c->width, c->height, AV_PIX_FMT_BGRA, c->width, c->height, c->pix_fmt, SWS_BICUBIC, NULL, NULL, NULL); 161 | if (!ost->sws_ctx) 162 | throw new Exception("Could not initialize the conversion context"); 163 | } 164 | sws_scale(ost->sws_ctx, (const uint8_t * const *)inData, inLinesize, 0, c->height, ost->frame->data, ost->frame->linesize); 165 | 166 | ost->frame->pts = ost->next_pts++; 167 | 168 | return ost->frame; 169 | } 170 | 171 | static void close_stream(OutputStream *ost) 172 | { 173 | avcodec_free_context(&ost->enc); 174 | av_frame_free(&ost->frame); 175 | sws_freeContext(ost->sws_ctx); 176 | swr_free(&ost->swr_ctx); 177 | } 178 | 179 | static int write_frame(AVFormatContext *fmt_ctx, const AVRational *time_base, AVStream *st, AVPacket *pkt) 180 | { 181 | av_packet_rescale_ts(pkt, *time_base, st->time_base); 182 | pkt->stream_index = st->index; 183 | return av_interleaved_write_frame(fmt_ctx, pkt); 184 | } 185 | 186 | static int write_video_frame(AVFormatContext *oc, OutputStream *ost, QImage img) 187 | { 188 | int ret; 189 | AVCodecContext *c; 190 | AVFrame *frame; 191 | int got_packet = 0; 192 | AVPacket pkt = { 0 }; 193 | c = ost->enc; 194 | frame = get_video_frame(ost, img); 195 | av_init_packet(&pkt); 196 | ret = avcodec_encode_video2(c, &pkt, frame, &got_packet); 197 | if (ret < 0) 198 | throw new Exception("Error encoding video frame"); 199 | 200 | if (got_packet) 201 | { 202 | ret = write_frame(oc, &c->time_base, ost->st, &pkt); 203 | } 204 | else 205 | { 206 | ret = 0; 207 | } 208 | if (ret < 0) 209 | throw new Exception("Error while writing video frame"); 210 | 211 | return (frame || got_packet) ? 0 : 1; 212 | } 213 | 214 | int video_encode(const char *filename, QGraphicsView *view, int length, MainWindow *win, AnimationScene *scene) 215 | { 216 | AVFormatContext *oc; 217 | AVOutputFormat *fmt; 218 | AVCodec *video_codec; 219 | OutputStream video_st = { 0 }; 220 | int ret; 221 | AVDictionary *opt = NULL; 222 | 223 | av_register_all(); 224 | 225 | avformat_alloc_output_context2(&oc, NULL, NULL, filename); 226 | if (!oc) 227 | { 228 | //printf("Could not deduce output format from file extension: using MPEG.\n"); 229 | avformat_alloc_output_context2(&oc, NULL, "mpeg", filename); 230 | } 231 | if (!oc) 232 | throw new Exception("Unable to allocate context"); 233 | fmt = oc->oformat; 234 | if (fmt->video_codec != AV_CODEC_ID_NONE) 235 | { 236 | add_stream(&video_st, oc, &video_codec, fmt->video_codec, scene->fps(), view->width(), view->height()); 237 | } 238 | 239 | open_video(video_codec, &video_st, opt); 240 | if (!(fmt->flags & AVFMT_NOFILE)) 241 | { 242 | ret = avio_open(&oc->pb, filename, AVIO_FLAG_WRITE); 243 | if (ret < 0) 244 | throw new Exception(QString("Could not open '%1'").arg(filename)); 245 | 246 | } 247 | ret = avformat_write_header(oc, &opt); 248 | if (ret < 0) 249 | throw new Exception("Error occurred when opening output file"); 250 | 251 | int delay = 1000 / scene->fps(); 252 | int frames = length / delay + 2; 253 | 254 | for (int i = 0; i < frames; i++) 255 | { 256 | win->statusBar()->showMessage(QString("Writing frame %1 of %2 frames").arg(i).arg(frames)); 257 | 258 | scene->setPlayheadPosition(i * delay); 259 | QTest::qSleep(delay); 260 | QCoreApplication::processEvents(QEventLoop::AllEvents, delay); 261 | 262 | QImage img = view->grab().toImage(); 263 | 264 | write_video_frame(oc, &video_st, img); 265 | } 266 | av_write_trailer(oc); 267 | close_stream(&video_st); 268 | if (!(fmt->flags & AVFMT_NOFILE)) 269 | avio_closep(&oc->pb); 270 | avformat_free_context(oc); 271 | win->statusBar()->showMessage(QString("Ready")); 272 | 273 | return 0; 274 | } 275 | -------------------------------------------------------------------------------- /coloreditor.cpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** Copyright (C) 2016 Olaf Japp 3 | ** 4 | ** This file is part of AnimationMaker. 5 | ** 6 | ** AnimationMaker is free software: you can redistribute it and/or modify 7 | ** it under the terms of the GNU General Public License as published by 8 | ** the Free Software Foundation, either version 3 of the License, or 9 | ** (at your option) any later version. 10 | ** 11 | ** AnimationMaker is distributed in the hope that it will be useful, 12 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | ** GNU General Public License for more details. 15 | ** 16 | ** You should have received a copy of the GNU General Public License 17 | ** along with AnimationMaker. If not, see . 18 | ** 19 | ****************************************************************************/ 20 | 21 | #include "coloreditor.h" 22 | 23 | #include 24 | #include 25 | 26 | ColorEditor::ColorEditor(QString label) 27 | { 28 | QGridLayout *layout = new QGridLayout(); 29 | m_color = new QLineEdit(); 30 | m_colorPicker = new ColorPicker(); 31 | m_colorPicker->setVisible(false); 32 | m_hueSlider = new QSlider(); 33 | m_hueSlider->setVisible(false); 34 | m_hueSlider->setMinimum(0); 35 | m_hueSlider->setMaximum(100); 36 | m_hueSlider->setOrientation(Qt::Vertical); 37 | m_hueSlider->setMaximumHeight(100); 38 | m_rect = new ColorRect(); 39 | m_hue = new QSpinBox(); 40 | m_saturation = new QSpinBox(); 41 | m_lightness = new QSpinBox(); 42 | m_labelHue = new QLabel("H"); 43 | m_labelSaturation = new QLabel("S"); 44 | m_labelLightness = new QLabel("L"); 45 | m_red = new QSpinBox(); 46 | m_green = new QSpinBox(); 47 | m_blue = new QSpinBox(); 48 | m_labelRed = new QLabel("R"); 49 | m_labelGreen = new QLabel("G"); 50 | m_labelBlue = new QLabel("B"); 51 | m_hue->setVisible(false); 52 | m_saturation->setVisible(false); 53 | m_lightness->setVisible(false); 54 | m_red->setVisible(false); 55 | m_green->setVisible(false); 56 | m_blue->setVisible(false); 57 | m_labelHue->setVisible(false); 58 | m_labelSaturation->setVisible(false); 59 | m_labelLightness->setVisible(false); 60 | m_labelRed->setVisible(false); 61 | m_labelGreen->setVisible(false); 62 | m_labelBlue->setVisible(false); 63 | m_red->setMinimum(0); 64 | m_red->setMaximum(255); 65 | m_green->setMinimum(0); 66 | m_green->setMaximum(255); 67 | m_blue->setMinimum(0); 68 | m_blue->setMaximum(255); 69 | m_hue->setMinimum(0); 70 | m_hue->setMaximum(100); 71 | m_saturation->setMinimum(0); 72 | m_saturation->setMaximum(100); 73 | m_lightness->setMinimum(0); 74 | m_lightness->setMaximum(100); 75 | m_labelHue->setFixedWidth(15); 76 | m_labelSaturation->setFixedWidth(15); 77 | m_labelLightness->setFixedWidth(15); 78 | m_labelRed->setFixedWidth(15); 79 | m_labelGreen->setFixedWidth(15); 80 | m_labelBlue->setFixedWidth(15); 81 | layout->addWidget(new QLabel(label), 0, 0); 82 | layout->addWidget(m_rect, 0, 1); 83 | layout->addWidget(m_color, 0, 2, 1, 4); 84 | layout->addWidget(m_colorPicker, 1, 0, 3, 1); 85 | layout->addWidget(m_hueSlider, 1, 1, 3, 1); 86 | layout->addWidget(m_labelHue, 1, 2); 87 | layout->addWidget(m_hue, 1, 3); 88 | layout->addWidget(m_labelSaturation, 2, 2); 89 | layout->addWidget(m_saturation, 2, 3); 90 | layout->addWidget(m_labelLightness, 3, 2); 91 | layout->addWidget(m_lightness, 3, 3); 92 | layout->addWidget(m_labelRed, 1, 4); 93 | layout->addWidget(m_red, 1, 5); 94 | layout->addWidget(m_labelGreen, 2, 4); 95 | layout->addWidget(m_green, 2, 5); 96 | layout->addWidget(m_labelBlue, 3, 4); 97 | layout->addWidget(m_blue, 3, 5); 98 | setLayout(layout); 99 | 100 | connectControls(); 101 | } 102 | 103 | void ColorEditor::setColor(QColor color) 104 | { 105 | setColorParts(color); 106 | } 107 | 108 | void ColorEditor::disconnectControls() 109 | { 110 | disconnect(m_color, SIGNAL(textChanged(QString)), this, SLOT(colorTextChanged(QString))); 111 | disconnect(m_hueSlider, SIGNAL(valueChanged(int)), this, SLOT(hueChanged(int))); 112 | disconnect(m_hueSlider, SIGNAL(sliderReleased()), this, SLOT(huePicked())); 113 | disconnect(m_colorPicker, SIGNAL(colorChanged(QColor)), this, SLOT(colorPickerChanged(QColor))); 114 | disconnect(m_colorPicker, SIGNAL(colorPicked(QColor)), this, SLOT(colorPicked(QColor))); 115 | disconnect(m_rect, SIGNAL(mouseClicked()), this, SLOT(rectClicked())); 116 | disconnect(m_hue, SIGNAL(valueChanged(int)), this, SLOT(hueValueChanged(int))); 117 | disconnect(m_saturation, SIGNAL(valueChanged(int)), this, SLOT(saturationValueChanged(int))); 118 | disconnect(m_lightness, SIGNAL(valueChanged(int)), this, SLOT(lightnessValueChanged(int))); 119 | disconnect(m_red, SIGNAL(valueChanged(int)), this, SLOT(redValueChanged(int))); 120 | disconnect(m_green, SIGNAL(valueChanged(int)), this, SLOT(greenValueChanged(int))); 121 | disconnect(m_blue, SIGNAL(valueChanged(int)), this, SLOT(blueValueChanged(int))); 122 | } 123 | 124 | void ColorEditor::connectControls() 125 | { 126 | connect(m_color, SIGNAL(textChanged(QString)), this, SLOT(colorTextChanged(QString))); 127 | connect(m_hueSlider, SIGNAL(valueChanged(int)), this, SLOT(hueChanged(int))); 128 | connect(m_hueSlider, SIGNAL(sliderReleased()), this, SLOT(huePicked())); 129 | connect(m_colorPicker, SIGNAL(colorChanged(QColor)), this, SLOT(colorPickerChanged(QColor))); 130 | connect(m_colorPicker, SIGNAL(colorPicked(QColor)), this, SLOT(colorPicked(QColor))); 131 | connect(m_rect, SIGNAL(mouseClicked()), this, SLOT(rectClicked())); 132 | connect(m_hue, SIGNAL(valueChanged(int)), this, SLOT(hueValueChanged(int))); 133 | connect(m_saturation, SIGNAL(valueChanged(int)), this, SLOT(saturationValueChanged(int))); 134 | connect(m_lightness, SIGNAL(valueChanged(int)), this, SLOT(lightnessValueChanged(int))); 135 | connect(m_red, SIGNAL(valueChanged(int)), this, SLOT(redValueChanged(int))); 136 | connect(m_green, SIGNAL(valueChanged(int)), this, SLOT(greenValueChanged(int))); 137 | connect(m_blue, SIGNAL(valueChanged(int)), this, SLOT(blueValueChanged(int))); 138 | } 139 | 140 | void ColorEditor::rectClicked() 141 | { 142 | setExpanded(!m_colorPicker->isVisible()); 143 | } 144 | 145 | void ColorEditor::setExpanded(bool value) 146 | { 147 | m_colorPicker->setVisible(value); 148 | m_hueSlider->setVisible(value); 149 | m_labelHue->setVisible(value); 150 | m_labelSaturation->setVisible(value); 151 | m_labelLightness->setVisible(value); 152 | m_hue->setVisible(value); 153 | m_saturation->setVisible(value); 154 | m_lightness->setVisible(value); 155 | m_labelRed->setVisible(value); 156 | m_labelGreen->setVisible(value); 157 | m_labelBlue->setVisible(value); 158 | m_red->setVisible(value); 159 | m_green->setVisible(value); 160 | m_blue->setVisible(value); 161 | } 162 | 163 | bool ColorEditor::isExpanded() 164 | { 165 | return m_colorPicker->isVisible(); 166 | } 167 | 168 | void ColorEditor::setColorParts(QColor value) 169 | { 170 | disconnectControls(); 171 | m_hue->setValue(value.hslHueF() * 100); 172 | m_hueSlider->setValue(value.hslHueF() * 100); 173 | m_colorPicker->setHue(value.hslHueF()); 174 | m_saturation->setValue(value.hslSaturationF() * 100); 175 | m_lightness->setValue(value.lightnessF() * 100); 176 | m_red->setValue(value.red()); 177 | m_green->setValue(value.green()); 178 | m_blue->setValue(value.blue()); 179 | m_color->setText(value.name()); 180 | m_rect->setColor(value); 181 | connectControls(); 182 | } 183 | 184 | void ColorEditor::colorTextChanged(QString value) 185 | { 186 | QColor color = QColor(value); 187 | setColorParts(color); 188 | emit colorChanged(color); 189 | } 190 | 191 | void ColorEditor::colorPicked(QColor value) 192 | { 193 | setColorParts(value); 194 | emit colorChanged(value); 195 | } 196 | 197 | void ColorEditor::colorPickerChanged(QColor value) 198 | { 199 | setColorParts(value); 200 | } 201 | 202 | void ColorEditor::hueChanged(int value) 203 | { 204 | m_colorPicker->setHue((qreal)value / 100.0); 205 | QColor color = QColor::fromHslF((qreal)value / 100, (qreal)m_saturation->value() / 100, (qreal)m_lightness->value() / 100, 1.0); 206 | setColorParts(color); 207 | } 208 | 209 | void ColorEditor::hueValueChanged(int value) 210 | { 211 | m_hueSlider->setValue(value); 212 | QColor color = QColor::fromHslF((qreal)value / 100, (qreal)m_saturation->value() / 100, (qreal)m_lightness->value() / 100, 1.0); 213 | setColorParts(color); 214 | emit colorChanged(color); 215 | } 216 | 217 | void ColorEditor::huePicked() 218 | { 219 | int value = m_hueSlider->value(); 220 | m_colorPicker->setHue((qreal)value / 100.0); 221 | QColor color = QColor::fromHslF((qreal)value / 100, (qreal)m_saturation->value() / 100, (qreal)m_lightness->value() / 100, 1.0); 222 | setColorParts(color); 223 | emit colorChanged(color); 224 | } 225 | 226 | void ColorEditor::saturationValueChanged(int value) 227 | { 228 | QColor color = QColor::fromHslF((qreal)m_hue->value() / 100, (qreal)value / 100, (qreal)m_lightness->value() / 100, 1.0); 229 | setColorParts(color); 230 | emit colorChanged(color); 231 | } 232 | 233 | void ColorEditor::lightnessValueChanged(int value) 234 | { 235 | QColor color = QColor::fromHslF((qreal)m_hue->value() / 100, (qreal)m_saturation->value() / 100, (qreal)value / 100, 1.0); 236 | setColorParts(color); 237 | emit colorChanged(color); 238 | } 239 | 240 | void ColorEditor::redValueChanged(int value) 241 | { 242 | QColor color = QColor::fromRgb(value, m_green->value(), m_blue->value()); 243 | setColorParts(color); 244 | emit colorChanged(color); 245 | } 246 | 247 | void ColorEditor::greenValueChanged(int value) 248 | { 249 | QColor color = QColor::fromRgb(m_red->value(), value, m_blue->value()); 250 | setColorParts(color); 251 | emit colorChanged(color); 252 | } 253 | 254 | void ColorEditor::blueValueChanged(int value) 255 | { 256 | QColor color = QColor::fromRgb(m_red->value(), m_green->value(), value); 257 | setColorParts(color); 258 | emit colorChanged(color); 259 | } 260 | -------------------------------------------------------------------------------- /commands.cpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** Copyright (C) 2016 Olaf Japp 3 | ** 4 | ** This file is part of AnimationMaker. 5 | ** 6 | ** AnimationMaker is free software: you can redistribute it and/or modify 7 | ** it under the terms of the GNU General Public License as published by 8 | ** the Free Software Foundation, either version 3 of the License, or 9 | ** (at your option) any later version. 10 | ** 11 | ** AnimationMaker is distributed in the hope that it will be useful, 12 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | ** GNU General Public License for more details. 15 | ** 16 | ** You should have received a copy of the GNU General Public License 17 | ** along with AnimationMaker. If not, see . 18 | ** 19 | ****************************************************************************/ 20 | 21 | #include "commands.h" 22 | #include "rectangle.h" 23 | #include "ellipse.h" 24 | #include "text.h" 25 | #include "bitmap.h" 26 | #include "vectorgraphic.h" 27 | 28 | AddItemCommand::AddItemCommand(qreal x, qreal y, AnimationScene::EditMode mode, QString fileName, AnimationScene *scene, QUndoCommand *parent) 29 | : QUndoCommand(parent) 30 | { 31 | m_scene = scene; 32 | switch(mode) 33 | { 34 | case AnimationScene::EditMode::ModeRectangle: 35 | { 36 | m_item = new Rectangle(50, 50, m_scene); 37 | m_item->setId("Rectangle"); 38 | m_item->setPen(QPen(Qt::black)); 39 | m_item->setBrush(QBrush(Qt::blue)); 40 | m_item->setFlag(QGraphicsItem::ItemIsMovable, true); 41 | m_item->setFlag(QGraphicsItem::ItemIsSelectable, true); 42 | m_item->setPos(x, y); 43 | setText(QObject::tr("Add Rectangle")); 44 | break; 45 | } 46 | case AnimationScene::EditMode::ModeEllipse: 47 | { 48 | m_item = new Ellipse(50, 50, m_scene); 49 | m_item->setId("Ellipse"); 50 | m_item->setPen(QPen(Qt::black)); 51 | m_item->setBrush(QBrush(Qt::blue)); 52 | m_item->setFlag(QGraphicsItem::ItemIsMovable, true); 53 | m_item->setFlag(QGraphicsItem::ItemIsSelectable, true); 54 | m_item->setPos(x, y); 55 | setText(QObject::tr("Add Ellipse")); 56 | break; 57 | } 58 | case AnimationScene::EditMode::ModeText: 59 | { 60 | m_item = new Text("Lorem ipsum dolor", m_scene); 61 | m_item->setId("Text"); 62 | m_item->setFlag(QGraphicsItem::ItemIsMovable, true); 63 | m_item->setFlag(QGraphicsItem::ItemIsSelectable, true); 64 | m_item->setPos(x, y); 65 | setText(QObject::tr("Add Text")); 66 | break; 67 | } 68 | case AnimationScene::EditMode::ModeBitmap: 69 | { 70 | m_item = new Bitmap(fileName, m_scene); 71 | m_item->setId("Bitmap"); 72 | m_item->setFlag(QGraphicsItem::ItemIsMovable, true); 73 | m_item->setFlag(QGraphicsItem::ItemIsSelectable, true); 74 | m_item->setPos(x, y); 75 | setText(QObject::tr("Add Bitmap")); 76 | break; 77 | } 78 | case AnimationScene::EditMode::ModeSvg: 79 | { 80 | m_item = new Vectorgraphic(fileName, m_scene); 81 | m_item->setId("Vectorgraphic"); 82 | m_item->setFlag(QGraphicsItem::ItemIsMovable, true); 83 | m_item->setFlag(QGraphicsItem::ItemIsSelectable, true); 84 | m_item->setPos(x, y); 85 | setText(QObject::tr("Add Vectorgraphic")); 86 | break; 87 | } 88 | } 89 | } 90 | 91 | void AddItemCommand::undo() 92 | { 93 | m_scene->clearSelection(); 94 | m_scene->removeItem(m_item); 95 | emit m_scene->itemRemoved(m_item); 96 | } 97 | 98 | void AddItemCommand::redo() 99 | { 100 | m_scene->clearSelection(); 101 | m_scene->addItem(m_item); 102 | emit m_scene->itemAdded(m_item); 103 | } 104 | 105 | 106 | DeleteItemCommand::DeleteItemCommand(ResizeableItem *item, AnimationScene *scene, QUndoCommand *parent) 107 | : QUndoCommand(parent) 108 | { 109 | m_scene = scene; 110 | m_item = item; 111 | setText("Delete " + getItemTypeName(item)); 112 | } 113 | 114 | void DeleteItemCommand::undo() 115 | { 116 | m_scene->clearSelection(); 117 | m_scene->addItem(m_item); 118 | emit m_scene->itemAdded(m_item); 119 | } 120 | 121 | void DeleteItemCommand::redo() 122 | { 123 | m_scene->clearSelection(); 124 | m_scene->removeItem(m_item); 125 | emit m_scene->itemRemoved(m_item); 126 | } 127 | 128 | MoveItemCommand::MoveItemCommand(qreal x, qreal y, qreal oldx, qreal oldy, AnimationScene *scene, ResizeableItem *item, QUndoCommand *parent) 129 | : QUndoCommand(parent) 130 | { 131 | m_x = x; 132 | m_y = y; 133 | m_oldx = oldx; 134 | m_oldy = oldy; 135 | m_time = scene->playheadPosition(); 136 | m_autokeyframes = scene->autokeyframes(); 137 | m_autotransition = scene->autotransition(); 138 | m_item = item; 139 | setText("Move " + getItemTypeName(item)); 140 | } 141 | 142 | void MoveItemCommand::undo() 143 | { 144 | m_item->setPos(m_oldx, m_oldy); 145 | m_item->adjustKeyframes("left", QVariant(m_oldx), m_time, m_autokeyframes, m_autotransition); 146 | m_item->adjustKeyframes("top", QVariant(m_oldy), m_time, m_autokeyframes, m_autotransition); 147 | } 148 | 149 | void MoveItemCommand::redo() 150 | { 151 | m_item->setPos(m_x, m_y); 152 | m_item->adjustKeyframes("left", QVariant(m_x), m_time, m_autokeyframes, m_autotransition); 153 | m_item->adjustKeyframes("top", QVariant(m_y), m_time, m_autokeyframes, m_autotransition); 154 | } 155 | 156 | 157 | ResizeItemCommand::ResizeItemCommand(qreal width, qreal height, qreal oldwidth, qreal oldheight, AnimationScene *scene, ResizeableItem *item, QUndoCommand *parent) 158 | : QUndoCommand(parent) 159 | { 160 | m_width = width; 161 | m_height = height; 162 | m_oldwidth = oldwidth; 163 | m_oldheight = oldheight; 164 | m_time = scene->playheadPosition(); 165 | m_autokeyframes = scene->autokeyframes(); 166 | m_autotransition = scene->autotransition(); 167 | m_item = item; 168 | setText("Resize " + getItemTypeName(item)); 169 | } 170 | 171 | void ResizeItemCommand::undo() 172 | { 173 | m_item->setWidth(m_oldwidth); 174 | m_item->setHeight(m_oldheight); 175 | m_item->adjustKeyframes("width", QVariant(m_oldwidth), m_time, m_autokeyframes, m_autotransition); 176 | m_item->adjustKeyframes("height", QVariant(m_oldheight), m_time, m_autokeyframes, m_autotransition); 177 | } 178 | 179 | void ResizeItemCommand::redo() 180 | { 181 | m_item->setWidth(m_width); 182 | m_item->setHeight(m_height); 183 | 184 | m_item->adjustKeyframes("width", QVariant(m_width), m_time, m_autokeyframes, m_autotransition); 185 | m_item->adjustKeyframes("height", QVariant(m_height), m_time, m_autokeyframes, m_autotransition); 186 | } 187 | 188 | ScaleItemCommand::ScaleItemCommand(qreal x, qreal y, qreal width, qreal height, qreal oldx, qreal oldy, qreal oldwidth, qreal oldheight, AnimationScene *scene, ResizeableItem *item, QUndoCommand *parent) 189 | : QUndoCommand(parent) 190 | { 191 | m_x = x; 192 | m_y = y; 193 | m_width = width; 194 | m_height = height; 195 | m_oldx = oldx; 196 | m_oldy = oldy; 197 | m_oldwidth = oldwidth; 198 | m_oldheight = oldheight; 199 | m_time = scene->playheadPosition(); 200 | m_autokeyframes = scene->autokeyframes(); 201 | m_autotransition = scene->autotransition(); 202 | m_item = item; 203 | setText("Scale " + getItemTypeName(item)); 204 | } 205 | 206 | void ScaleItemCommand::undo() 207 | { 208 | m_item->setPos(m_oldx, m_oldy); 209 | m_item->setWidth(m_oldwidth); 210 | m_item->setHeight(m_oldheight); 211 | m_item->adjustKeyframes("left", QVariant(m_oldx), m_time, m_autokeyframes, m_autotransition); 212 | m_item->adjustKeyframes("top", QVariant(m_oldy), m_time, m_autokeyframes, m_autotransition); 213 | m_item->adjustKeyframes("width", QVariant(m_oldwidth), m_time, m_autokeyframes, m_autotransition); 214 | m_item->adjustKeyframes("height", QVariant(m_oldheight), m_time, m_autokeyframes, m_autotransition); 215 | m_item->scaleObjects(); 216 | m_item->posChanged(m_oldx, m_oldy); 217 | } 218 | 219 | void ScaleItemCommand::redo() 220 | { 221 | m_item->setPos(m_x, m_y); 222 | m_item->setWidth(m_width); 223 | m_item->setHeight(m_height); 224 | m_item->adjustKeyframes("left", QVariant(m_x), m_time, m_autokeyframes, m_autotransition); 225 | m_item->adjustKeyframes("top", QVariant(m_y), m_time, m_autokeyframes, m_autotransition); 226 | m_item->adjustKeyframes("width", QVariant(m_width), m_time, m_autokeyframes, m_autotransition); 227 | m_item->adjustKeyframes("height", QVariant(m_height), m_time, m_autokeyframes, m_autotransition); 228 | m_item->scaleObjects(); 229 | m_item->posChanged(m_x, m_y); 230 | } 231 | 232 | ChangeIdCommand::ChangeIdCommand(QString id, QString oldid, ResizeableItem *item, QUndoCommand *parent) 233 | : QUndoCommand(parent) 234 | { 235 | m_id = id; 236 | m_oldid = oldid; 237 | m_item = item; 238 | setText("Change " + getItemTypeName(item) + " Id"); 239 | } 240 | 241 | void ChangeIdCommand::undo() 242 | { 243 | m_item->setId(m_oldid); 244 | } 245 | 246 | void ChangeIdCommand::redo() 247 | { 248 | m_item->setId(m_id); 249 | } 250 | 251 | ChangeColorCommand::ChangeColorCommand(QColor color, QColor oldcolor, ResizeableItem *item, QUndoCommand *parent) 252 | : QUndoCommand(parent) 253 | { 254 | m_color = color; 255 | m_oldcolor = oldcolor; 256 | m_item = item; 257 | setText("Change " + getItemTypeName(item) + " Color"); 258 | } 259 | 260 | void ChangeColorCommand::undo() 261 | { 262 | m_item->setBrush(QBrush(m_oldcolor)); 263 | } 264 | 265 | void ChangeColorCommand::redo() 266 | { 267 | m_item->setBrush(QBrush(m_color)); 268 | } 269 | 270 | ChangePenCommand::ChangePenCommand(QColor color, QColor oldcolor, ResizeableItem *item, QUndoCommand *parent) 271 | : QUndoCommand(parent) 272 | { 273 | m_color = color; 274 | m_oldcolor = oldcolor; 275 | m_item = item; 276 | setText("Change " + getItemTypeName(item) + " Pen"); 277 | } 278 | 279 | void ChangePenCommand::undo() 280 | { 281 | m_item->setPen(QPen(m_oldcolor)); 282 | } 283 | 284 | void ChangePenCommand::redo() 285 | { 286 | m_item->setPen(QPen(m_color)); 287 | } 288 | 289 | ChangeTextcolorCommand::ChangeTextcolorCommand(QColor color, QColor oldcolor, Text *item, QUndoCommand *parent) 290 | : QUndoCommand(parent) 291 | { 292 | m_color = color; 293 | m_oldcolor = oldcolor; 294 | m_item = item; 295 | setText("Change " + getItemTypeName(item) + " Textcolor"); 296 | } 297 | 298 | void ChangeTextcolorCommand::undo() 299 | { 300 | m_item->setTextcolor(m_oldcolor); 301 | } 302 | 303 | void ChangeTextcolorCommand::redo() 304 | { 305 | m_item->setTextcolor(m_color); 306 | } 307 | 308 | ChangeSceneColorCommand::ChangeSceneColorCommand(QColor color, QColor oldcolor, AnimationScene *scene, QUndoCommand *parent) 309 | : QUndoCommand(parent) 310 | { 311 | m_color = color; 312 | m_oldcolor = oldcolor; 313 | m_scene = scene; 314 | setText("Change Scene Color"); 315 | } 316 | 317 | void ChangeSceneColorCommand::undo() 318 | { 319 | m_scene->setBackgroundColor(m_oldcolor); 320 | } 321 | 322 | void ChangeSceneColorCommand::redo() 323 | { 324 | m_scene->setBackgroundColor(m_color); 325 | } 326 | 327 | ChangeOpacityCommand::ChangeOpacityCommand(int opacity, int oldopacity, AnimationScene *scene, ResizeableItem *item, QUndoCommand *parent) 328 | : QUndoCommand(parent) 329 | { 330 | m_opacity = opacity; 331 | m_oldopacity = oldopacity; 332 | m_time = scene->playheadPosition(); 333 | m_autokeyframes = scene->autokeyframes(); 334 | m_autotransition = scene->autotransition(); 335 | m_item = item; 336 | setText("Change " + getItemTypeName(item) + " Opacity"); 337 | } 338 | 339 | void ChangeOpacityCommand::undo() 340 | { 341 | m_item->setOpacity(m_oldopacity); 342 | m_item->adjustKeyframes("opacity", QVariant(m_oldopacity), m_time, m_autokeyframes, m_autotransition); 343 | } 344 | 345 | void ChangeOpacityCommand::redo() 346 | { 347 | m_item->setOpacity(m_opacity); 348 | m_item->adjustKeyframes("opacity", QVariant(m_opacity), m_time, m_autokeyframes, m_autotransition); 349 | } 350 | 351 | AddKeyframeCommand::AddKeyframeCommand(QString propertyName, KeyFrame *frame, ResizeableItem *item, Timeline *timeline, QUndoCommand *parent) 352 | : QUndoCommand(parent) 353 | { 354 | m_propertyName = propertyName; 355 | m_frame = frame; 356 | m_item = item; 357 | m_timeline = timeline; 358 | setText("Add " + getItemTypeName(item) + " Keyframe"); 359 | } 360 | 361 | void AddKeyframeCommand::undo() 362 | { 363 | m_timeline->deleteKeyFrame(m_item, m_propertyName, m_frame); 364 | } 365 | 366 | void AddKeyframeCommand::redo() 367 | { 368 | m_timeline->addKeyFrame(m_item, m_propertyName, m_frame); 369 | } 370 | 371 | DeleteKeyframeCommand::DeleteKeyframeCommand(QString propertyName, KeyFrame *frame, ResizeableItem *item, Timeline *timeline, QUndoCommand *parent) 372 | : QUndoCommand(parent) 373 | { 374 | m_propertyName = propertyName; 375 | m_frame = frame; 376 | m_item = item; 377 | m_timeline = timeline; 378 | setText("Delete " + getItemTypeName(item) + " Keyframe"); 379 | } 380 | 381 | void DeleteKeyframeCommand::undo() 382 | { 383 | m_timeline->addKeyFrame(m_item, m_propertyName, m_frame); 384 | } 385 | 386 | void DeleteKeyframeCommand::redo() 387 | { 388 | m_timeline->deleteKeyFrame(m_item, m_propertyName, m_frame); 389 | } 390 | 391 | AddTransitionCommand::AddTransitionCommand(QString propertyName, KeyFrame *frame, ResizeableItem *item, Timeline *timeline, QUndoCommand *parent) 392 | : QUndoCommand(parent) 393 | { 394 | m_propertyName = propertyName; 395 | m_frame = frame; 396 | m_item = item; 397 | m_timeline = timeline; 398 | setText("Add " + getItemTypeName(item) + " Transition"); 399 | } 400 | 401 | void AddTransitionCommand::undo() 402 | { 403 | m_timeline->deleteTransition(m_item, m_propertyName, m_frame); 404 | } 405 | 406 | void AddTransitionCommand::redo() 407 | { 408 | m_timeline->addTransition(m_item, m_propertyName, m_frame); 409 | } 410 | 411 | DeleteTransitionCommand::DeleteTransitionCommand(QString propertyName, KeyFrame *frame, ResizeableItem *item, Timeline *timeline, QUndoCommand *parent) 412 | : QUndoCommand(parent) 413 | { 414 | m_propertyName = propertyName; 415 | m_frame = frame; 416 | m_item = item; 417 | m_timeline = timeline; 418 | setText("Delete " + getItemTypeName(item) + " Transition"); 419 | } 420 | 421 | void DeleteTransitionCommand::undo() 422 | { 423 | m_timeline->addTransition(m_item, m_propertyName, m_frame); 424 | } 425 | 426 | void DeleteTransitionCommand::redo() 427 | { 428 | m_timeline->deleteTransition(m_item, m_propertyName, m_frame); 429 | } 430 | -------------------------------------------------------------------------------- /itempropertyeditor.cpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** Copyright (C) 2016 Olaf Japp 3 | ** 4 | ** This file is part of AnimationMaker. 5 | ** 6 | ** AnimationMaker is free software: you can redistribute it and/or modify 7 | ** it under the terms of the GNU General Public License as published by 8 | ** the Free Software Foundation, either version 3 of the License, or 9 | ** (at your option) any later version. 10 | ** 11 | ** AnimationMaker is distributed in the hope that it will be useful, 12 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | ** GNU General Public License for more details. 15 | ** 16 | ** You should have received a copy of the GNU General Public License 17 | ** along with AnimationMaker. If not, see . 18 | ** 19 | ****************************************************************************/ 20 | 21 | #include "itempropertyeditor.h" 22 | #include "animationscene.h" 23 | #include "commands.h" 24 | #include 25 | 26 | ItemPropertyEditor::ItemPropertyEditor() 27 | { 28 | m_rectangle = NULL; 29 | m_ellipse = NULL; 30 | m_initializing = false; 31 | 32 | QString buttonStyle = "QPushButton{border: none;image:url(:/images/raute.png)} QPushButton:hover{border: none;image:url(:/images/raute-hover.png)} QToolTip{background:#f5f0eb;}"; 33 | 34 | QVBoxLayout *vbox = new QVBoxLayout(); 35 | Expander *expTyp = new Expander("Typ"); 36 | QGridLayout *layoutTyp = new QGridLayout(); 37 | QLabel *labelTyp = new QLabel("Typ"); 38 | m_typ = new QLabel("Unknown"); 39 | QLabel *labelId = new QLabel("Id"); 40 | m_id = new QLineEdit(); 41 | layoutTyp->addWidget(labelTyp, 0, 0); 42 | layoutTyp->addWidget(m_typ, 0, 1); 43 | layoutTyp->addWidget(labelId, 1, 0); 44 | layoutTyp->addWidget(m_id, 1, 1); 45 | expTyp->addLayout(layoutTyp); 46 | vbox->addWidget(expTyp); 47 | 48 | Expander *expGeo = new Expander("Geometrie"); 49 | QGridLayout *layoutGeo = new QGridLayout(); 50 | QLabel *labelPosition = new QLabel("Position"); 51 | QLabel *labelSize = new QLabel("Size"); 52 | QLabel *labelX = new QLabel("X"); 53 | QLabel *labelY = new QLabel("Y"); 54 | QLabel *labelWidth = new QLabel("W"); 55 | QLabel *labelHeight = new QLabel("H"); 56 | labelX->setFixedWidth(15); 57 | labelY->setFixedWidth(15); 58 | labelWidth->setFixedWidth(15); 59 | labelHeight->setFixedWidth(15); 60 | m_x = new QSpinBox(); 61 | m_y = new QSpinBox(); 62 | m_width = new QSpinBox(); 63 | m_height = new QSpinBox(); 64 | m_x->setMinimum(-10000); 65 | m_x->setMaximum(10000); 66 | m_y->setMinimum(-10000); 67 | m_y->setMaximum(10000); 68 | m_width->setMaximum(10000); 69 | m_height->setMaximum(10000); 70 | QPushButton *addXKeyframe = new QPushButton(); 71 | addXKeyframe->setStyleSheet(buttonStyle); 72 | addXKeyframe->setMaximumWidth(9); 73 | addXKeyframe->setToolTip("Add keyframe for Left"); 74 | QPushButton *addYKeyframe = new QPushButton(); 75 | addYKeyframe->setStyleSheet(buttonStyle); 76 | addYKeyframe->setMaximumWidth(9); 77 | addYKeyframe->setToolTip("Add keyframe for Top"); 78 | QPushButton *addWidthKeyframe = new QPushButton(); 79 | addWidthKeyframe->setStyleSheet(buttonStyle); 80 | addWidthKeyframe->setMaximumWidth(9); 81 | addWidthKeyframe->setToolTip("Add keyframe for Width"); 82 | QPushButton *addHeightKeyframe = new QPushButton(); 83 | addHeightKeyframe->setStyleSheet(buttonStyle); 84 | addHeightKeyframe->setMaximumWidth(9); 85 | addHeightKeyframe->setToolTip("Add keyframe for Height"); 86 | layoutGeo->addWidget(labelPosition, 0, 0); 87 | layoutGeo->addWidget(labelX, 0, 1); 88 | layoutGeo->addWidget(addXKeyframe, 0, 2); 89 | layoutGeo->addWidget(m_x, 0, 3); 90 | layoutGeo->addWidget(labelY, 0, 4); 91 | layoutGeo->addWidget(addYKeyframe, 0, 5); 92 | layoutGeo->addWidget(m_y, 0, 6); 93 | 94 | layoutGeo->addWidget(labelSize, 1, 0); 95 | layoutGeo->addWidget(labelWidth, 1, 1); 96 | layoutGeo->addWidget(addWidthKeyframe, 1, 2); 97 | layoutGeo->addWidget(m_width, 1, 3); 98 | layoutGeo->addWidget(labelHeight, 1, 4); 99 | layoutGeo->addWidget(addHeightKeyframe, 1, 5); 100 | layoutGeo->addWidget(m_height, 1, 6); 101 | expGeo->addLayout(layoutGeo); 102 | vbox->addWidget(expGeo); 103 | 104 | expText = new Expander("Text"); 105 | expText->setVisible(false); 106 | QGridLayout *layoutText = new QGridLayout(); 107 | QLabel *labelText = new QLabel("Text"); 108 | m_text = new QLineEdit(); 109 | layoutText->addWidget(labelText, 0, 0); 110 | layoutText->addWidget(m_text, 0, 1); 111 | expText->addLayout(layoutText); 112 | vbox->addWidget(expText); 113 | 114 | expTextcolor = new Expander("Textcolor"); 115 | expTextcolor->setVisible(false); 116 | 117 | 118 | QVBoxLayout *layoutTextcolor = new QVBoxLayout(); 119 | textcolorEditor = new ColorEditor("Color"); 120 | layoutTextcolor->addWidget(textcolorEditor); 121 | expTextcolor->addLayout(layoutTextcolor); 122 | vbox->addWidget(expTextcolor); 123 | 124 | expColor = new Expander("Color"); 125 | expColor->setVisible(false); 126 | colorEditor = new ColorEditor("Brush"); 127 | borderColorEditor = new ColorEditor("Pen"); 128 | QVBoxLayout *layoutColor = new QVBoxLayout(); 129 | layoutColor->addWidget(colorEditor); 130 | layoutColor->addWidget(borderColorEditor); 131 | expColor->addLayout(layoutColor); 132 | vbox->addWidget(expColor); 133 | 134 | Expander *expOpacity = new Expander("Visibility"); 135 | QGridLayout *layoutOpacity = new QGridLayout(); 136 | QPushButton *addOpacityKeyframe = new QPushButton(); 137 | addOpacityKeyframe->setStyleSheet(buttonStyle); 138 | addOpacityKeyframe->setMaximumWidth(9); 139 | addOpacityKeyframe->setToolTip("Add keyframe for Opacity"); 140 | QLabel *labelOpacity = new QLabel("Opacity"); 141 | m_opacity = new QSlider(Qt::Horizontal); 142 | m_opacity->setMinimum(0); 143 | m_opacity->setMaximum(100); 144 | m_opacityText = new QSpinBox(); 145 | m_opacityText->setMinimum(0); 146 | m_opacityText->setMaximum(100); 147 | layoutOpacity->addWidget(labelOpacity, 0, 0); 148 | layoutOpacity->addWidget(m_opacity, 0, 1); 149 | layoutOpacity->addWidget(addOpacityKeyframe, 0, 2); 150 | layoutOpacity->addWidget(m_opacityText, 0, 3); 151 | expOpacity->addLayout(layoutOpacity); 152 | vbox->addWidget(expOpacity); 153 | 154 | vbox->addStretch(); 155 | this->setLayout(vbox); 156 | 157 | connect(m_id, SIGNAL(textChanged(QString)), this, SLOT(idChanged(QString))); 158 | connect(m_x, SIGNAL(valueChanged(int)), this, SLOT(xChanged(int))); 159 | connect(m_y, SIGNAL(valueChanged(int)), this, SLOT(yChanged(int))); 160 | connect(m_width, SIGNAL(valueChanged(int)), this, SLOT(widthChanged(int))); 161 | connect(m_height, SIGNAL(valueChanged(int)), this, SLOT(heightChanged(int))); 162 | connect(m_text, SIGNAL(textChanged(QString)), this, SLOT(textChanged(QString))); 163 | connect(addXKeyframe, SIGNAL(clicked(bool)), this, SLOT(addLeftKeyFrame())); 164 | connect(addYKeyframe, SIGNAL(clicked(bool)), this, SLOT(addTopKeyFrame())); 165 | connect(addWidthKeyframe, SIGNAL(clicked(bool)), this, SLOT(addWidthKeyFrame())); 166 | connect(addHeightKeyframe, SIGNAL(clicked(bool)), this, SLOT(addHeightKeyFrame())); 167 | connect(m_opacity, SIGNAL(sliderReleased()), this, SLOT(opacitySliderReleased())); 168 | connect(m_opacityText, SIGNAL(valueChanged(int)), this, SLOT(opacityTextChanged(int))); 169 | connect(addOpacityKeyframe, SIGNAL(clicked(bool)), this, SLOT(addOpacityKeyFrame())); 170 | connect(colorEditor, SIGNAL(colorChanged(QColor)), this, SLOT(colorChanged(QColor))); 171 | connect(borderColorEditor, SIGNAL(colorChanged(QColor)), this, SLOT(borderColorChanged(QColor))); 172 | connect(textcolorEditor, SIGNAL(colorChanged(QColor)), this, SLOT(textColorChanged(QColor))); 173 | } 174 | 175 | void ItemPropertyEditor::colorChanged(QColor color) 176 | { 177 | AnimationScene *as = dynamic_cast(m_item->scene()); 178 | if(as) 179 | { 180 | QUndoStack *undoStack = as->undoStack(); 181 | QUndoCommand *cmd = new ChangeColorCommand(color, m_item->brush().color(), m_item); 182 | undoStack->push(cmd); 183 | } 184 | } 185 | 186 | void ItemPropertyEditor::borderColorChanged(QColor color) 187 | { 188 | AnimationScene *as = dynamic_cast(m_item->scene()); 189 | if(as) 190 | { 191 | QUndoStack *undoStack = as->undoStack(); 192 | QUndoCommand *cmd = new ChangePenCommand(color, m_item->pen().color(), m_item); 193 | undoStack->push(cmd); 194 | } 195 | } 196 | 197 | void ItemPropertyEditor::textColorChanged(QColor color) 198 | { 199 | AnimationScene *as = dynamic_cast(m_item->scene()); 200 | if(as) 201 | { 202 | QUndoStack *undoStack = as->undoStack(); 203 | QUndoCommand *cmd = new ChangeTextcolorCommand(color, m_textitem->textcolor(), m_textitem); 204 | undoStack->push(cmd); 205 | } 206 | } 207 | 208 | void ItemPropertyEditor::addLeftKeyFrame() 209 | { 210 | emit addKeyFrame(m_item, "left", QVariant(m_x->value())); 211 | } 212 | 213 | void ItemPropertyEditor::addTopKeyFrame() 214 | { 215 | emit addKeyFrame(m_item, "top", QVariant(m_y->value())); 216 | } 217 | 218 | void ItemPropertyEditor::addWidthKeyFrame() 219 | { 220 | emit addKeyFrame(m_item, "width", QVariant(m_width->value())); 221 | } 222 | 223 | void ItemPropertyEditor::addHeightKeyFrame() 224 | { 225 | emit addKeyFrame(m_item, "height", QVariant(m_height->value())); 226 | } 227 | 228 | void ItemPropertyEditor::addOpacityKeyFrame() 229 | { 230 | emit addKeyFrame(m_item, "opacity", QVariant(m_opacity->value())); 231 | } 232 | 233 | void ItemPropertyEditor::setItem(ResizeableItem *item) 234 | { 235 | m_initializing = true; 236 | m_item = item; 237 | expColor->setVisible(false); 238 | m_x->setValue(m_item->x()); 239 | m_y->setValue(m_item->y()); 240 | m_width->setValue(m_item->rect().width()); 241 | m_height->setValue(m_item->rect().height()); 242 | m_typ->setText(getItemTypeName(m_item)); 243 | m_id->setText(item->id()); 244 | m_opacity->setValue(item->opacity()); 245 | m_opacityText->setValue(item->opacity()); 246 | 247 | m_textitem = dynamic_cast(item); 248 | if(m_textitem) 249 | { 250 | m_text->setText(m_textitem->text()); 251 | textcolorEditor->setColor(m_textitem->textcolor()); 252 | connect(m_textitem, SIGNAL(textcolorChanged(QColor)), this, SLOT(textcolorChanged(QColor))); 253 | } 254 | 255 | m_rectangle = dynamic_cast(item); 256 | if(m_rectangle) 257 | { 258 | expColor->setVisible(true); 259 | colorEditor->setColor(m_rectangle->brush().color()); 260 | borderColorEditor->setColor(m_rectangle->pen().color()); 261 | } 262 | 263 | m_ellipse = dynamic_cast(item); 264 | if(m_ellipse) 265 | { 266 | expColor->setVisible(true); 267 | colorEditor->setColor(m_ellipse->brush().color()); 268 | borderColorEditor->setColor(m_ellipse->pen().color()); 269 | } 270 | expText->setVisible(m_textitem); 271 | expTextcolor->setVisible(m_textitem); 272 | m_initializing = false; 273 | 274 | connect(item, SIGNAL(idChanged(ResizeableItem*,QString)), this, SLOT(idChanged(ResizeableItem*,QString))); 275 | connect(item, SIGNAL(sizeChanged(qreal,qreal)), this, SLOT(itemSizeChanged(qreal, qreal))); 276 | connect(item, SIGNAL(positionChanged(qreal,qreal)), this, SLOT(itemPositionChanged(qreal, qreal))); 277 | connect(item, SIGNAL(brushChanged(QColor)), this, SLOT(brushChanged(QColor))); 278 | connect(item, SIGNAL(penChanged(QColor)), this, SLOT(penChanged(QColor))); 279 | connect(item, SIGNAL(opacityChanged(int)), this, SLOT(opacityChanged(int))); 280 | } 281 | 282 | void ItemPropertyEditor::brushChanged(QColor color) 283 | { 284 | colorEditor->setColor(color); 285 | } 286 | 287 | void ItemPropertyEditor::penChanged(QColor color) 288 | { 289 | borderColorEditor->setColor(color); 290 | } 291 | 292 | void ItemPropertyEditor::textcolorChanged(QColor color) 293 | { 294 | textcolorEditor->setColor(color); 295 | } 296 | 297 | void ItemPropertyEditor::itemSizeChanged(qreal width, qreal height) 298 | { 299 | m_initializing = true; 300 | m_width->setValue(width); 301 | m_height->setValue(height); 302 | m_initializing = false; 303 | } 304 | 305 | void ItemPropertyEditor::itemPositionChanged(qreal x, qreal y) 306 | { 307 | m_initializing = true; 308 | m_x->setValue(x); 309 | m_y->setValue(y); 310 | m_initializing = false; 311 | } 312 | 313 | void ItemPropertyEditor::idChanged(ResizeableItem*, QString id) 314 | { 315 | m_initializing = true; 316 | m_id->setText(id); 317 | m_initializing = false; 318 | } 319 | 320 | void ItemPropertyEditor::idChanged(QString value) 321 | { 322 | if(m_initializing) 323 | return; 324 | AnimationScene *as = dynamic_cast(m_item->scene()); 325 | if(as) 326 | { 327 | QUndoStack *undoStack = as->undoStack(); 328 | QUndoCommand *cmd = new ChangeIdCommand(value, m_item->id(), m_item); 329 | undoStack->push(cmd); 330 | } 331 | } 332 | 333 | void ItemPropertyEditor::xChanged(int value) 334 | { 335 | if(m_initializing) 336 | return; 337 | AnimationScene *as = dynamic_cast(m_item->scene()); 338 | if(as) 339 | { 340 | QUndoStack *undoStack = as->undoStack(); 341 | QUndoCommand *cmd = new MoveItemCommand(value, m_item->y(), m_item->x(), m_item->y(), as, m_item); 342 | undoStack->push(cmd); 343 | } 344 | } 345 | 346 | void ItemPropertyEditor::yChanged(int value) 347 | { 348 | if(m_initializing) 349 | return; 350 | AnimationScene *as = dynamic_cast(m_item->scene()); 351 | if(as) 352 | { 353 | QUndoStack *undoStack = as->undoStack(); 354 | QUndoCommand *cmd = new MoveItemCommand(m_item->x(), value, m_item->x(), m_item->y(), as, m_item); 355 | undoStack->push(cmd); 356 | } 357 | } 358 | 359 | void ItemPropertyEditor::widthChanged(int value) 360 | { 361 | if(m_initializing) 362 | return; 363 | AnimationScene *as = dynamic_cast(m_item->scene()); 364 | if(as) 365 | { 366 | QUndoStack *undoStack = as->undoStack(); 367 | QUndoCommand *cmd = new ResizeItemCommand(value, m_item->rect().height(), m_item->rect().width(), m_item->rect().height(), as, m_item); 368 | undoStack->push(cmd); 369 | } 370 | } 371 | 372 | void ItemPropertyEditor::heightChanged(int value) 373 | { 374 | if(m_initializing) 375 | return; 376 | AnimationScene *as = dynamic_cast(m_item->scene()); 377 | if(as) 378 | { 379 | QUndoStack *undoStack = as->undoStack(); 380 | QUndoCommand *cmd = new ResizeItemCommand(m_item->rect().width(), value, m_item->rect().width(), m_item->rect().height(), as, m_item); 381 | undoStack->push(cmd); 382 | } 383 | } 384 | 385 | void ItemPropertyEditor::textChanged(QString value) 386 | { 387 | m_textitem->setText(value); 388 | } 389 | 390 | void ItemPropertyEditor::changeBrush(QColor color) 391 | { 392 | if(m_initializing || !color.isValid()) 393 | return; 394 | AnimationScene *as = dynamic_cast(m_item->scene()); 395 | if(as) 396 | { 397 | QUndoStack *undoStack = as->undoStack(); 398 | QUndoCommand *cmd = new ChangeColorCommand(color, m_item->brush().color(), m_item); 399 | undoStack->push(cmd); 400 | } 401 | } 402 | 403 | void ItemPropertyEditor::opacitySliderReleased() 404 | { 405 | changeOpacity(m_opacity->value()); 406 | } 407 | 408 | void ItemPropertyEditor::opacityTextChanged(int value) 409 | { 410 | changeOpacity(value); 411 | } 412 | 413 | void ItemPropertyEditor::changeOpacity(int opacity) 414 | { 415 | if(m_initializing) 416 | return; 417 | AnimationScene *as = dynamic_cast(m_item->scene()); 418 | if(as) 419 | { 420 | QUndoCommand *cmd = new ChangeOpacityCommand(opacity, m_item->opacity(), as, m_item); 421 | as->undoStack()->push(cmd); 422 | } 423 | } 424 | 425 | void ItemPropertyEditor::opacityChanged(int val) 426 | { 427 | m_initializing = true; 428 | m_opacity->setValue(val); 429 | m_opacityText->setValue(val); 430 | m_initializing = false; 431 | } 432 | -------------------------------------------------------------------------------- /timeline.cpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** Copyright (C) 2016 Olaf Japp 3 | ** 4 | ** This file is part of AnimationMaker. 5 | ** 6 | ** AnimationMaker is free software: you can redistribute it and/or modify 7 | ** it under the terms of the GNU General Public License as published by 8 | ** the Free Software Foundation, either version 3 of the License, or 9 | ** (at your option) any later version. 10 | ** 11 | ** AnimationMaker is distributed in the hope that it will be useful, 12 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | ** GNU General Public License for more details. 15 | ** 16 | ** You should have received a copy of the GNU General Public License 17 | ** along with AnimationMaker. If not, see . 18 | ** 19 | ****************************************************************************/ 20 | 21 | #include "timeline.h" 22 | #include "resizeableitem.h" 23 | #include "keyframe.h" 24 | #include "commands.h" 25 | 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | 33 | Timeline::Timeline(AnimationScene *scene) 34 | : QWidget(0) 35 | { 36 | m_scene = scene; 37 | 38 | QHBoxLayout *hbox = new QHBoxLayout(); 39 | QToolButton *revertButton = new QToolButton(); 40 | QToolButton *forwardButton = new QToolButton(); 41 | QToolButton *autokeyframeButton = new QToolButton(); 42 | autokeyframeButton->setCheckable(true); 43 | autokeyframeButton->setChecked(false); 44 | autokeyframeButton->setIcon(QIcon(":/images/autokeyframe.png")); 45 | connect(autokeyframeButton, SIGNAL(toggled(bool)), this, SLOT(autokeyframes(bool))); 46 | 47 | QToolButton *autotransitionButton = new QToolButton(); 48 | autotransitionButton->setCheckable(true); 49 | autotransitionButton->setChecked(false); 50 | autotransitionButton->setIcon(QIcon(":/images/autotransition.png")); 51 | connect(autotransitionButton, SIGNAL(toggled(bool)), this, SLOT(autotransitions(bool))); 52 | playButton = new QToolButton(); 53 | pauseButton = new QToolButton(); 54 | pauseButton->setVisible(false); 55 | m_time = new QLabel(); 56 | m_time->setText("0:00.000"); 57 | 58 | QAction *playAct = new QAction("Play"); 59 | playAct->setIcon(QIcon(":/images/play.png")); 60 | playAct->setToolTip("Start the animation"); 61 | connect(playAct, SIGNAL(triggered()), this, SLOT(playAnimation())); 62 | 63 | QAction *pauseAct = new QAction("Pause"); 64 | pauseAct->setIcon(QIcon(":/images/pause.png")); 65 | pauseAct->setToolTip("Pause the animation"); 66 | connect(pauseAct, SIGNAL(triggered()), this, SLOT(pauseAnimation())); 67 | 68 | QAction *reverseAct = new QAction("Reverse"); 69 | reverseAct->setIcon(QIcon(":/images/reverse.png")); 70 | reverseAct->setToolTip("Reset the animation"); 71 | connect(reverseAct, SIGNAL(triggered()), this, SLOT(revertAnimation())); 72 | 73 | QAction *forwardAct = new QAction("Forward"); 74 | forwardAct->setIcon(QIcon(":/images/forward.png")); 75 | forwardAct->setToolTip("Forward the animation"); 76 | connect(forwardAct, SIGNAL(triggered()), this, SLOT(forwardAnimation())); 77 | 78 | revertButton->setDefaultAction(reverseAct); 79 | playButton->setDefaultAction(playAct); 80 | pauseButton->setDefaultAction(pauseAct); 81 | forwardButton->setDefaultAction(forwardAct); 82 | 83 | hbox->addWidget(revertButton); 84 | hbox->addWidget(playButton); 85 | hbox->addWidget(pauseButton); 86 | hbox->addWidget(forwardButton); 87 | hbox->addStretch(); 88 | hbox->addWidget(autokeyframeButton); 89 | hbox->addWidget(autotransitionButton); 90 | hbox->addSpacing(5); 91 | hbox->addWidget(m_time); 92 | QGridLayout *layout = new QGridLayout; 93 | m_tree = new QTreeWidget(); 94 | m_tree->header()->close(); 95 | m_tree->setStyleSheet("QTreeWidget::item:has-children:!selected {background-color: #4c4e50;} QTreeWidget::item:!selected { border-bottom: 1px solid #292929;} QTreeView::branch:!selected {border-bottom: 1px solid #292929;} QTreeWidget::branch:has-children:!selected {background-color: #4c4e50;} QTreeWidget::branch:has-children:!has-siblings:closed, QTreeWidget::branch:closed:has-children:has-siblings {border-image: none; image: url(:/images/branch-closed.png);} QTreeWidget::branch:open:has-children:!has-siblings, QTreeWidget::branch:open:has-children:has-siblings {border-image: none;image: url(:/images/branch-open.png);}"); 96 | m_tree->setContextMenuPolicy(Qt::CustomContextMenu); 97 | 98 | m_transitionPanel = new TransitionPanel(); 99 | m_transitionPanel->setTreeWidget(m_tree); 100 | m_transitionPanel->registerTimeline(this); 101 | m_playhead = new PlayHead(); 102 | QScrollBar *sb = new QScrollBar(Qt::Horizontal); 103 | 104 | layout->addItem(hbox, 0, 0); 105 | layout->addWidget(m_playhead, 0, 1); 106 | layout->addWidget(m_tree, 1, 0); 107 | layout->addWidget(m_transitionPanel, 1, 1); 108 | layout->addWidget(sb, 2, 1); 109 | layout->setColumnStretch(0,0); 110 | layout->setColumnStretch(1,1); 111 | 112 | this->setLayout(layout); 113 | 114 | m_contextMenu = new QMenu(); 115 | m_delAct = new QAction("Delete"); 116 | 117 | connect(m_tree, SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(onCustomContextMenu(const QPoint &))); 118 | connect(m_tree, SIGNAL(expanded(QModelIndex)), m_transitionPanel, SLOT(treeExpanded(QModelIndex))); 119 | connect(m_tree, SIGNAL(collapsed(QModelIndex)), m_transitionPanel, SLOT(treeCollapsed(QModelIndex))); 120 | connect(this, SIGNAL(keyframeAdded(ResizeableItem*,QString)), m_transitionPanel, SLOT(keyframeAdded(ResizeableItem *, QString))); 121 | connect(this, SIGNAL(keyframeDeleted(ResizeableItem*,QString)), m_transitionPanel, SLOT(keyframeDeleted(ResizeableItem*,QString))); 122 | 123 | connect(m_tree->verticalScrollBar(), SIGNAL(valueChanged(int)), m_transitionPanel, SLOT(treeScrollValueChanged(int))); 124 | 125 | connect(m_playhead, SIGNAL(valueChanged(int)), this, SLOT(playheadValueChanged(int))); 126 | connect(sb, SIGNAL(valueChanged(int)), m_transitionPanel, SLOT(scrollValueChanged(int))); 127 | connect(sb, SIGNAL(valueChanged(int)), m_playhead, SLOT(scrollValueChanged(int))); 128 | 129 | connect(m_tree, SIGNAL(currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)), this, SLOT(treeCurrentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*))); 130 | connect(m_playhead, SIGNAL(valueChanged(int)), scene, SLOT(setPlayheadPosition(int))); 131 | connect(m_scene, SIGNAL(keyframeAdded(ResizeableItem*, QString, KeyFrame*)), this, SLOT(keyframeAdded(ResizeableItem*, QString, KeyFrame*))); 132 | } 133 | 134 | void Timeline::reset() 135 | { 136 | while(1) 137 | { 138 | QTreeWidgetItem *treeItem = m_tree->takeTopLevelItem(0); 139 | if(treeItem == NULL) 140 | break; 141 | delete treeItem; 142 | } 143 | m_transitionPanel->reset(); 144 | m_playhead->setValue(0); 145 | } 146 | 147 | void Timeline::onCustomContextMenu(const QPoint &point) 148 | { 149 | QTreeWidgetItem *treeItem = m_tree->itemAt(point); 150 | if(treeItem) 151 | { 152 | m_contextMenu->clear(); 153 | m_contextMenu->addAction(m_delAct); 154 | m_contextMenu->exec(m_tree->mapToGlobal(point)); 155 | } 156 | } 157 | 158 | void Timeline::playAnimation() 159 | { 160 | m_scene->clearSelection(); 161 | 162 | int delay = 1000 / m_scene->fps(); 163 | int last = lastKeyframe(); 164 | int frames = last / delay; 165 | m_playing = true; 166 | playButton->setVisible(false); 167 | pauseButton->setVisible(true); 168 | 169 | for(int i=0; i < frames; i++) 170 | { 171 | m_playhead->setValue(i * delay); 172 | QTest::qSleep(delay / 2); 173 | QCoreApplication::processEvents(QEventLoop::AllEvents, delay / 2); 174 | if(!m_playing) 175 | break; 176 | } 177 | if(m_playing) 178 | m_playhead->setValue(lastKeyframe()); 179 | playButton->setVisible(true); 180 | pauseButton->setVisible(false); 181 | m_playing = false; 182 | } 183 | 184 | void Timeline::pauseAnimation() 185 | { 186 | m_playing = false; 187 | } 188 | 189 | void Timeline::revertAnimation() 190 | { 191 | m_scene->clearSelection(); 192 | m_playhead->setValue(0); 193 | } 194 | 195 | void Timeline::forwardAnimation() 196 | { 197 | m_scene->clearSelection(); 198 | 199 | int last = lastKeyframe(); 200 | m_playhead->setValue(last); 201 | } 202 | 203 | void Timeline::playheadValueChanged(int val) 204 | { 205 | int seconds = val / 1000; 206 | int minutes = seconds / 60; 207 | int milliseconds = val - seconds * 1000; 208 | QString txt; 209 | txt.sprintf("%d:%02d.%03d", minutes, seconds, milliseconds); 210 | m_time->setText(txt); 211 | m_scene->clearSelection(); 212 | m_scene->setPlayheadPosition(val); 213 | m_transitionPanel->setPlayheadPosition(val); 214 | } 215 | 216 | void Timeline::treeCurrentItemChanged(QTreeWidgetItem *currentItem, QTreeWidgetItem*) 217 | { 218 | if(currentItem) 219 | { 220 | QVariant level = currentItem->data(1,0); 221 | if(level == 1) 222 | { 223 | ResizeableItem *item = (ResizeableItem *)currentItem->data(0,1).value(); 224 | if(item) 225 | emit itemSelectionChanged(item); 226 | } 227 | } 228 | } 229 | 230 | QTreeWidgetItem *Timeline::search(ResizeableItem *item) 231 | { 232 | for(int i=0; i < m_tree->topLevelItemCount(); i++) 233 | { 234 | QTreeWidgetItem *twi = m_tree->topLevelItem(i); 235 | if(twi->data(0, 1).value() == item) 236 | return twi; 237 | } 238 | return NULL; 239 | } 240 | 241 | QTreeWidgetItem *Timeline::search(QTreeWidgetItem *treeItem, QString propertyName) 242 | { 243 | for(int i=0; i < treeItem->childCount(); i++) 244 | { 245 | QTreeWidgetItem *twi = treeItem->child(i); 246 | if(twi->text(0) == propertyName) 247 | return twi; 248 | } 249 | return NULL; 250 | } 251 | 252 | void Timeline::idChanged(ResizeableItem *item, QString value) 253 | { 254 | QTreeWidgetItem *treeItem = search(item); 255 | if(treeItem) 256 | { 257 | treeItem->setText(0, value); 258 | } 259 | } 260 | 261 | void Timeline::deleteKeyFrameSlot(ResizeableItem *item, QString propertyName, KeyFrame *frame) 262 | { 263 | QUndoCommand *cmd = new DeleteKeyframeCommand(propertyName, frame, item, this); 264 | m_scene->undoStack()->push(cmd); 265 | } 266 | 267 | void Timeline::deleteTransitionSlot(ResizeableItem *item, QString propertyName, KeyFrame *frame) 268 | { 269 | QUndoCommand *cmd = new DeleteTransitionCommand(propertyName, frame, item, this); 270 | m_scene->undoStack()->push(cmd); 271 | } 272 | 273 | void Timeline::addTransitionSlot(ResizeableItem *item, QString propertyName, KeyFrame *frame) 274 | { 275 | QUndoCommand *cmd = new AddTransitionCommand(propertyName, frame, item, this); 276 | m_scene->undoStack()->push(cmd); 277 | } 278 | 279 | void Timeline::deleteTransition(ResizeableItem *item, QString propertyName, KeyFrame *frame) 280 | { 281 | frame->setEasing(-1); 282 | m_transitionPanel->transitionDeleted(item, propertyName); 283 | } 284 | 285 | void Timeline::addTransition(ResizeableItem *item, QString propertyName, KeyFrame *frame) 286 | { 287 | frame->setEasing((int)QEasingCurve::Linear); 288 | m_transitionPanel->transitionAdded(item, propertyName); 289 | } 290 | 291 | void Timeline::deleteKeyFrame(ResizeableItem *item, QString propertyName, KeyFrame *frame) 292 | { 293 | if(item->deleteKeyframe(propertyName, frame)) 294 | { 295 | QTreeWidgetItem *treeItem = search(item); 296 | if(treeItem) 297 | { 298 | QTreeWidgetItem *treeChildItem = search(treeItem, propertyName); 299 | if(treeChildItem) 300 | { 301 | treeItem->removeChild(treeChildItem); 302 | delete treeChildItem; 303 | 304 | if(treeItem->childCount() == 0) 305 | { 306 | int index = m_tree->indexOfTopLevelItem(treeItem); 307 | m_tree->takeTopLevelItem(index); 308 | delete treeItem; 309 | } 310 | } 311 | } 312 | } 313 | emit keyframeDeleted(item, propertyName); 314 | } 315 | 316 | void Timeline::addKeyFrame(ResizeableItem *item, QString propertyName, QVariant value) 317 | { 318 | KeyFrame *keyframe = new KeyFrame(); 319 | keyframe->setValue(value); 320 | keyframe->setTime(m_playhead->value()); 321 | 322 | QUndoCommand *cmd = new AddKeyframeCommand(propertyName, keyframe, item, this); 323 | item->scene()->undoStack()->push(cmd); 324 | } 325 | 326 | void Timeline::addKeyFrame(ResizeableItem *item, QString propertyName, KeyFrame *frame) 327 | { 328 | QTreeWidgetItem *treeChildItem = NULL; 329 | 330 | QTreeWidgetItem *treeItem = search(item); 331 | if(treeItem) 332 | { 333 | treeChildItem = search(treeItem, propertyName); 334 | } 335 | else 336 | { 337 | treeItem = new QTreeWidgetItem(); 338 | treeItem->setText(0, item->id()); 339 | treeItem->setData(0, 1, qVariantFromValue((void *) item)); 340 | treeItem->setData(1, 0, 1); 341 | connect(item, SIGNAL(idChanged(ResizeableItem *, QString)), this, SLOT(idChanged(ResizeableItem *, QString))); 342 | m_tree->addTopLevelItem(treeItem); 343 | emit keyframeAdded(item, NULL); 344 | } 345 | 346 | item->addKeyframe(propertyName, frame); 347 | if(treeChildItem) 348 | { 349 | QVariant var = treeChildItem->data(0, 1); 350 | QList *list = (QList*) var.value(); 351 | list->append(frame); 352 | emit keyframeAdded(NULL, NULL); 353 | } 354 | else 355 | { 356 | QList *list = new QList(); 357 | list->append(frame); 358 | treeChildItem = new QTreeWidgetItem(); 359 | treeChildItem->setText(0, propertyName); 360 | treeChildItem->setData(0, 1, qVariantFromValue((void *) list)); 361 | treeChildItem->setData(1, 0, 2); 362 | treeItem->addChild(treeChildItem); 363 | emit keyframeAdded(item, propertyName); 364 | } 365 | treeItem->setExpanded(true); 366 | } 367 | 368 | void Timeline::keyframeAdded(ResizeableItem * item, QString propertyName, KeyFrame *key) 369 | { 370 | QTreeWidgetItem *treeChildItem = NULL; 371 | 372 | QTreeWidgetItem *treeItem = search(item); 373 | if(treeItem) 374 | { 375 | treeChildItem = search(treeItem, propertyName); 376 | } 377 | else 378 | { 379 | treeItem = new QTreeWidgetItem(); 380 | treeItem->setText(0, item->id()); 381 | treeItem->setData(0, 1, qVariantFromValue((void *) item)); 382 | treeItem->setData(1, 0, 1); 383 | connect(item, SIGNAL(idChanged(ResizeableItem *, QString)), this, SLOT(idChanged(ResizeableItem *, QString))); 384 | m_tree->addTopLevelItem(treeItem); 385 | emit keyframeAdded(item, NULL); 386 | } 387 | 388 | if(treeChildItem) 389 | { 390 | QVariant var = treeChildItem->data(0, 1); 391 | QList *list = (QList*) var.value(); 392 | list->append(key); 393 | emit keyframeAdded(NULL, NULL); 394 | } 395 | else 396 | { 397 | QList *list = new QList(); 398 | list->append(key); 399 | treeChildItem = new QTreeWidgetItem(); 400 | treeChildItem->setText(0, propertyName); 401 | treeChildItem->setData(0, 1, qVariantFromValue((void *) list)); 402 | treeChildItem->setData(1, 0, 2); 403 | treeItem->addChild(treeChildItem); 404 | emit keyframeAdded(item, propertyName); 405 | } 406 | treeItem->setExpanded(true); 407 | } 408 | 409 | 410 | void Timeline::autokeyframes(bool value) 411 | { 412 | m_scene->setAutokeyframes(value); 413 | } 414 | 415 | void Timeline::autotransitions(bool value) 416 | { 417 | m_scene->setAutotransition(value); 418 | } 419 | 420 | void Timeline::removeItem(ResizeableItem *item) 421 | { 422 | for(int i=0; i < m_tree->topLevelItemCount(); i++) 423 | { 424 | QTreeWidgetItem *treeItem = m_tree->topLevelItem(i); 425 | if(treeItem->data(0, 1).value() == item) 426 | { 427 | m_tree->takeTopLevelItem(i); 428 | delete treeItem; 429 | } 430 | } 431 | m_transitionPanel->removeItem(item); 432 | } 433 | 434 | void Timeline::selectItem(ResizeableItem *item) 435 | { 436 | for(int i=0; i < m_tree->topLevelItemCount(); i++) 437 | { 438 | QTreeWidgetItem *treeItem = m_tree->topLevelItem(i); 439 | if(treeItem->data(0, 1).value() == item) 440 | treeItem->setSelected(true); 441 | else 442 | treeItem->setSelected(false); 443 | } 444 | } 445 | 446 | int Timeline::lastKeyframe() 447 | { 448 | int last = 0; 449 | for(int i = 0; i < m_tree->topLevelItemCount(); i++) 450 | { 451 | QTreeWidgetItem *treeItem = m_tree->topLevelItem(i); 452 | ResizeableItem *item = (ResizeableItem *) treeItem->data(0, 1).value(); 453 | 454 | QHash::iterator it; 455 | for (it = item->keyframes()->begin(); it != item->keyframes()->end(); it++) 456 | { 457 | KeyFrame *first = it.value(); 458 | for(KeyFrame *frame = first; frame != NULL; frame = frame->next()) 459 | { 460 | last = frame->time() > last ? frame->time() : last; 461 | } 462 | } 463 | } 464 | return last; 465 | } 466 | -------------------------------------------------------------------------------- /animationscene.cpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** Copyright (C) 2016 Olaf Japp 3 | ** 4 | ** This file is part of AnimationMaker. 5 | ** 6 | ** AnimationMaker is free software: you can redistribute it and/or modify 7 | ** it under the terms of the GNU General Public License as published by 8 | ** the Free Software Foundation, either version 3 of the License, or 9 | ** (at your option) any later version. 10 | ** 11 | ** AnimationMaker is distributed in the hope that it will be useful, 12 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | ** GNU General Public License for more details. 15 | ** 16 | ** You should have received a copy of the GNU General Public License 17 | ** along with AnimationMaker. If not, see . 18 | ** 19 | ****************************************************************************/ 20 | 21 | #include "animationscene.h" 22 | #include "serializeableitem.h" 23 | #include "handleitem.h" 24 | #include "rectangle.h" 25 | #include "ellipse.h" 26 | #include "text.h" 27 | #include "bitmap.h" 28 | #include "vectorgraphic.h" 29 | #include "keyframe.h" 30 | #include "commands.h" 31 | #include 32 | 33 | AnimationScene::AnimationScene() 34 | { 35 | m_autokeyframes = false; 36 | m_autotransitions = false; 37 | initialize(); 38 | } 39 | 40 | void AnimationScene::initialize() 41 | { 42 | setSceneRect(0, 0, 1200, 720); 43 | m_editMode = EditMode::ModeSelect; 44 | m_fps = 24; 45 | m_copy = NULL; 46 | m_playheadPosition = 0; 47 | m_tempKeyFrame = NULL; 48 | m_movingItem = NULL; 49 | 50 | addBackgroundRect(); 51 | } 52 | 53 | void AnimationScene::reset() 54 | { 55 | clear(); 56 | initialize(); 57 | m_undoStack->clear(); 58 | } 59 | 60 | void AnimationScene::deleteItem(ResizeableItem *item) 61 | { 62 | QUndoCommand *deleteCommand = new DeleteItemCommand(item, this); 63 | m_undoStack->push(deleteCommand); 64 | } 65 | 66 | void AnimationScene::mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent) 67 | { 68 | if (mouseEvent->button() != Qt::LeftButton) 69 | return; 70 | 71 | if(m_editMode == EditMode::ModeSelect) 72 | { 73 | QPointF mousePos(mouseEvent->buttonDownScenePos(Qt::LeftButton).x(), mouseEvent->buttonDownScenePos(Qt::LeftButton).y()); 74 | const QList itemList = items(mousePos); 75 | m_movingItem = itemList.isEmpty() ? 0 : dynamic_cast(itemList.first()); 76 | if(m_movingItem) 77 | m_oldPos = m_movingItem->pos(); 78 | QGraphicsScene::mousePressEvent(mouseEvent); 79 | } 80 | else 81 | { 82 | QString fileName; 83 | QString filter; 84 | QString title; 85 | if(m_editMode == EditMode::ModeBitmap) 86 | { 87 | filter = "Image Files (*.png *.jpeg *.jpg *.gif *.bmp);;All Files (*)"; 88 | title = "Open Bitmap"; 89 | } 90 | else if(m_editMode == EditMode::ModeSvg) 91 | { 92 | filter = "SVG Files (*.svg);;All Files (*)"; 93 | title = "Open SVG"; 94 | } 95 | if(!filter.isEmpty()) 96 | { 97 | QFileDialog *dialog = new QFileDialog(); 98 | dialog->setFileMode(QFileDialog::AnyFile); 99 | dialog->setNameFilter(filter); 100 | dialog->setWindowTitle(title); 101 | dialog->setOption(QFileDialog::DontUseNativeDialog, true); 102 | dialog->setAcceptMode(QFileDialog::AcceptOpen); 103 | if(dialog->exec()) 104 | fileName = dialog->selectedFiles().first(); 105 | delete dialog; 106 | if(fileName.isEmpty()) 107 | return; 108 | } 109 | QUndoCommand *addCommand = new AddItemCommand(mouseEvent->scenePos().x(), mouseEvent->scenePos().y(), m_editMode, fileName, this); 110 | m_undoStack->push(addCommand); 111 | } 112 | } 113 | 114 | void AnimationScene::mouseMoveEvent(QGraphicsSceneMouseEvent *mouseEvent) 115 | { 116 | QGraphicsScene::mouseMoveEvent(mouseEvent); 117 | } 118 | 119 | void AnimationScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *mouseEvent) 120 | { 121 | if(m_movingItem && mouseEvent->button() == Qt::LeftButton) 122 | { 123 | if(m_oldPos != m_movingItem->pos()) 124 | { 125 | QUndoCommand *cmd = new MoveItemCommand(m_movingItem->x(), m_movingItem->y(), m_oldPos.x(), m_oldPos.y(), this, m_movingItem); 126 | m_undoStack->push(cmd); 127 | } 128 | m_movingItem = NULL; 129 | } 130 | QGraphicsScene::mouseReleaseEvent(mouseEvent); 131 | } 132 | 133 | void AnimationScene::setEditMode(EditMode mode) 134 | { 135 | m_editMode = mode; 136 | } 137 | 138 | void AnimationScene::addBackgroundRect() 139 | { 140 | m_rect = new QGraphicsRectItem(0, 0, width(), height()); 141 | m_backgroundColor = QColor("#404244"); 142 | m_rect->setBrush(QBrush(QColor(m_backgroundColor))); 143 | m_rect->setPos(0,0); 144 | addItem(m_rect); 145 | } 146 | 147 | void AnimationScene::readKeyframes(QDataStream &dataStream, ResizeableItem *item) 148 | { 149 | int vars, easing, time, keyframes; 150 | QVariant value; 151 | QString propertyName; 152 | 153 | m_tempKeyFrame = NULL; 154 | dataStream >> vars; 155 | qDebug() << "read" << vars; 156 | 157 | for(int i=0; i < vars; i++) 158 | { 159 | dataStream >> propertyName; 160 | dataStream >> keyframes; 161 | for(int j=0; j < keyframes; j++) 162 | { 163 | dataStream >> time; 164 | dataStream >> value; 165 | dataStream >> easing; 166 | KeyFrame *key = new KeyFrame(); 167 | key->setTime(time); 168 | key->setValue(value); 169 | key->setEasing(easing); 170 | item->addKeyframe(propertyName, key); 171 | // set double linked list 172 | if(m_tempKeyFrame) 173 | { 174 | m_tempKeyFrame->setNext(key); 175 | key->setPrev(m_tempKeyFrame); 176 | } 177 | m_tempKeyFrame = key; 178 | emit keyframeAdded(item, propertyName, key); 179 | } 180 | } 181 | } 182 | 183 | QDataStream& AnimationScene::read(QDataStream &dataStream) 184 | { 185 | int type, fps, opacity; 186 | qreal x, y, width, height, xscale, yscale; 187 | QPen pen; 188 | QBrush brush; 189 | QString text, id; 190 | QColor color, bgColor; 191 | 192 | clear(); 193 | 194 | addBackgroundRect(); 195 | 196 | dataStream >> width; 197 | dataStream >> height; 198 | dataStream >> fps; 199 | dataStream >> bgColor; 200 | 201 | this->setWidth(width); 202 | this->setHeight(height); 203 | this->setFps(fps); 204 | this->setBackgroundColor(bgColor); 205 | 206 | while (!dataStream.atEnd()) 207 | { 208 | dataStream >> type; 209 | if(type == Rectangle::Type) 210 | { 211 | dataStream >> id; 212 | dataStream >> x; 213 | dataStream >> y; 214 | dataStream >> width; 215 | dataStream >> height; 216 | dataStream >> pen; 217 | dataStream >> brush; 218 | dataStream >> opacity; 219 | 220 | Rectangle *r = new Rectangle(width, height, this); 221 | r->setId(id); 222 | r->setPos(x, y); 223 | r->setPen(pen); 224 | r->setBrush(brush); 225 | r->setFlag(QGraphicsItem::ItemIsMovable, true); 226 | r->setFlag(QGraphicsItem::ItemIsSelectable, true); 227 | r->setOpacity(opacity); 228 | 229 | readKeyframes(dataStream, r); 230 | 231 | addItem(r); 232 | } 233 | else if(type == Ellipse::Type) 234 | { 235 | dataStream >> id; 236 | dataStream >> x; 237 | dataStream >> y; 238 | dataStream >> width; 239 | dataStream >> height; 240 | dataStream >> pen; 241 | dataStream >> brush; 242 | dataStream >> opacity; 243 | 244 | Ellipse *e = new Ellipse(width, height, this); 245 | e->setId(id); 246 | e->setPos(x, y); 247 | e->setPen(pen); 248 | e->setBrush(brush); 249 | e->setFlag(QGraphicsItem::ItemIsMovable, true); 250 | e->setFlag(QGraphicsItem::ItemIsSelectable, true); 251 | e->setOpacity(opacity); 252 | 253 | readKeyframes(dataStream, e); 254 | 255 | addItem(e); 256 | } 257 | else if(type == Text::Type) 258 | { 259 | dataStream >> id; 260 | dataStream >> x; 261 | dataStream >> y; 262 | dataStream >> xscale; 263 | dataStream >> yscale; 264 | dataStream >> text; 265 | dataStream >> color; 266 | dataStream >> opacity; 267 | 268 | Text *t = new Text(text, this); 269 | t->setId(id); 270 | t->setPos(x, y); 271 | t->setFlag(QGraphicsItem::ItemIsMovable, true); 272 | t->setFlag(QGraphicsItem::ItemIsSelectable, true); 273 | t->setScale(xscale, yscale); 274 | t->setTextcolor(color); 275 | t->setOpacity(opacity); 276 | 277 | readKeyframes(dataStream, t); 278 | 279 | addItem(t); 280 | } 281 | else if(type == Bitmap::Type) 282 | { 283 | QImage img; 284 | dataStream >> id; 285 | dataStream >> x; 286 | dataStream >> y; 287 | dataStream >> width; 288 | dataStream >> height; 289 | dataStream >> img; 290 | dataStream >> opacity; 291 | 292 | Bitmap *b = new Bitmap(img, width, height, this); 293 | b->setId(id); 294 | b->setPos(x, y); 295 | b->setFlag(QGraphicsItem::ItemIsMovable, true); 296 | b->setFlag(QGraphicsItem::ItemIsSelectable, true); 297 | b->setScale(xscale, yscale); 298 | b->setOpacity(opacity); 299 | 300 | readKeyframes(dataStream, b); 301 | 302 | addItem(b); 303 | } 304 | else if(type == Vectorgraphic::Type) 305 | { 306 | QByteArray arr; 307 | dataStream >> id; 308 | dataStream >> x; 309 | dataStream >> y; 310 | dataStream >> xscale; 311 | dataStream >> yscale; 312 | dataStream >> opacity; 313 | dataStream >> arr; 314 | Vectorgraphic *v = new Vectorgraphic(arr, this); 315 | v->setId(id); 316 | v->setPos(x, y); 317 | v->setFlag(QGraphicsItem::ItemIsMovable, true); 318 | v->setFlag(QGraphicsItem::ItemIsSelectable, true); 319 | v->setScale(xscale, yscale); 320 | v->setOpacity(opacity); 321 | 322 | readKeyframes(dataStream, v); 323 | 324 | addItem(v); 325 | } 326 | } 327 | 328 | return dataStream; 329 | } 330 | 331 | void AnimationScene::writeKeyframes(QDataStream &dataStream, ResizeableItem *item) const 332 | { 333 | qDebug() << "write" << item->keyframes()->count(); 334 | dataStream << item->keyframes()->count(); 335 | QHash::iterator it; 336 | for(it = item->keyframes()->begin(); it != item->keyframes()->end(); it++) 337 | { 338 | dataStream << it.key(); 339 | KeyFrame *first = it.value(); 340 | int count = 0; 341 | for(KeyFrame *frame = first; frame != NULL; frame = frame->next()) 342 | count++; 343 | 344 | dataStream << count; 345 | for(KeyFrame *frame = first; frame != NULL; frame = frame->next()) 346 | { 347 | dataStream << frame->time(); 348 | dataStream << frame->value(); 349 | dataStream << frame->easing(); 350 | } 351 | } 352 | } 353 | 354 | QDataStream& AnimationScene::write(QDataStream &dataStream) const 355 | { 356 | dataStream << width(); 357 | dataStream << height(); 358 | dataStream << fps(); 359 | dataStream << backgroundColor(); 360 | 361 | QList itemList = items(Qt::AscendingOrder); 362 | foreach (QGraphicsItem *item, itemList) 363 | { 364 | switch(item->type()) 365 | { 366 | case Rectangle::Type: 367 | { 368 | Rectangle *r = dynamic_cast(item); 369 | dataStream << Rectangle::Type; 370 | dataStream << r->id(); 371 | dataStream << r->pos().x(); 372 | dataStream << r->pos().y(); 373 | dataStream << r->rect().width(); 374 | dataStream << r->rect().height(); 375 | dataStream << r->pen(); 376 | dataStream << r->brush(); 377 | dataStream << r->opacity(); 378 | 379 | writeKeyframes(dataStream, r); 380 | break; 381 | } 382 | case Ellipse::Type: 383 | { 384 | Ellipse *e = dynamic_cast(item); 385 | dataStream << Ellipse::Type; 386 | dataStream << e->id(); 387 | dataStream << e->pos().x(); 388 | dataStream << e->pos().y(); 389 | dataStream << e->rect().width(); 390 | dataStream << e->rect().height(); 391 | dataStream << e->pen(); 392 | dataStream << e->brush(); 393 | dataStream << e->opacity(); 394 | 395 | writeKeyframes(dataStream, e); 396 | break; 397 | } 398 | case Text::Type: 399 | { 400 | Text *t = dynamic_cast(item); 401 | dataStream << Text::Type; 402 | dataStream << t->id(); 403 | dataStream << t->pos().x(); 404 | dataStream << t->pos().y(); 405 | dataStream << t->xscale(); 406 | dataStream << t->yscale(); 407 | dataStream << t->text(); 408 | dataStream << t->textcolor(); 409 | dataStream << t->opacity(); 410 | 411 | writeKeyframes(dataStream, t); 412 | break; 413 | } 414 | case Bitmap::Type: 415 | { 416 | Bitmap *b = dynamic_cast(item); 417 | dataStream << Bitmap::Type; 418 | dataStream << b->id(); 419 | dataStream << b->pos().x(); 420 | dataStream << b->pos().y(); 421 | dataStream << b->rect().width(); 422 | dataStream << b->rect().height(); 423 | dataStream << b->getImage(); 424 | dataStream << b->opacity(); 425 | 426 | writeKeyframes(dataStream, b); 427 | break; 428 | } 429 | case Vectorgraphic::Type: 430 | { 431 | Vectorgraphic *v = dynamic_cast(item); 432 | dataStream << Vectorgraphic::Type; 433 | dataStream << v->id(); 434 | dataStream << v->pos().x(); 435 | dataStream << v->pos().y(); 436 | dataStream << v->xscale(); 437 | dataStream << v->yscale(); 438 | dataStream << v->opacity(); 439 | dataStream << v->getData(); 440 | 441 | writeKeyframes(dataStream, v); 442 | break; 443 | } 444 | default: 445 | break; 446 | } 447 | } 448 | return dataStream; 449 | } 450 | 451 | void AnimationScene::copyItem() 452 | { 453 | if(selectedItems().count() == 0) 454 | return; 455 | 456 | QGraphicsItem *gi = selectedItems().first(); 457 | m_copy = dynamic_cast(gi); 458 | } 459 | 460 | void AnimationScene::pasteItem() 461 | { 462 | if(m_copy == NULL) 463 | return; 464 | 465 | m_copy->setSelected(false); 466 | switch(m_copy->type()) 467 | { 468 | case Rectangle::Type: 469 | { 470 | Rectangle *r = new Rectangle(m_copy->rect().width(), m_copy->rect().height(), this); 471 | r->setPos(m_copy->pos().x() + 10, m_copy->pos().y() + 10); 472 | r->setId(""); 473 | r->setPen(m_copy->pen()); 474 | r->setBrush(m_copy->brush()); 475 | r->setFlag(QGraphicsItem::ItemIsMovable, true); 476 | r->setFlag(QGraphicsItem::ItemIsSelectable, true); 477 | addItem(r); 478 | emit itemAdded(r); 479 | break; 480 | } 481 | case Ellipse::Type: 482 | { 483 | Ellipse *e = new Ellipse(m_copy->rect().width(), m_copy->rect().height(), this); 484 | e->setPos(m_copy->pos().x() + 10, m_copy->pos().y() + 10); 485 | e->setId(""); 486 | e->setPen(m_copy->pen()); 487 | e->setBrush(m_copy->brush()); 488 | e->setFlag(QGraphicsItem::ItemIsMovable, true); 489 | e->setFlag(QGraphicsItem::ItemIsSelectable, true); 490 | addItem(e); 491 | emit itemAdded(e); 492 | break; 493 | } 494 | case Text::Type: 495 | { 496 | Text *cpy = dynamic_cast(m_copy); 497 | Text *t = new Text(cpy->text(), this); 498 | t->setId(""); 499 | t->setPos(m_copy->pos().x() + 10, m_copy->pos().y() + 10); 500 | t->setFlag(QGraphicsItem::ItemIsMovable, true); 501 | t->setFlag(QGraphicsItem::ItemIsSelectable, true); 502 | t->setScale(cpy->xscale(), cpy->yscale()); 503 | t->setTextcolor(cpy->textcolor()); 504 | addItem(t); 505 | emit itemAdded(t); 506 | break; 507 | } 508 | case Bitmap::Type: 509 | { 510 | Bitmap *bm = dynamic_cast(m_copy); 511 | Bitmap *b = new Bitmap(bm->getImage(), bm->rect().width(), bm->rect().height(), this); 512 | b->setId(""); 513 | b->setPos(m_copy->pos().x() + 10, m_copy->pos().y() + 10); 514 | b->setFlag(QGraphicsItem::ItemIsMovable, true); 515 | b->setFlag(QGraphicsItem::ItemIsSelectable, true); 516 | b->setScale(bm->xscale(), bm->yscale()); 517 | addItem(b); 518 | emit itemAdded(b); 519 | break; 520 | } 521 | case Vectorgraphic::Type: 522 | { 523 | Vectorgraphic *vg = dynamic_cast(m_copy); 524 | Vectorgraphic *v = new Vectorgraphic(vg->getData(), this); 525 | v->setId(""); 526 | v->setPos(m_copy->pos().x() + 10, m_copy->pos().y() + 10); 527 | v->setFlag(QGraphicsItem::ItemIsMovable, true); 528 | v->setFlag(QGraphicsItem::ItemIsSelectable, true); 529 | v->setScale(vg->xscale(), vg->yscale()); 530 | addItem(v); 531 | emit itemAdded(v); 532 | break; 533 | } 534 | } 535 | } 536 | 537 | void AnimationScene::setPlayheadPosition(int val) 538 | { 539 | m_playheadPosition = val; 540 | 541 | for(int i=0; i < items().count(); i++) 542 | { 543 | ResizeableItem *item = dynamic_cast(items().at(i)); 544 | if(item) 545 | { 546 | QHash::iterator it; 547 | for (it = item->keyframes()->begin(); it != item->keyframes()->end(); ++it) 548 | { 549 | KeyFrame *found = NULL; 550 | KeyFrame *first = it.value(); 551 | for(KeyFrame *frame = first; frame != NULL; frame = frame->next()) 552 | { 553 | if((frame == first && val < first->time()) || frame->time() <= val) 554 | found = frame; 555 | } 556 | if(found) 557 | { 558 | QString propertyName = it.key(); 559 | qreal value; 560 | if(found->easing() >= 0) 561 | { 562 | QEasingCurve easing((QEasingCurve::Type)found->easing()); 563 | qreal progress = 1.0 / (found->next()->time() - found->time()) * (val - found->time()); 564 | qreal progressValue = easing.valueForProgress(progress); 565 | value = found->value().toReal() + (found->next()->value().toReal() - found->value().toReal()) / 1.0 * progressValue; 566 | } 567 | else 568 | value = found->value().toReal(); 569 | if(propertyName == "left") 570 | item->setX(value); 571 | else if(propertyName == "top") 572 | item->setY(value); 573 | else if(propertyName == "width") 574 | item->setWidth(value); 575 | else if(propertyName == "height") 576 | item->setHeight(value); 577 | else if(propertyName == "opacity") 578 | item->setOpacity(value); 579 | } 580 | } 581 | } 582 | } 583 | } 584 | 585 | QDataStream& operator <<(QDataStream &out, const AnimationScene *s) 586 | { 587 | return s->write(out); 588 | } 589 | 590 | QDataStream& operator >>(QDataStream &in, AnimationScene *s) 591 | { 592 | return s->read(in); 593 | } 594 | 595 | QString getItemTypeName(ResizeableItem *item) 596 | { 597 | switch(item->type()) 598 | { 599 | case Rectangle::Type: 600 | { 601 | return QString("Rectangle"); 602 | } 603 | case Ellipse::Type: 604 | { 605 | return QString("Ellipse"); 606 | } 607 | case Text::Type: 608 | { 609 | return QString("Text"); 610 | } 611 | case Bitmap::Type: 612 | { 613 | return QString("Bitmap"); 614 | } 615 | case Vectorgraphic::Type: 616 | { 617 | return QString("Vectorgraphic"); 618 | } 619 | default: 620 | qWarning() << "unknown item type: " << item->type(); 621 | break; 622 | } 623 | return QString(); 624 | } 625 | 626 | bool isAnimationMakerItem(QGraphicsItem *item) 627 | { 628 | switch(item->type()) 629 | { 630 | case Rectangle::Type: 631 | case Ellipse::Type: 632 | case Text::Type: 633 | case Bitmap::Type: 634 | case Vectorgraphic::Type: 635 | return true; 636 | } 637 | return false; 638 | } 639 | --------------------------------------------------------------------------------