Back to index

scribus-ng  1.3.4.dfsg+svn20071115
smlinestyle.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 "smlinestyle.h"
00009 #include "smlinestyle.moc"
00010 #include "scribusdoc.h"
00011 #include "linecombo.h"
00012 #include "mspinbox.h"
00013 #include "colorlistbox.h"
00014 #include "colorutil.h"
00015 #include "commonstrings.h"
00016 #include "selection.h"
00017 #include "scribusview.h"
00018 #include "scribus.h"
00019 #include "sccolorengine.h"
00020 #include "mpalette.h"
00021 #include <qheader.h>
00022 #include <qlineedit.h>
00023 #include <qlistview.h>
00024 #include <qpushbutton.h>
00025 #include <qpixmap.h>
00026 #include <qvaluelist.h>
00027 #include <qtabwidget.h>
00028 #include <qlayout.h>
00029 #include <qlistbox.h>
00030 
00031 extern QPixmap loadIcon(QString nam);
00032 
00033 /*** LineStyleWidget *******************************************************/
00034 
00035 LineStyleWidget::LineStyleWidget() : LineStyleWBase()
00036 {
00037        addButton->setPixmap(loadIcon("penciladd.png"));
00038        removeButton->setPixmap(loadIcon("pencilsub.png"));
00039 
00040        dashCombo = new LineCombo(this);
00041        lineLayout->addWidget(dashCombo, 0, 0);
00042 
00043        lineWidth = new MSpinBox( 0, 300, this, 1 );
00044        lineWidth->setSuffix( tr( " pt" ) );
00045        widthLayout->addWidget(lineWidth, 0, 1);
00046 
00047        endCombo->insertItem(loadIcon("ButtCap.png"), tr( "Flat Cap" ) );
00048        endCombo->insertItem(loadIcon("SquareCap.png"), tr( "Square Cap" ) );
00049        endCombo->insertItem(loadIcon("RoundCap.png"), tr( "Round Cap" ) );
00050 
00051        joinCombo->insertItem(loadIcon("MiterJoin.png"), tr( "Miter Join" ) );
00052        joinCombo->insertItem(loadIcon("BevelJoin.png"), tr( "Bevel Join" ) );
00053        joinCombo->insertItem(loadIcon("RoundJoin.png"), tr( "Round Join" ) );
00054 
00055        languageChange();
00056 }
00057 
00058 void LineStyleWidget::languageChange()
00059 {
00060 /***********************************/
00061 /*      Begin Tooltips             */
00062 /***********************************/
00063 // These are for the line style page
00064 
00065        QToolTip::add(addButton,    tr("Add a new line"));
00066        QToolTip::add(removeButton, tr("Remove a line"));
00067        QToolTip::add(dashCombo,    tr("Line style"));
00068        QToolTip::add(lineWidth,    tr("Line width"));
00069        QToolTip::add(endCombo,     tr("End style"));
00070        QToolTip::add(joinCombo,    tr("Join style"));
00071        QToolTip::add(colorCombo,   tr("Line color"));
00072        QToolTip::add(shadeBox,     tr("Line shade"));
00073 
00074 /***********************************/
00075 /*      End Tooltips               */
00076 /***********************************/
00077 
00078 
00079 }
00080 
00081 void LineStyleWidget::showStyle(const multiLine &lineStyle, ColorList &colorList, int subLine)
00082 {
00083        disconnect(lineStyles, SIGNAL(highlighted(int)), this, SLOT(slotEditNewLine(int)));
00084        currentStyle = lineStyle;
00085        colorCombo->clear();
00086        ColorList::Iterator it;
00087        ScribusDoc* doc = colorList.document();
00088        for (it = colorList.begin(); it != colorList.end(); ++it)
00089               colorCombo->listBox()->insertItem(new ColorWidePixmapItem(colorList[it.key()], doc, it.key()));
00090        colors = colorList;
00091        updateLineList();
00092        slotEditNewLine(subLine);
00093        connect(lineStyles, SIGNAL(highlighted(int)), this, SLOT(slotEditNewLine(int)));
00094 }
00095 
00096 void LineStyleWidget::slotEditNewLine(int i)
00097 {
00098        lineStyles->setSelected(i, true);
00099        //currentLine_ = i;
00100        lineWidth->setValue(currentStyle[i].Width);
00101        colorCombo->setCurrentText(currentStyle[i].Color);
00102        shadeBox->setValue(currentStyle[i].Shade);
00103        
00104        switch (static_cast<PenStyle>(currentStyle[i].Dash))
00105        {
00106        case SolidLine:
00107               dashCombo->setCurrentItem(0);
00108               break;
00109        case DashLine:
00110               dashCombo->setCurrentItem(1);
00111               break;
00112        case DotLine:
00113               dashCombo->setCurrentItem(2);
00114               break;
00115        case DashDotLine:
00116               dashCombo->setCurrentItem(3);
00117               break;
00118        case DashDotDotLine:
00119               dashCombo->setCurrentItem(4);
00120               break;
00121        default:
00122               dashCombo->setCurrentItem(0);
00123               break;
00124        }
00125 
00126        switch (static_cast<PenCapStyle>(currentStyle[i].LineEnd))
00127        {
00128        case FlatCap:
00129               endCombo->setCurrentItem(0);
00130               break;
00131        case SquareCap:
00132               endCombo->setCurrentItem(1);
00133               break;
00134        case RoundCap:
00135               endCombo->setCurrentItem(2);
00136               break;
00137        default:
00138               endCombo->setCurrentItem(0);
00139               break;
00140        }
00141 
00142        switch (static_cast<PenJoinStyle>(currentStyle[i].LineJoin))
00143        {
00144        case MiterJoin:
00145               joinCombo->setCurrentItem(0);
00146               break;
00147        case BevelJoin:
00148               joinCombo->setCurrentItem(1);
00149               break;
00150        case RoundJoin:
00151               joinCombo->setCurrentItem(2);
00152               break;
00153        default:
00154               joinCombo->setCurrentItem(0);
00155               break;
00156        }
00157 }
00158 
00159 void LineStyleWidget::updateLineList()
00160 {
00161        QString tmp, tmp2;
00162        lineStyles->clear();
00163        QPixmap * pm2;
00164        for (multiLine::iterator it = currentStyle.begin(); it != currentStyle.end(); ++it)
00165        {
00166               pm2 = getWidePixmap(getColor((*it).Color, (*it).Shade));
00167               tmp2 = " "+tmp.setNum((*it).Width)+ tr(" pt")+" ";
00168               tmp2 += CommonStrings::translatePenStyleName(static_cast<PenStyle>((*it).Dash));
00169               tmp2 += " ";
00170               lineStyles->insertItem(*pm2, tmp2);
00171        }
00172 }
00173 
00174 QColor LineStyleWidget::getColor(const QString &name, int shade)
00175 {
00176        const ScColor& color = colors[name];
00177        QColor tmpf = ScColorEngine::getDisplayColor(color, colors.document(), shade);
00178        return tmpf;
00179 }
00180 
00181 LineStyleWidget::~LineStyleWidget()
00182 {
00183        
00184 }
00185 
00186 /*************************************************************************/
00187 /*************************************************************************/
00188 
00189 SMLineStyle::SMLineStyle() : StyleItem(), doc_(0), widget_(0), twidget_(0), selectionIsDirty_(false)
00190 {
00191        
00192 }
00193 
00194 QTabWidget* SMLineStyle::widget()
00195 {
00196        if (!twidget_)
00197        {
00198               twidget_ = new QTabWidget();
00199               widget_ = new LineStyleWidget();
00200               twidget_->addTab(widget_, tr("Properties"));
00201               connect(widget_->lineStyles, SIGNAL(highlighted(int)), this, SLOT(slotCurrentLineChanged(int)));
00202        }
00203        return twidget_;
00204 }
00205 
00206 QString SMLineStyle::typeNamePlural()
00207 {
00208        return tr("Line Styles");
00209 }
00210 
00211 QString SMLineStyle::typeNameSingular()
00212 {
00213        return tr("Line Style");
00214 }
00215 
00216 void SMLineStyle::currentDoc(ScribusDoc *doc)
00217 {
00218        doc_ = doc;
00219        if (doc_)
00220        {
00221               tmpLines = doc_->MLineStyles;
00222               selection_.clear();
00223        }
00224        else
00225        {
00226               tmpLines.clear();
00227               selection_.clear();
00228        }
00229 }
00230 
00231 QValueList<StyleName> SMLineStyle::styles(bool reloadFromDoc)
00232 {
00233        if (doc_ && reloadFromDoc) {
00234               tmpLines = doc_->MLineStyles;
00235        }
00236 
00237        QValueList<StyleName> tmp;
00238        QMap<QString,multiLine>::Iterator it;
00239 
00240        for (it = tmpLines.begin(); it != tmpLines.end(); ++it)
00241               tmp << StyleName(it.key(), QString::null);
00242 
00243        return tmp;
00244 }
00245 
00246 void SMLineStyle::reload()
00247 {
00248        if (!doc_)
00249               return;
00250 
00251        selection_.clear();
00252        tmpLines = doc_->MLineStyles;
00253 }
00254 
00255 void SMLineStyle::selected(const QStringList &styleNames)
00256 {
00257        selection_.clear();
00258        selectionIsDirty_ = false;
00259 
00260        removeConnections();
00261 
00262        if (styleNames.count() > 1)
00263               setMultiSelection(styleNames);
00264        else if (styleNames.count() == 1)
00265               setSelection(styleNames[0]);
00266 
00267        updatePreview();
00268        setupConnections();
00269 }
00270 
00271 void SMLineStyle::setSelection(const QString& styleName)
00272 {
00273        if (!doc_)
00274               return;
00275 
00276        if (!tmpLines.contains(styleName))
00277               return; // something's wrong here
00278 
00279        selection_.clear();
00280        selection_[styleName] = &tmpLines[styleName];
00281        widget_->showStyle(tmpLines[styleName], doc_->PageColors);
00282        currentLine_ = 0;
00283 }
00284 
00285 void SMLineStyle::setMultiSelection(const QStringList& styles)
00286 {
00287        selection_.clear();
00288        for (uint i = 0; i < styles.count(); ++i)
00289        {
00290               if (!tmpLines.contains(styles[i]))
00291                      continue;
00292               selection_[styles[i]] = &tmpLines[styles[i]];
00293        }
00294        currentLine_ = 0;
00295        // todo do the tricks for clever showing of multiple styles
00296 }
00297 
00298 QString SMLineStyle::fromSelection() const
00299 {
00300        QString lsName(QString::null);
00301        if (!doc_)
00302               return lsName;
00303 
00304        for (uint i = 0; i < doc_->m_Selection->count(); ++i)
00305        {
00306               PageItem *item = doc_->m_Selection->itemAt(i);
00307               QString tmpName = item->customLineStyle();
00308               if (lsName.isNull() && !tmpName.isEmpty() && tmpName != "")
00309               {
00310                      lsName = item->customLineStyle();
00311               }
00312               else if (!lsName.isNull() && !tmpName.isEmpty() && tmpName != "" && lsName != tmpName)
00313               {
00314                      lsName = QString::null;
00315                      break;
00316               }
00317        }
00318        return lsName;
00319 }
00320 
00321 void SMLineStyle::toSelection(const QString &styleName) const
00322 {
00323        if (!doc_)
00324               return;
00325 
00326        for (uint i = 0; i < doc_->m_Selection->count(); ++i)
00327        {
00328               if (styleName.isNull())
00329                      doc_->m_Selection->itemAt(i)->setCustomLineStyle("");
00330               else
00331                      doc_->m_Selection->itemAt(i)->setCustomLineStyle(styleName);
00332 
00333               doc_->view()->RefreshItem(doc_->m_Selection->itemAt(i));
00334        }
00335 }
00336 
00337 QString SMLineStyle::newStyle()
00338 {
00339        if (!doc_)
00340               return QString::null;
00341        struct SingleLine sl;
00342 //     sl.Color = "Black";
00343 //     sl.Shade = 100;
00344 //     sl.Dash = SolidLine;
00345 //     sl.LineEnd = FlatCap;
00346 //     sl.LineJoin = MiterJoin;
00347 //     sl.Width = 1.0;
00348        sl.Color = doc_->toolSettings.dPenLine;
00349        sl.Shade = doc_->toolSettings.dShadeLine;
00350        sl.Dash = Qt::SolidLine;//Docu->toolSettings.;
00351        sl.LineEnd = Qt::FlatCap;//Docu->toolSettings.;
00352        sl.LineJoin = doc_->toolSettings.dLstyleLine;
00353        sl.Width = doc_->toolSettings.dWidthLine;
00354        multiLine ml;
00355        ml.push_back(sl);
00356        QString name = getUniqueName( tr("New Style"));
00357        tmpLines[name] = ml;
00358        return name;
00359 }
00360 
00361 QString SMLineStyle::newStyle(const QString &fromStyle)
00362 {
00363        Q_ASSERT(tmpLines.contains(fromStyle));
00364 
00365        multiLine ml(tmpLines[fromStyle]);
00366        QString name = getUniqueName( tr("Clone of %1").arg(fromStyle));
00367        tmpLines[name] = ml;
00368        return name;
00369 }
00370 
00371 QString SMLineStyle::getUniqueName(const QString &name)
00372 {
00373        int id = 0;
00374        QString s = name;
00375 
00376        while (tmpLines.contains(s))
00377        {
00378               ++id;
00379               s = tr("%1 (%2)", "This for unique name when creating "
00380                         "a new character style. %1 will be the name "
00381                         "of the style and %2 will be a number forming "
00382                         "a style name like: New Style (2)").arg(name).arg(id);
00383        }
00384 
00385        return s;
00386 }
00387 
00388 void SMLineStyle::apply()
00389 {
00390        if (!doc_)
00391               return;
00392 
00393        PageItem* ite;
00394        doc_->MLineStyles = tmpLines;
00395        QMap<QString, QString> replacement;
00396        for (uint i = 0; i < deleted_.count(); ++i)
00397               replacement[deleted_[i].first] = deleted_[i].second;
00398 
00399        deleted_.clear();
00400 
00401        for (uint d = 0; d < doc_->DocItems.count(); ++d)
00402        {
00403               ite = doc_->DocItems.at(d);
00404               if (!ite->NamedLStyle.isEmpty())
00405               {
00406                      if (!doc_->MLineStyles.contains(ite->NamedLStyle))
00407                             ite->NamedLStyle = replacement[ite->NamedLStyle];
00408               }
00409        }
00410        for (uint d1 = 0; d1 < doc_->MasterItems.count(); ++d1)
00411        {
00412               ite = doc_->MasterItems.at(d1);
00413               if (!ite->NamedLStyle.isEmpty())
00414               {
00415                      if (!doc_->MLineStyles.contains(ite->NamedLStyle))
00416                             ite->NamedLStyle = replacement[ite->NamedLStyle];
00417               }
00418        }
00419        for (uint d1 = 0; d1 < doc_->FrameItems.count(); ++d1)
00420        {
00421               ite = doc_->FrameItems.at(d1);
00422               if (!ite->NamedLStyle.isEmpty())
00423               {
00424                      if (!doc_->MLineStyles.contains(ite->NamedLStyle))
00425                             ite->NamedLStyle = replacement[ite->NamedLStyle];
00426               }
00427        }
00428        doc_->changed();
00429        doc_->scMW()->propertiesPalette->SetLineFormats(doc_);
00430        doc_->view()->DrawNew();
00431        selectionIsDirty_ = false;
00432 }
00433 
00434 QString SMLineStyle::shortcut(const QString &stylename) const
00435 {
00436        Q_ASSERT(tmpLines.contains(stylename));
00437        return tmpLines[stylename].shortcut;
00438 }
00439 
00440 void SMLineStyle::setShortcut(const QString &shortcut)
00441 {
00442        Q_ASSERT(selection_.count() == 1);
00443        if (selection_.count() != 1)
00444               return;
00445 
00446        QMap<QString, multiLine*>::iterator it;
00447        for (it = selection_.begin(); it != selection_.end(); ++it)
00448               (*it)->shortcut = shortcut;
00449 
00450        if (!selectionIsDirty_)
00451        {
00452               selectionIsDirty_ = true;
00453               emit selectionDirty();
00454        }
00455 }
00456 
00457 void SMLineStyle::deleteStyles(const QValueList<RemoveItem> &removeList)
00458 {
00459        for (uint i = 0; i < removeList.count(); ++i)
00460        {
00461               selection_.remove(selection_.find(removeList[i].first));
00462               tmpLines.remove(tmpLines.find(removeList[i].first));
00463               deleted_.append(removeList[i]);
00464        }
00465 }
00466 
00467 void SMLineStyle::nameChanged(const QString &newName)
00468 {
00469        if (selection_.count() != 1)
00470        {
00471               qDebug(QString("SMLineStyle::nameChanged #selection=%1").arg(selection_.count()));
00472               return;
00473        }
00474        QString oldName = selection_.begin().key();
00475        multiLine *tmpLine = selection_.begin().data();
00476        multiLine newLine(*tmpLine);
00477        
00478        selection_.clear();
00479        tmpLines.erase(oldName);
00480 
00481        tmpLines.insert(newName, newLine);
00482        selection_[newName] = &tmpLines[newName];
00483 
00484        QValueList<RemoveItem>::iterator it;
00485        for (it = deleted_.begin(); it != deleted_.end(); ++it)
00486        {
00487               if ((*it).second == oldName)
00488               {
00489                      oldName = (*it).first;
00490                      deleted_.remove(it);
00491                      break;
00492               }
00493        }
00494 
00495        deleted_.append(RemoveItem(oldName, newName));
00496 }
00497 
00498 void SMLineStyle::languageChange()
00499 {
00500        
00501 }
00502 
00503 void SMLineStyle::unitChange()
00504 {
00505 
00506 }
00507 
00508 void SMLineStyle::setupConnections()
00509 {
00510        connect(widget_->addButton, SIGNAL(clicked()), this, SLOT(slotAddLine()));
00511        connect(widget_->removeButton, SIGNAL(clicked()), this, SLOT(slotDeleteLine()));
00512        connect(widget_->endCombo, SIGNAL(activated(int)), this, SLOT(slotSetEnd(int)));
00513        connect(widget_->joinCombo, SIGNAL(activated(int)), this, SLOT(slotSetJoin(int)));
00514        connect(widget_->colorCombo, SIGNAL(activated(const QString&)), this, SLOT(slotColor(const QString&)));
00515        connect(widget_->dashCombo, SIGNAL(activated(int)), this, SLOT(slotLineStyle(int)));
00516        connect(widget_->shadeBox, SIGNAL(valueChanged(int)), this, SLOT(slotShade(int)));
00517        connect(widget_->lineWidth, SIGNAL(valueChanged(int)), this, SLOT(slotLineWidth()));
00518 }
00519 
00520 void SMLineStyle::removeConnections()
00521 {
00522        disconnect(widget_->addButton, SIGNAL(clicked()), this, SLOT(slotAddLine()));
00523        disconnect(widget_->removeButton, SIGNAL(clicked()), this, SLOT(slotDeleteLine()));
00524        disconnect(widget_->endCombo, SIGNAL(activated(int)), this, SLOT(slotSetEnd(int)));
00525        disconnect(widget_->joinCombo, SIGNAL(activated(int)), this, SLOT(slotSetJoin(int)));
00526        disconnect(widget_->colorCombo, SIGNAL(activated(const QString&)), this, SLOT(slotColor(const QString&)));
00527        disconnect(widget_->dashCombo, SIGNAL(activated(int)), this, SLOT(slotLineStyle(int)));
00528        disconnect(widget_->shadeBox, SIGNAL(valueChanged(int)), this, SLOT(slotShade(int)));
00529        disconnect(widget_->lineWidth, SIGNAL(valueChanged(int)), this, SLOT(slotLineWidth()));
00530 }
00531 
00532 void SMLineStyle::slotLineStyle(int i)
00533 {
00534        PenStyle c = SolidLine;
00535        switch (i)
00536        {
00537               case 0:
00538                      c = SolidLine;
00539                      break;
00540               case 1:
00541                      c = DashLine;
00542                      break;
00543               case 2:
00544                      c = DotLine;
00545                      break;
00546               case 3:
00547                      c = DashDotLine;
00548                      break;
00549               case 4:
00550                      c = DashDotDotLine;
00551                      break;
00552        }
00553 
00554        Q_ASSERT(currentLine_ >= 0);
00555        if (currentLine_ < 0)
00556               return;
00557 
00558        QMap<QString, multiLine*>::iterator it;
00559        for (it = selection_.begin(); it != selection_.end(); ++it)
00560        {
00561               multiLine *tmp = it.data();
00562               (*tmp)[currentLine_].Dash = static_cast<int>(c);
00563        }
00564 
00565        updateSList();
00566        updatePreview();
00567 
00568        if (!selectionIsDirty_)
00569        {
00570               selectionIsDirty_ = true;
00571               emit selectionDirty();
00572        }
00573 }
00574 
00575 void SMLineStyle::slotSetEnd(int i)
00576 {
00577        PenCapStyle c = FlatCap;
00578        switch (i)
00579        {
00580               case 0:
00581                      c = FlatCap;
00582                      break;
00583               case 1:
00584                      c = SquareCap;
00585                      break;
00586               case 2:
00587                      c = RoundCap;
00588                      break;
00589        }
00590 
00591        QMap<QString, multiLine*>::iterator it;
00592        for (it = selection_.begin(); it != selection_.end(); ++it)
00593        {
00594               multiLine *tmp = it.data();
00595               (*tmp)[currentLine_].LineEnd = static_cast<int>(c);
00596        }
00597 
00598        updateSList();
00599        updatePreview();
00600 
00601        if (!selectionIsDirty_)
00602        {
00603               selectionIsDirty_ = true;
00604               emit selectionDirty();
00605        }
00606 }
00607 
00608 void SMLineStyle::slotSetJoin(int i)
00609 {
00610        Q_ASSERT(currentLine_ >= 0);
00611        if (currentLine_ < 0)
00612               return;
00613 
00614        PenJoinStyle c = MiterJoin;
00615        switch (i)
00616        {
00617               case 0:
00618                      c = MiterJoin;
00619                      break;
00620               case 1:
00621                      c = BevelJoin;
00622                      break;
00623               case 2:
00624                      c = RoundJoin;
00625                      break;
00626        }
00627 
00628        QMap<QString, multiLine*>::iterator it;
00629        for (it = selection_.begin(); it != selection_.end(); ++it)
00630        {
00631               multiLine *tmp = it.data();
00632               (*tmp)[currentLine_].LineJoin = static_cast<int>(c);
00633        }
00634 
00635        updateSList();
00636        updatePreview();
00637 
00638        if (!selectionIsDirty_)
00639        {
00640               selectionIsDirty_ = true;
00641               emit selectionDirty();
00642        }
00643 }
00644 
00645 void SMLineStyle::slotColor(const QString &s)
00646 {
00647        QMap<QString, multiLine*>::iterator it;
00648        for (it = selection_.begin(); it != selection_.end(); ++it)
00649        {
00650               multiLine *tmp = it.data();
00651               (*tmp)[currentLine_].Color = s;
00652        }
00653 
00654        updateSList();
00655        updatePreview();
00656 
00657        if (!selectionIsDirty_)
00658        {
00659               selectionIsDirty_ = true;
00660               emit selectionDirty();
00661        }
00662 }
00663 
00664 void SMLineStyle::slotShade(int i)
00665 {
00666        QMap<QString, multiLine*>::iterator it;
00667        for (it = selection_.begin(); it != selection_.end(); ++it)
00668        {
00669               multiLine *tmp = it.data();
00670               (*tmp)[currentLine_].Shade = i;
00671        }
00672 
00673        updateSList();
00674        updatePreview();
00675 
00676        if (!selectionIsDirty_)
00677        {
00678               selectionIsDirty_ = true;
00679               emit selectionDirty();
00680        }
00681 }
00682 
00683 void SMLineStyle::slotLineWidth()
00684 {
00685        QMap<QString, multiLine*>::iterator it;
00686        for (it = selection_.begin(); it != selection_.end(); ++it)
00687        {
00688               multiLine *tmp = it.data();
00689               (*tmp)[currentLine_].Width = widget_->lineWidth->value();
00690        }
00691 
00692        updatePreview();
00693        resort();
00694 
00695        if (!selectionIsDirty_)
00696        {
00697               selectionIsDirty_ = true;
00698               emit selectionDirty();
00699        }
00700 }
00701 
00702 void SMLineStyle::slotAddLine()
00703 {
00704        if (!doc_ || selection_.count() != 1)
00705               return;
00706 
00707        multiLine *tmpLine = selection_.begin().data();
00708        struct SingleLine sl;
00709        sl.Color = (*tmpLine)[currentLine_].Color;
00710        sl.Shade = (*tmpLine)[currentLine_].Shade;
00711        sl.Dash = (*tmpLine)[currentLine_].Dash;
00712        sl.LineEnd = (*tmpLine)[currentLine_].LineEnd;
00713        sl.LineJoin = (*tmpLine)[currentLine_].LineJoin;
00714        sl.Width = (*tmpLine)[currentLine_].Width;
00715        int cc = 0;
00716        bool fo = false;
00717        for (multiLine::iterator it2 = (*tmpLine).begin(); it2 != (*tmpLine).end(); ++it2)
00718        {
00719               if (sl.Width < (*it2).Width)
00720               {
00721                      (*tmpLine).insert(it2, sl);
00722                      fo = true;
00723                      break;
00724               }
00725               cc++;
00726        }
00727        if (!fo)
00728               (*tmpLine).push_back(sl);
00729        currentLine_ = cc;
00730        rebuildList();
00731        widget_->showStyle(*tmpLine, doc_->PageColors, cc);
00732        updatePreview();
00733 
00734        if (!selectionIsDirty_)
00735        {
00736               selectionIsDirty_ = true;
00737               emit selectionDirty();
00738        }
00739 }
00740 
00741 void SMLineStyle::rebuildList()
00742 {
00743        QString tmp, tmp2;
00744        widget_->lineStyles->clear();
00745        QPixmap * pm2;
00746        multiLine *tmpLine = selection_.begin().data();
00747        for (multiLine::iterator it = (*tmpLine).begin(); it != (*tmpLine).end(); ++it)
00748        {
00749               pm2 = getWidePixmap(calcFarbe((*it).Color, (*it).Shade));
00750               tmp2 = " "+tmp.setNum((*it).Width)+ tr(" pt")+" ";
00751               switch (static_cast<PenStyle>((*it).Dash))
00752               {
00753                      case SolidLine:
00754                             tmp2 += tr("Solid Line");
00755                             break;
00756                      case DashLine:
00757                             tmp2 += tr("Dashed Line");
00758                             break;
00759                      case DotLine:
00760                             tmp2 += tr("Dotted Line");
00761                             break;
00762                      case DashDotLine:
00763                             tmp2 += tr("Dash Dot Line");
00764                             break;
00765                      case DashDotDotLine:
00766                             tmp2 += tr("Dash Dot Dot Line");
00767                             break;
00768                      default:
00769                             tmp2 += tr("Solid Line");
00770                             break;
00771               }
00772               tmp2 += " ";
00773               widget_->lineStyles->insertItem(*pm2, tmp2);
00774        }
00775 }
00776 
00777 void SMLineStyle::slotDeleteLine()
00778 {
00779        if (!doc_ || selection_.count() != 1)
00780               return;
00781 
00782        multiLine *tmpLine = selection_.begin().data();
00783 
00784        if ((*tmpLine).size() == 1)
00785               return;
00786 
00787        int cc = 0;
00788        for (multiLine::iterator it3 = (*tmpLine).begin(); it3 != (*tmpLine).end(); ++it3)
00789        {
00790               if (cc == currentLine_)
00791               {
00792                      (*tmpLine).erase(it3);
00793                      break;
00794               }
00795               cc++;
00796        }
00797 
00798        currentLine_ = 0;
00799        rebuildList();
00800        widget_->showStyle(*tmpLine, doc_->PageColors);
00801        updatePreview();
00802 
00803        if (!selectionIsDirty_)
00804        {
00805               selectionIsDirty_ = true;
00806               emit selectionDirty();
00807        }
00808 }
00809 
00810 void SMLineStyle::updateSList()
00811 {
00812        if (selection_.count() < 1)
00813               return;
00814 
00815        Q_ASSERT(currentLine_ >= 0);
00816        if  (currentLine_ < 0)
00817               return;
00818 
00819 
00820        QString tmp, tmp2;
00821        QPixmap * pm;
00822        multiLine *tmpLine = selection_.begin().data();
00823        
00824        pm = getWidePixmap(calcFarbe((*tmpLine)[currentLine_].Color, (*tmpLine)[currentLine_].Shade));
00825        tmp2 = " "+tmp.setNum((*tmpLine)[currentLine_].Width)+ tr(" pt ");
00826        switch (static_cast<PenStyle>((*tmpLine)[currentLine_].Dash))
00827        {
00828               case SolidLine:
00829                      tmp2 += tr("Solid Line");
00830                      break;
00831               case DashLine:
00832                      tmp2 += tr("Dashed Line");
00833                      break;
00834               case DotLine:
00835                      tmp2 += tr("Dotted Line");
00836                      break;
00837               case DashDotLine:
00838                      tmp2 += tr("Dash Dot Line");
00839                      break;
00840               case DashDotDotLine:
00841                      tmp2 += tr("Dash Dot Dot Line");
00842                      break;
00843               default:
00844                      tmp2 += tr("Solid Line");
00845                      break;
00846        }
00847        tmp2 += " ";
00848        if (widget_->lineStyles->count() == 1)  // to avoid Bug in Qt-3.1.2
00849        {
00850               widget_->lineStyles->clear();
00851               widget_->lineStyles->insertItem(*pm, tmp2);
00852        }
00853        else
00854               widget_->lineStyles->changeItem(*pm, tmp2, currentLine_);
00855 }
00856 
00857 void SMLineStyle::updatePreview()
00858 {
00859     if (selection_.count() < 1)
00860               return;
00861        
00862        QPixmap pm = QPixmap(200, 37);
00863        pm.fill(white);
00864        QPainter p;
00865        p.begin(&pm);
00866        multiLine *tmpLine = selection_.begin().data();
00867 
00868        for (int it = (*tmpLine).size()-1; it > -1; it--)
00869        {
00870               p.setPen(QPen(calcFarbe((*tmpLine)[it].Color, (*tmpLine)[it].Shade),
00871                              QMAX(static_cast<int>((*tmpLine)[it].Width), 1),
00872                              static_cast<PenStyle>((*tmpLine)[it].Dash),
00873                              static_cast<PenCapStyle>((*tmpLine)[it].LineEnd),
00874                              static_cast<PenJoinStyle>((*tmpLine)[it].LineJoin)));
00875               p.drawLine(17, 18, 183, 18);
00876        }
00877        p.end();
00878        widget_->previewLabel->setPixmap(pm);
00879 }
00880 
00881 QColor SMLineStyle::calcFarbe(const QString &name, int shade)
00882 {
00883        QColor tmpf;
00884        if (!doc_)
00885               return tmpf;
00886        const ScColor& color = doc_->PageColors[name];
00887        tmpf = ScColorEngine::getDisplayColor(color, doc_, shade);
00888        return tmpf;
00889 }
00890 
00891 void SMLineStyle::slotCurrentLineChanged(int i)
00892 {
00893        currentLine_ = i;
00894 }
00895 
00896 void SMLineStyle::resort()
00897 {
00898        if (!doc_ || selection_.count() != 1)
00899               return;
00900 
00901        int cc = 0;
00902        struct SingleLine sl;
00903        multiLine *tmpLine = selection_.begin().data();
00904 
00905        sl.Color = (*tmpLine)[currentLine_].Color;
00906        sl.Shade = (*tmpLine)[currentLine_].Shade;
00907        sl.Dash = (*tmpLine)[currentLine_].Dash;
00908        sl.LineEnd = (*tmpLine)[currentLine_].LineEnd;
00909        sl.LineJoin = (*tmpLine)[currentLine_].LineJoin;
00910        sl.Width = (*tmpLine)[currentLine_].Width;
00911        multiLine::iterator it3;
00912        for (it3 = (*tmpLine).begin(); it3 != (*tmpLine).end(); ++it3)
00913        {
00914               if (cc == currentLine_)
00915               {
00916                      (*tmpLine).erase(it3);
00917                      break;
00918               }
00919               cc++;
00920        }
00921        cc = 0;
00922        bool fo = false;
00923        for (multiLine::iterator it2 = (*tmpLine).begin(); it2 != (*tmpLine).end(); ++it2)
00924        {
00925               if (sl.Width < (*it2).Width)
00926               {
00927                      (*tmpLine).insert(it2, sl);
00928                      fo = true;
00929                      break;
00930               }
00931               cc++;
00932        }
00933        if (!fo)
00934               (*tmpLine).push_back(sl);
00935        currentLine_ = cc;
00936        rebuildList();
00937        widget_->showStyle(*tmpLine, doc_->PageColors, cc);
00938        updatePreview();
00939 }
00940 
00941 SMLineStyle::~SMLineStyle()
00942 {
00943        delete widget_;
00944        delete twidget_;
00945        widget_ = 0;
00946        twidget_ = 0;
00947 }