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 #include <QGridLayout>
9 #include <QHBoxLayout>
10 #include <QVBoxLayout>
11 #include <QIcon>
12 #include <QLabel>
13 #include <QSpacerItem>
14 #include <QPushButton>
15
16 #include "colorcombo.h"
17 #include "commonstrings.h"
18 #include "dcolor.h"
19 #include "iconmanager.h"
20 #include "prefsmanager.h"
21 #include "scpage.h"
22 #include "scribusdoc.h"
23
DelColor(QWidget * parent,const ColorList & colorList,const QString & colorName,bool haveDoc)24 DelColor::DelColor( QWidget* parent, const ColorList& colorList, const QString& colorName, bool haveDoc) : QDialog( parent )
25 {
26 setModal(true);
27 cList = colorList;
28 setWindowTitle( tr( "Delete Color" ) );
29 setWindowIcon(IconManager::instance().loadIcon("AppIcon.png"));
30 dialogLayout = new QVBoxLayout( this );
31 dialogLayout->setContentsMargins(9, 9, 9, 9);
32 dialogLayout->setSpacing(6);
33 delColorLayout = new QGridLayout;
34 delColorLayout->setSpacing(6);
35 delColorLayout->setContentsMargins(0, 0, 0, 0);
36 deleteLabel = new QLabel( tr( "Delete Color:" ), this );
37 delColorLayout->addWidget( deleteLabel, 0, 0 );
38 colorToDelLabel = new QLabel( colorName, this );
39 delColorLayout->addWidget( colorToDelLabel, 0, 1 );
40
41 PrefsManager& prefsManager = PrefsManager::instance();
42 bool isToolColor = prefsManager.isToolColor(colorName);
43 replaceLabel = nullptr;
44 replacementColData = nullptr;
45 if (haveDoc || isToolColor)
46 {
47 replaceLabel = new QLabel( tr( "Replace With:" ), this );
48 delColorLayout->addWidget( replaceLabel, 1, 0 );
49 replacementColData = new ColorCombo(false, this);
50 cList.remove(colorName);
51 // 10/26/2004 pv - user can replace deleted color with "None"
52 replacementColData->setPixmapType(ColorCombo::fancyPixmaps);
53 replacementColData->setColors(cList, true);
54 delColorLayout->addWidget( replacementColData, 1, 1 );
55 replacementColor = replacementColData->itemText(0);
56 }
57 dialogLayout->addLayout( delColorLayout );
58
59 okCancelLayout = new QHBoxLayout;
60 okCancelLayout->setSpacing(6);
61 okCancelLayout->setContentsMargins(0, 0, 0, 0);
62 QSpacerItem* spacer = new QSpacerItem( 2, 2, QSizePolicy::Expanding, QSizePolicy::Minimum );
63 okCancelLayout->addItem( spacer );
64 okButton = new QPushButton( CommonStrings::tr_OK, this );
65 okCancelLayout->addWidget( okButton );
66 cancelButton = new QPushButton( CommonStrings::tr_Cancel, this );
67 cancelButton->setDefault( true );
68 okCancelLayout->addWidget( cancelButton );
69 dialogLayout->addLayout( okCancelLayout );
70 setMaximumSize(sizeHint());
71
72 connect( okButton, SIGNAL( clicked() ), this, SLOT( accept() ) );
73 connect( cancelButton, SIGNAL( clicked() ), this, SLOT( reject() ) );
74 if (replacementColData)
75 connect( replacementColData, SIGNAL(activated(int)), this, SLOT( ReplaceColor(int) ) );
76 }
77
ReplaceColor(int id)78 void DelColor::ReplaceColor(int id)
79 {
80 replacementColor = replacementColData->itemText(id);
81 }
82
getReplacementColor()83 const QString& DelColor::getReplacementColor()
84 {
85 return replacementColor;
86 }
87