Add login screen

This commit is contained in:
daleclack 2022-01-26 20:08:57 +08:00
parent 23fdb549d4
commit 718e91bab8
9 changed files with 181 additions and 134 deletions

View File

@ -22,7 +22,8 @@ pkg_check_modules (GTKMM3 REQUIRED gtkmm-3.0)
include_directories (${GTKMM3_INCLUDE_DIRS})
link_directories (${GTKMM3_LIBRARY_DIRS})
set(SOURCES src/core/main.cc src/core/MyWin.cc src/core/MyStack.cc) #src/core/winconf.cc
set(SOURCES src/core/main.cc src/core/MyWin.cc src/core/MyStack.cc
src/ui/MyFinder.cc) #src/core/winconf.cc
# src/panels/LeftPanel.cc src/panels/TopPanel.cc
# src/draw_app/drawing.cc src/file_app/FileWindow.cc src/game_app/Game.cc
# src/image_app/ImageApp.cc src/image_app/MyImage.cc
@ -32,6 +33,7 @@ set(SOURCES src/core/main.cc src/core/MyWin.cc src/core/MyStack.cc) #src/core/wi
set(RESOURCE_LIST
menubar.xml
stack.ui
icons/16x16/actions/My_GtkUI.png
icons/48x48/actions/My_GtkUI.png)

View File

@ -81,11 +81,13 @@
</item>
<item>
<attribute name="label">Shut Down...</attribute>
<attribute name="action">win.quit</attribute>
</item>
</section>
<section>
<item>
<attribute name="label">Login Out dale...</attribute>
<attribute name="action">win.logout</attribute>
</item>
</section>
</menu>

View File

@ -5,6 +5,7 @@
<object class="GtkStack" id="main_stack">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="transition-type">crossfade</property>
<child>
<object class="GtkBox" id="login_page">
<property name="visible">True</property>
@ -13,9 +14,10 @@
<property name="valign">center</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkImage">
<object class="GtkImage" id="user_image">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="pixel-size">48</property>
<property name="icon-name">My_GtkUI</property>
</object>
<packing>
@ -25,7 +27,19 @@
</packing>
</child>
<child>
<object class="GtkButton">
<object class="GtkLabel" id="user_label">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label" translatable="yes">dale</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkButton" id="btnlogin">
<property name="label" translatable="yes">Login</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
@ -35,12 +49,9 @@
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
<property name="position">2</property>
</packing>
</child>
<child>
<placeholder/>
</child>
</object>
<packing>
<property name="name">page0</property>
@ -69,43 +80,7 @@
</packing>
</child>
<child>
<!-- n-columns=3 n-rows=3 -->
<object class="GtkGrid" id="launchpad_page">
<property name="visible">True</property>
<property name="can-focus">False</property>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
</object>
<packing>
<property name="name">page2</property>
<property name="title" translatable="yes">page2</property>
<property name="position">2</property>
</packing>
<placeholder/>
</child>
</object>
</interface>

View File

@ -0,0 +1,23 @@
#pragma once
#include <gtkmm.h>
class MyFinder : public Gtk::Box
{
public:
MyFinder();
private:
// Child Widgets
Gtk::MenuButton btnlogo, btntitle, btnfile, btnedit, btnshow,
btngoto, btnwin, btnhelp;
Gtk::MenuButton timer_button;
Gtk::Popover time_popover;
Gtk::Calendar calender;
// Get Menu
Glib::RefPtr<Gio::Menu> get_menu(Glib::RefPtr<Gtk::Builder> &builder, const Glib::ustring &id);
//Timer
sigc::connection mytimer;
};

View File

@ -1,9 +1,24 @@
#include "MyStack.hh"
MyStack::MyStack(){
// Get Widgets
stackbuilder = Gtk::Builder::create_from_resource("/org/gtk/daleclack/stack.ui");
stackbuilder->get_widget("main_stack",stack);
stackbuilder->get_widget("login_page",login_page);
stackbuilder->get_widget("main_page",main_page);
stackbuilder->get_widget("btnlogin",btnlogin);
// Link Signals
btnlogin->signal_clicked().connect(sigc::mem_fun(*this,&MyStack::btnlogin_clicked));
//Add Widget
main_page->pack_start(finder);
}
void MyStack::add_stack(Gtk::Overlay &overlay){
void MyStack::logout(){
stack->set_visible_child(*login_page);
}
void MyStack::btnlogin_clicked(){
stack->set_visible_child(*main_page);
}

View File

@ -1,12 +1,26 @@
#pragma once
#include <gtkmm.h>
#include "MyFinder.hh"
class MyStack{
class MyStack
{
public:
MyStack();
void add_stack(Gtk::Overlay &overlay);
void logout();
// Main Widget
Gtk::Stack *stack;
private:
Gtk::Stack * main_stack;
Glib::RefPtr<Gtk::Builder> stackbuilder;
// Child widgets
Gtk::Box *login_page, *main_page;
Gtk::Button *btnlogin;
//Finder
MyFinder finder;
// Signal Handlers
void btnlogin_clicked();
};

View File

@ -1,6 +1,6 @@
#include "MyWin.hh"
#include "MyStack.hh"
#include "winpe.xpm"
#include <iostream>
MyWin::MyWin()
:menubox(Gtk::ORIENTATION_HORIZONTAL,0)
@ -16,83 +16,21 @@ MyWin::MyWin()
gtk_image_set_from_pixbuf(m_background.gobj(),sized->gobj());
m_overlay.add(m_background);
//Add a menubar
auto menubuilder = Gtk::Builder::create_from_resource("/org/gtk/daleclack/menubar.xml");
//Add Action for menus
add_action("logout",sigc::mem_fun(*this,&MyWin::logout_activated));
add_action("quit",sigc::mem_fun(*this,&MyWin::quit_activated));
//Add widgets to menubox
btnlogo.set_image_from_icon_name("My_GtkUI",Gtk::ICON_SIZE_BUTTON);
btnlogo.set_relief(Gtk::RELIEF_NONE);
btnlogo.set_use_popover(false);
btnlogo.set_menu_model(get_menu(menubuilder,"main_menu"));
menubox.pack_start(btnlogo,Gtk::PACK_SHRINK);
btntitle.set_label("MyFinder");
btntitle.set_relief(Gtk::RELIEF_NONE);
btntitle.set_use_popover(false);
btntitle.set_menu_model(get_menu(menubuilder,"title_menu"));
menubox.pack_start(btntitle,Gtk::PACK_SHRINK);
btnfile.set_label("File");
btnfile.set_relief(Gtk::RELIEF_NONE);
btnfile.set_use_popover(false);
btnfile.set_menu_model(get_menu(menubuilder,"menu_file"));
menubox.pack_start(btnfile,Gtk::PACK_SHRINK);
btnedit.set_label("Edit");
btnedit.set_relief(Gtk::RELIEF_NONE);
btnedit.set_use_popover(false);
btnedit.set_menu_model(get_menu(menubuilder,"menu_edit"));
menubox.pack_start(btnedit,Gtk::PACK_SHRINK);
btnshow.set_label("Show");
btnshow.set_relief(Gtk::RELIEF_NONE);
btnshow.set_use_popover(false);
btnshow.set_menu_model(get_menu(menubuilder,"menu_show"));
menubox.pack_start(btnshow,Gtk::PACK_SHRINK);
btngoto.set_label("Go to");
btngoto.set_relief(Gtk::RELIEF_NONE);
btngoto.set_use_popover(false);
btngoto.set_menu_model(get_menu(menubuilder,"menu_goto"));
menubox.pack_start(btngoto,Gtk::PACK_SHRINK);
btnwin.set_label("Windows");
btnwin.set_relief(Gtk::RELIEF_NONE);
btnwin.set_use_popover(false);
btnwin.set_menu_model(get_menu(menubuilder,"menu_win"));
menubox.pack_start(btnwin,Gtk::PACK_SHRINK);
btnhelp.set_label("Help");
btnhelp.set_relief(Gtk::RELIEF_NONE);
btnhelp.set_use_popover(false);
btnhelp.set_menu_model(get_menu(menubuilder,"menu_help"));
menubox.pack_start(btnhelp,Gtk::PACK_SHRINK);
//Add menu to window
menubox.set_halign(Gtk::ALIGN_FILL);
menubox.set_valign(Gtk::ALIGN_START);
m_overlay.add_overlay(menubox);
//Add a timer
time_popover.add(calender);
calender.show();
calender.set_margin_bottom(5);
calender.set_margin_end(5);
calender.set_margin_start(5);
calender.set_margin_end(5);
//Timer
timer_button.set_label("2022/1/23 18:32");
timer_button.set_relief(Gtk::RELIEF_NONE);
timer_button.set_popover(time_popover);
menubox.pack_end(timer_button,Gtk::PACK_SHRINK);
//Add Stack
m_overlay.add_overlay(*(main_stack.stack));
add(m_overlay);
show_all_children();
}
Glib::RefPtr<Gio::Menu> MyWin::get_menu(Glib::RefPtr<Gtk::Builder> &builder, const Glib::ustring &id){
auto object = builder->get_object(id);
auto gmenu = Glib::RefPtr<Gio::Menu>::cast_dynamic(object);
return gmenu;
}
void MyWin::logout_activated(){
main_stack.logout();
}
void MyWin::quit_activated(){
hide();
}

View File

@ -1,6 +1,7 @@
#pragma once
#include <gtkmm.h>
#include "MyStack.hh"
class MyWin : public Gtk::ApplicationWindow{
public:
@ -10,15 +11,13 @@ private:
Gtk::Overlay m_overlay;
Gtk::Image m_background;
Gtk::Box menubox;
Gtk::MenuButton btnlogo, btntitle, btnfile, btnedit, btnshow,
btngoto, btnwin, btnhelp;
Gtk::MenuButton timer_button;
Gtk::Popover time_popover;
Gtk::Calendar calender;
Gtk::DrawingArea draw_area;
//Get Menu
Glib::RefPtr<Gio::Menu> get_menu(Glib::RefPtr<Gtk::Builder> &builder, const Glib::ustring &id);
//Main Stack
MyStack main_stack;
//Signal Handlers
void logout_activated();
void quit_activated();
//Timer auto update
sigc::connection mytimer;
};

View File

@ -0,0 +1,79 @@
#include "MyFinder.hh"
MyFinder::MyFinder(){
//Add a menubar
auto menubuilder = Gtk::Builder::create_from_resource("/org/gtk/daleclack/menubar.xml");
//Add widgets to menubox
btnlogo.set_image_from_icon_name("My_GtkUI",Gtk::ICON_SIZE_BUTTON);
btnlogo.set_relief(Gtk::RELIEF_NONE);
btnlogo.set_use_popover(false);
btnlogo.set_menu_model(get_menu(menubuilder,"main_menu"));
pack_start(btnlogo,Gtk::PACK_SHRINK);
btntitle.set_label("MyFinder");
btntitle.set_relief(Gtk::RELIEF_NONE);
btntitle.set_use_popover(false);
btntitle.set_menu_model(get_menu(menubuilder,"title_menu"));
pack_start(btntitle,Gtk::PACK_SHRINK);
btnfile.set_label("File");
btnfile.set_relief(Gtk::RELIEF_NONE);
btnfile.set_use_popover(false);
btnfile.set_menu_model(get_menu(menubuilder,"menu_file"));
pack_start(btnfile,Gtk::PACK_SHRINK);
btnedit.set_label("Edit");
btnedit.set_relief(Gtk::RELIEF_NONE);
btnedit.set_use_popover(false);
btnedit.set_menu_model(get_menu(menubuilder,"menu_edit"));
pack_start(btnedit,Gtk::PACK_SHRINK);
btnshow.set_label("Show");
btnshow.set_relief(Gtk::RELIEF_NONE);
btnshow.set_use_popover(false);
btnshow.set_menu_model(get_menu(menubuilder,"menu_show"));
pack_start(btnshow,Gtk::PACK_SHRINK);
btngoto.set_label("Go to");
btngoto.set_relief(Gtk::RELIEF_NONE);
btngoto.set_use_popover(false);
btngoto.set_menu_model(get_menu(menubuilder,"menu_goto"));
pack_start(btngoto,Gtk::PACK_SHRINK);
btnwin.set_label("Windows");
btnwin.set_relief(Gtk::RELIEF_NONE);
btnwin.set_use_popover(false);
btnwin.set_menu_model(get_menu(menubuilder,"menu_win"));
pack_start(btnwin,Gtk::PACK_SHRINK);
btnhelp.set_label("Help");
btnhelp.set_relief(Gtk::RELIEF_NONE);
btnhelp.set_use_popover(false);
btnhelp.set_menu_model(get_menu(menubuilder,"menu_help"));
pack_start(btnhelp,Gtk::PACK_SHRINK);
//Add menu to window
set_halign(Gtk::ALIGN_FILL);
set_valign(Gtk::ALIGN_START);
//Add a timer
time_popover.add(calender);
calender.show();
calender.set_margin_bottom(5);
calender.set_margin_end(5);
calender.set_margin_start(5);
calender.set_margin_end(5);
//Timer
timer_button.set_label("2022/1/23 18:32");
timer_button.set_relief(Gtk::RELIEF_NONE);
timer_button.set_popover(time_popover);
pack_end(timer_button,Gtk::PACK_SHRINK);
}
Glib::RefPtr<Gio::Menu> MyFinder::get_menu(Glib::RefPtr<Gtk::Builder> &builder, const Glib::ustring &id){
auto object = builder->get_object(id);
auto gmenu = Glib::RefPtr<Gio::Menu>::cast_dynamic(object);
return gmenu;
}