Pencil2D Animation
Download Community News Docs Contribute

core_lib/src/managers/clipboardmanager.cpp Source File

  • Main Page
  • Related Pages
  • Classes
  • Files
  •  
  • File List
Loading...
Searching...
No Matches
  • core_lib
  • src
  • managers
clipboardmanager.cpp
1/*
2
3Pencil2D - Traditional Animation Software
4Copyright (C) 2005-2007 Patrick Corrieri & Pascal Naidon
5Copyright (C) 2012-2020 Matthew Chiawen Chang
6
7This program is free software; you can redistribute it and/or
8modify it under the terms of the GNU General Public License
9as published by the Free Software Foundation; version 2 of the License.
10
11This program is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16*/
17#include "clipboardmanager.h"
18
19#include <QClipboard>
20
21#include <editor.h>
22
23ClipboardManager::ClipboardManager(Editor* editor) : BaseManager(editor, "ClipboardManager")
24{
25 resetStates();
26}
27
28ClipboardManager::~ClipboardManager()
29{
30
31}
32
33void ClipboardManager::setFromSystemClipboard(const QPointF& pos, const Layer* layer)
34{
35 // We intentially do not call resetStates here because we can only store image changes to the clipboard
36 // otherwise we break pasting for vector.
37 // Only bitmap is supported currently...
38 // Only update clipboard data if it was stored by other applications
39 if (layer->type() != Layer::BITMAP || mClipboard->ownsClipboard()) {
40 return;
41 }
42
43 QImage image = mClipboard->image(QClipboard::Clipboard);
44 if (!image.isNull()) {
45 mBitmapImage = BitmapImage(pos.toPoint()-QPoint(image.size().width()/2, image.size().height()/2), image);
46 }
47}
48
49void ClipboardManager::copyBitmapImage(BitmapImage* bitmapImage, QRectF selectionRect)
50{
51 resetStates();
52 Q_ASSERT(bitmapImage != nullptr && bitmapImage->isLoaded());
53
54 if (!selectionRect.isEmpty())
55 {
56 mBitmapImage = bitmapImage->copy(selectionRect.toRect());
57 }
58 else
59 {
60 mBitmapImage = bitmapImage->copy();
61 }
62
63 mClipboard->setImage(*mBitmapImage.image());
64}
65
66void ClipboardManager::copyVectorImage(const VectorImage* vectorImage)
67{
68 resetStates();
69 if (vectorImage == nullptr || vectorImage->isEmpty()) { return; }
70
71 // FIXME: handle vector selections, ie. independent strokes...
72 mVectorImage = *vectorImage->clone();
73}
74
75void ClipboardManager::copySelectedFrames(const Layer* currentLayer) {
76 resetStates();
77
78 for (int pos : currentLayer->selectedKeyFramesPositions()) {
79 KeyFrame* keyframe = currentLayer->getKeyFrameAt(pos);
80
81 Q_ASSERT(keyframe != nullptr);
82
83 keyframe->loadFile();
84
85 mFrames.insert(std::make_pair(keyframe->pos(), keyframe->clone()));
86 }
87 mFramesType = currentLayer->type();
88}
89
90void ClipboardManager::resetStates()
91{
92 mFrames.clear();
93 mBitmapImage = BitmapImage();
94 mVectorImage = VectorImage();
95 mFramesType = Layer::LAYER_TYPE::UNDEFINED;
96}
BaseManager
Definition: basemanager.h:29
BitmapImage
Definition: bitmapimage.h:27
ClipboardManager::copySelectedFrames
void copySelectedFrames(const Layer *currentLayer)
Copy selected keyframes of any given layer and remember its type.
Definition: clipboardmanager.cpp:75
ClipboardManager::copyVectorImage
void copyVectorImage(const VectorImage *vectorImage)
Copy the entire vector image to clipboard, this operation does not yet support partial selections.
Definition: clipboardmanager.cpp:66
ClipboardManager::resetStates
void resetStates()
This should be called before copying and updating the clipboard to ensure no previous state is saved.
Definition: clipboardmanager.cpp:90
ClipboardManager::copyBitmapImage
void copyBitmapImage(BitmapImage *image, QRectF selectionRect)
Copy bitmap image to clipboard and save its latest position Additionally only a part of the image wil...
Definition: clipboardmanager.cpp:49
Editor
Definition: editor.h:56
KeyFrame
Definition: keyframe.h:30
Layer
Definition: layer.h:38
Layer::selectedKeyFramesPositions
QList< int > selectedKeyFramesPositions() const
Get selected keyframe positions sorted by position.
Definition: layer.h:70
VectorImage
Definition: vectorimage.h:32
QClipboard::Clipboard
Clipboard
QClipboard::image
QImage image(QClipboard::Mode mode) const const
QClipboard::ownsClipboard
bool ownsClipboard() const const
QClipboard::setImage
void setImage(const QImage &image, QClipboard::Mode mode)
QImage
QImage::isNull
bool isNull() const const
QImage::size
QSize size() const const
QPoint
QPointF
QPointF::toPoint
QPoint toPoint() const const
QRectF
QRectF::isEmpty
bool isEmpty() const const
QRectF::toRect
QRect toRect() const const
QSize::height
int height() const const
QSize::width
int width() const const
Generated on Mon Jun 5 2023 19:54:05 for Pencil2D by doxygen 1.9.6 based on revision afd72d68a001f57b4de14011d6ef944ba0717158