diff options
author | dec05eba <dec05eba@protonmail.com> | 2018-10-25 16:19:49 +0200 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2018-10-25 16:19:49 +0200 |
commit | 9096d6ef3710118f98c46f6e7f7689d5aa11c7f4 (patch) | |
tree | 3fe958d79d2771cd8ee26863486eb3dedc1b4b49 /src | |
parent | c50ef935e0792eeb0256ddf5df87af015f3ae1d8 (diff) |
Initial commit
Diffstat (limited to 'src')
-rw-r--r-- | src/ChatMessage.cpp | 22 | ||||
-rw-r--r-- | src/ChatWindow.cpp | 106 | ||||
-rw-r--r-- | src/LoginWindow.cpp | 56 | ||||
-rw-r--r-- | src/Window.cpp | 25 | ||||
-rw-r--r-- | src/main.cpp | 52 |
5 files changed, 253 insertions, 8 deletions
diff --git a/src/ChatMessage.cpp b/src/ChatMessage.cpp new file mode 100644 index 0000000..6dbd671 --- /dev/null +++ b/src/ChatMessage.cpp @@ -0,0 +1,22 @@ +#include "../include/ChatMessage.hpp" + +namespace dchat +{ + ChatMessage::ChatMessage(const Glib::ustring &_username, const Glib::ustring &_text) : + username(_username), + text(_text) + { + username.set_selectable(true); + username.set_alignment(Gtk::ALIGN_START, Gtk::ALIGN_START); + username.get_style_context()->add_class("chat-message-username"); + + text.set_selectable(true); + text.set_alignment(Gtk::ALIGN_START, Gtk::ALIGN_START); + text.set_line_wrap_mode(Pango::WRAP_WORD_CHAR); + text.get_style_context()->add_class("chat-message-text"); + + attach(username, 0, 0, 1, 1); + attach(text, 0, 1, 1, 1); + get_style_context()->add_class("chat-message"); + } +}
\ No newline at end of file diff --git a/src/ChatWindow.cpp b/src/ChatWindow.cpp new file mode 100644 index 0000000..a428d0b --- /dev/null +++ b/src/ChatWindow.cpp @@ -0,0 +1,106 @@ +#include "../include/ChatWindow.hpp" +#include "../include/ChatMessage.hpp" +#include <gtkmm/alignment.h> + +namespace dchat +{ + ChatWindow::ChatWindow() + { + setupTopBar(); + + Gtk::Paned *sidePanels = Gtk::manage(new Gtk::Paned()); + sidePanels->set_name("side-panels"); + sidePanels->set_border_width(0); + attach(*sidePanels, 0, 1, 1, 2); + + setupLeftPanel(sidePanels); + + Gtk::Grid *rightPanel = Gtk::manage(new Gtk::Grid()); + rightPanel->set_hexpand(true); + sidePanels->add2(*rightPanel); + + setupMessageArea(rightPanel); + setupChatInput(rightPanel); + + set_vexpand(true); + set_hexpand(true); + } + + void ChatWindow::setupTopBar() + { + topbar.set_name("top-bar"); + topbar.set_hexpand(true); + attach(topbar, 0, 0, 2, 1); + + topbarSearchBar.set_size_request(175); + topbarSearchBar.set_name("top-bar-search"); + topbarSearchBar.set_placeholder_text("Search..."); + topbar.attach(topbarSearchBar, 0, 0, 1, 1); + + Gtk::Alignment *topbarSpacer = Gtk::manage(new Gtk::Alignment()); + topbarSpacer->set_size_request(50); + topbar.attach_next_to(*topbarSpacer, topbarSearchBar, Gtk::POS_RIGHT, 1, 1); + + currentChannelTitle.set_text("Linux"); + currentChannelTitle.set_name("current-channel-title"); + topbar.attach_next_to(currentChannelTitle, *topbarSpacer, Gtk::POS_RIGHT, 1, 1); + } + + void ChatWindow::setupLeftPanel(Gtk::Paned *sidePanels) + { + Gtk::Paned *leftPanel = Gtk::manage(new Gtk::Paned(Gtk::ORIENTATION_VERTICAL)); + leftPanel->set_size_request(200); + leftPanel->set_name("left-panel"); + leftPanel->set_vexpand(true); + sidePanels->add1(*leftPanel); + + Gtk::Grid *leftPanelChannels = Gtk::manage(new Gtk::Grid()); + leftPanelChannels->set_vexpand(true); + leftPanel->add1(*leftPanelChannels); + + Gtk::Label *channelsTitle = Gtk::manage(new Gtk::Label()); + channelsTitle->set_name("channels-title"); + channelsTitle->set_text("Channels"); + leftPanelChannels->attach(*channelsTitle, 0, 0, 1, 1); + + //// + Gtk::Grid *leftPanelUsers = Gtk::manage(new Gtk::Grid()); + leftPanelUsers->set_vexpand(true); + leftPanel->add2(*leftPanelUsers); + + Gtk::Label *usersTitle = Gtk::manage(new Gtk::Label()); + usersTitle->set_name("users-title"); + usersTitle->set_text("Users"); + leftPanelUsers->attach(*usersTitle, 0, 0, 1, 1); + } + + void ChatWindow::setupMessageArea(Gtk::Grid *rightPanel) + { + chatArea.set_vexpand(true); + rightPanel->attach(chatArea, 0, 0, 1, 2); + + Gtk::Grid *chatAreaLayout = Gtk::manage(new Gtk::Grid()); + chatAreaLayout->set_name("chat-area-layout"); + chatArea.add(*chatAreaLayout); + + for(int i = 0; i < 100; ++i) + { + ChatMessage *message = Gtk::manage(new ChatMessage("Arezu", "hellooooo" + std::to_string(i))); + message->set_valign(Gtk::Align::ALIGN_START); + message->set_hexpand(true); + chatAreaLayout->attach(*message, 0, i, 1, 1); + } + } + + void ChatWindow::setupChatInput(Gtk::Grid *rightPanel) + { + Gtk::ScrolledWindow *chatScrollWindow = Gtk::manage(new Gtk::ScrolledWindow()); + chatScrollWindow->set_name("chat-scroll-view"); + rightPanel->attach_next_to(*chatScrollWindow, chatArea, Gtk::POS_BOTTOM, 1, 1); + + chatInput.set_hexpand(true); + chatInput.set_name("chat-input"); + chatInput.set_wrap_mode(Gtk::WrapMode::WRAP_WORD_CHAR); + chatScrollWindow->add(chatInput); + } +}
\ No newline at end of file diff --git a/src/LoginWindow.cpp b/src/LoginWindow.cpp new file mode 100644 index 0000000..4232982 --- /dev/null +++ b/src/LoginWindow.cpp @@ -0,0 +1,56 @@ +#include "../include/LoginWindow.hpp" +#include <gtkmm/label.h> +#include <gtkmm/entry.h> +#include <gtkmm/alignment.h> +#include <gtkmm/button.h> +#include <cassert> + +namespace dchat +{ + LoginWindow::LoginWindow() : + loginButton("Login") + { + Gtk::Label *username = Gtk::manage(new Gtk::Label()); + username->set_text("Username"); + username->set_halign(Gtk::ALIGN_START); + attach(*username, 0, 0, 1, 1); + + usernameInput.set_size_request(200); + attach_next_to(usernameInput, *username, Gtk::POS_BOTTOM, 3, 1); + + Gtk::Alignment *usernamePasswordSpacer = Gtk::manage(new Gtk::Alignment()); + usernamePasswordSpacer->set_size_request(-1, 35); + attach_next_to(*usernamePasswordSpacer, usernameInput, Gtk::POS_BOTTOM, 1, 1); + + Gtk::Label *password = Gtk::manage(new Gtk::Label()); + password->set_text("Password"); + password->set_halign(Gtk::ALIGN_START); + attach_next_to(*password, *usernamePasswordSpacer, Gtk::POS_BOTTOM, 1, 1); + + passwordInput.set_visibility(false); + passwordInput.set_size_request(200); + attach_next_to(passwordInput, *password, Gtk::POS_BOTTOM, 3, 1); + + Gtk::Alignment *loginButtonSpacerTop = Gtk::manage(new Gtk::Alignment()); + loginButtonSpacerTop->set_size_request(-1, 20); + attach_next_to(*loginButtonSpacerTop, passwordInput, Gtk::POS_BOTTOM, 1, 1); + + Gtk::Alignment *loginButtonSpacer = Gtk::manage(new Gtk::Alignment()); + attach_next_to(*loginButtonSpacer, *loginButtonSpacerTop, Gtk::POS_BOTTOM, 2, 1); + + loginButton.set_halign(Gtk::ALIGN_END); + attach_next_to(loginButton, *loginButtonSpacer, Gtk::POS_RIGHT, 1, 1); + + set_halign(Gtk::ALIGN_CENTER); + set_valign(Gtk::ALIGN_CENTER); + get_style_context()->add_class("login-window"); + } + + void LoginWindow::setLoginHandler(std::function<void()> loginHandler) + { + assert(loginHandler); + usernameInput.signal_activate().connect(loginHandler); + passwordInput.signal_activate().connect(loginHandler); + loginButton.signal_clicked().connect(loginHandler); + } +}
\ No newline at end of file diff --git a/src/Window.cpp b/src/Window.cpp new file mode 100644 index 0000000..c912130 --- /dev/null +++ b/src/Window.cpp @@ -0,0 +1,25 @@ +#include "../include/Window.hpp" + +namespace dchat +{ + Window::Window() + { + set_border_width(0); + add(stack); + + stack.add(loginWindow, "login"); + stack.add(chatWindow, "chat"); + + show_all_children(); + + loginWindow.setLoginHandler([] + { + printf("login!\n"); + }); + } + + Window::~Window() + { + + } +}
\ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index e085836..d83fd27 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,13 +1,49 @@ -#include <gtkmm.h> +#include "../include/Window.hpp" +#include <gtkmm/application.h> +#include <gtkmm/cssprovider.h> +#include <odhtdb/Database.hpp> -int main(int argc, char *argv[]) +int main (int argc, char *argv[]) { - auto app = - Gtk::Application::create(argc, argv, - "org.gtkmm.examples.base"); + auto app = Gtk::Application::create(argc, argv, "dec05eba.dchat"); - Gtk::Window window; - window.set_default_size(200, 200); + auto css = Gtk::CssProvider::create(); + try + { + if(!css->load_from_path("css/style.css")) + { + fprintf(stderr, "Failed to load css/style.css"); + return 1; + } + } + catch(Gtk::CssProviderError &e) + { + fprintf(stderr, "Failed to load css/style.css, error: %s\n", e.what().c_str()); + return 1; + } - return app->run(window); + dchat::Window window; + auto ctx = window.get_style_context(); + auto screen = Gdk::Screen::get_default(); + ctx->add_provider_for_screen(screen, css, GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); + + odhtdb::DatabaseCallbackFuncs callbackFuncs; + callbackFuncs.createNodeCallbackFunc = [](const odhtdb::DatabaseCreateNodeRequest &request) + { + + }; + + callbackFuncs.addNodeCallbackFunc = [](const odhtdb::DatabaseAddNodeRequest &request) + { + + }; + + callbackFuncs.addUserCallbackFunc = [](const odhtdb::DatabaseAddUserRequest &request) + { + + }; + + //odhtdb::Database database("206.189.13.66", 27130, "/tmp/dchat_gtk", callbackFuncs); + + return app->run(window); } |