Subversion Repositories Scribus

Rev

Rev 7666 | Rev 7702 | 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
*/
3 paul 7
/****************************************************************************
8
**
9
**
10
** Created: Son Jun 2 11:23:14 2002
11
**      by:  Franz Schmid
12
**
13
**
14
****************************************************************************/
766 cbradney 15
#include <qpushbutton.h>
5583 fschmid 16
#include <qtoolbutton.h>
766 cbradney 17
#include <qlayout.h>
18
#include <qtooltip.h>
19
#include <qpixmap.h>
20
#include <qcheckbox.h>
21
#include <qheader.h>
22
#include <qvaluelist.h>
2190 cbradney 23
#include <qtooltip.h>
2937 cbradney 24
#include <qcheckbox.h>
5373 fschmid 25
#include <qspinbox.h>
26
#include <qlabel.h>
5572 fschmid 27
#include <qcolordialog.h>
766 cbradney 28
 
5887 fschmid 29
#include "dynamictip.h"
3953 cbradney 30
#include "scmessagebox.h"
5375 fschmid 31
#include "sccombobox.h"
766 cbradney 32
#include "scribus.h"
33
 
3 paul 34
#include "layers.h"
35
#include "layers.moc"
5471 fschmid 36
#ifdef HAVE_CAIRO
37
#include <cairo.h>
38
#endif
3 paul 39
 
40
extern QPixmap loadIcon(QString nam);
41
 
6293 fschmid 42
LayerLabel::LayerLabel(QTable *parent) : QTableItem (parent, QTableItem::OnTyping)
43
{
44
}
356 Franz 45
 
6293 fschmid 46
void LayerLabel::paint(QPainter * p, const QColorGroup &cg, const QRect &cr, bool selected)
47
{
48
        p->fillRect( 0, 0, cr.width(), cr.height(), selected ? cg.brush( QColorGroup::Highlight ) : cg.brush( QColorGroup::Base ) );
49
        int w = cr.width();
50
        int h = cr.height();
51
        int x = 0;
52
        if ( selected )
53
                p->setPen( cg.highlightedText() );
54
        else
55
                p->setPen( cg.text() );
56
        QString txt = text();
57
        QString ellipsis("...");
58
        QString elided;
59
        QFontMetrics fontMetrics(table()->font());
60
        int ellipsisWidth = fontMetrics.width(ellipsis) + 4;
61
        int length = txt.length();
62
        int i = 0;
63
        if (fontMetrics.width(txt) > w)
64
        {
65
                int offset = 0;
66
                while (i < length && fontMetrics.width(elided + txt.at(offset)) + ellipsisWidth < w)
67
                {
68
                        elided.append(txt.at(offset));
69
                        offset = ++i;
70
                }
71
                if (elided.isEmpty())
72
                        elided = txt.left(1);
73
                elided.append(ellipsis);
74
        }
75
        else
76
                elided = txt;
77
        p->drawText( x + 2, 0, w - x - 4, h, alignment(), elided );
78
}
3205 craig 79
 
356 Franz 80
LayerTable::LayerTable(QWidget* parent) : QTable(parent)
1166 fschmid 81
{
82
}
356 Franz 83
 
359 Franz 84
void LayerTable::endEdit ( int row, int col, bool accept, bool replace )
85
{
362 Franz 86
        QTable::EditMode ed = editMode();
7510 fschmid 87
        if ((row < 0) || (col < 0))
88
        {
89
                QTable::endEdit(row, col, accept, replace);
90
                return;
91
        }
4482 fschmid 92
        QString oldCont = text(row, col);
359 Franz 93
        QTable::endEdit(row, col, accept, replace);
4482 fschmid 94
        QString newCont = item(row, col)->text();
95
        bool realAccept = true;
96
        int b = numRows();
97
        for (int a = 0; a < b; ++a)
98
        {
99
                if (a != row)
100
                {
5572 fschmid 101
                        if (newCont == text(a, 6))
4482 fschmid 102
                                realAccept = false;
103
                }
104
        }
105
        if (newCont.isEmpty())
106
                realAccept = false;
107
        if (realAccept)
108
        {
109
                if (ed != QTable::NotEditing)
110
                        emit updtName(row);
111
        }
112
        else
4483 fschmid 113
        {
4482 fschmid 114
                setText(row, col, oldCont);
4483 fschmid 115
                emit updtName(row);
116
        }
359 Franz 117
}
118
 
1448 cbradney 119
LayerPalette::LayerPalette(QWidget* parent)
5781 cbradney 120
                : ScrPaletteBase( parent, "Layers", false, 0 ),
121
                m_Doc(0)
3 paul 122
{
5660 fschmid 123
        LayerPaletteLayout = new QVBoxLayout( this, 1, 2, "LayerPaletteLayout");
3 paul 124
 
5660 fschmid 125
        layout1 = new QHBoxLayout( 0, 0, 2, "layout1");
5375 fschmid 126
        textLabel1 = new QLabel( this, "textLabel1" );
127
        layout1->addWidget( textLabel1 );
128
        blendMode = new ScComboBox( false, this, "blendMode" );
129
        layout1->addWidget( blendMode );
5373 fschmid 130
        textLabel2 = new QLabel( this, "textLabel2" );
131
        textLabel2->setText( tr( "Opacity:" ) );
132
        layout1->addWidget( textLabel2 );
133
        opacitySpinBox = new QSpinBox( this, "opacitySpinBox" );
134
        opacitySpinBox->setMinValue(0);
135
        opacitySpinBox->setMaxValue(100);
136
        opacitySpinBox->setLineStep(10);
137
        opacitySpinBox->setSuffix( tr(" %"));
138
        opacitySpinBox->setFocusPolicy(QWidget::ClickFocus);
139
        layout1->addWidget( opacitySpinBox );
140
        LayerPaletteLayout->addLayout( layout1 );
141
#ifndef HAVE_CAIRO
5375 fschmid 142
        blendMode->hide();
143
        textLabel1->hide();
5373 fschmid 144
        textLabel2->hide();
145
        opacitySpinBox->hide();
7199 fschmid 146
/*
5471 fschmid 147
#else
5601 fschmid 148
#if CAIRO_VERSION < CAIRO_VERSION_ENCODE(1, 1, 8)
5471 fschmid 149
        blendMode->hide();
150
        textLabel1->hide();
5373 fschmid 151
#endif
5697 fschmid 152
#if CAIRO_VERSION < CAIRO_VERSION_ENCODE(1, 1, 6)
153
        opacitySpinBox->hide();
154
        textLabel2->hide();
5471 fschmid 155
#endif
7199 fschmid 156
*/
5697 fschmid 157
#endif
5373 fschmid 158
 
356 Franz 159
        Table = new LayerTable( this );
160
        Table->setNumRows( 0 );
5572 fschmid 161
        Table->setNumCols( 7 );
1166 fschmid 162
        QHeader *header = Table->horizontalHeader();
5572 fschmid 163
        header->setLabel(0, "");
164
        header->setLabel(1, loadIcon("16/show-object.png"), "");
165
        header->setLabel(2, loadIcon("16/document-print.png"), "");
166
        header->setLabel(3, loadIcon("16/lock.png"), "");
167
        header->setLabel(4, loadIcon("16/layer-flow-around.png"), "");
168
        header->setLabel(5, loadIcon("layer-outline.png"), "");
1166 fschmid 169
        Table->setColumnReadOnly(0, true);
170
        Table->setColumnReadOnly(1, true);
4832 fschmid 171
        Table->setColumnReadOnly(2, true);
5359 fschmid 172
        Table->setColumnReadOnly(3, true);
5572 fschmid 173
        Table->setColumnReadOnly(4, true);
174
        Table->setColumnReadOnly(5, true);
1166 fschmid 175
        Table->setColumnWidth(0, 24);
176
        Table->setColumnWidth(1, 24);
4832 fschmid 177
        Table->setColumnWidth(2, 24);
5359 fschmid 178
        Table->setColumnWidth(3, 24);
5572 fschmid 179
        Table->setColumnWidth(4, 24);
180
        Table->setColumnWidth(5, 24);
5583 fschmid 181
        header->setResizeEnabled(false, 0);
182
        header->setResizeEnabled(false, 1);
183
        header->setResizeEnabled(false, 2);
184
        header->setResizeEnabled(false, 3);
185
        header->setResizeEnabled(false, 4);
186
        header->setResizeEnabled(false, 5);
187
        header->setResizeEnabled(true, 6);
5887 fschmid 188
        dynTip = new DynamicTip(header);
161 Franz 189
        Table->setRowMovingEnabled(false);
190
        Table->setSorting(false);
356 Franz 191
        Table->setSelectionMode( QTable::SingleRow );
192
        Table->setFocusStyle( QTable::FollowStyle );
161 Franz 193
        Header = Table->verticalHeader();
194
        Header->setMovingEnabled(false);
195
        Header->setResizeEnabled(false);
5637 fschmid 196
        Table->setLeftMargin(0);
197
        Header->hide();
356 Franz 198
        LayerPaletteLayout->addWidget( Table );
3 paul 199
 
356 Franz 200
        Layout1 = new QHBoxLayout( 0, 0, 0, "Layout1");
201
        QSpacerItem* spacer = new QSpacerItem( 0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum );
202
        Layout1->addItem( spacer );
3 paul 203
 
2937 cbradney 204
        newLayerButton = new QPushButton( this, "newLayerButton" );
205
        newLayerButton->setMinimumSize( QSize( 50, 24 ) );
206
        newLayerButton->setMaximumSize( QSize( 50, 24 ) );
207
        newLayerButton->setText( "" );
208
        newLayerButton->setPixmap(loadIcon("Newlayer.png"));
209
        Layout1->addWidget( newLayerButton );
7694 subik 210
 
6290 fschmid 211
        duplicateLayerButton = new QPushButton( this, "duplicateLayerButton" );
212
        duplicateLayerButton->setMinimumSize( QSize( 50, 24 ) );
213
        duplicateLayerButton->setMaximumSize( QSize( 50, 24 ) );
214
        duplicateLayerButton->setText( "" );
215
        duplicateLayerButton->setPixmap(loadIcon("editcopy.png"));
216
        Layout1->addWidget( duplicateLayerButton );
3 paul 217
 
2937 cbradney 218
        deleteLayerButton = new QPushButton( this, "deleteLayerButton" );
219
        deleteLayerButton->setMinimumSize( QSize( 50, 24 ) );
220
        deleteLayerButton->setMaximumSize( QSize( 50, 24 ) );
221
        deleteLayerButton->setText( "" );
222
        deleteLayerButton->setPixmap(loadIcon("Deletelayer.png"));
223
        Layout1->addWidget( deleteLayerButton );
3 paul 224
 
2937 cbradney 225
        raiseLayerButton = new QPushButton( this, "raiseLayerButton" );
226
        raiseLayerButton->setMinimumSize( QSize( 50, 24 ) );
227
        raiseLayerButton->setMaximumSize( QSize( 50, 24 ) );
228
        raiseLayerButton->setText( "" );
7694 subik 229
//      raiseLayerButton->setPixmap(loadIcon("Raiselayer.png"));
230
        raiseLayerButton->setPixmap(loadIcon("16/go-up.png"));
2937 cbradney 231
        Layout1->addWidget( raiseLayerButton );
3 paul 232
 
2937 cbradney 233
        lowerLayerButton = new QPushButton( this, "lowerLayerButton" );
234
        lowerLayerButton->setMinimumSize( QSize( 50, 24 ) );
235
        lowerLayerButton->setMaximumSize( QSize( 50, 24 ) );
236
        lowerLayerButton->setText( "" );
7694 subik 237
//      lowerLayerButton->setPixmap(loadIcon("Lowerlayer.png"));
238
        lowerLayerButton->setPixmap(loadIcon("16/go-down.png"));
2937 cbradney 239
        Layout1->addWidget( lowerLayerButton );
3 paul 240
 
356 Franz 241
        LayerPaletteLayout->addLayout( Layout1 );
161 Franz 242
        ClearInhalt();
2190 cbradney 243
        languageChange();
7694 subik 244
 
2937 cbradney 245
        connect(newLayerButton, SIGNAL(clicked()), this, SLOT(addLayer()));
6290 fschmid 246
        connect(duplicateLayerButton, SIGNAL(clicked()), this, SLOT(dupLayer()));
2937 cbradney 247
        connect(deleteLayerButton, SIGNAL(clicked()), this, SLOT(removeLayer()));
248
        connect(raiseLayerButton, SIGNAL(clicked()), this, SLOT(upLayer()));
249
        connect(lowerLayerButton, SIGNAL(clicked()), this, SLOT(downLayer()));
359 Franz 250
        connect(Table, SIGNAL(updtName(int)), this, SLOT(updateName(int)));
5373 fschmid 251
        connect(opacitySpinBox, SIGNAL(valueChanged(int)), this, SLOT(changeOpacity()));
5375 fschmid 252
        connect(blendMode, SIGNAL(activated(int)), this, SLOT(changeBlendMode(int)));
1697 tsoots 253
 
3 paul 254
}
1448 cbradney 255
 
359 Franz 256
void LayerPalette::updateName(int r)
257
{
5572 fschmid 258
        changeName(r, 6);
5781 cbradney 259
        m_Doc->scMW()->changeLayer(m_Doc->activeLayer());
359 Franz 260
}
261
 
3 paul 262
void LayerPalette::ClearInhalt()
263
{
5375 fschmid 264
        disconnect(blendMode, SIGNAL(activated(int)), this, SLOT(changeBlendMode(int)));
5373 fschmid 265
        disconnect(opacitySpinBox, SIGNAL(valueChanged(int)), this, SLOT(changeOpacity()));
3 paul 266
        disconnect(Table, SIGNAL(currentChanged(int, int)), this, SLOT(setActiveLayer(int)));
286 Franz 267
        int b = Table->numRows();
268
        for (int a = 0; a < b; ++a)
272 Franz 269
                Table->removeRow(0);
2937 cbradney 270
        flagsPrintable.clear();
271
        flagsVisible.clear();
5359 fschmid 272
        flagsFlow.clear();
5572 fschmid 273
        flagsOutline.clear();
274
        flagsMarker.clear();
2937 cbradney 275
        newLayerButton->setEnabled(false);
276
        deleteLayerButton->setEnabled(false);
277
        raiseLayerButton->setEnabled(false);
278
        lowerLayerButton->setEnabled(false);
3 paul 279
}
280
 
5781 cbradney 281
void LayerPalette::setDoc(ScribusDoc* doc)
3 paul 282
{
5781 cbradney 283
        m_Doc=doc;
5375 fschmid 284
        disconnect(blendMode, SIGNAL(activated(int)), this, SLOT(changeBlendMode(int)));
5373 fschmid 285
        disconnect(opacitySpinBox, SIGNAL(valueChanged(int)), this, SLOT(changeOpacity()));
106 Franz 286
        disconnect(Table, SIGNAL(currentChanged(int, int)), this, SLOT(setActiveLayer(int)));
5781 cbradney 287
        if (!m_Doc)
288
        {
289
                layers=0;
290
                newLayerButton->setEnabled(false);
6290 fschmid 291
                duplicateLayerButton->setEnabled(false);
5781 cbradney 292
                deleteLayerButton->setEnabled(false);
293
                raiseLayerButton->setEnabled(false);
294
                lowerLayerButton->setEnabled(false);
295
 
296
                markActiveLayer(0);
297
        }
298
        layers=&m_Doc->Layers;
299
        rebuildList();
300
 
301
        markActiveLayer(m_Doc->activeLayer());
2937 cbradney 302
        newLayerButton->setEnabled(true);
6290 fschmid 303
        duplicateLayerButton->setEnabled(true);
2937 cbradney 304
        deleteLayerButton->setEnabled(true);
305
        raiseLayerButton->setEnabled(true);
306
        lowerLayerButton->setEnabled(true);
3 paul 307
        connect(Table, SIGNAL(currentChanged(int, int)), this, SLOT(setActiveLayer(int)));
5373 fschmid 308
        connect(opacitySpinBox, SIGNAL(valueChanged(int)), this, SLOT(changeOpacity()));
5375 fschmid 309
        connect(blendMode, SIGNAL(activated(int)), this, SLOT(changeBlendMode(int)));
3 paul 310
}
311
 
312
void LayerPalette::rebuildList()
313
{
5375 fschmid 314
        disconnect(blendMode, SIGNAL(activated(int)), this, SLOT(changeBlendMode(int)));
5373 fschmid 315
        disconnect(opacitySpinBox, SIGNAL(valueChanged(int)), this, SLOT(changeOpacity()));
3 paul 316
        disconnect(Table, SIGNAL(currentChanged(int, int)), this, SLOT(setActiveLayer(int)));
2937 cbradney 317
        flagsPrintable.clear();
318
        flagsVisible.clear();
5359 fschmid 319
        flagsFlow.clear();
5572 fschmid 320
        flagsOutline.clear();
321
        flagsMarker.clear();
3 paul 322
        QString tmp;
323
        QValueList<Layer>::iterator it;
5781 cbradney 324
        int layerCount=m_Doc->layerCount();
2937 cbradney 325
        Table->setNumRows(layerCount);
153 Franz 326
        for (it = layers->begin(); it != layers->end(); ++it)
161 Franz 327
        {
2937 cbradney 328
                int layerNumber=(*it).LNr;
329
                //TODO once "layers" is not set anymore, need to get layer number differently
5781 cbradney 330
                int layerLevel=m_Doc->layerLevelFromNumber(layerNumber);
2937 cbradney 331
                int row=layerCount-layerLevel-1;
5583 fschmid 332
                QToolButton *pb = new QToolButton(this, tmp.setNum(layerLevel));
333
                pb->setAutoRaise(true);
5572 fschmid 334
                pb->setText( "" );
5583 fschmid 335
                QPixmap pm(20,15);
5781 cbradney 336
                pm.fill(m_Doc->layerMarker(layerNumber));
5583 fschmid 337
                QIconSet ic;
338
                ic.setPixmap(pm, QIconSet::Small, QIconSet::Normal);
339
                ic.setPixmap(pm, QIconSet::Small, QIconSet::Active);
340
                pb->setIconSet(ic);
5572 fschmid 341
                Table->setCellWidget(row, 0, pb);
342
                flagsMarker.append(pb);
343
                connect(pb, SIGNAL(clicked()), this, SLOT(markLayer()));
344
                QCheckBox *cp2 = new QCheckBox(this, tmp.setNum(layerLevel));
5781 cbradney 345
                cp2->setChecked(m_Doc->layerVisible(layerNumber));
5572 fschmid 346
                flagsVisible.append(cp2);
347
                connect(cp2, SIGNAL(clicked()), this, SLOT(visibleLayer()));
348
                Table->setCellWidget(row, 1, cp2);
2937 cbradney 349
                QCheckBox *cp = new QCheckBox(this, tmp.setNum(layerLevel));
5781 cbradney 350
                cp->setChecked(m_Doc->layerPrintable(layerNumber));
5572 fschmid 351
                Table->setCellWidget(row, 2, cp);
2937 cbradney 352
                flagsPrintable.append(cp);
356 Franz 353
                connect(cp, SIGNAL(clicked()), this, SLOT(printLayer()));
4832 fschmid 354
                QCheckBox *cp3 = new QCheckBox(this, tmp.setNum(layerLevel));
5781 cbradney 355
                cp3->setChecked(m_Doc->layerLocked(layerNumber));
4832 fschmid 356
                flagsLocked.append(cp3);
357
                connect(cp3, SIGNAL(clicked()), this, SLOT(lockLayer()));
5572 fschmid 358
                Table->setCellWidget(row, 3, cp3);
5359 fschmid 359
                QCheckBox *cp4 = new QCheckBox(this, tmp.setNum(layerLevel));
5781 cbradney 360
                cp4->setChecked(m_Doc->layerFlow(layerNumber));
5359 fschmid 361
                flagsFlow.append(cp4);
362
                connect(cp4, SIGNAL(clicked()), this, SLOT(flowToggleLayer()));
5572 fschmid 363
                Table->setCellWidget(row, 4, cp4);
364
                QCheckBox *cp5 = new QCheckBox(this, tmp.setNum(layerLevel));
5781 cbradney 365
                cp5->setChecked(m_Doc->layerOutline(layerNumber));
5572 fschmid 366
                flagsOutline.append(cp5);
367
                connect(cp5, SIGNAL(clicked()), this, SLOT(outlineToggleLayer()));
368
                Table->setCellWidget(row, 5, cp5);
6293 fschmid 369
                LayerLabel *lbl = new LayerLabel(Table);
370
                lbl->setText(m_Doc->layerName(layerNumber));
371
                Table->setItem(row, 6, lbl);
372
//              Table->setText(row, 6, m_Doc->layerName(layerNumber));
2937 cbradney 373
                Header->setLabel(row, tmp.setNum(layerLevel));
161 Franz 374
        }
5572 fschmid 375
        Table->setColumnStretchable(6, true);
6293 fschmid 376
//      Table->adjustColumn(6);
3 paul 377
        connect(Table, SIGNAL(currentChanged(int, int)), this, SLOT(setActiveLayer(int)));
5373 fschmid 378
        connect(opacitySpinBox, SIGNAL(valueChanged(int)), this, SLOT(changeOpacity()));
5375 fschmid 379
        connect(blendMode, SIGNAL(activated(int)), this, SLOT(changeBlendMode(int)));
3 paul 380
}
381
 
382
void LayerPalette::addLayer()
383
{
5781 cbradney 384
        m_Doc->addLayer(QString::null, true);
3 paul 385
        rebuildList();
2937 cbradney 386
        markActiveLayer();
5781 cbradney 387
        m_Doc->scMW()->changeLayer(m_Doc->activeLayer());
388
        m_Doc->changed();
3 paul 389
}
390
 
6290 fschmid 391
void LayerPalette::dupLayer()
392
{
393
        int current = m_Doc->activeLayer();
394
        m_Doc->addLayer(QString::null, true);
395
        rebuildList();
396
        markActiveLayer();
397
        m_Doc->copyLayer(current, m_Doc->activeLayer());
398
        m_Doc->scMW()->changeLayer(m_Doc->activeLayer());
399
        m_Doc->changed();
400
}
401
 
3 paul 402
void LayerPalette::removeLayer()
403
{
5781 cbradney 404
        int layerCount=m_Doc->layerCount();
2937 cbradney 405
        if (layerCount < 2)
3 paul 406
                return;
2937 cbradney 407
        int level = layerCount-1-Table->currentRow();
5781 cbradney 408
        int layerNumber=m_Doc->layerNumberFromLevel(level);
216 Franz 409
        bool delToo = false;
5781 cbradney 410
        if (m_Doc->layerContainsItems(layerNumber))
2937 cbradney 411
        {
3953 cbradney 412
                int scmReturn=ScMessageBox::warning(this, tr("Delete Layer"),
2937 cbradney 413
                                                                        tr("Do you want to delete all objects on this layer too?"),
414
                                                                        QMessageBox::Yes,
3953 cbradney 415
                                                                        QMessageBox::No,
416
                                                                        QMessageBox::Cancel | QMessageBox::Default | QMessageBox::Escape);
417
                if (scmReturn == QMessageBox::Cancel)
418
                        return;
419
                if (scmReturn == QMessageBox::Yes)
2937 cbradney 420
                        delToo = true;
421
        }
1698 tsoots 422
 
5781 cbradney 423
        if (!m_Doc->deleteLayer(layerNumber, delToo))
1698 tsoots 424
                return;
7694 subik 425
 
3 paul 426
        rebuildList();
2937 cbradney 427
        markActiveLayer();
5781 cbradney 428
        m_Doc->scMW()->changeLayer(m_Doc->activeLayer());
429
        m_Doc->changed();
3 paul 430
}
431
 
432
void LayerPalette::upLayer()
433
{
5781 cbradney 434
        int layerCount=m_Doc->layerCount();
2937 cbradney 435
        if ((layerCount < 2) || (Table->currentRow() == 0))
3 paul 436
                return;
2941 cbradney 437
        int layerLevel = layerCount-1-Table->currentRow();
5781 cbradney 438
        m_Doc->raiseLayerByLevel(layerLevel);
3 paul 439
        rebuildList();
2937 cbradney 440
        markActiveLayer();
5781 cbradney 441
        m_Doc->scMW()->changeLayer(m_Doc->activeLayer());
3 paul 442
        emit LayerChanged();
5781 cbradney 443
        m_Doc->changed();
3 paul 444
}
445
 
446
void LayerPalette::downLayer()
447
{
5781 cbradney 448
        int layerCount=m_Doc->layerCount();
2937 cbradney 449
        if ((layerCount < 2) || (Table->currentRow() == static_cast<int>(layerCount) - 1))
3 paul 450
                return;
2941 cbradney 451
        int layerLevel = layerCount-1-Table->currentRow();
5781 cbradney 452
        m_Doc->lowerLayerByLevel(layerLevel);
3 paul 453
        rebuildList();
5781 cbradney 454
        m_Doc->scMW()->changeLayer(m_Doc->activeLayer());
3 paul 455
        emit LayerChanged();
2937 cbradney 456
        markActiveLayer();
5781 cbradney 457
        m_Doc->changed();
3 paul 458
}
459
 
460
void LayerPalette::changeName(int row, int col)
461
{
5572 fschmid 462
        if (col == 6)
161 Franz 463
        {
5781 cbradney 464
                int layerLevel = m_Doc->layerCount()-1-row;
465
                int layerNumber=m_Doc->layerNumberFromLevel(layerLevel);
2937 cbradney 466
                if (layerNumber!=-1)
6293 fschmid 467
                        m_Doc->changeLayerName(layerNumber, Table->item(row, col)->text());
161 Franz 468
        }
3 paul 469
}
470
 
471
void LayerPalette::visibleLayer()
472
{
2937 cbradney 473
        int level = QString(sender()->name()).toInt();
5781 cbradney 474
        int layerNumber=m_Doc->layerNumberFromLevel(level);
2937 cbradney 475
        if (layerNumber==-1)
476
                return;
477
        const QObject* senderBox=sender();
478
        if (senderBox->isA("QCheckBox"))
161 Franz 479
        {
5781 cbradney 480
                m_Doc->setLayerVisible(layerNumber,((QCheckBox*)(senderBox))->isChecked());
2937 cbradney 481
                emit LayerChanged();
161 Franz 482
        }
3 paul 483
}
484
 
485
void LayerPalette::printLayer()
486
{
2937 cbradney 487
        int level = QString(sender()->name()).toInt();
5781 cbradney 488
        int layerNumber=m_Doc->layerNumberFromLevel(level);
2937 cbradney 489
        if (layerNumber==-1)
490
                return;
491
        const QObject* senderBox=sender();
492
        if (senderBox->isA("QCheckBox"))
5781 cbradney 493
                m_Doc->setLayerPrintable(layerNumber,((QCheckBox*)(senderBox))->isChecked());
3 paul 494
}
495
 
4832 fschmid 496
void LayerPalette::lockLayer()
497
{
498
        int level = QString(sender()->name()).toInt();
5781 cbradney 499
        int layerNumber=m_Doc->layerNumberFromLevel(level);
4832 fschmid 500
        if (layerNumber==-1)
501
                return;
502
        const QObject* senderBox=sender();
503
        if (senderBox->isA("QCheckBox"))
6288 fschmid 504
        {
5781 cbradney 505
                m_Doc->setLayerLocked(layerNumber,((QCheckBox*)(senderBox))->isChecked());
6288 fschmid 506
                deleteLayerButton->setEnabled(!((QCheckBox*)(senderBox))->isChecked());
507
        }
6287 fschmid 508
        m_Doc->scMW()->changeLayer(m_Doc->activeLayer());
4832 fschmid 509
}
510
 
5359 fschmid 511
void LayerPalette::flowToggleLayer()
512
{
513
        int level = QString(sender()->name()).toInt();
5781 cbradney 514
        int layerNumber=m_Doc->layerNumberFromLevel(level);
5359 fschmid 515
        if (layerNumber==-1)
516
                return;
517
        const QObject* senderBox=sender();
518
        if (senderBox->isA("QCheckBox"))
5781 cbradney 519
                m_Doc->setLayerFlow(layerNumber,((QCheckBox*)(senderBox))->isChecked());
5359 fschmid 520
}
521
 
5572 fschmid 522
void LayerPalette::outlineToggleLayer()
523
{
524
        int level = QString(sender()->name()).toInt();
5781 cbradney 525
        int layerNumber=m_Doc->layerNumberFromLevel(level);
5572 fschmid 526
        if (layerNumber==-1)
527
                return;
528
        const QObject* senderBox=sender();
529
        if (senderBox->isA("QCheckBox"))
530
        {
5781 cbradney 531
                m_Doc->setLayerOutline(layerNumber,((QCheckBox*)(senderBox))->isChecked());
5572 fschmid 532
                emit LayerChanged();
533
        }
534
}
535
 
536
void LayerPalette::markLayer()
537
{
538
        int level = QString(sender()->name()).toInt();
5781 cbradney 539
        int layerNumber=m_Doc->layerNumberFromLevel(level);
5572 fschmid 540
        if (layerNumber==-1)
541
                return;
542
        const QObject* senderBox=sender();
5583 fschmid 543
        if (senderBox->isA("QToolButton"))
5572 fschmid 544
        {
545
                QColor neu = QColor();
5781 cbradney 546
                neu = QColorDialog::getColor(m_Doc->layerMarker(layerNumber), this);
5583 fschmid 547
                QPixmap pm(20,15);
5572 fschmid 548
                pm.fill(neu);
5583 fschmid 549
                QIconSet ic;
550
                ic.setPixmap(pm, QIconSet::Small, QIconSet::Normal);
551
                ic.setPixmap(pm, QIconSet::Small, QIconSet::Active);
552
                ((QToolButton*)(senderBox))->setIconSet(ic);
5781 cbradney 553
                m_Doc->setLayerMarker(layerNumber,neu);
5572 fschmid 554
                emit LayerChanged();
555
        }
556
}
557
 
5373 fschmid 558
void LayerPalette::changeOpacity()
559
{
5781 cbradney 560
        m_Doc->setLayerTransparency(m_Doc->activeLayer(), opacitySpinBox->value() / 100.0);
5373 fschmid 561
        emit LayerChanged();
562
}
563
 
5375 fschmid 564
void LayerPalette::changeBlendMode(int blend)
565
{
5781 cbradney 566
        m_Doc->setLayerBlendMode(m_Doc->activeLayer(), blend);
5375 fschmid 567
        emit LayerChanged();
568
}
569
 
2937 cbradney 570
void LayerPalette::markActiveLayer(int layerNumber)
3 paul 571
{
5375 fschmid 572
        disconnect(blendMode, SIGNAL(activated(int)), this, SLOT(changeBlendMode(int)));
5373 fschmid 573
        disconnect(opacitySpinBox, SIGNAL(valueChanged(int)), this, SLOT(changeOpacity()));
2130 fschmid 574
        disconnect(Table, SIGNAL(currentChanged(int, int)), this, SLOT(setActiveLayer(int)));
2937 cbradney 575
        int layerToMark=layerNumber;
576
        if (layerNumber==-1)
5781 cbradney 577
                layerToMark=m_Doc->activeLayer();
578
        Table->setCurrentCell(m_Doc->layerCount()-1-m_Doc->layerLevelFromNumber(layerToMark), 6);
579
        opacitySpinBox->setValue(qRound(m_Doc->layerTransparency(layerToMark) * 100));
580
        blendMode->setCurrentItem(m_Doc->layerBlendMode(layerToMark));
6288 fschmid 581
        deleteLayerButton->setEnabled(!m_Doc->layerLocked( m_Doc->activeLayer() ));
2130 fschmid 582
        connect(Table, SIGNAL(currentChanged(int, int)), this, SLOT(setActiveLayer(int)));
5373 fschmid 583
        connect(opacitySpinBox, SIGNAL(valueChanged(int)), this, SLOT(changeOpacity()));
5375 fschmid 584
        connect(blendMode, SIGNAL(activated(int)), this, SLOT(changeBlendMode(int)));
3 paul 585
}
586
 
587
void LayerPalette::setActiveLayer(int row)
588
{
5375 fschmid 589
        disconnect(blendMode, SIGNAL(activated(int)), this, SLOT(changeBlendMode(int)));
5373 fschmid 590
        disconnect(opacitySpinBox, SIGNAL(valueChanged(int)), this, SLOT(changeOpacity()));
5781 cbradney 591
        int layerNumber=m_Doc->layerNumberFromLevel(m_Doc->layerCount()-1-row);
592
        bool found=m_Doc->setActiveLayer(layerNumber);
2937 cbradney 593
        if (found)
5373 fschmid 594
        {
5781 cbradney 595
                m_Doc->scMW()->changeLayer(m_Doc->activeLayer());
596
                opacitySpinBox->setValue(qRound(m_Doc->layerTransparency(m_Doc->activeLayer()) * 100));
597
                blendMode->setCurrentItem(m_Doc->layerBlendMode(m_Doc->activeLayer()));
6288 fschmid 598
                deleteLayerButton->setEnabled(!m_Doc->layerLocked( m_Doc->activeLayer() ));
5373 fschmid 599
        }
600
        connect(opacitySpinBox, SIGNAL(valueChanged(int)), this, SLOT(changeOpacity()));
5375 fschmid 601
        connect(blendMode, SIGNAL(activated(int)), this, SLOT(changeBlendMode(int)));
3 paul 602
}
1697 tsoots 603
 
2190 cbradney 604
void LayerPalette::languageChange()
605
{
606
        setCaption( tr( "Layers" ) );
5375 fschmid 607
        textLabel1->setText( tr( "Blend Mode:" ) );
608
        blendMode->clear();
609
        blendMode->insertItem( tr("Normal"));
610
        blendMode->insertItem( tr("Darken"));
611
        blendMode->insertItem( tr("Lighten"));
612
        blendMode->insertItem( tr("Multiply"));
613
        blendMode->insertItem( tr("Screen"));
614
        blendMode->insertItem( tr("Overlay"));
615
        blendMode->insertItem( tr("Hard Light"));
616
        blendMode->insertItem( tr("Soft Light"));
617
        blendMode->insertItem( tr("Difference"));
5814 mrdocs 618
        blendMode->insertItem( tr("Exclusion"));
5375 fschmid 619
        blendMode->insertItem( tr("Color Dodge"));
620
        blendMode->insertItem( tr("Color Burn"));
5712 fschmid 621
        blendMode->insertItem( tr("Hue"));
622
        blendMode->insertItem( tr("Saturation"));
623
        blendMode->insertItem( tr("Color"));
624
        blendMode->insertItem( tr("Luminosity"));
5373 fschmid 625
        textLabel2->setText( tr( "Opacity:" ) );
626
        opacitySpinBox->setSuffix( tr(" %"));
5572 fschmid 627
        Table->horizontalHeader()->setLabel(6, tr("Name"));
2937 cbradney 628
        QToolTip::remove( newLayerButton );
6290 fschmid 629
        QToolTip::remove( duplicateLayerButton );
2937 cbradney 630
        QToolTip::remove( deleteLayerButton );
631
        QToolTip::remove( raiseLayerButton );
632
        QToolTip::remove( lowerLayerButton );
633
        QToolTip::add( newLayerButton, tr( "Add a new layer" ) );
6290 fschmid 634
        QToolTip::add( duplicateLayerButton, tr( "Duplicates the current layer" ) );
2937 cbradney 635
        QToolTip::add( deleteLayerButton, tr( "Delete layer" ) );
636
        QToolTip::add( raiseLayerButton, tr( "Raise layer" ) );
637
        QToolTip::add( lowerLayerButton, tr( "Lower layer" ) );
5887 fschmid 638
        dynTip->clearHeaderTips();
5888 mrdocs 639
        dynTip->addHeaderTip("<qt>" + tr("Color of the Layer Indicator - Each layer has a color assigned to display on the canvas when layer indicators are enabled. You can double click to edit the color. ") + "</qt>");
640
        dynTip->addHeaderTip( "<qt>" + tr("Make Layer Visible - Uncheck to hide the layer from the display ") + "</qt>" );
641
        dynTip->addHeaderTip( "<qt>" + tr("Print Layer - Uncheck to disable printing. ") + "</qt>" );
642
        dynTip->addHeaderTip( "<qt>" + tr("Lock or Unlock Layer - Unchecked is unlocked ") + "</qt>" );
643
        dynTip->addHeaderTip( "<qt>" + tr("Text flows around objects in lower Layers - Enabling this forces text frames to flow around other objects, even in layers below") + "</qt>" );
644
        dynTip->addHeaderTip( "<qt>" + tr("Outline Mode - Toggles the 'wireframe' display of objects to speed the display of very complex objects.") + "</qt>" ) ;
645
        dynTip->addHeaderTip( "<qt>" + tr("Name of the Layer - Double clicking on the name of a layer enabled editing") + "</qt>" );
2190 cbradney 646
}
2937 cbradney 647