/* $Id: RecipeView.cpp,v 1.7 2003/01/12 16:19:56 rjesse Exp $
 *
 * This file is part of the Mango recipe management distribution.
 * Copyright (c) 2000-2003, Roland Jesse
 * All rights reserved.
 *
 * For license and copyright information see the file COPYRIGHT or 
 * <http://www.opensource.org/licenses/bsd-license.html>.
 */

#include "RecipeView.h"
#include "RecipeModel.h"
#include "BusyWidget.h"
#include <qcombobox.h>
#include <qlabel.h>
#include <qlayout.h>
#include <qlineedit.h>
#include <qmultilineedit.h>
#include <qpushbutton.h>
#include <qstring.h>
#include <qwidget.h>

RecipeView::RecipeView( QWidget* parent, QString title, RecipeModel* model)
   : QextMdiChildView( parent), m_model( model)
{
   QString cap( title);
   cap.append( " - <unknown>");
   setMDICaption( cap);
   setFocusPolicy( QWidget::NoFocus);
   
   // One line for searching recipe names & one for searching categories
   QLabel* searchLabel = new QLabel( tr("Search"), this);
   QLineEdit* searchField = new QLineEdit( this);
   QPushButton* searchButton = new QPushButton( tr("Go"), this);
   BusyWidget* searchBusy = new BusyWidget( this);

   QLabel* categoryLabel = new QLabel( tr("Category"), this);
   QLineEdit* categoryField = new QLineEdit( this);
   // Match all categories or is one enough?
   QComboBox* categoryAndOr = new QComboBox( false, this);
     categoryAndOr->insertItem( "And");
     categoryAndOr->insertItem( "Or");
   QComboBox* categories = new QComboBox( false, this);

   // One line to display name, categories, and yielding of search result
   QLabel* resultNameLabel = new QLabel( tr("Name:"), this);
   QLabel* resultCategoriesLabel = new QLabel( tr("Categories:"), this);
   QLabel* resultYieldsLabel = new QLabel( tr("Yields:"), this);
   m_currentName = new QLabel( this);
   m_currentCategories = new QLabel( this);
   m_currentYields = new QLabel( this);

   // One line to display all ingredients and the description
   QLabel* currentIngredientsLabel = new QLabel( tr("Ingredients:"), this);
   QLabel* currentDescriptionLabel = new QLabel( tr("Description:"), this);
   m_currentIngredients = new QMultiLineEdit( this);
   m_currentDescription = new QMultiLineEdit( this);

   // One line with action buttons
   QPushButton* exportButton = new QPushButton( tr("Export"), this);
   QPushButton* loadButton = new QPushButton( tr("Load"), this);
   QPushButton* addButton = new QPushButton( tr("Add"), this);

   // Layout all widgets.
   QHBoxLayout* searchBox = new QHBoxLayout;
     QVBoxLayout* searchLabelBox = new QVBoxLayout;
       searchLabelBox->addWidget( searchLabel);
       searchLabelBox->addWidget( categoryLabel);
     QVBoxLayout* searchFieldBox = new QVBoxLayout;
       searchFieldBox->addWidget( searchField);
       searchFieldBox->addWidget( categoryField);
     QVBoxLayout* searchButtonBox = new QVBoxLayout;
       searchButtonBox->addWidget( searchButton);
       searchButtonBox->addWidget( categoryAndOr);
     QVBoxLayout* searchBusyBox = new QVBoxLayout;
       searchBusyBox->addWidget( searchBusy);
       searchBusyBox->addWidget( categories);
     searchBox->addLayout( searchLabelBox);
     searchBox->addLayout( searchFieldBox);
     searchBox->addLayout( searchButtonBox);
     searchBox->addLayout( searchBusyBox);
   QHBoxLayout* resultBox = new QHBoxLayout();
     resultBox->addWidget( resultNameLabel);
     resultBox->addWidget( m_currentName);
     resultBox->addWidget( resultCategoriesLabel);
     resultBox->addWidget( m_currentCategories);
     resultBox->addWidget( resultYieldsLabel);
     resultBox->addWidget( m_currentYields);
   QHBoxLayout* howtoBox = new QHBoxLayout();
     QVBoxLayout* ingredientBox = new QVBoxLayout;
       ingredientBox->addWidget( currentIngredientsLabel);
       ingredientBox->addWidget( m_currentIngredients);
     QVBoxLayout* descriptionBox = new QVBoxLayout;
       descriptionBox->addWidget( currentDescriptionLabel);
       descriptionBox->addWidget( m_currentDescription);
     howtoBox->addLayout( ingredientBox);
     howtoBox->addLayout( descriptionBox);
   QHBoxLayout* buttonBox = new QHBoxLayout();
     buttonBox->addStretch();
     buttonBox->addWidget( exportButton);
     buttonBox->addWidget( loadButton);
     buttonBox->addWidget( addButton);
   QVBoxLayout* mainLayout = new QVBoxLayout( this);
     mainLayout->addLayout( searchBox);
     mainLayout->addLayout( resultBox);
     mainLayout->addLayout( howtoBox);
     mainLayout->addLayout( buttonBox);
}

RecipeView::~RecipeView() {
}

/** Reset all variable widget entries. */
void
RecipeView::clearDisplay() {
   m_currentName->setText( "");
   m_currentCategories->setText( "");
   m_currentYields->setText( "");
}

//
// SLOTs
//

void
RecipeView::slotUpdate() {
   clearDisplay();
}

