mirror of
https://github.com/mudita/MuditaOS.git
synced 2026-04-20 23:17:35 -04:00
76 lines
3.3 KiB
C++
76 lines
3.3 KiB
C++
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
|
|
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
|
|
|
|
#include "CalculatorMainWindow.hpp"
|
|
#include "application-calculator/widgets/CalculatorStyle.hpp"
|
|
#include "application-calculator/data/CalculatorInputProcessorText.hpp"
|
|
#include <i18n/i18n.hpp>
|
|
|
|
namespace gui
|
|
{
|
|
|
|
CalculatorMainWindow::CalculatorMainWindow(app::Application *app, std::string name) : AppWindow(app, name)
|
|
{
|
|
buildInterface();
|
|
}
|
|
|
|
void CalculatorMainWindow::buildInterface()
|
|
{
|
|
AppWindow::buildInterface();
|
|
|
|
setTitle(utils::localize.get("app_calculator_title_main"));
|
|
|
|
bottomBar->setActive(gui::BottomBar::Side::CENTER, true);
|
|
bottomBar->setActive(gui::BottomBar::Side::RIGHT, true);
|
|
bottomBar->setActive(gui::BottomBar::Side::LEFT, true);
|
|
bottomBar->setText(gui::BottomBar::Side::RIGHT, utils::localize.get(style::strings::common::back));
|
|
bottomBar->setText(gui::BottomBar::Side::CENTER, utils::localize.get(style::calculator::equals));
|
|
bottomBar->setText(gui::BottomBar::Side::LEFT, utils::localize.get(style::calculator::decimal_separator));
|
|
bottomBar->setFont(BottomBar::Side::LEFT, style::window::font::largelight);
|
|
|
|
mathOperationInput = new gui::Text(this,
|
|
style::calculator::window::input_margin,
|
|
style::calculator::window::input_offset_top,
|
|
style::calculator::window::input_width,
|
|
style::calculator::window::input_height);
|
|
mathOperationInput->setEdges(gui::RectangleEdge::Bottom);
|
|
mathOperationInput->setAlignment(
|
|
gui::Alignment(gui::Alignment::Horizontal::Right, gui::Alignment::Vertical::Center));
|
|
mathOperationInput->setFont(style::window::font::supersizemelight);
|
|
mathOperationInput->setPenFocusWidth(style::window::default_border_focus_w);
|
|
mathOperationInput->setPenWidth(style::window::default_border_rect_no_focus);
|
|
mathOperationInput->setEditMode(gui::EditMode::Edit);
|
|
|
|
mathBox = new gui::MathOperationsBox(this,
|
|
style::calculator::window::math_box_offset_top,
|
|
style::window::default_body_width,
|
|
style::calculator::window::math_box_height,
|
|
style::calculator::window::math_box_cell_width,
|
|
style::calculator::window::math_box_cell_height);
|
|
addWidget(mathBox);
|
|
setFocusItem(mathOperationInput);
|
|
|
|
setupInputProcessing();
|
|
}
|
|
|
|
void CalculatorMainWindow::setupInputProcessing()
|
|
{
|
|
inputProcessor = std::make_unique<calc::InputProcessorText>(gsl::make_strict_not_null(mathOperationInput));
|
|
|
|
mathOperationInput->setInputMode(new InputMode({InputMode::digit}));
|
|
mathOperationInput->inputCallback = [&](Item &, const InputEvent &event) {
|
|
return inputProcessor->handle(event);
|
|
};
|
|
}
|
|
|
|
bool CalculatorMainWindow::onInput(const gui::InputEvent &inputEvent)
|
|
{
|
|
if (AppWindow::onInput(inputEvent)) {
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
} // namespace gui
|