summaryrefslogtreecommitdiff
path: root/src/mainwindow.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/mainwindow.cc')
-rw-r--r--src/mainwindow.cc38
1 files changed, 25 insertions, 13 deletions
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 <iostream>
+
#include <QToolBar>
#include <QDockWidget>
#include <QLabel>
@@ -33,6 +35,7 @@
#include <QListWidget>
#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);
+}