From 60cacb4babb46ae2ab22ae0b7b7357012887460d Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Sun, 24 Apr 2022 15:44:35 +0200 Subject: Better viewer. Set license to GPL 3. --- src/mainwindow.cc | 38 +++++++++++++++++++++++++------------- 1 file changed, 25 insertions(+), 13 deletions(-) (limited to 'src/mainwindow.cc') diff --git a/src/mainwindow.cc b/src/mainwindow.cc index c1b05f7..eae86d0 100644 --- a/src/mainwindow.cc +++ b/src/mainwindow.cc @@ -12,7 +12,7 @@ * * Qookie is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or + * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * Qookie is distributed in the hope that it will be useful, @@ -26,6 +26,8 @@ */ #include "mainwindow.h" +#include + #include #include #include @@ -33,6 +35,7 @@ #include #include "database.h" +#include "viewer.h" MainWindow::MainWindow(Database& db) : db(db) @@ -56,21 +59,22 @@ MainWindow::MainWindow(Database& db) // QDockWidget *browser = new QDockWidget("Browser"); listWidget = new QListWidget(this); - listWidget->setIconSize({128, 128}); + listWidget->setIconSize({64, 64}); browser->setWidget(listWidget); // // Create the viewer // -// viewer = new Viewer(); -// setCentralWidget(viewer); + viewer = new Viewer(); + setCentralWidget(viewer); addToolBar(Qt::TopToolBarArea, toolbar); addDockWidget(Qt::LeftDockWidgetArea, browser); -// connect signal: -// void itemChanged(QListWidgetItem *item) in listWidget to itemchanged slot + QObject::connect(listWidget, &QListWidget::currentRowChanged, + this, &MainWindow::itemChanged); + listWidget->setSortingEnabled(true); readDatabase(); } @@ -97,15 +101,23 @@ void MainWindow::readDatabase() icon.addPixmap(QPixmap::fromImage(image)); listItem->setIcon(icon); } + else + { + QIcon icon; + QImage image(QSize({1,1}), QImage::Format_RGBA8888); + image.fill(0); + icon.addPixmap(QPixmap::fromImage(image)); + listItem->setIcon(icon); + } listItem->setData(Qt::UserRole, item.id); - //listItem->setSizeHint({200,200}); listWidget->addItem(listItem); } } -//itemchanged slot(item*) -//{ -// id = item->data(Qt::UserRole); -// auto recipe = db.getRecipe(id); -// viewer->show(recipe); -//} +void MainWindow::itemChanged(int row) +{ + auto item = listWidget->currentItem(); + auto id = item->data(Qt::UserRole).toInt(); + auto recipe = db.getRecipe(id); + viewer->show(recipe); +} -- cgit v1.2.3