Icon.h
1 /* Copyright (C) 2019 Marc Boris Duerner
2 
3  This library is free software; you can redistribute it and/or
4  modify it under the terms of the GNU Lesser General Public
5  License as published by the Free Software Foundation; either
6  version 2.1 of the License, or (at your option) any later version.
7 
8  As a special exception, you may use this file as part of a free
9  software library without restriction. Specifically, if other files
10  instantiate templates or use macros or inline functions from this
11  file, or you compile this file and link it with other files to
12  produce an executable, this file does not by itself cause the
13  resulting executable to be covered by the GNU General Public
14  License. This exception does not however invalidate any other
15  reasons why the executable file might be covered by the GNU Library
16  General Public License.
17 
18  This library is distributed in the hope that it will be useful,
19  but WITHOUT ANY WARRANTY; without even the implied warranty of
20  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21  Lesser General Public License for more details.
22 
23  You should have received a copy of the GNU Lesser General Public
24  License along with this library; if not, write to the Free Software
25  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
26  MA 02110-1301 USA
27 */
28 
29 #ifndef Pt_Forms_Icon_h
30 #define Pt_Forms_Icon_h
31 
32 #include <Pt/Forms/Api.h>
33 #include <Pt/Gfx/Size.h>
34 #include <Pt/Gfx/Image.h>
35 #include <Pt/System/Path.h>
36 
37 #include <vector>
38 
39 namespace Pt {
40 
41 namespace Forms {
42 
43 class IconImpl;
44 
45 class PT_FORMS_API IconProvider
46 {
47  friend class IconImpl;
48 
49  public:
50  IconProvider();
51 
52  virtual ~IconProvider();
53 
54  virtual bool empty() const = 0;
55 
56  virtual void clear() = 0;
57 
58  virtual void addImage(const Gfx::SizeF& size, const Gfx::Image& image) = 0;
59 
60  virtual void addImage(const Gfx::SizeF& size, const System::Path& path) = 0;
61 
62  virtual Gfx::SizeF minimumSize() const = 0;
63 
64  virtual Gfx::SizeF maximumSize() const = 0;
65 
66  virtual const Gfx::Image& getImage(const Gfx::SizeF& area) = 0;
67 
68  private:
69  void attachIcon(IconImpl* parent);
70 
71  void detachIcon(IconImpl* parent);
72 
73  private:
74  std::vector<IconImpl*> _icons;
75 };
76 
77 
78 class PT_FORMS_API Icon
79 {
80  public:
81  Icon();
82 
83  Icon(const Icon& icon);
84 
85  Icon(IconProvider& provider);
86 
87  ~Icon();
88 
89  Icon& operator=(const Icon& icon);
90 
91  bool empty() const;
92 
93  void clear();
94 
95  void addImage(const Gfx::Image& image);
96 
97  void addImage(const Gfx::SizeF& size, const Gfx::Image& image);
98 
99  void addImage(const Gfx::SizeF& size, const System::Path& path);
100 
101  void addImage(double width, double height, const System::Path& path);
102 
103  const Gfx::Image& getImage(const Gfx::SizeF& area) const;
104 
105  Gfx::SizeF minimumSize() const;
106 
107  Gfx::SizeF maximumSize() const;
108 
109  private:
110  void detach();
111 
112  private:
113  mutable class IconImpl* _impl;
114 };
115 
116 } // namespace
117 
118 } // namespace
119 
120 #endif