main.cpp 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #include "QSWidget.h"
  2. #include <LibGUI/GAction.h>
  3. #include <LibGUI/GApplication.h>
  4. #include <LibGUI/GBoxLayout.h>
  5. #include <LibGUI/GLabel.h>
  6. #include <LibGUI/GMenu.h>
  7. #include <LibGUI/GMenuBar.h>
  8. #include <LibGUI/GWindow.h>
  9. #include <SharedGraphics/PNGLoader.h>
  10. #include <stdio.h>
  11. int main(int argc, char** argv)
  12. {
  13. GApplication app(argc, argv);
  14. auto menubar = make<GMenuBar>();
  15. auto app_menu = make<GMenu>("QuickShow");
  16. app_menu->add_action(GAction::create("Quit", { Mod_Alt, Key_F4 }, [](const GAction&) {
  17. GApplication::the().quit(0);
  18. return;
  19. }));
  20. menubar->add_menu(move(app_menu));
  21. auto file_menu = make<GMenu>("File");
  22. menubar->add_menu(move(file_menu));
  23. auto help_menu = make<GMenu>("Help");
  24. help_menu->add_action(GAction::create("About", [](const GAction&) {
  25. dbgprintf("FIXME: Implement Help/About\n");
  26. }));
  27. menubar->add_menu(move(help_menu));
  28. app.set_menubar(move(menubar));
  29. #if 0
  30. if (argc != 2) {
  31. printf("usage: qs <image-file>\n");
  32. return 0;
  33. }
  34. #endif
  35. const char* path = "/res/wallpapers/sunset-retro.png";
  36. if (argc > 1)
  37. path = argv[1];
  38. auto bitmap = load_png(path);
  39. if (!bitmap) {
  40. fprintf(stderr, "Failed to load %s\n", path);
  41. return 1;
  42. }
  43. auto* window = new GWindow;
  44. auto update_window_title = [&](int scale) {
  45. window->set_title(String::format("QuickShow: %s %s %d%%", path, bitmap->size().to_string().characters(), scale));
  46. };
  47. window->set_double_buffering_enabled(true);
  48. update_window_title(100);
  49. window->set_rect(200, 200, bitmap->width(), bitmap->height());
  50. auto* widget = new QSWidget(nullptr);
  51. widget->on_scale_change = [&](int scale) {
  52. update_window_title(scale);
  53. };
  54. widget->set_bitmap(*bitmap);
  55. window->set_main_widget(widget);
  56. window->set_should_exit_event_loop_on_close(true);
  57. window->show();
  58. return app.exec();
  59. }