mirror of https://github.com/daleclack/My_GtkUi
Add dock preferences window
This commit is contained in:
parent
9fbfdfa51c
commit
7da9607c2d
|
@ -9,6 +9,7 @@
|
|||
|
||||
box{
|
||||
background-color:alpha(gray,0.3);
|
||||
color:white;
|
||||
}
|
||||
|
||||
separator{
|
||||
|
|
|
@ -284,6 +284,205 @@
|
|||
<property name="position">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkBox" id="dock_page">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">False</property>
|
||||
<property name="halign">center</property>
|
||||
<property name="valign">center</property>
|
||||
<property name="orientation">vertical</property>
|
||||
<child>
|
||||
<placeholder/>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkBox">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">False</property>
|
||||
<property name="halign">center</property>
|
||||
<property name="valign">center</property>
|
||||
<property name="spacing">5</property>
|
||||
<child>
|
||||
<object class="GtkImage">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">False</property>
|
||||
<property name="pixel-size">128</property>
|
||||
<property name="icon-name">display_prefs</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<!-- n-columns=4 n-rows=5 -->
|
||||
<object class="GtkGrid">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">False</property>
|
||||
<property name="row-spacing">5</property>
|
||||
<property name="column-spacing">5</property>
|
||||
<child>
|
||||
<object class="GtkCheckButton" id="mode_check">
|
||||
<property name="label" translatable="yes">Use panel mode:expand the dock</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">True</property>
|
||||
<property name="receives-default">False</property>
|
||||
<property name="draw-indicator">True</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left-attach">1</property>
|
||||
<property name="top-attach">0</property>
|
||||
<property name="width">3</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkLabel">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">False</property>
|
||||
<property name="label" translatable="yes">Position:</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left-attach">1</property>
|
||||
<property name="top-attach">2</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkRadioButton" id="radio_left">
|
||||
<property name="label" translatable="yes">Left</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">True</property>
|
||||
<property name="receives-default">False</property>
|
||||
<property name="active">True</property>
|
||||
<property name="draw-indicator">True</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left-attach">2</property>
|
||||
<property name="top-attach">2</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkRadioButton" id="radio_right">
|
||||
<property name="label" translatable="yes">Right</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">True</property>
|
||||
<property name="receives-default">False</property>
|
||||
<property name="draw-indicator">True</property>
|
||||
<property name="group">radio_left</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left-attach">2</property>
|
||||
<property name="top-attach">3</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkRadioButton" id="radio_bottom">
|
||||
<property name="label" translatable="yes">Bottom</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">True</property>
|
||||
<property name="receives-default">False</property>
|
||||
<property name="draw-indicator">True</property>
|
||||
<property name="group">radio_left</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left-attach">2</property>
|
||||
<property name="top-attach">4</property>
|
||||
</packing>
|
||||
</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>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">False</property>
|
||||
<property name="position">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkBox">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">False</property>
|
||||
<property name="hexpand">True</property>
|
||||
<property name="vexpand">True</property>
|
||||
<child>
|
||||
<object class="GtkButton" id="btnapply1">
|
||||
<property name="label" translatable="yes">Apply</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">True</property>
|
||||
<property name="receives-default">True</property>
|
||||
<property name="halign">end</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="pack-type">end</property>
|
||||
<property name="position">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<placeholder/>
|
||||
</child>
|
||||
<child>
|
||||
<placeholder/>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="pack-type">end</property>
|
||||
<property name="position">2</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="name">dock_prefs</property>
|
||||
<property name="title" translatable="yes">Dock Preferences</property>
|
||||
<property name="position">2</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
|
||||
box{
|
||||
background-color:alpha(gray,0.7);
|
||||
color:white;
|
||||
}
|
||||
|
||||
label{
|
||||
|
|
|
@ -13,11 +13,6 @@
|
|||
#include "CalcApp.hh"
|
||||
#include "MineSweeper.hh"
|
||||
|
||||
enum class DockMode{
|
||||
MODE_DOCK,
|
||||
MODE_PANEL
|
||||
};
|
||||
|
||||
class MyDock : public Gtk::Box
|
||||
{
|
||||
public:
|
||||
|
|
|
@ -10,7 +10,8 @@ MyPrefs::MyPrefs()
|
|||
views_box(Gtk::ORIENTATION_HORIZONTAL, 5),
|
||||
btnbox(Gtk::ORIENTATION_HORIZONTAL, 5),
|
||||
width(1024),
|
||||
height(576)
|
||||
height(576),
|
||||
dock_pos(DockPos::POS_LEFT)
|
||||
{
|
||||
/*Step 1: Initalize widget that without Gtk::Builder*/
|
||||
|
||||
|
@ -112,8 +113,13 @@ MyPrefs::MyPrefs()
|
|||
stackbuilder->get_widget("spin_width", spin_width);
|
||||
stackbuilder->get_widget("spin_height", spin_height);
|
||||
stackbuilder->get_widget("btnapply", btnapply);
|
||||
stackbuilder->get_widget("btnGet",btnGet);
|
||||
stackbuilder->get_widget("label_size",label_size);
|
||||
stackbuilder->get_widget("btnGet", btnGet);
|
||||
stackbuilder->get_widget("label_size", label_size);
|
||||
stackbuilder->get_widget("mode_check", mode_check);
|
||||
stackbuilder->get_widget("radio_left", radio_left);
|
||||
stackbuilder->get_widget("radio_right", radio_right);
|
||||
stackbuilder->get_widget("radio_bottom", radio_bottom);
|
||||
stackbuilder->get_widget("btnapply1", btnapply1);
|
||||
|
||||
// Initalize radio buttons
|
||||
radio_default->set_active();
|
||||
|
@ -122,11 +128,14 @@ MyPrefs::MyPrefs()
|
|||
|
||||
// Initalize other widgets
|
||||
btnapply->signal_clicked().connect(sigc::mem_fun(*this, &MyPrefs::btnapply_clicked));
|
||||
btnGet->signal_clicked().connect(sigc::mem_fun(*this,&MyPrefs::btnGet_clicked));
|
||||
btnGet->signal_clicked().connect(sigc::mem_fun(*this, &MyPrefs::btnGet_clicked));
|
||||
|
||||
// Initalize Dock Preferences
|
||||
btnapply1->signal_clicked().connect(sigc::mem_fun(*this, &MyPrefs::btnapply1_clicked));
|
||||
|
||||
// Initalize Label
|
||||
load_winsize_config();
|
||||
char * size_str = g_strdup_printf("Current Config: %d x %d", width, height);
|
||||
char *size_str = g_strdup_printf("Current Config: %d x %d", width, height);
|
||||
label_size->set_label(size_str);
|
||||
g_free(size_str);
|
||||
|
||||
|
@ -366,7 +375,8 @@ void MyPrefs::set_background_file()
|
|||
}
|
||||
|
||||
void MyPrefs::update_background_size()
|
||||
{}
|
||||
{
|
||||
}
|
||||
|
||||
void MyPrefs::set_background(Gtk::Image *back)
|
||||
{
|
||||
|
@ -383,6 +393,30 @@ void MyPrefs::radiobutton_toggled()
|
|||
btnGet->set_sensitive(!mode);
|
||||
}
|
||||
|
||||
void MyPrefs::save_config_file()
|
||||
{
|
||||
// Open the file for configs
|
||||
json data = json::parse(R"(
|
||||
{
|
||||
"height":1280,
|
||||
"width":720,
|
||||
"panel_mode":false,
|
||||
"position":0
|
||||
}
|
||||
)");
|
||||
std::fstream outfile;
|
||||
outfile.open("config.json", std::ios_base::out);
|
||||
if (outfile.is_open())
|
||||
{
|
||||
data["width"] = width;
|
||||
data["height"] = height;
|
||||
data["panel_mode"] = panel_mode;
|
||||
data["position"] = dock_pos;
|
||||
outfile << data;
|
||||
outfile.close();
|
||||
}
|
||||
}
|
||||
|
||||
void MyPrefs::btnapply_clicked()
|
||||
{
|
||||
// Get Config
|
||||
|
@ -419,45 +453,75 @@ void MyPrefs::btnapply_clicked()
|
|||
height = spin_height->get_value_as_int();
|
||||
}
|
||||
|
||||
// Open the file for configs
|
||||
json data = json::parse(R"(
|
||||
{
|
||||
"height":1280,
|
||||
"width":720,
|
||||
"panel_mode":false
|
||||
}
|
||||
)");
|
||||
std::fstream outfile;
|
||||
outfile.open("config.json", std::ios_base::out);
|
||||
if (outfile.is_open())
|
||||
// Save the config to json file
|
||||
save_config_file();
|
||||
}
|
||||
|
||||
void MyPrefs::btnapply1_clicked()
|
||||
{
|
||||
// Whether panel mode is enabled
|
||||
panel_mode = mode_check->get_active();
|
||||
|
||||
// The dock position
|
||||
if (radio_left->get_active())
|
||||
{
|
||||
data["width"] = width;
|
||||
data["height"] = height;
|
||||
data["panel_mode"] = panel_mode;
|
||||
outfile<<data;
|
||||
outfile.close();
|
||||
dock_pos = DockPos::POS_LEFT;
|
||||
}
|
||||
if (radio_right->get_active())
|
||||
{
|
||||
dock_pos = DockPos::POS_RIGHT;
|
||||
}
|
||||
if (radio_bottom->get_active())
|
||||
{
|
||||
dock_pos = DockPos::POS_BOTTOM;
|
||||
}
|
||||
|
||||
// std::cout << dock_pos << std::endl;
|
||||
save_config_file();
|
||||
}
|
||||
|
||||
void MyPrefs::btnGet_clicked()
|
||||
{
|
||||
//Get Current Window Size
|
||||
// Get Current Window Size
|
||||
width = background1->get_width();
|
||||
height = background1->get_height();
|
||||
spin_width->set_value(width);
|
||||
spin_height->set_value(height);
|
||||
}
|
||||
|
||||
void MyPrefs::load_winsize_config(){
|
||||
void MyPrefs::load_winsize_config()
|
||||
{
|
||||
// Read the config
|
||||
std::ifstream jsonfile("config.json");
|
||||
if(jsonfile.is_open()){
|
||||
if (jsonfile.is_open())
|
||||
{
|
||||
json data = json::parse(jsonfile);
|
||||
height = data["height"];
|
||||
width = data["width"];
|
||||
panel_mode = data["panel_mode"];
|
||||
}else{
|
||||
dock_pos = data["position"];
|
||||
}
|
||||
else
|
||||
{
|
||||
// Default config
|
||||
height = 720;
|
||||
width = 1280;
|
||||
panel_mode = false;
|
||||
dock_pos = DockPos::POS_LEFT;
|
||||
}
|
||||
|
||||
// Load the config
|
||||
mode_check->set_active(panel_mode);
|
||||
switch (dock_pos)
|
||||
{
|
||||
case DockPos::POS_LEFT:
|
||||
radio_left->set_active();
|
||||
break;
|
||||
case DockPos::POS_RIGHT:
|
||||
radio_right->set_active();
|
||||
break;
|
||||
case DockPos::POS_BOTTOM:
|
||||
radio_left->set_active();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,6 +7,17 @@
|
|||
|
||||
using json = nlohmann::json;
|
||||
|
||||
enum class DockMode{
|
||||
MODE_DOCK,
|
||||
MODE_PANEL
|
||||
};
|
||||
|
||||
enum class DockPos{
|
||||
POS_LEFT,
|
||||
POS_RIGHT,
|
||||
POS_BOTTOM
|
||||
};
|
||||
|
||||
class MyPrefs : public Gtk::Window
|
||||
{
|
||||
public:
|
||||
|
@ -41,6 +52,7 @@ private:
|
|||
// Background widget and properties
|
||||
int width, height;
|
||||
bool panel_mode;
|
||||
DockPos dock_pos;
|
||||
Gtk::Image *background1;
|
||||
std::string path;
|
||||
bool background_internal;
|
||||
|
@ -54,6 +66,11 @@ private:
|
|||
Gtk::Button *btnapply, *btnGet;
|
||||
Gtk::Label *label_size;
|
||||
|
||||
// Dock Preferences
|
||||
Gtk::Button *btnapply1;
|
||||
Gtk::CheckButton *mode_check;
|
||||
Gtk::RadioButton *radio_left, *radio_right, *radio_bottom;
|
||||
|
||||
// Child Widgets
|
||||
Gtk::TreeView folders_view, images_view;
|
||||
Gtk::ScrolledWindow sw_folders, sw_images;
|
||||
|
@ -70,17 +87,31 @@ private:
|
|||
bool icasecompare(const std::string &a, const std::string &b);
|
||||
|
||||
// Signal Handlers
|
||||
void save_config_file();
|
||||
|
||||
// Background page buttons
|
||||
void btnadd_clicked();
|
||||
void btnremove_clicked();
|
||||
|
||||
// Folder and images view
|
||||
void folders_view_changed();
|
||||
void images_view_changed();
|
||||
|
||||
// Default settings
|
||||
void default_folders_view();
|
||||
|
||||
// Update the background
|
||||
void update_images_view(std::string &folder_path);
|
||||
void set_background_internal(const char *const *data);
|
||||
void set_background_file();
|
||||
|
||||
// Resoulution page
|
||||
void radiobutton_toggled();
|
||||
void btnapply_clicked();
|
||||
void btnGet_clicked();
|
||||
|
||||
// Dock Preferences
|
||||
void btnapply1_clicked();
|
||||
};
|
||||
|
||||
//Read Config from file without use the MyPrefs class
|
||||
|
|
Loading…
Reference in New Issue