2020-01-18 05:38:21 -03:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
|
* All rights reserved.
|
|
|
|
|
*
|
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
|
* modification, are permitted provided that the following conditions are met:
|
|
|
|
|
*
|
|
|
|
|
* 1. Redistributions of source code must retain the above copyright notice, this
|
|
|
|
|
* list of conditions and the following disclaimer.
|
|
|
|
|
*
|
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
|
* this list of conditions and the following disclaimer in the documentation
|
|
|
|
|
* and/or other materials provided with the distribution.
|
|
|
|
|
*
|
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
|
|
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
|
|
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
|
|
|
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
|
|
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
*/
|
|
|
|
|
|
2020-02-06 16:33:02 -03:00
|
|
|
#include <LibGUI/BoxLayout.h>
|
|
|
|
|
#include <LibGUI/Label.h>
|
|
|
|
|
#include <LibGUI/Painter.h>
|
|
|
|
|
#include <LibGUI/ResizeCorner.h>
|
|
|
|
|
#include <LibGUI/StatusBar.h>
|
2020-02-14 19:53:11 -03:00
|
|
|
#include <LibGfx/Palette.h>
|
|
|
|
|
#include <LibGfx/StylePainter.h>
|
2019-02-10 08:07:13 -02:00
|
|
|
|
2020-02-02 11:07:41 -03:00
|
|
|
namespace GUI {
|
|
|
|
|
|
2020-02-23 08:07:13 -03:00
|
|
|
StatusBar::StatusBar(int label_count)
|
2019-02-10 08:07:13 -02:00
|
|
|
{
|
|
|
|
|
set_size_policy(SizePolicy::Fill, SizePolicy::Fixed);
|
2020-04-23 13:51:51 -03:00
|
|
|
set_preferred_size(0, 18);
|
2020-03-04 05:43:54 -03:00
|
|
|
set_layout<HorizontalBoxLayout>();
|
2020-04-23 12:44:49 -03:00
|
|
|
layout()->set_margins({ 0, 0, 0, 0 });
|
2019-03-30 09:12:59 -03:00
|
|
|
layout()->set_spacing(2);
|
2019-10-23 19:43:40 -03:00
|
|
|
|
|
|
|
|
if (label_count < 1)
|
|
|
|
|
label_count = 1;
|
|
|
|
|
|
|
|
|
|
for (auto i = 0; i < label_count; i++)
|
|
|
|
|
m_labels.append(create_label());
|
2019-05-02 20:38:24 -03:00
|
|
|
|
2020-02-23 08:07:13 -03:00
|
|
|
m_corner = add<ResizeCorner>();
|
2019-02-10 08:07:13 -02:00
|
|
|
}
|
|
|
|
|
|
2020-02-02 11:07:41 -03:00
|
|
|
StatusBar::~StatusBar()
|
2019-02-10 08:07:13 -02:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-02 11:07:41 -03:00
|
|
|
NonnullRefPtr<Label> StatusBar::create_label()
|
2019-10-23 19:43:40 -03:00
|
|
|
{
|
2020-03-04 15:07:55 -03:00
|
|
|
auto& label = add<Label>();
|
|
|
|
|
label.set_frame_shadow(Gfx::FrameShadow::Sunken);
|
|
|
|
|
label.set_frame_shape(Gfx::FrameShape::Panel);
|
|
|
|
|
label.set_frame_thickness(1);
|
|
|
|
|
label.set_text_alignment(Gfx::TextAlignment::CenterLeft);
|
2019-10-23 19:43:40 -03:00
|
|
|
return label;
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-02 11:07:41 -03:00
|
|
|
void StatusBar::set_text(const StringView& text)
|
2019-02-10 08:07:13 -02:00
|
|
|
{
|
2019-10-23 19:43:40 -03:00
|
|
|
m_labels.first().set_text(text);
|
2019-02-10 08:07:13 -02:00
|
|
|
}
|
|
|
|
|
|
2020-02-02 11:07:41 -03:00
|
|
|
String StatusBar::text() const
|
2019-02-10 08:07:13 -02:00
|
|
|
{
|
2019-10-23 19:43:40 -03:00
|
|
|
return m_labels.first().text();
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-02 11:07:41 -03:00
|
|
|
void StatusBar::set_text(int index, const StringView& text)
|
2019-10-23 19:43:40 -03:00
|
|
|
{
|
|
|
|
|
m_labels.at(index).set_text(text);
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-02 11:07:41 -03:00
|
|
|
String StatusBar::text(int index) const
|
2019-10-23 19:43:40 -03:00
|
|
|
{
|
|
|
|
|
return m_labels.at(index).text();
|
2019-02-10 08:07:13 -02:00
|
|
|
}
|
|
|
|
|
|
2020-02-02 11:07:41 -03:00
|
|
|
void StatusBar::paint_event(PaintEvent& event)
|
2019-02-10 08:07:13 -02:00
|
|
|
{
|
2020-02-02 11:07:41 -03:00
|
|
|
Painter painter(*this);
|
2019-03-29 11:01:54 -03:00
|
|
|
painter.add_clip_rect(event.rect());
|
2020-04-23 08:53:17 -03:00
|
|
|
painter.fill_rect(rect(), palette().button());
|
2019-02-10 08:07:13 -02:00
|
|
|
}
|
2020-02-02 11:07:41 -03:00
|
|
|
|
|
|
|
|
}
|