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/Pixmap.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
43namespace Pt {
44
45namespace Forms {
46
47class Painter;
48
79class PT_FORMS_API Panel : public Control
80{
81 typedef Control Base;
82
83 public:
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 Pixmap _picture;
208 Alignment _imageAlignment;
209 bool _iconInvalid;
210};
211
212} // namespace
213
214} // namespace
215
216#endif
Names a position in a rectangle.
Definition Alignment.h:61
@ Center
Center of the rectangle.
Definition Alignment.h:85
Control()
Creates an unparented control.
Represents an image at one or more logical sizes.
Definition Icon.h:144
Active painting session on a Forms paint surface.
Definition PaintContext.h:51
Draws on a Forms paint surface or paint context.
Definition Painter.h:53
Renders the look of a panel-like widget.
Definition PanelStyler.h:93
Transient visual state of a panel-like widget.
Definition PanelStyler.h:48
Binds a panel-like widget to the current style renderer.
Definition PanelStyler.h:218
Panel()
Creates an empty panel.
virtual ~Panel()
Destroys the panel. The content control is not destroyed.
void setIcon(const Icon &icon, const Gfx::SizeF &iconSize, Alignment align=Alignment::Center)
Sets the icon painted in the panel.
virtual void onPaint(PaintContext &context, const Gfx::RectF &updateRect)
Paints background, content, and frame.
virtual void onRescaleEvent(const RescaleEvent &ev)
Invalidates a prepared icon after a scale change.
void setBackground(bool b)
Sets whether the panel paints a background fill.
virtual void onPaintBackground(PaintContext &context, const Gfx::RectF &rect, const PanelState &state)
Paints the panel background layer.
const Gfx::Brush * background() const
Returns the background brush, or 0 if the fill is off.
Control * content() const
Returns the attached content control, or 0.
virtual void onPaintContent(PaintContext &context, const Gfx::RectF &contentRect, const PanelState &state)
Paints the panel content layer.
virtual void onPaintFrame(PaintContext &context, const Gfx::RectF &rect, const PanelState &state)
Paints the panel frame layer.
virtual void onLayout(const Gfx::RectF &rect)
Places the content control in the inner rectangle.
void setContent(Control *control)
Attaches control as the content.
void setBackground(const Gfx::Brush &b)
Sets the widget-local background brush to b and enables the fill.
virtual void onRemoveControl(Control &control)
Clears the content pointer when control is detached.
const Gfx::Pen * contour() const
Returns the contour pen, or 0 if the frame is off.
virtual Gfx::SizeF onMeasure(const SizePolicy &policy)
Measures the content or icon and the frame.
void setFrame(bool b)
Sets whether the panel paints a frame.
void setContour(const Gfx::Pen &pen)
Sets the widget-local contour pen to pen and enables the frame.
void setRenderer(PanelRenderer *renderer)
Assigns renderer as the family renderer.
virtual void onInvalidate()
Binds the styler and prepares the icon.
Off-screen Forms paint surface.
Definition Pixmap.h:130
Constraint used when measuring a control.
Definition SizePolicy.h:48
Fill color, gradient or texture.
Definition Brush.h:151
Outline color, width and style.
Definition Pen.h:59
Graphical user interfaces.
Definition ActivateEvent.h:40
Core module.
Definition Allocator.h:33