/*************************************************************************** * Copyright (C) 2002-2003 Andi Peredri * * andi@ukr.net * * * * This program 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 * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #include "pdn.h" #include "pdnpreview.h" #include PdnPreview::PdnPreview(QWidget* parent) : QFrame(parent) { pdn = 0; setFont(QFont(font().family(), 10)); // layout QGridLayout* grid = new QGridLayout(this, 7, 2, 5, 0); grid->addMultiCellWidget(m_event = new QLabel(this), 0, 1, 0, 1); grid->addWidget(new QLabel(tr("White")+":", this), 2, 0); grid->addWidget(m_white = new QLabel(this), 2, 1); grid->addWidget(new QLabel(tr("Black")+":", this), 3, 0); grid->addWidget(m_black = new QLabel(this), 3, 1); grid->addMultiCellWidget(m_type = new QLabel(this), 4, 4, 0, 1); grid->addMultiCellWidget(lb = new QListBox(this), 5, 5, 0, 1); grid->addMultiCellWidget(m_boardonly = new QCheckBox(tr("Open board only"), this), 6, 6, 0, 1); m_event->setAlignment(Qt::AlignCenter | Qt::WordBreak); m_event->setFont(QFont(font().family(), font().pointSize(), QFont::Bold)); m_type->setAlignment(Qt::AlignCenter | Qt::WordBreak); m_type->setFont(QFont(font().family(), font().pointSize(), QFont::Bold)); lb->setVScrollBarMode(QScrollView::AlwaysOn); connect(lb, SIGNAL(highlighted(int)), this, SLOT(slotInfo(int))); connect(lb, SIGNAL(selected(int)), this, SIGNAL(selected(int))); m_boardonly->setChecked(true); m_boardonly->setEnabled(false); } PdnPreview::~PdnPreview() { if(pdn) delete pdn; } void PdnPreview::previewUrl(const QUrl& url) { lb->clear(); if(pdn) delete pdn; pdn = new Pdn; pdn->open(url.path()); QPixmap pixmap = QPixmap::fromMimeSource("logo.png"); for(int i=1; i <= pdn->count(); i++) lb->insertItem(pixmap, QString::number(i)); } void PdnPreview::slotInfo(int id) { if(pdn->parse(id)) { m_event->setText(pdn->get(Pdn::Event)); m_white->setText(pdn->get(Pdn::White)+(pdn->isWhite() ? "*" : "")); m_black->setText(pdn->get(Pdn::Black)+(pdn->isWhite() ? "" : "*")); int type = pdn->get(Pdn::Type).toInt(); m_type->setText(typeToString(type)); } else { m_event->clear(); m_white->clear(); m_black->clear(); m_type->setText(tr("No preview available.")); } } QString PdnPreview::typeToString(int type) { switch(type) { case ENGLISH: return tr("English draughts"); case RUSSIAN: return tr("Russian draughts"); }; return tr("Unknown game type"); }