summaryrefslogtreecommitdiffstats
path: root/src/dialogs/createingredientweightdialog.cpp
diff options
context:
space:
mode:
authorMichele Calgaro <[email protected]>2024-10-13 11:56:14 +0900
committerMichele Calgaro <[email protected]>2024-10-21 09:29:11 +0900
commit0c8ed6c9a4000af8f48581a81c4b5c2f5b9fd502 (patch)
tree10f9d3223f0a0904a0748a28ca44da52ee1092b7 /src/dialogs/createingredientweightdialog.cpp
parent7d5ba3180a82a0827c1fbd6dc93a2abf4f882c37 (diff)
downloadkrecipes-0c8ed6c9a4000af8f48581a81c4b5c2f5b9fd502.tar.gz
krecipes-0c8ed6c9a4000af8f48581a81c4b5c2f5b9fd502.zip
Rearrange folders structure to remove unnecessary 'krecipes' second level subfolder
Signed-off-by: Michele Calgaro <[email protected]>
Diffstat (limited to 'src/dialogs/createingredientweightdialog.cpp')
-rw-r--r--src/dialogs/createingredientweightdialog.cpp124
1 files changed, 124 insertions, 0 deletions
diff --git a/src/dialogs/createingredientweightdialog.cpp b/src/dialogs/createingredientweightdialog.cpp
new file mode 100644
index 0000000..45bf158
--- /dev/null
+++ b/src/dialogs/createingredientweightdialog.cpp
@@ -0,0 +1,124 @@
+/***************************************************************************
+* Copyright (C) 2006 by *
+* Jason Kivlighn ([email protected]) *
+* *
+* 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 "createingredientweightdialog.h"
+
+#include <tqgroupbox.h>
+#include <tqlabel.h>
+#include <tqpushbutton.h>
+#include <tqlayout.h>
+#include <tqtooltip.h>
+#include <tqwhatsthis.h>
+#include <tqvbox.h>
+
+#include <tdemessagebox.h>
+#include <tdelocale.h>
+
+#include "widgets/unitcombobox.h"
+#include "widgets/prepmethodcombobox.h"
+#include "widgets/fractioninput.h"
+#include "datablocks/weight.h"
+#include "backends/recipedb.h"
+
+CreateIngredientWeightDialog::CreateIngredientWeightDialog( TQWidget* parent, RecipeDB *db )
+ : KDialogBase( parent, "createIngWeightDialog", true, TQString::null,
+ KDialogBase::Ok | KDialogBase::Cancel, KDialogBase::Ok )
+{
+ TQVBox *page = makeVBoxMainWidget();
+
+ groupBox1 = new TQGroupBox( page );
+ groupBox1->setColumnLayout(0, TQt::Vertical );
+ groupBox1->layout()->setSpacing( 6 );
+ groupBox1->layout()->setMargin( 11 );
+ groupBox1Layout = new TQGridLayout( groupBox1->layout() );
+ groupBox1Layout->setAlignment( TQt::AlignTop );
+
+ perAmountEdit = new FractionInput( groupBox1 );
+
+ groupBox1Layout->addWidget( perAmountEdit, 1, 1 );
+
+ weightEdit = new FractionInput( groupBox1 );
+
+ groupBox1Layout->addWidget( weightEdit, 0, 1 );
+
+ weightUnitBox = new UnitComboBox( groupBox1, db, Unit::Mass );
+ weightUnitBox->reload();
+
+ groupBox1Layout->addMultiCellWidget( weightUnitBox, 0, 0, 2, 3 );
+
+ perAmountLabel = new TQLabel( groupBox1, "perAmountLabel" );
+
+ groupBox1Layout->addWidget( perAmountLabel, 1, 0 );
+
+ weightLabel = new TQLabel( groupBox1, "weightLabel" );
+
+ groupBox1Layout->addWidget( weightLabel, 0, 0 );
+
+ perAmountUnitBox = new UnitComboBox( groupBox1, db );
+ perAmountUnitBox->reload();
+
+ groupBox1Layout->addWidget( perAmountUnitBox, 1, 2 );
+
+ prepMethodBox = new PrepMethodComboBox( false, groupBox1, db, i18n("-No Preparation-") );
+ prepMethodBox->reload();
+ groupBox1Layout->addWidget( prepMethodBox, 1, 3 );
+
+ languageChange();
+ clearWState( WState_Polished );
+
+ weightEdit->setFocus();
+}
+
+CreateIngredientWeightDialog::~CreateIngredientWeightDialog()
+{
+ // no need to delete child widgets, TQt does it all for us
+}
+
+void CreateIngredientWeightDialog::languageChange()
+{
+ groupBox1->setTitle( i18n( "New Ingredient Weight" ) );
+ perAmountLabel->setText( i18n( "Per Amount:" ) );
+ weightLabel->setText( i18n( "Weight:" ) );
+}
+
+void CreateIngredientWeightDialog::slotOk()
+{
+ if ( !perAmountEdit->isInputValid() ) {
+ KMessageBox::error( this, i18n( "Amount field contains invalid input." ),
+ i18n( "Invalid input" ) );
+ perAmountEdit->setFocus();
+ perAmountEdit->selectAll();
+ return;
+ }
+ else if ( !weightEdit->isInputValid() ) {
+ KMessageBox::error( this, i18n( "Amount field contains invalid input." ),
+ i18n( "Invalid input" ) );
+ weightEdit->setFocus();
+ weightEdit->selectAll();
+ return;
+ }
+
+ accept();
+}
+
+Weight CreateIngredientWeightDialog::weight() const
+{
+ Weight w;
+ w.perAmount = perAmountEdit->value().toDouble();
+ w.perAmountUnitID = perAmountUnitBox->id( perAmountUnitBox->currentItem() );
+ w.weight = weightEdit->value().toDouble();
+ w.weightUnitID = weightUnitBox->id( weightUnitBox->currentItem() );
+ w.prepMethodID = prepMethodBox->id( prepMethodBox->currentItem() );
+ w.prepMethod = prepMethodBox->currentText();
+
+ return w;
+}
+
+#include "createingredientweightdialog.moc"