Subversion Repositories Scribus

Rev

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

Rev Author Line No. Line
27 Franz 1
#include "lineformats.h"
2
#include "lineformats.moc"
3
#include "multiline.h"
4
#include <qmessagebox.h>
118 Franz 5
#include "customfdialog.h"
6
#include "scribusXml.h"
27 Franz 7
extern QPixmap loadIcon(QString nam);
8
 
9
LineFormate::LineFormate( QWidget* parent, ScribusDoc *doc)
10
    : QDialog( parent, "Formate", true, 0)
11
{
12
    resize( 327, 260 );
13
    setCaption( tr( "Edit Line Styles" ) );
83 Franz 14
        setIcon(loadIcon("AppIcon.png"));
27 Franz 15
                Docu = doc;
16
                TempStyles = doc->MLineStyles;
17
    StilFormateLayout = new QHBoxLayout( this );
18
    StilFormateLayout->setSpacing( 5 );
19
    StilFormateLayout->setMargin( 10 );
20
 
21
    ListBox1 = new QListBox( this, "ListBox1" );
22
    ListBox1->setMinimumSize( QSize( 200, 240 ) );
23
    StilFormateLayout->addWidget( ListBox1 );
24
 
25
    Layout15 = new QVBoxLayout;
26
    Layout15->setSpacing( 6 );
27
    Layout15->setMargin( 0 );
28
 
118 Franz 29
    LoadLS = new QPushButton( this, "LoadF" );
30
    LoadLS->setText( tr( "Append" ) );
31
    Layout15->addWidget( LoadLS );
32
 
27 Franz 33
    NewB = new QPushButton( this, "NewB" );
34
    NewB->setText( tr( "New" ) );
35
    Layout15->addWidget( NewB );
36
 
37
    EditB = new QPushButton( this, "EditB" );
38
    EditB->setText( tr( "Edit" ) );
39
    EditB->setDefault( true );
40
    EditB->setEnabled(false);
41
    Layout15->addWidget( EditB );
42
 
43
    DublicateB = new QPushButton( this, "DublicateB" );
44
    DublicateB->setText( tr( "Duplicate" ) );
45
    DublicateB->setEnabled(false);
46
    Layout15->addWidget( DublicateB );
47
 
48
    DeleteB = new QPushButton( this, "DeleteB" );
49
    DeleteB->setText( tr( "Delete" ) );
50
    DeleteB->setEnabled(false);
51
    Layout15->addWidget( DeleteB );
52
 
53
    SaveB = new QPushButton( this, "SaveB" );
54
    SaveB->setText( tr( "Save" ) );
55
    Layout15->addWidget( SaveB );
56
 
57
    CancelB = new QPushButton( this, "CancelB" );
58
    CancelB->setText( tr( "Cancel" ) );
59
    Layout15->addWidget( CancelB );
60
    QSpacerItem* spacer = new QSpacerItem( 0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding );
61
    Layout15->addItem( spacer );
62
    StilFormateLayout->addLayout( Layout15 );
63
 
64
    // signals and slots connections
65
    connect(CancelB, SIGNAL(clicked()), this, SLOT(reject()));
66
    connect(SaveB, SIGNAL(clicked()), this, SLOT(accept()));
118 Franz 67
    connect(LoadLS, SIGNAL(clicked()), this, SLOT(loadLStyles()));
27 Franz 68
    connect(EditB, SIGNAL(clicked()), this, SLOT(editFormat()));
69
    connect(NewB, SIGNAL(clicked()), this, SLOT(neuesFormat()));
70
    connect(DublicateB, SIGNAL(clicked()), this, SLOT(dupFormat()));
71
    connect(DeleteB, SIGNAL(clicked()), this, SLOT(deleteFormat()));
72
    connect(ListBox1, SIGNAL(highlighted(QListBoxItem*)), this, SLOT(selFormat(QListBoxItem*)));
73
                if (ListBox1->count() > 0)
74
        sFnumber = TempStyles.begin().key();
75
                else
76
                        sFnumber = "";
77
    UpdateFList();
78
}
79
 
80
void LineFormate::selFormat(QListBoxItem *c)
81
{
82
        sFnumber = c->text();
83
        EditB->setEnabled(true);
84
        DublicateB->setEnabled(true);
85
        DeleteB->setEnabled(true);
86
}
87
 
88
void LineFormate::dupFormat()
89
{
90
        multiLine ml;
91
        ml = TempStyles[sFnumber];
115 Franz 92
        MultiLine* dia = new MultiLine(this, Docu, ml, tr("Copy of %1").arg(sFnumber), true, &TempStyles);
27 Franz 93
        if (dia->exec())
94
                {
95
                TempStyles.insert(dia->SName->text(), dia->TempVorl);
96
                sFnumber = dia->SName->text();
97
                }
98
        UpdateFList();
99
}
100
 
101
void LineFormate::neuesFormat()
102
{
103
        struct singleLine sl;
104
        sl.Color = "Black";
105
        sl.Shade = 100;
106
        sl.Dash = SolidLine;
107
        sl.LineEnd = FlatCap;
108
        sl.LineJoin = MiterJoin;
109
        sl.Width = 1.0;
110
        multiLine ml;
33 Franz 111
        ml.push_back(sl);
27 Franz 112
        MultiLine* dia = new MultiLine(this, Docu, ml, tr("New Style"), true, &TempStyles);
113
        if (dia->exec())
114
                {
115
                TempStyles.insert(dia->SName->text(), dia->TempVorl);
116
                sFnumber = dia->SName->text();
117
                }
118
        UpdateFList();
119
}
120
 
121
void LineFormate::editFormat()
122
{
123
        MultiLine* dia = new MultiLine(this, Docu, TempStyles[sFnumber], sFnumber, false, &TempStyles);
124
        if (dia->exec())
125
                TempStyles[sFnumber] = dia->TempVorl;
126
        delete dia;
127
        UpdateFList();
128
}
129
 
130
void LineFormate::deleteFormat()
131
{
132
  int exit=QMessageBox::warning(this,
133
                                                                                                                        tr("Warning"),
134
                                tr("Do you really want do delete this Style?"),
135
                                tr("No"),
136
                                tr("Yes"),
137
                                0, 0, 1);
138
        if (exit == 1)
139
        {
140
                TempStyles.remove(sFnumber);
141
                UpdateFList();
142
                }
143
}
144
 
118 Franz 145
void LineFormate::loadLStyles()
146
{
147
        QString fileName;
148
#ifdef HAVE_LIBZ
149
        CustomFDialog dia(this, tr("Open"), tr("Documents (*.sla *.sla.gz *.scd *.scd.gz);;All Files (*)"));
150
#else
151
        CustomFDialog dia(this, tr("Open"), tr("Documents (*.sla *.scd);;All Files (*)"));
152
#endif
153
        if (dia.exec() == QDialog::Accepted)
154
                fileName = dia.selectedFile();
155
        else
156
                return;
157
  if (!fileName.isEmpty())
158
        {
159
        ScriXmlDoc *ss = new ScriXmlDoc();
160
        if (ss->ReadLStyles(fileName, &TempStyles))
161
                        UpdateFList();
162
                delete ss;
163
        }
164
}
165
 
27 Franz 166
void LineFormate::UpdateFList()
167
{
168
        disconnect(ListBox1, SIGNAL(highlighted(QListBoxItem*)), this, SLOT(selFormat(QListBoxItem*)));
169
        ListBox1->clear();
170
        QMap<QString,multiLine>::Iterator it;
171
        for (it = TempStyles.begin(); it != TempStyles.end(); ++it)
172
                {
173
                ListBox1->insertItem(it.key());
174
                }
175
        if (ListBox1->count() > 0)
176
                ListBox1->setSelected(ListBox1->findItem(sFnumber), true);
80 Franz 177
        bool setter = ListBox1->count() == 0 ? true : false;
178
        if (setter == false)
27 Franz 179
                sFnumber = "";
80 Franz 180
  DublicateB->setEnabled(setter);
181
  EditB->setEnabled(setter);
182
  DeleteB->setEnabled(setter);
27 Franz 183
        connect(ListBox1, SIGNAL(highlighted(QListBoxItem*)), this, SLOT(selFormat(QListBoxItem*)));
184
}