Subversion Repositories Scribus

Rev

Rev 19168 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
4430 cbradney 1
/*
2
For general Scribus (>=1.3.2) copyright and licensing information please refer
3
to the COPYING file provided with the program. Following this notice may exist
4
a copyright and/or license notice that predates the release of Scribus 1.3.2
5
for which a new license (GPL+exception) is in place.
6
*/
3 paul 7
#include "newfile.h"
3699 cbradney 8
 
12594 cbradney 9
#include <QFormLayout>
9894 fschmid 10
#include <QGridLayout>
11
#include <QHBoxLayout>
12
#include <QVBoxLayout>
18154 jghali 13
 
14
#include <QDir>
15
#include <QCheckBox>
16
#include <QFileDialog>
9894 fschmid 17
#include <QFrame>
18
#include <QGroupBox>
8501 cbradney 19
#include <QLabel>
18154 jghali 20
#include <QListWidgetItem>
21
#include <QPixmap>
22
#include <QPoint>
23
#include <QPushButton>
24
#include <QSpacerItem>
9894 fschmid 25
#include <QSpinBox>
19180 craig 26
#include <QStandardPaths>
27
#include <QStringList>
9894 fschmid 28
#include <QTabWidget>
29
#include <QToolTip>
3699 cbradney 30
 
18154 jghali 31
#include "scconfig.h"
32
 
33
#include "commonstrings.h"
3699 cbradney 34
#include "fileloader.h"
18154 jghali 35
#include "marginwidget.h"
1542 cbradney 36
#include "pagesize.h"
5781 cbradney 37
#include "scribuscore.h"
2901 fschmid 38
#include "pagelayout.h"
4122 cbradney 39
#include "pagestructs.h"
18154 jghali 40
#include "prefsfile.h"
41
#include "prefsmanager.h"
42
#include "sccombobox.h"
19153 craig 43
#include "filedialogeventcatcher.h"
8602 cbradney 44
#include "scrspinbox.h"
18154 jghali 45
#include "units.h"
10200 cbradney 46
#include "util_icon.h"
401 Franz 47
 
9897 fschmid 48
PageLayoutsWidget::PageLayoutsWidget(QWidget* parent) : QListWidget(parent)
49
{
50
        setDragEnabled(false);
51
        setViewMode(QListView::IconMode);
52
        setFlow(QListView::LeftToRight);
53
        setSortingEnabled(false);
54
        setWrapping(false);
55
        setWordWrap(true);
56
        setAcceptDrops(false);
57
        setDropIndicatorShown(false);
58
        setDragDropMode(QAbstractItemView::NoDragDrop);
59
        setResizeMode(QListView::Adjust);
60
        setSelectionMode(QAbstractItemView::SingleSelection);
61
        setFocusPolicy(Qt::NoFocus);
62
        setIconSize(QSize(32, 32));
63
        clear();
64
        setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding);
65
}
3205 craig 66
 
9897 fschmid 67
void PageLayoutsWidget::arrangeIcons()
68
{
69
        QListWidgetItem* ic;
70
        int startY = 5;
71
        int startX = 5;
72
        setResizeMode(QListView::Fixed);
73
        int maxSizeY = 0;
74
        for (int cc = 0; cc < count(); ++cc)
75
        {
76
                ic = item(cc);
77
                QRect ir = visualItemRect(ic);
78
                setPositionForIndex(QPoint(startX, startY), indexFromItem(ic));
79
                startX += ir.width()+5;
80
                maxSizeY = qMax(maxSizeY, ir.height());
81
        }
82
        maxX = startX;
83
        maxY = maxSizeY+10;
84
}
85
 
86
const QSize PageLayoutsWidget::minimumSizeHint()
87
{
88
        return QSize(maxX, maxY);
89
}
90
 
15417 craig 91
NewDoc::NewDoc( QWidget* parent, const QStringList& recentDocs, bool startUp, QString lang) : QDialog( parent )
3 paul 92
{
13487 cbradney 93
        setObjectName(QString::fromLocal8Bit("NewDocumentWindow"));
9894 fschmid 94
        setModal(true);
2834 cbradney 95
        prefsManager=PrefsManager::instance();
13236 jghali 96
        m_tabSelected = 0;
97
        m_onStartup = startUp;
13876 cbradney 98
        m_unitIndex = prefsManager->appPrefs.docSetupPrefs.docUnitIndex;
13236 jghali 99
        m_unitRatio = unitGetRatioFromIndex(m_unitIndex);
100
        m_unitSuffix = unitGetSuffixFromIndex(m_unitIndex);
13876 cbradney 101
        m_orientation = prefsManager->appPrefs.docSetupPrefs.pageOrientation;
9894 fschmid 102
        setWindowTitle( tr( "New Document" ) );
103
        setWindowIcon(QIcon(loadIcon("AppIcon.png")));
104
        TabbedNewDocLayout = new QVBoxLayout( this );
105
        TabbedNewDocLayout->setMargin(10);
106
        TabbedNewDocLayout->setSpacing(5);
2830 fschmid 107
        if (startUp)
10529 fschmid 108
                tabWidget = new QTabWidget( this );
2830 fschmid 109
        createNewDocPage();
110
        if (startUp)
111
        {
3803 cbradney 112
                tabWidget->addTab(newDocFrame, tr("&New Document"));
13188 fschmid 113
                createNewFromTempPage();
15417 craig 114
                nftGui->setupSettings(lang);
13188 fschmid 115
                tabWidget->addTab(newFromTempFrame, tr("New &from Template"));
2842 fschmid 116
                createOpenDocPage();
3803 cbradney 117
                tabWidget->addTab(openDocFrame, tr("Open &Existing Document"));
5781 cbradney 118
                recentDocList=recentDocs;
5918 cbradney 119
                createRecentDocPage();
120
                tabWidget->addTab(recentDocFrame, tr("Open Recent &Document"));
121
                TabbedNewDocLayout->addWidget(tabWidget);
2830 fschmid 122
        }
123
        else
124
                TabbedNewDocLayout->addWidget(newDocFrame);
125
 
9894 fschmid 126
        Layout1 = new QHBoxLayout;
127
        Layout1->setSpacing( 5 );
2830 fschmid 128
        Layout1->setMargin( 0 );
2833 fschmid 129
        if (startUp)
130
        {
10529 fschmid 131
                startUpDialog = new QCheckBox( tr( "Do not show this dialog again" ), this );
13876 cbradney 132
                startUpDialog->setChecked(!prefsManager->appPrefs.uiPrefs.showStartupDialog);
2833 fschmid 133
                Layout1->addWidget( startUpDialog );
134
        }
9894 fschmid 135
        QSpacerItem* spacer = new QSpacerItem( 2, 2, QSizePolicy::Expanding, QSizePolicy::Minimum );
2830 fschmid 136
        Layout1->addItem( spacer );
10529 fschmid 137
        OKButton = new QPushButton( CommonStrings::tr_OK, this );
2830 fschmid 138
        OKButton->setDefault( true );
139
        Layout1->addWidget( OKButton );
10529 fschmid 140
        CancelB = new QPushButton( CommonStrings::tr_Cancel, this );
2830 fschmid 141
        CancelB->setAutoDefault( false );
142
        Layout1->addWidget( CancelB );
143
        TabbedNewDocLayout->addLayout( Layout1 );
144
        //tooltips
10397 cbradney 145
        pageSizeComboBox->setToolTip( tr( "Document page size, either a standard size or a custom size" ) );
146
        pageOrientationComboBox->setToolTip( tr( "Orientation of the document's pages" ) );
147
        widthSpinBox->setToolTip( tr( "Width of the document's pages, editable if you have chosen a custom page size" ) );
148
        heightSpinBox->setToolTip( tr( "Height of the document's pages, editable if you have chosen a custom page size" ) );
149
        pageCountSpinBox->setToolTip( tr( "Initial number of pages of the document" ) );
150
        unitOfMeasureComboBox->setToolTip( tr( "Default unit of measurement for document editing" ) );
151
        autoTextFrame->setToolTip( tr( "Create text frames automatically when new pages are added" ) );
152
        numberOfCols->setToolTip( tr( "Number of columns to create in automatically created text frames" ) );
153
        Distance->setToolTip( tr( "Distance between automatically created columns" ) );
2830 fschmid 154
 
155
        // signals and slots connections
156
        connect( OKButton, SIGNAL( clicked() ), this, SLOT( ExitOK() ) );
157
        connect( CancelB, SIGNAL( clicked() ), this, SLOT( reject() ) );
13236 jghali 158
        connect(pageSizeComboBox, SIGNAL(activated(const QString &)), this, SLOT(setPageSize(const QString &)));
159
        connect(pageOrientationComboBox, SIGNAL(activated(int)), this, SLOT(setOrientation(int)));
5918 cbradney 160
        connect(unitOfMeasureComboBox, SIGNAL(activated(int)), this, SLOT(setUnit(int)));
13236 jghali 161
        connect(Distance, SIGNAL(valueChanged(double)), this, SLOT(setDistance(double)));
7023 fschmid 162
        connect(autoTextFrame, SIGNAL(clicked()), this, SLOT(handleAutoFrame()));
9894 fschmid 163
        connect(layoutsView, SIGNAL(itemClicked(QListWidgetItem *)), this, SLOT(itemSelected(QListWidgetItem* )));
164
        connect(layoutsView, SIGNAL(itemDoubleClicked(QListWidgetItem *)), this, SLOT(itemSelected(QListWidgetItem* )));
165
        connect(layoutsView, SIGNAL(itemActivated(QListWidgetItem *)), this, SLOT(itemSelected(QListWidgetItem* )));
166
        connect(layoutsView, SIGNAL(itemPressed(QListWidgetItem *)), this, SLOT(itemSelected(QListWidgetItem* )));
2874 subik 167
        if (startUp)
13188 fschmid 168
        {
169
                connect(nftGui, SIGNAL(leaveOK()), this, SLOT(ExitOK()));
9894 fschmid 170
                connect(recentDocListBox, SIGNAL(itemDoubleClicked(QListWidgetItem *)), this, SLOT(recentDocListBox_doubleClicked()));
14452 fschmid 171
                connect(tabWidget, SIGNAL(currentChanged(int)), this, SLOT(adjustTitles(int)));
13188 fschmid 172
        }
2874 subik 173
 
12594 cbradney 174
//      setMinimumSize(minimumSizeHint());
175
//      setMaximumSize(minimumSizeHint());
176
//      resize(minimumSizeHint());
2830 fschmid 177
}
178
 
179
void NewDoc::createNewDocPage()
180
{
9894 fschmid 181
        newDocFrame = new QFrame(this);
7025 fschmid 182
 
9894 fschmid 183
        pageSizeGroupBox = new QGroupBox(newDocFrame );
7552 mrdocs 184
        pageSizeGroupBox->setTitle( tr( "Document Layout" ) );
9894 fschmid 185
        pageSizeGroupBoxLayout = new QGridLayout( pageSizeGroupBox );
186
        pageSizeGroupBoxLayout->setMargin(10);
187
        pageSizeGroupBoxLayout->setSpacing(5);
5918 cbradney 188
        pageSizeGroupBoxLayout->setAlignment( Qt::AlignTop );
7025 fschmid 189
 
9897 fschmid 190
        layoutsView = new PageLayoutsWidget( pageSizeGroupBox );
191
        layoutsView->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum);
8557 subik 192
        for (int pg = 0; pg < prefsManager->appPrefs.pageSets.count(); ++pg)
7025 fschmid 193
        {
9894 fschmid 194
                QListWidgetItem *ic;
7025 fschmid 195
                QString psname=CommonStrings::translatePageSetString(prefsManager->appPrefs.pageSets[pg].Name);
196
                if (pg == 0)
197
                {
9894 fschmid 198
                        ic = new QListWidgetItem( QIcon(loadIcon("32/page-simple.png")), psname, layoutsView );
199
                        ic->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
7025 fschmid 200
                }
201
                else if (pg == 1)
202
                {
9894 fschmid 203
                        ic = new QListWidgetItem( QIcon(loadIcon("32/page-doublesided.png")), psname, layoutsView );
204
                        ic->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
7025 fschmid 205
                }
206
                else if (pg == 2)
207
                {
9894 fschmid 208
                        ic = new QListWidgetItem( QIcon(loadIcon("32/page-3fold.png")), psname, layoutsView );
209
                        ic->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
7025 fschmid 210
                }
211
                else if (pg == 3)
212
                {
9894 fschmid 213
                        ic = new QListWidgetItem( QIcon(loadIcon("32/page-4fold.png")), psname, layoutsView );
214
                        ic->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
7025 fschmid 215
                }
216
                else
217
                {
9894 fschmid 218
                        ic = new QListWidgetItem( QIcon(loadIcon("32/page-simple.png")), psname, layoutsView );
219
                        ic->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
7025 fschmid 220
                }
221
        }
9897 fschmid 222
        layoutsView->arrangeIcons();
9894 fschmid 223
        pageSizeGroupBoxLayout->addWidget( layoutsView, 0, 0, 5, 1 );
9897 fschmid 224
        layoutsView->arrangeIcons();
7230 subik 225
 
226
 
10529 fschmid 227
        TextLabel1 = new QLabel( tr( "&Size:" ), pageSizeGroupBox );
7025 fschmid 228
        pageSizeGroupBoxLayout->addWidget( TextLabel1, 0, 1 );
13876 cbradney 229
        PageSize ps(prefsManager->appPrefs.docSetupPrefs.pageSize);
10529 fschmid 230
        pageSizeComboBox = new QComboBox( pageSizeGroupBox );
15105 cbradney 231
        pageSizeComboBox->addItems(ps.activeSizeTRList());
10529 fschmid 232
        pageSizeComboBox->addItem( CommonStrings::trCustomPageSize );
4555 cbradney 233
        pageSizeComboBox->setEditable(false);
234
        TextLabel1->setBuddy(pageSizeComboBox);
7025 fschmid 235
        pageSizeGroupBoxLayout->addWidget(pageSizeComboBox, 0, 2 );
10529 fschmid 236
        TextLabel2 = new QLabel( tr( "Orie&ntation:" ), pageSizeGroupBox );
7025 fschmid 237
        pageSizeGroupBoxLayout->addWidget( TextLabel2, 1, 1 );
10529 fschmid 238
        pageOrientationComboBox = new QComboBox( pageSizeGroupBox );
239
        pageOrientationComboBox->addItem( tr( "Portrait" ) );
240
        pageOrientationComboBox->addItem( tr( "Landscape" ) );
4555 cbradney 241
        pageOrientationComboBox->setEditable(false);
13876 cbradney 242
        pageOrientationComboBox->setCurrentIndex(prefsManager->appPrefs.docSetupPrefs.pageOrientation);
4555 cbradney 243
        TextLabel2->setBuddy(pageOrientationComboBox);
7025 fschmid 244
        pageSizeGroupBoxLayout->addWidget( pageOrientationComboBox, 1, 2 );
3 paul 245
 
10529 fschmid 246
        TextLabel1_2 = new QLabel( tr( "&Width:" ), pageSizeGroupBox );
7025 fschmid 247
        pageSizeGroupBoxLayout->addWidget(TextLabel1_2, 2, 1 );
13236 jghali 248
        widthSpinBox = new ScrSpinBox( 1, 16777215, pageSizeGroupBox, m_unitIndex );
249
        widthSpinBox->setSuffix(m_unitSuffix);
8602 cbradney 250
        TextLabel1_2->setBuddy(widthSpinBox);
251
        pageSizeGroupBoxLayout->addWidget(widthSpinBox, 2, 2 );
10529 fschmid 252
        TextLabel2_2 = new QLabel( tr( "&Height:" ), pageSizeGroupBox );
7025 fschmid 253
        pageSizeGroupBoxLayout->addWidget(TextLabel2_2, 3, 1 );
13236 jghali 254
        heightSpinBox = new ScrSpinBox( 1, 16777215, pageSizeGroupBox, m_unitIndex );
255
        heightSpinBox->setSuffix(m_unitSuffix);
8602 cbradney 256
        TextLabel2_2->setBuddy(heightSpinBox);
257
        pageSizeGroupBoxLayout->addWidget(heightSpinBox, 3, 2 );
10529 fschmid 258
        layoutLabel1 = new QLabel( pageSizeGroupBox );
7025 fschmid 259
        layoutLabel1->setText( tr( "First Page is:" ) );
260
        pageSizeGroupBoxLayout->addWidget( layoutLabel1, 4, 1 );
10508 cbradney 261
        firstPage = new ScComboBox( pageSizeGroupBox );
7025 fschmid 262
        firstPage->clear();
263
        pageSizeGroupBoxLayout->addWidget( firstPage, 4, 2 );
13876 cbradney 264
        selectItem(prefsManager->appPrefs.docSetupPrefs.pagePositioning);
265
        firstPage->setCurrentIndex(prefsManager->appPrefs.pageSets[prefsManager->appPrefs.docSetupPrefs.pagePositioning].FirstPage);
3 paul 266
 
13876 cbradney 267
        MarginStruct marg(prefsManager->appPrefs.docSetupPrefs.margins);
13236 jghali 268
        marginGroup = new MarginWidget(newDocFrame,  tr( "Margin Guides" ), &marg, m_unitIndex );
13876 cbradney 269
        marginGroup->setPageWidthHeight(prefsManager->appPrefs.docSetupPrefs.pageWidth, prefsManager->appPrefs.docSetupPrefs.pageHeight);
270
        marginGroup->setFacingPages(!(prefsManager->appPrefs.docSetupPrefs.pagePositioning == singlePage));
271
        widthSpinBox->setValue(prefsManager->appPrefs.docSetupPrefs.pageWidth * m_unitRatio);
272
        heightSpinBox->setValue(prefsManager->appPrefs.docSetupPrefs.pageHeight * m_unitRatio);
15105 cbradney 273
        QStringList pageSizes=ps.activeSizeTRList();
10517 cbradney 274
        int sizeIndex=pageSizes.indexOf(ps.nameTR());
7023 fschmid 275
        if (sizeIndex!=-1)
10529 fschmid 276
                pageSizeComboBox->setCurrentIndex(sizeIndex);
7023 fschmid 277
        else
10529 fschmid 278
                pageSizeComboBox->setCurrentIndex(pageSizeComboBox->count()-1);
7023 fschmid 279
        marginGroup->setPageSize(pageSizeComboBox->currentText());
13876 cbradney 280
        setDocLayout(prefsManager->appPrefs.docSetupPrefs.pagePositioning);
281
        setSize(prefsManager->appPrefs.docSetupPrefs.pageSize);
282
        setOrientation(prefsManager->appPrefs.docSetupPrefs.pageOrientation);
283
        marginGroup->setNewBleeds(prefsManager->appPrefs.docSetupPrefs.bleeds);
284
        marginGroup->setMarginPreset(prefsManager->appPrefs.docSetupPrefs.marginPreset);
7023 fschmid 285
 
9894 fschmid 286
        optionsGroupBox = new QGroupBox( newDocFrame );
5918 cbradney 287
        optionsGroupBox->setTitle( tr( "Options" ) );
12594 cbradney 288
        optionsGroupBoxLayout = new QFormLayout( optionsGroupBox );
9894 fschmid 289
        optionsGroupBoxLayout->setSpacing( 5 );
290
        optionsGroupBoxLayout->setMargin( 10 );
5918 cbradney 291
        optionsGroupBoxLayout->setAlignment( Qt::AlignTop );
12664 fschmid 292
        optionsGroupBoxLayout->setFormAlignment(Qt::AlignLeft | Qt::AlignTop);
293
        optionsGroupBoxLayout->setLabelAlignment(Qt::AlignLeft);
10529 fschmid 294
        pageCountLabel = new QLabel( tr( "N&umber of Pages:" ), optionsGroupBox );
7230 subik 295
 
10529 fschmid 296
        pageCountSpinBox = new QSpinBox( optionsGroupBox );
10493 fschmid 297
        pageCountSpinBox->setMaximum( 10000 );
298
        pageCountSpinBox->setMinimum( 1 );
5918 cbradney 299
        pageCountLabel->setBuddy(pageCountSpinBox);
10529 fschmid 300
        unitOfMeasureLabel = new QLabel( tr( "&Default Unit:" ), optionsGroupBox );
301
        unitOfMeasureComboBox = new QComboBox( optionsGroupBox );
302
        unitOfMeasureComboBox->addItems(unitGetTextUnitList());
13236 jghali 303
        unitOfMeasureComboBox->setCurrentIndex(m_unitIndex);
5918 cbradney 304
        unitOfMeasureComboBox->setEditable(false);
305
        unitOfMeasureLabel->setBuddy(unitOfMeasureComboBox);
12594 cbradney 306
        optionsGroupBoxLayout->addRow( pageCountLabel, pageCountSpinBox);
307
        optionsGroupBoxLayout->addRow( unitOfMeasureLabel, unitOfMeasureComboBox );
5918 cbradney 308
 
10529 fschmid 309
        autoTextFrame = new QCheckBox( optionsGroupBox );
7023 fschmid 310
        autoTextFrame->setText( tr( "&Automatic Text Frames" ) );
12594 cbradney 311
        optionsGroupBoxLayout->addRow( autoTextFrame );
10529 fschmid 312
        TextLabel3 = new QLabel( tr( "Colu&mns:" ), optionsGroupBox );
313
        numberOfCols = new QSpinBox( optionsGroupBox );
7230 subik 314
        numberOfCols->setButtonSymbols( QSpinBox::UpDownArrows );
10529 fschmid 315
        numberOfCols->setMinimum( 1 );
7230 subik 316
        numberOfCols->setValue( 1 );
317
        TextLabel3->setBuddy(numberOfCols);
12594 cbradney 318
        optionsGroupBoxLayout->addRow( TextLabel3, numberOfCols );
7230 subik 319
 
10529 fschmid 320
        TextLabel4 = new QLabel( tr( "&Gap:" ), optionsGroupBox );
13236 jghali 321
        Distance = new ScrSpinBox( 0, 1000, optionsGroupBox, m_unitIndex );
322
        Distance->setValue(11 * m_unitRatio);
323
        m_distance = 11;
12594 cbradney 324
        optionsGroupBoxLayout->addRow( TextLabel4, Distance );
340 Franz 325
        TextLabel4->setBuddy(Distance);
7230 subik 326
 
7023 fschmid 327
        TextLabel3->setEnabled(false);
328
        TextLabel4->setEnabled(false);
329
        Distance->setEnabled(false);
330
        numberOfCols->setEnabled(false);
10529 fschmid 331
        startDocSetup = new QCheckBox( optionsGroupBox );
7140 mrdocs 332
        startDocSetup->setText( tr( "Show Document Settings After Creation" ) );
7023 fschmid 333
        startDocSetup->setChecked(false);
12594 cbradney 334
        optionsGroupBoxLayout->addRow( startDocSetup );
9894 fschmid 335
        NewDocLayout = new QGridLayout( newDocFrame );
336
        NewDocLayout->setMargin(10);
337
        NewDocLayout->setSpacing(5);
7025 fschmid 338
        NewDocLayout->addWidget( marginGroup, 1, 0 );
339
        NewDocLayout->addWidget( optionsGroupBox, 1, 1 );
9894 fschmid 340
        NewDocLayout->addWidget( pageSizeGroupBox, 0, 0, 1, 2);
2830 fschmid 341
}
3 paul 342
 
13188 fschmid 343
void NewDoc::createNewFromTempPage()
344
{
345
        newFromTempFrame = new QFrame(this);
346
        verticalLayout = new QVBoxLayout(newFromTempFrame);
347
        nftGui = new nftwidget(newFromTempFrame);
348
        verticalLayout->addWidget(nftGui);
349
}
350
 
2830 fschmid 351
void NewDoc::createOpenDocPage()
352
{
2856 cbradney 353
        PrefsContext* docContext = prefsManager->prefsFile->getContext("docdirs", false);
2830 fschmid 354
        QString docDir = ".";
2871 cbradney 355
        QString prefsDocDir=prefsManager->documentDir();
2877 cbradney 356
        if (!prefsDocDir.isEmpty())
2871 cbradney 357
                docDir = docContext->get("docsopen", prefsDocDir);
2830 fschmid 358
        else
359
                docDir = docContext->get("docsopen", ".");
3644 craig 360
        QString formats(FileLoader::getLoadFilterString());
14061 fschmid 361
//      formats.remove("PDF (*.pdf *.PDF);;");
9894 fschmid 362
        openDocFrame = new QFrame(this);
363
        openDocLayout = new QVBoxLayout(openDocFrame);
364
        openDocLayout->setMargin(5);
365
        openDocLayout->setSpacing(5);
13236 jghali 366
        m_selectedFile = "";
18154 jghali 367
 
10034 fschmid 368
        fileDialog = new QFileDialog(openDocFrame, tr("Open"), docDir, formats);
369
        fileDialog->setFileMode(QFileDialog::ExistingFile);
370
        fileDialog->setAcceptMode(QFileDialog::AcceptOpen);
16235 fschmid 371
        fileDialog->setOption(QFileDialog::DontUseNativeDialog);
14061 fschmid 372
        fileDialog->setNameFilterDetailsVisible(false);
10034 fschmid 373
        fileDialog->setReadOnly(true);
2830 fschmid 374
        fileDialog->setSizeGripEnabled(false);
375
        fileDialog->setModal(false);
10529 fschmid 376
        QList<QPushButton *> b = fileDialog->findChildren<QPushButton *>();
377
        QListIterator<QPushButton *> i(b);
378
        while (i.hasNext())
379
                i.next()->setVisible(false);
9098 fschmid 380
        fileDialog->setWindowFlags(Qt::Widget);
2830 fschmid 381
        openDocLayout->addWidget(fileDialog);
18154 jghali 382
 
19153 craig 383
        FileDialogEventCatcher* keyCatcher = new FileDialogEventCatcher(this);
18154 jghali 384
        QList<QListView *> lv = fileDialog->findChildren<QListView *>();
385
        QListIterator<QListView *> lvi(lv);
386
        while (lvi.hasNext())
387
                lvi.next()->installEventFilter(keyCatcher);
388
        connect(keyCatcher, SIGNAL(escapePressed()), this, SLOT(reject()));
19153 craig 389
        connect(keyCatcher, SIGNAL(dropLocation(QString)), this, SLOT(locationDropped(QString)));
19180 craig 390
        connect(keyCatcher, SIGNAL(desktopPressed()), this, SLOT(gotoDesktopDirectory()));
391
        connect(keyCatcher, SIGNAL(homePressed()), this, SLOT(gotoHomeDirectory()));
392
        connect(keyCatcher, SIGNAL(parentPressed()), this, SLOT(gotoParentDirectory()));
393
        connect(keyCatcher, SIGNAL(enterSelectedPressed()), this, SLOT(gotoSelectedDirectory()));
10034 fschmid 394
        connect(fileDialog, SIGNAL(filesSelected(const QStringList &)), this, SLOT(openFile()));
18933 jghali 395
        connect(fileDialog, SIGNAL(rejected()), this, SLOT(reject()));
3 paul 396
}
397
 
10034 fschmid 398
void NewDoc::openFile()
2966 fschmid 399
{
400
        ExitOK();
401
}
402
 
2833 fschmid 403
void NewDoc::createRecentDocPage()
404
{
9894 fschmid 405
        recentDocFrame = new QFrame(this);
406
        recentDocLayout = new QVBoxLayout(recentDocFrame);
407
        recentDocLayout->setMargin(5);
408
        recentDocLayout->setSpacing(5);
409
        recentDocListBox = new QListWidget(recentDocFrame);
5781 cbradney 410
        recentDocLayout->addWidget(recentDocListBox);
13876 cbradney 411
        uint max = qMin(prefsManager->appPrefs.uiPrefs.recentDocCount, recentDocList.count());
2833 fschmid 412
        for (uint m = 0; m < max; ++m)
16577 craig 413
                recentDocListBox->addItem( QDir::toNativeSeparators(recentDocList[m]) );
16494 craig 414
        if (max>0)
415
                recentDocListBox->setCurrentRow(0);
2833 fschmid 416
}
417
 
8687 cbradney 418
void NewDoc::setWidth(double)
36 Franz 419
{
13236 jghali 420
        m_pageWidth = widthSpinBox->value() / m_unitRatio;
421
        marginGroup->setPageWidth(m_pageWidth);
4555 cbradney 422
        QString psText=pageSizeComboBox->currentText();
6859 cbradney 423
        if (psText!=CommonStrings::trCustomPageSize && psText!=CommonStrings::customPageSize)
10529 fschmid 424
                pageSizeComboBox->setCurrentIndex(pageSizeComboBox->count()-1);
13308 jghali 425
        int newOrientation = (widthSpinBox->value() > heightSpinBox->value()) ? landscapePage : portraitPage;
426
        if (newOrientation != m_orientation)
427
        {
428
                pageOrientationComboBox->blockSignals(true);
429
                pageOrientationComboBox->setCurrentIndex(newOrientation);
430
                pageOrientationComboBox->blockSignals(false);
431
                m_orientation = newOrientation;
432
        }
36 Franz 433
}
434
 
8687 cbradney 435
void NewDoc::setHeight(double)
36 Franz 436
{
13236 jghali 437
        m_pageHeight = heightSpinBox->value() / m_unitRatio;
438
        marginGroup->setPageHeight(m_pageHeight);
4555 cbradney 439
        QString psText=pageSizeComboBox->currentText();
6859 cbradney 440
        if (psText!=CommonStrings::trCustomPageSize && psText!=CommonStrings::customPageSize)
10529 fschmid 441
                pageSizeComboBox->setCurrentIndex(pageSizeComboBox->count()-1);
13308 jghali 442
        int newOrientation = (widthSpinBox->value() > heightSpinBox->value()) ? landscapePage : portraitPage;
443
        if (newOrientation != m_orientation)
444
        {
445
                pageOrientationComboBox->blockSignals(true);
446
                pageOrientationComboBox->setCurrentIndex(newOrientation);
447
                pageOrientationComboBox->blockSignals(false);
448
                m_orientation = newOrientation;
449
        }
36 Franz 450
}
451
 
7025 fschmid 452
void NewDoc::selectItem(uint nr)
453
{
9894 fschmid 454
        disconnect(layoutsView, SIGNAL(itemClicked(QListWidgetItem *)), this, SLOT(itemSelected(QListWidgetItem* )));
455
        disconnect(layoutsView, SIGNAL(itemDoubleClicked(QListWidgetItem *)), this, SLOT(itemSelected(QListWidgetItem* )));
456
        disconnect(layoutsView, SIGNAL(itemActivated(QListWidgetItem *)), this, SLOT(itemSelected(QListWidgetItem* )));
457
        disconnect(layoutsView, SIGNAL(itemPressed(QListWidgetItem *)), this, SLOT(itemSelected(QListWidgetItem* )));
458
        if (nr > 0)
7025 fschmid 459
        {
9894 fschmid 460
                firstPage->setEnabled(true);
461
                firstPage->clear();
462
                QStringList::Iterator pNames;
463
                for(pNames = prefsManager->appPrefs.pageSets[nr].pageNames.begin(); pNames != prefsManager->appPrefs.pageSets[nr].pageNames.end(); ++pNames )
7025 fschmid 464
                {
10529 fschmid 465
                        firstPage->addItem(CommonStrings::translatePageSetLocString((*pNames)));
7025 fschmid 466
                }
467
        }
9894 fschmid 468
        else
469
        {
470
                firstPage->clear();
10529 fschmid 471
                firstPage->addItem(" ");
9894 fschmid 472
                firstPage->setEnabled(false);
473
        }
474
        layoutsView->setCurrentRow(nr);
475
        layoutsView->item(nr)->setSelected(true);
476
        connect(layoutsView, SIGNAL(itemClicked(QListWidgetItem *)), this, SLOT(itemSelected(QListWidgetItem* )));
477
        connect(layoutsView, SIGNAL(itemDoubleClicked(QListWidgetItem *)), this, SLOT(itemSelected(QListWidgetItem* )));
478
        connect(layoutsView, SIGNAL(itemActivated(QListWidgetItem *)), this, SLOT(itemSelected(QListWidgetItem* )));
479
        connect(layoutsView, SIGNAL(itemPressed(QListWidgetItem *)), this, SLOT(itemSelected(QListWidgetItem* )));
7025 fschmid 480
}
481
 
9894 fschmid 482
void NewDoc::itemSelected(QListWidgetItem* ic)
7025 fschmid 483
{
484
        if (ic == 0)
485
                return;
9894 fschmid 486
        selectItem(layoutsView->row(ic));
13236 jghali 487
        setDocLayout(layoutsView->row(ic));
7025 fschmid 488
}
489
 
7023 fschmid 490
void NewDoc::handleAutoFrame()
491
{
492
        if (autoTextFrame->isChecked())
493
        {
494
                TextLabel3->setEnabled(true);
495
                TextLabel4->setEnabled(true);
496
                Distance->setEnabled(true);
497
                numberOfCols->setEnabled(true);
498
        }
499
        else
500
        {
501
                TextLabel3->setEnabled(false);
502
                TextLabel4->setEnabled(false);
503
                Distance->setEnabled(false);
504
                numberOfCols->setEnabled(false);
505
        }
506
}
507
 
13236 jghali 508
void NewDoc::setDistance(double)
3 paul 509
{
13236 jghali 510
        m_distance = Distance->value() / m_unitRatio;
3 paul 511
}
512
 
806 cbradney 513
void NewDoc::setUnit(int newUnitIndex)
3 paul 514
{
8687 cbradney 515
        disconnect(widthSpinBox, SIGNAL(valueChanged(double)), this, SLOT(setWidth(double)));
516
        disconnect(heightSpinBox, SIGNAL(valueChanged(double)), this, SLOT(setHeight(double)));
8602 cbradney 517
        widthSpinBox->setNewUnit(newUnitIndex);
518
        heightSpinBox->setNewUnit(newUnitIndex);
519
        Distance->setNewUnit(newUnitIndex);
13236 jghali 520
        m_unitRatio = unitGetRatioFromIndex(newUnitIndex);
521
        m_unitIndex = newUnitIndex;
17465 fschmid 522
        widthSpinBox->setValue(m_pageWidth * m_unitRatio);
523
        heightSpinBox->setValue(m_pageHeight * m_unitRatio);
8602 cbradney 524
/*     
525
double oldUnitRatio = unitRatio;
2141 cbradney 526
        double val, oldB, oldBM, oldH, oldHM;
7021 fschmid 527
        int decimals;
8602 cbradney 528
        widthSpinBox->getValues(&oldB, &oldBM, &decimals, &val);
806 cbradney 529
        oldB /= oldUnitRatio;
530
        oldBM /= oldUnitRatio;
8602 cbradney 531
        heightSpinBox->getValues(&oldH, &oldHM, &decimals, &val);
806 cbradney 532
        oldH /= oldUnitRatio;
533
        oldHM /= oldUnitRatio;
401 Franz 534
 
2874 subik 535
        unitIndex = newUnitIndex;
2141 cbradney 536
        unitRatio = unitGetRatioFromIndex(newUnitIndex);
537
        decimals = unitGetDecimalsFromIndex(newUnitIndex);
4555 cbradney 538
        if (pageOrientationComboBox->currentItem() == portraitPage)
534 fschmid 539
        {
8602 cbradney 540
                widthSpinBox->setValues(oldB * unitRatio, oldBM * unitRatio, decimals, pageWidth * unitRatio);
541
                heightSpinBox->setValues(oldH * unitRatio, oldHM * unitRatio, decimals, pageHeight * unitRatio);
534 fschmid 542
        }
543
        else
544
        {
8602 cbradney 545
                widthSpinBox->setValues(oldB * unitRatio, oldBM * unitRatio, decimals, pageHeight * unitRatio);
546
                heightSpinBox->setValues(oldH * unitRatio, oldHM * unitRatio, decimals, pageWidth * unitRatio);
534 fschmid 547
        }
806 cbradney 548
        Distance->setValue(Dist * unitRatio);
2769 fschmid 549
        unitSuffix = unitGetSuffixFromIndex(newUnitIndex);
8602 cbradney 550
        widthSpinBox->setSuffix(unitSuffix);
551
        heightSpinBox->setSuffix(unitSuffix);
806 cbradney 552
        Distance->setSuffix( unitSuffix );
8602 cbradney 553
*/
13236 jghali 554
        marginGroup->setNewUnit(m_unitIndex);
555
        marginGroup->setPageHeight(m_pageHeight);
556
        marginGroup->setPageWidth(m_pageWidth);
8687 cbradney 557
        connect(widthSpinBox, SIGNAL(valueChanged(double)), this, SLOT(setWidth(double)));
558
        connect(heightSpinBox, SIGNAL(valueChanged(double)), this, SLOT(setHeight(double)));
245 Franz 559
 
3 paul 560
}
561
 
562
void NewDoc::ExitOK()
563
{
13236 jghali 564
        m_pageWidth = widthSpinBox->value() / m_unitRatio;
565
        m_pageHeight = heightSpinBox->value() / m_unitRatio;
566
        m_bleedBottom = marginGroup->bottomBleed();
567
        m_bleedTop = marginGroup->topBleed();
568
        m_bleedLeft = marginGroup->leftBleed();
569
        m_bleedRight = marginGroup->rightBleed();
570
        if (m_onStartup)
10034 fschmid 571
        {
13236 jghali 572
                m_tabSelected = tabWidget->currentIndex();
13380 subik 573
                if (m_tabSelected == NewDoc::NewFromTemplateTab) // new doc from template
13236 jghali 574
                {
13477 jghali 575
                        if (nftGui->currentDocumentTemplate)
576
                        {
577
                                m_selectedFile = QDir::fromNativeSeparators(nftGui->currentDocumentTemplate->file);
578
                                m_selectedFile = QDir::cleanPath(m_selectedFile);
579
                        }
13236 jghali 580
                }
13380 subik 581
                else if (m_tabSelected == NewDoc::OpenExistingTab) // open existing doc
13236 jghali 582
                {
583
                        QStringList files = fileDialog->selectedFiles();
584
                        if (files.count() != 0)
585
                                m_selectedFile = QDir::fromNativeSeparators(files[0]);
586
                }
13380 subik 587
                else if (m_tabSelected == NewDoc::OpenRecentTab) // open recent doc
13236 jghali 588
                {
589
                        if (recentDocListBox->currentItem() != NULL)
590
                        {
591
                                QString fileName(recentDocListBox->currentItem()->text());
592
                                if (!fileName.isEmpty())
593
                                        m_selectedFile = QDir::fromNativeSeparators(fileName);
594
                        }
595
                }
10034 fschmid 596
        }
2833 fschmid 597
        else
13380 subik 598
                m_tabSelected = NewDoc::NewDocumentTab;
2830 fschmid 599
        accept();
3 paul 600
}
601
 
13236 jghali 602
void NewDoc::setOrientation(int ori)
3 paul 603
{
8687 cbradney 604
        disconnect(widthSpinBox, SIGNAL(valueChanged(double)), this, SLOT(setWidth(double)));
605
        disconnect(heightSpinBox, SIGNAL(valueChanged(double)), this, SLOT(setHeight(double)));
13236 jghali 606
        if (ori != m_orientation)
167 Franz 607
        {
13307 jghali 608
                double w = widthSpinBox->value(), h = heightSpinBox->value();
609
                widthSpinBox->setValue((ori == portraitPage) ? qMin(w, h) : qMax(w, h));
610
                heightSpinBox->setValue((ori == portraitPage) ? qMax(w, h) : qMin(w, h));
167 Franz 611
        }
401 Franz 612
        // #869 pv - defined constants added + code repeat (check w/h)
13236 jghali 613
        (ori == portraitPage) ? m_orientation = portraitPage : m_orientation = landscapePage;
6859 cbradney 614
        if (pageSizeComboBox->currentText() == CommonStrings::trCustomPageSize)
2798 fschmid 615
        {
8602 cbradney 616
                if (widthSpinBox->value() > heightSpinBox->value())
10529 fschmid 617
                        pageOrientationComboBox->setCurrentIndex(landscapePage);
2798 fschmid 618
                else
10529 fschmid 619
                        pageOrientationComboBox->setCurrentIndex(portraitPage);
2798 fschmid 620
        }
401 Franz 621
        // end of #869
13236 jghali 622
        marginGroup->setPageHeight(m_pageHeight);
623
        marginGroup->setPageWidth(m_pageWidth);
8687 cbradney 624
        connect(widthSpinBox, SIGNAL(valueChanged(double)), this, SLOT(setWidth(double)));
625
        connect(heightSpinBox, SIGNAL(valueChanged(double)), this, SLOT(setHeight(double)));
3 paul 626
}
627
 
13236 jghali 628
void NewDoc::setPageSize(const QString &size)
3 paul 629
{
6859 cbradney 630
        if (size == CommonStrings::trCustomPageSize)
1542 cbradney 631
                setSize(size);
3 paul 632
        else
332 Franz 633
        {
1542 cbradney 634
                setSize(size);
13236 jghali 635
                setOrientation(pageOrientationComboBox->currentIndex());
332 Franz 636
        }
5786 cbradney 637
        marginGroup->setPageSize(size);
3 paul 638
}
639
 
1542 cbradney 640
void NewDoc::setSize(QString gr)
3 paul 641
{
13236 jghali 642
        m_pageWidth = widthSpinBox->value() / m_unitRatio;
643
        m_pageHeight = heightSpinBox->value() / m_unitRatio;
2874 subik 644
 
8687 cbradney 645
        disconnect(widthSpinBox, SIGNAL(valueChanged(double)), this, SLOT(setWidth(double)));
646
        disconnect(heightSpinBox, SIGNAL(valueChanged(double)), this, SLOT(setHeight(double)));
6859 cbradney 647
        if (gr==CommonStrings::trCustomPageSize || gr==CommonStrings::customPageSize)
167 Franz 648
        {
8701 fschmid 649
                widthSpinBox->setEnabled(true);
650
                heightSpinBox->setEnabled(true);
167 Franz 651
        }
173 Franz 652
        else
653
        {
1542 cbradney 654
                PageSize *ps2=new PageSize(gr);
10529 fschmid 655
                if (pageOrientationComboBox->currentIndex() == portraitPage)
401 Franz 656
                {
13236 jghali 657
                        m_pageWidth = ps2->width();
658
                        m_pageHeight = ps2->height();
401 Franz 659
                } else {
13236 jghali 660
                        m_pageWidth = ps2->height();
661
                        m_pageHeight = ps2->width();
401 Franz 662
                }
3449 cbradney 663
                delete ps2;
173 Franz 664
        }
13236 jghali 665
        widthSpinBox->setValue(m_pageWidth * m_unitRatio);
666
        heightSpinBox->setValue(m_pageHeight * m_unitRatio);
667
        marginGroup->setPageHeight(m_pageHeight);
668
        marginGroup->setPageWidth(m_pageWidth);
8687 cbradney 669
        connect(widthSpinBox, SIGNAL(valueChanged(double)), this, SLOT(setWidth(double)));
670
        connect(heightSpinBox, SIGNAL(valueChanged(double)), this, SLOT(setHeight(double)));
3 paul 671
}
672
 
13236 jghali 673
void NewDoc::setDocLayout(int layout)
3 paul 674
{
14839 cbradney 675
        marginGroup->setFacingPages(layout != singlePage);
13236 jghali 676
        m_choosenLayout = layout;
677
        firstPage->setCurrentIndex(prefsManager->appPrefs.pageSets[m_choosenLayout].FirstPage);
3 paul 678
}
1542 cbradney 679
 
9894 fschmid 680
void NewDoc::recentDocListBox_doubleClicked()
2874 subik 681
{
4026 craig 682
        /* Yep. There is nothing to solve. ScribusMainWindow handles all
2874 subik 683
        openings etc. It's Franz's programming style ;) */
684
        ExitOK();
685
}
14452 fschmid 686
 
687
void NewDoc::adjustTitles(int tab)
688
{
689
        if (tab == 0)
690
                setWindowTitle( tr( "New Document" ) );
691
        else if (tab == 1)
692
                setWindowTitle( tr("New from Template"));
693
        else if (tab == 2)
694
                setWindowTitle( tr("Open Existing Document"));
695
        else if (tab == 3)
696
                setWindowTitle( tr("Open Recent Document"));
697
        else
698
                setWindowTitle( tr( "New Document" ) );
699
}
19153 craig 700
 
19168 craig 701
void NewDoc::locationDropped(QString fileUrl)
19153 craig 702
{
19168 craig 703
        QFileInfo fi(fileUrl);
704
        if (fi.isDir())
705
                fileDialog->setDirectory(fi.absoluteFilePath());
706
        else
707
        {
708
                fileDialog->setDirectory(fi.absolutePath());
709
                fileDialog->selectFile(fi.fileName());
710
        }
19153 craig 711
}
712
 
19180 craig 713
void NewDoc::gotoParentDirectory()
714
{
715
        QDir d(fileDialog->directory());
716
        d.cdUp();
717
        fileDialog->setDirectory(d);
718
}
719
 
720
 
721
void NewDoc::gotoSelectedDirectory()
722
{
723
        QStringList s(fileDialog->selectedFiles());
724
        if (s.count()>0)
725
        {
726
                QFileInfo fi(s.first());
727
                qDebug()<<s.first()<<fi.absoluteFilePath();
728
                if (fi.isDir())
729
                        fileDialog->setDirectory(fi.absoluteFilePath());
730
        }
731
}
732
 
733
void NewDoc::gotoDesktopDirectory()
734
{
735
        QString dp=QStandardPaths::writableLocation(QStandardPaths::DesktopLocation);
736
        QFileInfo fi(dp);
737
        if (fi.exists())
738
                fileDialog->setDirectory(dp);
739
}
740
 
741
 
742
void NewDoc::gotoHomeDirectory()
743
{
744
        QString dp=QStandardPaths::writableLocation(QStandardPaths::HomeLocation);
745
        QFileInfo fi(dp);
746
        if (fi.exists())
747
                fileDialog->setDirectory(dp);
748
}