00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include "insertaframe.h"
00016
00017 #include "ui/createrange.h"
00018 #include "customfdialog.h"
00019 #include "scrspinbox.h"
00020 #include "prefsfile.h"
00021 #include "prefsmanager.h"
00022 #include "scribusdoc.h"
00023 #include "units.h"
00024 #include "util.h"
00025 #include "util_formats.h"
00026 #include "util_icon.h"
00027 #include "scpaths.h"
00028
00029 #include <QGroupBox>
00030 #include <QIcon>
00031 #include <QLineEdit>
00032 #include <QPushButton>
00033 #include <QRadioButton>
00034 #include <QSpinBox>
00035 #include <QTextEdit>
00036 #include <QStackedWidget>
00037
00038 InsertAFrame::InsertAFrame(QWidget* parent, ScribusDoc *doc) :
00039 QDialog(parent),
00040 m_Doc(doc)
00041 {
00042 setupUi(this);
00043
00044
00045
00046
00047
00048 placementPagesRangeButton->setIcon(QIcon(loadIcon("ellipsis.png")));
00049
00050
00051 QWidget::setTabOrder(radioButtonCustomPosition, xPosScrSpinBox);
00052 QWidget::setTabOrder(xPosScrSpinBox, yPosScrSpinBox);
00053 QWidget::setTabOrder(radioButtonCustomSize, widthScrSpinBox);
00054 QWidget::setTabOrder(widthScrSpinBox, heightScrSpinBox);
00055 QWidget::setTabOrder(textColumnCountSpinBox, textColumnGapScrSpinBox);
00056
00057 typeButtonGroup = new QButtonGroup(typeGroupBox);
00058 typeButtonGroup->addButton(radioButtonTextFrame,0);
00059 typeButtonGroup->addButton(radioButtonImageFrame,1);
00060 pagePlacementButtonGroup = new QButtonGroup(pagePlacementGroupBox);
00061 pagePlacementButtonGroup->addButton(radioButtonCurrentPage,0);
00062 pagePlacementButtonGroup->addButton(radioButtonAllPages,1);
00063 pagePlacementButtonGroup->addButton(radioButtonRangeOfPages,2);
00064 framePositionButtonGroup = new QButtonGroup(framePositionGroupBox);
00065 framePositionButtonGroup->addButton(radioButtonTopLeftOfMargins,0);
00066 framePositionButtonGroup->addButton(radioButtonTopLeftOfPage,1);
00067 framePositionButtonGroup->addButton(radioButtonTopLeftOfBleed,2);
00068 framePositionButtonGroup->addButton(radioButtonCustomPosition,3);
00069 sizeButtonGroup = new QButtonGroup(sizeGroupBox);
00070 sizeButtonGroup->addButton(radioButtonPageMarginSize,0);
00071 sizeButtonGroup->addButton(radioButtonPageSize,1);
00072 sizeButtonGroup->addButton(radioButtonBleedSize,2);
00073 sizeButtonGroup->addButton(radioButtonImageSize,3);
00074 sizeButtonGroup->addButton(radioButtonCustomSize,4);
00075 radioButtonTextFrame->setChecked(true);
00076 radioButtonCurrentPage->setChecked(true);
00077 radioButtonTopLeftOfMargins->setChecked(true);
00078 radioButtonPageMarginSize->setChecked(true);
00079 slotSelectType(0);
00080 slotSelectPagePlacement(0);
00081 slotSelectPosition(0);
00082 slotSelectSize(0);
00083
00084 int docUnitIndex = m_Doc->unitIndex();
00085 int decimals = unitGetPrecisionFromIndex(docUnitIndex);
00086 QString unitSuffix(unitGetSuffixFromIndex(docUnitIndex));
00087 xPosScrSpinBox->setValues(0.0, 1000.0, decimals, 0.0);
00088 yPosScrSpinBox->setValues(0.0, 1000.0, decimals, 0.0);
00089 widthScrSpinBox->setValues(0.0, 1000.0, decimals, 0.0);
00090 heightScrSpinBox->setValues(0.0, 1000.0, decimals, 0.0);
00091 textColumnGapScrSpinBox->setValues(0.0, 1000.0, decimals, 0.0);
00092 xPosScrSpinBox->setSuffix(unitSuffix);
00093 yPosScrSpinBox->setSuffix(unitSuffix);
00094 widthScrSpinBox->setSuffix(unitSuffix);
00095 heightScrSpinBox->setSuffix(unitSuffix);
00096 textColumnGapScrSpinBox->setSuffix(unitSuffix);
00097
00098 sourceDocLineEdit->setText("");
00099 connect(typeButtonGroup, SIGNAL(buttonClicked(int)), this, SLOT(slotSelectType(int)));
00100 connect(pagePlacementButtonGroup, SIGNAL(buttonClicked(int)), this, SLOT(slotSelectPagePlacement(int)));
00101 connect(placementPagesRangeButton, SIGNAL(clicked()), this, SLOT(slotCreatePageNumberRange()));
00102 connect(framePositionButtonGroup, SIGNAL(buttonClicked(int)), this, SLOT(slotSelectPosition(int)));
00103 connect(sizeButtonGroup, SIGNAL(buttonClicked(int)), this, SLOT(slotSelectSize(int)));
00104 connect(selectImageFileButton, SIGNAL(clicked()), this, SLOT(locateImageFile()));
00105 connect(selectDocFileButton, SIGNAL(clicked()), this, SLOT(locateDocFile()));
00106 }
00107
00108 void InsertAFrame::slotSelectType( int id )
00109 {
00110 checkBoxLinkCreatedTextFrames->setEnabled(id==0);
00111 radioButtonImageSize->setShown(id==1);
00112 switch (id)
00113 {
00114 case 0:
00115 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."));
00116 optionsStackedWidget->setCurrentIndex(0);
00117 break;
00118 case 1:
00119 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."));
00120 optionsStackedWidget->setCurrentIndex(1);
00121 break;
00122 case 2:
00123 typeTextEdit->setText("Insert a table");
00124 optionsStackedWidget->setCurrentIndex(2);
00125 break;
00126 case 3:
00127 typeTextEdit->setText("Insert a shape");
00128 optionsStackedWidget->setCurrentIndex(2);
00129 break;
00130 case 4:
00131 typeTextEdit->setText("Insert a polygon");
00132 optionsStackedWidget->setCurrentIndex(2);
00133 break;
00134 case 5:
00135 typeTextEdit->setText("Insert a line");
00136 optionsStackedWidget->setCurrentIndex(2);
00137 break;
00138 case 6:
00139 typeTextEdit->setText("Insert a bezier curve");
00140 optionsStackedWidget->setCurrentIndex(2);
00141 break;
00142 }
00143 }
00144
00145 void InsertAFrame::slotSelectPagePlacement( int id )
00146 {
00147 placementPagesLineEdit->setEnabled(id==2);
00148 placementPagesRangeButton->setEnabled(id==2);
00149 checkBoxLinkCreatedTextFrames->setEnabled(typeButtonGroup->checkedId()==0 && (id!=0));
00150 }
00151
00152 void InsertAFrame::slotSelectPosition( int id )
00153 {
00154 xPosScrSpinBox->setEnabled(id==3);
00155 yPosScrSpinBox->setEnabled(id==3);
00156 }
00157
00158 void InsertAFrame::slotSelectSize( int id )
00159 {
00160 widthScrSpinBox->setEnabled(id==4);
00161 heightScrSpinBox->setEnabled(id==4);
00162 }
00163
00164 void InsertAFrame::getNewFrameProperties(InsertAFrameData &iafData)
00165 {
00166 int type=typeButtonGroup->checkedId();
00167 iafData.source="";
00168 switch(type)
00169 {
00170 case 0:
00171 iafData.frameType=PageItem::TextFrame;
00172 iafData.source=ScPaths::separatorsToSlashes(sourceDocLineEdit->text());
00173 break;
00174 case 1:
00175 iafData.frameType=PageItem::ImageFrame;
00176 iafData.source=ScPaths::separatorsToSlashes(sourceImageLineEdit->text());
00177 break;
00178 }
00179 iafData.locationType=pagePlacementButtonGroup->checkedId();
00180 iafData.pageList=placementPagesLineEdit->text();
00181 iafData.positionType=framePositionButtonGroup->checkedId();
00182 iafData.sizeType=sizeButtonGroup->checkedId();
00183 iafData.x=xPosScrSpinBox->value();
00184 iafData.y=yPosScrSpinBox->value();
00185 iafData.width=widthScrSpinBox->value();
00186 iafData.height=heightScrSpinBox->value();
00187 iafData.impsetup=m_ImportSetup;
00188 iafData.columnCount=textColumnCountSpinBox->value();
00189 iafData.columnGap=textColumnGapScrSpinBox->value();
00190 iafData.linkTextFrames=checkBoxLinkCreatedTextFrames->isChecked();
00191 }
00192
00193 void InsertAFrame::locateImageFile()
00194 {
00195 QString formatD(FormatsManager::instance()->fileDialogFormatList(FormatsManager::IMAGESIMGFRAME));
00196 QString docDir = ".";
00197 PrefsManager* prefsManager=PrefsManager::instance();
00198 QString prefsDocDir(prefsManager->documentDir());
00199 if (!prefsDocDir.isEmpty())
00200 docDir = prefsManager->prefsFile->getContext("dirs")->get("images", prefsDocDir);
00201 else
00202 docDir = prefsManager->prefsFile->getContext("dirs")->get("images", ".");
00203
00204 QString fileName("");
00205 CustomFDialog dia(this, docDir, tr("Open"), formatD, fdShowPreview | fdExistingFiles);
00206 if (dia.exec() == QDialog::Accepted)
00207 fileName = dia.selectedFile();
00208
00209 sourceImageLineEdit->setText(QDir::convertSeparators(fileName));
00210 }
00211
00212 void InsertAFrame::locateDocFile()
00213 {
00214 m_ImportSetup.runDialog=false;
00215 gtGetText* gt = new gtGetText(m_Doc);
00216 m_ImportSetup=gt->run();
00217 if (m_ImportSetup.runDialog)
00218 sourceDocLineEdit->setText(QDir::convertSeparators(m_ImportSetup.filename));
00219 delete gt;
00220 }
00221
00222 void InsertAFrame::slotCreatePageNumberRange( )
00223 {
00224 if (m_Doc!=0)
00225 {
00226 CreateRange cr(placementPagesLineEdit->text(), m_Doc->DocPages.count(), this);
00227 if (cr.exec())
00228 {
00229 CreateRangeData crData;
00230 cr.getCreateRangeData(crData);
00231 placementPagesLineEdit->setText(crData.pageRange);
00232 return;
00233 }
00234 }
00235 placementPagesLineEdit->setText(QString::null);
00236 }