Back to index

scribus-ng  1.3.4.dfsg+svn20071115
smreplacedia.cpp
Go to the documentation of this file.
00001 /*
00002 For general Scribus (>=1.3.2) copyright and licensing information please refer
00003 to the COPYING file provided with the program. Following this notice may exist
00004 a copyright and/or license notice that predates the release of Scribus 1.3.2
00005 for which a new license (GPL+exception) is in place.
00006 */
00007 
00008 #include "smreplacedia.h"
00009 #include "smreplacedia.moc"
00010 
00011 #include <qstring.h>
00012 #include <qstringlist.h>
00013 #include <qlabel.h>
00014 #include <qcombobox.h>
00015 #include <qptrlist.h>
00016 #include <qlayout.h>
00017 
00018 SMRowWidget::SMRowWidget(const QString &toBeDeleted, QStringList replaceOptions, QWidget *parent)
00019 : QWidget(parent, "SMRowWidget")
00020 {
00021        layout = new QHBoxLayout(this, 0, 5, "layout");
00022        deleteLabel = new QLabel(toBeDeleted, this, "deleteLabel");
00023        layout->addWidget(deleteLabel);
00024        optionsCombo = new QComboBox(this, "optionsCombo");
00025        optionsCombo->insertStringList(replaceOptions);
00026        optionsCombo->insertItem( tr("No Style"), 0);
00027        layout->addWidget(optionsCombo);
00028 }
00029 
00030 QString SMRowWidget::toBeDeleted()
00031 {
00032        return deleteLabel->text();
00033 }
00034 
00035 QString SMRowWidget::replaceWith()
00036 {
00037        return optionsCombo->currentItem() == 0 ? "" : optionsCombo->currentText();
00038 }
00039 
00040 SMRowWidget::~SMRowWidget()
00041 {
00042        delete deleteLabel;
00043        delete optionsCombo;
00044        delete layout;
00045 }
00046 
00047 /*************************************************************************/
00048 /*************************************************************************/
00049 
00050 SMReplaceDia::SMReplaceDia(const QStringList &toBeDeleted, const QStringList &replaceOptions, QWidget *parent) : SMReplaceDiaBase(parent)
00051 {
00052        rowWidgets.setAutoDelete(true);
00053 
00054        QStringList options;
00055 
00056        for (uint i = 0; i < replaceOptions.count(); ++i)
00057        {
00058               if (!toBeDeleted.contains(replaceOptions[i]))
00059                      options << replaceOptions[i];
00060        }
00061 
00062        layout = new QVBoxLayout(mainFrame, 0, 5, "layout");
00063        headerLayout = new QHBoxLayout(layout, 5, "headerLayout");
00064        deleteHeader = new QLabel("<b>" + tr("Remove") + "</b>", mainFrame);
00065        optionsHeader = new QLabel("<b>" + tr("Replace with") + "</b>", mainFrame);
00066        headerLayout->addWidget(deleteHeader);
00067        headerLayout->addWidget(optionsHeader);
00068 
00069        for (uint i = 0; i < toBeDeleted.count(); ++i)
00070        {
00071               SMRowWidget *tmp = new SMRowWidget(toBeDeleted[i], options, mainFrame);
00072               layout->addWidget(tmp);
00073               rowWidgets.append(tmp);
00074        }
00075 
00076        layout->addStretch(10);
00077 }
00078 
00079 QValueList<RemoveItem> SMReplaceDia::items()
00080 {
00081        QValueList<RemoveItem> tmp;
00082        for (uint i = 0; i < rowWidgets.count(); ++i)
00083        {
00084               QString s1 = rowWidgets.at(i)->toBeDeleted();
00085               QString s2 = rowWidgets.at(i)->replaceWith();
00086               tmp.append(RemoveItem(s1, s2));
00087        }
00088        return tmp;
00089 }
00090 
00091 SMReplaceDia::~SMReplaceDia()
00092 {
00093        delete optionsHeader;
00094        delete deleteHeader;
00095        delete headerLayout;
00096        delete layout;
00097 }