26#include <tdeglobalsettings.h>
28#include <kiconloader.h>
31#include <tqpopupmenu.h>
33#include <KoPageLayout.h>
44 bool whileMovingBorderLeft, whileMovingBorderRight;
45 bool whileMovingBorderTop, whileMovingBorderBottom;
46 TQPixmap pmFirst, pmLeft;
48 KoTabChooser *tabChooser;
49 KoTabulatorList tabList;
57 int mRemoveTab, mPageLayout;
61 bool doubleClickedIndent;
67static inline bool equals(
double a,
double b ) {
68 return kAbs( a - b ) < 1E-4;
76const int KoRuler::F_TABS = 1;
77const int KoRuler::F_INDENTS = 2;
78const int KoRuler::F_HELPLINES = 4;
79const int KoRuler::F_NORESIZE = 8;
84 : TQFrame( _parent ), buffer( width(), height() ), m_zoom(1.0), m_1_zoom(1.0),
87 setWFlags( WResizeNoErase | WRepaintNoErase );
88 setFrameStyle( MenuBarPanel );
90 d=
new KoRulerPrivate();
92 d->tabChooser = _tabChooser;
95 orientation = _orientation;
100 d->doubleClickedIndent=
false;
107 setMouseTracking(
true );
108 d->mousePressed =
false;
120 d->whileMovingBorderLeft = d->whileMovingBorderRight = d->whileMovingBorderTop = d->whileMovingBorderBottom =
false;
122 d->pmFirst = UserIcon(
"koRulerFirst" );
123 d->pmLeft = UserIcon(
"koRulerLeft" );
124 d->currTab.type = T_INVALID;
126 d->removeTab.type = T_INVALID;
127 if ( orientation == TQt::Horizontal ) {
128 frameStart = tqRound( zoomIt(d->layout.ptLeft) );
129 d->frameEnd = tqRound( zoomIt(d->layout.ptWidth - d->layout.ptRight) );
131 frameStart = tqRound( zoomIt(d->layout.ptTop) );
132 d->frameEnd = tqRound( zoomIt(d->layout.ptHeight - d->layout.ptBottom) );
134 m_bFrameStartSet =
false;
151 d->rb_menu->setItemEnabled(d->mPageLayout, b);
157 if ( !showMPos || ( mx == mposX && my == mposY ) )
return;
160 p.setRasterOp( TQt::NotROP );
162 if ( orientation == TQt::Horizontal ) {
164 p.drawLine( mposX, 1, mposX, height() - 1 );
165 p.drawLine( mx, 1, mx, height() - 1 );
170 p.drawLine( 1, mposY, width() - 1, mposY );
171 p.drawLine( 1, my, width() - 1, my );
181double KoRuler::lineDistance()
const
185 return INCH_TO_POINT( m_zoom );
187 return 100.0 * m_zoom;
191 return CM_TO_POINT ( m_zoom );
193 return PI_TO_POINT ( 10.0 * m_zoom );
195 return DD_TO_POINT( m_zoom );
197 return CC_TO_POINT( 10.0 * m_zoom );
200 return 100.0 * m_zoom;
204void KoRuler::drawHorizontal( TQPainter *_painter )
206 TQFont font = TDEGlobalSettings::toolBarFont();
207 TQFontMetrics fm( font );
208 resize( width(), TQMAX( fm.height() + 4, 20 ) );
211 TQPainter p( &buffer );
212 p.fillRect( 0, 0, width(), height(), TQBrush( colorGroup().brush( TQColorGroup::Background ) ) );
214 int totalw = tqRound( zoomIt(d->layout.ptWidth) );
217 p.setBrush( colorGroup().brush( TQColorGroup::Base ) );
221 if ( !d->whileMovingBorderLeft )
222 r.setLeft( -diffx + frameStart );
224 r.setLeft( d->oldMx );
226 if ( !d->whileMovingBorderRight )
227 r.setWidth(d->frameEnd-frameStart);
229 r.setRight( d->oldMx );
230 r.setBottom( height() );
236 double dist = lineDistance();
239 for (
double i = 0.0;i <= (double)totalw;i += dist ) {
241 int textwidth = fm.width( str );
242 maxwidth = TQMAX( maxwidth, textwidth );
246 while( dist <= maxwidth ) {
247 dist += lineDistance();
250 for (
double i = 0.0;i <= (double)totalw;i += dist ) {
252 int textwidth = fm.width( str );
253 maxwidth = TQMAX( maxwidth, textwidth );
254 p.drawText( tqRound(i) - diffx - tqRound(textwidth * 0.5),
255 tqRound(( height() - fm.height() ) * 0.5),
256 textwidth, height(), AlignLeft | AlignTop, str );
261 if ( dist > maxwidth + 2 )
263 for (
double i = dist * 0.5;i <= (double)totalw;i += dist ) {
265 p.drawLine( ii - diffx, 7, ii - diffx, height() - 7 );
271 if ( dist * 0.5 > maxwidth + 2 )
273 for (
double i = dist * 0.25;i <= (double)totalw;i += dist * 0.5 ) {
275 p.drawLine( ii - diffx, 9, ii - diffx, height() - 9 );
292 if ( d->flags & F_INDENTS ) {
294 double halfPixmapWidth = d->pmFirst.width() * 0.5;
296 double firstLineIdent = i_first + ( d->rtl ? d->i_right : i_left );
297 p.drawPixmap( tqRound(
static_cast<double>(r.left()) + applyRtlAndZoom( firstLineIdent ) - halfPixmapWidth ),
300 int bottom = height() - d->pmLeft.height() - 1;
301 halfPixmapWidth = d->pmLeft.width() * 0.5;
302 p.drawPixmap( tqRound(
static_cast<double>(r.left()) + zoomIt(i_left) - halfPixmapWidth ),
304 p.drawPixmap( tqRound(
static_cast<double>(r.right()) - zoomIt(d->i_right) - halfPixmapWidth ),
309 if ( d->action == A_NONE && showMPos ) {
310 p.setPen( colorGroup().color( TQColorGroup::Text ) );
311 p.drawLine( mposX, 1, mposX, height() - 1 );
316 if ( d->tabChooser && ( d->flags & F_TABS ) && !d->tabList.isEmpty() )
320 _painter->drawPixmap( 0, 0, buffer );
324void KoRuler::drawTabs( TQPainter &_painter )
328 _painter.setPen( TQPen( colorGroup().color( TQColorGroup::Text ), 2, SolidLine ) );
331 bool willRemove = d->mousePressed && willRemoveTab( d->oldMy ) && d->currTab.type != T_INVALID;
333 KoTabulatorList::ConstIterator it = d->tabList.begin();
334 for ( ; it != d->tabList.end() ; it++ ) {
335 if ( willRemove && equals( d->currTab.ptPos, (*it).ptPos ) )
337 ptPos = tqRound(applyRtlAndZoom((*it).ptPos)) - diffx + frameStart;
338 switch ( (*it).type ) {
341 _painter.drawLine( ptPos + 4, height() - 4, ptPos + 20 - 4, height() - 4 );
342 _painter.drawLine( ptPos + 5, 4, ptPos + 5, height() - 4 );
346 _painter.drawLine( ptPos + 4, height() - 4, ptPos + 20 - 4, height() - 4 );
347 _painter.drawLine( ptPos + 20 / 2, 4, ptPos + 20 / 2, height() - 4 );
351 _painter.drawLine( ptPos + 4, height() - 4, ptPos + 20 - 4, height() - 4 );
352 _painter.drawLine( ptPos + 20 - 5, 4, ptPos + 20 - 5, height() - 4 );
356 _painter.drawLine( ptPos + 4, height() - 4, ptPos + 20 - 4, height() - 4 );
357 _painter.drawLine( ptPos + 20 / 2, 4, ptPos + 20 / 2, height() - 4 );
358 _painter.fillRect( ptPos + 20 / 2 + 2, height() - 9, 3, 3,
359 colorGroup().color( TQColorGroup::Text ) );
367void KoRuler::drawVertical( TQPainter *_painter )
369 TQFont font = TDEGlobalSettings::toolBarFont();
370 TQFontMetrics fm( font );
371 resize( TQMAX( fm.height() + 4, 20 ), height() );
373 TQPainter p( &buffer );
374 p.fillRect( 0, 0, width(), height(), TQBrush( colorGroup().brush( TQColorGroup::Background ) ) );
376 int totalh = tqRound( zoomIt(d->layout.ptHeight) );
378 TQRect paintRect = _painter->clipRegion( TQPainter::CoordPainter ).boundingRect();
380 TQRect rulerRect( 0, -diffy, width(), totalh );
382 if ( paintRect.intersects( rulerRect ) ) {
385 p.setBrush( colorGroup().brush( TQColorGroup::Base ) );
389 if ( !d->whileMovingBorderTop )
390 r.setTop( -diffy + frameStart );
392 r.setTop( d->oldMy );
394 if ( !d->whileMovingBorderBottom )
395 r.setHeight(d->frameEnd-frameStart);
397 r.setBottom( d->oldMy );
398 r.setRight( width() );
404 double dist = lineDistance();
407 for (
double i = 0.0;i <= (double)totalh;i += dist ) {
409 int textwidth = fm.width( str );
410 maxheight = TQMAX( maxheight, textwidth );
414 while( dist <= maxheight ) {
415 dist += lineDistance();
418 for (
double i = 0.0;i <= (double)totalh;i += dist ) {
420 int textwidth = fm.width( str );
421 int yOffset = tqRound(i) - diffy + tqRound(textwidth * 0.5);
422 if(yOffset > paintRect.bottom())
424 int textheight = fm.height();
425 maxheight = TQMAX( maxheight, textwidth );
427 p.translate( tqRound(( width() - textheight ) * 0.5), yOffset);
429 p.drawText( 0, 0, textwidth + 1, textheight, AlignLeft | AlignTop, str );
434 if ( dist > maxheight + 2 )
436 for (
double i = dist * 0.5;i <= (double)totalh;i += dist ) {
437 int ii=tqRound(i) - diffy;
438 if(ii > paintRect.bottom())
440 p.drawLine( 7, ii, width() - 7, ii);
445 if ( dist * 0.5 > maxheight + 2 )
447 for (
double i = dist * 0.25;i <=(double)totalh;i += dist *0.5 ) {
448 int ii=tqRound(i) - diffy;
449 if(ii > paintRect.bottom())
451 p.drawLine( 9, ii, width() - 9, ii);
468 if ( d->action == A_NONE && showMPos ) {
469 p.setPen( colorGroup().color( TQColorGroup::Text ) );
470 p.drawLine( 1, mposY, width() - 1, mposY );
475 _painter->drawPixmap( 0, 0, buffer );
478void KoRuler::mousePressEvent( TQMouseEvent *e )
480 if( !d->m_bReadWrite)
485 d->mousePressed =
true;
486 d->removeTab.type = T_INVALID;
488 switch ( e->button() ) {
489 case TQt::RightButton:
490 if(d->currTab.type == T_INVALID || !(d->flags & F_TABS))
491 d->rb_menu->setItemEnabled(d->mRemoveTab,
false);
493 d->rb_menu->setItemEnabled(d->mRemoveTab,
true);
494 d->rb_menu->popup( TQCursor::pos() );
496 d->mousePressed =
false;
502 case TQt::LeftButton:
503 if ( d->action == A_BR_RIGHT || d->action == A_BR_LEFT ) {
504 if ( d->action == A_BR_RIGHT )
505 d->whileMovingBorderRight =
true;
507 d->whileMovingBorderLeft =
true;
510 drawLine(d->oldMx, -1);
512 }
else if ( d->action == A_BR_TOP || d->action == A_BR_BOTTOM ) {
513 if ( d->action == A_BR_TOP )
514 d->whileMovingBorderTop =
true;
516 d->whileMovingBorderBottom =
true;
519 TQPainter p( d->canvas );
520 p.setRasterOp( TQt::NotROP );
521 p.drawLine( 0, d->oldMy, d->canvas->width(), d->oldMy );
525 }
else if ( d->action == A_FIRST_INDENT || d->action == A_LEFT_INDENT || d->action == A_RIGHT_INDENT ) {
527 drawLine(d->oldMx, -1);
528 }
else if ( d->action == A_TAB ) {
529 if ( d->canvas && d->currTab.type != T_INVALID ) {
530 drawLine( tqRound( applyRtlAndZoom(d->currTab.ptPos) ) + frameStart - diffx, -1 );
532 }
else if ( d->tabChooser && ( d->flags & F_TABS ) && d->tabChooser->getCurrTabType() != 0 ) {
533 int left = frameStart - diffx;
534 int right = d->frameEnd - diffx;
536 if( e->x()-left < 0 || right-e->x() < 0 )
541 switch ( d->tabChooser->getCurrTabType() ) {
542 case KoTabChooser::TAB_LEFT:
545 case KoTabChooser::TAB_CENTER:
548 case KoTabChooser::TAB_RIGHT:
551 case KoTabChooser::TAB_DEC_PNT:
552 tab.
type = T_DEC_PNT;
553 tab.
alignChar = TDEGlobal::locale()->decimalSymbol()[0];
557 tab.
ptPos = unZoomItRtl( e->x() + diffx - frameStart );
559 KoTabulatorList::Iterator it=d->tabList.begin();
560 while ( it!=d->tabList.end() && tab > (*it) )
563 d->tabList.insert(it, tab);
569 emit tabListChanged( d->tabList );
572 else if ( d->flags & F_HELPLINES )
574 setCursor( orientation == TQt::Horizontal ?
575 TQt::sizeVerCursor : TQt::sizeHorCursor );
576 d->action = A_HELPLINES;
583void KoRuler::mouseReleaseEvent( TQMouseEvent *e )
585 d->mousePressed =
false;
588 bool fakeMovement=
false;
589 if(d->removeTab.type != T_INVALID) {
594 if ( d->action == A_BR_RIGHT || d->action == A_BR_LEFT ) {
595 d->whileMovingBorderRight =
false;
596 d->whileMovingBorderLeft =
false;
599 drawLine(d->oldMx, -1);
601 emit newPageLayout( d->layout );
602 }
else if ( d->action == A_BR_TOP || d->action == A_BR_BOTTOM ) {
603 d->whileMovingBorderTop =
false;
604 d->whileMovingBorderBottom =
false;
607 TQPainter p( d->canvas );
608 p.setRasterOp( TQt::NotROP );
609 p.drawLine( 0, d->oldMy, d->canvas->width(), d->oldMy );
613 emit newPageLayout( d->layout );
614 }
else if ( d->action == A_FIRST_INDENT ) {
616 drawLine(d->oldMx, -1);
618 emit newFirstIndent( i_first );
619 }
else if ( d->action == A_LEFT_INDENT ) {
621 drawLine(d->oldMx, -1);
623 emit newLeftIndent( i_left );
624 }
else if ( d->action == A_RIGHT_INDENT ) {
626 drawLine(d->oldMx, -1);
628 emit newRightIndent( d->i_right );
629 }
else if ( d->action == A_TAB ) {
630 if ( d->canvas && !fakeMovement ) {
631 drawLine( tqRound( applyRtlAndZoom( d->currTab.ptPos ) ) + frameStart - diffx, -1);
633 if ( willRemoveTab( e->y() ) )
635 d->tabList.remove(d->currTab);
637 qHeapSort( d->tabList );
640 KoTabulatorList::ConstIterator tmpTab=d->tabList.begin();
642 while(tmpTab!=d->tabList.end()) {
643 if( equals( (*tmpTab).ptPos, d->currTab.ptPos ) ) {
646 d->tabList.remove(d->currTab);
653 emit tabListChanged( d->tabList );
656 else if( d->action == A_HELPLINES )
658 emit addGuide( e->pos(), orientation == TQt::Horizontal, orientation == TQt::Horizontal ? size().height() : size().width() );
659 emit addHelpline( e->pos(), orientation == TQt::Horizontal);
660 setCursor( ArrowCursor );
662 d->currTab.type = T_INVALID;
665void KoRuler::mouseMoveEvent( TQMouseEvent *e )
669 int pw = d->frameEnd - frameStart;
670 int ph = tqRound(zoomIt(d->layout.ptHeight));
671 int left = frameStart - diffx;
672 int top = tqRound(zoomIt(d->layout.ptTop));
674 int right = d->frameEnd - diffx;
675 int bottom = tqRound(zoomIt(d->layout.ptBottom));
676 bottom = ph - bottom - diffy;
678 int ip_first = tqRound( zoomIt( i_first + ( d->rtl ? d->i_right : i_left) ) );
679 int ip_left = tqRound(zoomIt(i_left));
680 int ip_right = tqRound(zoomIt(d->i_right));
683 mx = mx+diffx < 0 ? 0 : mx;
685 my = my+diffy < 0 ? 0 : my;
687 TQToolTip::remove(
this);
688 switch ( orientation ) {
689 case TQt::Horizontal: {
690 if ( !d->mousePressed ) {
691 setCursor( ArrowCursor );
704 if ( !m_bFrameStartSet )
706 if ( mx > left - 5 && mx < left + 5 ) {
707 setCursor( TQt::sizeHorCursor );
708 d->action = A_BR_LEFT;
709 }
else if ( mx > right - 5 && mx < right + 5 ) {
710 setCursor( TQt::sizeHorCursor );
711 d->action = A_BR_RIGHT;
714 if ( d->flags & F_INDENTS ) {
715 int firstX = d->rtl ? right - ip_first : left + ip_first;
716 if ( mx > firstX - 5 && mx < firstX + 5 &&
717 my >= 2 && my <= d->pmFirst.size().height() + 2 ) {
718 TQToolTip::add(
this, i18n(
"First line indent") );
719 setCursor( ArrowCursor );
720 d->action = A_FIRST_INDENT;
721 }
else if ( mx > left + ip_left - 5 && mx < left + ip_left + 5 &&
722 my >= height() - d->pmLeft.size().height() - 2 && my <= height() - 2 ) {
723 TQToolTip::add(
this, i18n(
"Left indent") );
724 setCursor( ArrowCursor );
725 d->action = A_LEFT_INDENT;
726 }
else if ( mx > right - ip_right - 5 && mx < right - ip_right + 5 &&
727 my >= height() - d->pmLeft.size().height() - 2 && my <= height() - 2 ) {
728 TQToolTip::add(
this, i18n(
"Right indent") );
729 setCursor( ArrowCursor );
730 d->action = A_RIGHT_INDENT;
733 if ( d->flags & F_TABS )
738 if( newPos!=right && gridSize!=0.0 && (e->state() & ShiftButton)==0) {
739 double grid=zoomIt(gridSize * 16);
740 newPos=tqRound( ((newPos * 16 / grid) * grid) / 16 );
742 if(newPos-left < 0) newPos=left;
743 else if (right-newPos < 0) newPos=right;
744 double newValue = unZoomIt(
static_cast<double>(newPos) - frameStart + diffx);
746 switch ( d->action ) {
748 if ( d->canvas && mx < right-10 && mx+diffx-2 > 0) {
749 drawLine( d->oldMx, mx );
750 d->layout.ptLeft = unZoomIt(
static_cast<double>(mx + diffx));
751 if( ip_left > right-left-15 ) {
752 ip_left=right-left-15;
753 ip_left=ip_left<0 ? 0 : ip_left;
754 i_left=unZoomIt( ip_left );
755 emit newLeftIndent( i_left );
757 if ( ip_right > right-left-15 ) {
758 ip_right=right-left-15;
759 ip_right=ip_right<0? 0 : ip_right;
760 d->i_right=unZoomIt( ip_right );
761 emit newRightIndent( d->i_right );
771 if ( d->canvas && mx > left+10 && mx+diffx <= pw-2) {
772 drawLine( d->oldMx, mx );
773 d->layout.ptRight = unZoomIt(
static_cast<double>(pw - ( mx + diffx )));
774 if( ip_left > right-left-15 ) {
775 ip_left=right-left-15;
776 ip_left=ip_left<0 ? 0 : ip_left;
777 i_left=unZoomIt( ip_left );
778 emit newLeftIndent( i_left );
780 if ( ip_right > right-left-15 ) {
781 ip_right=right-left-15;
782 ip_right=ip_right<0? 0 : ip_right;
783 d->i_right=unZoomIt( ip_right );
784 emit newRightIndent( d->i_right );
793 case A_FIRST_INDENT: {
796 newValue = unZoomIt(pw) - newValue - d->i_right;
799 if(newValue == i_first)
break;
800 drawLine( d->oldMx, newPos);
806 case A_LEFT_INDENT: {
809 if(newValue == i_left)
break;
811 drawLine( d->oldMx, newPos);
817 case A_RIGHT_INDENT: {
819 double rightValue = unZoomIt(right - newPos);
821 if(rightValue == d->i_right)
break;
823 drawLine( d->oldMx, newPos);
824 d->i_right=rightValue;
831 if (d->rtl) newValue = unZoomIt(pw) - newValue;
832 if(newValue == d->currTab.ptPos)
break;
833 TQPainter p( d->canvas );
834 p.setRasterOp( TQt::NotROP );
839 if( d->currTab != d->removeTab )
841 pt = applyRtlAndZoom(d->currTab.ptPos);
842 pt_fr = tqRound(pt) + frameStart - diffx;
843 p.drawLine( pt_fr, 0, pt_fr, d->canvas->height() );
846 KoTabulatorList::Iterator it = d->tabList.find( d->currTab );
847 Q_ASSERT( it != d->tabList.end() );
848 if ( it != d->tabList.end() )
849 (*it).ptPos = newValue;
850 d->currTab.ptPos = newValue;
852 pt = applyRtlAndZoom( newValue );
853 pt_fr = tqRound(pt) + frameStart - diffx;
854 p.drawLine( pt_fr, 0, pt_fr, d->canvas->height() );
859 d->removeTab.type = T_INVALID;
866 if( d->action == A_HELPLINES )
868 emit moveGuide( e->pos(),
true, size().height() );
869 emit moveHelpLines( e->pos(),
true );
874 case TQt::Vertical: {
875 if ( !d->mousePressed ) {
876 setCursor( ArrowCursor );
878 if ( d->flags & F_NORESIZE )
880 if ( my > top - 5 && my < top + 5 ) {
881 TQToolTip::add(
this, i18n(
"Top margin") );
882 setCursor( TQt::sizeVerCursor );
883 d->action = A_BR_TOP;
884 }
else if ( my > bottom - 5 && my < bottom + 5 ) {
885 TQToolTip::add(
this, i18n(
"Bottom margin") );
886 setCursor( TQt::sizeVerCursor );
887 d->action = A_BR_BOTTOM;
890 switch ( d->action ) {
892 if ( d->canvas && my < bottom-20 && my+diffy-2 > 0) {
893 TQPainter p( d->canvas );
894 p.setRasterOp( TQt::NotROP );
895 p.drawLine( 0, d->oldMy, d->canvas->width(), d->oldMy );
896 p.drawLine( 0, my, d->canvas->width(), my );
898 d->layout.ptTop = unZoomIt(
static_cast<double>(my + diffy));
907 if ( d->canvas && my > top+20 && my+diffy < ph-2) {
908 TQPainter p( d->canvas );
909 p.setRasterOp( TQt::NotROP );
910 p.drawLine( 0, d->oldMy, d->canvas->width(), d->oldMy );
911 p.drawLine( 0, my, d->canvas->width(), my );
913 d->layout.ptBottom = unZoomIt(
static_cast<double>(ph - ( my + diffy )));
925 if( d->action == A_HELPLINES )
927 emit moveGuide( e->pos(),
false, size().width() );
928 emit moveHelpLines( e->pos(),
false );
937void KoRuler::resizeEvent( TQResizeEvent *e )
939 TQFrame::resizeEvent( e );
940 buffer.resize( size() );
943void KoRuler::mouseDoubleClickEvent( TQMouseEvent* )
948void KoRuler::handleDoubleClick()
950 if ( !d->m_bReadWrite )
953 d->doubleClickedIndent =
false;
954 if ( d->tabChooser && ( d->flags & F_TABS ) ) {
956 if ( d->tabChooser->getCurrTabType() != 0 && d->removeTab.type != T_INVALID && !d->tabList.isEmpty()) {
957 uint c = d->tabList.count();
958 d->tabList.remove( d->removeTab );
959 Q_ASSERT( d->tabList.count() < c );
961 d->removeTab.type = T_INVALID;
962 d->currTab.type = T_INVALID;
963 emit tabListChanged( d->tabList );
964 setCursor( ArrowCursor );
967 }
else if ( d->action == A_TAB ) {
977 if ( d->flags & F_INDENTS ) {
978 if ( d->action == A_LEFT_INDENT || d->action == A_RIGHT_INDENT || d->action == A_FIRST_INDENT ) {
979 d->doubleClickedIndent =
true;
992 d->tabList = _tabList;
993 qHeapSort(d->tabList);
1001double KoRuler::makeIntern(
double _v )
1006void KoRuler::setupMenu()
1008 d->rb_menu =
new TQPopupMenu();
1009 TQ_CHECK_PTR( d->rb_menu );
1010 for ( uint i = 0 ; i <= KoUnit::U_LASTUNIT ; ++i )
1014 if ( m_unit == unit )
1015 d->rb_menu->setItemChecked( i,
true );
1017 connect( d->rb_menu, TQ_SIGNAL( activated(
int ) ), TQ_SLOT( slotMenuActivated(
int ) ) );
1019 d->rb_menu->insertSeparator();
1020 d->mPageLayout=d->rb_menu->insertItem(i18n(
"Page Layout..."),
this, TQ_SLOT(pageLayoutDia()));
1021 d->rb_menu->insertSeparator();
1022 d->mRemoveTab=d->rb_menu->insertItem(i18n(
"Remove Tabulator"),
this, TQ_SLOT(rbRemoveTab()));
1023 d->rb_menu->setItemEnabled( d->mRemoveTab,
false );
1026void KoRuler::uncheckMenu()
1028 for ( uint i = 0 ; i <= KoUnit::U_LASTUNIT ; ++i )
1029 d->rb_menu->setItemChecked( i,
false );
1041 d->rb_menu->setItemChecked( m_unit,
true );
1056bool KoRuler::willRemoveTab(
int y )
const
1058 return (y < -50 || y > height() + 25) && d->currTab.type != T_INVALID;
1061void KoRuler::rbRemoveTab() {
1063 d->tabList.remove( d->currTab );
1064 d->currTab.type = T_INVALID;
1065 emit tabListChanged( d->tabList );
1071 d->m_bReadWrite=_readWrite;
1074void KoRuler::searchTab(
int mx) {
1077 d->currTab.type = T_INVALID;
1078 KoTabulatorList::ConstIterator it = d->tabList.begin();
1079 for ( ; it != d->tabList.end() ; ++it ) {
1080 pos = tqRound(applyRtlAndZoom((*it).ptPos)) - diffx + frameStart;
1081 if ( mx > pos - 5 && mx < pos + 5 ) {
1082 setCursor( TQt::sizeHorCursor );
1090void KoRuler::drawLine(
int oldX,
int newX) {
1092 TQPainter p( d->canvas );
1093 p.setRasterOp( TQt::NotROP );
1094 p.drawLine( oldX, 0, oldX, d->canvas->height() );
1096 p.drawLine( newX, 0, newX, d->canvas->height() );
1102 showMPos = _showMPos;
1103 hasToDelete =
false;
1119 if ( _frameStart != frameStart || _frameEnd != d->frameEnd || !m_bFrameStartSet )
1121 frameStart = _frameStart;
1122 d->frameEnd = _frameEnd;
1125 m_bFrameStartSet =
true;
1132 d->i_right = makeIntern( _right );
1154 return d->doubleClickedIndent;
1157double KoRuler::applyRtlAndZoom(
double value )
const
1159 int frameWidth = d->frameEnd - frameStart;
1160 return d->rtl ? ( frameWidth - zoomIt( value ) ) : zoomIt( value );
1163double KoRuler::unZoomItRtl(
int pixValue )
const
1165 int frameWidth = d->frameEnd - frameStart;
1166 return d->rtl ? ( unZoomIt( (
double)(frameWidth - pixValue) ) ) : unZoomIt( (double)pixValue );
1169void KoRuler::slotMenuActivated(
int i )
1171 if ( i >= 0 && i <= KoUnit::U_LASTUNIT )
1175 emit unitChanged( unit );
1182 TQFont font = TDEGlobalSettings::toolBarFont();
1183 TQFontMetrics fm( font );
1185 size.setWidth( TQMAX( fm.height() + 4, 20 ) );
1186 size.setHeight( TQMAX( fm.height() + 4, 20 ) );
1198 d->layout = _layout;
1202#include "KoRuler.moc"
void changeFlags(int _flags)
Change the flag (i.e.
virtual TQSize sizeHint() const
Reimplemented from TQWidget.
void doubleClicked()
This signal is emitted when double-clicking the ruler (or an indent)
virtual TQSize minimumSizeHint() const
Reimplemented from TQWidget.
bool doubleClickedIndent() const
void setReadWrite(bool _readWrite)
KoRuler is in "read write" mode by default.
void setPageLayout(const KoPageLayout &_layout)
Set the page layout, see KoPageLayout.
void setTabList(const KoTabulatorList &tabList)
Set the list of tabulators to show in the ruler.
void setMousePos(int mx, int my)
Set the position of the mouse, to update the indication in the ruler.
void setRightIndent(double _right)
Set the [paragraph] right indent to the specified position (in the current unit)
void setUnit(const TQString &unit) TDE_DEPRECATED
Set the unit to be used.
void setDirection(bool rtl)
Set the [paragraph] direction.
KoRuler(TQWidget *_parent, TQWidget *_canvas, TQt::Orientation _orientation, const KoPageLayout &_layout, int _flags, KoUnit::Unit _unit, KoTabChooser *_tabChooser=0L)
Create a ruler TODO document params.
void setZoom(const double &zoom=1.0)
Set the zoom of the ruler (default value of 1.0 is 100%)
void openPageLayoutDia()
Old signal, kept for compatibility.
const double & zoom() const
void showMousePos(bool _showMPos)
Call showMousePos(true) if the ruler should indicate the position of the mouse.
void setPageLayoutMenuItemEnabled(bool b)
Enable or disable the "Page Layout" menu item.
void setFrameStartEnd(int _frameStart, int _frameEnd)
Set the start and the end of the current 'frame', i.e.
void setOffset(int _diffx, int _diffy)
Set a global offset to the X and Y coordinates.
static double toUserValue(double ptValue, Unit unit)
This method is the one to use to display a value in a dialog.
static double fromUserValue(double value, Unit unit)
This method is the one to use to read a value from a dialog.
static TQString unitDescription(Unit _unit)
Get the full (translated) description of a unit.
Unit
Length units supported by KOffice.
static Unit unit(const TQString &_unitName, bool *ok=0)
Convert a unit name into a Unit enum.
TDEAction * action(StdAction act_enum, const TQObject *recvr, const char *slot, TDEActionCollection *parent, const char *name=0L)
This structure defines the page layout, including its size in pt, its format (e.g.
Struct: KoTabulator Defines the position of a tabulation (in pt), and its type.
KoTabulators type
Type of tab (left/center/right/decimalpoint)
KoTabulatorFilling filling
Type of tab filling.
double ptPos
Position of the tab in pt.
TQChar alignChar
Alignment character.
double ptWidth
Width of the tab filling line.