Adding ListView
This commit is contained in:
parent
9d054d4119
commit
2d2d5032c0
@ -85,7 +85,7 @@ add_executable(autocat_gnome main.cpp
|
||||
App.cpp
|
||||
App.h
|
||||
models/Vehicle.cpp
|
||||
models/Vehicle.h services/Storage.cpp services/Storage.h models/Engine.cpp models/Engine.h services/IDBEntity.h models/JsonOptional.h services/IDBEntity.cpp gtkpp/ScrolledWindow.cpp gtkpp/ScrolledWindow.h gtkpp/ListView.cpp gtkpp/ListView.h gtkpp/SelectionModel.cpp gtkpp/SelectionModel.h gtkpp/ListItemFactory.cpp gtkpp/ListItemFactory.h models/VehiclesListFactory.cpp models/VehiclesListFactory.h gtkpp/Separator.cpp gtkpp/Separator.h)
|
||||
models/Vehicle.h services/Storage.cpp services/Storage.h models/Engine.cpp models/Engine.h services/IDBEntity.h models/JsonOptional.h services/IDBEntity.cpp gtkpp/ScrolledWindow.cpp gtkpp/ScrolledWindow.h gtkpp/ListView.cpp gtkpp/ListView.h gtkpp/SelectionModel.cpp gtkpp/SelectionModel.h gtkpp/ListItemFactory.cpp gtkpp/ListItemFactory.h models/VehiclesListFactory.cpp models/VehiclesListFactory.h gtkpp/Separator.cpp gtkpp/Separator.h gtkpp/Label.cpp gtkpp/Label.h)
|
||||
|
||||
target_link_libraries(autocat_gnome ${GTK_LIBRARIES}
|
||||
${GLIB_LIBRARIES}
|
||||
|
||||
17
gtkpp/Label.cpp
Normal file
17
gtkpp/Label.cpp
Normal file
@ -0,0 +1,17 @@
|
||||
//
|
||||
// Created by selim on 18.12.22.
|
||||
//
|
||||
|
||||
#include "Label.h"
|
||||
|
||||
namespace gtkpp {
|
||||
|
||||
Label::Label(): Widget() {
|
||||
_widget = gtk_label_new("");
|
||||
}
|
||||
|
||||
void Label::setText(const std::string& text) {
|
||||
gtk_label_set_text(GTK_LABEL(_widget), text.c_str());
|
||||
}
|
||||
|
||||
}
|
||||
23
gtkpp/Label.h
Normal file
23
gtkpp/Label.h
Normal file
@ -0,0 +1,23 @@
|
||||
//
|
||||
// Created by selim on 18.12.22.
|
||||
//
|
||||
|
||||
#ifndef AUTOCAT_GNOME_LABEL_H
|
||||
#define AUTOCAT_GNOME_LABEL_H
|
||||
|
||||
#include "Widget.h"
|
||||
|
||||
namespace gtkpp {
|
||||
|
||||
class Label: public Widget {
|
||||
public:
|
||||
Label();
|
||||
using Widget::Widget;
|
||||
|
||||
public:
|
||||
void setText(const std::string& text);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif //AUTOCAT_GNOME_LABEL_H
|
||||
@ -8,20 +8,25 @@ namespace gtkpp {
|
||||
|
||||
void setupListItemCallback(GtkListItemFactory* factory, GtkListItem* list_item, void* data) {
|
||||
auto self = reinterpret_cast<ListItemFactory*>(data);
|
||||
self->setup();
|
||||
auto widget = self->setup();
|
||||
gtk_list_item_set_child(list_item, widget);
|
||||
}
|
||||
|
||||
void bindListItemCallback(GtkListItemFactory* factory, GtkListItem* list_item, void* data) {
|
||||
auto self = reinterpret_cast<ListItemFactory*>(data);
|
||||
auto widget = gtk_list_item_get_child(list_item);
|
||||
auto item = gtk_list_item_get_item (list_item);
|
||||
self->bind(widget);
|
||||
}
|
||||
|
||||
ListItemFactory::ListItemFactory() {
|
||||
_factory = gtk_signal_list_item_factory_new();
|
||||
g_signal_connect(_factory, "setup", G_CALLBACK(setupListItemCallback), this);
|
||||
g_signal_connect(_factory, "bind", G_CALLBACK(bindListItemCallback), this);
|
||||
}
|
||||
|
||||
GtkListItemFactory *ListItemFactory::gobj() const {
|
||||
return _factory;
|
||||
}
|
||||
|
||||
void ListItemFactory::setup() {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -5,6 +5,7 @@
|
||||
#ifndef AUTOCAT_GNOME_LISTITEMFACTORY_H
|
||||
#define AUTOCAT_GNOME_LISTITEMFACTORY_H
|
||||
|
||||
#include "Widget.h"
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
namespace gtkpp {
|
||||
@ -18,7 +19,8 @@ namespace gtkpp {
|
||||
[[nodiscard]] GtkListItemFactory* gobj() const;
|
||||
|
||||
public:
|
||||
virtual void setup();
|
||||
virtual GtkWidget* setup() = 0;
|
||||
virtual void bind(GtkWidget* widget) = 0;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@ -6,8 +6,8 @@
|
||||
|
||||
namespace gtkpp {
|
||||
|
||||
ListView::ListView(SelectionModel selectionModel, ListItemFactory factory) {
|
||||
_widget = gtk_list_view_new(selectionModel.gobj(), factory.gobj());
|
||||
ListView::ListView(SelectionModel selectionModel, ListItemFactory* factory) {
|
||||
_widget = gtk_list_view_new(selectionModel.gobj(), factory->gobj());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -13,7 +13,7 @@ namespace gtkpp {
|
||||
|
||||
class ListView: public Widget {
|
||||
public:
|
||||
ListView(SelectionModel selectionModel, ListItemFactory factory);
|
||||
ListView(SelectionModel selectionModel, ListItemFactory* factory);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@ -8,7 +8,7 @@ namespace gtkpp {
|
||||
|
||||
SelectionModel::SelectionModel(gtkpp::Selection selection) {
|
||||
|
||||
char *array[] = { "one", "two", "three", "four", NULL };
|
||||
const char *array[] = { "one", "two", "three", "four", nullptr };
|
||||
GtkStringList *sl = gtk_string_list_new ((const char * const *) array);
|
||||
|
||||
switch (selection) {
|
||||
|
||||
@ -21,7 +21,7 @@ namespace gtkpp {
|
||||
|
||||
Widget::Widget(GtkWidget *widget) {
|
||||
_widget = widget;
|
||||
g_signal_connect(_widget, "clicked", G_CALLBACK(clickedCallback), this);
|
||||
//g_signal_connect(_widget, "clicked", G_CALLBACK(clickedCallback), this);
|
||||
}
|
||||
|
||||
Widget::Widget(GtkBuilder *builder, const char *id) {
|
||||
|
||||
@ -9,10 +9,13 @@
|
||||
#include "../services/Storage.h"
|
||||
#include "../gtkpp/HeaderBar.h"
|
||||
#include "../gtkpp/Separator.h"
|
||||
#include "../gtkpp/SelectionModel.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
MainWindow::MainWindow(): gtkpp::Window(true) {
|
||||
MainWindow::MainWindow(): gtkpp::Window(true),
|
||||
_vehiclesListView(gtkpp::SelectionModel(gtkpp::Selection::Single),
|
||||
&_vehiclesListFactory) {
|
||||
|
||||
setDefaultSize(640, 480);
|
||||
setResizable(true);
|
||||
@ -28,6 +31,7 @@ MainWindow::MainWindow(): gtkpp::Window(true) {
|
||||
|
||||
gtkpp::Box leftPanel(GTK_ORIENTATION_VERTICAL, 0);
|
||||
leftPanel.append(leftHeader);
|
||||
leftPanel.append(_vehiclesListView);
|
||||
|
||||
gtkpp::HeaderBar rightHeader;
|
||||
gtkpp::Box rightPanel(GTK_ORIENTATION_VERTICAL, 0);
|
||||
|
||||
@ -8,12 +8,17 @@
|
||||
#include "../gtkpp/Window.h"
|
||||
#include "../gtkpp/Leaflet.h"
|
||||
#include "../gtkpp/Button.h"
|
||||
#include "../gtkpp/ListView.h"
|
||||
#include "../models/VehiclesListFactory.h"
|
||||
|
||||
class MainWindow: public gtkpp::Window {
|
||||
private:
|
||||
gtkpp::Leaflet _leaflet;
|
||||
gtkpp::Button _addNumberButton;
|
||||
|
||||
VehiclesListFactory _vehiclesListFactory;
|
||||
gtkpp::ListView _vehiclesListView;
|
||||
|
||||
public:
|
||||
explicit MainWindow();
|
||||
void showCheckDialog();
|
||||
|
||||
@ -3,7 +3,19 @@
|
||||
//
|
||||
|
||||
#include "VehiclesListFactory.h"
|
||||
#include "../gtkpp/Label.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
VehiclesListFactory::VehiclesListFactory() {
|
||||
|
||||
}
|
||||
|
||||
GtkWidget* VehiclesListFactory::setup() {
|
||||
gtkpp::Label label;
|
||||
return label.gobj();
|
||||
}
|
||||
|
||||
void VehiclesListFactory::bind(GtkWidget *widget) {
|
||||
gtkpp::Label label(widget);
|
||||
label.setText("qwe");
|
||||
}
|
||||
|
||||
@ -7,9 +7,13 @@
|
||||
|
||||
#include "../gtkpp/ListItemFactory.h"
|
||||
|
||||
class VehiclesListFactory: gtkpp::ListItemFactory {
|
||||
class VehiclesListFactory: public gtkpp::ListItemFactory {
|
||||
public:
|
||||
VehiclesListFactory();
|
||||
|
||||
public:
|
||||
GtkWidget* setup() override;
|
||||
void bind(GtkWidget* widget) override;
|
||||
};
|
||||
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user