Back to index

scribus-ng  1.3.4.dfsg+svn20071115
tabruler.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 "tabruler.h"
00008 #include "tabruler.moc"
00009 #include <qvariant.h>
00010 #include <qcombobox.h>
00011 #include <qlabel.h>
00012 #include <qpushbutton.h>
00013 #include <qtoolbutton.h>
00014 #include <qlayout.h>
00015 #include <qtooltip.h>
00016 #include <qwhatsthis.h>
00017 #include <qpainter.h>
00018 #include <qcursor.h>
00019 #include <qcolor.h>
00020 #include "commonstrings.h"
00021 #include "units.h"
00022 #include "scribusstructs.h"
00023 #include "mspinbox.h"
00024 
00025 extern QPixmap loadIcon(QString nam);
00026 
00027 RulerT::RulerT(QWidget *pa, int ein, QValueList<ParagraphStyle::TabRecord> Tabs, bool ind, double wid) : QWidget(pa)
00028 {
00029        setEraseColor(QColor(255,255,255));
00030        unitIndex = ein;
00031        iter=unitRulerGetIter1FromIndex(unitIndex);
00032        iter2=unitRulerGetIter2FromIndex(unitIndex);
00033        tabValues = Tabs;
00034        haveInd = ind;
00035        offsetIncrement = 5;
00036        offset = 0;
00037        firstLine = 0;
00038        leftIndent = 0;
00039        mousePressed = false;
00040        rulerCode = 0;
00041        actTab = -1;
00042        setMouseTracking(true);
00043        if (wid < 0)
00044        {
00045               setMinimumSize(QSize(400,25));
00046               setMaximumSize(QSize(4000,25));
00047               Width = 4000;
00048               resize(400, 25);
00049        }
00050        else
00051        {
00052               Width = wid;
00053               setMinimumSize(QSize(QMIN(static_cast<int>(Width), 400),25));
00054               setMaximumSize(QSize(4000,25));
00055               resize(QMIN(static_cast<int>(wid), 400), 25);
00056        }
00057 }
00058 
00059 void RulerT::setTabs(QValueList<ParagraphStyle::TabRecord> Tabs, int dEin)
00060 {
00061        unitIndex = dEin;
00062        iter=unitRulerGetIter1FromIndex(unitIndex);
00063        iter2=unitRulerGetIter2FromIndex(unitIndex);
00064        tabValues = Tabs;
00065        repaint();
00066 }
00067 
00068 void RulerT::paintEvent(QPaintEvent *)
00069 {
00070        double xl;
00071        QPainter p;
00072        p.begin(this);
00073        p.drawLine(0, 24, width(), 24);
00074        p.translate(-offset, 0);
00075        p.setBrush(black);
00076        p.setFont(font());
00077        p.setPen(QPen(black, 1, SolidLine, FlatCap, MiterJoin));
00078        for (xl = 0; xl < width()+offset; xl += iter)
00079        {
00080               if (xl < offset)
00081                      continue;
00082               p.drawLine(qRound(xl), 18, qRound(xl), 24);
00083        }
00084        for (xl = 0; xl < width()+(iter2/2)+offset; xl += iter2)
00085        {
00086               if (xl < offset)
00087                      continue;
00088               p.drawLine(qRound(xl), 11, qRound(xl), 24);
00089               switch (unitIndex)
00090               {
00091                      case 2:
00092                      {
00093                             QString tx = "";
00094                             int num1 = static_cast<int>(xl / iter2);
00095                             if (num1 != 0)
00096                                    tx = QString::number(num1);
00097                             double frac = (xl / iter2) - num1;
00098                             if ((frac > 0.24) && (frac < 0.26))
00099                                    tx += QChar(0xBC);
00100                             if ((frac > 0.49) && (frac < 0.51))
00101                                    tx += QChar(0xBD);
00102                             if ((frac > 0.74) && (frac < 0.76))
00103                                    tx += QChar(0xBE);
00104                             p.drawText(qRound(xl+2), 17, tx);
00105                             break;
00106                      }
00107                      case 3:
00108                             p.drawText(qRound(xl+2), 17, QString::number(xl / iter));
00109                             break;
00110                      default:
00111                             p.drawText(qRound(xl+2), 17, QString::number(xl / iter * 10));
00112                             break;
00113               }
00114        }
00115        if (tabValues.count() != 0)
00116        {
00117               for (int yg = 0; yg < static_cast<int>(tabValues.count()); yg++)
00118               {
00119                      if (yg == actTab)
00120                             p.setPen(QPen(red, 2, SolidLine, FlatCap, MiterJoin));
00121                      else
00122                             p.setPen(QPen(black, 2, SolidLine, FlatCap, MiterJoin));
00123                      switch (static_cast<int>(tabValues[yg].tabType))
00124                      {
00125                             case 0:
00126                                    p.drawLine(qRound(tabValues[yg].tabPosition), 15, qRound(tabValues[yg].tabPosition), 23);
00127                                    p.drawLine(qRound(tabValues[yg].tabPosition), 23, qRound(tabValues[yg].tabPosition+8), 23);
00128                                    break;
00129                             case 1:
00130                                    p.drawLine(qRound(tabValues[yg].tabPosition), 15, qRound(tabValues[yg].tabPosition), 23);
00131                                    p.drawLine(qRound(tabValues[yg].tabPosition), 23, qRound(tabValues[yg].tabPosition-8), 23);
00132                                    break;
00133                             case 2:
00134                             case 3:
00135                                    p.drawLine(qRound(tabValues[yg].tabPosition), 15, qRound(tabValues[yg].tabPosition), 23);
00136                                    p.drawLine(qRound(tabValues[yg].tabPosition-4), 23, qRound(tabValues[yg].tabPosition+4), 23);
00137                                    p.drawLine(qRound(tabValues[yg].tabPosition+3), 20, qRound(tabValues[yg].tabPosition+2), 20);
00138                                    break;
00139                             case 4:
00140                                    p.drawLine(qRound(tabValues[yg].tabPosition), 15, qRound(tabValues[yg].tabPosition), 23);
00141                                    p.drawLine(qRound(tabValues[yg].tabPosition-4), 23, qRound(tabValues[yg].tabPosition+4), 23);
00142                                    break;
00143                             default:
00144                                    break;
00145                      }
00146               }
00147        }
00148        if (haveInd)
00149        {
00150               p.setPen(QPen(blue, 1, SolidLine, FlatCap, MiterJoin));
00151               p.setBrush(blue);
00152               QPointArray cr;
00153               cr.setPoints(3, qRound(firstLine+leftIndent), 12, qRound(firstLine+leftIndent-4), 0, qRound(firstLine+leftIndent+4), 0);
00154               p.drawPolygon(cr);
00155               QPointArray cr2;
00156               cr2.setPoints(3, qRound(leftIndent), 12, qRound(leftIndent+4), 24, qRound(leftIndent-4), 24);
00157               p.drawPolygon(cr2);
00158        }
00159        p.end();
00160 }
00161 
00162 void RulerT::mousePressEvent(QMouseEvent *m)
00163 {
00164        QRect fpo;
00165        mousePressed = true;
00166        rulerCode = 0;
00167        if (haveInd)
00168        {
00169               fpo = QRect(static_cast<int>(firstLine+leftIndent-offset)-4, 0, 8, 12);
00170               if (fpo.contains(m->pos()))
00171               {
00172                      rulerCode = 1;
00173                      mouseX = m->x();
00174                      return;
00175               }
00176               fpo = QRect(static_cast<int>(leftIndent-offset)-4, 12, 8, 12);
00177               if (fpo.contains(m->pos()))
00178               {
00179                      rulerCode = 2;
00180                      mouseX = m->x();
00181                      return;
00182               }
00183        }
00184        if (tabValues.count() != 0)
00185        {
00186               for (int yg = 0; yg < static_cast<int>(tabValues.count()); yg++)
00187               {
00188                      fpo = QRect(static_cast<int>(tabValues[yg].tabPosition-offset)-3, 15, 8, 8);
00189                      if (fpo.contains(m->pos()))
00190                      {
00191                             rulerCode = 3;
00192                             actTab = yg;
00193                             mouseX = m->x();
00194                             emit tabSelected();
00195                             emit typeChanged(tabValues[actTab].tabType);
00196                             emit tabMoved(tabValues[actTab].tabPosition);
00197                             emit fillCharChanged(tabValues[actTab].tabFillChar);
00198                             repaint();
00199                             return;
00200                      }
00201               }
00202        }
00203        if ((rulerCode == 0) && (m->button() == LeftButton))
00204        {
00205               ParagraphStyle::TabRecord tb;
00206               tb.tabPosition = static_cast<double>(m->x() + offset);
00207               tb.tabType = 0;
00208               tb.tabFillChar = QChar();
00209               tabValues.prepend(tb);
00210               actTab = 0;
00211               rulerCode = 3;
00212               updateTabList();
00213               repaint();
00214               emit newTab();
00215               emit typeChanged(tabValues[actTab].tabType);
00216               emit tabMoved(tabValues[actTab].tabPosition);
00217               emit fillCharChanged(tabValues[actTab].tabFillChar);
00218               qApp->setOverrideCursor(QCursor(SizeHorCursor), true);
00219        }
00220        mouseX = m->x();
00221 }
00222 
00223 void RulerT::mouseReleaseEvent(QMouseEvent *m)
00224 {
00225        mousePressed = false;
00226        if ((m->y() < height()) && (m->y() > 0))
00227        {
00228               if (rulerCode == 3)
00229               {
00230                      if (m->button() == RightButton)
00231                      {
00232                             tabValues[actTab].tabType += 1;
00233                             if (tabValues[actTab].tabType > 4)
00234                                    tabValues[actTab].tabType = 0;
00235                             emit typeChanged(tabValues[actTab].tabType);
00236                             repaint();
00237                      }
00238               }
00239        }
00240        else
00241        {
00242               if (rulerCode == 3)
00243               {
00244                      QValueList<ParagraphStyle::TabRecord>::Iterator it;
00245                      it = tabValues.at(actTab);
00246                      tabValues.remove(it);
00247                      actTab = 0;
00248                      if (tabValues.count() != 0)
00249                      {
00250                             emit typeChanged(tabValues[actTab].tabType);
00251                             emit tabMoved(tabValues[actTab].tabPosition);
00252                             emit fillCharChanged(tabValues[actTab].tabFillChar);
00253                      }
00254                      else
00255                             emit noTabs();
00256                      repaint();
00257                      qApp->setOverrideCursor(QCursor(ArrowCursor), true);
00258               }
00259        }
00260        rulerCode = 0;
00261        emit mouseReleased();
00262 }
00263 
00264 void RulerT::mouseMoveEvent(QMouseEvent *m)
00265 {
00266        double oldInd;
00267        QRect fpo;
00268        if ((mousePressed) && (m->y() < height()) && (m->y() > 0) && (m->x() > 0) && (m->x() < width()))
00269        {
00270               qApp->setOverrideCursor(QCursor(SizeHorCursor), true);
00271               switch (rulerCode)
00272               {
00273                      case 1:
00274                             firstLine -= mouseX - m->x();
00275                             if (firstLine+leftIndent+offset < offset)
00276                                    firstLine += mouseX - m->x();
00277                             if (firstLine+leftIndent > Width)
00278                                    firstLine  = Width-leftIndent;
00279                             emit firstLineMoved(firstLine);
00280                             repaint();
00281                             break;
00282                      case 2:
00283                             oldInd = leftIndent+firstLine;
00284                             leftIndent -= mouseX - m->x();
00285                             if (leftIndent < 0)
00286                                    leftIndent = 0;
00287                             if (leftIndent > Width-1)
00288                                    leftIndent  = Width-1;
00289                             firstLine = oldInd - leftIndent;
00290                             emit leftIndentMoved(leftIndent);
00291                             emit firstLineMoved(firstLine);
00292                             repaint();
00293                             break;
00294                      case 3:
00295                             tabValues[actTab].tabPosition -= mouseX - m->x();
00296                             if (tabValues[actTab].tabPosition < 0)
00297                                    tabValues[actTab].tabPosition = 0;
00298                             if (tabValues[actTab].tabPosition > Width-1)
00299                                    tabValues[actTab].tabPosition = Width-1;
00300                             updateTabList();
00301                             emit tabMoved(tabValues[actTab].tabPosition);
00302                             repaint();
00303                             break;
00304                      default:
00305                             break;
00306               }
00307               mouseX = m->x();
00308               return;
00309        }
00310        if ((!mousePressed) && (m->y() < height()) && (m->y() > 0) && (m->x() > 0) && (m->x() < width()))
00311        {
00312               qApp->setOverrideCursor(QCursor(loadIcon("tab.png"), 3), true);
00313               if (haveInd)
00314               {
00315                      fpo = QRect(static_cast<int>(firstLine+leftIndent-offset)-4, 0, 8, 12);
00316                      if (fpo.contains(m->pos()))
00317                      {
00318                             qApp->setOverrideCursor(QCursor(SizeHorCursor), true);
00319                             return;
00320                      }
00321                      fpo = QRect(static_cast<int>(leftIndent-offset)-4, 12, 8, 12);
00322                      if (fpo.contains(m->pos()))
00323                      {
00324                             qApp->setOverrideCursor(QCursor(SizeHorCursor), true);
00325                             return;
00326                      }
00327               }
00328               if (tabValues.count() != 0)
00329               {
00330                      for (int yg = 0; yg < static_cast<int>(tabValues.count()); yg++)
00331                      {
00332                             fpo = QRect(static_cast<int>(tabValues[yg].tabPosition-offset)-3, 15, 8, 8);
00333                             if (fpo.contains(m->pos()))
00334                             {
00335                                    qApp->setOverrideCursor(QCursor(SizeHorCursor), true);
00336                                    return;
00337                             }
00338                      }
00339               }
00340        }
00341 }
00342 
00343 void RulerT::leaveEvent(QEvent*)
00344 {
00345        if ((mousePressed) && (rulerCode == 3))
00346        {
00347               qApp->setOverrideCursor(QCursor(loadIcon("DelPoint.png"), 1, 1), true);
00348               return;
00349        }
00350        else
00351               qApp->setOverrideCursor(QCursor(ArrowCursor), true);
00352 }
00353 
00354 void RulerT::updateTabList()
00355 {
00356        ParagraphStyle::TabRecord tb;
00357        tb.tabPosition = tabValues[actTab].tabPosition;
00358        tb.tabType = tabValues[actTab].tabType;
00359        tb.tabFillChar =  tabValues[actTab].tabFillChar;
00360        QValueList<ParagraphStyle::TabRecord>::Iterator it;
00361        int gg = static_cast<int>(tabValues.count()-1);
00362        int g = gg;
00363        it = tabValues.at(actTab);
00364        tabValues.remove(it);
00365        for (int yg = static_cast<int>(tabValues.count()); yg > -1; yg--)
00366        {
00367               if (tb.tabPosition < tabValues[yg].tabPosition)
00368                      g = yg;
00369        }
00370        actTab = g;
00371        if (gg == g)
00372        {
00373               tabValues.append(tb);
00374               actTab = static_cast<int>(tabValues.count()-1);
00375        }
00376        else
00377        {
00378               it = tabValues.at(actTab);
00379               tabValues.insert(it, tb);
00380        }
00381 }
00382 
00383 void RulerT::resetOffsetInc()
00384 {
00385        offsetIncrement = 5;
00386 }
00387 
00388 void RulerT::increaseOffset()
00389 {
00390        offset += offsetIncrement;
00391        offsetIncrement++;
00392        if (offsetIncrement > 30)
00393               offsetIncrement = 30;
00394        if (offset + width() > static_cast<int>(Width))
00395               offset -= 5;
00396        repaint();
00397 }
00398 
00399 void RulerT::decreaseOffset()
00400 {
00401        offset -= offsetIncrement;
00402        offsetIncrement++;
00403        if (offsetIncrement > 30)
00404               offsetIncrement = 30;
00405        if (offset < 0)
00406               offset = 0;
00407        repaint();
00408 }
00409 
00410 void RulerT::changeTab(int t)
00411 {
00412        tabValues[actTab].tabType = t;
00413        repaint();
00414 }
00415 
00416 void RulerT::changeTabChar(QChar t)
00417 {
00418        tabValues[actTab].tabFillChar = t;
00419        repaint();
00420 }
00421 
00422 void RulerT::moveTab(double t)
00423 {
00424        tabValues[actTab].tabPosition = t;
00425        updateTabList();
00426        repaint();
00427 }
00428 
00429 void RulerT::moveFirstLine(double t)
00430 {
00431        firstLine = t;
00432        if (firstLine+leftIndent+offset < offset)
00433        {
00434               firstLine = 0-leftIndent;
00435               emit firstLineMoved(firstLine);
00436        }
00437        if (firstLine+leftIndent > Width)
00438        {
00439               firstLine = Width-leftIndent;
00440               emit firstLineMoved(firstLine);
00441        }
00442        repaint();
00443 }
00444 
00445 void RulerT::moveLeftIndent(double t)
00446 {
00447        double oldInd = leftIndent+firstLine;
00448        leftIndent = t;
00449        if (leftIndent > Width-1)
00450        {
00451               leftIndent  = Width-1;
00452               emit leftIndentMoved(leftIndent);
00453        }
00454        firstLine = oldInd - leftIndent;
00455        emit firstLineMoved(firstLine);
00456        repaint();
00457 }
00458 
00459 Tabruler::Tabruler( QWidget* parent, bool haveFirst, int dEin, QValueList<ParagraphStyle::TabRecord> Tabs, double wid ) : QWidget( parent )
00460 {
00461        docUnitRatio=unitGetRatioFromIndex(dEin);
00462        double ww;
00463        ww = (wid < 0) ? 4000 : wid;
00464        setName( "tabruler" );
00465        tabrulerLayout = new QVBoxLayout( this, 0, 6, "tabrulerLayout");
00466        layout2 = new QHBoxLayout( 0, 0, 6, "layout2");
00467 
00468        rulerScrollL = new QToolButton( LeftArrow, this, "rulerScrollL" );
00469        rulerScrollL->setAutoRepeat( true );
00470        layout2->addWidget( rulerScrollL );
00471        ruler = new RulerT( this, dEin, Tabs, haveFirst, wid );
00472        ruler->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)7, (QSizePolicy::SizeType)5, 0, 0, ruler->sizePolicy().hasHeightForWidth() ) );
00473        layout2->addWidget( ruler );
00474        rulerScrollR = new QToolButton( RightArrow, this, "RulserScrollR" );
00475        rulerScrollR->setAutoRepeat( true );
00476        layout2->addWidget( rulerScrollR );
00477 
00478        layout1 = new QHBoxLayout( 0, 0, 6, "layout1" );
00479        layout1->setAlignment( Qt::AlignTop );
00480        TypeCombo = new QComboBox( false, this, "TypeCombo" );
00481        TypeCombo->clear();
00482        TypeCombo->insertItem( tr( "Left" ) );
00483        TypeCombo->insertItem( tr( "Right" ) );
00484        TypeCombo->insertItem( tr( "Full Stop" ) );
00485        TypeCombo->insertItem( tr( "Comma" ) );
00486        TypeCombo->insertItem( tr( "Center" ) );
00487        layout1->addWidget( TypeCombo );
00488        tabData = new MSpinBox( 0, ww / docUnitRatio, this, 1 );
00489        tabData->setValue(0);
00490        positionLabel = new QLabel( tabData, tr("&Position:"), this, "positionLabel" );
00491        layout1->addWidget( positionLabel );
00492        layout1->addWidget( tabData );
00493        tabFillCombo = new QComboBox( true, this, "tabFillCombo" );
00494        tabFillCombo->setEditable(false);
00495        tabFillCombo->insertItem( tr("None", "tab fill"));
00496        tabFillCombo->insertItem( tr("Dot"));
00497        tabFillCombo->insertItem( tr("Hyphen"));
00498        tabFillCombo->insertItem( tr("Underscore"));
00499        tabFillCombo->insertItem( tr("Custom"));
00500        tabFillComboT = new QLabel(tabFillCombo, tr( "Fill Char:" ), this, "tabFillComboT" );
00501        layout1->addWidget( tabFillComboT );
00502        layout1->addWidget( tabFillCombo );
00503 
00504        layout4 = new QHBoxLayout(0, 0, 6, "layout3");
00505 
00506        indentLayout = new QHBoxLayout(0, 0, 6, "indentLayout");
00507        if (haveFirst)
00508        {
00509               firstLineData = new MSpinBox( -3000, ww / docUnitRatio, this, 1);
00510               firstLineData->setValue(0);
00511               firstLineLabel = new QLabel( "", this, "firstLineLabel" );
00512               firstLineLabel->setText("");
00513               firstLineLabel->setPixmap(loadIcon("firstline.png"));
00514               indentLayout->addWidget( firstLineLabel );
00515               indentLayout->addWidget( firstLineData );
00516               leftIndentData = new MSpinBox( 0, ww / docUnitRatio, this, 1 );
00517               leftIndentData->setValue(0);
00518               leftIndentLabel = new QLabel( "", this, "leftIndentLabel" );
00519               leftIndentLabel->setText("");
00520               leftIndentLabel->setPixmap(loadIcon("leftindent.png"));
00521               layout4->addWidget( leftIndentLabel );
00522               layout4->addWidget( leftIndentData );
00523               layout4->addStretch(10);
00524               rightIndentLabel = new QLabel("", this, "rightIndentLabel");
00525               rightIndentLabel->setText("");
00526               rightIndentLabel->setPixmap(loadIcon("rightindent.png"));
00527               rightIndentData = new MSpinBox(0, ww / docUnitRatio, this, 1);
00528               rightIndentData->setValue(0);
00529               indentLayout->addWidget(rightIndentLabel);
00530               indentLayout->addWidget(rightIndentData);
00531        }
00532        clearButton = new QPushButton( this, "clearButton" );
00533        clearButton->setText( tr( "Delete All" ) );
00534        indentLayout->addSpacing(20);
00535        indentLayout->addWidget( clearButton);
00536        indentLayout->addStretch(10);
00537        if (!haveFirst)
00538        {
00539               QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
00540               layout1->addItem( spacer );
00541        }
00542        
00543        layout1->addStretch( 10 );
00544        tabrulerLayout->addLayout( layout1 );
00545        tabrulerLayout->addLayout( layout2 );
00546        indentLayout->addStretch( 10 );
00547        tabrulerLayout->addLayout( indentLayout );
00548        tabrulerLayout->addLayout(layout4);
00549 
00550        TypeCombo->setEnabled(false);
00551        tabData->setEnabled(false);
00552        tabFillCombo->setEnabled(false);
00553        if (Tabs.count() == 0)
00554               clearButton->setEnabled(false);
00555        resize( minimumSizeHint() );
00556        connect(rulerScrollL, SIGNAL(clicked()), ruler, SLOT(decreaseOffset()));
00557        connect(rulerScrollR, SIGNAL(clicked()), ruler, SLOT(increaseOffset()));
00558        connect(rulerScrollL, SIGNAL(released()), this, SLOT(resetOFfL()));
00559        connect(rulerScrollR, SIGNAL(released()), this, SLOT(resetOFfR()));
00560        connect(ruler, SIGNAL(typeChanged(int)) , this, SLOT(setTabType(int)));
00561        connect(ruler, SIGNAL(fillCharChanged(QChar)) , this, SLOT(setTabFillChar(QChar)));
00562        connect(TypeCombo, SIGNAL(activated(int)), this, SLOT(setType()));
00563        connect(tabFillCombo, SIGNAL(activated(int)), this, SLOT(setFillChar()));
00564        connect(tabFillCombo, SIGNAL(textChanged(const QString &)), this, SLOT(setCustomFillChar(const QString &)));
00565        connect(ruler, SIGNAL(tabMoved(double)) , this, SLOT(setTabData(double)));
00566        connect(ruler, SIGNAL(tabSelected()), this, SLOT(tabAdded()));
00567        connect(ruler, SIGNAL(newTab()), this, SLOT(tabAdded()));
00568        connect(ruler, SIGNAL(noTabs()), this, SLOT(lastTabRemoved()));
00569        connect(tabData, SIGNAL(valueChanged(int)), this, SLOT(setTab()));
00570        connect(clearButton, SIGNAL(clicked()), this, SLOT(clearAll()));
00571        QToolTip::add( tabFillCombo, tr( "Fill Character of Tab" ) );
00572        QToolTip::add( TypeCombo, tr( "Type/Orientation of Tab" ) );
00573        QToolTip::add( tabData, tr( "Position of Tab" ) );
00574        if (haveFirst)
00575        {
00576               connect(ruler, SIGNAL(firstLineMoved(double)) , this, SLOT(setFirstLineData(double)));
00577               connect(ruler, SIGNAL(leftIndentMoved(double)) , this, SLOT(setLeftIndentData(double)));
00578               connect(ruler, SIGNAL(mouseReleased()), this, SIGNAL(tabrulerChanged()));
00579               connect(ruler, SIGNAL(mouseReleased()), this, SLOT(slotMouseReleased()));
00580               connect(firstLineData, SIGNAL(valueChanged(int)), this, SLOT(setFirstLine()));
00581               connect(leftIndentData, SIGNAL(valueChanged(int)), this, SLOT(setLeftIndent()));
00582               connect(rightIndentData, SIGNAL(valueChanged(int)), this, SLOT(setRightIndent()));
00583               QToolTip::add( firstLineData, tr( "Indentation for first line of the paragraph" ) );
00584               QToolTip::add( leftIndentData, tr( "Indentation from the left for the whole paragraph" ) );
00585               QToolTip::add( rightIndentData, tr( "Indentation from the right for the whole paragraph" ) );
00586        }
00587        QToolTip::add( clearButton, tr( "Delete all Tabulators" ) );
00588        QString ein = unitGetSuffixFromIndex(dEin);
00589        if (dEin == 2)
00590        {
00591               if (haveFirst)
00592               {
00593                      firstLineData->setDecimals(10000);
00594                      leftIndentData->setDecimals(10000);
00595                      rightIndentData->setDecimals(10000);
00596               }
00597               tabData->setDecimals(10000);
00598        }
00599        if (haveFirst)
00600        {
00601               firstLineData->setSuffix(ein);
00602               leftIndentData->setSuffix(ein);
00603               rightIndentData->setSuffix(ein);
00604        }
00605        tabData->setSuffix(ein);
00606        haveF = haveFirst;
00607 }
00608 
00609 void Tabruler::setTabs(QValueList<ParagraphStyle::TabRecord> Tabs, int dEin)
00610 {
00611        docUnitRatio=unitGetRatioFromIndex(dEin);
00612        QString ein = unitGetSuffixFromIndex(dEin);
00613        tabData->setSuffix(ein);
00614        if (haveF)
00615        {
00616               firstLineData->setSuffix(ein);
00617               leftIndentData->setSuffix(ein);
00618               rightIndentData->setSuffix(ein);
00619        }
00620        ruler->setTabs(Tabs, dEin);
00621        if (Tabs.count() == 0)
00622               clearButton->setEnabled(false);
00623 }
00624 
00625 void Tabruler::resetOFfL()
00626 {
00627        if (!rulerScrollL->isDown())
00628               ruler->resetOffsetInc();
00629 }
00630 
00631 void Tabruler::resetOFfR()
00632 {
00633        if (!rulerScrollR->isDown())
00634               ruler->resetOffsetInc();
00635 }
00636 
00637 void Tabruler::clearAll()
00638 {
00639        ruler->tabValues.clear();
00640        ruler->repaint();
00641        lastTabRemoved();
00642        emit tabrulerChanged();
00643        emit tabsChanged();
00644 }
00645 
00646 void Tabruler::tabAdded()
00647 {
00648        TypeCombo->setEnabled(true);
00649        tabData->setEnabled(true);
00650        clearButton->setEnabled(true);
00651        tabFillCombo->setEnabled(true);
00652        emit tabrulerChanged();
00653        emit tabsChanged();
00654 }
00655 
00656 void Tabruler::lastTabRemoved()
00657 {
00658        TypeCombo->setEnabled(false);
00659        tabData->setEnabled(false);
00660        clearButton->setEnabled(false);
00661        tabFillCombo->setEnabled(false);
00662        emit tabrulerChanged();
00663        emit tabsChanged();
00664 }
00665 
00666 void Tabruler::setFillChar()
00667 {
00668        disconnect(tabFillCombo, SIGNAL(textChanged(const QString &)), this, SLOT(setCustomFillChar(const QString &)));
00669        disconnect(tabFillCombo, SIGNAL(activated(int)), this, SLOT(setFillChar()));
00670        QChar ret;
00671        switch (tabFillCombo->currentItem())
00672        {
00673               case 0:
00674                      tabFillCombo->setEditable(false);
00675                      ret = QChar();
00676                      break;
00677               case 1:
00678                      tabFillCombo->setEditable(false);
00679                      ret = '.';
00680                      break;
00681               case 2:
00682                      tabFillCombo->setEditable(false);
00683                      ret = '-';
00684                      break;
00685               case 3:
00686                      tabFillCombo->setEditable(false);
00687                      ret = '_';
00688                      break;
00689               case 4:
00690                      tabFillCombo->setEditable(true);
00691                      tabFillCombo->setEditText(CommonStrings::trCustomTabFill);
00692                      break;
00693        }
00694        if (tabFillCombo->currentItem() != 4)
00695               ruler->changeTabChar(ret);
00696        connect(tabFillCombo, SIGNAL(activated(int)), this, SLOT(setFillChar()));
00697        connect(tabFillCombo, SIGNAL(textChanged(const QString &)), this, SLOT(setCustomFillChar(const QString &)));
00698 }
00699 
00700 void Tabruler::setCustomFillChar(const QString &txt)
00701 {
00702        if (txt == CommonStrings::trCustomTabFill)
00703               return;
00704        disconnect(tabFillCombo, SIGNAL(textChanged(const QString &)), this, SLOT(setCustomFillChar(const QString &)));
00705        disconnect(tabFillCombo, SIGNAL(activated(int)), this, SLOT(setFillChar()));
00706        QChar ret = txt[txt.length()-1];
00707        ruler->changeTabChar(ret);
00708        connect(tabFillCombo, SIGNAL(activated(int)), this, SLOT(setFillChar()));
00709        connect(tabFillCombo, SIGNAL(textChanged(const QString &)), this, SLOT(setCustomFillChar(const QString &)));
00710 }
00711 
00712 void Tabruler::setTabFillChar(QChar t)
00713 {
00714        if (t.isNull())
00715        {
00716               tabFillCombo->setEditable(false);
00717               tabFillCombo->setCurrentItem(0);
00718        }
00719        else if (t == ".")
00720        {
00721               tabFillCombo->setEditable(false);
00722               tabFillCombo->setCurrentItem(1);
00723        }
00724        else if (t == "-")
00725        {
00726               tabFillCombo->setEditable(false);
00727               tabFillCombo->setCurrentItem(2);
00728        }
00729        else if (t == "_")
00730        {
00731               tabFillCombo->setEditable(false);
00732               tabFillCombo->setCurrentItem(3);
00733        }
00734        else
00735        {
00736               tabFillCombo->setCurrentItem(4);
00737               tabFillCombo->setEditable(true);
00738               tabFillCombo->setEditText(CommonStrings::trCustomTabFill+QString(t));
00739        }
00740        emit tabrulerChanged();
00741        emit tabsChanged();
00742 }
00743 
00744 void Tabruler::setTabType(int t)
00745 {
00746        TypeCombo->setCurrentItem(t);
00747        emit tabrulerChanged();
00748        emit tabsChanged();
00749 }
00750 
00751 void Tabruler::setType()
00752 {
00753        disconnect(TypeCombo, SIGNAL(activated(int)), this, SLOT(setType()));
00754        ruler->changeTab(TypeCombo->currentItem());
00755        connect(TypeCombo, SIGNAL(activated(int)), this, SLOT(setType()));
00756        emit tabrulerChanged();
00757        emit tabsChanged();
00758 }
00759 
00760 void Tabruler::setTabData(double t)
00761 {
00762        disconnect(tabData, SIGNAL(valueChanged(int)), this, SLOT(setTab()));
00763        tabData->setValue(t * docUnitRatio);
00764        connect(tabData, SIGNAL(valueChanged(int)), this, SLOT(setTab()));
00765        if (!ruler->mousePressed)
00766        {
00767               emit tabrulerChanged();
00768               emit tabsChanged();
00769        }
00770 }
00771 
00772 void Tabruler::setTab()
00773 {
00774        ruler->moveTab(tabData->value() / docUnitRatio);
00775        emit tabrulerChanged();
00776        emit tabsChanged();
00777 }
00778 
00779 void Tabruler::setFirstLineData(double t)
00780 {
00781        disconnect(firstLineData, SIGNAL(valueChanged(int)), this, SLOT(setFirstLine()));
00782        firstLineData->setValue(t * docUnitRatio);
00783        connect(firstLineData, SIGNAL(valueChanged(int)), this, SLOT(setFirstLine()));
00784        if (!ruler->mousePressed)
00785        {
00786               emit tabrulerChanged();
00787               double a, b, value;
00788               int c;
00789               firstLineData->getValues(&a, &b, &c, &value);
00790               emit firstLineChanged(value);
00791        }
00792 }
00793 
00794 void Tabruler::setFirstLine()
00795 {
00796        ruler->moveFirstLine(firstLineData->value() / docUnitRatio);
00797        emit tabrulerChanged();
00798        double a, b, value;
00799        int c;
00800        firstLineData->getValues(&a, &b, &c, &value);
00801        emit firstLineChanged(value);
00802 }
00803 
00804 void Tabruler::setLeftIndentData(double t)
00805 {
00806        disconnect(leftIndentData, SIGNAL(valueChanged(int)), this, SLOT(setLeftIndent()));
00807        leftIndentData->setValue(t * docUnitRatio);
00808        connect(leftIndentData, SIGNAL(valueChanged(int)), this, SLOT(setLeftIndent()));
00809        if (!ruler->mousePressed)
00810        {
00811               emit tabrulerChanged();
00812               double a, b, value;
00813               int c;
00814               leftIndentData->getValues(&a, &b, &c, &value);
00815               emit leftIndentChanged(value);
00816        }
00817 }
00818 
00819 void Tabruler::setLeftIndent()
00820 {
00821        ruler->moveLeftIndent(leftIndentData->value() / docUnitRatio);
00822        emit tabrulerChanged();
00823        double a, b, value;
00824        int c;
00825        leftIndentData->getValues(&a, &b, &c, &value);
00826        emit leftIndentChanged(value);
00827 }
00828 
00829 QValueList<ParagraphStyle::TabRecord> Tabruler::getTabVals()
00830 {
00831        return ruler->tabValues;
00832 }
00833 
00834 double Tabruler::getFirstLine()
00835 {
00836        return firstLineData->value() / docUnitRatio;
00837 }
00838 
00839 double Tabruler::getLeftIndent()
00840 {
00841        return leftIndentData->value() / docUnitRatio;
00842 }
00843 
00844 void Tabruler::setRightIndentData(double t)
00845 {
00846        disconnect(rightIndentData, SIGNAL(valueChanged(int)), this, SLOT(setRightIndent()));
00847        rightIndentData->setValue(t * docUnitRatio);
00848        connect(rightIndentData, SIGNAL(valueChanged(int)), this, SLOT(setRightIndent()));
00849        if (!ruler->mousePressed)
00850        {
00851               emit tabrulerChanged();
00852               double a, b, value;
00853               int c;
00854               rightIndentData->getValues(&a, &b, &c, &value);
00855               emit rightIndentChanged(value);
00856        }
00857 }
00858 
00859 void Tabruler::setRightIndent()
00860 {
00861        emit tabrulerChanged();
00862        double a, b, value;
00863        int c;
00864        rightIndentData->getValues(&a, &b, &c, &value);
00865        emit rightIndentChanged(value);
00866 }
00867 
00868 double Tabruler::getRightIndent()
00869 {
00870        return rightIndentData->value() / docUnitRatio;
00871 }
00872 
00873 void Tabruler::slotMouseReleased()
00874 {
00875        emit mouseReleased();
00876 }