#include "menu.h"#include <QtWidgets>#include <QDebug>#include <QApplication>enum actions{ ACT_CALCULATOR = 0, ACT_CALENDAR, ACT_NOTES,};menu::menu(QWidget *parent) : QWidget(parent){ calculator *mainCalc = new calculator(parent); testWidgetList = new QListWidget(); testWidgetList->setViewMode(QListView::IconMode); testWidgetList->setResizeMode(QListView::Adjust); testWidgetList->setDragEnabled(false); QListWidget::connect(testWidgetList,SIGNAL(itemClicked(QListWidgetItem*)),this,SLOT(ItemClicked(QListWidgetItem*))); testItemWidget = new QListWidgetItem(QIcon("D:\\qtPictures/calc.png") , QString("calculator"), testWidgetList); testItemWidget->setData(16,ACT_CALCULATOR); testWidgetList->addItem(testItemWidget); testItemWidget = new QListWidgetItem(QIcon("D:\\qtPictures/calendar.jpg") , QString("calendar"), testWidgetList); testItemWidget->setData(16,ACT_CALENDAR); testWidgetList->addItem(testItemWidget); testItemWidget = new QListWidgetItem(QIcon("D:\\qtPictures/zametki.png") , QString("notes"), testWidgetList); testItemWidget->setData(16,ACT_NOTES); testWidgetList->addItem(testItemWidget); QGridLayout *testlay = new QGridLayout; testlay->addWidget(testWidgetList); setLayout(testlay); setWindowTitle(tr("Fuorg"));}void menu::ItemClicked(QListWidgetItem *wi){ int action = wi->data(16).toInt(); qDebug() << "Item clicked: " << action; this->handleAction(action);}void menu::handleAction(int act){ switch(act) { case ACT_CALCULATOR: mainCalc->show(); break; case ACT_CALENDAR: qDebug() << "Calendar"; break; case ACT_NOTES: qDebug() << "Notes"; break; default: qDebug() << "Unhandled action: " << act; break;//do nothing }}
#ifndef MENU_H#define MENU_H#include <QListWidget>#include <QListWidgetItem>#include <QIcon>#include <QlistView>#include <QGridLayout>#include <QModelIndex>#include "calculator.h"class menu : public QWidget{ Q_OBJECTpublic: menu(QWidget *parent = 0); QListWidget *testWidgetList; QListWidgetItem *testItemWidget; void handleAction(int act); calculator *mainCalc;public slots: void ItemClicked(QListWidgetItem *wi);};#endif // MENU_H