Commit 13cb752c authored by Mathias Soeken's avatar Mathias Soeken

kruler can now measure from right to left or from bottom to top, when...

kruler can now measure from right to left or from bottom to top, when orientation is north/south or west/east, respectively.

CCBUG: 89630
BUGS: 89630

svn path=/trunk/KDE/kdegraphics/kruler/; revision=907732
parent 462d6b81
...@@ -67,9 +67,14 @@ KLineal::KLineal( QWidget *parent ) ...@@ -67,9 +67,14 @@ KLineal::KLineal( QWidget *parent )
mDragging( false ), mDragging( false ),
mOrientation( South ), mOrientation( South ),
mShortEdgeLen( 70 ), mShortEdgeLen( 70 ),
mLenMenu( 0 ), mLenMenu( 0 ), // INFO This member could be eventually deleted
// since if mFullScreenAction is initialized
// mLenMenu should have been, too.
mFullScreenAction( 0 ),
mScaleDirectionAction( 0 ),
mColorSelector( this ), mColorSelector( this ),
_clicked( false ) mClicked( false ),
mLeftToRight( true )
{ {
KWindowSystem::setType( winId(), NET::Override ); // or NET::Normal KWindowSystem::setType( winId(), NET::Override ); // or NET::Normal
KWindowSystem::setState( winId(), NET::KeepAbove ); KWindowSystem::setState( winId(), NET::KeepAbove );
...@@ -116,7 +121,6 @@ KLineal::KLineal( QWidget *parent ) ...@@ -116,7 +121,6 @@ KLineal::KLineal( QWidget *parent )
"little square at the end of the line cursor." ) ); "little square at the end of the line cursor." ) );
resize( QSize( mLongEdgeLen, mShortEdgeLen ) ); resize( QSize( mLongEdgeLen, mShortEdgeLen ) );
setOrientation( South );
mMenu = new KMenu( this ); mMenu = new KMenu( this );
mMenu->addTitle( i18n( "KRuler" ) ); mMenu->addTitle( i18n( "KRuler" ) );
...@@ -163,12 +167,13 @@ KLineal::KLineal( QWidget *parent ) ...@@ -163,12 +167,13 @@ KLineal::KLineal( QWidget *parent )
new QShortcut( Qt::CTRL + Qt::Key_F, this, SLOT( setFullLength() ) ); new QShortcut( Qt::CTRL + Qt::Key_F, this, SLOT( setFullLength() ) );
mMenu->addMenu( mLenMenu ); mMenu->addMenu( mLenMenu );
/*KMenu* mScaleMenu = new KMenu( i18n( "&Scale" ), this ); KMenu* scaleMenu = new KMenu( i18n( "&Scale" ), this );
mScaleMenu->addAction( i18n( "Right To Left" ), this, SLOT( switchDirection() ) ); mScaleDirectionAction = scaleMenu->addAction( i18n( "Right To Left" ), this, SLOT( switchDirection() ), Qt::Key_D );
mScaleMenu->addAction( i18n( "Center origin" ), this, SLOT( centerOrigin() ) ); new QShortcut( Qt::Key_D, this, SLOT( switchDirection() ) );
mMenu->addMenu( mScaleMenu ); //scaleMenu->addAction( i18n( "Center origin" ), this, SLOT( centerOrigin() ) );
mMenu->addMenu( scaleMenu );
mMenu->addAction( KStandardAction::preferences( this, SLOT( slotPreferences() ), this ) );*/ /*mMenu->addAction( KStandardAction::preferences( this, SLOT( slotPreferences() ), this ) );*/
mMenu->addAction( KIcon( "preferences-desktop-color" ), mMenu->addAction( KIcon( "preferences-desktop-color" ),
i18n( "&Choose Color..." ), this, SLOT( chooseColor() ), i18n( "&Choose Color..." ), this, SLOT( chooseColor() ),
...@@ -187,6 +192,8 @@ KLineal::KLineal( QWidget *parent ) ...@@ -187,6 +192,8 @@ KLineal::KLineal( QWidget *parent )
new QShortcut( quit->shortcut().primary(), this, SLOT(slotQuit() ) ); new QShortcut( quit->shortcut().primary(), this, SLOT(slotQuit() ) );
mLastClickPos = geometry().topLeft() + QPoint( width() / 2, height() / 2 ); mLastClickPos = geometry().topLeft() + QPoint( width() / 2, height() / 2 );
setOrientation( South );
} }
KLineal::~KLineal() KLineal::~KLineal()
...@@ -264,9 +271,9 @@ void KLineal::setOrientation( int inOrientation ) ...@@ -264,9 +271,9 @@ void KLineal::setOrientation( int inOrientation )
mOrientation = ( inOrientation + 4 ) % 4; mOrientation = ( inOrientation + 4 ) % 4;
QPoint center = mLastClickPos, newTopLeft; QPoint center = mLastClickPos, newTopLeft;
if ( _clicked ) { if ( mClicked ) {
center = mLastClickPos; center = mLastClickPos;
_clicked = false; mClicked = false;
} else { } else {
center = r.topLeft() + QPoint( width() / 2, height() / 2 ); center = r.topLeft() + QPoint( width() / 2, height() / 2 );
} }
...@@ -334,6 +341,8 @@ void KLineal::setOrientation( int inOrientation ) ...@@ -334,6 +341,8 @@ void KLineal::setOrientation( int inOrientation )
mFullScreenAction->setText( mOrientation % 2 ? i18n( "&Full Screen Height" ) : i18n( "&Full Screen Width" ) ); mFullScreenAction->setText( mOrientation % 2 ? i18n( "&Full Screen Height" ) : i18n( "&Full Screen Width" ) );
} }
updateScaleDirectionMenuItem();
setCursor( mCurrentCursor ); setCursor( mCurrentCursor );
repaint(); repaint();
} }
...@@ -395,6 +404,21 @@ void KLineal::reLength( int percentOfScreen ) ...@@ -395,6 +404,21 @@ void KLineal::reLength( int percentOfScreen )
saveSettings(); saveSettings();
} }
void KLineal::updateScaleDirectionMenuItem()
{
if ( !mScaleDirectionAction ) return;
QString label;
if ( mOrientation == North || mOrientation == South ) {
label = mLeftToRight ? i18n( "Right To Left" ) : i18n( "Left To Right" );
} else {
label = mLeftToRight ? i18n( "Bottom To Top" ) : i18n( "Top To Bottom" );
}
mScaleDirectionAction->setText( label );
}
void KLineal::setShortLength() void KLineal::setShortLength()
{ {
reLength( 30 ); reLength( 30 );
...@@ -415,6 +439,13 @@ void KLineal::setFullLength() ...@@ -415,6 +439,13 @@ void KLineal::setFullLength()
reLength( 100 ); reLength( 100 );
} }
void KLineal::switchDirection()
{
mLeftToRight = !mLeftToRight;
updateScaleDirectionMenuItem();
repaint();
}
void KLineal::chooseColor() void KLineal::chooseColor()
{ {
QRect r = KGlobalSettings::desktopGeometry( this ); QRect r = KGlobalSettings::desktopGeometry( this );
...@@ -694,7 +725,7 @@ void KLineal::mousePressEvent( QMouseEvent *inEvent ) ...@@ -694,7 +725,7 @@ void KLineal::mousePressEvent( QMouseEvent *inEvent )
mDragging = true; mDragging = true;
} }
} else if ( inEvent->button() == Qt::MidButton ) { } else if ( inEvent->button() == Qt::MidButton ) {
_clicked = true; mClicked = true;
turnLeft(); turnLeft();
} else if ( inEvent->button() == Qt::RightButton ) { } else if ( inEvent->button() == Qt::RightButton ) {
showMenu(); showMenu();
...@@ -769,7 +800,9 @@ void KLineal::drawScale( QPainter &painter ) ...@@ -769,7 +800,9 @@ void KLineal::drawScale( QPainter &painter )
} }
int ten = 10, twenty = 20, fourty = 40, hundred = 100; int ten = 10, twenty = 20, fourty = 40, hundred = 100;
for ( longCoo = 0; longCoo < longLen; longCoo += 2 ) { longCoo = mLeftToRight ? 0 : longLen;
while ( longCoo <= longLen && longCoo >= 0 ) {
int len = 6; int len = 6;
if (ten == 10) { if (ten == 10) {
if (twenty == 20) { if (twenty == 20) {
...@@ -783,9 +816,9 @@ void KLineal::drawScale( QPainter &painter ) ...@@ -783,9 +816,9 @@ void KLineal::drawScale( QPainter &painter )
QString units; QString units;
int digits; int digits;
if (hundred == 100 || mOrientation == West || mOrientation == East) { if (hundred == 100 || mOrientation == West || mOrientation == East) {
digits = longCoo; digits = mLeftToRight ? longCoo : ( longLen - longCoo );
} else { } else {
digits = longCoo % 100; digits = mLeftToRight ? ( longCoo % 100 ) : ( ( longLen - longCoo ) % 100 );
} }
units.sprintf( "%d", digits ); units.sprintf( "%d", digits );
QSize textSize = metrics.size( Qt::TextSingleLine, units ); QSize textSize = metrics.size( Qt::TextSingleLine, units );
...@@ -794,37 +827,37 @@ void KLineal::drawScale( QPainter &painter ) ...@@ -794,37 +827,37 @@ void KLineal::drawScale( QPainter &painter )
switch ( mOrientation ) { switch ( mOrientation ) {
case North: case North:
if ( digits < 1000 || fourty == 40 || hundred == 100 ) { if ( digits < 1000 || fourty == 40 || hundred == 100 ) {
if ( longCoo != 0 ) { if ( digits != 0 ) {
painter.drawText( longCoo - tw / 2, shortStart + len + th, units ); painter.drawText( longCoo - tw / 2, shortStart + len + th, units );
} else { } else {
painter.drawText( 1, shortStart + len + th, units ); painter.drawText( mLeftToRight ? 1 : ( longLen - 1 - tw ), shortStart + len + th, units );
} }
} }
break; break;
case South: case South:
if ( digits < 1000 || fourty == 40 || hundred == 100 ) { if ( digits < 1000 || fourty == 40 || hundred == 100 ) {
if ( longCoo != 0 ) { if ( digits != 0 ) {
painter.drawText( longCoo - tw / 2, shortStart - len - 2, units ); painter.drawText( longCoo - tw / 2, shortStart - len - 2, units );
} else { } else {
painter.drawText( 1, shortStart - len - 2, units ); painter.drawText( mLeftToRight ? 1 : ( longLen - 1 - tw ), shortStart - len - 2, units );
} }
} }
break; break;
case East: case East:
if (longCoo != 0) { if ( digits != 0 ) {
painter.drawText( shortStart - len - tw - 2, longCoo + th / 2 - 2, units ); painter.drawText( shortStart - len - tw - 2, longCoo + th / 2 - 2, units );
} else { } else {
painter.drawText( shortStart - len - tw - 2, th - 2, units ); painter.drawText( shortStart - len - tw - 2, mLeftToRight ? ( th - 2 ) : ( longLen + 9 - th ), units );
} }
break; break;
case West: case West:
if ( longCoo != 0 ) { if ( digits != 0 ) {
painter.drawText( shortStart + len + 2, longCoo + th / 2 - 2, units ); painter.drawText( shortStart + len + 2, longCoo + th / 2 - 2, units );
} else { } else {
painter.drawText( shortStart + len + 2, th - 2, units ); painter.drawText( shortStart + len + 2, mLeftToRight ? ( th - 2 ) : ( longLen + 9 - th ), units );
} }
break; break;
} }
...@@ -858,6 +891,8 @@ void KLineal::drawScale( QPainter &painter ) ...@@ -858,6 +891,8 @@ void KLineal::drawScale( QPainter &painter )
} else { } else {
hundred += 2; hundred += 2;
} }
longCoo += mLeftToRight ? 2 : -2;
} }
} }
......
...@@ -54,6 +54,8 @@ private: ...@@ -54,6 +54,8 @@ private:
void drawScale( QPainter &painter ); void drawScale( QPainter &painter );
void drawBackground( QPainter &painter ); void drawBackground( QPainter &painter );
void reLength( int percentOfScreen ); void reLength( int percentOfScreen );
void updateScaleDirectionMenuItem();
bool mDragging; bool mDragging;
QPoint mLastClickPos; QPoint mLastClickPos;
QPoint mDragOffset; QPoint mDragOffset;
...@@ -65,6 +67,7 @@ private: ...@@ -65,6 +67,7 @@ private:
KMenu *mMenu; KMenu *mMenu;
KMenu *mLenMenu; KMenu *mLenMenu;
QAction *mFullScreenAction; QAction *mFullScreenAction;
QAction *mScaleDirectionAction;
QColor mColor; QColor mColor;
QColor mStoredColor; QColor mStoredColor;
QCursor mCurrentCursor; QCursor mCurrentCursor;
...@@ -75,7 +78,8 @@ private: ...@@ -75,7 +78,8 @@ private:
QCursor mDragCursor; QCursor mDragCursor;
KColorDialog mColorSelector; KColorDialog mColorSelector;
QFont mScaleFont; QFont mScaleFont;
bool _clicked; bool mClicked;
bool mLeftToRight;
public slots: public slots:
void setOrientation( int ); void setOrientation( int );
...@@ -93,6 +97,7 @@ public slots: ...@@ -93,6 +97,7 @@ public slots:
void setMediumLength(); void setMediumLength();
void setTallLength(); void setTallLength();
void setFullLength(); void setFullLength();
void switchDirection();
void setColor(); void setColor();
void setFont( const QFont &font ); void setFont( const QFont &font );
void setColor( const QColor &color ); void setColor( const QColor &color );
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment