Back to index

scribus-ng  1.3.4.dfsg+svn20071115
lineformats.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 #include "lineformats.h"
00008 #include "lineformats.moc"
00009 
00010 #include <qpainter.h>
00011 
00012 #include "customfdialog.h"
00013 #include "fileloader.h"
00014 #include "prefsmanager.h"
00015 #include "prefsfile.h"
00016 #include "multiline.h"
00017 #include "commonstrings.h"
00018 #include "scribusdoc.h"
00019 #include "scmessagebox.h"
00020 #include "page.h"
00021 #include "sccolorengine.h"
00022 
00023 extern QPixmap loadIcon(QString nam);
00024 
00025 LineFormate::LineFormate( QWidget* parent, ScribusDoc *doc)
00026               : QDialog( parent, "Formate", true, 0)
00027 {
00028        resize( 327, 260 );
00029        setCaption( tr( "Edit Line Styles" ) );
00030        setIcon(loadIcon("AppIcon.png"));
00031        Docu = doc;
00032        TempStyles = doc->MLineStyles;
00033        StilFormateLayout = new QHBoxLayout( this );
00034        StilFormateLayout->setSpacing( 5 );
00035        StilFormateLayout->setMargin( 10 );
00036 
00037        ListBox1 = new QListBox( this, "ListBox1" );
00038        ListBox1->setMinimumSize( QSize( 200, 240 ) );
00039        StilFormateLayout->addWidget( ListBox1 );
00040 
00041        Layout15 = new QVBoxLayout;
00042        Layout15->setSpacing( 6 );
00043        Layout15->setMargin( 0 );
00044 
00045        LoadLS = new QPushButton( tr( "&Import" ), this, "LoadF" );
00046        Layout15->addWidget( LoadLS );
00047 
00048        NewB = new QPushButton( tr( "&New" ), this, "NewB" );
00049        Layout15->addWidget( NewB );
00050 
00051        EditB = new QPushButton( tr( "&Edit" ), this, "EditB" );
00052        EditB->setDefault( true );
00053        EditB->setEnabled(false);
00054        Layout15->addWidget( EditB );
00055 
00056        DublicateB = new QPushButton( tr( "D&uplicate" ), this, "DublicateB" );
00057        DublicateB->setEnabled(false);
00058        Layout15->addWidget( DublicateB );
00059 
00060        DeleteB = new QPushButton( tr( "&Delete" ), this, "DeleteB" );
00061        DeleteB->setEnabled(false);
00062        Layout15->addWidget( DeleteB );
00063 
00064        SaveB = new QPushButton( tr( "&Save" ), this, "SaveB" );
00065        Layout15->addWidget( SaveB );
00066 
00067        ExitB = new QPushButton( CommonStrings::tr_OK, this, "ExitB" );
00068        Layout15->addWidget( ExitB );
00069 
00070        CancelB = new QPushButton( CommonStrings::tr_Cancel, this, "CancelB" );
00071        Layout15->addWidget( CancelB );
00072        QSpacerItem* spacer = new QSpacerItem( 0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding );
00073        Layout15->addItem( spacer );
00074        StilFormateLayout->addLayout( Layout15 );
00075 
00076        // signals and slots connections
00077        connect(CancelB, SIGNAL(clicked()), this, SLOT(reject()));
00078        connect(SaveB, SIGNAL(clicked()), this, SLOT(saveIt()));
00079        connect(ExitB, SIGNAL(clicked()), this, SLOT(accept()));
00080        connect(LoadLS, SIGNAL(clicked()), this, SLOT(loadLStyles()));
00081        connect(EditB, SIGNAL(clicked()), this, SLOT(editFormat()));
00082        connect(NewB, SIGNAL(clicked()), this, SLOT(neuesFormat()));
00083        connect(DublicateB, SIGNAL(clicked()), this, SLOT(dupFormat()));
00084        connect(DeleteB, SIGNAL(clicked()), this, SLOT(deleteFormat()));
00085        connect(ListBox1, SIGNAL(highlighted(QListBoxItem*)), this, SLOT(selFormat(QListBoxItem*)));
00086        connect( ListBox1, SIGNAL( selected(QListBoxItem*) ), this, SLOT( selEditFormat(QListBoxItem*) ) );
00087        if (ListBox1->count() > 0)
00088        sFnumber = TempStyles.begin().key();
00089        else
00090               sFnumber = "";
00091        Replacement.clear();
00092        UpdateFList();
00093 }
00094 
00095 void LineFormate::saveIt()
00096 {
00097        emit saveStyle(this);
00098 }
00099 
00100 void LineFormate::selFormat(QListBoxItem *c)
00101 {
00102        sFnumber = c->text();
00103        EditB->setEnabled(true);
00104        DublicateB->setEnabled(true);
00105        DeleteB->setEnabled(true);
00106 }
00107 
00108 void LineFormate::selEditFormat(QListBoxItem *c)
00109 {
00110        sFnumber = c->text();
00111        EditB->setEnabled(true);
00112        DublicateB->setEnabled(true);
00113        DeleteB->setEnabled(true);
00114        editFormat();
00115 }
00116 
00117 void LineFormate::dupFormat()
00118 {
00119        multiLine ml;
00120        ml = TempStyles[sFnumber];
00121        MultiLine* dia = new MultiLine(this, Docu, ml, tr("Copy of %1").arg(sFnumber), &TempStyles);
00122        if (dia->exec())
00123        {
00124               TempStyles.insert(dia->SName->text(), dia->TempVorl);
00125               sFnumber = dia->SName->text();
00126        }
00127        delete dia;
00128        UpdateFList();
00129 }
00130 
00131 void LineFormate::neuesFormat()
00132 {
00133        int selectedIndex=ListBox1->currentItem();
00134        int topIndex=ListBox1->topItem();
00135        struct SingleLine sl;
00136 /*     sl.Color = "Black";
00137        sl.Shade = 100;
00138        sl.Dash = SolidLine;
00139        sl.LineEnd = FlatCap;
00140        sl.LineJoin = MiterJoin;
00141        sl.Width = 1.0; */
00142        sl.Color = Docu->toolSettings.dPenLine;
00143        sl.Shade = Docu->toolSettings.dShadeLine;
00144        sl.Dash = SolidLine;//Docu->toolSettings.;
00145        sl.LineEnd = FlatCap;//Docu->toolSettings.;
00146        sl.LineJoin = Docu->toolSettings.dLstyleLine;
00147        sl.Width = Docu->toolSettings.dWidthLine;
00148        multiLine ml;
00149        ml.push_back(sl);
00150        MultiLine* dia = new MultiLine(this, Docu, ml, tr("New Style"), &TempStyles);
00151        if (dia->exec())
00152        {
00153               TempStyles.insert(dia->SName->text(), dia->TempVorl);
00154               sFnumber = dia->SName->text();
00155        }
00156        UpdateFList();
00157        ListBox1->setSelected(selectedIndex, true);
00158        ListBox1->setTopItem(topIndex);
00159 }
00160 
00161 void LineFormate::editFormat()
00162 {
00163        int selectedIndex=ListBox1->currentItem();
00164        int topIndex=ListBox1->topItem();
00165        MultiLine* dia = new MultiLine(this, Docu, TempStyles[sFnumber], sFnumber, &TempStyles);
00166        if (dia->exec())
00167        {
00168               if (sFnumber != dia->SName->text())
00169               {
00170                      Replacement.insert(sFnumber, dia->SName->text());
00171                      TempStyles.remove(sFnumber);
00172                      TempStyles.insert(dia->SName->text(), dia->TempVorl);
00173                      sFnumber = dia->SName->text();
00174               }
00175               else
00176                      TempStyles[sFnumber] = dia->TempVorl;
00177        }
00178        delete dia;
00179        UpdateFList();
00180        ListBox1->setSelected(selectedIndex, true);
00181        ListBox1->setTopItem(topIndex);
00182 }
00183 
00184 void LineFormate::deleteFormat()
00185 {
00186        int selectedIndex=ListBox1->currentItem();
00187        int topIndex=ListBox1->topItem();
00188        int exit=ScMessageBox::warning(this,
00189                                      CommonStrings::trWarning,
00190                                      tr("Do you really want to delete this style?"),
00191                                      CommonStrings::trYesKey,
00192                                      CommonStrings::trNoKey,
00193                                      0, 0, 0);
00194        /* PFJ - 29.02.04 - Changed from 1 to QMessageBox::Yes */
00195        /* FS - 12.05.04 the 1 is correct in this version of QMessageBox, it returns the Nr of the clicked Button either 0 or 1 or 2 */
00196        if (exit == 0)
00197        {
00198               Replacement.insert(sFnumber, "");
00199               TempStyles.remove(sFnumber);
00200               UpdateFList();
00201               int listBoxCount=ListBox1->count();
00202               if (listBoxCount>selectedIndex)
00203                      ListBox1->setSelected(selectedIndex, true);
00204               if (listBoxCount>topIndex)
00205                      ListBox1->setTopItem(topIndex);
00206        }
00207 }
00208 
00209 void LineFormate::loadLStyles()
00210 {
00211        QString fileName;
00212        PrefsContext* dirs = PrefsManager::instance()->prefsFile->getContext("dirs");
00213        QString wdir = dirs->get("lineformats", ".");
00214        CustomFDialog dia(this, wdir, tr("Open"), tr("Documents (*.sla *.sla.gz *.scd *.scd.gz);;All Files (*)"));
00215        if (dia.exec() == QDialog::Accepted)
00216               fileName = dia.selectedFile();
00217        else
00218               return;
00219        if (!fileName.isEmpty())
00220        {
00221               dirs->set("lineformats", fileName.left(fileName.findRev("/")));
00222               FileLoader fl(fileName);
00223               if (fl.TestFile() == -1)
00224               //TODO put in nice user warning
00225                      return;
00226               if (fl.ReadLineStyles(fileName, &TempStyles))
00227                      UpdateFList();
00228        }
00229 }
00230 
00231 void LineFormate::UpdateFList()
00232 {
00233        disconnect(ListBox1, SIGNAL(highlighted(QListBoxItem*)), this, SLOT(selFormat(QListBoxItem*)));
00234        disconnect( ListBox1, SIGNAL( selected(QListBoxItem*) ), this, SLOT( selEditFormat(QListBoxItem*) ) );
00235        ListBox1->clear();
00236        QMap<QString,multiLine>::Iterator it;
00237        for (it = TempStyles.begin(); it != TempStyles.end(); ++it)
00238               ListBox1->insertItem( new LineFormateItem(Docu, it.data(), it.key()) );
00239        if (ListBox1->count() > 0)
00240               ListBox1->setSelected(ListBox1->findItem(sFnumber), true);
00241        bool setter = ListBox1->count() == 0 ? true : false;
00242        if (setter == true)
00243               sFnumber = "";
00244        DublicateB->setEnabled(!setter);
00245        EditB->setEnabled(!setter);
00246        DeleteB->setEnabled(!setter);
00247        ListBox1->sort( true );
00248        connect(ListBox1, SIGNAL(highlighted(QListBoxItem*)), this, SLOT(selFormat(QListBoxItem*)));
00249        connect( ListBox1, SIGNAL( selected(QListBoxItem*) ), this, SLOT( selEditFormat(QListBoxItem*) ) );
00250 }
00251 
00252 LineFormateItem::LineFormateItem(ScribusDoc* Doc, const multiLine& MultiLine, const QString& Text) : ScListBoxPixmap<37, 37>()
00253 {
00254        setText(Text);
00255        mLine = MultiLine;
00256        doc = Doc;
00257 }
00258 
00259 void LineFormateItem::redraw(void)
00260 {
00261        QColor tmpf;
00262        pmap->fill(Qt::white);
00263        QPainter p;
00264        p.begin(pmap.get());
00265        for (int its = mLine.size()-1; its > -1; its--)
00266        {
00267               const ScColor& col = doc->PageColors[mLine[its].Color];
00268               tmpf = ScColorEngine::getDisplayColor(col, doc, mLine[its].Shade);
00269               p.setPen(QPen(tmpf,
00270                                           QMAX(static_cast<int>(mLine[its].Width), 1),
00271                                           static_cast<Qt::PenStyle>(mLine[its].Dash),
00272                                           static_cast<Qt::PenCapStyle>(mLine[its].LineEnd),
00273                                           static_cast<Qt::PenJoinStyle>(mLine[its].LineJoin)));
00274               p.drawLine(0, 18, 37, 18);
00275        }
00276        p.end();
00277 }