Commit 31306680 authored by Aurélien Gâteau's avatar Aurélien Gâteau

Remove length actions

All resizing can now be done using the resize handles
parent 802902f2
...@@ -59,8 +59,8 @@ ...@@ -59,8 +59,8 @@
#include "ui_cfg_appearance.h" #include "ui_cfg_appearance.h"
#include "ui_cfg_advanced.h" #include "ui_cfg_advanced.h"
static const int RESIZE_HANDLE_LEN = 7; static const int RESIZE_HANDLE_LENGTH = 7;
static const int RESIZE_HANDLE_SHORT_LEN = 24; static const int RESIZE_HANDLE_THICKNESS = 24;
static const qreal RESIZE_HANDLE_OPACITY = 0.3; static const qreal RESIZE_HANDLE_OPACITY = 0.3;
static const int SMALL_TICK_SIZE = 6; static const int SMALL_TICK_SIZE = 6;
...@@ -77,12 +77,7 @@ static const int THICKNESS = 70; ...@@ -77,12 +77,7 @@ static const int THICKNESS = 70;
KLineal::KLineal( QWidget *parent ) KLineal::KLineal( QWidget *parent )
: QWidget( parent ), : QWidget( parent ),
mRulerState( StateNone ), mRulerState( StateNone ),
mShortEdgeLen( 70 ),
mCloseAction( 0 ), mCloseAction( 0 ),
mLenMenu( 0 ), // INFO This member could be eventually deleted
// since if mFullScreenAction is initialized
// mLenMenu should have been, too.
mFullScreenAction( 0 ),
mScaleDirectionAction( 0 ), mScaleDirectionAction( 0 ),
mCenterOriginAction( 0 ), mCenterOriginAction( 0 ),
mOffsetAction( 0 ), mOffsetAction( 0 ),
...@@ -104,7 +99,7 @@ KLineal::KLineal( QWidget *parent ) ...@@ -104,7 +99,7 @@ KLineal::KLineal( QWidget *parent )
mColor = RulerSettings::self()->bgColor(); mColor = RulerSettings::self()->bgColor();
mScaleFont = RulerSettings::self()->scaleFont(); mScaleFont = RulerSettings::self()->scaleFont();
mLongEdgeLen = RulerSettings::self()->length(); int len = RulerSettings::self()->length();
mHorizontal = RulerSettings::self()->horizontal(); mHorizontal = RulerSettings::self()->horizontal();
mLeftToRight = RulerSettings::self()->leftToRight(); mLeftToRight = RulerSettings::self()->leftToRight();
mOffset = RulerSettings::self()->offset(); mOffset = RulerSettings::self()->offset();
...@@ -114,7 +109,11 @@ KLineal::KLineal( QWidget *parent ) ...@@ -114,7 +109,11 @@ KLineal::KLineal( QWidget *parent )
mLabel = new QAutoSizeLabel( this ); mLabel = new QAutoSizeLabel( this );
mLabel->setWhatsThis( i18n( "This is the current distance measured in pixels." ) ); mLabel->setWhatsThis( i18n( "This is the current distance measured in pixels." ) );
resize( QSize( mLongEdgeLen, mShortEdgeLen ) ); if ( mHorizontal ) {
resize( QSize( len, THICKNESS ) );
} else {
resize( QSize( THICKNESS, len ) );
}
//BEGIN setup menu and actions //BEGIN setup menu and actions
mActionCollection = new KActionCollection( this ); mActionCollection = new KActionCollection( this );
...@@ -125,20 +124,6 @@ KLineal::KLineal( QWidget *parent ) ...@@ -125,20 +124,6 @@ KLineal::KLineal( QWidget *parent )
addAction( mMenu, QIcon::fromTheme( QStringLiteral( "object-rotate-left" ) ), i18n( "Rotate" ), addAction( mMenu, QIcon::fromTheme( QStringLiteral( "object-rotate-left" ) ), i18n( "Rotate" ),
this, SLOT(rotate()), Qt::Key_R, QStringLiteral( "turn_right" ) ); this, SLOT(rotate()), Qt::Key_R, QStringLiteral( "turn_right" ) );
mLenMenu = new QMenu( i18n( "&Length" ), this );
addAction( mLenMenu, QIcon(), i18nc( "Make Kruler Height Short", "&Short" ),
this, SLOT(setShortLength()), Qt::CTRL + Qt::Key_S, QStringLiteral( "length_short" ) );
addAction( mLenMenu, QIcon(), i18nc( "Make Kruler Height Medium", "&Medium" ),
this, SLOT(setMediumLength()), Qt::CTRL + Qt::Key_M, QStringLiteral( "length_medium" ) );
addAction( mLenMenu, QIcon(), i18nc( "Make Kruler Height Tall", "&Tall" ),
this, SLOT(setTallLength()), Qt::CTRL + Qt::Key_T, QStringLiteral( "length_tall" ) );
addAction( mLenMenu, QIcon(), i18n("&Full Screen Width"),
this, SLOT(setFullLength()), Qt::CTRL + Qt::Key_F, QStringLiteral( "length_full_length" ) );
mLenMenu->addSeparator();
addAction( mLenMenu, QIcon(), i18n( "Length..." ),
this, SLOT(slotLength()), QKeySequence(), QStringLiteral( "set_length" ) );
mMenu->addMenu( mLenMenu );
QMenu* scaleMenu = new QMenu( i18n( "&Scale" ), this ); QMenu* scaleMenu = new QMenu( i18n( "&Scale" ), this );
mScaleDirectionAction = addAction( scaleMenu, QIcon(), i18n( "Right to Left" ), mScaleDirectionAction = addAction( scaleMenu, QIcon(), i18n( "Right to Left" ),
this, SLOT(switchDirection()), Qt::Key_D, QStringLiteral( "right_to_left" ) ); this, SLOT(switchDirection()), Qt::Key_D, QStringLiteral( "right_to_left" ) );
...@@ -285,6 +270,9 @@ void KLineal::drawBackground( QPainter& painter ) ...@@ -285,6 +270,9 @@ void KLineal::drawBackground( QPainter& painter )
void KLineal::setHorizontal( bool horizontal ) void KLineal::setHorizontal( bool horizontal )
{ {
QRect r = frameGeometry(); QRect r = frameGeometry();
if ( mHorizontal != horizontal ) {
r.setSize( r.size().transposed() );
}
mHorizontal = horizontal; mHorizontal = horizontal;
QPoint center = mLastClickPos; QPoint center = mLastClickPos;
...@@ -295,17 +283,19 @@ void KLineal::setHorizontal( bool horizontal ) ...@@ -295,17 +283,19 @@ void KLineal::setHorizontal( bool horizontal )
center = r.topLeft() + QPoint( width() / 2, height() / 2 ); center = r.topLeft() + QPoint( width() / 2, height() / 2 );
} }
if ( mHorizontal ) {
r.setSize( QSize( mLongEdgeLen, mShortEdgeLen ) );
} else {
r.setSize( QSize( mShortEdgeLen, mLongEdgeLen ) );
}
QPoint newTopLeft = QPoint( center.x() - height() / 2, center.y() - width() / 2 ); QPoint newTopLeft = QPoint( center.x() - height() / 2, center.y() - width() / 2 );
r.moveTo(newTopLeft); r.moveTo(newTopLeft);
QRect desktop = QApplication::desktop()->screenGeometry( this ); QRect desktop = QApplication::desktop()->screenGeometry( this );
if ( r.width() > desktop.width() ) {
r.setWidth( desktop.width() );
}
if ( r.height() > desktop.height() ) {
r.setHeight( desktop.height() );
}
if ( r.top() < desktop.top() ) { if ( r.top() < desktop.top() ) {
r.moveTop( desktop.top() ); r.moveTop( desktop.top() );
} }
...@@ -325,10 +315,6 @@ void KLineal::setHorizontal( bool horizontal ) ...@@ -325,10 +315,6 @@ void KLineal::setHorizontal( bool horizontal )
setGeometry( r ); setGeometry( r );
adjustLabel(); adjustLabel();
if ( mLenMenu && mFullScreenAction ) {
mFullScreenAction->setText( mHorizontal ? i18n( "&Full Screen Width" ) : i18n( "&Full Screen Height" ) );
}
updateScaleDirectionMenuItem(); updateScaleDirectionMenuItem();
saveSettings(); saveSettings();
...@@ -339,57 +325,6 @@ void KLineal::rotate() ...@@ -339,57 +325,6 @@ void KLineal::rotate()
setHorizontal( !mHorizontal ); setHorizontal( !mHorizontal );
} }
void KLineal::reLength( int percentOfScreen )
{
if ( percentOfScreen < 10 ) {
return;
}
QRect r = QApplication::desktop()->screenGeometry( this );
if ( mHorizontal ) {
mLongEdgeLen = r.width() * percentOfScreen / 100;
resize( mLongEdgeLen, height() );
} else {
mLongEdgeLen = r.height() * percentOfScreen / 100;
resize( width(), mLongEdgeLen );
}
if ( x() + width() < 10 ) {
move( 10, y() );
}
if ( y() + height() < 10 ) {
move( x(), 10 );
}
saveSettings();
}
void KLineal::reLengthAbsolute( int length )
{
if ( length < 100 ) {
return;
}
mLongEdgeLen = length;
if ( mHorizontal ) {
resize( mLongEdgeLen, height() );
} else {
resize( width(), mLongEdgeLen );
}
if ( x() + width() < 10 ) {
move( 10, y() );
}
if ( y() + height() < 10 ) {
move( x(), 10 );
}
saveSettings();
}
void KLineal::updateScaleDirectionMenuItem() void KLineal::updateScaleDirectionMenuItem()
{ {
if ( !mScaleDirectionAction ) return; if ( !mScaleDirectionAction ) return;
...@@ -407,18 +342,18 @@ void KLineal::updateScaleDirectionMenuItem() ...@@ -407,18 +342,18 @@ void KLineal::updateScaleDirectionMenuItem()
QRect KLineal::beginRect() const QRect KLineal::beginRect() const
{ {
int shortLen = RESIZE_HANDLE_SHORT_LEN; int shortLen = RESIZE_HANDLE_THICKNESS;
return mHorizontal return mHorizontal
? QRect( 0, ( height() - shortLen ) / 2 + 1, RESIZE_HANDLE_LEN, shortLen ) ? QRect( 0, ( height() - shortLen ) / 2 + 1, RESIZE_HANDLE_LENGTH, shortLen )
: QRect( ( width() - shortLen ) / 2, 0, shortLen, RESIZE_HANDLE_LEN ); : QRect( ( width() - shortLen ) / 2, 0, shortLen, RESIZE_HANDLE_LENGTH );
} }
QRect KLineal::endRect() const QRect KLineal::endRect() const
{ {
int shortLen = RESIZE_HANDLE_SHORT_LEN; int shortLen = RESIZE_HANDLE_THICKNESS;
return mHorizontal return mHorizontal
? QRect( width() - RESIZE_HANDLE_LEN, ( height() - shortLen ) / 2 + 1, RESIZE_HANDLE_LEN, shortLen ) ? QRect( width() - RESIZE_HANDLE_LENGTH, ( height() - shortLen ) / 2 + 1, RESIZE_HANDLE_LENGTH, shortLen )
: QRect( ( width() - shortLen ) / 2, height() - RESIZE_HANDLE_LEN, shortLen, RESIZE_HANDLE_LEN ); : QRect( ( width() - shortLen ) / 2, height() - RESIZE_HANDLE_LENGTH, shortLen, RESIZE_HANDLE_LENGTH );
} }
Qt::CursorShape KLineal::resizeCursor() const Qt::CursorShape KLineal::resizeCursor() const
...@@ -426,26 +361,6 @@ Qt::CursorShape KLineal::resizeCursor() const ...@@ -426,26 +361,6 @@ Qt::CursorShape KLineal::resizeCursor() const
return mHorizontal ? Qt::SizeHorCursor : Qt::SizeVerCursor; return mHorizontal ? Qt::SizeHorCursor : Qt::SizeVerCursor;
} }
void KLineal::setShortLength()
{
reLength( 30 );
}
void KLineal::setMediumLength()
{
reLength( 50 );
}
void KLineal::setTallLength()
{
reLength( 75 );
}
void KLineal::setFullLength()
{
reLength( 100 );
}
void KLineal::switchDirection() void KLineal::switchDirection()
{ {
mLeftToRight = !mLeftToRight; mLeftToRight = !mLeftToRight;
...@@ -457,7 +372,7 @@ void KLineal::switchDirection() ...@@ -457,7 +372,7 @@ void KLineal::switchDirection()
void KLineal::centerOrigin() void KLineal::centerOrigin()
{ {
mOffset = -( mLongEdgeLen / 2 ); mOffset = -( length() / 2 );
repaint(); repaint();
adjustLabel(); adjustLabel();
saveSettings(); saveSettings();
...@@ -478,20 +393,6 @@ void KLineal::slotOffset() ...@@ -478,20 +393,6 @@ void KLineal::slotOffset()
} }
} }
void KLineal::slotLength()
{
bool ok;
QRect r = QApplication::desktop()->screenGeometry( this );
int width = mHorizontal ? r.width() : r.height();
int newLength = QInputDialog::getInt( this, i18nc( "@title:window", "Ruler Length" ),
i18n( "Length:" ), mLongEdgeLen,
0, width, 1, &ok );
if ( ok ) {
reLengthAbsolute( newLength );
}
}
void KLineal::slotOpacity( int value ) void KLineal::slotOpacity( int value )
{ {
mOpacity = value; mOpacity = value;
...@@ -575,7 +476,7 @@ void KLineal::saveSettings() ...@@ -575,7 +476,7 @@ void KLineal::saveSettings()
{ {
RulerSettings::self()->setBgColor( mColor ); RulerSettings::self()->setBgColor( mColor );
RulerSettings::self()->setScaleFont( mScaleFont ); RulerSettings::self()->setScaleFont( mScaleFont );
RulerSettings::self()->setLength( mLongEdgeLen ); RulerSettings::self()->setLength( length() );
RulerSettings::self()->setHorizontal( mHorizontal ); RulerSettings::self()->setHorizontal( mHorizontal );
RulerSettings::self()->setLeftToRight( mLeftToRight ); RulerSettings::self()->setLeftToRight( mLeftToRight );
RulerSettings::self()->setOffset( mOffset ); RulerSettings::self()->setOffset( mOffset );
...@@ -598,6 +499,11 @@ bool KLineal::isResizing() const ...@@ -598,6 +499,11 @@ bool KLineal::isResizing() const
return mouseGrabber() == this && ( mRulerState == StateBegin || mRulerState == StateEnd ); return mouseGrabber() == this && ( mRulerState == StateBegin || mRulerState == StateEnd );
} }
int KLineal::length() const
{
return mHorizontal ? width() : height();
}
QPoint KLineal::localCursorPos() const QPoint KLineal::localCursorPos() const
{ {
// For some reason mapFromGlobal( QCursor::pos() ) thinks the ruler is at 0, 0 at startup. // For some reason mapFromGlobal( QCursor::pos() ) thinks the ruler is at 0, 0 at startup.
...@@ -624,21 +530,21 @@ void KLineal::adjustLabel() ...@@ -624,21 +530,21 @@ void KLineal::adjustLabel()
} else { } else {
color = Qt::red; color = Qt::red;
QPoint pos = localCursorPos(); QPoint pos = localCursorPos();
int length = mHorizontal ? pos.x() : pos.y(); int len = mHorizontal ? pos.x() : pos.y();
if ( !mRelativeScale ) { if ( !mRelativeScale ) {
if ( mLeftToRight ) { if ( mLeftToRight ) {
length += mOffset; len += mOffset;
} else { } else {
length = mLongEdgeLen - length + mOffset; len = length() - len + mOffset;
} }
text = i18n( "%1 px", length ); text = i18n( "%1 px", len );
} else { } else {
length = ( length * 100.f ) / mLongEdgeLen; len = ( len * 100.f ) / length();
if ( !mLeftToRight ) { if ( !mLeftToRight ) {
length = 100 - length; len = 100 - len;
} }
text = i18n( "%1%", length ); text = i18n( "%1%", len );
} }
} }
...@@ -719,7 +625,6 @@ void KLineal::mouseMoveEvent( QMouseEvent *inEvent ) ...@@ -719,7 +625,6 @@ void KLineal::mouseMoveEvent( QMouseEvent *inEvent )
r.setTop( QCursor::pos().y() - mDragOffset.y() ); r.setTop( QCursor::pos().y() - mDragOffset.y() );
} }
setGeometry( r ); setGeometry( r );
adjustLabel(); adjustLabel();
} else if ( mRulerState == StateEnd ) { } else if ( mRulerState == StateEnd ) {
QPoint end = QCursor::pos() + mDragOffset - pos(); QPoint end = QCursor::pos() + mDragOffset - pos();
...@@ -820,6 +725,7 @@ void KLineal::mouseReleaseEvent( QMouseEvent *inEvent ) ...@@ -820,6 +725,7 @@ void KLineal::mouseReleaseEvent( QMouseEvent *inEvent )
if ( mRulerState != StateNone ) { if ( mRulerState != StateNone ) {
mRulerState = StateNone; mRulerState = StateNone;
releaseMouse(); releaseMouse();
saveSettings();
} else if ( nativeMove() ) { } else if ( nativeMove() ) {
stopNativeMove( inEvent ); stopNativeMove( inEvent );
} }
...@@ -841,26 +747,6 @@ void KLineal::wheelEvent( QWheelEvent *e ) ...@@ -841,26 +747,6 @@ void KLineal::wheelEvent( QWheelEvent *e )
mLabel->setText( i18n( "Offset: %1", mOffset ) ); mLabel->setText( i18n( "Offset: %1", mOffset ) );
saveSettings(); saveSettings();
} }
} else { // changing length
int oldLen = mLongEdgeLen;
int newLength = mLongEdgeLen + numSteps;
reLengthAbsolute( newLength );
mLabel->setText( i18n( "Length: %1 px", mLongEdgeLen ) );
// when holding shift relength at the other side
if ( e->modifiers() & Qt::ShiftModifier ) {
int change = mLongEdgeLen - oldLen;
QPoint dist;
if ( mHorizontal ) {
dist.setX( -change );
} else {
dist.setY( -change );
}
move( pos() + dist );
}
} }
QWidget::wheelEvent( e ); QWidget::wheelEvent( e );
...@@ -975,14 +861,14 @@ void KLineal::drawResizeHandle( QPainter &painter, Qt::Edge edge ) ...@@ -975,14 +861,14 @@ void KLineal::drawResizeHandle( QPainter &painter, Qt::Edge edge )
} }
painter.setOpacity( RESIZE_HANDLE_OPACITY ); painter.setOpacity( RESIZE_HANDLE_OPACITY );
if ( mHorizontal ) { if ( mHorizontal ) {
int y1 = ( mShortEdgeLen - RESIZE_HANDLE_SHORT_LEN ) / 2; int y1 = ( THICKNESS - RESIZE_HANDLE_THICKNESS ) / 2;
int y2 = y1 + RESIZE_HANDLE_SHORT_LEN - 1; int y2 = y1 + RESIZE_HANDLE_THICKNESS - 1;
for ( int x = rect.left() + 1; x < rect.right(); x += 2 ) { for ( int x = rect.left() + 1; x < rect.right(); x += 2 ) {
painter.drawLine( x, y1, x, y2 ); painter.drawLine( x, y1, x, y2 );
} }
} else { } else {
int x1 = ( mShortEdgeLen - RESIZE_HANDLE_SHORT_LEN ) / 2; int x1 = ( THICKNESS - RESIZE_HANDLE_THICKNESS ) / 2;
int x2 = x1 + RESIZE_HANDLE_SHORT_LEN - 1; int x2 = x1 + RESIZE_HANDLE_THICKNESS - 1;
for ( int y = rect.top() + 1; y < rect.bottom(); y += 2 ) { for ( int y = rect.top() + 1; y < rect.bottom(); y += 2 ) {
painter.drawLine( x1, y, x2, y ); painter.drawLine( x1, y, x2, y );
} }
......
...@@ -62,8 +62,6 @@ private: ...@@ -62,8 +62,6 @@ private:
void drawScaleText( QPainter &painter, int x, const QString &text ); void drawScaleText( QPainter &painter, int x, const QString &text );
void drawScaleTick( QPainter &painter, int x, int length ); void drawScaleTick( QPainter &painter, int x, int length );
void drawResizeHandle( QPainter &painter, Qt::Edge edge ); void drawResizeHandle( QPainter &painter, Qt::Edge edge );
void reLength( int percentOfScreen );
void reLengthAbsolute( int length );
void updateScaleDirectionMenuItem(); void updateScaleDirectionMenuItem();
QRect beginRect() const; QRect beginRect() const;
...@@ -85,12 +83,8 @@ private: ...@@ -85,12 +83,8 @@ private:
QPoint mDragOffset; QPoint mDragOffset;
QAutoSizeLabel *mLabel; QAutoSizeLabel *mLabel;
bool mHorizontal; bool mHorizontal;
int mLongEdgeLen;
int mShortEdgeLen;
QMenu *mMenu; QMenu *mMenu;
QAction *mCloseAction; QAction *mCloseAction;
QMenu *mLenMenu;
QAction *mFullScreenAction;
QAction *mScaleDirectionAction; QAction *mScaleDirectionAction;
QAction *mCenterOriginAction; QAction *mCenterOriginAction;
QAction *mOffsetAction; QAction *mOffsetAction;
...@@ -108,20 +102,16 @@ private: ...@@ -108,20 +102,16 @@ private:
void setHorizontal( bool horizontal ); void setHorizontal( bool horizontal );
bool isResizing() const; bool isResizing() const;
int length() const;
QPoint localCursorPos() const; QPoint localCursorPos() const;
public slots: public slots:
void rotate(); void rotate();
void showMenu(); void showMenu();
void adjustLabel(); void adjustLabel();
void setShortLength();
void setMediumLength();
void setTallLength();
void setFullLength();
void switchDirection(); void switchDirection();
void centerOrigin(); void centerOrigin();
void slotOffset(); void slotOffset();
void slotLength();
void slotOpacity( int value ); void slotOpacity( int value );
void slotKeyBindings(); void slotKeyBindings();
void slotPreferences(); void slotPreferences();
......
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