1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
|
/*
For general Scribus (>=1.3.2) copyright and licensing information please refer
to the COPYING file provided with the program. Following this notice may exist
a copyright and/or license notice that predates the release of Scribus 1.3.2
for which a new license (GPL+exception) is in place.
*/
//
//
// Author: Craig Bradney <cbradney@zip.com.au>, (C) 2006
//
// Copyright: See COPYING file that comes with this distribution
//
//
#include "insertaframe.h"
#include "ui/createrange.h"
#include "customfdialog.h"
#include "scrspinbox.h"
#include "pageitem.h"
#include "prefsfile.h"
#include "prefsmanager.h"
#include "scribusdoc.h"
#include "units.h"
#include "util.h"
#include "util_formats.h"
#include "util_icon.h"
#include "scpaths.h"
#include <QCheckBox>
#include <QGroupBox>
#include <QIcon>
#include <QLineEdit>
#include <QPushButton>
#include <QRadioButton>
#include <QSpinBox>
#include <QStringList>
#include <QTextEdit>
#include <QStackedWidget>
InsertAFrame::InsertAFrame(QWidget* parent, ScribusDoc *doc) :
QDialog(parent),
m_Doc(doc)
{
setupUi(this);
//Hide some unused items for now
// radioButtonTable->setShown(false);
// radioButtonShape->setShown(false);
// radioButtonPolygon->setShown(false);
placementPagesRangeButton->setIcon(QIcon(loadIcon("ellipsis.png")));
//set tab order
QWidget::setTabOrder(radioButtonCustomPosition, xPosScrSpinBox);
QWidget::setTabOrder(xPosScrSpinBox, yPosScrSpinBox);
QWidget::setTabOrder(radioButtonCustomSize, widthScrSpinBox);
QWidget::setTabOrder(widthScrSpinBox, heightScrSpinBox);
QWidget::setTabOrder(textColumnCountSpinBox, textColumnGapScrSpinBox);
typeButtonGroup = new QButtonGroup(typeGroupBox);
typeButtonGroup->addButton(radioButtonTextFrame,0);
typeButtonGroup->addButton(radioButtonImageFrame,1);
pagePlacementButtonGroup = new QButtonGroup(pagePlacementGroupBox);
pagePlacementButtonGroup->addButton(radioButtonCurrentPage,0);
pagePlacementButtonGroup->addButton(radioButtonAllPages,1);
pagePlacementButtonGroup->addButton(radioButtonRangeOfPages,2);
framePositionButtonGroup = new QButtonGroup(framePositionGroupBox);
framePositionButtonGroup->addButton(radioButtonTopLeftOfMargins,0);
framePositionButtonGroup->addButton(radioButtonTopLeftOfPage,1);
framePositionButtonGroup->addButton(radioButtonTopLeftOfBleed,2);
framePositionButtonGroup->addButton(radioButtonCustomPosition,3);
sizeButtonGroup = new QButtonGroup(sizeGroupBox);
sizeButtonGroup->addButton(radioButtonPageMarginSize,0);
sizeButtonGroup->addButton(radioButtonPageSize,1);
sizeButtonGroup->addButton(radioButtonBleedSize,2);
sizeButtonGroup->addButton(radioButtonImageSize,3);
sizeButtonGroup->addButton(radioButtonCustomSize,4);
radioButtonTextFrame->setChecked(true);
radioButtonCurrentPage->setChecked(true);
radioButtonTopLeftOfMargins->setChecked(true);
radioButtonPageMarginSize->setChecked(true);
slotSelectType(0);
slotSelectPagePlacement(0);
slotSelectPosition(0);
slotSelectSize(0);
int docUnitIndex = m_Doc ? m_Doc->unitIndex() : SC_PT;
int decimals = unitGetPrecisionFromIndex(docUnitIndex);
QString unitSuffix(unitGetSuffixFromIndex(docUnitIndex));
xPosScrSpinBox->setNewUnit(docUnitIndex);
yPosScrSpinBox->setNewUnit(docUnitIndex);
widthScrSpinBox->setNewUnit(docUnitIndex);
heightScrSpinBox->setNewUnit(docUnitIndex);
xPosScrSpinBox->setValues(0.0, 1000.0, decimals, 0.0);
yPosScrSpinBox->setValues(0.0, 1000.0, decimals, 0.0);
widthScrSpinBox->setValues(0.0, 1000.0, decimals, 0.0);
heightScrSpinBox->setValues(0.0, 1000.0, decimals, 0.0);
textColumnGapScrSpinBox->setValues(0.0, 1000.0, decimals, 0.0);
xPosScrSpinBox->setSuffix(unitSuffix);
yPosScrSpinBox->setSuffix(unitSuffix);
widthScrSpinBox->setSuffix(unitSuffix);
heightScrSpinBox->setSuffix(unitSuffix);
textColumnGapScrSpinBox->setSuffix(unitSuffix);
sourceDocLineEdit->setText("");
if (m_Doc!=0)
{
pageItemMap=m_Doc->getDocItemNames(PageItem::TextFrame);
comboBoxLinkToExistingFrameName->addItems(pageItemMap.values());
}
if (comboBoxLinkToExistingFrameName->count()==0)
checkBoxLinkToExistingFrame->setEnabled(false);
connect(typeButtonGroup, SIGNAL(buttonClicked(int)), this, SLOT(slotSelectType(int)));
connect(pagePlacementButtonGroup, SIGNAL(buttonClicked(int)), this, SLOT(slotSelectPagePlacement(int)));
connect(placementPagesRangeButton, SIGNAL(clicked()), this, SLOT(slotCreatePageNumberRange()));
connect(framePositionButtonGroup, SIGNAL(buttonClicked(int)), this, SLOT(slotSelectPosition(int)));
connect(sizeButtonGroup, SIGNAL(buttonClicked(int)), this, SLOT(slotSelectSize(int)));
connect(selectImageFileButton, SIGNAL(clicked()), this, SLOT(locateImageFile()));
connect(selectDocFileButton, SIGNAL(clicked()), this, SLOT(locateDocFile()));
connect(checkBoxLinkToExistingFrame, SIGNAL(stateChanged(int)), this, SLOT(slotLinkToExistingFrame(int)));
}
void InsertAFrame::slotSelectType( int id )
{
checkBoxLinkCreatedTextFrames->setEnabled(id==0);
radioButtonImageSize->setShown(id==1);
switch (id)
{
case 0:
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 formats from plain text to OpenOffice.org.<br/>Your text may be edited and formatted on the page directly or in the Story Editor."));
optionsStackedWidget->setCurrentIndex(0);
break;
case 1:
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, and posterisation that allow retouching or the creation of interesting visual results. Image scaling and shaping is performed with the Properties Palette."));
optionsStackedWidget->setCurrentIndex(1);
break;
case 2:
typeTextEdit->setText("Insert a table");
optionsStackedWidget->setCurrentIndex(2);
break;
case 3:
typeTextEdit->setText("Insert a shape");
optionsStackedWidget->setCurrentIndex(2);
break;
case 4:
typeTextEdit->setText("Insert a polygon");
optionsStackedWidget->setCurrentIndex(2);
break;
case 5:
typeTextEdit->setText("Insert a line");
optionsStackedWidget->setCurrentIndex(2);
break;
case 6:
typeTextEdit->setText("Insert a bezier curve");
optionsStackedWidget->setCurrentIndex(2);
break;
}
}
void InsertAFrame::slotSelectPagePlacement( int id )
{
placementPagesLineEdit->setEnabled(id==2);
placementPagesRangeButton->setEnabled(id==2);
checkBoxLinkCreatedTextFrames->setEnabled(typeButtonGroup->checkedId()==0 && (id!=0));
}
void InsertAFrame::slotSelectPosition( int id )
{
xPosScrSpinBox->setEnabled(id==3);
yPosScrSpinBox->setEnabled(id==3);
}
void InsertAFrame::slotSelectSize( int id )
{
widthScrSpinBox->setEnabled(id==4);
heightScrSpinBox->setEnabled(id==4);
}
void InsertAFrame::getNewFrameProperties(InsertAFrameData &iafData)
{
int type=typeButtonGroup->checkedId();
iafData.source="";
switch(type)
{
case 0:
iafData.frameType=PageItem::TextFrame;
iafData.source=QDir::fromNativeSeparators(sourceDocLineEdit->text());
break;
case 1:
iafData.frameType=PageItem::ImageFrame;
iafData.source=QDir::fromNativeSeparators(sourceImageLineEdit->text());
break;
}
iafData.locationType=pagePlacementButtonGroup->checkedId();
iafData.pageList=placementPagesLineEdit->text();
iafData.positionType=framePositionButtonGroup->checkedId();
iafData.sizeType=sizeButtonGroup->checkedId();
int docUnitIndex = m_Doc->unitIndex();
double unitRatio = unitGetRatioFromIndex(docUnitIndex);
iafData.x=xPosScrSpinBox->value() / unitRatio;
iafData.y=yPosScrSpinBox->value() / unitRatio;
iafData.width=widthScrSpinBox->value() / unitRatio;
iafData.height=heightScrSpinBox->value() / unitRatio;
iafData.impsetup=m_ImportSetup;
iafData.columnCount=textColumnCountSpinBox->value();
iafData.columnGap=textColumnGapScrSpinBox->value();
iafData.linkTextFrames=checkBoxLinkCreatedTextFrames->isChecked();
iafData.linkToExistingFrame=checkBoxLinkToExistingFrame->isChecked();
iafData.linkToExistingFramePtr=NULL;
if (comboBoxLinkToExistingFrameName->count()!=0)
{
QMapIterator<PageItem*, QString> i(pageItemMap);
while (i.hasNext())
{
i.next();
if (i.value()==comboBoxLinkToExistingFrameName->currentText())
iafData.linkToExistingFramePtr=i.key();
}
}
}
void InsertAFrame::locateImageFile()
{
QString formatD(FormatsManager::instance()->fileDialogFormatList(FormatsManager::IMAGESIMGFRAME));
QString docDir = ".";
PrefsManager* prefsManager=PrefsManager::instance();
QString prefsDocDir(prefsManager->documentDir());
if (!prefsDocDir.isEmpty())
docDir = prefsManager->prefsFile->getContext("dirs")->get("images", prefsDocDir);
else
docDir = prefsManager->prefsFile->getContext("dirs")->get("images", ".");
QString fileName("");
CustomFDialog dia(this, docDir, tr("Open"), formatD, fdShowPreview | fdExistingFiles);
if (dia.exec() == QDialog::Accepted)
fileName = dia.selectedFile();
sourceImageLineEdit->setText(QDir::toNativeSeparators(fileName));
}
void InsertAFrame::locateDocFile()
{
m_ImportSetup.runDialog=false;
gtGetText* gt = new gtGetText(m_Doc);
m_ImportSetup=gt->run();
if (m_ImportSetup.runDialog)
sourceDocLineEdit->setText(QDir::toNativeSeparators(m_ImportSetup.filename));
delete gt;
}
void InsertAFrame::slotCreatePageNumberRange( )
{
if (m_Doc!=0)
{
CreateRange cr(placementPagesLineEdit->text(), m_Doc->DocPages.count(), this);
if (cr.exec())
{
CreateRangeData crData;
cr.getCreateRangeData(crData);
placementPagesLineEdit->setText(crData.pageRange);
return;
}
}
placementPagesLineEdit->setText(QString::null);
}
void InsertAFrame::slotLinkToExistingFrame(int state)
{
comboBoxLinkToExistingFrameName->setEnabled(state==Qt::Checked);
sourceDocLineEdit->setEnabled(state==Qt::Unchecked);
selectDocFileButton->setEnabled(state==Qt::Unchecked);
}
|