Newer
Older
Import / applications / Photoframe / src / devicelist.cpp
#include <QLabel>
#include <QKeyEvent>
#include <QSettings>
#include <QSound>
#include "devicelist.h"
#include "text.h"
#include "image.h"
#include "manager.h"


const char *deviceNames[] = {
	QT_TRANSLATE_NOOP("DPF","Internal"),
	QT_TRANSLATE_NOOP("DPF","SD Card"),
	QT_TRANSLATE_NOOP("DPF","USB"),
	QT_TRANSLATE_NOOP("DPF","Network"),
	QT_TRANSLATE_NOOP("DPF","Flickr"),
	QT_TRANSLATE_NOOP("DPF","Back")
};


DeviceList::DeviceList(QWidget *parent, const char *title, const char *iconfile) : Stage(parent)
{
	QLabel *icon = new QLabel(this);
	icon->setPixmap(Image::icon(iconfile, 72));
	icon->move(10, 10);

	new Text(this, 110, 20, title, 37, QColor(0,0,0));
	new Text(this, 108, 18, title, 37, QColor(0xEf,0xEF,0xFC));

	for (int i = 0; i < 6; i++)
		items[i] = new MenuItem(this, 18, 140 + 50*i, deviceNames[i]);

	curItem = 0;
	items[curItem]->select();
	emit deviceChanged(deviceNames[curItem]);
}


DeviceList::~DeviceList()
{
	for (int i = 0; i < 6; i++)
		delete items[i];
}


void DeviceList::keyPressEvent(QKeyEvent *ke)
{
	if ( ke->key() == Qt::Key_Escape ) {
		emit setStage(-1);
	}

	if ( ke->key() == Qt::Key_Right ) {
		emit switchFocus();
	}

	if ( ke->key() == Qt::Key_Up ) {
		items[curItem]->unselect();
		curItem--;
		if (curItem < 0)
			curItem = 5;
		if (curItem == 0)
			QSound::play("sounds/Prev.wav");
		else
			QSound::play("sounds/Next.wav");
		items[curItem]->select();
		emit deviceChanged(deviceNames[curItem]);
	} else if ( ke->key() == Qt::Key_Down ) {
		items[curItem]->unselect();
		curItem++;
		if (curItem > 5)
			curItem = 0;
		if (curItem == 5)
			QSound::play("sounds/Prev.wav");
		else
			QSound::play("sounds/Next.wav");
		items[curItem]->select();
		emit deviceChanged(deviceNames[curItem]);
//	} else if ( ke->key() == Qt::Key_Select ) {
	} else if ( ke->key() == Qt::Key_Return ) {
		if (std::string(deviceNames[curItem]) == "Back") {
			emit setStage(-2);
			//items[curItem]->unselect();
			//curItem = 0;
			//items[curItem]->select();
		} else
			emit deviceChanged(deviceNames[curItem]);
	}
}