Files
MuditaOS/module-apps/application-notes/windows/NotesEditWindow.cpp
Adam Dobrowolski 164b9281c8 EGD-2195 - Changed sizes for fonts in project
* changed all fonts to follow one `Style.hpp` include
* Moved title to AppWindow from all the places in code
* added logging on font selection - when not found
* minor fixes
2019-10-25 13:04:33 +02:00

96 lines
2.4 KiB
C++

/*
* @file NotesEditWindow.cpp
* @author Robert Borzecki (robert.borzecki@mudita.com)
* @date 13 sie 2019
* @brief
* @copyright Copyright (C) 2019 mudita.com
* @details
*/
#include <memory>
#include <functional>
#include "service-appmgr/ApplicationManager.hpp"
#include "bsp/rtc/rtc.hpp"
#include "../ApplicationNotes.hpp"
#include "service-db/messages/DBMessage.hpp"
#include "i18/i18.hpp"
#include "Label.hpp"
#include "Margins.hpp"
#include "Text.hpp"
#include "NotesEditWindow.hpp"
#include <Style.hpp>
UTF8 textString = "Very long test line ABCDEFGHIJKLMNOPQRST123456789\n"
"abcdefghijklmnopqrs 123456789 ABCDEFGHIJKLMONPQRSTUW 12345\n test\nnew line\n\n\n12345";
namespace gui {
NotesEditWindow::NotesEditWindow( app::Application* app ) :
AppWindow(app,"EditWindow") {
setSize( 480, 600 );
buildInterface();
}
void NotesEditWindow::rebuild() {
destroyInterface();
buildInterface();
}
void NotesEditWindow::buildInterface() {
AppWindow::buildInterface();
bottomBar->setActive( BottomBar::Side::CENTER, true );
bottomBar->setActive( BottomBar::Side::RIGHT, true );
bottomBar->setText( BottomBar::Side::CENTER, utils::localize.get("app_notes_save"));
bottomBar->setText( BottomBar::Side::RIGHT, utils::localize.get("app_notes_back"));
setTitle(utils::localize.get("app_notes_new_note"));
text = new gui::Text( this, 11, 105, 480-22, 600-105-50 );
text->setFont(style::window::font::medium);
text->setRadius(5);
text->setMargins( gui::Margins(10, 5, 10, 5));
text->activatedCallback = [=] (gui::Item& item){
UTF8 getstr = text->getText();
time_t timestamp;
bsp::rtc_GetCurrentTimestamp(&timestamp);
UTF8 filename = "sys/data/applications/notes/" + std::to_string(timestamp) + ".txt";
auto file = vfs.fopen( filename.c_str(), "wb" );
vfs.fwrite( getstr.c_str(), getstr.used()-1, 1, file );
vfs.fclose( file );
return true; };
text->setTextType( gui::Text::TextType::MULTI_LINE );
text->setEditMode(gui::Text::EditMode::BROWSE );
topBar->setActive(TopBar::Elements::TIME, true );
}
void NotesEditWindow::destroyInterface() {
AppWindow::destroyInterface();
if( text ) { removeWidget(text); delete text; text = nullptr; }
children.clear();
}
NotesEditWindow::~NotesEditWindow() {
destroyInterface();
}
void NotesEditWindow::onBeforeShow( ShowMode mode, SwitchData* data ) {
application->setKeyboardProfile( "lang_eng_lower" );
text->setText( textString );
setFocusItem( text );
}
} /* namespace gui */