add Qt example, GTK example fixes, README update

This commit is contained in:
Syping 2021-08-27 20:07:14 +02:00
parent 350916588f
commit 33c3dcb512
9 changed files with 181 additions and 31 deletions

View file

@ -1,12 +1,12 @@
cmake_minimum_required(VERSION 3.7)
enable_language(CXX)
project(ragephoto-gtkviewer LANGUAGES CXX)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
find_package(PkgConfig REQUIRED)
pkg_check_modules(gtkmm REQUIRED gtkmm-3.0)
pkg_check_modules(GTKMM REQUIRED gtkmm-3.0)
project(ragephoto-gtkviewer LANGUAGES CXX)
@ -22,9 +22,9 @@ set(GTKVIEWER_SOURCES
if(TARGET ragephoto)
set(RAGEPHOTO_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/src)
add_executable(ragephoto-gtkviewer ${GTKVIEWER_HEADERS} ${GTKVIEWER_SOURCES})
target_link_libraries(ragephoto-gtkviewer ${gtkmm_LIBRARIES} ragephoto)
target_link_directories(ragephoto-gtkviewer PRIVATE ${gtkmm_LIBRARY_DIRS})
target_include_directories(ragephoto-gtkviewer PRIVATE ${gtkmm_INCLUDE_DIRS} ${RAGEPHOTO_INCLUDE_DIRS})
target_link_libraries(ragephoto-gtkviewer ${GTKMM_LIBRARIES} ragephoto)
target_link_directories(ragephoto-gtkviewer PRIVATE ${GTKMM_LIBRARY_DIRS})
target_include_directories(ragephoto-gtkviewer PRIVATE ${GTKMM_INCLUDE_DIRS} ${RAGEPHOTO_INCLUDE_DIRS})
install(TARGETS ragephoto-gtkviewer DESTINATION bin)
else()
message("ragephoto-gtkviewer need to be build with libragephoto together")

View file

@ -22,7 +22,7 @@
#include <RagePhoto.h>
#include <iostream>
PhotoViewer::PhotoViewer(Gtk::Label *title_label, Gtk::Label *json_label) : p_title_label(title_label), p_json_label(json_label)
PhotoViewer::PhotoViewer(Gtk::Window *win) : p_win(win)
{
}
@ -75,10 +75,7 @@ void PhotoViewer::open_file(const char *filename)
GdkPixbuf *c_pixbuf = gdk_pixbuf_loader_get_pixbuf(loader);
p_image = Glib::wrap(c_pixbuf);
p_title_label->set_text("Title: " + ragePhoto.title());
// p_title_label->show();
get_parent_window()->set_title("RagePhoto GTK Photo Viewer - " + ragePhoto.title());
p_win->set_title("RagePhoto GTK Photo Viewer - " + ragePhoto.title());
free(photoData);

View file

@ -19,21 +19,20 @@
#ifndef PHOTOVIEWER_H
#define PHOTOVIEWER_H
#include <gtkmm/drawingarea.h>
#include <gtkmm/label.h>
#include <gdkmm/pixbuf.h>
#include <gtkmm/drawingarea.h>
#include <gtkmm/window.h>
class PhotoViewer : public Gtk::DrawingArea
{
public:
PhotoViewer(Gtk::Label *title_label, Gtk::Label *json_label);
PhotoViewer(Gtk::Window *win);
void open_file(const char *filename);
protected:
bool on_draw(const Cairo::RefPtr<Cairo::Context>& cr) override;
Glib::RefPtr<Gdk::Pixbuf> p_image;
Gtk::Label *p_title_label;
Gtk::Label *p_json_label;
Gtk::Window *p_win;
};
#endif // PHOTOVIEWER_H

View file

@ -36,24 +36,25 @@ int main(int argc, char *argv[])
win.set_resizable(false);
Gtk::Box vertical_box(Gtk::ORIENTATION_VERTICAL);
vertical_box.set_margin_bottom(6);
vertical_box.set_spacing(6);
Gtk::Label title_label;
Gtk::Label json_label;
PhotoViewer photo_viewer(&title_label, &json_label);
PhotoViewer photo_viewer(&win);
vertical_box.add(photo_viewer);
vertical_box.add(title_label);
vertical_box.add(json_label);
photo_viewer.show();
Gtk::Box horizontal_box(Gtk::ORIENTATION_HORIZONTAL);
horizontal_box.set_margin_left(6);
horizontal_box.set_margin_right(6);
horizontal_box.set_spacing(6);
vertical_box.add(horizontal_box);
Gtk::Button open_button;
open_button.set_label("Open");
open_button.set_hexpand(true);
open_button.set_can_default(false);
open_button.set_size_request(100);
open_button.signal_clicked().connect([&](){
Gtk::FileChooserDialog dialog("Open Photo", Gtk::FILE_CHOOSER_ACTION_OPEN);
Gtk::FileChooserDialog dialog("Open Photo...", Gtk::FILE_CHOOSER_ACTION_OPEN);
dialog.set_transient_for(win);
dialog.add_button("_Cancel", Gtk::RESPONSE_CANCEL);
@ -62,6 +63,7 @@ int main(int argc, char *argv[])
Glib::RefPtr<Gtk::FileFilter> filter_photo = Gtk::FileFilter::create();
filter_photo->set_name("GTA V Photo");
filter_photo->add_pattern("PGTA5*");
dialog.add_filter(filter_photo);
int result = dialog.run();
@ -81,7 +83,7 @@ int main(int argc, char *argv[])
Gtk::Button close_button;
close_button.set_label("Close");
close_button.set_hexpand(true);
close_button.set_can_default(false);
close_button.set_size_request(100);
close_button.signal_clicked().connect([&](){
win.close();
});