Subversion Repositories Scribus

Rev

Rev 6369 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
6368 fschmid 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
*/
7
/***************************************************************************
8
*   Copyright (C) 2006 by Franz Schmid                                   *
9
*   franz.schmid@altmuehlnet.de                                                   *
10
*                                                                         *
11
*   This program is free software; you can redistribute it and/or modify  *
12
*   it under the terms of the GNU General Public License as published by  *
13
*   the Free Software Foundation; either version 2 of the License, or     *
14
*   (at your option) any later version.                                   *
15
*                                                                         *
16
*   This program is distributed in the hope that it will be useful,       *
17
*   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
18
*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
19
*   GNU General Public License for more details.                          *
20
*                                                                         *
21
*   You should have received a copy of the GNU General Public License     *
22
*   along with this program; if not, write to the                         *
23
*   Free Software Foundation, Inc.,                                       *
24
*   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
25
***************************************************************************/
26
 
27
#include "patterndialog.h"
28
#include "patterndialog.moc"
29
#include "customfdialog.h"
30
#include "prefsmanager.h"
31
#include "prefsfile.h"
32
#include "util.h"
33
#include <qpixmap.h>
34
#include <qimage.h>
35
 
36
PatternDialog::PatternDialog(QWidget* parent, QMap<QString, ScPattern> *docPatterns) : patternDialogBase(parent)
37
{
38
        patternView->clear();
39
        for (QMap<QString, ScPattern>::Iterator it = docPatterns->begin(); it != docPatterns->end(); ++it)
40
        {
41
                dialogPatterns.insert(it.key(), it.data());
42
        }
43
        updatePatternList();
44
        buttonRemove->setEnabled(false);
45
        connect(buttonOK, SIGNAL(clicked()), this, SLOT(accept()));
46
        connect(buttonCancel, SIGNAL(clicked()), this, SLOT(reject()));
47
        connect(buttonLoad, SIGNAL(clicked()), this, SLOT(loadPattern()));
48
        connect(buttonRemove, SIGNAL(clicked()), this, SLOT(removePattern()));
49
        connect(patternView, SIGNAL(clicked(QIconViewItem*)), this, SLOT(patternSelected(QIconViewItem*)));
50
}
51
 
52
void PatternDialog::updatePatternList()
53
{
54
        patternView->clear();
55
        for (QMap<QString, ScPattern>::Iterator it = dialogPatterns.begin(); it != dialogPatterns.end(); ++it)
56
        {
57
                QPixmap pm;
58
                if (it.data().getPattern()->width() > it.data().getPattern()->height())
59
                        pm.convertFromImage(it.data().getPattern()->scaleWidth(48));
60
                else
61
                        pm.convertFromImage(it.data().getPattern()->scaleHeight(48));
62
                (void) new QIconViewItem(patternView, it.key(), pm);
63
        }
64
}
65
 
66
void PatternDialog::loadPattern()
67
{
68
        QString fileName;
69
        QString formatD(setupImageFormats());
70
        PrefsContext* dirs = PrefsManager::instance()->prefsFile->getContext("dirs");
71
        QString wdir = dirs->get("patterns", ".");
72
        CustomFDialog dia(this, wdir, tr("Open"), formatD, fdShowPreview | fdExistingFiles);
73
        if (dia.exec() == QDialog::Accepted)
74
                fileName = dia.selectedFile();
75
        else
76
                return;
77
        if (!fileName.isEmpty())
78
        {
79
                PrefsManager::instance()->prefsFile->getContext("dirs")->set("patterns", fileName.left(fileName.findRev("/")));
80
                QFileInfo fi(fileName);
81
                QString patNam = fi.baseName().stripWhiteSpace().simplifyWhiteSpace().replace(" ", "_");
82
                ScPattern pat = ScPattern();
83
                pat.setPattern(fileName);
84
                if (!dialogPatterns.contains(patNam))
85
                {
86
                        dialogPatterns.insert(patNam, pat);
87
                        updatePatternList();
88
                }
89
        }
90
}
91
 
92
void PatternDialog::patternSelected(QIconViewItem* it)
93
{
94
        if (it)
95
                buttonRemove->setEnabled(true);
96
        else
97
        {
98
                buttonRemove->setEnabled(false);
99
                patternView->clearSelection();
100
        }
101
}
102
 
103
void PatternDialog::removePattern()
104
{
105
        QIconViewItem *it = patternView->currentItem();
106
        if (it)
107
        {
108
                dialogPatterns.remove(it->text());
109
                updatePatternList();
110
        }
111
}