1 /*************************************************************************** 2 templtopositiondialogbase.cpp - base dialog template to doc 3 ------------------- 4 begin : Mar 2007 5 copyright : (C) 2007 Klaas Freitag 6 email : freitag@kde.org 7 ***************************************************************************/ 8 9 /*************************************************************************** 10 * * 11 * This program is free software; you can redistribute it and/or modify * 12 * it under the terms of the GNU General Public License as published by * 13 * the Free Software Foundation; either version 2 of the License, or * 14 * (at your option) any later version. * 15 * * 16 ***************************************************************************/ 17 18 #include <QComboBox> 19 20 #include <QDialog> 21 #include <QDebug> 22 #include <QDialogButtonBox> 23 #include <QPushButton> 24 #include <QVBoxLayout> 25 26 #include <klocalizedstring.h> 27 28 #include "templtopositiondialogbase.h" 29 #include "docposition.h" 30 TemplToPositionDialogBase(QWidget * w)31TemplToPositionDialogBase::TemplToPositionDialogBase( QWidget *w ) 32 : QDialog( w ) 33 { 34 setObjectName( "TEMPL_DIALOG" ); 35 setWindowTitle( i18n("Create Item from Template" ) ); 36 setModal( true ); 37 } 38 ~TemplToPositionDialogBase()39TemplToPositionDialogBase::~TemplToPositionDialogBase() 40 { 41 42 } 43 setPositionList(DocPositionList list,int intendedPos)44void TemplToPositionDialogBase::setPositionList( DocPositionList list, int intendedPos ) 45 { 46 if ( ! getPositionCombo() ) { 47 qCritical() << "Can not get a ptr to the position combo" << endl; 48 return; 49 } 50 QStringList strList; 51 strList << i18n( "the Header of the Document as first item" ); 52 DocPositionListIterator it( list ); 53 while( it.hasNext() ) { 54 DocPosition *dp = static_cast<DocPosition*>( it.next() ); 55 QString h = QString( "%1. %2" ).arg( list.posNumber( dp ) ).arg( dp->text() ); 56 if ( h.length() > 50 ) { 57 h = h.left( 50 ); 58 h += i18n( "..." ); 59 } 60 strList.append( h ); 61 } 62 63 getPositionCombo()->insertItems( -1, strList ); 64 getPositionCombo()->setCurrentIndex( intendedPos ); 65 } 66 insertAfterPosition()67int TemplToPositionDialogBase::insertAfterPosition() 68 { 69 int itemPos = getPositionCombo()->currentIndex(); 70 // qDebug () << "Current item selected: " << itemPos << endl; 71 72 return itemPos; 73 } 74 75