add todo setup
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
|
||||
#include "widgets/date.hpp"
|
||||
#include "widgets/spacer.hpp"
|
||||
#include "widgets/todo.hpp"
|
||||
#include "widgets/todoPopover.hpp"
|
||||
#include "widgets/volumeWidget.hpp"
|
||||
#include "widgets/workspaceIndicator.hpp"
|
||||
|
||||
@@ -40,8 +40,8 @@ Bar::Bar(GdkMonitor *monitor, HyprlandService &hyprlandService,
|
||||
set_child(main_box);
|
||||
|
||||
this->volumeWidget = Gtk::make_managed<VolumeWidget>();
|
||||
workspaceIndicator = Gtk::make_managed<WorkspaceIndicator>(hyprlandService, monitorId);
|
||||
trayWidget = Gtk::make_managed<TrayWidget>(trayService);
|
||||
this->workspaceIndicator = Gtk::make_managed<WorkspaceIndicator>(hyprlandService, monitorId);
|
||||
this->trayWidget = Gtk::make_managed<TrayWidget>(trayService);
|
||||
|
||||
load_css();
|
||||
setup_ui();
|
||||
@@ -73,7 +73,7 @@ void Bar::setup_left_box() {
|
||||
void Bar::setup_center_box() {
|
||||
center_box.set_hexpand(false);
|
||||
|
||||
center_box.append(*(new Todo("\uf23a", "To-Do")));
|
||||
center_box.append(*(new TodoPopover("\uf23a", "To-Do")));
|
||||
center_box.append(*(new Spacer()));
|
||||
center_box.append(this->date);
|
||||
center_box.append(*(new Spacer()));
|
||||
|
||||
45
src/components/todoEntry.cpp
Normal file
45
src/components/todoEntry.cpp
Normal file
@@ -0,0 +1,45 @@
|
||||
#include "components/todoEntry.hpp"
|
||||
|
||||
#include <gtkmm/label.h>
|
||||
|
||||
#include "gtkmm/button.h"
|
||||
|
||||
TodoEntry::TodoEntry(int id, std::string text, sigc::signal<void(int)> signal_dismissed)
|
||||
: Gtk::Box(Gtk::Orientation::HORIZONTAL) {
|
||||
this->id = id;
|
||||
this->signal_dismissed = signal_dismissed;
|
||||
|
||||
|
||||
auto box = Gtk::make_managed<Gtk::Box>(Gtk::Orientation::HORIZONTAL);
|
||||
box->set_hexpand(true);
|
||||
box->set_halign(Gtk::Align::START);
|
||||
box->set_valign(Gtk::Align::CENTER);
|
||||
box->set_name("todo-entry-box");
|
||||
box->add_css_class("todo-entry-box");
|
||||
append(*box);
|
||||
|
||||
auto label = Gtk::make_managed<Gtk::Label>(text);
|
||||
label->set_halign(Gtk::Align::START);
|
||||
label->set_valign(Gtk::Align::CENTER);
|
||||
box->append(*label);
|
||||
|
||||
auto buttonBox = Gtk::make_managed<Gtk::Box>(Gtk::Orientation::HORIZONTAL);
|
||||
buttonBox->set_halign(Gtk::Align::END);
|
||||
buttonBox->set_valign(Gtk::Align::CENTER);
|
||||
append(*buttonBox);
|
||||
|
||||
auto dismissButton = Gtk::make_managed<Gtk::Button>("\uf00d");
|
||||
dismissButton->set_valign(Gtk::Align::CENTER);
|
||||
dismissButton->set_tooltip_text("Dismiss");
|
||||
|
||||
dismissButton->signal_clicked().connect(sigc::mem_fun(*this, &TodoEntry::on_dismiss_clicked));
|
||||
|
||||
buttonBox->append(*dismissButton);
|
||||
}
|
||||
|
||||
TodoEntry::~TodoEntry() {
|
||||
}
|
||||
|
||||
void TodoEntry::on_dismiss_clicked() {
|
||||
this->signal_dismissed.emit(this->id);
|
||||
}
|
||||
56
src/services/todo.cpp
Normal file
56
src/services/todo.cpp
Normal file
@@ -0,0 +1,56 @@
|
||||
#include "services/todo.hpp"
|
||||
#include "components/todoEntry.hpp"
|
||||
#include "gtkmm/object.h"
|
||||
#include <cassert>
|
||||
#include <iostream>
|
||||
|
||||
TodoService::TodoService(sigc::signal<void()> refreshSignal) {
|
||||
this->refreshSignal = refreshSignal;
|
||||
this->init();
|
||||
}
|
||||
|
||||
TodoService::~TodoService() {}
|
||||
|
||||
std::map<int, TodoEntry *> TodoService::getTodos() {
|
||||
return this->todos;
|
||||
}
|
||||
|
||||
void TodoService::init() {
|
||||
std::vector<std::string> items = {
|
||||
"Buy groceries",
|
||||
"Finish the report",
|
||||
"Call Alice",
|
||||
"Schedule dentist appointment"};
|
||||
|
||||
for (auto item : items) {
|
||||
this->addTodo(item, false);
|
||||
}
|
||||
}
|
||||
|
||||
void TodoService::removeTodo(int id) {
|
||||
if (todos.find(id) == todos.end()) {
|
||||
std::cerr << "Todo with id " << id << " not found!" << std::endl;
|
||||
assert(false);
|
||||
}
|
||||
|
||||
todos.erase(id);
|
||||
|
||||
this->refreshSignal.emit();
|
||||
}
|
||||
|
||||
TodoEntry *TodoService::addTodo(std::string text, bool emitSignal) {
|
||||
auto signal = sigc::signal<void(int)>();
|
||||
signal.connect(sigc::mem_fun(*this, &TodoService::removeTodo));
|
||||
TodoEntry *todo = Gtk::make_managed<TodoEntry>(nextId, text, signal);
|
||||
|
||||
todos[nextId] = todo;
|
||||
|
||||
nextId++;
|
||||
|
||||
if (emitSignal) {
|
||||
this->refreshSignal.emit();
|
||||
}
|
||||
return todo;
|
||||
}
|
||||
|
||||
void TodoService::updateTodo(int id, std::string text) {}
|
||||
@@ -1,9 +0,0 @@
|
||||
#include <gtkmm/label.h>
|
||||
|
||||
#include "widgets/todo.hpp"
|
||||
|
||||
Todo::Todo(std::string icon, std::string title) : Popover(icon, title) {
|
||||
auto label = Gtk::make_managed<Gtk::Label>(title);
|
||||
label->add_css_class("todo-label");
|
||||
this->set_popover_child(*label);
|
||||
}
|
||||
78
src/widgets/todoPopover.cpp
Normal file
78
src/widgets/todoPopover.cpp
Normal file
@@ -0,0 +1,78 @@
|
||||
#include "widgets/todoPopover.hpp"
|
||||
|
||||
#include <gtkmm/box.h>
|
||||
#include <gtkmm/entry.h>
|
||||
#include <string>
|
||||
|
||||
TodoPopover::TodoPopover(std::string icon, std::string title) : Popover(icon, title) {
|
||||
this->name = title;
|
||||
this->popover->set_size_request(300, -1);
|
||||
|
||||
container.set_orientation(Gtk::Orientation::VERTICAL);
|
||||
container.set_spacing(10);
|
||||
container.add_css_class("todo-popover-container");
|
||||
|
||||
|
||||
auto entry = Gtk::make_managed<Gtk::Entry>();
|
||||
entry->set_placeholder_text("Enter your to-do item...");
|
||||
entry->add_css_class("todo-input");
|
||||
entry->set_hexpand(true);
|
||||
entry->set_halign(Gtk::Align::FILL);
|
||||
entry->set_valign(Gtk::Align::START);
|
||||
|
||||
inputArea.append(*entry);
|
||||
inputArea.add_css_class("todo-input-area");
|
||||
inputArea.set_hexpand(true);
|
||||
inputArea.set_halign(Gtk::Align::FILL);
|
||||
|
||||
entry->signal_activate().connect([this, entry]() {
|
||||
std::string text = entry->get_text();
|
||||
if (!text.empty()) {
|
||||
this->todoService->addTodo(text);
|
||||
}
|
||||
});
|
||||
|
||||
container.append(inputArea);
|
||||
|
||||
this->todoList = Gtk::make_managed<Gtk::Box>(Gtk::Orientation::VERTICAL);
|
||||
container.append(*todoList);
|
||||
todoList->add_css_class("todo-list");
|
||||
|
||||
auto signal = sigc::signal<void()>();
|
||||
this->todoService = new TodoService(signal);
|
||||
|
||||
signal.connect(sigc::mem_fun(*this, &TodoPopover::update));
|
||||
|
||||
this->set_popover_child(this->container);
|
||||
this->update();
|
||||
}
|
||||
|
||||
void TodoPopover::update() {
|
||||
auto todos = this->todoService->getTodos();
|
||||
|
||||
Gtk::Widget* child = todoList->get_first_child();
|
||||
|
||||
while (child) {
|
||||
Gtk::Widget* next = child->get_next_sibling();
|
||||
|
||||
bool found = false;
|
||||
for (auto& [id, todo] : todos) {
|
||||
if (child == todo) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!found) {
|
||||
todoList->remove(*child);
|
||||
}
|
||||
|
||||
child = next;
|
||||
}
|
||||
|
||||
for (auto &[id, todo] : todos) {
|
||||
if (todo->get_parent() == nullptr) {
|
||||
todoList->append(*todo);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
#include "widgets/webWidget.hpp"
|
||||
#include <gtkmm/box.h>
|
||||
#include <gtkmm/label.h>
|
||||
#include <webkit/webkit.h>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user