Subversion Repositories Scribus

Rev

Rev 6368 | Rev 6372 | Go to most recent revision | Details | Compare with Previous | 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
 
6369 fschmid 36
PatternDialog::PatternDialog(QWidget* parent, QMap<QString, ScPattern> *docPatterns, ScribusDoc *doc) : patternDialogBase(parent)
6368 fschmid 37
{
6369 fschmid 38
        m_doc = doc;
6368 fschmid 39
        patternView->clear();
40
        for (QMap<QString, ScPattern>::Iterator it = docPatterns->begin(); it != docPatterns->end(); ++it)
41
        {
42
                dialogPatterns.insert(it.key(), it.data());
43
        }
44
        updatePatternList();
45
        buttonRemove->setEnabled(false);
46
        connect(buttonOK, SIGNAL(clicked()), this, SLOT(accept()));
47
        connect(buttonCancel, SIGNAL(clicked()), this, SLOT(reject()));
48
        connect(buttonLoad, SIGNAL(clicked()), this, SLOT(loadPattern()));
49
        connect(buttonRemove, SIGNAL(clicked()), this, SLOT(removePattern()));
50
        connect(patternView, SIGNAL(clicked(QIconViewItem*)), this, SLOT(patternSelected(QIconViewItem*)));
51
}
52
 
53
void PatternDialog::updatePatternList()
54
{
55
        patternView->clear();
56
        for (QMap<QString, ScPattern>::Iterator it = dialogPatterns.begin(); it != dialogPatterns.end(); ++it)
57
        {
58
                QPixmap pm;
59
                if (it.data().getPattern()->width() > it.data().getPattern()->height())
60
                        pm.convertFromImage(it.data().getPattern()->scaleWidth(48));
61
                else
62
                        pm.convertFromImage(it.data().getPattern()->scaleHeight(48));
63
                (void) new QIconViewItem(patternView, it.key(), pm);
64
        }
65
}
66
 
67
void PatternDialog::loadPattern()
68
{
69
        QString fileName;
70
        QString formatD(setupImageFormats());
71
        PrefsContext* dirs = PrefsManager::instance()->prefsFile->getContext("dirs");
72
        QString wdir = dirs->get("patterns", ".");
73
        CustomFDialog dia(this, wdir, tr("Open"), formatD, fdShowPreview | fdExistingFiles);
74
        if (dia.exec() == QDialog::Accepted)
75
                fileName = dia.selectedFile();
76
        else
77
                return;
78
        if (!fileName.isEmpty())
79
        {
80
                PrefsManager::instance()->prefsFile->getContext("dirs")->set("patterns", fileName.left(fileName.findRev("/")));
81
                QFileInfo fi(fileName);
82
                QString patNam = fi.baseName().stripWhiteSpace().simplifyWhiteSpace().replace(" ", "_");
83
                ScPattern pat = ScPattern();
6369 fschmid 84
                pat.setDoc(m_doc);
6368 fschmid 85
                pat.setPattern(fileName);
86
                if (!dialogPatterns.contains(patNam))
87
                {
88
                        dialogPatterns.insert(patNam, pat);
89
                        updatePatternList();
90
                }
91
        }
92
}
93
 
94
void PatternDialog::patternSelected(QIconViewItem* it)
95
{
96
        if (it)
97
                buttonRemove->setEnabled(true);
98
        else
99
        {
100
                buttonRemove->setEnabled(false);
101
                patternView->clearSelection();
102
        }
103
}
104
 
105
void PatternDialog::removePattern()
106
{
107
        QIconViewItem *it = patternView->currentItem();
108
        if (it)
109
        {
110
                dialogPatterns.remove(it->text());
111
                updatePatternList();
112
        }
113
}