Back to index

scribus-ng  1.3.4.dfsg+svn20071115
insertaframe.cpp
Go to the documentation of this file.
00001 /*
00002 For general Scribus (>=1.3.2) copyright and licensing information please refer
00003 to the COPYING file provided with the program. Following this notice may exist
00004 a copyright and/or license notice that predates the release of Scribus 1.3.2
00005 for which a new license (GPL+exception) is in place.
00006 */
00007 //
00008 //
00009 // Author: Craig Bradney <cbradney@zip.com.au>, (C) 2006
00010 //
00011 // Copyright: See COPYING file that comes with this distribution
00012 //
00013 //
00014 
00015 #include "insertaframe.h"
00016 #include "insertaframe.moc"
00017 
00018 #include "createrange.h"
00019 #include "customfdialog.h"
00020 #include "mspinbox.h"
00021 #include "prefsfile.h"
00022 #include "prefsmanager.h"
00023 #include "scribusdoc.h"
00024 #include "util.h"
00025 #include "scpaths.h"
00026 
00027 #include <qbuttongroup.h>
00028 #include <qlineedit.h>
00029 #include <qpushbutton.h>
00030 #include <qradiobutton.h>
00031 #include <qspinbox.h>
00032 #include <qtextedit.h>
00033 #include <qwidgetstack.h>
00034 
00035 InsertAFrame::InsertAFrame(QWidget* parent, ScribusDoc *doc) :
00036        InsertAFrameBase(parent),
00037        m_Doc(doc)
00038 {
00039        //Hide some unused items for now
00040        radioButtonTable->setShown(false);
00041        radioButtonShape->setShown(false);
00042        radioButtonPolygon->setShown(false);
00043        
00044        placementPagesRangeButton->setPixmap(loadIcon("ellipsis.png"));
00045        
00046        //set tab order
00047        QWidget::setTabOrder(radioButtonCustomPosition, xPosMSpinBox);
00048        QWidget::setTabOrder(xPosMSpinBox, yPosMSpinBox);
00049        QWidget::setTabOrder(radioButtonCustomSize, widthMSpinBox);
00050        QWidget::setTabOrder(widthMSpinBox, heightMSpinBox);
00051        QWidget::setTabOrder(textColumnCountSpinBox, textColumnGapMSpinBox);
00052        
00053        typeButtonGroup->setButton(0);
00054        pagePlacementButtonGroup->setButton(0);
00055        framePositionButtonGroup->setButton(0);
00056        sizeButtonGroup->setButton(0);
00057        slotSelectType(0);
00058        slotSelectPagePlacement(0);
00059        slotSelectPosition(0);
00060        slotSelectSize(0);
00061        
00062        int docUnitIndex = m_Doc->unitIndex();
00063        int decimals = unitGetDecimalsFromIndex(docUnitIndex);
00064        QString unitSuffix(unitGetSuffixFromIndex(docUnitIndex));
00065        xPosMSpinBox->setValues(0.0, 1000.0, decimals, 0.0);
00066        yPosMSpinBox->setValues(0.0, 1000.0, decimals, 0.0);
00067        widthMSpinBox->setValues(0.0, 1000.0, decimals, 0.0);
00068        heightMSpinBox->setValues(0.0, 1000.0, decimals, 0.0);
00069        textColumnGapMSpinBox->setValues(0.0, 1000.0, decimals, 0.0);
00070        xPosMSpinBox->setSuffix(unitSuffix);
00071        yPosMSpinBox->setSuffix(unitSuffix);
00072        widthMSpinBox->setSuffix(unitSuffix);
00073        heightMSpinBox->setSuffix(unitSuffix);
00074        textColumnGapMSpinBox->setSuffix(unitSuffix);
00075 
00076        sourceDocLineEdit->setText("");
00077        connect(typeButtonGroup, SIGNAL(clicked(int)), this, SLOT(slotSelectType(int)));
00078        connect(pagePlacementButtonGroup, SIGNAL(clicked(int)), this, SLOT(slotSelectPagePlacement(int)));
00079        connect(placementPagesRangeButton, SIGNAL(clicked()), this, SLOT(slotCreatePageNumberRange()));
00080        connect(framePositionButtonGroup, SIGNAL(clicked(int)), this, SLOT(slotSelectPosition(int)));
00081        connect(sizeButtonGroup, SIGNAL(clicked(int)), this, SLOT(slotSelectSize(int)));
00082        connect(selectImageFileButton, SIGNAL(clicked()), this, SLOT(locateImageFile()));
00083        connect(selectDocFileButton, SIGNAL(clicked()), this, SLOT(locateDocFile()));
00084 }
00085 
00086 void InsertAFrame::slotSelectType( int id )
00087 {
00088        checkBoxLinkCreatedTextFrames->setEnabled(id==0);
00089        radioButtonImageSize->setShown(id==1);
00090        switch (id)
00091        {
00092               case 0:
00093                      typeTextEdit->setText( tr("<b>Insert a text frame</b><br/>A text frame allows you to enter any text in a defined position with the formatting you choose. You may select a text file on the Options tab if you want to immediately import a document into the frame. Scribus supports a wide variety of importable format from plain text to OpenOffice.org.<br/>Your text may be edited and formatted on the page directly or in the simple Story Editor."));
00094                      optionsWidgetStack->raiseWidget(2);
00095                      break;
00096               case 1:
00097                      typeTextEdit->setText( tr("<b>Insert an image frame</b><br/>An image frame allows you to place an image onto your page. Various image effects may be applied or combined including transparencies, brightness, posterisation that allow retouching or the creation of interesting visual results. Image scaling and shaping is performed with the Properties Palette."));
00098                      optionsWidgetStack->raiseWidget(0);
00099                      break;
00100               case 2:
00101                      typeTextEdit->setText("Insert a table");
00102                      optionsWidgetStack->raiseWidget(1);
00103                      break;
00104               case 3:
00105                      typeTextEdit->setText("Insert a shape");
00106                      optionsWidgetStack->raiseWidget(1);
00107                      break;
00108               case 4:
00109                      typeTextEdit->setText("Insert a polygon");
00110                      optionsWidgetStack->raiseWidget(1);
00111                      break;
00112               case 5:
00113                      typeTextEdit->setText("Insert a line");
00114                      optionsWidgetStack->raiseWidget(1);
00115                      break;
00116               case 6:
00117                      typeTextEdit->setText("Insert a bezier curve");
00118                      optionsWidgetStack->raiseWidget(1);
00119                      break;
00120        }
00121 }
00122 
00123 void InsertAFrame::slotSelectPagePlacement( int id )
00124 {
00125        placementPagesLineEdit->setEnabled(id==1);
00126        placementPagesRangeButton->setEnabled(id==1);
00127        checkBoxLinkCreatedTextFrames->setEnabled(typeButtonGroup->selectedId()==0 && (id!=0));
00128 }
00129 
00130 void InsertAFrame::slotSelectPosition( int id )
00131 {
00132        xPosMSpinBox->setEnabled(id==99);
00133        yPosMSpinBox->setEnabled(id==99);
00134 }
00135 
00136 void InsertAFrame::slotSelectSize( int id )
00137 {
00138        widthMSpinBox->setEnabled(id==99);
00139        heightMSpinBox->setEnabled(id==99);
00140 }
00141 
00142 void InsertAFrame::getNewFrameProperties(InsertAFrameData &iafData)
00143 {
00144        int type=typeButtonGroup->selectedId();
00145        iafData.source="";
00146        switch(type)
00147        {
00148               case 0:
00149                      iafData.frameType=PageItem::TextFrame;
00150                      iafData.source=ScPaths::separatorsToSlashes(sourceDocLineEdit->text());
00151                      break;
00152               case 1:
00153                      iafData.frameType=PageItem::ImageFrame;
00154                      iafData.source=ScPaths::separatorsToSlashes(sourceImageLineEdit->text());
00155                      break;
00156        }
00157        iafData.locationType=pagePlacementButtonGroup->selectedId();
00158        iafData.pageList=placementPagesLineEdit->text();
00159        iafData.positionType=framePositionButtonGroup->selectedId();
00160        iafData.sizeType=sizeButtonGroup->selectedId();
00161        iafData.x=xPosMSpinBox->value();
00162        iafData.y=yPosMSpinBox->value();
00163        iafData.width=widthMSpinBox->value();
00164        iafData.height=heightMSpinBox->value();
00165        iafData.impsetup=m_ImportSetup;
00166        iafData.columnCount=textColumnCountSpinBox->value();
00167        iafData.columnGap=textColumnGapMSpinBox->value();
00168        iafData.linkTextFrames=checkBoxLinkCreatedTextFrames->isChecked();
00169 }
00170 
00171 void InsertAFrame::locateImageFile()
00172 {
00173        QString formatD(setupImageFormats());
00174        QString docDir = ".";
00175        PrefsManager* prefsManager=PrefsManager::instance();
00176        QString prefsDocDir(prefsManager->documentDir());
00177        if (!prefsDocDir.isEmpty())
00178               docDir = prefsManager->prefsFile->getContext("dirs")->get("images", prefsDocDir);
00179        else
00180               docDir = prefsManager->prefsFile->getContext("dirs")->get("images", ".");
00181               
00182        QString fileName("");
00183        CustomFDialog dia(this, docDir, tr("Open"), formatD, fdShowPreview | fdExistingFiles);
00184        if (dia.exec() == QDialog::Accepted)
00185               fileName = dia.selectedFile();
00186        
00187        sourceImageLineEdit->setText(QDir::convertSeparators(fileName));
00188 }
00189 
00190 void InsertAFrame::locateDocFile()
00191 {
00192        m_ImportSetup.runDialog=false;
00193        gtGetText* gt = new gtGetText(m_Doc);
00194        m_ImportSetup=gt->run();
00195        if (m_ImportSetup.runDialog)
00196               sourceDocLineEdit->setText(QDir::convertSeparators(m_ImportSetup.filename));
00197        delete gt;
00198 }
00199 
00200 void InsertAFrame::slotCreatePageNumberRange( )
00201 {
00202        if (m_Doc!=0)
00203        {
00204               CreateRange cr(placementPagesLineEdit->text(), m_Doc->DocPages.count(), this);
00205               if (cr.exec())
00206               {
00207                      CreateRangeData crData;
00208                      cr.getCreateRangeData(crData);
00209                      placementPagesLineEdit->setText(crData.pageRange);
00210                      return;
00211               }
00212        }
00213        placementPagesLineEdit->setText(QString::null);
00214 }