Add gtk150

This commit is contained in:
daleclack 2023-05-29 21:49:04 +08:00
parent 85f62d8e88
commit 84d29d8937
9 changed files with 515 additions and 6 deletions

View File

@ -0,0 +1,3 @@
{
"C_Cpp.default.configurationProvider": "ms-vscode.cmake-tools"
}

View File

@ -21,20 +21,18 @@ pkg_check_modules (GTKMM4 REQUIRED gtkmm-4.0)
include_directories (${GTKMM4_INCLUDE_DIRS})
link_directories (${GTKMM4_LIBRARY_DIRS})
#Find Gettext
# Find Gettext
# find_package (Gettext REQUIRED)
# set(PO_DIR ${CMAKE_BINARY_DIR}/po/zh_CN/LC_MESSAGES)
#Source files
# Source files
set(SOURCE_FILE src/main.cc src/MainWin.cc src/MyPrefs.cc)
#Compile Resource
# Compile Resource
set(RESOURCE_LIST
custom_style.css
STRIPBLANKS context_menu.xml
STRIPBLANKS default_menu.xml
STRIPBLANKS prefs_stack.ui
STRIPBLANKS mainmenu.xml
)
compile_gresources(RESOURCE_FILE

View File

@ -0,0 +1,52 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<menu id="model">
<section>
<item>
<attribute name="label">New Folder</attribute>
</item>
</section>
<section>
<item>
<attribute name="label">Show Info</attribute>
</item>
<item>
<attribute name="label">Customization</attribute>
<attribute name="action">win.back</attribute>
</item>
<item>
<attribute name="label">Refresh</attribute>
<attribute name="action">win.refresh</attribute>
</item>
</section>
<section>
<item>
<attribute name="label">Automater</attribute>
</item>
<submenu>
<attribute name="label">Automater method</attribute>
<item>
<attribute name="label">Name</attribute>
</item>
<item>
<attribute name="label">Date Modified</attribute>
</item>
<item>
<attribute name="label">Date Created</attribute>
</item>
<item>
<attribute name="label">Size</attribute>
</item>
<item>
<attribute name="label">Kind</attribute>
</item>
<item>
<attribute name="label">Label</attribute>
</item>
</submenu>
<item>
<attribute name="label">Show View Options</attribute>
</item>
</section>
</menu>
</interface>

View File

@ -0,0 +1,368 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<requires lib="gtk" version="4.0"/>
<object class="GtkAdjustment" id="adjustment1">
<property name="upper">9999</property>
<property name="value">1024</property>
<property name="step-increment">1</property>
<property name="page-increment">10</property>
</object>
<object class="GtkAdjustment" id="adjustment2">
<property name="upper">9999</property>
<property name="value">576</property>
<property name="step-increment">1</property>
<property name="page-increment">10</property>
</object>
<object class="GtkStringList" id="sizes_list">
<items>
<item translatable="yes">640x360</item>
<item translatable="yes">800x450</item>
<item translatable="yes">1024x576</item>
<item translatable="yes">1280x720</item>
<item translatable="yes">1366x768</item>
</items>
</object>
<object class="GtkBox" id="stack_box">
<property name="hexpand">1</property>
<property name="vexpand">1</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkStackSwitcher">
<property name="halign">center</property>
<property name="stack">main_stack</property>
</object>
</child>
<child>
<object class="GtkStack" id="main_stack">
<child>
<object class="GtkStackPage">
<property name="title" translatable="1">Background Preferences</property>
<property name="child">
<object class="GtkBox" id="back_page">
<property name="orientation">vertical</property>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
</object>
</property>
</object>
</child>
<child>
<object class="GtkStackPage">
<property name="title" translatable="1">Window Size Config</property>
<property name="child">
<object class="GtkBox" id="winsize_page">
<property name="halign">center</property>
<property name="valign">center</property>
<property name="hexpand">1</property>
<property name="vexpand">1</property>
<property name="orientation">vertical</property>
<property name="spacing">5</property>
<child>
<placeholder/>
</child>
<child>
<object class="GtkBox">
<property name="halign">center</property>
<property name="valign">center</property>
<property name="spacing">5</property>
<child>
<object class="GtkImage">
<property name="pixel-size">128</property>
<property name="icon-name">display_prefs</property>
</object>
</child>
<child>
<object class="GtkGrid">
<property name="row-spacing">5</property>
<property name="column-spacing">5</property>
<child>
<object class="GtkBox" id="combo_box">
<layout>
<property name="column">1</property>
<property name="row">1</property>
<property name="column-span">3</property>
</layout>
</object>
</child>
<child>
<object class="GtkCheckButton" id="radio_default">
<property name="label" translatable="1">Use default window size</property>
<property name="focusable">1</property>
<property name="active">1</property>
<property name="group">radio_custom</property>
<layout>
<property name="column">1</property>
<property name="row">0</property>
<property name="column-span">3</property>
</layout>
</object>
</child>
<child>
<object class="GtkCheckButton" id="radio_custom">
<property name="label" translatable="1">User defined window size</property>
<property name="focusable">1</property>
<layout>
<property name="column">1</property>
<property name="row">2</property>
<property name="column-span">3</property>
</layout>
</object>
</child>
<child>
<object class="GtkSpinButton" id="spin_width">
<property name="sensitive">0</property>
<property name="focusable">1</property>
<property name="adjustment">adjustment1</property>
<property name="value">1024</property>
<layout>
<property name="column">1</property>
<property name="row">3</property>
</layout>
</object>
</child>
<child>
<object class="GtkSpinButton" id="spin_height">
<property name="sensitive">0</property>
<property name="focusable">1</property>
<property name="adjustment">adjustment2</property>
<property name="value">576</property>
<layout>
<property name="column">3</property>
<property name="row">3</property>
</layout>
</object>
</child>
<child>
<object class="GtkLabel">
<property name="label" translatable="1">x</property>
<layout>
<property name="column">2</property>
<property name="row">3</property>
</layout>
</object>
</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>
</child>
</object>
</child>
<child>
<object class="GtkBox">
<property name="hexpand">1</property>
<property name="vexpand">1</property>
<child>
<object class="GtkLabel" id="label_size">
<property name="label" translatable="1">Current Config: </property>
</object>
</child>
<child>
<object class="GtkButton" id="btnGet">
<property name="label" translatable="1">Get Current</property>
<property name="sensitive">0</property>
<property name="focusable">1</property>
<property name="receives-default">1</property>
</object>
</child>
<child>
<object class="GtkButton" id="btnapply">
<property name="label" translatable="1">Apply</property>
<property name="focusable">1</property>
<property name="receives-default">1</property>
<property name="halign">end</property>
</object>
</child>
</object>
</child>
</object>
</property>
</object>
</child>
<child>
<object class="GtkStackPage">
<property name="title" translatable="1">Dock Preferences</property>
<property name="child">
<object class="GtkBox" id="dock_page">
<property name="halign">center</property>
<property name="valign">center</property>
<property name="orientation">vertical</property>
<child>
<placeholder/>
</child>
<child>
<object class="GtkBox">
<property name="halign">center</property>
<property name="valign">center</property>
<property name="spacing">5</property>
<child>
<object class="GtkImage">
<property name="pixel-size">128</property>
<property name="icon-name">display_prefs</property>
</object>
</child>
<child>
<object class="GtkGrid">
<property name="row-spacing">5</property>
<property name="column-spacing">5</property>
<child>
<object class="GtkCheckButton" id="mode_check">
<property name="label" translatable="1">Use panel mode:expand the dock</property>
<property name="focusable">1</property>
<layout>
<property name="column">1</property>
<property name="row">0</property>
<property name="column-span">3</property>
</layout>
</object>
</child>
<child>
<object class="GtkLabel">
<property name="label" translatable="1">Position:</property>
<layout>
<property name="column">1</property>
<property name="row">2</property>
</layout>
</object>
</child>
<child>
<object class="GtkCheckButton" id="radio_left">
<property name="label" translatable="1">Left</property>
<property name="focusable">1</property>
<property name="active">1</property>
<layout>
<property name="column">2</property>
<property name="row">2</property>
</layout>
</object>
</child>
<child>
<object class="GtkCheckButton" id="radio_right">
<property name="label" translatable="1">Right</property>
<property name="focusable">1</property>
<property name="group">radio_left</property>
<layout>
<property name="column">2</property>
<property name="row">3</property>
</layout>
</object>
</child>
<child>
<object class="GtkCheckButton" id="radio_bottom">
<property name="label" translatable="1">Bottom</property>
<property name="focusable">1</property>
<property name="group">radio_left</property>
<layout>
<property name="column">2</property>
<property name="row">4</property>
</layout>
</object>
</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>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
</object>
</child>
</object>
</child>
<child>
<object class="GtkBox">
<property name="hexpand">1</property>
<property name="vexpand">1</property>
<child>
<object class="GtkLabel">
<property name="label" translatable="1"> </property>
<property name="hexpand">1</property>
</object>
</child>
<child>
<object class="GtkButton" id="btnapply1">
<property name="label" translatable="1">Apply</property>
<property name="focusable">1</property>
<property name="receives-default">1</property>
<property name="halign">end</property>
</object>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
</object>
</child>
</object>
</property>
</object>
</child>
</object>
</child>
<child>
<placeholder/>
</child>
</object>
</interface>

View File

@ -0,0 +1,41 @@
#include "MainWin.hh"
#include "MyPrefs.hh"
#include "winpe.xpm"
MainWin::MainWin(){
// Initalize window
set_default_size(1024, 576);
set_icon_name("org.gtk.daleclack");
// Set default background
m_background.set_expand();
auto pixbuf = Gdk::Pixbuf::create_from_xpm_data(winpe);
auto sized = pixbuf->scale_simple(1024, 576, Gdk::InterpType::BILINEAR);
m_background.set_pixbuf(sized);
pixbuf.reset();
sized.reset();
// Add Gesture
right_click = Gtk::GestureClick::create();
m_overlay.add_controller(right_click);
right_click->set_button(GDK_BUTTON_SECONDARY);
right_click->signal_pressed().connect(sigc::mem_fun(*this, &MainWin::pressed));
// Initalize menu
menu_builder = Gtk::Builder::create_from_resource("/org/gtk/daleclack/mainmenu.xml");
auto model = menu_builder->get_object<Gio::MenuModel>("model");
context_menu.set_menu_model(model);
context_menu.set_parent(m_overlay);
context_menu.set_has_arrow(false);
// Add widgets
m_overlay.set_child(m_background);
set_child(m_overlay);
}
void MainWin::pressed(int n_click, double x, double y){
// Show the context menu on the position of mouse
context_menu.set_pointing_to(Gdk::Rectangle(x, y, 1, 1));
context_menu.popup();
}

View File

@ -0,0 +1,24 @@
#pragma once
#include <gtkmm.h>
class MainWin : public Gtk::ApplicationWindow
{
public:
MainWin();
private:
// Child widgets
Gtk::Picture m_background;
Gtk::Overlay m_overlay;
// Context Menu
Glib::RefPtr<Gtk::Builder> menu_builder;
Gtk::PopoverMenu context_menu;
// Gesture for right click
Glib::RefPtr<Gtk::GestureClick> right_click;
// Signal Handler
void pressed(int n_click, double x, double y);
};

View File

@ -0,0 +1,5 @@
#include "MyPrefs.hh"
MyPrefs::MyPrefs(){
}

View File

@ -0,0 +1,11 @@
#pragma once
#include <gtkmm.h>
class MyPrefs : public Gtk::Window
{
public:
MyPrefs();
private:
Glib::RefPtr<Gtk::Builder> stack_builder;
};

View File

@ -0,0 +1,7 @@
#include "MainWin.hh"
int main(int argc, char **argv){
// Create a application and run
auto app = Gtk::Application::create("org.gtk.daleclack");
return app->make_window_and_run<MainWin>(argc, argv);
}