LibrePCB Developers Documentation
Loading...
Searching...
No Matches
imagehelpers.h
Go to the documentation of this file.
1/*
2 * LibrePCB - Professional EDA for everyone!
3 * Copyright (C) 2013 LibrePCB Developers, see AUTHORS.md for contributors.
4 * https://librepcb.org/
5 *
6 * This program 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 * This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#ifndef LIBREPCB_EDITOR_IMAGEHELPERS_H
21#define LIBREPCB_EDITOR_IMAGEHELPERS_H
22
23/*******************************************************************************
24 * Includes
25 ******************************************************************************/
28
29#include <QtCore>
30
31#include <optional>
32
33/*******************************************************************************
34 * Namespace / Forward Declarations
35 ******************************************************************************/
36namespace librepcb {
37
38class TransactionalDirectory;
39
40namespace editor {
41
42/*******************************************************************************
43 * Class ImageHelpers
44 ******************************************************************************/
45
51class ImageHelpers final {
52 Q_DECLARE_TR_FUNCTIONS(ImageHelpers)
53
54public:
55 // Types
56 enum class Target { Symbol, Project };
57
58 // Constructors / Destructor
59 ImageHelpers() = delete;
60 ImageHelpers(const ImageHelpers& other) = delete;
61 ~ImageHelpers() = delete;
62
63 // Operator Overloadings
64 ImageHelpers& operator=(const ImageHelpers& rhs) = delete;
65
66 // Static Methods
67
77 static std::optional<FileProofName> findExistingFile(
78 const TransactionalDirectory& dir, const QByteArray& data);
79
99 QString nameUserInput,
100 const QString& extension);
101
122 static bool execImageChooserDialog(QByteArray& data, QString& format,
123 QString& basename,
124 const QString& settingsKey);
125
143 static std::optional<FileProofName> findExistingOrAskForNewImageFileName(
144 const TransactionalDirectory& dir, Target target, const QByteArray& data,
145 const QString& format, const QString& basename, bool& exists);
146
160 static bool isImageInClipboard() noexcept;
161
180 static bool getImageFromClipboard(QByteArray& data, QString& format,
181 QString& basename) noexcept;
182};
183
184/*******************************************************************************
185 * End of File
186 ******************************************************************************/
187
188} // namespace editor
189} // namespace librepcb
190
191#endif
The Project class represents a whole (opened) project with all its content.
Definition project.h:71
Helper class to access a subdirectory of TransactionalFileSystem.
Definition transactionaldirectory.h:51
Various editor helper functions for working with librepcb::Image.
Definition imagehelpers.h:51
static bool isImageInClipboard() noexcept
Check if the clipboard contains any kind of image.
Definition imagehelpers.cpp:214
static bool getImageFromClipboard(QByteArray &data, QString &format, QString &basename) noexcept
Try to get the image from the clipboard.
Definition imagehelpers.cpp:241
ImageHelpers & operator=(const ImageHelpers &rhs)=delete
static std::optional< FileProofName > findExistingOrAskForNewImageFileName(const TransactionalDirectory &dir, Target target, const QByteArray &data, const QString &format, const QString &basename, bool &exists)
Determine the filename of an image to be added to a directory.
Definition imagehelpers.cpp:173
Target
Definition imagehelpers.h:56
static std::optional< FileProofName > findExistingFile(const TransactionalDirectory &dir, const QByteArray &data)
Find a file with specific content in a directory.
Definition imagehelpers.cpp:100
static bool execImageChooserDialog(QByteArray &data, QString &format, QString &basename, const QString &settingsKey)
Execute "open file" dialog to choose an image.
Definition imagehelpers.cpp:138
ImageHelpers(const ImageHelpers &other)=delete
static FileProofName getUnusedFileName(const TransactionalDirectory &dir, QString nameUserInput, const QString &extension)
Build a valid filename for an image file to be created.
Definition imagehelpers.cpp:113
Definition occmodel.cpp:77
type_safe::constrained_type< QString, FileProofNameConstraint, FileProofNameVerifier > FileProofName
Definition fileproofname.h:90