/*************************************************************************** * Copyright (C) 2003-2005 * * Unai Garro (ugarro@users.sourceforge.net) * * Jason Kivlighn (jkivlighn@gmail.com) * * * * 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. * ***************************************************************************/ #include "dietviewdialog.h" #include #include #include DietViewDialog::DietViewDialog( TQWidget *parent, const RecipeList &recipeList, int dayNumber, int mealNumber, const TQValueList &dishNumbers ) : KDialogBase( parent, "dietViewDialog", true, TQString::null, KDialogBase::User2 | KDialogBase::Close | KDialogBase::User1, KDialogBase::User2, false, KStdGuiItem::print() ) { setButtonText( KDialogBase::User2, i18n( "Create &Shopping List" ) ); // Design the dialog TQVBox *page = makeVBoxMainWidget(); // The html part dietView = new TDEHTMLPart( page ); setInitialSize( TQSize(350, 450) ); setSizeGripEnabled( true ); connect ( this, TQ_SIGNAL( user2Clicked() ), this, TQ_SLOT( slotOk() ) ); connect ( this, TQ_SIGNAL( closeClicked() ), this, TQ_SLOT( close() ) ); connect ( this, TQ_SIGNAL( user1Clicked() ), this, TQ_SLOT( print() ) ); // Show the diet showDiet( recipeList, dayNumber, mealNumber, dishNumbers ); } DietViewDialog::~DietViewDialog() {} void DietViewDialog::showDiet( const RecipeList &recipeList, int dayNumber, int mealNumber, const TQValueList &dishNumbers ) { // Header TQString htmlCode = TQString( "%1" ).arg( i18n( "Diet" ) ); // CSS htmlCode += ""; htmlCode += ""; // /Header // Calendar border htmlCode += TQString( "
" ); // Title htmlCode += TQString( "
" ); htmlCode += TQString( "

%1

" ).arg( i18n( "Diet" ) ); // Diet table htmlCode += TQString( "
" ); htmlCode += TQString( "" ); TQValueList ::ConstIterator it; it = dishNumbers.begin(); RecipeList::ConstIterator rit; rit = recipeList.begin(); for ( int row = 0, day = 0; row <= ( ( dayNumber - 1 ) / 7 ); row++ ) // New row (week) { htmlCode += TQString( "" ); for ( int col = 0; ( col < 7 ) && ( day < dayNumber ); col++, day++ ) // New column (day) { htmlCode += TQString( "" ); } htmlCode += TQString( "" ); } htmlCode += TQString( "
" ); htmlCode += TQString( "
" ); htmlCode += TQString( i18n( "Day %1" ) ).arg( day + 1 ); htmlCode += TQString( "
" ); for ( int meal = 0;meal < mealNumber;meal++ ) // Meals in each cell { int dishNumber = *it; htmlCode += TQString( "
" ); for ( int dish = 0; dish < dishNumber;dish++ ) // Dishes in each Meal { htmlCode += TQString( "
" ); htmlCode += ( *rit ).title; htmlCode += "
"; htmlCode += TQString( "
" ); rit++; } it++; htmlCode += TQString( "
" ); } it = dishNumbers.begin(); // meals have same dish number everyday htmlCode += TQString( "
" ); htmlCode += TQString( "
" ); htmlCode += TQString( "
" ); resize( TQSize( 600, 400 ) ); // Display it dietView->begin( KURL( locateLocal( "tmp", "/" ) ) ); // Initialize to tmp dir, where photos and logos can be stored dietView->write( htmlCode ); dietView->end(); } void DietViewDialog::print( void ) { dietView->view()->print(); } void DietViewDialog::slotOk( void ) { emit signalOk(); close(); } #include "dietviewdialog.moc"