Panel.h
1 /* Copyright (C) 2015-2017 Marc Boris Duerner
2  Copyright (C) 2015 Laurentiu-Gheorghe Crisan
3 
4  This library is free software; you can redistribute it and/or
5  modify it under the terms of the GNU Lesser General Public
6  License as published by the Free Software Foundation; either
7  version 2.1 of the License, or (at your option) any later version.
8 
9  As a special exception, you may use this file as part of a free
10  software library without restriction. Specifically, if other files
11  instantiate templates or use macros or inline functions from this
12  file, or you compile this file and link it with other files to
13  produce an executable, this file does not by itself cause the
14  resulting executable to be covered by the GNU General Public
15  License. This exception does not however invalidate any other
16  reasons why the executable file might be covered by the GNU Library
17  General Public License.
18 
19  This library is distributed in the hope that it will be useful,
20  but WITHOUT ANY WARRANTY; without even the implied warranty of
21  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22  Lesser General Public License for more details.
23 
24  You should have received a copy of the GNU Lesser General Public
25  License along with this library; if not, write to the Free Software
26  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
27  MA 02110-1301 USA
28 */
29 
30 #ifndef Pt_Forms_Panel_H
31 #define Pt_Forms_Panel_H
32 
33 #include <Pt/Forms/Control.h>
34 #include <Pt/Forms/Alignment.h>
35 #include <Pt/Forms/PanelStyler.h>
36 #include <Pt/Forms/Icon.h>
37 #include <Pt/Forms/PixmapSurface.h>
38 #include <Pt/Gfx/Color.h>
39 #include <Pt/Gfx/Brush.h>
40 #include <Pt/Gfx/Rect.h>
41 #include <Pt/SmartPtr.h>
42 
43 namespace Pt {
44 
45 namespace Forms {
46 
47 class Painter;
48 
79 class PT_FORMS_API Panel : public Control
80 {
81  typedef Control Base;
82 
83  public:
86  Panel();
87 
90  virtual ~Panel();
91 
97  void setIcon(const Icon& icon, const Gfx::SizeF& iconSize,
99 
102  Control* content() const;
103 
109  void setContent(Control* control);
110 
111  public:
114  const Gfx::Brush* background() const;
115 
118  void setBackground(const Gfx::Brush& b);
119 
122  void setBackground(bool b);
123 
126  const Gfx::Pen* contour() const;
127 
130  void setContour(const Gfx::Pen& pen);
131 
134  void setFrame(bool b);
135 
141  void setRenderer(PanelRenderer* renderer);
142 
143  protected:
146  virtual void onRemoveControl(Control& control);
147 
154  virtual void onInvalidate();
155 
158  virtual void onRescaleEvent(const RescaleEvent& ev);
159 
162  virtual Gfx::SizeF onMeasure(const SizePolicy& policy);
163 
166  virtual void onLayout(const Gfx::RectF& rect);
167 
170  virtual void onPaint(PaintContext& context, const Gfx::RectF& updateRect);
171 
176  virtual void onPaintBackground(PaintContext& context,
177  const Gfx::RectF& rect,
178  const PanelState& state);
179 
184  virtual void onPaintContent(PaintContext& context,
185  const Gfx::RectF& contentRect,
186  const PanelState& state);
187 
192  virtual void onPaintFrame(PaintContext& context,
193  const Gfx::RectF& rect,
194  const PanelState& state);
195 
196  private:
197  PanelState panelState() const;
198 
199  private:
200  Control* _content;
201  PanelStyler _styler;
202  bool _hasBackground;
203  bool _hasFrame;
204  Icon _icon;
205  Gfx::SizeF _iconSize;
206  Gfx::RectF _contentRect;
207  PixmapSurface _picture;
208  Alignment _imageAlignment;
209  bool _iconInvalid;
210 };
211 
212 } // namespace
213 
214 } // namespace
215 
216 #endif
Core module.
Definition: Allocator.h:33
Represents an image at one or more logical sizes.
Definition: Icon.h:144
virtual void onPaintContent(PaintContext &context, const Gfx::RectF &contentRect, const PanelState &state)
Paints the panel content layer.
Attributes for the drawing of outlines.
Definition: Pen.h:54
virtual void onRescaleEvent(const RescaleEvent &ev)
Invalidates a prepared icon after a scale change.
void setFrame(bool b)
Sets whether the panel paints a frame.
virtual void onPaintBackground(PaintContext &context, const Gfx::RectF &rect, const PanelState &state)
Paints the panel background layer.
Control * content() const
Returns the attached content control, or 0.
const Gfx::Brush * background() const
Returns the background brush, or 0 if the fill is off.
virtual void onPaintFrame(PaintContext &context, const Gfx::RectF &rect, const PanelState &state)
Paints the panel frame layer.
void setIcon(const Icon &icon, const Gfx::SizeF &iconSize, Alignment align=Alignment::Center)
Sets the icon painted in the panel.
Active painting session on a Forms paint surface.
Definition: PaintContext.h:51
const Gfx::Pen * contour() const
Returns the contour pen, or 0 if the frame is off.
void setContour(const Gfx::Pen &pen)
Sets the widget-local contour pen to pen and enables the frame.
Size with floating-point width and height.
Definition: Size.h:47
@ Center
Center of the rectangle.
Definition: Alignment.h:85
Panel()
Creates an empty panel.
Reusable view used as application content.
Definition: Control.h:107
void setBackground(bool b)
Sets whether the panel paints a background fill.
Binds a panel-like widget to the current style renderer.
Definition: PanelStyler.h:218
void setContent(Control *control)
Attaches control as the content.
virtual void onPaint(PaintContext &context, const Gfx::RectF &updateRect)
Paints background, content, and frame.
virtual void onRemoveControl(Control &control)
Clears the content pointer when control is detached.
Surface that groups one child behind an optional fill and frame.
Definition: Panel.h:80
Widget that hosts controls on a paint surface.
Definition: View.h:86
virtual ~Panel()
Destroys the panel. The content control is not destroyed.
virtual Gfx::SizeF onMeasure(const SizePolicy &policy)
Measures the content or icon and the frame.
Constraint used when measuring a control.
Definition: SizePolicy.h:48
Renders the look of a panel-like widget.
Definition: PanelStyler.h:93
void setRenderer(PanelRenderer *renderer)
Assigns renderer as the family renderer.
Fill description for shapes and text.
Definition: Brush.h:145
Transient visual state of a panel-like widget.
Definition: PanelStyler.h:48
void setBackground(const Gfx::Brush &b)
Sets the widget-local background brush to b and enables the fill.
Rect with floating-point coordinates.
Definition: Rect.h:47
Off-screen Forms paint surface.
Definition: Pixmap.h:130
Names a position in a rectangle.
Definition: Alignment.h:61
virtual void onInvalidate()
Binds the styler and prepares the icon.
virtual void onLayout(const Gfx::RectF &rect)
Places the content control in the inner rectangle.