Subversion Repositories Scribus

Rev

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