QuickShow: Allow dropping an image file on the QuickShow window

We now try to open image files dropped on us from FileManager. :^)

The QuickShow code is not exactly well-factored, and should be fixes up
to not do the same thing twice, etc.
This commit is contained in:
Andreas Kling 2019-12-19 20:39:11 +01:00
parent f276030969
commit ea91f24a49
Notes: sideshowbarker 2024-07-19 10:48:10 +09:00
3 changed files with 51 additions and 5 deletions

View file

@ -44,30 +44,32 @@ int main(int argc, char** argv)
if (argc > 1)
path = argv[1];
auto bitmap = load_png(path);
auto bitmap = GraphicsBitmap::load_from_file(path);
if (!bitmap) {
fprintf(stderr, "Failed to load %s\n", path);
return 1;
}
auto window = GWindow::construct();
auto widget = QSWidget::construct();
widget->set_path(path);
widget->set_bitmap(*bitmap);
auto update_window_title = [&](int scale) {
window->set_title(String::format("QuickShow: %s %s %d%%", path, bitmap->size().to_string().characters(), scale));
window->set_title(String::format("QuickShow: %s %s %d%%", widget->path().characters(), widget->bitmap()->size().to_string().characters(), scale));
};
window->set_double_buffering_enabled(true);
update_window_title(100);
window->set_rect(200, 200, bitmap->width(), bitmap->height());
auto widget = QSWidget::construct();
widget->on_scale_change = [&](int scale) {
update_window_title(scale);
};
widget->set_bitmap(*bitmap);
window->set_main_widget(widget);
window->show();
bitmap = nullptr;
return app.exec();
}